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

1.82.2.5! he          1: /*     $NetBSD: ip_input.c,v 1.82.2.4 2000/02/12 18:10:24 he Exp $     */
1.76      thorpej     2:
                      3: /*-
                      4:  * Copyright (c) 1998 The NetBSD Foundation, Inc.
                      5:  * All rights reserved.
                      6:  *
                      7:  * This code is derived from software contributed to The NetBSD Foundation
                      8:  * by Public Access Networks Corporation ("Panix").  It was developed under
                      9:  * contract to Panix by Eric Haszlakiewicz and Thor Lancelot Simon.
                     10:  *
                     11:  * Redistribution and use in source and binary forms, with or without
                     12:  * modification, are permitted provided that the following conditions
                     13:  * are met:
                     14:  * 1. Redistributions of source code must retain the above copyright
                     15:  *    notice, this list of conditions and the following disclaimer.
                     16:  * 2. Redistributions in binary form must reproduce the above copyright
                     17:  *    notice, this list of conditions and the following disclaimer in the
                     18:  *    documentation and/or other materials provided with the distribution.
                     19:  * 3. All advertising materials mentioning features or use of this software
                     20:  *    must display the following acknowledgement:
                     21:  *     This product includes software developed by the NetBSD
                     22:  *     Foundation, Inc. and its contributors.
                     23:  * 4. Neither the name of The NetBSD Foundation nor the names of its
                     24:  *    contributors may be used to endorse or promote products derived
                     25:  *    from this software without specific prior written permission.
                     26:  *
                     27:  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
                     28:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     29:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     30:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
                     31:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     32:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     33:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     34:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     35:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     36:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     37:  * POSSIBILITY OF SUCH DAMAGE.
                     38:  */
1.14      cgd        39:
1.1       cgd        40: /*
1.13      mycroft    41:  * Copyright (c) 1982, 1986, 1988, 1993
                     42:  *     The Regents of the University of California.  All rights reserved.
1.1       cgd        43:  *
                     44:  * Redistribution and use in source and binary forms, with or without
                     45:  * modification, are permitted provided that the following conditions
                     46:  * are met:
                     47:  * 1. Redistributions of source code must retain the above copyright
                     48:  *    notice, this list of conditions and the following disclaimer.
                     49:  * 2. Redistributions in binary form must reproduce the above copyright
                     50:  *    notice, this list of conditions and the following disclaimer in the
                     51:  *    documentation and/or other materials provided with the distribution.
                     52:  * 3. All advertising materials mentioning features or use of this software
                     53:  *    must display the following acknowledgement:
                     54:  *     This product includes software developed by the University of
                     55:  *     California, Berkeley and its contributors.
                     56:  * 4. Neither the name of the University nor the names of its contributors
                     57:  *    may be used to endorse or promote products derived from this software
                     58:  *    without specific prior written permission.
                     59:  *
                     60:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     61:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     62:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     63:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     64:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     65:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     66:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     67:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     68:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     69:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     70:  * SUCH DAMAGE.
                     71:  *
1.14      cgd        72:  *     @(#)ip_input.c  8.2 (Berkeley) 1/4/94
1.1       cgd        73:  */
1.55      scottr     74:
1.62      matt       75: #include "opt_gateway.h"
1.69      mrg        76: #include "opt_pfil_hooks.h"
1.55      scottr     77: #include "opt_mrouting.h"
1.1       cgd        78:
1.5       mycroft    79: #include <sys/param.h>
                     80: #include <sys/systm.h>
                     81: #include <sys/malloc.h>
                     82: #include <sys/mbuf.h>
                     83: #include <sys/domain.h>
                     84: #include <sys/protosw.h>
                     85: #include <sys/socket.h>
1.44      thorpej    86: #include <sys/socketvar.h>
1.5       mycroft    87: #include <sys/errno.h>
                     88: #include <sys/time.h>
                     89: #include <sys/kernel.h>
1.28      christos   90: #include <sys/proc.h>
1.72      thorpej    91: #include <sys/pool.h>
1.28      christos   92:
                     93: #include <vm/vm.h>
                     94: #include <sys/sysctl.h>
1.1       cgd        95:
1.5       mycroft    96: #include <net/if.h>
1.44      thorpej    97: #include <net/if_dl.h>
1.5       mycroft    98: #include <net/route.h>
1.45      mrg        99: #include <net/pfil.h>
1.1       cgd       100:
1.5       mycroft   101: #include <netinet/in.h>
                    102: #include <netinet/in_systm.h>
                    103: #include <netinet/ip.h>
                    104: #include <netinet/in_pcb.h>
                    105: #include <netinet/in_var.h>
                    106: #include <netinet/ip_var.h>
                    107: #include <netinet/ip_icmp.h>
1.44      thorpej   108:
1.1       cgd       109: #ifndef        IPFORWARDING
                    110: #ifdef GATEWAY
                    111: #define        IPFORWARDING    1       /* forward IP packets not for us */
                    112: #else /* GATEWAY */
                    113: #define        IPFORWARDING    0       /* don't forward IP packets not for us */
                    114: #endif /* GATEWAY */
                    115: #endif /* IPFORWARDING */
                    116: #ifndef        IPSENDREDIRECTS
                    117: #define        IPSENDREDIRECTS 1
                    118: #endif
1.26      thorpej   119: #ifndef IPFORWSRCRT
1.47      cjs       120: #define        IPFORWSRCRT     1       /* forward source-routed packets */
                    121: #endif
                    122: #ifndef IPALLOWSRCRT
1.48      mrg       123: #define        IPALLOWSRCRT    1       /* allow source-routed packets */
1.26      thorpej   124: #endif
1.53      kml       125: #ifndef IPMTUDISC
                    126: #define IPMTUDISC      0
                    127: #endif
1.60      kml       128: #ifndef IPMTUDISCTIMEOUT
1.61      kml       129: #define IPMTUDISCTIMEOUT (10 * 60)     /* as per RFC 1191 */
1.60      kml       130: #endif
1.53      kml       131:
1.27      thorpej   132: /*
                    133:  * Note: DIRECTED_BROADCAST is handled this way so that previous
                    134:  * configuration using this option will Just Work.
                    135:  */
                    136: #ifndef IPDIRECTEDBCAST
                    137: #ifdef DIRECTED_BROADCAST
                    138: #define IPDIRECTEDBCAST        1
                    139: #else
                    140: #define        IPDIRECTEDBCAST 0
                    141: #endif /* DIRECTED_BROADCAST */
                    142: #endif /* IPDIRECTEDBCAST */
1.1       cgd       143: int    ipforwarding = IPFORWARDING;
                    144: int    ipsendredirects = IPSENDREDIRECTS;
1.13      mycroft   145: int    ip_defttl = IPDEFTTL;
1.26      thorpej   146: int    ip_forwsrcrt = IPFORWSRCRT;
1.27      thorpej   147: int    ip_directedbcast = IPDIRECTEDBCAST;
1.47      cjs       148: int    ip_allowsrcrt = IPALLOWSRCRT;
1.53      kml       149: int    ip_mtudisc = IPMTUDISC;
1.60      kml       150: u_int  ip_mtudisc_timeout = IPMTUDISCTIMEOUT;
1.1       cgd       151: #ifdef DIAGNOSTIC
                    152: int    ipprintfs = 0;
                    153: #endif
                    154:
1.60      kml       155: struct rttimer_queue *ip_mtudisc_timeout_q = NULL;
                    156:
1.1       cgd       157: extern struct domain inetdomain;
                    158: extern struct protosw inetsw[];
                    159: u_char ip_protox[IPPROTO_MAX];
                    160: int    ipqmaxlen = IFQ_MAXLEN;
1.22      mycroft   161: struct in_ifaddrhead in_ifaddr;
1.57      tls       162: struct in_ifaddrhashhead *in_ifaddrhashtbl;
1.13      mycroft   163: struct ifqueue ipintrq;
1.63      matt      164: struct ipstat  ipstat;
                    165: u_int16_t      ip_id;
                    166: int    ip_defttl;
1.75      thorpej   167:
1.63      matt      168: struct ipqhead ipq;
1.75      thorpej   169: int    ipq_locked;
                    170:
                    171: static __inline int ipq_lock_try __P((void));
                    172: static __inline void ipq_unlock __P((void));
                    173:
                    174: static __inline int
                    175: ipq_lock_try()
                    176: {
                    177:        int s;
                    178:
                    179:        s = splimp();
                    180:        if (ipq_locked) {
                    181:                splx(s);
                    182:                return (0);
                    183:        }
                    184:        ipq_locked = 1;
                    185:        splx(s);
                    186:        return (1);
                    187: }
                    188:
                    189: static __inline void
                    190: ipq_unlock()
                    191: {
                    192:        int s;
                    193:
                    194:        s = splimp();
                    195:        ipq_locked = 0;
                    196:        splx(s);
                    197: }
                    198:
                    199: #ifdef DIAGNOSTIC
                    200: #define        IPQ_LOCK()                                                      \
                    201: do {                                                                   \
                    202:        if (ipq_lock_try() == 0) {                                      \
                    203:                printf("%s:%d: ipq already locked\n", __FILE__, __LINE__); \
                    204:                panic("ipq_lock");                                      \
                    205:        }                                                               \
                    206: } while (0)
                    207: #define        IPQ_LOCK_CHECK()                                                \
                    208: do {                                                                   \
                    209:        if (ipq_locked == 0) {                                          \
                    210:                printf("%s:%d: ipq lock not held\n", __FILE__, __LINE__); \
                    211:                panic("ipq lock check");                                \
                    212:        }                                                               \
                    213: } while (0)
                    214: #else
                    215: #define        IPQ_LOCK()              (void) ipq_lock_try()
                    216: #define        IPQ_LOCK_CHECK()        /* nothing */
                    217: #endif
                    218:
                    219: #define        IPQ_UNLOCK()            ipq_unlock()
