summaryrefslogtreecommitdiffstats
path: root/lib/parse.c
diff options
context:
space:
mode:
authorQuentin Armitage <quentin@armitage.org.uk>2013-08-09 12:26:33 +0100
committerJozsef Kadlecsik <kadlec@blackhole.kfki.hu>2013-08-17 21:31:29 +0200
commit480761a3bdaa55bf8c966e4dab950ebf84775863 (patch)
tree6d750f948abf1ae4f93e4c704502d085ac13d679 /lib/parse.c
parent3a4419954a3ae0ba5dafd711e6b8dd8f0beb5c21 (diff)
Add specifying protocol for bitmap:port
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Diffstat (limited to 'lib/parse.c')
-rw-r--r--lib/parse.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/parse.c b/lib/parse.c
index ce3548d..112b273 100644
--- a/lib/parse.c
+++ b/lib/parse.c
@@ -637,6 +637,44 @@ error:
}
/**
+ * ipset_parse_tcp_udp_port - parse (optional) protocol and a single port
+ * @session: session structure
+ * @opt: option kind of the data
+ * @str: string to parse
+ *
+ * Parse string as a protocol and port, separated by a colon.
+ * The protocol part is optional, but may only be "tcp" or "udp".
+ * 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_udp_port(struct ipset_session *session,
+ enum ipset_opt opt, const char *str)
+{
+ struct ipset_data *data;
+ int err = 0;
+ uint8_t p = 0;
+
+ err = ipset_parse_proto_port(session, opt, str);
+
+ if (!err) {
+ data = ipset_session_data(session);
+
+ p = *(const uint8_t *) ipset_data_get(data, IPSET_OPT_PROTO);
+ if (p != IPPROTO_TCP && p != IPPROTO_UDP) {
+ syntax_err("Only protocols TCP and UDP are valid");
+ err = -1 ;
+ } else {
+ /* Reset the protocol to none */
+ ipset_data_flags_unset(data, IPSET_FLAG(IPSET_OPT_PROTO));
+ }
+ }
+ return err;
+}
+
+/**
* ipset_parse_family - parse INET|INET6 family names
* @session: session structure
* @opt: option kind of the data