]> granicus.if.org Git - ipset/commitdiff
Make IPv4 and IPv6 address handling similar
authorJozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Tue, 18 Jan 2011 16:20:30 +0000 (17:20 +0100)
committerJozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Tue, 18 Jan 2011 16:20:30 +0000 (17:20 +0100)
While the following works for AF_INET:

 ipset add foo 192.168.1.1/32

this does not work for AF_INET6:

 ipset add foo6 20a1:1:2:3:4:5:6:7/128
 ipset v5.2: Syntax error: plain IP address must be supplied: 20a1:1:2:3:4:5:6:7/128

Bug reported by Holger Eitzenberger.

The complete fix is to handle the special host prefixes in the general
IP address parser function.

lib/parse.c

index c4d9c75100134e0813f234a2592a4b08c2658ef3..fbc1dca74bcf6c31aafac4d41fcdf858da286916 100644 (file)
@@ -711,6 +711,14 @@ enum ipaddr_type {
        IPADDR_RANGE,
 };
 
+static inline bool
+cidr_hostaddr(const char *str, uint8_t family)
+{
+       char *a = cidr_separator(str);
+       
+       return family == AF_INET ? STREQ(a, "/32") : STREQ(a, "/128");
+}
+
 static int
 parse_ip(struct ipset_session *session,
         enum ipset_opt opt, const char *str, enum ipaddr_type addrtype)
@@ -725,7 +733,8 @@ parse_ip(struct ipset_session *session,
 
        switch (addrtype) {
        case IPADDR_PLAIN:
-               if (range_separator(str) || cidr_separator(str))
+               if (range_separator(str)
+                   || (cidr_separator(str) && !cidr_hostaddr(str, family)))
                        return syntax_err("plain IP address must be supplied: %s",
                                          str);
                break;