1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2013 Tom Gundersen <teg@jklm.no>
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 #include <netinet/ether.h>
26 #include "libudev-private.h"
29 int link_new(Manager *manager, struct udev_device *device, Link **ret) {
30 _cleanup_link_free_ Link *link = NULL;
41 ifindex = udev_device_get_ifindex(device);
45 link->ifindex = ifindex;
46 link->manager = manager;
48 r = hashmap_put(manager->links, &ifindex, link);
58 void link_free(Link *link) {
62 network_free(link->network);
64 hashmap_remove(link->manager->links, link);
69 int link_add(Manager *m, struct udev_device *device) {
78 ifindex = udev_device_get_ifindex(device);
79 link = hashmap_get(m->links, &ifindex);
83 r = link_new(m, device, &link);
85 log_error("could not create link: %s", strerror(-r));
89 r = network_get(m, device, &network);
91 return r == -ENOENT ? 0 : r;
93 r = network_apply(m, network, link);
100 int link_up(Manager *manager, Link *link) {
101 _cleanup_sd_rtnl_message_unref_ sd_rtnl_message *req = NULL;
104 r = sd_rtnl_message_link_new(RTM_NEWLINK, link->ifindex, 0, IFF_UP, &req);
106 log_error("Could not allocate RTM_NEWLINK message");
110 r = sd_rtnl_send_with_reply_and_block(manager->rtnl, req, 0, NULL);
112 log_error("Could not UP link: %s", strerror(-r));
116 log_info("Link is UP");