Skip to content

Commit ec89ca6

Browse files
committed
socket: ignore v6 endpoints when ipv6 is disabled
The previous commit fixed a memory leak on the send path in the event that IPv6 is disabled at compile time, but how did a packet even arrive there to begin with? It turns out we have previously allowed IPv6 endpoints even when IPv6 support is disabled at compile time. This is awkward and inconsistent. Instead, let's just ignore all things IPv6, the same way we do other malformed endpoints, in the case where IPv6 is disabled. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
1 parent fa32671 commit ec89ca6

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/socket.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ int wg_socket_endpoint_from_skb(struct endpoint *endpoint,
242242
endpoint->addr4.sin_addr.s_addr = ip_hdr(skb)->saddr;
243243
endpoint->src4.s_addr = ip_hdr(skb)->daddr;
244244
endpoint->src_if4 = skb->skb_iif;
245-
} else if (skb->protocol == htons(ETH_P_IPV6)) {
245+
} else if (IS_ENABLED(CONFIG_IPV6) && skb->protocol == htons(ETH_P_IPV6)) {
246246
endpoint->addr6.sin6_family = AF_INET6;
247247
endpoint->addr6.sin6_port = udp_hdr(skb)->source;
248248
endpoint->addr6.sin6_addr = ipv6_hdr(skb)->saddr;
@@ -285,7 +285,7 @@ void wg_socket_set_peer_endpoint(struct wg_peer *peer,
285285
peer->endpoint.addr4 = endpoint->addr4;
286286
peer->endpoint.src4 = endpoint->src4;
287287
peer->endpoint.src_if4 = endpoint->src_if4;
288-
} else if (endpoint->addr.sa_family == AF_INET6) {
288+
} else if (IS_ENABLED(CONFIG_IPV6) && endpoint->addr.sa_family == AF_INET6) {
289289
peer->endpoint.addr6 = endpoint->addr6;
290290
peer->endpoint.src6 = endpoint->src6;
291291
} else {

0 commit comments

Comments
 (0)