2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-31 06:15:47 +00:00

packets: Add more utility functions for IPv4 and IPv6 addresses.

We had these functions scattered around the source tree anyway.  packets.h
is a good place to centralize them.

I do plan to introduce some additional callers.
This commit is contained in:
Ben Pfaff
2011-08-17 10:55:15 -07:00
parent e7ed3a3a5f
commit aad29cd1a1
7 changed files with 119 additions and 45 deletions

View File

@@ -421,15 +421,8 @@ format_ip_netmask(struct ds *s, const char *name, ovs_be32 ip,
ovs_be32 netmask)
{
if (netmask) {
ds_put_format(s, "%s="IP_FMT, name, IP_ARGS(&ip));
if (netmask != htonl(UINT32_MAX)) {
if (ip_is_cidr(netmask)) {
int wcbits = ofputil_netmask_to_wcbits(netmask);
ds_put_format(s, "/%d", 32 - wcbits);
} else {
ds_put_format(s, "/"IP_FMT, IP_ARGS(&netmask));
}
}
ds_put_format(s, "%s=", name);
ip_format_masked(ip, netmask, s);
ds_put_char(s, ',');
}
}
@@ -441,16 +434,7 @@ format_ipv6_netmask(struct ds *s, const char *name,
{
if (!ipv6_mask_is_any(netmask)) {
ds_put_format(s, "%s=", name);
print_ipv6_addr(s, addr);
if (!ipv6_mask_is_exact(netmask)) {
if (ipv6_is_cidr(netmask)) {
int cidr_bits = ipv6_count_cidr_bits(netmask);
ds_put_format(s, "/%d", cidr_bits);
} else {
ds_put_char(s, '/');
print_ipv6_addr(s, netmask);
}
}
print_ipv6_masked(s, addr, netmask);
ds_put_char(s, ',');
}
}