From 5b97d36c7e326703bdde1e9eb22aadc57bcad63a Mon Sep 17 00:00:00 2001
From: Matthias Schiffer <mschiffer@universe-factory.net>
Date: Wed, 25 Sep 2019 00:13:23 +0200
Subject: [PATCH] gluon-mesh-batman-adv: remove gluon-mesh-batman-adv-14

---
 docs/package/gluon-ebtables-limit-arp.rst     | 14 +++---
 docs/package/gluon-mesh-batman-adv.rst        | 46 ++-----------------
 docs/user/faq.rst                             |  7 ++-
 docs/user/site.rst                            | 14 ++----
 package/features                              |  4 +-
 package/gluon-mesh-batman-adv/Makefile        | 40 ++--------------
 package/gluon-mesh-batman-adv/check_site.lua  | 16 +------
 .../files/lib/netifd/proto/gluon_bat0.sh      | 10 +---
 .../upgrade/310-gluon-mesh-batman-adv-mesh    | 32 +++++--------
 package/gluon-mesh-batman-adv/src/respondd.c  | 20 ++------
 ...tl-remove-kmod-batman-adv-dependency.patch | 22 ---------
 ...03-batman-adv-remove-module-autoload.patch | 21 ---------
 12 files changed, 42 insertions(+), 204 deletions(-)
 delete mode 100644 patches/packages/routing/0002-batctl-remove-kmod-batman-adv-dependency.patch
 delete mode 100644 patches/packages/routing/0003-batman-adv-remove-module-autoload.patch

diff --git a/docs/package/gluon-ebtables-limit-arp.rst b/docs/package/gluon-ebtables-limit-arp.rst
index e4ba6b4ba..9431f0046 100644
--- a/docs/package/gluon-ebtables-limit-arp.rst
+++ b/docs/package/gluon-ebtables-limit-arp.rst
@@ -1,17 +1,17 @@
 gluon-ebtables-limit-arp
 ========================
 
-The *gluon-ebtables-limit-arp* package adds filters to limit the 
-amount of ARP requests client devices are allowed to send into the 
-mesh. 
+The *gluon-ebtables-limit-arp* package adds filters to limit the
+amount of ARP requests client devices are allowed to send into the
+mesh.
 
 The limits per client device, identified by its MAC address, are
-6 packets per minute and 1 per second per node in total. 
+6 packets per minute and 1 per second per node in total.
 A burst of up to 50 ARP requests is allowed until the rate-limiting
 takes effect (see ``--limit-burst`` in ``ebtables(8)``).
 
 Furthermore, ARP requests for a target IP already present in the
-batman-adv DAT cache are excluded from rate-limiting, in regard 
+batman-adv DAT cache are excluded from rate-limiting, in regard
 to both counting and filtering, as batman-adv will be able
 to respond locally without a burden for the mesh. Therefore, this
 limiter should not affect popular target IP addresses, like those
@@ -21,8 +21,8 @@ However it mitigates the impact on the mesh when a larger range of
 its IPv4 subnet is being scanned, which would otherwise result in
 a significant amount of ARP chatter, even for unused IP addresses.
 
-This package is selected by default if the installed routing
-package is gluon-mesh-batman-adv-14 or gluon-mesh-batman-adv-15.
+This package is installed by default if the selected routing
+feature is *mesh-batman-adv-15*.
 It can be unselected via::
 
     GLUON_SITE_PACKAGES := \
diff --git a/docs/package/gluon-mesh-batman-adv.rst b/docs/package/gluon-mesh-batman-adv.rst
index 0e24f344f..70b55df71 100644
--- a/docs/package/gluon-mesh-batman-adv.rst
+++ b/docs/package/gluon-mesh-batman-adv.rst
@@ -20,49 +20,11 @@ B.A.T.M.A.N. Advanced project homepage:
 
 * https://www.open-mesh.org/projects/batman-adv/wiki/Wiki
 
