[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.306

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

CVSweb <webmaster@jp.NetBSD.org>