1.1       cgd       220:
1.72      thorpej   221: struct pool ipqent_pool;
                    222:
1.1       cgd       223: /*
                    224:  * We need to save the IP options in case a protocol wants to respond
                    225:  * to an incoming packet over the same route if the packet got here
                    226:  * using IP source routing.  This allows connection establishment and
                    227:  * maintenance when the remote end is on a network that is not known
                    228:  * to us.
                    229:  */
                    230: int    ip_nhops = 0;
                    231: static struct ip_srcrt {
                    232:        struct  in_addr dst;                    /* final destination */
                    233:        char    nop;                            /* one NOP to align */
                    234:        char    srcopt[IPOPT_OFFSET + 1];       /* OPTVAL, OLEN and OFFSET */
                    235:        struct  in_addr route[MAX_IPOPTLEN/sizeof(struct in_addr)];
                    236: } ip_srcrt;
                    237:
1.13      mycroft   238: static void save_rte __P((u_char *, struct in_addr));
1.35      mycroft   239:
1.1       cgd       240: /*
                    241:  * IP initialization: fill in IP protocol switch table.
                    242:  * All protocols not implemented in kernel go to raw IP protocol handler.
                    243:  */
1.8       mycroft   244: void
1.1       cgd       245: ip_init()
                    246: {
                    247:        register struct protosw *pr;
                    248:        register int i;
                    249:
1.72      thorpej   250:        pool_init(&ipqent_pool, sizeof(struct ipqent), 0, 0, 0, "ipqepl",
                    251:            0, NULL, NULL, M_IPQ);
                    252:
1.1       cgd       253:        pr = pffindproto(PF_INET, IPPROTO_RAW, SOCK_RAW);
                    254:        if (pr == 0)
                    255:                panic("ip_init");
                    256:        for (i = 0; i < IPPROTO_MAX; i++)
                    257:                ip_protox[i] = pr - inetsw;
                    258:        for (pr = inetdomain.dom_protosw;
                    259:            pr < inetdomain.dom_protoswNPROTOSW; pr++)
                    260:                if (pr->pr_domain->dom_family == PF_INET &&
                    261:                    pr->pr_protocol && pr->pr_protocol != IPPROTO_RAW)
                    262:                        ip_protox[pr->pr_protocol] = pr - inetsw;
1.25      cgd       263:        LIST_INIT(&ipq);
1.1       cgd       264:        ip_id = time.tv_sec & 0xffff;
                    265:        ipintrq.ifq_maxlen = ipqmaxlen;
1.22      mycroft   266:        TAILQ_INIT(&in_ifaddr);
1.57      tls       267:        in_ifaddrhashtbl =
                    268:            hashinit(IN_IFADDR_HASH_SIZE, M_IFADDR, M_WAITOK, &in_ifaddrhash);
1.60      kml       269:        if (ip_mtudisc != 0)
                    270:                ip_mtudisc_timeout_q =
                    271:                    rt_timer_queue_create(ip_mtudisc_timeout);
1.73      thorpej   272: #ifdef GATEWAY
                    273:        ipflow_init();
                    274: #endif
1.1       cgd       275: }
                    276:
                    277: struct sockaddr_in ipaddr = { sizeof(ipaddr), AF_INET };
                    278: struct route ipforward_rt;
                    279:
                    280: /*
                    281:  * Ip input routine.  Checksum and byte swap header.  If fragmented
                    282:  * try to reassemble.  Process options.  Pass to next level.
                    283:  */