-Flavours
---------
-
-Gluon currently supports two main build flavours of batman-adv:
-
-gluon-mesh-batman-adv-15
-^^^^^^^^^^^^^^^^^^^^^^^^
-
-This is the recommended batman-adv flavour to use.
-
-It follows recent, upstream batman-adv releases and is flexible to new feature additions.
-
-gluon-mesh-batman-adv-14 (`batman-adv-legacy`)
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-`gluon-mesh-batman-adv-14`, also known as `batman-adv-legacy` or batman-adv v2013.4
-is the last batman-adv release with the batman-adv compatibility version 14, which
-was released in October 2013.
-
-With batman-adv v2014.0.0 a compat breakage became necessary for the introduction
-of new features. However, one of these features was the addition of TVLV support
-(type-version-length-value fields) which from then on allowed adding features
-without breaking packet format compatibility. This made it possible to stay with
-compatibility version 15 so far.
-
-For new installations `gluon-mesh-batman-adv-14` is **not recommended**. It misses
-a lot of bugfixes and is currently only available for existing communities
-until they have migrated. This package will soon be deprecated and removed.
-
-Also see:
-
-* https://www.open-mesh.org/projects/batman-adv/wiki/Compatversion
-* https://www.open-mesh.org/news/56
-* https://github.com/freifunk-gluon/batman-adv-legacy/
-
-
 B.A.T.M.A.N. Routing Algorithms
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-For the `gluon-mesh-batman-adv-15` package two routing algorithms are selectable
-via :ref:`site.conf mesh section <user-site-mesh>`: BATMAN_IV and BATMAN_V.
-
-For the `gluon-mesh-batman-adv-14` package, BATMAN_IV_LEGACY needs to be selected.
+Two routing algorithms are selectable via
+:ref:`site.conf mesh section <user-site-mesh>`: BATMAN_IV and BATMAN_V.
 
 BATMAN_IV - stable
 """"""""""""""""""
@@ -92,8 +54,8 @@ mesh protocol, it quickly reaches its limit.
 
 For meshes with about **50 nodes / 100 clients, or more** it is therefore highly
 recommended to add the :doc:`gluon-ebtables-filter-multicast`
-package. Also, with gluon-mesh-batman-adv-15 or gluon-mesh-batman-adv-14
-installed :doc:`gluon-ebtables-limit-arp` is selected by default.
+package. Also, with the *mesh-batman-adv-15* feature,
+:doc:`gluon-ebtables-limit-arp` is selected by default.
 
 Furthermore, by default IGMP and MLD messages are filtered. See
 :ref:`site.conf mesh section <user-site-mesh>` and
diff --git a/docs/user/faq.rst b/docs/user/faq.rst
index 2c01814f4..d40fcb5c9 100644
--- a/docs/user/faq.rst
+++ b/docs/user/faq.rst
@@ -45,9 +45,8 @@ Consider these key values:
   .. _MSS clamping: https://www.tldp.org/HOWTO/Adv-Routing-HOWTO/lartc.cookbook.mtu-mss.html
 
 - Encapsulation: Account for the overhead created by the configured mesh protocol
-  encapsulating the payload, which is
-  - up to 32 Byte (14 Byte Ethernet + 18 Byte batadv) for batman-adv compat v15 (v2014.0 and later)
-  - up to 28 Byte (14 Byte Ethernet + 14 Byte batadv) for batman-adv compat v14 (v2011.3.0 until and including v2013.4.0)
+  encapsulating the payload, which is up to 32 Byte (14 Byte Ethernet + 18 Byte
+  batadv).
 
 - PMTU: What MTU does the path between your gateway and each of its peers support?
 
@@ -106,4 +105,4 @@ Conclusion
 Determining the maximum MTU can be a tedious process, especially since the PMTU
 of peers could change at any time. The general recommendation for maximized
 compatibility is therefore the minimum MTU of 1312 Byte, which works well with
