From: Harish Zunjarrao <harish.zunjar...@qlogic.com>

Signed-off-by: Harish Zunjarrao <harish.zunjar...@qlogic.com>
Signed-off-by: Vikas Chaudhary <vikas.chaudh...@qlogic.com>
---
 include/iscsi_if.h |  10 ++--
 usr/iface.c        | 143 ++++++++++++++++++++++++++---------------------------
 2 files changed, 72 insertions(+), 81 deletions(-)

diff --git a/include/iscsi_if.h b/include/iscsi_if.h
index 08cfaa9..b34a91a 100644
--- a/include/iscsi_if.h
+++ b/include/iscsi_if.h
@@ -352,9 +352,9 @@ struct iscsi_path {
        uint16_t        pmtu;
 } __attribute__ ((aligned (sizeof(uint64_t))));
 
-/* iscsi iface enabled/disabled setting */
-#define ISCSI_IFACE_DISABLE    0x01
-#define ISCSI_IFACE_ENABLE     0x02
+/* iscsi generic enable/disable setting for various features */
+#define ISCSI_NET_PARAM_DISABLE                0x01
+#define ISCSI_NET_PARAM_ENABLE         0x02
 
 /* ipv4 bootproto */
 #define ISCSI_BOOTPROTO_STATIC         0x01
