1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2015 Tom Gundersen
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.
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.
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/>.
22 #include "alloc-util.h"
24 #include "string-util.h"
27 static int property_get_ether_addrs(
30 const char *interface
,
32 sd_bus_message
*reply
,
34 sd_bus_error
*error
) {
36 Network
*n
= userdata
;
37 const char *ether
= NULL
;
45 ether
= ether_ntoa(n
->match_mac
);
47 r
= sd_bus_message_open_container(reply
, 'a', "s");
52 r
= sd_bus_message_append(reply
, "s", strempty(ether
));
57 return sd_bus_message_close_container(reply
);
60 const sd_bus_vtable network_vtable
[] = {
61 SD_BUS_VTABLE_START(0),
63 SD_BUS_PROPERTY("Description", "s", NULL
, offsetof(Network
, description
), SD_BUS_VTABLE_PROPERTY_CONST
),
64 SD_BUS_PROPERTY("SourcePath", "s", NULL
, offsetof(Network
, filename
), SD_BUS_VTABLE_PROPERTY_CONST
),
65 SD_BUS_PROPERTY("MatchMAC", "as", property_get_ether_addrs
, offsetof(Network
, match_mac
), SD_BUS_VTABLE_PROPERTY_CONST
),
66 SD_BUS_PROPERTY("MatchPath", "as", NULL
, offsetof(Network
, match_path
), SD_BUS_VTABLE_PROPERTY_CONST
),
67 SD_BUS_PROPERTY("MatchDriver", "as", NULL
, offsetof(Network
, match_driver
), SD_BUS_VTABLE_PROPERTY_CONST
),
68 SD_BUS_PROPERTY("MatchType", "as", NULL
, offsetof(Network
, match_type
), SD_BUS_VTABLE_PROPERTY_CONST
),
69 SD_BUS_PROPERTY("MatchName", "as", NULL
, offsetof(Network
, match_name
), SD_BUS_VTABLE_PROPERTY_CONST
),
74 static char *network_bus_path(Network
*network
) {
75 _cleanup_free_
char *name
= NULL
;
76 char *networkname
, *d
, *path
;
80 assert(network
->filename
);
82 name
= strdup(network
->filename
);
86 networkname
= basename(name
);
88 d
= strrchr(networkname
, '.');
92 assert(streq(d
, ".network"));
96 r
= sd_bus_path_encode("/org/freedesktop/network1/network", networkname
, &path
);
103 int network_node_enumerator(sd_bus
*bus
, const char *path
, void *userdata
, char ***nodes
, sd_bus_error
*error
) {
104 _cleanup_strv_free_
char **l
= NULL
;
105 Manager
*m
= userdata
;
114 LIST_FOREACH(networks
, network
, m
->networks
) {
117 p
= network_bus_path(network
);
121 r
= strv_consume(&l
, p
);
132 int network_object_find(sd_bus
*bus
, const char *path
, const char *interface
, void *userdata
, void **found
, sd_bus_error
*error
) {
133 Manager
*m
= userdata
;
135 _cleanup_free_
char *name
= NULL
;
144 r
= sd_bus_path_decode(path
, "/org/freedesktop/network1/network", &name
);
148 r
= network_get_by_name(m
, name
, &network
);