From a2711065c8cdca4f285319fb3d62db18aa0f0599 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer <mschiffer@universe-factory.net> Date: Wed, 21 Jun 2017 22:11:34 +0200 Subject: [PATCH] gluon-core: add VXLAN support for gluon_wired protocol --- package/gluon-core/Makefile | 4 +- .../files/lib/netifd/proto/gluon_wired.sh | 39 +++++++++++++++++-- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/package/gluon-core/Makefile b/package/gluon-core/Makefile index b4a2692ed..e90002bb3 100644 --- a/package/gluon-core/Makefile +++ b/package/gluon-core/Makefile @@ -15,7 +15,9 @@ define Package/gluon-core SECTION:=gluon CATEGORY:=Gluon TITLE:=Base files of Gluon - DEPENDS:=+gluon-site +libgluonutil +lua-platform-info +lua-simple-uci +lua-hash +luci-lib-jsonc +luci-lib-nixio +odhcp6c +firewall +pretty-hostname + DEPENDS:= \ + +gluon-site +libgluonutil +lua-platform-info +lua-simple-uci +lua-hash +luci-lib-jsonc +luci-lib-nixio \ + +vxlan +odhcp6c +firewall +pretty-hostname endef define Package/gluon-core/description 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 5c179b7ad..9431bbce7 100755 --- a/package/gluon-core/files/lib/netifd/proto/gluon_wired.sh +++ b/package/gluon-core/files/lib/netifd/proto/gluon_wired.sh @@ -6,21 +6,52 @@ init_proto "$@" proto_gluon_wired_init_config() { proto_config_add_boolean transitive + proto_config_add_int index + proto_config_add_boolean legacy +} + +xor2() { + echo -n "${1:0:1}" + echo -n "${1:1:1}" | tr '0123456789abcdef' '23016745ab89efcd' +} + +interface_linklocal() { + local macaddr="$(ubus call network.device status '{"name": "'"$1"'"}' | jsonfilter -e '@.macaddr')" + local oldIFS="$IFS"; IFS=':'; set -- $macaddr; IFS="$oldIFS" + + echo "fe80::$(xor2 "$1")$2:$3ff:fe$4:$5$6" } proto_gluon_wired_setup() { local config="$1" local ifname="$2" - local transitive - json_get_vars transitive + local meshif="$config" + + local transitive index legacy + json_get_vars transitive index legacy proto_init_update "$ifname" 1 proto_send_update "$config" + if [ "${legacy:-0}" -eq 0 ]; then + meshif="vx_$config" + + json_init + json_add_string name "$meshif" + [ -n "$index" ] && json_add_string macaddr "$(lua -lgluon.util -e "print(gluon.util.generate_mac($index))")" + json_add_string proto 'vxlan6' + json_add_string tunlink "$config" + json_add_string ip6addr "$(interface_linklocal "$ifname")" + json_add_string peer6addr 'ff02::15c' + json_add_int vid "$(lua -lgluon.util -e 'print(tonumber(gluon.util.site_seed_bytes("gluon-mesh-vxlan", 3), 16))')" + json_close_object + ubus call network add_dynamic "$(json_dump)" + fi + json_init json_add_string name "${config}_mesh" - json_add_string ifname "@${config}" + json_add_string ifname "@${meshif}" json_add_string proto 'gluon_mesh' json_add_boolean fixed_mtu 1 [ -n "$transitive" ] && json_add_boolean transitive "$transitive" @@ -29,7 +60,7 @@ proto_gluon_wired_setup() { } proto_gluon_wired_teardown() { - export config="$1" + local config="$1" proto_init_update "*" 0 proto_send_update "$config" -- GitLab