1.8       mycroft   284: void
1.1       cgd       285: ipintr()
                    286: {
1.33      mrg       287:        register struct ip *ip = NULL;
1.1       cgd       288:        register struct mbuf *m;
                    289:        register struct ipq *fp;
                    290:        register struct in_ifaddr *ia;
1.57      tls       291:        register struct ifaddr *ifa;
1.25      cgd       292:        struct ipqent *ipqe;
1.35      mycroft   293:        int hlen = 0, mff, len, s;
1.36      mrg       294: #ifdef PFIL_HOOKS
1.33      mrg       295:        struct packet_filter_hook *pfh;
                    296:        struct mbuf *m0;
1.43      mrg       297:        int rv;
1.36      mrg       298: #endif /* PFIL_HOOKS */
1.1       cgd       299:
                    300: next:
                    301:        /*
                    302:         * Get next datagram off input queue and get IP header
                    303:         * in first mbuf.
                    304:         */
                    305:        s = splimp();
                    306:        IF_DEQUEUE(&ipintrq, m);
                    307:        splx(s);
1.13      mycroft   308:        if (m == 0)
1.1       cgd       309:                return;
                    310: #ifdef DIAGNOSTIC
                    311:        if ((m->m_flags & M_PKTHDR) == 0)
                    312:                panic("ipintr no HDR");
                    313: #endif
                    314:        /*
                    315:         * If no IP addresses have been set yet but the interfaces
                    316:         * are receiving, can't do anything with incoming packets yet.
                    317:         */
1.22      mycroft   318:        if (in_ifaddr.tqh_first == 0)
1.1       cgd       319:                goto bad;
                    320:        ipstat.ips_total++;
                    321:        if (m->m_len < sizeof (struct ip) &&
                    322:            (m = m_pullup(m, sizeof (struct ip))) == 0) {
                    323:                ipstat.ips_toosmall++;
                    324:                goto next;
                    325:        }
                    326:        ip = mtod(m, struct ip *);
1.13      mycroft   327:        if (ip->ip_v != IPVERSION) {
                    328:                ipstat.ips_badvers++;
                    329:                goto bad;
                    330:        }
1.1       cgd       331:        hlen = ip->ip_hl << 2;
                    332:        if (hlen < sizeof(struct ip)) { /* minimum header length */
                    333:                ipstat.ips_badhlen++;
                    334:                goto bad;
                    335:        }
                    336:        if (hlen > m->m_len) {
                    337:                if ((m = m_pullup(m, hlen)) == 0) {
                    338:                        ipstat.ips_badhlen++;
                    339:                        goto next;
                    340:                }
                    341:                ip = mtod(m, struct ip *);
                    342:        }
1.82.2.4  he        343:
                    344:        /*
                    345:         * RFC1122: packets with a multicast source address are
                    346:         * not allowed.
                    347:         */
                    348:        if (IN_MULTICAST(ip->ip_src.s_addr)) {
                    349:                /* XXX stat */
                    350:                goto bad;
                    351:        }
                    352:
1.78      mycroft   353:        if (in_cksum(m, hlen) != 0) {
1.1       cgd       354:                ipstat.ips_badsum++;
                    355:                goto bad;
                    356:        }
                    357:
                    358:        /*
                    359:         * Convert fields to host representation.
                    360:         */
                    361:        NTOHS(ip->ip_len);
                    362:        NTOHS(ip->ip_off);
1.35      mycroft   363:        len = ip->ip_len;
1.81      proff     364:
                    365:        /*
                    366:         * Check for additional length bogosity
                    367:         */
                    368:        if (len < hlen)
                    369:        {
                    370:                ipstat.ips_badlen++;
                    371:                goto bad;
                    372:        }
1.1       cgd       373:
                    374:        /*
                    375:         * Check that the amount of data in the buffers
                    376:         * is as at least much as the IP header would have us expect.
                    377:         * Trim mbufs if longer than we expect.
                    378:         * Drop packet if shorter than we expect.
                    379:         */
1.35      mycroft   380:        if (m->m_pkthdr.len < len) {
1.1       cgd       381:                ipstat.ips_tooshort++;
                    382:                goto bad;
                    383:        }
1.35      mycroft   384:        if (m->m_pkthdr.len > len) {
1.1       cgd       385:                if (m->m_len == m->m_pkthdr.len) {
1.35      mycroft   386:                        m->m_len = len;
                    387:                        m->m_pkthdr.len = len;
1.1       cgd       388:                } else
1.35      mycroft   389:                        m_adj(m, len - m->m_pkthdr.len);
1.1       cgd       390:        }
                    391:
1.64      thorpej   392:        /*
                    393:         * Assume that we can create a fast-forward IP flow entry
                    394:         * based on this packet.
                    395:         */
                    396:        m->m_flags |= M_CANFASTFWD;
                    397:
1.36      mrg       398: #ifdef PFIL_HOOKS
1.33      mrg       399:        /*
1.64      thorpej   400:         * Run through list of hooks for input packets.  If there are any
                    401:         * filters which require that additional packets in the flow are
                    402:         * not fast-forwarded, they must clear the M_CANFASTFWD flag.
                    403:         * Note that filters must _never_ set this flag, as another filter
                    404:         * in the list may have previously cleared it.
1.33      mrg       405:         */
                    406:        m0 = m;
1.59      mrg       407:        for (pfh = pfil_hook_get(PFIL_IN); pfh; pfh = pfh->pfil_link.tqe_next)
1.33      mrg       408:                if (pfh->pfil_func) {
1.43      mrg       409:                        rv = pfh->pfil_func(ip, hlen, m->m_pkthdr.rcvif, 0, &m0);
                    410:                        if (rv)
1.40      veego     411:                                goto next;
1.68      sommerfe  412:                        m = m0;
                    413:                        if (m == NULL)
                    414:                                goto next;
                    415:                        ip = mtod(m, struct ip *);
1.33      mrg       416:                }
1.36      mrg       417: #endif /* PFIL_HOOKS */
1.33      mrg       418:
1.1       cgd       419:        /*
                    420:         * Process options and, if not destined for us,
                    421:         * ship it on.  ip_dooptions returns 1 when an
                    422:         * error was detected (causing an icmp message
                    423:         * to be sent and the original packet to be freed).
                    424:         */
                    425:        ip_nhops = 0;           /* for source routed packets */
                    426:        if (hlen > sizeof (struct ip) && ip_dooptions(m))
                    427:                goto next;
                    428:
                    429:        /*
                    430:         * Check our list of addresses, to see if the packet is for us.
                    431:         */
1.57      tls       432:        INADDR_TO_IA(ip->ip_dst, ia);
1.82.2.2  perry     433:        if (ia != NULL)
                    434:                goto ours;
1.57      tls       435:        if (m->m_pkthdr.rcvif->if_flags & IFF_BROADCAST) {
                    436:                for (ifa = m->m_pkthdr.rcvif->if_addrlist.tqh_first;
                    437:                    ifa != NULL; ifa = ifa->ifa_list.tqe_next) {
                    438:                        if (ifa->ifa_addr->sa_family != AF_INET) continue;
                    439:                        ia = ifatoia(ifa);
1.35      mycroft   440:                        if (in_hosteq(ip->ip_dst, ia->ia_broadaddr.sin_addr) ||
                    441:                            in_hosteq(ip->ip_dst, ia->ia_netbroadcast) ||
1.20      mycroft   442:                            /*
                    443:                             * Look for all-0's host part (old broadcast addr),
                    444:                             * either for subnet or net.
                    445:                             */
                    446:                            ip->ip_dst.s_addr == ia->ia_subnet ||
1.18      mycroft   447:                            ip->ip_dst.s_addr == ia->ia_net)
1.1       cgd       448:                                goto ours;
1.57      tls       449:                        /*
                    450:                         * An interface with IP address zero accepts
                    451:                         * all packets that arrive on that interface.
                    452:                         */
                    453:                        if (in_nullhost(ia->ia_addr.sin_addr))
                    454:                                goto ours;
1.1       cgd       455:                }
                    456:        }
1.18      mycroft   457:        if (IN_MULTICAST(ip->ip_dst.s_addr)) {
1.4       hpeyerl   458:                struct in_multi *inm;
                    459: #ifdef MROUTING
                    460:                extern struct socket *ip_mrouter;
1.10      brezak    461:
                    462:                if (m->m_flags & M_EXT) {
                    463:                        if ((m = m_pullup(m, hlen)) == 0) {
                    464:                                ipstat.ips_toosmall++;
                    465:                                goto next;
                    466:                        }
                    467:                        ip = mtod(m, struct ip *);
                    468:                }
1.4       hpeyerl   469:
                    470:                if (ip_mrouter) {
                    471:                        /*
                    472:                         * If we are acting as a multicast router, all
                    473:                         * incoming multicast packets are passed to the
                    474:                         * kernel-level multicast forwarding function.
                    475:                         * The packet is returned (relatively) intact; if
                    476:                         * ip_mforward() returns a non-zero value, the packet
                    477:                         * must be discarded, else it may be accepted below.
                    478:                         *
                    479:                         * (The IP ident field is put in the same byte order
                    480:                         * as expected when ip_mforward() is called from
                    481:                         * ip_output().)
                    482:                         */
1.13      mycroft   483:                        if (ip_mforward(m, m->m_pkthdr.rcvif) != 0) {
                    484:                                ipstat.ips_cantforward++;
1.4       hpeyerl   485:                                m_freem(m);
                    486:                                goto next;
                    487:                        }
                    488:
                    489:                        /*
                    490:                         * The process-level routing demon needs to receive
                    491:                         * all multicast IGMP packets, whether or not this
                    492:                         * host belongs to their destination groups.
                    493:                         */
                    494:                        if (ip->ip_p == IPPROTO_IGMP)
                    495:                                goto ours;
1.13      mycroft   496:                        ipstat.ips_forward++;
1.4       hpeyerl   497:                }
                    498: #endif
                    499:                /*
                    500:                 * See if we belong to the destination multicast group on the
                    501:                 * arrival interface.
                    502:                 */
                    503:                IN_LOOKUP_MULTI(ip->ip_dst, m->m_pkthdr.rcvif, inm);
                    504:                if (inm == NULL) {
1.13      mycroft   505:                        ipstat.ips_cantforward++;
1.4       hpeyerl   506:                        m_freem(m);
                    507:                        goto next;
                    508:                }
                    509:                goto ours;
                    510:        }
1.19      mycroft   511:        if (ip->ip_dst.s_addr == INADDR_BROADCAST ||
1.35      mycroft   512:            in_nullhost(ip->ip_dst))
1.1       cgd       513:                goto ours;
                    514:
                    515:        /*
                    516:         * Not for us; forward if possible and desirable.
                    517:         */
                    518:        if (ipforwarding == 0) {
                    519:                ipstat.ips_cantforward++;
                    520:                m_freem(m);
                    521:        } else
                    522:                ip_forward(m, 0);
                    523:        goto next;
                    524:
                    525: ours:
                    526:        /*
                    527:         * If offset or IP_MF are set, must reassemble.
                    528:         * Otherwise, nothing need be done.
                    529:         * (We could look in the reassembly queue to see
                    530:         * if the packet was previously fragmented,
                    531:         * but it's not worth the time; just let them time out.)
                    532:         */
1.37      perry     533:        if (ip->ip_off & ~(IP_DF|IP_RF)) {
1.1       cgd       534:                /*
                    535:                 * Look for queue of fragments
                    536:                 * of this datagram.
                    537:                 */
1.75      thorpej   538:                IPQ_LOCK();
1.25      cgd       539:                for (fp = ipq.lh_first; fp != NULL; fp = fp->ipq_q.le_next)
1.1       cgd       540:                        if (ip->ip_id == fp->ipq_id &&
1.35      mycroft   541:                            in_hosteq(ip->ip_src, fp->ipq_src) &&
                    542:                            in_hosteq(ip->ip_dst, fp->ipq_dst) &&
1.1       cgd       543:                            ip->ip_p == fp->ipq_p)
                    544:                                goto found;
                    545:                fp = 0;
                    546: found:
                    547:
                    548:                /*
                    549:                 * Adjust ip_len to not reflect header,
1.25      cgd       550:                 * set ipqe_mff if more fragments are expected,
1.1       cgd       551:                 * convert offset of this to bytes.
                    552:                 */
                    553:                ip->ip_len -= hlen;
1.25      cgd       554:                mff = (ip->ip_off & IP_MF) != 0;
                    555:                if (mff) {
1.16      cgd       556:                        /*
                    557:                         * Make sure that fragments have a data length
                    558:                         * that's a non-zero multiple of 8 bytes.
                    559:                         */
1.17      cgd       560:                        if (ip->ip_len == 0 || (ip->ip_len & 0x7) != 0) {
1.16      cgd       561:                                ipstat.ips_badfrags++;
1.75      thorpej   562:                                IPQ_UNLOCK();
1.16      cgd       563:                                goto bad;
                    564:                        }
                    565:                }
1.1       cgd       566:                ip->ip_off <<= 3;
                    567:
                    568:                /*
                    569:                 * If datagram marked as having more fragments
                    570:                 * or if this is not the first fragment,
                    571:                 * attempt reassembly; if it succeeds, proceed.
                    572:                 */
1.25      cgd       573:                if (mff || ip->ip_off) {
1.1       cgd       574:                        ipstat.ips_fragments++;
1.72      thorpej   575:                        ipqe = pool_get(&ipqent_pool, PR_NOWAIT);
1.25      cgd       576:                        if (ipqe == NULL) {
                    577:                                ipstat.ips_rcvmemdrop++;
1.75      thorpej   578:                                IPQ_UNLOCK();
1.25      cgd       579:                                goto bad;
                    580:                        }
                    581:                        ipqe->ipqe_mff = mff;
1.50      thorpej   582:                        ipqe->ipqe_m = m;
1.25      cgd       583:                        ipqe->ipqe_ip = ip;
1.50      thorpej   584:                        m = ip_reass(ipqe, fp);
1.75      thorpej   585:                        if (m == 0) {
                    586:                                IPQ_UNLOCK();
1.1       cgd       587:                                goto next;
1.75      thorpej   588:                        }
1.13      mycroft   589:                        ipstat.ips_reassembled++;
1.50      thorpej   590:                        ip = mtod(m, struct ip *);
1.74      thorpej   591:                        hlen = ip->ip_hl << 2;
1.79      mycroft   592:                        ip->ip_len += hlen;
1.1       cgd       593:                } else
                    594:                        if (fp)
                    595:                                ip_freef(fp);
1.75      thorpej   596:                IPQ_UNLOCK();
1.79      mycroft   597:        }
1.1       cgd       598:
                    599:        /*
                    600:         * Switch out to protocol's input routine.
                    601:         */
1.82      aidan     602: #if IFA_STATS
                    603:        ia->ia_ifa.ifa_data.ifad_inbytes += ip->ip_len;
                    604: #endif
1.1       cgd       605:        ipstat.ips_delivered++;
                    606:        (*inetsw[ip_protox[ip->ip_p]].pr_input)(m, hlen);
                    607:        goto next;
                    608: bad:
                    609:        m_freem(m);
                    610:        goto next;
                    611: }
                    612:
                    613: /*
                    614:  * Take incoming datagram fragment and try to
                    615:  * reassemble it into whole datagram.  If a chain for
                    616:  * reassembly of this datagram already exists, then it
                    617:  * is given as fp; otherwise have to make a chain.
                    618:  */
