From 984c309c5996c9ecaafeda473188a78f0f8eac63 Mon Sep 17 00:00:00 2001 From: Jozsef Kadlecsik Date: Sat, 30 Oct 2010 23:11:47 +0200 Subject: 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. --- lib/parse.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'lib') diff --git a/lib/parse.c b/lib/parse.c index 28192d8..08e3d7c 100644 --- a/lib/parse.c +++ b/lib/parse.c @@ -903,6 +903,46 @@ ipset_parse_ipnet(struct ipset_session *session, return parse_ip(session, opt, str, IPADDR_ANY); } +/** + * 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 -- cgit v1.2.3