Signed-off-by: Ben Pfaff <b...@nicira.com> --- lib/meta-flow.c | 19 +------------------ lib/packets.c | 21 +++++++++++++++++++++ lib/packets.h | 2 ++ 3 files changed, 24 insertions(+), 18 deletions(-)
diff --git a/lib/meta-flow.c b/lib/meta-flow.c index 224ba53..fba628c 100644 --- a/lib/meta-flow.c +++ b/lib/meta-flow.c @@ -1930,25 +1930,8 @@ static char * mf_from_ipv4_string(const struct mf_field *mf, const char *s, ovs_be32 *ip, ovs_be32 *mask) { - int prefix; - ovs_assert(mf->n_bytes == sizeof *ip); - - if (ovs_scan(s, IP_SCAN_FMT"/"IP_SCAN_FMT, - IP_SCAN_ARGS(ip), IP_SCAN_ARGS(mask))) { - /* OK. */ - } else if (ovs_scan(s, IP_SCAN_FMT"/%d", IP_SCAN_ARGS(ip), &prefix)) { - if (prefix <= 0 || prefix > 32) { - return xasprintf("%s: network prefix bits not between 0 and " - "32", s); - } - *mask = be32_prefix_mask(prefix); - } else if (ovs_scan(s, IP_SCAN_FMT, IP_SCAN_ARGS(ip))) { - *mask = OVS_BE32_MAX; - } else { - return xasprintf("%s: invalid IP address", s); - } - return NULL; + return ip_parse_masked(s, ip, mask); } static char * diff --git a/lib/packets.c b/lib/packets.c index a4d7854..778fc77 100644 --- a/lib/packets.c +++ b/lib/packets.c @@ -404,6 +404,27 @@ ip_format_masked(ovs_be32 ip, ovs_be32 mask, struct ds *s) } } +char * OVS_WARN_UNUSED_RESULT +ip_parse_masked(const char *s, ovs_be32 *ip, ovs_be32 *mask) +{ + int prefix; + + if (ovs_scan(s, IP_SCAN_FMT"/"IP_SCAN_FMT, + IP_SCAN_ARGS(ip), IP_SCAN_ARGS(mask))) { + /* OK. */ + } else if (ovs_scan(s, IP_SCAN_FMT"/%d", IP_SCAN_ARGS(ip), &prefix)) { + if (prefix <= 0 || prefix > 32) { + return xasprintf("%s: network prefix bits not between 0 and " + "32", s); + } + *mask = be32_prefix_mask(prefix); + } else if (ovs_scan(s, IP_SCAN_FMT, IP_SCAN_ARGS(ip))) { + *mask = OVS_BE32_MAX; + } else { + return xasprintf("%s: invalid IP address", s); + } + return NULL; +} /* Stores the string representation of the IPv6 address 'addr' into the * character array 'addr_str', which must be at least INET6_ADDRSTRLEN diff --git a/lib/packets.h b/lib/packets.h index e841fb1..ea74646 100644 --- a/lib/packets.h +++ b/lib/packets.h @@ -561,6 +561,8 @@ ip_is_local_multicast(ovs_be32 ip) } int ip_count_cidr_bits(ovs_be32 netmask); void ip_format_masked(ovs_be32 ip, ovs_be32 mask, struct ds *); +char *ip_parse_masked(const char *s, ovs_be32 *ip, ovs_be32 *mask) + OVS_WARN_UNUSED_RESULT; #define IP_VER(ip_ihl_ver) ((ip_ihl_ver) >> 4) #define IP_IHL(ip_ihl_ver) ((ip_ihl_ver) & 15) -- 2.1.3 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev