[PATCH 2/2] userspace - setting interface ip address

From: Karen Xie <[EMAIL PROTECTED]>

Enable setting of the ip address for iscsi traffic on a network interface via 
iface files.

The format of the iface files are:
        iface.transport_name = <transport name>
        iface.net_ifacename = <ethX>
        iface.ipaddress = <ip adress>

This patch is based on the master branch of the git tree.

Signed-off-by: Karen Xie <[EMAIL PROTECTED]>
---

 usr/idbm.c      |    6 +++---
 usr/iface.c     |   11 +++++++----
 usr/initiator.c |   47 ++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 56 insertions(+), 8 deletions(-)


diff --git a/usr/idbm.c b/usr/idbm.c
index 0cb3c44..48aec4f 100644
--- a/usr/idbm.c
+++ b/usr/idbm.c
@@ -274,8 +274,8 @@ idbm_recinfo_node(node_rec_t *r, recinfo_t *ri)
         */
        __recinfo_str("iface.hwaddress", ri, r, iface.hwaddress, IDBM_SHOW,
                      num, 1);
-//     __recinfo_str("iface.ipaddress", ri, r, iface.ipaddress,
-//                  IDBM_SHOW, num);
+       __recinfo_str("iface.ipaddress", ri, r, iface.ipaddress, IDBM_SHOW,
+                     num, 1);
        __recinfo_str("iface.iscsi_ifacename", ri, r, iface.name, IDBM_SHOW,
                      num, 1);
        __recinfo_str("iface.net_ifacename", ri, r, iface.netdev, IDBM_SHOW,
@@ -413,7 +413,7 @@ void idbm_recinfo_iface(iface_rec_t *r, recinfo_t *ri)
 
        __recinfo_str("iface.iscsi_ifacename", ri, r, name, IDBM_SHOW, num, 0);
        __recinfo_str("iface.net_ifacename", ri, r, netdev, IDBM_SHOW, num, 1);
-//     __recinfo_str("iface.ipaddress", ri, r, ipaddress, IDBM_SHOW, num, 1);
+       __recinfo_str("iface.ipaddress", ri, r, ipaddress, IDBM_SHOW, num, 1);
        __recinfo_str("iface.hwaddress", ri, r, hwaddress, IDBM_SHOW, num, 1);
        __recinfo_str("iface.transport_name", ri, r, transport_name,
                      IDBM_SHOW, num, 1);
diff --git a/usr/iface.c b/usr/iface.c
index 01b87da..3273197 100644
--- a/usr/iface.c
+++ b/usr/iface.c
@@ -104,7 +104,7 @@ static void iface_init(struct iface_rec *iface)
 void iface_setup_defaults(struct iface_rec *iface)
 {
        sprintf(iface->netdev, DEFAULT_NETDEV);
-//     sprintf(iface->ipaddress, DEFAULT_IPADDRESS);
+       sprintf(iface->ipaddress, DEFAULT_IPADDRESS);
        sprintf(iface->hwaddress, DEFAULT_HWADDRESS);
        sprintf(iface->transport_name, DEFAULT_TRANSPORT);
        iface_init(iface);
@@ -494,8 +494,8 @@ void iface_copy(struct iface_rec *dst, struct iface_rec 
*src)
                strcpy(dst->name, src->name);
        if (strlen(src->netdev))
                strcpy(dst->netdev, src->netdev);
-//     if (strlen(src->ipaddress))
-//             strcpy(dst->ipaddress, src->ipaddress);
+       if (strlen(src->ipaddress))
+               strcpy(dst->ipaddress, src->ipaddress);
        if (strlen(src->hwaddress))
                strcpy(dst->hwaddress, src->hwaddress);
        if (strlen(src->transport_name))
@@ -594,6 +594,8 @@ int iface_print_tree(void *data, struct iface_rec *iface)
               UNKNOWN_VALUE);
        printf("\tHW Address: %s\n",
               strlen(iface->hwaddress) ? iface->hwaddress : UNKNOWN_VALUE);
+       printf("\tIP Address: %s\n",
+              strlen(iface->ipaddress) ? iface->ipaddress : UNKNOWN_VALUE);
        printf("\tNetdev: %s\n",
               strlen(iface->netdev) ? iface->netdev : UNKNOWN_VALUE);
        printf("\tInitiator Name: %s\n",
@@ -603,11 +605,12 @@ int iface_print_tree(void *data, struct iface_rec *iface)
 
 int iface_print_flat(void *data, struct iface_rec *iface)
 {
-       printf("%s %s,%s,%s,%s\n",
+       printf("%s %s,%s,%s,%s,%s\n",
                strlen(iface->name) ? iface->name : UNKNOWN_VALUE,
                strlen(iface->transport_name) ? iface->transport_name :
                                                        UNKNOWN_VALUE,
                strlen(iface->hwaddress) ? iface->hwaddress : UNKNOWN_VALUE,
+               strlen(iface->ipaddress) ? iface->ipaddress : UNKNOWN_VALUE,
                strlen(iface->netdev) ? iface->netdev : UNKNOWN_VALUE,
                strlen(iface->iname) ? iface->iname : UNKNOWN_VALUE);
        return 0;
diff --git a/usr/initiator.c b/usr/initiator.c
index 2f29ffc..1cfcc7f 100644
--- a/usr/initiator.c
+++ b/usr/initiator.c
@@ -1909,6 +1909,46 @@ int session_is_running(node_rec_t *rec)
        return 0;
 }
 
+static int iface_set_param(struct iscsi_transport *t, iface_rec_t *iface,
+                          int hostno)
+{
+       int rc = 0;
+
+       log_debug(3, "iface %s, netdev %s, ipaddr %s, hwaddr %s, tranport 
%s.\n",
+                 iface->name, iface->netdev, iface->ipaddress, 
iface->hwaddress,
+                 iface->transport_name);
+
+       if (!strcmp(iface->netdev, DEFAULT_NETDEV))
+               return 0;
+
+       rc = __iscsi_host_set_param(t, hostno,
+                                   ISCSI_HOST_PARAM_NETDEV_NAME,
+                                   iface->netdev,
+                                   ISCSI_STRING);
+       if (rc)
+               return rc;
+
+       if (strcmp(iface->ipaddress, DEFAULT_IPADDRESS)) {
+               rc = __iscsi_host_set_param(t, hostno,
+                                           ISCSI_HOST_PARAM_IPADDRESS,
+                                           iface->ipaddress,
+                                           ISCSI_STRING);
+               if (rc)
+                       return rc;
+       }
+
+       if (strcmp(iface->hwaddress, DEFAULT_HWADDRESS)) {
+               rc = __iscsi_host_set_param(t, hostno,
+                                           ISCSI_HOST_PARAM_HWADDRESS,
+                                           iface->hwaddress,
+                                           ISCSI_STRING);
+               if (rc)
+                       return rc;
+       }
+
+        return 0;
+}
+
 int
 session_login_task(node_rec_t *rec, queue_task_t *qtask)
 {
@@ -1972,7 +2012,7 @@ session_login_task(node_rec_t *rec, queue_task_t *qtask)
 
        if (!(t->caps & CAP_MARKERS) &&
            rec->conn[0].iscsi.OFMarker) {
-               log_error("Transport '%s' does not support OFMarker.",
+               log_error("Transport '%s' does not support OFMarker."
                          "Disabling OFMarkers.\n", t->name);
                rec->conn[0].iscsi.OFMarker = 0;
        }
@@ -1991,6 +2031,11 @@ session_login_task(node_rec_t *rec, queue_task_t *qtask)
        conn = &session->conn[0];
        qtask->conn = conn;
 
+       if (iface_set_param(t, &rec->iface, session->hostno)) {
+               __session_destroy(session);
+               return MGMT_IPC_ERR_LOGIN_FAILURE;
+       }
+
        conn->state = STATE_XPT_WAIT;
        if (iscsi_conn_connect(conn, qtask)) {
                __session_destroy(session);

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"open-iscsi" group.
To post to this group, send email to open-iscsi@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/open-iscsi
-~----------~----~----~----~------~----~------~--~---

Reply via email to