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