router's rc.conf to set up a bridge device with vlan interfaces

I am transitioning my home lab's network to use VLANs. I have one dedicated machine with FreeBSD 15.1 which shall serve as a router on a stick and do the inter-vlan routing. It shall use the new vlan-filtering bridge as described in here. It shall access the internet through my other router 192.168.50.1.

So I put this into its rc.conf:
Code:
local_unbound_enable="YES"
cloned_interfaces="bridge0 bridge0.20 bridge0.30 bridge0.40 bridge0.50"
ifconfig_bridge0="create vlanfilter"
ifconfig_bridge0_addm_re0="tagged 20,30,40,50"
ifconfig_bridge0_20="inet 192.168.20.10/24 up"
ifconfig_bridge0_30="inet 192.168.30.1/24 up"
ifconfig_bridge0_40="inet 192.168.40.1/24 up"
ifconfig_bridge0_50="inet 192.168.50.10/24 up"
defaultrouter="192.168.50.1"
gateway_enable="YES"

Yet when the machine boots, I am getting these error messages:

Code:
route message indicates error: File exists
add host 127.0.0.1: gateway lo0 fib 0: route already in table
route message indicates error: Invalid argument
add net default: gateway 192.168.50.1 fib 0: Invalid argument
Additional inet routing options: gateway="YES"
route message indicates error: File exists
add host ::1: gateway lo0 fib 0: route already in table
...
Starting local unbound.
Waiting for nameserver to start... good

And when I log in to check ifconfig, I see no bridge0 device. Only the re0 and lo0 interfaces are present, re0 has no assigned IPv4 address (this is expected because I want the IPv4s to be assigned statically on the bridge0.20, bridge0.30, bridge0.40, bridge0.50 as I defined in the rc.conf).

When I then try to set the things up manually in the console, I can do the following:

Code:
ifconfig bridge0 create vlanfilter
ifconfig bridge0 addm re0 tagged 20,30,40,50
ifconfig bridge0.20 inet 192.168.20.10/24 up
ifconfig bridge0.30 inet 192.168.30.1/24 up
ifconfig bridge0.40 inet 192.168.40.1/24 up
ifconfig bridge0.50 inet 192.168.50.10/24 up

route add default 192.168.50.1

