2 This file is part of systemd.
4 Copyright 2015 Tom Gundersen
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 #include "alloc-util.h"
22 #include "networkd-link.h"
23 #include "networkd-manager.h"
24 #include "parse-util.h"
27 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_operational_state
, link_operstate
, LinkOperationalState
);
28 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_administrative_state
, link_state
, LinkState
);
30 const sd_bus_vtable link_vtable
[] = {
31 SD_BUS_VTABLE_START(0),
33 SD_BUS_PROPERTY("OperationalState", "s", property_get_operational_state
, offsetof(Link
, operstate
), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
34 SD_BUS_PROPERTY("AdministrativeState", "s", property_get_administrative_state
, offsetof(Link
, state
), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
39 static char *link_bus_path(Link
*link
) {
40 _cleanup_free_
char *ifindex
= NULL
;
45 assert(link
->ifindex
> 0);
47 if (asprintf(&ifindex
, "%d", link
->ifindex
) < 0)
50 r
= sd_bus_path_encode("/org/freedesktop/network1/link", ifindex
, &p
);
57 int link_node_enumerator(sd_bus
*bus
, const char *path
, void *userdata
, char ***nodes
, sd_bus_error
*error
) {
58 _cleanup_strv_free_
char **l
= NULL
;
59 Manager
*m
= userdata
;
69 l
= new0(char*, hashmap_size(m
->links
) + 1);
73 HASHMAP_FOREACH(link
, m
->links
, i
) {
76 p
= link_bus_path(link
);
90 int link_object_find(sd_bus
*bus
, const char *path
, const char *interface
, void *userdata
, void **found
, sd_bus_error
*error
) {
91 _cleanup_free_
char *identifier
= NULL
;
92 Manager
*m
= userdata
;
102 r
= sd_bus_path_decode(path
, "/org/freedesktop/network1/link", &identifier
);
106 r
= parse_ifindex(identifier
, &ifindex
);
110 r
= link_get(m
, ifindex
, &link
);
119 int link_send_changed(Link
*link
, const char *property
, ...) {
120 _cleanup_free_
char *p
= NULL
;
124 assert(link
->manager
);
126 if (!link
->manager
->bus
)
127 return 0; /* replace with assert when we have kdbus */
129 l
= strv_from_stdarg_alloca(property
);
131 p
= link_bus_path(link
);
135 return sd_bus_emit_properties_changed_strv(
138 "org.freedesktop.network1.Link",