@@ -1561,10 +1561,12 @@ call_ad(struct sock *ctnl, struct sk_buff *skb, struct ip_set *set,
15611561 return ret ;
15621562}
15631563
1564- static int ip_set_uadd (struct net * net , struct sock * ctnl , struct sk_buff * skb ,
1565- const struct nlmsghdr * nlh ,
1566- const struct nlattr * const attr [],
1567- struct netlink_ext_ack * extack )
1564+ static int ip_set_ad (struct net * net , struct sock * ctnl ,
1565+ struct sk_buff * skb ,
1566+ enum ipset_adt adt ,
1567+ const struct nlmsghdr * nlh ,
1568+ const struct nlattr * const attr [],
1569+ struct netlink_ext_ack * extack )
15681570{
15691571 struct ip_set_net * inst = ip_set_pernet (net );
15701572 struct ip_set * set ;
@@ -1593,7 +1595,7 @@ static int ip_set_uadd(struct net *net, struct sock *ctnl, struct sk_buff *skb,
15931595 if (attr [IPSET_ATTR_DATA ]) {
15941596 if (nla_parse_nested_deprecated (tb , IPSET_ATTR_ADT_MAX , attr [IPSET_ATTR_DATA ], set -> type -> adt_policy , NULL ))
15951597 return - IPSET_ERR_PROTOCOL ;
1596- ret = call_ad (ctnl , skb , set , tb , IPSET_ADD , flags ,
1598+ ret = call_ad (ctnl , skb , set , tb , adt , flags ,
15971599 use_lineno );
15981600 } else {
15991601 int nla_rem ;
@@ -1603,7 +1605,7 @@ static int ip_set_uadd(struct net *net, struct sock *ctnl, struct sk_buff *skb,
16031605 !flag_nested (nla ) ||
16041606 nla_parse_nested_deprecated (tb , IPSET_ATTR_ADT_MAX , nla , set -> type -> adt_policy , NULL ))
16051607 return - IPSET_ERR_PROTOCOL ;
1606- ret = call_ad (ctnl , skb , set , tb , IPSET_ADD ,
1608+ ret = call_ad (ctnl , skb , set , tb , adt ,
16071609 flags , use_lineno );
16081610 if (ret < 0 )
16091611 return ret ;
@@ -1612,55 +1614,22 @@ static int ip_set_uadd(struct net *net, struct sock *ctnl, struct sk_buff *skb,
16121614 return ret ;
16131615}
16141616
1615- static int ip_set_udel (struct net * net , struct sock * ctnl , struct sk_buff * skb ,
1616- const struct nlmsghdr * nlh ,
1617+ static int ip_set_uadd (struct net * net , struct sock * ctnl ,
1618+ struct sk_buff * skb , const struct nlmsghdr * nlh ,
16171619 const struct nlattr * const attr [],
16181620 struct netlink_ext_ack * extack )
16191621{
1620- struct ip_set_net * inst = ip_set_pernet (net );
1621- struct ip_set * set ;
1622- struct nlattr * tb [IPSET_ATTR_ADT_MAX + 1 ] = {};
1623- const struct nlattr * nla ;
1624- u32 flags = flag_exist (nlh );
1625- bool use_lineno ;
1626- int ret = 0 ;
1627-
1628- if (unlikely (protocol_min_failed (attr ) ||
1629- !attr [IPSET_ATTR_SETNAME ] ||
1630- !((attr [IPSET_ATTR_DATA ] != NULL ) ^
1631- (attr [IPSET_ATTR_ADT ] != NULL )) ||
1632- (attr [IPSET_ATTR_DATA ] &&
1633- !flag_nested (attr [IPSET_ATTR_DATA ])) ||
1634- (attr [IPSET_ATTR_ADT ] &&
1635- (!flag_nested (attr [IPSET_ATTR_ADT ]) ||
1636- !attr [IPSET_ATTR_LINENO ]))))
1637- return - IPSET_ERR_PROTOCOL ;
1638-
1639- set = find_set (inst , nla_data (attr [IPSET_ATTR_SETNAME ]));
1640- if (!set )
1641- return - ENOENT ;
1642-
1643- use_lineno = !!attr [IPSET_ATTR_LINENO ];
1644- if (attr [IPSET_ATTR_DATA ]) {
1645- if (nla_parse_nested_deprecated (tb , IPSET_ATTR_ADT_MAX , attr [IPSET_ATTR_DATA ], set -> type -> adt_policy , NULL ))
1646- return - IPSET_ERR_PROTOCOL ;
1647- ret = call_ad (ctnl , skb , set , tb , IPSET_DEL , flags ,
1648- use_lineno );
1649- } else {
1650- int nla_rem ;
1622+ return ip_set_ad (net , ctnl , skb ,
1623+ IPSET_ADD , nlh , attr , extack );
1624+ }
16511625
1652- nla_for_each_nested (nla , attr [IPSET_ATTR_ADT ], nla_rem ) {
1653- if (nla_type (nla ) != IPSET_ATTR_DATA ||
1654- !flag_nested (nla ) ||
1655- nla_parse_nested_deprecated (tb , IPSET_ATTR_ADT_MAX , nla , set -> type -> adt_policy , NULL ))
1656- return - IPSET_ERR_PROTOCOL ;
1657- ret = call_ad (ctnl , skb , set , tb , IPSET_DEL ,
1658- flags , use_lineno );
1659- if (ret < 0 )
1660- return ret ;
1661- }
1662- }
1663- return ret ;
1626+ static int ip_set_udel (struct net * net , struct sock * ctnl ,
1627+ struct sk_buff * skb , const struct nlmsghdr * nlh ,
1628+ const struct nlattr * const attr [],
1629+ struct netlink_ext_ack * extack )
1630+ {
1631+ return ip_set_ad (net , ctnl , skb ,
1632+ IPSET_DEL , nlh , attr , extack );
16641633}
16651634
16661635static int ip_set_utest (struct net * net , struct sock * ctnl , struct sk_buff * skb ,
0 commit comments