fix carrier drop handling in ttread & try improving LCASE mode
[unix-history] / usr / src / sys / deprecated / netimp / raw_imp.c
CommitLineData
91b2c865 1/* raw_imp.c 6.4 85/03/19 */
718d1f9e 2
54cf16ba
JB
3#include "param.h"
4#include "mbuf.h"
5#include "socket.h"
6#include "protosw.h"
7#include "socketvar.h"
8#include "errno.h"
f4d55810
SL
9
10#include "../net/if.h"
515ee6c7 11#include "../net/route.h"
f4d55810
SL
12#include "../net/raw_cb.h"
13
fcfe450e
BJ
14#include "../netinet/in.h"
15#include "../netinet/in_systm.h"
91b2c865 16#include "../netinet/in_var.h"
54cf16ba 17#include "if_imp.h"
718d1f9e
BJ
18
19/*
20 * Raw interface to IMP.
21 */
22
718d1f9e
BJ
23/*
24 * Generate IMP leader and pass packet to impoutput.
25 * The user must create a skeletal leader in order to
26 * communicate message type, message subtype, etc.
27 * We fill in holes where needed and verify parameters
28 * supplied by user.
29 */
8e999b50 30rimp_output(m, so)
718d1f9e
BJ
31 register struct mbuf *m;
32 struct socket *so;
33{
34 struct mbuf *n;
126472ab 35 int len, error = 0;
a0b7c7fb 36 register struct imp_leader *ip;
718d1f9e
BJ
37 register struct sockaddr_in *sin;
38 register struct rawcb *rp = sotorawcb(so);
91b2c865 39 struct in_ifaddr *ia;
a2cd4df7 40 struct control_leader *cp;
718d1f9e 41
718d1f9e
BJ
42 /*
43 * Verify user has supplied necessary space
44 * for the leader and check parameters in it.
45 */
a2cd4df7 46 if ((m->m_off > MMAXOFF || m->m_len < sizeof(struct control_leader)) &&
126472ab
SL
47 (m = m_pullup(m, sizeof(struct control_leader))) == 0) {
48 error = EMSGSIZE; /* XXX */
49 goto bad;
50 }
a2cd4df7
BJ
51 cp = mtod(m, struct control_leader *);
52 if (cp->dl_mtype == IMPTYPE_DATA)
53 if (m->m_len < sizeof(struct imp_leader) &&
126472ab
SL
54 (m = m_pullup(m, sizeof(struct imp_leader))) == 0) {
55 error = EMSGSIZE; /* XXX */
56 goto bad;
57 }
a0b7c7fb 58 ip = mtod(m, struct imp_leader *);
126472ab
SL
59 if (ip->il_format != IMP_NFF) {
60 error = EMSGSIZE; /* XXX */
718d1f9e 61 goto bad;
126472ab 62 }
27cadab0 63#ifdef notdef
a0b7c7fb 64 if (ip->il_link != IMPLINK_IP &&
126472ab
SL
65 (ip->il_link<IMPLINK_LOWEXPER || ip->il_link>IMPLINK_HIGHEXPER)) {
66 error = EPERM;
718d1f9e 67 goto bad;
126472ab 68 }
27cadab0 69#endif
718d1f9e
BJ
70
71 /*
72 * Fill in IMP leader -- impoutput refrains from rebuilding
73 * the leader when it sees the protocol family PF_IMPLINK.
74 * (message size calculated by walking through mbuf's)
75 */
76 for (len = 0, n = m; n; n = n->m_next)
77 len += n->m_len;
668cc26d 78 ip->il_length = htons((u_short)(len << 3));
126472ab 79 sin = (struct sockaddr_in *)&rp->rcb_faddr;
91b2c865 80 imp_addr_to_leader(ip, sin->sin_addr.s_addr); /* BRL */
ee787340 81 /* no routing here */
91b2c865
MK
82 ia = in_iaonnetof(in_netof(sin->sin_addr));
83 if (ia)
84 return (impoutput(ia->ia_ifp, m, (struct sockaddr *)sin));
126472ab 85 error = ENETUNREACH;
718d1f9e
BJ
86bad:
87 m_freem(m);
126472ab 88 return (error);
718d1f9e 89}