diff options
-rw-r--r-- | src/compat.h | 2 | ||||
-rw-r--r-- | src/config.c | 13 | ||||
-rw-r--r-- | src/device.c | 2 | ||||
-rw-r--r-- | src/peer.c | 2 | ||||
-rw-r--r-- | src/peer.h | 2 | ||||
-rw-r--r-- | src/receive.c | 14 | ||||
-rw-r--r-- | src/send.c | 6 | ||||
-rw-r--r-- | src/socket.c | 20 | ||||
-rw-r--r-- | src/timers.c | 6 |
9 files changed, 37 insertions, 30 deletions
diff --git a/src/compat.h b/src/compat.h index c286fec..5efb4e4 100644 --- a/src/compat.h +++ b/src/compat.h @@ -168,7 +168,7 @@ static inline struct net_device *netdev_pub(void *dev) #define net_dbg_skb_ratelimited(fmt, skb, ...) do { \ struct endpoint __endpoint; \ socket_endpoint_from_skb(&__endpoint, skb); \ - net_dbg_ratelimited(fmt, &__endpoint.addr_storage, ##__VA_ARGS__); \ + net_dbg_ratelimited(fmt, &__endpoint.addr, ##__VA_ARGS__); \ } while(0) #else #define net_dbg_skb_ratelimited(fmt, skb, ...) diff --git a/src/config.c b/src/config.c index b65e498..197c162 100644 --- a/src/config.c +++ b/src/config.c @@ -76,7 +76,7 @@ static int set_peer(struct wireguard_device *wg, void __user *user_peer, size_t if (netdev_pub(wg)->flags & IFF_UP) timers_init_peer(peer); } else - pr_debug("Peer %Lu (%pISpfsc) modified\n", peer->internal_id, &peer->endpoint.addr_storage); + pr_debug("Peer %Lu (%pISpfsc) modified\n", peer->internal_id, &peer->endpoint.addr); if (in_peer.remove_me) { peer_put(peer); @@ -85,7 +85,11 @@ static int set_peer(struct wireguard_device *wg, void __user *user_peer, size_t } if (in_peer.endpoint.ss_family == AF_INET || in_peer.endpoint.ss_family == AF_INET6) { - struct endpoint endpoint = { .addr_storage = in_peer.endpoint }; + struct endpoint endpoint = { 0 }; + if (in_peer.endpoint.ss_family == AF_INET) + endpoint.addr4 = *(struct sockaddr_in *)&in_peer.endpoint; + else if (in_peer.endpoint.ss_family == AF_INET6) + endpoint.addr6 = *(struct sockaddr_in6 *)&in_peer.endpoint; socket_set_peer_endpoint(peer, &endpoint); } @@ -237,7 +241,10 @@ static int populate_peer(struct wireguard_peer *peer, void *ctx) memcpy(out_peer.public_key, peer->handshake.remote_static, NOISE_PUBLIC_KEY_LEN); read_lock_bh(&peer->endpoint_lock); - out_peer.endpoint = peer->endpoint.addr_storage; + if (peer->endpoint.addr.sa_family == AF_INET) + *(struct sockaddr_in *)&out_peer.endpoint = peer->endpoint.addr4; + else if (peer->endpoint.addr.sa_family == AF_INET6) + *(struct sockaddr_in6 *)&out_peer.endpoint = peer->endpoint.addr6; read_unlock_bh(&peer->endpoint_lock); out_peer.last_handshake_time = peer->walltime_last_handshake; out_peer.tx_bytes = peer->tx_bytes; diff --git a/src/device.c b/src/device.c index 68e74b9..0c9434a 100644 --- a/src/device.c +++ b/src/device.c @@ -135,7 +135,7 @@ static netdev_tx_t xmit(struct sk_buff *skb, struct net_device *dev) } read_lock_bh(&peer->endpoint_lock); - ret = peer->endpoint.addr_storage.ss_family != AF_INET && peer->endpoint.addr_storage.ss_family != AF_INET6; + ret = peer->endpoint.addr.sa_family != AF_INET && peer->endpoint.addr.sa_family != AF_INET6; read_unlock_bh(&peer->endpoint_lock); if (unlikely(ret)) { ret = -EHOSTUNREACH; @@ -85,7 +85,7 @@ void peer_remove(struct wireguard_peer *peer) static void rcu_release(struct rcu_head *rcu) { struct wireguard_peer *peer = container_of(rcu, struct wireguard_peer, rcu); - pr_debug("Peer %Lu (%pISpfsc) destroyed\n", peer->internal_id, &peer->endpoint.addr_storage); + pr_debug("Peer %Lu (%pISpfsc) destroyed\n", peer->internal_id, &peer->endpoint.addr); skb_queue_purge(&peer->tx_packet_queue); dst_cache_destroy(&peer->endpoint_cache); kzfree(peer); @@ -18,7 +18,7 @@ struct wireguard_device; struct endpoint { union { - struct sockaddr_storage addr_storage; + struct sockaddr addr; struct sockaddr_in addr4; struct sockaddr_in6 addr6; }; diff --git a/src/receive.c b/src/receive.c index 2ee4f36..2120cca 100644 --- a/src/receive.c +++ b/src/receive.c @@ -110,7 +110,7 @@ static void receive_handshake_packet(struct wireguard_device *wg, void *data, si return; } update_latest_addr(peer, skb); - net_dbg_ratelimited("Receiving handshake initiation from peer %Lu (%pISpfsc)\n", peer->internal_id, &peer->endpoint.addr_storage); + net_dbg_ratelimited("Receiving handshake initiation from peer %Lu (%pISpfsc)\n", peer->internal_id, &peer->endpoint.addr); packet_send_handshake_response(peer); break; case MESSAGE_HANDSHAKE_RESPONSE: @@ -125,7 +125,7 @@ static void receive_handshake_packet(struct wireguard_device *wg, void *data, si return; } update_latest_addr(peer, skb); - net_dbg_ratelimited("Receiving handshake response from peer %Lu (%pISpfsc)\n", peer->internal_id, &peer->endpoint.addr_storage); + net_dbg_ratelimited("Receiving handshake response from peer %Lu (%pISpfsc)\n", peer->internal_id, &peer->endpoint.addr); if (noise_handshake_begin_session(&peer->handshake, &peer->keypairs, true)) { timers_ephemeral_key_created(peer); timers_handshake_complete(peer); @@ -218,14 +218,14 @@ static void receive_data_packet(struct sk_buff *skb, struct wireguard_peer *peer /* A packet with length 0 is a keepalive packet */ if (unlikely(!skb->len)) { - net_dbg_ratelimited("Receiving keepalive packet from peer %Lu (%pISpfsc)\n", peer->internal_id, &peer->endpoint.addr_storage); + net_dbg_ratelimited("Receiving keepalive packet from peer %Lu (%pISpfsc)\n", peer->internal_id, &peer->endpoint.addr); goto packet_processed; } if (!pskb_may_pull(skb, 1 /* For checking the ip version below */)) { ++dev->stats.rx_errors; ++dev->stats.rx_length_errors; - net_dbg_ratelimited("Packet missing IP version from peer %Lu (%pISpfsc)\n", peer->internal_id, &peer->endpoint.addr_storage); + net_dbg_ratelimited("Packet missing IP version from peer %Lu (%pISpfsc)\n", peer->internal_id, &peer->endpoint.addr); goto packet_processed; } @@ -242,7 +242,7 @@ static void receive_data_packet(struct sk_buff *skb, struct wireguard_peer *peer } else { ++dev->stats.rx_errors; ++dev->stats.rx_length_errors; - net_dbg_ratelimited("Packet neither ipv4 nor ipv6 from peer %Lu (%pISpfsc)\n", peer->internal_id, &peer->endpoint.addr_storage); + net_dbg_ratelimited("Packet neither ipv4 nor ipv6 from peer %Lu (%pISpfsc)\n", peer->internal_id, &peer->endpoint.addr); goto packet_processed; } @@ -254,7 +254,7 @@ static void receive_data_packet(struct sk_buff *skb, struct wireguard_peer *peer if (unlikely(routed_peer != peer)) { ++dev->stats.rx_errors; ++dev->stats.rx_frame_errors; - net_dbg_skb_ratelimited("Packet has unallowed src IP (%pISc) from peer %Lu (%pISpfsc)\n", skb, peer->internal_id, &peer->endpoint.addr_storage); + net_dbg_skb_ratelimited("Packet has unallowed src IP (%pISc) from peer %Lu (%pISpfsc)\n", skb, peer->internal_id, &peer->endpoint.addr); goto packet_processed; } @@ -263,7 +263,7 @@ static void receive_data_packet(struct sk_buff *skb, struct wireguard_peer *peer rx_stats(peer, skb->len); else { ++dev->stats.rx_dropped; - net_dbg_ratelimited("Failed to give packet to userspace from peer %Lu (%pISpfsc)\n", peer->internal_id, &peer->endpoint.addr_storage); + net_dbg_ratelimited("Failed to give packet to userspace from peer %Lu (%pISpfsc)\n", peer->internal_id, &peer->endpoint.addr); } goto continue_processing; @@ -27,7 +27,7 @@ static void packet_send_handshake_initiation(struct wireguard_peer *peer) peer->last_sent_handshake = get_jiffies_64(); up_write(&peer->handshake.lock); - net_dbg_ratelimited("Sending handshake initiation to peer %Lu (%pISpfsc)\n", peer->internal_id, &peer->endpoint.addr_storage); + net_dbg_ratelimited("Sending handshake initiation to peer %Lu (%pISpfsc)\n", peer->internal_id, &peer->endpoint.addr); if (noise_handshake_create_initiation(&packet, &peer->handshake)) { cookie_add_mac_to_packet(&packet, sizeof(packet), peer); @@ -64,7 +64,7 @@ void packet_send_handshake_response(struct wireguard_peer *peer) { struct message_handshake_response packet; - net_dbg_ratelimited("Sending handshake response to peer %Lu (%pISpfsc)\n", peer->internal_id, &peer->endpoint.addr_storage); + net_dbg_ratelimited("Sending handshake response to peer %Lu (%pISpfsc)\n", peer->internal_id, &peer->endpoint.addr); peer->last_sent_handshake = get_jiffies_64(); if (noise_handshake_create_response(&packet, &peer->handshake)) { @@ -113,7 +113,7 @@ void packet_send_keepalive(struct wireguard_peer *peer) skb_reserve(skb, DATA_PACKET_HEAD_ROOM); skb->dev = netdev_pub(peer->device); skb_queue_tail(&peer->tx_packet_queue, skb); - net_dbg_ratelimited("Sending keepalive packet to peer %Lu (%pISpfsc)\n", peer->internal_id, &peer->endpoint.addr_storage); + net_dbg_ratelimited("Sending keepalive packet to peer %Lu (%pISpfsc)\n", peer->internal_id, &peer->endpoint.addr); } packet_send_queue(peer); } diff --git a/src/socket.c b/src/socket.c index 01df365..7eae766 100644 --- a/src/socket.c +++ b/src/socket.c @@ -51,12 +51,12 @@ static inline int send4(struct wireguard_device *wg, struct sk_buff *skb, struct } if (unlikely(IS_ERR(rt))) { ret = PTR_ERR(rt); - net_dbg_ratelimited("No route to %pISpfsc, error %d\n", &endpoint->addr_storage, ret); + net_dbg_ratelimited("No route to %pISpfsc, error %d\n", &endpoint->addr, ret); goto err; } else if (unlikely(rt->dst.dev == skb->dev)) { dst_release(&rt->dst); ret = -ELOOP; - net_dbg_ratelimited("Avoiding routing loop to %pISpfsc\n", &endpoint->addr_storage); + net_dbg_ratelimited("Avoiding routing loop to %pISpfsc\n", &endpoint->addr); goto err; } if (cache) @@ -116,12 +116,12 @@ static inline int send6(struct wireguard_device *wg, struct sk_buff *skb, struct } ret = ipv6_stub->ipv6_dst_lookup(sock_net(sock), sock, &dst, &fl); if (unlikely(ret)) { - net_dbg_ratelimited("No route to %pISpfsc, error %d\n", &endpoint->addr_storage, ret); + net_dbg_ratelimited("No route to %pISpfsc, error %d\n", &endpoint->addr, ret); goto err; } else if (unlikely(dst->dev == skb->dev)) { dst_release(dst); ret = -ELOOP; - net_dbg_ratelimited("Avoiding routing loop to %pISpfsc\n", &endpoint->addr_storage); + net_dbg_ratelimited("Avoiding routing loop to %pISpfsc\n", &endpoint->addr); goto err; } if (cache) @@ -151,9 +151,9 @@ int socket_send_skb_to_peer(struct wireguard_peer *peer, struct sk_buff *skb, u8 int ret = -EAFNOSUPPORT; read_lock_bh(&peer->endpoint_lock); - if (peer->endpoint.addr_storage.ss_family == AF_INET) + if (peer->endpoint.addr.sa_family == AF_INET) ret = send4(peer->device, skb, &peer->endpoint, ds, &peer->endpoint_cache); - else if (peer->endpoint.addr_storage.ss_family == AF_INET6) + else if (peer->endpoint.addr.sa_family == AF_INET6) ret = send6(peer->device, skb, &peer->endpoint, ds, &peer->endpoint_cache); if (likely(!ret)) peer->tx_bytes += skb_len; @@ -190,9 +190,9 @@ int socket_send_buffer_as_reply_to_skb(struct wireguard_device *wg, struct sk_bu skb_reserve(skb, SKB_HEADER_LEN); memcpy(skb_put(skb, len), out_buffer, len); - if (endpoint.addr_storage.ss_family == AF_INET) + if (endpoint.addr.sa_family == AF_INET) ret = send4(wg, skb, &endpoint, 0, NULL); - else if (endpoint.addr_storage.ss_family == AF_INET6) + else if (endpoint.addr.sa_family == AF_INET6) ret = send6(wg, skb, &endpoint, 0, NULL); else ret = -EAFNOSUPPORT; @@ -222,7 +222,7 @@ int socket_endpoint_from_skb(struct endpoint *endpoint, struct sk_buff *skb) void socket_set_peer_endpoint(struct wireguard_peer *peer, struct endpoint *endpoint) { - if (endpoint->addr_storage.ss_family == AF_INET) { + if (endpoint->addr.sa_family == AF_INET) { read_lock_bh(&peer->endpoint_lock); if (likely(peer->endpoint.addr4.sin_family == AF_INET && peer->endpoint.addr4.sin_port == endpoint->addr4.sin_port && @@ -233,7 +233,7 @@ void socket_set_peer_endpoint(struct wireguard_peer *peer, struct endpoint *endp write_lock_bh(&peer->endpoint_lock); peer->endpoint.addr4 = endpoint->addr4; peer->endpoint.src4 = endpoint->src4; - } else if (endpoint->addr_storage.ss_family == AF_INET6) { + } else if (endpoint->addr.sa_family == AF_INET6) { read_lock_bh(&peer->endpoint_lock); if (likely(peer->endpoint.addr6.sin6_family == AF_INET6 && peer->endpoint.addr6.sin6_port == endpoint->addr6.sin6_port && diff --git a/src/timers.c b/src/timers.c index a11eb90..0abdbdb 100644 --- a/src/timers.c +++ b/src/timers.c @@ -27,7 +27,7 @@ static inline unsigned long slack_time(unsigned long time) static void expired_retransmit_handshake(unsigned long ptr) { peer_get_from_ptr(ptr); - pr_debug("Handshake for peer %Lu (%pISpfsc) did not complete after %d seconds, retrying\n", peer->internal_id, &peer->endpoint.addr_storage, REKEY_TIMEOUT / HZ); + pr_debug("Handshake for peer %Lu (%pISpfsc) did not complete after %d seconds, retrying\n", peer->internal_id, &peer->endpoint.addr, REKEY_TIMEOUT / HZ); if (peer->timer_handshake_attempts > MAX_TIMER_HANDSHAKES) { del_timer(&peer->timer_send_keepalive); /* We remove all existing packets and don't try again, @@ -63,7 +63,7 @@ static void expired_send_keepalive(unsigned long ptr) static void expired_new_handshake(unsigned long ptr) { peer_get_from_ptr(ptr); - pr_debug("Retrying handshake with peer %Lu (%pISpfsc) because we stopped hearing back after %d seconds\n", peer->internal_id, &peer->endpoint.addr_storage, (KEEPALIVE_TIMEOUT + REKEY_TIMEOUT) / HZ); + pr_debug("Retrying handshake with peer %Lu (%pISpfsc) because we stopped hearing back after %d seconds\n", peer->internal_id, &peer->endpoint.addr, (KEEPALIVE_TIMEOUT + REKEY_TIMEOUT) / HZ); /* We clear the endpoint address src address, in case this is the cause of trouble. */ socket_clear_peer_endpoint_src(peer); packet_queue_handshake_initiation(peer); @@ -79,7 +79,7 @@ static void expired_kill_ephemerals(unsigned long ptr) static void queued_expired_kill_ephemerals(struct work_struct *work) { struct wireguard_peer *peer = container_of(work, struct wireguard_peer, clear_peer_work); - pr_debug("Zeroing out all keys for peer %Lu (%pISpfsc), since we haven't received a new one in %d seconds\n", peer->internal_id, &peer->endpoint.addr_storage, (REJECT_AFTER_TIME * 3) / HZ); + pr_debug("Zeroing out all keys for peer %Lu (%pISpfsc), since we haven't received a new one in %d seconds\n", peer->internal_id, &peer->endpoint.addr, (REJECT_AFTER_TIME * 3) / HZ); noise_handshake_clear(&peer->handshake); noise_keypairs_clear(&peer->keypairs); peer_put(peer); |