[ipset-5: 7/9] Add parser function to handle IPv4 and IPv6 differently.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

Signed-off-by: Jozsef Kadlecsik <kadlec@xxxxxxxxxxxxxxxxx>
---
 include/libipset/parse.h |    2 ++
 lib/parse.c              |   40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/include/libipset/parse.h b/include/libipset/parse.h
index aaa1577..2e3f8a8 100644
--- a/include/libipset/parse.h
+++ b/include/libipset/parse.h
@@ -54,6 +54,8 @@ extern int ipset_parse_iprange(struct ipset_session *session,
 			       enum ipset_opt opt, const char *str);
 extern int ipset_parse_ipnet(struct ipset_session *session,
 			     enum ipset_opt opt, const char *str);
+extern int ipset_parse_ip4_single6(struct ipset_session *session,
+				enum ipset_opt opt, const char *str);
 extern int ipset_parse_name(struct ipset_session *session,
                             enum ipset_opt opt, const char *str);
 extern int ipset_parse_before(struct ipset_session *session,
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

[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux