Patch for ipset/setlist
Hello.
This patch adds ‘—matchall’ argument to setlist. By default, setlist returns true if packet match to any of it members. With –matchall packet must match to every member of setlist.
This is my first patch, so sorry if I do something wrong. Comments are welcome.
Piotr Piróg
ipset_setlist.c +13 -2
@@ -32,6 +32,7 @@ setlist_create_init(void *data)struct ip_set_req_setlist_create *mydata = data; mydata->size =8 ; + mydata->matchall =0 ; }/* Function which parses command options; returns true if it ate an option */
@@ -50,6 +51,9 @@ setlist_create_parse(int c, char *argv[] "between 1-255", optarg); mydata->size = size;break ; +case '2' : + mydata->matchall =1 ; +break ;default :return 0 ; }
@@ -65,6 +69,7 @@ setlist_create_final(void *data UNUSED,/* Create commandline options */ static const struct option create_opts[] = { {.name ="size" , .has_arg = required_argument, .val ='1' }, + {.name ="matchall" , .has_arg = no_argument, .val ='2' }, {NULL }, };
@@ -124,6 +129,7 @@ setlist_initheader(struct set *set, consmemset (map,0 ,sizeof (struct ip_set_setlist )); map->size = header->size; + map->matchall = header->matchall; } static void
@@ -131,6 +137,8 @@ setlist_printheader(struct set *set, uns {struct ip_set_setlist *mysetdata = set->settype->header; +if (mysetdata->matchall ==1 ) +printf (" matchall" );printf (" size: %u\n" , mysetdata->size); }
@@ -161,9 +169,12 @@ setlist_saveheader(struct set *set, unsi {struct ip_set_setlist *mysetdata = set->settype->header; -printf ("-N %s %s --size %u\n" , +printf ("-N %s %s --size %u" , set->name, set->settype->typename, mysetdata->size); +if (mysetdata->matchall ==1 ) +printf (" --matchall" ); +printf ("\n" ); } static void
@@ -189,7 +200,7 @@ static voidsetlist_usage (void) {printf - ("-N set setlist --size size\n" + ("-N set setlist --size size [--matchall]\n" "-A set setname[,before|after,setname]\n" "-D set setname\n" "-T set setname\n" );
diff -pruN ipset-4.2.orig/kernel/include/linux/netfilter_ipv4/ip_set_setlist.h ipset-4.2/kernel/include/linux/netfilter_ipv4/ip_set_setlist.h
--- ipset-4.2.orig/kernel/include/linux/netfilter_ipv4/ip_set_setlist.h 2010-03-18
14:59:54.000000000 +0100
+++ ipset-4.2/kernel/include/linux/netfilter_ipv4/ip_set_setlist.h 2010-03-18
19:02:42.000000000 +0100
@@ -10,11 +10,13 @@
struct ip_set_setlist {
uint8_t size;
+ uint8_t matchall;
ip_set_id_t index[0];
};
struct ip_set_req_setlist_create {
uint8_t size;
+ uint8_t matchall;
};
struct ip_set_req_setlist {
diff -pruN ipset-4.2.orig/kernel/ip_set_setlist.cipset-4.2/kernel/ip_set_setlist.c
kernel/ip_set_setlist.c +4 -2
@@ -75,11 +75,11 @@ setlist_ktest(struct ip_set *set, const u_int32_t *flags) {struct ip_set_setlist *map = set->data; -int i, res =0 ; +int i, res = map->matchall;for (i =0 ; i < map->size && map->index[i] !=IP_SET_INVALID_ID - && res ==0 ; i++) + && res == map->matchall; i++) res =ip_set_testip_kernel (map->index[i], skb, flags);return res; }
@@ -251,6 +251,7 @@ setlist_create(struct ip_set *set, constif (!map)return -ENOMEM ; map->size = req->size; + map->matchall = req->matchall;for (i =0 ; i < map->size; i++) map->index[i] =IP_SET_INVALID_ID ;
@@ -292,6 +293,7 @@ setlist_list_header(const struct ip_setstruct ip_set_req_setlist_create *header = data; header->size = map->size; + header->matchall = map->matchall; } static int
--
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi,
Quoted 4 lines · Piotr Pir?g
This patch adds ??matchall? argument to setlist. By default, setlist returns true if packet match to any of it members. With ?matchall packet must match to every member of setlist.
This is my first patch, so sorry if I do something wrong. Comments are welcome.
Could you write an example where it is useful? I can't figure out how could it be used.
Best regards,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : KFKI Research Institute for Particle and Nuclear Physics
H-1525 Budapest 114, POB. 49, Hungary