Blame SOURCES/0045-iscsi-tools-Use-macro-to-set-IPv4-IPv6-IP-addresses.patch

786c6d
From 466efaad99b0fc0d1181443386b823739a8b483b Mon Sep 17 00:00:00 2001
786c6d
From: Harish Zunjarrao <harish.zunjarrao@qlogic.com>
786c6d
Date: Fri, 18 Oct 2013 09:29:20 -0400
786c6d
Subject: [PATCH] iscsi tools: Use macro to set IPv4/IPv6 IP addresses
786c6d
786c6d
Signed-off-by: Harish Zunjarrao <harish.zunjarrao@qlogic.com>
786c6d
Signed-off-by: Vikas Chaudhary <vikas.chaudhary@qlogic.com>
786c6d
Signed-off-by: Adheer Chandravanshi <adheer.chandravanshi@qlogic.com>
786c6d
---
786c6d
 usr/iface.c | 154 +++++++++++++++++++++++++++---------------------------------
786c6d
 1 file changed, 69 insertions(+), 85 deletions(-)
786c6d
786c6d
diff --git a/usr/iface.c b/usr/iface.c
786c6d
index 8580d1a..19ad5ab 100644
786c6d
--- a/usr/iface.c
786c6d
+++ b/usr/iface.c
786c6d
@@ -1484,8 +1484,8 @@ static int iface_fill_router_autocfg(struct iovec *iov, struct iface_rec *iface)
786c6d
 }
786c6d
 
786c6d
 /* IPv4 IPAddress/Subnet Mask/Gateway: 4 bytes */
