diff --git a/package/gluon-core/files/lib/netifd/proto/gluon_wired.sh b/package/gluon-core/files/lib/netifd/proto/gluon_wired.sh index 5bc33d22..796ee3e5 100755 --- a/package/gluon-core/files/lib/netifd/proto/gluon_wired.sh +++ b/package/gluon-core/files/lib/netifd/proto/gluon_wired.sh @@ -8,6 +8,7 @@ proto_gluon_wired_init_config() { proto_config_add_boolean transitive proto_config_add_int index proto_config_add_boolean vxlan + proto_config_add_string vxpeer6addr } xor2() { @@ -15,8 +16,24 @@ xor2() { echo -n "${1:1:1}" | tr '0123456789abcdef' '23016745ab89efcd' } +is_layer3_device () { + local addrlen="$(cat "/sys/class/net/$1/addr_len")" + test "$addrlen" -eq 0 +} + # shellcheck disable=SC2086 interface_linklocal() { + if is_layer3_device "$1"; then + if ! ubus call network.interface dump | \ + jsonfilter -e "@.interface[@.l3_device='$1']['ipv6-address'][*].address" | \ + grep -e '^fe[89ab][0-9a-f]' -m 1; then + proto_notify_error "$config" "MISSING_LL_ADDR_ON_LOWER_IFACE" + proto_block_restart "$config" + exit 1 + fi + return + fi + local macaddr="$(ubus call network.device status '{"name": "'"$1"'"}' | jsonfilter -e '@.macaddr')" local oldIFS="$IFS"; IFS=':'; set -- $macaddr; IFS="$oldIFS" @@ -29,11 +46,12 @@ proto_gluon_wired_setup() { local meshif="$config" - local transitive index vxlan - json_get_vars transitive index vxlan + local transitive index vxlan vxpeer6addr + json_get_vars transitive index vxlan vxpeer6addr # default args [ -z "$vxlan" ] && vxlan=1 + [ -z "$vxpeer6addr" ] && vxpeer6addr='ff02::15c' proto_init_update "$ifname" 1 proto_send_update "$config" @@ -46,8 +64,9 @@ proto_gluon_wired_setup() { [ -n "$index" ] && json_add_string macaddr "$(lua -e "print(require('gluon.util').generate_mac($index))")" json_add_string proto 'vxlan6' json_add_string tunlink "$config" + # ip6addr (the lower interface ip6) is used by the vxlan.sh proto json_add_string ip6addr "$(interface_linklocal "$ifname")" - json_add_string peer6addr 'ff02::15c' + json_add_string peer6addr "$vxpeer6addr" json_add_int vid "$(lua -e 'print(tonumber(require("gluon.util").domain_seed_bytes("gluon-mesh-vxlan", 3), 16))')" json_add_boolean rxcsum '0' json_add_boolean txcsum '0'