From 4363971e05e5f10ca7fe592510dd438f9c05563c Mon Sep 17 00:00:00 2001 From: Vincent Li Date: Thu, 27 Jun 2024 16:26:38 +0000 Subject: [PATCH] dhcp: allow user to specify router IP In BPFire HA deployment, a floating/shared router IP is required for backend/endpoint server. by default BPFire uses the primary IP on green0 when running setup script. Now the floating/shared router IP can be added to green0 interface as secondary IP through loxilb UI, keepalived UI can configure the secondary IP as virtual ipaddress, when HA failover happens, keepalived will move the virtual ipaddress to new active BPFire. Signed-off-by: Vincent Li --- html/cgi-bin/dhcp.cgi | 62 ++++++++++++++++++++++++++++++++++++++---- langs/en/cgi-bin/en.pl | 2 ++ 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/html/cgi-bin/dhcp.cgi b/html/cgi-bin/dhcp.cgi index c079fe1ae..96e434716 100644 --- a/html/cgi-bin/dhcp.cgi +++ b/html/cgi-bin/dhcp.cgi @@ -42,11 +42,19 @@ our $filename1 = "${General::swroot}/dhcp/advoptions"; # Field separator is TAB # because we need commas in the some data our $filename2 = "${General::swroot}/dhcp/fixleases"; our $filename3 = "${General::swroot}/dhcp/advoptions-list"; # Describe the allowed syntax for dhcp options +my $loxilbipfile = "${General::swroot}/loxilb/ipconfig"; my $errormessage = ''; my $warnNTPmessage = ''; my @nosaved=(); my %color = (); +our @IPFILE = (); + +if (open(FILE, "$loxilbipfile")) { + @IPFILE = ; + close (FILE); +} + #Basic syntax allowed for new Option definition. Not implemented: RECORDS & array of RECORDS our $OptionTypes = 'boolean|((un)?signed )?integer (8|16|32)|ip-address|text|string|encapsulate \w+|array of ip-address'; @@ -58,6 +66,7 @@ if (&Header::blue_used()){push(@ITFs,'BLUE');} foreach my $itf (@ITFs) { $dhcpsettings{"ENABLE_${itf}"} = 'off'; $dhcpsettings{"ENABLEBOOTP_${itf}"} = 'off'; + $dhcpsettings{"ROUTER_ADDR_${itf}"} = ''; $dhcpsettings{"START_ADDR_${itf}"} = ''; $dhcpsettings{"END_ADDR_${itf}"} = ''; $dhcpsettings{"DOMAIN_NAME_${itf}"} = ''; @@ -144,6 +153,12 @@ if ($dhcpsettings{'ACTION'} eq $Lang::tr{'save'}) { foreach my $itf (@ITFs) { if ($dhcpsettings{"ENABLE_${itf}"} eq 'on' ) { # "Start" is defined, need "End" and vice versa + if ($dhcpsettings{"ROUTER_ADDR_${itf}"}) { + if (!(&General::validip($dhcpsettings{"ROUTER_ADDR_${itf}"}))) { + $errormessage = "DHCP on ${itf}: " . $Lang::tr{'invalid router address'}; + goto ERROR; + } + } if ($dhcpsettings{"START_ADDR_${itf}"}) { if (!(&General::validip($dhcpsettings{"START_ADDR_${itf}"}))) { $errormessage = "DHCP on ${itf}: " . $Lang::tr{'invalid start address'}; @@ -571,14 +586,45 @@ foreach my $itf (@ITFs) { if ($netsettings{"${itf}_DEV"} ne '' ) { # Show only defined interface my $lc_itf=lc($itf); -print < $Lang::tr{"$lc_itf interface"} $Lang::tr{'enabled'} $Lang::tr{'ip address'}
$Lang::tr{'netmask'}:$netsettings{"${itf}_ADDRESS"}
$netsettings{"${itf}_NETMASK"}
- + + + $Lang::tr{'router address'}  + + $Lang::tr{'end address'} * @@ -620,10 +666,9 @@ print <
END -; }# Show only defined interface }#foreach itf -print < * $Lang::tr{'required field'} @@ -632,7 +677,7 @@ print < END -; + &Header::closebox(); # DHCP DNS update support (RFC2136) @@ -1321,7 +1366,12 @@ sub buildconf { } print FILE "\toption subnet-mask " . $netsettings{"${itf}_NETMASK"} . ";\n"; print FILE "\toption domain-name \"" . $dhcpsettings{"DOMAIN_NAME_${itf}"} . "\";\n"; - print FILE "\toption routers " . $netsettings{"${itf}_ADDRESS"} . ";\n"; + if ($dhcpsettings{"ROUTER_ADDR_${itf}"}) { + my @temp = split("\/", $dhcpsettings{"ROUTER_ADDR_${itf}"}); + print FILE "\toption routers " . $temp[0] . ";\n"; + } else { + print FILE "\toption routers " . $netsettings{"${itf}_ADDRESS"} . ";\n"; + } print FILE "\toption domain-name-servers " . $dhcpsettings{"DNS1_${itf}"} if ($dhcpsettings{"DNS1_${itf}"}); print FILE ", " . $dhcpsettings{"DNS2_${itf}"} if ($dhcpsettings{"DNS2_${itf}"}); print FILE ";\n" if ($dhcpsettings{"DNS1_${itf}"}); diff --git a/langs/en/cgi-bin/en.pl b/langs/en/cgi-bin/en.pl index 62882c0b9..7a249f7dd 100644 --- a/langs/en/cgi-bin/en.pl +++ b/langs/en/cgi-bin/en.pl @@ -1596,6 +1596,7 @@ 'invalid secondary dns' => 'Invalid secondary DNS.', 'invalid secondary ntp' => 'Invalid Secondary NTP server address', 'invalid start address' => 'Invalid start address.', +'invalid router address' => 'Invalid router address.', 'invalid time entered' => 'Invalid time entered.', 'invalid time period' => 'Invalid time period', 'invalid uplink speed' => 'Invalid uplink speed.', @@ -2450,6 +2451,7 @@ 'standard login script' => 'Standard login script', 'start' => 'Start', 'start address' => 'Start address:', +'router address' => 'Router address:', 'start ovpn server' => 'Start OpenVPN Server', 'state or province' => 'State or Province', 'static ip' => 'Static IP',