5ebdd59
diff --git a/usr/Makefile b/usr/Makefile
5ebdd59
index e9d6bd1..8e505bf 100644
5ebdd59
--- a/usr/Makefile
5ebdd59
+++ b/usr/Makefile
5ebdd59
@@ -42,7 +42,7 @@ ISCSI_LIB_SRCS = iscsi_util.o io.o auth.o login.o log.o md5.o sha1.o iface.o \
5ebdd59
 	iscsid_req.o $(SYSDEPS_SRCS)
5ebdd59
 # core initiator files
5ebdd59
 INITIATOR_SRCS = initiator.o scsi.o actor.o event_poll.o mgmt_ipc.o \
5ebdd59
-		transport.o cxgb3i.o be2iscsi.o
5ebdd59
+		transport.o cxgb3i.o be2iscsi.o uip_mgmt_ipc.o
5ebdd59
 # fw boot files
5ebdd59
 FW_BOOT_SRCS = $(wildcard ../utils/fwparam_ibft/*.o)
5ebdd59
 
5ebdd59
diff --git a/usr/initiator.c b/usr/initiator.c
5ebdd59
index 1c9d8b6..8f7a383 100644
5ebdd59
--- a/usr/initiator.c
5ebdd59
+++ b/usr/initiator.c
5ebdd59
@@ -45,6 +45,7 @@
5ebdd59
 #include "iscsi_sysfs.h"
5ebdd59
 #include "iscsi_settings.h"
5ebdd59
 #include "iface.h"
5ebdd59
+#include "host.h"
5ebdd59
 #include "sysdeps.h"
5ebdd59
 
5ebdd59
 #define ISCSI_CONN_ERR_REOPEN_DELAY	3
5ebdd59
@@ -743,6 +744,38 @@ static int iscsi_conn_connect(struct iscsi_conn *conn, queue_task_t *qtask)
5ebdd59
 	return 0;
5ebdd59
 }
5ebdd59
 
5ebdd59
+static int __set_net_config(struct iscsi_transport *t,
5ebdd59
+			    iscsi_session_t *session,
5ebdd59
+			    struct iface_rec *iface)
5ebdd59
+{
5ebdd59
+	if (t->template->set_net_config) {
5ebdd59
+		/* uip needs the netdev name */
5ebdd59
+		struct host_info hinfo;
5ebdd59
+		int hostno, rc;
5ebdd59
+
5ebdd59
+		/* this assumes that the netdev or hw address is going to be
5ebdd59
+		   set */
5ebdd59
+		hostno = iscsi_sysfs_get_host_no_from_hwinfo(iface, &rc);
5ebdd59
+		if (rc) {
5ebdd59
+			log_debug(4, "Couldn't get host no.\n");
5ebdd59
+			return rc;
5ebdd59
+		}
5ebdd59
+
5ebdd59
+		/* uip needs the netdev name */
5ebdd59
+		if (!strlen(iface->netdev)) {
5ebdd59
+			memset(&hinfo, 0, sizeof(hinfo));
5ebdd59
+			hinfo.host_no = hostno;
5ebdd59
+			iscsi_sysfs_get_hostinfo_by_host_no(&hinfo);
5ebdd59
+			strcpy(iface->netdev, hinfo.iface.netdev);
5ebdd59
+		}
5ebdd59
+
5ebdd59
+		return t->template->set_net_config(t, iface, session);
5ebdd59
+	}
5ebdd59
+
5ebdd59
+	return 0;
5ebdd59
+}
5ebdd59
+
5ebdd59
+
5ebdd59
 static void
5ebdd59
 __session_conn_reopen(iscsi_conn_t *conn, queue_task_t *qtask, int do_stop,
5ebdd59
 		      int redirected)
