diff --git a/packages/lime-proto-babeld/files/usr/lib/lua/lime/proto/babeld.lua b/packages/lime-proto-babeld/files/usr/lib/lua/lime/proto/babeld.lua index 1fb4735c0..757b62f18 100644 --- a/packages/lime-proto-babeld/files/usr/lib/lua/lime/proto/babeld.lua +++ b/packages/lime-proto-babeld/files/usr/lib/lua/lime/proto/babeld.lua @@ -87,8 +87,39 @@ function babeld.configure(args) uci:set("babeld", "denyany", "type", "redistribute") uci:set("babeld", "denyany", "action", "deny") + uci:set("babeld", "br_lan_interface", "interface") + uci:set("babeld", "br_lan_interface", "ifname", "br-lan") + uci:set("babeld", "br_lan_interface", "type", "wired") + uci:save("babeld") + if utils.is_installed("kmod-batman-adv") then + local dir = "/usr/share/nftables.d/ruleset-post" + local path = dir .. "/20-lime-babel-filter.nft" + + if not fs.stat(dir) then fs.mkdir(dir) end + + if not fs.stat(path) then + fs.writefile(path, [[ +#!/usr/sbin/nft -f +add table inet lime_babel_filter +add chain inet lime_babel_filter prevent_babel_leak_from_bat0 +delete chain inet lime_babel_filter prevent_babel_leak_from_bat0 + +table inet lime_babel_filter { + chain prevent_babel_leak_from_bat0 { + type filter hook ingress device "bat0" priority 0; policy accept; + + ip6 daddr ff02::1:6 udp dport 6696 counter drop + ip daddr 224.0.0.111 udp dport 6696 counter drop + + ip6 nexthdr udp udp dport 6696 counter drop + ip protocol udp udp dport 6696 counter drop + } +} +]]) + end + end end function babeld.setup_interface(ifname, args) @@ -99,48 +130,26 @@ function babeld.setup_interface(ifname, args) utils.log("lime.proto.babeld.setup_interface(%s, ...)", ifname) - local vlanId = args[2] or 17 - local vlanProto = args[3] or "8021ad" - local nameSuffix = args[4] or "_babeld" - - local owrtInterfaceName, linuxVlanIfName, owrtDeviceName = - network.createVlanIface(ifname, vlanId, nameSuffix, vlanProto) - - local ipv4, _ = network.primary_address() - local uci = config.get_uci_cursor() - if(vlanId ~= 0 and (ifname:match("^eth") or ifname:match("^lan"))) then - uci:set("network", owrtDeviceName, "mtu", tostring(network.MTU_ETH_WITH_VLAN)) - end + local section_name = "babeld_" .. ifname:gsub("[.-]", "_") - uci:set("network", owrtInterfaceName, "proto", "static") - uci:set("network", owrtInterfaceName, "ipaddr", ipv4:host():string()) - uci:set("network", owrtInterfaceName, "netmask", "255.255.255.255") - uci:save("network") + uci:set("babeld", section_name, "interface") + uci:set("babeld", section_name, "ifname", ifname) - uci:set("babeld", owrtInterfaceName, "interface") - uci:set("babeld", owrtInterfaceName, "ifname", linuxVlanIfName) - --! It is quite common to have dummy radio device attached via ethernet so - --! disable wired optimization always as it would consider the link down at - --! first packet lost - uci:set("babeld", owrtInterfaceName, "type", "wireless") + if ifname:match("^wlan") then + uci:set("babeld", section_name, "type", "wireless") + else + uci:set("babeld", section_name, "type", "wired") + end uci:save("babeld") end function babeld.runOnDevice(linuxDev, args) utils.log("lime.proto.babeld.runOnDevice(%s, ...)", linuxDev) - - local vlanId = args[2] or 17 - local vlanProto = args[3] or "8021ad" - - local vlanDev = network.createVlan(linuxDev, vlanId, vlanProto) - network.createStatic(vlanDev) - local libubus = require("ubus") local ubus = libubus.connect() - ubus:call('babeld', 'add_interface', { ifname = vlanDev }) + ubus:call('babeld', 'add_interface', { ifname = linuxDev }) end - return babeld