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 55009 1999-12-22 19:13:38Z shin $ |
35 */ 36 |
37#include "opt_inet6.h" 38#include "opt_ipsec.h" 39 |
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 |
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 |
115rip_input(m, off, proto) |
116 struct mbuf *m; |
117 int off, proto; |
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; |
125 LIST_FOREACH(inp, &ripcb, inp_list) { 126#ifdef INET6 127 if ((inp->inp_vflag & INP_IPV4) == 0) |
128 continue; |
129#endif 130 if (inp->inp_ip_p && inp->inp_ip_p != proto) 131 continue; |
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 } |
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, |
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; |
454 s = splnet(); 455 error = in_pcballoc(so, &ripcbinfo, p); 456 splx(s); 457 if (error) 458 return error; |
459 inp = (struct inpcb *)so->so_pcb; |
460 inp->inp_vflag |= INP_IPV4; |
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*/ |
469 return 0; 470} 471 472static int 473rip_detach(struct socket *so) 474{ 475 struct inpcb *inp; 476 --- 186 unchanged lines hidden --- |