1 /*	raw_imp.c	4.15	83/02/10	*/
2 
3 #include "../h/param.h"
4 #include "../h/mbuf.h"
5 #include "../h/socket.h"
6 #include "../h/protosw.h"
7 #include "../h/socketvar.h"
8 #include "../h/errno.h"
9 
10 #include "../net/if.h"
11 #include "../net/raw_cb.h"
12 
13 #include "../netinet/in.h"
14 #include "../netinet/in_systm.h"
15 #include "../netimp/if_imp.h"
16 
17 /*
18  * Raw interface to IMP.
19  */
20 
21 /*
22  * Generate IMP leader and pass packet to impoutput.
23  * The user must create a skeletal leader in order to
24  * communicate message type, message subtype, etc.
25  * We fill in holes where needed and verify parameters
26  * supplied by user.
27  */
28 rimp_output(m, so)
29 	register struct mbuf *m;
30 	struct socket *so;
31 {
32 	struct mbuf *n;
33 	int len, error = 0;
34 	register struct imp_leader *ip;
35 	register struct sockaddr_in *sin;
36 	register struct rawcb *rp = sotorawcb(so);
37 	struct ifnet *ifp;
38 	struct control_leader *cp;
39 
40 	/*
41 	 * Verify user has supplied necessary space
42 	 * for the leader and check parameters in it.
43 	 */
44 	if ((m->m_off > MMAXOFF || m->m_len < sizeof(struct control_leader)) &&
45 	    (m = m_pullup(m, sizeof(struct control_leader))) == 0) {
46 		error = EMSGSIZE;	/* XXX */
47 		goto bad;
48 	}
49 	cp = mtod(m, struct control_leader *);
50 	if (cp->dl_mtype == IMPTYPE_DATA)
51 		if (m->m_len < sizeof(struct imp_leader) &&
52 		    (m = m_pullup(m, sizeof(struct imp_leader))) == 0) {
53 			error = EMSGSIZE;	/* XXX */
54 			goto bad;
55 		}
56 	ip = mtod(m, struct imp_leader *);
57 	if (ip->il_format != IMP_NFF) {
58 		error = EMSGSIZE;		/* XXX */
59 		goto bad;
60 	}
61 #ifdef notdef
62 	if (ip->il_link != IMPLINK_IP &&
63 	    (ip->il_link<IMPLINK_LOWEXPER || ip->il_link>IMPLINK_HIGHEXPER)) {
64 		error = EPERM;
65 		goto bad;
66 	}
67 #endif
68 
69 	/*
70 	 * Fill in IMP leader -- impoutput refrains from rebuilding
71 	 * the leader when it sees the protocol family PF_IMPLINK.
72 	 * (message size calculated by walking through mbuf's)
73 	 */
74 	for (len = 0, n = m; n; n = n->m_next)
75 		len += n->m_len;
76 	ip->il_length = htons((u_short)(len << 3));
77 	sin = (struct sockaddr_in *)&rp->rcb_faddr;
78 #ifdef notdef
79 	ip->il_network = sin->sin_addr.s_net;
80 #else
81 	ip->il_network = 0;
82 #endif
83 	ip->il_host = sin->sin_addr.s_host;
84 	ip->il_imp = sin->sin_addr.s_imp;
85 	/* no routing here */
86 	ifp = if_ifonnetof((int)sin->sin_addr.s_net);
87 	if (ifp)
88 		return (impoutput(ifp, m, (struct sockaddr *)sin));
89 	error = ENETUNREACH;
90 bad:
91 	m_freem(m);
92 	return (error);
93 }
94