summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsarthurdev <965089+sarthurdev@users.noreply.github.com>2023-12-17 01:25:22 +0100
committersarthurdev <965089+sarthurdev@users.noreply.github.com>2023-12-17 01:39:26 +0100
commit8e0a54676ff2ac90b7c24e4f05b05bcebc584bd3 (patch)
treecded61e59bb7a936d299ab3a8518ca80577a77d8
parent03202504d559417266e437bbf53eb26ade187c07 (diff)
downloadvyos-1x-8e0a54676ff2ac90b7c24e4f05b05bcebc584bd3.tar.gz
vyos-1x-8e0a54676ff2ac90b7c24e4f05b05bcebc584bd3.zip
dhcp: T3316: Kea DHCP and DHCPv6 fixes
* Move Kea socket permission change on-demand and speed up conf scripts * Fix issue with DHCP reservations when no `ip-address` value
-rw-r--r--python/vyos/kea.py17
-rw-r--r--python/vyos/utils/file.py4
-rwxr-xr-xsrc/conf_mode/dhcp_server.py11
-rwxr-xr-xsrc/conf_mode/dhcpv6_server.py11
4 files changed, 17 insertions, 26 deletions
diff --git a/python/vyos/kea.py b/python/vyos/kea.py
index cb341e0f2..4a517da5f 100644
--- a/python/vyos/kea.py
+++ b/python/vyos/kea.py
@@ -23,7 +23,9 @@ from vyos.template import is_ipv6
from vyos.template import isc_static_route
from vyos.template import netmask_from_cidr
from vyos.utils.dict import dict_search_args
+from vyos.utils.file import file_permissions
from vyos.utils.file import read_file
+from vyos.utils.process import cmd
kea4_options = {
'name_server': 'domain-name-servers',
@@ -119,10 +121,14 @@ def kea_parse_subnet(subnet, config):
if 'disable' in host_config:
continue
- reservations.append({
- 'hw-address': host_config['mac_address'],
- 'ip-address': host_config['ip_address']
- })
+ obj = {
+ 'hw-address': host_config['mac_address']
+ }
+
+ if 'ip_address' in host_config:
+ obj['ip-address'] = host_config['ip_address']
+
+ reservations.append(obj)
out['reservations'] = reservations
unifi_controller = dict_search_args(config, 'vendor_option', 'ubiquiti', 'unifi_controller')
@@ -275,6 +281,9 @@ def _ctrl_socket_command(path, command, args=None):
if not os.path.exists(path):
return None
+ if file_permissions(path) != '0775':
+ cmd(f'sudo chmod 775 {path}')
+
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock:
sock.connect(path)
diff --git a/python/vyos/utils/file.py b/python/vyos/utils/file.py
index 2af87a0ca..70ac1753b 100644
--- a/python/vyos/utils/file.py
+++ b/python/vyos/utils/file.py
@@ -149,6 +149,10 @@ def chmod_775(path):
S_IROTH | S_IXOTH
chmod(path, bitmask)
+def file_permissions(path):
+ """ Return file permissions in string format, e.g '0755' """
+ return oct(os.stat(path).st_mode)[4:]
+
def makedir(path, user=None, group=None):
if os.path.exists(path):
return
diff --git a/src/conf_mode/dhcp_server.py b/src/conf_mode/dhcp_server.py
index 66f7c8057..958e90014 100755
--- a/src/conf_mode/dhcp_server.py
+++ b/src/conf_mode/dhcp_server.py
@@ -21,7 +21,6 @@ from ipaddress import ip_network
from netaddr import IPAddress
from netaddr import IPRange
from sys import exit
-from time import sleep
from vyos.config import Config
from vyos.pki import wrap_certificate
@@ -29,7 +28,6 @@ from vyos.pki import wrap_private_key
from vyos.template import render
from vyos.utils.dict import dict_search
from vyos.utils.dict import dict_search_args
-from vyos.utils.file import chmod_775
from vyos.utils.file import write_file
from vyos.utils.process import call
from vyos.utils.process import run
@@ -362,15 +360,6 @@ def apply(dhcp):
call(f'systemctl {action} {service}.service')
- # op-mode needs ctrl socket permission change
- i = 0
- while not os.path.exists(ctrl_socket):
- if i > 15:
- break
- i += 1
- sleep(1)
- chmod_775(ctrl_socket)
-
return None
if __name__ == '__main__':
diff --git a/src/conf_mode/dhcpv6_server.py b/src/conf_mode/dhcpv6_server.py
index 73a708ff5..b01f510e5 100755
--- a/src/conf_mode/dhcpv6_server.py
+++ b/src/conf_mode/dhcpv6_server.py
@@ -19,13 +19,11 @@ import os
from ipaddress import ip_address
from ipaddress import ip_network
from sys import exit
-from time import sleep
from vyos.config import Config
from vyos.template import render
from vyos.template import is_ipv6
from vyos.utils.process import call
-from vyos.utils.file import chmod_775
from vyos.utils.file import write_file
from vyos.utils.dict import dict_search
from vyos.utils.network import is_subnet_connected
@@ -197,15 +195,6 @@ def apply(dhcpv6):
call(f'systemctl restart {service_name}')
- # op-mode needs ctrl socket permission change
- i = 0
- while not os.path.exists(ctrl_socket):
- if i > 15:
- break
- i += 1
- sleep(1)
- chmod_775(ctrl_socket)
-
return None
if __name__ == '__main__':