aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2017-10-25 17:13:46 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2017-10-31 17:25:23 +0100
commit7491cd4c22601eb0c3bedfea740f2aec3b8372ed (patch)
treee5b8c3adf9e17e9abf3c028ea163ee7840659826
parentpeer: store total number of peers instead of iterating (diff)
downloadwireguard-monolithic-historical-7491cd4c22601eb0c3bedfea740f2aec3b8372ed.tar.xz
wireguard-monolithic-historical-7491cd4c22601eb0c3bedfea740f2aec3b8372ed.zip
global: infuriating kernel iterator style
One types: for (i = 0 ... So one should also type: for_each_obj (obj ... But the upstream kernel style guidelines are insane, and so we must instead do: for_each_obj(obj ... Ugly, but one must choose his battles wisely.
-rw-r--r--src/compat/compat.h2
-rw-r--r--src/device.c8
-rw-r--r--src/hashtables.c8
-rw-r--r--src/netlink.c12
-rw-r--r--src/peer.c2
-rw-r--r--src/queueing.c2
-rw-r--r--src/ratelimiter.c6
-rw-r--r--src/selftest/routingtable.h8
-rw-r--r--src/send.c10
-rw-r--r--src/tools/config.c2
-rw-r--r--src/tools/ipc.c4
-rw-r--r--src/tools/show.c28
-rw-r--r--src/tools/showconf.c4
13 files changed, 48 insertions, 48 deletions
diff --git a/src/compat/compat.h b/src/compat/compat.h
index e8076db..34353ea 100644
--- a/src/compat/compat.h
+++ b/src/compat/compat.h
@@ -162,7 +162,7 @@ static inline void netif_keep_dst(struct net_device *dev)
typeof(type) __percpu *pcpu_stats = alloc_percpu(type); \
if (pcpu_stats) { \
int __cpu; \
- for_each_possible_cpu (__cpu) { \
+ for_each_possible_cpu(__cpu) { \
typeof(type) *stat; \
stat = per_cpu_ptr(pcpu_stats, __cpu); \
u64_stats_init(&stat->syncp); \
diff --git a/src/device.c b/src/device.c
index cf6e2b2..8a2eb0a 100644
--- a/src/device.c
+++ b/src/device.c
@@ -54,7 +54,7 @@ static int open(struct net_device *dev)
if (ret < 0)
return ret;
mutex_lock(&wg->device_update_lock);
- list_for_each_entry (peer, &wg->peer_list, peer_list) {
+ list_for_each_entry(peer, &wg->peer_list, peer_list) {
packet_send_staged_packets(peer);
if (peer->persistent_keepalive_interval)
packet_send_keepalive(peer);
@@ -73,9 +73,9 @@ static int suspending_clear_noise_peers(struct notifier_block *nb, unsigned long
return 0;
rtnl_lock();
- list_for_each_entry (wg, &device_list, device_list) {
+ list_for_each_entry(wg, &device_list, device_list) {
mutex_lock(&wg->device_update_lock);
- list_for_each_entry (peer, &wg->peer_list, peer_list) {
+ list_for_each_entry(peer, &wg->peer_list, peer_list) {
noise_handshake_clear(&peer->handshake);
noise_keypairs_clear(&peer->keypairs);
if (peer->timers_enabled)
@@ -96,7 +96,7 @@ static int stop(struct net_device *dev)
struct wireguard_peer *peer;
mutex_lock(&wg->device_update_lock);
- list_for_each_entry (peer, &wg->peer_list, peer_list) {
+ list_for_each_entry(peer, &wg->peer_list, peer_list) {
skb_queue_purge(&peer->staged_packet_queue);
timers_stop(peer);
noise_handshake_clear(&peer->handshake);
diff --git a/src/hashtables.c b/src/hashtables.c
index 4a3798c..a0c0c64 100644
--- a/src/hashtables.c
+++ b/src/hashtables.c
@@ -38,7 +38,7 @@ struct wireguard_peer *pubkey_hashtable_lookup(struct pubkey_hashtable *table, c
struct wireguard_peer *iter_peer, *peer = NULL;
rcu_read_lock_bh();
- hlist_for_each_entry_rcu_bh (iter_peer, pubkey_bucket(table, pubkey), pubkey_hash) {
+ hlist_for_each_entry_rcu_bh(iter_peer, pubkey_bucket(table, pubkey), pubkey_hash) {
if (!memcmp(pubkey, iter_peer->handshake.remote_static, NOISE_PUBLIC_KEY_LEN)) {
peer = iter_peer;
break;
@@ -97,7 +97,7 @@ __le32 index_hashtable_insert(struct index_hashtable *table, struct index_hashta
search_unused_slot:
/* First we try to find an unused slot, randomly, while unlocked. */
entry->index = (__force __le32)get_random_u32();
- hlist_for_each_entry_rcu_bh (existing_entry, index_bucket(table, entry->index), index_hash) {
+ hlist_for_each_entry_rcu_bh(existing_entry, index_bucket(table, entry->index), index_hash) {
if (existing_entry->index == entry->index)
goto search_unused_slot; /* If it's already in use, we continue searching. */
}
@@ -105,7 +105,7 @@ search_unused_slot:
/* Once we've found an unused slot, we lock it, and then double-check
* that nobody else stole it from us. */
spin_lock_bh(&table->lock);
- hlist_for_each_entry_rcu_bh (existing_entry, index_bucket(table, entry->index), index_hash) {
+ hlist_for_each_entry_rcu_bh(existing_entry, index_bucket(table, entry->index), index_hash) {
if (existing_entry->index == entry->index) {
spin_unlock_bh(&table->lock);
goto search_unused_slot; /* If it was stolen, we start over. */
@@ -145,7 +145,7 @@ struct index_hashtable_entry *index_hashtable_lookup(struct index_hashtable *tab
struct index_hashtable_entry *iter_entry, *entry = NULL;
rcu_read_lock_bh();
- hlist_for_each_entry_rcu_bh (iter_entry, index_bucket(table, index), index_hash) {
+ hlist_for_each_entry_rcu_bh(iter_entry, index_bucket(table, index), index_hash) {
if (iter_entry->index == index) {
if (likely(iter_entry->type & type_mask))
entry = iter_entry;
diff --git a/src/netlink.c b/src/netlink.c
index fed16dc..60c58e0 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -206,7 +206,7 @@ static int get_device_dump(struct sk_buff *skb, struct netlink_callback *cb)
}
lockdep_assert_held(&wg->device_update_lock);
peer = list_prepare_entry(last_peer_cursor, &wg->peer_list, peer_list);
- list_for_each_entry_continue (peer, &wg->peer_list, peer_list) {
+ list_for_each_entry_continue(peer, &wg->peer_list, peer_list) {
if (get_peer(peer, peer_idx++, rt_cursor, skb)) {
done = false;
break;
@@ -260,7 +260,7 @@ static int set_port(struct wireguard_device *wg, u16 port)
return 0;
socket_uninit(wg);
wg->incoming_port = port;
- list_for_each_entry (peer, &wg->peer_list, peer_list)
+ list_for_each_entry(peer, &wg->peer_list, peer_list)
socket_clear_peer_endpoint_src(peer);
if (!netif_running(wg->dev))
return 0;
@@ -356,7 +356,7 @@ static int set_peer(struct wireguard_device *wg, struct nlattr **attrs)
int rem;
struct nlattr *attr, *allowedip[WGALLOWEDIP_A_MAX + 1];
- nla_for_each_nested (attr, attrs[WGPEER_A_ALLOWEDIPS], rem) {
+ nla_for_each_nested(attr, attrs[WGPEER_A_ALLOWEDIPS], rem) {
ret = nla_parse_nested(allowedip, WGALLOWEDIP_A_MAX, attr, allowedip_policy, NULL);
if (ret < 0)
goto out;
@@ -403,7 +403,7 @@ static int set_device(struct sk_buff *skb, struct genl_info *info)
struct wireguard_peer *peer;
wg->fwmark = nla_get_u32(info->attrs[WGDEVICE_A_FWMARK]);
- list_for_each_entry (peer, &wg->peer_list, peer_list)
+ list_for_each_entry(peer, &wg->peer_list, peer_list)
socket_clear_peer_endpoint_src(peer);
}
@@ -428,7 +428,7 @@ static int set_device(struct sk_buff *skb, struct genl_info *info)
peer_remove(peer);
}
noise_set_static_identity_private_key(&wg->static_identity, private_key);
- list_for_each_entry_safe (peer, temp, &wg->peer_list, peer_list) {
+ list_for_each_entry_safe(peer, temp, &wg->peer_list, peer_list) {
if (!noise_precompute_static_static(peer))
peer_remove(peer);
}
@@ -439,7 +439,7 @@ static int set_device(struct sk_buff *skb, struct genl_info *info)
int rem;
struct nlattr *attr, *peer[WGPEER_A_MAX + 1];
- nla_for_each_nested (attr, info->attrs[WGDEVICE_A_PEERS], rem) {
+ nla_for_each_nested(attr, info->attrs[WGDEVICE_A_PEERS], rem) {
ret = nla_parse_nested(peer, WGPEER_A_MAX, attr, peer_policy, NULL);
if (ret < 0)
goto out;
diff --git a/src/peer.c b/src/peer.c
index 55efde3..6ddad26 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -126,6 +126,6 @@ void peer_remove_all(struct wireguard_device *wg)
struct wireguard_peer *peer, *temp;
lockdep_assert_held(&wg->device_update_lock);
- list_for_each_entry_safe (peer, temp, &wg->peer_list, peer_list)
+ list_for_each_entry_safe(peer, temp, &wg->peer_list, peer_list)
peer_remove(peer);
}
diff --git a/src/queueing.c b/src/queueing.c
index fa50511..bce406a 100644
--- a/src/queueing.c
+++ b/src/queueing.c
@@ -10,7 +10,7 @@ struct multicore_worker __percpu *packet_alloc_percpu_multicore_worker(work_func
if (!worker)
return NULL;
- for_each_possible_cpu (cpu) {
+ for_each_possible_cpu(cpu) {
per_cpu_ptr(worker, cpu)->ptr = ptr;
INIT_WORK(&per_cpu_ptr(worker, cpu)->work, function);
}
diff --git a/src/ratelimiter.c b/src/ratelimiter.c
index 0afcdac..a9caf32 100644
--- a/src/ratelimiter.c
+++ b/src/ratelimiter.c
@@ -57,12 +57,12 @@ static void gc_entries(struct work_struct *work)
for (i = 0; i < table_size; ++i) {
spin_lock(&table_lock);
- hlist_for_each_entry_safe (entry, temp, &table_v4[i], hash) {
+ hlist_for_each_entry_safe(entry, temp, &table_v4[i], hash) {
if (unlikely(!work) || now - entry->last_time_ns > NSEC_PER_SEC)
entry_uninit(entry);
}
#if IS_ENABLED(CONFIG_IPV6)
- hlist_for_each_entry_safe (entry, temp, &table_v6[i], hash) {
+ hlist_for_each_entry_safe(entry, temp, &table_v6[i], hash) {
if (unlikely(!work) || now - entry->last_time_ns > NSEC_PER_SEC)
entry_uninit(entry);
}
@@ -94,7 +94,7 @@ bool ratelimiter_allow(struct sk_buff *skb, struct net *net)
else
return false;
rcu_read_lock();
- hlist_for_each_entry_rcu (entry, bucket, hash) {
+ hlist_for_each_entry_rcu(entry, bucket, hash) {
if (entry->net == net && entry->ip == data.ip) {
u64 now, tokens;
bool ret;
diff --git a/src/selftest/routingtable.h b/src/selftest/routingtable.h
index 473f0f9..434c6fc 100644
--- a/src/selftest/routingtable.h
+++ b/src/selftest/routingtable.h
@@ -65,7 +65,7 @@ static __init void horrible_routing_table_free(struct horrible_routing_table *ta
{
struct hlist_node *h;
struct horrible_routing_table_node *node;
- hlist_for_each_entry_safe (node, h, &table->head, table) {
+ hlist_for_each_entry_safe(node, h, &table->head, table) {
hlist_del(&node->table);
kfree(node);
}
@@ -112,7 +112,7 @@ static __init void horrible_insert_ordered(struct horrible_routing_table *table,
{
struct horrible_routing_table_node *other = NULL, *where = NULL;
uint8_t my_cidr = horrible_mask_to_cidr(node->mask);
- hlist_for_each_entry (other, &table->head, table) {
+ hlist_for_each_entry(other, &table->head, table) {
if (!memcmp(&other->mask, &node->mask, sizeof(union nf_inet_addr)) &&
!memcmp(&other->ip, &node->ip, sizeof(union nf_inet_addr)) &&
other->ip_version == node->ip_version) {
@@ -161,7 +161,7 @@ static __init void *horrible_routing_table_lookup_v4(struct horrible_routing_tab
{
struct horrible_routing_table_node *node;
void *ret = NULL;
- hlist_for_each_entry (node, &table->head, table) {
+ hlist_for_each_entry(node, &table->head, table) {
if (node->ip_version != 4)
continue;
if (horrible_match_v4(node, ip)) {
@@ -175,7 +175,7 @@ static __init void *horrible_routing_table_lookup_v6(struct horrible_routing_tab
{
struct horrible_routing_table_node *node;
void *ret = NULL;
- hlist_for_each_entry (node, &table->head, table) {
+ hlist_for_each_entry(node, &table->head, table) {
if (node->ip_version != 6)
continue;
if (horrible_match_v6(node, ip)) {
diff --git a/src/send.c b/src/send.c
index d05c2fe..9e0f635 100644
--- a/src/send.c
+++ b/src/send.c
@@ -185,7 +185,7 @@ static inline void skb_free_null_queue(struct sk_buff *first)
{
struct sk_buff *skb, *next;
- skb_walk_null_queue_safe (first, skb, next)
+ skb_walk_null_queue_safe(first, skb, next)
dev_kfree_skb(skb);
}
@@ -195,7 +195,7 @@ static void packet_create_data_done(struct sk_buff *first, struct wireguard_peer
bool is_keepalive, data_sent = false;
timers_any_authenticated_packet_traversal(peer);
- skb_walk_null_queue_safe (first, skb, next) {
+ skb_walk_null_queue_safe(first, skb, next) {
is_keepalive = skb->len == message_data_len(0);
if (likely(!socket_send_skb_to_peer(peer, skb, PACKET_CB(skb)->ds) && !is_keepalive))
data_sent = true;
@@ -241,7 +241,7 @@ void packet_encrypt_worker(struct work_struct *work)
while ((first = ptr_ring_consume_bh(&queue->ring)) != NULL) {
enum packet_state state = PACKET_STATE_CRYPTED;
- skb_walk_null_queue_safe (first, skb, next) {
+ skb_walk_null_queue_safe(first, skb, next) {
if (likely(skb_encrypt(skb, PACKET_CB(first)->keypair, have_simd)))
skb_reset(skb);
else {
@@ -303,7 +303,7 @@ void packet_send_staged_packets(struct wireguard_peer *peer)
/* After we know we have a somewhat valid key, we now try to assign nonces to
* all of the packets in the queue. If we can't assign nonces for all of them,
* we just consider it a failure and wait for the next handshake. */
- skb_queue_walk (&packets, skb) {
+ skb_queue_walk(&packets, skb) {
PACKET_CB(skb)->ds = ip_tunnel_ecn_encap(0 /* No outer TOS: no leak. TODO: should we use flowi->tos as outer? */, ip_hdr(skb), skb);
PACKET_CB(skb)->nonce = atomic64_inc_return(&key->counter.counter) - 1;
if (unlikely(PACKET_CB(skb)->nonce >= REJECT_AFTER_MESSAGES))
@@ -323,7 +323,7 @@ out_nokey:
/* We orphan the packets if we're waiting on a handshake, so that they
* don't block a socket's pool. */
- skb_queue_walk (&packets, skb)
+ skb_queue_walk(&packets, skb)
skb_orphan(skb);
/* Then we put them back on the top of the queue. We're not too concerned about
* accidently getting things a little out of order if packets are being added
diff --git a/src/tools/config.c b/src/tools/config.c
index ec16e26..8fe3e1c 100644
--- a/src/tools/config.c
+++ b/src/tools/config.c
@@ -384,7 +384,7 @@ bool config_read_init(struct config_ctx *ctx, bool append)
struct wgdevice *config_read_finish(struct config_ctx *ctx)
{
struct wgpeer *peer;
- for_each_wgpeer (ctx->device, peer) {
+ for_each_wgpeer(ctx->device, peer) {
if (key_is_zero(peer->public_key)) {
fprintf(stderr, "A peer is missing a public key\n");
goto err;
diff --git a/src/tools/ipc.c b/src/tools/ipc.c
index 72bbd38..66a5720 100644
--- a/src/tools/ipc.c
+++ b/src/tools/ipc.c
@@ -227,7 +227,7 @@ static int userspace_set_device(struct wgdevice *dev)
if (dev->flags & WGDEVICE_REPLACE_PEERS)
fprintf(f, "replace_peers=true\n");
- for_each_wgpeer (dev, peer) {
+ for_each_wgpeer(dev, peer) {
key_to_hex(hex, peer->public_key);
fprintf(f, "public_key=%s\n", hex);
if (peer->flags & WGPEER_REMOVE_ME) {
@@ -255,7 +255,7 @@ static int userspace_set_device(struct wgdevice *dev)
fprintf(f, "persistent_keepalive_interval=%u\n", peer->persistent_keepalive_interval);
if (peer->flags & WGPEER_REPLACE_ALLOWEDIPS)
fprintf(f, "replace_allowed_ips=true\n");
- for_each_wgallowedip (peer, allowedip) {
+ for_each_wgallowedip(peer, allowedip) {
if (allowedip->family == AF_INET) {
if (!inet_ntop(AF_INET, &allowedip->ip4, ip, INET6_ADDRSTRLEN))
continue;
diff --git a/src/tools/show.c b/src/tools/show.c
index 4203494..d315ee8 100644
--- a/src/tools/show.c
+++ b/src/tools/show.c
@@ -43,14 +43,14 @@ static void sort_peers(struct wgdevice *device)
size_t peer_count = 0, i = 0;
struct wgpeer *peer, **peers;
- for_each_wgpeer (device, peer)
+ for_each_wgpeer(device, peer)
++peer_count;
if (!peer_count)
return;
peers = calloc(peer_count, sizeof(struct wgpeer *));
if (!peers)
return;
- for_each_wgpeer (device, peer)
+ for_each_wgpeer(device, peer)
peers[i++] = peer;
qsort(peers, peer_count, sizeof(struct wgpeer *), peer_cmp);
device->first_peer = peers[0];
@@ -208,7 +208,7 @@ static void pretty_print(struct wgdevice *device)
sort_peers(device);
terminal_printf("\n");
}
- for_each_wgpeer (device, peer) {
+ for_each_wgpeer(device, peer) {
terminal_printf(TERMINAL_FG_YELLOW TERMINAL_BOLD "peer" TERMINAL_RESET ": " TERMINAL_FG_YELLOW "%s" TERMINAL_RESET "\n", key(peer->public_key));
if (!key_is_zero(peer->preshared_key))
terminal_printf(" " TERMINAL_BOLD "preshared key" TERMINAL_RESET ": %s\n", masked_key(peer->preshared_key));
@@ -216,7 +216,7 @@ static void pretty_print(struct wgdevice *device)
terminal_printf(" " TERMINAL_BOLD "endpoint" TERMINAL_RESET ": %s\n", endpoint(&peer->endpoint.addr));
terminal_printf(" " TERMINAL_BOLD "allowed ips" TERMINAL_RESET ": ");
if (peer->first_allowedip) {
- for_each_wgallowedip (peer, allowedip)
+ for_each_wgallowedip(peer, allowedip)
terminal_printf("%s" TERMINAL_FG_CYAN "/" TERMINAL_RESET "%u%s", ip(allowedip), allowedip->cidr, allowedip->next_allowedip ? ", " : "\n");
} else
terminal_printf("(none)\n");
@@ -248,7 +248,7 @@ static void dump_print(struct wgdevice *device, bool with_interface)
printf("0x%x\n", device->fwmark);
else
printf("off\n");
- for_each_wgpeer (device, peer) {
+ for_each_wgpeer(device, peer) {
if (with_interface)
printf("%s\t", device->name);
printf("%s\t", key(peer->public_key));
@@ -258,7 +258,7 @@ static void dump_print(struct wgdevice *device, bool with_interface)
else
printf("(none)\t");
if (peer->first_allowedip) {
- for_each_wgallowedip (peer, allowedip)
+ for_each_wgallowedip(peer, allowedip)
printf("%s/%u%c", ip(allowedip), allowedip->cidr, allowedip->next_allowedip ? ',' : '\t');
} else
printf("(none)\t");
@@ -297,7 +297,7 @@ static bool ugly_print(struct wgdevice *device, const char *param, bool with_int
} else if (!strcmp(param, "endpoints")) {
if (with_interface)
printf("%s\t", device->name);
- for_each_wgpeer (device, peer) {
+ for_each_wgpeer(device, peer) {
printf("%s\t", key(peer->public_key));
if (peer->endpoint.addr.sa_family == AF_INET || peer->endpoint.addr.sa_family == AF_INET6)
printf("%s\n", endpoint(&peer->endpoint.addr));
@@ -305,30 +305,30 @@ static bool ugly_print(struct wgdevice *device, const char *param, bool with_int
printf("(none)\n");
}
} else if (!strcmp(param, "allowed-ips")) {
- for_each_wgpeer (device, peer) {
+ for_each_wgpeer(device, peer) {
if (with_interface)
printf("%s\t", device->name);
printf("%s\t", key(peer->public_key));
if (peer->first_allowedip) {
- for_each_wgallowedip (peer, allowedip)
+ for_each_wgallowedip(peer, allowedip)
printf("%s/%u%c", ip(allowedip), allowedip->cidr, allowedip->next_allowedip ? ' ' : '\n');
} else
printf("(none)\n");
}
} else if (!strcmp(param, "latest-handshakes")) {
- for_each_wgpeer (device, peer) {
+ for_each_wgpeer(device, peer) {
if (with_interface)
printf("%s\t", device->name);
printf("%s\t%llu\n", key(peer->public_key), (unsigned long long)peer->last_handshake_time.tv_sec);
}
} else if (!strcmp(param, "transfer")) {
- for_each_wgpeer (device, peer) {
+ for_each_wgpeer(device, peer) {
if (with_interface)
printf("%s\t", device->name);
printf("%s\t%" PRIu64 "\t%" PRIu64 "\n", key(peer->public_key), (uint64_t)peer->rx_bytes, (uint64_t)peer->tx_bytes);
}
} else if (!strcmp(param, "persistent-keepalive")) {
- for_each_wgpeer (device, peer) {
+ for_each_wgpeer(device, peer) {
if (with_interface)
printf("%s\t", device->name);
if (peer->persistent_keepalive_interval)
@@ -337,14 +337,14 @@ static bool ugly_print(struct wgdevice *device, const char *param, bool with_int
printf("%s\toff\n", key(peer->public_key));
}
} else if (!strcmp(param, "preshared-keys")) {
- for_each_wgpeer (device, peer) {
+ for_each_wgpeer(device, peer) {
if (with_interface)
printf("%s\t", device->name);
printf("%s\t", key(peer->public_key));
printf("%s\n", key(peer->preshared_key));
}
} else if (!strcmp(param, "peers")) {
- for_each_wgpeer (device, peer) {
+ for_each_wgpeer(device, peer) {
if (with_interface)
printf("%s\t", device->name);
printf("%s\n", key(peer->public_key));
diff --git a/src/tools/showconf.c b/src/tools/showconf.c
index 51f9a6f..adc3789 100644
--- a/src/tools/showconf.c
+++ b/src/tools/showconf.c
@@ -43,7 +43,7 @@ int showconf_main(int argc, char *argv[])
printf("PrivateKey = %s\n", base64);
}
printf("\n");
- for_each_wgpeer (device, peer) {
+ for_each_wgpeer(device, peer) {
key_to_base64(base64, peer->public_key);
printf("[Peer]\nPublicKey = %s\n", base64);
if (!key_is_zero(peer->preshared_key)) {
@@ -52,7 +52,7 @@ int showconf_main(int argc, char *argv[])
}
if (peer->first_allowedip)
printf("AllowedIPs = ");
- for_each_wgallowedip (peer, allowedip) {
+ for_each_wgallowedip(peer, allowedip) {
if (allowedip->family == AF_INET) {
if (!inet_ntop(AF_INET, &allowedip->ip4, ip, INET6_ADDRSTRLEN))
continue;