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