Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2025-05-09 21:31:09 +02:00
commit 8fcfefc900
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
3 changed files with 143 additions and 2 deletions

View file

@ -3,6 +3,7 @@
. ./lib/db.sh
. ./lib/colors.sh
. ./lib/vpc.sh
. ./lib/dhcp.sh
function check_subnet_exist {
local vpc_name="${1}"
@ -78,7 +79,11 @@ function create_subnet {
print_in_color "${COLOR_GREEN}" " - add subnet route"
ip -n "${vpc_name}" r add "${subnet}" dev "br-${subnet_id}" scope link
print_in_color "${COLOR_GREEN}" " - add subnet firewall"
ebtables -A FORWARD -p arp --arp-op Request --arp-ip-dst "${gateway_ip}" --out-interface "br-${subnet_id}" -j DROP
ebtables -A FORWARD --out-interface "br-${subnet_id}" -p arp --arp-op Request --arp-ip-dst "${gateway_ip}" -j DROP
ebtables -A FORWARD --out-interface "br-${subnet_id}" -p IPv4 --ip-protocol udp --ip-source-port 67:68 --ip-destination-port 67:68 -j DROP
generate_dhcp_file "${subnet}" "${vpc_name}_br-${subnet_id}"
systemctl start "dnsmasq@${vpc_name}_br-${subnet_id}.service"
}
return 0
@ -98,7 +103,10 @@ function delete_subnet {
delete_in_db "subnet" "${subnet_name}"
ip -n "${vpc_name}" route del "${subnet}" dev "br-${subnet_id}"
ip link del dev "vxlan-${vxlan_id}"
systemctl stop "dnsmasq@${vpc_name_br}-br-${subnet_id}.service"
rm /etc/dnsmasq.d/${vpc_name}_br-${subnet_id}.conf
ebtables -D FORWARD -p arp --arp-op Request --arp-ip-dst "${gateway_ip}" --out-interface "br-${subnet_id}" -j DROP
ebtables -D FORWARD --out-interface "br-${subnet_id}" -p IPv4 --ip-protocol udp --ip-source-port 67:68 --ip-destination-port 67:68 -j DROP
ip link del dev "br-${subnet_id}"
ip -n "${vpc_name}" link del dev "br-${subnet_id}"
ip link del dev "veth-${subnet_id}-ext"