- ksocknal_data.ksnd_nnets--;
- if (ksocknal_data.ksnd_nnets == 0)
- ksocknal_base_shutdown();
-}
-
-static int
-ksocknal_enumerate_interfaces(struct ksock_net *net, char *iname)
-{
- struct net_device *dev;
-
- 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;
-
- if (strcmp(dev->name, "lo") == 0) /* skip the loopback IF */
- continue;
-
- if (!(dev_get_flags(dev) & IFF_UP)) {
- CWARN("Ignoring interface %s (down)\n", dev->name);
- continue;
- }
-
- in_dev = __in_dev_get_rtnl(dev);
- if (!in_dev) {
- CWARN("Interface %s has no IPv4 status.\n", dev->name);
- continue;
- }
-
- 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;
- }
-
- 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 (net->ksnn_ninterfaces == 0)
- CERROR("Can't find any usable interfaces\n");
-
- return net->ksnn_ninterfaces > 0 ? 0 : -ENOENT;