Source-Changes-HG archive

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

[src/trunk]: src/sys/net Fix (bridge && !inet6) build.



details:   https://anonhg.NetBSD.org/src/rev/74b8a19a9751
branches:  trunk
changeset: 446658:74b8a19a9751
user:      rin <rin%NetBSD.org@localhost>
date:      Thu Dec 13 12:13:33 2018 +0000

description:
Fix (bridge && !inet6) build.

diffstat:

 sys/net/ether_sw_offload.c |  132 ++++++++++++++++++++++++++------------------
 1 files changed, 78 insertions(+), 54 deletions(-)

diffs (229 lines):

diff -r dd6188bacb3c -r 74b8a19a9751 sys/net/ether_sw_offload.c
--- a/sys/net/ether_sw_offload.c        Thu Dec 13 11:28:00 2018 +0000
+++ b/sys/net/ether_sw_offload.c        Thu Dec 13 12:13:33 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ether_sw_offload.c,v 1.1 2018/12/12 01:40:20 rin Exp $ */
+/*     $NetBSD: ether_sw_offload.c,v 1.2 2018/12/13 12:13:33 rin Exp $ */
 
 /*
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -29,8 +29,12 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#ifdef _KERNEL_OPT
+#include "opt_inet.h"
+#endif
+
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ether_sw_offload.c,v 1.1 2018/12/12 01:40:20 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ether_sw_offload.c,v 1.2 2018/12/13 12:13:33 rin Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -43,12 +47,14 @@
 #include <netinet/in.h>
 #include <netinet/in_offload.h>
 #include <netinet/ip.h>
-#include <netinet/ip6.h>
 #include <netinet/tcp.h>
 #include <netinet/udp.h>
 
+#ifdef INET6
+#include <netinet/ip6.h>
 #include <netinet6/in6.h>
 #include <netinet6/in6_offload.h>
+#endif
 
 /*
  * Handle TX offload in software. For TSO, split the packet into
@@ -62,7 +68,7 @@
 {
        struct ether_header *ep;
        int flags, ehlen;
-       bool v4;
+       bool v6;
 
        KASSERT(m->m_flags & M_PKTHDR);
        flags = m->m_pkthdr.csum_flags;
@@ -93,7 +99,10 @@
        }
        KASSERT(m->m_pkthdr.len >= ehlen);
 
-       v4 = flags & (M_CSUM_TSOv4 | M_CSUM_IPv4 | M_CSUM_TCPv4 | M_CSUM_UDPv4);
+       v6 = flags & (M_CSUM_TSOv6 | M_CSUM_TCPv6 | M_CSUM_UDPv6);
+#ifndef INET6
+       KASSERT(!v6);
+#endif
 
        if (flags & (M_CSUM_TSOv4 | M_CSUM_TSOv6)) {
                /*
@@ -103,16 +112,20 @@
                 *
                 * XXX Do we need some KASSERT's?
                 */
-               if (v4)
+#ifdef INET6
+               if (v6)
+                       return tcp6_segment(m, ehlen);
+               else
+#endif
                        return tcp4_segment(m, ehlen);
-               else
-                       return tcp6_segment(m, ehlen);
        }
 
-       if (v4)
+#ifdef INET6
+       if (v6)
+               in6_undefer_cksum(m, ehlen, flags);
+       else
+#endif
                in_undefer_cksum(m, ehlen, flags);
-       else
-               in6_undefer_cksum(m, ehlen, flags);
 done:
        m->m_pkthdr.csum_flags = 0;
        m->m_nextpkt = NULL;
@@ -134,13 +147,12 @@
 {
        struct ether_header *eh;
        struct ip *ip;
-       struct ip6_hdr *ip6;
        struct tcphdr *th;
        struct udphdr *uh;
        uint16_t sum, osum;
        uint8_t proto;
        int flags, enabled, len, ehlen, iphlen, l4offset;
-       bool v4;
+       bool v6;
 
        flags = 0;
 
@@ -181,9 +193,46 @@
                        return NULL;
        }
        ip = (void *)(mtod(m, char *) + ehlen);
