@@ -78,18 +78,11 @@ bool ovn_lb_vip_init(struct ovn_lb_vip *lb_vip, const char *lb_key,
int addr_family;
if (!ip_address_and_port_from_lb_key(lb_key, &lb_vip->vip_str,
- &lb_vip->vip_port, &addr_family)) {
+ &lb_vip->vip, &lb_vip->vip_port,
+ &addr_family)) {
return false;
}
- if (addr_family == AF_INET) {
- ovs_be32 vip4;
- ip_parse(lb_vip->vip_str, &vip4);
- in6_addr_set_mapped_ipv4(&lb_vip->vip, vip4);
- } else {
- ipv6_parse(lb_vip->vip_str, &lb_vip->vip);
- }
-
/* Format for backend ips: "IP1:port1,IP2:port2,...". */
size_t n_backends = 0;
size_t n_allocated_backends = 0;
@@ -108,7 +101,7 @@ bool ovn_lb_vip_init(struct ovn_lb_vip *lb_vip, const char *lb_key,
struct ovn_lb_backend *backend = &lb_vip->backends[n_backends];
int backend_addr_family;
if (!ip_address_and_port_from_lb_key(token, &backend->ip_str,
- &backend->port,
+ &backend->ip, &backend->port,
&backend_addr_family)) {
continue;
}
@@ -118,13 +111,6 @@ bool ovn_lb_vip_init(struct ovn_lb_vip *lb_vip, const char *lb_key,
continue;
}
- if (addr_family == AF_INET) {
- ovs_be32 ip4;
- ip_parse(backend->ip_str, &ip4);
- in6_addr_set_mapped_ipv4(&backend->ip, ip4);
- } else {
- ipv6_parse(backend->ip_str, &backend->ip);
- }
n_backends++;
}
free(tokstr);
@@ -781,14 +781,15 @@ ovn_smap_get_uint(const struct smap *smap, const char *key, unsigned int def)
return u_value;
}
-/* For a 'key' of the form "IP:port" or just "IP", sets 'port' and
- * 'ip_address'. The caller must free() the memory allocated for
- * 'ip_address'.
+/* For a 'key' of the form "IP:port" or just "IP", sets 'port',
+ * 'ip_address' and 'ip' ('struct in6_addr' IPv6 or IPv4 mapped address).
+ * The caller must free() the memory allocated for 'ip_address'.
* Returns true if parsing of 'key' was successful, false otherwise.
*/
bool
ip_address_and_port_from_lb_key(const char *key, char **ip_address,
- uint16_t *port, int *addr_family)
+ struct in6_addr *ip, uint16_t *port,
+ int *addr_family)
{
struct sockaddr_storage ss;
if (!inet_parse_active(key, 0, &ss, false, NULL)) {
@@ -798,12 +799,14 @@ ip_address_and_port_from_lb_key(const char *key, char **ip_address,
*ip_address = NULL;
*port = 0;
*addr_family = 0;
+ memset(ip, 0, sizeof(*ip));
return false;
}
struct ds s = DS_EMPTY_INITIALIZER;
ss_format_address_nobracks(&ss, &s);
*ip_address = ds_steal_cstr(&s);
+ *ip = ss_get_address(&ss);
*port = ss_get_port(&ss);
*addr_family = ss.ss_family;
return true;
@@ -241,7 +241,8 @@ char *str_tolower(const char *orig);
case OVN_OPT_USER_GROUP:
bool ip_address_and_port_from_lb_key(const char *key, char **ip_address,
- uint16_t *port, int *addr_family);
+ struct in6_addr *ip, uint16_t *port,
+ int *addr_family);
/* Returns the internal OVN version. The caller must free the returned
* value. */
@@ -2601,23 +2601,15 @@ get_lb_vip_data(struct flow *uflow, struct in6_addr *vip,
SBREC_LOAD_BALANCER_FOR_EACH (sbdb, ovnsb_idl) {
struct smap_node *node;
SMAP_FOR_EACH (node, &sbdb->vips) {
- if (!ip_address_and_port_from_lb_key(node->key, vip_str,
- port, &family)) {
+ if (!ip_address_and_port_from_lb_key(node->key, vip_str, vip, port,
+ &family)) {
continue;
}
- if (family == AF_INET) {
- ovs_be32 vip4;
- ip_parse(*vip_str, &vip4);
- in6_addr_set_mapped_ipv4(vip, vip4);
- if (vip4 == uflow->ct_nw_dst) {
- return true;
- }
- } else {
- ipv6_parse(*vip_str, vip);
- if (ipv6_addr_equals(vip, &uflow->ct_ipv6_dst)) {
- return true;
- }
+ if ((family == AF_INET
+ && in6_addr_get_mapped_ipv4(vip) == uflow->ct_nw_dst)
+ || ipv6_addr_equals(vip, &uflow->ct_ipv6_dst)) {
+ return true;
}
free(*vip_str);
}