which works, the last route add default then says: `add net default: gateway 192.168.50.1 fib 0: route already in table.

`netstat -4rn` then shows:

Code:
Routing tables

Internet:
Destination      Gateway       Flags  Netif       Expire
deault           192.168.50.1  UGS    bridge0.50
127.0.0.1        link#2        UH     lo0
192.168.20.0/24  link#4        U      bridge0.20
192.168.20.10    link#2        UHS    lo0
192.168.30.0/24  link#5        U      bridge0.30
192.168.30.1     link#2        UHS    lo0
192.168.40.0/24  link#6        U      bridge0.40
192.168.40.1     link#2        UHS    lo0
192.168.50.0/24  link#7        U      bridge0.50
192.168.50.10    link#2        UHS    lo0

there is some minor residual problems with this, as this does not yet give me the connectivity I need to reach internet or the other machines in the home lab, but I will deal with that later. Currently I don't understand why this bridge device and these static adresses on its member interfaces cannot be created during boot according to my rc.conf
 
Try:
Code:
cloned_interfaces="bridge0"
ifconfig_bridge0="vlanfilter addm re0 tagged 20,30,40,50"
ifconfig_bridge0_20="inet 192.168.20.10/24 up"
ifconfig_bridge0_30="inet 192.168.30.1/24 up"
ifconfig_bridge0_40="inet 192.168.40.1/24 up"
ifconfig_bridge0_50="inet 192.168.50.10/24 up"
defaultrouter="192.168.50.1"
gateway_enable="YES"

I'm unsure about "ifconfig_bridge0_XX=", but what you did about bridge0 in rc.conf cannot work.
 
Code:
ifconfig_bridge0="create vlanfilter"
I don't know a lot about VLAN but I am pretty sure this doesn't play nice with /etc/rc.conf
Without talking about how 15.0-RELEASE handles VLAN bridging, there are examples in the man rc.conf() how to put VLAN variables (or any type of variables) in /etc/rc.conf, search for "vlans_" there is an entire paragraph, this should help to make sure that your variables are written correctly.

That blog post should be usefull, lot of information and examples too.
 
That definitely got me a bit further. Indeed, my syntax was not correct. The first two lines of what Emrion suggested work well and create a bridge0 device after boot. However, rc somehow cannot interpret the lines with "ifconfig_bridge0_XX", so these vlan interfaces don't get created on the bridge and no IP is assigned anywhere.

Grok AI suggests to create a workaround here with a rc.d script like this:

Code:
#!/bin/sh

# PROVIDE: bridge_setup
# REQUIRE: netif
# BEFORE: routing

. /etc/rc.subr

name="bridge_setup"
rcvar="bridge_setup_enable"

start_cmd="bridge_setup_start"
stop_cmd="bridge_setup_stop"

bridge_setup_start()
{
    echo "Creating vlanfilter bridge and interfaces..."

    ifconfig bridge0 create vlanfilter 2>/dev/null || true
    ifconfig bridge0 addm re0 tagged 20,30,40,50

    ifconfig bridge0.20 inet 192.168.20.10/24 up 2>/dev/null || true
    ifconfig bridge0.30 inet 192.168.30.1/24 up 2>/dev/null || true
    ifconfig bridge0.40 inet 192.168.40.1/24 up 2>/dev/null || true
    ifconfig bridge0.50 inet 192.168.50.10/24 up 2>/dev/null || true

    route add default 192.168.50.1 2>/dev/null || true
}

bridge_setup_stop()
{
    ifconfig bridge0 destroy 2>/dev/null || true
}

load_rc_config $name
run_rc_command "$1"

and to enable this script in rc.conf with `bridge_setup_enable="YES"`.

It really seems that there is currently no clear way to write in rc.conf what I would do manually or with this bridge setup script.
 
Allright, but then what must I write into the rc.conf to get a bridge0 device with the interfaces already configured right after boot? Currently, a slightly modified Grok's workaround script is the only thing that works for me.

This works, all the interfaces on the bridge are created and assigned the desired IPs during boot:

/etc/rc.conf
Code:
cloned_interfaces="bridge0"
bridge_setup_enable="YES"
defaultrouter="192.168.50.1"
gateway_enable="YES"

/usr/local/etc/rc.d/bridge_setup.sh
Code:
#!/bin/sh

# PROVIDE: bridge_setup
# REQUIRE: netif
# BEFORE: routing

. /etc/rc.subr

name="bridge_setup"
rcvar="bridge_setup_enable"

start_cmd="bridge_setup_start"
stop_cmd="bridge_setup_stop"

bridge_setup_start() {
    echo "Creating vlanfilter bridge and interfaces ..."

    ifconfig bridge0 create vlanfilter addm re0 tagged 20,30,40,50 up 2>&1 || true

    ifconfig bridge0.20 create inet 192.168.20.10/24 up 2>&1 || true
    ifconfig bridge0.30 create inet 192.168.30.1/24 up 2>&1 || true
    ifconfig bridge0.40 create inet 192.168.40.1/24 up 2>&1 || true
    ifconfig bridge0.50 create inet 192.168.50.10/24 up 2>&1 || true
}

bridge_setup_stop() {
    ifconfig bridge0 destroy 2>&1 || true
}

load_rc_config $name
run_rc_command $1

But this does not work (only the bridge0 device is created during boot, it gets the re0 member but it gets no interfaces, no IPs):

/etc/rc.conf
Code:
cloned_interfaces="bridge0"
ifconfig_bridge0="create vlanfilter addm re0 tagged 20,30,40,50 up"
ifconfig_bridge0_20="create inet 192.168.20.10/24 up"
ifconfig_bridge0_30="create inet 192.168.30.1/24 up"
ifconfig_bridge0_40="create inet 192.168.40.1/24 up"
ifconfig_bridge0_50="create inet 192.168.50.10/24 up"
defaultrouter="192.168.50.1"
gateway_enable="YES"
 
I have the following config for vlan bridges which is working for me on all recent FreeBSD versions.

Code:
cloned_interfaces="bridge0 bridge1 bridge2"
vlans_igb0="10 20 30"

ifconfig_igb0_10="up"
ifconfig_igb0_20="up"
ifconfig_igb0_30="up"


ifconfig_bridge0_name="mgmt"
ifconfig_mgmt="inet 192.168.0.42/24 addm igb0.10"

ifconfig_bridge1_name="core1"
ifconfig_core1="addm igb0.20"

ifconfig_bridge2_name="core2"
ifconfig_core2="addm igb0.30"

This is creating 3 bridges, 3 vlan interfaces on igb0, renaming the bridges as I use them for bhyve switches, then configuring the bridges with one of the vlan interfaces as a member. I suspect the vlanfilter and tagged options should be able to be specified on those last ifconfig_bridgename lines.
 
Back
Top