Source-Changes-HG archive

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

[src/trunk]: src/sys/net wg: Sprinkle #ifdef INET6. Avoid unconditional use ...



details:   https://anonhg.NetBSD.org/src/rev/13c9acdd80cb
branches:  trunk
changeset: 945962:13c9acdd80cb
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Wed Nov 11 18:08:34 2020 +0000

description:
wg: Sprinkle #ifdef INET6.  Avoid unconditional use of ip6 structs.

Fixes no-INET6 build.

Based on patch from Brad Spencer:

https://mail-index.NetBSD.org/current-users/2020/11/11/msg039883.html

diffstat:

 sys/net/if_wg.c |  40 ++++++++++++++++++++++++++++++++--------
 1 files changed, 32 insertions(+), 8 deletions(-)

diffs (95 lines):

diff -r 7d8f405f3084 -r 13c9acdd80cb sys/net/if_wg.c
--- a/sys/net/if_wg.c   Wed Nov 11 17:11:19 2020 +0000
+++ b/sys/net/if_wg.c   Wed Nov 11 18:08:34 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_wg.c,v 1.61 2020/10/15 10:09:49 roy Exp $   */
+/*     $NetBSD: if_wg.c,v 1.62 2020/11/11 18:08:34 riastradh Exp $     */
 
 /*
  * Copyright (C) Ryota Ozaki <ozaki.ryota%gmail.com@localhost>
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.61 2020/10/15 10:09:49 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.62 2020/11/11 18:08:34 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_altq_enabled.h"
@@ -1611,7 +1611,18 @@
 wg_get_so_by_af(struct wg_softc *wg, const int af)
 {
 
-       return (af == AF_INET) ? wg->wg_so4 : wg->wg_so6;
+       switch (af) {
+#ifdef INET
+       case AF_INET:
+               return wg->wg_so4;
+#endif
+#ifdef INET6
+       case AF_INET6:
+               return wg->wg_so6;
+#endif
+       default:
+               panic("wg: no such af: %d", af);
+       }
 }
 
 static struct socket *
@@ -2349,9 +2360,14 @@
 
        WG_DLOG("af=%d\n", *af);
 
-       if (*af == AF_INET) {
+       switch (*af) {
+#ifdef INET
+       case AF_INET:
                packet_len = ntohs(ip->ip_len);
-       } else {
+               break;
+#endif
+#ifdef INET6
+       case AF_INET6: {
                const struct ip6_hdr *ip6;
 
                if (__predict_false(decrypted_len < sizeof(struct ip6_hdr)))
@@ -2359,6 +2375,11 @@
 
                ip6 = (const struct ip6_hdr *)packet;
                packet_len = sizeof(struct ip6_hdr) + ntohs(ip6->ip6_plen);
+               break;
+       }
+#endif
+       default:
+               return false;
        }
 
        WG_DLOG("packet_len=%u\n", packet_len);
@@ -2432,12 +2453,16 @@
                return false;
 
        switch (sa1->sa_family) {
+#ifdef INET
        case AF_INET:
                return satocsin(sa1)->sin_port == satocsin(sa2)->sin_port;
+#endif
+#ifdef INET6
        case AF_INET6:
                return satocsin6(sa1)->sin6_port == satocsin6(sa2)->sin6_port;
+#endif
        default:
-               return true;
+               return false;
        }
 }
 
@@ -3938,8 +3963,7 @@
        struct wg_msg_data *wgmd;
        bool free_padded_buf = false;
        struct mbuf *n;
-       size_t leading_len = max_linkhdr + sizeof(struct ip6_hdr) +
-           sizeof(struct udphdr);
+       size_t leading_len = max_hdr + sizeof(struct udphdr);
 
        mlen = m_length(m);
        inner_len = mlen;



Home | Main Index | Thread Index | Old Index