]> git.ipfire.org Git - thirdparty/wireguard-tools.git/commitdiff
wg: warn once on unrecognized items
authorJason A. Donenfeld <Jason@zx2c4.com>
Mon, 9 Oct 2017 11:27:00 +0000 (13:27 +0200)
committerJason A. Donenfeld <Jason@zx2c4.com>
Mon, 9 Oct 2017 11:31:18 +0000 (13:31 +0200)
DaveM suggests we do in fact do this. Others on the same thread weren't
happy about the length of the proposed message, so we also give a bit of
a less dramatic warning.

This reverts commit a2cc976a3b572cf308cc2d97c080eacac60416fe.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
src/containers.h
src/ipc.c

index 2261b07c62562cd1671ada1a551e2563027b5eb5..4c80a770bdda809450649f53d4d5b9a409dc6e46 100644 (file)
@@ -63,6 +63,7 @@ enum {
 
 struct wgdevice {
        char name[IFNAMSIZ];
+       uint32_t ifindex;
 
        uint32_t flags;
 
index a460d2832c441d6aa77b7755f2e64395f9e05e47..521a904320a2a1797536eb3b8322f66be3d36f2b 100644 (file)
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -91,6 +91,15 @@ static int add_next_to_inflatable_buffer(struct inflatable_buffer *buffer)
        return 0;
 }
 
+static void warn_unrecognized(const char *which)
+{
+       static bool once = false;
+       if (once)
+               return;
+       once = true;
+       fprintf(stderr, "Warning: one or more unrecognized %s attributes", which);
+}
+
 static FILE *userspace_interface_file(const char *interface)
 {
        struct stat sbuf;
@@ -421,6 +430,8 @@ static int userspace_get_device(struct wgdevice **out, const char *interface)
                        peer->tx_bytes = NUM(0xffffffffffffffffULL);
                else if (!strcmp(key, "errno"))
                        ret = -NUM(0x7fffffffU);
+               else
+                       warn_unrecognized("daemon");
        }
        ret = -EPROTO;
 err:
@@ -692,6 +703,8 @@ static int parse_allowedip(const struct nlattr *attr, void *data)
                if (!mnl_attr_validate(attr, MNL_TYPE_U8))
                        ctx->allowedip->cidr = mnl_attr_get_u8(attr);
                break;
+       default:
+               warn_unrecognized("netlink");
        }
 
        return MNL_CB_OK;
@@ -761,6 +774,8 @@ static int parse_peer(const struct nlattr *attr, void *data)
                break;
        case WGPEER_A_ALLOWEDIPS:
                return mnl_attr_parse_nested(attr, parse_allowedips, ctx);
+       default:
+               warn_unrecognized("netlink");
        }
 
        return MNL_CB_OK;
@@ -794,6 +809,10 @@ static int parse_device(const struct nlattr *attr, void *data)
        struct get_device_ctx *ctx = data;
 
        switch (mnl_attr_get_type(attr)) {
+       case WGDEVICE_A_IFINDEX:
+               if (!mnl_attr_validate(attr, MNL_TYPE_U32))
+                       ctx->device->ifindex = mnl_attr_get_u32(attr);
+               break;
        case WGDEVICE_A_IFNAME:
                if (!mnl_attr_validate(attr, MNL_TYPE_STRING))
                        strncpy(ctx->device->name, mnl_attr_get_str(attr), sizeof(ctx->device->name) - 1);
@@ -816,6 +835,8 @@ static int parse_device(const struct nlattr *attr, void *data)
                break;
        case WGDEVICE_A_PEERS:
                return mnl_attr_parse_nested(attr, parse_peers, ctx);
+       default:
+               warn_unrecognized("netlink");
        }
 
        return MNL_CB_OK;