]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
netlink: add netlink specific location
authorPatrick McHardy <kaber@trash.net>
Wed, 5 Feb 2014 19:50:43 +0000 (19:50 +0000)
committerPatrick McHardy <kaber@trash.net>
Wed, 5 Feb 2014 19:53:47 +0000 (19:53 +0000)
Add a netlink_location and use it for error messages instead of internal_location.

internal:0:0-0: Error: Could not add set: Operation not permitted
=>
netlink: Error: Could not add set: Operation not permitted

Signed-off-by: Patrick McHardy <kaber@trash.net>
include/netlink.h
src/netlink.c
src/netlink_delinearize.c

index 84b24877fe53f2f17999319a63c3075c7fd8f6ac..4e3f8aa757ea00e89ff6c4ee2386e9196d3b8e78 100644 (file)
@@ -12,6 +12,9 @@
 
 #include <rule.h>
 
+extern const struct input_descriptor indesc_netlink;
+extern const struct location netlink_location;
+
 /** 
  * struct netlink_ctx
  *
index 98e7fc6c4caed06c7ae613a6362798705b126fad..6e797dcfe16f9b790d3b167d531271e5312990c4 100644 (file)
 
 static struct mnl_socket *nf_sock;
 
+const struct input_descriptor indesc_netlink = {
+       .name   = "netlink",
+       .type   = INDESC_NETLINK,
+};
+
+const struct location netlink_location = {
+       .indesc = &indesc_netlink,
+};
+
 static void __init netlink_open_sock(void)
 {
        nf_sock = mnl_socket_open(NETLINK_NETFILTER);
@@ -55,7 +64,7 @@ int netlink_io_error(struct netlink_ctx *ctx, const struct location *loc,
        va_list ap;
 
        if (loc == NULL)
-               loc = &internal_location;
+               loc = &netlink_location;
 
        va_start(ap, fmt);
        erec = erec_vcreate(EREC_ERROR, loc, fmt, ap);
@@ -848,7 +857,7 @@ static int list_set_cb(struct nft_set *nls, void *arg)
        } else
                datatype = NULL;
 
-       set = set_alloc(&internal_location);
+       set = set_alloc(&netlink_location);
        set->handle.family = nft_set_attr_get_u32(nls, NFT_SET_ATTR_FAMILY);
        set->handle.table  =
                xstrdup(nft_set_attr_get_str(nls, NFT_SET_ATTR_TABLE));
@@ -899,7 +908,7 @@ int netlink_get_set(struct netlink_ctx *ctx, const struct handle *h,
                                        "Could not receive set from kernel: %s",
                                        strerror(errno));
 
-       set = set_alloc(&internal_location);
+       set = set_alloc(&netlink_location);
        set->handle.family = nft_set_attr_get_u32(nls, NFT_SET_ATTR_FAMILY);
        set->handle.table  =
                xstrdup(nft_set_attr_get_str(nls, NFT_SET_ATTR_TABLE));
@@ -984,7 +993,7 @@ static int list_setelem_cb(struct nft_set_elem *nlse, void *arg)
        if (nft_set_elem_attr_is_set(nlse, NFT_SET_ELEM_ATTR_FLAGS))
                flags = nft_set_elem_attr_get_u32(nlse, NFT_SET_ELEM_ATTR_FLAGS);
 
-       expr = netlink_alloc_value(&internal_location, &nld);
+       expr = netlink_alloc_value(&netlink_location, &nld);
        expr->dtype     = set->keytype;
        expr->byteorder = set->keytype->byteorder;
        if (expr->byteorder == BYTEORDER_HOST_ENDIAN)
@@ -1004,7 +1013,7 @@ static int list_setelem_cb(struct nft_set_elem *nlse, void *arg)
                } else
                        goto out;
 
-               data = netlink_alloc_data(&internal_location, &nld,
+               data = netlink_alloc_data(&netlink_location, &nld,
                                          set->datatype->type == TYPE_VERDICT ?
                                          NFT_REG_VERDICT : NFT_REG_1);
                data->dtype = set->datatype;
@@ -1012,7 +1021,7 @@ static int list_setelem_cb(struct nft_set_elem *nlse, void *arg)
                if (data->byteorder == BYTEORDER_HOST_ENDIAN)
                        mpz_switch_byteorder(data->value, data->len / BITS_PER_BYTE);
 
-               expr = mapping_expr_alloc(&internal_location, expr, data);
+               expr = mapping_expr_alloc(&netlink_location, expr, data);
        }
 out:
        compound_expr_add(set->init, expr);
index 59b507456bfb3f5c05644ae14b58bb6b077a5587..666830837022eacb3a5448afba2edf0a907742fc 100644 (file)
@@ -545,11 +545,6 @@ static const struct {
        { .name = "queue",      .parse = netlink_parse_queue },
 };
 
-static const struct input_descriptor indesc_netlink = {
-       .name = "netlink",
-       .type  = INDESC_NETLINK,
-};
-
 static int netlink_parse_expr(struct nft_rule_expr *nle, void *arg)
 {
        const char *type = nft_rule_expr_get_str(nle, NFT_RULE_EXPR_ATTR_NAME);
@@ -878,7 +873,7 @@ struct rule *netlink_delinearize_rule(struct netlink_ctx *ctx,
        if (nft_rule_attr_is_set(nlr, NFT_RULE_ATTR_POSITION))
                h.position = nft_rule_attr_get_u64(nlr, NFT_RULE_ATTR_POSITION);
 
-       pctx->rule = rule_alloc(&internal_location, &h);
+       pctx->rule = rule_alloc(&netlink_location, &h);
        pctx->table = table_lookup(&h);
        assert(pctx->table != NULL);
        nft_rule_expr_foreach((struct nft_rule *)nlr, netlink_parse_expr, pctx);