diff options
Diffstat (limited to 'usr/iface.c')
-rw-r--r-- | usr/iface.c | 67 |
1 files changed, 51 insertions, 16 deletions
diff --git a/usr/iface.c b/usr/iface.c index 21d52b3..9db73c3 100644 --- a/usr/iface.c +++ b/usr/iface.c @@ -445,25 +445,34 @@ int iface_get_by_net_binding(struct iface_rec *pattern, return ISCSI_ERR_NO_OBJS_FOUND; } -int iface_get_iptype(struct iface_rec *iface) +/* + * detect IPv4 vs IPv4 IP address + */ +enum iscsi_iface_type iface_get_iptype(struct iface_rec *iface) { + enum iscsi_iface_type res = ISCSI_IFACE_TYPE_IPV4; + /* address might not be set if user config with another tool */ if (!strlen(iface->ipaddress) || !strcmp(UNKNOWN_VALUE, iface->ipaddress)) { - /* try to figure out by name */ - if (strstr(iface->name, "ipv4")) - return ISCSI_IFACE_TYPE_IPV4; - else if (strstr(iface->name, "ipv6")) - return ISCSI_IFACE_TYPE_IPV6; - else /* assume ipv4 by default */ - return ISCSI_IFACE_TYPE_IPV4; + /* unknown or empty IP address: try to figure out by name */ + if (strstr(iface->name, "ipv6")) + res = ISCSI_IFACE_TYPE_IPV6; } else { + /* figure out what type of IP address string we have */ if (strcmp(iface->bootproto, "dhcp") && - !strstr(iface->ipaddress, ".")) - return ISCSI_IFACE_TYPE_IPV6; - else - return ISCSI_IFACE_TYPE_IPV4; + !strchr(iface->ipaddress, '.')) { + /* bootproto is NOT "dhcp", IP addr does NOT have a dot in it */ + res = ISCSI_IFACE_TYPE_IPV6; + } } + + log_debug(8, "iface: ipaddr=\"%s\" name=\"%s\" bootproto=\"%s\" -> %s", + iface->ipaddress, iface->name, + iface->bootproto, + res == ISCSI_IFACE_TYPE_IPV4 ? "IPv4" : "IPv6"); + + return res; } static int iface_setup_binding_from_kern_iface(void *data, @@ -986,6 +995,30 @@ void iface_link_ifaces(struct list_head *ifaces) iface_for_each_iface(ifaces, 1, &nr_found, iface_link); } +/* + * ipv6 address strings will have at least two colons + * + * NOTE: does NOT validate the IP address + */ +static bool ipaddr_is_ipv6(char *ipaddr) +{ + char *first_colon, *second_colon; + bool res = false; + + if (ipaddr) { + first_colon = strchr(ipaddr, ':'); + if (first_colon) { + second_colon = strchr(first_colon+1, ':'); + if (second_colon && + (second_colon != first_colon)) + res = true; + } + } + log_debug(8, "%s(%s) -> %u", + __FUNCTION__, ipaddr, res); + return res; +} + /** * iface_setup_from_boot_context - setup iface from boot context info * @iface: iface t setup @@ -1059,9 +1092,6 @@ int iface_setup_from_boot_context(struct iface_rec *iface, } strcpy(iface->transport_name, t->name); - memset(iface->name, 0, sizeof(iface->name)); - snprintf(iface->name, sizeof(iface->name), "%s.%s", - iface->transport_name, context->mac); strlcpy(iface->hwaddress, context->mac, sizeof(iface->hwaddress)); strlcpy(iface->ipaddress, context->ipaddr, @@ -1071,6 +1101,11 @@ int iface_setup_from_boot_context(struct iface_rec *iface, sizeof(iface->subnet_mask)); strlcpy(iface->gateway, context->gateway, sizeof(iface->gateway)); + snprintf(iface->name, sizeof(iface->name), "%s.%s.%s.%u", + iface->transport_name, context->mac, + ipaddr_is_ipv6(iface->ipaddress) ? "ipv6" : "ipv4", + iface->iface_num); + log_debug(1, "iface " iface_fmt "", iface_str(iface)); return 1; } @@ -1211,7 +1246,7 @@ static void iface_get_common_param_count(struct iface_rec *iface, int *count) static int __iface_get_param_count(void *data, struct iface_rec *iface) { struct iface_param_count *iface_params = data; - int iptype = ISCSI_IFACE_TYPE_IPV4; + enum iscsi_iface_type iptype; int count = 0; if (strcmp(iface_params->primary->hwaddress, iface->hwaddress)) |