From c14b4c0b4be7ec265b54be6e881e9a7e11ac628a Mon Sep 17 00:00:00 2001 From: lemoer Date: Thu, 18 Mar 2021 23:12:55 +0100 Subject: [PATCH 1/2] gluon-core: add vxlan option to gluon_wired proto Before this commit the decision whether a vxlan layer will be introduced between the lower interface before the interface is added to batman was inside the proto. Now the decision is moved to the user of the proto. --- .../gluon-core/files/lib/netifd/proto/gluon_wired.sh | 10 ++++++---- .../luasrc/lib/gluon/upgrade/210-interface-wan | 1 + .../luasrc/lib/gluon/upgrade/220-interface-lan | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) 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 708e9743..5bc33d22 100755 --- a/package/gluon-core/files/lib/netifd/proto/gluon_wired.sh +++ b/package/gluon-core/files/lib/netifd/proto/gluon_wired.sh @@ -7,6 +7,7 @@ init_proto "$@" proto_gluon_wired_init_config() { proto_config_add_boolean transitive proto_config_add_int index + proto_config_add_boolean vxlan } xor2() { @@ -28,15 +29,16 @@ proto_gluon_wired_setup() { local meshif="$config" - local vxlan="$(lua -e 'print(require("gluon.site").mesh.vxlan(true))')" + local transitive index vxlan + json_get_vars transitive index vxlan - local transitive index - json_get_vars transitive index + # default args + [ -z "$vxlan" ] && vxlan=1 proto_init_update "$ifname" 1 proto_send_update "$config" - if [ "$vxlan" = 'true' ]; then + if [ "$vxlan" -eq 1 ]; then meshif="vx_$config" json_init diff --git a/package/gluon-core/luasrc/lib/gluon/upgrade/210-interface-wan b/package/gluon-core/luasrc/lib/gluon/upgrade/210-interface-wan index 070b264d..051b213e 100755 --- a/package/gluon-core/luasrc/lib/gluon/upgrade/210-interface-wan +++ b/package/gluon-core/luasrc/lib/gluon/upgrade/210-interface-wan @@ -7,6 +7,7 @@ uci:section('network', 'interface', 'mesh_wan', { ifname = 'br-wan', proto = 'gluon_wired', index = 0, + vxlan = site.mesh.vxlan(true), }) local enable = site.mesh_on_wan(false) diff --git a/package/gluon-core/luasrc/lib/gluon/upgrade/220-interface-lan b/package/gluon-core/luasrc/lib/gluon/upgrade/220-interface-lan index e80cbf9f..19ccfb49 100755 --- a/package/gluon-core/luasrc/lib/gluon/upgrade/220-interface-lan +++ b/package/gluon-core/luasrc/lib/gluon/upgrade/220-interface-lan @@ -15,6 +15,7 @@ uci:section('network', 'interface', 'mesh_lan', { igmp_snooping = false, proto = 'gluon_wired', index = 4, + vxlan = site.mesh.vxlan(true), }) if sysconfig.lan_ifname:match(' ') then From bbecd44be13e3b5a55c0e67e3b1b51f434c2db0d Mon Sep 17 00:00:00 2001 From: lemoer Date: Thu, 18 Mar 2021 23:16:24 +0100 Subject: [PATCH 2/2] gluon-core: extend gluon_wired proto for l3 devices This is a preparation to use the gluon_wired.sh proto on top of layer 3 tunnel interfaces. --- .../files/lib/netifd/proto/gluon_wired.sh | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) 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'