]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blobdiff - net/netfilter/nf_tables_api.c
netfilter: Remove unnecessary cast on void pointer
[mirror_ubuntu-artful-kernel.git] / net / netfilter / nf_tables_api.c
index 5e0ccfd5bb37d1cbebb7e03b0998b7c24cca024d..7ba76da96cc2c61f11c115b8393a410168f29b31 100644 (file)
@@ -144,7 +144,7 @@ static int nf_tables_register_hooks(struct net *net,
                                    unsigned int hook_nops)
 {
        if (table->flags & NFT_TABLE_F_DORMANT ||
-           !(chain->flags & NFT_BASE_CHAIN))
+           !nft_is_base_chain(chain))
                return 0;
 
        return nf_register_net_hooks(net, nft_base_chain(chain)->ops,
@@ -157,7 +157,7 @@ static void nf_tables_unregister_hooks(struct net *net,
                                       unsigned int hook_nops)
 {
        if (table->flags & NFT_TABLE_F_DORMANT ||
-           !(chain->flags & NFT_BASE_CHAIN))
+           !nft_is_base_chain(chain))
                return;
 
        nf_unregister_net_hooks(net, nft_base_chain(chain)->ops, hook_nops);
@@ -438,7 +438,7 @@ static int nf_tables_fill_table_info(struct sk_buff *skb, struct net *net,
        struct nlmsghdr *nlh;
        struct nfgenmsg *nfmsg;
 
-       event |= NFNL_SUBSYS_NFTABLES << 8;
+       event = nfnl_msg_type(NFNL_SUBSYS_NFTABLES, event);
        nlh = nlmsg_put(skb, portid, seq, event, sizeof(struct nfgenmsg), flags);
        if (nlh == NULL)
                goto nla_put_failure;
@@ -587,7 +587,7 @@ static void _nf_tables_table_disable(struct net *net,
        list_for_each_entry(chain, &table->chains, list) {
                if (!nft_is_active_next(net, chain))
                        continue;
-               if (!(chain->flags & NFT_BASE_CHAIN))
+               if (!nft_is_base_chain(chain))
                        continue;
 
                if (cnt && i++ == cnt)
@@ -608,7 +608,7 @@ static int nf_tables_table_enable(struct net *net,
        list_for_each_entry(chain, &table->chains, list) {
                if (!nft_is_active_next(net, chain))
                        continue;
-               if (!(chain->flags & NFT_BASE_CHAIN))
+               if (!nft_is_base_chain(chain))
                        continue;
 
                err = nf_register_net_hooks(net, nft_base_chain(chain)->ops,
@@ -989,7 +989,7 @@ static int nf_tables_fill_chain_info(struct sk_buff *skb, struct net *net,
        struct nlmsghdr *nlh;
        struct nfgenmsg *nfmsg;
 
-       event |= NFNL_SUBSYS_NFTABLES << 8;
+       event = nfnl_msg_type(NFNL_SUBSYS_NFTABLES, event);
        nlh = nlmsg_put(skb, portid, seq, event, sizeof(struct nfgenmsg), flags);
        if (nlh == NULL)
                goto nla_put_failure;
@@ -1007,7 +1007,7 @@ static int nf_tables_fill_chain_info(struct sk_buff *skb, struct net *net,
        if (nla_put_string(skb, NFTA_CHAIN_NAME, chain->name))
                goto nla_put_failure;
 
-       if (chain->flags & NFT_BASE_CHAIN) {
+       if (nft_is_base_chain(chain)) {
                const struct nft_base_chain *basechain = nft_base_chain(chain);
                const struct nf_hook_ops *ops = &basechain->ops[0];
                struct nlattr *nest;
@@ -1226,7 +1226,7 @@ static void nf_tables_chain_destroy(struct nft_chain *chain)
 {
        BUG_ON(chain->use > 0);
 
-       if (chain->flags & NFT_BASE_CHAIN) {
+       if (nft_is_base_chain(chain)) {
                struct nft_base_chain *basechain = nft_base_chain(chain);
 
                module_put(basechain->type->owner);
@@ -1364,8 +1364,8 @@ static int nf_tables_newchain(struct net *net, struct sock *nlsk,
        }
 
        if (nla[NFTA_CHAIN_POLICY]) {
-               if ((chain != NULL &&
-                   !(chain->flags & NFT_BASE_CHAIN)))
+               if (chain != NULL &&
+                   !nft_is_base_chain(chain))
                        return -EOPNOTSUPP;
 
                if (chain == NULL &&
@@ -1396,7 +1396,7 @@ static int nf_tables_newchain(struct net *net, struct sock *nlsk,
                        struct nft_chain_hook hook;
                        struct nf_hook_ops *ops;
 
-                       if (!(chain->flags & NFT_BASE_CHAIN))
+                       if (!nft_is_base_chain(chain))
                                return -EBUSY;
 
                        err = nft_chain_parse_hook(net, nla, afi, &hook,
@@ -1433,7 +1433,7 @@ static int nf_tables_newchain(struct net *net, struct sock *nlsk,
                }
 
                if (nla[NFTA_CHAIN_COUNTERS]) {
-                       if (!(chain->flags & NFT_BASE_CHAIN))
+                       if (!nft_is_base_chain(chain))
                                return -EOPNOTSUPP;
 
                        stats = nft_stats_alloc(nla[NFTA_CHAIN_COUNTERS]);
@@ -1772,8 +1772,19 @@ static int nf_tables_newexpr(const struct nft_ctx *ctx,
                        goto err1;
        }
 
+       if (ops->validate) {
+               const struct nft_data *data = NULL;
+
+               err = ops->validate(ctx, expr, &data);
+               if (err < 0)
+                       goto err2;
+       }
+
        return 0;
 
+err2:
+       if (ops->destroy)
+               ops->destroy(ctx, expr);
 err1:
        expr->ops = NULL;
        return err;
@@ -1874,10 +1885,9 @@ static int nf_tables_fill_rule_info(struct sk_buff *skb, struct net *net,
        const struct nft_expr *expr, *next;
        struct nlattr *list;
        const struct nft_rule *prule;
-       int type = event | NFNL_SUBSYS_NFTABLES << 8;
+       u16 type = nfnl_msg_type(NFNL_SUBSYS_NFTABLES, event);
 
-       nlh = nlmsg_put(skb, portid, seq, type, sizeof(struct nfgenmsg),
-                       flags);
+       nlh = nlmsg_put(skb, portid, seq, type, sizeof(struct nfgenmsg), flags);
        if (nlh == NULL)
                goto nla_put_failure;
 
@@ -2523,8 +2533,8 @@ static int nft_ctx_init_from_setattr(struct nft_ctx *ctx, struct net *net,
        return 0;
 }
 
-struct nft_set *nf_tables_set_lookup(const struct nft_table *table,
-                                    const struct nlattr *nla, u8 genmask)
+static struct nft_set *nf_tables_set_lookup(const struct nft_table *table,
+                                           const struct nlattr *nla, u8 genmask)
 {
        struct nft_set *set;
 
@@ -2538,11 +2548,10 @@ struct nft_set *nf_tables_set_lookup(const struct nft_table *table,
        }
        return ERR_PTR(-ENOENT);
 }
-EXPORT_SYMBOL_GPL(nf_tables_set_lookup);
 
-struct nft_set *nf_tables_set_lookup_byid(const struct net *net,
-                                         const struct nlattr *nla,
-                                         u8 genmask)
+static struct nft_set *nf_tables_set_lookup_byid(const struct net *net,
+                                                const struct nlattr *nla,
+                                                u8 genmask)
 {
        struct nft_trans *trans;
        u32 id = ntohl(nla_get_be32(nla));
@@ -2557,7 +2566,25 @@ struct nft_set *nf_tables_set_lookup_byid(const struct net *net,
        }
        return ERR_PTR(-ENOENT);
 }
-EXPORT_SYMBOL_GPL(nf_tables_set_lookup_byid);
+
+struct nft_set *nft_set_lookup(const struct net *net,
+                              const struct nft_table *table,
+                              const struct nlattr *nla_set_name,
+                              const struct nlattr *nla_set_id,
+                              u8 genmask)
+{
+       struct nft_set *set;
+
+       set = nf_tables_set_lookup(table, nla_set_name, genmask);
+       if (IS_ERR(set)) {
+               if (!nla_set_id)
+                       return set;
+
+               set = nf_tables_set_lookup_byid(net, nla_set_id, genmask);
+       }
+       return set;
+}
+EXPORT_SYMBOL_GPL(nft_set_lookup);
 
 static int nf_tables_set_alloc_name(struct nft_ctx *ctx, struct nft_set *set,
                                    const char *name)
@@ -2617,7 +2644,7 @@ static int nf_tables_fill_set(struct sk_buff *skb, const struct nft_ctx *ctx,
        u32 portid = ctx->portid;
        u32 seq = ctx->seq;
 
-       event |= NFNL_SUBSYS_NFTABLES << 8;
+       event = nfnl_msg_type(NFNL_SUBSYS_NFTABLES, event);
        nlh = nlmsg_put(skb, portid, seq, event, sizeof(struct nfgenmsg),
                        flags);
        if (nlh == NULL)
@@ -3145,7 +3172,6 @@ int nf_tables_bind_set(const struct nft_ctx *ctx, struct nft_set *set,
                iter.count      = 0;
                iter.err        = 0;
                iter.fn         = nf_tables_bind_check_setelem;
-               iter.flush      = false;
 
                set->ops->walk(ctx, set, &iter);
                if (iter.err < 0)
@@ -3368,8 +3394,7 @@ static int nf_tables_dump_set(struct sk_buff *skb, struct netlink_callback *cb)
        if (IS_ERR(set))
                return PTR_ERR(set);
 
-       event  = NFT_MSG_NEWSETELEM;
-       event |= NFNL_SUBSYS_NFTABLES << 8;
+       event  = nfnl_msg_type(NFNL_SUBSYS_NFTABLES, NFT_MSG_NEWSETELEM);
        portid = NETLINK_CB(cb->skb).portid;
        seq    = cb->nlh->nlmsg_seq;
 
@@ -3399,7 +3424,6 @@ static int nf_tables_dump_set(struct sk_buff *skb, struct netlink_callback *cb)
        args.iter.count         = 0;
        args.iter.err           = 0;
        args.iter.fn            = nf_tables_dump_setelem;
-       args.iter.flush         = false;
        set->ops->walk(&ctx, set, &args.iter);
 
        nla_nest_end(skb, nest);
@@ -3455,7 +3479,7 @@ static int nf_tables_fill_setelem_info(struct sk_buff *skb,
        struct nlattr *nest;
        int err;
 
-       event |= NFNL_SUBSYS_NFTABLES << 8;
+       event = nfnl_msg_type(NFNL_SUBSYS_NFTABLES, event);
        nlh = nlmsg_put(skb, portid, seq, event, sizeof(struct nfgenmsg),
                        flags);
        if (nlh == NULL)
@@ -3963,7 +3987,6 @@ static int nf_tables_delsetelem(struct net *net, struct sock *nlsk,
                struct nft_set_iter iter = {
                        .genmask        = genmask,
                        .fn             = nft_flush_set,
-                       .flush          = true,
                };
                set->ops->walk(&ctx, set, &iter);
 
@@ -4067,7 +4090,8 @@ static const struct nla_policy nft_obj_policy[NFTA_OBJ_MAX + 1] = {
        [NFTA_OBJ_DATA]         = { .type = NLA_NESTED },
 };
 
-static struct nft_object *nft_obj_init(const struct nft_object_type *type,
+static struct nft_object *nft_obj_init(const struct nft_ctx *ctx,
+                                      const struct nft_object_type *type,
                                       const struct nlattr *attr)
 {
        struct nlattr *tb[type->maxattr + 1];
@@ -4087,7 +4111,7 @@ static struct nft_object *nft_obj_init(const struct nft_object_type *type,
        if (obj == NULL)
                goto err1;
 
-       err = type->init((const struct nlattr * const *)tb, obj);
+       err = type->init(ctx, (const struct nlattr * const *)tb, obj);
        if (err < 0)
                goto err2;
 
@@ -4195,7 +4219,7 @@ static int nf_tables_newobj(struct net *net, struct sock *nlsk,
        if (IS_ERR(type))
                return PTR_ERR(type);
 
-       obj = nft_obj_init(type, nla[NFTA_OBJ_DATA]);
+       obj = nft_obj_init(&ctx, type, nla[NFTA_OBJ_DATA]);
        if (IS_ERR(obj)) {
                err = PTR_ERR(obj);
                goto err1;
@@ -4227,7 +4251,7 @@ static int nf_tables_fill_obj_info(struct sk_buff *skb, struct net *net,
        struct nfgenmsg *nfmsg;
        struct nlmsghdr *nlh;
 
-       event |= NFNL_SUBSYS_NFTABLES << 8;
+       event = nfnl_msg_type(NFNL_SUBSYS_NFTABLES, event);
        nlh = nlmsg_put(skb, portid, seq, event, sizeof(struct nfgenmsg), flags);
        if (nlh == NULL)
                goto nla_put_failure;
@@ -4500,7 +4524,7 @@ static int nf_tables_fill_gen_info(struct sk_buff *skb, struct net *net,
 {
        struct nlmsghdr *nlh;
        struct nfgenmsg *nfmsg;
-       int event = (NFNL_SUBSYS_NFTABLES << 8) | NFT_MSG_NEWGEN;
+       int event = nfnl_msg_type(NFNL_SUBSYS_NFTABLES, NFT_MSG_NEWGEN);
 
        nlh = nlmsg_put(skb, portid, seq, event, sizeof(struct nfgenmsg), 0);
        if (nlh == NULL)
@@ -4682,7 +4706,7 @@ static void nft_chain_commit_update(struct nft_trans *trans)
        if (nft_trans_chain_name(trans)[0])
                strcpy(trans->ctx.chain->name, nft_trans_chain_name(trans));
 
-       if (!(trans->ctx.chain->flags & NFT_BASE_CHAIN))
+       if (!nft_is_base_chain(trans->ctx.chain))
                return;
 
        basechain = nft_base_chain(trans->ctx.chain);
@@ -4996,7 +5020,7 @@ int nft_chain_validate_dependency(const struct nft_chain *chain,
 {
        const struct nft_base_chain *basechain;
 
-       if (chain->flags & NFT_BASE_CHAIN) {
+       if (nft_is_base_chain(chain)) {
                basechain = nft_base_chain(chain);
                if (basechain->type->type != type)
                        return -EOPNOTSUPP;
@@ -5010,7 +5034,7 @@ int nft_chain_validate_hooks(const struct nft_chain *chain,
 {
        struct nft_base_chain *basechain;
 
-       if (chain->flags & NFT_BASE_CHAIN) {
+       if (nft_is_base_chain(chain)) {
                basechain = nft_base_chain(chain);
 
                if ((1 << basechain->ops[0].hooknum) & hook_flags)
@@ -5114,7 +5138,6 @@ static int nf_tables_check_loops(const struct nft_ctx *ctx,
                        iter.count      = 0;
                        iter.err        = 0;
                        iter.fn         = nf_tables_loop_check_setelem;
-                       iter.flush      = false;
 
                        set->ops->walk(ctx, set, &iter);
                        if (iter.err < 0)
@@ -5320,7 +5343,7 @@ static int nft_verdict_init(const struct nft_ctx *ctx, struct nft_data *data,
                                               tb[NFTA_VERDICT_CHAIN], genmask);
                if (IS_ERR(chain))
                        return PTR_ERR(chain);
-               if (chain->flags & NFT_BASE_CHAIN)
+               if (nft_is_base_chain(chain))
                        return -EOPNOTSUPP;
 
                chain->use++;
@@ -5493,7 +5516,7 @@ int __nft_release_basechain(struct nft_ctx *ctx)
 {
        struct nft_rule *rule, *nr;
 
-       BUG_ON(!(ctx->chain->flags & NFT_BASE_CHAIN));
+       BUG_ON(!nft_is_base_chain(ctx->chain));
 
        nf_tables_unregister_hooks(ctx->net, ctx->chain->table, ctx->chain,
                                   ctx->afi->nops);