summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorMike Christie <michaelc@cs.wisc.edu>2010-01-14 04:33:51 -0600
committerMike Christie <michaelc@cs.wisc.edu>2010-01-15 02:24:01 -0600
commit2e39c68d905380efad58cd19ba982c06147161e3 (patch)
tree18bb63ae514ee6b0bc1b6a17edcc02ba1fbd51b2 /utils
parent29a1a1d624c12d2db0645c69cd672d54a5bdc549 (diff)
downloadopen-iscsi-2e39c68d905380efad58cd19ba982c06147161e3.tar.gz
iscsi tools: merge functions to get net iface name from mac address
There are 3 functions to get the net iface name from the mac address. This merges them into one function and moves it to a new file.
Diffstat (limited to 'utils')
-rw-r--r--utils/fwparam_ibft/Makefile2
-rw-r--r--utils/fwparam_ibft/fw_entry.c7
-rw-r--r--utils/fwparam_ibft/fwparam_ibft_sysfs.c146
3 files changed, 7 insertions, 148 deletions
diff --git a/utils/fwparam_ibft/Makefile b/utils/fwparam_ibft/Makefile
index c160e0b..b9e7988 100644
--- a/utils/fwparam_ibft/Makefile
+++ b/utils/fwparam_ibft/Makefile
@@ -22,7 +22,7 @@
#
SYSDEPS_OBJS = $(wildcard ../sysdeps/*.o)
-OBJS := fw_entry.o fwparam_ibft_sysfs.o $(SYSDEPS_OBJS)
+OBJS := fw_entry.o fwparam_ibft_sysfs.o $(SYSDEPS_OBJS) ../../usr/iscsi_net_util.o
OBJS += prom_lex.o prom_parse.tab.o fwparam_ppc.o
CLEANFILES = $(OBJS) *.output *~
diff --git a/utils/fwparam_ibft/fw_entry.c b/utils/fwparam_ibft/fw_entry.c
index 479473c..894bd64 100644
--- a/utils/fwparam_ibft/fw_entry.c
+++ b/utils/fwparam_ibft/fw_entry.c
@@ -33,15 +33,16 @@
#include "fw_context.h"
#include "fwparam.h"
#include "idbm_fields.h"
+#include "ethtool-copy.h"
/**
* fw_setup_nics - setup nics (ethXs) based on ibft net info
*
* Currently does not support vlans.
*
- * TODO:
- * For offload cards, this will setup the ethX with the net info.
- * It will not yet setup the offload card with it, but this is planned.
+ * If this is a offload card, this function does nothing. The
+ * net info is used by the iscsi iface settings for the iscsi
+ * function.
*/
int fw_setup_nics(void)
{
diff --git a/utils/fwparam_ibft/fwparam_ibft_sysfs.c b/utils/fwparam_ibft/fwparam_ibft_sysfs.c
index 1527485..b782f5a 100644
--- a/utils/fwparam_ibft/fwparam_ibft_sysfs.c
+++ b/utils/fwparam_ibft/fwparam_ibft_sysfs.c
@@ -35,6 +35,7 @@
#include "fw_context.h"
#include "fwparam.h"
#include "sysdeps.h"
+#include "iscsi_net_util.h"
#define IBFT_MAX 255
#define IBFT_SYSFS_ROOT "/sys/firmware/ibft/"
@@ -80,146 +81,6 @@ static int find_sysfs_dirs(const char *fpath, const struct stat *sb,
return 0;
}
-static int get_iface_from_device(char *id, struct boot_context *context)
-{
- char dev_dir[FILENAMESZ];
- int rc = ENODEV;
- DIR *dirfd;
- struct dirent *dent;
-
- memset(dev_dir, 0, FILENAMESZ);
- snprintf(dev_dir, FILENAMESZ, IBFT_SYSFS_ROOT"/%s/device", id);
-
- if (!file_exist(dev_dir))
- return 0;
-
- dirfd = opendir(dev_dir);
- if (!dirfd)
- return errno;
-
- while ((dent = readdir(dirfd))) {
- if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, "..") ||
- strncmp(dent->d_name, "net:", 4))
- continue;
-
- if (!strncmp(dent->d_name, "net:", 4)) {
- if ((strlen(dent->d_name) - 4) >
- (sizeof(context->iface) - 1)) {
- rc = EINVAL;
- printf("Net device %s too big for iface "
- "buffer.\n", dent->d_name);
- break;
- }
-
- if (sscanf(dent->d_name, "net:%s", context->iface) != 1)
- rc = EINVAL;
- rc = 0;
- break;
- } else {
- printf("Could not read ethernet to net link.\n");
- rc = EOPNOTSUPP;
- break;
- }
- }
-
- closedir(dirfd);
-
- if (rc != ENODEV)
- return rc;
-
- /* If not found try again with newer kernel networkdev sysfs layout */
- strlcat(dev_dir, "/net", FILENAMESZ);
-
- if (!file_exist(dev_dir))
- return rc;
-
- dirfd = opendir(dev_dir);
- if (!dirfd)
- return errno;
-
- while ((dent = readdir(dirfd))) {
- if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, ".."))
- continue;
-
- /* Take the first "regular" directory entry */
- if (strlen(dent->d_name) > (sizeof(context->iface) - 1)) {
- rc = EINVAL;
- printf("Net device %s too big for iface buffer.\n",
- dent->d_name);
- break;
- }
-
- strcpy(context->iface, dent->d_name);
- rc = 0;
- break;
- }
-
- closedir(dirfd);
-
- return rc;
-}
-
-static int get_iface_from_mac(char *id, struct boot_context *context)
-{
- char mac_fname[FILENAMESZ];
- char mac[18] = {0};
- int rc = ENODEV;
- int fd;
- int retval;
- struct dirent **namelist;
- int n, i;
-
- memset(mac_fname, 0, FILENAMESZ);
- snprintf(mac_fname, FILENAMESZ, IBFT_SYSFS_ROOT"/%s/mac", id);
-
- if (!file_exist(mac_fname))
- return 0;
-
- fd = open(mac_fname, O_RDONLY);
- if (fd == -1)
- return errno;
-
- retval = read(fd, mac, 17);
- if (retval == -1)
- return errno;
- if (retval != 17) {
- printf("Couldn't read whole mac address from %s\n", mac_fname);
- return EINVAL;
- }
- close(fd);
-
- n = scandir(NET_SYSFS_ROOT, &namelist, NULL, alphasort);
- if (n <= 0)
- return -n;
-
- for (i = 0; i < n; i++) {
- char name[256];
- char *dir = namelist[i]->d_name;
- char buf[18] = {0};
- if (!strcmp(name, ".") || !strcmp(name, ".."))
- continue;
-
- snprintf(name, sizeof(name), "%s%s/address", NET_SYSFS_ROOT, dir);
- fd = open(name, O_RDONLY);
- if (fd == -1)
- continue;
- retval = read(fd, buf, 17);
- close(fd);
-
- if (strncasecmp(buf, mac, 17) == 0) {
- strlcpy(context->iface, dir, sizeof(context->iface));
- rc = 0;
- break;
- }
- }
-
- for (i = 0; i < n; i++)
- free(namelist[i]);
- free(namelist);
-
- return rc;
-}
-
/*
* Routines to fill in the context values.
*/
@@ -232,10 +93,7 @@ static int fill_nic_context(char *id, struct boot_context *context)
if (rc)
return rc;
- rc = get_iface_from_device(id, context);
- if (rc)
- rc = get_iface_from_mac(id, context);
-
+ rc = net_get_dev_from_hwaddress(context->mac, context->iface);
if (rc)
return rc;