]> git.ipfire.org Git - people/stevee/perl-ipset.git/commitdiff
Add function to remove ports from a set.
authorStefan Schantl <stefan.schantl@ipfire.org>
Mon, 17 Apr 2023 13:17:59 +0000 (15:17 +0200)
committerStefan Schantl <stefan.schantl@ipfire.org>
Mon, 17 Apr 2023 13:17:59 +0000 (15:17 +0200)
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
IPSet.xs

index 295a9b7cf2a027bac29420fc2bc246bfa05d582d..4f9ff1bc76bc3aeb041ca49ea48e379026b088cf 100644 (file)
--- a/IPSet.xs
+++ b/IPSet.xs
@@ -526,6 +526,53 @@ add_port(session, setname, port)
        OUTPUT:
                RETVAL
 
+bool
+remove_port(session, setname, port)
+       struct ipset_session *session;
+       const char *setname;
+       const char *port;
+
+       PREINIT:
+               enum ipset_cmd cmd = IPSET_CMD_DEL;
+               const struct ipset_type *type;
+
+       CODE:
+               // Assign setname to session data.
+               int r = ipset_session_data_set(session, IPSET_SETNAME, setname);
+               if (r < 0) {
+                       goto ERROR;
+               }
+
+               // Get the set type.
+               type = ipset_type_get(session, cmd);
+               if (type = NULL) {
+                       goto ERROR;
+               }
+
+               // Parse and add the given port number to the session data.
+               r = ipset_parse_tcp_udp_port(session, IPSET_OPT_PORT, port);
+               if (r < 0) {
+                       goto ERROR;
+               }
+
+               r = ipset_cmd(session, cmd, 0);
+               if (r < 0) {
+                       goto ERROR;
+               }
+
+               RETVAL = true;
+
+               goto END;
+
+               ERROR:
+                       RETVAL = false;
+
+                       // Reset session data.
+                       ipset_data_reset(ipset_session_data(session));
+               END:
+       OUTPUT:
+               RETVAL
+
 #
 # Get functions to ask for various data or receive error messages.
 #