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