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

Add package gluon-radv-filterd #838

Closed
wants to merge 51 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
f963e05
Add package gluon-radv-filterd
jplitza Jul 29, 2016
e3b4dc5
gluon-radv-filterd: Update originators only if one is unknown
jplitza Nov 26, 2016
7d20a24
gluon-radv-filterd: Work with newer batman-adv versions
jplitza Nov 26, 2016
615fb91
gluon-radv-filterd: Fix upgrade script permissions and compilation
jplitza Nov 26, 2016
3667d60
gluon-radv-filterd: Add license to source file
jplitza Dec 8, 2016
e4457f2
gluon-radv-filterd: Fix use-after-free when best router expires
jplitza Dec 9, 2016
2f8eed6
gluon-radv-filterd: Add more debugging messages and more detailed errors
jplitza Dec 9, 2016
bd85e99
gluon-radv-filterd: Use fscanf() instead of getline() & sscanf() for …
jplitza Dec 9, 2016
c887960
gluon-radv-filterd: Tweak constants
jplitza Dec 9, 2016
a313af7
gluon-radv-filterd: Always output a message when choosing new router
jplitza Dec 9, 2016
43664bf
gluon-radv-filterd: updated socket filter
belzebub40k Dec 15, 2016
5a4dc1f
gluon-radv-filterd: Avoid use of GLUONDIR variable
jplitza Feb 8, 2017
3bf4d12
gluon-radv-filterd: Ship with own implementation of error()
jplitza Feb 8, 2017
a1fea71
gluon-radv-filterd: Add respondd module reporting the chosen gateway
jplitza Feb 9, 2017
5f3f371
gluon-radv-filterd: Fix and simplify originators parsing
jplitza Mar 6, 2017
20d83bc
gluon-radv-filterd: Refactor packet checking
jplitza Mar 31, 2017
66a26d0
gluon-radv-filterd: Various small fixes due to NeoRaider
jplitza Mar 31, 2017
ccfd102
gluon-radv-filterd: Remove all UCI options except threshold
jplitza Mar 31, 2017
31660c7
gluon-radv-filterd: Seperate macros for printf() and scanf()
jplitza Apr 30, 2017
5b34931
gluon-radv-filterd: Fix bug in BPF router lifetime filter
jplitza May 26, 2017
0aca838
gluon-radv-filterd: rename error() -> error_message()
jplitza Aug 20, 2017
93e2820
gluon-radv-filterd: Some minor fixes and cleanup
jplitza Aug 20, 2017
c9eccb9
gluon-radv-filterd: Use _GNU_SOURCE by default
ecsv Dec 20, 2017
779f17a
gluon-radv-filterd: Fix use-after-free in expire_routers
ecsv Dec 20, 2017
8d4a7bd
gluon-radv-filterd: Fix parenthesis in foreach macros
jplitza Jan 3, 2018
87bf15e
gluon-radv-filterd: Remove unused variable
ecsv Dec 20, 2017
f9b3b24
gluon-radv-filterd: Keep global variables static
ecsv Dec 20, 2017
9d194c3
gluon-radv-filterd: Handle bind errors
ecsv Dec 20, 2017
86c3fa8
gluon-radv-filterd: Use existing type ether_addr for mac addresses
ecsv Dec 20, 2017
7014d9e
gluon-radv-filterd: Move router code to extra functions
ecsv Dec 20, 2017
2d6cd71
gluon-radv-filterd: Handle malloc errors
ecsv Dec 20, 2017
07a7604
gluon-radv-filterd: Fix byte order of nd_ra_router_lifetime
ecsv Dec 20, 2017
3c8b9fd
gluon-radv-filterd: Finish va_start with va_end
ecsv Dec 20, 2017
1633c7c
gluon-radv-filterd: Check for recvfrom errors
ecsv Dec 20, 2017
a629849
gluon-radv-filterd: Fix size argument of recvfrom
ecsv Dec 20, 2017
c9f6617
gluon-radv-filterd: Move election prereq checks into function
ecsv Dec 20, 2017
8251de6
gluon-radv-filterd: Fix integer underflow with low TQs
ecsv Dec 20, 2017
dc70f24
gluon-radv-filterd: Use monotonic time source
ecsv Dec 20, 2017
bc3b3e3
gluon-radv-filterd: Don't kill daemon when select is interrupted
ecsv Dec 20, 2017
c39a62a
gluon-radv-filterd: Reset chain when daemon shuts down
ecsv Dec 20, 2017
34daf35
gluon-radv-filterd: Initialize router->originator after alloc
ecsv Dec 20, 2017
b06f126
gluon-radv-filterd: Use generic netlink to request batman-adv data
ecsv Dec 20, 2017
e3cb030
gluon-radv-filterd: Fix sock initialization check
ecsv Dec 20, 2017
2d3614c
gluon-radv-filterd: Trigger config reload checks on interface.* events
ecsv Dec 23, 2017
2394ad0
gluon-radv-filterd: Call cleanup when stopping daemon
ecsv Dec 20, 2017
4cc2ba2
gluon-radv-filterd: Mention respondd module in readme
jplitza Jan 3, 2018
9b3a2f2
gluon-radv-filterd: Use ebtables locking
ecsv Dec 20, 2017
f6f1ae9
gluon-radv-filterd: Return null via respondd without chosen gateway
jplitza Jan 3, 2018
f1a9196
gluon-radv-filterd: Move readme to docs/package/
jplitza Jan 3, 2018
32c1918
gluon-radv-filterd: Add documentation of site.conf parameter
jplitza Jan 3, 2018
1c7ce32
gluon-radv-filterd: improve documentation of selected router
lemoer Jan 5, 2018
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
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Several Freifunk communities in Germany use Gluon as the foundation of their Fre
package/gluon-ebtables-filter-ra-dhcp
package/gluon-ebtables-segment-mld
package/gluon-ebtables-source-filter
package/gluon-radv-filterd
package/gluon-web-admin

