netfilter: ipset: merge uadd and udel functions

Both functions are using exactly the same code, except the command value
passed to call_ad function.

Signed-off-by: Florent Fourcot <florent.fourcot@wifirst.fr>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
This commit is contained in:
Florent Fourcot 2019-06-10 12:42:56 +02:00 committed by Jozsef Kadlecsik
parent 24c509b2e2
commit f0cb839084
1 changed files with 20 additions and 51 deletions

View File

@ -1561,10 +1561,12 @@ call_ad(struct sock *ctnl, struct sk_buff *skb, struct ip_set *set,
return ret; return ret;
} }
static int ip_set_uadd(struct net *net, struct sock *ctnl, struct sk_buff *skb, static int ip_set_ad(struct net *net, struct sock *ctnl,
const struct nlmsghdr *nlh, struct sk_buff *skb,
const struct nlattr * const attr[], enum ipset_adt adt,
struct netlink_ext_ack *extack) const struct nlmsghdr *nlh,
const struct nlattr * const attr[],
struct netlink_ext_ack *extack)
{ {
struct ip_set_net *inst = ip_set_pernet(net); struct ip_set_net *inst = ip_set_pernet(net);
struct ip_set *set; struct ip_set *set;
@ -1593,7 +1595,7 @@ static int ip_set_uadd(struct net *net, struct sock *ctnl, struct sk_buff *skb,
if (attr[IPSET_ATTR_DATA]) { if (attr[IPSET_ATTR_DATA]) {
if (nla_parse_nested_deprecated(tb, IPSET_ATTR_ADT_MAX, attr[IPSET_ATTR_DATA], set->type->adt_policy, NULL)) if (nla_parse_nested_deprecated(tb, IPSET_ATTR_ADT_MAX, attr[IPSET_ATTR_DATA], set->type->adt_policy, NULL))
return -IPSET_ERR_PROTOCOL; return -IPSET_ERR_PROTOCOL;
ret = call_ad(ctnl, skb, set, tb, IPSET_ADD, flags, ret = call_ad(ctnl, skb, set, tb, adt, flags,
use_lineno); use_lineno);
} else { } else {
int nla_rem; int nla_rem;
@ -1603,7 +1605,7 @@ static int ip_set_uadd(struct net *net, struct sock *ctnl, struct sk_buff *skb,
!flag_nested(nla) || !flag_nested(nla) ||
nla_parse_nested_deprecated(tb, IPSET_ATTR_ADT_MAX, nla, set->type->adt_policy, NULL)) nla_parse_nested_deprecated(tb, IPSET_ATTR_ADT_MAX, nla, set->type->adt_policy, NULL))
return -IPSET_ERR_PROTOCOL; return -IPSET_ERR_PROTOCOL;
ret = call_ad(ctnl, skb, set, tb, IPSET_ADD, ret = call_ad(ctnl, skb, set, tb, adt,
flags, use_lineno); flags, use_lineno);
if (ret < 0) if (ret < 0)
return ret; return ret;
@ -1612,55 +1614,22 @@ static int ip_set_uadd(struct net *net, struct sock *ctnl, struct sk_buff *skb,
return ret; return ret;
} }
static int ip_set_udel(struct net *net, struct sock *ctnl, struct sk_buff *skb, static int ip_set_uadd(struct net *net, struct sock *ctnl,
const struct nlmsghdr *nlh, struct sk_buff *skb, const struct nlmsghdr *nlh,
const struct nlattr * const attr[], const struct nlattr * const attr[],
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
struct ip_set_net *inst = ip_set_pernet(net); return ip_set_ad(net, ctnl, skb,
struct ip_set *set; IPSET_ADD, nlh, attr, extack);
struct nlattr *tb[IPSET_ATTR_ADT_MAX + 1] = {}; }
const struct nlattr *nla;
u32 flags = flag_exist(nlh);
bool use_lineno;
int ret = 0;
if (unlikely(protocol_min_failed(attr) || static int ip_set_udel(struct net *net, struct sock *ctnl,
!attr[IPSET_ATTR_SETNAME] || struct sk_buff *skb, const struct nlmsghdr *nlh,
!((attr[IPSET_ATTR_DATA] != NULL) ^ const struct nlattr * const attr[],
(attr[IPSET_ATTR_ADT] != NULL)) || struct netlink_ext_ack *extack)
(attr[IPSET_ATTR_DATA] && {
!flag_nested(attr[IPSET_ATTR_DATA])) || return ip_set_ad(net, ctnl, skb,
(attr[IPSET_ATTR_ADT] && IPSET_DEL, nlh, attr, extack);
(!flag_nested(attr[IPSET_ATTR_ADT]) ||
!attr[IPSET_ATTR_LINENO]))))
return -IPSET_ERR_PROTOCOL;
set = find_set(inst, nla_data(attr[IPSET_ATTR_SETNAME]));
if (!set)
return -ENOENT;
use_lineno = !!attr[IPSET_ATTR_LINENO];
if (attr[IPSET_ATTR_DATA]) {
if (nla_parse_nested_deprecated(tb, IPSET_ATTR_ADT_MAX, attr[IPSET_ATTR_DATA], set->type->adt_policy, NULL))
return -IPSET_ERR_PROTOCOL;
ret = call_ad(ctnl, skb, set, tb, IPSET_DEL, flags,
use_lineno);
} else {
int nla_rem;
nla_for_each_nested(nla, attr[IPSET_ATTR_ADT], nla_rem) {
if (nla_type(nla) != IPSET_ATTR_DATA ||
!flag_nested(nla) ||
nla_parse_nested_deprecated(tb, IPSET_ATTR_ADT_MAX, nla, set->type->adt_policy, NULL))
return -IPSET_ERR_PROTOCOL;
ret = call_ad(ctnl, skb, set, tb, IPSET_DEL,
flags, use_lineno);
if (ret < 0)
return ret;
}
}
return ret;
} }
static int ip_set_utest(struct net *net, struct sock *ctnl, struct sk_buff *skb, static int ip_set_utest(struct net *net, struct sock *ctnl, struct sk_buff *skb,