2b1b22366370ced1029db36826464929f4fe7c5c
[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
28 config_load 'lldpd'
29 config_get_bool enable_cdp 'config' 'enable_cdp' 0
30 config_get_bool enable_fdp 'config' 'enable_fdp' 0
31 config_get_bool enable_sonmp 'config' 'enable_sonmp' 0
32 config_get_bool enable_edp 'config' 'enable_edp' 0
33 config_get lldp_class 'config' 'lldp_class'
34 config_get lldp_location 'config' 'lldp_location'
35 config_get lldp_description 'config' 'lldp_description' "$(find_release_info)"
36
37 local ifaces
38 config_get ifaces 'config' 'interface'
39
40 local iface ifnames=""
41 for iface in $ifaces; do
42 local ifname=""
43 if network_get_device ifname "$iface" || [ -e "/sys/class/net/$iface" ]; then
44 append ifnames "${ifname:-$iface}" ","
45 fi
46 done
47
48 [ -n "$ifnames" ] && append args "-I $ifnames"
49 [ $enable_cdp -gt 0 ] && append args '-c'
50 [ $enable_fdp -gt 0 ] && append args '-f'
51 [ $enable_sonmp -gt 0 ] && append args '-s'
52 [ $enable_edp -gt 0 ] && append args '-e'
53
54 mkdir -p /var/run/lldp
55 chown lldp:lldp /var/run/lldp
56
57 service_start /usr/sbin/lldpd $args \
58 ${lldp_class:+ -M $lldp_class} \
59 ${lldp_description:+ -S "$lldp_description"}
60
61 [ -n "$lldp_location" ] && {
62 sleep 1
63 /usr/sbin/lldpctl -L "$lldp_location" > /dev/null 2>&1
64 }
65 }
66
67 stop() {
68 service_stop /usr/sbin/lldpd
69 rm -f /var/run/lldpd.socket /var/run/lldpd.pid
70 }