Skip to content

Commit 0703fb5

Browse files
Defenso-QTHdgeo
andauthored
ioc_start.py: allow setting IP address on lo0 (#48)
* ioc_start.py: allow 'none' bridge in interfaces Iocage currently expects interfaces to be specified in the nic:bridge format, where bridge cannot be none. This results in iocage always creating a bridge to which VNET jail epair interfaces are added as members. In a scenario where the user wants jails to be isolated on the data-link layer (OSI layer 2 / Ethernet) and use the host as a router, this bridge is unnecessery. It can also result in illegitimate cross-jail traffic being allowed, since pf filtering on bridge interfaces is disabled by default on FreeBSD systems (net.link.bridge.pfil_bridge=0). Closes #44 * ioc_start.py: allow setting IP address on lo0 Currently, iocage ignores IP addresses given for the loopback interface lo0 that exists by default in a VNET jail. Adding addresses to that interface can be useful, for instance to implement rfc7404 addressing where link-local addresses are used for interconnections, and routable addresses are set on loopback interfaces. This commit enables setting additional addresses on the lo0 interface using the usual ip4_addr or ip6_addr settings. For instance: ip4_addr='lo0|192.168.2.10' Closes #46 --------- Co-authored-by: dgeo <[email protected]>
1 parent 8f580fa commit 0703fb5

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

iocage_lib/ioc_start.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,7 @@ def start_network_interface_vnet(
11741174

11751175
dhcp = self.get('dhcp')
11761176

1177-
ifaces = []
1177+
ifaces = ['lo0']
11781178

11791179
for addrs, gw, ipv6 in net_configs:
11801180
if (
@@ -1193,7 +1193,7 @@ def start_network_interface_vnet(
11931193
# They didn't supply an interface, assuming default
11941194
iface, ip = "vnet0", addr
11951195

1196-
if iface not in nics:
1196+
if iface not in nics and iface != 'lo0':
11971197
continue
11981198

11991199
if iface not in ifaces:

tests/functional_tests/0004_start_test.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ def test_02_start_rc_jail(invoke_cli, resource_selector):
5757
for jail in resource_selector.rcjails:
5858
assert jail.running is True, f'{jail.name} not running'
5959

60-
# TODO: Let's also start jails in a single command to test that out
60+
# Network-related tests belong here because the code is only executed at jail
61+
# start time.
6162

6263
@require_root
6364
@require_zpool
@@ -109,3 +110,30 @@ def test_03_create_and_start_nobridge_vnet_jail(release, jail, invoke_cli):
109110

110111
finally:
111112
os.remove(path)
113+
114+
115+
# TODO: Let's also start jails in a single command to test that out
116+
117+
@require_root
118+
@require_zpool
119+
def test_04_vnet_jail_with_loopback_alias(release, jail, invoke_cli):
120+
jail = jail('loopback_alias_jail')
121+
122+
invoke_cli([
123+
'create', '-r', release, '-n', jail.name,
124+
'boot=on', 'vnet=on', 'defaultrouter=none',
125+
f'ip4_addr=lo0|192.168.2.10'
126+
])
127+
128+
assert jail.exists is True
129+
assert jail.running is True
130+
131+
stdout, stderr = jail.run_command(['ifconfig', 'lo0'])
132+
assert bool(stderr) is False, f'Ifconfig returned an error: {stderr}'
133+
assert '192.168.2.10' in stdout, (
134+
'Could not set address on loopback interface.'
135+
)
136+
137+
invoke_cli([
138+
'destroy', jail.name, '-f'
139+
])

0 commit comments

Comments
 (0)