Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Simplify logic of udp4_sendup and udp6_sendup



details:   https://anonhg.NetBSD.org/src/rev/612eef219d93
branches:  trunk
changeset: 823348:612eef219d93
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Thu Apr 20 08:45:09 2017 +0000

description:
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.

diffstat:

 sys/netinet/in_pcb.c       |   6 ++++--
 sys/netinet/udp_usrreq.c   |  24 ++++++++----------------
 sys/netinet6/in6_pcb.c     |   6 ++++--
 sys/netinet6/udp6_usrreq.c |  19 +++++++++----------
 4 files changed, 25 insertions(+), 30 deletions(-)

diffs (167 lines):

diff -r 54a112ede701 -r 612eef219d93 sys/netinet/in_pcb.c
--- a/sys/netinet/in_pcb.c      Thu Apr 20 08:34:23 2017 +0000
+++ b/sys/netinet/in_pcb.c      Thu Apr 20 08:45:09 2017 +0000
@@ -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 @@
        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);
diff -r 54a112ede701 -r 612eef219d93 sys/netinet/udp_usrreq.c
--- a/sys/netinet/udp_usrreq.c  Thu Apr 20 08:34:23 2017 +0000
+++ b/sys/netinet/udp_usrreq.c  Thu Apr 20 08:45:09 2017 +0000
@@ -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 @@
 {
        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 @@
 #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);
                }
diff -r 54a112ede701 -r 612eef219d93 sys/netinet6/in6_pcb.c
--- a/sys/netinet6/in6_pcb.c    Thu Apr 20 08:34:23 2017 +0000
+++ b/sys/netinet6/in6_pcb.c    Thu Apr 20 08:45:09 2017 +0000
@@ -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 @@
        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);
diff -r 54a112ede701 -r 612eef219d93 sys/netinet6/udp6_usrreq.c
--- a/sys/netinet6/udp6_usrreq.c        Thu Apr 20 08:34:23 2017 +0000
+++ b/sys/netinet6/udp6_usrreq.c        Thu Apr 20 08:45:09 2017 +0000
@@ -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 @@
 {
        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 @@
 #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);
                }



Home | Main Index | Thread Index | Old Index