]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-wait-online-link.c
e63ba07e909525bf0ead0d03f427a14f287193af
2 This file is part of systemd.
4 Copyright 2014 Lennart Poettering
5 Copyright 2014 Tom Gundersen
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
21 #include "sd-network.h"
23 #include "alloc-util.h"
24 #include "networkd-wait-online-link.h"
25 #include "string-util.h"
27 int link_new(Manager
*m
, Link
**ret
, int ifindex
, const char *ifname
) {
28 _cleanup_(link_freep
) Link
*l
= NULL
;
34 r
= hashmap_ensure_allocated(&m
->links
, NULL
);
38 r
= hashmap_ensure_allocated(&m
->links_by_name
, &string_hash_ops
);
48 l
->ifname
= strdup(ifname
);
52 r
= hashmap_put(m
->links_by_name
, l
->ifname
, l
);
58 r
= hashmap_put(m
->links
, INT_TO_PTR(ifindex
), l
);
69 Link
*link_free(Link
*l
) {
75 hashmap_remove(l
->manager
->links
, INT_TO_PTR(l
->ifindex
));
76 hashmap_remove(l
->manager
->links_by_name
, l
->ifname
);
83 int link_update_rtnl(Link
*l
, sd_netlink_message
*m
) {
91 r
= sd_rtnl_message_link_get_flags(m
, &l
->flags
);
95 r
= sd_netlink_message_read_string(m
, IFLA_IFNAME
, &ifname
);
99 if (!streq(l
->ifname
, ifname
)) {
102 new_ifname
= strdup(ifname
);
106 hashmap_remove(l
->manager
->links_by_name
, l
->ifname
);
108 l
->ifname
= new_ifname
;
110 r
= hashmap_put(l
->manager
->links_by_name
, l
->ifname
, l
);
118 int link_update_monitor(Link
*l
) {
121 l
->operational_state
= mfree(l
->operational_state
);
123 sd_network_link_get_operational_state(l
->ifindex
, &l
->operational_state
);
125 l
->state
= mfree(l
->state
);
127 sd_network_link_get_setup_state(l
->ifindex
, &l
->state
);