|
|
786c6d |
From d8991c9e1de373a1c55ad2f8ca07bb3fbda1aa5c Mon Sep 17 00:00:00 2001
|
|
|
786c6d |
From: Harish Zunjarrao <harish.zunjarrao@qlogic.com>
|
|
|
786c6d |
Date: Fri, 18 Oct 2013 09:29:22 -0400
|
|
|
786c6d |
Subject: [PATCH] iscsi tools: Use single function to set integer network
|
|
|
786c6d |
parameters
|
|
|
786c6d |
|
|
|
786c6d |
Signed-off-by: Harish Zunjarrao <harish.zunjarrao@qlogic.com>
|
|
|
786c6d |
Signed-off-by: Adheer Chandravanshi <adheer.chandravanshi@qlogic.com>
|
|
|
786c6d |
Signed-off-by: Vikas Chaudhary <vikas.chaudhary@qlogic.com>
|
|
|
786c6d |
---
|
|
|
786c6d |
usr/iface.c | 162 +++++++++++++++++++++++++++++++++---------------------------
|
|
|
786c6d |
1 file changed, 90 insertions(+), 72 deletions(-)
|
|
|
786c6d |
|
|
|
786c6d |
diff --git a/usr/iface.c b/usr/iface.c
|
|
|
786c6d |
index 292c804..6454f75 100644
|
|
|
786c6d |
--- a/usr/iface.c
|
|
|
786c6d |
+++ b/usr/iface.c
|
|
|
786c6d |
@@ -1223,58 +1223,68 @@ int iface_get_param_count(struct iface_rec *iface, int iface_all)
|
|
|
786c6d |
return iface_params.count;
|
|
|
786c6d |
}
|
|
|
786c6d |
|
|
|
786c6d |
-/* IPv4/IPv6 Port: 3260 or User defined */
|
|
|
786c6d |
-static int iface_fill_port(struct iovec *iov, struct iface_rec *iface,
|
|
|
786c6d |
- uint32_t iface_type)
|
|
|
786c6d |
+/* write integer parameter value */
|
|
|
786c6d |
+static int iface_fill_int_param_val(struct iovec *iov, uint32_t iface_num,
|
|
|
786c6d |
+ uint8_t iface_type, uint16_t param,
|
|
|
786c6d |
+ uint8_t param_type, uint32_t param_len,
|
|
|
786c6d |
+ uint32_t param_val)
|
|
|
786c6d |
{
|
|
|
786c6d |
int len;
|
|
|
786c6d |
struct iscsi_iface_param_info *net_param;
|
|
|
786c6d |
- uint16_t port = 3260;
|
|
|
786c6d |
struct nlattr *attr;
|
|
|
786c6d |
+ uint8_t val8 = 0;
|
|
|
786c6d |
+ uint16_t val16 = 0;
|
|
|
786c6d |
+ uint32_t val32 = 0;
|
|
|
786c6d |
+ char *val = NULL;
|
|
|
786c6d |
|
|
|
786c6d |
- len = sizeof(struct iscsi_iface_param_info) + sizeof(port);
|
|
|
786c6d |
- iov->iov_base = iscsi_nla_alloc(ISCSI_NET_PARAM_PORT, len);
|
|
|
786c6d |
- if (!iov->iov_base)
|
|
|
786c6d |
- return 1;
|
|
|
786c6d |
- attr = iov->iov_base;
|
|
|
786c6d |
- iov->iov_len = NLA_ALIGN(attr->nla_len);
|
|
|
786c6d |
-
|
|
|
786c6d |
- net_param = (struct iscsi_iface_param_info *)ISCSI_NLA_DATA(attr);
|
|
|
786c6d |
- net_param->param = ISCSI_NET_PARAM_PORT;
|
|
|
786c6d |
- net_param->iface_type = iface_type;
|
|
|
786c6d |
- net_param->iface_num = iface->iface_num;
|
|
|
786c6d |
- net_param->param_type = ISCSI_NET_PARAM;
|
|
|
786c6d |
- net_param->len = 2;
|
|
|
786c6d |
- if (iface->port)
|
|
|
786c6d |
- port = iface->port;
|
|
|
786c6d |
- memcpy(net_param->value, &port, net_param->len);
|
|
|
786c6d |
- return 0;
|
|
|
786c6d |
-}
|
|
|
786c6d |
-
|
|
|
786c6d |
-static int iface_fill_mtu(struct iovec *iov, struct iface_rec *iface,
|
|
|
786c6d |
- uint32_t iface_type)
|
|
|
786c6d |
-{
|
|
|
786c6d |
- int len;
|
|
|
786c6d |
- struct iscsi_iface_param_info *net_param;
|
|
|
786c6d |
- uint16_t mtu = 0;
|
|
|
786c6d |
- struct nlattr *attr;
|
|
|
786c6d |
-
|
|
|
786c6d |
- len = sizeof(struct iscsi_iface_param_info) + 2;
|
|
|
786c6d |
- iov->iov_base = iscsi_nla_alloc(ISCSI_NET_PARAM_MTU, len);
|
|
|
786c6d |
+ len = sizeof(struct iscsi_iface_param_info) + param_len;
|
|
|
786c6d |
+ iov->iov_base = iscsi_nla_alloc(param, len);
|
|
|
786c6d |
if (!(iov->iov_base))
|
|
|
786c6d |
return 1;
|
|
|
786c6d |
+
|
|
|
786c6d |
attr = iov->iov_base;
|
|
|
786c6d |
iov->iov_len = NLA_ALIGN(attr->nla_len);
|
|
|
786c6d |
-
|
|
|
786c6d |
net_param = (struct iscsi_iface_param_info *)ISCSI_NLA_DATA(attr);
|
|
|
786c6d |
- net_param->param = ISCSI_NET_PARAM_MTU;
|
|
|
786c6d |
+ net_param->iface_num = iface_num;
|
|
|
786c6d |
+ net_param->len = param_len;
|
|
|
786c6d |
+ net_param->param = param;
|
|
|
786c6d |
net_param->iface_type = iface_type;
|
|
|
786c6d |
- net_param->iface_num = iface->iface_num;
|
|
|
786c6d |
- net_param->param_type = ISCSI_NET_PARAM;
|
|
|
786c6d |
- net_param->len = 2;
|
|
|
786c6d |
- mtu = iface->mtu;
|
|
|
786c6d |
- memcpy(net_param->value, &mtu, net_param->len);
|
|
|
786c6d |
+ net_param->param_type = param_type;
|
|
|
786c6d |
+ switch (param_len) {
|
|
|
786c6d |
+ case 1:
|
|
|
786c6d |
+ val8 = (uint8_t)param_val;
|
|
|
786c6d |
+ val = (char *)&val;;
|
|
|
786c6d |
+ break;
|
|
|
786c6d |
+
|
|
|
786c6d |
+ case 2:
|
|
|
786c6d |
+ val16 = (uint16_t)param_val;
|
|
|
786c6d |
+ val = (char *)&val16;
|
|
|
786c6d |
+ break;
|
|
|
786c6d |
+
|
|
|
786c6d |
+ case 4:
|
|
|
786c6d |
+ val32 = (uint32_t)param_val;
|
|
|
786c6d |
+ val = (char *)&val32;
|
|
|
786c6d |
+ break;
|
|
|
786c6d |
+
|
|
|
786c6d |
+ default:
|
|
|
786c6d |
+ goto free;
|
|
|
786c6d |
+ }
|
|
|
786c6d |
+ memcpy(net_param->value, val, param_len);
|
|
|
786c6d |
return 0;
|
|
|
786c6d |
+free:
|
|
|
786c6d |
+ free(iov->iov_base);
|
|
|
786c6d |
+ iov->iov_base = NULL;
|
|
|
786c6d |
+ iov->iov_len = 0;
|
|
|
786c6d |
+ return 1;
|
|
|
786c6d |
+}
|
|
|
786c6d |
+
|
|
|
786c6d |
+#define IFACE_SET_PARAM_INTVAL(iov, inum, itype, param, ptype, plen, \
|
|
|
786c6d |
+ ival, gcnt, lcnt) { \
|
|
|
786c6d |
+ if (ival && !iface_fill_int_param_val(iov, inum, itype, param, \
|
|
|
786c6d |
+ ptype, plen, ival)) { \
|
|
|
786c6d |
+ (*gcnt)++; \
|
|
|
786c6d |
+ (*lcnt)++; \
|
|
|
786c6d |
+ } \
|
|
|
786c6d |
}
|
|
|
786c6d |
|
|
|
786c6d |
/* IPv4/IPv6 VLAN_ID: decimal value <= 4095 */
|
|
|
786c6d |
@@ -1660,22 +1670,26 @@ static int __iface_build_net_config(void *data, struct iface_rec *iface)
|
|
|
786c6d |
count++;
|
|
|
786c6d |
}
|
|
|
786c6d |
}
|
|
|
786c6d |
- if (iface->mtu) {
|
|
|
786c6d |
- if (!iface_fill_mtu(&iov[net_config->count],
|
|
|
786c6d |
- iface,
|
|
|
786c6d |
- ISCSI_IFACE_TYPE_IPV4)) {
|
|
|
786c6d |
- net_config->count++;
|
|
|
786c6d |
- count++;
|
|
|
786c6d |
- }
|
|
|
786c6d |
- }
|
|
|
786c6d |
- if (iface->port) {
|
|
|
786c6d |
- if (!iface_fill_port(&iov[net_config->count],
|
|
|
786c6d |
- iface,
|
|
|
786c6d |
- ISCSI_IFACE_TYPE_IPV4)) {
|
|
|
786c6d |
- net_config->count++;
|
|
|
786c6d |
- count++;
|
|
|
786c6d |
- }
|
|
|
786c6d |
- }
|
|
|
786c6d |
+
|
|
|
786c6d |
+ IFACE_SET_PARAM_INTVAL(&iov[net_config->count],
|
|
|
786c6d |
+ iface->iface_num,
|
|
|
786c6d |
+ ISCSI_IFACE_TYPE_IPV4,
|
|
|
786c6d |
+ ISCSI_NET_PARAM_MTU,
|
|
|
786c6d |
+ ISCSI_NET_PARAM,
|
|
|
786c6d |
+ 2,
|
|
|
786c6d |
+ iface->mtu,
|
|
|
786c6d |
+ &net_config->count,
|
|
|
786c6d |
+ &count);
|
|
|
786c6d |
+
|
|
|
786c6d |
+ IFACE_SET_PARAM_INTVAL(&iov[net_config->count],
|
|
|
786c6d |
+ iface->iface_num,
|
|
|
786c6d |
+ ISCSI_IFACE_TYPE_IPV4,
|
|
|
786c6d |
+ ISCSI_NET_PARAM_PORT,
|
|
|
786c6d |
+ ISCSI_NET_PARAM,
|
|
|
786c6d |
+ 2,
|
|
|
786c6d |
+ iface->port,
|
|
|
786c6d |
+ &net_config->count,
|
|
|
786c6d |
+ &count);
|
|
|
786c6d |
}
|
|
|
786c6d |
} else if (iptype == ISCSI_IFACE_TYPE_IPV6) {
|
|
|
786c6d |
if (!strcmp(iface->state, "disable")) {
|
|
|
786c6d |
@@ -1791,22 +1805,26 @@ static int __iface_build_net_config(void *data, struct iface_rec *iface)
|
|
|
786c6d |
count++;
|
|
|
786c6d |
}
|
|
|
786c6d |
}
|
|
|
786c6d |
- if (iface->mtu) {
|
|
|
786c6d |
- if (!iface_fill_mtu(&iov[net_config->count],
|
|
|
786c6d |
- iface,
|
|
|
786c6d |
- ISCSI_IFACE_TYPE_IPV6)) {
|
|
|
786c6d |
- net_config->count++;
|
|
|
786c6d |
- count++;
|
|
|
786c6d |
- }
|
|
|
786c6d |
- }
|
|
|
786c6d |
- if (iface->port) {
|
|
|
786c6d |
- if (!iface_fill_port(&iov[net_config->count],
|
|
|
786c6d |
- iface,
|
|
|
786c6d |
- ISCSI_IFACE_TYPE_IPV6)) {
|
|
|
786c6d |
- net_config->count++;
|
|
|
786c6d |
- count++;
|
|
|
786c6d |
- }
|
|
|
786c6d |
- }
|
|
|
786c6d |
+
|
|
|
786c6d |
+ IFACE_SET_PARAM_INTVAL(&iov[net_config->count],
|
|
|
786c6d |
+ iface->iface_num,
|
|
|
786c6d |
+ ISCSI_IFACE_TYPE_IPV6,
|
|
|
786c6d |
+ ISCSI_NET_PARAM_MTU,
|
|
|
786c6d |
+ ISCSI_NET_PARAM,
|
|
|
786c6d |
+ 2,
|
|
|
786c6d |
+ iface->mtu,
|
|
|
786c6d |
+ &net_config->count,
|
|
|
786c6d |
+ &count);
|
|
|
786c6d |
+
|
|
|
786c6d |
+ IFACE_SET_PARAM_INTVAL(&iov[net_config->count],
|
|
|
786c6d |
+ iface->iface_num,
|
|
|
786c6d |
+ ISCSI_IFACE_TYPE_IPV6,
|
|
|
786c6d |
+ ISCSI_NET_PARAM_PORT,
|
|
|
786c6d |
+ ISCSI_NET_PARAM,
|
|
|
786c6d |
+ 2,
|
|
|
786c6d |
+ iface->port,
|
|
|
786c6d |
+ &net_config->count,
|
|
|
786c6d |
+ &count);
|
|
|
786c6d |
}
|
|
|
786c6d |
}
|
|
|
786c6d |
return 0;
|
|
|
786c6d |
--
|
|
|
786c6d |
1.8.3.1
|
|
|
786c6d |
|