]> git.ipfire.org Git - people/stevee/perl-ipset.git/commitdiff
Add support to create bitmap:port based sets
authorStefan Schantl <stefan.schantl@ipfire.org>
Mon, 17 Apr 2023 13:16:06 +0000 (15:16 +0200)
committerStefan Schantl <stefan.schantl@ipfire.org>
Mon, 17 Apr 2023 13:16:06 +0000 (15:16 +0200)
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
IPSet.xs

index 71c29d9c7b6be5ebad5ce5b161fee46a0de1e9b3..02a7c40a2b1bf69baae6643e3f7e542acc2b2d46 100644 (file)
--- a/IPSet.xs
+++ b/IPSet.xs
@@ -131,6 +131,9 @@ bool create_set(session, setname, typename, hashsize, maxelem)
                // Family current is hardcoded to IPv4.
                int family = NFPROTO_IPV4;
 
+               // The range for bitmap:port based sets currently is hardcoded.
+               const uint16_t range_start = 0;
+               const uint16_t range_stop = 65535;
        CODE:
                // Load everything
                ipset_load_types();
@@ -152,19 +155,31 @@ bool create_set(session, setname, typename, hashsize, maxelem)
                        goto ERROR;
                }
 
-               r = ipset_session_data_set(session, IPSET_OPT_FAMILY, &family);
-               if (r < 0) {
-                       goto ERROR;
-               }
-
-               r = ipset_session_data_set(session, IPSET_OPT_HASHSIZE, &hashsize);
-               if (r < 0) {
-                       goto ERROR;
-               }
-
-               r = ipset_session_data_set(session, IPSET_OPT_MAXELEM, &maxelem);
-               if (r < 0) {
-                       goto ERROR;
+               if (strcmp(typename, "bitmap:port") == 0) {
+                       r = ipset_session_data_set(session, IPSET_OPT_PORT_FROM, &range_start);
+                       if (r < 0) {
+                               goto ERROR;
+                       }
+
+                       r = ipset_session_data_set(session, IPSET_OPT_PORT_TO, &range_stop);
+                       if (r < 0) {
+                               goto ERROR;
+                       }
+               } else {
+                       r = ipset_session_data_set(session, IPSET_OPT_FAMILY, &family);
+                       if (r < 0) {
+                               goto ERROR;
+                       }
+
+                       r = ipset_session_data_set(session, IPSET_OPT_HASHSIZE, &hashsize);
+                       if (r < 0) {
+                               goto ERROR;
+                       }
+
+                       r = ipset_session_data_set(session, IPSET_OPT_MAXELEM, &maxelem);
+                       if (r < 0) {
+                               goto ERROR;
+                       }
                }
 
                r = ipset_cmd(session, IPSET_CMD_CREATE, 0);