Bug 270607 - if_bridge: net.link.bridge.inherit_mac doesn't quite work
Summary: if_bridge: net.link.bridge.inherit_mac doesn't quite work
Status: In Progress
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 13.1-STABLE
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-net (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-04-02 19:39 UTC by Bob Bishop
Modified: 2024-01-10 06:14 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bob Bishop 2023-04-02 19:39:05 UTC
With net.link.bridge.inherit_mac set to 1, when a bridge is created via rc.conf eg:

cloned_interfaces="bridge0"
ifconfig_bridge0="addm igb1 addm igb2 10.0.0.65 netmask 255.255.255.0 "
ifconfig_igb1="up"
ifconfig_igb2="up"

the MAC address of igb1 is not applied to the bridge. Using:

ifconfig bridge0 create addm igb1 addm igb2 10.0.0.65 netmask 255.255.255.0

the MAC address is inherited as expected.
Comment 1 Mina Galić freebsd_triage 2023-04-02 21:11:25 UTC
how are you bringing the bridges up?
does this only fail on boot, or also on service netif restart?
Comment 2 Bob Bishop 2023-04-02 23:16:10 UTC
(In reply to Mina Galić from comment #1)

> how are you bringing the bridges up?

Via rc.conf as above

> does this only fail on boot, or also on service netif restart?

On `service netif restart' it doesn't fail. Weird.
Comment 3 Zhenlei Huang freebsd_committer freebsd_triage 2023-04-03 06:51:03 UTC
(In reply to Bob Bishop from comment #0)
I think that is expected behavior as per if_bridge(4):

> If sysctl(8) node net.link.bridge.inherit_mac has a non-zero value, the
>     **newly** created bridge will inherit the MAC address from its first member
>     instead of choosing a random link-level address. 

You config in rc.conf
> ifconfig_bridge0="addm igb1 addm igb2 10.0.0.65 netmask 255.255.255.0 "
is adding bridge members to an **existing** bridge bridge0.
Comment 4 Zhenlei Huang freebsd_committer freebsd_triage 2023-04-03 08:42:58 UTC
(In reply to Zhenlei Huang from comment #3)
(In reply to Bob Bishop from comment #0)
> I think that is expected behavior as per if_bridge(4):
Sorry I'm wrong.

>> If sysctl(8) node net.link.bridge.inherit_mac has a non-zero value, the
>>     **newly** created bridge will inherit the MAC address from its first member
>>     instead of choosing a random link-level address. 


> You config in rc.conf
>> ifconfig_bridge0="addm igb1 addm igb2 10.0.0.65 netmask 255.255.255.0 "

> is adding bridge members to an **existing** bridge bridge0.
The bridge0 has no members and igb1 is its first member and net.link.bridge.inherit_mac should work.
Comment 5 Zhenlei Huang freebsd_committer freebsd_triage 2023-04-04 16:02:25 UTC
Found an interesting bug while repeating.

`ifconfig bridge0 addm ` was executed twice when `service netif restart`.

After enabled auditd, the audit log shows that devd invoked `hyperv` rules.
Comment 6 Zhenlei Huang freebsd_committer freebsd_triage 2023-04-04 16:03:49 UTC
(In reply to Zhenlei Huang from comment #5)
> After enabled auditd, the audit log shows that devd invoked `hyperv` rules.
And then `hyperv` executed the second `ifconfig bridge0 addm` .
Comment 7 punkt.de Hosting Team 2023-04-04 17:09:01 UTC
The sysctl does not exist if the if_bridge kmod is not loaded. For this mechanism to work as expected at boot time you need to load the module early e.g. by placing

if_bridge_load="YES"

in /boot/loader.conf.

HTH,
Patrick
Comment 8 Mina Galić freebsd_triage 2023-04-04 17:14:35 UTC
could we document that dependency somehow?
Comment 9 punkt.de Hosting Team 2023-04-04 17:34:18 UTC
Just adding some proof:

# freebsd-version
13.1-RELEASE-p7
# kldstat | grep bridge
# sysctl net.link.bridge
sysctl: unknown oid 'net.link.bridge'
# ifconfig bridge0 create
# kldstat | grep bridge
34    1 0xffffffff8301e000     7638 if_bridge.ko
35    1 0xffffffff83026000     50d8 bridgestp.ko
# sysctl net.link.bridge
net.link.bridge.ipfw: 0
net.link.bridge.allow_llz_overlap: 0
net.link.bridge.inherit_mac: 0
net.link.bridge.log_stp: 0
net.link.bridge.pfil_local_phys: 0
net.link.bridge.pfil_member: 1
net.link.bridge.ipfw_arp: 0
net.link.bridge.pfil_bridge: 1
net.link.bridge.pfil_onlyip: 1
#

The behavior which I claimed happens during the boot process follows from that. The interfaces are brought up after /etc/sysctl.conf is applied, so no bridge, hence no kmod, hence no sysctl.

Kind regards,
Patrick
Comment 10 Bob Bishop 2023-04-04 19:06:26 UTC
(In reply to punkt.de Hosting Team from comment #7)
Good catch. I confirm that loading if_bridge early produces the expected behaviour. So this is `just' a documentation problem.

The paragraph in IF_BRIDGE(4) that describes net.link.bridge.inherit_mac needs to say something like: "Note that node net.link.bridge.inherit_mac does not exist until if_bridge is loaded."
Comment 11 Zhenlei Huang freebsd_committer freebsd_triage 2023-04-07 08:52:59 UTC
Given `net.link.bridge.inherit_mac` changes the behavior of clone creating for all bridges, it might be better to have per bridge parameter `inherit_mac`.

See IFCONFIG(8) section lagg.
Comment 12 Zhenlei Huang freebsd_committer freebsd_triage 2023-04-19 02:36:52 UTC
@Bob Bishop 

Once https://reviews.freebsd.org/D39638 is done, you can also add `net.link.bridge.inherit_mac=1` to /boot/loader.conf .

`net.link.bridge.inherit_mac` is actually a loader tunable, but does not work without the fix.
Comment 13 Mark Linimon freebsd_committer freebsd_triage 2024-01-10 06:14:09 UTC
(In reply to Zhenlei Huang from comment #12)
Note that that DR was committed Sep 9 2023.