Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/lime-proto-babeld/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ define Package/$(PKG_NAME)
SECTION:=lime
CATEGORY:=LibreMesh
TITLE:=LiMe babeld proto support
DEPENDS:=+babeld +lime-system +luci-lib-nixio
DEPENDS:=+babeld +lime-system +luci-lib-nixio
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a leftover whitespace here

MAINTAINER:=Gioacchino Mazzurco <gio@eigenlab.org>
VERSION:=$(if $(PKG_VERSION),$(PKG_VERSION),$(PKG_SRC_VERSION))
PKGARCH:=all
Expand Down
71 changes: 40 additions & 31 deletions packages/lime-proto-babeld/files/usr/lib/lua/lime/proto/babeld.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Loading