summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorMike Christie <michaelc@cs.wisc.edu>2010-01-15 11:50:16 -0600
committerMike Christie <michaelc@cs.wisc.edu>2010-01-15 11:50:16 -0600
commit65a224afcd13198ce4d881be0ad3647143edb144 (patch)
treec93cfec8b924061b363e05ddd3273dc708307626 /utils
parent0c74f070052002cb984cd39146e0090ec930714e (diff)
downloadopen-iscsi-65a224afcd13198ce4d881be0ad3647143edb144.tar.gz
iscsi tools: nic setup cleanup
This just breaks up the network part of the nic setup code to a new function that lives in the net utils code, so it can be used by other callers one day.
Diffstat (limited to 'utils')
-rw-r--r--utils/fwparam_ibft/fw_entry.c126
-rw-r--r--utils/fwparam_ibft/fwparam_ibft_sysfs.c3
2 files changed, 12 insertions, 117 deletions
diff --git a/utils/fwparam_ibft/fw_entry.c b/utils/fwparam_ibft/fw_entry.c
index 9dbaf59..ae5d34a 100644
--- a/utils/fwparam_ibft/fw_entry.c
+++ b/utils/fwparam_ibft/fw_entry.c
@@ -49,8 +49,7 @@ int fw_setup_nics(void)
struct boot_context *context;
struct list_head targets;
char *iface_prev = NULL, transport[16];
- int sock;
- int ret;
+ int needs_bringup = 0, ret = 0, err;
INIT_LIST_HEAD(&targets);
@@ -60,140 +59,35 @@ int fw_setup_nics(void)
return ENODEV;
}
- /* Create socket for making networking changes */
- if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
- perror("socket(AF_INET, SOCK_DGRAM, 0)");
- ret = errno;
- goto free_targets;
- }
-
/*
* For each target in iBFT bring up required NIC and use routing
* to force iSCSI traffic through correct NIC
*/
list_for_each_entry(context, &targets, list) {
- if (!net_get_transport_name_from_iface(context->iface,
- transport))
- continue;
-
- /* Bring up NIC with correct address - unless it
- * has already been handled (2 targets in IBFT may share
- * one NIC)
- */
- struct sockaddr_in ipaddr = { .sin_family = AF_INET };
- struct sockaddr_in netmask = { .sin_family = AF_INET };
- struct sockaddr_in hostmask = { .sin_family = AF_INET };
- struct sockaddr_in gateway = { .sin_family = AF_INET };
- struct sockaddr_in tgt_ipaddr = { .sin_family = AF_INET };
- struct rtentry rt;
- struct ifreq ifr;
-
- if (!strlen(context->iface)) {
- printf("No iface in fw entry\n");
- ret = EINVAL;
- continue;
- }
- if (!inet_aton(context->ipaddr, &ipaddr.sin_addr)) {
- printf("Invalid or no ipaddr in fw entry\n");
- ret = EINVAL;
- continue;
- }
-
- if (!inet_aton(context->mask, &netmask.sin_addr)) {
- printf("Invalid or no netmask in fw entry\n");
- ret = EINVAL;
+ /* if it is a offload nic ignore it */
+ if (!net_get_transport_name_from_netdev(context->iface,
+ transport))
continue;
- }
- inet_aton("255.255.255.255", &hostmask.sin_addr);
-
- if (!inet_aton(context->target_ipaddr, &tgt_ipaddr.sin_addr)) {
- printf("Invalid or no target ipaddr in fw entry\n");
- ret = EINVAL;
- continue;
- }
- /* Only set IP/NM if this is a new interface */
if (iface_prev == NULL || strcmp(context->iface, iface_prev)) {
/* Note: test above works because there is a
* maximum of two targets in the iBFT
*/
iface_prev = context->iface;
-
- /* TODO: create vlan if strlen(context->vlan) */
-
- /* Bring up interface */
- memset(&ifr, 0, sizeof(ifr));
- strncpy(ifr.ifr_name, context->iface, IFNAMSIZ);
- ifr.ifr_flags = IFF_UP | IFF_RUNNING;
- if (ioctl(sock, SIOCSIFFLAGS, &ifr) < 0) {
- perror("ioctl(SIOCSIFFLAGS)");
- ret = errno;
- continue;
- }
- /* Set IP address */
- memset(&ifr, 0, sizeof(ifr));
- strncpy(ifr.ifr_name, context->iface, IFNAMSIZ);
- memcpy(&ifr.ifr_addr, &ipaddr, sizeof(struct sockaddr));
- if (ioctl(sock, SIOCSIFADDR, &ifr) < 0) {
- perror("ioctl(SIOCSIFADDR)");
- ret = errno;
- continue;
- }
- /* Set netmask */
- memset(&ifr, 0, sizeof(ifr));
- strncpy(ifr.ifr_name, context->iface, IFNAMSIZ);
- memcpy(&ifr.ifr_addr, &netmask, sizeof(struct sockaddr));
- if (ioctl(sock, SIOCSIFNETMASK, &ifr) < 0) {
- perror("ioctl(SIOCSIFNETMASK)");
- ret = errno;
- continue;
- }
+ needs_bringup = 1;
}
- /* Set static route to target via this interface */
- memset((char *) &rt, 0, sizeof(rt));
- memcpy(&rt.rt_dst, &tgt_ipaddr, sizeof(tgt_ipaddr));
- memcpy(&rt.rt_genmask, &hostmask, sizeof(hostmask));
- rt.rt_flags = RTF_UP | RTF_HOST;
- rt.rt_dev = context->iface;
-
- if ((tgt_ipaddr.sin_addr.s_addr & netmask.sin_addr.s_addr) ==
- (ipaddr.sin_addr.s_addr & netmask.sin_addr.s_addr)) {
- /* Same subnet */
- if (ioctl(sock, SIOCADDRT, &rt) < 0) {
- if (errno != EEXIST) {
- perror("ioctl(SIOCADDRT)");
- ret = errno;
- continue;
- }
- }
- } else {
- /* Different subnet. Use gateway */
- rt.rt_flags |= RTF_GATEWAY;
- if (!inet_aton(context->gateway, &gateway.sin_addr)) {
- printf("Invalid or no gateway in fw entry\n");
- ret = errno;
- continue;
- }
- memcpy(&rt.rt_gateway, &gateway, sizeof(gateway));
- if (ioctl(sock, SIOCADDRT, &rt) < 0) {
- if (errno != EEXIST) {
- perror("ioctl(SIOCADDRT)");
- ret = errno;
- continue;
- }
- }
- }
- /* This target handled */
+ err = net_setup_netdev(context->iface, context->ipaddr,
+ context->mask, context->gateway,
+ context->target_ipaddr, needs_bringup);
+ if (err)
+ ret = err;
}
- close(sock);
-free_targets:
fw_free_targets(&targets);
return ret;
}
-
/**
* fw_get_entry - return boot context of portal used for boot
* @context: firmware info of portal
diff --git a/utils/fwparam_ibft/fwparam_ibft_sysfs.c b/utils/fwparam_ibft/fwparam_ibft_sysfs.c
index 9a2cb7d..9185c85 100644
--- a/utils/fwparam_ibft/fwparam_ibft_sysfs.c
+++ b/utils/fwparam_ibft/fwparam_ibft_sysfs.c
@@ -181,7 +181,8 @@ static int fill_nic_context(char *id, struct boot_context *context)
*/
rc = get_iface_from_device(id, context);
if (rc) {
- rc = net_get_dev_from_hwaddress(context->mac, context->iface);
+ rc = net_get_netdev_from_hwaddress(context->mac,
+ context->iface);
if (rc)
return rc;
}