iproute2mac
iproute2mac copied to clipboard
VLAN support
It is desirable to manage VLANs as Linux does:
$ sudo ip link add link eth0 name eth0.111 type vlan id 111
$ sudo ip addr add 192.168.111.1/24 brd + dev eth0.111
$ sudo ip link set up dev eth0.111
$ ip addr show dev eth0.111
7: eth0.111@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether da:8d:21:53:7a:b5 brd ff:ff:ff:ff:ff:ff
inet 192.168.111.1/24 brd 192.168.111.255 scope global eth0.111
valid_lft forever preferred_lft forever
To show VLAN id in the output of ip command -details option is needed:
$ ip -details addr show dev eth0.111 7: eth0.111@eth0:mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether da:8d:21:53:7a:b5 brd ff:ff:ff:ff:ff:ff promiscuity 0 allmulti 0 minmtu 0 maxmtu 65535 vlan protocol 802.1Q id 111 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 tso_max_size 65536 tso_max_segs 65535 gro_max_size 65536 inet 192.168.111.1/24 brd 192.168.111.255 scope global eth0.111 valid_lft forever preferred_lft forever
In macOS could be translated into:
$ sudo ifconfig vlan111 create
$ sudo ifconfig vlan111 vlan 111 vlandev en0
$ sudo ifconfig vlan111 add 192.168.111.2/24
$ ifconfig vlan111
vlan111: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=3<RXCSUM,TXCSUM>
ether 14:98:77:71:03:99
inet 192.168.111.2 netmask 0xffffff00 broadcast 192.168.111.255
vlan: 111 parent interface: en0
media: 100baseTX <full-duplex>
status: active
To remove the interface link (ip link del eth0.111 in Linux) it is possible to use ifconfig vlan111 destroy.
There are some difference between macOS and Linux for VLAN interfaces:
- in macOS the link is already UP (active) after the
ifconfig <interface> vlan <tag> vlandev <iface>command; - it is impossible to set the link DOWN (inactive),
ifconfig <interface> downhas no effect; - in macOS interfaces cannot have a dotted notation as in Linux (e.g. en0.111):
$ sudo ifconfig en0.111 create
ifconfig: SIOCIFCREATE2: Invalid argument
Thanks for documenting the behavior and working on it!