a288e4f
From 2220ee4334637946e93dca5c68889b5e3e807515 Mon Sep 17 00:00:00 2001
a288e4f
From: Harish Zunjarrao <harish.zunjarrao@qlogic.com>
a288e4f
Date: Fri, 18 Oct 2013 09:29:21 -0400
a288e4f
Subject: [PATCH] iscsi tools: Use single function to enable/disable network
a288e4f
 parameters
a288e4f
a288e4f
Signed-off-by: Harish Zunjarrao <harish.zunjarrao@qlogic.com>
a288e4f
Signed-off-by: Adheer Chandravanshi <adheer.chandravanshi@qlogic.com>
a288e4f
Signed-off-by: Vikas Chaudhary <vikas.chaudhary@qlogic.com>
a288e4f
---
a288e4f
 usr/iface.c | 148 ++++++++++++++++++++++++++++++------------------------------
a288e4f
 1 file changed, 74 insertions(+), 74 deletions(-)
a288e4f
a288e4f
diff --git a/usr/iface.c b/usr/iface.c
a288e4f
index 19ad5ab..292c804 100644
a288e4f
--- a/usr/iface.c
a288e4f
+++ b/usr/iface.c
a288e4f
@@ -1311,60 +1311,45 @@ static int iface_fill_vlan_id(struct iovec *iov, struct iface_rec *iface,
a288e4f
 	return 0;
a288e4f
 }
a288e4f
 
a288e4f
-/* IPv4/IPv6 VLAN state: disable/enable */
a288e4f
-static int iface_fill_vlan_state(struct iovec *iov, struct iface_rec *iface,
a288e4f
-				 uint32_t iface_type)
a288e4f
+/* disable/enable parameters */
a288e4f
+static int iface_fill_param_state(struct iovec *iov, uint32_t iface_num,
a288e4f
+				  uint8_t iface_type, uint16_t param,
a288e4f
+				  uint8_t param_type, char *param_val)
a288e4f
 {
a288e4f
 	int len;
a288e4f
 	struct iscsi_iface_param_info *net_param;
a288e4f
 	struct nlattr *attr;
a288e4f
 
a288e4f
+	if (!param_val[0])
a288e4f
+		return 1;
a288e4f
+
a288e4f
 	len = sizeof(struct iscsi_iface_param_info) + 1;
a288e4f
-	iov->iov_base = iscsi_nla_alloc(ISCSI_NET_PARAM_VLAN_ENABLED, len);
a288e4f
+	iov->iov_base = iscsi_nla_alloc(param, len);
a288e4f
 	if (!(iov->iov_base))
a288e4f
 		return 1;
a288e4f
 
a288e4f
 	attr = iov->iov_base;
a288e4f
 	iov->iov_len = NLA_ALIGN(attr->nla_len);
a288e4f
 	net_param = (struct iscsi_iface_param_info *)ISCSI_NLA_DATA(attr);
a288e4f
-	net_param->param = ISCSI_NET_PARAM_VLAN_ENABLED;
a288e4f
-	net_param->iface_type = iface_type;
a288e4f
-	net_param->iface_num = iface->iface_num;
a288e4f
-	net_param->param_type = ISCSI_NET_PARAM;
a288e4f
+	net_param->iface_num = iface_num;
a288e4f
 	net_param->len = 1;
a288e4f
-	if (strcmp(iface->vlan_state, "disable") && iface->vlan_id)
a288e4f
-		net_param->value[0] = ISCSI_VLAN_ENABLE;
a288e4f
+	net_param->param = param;
a288e4f
+	net_param->iface_type = iface_type;
a288e4f
+	net_param->param_type = param_type;
a288e4f
+	if (strcmp(param_val, "disable"))
a288e4f
+		net_param->value[0] = ISCSI_NET_PARAM_ENABLE;
a288e4f
 	else /* Assume disabled */
a288e4f
-		net_param->value[0] = ISCSI_VLAN_DISABLE;
a288e4f
+		net_param->value[0] = ISCSI_NET_PARAM_DISABLE;
a288e4f
 	return 0;
a288e4f
 }
a288e4f
 
