diff options
-rw-r--r-- | include/libipset/parse.h | 3 | ||||
-rw-r--r-- | lib/parse.c | 34 |
2 files changed, 30 insertions, 7 deletions
diff --git a/include/libipset/parse.h b/include/libipset/parse.h index 2e3f8a8..e87a60d 100644 --- a/include/libipset/parse.h +++ b/include/libipset/parse.h @@ -26,6 +26,9 @@ extern int ipset_parse_ether(struct ipset_session *session, extern int ipset_parse_port(struct ipset_session *session, enum ipset_opt opt, const char *str, const char *proto); +extern int ipset_parse_tcpudp_port(struct ipset_session *session, + enum ipset_opt opt, const char *str, + const char *proto); extern int ipset_parse_tcp_port(struct ipset_session *session, enum ipset_opt opt, const char *str); extern int ipset_parse_single_tcp_port(struct ipset_session *session, diff --git a/lib/parse.c b/lib/parse.c index 08e3d7c..fa8a4f7 100644 --- a/lib/parse.c +++ b/lib/parse.c @@ -244,20 +244,21 @@ ipset_parse_port(struct ipset_session *session, } /** - * ipset_parse_tcp_port - parse TCP port name, number, or range of them + * ipset_parse_tcpudp_port - parse TCP/UDP port name, number, or range of them * @session: session structure * @opt: option kind of the data * @str: string to parse + * @proto: TCP|UDP * - * Parse string as a TCP port name or number or range of them + * Parse string as a TCP/UDP port name or number or range of them * separated by a dash. The parsed port numbers are stored * in the data blob of the session. * * Returns 0 on success or a negative error code. */ int -ipset_parse_tcp_port(struct ipset_session *session, - enum ipset_opt opt, const char *str) +ipset_parse_tcpudp_port(struct ipset_session *session, + enum ipset_opt opt, const char *str, const char *proto) { char *a, *saved, *tmp; int err = 0; @@ -276,11 +277,11 @@ ipset_parse_tcp_port(struct ipset_session *session, if (a != NULL) { /* port-port */ *a++ = '\0'; - err = ipset_parse_port(session, IPSET_OPT_PORT_TO, a, "TCP"); + err = ipset_parse_port(session, IPSET_OPT_PORT_TO, a, proto); if (err) goto error; } - err = ipset_parse_port(session, opt, tmp, "TCP"); + err = ipset_parse_port(session, opt, tmp, proto); error: free(saved); @@ -288,6 +289,25 @@ error: } /** + * ipset_parse_tcp_port - parse TCP port name, number, or range of them + * @session: session structure + * @opt: option kind of the data + * @str: string to parse + * + * Parse string as a TCP port name or number or range of them + * separated by a dash. The parsed port numbers are stored + * in the data blob of the session. + * + * Returns 0 on success or a negative error code. + */ +int +ipset_parse_tcp_port(struct ipset_session *session, + enum ipset_opt opt, const char *str) +{ + return ipset_parse_tcpudp_port(session, opt, str, "TCP"); +} + +/** * ipset_parse_single_tcp_port - parse TCP port name or number * @session: session structure * @opt: option kind of the data @@ -516,7 +536,7 @@ ipset_parse_proto_port(struct ipset_session *session, goto error; } parse_port: - err = ipset_parse_port(session, opt, tmp, proto); + err = ipset_parse_tcpudp_port(session, opt, tmp, proto); error: free(saved); |