Module Name:    src
Committed By:   riastradh
Date:           Wed Nov 11 18:08:35 UTC 2020

Modified Files:
        src/sys/net: if_wg.c

Log Message:
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


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/sys/net/if_wg.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/net/if_wg.c
diff -u src/sys/net/if_wg.c:1.61 src/sys/net/if_wg.c:1.62
--- src/sys/net/if_wg.c:1.61	Thu Oct 15 10:09:49 2020
+++ src/sys/net/if_wg.c	Wed Nov 11 18:08:34 2020
@@ -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.ry...@gmail.com>
@@ -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 @@ static struct socket *
 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_validate_inner_packet(const char *pac
 
 	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 @@ wg_validate_inner_packet(const char *pac
 
 		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 @@ sockaddr_port_match(const struct sockadd
 		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 @@ wg_send_data_msg(struct wg_peer *wgp, st
 	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;

Reply via email to