.. toctree::
Expand Down
61 changes: 61 additions & 0 deletions docs/package/gluon-radv-filterd.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
gluon-radv-filterd
==================

This package drops all incoming router advertisements except for the
default router with the best metric according to B.A.T.M.A.N. advanced.

Note that advertisements originating from the node itself (for example
via gluon-radvd) are not affected and considered at all.

Selected router
-------------

The router selection mechanism is independent from the batman-adv gateway mode.
In contrast, the device originating the router advertisment could be any router
or client connected to the mesh, as radv-filterd captures all router
advertisements originating from it. All nodes announcing router advertisement
**with** a default lifetime greater than 0 are being considered as candidates.

In case a router is not a batman-adv originator itself, its TQ is defined by
the originator it is connected to. This lookup uses the batman-adv global
translation table.

Initially the router is the selected by choosing the candidate with the
strongest TQ. When another candidate can provide a better TQ metric it is not
picked up as the selected router until it will outperform the currently
selected router by X metric units. The hysteresis threshold is configurable
and prevents excessive flapping of the gateway.

"Local" routers
---------------

The package has functionality to select "local" routers, i.e. those connected
via cable or WLAN instead of via the mesh (technically: appearing in the
``transtable_local``), a fake TQ of 512 so that they are always preferred.
However, if used together with the :doc:`package/gluon-ebtables-filter-ra-dhcp`
package, these router advertisements are filtered anyway and reach neither the
node nor any other client. You currently have to disable the package or insert
custom ebtables rules in order to use local routers.

respondd module
---------------

This package also contains a module for respondd that announces the currently
selected router via the ``statistics.gateway6`` property using its interface MAC
address. Note that this is different from the ``statistics.gateway`` property,
which contains the MAC address of the main B.A.T.M.A.N. adv slave interface of
the selected IPv4 gateway.

site.conf
---------

radv_filterd.threshold : optional
- minimal difference in TQ value that another gateway has to be better than
the currently chosen gateway to become the new chosen gateway
- defaults to ``20``

Example::

radv_filterd = {
threshold = 20,
}
51 changes: 51 additions & 0 deletions package/gluon-radv-filterd/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=gluon-radv-filterd
PKG_VERSION:=1
PKG_RELEASE:=1

PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)

include ../gluon.mk

define Package/gluon-radv-filterd
SECTION:=gluon
CATEGORY:=Gluon
TITLE:=Filter IPv6 router advertisements
DEPENDS:=+gluon-ebtables +libgluonutil +libbatadv +libnl-tiny
endef

MAKE_VARS += \
LIBNL_NAME="libnl-tiny" \
LIBNL_GENL_NAME="libnl-tiny"

define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/
endef

define Build/Configure
endef

define Build/Compile
$(call Build/Compile/Default)
$(call GluonSrcDiet,./luasrc,$(PKG_BUILD_DIR)/luadest/)
endef

