From: Stefan Schantl Date: Mon, 17 Apr 2023 13:17:01 +0000 (+0200) Subject: Add function to add ports to a set. X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=07d9bb205e4a8f6d27355acd3450dcdac77a2454;p=people%2Fstevee%2Fperl-ipset.git Add function to add ports to a set. Signed-off-by: Stefan Schantl --- diff --git a/IPSet.xs b/IPSet.xs index 02a7c40..295a9b7 100644 --- a/IPSet.xs +++ b/IPSet.xs @@ -478,7 +478,54 @@ remove_address(session, setname, address) END: OUTPUT: RETVAL - + +bool +add_port(session, setname, port) + struct ipset_session *session; + const char *setname; + const char *port; + + PREINIT: + enum ipset_cmd cmd = IPSET_CMD_ADD; + const struct ipset_type *type; + + CODE: + // Assign setname as 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 try to add the given port 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. #