test: new test, verify dhcp option 121 is preferred over option 3

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2023-12-14 16:40:41 +01:00
committed by Mattias Walström
parent 6b84bb4b13
commit 95c3e5c67c
3 changed files with 48 additions and 3 deletions
+1
View File
@@ -1,3 +1,4 @@
---
- case: dhcp_basic.py
- case: dhcp_router.py
- case: dhcp_routes.py
+42
View File
@@ -0,0 +1,42 @@
#!/usr/bin/env python3
# Verify DHCP option 121 (staticroutes) is used over option 3
import time
import infamy, infamy.dhcp
import infamy.iface as iface
import infamy.route as route
from infamy.util import until
with infamy.Test() as test:
PREFIX = '10.0.0.0/24'
ROUTER = '192.168.0.254'
with test.step("Initialize"):
env = infamy.Env(infamy.std_topology("1x2"))
target = env.attach("target", "mgmt")
_, host = env.ltop.xlate("host", "data")
with infamy.IsolatedMacVlan(host) as netns:
netns.addip("192.168.0.1")
with infamy.dhcp.Server(netns, prefix=PREFIX, router=ROUTER):
_, port = env.ltop.xlate("target", "data")
config = {
"dhcp-client": {
"client-if": [{
"if-name": f"{port}",
"option": [
{ "name": "router" },
{ "name": "staticroutes" }
]
}]
}
}
target.put_config_dict("infix-dhcp-client", config)
with test.step(f"Verify client sets up correct route via {ROUTER}"):
# Wait for client to set the classless static route, option 121
until(lambda: route.ipv4_route_exist(target, PREFIX, ROUTER))
# Ensure client did *not* use option 3 (option 121 takes precedence)
if route.ipv4_route_exist(target, "0.0.0.0/0", ROUTER):
test.fail()
test.succeed()
+5 -3
View File
@@ -7,10 +7,10 @@ class Server:
config_file = '/tmp/udhcpd.conf'
leases_file = '/tmp/udhcpd.leases'
def __init__(self, netns, start='192.168.0.100', end='192.168.0.110', netmask='255.255.255.0', ip=None, router=None):
def __init__(self, netns, start='192.168.0.100', end='192.168.0.110', netmask='255.255.255.0', ip=None, router=None, prefix=None):
self.process = None
self.netns = netns
self._create_files(start, end, netmask, ip, router)
self._create_files(start, end, netmask, ip, router, prefix)
def __del__(self):
print(self.config_file)
@@ -23,7 +23,7 @@ class Server:
def __exit__(self, _, __, ___):
self.stop()
def _create_files(self, start, end, netmask, ip, router):
def _create_files(self, start, end, netmask, ip, router, prefix):
f = open(self.leases_file, "w")
f.close()
@@ -42,6 +42,8 @@ option lease 864000
''')
if router:
f.write(f"option router {router}\n")
if prefix and router:
f.write(f"option staticroutes {prefix} {router}\n")
def get_pid(self):
return self.process.pid