1.50      thorpej   619: struct mbuf *
1.25      cgd       620: ip_reass(ipqe, fp)
                    621:        register struct ipqent *ipqe;
1.1       cgd       622:        register struct ipq *fp;
                    623: {
1.50      thorpej   624:        register struct mbuf *m = ipqe->ipqe_m;
1.25      cgd       625:        register struct ipqent *nq, *p, *q;
                    626:        struct ip *ip;
1.1       cgd       627:        struct mbuf *t;
1.25      cgd       628:        int hlen = ipqe->ipqe_ip->ip_hl << 2;
1.1       cgd       629:        int i, next;
                    630:
1.75      thorpej   631:        IPQ_LOCK_CHECK();
                    632:
1.1       cgd       633:        /*
                    634:         * Presence of header sizes in mbufs
                    635:         * would confuse code below.
                    636:         */
                    637:        m->m_data += hlen;
                    638:        m->m_len -= hlen;
                    639:
                    640:        /*
                    641:         * If first fragment to arrive, create a reassembly queue.
                    642:         */
                    643:        if (fp == 0) {
1.50      thorpej   644:                MALLOC(fp, struct ipq *, sizeof (struct ipq),
                    645:                    M_FTABLE, M_NOWAIT);
                    646:                if (fp == NULL)
1.1       cgd       647:                        goto dropfrag;
1.25      cgd       648:                LIST_INSERT_HEAD(&ipq, fp, ipq_q);
1.1       cgd       649:                fp->ipq_ttl = IPFRAGTTL;
1.25      cgd       650:                fp->ipq_p = ipqe->ipqe_ip->ip_p;
                    651:                fp->ipq_id = ipqe->ipqe_ip->ip_id;
                    652:                LIST_INIT(&fp->ipq_fragq);
                    653:                fp->ipq_src = ipqe->ipqe_ip->ip_src;
                    654:                fp->ipq_dst = ipqe->ipqe_ip->ip_dst;
                    655:                p = NULL;
1.1       cgd       656:                goto insert;
                    657:        }
                    658:
                    659:        /*
                    660:         * Find a segment which begins after this one does.
                    661:         */
1.25      cgd       662:        for (p = NULL, q = fp->ipq_fragq.lh_first; q != NULL;
                    663:            p = q, q = q->ipqe_q.le_next)
                    664:                if (q->ipqe_ip->ip_off > ipqe->ipqe_ip->ip_off)
1.1       cgd       665:                        break;
                    666:
                    667:        /*
                    668:         * If there is a preceding segment, it may provide some of
                    669:         * our data already.  If so, drop the data from the incoming
                    670:         * segment.  If it provides all of our data, drop us.
                    671:         */
1.25      cgd       672:        if (p != NULL) {
                    673:                i = p->ipqe_ip->ip_off + p->ipqe_ip->ip_len -
                    674:                    ipqe->ipqe_ip->ip_off;
1.1       cgd       675:                if (i > 0) {
1.25      cgd       676:                        if (i >= ipqe->ipqe_ip->ip_len)
1.1       cgd       677:                                goto dropfrag;
1.50      thorpej   678:                        m_adj(ipqe->ipqe_m, i);
1.25      cgd       679:                        ipqe->ipqe_ip->ip_off += i;
                    680:                        ipqe->ipqe_ip->ip_len -= i;
1.1       cgd       681:                }
                    682:        }
                    683:
                    684:        /*
                    685:         * While we overlap succeeding segments trim them or,
                    686:         * if they are completely covered, dequeue them.
                    687:         */
1.25      cgd       688:        for (; q != NULL && ipqe->ipqe_ip->ip_off + ipqe->ipqe_ip->ip_len >
                    689:            q->ipqe_ip->ip_off; q = nq) {
                    690:                i = (ipqe->ipqe_ip->ip_off + ipqe->ipqe_ip->ip_len) -
                    691:                    q->ipqe_ip->ip_off;
                    692:                if (i < q->ipqe_ip->ip_len) {
                    693:                        q->ipqe_ip->ip_len -= i;
                    694:                        q->ipqe_ip->ip_off += i;
1.50      thorpej   695:                        m_adj(q->ipqe_m, i);
1.1       cgd       696:                        break;
                    697:                }
1.25      cgd       698:                nq = q->ipqe_q.le_next;
1.50      thorpej   699:                m_freem(q->ipqe_m);
1.25      cgd       700:                LIST_REMOVE(q, ipqe_q);
1.72      thorpej   701:                pool_put(&ipqent_pool, q);
1.1       cgd       702:        }
                    703:
                    704: insert:
                    705:        /*
                    706:         * Stick new segment in its place;
                    707:         * check for complete reassembly.
                    708:         */
1.25      cgd       709:        if (p == NULL) {
                    710:                LIST_INSERT_HEAD(&fp->ipq_fragq, ipqe, ipqe_q);
                    711:        } else {
                    712:                LIST_INSERT_AFTER(p, ipqe, ipqe_q);
                    713:        }
1.1       cgd       714:        next = 0;
1.25      cgd       715:        for (p = NULL, q = fp->ipq_fragq.lh_first; q != NULL;
                    716:            p = q, q = q->ipqe_q.le_next) {
                    717:                if (q->ipqe_ip->ip_off != next)
1.1       cgd       718:                        return (0);
1.25      cgd       719:                next += q->ipqe_ip->ip_len;
1.1       cgd       720:        }
1.25      cgd       721:        if (p->ipqe_mff)
1.1       cgd       722:                return (0);
                    723:
                    724:        /*
1.41      thorpej   725:         * Reassembly is complete.  Check for a bogus message size and
                    726:         * concatenate fragments.
1.1       cgd       727:         */
1.25      cgd       728:        q = fp->ipq_fragq.lh_first;
                    729:        ip = q->ipqe_ip;
1.41      thorpej   730:        if ((next + (ip->ip_hl << 2)) > IP_MAXPACKET) {
                    731:                ipstat.ips_toolong++;
                    732:                ip_freef(fp);
                    733:                return (0);
                    734:        }
1.50      thorpej   735:        m = q->ipqe_m;
1.1       cgd       736:        t = m->m_next;
                    737:        m->m_next = 0;
                    738:        m_cat(m, t);
1.25      cgd       739:        nq = q->ipqe_q.le_next;
1.72      thorpej   740:        pool_put(&ipqent_pool, q);
1.25      cgd       741:        for (q = nq; q != NULL; q = nq) {
1.50      thorpej   742:                t = q->ipqe_m;
1.25      cgd       743:                nq = q->ipqe_q.le_next;
1.72      thorpej   744:                pool_put(&ipqent_pool, q);
1.1       cgd       745:                m_cat(m, t);
                    746:        }
                    747:
                    748:        /*
                    749:         * Create header for new ip packet by
                    750:         * modifying header of first packet;
                    751:         * dequeue and discard fragment reassembly header.
                    752:         * Make header visible.
                    753:         */
                    754:        ip->ip_len = next;
1.25      cgd       755:        ip->ip_src = fp->ipq_src;
                    756:        ip->ip_dst = fp->ipq_dst;
                    757:        LIST_REMOVE(fp, ipq_q);
1.50      thorpej   758:        FREE(fp, M_FTABLE);
1.1       cgd       759:        m->m_len += (ip->ip_hl << 2);
                    760:        m->m_data -= (ip->ip_hl << 2);
                    761:        /* some debugging cruft by sklower, below, will go away soon */
                    762:        if (m->m_flags & M_PKTHDR) { /* XXX this should be done elsewhere */
                    763:                register int plen = 0;
1.50      thorpej   764:                for (t = m; t; t = t->m_next)
                    765:                        plen += t->m_len;
                    766:                m->m_pkthdr.len = plen;
1.1       cgd       767:        }
1.50      thorpej   768:        return (m);
1.1       cgd       769:
                    770: dropfrag:
                    771:        ipstat.ips_fragdropped++;
                    772:        m_freem(m);
1.72      thorpej   773:        pool_put(&ipqent_pool, ipqe);
1.1       cgd       774:        return (0);
                    775: }
                    776:
                    777: /*
                    778:  * Free a fragment reassembly header and all
                    779:  * associated datagrams.
                    780:  */
