-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gluon-ebtables-limit-arp: a package for ARP rate-limiting
This package adds filters to limit the amount of ARP Requests devices are allowed to send into the mesh from a particular node to 1 per second on average. A burst of up to 50 ARP Requests is allowed until the rate-limiting takes effect (see --limit-burst in the ebtables manpage). Furthermore, ARP Requests with a target IP already present in the batman-adv DAT Cache are excluded from the rate-limiting, both regarding counting and filtering, as batman-adv will respond locally with no burden for the mesh. Therefore, this limiter should not affect popular target IPs, like gateways. However it should mitigate the problem of curious people or smart devices scanning the whole IP range. Which could create a significant amount of overhead for all participants so far. Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue>
- Loading branch information
Showing
4 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
include $(TOPDIR)/rules.mk | ||
|
||
PKG_NAME:=gluon-ebtables-limit-arp | ||
PKG_VERSION:=1 | ||
PKG_RELEASE:=1 | ||
|
||
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) | ||
|
||
include ../gluon.mk | ||
|
||
define Package/gluon-ebtables-limit-arp | ||
SECTION:=gluon | ||
CATEGORY:=Gluon | ||
TITLE:=Ebtables limiter for ARP packets | ||
DEPENDS:=+gluon-core +gluon-ebtables | ||
endef | ||
|
||
define Package/gluon-ebtables-limit-arp/description | ||
Gluon community wifi mesh firmware framework: Ebtables rules to | ||
rate-limit ARP packets. | ||
|
||
These filters limit the amount of ARP Requests devices are allowed | ||
to send into the mesh from a particular node to 1 per second on | ||
average. | ||
|
||
A burst of up to 50 ARP Requests is allowed until the rate-limiting | ||
takes effect (see --limit-burst in the ebtables manpage). | ||
|
||
Furthermore, ARP Requests with a target IP already present in the | ||
batman-adv DAT Cache are excluded from the rate-limiting, | ||
both regarding counting and filtering, as batman-adv will respond | ||
locally with no burden for the mesh. Therefore, this limiter | ||
should not affect popular target IPs, like gateways. | ||
|
||
However it should mitigate the problem of curious people or | ||
smart devices scanning the whole IP range. Which could create | ||
a significant amount of overhead for all participants so far. | ||
endef | ||
|
||
define Build/Prepare | ||
mkdir -p $(PKG_BUILD_DIR) | ||
endef | ||
|
||
define Build/Configure | ||
endef | ||
|
||
define Build/Compile | ||
endef | ||
|
||
define Package/gluon-ebtables-limit-arp/install | ||
$(CP) ./files/* $(1)/ | ||
endef | ||
|
||
$(eval $(call BuildPackage,gluon-ebtables-limit-arp)) |
25 changes: 25 additions & 0 deletions
25
package/gluon-ebtables-limit-arp/files/lib/gluon/ebtables-worker/100-arp-limit.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/lua | ||
|
||
local nixio = require('nixio') | ||
|
||
if not nixio.getenv("EBTABLES_ATOMIC_FILE") then | ||
print("Error: Refusing to run without EBTABLES_ATOMIC_FILE") | ||
os.exit(1) | ||
end | ||
|
||
os.execute("ebtables -F ARP_LIMIT_DATCHECK") | ||
|
||
local popen = io.popen("batctl dc -H") | ||
for line in popen:lines() do | ||
local t={} ; i=1 | ||
local bar = line:gmatch("(%d+\.%d+\.%d+\.%d+)%s+(%w+:%w+:%w+:%w+:%w+:%w+)") | ||
local ip, mac | ||
|
||
for a, b in bar do | ||
ip = a | ||
mac = b | ||
end | ||
|
||
os.execute("ebtables -I ARP_LIMIT_DATCHECK -p ARP --arp-ip-dst " .. ip .. " -j mark --mark-or 0x2 --mark-target RETURN") | ||
end | ||
popen:close() |
2 changes: 2 additions & 0 deletions
2
package/gluon-ebtables-limit-arp/files/lib/gluon/ebtables/100-arp-limit-chains
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
chain('ARP_LIMIT', 'DROP') | ||
chain('ARP_LIMIT_DATCHECK', 'RETURN') |
5 changes: 5 additions & 0 deletions
5
package/gluon-ebtables-limit-arp/files/lib/gluon/ebtables/320-arp-limit-rules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
rule('ARP_LIMIT -j ARP_LIMIT_DATCHECK') | ||
rule('ARP_LIMIT --mark 0x2/0x2 -j RETURN') | ||
rule('ARP_LIMIT --limit 1/sec --limit-burst 50 -j RETURN') | ||
|
||
rule('FORWARD -p ARP --logical-out br-client -o bat0 --arp-op Request -j ARP_LIMIT') |