1df8bae1dSRodney W. Grimes /* 2df8bae1dSRodney W. Grimes * Copyright (c) 1982, 1986, 1993 3df8bae1dSRodney W. Grimes * The Regents of the University of California. All rights reserved. 4df8bae1dSRodney W. Grimes * 5df8bae1dSRodney W. Grimes * Redistribution and use in source and binary forms, with or without 6df8bae1dSRodney W. Grimes * modification, are permitted provided that the following conditions 7df8bae1dSRodney W. Grimes * are met: 8df8bae1dSRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 9df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer. 10df8bae1dSRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 11df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 12df8bae1dSRodney W. Grimes * documentation and/or other materials provided with the distribution. 13df8bae1dSRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 14df8bae1dSRodney W. Grimes * must display the following acknowledgement: 15df8bae1dSRodney W. Grimes * This product includes software developed by the University of 16df8bae1dSRodney W. Grimes * California, Berkeley and its contributors. 17df8bae1dSRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 18df8bae1dSRodney W. Grimes * may be used to endorse or promote products derived from this software 19df8bae1dSRodney W. Grimes * without specific prior written permission. 20df8bae1dSRodney W. Grimes * 21df8bae1dSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22df8bae1dSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23df8bae1dSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24df8bae1dSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25df8bae1dSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26df8bae1dSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27df8bae1dSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28df8bae1dSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29df8bae1dSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30df8bae1dSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31df8bae1dSRodney W. Grimes * SUCH DAMAGE. 32df8bae1dSRodney W. Grimes * 33425f123eSGarrett Wollman * @(#)in_proto.c 8.2 (Berkeley) 2/9/95 34c3aac50fSPeter Wemm * $FreeBSD$ 35df8bae1dSRodney W. Grimes */ 36df8bae1dSRodney W. Grimes 37fbd1372aSJoerg Wunsch #include "opt_ipdivert.h" 38430df5f4SEivind Eklund #include "opt_ipx.h" 396a800098SYoshinobu Inoue #include "opt_ipsec.h" 406a800098SYoshinobu Inoue #include "opt_inet6.h" 41fbd1372aSJoerg Wunsch 42df8bae1dSRodney W. Grimes #include <sys/param.h> 43748e0b0aSGarrett Wollman #include <sys/kernel.h> 44df8bae1dSRodney W. Grimes #include <sys/socket.h> 45df8bae1dSRodney W. Grimes #include <sys/domain.h> 46dcc3cb75SPoul-Henning Kamp #include <sys/protosw.h> 47ce02431fSDoug Rabson #include <sys/queue.h> 4898163b98SPoul-Henning Kamp #include <sys/sysctl.h> 49df8bae1dSRodney W. Grimes 50df8bae1dSRodney W. Grimes #include <net/if.h> 51df8bae1dSRodney W. Grimes #include <net/route.h> 52df8bae1dSRodney W. Grimes 53df8bae1dSRodney W. Grimes #include <netinet/in.h> 54df8bae1dSRodney W. Grimes #include <netinet/in_systm.h> 55df8bae1dSRodney W. Grimes #include <netinet/ip.h> 56df8bae1dSRodney W. Grimes #include <netinet/ip_var.h> 57df8bae1dSRodney W. Grimes #include <netinet/ip_icmp.h> 58df8bae1dSRodney W. Grimes #include <netinet/igmp_var.h> 59df8bae1dSRodney W. Grimes #include <netinet/tcp.h> 60df8bae1dSRodney W. Grimes #include <netinet/tcp_timer.h> 61df8bae1dSRodney W. Grimes #include <netinet/tcp_var.h> 62df8bae1dSRodney W. Grimes #include <netinet/udp.h> 63df8bae1dSRodney W. Grimes #include <netinet/udp_var.h> 646a800098SYoshinobu Inoue 656a800098SYoshinobu Inoue #include <netinet/ipprotosw.h> 666a800098SYoshinobu Inoue 67df8bae1dSRodney W. Grimes /* 68df8bae1dSRodney W. Grimes * TCP/IP protocol family: IP, ICMP, UDP, TCP. 69df8bae1dSRodney W. Grimes */ 70df8bae1dSRodney W. Grimes 716a800098SYoshinobu Inoue #ifdef IPSEC 726a800098SYoshinobu Inoue #include <netinet6/ipsec.h> 736a800098SYoshinobu Inoue #include <netinet6/ah.h> 746a800098SYoshinobu Inoue #ifdef IPSEC_ESP 756a800098SYoshinobu Inoue #include <netinet6/esp.h> 766a800098SYoshinobu Inoue #endif 776a800098SYoshinobu Inoue #endif /* IPSEC */ 786a800098SYoshinobu Inoue 79cfa1ca9dSYoshinobu Inoue #include "gif.h" 80cfa1ca9dSYoshinobu Inoue #if NGIF > 0 81cfa1ca9dSYoshinobu Inoue #include <netinet/in_gif.h> 82cfa1ca9dSYoshinobu Inoue #endif 83cfa1ca9dSYoshinobu Inoue 84cc6a66f2SJulian Elischer #ifdef IPXIP 85ce7609a4SBruce Evans #include <netipx/ipx_ip.h> 86cc6a66f2SJulian Elischer #endif 87cc6a66f2SJulian Elischer 88df8bae1dSRodney W. Grimes #ifdef NSIP 89ce7609a4SBruce Evans #include <netns/ns.h> 90ce7609a4SBruce Evans #include <netns/ns_if.h> 91df8bae1dSRodney W. Grimes #endif 92df8bae1dSRodney W. Grimes 93df8bae1dSRodney W. Grimes extern struct domain inetdomain; 94a29f300eSGarrett Wollman static struct pr_usrreqs nousrreqs; 95df8bae1dSRodney W. Grimes 966a800098SYoshinobu Inoue struct ipprotosw inetsw[] = { 97df8bae1dSRodney W. Grimes { 0, &inetdomain, 0, 0, 98dbe4b3f0SGarrett Wollman 0, 0, 0, 0, 99df8bae1dSRodney W. Grimes 0, 100a29f300eSGarrett Wollman ip_init, 0, ip_slowtimo, ip_drain, 101a29f300eSGarrett Wollman &nousrreqs 102df8bae1dSRodney W. Grimes }, 103df8bae1dSRodney W. Grimes { SOCK_DGRAM, &inetdomain, IPPROTO_UDP, PR_ATOMIC|PR_ADDR, 104df8bae1dSRodney W. Grimes udp_input, 0, udp_ctlinput, ip_ctloutput, 105d0390e05SGarrett Wollman 0, 106d0390e05SGarrett Wollman udp_init, 0, 0, 0, 107d0390e05SGarrett Wollman &udp_usrreqs 108df8bae1dSRodney W. Grimes }, 109999f1343SGarrett Wollman { SOCK_STREAM, &inetdomain, IPPROTO_TCP, 110999f1343SGarrett Wollman PR_CONNREQUIRED|PR_IMPLOPCL|PR_WANTRCVD, 111df8bae1dSRodney W. Grimes tcp_input, 0, tcp_ctlinput, tcp_ctloutput, 1122c37256eSGarrett Wollman 0, 1139b8b58e0SJonathan Lemon tcp_init, 0, tcp_slowtimo, tcp_drain, 1142c37256eSGarrett Wollman &tcp_usrreqs 115df8bae1dSRodney W. Grimes }, 116df8bae1dSRodney W. Grimes { SOCK_RAW, &inetdomain, IPPROTO_RAW, PR_ATOMIC|PR_ADDR, 11739191c8eSGarrett Wollman rip_input, 0, rip_ctlinput, rip_ctloutput, 118117bcae7SGarrett Wollman 0, 119df8bae1dSRodney W. Grimes 0, 0, 0, 0, 120117bcae7SGarrett Wollman &rip_usrreqs 121df8bae1dSRodney W. Grimes }, 122df8bae1dSRodney W. Grimes { SOCK_RAW, &inetdomain, IPPROTO_ICMP, PR_ATOMIC|PR_ADDR, 123b1e8a2c5SGary Palmer icmp_input, 0, 0, rip_ctloutput, 124117bcae7SGarrett Wollman 0, 125117bcae7SGarrett Wollman 0, 0, 0, 0, 126117bcae7SGarrett Wollman &rip_usrreqs 127df8bae1dSRodney W. Grimes }, 128df8bae1dSRodney W. Grimes { SOCK_RAW, &inetdomain, IPPROTO_IGMP, PR_ATOMIC|PR_ADDR, 129b1e8a2c5SGary Palmer igmp_input, 0, 0, rip_ctloutput, 130117bcae7SGarrett Wollman 0, 131117bcae7SGarrett Wollman igmp_init, igmp_fasttimo, igmp_slowtimo, 0, 132117bcae7SGarrett Wollman &rip_usrreqs 133df8bae1dSRodney W. Grimes }, 134f0068c4aSGarrett Wollman { SOCK_RAW, &inetdomain, IPPROTO_RSVP, PR_ATOMIC|PR_ADDR, 135b1e8a2c5SGary Palmer rsvp_input, 0, 0, rip_ctloutput, 136117bcae7SGarrett Wollman 0, 137f0068c4aSGarrett Wollman 0, 0, 0, 0, 138117bcae7SGarrett Wollman &rip_usrreqs 139f0068c4aSGarrett Wollman }, 1406a800098SYoshinobu Inoue #ifdef IPSEC 1416a800098SYoshinobu Inoue { SOCK_RAW, &inetdomain, IPPROTO_AH, PR_ATOMIC|PR_ADDR, 1426a800098SYoshinobu Inoue ah4_input, 0, 0, 0, 1436a800098SYoshinobu Inoue 0, 1446a800098SYoshinobu Inoue 0, 0, 0, 0, 1456a800098SYoshinobu Inoue &nousrreqs 1466a800098SYoshinobu Inoue }, 1476a800098SYoshinobu Inoue #ifdef IPSEC_ESP 1486a800098SYoshinobu Inoue { SOCK_RAW, &inetdomain, IPPROTO_ESP, PR_ATOMIC|PR_ADDR, 1496a800098SYoshinobu Inoue esp4_input, 0, 0, 0, 1506a800098SYoshinobu Inoue 0, 1516a800098SYoshinobu Inoue 0, 0, 0, 0, 1526a800098SYoshinobu Inoue &nousrreqs 1536a800098SYoshinobu Inoue }, 1546a800098SYoshinobu Inoue #endif 1556a800098SYoshinobu Inoue #endif /* IPSEC */ 156cfa1ca9dSYoshinobu Inoue #if NGIF > 0 157cfa1ca9dSYoshinobu Inoue { SOCK_RAW, &inetdomain, IPPROTO_IPV4, PR_ATOMIC|PR_ADDR, 158cfa1ca9dSYoshinobu Inoue in_gif_input, 0, 0, 0, 159cfa1ca9dSYoshinobu Inoue 0, 160cfa1ca9dSYoshinobu Inoue 0, 0, 0, 0, 161cfa1ca9dSYoshinobu Inoue &nousrreqs 162cfa1ca9dSYoshinobu Inoue }, 163cfa1ca9dSYoshinobu Inoue # ifdef INET6 164cfa1ca9dSYoshinobu Inoue { SOCK_RAW, &inetdomain, IPPROTO_IPV6, PR_ATOMIC|PR_ADDR, 165cfa1ca9dSYoshinobu Inoue in_gif_input, 0, 0, 0, 166cfa1ca9dSYoshinobu Inoue 0, 167cfa1ca9dSYoshinobu Inoue 0, 0, 0, 0, 168cfa1ca9dSYoshinobu Inoue &nousrreqs 169cfa1ca9dSYoshinobu Inoue }, 170cfa1ca9dSYoshinobu Inoue #endif 171cfa1ca9dSYoshinobu Inoue #else /*NGIF*/ 172fba14c2eSGarrett Wollman { SOCK_RAW, &inetdomain, IPPROTO_IPIP, PR_ATOMIC|PR_ADDR, 173b1e8a2c5SGary Palmer ipip_input, 0, 0, rip_ctloutput, 174117bcae7SGarrett Wollman 0, 175f0068c4aSGarrett Wollman 0, 0, 0, 0, 176117bcae7SGarrett Wollman &rip_usrreqs 177f0068c4aSGarrett Wollman }, 178cfa1ca9dSYoshinobu Inoue #endif /*NGIF*/ 17993e0e116SJulian Elischer #ifdef IPDIVERT 18093e0e116SJulian Elischer { SOCK_RAW, &inetdomain, IPPROTO_DIVERT, PR_ATOMIC|PR_ADDR, 18193e0e116SJulian Elischer div_input, 0, 0, ip_ctloutput, 18277d1915bSPeter Wemm 0, 18393e0e116SJulian Elischer div_init, 0, 0, 0, 18477d1915bSPeter Wemm &div_usrreqs, 18593e0e116SJulian Elischer }, 18693e0e116SJulian Elischer #endif 187df8bae1dSRodney W. Grimes #ifdef TPIP 188df8bae1dSRodney W. Grimes { SOCK_SEQPACKET,&inetdomain, IPPROTO_TP, PR_CONNREQUIRED|PR_WANTRCVD, 189df8bae1dSRodney W. Grimes tpip_input, 0, tpip_ctlinput, tp_ctloutput, 190df8bae1dSRodney W. Grimes tp_usrreq, 191df8bae1dSRodney W. Grimes tp_init, 0, tp_slowtimo, tp_drain, 192df8bae1dSRodney W. Grimes }, 193df8bae1dSRodney W. Grimes #endif 194df8bae1dSRodney W. Grimes /* EON (ISO CLNL over IP) */ 195df8bae1dSRodney W. Grimes #ifdef EON 196df8bae1dSRodney W. Grimes { SOCK_RAW, &inetdomain, IPPROTO_EON, 0, 197df8bae1dSRodney W. Grimes eoninput, 0, eonctlinput, 0, 198df8bae1dSRodney W. Grimes 0, 199df8bae1dSRodney W. Grimes eonprotoinit, 0, 0, 0, 200df8bae1dSRodney W. Grimes }, 201df8bae1dSRodney W. Grimes #endif 202cc6a66f2SJulian Elischer #ifdef IPXIP 203cc6a66f2SJulian Elischer { SOCK_RAW, &inetdomain, IPPROTO_IDP, PR_ATOMIC|PR_ADDR, 204b1e8a2c5SGary Palmer ipxip_input, 0, ipxip_ctlinput, 0, 205117bcae7SGarrett Wollman 0, 206cc6a66f2SJulian Elischer 0, 0, 0, 0, 207117bcae7SGarrett Wollman &rip_usrreqs 208cc6a66f2SJulian Elischer }, 209cc6a66f2SJulian Elischer #endif 210df8bae1dSRodney W. Grimes #ifdef NSIP 211df8bae1dSRodney W. Grimes { SOCK_RAW, &inetdomain, IPPROTO_IDP, PR_ATOMIC|PR_ADDR, 212d7e74838SBill Fenner idpip_input, 0, nsip_ctlinput, 0, 213117bcae7SGarrett Wollman 0, 214df8bae1dSRodney W. Grimes 0, 0, 0, 0, 215117bcae7SGarrett Wollman &rip_usrreqs 216df8bae1dSRodney W. Grimes }, 217df8bae1dSRodney W. Grimes #endif 218df8bae1dSRodney W. Grimes /* raw wildcard */ 219df8bae1dSRodney W. Grimes { SOCK_RAW, &inetdomain, 0, PR_ATOMIC|PR_ADDR, 220b1e8a2c5SGary Palmer rip_input, 0, 0, rip_ctloutput, 221117bcae7SGarrett Wollman 0, 222df8bae1dSRodney W. Grimes rip_init, 0, 0, 0, 223117bcae7SGarrett Wollman &rip_usrreqs 224df8bae1dSRodney W. Grimes }, 225df8bae1dSRodney W. Grimes }; 226df8bae1dSRodney W. Grimes 227514ede09SBruce Evans extern int in_inithead __P((void **, int)); 2285c2dae8eSGarrett Wollman 229df8bae1dSRodney W. Grimes struct domain inetdomain = 230df8bae1dSRodney W. Grimes { AF_INET, "internet", 0, 0, 0, 2316a800098SYoshinobu Inoue (struct protosw *)inetsw, 2326a800098SYoshinobu Inoue (struct protosw *)&inetsw[sizeof(inetsw)/sizeof(inetsw[0])], 0, 2335c2dae8eSGarrett Wollman in_inithead, 32, sizeof(struct sockaddr_in) 2345c2dae8eSGarrett Wollman }; 235df8bae1dSRodney W. Grimes 236748e0b0aSGarrett Wollman DOMAIN_SET(inet); 237748e0b0aSGarrett Wollman 238602d513cSGarrett Wollman SYSCTL_NODE(_net, PF_INET, inet, CTLFLAG_RW, 0, 239602d513cSGarrett Wollman "Internet Family"); 24098163b98SPoul-Henning Kamp 24198163b98SPoul-Henning Kamp SYSCTL_NODE(_net_inet, IPPROTO_IP, ip, CTLFLAG_RW, 0, "IP"); 24298163b98SPoul-Henning Kamp SYSCTL_NODE(_net_inet, IPPROTO_ICMP, icmp, CTLFLAG_RW, 0, "ICMP"); 24398163b98SPoul-Henning Kamp SYSCTL_NODE(_net_inet, IPPROTO_UDP, udp, CTLFLAG_RW, 0, "UDP"); 24498163b98SPoul-Henning Kamp SYSCTL_NODE(_net_inet, IPPROTO_TCP, tcp, CTLFLAG_RW, 0, "TCP"); 24598163b98SPoul-Henning Kamp SYSCTL_NODE(_net_inet, IPPROTO_IGMP, igmp, CTLFLAG_RW, 0, "IGMP"); 2466a800098SYoshinobu Inoue #ifdef IPSEC 2476a800098SYoshinobu Inoue SYSCTL_NODE(_net_inet, IPPROTO_AH, ipsec, CTLFLAG_RW, 0, "IPSEC"); 2486a800098SYoshinobu Inoue #endif /* IPSEC */ 249117bcae7SGarrett Wollman SYSCTL_NODE(_net_inet, IPPROTO_RAW, raw, CTLFLAG_RW, 0, "RAW"); 25093e0e116SJulian Elischer #ifdef IPDIVERT 25193e0e116SJulian Elischer SYSCTL_NODE(_net_inet, IPPROTO_DIVERT, div, CTLFLAG_RW, 0, "DIVERT"); 25293e0e116SJulian Elischer #endif 25398163b98SPoul-Henning Kamp 254