make rip PR_ADDR again
[unix-history] / usr / src / sys / netinet / raw_ip.c
CommitLineData
94a62155 1/* raw_ip.c 4.2 82/01/24 */
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"
13#include "/usr/include/errno.h"
2a598b25
BJ
14
15/*
94a62155
BJ
16 * Raw interface to IP protocol.
17 */
18
19static struct sockaddr_in ripaddr = { PF_INET };
20static struct sockproto ripproto = { AF_INET };
21
22/*
23 * Setup generic address and protocol structures
24 * for raw_input routine, then pass them along with
25 * mbuf chain.
2a598b25 26 */
2a598b25
BJ
27rip_input(m)
28 struct mbuf *m;
29{
94a62155
BJ
30 register struct ip *ip = mtod(m, struct ip *);
31 struct sockaddr_in sin;
32 struct sockproto sp;
2a598b25
BJ
33
34COUNT(RIP_INPUT);
94a62155
BJ
35 ripproto.sp_protocol = ip->ip_p;
36 ripaddr.sin_addr = ip->ip_dst;
37 raw_input(m, ripproto, ripaddr);
2a598b25
BJ
38}
39
40/*ARGSUSED*/
41rip_ctlinput(m)
42 struct mbuf *m;
43{
2a598b25 44COUNT(RIP_CTLINPUT);
2a598b25
BJ
45}
46
94a62155
BJ
47/*
48 * Generate IP header and pass packet to ip_output.
49 * Tack on options user may have setup with control call.
50 */
51rip_output(m0, so)
52 struct mbuf *m0;
53 struct socket *so;
2a598b25 54{
94a62155
BJ
55 register struct mbuf *m;
56 register struct ip *ip;
57 register int len = 0;
58 register struct rawcb *rp = sotorawcb(so);
2a598b25
BJ
59
60COUNT(RIP_OUTPUT);
94a62155
BJ
61 if (so->so_options & SO_DEBUG)
62 printf("rip_output\n");
63 /*
64 * Calculate data length and get an mbuf
65 * for IP header.
66 */
67 for (m = m0; m; m = m->m_next)
68 len += m->m_len;
69 m = m_get(M_DONTWAIT);
70 if (m == 0) {
71 (void) m_freem(m);
72 return;
73 }
74
75 /*
76 * Fill in IP header as needed.
77 */
78 m->m_off = MMAXOFF - sizeof(struct ip);
79 m->m_len = sizeof(struct ip);
80 m->m_next = m0;
81 ip = mtod(m, struct ip *);
82 ip->ip_p = so->so_proto->pr_protocol;
83 ip->ip_len = sizeof(struct ip) + len;
84 ip->ip_dst =
85 ((struct sockaddr_in *)&rp->rcb_addr)->sin_addr;
86 ip->ip_src =
87 ((struct sockaddr_in *)&so->so_addr)->sin_addr;
88 ip->ip_ttl = MAXTTL;
89printf("ip=<p=%d,len=%d,dst=%x,src=%x>\n",ip->ip_p,ip->ip_len,ip->ip_dst,ip->ip_src);
90 return (ip_output(m, 0));
2a598b25
BJ
91}
92
94a62155
BJ
93/*
94 * Intercept control operations related to
95 * handling of IP options. Otherwise,
96 * just pass things on to the raw_usrreq
97 * routine for setup and tear down of
98 * raw control block data structures.
99 */
2a598b25
BJ
100rip_usrreq(so, req, m, addr)
101 struct socket *so;
102 int req;
103 struct mbuf *m;
104 caddr_t addr;
105{
94a62155 106 register struct rawcb *rp = sotorawcb(so);
2a598b25
BJ
107
108COUNT(RAW_USRREQ);
94a62155
BJ
109 if (rp == 0 && req != PRU_ATTACH)
110 return (EINVAL);
111
112 switch (req) {
113
114 case PRU_CONTROL:
115 return (EOPNOTSUPP);
116 }
117 return (raw_usrreq(so, req, m, addr));
2a598b25 118}