Skip to content

Commit c2acc60

Browse files
authored
Merge pull request #1213 from bluhm/route-locked
Handle OpenBSD routes with locked MTU.
2 parents 71c23da + 438f4ce commit c2acc60

2 files changed

Lines changed: 60 additions & 1 deletion

File tree

scapy/arch/unix.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ def read_routes():
7878
else:
7979
rt = l.split()
8080
dest,gw,flg = rt[:3]
81-
netif = rt[4 + mtu_present + prio_present + refs_present]
81+
locked = OPENBSD and rt[6] == "L"
82+
netif = rt[4 + mtu_present + prio_present + refs_present + locked]
8283
if flg.find("Lc") >= 0:
8384
continue
8485
if dest == "default":

test/regression.uts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6335,6 +6335,64 @@ default link#11 UCSI 1 0 bridge1
63356335
test_osx_netstat_truncated()
63366336

63376337

6338+
= OpenBSD 6.3
6339+
~ mock_read_routes6_bsd
6340+
6341+
import mock
6342+
from io import StringIO
6343+
6344+
@mock.patch("scapy.arch.unix.OPENBSD")
6345+
@mock.patch("scapy.arch.unix.os")
6346+
def test_openbsd_6_3(mock_os, mock_openbsd):
6347+
"""Test read_routes() on OpenBSD 6.3"""
6348+
# 'netstat -rn -f inet' output
6349+
netstat_output = u"""
6350+
Routing tables
6351+
6352+
Internet:
6353+
Destination Gateway Flags Refs Use Mtu Prio Iface
6354+
default 10.0.1.254 UGS 0 0 - 8 bge0
6355+
224/4 127.0.0.1 URS 0 23 32768 8 lo0
6356+
10.0.1/24 10.0.1.26 UCn 4 192 - 4 bge0
6357+
10.0.1.1 00:30:48:57:ed:0b UHLc 2 338 - 3 bge0
6358+
10.0.1.2 00:03:ba:0c:0b:52 UHLc 1 186 - 3 bge0
6359+
10.0.1.26 00:30:48:62:b3:f4 UHLl 0 47877 - 1 bge0
6360+
10.0.1.135 link#1 UHLch 1 194 - 3 bge0
6361+
10.0.1.254 link#1 UHLch 1 190 - 3 bge0
6362+
10.0.1.255 10.0.1.26 UHb 0 0 - 1 bge0
6363+
10.188.6/24 10.188.6.17 Cn 0 0 - 4 tap3
6364+
10.188.6.17 fe:e1:ba:d7:ff:32 UHLl 0 25 - 1 tap3
6365+
10.188.6.255 10.188.6.17 Hb 0 0 - 1 tap3
6366+
10.188.135/24 10.0.1.135 UGS 0 0 1350 L 8 bge0
6367+
127/8 127.0.0.1 UGRS 0 0 32768 8 lo0
6368+
127.0.0.1 127.0.0.1 UHhl 1 3835230 32768 1 lo0
6369+
"""
6370+
# Mocked file descriptor
6371+
strio = StringIO(netstat_output)
6372+
mock_os.popen = mock.MagicMock(return_value=strio)
6373+
6374+
# Mocked OpenBSD parsing behavior
6375+
mock_openbsd = True
6376+
# Test the function
6377+
from scapy.arch.unix import read_routes
6378+
routes = read_routes()
6379+
for r in routes:
6380+
print(ltoa(r[0]), ltoa(r[1]), r)
6381+
# check that default route exists in parsed data structure
6382+
if ltoa(r[0]) == "0.0.0.0":
6383+
default=r
6384+
# check that route with locked mtu exists in parsed data structure
6385+
if ltoa(r[0]) == "10.188.135.0":
6386+
locked=r
6387+
assert(len(routes) == 11)
6388+
assert(default[2] == "10.0.1.254")
6389+
assert(default[3] == "bge0")
6390+
assert(locked[2] == "10.0.1.135")
6391+
assert(locked[3] == "bge0")
6392+
6393+
test_openbsd_6_3()
6394+
6395+
63386396
############
63396397
############
63406398
+ Mocked read_routes6() calls

0 commit comments

Comments
 (0)