]> granicus.if.org Git - ipset/commitdiff
Propagate "expose userspace-relevant parts in ip_set.h" to ipset source
authorJozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Wed, 31 Aug 2011 13:56:34 +0000 (15:56 +0200)
committerJozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Wed, 31 Aug 2011 13:56:34 +0000 (15:56 +0200)
With the header file restructuring, the ipset userspace enums IPSET_DIM_*
clash with the kernel ones. In this patch the userspace is converted to
use the kernel part enums and thus we got rid of userspace enums IPSET_DIM_*.

15 files changed:
include/libipset/linux_ip_set.h
include/libipset/types.h
lib/parse.c
lib/print.c
src/ipset_bitmap_ip.c
src/ipset_bitmap_ipmac.c
src/ipset_bitmap_port.c
src/ipset_hash_ip.c
src/ipset_hash_ipport.c
src/ipset_hash_ipportip.c
src/ipset_hash_ipportnet.c
src/ipset_hash_net.c
src/ipset_hash_netiface.c
src/ipset_hash_netport.c
src/ipset_list_set.c

index fb4b69e9ea776c76de1ef00c2c45d22d8ea541d8..b336d43c7e8d4dd6f65f9c0e1a65f241e6c84aa1 100644 (file)
@@ -11,6 +11,8 @@
  * published by the Free Software Foundation.
  */
 
+#include <linux/types.h>
+
 /* The protocol version */
 #define IPSET_PROTOCOL         6
 
@@ -168,4 +170,30 @@ enum ipset_adt {
        IPSET_CADT_MAX,
 };
 
+/* Sets are identified by an index in kernel space. Tweak with ip_set_id_t
+ * and IPSET_INVALID_ID if you want to increase the max number of sets.
+ */
+typedef __u16 ip_set_id_t;
+
+#define IPSET_INVALID_ID               65535
+
+enum ip_set_dim {
+       IPSET_DIM_ZERO = 0,
+       IPSET_DIM_ONE,
+       IPSET_DIM_TWO,
+       IPSET_DIM_THREE,
+       /* Max dimension in elements.
+        * If changed, new revision of iptables match/target is required.
+        */
+       IPSET_DIM_MAX = 6,
+};
+
+/* Option flags for kernel operations */
+enum ip_set_kopt {
+       IPSET_INV_MATCH = (1 << IPSET_DIM_ZERO),
+       IPSET_DIM_ONE_SRC = (1 << IPSET_DIM_ONE),
+       IPSET_DIM_TWO_SRC = (1 << IPSET_DIM_TWO),
+       IPSET_DIM_THREE_SRC = (1 << IPSET_DIM_THREE),
+};
+
 #endif /* __IP_SET_H */
index d3a0b4ca85e0e12c5f9d70eb59a711e17f344250..d2801f16ac1b6e640d2b9b4a2844df14177dd271 100644 (file)
  * - AF_INET46:        type supports both IPv4 and IPv6
  */
 
