From 8d79df480941228260b8a6aa9d17ea62641051d0 Mon Sep 17 00:00:00 2001 From: Stefan Schantl Date: Mon, 17 Apr 2023 15:17:59 +0200 Subject: [PATCH] Add function to remove ports from a set. Signed-off-by: Stefan Schantl --- IPSet.xs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/IPSet.xs b/IPSet.xs index 295a9b7..4f9ff1b 100644 --- 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. # -- 2.47.3