aboutsummaryrefslogtreecommitdiffstats
path: root/package/base-files
diff options
context:
space:
mode:
authorJohn Crispin <john@phrozen.org>2020-11-28 11:43:47 +0100
committerJohn Crispin <john@phrozen.org>2020-12-02 07:51:36 +0100
commit9290539ca9c7b296891b1b386052c0fe308e9a62 (patch)
tree747e104534af271aaa9eae1d934f820b012f2852 /package/base-files
parentf3926d233dba451831f4dd587fb3d01cc126df5b (diff)
downloadupstream-9290539ca9c7b296891b1b386052c0fe308e9a62.tar.gz
upstream-9290539ca9c7b296891b1b386052c0fe308e9a62.tar.bz2
upstream-9290539ca9c7b296891b1b386052c0fe308e9a62.zip
base-files: allow setting device and bridge macs
Add code for setting mac addresses inside board.json and rendering them out to uci. On switches we want to have a unique MAC on each port. With 48 port switches that would require 48 device sections in /etc/config/network. Doing so via board.json is easier. Signed-off-by: John Crispin <john@phrozen.org>
Diffstat (limited to 'package/base-files')
-rwxr-xr-xpackage/base-files/files/bin/config_generate33
-rwxr-xr-xpackage/base-files/files/lib/functions/uci-defaults.sh18
2 files changed, 42 insertions, 9 deletions
diff --git a/package/base-files/files/bin/config_generate b/package/base-files/files/bin/config_generate
index 79386d41b5..ee3958e733 100755
--- a/package/base-files/files/bin/config_generate
+++ b/package/base-files/files/bin/config_generate
@@ -9,11 +9,17 @@ CFG=/etc/board.json
generate_bridge() {
local name=$1
+ local macaddr=$2
uci -q batch <<-EOF
set network.$name=device
set network.$name.name=$name
set network.$name.type=bridge
EOF
+ if [ -n "$macaddr" ]; then
+ uci -q batch <<-EOF
+ set network.$name.macaddr=$macaddr
+ EOF
+ fi
}
bridge_vlan_id=0
@@ -21,11 +27,11 @@ generate_bridge_vlan() {
local name=$1_vlan
local device=$2
local ports="$3"
- bridge_vlan_id=$((bridge_vlan_id + 1))
+ local vlan="$4"
uci -q batch <<-EOF
set network.$name=bridge-vlan
set network.$name.device='$device'
- set network.$name.vlan='$bridge_vlan_id'
+ set network.$name.vlan='$vlan'
set network.$name.ports='$ports'
EOF
}
@@ -85,12 +91,12 @@ generate_static_network() {
addr_offset=2
generate_network() {
- local ifname macaddr protocol type ipaddr netmask
+ local ifname macaddr protocol type ipaddr netmask vlan
local bridge=$2
json_select network
json_select "$1"
- json_get_vars ifname macaddr protocol ipaddr netmask
+ json_get_vars ifname macaddr protocol ipaddr netmask vlan
json_select ..
json_select ..
@@ -102,8 +108,12 @@ generate_network() {
esac
[ -n "$bridge" ] && {
- generate_bridge_vlan $1 $bridge "$ifname"
- ifname=$bridge.$bridge_vlan_id
+ if [ -z "$vlan" ]; then
+ bridge_vlan_id=$((bridge_vlan_id + 1))
+ vlan=$bridge_vlan_id
+ fi
+ generate_bridge_vlan $1 $bridge "$ifname" $vlan
+ ifname=$bridge.$vlan
type=""
}
@@ -465,14 +475,21 @@ json_load "$(cat ${CFG})"
umask 077
if [ ! -s /etc/config/network ]; then
+ bridge_name=""
touch /etc/config/network
generate_static_network
json_get_vars bridge
- [ -n "$bridge" ] && generate_bridge $bridge
+ [ -n "$bridge" ] && {
+ json_select bridge
+ json_get_vars name macaddr
+ generate_bridge "$name" "$macaddr"
+ json_select ..
+ bridge_name=$name
+ }
json_get_keys keys network
- for key in $keys; do generate_network $key $bridge; done
+ for key in $keys; do generate_network $key $bridge_name; done
json_get_keys keys switch
for key in $keys; do generate_switch $key; done
diff --git a/package/base-files/files/lib/functions/uci-defaults.sh b/package/base-files/files/lib/functions/uci-defaults.sh
index 39bbeda24c..2f50cd6bfd 100755
--- a/package/base-files/files/lib/functions/uci-defaults.sh
+++ b/package/base-files/files/lib/functions/uci-defaults.sh
@@ -91,7 +91,23 @@ ucidef_set_interfaces_lan_wan() {
}
ucidef_set_bridge_device() {
- json_add_string bridge "${1:switch0}"
+ json_select_object bridge
+ json_add_string name "${1:switch0}"
+ json_select ..
+}
+
+ucidef_set_bridge_mac() {
+ json_select_object bridge
+ json_add_string macaddr "${1}"
+ json_select ..
+}
+
+ucidef_set_network_device_mac() {
+ json_select_object "network-device"
+ json_select_object "${1}"
+ json_add_string macaddr "${2}"
+ json_select ..
+ json_select ..
}
_ucidef_add_switch_port() {