* Author: Eric Barton <eric@bartonsoftware.com>
*/
-#include <linux/pci.h>
#include "socklnd.h"
+#include <linux/inetdevice.h>
static struct lnet_lnd the_ksocklnd;
struct ksock_nal_data ksocknal_data;
read_unlock(&ksocknal_data.ksnd_global_lock);
if (notify)
- lnet_notify(peer_ni->ksnp_ni, peer_ni->ksnp_id.nid, 0,
- last_alive);
+ lnet_notify(peer_ni->ksnp_ni, peer_ni->ksnp_id.nid,
+ false, false, last_alive);
}
void
}
void
-ksocknal_notify(struct lnet_ni *ni, lnet_nid_t gw_nid, int alive)
+ksocknal_notify_gw_down(lnet_nid_t gw_nid)
{
/* The router is telling me she's been notified of a change in
* gateway state....
.pid = LNET_PID_ANY,
};
- CDEBUG (D_NET, "gw %s %s\n", libcfs_nid2str(gw_nid),
- alive ? "up" : "down");
+ CDEBUG(D_NET, "gw %s down\n", libcfs_nid2str(gw_nid));
- if (!alive) {
- /* If the gateway crashed, close all open connections... */
- ksocknal_close_matching_conns (id, 0);
- return;
- }
+ /* If the gateway crashed, close all open connections... */
+ ksocknal_close_matching_conns(id, 0);
+ return;
- /* ...otherwise do nothing. We can only establish new connections
- * if we have autroutes, and these connect on demand. */
+ /* We can only establish new connections
+ * if we have autroutes, and these connect on demand. */
}
void
}
static int
-ksocknal_enumerate_interfaces(struct ksock_net *net)
+ksocknal_enumerate_interfaces(struct ksock_net *net, char *iname)
{
- char **names;
- int i;
- int j;
- int rc;
- int n;
-
- n = lnet_ipif_enumerate(&names);
- if (n <= 0) {
- CERROR("Can't enumerate interfaces: %d\n", n);
- return n;
- }
+ struct net_device *dev;
- for (i = j = 0; i < n; i++) {
- int up;
- __u32 ip;
- __u32 mask;
-
- if (!strcmp(names[i], "lo")) /* skip the loopback IF */
- continue;
+ rtnl_lock();
+ for_each_netdev(&init_net, dev) {
+ /* The iname specified by an user land configuration can
+ * map to an ifa_label so always treat iname as an ifa_label.
+ * If iname is NULL then fall back to the net device name.
+ */
+ const char *name = iname ? iname : dev->name;
+ struct in_device *in_dev;
- rc = lnet_ipif_query(names[i], &up, &ip, &mask);
- if (rc != 0) {
- CWARN("Can't get interface %s info: %d\n",
- names[i], rc);
- continue;
- }
+ if (strcmp(dev->name, "lo") == 0) /* skip the loopback IF */
+ continue;
- if (!up) {
- CWARN("Ignoring interface %s (down)\n",
- names[i]);
- continue;
- }
+ if (!(dev_get_flags(dev) & IFF_UP)) {
+ CWARN("Ignoring interface %s (down)\n", dev->name);
+ continue;
+ }
- if (j == LNET_INTERFACES_NUM) {
- CWARN("Ignoring interface %s (too many interfaces)\n",
- names[i]);
+ in_dev = __in_dev_get_rtnl(dev);
+ if (!in_dev) {
+ CWARN("Interface %s has no IPv4 status.\n", dev->name);
continue;
}
- net->ksnn_interfaces[j].ksni_ipaddr = ip;
- net->ksnn_interfaces[j].ksni_netmask = mask;
- strlcpy(net->ksnn_interfaces[j].ksni_name,
- names[i], sizeof(net->ksnn_interfaces[j].ksni_name));
- j++;
- }
+ for_ifa(in_dev)
+ if (strcmp(name, ifa->ifa_label) == 0) {
+ int idx = net->ksnn_ninterfaces;
+ struct ksock_interface *ksi;
+
+ if (idx >= ARRAY_SIZE(net->ksnn_interfaces)) {
+ rtnl_unlock();
+ return -E2BIG;
+ }
- lnet_ipif_free_enumeration(names, n);
+ ksi = &net->ksnn_interfaces[idx];
+ ksi->ksni_ipaddr = ntohl(ifa->ifa_local);
+ ksi->ksni_netmask = ifa->ifa_mask;
+ strlcpy(ksi->ksni_name,
+ name, sizeof(ksi->ksni_name));
+ net->ksnn_ninterfaces++;
+ break;
+ }
+ endfor_ifa(in_dev);
+ }
+ rtnl_unlock();
- if (j == 0)
+ if (net->ksnn_ninterfaces == 0)
CERROR("Can't find any usable interfaces\n");
- return j;
+ return net->ksnn_ninterfaces > 0 ? 0 : -ENOENT;
}
static int
net_tunables->lct_peer_rtr_credits =
*ksocknal_tunables.ksnd_peerrtrcredits;
- if (ni->ni_interfaces[0] == NULL) {
- rc = ksocknal_enumerate_interfaces(net);
- if (rc <= 0)
+ if (!ni->ni_interfaces[0]) {
+ rc = ksocknal_enumerate_interfaces(net, NULL);
+ if (rc < 0)
goto fail_1;
-
- net->ksnn_ninterfaces = 1;
} else {
+ /* Before Multi-Rail ksocklnd would manage
+ * multiple interfaces with its own tcp bonding.
+ * If we encounter an old configuration using
+ * this tcp bonding approach then we need to
+ * handle more than one ni_interfaces.
+ *
+ * In Multi-Rail configuration only ONE ni_interface
+ * should exist. Each IP alias should be mapped to
+ * each 'struct net_ni'.
+ */
for (i = 0; i < LNET_INTERFACES_NUM; i++) {
- int up;
+ int j;
- if (ni->ni_interfaces[i] == NULL)
+ if (!ni->ni_interfaces[i])
break;
- rc = lnet_ipif_query(ni->ni_interfaces[i], &up,
- &net->ksnn_interfaces[i].ksni_ipaddr,
- &net->ksnn_interfaces[i].ksni_netmask);
+ for (j = 0; j < net->ksnn_ninterfaces; j++) {
+ struct ksock_interface *ksi;
- if (rc != 0) {
- CERROR("Can't get interface %s info: %d\n",
- ni->ni_interfaces[i], rc);
- goto fail_1;
- }
+ ksi = &net->ksnn_interfaces[j];
- if (!up) {
- CERROR("Interface %s is down\n",
- ni->ni_interfaces[i]);
- goto fail_1;
+ if (strcmp(ni->ni_interfaces[i],
+ ksi->ksni_name) == 0) {
+ CERROR("found duplicate %s\n",
+ ksi->ksni_name);
+ rc = -EEXIST;
+ goto fail_1;
+ }
}
- strlcpy(net->ksnn_interfaces[i].ksni_name,
- ni->ni_interfaces[i],
- sizeof(net->ksnn_interfaces[i].ksni_name));
-
+ rc = ksocknal_enumerate_interfaces(net, ni->ni_interfaces[i]);
+ if (rc < 0)
+ goto fail_1;
}
- net->ksnn_ninterfaces = i;
}
net_dev = dev_get_by_name(&init_net,
the_ksocklnd.lnd_ctl = ksocknal_ctl;
the_ksocklnd.lnd_send = ksocknal_send;
the_ksocklnd.lnd_recv = ksocknal_recv;
- the_ksocklnd.lnd_notify = ksocknal_notify;
+ the_ksocklnd.lnd_notify_peer_down = ksocknal_notify_gw_down;
the_ksocklnd.lnd_query = ksocknal_query;
the_ksocklnd.lnd_accept = ksocknal_accept;