Source-Changes-HG archive

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

[src/trunk]: src/sys/netinet6 Dedup: introduce rip6_sbappendaddr...



details:   https://anonhg.NetBSD.org/src/rev/deef78897f41
branches:  trunk
changeset: 318980:deef78897f41
user:      maxv <maxv%NetBSD.org@localhost>
date:      Fri May 11 14:25:50 2018 +0000
description:
Dedup: introduce rip6_sbappendaddr. Same as IPv4.

diffstat:

 sys/netinet6/raw_ip6.c |  61 +++++++++++++++++++++++--------------------------
 1 files changed, 29 insertions(+), 32 deletions(-)

diffs (103 lines):

diff -r 6b96a0ddbc81 -r deef78897f41 sys/netinet6/raw_ip6.c
--- a/sys/netinet6/raw_ip6.c    Fri May 11 14:07:58 2018 +0000
+++ b/sys/netinet6/raw_ip6.c    Fri May 11 14:25:50 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: raw_ip6.c,v 1.171 2018/04/29 07:05:13 maxv Exp $       */
+/*     $NetBSD: raw_ip6.c,v 1.172 2018/05/11 14:25:50 maxv Exp $       */
 /*     $KAME: raw_ip6.c,v 1.82 2001/07/23 18:57:56 jinmei Exp $        */
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: raw_ip6.c,v 1.171 2018/04/29 07:05:13 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: raw_ip6.c,v 1.172 2018/05/11 14:25:50 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ipsec.h"
@@ -134,6 +134,28 @@
        rip6stat_percpu = percpu_alloc(sizeof(uint64_t) * RIP6_NSTATS);
 }
 
+static void
+rip6_sbappendaddr(struct in6pcb *last, struct ip6_hdr *ip6,
+    const struct sockaddr *sa, int hlen, struct mbuf *n)
+{
+       struct mbuf *opts = NULL;
+
+       if (last->in6p_flags & IN6P_CONTROLOPTS)
+               ip6_savecontrol(last, &opts, ip6, n);
+
+       m_adj(n, hlen);
+
+       if (sbappendaddr(&last->in6p_socket->so_rcv, sa, n, opts) == 0) {
+               soroverflow(last->in6p_socket);
+               m_freem(n);
+               if (opts)
+                       m_freem(opts);
+               RIP6_STATINC(RIP6_STAT_FULLSOCK);
+       } else {
+               sorwakeup(last->in6p_socket);
+       }
+}
+
 /*
  * Setup generic address and protocol structures
  * for raw_input routine, then pass them along with
@@ -148,7 +170,7 @@
        struct in6pcb *in6p;
        struct in6pcb *last = NULL;
        struct sockaddr_in6 rip6src;
-       struct mbuf *n, *opts = NULL;
+       struct mbuf *n;
 
        RIP6_STATINC(RIP6_STAT_IPACKETS);
 
@@ -198,21 +220,8 @@
                }
 #endif
                else if ((n = m_copypacket(m, M_DONTWAIT)) != NULL) {
-                       if (last->in6p_flags & IN6P_CONTROLOPTS)
-                               ip6_savecontrol(last, &opts, ip6, n);
-                       /* strip intermediate headers */
-                       m_adj(n, *offp);
-                       if (sbappendaddr(&last->in6p_socket->so_rcv,
-                           sin6tosa(&rip6src), n, opts) == 0) {
-                               soroverflow(last->in6p_socket);
-                               m_freem(n);
-                               if (opts)
-                                       m_freem(opts);
-                               RIP6_STATINC(RIP6_STAT_FULLSOCK);
-                       } else {
-                               sorwakeup(last->in6p_socket);
-                       }
-                       opts = NULL;
+                       rip6_sbappendaddr(last, ip6, sin6tosa(&rip6src),
+                           *offp, n);
                }
 
                last = in6p;
@@ -225,20 +234,8 @@
                /* do not inject data into pcb */
        } else
 #endif
-       if (last) {
-               if (last->in6p_flags & IN6P_CONTROLOPTS)
-                       ip6_savecontrol(last, &opts, ip6, m);
-               /* strip intermediate headers */
-               m_adj(m, *offp);
-               if (sbappendaddr(&last->in6p_socket->so_rcv,
-                   sin6tosa(&rip6src), m, opts) == 0) {
-                       soroverflow(last->in6p_socket);
-                       m_freem(m);
-                       if (opts)
-                               m_freem(opts);
-                       RIP6_STATINC(RIP6_STAT_FULLSOCK);
-               } else
-                       sorwakeup(last->in6p_socket);
+       if (last != NULL) {
+               rip6_sbappendaddr(last, ip6, sin6tosa(&rip6src), *offp, m);
        } else {
                RIP6_STATINC(RIP6_STAT_NOSOCK);
                if (m->m_flags & M_MCAST)



Home | Main Index | Thread Index | Old Index