[BACK]Return to ip_input.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / netinet

Annotation of src/sys/netinet/ip_input.c, Revision 1.309

1.309   ! pooka       1: /*     $NetBSD: ip_input.c,v 1.308 2013/06/29 21:06:58 rmind Exp $     */
1.89      itojun      2:
                      3: /*
                      4:  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
                      5:  * All rights reserved.
1.152     itojun      6:  *
1.89      itojun      7:  * Redistribution and use in source and binary forms, with or without
                      8:  * modification, are permitted provided that the following conditions
                      9:  * are met:
                     10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer.
                     12:  * 2. Redistributions in binary form must reproduce the above copyright
                     13:  *    notice, this list of conditions and the following disclaimer in the
                     14:  *    documentation and/or other materials provided with the distribution.
                     15:  * 3. Neither the name of the project nor the names of its contributors
                     16:  *    may be used to endorse or promote products derived from this software
                     17:  *    without specific prior written permission.
1.152     itojun     18:  *
1.89      itojun     19:  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
                     20:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     21:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     22:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
                     23:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     24:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     25:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     26:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     27:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     28:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     29:  * SUCH DAMAGE.
                     30:  */
1.76      thorpej    31:
                     32: /*-
                     33:  * Copyright (c) 1998 The NetBSD Foundation, Inc.
                     34:  * All rights reserved.
                     35:  *
                     36:  * This code is derived from software contributed to The NetBSD Foundation
                     37:  * by Public Access Networks Corporation ("Panix").  It was developed under
                     38:  * contract to Panix by Eric Haszlakiewicz and Thor Lancelot Simon.
                     39:  *
                     40:  * Redistribution and use in source and binary forms, with or without
                     41:  * modification, are permitted provided that the following conditions
                     42:  * are met:
                     43:  * 1. Redistributions of source code must retain the above copyright
                     44:  *    notice, this list of conditions and the following disclaimer.
                     45:  * 2. Redistributions in binary form must reproduce the above copyright
                     46:  *    notice, this list of conditions and the following disclaimer in the
                     47:  *    documentation and/or other materials provided with the distribution.
                     48:  *
                     49:  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
                     50:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     51:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     52:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
                     53:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     54:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     55:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     56:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     57:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     58:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     59:  * POSSIBILITY OF SUCH DAMAGE.
                     60:  */
1.14      cgd        61:
1.1       cgd        62: /*
1.13      mycroft    63:  * Copyright (c) 1982, 1986, 1988, 1993
                     64:  *     The Regents of the University of California.  All rights reserved.
1.1       cgd        65:  *
                     66:  * Redistribution and use in source and binary forms, with or without
                     67:  * modification, are permitted provided that the following conditions
                     68:  * are met:
                     69:  * 1. Redistributions of source code must retain the above copyright
                     70:  *    notice, this list of conditions and the following disclaimer.
                     71:  * 2. Redistributions in binary form must reproduce the above copyright
                     72:  *    notice, this list of conditions and the following disclaimer in the
                     73:  *    documentation and/or other materials provided with the distribution.
1.172     agc        74:  * 3. Neither the name of the University nor the names of its contributors
1.1       cgd        75:  *    may be used to endorse or promote products derived from this software
                     76:  *    without specific prior written permission.
                     77:  *
                     78:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     79:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     80:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     81:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     82:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     83:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     84:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     85:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     86:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     87:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     88:  * SUCH DAMAGE.
                     89:  *
1.14      cgd        90:  *     @(#)ip_input.c  8.2 (Berkeley) 1/4/94
1.1       cgd        91:  */
1.141     lukem      92:
                     93: #include <sys/cdefs.h>
1.309   ! pooka      94: __KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.308 2013/06/29 21:06:58 rmind Exp $");
1.55      scottr     95:
1.184     jonathan   96: #include "opt_inet.h"
1.278     christos   97: #include "opt_compat_netbsd.h"
1.62      matt       98: #include "opt_gateway.h"
1.91      thorpej    99: #include "opt_ipsec.h"
1.55      scottr    100: #include "opt_mrouting.h"
1.167     martin    101: #include "opt_mbuftrace.h"
1.135     thorpej   102: #include "opt_inet_csum.h"
1.1       cgd       103:
1.5       mycroft   104: #include <sys/param.h>
                    105: #include <sys/systm.h>
                    106: #include <sys/mbuf.h>
                    107: #include <sys/domain.h>
                    108: #include <sys/protosw.h>
                    109: #include <sys/socket.h>
1.44      thorpej   110: #include <sys/socketvar.h>
1.5       mycroft   111: #include <sys/errno.h>
                    112: #include <sys/time.h>
                    113: #include <sys/kernel.h>
1.72      thorpej   114: #include <sys/pool.h>
1.28      christos  115: #include <sys/sysctl.h>
1.230     elad      116: #include <sys/kauth.h>
1.1       cgd       117:
1.5       mycroft   118: #include <net/if.h>
1.44      thorpej   119: #include <net/if_dl.h>
1.5       mycroft   120: #include <net/route.h>
1.45      mrg       121: #include <net/pfil.h>
1.1       cgd       122:
1.5       mycroft   123: #include <netinet/in.h>
                    124: #include <netinet/in_systm.h>
                    125: #include <netinet/ip.h>
                    126: #include <netinet/in_pcb.h>
1.215     yamt      127: #include <netinet/in_proto.h>
1.5       mycroft   128: #include <netinet/in_var.h>
                    129: #include <netinet/ip_var.h>
1.266     thorpej   130: #include <netinet/ip_private.h>
1.5       mycroft   131: #include <netinet/ip_icmp.h>
1.89      itojun    132: /* just for gif_ttl */
                    133: #include <netinet/in_gif.h>
                    134: #include "gif.h"
1.144     martin    135: #include <net/if_gre.h>
                    136: #include "gre.h"
1.111     jdolecek  137:
                    138: #ifdef MROUTING
                    139: #include <netinet/ip_mroute.h>
                    140: #endif
1.302     christos  141: #include <netinet/portalgo.h>
1.89      itojun    142:
1.304     christos  143: #ifdef IPSEC
1.173     jonathan  144: #include <netipsec/ipsec.h>
1.305     rmind     145: #endif
1.44      thorpej   146:
1.1       cgd       147: #ifndef        IPFORWARDING
                    148: #ifdef GATEWAY
                    149: #define        IPFORWARDING    1       /* forward IP packets not for us */
                    150: #else /* GATEWAY */
                    151: #define        IPFORWARDING    0       /* don't forward IP packets not for us */
                    152: #endif /* GATEWAY */
                    153: #endif /* IPFORWARDING */
                    154: #ifndef        IPSENDREDIRECTS
                    155: #define        IPSENDREDIRECTS 1
                    156: #endif
1.26      thorpej   157: #ifndef IPFORWSRCRT
1.47      cjs       158: #define        IPFORWSRCRT     1       /* forward source-routed packets */
                    159: #endif
                    160: #ifndef IPALLOWSRCRT
1.48      mrg       161: #define        IPALLOWSRCRT    1       /* allow source-routed packets */
1.26      thorpej   162: #endif
1.53      kml       163: #ifndef IPMTUDISC
1.153     itojun    164: #define IPMTUDISC      1
1.53      kml       165: #endif
1.60      kml       166: #ifndef IPMTUDISCTIMEOUT
1.61      kml       167: #define IPMTUDISCTIMEOUT (10 * 60)     /* as per RFC 1191 */
1.60      kml       168: #endif
1.53      kml       169:
1.278     christos  170: #ifdef COMPAT_50
                    171: #include <compat/sys/time.h>
                    172: #include <compat/sys/socket.h>
                    173: #endif
                    174:
1.27      thorpej   175: /*
                    176:  * Note: DIRECTED_BROADCAST is handled this way so that previous
                    177:  * configuration using this option will Just Work.
                    178:  */
                    179: #ifndef IPDIRECTEDBCAST
                    180: #ifdef DIRECTED_BROADCAST
                    181: #define IPDIRECTEDBCAST        1
                    182: #else
                    183: #define        IPDIRECTEDBCAST 0
                    184: #endif /* DIRECTED_BROADCAST */
                    185: #endif /* IPDIRECTEDBCAST */
1.1       cgd       186: int    ipforwarding = IPFORWARDING;
                    187: int    ipsendredirects = IPSENDREDIRECTS;
1.13      mycroft   188: int    ip_defttl = IPDEFTTL;
1.26      thorpej   189: int    ip_forwsrcrt = IPFORWSRCRT;
1.27      thorpej   190: int    ip_directedbcast = IPDIRECTEDBCAST;
1.47      cjs       191: int    ip_allowsrcrt = IPALLOWSRCRT;
1.53      kml       192: int    ip_mtudisc = IPMTUDISC;
1.156     itojun    193: int    ip_mtudisc_timeout = IPMTUDISCTIMEOUT;
1.1       cgd       194: #ifdef DIAGNOSTIC
                    195: int    ipprintfs = 0;
                    196: #endif
1.184     jonathan  197:
                    198: int    ip_do_randomid = 0;
                    199:
1.165     christos  200: /*
                    201:  * XXX - Setting ip_checkinterface mostly implements the receive side of
                    202:  * the Strong ES model described in RFC 1122, but since the routing table
                    203:  * and transmit implementation do not implement the Strong ES model,
                    204:  * setting this to 1 results in an odd hybrid.
                    205:  *
                    206:  * XXX - ip_checkinterface currently must be disabled if you use ipnat
                    207:  * to translate the destination address to another local interface.
                    208:  *
                    209:  * XXX - ip_checkinterface must be disabled if you add IP aliases
                    210:  * to the loopback interface instead of the interface where the
                    211:  * packets for those addresses are received.
                    212:  */
                    213: int    ip_checkinterface = 0;
                    214:
1.1       cgd       215:
1.60      kml       216: struct rttimer_queue *ip_mtudisc_timeout_q = NULL;
                    217:
1.150     matt      218: u_long in_ifaddrhash;                          /* size of hash table - 1 */
                    219: int    in_ifaddrentries;                       /* total number of addrs */
1.212     perry     220: struct in_ifaddrhead in_ifaddrhead;
1.57      tls       221: struct in_ifaddrhashhead *in_ifaddrhashtbl;
1.166     matt      222: u_long in_multihash;                           /* size of hash table - 1 */
                    223: int    in_multientries;                        /* total number of addrs */
                    224: struct in_multihashhead *in_multihashtbl;
1.13      mycroft   225: struct ifqueue ipintrq;
1.286     tls       226:
1.291     rmind     227: ipid_state_t *         ip_ids;
1.183     jonathan  228: uint16_t ip_id;
1.75      thorpej   229:
1.266     thorpej   230: percpu_t *ipstat_percpu;
                    231:
1.308     rmind     232: pfil_head_t *inet_pfil_hook;
1.121     thorpej   233:
1.275     pooka     234: struct pool inmulti_pool;
1.72      thorpej   235:
1.135     thorpej   236: #ifdef INET_CSUM_COUNTERS
                    237: #include <sys/device.h>
                    238:
                    239: struct evcnt ip_hwcsum_bad = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,
                    240:     NULL, "inet", "hwcsum bad");
                    241: struct evcnt ip_hwcsum_ok = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,
                    242:     NULL, "inet", "hwcsum ok");
                    243: struct evcnt ip_swcsum = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,
                    244:     NULL, "inet", "swcsum");
                    245:
                    246: #define        INET_CSUM_COUNTER_INCR(ev)      (ev)->ev_count++
                    247:
1.201     matt      248: EVCNT_ATTACH_STATIC(ip_hwcsum_bad);
                    249: EVCNT_ATTACH_STATIC(ip_hwcsum_ok);
                    250: EVCNT_ATTACH_STATIC(ip_swcsum);
                    251:
1.135     thorpej   252: #else
                    253:
                    254: #define        INET_CSUM_COUNTER_INCR(ev)      /* nothing */
                    255:
                    256: #endif /* INET_CSUM_COUNTERS */
                    257:
