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

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