1 /*#############################################################################
3 # IPFire.org - A linux based firewall #
4 # Copyright (C) 2023 IPFire Network Development Team #
6 # This program is free software: you can redistribute it and/or modify #
7 # it under the terms of the GNU General Public License as published by #
8 # the Free Software Foundation, either version 3 of the License, or #
9 # (at your option) any later version. #
11 # This program is distributed in the hope that it will be useful, #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 # GNU General Public License for more details. #
16 # You should have received a copy of the GNU General Public License #
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 #############################################################################*/
30 static int nw_zone_node_enumerator(sd_bus
* bus
, const char* path
, void* data
,
31 char*** nodes
, sd_bus_error
* error
) {
34 DEBUG("Enumerating zones...\n");
36 // Fetch a reference to the daemon
37 nw_daemon
* daemon
= (nw_daemon
*)data
;
40 nw_zones
* zones
= nw_daemon_zones(daemon
);
42 // Make bus paths for all zones
43 r
= nw_zones_bus_paths(zones
, nodes
);
48 nw_zones_unref(zones
);
53 static int nw_zone_object_find(sd_bus
* bus
, const char* path
, const char* interface
,
54 void* data
, void** found
, sd_bus_error
* error
) {
58 // Fetch a reference to the daemon
59 nw_daemon
* daemon
= (nw_daemon
*)data
;
61 // Decode the path of the requested object
62 r
= sd_bus_path_decode(path
, "/org/ipfire/network1/zone", &name
);
67 nw_zone
* zone
= nw_daemon_get_zone_by_name(daemon
, name
);
82 static int nw_zone_bus_get_mtu(sd_bus
* bus
, const char *path
, const char *interface
,
83 const char* property
, sd_bus_message
* reply
, void* data
, sd_bus_error
*error
) {
84 nw_zone
* zone
= (nw_zone
*)data
;
86 return sd_bus_message_append(reply
, "u", nw_zone_mtu(zone
));
89 static int nw_zone_bus_set_mtu(sd_bus
* bus
, const char* path
, const char* interface
,
90 const char* property
, sd_bus_message
* value
, void* data
, sd_bus_error
* error
) {
94 nw_zone
* zone
= (nw_zone
*)data
;
97 r
= sd_bus_message_read(value
, "u", &mtu
);
101 if (!nw_zone_set_mtu(zone
, mtu
))
107 static const sd_bus_vtable zone_vtable
[] = {
108 SD_BUS_VTABLE_START(0),
111 SD_BUS_WRITABLE_PROPERTY("MTU", "u", nw_zone_bus_get_mtu
, nw_zone_bus_set_mtu
,
112 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
117 const nw_bus_implementation zone_bus_impl
= {
118 "/org/ipfire/network1/zone",
119 "org.ipfire.network1.Zone",
120 .fallback_vtables
= BUS_FALLBACK_VTABLES({zone_vtable
, nw_zone_object_find
}),
121 .node_enumerator
= nw_zone_node_enumerator
,