bd957b672bfc6b0d985d44ffbb7582c8ad5f972b
[openwrt/svn-archive/archive.git] / package / network / services / lldpd / files / lldpd.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2008-2012 OpenWrt.org
3
4 START=90
5
6 SERVICE_USE_PID=1
7
8 find_release_info()
9 {
10 [ -s /etc/openwrt_release ] && . /etc/openwrt_release
11 [ -z "$DISTRIB_DESCRIPTION" ] && [ -s /etc/openwrt_version ] && \
12 DISTRIB_DESCRIPTION="$(cat /etc/openwrt_version)"
13
14 echo "${DISTRIB_DESCRIPTION:-Unknown OpenWrt release} @ $(cat /proc/sys/kernel/hostname)"
15 }
16
17 start() {
18 . /lib/functions/network.sh
19
20 local enable_cdp
21 local enable_fdp
22 local enable_sonmp
23 local enable_edp
24 local lldp_class
25 local lldp_location
26 local lldp_description
27 local readonly_mode
28
29 config_load 'lldpd'
30 config_get_bool enable_cdp 'config' 'enable_cdp' 0
31 config_get_bool enable_fdp 'config' 'enable_fdp' 0
32 config_get_bool enable_sonmp 'config' 'enable_sonmp' 0
33 config_get_bool enable_edp 'config' 'enable_edp' 0
34 config_get lldp_class 'config' 'lldp_class'
35 config_get lldp_location 'config' 'lldp_location'
36 config_get lldp_description 'config' 'lldp_description' "$(find_release_info)"
37 config_get_bool readonly_mode 'config' 'readonly_mode' 0
38
39 local ifaces
40 config_get ifaces 'config' 'interface'
41
42 local iface ifnames=""
43 for iface in $ifaces; do
44 local ifname=""
45 if network_get_device ifname "$iface" || [ -e "/sys/class/net/$iface" ]; then
46 append ifnames "${ifname:-$iface}" ","
47 fi
48 done
49
50 mkdir -p /var/run/lldp
51 chown lldp:lldp /var/run/lldp
52
53 [ -n "$ifnames" ] && append args "-I $ifnames"
54 [ $enable_cdp -gt 0 ] && append args '-c'
55 [ $enable_fdp -gt 0 ] && append args '-f'
56 [ $enable_sonmp -gt 0 ] && append args '-s'
57 [ $enable_edp -gt 0 ] && append args '-e'
58 [ $readonly_mode -gt 0 ] && append args '-r'
59
60 service_start /usr/sbin/lldpd $args \
61 ${lldp_class:+ -M $lldp_class} \
62 ${lldp_description:+ -S "$lldp_description"}
63 }
64
65 stop() {
66 service_stop /usr/sbin/lldpd
67 rm -f /var/run/lldpd.socket /var/run/lldpd.pid
68 }