diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-10-08 22:54:32 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-10-09 01:57:47 +0200 |
commit | 1564e913bf02a924116497bdb8c1b994298c0465 (patch) | |
tree | bd28848929af527602fd0e8474cf50670221b9a0 /src | |
parent | 11d9063c3d2084a6eeb78aaaf5cadc9b8a2ff437 (diff) |
global: give if statements brackets and other cleanups
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/allowedips.c | 19 | ||||
-rw-r--r-- | src/cookie.c | 3 | ||||
-rw-r--r-- | src/device.c | 5 | ||||
-rw-r--r-- | src/hashtables.c | 6 | ||||
-rw-r--r-- | src/noise.c | 3 | ||||
-rw-r--r-- | src/queueing.c | 3 | ||||
-rw-r--r-- | src/receive.c | 12 | ||||
-rw-r--r-- | src/selftest/allowedips.c | 6 | ||||
-rw-r--r-- | src/send.c | 4 | ||||
-rw-r--r-- | src/socket.c | 6 |
10 files changed, 40 insertions, 27 deletions
diff --git a/src/allowedips.c b/src/allowedips.c index 8699fb1..bc43b71 100644 --- a/src/allowedips.c +++ b/src/allowedips.c @@ -20,9 +20,9 @@ struct allowedips_node { static __always_inline void swap_endian(u8 *dst, const u8 *src, u8 bits) { - if (bits == 32) + if (bits == 32) { *(u32 *)dst = be32_to_cpu(*(const __be32 *)src); - else if (bits == 128) { + } else if (bits == 128) { ((u64 *)dst)[0] = be64_to_cpu(((const __be64 *)src)[0]); ((u64 *)dst)[1] = be64_to_cpu(((const __be64 *)src)[1]); } @@ -50,8 +50,8 @@ static void node_free_rcu(struct rcu_head *rcu) #define push_rcu(stack, p, len) ({ \ if (rcu_access_pointer(p)) { \ - WARN_ON(IS_ENABLED(DEBUG) && len >= 128); \ - stack[len++] = rcu_dereference_raw(p); \ + WARN_ON(IS_ENABLED(DEBUG) && (len) >= 128); \ + stack[(len)++] = rcu_dereference_raw(p); \ } \ true; \ }) @@ -104,14 +104,16 @@ walk_by_peer(struct allowedips_node __rcu *top, u8 bits, } return 0; } + #undef push_rcu #define ref(p) rcu_access_pointer(p) -#define deref(p) rcu_dereference_protected(*p, lockdep_is_held(lock)) +#define deref(p) rcu_dereference_protected(*(p), lockdep_is_held(lock)) #define push(p) ({ \ WARN_ON(IS_ENABLED(DEBUG) && len >= 128); \ stack[len++] = p; \ }) + static void walk_remove_by_peer(struct allowedips_node __rcu **top, struct wg_peer *peer, struct mutex *lock) { @@ -153,6 +155,7 @@ static void walk_remove_by_peer(struct allowedips_node __rcu **top, } } } + #undef ref #undef deref #undef push @@ -181,7 +184,7 @@ static __always_inline u8 common_bits(const struct allowedips_node *node, * this instead. */ #define prefix_matches(node, key, bits) \ - (common_bits(node, key, bits) >= node->cidr) + (common_bits(node, key, bits) >= (node)->cidr) static __always_inline struct allowedips_node * find_node(struct allowedips_node *trie, u8 bits, const u8 *key) @@ -270,9 +273,9 @@ static int add(struct allowedips_node __rcu **trie, u8 bits, const u8 *key, RCU_INIT_POINTER(newnode->peer, peer); copy_and_assign_cidr(newnode, key, cidr, bits); - if (!node) + if (!node) { down = rcu_dereference_protected(*trie, lockdep_is_held(lock)); - else { + } else { down = rcu_dereference_protected(choose_node(node, key), lockdep_is_held(lock)); if (!down) { diff --git a/src/cookie.c b/src/cookie.c index d4a6cf2..b1e650d 100644 --- a/src/cookie.c +++ b/src/cookie.c @@ -226,9 +226,10 @@ void wg_cookie_message_consume(struct message_handshake_cookie *src, peer->latest_cookie.is_valid = true; peer->latest_cookie.have_sent_mac1 = false; up_write(&peer->latest_cookie.lock); - } else + } else { net_dbg_ratelimited("%s: Could not decrypt invalid cookie response\n", wg->dev->name); + } out: wg_peer_put(peer); diff --git a/src/device.c b/src/device.c index 63e89e1..3a14e33 100644 --- a/src/device.c +++ b/src/device.c @@ -91,6 +91,7 @@ static int wg_pm_notification(struct notifier_block *nb, unsigned long action, rcu_barrier_bh(); return 0; } + static struct notifier_block pm_notifier = { .notifier_call = wg_pm_notification }; #endif @@ -154,9 +155,9 @@ static netdev_tx_t wg_xmit(struct sk_buff *skb, struct net_device *dev) mtu = skb_dst(skb) ? dst_mtu(skb_dst(skb)) : dev->mtu; __skb_queue_head_init(&packets); - if (!skb_is_gso(skb)) + if (!skb_is_gso(skb)) { skb->next = NULL; - else { + } else { struct sk_buff *segs = skb_gso_segment(skb, 0); if (unlikely(IS_ERR(segs))) { diff --git a/src/hashtables.c b/src/hashtables.c index ee55b8e..14baf5b 100644 --- a/src/hashtables.c +++ b/src/hashtables.c @@ -14,9 +14,9 @@ static struct hlist_head *pubkey_bucket(struct pubkey_hashtable *table, * the bits are uniformly distributed, we can then mask off to get the * bits we need. */ - return &table->hashtable[ - siphash(pubkey, NOISE_PUBLIC_KEY_LEN, &table->key) & - (HASH_SIZE(table->hashtable) - 1)]; + const u64 hash = siphash(pubkey, NOISE_PUBLIC_KEY_LEN, &table->key); + + return &table->hashtable[hash & (HASH_SIZE(table->hashtable) - 1)]; } void wg_pubkey_hashtable_init(struct pubkey_hashtable *table) diff --git a/src/noise.c b/src/noise.c index 0de09fb..098c060 100644 --- a/src/noise.c +++ b/src/noise.c @@ -777,8 +777,9 @@ bool wg_noise_handshake_begin_session(struct noise_handshake *handshake, ret = wg_index_hashtable_replace( &handshake->entry.peer->device->index_hashtable, &handshake->entry, &new_keypair->entry); - } else + } else { kzfree(new_keypair); + } rcu_read_unlock_bh(); out: diff --git a/src/queueing.c b/src/queueing.c index 70e9394..5d0219e 100644 --- a/src/queueing.c +++ b/src/queueing.c @@ -37,8 +37,9 @@ int wg_packet_queue_init(struct crypt_queue *queue, work_func_t function, function, queue); if (!queue->worker) return -ENOMEM; - } else + } else { INIT_WORK(&queue->work, function); + } } return 0; } diff --git a/src/receive.c b/src/receive.c index 0a48933..33a60b7 100644 --- a/src/receive.c +++ b/src/receive.c @@ -126,11 +126,11 @@ static void wg_receive_handshake_packet(struct wg_device *wg, mac_state = wg_cookie_validate_packet(&wg->cookie_checker, skb, under_load); if ((under_load && mac_state == VALID_MAC_WITH_COOKIE) || - (!under_load && mac_state == VALID_MAC_BUT_NO_COOKIE)) + (!under_load && mac_state == VALID_MAC_BUT_NO_COOKIE)) { packet_needs_cookie = false; - else if (under_load && mac_state == VALID_MAC_BUT_NO_COOKIE) + } else if (under_load && mac_state == VALID_MAC_BUT_NO_COOKIE) { packet_needs_cookie = true; - else { + } else { net_dbg_skb_ratelimited("%s: Invalid MAC of handshake, dropping packet from %pISpfsc\n", wg->dev->name, skb); return; @@ -392,8 +392,9 @@ static void wg_packet_consume_data_done(struct wg_peer *peer, sizeof(struct ipv6hdr); if (INET_ECN_is_ce(PACKET_CB(skb)->ds)) IP6_ECN_set_ce(skb, ipv6_hdr(skb)); - } else + } else { goto dishonest_packet_type; + } if (unlikely(len > skb->len)) goto dishonest_packet_size; @@ -413,8 +414,9 @@ static void wg_packet_consume_data_done(struct wg_peer *peer, net_dbg_ratelimited("%s: Failed to give packet to userspace from peer %llu (%pISpfsc)\n", dev->name, peer->internal_id, &peer->endpoint.addr); - } else + } else { update_rx_stats(peer, message_data_len(len_before_trim)); + } return; dishonest_packet_peer: diff --git a/src/selftest/allowedips.c b/src/selftest/allowedips.c index fdedfef..74d1472 100644 --- a/src/selftest/allowedips.c +++ b/src/selftest/allowedips.c @@ -72,6 +72,7 @@ static __init void print_node(struct allowedips_node *node, u8 bits) print_node(node->bit[1], bits); } } + static __init void print_tree(struct allowedips_node *top, u8 bits) { printk(KERN_DEBUG "digraph trie {\n"); @@ -135,9 +136,9 @@ static __init inline u8 horrible_mask_to_cidr(union nf_inet_addr subnet) static __init inline void horrible_mask_self(struct horrible_allowedips_node *node) { - if (node->ip_version == 4) + if (node->ip_version == 4) { node->ip.ip &= node->mask.ip; - else if (node->ip_version == 6) { + } else if (node->ip_version == 6) { node->ip.ip6[0] &= node->mask.ip6[0]; node->ip.ip6[1] &= node->mask.ip6[1]; node->ip.ip6[2] &= node->mask.ip6[2]; @@ -487,6 +488,7 @@ static __init int walk_callback(void *ctx, const u8 *ip, u8 cidr, int family) static __init struct wg_peer *init_peer(void) { struct wg_peer *peer = kzalloc(sizeof(*peer), GFP_KERNEL); + if (peer) kref_init(&peer->refcount); return peer; @@ -305,9 +305,9 @@ void wg_packet_encrypt_worker(struct work_struct *work) skb_walk_null_queue_safe(first, skb, next) { if (likely(encrypt_packet(skb, PACKET_CB(first)->keypair, - &simd_context))) + &simd_context))) { wg_reset_packet(skb); - else { + } else { state = PACKET_STATE_DEAD; break; } diff --git a/src/socket.c b/src/socket.c index 7fa9fa6..2752335 100644 --- a/src/socket.c +++ b/src/socket.c @@ -256,8 +256,9 @@ int wg_socket_endpoint_from_skb(struct endpoint *endpoint, endpoint->addr6.sin6_scope_id = ipv6_iface_scope_id( &ipv6_hdr(skb)->saddr, skb->skb_iif); endpoint->src6 = ipv6_hdr(skb)->daddr; - } else + } else { return -EINVAL; + } return 0; } @@ -294,8 +295,9 @@ void wg_socket_set_peer_endpoint(struct wg_peer *peer, } else if (endpoint->addr.sa_family == AF_INET6) { peer->endpoint.addr6 = endpoint->addr6; peer->endpoint.src6 = endpoint->src6; - } else + } else { goto out; + } dst_cache_reset(&peer->endpoint_cache); out: write_unlock_bh(&peer->endpoint_lock); |