1.8       mycroft   781: void
1.1       cgd       782: ip_freef(fp)
                    783:        struct ipq *fp;
                    784: {
1.25      cgd       785:        register struct ipqent *q, *p;
1.1       cgd       786:
1.75      thorpej   787:        IPQ_LOCK_CHECK();
                    788:
1.25      cgd       789:        for (q = fp->ipq_fragq.lh_first; q != NULL; q = p) {
                    790:                p = q->ipqe_q.le_next;
1.50      thorpej   791:                m_freem(q->ipqe_m);
1.25      cgd       792:                LIST_REMOVE(q, ipqe_q);
1.72      thorpej   793:                pool_put(&ipqent_pool, q);
1.1       cgd       794:        }
1.25      cgd       795:        LIST_REMOVE(fp, ipq_q);
1.50      thorpej   796:        FREE(fp, M_FTABLE);
1.1       cgd       797: }
                    798:
                    799: /*
                    800:  * IP timer processing;
                    801:  * if a timer expires on a reassembly
                    802:  * queue, discard it.
                    803:  */
1.8       mycroft   804: void
1.1       cgd       805: ip_slowtimo()
                    806: {
1.25      cgd       807:        register struct ipq *fp, *nfp;
1.24      mycroft   808:        int s = splsoftnet();
1.1       cgd       809:
1.75      thorpej   810:        IPQ_LOCK();
1.25      cgd       811:        for (fp = ipq.lh_first; fp != NULL; fp = nfp) {
                    812:                nfp = fp->ipq_q.le_next;
                    813:                if (--fp->ipq_ttl == 0) {
1.1       cgd       814:                        ipstat.ips_fragtimeout++;
1.25      cgd       815:                        ip_freef(fp);
1.1       cgd       816:                }
                    817:        }
1.75      thorpej   818:        IPQ_UNLOCK();
1.63      matt      819: #ifdef GATEWAY
                    820:        ipflow_slowtimo();
                    821: #endif
1.1       cgd       822:        splx(s);
                    823: }
                    824:
                    825: /*
                    826:  * Drain off all datagram fragments.
                    827:  */
1.8       mycroft   828: void
1.1       cgd       829: ip_drain()
                    830: {
                    831:
1.75      thorpej   832:        /*
                    833:         * We may be called from a device's interrupt context.  If
                    834:         * the ipq is already busy, just bail out now.
                    835:         */
                    836:        if (ipq_lock_try() == 0)
                    837:                return;
                    838:
1.25      cgd       839:        while (ipq.lh_first != NULL) {
1.1       cgd       840:                ipstat.ips_fragdropped++;
1.25      cgd       841:                ip_freef(ipq.lh_first);
1.1       cgd       842:        }
1.75      thorpej   843:
                    844:        IPQ_UNLOCK();
1.1       cgd       845: }
                    846:
                    847: /*
                    848:  * Do option processing on a datagram,
                    849:  * possibly discarding it if bad options are encountered,
                    850:  * or forwarding it if source-routed.
                    851:  * Returns 1 if packet has been forwarded/freed,
                    852:  * 0 if the packet should be processed further.
                    853:  */
1.8       mycroft   854: int
1.1       cgd       855: ip_dooptions(m)
                    856:        struct mbuf *m;
                    857: {
                    858:        register struct ip *ip = mtod(m, struct ip *);
1.82.2.5! he        859:        register u_char *cp, *cp0;
1.1       cgd       860:        register struct ip_timestamp *ipt;
                    861:        register struct in_ifaddr *ia;
                    862:        int opt, optlen, cnt, off, code, type = ICMP_PARAMPROB, forward = 0;
1.82.2.5! he        863:        struct in_addr dst;
1.1       cgd       864:        n_time ntime;
                    865:
1.13      mycroft   866:        dst = ip->ip_dst;
1.1       cgd       867:        cp = (u_char *)(ip + 1);
                    868:        cnt = (ip->ip_hl << 2) - sizeof (struct ip);
                    869:        for (; cnt > 0; cnt -= optlen, cp += optlen) {
                    870:                opt = cp[IPOPT_OPTVAL];
                    871:                if (opt == IPOPT_EOL)
                    872:                        break;
                    873:                if (opt == IPOPT_NOP)
                    874:                        optlen = 1;
                    875:                else {
                    876:                        optlen = cp[IPOPT_OLEN];
                    877:                        if (optlen <= 0 || optlen > cnt) {
                    878:                                code = &cp[IPOPT_OLEN] - (u_char *)ip;
                    879:                                goto bad;
                    880:                        }
                    881:                }
                    882:                switch (opt) {
                    883:
                    884:                default:
                    885:                        break;
                    886:
                    887:                /*
                    888:                 * Source routing with record.
                    889:                 * Find interface with current destination address.
                    890:                 * If none on this machine then drop if strictly routed,
                    891:                 * or do nothing if loosely routed.
                    892:                 * Record interface address and bring up next address
                    893:                 * component.  If strictly routed make sure next
                    894:                 * address is on directly accessible net.
                    895:                 */
                    896:                case IPOPT_LSRR:
                    897:                case IPOPT_SSRR:
1.47      cjs       898:                        if (ip_allowsrcrt == 0) {
                    899:                                type = ICMP_UNREACH;
                    900:                                code = ICMP_UNREACH_NET_PROHIB;
                    901:                                goto bad;
                    902:                        }
1.1       cgd       903:                        if ((off = cp[IPOPT_OFFSET]) < IPOPT_MINOFF) {
                    904:                                code = &cp[IPOPT_OFFSET] - (u_char *)ip;
                    905:                                goto bad;
                    906:                        }
                    907:                        ipaddr.sin_addr = ip->ip_dst;
1.19      mycroft   908:                        ia = ifatoia(ifa_ifwithaddr(sintosa(&ipaddr)));
1.1       cgd       909:                        if (ia == 0) {
                    910:                                if (opt == IPOPT_SSRR) {
                    911:                                        type = ICMP_UNREACH;
                    912:                                        code = ICMP_UNREACH_SRCFAIL;
                    913:                                        goto bad;
                    914:                                }
                    915:                                /*
                    916:                                 * Loose routing, and not at next destination
                    917:                                 * yet; nothing to do except forward.
                    918:                                 */
                    919:                                break;
                    920:                        }
                    921:                        off--;                  /* 0 origin */
                    922:                        if (off > optlen - sizeof(struct in_addr)) {
                    923:                                /*
                    924:                                 * End of source route.  Should be for us.
                    925:                                 */
                    926:                                save_rte(cp, ip->ip_src);
                    927:                                break;
                    928:                        }
                    929:                        /*
                    930:                         * locate outgoing interface
                    931:                         */
                    932:                        bcopy((caddr_t)(cp + off), (caddr_t)&ipaddr.sin_addr,
                    933:                            sizeof(ipaddr.sin_addr));
                    934:                        if (opt == IPOPT_SSRR) {
                    935: #define        INA     struct in_ifaddr *
                    936: #define        SA      struct sockaddr *
1.29      mrg       937:                            ia = (INA)ifa_ifwithladdr((SA)&ipaddr);
1.1       cgd       938:                        } else
                    939:                                ia = ip_rtaddr(ipaddr.sin_addr);
                    940:                        if (ia == 0) {
                    941:                                type = ICMP_UNREACH;
                    942:                                code = ICMP_UNREACH_SRCFAIL;
                    943:                                goto bad;
                    944:                        }
                    945:                        ip->ip_dst = ipaddr.sin_addr;
1.20      mycroft   946:                        bcopy((caddr_t)&ia->ia_addr.sin_addr,
1.1       cgd       947:                            (caddr_t)(cp + off), sizeof(struct in_addr));
                    948:                        cp[IPOPT_OFFSET] += sizeof(struct in_addr);
1.13      mycroft   949:                        /*
                    950:                         * Let ip_intr's mcast routing check handle mcast pkts
                    951:                         */
1.18      mycroft   952:                        forward = !IN_MULTICAST(ip->ip_dst.s_addr);
1.1       cgd       953:                        break;
                    954:
                    955:                case IPOPT_RR:
                    956:                        if ((off = cp[IPOPT_OFFSET]) < IPOPT_MINOFF) {
                    957:                                code = &cp[IPOPT_OFFSET] - (u_char *)ip;
                    958:                                goto bad;
                    959:                        }
                    960:                        /*
                    961:                         * If no space remains, ignore.
                    962:                         */
                    963:                        off--;                  /* 0 origin */
                    964:                        if (off > optlen - sizeof(struct in_addr))
                    965:                                break;
                    966:                        bcopy((caddr_t)(&ip->ip_dst), (caddr_t)&ipaddr.sin_addr,
                    967:                            sizeof(ipaddr.sin_addr));
                    968:                        /*
                    969:                         * locate outgoing interface; if we're the destination,
                    970:                         * use the incoming interface (should be same).
                    971:                         */
                    972:                        if ((ia = (INA)ifa_ifwithaddr((SA)&ipaddr)) == 0 &&
                    973:                            (ia = ip_rtaddr(ipaddr.sin_addr)) == 0) {
                    974:                                type = ICMP_UNREACH;
                    975:                                code = ICMP_UNREACH_HOST;
                    976:                                goto bad;
                    977:                        }
1.20      mycroft   978:                        bcopy((caddr_t)&ia->ia_addr.sin_addr,
1.1       cgd       979:                            (caddr_t)(cp + off), sizeof(struct in_addr));
                    980:                        cp[IPOPT_OFFSET] += sizeof(struct in_addr);
                    981:                        break;
                    982:
                    983:                case IPOPT_TS:
                    984:                        code = cp - (u_char *)ip;
                    985:                        ipt = (struct ip_timestamp *)cp;
                    986:                        if (ipt->ipt_len < 5)
                    987:                                goto bad;
1.15      cgd       988:                        if (ipt->ipt_ptr > ipt->ipt_len - sizeof (int32_t)) {
1.1       cgd       989:                                if (++ipt->ipt_oflw == 0)
                    990:                                        goto bad;
                    991:                                break;
                    992:                        }
1.82.2.5! he        993:                        cp0 = (cp + ipt->ipt_ptr - 1);
1.1       cgd       994:                        switch (ipt->ipt_flg) {
                    995:
                    996:                        case IPOPT_TS_TSONLY:
                    997:                                break;
                    998:
                    999:                        case IPOPT_TS_TSANDADDR:
1.66      thorpej  1000:                                if (ipt->ipt_ptr - 1 + sizeof(n_time) +
1.1       cgd      1001:                                    sizeof(struct in_addr) > ipt->ipt_len)
                   1002:                                        goto bad;
1.13      mycroft  1003:                                ipaddr.sin_addr = dst;
                   1004:                                ia = (INA)ifaof_ifpforaddr((SA)&ipaddr,
                   1005:                                                            m->m_pkthdr.rcvif);
                   1006:                                if (ia == 0)
                   1007:                                        continue;
1.82.2.5! he       1008:                                bcopy(&ia->ia_addr.sin_addr,
        !          1009:                                    cp0, sizeof(struct in_addr));
1.1       cgd      1010:                                ipt->ipt_ptr += sizeof(struct in_addr);
                   1011:                                break;
                   1012:
                   1013:                        case IPOPT_TS_PRESPEC:
1.66      thorpej  1014:                                if (ipt->ipt_ptr - 1 + sizeof(n_time) +
1.1       cgd      1015:                                    sizeof(struct in_addr) > ipt->ipt_len)
                   1016:                                        goto bad;
1.82.2.5! he       1017:                                bcopy(cp0, &ipaddr.sin_addr,
1.1       cgd      1018:                                    sizeof(struct in_addr));
                   1019:                                if (ifa_ifwithaddr((SA)&ipaddr) == 0)
                   1020:                                        continue;
                   1021:                                ipt->ipt_ptr += sizeof(struct in_addr);
                   1022:                                break;
                   1023:
                   1024:                        default:
                   1025:                                goto bad;
                   1026:                        }
                   1027:                        ntime = iptime();
1.82.2.5! he       1028:                        cp0 = (u_char *) &ntime;        /* XXX GCC BUG */
        !          1029:                        bcopy(cp0, (caddr_t)cp + ipt->ipt_ptr - 1,
1.1       cgd      1030:                            sizeof(n_time));
                   1031:                        ipt->ipt_ptr += sizeof(n_time);
                   1032:                }
                   1033:        }
                   1034:        if (forward) {
1.26      thorpej  1035:                if (ip_forwsrcrt == 0) {
                   1036:                        type = ICMP_UNREACH;
                   1037:                        code = ICMP_UNREACH_SRCFAIL;
                   1038:                        goto bad;
                   1039:                }
1.1       cgd      1040:                ip_forward(m, 1);
                   1041:                return (1);
1.13      mycroft  1042:        }
                   1043:        return (0);
1.1       cgd      1044: bad:
1.13      mycroft  1045:        icmp_error(m, type, code, 0, 0);
                   1046:        ipstat.ips_badoptions++;
1.1       cgd      1047:        return (1);
                   1048: }
                   1049:
                   1050: /*
                   1051:  * Given address of next destination (final or next hop),
                   1052:  * return internet address info of interface to be used to get there.
                   1053:  */
                   1054: struct in_ifaddr *
                   1055: ip_rtaddr(dst)
                   1056:         struct in_addr dst;
                   1057: {
                   1058:        register struct sockaddr_in *sin;
                   1059:
1.19      mycroft  1060:        sin = satosin(&ipforward_rt.ro_dst);
1.1       cgd      1061:
1.35      mycroft  1062:        if (ipforward_rt.ro_rt == 0 || !in_hosteq(dst, sin->sin_addr)) {
1.1       cgd      1063:                if (ipforward_rt.ro_rt) {
                   1064:                        RTFREE(ipforward_rt.ro_rt);
                   1065:                        ipforward_rt.ro_rt = 0;
                   1066:                }
                   1067:                sin->sin_family = AF_INET;
                   1068:                sin->sin_len = sizeof(*sin);
                   1069:                sin->sin_addr = dst;
                   1070:
                   1071:                rtalloc(&ipforward_rt);
                   1072:        }
                   1073:        if (ipforward_rt.ro_rt == 0)
                   1074:                return ((struct in_ifaddr *)0);
1.19      mycroft  1075:        return (ifatoia(ipforward_rt.ro_rt->rt_ifa));
1.1       cgd      1076: }
                   1077:
                   1078: /*
                   1079:  * Save incoming source route for use in replies,
                   1080:  * to be picked up later by ip_srcroute if the receiver is interested.
                   1081:  */
