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-device.h>
27 static int nw_daemon_handle_uevent_net(nw_daemon
* daemon
,
28 sd_device
* device
, sd_device_action_t action
) {
34 r
= sd_device_get_ifindex(device
, &ifindex
);
36 ERROR("Could not get ifindex from uevent: %s\n", strerror(-r
));
41 link
= nw_daemon_get_link_by_ifindex(daemon
, ifindex
);
43 DEBUG("Could not fetch link %d, ignoring\n", ifindex
);
48 // Let the link handle its uevent
49 r
= nw_link_handle_uevent(link
, device
, action
);
58 int nw_devmon_handle_uevent(sd_device_monitor
* monitor
, sd_device
* device
, void* data
) {
59 sd_device_action_t action
;
60 const char* subsystem
= NULL
;
64 nw_daemon
* daemon
= (nw_daemon
*)data
;
67 r
= sd_device_get_action(device
, &action
);
69 WARNING("Could not get uevent action, ignoring: %s\n", strerror(-r
));
74 r
= sd_device_get_subsystem(device
, &subsystem
);
76 ERROR("Could not get uevent subsystem, ignoring: %s\n", strerror(-r
));
81 if (strcmp(subsystem
, "net") == 0) {
82 r
= nw_daemon_handle_uevent_net(daemon
, device
, action
);
85 DEBUG("Received an uevent for an unhandled subsystem '%s', ignoring\n", subsystem
);
89 // Log if something went wrong
91 ERROR("Failed processing uevent: %s\n", strerror(-r
));