diff --git a/config/cfgroot/ddos-settings b/config/cfgroot/ddos-settings new file mode 100644 index 000000000..3bffabddf --- /dev/null +++ b/config/cfgroot/ddos-settings @@ -0,0 +1 @@ +ENABLE_DDOS=on diff --git a/config/rootfiles/common/configroot b/config/rootfiles/common/configroot index e2352e8a7..33cc508e1 100644 --- a/config/rootfiles/common/configroot +++ b/config/rootfiles/common/configroot @@ -202,3 +202,4 @@ var/ipfire/wireless #var/ipfire/wireless/config #var/ipfire/wireless/settings var/ipfire/xdptailcall +var/ipfire/ddos diff --git a/config/rootfiles/common/loongarch64/initscripts b/config/rootfiles/common/loongarch64/initscripts index 3f3276995..fe3740da8 100644 --- a/config/rootfiles/common/loongarch64/initscripts +++ b/config/rootfiles/common/loongarch64/initscripts @@ -93,6 +93,7 @@ etc/rc.d/init.d/vnstat etc/rc.d/init.d/waitdrives etc/rc.d/init.d/wlanclient etc/rc.d/init.d/xdptailcall +etc/rc.d/init.d/ddos #etc/rc.d/rc0.d etc/rc.d/rc0.d/K01grub-btrfsd #etc/rc.d/rc0.d/K01imspetor @@ -141,6 +142,7 @@ etc/rc.d/rc3.d/S99grub-btrfsd #etc/rc.d/rc3.d/S99motion #etc/rc.d/rc3.d/S99vdradmin etc/rc.d/rc3.d/S102xdptailcall +etc/rc.d/rc3.d/S105ddos #etc/rc.d/rc6.d etc/rc.d/rc6.d/K01grub-btrfsd #etc/rc.d/rc6.d/K01imspetor diff --git a/lfs/configroot b/lfs/configroot index efd5b7b97..92611ce93 100644 --- a/lfs/configroot +++ b/lfs/configroot @@ -56,7 +56,7 @@ $(TARGET) : ovpn patches pakfire portfw ppp private proxy/advanced/cre \ proxy/calamaris/bin qos/bin red remote sensors suricata time \ updatexlrator/bin updatexlrator/autocheck urlfilter/autoupdate urlfilter/bin vpn \ - wakeonlan wireless xdptailcall; do \ + wakeonlan wireless xdptailcall ddos; do \ mkdir -p $(CONFIG_ROOT)/$$i; \ done @@ -70,7 +70,7 @@ $(TARGET) : ovpn/ccd.conf ovpn/ccdroute ovpn/ccdroute2 pakfire/settings portfw/config ppp/settings-1 ppp/settings-2 ppp/settings-3 ppp/settings-4 \ ppp/settings-5 ppp/settings proxy/settings proxy/squid.conf proxy/advanced/settings proxy/advanced/cre/enable remote/settings qos/settings qos/classes qos/subclasses qos/level7config qos/portconfig \ qos/tosconfig suricata/settings vpn/config vpn/settings vpn/ipsec.conf \ - vpn/ipsec.secrets vpn/caconfig wakeonlan/clients.conf wireless/config wireless/settings xdptailcall/settings; do \ + vpn/ipsec.secrets vpn/caconfig wakeonlan/clients.conf wireless/config wireless/settings xdptailcall/settings ddos/settings; do \ touch $(CONFIG_ROOT)/$$i; \ done @@ -112,6 +112,7 @@ $(TARGET) : cp $(DIR_SRC)/config/fwhosts/customservices $(CONFIG_ROOT)/fwhosts/customservices cp $(DIR_SRC)/config/fwhosts/customservices $(CONFIG_ROOT)/fwhosts/customservices.default cp $(DIR_SRC)/config/cfgroot/xdptailcall-settings $(CONFIG_ROOT)/xdptailcall/settings + cp $(DIR_SRC)/config/cfgroot/ddos-settings $(CONFIG_ROOT)/ddos/settings # Oneliner configfiles echo "ENABLED=off" > $(CONFIG_ROOT)/vpn/settings echo "01" > $(CONFIG_ROOT)/certs/serial diff --git a/lfs/initscripts b/lfs/initscripts index 8f64635ad..f3538e17f 100644 --- a/lfs/initscripts +++ b/lfs/initscripts @@ -184,7 +184,7 @@ $(TARGET) : ln -sf ../init.d/xdptailcall /etc/rc.d/rc3.d/S102xdptailcall #ln -sf ../init.d/xdpsni /etc/rc.d/rc3.d/S103xdpsni #ln -sf ../init.d/xdpgeoip /etc/rc.d/rc3.d/S104xdpgeoip - #ln -sf ../init.d/ddos /etc/rc.d/rc3.d/S105ddos + ln -sf ../init.d/ddos /etc/rc.d/rc3.d/S105ddos ln -sf ../../../../../usr/local/bin/qosctrl \ /etc/rc.d/init.d/networking/red.up/24-RS-qos diff --git a/src/initscripts/system/ddos b/src/initscripts/system/ddos new file mode 100755 index 000000000..796961e39 --- /dev/null +++ b/src/initscripts/system/ddos @@ -0,0 +1,77 @@ +#!/bin/sh +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2007-2022 IPFire Team # +# Copyright (C) 2024-2025 BPFire # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +############################################################################### + +. /etc/sysconfig/rc +. $rc_functions + +eval $(/usr/local/bin/readhash /var/ipfire/ddos/settings) + + +load_ddos () { + /usr/sbin/xdp-loader status red0 | grep -w 'xdp_ddos' + if [ $? -ne 0 ]; then + xdp-loader load red0 -P 80 -p /sys/fs/bpf/xdp-ddos -n xdp_ddos /usr/lib/bpf/xdp_ddos.bpf.o + if [ $? -ge 1 ]; then + boot_mesg "Native mode not supported, try SKB" + xdp-loader load red0 -m skb -P 80 -p /sys/fs/bpf/xdp-ddos -n xdp_ddos /usr/lib/bpf/xdp_ddos.bpf.o + fi + + fi +} + +unload_ddos () { + /usr/sbin/xdp-loader status red0 | grep -w 'xdp_ddos' + if [ $? -eq 0 ]; then + prog_id=$(xdp-loader status red0 | grep 'xdp_ddos' | awk '{print $4}') + /usr/sbin/xdp-loader unload -i $prog_id red0 + else + boot_mesg "Error xdp_ddos not loaded!" + fi +} + + +case "$1" in + start) + boot_mesg -n "Starting xdp-ddos..." + if [ "$ENABLE_DDOS" == "on" ]; then + load_ddos + fi + ;; + + stop) + boot_mesg "Stopping xdp-ddos..." + if [ "$ENABLE_DDOS" == "off" ]; then + unload_ddos + fi + ;; + + restart) + $0 stop + sleep 1 + $0 start + ;; + + *) + echo "Usage: $0 {start|stop|restart}" + exit 1 + ;; +esac