Annotation of src/sys/netinet/ip_input.c, Revision 1.192
1.192 ! jonathan 1: /* $NetBSD: ip_input.c,v 1.191 2003/12/07 01:18:26 jonathan 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: * 3. All advertising materials mentioning features or use of this software
49: * must display the following acknowledgement:
50: * This product includes software developed by the NetBSD
51: * Foundation, Inc. and its contributors.
52: * 4. Neither the name of The NetBSD Foundation nor the names of its
53: * contributors may be used to endorse or promote products derived
54: * from this software without specific prior written permission.
55: *
56: * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
57: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
58: * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
59: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
60: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
61: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
62: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
63: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
64: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
65: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
66: * POSSIBILITY OF SUCH DAMAGE.
67: */
1.14 cgd 68:
1.1 cgd 69: /*
1.13 mycroft 70: * Copyright (c) 1982, 1986, 1988, 1993
71: * The Regents of the University of California. All rights reserved.
1.1 cgd 72: *
73: * Redistribution and use in source and binary forms, with or without
74: * modification, are permitted provided that the following conditions
75: * are met:
76: * 1. Redistributions of source code must retain the above copyright
77: * notice, this list of conditions and the following disclaimer.
78: * 2. Redistributions in binary form must reproduce the above copyright
79: * notice, this list of conditions and the following disclaimer in the
80: * documentation and/or other materials provided with the distribution.
1.172 agc 81: * 3. Neither the name of the University nor the names of its contributors
1.1 cgd 82: * may be used to endorse or promote products derived from this software
83: * without specific prior written permission.
84: *
85: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
86: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
87: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
88: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
89: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
90: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
91: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
92: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
93: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
94: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
95: * SUCH DAMAGE.
96: *
1.14 cgd 97: * @(#)ip_input.c 8.2 (Berkeley) 1/4/94
1.1 cgd 98: */
1.141 lukem 99:
100: #include <sys/cdefs.h>
1.192 ! jonathan 101: __KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.191 2003/12/07 01:18:26 jonathan Exp $");
1.55 scottr 102:
1.184 jonathan 103: #include "opt_inet.h"
1.62 matt 104: #include "opt_gateway.h"
1.69 mrg 105: #include "opt_pfil_hooks.h"
1.91 thorpej 106: #include "opt_ipsec.h"
1.55 scottr 107: #include "opt_mrouting.h"
1.167 martin 108: #include "opt_mbuftrace.h"
1.135 thorpej 109: #include "opt_inet_csum.h"
1.1 cgd 110:
1.5 mycroft 111: #include <sys/param.h>
112: #include <sys/systm.h>
113: #include <sys/malloc.h>
114: #include <sys/mbuf.h>
115: #include <sys/domain.h>
116: #include <sys/protosw.h>
117: #include <sys/socket.h>
1.44 thorpej 118: #include <sys/socketvar.h>
1.5 mycroft 119: #include <sys/errno.h>
120: #include <sys/time.h>
121: #include <sys/kernel.h>
1.72 thorpej 122: #include <sys/pool.h>
1.28 christos 123: #include <sys/sysctl.h>
1.1 cgd 124:
1.5 mycroft 125: #include <net/if.h>
1.44 thorpej 126: #include <net/if_dl.h>
1.5 mycroft 127: #include <net/route.h>
1.45 mrg 128: #include <net/pfil.h>
1.1 cgd 129:
1.5 mycroft 130: #include <netinet/in.h>
131: #include <netinet/in_systm.h>
132: #include <netinet/ip.h>
133: #include <netinet/in_pcb.h>
134: #include <netinet/in_var.h>
135: #include <netinet/ip_var.h>
136: #include <netinet/ip_icmp.h>
1.89 itojun 137: /* just for gif_ttl */
138: #include <netinet/in_gif.h>
139: #include "gif.h"
1.144 martin 140: #include <net/if_gre.h>
141: #include "gre.h"
1.111 jdolecek 142:
143: #ifdef MROUTING
144: #include <netinet/ip_mroute.h>
145: #endif
1.89 itojun 146:
147: #ifdef IPSEC
148: #include <netinet6/ipsec.h>
149: #include <netkey/key.h>
150: #endif
1.173 jonathan 151: #ifdef FAST_IPSEC
152: #include <netipsec/ipsec.h>
153: #include <netipsec/key.h>
154: #endif /* FAST_IPSEC*/
1.44 thorpej 155:
1.1 cgd 156: #ifndef IPFORWARDING
157: #ifdef GATEWAY
158: #define IPFORWARDING 1 /* forward IP packets not for us */
159: #else /* GATEWAY */
160: #define IPFORWARDING 0 /* don't forward IP packets not for us */
161: #endif /* GATEWAY */
162: #endif /* IPFORWARDING */
163: #ifndef IPSENDREDIRECTS
164: #define IPSENDREDIRECTS 1
165: #endif
1.26 thorpej 166: #ifndef IPFORWSRCRT
1.47 cjs 167: #define IPFORWSRCRT 1 /* forward source-routed packets */
168: #endif
169: #ifndef IPALLOWSRCRT
1.48 mrg 170: #define IPALLOWSRCRT 1 /* allow source-routed packets */
1.26 thorpej 171: #endif
1.53 kml 172: #ifndef IPMTUDISC
1.153 itojun 173: #define IPMTUDISC 1
1.53 kml 174: #endif
1.60 kml 175: #ifndef IPMTUDISCTIMEOUT
1.61 kml 176: #define IPMTUDISCTIMEOUT (10 * 60) /* as per RFC 1191 */
1.60 kml 177: #endif
1.53 kml 178:
1.27 thorpej 179: /*
180: * Note: DIRECTED_BROADCAST is handled this way so that previous
181: * configuration using this option will Just Work.
182: */
183: #ifndef IPDIRECTEDBCAST
184: #ifdef DIRECTED_BROADCAST
185: #define IPDIRECTEDBCAST 1
186: #else
187: #define IPDIRECTEDBCAST 0
188: #endif /* DIRECTED_BROADCAST */
189: #endif /* IPDIRECTEDBCAST */
1.1 cgd 190: int ipforwarding = IPFORWARDING;
191: int ipsendredirects = IPSENDREDIRECTS;
1.13 mycroft 192: int ip_defttl = IPDEFTTL;
1.26 thorpej 193: int ip_forwsrcrt = IPFORWSRCRT;
1.27 thorpej 194: int ip_directedbcast = IPDIRECTEDBCAST;
1.47 cjs 195: int ip_allowsrcrt = IPALLOWSRCRT;
1.53 kml 196: int ip_mtudisc = IPMTUDISC;
1.156 itojun 197: int ip_mtudisc_timeout = IPMTUDISCTIMEOUT;
1.1 cgd 198: #ifdef DIAGNOSTIC
199: int ipprintfs = 0;
200: #endif
1.184 jonathan 201:
202: int ip_do_randomid = 0;
203:
1.165 christos 204: /*
205: * XXX - Setting ip_checkinterface mostly implements the receive side of
206: * the Strong ES model described in RFC 1122, but since the routing table
207: * and transmit implementation do not implement the Strong ES model,
208: * setting this to 1 results in an odd hybrid.
209: *
210: * XXX - ip_checkinterface currently must be disabled if you use ipnat
211: * to translate the destination address to another local interface.
212: *
213: * XXX - ip_checkinterface must be disabled if you add IP aliases
214: * to the loopback interface instead of the interface where the
215: * packets for those addresses are received.
216: */
217: int ip_checkinterface = 0;
218:
1.1 cgd 219:
1.60 kml 220: struct rttimer_queue *ip_mtudisc_timeout_q = NULL;
221:
1.1 cgd 222: extern struct domain inetdomain;
223: int ipqmaxlen = IFQ_MAXLEN;
1.150 matt 224: u_long in_ifaddrhash; /* size of hash table - 1 */
225: int in_ifaddrentries; /* total number of addrs */
1.181 jonathan 226: struct in_ifaddrhead in_ifaddrhead;
1.57 tls 227: struct in_ifaddrhashhead *in_ifaddrhashtbl;
1.166 matt 228: u_long in_multihash; /* size of hash table - 1 */
229: int in_multientries; /* total number of addrs */
230: struct in_multihashhead *in_multihashtbl;
1.13 mycroft 231: struct ifqueue ipintrq;
1.63 matt 232: struct ipstat ipstat;
1.183 jonathan 233: uint16_t ip_id;
1.75 thorpej 234:
1.121 thorpej 235: #ifdef PFIL_HOOKS
236: struct pfil_head inet_pfil_hook;
237: #endif
238:
1.190 jonathan 239: /* IP datagram reassembly queues (hashed) */
240: #define IPREASS_NHASH_LOG2 6
241: #define IPREASS_NHASH (1 << IPREASS_NHASH_LOG2)
242: #define IPREASS_HMASK (IPREASS_NHASH - 1)
243: #define IPREASS_HASH(x,y) \
244: (((((x) & 0xF) | ((((x) >> 8) & 0xF) << 4)) ^ (y)) & IPREASS_HMASK)
245: struct ipqhead ipq[IPREASS_NHASH];
1.75 thorpej 246: int ipq_locked;
1.131 itojun 247: int ip_nfragpackets = 0;
1.133 itojun 248: int ip_maxfragpackets = 200;
1.192 ! jonathan 249: int ip_nfrags = 0; /* total fragments in reass queues */
1.75 thorpej 250:
251: static __inline int ipq_lock_try __P((void));
252: static __inline void ipq_unlock __P((void));
253:
254: static __inline int
255: ipq_lock_try()
256: {
257: int s;
258:
1.132 thorpej 259: /*
1.149 wiz 260: * Use splvm() -- we're blocking things that would cause
1.132 thorpej 261: * mbuf allocation.
262: */
263: s = splvm();
1.75 thorpej 264: if (ipq_locked) {
265: splx(s);
266: return (0);
267: }
268: ipq_locked = 1;
269: splx(s);
270: return (1);
271: }
272:
273: static __inline void
274: ipq_unlock()
275: {
276: int s;
277:
1.132 thorpej 278: s = splvm();
1.75 thorpej 279: ipq_locked = 0;
280: splx(s);
281: }
282:
283: #ifdef DIAGNOSTIC
284: #define IPQ_LOCK() \
285: do { \
286: if (ipq_lock_try() == 0) { \
287: printf("%s:%d: ipq already locked\n", __FILE__, __LINE__); \
288: panic("ipq_lock"); \
289: } \
1.159 perry 290: } while (/*CONSTCOND*/ 0)
1.75 thorpej 291: #define IPQ_LOCK_CHECK() \
292: do { \
293: if (ipq_locked == 0) { \
294: printf("%s:%d: ipq lock not held\n", __FILE__, __LINE__); \
295: panic("ipq lock check"); \
296: } \
1.159 perry 297: } while (/*CONSTCOND*/ 0)
1.75 thorpej 298: #else
299: #define IPQ_LOCK() (void) ipq_lock_try()
300: #define IPQ_LOCK_CHECK() /* nothing */
301: #endif
302:
303: #define IPQ_UNLOCK() ipq_unlock()
1.1 cgd 304:
1.166 matt 305: struct pool inmulti_pool;
1.72 thorpej 306: struct pool ipqent_pool;
307:
1.135 thorpej 308: #ifdef INET_CSUM_COUNTERS
309: #include <sys/device.h>
310:
311: struct evcnt ip_hwcsum_bad = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,
312: NULL, "inet", "hwcsum bad");
313: struct evcnt ip_hwcsum_ok = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,
314: NULL, "inet", "hwcsum ok");
315: struct evcnt ip_swcsum = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,
316: NULL, "inet", "swcsum");
317:
318: #define INET_CSUM_COUNTER_INCR(ev) (ev)->ev_count++
319:
320: #else
321:
322: #define INET_CSUM_COUNTER_INCR(ev) /* nothing */
323:
324: #endif /* INET_CSUM_COUNTERS */
325:
1.1 cgd 326: /*
327: * We need to save the IP options in case a protocol wants to respond
328: * to an incoming packet over the same route if the packet got here
329: * using IP source routing. This allows connection establishment and
330: * maintenance when the remote end is on a network that is not known
331: * to us.
332: */
333: int ip_nhops = 0;
334: static struct ip_srcrt {
335: struct in_addr dst; /* final destination */
336: char nop; /* one NOP to align */
337: char srcopt[IPOPT_OFFSET + 1]; /* OPTVAL, OLEN and OFFSET */
338: struct in_addr route[MAX_IPOPTLEN/sizeof(struct in_addr)];
339: } ip_srcrt;
340:
1.13 mycroft 341: static void save_rte __P((u_char *, struct in_addr));
1.35 mycroft 342:
1.164 matt 343: #ifdef MBUFTRACE
344: struct mowner ip_rx_mowner = { "internet", "rx" };
345: struct mowner ip_tx_mowner = { "internet", "tx" };
346: #endif
347:
1.1 cgd 348: /*
349: * IP initialization: fill in IP protocol switch table.
350: * All protocols not implemented in kernel go to raw IP protocol handler.
351: */
1.8 mycroft 352: void
1.1 cgd 353: ip_init()
354: {
1.109 augustss 355: struct protosw *pr;
356: int i;
1.1 cgd 357:
1.166 matt 358: pool_init(&inmulti_pool, sizeof(struct in_multi), 0, 0, 0, "inmltpl",
359: NULL);
1.72 thorpej 360: pool_init(&ipqent_pool, sizeof(struct ipqent), 0, 0, 0, "ipqepl",
1.146 thorpej 361: NULL);
1.72 thorpej 362:
1.1 cgd 363: pr = pffindproto(PF_INET, IPPROTO_RAW, SOCK_RAW);
364: if (pr == 0)
365: panic("ip_init");
366: for (i = 0; i < IPPROTO_MAX; i++)
367: ip_protox[i] = pr - inetsw;
368: for (pr = inetdomain.dom_protosw;
369: pr < inetdomain.dom_protoswNPROTOSW; pr++)
370: if (pr->pr_domain->dom_family == PF_INET &&
371: pr->pr_protocol && pr->pr_protocol != IPPROTO_RAW)
372: ip_protox[pr->pr_protocol] = pr - inetsw;
1.192 ! jonathan 373:
1.190 jonathan 374: for (i = 0; i < IPREASS_NHASH; i++)
375: LIST_INIT(&ipq[i]);
376:
1.183 jonathan 377: ip_id = time.tv_sec & 0xfffff;
1.1 cgd 378: ipintrq.ifq_maxlen = ipqmaxlen;
1.181 jonathan 379: TAILQ_INIT(&in_ifaddrhead);
1.120 ad 380: in_ifaddrhashtbl = hashinit(IN_IFADDR_HASH_SIZE, HASH_LIST, M_IFADDR,
381: M_WAITOK, &in_ifaddrhash);
1.166 matt 382: in_multihashtbl = hashinit(IN_IFADDR_HASH_SIZE, HASH_LIST, M_IPMADDR,
383: M_WAITOK, &in_multihash);
1.160 itojun 384: ip_mtudisc_timeout_q = rt_timer_queue_create(ip_mtudisc_timeout);
1.73 thorpej 385: #ifdef GATEWAY
386: ipflow_init();
387: #endif
1.121 thorpej 388:
389: #ifdef PFIL_HOOKS
390: /* Register our Packet Filter hook. */
1.126 thorpej 391: inet_pfil_hook.ph_type = PFIL_TYPE_AF;
392: inet_pfil_hook.ph_af = AF_INET;
1.121 thorpej 393: i = pfil_head_register(&inet_pfil_hook);
394: if (i != 0)
395: printf("ip_init: WARNING: unable to register pfil hook, "
396: "error %d\n", i);
397: #endif /* PFIL_HOOKS */
1.135 thorpej 398:
399: #ifdef INET_CSUM_COUNTERS
400: evcnt_attach_static(&ip_hwcsum_bad);
401: evcnt_attach_static(&ip_hwcsum_ok);
402: evcnt_attach_static(&ip_swcsum);
403: #endif /* INET_CSUM_COUNTERS */
1.164 matt 404:
405: #ifdef MBUFTRACE
406: MOWNER_ATTACH(&ip_tx_mowner);
407: MOWNER_ATTACH(&ip_rx_mowner);
408: #endif /* MBUFTRACE */
1.1 cgd 409: }
410:
411: struct sockaddr_in ipaddr = { sizeof(ipaddr), AF_INET };
412: struct route ipforward_rt;
413:
414: /*
1.89 itojun 415: * IP software interrupt routine
416: */
417: void
418: ipintr()
419: {
420: int s;
421: struct mbuf *m;
422:
423: while (1) {
1.132 thorpej 424: s = splnet();
1.89 itojun 425: IF_DEQUEUE(&ipintrq, m);
426: splx(s);
427: if (m == 0)
428: return;
1.164 matt 429: MCLAIM(m, &ip_rx_mowner);
1.89 itojun 430: ip_input(m);
431: }
432: }
433:
434: /*
1.1 cgd 435: * Ip input routine. Checksum and byte swap header. If fragmented
436: * try to reassemble. Process options. Pass to next level.
437: */
1.8 mycroft 438: void
1.89 itojun 439: ip_input(struct mbuf *m)
1.1 cgd 440: {
1.109 augustss 441: struct ip *ip = NULL;
442: struct ipq *fp;
443: struct in_ifaddr *ia;
444: struct ifaddr *ifa;
1.25 cgd 445: struct ipqent *ipqe;
1.89 itojun 446: int hlen = 0, mff, len;
1.100 itojun 447: int downmatch;
1.165 christos 448: int checkif;
1.169 itojun 449: int srcrt = 0;
1.190 jonathan 450: u_int hash;
1.173 jonathan 451: #ifdef FAST_IPSEC
452: struct m_tag *mtag;
453: struct tdb_ident *tdbi;
454: struct secpolicy *sp;
455: int s, error;
456: #endif /* FAST_IPSEC */
1.1 cgd 457:
1.164 matt 458: MCLAIM(m, &ip_rx_mowner);
1.1 cgd 459: #ifdef DIAGNOSTIC
460: if ((m->m_flags & M_PKTHDR) == 0)
461: panic("ipintr no HDR");
1.89 itojun 462: #endif
1.164 matt 463:
1.1 cgd 464: /*
465: * If no IP addresses have been set yet but the interfaces
466: * are receiving, can't do anything with incoming packets yet.
467: */
1.181 jonathan 468: if (TAILQ_FIRST(&in_ifaddrhead) == 0)
1.1 cgd 469: goto bad;
470: ipstat.ips_total++;
1.154 thorpej 471: /*
472: * If the IP header is not aligned, slurp it up into a new
473: * mbuf with space for link headers, in the event we forward
474: * it. Otherwise, if it is aligned, make sure the entire
475: * base IP header is in the first mbuf of the chain.
476: */
477: if (IP_HDR_ALIGNED_P(mtod(m, caddr_t)) == 0) {
478: if ((m = m_copyup(m, sizeof(struct ip),
479: (max_linkhdr + 3) & ~3)) == NULL) {
480: /* XXXJRT new stat, please */
481: ipstat.ips_toosmall++;
482: return;
483: }
484: } else if (__predict_false(m->m_len < sizeof (struct ip))) {
485: if ((m = m_pullup(m, sizeof (struct ip))) == NULL) {
486: ipstat.ips_toosmall++;
487: return;
488: }
1.1 cgd 489: }
490: ip = mtod(m, struct ip *);
1.13 mycroft 491: if (ip->ip_v != IPVERSION) {
492: ipstat.ips_badvers++;
493: goto bad;
494: }
1.1 cgd 495: hlen = ip->ip_hl << 2;
496: if (hlen < sizeof(struct ip)) { /* minimum header length */
497: ipstat.ips_badhlen++;
498: goto bad;
499: }
500: if (hlen > m->m_len) {
501: if ((m = m_pullup(m, hlen)) == 0) {
502: ipstat.ips_badhlen++;
1.89 itojun 503: return;
1.1 cgd 504: }
505: ip = mtod(m, struct ip *);
506: }
1.98 thorpej 507:
1.85 hwr 508: /*
1.99 thorpej 509: * RFC1122: packets with a multicast source address are
1.98 thorpej 510: * not allowed.
1.85 hwr 511: */
512: if (IN_MULTICAST(ip->ip_src.s_addr)) {
1.130 itojun 513: ipstat.ips_badaddr++;
1.85 hwr 514: goto bad;
1.129 itojun 515: }
516:
517: /* 127/8 must not appear on wire - RFC1122 */
518: if ((ntohl(ip->ip_dst.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET ||
519: (ntohl(ip->ip_src.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET) {
1.130 itojun 520: if ((m->m_pkthdr.rcvif->if_flags & IFF_LOOPBACK) == 0) {
521: ipstat.ips_badaddr++;
1.129 itojun 522: goto bad;
1.130 itojun 523: }
1.85 hwr 524: }
525:
1.135 thorpej 526: switch (m->m_pkthdr.csum_flags &
1.137 thorpej 527: ((m->m_pkthdr.rcvif->if_csum_flags_rx & M_CSUM_IPv4) |
1.135 thorpej 528: M_CSUM_IPv4_BAD)) {
529: case M_CSUM_IPv4|M_CSUM_IPv4_BAD:
530: INET_CSUM_COUNTER_INCR(&ip_hwcsum_bad);
531: goto badcsum;
532:
533: case M_CSUM_IPv4:
534: /* Checksum was okay. */
535: INET_CSUM_COUNTER_INCR(&ip_hwcsum_ok);
536: break;
537:
538: default:
539: /* Must compute it ourselves. */
540: INET_CSUM_COUNTER_INCR(&ip_swcsum);
541: if (in_cksum(m, hlen) != 0)
542: goto bad;
543: break;
1.1 cgd 544: }
545:
1.121 thorpej 546: /* Retrieve the packet length. */
547: len = ntohs(ip->ip_len);
1.81 proff 548:
549: /*
550: * Check for additional length bogosity
551: */
1.84 proff 552: if (len < hlen) {
1.81 proff 553: ipstat.ips_badlen++;
554: goto bad;
555: }
1.1 cgd 556:
557: /*
558: * Check that the amount of data in the buffers
559: * is as at least much as the IP header would have us expect.
560: * Trim mbufs if longer than we expect.
561: * Drop packet if shorter than we expect.
562: */
1.35 mycroft 563: if (m->m_pkthdr.len < len) {
1.1 cgd 564: ipstat.ips_tooshort++;
565: goto bad;
566: }
1.35 mycroft 567: if (m->m_pkthdr.len > len) {
1.1 cgd 568: if (m->m_len == m->m_pkthdr.len) {
1.35 mycroft 569: m->m_len = len;
570: m->m_pkthdr.len = len;
1.1 cgd 571: } else
1.35 mycroft 572: m_adj(m, len - m->m_pkthdr.len);
1.1 cgd 573: }
574:
1.188 scw 575: #if defined(IPSEC) || defined(FAST_IPSEC)
1.149 wiz 576: /* ipflow (IP fast forwarding) is not compatible with IPsec. */
1.94 itojun 577: m->m_flags &= ~M_CANFASTFWD;
578: #else
1.64 thorpej 579: /*
580: * Assume that we can create a fast-forward IP flow entry
581: * based on this packet.
582: */
583: m->m_flags |= M_CANFASTFWD;
1.94 itojun 584: #endif
1.64 thorpej 585:
1.36 mrg 586: #ifdef PFIL_HOOKS
1.33 mrg 587: /*
1.64 thorpej 588: * Run through list of hooks for input packets. If there are any
589: * filters which require that additional packets in the flow are
590: * not fast-forwarded, they must clear the M_CANFASTFWD flag.
591: * Note that filters must _never_ set this flag, as another filter
592: * in the list may have previously cleared it.
1.33 mrg 593: */
1.127 itojun 594: /*
595: * let ipfilter look at packet on the wire,
596: * not the decapsulated packet.
597: */
598: #ifdef IPSEC
1.136 itojun 599: if (!ipsec_getnhist(m))
1.186 scw 600: #elif defined(FAST_IPSEC)
601: if (!ipsec_indone(m))
1.127 itojun 602: #else
603: if (1)
604: #endif
605: {
1.169 itojun 606: struct in_addr odst;
607:
608: odst = ip->ip_dst;
1.127 itojun 609: if (pfil_run_hooks(&inet_pfil_hook, &m, m->m_pkthdr.rcvif,
1.168 itojun 610: PFIL_IN) != 0)
611: return;
1.127 itojun 612: if (m == NULL)
613: return;
614: ip = mtod(m, struct ip *);
1.142 darrenr 615: hlen = ip->ip_hl << 2;
1.169 itojun 616: srcrt = (odst.s_addr != ip->ip_dst.s_addr);
1.127 itojun 617: }
1.36 mrg 618: #endif /* PFIL_HOOKS */
1.123 thorpej 619:
620: #ifdef ALTQ
621: /* XXX Temporary until ALTQ is changed to use a pfil hook */
622: if (altq_input != NULL && (*altq_input)(m, AF_INET) == 0) {
623: /* packet dropped by traffic conditioner */
624: return;
625: }
626: #endif
1.121 thorpej 627:
628: /*
1.1 cgd 629: * Process options and, if not destined for us,
630: * ship it on. ip_dooptions returns 1 when an
631: * error was detected (causing an icmp message
632: * to be sent and the original packet to be freed).
633: */
634: ip_nhops = 0; /* for source routed packets */
635: if (hlen > sizeof (struct ip) && ip_dooptions(m))
1.89 itojun 636: return;
1.1 cgd 637:
638: /*
1.165 christos 639: * Enable a consistency check between the destination address
640: * and the arrival interface for a unicast packet (the RFC 1122
641: * strong ES model) if IP forwarding is disabled and the packet
642: * is not locally generated.
643: *
644: * XXX - Checking also should be disabled if the destination
645: * address is ipnat'ed to a different interface.
646: *
647: * XXX - Checking is incompatible with IP aliases added
648: * to the loopback interface instead of the interface where
649: * the packets are received.
650: *
651: * XXX - We need to add a per ifaddr flag for this so that
652: * we get finer grain control.
653: */
654: checkif = ip_checkinterface && (ipforwarding == 0) &&
655: (m->m_pkthdr.rcvif != NULL) &&
656: ((m->m_pkthdr.rcvif->if_flags & IFF_LOOPBACK) == 0);
657:
658: /*
1.1 cgd 659: * Check our list of addresses, to see if the packet is for us.
1.100 itojun 660: *
661: * Traditional 4.4BSD did not consult IFF_UP at all.
662: * The behavior here is to treat addresses on !IFF_UP interface
663: * as not mine.
1.1 cgd 664: */
1.100 itojun 665: downmatch = 0;
1.140 matt 666: LIST_FOREACH(ia, &IN_IFADDR_HASH(ip->ip_dst.s_addr), ia_hash) {
1.97 itojun 667: if (in_hosteq(ia->ia_addr.sin_addr, ip->ip_dst)) {
1.165 christos 668: if (checkif && ia->ia_ifp != m->m_pkthdr.rcvif)
669: continue;
1.97 itojun 670: if ((ia->ia_ifp->if_flags & IFF_UP) != 0)
671: break;
1.100 itojun 672: else
673: downmatch++;
1.97 itojun 674: }
675: }
1.86 thorpej 676: if (ia != NULL)
677: goto ours;
1.57 tls 678: if (m->m_pkthdr.rcvif->if_flags & IFF_BROADCAST) {
1.140 matt 679: TAILQ_FOREACH(ifa, &m->m_pkthdr.rcvif->if_addrlist, ifa_list) {
680: if (ifa->ifa_addr->sa_family != AF_INET)
681: continue;
1.57 tls 682: ia = ifatoia(ifa);
1.35 mycroft 683: if (in_hosteq(ip->ip_dst, ia->ia_broadaddr.sin_addr) ||
684: in_hosteq(ip->ip_dst, ia->ia_netbroadcast) ||
1.20 mycroft 685: /*
686: * Look for all-0's host part (old broadcast addr),
687: * either for subnet or net.
688: */
689: ip->ip_dst.s_addr == ia->ia_subnet ||
1.18 mycroft 690: ip->ip_dst.s_addr == ia->ia_net)
1.1 cgd 691: goto ours;
1.57 tls 692: /*
693: * An interface with IP address zero accepts
694: * all packets that arrive on that interface.
695: */
696: if (in_nullhost(ia->ia_addr.sin_addr))
697: goto ours;
1.1 cgd 698: }
699: }
1.18 mycroft 700: if (IN_MULTICAST(ip->ip_dst.s_addr)) {
1.4 hpeyerl 701: struct in_multi *inm;
702: #ifdef MROUTING
703: extern struct socket *ip_mrouter;
1.10 brezak 704:
1.147 matt 705: if (M_READONLY(m)) {
1.10 brezak 706: if ((m = m_pullup(m, hlen)) == 0) {
707: ipstat.ips_toosmall++;
1.89 itojun 708: return;
1.10 brezak 709: }
710: ip = mtod(m, struct ip *);
711: }
1.4 hpeyerl 712:
713: if (ip_mrouter) {
714: /*
715: * If we are acting as a multicast router, all
716: * incoming multicast packets are passed to the
717: * kernel-level multicast forwarding function.
718: * The packet is returned (relatively) intact; if
719: * ip_mforward() returns a non-zero value, the packet
720: * must be discarded, else it may be accepted below.
721: *
722: * (The IP ident field is put in the same byte order
723: * as expected when ip_mforward() is called from
724: * ip_output().)
725: */
1.13 mycroft 726: if (ip_mforward(m, m->m_pkthdr.rcvif) != 0) {
727: ipstat.ips_cantforward++;
1.4 hpeyerl 728: m_freem(m);
1.89 itojun 729: return;
1.4 hpeyerl 730: }
731:
732: /*
733: * The process-level routing demon needs to receive
734: * all multicast IGMP packets, whether or not this
735: * host belongs to their destination groups.
736: */
737: if (ip->ip_p == IPPROTO_IGMP)
738: goto ours;
1.13 mycroft 739: ipstat.ips_forward++;
1.4 hpeyerl 740: }
741: #endif
742: /*
743: * See if we belong to the destination multicast group on the
744: * arrival interface.
745: */
746: IN_LOOKUP_MULTI(ip->ip_dst, m->m_pkthdr.rcvif, inm);
747: if (inm == NULL) {
1.13 mycroft 748: ipstat.ips_cantforward++;
1.4 hpeyerl 749: m_freem(m);
1.89 itojun 750: return;
1.4 hpeyerl 751: }
752: goto ours;
753: }
1.19 mycroft 754: if (ip->ip_dst.s_addr == INADDR_BROADCAST ||
1.35 mycroft 755: in_nullhost(ip->ip_dst))
1.1 cgd 756: goto ours;
757:
758: /*
759: * Not for us; forward if possible and desirable.
760: */
761: if (ipforwarding == 0) {
762: ipstat.ips_cantforward++;
763: m_freem(m);
1.100 itojun 764: } else {
765: /*
766: * If ip_dst matched any of my address on !IFF_UP interface,
767: * and there's no IFF_UP interface that matches ip_dst,
768: * send icmp unreach. Forwarding it will result in in-kernel
769: * forwarding loop till TTL goes to 0.
770: */
771: if (downmatch) {
772: icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_HOST, 0, 0);
773: ipstat.ips_cantforward++;
774: return;
775: }
1.145 itojun 776: #ifdef IPSEC
777: if (ipsec4_in_reject(m, NULL)) {
778: ipsecstat.in_polvio++;
779: goto bad;
780: }
781: #endif
1.173 jonathan 782: #ifdef FAST_IPSEC
783: mtag = m_tag_find(m, PACKET_TAG_IPSEC_IN_DONE, NULL);
784: s = splsoftnet();
785: if (mtag != NULL) {
786: tdbi = (struct tdb_ident *)(mtag + 1);
787: sp = ipsec_getpolicy(tdbi, IPSEC_DIR_INBOUND);
788: } else {
789: sp = ipsec_getpolicybyaddr(m, IPSEC_DIR_INBOUND,
790: IP_FORWARDING, &error);
791: }
792: if (sp == NULL) { /* NB: can happen if error */
793: splx(s);
794: /*XXX error stat???*/
795: DPRINTF(("ip_input: no SP for forwarding\n")); /*XXX*/
796: goto bad;
797: }
798:
799: /*
800: * Check security policy against packet attributes.
801: */
802: error = ipsec_in_reject(sp, m);
803: KEY_FREESP(&sp);
804: splx(s);
805: if (error) {
806: ipstat.ips_cantforward++;
807: goto bad;
808: }
809: #endif /* FAST_IPSEC */
1.145 itojun 810:
1.169 itojun 811: ip_forward(m, srcrt);
1.100 itojun 812: }
1.89 itojun 813: return;
1.1 cgd 814:
815: ours:
816: /*
817: * If offset or IP_MF are set, must reassemble.
818: * Otherwise, nothing need be done.
819: * (We could look in the reassembly queue to see
820: * if the packet was previously fragmented,
821: * but it's not worth the time; just let them time out.)
822: */
1.155 itojun 823: if (ip->ip_off & ~htons(IP_DF|IP_RF)) {
824: if (M_READONLY(m)) {
825: if ((m = m_pullup(m, hlen)) == NULL) {
826: ipstat.ips_toosmall++;
827: goto bad;
828: }
829: ip = mtod(m, struct ip *);
830: }
831:
1.1 cgd 832: /*
833: * Look for queue of fragments
834: * of this datagram.
835: */
1.75 thorpej 836: IPQ_LOCK();
1.190 jonathan 837: hash = IPREASS_HASH(ip->ip_src.s_addr, ip->ip_id);
838: /* XXX LIST_FOREACH(fp, &ipq[hash], ipq_q) */
839: for (fp = LIST_FIRST(&ipq[hash]); fp != NULL;
840: fp = LIST_NEXT(fp, ipq_q)) {
1.1 cgd 841: if (ip->ip_id == fp->ipq_id &&
1.35 mycroft 842: in_hosteq(ip->ip_src, fp->ipq_src) &&
843: in_hosteq(ip->ip_dst, fp->ipq_dst) &&
1.1 cgd 844: ip->ip_p == fp->ipq_p)
845: goto found;
1.190 jonathan 846:
847: }
1.1 cgd 848: fp = 0;
849: found:
850:
851: /*
852: * Adjust ip_len to not reflect header,
1.25 cgd 853: * set ipqe_mff if more fragments are expected,
1.1 cgd 854: * convert offset of this to bytes.
855: */
1.155 itojun 856: ip->ip_len = htons(ntohs(ip->ip_len) - hlen);
857: mff = (ip->ip_off & htons(IP_MF)) != 0;
1.25 cgd 858: if (mff) {
1.16 cgd 859: /*
860: * Make sure that fragments have a data length
861: * that's a non-zero multiple of 8 bytes.
862: */
1.155 itojun 863: if (ntohs(ip->ip_len) == 0 ||
864: (ntohs(ip->ip_len) & 0x7) != 0) {
1.16 cgd 865: ipstat.ips_badfrags++;
1.75 thorpej 866: IPQ_UNLOCK();
1.16 cgd 867: goto bad;
868: }
869: }
1.155 itojun 870: ip->ip_off = htons((ntohs(ip->ip_off) & IP_OFFMASK) << 3);
1.1 cgd 871:
872: /*
873: * If datagram marked as having more fragments
874: * or if this is not the first fragment,
875: * attempt reassembly; if it succeeds, proceed.
876: */
1.155 itojun 877: if (mff || ip->ip_off != htons(0)) {
1.1 cgd 878: ipstat.ips_fragments++;
1.72 thorpej 879: ipqe = pool_get(&ipqent_pool, PR_NOWAIT);
1.25 cgd 880: if (ipqe == NULL) {
881: ipstat.ips_rcvmemdrop++;
1.75 thorpej 882: IPQ_UNLOCK();
1.25 cgd 883: goto bad;
884: }
885: ipqe->ipqe_mff = mff;
1.50 thorpej 886: ipqe->ipqe_m = m;
1.25 cgd 887: ipqe->ipqe_ip = ip;
1.190 jonathan 888: m = ip_reass(ipqe, fp, &ipq[hash]);
1.75 thorpej 889: if (m == 0) {
890: IPQ_UNLOCK();
1.89 itojun 891: return;
1.75 thorpej 892: }
1.13 mycroft 893: ipstat.ips_reassembled++;
1.50 thorpej 894: ip = mtod(m, struct ip *);
1.74 thorpej 895: hlen = ip->ip_hl << 2;
1.155 itojun 896: ip->ip_len = htons(ntohs(ip->ip_len) + hlen);
1.1 cgd 897: } else
898: if (fp)
899: ip_freef(fp);
1.75 thorpej 900: IPQ_UNLOCK();
1.79 mycroft 901: }
1.128 itojun 902:
1.173 jonathan 903: #if defined(IPSEC)
1.128 itojun 904: /*
905: * enforce IPsec policy checking if we are seeing last header.
906: * note that we do not visit this with protocols with pcb layer
907: * code - like udp/tcp/raw ip.
908: */
909: if ((inetsw[ip_protox[ip->ip_p]].pr_flags & PR_LASTHDR) != 0 &&
910: ipsec4_in_reject(m, NULL)) {
911: ipsecstat.in_polvio++;
912: goto bad;
913: }
914: #endif
1.173 jonathan 915: #if FAST_IPSEC
916: /*
917: * enforce IPsec policy checking if we are seeing last header.
918: * note that we do not visit this with protocols with pcb layer
919: * code - like udp/tcp/raw ip.
920: */
921: if ((inetsw[ip_protox[ip->ip_p]].pr_flags & PR_LASTHDR) != 0) {
922: /*
923: * Check if the packet has already had IPsec processing
924: * done. If so, then just pass it along. This tag gets
925: * set during AH, ESP, etc. input handling, before the
926: * packet is returned to the ip input queue for delivery.
927: */
928: mtag = m_tag_find(m, PACKET_TAG_IPSEC_IN_DONE, NULL);
929: s = splsoftnet();
930: if (mtag != NULL) {
931: tdbi = (struct tdb_ident *)(mtag + 1);
932: sp = ipsec_getpolicy(tdbi, IPSEC_DIR_INBOUND);
933: } else {
934: sp = ipsec_getpolicybyaddr(m, IPSEC_DIR_INBOUND,
935: IP_FORWARDING, &error);
936: }
937: if (sp != NULL) {
938: /*
939: * Check security policy against packet attributes.
940: */
941: error = ipsec_in_reject(sp, m);
942: KEY_FREESP(&sp);
943: } else {
944: /* XXX error stat??? */
945: error = EINVAL;
946: DPRINTF(("ip_input: no SP, packet discarded\n"));/*XXX*/
947: goto bad;
948: }
949: splx(s);
950: if (error)
951: goto bad;
952: }
953: #endif /* FAST_IPSEC */
1.1 cgd 954:
955: /*
956: * Switch out to protocol's input routine.
957: */
1.82 aidan 958: #if IFA_STATS
1.122 itojun 959: if (ia && ip)
1.155 itojun 960: ia->ia_ifa.ifa_data.ifad_inbytes += ntohs(ip->ip_len);
1.82 aidan 961: #endif
1.1 cgd 962: ipstat.ips_delivered++;
1.89 itojun 963: {
964: int off = hlen, nh = ip->ip_p;
965:
966: (*inetsw[ip_protox[nh]].pr_input)(m, off, nh);
967: return;
968: }
1.1 cgd 969: bad:
970: m_freem(m);
1.135 thorpej 971: return;
972:
973: badcsum:
974: ipstat.ips_badsum++;
975: m_freem(m);
1.1 cgd 976: }
977:
978: /*
979: * Take incoming datagram fragment and try to
980: * reassemble it into whole datagram. If a chain for
981: * reassembly of this datagram already exists, then it
982: * is given as fp; otherwise have to make a chain.
983: */
1.50 thorpej 984: struct mbuf *
1.190 jonathan 985: ip_reass(ipqe, fp, ipqhead)
1.109 augustss 986: struct ipqent *ipqe;
987: struct ipq *fp;
1.190 jonathan 988: struct ipqhead *ipqhead;
1.1 cgd 989: {
1.109 augustss 990: struct mbuf *m = ipqe->ipqe_m;
991: struct ipqent *nq, *p, *q;
1.25 cgd 992: struct ip *ip;
1.1 cgd 993: struct mbuf *t;
1.25 cgd 994: int hlen = ipqe->ipqe_ip->ip_hl << 2;
1.1 cgd 995: int i, next;
996:
1.75 thorpej 997: IPQ_LOCK_CHECK();
998:
1.1 cgd 999: /*
1000: * Presence of header sizes in mbufs
1001: * would confuse code below.
1002: */
1003: m->m_data += hlen;
1004: m->m_len -= hlen;
1005:
1006: /*
1.192 ! jonathan 1007: * We are about to add a fragment; increment frag count.
! 1008: */
! 1009: ip_nfrags++;
! 1010:
! 1011: /*
1.1 cgd 1012: * If first fragment to arrive, create a reassembly queue.
1013: */
1014: if (fp == 0) {
1.131 itojun 1015: /*
1016: * Enforce upper bound on number of fragmented packets
1017: * for which we attempt reassembly;
1018: * If maxfrag is 0, never accept fragments.
1019: * If maxfrag is -1, accept all fragments without limitation.
1020: */
1021: if (ip_maxfragpackets < 0)
1022: ;
1023: else if (ip_nfragpackets >= ip_maxfragpackets)
1024: goto dropfrag;
1025: ip_nfragpackets++;
1.50 thorpej 1026: MALLOC(fp, struct ipq *, sizeof (struct ipq),
1027: M_FTABLE, M_NOWAIT);
1028: if (fp == NULL)
1.1 cgd 1029: goto dropfrag;
1.190 jonathan 1030: LIST_INSERT_HEAD(ipqhead, fp, ipq_q);
1.192 ! jonathan 1031: fp->ipq_nfrags = 1;
1.1 cgd 1032: fp->ipq_ttl = IPFRAGTTL;
1.25 cgd 1033: fp->ipq_p = ipqe->ipqe_ip->ip_p;
1034: fp->ipq_id = ipqe->ipqe_ip->ip_id;
1.148 matt 1035: TAILQ_INIT(&fp->ipq_fragq);
1.25 cgd 1036: fp->ipq_src = ipqe->ipqe_ip->ip_src;
1037: fp->ipq_dst = ipqe->ipqe_ip->ip_dst;
1038: p = NULL;
1.1 cgd 1039: goto insert;
1.192 ! jonathan 1040: } else {
! 1041: fp->ipq_nfrags++;
1.1 cgd 1042: }
1043:
1044: /*
1045: * Find a segment which begins after this one does.
1046: */
1.148 matt 1047: for (p = NULL, q = TAILQ_FIRST(&fp->ipq_fragq); q != NULL;
1048: p = q, q = TAILQ_NEXT(q, ipqe_q))
1.155 itojun 1049: if (ntohs(q->ipqe_ip->ip_off) > ntohs(ipqe->ipqe_ip->ip_off))
1.1 cgd 1050: break;
1051:
1052: /*
1053: * If there is a preceding segment, it may provide some of
1054: * our data already. If so, drop the data from the incoming
1055: * segment. If it provides all of our data, drop us.
1056: */
1.25 cgd 1057: if (p != NULL) {
1.155 itojun 1058: i = ntohs(p->ipqe_ip->ip_off) + ntohs(p->ipqe_ip->ip_len) -
1059: ntohs(ipqe->ipqe_ip->ip_off);
1.1 cgd 1060: if (i > 0) {
1.155 itojun 1061: if (i >= ntohs(ipqe->ipqe_ip->ip_len))
1.1 cgd 1062: goto dropfrag;
1.50 thorpej 1063: m_adj(ipqe->ipqe_m, i);
1.155 itojun 1064: ipqe->ipqe_ip->ip_off =
1065: htons(ntohs(ipqe->ipqe_ip->ip_off) + i);
1066: ipqe->ipqe_ip->ip_len =
1067: htons(ntohs(ipqe->ipqe_ip->ip_len) - i);
1.1 cgd 1068: }
1069: }
1070:
1071: /*
1072: * While we overlap succeeding segments trim them or,
1073: * if they are completely covered, dequeue them.
1074: */
1.155 itojun 1075: for (; q != NULL &&
1076: ntohs(ipqe->ipqe_ip->ip_off) + ntohs(ipqe->ipqe_ip->ip_len) >
1077: ntohs(q->ipqe_ip->ip_off); q = nq) {
1078: i = (ntohs(ipqe->ipqe_ip->ip_off) +
1079: ntohs(ipqe->ipqe_ip->ip_len)) - ntohs(q->ipqe_ip->ip_off);
1080: if (i < ntohs(q->ipqe_ip->ip_len)) {
1081: q->ipqe_ip->ip_len =
1082: htons(ntohs(q->ipqe_ip->ip_len) - i);
1083: q->ipqe_ip->ip_off =
1084: htons(ntohs(q->ipqe_ip->ip_off) + i);
1.50 thorpej 1085: m_adj(q->ipqe_m, i);
1.1 cgd 1086: break;
1087: }
1.148 matt 1088: nq = TAILQ_NEXT(q, ipqe_q);
1.50 thorpej 1089: m_freem(q->ipqe_m);
1.148 matt 1090: TAILQ_REMOVE(&fp->ipq_fragq, q, ipqe_q);
1.72 thorpej 1091: pool_put(&ipqent_pool, q);
1.192 ! jonathan 1092: fp->ipq_nfrags--;
! 1093: ip_nfrags--;
1.1 cgd 1094: }
1095:
1096: insert:
1097: /*
1098: * Stick new segment in its place;
1099: * check for complete reassembly.
1100: */
1.25 cgd 1101: if (p == NULL) {
1.148 matt 1102: TAILQ_INSERT_HEAD(&fp->ipq_fragq, ipqe, ipqe_q);
1.25 cgd 1103: } else {
1.148 matt 1104: TAILQ_INSERT_AFTER(&fp->ipq_fragq, p, ipqe, ipqe_q);
1.25 cgd 1105: }
1.1 cgd 1106: next = 0;
1.148 matt 1107: for (p = NULL, q = TAILQ_FIRST(&fp->ipq_fragq); q != NULL;
1108: p = q, q = TAILQ_NEXT(q, ipqe_q)) {
1.155 itojun 1109: if (ntohs(q->ipqe_ip->ip_off) != next)
1.1 cgd 1110: return (0);
1.155 itojun 1111: next += ntohs(q->ipqe_ip->ip_len);
1.1 cgd 1112: }
1.25 cgd 1113: if (p->ipqe_mff)
1.1 cgd 1114: return (0);
1115:
1116: /*
1.41 thorpej 1117: * Reassembly is complete. Check for a bogus message size and
1118: * concatenate fragments.
1.1 cgd 1119: */
1.148 matt 1120: q = TAILQ_FIRST(&fp->ipq_fragq);
1.25 cgd 1121: ip = q->ipqe_ip;
1.41 thorpej 1122: if ((next + (ip->ip_hl << 2)) > IP_MAXPACKET) {
1123: ipstat.ips_toolong++;
1124: ip_freef(fp);
1125: return (0);
1126: }
1.50 thorpej 1127: m = q->ipqe_m;
1.1 cgd 1128: t = m->m_next;
1129: m->m_next = 0;
1130: m_cat(m, t);
1.148 matt 1131: nq = TAILQ_NEXT(q, ipqe_q);
1.72 thorpej 1132: pool_put(&ipqent_pool, q);
1.25 cgd 1133: for (q = nq; q != NULL; q = nq) {
1.50 thorpej 1134: t = q->ipqe_m;
1.148 matt 1135: nq = TAILQ_NEXT(q, ipqe_q);
1.72 thorpej 1136: pool_put(&ipqent_pool, q);
1.1 cgd 1137: m_cat(m, t);
1138: }
1.192 ! jonathan 1139: ip_nfrags -= fp->ipq_nfrags;
1.1 cgd 1140:
1141: /*
1142: * Create header for new ip packet by
1143: * modifying header of first packet;
1144: * dequeue and discard fragment reassembly header.
1145: * Make header visible.
1146: */
1.155 itojun 1147: ip->ip_len = htons(next);
1.25 cgd 1148: ip->ip_src = fp->ipq_src;
1149: ip->ip_dst = fp->ipq_dst;
1150: LIST_REMOVE(fp, ipq_q);
1.50 thorpej 1151: FREE(fp, M_FTABLE);
1.131 itojun 1152: ip_nfragpackets--;
1.1 cgd 1153: m->m_len += (ip->ip_hl << 2);
1154: m->m_data -= (ip->ip_hl << 2);
1155: /* some debugging cruft by sklower, below, will go away soon */
1156: if (m->m_flags & M_PKTHDR) { /* XXX this should be done elsewhere */
1.109 augustss 1157: int plen = 0;
1.50 thorpej 1158: for (t = m; t; t = t->m_next)
1159: plen += t->m_len;
1160: m->m_pkthdr.len = plen;
1.1 cgd 1161: }
1.50 thorpej 1162: return (m);
1.1 cgd 1163:
1164: dropfrag:
1.192 ! jonathan 1165: if (fp != 0)
! 1166: fp->ipq_nfrags--;
! 1167: ip_nfrags--;
1.1 cgd 1168: ipstat.ips_fragdropped++;
1169: m_freem(m);
1.72 thorpej 1170: pool_put(&ipqent_pool, ipqe);
1.1 cgd 1171: return (0);
1172: }
1173:
1174: /*
1175: * Free a fragment reassembly header and all
1176: * associated datagrams.
1177: */
1.8 mycroft 1178: void
1.1 cgd 1179: ip_freef(fp)
1180: struct ipq *fp;
1181: {
1.109 augustss 1182: struct ipqent *q, *p;
1.192 ! jonathan 1183: u_int nfrags = 0;
1.1 cgd 1184:
1.75 thorpej 1185: IPQ_LOCK_CHECK();
1186:
1.148 matt 1187: for (q = TAILQ_FIRST(&fp->ipq_fragq); q != NULL; q = p) {
1188: p = TAILQ_NEXT(q, ipqe_q);
1.50 thorpej 1189: m_freem(q->ipqe_m);
1.192 ! jonathan 1190: nfrags++;
1.148 matt 1191: TAILQ_REMOVE(&fp->ipq_fragq, q, ipqe_q);
1.72 thorpej 1192: pool_put(&ipqent_pool, q);
1.1 cgd 1193: }
1.192 ! jonathan 1194:
! 1195: if (nfrags != fp->ipq_nfrags)
! 1196: printf("ip_freef: nfrags %d != %d\n", fp->ipq_nfrags, nfrags);
! 1197: ip_nfrags -= nfrags;
1.25 cgd 1198: LIST_REMOVE(fp, ipq_q);
1.50 thorpej 1199: FREE(fp, M_FTABLE);
1.131 itojun 1200: ip_nfragpackets--;
1.1 cgd 1201: }
1202:
1203: /*
1204: * IP timer processing;
1205: * if a timer expires on a reassembly
1206: * queue, discard it.
1207: */
1.8 mycroft 1208: void
1.1 cgd 1209: ip_slowtimo()
1210: {
1.191 jonathan 1211: static u_int dropscanidx = 0;
1212: u_int i;
1.109 augustss 1213: struct ipq *fp, *nfp;
1.24 mycroft 1214: int s = splsoftnet();
1.1 cgd 1215:
1.75 thorpej 1216: IPQ_LOCK();
1.190 jonathan 1217: for (i = 0; i < IPREASS_NHASH; i++) {
1218: for (fp = LIST_FIRST(&ipq[i]); fp != NULL; fp = nfp) {
1219: nfp = LIST_NEXT(fp, ipq_q);
1220: if (--fp->ipq_ttl == 0) {
1221: ipstat.ips_fragtimeout++;
1222: ip_freef(fp);
1223: }
1.1 cgd 1224: }
1225: }
1.131 itojun 1226: /*
1227: * If we are over the maximum number of fragments
1228: * (due to the limit being lowered), drain off
1.190 jonathan 1229: * enough to get down to the new limit. Start draining
1230: * from the reassembly hashqueue most recently drained.
1.131 itojun 1231: */
1232: if (ip_maxfragpackets < 0)
1233: ;
1234: else {
1.190 jonathan 1235: int wrapped = 0;
1236:
1237: i = dropscanidx;
1238: while (ip_nfragpackets > ip_maxfragpackets && wrapped == 0) {
1239: while (LIST_FIRST(&ipq[i]) != NULL)
1240: ip_freef(LIST_FIRST(&ipq[i]));
1241: if (++i >= IPREASS_NHASH) {
1242: i = 0;
1243: }
1244: /*
1245: * Dont scan forever even if fragment counters are
1246: * wrong: stop after scanning entire reassembly queue.
1247: */
1248: if (i == dropscanidx)
1249: wrapped = 1;
1250: }
1251: dropscanidx = i;
1.131 itojun 1252: }
1.75 thorpej 1253: IPQ_UNLOCK();
1.63 matt 1254: #ifdef GATEWAY
1255: ipflow_slowtimo();
1256: #endif
1.1 cgd 1257: splx(s);
1258: }
1259:
1260: /*
1261: * Drain off all datagram fragments.
1262: */
1.8 mycroft 1263: void
1.1 cgd 1264: ip_drain()
1265: {
1.190 jonathan 1266: int i;
1.1 cgd 1267:
1.75 thorpej 1268: /*
1269: * We may be called from a device's interrupt context. If
1270: * the ipq is already busy, just bail out now.
1271: */
1272: if (ipq_lock_try() == 0)
1273: return;
1274:
1.190 jonathan 1275: for (i = 0; i < IPREASS_NHASH; i++) {
1276: struct ipqhead *ipqh = &ipq[i];
1277: struct ipq *fp, *nfp;
1278: for (fp = LIST_FIRST(ipqh); fp != NULL; fp = nfp) {
1279: nfp = LIST_NEXT(fp, ipq_q);
1280: ip_freef(fp);
1281: ipstat.ips_fragdropped++;
1282: }
1.1 cgd 1283: }
1.75 thorpej 1284:
1285: IPQ_UNLOCK();
1.1 cgd 1286: }
1287:
1288: /*
1289: * Do option processing on a datagram,
1290: * possibly discarding it if bad options are encountered,
1291: * or forwarding it if source-routed.
1292: * Returns 1 if packet has been forwarded/freed,
1293: * 0 if the packet should be processed further.
1294: */
1.8 mycroft 1295: int
1.1 cgd 1296: ip_dooptions(m)
1297: struct mbuf *m;
1298: {
1.109 augustss 1299: struct ip *ip = mtod(m, struct ip *);
1300: u_char *cp, *cp0;
1301: struct ip_timestamp *ipt;
1302: struct in_ifaddr *ia;
1.1 cgd 1303: int opt, optlen, cnt, off, code, type = ICMP_PARAMPROB, forward = 0;
1.104 thorpej 1304: struct in_addr dst;
1.1 cgd 1305: n_time ntime;
1306:
1.13 mycroft 1307: dst = ip->ip_dst;
1.1 cgd 1308: cp = (u_char *)(ip + 1);
1309: cnt = (ip->ip_hl << 2) - sizeof (struct ip);
1310: for (; cnt > 0; cnt -= optlen, cp += optlen) {
1311: opt = cp[IPOPT_OPTVAL];
1312: if (opt == IPOPT_EOL)
1313: break;
1314: if (opt == IPOPT_NOP)
1315: optlen = 1;
1316: else {
1.113 itojun 1317: if (cnt < IPOPT_OLEN + sizeof(*cp)) {
1318: code = &cp[IPOPT_OLEN] - (u_char *)ip;
1319: goto bad;
1320: }
1.1 cgd 1321: optlen = cp[IPOPT_OLEN];
1.114 itojun 1322: if (optlen < IPOPT_OLEN + sizeof(*cp) || optlen > cnt) {
1.1 cgd 1323: code = &cp[IPOPT_OLEN] - (u_char *)ip;
1324: goto bad;
1325: }
1326: }
1327: switch (opt) {
1328:
1329: default:
1330: break;
1331:
1332: /*
1333: * Source routing with record.
1334: * Find interface with current destination address.
1335: * If none on this machine then drop if strictly routed,
1336: * or do nothing if loosely routed.
1337: * Record interface address and bring up next address
1338: * component. If strictly routed make sure next
1339: * address is on directly accessible net.
1340: */
1341: case IPOPT_LSRR:
1342: case IPOPT_SSRR:
1.47 cjs 1343: if (ip_allowsrcrt == 0) {
1344: type = ICMP_UNREACH;
1345: code = ICMP_UNREACH_NET_PROHIB;
1346: goto bad;
1347: }
1.114 itojun 1348: if (optlen < IPOPT_OFFSET + sizeof(*cp)) {
1349: code = &cp[IPOPT_OLEN] - (u_char *)ip;
1350: goto bad;
1351: }
1.1 cgd 1352: if ((off = cp[IPOPT_OFFSET]) < IPOPT_MINOFF) {
1353: code = &cp[IPOPT_OFFSET] - (u_char *)ip;
1354: goto bad;
1355: }
1356: ipaddr.sin_addr = ip->ip_dst;
1.19 mycroft 1357: ia = ifatoia(ifa_ifwithaddr(sintosa(&ipaddr)));
1.1 cgd 1358: if (ia == 0) {
1359: if (opt == IPOPT_SSRR) {
1360: type = ICMP_UNREACH;
1361: code = ICMP_UNREACH_SRCFAIL;
1362: goto bad;
1363: }
1364: /*
1365: * Loose routing, and not at next destination
1366: * yet; nothing to do except forward.
1367: */
1368: break;
1369: }
1370: off--; /* 0 origin */
1.112 sommerfe 1371: if ((off + sizeof(struct in_addr)) > optlen) {
1.1 cgd 1372: /*
1373: * End of source route. Should be for us.
1374: */
1375: save_rte(cp, ip->ip_src);
1376: break;
1377: }
1378: /*
1379: * locate outgoing interface
1380: */
1381: bcopy((caddr_t)(cp + off), (caddr_t)&ipaddr.sin_addr,
1382: sizeof(ipaddr.sin_addr));
1.96 thorpej 1383: if (opt == IPOPT_SSRR)
1384: ia = ifatoia(ifa_ifwithaddr(sintosa(&ipaddr)));
1385: else
1.1 cgd 1386: ia = ip_rtaddr(ipaddr.sin_addr);
1387: if (ia == 0) {
1388: type = ICMP_UNREACH;
1389: code = ICMP_UNREACH_SRCFAIL;
1390: goto bad;
1391: }
1392: ip->ip_dst = ipaddr.sin_addr;
1.20 mycroft 1393: bcopy((caddr_t)&ia->ia_addr.sin_addr,
1.1 cgd 1394: (caddr_t)(cp + off), sizeof(struct in_addr));
1395: cp[IPOPT_OFFSET] += sizeof(struct in_addr);
1.13 mycroft 1396: /*
1397: * Let ip_intr's mcast routing check handle mcast pkts
1398: */
1.18 mycroft 1399: forward = !IN_MULTICAST(ip->ip_dst.s_addr);
1.1 cgd 1400: break;
1401:
1402: case IPOPT_RR:
1.114 itojun 1403: if (optlen < IPOPT_OFFSET + sizeof(*cp)) {
1404: code = &cp[IPOPT_OLEN] - (u_char *)ip;
1405: goto bad;
1406: }
1.1 cgd 1407: if ((off = cp[IPOPT_OFFSET]) < IPOPT_MINOFF) {
1408: code = &cp[IPOPT_OFFSET] - (u_char *)ip;
1409: goto bad;
1410: }
1411: /*
1412: * If no space remains, ignore.
1413: */
1414: off--; /* 0 origin */
1.112 sommerfe 1415: if ((off + sizeof(struct in_addr)) > optlen)
1.1 cgd 1416: break;
1417: bcopy((caddr_t)(&ip->ip_dst), (caddr_t)&ipaddr.sin_addr,
1418: sizeof(ipaddr.sin_addr));
1419: /*
1420: * locate outgoing interface; if we're the destination,
1421: * use the incoming interface (should be same).
1422: */
1.96 thorpej 1423: if ((ia = ifatoia(ifa_ifwithaddr(sintosa(&ipaddr))))
1424: == NULL &&
1425: (ia = ip_rtaddr(ipaddr.sin_addr)) == NULL) {
1.1 cgd 1426: type = ICMP_UNREACH;
1427: code = ICMP_UNREACH_HOST;
1428: goto bad;
1429: }
1.20 mycroft 1430: bcopy((caddr_t)&ia->ia_addr.sin_addr,
1.1 cgd 1431: (caddr_t)(cp + off), sizeof(struct in_addr));
1432: cp[IPOPT_OFFSET] += sizeof(struct in_addr);
1433: break;
1434:
1435: case IPOPT_TS:
1436: code = cp - (u_char *)ip;
1437: ipt = (struct ip_timestamp *)cp;
1.114 itojun 1438: if (ipt->ipt_len < 4 || ipt->ipt_len > 40) {
1439: code = (u_char *)&ipt->ipt_len - (u_char *)ip;
1.1 cgd 1440: goto bad;
1.114 itojun 1441: }
1442: if (ipt->ipt_ptr < 5) {
1443: code = (u_char *)&ipt->ipt_ptr - (u_char *)ip;
1444: goto bad;
1445: }
1.15 cgd 1446: if (ipt->ipt_ptr > ipt->ipt_len - sizeof (int32_t)) {
1.114 itojun 1447: if (++ipt->ipt_oflw == 0) {
1448: code = (u_char *)&ipt->ipt_ptr -
1449: (u_char *)ip;
1.1 cgd 1450: goto bad;
1.114 itojun 1451: }
1.1 cgd 1452: break;
1453: }
1.104 thorpej 1454: cp0 = (cp + ipt->ipt_ptr - 1);
1.1 cgd 1455: switch (ipt->ipt_flg) {
1456:
1457: case IPOPT_TS_TSONLY:
1458: break;
1459:
1460: case IPOPT_TS_TSANDADDR:
1.66 thorpej 1461: if (ipt->ipt_ptr - 1 + sizeof(n_time) +
1.114 itojun 1462: sizeof(struct in_addr) > ipt->ipt_len) {
1463: code = (u_char *)&ipt->ipt_ptr -
1464: (u_char *)ip;
1.1 cgd 1465: goto bad;
1.114 itojun 1466: }
1.13 mycroft 1467: ipaddr.sin_addr = dst;
1.96 thorpej 1468: ia = ifatoia(ifaof_ifpforaddr(sintosa(&ipaddr),
1469: m->m_pkthdr.rcvif));
1.13 mycroft 1470: if (ia == 0)
1471: continue;
1.104 thorpej 1472: bcopy(&ia->ia_addr.sin_addr,
1473: cp0, sizeof(struct in_addr));
1.1 cgd 1474: ipt->ipt_ptr += sizeof(struct in_addr);
1475: break;
1476:
1477: case IPOPT_TS_PRESPEC:
1.66 thorpej 1478: if (ipt->ipt_ptr - 1 + sizeof(n_time) +
1.114 itojun 1479: sizeof(struct in_addr) > ipt->ipt_len) {
1480: code = (u_char *)&ipt->ipt_ptr -
1481: (u_char *)ip;
1.1 cgd 1482: goto bad;
1.114 itojun 1483: }
1.104 thorpej 1484: bcopy(cp0, &ipaddr.sin_addr,
1.1 cgd 1485: sizeof(struct in_addr));
1.96 thorpej 1486: if (ifatoia(ifa_ifwithaddr(sintosa(&ipaddr)))
1487: == NULL)
1.1 cgd 1488: continue;
1489: ipt->ipt_ptr += sizeof(struct in_addr);
1490: break;
1491:
1492: default:
1.114 itojun 1493: /* XXX can't take &ipt->ipt_flg */
1494: code = (u_char *)&ipt->ipt_ptr -
1495: (u_char *)ip + 1;
1.1 cgd 1496: goto bad;
1497: }
1498: ntime = iptime();
1.107 thorpej 1499: cp0 = (u_char *) &ntime; /* XXX grumble, GCC... */
1500: bcopy(cp0, (caddr_t)cp + ipt->ipt_ptr - 1,
1.1 cgd 1501: sizeof(n_time));
1502: ipt->ipt_ptr += sizeof(n_time);
1503: }
1504: }
1505: if (forward) {
1.26 thorpej 1506: if (ip_forwsrcrt == 0) {
1507: type = ICMP_UNREACH;
1508: code = ICMP_UNREACH_SRCFAIL;
1509: goto bad;
1510: }
1.1 cgd 1511: ip_forward(m, 1);
1512: return (1);
1.13 mycroft 1513: }
1514: return (0);
1.1 cgd 1515: bad:
1.13 mycroft 1516: icmp_error(m, type, code, 0, 0);
1517: ipstat.ips_badoptions++;
1.1 cgd 1518: return (1);
1519: }
1520:
1521: /*
1522: * Given address of next destination (final or next hop),
1523: * return internet address info of interface to be used to get there.
1524: */
1525: struct in_ifaddr *
1526: ip_rtaddr(dst)
1527: struct in_addr dst;
1528: {
1.109 augustss 1529: struct sockaddr_in *sin;
1.1 cgd 1530:
1.19 mycroft 1531: sin = satosin(&ipforward_rt.ro_dst);
1.1 cgd 1532:
1.35 mycroft 1533: if (ipforward_rt.ro_rt == 0 || !in_hosteq(dst, sin->sin_addr)) {
1.1 cgd 1534: if (ipforward_rt.ro_rt) {
1535: RTFREE(ipforward_rt.ro_rt);
1536: ipforward_rt.ro_rt = 0;
1537: }
1538: sin->sin_family = AF_INET;
1539: sin->sin_len = sizeof(*sin);
1540: sin->sin_addr = dst;
1541:
1542: rtalloc(&ipforward_rt);
1543: }
1544: if (ipforward_rt.ro_rt == 0)
1545: return ((struct in_ifaddr *)0);
1.19 mycroft 1546: return (ifatoia(ipforward_rt.ro_rt->rt_ifa));
1.1 cgd 1547: }
1548:
1549: /*
1550: * Save incoming source route for use in replies,
1551: * to be picked up later by ip_srcroute if the receiver is interested.
1552: */
1.13 mycroft 1553: void
1.1 cgd 1554: save_rte(option, dst)
1555: u_char *option;
1556: struct in_addr dst;
1557: {
1558: unsigned olen;
1559:
1560: olen = option[IPOPT_OLEN];
1561: #ifdef DIAGNOSTIC
1562: if (ipprintfs)
1.39 christos 1563: printf("save_rte: olen %d\n", olen);
1.89 itojun 1564: #endif /* 0 */
1.1 cgd 1565: if (olen > sizeof(ip_srcrt) - (1 + sizeof(dst)))
1566: return;
1567: bcopy((caddr_t)option, (caddr_t)ip_srcrt.srcopt, olen);
1568: ip_nhops = (olen - IPOPT_OFFSET - 1) / sizeof(struct in_addr);
1569: ip_srcrt.dst = dst;
1570: }
1571:
1572: /*
1573: * Retrieve incoming source route for use in replies,
1574: * in the same form used by setsockopt.
1575: * The first hop is placed before the options, will be removed later.
1576: */
1577: struct mbuf *
1578: ip_srcroute()
1579: {
1.109 augustss 1580: struct in_addr *p, *q;
1581: struct mbuf *m;
1.1 cgd 1582:
1583: if (ip_nhops == 0)
1584: return ((struct mbuf *)0);
1585: m = m_get(M_DONTWAIT, MT_SOOPTS);
1586: if (m == 0)
1587: return ((struct mbuf *)0);
1588:
1.164 matt 1589: MCLAIM(m, &inetdomain.dom_mowner);
1.13 mycroft 1590: #define OPTSIZ (sizeof(ip_srcrt.nop) + sizeof(ip_srcrt.srcopt))
1.1 cgd 1591:
1592: /* length is (nhops+1)*sizeof(addr) + sizeof(nop + srcrt header) */
1593: m->m_len = ip_nhops * sizeof(struct in_addr) + sizeof(struct in_addr) +
1594: OPTSIZ;
1595: #ifdef DIAGNOSTIC
1596: if (ipprintfs)
1.39 christos 1597: printf("ip_srcroute: nhops %d mlen %d", ip_nhops, m->m_len);
1.1 cgd 1598: #endif
1599:
1600: /*
1601: * First save first hop for return route
1602: */
1603: p = &ip_srcrt.route[ip_nhops - 1];
1604: *(mtod(m, struct in_addr *)) = *p--;
1605: #ifdef DIAGNOSTIC
1606: if (ipprintfs)
1.39 christos 1607: printf(" hops %x", ntohl(mtod(m, struct in_addr *)->s_addr));
1.1 cgd 1608: #endif
1609:
1610: /*
1611: * Copy option fields and padding (nop) to mbuf.
1612: */
1613: ip_srcrt.nop = IPOPT_NOP;
1614: ip_srcrt.srcopt[IPOPT_OFFSET] = IPOPT_MINOFF;
1615: bcopy((caddr_t)&ip_srcrt.nop,
1616: mtod(m, caddr_t) + sizeof(struct in_addr), OPTSIZ);
1617: q = (struct in_addr *)(mtod(m, caddr_t) +
1618: sizeof(struct in_addr) + OPTSIZ);
1619: #undef OPTSIZ
1620: /*
1621: * Record return path as an IP source route,
1622: * reversing the path (pointers are now aligned).
1623: */
1624: while (p >= ip_srcrt.route) {
1625: #ifdef DIAGNOSTIC
1626: if (ipprintfs)
1.39 christos 1627: printf(" %x", ntohl(q->s_addr));
1.1 cgd 1628: #endif
1629: *q++ = *p--;
1630: }
1631: /*
1632: * Last hop goes to final destination.
1633: */
1634: *q = ip_srcrt.dst;
1635: #ifdef DIAGNOSTIC
1636: if (ipprintfs)
1.39 christos 1637: printf(" %x\n", ntohl(q->s_addr));
1.1 cgd 1638: #endif
1639: return (m);
1640: }
1641:
1642: /*
1643: * Strip out IP options, at higher
1644: * level protocol in the kernel.
1645: * Second argument is buffer to which options
1646: * will be moved, and return value is their length.
1647: * XXX should be deleted; last arg currently ignored.
1648: */
1.8 mycroft 1649: void
1.1 cgd 1650: ip_stripoptions(m, mopt)
1.109 augustss 1651: struct mbuf *m;
1.1 cgd 1652: struct mbuf *mopt;
1653: {
1.109 augustss 1654: int i;
1.1 cgd 1655: struct ip *ip = mtod(m, struct ip *);
1.109 augustss 1656: caddr_t opts;
1.1 cgd 1657: int olen;
1658:
1.79 mycroft 1659: olen = (ip->ip_hl << 2) - sizeof (struct ip);
1.1 cgd 1660: opts = (caddr_t)(ip + 1);
1661: i = m->m_len - (sizeof (struct ip) + olen);
1662: bcopy(opts + olen, opts, (unsigned)i);
1663: m->m_len -= olen;
1664: if (m->m_flags & M_PKTHDR)
1665: m->m_pkthdr.len -= olen;
1.155 itojun 1666: ip->ip_len = htons(ntohs(ip->ip_len) - olen);
1.79 mycroft 1667: ip->ip_hl = sizeof (struct ip) >> 2;
1.1 cgd 1668: }
1669:
1.139 matt 1670: const int inetctlerrmap[PRC_NCMDS] = {
1.1 cgd 1671: 0, 0, 0, 0,
1672: 0, EMSGSIZE, EHOSTDOWN, EHOSTUNREACH,
1673: EHOSTUNREACH, EHOSTUNREACH, ECONNREFUSED, ECONNREFUSED,
1674: EMSGSIZE, EHOSTUNREACH, 0, 0,
1675: 0, 0, 0, 0,
1676: ENOPROTOOPT
1677: };
1678:
1679: /*
1680: * Forward a packet. If some error occurs return the sender
1681: * an icmp packet. Note we can't always generate a meaningful
1682: * icmp message because icmp doesn't have a large enough repertoire
1683: * of codes and types.
1684: *
1685: * If not forwarding, just drop the packet. This could be confusing
1686: * if ipforwarding was zero but some routing protocol was advancing
1687: * us as a gateway to somewhere. However, we must let the routing
1688: * protocol deal with that.
1689: *
1690: * The srcrt parameter indicates whether the packet is being forwarded
1691: * via a source route.
1692: */
1.13 mycroft 1693: void
1.1 cgd 1694: ip_forward(m, srcrt)
1695: struct mbuf *m;
1696: int srcrt;
1697: {
1.109 augustss 1698: struct ip *ip = mtod(m, struct ip *);
1699: struct sockaddr_in *sin;
1700: struct rtentry *rt;
1.28 christos 1701: int error, type = 0, code = 0;
1.1 cgd 1702: struct mbuf *mcopy;
1.13 mycroft 1703: n_long dest;
1704: struct ifnet *destifp;
1.173 jonathan 1705: #if defined(IPSEC) || defined(FAST_IPSEC)
1.89 itojun 1706: struct ifnet dummyifp;
1707: #endif
1.164 matt 1708:
1709: /*
1710: * We are now in the output path.
1711: */
1712: MCLAIM(m, &ip_tx_mowner);
1.135 thorpej 1713:
1714: /*
1715: * Clear any in-bound checksum flags for this packet.
1716: */
1717: m->m_pkthdr.csum_flags = 0;
1.1 cgd 1718:
1.13 mycroft 1719: dest = 0;
1.1 cgd 1720: #ifdef DIAGNOSTIC
1721: if (ipprintfs)
1.70 thorpej 1722: printf("forward: src %2.2x dst %2.2x ttl %x\n",
1723: ntohl(ip->ip_src.s_addr),
1724: ntohl(ip->ip_dst.s_addr), ip->ip_ttl);
1.1 cgd 1725: #endif
1.93 sommerfe 1726: if (m->m_flags & (M_BCAST|M_MCAST) || in_canforward(ip->ip_dst) == 0) {
1.1 cgd 1727: ipstat.ips_cantforward++;
1728: m_freem(m);
1729: return;
1730: }
1731: if (ip->ip_ttl <= IPTTLDEC) {
1.13 mycroft 1732: icmp_error(m, ICMP_TIMXCEED, ICMP_TIMXCEED_INTRANS, dest, 0);
1.1 cgd 1733: return;
1734: }
1735: ip->ip_ttl -= IPTTLDEC;
1736:
1.19 mycroft 1737: sin = satosin(&ipforward_rt.ro_dst);
1.1 cgd 1738: if ((rt = ipforward_rt.ro_rt) == 0 ||
1.35 mycroft 1739: !in_hosteq(ip->ip_dst, sin->sin_addr)) {
1.1 cgd 1740: if (ipforward_rt.ro_rt) {
1741: RTFREE(ipforward_rt.ro_rt);
1742: ipforward_rt.ro_rt = 0;
1743: }
1744: sin->sin_family = AF_INET;
1.35 mycroft 1745: sin->sin_len = sizeof(struct sockaddr_in);
1.1 cgd 1746: sin->sin_addr = ip->ip_dst;
1747:
1748: rtalloc(&ipforward_rt);
1749: if (ipforward_rt.ro_rt == 0) {
1.13 mycroft 1750: icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_HOST, dest, 0);
1.1 cgd 1751: return;
1752: }
1753: rt = ipforward_rt.ro_rt;
1754: }
1755:
1756: /*
1.34 mycroft 1757: * Save at most 68 bytes of the packet in case
1.1 cgd 1758: * we need to generate an ICMP message to the src.
1.119 itojun 1759: * Pullup to avoid sharing mbuf cluster between m and mcopy.
1.1 cgd 1760: */
1.155 itojun 1761: mcopy = m_copym(m, 0, imin(ntohs(ip->ip_len), 68), M_DONTWAIT);
1.119 itojun 1762: if (mcopy)
1763: mcopy = m_pullup(mcopy, ip->ip_hl << 2);
1.1 cgd 1764:
1765: /*
1766: * If forwarding packet using same interface that it came in on,
1767: * perhaps should send a redirect to sender to shortcut a hop.
1768: * Only send redirect if source is sending directly to us,
1769: * and if packet was not source routed (or has any options).
1770: * Also, don't send redirect if forwarding using a default route
1771: * or a route modified by a redirect.
1772: */
1773: if (rt->rt_ifp == m->m_pkthdr.rcvif &&
1774: (rt->rt_flags & (RTF_DYNAMIC|RTF_MODIFIED)) == 0 &&
1.35 mycroft 1775: !in_nullhost(satosin(rt_key(rt))->sin_addr) &&
1.1 cgd 1776: ipsendredirects && !srcrt) {
1.19 mycroft 1777: if (rt->rt_ifa &&
1778: (ip->ip_src.s_addr & ifatoia(rt->rt_ifa)->ia_subnetmask) ==
1779: ifatoia(rt->rt_ifa)->ia_subnet) {
1.77 thorpej 1780: if (rt->rt_flags & RTF_GATEWAY)
1781: dest = satosin(rt->rt_gateway)->sin_addr.s_addr;
1782: else
1783: dest = ip->ip_dst.s_addr;
1784: /*
1785: * Router requirements says to only send host
1786: * redirects.
1787: */
1788: type = ICMP_REDIRECT;
1789: code = ICMP_REDIRECT_HOST;
1.1 cgd 1790: #ifdef DIAGNOSTIC
1.77 thorpej 1791: if (ipprintfs)
1792: printf("redirect (%d) to %x\n", code,
1793: (u_int32_t)dest);
1.1 cgd 1794: #endif
1795: }
1796: }
1797:
1.27 thorpej 1798: error = ip_output(m, (struct mbuf *)0, &ipforward_rt,
1.173 jonathan 1799: (IP_FORWARDING | (ip_directedbcast ? IP_ALLOWBROADCAST : 0)),
1.174 itojun 1800: (struct ip_moptions *)NULL, (struct socket *)NULL);
1.173 jonathan 1801:
1.1 cgd 1802: if (error)
1803: ipstat.ips_cantforward++;
1804: else {
1805: ipstat.ips_forward++;
1806: if (type)
1807: ipstat.ips_redirectsent++;
1808: else {
1.63 matt 1809: if (mcopy) {
1810: #ifdef GATEWAY
1.64 thorpej 1811: if (mcopy->m_flags & M_CANFASTFWD)
1812: ipflow_create(&ipforward_rt, mcopy);
1.63 matt 1813: #endif
1.1 cgd 1814: m_freem(mcopy);
1.63 matt 1815: }
1.1 cgd 1816: return;
1817: }
1818: }
1819: if (mcopy == NULL)
1820: return;
1.13 mycroft 1821: destifp = NULL;
1822:
1.1 cgd 1823: switch (error) {
1824:
1825: case 0: /* forwarded, but need redirect */
1826: /* type, code set above */
1827: break;
1828:
1829: case ENETUNREACH: /* shouldn't happen, checked above */
1830: case EHOSTUNREACH:
1831: case ENETDOWN:
1832: case EHOSTDOWN:
1833: default:
1834: type = ICMP_UNREACH;
1835: code = ICMP_UNREACH_HOST;
1836: break;
1837:
1838: case EMSGSIZE:
1839: type = ICMP_UNREACH;
1840: code = ICMP_UNREACH_NEEDFRAG;
1.173 jonathan 1841: #if !defined(IPSEC) && !defined(FAST_IPSEC)
1.13 mycroft 1842: if (ipforward_rt.ro_rt)
1843: destifp = ipforward_rt.ro_rt->rt_ifp;
1.89 itojun 1844: #else
1845: /*
1846: * If the packet is routed over IPsec tunnel, tell the
1847: * originator the tunnel MTU.
1848: * tunnel MTU = if MTU - sizeof(IP) - ESP/AH hdrsiz
1849: * XXX quickhack!!!
1850: */
1851: if (ipforward_rt.ro_rt) {
1852: struct secpolicy *sp;
1853: int ipsecerror;
1.95 itojun 1854: size_t ipsechdr;
1.89 itojun 1855: struct route *ro;
1856:
1857: sp = ipsec4_getpolicybyaddr(mcopy,
1.170 itojun 1858: IPSEC_DIR_OUTBOUND, IP_FORWARDING,
1859: &ipsecerror);
1.89 itojun 1860:
1861: if (sp == NULL)
1862: destifp = ipforward_rt.ro_rt->rt_ifp;
1863: else {
1864: /* count IPsec header size */
1.95 itojun 1865: ipsechdr = ipsec4_hdrsiz(mcopy,
1.170 itojun 1866: IPSEC_DIR_OUTBOUND, NULL);
1.89 itojun 1867:
1868: /*
1869: * find the correct route for outer IPv4
1870: * header, compute tunnel MTU.
1871: *
1872: * XXX BUG ALERT
1873: * The "dummyifp" code relies upon the fact
1874: * that icmp_error() touches only ifp->if_mtu.
1875: */
1876: /*XXX*/
1877: destifp = NULL;
1878: if (sp->req != NULL
1.95 itojun 1879: && sp->req->sav != NULL
1880: && sp->req->sav->sah != NULL) {
1881: ro = &sp->req->sav->sah->sa_route;
1.89 itojun 1882: if (ro->ro_rt && ro->ro_rt->rt_ifp) {
1883: dummyifp.if_mtu =
1.151 itojun 1884: ro->ro_rt->rt_rmx.rmx_mtu ?
1885: ro->ro_rt->rt_rmx.rmx_mtu :
1.89 itojun 1886: ro->ro_rt->rt_ifp->if_mtu;
1887: dummyifp.if_mtu -= ipsechdr;
1888: destifp = &dummyifp;
1889: }
1890: }
1891:
1.173 jonathan 1892: #ifdef IPSEC
1.89 itojun 1893: key_freesp(sp);
1.173 jonathan 1894: #else
1895: KEY_FREESP(&sp);
1896: #endif
1.89 itojun 1897: }
1898: }
1899: #endif /*IPSEC*/
1.1 cgd 1900: ipstat.ips_cantfrag++;
1901: break;
1902:
1903: case ENOBUFS:
1.143 itojun 1904: #if 1
1905: /*
1906: * a router should not generate ICMP_SOURCEQUENCH as
1907: * required in RFC1812 Requirements for IP Version 4 Routers.
1908: * source quench could be a big problem under DoS attacks,
1.149 wiz 1909: * or if the underlying interface is rate-limited.
1.143 itojun 1910: */
1911: if (mcopy)
1912: m_freem(mcopy);
1913: return;
1914: #else
1.1 cgd 1915: type = ICMP_SOURCEQUENCH;
1916: code = 0;
1917: break;
1.143 itojun 1918: #endif
1.1 cgd 1919: }
1.13 mycroft 1920: icmp_error(mcopy, type, code, dest, destifp);
1.44 thorpej 1921: }
1922:
1923: void
1924: ip_savecontrol(inp, mp, ip, m)
1.109 augustss 1925: struct inpcb *inp;
1926: struct mbuf **mp;
1927: struct ip *ip;
1928: struct mbuf *m;
1.44 thorpej 1929: {
1930:
1931: if (inp->inp_socket->so_options & SO_TIMESTAMP) {
1932: struct timeval tv;
1933:
1934: microtime(&tv);
1935: *mp = sbcreatecontrol((caddr_t) &tv, sizeof(tv),
1936: SCM_TIMESTAMP, SOL_SOCKET);
1937: if (*mp)
1938: mp = &(*mp)->m_next;
1939: }
1940: if (inp->inp_flags & INP_RECVDSTADDR) {
1941: *mp = sbcreatecontrol((caddr_t) &ip->ip_dst,
1942: sizeof(struct in_addr), IP_RECVDSTADDR, IPPROTO_IP);
1943: if (*mp)
1944: mp = &(*mp)->m_next;
1945: }
1946: #ifdef notyet
1947: /*
1948: * XXX
1949: * Moving these out of udp_input() made them even more broken
1950: * than they already were.
1951: * - fenner@parc.xerox.com
1952: */
1953: /* options were tossed already */
1954: if (inp->inp_flags & INP_RECVOPTS) {
1955: *mp = sbcreatecontrol((caddr_t) opts_deleted_above,
1956: sizeof(struct in_addr), IP_RECVOPTS, IPPROTO_IP);
1957: if (*mp)
1958: mp = &(*mp)->m_next;
1959: }
1960: /* ip_srcroute doesn't do what we want here, need to fix */
1961: if (inp->inp_flags & INP_RECVRETOPTS) {
1962: *mp = sbcreatecontrol((caddr_t) ip_srcroute(),
1963: sizeof(struct in_addr), IP_RECVRETOPTS, IPPROTO_IP);
1964: if (*mp)
1965: mp = &(*mp)->m_next;
1966: }
1967: #endif
1968: if (inp->inp_flags & INP_RECVIF) {
1969: struct sockaddr_dl sdl;
1970:
1971: sdl.sdl_len = offsetof(struct sockaddr_dl, sdl_data[0]);
1972: sdl.sdl_family = AF_LINK;
1973: sdl.sdl_index = m->m_pkthdr.rcvif ?
1974: m->m_pkthdr.rcvif->if_index : 0;
1975: sdl.sdl_nlen = sdl.sdl_alen = sdl.sdl_slen = 0;
1976: *mp = sbcreatecontrol((caddr_t) &sdl, sdl.sdl_len,
1977: IP_RECVIF, IPPROTO_IP);
1978: if (*mp)
1979: mp = &(*mp)->m_next;
1980: }
1.13 mycroft 1981: }
1982:
1.189 atatat 1983: /*
1984: * sysctl helper routine for net.inet.ip.mtudisctimeout. checks the
1985: * range of the new value and tweaks timers if it changes.
1986: */
1987: static int
1988: sysctl_net_inet_ip_pmtudto(SYSCTLFN_ARGS)
1.13 mycroft 1989: {
1.189 atatat 1990: int error, tmp;
1991: struct sysctlnode node;
1992:
1993: node = *rnode;
1994: tmp = ip_mtudisc_timeout;
1995: node.sysctl_data = &tmp;
1996: error = sysctl_lookup(SYSCTLFN_CALL(&node));
1997: if (error || newp == NULL)
1998: return (error);
1999: if (tmp < 0)
2000: return (EINVAL);
1.52 thorpej 2001:
1.189 atatat 2002: ip_mtudisc_timeout = tmp;
2003: rt_timer_queue_change(ip_mtudisc_timeout_q, ip_mtudisc_timeout);
2004:
2005: return (0);
2006: }
1.54 lukem 2007:
1.65 matt 2008: #ifdef GATEWAY
1.189 atatat 2009: /*
2010: * sysctl helper routine for net.inet.ip.maxflows. apparently if
2011: * maxflows is even looked up, we "reap flows".
2012: */
2013: static int
2014: sysctl_net_inet_ip_maxflows(SYSCTLFN_ARGS)
2015: {
2016: int s;
1.67 thorpej 2017:
1.189 atatat 2018: s = sysctl_lookup(SYSCTLFN_CALL(rnode));
2019: if (s)
2020: return (s);
2021:
2022: s = splsoftnet();
2023: ipflow_reap(0);
2024: splx(s);
1.144 martin 2025:
1.189 atatat 2026: return (0);
2027: }
2028: #endif /* GATEWAY */
1.117 tron 2029:
1.131 itojun 2030:
1.189 atatat 2031: SYSCTL_SETUP(sysctl_net_inet_ip_setup, "sysctl net.inet.ip subtree setup")
2032: {
2033: extern int subnetsarelocal, hostzeroisbroadcast;
1.180 jonathan 2034:
1.189 atatat 2035: sysctl_createv(SYSCTL_PERMANENT,
2036: CTLTYPE_NODE, "net", NULL,
2037: NULL, 0, NULL, 0,
2038: CTL_NET, CTL_EOL);
2039: sysctl_createv(SYSCTL_PERMANENT,
2040: CTLTYPE_NODE, "inet", NULL,
2041: NULL, 0, NULL, 0,
2042: CTL_NET, PF_INET, CTL_EOL);
2043: sysctl_createv(SYSCTL_PERMANENT,
2044: CTLTYPE_NODE, "ip", NULL,
2045: NULL, 0, NULL, 0,
2046: CTL_NET, PF_INET, IPPROTO_IP, CTL_EOL);
2047:
2048: sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
2049: CTLTYPE_INT, "forwarding", NULL,
2050: NULL, 0, &ipforwarding, 0,
2051: CTL_NET, PF_INET, IPPROTO_IP,
2052: IPCTL_FORWARDING, CTL_EOL);
2053: sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
2054: CTLTYPE_INT, "redirect", NULL,
2055: NULL, 0, &ipsendredirects, 0,
2056: CTL_NET, PF_INET, IPPROTO_IP,
2057: IPCTL_SENDREDIRECTS, CTL_EOL);
2058: sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
2059: CTLTYPE_INT, "ttl", NULL,
2060: NULL, 0, &ip_defttl, 0,
2061: CTL_NET, PF_INET, IPPROTO_IP,
2062: IPCTL_DEFTTL, CTL_EOL);
2063: #ifdef IPCTL_DEFMTU
2064: sysctl_createv(SYSCTL_PERMANENT /* |SYSCTL_READWRITE? */,
2065: CTLTYPE_INT, "mtu", NULL,
2066: NULL, 0, &ip_mtu, 0,
2067: CTL_NET, PF_INET, IPPROTO_IP,
2068: IPCTL_DEFMTU, CTL_EOL);
2069: #endif /* IPCTL_DEFMTU */
2070: sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READONLY1,
2071: CTLTYPE_INT, "forwsrcrt", NULL,
2072: NULL, 0, &ip_forwsrcrt, 0,
2073: CTL_NET, PF_INET, IPPROTO_IP,
2074: IPCTL_FORWSRCRT, CTL_EOL);
2075: sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
2076: CTLTYPE_INT, "directed-broadcast", NULL,
2077: NULL, 0, &ip_directedbcast, 0,
2078: CTL_NET, PF_INET, IPPROTO_IP,
2079: IPCTL_DIRECTEDBCAST, CTL_EOL);
2080: sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
2081: CTLTYPE_INT, "allowsrcrt", NULL,
2082: NULL, 0, &ip_allowsrcrt, 0,
2083: CTL_NET, PF_INET, IPPROTO_IP,
2084: IPCTL_ALLOWSRCRT, CTL_EOL);
2085: sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
2086: CTLTYPE_INT, "subnetsarelocal", NULL,
2087: NULL, 0, &subnetsarelocal, 0,
2088: CTL_NET, PF_INET, IPPROTO_IP,
2089: IPCTL_SUBNETSARELOCAL, CTL_EOL);
2090: sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
2091: CTLTYPE_INT, "mtudisc", NULL,
2092: NULL, 0, &ip_mtudisc, 0,
2093: CTL_NET, PF_INET, IPPROTO_IP,
2094: IPCTL_MTUDISC, CTL_EOL);
2095: sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
2096: CTLTYPE_INT, "anonportmin", NULL,
2097: sysctl_net_inet_ip_ports, 0, &anonportmin, 0,
2098: CTL_NET, PF_INET, IPPROTO_IP,
2099: IPCTL_ANONPORTMIN, CTL_EOL);
2100: sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
2101: CTLTYPE_INT, "anonportmax", NULL,
2102: sysctl_net_inet_ip_ports, 0, &anonportmax, 0,
2103: CTL_NET, PF_INET, IPPROTO_IP,
2104: IPCTL_ANONPORTMAX, CTL_EOL);
2105: sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
2106: CTLTYPE_INT, "mtudisctimeout", NULL,
2107: sysctl_net_inet_ip_pmtudto, 0, &ip_mtudisc_timeout, 0,
2108: CTL_NET, PF_INET, IPPROTO_IP,
2109: IPCTL_MTUDISCTIMEOUT, CTL_EOL);
2110: #ifdef GATEWAY
2111: sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
2112: CTLTYPE_INT, "maxflows", NULL,
2113: sysctl_net_inet_ip_maxflows, 0, &ip_maxflows, 0,
2114: CTL_NET, PF_INET, IPPROTO_IP,
2115: IPCTL_MAXFLOWS, CTL_EOL);
2116: #endif /* GATEWAY */
2117: sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
2118: CTLTYPE_INT, "hostzerobroadcast", NULL,
2119: NULL, 0, &hostzeroisbroadcast, 0,
2120: CTL_NET, PF_INET, IPPROTO_IP,
2121: IPCTL_HOSTZEROBROADCAST, CTL_EOL);
2122: #if NGIF > 0
2123: sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
2124: CTLTYPE_INT, "gifttl", NULL,
2125: NULL, 0, &ip_gif_ttl, 0,
2126: CTL_NET, PF_INET, IPPROTO_IP,
2127: IPCTL_GIF_TTL, CTL_EOL);
2128: #endif /* NGIF */
2129: #ifndef IPNOPRIVPORTS
2130: sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
2131: CTLTYPE_INT, "lowportmin", NULL,
2132: sysctl_net_inet_ip_ports, 0, &lowportmin, 0,
2133: CTL_NET, PF_INET, IPPROTO_IP,
2134: IPCTL_LOWPORTMIN, CTL_EOL);
2135: sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
2136: CTLTYPE_INT, "lowportmax", NULL,
2137: sysctl_net_inet_ip_ports, 0, &lowportmax, 0,
2138: CTL_NET, PF_INET, IPPROTO_IP,
2139: IPCTL_LOWPORTMAX, CTL_EOL);
2140: #endif /* IPNOPRIVPORTS */
2141: sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
2142: CTLTYPE_INT, "maxfragpackets", NULL,
2143: NULL, 0, &ip_maxfragpackets, 0,
2144: CTL_NET, PF_INET, IPPROTO_IP,
2145: IPCTL_MAXFRAGPACKETS, CTL_EOL);
2146: #if NGRE > 0
2147: sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
2148: CTLTYPE_INT, "grettl", NULL,
2149: NULL, 0, &ip_gre_ttl, 0,
2150: CTL_NET, PF_INET, IPPROTO_IP,
2151: IPCTL_GRE_TTL, CTL_EOL);
2152: #endif /* NGRE */
2153: sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
2154: CTLTYPE_INT, "checkinterface", NULL,
2155: NULL, 0, &ip_checkinterface, 0,
2156: CTL_NET, PF_INET, IPPROTO_IP,
2157: IPCTL_CHECKINTERFACE, CTL_EOL);
2158: sysctl_createv(SYSCTL_PERMANENT|SYSCTL_READWRITE,
2159: CTLTYPE_INT, "random_id", NULL,
2160: NULL, 0, &ip_do_randomid, 0,
2161: CTL_NET, PF_INET, IPPROTO_IP,
2162: IPCTL_RANDOMID, CTL_EOL);
1.1 cgd 2163: }
CVSweb <webmaster@jp.NetBSD.org>