summaryrefslogtreecommitdiff
path: root/ovn/northd
diff options
context:
space:
mode:
authorBen Pfaff <blp@ovn.org>2018-04-11 10:39:38 -0700
committerBen Pfaff <blp@ovn.org>2018-04-16 14:51:03 -0700
commit51b8505b66d4d570804305ea5874a6db44cf53ba (patch)
tree99bf3caf0ca887f727727df8a09f56bd384faed2 /ovn/northd
parentb1b8f0cbfa105f2df2528b106658ef1d6c6a1666 (diff)
downloadopenvswitch-51b8505b66d4d570804305ea5874a6db44cf53ba.tar.gz
ovn-northd: Use common code for sockaddr_storage.
This better reuses existing code. It does require adding a slight variant on ss_format_address(), but it still seems like a net win. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Mark Michelson <mmichels@redhat.com>
Diffstat (limited to 'ovn/northd')
-rw-r--r--ovn/northd/ovn-northd.c22
1 files changed, 6 insertions, 16 deletions
diff --git a/ovn/northd/ovn-northd.c b/ovn/northd/ovn-northd.c
index b55f5f8eb..6ffebde12 100644
--- a/ovn/northd/ovn-northd.c
+++ b/ovn/northd/ovn-northd.c
@@ -2942,29 +2942,19 @@ ip_address_and_port_from_lb_key(const char *key, char **ip_address,
uint16_t *port, int *addr_family)
{
struct sockaddr_storage ss;
- char ip_addr_buf[INET6_ADDRSTRLEN];
- char *error;
-
- error = ipv46_parse(key, PORT_OPTIONAL, &ss);
- if (error) {
+ if (!inet_parse_active(key, 0, &ss)) {
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 1);
VLOG_WARN_RL(&rl, "bad ip address or port for load balancer key %s",
key);
- free(error);
return;
}
- if (ss.ss_family == AF_INET) {
- struct sockaddr_in *sin = ALIGNED_CAST(struct sockaddr_in *, &ss);
- *port = sin->sin_port == 0 ? 0 : ntohs(sin->sin_port);
- inet_ntop(AF_INET, &sin->sin_addr, ip_addr_buf, sizeof ip_addr_buf);
- } else {
- struct sockaddr_in6 *sin6 = ALIGNED_CAST(struct sockaddr_in6 *, &ss);
- *port = sin6->sin6_port == 0 ? 0 : ntohs(sin6->sin6_port);
- inet_ntop(AF_INET6, &sin6->sin6_addr, ip_addr_buf, sizeof ip_addr_buf);
- }
+ struct ds s = DS_EMPTY_INITIALIZER;
+ ss_format_address_nobracks(&ss, &s);
+ *ip_address = ds_steal_cstr(&s);
+
+ *port = ss_get_port(&ss);
- *ip_address = xstrdup(ip_addr_buf);
*addr_family = ss.ss_family;
}