1.13      mycroft  1082: void
1.1       cgd      1083: save_rte(option, dst)
                   1084:        u_char *option;
                   1085:        struct in_addr dst;
                   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.1       cgd      1093: #endif
                   1094:        if (olen > sizeof(ip_srcrt) - (1 + sizeof(dst)))
                   1095:                return;
                   1096:        bcopy((caddr_t)option, (caddr_t)ip_srcrt.srcopt, olen);
                   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 *
                   1107: ip_srcroute()
                   1108: {
                   1109:        register struct in_addr *p, *q;
                   1110:        register struct mbuf *m;
                   1111:
                   1112:        if (ip_nhops == 0)
                   1113:                return ((struct mbuf *)0);
                   1114:        m = m_get(M_DONTWAIT, MT_SOOPTS);
                   1115:        if (m == 0)
                   1116:                return ((struct mbuf *)0);
                   1117:
1.13      mycroft  1118: #define OPTSIZ (sizeof(ip_srcrt.nop) + sizeof(ip_srcrt.srcopt))
1.1       cgd      1119:
                   1120:        /* length is (nhops+1)*sizeof(addr) + sizeof(nop + srcrt header) */
                   1121:        m->m_len = ip_nhops * sizeof(struct in_addr) + sizeof(struct in_addr) +
                   1122:            OPTSIZ;
                   1123: #ifdef DIAGNOSTIC
                   1124:        if (ipprintfs)
1.39      christos 1125:                printf("ip_srcroute: nhops %d mlen %d", ip_nhops, m->m_len);
1.1       cgd      1126: #endif
                   1127:
                   1128:        /*
                   1129:         * First save first hop for return route
                   1130:         */
                   1131:        p = &ip_srcrt.route[ip_nhops - 1];
                   1132:        *(mtod(m, struct in_addr *)) = *p--;
                   1133: #ifdef DIAGNOSTIC
                   1134:        if (ipprintfs)
1.39      christos 1135:                printf(" hops %x", ntohl(mtod(m, struct in_addr *)->s_addr));
1.1       cgd      1136: #endif
                   1137:
                   1138:        /*
                   1139:         * Copy option fields and padding (nop) to mbuf.
                   1140:         */
                   1141:        ip_srcrt.nop = IPOPT_NOP;
                   1142:        ip_srcrt.srcopt[IPOPT_OFFSET] = IPOPT_MINOFF;
                   1143:        bcopy((caddr_t)&ip_srcrt.nop,
                   1144:            mtod(m, caddr_t) + sizeof(struct in_addr), OPTSIZ);
                   1145:        q = (struct in_addr *)(mtod(m, caddr_t) +
                   1146:            sizeof(struct in_addr) + OPTSIZ);
                   1147: #undef OPTSIZ
                   1148:        /*
                   1149:         * Record return path as an IP source route,
                   1150:         * reversing the path (pointers are now aligned).
                   1151:         */
                   1152:        while (p >= ip_srcrt.route) {
                   1153: #ifdef DIAGNOSTIC
                   1154:                if (ipprintfs)
1.39      christos 1155:                        printf(" %x", ntohl(q->s_addr));
1.1       cgd      1156: #endif
                   1157:                *q++ = *p--;
                   1158:        }
                   1159:        /*
                   1160:         * Last hop goes to final destination.
                   1161:         */
                   1162:        *q = ip_srcrt.dst;
                   1163: #ifdef DIAGNOSTIC
                   1164:        if (ipprintfs)
1.39      christos 1165:                printf(" %x\n", ntohl(q->s_addr));
1.1       cgd      1166: #endif
                   1167:        return (m);
                   1168: }
                   1169:
                   1170: /*
                   1171:  * Strip out IP options, at higher
                   1172:  * level protocol in the kernel.
                   1173:  * Second argument is buffer to which options
                   1174:  * will be moved, and return value is their length.
                   1175:  * XXX should be deleted; last arg currently ignored.
                   1176:  */
