Page MenuHomeFreeBSD

examples/jails: Encode ifnames used as derive_mac counters
ClosedPublic

Authored by dteske on Thu, Sep 3, 12:05 AM.
Referenced Files
F170714929: D59326.diff
Sun, Sep 6, 4:28 AM
F170645257: D59326.diff
Sat, Sep 5, 7:11 PM
Unknown Object (File)
Fri, Sep 4, 7:42 PM
Unknown Object (File)
Fri, Sep 4, 4:36 PM
Unknown Object (File)
Fri, Sep 4, 3:29 PM
Unknown Object (File)
Fri, Sep 4, 3:19 PM
Unknown Object (File)
Thu, Sep 3, 9:41 PM
Unknown Object (File)
Thu, Sep 3, 12:21 PM
Subscribers

Details

Summary

derive_mac keeps a per-parent branch index in a global named from the
parent interface so the N nibble can increment when the same PHY is
presented more than once. That name must be a POSIX identifier; a
vlan-style parent (em0.20) is not.

Encode the ifname first (alnum unchanged, every other byte as _HH) so
the lookup stays a symbol-table hit and em0.20 does not collide with
em0_20. Same change in jib (9.2) and jng (9.4).

In jng, also address netgraph by node name. ngctl(8) treats `.' and
`:' as control characters, so ng_ether(4) names its node after the
sanitized ifname (vtnet0.20 becomes vtnet0_20). Sanitize the parent
ifname where it enters and use that for every ngctl call; ifconfig(8)
and derive_mac keep the real name. Previously jng failed outright on
such parents where jib did not.

PR: 291143
Reported by: Victor <tschetter.victor@gmail.com>
MFC after: 1 week

Test Plan

if_bridge/epair:

cd /usr/src/share/examples/jails
sudo ifconfig vtnet0.20 create vlan 20 vlandev vtnet0
sudo ./jib addm test vtnet0.20

Netgraph:

cd /usr/src/share/examples/jails
kldstat -q -m ng_ether || sudo kldload ng_ether
sudo ifconfig ue0.20 create vlan 20 vlandev ue0
sudo ./jng bridge test ue0.20        # expect ng0_test, no "send msg: Invalid argument"
sudo ngctl list                      # expect ue0_20 and ue0_20bridge
sudo ./jng shutdown test
sudo ngctl shutdown ue0_20bridge:
sudo ifconfig ue0.20 destroy

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Impeccable!

Briefly tested:

# ifconfig vtnet0.20 create vlan 20 vlandev vtnet0
# sh ./jib addm test vtnet0.20
vtnet0.20bridge
e0a_test
e0b_test

I was not able to test it with jng:

# kldload ng_ether
# ifconfig vtnet0.20 create vlan 20 vlandev vtnet0
# jail -c name=test host.hostname=test.home.arpa vnet persist
# sh ./jng bridge test vtnet0.20
ngctl: send msg: Invalid argument
# ngctl list
There are 3 total nodes:
  Name: vtnet0          Type: ether           ID: 00000001   Num hooks: 0
  Name: vtnet0_20       Type: ether           ID: 00000002   Num hooks: 0
  Name: ngctl3288       Type: socket          ID: 00000005   Num hooks: 0
# sh ./jng bridge test vtnet0 # The parent works as expected
ng0_test

Impeccable!

^_^

Briefly tested:

# ifconfig vtnet0.20 create vlan 20 vlandev vtnet0
# sh ./jib addm test vtnet0.20
vtnet0.20bridge
e0a_test
e0b_test

(thumbs up)

I was not able to test it with jng:

# kldload ng_ether
# ifconfig vtnet0.20 create vlan 20 vlandev vtnet0
# jail -c name=test host.hostname=test.home.arpa vnet persist
# sh ./jng bridge test vtnet0.20
ngctl: send msg: Invalid argument
# ngctl list
There are 3 total nodes:
  Name: vtnet0          Type: ether           ID: 00000001   Num hooks: 0
  Name: vtnet0_20       Type: ether           ID: 00000002   Num hooks: 0
  Name: ngctl3288       Type: socket          ID: 00000005   Num hooks: 0
# sh ./jng bridge test vtnet0 # The parent works as expected
ng0_test

Derp.

The culprit is ng_ether_sanitize_ifname() at:

https://cgit.freebsd.org/src/tree/sys/netgraph/ng_ether.c#n223

I'll fix this up.

dteske edited the test plan for this revision. (Show Details)
dteske added a project: Netgraph.
dteske edited the test plan for this revision. (Show Details)

Fix jng to incorporate kernel ng_ether_sanitize_ifname() logic

This revision is now accepted and ready to land.Thu, Sep 3, 4:01 AM