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.269 retrieving revision 1.278 diff -u -p -r1.269 -r1.278 --- src/sys/netinet/ip_input.c 2008/04/28 20:24:09 1.269 +++ src/sys/netinet/ip_input.c 2009/01/19 02:27:57 1.278 @@ -1,4 +1,4 @@ -/* $NetBSD: ip_input.c,v 1.269 2008/04/28 20:24:09 martin Exp $ */ +/* $NetBSD: ip_input.c,v 1.278 2009/01/19 02:27:57 christos Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -91,9 +91,10 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.269 2008/04/28 20:24:09 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.278 2009/01/19 02:27:57 christos Exp $"); #include "opt_inet.h" +#include "opt_compat_netbsd.h" #include "opt_gateway.h" #include "opt_pfil_hooks.h" #include "opt_ipsec.h" @@ -173,6 +174,11 @@ __KERNEL_RCSID(0, "$NetBSD: ip_input.c,v #define IPMTUDISCTIMEOUT (10 * 60) /* as per RFC 1191 */ #endif +#ifdef COMPAT_50 +#include +#include +#endif + /* * Note: DIRECTED_BROADCAST is handled this way so that previous * configuration using this option will Just Work. @@ -330,10 +336,8 @@ do { \ #define IPQ_UNLOCK() ipq_unlock() -POOL_INIT(inmulti_pool, sizeof(struct in_multi), 0, 0, 0, "inmltpl", NULL, - IPL_SOFTNET); -POOL_INIT(ipqent_pool, sizeof(struct ipqent), 0, 0, 0, "ipqepl", NULL, - IPL_VM); +struct pool inmulti_pool; +struct pool ipqent_pool; #ifdef INET_CSUM_COUNTERS #include @@ -399,6 +403,11 @@ ip_init(void) const struct protosw *pr; int i; + pool_init(&inmulti_pool, sizeof(struct in_multi), 0, 0, 0, "inmltpl", + NULL, IPL_SOFTNET); + pool_init(&ipqent_pool, sizeof(struct ipqent), 0, 0, 0, "ipqepl", + NULL, IPL_VM); + pr = pffindproto(PF_INET, IPPROTO_RAW, SOCK_RAW); if (pr == 0) panic("ip_init"); @@ -420,10 +429,10 @@ ip_init(void) ip_nmbclusters_changed(); TAILQ_INIT(&in_ifaddrhead); - in_ifaddrhashtbl = hashinit(IN_IFADDR_HASH_SIZE, HASH_LIST, M_IFADDR, - M_WAITOK, &in_ifaddrhash); - in_multihashtbl = hashinit(IN_IFADDR_HASH_SIZE, HASH_LIST, M_IPMADDR, - M_WAITOK, &in_multihash); + in_ifaddrhashtbl = hashinit(IN_IFADDR_HASH_SIZE, HASH_LIST, true, + &in_ifaddrhash); + in_multihashtbl = hashinit(IN_IFADDR_HASH_SIZE, HASH_LIST, true, + &in_multihash); ip_mtudisc_timeout_q = rt_timer_queue_create(ip_mtudisc_timeout); #ifdef GATEWAY ipflow_init(ip_hashsize); @@ -928,6 +937,7 @@ ours: */ if (ip->ip_tos != fp->ipq_tos) { IP_STATINC(IP_STAT_BADFRAGS); + IPQ_UNLOCK(); goto bad; } goto found; @@ -1118,8 +1128,7 @@ ip_reass(struct ipqent *ipqe, struct ipq else if (ip_nfragpackets >= ip_maxfragpackets) goto dropfrag; ip_nfragpackets++; - MALLOC(fp, struct ipq *, sizeof (struct ipq), - M_FTABLE, M_NOWAIT); + fp = malloc(sizeof (struct ipq), M_FTABLE, M_NOWAIT); if (fp == NULL) goto dropfrag; LIST_INSERT_HEAD(ipqhead, fp, ipq_q); @@ -1250,7 +1259,7 @@ insert: ip->ip_src = fp->ipq_src; ip->ip_dst = fp->ipq_dst; LIST_REMOVE(fp, ipq_q); - FREE(fp, M_FTABLE); + free(fp, M_FTABLE); ip_nfragpackets--; m->m_len += (ip->ip_hl << 2); m->m_data -= (ip->ip_hl << 2); @@ -1303,7 +1312,7 @@ ip_freef(struct ipq *fp) printf("ip_freef: nfrags %d != %d\n", fp->ipq_nfrags, nfrags); ip_nfrags -= nfrags; LIST_REMOVE(fp, ipq_q); - FREE(fp, M_FTABLE); + free(fp, M_FTABLE); ip_nfragpackets--; } @@ -1436,13 +1445,13 @@ ip_slowtimo(void) } /* - * Drain off all datagram fragments. + * Drain off all datagram fragments. Don't acquire softnet_lock as + * can be called from hardware interrupt context. */ void ip_drain(void) { - mutex_enter(softnet_lock); KERNEL_LOCK(1, NULL); /* @@ -1459,7 +1468,6 @@ ip_drain(void) } KERNEL_UNLOCK_ONE(NULL); - mutex_exit(softnet_lock); } /* @@ -1968,9 +1976,11 @@ ip_forward(struct mbuf *m, int srcrt) type = ICMP_UNREACH; code = ICMP_UNREACH_NEEDFRAG; - if ((rt = rtcache_validate(&ipforward_rt)) != NULL) { + if ((rt = rtcache_validate(&ipforward_rt)) != NULL) + destmtu = rt->rt_ifp->if_mtu; #if defined(IPSEC) || defined(FAST_IPSEC) + { /* * If the packet is routed over IPsec tunnel, tell the * originator the tunnel MTU. @@ -1986,10 +1996,7 @@ ip_forward(struct mbuf *m, int srcrt) sp = ipsec4_getpolicybyaddr(mcopy, IPSEC_DIR_OUTBOUND, IP_FORWARDING, &ipsecerror); -#endif - destmtu = rt->rt_ifp->if_mtu; -#if defined(IPSEC) || defined(FAST_IPSEC) if (sp != NULL) { /* count IPsec header size */ ipsechdr = ipsec4_hdrsiz(mcopy, @@ -2004,6 +2011,7 @@ ip_forward(struct mbuf *m, int srcrt) && sp->req->sav != NULL && sp->req->sav->sah != NULL) { ro = &sp->req->sav->sah->sa_route; + rt = rtcache_validate(ro); if (rt && rt->rt_ifp) { destmtu = rt->rt_rmx.rmx_mtu ? @@ -2019,8 +2027,8 @@ ip_forward(struct mbuf *m, int srcrt) KEY_FREESP(&sp); #endif } -#endif /*defined(IPSEC) || defined(FAST_IPSEC)*/ } +#endif /*defined(IPSEC) || defined(FAST_IPSEC)*/ IP_STATINC(IP_STAT_CANTFRAG); break; @@ -2049,10 +2057,22 @@ ip_savecontrol(struct inpcb *inp, struct struct mbuf *m) { - if (inp->inp_socket->so_options & SO_TIMESTAMP) { + if (inp->inp_socket->so_options & SO_TIMESTAMP +#ifdef SO_OTIMESTAMP + || inp->inp_socket->so_options & SO_OTIMESTAMP +#endif + ) { struct timeval tv; microtime(&tv); +#ifdef SO_OTIMESTAMP + if (inp->inp_socket->so_options & SO_OTIMESTAMP) { + struct timeval50 tv50; + timeval_to_timeval50(&tv, &tv50); + *mp = sbcreatecontrol((void *) &tv50, sizeof(tv50), + SCM_OTIMESTAMP, SOL_SOCKET); + } else +#endif *mp = sbcreatecontrol((void *) &tv, sizeof(tv), SCM_TIMESTAMP, SOL_SOCKET); if (*mp) @@ -2144,9 +2164,13 @@ sysctl_net_inet_ip_pmtudto(SYSCTLFN_ARGS if (tmp < 0) return (EINVAL); + mutex_enter(softnet_lock); + ip_mtudisc_timeout = tmp; rt_timer_queue_change(ip_mtudisc_timeout_q, ip_mtudisc_timeout); + mutex_exit(softnet_lock); + return (0); } @@ -2157,15 +2181,19 @@ sysctl_net_inet_ip_pmtudto(SYSCTLFN_ARGS static int sysctl_net_inet_ip_maxflows(SYSCTLFN_ARGS) { - int s; + int error; + + error = sysctl_lookup(SYSCTLFN_CALL(rnode)); + if (error || newp == NULL) + return (error); - s = sysctl_lookup(SYSCTLFN_CALL(rnode)); - if (s || newp == NULL) - return (s); + mutex_enter(softnet_lock); + KERNEL_LOCK(1, NULL); - s = splsoftnet(); ipflow_prune(); - splx(s); + + KERNEL_UNLOCK_ONE(NULL); + mutex_exit(softnet_lock); return (0); } @@ -2187,29 +2215,30 @@ sysctl_net_inet_ip_hashsize(SYSCTLFN_ARG /* * Can only fail due to malloc() */ - if (ipflow_invalidate_all(tmp)) - return ENOMEM; + mutex_enter(softnet_lock); + KERNEL_LOCK(1, NULL); + + error = ipflow_invalidate_all(tmp); + + KERNEL_UNLOCK_ONE(NULL); + mutex_exit(softnet_lock); + } else { /* * EINVAL if not a power of 2 */ - return EINVAL; + error = EINVAL; } - return (0); + return error; } #endif /* GATEWAY */ static int sysctl_net_inet_ip_stats(SYSCTLFN_ARGS) { - netstat_sysctl_context ctx; - uint64_t ips[IP_NSTATS]; - ctx.ctx_stat = ipstat_percpu; - ctx.ctx_counters = ips; - ctx.ctx_ncounters = IP_NSTATS; - return (NETSTAT_SYSCTL(&ctx)); + return (NETSTAT_SYSCTL(ipstat_percpu, IP_NSTATS)); } SYSCTL_SETUP(sysctl_net_inet_ip_setup, "sysctl net.inet.ip subtree setup")