-/* Set dimensions */
-enum {
-       IPSET_DIM_ONE,                  /* foo */
-       IPSET_DIM_TWO,                  /* foo,bar */
-       IPSET_DIM_THREE,                /* foo,bar,fie */
-       IPSET_DIM_MAX,
-};
+/* The maximal type dimension userspace supports */
+#define IPSET_DIM_UMAX         3
 
 /* Parser options */
 enum {
@@ -76,7 +71,7 @@ struct ipset_type {
        uint8_t dimension;                      /* elem dimension */
        int8_t kernel_check;                    /* kernel check */
        bool last_elem_optional;                /* last element optional */
-       struct ipset_elem elem[IPSET_DIM_MAX];  /* parse elem */
+       struct ipset_elem elem[IPSET_DIM_UMAX]; /* parse elem */
        ipset_parsefn compat_parse_elem;        /* compatibility parser */
        const struct ipset_arg *args[IPSET_CADT_MAX]; /* create/ADT args besides elem */
        uint64_t mandatory[IPSET_CADT_MAX];     /* create/ADT mandatory flags */
index 2bb0601b10173d570954138cce2c344fd57901db..1aaf072a754990fb9cf617b43dd6cafe7098ae46 100644 (file)
@@ -1525,9 +1525,9 @@ ipset_call_parser(struct ipset_session *session,
 
 #define parse_elem(s, t, d, str)                                       \
 do {                                                                   \
-       if (!(t)->elem[d].parse)                                        \
+       if (!(t)->elem[d - 1].parse)                                    \
                goto internal;                                          \
-       ret = (t)->elem[d].parse(s, (t)->elem[d].opt, str);             \
+       ret = (t)->elem[d - 1].parse(s, (t)->elem[d - 1].opt, str);     \
        if (ret)                                                        \
                goto out;                                               \
 } while (0)
@@ -1582,7 +1582,7 @@ ipset_parse_elem(struct ipset_session *session,
        } else if (a != NULL) {
                if (type->compat_parse_elem) {
                        ret = type->compat_parse_elem(session,
-                                       type->elem[IPSET_DIM_ONE].opt,
+                                       type->elem[IPSET_DIM_ONE - 1].opt,
                                        saved);
                        goto out;
                }
index 6452ab52d93ee06c7ec274715c94aa3176cf81f6..96c19a1eaad6eed63f3092a918dc116f68f6d990 100644 (file)
@@ -705,30 +705,30 @@ ipset_print_elem(char *buf, unsigned int len,
        if (!type)
                return -1;
 
-       size = type->elem[IPSET_DIM_ONE].print(buf, len, data,
-                       type->elem[IPSET_DIM_ONE].opt, env);
+       size = type->elem[IPSET_DIM_ONE - 1].print(buf, len, data,
+                       type->elem[IPSET_DIM_ONE - 1].opt, env);
        SNPRINTF_FAILURE(size, len, offset);
-       IF_D(ipset_data_test(data, type->elem[IPSET_DIM_TWO].opt),
+       IF_D(ipset_data_test(data, type->elem[IPSET_DIM_TWO - 1].opt),
             "print second elem");
        if (type->dimension == IPSET_DIM_ONE ||
            (type->last_elem_optional &&
-            !ipset_data_test(data, type->elem[IPSET_DIM_TWO].opt)))
+            !ipset_data_test(data, type->elem[IPSET_DIM_TWO - 1].opt)))
                return offset;
 
        size = snprintf(buf + offset, len, IPSET_ELEM_SEPARATOR);
        SNPRINTF_FAILURE(size, len, offset);
-       size = type->elem[IPSET_DIM_TWO].print(buf + offset, len, data,
-                       type->elem[IPSET_DIM_TWO].opt, env);
+       size = type->elem[IPSET_DIM_TWO - 1].print(buf + offset, len, data,
+                       type->elem[IPSET_DIM_TWO - 1].opt, env);
        SNPRINTF_FAILURE(size, len, offset);
        if (type->dimension == IPSET_DIM_TWO ||
            (type->last_elem_optional &&
-            !ipset_data_test(data, type->elem[IPSET_DIM_THREE].opt)))
+            !ipset_data_test(data, type->elem[IPSET_DIM_THREE - 1].opt)))
                return offset;
 
        size = snprintf(buf + offset, len, IPSET_ELEM_SEPARATOR);
        SNPRINTF_FAILURE(size, len, offset);
-       size = type->elem[IPSET_DIM_THREE].print(buf + offset, len, data,
-                       type->elem[IPSET_DIM_THREE].opt, env);
+       size = type->elem[IPSET_DIM_THREE - 1].print(buf + offset, len, data,
+                       type->elem[IPSET_DIM_THREE - 1].opt, env);
        SNPRINTF_FAILURE(size, len, offset);
 
        return offset;
index e73bc7cc255e76983623b2d25460fb8f741b9e58..89f30028b3949e5ab0b76a0501524323d37df5d3 100644 (file)
@@ -63,7 +63,7 @@ struct ipset_type ipset_bitmap_ip0 = {
        .family = AF_INET,
        .dimension = IPSET_DIM_ONE,
        .elem = {
-               [IPSET_DIM_ONE] = {
+               [IPSET_DIM_ONE - 1] = {
                        .parse = ipset_parse_ip,
                        .print = ipset_print_ip,
                        .opt = IPSET_OPT_IP
index f47f25d9da8b43243a4016b1331ff659e989cab8..f8f7495b90aabb773d1f8656673d2399f37e6835 100644 (file)
@@ -61,12 +61,12 @@ struct ipset_type ipset_bitmap_ipmac0 = {
        .dimension = IPSET_DIM_TWO,
        .last_elem_optional = true,
        .elem = {
-               [IPSET_DIM_ONE] = {
+               [IPSET_DIM_ONE - 1] = {
                        .parse = ipset_parse_single_ip,
                        .print = ipset_print_ip,
                        .opt = IPSET_OPT_IP
                },
-               [IPSET_DIM_TWO] = {
+               [IPSET_DIM_TWO - 1] = {
                        .parse = ipset_parse_ether,
                        .print = ipset_print_ether,
                        .opt = IPSET_OPT_ETHER
index c8c6e1f43b2fba51fea05608ba0c81ed9f53fdef..9acdf23ee7f3f106f26e67b7c2d0276da42f3e8d 100644 (file)
@@ -54,7 +54,7 @@ struct ipset_type ipset_bitmap_port0 = {
        .family = AF_UNSPEC,
        .dimension = IPSET_DIM_ONE,
        .elem = {
-               [IPSET_DIM_ONE] = {
+               [IPSET_DIM_ONE - 1] = {
                        .parse = ipset_parse_tcp_port,
                        .print = ipset_print_port,
                        .opt = IPSET_OPT_PORT
index 315804ae56fff1f98a435cbfc8cd95e737893eb0..7be8e19285da13ccb9234cd9f4c90b07842a8a09 100644 (file)
@@ -86,7 +86,7 @@ struct ipset_type ipset_hash_ip0 = {
        .family = AF_INET46,
        .dimension = IPSET_DIM_ONE,
        .elem = {
-               [IPSET_DIM_ONE] = {
+               [IPSET_DIM_ONE - 1] = {
                        .parse = ipset_parse_ip4_single6,
                        .print = ipset_print_ip,
                        .opt = IPSET_OPT_IP
index b5bd41b9c676a48d3d6c10740b999e2cb1d30cd0..3738aa46326afb389e6e09b0b757eec7452f5672 100644 (file)
@@ -92,12 +92,12 @@ struct ipset_type ipset_hash_ipport1 = {
        .family = AF_INET46,
        .dimension = IPSET_DIM_TWO,
        .elem = {
-               [IPSET_DIM_ONE] = {
+               [IPSET_DIM_ONE - 1] = {
                        .parse = ipset_parse_ip4_single6,
                        .print = ipset_print_ip,
                        .opt = IPSET_OPT_IP
                },
-               [IPSET_DIM_TWO] = {
+               [IPSET_DIM_TWO - 1] = {
                        .parse = ipset_parse_proto_port,
                        .print = ipset_print_proto_port,
                        .opt = IPSET_OPT_PORT
index b27cebff52a7cb01628ac6e75fb0b96b528d6f42..9a2c44c8eafc2b7fbc4644d1acb7f9358aaa8592 100644 (file)
@@ -92,17 +92,17 @@ struct ipset_type ipset_hash_ipportip1 = {
        .family = AF_INET46,
        .dimension = IPSET_DIM_THREE,
        .elem = {
-               [IPSET_DIM_ONE] = {
+               [IPSET_DIM_ONE - 1] = {
                        .parse = ipset_parse_ip4_single6,
                        .print = ipset_print_ip,
                        .opt = IPSET_OPT_IP
                },
-               [IPSET_DIM_TWO] = {
+               [IPSET_DIM_TWO - 1] = {
                        .parse = ipset_parse_proto_port,
                        .print = ipset_print_proto_port,
                        .opt = IPSET_OPT_PORT
                },
-               [IPSET_DIM_THREE] = {
+               [IPSET_DIM_THREE - 1] = {
                        .parse = ipset_parse_single_ip,
                        .print = ipset_print_ip,
                        .opt = IPSET_OPT_IP2
index ecab191b6fe145c386588c80fdd1ff95ebc299b0..b7415dc913c8004d6c2f7f65f3ce25e55bd842b9 100644 (file)
@@ -93,17 +93,17 @@ struct ipset_type ipset_hash_ipportnet1 = {
        .family = AF_INET46,
        .dimension = IPSET_DIM_THREE,
        .elem = {
-               [IPSET_DIM_ONE] = {
+               [IPSET_DIM_ONE - 1] = {
                        .parse = ipset_parse_ip4_single6,
                        .print = ipset_print_ip,
                        .opt = IPSET_OPT_IP
                },
-               [IPSET_DIM_TWO] = {
+               [IPSET_DIM_TWO - 1] = {
                        .parse = ipset_parse_proto_port,
                        .print = ipset_print_proto_port,
                        .opt = IPSET_OPT_PORT
                },
-               [IPSET_DIM_THREE] = {
+               [IPSET_DIM_THREE - 1] = {
                        .parse = ipset_parse_ipnet,
                        .print = ipset_print_ip,
                        .opt = IPSET_OPT_IP2
@@ -183,17 +183,17 @@ struct ipset_type ipset_hash_ipportnet2 = {
        .family = AF_INET46,
        .dimension = IPSET_DIM_THREE,
        .elem = {
-               [IPSET_DIM_ONE] = {
+               [IPSET_DIM_ONE - 1] = {
                        .parse = ipset_parse_ip4_single6,
                        .print = ipset_print_ip,
                        .opt = IPSET_OPT_IP
                },
-               [IPSET_DIM_TWO] = {
+               [IPSET_DIM_TWO - 1] = {
                        .parse = ipset_parse_proto_port,
                        .print = ipset_print_proto_port,
                        .opt = IPSET_OPT_PORT
                },
-               [IPSET_DIM_THREE] = {
+               [IPSET_DIM_THREE - 1] = {
                        .parse = ipset_parse_ip4_net6,
                        .print = ipset_print_ip,
                        .opt = IPSET_OPT_IP2
index 665c398990419d9e5f55cad489aee18f8726d344..587f891f066fe0569fb8a7849d64ca85d113ccbc 100644 (file)
@@ -76,7 +76,7 @@ struct ipset_type ipset_hash_net0 = {
        .family = AF_INET46,
        .dimension = IPSET_DIM_ONE,
        .elem = {
-               [IPSET_DIM_ONE] = {
+               [IPSET_DIM_ONE - 1] = {
                        .parse = ipset_parse_ipnet,
                        .print = ipset_print_ip,
                        .opt = IPSET_OPT_IP
@@ -128,7 +128,7 @@ struct ipset_type ipset_hash_net1 = {
        .family = AF_INET46,
        .dimension = IPSET_DIM_ONE,
        .elem = {
-               [IPSET_DIM_ONE] = {
+               [IPSET_DIM_ONE - 1] = {
                        .parse = ipset_parse_ip4_net6,
                        .print = ipset_print_ip,
                        .opt = IPSET_OPT_IP
index 2fbe27db21a37e892084ff2714024c17277017c4..d1f5f7ebd857c2451302f01e3f4cc3d07c2a2cf7 100644 (file)
@@ -69,12 +69,12 @@ struct ipset_type ipset_hash_netiface0 = {
        .family = AF_INET46,
        .dimension = IPSET_DIM_TWO,
        .elem = {
-               [IPSET_DIM_ONE] = {
+               [IPSET_DIM_ONE - 1] = {
                        .parse = ipset_parse_ip4_net6,
                        .print = ipset_print_ip,
                        .opt = IPSET_OPT_IP
                },
-               [IPSET_DIM_TWO] = {
+               [IPSET_DIM_TWO - 1] = {
                        .parse = ipset_parse_iface,
                        .print = ipset_print_iface,
                        .opt = IPSET_OPT_IFACE
index 480dd84c9b993c6954efb6eb57c77143e72fbc16..acf4a29b93a7eca475f1edfa283756948248f683 100644 (file)
@@ -70,12 +70,12 @@ struct ipset_type ipset_hash_netport1 = {
        .family = AF_INET46,
        .dimension = IPSET_DIM_TWO,
        .elem = {
-               [IPSET_DIM_ONE] = {
+               [IPSET_DIM_ONE - 1] = {
                        .parse = ipset_parse_ipnet,
                        .print = ipset_print_ip,
                        .opt = IPSET_OPT_IP
                },
-               [IPSET_DIM_TWO] = {
+               [IPSET_DIM_TWO - 1] = {
                        .parse = ipset_parse_proto_port,
                        .print = ipset_print_proto_port,
                        .opt = IPSET_OPT_PORT
@@ -144,12 +144,12 @@ struct ipset_type ipset_hash_netport2 = {
        .family = AF_INET46,
        .dimension = IPSET_DIM_TWO,
        .elem = {
-               [IPSET_DIM_ONE] = {
+               [IPSET_DIM_ONE - 1] = {
                        .parse = ipset_parse_ip4_net6,
                        .print = ipset_print_ip,
                        .opt = IPSET_OPT_IP
                },
-               [IPSET_DIM_TWO] = {
+               [IPSET_DIM_TWO - 1] = {
                        .parse = ipset_parse_proto_port,
                        .print = ipset_print_proto_port,
                        .opt = IPSET_OPT_PORT
index f3fa6dfb6a5a4645d964ce596b81a40b0f6f173a..68616e84066c180d0ec7ee8d8c0c48f0a97ba239 100644 (file)
@@ -53,7 +53,7 @@ struct ipset_type ipset_list_set0 = {
        .family = AF_UNSPEC,
        .dimension = IPSET_DIM_ONE,
        .elem = {
-               [IPSET_DIM_ONE] = {
+               [IPSET_DIM_ONE - 1] = {
                        .parse = ipset_parse_setname,
                        .print = ipset_print_name,
                        .opt = IPSET_OPT_NAME