-all combinations of IPv4, IPv6, batman-adv compat v14 and v15.
+both IPv4 and IPv6.
diff --git a/docs/user/site.rst b/docs/user/site.rst
index 4d09ccec1..0aabbc9ce 100644
--- a/docs/user/site.rst
+++ b/docs/user/site.rst
@@ -244,12 +244,8 @@ mesh
     The mandatory value *routing_algo* selects the batman-adv protocol variant.
     The following values are supported:
 
-    - ``BATMAN_IV_LEGACY`` (*mesh-batman-adv-14*)
-    - ``BATMAN_IV`` (*mesh-batman-adv-15*)
-    - ``BATMAN_V`` (*mesh-batman-adv-15*)
-
-    When both *mesh-batman-adv-14* and *mesh-batman-adv-15* are included, this
-    setting specifies which one to use.
+    - ``BATMAN_IV``
+    - ``BATMAN_V``
 
     The optional value *gw_sel_class* sets the gateway selection class, the
     default is ``20`` for B.A.T.M.A.N. IV and ``5000`` kbit/s for B.A.T.M.A.N. V.
@@ -598,12 +594,12 @@ prefix: The feature flag corresponding to the package *gluon-mesh-batman-adv-15*
 
 The file ``package/features`` in the Gluon repository (or
 ``features`` in site feeds) can specify additional rules for deriving package lists
-from feature flags, e.g. specifying both *status-page* and either *mesh-batman-adv-14*
-or *mesh-batman-adv-15* will automatically select the additional package
+from feature flags, e.g. specifying both *status-page* and *mesh-batman-adv-15*
+will automatically select the additional package
 *gluon-status-page-mesh-batman-adv*. In the future, selecting the flags
 *mesh-vpn-fastd* and *respondd* might automatically enable the additional
 package *gluon-mesh-vpn-fastd-respondd*, and enabling *status-page* and
-*mesh-batman-adv-15* (or *-14*) with ``de`` in *GLUON_LANGS* could
+*mesh-batman-adv-15* with ``de`` in *GLUON_LANGS* could
 add the package *gluon-status-page-mesh-batman-adv-i18n-de*.
 
 In short, it is not necessary anymore to list all the individual packages that are
diff --git a/package/features b/package/features
index ba2745030..1f0d825a3 100644
--- a/package/features
+++ b/package/features
@@ -23,10 +23,10 @@ packages 'web-advanced' \
 packages 'web-advanced & autoupdater' \
 	'gluon-web-autoupdater'
 
-packages 'status-page & (mesh-batman-adv-14 | mesh-batman-adv-15)' \
+packages 'status-page & mesh-batman-adv-15' \
 	'gluon-status-page-mesh-batman-adv'
 
-packages 'mesh-batman-adv-14 | mesh-batman-adv-15' \
+packages 'mesh-batman-adv-15' \
 	'gluon-ebtables-limit-arp' \
 	'gluon-radvd'
 
diff --git a/package/gluon-mesh-batman-adv/Makefile b/package/gluon-mesh-batman-adv/Makefile
index 70e9d9994..eac84ac5f 100644
--- a/package/gluon-mesh-batman-adv/Makefile
+++ b/package/gluon-mesh-batman-adv/Makefile
@@ -5,9 +5,11 @@ PKG_VERSION:=1
 
 include ../gluon.mk
 
-define Package/gluon-mesh-batman-adv-common
-  TITLE:=Gluon scripts for batman-adv and batman-adv-legacy
-  DEPENDS:= \
+define Package/gluon-mesh-batman-adv-15
+  PROVIDES:=gluon-mesh-batman-adv
+  TITLE:=Support for batman-adv meshing (compat level 15)
+  DEPENDS+= \
+	+kmod-batman-adv \
 	+gluon-core \
 	+libgluonutil \
 	+gluon-client-bridge \
@@ -23,36 +25,4 @@ define Package/gluon-mesh-batman-adv-common
 	+@GLUON_SPECIALIZE_KERNEL:KERNEL_LIBCRC32C
 endef
 
