summaryrefslogtreecommitdiff
path: root/usr/iscsi_net_util.c
diff options
context:
space:
mode:
authorMike Christie <michaelc@cs.wisc.edu>2012-03-22 04:09:01 -0400
committerMike Christie <michaelc@cs.wisc.edu>2012-03-22 04:09:01 -0400
commit04b4a6699f63c4f0bab9523aae3efb8c909d6587 (patch)
tree41e0a098759657094cff25d8d2d9f82ea380a7dc /usr/iscsi_net_util.c
parente6e47f08eef2978c0915658f610c5251e86925ae (diff)
downloadopen-iscsi-04b4a6699f63c4f0bab9523aae3efb8c909d6587.tar.gz
iscsi tools: have iscsi tools bring up offload net iface
bnx2i and cxgb*i need the network interface that the offload engine attaches to brought up before we can connect. This patch has the iscsi tools do this before trying to create a tcp/ip connection.
Diffstat (limited to 'usr/iscsi_net_util.c')
-rw-r--r--usr/iscsi_net_util.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/usr/iscsi_net_util.c b/usr/iscsi_net_util.c
index 7edc0b9..212cc59 100644
--- a/usr/iscsi_net_util.c
+++ b/usr/iscsi_net_util.c
@@ -306,4 +306,57 @@ done:
return ret;
}
+/**
+ * net_ifup_netdev - bring up network interface
+ * @netdev: netdevice to bring up.
+ */
+int net_ifup_netdev(char *netdev)
+{
+ struct ifreq ifr;
+ int sock;
+ int ret = 0;
+
+ if (!strlen(netdev)) {
+ log_error("No netdev name in fw entry.\n");
+ return EINVAL;
+ }
+
+ /* Create socket for making networking changes */
+ if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
+ log_error("Could not open socket to manage network "
+ "(err %d - %s)", errno, strerror(errno));
+ return errno;
+ }
+
+ memset(&ifr, 0, sizeof(ifr));
+ strncpy(ifr.ifr_name, netdev, IFNAMSIZ);
+ if (ioctl(sock, SIOCSIFFLAGS, &ifr) < 0) {
+ log_error("Could not bring up netdev %s (err %d - %s)",
+ netdev, errno, strerror(errno));
+ ret = errno;
+ goto done;
+ }
+
+ if (ifr.ifr_flags & IFF_UP) {
+ log_debug(3, "%s up\n", netdev);
+ goto done;
+ }
+
+ log_debug(3, "bringing %s up\n", netdev);
+
+ /* Bring up interface */
+ memset(&ifr, 0, sizeof(ifr));
+ strncpy(ifr.ifr_name, netdev, IFNAMSIZ);
+ ifr.ifr_flags = IFF_UP;
+ if (ioctl(sock, SIOCSIFFLAGS, &ifr) < 0) {
+ log_error("Could not bring up netdev %s (err %d - %s)",
+ netdev, errno, strerror(errno));
+ ret = errno;
+ goto done;
+ }
+done:
+ close(sock);
+ return ret;
+}
+