a288e4f
-/* IPv4/IPv6 Network state: disable/enable */
a288e4f
-static int iface_fill_net_state(struct iovec *iov, struct iface_rec *iface,
a288e4f
-				uint32_t iface_type)
a288e4f
-{
a288e4f
-	int len;
a288e4f
-	struct iscsi_iface_param_info *net_param;
a288e4f
-	struct nlattr *attr;
a288e4f
-
a288e4f
-	len = sizeof(struct iscsi_iface_param_info) + 1;
a288e4f
-	iov->iov_base = iscsi_nla_alloc(ISCSI_NET_PARAM_IFACE_ENABLE, len);
a288e4f
-	if (!(iov->iov_base))
a288e4f
-		return 1;
a288e4f
-
a288e4f
-	attr = iov->iov_base;
a288e4f
-	iov->iov_len = NLA_ALIGN(attr->nla_len);
a288e4f
-	net_param = (struct iscsi_iface_param_info *)ISCSI_NLA_DATA(attr);
a288e4f
-	net_param->param = ISCSI_NET_PARAM_IFACE_ENABLE;
a288e4f
-	net_param->iface_type = iface_type;
a288e4f
-	net_param->iface_num = iface->iface_num;
a288e4f
-	net_param->param_type = ISCSI_NET_PARAM;
a288e4f
-	net_param->len = 1;
a288e4f
-	if (!strcmp(iface->state, "disable"))
a288e4f
-		net_param->value[0] = ISCSI_IFACE_DISABLE;
a288e4f
-	else /* Assume enabled */
a288e4f
-		net_param->value[0] = ISCSI_IFACE_ENABLE;
a288e4f
-	return 0;
a288e4f
+#define IFACE_SET_PARAM_STATE(iov, inum, itype, param, ptype, ival,	\
a288e4f
+			      gcnt, lcnt) {				\
a288e4f
+	if (!iface_fill_param_state(iov, inum, itype, param, ptype,	\
a288e4f
+				    ival)) {				\
a288e4f
+		(*gcnt)++;						\
a288e4f
+		(*lcnt)++;						\
a288e4f
+	}								\
a288e4f
 }
a288e4f
 
a288e4f
 /* IPv4 Bootproto: DHCP/static */
a288e4f
@@ -1598,13 +1583,14 @@ static int __iface_build_net_config(void *data, struct iface_rec *iface)
a288e4f
 	iptype = iface_get_iptype(iface);
