From: Justin Pettit Date: Sun, 25 Oct 2015 20:19:22 +0000 (-0700) Subject: packets: Change IPv6 functions to more closely resemble IPv4 ones. X-Git-Tag: v2.5.0~304 X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Fovs.git;a=commitdiff_plain;h=ac6d120f8e8ad1802b7d89dcf3c6e6d9d399cdf7 packets: Change IPv6 functions to more closely resemble IPv4 ones. Signed-off-by: Justin Petitt Acked-by: Ben Pfaff --- diff --git a/lib/match.c b/lib/match.c index d22772ba6..6519065ae 100644 --- a/lib/match.c +++ b/lib/match.c @@ -862,7 +862,7 @@ format_ipv6_netmask(struct ds *s, const char *name, { if (!ipv6_mask_is_any(netmask)) { ds_put_format(s, "%s=", name); - print_ipv6_masked(s, addr, netmask); + ipv6_format_masked(addr, netmask, s); ds_put_char(s, ','); } } diff --git a/lib/meta-flow.c b/lib/meta-flow.c index eaf4ca885..1a10a9b36 100644 --- a/lib/meta-flow.c +++ b/lib/meta-flow.c @@ -2422,7 +2422,7 @@ mf_format(const struct mf_field *mf, break; case MFS_IPV6: - print_ipv6_masked(s, &value->ipv6, mask ? &mask->ipv6 : NULL); + ipv6_format_masked(&value->ipv6, mask ? &mask->ipv6 : NULL, s); break; case MFS_FRAG: diff --git a/lib/ovs-router.c b/lib/ovs-router.c index 2f093e8a3..3962aef5b 100644 --- a/lib/ovs-router.c +++ b/lib/ovs-router.c @@ -318,7 +318,7 @@ ovs_router_show(struct unixctl_conn *conn, int argc OVS_UNUSED, } else { ds_put_format(&ds, "User: "); } - print_ipv6_mapped(&ds, &rt->nw_addr); + ipv6_format_mapped(&rt->nw_addr, &ds); plen = rt->plen; if (IN6_IS_ADDR_V4MAPPED(&rt->nw_addr)) { plen -= 96; @@ -326,7 +326,7 @@ ovs_router_show(struct unixctl_conn *conn, int argc OVS_UNUSED, ds_put_format(&ds, "/%"PRIu16" dev %s", plen, rt->output_bridge); if (ipv6_addr_is_set(&rt->gw)) { ds_put_format(&ds, " GW "); - print_ipv6_mapped(&ds, &rt->gw); + ipv6_format_mapped(&rt->gw, &ds); } ds_put_format(&ds, "\n"); } @@ -353,7 +353,7 @@ ovs_router_lookup_cmd(struct unixctl_conn *conn, int argc OVS_UNUSED, if (ovs_router_lookup(&ip6, iface, &gw)) { struct ds ds = DS_EMPTY_INITIALIZER; ds_put_format(&ds, "gateway "); - print_ipv6_mapped(&ds, &ip6); + ipv6_format_mapped(&ip6, &ds); ds_put_format(&ds, "\ndev %s\n", iface); unixctl_command_reply(conn, ds_cstr(&ds)); ds_destroy(&ds); diff --git a/lib/packets.c b/lib/packets.c index 701a5ec95..866d78274 100644 --- a/lib/packets.c +++ b/lib/packets.c @@ -435,50 +435,41 @@ ip_parse_masked(const char *s, ovs_be32 *ip, ovs_be32 *mask) return NULL; } -/* Stores the string representation of the IPv6 address 'addr' into the - * character array 'addr_str', which must be at least INET6_ADDRSTRLEN - * bytes long. */ void -format_ipv6_addr(char *addr_str, const struct in6_addr *addr) -{ - inet_ntop(AF_INET6, addr, addr_str, INET6_ADDRSTRLEN); -} - -void -print_ipv6_addr(struct ds *string, const struct in6_addr *addr) +ipv6_format_addr(const struct in6_addr *addr, struct ds *s) { char *dst; - ds_reserve(string, string->length + INET6_ADDRSTRLEN); + ds_reserve(s, s->length + INET6_ADDRSTRLEN); - dst = string->string + string->length; - format_ipv6_addr(dst, addr); - string->length += strlen(dst); + dst = s->string + s->length; + inet_ntop(AF_INET6, addr, dst, INET6_ADDRSTRLEN); + s->length += strlen(dst); } void -print_ipv6_mapped(struct ds *s, const struct in6_addr *addr) +ipv6_format_mapped(const struct in6_addr *addr, struct ds *s) { if (IN6_IS_ADDR_V4MAPPED(addr)) { ds_put_format(s, IP_FMT, addr->s6_addr[12], addr->s6_addr[13], addr->s6_addr[14], addr->s6_addr[15]); } else { - print_ipv6_addr(s, addr); + ipv6_format_addr(addr, s); } } void -print_ipv6_masked(struct ds *s, const struct in6_addr *addr, - const struct in6_addr *mask) +ipv6_format_masked(const struct in6_addr *addr, const struct in6_addr *mask, + struct ds *s) { - print_ipv6_addr(s, addr); + ipv6_format_addr(addr, s); if (mask && !ipv6_mask_is_exact(mask)) { if (ipv6_is_cidr(mask)) { int cidr_bits = ipv6_count_cidr_bits(mask); ds_put_format(s, "/%d", cidr_bits); } else { ds_put_char(s, '/'); - print_ipv6_addr(s, mask); + ipv6_format_addr(mask, s); } } } diff --git a/lib/packets.h b/lib/packets.h index de8d4b643..6a52b3248 100644 --- a/lib/packets.h +++ b/lib/packets.h @@ -950,11 +950,10 @@ struct vxlanhdr { #define VXLAN_FLAGS 0x08000000 /* struct vxlanhdr.vx_flags required value. */ -void format_ipv6_addr(char *addr_str, const struct in6_addr *addr); -void print_ipv6_addr(struct ds *string, const struct in6_addr *addr); -void print_ipv6_mapped(struct ds *string, const struct in6_addr *addr); -void print_ipv6_masked(struct ds *string, const struct in6_addr *addr, - const struct in6_addr *mask); +void ipv6_format_addr(const struct in6_addr *addr, struct ds *); +void ipv6_format_mapped(const struct in6_addr *addr, struct ds *); +void ipv6_format_masked(const struct in6_addr *addr, + const struct in6_addr *mask, struct ds *); struct in6_addr ipv6_addr_bitand(const struct in6_addr *src, const struct in6_addr *mask); struct in6_addr ipv6_create_mask(int mask); diff --git a/lib/tnl-arp-cache.c b/lib/tnl-arp-cache.c index d817d6639..ceb156019 100644 --- a/lib/tnl-arp-cache.c +++ b/lib/tnl-arp-cache.c @@ -291,7 +291,7 @@ tnl_arp_cache_show(struct unixctl_conn *conn, int argc OVS_UNUSED, int start_len, need_ws; start_len = ds.length; - print_ipv6_mapped(&ds, &arp->ip); + ipv6_format_mapped(&arp->ip, &ds); need_ws = INET6_ADDRSTRLEN - (ds.length - start_len); ds_put_char_multiple(&ds, ' ', need_ws); diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index 49001e896..9fe565e1c 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -4540,7 +4540,7 @@ ofproto_unixctl_mcast_snooping_show(struct unixctl_conn *conn, ofputil_port_to_string(ofbundle_get_a_port(bundle)->up.ofp_port, name, sizeof name); ds_put_format(&ds, "%5s %4d ", name, grp->vlan); - print_ipv6_mapped(&ds, &grp->addr); + ipv6_format_mapped(&grp->addr, &ds); ds_put_format(&ds, " %3d\n", mcast_bundle_age(ofproto->ms, b)); } diff --git a/ofproto/tunnel.c b/ofproto/tunnel.c index 60e477376..1b92d0827 100644 --- a/ofproto/tunnel.c +++ b/ofproto/tunnel.c @@ -584,11 +584,11 @@ tnl_match_fmt(const struct tnl_match *match, struct ds *ds) OVS_REQ_RDLOCK(rwlock) { if (!match->ip_dst_flow) { - print_ipv6_mapped(ds, &match->ipv6_src); + ipv6_format_mapped(&match->ipv6_src, ds); ds_put_cstr(ds, "->"); - print_ipv6_mapped(ds, &match->ipv6_dst); + ipv6_format_mapped(&match->ipv6_dst, ds); } else if (!match->ip_src_flow) { - print_ipv6_mapped(ds, &match->ipv6_src); + ipv6_format_mapped(&match->ipv6_src, ds); ds_put_cstr(ds, "->flow"); } else { ds_put_cstr(ds, "flow->flow"); diff --git a/ovn/lib/lex.c b/ovn/lib/lex.c index cc8eb2858..fd906fd9a 100644 --- a/ovn/lib/lex.c +++ b/ovn/lib/lex.c @@ -117,7 +117,7 @@ lex_token_format_value(const union mf_subvalue *value, break; case LEX_F_IPV6: - print_ipv6_addr(s, &value->ipv6); + ipv6_format_addr(&value->ipv6, s); break; case LEX_F_ETHERNET: