Skip to content

Commit 95c3e5c

Browse files
troglobitmattiaswal
authored andcommitted
test: new test, verify dhcp option 121 is preferred over option 3
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
1 parent 6b84bb4 commit 95c3e5c

3 files changed

Lines changed: 48 additions & 3 deletions

File tree

test/case/infix_dhcp/all.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
---
22
- case: dhcp_basic.py
33
- case: dhcp_router.py
4+
- case: dhcp_routes.py
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env python3
2+
# Verify DHCP option 121 (staticroutes) is used over option 3
3+
4+
import time
5+
import infamy, infamy.dhcp
6+
import infamy.iface as iface
7+
import infamy.route as route
8+
from infamy.util import until
9+
10+
with infamy.Test() as test:
11+
PREFIX = '10.0.0.0/24'
12+
ROUTER = '192.168.0.254'
13+
with test.step("Initialize"):
14+
env = infamy.Env(infamy.std_topology("1x2"))
15+
target = env.attach("target", "mgmt")
16+
_, host = env.ltop.xlate("host", "data")
17+
18+
with infamy.IsolatedMacVlan(host) as netns:
19+
netns.addip("192.168.0.1")
20+
with infamy.dhcp.Server(netns, prefix=PREFIX, router=ROUTER):
21+
_, port = env.ltop.xlate("target", "data")
22+
config = {
23+
"dhcp-client": {
24+
"client-if": [{
25+
"if-name": f"{port}",
26+
"option": [
27+
{ "name": "router" },
28+
{ "name": "staticroutes" }
29+
]
30+
}]
31+
}
32+
}
33+
target.put_config_dict("infix-dhcp-client", config)
34+
35+
with test.step(f"Verify client sets up correct route via {ROUTER}"):
36+
# Wait for client to set the classless static route, option 121
37+
until(lambda: route.ipv4_route_exist(target, PREFIX, ROUTER))
38+
# Ensure client did *not* use option 3 (option 121 takes precedence)
39+
if route.ipv4_route_exist(target, "0.0.0.0/0", ROUTER):
40+
test.fail()
41+
42+
test.succeed()

test/infamy/dhcp.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ class Server:
77
config_file = '/tmp/udhcpd.conf'
88
leases_file = '/tmp/udhcpd.leases'
99

10-
def __init__(self, netns, start='192.168.0.100', end='192.168.0.110', netmask='255.255.255.0', ip=None, router=None):
10+
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):
1111
self.process = None
1212
self.netns = netns
13-
self._create_files(start, end, netmask, ip, router)
13+
self._create_files(start, end, netmask, ip, router, prefix)
1414

1515
def __del__(self):
1616
print(self.config_file)
@@ -23,7 +23,7 @@ def __enter__(self):
2323
def __exit__(self, _, __, ___):
2424
self.stop()
2525

26-
def _create_files(self, start, end, netmask, ip, router):
26+
def _create_files(self, start, end, netmask, ip, router, prefix):
2727
f = open(self.leases_file, "w")
2828
f.close()
2929

@@ -42,6 +42,8 @@ def _create_files(self, start, end, netmask, ip, router):
4242
''')
4343
if router:
4444
f.write(f"option router {router}\n")
45+
if prefix and router:
46+
f.write(f"option staticroutes {prefix} {router}\n")
4547

4648
def get_pid(self):
4749
return self.process.pid

0 commit comments

Comments
 (0)