]> git.ipfire.org Git - thirdparty/libnftnl.git/commitdiff
chain: Add support for NFTA_CHAIN_NEW_NAME attribute
authorTomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Thu, 1 Nov 2012 02:20:37 +0000 (02:20 +0000)
committerPablo Neira Ayuso <pablo@netfilter.org>
Thu, 1 Nov 2012 12:55:06 +0000 (13:55 +0100)
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/libnftables/chain.h
include/linux/netfilter/nf_tables.h
src/chain.c

index 4325fade528fecae3c57b404a76851cdd45f4e7a..39e4b9a3fc1bed52680288abc5cbb8616d2f9e4a 100644 (file)
@@ -22,6 +22,7 @@ enum {
        NFT_CHAIN_ATTR_USE,
        NFT_CHAIN_ATTR_BYTES,
        NFT_CHAIN_ATTR_PACKETS  = 8,
+       NFT_CHAIN_ATTR_NEW_NAME,
 };
 
 void nft_chain_attr_set(struct nft_chain *t, uint16_t attr, void *data);
index a41f73ae88018641ef5f7a2a2cc52f2619076896..aa84cea7f2acf38bb10aa4ce677ebd613a1a8402 100644 (file)
@@ -69,6 +69,7 @@ enum nft_chain_attributes {
        NFTA_CHAIN_HOOK,
        NFTA_CHAIN_POLICY,
        NFTA_CHAIN_USE,
+       NFTA_CHAIN_NEW_NAME,
        NFTA_CHAIN_COUNTERS,
        __NFTA_CHAIN_MAX
 };
index bdda01c30e70735f3de41a1417c56a8b988d73f9..3b61d92451cefea1ddf1929ad3f81404f579c1cd 100644 (file)
@@ -36,6 +36,7 @@ struct nft_chain {
        uint64_t        packets;
        uint64_t        bytes;
        uint32_t        flags;
+       char            new_name[NFT_CHAIN_MAXNAMELEN];
 };
 
 struct nft_chain *nft_chain_alloc(void)
@@ -83,6 +84,9 @@ void nft_chain_attr_set(struct nft_chain *c, uint16_t attr, void *data)
        case NFT_CHAIN_ATTR_PACKETS:
                c->bytes = *((uint64_t *)data);
                break;
+       case NFT_CHAIN_ATTR_NEW_NAME:
+               strncpy(c->new_name, data, NFT_CHAIN_MAXNAMELEN);
+               break;
        default:
                return;
        }
@@ -158,6 +162,12 @@ void *nft_chain_attr_get(struct nft_chain *c, uint16_t attr)
                else
                        return NULL;
                break;
+       case NFT_CHAIN_ATTR_NEW_NAME:
+               if (c->flags & (1 << NFT_CHAIN_ATTR_NEW_NAME))
+                       return c->new_name;
+               else
+                       return NULL;
+               break;
        default:
                return NULL;
        }
@@ -238,6 +248,8 @@ void nft_chain_nlmsg_build_payload(struct nlmsghdr *nlh, const struct nft_chain
                mnl_attr_put_u64(nlh, NFTA_COUNTER_BYTES, be64toh(c->bytes));
                mnl_attr_nest_end(nlh, nest);
        }
+       if (c->flags & (1 << NFT_CHAIN_ATTR_NEW_NAME))
+               mnl_attr_put_strz(nlh, NFTA_CHAIN_NEW_NAME, c->new_name);
 }
 EXPORT_SYMBOL(nft_chain_nlmsg_build_payload);
 
@@ -252,6 +264,7 @@ static int nft_chain_parse_attr_cb(const struct nlattr *attr, void *data)
        switch(type) {
        case NFTA_CHAIN_NAME:
        case NFTA_CHAIN_TABLE:
+       case NFTA_CHAIN_NEW_NAME:
                if (mnl_attr_validate(attr, MNL_TYPE_STRING) < 0) {
                        perror("mnl_attr_validate");
                        return MNL_CB_ERROR;
@@ -386,6 +399,11 @@ int nft_chain_nlmsg_parse(const struct nlmsghdr *nlh, struct nft_chain *c)
        }
        if (tb[NFTA_CHAIN_COUNTERS])
                ret = nft_chain_parse_counters(tb[NFTA_CHAIN_COUNTERS], c);
+       if (tb[NFTA_CHAIN_NEW_NAME]) {
+               strncpy(c->new_name, mnl_attr_get_str(tb[NFTA_CHAIN_NEW_NAME]),
+                       NFT_CHAIN_MAXNAMELEN);
+               c->flags |= (1 << NFT_CHAIN_ATTR_NEW_NAME);
+       }
 
        c->family = nfg->nfgen_family;