Commit | Line | Data |
---|---|---|
ee787340 | 1 | /* raw_ip.c 4.9 82/03/28 */ |
2a598b25 BJ |
2 | |
3 | #include "../h/param.h" | |
4 | #include "../h/mbuf.h" | |
5 | #include "../h/socket.h" | |
94a62155 | 6 | #include "../h/protosw.h" |
2a598b25 BJ |
7 | #include "../h/socketvar.h" |
8 | #include "../net/in.h" | |
9 | #include "../net/in_systm.h" | |
94a62155 BJ |
10 | #include "../net/ip.h" |
11 | #include "../net/ip_var.h" | |
12 | #include "../net/raw_cb.h" | |
028a20e2 | 13 | #include "../errno.h" |
2a598b25 BJ |
14 | |
15 | /* | |
94a62155 BJ |
16 | * Raw interface to IP protocol. |
17 | */ | |
18 | ||
ee787340 SL |
19 | static struct sockaddr_in ripdst = { AF_INET }; |
20 | static struct sockaddr_in ripsrc = { AF_INET }; | |
21 | static struct sockproto ripproto = { PF_INET }; | |
94a62155 BJ |
22 | |
23 | /* | |
24 | * Setup generic address and protocol structures | |
25 | * for raw_input routine, then pass them along with | |
26 | * mbuf chain. | |
2a598b25 | 27 | */ |
2a598b25 BJ |
28 | rip_input(m) |
29 | struct mbuf *m; | |
30 | { | |
94a62155 | 31 | register struct ip *ip = mtod(m, struct ip *); |
2a598b25 BJ |
32 | |
33 | COUNT(RIP_INPUT); | |
94a62155 | 34 | ripproto.sp_protocol = ip->ip_p; |
faad37c0 SL |
35 | ripdst.sin_addr = ip->ip_dst; |
36 | ripsrc.sin_addr = ip->ip_src; | |
668cc26d SL |
37 | raw_input(m, &ripproto, (struct sockaddr *)&ripdst, |
38 | (struct sockaddr *)&ripsrc); | |
2a598b25 BJ |
39 | } |
40 | ||
94a62155 BJ |
41 | /* |
42 | * Generate IP header and pass packet to ip_output. | |
43 | * Tack on options user may have setup with control call. | |
44 | */ | |
45 | rip_output(m0, so) | |
46 | struct mbuf *m0; | |
47 | struct socket *so; | |
2a598b25 | 48 | { |
94a62155 BJ |
49 | register struct mbuf *m; |
50 | register struct ip *ip; | |
51 | register int len = 0; | |
52 | register struct rawcb *rp = sotorawcb(so); | |
2a598b25 BJ |
53 | |
54 | COUNT(RIP_OUTPUT); | |
94a62155 BJ |
55 | /* |
56 | * Calculate data length and get an mbuf | |
57 | * for IP header. | |
58 | */ | |
59 | for (m = m0; m; m = m->m_next) | |
60 | len += m->m_len; | |
61 | m = m_get(M_DONTWAIT); | |
62 | if (m == 0) { | |
e148ab0a | 63 | m_freem(m); |
220dba7d | 64 | return (0); |
94a62155 BJ |
65 | } |
66 | ||
67 | /* | |
68 | * Fill in IP header as needed. | |
69 | */ | |
70 | m->m_off = MMAXOFF - sizeof(struct ip); | |
71 | m->m_len = sizeof(struct ip); | |
72 | m->m_next = m0; | |
73 | ip = mtod(m, struct ip *); | |
74 | ip->ip_p = so->so_proto->pr_protocol; | |
75 | ip->ip_len = sizeof(struct ip) + len; | |
76 | ip->ip_dst = | |
77 | ((struct sockaddr_in *)&rp->rcb_addr)->sin_addr; | |
78 | ip->ip_src = | |
79 | ((struct sockaddr_in *)&so->so_addr)->sin_addr; | |
80 | ip->ip_ttl = MAXTTL; | |
ee787340 | 81 | return (ip_output(m, (struct mbuf *)0, 0, 1)); |
2a598b25 | 82 | } |