Skip to content

Commit

Permalink
gluon-mesh-batman-adv-core: disable bridge port learning on bat0
Browse files Browse the repository at this point in the history
The mesh side has become fairly huge in many communities. Up to
a few thousand entries can currently be found in the forwarding
database (fdb) of a bridge for its bridge port bat0.

The bridge fdb is kind of redundant to the batman-adv global translation
table here. Therefore this patch tries to reduce memory footprint by
following an approach similar to the IGMP/MLD split patchset approach:

Make the bridge oblivious not only regarding multicast listeners towards
the mesh but with this patch unicast hosts on the mesh, too.

If the destination of an ethernet frame is known by the bridge to be a
local one, then the frame is forwarded to the according port. If it is
unknown, then the frame is forwarded to the wifi AP interface and bat0.

mac80211 and batman-adv then know whether to drop or forward a frame
further through their own book-keeping.

Note that unicast-flood is not disabled for the wifi AP bridge port, nor
is learning disabled on the wifi AP. This is mainly to keep the
configuration in UCI and according setup scripts simple ;). However, not
disalbling unicast-flood on the wifi AP interface might also give a
minor latency improvement for newly joining wifi clients.

Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue>
  • Loading branch information
T-X committed Aug 1, 2016
1 parent d445cb7 commit beab1d7
Show file tree
Hide file tree
Showing 2 changed files with 175 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,22 @@ uci:section('network', 'interface', 'bat0',
proto = 'none',
macaddr = sysconfig.primary_mac,
multicast_router = 2,
learning = 0,
}
)

uci:delete('network', 'client_lan')
if sysconfig.lan_ifname then
uci:section('network', 'interface', 'client_lan',
{
unicast_flood = 0,
}
)
for _, lanif in ipairs(lutil.split(sysconfig.lan_ifname, ' ')) do
uci:set('network', 'client_lan', 'ifname', lanif)
end
end

uci:save('network')


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
From: Linus Lüssing <linus.luessing@c0d3.blue>
Date: Sat, 21 May 2016 02:04:06 +0200
Subject: netifd: bridge: make learning and unicast flood configurable

Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue>

