Skip to content

Commit

Permalink
confd: support mixed bridge/router use-case in inteface generator
Browse files Browse the repository at this point in the history
Fix #160

Signed-off-by: Joachim Wiberg <[email protected]>
  • Loading branch information
troglobit committed Oct 17, 2023
1 parent b4d7609 commit cefe24c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/confd/bin/.confdrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ FAILURE_CFG=$CFG_PATH_/failure-config.cfg
STARTUP_CFG=$CFG_PATH_/startup-config.cfg

# Uncomment this line in to create a bridge (br0) with all (classified
# 'gruop port') interfaces as bridge ports. The br0 interface will get
# 'group port') interfaces as bridge ports. The br0 interface will get
# an IPv6 EUI64 SLAAC address as well as an IPv4 ZeroConf address, and a
# DHCPv4 address if the device is attached to a LAN with a DHCP server.
#GEN_IFACE_OPTS="-b -4 -d"
Expand Down
53 changes: 36 additions & 17 deletions src/confd/bin/gen-interfaces
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,36 @@
# -b brN Bridged mode, set all interfaces as ports in brN
# -4 Generic option for both modes, enables ZeroConf IPv4
# -d Generic option for both modes, enables DHCPv4 client
# -g grp Filter interfaces using 'ip link show group grp'
#
# By default this script generates plain interfaces with IPv6 autoconfig
# (EUI64) enabled. Useful both in a plain router and a Fail Secure mode
# where any switchcore-backed ports should be prevented from switching.
#
# The default mode currently does not support the '-4' or '-d' options,
# The default mode currently does not support the '-4' or '-d' options
# for IPv4 ZeroConf or DHCPv4 address, beacause they require source
# routing, or similar, to work. IPv6 does not require that and is
# therefore the recommended access method. A separate (and optional)
# 'gen-cfg-custom' script is checked for in the bootstrap script which
# can be used to enable IPv4 and DHCP on a single service interface if
# needed.
#
# The -b option triggers the bridge mode, creating a 'brN' interface
# using all interfaces classified in 'group port' by the nameif script.
# In the bridge mode port interfaces do not have any IP address, the
# IPv6 autoconfig address is instead set on 'brN'. If the '-4' option
# is set, ZeroConfig (169.254.x.y) is anabled on 'brN'. If the '-d'
# option is set, a DHCPv4 client is enabled on 'brN'.

# The '-b brname' option triggers the bridge mode, creating a 'brname'
# bridge interface using all interfaces classified in 'group port' by
# the nameif script. In the bridge mode port interfaces do not have any
# IP address, the IPv6 autoconfig address is instead set on 'brN'. If
# the '-4' option is set, ZeroConfig (169.254.x.y) is anabled on 'brN'.
# If the '-d' option is set, a DHCPv4 client is enabled on 'brN'.
#
# A "mixed mode" is also supported, where the system may have multiple
# ports in a switchcore, but some Ethernet interfaces directly connected
# to the SoC. In this case, if '-b brname' is given, all 'group port'
# interfaces will be placed in the bridge 'brname' and all other
# interfaces will be brought up and given an IPv6 address (like above).
#
set -e

bridge=
ipv4=false
ipv6=true
dhcp=

gen_interface()
Expand Down Expand Up @@ -66,27 +70,41 @@ while [ "$1" != "" ]; do
-b)
bridge="$2"
shift
ipv6=false # for bridge port interfaces
;;
-d)
dhcp=true
;;
-g)
group="group $2" # -g port => 'ip link show group port'
shift
;;
*)
break
esac
shift
done

phys_ifaces=$(ip -d -j link show $group | jq -r '
phys_ifaces=$(ip -d -j link show | jq -r '
.[] |
select(.link_type == "ether") |
select(.group != "internal") |
select(has("parentbus")) |
.ifname')
ports=$(ip -d -j link show group port | jq -r '
.[] |
select(.link_type == "ether") |
select(.group != "internal") |
select(has("parentbus")) |
.ifname')
ifaces=""
for phy in $phys_ifaces; do
found=""
for port in $ports; do
if [ $port = $phy ]; then
found=true
break
fi
done
if [ -z "$found" ]; then
ifaces="$ifaces $phy"
fi
done

cat <<EOF
{
Expand Down Expand Up @@ -121,7 +139,8 @@ fi

cat <<EOF
}
$(for iface in $phys_ifaces; do gen_interface $iface $ipv6 $bridge; done)
$(for iface in $ifaces; do gen_interface $iface true; done)
$(for iface in $ports; do gen_interface $iface false $bridge; done)
]
EOF
if [ "$dhcp" = "true" ] && [ -n "$bridge" ]; then
Expand Down
4 changes: 2 additions & 2 deletions src/confd/confdrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ FAILURE_CFG=$CFG_PATH_/failure-config.cfg
STARTUP_CFG=$CFG_PATH_/startup-config.cfg

# Uncomment this line in to create a bridge (br0) with all (classified
# 'gruop port') interfaces as bridge ports. The br0 interface will get
# 'group port') interfaces as bridge ports. The br0 interface will get
# an IPv6 EUI64 SLAAC address as well as an IPv4 ZeroConf address, and a
# DHCPv4 address if the device is attached to a LAN with a DHCP server.
#GEN_IFACE_OPTS="-g port -b br0 -4 -d"
#GEN_IFACE_OPTS="-b br0 -4 -d"

# Default hostname in Fail Secure mode, plus last three octets in the base
# MAC address, e.g. "failed-c0-ff-ee".
Expand Down

0 comments on commit cefe24c

Please sign in to comment.