@@ -379,10 +379,6 @@ struct iscsi_path {
 #define ISCSI_MAX_VLAN_ID              4095
 #define ISCSI_MAX_VLAN_PRIORITY                7
 
-/* iscsi vlan enable/disabled setting */
-#define ISCSI_VLAN_DISABLE     0x01
-#define ISCSI_VLAN_ENABLE      0x02
-
 /* iSCSI network params */
 enum iscsi_net_param {
        ISCSI_NET_PARAM_IPV4_ADDR               = 1,
diff --git a/usr/iface.c b/usr/iface.c
index d3bada4..75ed28e 100644
--- a/usr/iface.c
+++ b/usr/iface.c
@@ -1311,62 +1311,48 @@ static int iface_fill_vlan_id(struct iovec *iov, struct 
iface_rec *iface,
        return 0;
 }
 
-/* IPv4/IPv6 VLAN state: disable/enable */
-static int iface_fill_vlan_state(struct iovec *iov, struct iface_rec *iface,
-                                uint32_t iface_type)
+/* disable/enable parameters */
+static int iface_fill_enable_disable_param(struct iovec *iov,
+                                          uint32_t iface_num,
+                                          uint8_t iface_type,
+                                          uint16_t param,
+                                          char *param_val)
 {
        int len;
        struct iscsi_iface_param_info *net_param;
        struct nlattr *attr;
 
-       len = sizeof(struct iscsi_iface_param_info) + 1;
-       iov->iov_base = iscsi_nla_alloc(ISCSI_NET_PARAM_VLAN_ENABLED, len);
-       if (!(iov->iov_base))
+       if (!param_val[0])
                return 1;
 
-       attr = iov->iov_base;
-       iov->iov_len = NLA_ALIGN(attr->nla_len);
-       net_param = (struct iscsi_iface_param_info *)ISCSI_NLA_DATA(attr);
-       net_param->param = ISCSI_NET_PARAM_VLAN_ENABLED;
-       net_param->iface_type = iface_type;
-       net_param->iface_num = iface->iface_num;
-       net_param->param_type = ISCSI_NET_PARAM;
-       net_param->len = 1;
-       if (strcmp(iface->vlan_state, "disable") && iface->vlan_id)
-               net_param->value[0] = ISCSI_VLAN_ENABLE;
-       else /* Assume disabled */
-               net_param->value[0] = ISCSI_VLAN_DISABLE;
-       return 0;
-}
-
-/* IPv4/IPv6 Network state: disable/enable */
-static int iface_fill_net_state(struct iovec *iov, struct iface_rec *iface,
-                               uint32_t iface_type)
-{
-       int len;
-       struct iscsi_iface_param_info *net_param;
-       struct nlattr *attr;
-
        len = sizeof(struct iscsi_iface_param_info) + 1;
-       iov->iov_base = iscsi_nla_alloc(ISCSI_NET_PARAM_IFACE_ENABLE, len);
+       iov->iov_base = iscsi_nla_alloc(param, len);
        if (!(iov->iov_base))
                return 1;
 
        attr = iov->iov_base;
        iov->iov_len = NLA_ALIGN(attr->nla_len);
        net_param = (struct iscsi_iface_param_info *)ISCSI_NLA_DATA(attr);
-       net_param->param = ISCSI_NET_PARAM_IFACE_ENABLE;
+       net_param->iface_num = iface_num;
+       net_param->len = 1;
+       net_param->param = param;
        net_param->iface_type = iface_type;
-       net_param->iface_num = iface->iface_num;
        net_param->param_type = ISCSI_NET_PARAM;
-       net_param->len = 1;
-       if (!strcmp(iface->state, "disable"))
-               net_param->value[0] = ISCSI_IFACE_DISABLE;
-       else /* Assume enabled */
-               net_param->value[0] = ISCSI_IFACE_ENABLE;
+       if (strcmp(param_val, "disable"))
+               net_param->value[0] = ISCSI_NET_PARAM_ENABLE;
+       else /* Assume disabled */
+               net_param->value[0] = ISCSI_NET_PARAM_DISABLE;
        return 0;
 }
 
+#define IFACE_SET_NET_PARAM_EN(iov, inum, itype, param, ival, gcnt,    \
+                              lcnt)                                    \
+       if (!iface_fill_enable_disable_param(iov, inum, itype, param,   \
+                                            ival)) {                   \
+               (*gcnt)++;                                              \
+               (*lcnt)++;                                              \
+       }
+
 /* IPv4 Bootproto: DHCP/static */
 static int iface_fill_net_bootproto(struct iovec *iov, struct iface_rec *iface)
 {
@@ -1596,13 +1582,13 @@ static int __iface_build_net_config(void *data, struct 
iface_rec *iface)
        iptype = iface_get_iptype(iface);
        if (iptype == ISCSI_IFACE_TYPE_IPV4) {
                if (!strcmp(iface->state, "disable")) {
-                       if (!iface_fill_net_state(&iov[net_config->count],
-                                                 iface,
-                                                 ISCSI_IFACE_TYPE_IPV4)) {
-                               net_config->count++;
-                               count++;
-                       }
-
+                       IFACE_SET_NET_PARAM_EN(&iov[net_config->count],
+                                              iface->iface_num,
+                                              ISCSI_IFACE_TYPE_IPV4,
+                                              ISCSI_NET_PARAM_IFACE_ENABLE,
+                                              iface->state,
+                                              &net_config->count,
+                                              &count);
                        return 0;
                }
 
@@ -1646,18 +1632,22 @@ static int __iface_build_net_config(void *data, struct 
iface_rec *iface)
                 * fill state and other parameters (if any)
                 */
                if (count) {
-                       if (!iface_fill_net_state(&iov[net_config->count],
-                                                 iface,
-                                                 ISCSI_IFACE_TYPE_IPV4)) {
-                               net_config->count++;
-                               count++;
-                       }
-                       if (!iface_fill_vlan_state(&iov[net_config->count],
-                                               iface,
-                                               ISCSI_IFACE_TYPE_IPV4)) {
-                               net_config->count++;
-                               count++;
-                       }
+                       IFACE_SET_NET_PARAM_EN(&iov[net_config->count],
+                                              iface->iface_num,
+                                              ISCSI_IFACE_TYPE_IPV4,
+                                              ISCSI_NET_PARAM_IFACE_ENABLE,
+                                              iface->state,
+                                              &net_config->count,
+                                              &count);
+
+                       IFACE_SET_NET_PARAM_EN(&iov[net_config->count],
+                                              iface->iface_num,
+                                              ISCSI_IFACE_TYPE_IPV4,
+                                              ISCSI_NET_PARAM_VLAN_ENABLED,
+                                              iface->vlan_state,
+                                              &net_config->count,
+                                              &count);
+
                        if (strcmp(iface->vlan_state, "disable") &&
                            iface->vlan_id) {
                                if (!iface_fill_vlan_id(&iov[net_config->count],
@@ -1685,12 +1675,13 @@ static int __iface_build_net_config(void *data, struct 
iface_rec *iface)
                }
        } else if (iptype == ISCSI_IFACE_TYPE_IPV6) {
                if (!strcmp(iface->state, "disable")) {
-                       if (!iface_fill_net_state(&iov[net_config->count],
-                                                 iface,
-                                                 ISCSI_IFACE_TYPE_IPV6)) {
-                               net_config->count++;
-                               count++;
-                       }
+                       IFACE_SET_NET_PARAM_EN(&iov[net_config->count],
+                                              iface->iface_num,
+                                              ISCSI_IFACE_TYPE_IPV6,
+                                              ISCSI_NET_PARAM_IFACE_ENABLE,
+                                              iface->state,
+                                              &net_config->count,
+                                              &count);
                        return 0;
                }
 
@@ -1768,18 +1759,22 @@ static int __iface_build_net_config(void *data, struct 
iface_rec *iface)
                 * fill state and other parameters
                 */
                if (count) {
-                       if (!iface_fill_net_state(&iov[net_config->count],
-                                                 iface,
-                                                 ISCSI_IFACE_TYPE_IPV6)) {
-                               net_config->count++;
-                               count++;
-                       }
-                       if (!iface_fill_vlan_state(&iov[net_config->count],
-                                                  iface,
-                                                  ISCSI_IFACE_TYPE_IPV6)) {
-                               net_config->count++;
-                               count++;
-                       }
+                       IFACE_SET_NET_PARAM_EN(&iov[net_config->count],
+                                              iface->iface_num,
+                                              ISCSI_IFACE_TYPE_IPV6,
+                                              ISCSI_NET_PARAM_IFACE_ENABLE,
+                                              iface->state,
+                                              &net_config->count,
+                                              &count);
+
+                       IFACE_SET_NET_PARAM_EN(&iov[net_config->count],
+                                              iface->iface_num,
+                                              ISCSI_IFACE_TYPE_IPV6,
+                                              ISCSI_NET_PARAM_VLAN_ENABLED,
+                                              iface->vlan_state,
+                                              &net_config->count,
+                                              &count);
+
                        if (strcmp(iface->vlan_state, "disable") &&
                            iface->vlan_id) {
                                if (!iface_fill_vlan_id(&iov[net_config->count],
-- 
1.8.2.GIT


-- 
You received this message because you are subscribed to the Google Groups 
"open-iscsi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to open-iscsi+unsubscr...@googlegroups.com.
To post to this group, send email to open-iscsi@googlegroups.com.
Visit this group at http://groups.google.com/group/open-iscsi?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to