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.347.2.1 retrieving revision 1.362 diff -u -p -r1.347.2.1 -r1.362 --- src/sys/netinet/ip_input.c 2017/04/21 16:54:06 1.347.2.1 +++ src/sys/netinet/ip_input.c 2017/11/17 07:37:12 1.362 @@ -1,4 +1,4 @@ -/* $NetBSD: ip_input.c,v 1.347.2.1 2017/04/21 16:54:06 bouyer Exp $ */ +/* $NetBSD: ip_input.c,v 1.362 2017/11/17 07:37:12 ozaki-r Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -91,11 +91,10 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.347.2.1 2017/04/21 16:54:06 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.362 2017/11/17 07:37:12 ozaki-r Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" -#include "opt_compat_netbsd.h" #include "opt_gateway.h" #include "opt_ipsec.h" #include "opt_mrouting.h" @@ -174,11 +173,6 @@ __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. @@ -342,11 +336,7 @@ ip_init(void) #endif /* MBUFTRACE */ ipstat_percpu = percpu_alloc(sizeof(uint64_t) * IP_NSTATS); - ipforward_rt_percpu = percpu_alloc(sizeof(struct route)); - if (ipforward_rt_percpu == NULL) - panic("failed to allocate ipforward_rt_percpu"); - ip_mtudisc_timeout_q = rt_timer_queue_create(ip_mtudisc_timeout); } @@ -436,15 +426,11 @@ ipintr(void *arg __unused) KASSERT(cpu_softintr_p()); -#ifndef NET_MPSAFE - mutex_enter(softnet_lock); -#endif + SOFTNET_LOCK_UNLESS_NET_MPSAFE(); while ((m = pktq_dequeue(ip_pktq)) != NULL) { ip_input(m); } -#ifndef NET_MPSAFE - mutex_exit(softnet_lock); -#endif + SOFTNET_UNLOCK_UNLESS_NET_MPSAFE(); } /* @@ -762,15 +748,12 @@ ip_input(struct mbuf *m) return; } #ifdef IPSEC - /* Perform IPsec, if any. */ + /* Check the security policy (SP) for the packet */ if (ipsec_used) { - SOFTNET_LOCK(); if (ipsec4_input(m, IP_FORWARDING | (ip_directedbcast ? IP_ALLOWBROADCAST : 0)) != 0) { - SOFTNET_UNLOCK(); goto out; } - SOFTNET_UNLOCK(); } #endif ip_forward(m, srcrt, ifp); @@ -813,12 +796,9 @@ ours: */ if (ipsec_used && (inetsw[ip_protox[ip->ip_p]].pr_flags & PR_LASTHDR) != 0) { - SOFTNET_LOCK(); if (ipsec4_input(m, 0) != 0) { - SOFTNET_UNLOCK(); goto out; } - SOFTNET_UNLOCK(); } #endif @@ -842,9 +822,7 @@ ours: const int off = hlen, nh = ip->ip_p; - SOFTNET_LOCK(); (*inetsw[ip_protox[nh]].pr_input)(m, off, nh); - SOFTNET_UNLOCK(); return; out: @@ -860,17 +838,11 @@ void ip_slowtimo(void) { -#ifndef NET_MPSAFE - mutex_enter(softnet_lock); - KERNEL_LOCK(1, NULL); -#endif + SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE(); ip_reass_slowtimo(); -#ifndef NET_MPSAFE - KERNEL_UNLOCK_ONE(NULL); - mutex_exit(softnet_lock); -#endif + SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); } /* @@ -1525,46 +1497,39 @@ ip_savecontrol(struct inpcb *inp, struct struct mbuf *m) { struct socket *so = inp->inp_socket; - ifnet_t *ifp; int inpflags = inp->inp_flags; - struct psref psref; - ifp = m_get_rcvif_psref(m, &psref); - if (__predict_false(ifp == NULL)) - return; /* XXX should report error? */ + if (SOOPT_TIMESTAMP(so->so_options)) + mp = sbsavetimestamp(so->so_options, m, mp); - if (so->so_options & SO_TIMESTAMP -#ifdef SO_OTIMESTAMP - || so->so_options & SO_OTIMESTAMP -#endif - ) { - struct timeval tv; - - microtime(&tv); -#ifdef SO_OTIMESTAMP - if (so->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 (inpflags & INP_RECVDSTADDR) { + *mp = sbcreatecontrol(&ip->ip_dst, + sizeof(struct in_addr), IP_RECVDSTADDR, IPPROTO_IP); if (*mp) mp = &(*mp)->m_next; } - if (inpflags & INP_RECVDSTADDR) { - *mp = sbcreatecontrol((void *) &ip->ip_dst, - sizeof(struct in_addr), IP_RECVDSTADDR, IPPROTO_IP); + + if (inpflags & INP_RECVTTL) { + *mp = sbcreatecontrol(&ip->ip_ttl, + sizeof(uint8_t), IP_RECVTTL, IPPROTO_IP); if (*mp) mp = &(*mp)->m_next; } + + struct psref psref; + ifnet_t *ifp = m_get_rcvif_psref(m, &psref); + if (__predict_false(ifp == NULL)) { +#ifdef DIAGNOSTIC + printf("%s: missing receive interface\n", __func__); +#endif + return; /* XXX should report error? */ + } + if (inpflags & INP_RECVPKTINFO) { struct in_pktinfo ipi; ipi.ipi_addr = ip->ip_src; ipi.ipi_ifindex = ifp->if_index; - *mp = sbcreatecontrol((void *) &ipi, + *mp = sbcreatecontrol(&ipi, sizeof(ipi), IP_RECVPKTINFO, IPPROTO_IP); if (*mp) mp = &(*mp)->m_next; @@ -1573,7 +1538,7 @@ ip_savecontrol(struct inpcb *inp, struct struct in_pktinfo ipi; ipi.ipi_addr = ip->ip_dst; ipi.ipi_ifindex = ifp->if_index; - *mp = sbcreatecontrol((void *) &ipi, + *mp = sbcreatecontrol(&ipi, sizeof(ipi), IP_PKTINFO, IPPROTO_IP); if (*mp) mp = &(*mp)->m_next; @@ -1587,12 +1552,6 @@ ip_savecontrol(struct inpcb *inp, struct if (*mp) mp = &(*mp)->m_next; } - if (inpflags & INP_RECVTTL) { - *mp = sbcreatecontrol((void *) &ip->ip_ttl, - sizeof(uint8_t), IP_RECVTTL, IPPROTO_IP); - if (*mp) - mp = &(*mp)->m_next; - } m_put_rcvif_psref(ifp, &psref); }