1.8       mycroft  1177: void
1.1       cgd      1178: ip_stripoptions(m, mopt)
                   1179:        register struct mbuf *m;
                   1180:        struct mbuf *mopt;
                   1181: {
                   1182:        register int i;
                   1183:        struct ip *ip = mtod(m, struct ip *);
                   1184:        register caddr_t opts;
                   1185:        int olen;
                   1186:
1.79      mycroft  1187:        olen = (ip->ip_hl << 2) - sizeof (struct ip);
1.1       cgd      1188:        opts = (caddr_t)(ip + 1);
                   1189:        i = m->m_len - (sizeof (struct ip) + olen);
                   1190:        bcopy(opts  + olen, opts, (unsigned)i);
                   1191:        m->m_len -= olen;
                   1192:        if (m->m_flags & M_PKTHDR)
                   1193:                m->m_pkthdr.len -= olen;
1.79      mycroft  1194:        ip->ip_len -= olen;
                   1195:        ip->ip_hl = sizeof (struct ip) >> 2;
1.1       cgd      1196: }
                   1197:
1.23      mycroft  1198: int inetctlerrmap[PRC_NCMDS] = {
1.1       cgd      1199:        0,              0,              0,              0,
                   1200:        0,              EMSGSIZE,       EHOSTDOWN,      EHOSTUNREACH,
                   1201:        EHOSTUNREACH,   EHOSTUNREACH,   ECONNREFUSED,   ECONNREFUSED,
                   1202:        EMSGSIZE,       EHOSTUNREACH,   0,              0,
                   1203:        0,              0,              0,              0,
                   1204:        ENOPROTOOPT
                   1205: };
                   1206:
                   1207: /*
                   1208:  * Forward a packet.  If some error occurs return the sender
                   1209:  * an icmp packet.  Note we can't always generate a meaningful
                   1210:  * icmp message because icmp doesn't have a large enough repertoire
                   1211:  * of codes and types.
                   1212:  *
                   1213:  * If not forwarding, just drop the packet.  This could be confusing
                   1214:  * if ipforwarding was zero but some routing protocol was advancing
                   1215:  * us as a gateway to somewhere.  However, we must let the routing
                   1216:  * protocol deal with that.
                   1217:  *
                   1218:  * The srcrt parameter indicates whether the packet is being forwarded
                   1219:  * via a source route.
                   1220:  */
1.13      mycroft  1221: void
1.1       cgd      1222: ip_forward(m, srcrt)
                   1223:        struct mbuf *m;
                   1224:        int srcrt;
                   1225: {
                   1226:        register struct ip *ip = mtod(m, struct ip *);
                   1227:        register struct sockaddr_in *sin;
                   1228:        register struct rtentry *rt;
1.28      christos 1229:        int error, type = 0, code = 0;
1.1       cgd      1230:        struct mbuf *mcopy;
1.13      mycroft  1231:        n_long dest;
                   1232:        struct ifnet *destifp;
1.1       cgd      1233:
1.13      mycroft  1234:        dest = 0;
1.1       cgd      1235: #ifdef DIAGNOSTIC
                   1236:        if (ipprintfs)
1.70      thorpej  1237:                printf("forward: src %2.2x dst %2.2x ttl %x\n",
                   1238:                    ntohl(ip->ip_src.s_addr),
                   1239:                    ntohl(ip->ip_dst.s_addr), ip->ip_ttl);
1.1       cgd      1240: #endif
1.82.2.3  cgd      1241:        if (m->m_flags & (M_BCAST|M_MCAST) || in_canforward(ip->ip_dst) == 0) {
1.1       cgd      1242:                ipstat.ips_cantforward++;
                   1243:                m_freem(m);
                   1244:                return;
                   1245:        }
                   1246:        if (ip->ip_ttl <= IPTTLDEC) {
1.13      mycroft  1247:                icmp_error(m, ICMP_TIMXCEED, ICMP_TIMXCEED_INTRANS, dest, 0);
1.1       cgd      1248:                return;
                   1249:        }
                   1250:        ip->ip_ttl -= IPTTLDEC;
                   1251:
1.19      mycroft  1252:        sin = satosin(&ipforward_rt.ro_dst);
1.1       cgd      1253:        if ((rt = ipforward_rt.ro_rt) == 0 ||
1.35      mycroft  1254:            !in_hosteq(ip->ip_dst, sin->sin_addr)) {
1.1       cgd      1255:                if (ipforward_rt.ro_rt) {
                   1256:                        RTFREE(ipforward_rt.ro_rt);
                   1257:                        ipforward_rt.ro_rt = 0;
                   1258:                }
                   1259:                sin->sin_family = AF_INET;
1.35      mycroft  1260:                sin->sin_len = sizeof(struct sockaddr_in);
1.1       cgd      1261:                sin->sin_addr = ip->ip_dst;
                   1262:
                   1263:                rtalloc(&ipforward_rt);
                   1264:                if (ipforward_rt.ro_rt == 0) {
1.13      mycroft  1265:                        icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_HOST, dest, 0);
1.1       cgd      1266:                        return;
                   1267:                }
                   1268:                rt = ipforward_rt.ro_rt;
                   1269:        }
                   1270:
                   1271:        /*
1.34      mycroft  1272:         * Save at most 68 bytes of the packet in case
1.1       cgd      1273:         * we need to generate an ICMP message to the src.
                   1274:         */
1.34      mycroft  1275:        mcopy = m_copy(m, 0, imin((int)ip->ip_len, 68));
1.1       cgd      1276:
                   1277:        /*
                   1278:         * If forwarding packet using same interface that it came in on,
                   1279:         * perhaps should send a redirect to sender to shortcut a hop.
                   1280:         * Only send redirect if source is sending directly to us,
                   1281:         * and if packet was not source routed (or has any options).
                   1282:         * Also, don't send redirect if forwarding using a default route
                   1283:         * or a route modified by a redirect.
                   1284:         */
                   1285:        if (rt->rt_ifp == m->m_pkthdr.rcvif &&
                   1286:            (rt->rt_flags & (RTF_DYNAMIC|RTF_MODIFIED)) == 0 &&
1.35      mycroft  1287:            !in_nullhost(satosin(rt_key(rt))->sin_addr) &&
1.1       cgd      1288:            ipsendredirects && !srcrt) {
1.19      mycroft  1289:                if (rt->rt_ifa &&
                   1290:                    (ip->ip_src.s_addr & ifatoia(rt->rt_ifa)->ia_subnetmask) ==
                   1291:                    ifatoia(rt->rt_ifa)->ia_subnet) {
1.77      thorpej  1292:                        if (rt->rt_flags & RTF_GATEWAY)
                   1293:                                dest = satosin(rt->rt_gateway)->sin_addr.s_addr;
                   1294:                        else
                   1295:                                dest = ip->ip_dst.s_addr;
                   1296:                        /*
                   1297:                         * Router requirements says to only send host
                   1298:                         * redirects.
                   1299:                         */
                   1300:                        type = ICMP_REDIRECT;
                   1301:                        code = ICMP_REDIRECT_HOST;
1.1       cgd      1302: #ifdef DIAGNOSTIC
1.77      thorpej  1303:                        if (ipprintfs)
                   1304:                                printf("redirect (%d) to %x\n", code,
                   1305:                                    (u_int32_t)dest);
1.1       cgd      1306: #endif
                   1307:                }
                   1308:        }
                   1309:
1.27      thorpej  1310:        error = ip_output(m, (struct mbuf *)0, &ipforward_rt,
                   1311:            (IP_FORWARDING | (ip_directedbcast ? IP_ALLOWBROADCAST : 0)), 0);
1.1       cgd      1312:        if (error)
                   1313:                ipstat.ips_cantforward++;
                   1314:        else {
                   1315:                ipstat.ips_forward++;
                   1316:                if (type)
                   1317:                        ipstat.ips_redirectsent++;
                   1318:                else {
1.63      matt     1319:                        if (mcopy) {
                   1320: #ifdef GATEWAY
1.64      thorpej  1321:                                if (mcopy->m_flags & M_CANFASTFWD)
                   1322:                                        ipflow_create(&ipforward_rt, mcopy);
1.63      matt     1323: #endif
1.1       cgd      1324:                                m_freem(mcopy);
1.63      matt     1325:                        }
1.1       cgd      1326:                        return;
                   1327:                }
                   1328:        }
                   1329:        if (mcopy == NULL)
                   1330:                return;
1.13      mycroft  1331:        destifp = NULL;
                   1332:
1.1       cgd      1333:        switch (error) {
                   1334:
                   1335:        case 0:                         /* forwarded, but need redirect */
                   1336:                /* type, code set above */
                   1337:                break;
                   1338:
                   1339:        case ENETUNREACH:               /* shouldn't happen, checked above */
                   1340:        case EHOSTUNREACH:
                   1341:        case ENETDOWN:
                   1342:        case EHOSTDOWN:
                   1343:        default:
                   1344:                type = ICMP_UNREACH;
                   1345:                code = ICMP_UNREACH_HOST;
                   1346:                break;
                   1347:
                   1348:        case EMSGSIZE:
                   1349:                type = ICMP_UNREACH;
                   1350:                code = ICMP_UNREACH_NEEDFRAG;
1.13      mycroft  1351:                if (ipforward_rt.ro_rt)
                   1352:                        destifp = ipforward_rt.ro_rt->rt_ifp;
1.1       cgd      1353:                ipstat.ips_cantfrag++;
                   1354:                break;
                   1355:
                   1356:        case ENOBUFS:
                   1357:                type = ICMP_SOURCEQUENCH;
                   1358:                code = 0;
                   1359:                break;
                   1360:        }