a288e4f
 	if (iptype == ISCSI_IFACE_TYPE_IPV4) {
a288e4f
 		if (!strcmp(iface->state, "disable")) {
a288e4f
-			if (!iface_fill_net_state(&iov[net_config->count],
a288e4f
-						  iface,
a288e4f
-						  ISCSI_IFACE_TYPE_IPV4)) {
a288e4f
-				net_config->count++;
a288e4f
-				count++;
a288e4f
-			}
a288e4f
-
a288e4f
+			IFACE_SET_PARAM_STATE(&iov[net_config->count],
a288e4f
+					      iface->iface_num,
a288e4f
+					      ISCSI_IFACE_TYPE_IPV4,
a288e4f
+					      ISCSI_NET_PARAM_IFACE_ENABLE,
a288e4f
+					      ISCSI_NET_PARAM,
a288e4f
+					      iface->state,
a288e4f
+					      &net_config->count,
a288e4f
+					      &count);
a288e4f
 			return 0;
a288e4f
 		}
a288e4f
 
a288e4f
@@ -1648,18 +1634,24 @@ static int __iface_build_net_config(void *data, struct iface_rec *iface)
a288e4f
 		 * fill state and other parameters (if any)
a288e4f
 		 */
a288e4f
 		if (count) {
a288e4f
-			if (!iface_fill_net_state(&iov[net_config->count],
a288e4f
-						  iface,
a288e4f
-						  ISCSI_IFACE_TYPE_IPV4)) {
a288e4f
-				net_config->count++;
a288e4f
-				count++;
a288e4f
-			}
a288e4f
-			if (!iface_fill_vlan_state(&iov[net_config->count],
a288e4f
-						iface,
a288e4f
-						ISCSI_IFACE_TYPE_IPV4)) {
a288e4f
-				net_config->count++;
a288e4f
-				count++;
a288e4f
-			}
a288e4f
+			IFACE_SET_PARAM_STATE(&iov[net_config->count],
a288e4f
+					      iface->iface_num,
a288e4f
+					      ISCSI_IFACE_TYPE_IPV4,
a288e4f
+					      ISCSI_NET_PARAM_IFACE_ENABLE,
a288e4f
+					      ISCSI_NET_PARAM,
a288e4f
+					      iface->state,
a288e4f
+					      &net_config->count,
a288e4f
+					      &count);
a288e4f
+
a288e4f
+			IFACE_SET_PARAM_STATE(&iov[net_config->count],
a288e4f
+					      iface->iface_num,
a288e4f
+					      ISCSI_IFACE_TYPE_IPV4,
a288e4f
+					      ISCSI_NET_PARAM_VLAN_ENABLED,
a288e4f
+					      ISCSI_NET_PARAM,
a288e4f
+					      iface->vlan_state,
a288e4f
+					      &net_config->count,
a288e4f
+					      &count);
a288e4f
+
a288e4f
 			if (strcmp(iface->vlan_state, "disable") &&
a288e4f
 			    iface->vlan_id) {
a288e4f
 				if (!iface_fill_vlan_id(&iov[net_config->count],
a288e4f
@@ -1687,12 +1679,14 @@ static int __iface_build_net_config(void *data, struct iface_rec *iface)
a288e4f
 		}
a288e4f
 	} else if (iptype == ISCSI_IFACE_TYPE_IPV6) {
a288e4f
 		if (!strcmp(iface->state, "disable")) {
a288e4f
-			if (!iface_fill_net_state(&iov[net_config->count],
a288e4f
-						  iface,
a288e4f
-						  ISCSI_IFACE_TYPE_IPV6)) {
a288e4f
-				net_config->count++;
a288e4f
-				count++;
a288e4f
-			}
a288e4f
+			IFACE_SET_PARAM_STATE(&iov[net_config->count],
a288e4f
+					      iface->iface_num,
a288e4f
+					      ISCSI_IFACE_TYPE_IPV6,
a288e4f
+					      ISCSI_NET_PARAM_IFACE_ENABLE,
a288e4f
+					      ISCSI_NET_PARAM,
a288e4f
+					      iface->state,
a288e4f
+					      &net_config->count,
a288e4f
+					      &count);
a288e4f
 			return 0;
a288e4f
 		}
a288e4f
 
a288e4f
@@ -1770,18 +1764,24 @@ static int __iface_build_net_config(void *data, struct iface_rec *iface)
a288e4f
 		 * fill state and other parameters
a288e4f
 		 */
a288e4f
 		if (count) {
a288e4f
-			if (!iface_fill_net_state(&iov[net_config->count],
a288e4f
-						  iface,
a288e4f
-						  ISCSI_IFACE_TYPE_IPV6)) {
a288e4f
-				net_config->count++;
a288e4f
-				count++;
a288e4f
-			}
a288e4f
-			if (!iface_fill_vlan_state(&iov[net_config->count],
a288e4f
-						   iface,
a288e4f
-						   ISCSI_IFACE_TYPE_IPV6)) {
a288e4f
-				net_config->count++;
a288e4f
-				count++;
a288e4f
-			}
a288e4f
+			IFACE_SET_PARAM_STATE(&iov[net_config->count],
a288e4f
+					      iface->iface_num,
a288e4f
+					      ISCSI_IFACE_TYPE_IPV6,
a288e4f
+					      ISCSI_NET_PARAM_IFACE_ENABLE,
a288e4f
+					      ISCSI_NET_PARAM,
a288e4f
+					      iface->state,
a288e4f
+					      &net_config->count,
a288e4f
+					      &count);
a288e4f
+
a288e4f
+			IFACE_SET_PARAM_STATE(&iov[net_config->count],
a288e4f
+					      iface->iface_num,
a288e4f
+					      ISCSI_IFACE_TYPE_IPV6,
a288e4f
+					      ISCSI_NET_PARAM_VLAN_ENABLED,
a288e4f
+					      ISCSI_NET_PARAM,
a288e4f
+					      iface->vlan_state,
a288e4f
+					      &net_config->count,
a288e4f
+					      &count);
a288e4f
+
a288e4f
 			if (strcmp(iface->vlan_state, "disable") &&
a288e4f
 			    iface->vlan_id) {
a288e4f
 				if (!iface_fill_vlan_id(&iov[net_config->count],
a288e4f
-- 
a288e4f
1.8.3.1
a288e4f