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"
21 #include "networkd-manager.h"
22 #include "string-util.h"
25 static int property_get_ether_addrs(
28 const char *interface
,
30 sd_bus_message
*reply
,
32 sd_bus_error
*error
) {
34 Network
*n
= userdata
;
35 const char *ether
= NULL
;
43 ether
= ether_ntoa(n
->match_mac
);
45 r
= sd_bus_message_open_container(reply
, 'a', "s");
50 r
= sd_bus_message_append(reply
, "s", strempty(ether
));
55 return sd_bus_message_close_container(reply
);
58 const sd_bus_vtable network_vtable
[] = {
59 SD_BUS_VTABLE_START(0),
61 SD_BUS_PROPERTY("Description", "s", NULL
, offsetof(Network
, description
), SD_BUS_VTABLE_PROPERTY_CONST
),
62 SD_BUS_PROPERTY("SourcePath", "s", NULL
, offsetof(Network
, filename
), SD_BUS_VTABLE_PROPERTY_CONST
),
63 SD_BUS_PROPERTY("MatchMAC", "as", property_get_ether_addrs
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
64 SD_BUS_PROPERTY("MatchPath", "as", NULL
, offsetof(Network
, match_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
65 SD_BUS_PROPERTY("MatchDriver", "as", NULL
, offsetof(Network
, match_driver
), SD_BUS_VTABLE_PROPERTY_CONST
),
66 SD_BUS_PROPERTY("MatchType", "as", NULL
, offsetof(Network
, match_type
), SD_BUS_VTABLE_PROPERTY_CONST
),
67 SD_BUS_PROPERTY("MatchName", "as", NULL
, offsetof(Network
, match_name
), SD_BUS_VTABLE_PROPERTY_CONST
),
72 static char *network_bus_path(Network
*network
) {
73 _cleanup_free_
char *name
= NULL
;
74 char *networkname
, *d
, *path
;
78 assert(network
->filename
);
80 name
= strdup(network
->filename
);
84 networkname
= basename(name
);
86 d
= strrchr(networkname
, '.');
90 assert(streq(d
, ".network"));
94 r
= sd_bus_path_encode("/org/freedesktop/network1/network", networkname
, &path
);
101 int network_node_enumerator(sd_bus
*bus
, const char *path
, void *userdata
, char ***nodes
, sd_bus_error
*error
) {
102 _cleanup_strv_free_
char **l
= NULL
;
103 Manager
*m
= userdata
;
112 LIST_FOREACH(networks
, network
, m
->networks
) {
115 p
= network_bus_path(network
);
119 r
= strv_consume(&l
, p
);
130 int network_object_find(sd_bus
*bus
, const char *path
, const char *interface
, void *userdata
, void **found
, sd_bus_error
*error
) {
131 Manager
*m
= userdata
;
133 _cleanup_free_
char *name
= NULL
;
142 r
= sd_bus_path_decode(path
, "/org/freedesktop/network1/network", &name
);
146 r
= network_get_by_name(m
, name
, &network
);