From patchwork Tue Jan 5 13:07:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 563075 X-Patchwork-Delegate: jow@openwrt.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1C1911402EC for ; Wed, 6 Jan 2016 00:07:29 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=viFnXSvY; dkim-atps=neutral Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id D06AB28BD3F; Tue, 5 Jan 2016 14:06:51 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID autolearn=unavailable version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id CE85328B84F for ; Tue, 5 Jan 2016 14:06:47 +0100 (CET) X-policyd-weight: using cached result; rate: -8.5 Received: from mail-wm0-f44.google.com (mail-wm0-f44.google.com [74.125.82.44]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Tue, 5 Jan 2016 14:06:47 +0100 (CET) Received: by mail-wm0-f44.google.com with SMTP id f206so22233301wmf.0 for ; Tue, 05 Jan 2016 05:07:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=/RgfdMBlOIjbiA/+kRNhxKuzgwE9vYex17S4g2XsayI=; b=viFnXSvYuWQ2YKUrBehX8Rw8M20iUbbPd492LaesyEJt8nmPi+gvkZU2eNFyybUlKM kJcg/UPxF27Q1EdTa+BSwP+jgwQ+D9Ch8IbMCDzeB/54IWnZbFpvc9W7Sgq7dSU5hBKu 67hIYT4wEO4cJ/ldq3C2y2IqT9sm2GtUbpggbCCqo05GsmFMs4mSt4937ua7aavW+A8A APwfMXIVOQr60mi1nlCCWpDSwx8SbRufpw6NurFdLVvfj7i1L3zksaqdgU48ywr/48V2 c4aMHDSlKU/EF4XOEVUoTEkR/h5ioXDJztW7dn+nqHkzQ2LHJwieflZKqAkHMdq/eC7E 3yag== X-Received: by 10.28.148.140 with SMTP id w134mr4243973wmd.66.1451999236118; Tue, 05 Jan 2016 05:07:16 -0800 (PST) Received: from orion.ocedo.cluj.local ([5.2.198.78]) by smtp.gmail.com with ESMTPSA id w23sm3506983wmd.1.2016.01.05.05.07.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 05 Jan 2016 05:07:15 -0800 (PST) From: Alexandru Ardelean To: openwrt-devel@lists.openwrt.org Date: Tue, 5 Jan 2016 15:07:08 +0200 Message-Id: <1451999229-13327-1-git-send-email-ardeleanalex@gmail.com> X-Mailer: git-send-email 2.1.4 Cc: Alexandru Ardelean Subject: [OpenWrt-Devel] [PATCH 1/2] lldpd: fix reload function for when interfaces change X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" From: Alexandru Ardelean The problem is that interfaces are specified at start as command line arguments, making them unchange-able via reload. That means, we have to move (since lldpd allows this) the interfaces-match-pattern option to be in a config file and reload the configuration. It's either that, or do a 'restart'. Since we're generating the lldpd.conf file, we'll have to move the 'sysconfdir' of lldpd to /tmp, where the files will get written ; this will prevent any unncessary flash writes. Signed-off-by: Alexandru Ardelean --- package/network/services/lldpd/Makefile | 1 + package/network/services/lldpd/files/lldpd.init | 53 +++++++++++++++++-------- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/package/network/services/lldpd/Makefile b/package/network/services/lldpd/Makefile index 81e4a8f..5f413cf 100644 --- a/package/network/services/lldpd/Makefile +++ b/package/network/services/lldpd/Makefile @@ -94,6 +94,7 @@ CONFIGURE_ARGS += \ --with-embedded-libevent=no \ --disable-hardening \ --without-xml \ + --sysconfdir=/tmp \ $(if $(CONFIG_LLDPD_WITH_CDP),,--disable-cdp) \ $(if $(CONFIG_LLDPD_WITH_FDP),,--disable-fdp) \ $(if $(CONFIG_LLDPD_WITH_EDP),,--disable-edp) \ diff --git a/package/network/services/lldpd/files/lldpd.init b/package/network/services/lldpd/files/lldpd.init index 6965189..064bac1 100644 --- a/package/network/services/lldpd/files/lldpd.init +++ b/package/network/services/lldpd/files/lldpd.init @@ -7,6 +7,8 @@ STOP=01 USE_PROCD=1 LLDPCLI=/usr/sbin/lldpcli LLDPSOCKET=/var/run/lldpd.socket +LLDPD_CONF=/tmp/lldpd.conf +LLDPD_CONFS_DIR=/tmp/lldpd.d find_release_info() { @@ -17,16 +19,43 @@ find_release_info() echo "${DISTRIB_DESCRIPTION:-Unknown OpenWrt release} @ $(cat /proc/sys/kernel/hostname)" } -start_service() { +write_lldpd_conf() +{ . /lib/functions/network.sh + local lldp_description + + config_load 'lldpd' + config_get lldp_description 'config' 'lldp_description' "$(find_release_info)" + + local ifaces + config_get ifaces 'config' 'interface' + + local iface ifnames="" + for iface in $ifaces; do + local ifname="" + if network_get_device ifname "$iface" || [ -e "/sys/class/net/$iface" ]; then + append ifnames "${ifname:-$iface}" "," + fi + done + + # Clear out the config file first + echo -n > "$LLDPD_CONF" + [ -n "$ifnames" ] && echo "configure system interface pattern" "$ifnames" >> "$LLDPD_CONF" + [ -n "$lldp_description" ] && echo "configure system description" "\"$lldp_description\"" >> "$LLDPD_CONF" + + # Since lldpd's sysconfdir is /tmp, we'll symlink /etc/lldpd.d to /tmp/$LLDPD_CONFS_DIR + [ -e $LLDPD_CONFS_DIR ] || ln -s /etc/lldpd.d $LLDPD_CONFS_DIR +} + +start_service() { + local enable_cdp local enable_fdp local enable_sonmp local enable_edp local lldp_class local lldp_location - local lldp_description local readonly_mode config_load 'lldpd' @@ -36,35 +65,24 @@ start_service() { config_get_bool enable_edp 'config' 'enable_edp' 0 config_get lldp_class 'config' 'lldp_class' config_get lldp_location 'config' 'lldp_location' - config_get lldp_description 'config' 'lldp_description' "$(find_release_info)" config_get_bool readonly_mode 'config' 'readonly_mode' 0 - local ifaces - config_get ifaces 'config' 'interface' - - local iface ifnames="" - for iface in $ifaces; do - local ifname="" - if network_get_device ifname "$iface" || [ -e "/sys/class/net/$iface" ]; then - append ifnames "${ifname:-$iface}" "," - fi - done - mkdir -p /var/run/lldp chown lldp:lldp /var/run/lldp + # When lldpd starts, it also loads up what we write in this config file + write_lldpd_conf + procd_open_instance procd_set_param command /usr/sbin/lldpd procd_append_param command -d # don't daemonize, procd will handle that for us - [ -n "$ifnames" ] && procd_append_param command -I "$ifnames" [ $enable_cdp -gt 0 ] && procd_append_param command '-c' [ $enable_fdp -gt 0 ] && procd_append_param command '-f' [ $enable_sonmp -gt 0 ] && procd_append_param command '-s' [ $enable_edp -gt 0 ] && procd_append_param command '-e' [ $readonly_mode -gt 0 ] && procd_append_param command '-r' [ -n "$lldp_class" ] && procd_append_param command -M "$lldp_class" - [ -n "$lldp_description" ] && procd_append_param command -S "$lldp_description" # set auto respawn behavior procd_set_param respawn @@ -83,7 +101,8 @@ reload_service() { # Custom TLVs are special and should be # reloaded from config during lldpd reload $LLDPCLI -u $LLDPSOCKET unconfigure lldp custom-tlv &> /dev/null - $LLDPCLI -u $LLDPSOCKET -c /etc/lldpd.conf -c /etc/lldpd.d &> /dev/null + write_lldpd_conf + $LLDPCLI -u $LLDPSOCKET -c $LLDPD_CONF -c $LLDPD_CONFS_DIR &> /dev/null # Broadcast update over the wire $LLDPCLI -u $LLDPSOCKET update &> /dev/null return 0