Esempio n. 1
0
static int manager_process_link(Manager *m, struct udev_device *device) {
        Link *link;
        int r;

        if (streq_ptr(udev_device_get_action(device), "remove")) {
                uint64_t ifindex;

                log_debug("%s: link removed", udev_device_get_sysname(device));

                ifindex = udev_device_get_ifindex(device);
                link = hashmap_get(m->links, &ifindex);
                if (!link)
                        return 0;

                link_free(link);
        } else {
                r = link_add(m, device, &link);
                if (r < 0) {
                        if (r == -EEXIST)
                                log_debug("%s: link already exists, ignoring",
                                          link->ifname);
                        else
                                log_error("%s: could not handle link: %s",
                                          udev_device_get_sysname(device),
                                          strerror(-r));
                } else
                        log_debug("%s: link (with ifindex %" PRIu64") added",
                                  link->ifname, link->ifindex);
        }

        return 0;
}
Esempio n. 2
0
int main(void) {
        _cleanup_manager_free_ Manager *manager = NULL;
        struct udev *udev;
        struct udev_device *loopback;

        assert_se(manager_new(&manager) >= 0);

        test_load_config(manager);

        udev = udev_new();
        assert_se(udev);

        loopback = udev_device_new_from_syspath(udev, "/sys/class/net/lo");
        assert_se(loopback);
        assert_se(udev_device_get_ifindex(loopback) == 1);

        test_network_get(manager, loopback);

        test_link(manager, loopback);

        assert_se(manager_udev_listen(manager) >= 0);
        assert_se(manager_udev_enumerate_links(manager) >= 0);
        assert_se(manager_rtnl_listen(manager) >= 0);

        udev_device_unref(loopback);
        udev_unref(udev);
}
Esempio n. 3
0
static int manager_process_link(Manager *m, struct udev_device *device) {
        Link *link = NULL;
        int r;

        assert(m);
        assert(device);

        link_get(m, udev_device_get_ifindex(device), &link);

        if (streq_ptr(udev_device_get_action(device), "remove")) {
                log_debug("%s: link removed", udev_device_get_sysname(device));

                if (link)
                        link_free(link);
        } else {
                if (link) {
                        log_debug("%s: link already exists, ignoring",
                                  link->ifname);
                        return 0;
                }

                r = link_add(m, device, &link);
                if (r < 0) {
                        log_error("%s: could not handle link: %s",
                                  udev_device_get_sysname(device),
                                  strerror(-r));
                } else
                        log_debug("%s: link (with ifindex %" PRIu64") added",
                                  link->ifname, link->ifindex);
        }

        return 0;
}
Esempio n. 4
0
static int manager_process_link(Manager *m, struct udev_device *device) {
        Link *link;
        int r;

        if (streq_ptr(udev_device_get_action(device), "remove")) {
                uint64_t ifindex;

                log_debug("Link removed: %s", udev_device_get_sysname(device));

                ifindex = udev_device_get_ifindex(device);
                link = hashmap_get(m->links, &ifindex);
                if (!link)
                        return 0;

                link_free(link);
        } else {
                log_debug("New link: %s", udev_device_get_sysname(device));

                r = link_add(m, device);
                if (r < 0) {
                        log_error("Could not handle link %s: %s",
                                        udev_device_get_sysname(device),
                                        strerror(-r));
                }
        }

        return 0;
}
Esempio n. 5
0
int main(void) {
        _cleanup_manager_free_ Manager *manager = NULL;
        struct udev *udev;
        struct udev_device *loopback;
        int r;

        test_deserialize_in_addr();
        test_deserialize_dhcp_routes();
        test_address_equality();

        assert_se(manager_new(&manager) >= 0);

        r = test_load_config(manager);
        if (r == -EPERM)
                return EXIT_TEST_SKIP;

        udev = udev_new();
        assert_se(udev);

        loopback = udev_device_new_from_syspath(udev, "/sys/class/net/lo");
        assert_se(loopback);
        assert_se(udev_device_get_ifindex(loopback) == 1);

        test_network_get(manager, loopback);

        assert_se(manager_rtnl_enumerate_links(manager) >= 0);

        udev_device_unref(loopback);
        udev_unref(udev);
}