]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/wait-online/link.c
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"
27 #include "string-util.h"
29 int link_new(Manager
*m
, Link
**ret
, int ifindex
, const char *ifname
) {
30 _cleanup_(link_freep
) Link
*l
= NULL
;
36 r
= hashmap_ensure_allocated(&m
->links
, NULL
);
40 r
= hashmap_ensure_allocated(&m
->links_by_name
, &string_hash_ops
);
50 l
->ifname
= strdup(ifname
);
54 r
= hashmap_put(m
->links_by_name
, l
->ifname
, l
);
60 r
= hashmap_put(m
->links
, INT_TO_PTR(ifindex
), l
);
71 Link
*link_free(Link
*l
) {
77 hashmap_remove(l
->manager
->links
, INT_TO_PTR(l
->ifindex
));
78 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
);