Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Babeld without VLAN on ethernet interfaces inside br-lan #600

Closed
wants to merge 9 commits into from
1 change: 1 addition & 0 deletions packages/lime-docs/files/lime-example
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ config lime network
option bmx7_over_batman false
option bmx7_pref_gw none # Force bmx7 to use a specific gateway to Internet (hostname must be used as identifier)
option bmx7_wifi_rate_max 'auto'
option babeld_over_batman false # When Babeld is run without VLAN (babeld:0), it runs on the bridge which includes Batman-adv's bat0, keeping this false avoids to have Babeld metrics distorted by Batman-adv
Copy link
Contributor

Choose a reason for hiding this comment

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

@ilario When someone would want to change from false to true ? If there is not known useful use case I prefer not to add more options.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree with you, and I'll remove this.
I added this originally just because the same was present for BMX6 over Batman-adv

option anygw_mac 'aa:aa:aa:%N1:%N2:aa' # Parametrizable with %Nn. Keep in mind that the ebtables rule will use a mask of ff:ff:ff:00:00:00 so br-lan will not forward anything coming in that matches the first 3 bytes of it's own anygw_mac (aa:aa:aa: by default)
# option autoap_enabled 0 # Requires lime-ap-watchping installed. If enabled AP SSID is changed to ERROR when network issues
# option autoap_hosts "8.8.8.8 141.1.1.1" # Requires lime-ap-watchping installed. Hosts used to check if the network is working fine
Expand Down
2 changes: 1 addition & 1 deletion packages/lime-proto-anygw/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ define Package/$(PKG_NAME)
URL:=http://libremesh.org
DEPENDS:=+dnsmasq-dhcpv6 @(!PACKAGE_dnsmasq) +ebtables +libuci-lua \
+lime-system +lua +kmod-ebtables +kmod-macvlan \
+shared-state +shared-state-dnsmasq_leases
+shared-state +shared-state-dnsmasq_leases +kmod-ebtables-ipv6
Copy link
Member

Choose a reason for hiding this comment

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

Didn't you fixed this in another PR? here it seems unrelated

Copy link
Member Author

Choose a reason for hiding this comment

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

That kernel module is needed both by anygw (see #599) and Babeld in case of no VLAN and presence of Batman.

Copy link
Member Author

Choose a reason for hiding this comment

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

Gosh, now I noticed that this file was actually not pertaining to this PR, sorry.

PKGARCH:=all
endef

Expand Down
2 changes: 1 addition & 1 deletion packages/lime-proto-babeld/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ define Package/$(PKG_NAME)
CATEGORY:=LiMe
MAINTAINER:=Gioacchino Mazzurco <[email protected]>
URL:=https://libremesh.org
DEPENDS:=+babeld +lime-system
DEPENDS:=+babeld +lime-system +PACKAGE_lime-proto-batadv:kmod-ebtables-ipv6
PKGARCH:=all
endef

Expand Down
72 changes: 66 additions & 6 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 @@ -89,6 +89,18 @@ function babeld.configure(args)

uci:save("libremap")

--! If Babeld's Hello packets run over Batman-adv (whose bat0 is also
--! included in br-lan), all the Babeld nodes would appear as being direct
--! neighbors, so these Hello packets on bat0 have to be filtered
local babeldOverBatman = config.get_bool("network", "babeld_over_batman")
if utils.is_installed("kmod-batman-adv") and not babeldOverBatman then
fs.mkdir("/etc/firewall.lime.d")
fs.writefile("/etc/firewall.lime.d/21-babeld-not-over-bat0-ebtables",
"ebtables -t nat -A POSTROUTING -o bat0 -p ipv6"..
" --ip6-proto udp --ip6-sport 6696 --ip6-dport 6696 -j DROP\n")
else
fs.remove("/etc/firewall.lime.d/21-babeld-not-over-bat0-ebtables")
end
end

function babeld.setup_interface(ifname, args)
Expand All @@ -103,17 +115,65 @@ function babeld.setup_interface(ifname, args)
local vlanProto = args[3] or "8021ad"
local nameSuffix = args[4] or "_babeld"

--! If Babeld is without VLAN (vlanId is 0) it should run directly on plain
--! ethernet interfaces, but the ones which are inside of the LAN bridge
--! (e.g. eth0 or eth0.1) cannot have an IPv6 Link-Local and Babeld needs it.
--! So Babeld has to run on the bridge interface br-lan
local isIntoLAN = false
local addIPtoIf = true
for _,v in pairs(args["deviceProtos"]) do
if v == "lan" then
isIntoLAN = true
--! would be weird to add a static IP to the WAN interface
elseif v == "wan" then
addIPtoIf = false
end
end

if ifname:match("^wlan") then
--! currently (2019-10-12) mode-ap and mode-apname have an hardcoded
--! "option network lan" so they are always in the br-lan bridge
if ifname:match("^wlan.*ap$") or ifname:match("^wlan.*apname$") then
isIntoLAN = true

--! all the WLAN interfaces are ignored by proto-lan
--! so they are not in the bridge even if proto-lan is present
--! (except mode-ap and mode-apname as mentioned above)
else
isIntoLAN = false
end
end

if tonumber(vlanId) == 0 and isIntoLAN then
utils.log("Rather than "..ifname..
", adding br-lan into Babeld interfaces")
ifname = "br-lan"
--! br-lan has already an IPv4, no need to add it
addIPtoIf = false
end

local owrtInterfaceName, linuxVlanIfName, owrtDeviceName =
network.createVlanIface(ifname, vlanId, nameSuffix, vlanProto)

local ipv4, _ = network.primary_address()

local uci = config.get_uci_cursor()

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")
if addIPtoIf then
local ipv4, _ = network.primary_address()
--! the "else" way should always work but it fails in a weird way
--! with some wireless interfaces without VLAN
--! (e.g. works with wlan0-mesh and fails with wlan1-mesh)
--! so for these cases, the first way is used
--! (which indeed fails for most of the other cases)
if ifname:match("^wlan") and tonumber(vlanId) == 0 then
uci:set("network", owrtInterfaceName, "ifname", "@"..owrtDeviceName)
else
uci:set("network", owrtInterfaceName, "ifname", linuxVlanIfName)
end
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")
end

uci:set("babeld", owrtInterfaceName, "interface")
uci:set("babeld", owrtInterfaceName, "ifname", linuxVlanIfName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ config lime network
option bmx7_over_batman false
option bmx7_pref_gw none
option bmx7_wifi_rate_max 'auto'
option babeld_over_batman false
option anygw_mac "aa:aa:aa:%N1:%N2:aa"
option use_odhcpd false

Expand Down
2 changes: 2 additions & 0 deletions packages/lime-system/files/usr/lib/lua/lime/network.lua
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ function network.configure()
flags["specific"] = true
flags["_specific_section"] = owrtIf
end

flags["deviceProtos"] = deviceProtos

for _,protoParams in pairs(deviceProtos) do
local args = utils.split(protoParams, network.protoParamsSeparator)
Expand Down