summaryrefslogtreecommitdiffstats
path: root/lib/parse.c
diff options
context:
space:
mode:
authorJozsef Kadlecsik <kadlec@blackhole.kfki.hu>2010-10-30 23:11:47 +0200
committerJozsef Kadlecsik <kadlec@blackhole.kfki.hu>2010-10-30 23:11:47 +0200
commit984c309c5996c9ecaafeda473188a78f0f8eac63 (patch)
tree6ec241de3baa3e3af56f82b29b94c3de78c91220 /lib/parse.c
parent3f8f60c2115992ecf6678fb6ce24d46dbb09e5f8 (diff)
Add parser function to handle IPv4 and IPv6 differently.
At present IPv6 does not support adding/deleting multiple IPv6 addresses specified as an ip-ip range or ip/prefix block. A parser function is added by which can enforce it at parsing the address pattern.
Diffstat (limited to 'lib/parse.c')
-rw-r--r--lib/parse.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/parse.c b/lib/parse.c
index 28192d8..08e3d7c 100644
--- a/lib/parse.c
+++ b/lib/parse.c
@@ -904,6 +904,46 @@ ipset_parse_ipnet(struct ipset_session *session,
}
/**
+ * ipset_parse_ip4_single6 - parse IPv4 address, range or netblock or IPv6 address
+ * @session: session structure
+ * @opt: option kind of the data
+ * @str: string to parse
+ *
+ * Parse string as an IPv4 address or address range
+ * or netblock or and IPv6 address. Hostnames are resolved. If family
+ * is not set yet in the data blob, INET is assumed.
+ * The values are stored in the data blob of the session.
+ *
+ * FIXME: if the hostname resolves to multiple addresses,
+ * the first one is used only.
+ *
+ * Returns 0 on success or a negative error code.
+ */
+int
+ipset_parse_ip4_single6(struct ipset_session *session,
+ enum ipset_opt opt, const char *str)
+{
+ struct ipset_data *data;
+ uint8_t family;
+
+ assert(session);
+ assert(opt == IPSET_OPT_IP || opt == IPSET_OPT_IP2);
+ assert(str);
+
+ data = ipset_session_data(session);
+ family = ipset_data_family(data);
+
+ if (family == AF_UNSPEC) {
+ family = AF_INET;
+ ipset_data_set(data, IPSET_OPT_FAMILY, &family);
+ }
+
+ return family == AF_INET ? ipset_parse_ip(session, opt, str)
+ : ipset_parse_single_ip(session, opt, str);
+
+}
+
+/**
* ipset_parse_iptimeout - parse IPv4|IPv6 address and timeout
* @session: session structure
* @opt: option kind of the data