-define Package/gluon-mesh-batman-adv-14
-  PROVIDES:=gluon-mesh-batman-adv
-  TITLE:=Support for batman-adv meshing (compat level 14)
-  DEPENDS+= \
-	+gluon-mesh-batman-adv-common \
-	+kmod-batman-adv-legacy
-endef
-
-define Package/gluon-mesh-batman-adv-15
-  PROVIDES:=gluon-mesh-batman-adv
-  TITLE:=Support for batman-adv meshing (compat level 15)
-  DEPENDS+= \
-	+gluon-mesh-batman-adv-common \
-	+kmod-batman-adv
-endef
-
-define Package/gluon-mesh-batman-adv-common/install
-	$(Gluon/Build/Install)
-endef
-
-define Package/gluon-mesh-batman-adv-14/install
-	$(INSTALL_DIR) $(1)/lib/gluon/mesh-batman-adv
-	touch $(1)/lib/gluon/mesh-batman-adv/compat-14
-endef
-#
-define Package/gluon-mesh-batman-adv-15/install
-	$(INSTALL_DIR) $(1)/lib/gluon/mesh-batman-adv
-	touch $(1)/lib/gluon/mesh-batman-adv/compat-15
-endef
-
-$(eval $(call BuildPackageGluon,gluon-mesh-batman-adv-common))
-$(eval $(call BuildPackageGluon,gluon-mesh-batman-adv-14))
 $(eval $(call BuildPackageGluon,gluon-mesh-batman-adv-15))
diff --git a/package/gluon-mesh-batman-adv/check_site.lua b/package/gluon-mesh-batman-adv/check_site.lua
index aa930955e..c0b6f3053 100644
--- a/package/gluon-mesh-batman-adv/check_site.lua
+++ b/package/gluon-mesh-batman-adv/check_site.lua
@@ -2,18 +2,4 @@
 need_boolean(in_domain({'mesh', 'vxlan'}), not this_domain())
 
 need_number({'mesh', 'batman_adv', 'gw_sel_class'}, false)
