Skip to content

Commit

Permalink
meta-flow: Use standard libraries in mf_from_ipv6_string().
Browse files Browse the repository at this point in the history
Signed-off-by: Justin Pettit <jpettit@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
  • Loading branch information
justinpettit committed Nov 24, 2015
1 parent fac5bd3 commit 10f61b6
Showing 1 changed file with 3 additions and 36 deletions.
39 changes: 3 additions & 36 deletions lib/meta-flow.c
Expand Up @@ -2048,43 +2048,10 @@ mf_from_ipv4_string(const struct mf_field *mf, const char *s,

static char *
mf_from_ipv6_string(const struct mf_field *mf, const char *s,
struct in6_addr *value, struct in6_addr *mask)
struct in6_addr *ipv6, struct in6_addr *mask)
{
char *str = xstrdup(s);
char *save_ptr = NULL;
const char *name, *netmask;
int retval;

ovs_assert(mf->n_bytes == sizeof *value);

name = strtok_r(str, "/", &save_ptr);
retval = name ? lookup_ipv6(name, value) : EINVAL;
if (retval) {
char *err;

err = xasprintf("%s: could not convert to IPv6 address", str);
free(str);

return err;
}

netmask = strtok_r(NULL, "/", &save_ptr);
if (netmask) {
if (inet_pton(AF_INET6, netmask, mask) != 1) {
int prefix = atoi(netmask);
if (prefix <= 0 || prefix > 128) {
free(str);
return xasprintf("%s: prefix bits not between 1 and 128", s);
} else {
*mask = ipv6_create_mask(prefix);
}
}
} else {
*mask = in6addr_exact;
}
free(str);

return NULL;
ovs_assert(mf->n_bytes == sizeof *ipv6);
return ipv6_parse_masked(s, ipv6, mask);
}

static char *
Expand Down

0 comments on commit 10f61b6

Please sign in to comment.