Module Name: src Committed By: ozaki-r Date: Thu Apr 20 08:45:09 UTC 2017
Modified Files: src/sys/netinet: in_pcb.c udp_usrreq.c src/sys/netinet6: in6_pcb.c udp6_usrreq.c Log Message: Simplify logic of udp4_sendup and udp6_sendup They are always passed a socket with the same protocol faimiliy as its own: AF_INET for udp4_sendup and AF_INET6 for udp6_sendup. To generate a diff of this commit: cvs rdiff -u -r1.176 -r1.177 src/sys/netinet/in_pcb.c cvs rdiff -u -r1.231 -r1.232 src/sys/netinet/udp_usrreq.c cvs rdiff -u -r1.159 -r1.160 src/sys/netinet6/in6_pcb.c cvs rdiff -u -r1.127 -r1.128 src/sys/netinet6/udp6_usrreq.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/netinet/in_pcb.c diff -u src/sys/netinet/in_pcb.c:1.176 src/sys/netinet/in_pcb.c:1.177 --- src/sys/netinet/in_pcb.c:1.176 Thu Mar 2 05:29:31 2017 +++ src/sys/netinet/in_pcb.c Thu Apr 20 08:45:09 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: in_pcb.c,v 1.176 2017/03/02 05:29:31 ozaki-r Exp $ */ +/* $NetBSD: in_pcb.c,v 1.177 2017/04/20 08:45:09 ozaki-r Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -93,7 +93,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: in_pcb.c,v 1.176 2017/03/02 05:29:31 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: in_pcb.c,v 1.177 2017/04/20 08:45:09 ozaki-r Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -192,6 +192,8 @@ in_pcballoc(struct socket *so, void *v) struct inpcb *inp; int s; + KASSERT(so->so_proto->pr_domain->dom_family == AF_INET); + inp = pool_get(&inpcb_pool, PR_NOWAIT); if (inp == NULL) return (ENOBUFS); Index: src/sys/netinet/udp_usrreq.c diff -u src/sys/netinet/udp_usrreq.c:1.231 src/sys/netinet/udp_usrreq.c:1.232 --- src/sys/netinet/udp_usrreq.c:1.231 Fri Mar 3 07:13:06 2017 +++ src/sys/netinet/udp_usrreq.c Thu Apr 20 08:45:09 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: udp_usrreq.c,v 1.231 2017/03/03 07:13:06 ozaki-r Exp $ */ +/* $NetBSD: udp_usrreq.c,v 1.232 2017/04/20 08:45:09 ozaki-r Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -66,7 +66,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.231 2017/03/03 07:13:06 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.232 2017/04/20 08:45:09 ozaki-r Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -468,21 +468,13 @@ udp4_sendup(struct mbuf *m, int off /* o { struct mbuf *opts = NULL; struct mbuf *n; - struct inpcb *inp = NULL; + struct inpcb *inp; if (!so) return; - switch (so->so_proto->pr_domain->dom_family) { - case AF_INET: - inp = sotoinpcb(so); - break; -#ifdef INET6 - case AF_INET6: - break; -#endif - default: - return; - } + KASSERT(so->so_proto->pr_domain->dom_family == AF_INET); + inp = sotoinpcb(so); + KASSERT(inp != NULL); #if defined(IPSEC) /* check AH/ESP integrity. */ @@ -496,11 +488,11 @@ udp4_sendup(struct mbuf *m, int off /* o #endif /*IPSEC*/ if ((n = m_copypacket(m, M_DONTWAIT)) != NULL) { - if (inp && (inp->inp_flags & INP_CONTROLOPTS + if (inp->inp_flags & INP_CONTROLOPTS #ifdef SO_OTIMESTAMP || so->so_options & SO_OTIMESTAMP #endif - || so->so_options & SO_TIMESTAMP)) { + || so->so_options & SO_TIMESTAMP) { struct ip *ip = mtod(n, struct ip *); ip_savecontrol(inp, &opts, ip, n); } Index: src/sys/netinet6/in6_pcb.c diff -u src/sys/netinet6/in6_pcb.c:1.159 src/sys/netinet6/in6_pcb.c:1.160 --- src/sys/netinet6/in6_pcb.c:1.159 Thu Mar 2 05:26:24 2017 +++ src/sys/netinet6/in6_pcb.c Thu Apr 20 08:45:09 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: in6_pcb.c,v 1.159 2017/03/02 05:26:24 ozaki-r Exp $ */ +/* $NetBSD: in6_pcb.c,v 1.160 2017/04/20 08:45:09 ozaki-r Exp $ */ /* $KAME: in6_pcb.c,v 1.84 2001/02/08 18:02:08 itojun Exp $ */ /* @@ -62,7 +62,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: in6_pcb.c,v 1.159 2017/03/02 05:26:24 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: in6_pcb.c,v 1.160 2017/04/20 08:45:09 ozaki-r Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -158,6 +158,8 @@ in6_pcballoc(struct socket *so, void *v) struct in6pcb *in6p; int s; + KASSERT(so->so_proto->pr_domain->dom_family == AF_INET6); + in6p = pool_get(&in6pcb_pool, PR_NOWAIT); if (in6p == NULL) return (ENOBUFS); Index: src/sys/netinet6/udp6_usrreq.c diff -u src/sys/netinet6/udp6_usrreq.c:1.127 src/sys/netinet6/udp6_usrreq.c:1.128 --- src/sys/netinet6/udp6_usrreq.c:1.127 Tue Jan 24 07:09:25 2017 +++ src/sys/netinet6/udp6_usrreq.c Thu Apr 20 08:45:09 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: udp6_usrreq.c,v 1.127 2017/01/24 07:09:25 ozaki-r Exp $ */ +/* $NetBSD: udp6_usrreq.c,v 1.128 2017/04/20 08:45:09 ozaki-r Exp $ */ /* $KAME: udp6_usrreq.c,v 1.86 2001/05/27 17:33:00 itojun Exp $ */ /* @@ -62,7 +62,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: udp6_usrreq.c,v 1.127 2017/01/24 07:09:25 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: udp6_usrreq.c,v 1.128 2017/04/20 08:45:09 ozaki-r Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -343,17 +343,16 @@ udp6_sendup(struct mbuf *m, int off /* o { struct mbuf *opts = NULL; struct mbuf *n; - struct in6pcb *in6p = NULL; + struct in6pcb *in6p; - if (!so) - return; - if (so->so_proto->pr_domain->dom_family != AF_INET6) - return; + KASSERT(so != NULL); + KASSERT(so->so_proto->pr_domain->dom_family == AF_INET6); in6p = sotoin6pcb(so); + KASSERT(in6p != NULL); #if defined(IPSEC) /* check AH/ESP integrity. */ - if (ipsec_used && so != NULL && ipsec6_in_reject_so(m, so)) { + if (ipsec_used && ipsec6_in_reject_so(m, so)) { IPSEC6_STATINC(IPSEC_STAT_IN_POLVIO); if ((n = m_copypacket(m, M_DONTWAIT)) != NULL) icmp6_error(n, ICMP6_DST_UNREACH, @@ -363,11 +362,11 @@ udp6_sendup(struct mbuf *m, int off /* o #endif /*IPSEC*/ if ((n = m_copypacket(m, M_DONTWAIT)) != NULL) { - if (in6p && (in6p->in6p_flags & IN6P_CONTROLOPTS + if (in6p->in6p_flags & IN6P_CONTROLOPTS #ifdef SO_OTIMESTAMP || in6p->in6p_socket->so_options & SO_OTIMESTAMP #endif - || in6p->in6p_socket->so_options & SO_TIMESTAMP)) { + || in6p->in6p_socket->so_options & SO_TIMESTAMP) { struct ip6_hdr *ip6 = mtod(n, struct ip6_hdr *); ip6_savecontrol(in6p, &opts, ip6, n); }