1.1       cgd       258: /*
                    259:  * We need to save the IP options in case a protocol wants to respond
                    260:  * to an incoming packet over the same route if the packet got here
                    261:  * using IP source routing.  This allows connection establishment and
                    262:  * maintenance when the remote end is on a network that is not known
                    263:  * to us.
                    264:  */
                    265: int    ip_nhops = 0;
                    266: static struct ip_srcrt {
                    267:        struct  in_addr dst;                    /* final destination */
                    268:        char    nop;                            /* one NOP to align */
                    269:        char    srcopt[IPOPT_OFFSET + 1];       /* OPTVAL, OLEN and OFFSET */
                    270:        struct  in_addr route[MAX_IPOPTLEN/sizeof(struct in_addr)];
                    271: } ip_srcrt;
                    272:
1.295     dyoung    273: static int ip_drainwanted;
                    274:
1.210     perry     275: static void save_rte(u_char *, struct in_addr);
1.35      mycroft   276:
1.164     matt      277: #ifdef MBUFTRACE
1.234     dogcow    278: struct mowner ip_rx_mowner = MOWNER_INIT("internet", "rx");
                    279: struct mowner ip_tx_mowner = MOWNER_INIT("internet", "tx");
1.164     matt      280: #endif
                    281:
1.284     pooka     282: static void sysctl_net_inet_ip_setup(struct sysctllog **);
                    283:
1.1       cgd       284: /*
                    285:  * IP initialization: fill in IP protocol switch table.
                    286:  * All protocols not implemented in kernel go to raw IP protocol handler.
                    287:  */
1.8       mycroft   288: void
1.211     perry     289: ip_init(void)
1.1       cgd       290: {
1.199     matt      291:        const struct protosw *pr;
1.109     augustss  292:        int i;
1.1       cgd       293:
1.284     pooka     294:        sysctl_net_inet_ip_setup(NULL);
                    295:
1.275     pooka     296:        pool_init(&inmulti_pool, sizeof(struct in_multi), 0, 0, 0, "inmltpl",
                    297:            NULL, IPL_SOFTNET);
                    298:
1.1       cgd       299:        pr = pffindproto(PF_INET, IPPROTO_RAW, SOCK_RAW);
                    300:        if (pr == 0)
                    301:                panic("ip_init");
                    302:        for (i = 0; i < IPPROTO_MAX; i++)
                    303:                ip_protox[i] = pr - inetsw;
                    304:        for (pr = inetdomain.dom_protosw;
                    305:            pr < inetdomain.dom_protoswNPROTOSW; pr++)
                    306:                if (pr->pr_domain->dom_family == PF_INET &&
                    307:                    pr->pr_protocol && pr->pr_protocol != IPPROTO_RAW)
                    308:                        ip_protox[pr->pr_protocol] = pr - inetsw;
1.192     jonathan  309:
1.288     rmind     310:        ip_reass_init();
1.190     jonathan  311:
1.291     rmind     312:        ip_ids = ip_id_init();
1.227     kardel    313:        ip_id = time_second & 0xfffff;
1.194     jonathan  314:
1.294     dyoung    315:        ipintrq.ifq_maxlen = IFQ_MAXLEN;
1.194     jonathan  316:
1.181     jonathan  317:        TAILQ_INIT(&in_ifaddrhead);
1.272     ad        318:        in_ifaddrhashtbl = hashinit(IN_IFADDR_HASH_SIZE, HASH_LIST, true,
                    319:            &in_ifaddrhash);
                    320:        in_multihashtbl = hashinit(IN_IFADDR_HASH_SIZE, HASH_LIST, true,
                    321:            &in_multihash);
1.160     itojun    322:        ip_mtudisc_timeout_q = rt_timer_queue_create(ip_mtudisc_timeout);
1.73      thorpej   323: #ifdef GATEWAY
1.248     liamjfoy  324:        ipflow_init(ip_hashsize);
1.73      thorpej   325: #endif
1.121     thorpej   326:
                    327:        /* Register our Packet Filter hook. */
1.308     rmind     328:        inet_pfil_hook = pfil_head_create(PFIL_TYPE_AF, (void *)AF_INET);
                    329:        KASSERT(inet_pfil_hook != NULL);
1.135     thorpej   330:
1.164     matt      331: #ifdef MBUFTRACE
                    332:        MOWNER_ATTACH(&ip_tx_mowner);
                    333:        MOWNER_ATTACH(&ip_rx_mowner);
                    334: #endif /* MBUFTRACE */
1.266     thorpej   335:
                    336:        ipstat_percpu = percpu_alloc(sizeof(uint64_t) * IP_NSTATS);
1.1       cgd       337: }
                    338:
1.229     christos  339: struct sockaddr_in ipaddr = {
                    340:        .sin_len = sizeof(ipaddr),
                    341:        .sin_family = AF_INET,
                    342: };
1.1       cgd       343: struct route ipforward_rt;
                    344:
                    345: /*
1.89      itojun    346:  * IP software interrupt routine
                    347:  */
                    348: void
1.211     perry     349: ipintr(void)
1.89      itojun    350: {
                    351:        int s;
                    352:        struct mbuf *m;
1.286     tls       353:        struct ifqueue lcl_intrq;
                    354:
                    355:        memset(&lcl_intrq, 0, sizeof(lcl_intrq));
1.89      itojun    356:
1.268     ad        357:        mutex_enter(softnet_lock);
                    358:        KERNEL_LOCK(1, NULL);
1.286     tls       359:        if (!IF_IS_EMPTY(&ipintrq)) {
1.132     thorpej   360:                s = splnet();
1.286     tls       361:
                    362:                /* Take existing queue onto stack */
                    363:                lcl_intrq = ipintrq;
                    364:
                    365:                /* Zero out global queue, preserving maxlen and drops */
                    366:                ipintrq.ifq_head = NULL;
                    367:                ipintrq.ifq_tail = NULL;
                    368:                ipintrq.ifq_len = 0;
                    369:                ipintrq.ifq_maxlen = lcl_intrq.ifq_maxlen;
                    370:                ipintrq.ifq_drops = lcl_intrq.ifq_drops;
                    371:
1.89      itojun    372:                splx(s);
1.286     tls       373:        }
                    374:        KERNEL_UNLOCK_ONE(NULL);
                    375:        while (!IF_IS_EMPTY(&lcl_intrq)) {
                    376:                IF_DEQUEUE(&lcl_intrq, m);
1.268     ad        377:                if (m == NULL)
                    378:                        break;
1.89      itojun    379:                ip_input(m);
                    380:        }
1.268     ad        381:        mutex_exit(softnet_lock);
1.89      itojun    382: }
                    383:
                    384: /*
1.1       cgd       385:  * Ip input routine.  Checksum and byte swap header.  If fragmented
                    386:  * try to reassemble.  Process options.  Pass to next level.
                    387:  */