-
-
-local allowed_algos = {}
-local has_compat_14 = (os.execute('exec ls "$IPKG_INSTROOT"/lib/gluon/mesh-batman-adv/compat-14 >/dev/null 2>&1') == 0)
-local has_compat_15 = (os.execute('exec ls "$IPKG_INSTROOT"/lib/gluon/mesh-batman-adv/compat-15 >/dev/null 2>&1') == 0)
-
-if has_compat_14 then
-	table.insert(allowed_algos, 'BATMAN_IV_LEGACY')
-end
-if has_compat_15 then
-	table.insert(allowed_algos, 'BATMAN_IV')
-	table.insert(allowed_algos, 'BATMAN_V')
-end
-
-need_one_of({'mesh', 'batman_adv', 'routing_algo'}, allowed_algos)
+need_one_of({'mesh', 'batman_adv', 'routing_algo'}, {'BATMAN_IV', 'BATMAN_V'})
diff --git a/package/gluon-mesh-batman-adv/files/lib/netifd/proto/gluon_bat0.sh b/package/gluon-mesh-batman-adv/files/lib/netifd/proto/gluon_bat0.sh
index dcc28f60a..8cbf3d14d 100755
--- a/package/gluon-mesh-batman-adv/files/lib/netifd/proto/gluon_bat0.sh
+++ b/package/gluon-mesh-batman-adv/files/lib/netifd/proto/gluon_bat0.sh
@@ -43,13 +43,7 @@ proto_gluon_bat0_setup() {
 	ip link set primary0 address "$primary0_mac" mtu 1532 up
 
 	local routing_algo="$(lua -e 'print(require("gluon.site").mesh.batman_adv.routing_algo())')"
-
-	if [ "$routing_algo" = 'BATMAN_IV_LEGACY' ]; then
-		modprobe batman-adv-legacy
-	else
-		modprobe batman-adv
-		(echo "$routing_algo" >/sys/module/batman_adv/parameters/routing_algo) 2>/dev/null
-	fi
+	(echo "$routing_algo" >/sys/module/batman_adv/parameters/routing_algo) 2>/dev/null
 
 	echo bat0 > /sys/class/net/primary0/batman_adv/mesh_iface
 
@@ -64,8 +58,6 @@ proto_gluon_bat0_teardown() {
 
 	ip link del bat0
 	ip link del primary0
-
-	rmmod batman-adv
 }
 
 add_protocol gluon_bat0
diff --git a/package/gluon-mesh-batman-adv/luasrc/lib/gluon/upgrade/310-gluon-mesh-batman-adv-mesh b/package/gluon-mesh-batman-adv/luasrc/lib/gluon/upgrade/310-gluon-mesh-batman-adv-mesh
index b864dda72..f021de2d1 100755
--- a/package/gluon-mesh-batman-adv/luasrc/lib/gluon/upgrade/310-gluon-mesh-batman-adv-mesh
+++ b/package/gluon-mesh-batman-adv/luasrc/lib/gluon/upgrade/310-gluon-mesh-batman-adv-mesh
@@ -7,32 +7,22 @@ local util = require 'gluon.util'
 local uci = require('simple-uci').cursor()
 
 
-local gw_mode = uci:get('batman-adv', 'bat0', 'gw_mode') or uci:get('batman-adv-legacy', 'bat0', 'gw_mode') or 'client'
+local gw_mode = uci:get('batman-adv', 'bat0', 'gw_mode') or 'client'
 local gw_sel_class = site.mesh.batman_adv.gw_sel_class()
 local routing_algo = site.mesh.batman_adv.routing_algo()
 
 uci:delete('batman-adv-legacy', 'bat0')
-uci:delete('batman-adv', 'bat0')
-
-if routing_algo == 'BATMAN_IV_LEGACY' then
-	uci:section('batman-adv-legacy', 'mesh', 'bat0', {
-		orig_interval = 5000,
-		gw_mode = gw_mode,
-		gw_sel_class = gw_sel_class,
-		hop_penalty = 15,
-	})
-else
-	uci:section('batman-adv', 'mesh', 'bat0', {
-		orig_interval = 5000,
-		gw_mode = gw_mode,
-		gw_sel_class = gw_sel_class,
-		hop_penalty = 15,
-		routing_algo = routing_algo,
-		multicast_mode = false,
-	})
-end
-
 uci:save('batman-adv-legacy')
+
+uci:delete('batman-adv', 'bat0')
+uci:section('batman-adv', 'mesh', 'bat0', {
+	orig_interval = 5000,
+	gw_mode = gw_mode,
+	gw_sel_class = gw_sel_class,
+	hop_penalty = 15,
+	routing_algo = routing_algo,
+	multicast_mode = false,
+})
 uci:save('batman-adv')
 
 uci:delete('network', 'gluon_bat0')
diff --git a/package/gluon-mesh-batman-adv/src/respondd.c b/package/gluon-mesh-batman-adv/src/respondd.c
index 7d84d1499..c2b20399f 100644
--- a/package/gluon-mesh-batman-adv/src/respondd.c
+++ b/package/gluon-mesh-batman-adv/src/respondd.c
@@ -232,24 +232,9 @@ static struct json_object * get_mesh(void) {
 	return ret;
 }
 
-static struct json_object * get_batman_adv_compat(const char *version) {
-	int compat = 15;
-
-	if (!version)
-		return NULL;
-
-	if (strcmp(version, "2013.4.0") == 0)
-		compat = 14;
-
-	return json_object_new_int(compat);
-}
-
 static struct json_object * respondd_provider_nodeinfo(void) {
 	struct json_object *ret = json_object_new_object();
 
-	char *version = gluonutil_read_line("/sys/module/batman_adv/version");
-	struct json_object *compat = get_batman_adv_compat(version);
-
 	struct json_object *network = json_object_new_object();
 	json_object_object_add(network, "addresses", get_addresses());
 	json_object_object_add(network, "mesh", get_mesh());
@@ -257,8 +242,9 @@ static struct json_object * respondd_provider_nodeinfo(void) {
 
 	struct json_object *software = json_object_new_object();
 	struct json_object *software_batman_adv = json_object_new_object();
-	json_object_object_add(software_batman_adv, "version", gluonutil_wrap_and_free_string(version));
-	json_object_object_add(software_batman_adv, "compat", compat);
+	json_object_object_add(software_batman_adv, "version",
+		gluonutil_wrap_and_free_string(gluonutil_read_line("/sys/module/batman_adv/version")));
+	json_object_object_add(software_batman_adv, "compat", json_object_new_int(15));
 	json_object_object_add(software, "batman-adv", software_batman_adv);
 	json_object_object_add(ret, "software", software);
 
diff --git a/patches/packages/routing/0002-batctl-remove-kmod-batman-adv-dependency.patch b/patches/packages/routing/0002-batctl-remove-kmod-batman-adv-dependency.patch
deleted file mode 100644
index dc3b4b634..000000000
--- a/patches/packages/routing/0002-batctl-remove-kmod-batman-adv-dependency.patch
+++ /dev/null
@@ -1,22 +0,0 @@
-From: Linus Lüssing <linus.luessing@c0d3.blue>
-Date: Mon, 18 Feb 2019 18:28:03 +0100
-Subject: batctl: remove kmod-batman-adv dependency
-
-This always pulls in the batman-adv compat 15 kernel module. However,
-batctl works just as well with batman-adv-legacy (compat 14).
-
-Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue>
-
-diff --git a/batctl/Makefile b/batctl/Makefile
-index 4e67512844d07607852a5447a336dc9f93f5990a..df96ca7325ba3f84bd682da6df32fa4489474113 100644
---- a/batctl/Makefile
-+++ b/batctl/Makefile
-@@ -23,7 +23,7 @@ define Package/batctl
-   URL:=https://www.open-mesh.org/
-   SECTION:=net
-   CATEGORY:=Network
--  DEPENDS:=+kmod-batman-adv +libnl-tiny +libc +librt
-+  DEPENDS:=+libnl-tiny +libc +librt
-   TITLE:=B.A.T.M.A.N. Advanced user space configuration tool batctl
-   MAINTAINER:=Simon Wunderlich <sw@simonwunderlich.de>
- endef
diff --git a/patches/packages/routing/0003-batman-adv-remove-module-autoload.patch b/patches/packages/routing/0003-batman-adv-remove-module-autoload.patch
deleted file mode 100644
index cd7a809f5..000000000
--- a/patches/packages/routing/0003-batman-adv-remove-module-autoload.patch
+++ /dev/null
@@ -1,21 +0,0 @@
-From: Linus Lüssing <linus.luessing@c0d3.blue>
-Date: Sun, 16 Jun 2019 00:01:36 +0200
-Subject: batman-adv: remove module autoload
-
-Instead of unconditionally loading this module on boot the gluon_bat0
-netifd protocol script will later take care of loading either the batman-adv
-or batman-adv-legacy module, depending on the configured routing
-algorithm in UCI.
-
-diff --git a/batman-adv/Makefile b/batman-adv/Makefile
-index ae434909c90f61efdf0d80b56352c983cfef25b0..e58f862b0e5fac7ac12d6ba5a09241d23148a252 100644
---- a/batman-adv/Makefile
-+++ b/batman-adv/Makefile
-@@ -30,7 +30,6 @@ define KernelPackage/batman-adv
-   DEPENDS:=+KMOD_BATMAN_ADV_BLA:kmod-lib-crc16 +kmod-crypto-crc32c +kmod-lib-crc32c +kmod-cfg80211
-   TITLE:=B.A.T.M.A.N. Adv
-   FILES:=$(PKG_BUILD_DIR)/net/batman-adv/batman-adv.$(LINUX_KMOD_SUFFIX)
--  AUTOLOAD:=$(call AutoProbe,batman-adv)
- endef
- 
- define KernelPackage/batman-adv/description
-- 
GitLab