raw_ip.c (54799) | raw_ip.c (55009) |
---|---|
1/* 2 * Copyright (c) 1982, 1986, 1988, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)raw_ip.c 8.7 (Berkeley) 5/15/95 | 1/* 2 * Copyright (c) 1982, 1986, 1988, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)raw_ip.c 8.7 (Berkeley) 5/15/95 |
34 * $FreeBSD: head/sys/netinet/raw_ip.c 54799 1999-12-19 01:55:37Z green $ | 34 * $FreeBSD: head/sys/netinet/raw_ip.c 55009 1999-12-22 19:13:38Z shin $ |
35 */ 36 | 35 */ 36 |
37#include "opt_inet6.h" 38#include "opt_ipsec.h" 39 |
|
37#include <sys/param.h> 38#include <sys/systm.h> 39#include <sys/kernel.h> 40#include <sys/malloc.h> 41#include <sys/mbuf.h> 42#include <sys/proc.h> 43#include <sys/protosw.h> 44#include <sys/socket.h> --- 11 unchanged lines hidden (view full) --- 56#include <netinet/ip.h> 57#include <netinet/in_pcb.h> 58#include <netinet/in_var.h> 59#include <netinet/ip_var.h> 60#include <netinet/ip_mroute.h> 61 62#include <netinet/ip_fw.h> 63 | 40#include <sys/param.h> 41#include <sys/systm.h> 42#include <sys/kernel.h> 43#include <sys/malloc.h> 44#include <sys/mbuf.h> 45#include <sys/proc.h> 46#include <sys/protosw.h> 47#include <sys/socket.h> --- 11 unchanged lines hidden (view full) --- 59#include <netinet/ip.h> 60#include <netinet/in_pcb.h> 61#include <netinet/in_var.h> 62#include <netinet/ip_var.h> 63#include <netinet/ip_mroute.h> 64 65#include <netinet/ip_fw.h> 66 |
67#ifdef IPSEC 68#include <netinet6/ipsec.h> 69#endif /*IPSEC*/ 70 |
|
64#include "opt_ipdn.h" 65#ifdef DUMMYNET 66#include <netinet/ip_dummynet.h> 67#endif 68 69struct inpcbhead ripcb; 70struct inpcbinfo ripcbinfo; 71 --- 28 unchanged lines hidden (view full) --- 100 101static struct sockaddr_in ripsrc = { sizeof(ripsrc), AF_INET }; 102/* 103 * Setup generic address and protocol structures 104 * for raw_input routine, then pass them along with 105 * mbuf chain. 106 */ 107void | 71#include "opt_ipdn.h" 72#ifdef DUMMYNET 73#include <netinet/ip_dummynet.h> 74#endif 75 76struct inpcbhead ripcb; 77struct inpcbinfo ripcbinfo; 78 --- 28 unchanged lines hidden (view full) --- 107 108static struct sockaddr_in ripsrc = { sizeof(ripsrc), AF_INET }; 109/* 110 * Setup generic address and protocol structures 111 * for raw_input routine, then pass them along with 112 * mbuf chain. 113 */ 114void |
108rip_input(m, iphlen) | 115rip_input(m, off, proto) |
109 struct mbuf *m; | 116 struct mbuf *m; |
110 int iphlen; | 117 int off, proto; |
111{ 112 register struct ip *ip = mtod(m, struct ip *); 113 register struct inpcb *inp; 114 struct inpcb *last = 0; 115 struct mbuf *opts = 0; 116 117 ripsrc.sin_addr = ip->ip_src; | 118{ 119 register struct ip *ip = mtod(m, struct ip *); 120 register struct inpcb *inp; 121 struct inpcb *last = 0; 122 struct mbuf *opts = 0; 123 124 ripsrc.sin_addr = ip->ip_src; |
118 for (inp = ripcb.lh_first; inp != NULL; inp = inp->inp_list.le_next) { 119 if (inp->inp_ip_p && inp->inp_ip_p != ip->ip_p) | 125 LIST_FOREACH(inp, &ripcb, inp_list) { 126#ifdef INET6 127 if ((inp->inp_vflag & INP_IPV4) == 0) |
120 continue; | 128 continue; |
129#endif 130 if (inp->inp_ip_p && inp->inp_ip_p != proto) 131 continue; |
|
121 if (inp->inp_laddr.s_addr && 122 inp->inp_laddr.s_addr != ip->ip_dst.s_addr) 123 continue; 124 if (inp->inp_faddr.s_addr && 125 inp->inp_faddr.s_addr != ip->ip_src.s_addr) 126 continue; 127 if (last) { 128 struct mbuf *n = m_copy(m, 0, (int)M_COPYALL); --- 81 unchanged lines hidden (view full) --- 210 return EINVAL; 211 } 212 if (ip->ip_id == 0) 213 ip->ip_id = htons(ip_id++); 214 /* XXX prevent ip_output from overwriting header fields */ 215 flags |= IP_RAWOUTPUT; 216 ipstat.ips_rawout++; 217 } | 132 if (inp->inp_laddr.s_addr && 133 inp->inp_laddr.s_addr != ip->ip_dst.s_addr) 134 continue; 135 if (inp->inp_faddr.s_addr && 136 inp->inp_faddr.s_addr != ip->ip_src.s_addr) 137 continue; 138 if (last) { 139 struct mbuf *n = m_copy(m, 0, (int)M_COPYALL); --- 81 unchanged lines hidden (view full) --- 221 return EINVAL; 222 } 223 if (ip->ip_id == 0) 224 ip->ip_id = htons(ip_id++); 225 /* XXX prevent ip_output from overwriting header fields */ 226 flags |= IP_RAWOUTPUT; 227 ipstat.ips_rawout++; 228 } |
218 return (ip_output(m, inp->inp_options, &inp->inp_route, flags, | 229 230#ifdef IPSEC 231 m->m_pkthdr.rcvif = (struct ifnet *)so; /*XXX*/ 232#endif /*IPSEC*/ 233 234 return (ip_output(m, inp->inp_options, &inp->inp_route, 235 flags | IP_SOCKINMRCVIF, |
219 inp->inp_moptions)); 220} 221 222/* 223 * Raw IP socket option processing. 224 */ 225int 226rip_ctloutput(so, sopt) --- 199 unchanged lines hidden (view full) --- 426 int error, s; 427 428 inp = sotoinpcb(so); 429 if (inp) 430 panic("rip_attach"); 431 if (p && (error = suser(p)) != 0) 432 return error; 433 | 236 inp->inp_moptions)); 237} 238 239/* 240 * Raw IP socket option processing. 241 */ 242int 243rip_ctloutput(so, sopt) --- 199 unchanged lines hidden (view full) --- 443 int error, s; 444 445 inp = sotoinpcb(so); 446 if (inp) 447 panic("rip_attach"); 448 if (p && (error = suser(p)) != 0) 449 return error; 450 |
451 error = soreserve(so, rip_sendspace, rip_recvspace); 452 if (error) 453 return error; |
|
434 s = splnet(); 435 error = in_pcballoc(so, &ripcbinfo, p); 436 splx(s); 437 if (error) 438 return error; | 454 s = splnet(); 455 error = in_pcballoc(so, &ripcbinfo, p); 456 splx(s); 457 if (error) 458 return error; |
439 error = soreserve(so, rip_sendspace, rip_recvspace); 440 if (error) 441 return error; | |
442 inp = (struct inpcb *)so->so_pcb; | 459 inp = (struct inpcb *)so->so_pcb; |
460 inp->inp_vflag |= INP_IPV4; |
|
443 inp->inp_ip_p = proto; | 461 inp->inp_ip_p = proto; |
462#ifdef IPSEC 463 error = ipsec_init_policy(so, &inp->inp_sp); 464 if (error != 0) { 465 in_pcbdetach(inp); 466 return error; 467 } 468#endif /*IPSEC*/ |
|
444 return 0; 445} 446 447static int 448rip_detach(struct socket *so) 449{ 450 struct inpcb *inp; 451 --- 186 unchanged lines hidden --- | 469 return 0; 470} 471 472static int 473rip_detach(struct socket *so) 474{ 475 struct inpcb *inp; 476 --- 186 unchanged lines hidden --- |