5ebdd59
@@ -784,6 +817,11 @@ __session_conn_reopen(iscsi_conn_t *conn, queue_task_t *qtask, int do_stop,
5ebdd59
 	if (!redirected)
5ebdd59
 		session->reopen_cnt++;
5ebdd59
 
5ebdd59
+	/* uIP will needs to be re-triggered on the connection re-open */
5ebdd59
+	if (__set_net_config(conn->session->t, conn->session,
5ebdd59
+			      &conn->session->nrec.iface) != 0)
5ebdd59
+		goto queue_reopen;
5ebdd59
+
5ebdd59
 	if (iscsi_conn_connect(conn, qtask)) {
5ebdd59
 		delay = ISCSI_CONN_ERR_REOPEN_DELAY;
5ebdd59
 		goto queue_reopen;
5ebdd59
@@ -2130,6 +2168,10 @@ static int iface_set_param(struct iscsi_transport *t, struct iface_rec *iface,
5ebdd59
 		return EINVAL;
5ebdd59
 	}
5ebdd59
 
5ebdd59
+	rc = __set_net_config(t, session, iface);
5ebdd59
+	if (rc != 0)
5ebdd59
+		return rc;
5ebdd59
+
5ebdd59
 	rc = __iscsi_host_set_param(t, session->hostno,
5ebdd59
 				    ISCSI_HOST_PARAM_IPADDRESS,
5ebdd59
 				    iface->ipaddress, ISCSI_STRING);
5ebdd59
diff --git a/usr/iscsid_req.c b/usr/iscsid_req.c
5ebdd59
index 5280a0a..6eb8b1d 100644
5ebdd59
--- a/usr/iscsid_req.c
5ebdd59
+++ b/usr/iscsid_req.c
5ebdd59
@@ -22,6 +22,7 @@
5ebdd59
 #include <stdlib.h>
5ebdd59
 #include <string.h>
5ebdd59
 #include <errno.h>
5ebdd59
+#include <fcntl.h>
5ebdd59
 #include <sys/un.h>
5ebdd59
 #include <sys/types.h>
5ebdd59
 #include <sys/socket.h>
5ebdd59
@@ -31,6 +32,7 @@
5ebdd59
 #include "mgmt_ipc.h"
5ebdd59
 #include "iscsi_util.h"
5ebdd59
 #include "config.h"
5ebdd59
+#include "uip_mgmt_ipc.h"
5ebdd59
 
5ebdd59
 static void iscsid_startup(void)
5ebdd59
 {
5ebdd59
@@ -51,7 +53,8 @@ static void iscsid_startup(void)
5ebdd59
 
5ebdd59
 #define MAXSLEEP 128
5ebdd59
 
5ebdd59
-static mgmt_ipc_err_e iscsid_connect(int *fd, int start_iscsid)
5ebdd59
+static mgmt_ipc_err_e ipc_connect(int *fd, char *unix_sock_name,
5ebdd59
+				  int start_iscsid)
5ebdd59
 {
5ebdd59
 	int nsec;
5ebdd59
 	struct sockaddr_un addr;
5ebdd59
@@ -64,8 +67,8 @@ static mgmt_ipc_err_e iscsid_connect(int *fd, int start_iscsid)
5ebdd59
 
5ebdd59
 	memset(&addr, 0, sizeof(addr));
5ebdd59
 	addr.sun_family = AF_LOCAL;
5ebdd59
-	memcpy((char *) &addr.sun_path + 1, ISCSIADM_NAMESPACE,
5ebdd59
-		strlen(ISCSIADM_NAMESPACE));
5ebdd59
+	memcpy((char *) &addr.sun_path + 1, unix_sock_name,
5ebdd59
+		strlen(unix_sock_name));
5ebdd59
 	/*
5ebdd59
 	 * Trying to connect with exponential backoff
5ebdd59
 	 */
5ebdd59
@@ -93,6 +96,11 @@ static mgmt_ipc_err_e iscsid_connect(int *fd, int start_iscsid)
5ebdd59
 	return MGMT_IPC_ERR_ISCSID_NOTCONN;
5ebdd59
 }
5ebdd59
 
5ebdd59
+static mgmt_ipc_err_e iscsid_connect(int *fd, int start_iscsid)
5ebdd59
+{
5ebdd59
+       return ipc_connect(fd, ISCSIADM_NAMESPACE, start_iscsid);
5ebdd59
+}
5ebdd59
+
5ebdd59
 mgmt_ipc_err_e iscsid_request(int *fd, iscsiadm_req_t *req, int start_iscsid)
5ebdd59
 {
5ebdd59
 	int err;
5ebdd59
@@ -190,6 +198,72 @@ int iscsid_req_by_sid(iscsiadm_cmd_e cmd, int sid)
5ebdd59
 	return iscsid_req_wait(cmd, fd);
5ebdd59
 }
5ebdd59
 
5ebdd59
+static mgmt_ipc_err_e uip_connect(int *fd)
5ebdd59
+{
5ebdd59
+	return ipc_connect(fd, ISCSID_UIP_NAMESPACE, 0);
5ebdd59
+}
5ebdd59
+
5ebdd59
+int uip_broadcast(void *buf, size_t buf_len)
5ebdd59
+{
5ebdd59
+	int err;
5ebdd59
+	int fd;
5ebdd59
+	iscsid_uip_rsp_t rsp;
5ebdd59
+	int flags;
5ebdd59
+	int count;
5ebdd59
+
5ebdd59
+	err = uip_connect(&fd;;
5ebdd59
+	if (err) {
5ebdd59
+		log_warning("uIP daemon is not up");
5ebdd59
+		return err;
5ebdd59
+	}
5ebdd59
+
5ebdd59
+	/*  Send the data to uIP */
5ebdd59
+	if ((err = write(fd, buf, buf_len)) != buf_len) {
5ebdd59
+		log_error("got write error (%d/%d), daemon died?",
5ebdd59
+			err, errno);
5ebdd59
+		close(fd);
5ebdd59
+		return -EIO;
5ebdd59
+	}
5ebdd59
+
5ebdd59
+	/*  Set the socket to a non-blocking read, this way if there are
5ebdd59
+	 *  problems waiting for uIP, iscsid can bailout early */
5ebdd59
+	flags = fcntl(fd, F_GETFL, 0);
5ebdd59
+	if (flags == -1)
5ebdd59
+	        flags = 0;
5ebdd59
+	err = fcntl(fd, F_SETFL, flags | O_NONBLOCK);
5ebdd59
+	if(err != 0) {
5ebdd59
+		log_error("could not set uip broadcast to non-blocking: %d",
5ebdd59
+			  errno);
5ebdd59
+		close(fd);
5ebdd59
+		return -EIO;
5ebdd59
+	}
5ebdd59
+
5ebdd59
+#define MAX_UIP_BROADCAST_READ_TRIES 3
5ebdd59
+	for(count = 0; count < MAX_UIP_BROADCAST_READ_TRIES; count++) {
5ebdd59
+		/*  Wait for the response */
5ebdd59
+		err = read(fd, &rsp, sizeof(rsp));
5ebdd59
+		if (err == sizeof(rsp)) {
5ebdd59
+			log_debug(3, "Broadcasted to uIP with length: %ld\n",
5ebdd59
+				  buf_len);
5ebdd59
+			break;
5ebdd59
+		} else if((err == -1) && (errno == EAGAIN)) {
5ebdd59
+			usleep(250000);
5ebdd59
+			continue;
5ebdd59
+		} else {
5ebdd59
+			log_error("Could not read response (%d/%d), daemon died?",
5ebdd59
+				  err, errno);
5ebdd59
+			break;
5ebdd59
+		}
5ebdd59
+	}
5ebdd59
+
5ebdd59
+	if(count == MAX_UIP_BROADCAST_READ_TRIES)
5ebdd59
+		log_error("Could not broadcast to uIP");
5ebdd59
+
5ebdd59
+	close(fd);
5ebdd59
+
5ebdd59
+	return 0;
5ebdd59
+}
5ebdd59
+
5ebdd59
 void iscsid_handle_error(mgmt_ipc_err_e err)
5ebdd59
 {
5ebdd59
 	static char *err_msgs[] = {
5ebdd59
diff --git a/usr/iscsid_req.h b/usr/iscsid_req.h
5ebdd59
index 3bba2f4..e2cf1c3 100644
5ebdd59
--- a/usr/iscsid_req.h
5ebdd59
+++ b/usr/iscsid_req.h
5ebdd59
@@ -34,4 +34,6 @@ extern int iscsid_req_by_rec(int cmd, struct node_rec *rec);
5ebdd59
 extern int iscsid_req_by_sid_async(int cmd, int sid, int *fd);
5ebdd59
 extern int iscsid_req_by_sid(int cmd, int sid);
5ebdd59
 
5ebdd59
+extern int uip_broadcast(void *buf, size_t buf_len);
5ebdd59
+
5ebdd59
 #endif
5ebdd59
diff --git a/usr/transport.c b/usr/transport.c
5ebdd59
index c0789bb..aa0395c 100644
5ebdd59
--- a/usr/transport.c
5ebdd59
+++ b/usr/transport.c
5ebdd59
@@ -25,6 +25,7 @@
5ebdd59
 #include "log.h"
5ebdd59
 #include "iscsi_util.h"
5ebdd59
 #include "iscsi_sysfs.h"
5ebdd59
+#include "uip_mgmt_ipc.h"
5ebdd59
 #include "cxgb3i.h"
5ebdd59
 #include "be2iscsi.h"
5ebdd59
 
5ebdd59
@@ -58,6 +59,7 @@ struct iscsi_transport_template bnx2i = {
5ebdd59
 	.ep_connect	= ktransport_ep_connect,
5ebdd59
 	.ep_poll	= ktransport_ep_poll,
5ebdd59
 	.ep_disconnect	= ktransport_ep_disconnect,
5ebdd59
+	.set_net_config = uip_broadcast_params,
5ebdd59
 };
5ebdd59
 
5ebdd59
 struct iscsi_transport_template be2iscsi = {
5ebdd59
diff --git a/usr/transport.h b/usr/transport.h
5ebdd59
index 5ceedb3..2ec903c 100644
5ebdd59
--- a/usr/transport.h
5ebdd59
+++ b/usr/transport.h
5ebdd59
@@ -35,6 +35,9 @@ struct iscsi_transport_template {
5ebdd59
 	int (*ep_poll) (struct iscsi_conn *conn, int timeout_ms);
5ebdd59
 	void (*ep_disconnect) (struct iscsi_conn *conn);
5ebdd59
 	void (*create_conn) (struct iscsi_conn *conn);
5ebdd59
+	int (*set_net_config) (struct iscsi_transport *t,
5ebdd59
+			       struct iface_rec *iface,
5ebdd59
+			       struct iscsi_session *session);
5ebdd59
 };
5ebdd59
 
5ebdd59
 /* represents data path provider */
5ebdd59
diff --git a/usr/uip_mgmt_ipc.c b/usr/uip_mgmt_ipc.c
5ebdd59
new file mode 100644
5ebdd59
index 0000000..73b1632
5ebdd59
--- /dev/null
5ebdd59
+++ b/usr/uip_mgmt_ipc.c
5ebdd59
@@ -0,0 +1,41 @@
5ebdd59
+/*
5ebdd59
+ * uIP iSCSI Daemon/Admin Management IPC
5ebdd59
+ *
5ebdd59
+ * This program is free software; you can redistribute it and/or modify
5ebdd59
+ * it under the terms of the GNU General Public License as published
5ebdd59
+ * by the Free Software Foundation; either version 2 of the License, or
5ebdd59
+ * (at your option) any later version.
5ebdd59
+ *
5ebdd59
+ * This program is distributed in the hope that it will be useful, but
5ebdd59
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
5ebdd59
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5ebdd59
+ * General Public License for more details.
5ebdd59
+ *
5ebdd59
+ * See the file COPYING included with this distribution for more details.
5ebdd59
+ */
5ebdd59
+
5ebdd59
+#include <string.h>
5ebdd59
+
5ebdd59
+#include "log.h"
5ebdd59
+#include "uip_mgmt_ipc.h"
5ebdd59
+#include "iscsid_req.h"
5ebdd59
+
5ebdd59
+int uip_broadcast_params(struct iscsi_transport *t,
5ebdd59
+			 struct iface_rec *iface,
5ebdd59
+			 struct iscsi_session *session)
5ebdd59
+{
5ebdd59
+	struct iscsid_uip_broadcast broadcast;
5ebdd59
+
5ebdd59
+        log_debug(3, "broadcasting to uip\n");
5ebdd59
+
5ebdd59
+	memset(&broadcast, 0, sizeof(broadcast));
5ebdd59
+
5ebdd59
+	broadcast.header.command = ISCSID_UIP_IPC_GET_IFACE;
5ebdd59
+	broadcast.header.payload_len = sizeof(*iface);
5ebdd59
+
5ebdd59
+	memcpy(&broadcast.u.iface_rec, iface, sizeof(*iface));
5ebdd59
+
5ebdd59
+	return uip_broadcast(&broadcast,
5ebdd59
+			     sizeof(iscsid_uip_broadcast_header_t) +
5ebdd59
+			     sizeof(*iface));
5ebdd59
+}
5ebdd59
diff --git a/usr/uip_mgmt_ipc.h b/usr/uip_mgmt_ipc.h
5ebdd59
new file mode 100644
5ebdd59
index 0000000..dd49c0b
5ebdd59
--- /dev/null
5ebdd59
+++ b/usr/uip_mgmt_ipc.h
5ebdd59
@@ -0,0 +1,71 @@
5ebdd59
+/*
5ebdd59
+ * uIP iSCSI Daemon/Admin Management IPC
5ebdd59
+ *
5ebdd59
+ * This program is free software; you can redistribute it and/or modify
5ebdd59
+ * it under the terms of the GNU General Public License as published
5ebdd59
+ * by the Free Software Foundation; either version 2 of the License, or
5ebdd59
+ * (at your option) any later version.
5ebdd59
+ *
5ebdd59
+ * This program is distributed in the hope that it will be useful, but
5ebdd59
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
5ebdd59
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5ebdd59
+ * General Public License for more details.
5ebdd59
+ *
5ebdd59
+ * See the file COPYING included with this distribution for more details.
5ebdd59
+ */
5ebdd59
+#ifndef UIP_MGMT_IPC_H
5ebdd59
+#define UIP_MGMT_IPC_H
5ebdd59
+
5ebdd59
+#include "types.h"
5ebdd59
+#include "iscsi_if.h"
5ebdd59
+#include "config.h"
5ebdd59
+#include "mgmt_ipc.h"
5ebdd59
+
5ebdd59
+#include "initiator.h"
5ebdd59
+#include "transport.h"
5ebdd59
+
5ebdd59
+#define ISCSID_UIP_NAMESPACE	"ISCSID_UIP_ABSTRACT_NAMESPACE"
5ebdd59
+
5ebdd59
+typedef enum iscsid_uip_cmd {
5ebdd59
+	ISCSID_UIP_IPC_UNKNOWN			= 0,
5ebdd59
+	ISCSID_UIP_IPC_GET_IFACE		= 1,
5ebdd59
+
5ebdd59
+        __ISCSID_UIP_IPC_MAX_COMMAND
5ebdd59
+} iscsid_uip_cmd_e;
5ebdd59
+
5ebdd59
+typedef struct iscsid_uip_broadcast_header {
5ebdd59
+	iscsid_uip_cmd_e command;
5ebdd59
+	uint32_t payload_len;
5ebdd59
+} iscsid_uip_broadcast_header_t;
5ebdd59
+
5ebdd59
+/* IPC Request */
5ebdd59
+typedef struct iscsid_uip_broadcast {
5ebdd59
+	struct iscsid_uip_broadcast_header header;
5ebdd59
+
5ebdd59
+	union {
5ebdd59
+		/* messages */
5ebdd59
+		struct ipc_broadcast_iface_rec {
5ebdd59
+			struct iface_rec rec;
5ebdd59
+		} iface_rec;
5ebdd59
+	} u;
5ebdd59
+} iscsid_uip_broadcast_t;
5ebdd59
+
5ebdd59
+typedef enum iscsid_uip_mgmt_ipc_err {
5ebdd59
+	ISCSID_UIP_MGMT_IPC_OK                     = 0,
5ebdd59
+        ISCISD_UIP_MGMT_IPC_ERR                    = 1,
5ebdd59
+        ISCISD_UIP_MGMT_IPC_ERR_NOT_FOUND          = 2,
5ebdd59
+        ISCISD_UIP_MGMT_IPC_ERR_NOMEM              = 3,
5ebdd59
+} iscsid_uip_mgmt_ipc_err_e;
5ebdd59
+
5ebdd59
+/* IPC Response */
5ebdd59
+typedef struct iscsid_uip_mgmt_rsp {
5ebdd59
+	iscsid_uip_cmd_e command;
5ebdd59
+	iscsid_uip_mgmt_ipc_err_e err;
5ebdd59
+} iscsid_uip_rsp_t;
5ebdd59
+
5ebdd59
+extern int uip_broadcast_params(struct iscsi_transport *t,
5ebdd59
+				struct iface_rec *iface,
5ebdd59
+				struct iscsi_session *session);
5ebdd59
+
5ebdd59
+
5ebdd59
+#endif /* UIP_MGMT_IPC_H */
5ebdd59
-- 
5ebdd59
1.6.6.1
5ebdd59