1 /*	raw_imp.c	4.11	82/04/11	*/
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 "../net/in.h"
9 #include "../net/in_systm.h"
10 #include "../net/if.h"
11 #include "../net/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 COUNT(RIMP_OUTPUT);
39 	/*
40 	 * Verify user has supplied necessary space
41 	 * for the leader and check parameters in it.
42 	 */
43 	if ((m->m_off > MMAXOFF || m->m_len < sizeof(struct control_leader)) &&
44 	    (m = m_pullup(m, sizeof(struct control_leader))) == 0) {
45 		error = EMSGSIZE;	/* XXX */
46 		goto bad;
47 	}
48 	cp = mtod(m, struct control_leader *);
49 	if (cp->dl_mtype == IMPTYPE_DATA)
50 		if (m->m_len < sizeof(struct imp_leader) &&
51 		    (m = m_pullup(m, sizeof(struct imp_leader))) == 0) {
52 			error = EMSGSIZE;	/* XXX */
53 			goto bad;
54 		}
55 	ip = mtod(m, struct imp_leader *);
56 	if (ip->il_format != IMP_NFF) {
57 		error = EMSGSIZE;		/* XXX */
58 		goto bad;
59 	}
60 #ifdef notdef
61 	if (ip->il_link != IMPLINK_IP &&
62 	    (ip->il_link<IMPLINK_LOWEXPER || ip->il_link>IMPLINK_HIGHEXPER)) {
63 		error = EPERM;
64 		goto bad;
65 	}
66 #endif
67 
68 	/*
69 	 * Fill in IMP leader -- impoutput refrains from rebuilding
70 	 * the leader when it sees the protocol family PF_IMPLINK.
71 	 * (message size calculated by walking through mbuf's)
72 	 */
73 	for (len = 0, n = m; n; n = n->m_next)
74 		len += n->m_len;
75 	ip->il_length = htons((u_short)(len << 3));
76 	sin = (struct sockaddr_in *)&rp->rcb_faddr;
77 #ifdef notdef
78 	ip->il_network = sin->sin_addr.s_net;
79 #else
80 	ip->il_network = 0;
81 #endif
82 	ip->il_host = sin->sin_addr.s_host;
83 	ip->il_imp = sin->sin_addr.s_imp;
84 	/* no routing here */
85 	ifp = if_ifonnetof(sin->sin_addr.s_net);
86 	if (ifp)
87 		return (impoutput(ifp, m, (struct sockaddr *)sin));
88 	error = ENETUNREACH;
89 bad:
90 	m_freem(m);
91 	return (error);
92 }
93