-       v4 = (ip->ip_v == IPVERSION);
+       v6 = (ip->ip_v != IPVERSION);
+
+       if (v6) {
+#ifdef INET6
+               struct ip6_hdr *ip6;
+
+               KASSERT(len >= sizeof(*ip6));
+               if (m->m_len < ehlen + sizeof(*ip6)) {
+                       m = m_pullup(m, ehlen + sizeof(*ip6));
+                       if (m == NULL)
+                               return NULL;
+               }
+               ip6 = (void *)(mtod(m, char *) + ehlen);
+               KASSERT((ip6->ip6_vfc & IPV6_VERSION_MASK) == IPV6_VERSION);
+
+               iphlen = sizeof(*ip6);
+
+               len -= iphlen;
 
-       if (v4) {
+               proto = ip6->ip6_nxt;
+               switch (proto) {
+               case IPPROTO_TCP:
+                       if (!(enabled & M_CSUM_TCPv6))
+                               goto done;
+                       break;
+               case IPPROTO_UDP:
+                       if (!(enabled & M_CSUM_UDPv6))
+                               goto done;
+                       break;
+               default:
+                       /* XXX Extension headers are not supported. */
+                       goto done;
+               }
+
+               sum = in6_cksum_phdr(&ip6->ip6_src, &ip6->ip6_dst, htonl(len),
+                   htonl(proto));
+#else
+               goto done;
+#endif
+       } else {
                if (enabled & M_CSUM_IPv4)
                        flags |= M_CSUM_IPv4;
 
@@ -220,37 +269,6 @@
 
                sum = in_cksum_phdr(ip->ip_src.s_addr, ip->ip_dst.s_addr,
                    htons((uint16_t)len + proto));
-       } else {
-               KASSERT(len >= sizeof(*ip6));
-               if (m->m_len < ehlen + sizeof(*ip6)) {
-                       m = m_pullup(m, ehlen + sizeof(*ip6));
-                       if (m == NULL)
-                               return NULL;
-               }
-               ip6 = (void *)(mtod(m, char *) + ehlen);
-               KASSERT((ip6->ip6_vfc & IPV6_VERSION_MASK) == IPV6_VERSION);
-
-               iphlen = sizeof(*ip6);
-
-               len -= iphlen;
-
-               proto = ip6->ip6_nxt;
-               switch (proto) {
-               case IPPROTO_TCP:
-                       if (!(enabled & M_CSUM_TCPv6))
-                               goto done;
-                       break;
-               case IPPROTO_UDP:
-                       if (!(enabled & M_CSUM_UDPv6))
-                               goto done;
-                       break;
-               default:
-                       /* XXX Extension headers are not supported. */
-                       goto done;
-               }
-
-               sum = in6_cksum_phdr(&ip6->ip6_src, &ip6->ip6_dst, htonl(len),
-                   htonl(proto));
        }
 
        l4offset = ehlen + iphlen;
@@ -265,12 +283,15 @@
                th = (void *)(mtod(m, char *) + l4offset);
                osum = th->th_sum;
                th->th_sum = sum;
-               if (v4) {
+#ifdef INET6
+               if (v6) {
+                       flags |= M_CSUM_TCPv6;
+                       sum = in6_cksum(m, 0, l4offset, len);
+               } else
+#endif
+               {
                        flags |= M_CSUM_TCPv4;
                        sum = in4_cksum(m, 0, l4offset, len);
-               } else {
-                       flags |= M_CSUM_TCPv6;
-                       sum = in6_cksum(m, 0, l4offset, len);
                }
                if (sum != osum)
                        flags |= M_CSUM_TCP_UDP_BAD;
@@ -288,12 +309,15 @@
                if (osum == 0)
                        break;
                uh->uh_sum = sum;
-               if (v4) {
+#ifdef INET6
+               if (v6) {
+                       flags |= M_CSUM_UDPv6;
+                       sum = in6_cksum(m, 0, l4offset, len);
+               } else
+#endif
+               {
                        flags |= M_CSUM_UDPv4;
                        sum = in4_cksum(m, 0, l4offset, len);
-               } else {
-                       flags |= M_CSUM_UDPv6;
-                       sum = in6_cksum(m, 0, l4offset, len);
                }
                if (sum == 0)
                        sum = 0xffff;



Home | Main Index | Thread Index | Old Index