diff --git a/test/case/infix_dhcp/all.yaml b/test/case/infix_dhcp/all.yaml index d185d99c..d25ec299 100644 --- a/test/case/infix_dhcp/all.yaml +++ b/test/case/infix_dhcp/all.yaml @@ -1,3 +1,4 @@ --- - case: dhcp_basic.py - case: dhcp_router.py +- case: dhcp_routes.py diff --git a/test/case/infix_dhcp/dhcp_routes.py b/test/case/infix_dhcp/dhcp_routes.py new file mode 100755 index 00000000..78e3094e --- /dev/null +++ b/test/case/infix_dhcp/dhcp_routes.py @@ -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() diff --git a/test/infamy/dhcp.py b/test/infamy/dhcp.py index f47694d8..dc30a1b5 100644 --- a/test/infamy/dhcp.py +++ b/test/infamy/dhcp.py @@ -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