diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cookie.c | 8 | ||||
-rw-r--r-- | src/crypto/include/zinc/blake2s.h | 2 | ||||
-rw-r--r-- | src/crypto/zinc/blake2s/blake2s.c | 2 | ||||
-rw-r--r-- | src/device.c | 5 | ||||
-rw-r--r-- | src/netlink.c | 9 | ||||
-rw-r--r-- | src/noise.c | 5 | ||||
-rw-r--r-- | src/peer.c | 2 | ||||
-rw-r--r-- | src/ratelimiter.c | 4 | ||||
-rw-r--r-- | src/selftest/allowedips.h | 12 | ||||
-rw-r--r-- | src/selftest/ratelimiter.h | 4 | ||||
-rw-r--r-- | src/send.c | 16 | ||||
-rw-r--r-- | src/socket.c | 2 |
12 files changed, 31 insertions, 40 deletions
diff --git a/src/cookie.c b/src/cookie.c index a9f5fda..d073962 100644 --- a/src/cookie.c +++ b/src/cookie.c @@ -68,7 +68,7 @@ void cookie_checker_precompute_peer_keys(struct wireguard_peer *peer) void cookie_init(struct cookie *cookie) { - memset(cookie, 0, sizeof(struct cookie)); + memset(cookie, 0, sizeof(*cookie)); init_rwsem(&cookie->lock); } @@ -120,7 +120,7 @@ enum cookie_mac_state cookie_validate_packet(struct cookie_checker *checker, bool check_cookie) { struct message_macs *macs = (struct message_macs *) - (skb->data + skb->len - sizeof(struct message_macs)); + (skb->data + skb->len - sizeof(*macs)); enum cookie_mac_state ret; u8 computed_mac[COOKIE_LEN]; u8 cookie[COOKIE_LEN]; @@ -156,7 +156,7 @@ void cookie_add_mac_to_packet(void *message, size_t len, struct wireguard_peer *peer) { struct message_macs *macs = (struct message_macs *) - ((u8 *)message + len - sizeof(struct message_macs)); + ((u8 *)message + len - sizeof(*macs)); down_write(&peer->latest_cookie.lock); compute_mac1(macs->mac1, message, len, @@ -181,7 +181,7 @@ void cookie_message_create(struct message_handshake_cookie *dst, struct cookie_checker *checker) { struct message_macs *macs = (struct message_macs *) - ((u8 *)skb->data + skb->len - sizeof(struct message_macs)); + ((u8 *)skb->data + skb->len - sizeof(*macs)); u8 cookie[COOKIE_LEN]; dst->header.type = cpu_to_le32(MESSAGE_HANDSHAKE_COOKIE); diff --git a/src/crypto/include/zinc/blake2s.h b/src/crypto/include/zinc/blake2s.h index 0e50836..5e32d57 100644 --- a/src/crypto/include/zinc/blake2s.h +++ b/src/crypto/include/zinc/blake2s.h @@ -65,7 +65,7 @@ static inline void blake2s_final(struct blake2s_state *state, u8 *out, memzero_explicit(buffer, sizeof(buffer)); } - memzero_explicit(state, sizeof(struct blake2s_state)); + memzero_explicit(state, sizeof(*state)); } static inline void blake2s(u8 *out, const u8 *in, const u8 *key, diff --git a/src/crypto/zinc/blake2s/blake2s.c b/src/crypto/zinc/blake2s/blake2s.c index 76232a3..13765d3 100644 --- a/src/crypto/zinc/blake2s/blake2s.c +++ b/src/crypto/zinc/blake2s/blake2s.c @@ -71,7 +71,7 @@ static inline void blake2s_init_param(struct blake2s_state *state, { int i; - memset(state, 0, sizeof(struct blake2s_state)); + memset(state, 0, sizeof(*state)); for (i = 0; i < 8; ++i) state->h[i] = blake2s_iv[i] ^ le32_to_cpu(param->words[i]); } diff --git a/src/device.c b/src/device.c index 5bdc649..255ad49 100644 --- a/src/device.c +++ b/src/device.c @@ -238,8 +238,7 @@ static void destruct(struct net_device *dev) packet_queue_free(&wg->encrypt_queue, true); rcu_barrier_bh(); /* Wait for all the peers to be actually freed. */ ratelimiter_uninit(); - memzero_explicit(&wg->static_identity, - sizeof(struct noise_static_identity)); + memzero_explicit(&wg->static_identity, sizeof(wg->static_identity)); skb_queue_purge(&wg->incoming_handshakes); free_percpu(dev->tstats); free_percpu(wg->incoming_handshakes_worker); @@ -285,7 +284,7 @@ static void setup(struct net_device *dev) /* We need to keep the dst around in case of icmp replies. */ netif_keep_dst(dev); - memset(wg, 0, sizeof(struct wireguard_device)); + memset(wg, 0, sizeof(*wg)); wg->dev = dev; } diff --git a/src/netlink.c b/src/netlink.c index 63f3794..98848c9 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -122,7 +122,7 @@ static int get_peer(struct wireguard_peer *peer, unsigned int index, goto err; if (nla_put(skb, WGPEER_A_LAST_HANDSHAKE_TIME, - sizeof(struct timespec), + sizeof(peer->walltime_last_handshake), &peer->walltime_last_handshake) || nla_put_u16(skb, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL, peer->persistent_keepalive_interval) || @@ -136,11 +136,11 @@ static int get_peer(struct wireguard_peer *peer, unsigned int index, read_lock_bh(&peer->endpoint_lock); if (peer->endpoint.addr.sa_family == AF_INET) fail = nla_put(skb, WGPEER_A_ENDPOINT, - sizeof(struct sockaddr_in), + sizeof(peer->endpoint.addr4), &peer->endpoint.addr4); else if (peer->endpoint.addr.sa_family == AF_INET6) fail = nla_put(skb, WGPEER_A_ENDPOINT, - sizeof(struct sockaddr_in6), + sizeof(peer->endpoint.addr6), &peer->endpoint.addr6); read_unlock_bh(&peer->endpoint_lock); if (fail) @@ -336,8 +336,7 @@ static int set_allowedip(struct wireguard_peer *peer, struct nlattr **attrs) nla_data(attrs[WGALLOWEDIP_A_IPADDR]), cidr, peer, &peer->device->device_update_lock); else if (family == AF_INET6 && cidr <= 128 && - nla_len(attrs[WGALLOWEDIP_A_IPADDR]) == - sizeof(struct in6_addr)) + nla_len(attrs[WGALLOWEDIP_A_IPADDR]) == sizeof(struct in6_addr)) ret = allowedips_insert_v6( &peer->device->peer_allowedips, nla_data(attrs[WGALLOWEDIP_A_IPADDR]), cidr, peer, diff --git a/src/noise.c b/src/noise.c index 70b53a6..9bd2d7e 100644 --- a/src/noise.c +++ b/src/noise.c @@ -67,7 +67,7 @@ bool noise_handshake_init(struct noise_handshake *handshake, const u8 peer_preshared_key[NOISE_SYMMETRIC_KEY_LEN], struct wireguard_peer *peer) { - memset(handshake, 0, sizeof(struct noise_handshake)); + memset(handshake, 0, sizeof(*handshake)); init_rwsem(&handshake->lock); handshake->entry.type = INDEX_HASHTABLE_HANDSHAKE; handshake->entry.peer = peer; @@ -103,8 +103,7 @@ void noise_handshake_clear(struct noise_handshake *handshake) static struct noise_keypair *keypair_create(struct wireguard_peer *peer) { - struct noise_keypair *keypair = - kzalloc(sizeof(struct noise_keypair), GFP_KERNEL); + struct noise_keypair *keypair = kzalloc(sizeof(*keypair), GFP_KERNEL); if (unlikely(!keypair)) return NULL; @@ -29,7 +29,7 @@ peer_create(struct wireguard_device *wg, if (wg->num_peers >= MAX_PEERS_PER_DEVICE) return NULL; - peer = kzalloc(sizeof(struct wireguard_peer), GFP_KERNEL); + peer = kzalloc(sizeof(*peer), GFP_KERNEL); if (!peer) return NULL; peer->device = wg; diff --git a/src/ratelimiter.c b/src/ratelimiter.c index 836b4a6..6c7262a 100644 --- a/src/ratelimiter.c +++ b/src/ratelimiter.c @@ -173,12 +173,12 @@ int ratelimiter_init(void) (1U << 14) / sizeof(struct hlist_head))); max_entries = table_size * 8; - table_v4 = kvzalloc(table_size * sizeof(struct hlist_head), GFP_KERNEL); + table_v4 = kvzalloc(table_size * sizeof(*table_v4), GFP_KERNEL); if (!table_v4) goto err_kmemcache; #if IS_ENABLED(CONFIG_IPV6) - table_v6 = kvzalloc(table_size * sizeof(struct hlist_head), GFP_KERNEL); + table_v6 = kvzalloc(table_size * sizeof(*table_v6), GFP_KERNEL); if (!table_v6) { kvfree(table_v4); goto err_kmemcache; diff --git a/src/selftest/allowedips.h b/src/selftest/allowedips.h index 28461d7..6b47fc8 100644 --- a/src/selftest/allowedips.h +++ b/src/selftest/allowedips.h @@ -176,8 +176,7 @@ static __init int horrible_allowedips_insert_v4(struct horrible_allowedips *table, struct in_addr *ip, uint8_t cidr, void *value) { - struct horrible_allowedips_node *node = - kzalloc(sizeof(struct horrible_allowedips_node), GFP_KERNEL); + struct horrible_allowedips_node *node = kzalloc(sizeof(*node), GFP_KERNEL); if (!node) return -ENOMEM; @@ -193,8 +192,7 @@ static __init int horrible_allowedips_insert_v6(struct horrible_allowedips *table, struct in6_addr *ip, uint8_t cidr, void *value) { - struct horrible_allowedips_node *node = - kzalloc(sizeof(struct horrible_allowedips_node), GFP_KERNEL); + struct horrible_allowedips_node *node = kzalloc(sizeof(*node), GFP_KERNEL); if (!node) return -ENOMEM; @@ -256,13 +254,13 @@ static __init bool randomized_test(void) allowedips_init(&t); horrible_allowedips_init(&h); - peers = kcalloc(NUM_PEERS, sizeof(struct wireguard_peer *), GFP_KERNEL); + peers = kcalloc(NUM_PEERS, sizeof(*peers), GFP_KERNEL); if (!peers) { pr_info("allowedips random self-test: out of memory\n"); goto free; } for (i = 0; i < NUM_PEERS; ++i) { - peers[i] = kzalloc(sizeof(struct wireguard_peer), GFP_KERNEL); + peers[i] = kzalloc(sizeof(*peers[i]), GFP_KERNEL); if (!peers[i]) { pr_info("allowedips random self-test: out of memory\n"); goto free; @@ -456,7 +454,7 @@ static __init int walk_callback(void *ctx, const u8 *ip, u8 cidr, int family) } #define init_peer(name) do { \ - name = kzalloc(sizeof(struct wireguard_peer), GFP_KERNEL); \ + name = kzalloc(sizeof(*name), GFP_KERNEL); \ if (!name) { \ pr_info("allowedips self-test: out of memory\n"); \ goto free; \ diff --git a/src/selftest/ratelimiter.h b/src/selftest/ratelimiter.h index a71ddb1..1f2b697 100644 --- a/src/selftest/ratelimiter.h +++ b/src/selftest/ratelimiter.h @@ -62,7 +62,7 @@ bool __init ratelimiter_selftest(void) if (!skb4) goto err_nofree; skb4->protocol = htons(ETH_P_IP); - hdr4 = (struct iphdr *)skb_put(skb4, sizeof(struct iphdr)); + hdr4 = (struct iphdr *)skb_put(skb4, sizeof(*hdr4)); hdr4->saddr = htonl(8182); skb_reset_network_header(skb4); ++test; @@ -74,7 +74,7 @@ bool __init ratelimiter_selftest(void) goto err_nofree; } skb6->protocol = htons(ETH_P_IPV6); - hdr6 = (struct ipv6hdr *)skb_put(skb6, sizeof(struct ipv6hdr)); + hdr6 = (struct ipv6hdr *)skb_put(skb6, sizeof(*hdr6)); hdr6->saddr.in6_u.u6_addr32[0] = htonl(1212); hdr6->saddr.in6_u.u6_addr32[1] = htonl(289188); skb_reset_network_header(skb6); @@ -38,10 +38,8 @@ static void packet_send_handshake_initiation(struct wireguard_peer *peer) timers_any_authenticated_packet_sent(peer); atomic64_set(&peer->last_sent_handshake, ktime_get_boot_fast_ns()); - socket_send_buffer_to_peer( - peer, &packet, - sizeof(struct message_handshake_initiation), - HANDSHAKE_DSCP); + socket_send_buffer_to_peer(peer, &packet, sizeof(packet), + HANDSHAKE_DSCP); timers_handshake_initiated(peer); } } @@ -102,10 +100,9 @@ void packet_send_handshake_response(struct wireguard_peer *peer) timers_any_authenticated_packet_sent(peer); atomic64_set(&peer->last_sent_handshake, ktime_get_boot_fast_ns()); - socket_send_buffer_to_peer( - peer, &packet, - sizeof(struct message_handshake_response), - HANDSHAKE_DSCP); + socket_send_buffer_to_peer(peer, &packet, + sizeof(packet), + HANDSHAKE_DSCP); } } } @@ -200,8 +197,7 @@ static inline bool skb_encrypt(struct sk_buff *skb, * and the header. */ skb_set_inner_network_header(skb, 0); - header = (struct message_data *)skb_push(skb, - sizeof(struct message_data)); + header = (struct message_data *)skb_push(skb, sizeof(*header)); header->header.type = cpu_to_le32(MESSAGE_DATA); header->key_idx = keypair->remote_index; header->counter = cpu_to_le64(PACKET_CB(skb)->nonce); diff --git a/src/socket.c b/src/socket.c index f544dd0..2e9e44f 100644 --- a/src/socket.c +++ b/src/socket.c @@ -245,7 +245,7 @@ int socket_send_buffer_as_reply_to_skb(struct wireguard_device *wg, int socket_endpoint_from_skb(struct endpoint *endpoint, const struct sk_buff *skb) { - memset(endpoint, 0, sizeof(struct endpoint)); + memset(endpoint, 0, sizeof(*endpoint)); if (skb->protocol == htons(ETH_P_IP)) { endpoint->addr4.sin_family = AF_INET; endpoint->addr4.sin_port = udp_hdr(skb)->source; |