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 #############################################################################*/
21 #include <systemd/sd-bus.h>
26 typedef int (*networkctl_zone_walk_callback
)
27 (sd_bus
* bus
, const char* path
, const char* name
, void* data
);
29 static int networkctl_zone_walk(sd_bus
* bus
,
30 networkctl_zone_walk_callback callback
, void* data
) {
31 sd_bus_message
* reply
= NULL
;
32 sd_bus_error error
= SD_BUS_ERROR_NULL
;
36 r
= sd_bus_call_method(bus
, "org.ipfire.network1", "/org/ipfire/network1",
37 "org.ipfire.network1", "ListZones", &error
, &reply
, "");
39 fprintf(stderr
, "ListZones call failed: %m\n");
43 const char* name
= NULL
;
44 const char* path
= NULL
;
47 r
= sd_bus_message_enter_container(reply
, 'a', "(so)");
49 fprintf(stderr
, "Could not open container: %m\n");
53 // Iterate over all zones
55 r
= sd_bus_message_read(reply
, "(so)", &name
, &path
);
59 // Break if we reached the end of the container
64 r
= callback(bus
, path
, name
, data
);
69 // Close the container
70 sd_bus_message_exit_container(reply
);
74 sd_bus_message_unref(reply
);
75 sd_bus_error_free(&error
);
80 static int __networkctl_zone_list(sd_bus
* bus
, const char* path
, const char* name
, void* data
) {
86 static int networkctl_zone_list(sd_bus
* bus
, int argc
, char* argv
[]) {
87 return networkctl_zone_walk(bus
, __networkctl_zone_list
, NULL
);
90 int networkctl_zone(sd_bus
* bus
, int argc
, char* argv
[]) {
91 static const struct command commands
[] = {
92 { "list", 0, networkctl_zone_list
},
96 return command_dispatch(bus
, commands
, argc
, argv
);