786c6d
-static int iface_fill_net_ipv4_addr(struct iovec *iov, struct iface_rec *iface,
786c6d
-				    uint32_t param)
786c6d
+static int iface_fill_net_ipv4_addr(struct iovec *iov, uint32_t iface_num,
786c6d
+				    uint16_t param, char *param_val)
786c6d
 {
786c6d
 	int rc = 1;
786c6d
 	int len;
786c6d
@@ -1502,29 +1502,12 @@ static int iface_fill_net_ipv4_addr(struct iovec *iov, struct iface_rec *iface,
786c6d
 	net_param = (struct iscsi_iface_param_info *)ISCSI_NLA_DATA(attr);
786c6d
 	net_param->param = param;
786c6d
 	net_param->iface_type = ISCSI_IFACE_TYPE_IPV4;
786c6d
-	net_param->iface_num = iface->iface_num;
786c6d
+	net_param->iface_num = iface_num;
786c6d
 	net_param->len = 4;
786c6d
 	net_param->param_type = ISCSI_NET_PARAM;
786c6d
-
786c6d
-	switch (param) {
786c6d
-	case ISCSI_NET_PARAM_IPV4_ADDR:
786c6d
-		rc = inet_pton(AF_INET, iface->ipaddress, net_param->value);
786c6d
-		if (rc <= 0)
786c6d
-			goto free;
786c6d
-		break;
786c6d
-	case ISCSI_NET_PARAM_IPV4_SUBNET:
786c6d
-		rc = inet_pton(AF_INET, iface->subnet_mask, net_param->value);
786c6d
-		if (rc <= 0)
786c6d
-			goto free;
786c6d
-		break;
786c6d
-	case ISCSI_NET_PARAM_IPV4_GW:
786c6d
-		rc = inet_pton(AF_INET, iface->gateway, net_param->value);
786c6d
-		if (rc <= 0)
786c6d
-			goto free;
786c6d
-		break;
786c6d
-	default:
786c6d
+	rc = inet_pton(AF_INET, param_val, net_param->value);
786c6d
+	if (rc <= 0)
786c6d
 		goto free;
786c6d
-	}
786c6d
 
786c6d
 	/* validate */
786c6d
 	if (!net_param->value[0] && !net_param->value[1] &&
786c6d
@@ -1539,9 +1522,19 @@ free:
786c6d
 	return 1;
786c6d
 }
786c6d
 
786c6d
+#define IFACE_SET_NET_PARAM_IPV4_ADDR(iov, inum, param, ival, gcnt,	\
786c6d
+				      lcnt) {				\
786c6d
+	if (strstr(ival, ".")) {					\
786c6d
+		if (!iface_fill_net_ipv4_addr(iov, inum, param, ival)) {\
786c6d
+			(*gcnt)++;					\
786c6d
+			(*lcnt)++;					\
786c6d
+		}							\
786c6d
+	}								\
786c6d
+}
786c6d
+
786c6d
 /* IPv6 IPAddress/LinkLocal/Router: 16 bytes */
786c6d
-static int iface_fill_net_ipv6_addr(struct iovec *iov, struct iface_rec *iface,
786c6d
-				    uint32_t param)
786c6d
+static int iface_fill_net_ipv6_addr(struct iovec *iov, uint32_t iface_num,
786c6d
+				    uint16_t param, char *param_val)
786c6d
 {
786c6d
 	int rc;
786c6d
 	int len;
786c6d
@@ -1558,30 +1551,12 @@ static int iface_fill_net_ipv6_addr(struct iovec *iov, struct iface_rec *iface,
786c6d
 	net_param = (struct iscsi_iface_param_info *)ISCSI_NLA_DATA(attr);
786c6d
 	net_param->param = param;
786c6d
 	net_param->iface_type = ISCSI_IFACE_TYPE_IPV6;
786c6d
-	net_param->iface_num = iface->iface_num;
786c6d
+	net_param->iface_num = iface_num;
786c6d
 	net_param->param_type = ISCSI_NET_PARAM;
786c6d
 	net_param->len = 16;
786c6d
-
786c6d
-	switch (param) {
786c6d
-	case ISCSI_NET_PARAM_IPV6_ADDR:
786c6d
-		rc = inet_pton(AF_INET6, iface->ipaddress, net_param->value);
786c6d
-		if (rc <= 0)
786c6d
-			goto free;
786c6d
-		break;
786c6d
-	case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
786c6d
-		rc = inet_pton(AF_INET6, iface->ipv6_linklocal,
786c6d
-			       net_param->value);
786c6d
-		if (rc <= 0)
786c6d
-			goto free;
786c6d
-		break;
786c6d
-	case ISCSI_NET_PARAM_IPV6_ROUTER:
786c6d
-		rc = inet_pton(AF_INET6, iface->ipv6_router, net_param->value);
786c6d
-		if (rc <= 0)
786c6d
-			goto free;
786c6d
-		break;
786c6d
-	default:
786c6d
+	rc = inet_pton(AF_INET6, param_val, net_param->value);
786c6d
+	if (rc <= 0)
786c6d
 		goto free;
786c6d
-	}
786c6d
 
786c6d
 	return 0;
786c6d
 free:
786c6d
@@ -1591,6 +1566,16 @@ free:
786c6d
 	return 1;
786c6d
 }
786c6d
 
786c6d
+#define IFACE_SET_NET_PARAM_IPV6_ADDR(iov, inum, param, ival, gcnt,	\
786c6d
+				      lcnt) {				\
786c6d
+	if (strstr(ival, ":")) {					\
786c6d
+		if (!iface_fill_net_ipv6_addr(iov, inum, param, ival)) {\
786c6d
+			(*gcnt)++;					\
786c6d
+			(*lcnt)++;					\
786c6d
+		}							\
786c6d
+	}								\
786c6d
+}
786c6d
+
786c6d
 struct iface_net_config {
786c6d
 	struct iface_rec *primary;
786c6d
 	struct iovec *iovs;
786c6d
@@ -1635,28 +1620,27 @@ static int __iface_build_net_config(void *data, struct iface_rec *iface)
786c6d
 				net_config->count++;
786c6d
 				count++;
786c6d
 			}
786c6d
-			if (!iface_fill_net_ipv4_addr(&iov[net_config->count],
786c6d
-						iface,
786c6d
-						ISCSI_NET_PARAM_IPV4_ADDR)) {
786c6d
-				net_config->count++;
786c6d
-				count++;
786c6d
-			}
786c6d
-			if (strstr(iface->subnet_mask, ".")) {
786c6d
-				if (!iface_fill_net_ipv4_addr(
786c6d
-						&iov[net_config->count], iface,
786c6d
-						ISCSI_NET_PARAM_IPV4_SUBNET)) {
786c6d
-					net_config->count++;
786c6d
-					count++;
786c6d
-				}
786c6d
-			}
786c6d
-			if (strstr(iface->gateway, ".")) {
786c6d
-				if (!iface_fill_net_ipv4_addr(
786c6d
-						&iov[net_config->count], iface,
786c6d
-						ISCSI_NET_PARAM_IPV4_GW)) {
786c6d
-					net_config->count++;
786c6d
-					count++;
786c6d
-				}
786c6d
-			}
786c6d
+
786c6d
+			IFACE_SET_NET_PARAM_IPV4_ADDR(&iov[net_config->count],
786c6d
+						      iface->iface_num,
786c6d
+						      ISCSI_NET_PARAM_IPV4_ADDR,
786c6d
+						      iface->ipaddress,
786c6d
+						      &net_config->count,
786c6d
+						      &count);
786c6d
+
786c6d
+			IFACE_SET_NET_PARAM_IPV4_ADDR(&iov[net_config->count],
786c6d
+						    iface->iface_num,
786c6d
+						    ISCSI_NET_PARAM_IPV4_SUBNET,
786c6d
+						    iface->subnet_mask,
786c6d
+						    &net_config->count,
786c6d
+						    &count);
786c6d
+
786c6d
+			IFACE_SET_NET_PARAM_IPV4_ADDR(&iov[net_config->count],
786c6d
+						      iface->iface_num,
786c6d
+						      ISCSI_NET_PARAM_IPV4_GW,
786c6d
+						      iface->gateway,
786c6d
+						      &net_config->count,
786c6d
+						      &count);
786c6d
 		}
