From 58242d355b483e105affd0c69c681e46e88ad84c Mon Sep 17 00:00:00 2001
From: John Crispin <john@phrozen.org>
Date: Fri, 4 Dec 2020 16:29:35 +0100
Subject: [PATCH 19/43] lldp: add TIP tweaks

Signed-off-by: John Crispin <john@phrozen.org>
---
 package/network/services/lldpd/Makefile       |  5 ++--
 .../network/services/lldpd/files/lldpd.config | 16 ----------
 .../network/services/lldpd/files/lldpd.init   | 30 +++++++------------
 3 files changed, 14 insertions(+), 37 deletions(-)

diff --git a/package/network/services/lldpd/Makefile b/package/network/services/lldpd/Makefile
index 74d6791091..fd55c94cf4 100644
--- a/package/network/services/lldpd/Makefile
+++ b/package/network/services/lldpd/Makefile
@@ -8,12 +8,12 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=lldpd
-PKG_VERSION:=1.0.7
+PKG_VERSION:=1.0.5
 PKG_RELEASE:=1
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=https://media.luffy.cx/files/lldpd
-PKG_HASH:=1df79179d489c841b49265f2ab5ff05f284a647e95862d2f3c02b3fb079a87e1
+PKG_HASH:=2dd3b212f4dbabfcbb2794c0010b245f9f8e74b387984e757be6243a74c6cb99
 
 PKG_MAINTAINER:=Stijn Tintel <stijn@linux-ipv6.be>
 PKG_LICENSE:=ISC
@@ -97,6 +97,7 @@ CONFIGURE_ARGS += \
 	--disable-hardening \
 	--without-xml \
 	--disable-doxygen-doc \
+	--enable-json0 \
 	--sysconfdir=/tmp \
 	$(if $(CONFIG_LLDPD_WITH_CDP),,--disable-cdp) \
 	$(if $(CONFIG_LLDPD_WITH_FDP),,--disable-fdp) \
diff --git a/package/network/services/lldpd/files/lldpd.config b/package/network/services/lldpd/files/lldpd.config
index 5e7c51ba7e..b37dda87bf 100644
--- a/package/network/services/lldpd/files/lldpd.config
+++ b/package/network/services/lldpd/files/lldpd.config
@@ -1,20 +1,4 @@
 config lldpd config
-	option enable_cdp 1
-	option enable_fdp 1
-	option enable_sonmp 1
-	option enable_edp 1
-
 	option agentxsocket /var/run/agentx.sock
 
 	option lldp_class 4
-	option lldp_location "2:FR:6:Commercial Rd:3:Roseville:19:4"
-
-	# if empty, the distribution description is sent
-	#option lldp_description "OpenWrt System"
-	#option lldp_hostname "Modified Hostname"
-
-	#option lldp_mgmt_ip "!192.168.1.1"
-
-	# interfaces to listen on
-	list interface "loopback"
-	list interface "lan"
diff --git a/package/network/services/lldpd/files/lldpd.init b/package/network/services/lldpd/files/lldpd.init
index 7a5b25e016..e587bd7ebd 100644
--- a/package/network/services/lldpd/files/lldpd.init
+++ b/package/network/services/lldpd/files/lldpd.init
@@ -10,6 +10,10 @@ LLDPSOCKET=/var/run/lldpd.socket
 LLDPD_CONF=/tmp/lldpd.conf
 LLDPD_CONFS_DIR=/tmp/lldpd.d
 
+service_triggers() {
+	procd_add_reload_trigger lldpd
+}
+
 find_release_info()
 {
 	[ -s /etc/os-release ] && . /etc/os-release
@@ -37,7 +41,7 @@ write_lldpd_conf()
 	local iface ifnames=""
 	for iface in $ifaces; do
 		local ifname=""
-		if network_get_device ifname "$iface" || [ -e "/sys/class/net/$iface" ]; then
+		if [ -e "/sys/class/net/$iface" ]; then
 			append ifnames "${ifname:-$iface}" ","
 		fi
 	done
@@ -58,6 +62,7 @@ write_lldpd_conf()
 
 start_service() {
 
+	local enable
 	local enable_cdp
 	local enable_fdp
 	local enable_sonmp
@@ -68,6 +73,10 @@ start_service() {
 	local agentxsocket
 
 	config_load 'lldpd'
+	config_get_bool enable 'config' 'enable' 0
+
+	[ "$enable" -eq 1 ] || return
+
 	config_get_bool enable_cdp 'config' 'enable_cdp' 0
 	config_get_bool enable_fdp 'config' 'enable_fdp' 0
 	config_get_bool enable_sonmp 'config' 'enable_sonmp' 0
@@ -101,24 +110,7 @@ start_service() {
 }
 
 reload_service() {
-	running || return 1
-	$LLDPCLI -u $LLDPSOCKET &> /dev/null <<-EOF
-		pause
-		unconfigure lldp custom-tlv
-		unconfigure system interface pattern
-		unconfigure system description
-		unconfigure system hostname
-		unconfigure system ip management pattern
-	EOF
-	# Rewrite lldpd.conf
-	# If something changed it should be included by the lldpcli call
-	write_lldpd_conf
-	$LLDPCLI -u $LLDPSOCKET -c $LLDPD_CONF -c $LLDPD_CONFS_DIR &> /dev/null
-	# Broadcast update over the wire
-	$LLDPCLI -u $LLDPSOCKET &> /dev/null <<-EOF
-		resume
-		update
-	EOF
+	restart
 	return 0
 }
 
-- 
2.25.1

