Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sys/netinet/ip_input.c,v rcsdiff: /ftp/cvs/cvsroot/src/sys/netinet/ip_input.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.53.2.1 retrieving revision 1.57 diff -u -p -r1.53.2.1 -r1.57 --- src/sys/netinet/ip_input.c 1998/05/09 03:33:00 1.53.2.1 +++ src/sys/netinet/ip_input.c 1998/02/13 18:21:44 1.57 @@ -1,4 +1,4 @@ -/* $NetBSD: ip_input.c,v 1.53.2.1 1998/05/09 03:33:00 mycroft Exp $ */ +/* $NetBSD: ip_input.c,v 1.57 1998/02/13 18:21:44 tls Exp $ */ /* * Copyright (c) 1982, 1986, 1988, 1993 @@ -35,6 +35,8 @@ * @(#)ip_input.c 8.2 (Berkeley) 1/4/94 */ +#include "opt_mrouting.h" + #include #include #include @@ -64,9 +66,6 @@ #include #include -/* XXX should really put this in libkern.h */ -#define offsetof(type, member) ((size_t)(&((type *)0)->member)) - #ifndef IPFORWARDING #ifdef GATEWAY #define IPFORWARDING 1 /* forward IP packets not for us */ @@ -86,10 +85,6 @@ #ifndef IPMTUDISC #define IPMTUDISC 0 #endif -#ifndef IPMTUDISCTIMEOUT -#define IPMTUDISCTIMEOUT (10 * 60) /* as per RFC 1191 */ -#endif - /* * Note: DIRECTED_BROADCAST is handled this way so that previous @@ -109,18 +104,16 @@ int ip_forwsrcrt = IPFORWSRCRT; int ip_directedbcast = IPDIRECTEDBCAST; int ip_allowsrcrt = IPALLOWSRCRT; int ip_mtudisc = IPMTUDISC; -u_int ip_mtudisc_timeout = IPMTUDISCTIMEOUT; #ifdef DIAGNOSTIC int ipprintfs = 0; #endif -struct rttimer_queue *ip_mtudisc_timeout_q = NULL; - extern struct domain inetdomain; extern struct protosw inetsw[]; u_char ip_protox[IPPROTO_MAX]; int ipqmaxlen = IFQ_MAXLEN; struct in_ifaddrhead in_ifaddr; +struct in_ifaddrhashhead *in_ifaddrhashtbl; struct ifqueue ipintrq; /* @@ -164,10 +157,8 @@ ip_init() ip_id = time.tv_sec & 0xffff; ipintrq.ifq_maxlen = ipqmaxlen; TAILQ_INIT(&in_ifaddr); - - if (ip_mtudisc != 0) - ip_mtudisc_timeout_q = - rt_timer_queue_create(ip_mtudisc_timeout); + in_ifaddrhashtbl = + hashinit(IN_IFADDR_HASH_SIZE, M_IFADDR, M_WAITOK, &in_ifaddrhash); } struct sockaddr_in ipaddr = { sizeof(ipaddr), AF_INET }; @@ -184,6 +175,7 @@ ipintr() register struct mbuf *m; register struct ipq *fp; register struct in_ifaddr *ia; + register struct ifaddr *ifa; struct ipqent *ipqe; int hlen = 0, mff, len, s; #ifdef PFIL_HOOKS @@ -293,12 +285,13 @@ next: /* * Check our list of addresses, to see if the packet is for us. */ - for (ia = in_ifaddr.tqh_first; ia; ia = ia->ia_list.tqe_next) { - if (in_hosteq(ip->ip_dst, ia->ia_addr.sin_addr)) - goto ours; - if (((ip_directedbcast == 0) || (ip_directedbcast && - ia->ia_ifp == m->m_pkthdr.rcvif)) && - (ia->ia_ifp->if_flags & IFF_BROADCAST)) { + INADDR_TO_IA(ip->ip_dst, ia); + if (ia != NULL) goto ours; + if (m->m_pkthdr.rcvif->if_flags & IFF_BROADCAST) { + for (ifa = m->m_pkthdr.rcvif->if_addrlist.tqh_first; + ifa != NULL; ifa = ifa->ifa_list.tqe_next) { + if (ifa->ifa_addr->sa_family != AF_INET) continue; + ia = ifatoia(ifa); if (in_hosteq(ip->ip_dst, ia->ia_broadaddr.sin_addr) || in_hosteq(ip->ip_dst, ia->ia_netbroadcast) || /* @@ -308,14 +301,13 @@ next: ip->ip_dst.s_addr == ia->ia_subnet || ip->ip_dst.s_addr == ia->ia_net) goto ours; + /* + * An interface with IP address zero accepts + * all packets that arrive on that interface. + */ + if (in_nullhost(ia->ia_addr.sin_addr)) + goto ours; } - /* - * An interface with IP address zero accepts - * all packets that arrive on that interface. - */ - if ((ia->ia_ifp == m->m_pkthdr.rcvif) && - in_nullhost(ia->ia_addr.sin_addr)) - goto ours; } if (IN_MULTICAST(ip->ip_dst.s_addr)) { struct in_multi *inm; @@ -1259,7 +1251,8 @@ ip_sysctl(name, namelen, oldp, oldlenp, size_t newlen; { extern int subnetsarelocal; - int error; + + int error, old; /* All sysctl names at this level are terminal. */ if (namelen != 1) @@ -1295,23 +1288,32 @@ ip_sysctl(name, namelen, oldp, oldlenp, return (sysctl_int(oldp, oldlenp, newp, newlen, &subnetsarelocal)); case IPCTL_MTUDISC: - error = sysctl_int(oldp, oldlenp, newp, newlen, - &ip_mtudisc); - if (ip_mtudisc != 0 && ip_mtudisc_timeout_q == NULL) { - ip_mtudisc_timeout_q = - rt_timer_queue_create(ip_mtudisc_timeout); - } else if (ip_mtudisc == 0 && ip_mtudisc_timeout_q != NULL) { - rt_timer_queue_destroy(ip_mtudisc_timeout_q, TRUE); - ip_mtudisc_timeout_q = NULL; + return (sysctl_int(oldp, oldlenp, newp, newlen, + &ip_mtudisc)); + case IPCTL_ANONPORTMIN: + old = anonportmin; + error = sysctl_int(oldp, oldlenp, newp, newlen, &anonportmin); + if (anonportmin >= anonportmax || anonportmin > 65535 +#ifndef IPNOPRIVPORTS + || anonportmin < IPPORT_RESERVED +#endif + ) { + anonportmin = old; + return (EINVAL); + } + return (error); + case IPCTL_ANONPORTMAX: + old = anonportmax; + error = sysctl_int(oldp, oldlenp, newp, newlen, &anonportmax); + if (anonportmin >= anonportmax || anonportmax > 65535 +#ifndef IPNOPRIVPORTS + || anonportmax < IPPORT_RESERVED +#endif + ) { + anonportmax = old; + return (EINVAL); } - return error; - case IPCTL_MTUDISCTIMEOUT: - error = sysctl_int(oldp, oldlenp, newp, newlen, - &ip_mtudisc_timeout); - if (ip_mtudisc_timeout_q != NULL) - rt_timer_queue_change(ip_mtudisc_timeout_q, - ip_mtudisc_timeout); - return (error); + return (error); default: return (EOPNOTSUPP); }