786c6d
 
786c6d
 		/*
786c6d
@@ -1727,12 +1711,12 @@ static int __iface_build_net_config(void *data, struct iface_rec *iface)
786c6d
 				count++;
786c6d
 			}
786c6d
 			/* User provided IPv6 Address */
786c6d
-			if (!iface_fill_net_ipv6_addr(&iov[net_config->count],
786c6d
-						iface,
786c6d
-						ISCSI_NET_PARAM_IPV6_ADDR)) {
786c6d
-				net_config->count++;
786c6d
-				count++;
786c6d
-			}
786c6d
+			IFACE_SET_NET_PARAM_IPV6_ADDR(&iov[net_config->count],
786c6d
+						      iface->iface_num,
786c6d
+						      ISCSI_NET_PARAM_IPV6_ADDR,
786c6d
+						      iface->ipaddress,
786c6d
+						      &net_config->count,
786c6d
+						      &count);
786c6d
 		}
786c6d
 
786c6d
 		/* For LinkLocal Address */
786c6d
@@ -1751,12 +1735,12 @@ static int __iface_build_net_config(void *data, struct iface_rec *iface)
786c6d
 				count++;
786c6d
 			}
786c6d
 			/* User provided Link Local Address */
786c6d
-			if (!iface_fill_net_ipv6_addr(&iov[net_config->count],
786c6d
-					iface,
786c6d
-					ISCSI_NET_PARAM_IPV6_LINKLOCAL)) {
786c6d
-				net_config->count++;
786c6d
-				count++;
786c6d
-			}
786c6d
+			IFACE_SET_NET_PARAM_IPV6_ADDR(&iov[net_config->count],
786c6d
+						 iface->iface_num,
786c6d
+						 ISCSI_NET_PARAM_IPV6_LINKLOCAL,
786c6d
+						 iface->ipv6_linklocal,
786c6d
+						 &net_config->count,
786c6d
+						 &count);
786c6d
 		}
786c6d
 
786c6d
 		/* For Router Address */
786c6d
@@ -1773,12 +1757,12 @@ static int __iface_build_net_config(void *data, struct iface_rec *iface)
786c6d
 				count++;
786c6d
 			}
786c6d
 			/* User provided Router Address */
786c6d
-			if (!iface_fill_net_ipv6_addr(&iov[net_config->count],
786c6d
-						iface,
786c6d
-						ISCSI_NET_PARAM_IPV6_ROUTER)) {
786c6d
-				net_config->count++;
786c6d
-				count++;
786c6d
-			}
786c6d
+			IFACE_SET_NET_PARAM_IPV6_ADDR(&iov[net_config->count],
786c6d
+						    iface->iface_num,
786c6d
+						    ISCSI_NET_PARAM_IPV6_ROUTER,
786c6d
+						    iface->ipv6_router,
786c6d
+						    &net_config->count,
786c6d
+						    &count);
786c6d
 		}
786c6d
 
786c6d
 		/*
786c6d
-- 
786c6d
1.8.3.1
786c6d