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

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