]>
Commit | Line | Data |
---|---|---|
e331e246 TG |
1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
2 | ||
3 | /*** | |
4 | This file is part of systemd. | |
5 | ||
6 | Copyright 2015 Tom Gundersen | |
7 | ||
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. | |
12 | ||
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. | |
17 | ||
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/>. | |
20 | ***/ | |
21 | ||
22 | #include "bus-util.h" | |
23 | #include "strv.h" | |
24 | ||
25 | #include "networkd.h" | |
26 | #include "networkd-link.h" | |
27 | ||
28 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_operational_state, link_operstate, LinkOperationalState); | |
29 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_administrative_state, link_state, LinkState); | |
30 | ||
31 | const sd_bus_vtable link_vtable[] = { | |
32 | SD_BUS_VTABLE_START(0), | |
33 | ||
34 | SD_BUS_PROPERTY("OperationalState", "s", property_get_operational_state, offsetof(Link, operstate), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), | |
35 | SD_BUS_PROPERTY("AdministrativeState", "s", property_get_administrative_state, offsetof(Link, state), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), | |
36 | ||
37 | SD_BUS_VTABLE_END | |
38 | }; | |
39 | ||
40 | static char *link_bus_path(Link *link) { | |
41 | char *p; | |
42 | ||
43 | assert(link); | |
44 | assert(link->ifindex > 0); | |
45 | ||
46 | asprintf(&p, "/org/freedesktop/network1/link/%d", link->ifindex); | |
47 | ||
48 | return p; | |
49 | } | |
50 | ||
51 | int link_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) { | |
52 | _cleanup_strv_free_ char **l = NULL; | |
53 | Manager *m = userdata; | |
54 | Link *link; | |
55 | Iterator i; | |
56 | int r; | |
57 | ||
58 | assert(bus); | |
59 | assert(path); | |
60 | assert(m); | |
61 | assert(nodes); | |
62 | ||
63 | HASHMAP_FOREACH(link, m->links, i) { | |
64 | char *p; | |
65 | ||
66 | p = link_bus_path(link); | |
67 | if (!p) | |
68 | return -ENOMEM; | |
69 | ||
70 | r = strv_consume(&l, p); | |
71 | if (r < 0) | |
72 | return r; | |
73 | } | |
74 | ||
75 | *nodes = l; | |
76 | l = NULL; | |
77 | ||
78 | return 1; | |
79 | } | |
80 | ||
81 | int link_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) { | |
82 | Manager *m = userdata; | |
83 | Link *link; | |
84 | int ifindex, r; | |
85 | ||
86 | assert(bus); | |
87 | assert(path); | |
88 | assert(interface); | |
89 | assert(m); | |
90 | assert(found); | |
91 | ||
92 | if (sscanf(path, "/org/freedesktop/network1/link/%d", &ifindex) != 1) | |
93 | return 0; | |
94 | ||
95 | r = link_get(m, ifindex, &link); | |
96 | if (r < 0) | |
97 | return 0; | |
98 | ||
99 | *found = link; | |
100 | ||
101 | return 1; | |
102 | } | |
103 | ||
104 | int link_send_changed(Link *link, const char *property, ...) { | |
105 | _cleanup_free_ char *p = NULL; | |
106 | char **l; | |
107 | ||
108 | assert(link); | |
109 | assert(link->manager); | |
110 | ||
111 | l = strv_from_stdarg_alloca(property); | |
112 | ||
113 | p = link_bus_path(link); | |
114 | if (!p) | |
115 | return -ENOMEM; | |
116 | ||
117 | return sd_bus_emit_properties_changed_strv( | |
118 | link->manager->bus, | |
119 | p, | |
120 | "org.freedesktop.network1.Link", | |
121 | l); | |
122 | } |