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.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2017-10-25 17:13:46 +02:00
parent fe703c0cf5
commit d9d0a2cbed
4 changed files with 19 additions and 19 deletions

View File

@ -384,7 +384,7 @@ bool config_read_init(struct config_ctx *ctx, bool append)
struct wgdevice *config_read_finish(struct config_ctx *ctx) struct wgdevice *config_read_finish(struct config_ctx *ctx)
{ {
struct wgpeer *peer; struct wgpeer *peer;
for_each_wgpeer (ctx->device, peer) { for_each_wgpeer(ctx->device, peer) {
if (key_is_zero(peer->public_key)) { if (key_is_zero(peer->public_key)) {
fprintf(stderr, "A peer is missing a public key\n"); fprintf(stderr, "A peer is missing a public key\n");
goto err; goto err;

View File

@ -227,7 +227,7 @@ static int userspace_set_device(struct wgdevice *dev)
if (dev->flags & WGDEVICE_REPLACE_PEERS) if (dev->flags & WGDEVICE_REPLACE_PEERS)
fprintf(f, "replace_peers=true\n"); fprintf(f, "replace_peers=true\n");
for_each_wgpeer (dev, peer) { for_each_wgpeer(dev, peer) {
key_to_hex(hex, peer->public_key); key_to_hex(hex, peer->public_key);
fprintf(f, "public_key=%s\n", hex); fprintf(f, "public_key=%s\n", hex);
if (peer->flags & WGPEER_REMOVE_ME) { 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); fprintf(f, "persistent_keepalive_interval=%u\n", peer->persistent_keepalive_interval);
if (peer->flags & WGPEER_REPLACE_ALLOWEDIPS) if (peer->flags & WGPEER_REPLACE_ALLOWEDIPS)
fprintf(f, "replace_allowed_ips=true\n"); fprintf(f, "replace_allowed_ips=true\n");
for_each_wgallowedip (peer, allowedip) { for_each_wgallowedip(peer, allowedip) {
if (allowedip->family == AF_INET) { if (allowedip->family == AF_INET) {
if (!inet_ntop(AF_INET, &allowedip->ip4, ip, INET6_ADDRSTRLEN)) if (!inet_ntop(AF_INET, &allowedip->ip4, ip, INET6_ADDRSTRLEN))
continue; continue;

View File

@ -43,14 +43,14 @@ static void sort_peers(struct wgdevice *device)
size_t peer_count = 0, i = 0; size_t peer_count = 0, i = 0;
struct wgpeer *peer, **peers; struct wgpeer *peer, **peers;
for_each_wgpeer (device, peer) for_each_wgpeer(device, peer)
++peer_count; ++peer_count;
if (!peer_count) if (!peer_count)
return; return;
peers = calloc(peer_count, sizeof(struct wgpeer *)); peers = calloc(peer_count, sizeof(struct wgpeer *));
if (!peers) if (!peers)
return; return;
for_each_wgpeer (device, peer) for_each_wgpeer(device, peer)
peers[i++] = peer; peers[i++] = peer;
qsort(peers, peer_count, sizeof(struct wgpeer *), peer_cmp); qsort(peers, peer_count, sizeof(struct wgpeer *), peer_cmp);
device->first_peer = peers[0]; device->first_peer = peers[0];
@ -208,7 +208,7 @@ static void pretty_print(struct wgdevice *device)
sort_peers(device); sort_peers(device);
terminal_printf("\n"); 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)); 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)) if (!key_is_zero(peer->preshared_key))
terminal_printf(" " TERMINAL_BOLD "preshared key" TERMINAL_RESET ": %s\n", masked_key(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 "endpoint" TERMINAL_RESET ": %s\n", endpoint(&peer->endpoint.addr));
terminal_printf(" " TERMINAL_BOLD "allowed ips" TERMINAL_RESET ": "); terminal_printf(" " TERMINAL_BOLD "allowed ips" TERMINAL_RESET ": ");
if (peer->first_allowedip) { 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"); terminal_printf("%s" TERMINAL_FG_CYAN "/" TERMINAL_RESET "%u%s", ip(allowedip), allowedip->cidr, allowedip->next_allowedip ? ", " : "\n");
} else } else
terminal_printf("(none)\n"); terminal_printf("(none)\n");
@ -248,7 +248,7 @@ static void dump_print(struct wgdevice *device, bool with_interface)
printf("0x%x\n", device->fwmark); printf("0x%x\n", device->fwmark);
else else
printf("off\n"); printf("off\n");
for_each_wgpeer (device, peer) { for_each_wgpeer(device, peer) {
if (with_interface) if (with_interface)
printf("%s\t", device->name); printf("%s\t", device->name);
printf("%s\t", key(peer->public_key)); printf("%s\t", key(peer->public_key));
@ -258,7 +258,7 @@ static void dump_print(struct wgdevice *device, bool with_interface)
else else
printf("(none)\t"); printf("(none)\t");
if (peer->first_allowedip) { 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'); printf("%s/%u%c", ip(allowedip), allowedip->cidr, allowedip->next_allowedip ? ',' : '\t');
} else } else
printf("(none)\t"); 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")) { } else if (!strcmp(param, "endpoints")) {
if (with_interface) if (with_interface)
printf("%s\t", device->name); printf("%s\t", device->name);
for_each_wgpeer (device, peer) { for_each_wgpeer(device, peer) {
printf("%s\t", key(peer->public_key)); printf("%s\t", key(peer->public_key));
if (peer->endpoint.addr.sa_family == AF_INET || peer->endpoint.addr.sa_family == AF_INET6) if (peer->endpoint.addr.sa_family == AF_INET || peer->endpoint.addr.sa_family == AF_INET6)
printf("%s\n", endpoint(&peer->endpoint.addr)); 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"); printf("(none)\n");
} }
} else if (!strcmp(param, "allowed-ips")) { } else if (!strcmp(param, "allowed-ips")) {
for_each_wgpeer (device, peer) { for_each_wgpeer(device, peer) {
if (with_interface) if (with_interface)
printf("%s\t", device->name); printf("%s\t", device->name);
printf("%s\t", key(peer->public_key)); printf("%s\t", key(peer->public_key));
if (peer->first_allowedip) { 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'); printf("%s/%u%c", ip(allowedip), allowedip->cidr, allowedip->next_allowedip ? ' ' : '\n');
} else } else
printf("(none)\n"); printf("(none)\n");
} }
} else if (!strcmp(param, "latest-handshakes")) { } else if (!strcmp(param, "latest-handshakes")) {
for_each_wgpeer (device, peer) { for_each_wgpeer(device, peer) {
if (with_interface) if (with_interface)
printf("%s\t", device->name); printf("%s\t", device->name);
printf("%s\t%llu\n", key(peer->public_key), (unsigned long long)peer->last_handshake_time.tv_sec); printf("%s\t%llu\n", key(peer->public_key), (unsigned long long)peer->last_handshake_time.tv_sec);
} }
} else if (!strcmp(param, "transfer")) { } else if (!strcmp(param, "transfer")) {
for_each_wgpeer (device, peer) { for_each_wgpeer(device, peer) {
if (with_interface) if (with_interface)
printf("%s\t", device->name); 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); 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")) { } else if (!strcmp(param, "persistent-keepalive")) {
for_each_wgpeer (device, peer) { for_each_wgpeer(device, peer) {
if (with_interface) if (with_interface)
printf("%s\t", device->name); printf("%s\t", device->name);
if (peer->persistent_keepalive_interval) 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)); printf("%s\toff\n", key(peer->public_key));
} }
} else if (!strcmp(param, "preshared-keys")) { } else if (!strcmp(param, "preshared-keys")) {
for_each_wgpeer (device, peer) { for_each_wgpeer(device, peer) {
if (with_interface) if (with_interface)
printf("%s\t", device->name); printf("%s\t", device->name);
printf("%s\t", key(peer->public_key)); printf("%s\t", key(peer->public_key));
printf("%s\n", key(peer->preshared_key)); printf("%s\n", key(peer->preshared_key));
} }
} else if (!strcmp(param, "peers")) { } else if (!strcmp(param, "peers")) {
for_each_wgpeer (device, peer) { for_each_wgpeer(device, peer) {
if (with_interface) if (with_interface)
printf("%s\t", device->name); printf("%s\t", device->name);
printf("%s\n", key(peer->public_key)); printf("%s\n", key(peer->public_key));

View File

@ -43,7 +43,7 @@ int showconf_main(int argc, char *argv[])
printf("PrivateKey = %s\n", base64); printf("PrivateKey = %s\n", base64);
} }
printf("\n"); printf("\n");
for_each_wgpeer (device, peer) { for_each_wgpeer(device, peer) {
key_to_base64(base64, peer->public_key); key_to_base64(base64, peer->public_key);
printf("[Peer]\nPublicKey = %s\n", base64); printf("[Peer]\nPublicKey = %s\n", base64);
if (!key_is_zero(peer->preshared_key)) { if (!key_is_zero(peer->preshared_key)) {
@ -52,7 +52,7 @@ int showconf_main(int argc, char *argv[])
} }
if (peer->first_allowedip) if (peer->first_allowedip)
printf("AllowedIPs = "); printf("AllowedIPs = ");
for_each_wgallowedip (peer, allowedip) { for_each_wgallowedip(peer, allowedip) {
if (allowedip->family == AF_INET) { if (allowedip->family == AF_INET) {
if (!inet_ntop(AF_INET, &allowedip->ip4, ip, INET6_ADDRSTRLEN)) if (!inet_ntop(AF_INET, &allowedip->ip4, ip, INET6_ADDRSTRLEN))
continue; continue;