aboutsummaryrefslogtreecommitdiffstats
path: root/package/base-files/files/bin
diff options
context:
space:
mode:
authorJohn Crispin <john@phrozen.org>2020-11-03 17:43:22 +0100
committerJohn Crispin <john@phrozen.org>2020-11-04 07:36:49 +0100
commitbe09c5a3cd6535ccfc6b1628546c0416d94bd131 (patch)
treefa52ddb71dab5721bbc130ebb727f58e0399916c /package/base-files/files/bin
parentdf9ee254aae57752ea23ea17372b08947a01ef71 (diff)
downloadupstream-be09c5a3cd6535ccfc6b1628546c0416d94bd131.tar.gz
upstream-be09c5a3cd6535ccfc6b1628546c0416d94bd131.tar.bz2
upstream-be09c5a3cd6535ccfc6b1628546c0416d94bd131.zip
base-files: add board.d support for bridge device
Latest netifd allows us to setup network bridges with implicit vlan tagging. For this to work, we need to setup several additional uci sections. This feature is particularly usefull for DSA tupe devices. Add board.d and uci-defaults support for generating the sections. Signed-off-by: John Crispin <john@phrozen.org>
Diffstat (limited to 'package/base-files/files/bin')
-rwxr-xr-xpackage/base-files/files/bin/config_generate35
1 files changed, 33 insertions, 2 deletions
diff --git a/package/base-files/files/bin/config_generate b/package/base-files/files/bin/config_generate
index eb6816e519..e23f901504 100755
--- a/package/base-files/files/bin/config_generate
+++ b/package/base-files/files/bin/config_generate
@@ -7,6 +7,28 @@ CFG=/etc/board.json
[ -s $CFG ] || /bin/board_detect || exit 1
[ -s /etc/config/network -a -s /etc/config/system ] && exit 0
+generate_bridge() {
+ local name=$1
+ uci -q batch <<-EOF
+ set network.$name=device
+ set network.$name.name=$name
+ set network.$name.type=bridge
+ EOF
+}
+
+bridge_vlan_id=0
+generate_bridge_vlan() {
+ local device=$1
+ local ports="$2"
+ bridge_vlan_id=$((bridge_vlan_id + 1))
+ uci -q batch <<-EOF
+ add network bridge-vlan
+ set network.@bridge-vlan[-1].device='$device'
+ set network.@bridge-vlan[-1].vlan='$bridge_vlan_id'
+ set network.@bridge-vlan[-1].ports='$ports'
+ EOF
+}
+
generate_static_network() {
uci -q batch <<-EOF
delete network.loopback
@@ -63,6 +85,7 @@ generate_static_network() {
addr_offset=2
generate_network() {
local ifname macaddr protocol type ipaddr netmask
+ local bridge=$2
json_select network
json_select "$1"
@@ -77,6 +100,12 @@ generate_network() {
*\ * | lan:*) type="bridge" ;;
esac
+ [ -n "$bridge" ] && {
+ generate_bridge_vlan $bridge "$ifname"
+ ifname=$bridge.$bridge_vlan_id
+ type=""
+ }
+
uci -q batch <<-EOF
delete network.$1
set network.$1='interface'
@@ -236,7 +265,6 @@ generate_switch() {
json_select ..
}
-
generate_static_system() {
uci -q batch <<-EOF
delete system.@system[0]
@@ -439,8 +467,11 @@ if [ ! -s /etc/config/network ]; then
touch /etc/config/network
generate_static_network
+ json_get_vars bridge
+ [ -n "$bridge" ] && generate_bridge $bridge
+
json_get_keys keys network
- for key in $keys; do generate_network $key; done
+ for key in $keys; do generate_network $key $bridge; done
json_get_keys keys switch
for key in $keys; do generate_switch $key; done