Files
webmin/net/delete_bifcs.cgi
Ilia Ross 7ebe3f7dfa Add dhcpcd network backend for Debian and Raspberry Pi OS
This PR adds dhcpcd backend support for Debian and Raspberry Pi OS network configuration. It detects dhcpcd only as a final fallback after Netplan, NetworkManager, and ifupdown, preventing Webmin from incorrectly falling back to `/etc/network/interfaces` on dhcpcd-managed systems.

The new backend reads and writes `/etc/dhcpcd.conf`, including DHCP and static IPv4/IPv6 configuration, gateways, static routes, DNS servers, search domains, MTU, and virtual IPv4 aliases. It also supports implicit DHCP-managed interfaces for default dhcpcd setups with no explicit interface blocks, and handles `allowinterfaces` / `denyinterfaces` behavior.

This PR also fixes apply/delete flows for dhcpcd-managed interfaces and virtual aliases, avoids rewriting generated `/etc/resolv.conf`, preserves spacing/comments in touched hosts and nsswitch files, and tightens Active Now handling so virtual aliases are treated as IP addresses rather than independent links.

https://github.com/webmin/webmin/issues/1607
2026-06-20 01:57:50 +02:00

72 lines
2.1 KiB
Perl
Executable File

#!/usr/local/bin/perl
# Delete some boot-time interfaces, and perhaps de-activate them too
require './net-lib.pl';
&ReadParse();
&error_setup($in{'apply'} ? $text{'dbifcs_err2'} : $text{'dbifcs_err'});
@d = split(/\0/, $in{'b'});
@d || &error($text{'daifcs_enone'});
# Do the deletes
@boot = &boot_interfaces();
@active = &active_interfaces();
foreach $d (reverse(@d)) {
($b) = grep { $_->{'fullname'} eq $d } @boot;
$b || &error($text{'daifcs_egone'});
&can_iface($b) || &error($text{'ifcs_ecannot_this'});
$act = undef;
if ($in{'deleteapply'}) {
($act) = grep { $_->{'fullname'} eq $b->{'fullname'} } @active;
if (!$act && $b->{'virtual'} ne '' && $b->{'address'}) {
# ip(8) may renumber unlabelled secondary addresses.
($act) = grep { $_->{'virtual'} ne '' &&
$_->{'name'} eq $b->{'name'} &&
$_->{'address'} eq $b->{'address'} } @active;
}
}
if ($in{'apply'}) {
# Make this interface active
if (defined(&apply_interface)) {
$err = &apply_interface($b);
$err && &error("<pre>$err</pre>");
}
else {
&activate_interface($b);
}
}
else {
# Deleting
if ($in{'deleteapply'} && $act &&
!defined(&unapply_interface_after_delete)) {
# De-activate first for legacy immediate-action backends.
if (defined(&unapply_interface)) {
$err = &unapply_interface($act);
$err && &error("<pre>$err</pre>");
}
else {
&deactivate_interface($act);
if(&iface_type($b->{'name'}) eq 'Bonded'){
if (($gconfig{'os_type'} eq 'debian-linux') && ($gconfig{'os_version'} >= 5)) {}
else {&unload_module($b->{'name'});}
}
}
}
# Delete config
&delete_interface($b);
if(&iface_type($b->{'name'}) eq 'Bonded' &&
defined(&delete_module_def)){
&delete_module_def($b->{'name'});
}
if ($in{'deleteapply'} && $act &&
defined(&unapply_interface_after_delete)) {
# Config-driven backends apply removals after deleting config.
$err = &unapply_interface_after_delete($act, $b);
$err && &error("<pre>$err</pre>");
}
}
}
&webmin_log($in{'apply'} ? "apply" : "delete", "bifcs", scalar(@d));
&redirect("list_ifcs.cgi?mode=boot");