1.13      mycroft  1361:        icmp_error(mcopy, type, code, dest, destifp);
1.44      thorpej  1362: }
                   1363:
                   1364: void
                   1365: ip_savecontrol(inp, mp, ip, m)
                   1366:        register struct inpcb *inp;
                   1367:        register struct mbuf **mp;
                   1368:        register struct ip *ip;
                   1369:        register struct mbuf *m;
                   1370: {
                   1371:
                   1372:        if (inp->inp_socket->so_options & SO_TIMESTAMP) {
                   1373:                struct timeval tv;
                   1374:
                   1375:                microtime(&tv);
                   1376:                *mp = sbcreatecontrol((caddr_t) &tv, sizeof(tv),
                   1377:                    SCM_TIMESTAMP, SOL_SOCKET);
                   1378:                if (*mp)
                   1379:                        mp = &(*mp)->m_next;
                   1380:        }
                   1381:        if (inp->inp_flags & INP_RECVDSTADDR) {
                   1382:                *mp = sbcreatecontrol((caddr_t) &ip->ip_dst,
                   1383:                    sizeof(struct in_addr), IP_RECVDSTADDR, IPPROTO_IP);
                   1384:                if (*mp)
                   1385:                        mp = &(*mp)->m_next;
                   1386:        }
                   1387: #ifdef notyet
                   1388:        /*
                   1389:         * XXX
                   1390:         * Moving these out of udp_input() made them even more broken
                   1391:         * than they already were.
                   1392:         *      - fenner@parc.xerox.com
                   1393:         */
                   1394:        /* options were tossed already */
                   1395:        if (inp->inp_flags & INP_RECVOPTS) {
                   1396:                *mp = sbcreatecontrol((caddr_t) opts_deleted_above,
                   1397:                    sizeof(struct in_addr), IP_RECVOPTS, IPPROTO_IP);
                   1398:                if (*mp)
                   1399:                        mp = &(*mp)->m_next;
                   1400:        }
                   1401:        /* ip_srcroute doesn't do what we want here, need to fix */
                   1402:        if (inp->inp_flags & INP_RECVRETOPTS) {
                   1403:                *mp = sbcreatecontrol((caddr_t) ip_srcroute(),
                   1404:                    sizeof(struct in_addr), IP_RECVRETOPTS, IPPROTO_IP);
                   1405:                if (*mp)
                   1406:                        mp = &(*mp)->m_next;
                   1407:        }
                   1408: #endif
                   1409:        if (inp->inp_flags & INP_RECVIF) {
                   1410:                struct sockaddr_dl sdl;
                   1411:
                   1412:                sdl.sdl_len = offsetof(struct sockaddr_dl, sdl_data[0]);
                   1413:                sdl.sdl_family = AF_LINK;
                   1414:                sdl.sdl_index = m->m_pkthdr.rcvif ?
                   1415:                    m->m_pkthdr.rcvif->if_index : 0;
                   1416:                sdl.sdl_nlen = sdl.sdl_alen = sdl.sdl_slen = 0;
                   1417:                *mp = sbcreatecontrol((caddr_t) &sdl, sdl.sdl_len,
                   1418:                    IP_RECVIF, IPPROTO_IP);
                   1419:                if (*mp)
                   1420:                        mp = &(*mp)->m_next;
                   1421:        }
1.13      mycroft  1422: }
                   1423:
                   1424: int
                   1425: ip_sysctl(name, namelen, oldp, oldlenp, newp, newlen)
                   1426:        int *name;
                   1427:        u_int namelen;
                   1428:        void *oldp;
                   1429:        size_t *oldlenp;
                   1430:        void *newp;
                   1431:        size_t newlen;
                   1432: {
1.52      thorpej  1433:        extern int subnetsarelocal;
                   1434:
1.54      lukem    1435:        int error, old;
                   1436:
1.13      mycroft  1437:        /* All sysctl names at this level are terminal. */
                   1438:        if (namelen != 1)
                   1439:                return (ENOTDIR);
                   1440:
                   1441:        switch (name[0]) {
                   1442:        case IPCTL_FORWARDING:
                   1443:                return (sysctl_int(oldp, oldlenp, newp, newlen, &ipforwarding));
                   1444:        case IPCTL_SENDREDIRECTS:
                   1445:                return (sysctl_int(oldp, oldlenp, newp, newlen,
                   1446:                        &ipsendredirects));
                   1447:        case IPCTL_DEFTTL:
                   1448:                return (sysctl_int(oldp, oldlenp, newp, newlen, &ip_defttl));
                   1449: #ifdef notyet
                   1450:        case IPCTL_DEFMTU:
                   1451:                return (sysctl_int(oldp, oldlenp, newp, newlen, &ip_mtu));
                   1452: #endif
1.26      thorpej  1453:        case IPCTL_FORWSRCRT:
1.47      cjs      1454:                /* Don't allow this to change in a secure environment.  */
1.26      thorpej  1455:                if (securelevel > 0)
1.46      cjs      1456:                        return (sysctl_rdint(oldp, oldlenp, newp,
                   1457:                            ip_forwsrcrt));
                   1458:                else
                   1459:                        return (sysctl_int(oldp, oldlenp, newp, newlen,
                   1460:                            &ip_forwsrcrt));
1.27      thorpej  1461:        case IPCTL_DIRECTEDBCAST:
                   1462:                return (sysctl_int(oldp, oldlenp, newp, newlen,
                   1463:                    &ip_directedbcast));
1.47      cjs      1464:        case IPCTL_ALLOWSRCRT:
                   1465:                return (sysctl_int(oldp, oldlenp, newp, newlen,
                   1466:                    &ip_allowsrcrt));
1.52      thorpej  1467:        case IPCTL_SUBNETSARELOCAL:
                   1468:                return (sysctl_int(oldp, oldlenp, newp, newlen,
                   1469:                    &subnetsarelocal));
1.53      kml      1470:        case IPCTL_MTUDISC:
1.60      kml      1471:                error = sysctl_int(oldp, oldlenp, newp, newlen,
                   1472:                    &ip_mtudisc);
                   1473:                if (ip_mtudisc != 0 && ip_mtudisc_timeout_q == NULL) {
                   1474:                        ip_mtudisc_timeout_q =
                   1475:                            rt_timer_queue_create(ip_mtudisc_timeout);
                   1476:                } else if (ip_mtudisc == 0 && ip_mtudisc_timeout_q != NULL) {
                   1477:                        rt_timer_queue_destroy(ip_mtudisc_timeout_q, TRUE);
                   1478:                        ip_mtudisc_timeout_q = NULL;
                   1479:                }
                   1480:                return error;
1.54      lukem    1481:        case IPCTL_ANONPORTMIN:
                   1482:                old = anonportmin;
                   1483:                error = sysctl_int(oldp, oldlenp, newp, newlen, &anonportmin);
                   1484:                if (anonportmin >= anonportmax || anonportmin > 65535
                   1485: #ifndef IPNOPRIVPORTS
                   1486:                    || anonportmin < IPPORT_RESERVED
                   1487: #endif
                   1488:                    ) {
                   1489:                        anonportmin = old;
                   1490:                        return (EINVAL);
                   1491:                }
                   1492:                return (error);
                   1493:        case IPCTL_ANONPORTMAX:
                   1494:                old = anonportmax;
                   1495:                error = sysctl_int(oldp, oldlenp, newp, newlen, &anonportmax);
                   1496:                if (anonportmin >= anonportmax || anonportmax > 65535
                   1497: #ifndef IPNOPRIVPORTS
                   1498:                    || anonportmax < IPPORT_RESERVED
                   1499: #endif
                   1500:                    ) {
                   1501:                        anonportmax = old;
                   1502:                        return (EINVAL);
                   1503:                }
1.60      kml      1504:                return (error);
                   1505:        case IPCTL_MTUDISCTIMEOUT:
                   1506:                error = sysctl_int(oldp, oldlenp, newp, newlen,
                   1507:                   &ip_mtudisc_timeout);
                   1508:                if (ip_mtudisc_timeout_q != NULL)
                   1509:                        rt_timer_queue_change(ip_mtudisc_timeout_q,
                   1510:                                              ip_mtudisc_timeout);
1.54      lukem    1511:                return (error);
1.65      matt     1512: #ifdef GATEWAY
                   1513:        case IPCTL_MAXFLOWS:
1.67      thorpej  1514:            {
                   1515:                int s;
                   1516:
1.65      matt     1517:                error = sysctl_int(oldp, oldlenp, newp, newlen,
                   1518:                   &ip_maxflows);
1.67      thorpej  1519:                s = splsoftnet();
1.65      matt     1520:                ipflow_reap(0);
1.67      thorpej  1521:                splx(s);
1.65      matt     1522:                return (error);
1.67      thorpej  1523:            }
1.65      matt     1524: #endif
1.13      mycroft  1525:        default:
                   1526:                return (EOPNOTSUPP);
                   1527:        }
                   1528:        /* NOTREACHED */
1.1       cgd      1529: }

CVSweb <webmaster@jp.NetBSD.org>