ipset: Add net namespace for ipset
Subsystems (3)
PATCH 1/1 ipset: Add net namespace for ipset
This patch adds netns support for ipset.
Major changes were made in ip_set_core.c and ip_set.h.Added the initialization and destruction of the network namespace for ipset subsystem.
In the prototypes of public functions ip_set added parameter "struct net*".
The remaining corrections related to the change prototypes of public functions ip_set_xxx.
The patch was developed for the kernel 3.10.10 (ipset not changed in .11 and .12).
--include/linux/netfilter/ipset/ip_set.h | 16 +-- net/netfilter/ipset/ip_set_bitmap_ip.c | 3 +- net/netfilter/ipset/ip_set_bitmap_ipmac.c | 2 +- net/netfilter/ipset/ip_set_bitmap_port.c | 3 +- net/netfilter/ipset/ip_set_core.c | 282 ++++++++++++++++++++++++++++++---------------- net/netfilter/ipset/ip_set_hash_gen.h | 3 +- net/netfilter/ipset/ip_set_list_set.c | 26 +++--net/netfilter/xt_set.c | 40 +++----net/sched/em_ipset.c | 7 +-
9 files changed, 238 insertions(+), 144 deletions(-)
include/linux/netfilter/ipset/ip_set.h +9 -7
@@ -147,7 +147,8 @@ struct ip_set_type {u8 revision_min, revision_max;/* Create set */ -int (*create)(struct ip_set *set,struct nlattr *tb[],u32 flags); +int (*create)(struct net *net, +struct ip_set *set,struct nlattr *tb[],u32 flags);/* Attribute policies */ const struct nla_policy create_policy[IPSET_ATTR_CREATE_MAX +1 ];
@@ -248,12 +249,13 @@ ip_set_init_counter(struct ip_set_counter *counter, }/* register and unregister set references */ -extern ip_set_id_t ip_set_get_byname (const char *name,struct ip_set **set); -extern void ip_set_put_byindex (ip_set_id_t index); -extern const char *ip_set_name_byindex (ip_set_id_t index); -extern ip_set_id_t ip_set_nfnl_get (const char *name); -extern ip_set_id_t ip_set_nfnl_get_byindex (ip_set_id_t index); -extern void ip_set_nfnl_put (ip_set_id_t index); +extern ip_set_id_t ip_set_get_byname (struct net *net, +const char *name,struct ip_set **set); +extern void ip_set_put_byindex (struct net *net,ip_set_id_t index); +extern const char *ip_set_name_byindex (struct net *net,ip_set_id_t index); +extern ip_set_id_t ip_set_nfnl_get (struct net *net,const char *name); +extern ip_set_id_t ip_set_nfnl_get_byindex (struct net *net,ip_set_id_t index); +extern void ip_set_nfnl_put (struct net *net,ip_set_id_t index);/* API for iptables set match, and SET target */
net/netfilter/ipset/ip_set_bitmap_ip.c +2 -1
@@ -261,7 +261,8 @@ init_map_ip(struct ip_set *set, struct bitmap_ip *map, }static int -bitmap_ip_create (struct ip_set *set,struct nlattr *tb[],u32 flags) +bitmap_ip_create (struct net *net, +struct ip_set *set,struct nlattr *tb[],u32 flags) {struct bitmap_ip *map;u32 first_ip, last_ip, hosts, cadt_flags =0 ;
net/netfilter/ipset/ip_set_bitmap_ipmac.c +1 -1
@@ -352,7 +352,7 @@ init_map_ipmac(struct ip_set *set, struct bitmap_ipmac *map, }static int -bitmap_ipmac_create (struct ip_set *set,struct nlattr *tb[], +bitmap_ipmac_create (struct net *net,struct ip_set *set,struct nlattr *tb[],u32 flags) {u32 first_ip, last_ip, cadt_flags =0 ;
net/netfilter/ipset/ip_set_bitmap_port.c +2 -1
@@ -248,7 +248,8 @@ init_map_port(struct ip_set *set, struct bitmap_port *map, }static int -bitmap_port_create (struct ip_set *set,struct nlattr *tb[],u32 flags) +bitmap_port_create (struct net *net, +struct ip_set *set,struct nlattr *tb[],u32 flags) {struct bitmap_port *map;u16 first_port, last_port;
net/netfilter/ipset/ip_set_core.c +183 -99
712 lines not on this page · raw message
net/netfilter/ipset/ip_set_hash_gen.h +2 -1
@@ -942,7 +942,8 @@ static const struct ip_set_type_variant mtype_variant = {#ifdef IP_SET_EMIT_CREATE static int -TOKEN (HTYPE ,_create )(struct ip_set *set,struct nlattr *tb[],u32 flags) +TOKEN (HTYPE ,_create )(struct net *net, +struct ip_set *set,struct nlattr *tb[],u32 flags) {u32 hashsize =IPSET_DEFAULT_HASHSIZE , maxelem =IPSET_DEFAULT_MAXELEM ;u32 cadt_flags =0 ;
net/netfilter/ipset/ip_set_list_set.c +15 -11
@@ -63,6 +63,7 @@ struct list_set {u32 size;/* size of set list array */ u32 timeout;/* timeout value */ struct timer_list gc;/* garbage collection */ +struct net *net;/* namespace */ struct set_elem members[0 ];/* the set members */ };
@@ -204,13 +205,13 @@ list_set_add(struct ip_set *set, u32 i, struct set_adt_elem *d,if (e->id !=IPSET_INVALID_ID ) {if (i == map->size -1 )/* Last element replaced: e.g. add new,before,last */ -ip_set_put_byindex (e->id); +ip_set_put_byindex (map->net, e->id);else {struct set_elem *x =list_set_elem (map, map->size -1 );/* Last element pushed off */ if (x->id !=IPSET_INVALID_ID ) -ip_set_put_byindex (x->id); +ip_set_put_byindex (map->net, x->id);memmove (list_set_elem (map, i +1 ), e, map->dsize * (map->size - (i +1 ))); }
@@ -230,7 +231,7 @@ list_set_del(struct ip_set *set, u32 i)struct list_set *map = set->data;struct set_elem *e =list_set_elem (map, i); -ip_set_put_byindex (e->id); +ip_set_put_byindex (map->net, e->id);if (i < map->size -1 ) memmove(e, list_set_elem(map, i + 1),
@@ -324,7 +325,7 @@ list_set_uadd(struct ip_set *set, void *value, const struct ip_set_ext *ext,if (SET_WITH_COUNTER (set))ip_set_init_counter (ext_counter (e, map), ext);/* Set is already added to the list */ -ip_set_put_byindex (d->id); +ip_set_put_byindex (map->net, d->id);return 0 ; } insert:
@@ -403,7 +404,7 @@ list_set_uadt(struct ip_set *set, struct nlattr *tb[], ret =ip_set_get_extensions (set, tb, &ext);if (ret)return ret; - e.id =ip_set_get_byname (nla_data (tb[IPSET_ATTR_NAME ]), &s); + e.id =ip_set_get_byname (map->net,nla_data (tb[IPSET_ATTR_NAME ]), &s);if (e.id ==IPSET_INVALID_ID )return -IPSET_ERR_NAME ;/* "Loop detection" */
@@ -423,7 +424,8 @@ list_set_uadt(struct ip_set *set, struct nlattr *tb[], }if (tb[IPSET_ATTR_NAMEREF ]) { - e.refid =ip_set_get_byname (nla_data (tb[IPSET_ATTR_NAMEREF ]), + e.refid =ip_set_get_byname (map->net, +nla_data (tb[IPSET_ATTR_NAMEREF ]), &s);if (e.refid ==IPSET_INVALID_ID ) { ret = -IPSET_ERR_NAMEREF ;
@@ -439,9 +441,9 @@ list_set_uadt(struct ip_set *set, struct nlattr *tb[], finish:if (e.refid !=IPSET_INVALID_ID ) -ip_set_put_byindex (e.refid); +ip_set_put_byindex (map->net, e.refid);if (adt !=IPSET_ADD || ret) -ip_set_put_byindex (e.id); +ip_set_put_byindex (map->net, e.id);return ip_set_eexist (ret, flags) ?0 : ret; }
@@ -456,7 +458,7 @@ list_set_flush(struct ip_set *set)for (i =0 ; i < map->size; i++) { e =list_set_elem (map, i);if (e->id !=IPSET_INVALID_ID ) { -ip_set_put_byindex (e->id); +ip_set_put_byindex (map->net, e->id); e->id =IPSET_INVALID_ID ; } }
@@ -530,7 +532,7 @@ list_set_list(const struct ip_set *set, goto nla_put_failure; }if (nla_put_string (skb,IPSET_ATTR_NAME , -ip_set_name_byindex (e->id))) +ip_set_name_byindex (map->net, e->id))) goto nla_put_failure;if (SET_WITH_TIMEOUT (set) && nla_put_net32(skb, IPSET_ATTR_TIMEOUT,
@@ -638,7 +640,8 @@ init_list_set(struct ip_set *set, u32 size, size_t dsize, }static int -list_set_create (struct ip_set *set,struct nlattr *tb[],u32 flags) +list_set_create (struct net *net, +struct ip_set *set,struct nlattr *tb[],u32 flags) {struct list_set *map;u32 size =IP_SET_LIST_DEFAULT_SIZE , cadt_flags =0 ;
@@ -694,6 +697,7 @@ list_set_create(struct ip_set *set, struct nlattr *tb[], u32 flags)if (!map)return -ENOMEM ; } + map->net = net;return 0 ; }
net/netfilter/xt_set.c +20 -20
@@ -81,7 +81,7 @@ set_match_v0_checkentry(const struct xt_mtchk_param *par)struct xt_set_info_match_v0 *info = par->matchinfo;ip_set_id_t index; - index =ip_set_nfnl_get_byindex (info->match_set.index); + index =ip_set_nfnl_get_byindex (par->net, info->match_set.index);if (index ==IPSET_INVALID_ID ) { pr_warning("Cannot find set indentified by id %u to match\n",
@@ -91,7 +91,7 @@ set_match_v0_checkentry(const struct xt_mtchk_param *par)if (info->match_set.u.flags[IPSET_DIM_MAX -1 ] !=0 ) {pr_warning ("Protocol error: set match dimension " "is over the limit!\n" ); -ip_set_nfnl_put (info->match_set.index); +ip_set_nfnl_put (par->net, info->match_set.index);return -ERANGE ; }
@@ -106,7 +106,7 @@ set_match_v0_destroy(const struct xt_mtdtor_param *par) {struct xt_set_info_match_v0 *info = par->matchinfo; -ip_set_nfnl_put (info->match_set.index); +ip_set_nfnl_put (par->net, info->match_set.index); } static unsigned int
@@ -133,7 +133,7 @@ set_target_v0_checkentry(const struct xt_tgchk_param *par)ip_set_id_t index;if (info->add_set.index !=IPSET_INVALID_ID ) { - index =ip_set_nfnl_get_byindex (info->add_set.index); + index =ip_set_nfnl_get_byindex (par->net, info->add_set.index);if (index ==IPSET_INVALID_ID ) {pr_warning ("Cannot find add_set index %u as target\n" , info->add_set.index);
@@ -142,12 +142,12 @@ set_target_v0_checkentry(const struct xt_tgchk_param *par) }if (info->del_set.index !=IPSET_INVALID_ID ) { - index =ip_set_nfnl_get_byindex (info->del_set.index); + index =ip_set_nfnl_get_byindex (par->net, info->del_set.index);if (index ==IPSET_INVALID_ID ) {pr_warning ("Cannot find del_set index %u as target\n" , info->del_set.index);if (info->add_set.index !=IPSET_INVALID_ID ) -ip_set_nfnl_put (info->add_set.index); +ip_set_nfnl_put (par->net, info->add_set.index);return -ENOENT ; } }
@@ -156,9 +156,9 @@ set_target_v0_checkentry(const struct xt_tgchk_param *par)pr_warning ("Protocol error: SET target dimension " "is over the limit!\n" );if (info->add_set.index !=IPSET_INVALID_ID ) -ip_set_nfnl_put (info->add_set.index); +ip_set_nfnl_put (par->net, info->add_set.index);if (info->del_set.index !=IPSET_INVALID_ID ) -ip_set_nfnl_put (info->del_set.index); +ip_set_nfnl_put (par->net, info->del_set.index);return -ERANGE ; }
@@ -175,9 +175,9 @@ set_target_v0_destroy(const struct xt_tgdtor_param *par)const struct xt_set_info_target_v0 *info = par->targinfo;if (info->add_set.index !=IPSET_INVALID_ID ) -ip_set_nfnl_put (info->add_set.index); +ip_set_nfnl_put (par->net, info->add_set.index);if (info->del_set.index !=IPSET_INVALID_ID ) -ip_set_nfnl_put (info->del_set.index); +ip_set_nfnl_put (par->net, info->del_set.index); }/* Revision 1 match and target */
@@ -202,7 +202,7 @@ set_match_v1_checkentry(const struct xt_mtchk_param *par)struct xt_set_info_match_v1 *info = par->matchinfo;ip_set_id_t index; - index =ip_set_nfnl_get_byindex (info->match_set.index); + index =ip_set_nfnl_get_byindex (par->net, info->match_set.index);if (index ==IPSET_INVALID_ID ) { pr_warning("Cannot find set indentified by id %u to match\n",
@@ -212,7 +212,7 @@ set_match_v1_checkentry(const struct xt_mtchk_param *par)if (info->match_set.dim >IPSET_DIM_MAX ) {pr_warning ("Protocol error: set match dimension " "is over the limit!\n" ); -ip_set_nfnl_put (info->match_set.index); +ip_set_nfnl_put (par->net, info->match_set.index);return -ERANGE ; }
@@ -224,7 +224,7 @@ set_match_v1_destroy(const struct xt_mtdtor_param *par) {struct xt_set_info_match_v1 *info = par->matchinfo; -ip_set_nfnl_put (info->match_set.index); +ip_set_nfnl_put (par->net, info->match_set.index); } static unsigned int
@@ -251,7 +251,7 @@ set_target_v1_checkentry(const struct xt_tgchk_param *par)ip_set_id_t index;if (info->add_set.index !=IPSET_INVALID_ID ) { - index =ip_set_nfnl_get_byindex (info->add_set.index); + index =ip_set_nfnl_get_byindex (par->net, info->add_set.index);if (index ==IPSET_INVALID_ID ) {pr_warning ("Cannot find add_set index %u as target\n" , info->add_set.index);
@@ -260,12 +260,12 @@ set_target_v1_checkentry(const struct xt_tgchk_param *par) }if (info->del_set.index !=IPSET_INVALID_ID ) { - index =ip_set_nfnl_get_byindex (info->del_set.index); + index =ip_set_nfnl_get_byindex (par->net, info->del_set.index);if (index ==IPSET_INVALID_ID ) {pr_warning ("Cannot find del_set index %u as target\n" , info->del_set.index);if (info->add_set.index !=IPSET_INVALID_ID ) -ip_set_nfnl_put (info->add_set.index); +ip_set_nfnl_put (par->net, info->add_set.index);return -ENOENT ; } }
@@ -274,9 +274,9 @@ set_target_v1_checkentry(const struct xt_tgchk_param *par)pr_warning ("Protocol error: SET target dimension " "is over the limit!\n" );if (info->add_set.index !=IPSET_INVALID_ID ) -ip_set_nfnl_put (info->add_set.index); +ip_set_nfnl_put (par->net, info->add_set.index);if (info->del_set.index !=IPSET_INVALID_ID ) -ip_set_nfnl_put (info->del_set.index); +ip_set_nfnl_put (par->net, info->del_set.index);return -ERANGE ; }
@@ -289,9 +289,9 @@ set_target_v1_destroy(const struct xt_tgdtor_param *par)const struct xt_set_info_target_v1 *info = par->targinfo;if (info->add_set.index !=IPSET_INVALID_ID ) -ip_set_nfnl_put (info->add_set.index); +ip_set_nfnl_put (par->net, info->add_set.index);if (info->del_set.index !=IPSET_INVALID_ID ) -ip_set_nfnl_put (info->del_set.index); +ip_set_nfnl_put (par->net, info->del_set.index); }/* Revision 2 target */
net/sched/em_ipset.c +4 -3
@@ -24,11 +24,12 @@ static int em_ipset_change(struct tcf_proto *tp, void *data, int data_len, {struct xt_set_info *set = data;ip_set_id_t index; +struct net *net =qdisc_dev (tp->q)->nd_net;if (data_len !=sizeof (*set))return -EINVAL ; - index =ip_set_nfnl_get_byindex (set->index); + index =ip_set_nfnl_get_byindex (net, set->index);if (index ==IPSET_INVALID_ID )return -ENOENT ;
@@ -37,7 +38,7 @@ static int em_ipset_change(struct tcf_proto *tp, void *data, int data_len,if (em->data)return 0 ; -ip_set_nfnl_put (index); +ip_set_nfnl_put (net, index);return -ENOMEM ; }
@@ -45,7 +46,7 @@ static void em_ipset_destroy(struct tcf_proto *p, struct tcf_ematch *em) {const struct xt_set_info *set = (const void *) em->data;if (set) { -ip_set_nfnl_put (set->index); +ip_set_nfnl_put (qdisc_dev (p->q)->nd_net, set->index);kfree ((void *) em->data); } }
Hi,
Quoted 7 lines · V. Lavrov
This patch adds netns support for ipset.
Major changes were made in
ip_set_core.cand ip_set.h.Added the initialization and
destruction of the network namespace for ipset subsystem.
In the prototypes of public functionsip_setadded parameter "struct net*".
Quoted 5 lines
The remaining corrections related to the change prototypes of public functions
ip_set_xxx.The patch was developed for the kernel 3.10.10 (ipset not changed in .11 and .12).
The patch looks OK, however please rebase it using the ipset git tree. There was a couple of changes and your patch cannot be applied.
I'll work on to solve the backward incompatibility with the supported kernel version where there was no netns at all.
Best regards,
Jozsef
Quoted 12 lines
Signed-off-by Vitaly Lavrov <[email protected]>--
include/linux/netfilter/ipset/ip_set.h| 16 +--net/netfilter/ipset/ip_set_bitmap_ip.c| 3 +-net/netfilter/ipset/ip_set_bitmap_ipmac.c| 2 +-net/netfilter/ipset/ip_set_bitmap_port.c| 3 +-net/netfilter/ipset/ip_set_core.c| 282
++++++++++++++++++++++++++++++----------------net/netfilter/ipset/ip_set_hash_gen.h| 3 +-net/netfilter/ipset/ip_set_list_set.c| 26 +++--net/netfilter/xt_set.c| 40 +++----net/sched/em_ipset.c| 7 +-
Quoted 4 lines
9 files changed, 238 insertions(+), 144 deletions(-)
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : Wigner Research Centre for Physics, Hungarian Academy of Sciences
H-1525 Budapest 114, POB. 49, Hungary