]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-wait-online-link.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2014 Lennart Poettering
7 Copyright 2014 Tom Gundersen
9 systemd is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
14 systemd is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public License
20 along with systemd; If not, see <http://www.gnu.org/licenses/>.
24 #include "sd-network.h"
26 #include "networkd-wait-online-link.h"
28 int link_new(Manager
*m
, Link
**ret
, int ifindex
, const char *ifname
) {
29 _cleanup_(link_freep
) Link
*l
= NULL
;
35 r
= hashmap_ensure_allocated(&m
->links
, NULL
);
39 r
= hashmap_ensure_allocated(&m
->links_by_name
, &string_hash_ops
);
49 l
->ifname
= strdup(ifname
);
53 r
= hashmap_put(m
->links_by_name
, l
->ifname
, l
);
59 r
= hashmap_put(m
->links
, INT_TO_PTR(ifindex
), l
);
70 Link
*link_free(Link
*l
) {
76 hashmap_remove(l
->manager
->links
, INT_TO_PTR(l
->ifindex
));
77 hashmap_remove(l
->manager
->links_by_name
, l
->ifname
);
85 int link_update_rtnl(Link
*l
, sd_netlink_message
*m
) {
93 r
= sd_rtnl_message_link_get_flags(m
, &l
->flags
);
97 r
= sd_netlink_message_read_string(m
, IFLA_IFNAME
, &ifname
);
101 if (!streq(l
->ifname
, ifname
)) {
104 new_ifname
= strdup(ifname
);
108 hashmap_remove(l
->manager
->links_by_name
, l
->ifname
);
110 l
->ifname
= new_ifname
;
112 r
= hashmap_put(l
->manager
->links_by_name
, l
->ifname
, l
);
120 int link_update_monitor(Link
*l
) {
123 l
->operational_state
= mfree(l
->operational_state
);
125 sd_network_link_get_operational_state(l
->ifindex
, &l
->operational_state
);
127 l
->state
= mfree(l
->state
);
129 sd_network_link_get_setup_state(l
->ifindex
, &l
->state
);