1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2015 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 "alloc-util.h"
22 #include "networkd-manager.h"
23 #include "string-util.h"
26 static int property_get_ether_addrs(
29 const char *interface
,
31 sd_bus_message
*reply
,
33 sd_bus_error
*error
) {
35 Network
*n
= userdata
;
36 const char *ether
= NULL
;
44 ether
= ether_ntoa(n
->match_mac
);
46 r
= sd_bus_message_open_container(reply
, 'a', "s");
51 r
= sd_bus_message_append(reply
, "s", strempty(ether
));
56 return sd_bus_message_close_container(reply
);
59 const sd_bus_vtable network_vtable
[] = {
60 SD_BUS_VTABLE_START(0),
62 SD_BUS_PROPERTY("Description", "s", NULL
, offsetof(Network
, description
), SD_BUS_VTABLE_PROPERTY_CONST
),
63 SD_BUS_PROPERTY("SourcePath", "s", NULL
, offsetof(Network
, filename
), SD_BUS_VTABLE_PROPERTY_CONST
),
64 SD_BUS_PROPERTY("MatchMAC", "as", property_get_ether_addrs
, 0, SD_BUS_VTABLE_PROPERTY_CONST
),
65 SD_BUS_PROPERTY("MatchPath", "as", NULL
, offsetof(Network
, match_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
66 SD_BUS_PROPERTY("MatchDriver", "as", NULL
, offsetof(Network
, match_driver
), SD_BUS_VTABLE_PROPERTY_CONST
),
67 SD_BUS_PROPERTY("MatchType", "as", NULL
, offsetof(Network
, match_type
), SD_BUS_VTABLE_PROPERTY_CONST
),
68 SD_BUS_PROPERTY("MatchName", "as", NULL
, offsetof(Network
, match_name
), SD_BUS_VTABLE_PROPERTY_CONST
),
73 static char *network_bus_path(Network
*network
) {
74 _cleanup_free_
char *name
= NULL
;
75 char *networkname
, *d
, *path
;
79 assert(network
->filename
);
81 name
= strdup(network
->filename
);
85 networkname
= basename(name
);
87 d
= strrchr(networkname
, '.');
91 assert(streq(d
, ".network"));
95 r
= sd_bus_path_encode("/org/freedesktop/network1/network", networkname
, &path
);
102 int network_node_enumerator(sd_bus
*bus
, const char *path
, void *userdata
, char ***nodes
, sd_bus_error
*error
) {
103 _cleanup_strv_free_
char **l
= NULL
;
104 Manager
*m
= userdata
;
113 LIST_FOREACH(networks
, network
, m
->networks
) {
116 p
= network_bus_path(network
);
120 r
= strv_consume(&l
, p
);
125 *nodes
= TAKE_PTR(l
);
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
);