diff options
author | Hans Dedecker <dedeckeh@gmail.com> | 2016-08-11 15:53:29 +0200 |
---|---|---|
committer | Felix Fietkau <nbd@nbd.name> | 2016-08-11 19:34:51 +0200 |
commit | cec1ce296eede81dc62628fce33b8cc216727b17 (patch) | |
tree | dbb8789b86a66ae7304a27c596558896bc1f7d03 /proto.c | |
parent | 00fc987a147841a2e9bfd15399056886b6c77064 (diff) |
utils: Move IP address validation to parse_addr function
Commit 7a51f23e adds IP address validation in the function parse_ip_and_netmask;
however the added check is too restrictive as the function is used on several places
resulting into the problem multicast routes cannot be added anymore via UCI.
Therefore move the IP host address validation to the function parse_addr so
experimantal/multicast addresses cannot be added as a host IP address while
multicast routes can be added again.
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Diffstat (limited to 'proto.c')
-rw-r--r-- | proto.c | 20 |
1 files changed, 15 insertions, 5 deletions
@@ -123,17 +123,27 @@ parse_addr(struct interface *iface, const char *str, bool v6, int mask, return false; addr->mask = mask; - if (!parse_ip_and_netmask(af, str, &addr->addr, &addr->mask)) { - interface_add_error(iface, "proto", "INVALID_ADDRESS", &str, 1); - free(addr); - return false; - } + if (!parse_ip_and_netmask(af, str, &addr->addr, &addr->mask)) + goto error; + + if (!v6) { + if (IN_EXPERIMENTAL(ntohl(addr->addr.in.s_addr))) + goto error; + + } else if (IN6_IS_ADDR_MULTICAST(&addr->addr.in6)) + goto error; if (broadcast) addr->broadcast = broadcast; vlist_add(&iface->proto_ip.addr, &addr->node, &addr->flags); return true; + +error: + interface_add_error(iface, "proto", "INVALID_ADDRESS", &str, 1); + free(addr); + + return false; } static int |