diff --git a/package/network/config/netifd/patches/0002-bridge-make-learning-and-unicast-flood-configurable-.patch b/package/network/config/netifd/patches/0002-bridge-make-learning-and-unicast-flood-configurable-.patch
new file mode 100644
index 0000000..0ca24bc
--- /dev/null
+++ b/package/network/config/netifd/patches/0002-bridge-make-learning-and-unicast-flood-configurable-.patch
@@ -0,0 +1,150 @@
+From 8c6ca8c86fad083690266e96404ff88d9c6f1bdd Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Linus=20L=C3=BCssing?= <linus.luessing@c0d3.blue>
+Date: Sat, 21 May 2016 01:49:45 +0200
+Subject: [PATCH] bridge: make learning and unicast-flood configurable per
+ bridge port
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Tuning these two options allows a more fine grained configuration of the
+forwarding database (fdb) of a bridge.
+
+The former allows to enable or disable the learning of the presence of
+MAC addresses behind a bridge port. (default: enabled on all ports)
+
+The latter allows to tune the behaviour in case a destination MAC address
+of a frame is unknown to the fdb, like only flooding on specific ports or
+not flooding on any port. (default: flood on all ports, except incoming)
+
+This can be useful to create a dumb hub, for instance for monitoring
+purposes. Or in larger layer 2 mesh networks to avoid keeping redundant
+databases (e.g. with the batman-adv translation table).
+
+Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue>
+---
+ device.c | 18 ++++++++++++++++++
+ device.h | 6 ++++++
+ system-linux.c | 18 ++++++++++++++++++
+ 3 files changed, 42 insertions(+)
+
+diff --git a/device.c b/device.c
+index 9344e1b..0e07615 100644
+--- a/device.c
++++ b/device.c
+@@ -51,6 +51,8 @@ static const struct blobmsg_policy dev_attrs[__DEV_ATTR_MAX] = {
+ [DEV_ATTR_MULTICAST_TO_UNICAST] = { .name = "multicast_to_unicast", .type = BLOBMSG_TYPE_BOOL },
+ [DEV_ATTR_MULTICAST_ROUTER] = { .name = "multicast_router", .type = BLOBMSG_TYPE_INT32 },
+ [DEV_ATTR_MULTICAST] = { .name ="multicast", .type = BLOBMSG_TYPE_BOOL },
++ [DEV_ATTR_LEARNING] = { .name ="learning", .type = BLOBMSG_TYPE_BOOL },
++ [DEV_ATTR_UNICAST_FLOOD] = { .name ="unicast_flood", .type = BLOBMSG_TYPE_BOOL },
+ };
+
+ const struct uci_blob_param_list device_attr_list = {
+@@ -177,6 +179,8 @@ device_merge_settings(struct device *dev, struct device_settings *n)
+ s->multicast : os->multicast;
+ n->multicast_to_unicast = s->multicast_to_unicast;
+ n->multicast_router = s->multicast_router;
++ n->learning = s->learning;
++ n->unicast_flood = s->unicast_flood;
+ n->flags = s->flags | os->flags | os->valid_flags;
+ }
+
+@@ -295,6 +299,16 @@ device_init_settings(struct device *dev, struct blob_attr **tb)
+ s->flags |= DEV_OPT_MULTICAST;
+ }
+
++ if ((cur = tb[DEV_ATTR_LEARNING])) {
++ s->learning = blobmsg_get_bool(cur);
++ s->flags |= DEV_OPT_LEARNING;
++ }
++
++ if ((cur = tb[DEV_ATTR_UNICAST_FLOOD])) {
++ s->unicast_flood = blobmsg_get_bool(cur);
++ s->flags |= DEV_OPT_UNICAST_FLOOD;
++ }
++
+ device_set_disabled(dev, disabled);
+ }
+
+@@ -939,6 +953,10 @@ device_dump_status(struct blob_buf *b, struct device *dev)
+ blobmsg_add_u32(b, "multicast_router", st.multicast_router);
+ if (st.flags & DEV_OPT_MULTICAST)
+ blobmsg_add_u8(b, "multicast", st.multicast);
++ if (st.flags & DEV_OPT_LEARNING)
++ blobmsg_add_u8(b, "learning", st.learning);
++ if (st.flags & DEV_OPT_UNICAST_FLOOD)
++ blobmsg_add_u8(b, "unicast_flood", st.unicast_flood);
+ }
+
+ s = blobmsg_open_table(b, "statistics");
+diff --git a/device.h b/device.h
+index ac77cfb..4a88c05 100644
+--- a/device.h
++++ b/device.h
+@@ -45,6 +45,8 @@ enum {
+ DEV_ATTR_MULTICAST_TO_UNICAST,
+ DEV_ATTR_MULTICAST_ROUTER,
+ DEV_ATTR_MULTICAST,
++ DEV_ATTR_LEARNING,
++ DEV_ATTR_UNICAST_FLOOD,
+ __DEV_ATTR_MAX,
+ };
+
+@@ -88,6 +90,8 @@ enum {
+ DEV_OPT_MULTICAST_TO_UNICAST = (1 << 14),
+ DEV_OPT_MULTICAST_ROUTER = (1 << 15),
+ DEV_OPT_MULTICAST = (1 << 16),
++ DEV_OPT_LEARNING = (1 << 17),
++ DEV_OPT_UNICAST_FLOOD = (1 << 18),
+ };
+
+ /* events broadcasted to all users of a device */
+@@ -149,6 +153,8 @@ struct device_settings {
+ bool multicast_to_unicast;
+ unsigned int multicast_router;
+ bool multicast;
++ bool learning;
++ bool unicast_flood;
+ };
+
+ /*
+diff --git a/system-linux.c b/system-linux.c
+index 351a994..621f99b 100644
+--- a/system-linux.c
++++ b/system-linux.c
+@@ -372,6 +372,16 @@ static void system_bridge_set_startup_query_interval(struct device *dev, const c
+ dev->ifname, val);
+ }
+
++static void system_bridge_set_learning(struct device *dev, const char *val)
++{
++ system_set_dev_sysctl("/sys/class/net/%s/brport/learning", dev->ifname, val);
++}
++
++static void system_bridge_set_unicast_flood(struct device *dev, const char *val)
++{
++ system_set_dev_sysctl("/sys/class/net/%s/brport/unicast_flood", dev->ifname, val);
++}
++
+ static int system_get_sysctl(const char *path, char *buf, const size_t buf_sz)
+ {
+ int fd = -1, ret = -1;
+@@ -648,6 +658,14 @@ int system_bridge_addif(struct device *bridge, struct device *dev)
+ system_bridge_set_multicast_router(dev, buf, false);
+ }
+
++ if (dev->settings.flags & DEV_OPT_LEARNING &&
++ !dev->settings.learning)
++ system_bridge_set_learning(dev, "0");
++
++ if (dev->settings.flags & DEV_OPT_UNICAST_FLOOD &&
++ !dev->settings.unicast_flood)
++ system_bridge_set_unicast_flood(dev, "0");
++
+ return ret;
+ }
+
+--
+1.7.10.4
+

0 comments on commit beab1d7

Please sign in to comment.