1.8       mycroft   388: void
1.89      itojun    389: ip_input(struct mbuf *m)
1.1       cgd       390: {
1.109     augustss  391:        struct ip *ip = NULL;
                    392:        struct in_ifaddr *ia;
                    393:        struct ifaddr *ifa;
1.288     rmind     394:        int hlen = 0, len;
1.100     itojun    395:        int downmatch;
1.165     christos  396:        int checkif;
1.169     itojun    397:        int srcrt = 0;
1.1       cgd       398:
1.164     matt      399:        MCLAIM(m, &ip_rx_mowner);
1.289     rmind     400:        KASSERT((m->m_flags & M_PKTHDR) != 0);
1.164     matt      401:
1.1       cgd       402:        /*
                    403:         * If no IP addresses have been set yet but the interfaces
                    404:         * are receiving, can't do anything with incoming packets yet.
                    405:         */
1.181     jonathan  406:        if (TAILQ_FIRST(&in_ifaddrhead) == 0)
1.1       cgd       407:                goto bad;
1.266     thorpej   408:        IP_STATINC(IP_STAT_TOTAL);
1.154     thorpej   409:        /*
                    410:         * If the IP header is not aligned, slurp it up into a new
                    411:         * mbuf with space for link headers, in the event we forward
                    412:         * it.  Otherwise, if it is aligned, make sure the entire
                    413:         * base IP header is in the first mbuf of the chain.
                    414:         */
1.244     christos  415:        if (IP_HDR_ALIGNED_P(mtod(m, void *)) == 0) {
1.154     thorpej   416:                if ((m = m_copyup(m, sizeof(struct ip),
                    417:                                  (max_linkhdr + 3) & ~3)) == NULL) {
                    418:                        /* XXXJRT new stat, please */
1.266     thorpej   419:                        IP_STATINC(IP_STAT_TOOSMALL);
1.154     thorpej   420:                        return;
                    421:                }
                    422:        } else if (__predict_false(m->m_len < sizeof (struct ip))) {
                    423:                if ((m = m_pullup(m, sizeof (struct ip))) == NULL) {
1.266     thorpej   424:                        IP_STATINC(IP_STAT_TOOSMALL);
1.154     thorpej   425:                        return;
                    426:                }
1.1       cgd       427:        }
                    428:        ip = mtod(m, struct ip *);
1.13      mycroft   429:        if (ip->ip_v != IPVERSION) {
1.266     thorpej   430:                IP_STATINC(IP_STAT_BADVERS);
1.13      mycroft   431:                goto bad;
                    432:        }
1.1       cgd       433:        hlen = ip->ip_hl << 2;
                    434:        if (hlen < sizeof(struct ip)) { /* minimum header length */
1.266     thorpej   435:                IP_STATINC(IP_STAT_BADHLEN);
1.1       cgd       436:                goto bad;
                    437:        }
                    438:        if (hlen > m->m_len) {
1.298     liamjfoy  439:                if ((m = m_pullup(m, hlen)) == NULL) {
1.266     thorpej   440:                        IP_STATINC(IP_STAT_BADHLEN);
1.89      itojun    441:                        return;
1.1       cgd       442:                }
                    443:                ip = mtod(m, struct ip *);
                    444:        }
1.98      thorpej   445:
1.85      hwr       446:        /*
1.99      thorpej   447:         * RFC1122: packets with a multicast source address are
1.98      thorpej   448:         * not allowed.
1.85      hwr       449:         */
                    450:        if (IN_MULTICAST(ip->ip_src.s_addr)) {
1.266     thorpej   451:                IP_STATINC(IP_STAT_BADADDR);
1.85      hwr       452:                goto bad;
1.129     itojun    453:        }
                    454:
                    455:        /* 127/8 must not appear on wire - RFC1122 */
                    456:        if ((ntohl(ip->ip_dst.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET ||
                    457:            (ntohl(ip->ip_src.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET) {
1.130     itojun    458:                if ((m->m_pkthdr.rcvif->if_flags & IFF_LOOPBACK) == 0) {
1.266     thorpej   459:                        IP_STATINC(IP_STAT_BADADDR);
1.129     itojun    460:                        goto bad;
1.130     itojun    461:                }
1.85      hwr       462:        }
                    463:
1.135     thorpej   464:        switch (m->m_pkthdr.csum_flags &
1.137     thorpej   465:                ((m->m_pkthdr.rcvif->if_csum_flags_rx & M_CSUM_IPv4) |
1.135     thorpej   466:                 M_CSUM_IPv4_BAD)) {
                    467:        case M_CSUM_IPv4|M_CSUM_IPv4_BAD:
                    468:                INET_CSUM_COUNTER_INCR(&ip_hwcsum_bad);
                    469:                goto badcsum;
                    470:
                    471:        case M_CSUM_IPv4:
                    472:                /* Checksum was okay. */
                    473:                INET_CSUM_COUNTER_INCR(&ip_hwcsum_ok);
                    474:                break;
                    475:
                    476:        default:
1.206     thorpej   477:                /*
                    478:                 * Must compute it ourselves.  Maybe skip checksum on
                    479:                 * loopback interfaces.
                    480:                 */
                    481:                if (__predict_true(!(m->m_pkthdr.rcvif->if_flags &
                    482:                                     IFF_LOOPBACK) || ip_do_loopback_cksum)) {
                    483:                        INET_CSUM_COUNTER_INCR(&ip_swcsum);
                    484:                        if (in_cksum(m, hlen) != 0)
                    485:                                goto badcsum;
                    486:                }
1.135     thorpej   487:                break;
1.1       cgd       488:        }
                    489:
1.121     thorpej   490:        /* Retrieve the packet length. */
                    491:        len = ntohs(ip->ip_len);
1.81      proff     492:
                    493:        /*
                    494:         * Check for additional length bogosity
                    495:         */
1.84      proff     496:        if (len < hlen) {
1.266     thorpej   497:                IP_STATINC(IP_STAT_BADLEN);
1.81      proff     498:                goto bad;
                    499:        }
1.1       cgd       500:
                    501:        /*
                    502:         * Check that the amount of data in the buffers
                    503:         * is as at least much as the IP header would have us expect.
                    504:         * Trim mbufs if longer than we expect.
                    505:         * Drop packet if shorter than we expect.
                    506:         */
1.35      mycroft   507:        if (m->m_pkthdr.len < len) {
1.266     thorpej   508:                IP_STATINC(IP_STAT_TOOSHORT);
1.1       cgd       509:                goto bad;
                    510:        }
1.35      mycroft   511:        if (m->m_pkthdr.len > len) {
1.1       cgd       512:                if (m->m_len == m->m_pkthdr.len) {
1.35      mycroft   513:                        m->m_len = len;
                    514:                        m->m_pkthdr.len = len;
1.1       cgd       515:                } else
1.35      mycroft   516:                        m_adj(m, len - m->m_pkthdr.len);
1.1       cgd       517:        }
                    518:
1.64      thorpej   519:        /*
                    520:         * Assume that we can create a fast-forward IP flow entry
                    521:         * based on this packet.
                    522:         */
                    523:        m->m_flags |= M_CANFASTFWD;
                    524:
1.33      mrg       525:        /*
1.64      thorpej   526:         * Run through list of hooks for input packets.  If there are any
                    527:         * filters which require that additional packets in the flow are
                    528:         * not fast-forwarded, they must clear the M_CANFASTFWD flag.
                    529:         * Note that filters must _never_ set this flag, as another filter
                    530:         * in the list may have previously cleared it.
1.33      mrg       531:         */
1.127     itojun    532:        /*
                    533:         * let ipfilter look at packet on the wire,
                    534:         * not the decapsulated packet.
                    535:         */
1.304     christos  536: #if defined(IPSEC)
1.186     scw       537:        if (!ipsec_indone(m))
1.127     itojun    538: #else
                    539:        if (1)
                    540: #endif
                    541:        {
1.169     itojun    542:                struct in_addr odst;
                    543:
                    544:                odst = ip->ip_dst;
1.308     rmind     545:                if (pfil_run_hooks(inet_pfil_hook, &m, m->m_pkthdr.rcvif,
1.168     itojun    546:                    PFIL_IN) != 0)
                    547:                        return;
1.127     itojun    548:                if (m == NULL)
                    549:                        return;
                    550:                ip = mtod(m, struct ip *);
1.142     darrenr   551:                hlen = ip->ip_hl << 2;
1.205     darrenr   552:                /*
                    553:                 * XXX The setting of "srcrt" here is to prevent ip_forward()
                    554:                 * from generating ICMP redirects for packets that have
                    555:                 * been redirected by a hook back out on to the same LAN that
                    556:                 * they came from and is not an indication that the packet
                    557:                 * is being inffluenced by source routing options.  This
                    558:                 * allows things like
                    559:                 * "rdr tlp0 0/0 port 80 -> 1.1.1.200 3128 tcp"
                    560:                 * where tlp0 is both on the 1.1.1.0/24 network and is the
                    561:                 * default route for hosts on 1.1.1.0/24.  Of course this
                    562:                 * also requires a "map tlp0 ..." to complete the story.
                    563:                 * One might argue whether or not this kind of network config.
1.212     perry     564:                 * should be supported in this manner...
1.205     darrenr   565:                 */
1.169     itojun    566:                srcrt = (odst.s_addr != ip->ip_dst.s_addr);
1.127     itojun    567:        }
1.123     thorpej   568:
                    569: #ifdef ALTQ
                    570:        /* XXX Temporary until ALTQ is changed to use a pfil hook */
                    571:        if (altq_input != NULL && (*altq_input)(m, AF_INET) == 0) {
                    572:                /* packet dropped by traffic conditioner */
                    573:                return;
                    574:        }
                    575: #endif
1.121     thorpej   576:
                    577:        /*
1.1       cgd       578:         * Process options and, if not destined for us,
                    579:         * ship it on.  ip_dooptions returns 1 when an
                    580:         * error was detected (causing an icmp message
                    581:         * to be sent and the original packet to be freed).
                    582:         */
                    583:        ip_nhops = 0;           /* for source routed packets */
                    584:        if (hlen > sizeof (struct ip) && ip_dooptions(m))
1.89      itojun    585:                return;
1.1       cgd       586:
                    587:        /*
1.165     christos  588:         * Enable a consistency check between the destination address
                    589:         * and the arrival interface for a unicast packet (the RFC 1122
                    590:         * strong ES model) if IP forwarding is disabled and the packet
                    591:         * is not locally generated.
                    592:         *
                    593:         * XXX - Checking also should be disabled if the destination
                    594:         * address is ipnat'ed to a different interface.
                    595:         *
                    596:         * XXX - Checking is incompatible with IP aliases added
                    597:         * to the loopback interface instead of the interface where
                    598:         * the packets are received.
                    599:         *
                    600:         * XXX - We need to add a per ifaddr flag for this so that
                    601:         * we get finer grain control.
                    602:         */
                    603:        checkif = ip_checkinterface && (ipforwarding == 0) &&
                    604:            (m->m_pkthdr.rcvif != NULL) &&
                    605:            ((m->m_pkthdr.rcvif->if_flags & IFF_LOOPBACK) == 0);
                    606:
                    607:        /*
1.1       cgd       608:         * Check our list of addresses, to see if the packet is for us.
1.100     itojun    609:         *
                    610:         * Traditional 4.4BSD did not consult IFF_UP at all.
                    611:         * The behavior here is to treat addresses on !IFF_UP interface
                    612:         * as not mine.
1.1       cgd       613:         */
1.100     itojun    614:        downmatch = 0;
1.140     matt      615:        LIST_FOREACH(ia, &IN_IFADDR_HASH(ip->ip_dst.s_addr), ia_hash) {
1.97      itojun    616:                if (in_hosteq(ia->ia_addr.sin_addr, ip->ip_dst)) {
1.165     christos  617:                        if (checkif && ia->ia_ifp != m->m_pkthdr.rcvif)
                    618:                                continue;
1.97      itojun    619:                        if ((ia->ia_ifp->if_flags & IFF_UP) != 0)
                    620:                                break;
1.100     itojun    621:                        else
                    622:                                downmatch++;
1.97      itojun    623:                }
                    624:        }
1.86      thorpej   625:        if (ia != NULL)
                    626:                goto ours;
1.225     christos  627:        if (m->m_pkthdr.rcvif && m->m_pkthdr.rcvif->if_flags & IFF_BROADCAST) {
1.209     matt      628:                IFADDR_FOREACH(ifa, m->m_pkthdr.rcvif) {
1.140     matt      629:                        if (ifa->ifa_addr->sa_family != AF_INET)
                    630:                                continue;
1.57      tls       631:                        ia = ifatoia(ifa);
1.35      mycroft   632:                        if (in_hosteq(ip->ip_dst, ia->ia_broadaddr.sin_addr) ||
                    633:                            in_hosteq(ip->ip_dst, ia->ia_netbroadcast) ||
1.20      mycroft   634:                            /*
                    635:                             * Look for all-0's host part (old broadcast addr),
                    636:                             * either for subnet or net.
                    637:                             */
                    638:                            ip->ip_dst.s_addr == ia->ia_subnet ||
1.18      mycroft   639:                            ip->ip_dst.s_addr == ia->ia_net)
1.1       cgd       640:                                goto ours;
1.57      tls       641:                        /*
                    642:                         * An interface with IP address zero accepts
                    643:                         * all packets that arrive on that interface.
                    644:                         */
                    645:                        if (in_nullhost(ia->ia_addr.sin_addr))
                    646:                                goto ours;
1.1       cgd       647:                }
                    648:        }
1.18      mycroft   649:        if (IN_MULTICAST(ip->ip_dst.s_addr)) {
1.4       hpeyerl   650:                struct in_multi *inm;
                    651: #ifdef MROUTING
                    652:                extern struct socket *ip_mrouter;
1.10      brezak    653:
1.4       hpeyerl   654:                if (ip_mrouter) {
                    655:                        /*
                    656:                         * If we are acting as a multicast router, all
                    657:                         * incoming multicast packets are passed to the
                    658:                         * kernel-level multicast forwarding function.
                    659:                         * The packet is returned (relatively) intact; if
                    660:                         * ip_mforward() returns a non-zero value, the packet
                    661:                         * must be discarded, else it may be accepted below.
                    662:                         *
                    663:                         * (The IP ident field is put in the same byte order
                    664:                         * as expected when ip_mforward() is called from
                    665:                         * ip_output().)
                    666:                         */
1.13      mycroft   667:                        if (ip_mforward(m, m->m_pkthdr.rcvif) != 0) {
1.266     thorpej   668:                                IP_STATINC(IP_STAT_CANTFORWARD);
1.4       hpeyerl   669:                                m_freem(m);
1.89      itojun    670:                                return;
1.4       hpeyerl   671:                        }
                    672:
                    673:                        /*
                    674:                         * The process-level routing demon needs to receive
                    675:                         * all multicast IGMP packets, whether or not this
                    676:                         * host belongs to their destination groups.
                    677:                         */
                    678:                        if (ip->ip_p == IPPROTO_IGMP)
                    679:                                goto ours;
1.266     thorpej   680:                        IP_STATINC(IP_STAT_CANTFORWARD);
1.4       hpeyerl   681:                }
                    682: #endif
                    683:                /*
                    684:                 * See if we belong to the destination multicast group on the
                    685:                 * arrival interface.
                    686:                 */
                    687:                IN_LOOKUP_MULTI(ip->ip_dst, m->m_pkthdr.rcvif, inm);
                    688:                if (inm == NULL) {
1.266     thorpej   689:                        IP_STATINC(IP_STAT_CANTFORWARD);
1.4       hpeyerl   690:                        m_freem(m);
1.89      itojun    691:                        return;
1.4       hpeyerl   692:                }
                    693:                goto ours;
                    694:        }
1.19      mycroft   695:        if (ip->ip_dst.s_addr == INADDR_BROADCAST ||
1.35      mycroft   696:            in_nullhost(ip->ip_dst))
1.1       cgd       697:                goto ours;
                    698:
                    699:        /*
                    700:         * Not for us; forward if possible and desirable.
                    701:         */
                    702:        if (ipforwarding == 0) {
1.266     thorpej   703:                IP_STATINC(IP_STAT_CANTFORWARD);
1.1       cgd       704:                m_freem(m);
1.100     itojun    705:        } else {
                    706:                /*
                    707:                 * If ip_dst matched any of my address on !IFF_UP interface,
                    708:                 * and there's no IFF_UP interface that matches ip_dst,
                    709:                 * send icmp unreach.  Forwarding it will result in in-kernel
                    710:                 * forwarding loop till TTL goes to 0.
                    711:                 */
                    712:                if (downmatch) {
                    713:                        icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_HOST, 0, 0);
1.266     thorpej   714:                        IP_STATINC(IP_STAT_CANTFORWARD);
1.100     itojun    715:                        return;
                    716:                }
1.304     christos  717: #ifdef IPSEC
1.305     rmind     718:                /* Perform IPsec, if any. */
                    719:                if (ipsec4_input(m, IP_FORWARDING | (ip_directedbcast ?
                    720:                    IP_ALLOWBROADCAST : 0)) != 0) {
1.173     jonathan  721:                        goto bad;
                    722:                }
1.305     rmind     723: #endif
1.169     itojun    724:                ip_forward(m, srcrt);
1.100     itojun    725:        }
1.89      itojun    726:        return;
1.1       cgd       727:
                    728: ours:
                    729:        /*
                    730:         * If offset or IP_MF are set, must reassemble.
                    731:         */
1.155     itojun    732:        if (ip->ip_off & ~htons(IP_DF|IP_RF)) {
1.289     rmind     733:                /*
                    734:                 * Pass to IP reassembly mechanism.
                    735:                 */
1.290     rmind     736:                if (ip_reass_packet(&m, ip) != 0) {
1.289     rmind     737:                        /* Failed; invalid fragment(s) or packet. */
1.288     rmind     738:                        goto bad;
1.16      cgd       739:                }
1.290     rmind     740:                if (m == NULL) {
1.289     rmind     741:                        /* More fragments should come; silently return. */
                    742:                        return;
                    743:                }
1.290     rmind     744:                /*
                    745:                 * Reassembly is done, we have the final packet.
                    746:                 * Updated cached data in local variable(s).
                    747:                 */
1.289     rmind     748:                ip = mtod(m, struct ip *);
                    749:                hlen = ip->ip_hl << 2;
1.79      mycroft   750:        }
1.128     itojun    751:
1.304     christos  752: #ifdef IPSEC
1.173     jonathan  753:        /*
1.305     rmind     754:         * Enforce IPsec policy checking if we are seeing last header.
                    755:         * Note that we do not visit this with protocols with PCB layer
                    756:         * code - like UDP/TCP/raw IP.
1.173     jonathan  757:         */
                    758:        if ((inetsw[ip_protox[ip->ip_p]].pr_flags & PR_LASTHDR) != 0) {
1.305     rmind     759:                if (ipsec4_input(m, 0) != 0) {
                    760:                        goto bad;
1.173     jonathan  761:                }
                    762:        }
1.305     rmind     763: #endif
1.1       cgd       764:
                    765:        /*
                    766:         * Switch out to protocol's input routine.
                    767:         */
1.82      aidan     768: #if IFA_STATS
1.122     itojun    769:        if (ia && ip)
1.155     itojun    770:                ia->ia_ifa.ifa_data.ifad_inbytes += ntohs(ip->ip_len);
1.82      aidan     771: #endif
1.266     thorpej   772:        IP_STATINC(IP_STAT_DELIVERED);
1.89      itojun    773:     {
                    774:        int off = hlen, nh = ip->ip_p;
                    775:
                    776:        (*inetsw[ip_protox[nh]].pr_input)(m, off, nh);
                    777:        return;
                    778:     }
1.1       cgd       779: bad:
                    780:        m_freem(m);
1.135     thorpej   781:        return;
                    782:
                    783: badcsum:
1.266     thorpej   784:        IP_STATINC(IP_STAT_BADSUM);
1.135     thorpej   785:        m_freem(m);
1.1       cgd       786: }
                    787:
                    788: /*
1.288     rmind     789:  * IP timer processing.
1.1       cgd       790:  */
1.8       mycroft   791: void
1.211     perry     792: ip_slowtimo(void)
1.1       cgd       793: {
1.268     ad        794:
                    795:        mutex_enter(softnet_lock);
                    796:        KERNEL_LOCK(1, NULL);
1.1       cgd       797:
1.288     rmind     798:        ip_reass_slowtimo();
1.268     ad        799:
                    800:        KERNEL_UNLOCK_ONE(NULL);
                    801:        mutex_exit(softnet_lock);
1.1       cgd       802: }
                    803:
                    804: /*
1.288     rmind     805:  * IP drain processing.
1.1       cgd       806:  */
1.8       mycroft   807: void
1.211     perry     808: ip_drain(void)
1.1       cgd       809: {
                    810:
1.268     ad        811:        KERNEL_LOCK(1, NULL);
1.288     rmind     812:        ip_reass_drain();
1.268     ad        813:        KERNEL_UNLOCK_ONE(NULL);
1.1       cgd       814: }
                    815:
                    816: /*
                    817:  * Do option processing on a datagram,
                    818:  * possibly discarding it if bad options are encountered,
                    819:  * or forwarding it if source-routed.
                    820:  * Returns 1 if packet has been forwarded/freed,
                    821:  * 0 if the packet should be processed further.
                    822:  */
1.8       mycroft   823: int
1.211     perry     824: ip_dooptions(struct mbuf *m)
1.1       cgd       825: {
1.109     augustss  826:        struct ip *ip = mtod(m, struct ip *);
                    827:        u_char *cp, *cp0;
                    828:        struct ip_timestamp *ipt;
                    829:        struct in_ifaddr *ia;
1.1       cgd       830:        int opt, optlen, cnt, off, code, type = ICMP_PARAMPROB, forward = 0;
1.104     thorpej   831:        struct in_addr dst;
1.1       cgd       832:        n_time ntime;
                    833:
1.13      mycroft   834:        dst = ip->ip_dst;
1.1       cgd       835:        cp = (u_char *)(ip + 1);
                    836:        cnt = (ip->ip_hl << 2) - sizeof (struct ip);
                    837:        for (; cnt > 0; cnt -= optlen, cp += optlen) {
                    838:                opt = cp[IPOPT_OPTVAL];
                    839:                if (opt == IPOPT_EOL)
                    840:                        break;
                    841:                if (opt == IPOPT_NOP)
                    842:                        optlen = 1;
                    843:                else {
1.113     itojun    844:                        if (cnt < IPOPT_OLEN + sizeof(*cp)) {
                    845:                                code = &cp[IPOPT_OLEN] - (u_char *)ip;
                    846:                                goto bad;
                    847:                        }
1.1       cgd       848:                        optlen = cp[IPOPT_OLEN];
1.114     itojun    849:                        if (optlen < IPOPT_OLEN + sizeof(*cp) || optlen > cnt) {
1.1       cgd       850:                                code = &cp[IPOPT_OLEN] - (u_char *)ip;
                    851:                                goto bad;
                    852:                        }
                    853:                }
                    854:                switch (opt) {
                    855:
                    856:                default:
                    857:                        break;
                    858:
                    859:                /*
                    860:                 * Source routing with record.
                    861:                 * Find interface with current destination address.
                    862:                 * If none on this machine then drop if strictly routed,
                    863:                 * or do nothing if loosely routed.
                    864:                 * Record interface address and bring up next address
                    865:                 * component.  If strictly routed make sure next
                    866:                 * address is on directly accessible net.
                    867:                 */
                    868:                case IPOPT_LSRR:
                    869:                case IPOPT_SSRR:
1.47      cjs       870:                        if (ip_allowsrcrt == 0) {
                    871:                                type = ICMP_UNREACH;
                    872:                                code = ICMP_UNREACH_NET_PROHIB;
                    873:                                goto bad;
                    874:                        }
1.114     itojun    875:                        if (optlen < IPOPT_OFFSET + sizeof(*cp)) {
                    876:                                code = &cp[IPOPT_OLEN] - (u_char *)ip;
                    877:                                goto bad;
                    878:                        }
1.1       cgd       879:                        if ((off = cp[IPOPT_OFFSET]) < IPOPT_MINOFF) {
                    880:                                code = &cp[IPOPT_OFFSET] - (u_char *)ip;
                    881:                                goto bad;
                    882:                        }
                    883:                        ipaddr.sin_addr = ip->ip_dst;
1.19      mycroft   884:                        ia = ifatoia(ifa_ifwithaddr(sintosa(&ipaddr)));
1.1       cgd       885:                        if (ia == 0) {
                    886:                                if (opt == IPOPT_SSRR) {
                    887:                                        type = ICMP_UNREACH;
                    888:                                        code = ICMP_UNREACH_SRCFAIL;
                    889:                                        goto bad;
                    890:                                }
                    891:                                /*
                    892:                                 * Loose routing, and not at next destination
                    893:                                 * yet; nothing to do except forward.
                    894:                                 */
                    895:                                break;
                    896:                        }
                    897:                        off--;                  /* 0 origin */
1.112     sommerfe  898:                        if ((off + sizeof(struct in_addr)) > optlen) {
1.1       cgd       899:                                /*
                    900:                                 * End of source route.  Should be for us.
                    901:                                 */
                    902:                                save_rte(cp, ip->ip_src);
                    903:                                break;
                    904:                        }
                    905:                        /*
                    906:                         * locate outgoing interface
                    907:                         */
1.281     tsutsui   908:                        memcpy((void *)&ipaddr.sin_addr, (void *)(cp + off),
1.1       cgd       909:                            sizeof(ipaddr.sin_addr));
1.96      thorpej   910:                        if (opt == IPOPT_SSRR)
1.196     itojun    911:                                ia = ifatoia(ifa_ifwithladdr(sintosa(&ipaddr)));
1.96      thorpej   912:                        else
1.1       cgd       913:                                ia = ip_rtaddr(ipaddr.sin_addr);
                    914:                        if (ia == 0) {
                    915:                                type = ICMP_UNREACH;
                    916:                                code = ICMP_UNREACH_SRCFAIL;
                    917:                                goto bad;
                    918:                        }
                    919:                        ip->ip_dst = ipaddr.sin_addr;
1.244     christos  920:                        bcopy((void *)&ia->ia_addr.sin_addr,
                    921:                            (void *)(cp + off), sizeof(struct in_addr));
1.1       cgd       922:                        cp[IPOPT_OFFSET] += sizeof(struct in_addr);
1.13      mycroft   923:                        /*
                    924:                         * Let ip_intr's mcast routing check handle mcast pkts
                    925:                         */
1.18      mycroft   926:                        forward = !IN_MULTICAST(ip->ip_dst.s_addr);
1.1       cgd       927:                        break;
                    928:
                    929:                case IPOPT_RR:
1.114     itojun    930:                        if (optlen < IPOPT_OFFSET + sizeof(*cp)) {
                    931:                                code = &cp[IPOPT_OLEN] - (u_char *)ip;
                    932:                                goto bad;
                    933:                        }
1.1       cgd       934:                        if ((off = cp[IPOPT_OFFSET]) < IPOPT_MINOFF) {
                    935:                                code = &cp[IPOPT_OFFSET] - (u_char *)ip;
                    936:                                goto bad;
                    937:                        }
                    938:                        /*
                    939:                         * If no space remains, ignore.
                    940:                         */
                    941:                        off--;                  /* 0 origin */
1.112     sommerfe  942:                        if ((off + sizeof(struct in_addr)) > optlen)
1.1       cgd       943:                                break;
1.281     tsutsui   944:                        memcpy((void *)&ipaddr.sin_addr, (void *)(&ip->ip_dst),
1.1       cgd       945:                            sizeof(ipaddr.sin_addr));
                    946:                        /*
                    947:                         * locate outgoing interface; if we're the destination,
                    948:                         * use the incoming interface (should be same).
                    949:                         */
1.96      thorpej   950:                        if ((ia = ifatoia(ifa_ifwithaddr(sintosa(&ipaddr))))
                    951:                            == NULL &&
                    952:                            (ia = ip_rtaddr(ipaddr.sin_addr)) == NULL) {
1.1       cgd       953:                                type = ICMP_UNREACH;
                    954:                                code = ICMP_UNREACH_HOST;
                    955:                                goto bad;
                    956:                        }
1.244     christos  957:                        bcopy((void *)&ia->ia_addr.sin_addr,
                    958:                            (void *)(cp + off), sizeof(struct in_addr));
1.1       cgd       959:                        cp[IPOPT_OFFSET] += sizeof(struct in_addr);
                    960:                        break;
                    961:
                    962:                case IPOPT_TS:
                    963:                        code = cp - (u_char *)ip;
                    964:                        ipt = (struct ip_timestamp *)cp;
1.114     itojun    965:                        if (ipt->ipt_len < 4 || ipt->ipt_len > 40) {
                    966:                                code = (u_char *)&ipt->ipt_len - (u_char *)ip;
1.1       cgd       967:                                goto bad;
1.114     itojun    968:                        }
                    969:                        if (ipt->ipt_ptr < 5) {
                    970:                                code = (u_char *)&ipt->ipt_ptr - (u_char *)ip;
                    971:                                goto bad;
                    972:                        }
1.15      cgd       973:                        if (ipt->ipt_ptr > ipt->ipt_len - sizeof (int32_t)) {
1.114     itojun    974:                                if (++ipt->ipt_oflw == 0) {
                    975:                                        code = (u_char *)&ipt->ipt_ptr -
                    976:                                            (u_char *)ip;
1.1       cgd       977:                                        goto bad;
1.114     itojun    978:                                }
1.1       cgd       979:                                break;
                    980:                        }
1.104     thorpej   981:                        cp0 = (cp + ipt->ipt_ptr - 1);
1.1       cgd       982:                        switch (ipt->ipt_flg) {
                    983:
                    984:                        case IPOPT_TS_TSONLY:
                    985:                                break;
                    986:
                    987:                        case IPOPT_TS_TSANDADDR:
1.66      thorpej   988:                                if (ipt->ipt_ptr - 1 + sizeof(n_time) +
1.114     itojun    989:                                    sizeof(struct in_addr) > ipt->ipt_len) {
                    990:                                        code = (u_char *)&ipt->ipt_ptr -
                    991:                                            (u_char *)ip;
1.1       cgd       992:                                        goto bad;
1.114     itojun    993:                                }
1.13      mycroft   994:                                ipaddr.sin_addr = dst;
1.96      thorpej   995:                                ia = ifatoia(ifaof_ifpforaddr(sintosa(&ipaddr),
                    996:                                    m->m_pkthdr.rcvif));
1.13      mycroft   997:                                if (ia == 0)
                    998:                                        continue;
1.104     thorpej   999:                                bcopy(&ia->ia_addr.sin_addr,
                   1000:                                    cp0, sizeof(struct in_addr));
1.1       cgd      1001:                                ipt->ipt_ptr += sizeof(struct in_addr);
                   1002:                                break;
                   1003:
                   1004:                        case IPOPT_TS_PRESPEC:
1.66      thorpej  1005:                                if (ipt->ipt_ptr - 1 + sizeof(n_time) +
1.114     itojun   1006:                                    sizeof(struct in_addr) > ipt->ipt_len) {
                   1007:                                        code = (u_char *)&ipt->ipt_ptr -
                   1008:                                            (u_char *)ip;
1.1       cgd      1009:                                        goto bad;
1.114     itojun   1010:                                }
1.281     tsutsui  1011:                                memcpy(&ipaddr.sin_addr, cp0,
1.1       cgd      1012:                                    sizeof(struct in_addr));
1.96      thorpej  1013:                                if (ifatoia(ifa_ifwithaddr(sintosa(&ipaddr)))
                   1014:                                    == NULL)
1.1       cgd      1015:                                        continue;
                   1016:                                ipt->ipt_ptr += sizeof(struct in_addr);
                   1017:                                break;
                   1018:
                   1019:                        default:
1.114     itojun   1020:                                /* XXX can't take &ipt->ipt_flg */
                   1021:                                code = (u_char *)&ipt->ipt_ptr -
                   1022:                                    (u_char *)ip + 1;
1.1       cgd      1023:                                goto bad;
                   1024:                        }
                   1025:                        ntime = iptime();
1.107     thorpej  1026:                        cp0 = (u_char *) &ntime; /* XXX grumble, GCC... */
1.244     christos 1027:                        memmove((char *)cp + ipt->ipt_ptr - 1, cp0,
1.1       cgd      1028:                            sizeof(n_time));
                   1029:                        ipt->ipt_ptr += sizeof(n_time);
                   1030:                }
                   1031:        }
                   1032:        if (forward) {
1.26      thorpej  1033:                if (ip_forwsrcrt == 0) {
                   1034:                        type = ICMP_UNREACH;
                   1035:                        code = ICMP_UNREACH_SRCFAIL;
                   1036:                        goto bad;
                   1037:                }
1.1       cgd      1038:                ip_forward(m, 1);
                   1039:                return (1);
1.13      mycroft  1040:        }
                   1041:        return (0);
1.1       cgd      1042: bad:
1.13      mycroft  1043:        icmp_error(m, type, code, 0, 0);
1.266     thorpej  1044:        IP_STATINC(IP_STAT_BADOPTIONS);
1.1       cgd      1045:        return (1);
                   1046: }
                   1047:
                   1048: /*
                   1049:  * Given address of next destination (final or next hop),
                   1050:  * return internet address info of interface to be used to get there.
                   1051:  */
                   1052: struct in_ifaddr *
1.211     perry    1053: ip_rtaddr(struct in_addr dst)
1.1       cgd      1054: {
1.249     dyoung   1055:        struct rtentry *rt;
                   1056:        union {
                   1057:                struct sockaddr         dst;
                   1058:                struct sockaddr_in      dst4;
                   1059:        } u;
                   1060:
                   1061:        sockaddr_in_init(&u.dst4, &dst, 0);
                   1062:
                   1063:        if ((rt = rtcache_lookup(&ipforward_rt, &u.dst)) == NULL)
                   1064:                return NULL;
                   1065:
                   1066:        return ifatoia(rt->rt_ifa);
1.1       cgd      1067: }
                   1068:
                   1069: /*
                   1070:  * Save incoming source route for use in replies,
                   1071:  * to be picked up later by ip_srcroute if the receiver is interested.
                   1072:  */
1.13      mycroft  1073: void
1.211     perry    1074: save_rte(u_char *option, struct in_addr dst)
1.1       cgd      1075: {
                   1076:        unsigned olen;
                   1077:
                   1078:        olen = option[IPOPT_OLEN];
                   1079: #ifdef DIAGNOSTIC
                   1080:        if (ipprintfs)
1.39      christos 1081:                printf("save_rte: olen %d\n", olen);
1.89      itojun   1082: #endif /* 0 */
1.1       cgd      1083:        if (olen > sizeof(ip_srcrt) - (1 + sizeof(dst)))
                   1084:                return;
1.281     tsutsui  1085:        memcpy((void *)ip_srcrt.srcopt, (void *)option, olen);
1.1       cgd      1086:        ip_nhops = (olen - IPOPT_OFFSET - 1) / sizeof(struct in_addr);
                   1087:        ip_srcrt.dst = dst;
                   1088: }
                   1089:
                   1090: /*
                   1091:  * Retrieve incoming source route for use in replies,
                   1092:  * in the same form used by setsockopt.
                   1093:  * The first hop is placed before the options, will be removed later.
                   1094:  */
                   1095: struct mbuf *
1.211     perry    1096: ip_srcroute(void)
1.1       cgd      1097: {
1.109     augustss 1098:        struct in_addr *p, *q;
                   1099:        struct mbuf *m;
1.1       cgd      1100:
                   1101:        if (ip_nhops == 0)
1.237     dyoung   1102:                return NULL;
1.1       cgd      1103:        m = m_get(M_DONTWAIT, MT_SOOPTS);
                   1104:        if (m == 0)
1.237     dyoung   1105:                return NULL;
1.1       cgd      1106:
1.164     matt     1107:        MCLAIM(m, &inetdomain.dom_mowner);
1.13      mycroft  1108: #define OPTSIZ (sizeof(ip_srcrt.nop) + sizeof(ip_srcrt.srcopt))
1.1       cgd      1109:
                   1110:        /* length is (nhops+1)*sizeof(addr) + sizeof(nop + srcrt header) */
                   1111:        m->m_len = ip_nhops * sizeof(struct in_addr) + sizeof(struct in_addr) +
                   1112:            OPTSIZ;
                   1113: #ifdef DIAGNOSTIC
                   1114:        if (ipprintfs)
1.39      christos 1115:                printf("ip_srcroute: nhops %d mlen %d", ip_nhops, m->m_len);
1.1       cgd      1116: #endif
                   1117:
                   1118:        /*
                   1119:         * First save first hop for return route
                   1120:         */
                   1121:        p = &ip_srcrt.route[ip_nhops - 1];
                   1122:        *(mtod(m, struct in_addr *)) = *p--;
                   1123: #ifdef DIAGNOSTIC
                   1124:        if (ipprintfs)
1.39      christos 1125:                printf(" hops %x", ntohl(mtod(m, struct in_addr *)->s_addr));
1.1       cgd      1126: #endif
                   1127:
                   1128:        /*
                   1129:         * Copy option fields and padding (nop) to mbuf.
                   1130:         */
                   1131:        ip_srcrt.nop = IPOPT_NOP;
                   1132:        ip_srcrt.srcopt[IPOPT_OFFSET] = IPOPT_MINOFF;
1.244     christos 1133:        memmove(mtod(m, char *) + sizeof(struct in_addr), &ip_srcrt.nop,
                   1134:            OPTSIZ);
                   1135:        q = (struct in_addr *)(mtod(m, char *) +
1.1       cgd      1136:            sizeof(struct in_addr) + OPTSIZ);
                   1137: #undef OPTSIZ
                   1138:        /*
                   1139:         * Record return path as an IP source route,
                   1140:         * reversing the path (pointers are now aligned).
                   1141:         */
                   1142:        while (p >= ip_srcrt.route) {
                   1143: #ifdef DIAGNOSTIC
                   1144:                if (ipprintfs)
1.39      christos 1145:                        printf(" %x", ntohl(q->s_addr));
1.1       cgd      1146: #endif
                   1147:                *q++ = *p--;
                   1148:        }
                   1149:        /*
                   1150:         * Last hop goes to final destination.
                   1151:         */
                   1152:        *q = ip_srcrt.dst;
                   1153: #ifdef DIAGNOSTIC
                   1154:        if (ipprintfs)
1.39      christos 1155:                printf(" %x\n", ntohl(q->s_addr));
1.1       cgd      1156: #endif
                   1157:        return (m);
                   1158: }
                   1159:
1.139     matt     1160: const int inetctlerrmap[PRC_NCMDS] = {
1.256     yamt     1161:        [PRC_MSGSIZE] = EMSGSIZE,
                   1162:        [PRC_HOSTDEAD] = EHOSTDOWN,
                   1163:        [PRC_HOSTUNREACH] = EHOSTUNREACH,
                   1164:        [PRC_UNREACH_NET] = EHOSTUNREACH,
                   1165:        [PRC_UNREACH_HOST] = EHOSTUNREACH,
                   1166:        [PRC_UNREACH_PROTOCOL] = ECONNREFUSED,
                   1167:        [PRC_UNREACH_PORT] = ECONNREFUSED,
                   1168:        [PRC_UNREACH_SRCFAIL] = EHOSTUNREACH,
                   1169:        [PRC_PARAMPROB] = ENOPROTOOPT,
1.1       cgd      1170: };
                   1171:
1.295     dyoung   1172: void
                   1173: ip_fasttimo(void)
                   1174: {
                   1175:        if (ip_drainwanted) {
                   1176:                ip_drain();
                   1177:                ip_drainwanted = 0;
                   1178:        }
                   1179: }
                   1180:
                   1181: void
                   1182: ip_drainstub(void)
                   1183: {
                   1184:        ip_drainwanted = 1;
                   1185: }
                   1186:
1.1       cgd      1187: /*
                   1188:  * Forward a packet.  If some error occurs return the sender
                   1189:  * an icmp packet.  Note we can't always generate a meaningful
                   1190:  * icmp message because icmp doesn't have a large enough repertoire
                   1191:  * of codes and types.
                   1192:  *
                   1193:  * If not forwarding, just drop the packet.  This could be confusing
                   1194:  * if ipforwarding was zero but some routing protocol was advancing
                   1195:  * us as a gateway to somewhere.  However, we must let the routing
                   1196:  * protocol deal with that.
                   1197:  *
                   1198:  * The srcrt parameter indicates whether the packet is being forwarded
                   1199:  * via a source route.
                   1200:  */
1.13      mycroft  1201: void
1.211     perry    1202: ip_forward(struct mbuf *m, int srcrt)
1.1       cgd      1203: {
1.109     augustss 1204:        struct ip *ip = mtod(m, struct ip *);
                   1205:        struct rtentry *rt;
1.220     christos 1206:        int error, type = 0, code = 0, destmtu = 0;
1.1       cgd      1207:        struct mbuf *mcopy;
1.13      mycroft  1208:        n_long dest;
1.249     dyoung   1209:        union {
                   1210:                struct sockaddr         dst;
                   1211:                struct sockaddr_in      dst4;
                   1212:        } u;
1.164     matt     1213:
                   1214:        /*
                   1215:         * We are now in the output path.
                   1216:         */
                   1217:        MCLAIM(m, &ip_tx_mowner);
1.135     thorpej  1218:
                   1219:        /*
                   1220:         * Clear any in-bound checksum flags for this packet.
                   1221:         */
                   1222:        m->m_pkthdr.csum_flags = 0;
1.1       cgd      1223:
1.13      mycroft  1224:        dest = 0;
1.1       cgd      1225: #ifdef DIAGNOSTIC
1.224     joerg    1226:        if (ipprintfs) {
                   1227:                printf("forward: src %s ", inet_ntoa(ip->ip_src));
                   1228:                printf("dst %s ttl %x\n", inet_ntoa(ip->ip_dst), ip->ip_ttl);
                   1229:        }
1.1       cgd      1230: #endif
1.93      sommerfe 1231:        if (m->m_flags & (M_BCAST|M_MCAST) || in_canforward(ip->ip_dst) == 0) {
1.266     thorpej  1232:                IP_STATINC(IP_STAT_CANTFORWARD);
1.1       cgd      1233:                m_freem(m);
                   1234:                return;
                   1235:        }
                   1236:        if (ip->ip_ttl <= IPTTLDEC) {
1.13      mycroft  1237:                icmp_error(m, ICMP_TIMXCEED, ICMP_TIMXCEED_INTRANS, dest, 0);
1.1       cgd      1238:                return;
                   1239:        }
                   1240:
1.249     dyoung   1241:        sockaddr_in_init(&u.dst4, &ip->ip_dst, 0);
                   1242:        if ((rt = rtcache_lookup(&ipforward_rt, &u.dst)) == NULL) {
                   1243:                icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, dest, 0);
                   1244:                return;
1.1       cgd      1245:        }
                   1246:
                   1247:        /*
1.34      mycroft  1248:         * Save at most 68 bytes of the packet in case
1.1       cgd      1249:         * we need to generate an ICMP message to the src.
1.119     itojun   1250:         * Pullup to avoid sharing mbuf cluster between m and mcopy.
1.1       cgd      1251:         */
1.155     itojun   1252:        mcopy = m_copym(m, 0, imin(ntohs(ip->ip_len), 68), M_DONTWAIT);
1.119     itojun   1253:        if (mcopy)
                   1254:                mcopy = m_pullup(mcopy, ip->ip_hl << 2);
1.1       cgd      1255:
1.221     christos 1256:        ip->ip_ttl -= IPTTLDEC;
                   1257:
1.1       cgd      1258:        /*
                   1259:         * If forwarding packet using same interface that it came in on,
                   1260:         * perhaps should send a redirect to sender to shortcut a hop.
                   1261:         * Only send redirect if source is sending directly to us,
                   1262:         * and if packet was not source routed (or has any options).
                   1263:         * Also, don't send redirect if forwarding using a default route
                   1264:         * or a route modified by a redirect.
                   1265:         */
                   1266:        if (rt->rt_ifp == m->m_pkthdr.rcvif &&
                   1267:            (rt->rt_flags & (RTF_DYNAMIC|RTF_MODIFIED)) == 0 &&
1.250     dyoung   1268:            !in_nullhost(satocsin(rt_getkey(rt))->sin_addr) &&
1.1       cgd      1269:            ipsendredirects && !srcrt) {
1.19      mycroft  1270:                if (rt->rt_ifa &&
                   1271:                    (ip->ip_src.s_addr & ifatoia(rt->rt_ifa)->ia_subnetmask) ==
                   1272:                    ifatoia(rt->rt_ifa)->ia_subnet) {
1.77      thorpej  1273:                        if (rt->rt_flags & RTF_GATEWAY)
                   1274:                                dest = satosin(rt->rt_gateway)->sin_addr.s_addr;
                   1275:                        else
                   1276:                                dest = ip->ip_dst.s_addr;
                   1277:                        /*
                   1278:                         * Router requirements says to only send host
                   1279:                         * redirects.
                   1280:                         */
                   1281:                        type = ICMP_REDIRECT;
                   1282:                        code = ICMP_REDIRECT_HOST;
1.1       cgd      1283: #ifdef DIAGNOSTIC
1.77      thorpej  1284:                        if (ipprintfs)
                   1285:                                printf("redirect (%d) to %x\n", code,
                   1286:                                    (u_int32_t)dest);
1.1       cgd      1287: #endif
                   1288:                }
                   1289:        }
                   1290:
1.238     dyoung   1291:        error = ip_output(m, NULL, &ipforward_rt,
1.173     jonathan 1292:            (IP_FORWARDING | (ip_directedbcast ? IP_ALLOWBROADCAST : 0)),
1.296     plunky   1293:            NULL, NULL);
1.173     jonathan 1294:
1.1       cgd      1295:        if (error)
1.266     thorpej  1296:                IP_STATINC(IP_STAT_CANTFORWARD);
1.1       cgd      1297:        else {
1.266     thorpej  1298:                uint64_t *ips = IP_STAT_GETREF();
                   1299:                ips[IP_STAT_FORWARD]++;
                   1300:                if (type) {
                   1301:                        ips[IP_STAT_REDIRECTSENT]++;
                   1302:                        IP_STAT_PUTREF();
                   1303:                } else {
                   1304:                        IP_STAT_PUTREF();
1.63      matt     1305:                        if (mcopy) {
                   1306: #ifdef GATEWAY
1.64      thorpej  1307:                                if (mcopy->m_flags & M_CANFASTFWD)
                   1308:                                        ipflow_create(&ipforward_rt, mcopy);
1.63      matt     1309: #endif
1.1       cgd      1310:                                m_freem(mcopy);
1.63      matt     1311:                        }
1.1       cgd      1312:                        return;
                   1313:                }
                   1314:        }
                   1315:        if (mcopy == NULL)
                   1316:                return;
1.13      mycroft  1317:
1.1       cgd      1318:        switch (error) {
                   1319:
                   1320:        case 0:                         /* forwarded, but need redirect */
                   1321:                /* type, code set above */
                   1322:                break;
                   1323:
                   1324:        case ENETUNREACH:               /* shouldn't happen, checked above */
                   1325:        case EHOSTUNREACH:
                   1326:        case ENETDOWN:
                   1327:        case EHOSTDOWN:
                   1328:        default:
                   1329:                type = ICMP_UNREACH;
                   1330:                code = ICMP_UNREACH_HOST;
                   1331:                break;
                   1332:
                   1333:        case EMSGSIZE:
                   1334:                type = ICMP_UNREACH;
                   1335:                code = ICMP_UNREACH_NEEDFRAG;
1.263     cube     1336:
1.274     seanb    1337:                if ((rt = rtcache_validate(&ipforward_rt)) != NULL)
                   1338:                        destmtu = rt->rt_ifp->if_mtu;
1.305     rmind    1339: #ifdef IPSEC
                   1340:                (void)ipsec4_forward(mcopy, &destmtu);
                   1341: #endif
1.266     thorpej  1342:                IP_STATINC(IP_STAT_CANTFRAG);
1.1       cgd      1343:                break;
                   1344:
                   1345:        case ENOBUFS:
1.143     itojun   1346: #if 1
                   1347:                /*
                   1348:                 * a router should not generate ICMP_SOURCEQUENCH as
                   1349:                 * required in RFC1812 Requirements for IP Version 4 Routers.
                   1350:                 * source quench could be a big problem under DoS attacks,
1.149     wiz      1351:                 * or if the underlying interface is rate-limited.
1.143     itojun   1352:                 */
                   1353:                if (mcopy)
                   1354:                        m_freem(mcopy);
                   1355:                return;
                   1356: #else
1.1       cgd      1357:                type = ICMP_SOURCEQUENCH;
                   1358:                code = 0;
                   1359:                break;
1.143     itojun   1360: #endif
1.1       cgd      1361:        }
1.220     christos 1362:        icmp_error(mcopy, type, code, dest, destmtu);
1.44      thorpej  1363: }
                   1364:
                   1365: void
1.211     perry    1366: ip_savecontrol(struct inpcb *inp, struct mbuf **mp, struct ip *ip,
                   1367:     struct mbuf *m)
1.44      thorpej  1368: {
                   1369:
1.283     minskim  1370:        if (inp->inp_socket->so_options & SO_TIMESTAMP
1.278     christos 1371: #ifdef SO_OTIMESTAMP
1.283     minskim  1372:            || inp->inp_socket->so_options & SO_OTIMESTAMP
1.278     christos 1373: #endif
                   1374:            ) {
1.44      thorpej  1375:                struct timeval tv;
                   1376:
                   1377:                microtime(&tv);
1.278     christos 1378: #ifdef SO_OTIMESTAMP
                   1379:                if (inp->inp_socket->so_options & SO_OTIMESTAMP) {
                   1380:                        struct timeval50 tv50;
                   1381:                        timeval_to_timeval50(&tv, &tv50);
                   1382:                        *mp = sbcreatecontrol((void *) &tv50, sizeof(tv50),
                   1383:                            SCM_OTIMESTAMP, SOL_SOCKET);
                   1384:                } else
                   1385: #endif
1.244     christos 1386:                *mp = sbcreatecontrol((void *) &tv, sizeof(tv),
1.44      thorpej  1387:                    SCM_TIMESTAMP, SOL_SOCKET);
                   1388:                if (*mp)
                   1389:                        mp = &(*mp)->m_next;
                   1390:        }
                   1391:        if (inp->inp_flags & INP_RECVDSTADDR) {
1.244     christos 1392:                *mp = sbcreatecontrol((void *) &ip->ip_dst,
1.44      thorpej  1393:                    sizeof(struct in_addr), IP_RECVDSTADDR, IPPROTO_IP);
                   1394:                if (*mp)
                   1395:                        mp = &(*mp)->m_next;
                   1396:        }
1.306     christos 1397:        if (inp->inp_flags & INP_RECVPKTINFO) {
                   1398:                struct in_pktinfo ipi;
1.307     christos 1399:                ipi.ipi_addr = ip->ip_src;
1.306     christos 1400:                ipi.ipi_ifindex = m->m_pkthdr.rcvif->if_index;
                   1401:                *mp = sbcreatecontrol((void *) &ipi,
                   1402:                    sizeof(ipi), IP_RECVPKTINFO, IPPROTO_IP);
                   1403:                if (*mp)
                   1404:                        mp = &(*mp)->m_next;
                   1405:        }
                   1406:        if (inp->inp_flags & INP_PKTINFO) {
                   1407:                struct in_pktinfo ipi;
1.307     christos 1408:                ipi.ipi_addr = ip->ip_dst;
1.306     christos 1409:                ipi.ipi_ifindex = m->m_pkthdr.rcvif->if_index;
                   1410:                *mp = sbcreatecontrol((void *) &ipi,
                   1411:                    sizeof(ipi), IP_PKTINFO, IPPROTO_IP);
                   1412:                if (*mp)
                   1413:                        mp = &(*mp)->m_next;
                   1414:        }
1.44      thorpej  1415: #ifdef notyet
                   1416:        /*
                   1417:         * XXX
                   1418:         * Moving these out of udp_input() made them even more broken
                   1419:         * than they already were.
                   1420:         *      - fenner@parc.xerox.com
                   1421:         */
                   1422:        /* options were tossed already */
                   1423:        if (inp->inp_flags & INP_RECVOPTS) {
1.244     christos 1424:                *mp = sbcreatecontrol((void *) opts_deleted_above,
1.44      thorpej  1425:                    sizeof(struct in_addr), IP_RECVOPTS, IPPROTO_IP);
                   1426:                if (*mp)
                   1427:                        mp = &(*mp)->m_next;
                   1428:        }
                   1429:        /* ip_srcroute doesn't do what we want here, need to fix */
                   1430:        if (inp->inp_flags & INP_RECVRETOPTS) {
1.244     christos 1431:                *mp = sbcreatecontrol((void *) ip_srcroute(),
1.44      thorpej  1432:                    sizeof(struct in_addr), IP_RECVRETOPTS, IPPROTO_IP);
                   1433:                if (*mp)
                   1434:                        mp = &(*mp)->m_next;
                   1435:        }
                   1436: #endif
                   1437:        if (inp->inp_flags & INP_RECVIF) {
                   1438:                struct sockaddr_dl sdl;
                   1439:
1.252     dyoung   1440:                sockaddr_dl_init(&sdl, sizeof(sdl),
                   1441:                    (m->m_pkthdr.rcvif != NULL)
                   1442:                        ?  m->m_pkthdr.rcvif->if_index
                   1443:                        : 0,
                   1444:                        0, NULL, 0, NULL, 0);
1.251     dyoung   1445:                *mp = sbcreatecontrol(&sdl, sdl.sdl_len, IP_RECVIF, IPPROTO_IP);
1.44      thorpej  1446:                if (*mp)
                   1447:                        mp = &(*mp)->m_next;
                   1448:        }
1.282     minskim  1449:        if (inp->inp_flags & INP_RECVTTL) {
                   1450:                *mp = sbcreatecontrol((void *) &ip->ip_ttl,
                   1451:                    sizeof(uint8_t), IP_RECVTTL, IPPROTO_IP);
                   1452:                if (*mp)
                   1453:                        mp = &(*mp)->m_next;
                   1454:        }
1.13      mycroft  1455: }
                   1456:
1.189     atatat   1457: /*
1.228     elad     1458:  * sysctl helper routine for net.inet.ip.forwsrcrt.
                   1459:  */
                   1460: static int
                   1461: sysctl_net_inet_ip_forwsrcrt(SYSCTLFN_ARGS)
                   1462: {
                   1463:        int error, tmp;
                   1464:        struct sysctlnode node;
                   1465:
                   1466:        node = *rnode;
                   1467:        tmp = ip_forwsrcrt;
                   1468:        node.sysctl_data = &tmp;
                   1469:        error = sysctl_lookup(SYSCTLFN_CALL(&node));
                   1470:        if (error || newp == NULL)
                   1471:                return (error);
                   1472:
1.280     elad     1473:        error = kauth_authorize_network(l->l_cred, KAUTH_NETWORK_FORWSRCRT,
                   1474:            0, NULL, NULL, NULL);
                   1475:        if (error)
                   1476:                return (error);
1.228     elad     1477:
                   1478:        ip_forwsrcrt = tmp;
                   1479:
                   1480:        return (0);
                   1481: }
                   1482:
                   1483: /*
1.189     atatat   1484:  * sysctl helper routine for net.inet.ip.mtudisctimeout.  checks the
                   1485:  * range of the new value and tweaks timers if it changes.
                   1486:  */
                   1487: static int
                   1488: sysctl_net_inet_ip_pmtudto(SYSCTLFN_ARGS)
1.13      mycroft  1489: {
1.189     atatat   1490:        int error, tmp;
                   1491:        struct sysctlnode node;
                   1492:
                   1493:        node = *rnode;
                   1494:        tmp = ip_mtudisc_timeout;
                   1495:        node.sysctl_data = &tmp;
                   1496:        error = sysctl_lookup(SYSCTLFN_CALL(&node));
                   1497:        if (error || newp == NULL)
                   1498:                return (error);
                   1499:        if (tmp < 0)
                   1500:                return (EINVAL);
1.52      thorpej  1501:
1.273     matt     1502:        mutex_enter(softnet_lock);
                   1503:
1.189     atatat   1504:        ip_mtudisc_timeout = tmp;
                   1505:        rt_timer_queue_change(ip_mtudisc_timeout_q, ip_mtudisc_timeout);
                   1506:
1.273     matt     1507:        mutex_exit(softnet_lock);
                   1508:
1.189     atatat   1509:        return (0);
                   1510: }
1.54      lukem    1511:
1.65      matt     1512: #ifdef GATEWAY
1.189     atatat   1513: /*
1.247     liamjfoy 1514:  * sysctl helper routine for net.inet.ip.maxflows.
1.189     atatat   1515:  */
                   1516: static int
                   1517: sysctl_net_inet_ip_maxflows(SYSCTLFN_ARGS)
                   1518: {
1.273     matt     1519:        int error;
1.67      thorpej  1520:
1.273     matt     1521:        error = sysctl_lookup(SYSCTLFN_CALL(rnode));
                   1522:        if (error || newp == NULL)
                   1523:                return (error);
                   1524:
                   1525:        mutex_enter(softnet_lock);
                   1526:        KERNEL_LOCK(1, NULL);
1.212     perry    1527:
1.265     thorpej  1528:        ipflow_prune();
1.273     matt     1529:
                   1530:        KERNEL_UNLOCK_ONE(NULL);
                   1531:        mutex_exit(softnet_lock);
1.144     martin   1532:
1.189     atatat   1533:        return (0);
                   1534: }
1.248     liamjfoy 1535:
                   1536: static int
                   1537: sysctl_net_inet_ip_hashsize(SYSCTLFN_ARGS)
1.283     minskim  1538: {
1.248     liamjfoy 1539:        int error, tmp;
                   1540:        struct sysctlnode node;
                   1541:
                   1542:        node = *rnode;
                   1543:        tmp = ip_hashsize;
                   1544:        node.sysctl_data = &tmp;
                   1545:        error = sysctl_lookup(SYSCTLFN_CALL(&node));
                   1546:        if (error || newp == NULL)
                   1547:                return (error);
                   1548:
                   1549:        if ((tmp & (tmp - 1)) == 0 && tmp != 0) {
                   1550:                /*
                   1551:                 * Can only fail due to malloc()
                   1552:                 */
1.273     matt     1553:                mutex_enter(softnet_lock);
                   1554:                KERNEL_LOCK(1, NULL);
                   1555:
                   1556:                error = ipflow_invalidate_all(tmp);
                   1557:
                   1558:                KERNEL_UNLOCK_ONE(NULL);
                   1559:                mutex_exit(softnet_lock);
                   1560:
1.248     liamjfoy 1561:        } else {
                   1562:                /*
                   1563:                 * EINVAL if not a power of 2
                   1564:                 */
1.273     matt     1565:                error = EINVAL;
1.283     minskim  1566:        }
1.248     liamjfoy 1567:
1.273     matt     1568:        return error;
1.248     liamjfoy 1569: }
1.189     atatat   1570: #endif /* GATEWAY */
1.117     tron     1571:
1.266     thorpej  1572: static int
                   1573: sysctl_net_inet_ip_stats(SYSCTLFN_ARGS)
                   1574: {
                   1575:
1.271     thorpej  1576:        return (NETSTAT_SYSCTL(ipstat_percpu, IP_NSTATS));
1.266     thorpej  1577: }
1.131     itojun   1578:
1.284     pooka    1579: static void
                   1580: sysctl_net_inet_ip_setup(struct sysctllog **clog)
1.189     atatat   1581: {
                   1582:        extern int subnetsarelocal, hostzeroisbroadcast;
1.180     jonathan 1583:
1.197     atatat   1584:        sysctl_createv(clog, 0, NULL, NULL,
                   1585:                       CTLFLAG_PERMANENT,
1.203     atatat   1586:                       CTLTYPE_NODE, "inet",
                   1587:                       SYSCTL_DESCR("PF_INET related settings"),
1.189     atatat   1588:                       NULL, 0, NULL, 0,
                   1589:                       CTL_NET, PF_INET, CTL_EOL);
1.197     atatat   1590:        sysctl_createv(clog, 0, NULL, NULL,
                   1591:                       CTLFLAG_PERMANENT,
1.203     atatat   1592:                       CTLTYPE_NODE, "ip",
                   1593:                       SYSCTL_DESCR("IPv4 related settings"),
1.189     atatat   1594:                       NULL, 0, NULL, 0,
                   1595:                       CTL_NET, PF_INET, IPPROTO_IP, CTL_EOL);
1.212     perry    1596:
1.197     atatat   1597:        sysctl_createv(clog, 0, NULL, NULL,
                   1598:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.203     atatat   1599:                       CTLTYPE_INT, "forwarding",
                   1600:                       SYSCTL_DESCR("Enable forwarding of INET datagrams"),
1.189     atatat   1601:                       NULL, 0, &ipforwarding, 0,
                   1602:                       CTL_NET, PF_INET, IPPROTO_IP,
                   1603:                       IPCTL_FORWARDING, CTL_EOL);
1.197     atatat   1604:        sysctl_createv(clog, 0, NULL, NULL,
                   1605:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.203     atatat   1606:                       CTLTYPE_INT, "redirect",
                   1607:                       SYSCTL_DESCR("Enable sending of ICMP redirect messages"),
1.189     atatat   1608:                       NULL, 0, &ipsendredirects, 0,
                   1609:                       CTL_NET, PF_INET, IPPROTO_IP,
                   1610:                       IPCTL_SENDREDIRECTS, CTL_EOL);
1.197     atatat   1611:        sysctl_createv(clog, 0, NULL, NULL,
                   1612:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.203     atatat   1613:                       CTLTYPE_INT, "ttl",
                   1614:                       SYSCTL_DESCR("Default TTL for an INET datagram"),
1.189     atatat   1615:                       NULL, 0, &ip_defttl, 0,
                   1616:                       CTL_NET, PF_INET, IPPROTO_IP,
                   1617:                       IPCTL_DEFTTL, CTL_EOL);
                   1618: #ifdef IPCTL_DEFMTU
1.197     atatat   1619:        sysctl_createv(clog, 0, NULL, NULL,
                   1620:                       CTLFLAG_PERMANENT /* |CTLFLAG_READWRITE? */,
1.203     atatat   1621:                       CTLTYPE_INT, "mtu",
                   1622:                       SYSCTL_DESCR("Default MTA for an INET route"),
1.189     atatat   1623:                       NULL, 0, &ip_mtu, 0,
                   1624:                       CTL_NET, PF_INET, IPPROTO_IP,
                   1625:                       IPCTL_DEFMTU, CTL_EOL);
                   1626: #endif /* IPCTL_DEFMTU */
1.197     atatat   1627:        sysctl_createv(clog, 0, NULL, NULL,
1.228     elad     1628:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.203     atatat   1629:                       CTLTYPE_INT, "forwsrcrt",
                   1630:                       SYSCTL_DESCR("Enable forwarding of source-routed "
                   1631:                                    "datagrams"),
1.228     elad     1632:                       sysctl_net_inet_ip_forwsrcrt, 0, &ip_forwsrcrt, 0,
1.189     atatat   1633:                       CTL_NET, PF_INET, IPPROTO_IP,
                   1634:                       IPCTL_FORWSRCRT, CTL_EOL);
1.197     atatat   1635:        sysctl_createv(clog, 0, NULL, NULL,
                   1636:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.203     atatat   1637:                       CTLTYPE_INT, "directed-broadcast",
                   1638:                       SYSCTL_DESCR("Enable forwarding of broadcast datagrams"),
1.189     atatat   1639:                       NULL, 0, &ip_directedbcast, 0,
                   1640:                       CTL_NET, PF_INET, IPPROTO_IP,
                   1641:                       IPCTL_DIRECTEDBCAST, CTL_EOL);
1.197     atatat   1642:        sysctl_createv(clog, 0, NULL, NULL,
                   1643:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.203     atatat   1644:                       CTLTYPE_INT, "allowsrcrt",
                   1645:                       SYSCTL_DESCR("Accept source-routed datagrams"),
1.189     atatat   1646:                       NULL, 0, &ip_allowsrcrt, 0,
                   1647:                       CTL_NET, PF_INET, IPPROTO_IP,
                   1648:                       IPCTL_ALLOWSRCRT, CTL_EOL);
1.197     atatat   1649:        sysctl_createv(clog, 0, NULL, NULL,
                   1650:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.203     atatat   1651:                       CTLTYPE_INT, "subnetsarelocal",
                   1652:                       SYSCTL_DESCR("Whether logical subnets are considered "
                   1653:                                    "local"),
1.189     atatat   1654:                       NULL, 0, &subnetsarelocal, 0,
                   1655:                       CTL_NET, PF_INET, IPPROTO_IP,
                   1656:                       IPCTL_SUBNETSARELOCAL, CTL_EOL);
1.197     atatat   1657:        sysctl_createv(clog, 0, NULL, NULL,
                   1658:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.203     atatat   1659:                       CTLTYPE_INT, "mtudisc",
                   1660:                       SYSCTL_DESCR("Use RFC1191 Path MTU Discovery"),
1.189     atatat   1661:                       NULL, 0, &ip_mtudisc, 0,
                   1662:                       CTL_NET, PF_INET, IPPROTO_IP,
                   1663:                       IPCTL_MTUDISC, CTL_EOL);
1.197     atatat   1664:        sysctl_createv(clog, 0, NULL, NULL,
                   1665:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.203     atatat   1666:                       CTLTYPE_INT, "anonportmin",
                   1667:                       SYSCTL_DESCR("Lowest ephemeral port number to assign"),
1.189     atatat   1668:                       sysctl_net_inet_ip_ports, 0, &anonportmin, 0,
                   1669:                       CTL_NET, PF_INET, IPPROTO_IP,
                   1670:                       IPCTL_ANONPORTMIN, CTL_EOL);
1.197     atatat   1671:        sysctl_createv(clog, 0, NULL, NULL,
                   1672:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.203     atatat   1673:                       CTLTYPE_INT, "anonportmax",
                   1674:                       SYSCTL_DESCR("Highest ephemeral port number to assign"),
1.189     atatat   1675:                       sysctl_net_inet_ip_ports, 0, &anonportmax, 0,
                   1676:                       CTL_NET, PF_INET, IPPROTO_IP,
                   1677:                       IPCTL_ANONPORTMAX, CTL_EOL);
1.197     atatat   1678:        sysctl_createv(clog, 0, NULL, NULL,
                   1679:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.203     atatat   1680:                       CTLTYPE_INT, "mtudisctimeout",
                   1681:                       SYSCTL_DESCR("Lifetime of a Path MTU Discovered route"),
1.300     dsl      1682:                       sysctl_net_inet_ip_pmtudto, 0, (void *)&ip_mtudisc_timeout, 0,
1.189     atatat   1683:                       CTL_NET, PF_INET, IPPROTO_IP,
                   1684:                       IPCTL_MTUDISCTIMEOUT, CTL_EOL);
                   1685: #ifdef GATEWAY
1.197     atatat   1686:        sysctl_createv(clog, 0, NULL, NULL,
                   1687:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.203     atatat   1688:                       CTLTYPE_INT, "maxflows",
                   1689:                       SYSCTL_DESCR("Number of flows for fast forwarding"),
1.189     atatat   1690:                       sysctl_net_inet_ip_maxflows, 0, &ip_maxflows, 0,
                   1691:                       CTL_NET, PF_INET, IPPROTO_IP,
                   1692:                       IPCTL_MAXFLOWS, CTL_EOL);
1.248     liamjfoy 1693:        sysctl_createv(clog, 0, NULL, NULL,
                   1694:                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1695:                        CTLTYPE_INT, "hashsize",
                   1696:                        SYSCTL_DESCR("Size of hash table for fast forwarding (IPv4)"),
                   1697:                        sysctl_net_inet_ip_hashsize, 0, &ip_hashsize, 0,
                   1698:                        CTL_NET, PF_INET, IPPROTO_IP,
                   1699:                        CTL_CREATE, CTL_EOL);
1.189     atatat   1700: #endif /* GATEWAY */
1.197     atatat   1701:        sysctl_createv(clog, 0, NULL, NULL,
                   1702:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.203     atatat   1703:                       CTLTYPE_INT, "hostzerobroadcast",
                   1704:                       SYSCTL_DESCR("All zeroes address is broadcast address"),
1.189     atatat   1705:                       NULL, 0, &hostzeroisbroadcast, 0,
                   1706:                       CTL_NET, PF_INET, IPPROTO_IP,
                   1707:                       IPCTL_HOSTZEROBROADCAST, CTL_EOL);
                   1708: #if NGIF > 0
1.197     atatat   1709:        sysctl_createv(clog, 0, NULL, NULL,
                   1710:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.203     atatat   1711:                       CTLTYPE_INT, "gifttl",
                   1712:                       SYSCTL_DESCR("Default TTL for a gif tunnel datagram"),
1.189     atatat   1713:                       NULL, 0, &ip_gif_ttl, 0,
                   1714:                       CTL_NET, PF_INET, IPPROTO_IP,
                   1715:                       IPCTL_GIF_TTL, CTL_EOL);
                   1716: #endif /* NGIF */
                   1717: #ifndef IPNOPRIVPORTS
1.197     atatat   1718:        sysctl_createv(clog, 0, NULL, NULL,
                   1719:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.203     atatat   1720:                       CTLTYPE_INT, "lowportmin",
                   1721:                       SYSCTL_DESCR("Lowest privileged ephemeral port number "
                   1722:                                    "to assign"),
1.189     atatat   1723:                       sysctl_net_inet_ip_ports, 0, &lowportmin, 0,
                   1724:                       CTL_NET, PF_INET, IPPROTO_IP,
                   1725:                       IPCTL_LOWPORTMIN, CTL_EOL);
1.197     atatat   1726:        sysctl_createv(clog, 0, NULL, NULL,
                   1727:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.203     atatat   1728:                       CTLTYPE_INT, "lowportmax",
                   1729:                       SYSCTL_DESCR("Highest privileged ephemeral port number "
                   1730:                                    "to assign"),
1.189     atatat   1731:                       sysctl_net_inet_ip_ports, 0, &lowportmax, 0,
                   1732:                       CTL_NET, PF_INET, IPPROTO_IP,
                   1733:                       IPCTL_LOWPORTMAX, CTL_EOL);
                   1734: #endif /* IPNOPRIVPORTS */
                   1735: #if NGRE > 0
1.197     atatat   1736:        sysctl_createv(clog, 0, NULL, NULL,
                   1737:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.203     atatat   1738:                       CTLTYPE_INT, "grettl",
                   1739:                       SYSCTL_DESCR("Default TTL for a gre tunnel datagram"),
1.189     atatat   1740:                       NULL, 0, &ip_gre_ttl, 0,
                   1741:                       CTL_NET, PF_INET, IPPROTO_IP,
                   1742:                       IPCTL_GRE_TTL, CTL_EOL);
                   1743: #endif /* NGRE */
1.197     atatat   1744:        sysctl_createv(clog, 0, NULL, NULL,
                   1745:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.203     atatat   1746:                       CTLTYPE_INT, "checkinterface",
                   1747:                       SYSCTL_DESCR("Enable receive side of Strong ES model "
                   1748:                                    "from RFC1122"),
1.189     atatat   1749:                       NULL, 0, &ip_checkinterface, 0,
                   1750:                       CTL_NET, PF_INET, IPPROTO_IP,
                   1751:                       IPCTL_CHECKINTERFACE, CTL_EOL);
1.197     atatat   1752:        sysctl_createv(clog, 0, NULL, NULL,
                   1753:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.203     atatat   1754:                       CTLTYPE_INT, "random_id",
                   1755:                       SYSCTL_DESCR("Assign random ip_id values"),
1.189     atatat   1756:                       NULL, 0, &ip_do_randomid, 0,
                   1757:                       CTL_NET, PF_INET, IPPROTO_IP,
                   1758:                       IPCTL_RANDOMID, CTL_EOL);
1.206     thorpej  1759:        sysctl_createv(clog, 0, NULL, NULL,
                   1760:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1761:                       CTLTYPE_INT, "do_loopback_cksum",
                   1762:                       SYSCTL_DESCR("Perform IP checksum on loopback"),
                   1763:                       NULL, 0, &ip_do_loopback_cksum, 0,
                   1764:                       CTL_NET, PF_INET, IPPROTO_IP,
                   1765:                       IPCTL_LOOPBACKCKSUM, CTL_EOL);
1.219     elad     1766:        sysctl_createv(clog, 0, NULL, NULL,
                   1767:                       CTLFLAG_PERMANENT,
                   1768:                       CTLTYPE_STRUCT, "stats",
                   1769:                       SYSCTL_DESCR("IP statistics"),
1.266     thorpej  1770:                       sysctl_net_inet_ip_stats, 0, NULL, 0,
1.219     elad     1771:                       CTL_NET, PF_INET, IPPROTO_IP, IPCTL_STATS,
                   1772:                       CTL_EOL);
1.301     christos 1773:
                   1774:        /* anonportalgo RFC6056 subtree */
1.302     christos 1775:        const struct sysctlnode *portalgo_node;
                   1776:        sysctl_createv(clog, 0, NULL, &portalgo_node,
1.301     christos 1777:                       CTLFLAG_PERMANENT,
                   1778:                       CTLTYPE_NODE, "anonportalgo",
                   1779:                       SYSCTL_DESCR("Anonymous Port Algorithm Selection (RFC 6056)"),
                   1780:                       NULL, 0, NULL, 0,
                   1781:                       CTL_NET, PF_INET, IPPROTO_IP, CTL_CREATE, CTL_EOL);
1.302     christos 1782:        sysctl_createv(clog, 0, &portalgo_node, NULL,
1.301     christos 1783:                       CTLFLAG_PERMANENT,
                   1784:                       CTLTYPE_STRING, "available",
                   1785:                       SYSCTL_DESCR("available algorithms"),
1.302     christos 1786:                       sysctl_portalgo_available, 0, NULL, PORTALGO_MAXLEN,
1.301     christos 1787:                       CTL_CREATE, CTL_EOL);
1.302     christos 1788:        sysctl_createv(clog, 0, &portalgo_node, NULL,
1.301     christos 1789:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1790:                       CTLTYPE_STRING, "selected",
                   1791:                       SYSCTL_DESCR("selected algorithm"),
1.303     christos 1792:                       sysctl_portalgo_selected4, 0, NULL, PORTALGO_MAXLEN,
                   1793:                       CTL_CREATE, CTL_EOL);
                   1794:        sysctl_createv(clog, 0, &portalgo_node, NULL,
                   1795:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1796:                       CTLTYPE_STRUCT, "reserve",
                   1797:                       SYSCTL_DESCR("bitmap of reserved ports"),
                   1798:                       sysctl_portalgo_reserve4, 0, NULL, 0,
1.301     christos 1799:                       CTL_CREATE, CTL_EOL);
1.1       cgd      1800: }
1.266     thorpej  1801:
                   1802: void
                   1803: ip_statinc(u_int stat)
                   1804: {
                   1805:
                   1806:        KASSERT(stat < IP_NSTATS);
                   1807:        IP_STATINC(stat);
                   1808: }

CVSweb <webmaster@jp.NetBSD.org>