define Package/gluon-radv-filterd/install
$(CP) ./files/* $(1)/
$(CP) $(PKG_BUILD_DIR)/luadest/* $(1)/

$(INSTALL_DIR) $(1)/usr/sbin/
$(INSTALL_BIN) $(PKG_BUILD_DIR)/gluon-radv-filterd $(1)/usr/sbin/

$(INSTALL_DIR) $(1)/lib/gluon/respondd
$(CP) $(PKG_BUILD_DIR)/respondd.so $(1)/lib/gluon/respondd/radv-filterd.so
endef

define Package/gluon-radv-filterd/postinst
#!/bin/sh
$(call GluonCheckSite,check_site.lua)
endef

$(eval $(call BuildPackage,gluon-radv-filterd))
3 changes: 3 additions & 0 deletions package/gluon-radv-filterd/check_site.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if need_table('radv_filterd', nil, false) then
need_number('radv_filterd.threshold')
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
config filterd
option threshold '20'
33 changes: 33 additions & 0 deletions package/gluon-radv-filterd/files/etc/init.d/gluon-radv-filterd
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/sh /etc/rc.common

USE_PROCD=1
START=50
DAEMON=/usr/sbin/gluon-radv-filterd

validate_filterd_section() {
uci_validate_section gluon-radv-filterd filterd "${1}" \
'threshold:uinteger:20'
}

start_service() {
config_load gluon-radv-filterd
config_foreach start_filterd filterd
}

start_filterd() {
local iface chain threshold
validate_filterd_section "$1"

procd_open_instance
procd_set_param command $DAEMON -i br-client -c RADV_FILTER -t $threshold
procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5}
procd_set_param netdev br-client
procd_set_param stderr 1
procd_close_instance
}

service_triggers() {
procd_add_reload_trigger "gluon-radv-filterd"
procd_add_validation "validate_filterd_section"
procd_add_raw_trigger "interface.*" 1000 /etc/init.d/gluon-radv-filterd reload
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
chain('RADV_FILTER', 'DROP')
rule 'FORWARD -p IPv6 -i bat0 --ip6-protocol ipv6-icmp --ip6-icmp-type router-advertisement -j RADV_FILTER'
rule 'RADV_FILTER -j ACCEPT'
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/lua

local site = require 'gluon.site_config'
local uci = (require 'simple-uci').cursor()

if site.radv_filterd and site.radv_filterd.threshold then
uci:foreach('gluon-radv-filterd', 'filterd', function(section)
uci:set('gluon-radv-filterd', section['.name'], 'threshold', site.radv_filterd.threshold)
end)
uci:save('gluon-radv-filterd')
end
49 changes: 49 additions & 0 deletions package/gluon-radv-filterd/src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
all: gluon-radv-filterd respondd.so

CPPFLAGS += -D_GNU_SOURCE

ifeq ($(origin PKG_CONFIG), undefined)
PKG_CONFIG = pkg-config
ifeq ($(shell which $(PKG_CONFIG) 2>/dev/null),)
$(error $(PKG_CONFIG) not found)
endif
endif

ifeq ($(origin LIBNL_CFLAGS) $(origin LIBNL_LDLIBS), undefined undefined)
LIBNL_NAME ?= libnl-3.0
ifeq ($(shell $(PKG_CONFIG) --modversion $(LIBNL_NAME) 2>/dev/null),)
$(error No $(LIBNL_NAME) development libraries found!)
endif
LIBNL_CFLAGS += $(shell $(PKG_CONFIG) --cflags $(LIBNL_NAME))
LIBNL_LDLIBS += $(shell $(PKG_CONFIG) --libs $(LIBNL_NAME))
endif
CFLAGS += $(LIBNL_CFLAGS)
LDLIBS += $(LIBNL_LDLIBS)

ifeq ($(origin LIBNL_GENL_CFLAGS) $(origin LIBNL_GENL_LDLIBS), undefined undefined)
LIBNL_GENL_NAME ?= libnl-genl-3.0
ifeq ($(shell $(PKG_CONFIG) --modversion $(LIBNL_GENL_NAME) 2>/dev/null),)
$(error No $(LIBNL_GENL_NAME) development libraries found!)
endif
LIBNL_GENL_CFLAGS += $(shell $(PKG_CONFIG) --cflags $(LIBNL_GENL_NAME))
LIBNL_GENL_LDLIBS += $(shell $(PKG_CONFIG) --libs $(LIBNL_GENL_NAME))
endif
CFLAGS += $(LIBNL_GENL_CFLAGS)
LDLIBS += $(LIBNL_GENL_LDLIBS)

ifeq ($(origin LIBBATADV_CFLAGS) $(origin LIBBATADV_LDLIBS), undefined undefined)
LIBBATADV_NAME ?= libbatadv
ifeq ($(shell $(PKG_CONFIG) --modversion $(LIBBATADV_NAME) 2>/dev/null),)
$(error No $(LIBBATADV_NAME) development libraries found!)
endif
LIBBATADV_CFLAGS += $(shell $(PKG_CONFIG) --cflags $(LIBBATADV_NAME))
LIBBATADV_LDLIBS += $(shell $(PKG_CONFIG) --libs $(LIBBATADV_NAME))
endif
CFLAGS += $(LIBBATADV_CFLAGS)
LDLIBS += $(LIBBATADV_LDLIBS)

gluon-radv-filterd: gluon-radv-filterd.c
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -Wall -o $@ $^ $(LDLIBS)

respondd.so: respondd.c
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -shared -fPIC -o $@ $^ $(LDLIBS) -lgluonutil
Loading