summaryrefslogtreecommitdiff
path: root/package/network/services/lldpd/files/lldpd.init
blob: 4b49cbd5204fbaf7250be3a02b991a037a6bfacc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/sh /etc/rc.common
# Copyright (C) 2008-2012 OpenWrt.org

START=90

SERVICE_USE_PID=1

find_release_info()
{
	[ -s /etc/openwrt_release ] && . /etc/openwrt_release
	[ -z "$DISTRIB_DESCRIPTION" ] && [ -s /etc/openwrt_version ] && \
		DISTRIB_DESCRIPTION="$(cat /etc/openwrt_version)"

	echo "${DISTRIB_DESCRIPTION:-Unknown OpenWrt release} @ $(cat /proc/sys/kernel/hostname)"
}

start() {
	. /lib/functions/network.sh

	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'
	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
	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

	[ -n "$ifnames" ] && append args "-I $ifnames"
	[ $enable_cdp -gt 0 ] && append args '-c'
	[ $enable_fdp -gt 0 ] && append args '-f'
	[ $enable_sonmp -gt 0 ] && append args '-s'
	[ $enable_edp -gt 0 ] && append args '-e'
	[ $readonly_mode -gt 0 ] && append args '-r'

	mkdir -p /var/run/lldp
	chown lldp:lldp /var/run/lldp

	service_start /usr/sbin/lldpd $args \
		${lldp_class:+ -M $lldp_class} \
		${lldp_description:+ -S "$lldp_description"}
}

stop() {
	service_stop /usr/sbin/lldpd
	rm -f /var/run/lldpd.socket /var/run/lldpd.pid
}