summaryrefslogtreecommitdiffstats
path: root/src/daemon
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon')
-rw-r--r--src/daemon/Makefile.am180
-rw-r--r--src/daemon/Makefile.in1545
-rw-r--r--src/daemon/agent.c1939
-rw-r--r--src/daemon/agent.h35
-rw-r--r--src/daemon/agent_priv.c243
-rw-r--r--src/daemon/bitmap.c63
-rw-r--r--src/daemon/client.c700
-rw-r--r--src/daemon/dmi-dummy.c57
-rw-r--r--src/daemon/dmi-freebsd.c82
-rw-r--r--src/daemon/dmi-linux.c90
-rw-r--r--src/daemon/dmi-openbsd.c73
-rw-r--r--src/daemon/dmi-osx.c109
-rw-r--r--src/daemon/dtrace2systemtap.awk25
-rw-r--r--src/daemon/event.c911
-rw-r--r--src/daemon/forward-bsd.c31
-rw-r--r--src/daemon/forward-linux.c59
-rw-r--r--src/daemon/forward-solaris.c27
-rw-r--r--src/daemon/frame.c66
-rw-r--r--src/daemon/frame.h102
-rw-r--r--src/daemon/interfaces-bpf.c117
-rw-r--r--src/daemon/interfaces-bsd.c641
-rw-r--r--src/daemon/interfaces-linux.c1046
-rw-r--r--src/daemon/interfaces-solaris.c174
-rw-r--r--src/daemon/interfaces.c764
-rw-r--r--src/daemon/lldp-tlv.h83
-rw-r--r--src/daemon/lldpd.8.in424
-rw-r--r--src/daemon/lldpd.c2020
-rw-r--r--src/daemon/lldpd.h429
-rw-r--r--src/daemon/lldpd.service.in22
-rw-r--r--src/daemon/lldpd.sysusers.conf.in6
-rw-r--r--src/daemon/main.c17
-rw-r--r--src/daemon/netlink.c993
-rw-r--r--src/daemon/pattern.c80
-rw-r--r--src/daemon/priv-bsd.c202
-rw-r--r--src/daemon/priv-linux.c337
-rw-r--r--src/daemon/priv-seccomp.c210
-rw-r--r--src/daemon/priv.c761
-rw-r--r--src/daemon/privsep.c26
-rw-r--r--src/daemon/privsep_fd.c129
-rw-r--r--src/daemon/privsep_io.c100
-rw-r--r--src/daemon/probes.d115
-rw-r--r--src/daemon/protocols/cdp.c711
-rw-r--r--src/daemon/protocols/cdp.h70
-rw-r--r--src/daemon/protocols/edp.c514
-rw-r--r--src/daemon/protocols/edp.h41
-rw-r--r--src/daemon/protocols/lldp.c1315
-rw-r--r--src/daemon/protocols/sonmp.c410
-rw-r--r--src/daemon/protocols/sonmp.h42
-rw-r--r--src/daemon/trace.h8
-rw-r--r--src/daemon/usr.sbin.lldpd.in65
50 files changed, 18209 insertions, 0 deletions
diff --git a/src/daemon/Makefile.am b/src/daemon/Makefile.am
new file mode 100644
index 0000000..42240a4
--- /dev/null
+++ b/src/daemon/Makefile.am
@@ -0,0 +1,180 @@
+AM_CFLAGS = -I $(top_srcdir)/include $(LLDP_CFLAGS)
+AM_CPPFLAGS = $(LLDP_CPPFLAGS)
+AM_LDFLAGS = $(LLDP_LDFLAGS)
+BUILT_SOURCES =
+CLEANFILES =
+
+sbin_PROGRAMS = lldpd
+man_MANS = lldpd.8
+
+noinst_LTLIBRARIES = liblldpd.la
+
+## Convenience library for lldpd and tests
+nodist_liblldpd_la_SOURCES =
+liblldpd_la_SOURCES = \
+ frame.h frame.c \
+ lldp-tlv.h \
+ client.c \
+ priv.c \
+ privsep.c privsep_io.c privsep_fd.c \
+ interfaces.c \
+ event.c lldpd.c \
+ pattern.c \
+ bitmap.c \
+ probes.d trace.h \
+ protocols/lldp.c \
+ protocols/cdp.c \
+ protocols/cdp.h \
+ protocols/sonmp.c \
+ protocols/sonmp.h \
+ protocols/edp.c \
+ protocols/edp.h
+liblldpd_la_CFLAGS = $(AM_CFLAGS) @libevent_CFLAGS@ @libcap_CFLAGS@
+liblldpd_la_CPPFLAGS = $(AM_CPPFLAGS) -DSYSCONFDIR='"$(sysconfdir)"' -DLLDPCLI_PATH='"$(sbindir)/lldpcli"'
+liblldpd_la_LIBADD = \
+ $(top_builddir)/src/libcommon-daemon-client.la \
+ $(top_builddir)/src/libcommon-daemon-lib.la @libevent_LIBS@ @libcap_LIBS@
+
+## lldpd
+lldpd_SOURCES = main.c
+lldpd_LDFLAGS = $(AM_LDFLAGS) $(LLDP_BIN_LDFLAGS)
+lldpd_LDADD = liblldpd.la @libevent_LDFLAGS@
+
+if HOST_OS_LINUX
+liblldpd_la_SOURCES += \
+ forward-linux.c \
+ interfaces-linux.c \
+ netlink.c \
+ dmi-linux.c \
+ priv-linux.c
+endif
+if HOST_OS_DRAGONFLY
+liblldpd_la_SOURCES += \
+ forward-bsd.c \
+ interfaces-bpf.c \
+ interfaces-bsd.c \
+ dmi-dummy.c \
+ priv-bsd.c
+endif
+if HOST_OS_FREEBSD
+liblldpd_la_SOURCES += \
+ forward-bsd.c \
+ interfaces-bpf.c \
+ interfaces-bsd.c \
+ dmi-freebsd.c \
+ priv-bsd.c
+endif
+if HOST_OS_OPENBSD
+liblldpd_la_SOURCES += \
+ interfaces-bpf.c \
+ forward-bsd.c \
+ interfaces-bsd.c \
+ dmi-openbsd.c \
+ priv-bsd.c
+endif
+if HOST_OS_NETBSD
+liblldpd_la_SOURCES += \
+ forward-bsd.c \
+ interfaces-bpf.c \
+ interfaces-bsd.c \
+ dmi-dummy.c \
+ priv-bsd.c
+endif
+if HOST_OS_OSX
+liblldpd_la_SOURCES += \
+ forward-bsd.c \
+ interfaces-bpf.c \
+ interfaces-bsd.c \
+ dmi-osx.c \
+ priv-bsd.c
+liblldpd_la_LDFLAGS = $(AM_LDFLAGS)
+liblldpd_la_LDFLAGS += -framework Foundation
+liblldpd_la_LDFLAGS += -framework CoreFoundation -framework IOKit
+liblldpd_la_LDFLAGS += -framework IOKit
+endif
+if HOST_OS_SOLARIS
+liblldpd_la_SOURCES += \
+ forward-solaris.c \
+ interfaces-bpf.c \
+ interfaces-solaris.c \
+ dmi-dummy.c \
+ priv-bsd.c
+endif
+
+# seccomp support
+if USE_SECCOMP
+BUILT_SOURCES += syscall-names.h
+CLEANFILES += syscall-names.h syscall-names.h.tmp
+syscall-names.h:
+ $(AM_V_GEN)
+ $(AM_V_at)echo "#include <sys/syscall.h>" | $(CPP) -dM - > $@.tmp ;\
+ echo "static const char *syscall_names[] = {" > $@ ;\
+ grep '^#define __NR_' $@.tmp | \
+ LC_ALL=C sed -r -n -e 's/^\#define[ \t]+__NR_([a-z0-9_]+)[ \t]+([0-9]+)(.*)/ [\2] = "\1",/p' >> $@ ;\
+ echo "};" >> $@ ;\
+ rm $@.tmp
+nodist_liblldpd_la_SOURCES += syscall-names.h
+liblldpd_la_SOURCES += priv-seccomp.c
+liblldpd_la_CFLAGS += @libseccomp_CFLAGS@
+liblldpd_la_LIBADD += @libseccomp_LIBS@
+endif
+
+# Add SNMP support if needed
+if USE_SNMP
+noinst_LTLIBRARIES += liblldpd-snmp.la
+liblldpd_snmp_la_SOURCES = agent.c agent_priv.c agent.h
+liblldpd_snmp_la_CFLAGS = $(liblldpd_la_CFLAGS) @NETSNMP_CFLAGS@
+liblldpd_snmp_la_CPPFLAGS = $(liblldpd_la_CPPFLAGS)
+liblldpd_la_LIBADD += liblldpd-snmp.la
+lldpd_LDADD += @NETSNMP_LIBS@
+endif
+
+## Systemtap/DTrace
+EXTRA_DIST = dtrace2systemtap.awk
+if ENABLE_SYSTEMTAP
+BUILT_SOURCES += probes.h
+CLEANFILES += probes.h lldpd.stp
+probes.h: probes.d
+ $(AM_V_GEN)
+ $(AM_V_at)$(DTRACE) -C -h -s $< -o $@
+probes.o: probes.d
+ $(AM_V_GEN)
+ $(AM_V_at)$(DTRACE) -C -G -s $< -o $@
+lldpd_LDADD += probes.o
+
+lldpd.stp: probes.d $(srcdir)/dtrace2systemtap.awk $(top_builddir)/config.status
+ $(AM_V_GEN)$(AWK) -f $(srcdir)/dtrace2systemtap.awk -v sbindir=$(sbindir) $< > $@ || ( rm -f $@ ; exit 1 )
+tapsetdir = $(datadir)/systemtap/tapset
+tapset_DATA = lldpd.stp
+endif
+
+## libevent
+if LIBEVENT_EMBEDDED
+event.c: $(top_builddir)/libevent/libevent.la
+$(top_builddir)/libevent/libevent.la: $(top_srcdir)/libevent/*.c $(top_srcdir)/libevent/*.h
+ (cd $(top_builddir)/libevent && $(MAKE))
+endif
+
+## systemd service file
+if HAVE_SYSTEMDSYSTEMUNITDIR
+systemdsystemunit_DATA = lldpd.service
+endif
+
+if HAVE_SYSUSERSDIR
+sysusers_DATA = lldpd.sysusers.conf
+endif
+
+if HOST_OS_LINUX
+if HAVE_APPARMORDIR
+apparmor_DATA = usr.sbin.lldpd
+endif
+endif
+
+TEMPLATES = lldpd.8 lldpd.service lldpd.sysusers.conf usr.sbin.lldpd
+EXTRA_DIST += lldpd.8.in lldpd.service.in lldpd.sysusers.conf.in usr.sbin.lldpd.in
+CLEANFILES += $(TEMPLATES)
+lldpd.8: lldpd.8.in
+lldpd.service: lldpd.service.in
+lldpd.sysusers.conf: lldpd.sysusers.conf.in
+usr.sbin.lldpd: usr.sbin.lldpd.in
+include $(top_srcdir)/edit.am
diff --git a/src/daemon/Makefile.in b/src/daemon/Makefile.in
new file mode 100644
index 0000000..397289e
--- /dev/null
+++ b/src/daemon/Makefile.in
@@ -0,0 +1,1545 @@
+# Makefile.in generated by automake 1.16.5 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994-2021 Free Software Foundation, Inc.
+
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+
+
+VPATH = @srcdir@
+am__is_gnu_make = { \
+ if test -z '$(MAKELEVEL)'; then \
+ false; \
+ elif test -n '$(MAKE_HOST)'; then \
+ true; \
+ elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
+ true; \
+ else \
+ false; \
+ fi; \
+}
+am__make_running_with_option = \
+ case $${target_option-} in \
+ ?) ;; \
+ *) echo "am__make_running_with_option: internal error: invalid" \
+ "target option '$${target_option-}' specified" >&2; \
+ exit 1;; \
+ esac; \
+ has_opt=no; \
+ sane_makeflags=$$MAKEFLAGS; \
+ if $(am__is_gnu_make); then \
+ sane_makeflags=$$MFLAGS; \
+ else \
+ case $$MAKEFLAGS in \
+ *\\[\ \ ]*) \
+ bs=\\; \
+ sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
+ | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \
+ esac; \
+ fi; \
+ skip_next=no; \
+ strip_trailopt () \
+ { \
+ flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
+ }; \
+ for flg in $$sane_makeflags; do \
+ test $$skip_next = yes && { skip_next=no; continue; }; \
+ case $$flg in \
+ *=*|--*) continue;; \
+ -*I) strip_trailopt 'I'; skip_next=yes;; \
+ -*I?*) strip_trailopt 'I';; \
+ -*O) strip_trailopt 'O'; skip_next=yes;; \
+ -*O?*) strip_trailopt 'O';; \
+ -*l) strip_trailopt 'l'; skip_next=yes;; \
+ -*l?*) strip_trailopt 'l';; \
+ -[dEDm]) skip_next=yes;; \
+ -[JT]) skip_next=yes;; \
+ esac; \
+ case $$flg in \
+ *$$target_option*) has_opt=yes; break;; \
+ esac; \
+ done; \
+ test $$has_opt = yes
+am__make_dryrun = (target_option=n; $(am__make_running_with_option))
+am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+sbin_PROGRAMS = lldpd$(EXEEXT)
+@HOST_OS_LINUX_TRUE@am__append_1 = \
+@HOST_OS_LINUX_TRUE@ forward-linux.c \
+@HOST_OS_LINUX_TRUE@ interfaces-linux.c \
+@HOST_OS_LINUX_TRUE@ netlink.c \
+@HOST_OS_LINUX_TRUE@ dmi-linux.c \
+@HOST_OS_LINUX_TRUE@ priv-linux.c
+
+@HOST_OS_DRAGONFLY_TRUE@am__append_2 = \
+@HOST_OS_DRAGONFLY_TRUE@ forward-bsd.c \
+@HOST_OS_DRAGONFLY_TRUE@ interfaces-bpf.c \
+@HOST_OS_DRAGONFLY_TRUE@ interfaces-bsd.c \
+@HOST_OS_DRAGONFLY_TRUE@ dmi-dummy.c \
+@HOST_OS_DRAGONFLY_TRUE@ priv-bsd.c
+
+@HOST_OS_FREEBSD_TRUE@am__append_3 = \
+@HOST_OS_FREEBSD_TRUE@ forward-bsd.c \
+@HOST_OS_FREEBSD_TRUE@ interfaces-bpf.c \
+@HOST_OS_FREEBSD_TRUE@ interfaces-bsd.c \
+@HOST_OS_FREEBSD_TRUE@ dmi-freebsd.c \
+@HOST_OS_FREEBSD_TRUE@ priv-bsd.c
+
+@HOST_OS_OPENBSD_TRUE@am__append_4 = \
+@HOST_OS_OPENBSD_TRUE@ interfaces-bpf.c \
+@HOST_OS_OPENBSD_TRUE@ forward-bsd.c \
+@HOST_OS_OPENBSD_TRUE@ interfaces-bsd.c \
+@HOST_OS_OPENBSD_TRUE@ dmi-openbsd.c \
+@HOST_OS_OPENBSD_TRUE@ priv-bsd.c
+
+@HOST_OS_NETBSD_TRUE@am__append_5 = \
+@HOST_OS_NETBSD_TRUE@ forward-bsd.c \
+@HOST_OS_NETBSD_TRUE@ interfaces-bpf.c \
+@HOST_OS_NETBSD_TRUE@ interfaces-bsd.c \
+@HOST_OS_NETBSD_TRUE@ dmi-dummy.c \
+@HOST_OS_NETBSD_TRUE@ priv-bsd.c
+
+@HOST_OS_OSX_TRUE@am__append_6 = \
+@HOST_OS_OSX_TRUE@ forward-bsd.c \
+@HOST_OS_OSX_TRUE@ interfaces-bpf.c \
+@HOST_OS_OSX_TRUE@ interfaces-bsd.c \
+@HOST_OS_OSX_TRUE@ dmi-osx.c \
+@HOST_OS_OSX_TRUE@ priv-bsd.c
+
+@HOST_OS_SOLARIS_TRUE@am__append_7 = \
+@HOST_OS_SOLARIS_TRUE@ forward-solaris.c \
+@HOST_OS_SOLARIS_TRUE@ interfaces-bpf.c \
+@HOST_OS_SOLARIS_TRUE@ interfaces-solaris.c \
+@HOST_OS_SOLARIS_TRUE@ dmi-dummy.c \
+@HOST_OS_SOLARIS_TRUE@ priv-bsd.c
+
+
+# seccomp support
+@USE_SECCOMP_TRUE@am__append_8 = syscall-names.h
+@USE_SECCOMP_TRUE@am__append_9 = syscall-names.h syscall-names.h.tmp
+@USE_SECCOMP_TRUE@am__append_10 = syscall-names.h
+@USE_SECCOMP_TRUE@am__append_11 = priv-seccomp.c
+@USE_SECCOMP_TRUE@am__append_12 = @libseccomp_CFLAGS@
+@USE_SECCOMP_TRUE@am__append_13 = @libseccomp_LIBS@
+
+# Add SNMP support if needed
+@USE_SNMP_TRUE@am__append_14 = liblldpd-snmp.la
+@USE_SNMP_TRUE@am__append_15 = liblldpd-snmp.la
+@USE_SNMP_TRUE@am__append_16 = @NETSNMP_LIBS@
+@ENABLE_SYSTEMTAP_TRUE@am__append_17 = probes.h
+@ENABLE_SYSTEMTAP_TRUE@am__append_18 = probes.h lldpd.stp
+@ENABLE_SYSTEMTAP_TRUE@am__append_19 = probes.o
+subdir = src/daemon
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4/alignof.m4 \
+ $(top_srcdir)/m4/args.m4 \
+ $(top_srcdir)/m4/ax_build_date_epoch.m4 \
+ $(top_srcdir)/m4/ax_cflags_gcc_option.m4 \
+ $(top_srcdir)/m4/ax_ld_check_flag.m4 \
+ $(top_srcdir)/m4/ax_lib_readline.m4 \
+ $(top_srcdir)/m4/ax_prog_doxygen.m4 \
+ $(top_srcdir)/m4/config_subdirs.m4 \
+ $(top_srcdir)/m4/ld-version-script.m4 \
+ $(top_srcdir)/m4/libcap.m4 $(top_srcdir)/m4/libevent.m4 \
+ $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \
+ $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \
+ $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/os.m4 \
+ $(top_srcdir)/m4/progname.m4 $(top_srcdir)/m4/seccomp.m4 \
+ $(top_srcdir)/m4/snmp.m4 $(top_srcdir)/m4/stdint.m4 \
+ $(top_srcdir)/m4/systemtap.m4 $(top_srcdir)/m4/xml2.m4 \
+ $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+am__installdirs = "$(DESTDIR)$(sbindir)" "$(DESTDIR)$(man8dir)" \
+ "$(DESTDIR)$(apparmordir)" "$(DESTDIR)$(systemdsystemunitdir)" \
+ "$(DESTDIR)$(sysusersdir)" "$(DESTDIR)$(tapsetdir)"
+PROGRAMS = $(sbin_PROGRAMS)
+LTLIBRARIES = $(noinst_LTLIBRARIES)
+liblldpd_snmp_la_LIBADD =
+am__liblldpd_snmp_la_SOURCES_DIST = agent.c agent_priv.c agent.h
+@USE_SNMP_TRUE@am_liblldpd_snmp_la_OBJECTS = \
+@USE_SNMP_TRUE@ liblldpd_snmp_la-agent.lo \
+@USE_SNMP_TRUE@ liblldpd_snmp_la-agent_priv.lo
+liblldpd_snmp_la_OBJECTS = $(am_liblldpd_snmp_la_OBJECTS)
+AM_V_lt = $(am__v_lt_@AM_V@)
+am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
+am__v_lt_0 = --silent
+am__v_lt_1 =
+liblldpd_snmp_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
+ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
+ $(liblldpd_snmp_la_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \
+ -o $@
+@USE_SNMP_TRUE@am_liblldpd_snmp_la_rpath =
+am__DEPENDENCIES_1 =
+liblldpd_la_DEPENDENCIES = \
+ $(top_builddir)/src/libcommon-daemon-client.la \
+ $(top_builddir)/src/libcommon-daemon-lib.la \
+ $(am__DEPENDENCIES_1) $(am__append_15)
+am__liblldpd_la_SOURCES_DIST = frame.h frame.c lldp-tlv.h client.c \
+ priv.c privsep.c privsep_io.c privsep_fd.c interfaces.c \
+ event.c lldpd.c pattern.c bitmap.c probes.d trace.h \
+ protocols/lldp.c protocols/cdp.c protocols/cdp.h \
+ protocols/sonmp.c protocols/sonmp.h protocols/edp.c \
+ protocols/edp.h forward-linux.c interfaces-linux.c netlink.c \
+ dmi-linux.c priv-linux.c forward-bsd.c interfaces-bpf.c \
+ interfaces-bsd.c dmi-dummy.c priv-bsd.c dmi-freebsd.c \
+ dmi-openbsd.c dmi-osx.c forward-solaris.c interfaces-solaris.c \
+ priv-seccomp.c
+am__dirstamp = $(am__leading_dot)dirstamp
+@HOST_OS_LINUX_TRUE@am__objects_1 = liblldpd_la-forward-linux.lo \
+@HOST_OS_LINUX_TRUE@ liblldpd_la-interfaces-linux.lo \
+@HOST_OS_LINUX_TRUE@ liblldpd_la-netlink.lo \
+@HOST_OS_LINUX_TRUE@ liblldpd_la-dmi-linux.lo \
+@HOST_OS_LINUX_TRUE@ liblldpd_la-priv-linux.lo
+@HOST_OS_DRAGONFLY_TRUE@am__objects_2 = liblldpd_la-forward-bsd.lo \
+@HOST_OS_DRAGONFLY_TRUE@ liblldpd_la-interfaces-bpf.lo \
+@HOST_OS_DRAGONFLY_TRUE@ liblldpd_la-interfaces-bsd.lo \
+@HOST_OS_DRAGONFLY_TRUE@ liblldpd_la-dmi-dummy.lo \
+@HOST_OS_DRAGONFLY_TRUE@ liblldpd_la-priv-bsd.lo
+@HOST_OS_FREEBSD_TRUE@am__objects_3 = liblldpd_la-forward-bsd.lo \
+@HOST_OS_FREEBSD_TRUE@ liblldpd_la-interfaces-bpf.lo \
+@HOST_OS_FREEBSD_TRUE@ liblldpd_la-interfaces-bsd.lo \
+@HOST_OS_FREEBSD_TRUE@ liblldpd_la-dmi-freebsd.lo \
+@HOST_OS_FREEBSD_TRUE@ liblldpd_la-priv-bsd.lo
+@HOST_OS_OPENBSD_TRUE@am__objects_4 = liblldpd_la-interfaces-bpf.lo \
+@HOST_OS_OPENBSD_TRUE@ liblldpd_la-forward-bsd.lo \
+@HOST_OS_OPENBSD_TRUE@ liblldpd_la-interfaces-bsd.lo \
+@HOST_OS_OPENBSD_TRUE@ liblldpd_la-dmi-openbsd.lo \
+@HOST_OS_OPENBSD_TRUE@ liblldpd_la-priv-bsd.lo
+@HOST_OS_NETBSD_TRUE@am__objects_5 = liblldpd_la-forward-bsd.lo \
+@HOST_OS_NETBSD_TRUE@ liblldpd_la-interfaces-bpf.lo \
+@HOST_OS_NETBSD_TRUE@ liblldpd_la-interfaces-bsd.lo \
+@HOST_OS_NETBSD_TRUE@ liblldpd_la-dmi-dummy.lo \
+@HOST_OS_NETBSD_TRUE@ liblldpd_la-priv-bsd.lo
+@HOST_OS_OSX_TRUE@am__objects_6 = liblldpd_la-forward-bsd.lo \
+@HOST_OS_OSX_TRUE@ liblldpd_la-interfaces-bpf.lo \
+@HOST_OS_OSX_TRUE@ liblldpd_la-interfaces-bsd.lo \
+@HOST_OS_OSX_TRUE@ liblldpd_la-dmi-osx.lo \
+@HOST_OS_OSX_TRUE@ liblldpd_la-priv-bsd.lo
+@HOST_OS_SOLARIS_TRUE@am__objects_7 = liblldpd_la-forward-solaris.lo \
+@HOST_OS_SOLARIS_TRUE@ liblldpd_la-interfaces-bpf.lo \
+@HOST_OS_SOLARIS_TRUE@ liblldpd_la-interfaces-solaris.lo \
+@HOST_OS_SOLARIS_TRUE@ liblldpd_la-dmi-dummy.lo \
+@HOST_OS_SOLARIS_TRUE@ liblldpd_la-priv-bsd.lo
+@USE_SECCOMP_TRUE@am__objects_8 = liblldpd_la-priv-seccomp.lo
+am_liblldpd_la_OBJECTS = liblldpd_la-frame.lo liblldpd_la-client.lo \
+ liblldpd_la-priv.lo liblldpd_la-privsep.lo \
+ liblldpd_la-privsep_io.lo liblldpd_la-privsep_fd.lo \
+ liblldpd_la-interfaces.lo liblldpd_la-event.lo \
+ liblldpd_la-lldpd.lo liblldpd_la-pattern.lo \
+ liblldpd_la-bitmap.lo protocols/liblldpd_la-lldp.lo \
+ protocols/liblldpd_la-cdp.lo protocols/liblldpd_la-sonmp.lo \
+ protocols/liblldpd_la-edp.lo $(am__objects_1) $(am__objects_2) \
+ $(am__objects_3) $(am__objects_4) $(am__objects_5) \
+ $(am__objects_6) $(am__objects_7) $(am__objects_8)
+am__objects_9 =
+nodist_liblldpd_la_OBJECTS = $(am__objects_9)
+liblldpd_la_OBJECTS = $(am_liblldpd_la_OBJECTS) \
+ $(nodist_liblldpd_la_OBJECTS)
+liblldpd_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(liblldpd_la_CFLAGS) \
+ $(CFLAGS) $(liblldpd_la_LDFLAGS) $(LDFLAGS) -o $@
+am_lldpd_OBJECTS = main.$(OBJEXT)
+lldpd_OBJECTS = $(am_lldpd_OBJECTS)
+lldpd_DEPENDENCIES = liblldpd.la $(am__DEPENDENCIES_1) \
+ $(am__append_19)
+lldpd_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+ $(lldpd_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_P = $(am__v_P_@AM_V@)
+am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
+am__v_P_0 = false
+am__v_P_1 = :
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
+am__v_GEN_0 = @echo " GEN " $@;
+am__v_GEN_1 =
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
+am__v_at_0 = @
+am__v_at_1 =
+DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__maybe_remake_depfiles = depfiles
+am__depfiles_remade = ./$(DEPDIR)/liblldpd_la-bitmap.Plo \
+ ./$(DEPDIR)/liblldpd_la-client.Plo \
+ ./$(DEPDIR)/liblldpd_la-dmi-dummy.Plo \
+ ./$(DEPDIR)/liblldpd_la-dmi-freebsd.Plo \
+ ./$(DEPDIR)/liblldpd_la-dmi-linux.Plo \
+ ./$(DEPDIR)/liblldpd_la-dmi-openbsd.Plo \
+ ./$(DEPDIR)/liblldpd_la-dmi-osx.Plo \
+ ./$(DEPDIR)/liblldpd_la-event.Plo \
+ ./$(DEPDIR)/liblldpd_la-forward-bsd.Plo \
+ ./$(DEPDIR)/liblldpd_la-forward-linux.Plo \
+ ./$(DEPDIR)/liblldpd_la-forward-solaris.Plo \
+ ./$(DEPDIR)/liblldpd_la-frame.Plo \
+ ./$(DEPDIR)/liblldpd_la-interfaces-bpf.Plo \
+ ./$(DEPDIR)/liblldpd_la-interfaces-bsd.Plo \
+ ./$(DEPDIR)/liblldpd_la-interfaces-linux.Plo \
+ ./$(DEPDIR)/liblldpd_la-interfaces-solaris.Plo \
+ ./$(DEPDIR)/liblldpd_la-interfaces.Plo \
+ ./$(DEPDIR)/liblldpd_la-lldpd.Plo \
+ ./$(DEPDIR)/liblldpd_la-netlink.Plo \
+ ./$(DEPDIR)/liblldpd_la-pattern.Plo \
+ ./$(DEPDIR)/liblldpd_la-priv-bsd.Plo \
+ ./$(DEPDIR)/liblldpd_la-priv-linux.Plo \
+ ./$(DEPDIR)/liblldpd_la-priv-seccomp.Plo \
+ ./$(DEPDIR)/liblldpd_la-priv.Plo \
+ ./$(DEPDIR)/liblldpd_la-privsep.Plo \
+ ./$(DEPDIR)/liblldpd_la-privsep_fd.Plo \
+ ./$(DEPDIR)/liblldpd_la-privsep_io.Plo \
+ ./$(DEPDIR)/liblldpd_snmp_la-agent.Plo \
+ ./$(DEPDIR)/liblldpd_snmp_la-agent_priv.Plo \
+ ./$(DEPDIR)/main.Po protocols/$(DEPDIR)/liblldpd_la-cdp.Plo \
+ protocols/$(DEPDIR)/liblldpd_la-edp.Plo \
+ protocols/$(DEPDIR)/liblldpd_la-lldp.Plo \
+ protocols/$(DEPDIR)/liblldpd_la-sonmp.Plo
+am__mv = mv -f
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
+ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+ $(AM_CFLAGS) $(CFLAGS)
+AM_V_CC = $(am__v_CC_@AM_V@)
+am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
+am__v_CC_0 = @echo " CC " $@;
+am__v_CC_1 =
+CCLD = $(CC)
+LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+ $(AM_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_CCLD = $(am__v_CCLD_@AM_V@)
+am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
+am__v_CCLD_0 = @echo " CCLD " $@;
+am__v_CCLD_1 =
+SOURCES = $(liblldpd_snmp_la_SOURCES) $(liblldpd_la_SOURCES) \
+ $(nodist_liblldpd_la_SOURCES) $(lldpd_SOURCES)
+DIST_SOURCES = $(am__liblldpd_snmp_la_SOURCES_DIST) \
+ $(am__liblldpd_la_SOURCES_DIST) $(lldpd_SOURCES)
+am__can_run_installinfo = \
+ case $$AM_UPDATE_INFO_DIR in \
+ n|no|NO) false;; \
+ *) (install-info --version) >/dev/null 2>&1;; \
+ esac
+am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
+am__vpath_adj = case $$p in \
+ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
+ *) f=$$p;; \
+ esac;
+am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
+am__install_max = 40
+am__nobase_strip_setup = \
+ srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
+am__nobase_strip = \
+ for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
+am__nobase_list = $(am__nobase_strip_setup); \
+ for p in $$list; do echo "$$p $$p"; done | \
+ sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
+ $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
+ if (++n[$$2] == $(am__install_max)) \
+ { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
+ END { for (dir in files) print dir, files[dir] }'
+am__base_list = \
+ sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
+ sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__uninstall_files_from_dir = { \
+ test -z "$$files" \
+ || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
+ || { echo " ( cd '$$dir' && rm -f" $$files ")"; \
+ $(am__cd) "$$dir" && rm -f $$files; }; \
+ }
+man8dir = $(mandir)/man8
+NROFF = nroff
+MANS = $(man_MANS)
+DATA = $(apparmor_DATA) $(systemdsystemunit_DATA) $(sysusers_DATA) \
+ $(tapset_DATA)
+am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
+# Read a list of newline-separated strings from the standard input,
+# and print each of them once, without duplicates. Input order is
+# *not* preserved.
+am__uniquify_input = $(AWK) '\
+ BEGIN { nonempty = 0; } \
+ { items[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in items) print i; }; } \
+'
+# Make sure the list of sources is unique. This is necessary because,
+# e.g., the same source file might be shared among _SOURCES variables
+# for different programs/libraries.
+am__define_uniq_tagged_files = \
+ list='$(am__tagged_files)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | $(am__uniquify_input)`
+am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp \
+ $(top_srcdir)/edit.am
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
+APPARMORDIR = @APPARMORDIR@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CONFIGURE_ARGS = @CONFIGURE_ARGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CSCOPE = @CSCOPE@
+CTAGS = @CTAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+DOXYGEN_PAPER_SIZE = @DOXYGEN_PAPER_SIZE@
+DSYMUTIL = @DSYMUTIL@
+DTRACE = @DTRACE@
+DUMPBIN = @DUMPBIN@
+DX_CONFIG = @DX_CONFIG@
+DX_DOCDIR = @DX_DOCDIR@
+DX_DOT = @DX_DOT@
+DX_DOXYGEN = @DX_DOXYGEN@
+DX_DVIPS = @DX_DVIPS@
+DX_EGREP = @DX_EGREP@
+DX_ENV = @DX_ENV@
+DX_FLAG_chi = @DX_FLAG_chi@
+DX_FLAG_chm = @DX_FLAG_chm@
+DX_FLAG_doc = @DX_FLAG_doc@
+DX_FLAG_dot = @DX_FLAG_dot@
+DX_FLAG_html = @DX_FLAG_html@
+DX_FLAG_man = @DX_FLAG_man@
+DX_FLAG_pdf = @DX_FLAG_pdf@
+DX_FLAG_ps = @DX_FLAG_ps@
+DX_FLAG_rtf = @DX_FLAG_rtf@
+DX_FLAG_xml = @DX_FLAG_xml@
+DX_HHC = @DX_HHC@
+DX_LATEX = @DX_LATEX@
+DX_MAKEINDEX = @DX_MAKEINDEX@
+DX_PDFLATEX = @DX_PDFLATEX@
+DX_PERL = @DX_PERL@
+DX_PROJECT = @DX_PROJECT@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+ETAGS = @ETAGS@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+FILECMD = @FILECMD@
+FUZZ_DECODE_ENGINE = @FUZZ_DECODE_ENGINE@
+GREP = @GREP@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LAUNCHDDAEMONSDIR = @LAUNCHDDAEMONSDIR@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LIPO = @LIPO@
+LLDPD_CTL_SOCKET = @LLDPD_CTL_SOCKET@
+LLDPD_PID_FILE = @LLDPD_PID_FILE@
+LLDP_BIN_LDFLAGS = @LLDP_BIN_LDFLAGS@
+LLDP_CFLAGS = @LLDP_CFLAGS@
+LLDP_CPPFLAGS = @LLDP_CPPFLAGS@
+LLDP_LDFLAGS = @LLDP_LDFLAGS@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@
+MAINT = @MAINT@
+MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
+MKDIR_P = @MKDIR_P@
+NETLINK_MAX_RECEIVE_BUFSIZE = @NETLINK_MAX_RECEIVE_BUFSIZE@
+NETLINK_RECEIVE_BUFSIZE = @NETLINK_RECEIVE_BUFSIZE@
+NETLINK_SEND_BUFSIZE = @NETLINK_SEND_BUFSIZE@
+NETSNMP_CFLAGS = @NETSNMP_CFLAGS@
+NETSNMP_CONFIG = @NETSNMP_CONFIG@
+NETSNMP_LIBS = @NETSNMP_LIBS@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PKG_CONFIG = @PKG_CONFIG@
+PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
+PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
+PRIVSEP_CHROOT = @PRIVSEP_CHROOT@
+PRIVSEP_GROUP = @PRIVSEP_GROUP@
+PRIVSEP_USER = @PRIVSEP_USER@
+RANLIB = @RANLIB@
+READLINE_LIBS = @READLINE_LIBS@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+SYSTEMDSYSTEMUNITDIR = @SYSTEMDSYSTEMUNITDIR@
+SYSUSERSDIR = @SYSUSERSDIR@
+VERSION = @VERSION@
+XML2_CONFIG = @XML2_CONFIG@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+apparmordir = @apparmordir@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+check_CFLAGS = @check_CFLAGS@
+check_LIBS = @check_LIBS@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+launchddaemonsdir = @launchddaemonsdir@
+libbsd_CFLAGS = @libbsd_CFLAGS@
+libbsd_LIBS = @libbsd_LIBS@
+libcap_CFLAGS = @libcap_CFLAGS@
+libcap_LIBS = @libcap_LIBS@
+libdir = @libdir@
+libevent_CFLAGS = @libevent_CFLAGS@
+libevent_LDFLAGS = @libevent_LDFLAGS@
+libevent_LIBS = @libevent_LIBS@
+libexecdir = @libexecdir@
+libseccomp_CFLAGS = @libseccomp_CFLAGS@
+libseccomp_LIBS = @libseccomp_LIBS@
+libxml2_CFLAGS = @libxml2_CFLAGS@
+libxml2_LIBS = @libxml2_LIBS@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+pkgconfigdir = @pkgconfigdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+runstatedir = @runstatedir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+systemdsystemunitdir = @systemdsystemunitdir@
+sysusersdir = @sysusersdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+AM_CFLAGS = -I $(top_srcdir)/include $(LLDP_CFLAGS)
+AM_CPPFLAGS = $(LLDP_CPPFLAGS)
+AM_LDFLAGS = $(LLDP_LDFLAGS)
+BUILT_SOURCES = $(am__append_8) $(am__append_17)
+CLEANFILES = $(am__append_9) $(am__append_18) $(TEMPLATES)
+man_MANS = lldpd.8
+noinst_LTLIBRARIES = liblldpd.la $(am__append_14)
+nodist_liblldpd_la_SOURCES = $(am__append_10)
+liblldpd_la_SOURCES = frame.h frame.c lldp-tlv.h client.c priv.c \
+ privsep.c privsep_io.c privsep_fd.c interfaces.c event.c \
+ lldpd.c pattern.c bitmap.c probes.d trace.h protocols/lldp.c \
+ protocols/cdp.c protocols/cdp.h protocols/sonmp.c \
+ protocols/sonmp.h protocols/edp.c protocols/edp.h \
+ $(am__append_1) $(am__append_2) $(am__append_3) \
+ $(am__append_4) $(am__append_5) $(am__append_6) \
+ $(am__append_7) $(am__append_11)
+liblldpd_la_CFLAGS = $(AM_CFLAGS) @libevent_CFLAGS@ @libcap_CFLAGS@ \
+ $(am__append_12)
+liblldpd_la_CPPFLAGS = $(AM_CPPFLAGS) -DSYSCONFDIR='"$(sysconfdir)"' -DLLDPCLI_PATH='"$(sbindir)/lldpcli"'
+liblldpd_la_LIBADD = $(top_builddir)/src/libcommon-daemon-client.la \
+ $(top_builddir)/src/libcommon-daemon-lib.la @libevent_LIBS@ \
+ @libcap_LIBS@ $(am__append_13) $(am__append_15)
+lldpd_SOURCES = main.c
+lldpd_LDFLAGS = $(AM_LDFLAGS) $(LLDP_BIN_LDFLAGS)
+lldpd_LDADD = liblldpd.la @libevent_LDFLAGS@ $(am__append_16) \
+ $(am__append_19)
+@HOST_OS_OSX_TRUE@liblldpd_la_LDFLAGS = $(AM_LDFLAGS) -framework \
+@HOST_OS_OSX_TRUE@ Foundation -framework CoreFoundation \
+@HOST_OS_OSX_TRUE@ -framework IOKit -framework IOKit
+@USE_SNMP_TRUE@liblldpd_snmp_la_SOURCES = agent.c agent_priv.c agent.h
+@USE_SNMP_TRUE@liblldpd_snmp_la_CFLAGS = $(liblldpd_la_CFLAGS) @NETSNMP_CFLAGS@
+@USE_SNMP_TRUE@liblldpd_snmp_la_CPPFLAGS = $(liblldpd_la_CPPFLAGS)
+EXTRA_DIST = dtrace2systemtap.awk lldpd.8.in lldpd.service.in \
+ lldpd.sysusers.conf.in usr.sbin.lldpd.in
+@ENABLE_SYSTEMTAP_TRUE@tapsetdir = $(datadir)/systemtap/tapset
+@ENABLE_SYSTEMTAP_TRUE@tapset_DATA = lldpd.stp
+@HAVE_SYSTEMDSYSTEMUNITDIR_TRUE@systemdsystemunit_DATA = lldpd.service
+@HAVE_SYSUSERSDIR_TRUE@sysusers_DATA = lldpd.sysusers.conf
+@HAVE_APPARMORDIR_TRUE@@HOST_OS_LINUX_TRUE@apparmor_DATA = usr.sbin.lldpd
+TEMPLATES = lldpd.8 lldpd.service lldpd.sysusers.conf usr.sbin.lldpd
+edit = $(SED) \
+ -e 's|@bindir[@]|$(bindir)|g' \
+ -e 's|@sbindir[@]|$(sbindir)|g' \
+ -e 's|@sysconfdir[@]|$(sysconfdir)|g' \
+ -e 's|@pkgdatadir[@]|$(pkgdatadir)|g' \
+ -e 's|@libdir[@]|$(libdir)|g' \
+ -e 's|@srcdir[@]|$(srcdir)|g' \
+ -e 's|@top_builddir[@]|$(top_builddir)|g' \
+ -e 's|@includedir[@]|$(includedir)|g' \
+ -e 's|@exec_prefix[@]|$(exec_prefix)|g' \
+ -e 's|@prefix[@]|$(prefix)|g' \
+ -e 's|@VERSION[@]|$(VERSION)|g' \
+ -e 's|@PACKAGE[@]|$(PACKAGE)|g' \
+ -e 's|@PACKAGE_NAME[@]|$(PACKAGE_NAME)|g' \
+ -e 's|@PACKAGE_URL[@]|$(PACKAGE_URL)|g' \
+ -e 's|@PRIVSEP_USER[@]|$(PRIVSEP_USER)|g' \
+ -e 's|@PRIVSEP_GROUP[@]|$(PRIVSEP_GROUP)|g' \
+ -e 's|@PRIVSEP_CHROOT[@]|$(PRIVSEP_CHROOT)|g' \
+ -e 's|@LLDPD_PID_FILE[@]|$(LLDPD_PID_FILE)|g' \
+ -e 's|@LLDPD_CTL_SOCKET[@]|$(LLDPD_CTL_SOCKET)|g' \
+ -e 's|@PRIVSEP_CHROOT[@]|$(PRIVSEP_CHROOT)|g'
+
+all: $(BUILT_SOURCES)
+ $(MAKE) $(AM_MAKEFLAGS) all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(top_srcdir)/edit.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/daemon/Makefile'; \
+ $(am__cd) $(top_srcdir) && \
+ $(AUTOMAKE) --foreign src/daemon/Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ @case '$?' in \
+ *config.status*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+ *) \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \
+ esac;
+$(top_srcdir)/edit.am $(am__empty):
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+install-sbinPROGRAMS: $(sbin_PROGRAMS)
+ @$(NORMAL_INSTALL)
+ @list='$(sbin_PROGRAMS)'; test -n "$(sbindir)" || list=; \
+ if test -n "$$list"; then \
+ echo " $(MKDIR_P) '$(DESTDIR)$(sbindir)'"; \
+ $(MKDIR_P) "$(DESTDIR)$(sbindir)" || exit 1; \
+ fi; \
+ for p in $$list; do echo "$$p $$p"; done | \
+ sed 's/$(EXEEXT)$$//' | \
+ while read p p1; do if test -f $$p \
+ || test -f $$p1 \
+ ; then echo "$$p"; echo "$$p"; else :; fi; \
+ done | \
+ sed -e 'p;s,.*/,,;n;h' \
+ -e 's|.*|.|' \
+ -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \
+ sed 'N;N;N;s,\n, ,g' | \
+ $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \
+ { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \
+ if ($$2 == $$4) files[d] = files[d] " " $$1; \
+ else { print "f", $$3 "/" $$4, $$1; } } \
+ END { for (d in files) print "f", d, files[d] }' | \
+ while read type dir files; do \
+ if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \
+ test -z "$$files" || { \
+ echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(sbindir)$$dir'"; \
+ $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(sbindir)$$dir" || exit $$?; \
+ } \
+ ; done
+
+uninstall-sbinPROGRAMS:
+ @$(NORMAL_UNINSTALL)
+ @list='$(sbin_PROGRAMS)'; test -n "$(sbindir)" || list=; \
+ files=`for p in $$list; do echo "$$p"; done | \
+ sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \
+ -e 's/$$/$(EXEEXT)/' \
+ `; \
+ test -n "$$list" || exit 0; \
+ echo " ( cd '$(DESTDIR)$(sbindir)' && rm -f" $$files ")"; \
+ cd "$(DESTDIR)$(sbindir)" && rm -f $$files
+
+clean-sbinPROGRAMS:
+ @list='$(sbin_PROGRAMS)'; test -n "$$list" || exit 0; \
+ echo " rm -f" $$list; \
+ rm -f $$list || exit $$?; \
+ test -n "$(EXEEXT)" || exit 0; \
+ list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
+ echo " rm -f" $$list; \
+ rm -f $$list
+
+clean-noinstLTLIBRARIES:
+ -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES)
+ @list='$(noinst_LTLIBRARIES)'; \
+ locs=`for p in $$list; do echo $$p; done | \
+ sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \
+ sort -u`; \
+ test -z "$$locs" || { \
+ echo rm -f $${locs}; \
+ rm -f $${locs}; \
+ }
+
+liblldpd-snmp.la: $(liblldpd_snmp_la_OBJECTS) $(liblldpd_snmp_la_DEPENDENCIES) $(EXTRA_liblldpd_snmp_la_DEPENDENCIES)
+ $(AM_V_CCLD)$(liblldpd_snmp_la_LINK) $(am_liblldpd_snmp_la_rpath) $(liblldpd_snmp_la_OBJECTS) $(liblldpd_snmp_la_LIBADD) $(LIBS)
+protocols/$(am__dirstamp):
+ @$(MKDIR_P) protocols
+ @: > protocols/$(am__dirstamp)
+protocols/$(DEPDIR)/$(am__dirstamp):
+ @$(MKDIR_P) protocols/$(DEPDIR)
+ @: > protocols/$(DEPDIR)/$(am__dirstamp)
+protocols/liblldpd_la-lldp.lo: protocols/$(am__dirstamp) \
+ protocols/$(DEPDIR)/$(am__dirstamp)
+protocols/liblldpd_la-cdp.lo: protocols/$(am__dirstamp) \
+ protocols/$(DEPDIR)/$(am__dirstamp)
+protocols/liblldpd_la-sonmp.lo: protocols/$(am__dirstamp) \
+ protocols/$(DEPDIR)/$(am__dirstamp)
+protocols/liblldpd_la-edp.lo: protocols/$(am__dirstamp) \
+ protocols/$(DEPDIR)/$(am__dirstamp)
+
+liblldpd.la: $(liblldpd_la_OBJECTS) $(liblldpd_la_DEPENDENCIES) $(EXTRA_liblldpd_la_DEPENDENCIES)
+ $(AM_V_CCLD)$(liblldpd_la_LINK) $(liblldpd_la_OBJECTS) $(liblldpd_la_LIBADD) $(LIBS)
+
+lldpd$(EXEEXT): $(lldpd_OBJECTS) $(lldpd_DEPENDENCIES) $(EXTRA_lldpd_DEPENDENCIES)
+ @rm -f lldpd$(EXEEXT)
+ $(AM_V_CCLD)$(lldpd_LINK) $(lldpd_OBJECTS) $(lldpd_LDADD) $(LIBS)
+
+mostlyclean-compile:
+ -rm -f *.$(OBJEXT)
+ -rm -f protocols/*.$(OBJEXT)
+ -rm -f protocols/*.lo
+
+distclean-compile:
+ -rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liblldpd_la-bitmap.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liblldpd_la-client.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liblldpd_la-dmi-dummy.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liblldpd_la-dmi-freebsd.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liblldpd_la-dmi-linux.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liblldpd_la-dmi-openbsd.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liblldpd_la-dmi-osx.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liblldpd_la-event.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liblldpd_la-forward-bsd.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liblldpd_la-forward-linux.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liblldpd_la-forward-solaris.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liblldpd_la-frame.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liblldpd_la-interfaces-bpf.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liblldpd_la-interfaces-bsd.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liblldpd_la-interfaces-linux.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liblldpd_la-interfaces-solaris.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liblldpd_la-interfaces.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liblldpd_la-lldpd.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liblldpd_la-netlink.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liblldpd_la-pattern.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liblldpd_la-priv-bsd.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liblldpd_la-priv-linux.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liblldpd_la-priv-seccomp.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liblldpd_la-priv.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liblldpd_la-privsep.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liblldpd_la-privsep_fd.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liblldpd_la-privsep_io.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liblldpd_snmp_la-agent.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liblldpd_snmp_la-agent_priv.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@protocols/$(DEPDIR)/liblldpd_la-cdp.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@protocols/$(DEPDIR)/liblldpd_la-edp.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@protocols/$(DEPDIR)/liblldpd_la-lldp.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@protocols/$(DEPDIR)/liblldpd_la-sonmp.Plo@am__quote@ # am--include-marker
+
+$(am__depfiles_remade):
+ @$(MKDIR_P) $(@D)
+ @echo '# dummy' >$@-t && $(am__mv) $@-t $@
+
+am--depfiles: $(am__depfiles_remade)
+
+.c.o:
+@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
+@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\
+@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $<
+
+.c.obj:
+@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\
+@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ `$(CYGPATH_W) '$<'` &&\
+@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
+
+.c.lo:
+@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\
+@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\
+@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
+
+liblldpd_snmp_la-agent.lo: agent.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_snmp_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_snmp_la_CFLAGS) $(CFLAGS) -MT liblldpd_snmp_la-agent.lo -MD -MP -MF $(DEPDIR)/liblldpd_snmp_la-agent.Tpo -c -o liblldpd_snmp_la-agent.lo `test -f 'agent.c' || echo '$(srcdir)/'`agent.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/liblldpd_snmp_la-agent.Tpo $(DEPDIR)/liblldpd_snmp_la-agent.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='agent.c' object='liblldpd_snmp_la-agent.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_snmp_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_snmp_la_CFLAGS) $(CFLAGS) -c -o liblldpd_snmp_la-agent.lo `test -f 'agent.c' || echo '$(srcdir)/'`agent.c
+
+liblldpd_snmp_la-agent_priv.lo: agent_priv.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_snmp_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_snmp_la_CFLAGS) $(CFLAGS) -MT liblldpd_snmp_la-agent_priv.lo -MD -MP -MF $(DEPDIR)/liblldpd_snmp_la-agent_priv.Tpo -c -o liblldpd_snmp_la-agent_priv.lo `test -f 'agent_priv.c' || echo '$(srcdir)/'`agent_priv.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/liblldpd_snmp_la-agent_priv.Tpo $(DEPDIR)/liblldpd_snmp_la-agent_priv.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='agent_priv.c' object='liblldpd_snmp_la-agent_priv.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_snmp_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_snmp_la_CFLAGS) $(CFLAGS) -c -o liblldpd_snmp_la-agent_priv.lo `test -f 'agent_priv.c' || echo '$(srcdir)/'`agent_priv.c
+
+liblldpd_la-frame.lo: frame.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -MT liblldpd_la-frame.lo -MD -MP -MF $(DEPDIR)/liblldpd_la-frame.Tpo -c -o liblldpd_la-frame.lo `test -f 'frame.c' || echo '$(srcdir)/'`frame.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/liblldpd_la-frame.Tpo $(DEPDIR)/liblldpd_la-frame.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='frame.c' object='liblldpd_la-frame.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -c -o liblldpd_la-frame.lo `test -f 'frame.c' || echo '$(srcdir)/'`frame.c
+
+liblldpd_la-client.lo: client.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -MT liblldpd_la-client.lo -MD -MP -MF $(DEPDIR)/liblldpd_la-client.Tpo -c -o liblldpd_la-client.lo `test -f 'client.c' || echo '$(srcdir)/'`client.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/liblldpd_la-client.Tpo $(DEPDIR)/liblldpd_la-client.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='client.c' object='liblldpd_la-client.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -c -o liblldpd_la-client.lo `test -f 'client.c' || echo '$(srcdir)/'`client.c
+
+liblldpd_la-priv.lo: priv.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -MT liblldpd_la-priv.lo -MD -MP -MF $(DEPDIR)/liblldpd_la-priv.Tpo -c -o liblldpd_la-priv.lo `test -f 'priv.c' || echo '$(srcdir)/'`priv.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/liblldpd_la-priv.Tpo $(DEPDIR)/liblldpd_la-priv.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='priv.c' object='liblldpd_la-priv.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -c -o liblldpd_la-priv.lo `test -f 'priv.c' || echo '$(srcdir)/'`priv.c
+
+liblldpd_la-privsep.lo: privsep.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -MT liblldpd_la-privsep.lo -MD -MP -MF $(DEPDIR)/liblldpd_la-privsep.Tpo -c -o liblldpd_la-privsep.lo `test -f 'privsep.c' || echo '$(srcdir)/'`privsep.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/liblldpd_la-privsep.Tpo $(DEPDIR)/liblldpd_la-privsep.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='privsep.c' object='liblldpd_la-privsep.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -c -o liblldpd_la-privsep.lo `test -f 'privsep.c' || echo '$(srcdir)/'`privsep.c
+
+liblldpd_la-privsep_io.lo: privsep_io.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -MT liblldpd_la-privsep_io.lo -MD -MP -MF $(DEPDIR)/liblldpd_la-privsep_io.Tpo -c -o liblldpd_la-privsep_io.lo `test -f 'privsep_io.c' || echo '$(srcdir)/'`privsep_io.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/liblldpd_la-privsep_io.Tpo $(DEPDIR)/liblldpd_la-privsep_io.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='privsep_io.c' object='liblldpd_la-privsep_io.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -c -o liblldpd_la-privsep_io.lo `test -f 'privsep_io.c' || echo '$(srcdir)/'`privsep_io.c
+
+liblldpd_la-privsep_fd.lo: privsep_fd.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -MT liblldpd_la-privsep_fd.lo -MD -MP -MF $(DEPDIR)/liblldpd_la-privsep_fd.Tpo -c -o liblldpd_la-privsep_fd.lo `test -f 'privsep_fd.c' || echo '$(srcdir)/'`privsep_fd.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/liblldpd_la-privsep_fd.Tpo $(DEPDIR)/liblldpd_la-privsep_fd.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='privsep_fd.c' object='liblldpd_la-privsep_fd.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -c -o liblldpd_la-privsep_fd.lo `test -f 'privsep_fd.c' || echo '$(srcdir)/'`privsep_fd.c
+
+liblldpd_la-interfaces.lo: interfaces.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -MT liblldpd_la-interfaces.lo -MD -MP -MF $(DEPDIR)/liblldpd_la-interfaces.Tpo -c -o liblldpd_la-interfaces.lo `test -f 'interfaces.c' || echo '$(srcdir)/'`interfaces.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/liblldpd_la-interfaces.Tpo $(DEPDIR)/liblldpd_la-interfaces.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='interfaces.c' object='liblldpd_la-interfaces.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -c -o liblldpd_la-interfaces.lo `test -f 'interfaces.c' || echo '$(srcdir)/'`interfaces.c
+
+liblldpd_la-event.lo: event.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -MT liblldpd_la-event.lo -MD -MP -MF $(DEPDIR)/liblldpd_la-event.Tpo -c -o liblldpd_la-event.lo `test -f 'event.c' || echo '$(srcdir)/'`event.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/liblldpd_la-event.Tpo $(DEPDIR)/liblldpd_la-event.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='event.c' object='liblldpd_la-event.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -c -o liblldpd_la-event.lo `test -f 'event.c' || echo '$(srcdir)/'`event.c
+
+liblldpd_la-lldpd.lo: lldpd.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -MT liblldpd_la-lldpd.lo -MD -MP -MF $(DEPDIR)/liblldpd_la-lldpd.Tpo -c -o liblldpd_la-lldpd.lo `test -f 'lldpd.c' || echo '$(srcdir)/'`lldpd.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/liblldpd_la-lldpd.Tpo $(DEPDIR)/liblldpd_la-lldpd.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='lldpd.c' object='liblldpd_la-lldpd.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -c -o liblldpd_la-lldpd.lo `test -f 'lldpd.c' || echo '$(srcdir)/'`lldpd.c
+
+liblldpd_la-pattern.lo: pattern.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -MT liblldpd_la-pattern.lo -MD -MP -MF $(DEPDIR)/liblldpd_la-pattern.Tpo -c -o liblldpd_la-pattern.lo `test -f 'pattern.c' || echo '$(srcdir)/'`pattern.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/liblldpd_la-pattern.Tpo $(DEPDIR)/liblldpd_la-pattern.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='pattern.c' object='liblldpd_la-pattern.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -c -o liblldpd_la-pattern.lo `test -f 'pattern.c' || echo '$(srcdir)/'`pattern.c
+
+liblldpd_la-bitmap.lo: bitmap.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -MT liblldpd_la-bitmap.lo -MD -MP -MF $(DEPDIR)/liblldpd_la-bitmap.Tpo -c -o liblldpd_la-bitmap.lo `test -f 'bitmap.c' || echo '$(srcdir)/'`bitmap.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/liblldpd_la-bitmap.Tpo $(DEPDIR)/liblldpd_la-bitmap.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='bitmap.c' object='liblldpd_la-bitmap.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -c -o liblldpd_la-bitmap.lo `test -f 'bitmap.c' || echo '$(srcdir)/'`bitmap.c
+
+protocols/liblldpd_la-lldp.lo: protocols/lldp.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -MT protocols/liblldpd_la-lldp.lo -MD -MP -MF protocols/$(DEPDIR)/liblldpd_la-lldp.Tpo -c -o protocols/liblldpd_la-lldp.lo `test -f 'protocols/lldp.c' || echo '$(srcdir)/'`protocols/lldp.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) protocols/$(DEPDIR)/liblldpd_la-lldp.Tpo protocols/$(DEPDIR)/liblldpd_la-lldp.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='protocols/lldp.c' object='protocols/liblldpd_la-lldp.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -c -o protocols/liblldpd_la-lldp.lo `test -f 'protocols/lldp.c' || echo '$(srcdir)/'`protocols/lldp.c
+
+protocols/liblldpd_la-cdp.lo: protocols/cdp.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -MT protocols/liblldpd_la-cdp.lo -MD -MP -MF protocols/$(DEPDIR)/liblldpd_la-cdp.Tpo -c -o protocols/liblldpd_la-cdp.lo `test -f 'protocols/cdp.c' || echo '$(srcdir)/'`protocols/cdp.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) protocols/$(DEPDIR)/liblldpd_la-cdp.Tpo protocols/$(DEPDIR)/liblldpd_la-cdp.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='protocols/cdp.c' object='protocols/liblldpd_la-cdp.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -c -o protocols/liblldpd_la-cdp.lo `test -f 'protocols/cdp.c' || echo '$(srcdir)/'`protocols/cdp.c
+
+protocols/liblldpd_la-sonmp.lo: protocols/sonmp.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -MT protocols/liblldpd_la-sonmp.lo -MD -MP -MF protocols/$(DEPDIR)/liblldpd_la-sonmp.Tpo -c -o protocols/liblldpd_la-sonmp.lo `test -f 'protocols/sonmp.c' || echo '$(srcdir)/'`protocols/sonmp.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) protocols/$(DEPDIR)/liblldpd_la-sonmp.Tpo protocols/$(DEPDIR)/liblldpd_la-sonmp.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='protocols/sonmp.c' object='protocols/liblldpd_la-sonmp.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -c -o protocols/liblldpd_la-sonmp.lo `test -f 'protocols/sonmp.c' || echo '$(srcdir)/'`protocols/sonmp.c
+
+protocols/liblldpd_la-edp.lo: protocols/edp.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -MT protocols/liblldpd_la-edp.lo -MD -MP -MF protocols/$(DEPDIR)/liblldpd_la-edp.Tpo -c -o protocols/liblldpd_la-edp.lo `test -f 'protocols/edp.c' || echo '$(srcdir)/'`protocols/edp.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) protocols/$(DEPDIR)/liblldpd_la-edp.Tpo protocols/$(DEPDIR)/liblldpd_la-edp.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='protocols/edp.c' object='protocols/liblldpd_la-edp.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -c -o protocols/liblldpd_la-edp.lo `test -f 'protocols/edp.c' || echo '$(srcdir)/'`protocols/edp.c
+
+liblldpd_la-forward-linux.lo: forward-linux.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -MT liblldpd_la-forward-linux.lo -MD -MP -MF $(DEPDIR)/liblldpd_la-forward-linux.Tpo -c -o liblldpd_la-forward-linux.lo `test -f 'forward-linux.c' || echo '$(srcdir)/'`forward-linux.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/liblldpd_la-forward-linux.Tpo $(DEPDIR)/liblldpd_la-forward-linux.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='forward-linux.c' object='liblldpd_la-forward-linux.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -c -o liblldpd_la-forward-linux.lo `test -f 'forward-linux.c' || echo '$(srcdir)/'`forward-linux.c
+
+liblldpd_la-interfaces-linux.lo: interfaces-linux.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -MT liblldpd_la-interfaces-linux.lo -MD -MP -MF $(DEPDIR)/liblldpd_la-interfaces-linux.Tpo -c -o liblldpd_la-interfaces-linux.lo `test -f 'interfaces-linux.c' || echo '$(srcdir)/'`interfaces-linux.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/liblldpd_la-interfaces-linux.Tpo $(DEPDIR)/liblldpd_la-interfaces-linux.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='interfaces-linux.c' object='liblldpd_la-interfaces-linux.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -c -o liblldpd_la-interfaces-linux.lo `test -f 'interfaces-linux.c' || echo '$(srcdir)/'`interfaces-linux.c
+
+liblldpd_la-netlink.lo: netlink.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -MT liblldpd_la-netlink.lo -MD -MP -MF $(DEPDIR)/liblldpd_la-netlink.Tpo -c -o liblldpd_la-netlink.lo `test -f 'netlink.c' || echo '$(srcdir)/'`netlink.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/liblldpd_la-netlink.Tpo $(DEPDIR)/liblldpd_la-netlink.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='netlink.c' object='liblldpd_la-netlink.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -c -o liblldpd_la-netlink.lo `test -f 'netlink.c' || echo '$(srcdir)/'`netlink.c
+
+liblldpd_la-dmi-linux.lo: dmi-linux.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -MT liblldpd_la-dmi-linux.lo -MD -MP -MF $(DEPDIR)/liblldpd_la-dmi-linux.Tpo -c -o liblldpd_la-dmi-linux.lo `test -f 'dmi-linux.c' || echo '$(srcdir)/'`dmi-linux.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/liblldpd_la-dmi-linux.Tpo $(DEPDIR)/liblldpd_la-dmi-linux.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='dmi-linux.c' object='liblldpd_la-dmi-linux.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -c -o liblldpd_la-dmi-linux.lo `test -f 'dmi-linux.c' || echo '$(srcdir)/'`dmi-linux.c
+
+liblldpd_la-priv-linux.lo: priv-linux.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -MT liblldpd_la-priv-linux.lo -MD -MP -MF $(DEPDIR)/liblldpd_la-priv-linux.Tpo -c -o liblldpd_la-priv-linux.lo `test -f 'priv-linux.c' || echo '$(srcdir)/'`priv-linux.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/liblldpd_la-priv-linux.Tpo $(DEPDIR)/liblldpd_la-priv-linux.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='priv-linux.c' object='liblldpd_la-priv-linux.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -c -o liblldpd_la-priv-linux.lo `test -f 'priv-linux.c' || echo '$(srcdir)/'`priv-linux.c
+
+liblldpd_la-forward-bsd.lo: forward-bsd.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -MT liblldpd_la-forward-bsd.lo -MD -MP -MF $(DEPDIR)/liblldpd_la-forward-bsd.Tpo -c -o liblldpd_la-forward-bsd.lo `test -f 'forward-bsd.c' || echo '$(srcdir)/'`forward-bsd.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/liblldpd_la-forward-bsd.Tpo $(DEPDIR)/liblldpd_la-forward-bsd.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='forward-bsd.c' object='liblldpd_la-forward-bsd.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -c -o liblldpd_la-forward-bsd.lo `test -f 'forward-bsd.c' || echo '$(srcdir)/'`forward-bsd.c
+
+liblldpd_la-interfaces-bpf.lo: interfaces-bpf.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -MT liblldpd_la-interfaces-bpf.lo -MD -MP -MF $(DEPDIR)/liblldpd_la-interfaces-bpf.Tpo -c -o liblldpd_la-interfaces-bpf.lo `test -f 'interfaces-bpf.c' || echo '$(srcdir)/'`interfaces-bpf.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/liblldpd_la-interfaces-bpf.Tpo $(DEPDIR)/liblldpd_la-interfaces-bpf.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='interfaces-bpf.c' object='liblldpd_la-interfaces-bpf.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -c -o liblldpd_la-interfaces-bpf.lo `test -f 'interfaces-bpf.c' || echo '$(srcdir)/'`interfaces-bpf.c
+
+liblldpd_la-interfaces-bsd.lo: interfaces-bsd.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -MT liblldpd_la-interfaces-bsd.lo -MD -MP -MF $(DEPDIR)/liblldpd_la-interfaces-bsd.Tpo -c -o liblldpd_la-interfaces-bsd.lo `test -f 'interfaces-bsd.c' || echo '$(srcdir)/'`interfaces-bsd.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/liblldpd_la-interfaces-bsd.Tpo $(DEPDIR)/liblldpd_la-interfaces-bsd.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='interfaces-bsd.c' object='liblldpd_la-interfaces-bsd.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -c -o liblldpd_la-interfaces-bsd.lo `test -f 'interfaces-bsd.c' || echo '$(srcdir)/'`interfaces-bsd.c
+
+liblldpd_la-dmi-dummy.lo: dmi-dummy.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -MT liblldpd_la-dmi-dummy.lo -MD -MP -MF $(DEPDIR)/liblldpd_la-dmi-dummy.Tpo -c -o liblldpd_la-dmi-dummy.lo `test -f 'dmi-dummy.c' || echo '$(srcdir)/'`dmi-dummy.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/liblldpd_la-dmi-dummy.Tpo $(DEPDIR)/liblldpd_la-dmi-dummy.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='dmi-dummy.c' object='liblldpd_la-dmi-dummy.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -c -o liblldpd_la-dmi-dummy.lo `test -f 'dmi-dummy.c' || echo '$(srcdir)/'`dmi-dummy.c
+
+liblldpd_la-priv-bsd.lo: priv-bsd.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -MT liblldpd_la-priv-bsd.lo -MD -MP -MF $(DEPDIR)/liblldpd_la-priv-bsd.Tpo -c -o liblldpd_la-priv-bsd.lo `test -f 'priv-bsd.c' || echo '$(srcdir)/'`priv-bsd.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/liblldpd_la-priv-bsd.Tpo $(DEPDIR)/liblldpd_la-priv-bsd.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='priv-bsd.c' object='liblldpd_la-priv-bsd.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -c -o liblldpd_la-priv-bsd.lo `test -f 'priv-bsd.c' || echo '$(srcdir)/'`priv-bsd.c
+
+liblldpd_la-dmi-freebsd.lo: dmi-freebsd.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -MT liblldpd_la-dmi-freebsd.lo -MD -MP -MF $(DEPDIR)/liblldpd_la-dmi-freebsd.Tpo -c -o liblldpd_la-dmi-freebsd.lo `test -f 'dmi-freebsd.c' || echo '$(srcdir)/'`dmi-freebsd.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/liblldpd_la-dmi-freebsd.Tpo $(DEPDIR)/liblldpd_la-dmi-freebsd.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='dmi-freebsd.c' object='liblldpd_la-dmi-freebsd.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -c -o liblldpd_la-dmi-freebsd.lo `test -f 'dmi-freebsd.c' || echo '$(srcdir)/'`dmi-freebsd.c
+
+liblldpd_la-dmi-openbsd.lo: dmi-openbsd.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -MT liblldpd_la-dmi-openbsd.lo -MD -MP -MF $(DEPDIR)/liblldpd_la-dmi-openbsd.Tpo -c -o liblldpd_la-dmi-openbsd.lo `test -f 'dmi-openbsd.c' || echo '$(srcdir)/'`dmi-openbsd.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/liblldpd_la-dmi-openbsd.Tpo $(DEPDIR)/liblldpd_la-dmi-openbsd.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='dmi-openbsd.c' object='liblldpd_la-dmi-openbsd.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -c -o liblldpd_la-dmi-openbsd.lo `test -f 'dmi-openbsd.c' || echo '$(srcdir)/'`dmi-openbsd.c
+
+liblldpd_la-dmi-osx.lo: dmi-osx.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -MT liblldpd_la-dmi-osx.lo -MD -MP -MF $(DEPDIR)/liblldpd_la-dmi-osx.Tpo -c -o liblldpd_la-dmi-osx.lo `test -f 'dmi-osx.c' || echo '$(srcdir)/'`dmi-osx.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/liblldpd_la-dmi-osx.Tpo $(DEPDIR)/liblldpd_la-dmi-osx.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='dmi-osx.c' object='liblldpd_la-dmi-osx.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -c -o liblldpd_la-dmi-osx.lo `test -f 'dmi-osx.c' || echo '$(srcdir)/'`dmi-osx.c
+
+liblldpd_la-forward-solaris.lo: forward-solaris.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -MT liblldpd_la-forward-solaris.lo -MD -MP -MF $(DEPDIR)/liblldpd_la-forward-solaris.Tpo -c -o liblldpd_la-forward-solaris.lo `test -f 'forward-solaris.c' || echo '$(srcdir)/'`forward-solaris.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/liblldpd_la-forward-solaris.Tpo $(DEPDIR)/liblldpd_la-forward-solaris.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='forward-solaris.c' object='liblldpd_la-forward-solaris.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -c -o liblldpd_la-forward-solaris.lo `test -f 'forward-solaris.c' || echo '$(srcdir)/'`forward-solaris.c
+
+liblldpd_la-interfaces-solaris.lo: interfaces-solaris.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -MT liblldpd_la-interfaces-solaris.lo -MD -MP -MF $(DEPDIR)/liblldpd_la-interfaces-solaris.Tpo -c -o liblldpd_la-interfaces-solaris.lo `test -f 'interfaces-solaris.c' || echo '$(srcdir)/'`interfaces-solaris.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/liblldpd_la-interfaces-solaris.Tpo $(DEPDIR)/liblldpd_la-interfaces-solaris.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='interfaces-solaris.c' object='liblldpd_la-interfaces-solaris.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -c -o liblldpd_la-interfaces-solaris.lo `test -f 'interfaces-solaris.c' || echo '$(srcdir)/'`interfaces-solaris.c
+
+liblldpd_la-priv-seccomp.lo: priv-seccomp.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -MT liblldpd_la-priv-seccomp.lo -MD -MP -MF $(DEPDIR)/liblldpd_la-priv-seccomp.Tpo -c -o liblldpd_la-priv-seccomp.lo `test -f 'priv-seccomp.c' || echo '$(srcdir)/'`priv-seccomp.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/liblldpd_la-priv-seccomp.Tpo $(DEPDIR)/liblldpd_la-priv-seccomp.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='priv-seccomp.c' object='liblldpd_la-priv-seccomp.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(liblldpd_la_CPPFLAGS) $(CPPFLAGS) $(liblldpd_la_CFLAGS) $(CFLAGS) -c -o liblldpd_la-priv-seccomp.lo `test -f 'priv-seccomp.c' || echo '$(srcdir)/'`priv-seccomp.c
+
+mostlyclean-libtool:
+ -rm -f *.lo
+
+clean-libtool:
+ -rm -rf .libs _libs
+ -rm -rf protocols/.libs protocols/_libs
+install-man8: $(man_MANS)
+ @$(NORMAL_INSTALL)
+ @list1=''; \
+ list2='$(man_MANS)'; \
+ test -n "$(man8dir)" \
+ && test -n "`echo $$list1$$list2`" \
+ || exit 0; \
+ echo " $(MKDIR_P) '$(DESTDIR)$(man8dir)'"; \
+ $(MKDIR_P) "$(DESTDIR)$(man8dir)" || exit 1; \
+ { for i in $$list1; do echo "$$i"; done; \
+ if test -n "$$list2"; then \
+ for i in $$list2; do echo "$$i"; done \
+ | sed -n '/\.8[a-z]*$$/p'; \
+ fi; \
+ } | while read p; do \
+ if test -f $$p; then d=; else d="$(srcdir)/"; fi; \
+ echo "$$d$$p"; echo "$$p"; \
+ done | \
+ sed -e 'n;s,.*/,,;p;h;s,.*\.,,;s,^[^8][0-9a-z]*$$,8,;x' \
+ -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,' | \
+ sed 'N;N;s,\n, ,g' | { \
+ list=; while read file base inst; do \
+ if test "$$base" = "$$inst"; then list="$$list $$file"; else \
+ echo " $(INSTALL_DATA) '$$file' '$(DESTDIR)$(man8dir)/$$inst'"; \
+ $(INSTALL_DATA) "$$file" "$(DESTDIR)$(man8dir)/$$inst" || exit $$?; \
+ fi; \
+ done; \
+ for i in $$list; do echo "$$i"; done | $(am__base_list) | \
+ while read files; do \
+ test -z "$$files" || { \
+ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(man8dir)'"; \
+ $(INSTALL_DATA) $$files "$(DESTDIR)$(man8dir)" || exit $$?; }; \
+ done; }
+
+uninstall-man8:
+ @$(NORMAL_UNINSTALL)
+ @list=''; test -n "$(man8dir)" || exit 0; \
+ files=`{ for i in $$list; do echo "$$i"; done; \
+ l2='$(man_MANS)'; for i in $$l2; do echo "$$i"; done | \
+ sed -n '/\.8[a-z]*$$/p'; \
+ } | sed -e 's,.*/,,;h;s,.*\.,,;s,^[^8][0-9a-z]*$$,8,;x' \
+ -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,'`; \
+ dir='$(DESTDIR)$(man8dir)'; $(am__uninstall_files_from_dir)
+install-apparmorDATA: $(apparmor_DATA)
+ @$(NORMAL_INSTALL)
+ @list='$(apparmor_DATA)'; test -n "$(apparmordir)" || list=; \
+ if test -n "$$list"; then \
+ echo " $(MKDIR_P) '$(DESTDIR)$(apparmordir)'"; \
+ $(MKDIR_P) "$(DESTDIR)$(apparmordir)" || exit 1; \
+ fi; \
+ for p in $$list; do \
+ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+ echo "$$d$$p"; \
+ done | $(am__base_list) | \
+ while read files; do \
+ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(apparmordir)'"; \
+ $(INSTALL_DATA) $$files "$(DESTDIR)$(apparmordir)" || exit $$?; \
+ done
+
+uninstall-apparmorDATA:
+ @$(NORMAL_UNINSTALL)
+ @list='$(apparmor_DATA)'; test -n "$(apparmordir)" || list=; \
+ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+ dir='$(DESTDIR)$(apparmordir)'; $(am__uninstall_files_from_dir)
+install-systemdsystemunitDATA: $(systemdsystemunit_DATA)
+ @$(NORMAL_INSTALL)
+ @list='$(systemdsystemunit_DATA)'; test -n "$(systemdsystemunitdir)" || list=; \
+ if test -n "$$list"; then \
+ echo " $(MKDIR_P) '$(DESTDIR)$(systemdsystemunitdir)'"; \
+ $(MKDIR_P) "$(DESTDIR)$(systemdsystemunitdir)" || exit 1; \
+ fi; \
+ for p in $$list; do \
+ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+ echo "$$d$$p"; \
+ done | $(am__base_list) | \
+ while read files; do \
+ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(systemdsystemunitdir)'"; \
+ $(INSTALL_DATA) $$files "$(DESTDIR)$(systemdsystemunitdir)" || exit $$?; \
+ done
+
+uninstall-systemdsystemunitDATA:
+ @$(NORMAL_UNINSTALL)
+ @list='$(systemdsystemunit_DATA)'; test -n "$(systemdsystemunitdir)" || list=; \
+ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+ dir='$(DESTDIR)$(systemdsystemunitdir)'; $(am__uninstall_files_from_dir)
+install-sysusersDATA: $(sysusers_DATA)
+ @$(NORMAL_INSTALL)
+ @list='$(sysusers_DATA)'; test -n "$(sysusersdir)" || list=; \
+ if test -n "$$list"; then \
+ echo " $(MKDIR_P) '$(DESTDIR)$(sysusersdir)'"; \
+ $(MKDIR_P) "$(DESTDIR)$(sysusersdir)" || exit 1; \
+ fi; \
+ for p in $$list; do \
+ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+ echo "$$d$$p"; \
+ done | $(am__base_list) | \
+ while read files; do \
+ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(sysusersdir)'"; \
+ $(INSTALL_DATA) $$files "$(DESTDIR)$(sysusersdir)" || exit $$?; \
+ done
+
+uninstall-sysusersDATA:
+ @$(NORMAL_UNINSTALL)
+ @list='$(sysusers_DATA)'; test -n "$(sysusersdir)" || list=; \
+ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+ dir='$(DESTDIR)$(sysusersdir)'; $(am__uninstall_files_from_dir)
+install-tapsetDATA: $(tapset_DATA)
+ @$(NORMAL_INSTALL)
+ @list='$(tapset_DATA)'; test -n "$(tapsetdir)" || list=; \
+ if test -n "$$list"; then \
+ echo " $(MKDIR_P) '$(DESTDIR)$(tapsetdir)'"; \
+ $(MKDIR_P) "$(DESTDIR)$(tapsetdir)" || exit 1; \
+ fi; \
+ for p in $$list; do \
+ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+ echo "$$d$$p"; \
+ done | $(am__base_list) | \
+ while read files; do \
+ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(tapsetdir)'"; \
+ $(INSTALL_DATA) $$files "$(DESTDIR)$(tapsetdir)" || exit $$?; \
+ done
+
+uninstall-tapsetDATA:
+ @$(NORMAL_UNINSTALL)
+ @list='$(tapset_DATA)'; test -n "$(tapsetdir)" || list=; \
+ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+ dir='$(DESTDIR)$(tapsetdir)'; $(am__uninstall_files_from_dir)
+
+ID: $(am__tagged_files)
+ $(am__define_uniq_tagged_files); mkid -fID $$unique
+tags: tags-am
+TAGS: tags
+
+tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
+ set x; \
+ here=`pwd`; \
+ $(am__define_uniq_tagged_files); \
+ shift; \
+ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+ test -n "$$unique" || unique=$$empty_fix; \
+ if test $$# -gt 0; then \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ "$$@" $$unique; \
+ else \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ $$unique; \
+ fi; \
+ fi
+ctags: ctags-am
+
+CTAGS: ctags
+ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
+ $(am__define_uniq_tagged_files); \
+ test -z "$(CTAGS_ARGS)$$unique" \
+ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+ $$unique
+
+GTAGS:
+ here=`$(am__cd) $(top_builddir) && pwd` \
+ && $(am__cd) $(top_srcdir) \
+ && gtags -i $(GTAGS_ARGS) "$$here"
+cscopelist: cscopelist-am
+
+cscopelist-am: $(am__tagged_files)
+ list='$(am__tagged_files)'; \
+ case "$(srcdir)" in \
+ [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
+ *) sdir=$(subdir)/$(srcdir) ;; \
+ esac; \
+ for i in $$list; do \
+ if test -f "$$i"; then \
+ echo "$(subdir)/$$i"; \
+ else \
+ echo "$$sdir/$$i"; \
+ fi; \
+ done >> $(top_builddir)/cscope.files
+
+distclean-tags:
+ -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+distdir: $(BUILT_SOURCES)
+ $(MAKE) $(AM_MAKEFLAGS) distdir-am
+
+distdir-am: $(DISTFILES)
+ @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ list='$(DISTFILES)'; \
+ dist_files=`for file in $$list; do echo $$file; done | \
+ sed -e "s|^$$srcdirstrip/||;t" \
+ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+ case $$dist_files in \
+ */*) $(MKDIR_P) `echo "$$dist_files" | \
+ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+ sort -u` ;; \
+ esac; \
+ for file in $$dist_files; do \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ if test -d $$d/$$file; then \
+ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test -d "$(distdir)/$$file"; then \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+ else \
+ test -f "$(distdir)/$$file" \
+ || cp -p $$d/$$file "$(distdir)/$$file" \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+check: $(BUILT_SOURCES)
+ $(MAKE) $(AM_MAKEFLAGS) check-am
+all-am: Makefile $(PROGRAMS) $(LTLIBRARIES) $(MANS) $(DATA)
+installdirs:
+ for dir in "$(DESTDIR)$(sbindir)" "$(DESTDIR)$(man8dir)" "$(DESTDIR)$(apparmordir)" "$(DESTDIR)$(systemdsystemunitdir)" "$(DESTDIR)$(sysusersdir)" "$(DESTDIR)$(tapsetdir)"; do \
+ test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+ done
+install: $(BUILT_SOURCES)
+ $(MAKE) $(AM_MAKEFLAGS) install-am
+install-exec: $(BUILT_SOURCES)
+ $(MAKE) $(AM_MAKEFLAGS) install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+ if test -z '$(STRIP)'; then \
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ install; \
+ else \
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+ fi
+mostlyclean-generic:
+
+clean-generic:
+ -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
+
+distclean-generic:
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+ -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+ -rm -f protocols/$(DEPDIR)/$(am__dirstamp)
+ -rm -f protocols/$(am__dirstamp)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+ -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES)
+clean: clean-am
+
+clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \
+ clean-sbinPROGRAMS mostlyclean-am
+
+distclean: distclean-am
+ -rm -f ./$(DEPDIR)/liblldpd_la-bitmap.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-client.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-dmi-dummy.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-dmi-freebsd.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-dmi-linux.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-dmi-openbsd.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-dmi-osx.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-event.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-forward-bsd.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-forward-linux.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-forward-solaris.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-frame.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-interfaces-bpf.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-interfaces-bsd.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-interfaces-linux.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-interfaces-solaris.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-interfaces.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-lldpd.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-netlink.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-pattern.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-priv-bsd.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-priv-linux.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-priv-seccomp.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-priv.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-privsep.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-privsep_fd.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-privsep_io.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_snmp_la-agent.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_snmp_la-agent_priv.Plo
+ -rm -f ./$(DEPDIR)/main.Po
+ -rm -f protocols/$(DEPDIR)/liblldpd_la-cdp.Plo
+ -rm -f protocols/$(DEPDIR)/liblldpd_la-edp.Plo
+ -rm -f protocols/$(DEPDIR)/liblldpd_la-lldp.Plo
+ -rm -f protocols/$(DEPDIR)/liblldpd_la-sonmp.Plo
+ -rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+ distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am: install-apparmorDATA install-man \
+ install-systemdsystemunitDATA install-sysusersDATA \
+ install-tapsetDATA
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am: install-sbinPROGRAMS
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man: install-man8
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+ -rm -f ./$(DEPDIR)/liblldpd_la-bitmap.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-client.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-dmi-dummy.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-dmi-freebsd.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-dmi-linux.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-dmi-openbsd.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-dmi-osx.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-event.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-forward-bsd.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-forward-linux.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-forward-solaris.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-frame.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-interfaces-bpf.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-interfaces-bsd.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-interfaces-linux.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-interfaces-solaris.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-interfaces.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-lldpd.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-netlink.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-pattern.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-priv-bsd.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-priv-linux.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-priv-seccomp.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-priv.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-privsep.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-privsep_fd.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_la-privsep_io.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_snmp_la-agent.Plo
+ -rm -f ./$(DEPDIR)/liblldpd_snmp_la-agent_priv.Plo
+ -rm -f ./$(DEPDIR)/main.Po
+ -rm -f protocols/$(DEPDIR)/liblldpd_la-cdp.Plo
+ -rm -f protocols/$(DEPDIR)/liblldpd_la-edp.Plo
+ -rm -f protocols/$(DEPDIR)/liblldpd_la-lldp.Plo
+ -rm -f protocols/$(DEPDIR)/liblldpd_la-sonmp.Plo
+ -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+ mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-apparmorDATA uninstall-man \
+ uninstall-sbinPROGRAMS uninstall-systemdsystemunitDATA \
+ uninstall-sysusersDATA uninstall-tapsetDATA
+
+uninstall-man: uninstall-man8
+
+.MAKE: all check install install-am install-exec install-strip
+
+.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \
+ clean-generic clean-libtool clean-noinstLTLIBRARIES \
+ clean-sbinPROGRAMS cscopelist-am ctags ctags-am distclean \
+ distclean-compile distclean-generic distclean-libtool \
+ distclean-tags distdir dvi dvi-am html html-am info info-am \
+ install install-am install-apparmorDATA install-data \
+ install-data-am install-dvi install-dvi-am install-exec \
+ install-exec-am install-html install-html-am install-info \
+ install-info-am install-man install-man8 install-pdf \
+ install-pdf-am install-ps install-ps-am install-sbinPROGRAMS \
+ install-strip install-systemdsystemunitDATA \
+ install-sysusersDATA install-tapsetDATA installcheck \
+ installcheck-am installdirs maintainer-clean \
+ maintainer-clean-generic mostlyclean mostlyclean-compile \
+ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+ tags tags-am uninstall uninstall-am uninstall-apparmorDATA \
+ uninstall-man uninstall-man8 uninstall-sbinPROGRAMS \
+ uninstall-systemdsystemunitDATA uninstall-sysusersDATA \
+ uninstall-tapsetDATA
+
+.PRECIOUS: Makefile
+
+@USE_SECCOMP_TRUE@syscall-names.h:
+@USE_SECCOMP_TRUE@ $(AM_V_GEN)
+@USE_SECCOMP_TRUE@ $(AM_V_at)echo "#include <sys/syscall.h>" | $(CPP) -dM - > $@.tmp ;\
+@USE_SECCOMP_TRUE@ echo "static const char *syscall_names[] = {" > $@ ;\
+@USE_SECCOMP_TRUE@ grep '^#define __NR_' $@.tmp | \
+@USE_SECCOMP_TRUE@ LC_ALL=C sed -r -n -e 's/^\#define[ \t]+__NR_([a-z0-9_]+)[ \t]+([0-9]+)(.*)/ [\2] = "\1",/p' >> $@ ;\
+@USE_SECCOMP_TRUE@ echo "};" >> $@ ;\
+@USE_SECCOMP_TRUE@ rm $@.tmp
+@ENABLE_SYSTEMTAP_TRUE@probes.h: probes.d
+@ENABLE_SYSTEMTAP_TRUE@ $(AM_V_GEN)
+@ENABLE_SYSTEMTAP_TRUE@ $(AM_V_at)$(DTRACE) -C -h -s $< -o $@
+@ENABLE_SYSTEMTAP_TRUE@probes.o: probes.d
+@ENABLE_SYSTEMTAP_TRUE@ $(AM_V_GEN)
+@ENABLE_SYSTEMTAP_TRUE@ $(AM_V_at)$(DTRACE) -C -G -s $< -o $@
+
+@ENABLE_SYSTEMTAP_TRUE@lldpd.stp: probes.d $(srcdir)/dtrace2systemtap.awk $(top_builddir)/config.status
+@ENABLE_SYSTEMTAP_TRUE@ $(AM_V_GEN)$(AWK) -f $(srcdir)/dtrace2systemtap.awk -v sbindir=$(sbindir) $< > $@ || ( rm -f $@ ; exit 1 )
+
+@LIBEVENT_EMBEDDED_TRUE@event.c: $(top_builddir)/libevent/libevent.la
+@LIBEVENT_EMBEDDED_TRUE@$(top_builddir)/libevent/libevent.la: $(top_srcdir)/libevent/*.c $(top_srcdir)/libevent/*.h
+@LIBEVENT_EMBEDDED_TRUE@ (cd $(top_builddir)/libevent && $(MAKE))
+lldpd.8: lldpd.8.in
+lldpd.service: lldpd.service.in
+lldpd.sysusers.conf: lldpd.sysusers.conf.in
+usr.sbin.lldpd: usr.sbin.lldpd.in
+
+$(TEMPLATES): Makefile
+ $(AM_V_GEN)$(MKDIR_P) $(@D) && $(edit) $(srcdir)/$@.in > $@.tmp && mv $@.tmp $@
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/src/daemon/agent.c b/src/daemon/agent.c
new file mode 100644
index 0000000..cd631a8
--- /dev/null
+++ b/src/daemon/agent.c
@@ -0,0 +1,1939 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2008 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "lldpd.h"
+
+#include <assert.h>
+
+#include "agent.h"
+
+#if HAVE_NET_SNMP_AGENT_UTIL_FUNCS_H
+# include <net-snmp/agent/util_funcs.h>
+#else
+/* The above header may be buggy. We just need this function. */
+int header_generic(struct variable *, oid *, size_t *, int, size_t *, WriteMethod **);
+#endif
+
+/* For net-snmp */
+extern int register_sysORTable(oid *, size_t, const char *);
+extern int unregister_sysORTable(oid *, size_t);
+
+/* Global variable because no way to pass it as argument. Should not be used
+ * elsewhere. */
+#define scfg agent_scfg
+struct lldpd *agent_scfg;
+
+static uint8_t
+swap_bits(uint8_t n)
+{
+ n = ((n & 0xF0) >> 4) | ((n & 0x0F) << 4);
+ n = ((n & 0xCC) >> 2) | ((n & 0x33) << 2);
+ n = ((n & 0xAA) >> 1) | ((n & 0x55) << 1);
+
+ return n;
+};
+
+extern struct timeval starttime;
+static long int
+lastchange(struct lldpd_port *port)
+{
+ if (port->p_lastchange > starttime.tv_sec)
+ return (port->p_lastchange - starttime.tv_sec) * 100;
+ return 0;
+}
+
+/* -------------
+ Helper functions to build header_*indexed_table() functions.
+ Those functions keep an internal state. They are not reentrant!
+*/
+struct header_index {
+ struct variable *vp;
+ oid *name; /* Requested/returned OID */
+ size_t *length; /* Length of above OID */
+ int exact;
+ oid best[MAX_OID_LEN]; /* Best OID */
+ size_t best_len; /* Best OID length */
+ void *entity; /* Best entity */
+};
+static struct header_index header_idx;
+
+static int
+header_index_init(struct variable *vp, oid *name, size_t *length, int exact,
+ size_t *var_len, WriteMethod **write_method)
+{
+ /* If the requested OID name is less than OID prefix we
+ handle, adjust it to our prefix. */
+ if ((snmp_oid_compare(name, *length, vp->name, vp->namelen)) < 0) {
+ memcpy(name, vp->name, sizeof(oid) * vp->namelen);
+ *length = vp->namelen;
+ }
+ /* Now, we can only handle OID matching our prefix. Those two
+ tests are not really necessary since NetSNMP won't give us
+ OID "above" our prefix. But this makes unit tests
+ easier. */
+ if (*length < vp->namelen) return 0;
+ if (memcmp(name, vp->name, vp->namelen * sizeof(oid))) return 0;
+
+ if (write_method != NULL) *write_method = 0;
+ *var_len = sizeof(long);
+
+ /* Initialize our header index structure */
+ header_idx.vp = vp;
+ header_idx.name = name;
+ header_idx.length = length;
+ header_idx.exact = exact;
+ header_idx.best_len = 0;
+ header_idx.entity = NULL;
+ return 1;
+}
+
+static int
+header_index_add(oid *index, size_t len, void *entity)
+{
+ int result;
+ oid *target;
+ size_t target_len;
+
+ target = header_idx.name + header_idx.vp->namelen;
+ target_len = *header_idx.length - header_idx.vp->namelen;
+ if ((result = snmp_oid_compare(index, len, target, target_len)) < 0)
+ return 0; /* Too small. */
+ if (result == 0) return header_idx.exact;
+ if (header_idx.best_len == 0 ||
+ (snmp_oid_compare(index, len, header_idx.best, header_idx.best_len) < 0)) {
+ memcpy(header_idx.best, index, sizeof(oid) * len);
+ header_idx.best_len = len;
+ header_idx.entity = entity;
+ }
+ return 0; /* No best match yet. */
+}
+
+static void *
+header_index_best()
+{
+ if (header_idx.entity == NULL) return NULL;
+ if (header_idx.exact) return NULL;
+ memcpy(header_idx.name + header_idx.vp->namelen, header_idx.best,
+ sizeof(oid) * header_idx.best_len);
+ *header_idx.length = header_idx.vp->namelen + header_idx.best_len;
+ return header_idx.entity;
+}
+/* ----------------------------- */
+
+static struct lldpd_hardware *
+header_portindexed_table(struct variable *vp, oid *name, size_t *length, int exact,
+ size_t *var_len, WriteMethod **write_method)
+{
+ struct lldpd_hardware *hardware;
+
+ if (!header_index_init(vp, name, length, exact, var_len, write_method))
+ return NULL;
+ TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries) {
+ oid index[1] = { hardware->h_ifindex };
+ if (header_index_add(index, 1, hardware)) return hardware;
+ }
+ return header_index_best();
+}
+
+#ifdef ENABLE_LLDPMED
+static struct lldpd_med_policy *
+header_pmedindexed_policy_table(struct variable *vp, oid *name, size_t *length,
+ int exact, size_t *var_len, WriteMethod **write_method)
+{
+ struct lldpd_hardware *hardware;
+ int i;
+ oid index[2];
+
+ if (!header_index_init(vp, name, length, exact, var_len, write_method))
+ return NULL;
+ TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries) {
+ for (i = 0; i < LLDP_MED_APPTYPE_LAST; i++) {
+ if (hardware->h_lport.p_med_policy[i].type != i + 1) continue;
+ index[0] = hardware->h_ifindex;
+ index[1] = i + 1;
+ if (header_index_add(index, 2,
+ &hardware->h_lport.p_med_policy[i]))
+ return &hardware->h_lport.p_med_policy[i];
+ }
+ }
+ return header_index_best();
+}
+
+static struct lldpd_med_loc *
+header_pmedindexed_location_table(struct variable *vp, oid *name, size_t *length,
+ int exact, size_t *var_len, WriteMethod **write_method)
+{
+ struct lldpd_hardware *hardware;
+ int i;
+ oid index[2];
+
+ if (!header_index_init(vp, name, length, exact, var_len, write_method))
+ return NULL;
+ TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries) {
+ for (i = 0; i < LLDP_MED_LOCFORMAT_LAST; i++) {
+ if (hardware->h_lport.p_med_location[i].format != i + 1)
+ continue;
+ index[0] = hardware->h_ifindex;
+ index[1] = i + 2;
+ if (header_index_add(index, 2,
+ &hardware->h_lport.p_med_location[i]))
+ return &hardware->h_lport.p_med_location[i];
+ }
+ }
+ return header_index_best();
+}
+#endif
+
+static struct lldpd_port *
+header_tprindexed_table(struct variable *vp, oid *name, size_t *length, int exact,
+ size_t *var_len, WriteMethod **write_method, int withmed)
+{
+ struct lldpd_hardware *hardware;
+ struct lldpd_port *port;
+ oid index[3];
+
+ if (!header_index_init(vp, name, length, exact, var_len, write_method))
+ return NULL;
+ TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries) {
+ TAILQ_FOREACH (port, &hardware->h_rports, p_entries) {
+ if (SMART_HIDDEN(port)) continue;
+#ifdef ENABLE_LLDPMED
+ if (withmed && !port->p_chassis->c_med_cap_available) continue;
+#endif
+ index[0] = lastchange(port);
+ index[1] = hardware->h_ifindex;
+ index[2] = port->p_chassis->c_index;
+ if (header_index_add(index, 3, port)) return port;
+ }
+ }
+ return header_index_best();
+}
+
+static struct lldpd_mgmt *
+header_ipindexed_table(struct variable *vp, oid *name, size_t *length, int exact,
+ size_t *var_len, WriteMethod **write_method)
+{
+ struct lldpd_chassis *chassis = LOCAL_CHASSIS(scfg);
+ struct lldpd_mgmt *mgmt;
+ oid index[2 + 16];
+
+ if (!header_index_init(vp, name, length, exact, var_len, write_method))
+ return NULL;
+ TAILQ_FOREACH (mgmt, &chassis->c_mgmt, m_entries) {
+ int i;
+ switch (mgmt->m_family) {
+ case LLDPD_AF_IPV4:
+ index[0] = 1;
+ break;
+ case LLDPD_AF_IPV6:
+ index[0] = 2;
+ break;
+ default:
+ assert(0);
+ }
+ index[1] = mgmt->m_addrsize;
+ if (index[1] > sizeof(index) - 2) continue; /* Odd... */
+ for (i = 0; i < index[1]; i++)
+ index[i + 2] = mgmt->m_addr.octets[i];
+ if (header_index_add(index, 2 + index[1], mgmt)) return mgmt;
+ }
+
+ return header_index_best();
+}
+
+static struct lldpd_mgmt *
+header_tpripindexed_table(struct variable *vp, oid *name, size_t *length, int exact,
+ size_t *var_len, WriteMethod **write_method)
+{
+ struct lldpd_hardware *hardware;
+ struct lldpd_port *port;
+ struct lldpd_mgmt *mgmt;
+ oid index[5 + 16];
+
+ if (!header_index_init(vp, name, length, exact, var_len, write_method))
+ return NULL;
+ TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries) {
+ TAILQ_FOREACH (port, &hardware->h_rports, p_entries) {
+ if (SMART_HIDDEN(port)) continue;
+ TAILQ_FOREACH (mgmt, &port->p_chassis->c_mgmt, m_entries) {
+ int i;
+ index[0] = lastchange(port);
+ index[1] = hardware->h_ifindex;
+ index[2] = port->p_chassis->c_index;
+ switch (mgmt->m_family) {
+ case LLDPD_AF_IPV4:
+ index[3] = 1;
+ break;
+ case LLDPD_AF_IPV6:
+ index[3] = 2;
+ break;
+ default:
+ assert(0);
+ }
+ index[4] = mgmt->m_addrsize;
+ if (index[4] > sizeof(index) - 5) continue; /* Odd... */
+ for (i = 0; i < index[4]; i++)
+ index[i + 5] = mgmt->m_addr.octets[i];
+ if (header_index_add(index, 5 + index[4], mgmt))
+ return mgmt;
+ }
+ }
+ }
+ return header_index_best();
+}
+
+#ifdef ENABLE_CUSTOM
+static struct lldpd_custom *
+header_tprcustomindexed_table(struct variable *vp, oid *name, size_t *length, int exact,
+ size_t *var_len, WriteMethod **write_method)
+{
+ struct lldpd_hardware *hardware;
+ struct lldpd_port *port;
+ struct lldpd_custom *custom;
+ oid index[8];
+ oid idx;
+
+ if (!header_index_init(vp, name, length, exact, var_len, write_method))
+ return NULL;
+ TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries) {
+ TAILQ_FOREACH (port, &hardware->h_rports, p_entries) {
+ if (SMART_HIDDEN(port)) continue;
+ idx = 1;
+ TAILQ_FOREACH (custom, &port->p_custom_list, next) {
+ index[0] = lastchange(port);
+ index[1] = hardware->h_ifindex;
+ index[2] = port->p_chassis->c_index;
+ index[3] = custom->oui[0];
+ index[4] = custom->oui[1];
+ index[5] = custom->oui[2];
+ index[6] = custom->subtype;
+ index[7] = idx++;
+ if (header_index_add(index, 8, custom)) return custom;
+ }
+ }
+ }
+ return header_index_best();
+}
+#endif
+
+#ifdef ENABLE_LLDPMED
+# define TPR_VARIANT_MED_POLICY 2
+# define TPR_VARIANT_MED_LOCATION 3
+static void *
+header_tprmedindexed_table(struct variable *vp, oid *name, size_t *length, int exact,
+ size_t *var_len, WriteMethod **write_method, int variant)
+{
+ struct lldpd_hardware *hardware;
+ struct lldpd_port *port;
+ int j;
+ oid index[4];
+
+ if (!header_index_init(vp, name, length, exact, var_len, write_method))
+ return NULL;
+ TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries) {
+ TAILQ_FOREACH (port, &hardware->h_rports, p_entries) {
+ if (SMART_HIDDEN(port)) continue;
+ if (!port->p_chassis->c_med_cap_available) continue;
+ switch (variant) {
+ case TPR_VARIANT_MED_POLICY:
+ for (j = 0; j < LLDP_MED_APPTYPE_LAST; j++) {
+ if (port->p_med_policy[j].type != j + 1)
+ continue;
+ index[0] = lastchange(port);
+ index[1] = hardware->h_ifindex;
+ index[2] = port->p_chassis->c_index;
+ index[3] = j + 1;
+ if (header_index_add(index, 4,
+ &port->p_med_policy[j]))
+ return &port->p_med_policy[j];
+ }
+ break;
+ case TPR_VARIANT_MED_LOCATION:
+ for (j = 0; j < LLDP_MED_LOCFORMAT_LAST; j++) {
+ if (port->p_med_location[j].format != j + 1)
+ continue;
+ index[0] = lastchange(port);
+ index[1] = hardware->h_ifindex;
+ index[2] = port->p_chassis->c_index;
+ index[3] = j + 2;
+ if (header_index_add(index, 4,
+ &port->p_med_location[j]))
+ return &port->p_med_location[j];
+ }
+ break;
+ }
+ }
+ }
+ return header_index_best();
+}
+#endif
+
+#ifdef ENABLE_DOT1
+static struct lldpd_vlan *
+header_pvindexed_table(struct variable *vp, oid *name, size_t *length, int exact,
+ size_t *var_len, WriteMethod **write_method)
+{
+ struct lldpd_hardware *hardware;
+ struct lldpd_vlan *vlan;
+
+ if (!header_index_init(vp, name, length, exact, var_len, write_method))
+ return NULL;
+ TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries) {
+ TAILQ_FOREACH (vlan, &hardware->h_lport.p_vlans, v_entries) {
+ oid index[2] = { hardware->h_ifindex, vlan->v_vid };
+ if (header_index_add(index, 2, vlan)) return vlan;
+ }
+ }
+ return header_index_best();
+}
+
+static struct lldpd_vlan *
+header_tprvindexed_table(struct variable *vp, oid *name, size_t *length, int exact,
+ size_t *var_len, WriteMethod **write_method)
+{
+ struct lldpd_hardware *hardware;
+ struct lldpd_port *port;
+ struct lldpd_vlan *vlan;
+
+ if (!header_index_init(vp, name, length, exact, var_len, write_method))
+ return NULL;
+ TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries) {
+ TAILQ_FOREACH (port, &hardware->h_rports, p_entries) {
+ if (SMART_HIDDEN(port)) continue;
+ TAILQ_FOREACH (vlan, &port->p_vlans, v_entries) {
+ oid index[4] = { lastchange(port), hardware->h_ifindex,
+ port->p_chassis->c_index, vlan->v_vid };
+ if (header_index_add(index, 4, vlan)) return vlan;
+ }
+ }
+ }
+ return header_index_best();
+}
+
+static struct lldpd_ppvid *
+header_pppvidindexed_table(struct variable *vp, oid *name, size_t *length, int exact,
+ size_t *var_len, WriteMethod **write_method)
+{
+ struct lldpd_hardware *hardware;
+ struct lldpd_ppvid *ppvid;
+
+ if (!header_index_init(vp, name, length, exact, var_len, write_method))
+ return NULL;
+ TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries) {
+ TAILQ_FOREACH (ppvid, &hardware->h_lport.p_ppvids, p_entries) {
+ oid index[2] = { hardware->h_ifindex, ppvid->p_ppvid };
+ if (header_index_add(index, 2, ppvid)) return ppvid;
+ }
+ }
+ return header_index_best();
+}
+
+static struct lldpd_ppvid *
+header_tprppvidindexed_table(struct variable *vp, oid *name, size_t *length, int exact,
+ size_t *var_len, WriteMethod **write_method)
+{
+ struct lldpd_hardware *hardware;
+ struct lldpd_port *port;
+ struct lldpd_ppvid *ppvid;
+
+ if (!header_index_init(vp, name, length, exact, var_len, write_method))
+ return NULL;
+ TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries) {
+ TAILQ_FOREACH (port, &hardware->h_rports, p_entries) {
+ if (SMART_HIDDEN(port)) continue;
+ TAILQ_FOREACH (ppvid, &port->p_ppvids, p_entries) {
+ oid index[4] = { lastchange(port), hardware->h_ifindex,
+ port->p_chassis->c_index, ppvid->p_ppvid };
+ if (header_index_add(index, 4, ppvid)) return ppvid;
+ }
+ }
+ }
+ return header_index_best();
+}
+
+static struct lldpd_pi *
+header_ppiindexed_table(struct variable *vp, oid *name, size_t *length, int exact,
+ size_t *var_len, WriteMethod **write_method)
+{
+ struct lldpd_hardware *hardware;
+ struct lldpd_pi *pi;
+
+ if (!header_index_init(vp, name, length, exact, var_len, write_method))
+ return NULL;
+ TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries) {
+ TAILQ_FOREACH (pi, &hardware->h_lport.p_pids, p_entries) {
+ oid index[2] = { hardware->h_ifindex,
+ frame_checksum((const u_char *)pi->p_pi, pi->p_pi_len,
+ 0) };
+ if (header_index_add(index, 2, pi)) return pi;
+ }
+ }
+ return header_index_best();
+}
+
+static struct lldpd_pi *
+header_tprpiindexed_table(struct variable *vp, oid *name, size_t *length, int exact,
+ size_t *var_len, WriteMethod **write_method)
+{
+ struct lldpd_hardware *hardware;
+ struct lldpd_port *port;
+ struct lldpd_pi *pi;
+
+ if (!header_index_init(vp, name, length, exact, var_len, write_method))
+ return NULL;
+ TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries) {
+ TAILQ_FOREACH (port, &hardware->h_rports, p_entries) {
+ if (SMART_HIDDEN(port)) continue;
+ TAILQ_FOREACH (pi, &port->p_pids, p_entries) {
+ oid index[4] = { lastchange(port), hardware->h_ifindex,
+ port->p_chassis->c_index,
+ frame_checksum((const u_char *)pi->p_pi,
+ pi->p_pi_len, 0) };
+ if (header_index_add(index, 4, pi)) return pi;
+ }
+ }
+ }
+ return header_index_best();
+}
+#endif
+
+/* Scalars */
+#define LLDP_SNMP_TXINTERVAL 1
+#define LLDP_SNMP_TXMULTIPLIER 2
+#define LLDP_SNMP_REINITDELAY 3
+#define LLDP_SNMP_TXDELAY 4
+#define LLDP_SNMP_NOTIFICATION 5
+#define LLDP_SNMP_LASTUPDATE 6
+#define LLDP_SNMP_STATS_INSERTS 7
+#define LLDP_SNMP_STATS_DELETES 8
+#define LLDP_SNMP_STATS_DROPS 9
+#define LLDP_SNMP_STATS_AGEOUTS 10
+/* Chassis */
+#define LLDP_SNMP_CIDSUBTYPE 1
+#define LLDP_SNMP_CID 2
+#define LLDP_SNMP_SYSNAME 3
+#define LLDP_SNMP_SYSDESCR 4
+#define LLDP_SNMP_SYSCAP_SUP 5
+#define LLDP_SNMP_SYSCAP_ENA 6
+/* Stats */
+#define LLDP_SNMP_STATS_TX 2
+#define LLDP_SNMP_STATS_RX_DISCARDED 4
+#define LLDP_SNMP_STATS_RX_ERRORS 5
+#define LLDP_SNMP_STATS_RX 6
+#define LLDP_SNMP_STATS_RX_TLVDISCARDED 7
+#define LLDP_SNMP_STATS_RX_TLVUNRECOGNIZED 8
+#define LLDP_SNMP_STATS_RX_AGEOUTS 9
+/* Ports */
+#define LLDP_SNMP_PIDSUBTYPE 2
+#define LLDP_SNMP_PID 3
+#define LLDP_SNMP_PORTDESC 4
+#define LLDP_SNMP_DOT3_AUTONEG_SUPPORT 5
+#define LLDP_SNMP_DOT3_AUTONEG_ENABLED 6
+#define LLDP_SNMP_DOT3_AUTONEG_ADVERTISED 7
+#define LLDP_SNMP_DOT3_AUTONEG_MAU 8
+#define LLDP_SNMP_DOT3_AGG_STATUS 9
+#define LLDP_SNMP_DOT3_AGG_ID 10
+#define LLDP_SNMP_DOT3_MFS 11
+#define LLDP_SNMP_DOT3_POWER_DEVICETYPE 12
+#define LLDP_SNMP_DOT3_POWER_SUPPORT 13
+#define LLDP_SNMP_DOT3_POWER_ENABLED 14
+#define LLDP_SNMP_DOT3_POWER_PAIRCONTROL 15
+#define LLDP_SNMP_DOT3_POWER_PAIRS 16
+#define LLDP_SNMP_DOT3_POWER_CLASS 17
+#define LLDP_SNMP_DOT3_POWER_TYPE 18
+#define LLDP_SNMP_DOT3_POWER_SOURCE 19
+#define LLDP_SNMP_DOT3_POWER_PRIORITY 20
+#define LLDP_SNMP_DOT3_POWER_REQUESTED 21
+#define LLDP_SNMP_DOT3_POWER_ALLOCATED 22
+#define LLDP_SNMP_DOT1_PVID 23
+/* Vlans */
+#define LLDP_SNMP_DOT1_VLANNAME 1
+/* Protocol VLAN IDs */
+#define LLDP_SNMP_DOT1_PPVLAN_SUPPORTED 2
+#define LLDP_SNMP_DOT1_PPVLAN_ENABLED 3
+/* Protocol Identity */
+#define LLDP_SNMP_DOT1_PI 1
+/* Management address */
+#define LLDP_SNMP_ADDR_LEN 1
+#define LLDP_SNMP_ADDR_IFSUBTYPE 2
+#define LLDP_SNMP_ADDR_IFID 3
+#define LLDP_SNMP_ADDR_OID 4
+/* Custom TLVs */
+#define LLDP_SNMP_ORG_DEF_INFO 1
+/* LLDP-MED */
+#define LLDP_SNMP_MED_CAP_AVAILABLE 1
+#define LLDP_SNMP_MED_CAP_ENABLED 2
+#define LLDP_SNMP_MED_CLASS 3
+#define LLDP_SNMP_MED_HW 4
+#define LLDP_SNMP_MED_FW 5
+#define LLDP_SNMP_MED_SW 6
+#define LLDP_SNMP_MED_SN 7
+#define LLDP_SNMP_MED_MANUF 8
+#define LLDP_SNMP_MED_MODEL 9
+#define LLDP_SNMP_MED_ASSET 10
+#define LLDP_SNMP_MED_POLICY_VID 11
+#define LLDP_SNMP_MED_POLICY_PRIO 12
+#define LLDP_SNMP_MED_POLICY_DSCP 13
+#define LLDP_SNMP_MED_POLICY_UNKNOWN 14
+#define LLDP_SNMP_MED_POLICY_TAGGED 15
+#define LLDP_SNMP_MED_LOCATION 16
+#define LLDP_SNMP_MED_POE_DEVICETYPE 17
+#define LLDP_SNMP_MED_POE_PSE_POWERVAL 19
+#define LLDP_SNMP_MED_POE_PSE_POWERSOURCE 20
+#define LLDP_SNMP_MED_POE_PSE_POWERPRIORITY 21
+#define LLDP_SNMP_MED_POE_PD_POWERVAL 22
+#define LLDP_SNMP_MED_POE_PD_POWERSOURCE 23
+#define LLDP_SNMP_MED_POE_PD_POWERPRIORITY 24
+
+/* The following macro should be used anytime where the selected OID
+ is finally not returned (for example, when the associated data is
+ not available). In this case, we retry the function with the next
+ OID. */
+#define TRYNEXT(X) \
+ do { \
+ if (!exact && (name[*length - 1] < MAX_SUBID)) \
+ return X(vp, name, length, exact, var_len, write_method); \
+ return NULL; \
+ } while (0)
+
+static u_char *
+agent_h_scalars(struct variable *vp, oid *name, size_t *length, int exact,
+ size_t *var_len, WriteMethod **write_method)
+{
+ static unsigned long long_ret;
+ struct lldpd_hardware *hardware;
+ struct lldpd_port *port;
+
+ if (header_generic(vp, name, length, exact, var_len, write_method)) return NULL;
+
+ switch (vp->magic) {
+ case LLDP_SNMP_TXINTERVAL:
+ long_ret = (scfg->g_config.c_tx_interval + 999) / 1000;
+ return (u_char *)&long_ret;
+ case LLDP_SNMP_TXMULTIPLIER:
+ long_ret = scfg->g_config.c_tx_hold;
+ return (u_char *)&long_ret;
+ case LLDP_SNMP_REINITDELAY:
+ long_ret = 1;
+ return (u_char *)&long_ret;
+ case LLDP_SNMP_TXDELAY:
+ long_ret = LLDPD_TX_MSGDELAY;
+ return (u_char *)&long_ret;
+ case LLDP_SNMP_NOTIFICATION:
+ long_ret = 5;
+ return (u_char *)&long_ret;
+ case LLDP_SNMP_LASTUPDATE:
+ long_ret = 0;
+ TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries) {
+ /* Check if the last removal of a remote port on this local port
+ * was the last change. */
+ if (hardware->h_lport.p_lastremove > long_ret)
+ long_ret = hardware->h_lport.p_lastremove;
+ /* Check if any change on the existing remote ports was the last
+ * change. */
+ TAILQ_FOREACH (port, &hardware->h_rports, p_entries) {
+ if (SMART_HIDDEN(port)) continue;
+ if (port->p_lastchange > long_ret)
+ long_ret = port->p_lastchange;
+ }
+ }
+ if (long_ret) long_ret = (long_ret - starttime.tv_sec) * 100;
+ return (u_char *)&long_ret;
+ case LLDP_SNMP_STATS_INSERTS:
+ /* We assume this is equal to valid frames received on all ports */
+ long_ret = 0;
+ TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries)
+ long_ret += hardware->h_insert_cnt;
+ return (u_char *)&long_ret;
+ case LLDP_SNMP_STATS_AGEOUTS:
+ long_ret = 0;
+ TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries)
+ long_ret += hardware->h_ageout_cnt;
+ return (u_char *)&long_ret;
+ case LLDP_SNMP_STATS_DELETES:
+ long_ret = 0;
+ TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries)
+ long_ret += hardware->h_delete_cnt;
+ return (u_char *)&long_ret;
+ case LLDP_SNMP_STATS_DROPS:
+ long_ret = 0;
+ TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries)
+ long_ret += hardware->h_drop_cnt;
+ return (u_char *)&long_ret;
+ default:
+ break;
+ }
+ return NULL;
+}
+
+#ifdef ENABLE_LLDPMED
+static u_char *
+agent_v_med_power(struct variable *vp, size_t *var_len, struct lldpd_med_power *power)
+{
+ static unsigned long long_ret;
+
+ switch (vp->magic) {
+ case LLDP_SNMP_MED_POE_DEVICETYPE:
+ switch (power->devicetype) {
+ case LLDP_MED_POW_TYPE_PSE:
+ long_ret = 2;
+ break;
+ case LLDP_MED_POW_TYPE_PD:
+ long_ret = 3;
+ break;
+ case 0:
+ long_ret = 4;
+ break;
+ default:
+ long_ret = 1;
+ }
+ return (u_char *)&long_ret;
+ case LLDP_SNMP_MED_POE_PSE_POWERVAL:
+ case LLDP_SNMP_MED_POE_PD_POWERVAL:
+ if (((vp->magic == LLDP_SNMP_MED_POE_PSE_POWERVAL) &&
+ (power->devicetype == LLDP_MED_POW_TYPE_PSE)) ||
+ ((vp->magic == LLDP_SNMP_MED_POE_PD_POWERVAL) &&
+ (power->devicetype == LLDP_MED_POW_TYPE_PD))) {
+ long_ret = power->val;
+ return (u_char *)&long_ret;
+ }
+ break;
+ case LLDP_SNMP_MED_POE_PSE_POWERSOURCE:
+ if (power->devicetype == LLDP_MED_POW_TYPE_PSE) {
+ switch (power->source) {
+ case LLDP_MED_POW_SOURCE_PRIMARY:
+ long_ret = 2;
+ break;
+ case LLDP_MED_POW_SOURCE_BACKUP:
+ long_ret = 3;
+ break;
+ default:
+ long_ret = 1;
+ }
+ return (u_char *)&long_ret;
+ }
+ break;
+ case LLDP_SNMP_MED_POE_PD_POWERSOURCE:
+ if (power->devicetype == LLDP_MED_POW_TYPE_PD) {
+ switch (power->source) {
+ case LLDP_MED_POW_SOURCE_PSE:
+ long_ret = 2;
+ break;
+ case LLDP_MED_POW_SOURCE_LOCAL:
+ long_ret = 3;
+ break;
+ case LLDP_MED_POW_SOURCE_BOTH:
+ long_ret = 4;
+ break;
+ default:
+ long_ret = 1;
+ }
+ return (u_char *)&long_ret;
+ }
+ break;
+ case LLDP_SNMP_MED_POE_PSE_POWERPRIORITY:
+ case LLDP_SNMP_MED_POE_PD_POWERPRIORITY:
+ if (((vp->magic == LLDP_SNMP_MED_POE_PSE_POWERPRIORITY) &&
+ (power->devicetype == LLDP_MED_POW_TYPE_PSE)) ||
+ ((vp->magic == LLDP_SNMP_MED_POE_PD_POWERPRIORITY) &&
+ (power->devicetype == LLDP_MED_POW_TYPE_PD))) {
+ switch (power->priority) {
+ case LLDP_MED_POW_PRIO_CRITICAL:
+ long_ret = 2;
+ break;
+ case LLDP_MED_POW_PRIO_HIGH:
+ long_ret = 3;
+ break;
+ case LLDP_MED_POW_PRIO_LOW:
+ long_ret = 4;
+ break;
+ default:
+ long_ret = 1;
+ }
+ return (u_char *)&long_ret;
+ }
+ break;
+ }
+
+ return NULL;
+}
+static u_char *
+agent_h_local_med_power(struct variable *vp, oid *name, size_t *length, int exact,
+ size_t *var_len, WriteMethod **write_method)
+{
+ struct lldpd_med_power *power = NULL;
+ struct lldpd_hardware *hardware;
+ int pse = 0;
+
+ if (!LOCAL_CHASSIS(scfg)->c_med_cap_available) return NULL;
+ if (header_generic(vp, name, length, exact, var_len, write_method)) return NULL;
+
+ /* LLDP-MED requires only one device type for all
+ ports. Moreover, a PSE can only have one power source. At
+ least, all PD values are global and not per-port. We try to
+ do our best. For device type, we decide on the number of
+ PD/PSE ports. */
+ TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries) {
+ if (hardware->h_lport.p_med_power.devicetype == LLDP_MED_POW_TYPE_PSE) {
+ pse++;
+ if (pse == 1) /* Take this port as a reference */
+ power = &hardware->h_lport.p_med_power;
+ } else if (hardware->h_lport.p_med_power.devicetype ==
+ LLDP_MED_POW_TYPE_PD) {
+ pse--;
+ if (pse == -1) /* Take this one instead */
+ power = &hardware->h_lport.p_med_power;
+ }
+ }
+ if (power) {
+ u_char *a;
+ if ((a = agent_v_med_power(vp, var_len, power)) != NULL) return a;
+ }
+ TRYNEXT(agent_h_local_med_power);
+}
+static u_char *
+agent_h_remote_med_power(struct variable *vp, oid *name, size_t *length, int exact,
+ size_t *var_len, WriteMethod **write_method)
+{
+ struct lldpd_port *port;
+ u_char *a;
+
+ if ((port = header_tprindexed_table(vp, name, length, exact, var_len,
+ write_method, 1)) == NULL)
+ return NULL;
+
+ if ((a = agent_v_med_power(vp, var_len, &port->p_med_power)) != NULL) return a;
+ TRYNEXT(agent_h_remote_med_power);
+}
+
+static u_char *
+agent_v_med(struct variable *vp, size_t *var_len, struct lldpd_chassis *chassis,
+ struct lldpd_port *port)
+{
+ static unsigned long long_ret;
+ static uint8_t bit;
+
+ switch (vp->magic) {
+ case LLDP_SNMP_MED_CLASS:
+ long_ret = chassis->c_med_type;
+ return (u_char *)&long_ret;
+ case LLDP_SNMP_MED_CAP_AVAILABLE:
+ *var_len = 1;
+ bit = swap_bits(chassis->c_med_cap_available);
+ return (u_char *)&bit;
+ case LLDP_SNMP_MED_CAP_ENABLED:
+ if (!port) break;
+ *var_len = 1;
+ bit = swap_bits(port->p_med_cap_enabled);
+ return (u_char *)&bit;
+
+# define LLDP_H_MED(magic, variable) \
+ case magic: \
+ if (chassis->variable) { \
+ *var_len = strlen(chassis->variable); \
+ return (u_char *)chassis->variable; \
+ } \
+ break
+
+ LLDP_H_MED(LLDP_SNMP_MED_HW, c_med_hw);
+ LLDP_H_MED(LLDP_SNMP_MED_SW, c_med_sw);
+ LLDP_H_MED(LLDP_SNMP_MED_FW, c_med_fw);
+ LLDP_H_MED(LLDP_SNMP_MED_SN, c_med_sn);
+ LLDP_H_MED(LLDP_SNMP_MED_MANUF, c_med_manuf);
+ LLDP_H_MED(LLDP_SNMP_MED_MODEL, c_med_model);
+ LLDP_H_MED(LLDP_SNMP_MED_ASSET, c_med_asset);
+ }
+ return NULL;
+}
+static u_char *
+agent_h_local_med(struct variable *vp, oid *name, size_t *length, int exact,
+ size_t *var_len, WriteMethod **write_method)
+{
+ u_char *a;
+
+ if (!LOCAL_CHASSIS(scfg)->c_med_cap_available) return NULL;
+ if (header_generic(vp, name, length, exact, var_len, write_method)) return NULL;
+
+ if ((a = agent_v_med(vp, var_len, LOCAL_CHASSIS(scfg), NULL)) != NULL) return a;
+ TRYNEXT(agent_h_local_med);
+}
+
+static u_char *
+agent_h_remote_med(struct variable *vp, oid *name, size_t *length, int exact,
+ size_t *var_len, WriteMethod **write_method)
+{
+ struct lldpd_port *port;
+ u_char *a;
+
+ if ((port = header_tprindexed_table(vp, name, length, exact, var_len,
+ write_method, 1)) == NULL)
+ return NULL;
+
+ if ((a = agent_v_med(vp, var_len, port->p_chassis, port)) != NULL) return a;
+ TRYNEXT(agent_h_remote_med);
+}
+
+static u_char *
+agent_v_med_policy(struct variable *vp, size_t *var_len,
+ struct lldpd_med_policy *policy)
+{
+ static unsigned long long_ret;
+
+ switch (vp->magic) {
+ case LLDP_SNMP_MED_POLICY_VID:
+ long_ret = policy->vid;
+ return (u_char *)&long_ret;
+ case LLDP_SNMP_MED_POLICY_PRIO:
+ long_ret = policy->priority;
+ return (u_char *)&long_ret;
+ case LLDP_SNMP_MED_POLICY_DSCP:
+ long_ret = policy->dscp;
+ return (u_char *)&long_ret;
+ case LLDP_SNMP_MED_POLICY_UNKNOWN:
+ long_ret = policy->unknown ? 1 : 2;
+ return (u_char *)&long_ret;
+ case LLDP_SNMP_MED_POLICY_TAGGED:
+ long_ret = policy->tagged ? 1 : 2;
+ return (u_char *)&long_ret;
+ default:
+ return NULL;
+ }
+}
+static u_char *
+agent_h_remote_med_policy(struct variable *vp, oid *name, size_t *length, int exact,
+ size_t *var_len, WriteMethod **write_method)
+{
+ struct lldpd_med_policy *policy;
+
+ if ((policy = (struct lldpd_med_policy *)header_tprmedindexed_table(vp, name,
+ length, exact, var_len, write_method, TPR_VARIANT_MED_POLICY)) == NULL)
+ return NULL;
+
+ return agent_v_med_policy(vp, var_len, policy);
+}
+static u_char *
+agent_h_local_med_policy(struct variable *vp, oid *name, size_t *length, int exact,
+ size_t *var_len, WriteMethod **write_method)
+{
+ struct lldpd_med_policy *policy;
+
+ if ((policy = (struct lldpd_med_policy *)header_pmedindexed_policy_table(vp,
+ name, length, exact, var_len, write_method)) == NULL)
+ return NULL;
+
+ return agent_v_med_policy(vp, var_len, policy);
+}
+
+static u_char *
+agent_v_med_location(struct variable *vp, size_t *var_len,
+ struct lldpd_med_loc *location)
+{
+ switch (vp->magic) {
+ case LLDP_SNMP_MED_LOCATION:
+ *var_len = location->data_len;
+ return (u_char *)location->data;
+ default:
+ return NULL;
+ }
+}
+static u_char *
+agent_h_remote_med_location(struct variable *vp, oid *name, size_t *length, int exact,
+ size_t *var_len, WriteMethod **write_method)
+{
+ struct lldpd_med_loc *location;
+
+ if ((location = (struct lldpd_med_loc *)header_tprmedindexed_table(vp, name,
+ length, exact, var_len, write_method, TPR_VARIANT_MED_LOCATION)) ==
+ NULL)
+ return NULL;
+
+ return agent_v_med_location(vp, var_len, location);
+}
+static u_char *
+agent_h_local_med_location(struct variable *vp, oid *name, size_t *length, int exact,
+ size_t *var_len, WriteMethod **write_method)
+{
+ struct lldpd_med_loc *location;
+
+ if ((location = (struct lldpd_med_loc *)header_pmedindexed_location_table(vp,
+ name, length, exact, var_len, write_method)) == NULL)
+ return NULL;
+
+ return agent_v_med_location(vp, var_len, location);
+}
+#endif
+
+static u_char *
+agent_v_chassis(struct variable *vp, size_t *var_len, struct lldpd_chassis *chassis)
+{
+ static uint8_t bit;
+ static unsigned long long_ret;
+
+ switch (vp->magic) {
+ case LLDP_SNMP_CIDSUBTYPE:
+ long_ret = chassis->c_id_subtype;
+ return (u_char *)&long_ret;
+ case LLDP_SNMP_CID:
+ *var_len = chassis->c_id_len;
+ return (u_char *)chassis->c_id;
+ case LLDP_SNMP_SYSNAME:
+ if (!chassis->c_name || *chassis->c_name == '\0') break;
+ *var_len = strlen(chassis->c_name);
+ return (u_char *)chassis->c_name;
+ case LLDP_SNMP_SYSDESCR:
+ if (!chassis->c_descr || *chassis->c_descr == '\0') break;
+ *var_len = strlen(chassis->c_descr);
+ return (u_char *)chassis->c_descr;
+ case LLDP_SNMP_SYSCAP_SUP:
+ *var_len = 1;
+ bit = swap_bits(chassis->c_cap_available);
+ return (u_char *)&bit;
+ case LLDP_SNMP_SYSCAP_ENA:
+ *var_len = 1;
+ bit = swap_bits(chassis->c_cap_enabled);
+ return (u_char *)&bit;
+ default:
+ break;
+ }
+ return NULL;
+}
+static u_char *
+agent_h_local_chassis(struct variable *vp, oid *name, size_t *length, int exact,
+ size_t *var_len, WriteMethod **write_method)
+{
+ u_char *a;
+
+ if (header_generic(vp, name, length, exact, var_len, write_method)) return NULL;
+
+ if ((a = agent_v_chassis(vp, var_len, LOCAL_CHASSIS(scfg))) != NULL) return a;
+ TRYNEXT(agent_h_local_chassis);
+}
+static u_char *
+agent_h_remote_chassis(struct variable *vp, oid *name, size_t *length, int exact,
+ size_t *var_len, WriteMethod **write_method)
+{
+ struct lldpd_port *port;
+ u_char *a;
+
+ if ((port = header_tprindexed_table(vp, name, length, exact, var_len,
+ write_method, 0)) == NULL)
+ return NULL;
+
+ if ((a = agent_v_chassis(vp, var_len, port->p_chassis)) != NULL) return a;
+ TRYNEXT(agent_h_remote_chassis);
+}
+
+static u_char *
+agent_h_stats(struct variable *vp, oid *name, size_t *length, int exact,
+ size_t *var_len, WriteMethod **write_method)
+{
+ static unsigned long long_ret;
+ struct lldpd_hardware *hardware;
+
+ if ((hardware = header_portindexed_table(vp, name, length, exact, var_len,
+ write_method)) == NULL)
+ return NULL;
+
+ switch (vp->magic) {
+ case LLDP_SNMP_STATS_TX:
+ long_ret = hardware->h_tx_cnt;
+ return (u_char *)&long_ret;
+ case LLDP_SNMP_STATS_RX:
+ long_ret = hardware->h_rx_cnt;
+ return (u_char *)&long_ret;
+ case LLDP_SNMP_STATS_RX_DISCARDED:
+ case LLDP_SNMP_STATS_RX_ERRORS:
+ /* We discard only frame with errors. Therefore, the two values
+ * are equal */
+ long_ret = hardware->h_rx_discarded_cnt;
+ return (u_char *)&long_ret;
+ case LLDP_SNMP_STATS_RX_TLVDISCARDED:
+ case LLDP_SNMP_STATS_RX_TLVUNRECOGNIZED:
+ /* We discard only unrecognized TLV. Malformed TLV
+ implies dropping the whole frame */
+ long_ret = hardware->h_rx_unrecognized_cnt;
+ return (u_char *)&long_ret;
+ case LLDP_SNMP_STATS_RX_AGEOUTS:
+ long_ret = hardware->h_ageout_cnt;
+ return (u_char *)&long_ret;
+ default:
+ return NULL;
+ }
+}
+
+#ifdef ENABLE_DOT1
+static u_char *
+agent_v_vlan(struct variable *vp, size_t *var_len, struct lldpd_vlan *vlan)
+{
+ switch (vp->magic) {
+ case LLDP_SNMP_DOT1_VLANNAME:
+ *var_len = strlen(vlan->v_name);
+ return (u_char *)vlan->v_name;
+ default:
+ return NULL;
+ }
+}
+static u_char *
+agent_h_local_vlan(struct variable *vp, oid *name, size_t *length, int exact,
+ size_t *var_len, WriteMethod **write_method)
+{
+ struct lldpd_vlan *vlan;
+
+ if ((vlan = header_pvindexed_table(vp, name, length, exact, var_len,
+ write_method)) == NULL)
+ return NULL;
+
+ return agent_v_vlan(vp, var_len, vlan);
+}
+static u_char *
+agent_h_remote_vlan(struct variable *vp, oid *name, size_t *length, int exact,
+ size_t *var_len, WriteMethod **write_method)
+{
+ struct lldpd_vlan *vlan;
+
+ if ((vlan = header_tprvindexed_table(vp, name, length, exact, var_len,
+ write_method)) == NULL)
+ return NULL;
+
+ return agent_v_vlan(vp, var_len, vlan);
+}
+
+static u_char *
+agent_v_ppvid(struct variable *vp, size_t *var_len, struct lldpd_ppvid *ppvid)
+{
+ static unsigned long long_ret;
+
+ switch (vp->magic) {
+ case LLDP_SNMP_DOT1_PPVLAN_SUPPORTED:
+ long_ret = (ppvid->p_cap_status & LLDP_PPVID_CAP_SUPPORTED) ? 1 : 2;
+ return (u_char *)&long_ret;
+ case LLDP_SNMP_DOT1_PPVLAN_ENABLED:
+ long_ret = (ppvid->p_cap_status & LLDP_PPVID_CAP_ENABLED) ? 1 : 2;
+ return (u_char *)&long_ret;
+ default:
+ return NULL;
+ }
+}
+static u_char *
+agent_h_local_ppvid(struct variable *vp, oid *name, size_t *length, int exact,
+ size_t *var_len, WriteMethod **write_method)
+{
+ struct lldpd_ppvid *ppvid;
+
+ if ((ppvid = header_pppvidindexed_table(vp, name, length, exact, var_len,
+ write_method)) == NULL)
+ return NULL;
+
+ return agent_v_ppvid(vp, var_len, ppvid);
+}
+
+static u_char *
+agent_h_remote_ppvid(struct variable *vp, oid *name, size_t *length, int exact,
+ size_t *var_len, WriteMethod **write_method)
+{
+ struct lldpd_ppvid *ppvid;
+
+ if ((ppvid = header_tprppvidindexed_table(vp, name, length, exact, var_len,
+ write_method)) == NULL)
+ return NULL;
+
+ return agent_v_ppvid(vp, var_len, ppvid);
+}
+
+static u_char *
+agent_v_pi(struct variable *vp, size_t *var_len, struct lldpd_pi *pi)
+{
+ switch (vp->magic) {
+ case LLDP_SNMP_DOT1_PI:
+ *var_len = pi->p_pi_len;
+ return (u_char *)pi->p_pi;
+ default:
+ return NULL;
+ }
+}
+static u_char *
+agent_h_local_pi(struct variable *vp, oid *name, size_t *length, int exact,
+ size_t *var_len, WriteMethod **write_method)
+{
+ struct lldpd_pi *pi;
+
+ if ((pi = header_ppiindexed_table(vp, name, length, exact, var_len,
+ write_method)) == NULL)
+ return NULL;
+
+ return agent_v_pi(vp, var_len, pi);
+}
+static u_char *
+agent_h_remote_pi(struct variable *vp, oid *name, size_t *length, int exact,
+ size_t *var_len, WriteMethod **write_method)
+{
+ struct lldpd_pi *pi;
+
+ if ((pi = header_tprpiindexed_table(vp, name, length, exact, var_len,
+ write_method)) == NULL)
+ return NULL;
+
+ return agent_v_pi(vp, var_len, pi);
+}
+#endif
+
+static u_char *
+agent_v_port(struct variable *vp, size_t *var_len, struct lldpd_port *port)
+{
+#ifdef ENABLE_DOT3
+ static uint16_t short_ret;
+ static uint8_t bit;
+#endif
+ static unsigned long long_ret;
+
+ switch (vp->magic) {
+ case LLDP_SNMP_PIDSUBTYPE:
+ long_ret = port->p_id_subtype;
+ return (u_char *)&long_ret;
+ case LLDP_SNMP_PID:
+ *var_len = port->p_id_len;
+ return (u_char *)port->p_id;
+ case LLDP_SNMP_PORTDESC:
+ if (!port->p_descr || *port->p_descr == '\0') break;
+ *var_len = strlen(port->p_descr);
+ return (u_char *)port->p_descr;
+#ifdef ENABLE_DOT3
+ case LLDP_SNMP_DOT3_AUTONEG_SUPPORT:
+ long_ret = 2 - port->p_macphy.autoneg_support;
+ return (u_char *)&long_ret;
+ case LLDP_SNMP_DOT3_AUTONEG_ENABLED:
+ long_ret = 2 - port->p_macphy.autoneg_enabled;
+ return (u_char *)&long_ret;
+ case LLDP_SNMP_DOT3_AUTONEG_ADVERTISED:
+ *var_len = 2;
+ short_ret = htons(port->p_macphy.autoneg_advertised);
+ return (u_char *)&short_ret;
+ case LLDP_SNMP_DOT3_AUTONEG_MAU:
+ long_ret = port->p_macphy.mau_type;
+ return (u_char *)&long_ret;
+ case LLDP_SNMP_DOT3_AGG_STATUS:
+ bit = swap_bits((port->p_aggregid > 0) ? 3 : 0);
+ *var_len = 1;
+ return (u_char *)&bit;
+ case LLDP_SNMP_DOT3_AGG_ID:
+ long_ret = port->p_aggregid;
+ return (u_char *)&long_ret;
+ case LLDP_SNMP_DOT3_MFS:
+ if (port->p_mfs) {
+ long_ret = port->p_mfs;
+ return (u_char *)&long_ret;
+ }
+ break;
+ case LLDP_SNMP_DOT3_POWER_DEVICETYPE:
+ if (port->p_power.devicetype) {
+ long_ret =
+ (port->p_power.devicetype == LLDP_DOT3_POWER_PSE) ? 1 : 2;
+ return (u_char *)&long_ret;
+ }
+ break;
+ case LLDP_SNMP_DOT3_POWER_SUPPORT:
+ if (port->p_power.devicetype) {
+ long_ret = (port->p_power.supported) ? 1 : 2;
+ return (u_char *)&long_ret;
+ }
+ break;
+ case LLDP_SNMP_DOT3_POWER_ENABLED:
+ if (port->p_power.devicetype) {
+ long_ret = (port->p_power.enabled) ? 1 : 2;
+ return (u_char *)&long_ret;
+ }
+ break;
+ case LLDP_SNMP_DOT3_POWER_PAIRCONTROL:
+ if (port->p_power.devicetype) {
+ long_ret = (port->p_power.paircontrol) ? 1 : 2;
+ return (u_char *)&long_ret;
+ }
+ break;
+ case LLDP_SNMP_DOT3_POWER_PAIRS:
+ if (port->p_power.devicetype) {
+ long_ret = port->p_power.pairs;
+ return (u_char *)&long_ret;
+ }
+ break;
+ case LLDP_SNMP_DOT3_POWER_CLASS:
+ if (port->p_power.devicetype && port->p_power.class) {
+ long_ret = port->p_power.class;
+ return (u_char *)&long_ret;
+ }
+ break;
+ case LLDP_SNMP_DOT3_POWER_TYPE:
+ if (port->p_power.devicetype &&
+ port->p_power.powertype != LLDP_DOT3_POWER_8023AT_OFF) {
+ *var_len = 1;
+ bit = (((port->p_power.powertype ==
+ LLDP_DOT3_POWER_8023AT_TYPE1) ?
+ 0 :
+ 1)
+ << 7) |
+ (((port->p_power.devicetype == LLDP_DOT3_POWER_PSE) ? 0 : 1)
+ << 6);
+ return (u_char *)&bit;
+ }
+ break;
+ case LLDP_SNMP_DOT3_POWER_SOURCE:
+ if (port->p_power.devicetype &&
+ port->p_power.powertype != LLDP_DOT3_POWER_8023AT_OFF) {
+ *var_len = 1;
+ bit = swap_bits(port->p_power.source % (1 << 2));
+ return (u_char *)&bit;
+ }
+ break;
+ case LLDP_SNMP_DOT3_POWER_PRIORITY:
+ if (port->p_power.devicetype &&
+ port->p_power.powertype != LLDP_DOT3_POWER_8023AT_OFF) {
+ /* See 30.12.2.1.16. This seems defined in reverse order... */
+ long_ret = 4 - port->p_power.priority;
+ return (u_char *)&long_ret;
+ }
+ break;
+ case LLDP_SNMP_DOT3_POWER_REQUESTED:
+ if (port->p_power.devicetype &&
+ port->p_power.powertype != LLDP_DOT3_POWER_8023AT_OFF) {
+ long_ret = port->p_power.requested;
+ return (u_char *)&long_ret;
+ }
+ break;
+ case LLDP_SNMP_DOT3_POWER_ALLOCATED:
+ if (port->p_power.devicetype &&
+ port->p_power.powertype != LLDP_DOT3_POWER_8023AT_OFF) {
+ long_ret = port->p_power.allocated;
+ return (u_char *)&long_ret;
+ }
+ break;
+#endif
+#ifdef ENABLE_DOT1
+ case LLDP_SNMP_DOT1_PVID:
+ long_ret = port->p_pvid;
+ return (u_char *)&long_ret;
+#endif
+ default:
+ break;
+ }
+ return NULL;
+}
+static u_char *
+agent_h_remote_port(struct variable *vp, oid *name, size_t *length, int exact,
+ size_t *var_len, WriteMethod **write_method)
+{
+ struct lldpd_port *port;
+ u_char *a;
+
+ if ((port = header_tprindexed_table(vp, name, length, exact, var_len,
+ write_method, 0)) == NULL)
+ return NULL;
+
+ if ((a = agent_v_port(vp, var_len, port)) != NULL) return a;
+ TRYNEXT(agent_h_remote_port);
+}
+static u_char *
+agent_h_local_port(struct variable *vp, oid *name, size_t *length, int exact,
+ size_t *var_len, WriteMethod **write_method)
+{
+ struct lldpd_hardware *hardware;
+ u_char *a;
+
+ if ((hardware = header_portindexed_table(vp, name, length, exact, var_len,
+ write_method)) == NULL)
+ return NULL;
+
+ if ((a = agent_v_port(vp, var_len, &hardware->h_lport)) != NULL) return a;
+ TRYNEXT(agent_h_local_port);
+}
+
+static u_char *
+agent_v_management(struct variable *vp, size_t *var_len, struct lldpd_mgmt *mgmt)
+{
+ static unsigned long int long_ret;
+ static oid zeroDotZero[2] = { 0, 0 };
+
+ switch (vp->magic) {
+ case LLDP_SNMP_ADDR_LEN:
+ long_ret = mgmt->m_addrsize + 1;
+ return (u_char *)&long_ret;
+ case LLDP_SNMP_ADDR_IFSUBTYPE:
+ if (mgmt->m_iface != 0)
+ long_ret = LLDP_MGMT_IFACE_IFINDEX;
+ else
+ long_ret = 1;
+ return (u_char *)&long_ret;
+ case LLDP_SNMP_ADDR_IFID:
+ long_ret = mgmt->m_iface;
+ return (u_char *)&long_ret;
+ case LLDP_SNMP_ADDR_OID:
+ *var_len = sizeof(zeroDotZero);
+ return (u_char *)zeroDotZero;
+ default:
+ return NULL;
+ }
+}
+static u_char *
+agent_h_local_management(struct variable *vp, oid *name, size_t *length, int exact,
+ size_t *var_len, WriteMethod **write_method)
+{
+
+ struct lldpd_mgmt *mgmt;
+
+ if ((mgmt = header_ipindexed_table(vp, name, length, exact, var_len,
+ write_method)) == NULL)
+ return NULL;
+
+ return agent_v_management(vp, var_len, mgmt);
+}
+static u_char *
+agent_h_remote_management(struct variable *vp, oid *name, size_t *length, int exact,
+ size_t *var_len, WriteMethod **write_method)
+{
+ struct lldpd_mgmt *mgmt;
+
+ if ((mgmt = header_tpripindexed_table(vp, name, length, exact, var_len,
+ write_method)) == NULL)
+ return NULL;
+
+ return agent_v_management(vp, var_len, mgmt);
+}
+
+#ifdef ENABLE_CUSTOM
+static u_char *
+agent_v_custom(struct variable *vp, size_t *var_len, struct lldpd_custom *custom)
+{
+ switch (vp->magic) {
+ case LLDP_SNMP_ORG_DEF_INFO:
+ *var_len = custom->oui_info_len;
+ return (u_char *)custom->oui_info;
+ default:
+ return NULL;
+ }
+}
+static u_char *
+agent_h_remote_custom(struct variable *vp, oid *name, size_t *length, int exact,
+ size_t *var_len, WriteMethod **write_method)
+{
+ struct lldpd_custom *custom;
+
+ if ((custom = header_tprcustomindexed_table(vp, name, length, exact, var_len,
+ write_method)) == NULL)
+ return NULL;
+
+ return agent_v_custom(vp, var_len, custom);
+}
+#endif
+
+/*
+ Here is how it works: a agent_h_*() function will handle incoming
+ requests. It will use an appropriate header_*indexed_table()
+ function to grab the appropriate structure that was queried (a port,
+ a chassis, ...). It will then delegate to a agent_v_*() function the
+ responsability to extract the appropriate answer.
+
+ agent_h_*() functions and header_*indexed_table() are not shared
+ between remote and not remote version while agent_v_*() functions
+ are the same for both version.
+*/
+
+/* For testing purposes, keep this structure ordered by increasing OID! */
+struct variable8 agent_lldp_vars[] = {
+ /* Scalars */
+ { LLDP_SNMP_TXINTERVAL, ASN_INTEGER, RONLY, agent_h_scalars, 3, { 1, 1, 1 } },
+ { LLDP_SNMP_TXMULTIPLIER, ASN_INTEGER, RONLY, agent_h_scalars, 3, { 1, 1, 2 } },
+ { LLDP_SNMP_REINITDELAY, ASN_INTEGER, RONLY, agent_h_scalars, 3, { 1, 1, 3 } },
+ { LLDP_SNMP_TXDELAY, ASN_INTEGER, RONLY, agent_h_scalars, 3, { 1, 1, 4 } },
+ { LLDP_SNMP_NOTIFICATION, ASN_INTEGER, RONLY, agent_h_scalars, 3, { 1, 1, 5 } },
+ { LLDP_SNMP_LASTUPDATE, ASN_TIMETICKS, RONLY, agent_h_scalars, 3, { 1, 2, 1 } },
+ { LLDP_SNMP_STATS_INSERTS, ASN_GAUGE, RONLY, agent_h_scalars, 3, { 1, 2, 2 } },
+ { LLDP_SNMP_STATS_DELETES, ASN_GAUGE, RONLY, agent_h_scalars, 3, { 1, 2, 3 } },
+ { LLDP_SNMP_STATS_DROPS, ASN_GAUGE, RONLY, agent_h_scalars, 3, { 1, 2, 4 } },
+ { LLDP_SNMP_STATS_AGEOUTS, ASN_GAUGE, RONLY, agent_h_scalars, 3, { 1, 2, 5 } },
+ /* Stats */
+ { LLDP_SNMP_STATS_TX, ASN_COUNTER, RONLY, agent_h_stats, 5, { 1, 2, 6, 1, 2 } },
+ { LLDP_SNMP_STATS_RX_DISCARDED, ASN_COUNTER, RONLY, agent_h_stats, 5,
+ { 1, 2, 7, 1, 2 } },
+ { LLDP_SNMP_STATS_RX_ERRORS, ASN_COUNTER, RONLY, agent_h_stats, 5,
+ { 1, 2, 7, 1, 3 } },
+ { LLDP_SNMP_STATS_RX, ASN_COUNTER, RONLY, agent_h_stats, 5, { 1, 2, 7, 1, 4 } },
+ { LLDP_SNMP_STATS_RX_TLVDISCARDED, ASN_COUNTER, RONLY, agent_h_stats, 5,
+ { 1, 2, 7, 1, 5 } },
+ { LLDP_SNMP_STATS_RX_TLVUNRECOGNIZED, ASN_COUNTER, RONLY, agent_h_stats, 5,
+ { 1, 2, 7, 1, 6 } },
+ { LLDP_SNMP_STATS_RX_AGEOUTS, ASN_GAUGE, RONLY, agent_h_stats, 5,
+ { 1, 2, 7, 1, 7 } },
+ /* Local chassis */
+ { LLDP_SNMP_CIDSUBTYPE, ASN_INTEGER, RONLY, agent_h_local_chassis, 3,
+ { 1, 3, 1 } },
+ { LLDP_SNMP_CID, ASN_OCTET_STR, RONLY, agent_h_local_chassis, 3, { 1, 3, 2 } },
+ { LLDP_SNMP_SYSNAME, ASN_OCTET_STR, RONLY, agent_h_local_chassis, 3,
+ { 1, 3, 3 } },
+ { LLDP_SNMP_SYSDESCR, ASN_OCTET_STR, RONLY, agent_h_local_chassis, 3,
+ { 1, 3, 4 } },
+ { LLDP_SNMP_SYSCAP_SUP, ASN_OCTET_STR, RONLY, agent_h_local_chassis, 3,
+ { 1, 3, 5 } },
+ { LLDP_SNMP_SYSCAP_ENA, ASN_OCTET_STR, RONLY, agent_h_local_chassis, 3,
+ { 1, 3, 6 } },
+ /* Local ports */
+ { LLDP_SNMP_PIDSUBTYPE, ASN_INTEGER, RONLY, agent_h_local_port, 5,
+ { 1, 3, 7, 1, 2 } },
+ { LLDP_SNMP_PID, ASN_OCTET_STR, RONLY, agent_h_local_port, 5,
+ { 1, 3, 7, 1, 3 } },
+ { LLDP_SNMP_PORTDESC, ASN_OCTET_STR, RONLY, agent_h_local_port, 5,
+ { 1, 3, 7, 1, 4 } },
+ /* Local management address */
+ { LLDP_SNMP_ADDR_LEN, ASN_INTEGER, RONLY, agent_h_local_management, 5,
+ { 1, 3, 8, 1, 3 } },
+ { LLDP_SNMP_ADDR_IFSUBTYPE, ASN_INTEGER, RONLY, agent_h_local_management, 5,
+ { 1, 3, 8, 1, 4 } },
+ { LLDP_SNMP_ADDR_IFID, ASN_INTEGER, RONLY, agent_h_local_management, 5,
+ { 1, 3, 8, 1, 5 } },
+ { LLDP_SNMP_ADDR_OID, ASN_OBJECT_ID, RONLY, agent_h_local_management, 5,
+ { 1, 3, 8, 1, 6 } },
+ /* Remote ports */
+ { LLDP_SNMP_CIDSUBTYPE, ASN_INTEGER, RONLY, agent_h_remote_chassis, 5,
+ { 1, 4, 1, 1, 4 } },
+ { LLDP_SNMP_CID, ASN_OCTET_STR, RONLY, agent_h_remote_chassis, 5,
+ { 1, 4, 1, 1, 5 } },
+ { LLDP_SNMP_PIDSUBTYPE, ASN_INTEGER, RONLY, agent_h_remote_port, 5,
+ { 1, 4, 1, 1, 6 } },
+ { LLDP_SNMP_PID, ASN_OCTET_STR, RONLY, agent_h_remote_port, 5,
+ { 1, 4, 1, 1, 7 } },
+ { LLDP_SNMP_PORTDESC, ASN_OCTET_STR, RONLY, agent_h_remote_port, 5,
+ { 1, 4, 1, 1, 8 } },
+ { LLDP_SNMP_SYSNAME, ASN_OCTET_STR, RONLY, agent_h_remote_chassis, 5,
+ { 1, 4, 1, 1, 9 } },
+ { LLDP_SNMP_SYSDESCR, ASN_OCTET_STR, RONLY, agent_h_remote_chassis, 5,
+ { 1, 4, 1, 1, 10 } },
+ { LLDP_SNMP_SYSCAP_SUP, ASN_OCTET_STR, RONLY, agent_h_remote_chassis, 5,
+ { 1, 4, 1, 1, 11 } },
+ { LLDP_SNMP_SYSCAP_ENA, ASN_OCTET_STR, RONLY, agent_h_remote_chassis, 5,
+ { 1, 4, 1, 1, 12 } },
+ /* Remote management address */
+ { LLDP_SNMP_ADDR_IFSUBTYPE, ASN_INTEGER, RONLY, agent_h_remote_management, 5,
+ { 1, 4, 2, 1, 3 } },
+ { LLDP_SNMP_ADDR_IFID, ASN_INTEGER, RONLY, agent_h_remote_management, 5,
+ { 1, 4, 2, 1, 4 } },
+ { LLDP_SNMP_ADDR_OID, ASN_OBJECT_ID, RONLY, agent_h_remote_management, 5,
+ { 1, 4, 2, 1, 5 } },
+#ifdef ENABLE_CUSTOM
+ /* Custom TLVs */
+ { LLDP_SNMP_ORG_DEF_INFO, ASN_OCTET_STR, RONLY, agent_h_remote_custom, 5,
+ { 1, 4, 4, 1, 4 } },
+#endif
+#ifdef ENABLE_DOT3
+ /* Dot3, local ports */
+ { LLDP_SNMP_DOT3_AUTONEG_SUPPORT, ASN_INTEGER, RONLY, agent_h_local_port, 8,
+ { 1, 5, 4623, 1, 2, 1, 1, 1 } },
+ { LLDP_SNMP_DOT3_AUTONEG_ENABLED, ASN_INTEGER, RONLY, agent_h_local_port, 8,
+ { 1, 5, 4623, 1, 2, 1, 1, 2 } },
+ { LLDP_SNMP_DOT3_AUTONEG_ADVERTISED, ASN_OCTET_STR, RONLY, agent_h_local_port,
+ 8, { 1, 5, 4623, 1, 2, 1, 1, 3 } },
+ { LLDP_SNMP_DOT3_AUTONEG_MAU, ASN_INTEGER, RONLY, agent_h_local_port, 8,
+ { 1, 5, 4623, 1, 2, 1, 1, 4 } },
+ { LLDP_SNMP_DOT3_POWER_DEVICETYPE, ASN_INTEGER, RONLY, agent_h_local_port, 8,
+ { 1, 5, 4623, 1, 2, 2, 1, 1 } },
+ { LLDP_SNMP_DOT3_POWER_SUPPORT, ASN_INTEGER, RONLY, agent_h_local_port, 8,
+ { 1, 5, 4623, 1, 2, 2, 1, 2 } },
+ { LLDP_SNMP_DOT3_POWER_ENABLED, ASN_INTEGER, RONLY, agent_h_local_port, 8,
+ { 1, 5, 4623, 1, 2, 2, 1, 3 } },
+ { LLDP_SNMP_DOT3_POWER_PAIRCONTROL, ASN_INTEGER, RONLY, agent_h_local_port, 8,
+ { 1, 5, 4623, 1, 2, 2, 1, 4 } },
+ { LLDP_SNMP_DOT3_POWER_PAIRS, ASN_INTEGER, RONLY, agent_h_local_port, 8,
+ { 1, 5, 4623, 1, 2, 2, 1, 5 } },
+ { LLDP_SNMP_DOT3_POWER_CLASS, ASN_INTEGER, RONLY, agent_h_local_port, 8,
+ { 1, 5, 4623, 1, 2, 2, 1, 6 } },
+ { LLDP_SNMP_DOT3_POWER_TYPE, ASN_OCTET_STR, RONLY, agent_h_local_port, 8,
+ { 1, 5, 4623, 1, 2, 2, 1, 7 } },
+ { LLDP_SNMP_DOT3_POWER_SOURCE, ASN_OCTET_STR, RONLY, agent_h_local_port, 8,
+ { 1, 5, 4623, 1, 2, 2, 1, 8 } },
+ { LLDP_SNMP_DOT3_POWER_PRIORITY, ASN_INTEGER, RONLY, agent_h_local_port, 8,
+ { 1, 5, 4623, 1, 2, 2, 1, 9 } },
+ { LLDP_SNMP_DOT3_POWER_REQUESTED, ASN_INTEGER, RONLY, agent_h_local_port, 8,
+ { 1, 5, 4623, 1, 2, 2, 1, 10 } },
+ { LLDP_SNMP_DOT3_POWER_ALLOCATED, ASN_INTEGER, RONLY, agent_h_local_port, 8,
+ { 1, 5, 4623, 1, 2, 2, 1, 11 } },
+ { LLDP_SNMP_DOT3_AGG_STATUS, ASN_OCTET_STR, RONLY, agent_h_local_port, 8,
+ { 1, 5, 4623, 1, 2, 3, 1, 1 } },
+ { LLDP_SNMP_DOT3_AGG_ID, ASN_INTEGER, RONLY, agent_h_local_port, 8,
+ { 1, 5, 4623, 1, 2, 3, 1, 2 } },
+ { LLDP_SNMP_DOT3_MFS, ASN_INTEGER, RONLY, agent_h_local_port, 8,
+ { 1, 5, 4623, 1, 2, 4, 1, 1 } },
+#endif
+/* Dot3, remote ports */
+#ifdef ENABLE_DOT3
+ { LLDP_SNMP_DOT3_AUTONEG_SUPPORT, ASN_INTEGER, RONLY, agent_h_remote_port, 8,
+ { 1, 5, 4623, 1, 3, 1, 1, 1 } },
+ { LLDP_SNMP_DOT3_AUTONEG_ENABLED, ASN_INTEGER, RONLY, agent_h_remote_port, 8,
+ { 1, 5, 4623, 1, 3, 1, 1, 2 } },
+ { LLDP_SNMP_DOT3_AUTONEG_ADVERTISED, ASN_OCTET_STR, RONLY, agent_h_remote_port,
+ 8, { 1, 5, 4623, 1, 3, 1, 1, 3 } },
+ { LLDP_SNMP_DOT3_AUTONEG_MAU, ASN_INTEGER, RONLY, agent_h_remote_port, 8,
+ { 1, 5, 4623, 1, 3, 1, 1, 4 } },
+ { LLDP_SNMP_DOT3_POWER_DEVICETYPE, ASN_INTEGER, RONLY, agent_h_remote_port, 8,
+ { 1, 5, 4623, 1, 3, 2, 1, 1 } },
+ { LLDP_SNMP_DOT3_POWER_SUPPORT, ASN_INTEGER, RONLY, agent_h_remote_port, 8,
+ { 1, 5, 4623, 1, 3, 2, 1, 2 } },
+ { LLDP_SNMP_DOT3_POWER_ENABLED, ASN_INTEGER, RONLY, agent_h_remote_port, 8,
+ { 1, 5, 4623, 1, 3, 2, 1, 3 } },
+ { LLDP_SNMP_DOT3_POWER_PAIRCONTROL, ASN_INTEGER, RONLY, agent_h_remote_port, 8,
+ { 1, 5, 4623, 1, 3, 2, 1, 4 } },
+ { LLDP_SNMP_DOT3_POWER_PAIRS, ASN_INTEGER, RONLY, agent_h_remote_port, 8,
+ { 1, 5, 4623, 1, 3, 2, 1, 5 } },
+ { LLDP_SNMP_DOT3_POWER_CLASS, ASN_INTEGER, RONLY, agent_h_remote_port, 8,
+ { 1, 5, 4623, 1, 3, 2, 1, 6 } },
+ { LLDP_SNMP_DOT3_POWER_TYPE, ASN_OCTET_STR, RONLY, agent_h_remote_port, 8,
+ { 1, 5, 4623, 1, 3, 2, 1, 7 } },
+ { LLDP_SNMP_DOT3_POWER_SOURCE, ASN_OCTET_STR, RONLY, agent_h_remote_port, 8,
+ { 1, 5, 4623, 1, 3, 2, 1, 8 } },
+ { LLDP_SNMP_DOT3_POWER_PRIORITY, ASN_INTEGER, RONLY, agent_h_remote_port, 8,
+ { 1, 5, 4623, 1, 3, 2, 1, 9 } },
+ { LLDP_SNMP_DOT3_POWER_REQUESTED, ASN_INTEGER, RONLY, agent_h_remote_port, 8,
+ { 1, 5, 4623, 1, 3, 2, 1, 10 } },
+ { LLDP_SNMP_DOT3_POWER_ALLOCATED, ASN_INTEGER, RONLY, agent_h_remote_port, 8,
+ { 1, 5, 4623, 1, 3, 2, 1, 11 } },
+ { LLDP_SNMP_DOT3_AGG_STATUS, ASN_OCTET_STR, RONLY, agent_h_remote_port, 8,
+ { 1, 5, 4623, 1, 3, 3, 1, 1 } },
+ { LLDP_SNMP_DOT3_AGG_ID, ASN_INTEGER, RONLY, agent_h_remote_port, 8,
+ { 1, 5, 4623, 1, 3, 3, 1, 2 } },
+ { LLDP_SNMP_DOT3_MFS, ASN_INTEGER, RONLY, agent_h_remote_port, 8,
+ { 1, 5, 4623, 1, 3, 4, 1, 1 } },
+#endif
+#ifdef ENABLE_LLDPMED
+ /* LLDP-MED local */
+ { LLDP_SNMP_MED_CLASS, ASN_INTEGER, RONLY, agent_h_local_med, 6,
+ { 1, 5, 4795, 1, 1, 1 } },
+ { LLDP_SNMP_MED_POLICY_VID, ASN_INTEGER, RONLY, agent_h_local_med_policy, 8,
+ { 1, 5, 4795, 1, 2, 1, 1, 2 } },
+ { LLDP_SNMP_MED_POLICY_PRIO, ASN_INTEGER, RONLY, agent_h_local_med_policy, 8,
+ { 1, 5, 4795, 1, 2, 1, 1, 3 } },
+ { LLDP_SNMP_MED_POLICY_DSCP, ASN_INTEGER, RONLY, agent_h_local_med_policy, 8,
+ { 1, 5, 4795, 1, 2, 1, 1, 4 } },
+ { LLDP_SNMP_MED_POLICY_UNKNOWN, ASN_INTEGER, RONLY, agent_h_local_med_policy, 8,
+ { 1, 5, 4795, 1, 2, 1, 1, 5 } },
+ { LLDP_SNMP_MED_POLICY_TAGGED, ASN_INTEGER, RONLY, agent_h_local_med_policy, 8,
+ { 1, 5, 4795, 1, 2, 1, 1, 6 } },
+ { LLDP_SNMP_MED_HW, ASN_OCTET_STR, RONLY, agent_h_local_med, 6,
+ { 1, 5, 4795, 1, 2, 2 } },
+ { LLDP_SNMP_MED_FW, ASN_OCTET_STR, RONLY, agent_h_local_med, 6,
+ { 1, 5, 4795, 1, 2, 3 } },
+ { LLDP_SNMP_MED_SW, ASN_OCTET_STR, RONLY, agent_h_local_med, 6,
+ { 1, 5, 4795, 1, 2, 4 } },
+ { LLDP_SNMP_MED_SN, ASN_OCTET_STR, RONLY, agent_h_local_med, 6,
+ { 1, 5, 4795, 1, 2, 5 } },
+ { LLDP_SNMP_MED_MANUF, ASN_OCTET_STR, RONLY, agent_h_local_med, 6,
+ { 1, 5, 4795, 1, 2, 6 } },
+ { LLDP_SNMP_MED_MODEL, ASN_OCTET_STR, RONLY, agent_h_local_med, 6,
+ { 1, 5, 4795, 1, 2, 7 } },
+ { LLDP_SNMP_MED_ASSET, ASN_OCTET_STR, RONLY, agent_h_local_med, 6,
+ { 1, 5, 4795, 1, 2, 8 } },
+ { LLDP_SNMP_MED_LOCATION, ASN_OCTET_STR, RONLY, agent_h_local_med_location, 8,
+ { 1, 5, 4795, 1, 2, 9, 1, 2 } },
+ { LLDP_SNMP_MED_POE_DEVICETYPE, ASN_INTEGER, RONLY, agent_h_local_med_power, 6,
+ { 1, 5, 4795, 1, 2, 10 } },
+ { LLDP_SNMP_MED_POE_PSE_POWERVAL, ASN_GAUGE, RONLY, agent_h_local_med_power, 8,
+ { 1, 5, 4795, 1, 2, 11, 1, 1 } },
+ { LLDP_SNMP_MED_POE_PSE_POWERPRIORITY, ASN_INTEGER, RONLY,
+ agent_h_local_med_power, 8, { 1, 5, 4795, 1, 2, 11, 1, 2 } },
+ { LLDP_SNMP_MED_POE_PSE_POWERSOURCE, ASN_INTEGER, RONLY,
+ agent_h_local_med_power, 6, { 1, 5, 4795, 1, 2, 12 } },
+ { LLDP_SNMP_MED_POE_PD_POWERVAL, ASN_GAUGE, RONLY, agent_h_local_med_power, 6,
+ { 1, 5, 4795, 1, 2, 13 } },
+ { LLDP_SNMP_MED_POE_PD_POWERSOURCE, ASN_INTEGER, RONLY, agent_h_local_med_power,
+ 6, { 1, 5, 4795, 1, 2, 14 } },
+ { LLDP_SNMP_MED_POE_PD_POWERPRIORITY, ASN_INTEGER, RONLY,
+ agent_h_local_med_power, 6, { 1, 5, 4795, 1, 2, 15 } },
+ /* LLDP-MED remote */
+ { LLDP_SNMP_MED_CAP_AVAILABLE, ASN_OCTET_STR, RONLY, agent_h_remote_med, 8,
+ { 1, 5, 4795, 1, 3, 1, 1, 1 } },
+ { LLDP_SNMP_MED_CAP_ENABLED, ASN_OCTET_STR, RONLY, agent_h_remote_med, 8,
+ { 1, 5, 4795, 1, 3, 1, 1, 2 } },
+ { LLDP_SNMP_MED_CLASS, ASN_INTEGER, RONLY, agent_h_remote_med, 8,
+ { 1, 5, 4795, 1, 3, 1, 1, 3 } },
+ { LLDP_SNMP_MED_POLICY_VID, ASN_INTEGER, RONLY, agent_h_remote_med_policy, 8,
+ { 1, 5, 4795, 1, 3, 2, 1, 2 } },
+ { LLDP_SNMP_MED_POLICY_PRIO, ASN_INTEGER, RONLY, agent_h_remote_med_policy, 8,
+ { 1, 5, 4795, 1, 3, 2, 1, 3 } },
+ { LLDP_SNMP_MED_POLICY_DSCP, ASN_INTEGER, RONLY, agent_h_remote_med_policy, 8,
+ { 1, 5, 4795, 1, 3, 2, 1, 4 } },
+ { LLDP_SNMP_MED_POLICY_UNKNOWN, ASN_INTEGER, RONLY, agent_h_remote_med_policy,
+ 8, { 1, 5, 4795, 1, 3, 2, 1, 5 } },
+ { LLDP_SNMP_MED_POLICY_TAGGED, ASN_INTEGER, RONLY, agent_h_remote_med_policy, 8,
+ { 1, 5, 4795, 1, 3, 2, 1, 6 } },
+ { LLDP_SNMP_MED_HW, ASN_OCTET_STR, RONLY, agent_h_remote_med, 8,
+ { 1, 5, 4795, 1, 3, 3, 1, 1 } },
+ { LLDP_SNMP_MED_FW, ASN_OCTET_STR, RONLY, agent_h_remote_med, 8,
+ { 1, 5, 4795, 1, 3, 3, 1, 2 } },
+ { LLDP_SNMP_MED_SW, ASN_OCTET_STR, RONLY, agent_h_remote_med, 8,
+ { 1, 5, 4795, 1, 3, 3, 1, 3 } },
+ { LLDP_SNMP_MED_SN, ASN_OCTET_STR, RONLY, agent_h_remote_med, 8,
+ { 1, 5, 4795, 1, 3, 3, 1, 4 } },
+ { LLDP_SNMP_MED_MANUF, ASN_OCTET_STR, RONLY, agent_h_remote_med, 8,
+ { 1, 5, 4795, 1, 3, 3, 1, 5 } },
+ { LLDP_SNMP_MED_MODEL, ASN_OCTET_STR, RONLY, agent_h_remote_med, 8,
+ { 1, 5, 4795, 1, 3, 3, 1, 6 } },
+ { LLDP_SNMP_MED_ASSET, ASN_OCTET_STR, RONLY, agent_h_remote_med, 8,
+ { 1, 5, 4795, 1, 3, 3, 1, 7 } },
+ { LLDP_SNMP_MED_LOCATION, ASN_OCTET_STR, RONLY, agent_h_remote_med_location, 8,
+ { 1, 5, 4795, 1, 3, 4, 1, 2 } },
+ { LLDP_SNMP_MED_POE_DEVICETYPE, ASN_INTEGER, RONLY, agent_h_remote_med_power, 8,
+ { 1, 5, 4795, 1, 3, 5, 1, 1 } },
+ { LLDP_SNMP_MED_POE_PSE_POWERVAL, ASN_GAUGE, RONLY, agent_h_remote_med_power, 8,
+ { 1, 5, 4795, 1, 3, 6, 1, 1 } },
+ { LLDP_SNMP_MED_POE_PSE_POWERSOURCE, ASN_INTEGER, RONLY,
+ agent_h_remote_med_power, 8, { 1, 5, 4795, 1, 3, 6, 1, 2 } },
+ { LLDP_SNMP_MED_POE_PSE_POWERPRIORITY, ASN_INTEGER, RONLY,
+ agent_h_remote_med_power, 8, { 1, 5, 4795, 1, 3, 6, 1, 3 } },
+ { LLDP_SNMP_MED_POE_PD_POWERVAL, ASN_GAUGE, RONLY, agent_h_remote_med_power, 8,
+ { 1, 5, 4795, 1, 3, 7, 1, 1 } },
+ { LLDP_SNMP_MED_POE_PD_POWERSOURCE, ASN_INTEGER, RONLY,
+ agent_h_remote_med_power, 8, { 1, 5, 4795, 1, 3, 7, 1, 2 } },
+ { LLDP_SNMP_MED_POE_PD_POWERPRIORITY, ASN_INTEGER, RONLY,
+ agent_h_remote_med_power, 8, { 1, 5, 4795, 1, 3, 7, 1, 3 } },
+#endif
+/* Dot1, local and remote ports */
+#ifdef ENABLE_DOT1
+ { LLDP_SNMP_DOT1_PVID, ASN_INTEGER, RONLY, agent_h_local_port, 8,
+ { 1, 5, 32962, 1, 2, 1, 1, 1 } },
+ { LLDP_SNMP_DOT1_PPVLAN_SUPPORTED, ASN_INTEGER, RONLY, agent_h_local_ppvid, 8,
+ { 1, 5, 32962, 1, 2, 2, 1, 2 } },
+ { LLDP_SNMP_DOT1_PPVLAN_ENABLED, ASN_INTEGER, RONLY, agent_h_local_ppvid, 8,
+ { 1, 5, 32962, 1, 2, 2, 1, 3 } },
+ { LLDP_SNMP_DOT1_VLANNAME, ASN_OCTET_STR, RONLY, agent_h_local_vlan, 8,
+ { 1, 5, 32962, 1, 2, 3, 1, 2 } },
+ { LLDP_SNMP_DOT1_PI, ASN_OCTET_STR, RONLY, agent_h_local_pi, 8,
+ { 1, 5, 32962, 1, 2, 4, 1, 2 } },
+#endif
+#ifdef ENABLE_DOT1
+ { LLDP_SNMP_DOT1_PVID, ASN_INTEGER, RONLY, agent_h_remote_port, 8,
+ { 1, 5, 32962, 1, 3, 1, 1, 1 } },
+ { LLDP_SNMP_DOT1_PPVLAN_SUPPORTED, ASN_INTEGER, RONLY, agent_h_remote_ppvid, 8,
+ { 1, 5, 32962, 1, 3, 2, 1, 2 } },
+ { LLDP_SNMP_DOT1_PPVLAN_ENABLED, ASN_INTEGER, RONLY, agent_h_remote_ppvid, 8,
+ { 1, 5, 32962, 1, 3, 2, 1, 3 } },
+ /* Remote vlans */
+ { LLDP_SNMP_DOT1_VLANNAME, ASN_OCTET_STR, RONLY, agent_h_remote_vlan, 8,
+ { 1, 5, 32962, 1, 3, 3, 1, 2 } },
+ /* Protocol identity */
+ { LLDP_SNMP_DOT1_PI, ASN_OCTET_STR, RONLY, agent_h_remote_pi, 8,
+ { 1, 5, 32962, 1, 3, 4, 1, 2 } },
+#endif
+};
+size_t
+agent_lldp_vars_size(void)
+{
+ return sizeof(agent_lldp_vars) / sizeof(struct variable8);
+}
+
+/**
+ * Send a notification about a change in one remote neighbor.
+ *
+ * @param hardware Interface on which the change has happened.
+ * @param type Type of change (add, delete, update)
+ * @param rport Changed remote port
+ */
+void
+agent_notify(struct lldpd_hardware *hardware, int type, struct lldpd_port *rport)
+{
+ struct lldpd_hardware *h;
+
+ /* OID of the notification */
+ oid notification_oid[] = { LLDP_OID, 0, 0, 1 };
+ size_t notification_oid_len = OID_LENGTH(notification_oid);
+ /* OID for snmpTrapOID.0 */
+ oid objid_snmptrap[] = { SNMPTRAP_OID };
+ size_t objid_snmptrap_len = OID_LENGTH(objid_snmptrap);
+
+ /* Other OID */
+ oid inserts_oid[] = { LLDP_OID, 1, 2, 2 };
+ size_t inserts_oid_len = OID_LENGTH(inserts_oid);
+ unsigned long inserts = 0;
+
+ oid deletes_oid[] = { LLDP_OID, 1, 2, 3 };
+ size_t deletes_oid_len = OID_LENGTH(deletes_oid);
+ unsigned long deletes = 0;
+
+ oid drops_oid[] = { LLDP_OID, 1, 2, 4 };
+ size_t drops_oid_len = OID_LENGTH(drops_oid);
+ unsigned long drops = 0;
+
+ oid ageouts_oid[] = { LLDP_OID, 1, 2, 5 };
+ size_t ageouts_oid_len = OID_LENGTH(ageouts_oid);
+ unsigned long ageouts = 0;
+
+ /* We also add some extra. Easy ones. */
+ oid locport_oid[] = { LLDP_OID, 1, 3, 7, 1, 4, hardware->h_ifindex };
+ size_t locport_oid_len = OID_LENGTH(locport_oid);
+ oid sysname_oid[] = { LLDP_OID, 1, 4, 1, 1, 9, lastchange(rport),
+ hardware->h_ifindex, rport->p_chassis->c_index };
+ size_t sysname_oid_len = OID_LENGTH(sysname_oid);
+ oid portdescr_oid[] = { LLDP_OID, 1, 4, 1, 1, 8, lastchange(rport),
+ hardware->h_ifindex, rport->p_chassis->c_index };
+ size_t portdescr_oid_len = OID_LENGTH(portdescr_oid);
+
+ netsnmp_variable_list *notification_vars = NULL;
+
+ if (!hardware->h_cfg->g_snmp) return;
+
+ switch (type) {
+ case NEIGHBOR_CHANGE_DELETED:
+ log_debug("snmp", "send notification for neighbor deleted on %s",
+ hardware->h_ifname);
+ break;
+ case NEIGHBOR_CHANGE_UPDATED:
+ log_debug("snmp", "send notification for neighbor updated on %s",
+ hardware->h_ifname);
+ break;
+ case NEIGHBOR_CHANGE_ADDED:
+ log_debug("snmp", "send notification for neighbor added on %s",
+ hardware->h_ifname);
+ break;
+ }
+
+ TAILQ_FOREACH (h, &hardware->h_cfg->g_hardware, h_entries) {
+ inserts += h->h_insert_cnt;
+ deletes += h->h_delete_cnt;
+ ageouts += h->h_ageout_cnt;
+ drops += h->h_drop_cnt;
+ }
+
+ /* snmpTrapOID */
+ snmp_varlist_add_variable(&notification_vars, objid_snmptrap,
+ objid_snmptrap_len, ASN_OBJECT_ID, (u_char *)notification_oid,
+ notification_oid_len * sizeof(oid));
+
+ snmp_varlist_add_variable(&notification_vars, inserts_oid, inserts_oid_len,
+ ASN_GAUGE, (u_char *)&inserts, sizeof(inserts));
+ snmp_varlist_add_variable(&notification_vars, deletes_oid, deletes_oid_len,
+ ASN_GAUGE, (u_char *)&deletes, sizeof(inserts));
+ snmp_varlist_add_variable(&notification_vars, drops_oid, drops_oid_len,
+ ASN_GAUGE, (u_char *)&drops, sizeof(drops));
+ snmp_varlist_add_variable(&notification_vars, ageouts_oid, ageouts_oid_len,
+ ASN_GAUGE, (u_char *)&ageouts, sizeof(ageouts));
+
+ if (type != NEIGHBOR_CHANGE_DELETED) {
+ snmp_varlist_add_variable(&notification_vars, locport_oid,
+ locport_oid_len, ASN_OCTET_STR, (u_char *)hardware->h_ifname,
+ strnlen(hardware->h_ifname, IFNAMSIZ));
+ if (rport->p_chassis->c_name && *rport->p_chassis->c_name != '\0') {
+ snmp_varlist_add_variable(&notification_vars, sysname_oid,
+ sysname_oid_len, ASN_OCTET_STR,
+ (u_char *)rport->p_chassis->c_name,
+ strlen(rport->p_chassis->c_name));
+ }
+ if (rport->p_descr) {
+ snmp_varlist_add_variable(&notification_vars, portdescr_oid,
+ portdescr_oid_len, ASN_OCTET_STR, (u_char *)rport->p_descr,
+ strlen(rport->p_descr));
+ }
+ }
+
+ log_debug("snmp", "sending SNMP trap (%ld, %ld, %ld)", inserts, deletes,
+ ageouts);
+ send_v2trap(notification_vars);
+ snmp_free_varbind(notification_vars);
+}
+
+/* Logging NetSNMP messages */
+static int
+agent_log_callback(int major, int minor, void *serverarg, void *clientarg)
+{
+ struct snmp_log_message *slm = (struct snmp_log_message *)serverarg;
+ char *msg = strdup(slm->msg);
+ (void)major;
+ (void)minor;
+ (void)clientarg;
+
+ if (msg && msg[strlen(msg) - 1] == '\n') msg[strlen(msg) - 1] = '\0';
+ switch (slm->priority) {
+ case LOG_EMERG:
+ log_warnx("libsnmp", "%s", msg ? msg : slm->msg);
+ break;
+ case LOG_ALERT:
+ log_warnx("libsnmp", "%s", msg ? msg : slm->msg);
+ break;
+ case LOG_CRIT:
+ log_warnx("libsnmp", "%s", msg ? msg : slm->msg);
+ break;
+ case LOG_ERR:
+ log_warnx("libsnmp", "%s", msg ? msg : slm->msg);
+ break;
+ case LOG_WARNING:
+ log_warnx("libsnmp", "%s", msg ? msg : slm->msg);
+ break;
+ case LOG_NOTICE:
+ log_info("libsnmp", "%s", msg ? msg : slm->msg);
+ break;
+ case LOG_INFO:
+ log_info("libsnmp", "%s", msg ? msg : slm->msg);
+ break;
+ case LOG_DEBUG:
+ log_debug("libsnmp", "%s", msg ? msg : slm->msg);
+ break;
+ }
+ free(msg);
+ return SNMP_ERR_NOERROR;
+}
+
+void
+agent_init(struct lldpd *cfg, const char *agentx)
+{
+ int rc;
+
+ log_info("snmp", "enable SNMP subagent");
+ netsnmp_enable_subagent();
+
+ log_debug("snmp", "enable logging");
+ snmp_disable_log();
+ snmp_enable_calllog();
+ snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_LOGGING,
+ agent_log_callback, NULL);
+
+ scfg = cfg;
+
+ /* We are chrooted, we don't want to handle persistent states */
+ netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_PERSIST_STATE,
+ TRUE);
+ /* Do not load any MIB */
+ setenv("MIBS", "", 1);
+ setenv("MIBDIRS", "/dev/null", 1);
+
+#ifdef ENABLE_PRIVSEP
+ /* We provide our UNIX domain transport */
+ log_debug("snmp", "register UNIX domain transport");
+ agent_priv_register_domain();
+#endif
+
+ if (agentx)
+ netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID,
+ NETSNMP_DS_AGENT_X_SOCKET, agentx);
+ init_agent("lldpAgent");
+ REGISTER_MIB("lldp", agent_lldp_vars, variable8, lldp_oid);
+ init_snmp("lldpAgent");
+
+ log_debug("snmp", "register to sysORTable");
+ if ((rc = register_sysORTable(lldp_oid, OID_LENGTH(lldp_oid),
+ "lldpMIB implementation by lldpd")) != 0)
+ log_warnx("snmp", "unable to register to sysORTable (%d)", rc);
+}
+
+void
+agent_shutdown()
+{
+ log_debug("snmp", "agent shutdown");
+ unregister_sysORTable(lldp_oid, OID_LENGTH(lldp_oid));
+ snmp_shutdown("lldpAgent");
+}
diff --git a/src/daemon/agent.h b/src/daemon/agent.h
new file mode 100644
index 0000000..b498aeb
--- /dev/null
+++ b/src/daemon/agent.h
@@ -0,0 +1,35 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2008 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _AGENT_H
+#define _AGENT_H
+
+#include <net-snmp/net-snmp-config.h>
+#include <net-snmp/net-snmp-includes.h>
+#include <net-snmp/agent/net-snmp-agent-includes.h>
+#include <net-snmp/agent/snmp_vars.h>
+
+#ifndef RONLY
+# define RONLY NETSNMP_OLDAPI_RONLY
+#endif
+
+#define LLDP_OID 1, 0, 8802, 1, 1, 2
+#define SNMPTRAP_OID 1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0
+static oid lldp_oid[] = { LLDP_OID };
+size_t agent_lldp_vars_size(void);
+
+#endif
diff --git a/src/daemon/agent_priv.c b/src/daemon/agent_priv.c
new file mode 100644
index 0000000..b5cf72a
--- /dev/null
+++ b/src/daemon/agent_priv.c
@@ -0,0 +1,243 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2008 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/* Some of the code here (agent_priv_unix_*) has been adapted from code from
+ * Net-SNMP project (snmplib/snmpUnixDomain.c). Net-SNMP project is licensed
+ * using BSD and BSD-like licenses. I don't know the exact license of the file
+ * snmplib/snmpUnixDomain.c. */
+
+#include "lldpd.h"
+
+#include <unistd.h>
+#include <errno.h>
+#include <poll.h>
+
+#ifdef ENABLE_PRIVSEP
+# include <net-snmp/net-snmp-config.h>
+# include <net-snmp/net-snmp-includes.h>
+# include <net-snmp/agent/net-snmp-agent-includes.h>
+# include <net-snmp/agent/snmp_vars.h>
+# include <net-snmp/library/snmpUnixDomain.h>
+
+# ifdef ASN_PRIV_STOP
+/* NetSNMP 5.8+ */
+# define F_SEND_SIGNATURE \
+ netsnmp_transport *t, const void *buf, int size, void **opaque, int *olength
+# define F_FMTADDR_SIGNATURE netsnmp_transport *t, const void *data, int len
+# define F_FROM_OSTRING_SIGNATURE const void *o, size_t o_len, int local
+# else
+# define F_SEND_SIGNATURE \
+ netsnmp_transport *t, void *buf, int size, void **opaque, int *olength
+# define F_FMTADDR_SIGNATURE netsnmp_transport *t, void *data, int len
+# define F_FROM_OSTRING_SIGNATURE const u_char *o, size_t o_len, int local
+# endif
+
+static oid netsnmp_unix[] = { TRANSPORT_DOMAIN_LOCAL };
+static netsnmp_tdomain unixDomain;
+
+static char *
+agent_priv_unix_fmtaddr(F_FMTADDR_SIGNATURE)
+{
+ /* We don't bother to implement the full function */
+ return strdup("Local Unix socket with privilege separation: unknown");
+}
+
+static int
+agent_priv_unix_recv(netsnmp_transport *t, void *buf, int size, void **opaque,
+ int *olength)
+{
+ int rc = -1;
+ socklen_t tolen = sizeof(struct sockaddr_un);
+ struct sockaddr *to = NULL;
+
+ if (t == NULL || t->sock < 0) goto recv_error;
+ to = (struct sockaddr *)calloc(1, sizeof(struct sockaddr_un));
+ if (to == NULL) goto recv_error;
+ if (getsockname(t->sock, to, &tolen) != 0) goto recv_error;
+ while (rc < 0) {
+ rc = recv(t->sock, buf, size, 0);
+ /* TODO: handle the (unlikely) case where we get EAGAIN or EWOULDBLOCK
+ */
+ if (rc < 0 && errno != EINTR) {
+ log_warn("snmp", "unable to receive from fd %d", t->sock);
+ goto recv_error;
+ }
+ }
+ *opaque = (void *)to;
+ *olength = sizeof(struct sockaddr_un);
+ return rc;
+
+recv_error:
+ free(to);
+ *opaque = NULL;
+ *olength = 0;
+ return -1;
+}
+
+# define AGENT_WRITE_TIMEOUT 2000
+static int
+agent_priv_unix_send(F_SEND_SIGNATURE)
+{
+ int rc = -1;
+
+ if (t != NULL && t->sock >= 0) {
+ struct pollfd sagentx = { .fd = t->sock,
+ .events = POLLOUT | POLLERR | POLLHUP };
+ while (rc < 0) {
+ rc = poll(&sagentx, 1, AGENT_WRITE_TIMEOUT);
+ if (rc == 0) {
+ log_warnx("snmp",
+ "timeout while communicating with the master agent");
+ rc = -1;
+ break;
+ }
+ if (rc > 0) {
+ /* We can either write or have an error somewhere */
+ rc = send(t->sock, buf, size, 0);
+ if (rc < 0) {
+ if (errno == EAGAIN || errno == EWOULDBLOCK ||
+ errno == EINTR)
+ /* Let's retry */
+ continue;
+ log_warn("snmp",
+ "error while sending to master agent");
+ break;
+ }
+ } else {
+ if (errno != EINTR) {
+ log_warn("snmp",
+ "error while attempting to send to master agent");
+ break;
+ }
+ continue;
+ }
+ }
+ }
+ return rc;
+}
+
+static int
+agent_priv_unix_close(netsnmp_transport *t)
+{
+ int rc = 0;
+
+ if (t->sock >= 0) {
+ rc = close(t->sock);
+ t->sock = -1;
+ return rc;
+ }
+ return -1;
+}
+
+static int
+agent_priv_unix_accept(netsnmp_transport *t)
+{
+ log_warnx("snmp", "should not have been called");
+ return -1;
+}
+
+static netsnmp_transport *
+agent_priv_unix_transport(const char *string, int len, int local)
+{
+ struct sockaddr_un addr = { .sun_family = AF_UNIX };
+ netsnmp_transport *t = NULL;
+
+ if (local) {
+ log_warnx("snmp", "should not have been called for local transport");
+ return NULL;
+ }
+ if (!string) return NULL;
+ if (len >= sizeof(addr.sun_path) ||
+ strlcpy(addr.sun_path, string, sizeof(addr.sun_path)) >=
+ sizeof(addr.sun_path)) {
+ log_warnx("snmp", "path too long for Unix domain transport");
+ return NULL;
+ }
+
+ if ((t = (netsnmp_transport *)calloc(1, sizeof(netsnmp_transport))) == NULL)
+ return NULL;
+
+ t->domain = netsnmp_unix;
+ t->domain_length = sizeof(netsnmp_unix) / sizeof(netsnmp_unix[0]);
+
+ if ((t->sock = priv_snmp_socket(&addr)) < 0) {
+ netsnmp_transport_free(t);
+ return NULL;
+ }
+
+ t->flags = NETSNMP_TRANSPORT_FLAG_STREAM;
+
+ if ((t->remote = (u_char *)calloc(1, strlen(addr.sun_path) + 1)) == NULL) {
+ agent_priv_unix_close(t);
+ netsnmp_transport_free(t);
+ return NULL;
+ }
+ memcpy(t->remote, addr.sun_path, strlen(addr.sun_path));
+ t->remote_length = strlen(addr.sun_path);
+
+ t->msgMaxSize = 0x7fffffff;
+ t->f_recv = agent_priv_unix_recv;
+ t->f_send = agent_priv_unix_send;
+ t->f_close = agent_priv_unix_close;
+ t->f_accept = agent_priv_unix_accept;
+ t->f_fmtaddr = agent_priv_unix_fmtaddr;
+
+ return t;
+}
+
+# if HAVE_NETSNMP_TDOMAIN_F_CREATE_FROM_TSTRING_NEW
+static netsnmp_transport *
+agent_priv_unix_create_tstring_new(const char *string, int local,
+ const char *default_target)
+{
+ if ((!string || *string == '\0') && default_target && *default_target != '\0') {
+ string = default_target;
+ }
+ if (!string) return NULL;
+ return agent_priv_unix_transport(string, strlen(string), local);
+}
+# else
+static netsnmp_transport *
+agent_priv_unix_create_tstring(const char *string, int local)
+{
+ if (!string) return NULL;
+ return agent_priv_unix_transport(string, strlen(string), local);
+}
+# endif
+
+static netsnmp_transport *
+agent_priv_unix_create_ostring(F_FROM_OSTRING_SIGNATURE)
+{
+ return agent_priv_unix_transport((char *)o, o_len, local);
+}
+
+void
+agent_priv_register_domain()
+{
+ unixDomain.name = netsnmp_unix;
+ unixDomain.name_length = sizeof(netsnmp_unix) / sizeof(oid);
+ unixDomain.prefix = (const char **)calloc(2, sizeof(char *));
+ unixDomain.prefix[0] = "unix";
+# if HAVE_NETSNMP_TDOMAIN_F_CREATE_FROM_TSTRING_NEW
+ unixDomain.f_create_from_tstring_new = agent_priv_unix_create_tstring_new;
+# else
+ unixDomain.f_create_from_tstring = agent_priv_unix_create_tstring;
+# endif
+ unixDomain.f_create_from_ostring = agent_priv_unix_create_ostring;
+ netsnmp_tdomain_register(&unixDomain);
+}
+#endif
diff --git a/src/daemon/bitmap.c b/src/daemon/bitmap.c
new file mode 100644
index 0000000..c7a6330
--- /dev/null
+++ b/src/daemon/bitmap.c
@@ -0,0 +1,63 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2020 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/* Helpers around bitmaps */
+
+#include "lldpd.h"
+
+/*
+ * Set vlan id in the bitmap
+ */
+void
+bitmap_set(uint32_t *bmap, uint16_t vlan_id)
+{
+ if (vlan_id < MAX_VLAN) bmap[vlan_id / 32] |= (((uint32_t)1) << (vlan_id % 32));
+}
+
+/*
+ * Checks if the bitmap is empty
+ */
+int
+bitmap_isempty(uint32_t *bmap)
+{
+ int i;
+
+ for (i = 0; i < VLAN_BITMAP_LEN; i++) {
+ if (bmap[i] != 0) return 0;
+ }
+
+ return 1;
+}
+
+/*
+ * Calculate the number of bits set in the bitmap to get total
+ * number of VLANs
+ */
+unsigned int
+bitmap_numbits(uint32_t *bmap)
+{
+ unsigned int num = 0;
+
+ for (int i = 0; (i < VLAN_BITMAP_LEN); i++) {
+ uint32_t v = bmap[i];
+ v = v - ((v >> 1) & 0x55555555);
+ v = (v & 0x33333333) + ((v >> 2) & 0x33333333);
+ num += (((v + (v >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24;
+ }
+
+ return num;
+}
diff --git a/src/daemon/client.c b/src/daemon/client.c
new file mode 100644
index 0000000..d9d907f
--- /dev/null
+++ b/src/daemon/client.c
@@ -0,0 +1,700 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2008 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "lldpd.h"
+#include "trace.h"
+
+#include <sys/utsname.h>
+
+static ssize_t
+client_handle_none(struct lldpd *cfg, enum hmsg_type *type, void *input, int input_len,
+ void **output, int *subscribed)
+{
+ log_info("rpc", "received noop request from client");
+ *type = NONE;
+ return 0;
+}
+
+/* Return the global configuration */
+static ssize_t
+client_handle_get_configuration(struct lldpd *cfg, enum hmsg_type *type, void *input,
+ int input_len, void **output, int *subscribed)
+{
+ ssize_t output_len;
+ log_debug("rpc", "client requested configuration");
+ output_len = lldpd_config_serialize(&cfg->g_config, output);
+ if (output_len <= 0) {
+ output_len = 0;
+ *type = NONE;
+ }
+ return output_len;
+}
+
+static char *
+xstrdup(const char *str)
+{
+ if (!str) return NULL;
+ return strdup(str);
+}
+
+/* Change the global configuration */
+static ssize_t
+client_handle_set_configuration(struct lldpd *cfg, enum hmsg_type *type, void *input,
+ int input_len, void **output, int *subscribed)
+{
+ struct lldpd_config *config;
+
+ log_debug("rpc", "client request a change in configuration");
+ /* Get the proposed configuration. */
+ if (lldpd_config_unserialize(input, input_len, &config) <= 0) {
+ *type = NONE;
+ return 0;
+ }
+
+#define CHANGED(w) (config->w != cfg->g_config.w)
+#define CHANGED_STR(w) \
+ (!(config->w == cfg->g_config.w || \
+ (config->w && cfg->g_config.w && !strcmp(config->w, cfg->g_config.w))))
+
+ /* What needs to be done? Transmit delay? */
+ if (CHANGED(c_tx_interval) && config->c_tx_interval != 0) {
+ if (config->c_tx_interval < 0) {
+ log_debug("rpc", "client asked for immediate retransmission");
+ } else {
+ log_debug("rpc", "client change transmit interval to %d ms",
+ config->c_tx_interval);
+ cfg->g_config.c_tx_interval = config->c_tx_interval;
+ cfg->g_config.c_ttl =
+ cfg->g_config.c_tx_interval * cfg->g_config.c_tx_hold;
+ cfg->g_config.c_ttl = (cfg->g_config.c_ttl + 999) / 1000;
+ }
+ levent_send_now(cfg);
+ }
+ if (CHANGED(c_tx_hold) && config->c_tx_hold > 0) {
+ log_debug("rpc", "client change transmit hold to %d",
+ config->c_tx_hold);
+ cfg->g_config.c_tx_hold = config->c_tx_hold;
+ cfg->g_config.c_ttl =
+ cfg->g_config.c_tx_interval * cfg->g_config.c_tx_hold;
+ cfg->g_config.c_ttl = (cfg->g_config.c_ttl + 999) / 1000;
+ }
+ if (CHANGED(c_max_neighbors) && config->c_max_neighbors > 0) {
+ log_debug("rpc", "client change maximum neighbors to %d",
+ config->c_max_neighbors);
+ cfg->g_config.c_max_neighbors = config->c_max_neighbors;
+ }
+ if (CHANGED(c_lldp_portid_type) &&
+ config->c_lldp_portid_type > LLDP_PORTID_SUBTYPE_UNKNOWN &&
+ config->c_lldp_portid_type <= LLDP_PORTID_SUBTYPE_MAX) {
+ log_debug("rpc", "change lldp portid tlv subtype to %d",
+ config->c_lldp_portid_type);
+ cfg->g_config.c_lldp_portid_type = config->c_lldp_portid_type;
+ levent_update_now(cfg);
+ }
+ if (CHANGED(c_lldp_agent_type) &&
+ config->c_lldp_agent_type > LLDP_AGENT_TYPE_UNKNOWN &&
+ config->c_lldp_agent_type <= LLDP_AGENT_TYPE_MAX) {
+ log_debug("rpc", "change lldp agent type to %d",
+ config->c_lldp_agent_type);
+ cfg->g_config.c_lldp_agent_type = config->c_lldp_agent_type;
+ levent_update_now(cfg);
+ }
+ /* Pause/resume */
+ if (CHANGED(c_paused)) {
+ log_debug("rpc", "client asked to %s lldpd",
+ config->c_paused ? "pause" : "resume");
+ cfg->g_config.c_paused = config->c_paused;
+ levent_send_now(cfg);
+ }
+
+#ifdef ENABLE_LLDPMED
+ if (CHANGED(c_enable_fast_start)) {
+ cfg->g_config.c_enable_fast_start = config->c_enable_fast_start;
+ log_debug("rpc", "client asked to %s fast start",
+ cfg->g_config.c_enable_fast_start ? "enable" : "disable");
+ }
+ if (CHANGED(c_tx_fast_interval) && config->c_tx_fast_interval > 0) {
+ log_debug("rpc", "change fast interval to %d",
+ config->c_tx_fast_interval);
+ cfg->g_config.c_tx_fast_interval = config->c_tx_fast_interval;
+ }
+#endif
+ if (CHANGED_STR(c_iface_pattern)) {
+ log_debug("rpc", "change interface pattern to %s",
+ config->c_iface_pattern ? config->c_iface_pattern : "(NULL)");
+ free(cfg->g_config.c_iface_pattern);
+ cfg->g_config.c_iface_pattern = xstrdup(config->c_iface_pattern);
+ levent_update_now(cfg);
+ }
+ if (CHANGED_STR(c_perm_ifaces)) {
+ log_debug("rpc", "change permanent interface pattern to %s",
+ config->c_perm_ifaces ? config->c_perm_ifaces : "(NULL)");
+ free(cfg->g_config.c_perm_ifaces);
+ cfg->g_config.c_perm_ifaces = xstrdup(config->c_perm_ifaces);
+ levent_update_now(cfg);
+ }
+ if (CHANGED_STR(c_mgmt_pattern)) {
+ log_debug("rpc", "change management pattern to %s",
+ config->c_mgmt_pattern ? config->c_mgmt_pattern : "(NULL)");
+ free(cfg->g_config.c_mgmt_pattern);
+ cfg->g_config.c_mgmt_pattern = xstrdup(config->c_mgmt_pattern);
+ levent_update_now(cfg);
+ }
+ if (CHANGED_STR(c_cid_string)) {
+ log_debug("rpc", "change chassis ID string to %s",
+ config->c_cid_string ? config->c_cid_string : "(NULL)");
+ free(cfg->g_config.c_cid_string);
+ cfg->g_config.c_cid_string = xstrdup(config->c_cid_string);
+ free(LOCAL_CHASSIS(cfg)->c_id);
+ LOCAL_CHASSIS(cfg)->c_id = NULL;
+ lldpd_update_localchassis(cfg);
+ levent_update_now(cfg);
+ }
+ if (CHANGED_STR(c_description)) {
+ log_debug("rpc", "change chassis description to %s",
+ config->c_description ? config->c_description : "(NULL)");
+ free(cfg->g_config.c_description);
+ cfg->g_config.c_description = xstrdup(config->c_description);
+ lldpd_update_localchassis(cfg);
+ levent_update_now(cfg);
+ }
+ if (CHANGED_STR(c_platform)) {
+ log_debug("rpc", "change platform description to %s",
+ config->c_platform ? config->c_platform : "(NULL)");
+ free(cfg->g_config.c_platform);
+ cfg->g_config.c_platform = xstrdup(config->c_platform);
+ lldpd_update_localchassis(cfg);
+ levent_update_now(cfg);
+ }
+ if (CHANGED_STR(c_hostname)) {
+ log_debug("rpc", "change system name to %s",
+ config->c_hostname ? config->c_hostname : "(NULL)");
+ free(cfg->g_config.c_hostname);
+ cfg->g_config.c_hostname = xstrdup(config->c_hostname);
+ lldpd_update_localchassis(cfg);
+ levent_update_now(cfg);
+ }
+ if (CHANGED(c_set_ifdescr)) {
+ log_debug("rpc",
+ "%s setting of interface description based on discovered neighbors",
+ config->c_set_ifdescr ? "enable" : "disable");
+ cfg->g_config.c_set_ifdescr = config->c_set_ifdescr;
+ levent_update_now(cfg);
+ }
+ if (CHANGED(c_promisc)) {
+ log_debug("rpc", "%s promiscuous mode on managed interfaces",
+ config->c_promisc ? "enable" : "disable");
+ cfg->g_config.c_promisc = config->c_promisc;
+ levent_update_now(cfg);
+ }
+ if (CHANGED(c_cap_advertise)) {
+ log_debug("rpc", "%s chassis capabilities advertisement",
+ config->c_cap_advertise ? "enable" : "disable");
+ cfg->g_config.c_cap_advertise = config->c_cap_advertise;
+ levent_update_now(cfg);
+ }
+ if (CHANGED(c_cap_override)) {
+ log_debug("rpc", "%s chassis capabilities override",
+ config->c_cap_override ? "enable" : "disable");
+ cfg->g_config.c_cap_override = config->c_cap_override;
+ levent_update_now(cfg);
+ }
+ if (CHANGED(c_mgmt_advertise)) {
+ log_debug("rpc", "%s management addresses advertisement",
+ config->c_mgmt_advertise ? "enable" : "disable");
+ cfg->g_config.c_mgmt_advertise = config->c_mgmt_advertise;
+ levent_update_now(cfg);
+ }
+ if (CHANGED(c_bond_slave_src_mac_type)) {
+ if (config->c_bond_slave_src_mac_type >
+ LLDP_BOND_SLAVE_SRC_MAC_TYPE_UNKNOWN &&
+ config->c_bond_slave_src_mac_type <=
+ LLDP_BOND_SLAVE_SRC_MAC_TYPE_MAX) {
+ log_debug("rpc", "change bond src mac type to %d",
+ config->c_bond_slave_src_mac_type);
+ cfg->g_config.c_bond_slave_src_mac_type =
+ config->c_bond_slave_src_mac_type;
+ } else {
+ log_info("rpc", "Invalid bond slave src mac type: %d\n",
+ config->c_bond_slave_src_mac_type);
+ }
+ }
+
+ lldpd_config_cleanup(config);
+ free(config);
+
+ return 0;
+}
+
+/* Return the list of interfaces.
+ Input: nothing.
+ Output: list of interface names (lldpd_interface_list)
+*/
+static ssize_t
+client_handle_get_interfaces(struct lldpd *cfg, enum hmsg_type *type, void *input,
+ int input_len, void **output, int *subscribed)
+{
+ struct lldpd_interface *iff, *iff_next;
+ struct lldpd_hardware *hardware;
+ ssize_t output_len;
+
+ /* Build the list of interfaces */
+ struct lldpd_interface_list ifs;
+
+ log_debug("rpc", "client request the list of interfaces");
+ TAILQ_INIT(&ifs);
+ TAILQ_FOREACH (hardware, &cfg->g_hardware, h_entries) {
+ if ((iff = (struct lldpd_interface *)malloc(
+ sizeof(struct lldpd_interface))) == NULL)
+ fatal("rpc", NULL);
+ iff->name = hardware->h_ifname;
+ TAILQ_INSERT_TAIL(&ifs, iff, next);
+ }
+
+ output_len = lldpd_interface_list_serialize(&ifs, output);
+ if (output_len <= 0) {
+ output_len = 0;
+ *type = NONE;
+ }
+
+ /* Free the temporary list */
+ for (iff = TAILQ_FIRST(&ifs); iff != NULL; iff = iff_next) {
+ iff_next = TAILQ_NEXT(iff, next);
+ TAILQ_REMOVE(&ifs, iff, next);
+ free(iff);
+ }
+
+ return output_len;
+}
+
+/**
+ * Set local chassis info
+ * Input: chassis object
+ * Output: updated chassis object
+ */
+static ssize_t
+client_handle_set_local_chassis(struct lldpd *cfg, enum hmsg_type *type, void *input,
+ int input_len, void **output, int *subscribed)
+{
+ struct lldpd_chassis *chassis = NULL;
+ struct lldpd_chassis *local_chassis = NULL;
+#ifdef ENABLE_LLDPMED
+ struct utsname un;
+#endif
+
+ log_debug("rpc", "client request a change in chassis configuration");
+ if (lldpd_chassis_unserialize(input, input_len, &chassis) <= 0) {
+ *type = NONE;
+ return 0;
+ }
+
+ local_chassis = LOCAL_CHASSIS(cfg);
+
+#ifdef ENABLE_LLDPMED
+ free(local_chassis->c_med_hw);
+ local_chassis->c_med_hw =
+ (!chassis->c_med_hw) ? dmi_hw() : strdup(chassis->c_med_hw);
+
+ // Follows lldpd.c - only set sw if advertising is enabled
+ if (cfg->g_config.c_advertise_version) {
+ free(local_chassis->c_med_sw);
+
+ if (!chassis->c_med_sw) {
+ if (uname(&un) < 0) {
+ log_warn("rpc",
+ "Could not get default uname. Will continue anyway.");
+ local_chassis->c_med_sw = NULL;
+ } else {
+ local_chassis->c_med_sw = strdup(un.release);
+ }
+ } else {
+ local_chassis->c_med_sw = strdup(chassis->c_med_sw);
+ }
+ }
+
+ free(local_chassis->c_med_fw);
+ local_chassis->c_med_fw =
+ (!chassis->c_med_fw) ? dmi_fw() : strdup(chassis->c_med_fw);
+
+ free(local_chassis->c_med_sn);
+ local_chassis->c_med_sn =
+ (!chassis->c_med_sn) ? dmi_sn() : strdup(chassis->c_med_sn);
+
+ free(local_chassis->c_med_manuf);
+ local_chassis->c_med_manuf =
+ (!chassis->c_med_manuf) ? dmi_manuf() : strdup(chassis->c_med_manuf);
+
+ free(local_chassis->c_med_model);
+ local_chassis->c_med_model =
+ (!chassis->c_med_model) ? dmi_model() : strdup(chassis->c_med_model);
+
+ free(local_chassis->c_med_asset);
+ local_chassis->c_med_asset =
+ (!chassis->c_med_asset) ? dmi_asset() : strdup(chassis->c_med_asset);
+#endif
+
+ if (chassis->c_cap_enabled != local_chassis->c_cap_enabled) {
+ local_chassis->c_cap_enabled = chassis->c_cap_enabled;
+ log_debug("rpc", "change capabilities enabled to: %d",
+ local_chassis->c_cap_enabled);
+ }
+
+#ifdef ENABLE_LLDPMED
+ log_debug("rpc", "change hardware-revision to: %s", local_chassis->c_med_hw);
+ log_debug("rpc", "change software-revision to: %s", local_chassis->c_med_sw);
+ log_debug("rpc", "change firmware-revision to: %s", local_chassis->c_med_fw);
+ log_debug("rpc", "change serial-number to: %s", local_chassis->c_med_sn);
+ log_debug("rpc", "change manufacturer to: %s", local_chassis->c_med_manuf);
+ log_debug("rpc", "change model to: %s", local_chassis->c_med_model);
+ log_debug("rpc", "change asset to: %s", local_chassis->c_med_asset);
+#endif
+
+ lldpd_chassis_cleanup(chassis, 1);
+
+ ssize_t output_len = lldpd_chassis_serialize(local_chassis, output);
+ if (output_len <= 0) {
+ *type = NONE;
+ return 0;
+ }
+
+ return output_len;
+}
+
+/* Return the local chassis.
+ Input: nothing.
+ Output: local chassis (lldpd_chassis)
+*/
+static ssize_t
+client_handle_get_local_chassis(struct lldpd *cfg, enum hmsg_type *type, void *input,
+ int input_len, void **output, int *subscribed)
+{
+ struct lldpd_chassis *chassis = LOCAL_CHASSIS(cfg);
+ ssize_t output_len;
+
+ log_debug("rpc", "client request the local chassis");
+ output_len = lldpd_chassis_serialize(chassis, output);
+ if (output_len <= 0) {
+ output_len = 0;
+ *type = NONE;
+ }
+
+ return output_len;
+}
+
+/* Return all available information related to an interface
+ Input: name of the interface (serialized)
+ Output: Information about the interface (lldpd_hardware)
+*/
+static ssize_t
+client_handle_get_interface(struct lldpd *cfg, enum hmsg_type *type, void *input,
+ int input_len, void **output, int *subscribed)
+{
+ char *name;
+ struct lldpd_hardware *hardware;
+ void *p;
+
+ /* Get name of the interface */
+ if (marshal_unserialize(string, input, input_len, &p) <= 0) {
+ *type = NONE;
+ return 0;
+ }
+ name = p;
+
+ /* Search appropriate hardware */
+ log_debug("rpc", "client request interface %s", name);
+ TAILQ_FOREACH (hardware, &cfg->g_hardware, h_entries)
+ if (!strcmp(hardware->h_ifname, name)) {
+ ssize_t output_len = lldpd_hardware_serialize(hardware, output);
+ free(name);
+ if (output_len <= 0) {
+ *type = NONE;
+ return 0;
+ }
+ return output_len;
+ }
+
+ log_warnx("rpc", "no interface %s found", name);
+ free(name);
+ *type = NONE;
+ return 0;
+}
+
+/* Return all available information related to an interface
+ Input: name of the interface (serialized)
+ Output: Information about the interface (lldpd_hardware)
+*/
+static ssize_t
+client_handle_get_default_port(struct lldpd *cfg, enum hmsg_type *type, void *input,
+ int input_len, void **output, int *subscribed)
+{
+ log_debug("rpc", "client request the default local port");
+ ssize_t output_len = lldpd_port_serialize(cfg->g_default_local_port, output);
+ if (output_len <= 0) {
+ *type = NONE;
+ return 0;
+ }
+ return output_len;
+}
+
+static int
+_client_handle_set_port(struct lldpd *cfg, struct lldpd_port *port,
+ struct lldpd_port_set *set)
+{
+#ifdef ENABLE_LLDPMED
+ struct lldpd_med_loc *loc = NULL;
+#endif
+ if (set->local_id) {
+ log_debug("rpc", "requested change to Port ID");
+ free(port->p_id);
+ port->p_id = strdup(set->local_id);
+ port->p_id_len = strlen(set->local_id);
+ port->p_id_subtype = LLDP_PORTID_SUBTYPE_LOCAL;
+ port->p_descr_force = 0;
+ }
+ if (set->local_descr) {
+ log_debug("rpc", "requested change to Port Description");
+ free(port->p_descr);
+ port->p_descr = strdup(set->local_descr);
+ port->p_descr_force = 1;
+ }
+ switch (set->rxtx) {
+ case LLDPD_RXTX_TXONLY:
+ log_debug("rpc", "requested TX only mode");
+ port->p_disable_rx = 1;
+ port->p_disable_tx = 0;
+ break;
+ case LLDPD_RXTX_RXONLY:
+ log_debug("rpc", "requested RX only mode");
+ port->p_disable_rx = 0;
+ port->p_disable_tx = 1;
+ break;
+ case LLDPD_RXTX_BOTH:
+ log_debug("rpc", "requested RX/TX mode");
+ port->p_disable_rx = port->p_disable_tx = 0;
+ break;
+ case LLDPD_RXTX_DISABLED:
+ log_debug("rpc", "requested disabled mode");
+ port->p_disable_rx = port->p_disable_tx = 1;
+ break;
+ }
+ if (set->vlan_tx_enabled > -1) {
+ port->p_vlan_tx_enabled = set->vlan_tx_enabled;
+ port->p_vlan_tx_tag = set->vlan_tx_tag;
+ }
+#ifdef ENABLE_LLDPMED
+ if (set->med_policy && set->med_policy->type > 0) {
+ log_debug("rpc", "requested change to MED policy");
+ if (set->med_policy->type > LLDP_MED_APPTYPE_LAST) {
+ log_warnx("rpc", "invalid policy provided: %d",
+ set->med_policy->type);
+ return -1;
+ }
+ memcpy(&port->p_med_policy[set->med_policy->type - 1], set->med_policy,
+ sizeof(struct lldpd_med_policy));
+ port->p_med_cap_enabled |= LLDP_MED_CAP_POLICY;
+ }
+ if (set->med_location && set->med_location->format > 0) {
+ char *newdata = NULL;
+ log_debug("rpc", "requested change to MED location");
+ if (set->med_location->format > LLDP_MED_LOCFORMAT_LAST) {
+ log_warnx("rpc", "invalid location format provided: %d",
+ set->med_location->format);
+ return -1;
+ }
+ loc = &port->p_med_location[set->med_location->format - 1];
+ free(loc->data);
+ memcpy(loc, set->med_location, sizeof(struct lldpd_med_loc));
+ if (!loc->data || !(newdata = malloc(loc->data_len))) loc->data_len = 0;
+ if (newdata) memcpy(newdata, loc->data, loc->data_len);
+ loc->data = newdata;
+ port->p_med_cap_enabled |= LLDP_MED_CAP_LOCATION;
+ }
+ if (set->med_power) {
+ log_debug("rpc", "requested change to MED power");
+ memcpy(&port->p_med_power, set->med_power,
+ sizeof(struct lldpd_med_power));
+ switch (set->med_power->devicetype) {
+ case LLDP_MED_POW_TYPE_PD:
+ port->p_med_cap_enabled |= LLDP_MED_CAP_MDI_PD;
+ port->p_med_cap_enabled &= ~LLDP_MED_CAP_MDI_PSE;
+ break;
+ case LLDP_MED_POW_TYPE_PSE:
+ port->p_med_cap_enabled |= LLDP_MED_CAP_MDI_PSE;
+ port->p_med_cap_enabled &= ~LLDP_MED_CAP_MDI_PD;
+ break;
+ }
+ }
+#endif
+#ifdef ENABLE_DOT3
+ if (set->dot3_power) {
+ log_debug("rpc", "requested change to Dot3 power");
+ memcpy(&port->p_power, set->dot3_power,
+ sizeof(struct lldpd_dot3_power));
+ }
+#endif
+#ifdef ENABLE_CUSTOM
+ if (set->custom_list_clear) {
+ log_debug("rpc", "requested custom TLVs clear");
+ lldpd_custom_list_cleanup(port);
+ } else {
+ if (set->custom) {
+ log_info("rpc",
+ "custom TLV op %s oui %02x:%02x:%02x subtype %x",
+ (set->custom_tlv_op == CUSTOM_TLV_REMOVE) ? "remove" :
+ (set->custom_tlv_op == CUSTOM_TLV_ADD) ? "add" :
+ "replace",
+ set->custom->oui[0], set->custom->oui[1],
+ set->custom->oui[2], set->custom->subtype);
+ switch (set->custom_tlv_op) {
+ case CUSTOM_TLV_REMOVE:
+ lldpd_custom_tlv_cleanup(port, set->custom);
+ break;
+ case CUSTOM_TLV_ADD:
+ lldpd_custom_tlv_add(port, set->custom);
+ break;
+ case CUSTOM_TLV_REPLACE:
+ default:
+ lldpd_custom_tlv_cleanup(port, set->custom);
+ lldpd_custom_tlv_add(port, set->custom);
+ break;
+ }
+ }
+ }
+#endif
+ return 0;
+}
+
+/* Set some port related settings (policy, location, power)
+ Input: name of the interface, policy/location/power setting to be modified
+ Output: nothing
+*/
+static ssize_t
+client_handle_set_port(struct lldpd *cfg, enum hmsg_type *type, void *input,
+ int input_len, void **output, int *subscribed)
+{
+ int ret = 0;
+ struct lldpd_port_set *set = NULL;
+ struct lldpd_hardware *hardware = NULL;
+
+ if (lldpd_port_set_unserialize(input, input_len, &set) <= 0) {
+ *type = NONE;
+ return 0;
+ }
+ if (!set->ifname) {
+ log_warnx("rpc", "no interface provided");
+ goto set_port_finished;
+ }
+
+ /* Search the appropriate hardware */
+ if (strlen(set->ifname) == 0) {
+ log_debug("rpc", "client request change to default port");
+ if (_client_handle_set_port(cfg, cfg->g_default_local_port, set) == -1)
+ goto set_port_finished;
+ ret = 1;
+ } else {
+ log_debug("rpc", "client request change to port %s", set->ifname);
+ TAILQ_FOREACH (hardware, &cfg->g_hardware, h_entries) {
+ if (!strcmp(hardware->h_ifname, set->ifname)) {
+ struct lldpd_port *port = &hardware->h_lport;
+ if (_client_handle_set_port(cfg, port, set) == -1)
+ goto set_port_finished;
+ ret = 1;
+ break;
+ }
+ }
+ }
+
+ if (ret == 0)
+ log_warn("rpc", "no interface %s found", set->ifname);
+ else
+ levent_update_now(cfg);
+
+set_port_finished:
+ if (!ret) *type = NONE;
+ free(set->ifname);
+ free(set->local_id);
+ free(set->local_descr);
+#ifdef ENABLE_LLDPMED
+ free(set->med_policy);
+ if (set->med_location) free(set->med_location->data);
+ free(set->med_location);
+ free(set->med_power);
+#endif
+#ifdef ENABLE_DOT3
+ free(set->dot3_power);
+#endif
+#ifdef ENABLE_CUSTOM
+ if (set->custom) {
+ free(set->custom->oui_info);
+ free(set->custom);
+ }
+#endif
+ free(set);
+ return 0;
+}
+
+/* Register subscribtion to neighbor changes */
+static ssize_t
+client_handle_subscribe(struct lldpd *cfg, enum hmsg_type *type, void *input,
+ int input_len, void **output, int *subscribed)
+{
+ log_debug("rpc", "client subscribe to changes");
+ *subscribed = 1;
+ return 0;
+}
+
+struct client_handle {
+ enum hmsg_type type;
+ const char *name;
+ ssize_t (
+ *handle)(struct lldpd *, enum hmsg_type *, void *, int, void **, int *);
+};
+
+static struct client_handle client_handles[] = { { NONE, "None", client_handle_none },
+ { GET_CONFIG, "Get configuration", client_handle_get_configuration },
+ { SET_CONFIG, "Set configuration", client_handle_set_configuration },
+ { GET_INTERFACES, "Get interfaces", client_handle_get_interfaces },
+ { GET_INTERFACE, "Get interface", client_handle_get_interface },
+ { GET_DEFAULT_PORT, "Get default port", client_handle_get_default_port },
+ { SET_CHASSIS, "Set local chassis", client_handle_set_local_chassis },
+ { GET_CHASSIS, "Get local chassis", client_handle_get_local_chassis },
+ { SET_PORT, "Set port", client_handle_set_port },
+ { SUBSCRIBE, "Subscribe", client_handle_subscribe }, { 0, NULL } };
+
+int
+client_handle_client(struct lldpd *cfg, ssize_t (*send)(void *, int, void *, size_t),
+ void *out, enum hmsg_type type, void *buffer, size_t n, int *subscribed)
+{
+ struct client_handle *ch;
+ void *answer;
+ ssize_t len, sent;
+
+ log_debug("rpc", "handle client request");
+ for (ch = client_handles; ch->handle != NULL; ch++) {
+ if (ch->type == type) {
+ TRACE(LLDPD_CLIENT_REQUEST(ch->name));
+ answer = NULL;
+ len = ch->handle(cfg, &type, buffer, n, &answer, subscribed);
+ sent = send(out, type, answer, len);
+ free(answer);
+ return sent;
+ }
+ }
+
+ log_warnx("rpc", "unknown message request (%d) received", type);
+ return -1;
+}
diff --git a/src/daemon/dmi-dummy.c b/src/daemon/dmi-dummy.c
new file mode 100644
index 0000000..2954d50
--- /dev/null
+++ b/src/daemon/dmi-dummy.c
@@ -0,0 +1,57 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2012 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "lldpd.h"
+
+#ifdef ENABLE_LLDPMED
+
+char *
+dmi_hw()
+{
+ return NULL;
+}
+
+char *
+dmi_fw()
+{
+ return NULL;
+}
+
+char *
+dmi_sn()
+{
+ return NULL;
+}
+
+char *
+dmi_manuf()
+{
+ return NULL;
+}
+
+char *
+dmi_model()
+{
+ return NULL;
+}
+
+char *
+dmi_asset()
+{
+ return NULL;
+}
+#endif
diff --git a/src/daemon/dmi-freebsd.c b/src/daemon/dmi-freebsd.c
new file mode 100644
index 0000000..f20b71b
--- /dev/null
+++ b/src/daemon/dmi-freebsd.c
@@ -0,0 +1,82 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2012 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "lldpd.h"
+#include <unistd.h>
+#include <kenv.h>
+
+#ifdef ENABLE_LLDPMED
+/* Fill in inventory stuff:
+ - hardware version: smbios.system.version
+ - firmware version: smbios.bios.version
+ - software version: `uname -r`
+ - serial number: smbios.system.serial
+ - manufacturer: smbios.system.maker
+ - model: smbios.system.product
+ - asset: smbios.chassis.tag
+*/
+
+static char *
+dmi_get(char *file)
+{
+ char buffer[100] = {};
+
+ log_debug("localchassis", "DMI request for %s", file);
+ if (kenv(KENV_GET, file, buffer, sizeof(buffer) - 1) == -1) {
+ log_debug("localchassis", "cannot get %s", file);
+ return NULL;
+ }
+ if (strlen(buffer)) return strdup(buffer);
+ return NULL;
+}
+
+char *
+dmi_hw()
+{
+ return dmi_get("smbios.system.version");
+}
+
+char *
+dmi_fw()
+{
+ return dmi_get("smbios.bios.version");
+}
+
+char *
+dmi_sn()
+{
+ return dmi_get("smbios.system.serial");
+}
+
+char *
+dmi_manuf()
+{
+ return dmi_get("smbios.system.maker");
+}
+
+char *
+dmi_model()
+{
+ return dmi_get("smibios.system.product");
+}
+
+char *
+dmi_asset()
+{
+ return dmi_get("smibios.chassis.tag");
+}
+#endif
diff --git a/src/daemon/dmi-linux.c b/src/daemon/dmi-linux.c
new file mode 100644
index 0000000..47a6d1b
--- /dev/null
+++ b/src/daemon/dmi-linux.c
@@ -0,0 +1,90 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2009 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "lldpd.h"
+#include <unistd.h>
+
+#ifdef ENABLE_LLDPMED
+/* Fill in inventory stuff:
+ - hardware version: /sys/class/dmi/id/product_version
+ - firmware version: /sys/class/dmi/id/bios_version
+ - software version: `uname -r`
+ - serial number: /sys/class/dmi/id/product_serial
+ - manufacturer: /sys/class/dmi/id/sys_vendor
+ - model: /sys/class/dmi/id/product_name
+ - asset: /sys/class/dmi/id/chassis_asset_tag
+*/
+
+static char *
+dmi_get(const char *file)
+{
+ int dmi, s;
+ char buffer[100] = {};
+
+ log_debug("localchassis", "DMI request for file %s", file);
+ if ((dmi = priv_open(file)) < 0) {
+ log_debug("localchassis", "cannot get DMI file %s", file);
+ return NULL;
+ }
+ if ((s = read(dmi, buffer, sizeof(buffer))) == -1) {
+ log_debug("localchassis", "cannot read DMI file %s", file);
+ close(dmi);
+ return NULL;
+ }
+ close(dmi);
+ buffer[sizeof(buffer) - 1] = '\0';
+ if ((s > 0) && (buffer[s - 1] == '\n')) buffer[s - 1] = '\0';
+ if (strlen(buffer)) return strdup(buffer);
+ return NULL;
+}
+
+char *
+dmi_hw()
+{
+ return dmi_get(SYSFS_CLASS_DMI "product_version");
+}
+
+char *
+dmi_fw()
+{
+ return dmi_get(SYSFS_CLASS_DMI "bios_version");
+}
+
+char *
+dmi_sn()
+{
+ return dmi_get(SYSFS_CLASS_DMI "product_serial");
+}
+
+char *
+dmi_manuf()
+{
+ return dmi_get(SYSFS_CLASS_DMI "sys_vendor");
+}
+
+char *
+dmi_model()
+{
+ return dmi_get(SYSFS_CLASS_DMI "product_name");
+}
+
+char *
+dmi_asset()
+{
+ return dmi_get(SYSFS_CLASS_DMI "chassis_asset_tag");
+}
+#endif
diff --git a/src/daemon/dmi-openbsd.c b/src/daemon/dmi-openbsd.c
new file mode 100644
index 0000000..a226829
--- /dev/null
+++ b/src/daemon/dmi-openbsd.c
@@ -0,0 +1,73 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2012 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "lldpd.h"
+#include <sys/param.h>
+#include <sys/sysctl.h>
+
+#ifdef ENABLE_LLDPMED
+
+static char *
+dmi_get(int what, const char *descr)
+{
+ char result[100] = {};
+ size_t len = sizeof(result) - 1;
+ int mib[2] = { CTL_HW, what };
+ if (sysctl(mib, 2, result, &len, NULL, 0) == -1) {
+ log_debug("localchassis", "cannot get %s", descr);
+ return NULL;
+ }
+ log_debug("localchassis", "got `%s` for %s", result, descr);
+ return strdup(result);
+}
+
+char *
+dmi_hw()
+{
+ return dmi_get(HW_VERSION, "hardware revision");
+}
+
+char *
+dmi_fw()
+{
+ return NULL;
+}
+
+char *
+dmi_sn()
+{
+ return dmi_get(HW_SERIALNO, "serial number");
+}
+
+char *
+dmi_manuf()
+{
+ return dmi_get(HW_VENDOR, "hardware vendor");
+}
+
+char *
+dmi_model()
+{
+ return dmi_get(HW_PRODUCT, "hardware product");
+}
+
+char *
+dmi_asset()
+{
+ return dmi_get(HW_UUID, "hardware UUID");
+}
+#endif
diff --git a/src/daemon/dmi-osx.c b/src/daemon/dmi-osx.c
new file mode 100644
index 0000000..cde8676
--- /dev/null
+++ b/src/daemon/dmi-osx.c
@@ -0,0 +1,109 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2012 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "lldpd.h"
+
+#include <CoreFoundation/CoreFoundation.h>
+#include <IOKit/IOKitLib.h>
+
+#ifdef ENABLE_LLDPMED
+static char *
+dmi_get(const char *classname, CFStringRef property)
+{
+ char *result = NULL;
+ CFMutableDictionaryRef matching = NULL;
+ CFTypeRef cfres = NULL;
+ io_service_t service = 0;
+ matching = IOServiceMatching(classname);
+ if (!matching) {
+ log_debug("localchassis", "cannot get %s class from registry",
+ classname);
+ goto end;
+ }
+ service = IOServiceGetMatchingService(kIOMasterPortDefault, matching);
+ if (!service) {
+ log_warnx("localchassis", "cannot get matching %s class from registry",
+ classname);
+ goto end;
+ }
+ cfres = IORegistryEntryCreateCFProperty(service, property, kCFAllocatorDefault,
+ kNilOptions);
+ if (!cfres) {
+ log_debug("localchassis",
+ "cannot find property %s in class %s in registry",
+ CFStringGetCStringPtr(property, kCFStringEncodingMacRoman),
+ classname);
+ goto end;
+ }
+
+ if (CFGetTypeID(cfres) == CFStringGetTypeID())
+ result = strdup(CFStringGetCStringPtr((CFStringRef)cfres,
+ kCFStringEncodingMacRoman));
+ else if (CFGetTypeID(cfres) == CFDataGetTypeID()) {
+ /* OK, we know this is a string. */
+ result = calloc(1, CFDataGetLength((CFDataRef)cfres) + 1);
+ if (!result) goto end;
+ memcpy(result, CFDataGetBytePtr((CFDataRef)cfres),
+ CFDataGetLength((CFDataRef)cfres));
+ } else
+ log_debug("localchassis", "unknown type for property %s in class %s",
+ CFStringGetCStringPtr(property, kCFStringEncodingMacRoman),
+ classname);
+
+end:
+ if (cfres) CFRelease(cfres);
+ if (service) IOObjectRelease(service);
+ return result;
+}
+
+char *
+dmi_hw()
+{
+ return dmi_get("IOPlatformExpertDevice", CFSTR("version"));
+}
+
+char *
+dmi_fw()
+{
+ /* Dunno where it is. Maybe in SMC? */
+ return NULL;
+}
+
+char *
+dmi_sn()
+{
+ return dmi_get("IOPlatformExpertDevice", CFSTR("IOPlatformSerialNumber"));
+}
+
+char *
+dmi_manuf()
+{
+ return dmi_get("IOPlatformExpertDevice", CFSTR("manufacturer"));
+}
+
+char *
+dmi_model()
+{
+ return dmi_get("IOPlatformExpertDevice", CFSTR("model"));
+}
+
+char *
+dmi_asset()
+{
+ return dmi_get("IOPlatformExpertDevice", CFSTR("board-id"));
+}
+#endif
diff --git a/src/daemon/dtrace2systemtap.awk b/src/daemon/dtrace2systemtap.awk
new file mode 100644
index 0000000..3761008
--- /dev/null
+++ b/src/daemon/dtrace2systemtap.awk
@@ -0,0 +1,25 @@
+#!/usr/bin/awk -f
+
+# Convert a simple dtrace probe files into a tapset. Heavily inspired
+# by dtrace2systemtap.pl from libvirt
+
+($1 == "provider") {
+ provider = $2
+}
+
+($1 == "probe") {
+ name = substr($2, 0, index($2, "(") - 1)
+ split(substr($0, index($0, "(") + 1, index($0, ")") - index($0, "(") - 1),
+ args, /, /)
+ printf "probe %s.%s = process(\"%s/%s\").provider(\"%s\").mark(\"%s\") {\n", provider, name, sbindir, provider, provider, name
+ for (arg in args) {
+ match(args[arg], /^(.+[^a-z_])([a-z_]+)$/, aarg)
+ type = aarg[1]
+ argname = aarg[2]
+ if (type == "char *")
+ printf " %s = user_string($arg%d);\n", argname, arg
+ else
+ printf " %s = $arg%d;\n", argname, arg
+ }
+ printf "}\n\n"
+}
diff --git a/src/daemon/event.c b/src/daemon/event.c
new file mode 100644
index 0000000..971500f
--- /dev/null
+++ b/src/daemon/event.c
@@ -0,0 +1,911 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2012 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "lldpd.h"
+#include "trace.h"
+
+#include <unistd.h>
+#include <signal.h>
+#include <errno.h>
+#include <time.h>
+#include <fcntl.h>
+#if defined(__clang__)
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wdocumentation"
+#endif
+#include <event2/event.h>
+#include <event2/bufferevent.h>
+#include <event2/buffer.h>
+#if defined(__clang__)
+# pragma clang diagnostic pop
+#endif
+
+#define EVENT_BUFFER 1024
+
+static void
+levent_log_cb(int severity, const char *msg)
+{
+ switch (severity) {
+ case _EVENT_LOG_DEBUG:
+ log_debug("libevent", "%s", msg);
+ break;
+ case _EVENT_LOG_MSG:
+ log_info("libevent", "%s", msg);
+ break;
+ case _EVENT_LOG_WARN:
+ log_warnx("libevent", "%s", msg);
+ break;
+ case _EVENT_LOG_ERR:
+ log_warnx("libevent", "%s", msg);
+ break;
+ }
+}
+
+struct lldpd_events {
+ TAILQ_ENTRY(lldpd_events) next;
+ struct event *ev;
+};
+TAILQ_HEAD(ev_l, lldpd_events);
+
+#define levent_snmp_fds(cfg) ((struct ev_l *)(cfg)->g_snmp_fds)
+#define levent_hardware_fds(hardware) ((struct ev_l *)(hardware)->h_recv)
+
+#ifdef USE_SNMP
+# include <net-snmp/net-snmp-config.h>
+# include <net-snmp/net-snmp-includes.h>
+# include <net-snmp/agent/net-snmp-agent-includes.h>
+# include <net-snmp/agent/snmp_vars.h>
+
+/* Compatibility with older versions of NetSNMP */
+# ifndef HAVE_SNMP_SELECT_INFO2
+# define netsnmp_large_fd_set fd_set
+# define snmp_read2 snmp_read
+# define snmp_select_info2 snmp_select_info
+# define netsnmp_large_fd_set_init(...)
+# define netsnmp_large_fd_set_cleanup(...)
+# define NETSNMP_LARGE_FD_SET FD_SET
+# define NETSNMP_LARGE_FD_CLR FD_CLR
+# define NETSNMP_LARGE_FD_ZERO FD_ZERO
+# define NETSNMP_LARGE_FD_ISSET FD_ISSET
+# else
+# include <net-snmp/library/large_fd_set.h>
+# endif
+
+static void levent_snmp_update(struct lldpd *);
+
+/*
+ * Callback function when we have something to read from SNMP.
+ *
+ * This function is called because we have a read event on one SNMP
+ * file descriptor. When need to call snmp_read() on it.
+ */
+static void
+levent_snmp_read(evutil_socket_t fd, short what, void *arg)
+{
+ struct lldpd *cfg = arg;
+ netsnmp_large_fd_set fdset;
+ (void)what;
+ netsnmp_large_fd_set_init(&fdset, FD_SETSIZE);
+ NETSNMP_LARGE_FD_ZERO(&fdset);
+ NETSNMP_LARGE_FD_SET(fd, &fdset);
+ snmp_read2(&fdset);
+ levent_snmp_update(cfg);
+}
+
+/*
+ * Callback function for a SNMP timeout.
+ *
+ * A SNMP timeout has occurred. Call `snmp_timeout()` to handle it.
+ */
+static void
+levent_snmp_timeout(evutil_socket_t fd, short what, void *arg)
+{
+ struct lldpd *cfg = arg;
+ (void)what;
+ (void)fd;
+ snmp_timeout();
+ run_alarms();
+ levent_snmp_update(cfg);
+}
+
+/*
+ * Watch a new SNMP FD.
+ *
+ * @param base The libevent base we are working on.
+ * @param fd The file descriptor we want to watch.
+ *
+ * The file descriptor is appended to the list of file descriptors we
+ * want to watch.
+ */
+static void
+levent_snmp_add_fd(struct lldpd *cfg, int fd)
+{
+ struct event_base *base = cfg->g_base;
+ struct lldpd_events *snmpfd = calloc(1, sizeof(struct lldpd_events));
+ if (!snmpfd) {
+ log_warn("event", "unable to allocate memory for new SNMP event");
+ return;
+ }
+ levent_make_socket_nonblocking(fd);
+ if ((snmpfd->ev = event_new(base, fd, EV_READ | EV_PERSIST, levent_snmp_read,
+ cfg)) == NULL) {
+ log_warnx("event", "unable to allocate a new SNMP event for FD %d", fd);
+ free(snmpfd);
+ return;
+ }
+ if (event_add(snmpfd->ev, NULL) == -1) {
+ log_warnx("event", "unable to schedule new SNMP event for FD %d", fd);
+ event_free(snmpfd->ev);
+ free(snmpfd);
+ return;
+ }
+ TAILQ_INSERT_TAIL(levent_snmp_fds(cfg), snmpfd, next);
+}
+
+/*
+ * Update SNMP event loop.
+ *
+ * New events are added and some other are removed. This function
+ * should be called every time a SNMP event happens: either when
+ * handling a SNMP packet, a SNMP timeout or when sending a SNMP
+ * packet. This function will keep libevent in sync with NetSNMP.
+ *
+ * @param base The libevent base we are working on.
+ */
+static void
+levent_snmp_update(struct lldpd *cfg)
+{
+ int maxfd = 0;
+ int block = 1;
+ struct timeval timeout;
+ static int howmany = 0;
+ int added = 0, removed = 0, current = 0;
+ struct lldpd_events *snmpfd, *snmpfd_next;
+
+ /* snmp_select_info() can be tricky to understand. We set `block` to
+ 1 to means that we don't request a timeout. snmp_select_info()
+ will reset `block` to 0 if it wants us to setup a timeout. In
+ this timeout, `snmp_timeout()` should be invoked.
+
+ Each FD in `fdset` will need to be watched for reading. If one of
+ them become active, `snmp_read()` should be called on it.
+ */
+
+ netsnmp_large_fd_set fdset;
+ netsnmp_large_fd_set_init(&fdset, FD_SETSIZE);
+ NETSNMP_LARGE_FD_ZERO(&fdset);
+ snmp_select_info2(&maxfd, &fdset, &timeout, &block);
+
+ /* We need to untrack any event whose FD is not in `fdset`
+ anymore */
+ for (snmpfd = TAILQ_FIRST(levent_snmp_fds(cfg)); snmpfd; snmpfd = snmpfd_next) {
+ snmpfd_next = TAILQ_NEXT(snmpfd, next);
+ if (event_get_fd(snmpfd->ev) >= maxfd ||
+ (!NETSNMP_LARGE_FD_ISSET(event_get_fd(snmpfd->ev), &fdset))) {
+ event_free(snmpfd->ev);
+ TAILQ_REMOVE(levent_snmp_fds(cfg), snmpfd, next);
+ free(snmpfd);
+ removed++;
+ } else {
+ NETSNMP_LARGE_FD_CLR(event_get_fd(snmpfd->ev), &fdset);
+ current++;
+ }
+ }
+
+ /* Invariant: FD in `fdset` are not in list of FD */
+ for (int fd = 0; fd < maxfd; fd++) {
+ if (NETSNMP_LARGE_FD_ISSET(fd, &fdset)) {
+ levent_snmp_add_fd(cfg, fd);
+ added++;
+ }
+ }
+ current += added;
+ if (howmany != current) {
+ log_debug("event",
+ "added %d events, removed %d events, total of %d events", added,
+ removed, current);
+ howmany = current;
+ }
+
+ /* If needed, handle timeout */
+ if (evtimer_add(cfg->g_snmp_timeout, block ? NULL : &timeout) == -1)
+ log_warnx("event", "unable to schedule timeout function for SNMP");
+
+ netsnmp_large_fd_set_cleanup(&fdset);
+}
+#endif /* USE_SNMP */
+
+struct lldpd_one_client {
+ TAILQ_ENTRY(lldpd_one_client) next;
+ struct lldpd *cfg;
+ struct bufferevent *bev;
+ int subscribed; /* Is this client subscribed to changes? */
+};
+TAILQ_HEAD(, lldpd_one_client) lldpd_clients;
+
+static void
+levent_ctl_free_client(struct lldpd_one_client *client)
+{
+ if (client && client->bev) bufferevent_free(client->bev);
+ if (client) {
+ TAILQ_REMOVE(&lldpd_clients, client, next);
+ free(client);
+ }
+}
+
+static void
+levent_ctl_close_clients()
+{
+ struct lldpd_one_client *client, *client_next;
+ for (client = TAILQ_FIRST(&lldpd_clients); client; client = client_next) {
+ client_next = TAILQ_NEXT(client, next);
+ levent_ctl_free_client(client);
+ }
+}
+
+static ssize_t
+levent_ctl_send(struct lldpd_one_client *client, int type, void *data, size_t len)
+{
+ struct bufferevent *bev = client->bev;
+ struct hmsg_header hdr = { .len = len, .type = type };
+ bufferevent_disable(bev, EV_WRITE);
+ if (bufferevent_write(bev, &hdr, sizeof(struct hmsg_header)) == -1 ||
+ (len > 0 && bufferevent_write(bev, data, len) == -1)) {
+ log_warnx("event", "unable to create answer to client");
+ levent_ctl_free_client(client);
+ return -1;
+ }
+ bufferevent_enable(bev, EV_WRITE);
+ return len;
+}
+
+void
+levent_ctl_notify(char *ifname, int state, struct lldpd_port *neighbor)
+{
+ struct lldpd_one_client *client, *client_next;
+ struct lldpd_neighbor_change neigh = { .ifname = ifname,
+ .state = state,
+ .neighbor = neighbor };
+ void *output = NULL;
+ ssize_t output_len = 0;
+
+ /* Don't use TAILQ_FOREACH, the client may be deleted in case of errors. */
+ log_debug("control", "notify clients of neighbor changes");
+ for (client = TAILQ_FIRST(&lldpd_clients); client; client = client_next) {
+ client_next = TAILQ_NEXT(client, next);
+ if (!client->subscribed) continue;
+
+ if (output == NULL) {
+ /* Ugly hack: we don't want to transmit a list of
+ * ports. We patch the port to avoid this. */
+ TAILQ_ENTRY(lldpd_port) backup_p_entries;
+ memcpy(&backup_p_entries, &neighbor->p_entries,
+ sizeof(backup_p_entries));
+ memset(&neighbor->p_entries, 0, sizeof(backup_p_entries));
+ output_len = lldpd_neighbor_change_serialize(&neigh, &output);
+ memcpy(&neighbor->p_entries, &backup_p_entries,
+ sizeof(backup_p_entries));
+
+ if (output_len <= 0) {
+ log_warnx("event",
+ "unable to serialize changed neighbor");
+ return;
+ }
+ }
+
+ levent_ctl_send(client, NOTIFICATION, output, output_len);
+ }
+
+ free(output);
+}
+
+static ssize_t
+levent_ctl_send_cb(void *out, int type, void *data, size_t len)
+{
+ struct lldpd_one_client *client = out;
+ return levent_ctl_send(client, type, data, len);
+}
+
+static void
+levent_ctl_recv(struct bufferevent *bev, void *ptr)
+{
+ struct lldpd_one_client *client = ptr;
+ struct evbuffer *buffer = bufferevent_get_input(bev);
+ size_t buffer_len = evbuffer_get_length(buffer);
+ struct hmsg_header hdr;
+ void *data = NULL;
+
+ log_debug("control", "receive data on Unix socket");
+ if (buffer_len < sizeof(struct hmsg_header)) return; /* Not enough data yet */
+ if (evbuffer_copyout(buffer, &hdr, sizeof(struct hmsg_header)) !=
+ sizeof(struct hmsg_header)) {
+ log_warnx("event", "not able to read header");
+ return;
+ }
+ if (hdr.len > HMSG_MAX_SIZE) {
+ log_warnx("event", "message received is too large");
+ goto recv_error;
+ }
+
+ if (buffer_len < hdr.len + sizeof(struct hmsg_header))
+ return; /* Not enough data yet */
+ if (hdr.len > 0 && (data = malloc(hdr.len)) == NULL) {
+ log_warnx("event", "not enough memory");
+ goto recv_error;
+ }
+ evbuffer_drain(buffer, sizeof(struct hmsg_header));
+ if (hdr.len > 0) evbuffer_remove(buffer, data, hdr.len);
+
+ /* Currently, we should not receive notification acknowledgment. But if
+ * we receive one, we can discard it. */
+ if (hdr.len == 0 && hdr.type == NOTIFICATION) return;
+ if (client_handle_client(client->cfg, levent_ctl_send_cb, client, hdr.type,
+ data, hdr.len, &client->subscribed) == -1)
+ goto recv_error;
+ free(data);
+ return;
+
+recv_error:
+ free(data);
+ levent_ctl_free_client(client);
+}
+
+static void
+levent_ctl_event(struct bufferevent *bev, short events, void *ptr)
+{
+ struct lldpd_one_client *client = ptr;
+ if (events & BEV_EVENT_ERROR) {
+ log_warnx("event", "an error occurred with client: %s",
+ evutil_socket_error_to_string(EVUTIL_SOCKET_ERROR()));
+ levent_ctl_free_client(client);
+ } else if (events & BEV_EVENT_EOF) {
+ log_debug("event", "client has been disconnected");
+ levent_ctl_free_client(client);
+ }
+}
+
+static void
+levent_ctl_accept(evutil_socket_t fd, short what, void *arg)
+{
+ struct lldpd *cfg = arg;
+ struct lldpd_one_client *client = NULL;
+ int s;
+ (void)what;
+
+ log_debug("control", "accept a new connection");
+ if ((s = accept(fd, NULL, NULL)) == -1) {
+ log_warn("event", "unable to accept connection from socket");
+ return;
+ }
+ client = calloc(1, sizeof(struct lldpd_one_client));
+ if (!client) {
+ log_warnx("event", "unable to allocate memory for new client");
+ close(s);
+ goto accept_failed;
+ }
+ client->cfg = cfg;
+ levent_make_socket_nonblocking(s);
+ TAILQ_INSERT_TAIL(&lldpd_clients, client, next);
+ if ((client->bev = bufferevent_socket_new(cfg->g_base, s,
+ BEV_OPT_CLOSE_ON_FREE)) == NULL) {
+ log_warnx("event",
+ "unable to allocate a new buffer event for new client");
+ close(s);
+ goto accept_failed;
+ }
+ bufferevent_setcb(client->bev, levent_ctl_recv, NULL, levent_ctl_event, client);
+ bufferevent_enable(client->bev, EV_READ | EV_WRITE);
+ log_debug("event", "new client accepted");
+ /* coverity[leaked_handle]
+ s has been saved by bufferevent_socket_new */
+ return;
+accept_failed:
+ levent_ctl_free_client(client);
+}
+
+static void
+levent_priv(evutil_socket_t fd, short what, void *arg)
+{
+ struct event_base *base = arg;
+ ssize_t n;
+ int err;
+ char one;
+ (void)what;
+ /* Check if we have some data available. We need to pass the socket in
+ * non-blocking mode to be able to run the check without disruption. */
+ levent_make_socket_nonblocking(fd);
+ n = read(fd, &one, 1);
+ err = errno;
+ levent_make_socket_blocking(fd);
+
+ switch (n) {
+ case -1:
+ if (err == EAGAIN || err == EWOULDBLOCK) /* No data, all good */
+ return;
+ log_warnx("event", "unable to poll monitor process, exit");
+ break;
+ case 0:
+ log_warnx("event", "monitor process has terminated, exit");
+ break;
+ default:
+ /* This is a bit unsafe as we are now out-of-sync with the
+ * monitor. It would be safer to request 0 byte, but some OS
+ * (illumos) seem to take the shortcut that by asking 0 byte,
+ * we can just return 0 byte. */
+ log_warnx("event",
+ "received unexpected data from monitor process, exit");
+ break;
+ }
+ event_base_loopbreak(base);
+}
+
+static void
+levent_dump(evutil_socket_t fd, short what, void *arg)
+{
+ struct event_base *base = arg;
+ (void)fd;
+ (void)what;
+ log_debug("event", "dumping all events");
+ event_base_dump_events(base, stderr);
+}
+static void
+levent_stop(evutil_socket_t fd, short what, void *arg)
+{
+ struct event_base *base = arg;
+ (void)fd;
+ (void)what;
+ event_base_loopbreak(base);
+}
+
+static void
+levent_update_and_send(evutil_socket_t fd, short what, void *arg)
+{
+ struct lldpd *cfg = arg;
+ struct timeval tv;
+ long interval_ms = cfg->g_config.c_tx_interval;
+
+ (void)fd;
+ (void)what;
+ lldpd_loop(cfg);
+ if (cfg->g_iface_event != NULL) interval_ms *= 20;
+ if (interval_ms < 30000) interval_ms = 30000;
+ tv.tv_sec = interval_ms / 1000;
+ tv.tv_usec = (interval_ms % 1000) * 1000;
+ event_add(cfg->g_main_loop, &tv);
+}
+
+void
+levent_update_now(struct lldpd *cfg)
+{
+ if (cfg->g_main_loop) event_active(cfg->g_main_loop, EV_TIMEOUT, 1);
+}
+
+void
+levent_send_now(struct lldpd *cfg)
+{
+ struct lldpd_hardware *hardware;
+ TAILQ_FOREACH (hardware, &cfg->g_hardware, h_entries) {
+ if (hardware->h_timer)
+ event_active(hardware->h_timer, EV_TIMEOUT, 1);
+ else
+ log_warnx("event", "BUG: no timer present for interface %s",
+ hardware->h_ifname);
+ }
+}
+
+static void
+levent_init(struct lldpd *cfg)
+{
+ /* Setup libevent */
+ log_debug("event", "initialize libevent");
+ event_set_log_callback(levent_log_cb);
+ if (!(cfg->g_base = event_base_new()))
+ fatalx("event", "unable to create a new libevent base");
+ log_info("event", "libevent %s initialized with %s method", event_get_version(),
+ event_base_get_method(cfg->g_base));
+
+ /* Setup SNMP */
+#ifdef USE_SNMP
+ if (cfg->g_snmp) {
+ agent_init(cfg, cfg->g_snmp_agentx);
+ cfg->g_snmp_timeout =
+ evtimer_new(cfg->g_base, levent_snmp_timeout, cfg);
+ if (!cfg->g_snmp_timeout)
+ fatalx("event", "unable to setup timeout function for SNMP");
+ if ((cfg->g_snmp_fds = malloc(sizeof(struct ev_l))) == NULL)
+ fatalx("event", "unable to allocate memory for SNMP events");
+ TAILQ_INIT(levent_snmp_fds(cfg));
+ }
+#endif
+
+ /* Setup loop that will run every X seconds. */
+ log_debug("event", "register loop timer");
+ if (!(cfg->g_main_loop =
+ event_new(cfg->g_base, -1, 0, levent_update_and_send, cfg)))
+ fatalx("event", "unable to setup main timer");
+ event_active(cfg->g_main_loop, EV_TIMEOUT, 1);
+
+ /* Setup unix socket */
+ struct event *ctl_event;
+ log_debug("event", "register Unix socket");
+ TAILQ_INIT(&lldpd_clients);
+ levent_make_socket_nonblocking(cfg->g_ctl);
+ if ((ctl_event = event_new(cfg->g_base, cfg->g_ctl, EV_READ | EV_PERSIST,
+ levent_ctl_accept, cfg)) == NULL)
+ fatalx("event", "unable to setup control socket event");
+ event_add(ctl_event, NULL);
+
+ /* Somehow monitor the monitor process */
+ struct event *monitor_event;
+ log_debug("event", "monitor the monitor process");
+ if ((monitor_event = event_new(cfg->g_base, priv_fd(PRIV_UNPRIVILEGED),
+ EV_READ | EV_PERSIST, levent_priv, cfg->g_base)) == NULL)
+ fatalx("event", "unable to monitor monitor process");
+ event_add(monitor_event, NULL);
+
+ /* Signals */
+ log_debug("event", "register signals");
+ evsignal_add(evsignal_new(cfg->g_base, SIGUSR1, levent_dump, cfg->g_base),
+ NULL);
+ evsignal_add(evsignal_new(cfg->g_base, SIGINT, levent_stop, cfg->g_base), NULL);
+ evsignal_add(evsignal_new(cfg->g_base, SIGTERM, levent_stop, cfg->g_base),
+ NULL);
+}
+
+/* Initialize libevent and start the event loop */
+void
+levent_loop(struct lldpd *cfg)
+{
+ levent_init(cfg);
+ lldpd_loop(cfg);
+#ifdef USE_SNMP
+ if (cfg->g_snmp) levent_snmp_update(cfg);
+#endif
+
+ /* libevent loop */
+ do {
+ TRACE(LLDPD_EVENT_LOOP());
+ if (event_base_got_break(cfg->g_base) ||
+ event_base_got_exit(cfg->g_base))
+ break;
+ } while (event_base_loop(cfg->g_base, EVLOOP_ONCE) == 0);
+
+ if (cfg->g_iface_timer_event != NULL) event_free(cfg->g_iface_timer_event);
+
+#ifdef USE_SNMP
+ if (cfg->g_snmp) agent_shutdown();
+#endif /* USE_SNMP */
+
+ levent_ctl_close_clients();
+}
+
+/* Release libevent resources */
+void
+levent_shutdown(struct lldpd *cfg)
+{
+ if (cfg->g_iface_event) event_free(cfg->g_iface_event);
+ if (cfg->g_cleanup_timer) event_free(cfg->g_cleanup_timer);
+ event_base_free(cfg->g_base);
+}
+
+static void
+levent_hardware_recv(evutil_socket_t fd, short what, void *arg)
+{
+ struct lldpd_hardware *hardware = arg;
+ struct lldpd *cfg = hardware->h_cfg;
+ (void)what;
+ log_debug("event", "received something for %s", hardware->h_ifname);
+ lldpd_recv(cfg, hardware, fd);
+ levent_schedule_cleanup(cfg);
+}
+
+void
+levent_hardware_init(struct lldpd_hardware *hardware)
+{
+ log_debug("event", "initialize events for %s", hardware->h_ifname);
+ if ((hardware->h_recv = malloc(sizeof(struct ev_l))) == NULL) {
+ log_warnx("event", "unable to allocate memory for %s",
+ hardware->h_ifname);
+ return;
+ }
+ TAILQ_INIT(levent_hardware_fds(hardware));
+}
+
+void
+levent_hardware_add_fd(struct lldpd_hardware *hardware, int fd)
+{
+ struct lldpd_events *hfd = NULL;
+ if (!hardware->h_recv) return;
+
+ hfd = calloc(1, sizeof(struct lldpd_events));
+ if (!hfd) {
+ log_warnx("event", "unable to allocate new event for %s",
+ hardware->h_ifname);
+ return;
+ }
+ levent_make_socket_nonblocking(fd);
+ if ((hfd->ev = event_new(hardware->h_cfg->g_base, fd, EV_READ | EV_PERSIST,
+ levent_hardware_recv, hardware)) == NULL) {
+ log_warnx("event", "unable to allocate a new event for %s",
+ hardware->h_ifname);
+ free(hfd);
+ return;
+ }
+ if (event_add(hfd->ev, NULL) == -1) {
+ log_warnx("event", "unable to schedule new event for %s",
+ hardware->h_ifname);
+ event_free(hfd->ev);
+ free(hfd);
+ return;
+ }
+ TAILQ_INSERT_TAIL(levent_hardware_fds(hardware), hfd, next);
+}
+
+void
+levent_hardware_release(struct lldpd_hardware *hardware)
+{
+ struct lldpd_events *ev, *ev_next;
+ if (hardware->h_timer) {
+ event_free(hardware->h_timer);
+ hardware->h_timer = NULL;
+ }
+ if (!hardware->h_recv) return;
+
+ log_debug("event", "release events for %s", hardware->h_ifname);
+ for (ev = TAILQ_FIRST(levent_hardware_fds(hardware)); ev; ev = ev_next) {
+ ev_next = TAILQ_NEXT(ev, next);
+ /* We may close several time the same FD. This is harmless. */
+ close(event_get_fd(ev->ev));
+ event_free(ev->ev);
+ TAILQ_REMOVE(levent_hardware_fds(hardware), ev, next);
+ free(ev);
+ }
+ free(levent_hardware_fds(hardware));
+}
+
+static void
+levent_iface_trigger(evutil_socket_t fd, short what, void *arg)
+{
+ struct lldpd *cfg = arg;
+ log_debug("event", "triggering update of all interfaces");
+ lldpd_update_localports(cfg);
+}
+
+static void
+levent_iface_recv(evutil_socket_t fd, short what, void *arg)
+{
+ struct lldpd *cfg = arg;
+ char buffer[EVENT_BUFFER];
+ int n;
+
+ if (cfg->g_iface_cb == NULL) {
+ /* Discard the message */
+ while (1) {
+ n = read(fd, buffer, sizeof(buffer));
+ if (n == -1 && (errno == EWOULDBLOCK || errno == EAGAIN)) break;
+ if (n == -1) {
+ log_warn("event",
+ "unable to receive interface change notification message");
+ return;
+ }
+ if (n == 0) {
+ log_warnx("event",
+ "end of file reached while getting interface change notification message");
+ return;
+ }
+ }
+ } else {
+ cfg->g_iface_cb(cfg);
+ }
+
+ /* Schedule local port update. We don't run it right away because we may
+ * receive a batch of events like this. */
+ struct timeval one_sec = { 1, 0 };
+ TRACE(LLDPD_INTERFACES_NOTIFICATION());
+ log_debug("event",
+ "received notification change, schedule an update of all interfaces in one second");
+ if (cfg->g_iface_timer_event == NULL) {
+ if ((cfg->g_iface_timer_event = evtimer_new(cfg->g_base,
+ levent_iface_trigger, cfg)) == NULL) {
+ log_warnx("event",
+ "unable to create a new event to trigger interface update");
+ return;
+ }
+ }
+ if (evtimer_add(cfg->g_iface_timer_event, &one_sec) == -1) {
+ log_warnx("event", "unable to schedule interface updates");
+ return;
+ }
+}
+
+int
+levent_iface_subscribe(struct lldpd *cfg, int socket)
+{
+ log_debug("event", "subscribe to interface changes from socket %d", socket);
+ levent_make_socket_nonblocking(socket);
+ cfg->g_iface_event = event_new(cfg->g_base, socket, EV_READ | EV_PERSIST,
+ levent_iface_recv, cfg);
+ if (cfg->g_iface_event == NULL) {
+ log_warnx("event",
+ "unable to allocate a new event for interface changes");
+ return -1;
+ }
+ if (event_add(cfg->g_iface_event, NULL) == -1) {
+ log_warnx("event", "unable to schedule new interface changes event");
+ event_free(cfg->g_iface_event);
+ cfg->g_iface_event = NULL;
+ return -1;
+ }
+ return 0;
+}
+
+static void
+levent_trigger_cleanup(evutil_socket_t fd, short what, void *arg)
+{
+ struct lldpd *cfg = arg;
+ lldpd_cleanup(cfg);
+}
+
+void
+levent_schedule_cleanup(struct lldpd *cfg)
+{
+ log_debug("event", "schedule next cleanup");
+ if (cfg->g_cleanup_timer != NULL) {
+ event_free(cfg->g_cleanup_timer);
+ }
+ cfg->g_cleanup_timer = evtimer_new(cfg->g_base, levent_trigger_cleanup, cfg);
+ if (cfg->g_cleanup_timer == NULL) {
+ log_warnx("event", "unable to allocate a new event for cleanup tasks");
+ return;
+ }
+
+ /* Compute the next TTL event */
+ struct timeval tv = { cfg->g_config.c_ttl, 0 };
+ time_t now = time(NULL);
+ time_t next;
+ struct lldpd_hardware *hardware;
+ struct lldpd_port *port;
+ TAILQ_FOREACH (hardware, &cfg->g_hardware, h_entries) {
+ TAILQ_FOREACH (port, &hardware->h_rports, p_entries) {
+ if (now >= port->p_lastupdate + port->p_ttl) {
+ tv.tv_sec = 0;
+ log_debug("event",
+ "immediate cleanup on port %s (%lld, %d, %lld)",
+ hardware->h_ifname, (long long)now, port->p_ttl,
+ (long long)port->p_lastupdate);
+ break;
+ }
+ next = port->p_ttl - (now - port->p_lastupdate);
+ if (next < tv.tv_sec) tv.tv_sec = next;
+ }
+ }
+
+ log_debug("event", "next cleanup in %ld seconds", (long)tv.tv_sec);
+ if (event_add(cfg->g_cleanup_timer, &tv) == -1) {
+ log_warnx("event", "unable to schedule cleanup task");
+ event_free(cfg->g_cleanup_timer);
+ cfg->g_cleanup_timer = NULL;
+ return;
+ }
+}
+
+static void
+levent_send_pdu(evutil_socket_t fd, short what, void *arg)
+{
+ struct lldpd_hardware *hardware = arg;
+ int tx_interval = hardware->h_cfg->g_config.c_tx_interval;
+
+ log_debug("event", "trigger sending PDU for port %s", hardware->h_ifname);
+ lldpd_send(hardware);
+
+#ifdef ENABLE_LLDPMED
+ if (hardware->h_tx_fast > 0) hardware->h_tx_fast--;
+
+ if (hardware->h_tx_fast > 0)
+ tx_interval = hardware->h_cfg->g_config.c_tx_fast_interval * 1000;
+#endif
+
+ struct timeval tv;
+ tv.tv_sec = tx_interval / 1000;
+ tv.tv_usec = (tx_interval % 1000) * 1000;
+ if (event_add(hardware->h_timer, &tv) == -1) {
+ log_warnx("event", "unable to re-register timer event for port %s",
+ hardware->h_ifname);
+ event_free(hardware->h_timer);
+ hardware->h_timer = NULL;
+ return;
+ }
+}
+
+void
+levent_schedule_pdu(struct lldpd_hardware *hardware)
+{
+ log_debug("event", "schedule sending PDU on %s", hardware->h_ifname);
+ if (hardware->h_timer == NULL) {
+ hardware->h_timer =
+ evtimer_new(hardware->h_cfg->g_base, levent_send_pdu, hardware);
+ if (hardware->h_timer == NULL) {
+ log_warnx("event", "unable to schedule PDU sending for port %s",
+ hardware->h_ifname);
+ return;
+ }
+ }
+
+ struct timeval tv = { 0, 0 };
+ if (event_add(hardware->h_timer, &tv) == -1) {
+ log_warnx("event", "unable to register timer event for port %s",
+ hardware->h_ifname);
+ event_free(hardware->h_timer);
+ hardware->h_timer = NULL;
+ return;
+ }
+}
+
+int
+levent_make_socket_nonblocking(int fd)
+{
+ int flags;
+ if ((flags = fcntl(fd, F_GETFL, NULL)) < 0) {
+ log_warn("event", "fcntl(%d, F_GETFL)", fd);
+ return -1;
+ }
+ if (flags & O_NONBLOCK) return 0;
+ if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) {
+ log_warn("event", "fcntl(%d, F_SETFL)", fd);
+ return -1;
+ }
+ return 0;
+}
+
+int
+levent_make_socket_blocking(int fd)
+{
+ int flags;
+ if ((flags = fcntl(fd, F_GETFL, NULL)) < 0) {
+ log_warn("event", "fcntl(%d, F_GETFL)", fd);
+ return -1;
+ }
+ if (!(flags & O_NONBLOCK)) return 0;
+ if (fcntl(fd, F_SETFL, flags & ~O_NONBLOCK) == -1) {
+ log_warn("event", "fcntl(%d, F_SETFL)", fd);
+ return -1;
+ }
+ return 0;
+}
+
+#ifdef HOST_OS_LINUX
+/* Receive and log error from a socket when there is suspicion of an error. */
+void
+levent_recv_error(int fd, const char *source)
+{
+ do {
+ ssize_t n;
+ char buf[1024] = {};
+ struct msghdr msg = { .msg_control = buf,
+ .msg_controllen = sizeof(buf) };
+ if ((n = recvmsg(fd, &msg, MSG_ERRQUEUE | MSG_DONTWAIT)) <= 0) {
+ return;
+ }
+ struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg);
+ if (cmsg == NULL)
+ log_warnx("event", "received unknown error on %s", source);
+ else
+ log_warnx("event", "received error (level=%d/type=%d) on %s",
+ cmsg->cmsg_level, cmsg->cmsg_type, source);
+ } while (1);
+}
+#endif
diff --git a/src/daemon/forward-bsd.c b/src/daemon/forward-bsd.c
new file mode 100644
index 0000000..1f930de
--- /dev/null
+++ b/src/daemon/forward-bsd.c
@@ -0,0 +1,31 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2013 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "lldpd.h"
+
+#include <sys/param.h>
+#include <sys/sysctl.h>
+
+int
+interfaces_routing_enabled(struct lldpd *cfg)
+{
+ (void)cfg;
+ int n, mib[4] = { CTL_NET, PF_INET, IPPROTO_IP, IPCTL_FORWARDING };
+ size_t len = sizeof(int);
+ if (sysctl(mib, 4, &n, &len, NULL, 0) != -1) return (n == 1);
+ return -1;
+}
diff --git a/src/daemon/forward-linux.c b/src/daemon/forward-linux.c
new file mode 100644
index 0000000..6308445
--- /dev/null
+++ b/src/daemon/forward-linux.c
@@ -0,0 +1,59 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2013 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "lldpd.h"
+
+#include <unistd.h>
+
+static int
+ip_forwarding_enabled(int af)
+{
+ int fd, rc = -1;
+ const char *fname;
+ char status;
+
+ if (af == LLDPD_AF_IPV4)
+ fname = PROCFS_SYS_NET "ipv4/ip_forward";
+ else if (af == LLDPD_AF_IPV6)
+ fname = PROCFS_SYS_NET "ipv6/conf/all/forwarding";
+ else
+ return -1;
+
+ if ((fd = priv_open(fname)) < 0) return -1;
+
+ if (read(fd, &status, 1) == 1) rc = (status == '1');
+
+ close(fd);
+ return rc;
+}
+
+int
+interfaces_routing_enabled(struct lldpd *cfg)
+{
+ (void)cfg;
+ int rc;
+
+ rc = ip_forwarding_enabled(LLDPD_AF_IPV4);
+ /*
+ * Report being a router if IPv4 forwarding is enabled.
+ * In case of error also stop the execution right away.
+ * If IPv4 forwarding is disabled we'll check the IPv6 status.
+ */
+ if (rc != 0) return rc;
+
+ return ip_forwarding_enabled(LLDPD_AF_IPV6);
+}
diff --git a/src/daemon/forward-solaris.c b/src/daemon/forward-solaris.c
new file mode 100644
index 0000000..b44a110
--- /dev/null
+++ b/src/daemon/forward-solaris.c
@@ -0,0 +1,27 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2013 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "lldpd.h"
+
+int
+interfaces_routing_enabled(struct lldpd *cfg)
+{
+ /* Dunno how to get this for Solaris. See the commit introducing Solaris
+ support (maybe c3e340b6be8add4eb3a41882847a96e66793e82c) for a
+ solution which does not work in a chroot. */
+ return 0;
+}
diff --git a/src/daemon/frame.c b/src/daemon/frame.c
new file mode 100644
index 0000000..adc4629
--- /dev/null
+++ b/src/daemon/frame.c
@@ -0,0 +1,66 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2009 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "lldpd.h"
+
+/**
+ * Compute the checksum as 16-bit word.
+ */
+u_int16_t
+frame_checksum(const u_char *cp, int len, int cisco)
+{
+ unsigned int sum = 0, v = 0;
+ int oddbyte = 0;
+
+ while ((len -= 2) >= 0) {
+ sum += *cp++ << 8;
+ sum += *cp++;
+ }
+ if ((oddbyte = len & 1) != 0) v = *cp;
+
+ /* The remaining byte seems to be handled oddly by Cisco. From function
+ * dissect_cdp() in wireshark. 2014/6/14,zhengy@yealink.com:
+ *
+ * CDP doesn't adhere to RFC 1071 section 2. (B). It incorrectly assumes
+ * checksums are calculated on a big endian platform, therefore i.s.o.
+ * padding odd sized data with a zero byte _at the end_ it sets the last
+ * big endian _word_ to contain the last network _octet_. This byteswap
+ * has to be done on the last octet of network data before feeding it to
+ * the Internet checksum routine.
+ * CDP checksumming code has a bug in the addition of this last _word_
+ * as a signed number into the long word intermediate checksum. When
+ * reducing this long to word size checksum an off-by-one error can be
+ * made. This off-by-one error is compensated for in the last _word_ of
+ * the network data.
+ */
+ if (oddbyte) {
+ if (cisco) {
+ if (v & 0x80) {
+ sum += 0xff << 8;
+ sum += v - 1;
+ } else {
+ sum += v;
+ }
+ } else {
+ sum += v << 8;
+ }
+ }
+
+ sum = (sum >> 16) + (sum & 0xffff);
+ sum += sum >> 16;
+ return (0xffff & ~sum);
+}
diff --git a/src/daemon/frame.h b/src/daemon/frame.h
new file mode 100644
index 0000000..714de09
--- /dev/null
+++ b/src/daemon/frame.h
@@ -0,0 +1,102 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2009 Vincent Bernat <bernat@luffy.cx>
+ * Copyright (c) 2014 Michael Chapman
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _FRAME_H
+#define _FRAME_H
+
+static union {
+ uint8_t f_uint8;
+ uint16_t f_uint16;
+ uint32_t f_uint32;
+} types;
+
+/* This set of macro are used to build packets. The current position in buffer
+ * is `pos'. The length of the remaining space in buffer is `length'. `type'
+ * should be a member of `types'.
+ *
+ * This was stolen from ladvd which was adapted from Net::CDP. The original
+ * author of those macros, Michael Chapman, has relicensed those macros under
+ * the ISC license. */
+
+#define POKE(value, type, func) \
+ ((length >= sizeof(type)) && \
+ (type = func(value), memcpy(pos, &type, sizeof(type)), length -= sizeof(type), \
+ pos += sizeof(type), 1))
+#define POKE_UINT8(value) POKE(value, types.f_uint8, )
+#define POKE_UINT16(value) POKE(value, types.f_uint16, htons)
+#define POKE_UINT32(value) POKE(value, types.f_uint32, htonl)
+#define POKE_BYTES(value, bytes) \
+ ((length >= (bytes)) && \
+ (memcpy(pos, value, bytes), length -= (bytes), pos += (bytes), 1))
+#define POKE_SAVE(where) (where = pos, 1)
+#define POKE_RESTORE(where) \
+ do { \
+ if ((where) > pos) \
+ length -= ((where)-pos); \
+ else \
+ length += (pos - (where)); \
+ pos = (where); \
+ } while (0)
+
+/* This set of macro are used to parse packets. The same variable as for POKE_*
+ * are used. There is no check on boundaries. */
+
+#define PEEK(type, func) \
+ (memcpy(&type, pos, sizeof(type)), length -= sizeof(type), pos += sizeof(type), \
+ func(type))
+#define PEEK_UINT8 PEEK(types.f_uint8, )
+#define PEEK_UINT16 PEEK(types.f_uint16, ntohs)
+#define PEEK_UINT32 PEEK(types.f_uint32, ntohl)
+#define PEEK_BYTES(value, bytes) \
+ do { \
+ memcpy(value, pos, bytes); \
+ length -= (bytes); \
+ pos += (bytes); \
+ } while (0)
+#define PEEK_DISCARD(bytes) \
+ do { \
+ length -= (bytes); \
+ pos += (bytes); \
+ } while (0)
+#define PEEK_DISCARD_UINT8 PEEK_DISCARD(1)
+#define PEEK_DISCARD_UINT16 PEEK_DISCARD(2)
+#define PEEK_DISCARD_UINT32 PEEK_DISCARD(4)
+#define PEEK_CMP(value, bytes) \
+ (length -= (bytes), pos += (bytes), memcmp(pos - bytes, value, bytes))
+#define PEEK_SAVE POKE_SAVE
+#define PEEK_RESTORE POKE_RESTORE
+
+/* LLDP specific. We need a `tlv' pointer. */
+#define POKE_START_LLDP_TLV(type) (tlv = pos, POKE_UINT16(type << 9))
+#define POKE_END_LLDP_TLV \
+ (memcpy(&types.f_uint16, tlv, sizeof(uint16_t)), \
+ types.f_uint16 |= htons((pos - (tlv + 2)) & 0x01ff), \
+ memcpy(tlv, &types.f_uint16, sizeof(uint16_t)), 1)
+
+/* Same for CDP */
+#define POKE_START_CDP_TLV(type) ((void)POKE_UINT16(type), tlv = pos, POKE_UINT16(0))
+#define POKE_END_CDP_TLV \
+ (types.f_uint16 = htons(pos - tlv + 2), \
+ memcpy(tlv, &types.f_uint16, sizeof(uint16_t)), 1)
+
+/* Same for EDP */
+#define POKE_START_EDP_TLV(type) \
+ ((void)POKE_UINT8(EDP_TLV_MARKER), (void)POKE_UINT8(type), tlv = pos, POKE_UINT16(0))
+#define POKE_END_EDP_TLV POKE_END_CDP_TLV
+
+#endif /* _FRAME_H */
diff --git a/src/daemon/interfaces-bpf.c b/src/daemon/interfaces-bpf.c
new file mode 100644
index 0000000..2091eaf
--- /dev/null
+++ b/src/daemon/interfaces-bpf.c
@@ -0,0 +1,117 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2013 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "lldpd.h"
+#include <unistd.h>
+#include <errno.h>
+#include <net/bpf.h>
+
+struct bpf_buffer {
+ size_t len; /* Total length of the buffer */
+ struct bpf_hdr data[0];
+};
+
+int
+ifbpf_phys_init(struct lldpd *cfg, struct lldpd_hardware *hardware)
+{
+ struct bpf_buffer *buffer = NULL;
+ int fd = -1;
+
+ log_debug("interfaces", "initialize ethernet device %s", hardware->h_ifname);
+ if ((fd = priv_iface_init(hardware->h_ifindex, hardware->h_ifname)) == -1)
+ return -1;
+
+ /* Allocate receive buffer */
+ hardware->h_data = buffer = malloc(ETHER_MAX_LEN +
+ BPF_WORDALIGN(sizeof(struct bpf_hdr)) + sizeof(struct bpf_buffer));
+ if (buffer == NULL) {
+ log_warn("interfaces", "unable to allocate buffer space for BPF on %s",
+ hardware->h_ifname);
+ goto end;
+ }
+ buffer->len = ETHER_MAX_LEN + BPF_WORDALIGN(sizeof(struct bpf_hdr));
+
+ /* Setup multicast */
+ interfaces_setup_multicast(cfg, hardware->h_ifname, 0);
+
+ hardware->h_sendfd = fd; /* Send */
+
+ levent_hardware_add_fd(hardware, fd); /* Receive */
+ log_debug("interfaces", "interface %s initialized (fd=%d)", hardware->h_ifname,
+ fd);
+ return 0;
+
+end:
+ if (fd >= 0) close(fd);
+ free(buffer);
+ hardware->h_data = NULL;
+ return -1;
+}
+
+/* Ethernet send/receive through BPF */
+static int
+ifbpf_eth_send(struct lldpd *cfg, struct lldpd_hardware *hardware, char *buffer,
+ size_t size)
+{
+ log_debug("interfaces", "send PDU to ethernet device %s (fd=%d)",
+ hardware->h_ifname, hardware->h_sendfd);
+ return write(hardware->h_sendfd, buffer, size);
+}
+
+static int
+ifbpf_eth_recv(struct lldpd *cfg, struct lldpd_hardware *hardware, int fd, char *buffer,
+ size_t size)
+{
+ struct bpf_buffer *bpfbuf = hardware->h_data;
+ struct bpf_hdr *bh;
+ log_debug("interfaces", "receive PDU from ethernet device %s",
+ hardware->h_ifname);
+
+ /* We assume we have only receive one packet (unbuffered mode). Dunno if
+ * this is correct. */
+ if (read(fd, bpfbuf->data, bpfbuf->len) == -1) {
+ if (errno == ENETDOWN) {
+ log_debug("interfaces",
+ "error while receiving frame on %s (network down)",
+ hardware->h_ifname);
+ } else {
+ log_warn("interfaces", "error while receiving frame on %s",
+ hardware->h_ifname);
+ hardware->h_rx_discarded_cnt++;
+ }
+ return -1;
+ }
+ bh = (struct bpf_hdr *)bpfbuf->data;
+ if (bh->bh_caplen < size) size = bh->bh_caplen;
+ memcpy(buffer, (char *)bpfbuf->data + bh->bh_hdrlen, size);
+
+ return size;
+}
+
+static int
+ifbpf_eth_close(struct lldpd *cfg, struct lldpd_hardware *hardware)
+{
+ log_debug("interfaces", "close ethernet device %s", hardware->h_ifname);
+ interfaces_setup_multicast(cfg, hardware->h_ifname, 1);
+ return 0;
+}
+
+struct lldpd_ops bpf_ops = {
+ .send = ifbpf_eth_send,
+ .recv = ifbpf_eth_recv,
+ .cleanup = ifbpf_eth_close,
+};
diff --git a/src/daemon/interfaces-bsd.c b/src/daemon/interfaces-bsd.c
new file mode 100644
index 0000000..a8248fe
--- /dev/null
+++ b/src/daemon/interfaces-bsd.c
@@ -0,0 +1,641 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2012 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "lldpd.h"
+
+#include <unistd.h>
+#include <ifaddrs.h>
+#include <errno.h>
+#include <ctype.h>
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <sys/ioctl.h>
+#include <net/bpf.h>
+#include <net/if_types.h>
+#include <net/if_media.h>
+#include <net/if_dl.h>
+#if defined HOST_OS_FREEBSD
+# include <net/if_vlan_var.h>
+# include <net/if_bridgevar.h>
+# include <net/if_lagg.h>
+#elif defined HOST_OS_DRAGONFLY
+# include <net/vlan/if_vlan_var.h>
+# include <net/bridge/if_bridgevar.h>
+#elif defined HOST_OS_OPENBSD
+# include <net/if_vlan_var.h>
+# include <net/if_bridge.h>
+# include <net/if_trunk.h>
+#elif defined HOST_OS_NETBSD
+# include <net/if_vlanvar.h>
+# include <net/if_bridgevar.h>
+# include <net/agr/if_agrioctl.h>
+#elif defined HOST_OS_OSX
+# include <osx/if_vlan_var.h>
+# include <osx/if_bridgevar.h>
+# include <osx/if_bond_var.h>
+#endif
+
+#ifndef IFDESCRSIZE
+# define IFDESCRSIZE 64
+#endif
+
+static int
+ifbsd_check_wireless(struct lldpd *cfg, struct ifaddrs *ifaddr,
+ struct interfaces_device *iface)
+{
+ struct ifmediareq ifmr = {};
+ strlcpy(ifmr.ifm_name, iface->name, sizeof(ifmr.ifm_name));
+ if (ioctl(cfg->g_sock, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0 ||
+ IFM_TYPE(ifmr.ifm_current) != IFM_IEEE80211)
+ return 0; /* Not wireless either */
+ iface->type |= IFACE_WIRELESS_T | IFACE_PHYSICAL_T;
+ return 0;
+}
+
+static void
+ifbsd_check_bridge(struct lldpd *cfg, struct interfaces_device_list *interfaces,
+ struct interfaces_device *master)
+{
+ static size_t ifbic_len = 64;
+ struct ifbreq *req = NULL;
+ struct ifbifconf bifc = {};
+
+retry_alloc:
+ if ((req = realloc(req, ifbic_len)) == NULL) {
+ log_warn("interfaces", "unable to allocate memory to query bridge %s",
+ master->name);
+ free(bifc.ifbic_req);
+ return;
+ }
+ bifc.ifbic_len = ifbic_len;
+ bifc.ifbic_req = req;
+
+#if defined HOST_OS_FREEBSD || defined HOST_OS_NETBSD || defined HOST_OS_OSX || \
+ defined HOST_OS_DRAGONFLY
+ struct ifdrv ifd = { .ifd_cmd = BRDGGIFS,
+ .ifd_len = sizeof(bifc),
+ .ifd_data = &bifc };
+
+ strlcpy(ifd.ifd_name, master->name, sizeof(ifd.ifd_name));
+ if (ioctl(cfg->g_sock, SIOCGDRVSPEC, (caddr_t)&ifd) < 0) {
+ log_debug("interfaces", "%s is not a bridge", master->name);
+ return;
+ }
+#elif defined HOST_OS_OPENBSD
+ strlcpy(bifc.ifbic_name, master->name, sizeof(bifc.ifbic_name));
+ if (ioctl(cfg->g_sock, SIOCBRDGIFS, (caddr_t)&bifc) < 0) {
+ log_debug("interfaces", "%s is not a bridge", master->name);
+ return;
+ }
+#else
+# error Unsupported OS
+#endif
+ if (bifc.ifbic_len >= ifbic_len) {
+ ifbic_len = bifc.ifbic_len + 1;
+ goto retry_alloc;
+ }
+ for (int i = 0; i < bifc.ifbic_len / sizeof(*req); i++) {
+ struct interfaces_device *slave =
+ interfaces_nametointerface(interfaces, req[i].ifbr_ifsname);
+ if (slave == NULL) {
+ log_warnx("interfaces",
+ "%s should be bridged to %s but we don't know %s",
+ req[i].ifbr_ifsname, master->name, req[i].ifbr_ifsname);
+ continue;
+ }
+ log_debug("interfaces", "%s is bridged to %s", slave->name,
+ master->name);
+ slave->upper = master;
+ }
+ master->type |= IFACE_BRIDGE_T;
+}
+
+static void
+ifbsd_check_bond(struct lldpd *cfg, struct interfaces_device_list *interfaces,
+ struct interfaces_device *master)
+{
+#if defined HOST_OS_OPENBSD
+/* OpenBSD is the same as FreeBSD, just lagg->trunk */
+# define lagg_reqport trunk_reqport
+# define lagg_reqall trunk_reqall
+# define SIOCGLAGG SIOCGTRUNK
+# define LAGG_MAX_PORTS TRUNK_MAX_PORTS
+#endif
+#if defined HOST_OS_OPENBSD || defined HOST_OS_FREEBSD
+ struct lagg_reqport rpbuf[LAGG_MAX_PORTS];
+ struct lagg_reqall ra = { .ra_size = sizeof(rpbuf), .ra_port = rpbuf };
+ strlcpy(ra.ra_ifname, master->name, IFNAMSIZ);
+ if (ioctl(cfg->g_sock, SIOCGLAGG, (caddr_t)&ra) < 0) {
+ log_debug("interfaces", "%s is not a bond", master->name);
+ return;
+ }
+
+ for (int i = 0; i < ra.ra_ports; i++) {
+ struct interfaces_device *slave;
+ slave = interfaces_nametointerface(interfaces, rpbuf[i].rp_portname);
+ if (slave == NULL) {
+ log_warnx("interfaces",
+ "%s should be enslaved to %s but we don't know %s",
+ rpbuf[i].rp_portname, master->name, rpbuf[i].rp_portname);
+ continue;
+ }
+ log_debug("interfaces", "%s is enslaved to bond %s", slave->name,
+ master->name);
+ slave->upper = master;
+ }
+ master->type |= IFACE_BOND_T;
+#elif defined HOST_OS_NETBSD
+ /* No max, we consider a maximum of 24 ports */
+ char buf[sizeof(struct agrportinfo) * 24] = {};
+ size_t buflen = sizeof(buf);
+ struct agrreq ar = { .ar_version = AGRREQ_VERSION,
+ .ar_cmd = AGRCMD_PORTLIST,
+ .ar_buf = buf,
+ .ar_buflen = buflen };
+ struct ifreq ifr = { .ifr_data = &ar };
+ struct agrportlist *apl = (void *)buf;
+ struct agrportinfo *api = (void *)(apl + 1);
+ strlcpy(ifr.ifr_name, master->name, sizeof(ifr.ifr_name));
+ if (ioctl(cfg->g_sock, SIOCGETAGR, &ifr) == -1) {
+ if (errno == E2BIG) {
+ log_warnx("interfaces",
+ "%s is a too big aggregate. Please, report the problem",
+ master->name);
+ } else {
+ log_debug("interfaces", "%s is not an aggregate", master->name);
+ }
+ return;
+ }
+ for (int i = 0; i < apl->apl_nports; i++, api++) {
+ struct interfaces_device *slave;
+ slave = interfaces_nametointerface(interfaces, api->api_ifname);
+ if (slave == NULL) {
+ log_warnx("interfaces",
+ "%s should be enslaved to %s but we don't know %s",
+ api->api_ifname, master->name, api->api_ifname);
+ continue;
+ }
+ log_debug("interfaces", "%s is enslaved to bond %s", slave->name,
+ master->name);
+ slave->upper = master;
+ }
+ master->type |= IFACE_BOND_T;
+#elif defined HOST_OS_OSX
+ struct if_bond_req ibr = { .ibr_op = IF_BOND_OP_GET_STATUS,
+ .ibr_ibru = {
+ .ibru_status = { .ibsr_version = IF_BOND_STATUS_REQ_VERSION } } };
+ struct ifreq ifr = { .ifr_data = (caddr_t)&ibr };
+ strlcpy(ifr.ifr_name, master->name, sizeof(ifr.ifr_name));
+ if (ioctl(cfg->g_sock, SIOCGIFBOND, (caddr_t)&ifr) < 0) {
+ log_debug("interfaces", "%s is not an aggregate", master->name);
+ return;
+ }
+ master->type |= IFACE_BOND_T;
+ if (ibr.ibr_ibru.ibru_status.ibsr_total == 0) {
+ log_debug("interfaces", "no members for bond %s", master->name);
+ return;
+ }
+
+ struct if_bond_status_req *ibsr_p = &ibr.ibr_ibru.ibru_status;
+ ibsr_p->ibsr_buffer =
+ malloc(sizeof(struct if_bond_status) * ibsr_p->ibsr_total);
+ if (ibsr_p->ibsr_buffer == NULL) {
+ log_warnx("interfaces", "not enough memory to check bond members");
+ return;
+ }
+ ibsr_p->ibsr_count = ibsr_p->ibsr_total;
+ if (ioctl(cfg->g_sock, SIOCGIFBOND, (caddr_t)&ifr) < 0) {
+ log_warn("interfaces", "unable to get members for bond %s",
+ master->name);
+ goto end;
+ }
+
+ struct if_bond_status *ibs_p = (struct if_bond_status *)ibsr_p->ibsr_buffer;
+ for (int i = 0; i < ibsr_p->ibsr_total; i++, ibs_p++) {
+ struct interfaces_device *slave;
+ slave = interfaces_nametointerface(interfaces, ibs_p->ibs_if_name);
+ if (slave == NULL) {
+ log_warnx("interfaces",
+ "%s should be enslaved to %s but we don't know %s",
+ ibs_p->ibs_if_name, master->name, ibs_p->ibs_if_name);
+ continue;
+ }
+ log_debug("interfaces", "%s is enslaved to bond %s", slave->name,
+ master->name);
+ slave->upper = master;
+ }
+end:
+ free(ibsr_p->ibsr_buffer);
+#elif defined HOST_OS_DRAGONFLY
+ log_debug("interfaces", "DragonFly BSD does not support link aggregation");
+#else
+# error Unsupported OS
+#endif
+}
+
+static void
+ifbsd_check_vlan(struct lldpd *cfg, struct interfaces_device_list *interfaces,
+ struct interfaces_device *vlan)
+{
+ struct interfaces_device *lower;
+ struct vlanreq vreq = {};
+ struct ifreq ifr = { .ifr_data = (caddr_t)&vreq };
+ strlcpy(ifr.ifr_name, vlan->name, sizeof(ifr.ifr_name));
+ if (ioctl(cfg->g_sock, SIOCGETVLAN, (caddr_t)&ifr) < 0) {
+ log_debug("interfaces", "%s is not a VLAN", vlan->name);
+ return;
+ }
+ if (strlen(vreq.vlr_parent) == 0) {
+ log_debug("interfaces", "%s is a VLAN but has no lower interface",
+ vlan->name);
+ vlan->lower = NULL;
+ vlan->type |= IFACE_VLAN_T;
+ return;
+ }
+ lower = interfaces_nametointerface(interfaces, vreq.vlr_parent);
+ if (lower == NULL) {
+ log_warnx("interfaces",
+ "%s should be a VLAN of %s but %s does not exist", vlan->name,
+ vreq.vlr_parent, vreq.vlr_parent);
+ return;
+ }
+ log_debug("interfaces", "%s is VLAN %d of %s", vlan->name, vreq.vlr_tag,
+ lower->name);
+ vlan->lower = lower;
+ bitmap_set(vlan->vlan_bmap, vreq.vlr_tag);
+ vlan->type |= IFACE_VLAN_T;
+}
+
+static void
+ifbsd_check_physical(struct lldpd *cfg, struct interfaces_device_list *interfaces,
+ struct interfaces_device *iface)
+{
+ if (iface->type &
+ (IFACE_VLAN_T | IFACE_BOND_T | IFACE_BRIDGE_T | IFACE_PHYSICAL_T))
+ return;
+
+ if (!(iface->flags & (IFF_MULTICAST | IFF_BROADCAST))) {
+ log_debug("interfaces",
+ "skip %s: not able to do multicast nor broadcast", iface->name);
+ return;
+ }
+ log_debug("interfaces", "%s is a physical interface", iface->name);
+ iface->type |= IFACE_PHYSICAL_T;
+}
+
+/* Remove any dangerous interface. Currently, only p2p0 is removed as it
+ * triggers some AirDrop functionality when we send something on it.
+ * See: https://github.com/lldpd/lldpd/issues/61
+ */
+static void
+ifbsd_denylist(struct lldpd *cfg, struct interfaces_device_list *interfaces)
+{
+#ifdef HOST_OS_OSX
+ struct interfaces_device *iface = NULL;
+ TAILQ_FOREACH (iface, interfaces, next) {
+ int i;
+ if (strncmp(iface->name, "p2p", 3)) continue;
+ if (strlen(iface->name) < 4) continue;
+ for (i = 3;
+ iface->name[i] != '\0' && isdigit((unsigned char)(iface->name[i]));
+ i++)
+ ;
+ if (iface->name[i] == '\0') {
+ log_debug("interfaces", "skip %s: AirDrop interface",
+ iface->name);
+ iface->ignore = 1;
+ }
+ }
+#endif
+}
+
+static struct interfaces_device *
+ifbsd_extract_device(struct lldpd *cfg, struct ifaddrs *ifaddr)
+{
+ struct interfaces_device *iface = NULL;
+ struct sockaddr_dl *saddrdl =
+ ALIGNED_CAST(struct sockaddr_dl *, ifaddr->ifa_addr);
+ if ((saddrdl->sdl_type != IFT_BRIDGE) && (saddrdl->sdl_type != IFT_L2VLAN) &&
+ (saddrdl->sdl_type != IFT_ETHER)) {
+ log_debug("interfaces", "skip %s: not an ethernet device (%d)",
+ ifaddr->ifa_name, saddrdl->sdl_type);
+ return NULL;
+ }
+ if ((iface = calloc(1, sizeof(struct interfaces_device))) == NULL) {
+ log_warn("interfaces", "unable to allocate memory for %s",
+ ifaddr->ifa_name);
+ return NULL;
+ }
+
+ iface->index = saddrdl->sdl_index;
+ iface->name = strdup(ifaddr->ifa_name);
+ iface->flags = ifaddr->ifa_flags;
+
+ /* MAC address */
+ iface->address = malloc(ETHER_ADDR_LEN);
+ if (iface->address) memcpy(iface->address, LLADDR(saddrdl), ETHER_ADDR_LEN);
+
+ /* Grab description */
+#ifdef SIOCGIFDESCR
+# if defined HOST_OS_FREEBSD || defined HOST_OS_OPENBSD
+ iface->alias = malloc(IFDESCRSIZE);
+ if (iface->alias) {
+# if defined HOST_OS_FREEBSD
+ struct ifreq ifr = { .ifr_buffer = { .buffer = iface->alias,
+ .length = IFDESCRSIZE } };
+# else
+ struct ifreq ifr = { .ifr_data = (caddr_t)iface->alias };
+# endif
+ strlcpy(ifr.ifr_name, ifaddr->ifa_name, sizeof(ifr.ifr_name));
+ if (ioctl(cfg->g_sock, SIOCGIFDESCR, (caddr_t)&ifr) < 0) {
+ free(iface->alias);
+ iface->alias = NULL;
+ }
+ }
+# endif
+#endif /* SIOCGIFDESCR */
+
+ if (ifbsd_check_wireless(cfg, ifaddr, iface) == -1) {
+ interfaces_free_device(iface);
+ return NULL;
+ }
+
+ return iface;
+}
+
+static void
+ifbsd_extract(struct lldpd *cfg, struct interfaces_device_list *interfaces,
+ struct interfaces_address_list *addresses, struct ifaddrs *ifaddr)
+{
+ struct interfaces_address *address = NULL;
+ struct interfaces_device *device = NULL;
+ if (!ifaddr->ifa_name) return;
+ if (!ifaddr->ifa_addr) return;
+ switch (ifaddr->ifa_addr->sa_family) {
+ case AF_LINK:
+ log_debug("interfaces", "grabbing information on interface %s",
+ ifaddr->ifa_name);
+ device = ifbsd_extract_device(cfg, ifaddr);
+ if (device) {
+#if defined HOST_OS_OPENBSD
+ /* On OpenBSD, the interface can have IFF_RUNNING but be down.
+ */
+ struct if_data *ifdata;
+ ifdata = ifaddr->ifa_data;
+ if (!LINK_STATE_IS_UP(ifdata->ifi_link_state))
+ device->flags &= ~IFF_RUNNING;
+#endif
+ TAILQ_INSERT_TAIL(interfaces, device, next);
+ }
+ break;
+ case AF_INET:
+ case AF_INET6:
+ log_debug("interfaces", "got an IP address on %s", ifaddr->ifa_name);
+ address = malloc(sizeof(struct interfaces_address));
+ if (address == NULL) {
+ log_warn("interfaces",
+ "not enough memory for a new IP address on %s",
+ ifaddr->ifa_name);
+ return;
+ }
+ address->flags = ifaddr->ifa_flags;
+ address->index = if_nametoindex(ifaddr->ifa_name);
+ memcpy(&address->address, ifaddr->ifa_addr,
+ (ifaddr->ifa_addr->sa_family == AF_INET) ?
+ sizeof(struct sockaddr_in) :
+ sizeof(struct sockaddr_in6));
+ TAILQ_INSERT_TAIL(addresses, address, next);
+ break;
+ default:
+ log_debug("interfaces", "unhandled family %d for interface %s",
+ ifaddr->ifa_addr->sa_family, ifaddr->ifa_name);
+ }
+}
+
+static void
+ifbsd_macphy(struct lldpd *cfg, struct lldpd_hardware *hardware)
+{
+#ifdef ENABLE_DOT3
+ struct ifmediareq ifmr = {};
+# ifdef HAVE_TYPEOF
+ typeof(ifmr.ifm_ulist[0]) media_list[32] = {};
+# else
+ int media_list[32] = {};
+# endif
+ ifmr.ifm_ulist = media_list;
+ ifmr.ifm_count = 32;
+ struct lldpd_port *port = &hardware->h_lport;
+ unsigned int duplex;
+ unsigned int media;
+ int advertised_ifmedia_to_rfc3636[][3] = {
+ { IFM_10_T, LLDP_DOT3_LINK_AUTONEG_10BASE_T,
+ LLDP_DOT3_LINK_AUTONEG_10BASET_FD },
+ { IFM_10_STP, LLDP_DOT3_LINK_AUTONEG_10BASE_T,
+ LLDP_DOT3_LINK_AUTONEG_10BASET_FD },
+ { IFM_100_TX, LLDP_DOT3_LINK_AUTONEG_100BASE_TX,
+ LLDP_DOT3_LINK_AUTONEG_100BASE_TXFD },
+ { IFM_100_T4, LLDP_DOT3_LINK_AUTONEG_100BASE_T4,
+ LLDP_DOT3_LINK_AUTONEG_100BASE_T4 },
+ { IFM_100_T2, LLDP_DOT3_LINK_AUTONEG_100BASE_T2,
+ LLDP_DOT3_LINK_AUTONEG_100BASE_T2FD },
+ { IFM_1000_SX, LLDP_DOT3_LINK_AUTONEG_1000BASE_X,
+ LLDP_DOT3_LINK_AUTONEG_1000BASE_XFD },
+ { IFM_1000_LX, LLDP_DOT3_LINK_AUTONEG_1000BASE_X,
+ LLDP_DOT3_LINK_AUTONEG_1000BASE_XFD },
+ { IFM_1000_CX, LLDP_DOT3_LINK_AUTONEG_1000BASE_X,
+ LLDP_DOT3_LINK_AUTONEG_1000BASE_XFD },
+ { IFM_1000_T, LLDP_DOT3_LINK_AUTONEG_1000BASE_T,
+ LLDP_DOT3_LINK_AUTONEG_1000BASE_TFD },
+ { 0, 0, 0 }
+ };
+ int current_ifmedia_to_rfc3636[][3] = { { IFM_10_T, LLDP_DOT3_MAU_10BASETHD,
+ LLDP_DOT3_MAU_10BASETFD },
+ { IFM_10_STP, LLDP_DOT3_MAU_10BASETHD, LLDP_DOT3_MAU_10BASETFD },
+ { IFM_10_2, LLDP_DOT3_MAU_10BASE2, LLDP_DOT3_MAU_10BASE2 },
+ { IFM_10_5, LLDP_DOT3_MAU_10BASE5, LLDP_DOT3_MAU_10BASE5 },
+ { IFM_100_TX, LLDP_DOT3_MAU_100BASETXHD, LLDP_DOT3_MAU_100BASETXFD },
+ { IFM_100_FX, LLDP_DOT3_MAU_100BASEFXHD, LLDP_DOT3_MAU_100BASEFXFD },
+ { IFM_100_T2, LLDP_DOT3_MAU_100BASET2HD, LLDP_DOT3_MAU_100BASET2FD },
+ { IFM_1000_SX, LLDP_DOT3_MAU_1000BASESXHD, LLDP_DOT3_MAU_1000BASESXFD },
+ { IFM_10_FL, LLDP_DOT3_MAU_10BASEFLHD, LLDP_DOT3_MAU_10BASEFLFD },
+ { IFM_1000_LX, LLDP_DOT3_MAU_1000BASELXHD, LLDP_DOT3_MAU_1000BASELXFD },
+ { IFM_1000_CX, LLDP_DOT3_MAU_1000BASECXHD, LLDP_DOT3_MAU_1000BASECXFD },
+ { IFM_1000_T, LLDP_DOT3_MAU_1000BASETHD, LLDP_DOT3_MAU_1000BASETFD },
+ { IFM_10G_LR, LLDP_DOT3_MAU_10GIGBASELR, LLDP_DOT3_MAU_10GIGBASELR },
+ { IFM_10G_SR, LLDP_DOT3_MAU_10GIGBASESR, LLDP_DOT3_MAU_10GIGBASESR },
+ { IFM_10G_CX4, LLDP_DOT3_MAU_10GIGBASELX4, LLDP_DOT3_MAU_10GIGBASELX4 },
+# ifdef IFM_10G_T
+ { IFM_10G_T, LLDP_DOT3_MAU_10GIGBASECX4, LLDP_DOT3_MAU_10GIGBASECX4 },
+# endif
+# ifdef IFM_10G_TWINAX
+ { IFM_10G_TWINAX, LLDP_DOT3_MAU_10GIGBASECX4,
+ LLDP_DOT3_MAU_10GIGBASECX4 },
+# endif
+# ifdef IFM_10G_TWINAX_LONG
+ { IFM_10G_TWINAX_LONG, LLDP_DOT3_MAU_10GIGBASECX4,
+ LLDP_DOT3_MAU_10GIGBASECX4 },
+# endif
+# ifdef IFM_10G_LRM
+ { IFM_10G_LRM, LLDP_DOT3_MAU_10GIGBASELR, LLDP_DOT3_MAU_10GIGBASELR },
+# endif
+# ifdef IFM_10G_SFP_CU
+ { IFM_10G_SFP_CU, LLDP_DOT3_MAU_10GIGBASECX4,
+ LLDP_DOT3_MAU_10GIGBASECX4 },
+# endif
+ { 0, 0, 0 } };
+
+ log_debug("interfaces", "get MAC/phy for %s", hardware->h_ifname);
+ strlcpy(ifmr.ifm_name, hardware->h_ifname, sizeof(ifmr.ifm_name));
+ if (ioctl(cfg->g_sock, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) {
+ log_debug("interfaces", "unable to get media information from %s",
+ hardware->h_ifname);
+ return;
+ }
+ if (IFM_TYPE(ifmr.ifm_current) != IFM_ETHER) {
+ log_warnx("interfaces",
+ "cannot get media information from %s: not an ethernet device",
+ hardware->h_ifname);
+ return;
+ }
+ if ((ifmr.ifm_status & IFM_ACTIVE) == 0) {
+ log_debug("interfaces", "interface %s is now down, skip",
+ hardware->h_ifname);
+ return;
+ }
+ if (ifmr.ifm_count == 0) {
+ log_warnx("interfaces", "no media information available on %s",
+ hardware->h_ifname);
+ return;
+ }
+ port->p_macphy.autoneg_support = port->p_macphy.autoneg_enabled = 0;
+ for (int m = 0; m < ifmr.ifm_count; m++) {
+ media = IFM_SUBTYPE(ifmr.ifm_ulist[m]);
+ duplex = !!(IFM_OPTIONS(ifmr.ifm_ulist[m]) & IFM_FDX);
+ if (media == IFM_AUTO) {
+ port->p_macphy.autoneg_support = 1;
+ port->p_macphy.autoneg_enabled =
+ (IFM_SUBTYPE(ifmr.ifm_current) == IFM_AUTO);
+ continue;
+ }
+
+ int found = 0;
+ for (int j = 0; advertised_ifmedia_to_rfc3636[j][0]; j++) {
+ if (advertised_ifmedia_to_rfc3636[j][0] == media) {
+ port->p_macphy.autoneg_advertised |=
+ advertised_ifmedia_to_rfc3636[j][1 + duplex];
+ found = 1;
+ break;
+ }
+ }
+ if (!found)
+ port->p_macphy.autoneg_advertised |=
+ LLDP_DOT3_LINK_AUTONEG_OTHER;
+ }
+
+ port->p_macphy.mau_type = 0;
+ media = IFM_SUBTYPE(ifmr.ifm_active);
+ duplex = !!(IFM_OPTIONS(ifmr.ifm_active) & IFM_FDX);
+ for (int j = 0; current_ifmedia_to_rfc3636[j][0]; j++) {
+ if (current_ifmedia_to_rfc3636[j][0] == media) {
+ port->p_macphy.mau_type =
+ current_ifmedia_to_rfc3636[j][1 + duplex];
+ break;
+ }
+ }
+#endif
+}
+
+extern struct lldpd_ops bpf_ops;
+void
+interfaces_update(struct lldpd *cfg)
+{
+ struct lldpd_hardware *hardware;
+ struct interfaces_device *iface;
+ struct interfaces_device_list *interfaces;
+ struct interfaces_address_list *addresses;
+ struct ifaddrs *ifaddrs = NULL, *ifaddr;
+
+ interfaces = malloc(sizeof(struct interfaces_device_list));
+ addresses = malloc(sizeof(struct interfaces_address_list));
+ if (interfaces == NULL || addresses == NULL) {
+ log_warnx("interfaces", "unable to allocate memory");
+ goto end;
+ }
+ TAILQ_INIT(interfaces);
+ TAILQ_INIT(addresses);
+ if (getifaddrs(&ifaddrs) < 0) {
+ log_warnx("interfaces", "unable to get list of interfaces");
+ goto end;
+ }
+
+ for (ifaddr = ifaddrs; ifaddr != NULL; ifaddr = ifaddr->ifa_next) {
+ ifbsd_extract(cfg, interfaces, addresses, ifaddr);
+ }
+ /* Link interfaces together if needed */
+ TAILQ_FOREACH (iface, interfaces, next) {
+ ifbsd_check_bridge(cfg, interfaces, iface);
+ ifbsd_check_bond(cfg, interfaces, iface);
+ ifbsd_check_vlan(cfg, interfaces, iface);
+ ifbsd_check_physical(cfg, interfaces, iface);
+ }
+
+ ifbsd_denylist(cfg, interfaces);
+ interfaces_helper_allowlist(cfg, interfaces);
+ interfaces_helper_physical(cfg, interfaces, &bpf_ops, ifbpf_phys_init);
+#ifdef ENABLE_DOT1
+ interfaces_helper_vlan(cfg, interfaces);
+#endif
+ interfaces_helper_mgmt(cfg, addresses, interfaces);
+ interfaces_helper_chassis(cfg, interfaces);
+
+ /* Mac/PHY */
+ TAILQ_FOREACH (hardware, &cfg->g_hardware, h_entries) {
+ if (!hardware->h_flags) continue;
+ ifbsd_macphy(cfg, hardware);
+ interfaces_helper_promisc(cfg, hardware);
+ }
+
+ if (cfg->g_iface_event == NULL) {
+ int s;
+ log_debug("interfaces", "subscribe to route socket notifications");
+ if ((s = socket(PF_ROUTE, SOCK_RAW, 0)) < 0) {
+ log_warn("interfaces", "unable to open route socket");
+ goto end;
+ }
+
+#ifdef ROUTE_MSGFILTER
+ unsigned int rtfilter;
+ rtfilter = ROUTE_FILTER(RTM_IFINFO);
+ if (setsockopt(s, PF_ROUTE, ROUTE_MSGFILTER, &rtfilter,
+ sizeof(rtfilter)) == -1)
+ log_warn("interfaces",
+ "unable to set filter for interface updates");
+#endif
+
+ if (levent_iface_subscribe(cfg, s) == -1) close(s);
+ }
+
+end:
+ interfaces_free_devices(interfaces);
+ interfaces_free_addresses(addresses);
+ if (ifaddrs) freeifaddrs(ifaddrs);
+}
+
+void
+interfaces_cleanup(struct lldpd *cfg)
+{
+}
diff --git a/src/daemon/interfaces-linux.c b/src/daemon/interfaces-linux.c
new file mode 100644
index 0000000..e764943
--- /dev/null
+++ b/src/daemon/interfaces-linux.c
@@ -0,0 +1,1046 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2008 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "lldpd.h"
+
+#include <stdio.h>
+#include <unistd.h>
+#include <inttypes.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#if defined(__clang__)
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wdocumentation"
+#endif
+#include <netinet/in.h>
+#include <linux/if_vlan.h>
+#include <linux/if_bonding.h>
+#include <linux/if_bridge.h>
+#include <linux/wireless.h>
+#include <linux/sockios.h>
+#include <linux/if_packet.h>
+#include <linux/ethtool.h>
+#if defined(__clang__)
+# pragma clang diagnostic pop
+#endif
+
+#define SYSFS_PATH_MAX 256
+#define MAX_PORTS 1024
+#define MAX_BRIDGES 1024
+
+static int
+iflinux_eth_init(struct lldpd *cfg, struct lldpd_hardware *hardware)
+{
+ int fd;
+
+ log_debug("interfaces", "initialize ethernet device %s", hardware->h_ifname);
+ if ((fd = priv_iface_init(hardware->h_ifindex, hardware->h_ifname)) == -1)
+ return -1;
+ hardware->h_sendfd = fd; /* Send */
+
+ interfaces_setup_multicast(cfg, hardware->h_ifname, 0);
+
+ levent_hardware_add_fd(hardware, fd); /* Receive */
+ log_debug("interfaces", "interface %s initialized (fd=%d)", hardware->h_ifname,
+ fd);
+ return 0;
+}
+
+/* Generic ethernet send/receive */
+static int
+iflinux_eth_send(struct lldpd *cfg, struct lldpd_hardware *hardware, char *buffer,
+ size_t size)
+{
+ log_debug("interfaces", "send PDU to ethernet device %s (fd=%d)",
+ hardware->h_ifname, hardware->h_sendfd);
+ return write(hardware->h_sendfd, buffer, size);
+}
+
+static int
+iflinux_generic_recv(struct lldpd_hardware *hardware, int fd, char *buffer, size_t size,
+ struct sockaddr_ll *from)
+{
+ int n, retry = 0;
+ socklen_t fromlen;
+
+retry:
+ fromlen = sizeof(*from);
+ memset(from, 0, fromlen);
+ if ((n = recvfrom(fd, buffer, size, 0, (struct sockaddr *)from, &fromlen)) ==
+ -1) {
+ if (errno == EAGAIN && retry == 0) {
+ /* There may be an error queued in the socket. Clear it and
+ * retry. */
+ levent_recv_error(fd, hardware->h_ifname);
+ retry++;
+ goto retry;
+ }
+ if (errno == ENETDOWN) {
+ log_debug("interfaces",
+ "error while receiving frame on %s (network down)",
+ hardware->h_ifname);
+ } else {
+ log_warn("interfaces",
+ "error while receiving frame on %s (retry: %d)",
+ hardware->h_ifname, retry);
+ hardware->h_rx_discarded_cnt++;
+ }
+ return -1;
+ }
+ if (from->sll_pkttype == PACKET_OUTGOING) return -1;
+ return n;
+}
+
+static int
+iflinux_eth_recv(struct lldpd *cfg, struct lldpd_hardware *hardware, int fd,
+ char *buffer, size_t size)
+{
+ int n;
+ struct sockaddr_ll from;
+
+ log_debug("interfaces", "receive PDU from ethernet device %s",
+ hardware->h_ifname);
+ if ((n = iflinux_generic_recv(hardware, fd, buffer, size, &from)) == -1)
+ return -1;
+ return n;
+}
+
+static int
+iflinux_eth_close(struct lldpd *cfg, struct lldpd_hardware *hardware)
+{
+ log_debug("interfaces", "close ethernet device %s", hardware->h_ifname);
+ interfaces_setup_multicast(cfg, hardware->h_ifname, 1);
+ return 0;
+}
+
+static struct lldpd_ops eth_ops = {
+ .send = iflinux_eth_send,
+ .recv = iflinux_eth_recv,
+ .cleanup = iflinux_eth_close,
+};
+
+static int
+iflinux_is_bridge(struct lldpd *cfg, struct interfaces_device_list *interfaces,
+ struct interfaces_device *iface)
+{
+#ifdef ENABLE_OLDIES
+ struct interfaces_device *port;
+ char path[SYSFS_PATH_MAX];
+ int f;
+
+ if ((snprintf(path, SYSFS_PATH_MAX, SYSFS_CLASS_NET "%s/" SYSFS_BRIDGE_FDB,
+ iface->name)) >= SYSFS_PATH_MAX)
+ log_warnx("interfaces", "path truncated");
+ if ((f = priv_open(path)) < 0) return 0;
+ close(f);
+
+ /* Also grab all ports */
+ TAILQ_FOREACH (port, interfaces, next) {
+ if (port->upper) continue;
+ if (snprintf(path, SYSFS_PATH_MAX,
+ SYSFS_CLASS_NET "%s/" SYSFS_BRIDGE_PORT_SUBDIR "/%s/port_no",
+ iface->name, port->name) >= SYSFS_PATH_MAX)
+ log_warnx("interfaces", "path truncated");
+ if ((f = priv_open(path)) < 0) continue;
+ log_debug("interfaces", "port %s is bridged to %s", port->name,
+ iface->name);
+ port->upper = iface;
+ close(f);
+ }
+
+ return 1;
+#else
+ return 0;
+#endif
+}
+
+static int
+iflinux_is_vlan(struct lldpd *cfg, struct interfaces_device_list *interfaces,
+ struct interfaces_device *iface)
+{
+#ifdef ENABLE_OLDIES
+ struct vlan_ioctl_args ifv = {};
+ ifv.cmd = GET_VLAN_REALDEV_NAME_CMD;
+ strlcpy(ifv.device1, iface->name, sizeof(ifv.device1));
+ if (ioctl(cfg->g_sock, SIOCGIFVLAN, &ifv) >= 0) {
+ /* This is a VLAN, get the lower interface and the VID */
+ struct interfaces_device *lower =
+ interfaces_nametointerface(interfaces, ifv.u.device2);
+ if (!lower) {
+ log_debug("interfaces",
+ "unable to find lower interface for VLAN %s", iface->name);
+ return 0;
+ }
+
+ memset(&ifv, 0, sizeof(ifv));
+ ifv.cmd = GET_VLAN_VID_CMD;
+ strlcpy(ifv.device1, iface->name, sizeof(ifv.device1));
+ if (ioctl(cfg->g_sock, SIOCGIFVLAN, &ifv) < 0) {
+ log_debug("interfaces", "unable to find VID for VLAN %s",
+ iface->name);
+ return 0;
+ }
+
+ iface->lower = lower;
+ bitmap_set(iface->vlan_bmap, ifv.u.VID);
+ return 1;
+ }
+#endif
+ return 0;
+}
+
+static int
+iflinux_is_bond(struct lldpd *cfg, struct interfaces_device_list *interfaces,
+ struct interfaces_device *master)
+{
+#ifdef ENABLE_OLDIES
+ /* Shortcut if we detect the new team driver. Upper and lower links
+ * should already be set with netlink in this case. */
+ if (master->driver && !strcmp(master->driver, "team")) {
+ return 1;
+ }
+
+ struct ifreq ifr = {};
+ struct ifbond ifb = {};
+ strlcpy(ifr.ifr_name, master->name, sizeof(ifr.ifr_name));
+ ifr.ifr_data = (char *)&ifb;
+ if (ioctl(cfg->g_sock, SIOCBONDINFOQUERY, &ifr) >= 0) {
+ while (ifb.num_slaves--) {
+ struct ifslave ifs;
+ memset(&ifr, 0, sizeof(ifr));
+ memset(&ifs, 0, sizeof(ifs));
+ strlcpy(ifr.ifr_name, master->name, sizeof(ifr.ifr_name));
+ ifr.ifr_data = (char *)&ifs;
+ ifs.slave_id = ifb.num_slaves;
+ if (ioctl(cfg->g_sock, SIOCBONDSLAVEINFOQUERY, &ifr) >= 0) {
+ struct interfaces_device *slave =
+ interfaces_nametointerface(interfaces,
+ ifs.slave_name);
+ if (slave == NULL) continue;
+ if (slave->upper) continue;
+ log_debug("interfaces",
+ "interface %s is enslaved to %s", slave->name,
+ master->name);
+ slave->upper = master;
+ }
+ }
+ return 1;
+ }
+#endif
+ return 0;
+}
+
+/**
+ * Get permanent MAC from ethtool.
+ *
+ * Return 0 on success, -1 on error.
+ */
+static int
+iflinux_get_permanent_mac_ethtool(struct lldpd *cfg,
+ struct interfaces_device_list *interfaces, struct interfaces_device *iface)
+{
+ int ret = -1;
+ struct ifreq ifr = {};
+ struct ethtool_perm_addr *epaddr =
+ calloc(sizeof(struct ethtool_perm_addr) + ETHER_ADDR_LEN, 1);
+ if (epaddr == NULL) goto end;
+
+ strlcpy(ifr.ifr_name, iface->name, sizeof(ifr.ifr_name));
+ epaddr->cmd = ETHTOOL_GPERMADDR;
+ epaddr->size = ETHER_ADDR_LEN;
+ ifr.ifr_data = (caddr_t)epaddr;
+ if (ioctl(cfg->g_sock, SIOCETHTOOL, &ifr) == -1) {
+ static int once = 0;
+ if (errno == EPERM && !once) {
+ log_warnx("interfaces",
+ "no permission to get permanent MAC address for %s (requires 2.6.19+)",
+ iface->name);
+ once = 1;
+ goto end;
+ }
+ if (errno != EPERM)
+ log_warn("interfaces",
+ "cannot get permanent MAC address for %s", iface->name);
+ goto end;
+ }
+ if (epaddr->data[0] != 0 || epaddr->data[1] != 0 || epaddr->data[2] != 0 ||
+ epaddr->data[3] != 0 || epaddr->data[4] != 0 || epaddr->data[5] != 0) {
+ memcpy(iface->address, epaddr->data, ETHER_ADDR_LEN);
+ ret = 0;
+ goto end;
+ }
+ log_debug("interfaces", "cannot get permanent MAC for %s (all 0)", iface->name);
+end:
+ free(epaddr);
+ return ret;
+}
+
+/**
+ * Get permanent MAC address for a bond device.
+ */
+static void
+iflinux_get_permanent_mac_bond(struct lldpd *cfg,
+ struct interfaces_device_list *interfaces, struct interfaces_device *iface)
+{
+ struct interfaces_device *master = iface->upper;
+ int f, state = 0;
+ FILE *netbond;
+ const char *slaveif = "Slave Interface: ";
+ const char *hwaddr = "Permanent HW addr: ";
+ u_int8_t mac[ETHER_ADDR_LEN];
+ char path[SYSFS_PATH_MAX];
+ char line[100];
+
+ /* We have a bond, we need to query it to get real MAC addresses */
+ if (snprintf(path, SYSFS_PATH_MAX, "/proc/net/bonding/%s", master->name) >=
+ SYSFS_PATH_MAX) {
+ log_warnx("interfaces", "path truncated");
+ return;
+ }
+ if ((f = priv_open(path)) < 0) {
+ if (snprintf(path, SYSFS_PATH_MAX, "/proc/self/net/bonding/%s",
+ master->name) >= SYSFS_PATH_MAX) {
+ log_warnx("interfaces", "path truncated");
+ return;
+ }
+ f = priv_open(path);
+ }
+ if (f < 0) {
+ log_warnx("interfaces", "unable to get permanent MAC address for %s",
+ iface->name);
+ return;
+ }
+ if ((netbond = fdopen(f, "r")) == NULL) {
+ log_warn("interfaces", "unable to read stream from %s", path);
+ close(f);
+ return;
+ }
+ /* State 0:
+ We parse the file to search "Slave Interface: ". If found, go to
+ state 1.
+ State 1:
+ We parse the file to search "Permanent HW addr: ". If found, we get
+ the mac.
+ */
+ while (fgets(line, sizeof(line), netbond)) {
+ switch (state) {
+ case 0:
+ if (strncmp(line, slaveif, strlen(slaveif)) == 0) {
+ if (line[strlen(line) - 1] == '\n')
+ line[strlen(line) - 1] = '\0';
+ if (strcmp(iface->name, line + strlen(slaveif)) == 0)
+ state++;
+ }
+ break;
+ case 1:
+ if (strncmp(line, hwaddr, strlen(hwaddr)) == 0) {
+ if (line[strlen(line) - 1] == '\n')
+ line[strlen(line) - 1] = '\0';
+ if (sscanf(line + strlen(hwaddr),
+ "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
+ &mac[0], &mac[1], &mac[2], &mac[3], &mac[4],
+ &mac[5]) != ETHER_ADDR_LEN) {
+ log_warn("interfaces", "unable to parse %s",
+ line + strlen(hwaddr));
+ fclose(netbond);
+ return;
+ }
+ memcpy(iface->address, mac, ETHER_ADDR_LEN);
+ fclose(netbond);
+ return;
+ }
+ break;
+ }
+ }
+ log_warnx("interfaces", "unable to find real MAC address for enslaved %s",
+ iface->name);
+ fclose(netbond);
+}
+
+/**
+ * Get permanent MAC.
+ */
+static void
+iflinux_get_permanent_mac(struct lldpd *cfg, struct interfaces_device_list *interfaces,
+ struct interfaces_device *iface)
+{
+ struct interfaces_device *master = iface->upper;
+
+ if (master == NULL || master->type != IFACE_BOND_T) return;
+ if (iflinux_get_permanent_mac_ethtool(cfg, interfaces, iface) == -1 &&
+ (master->driver == NULL || !strcmp(master->driver, "bonding")))
+ /* Fallback to old method for a bond */
+ iflinux_get_permanent_mac_bond(cfg, interfaces, iface);
+}
+
+#ifdef ENABLE_DOT3
+# define ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32 (SCHAR_MAX)
+# define ETHTOOL_DECLARE_LINK_MODE_MASK(name) \
+ uint32_t name[ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32]
+
+struct ethtool_link_usettings {
+ struct ethtool_link_settings base;
+ struct {
+ ETHTOOL_DECLARE_LINK_MODE_MASK(supported);
+ ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
+ ETHTOOL_DECLARE_LINK_MODE_MASK(lp_advertising);
+ } link_modes;
+};
+
+static int
+iflinux_ethtool_link_mode_test_bit(unsigned int nr, const uint32_t *mask)
+{
+ if (nr >= 32 * ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32) return 0;
+ return !!(mask[nr / 32] & (1 << (nr % 32)));
+}
+static void
+iflinux_ethtool_link_mode_unset_bit(unsigned int nr, uint32_t *mask)
+{
+ if (nr >= 32 * ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32) return;
+ mask[nr / 32] &= ~(1 << (nr % 32));
+}
+static int
+iflinux_ethtool_link_mode_is_empty(const uint32_t *mask)
+{
+ for (unsigned int i = 0; i < ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32; ++i) {
+ if (mask[i] != 0) return 0;
+ }
+
+ return 1;
+}
+
+static int
+iflinux_ethtool_glink(struct lldpd *cfg, const char *ifname,
+ struct ethtool_link_usettings *uset)
+{
+ int rc;
+
+ /* Try with ETHTOOL_GLINKSETTINGS first */
+ struct {
+ struct ethtool_link_settings req;
+ uint32_t link_mode_data[3 * ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32];
+ } ecmd;
+ static int8_t nwords = 0;
+ struct ifreq ifr = {};
+ strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
+
+ if (nwords == 0) {
+ /* Do a handshake first. We assume that this is device-independant. */
+ memset(&ecmd, 0, sizeof(ecmd));
+ ecmd.req.cmd = ETHTOOL_GLINKSETTINGS;
+ ifr.ifr_data = (caddr_t)&ecmd;
+ rc = ioctl(cfg->g_sock, SIOCETHTOOL, &ifr);
+ if (rc == 0) {
+ nwords = -ecmd.req.link_mode_masks_nwords;
+ log_debug("interfaces", "glinksettings nwords is %" PRId8,
+ nwords);
+ } else {
+ static int once = 0;
+ if (errno == EPERM && !once) {
+ log_warnx("interfaces",
+ "cannot get ethtool link information "
+ "with GLINKSETTINGS (requires 4.9+). "
+ "25G+ speeds may be missing in MAC/PHY TLVs");
+ once = 1;
+ }
+ nwords = -1;
+ }
+ }
+ if (nwords > 0) {
+ memset(&ecmd, 0, sizeof(ecmd));
+ ecmd.req.cmd = ETHTOOL_GLINKSETTINGS;
+ ecmd.req.link_mode_masks_nwords = nwords;
+ ifr.ifr_data = (caddr_t)&ecmd;
+ rc = ioctl(cfg->g_sock, SIOCETHTOOL, &ifr);
+ if (rc == 0) {
+ log_debug("interfaces",
+ "got ethtool results for %s with GLINKSETTINGS", ifname);
+ memcpy(&uset->base, &ecmd.req, sizeof(uset->base));
+ unsigned int u32_offs = 0;
+ memcpy(uset->link_modes.supported,
+ &ecmd.link_mode_data[u32_offs],
+ 4 * ecmd.req.link_mode_masks_nwords);
+ u32_offs += ecmd.req.link_mode_masks_nwords;
+ memcpy(uset->link_modes.advertising,
+ &ecmd.link_mode_data[u32_offs],
+ 4 * ecmd.req.link_mode_masks_nwords);
+ u32_offs += ecmd.req.link_mode_masks_nwords;
+ memcpy(uset->link_modes.lp_advertising,
+ &ecmd.link_mode_data[u32_offs],
+ 4 * ecmd.req.link_mode_masks_nwords);
+ goto end;
+ }
+ }
+
+ /* Try with ETHTOOL_GSET */
+ struct ethtool_cmd ethc;
+ memset(&ethc, 0, sizeof(ethc));
+ ethc.cmd = ETHTOOL_GSET;
+ ifr.ifr_data = (caddr_t)&ethc;
+ rc = ioctl(cfg->g_sock, SIOCETHTOOL, &ifr);
+ if (rc == 0) {
+ /* Do a partial copy (only what we need) */
+ log_debug("interfaces", "got ethtool results for %s with GSET", ifname);
+ memset(uset, 0, sizeof(*uset));
+ uset->base.cmd = ETHTOOL_GSET;
+ uset->base.link_mode_masks_nwords = 1;
+ uset->link_modes.supported[0] = ethc.supported;
+ uset->link_modes.advertising[0] = ethc.advertising;
+ uset->link_modes.lp_advertising[0] = ethc.lp_advertising;
+ uset->base.speed = (ethc.speed_hi << 16) | ethc.speed;
+ uset->base.duplex = ethc.duplex;
+ uset->base.port = ethc.port;
+ uset->base.autoneg = ethc.autoneg;
+ } else {
+ static int once = 0;
+ if (errno == EPERM && !once) {
+ log_warnx("interfaces",
+ "cannot get ethtool link information "
+ "with GSET (requires 2.6.19+). "
+ "MAC/PHY TLV will be unavailable");
+ once = 1;
+ }
+ }
+end:
+ return rc;
+}
+
+/* Fill up MAC/PHY for a given hardware port */
+static void
+iflinux_macphy(struct lldpd *cfg, struct lldpd_hardware *hardware)
+{
+ struct ethtool_link_usettings uset = {};
+ struct lldpd_port *port = &hardware->h_lport;
+ int j;
+ int advertised_ethtool_to_rfc3636[][2] = {
+ { ETHTOOL_LINK_MODE_10baseT_Half_BIT, LLDP_DOT3_LINK_AUTONEG_10BASE_T },
+ { ETHTOOL_LINK_MODE_10baseT_Full_BIT,
+ LLDP_DOT3_LINK_AUTONEG_10BASET_FD },
+ { ETHTOOL_LINK_MODE_100baseT_Half_BIT,
+ LLDP_DOT3_LINK_AUTONEG_100BASE_TX },
+ { ETHTOOL_LINK_MODE_100baseT_Full_BIT,
+ LLDP_DOT3_LINK_AUTONEG_100BASE_TXFD },
+ { ETHTOOL_LINK_MODE_1000baseT_Half_BIT,
+ LLDP_DOT3_LINK_AUTONEG_1000BASE_T },
+ { ETHTOOL_LINK_MODE_1000baseT_Full_BIT,
+ LLDP_DOT3_LINK_AUTONEG_1000BASE_TFD },
+ { ETHTOOL_LINK_MODE_1000baseKX_Full_BIT,
+ LLDP_DOT3_LINK_AUTONEG_1000BASE_XFD },
+ { ETHTOOL_LINK_MODE_Pause_BIT, LLDP_DOT3_LINK_AUTONEG_FDX_PAUSE },
+ { ETHTOOL_LINK_MODE_Asym_Pause_BIT, LLDP_DOT3_LINK_AUTONEG_FDX_APAUSE },
+ { -1, 0 }
+ };
+
+ log_debug("interfaces", "ask ethtool for the appropriate MAC/PHY for %s",
+ hardware->h_ifname);
+ if (iflinux_ethtool_glink(cfg, hardware->h_ifname, &uset) == 0) {
+ port->p_macphy.autoneg_support =
+ iflinux_ethtool_link_mode_test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
+ uset.link_modes.supported);
+ port->p_macphy.autoneg_enabled =
+ (uset.base.autoneg == AUTONEG_DISABLE) ? 0 : 1;
+ for (j = 0; advertised_ethtool_to_rfc3636[j][0] >= 0; j++) {
+ if (iflinux_ethtool_link_mode_test_bit(
+ advertised_ethtool_to_rfc3636[j][0],
+ uset.link_modes.advertising)) {
+ port->p_macphy.autoneg_advertised |=
+ advertised_ethtool_to_rfc3636[j][1];
+ iflinux_ethtool_link_mode_unset_bit(
+ advertised_ethtool_to_rfc3636[j][0],
+ uset.link_modes.advertising);
+ }
+ }
+ iflinux_ethtool_link_mode_unset_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
+ uset.link_modes.advertising);
+ iflinux_ethtool_link_mode_unset_bit(ETHTOOL_LINK_MODE_TP_BIT,
+ uset.link_modes.advertising);
+ iflinux_ethtool_link_mode_unset_bit(ETHTOOL_LINK_MODE_AUI_BIT,
+ uset.link_modes.advertising);
+ iflinux_ethtool_link_mode_unset_bit(ETHTOOL_LINK_MODE_MII_BIT,
+ uset.link_modes.advertising);
+ iflinux_ethtool_link_mode_unset_bit(ETHTOOL_LINK_MODE_FIBRE_BIT,
+ uset.link_modes.advertising);
+ iflinux_ethtool_link_mode_unset_bit(ETHTOOL_LINK_MODE_BNC_BIT,
+ uset.link_modes.advertising);
+ iflinux_ethtool_link_mode_unset_bit(ETHTOOL_LINK_MODE_Pause_BIT,
+ uset.link_modes.advertising);
+ iflinux_ethtool_link_mode_unset_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
+ uset.link_modes.advertising);
+ iflinux_ethtool_link_mode_unset_bit(ETHTOOL_LINK_MODE_Backplane_BIT,
+ uset.link_modes.advertising);
+ if (!iflinux_ethtool_link_mode_is_empty(uset.link_modes.advertising)) {
+ port->p_macphy.autoneg_advertised |=
+ LLDP_DOT3_LINK_AUTONEG_OTHER;
+ }
+ switch (uset.base.speed) {
+ case SPEED_10:
+ port->p_macphy.mau_type = (uset.base.duplex == DUPLEX_FULL) ?
+ LLDP_DOT3_MAU_10BASETFD :
+ LLDP_DOT3_MAU_10BASETHD;
+ if (uset.base.port == PORT_BNC)
+ port->p_macphy.mau_type = LLDP_DOT3_MAU_10BASE2;
+ if (uset.base.port == PORT_FIBRE)
+ port->p_macphy.mau_type =
+ (uset.base.duplex == DUPLEX_FULL) ?
+ LLDP_DOT3_MAU_10BASEFLFD :
+ LLDP_DOT3_MAU_10BASEFLHD;
+ break;
+ case SPEED_100:
+ port->p_macphy.mau_type = (uset.base.duplex == DUPLEX_FULL) ?
+ LLDP_DOT3_MAU_100BASETXFD :
+ LLDP_DOT3_MAU_100BASETXHD;
+ if (uset.base.port == PORT_BNC)
+ port->p_macphy.mau_type =
+ (uset.base.duplex == DUPLEX_FULL) ?
+ LLDP_DOT3_MAU_100BASET2FD :
+ LLDP_DOT3_MAU_100BASET2HD;
+ if (uset.base.port == PORT_FIBRE)
+ port->p_macphy.mau_type =
+ (uset.base.duplex == DUPLEX_FULL) ?
+ LLDP_DOT3_MAU_100BASEFXFD :
+ LLDP_DOT3_MAU_100BASEFXHD;
+ break;
+ case SPEED_1000:
+ port->p_macphy.mau_type = (uset.base.duplex == DUPLEX_FULL) ?
+ LLDP_DOT3_MAU_1000BASETFD :
+ LLDP_DOT3_MAU_1000BASETHD;
+ if (uset.base.port == PORT_FIBRE)
+ port->p_macphy.mau_type =
+ (uset.base.duplex == DUPLEX_FULL) ?
+ LLDP_DOT3_MAU_1000BASEXFD :
+ LLDP_DOT3_MAU_1000BASEXHD;
+ break;
+ case SPEED_2500:
+ port->p_macphy.mau_type = LLDP_DOT3_MAU_2P5GIGT;
+ break;
+ case SPEED_5000:
+ port->p_macphy.mau_type = LLDP_DOT3_MAU_5GIGT;
+ break;
+ case SPEED_10000:
+ // Distinguish between RJ45 BaseT, DAC BaseCX4, or Fibre BaseLR
+ if (uset.base.port == PORT_TP) {
+ port->p_macphy.mau_type = LLDP_DOT3_MAU_10GBASET;
+ } else if (uset.base.port == PORT_FIBRE) {
+ port->p_macphy.mau_type = LLDP_DOT3_MAU_10GIGBASELR;
+ } else if (uset.base.port == PORT_DA) {
+ port->p_macphy.mau_type = LLDP_DOT3_MAU_10GIGBASECX4;
+ }
+ break;
+ case SPEED_25000:
+ // Distinguish between RJ45 BaseT, DAC BaseCR, or Fibre BaseLR
+ if (uset.base.port == PORT_TP) {
+ port->p_macphy.mau_type = LLDP_DOT3_MAU_25GBASET;
+ } else if (uset.base.port == PORT_FIBRE) {
+ port->p_macphy.mau_type = LLDP_DOT3_MAU_25GBASELR;
+ } else if (uset.base.port == PORT_DA) {
+ port->p_macphy.mau_type = LLDP_DOT3_MAU_25GBASECR;
+ }
+ break;
+ case SPEED_40000:
+ // Same kind of approximation.
+ port->p_macphy.mau_type = (uset.base.port == PORT_FIBRE) ?
+ LLDP_DOT3_MAU_40GBASELR4 :
+ LLDP_DOT3_MAU_40GBASECR4;
+ break;
+ case SPEED_50000:
+ // Same kind of approximation.
+ port->p_macphy.mau_type = (uset.base.port == PORT_FIBRE) ?
+ LLDP_DOT3_MAU_50GBASELR :
+ LLDP_DOT3_MAU_50GBASECR;
+ break;
+ case SPEED_100000:
+ // Ditto
+ port->p_macphy.mau_type = (uset.base.port == PORT_FIBRE) ?
+ LLDP_DOT3_MAU_100GBASELR4 :
+ LLDP_DOT3_MAU_100GBASECR4;
+ break;
+ }
+ if (uset.base.port == PORT_AUI)
+ port->p_macphy.mau_type = LLDP_DOT3_MAU_AUI;
+ }
+}
+#else /* ENABLE_DOT3 */
+static void
+iflinux_macphy(struct lldpd *cfg, struct lldpd_hardware *hardware)
+{
+}
+#endif /* ENABLE_DOT3 */
+
+#ifdef ENABLE_OLDIES
+struct bond_master {
+ char name[IFNAMSIZ];
+ int index;
+};
+
+static int
+iface_bond_init(struct lldpd *cfg, struct lldpd_hardware *hardware)
+{
+ struct bond_master *master = hardware->h_data;
+ int fd;
+ int un = 1;
+
+ if (!master) return -1;
+
+ log_debug("interfaces", "initialize enslaved device %s", hardware->h_ifname);
+
+ /* First, we get a socket to the raw physical interface */
+ if ((fd = priv_iface_init(hardware->h_ifindex, hardware->h_ifname)) == -1)
+ return -1;
+ hardware->h_sendfd = fd;
+ interfaces_setup_multicast(cfg, hardware->h_ifname, 0);
+
+ /* Then, we open a raw interface for the master */
+ log_debug("interfaces", "enslaved device %s has master %s(%d)",
+ hardware->h_ifname, master->name, master->index);
+ if ((fd = priv_iface_init(master->index, master->name)) == -1) {
+ close(hardware->h_sendfd);
+ return -1;
+ }
+ /* With bonding and older kernels (< 2.6.27) we need to listen
+ * to bond device. We use setsockopt() PACKET_ORIGDEV to get
+ * physical device instead of bond device (works with >=
+ * 2.6.24). */
+ if (setsockopt(fd, SOL_PACKET, PACKET_ORIGDEV, &un, sizeof(un)) == -1) {
+ log_info("interfaces",
+ "unable to setsockopt for master bonding device of %s. "
+ "You will get inaccurate results",
+ hardware->h_ifname);
+ }
+ interfaces_setup_multicast(cfg, master->name, 0);
+
+ levent_hardware_add_fd(hardware, hardware->h_sendfd);
+ levent_hardware_add_fd(hardware, fd);
+ log_debug("interfaces", "interface %s initialized (fd=%d,master=%s[%d])",
+ hardware->h_ifname, hardware->h_sendfd, master->name, fd);
+ return 0;
+}
+
+static int
+iface_bond_recv(struct lldpd *cfg, struct lldpd_hardware *hardware, int fd,
+ char *buffer, size_t size)
+{
+ int n;
+ struct sockaddr_ll from;
+ struct bond_master *master = hardware->h_data;
+
+ log_debug("interfaces", "receive PDU from enslaved device %s",
+ hardware->h_ifname);
+ if ((n = iflinux_generic_recv(hardware, fd, buffer, size, &from)) == -1)
+ return -1;
+ if (fd == hardware->h_sendfd) /* We received this on the physical interface. */
+ return n;
+ /* We received this on the bonding interface. Is it really for us? */
+ if (from.sll_ifindex == hardware->h_ifindex) /* This is for us */
+ return n;
+ if (from.sll_ifindex == master->index)
+ /* We don't know from which physical interface it comes (kernel
+ * < 2.6.24). In doubt, this is for us. */
+ return n;
+ return -1; /* Not for us */
+}
+
+static int
+iface_bond_close(struct lldpd *cfg, struct lldpd_hardware *hardware)
+{
+ struct bond_master *master = hardware->h_data;
+ log_debug("interfaces", "closing enslaved device %s", hardware->h_ifname);
+ interfaces_setup_multicast(cfg, hardware->h_ifname, 1);
+ interfaces_setup_multicast(cfg, master->name, 1);
+ free(hardware->h_data);
+ hardware->h_data = NULL;
+ return 0;
+}
+
+struct lldpd_ops bond_ops = {
+ .send = iflinux_eth_send,
+ .recv = iface_bond_recv,
+ .cleanup = iface_bond_close,
+};
+
+static void
+iflinux_handle_bond(struct lldpd *cfg, struct interfaces_device_list *interfaces)
+{
+ struct interfaces_device *iface;
+ struct interfaces_device *master;
+ struct lldpd_hardware *hardware;
+ struct bond_master *bmaster;
+ int created;
+ TAILQ_FOREACH (iface, interfaces, next) {
+ if (!(iface->type & IFACE_PHYSICAL_T)) continue;
+ if (iface->ignore) continue;
+ if (!iface->upper || !(iface->upper->type & IFACE_BOND_T)) continue;
+
+ master = iface->upper;
+ log_debug("interfaces",
+ "%s is an acceptable enslaved device (master=%s)", iface->name,
+ master->name);
+ created = 0;
+ if ((hardware = lldpd_get_hardware(cfg, iface->name, iface->index)) ==
+ NULL) {
+ if ((hardware = lldpd_alloc_hardware(cfg, iface->name,
+ iface->index)) == NULL) {
+ log_warnx("interfaces",
+ "Unable to allocate space for %s", iface->name);
+ continue;
+ }
+ created = 1;
+ }
+ if (hardware->h_flags) continue;
+ if (hardware->h_ops != &bond_ops || hardware->h_ifindex_changed) {
+ if (!created) {
+ log_debug("interfaces",
+ "bond %s is converted from another type of interface",
+ hardware->h_ifname);
+ if (hardware->h_ops && hardware->h_ops->cleanup)
+ hardware->h_ops->cleanup(cfg, hardware);
+ levent_hardware_release(hardware);
+ levent_hardware_init(hardware);
+ }
+ bmaster = hardware->h_data =
+ calloc(1, sizeof(struct bond_master));
+ if (!bmaster) {
+ log_warn("interfaces", "not enough memory");
+ lldpd_hardware_cleanup(cfg, hardware);
+ continue;
+ }
+ } else
+ bmaster = hardware->h_data;
+ bmaster->index = master->index;
+ strlcpy(bmaster->name, master->name, IFNAMSIZ);
+ if (hardware->h_ops != &bond_ops || hardware->h_ifindex_changed) {
+ if (iface_bond_init(cfg, hardware) != 0) {
+ log_warn("interfaces", "unable to initialize %s",
+ hardware->h_ifname);
+ lldpd_hardware_cleanup(cfg, hardware);
+ continue;
+ }
+ hardware->h_ops = &bond_ops;
+ hardware->h_mangle = 1;
+ }
+ if (created)
+ interfaces_helper_add_hardware(cfg, hardware);
+ else
+ lldpd_port_cleanup(&hardware->h_lport, 0);
+
+ hardware->h_flags = iface->flags;
+ iface->ignore = 1;
+
+ /* Get local address */
+ memcpy(&hardware->h_lladdr, iface->address, ETHER_ADDR_LEN);
+
+ /* Fill information about port */
+ interfaces_helper_port_name_desc(cfg, hardware, iface);
+
+ /* Fill additional info */
+# ifdef ENABLE_DOT3
+ hardware->h_lport.p_aggregid = master->index;
+# endif
+ hardware->h_mtu = iface->mtu ? iface->mtu : 1500;
+ }
+}
+#endif
+
+/* Query each interface to get the appropriate driver */
+static void
+iflinux_add_driver(struct lldpd *cfg, struct interfaces_device_list *interfaces)
+{
+ struct interfaces_device *iface;
+ TAILQ_FOREACH (iface, interfaces, next) {
+ struct ethtool_drvinfo ethc = { .cmd = ETHTOOL_GDRVINFO };
+ struct ifreq ifr = { .ifr_data = (caddr_t)&ethc };
+ if (iface->driver) continue;
+
+ strlcpy(ifr.ifr_name, iface->name, IFNAMSIZ);
+ if (ioctl(cfg->g_sock, SIOCETHTOOL, &ifr) == 0) {
+ iface->driver = strdup(ethc.driver);
+ log_debug("interfaces", "driver for %s is `%s`", iface->name,
+ iface->driver);
+ }
+ }
+}
+
+/* Query each interface to see if it is a wireless one */
+static void
+iflinux_add_wireless(struct lldpd *cfg, struct interfaces_device_list *interfaces)
+{
+ struct interfaces_device *iface;
+ TAILQ_FOREACH (iface, interfaces, next) {
+ struct iwreq iwr = {};
+ strlcpy(iwr.ifr_name, iface->name, IFNAMSIZ);
+ if (ioctl(cfg->g_sock, SIOCGIWNAME, &iwr) >= 0) {
+ log_debug("interfaces", "%s is wireless", iface->name);
+ iface->type |= IFACE_WIRELESS_T | IFACE_PHYSICAL_T;
+ }
+ }
+}
+
+/* Query each interface to see if it is a bridge */
+static void
+iflinux_add_bridge(struct lldpd *cfg, struct interfaces_device_list *interfaces)
+{
+ struct interfaces_device *iface;
+
+ TAILQ_FOREACH (iface, interfaces, next) {
+ if (iface->type &
+ (IFACE_PHYSICAL_T | IFACE_VLAN_T | IFACE_BOND_T | IFACE_BRIDGE_T))
+ continue;
+ if (iflinux_is_bridge(cfg, interfaces, iface)) {
+ log_debug("interfaces", "interface %s is a bridge",
+ iface->name);
+ iface->type |= IFACE_BRIDGE_T;
+ }
+ }
+}
+
+/* Query each interface to see if it is a bond */
+static void
+iflinux_add_bond(struct lldpd *cfg, struct interfaces_device_list *interfaces)
+{
+ struct interfaces_device *iface;
+
+ TAILQ_FOREACH (iface, interfaces, next) {
+ if (iface->type &
+ (IFACE_PHYSICAL_T | IFACE_VLAN_T | IFACE_BOND_T | IFACE_BRIDGE_T))
+ continue;
+ if (iflinux_is_bond(cfg, interfaces, iface)) {
+ log_debug("interfaces", "interface %s is a bond", iface->name);
+ iface->type |= IFACE_BOND_T;
+ }
+ }
+}
+
+/* Query each interface to see if it is a vlan */
+static void
+iflinux_add_vlan(struct lldpd *cfg, struct interfaces_device_list *interfaces)
+{
+ struct interfaces_device *iface;
+
+ TAILQ_FOREACH (iface, interfaces, next) {
+ if (iface->type &
+ (IFACE_PHYSICAL_T | IFACE_VLAN_T | IFACE_BOND_T | IFACE_BRIDGE_T))
+ continue;
+ if (iflinux_is_vlan(cfg, interfaces, iface)) {
+ log_debug("interfaces", "interface %s is a VLAN", iface->name);
+ iface->type |= IFACE_VLAN_T;
+ }
+ }
+}
+
+static void
+iflinux_add_physical(struct lldpd *cfg, struct interfaces_device_list *interfaces)
+{
+ struct interfaces_device *iface;
+ /* Deny some drivers */
+ const char *const *rif;
+ const char *const denied_drivers[] = { "cdc_mbim", "vxlan", NULL };
+
+ TAILQ_FOREACH (iface, interfaces, next) {
+ if (iface->type & (IFACE_VLAN_T | IFACE_BOND_T | IFACE_BRIDGE_T))
+ continue;
+
+ iface->type &= ~IFACE_PHYSICAL_T;
+
+ /* We request that the interface is able to do either multicast
+ * or broadcast to be able to send discovery frames. */
+ if (!(iface->flags & (IFF_MULTICAST | IFF_BROADCAST))) {
+ log_debug("interfaces",
+ "skip %s: not able to do multicast nor broadcast",
+ iface->name);
+ continue;
+ }
+
+ /* Check if the driver is not denied */
+ if (iface->driver) {
+ int skip = 0;
+ for (rif = denied_drivers; *rif; rif++) {
+ if (strcmp(iface->driver, *rif) == 0) {
+ log_debug("interfaces",
+ "skip %s: denied driver", iface->name);
+ skip = 1;
+ break;
+ }
+ }
+ if (skip) continue;
+ }
+
+ /* If the interface is linked to another one, skip it too. */
+ if (iface->lower &&
+ (!iface->driver ||
+ (strcmp(iface->driver, "veth") &&
+ strcmp(iface->driver, "dsa")))) {
+ log_debug("interfaces",
+ "skip %s: there is a lower interface (%s)", iface->name,
+ iface->lower->name);
+ continue;
+ }
+
+ /* Get the real MAC address (for example, if the interface is enslaved)
+ */
+ iflinux_get_permanent_mac(cfg, interfaces, iface);
+
+ log_debug("interfaces", "%s is a physical interface", iface->name);
+ iface->type |= IFACE_PHYSICAL_T;
+ }
+}
+
+void
+interfaces_update(struct lldpd *cfg)
+{
+ struct lldpd_hardware *hardware;
+ struct interfaces_device_list *interfaces;
+ struct interfaces_address_list *addresses;
+ interfaces = netlink_get_interfaces(cfg);
+ addresses = netlink_get_addresses(cfg);
+ if (interfaces == NULL || addresses == NULL) {
+ log_warnx("interfaces", "cannot update the list of local interfaces");
+ return;
+ }
+
+ /* Add missing bits to list of interfaces */
+ iflinux_add_driver(cfg, interfaces);
+ if (LOCAL_CHASSIS(cfg)->c_cap_available & LLDP_CAP_WLAN)
+ iflinux_add_wireless(cfg, interfaces);
+ if (LOCAL_CHASSIS(cfg)->c_cap_available & LLDP_CAP_BRIDGE)
+ iflinux_add_bridge(cfg, interfaces);
+ iflinux_add_bond(cfg, interfaces);
+ iflinux_add_vlan(cfg, interfaces);
+ iflinux_add_physical(cfg, interfaces);
+
+ interfaces_helper_allowlist(cfg, interfaces);
+#ifdef ENABLE_OLDIES
+ iflinux_handle_bond(cfg, interfaces);
+#endif
+ interfaces_helper_physical(cfg, interfaces, &eth_ops, iflinux_eth_init);
+#ifdef ENABLE_DOT1
+ interfaces_helper_vlan(cfg, interfaces);
+#endif
+ interfaces_helper_mgmt(cfg, addresses, interfaces);
+ interfaces_helper_chassis(cfg, interfaces);
+
+ /* Mac/PHY */
+ TAILQ_FOREACH (hardware, &cfg->g_hardware, h_entries) {
+ if (!hardware->h_flags) continue;
+ iflinux_macphy(cfg, hardware);
+ interfaces_helper_promisc(cfg, hardware);
+ }
+}
+
+void
+interfaces_cleanup(struct lldpd *cfg)
+{
+ netlink_cleanup(cfg);
+}
diff --git a/src/daemon/interfaces-solaris.c b/src/daemon/interfaces-solaris.c
new file mode 100644
index 0000000..5e3ae3c
--- /dev/null
+++ b/src/daemon/interfaces-solaris.c
@@ -0,0 +1,174 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2013 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "lldpd.h"
+
+#include <unistd.h>
+#include <sys/sockio.h>
+#include <net/if_types.h>
+
+/* Solaris comes with libdladm which seems to be handy to get all the necessary
+ * information. Unfortunately, this library needs a special device file and a
+ * Unix socket to a daemon. This is a bit difficult to use it in a
+ * privilege-separated daemon. Therefore, we keep using ioctl(). This should
+ * also improve compatibility with older versions of Solaris.
+ */
+
+static void
+ifsolaris_extract(struct lldpd *cfg, struct interfaces_device_list *interfaces,
+ struct interfaces_address_list *addresses, struct lifreq *lifr)
+{
+ int flags = 0;
+ int index = 0;
+ struct interfaces_address *address = NULL;
+ struct interfaces_device *device = NULL;
+
+ sa_family_t lifr_af = lifr->lifr_addr.ss_family;
+ struct lifreq lifrl = { .lifr_name = {} };
+ strlcpy(lifrl.lifr_name, lifr->lifr_name, sizeof(lifrl.lifr_name));
+
+ /* Flags */
+ if (ioctl(cfg->g_sock, SIOCGLIFFLAGS, (caddr_t)&lifrl) < 0) {
+ log_warn("interfaces", "unable to get flags for %s", lifrl.lifr_name);
+ return;
+ }
+ flags = lifrl.lifr_flags;
+
+ /* Index */
+ if (ioctl(cfg->g_sock, SIOCGLIFINDEX, (caddr_t)&lifrl) < 0) {
+ log_warn("interfaces", "unable to get index for %s", lifrl.lifr_name);
+ return;
+ }
+ index = lifrl.lifr_index;
+
+ /* Record the address */
+ if ((address = malloc(sizeof(struct interfaces_address))) == NULL) {
+ log_warn("interfaces", "not enough memory for a new IP address on %s",
+ lifrl.lifr_name);
+ return;
+ }
+ address->flags = flags;
+ address->index = index;
+ memcpy(&address->address, &lifr->lifr_addr,
+ (lifr_af == AF_INET) ? sizeof(struct sockaddr_in) :
+ sizeof(struct sockaddr_in6));
+ TAILQ_INSERT_TAIL(addresses, address, next);
+
+ /* Hardware address */
+ if (ioctl(cfg->g_sock, SIOCGLIFHWADDR, (caddr_t)&lifrl) < 0) {
+ log_debug("interfaces", "unable to get hardware address for %s",
+ lifrl.lifr_name);
+ return;
+ }
+ struct sockaddr_dl *saddrdl = (struct sockaddr_dl *)&lifrl.lifr_addr;
+ if (saddrdl->sdl_type != 4) {
+ log_debug("interfaces", "skip %s: not an ethernet device (%d)",
+ lifrl.lifr_name, saddrdl->sdl_type);
+ return;
+ }
+
+ /* Handle the interface */
+ if ((device = calloc(1, sizeof(struct interfaces_device))) == NULL) {
+ log_warn("interfaces", "unable to allocate memory for %s",
+ lifrl.lifr_name);
+ return;
+ }
+
+ device->name = strdup(lifrl.lifr_name);
+ device->flags = flags;
+ device->index = index;
+ device->type = IFACE_PHYSICAL_T;
+ device->address = malloc(ETHER_ADDR_LEN);
+ if (device->address) memcpy(device->address, LLADDR(saddrdl), ETHER_ADDR_LEN);
+
+ /* MTU */
+ if (ioctl(cfg->g_sock, SIOCGLIFMTU, (caddr_t)&lifrl) < 0) {
+ log_debug("interfaces", "unable to get MTU for %s", lifrl.lifr_name);
+ } else
+ device->mtu = lifrl.lifr_mtu;
+
+ TAILQ_INSERT_TAIL(interfaces, device, next);
+}
+
+extern struct lldpd_ops bpf_ops;
+void
+interfaces_update(struct lldpd *cfg)
+{
+ struct lldpd_hardware *hardware;
+ caddr_t buffer = NULL;
+ struct interfaces_device_list *interfaces;
+ struct interfaces_address_list *addresses;
+ interfaces = malloc(sizeof(struct interfaces_device_list));
+ addresses = malloc(sizeof(struct interfaces_address_list));
+ if (interfaces == NULL || addresses == NULL) {
+ log_warnx("interfaces", "unable to allocate memory");
+ goto end;
+ }
+ TAILQ_INIT(interfaces);
+ TAILQ_INIT(addresses);
+
+ struct lifnum lifn = { .lifn_family = AF_UNSPEC, .lifn_flags = LIFC_ENABLED };
+ if (ioctl(cfg->g_sock, SIOCGLIFNUM, &lifn) < 0) {
+ log_warn("interfaces", "unable to get the number of interfaces");
+ goto end;
+ }
+
+ size_t bufsize = lifn.lifn_count * sizeof(struct lifreq);
+ if ((buffer = malloc(bufsize)) == NULL) {
+ log_warn("interfaces", "unable to allocate buffer to get interfaces");
+ goto end;
+ }
+
+ struct lifconf lifc = { .lifc_family = AF_UNSPEC,
+ .lifc_flags = LIFC_ENABLED,
+ .lifc_len = bufsize,
+ .lifc_buf = buffer };
+ if (ioctl(cfg->g_sock, SIOCGLIFCONF, (char *)&lifc) < 0) {
+ log_warn("interfaces", "unable to get the network interfaces");
+ goto end;
+ }
+
+ int num = lifc.lifc_len / sizeof(struct lifreq);
+ if (num > lifn.lifn_count) num = lifn.lifn_count;
+ log_debug("interfaces", "got %d interfaces", num);
+
+ struct lifreq *lifrp = (struct lifreq *)buffer;
+ for (int n = 0; n < num; n++, lifrp++)
+ ifsolaris_extract(cfg, interfaces, addresses, lifrp);
+
+ interfaces_helper_allowlist(cfg, interfaces);
+ interfaces_helper_physical(cfg, interfaces, &bpf_ops, ifbpf_phys_init);
+ interfaces_helper_mgmt(cfg, addresses, interfaces);
+ interfaces_helper_chassis(cfg, interfaces);
+
+ /* Mac/PHY */
+ TAILQ_FOREACH (hardware, &cfg->g_hardware, h_entries) {
+ if (!hardware->h_flags) continue;
+ /* TODO: mac/phy for Solaris */
+ interfaces_helper_promisc(cfg, hardware);
+ }
+
+end:
+ free(buffer);
+ interfaces_free_devices(interfaces);
+ interfaces_free_addresses(addresses);
+}
+
+void
+interfaces_cleanup(struct lldpd *cfg)
+{
+}
diff --git a/src/daemon/interfaces.c b/src/daemon/interfaces.c
new file mode 100644
index 0000000..c1179d9
--- /dev/null
+++ b/src/daemon/interfaces.c
@@ -0,0 +1,764 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2012 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "lldpd.h"
+#include "trace.h"
+
+#include <stddef.h>
+#include <unistd.h>
+#include <errno.h>
+#include <assert.h>
+#include <arpa/inet.h>
+
+static int
+lldpd_af(int af)
+{
+ switch (af) {
+ case LLDPD_AF_IPV4:
+ return AF_INET;
+ case LLDPD_AF_IPV6:
+ return AF_INET6;
+ case LLDPD_AF_LAST:
+ return AF_MAX;
+ default:
+ return AF_UNSPEC;
+ }
+}
+
+/* Generic ethernet interface initialization */
+/**
+ * Enable multicast on the given interface.
+ */
+void
+interfaces_setup_multicast(struct lldpd *cfg, const char *name, int remove)
+{
+ int rc;
+ size_t i, j;
+ const u_int8_t *mac;
+ const u_int8_t zero[ETHER_ADDR_LEN] = {};
+
+ for (i = 0; cfg->g_protocols[i].mode != 0; i++) {
+ if (!cfg->g_protocols[i].enabled) continue;
+ for (j = 0; j < sizeof(cfg->g_protocols[0].mac) /
+ sizeof(cfg->g_protocols[0].mac[0]);
+ j++) {
+ mac = cfg->g_protocols[i].mac[j];
+ if (memcmp(mac, zero, ETHER_ADDR_LEN) == 0) break;
+ if ((rc = priv_iface_multicast(name, mac, !remove)) != 0) {
+ errno = rc;
+ if (errno != ENOENT)
+ log_debug("interfaces",
+ "unable to %s %s address to multicast filter for %s (%s)",
+ (remove) ? "delete" : "add",
+ cfg->g_protocols[i].name, name,
+ strerror(rc));
+ }
+ }
+ }
+}
+
+/**
+ * Free an interface.
+ *
+ * @param iff interface to be freed
+ */
+void
+interfaces_free_device(struct interfaces_device *iff)
+{
+ if (!iff) return;
+ free(iff->name);
+ free(iff->alias);
+ free(iff->address);
+ free(iff->driver);
+ free(iff);
+}
+
+/**
+ * Free a list of interfaces.
+ *
+ * @param ifs list of interfaces to be freed
+ */
+void
+interfaces_free_devices(struct interfaces_device_list *ifs)
+{
+ struct interfaces_device *iff, *iff_next;
+ if (!ifs) return;
+ for (iff = TAILQ_FIRST(ifs); iff != NULL; iff = iff_next) {
+ iff_next = TAILQ_NEXT(iff, next);
+ interfaces_free_device(iff);
+ }
+ free(ifs);
+}
+
+/**
+ * Free one address
+ *
+ * @param ifaddr Address to be freed
+ */
+void
+interfaces_free_address(struct interfaces_address *ifaddr)
+{
+ free(ifaddr);
+}
+
+/**
+ * Free a list of addresses.
+ *
+ * @param ifaddrs list of addresses
+ */
+void
+interfaces_free_addresses(struct interfaces_address_list *ifaddrs)
+{
+ struct interfaces_address *ifa, *ifa_next;
+ if (!ifaddrs) return;
+ for (ifa = TAILQ_FIRST(ifaddrs); ifa != NULL; ifa = ifa_next) {
+ ifa_next = TAILQ_NEXT(ifa, next);
+ interfaces_free_address(ifa);
+ }
+ free(ifaddrs);
+}
+
+/**
+ * Find the appropriate interface from the name.
+ *
+ * @param interfaces List of available interfaces
+ * @param device Name of the device we search for
+ * @return The interface or NULL if not found
+ */
+struct interfaces_device *
+interfaces_nametointerface(struct interfaces_device_list *interfaces,
+ const char *device)
+{
+ struct interfaces_device *iface;
+ TAILQ_FOREACH (iface, interfaces, next) {
+ if (!strncmp(iface->name, device, IFNAMSIZ)) return iface;
+ }
+ log_debug("interfaces", "cannot get interface for index %s", device);
+ return NULL;
+}
+
+/**
+ * Find the appropriate interface from the index.
+ *
+ * @param interfaces List of available interfaces
+ * @param index Index of the device we search for
+ * @return The interface or NULL if not found
+ */
+struct interfaces_device *
+interfaces_indextointerface(struct interfaces_device_list *interfaces, int index)
+{
+ struct interfaces_device *iface;
+ TAILQ_FOREACH (iface, interfaces, next) {
+ if (iface->index == index) return iface;
+ }
+ log_debug("interfaces", "cannot get interface for index %d", index);
+ return NULL;
+}
+
+void
+interfaces_helper_allowlist(struct lldpd *cfg,
+ struct interfaces_device_list *interfaces)
+{
+ struct interfaces_device *iface;
+
+ if (!cfg->g_config.c_iface_pattern) return;
+
+ TAILQ_FOREACH (iface, interfaces, next) {
+ int m = pattern_match(iface->name, cfg->g_config.c_iface_pattern, 0);
+ switch (m) {
+ case PATTERN_MATCH_DENIED:
+ log_debug("interfaces", "deny %s", iface->name);
+ iface->ignore = 1;
+ continue;
+ case PATTERN_MATCH_ALLOWED_EXACT:
+ log_debug("interfaces",
+ "allow %s (consider it as a physical interface)",
+ iface->name);
+ iface->type |= IFACE_PHYSICAL_T;
+ continue;
+ }
+ }
+}
+
+#ifdef ENABLE_DOT1
+static void
+iface_append_vlan(struct lldpd *cfg, struct interfaces_device *vlan,
+ struct interfaces_device *lower)
+{
+ struct lldpd_hardware *hardware =
+ lldpd_get_hardware(cfg, lower->name, lower->index);
+ struct lldpd_port *port;
+ struct lldpd_vlan *v;
+ char *name = NULL;
+ uint16_t vlan_id;
+
+ if (hardware == NULL) {
+ log_debug("interfaces", "cannot find real interface %s for VLAN %s",
+ lower->name, vlan->name);
+ return;
+ }
+ port = &hardware->h_lport;
+
+ for (int i = 0; (i < VLAN_BITMAP_LEN); i++) {
+ if (vlan->vlan_bmap[i] == 0) continue;
+ for (unsigned bit = 0; bit < 32; bit++) {
+ uint32_t mask = 1L << bit;
+ if (!(vlan->vlan_bmap[i] & mask)) continue;
+ vlan_id = (i * 32) + bit;
+ if (asprintf(&name, "vlan%d", vlan_id) == -1) return;
+
+ /* Check if the VLAN is already here. */
+ TAILQ_FOREACH (v, &port->p_vlans, v_entries)
+ if (strncmp(name, v->v_name, IFNAMSIZ) == 0) {
+ free(name);
+ return;
+ }
+
+ if ((v = (struct lldpd_vlan *)calloc(1,
+ sizeof(struct lldpd_vlan))) == NULL) {
+ free(name);
+ return;
+ }
+ v->v_name = name;
+ v->v_vid = vlan_id;
+ if (vlan->pvid) port->p_pvid = vlan->pvid;
+ log_debug("interfaces", "append VLAN %s for %s", v->v_name,
+ hardware->h_ifname);
+ TAILQ_INSERT_TAIL(&port->p_vlans, v, v_entries);
+ }
+ }
+}
+
+/**
+ * Append VLAN to the lowest possible interface.
+ *
+ * @param vlan The VLAN interface (used to get VLAN ID).
+ * @param upper The upper interface we are currently examining.
+ * @param depth Depth of the stack (avoid infinite recursion)
+ *
+ * Initially, upper == vlan. This function will be called recursively.
+ */
+static void
+iface_append_vlan_to_lower(struct lldpd *cfg, struct interfaces_device_list *interfaces,
+ struct interfaces_device *vlan, struct interfaces_device *upper, int depth)
+{
+ if (depth > 5) {
+ log_warnx("interfaces",
+ "BUG: maximum depth reached when applying VLAN %s (loop?)",
+ vlan->name);
+ return;
+ }
+ depth++;
+ struct interfaces_device *lower;
+ log_debug("interfaces",
+ "looking to apply VLAN %s to physical interface behind %s", vlan->name,
+ upper->name);
+
+ /* Some bridges managed VLAN internally, skip them. */
+ if (upper->type & IFACE_BRIDGE_VLAN_T) {
+ log_debug("interfaces",
+ "VLAN %s ignored for VLAN-aware bridge interface %s", vlan->name,
+ upper->name);
+ return;
+ }
+
+ /* Easy: check if we have a lower interface. */
+ if (upper->lower) {
+ log_debug("interfaces", "VLAN %s on lower interface %s", vlan->name,
+ upper->name);
+ iface_append_vlan_to_lower(cfg, interfaces, vlan, upper->lower, depth);
+ return;
+ }
+
+ /* Other easy case, we have a physical interface. */
+ if (upper->type & IFACE_PHYSICAL_T) {
+ log_debug("interfaces", "VLAN %s on physical interface %s", vlan->name,
+ upper->name);
+ iface_append_vlan(cfg, vlan, upper);
+ return;
+ }
+
+ /* We can now search for interfaces that have our interface as an upper
+ * interface. */
+ TAILQ_FOREACH (lower, interfaces, next) {
+ if (lower->upper != upper) continue;
+ log_debug("interfaces", "VLAN %s on lower interface %s", vlan->name,
+ upper->name);
+ iface_append_vlan_to_lower(cfg, interfaces, vlan, lower, depth);
+ }
+}
+
+void
+interfaces_helper_vlan(struct lldpd *cfg, struct interfaces_device_list *interfaces)
+{
+ struct interfaces_device *iface;
+
+ TAILQ_FOREACH (iface, interfaces, next) {
+ if (!(iface->type & IFACE_VLAN_T) && bitmap_isempty(iface->vlan_bmap))
+ continue;
+
+ /* We need to find the physical interfaces of this
+ vlan, through bonds and bridges. */
+ log_debug("interfaces",
+ "search physical interface for VLAN interface %s", iface->name);
+ iface_append_vlan_to_lower(cfg, interfaces, iface, iface, 0);
+ }
+}
+#endif
+
+/* Fill out chassis ID if not already done. Only physical interfaces are
+ * considered. */
+void
+interfaces_helper_chassis(struct lldpd *cfg, struct interfaces_device_list *interfaces)
+{
+ struct interfaces_device *iface;
+ struct lldpd_hardware *hardware;
+ char *name = NULL;
+ static u_int8_t zero_mac[] = { 0, 0, 0, 0, 0, 0 };
+
+ if (!cfg->g_config.c_cap_override) {
+ LOCAL_CHASSIS(cfg)->c_cap_enabled &=
+ ~(LLDP_CAP_BRIDGE | LLDP_CAP_WLAN | LLDP_CAP_STATION);
+ TAILQ_FOREACH (iface, interfaces, next) {
+ if (iface->type & IFACE_BRIDGE_T)
+ LOCAL_CHASSIS(cfg)->c_cap_enabled |= LLDP_CAP_BRIDGE;
+ if (iface->type & IFACE_WIRELESS_T)
+ LOCAL_CHASSIS(cfg)->c_cap_enabled |= LLDP_CAP_WLAN;
+ }
+ if ((LOCAL_CHASSIS(cfg)->c_cap_available & LLDP_CAP_STATION) &&
+ (LOCAL_CHASSIS(cfg)->c_cap_enabled == 0))
+ LOCAL_CHASSIS(cfg)->c_cap_enabled = LLDP_CAP_STATION;
+ }
+
+ /* Do not modify the chassis if it's already set to a MAC address or if
+ * it's set to a local address equal to the user-provided
+ * configuration. */
+ if ((LOCAL_CHASSIS(cfg)->c_id != NULL &&
+ LOCAL_CHASSIS(cfg)->c_id_subtype == LLDP_CHASSISID_SUBTYPE_LLADDR) ||
+ cfg->g_config.c_cid_string != NULL)
+ return; /* We already have one */
+
+ TAILQ_FOREACH (iface, interfaces, next) {
+ if (!(iface->type & IFACE_PHYSICAL_T)) continue;
+ if (cfg->g_config.c_cid_pattern &&
+ !pattern_match(iface->name, cfg->g_config.c_cid_pattern, 0))
+ continue;
+
+ if ((hardware = lldpd_get_hardware(cfg, iface->name, iface->index)) ==
+ NULL)
+ /* That's odd. Let's skip. */
+ continue;
+ if (memcmp(hardware->h_lladdr, zero_mac, ETHER_ADDR_LEN) == 0)
+ /* All-zero MAC address */
+ continue;
+
+ name = malloc(ETHER_ADDR_LEN);
+ if (!name) {
+ log_warn("interfaces", "not enough memory for chassis ID");
+ return;
+ }
+ free(LOCAL_CHASSIS(cfg)->c_id);
+ memcpy(name, hardware->h_lladdr, ETHER_ADDR_LEN);
+ LOCAL_CHASSIS(cfg)->c_id = name;
+ LOCAL_CHASSIS(cfg)->c_id_len = ETHER_ADDR_LEN;
+ LOCAL_CHASSIS(cfg)->c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR;
+ return;
+ }
+}
+
+#undef IN_IS_ADDR_LOOPBACK
+#define IN_IS_ADDR_LOOPBACK(a) ((a)->s_addr == htonl(INADDR_LOOPBACK))
+#undef IN_IS_ADDR_ANY
+#define IN_IS_ADDR_ANY(a) ((a)->s_addr == htonl(INADDR_ANY))
+#undef IN_IS_ADDR_LINKLOCAL
+#define IN_IS_ADDR_LINKLOCAL(a) (((a)->s_addr & htonl(0xffff0000)) == htonl(0xa9fe0000))
+#undef IN_IS_ADDR_GLOBAL
+#define IN_IS_ADDR_GLOBAL(a) \
+ (!IN_IS_ADDR_LOOPBACK(a) && !IN_IS_ADDR_ANY(a) && !IN_IS_ADDR_LINKLOCAL(a))
+#undef IN6_IS_ADDR_GLOBAL
+#define IN6_IS_ADDR_GLOBAL(a) (!IN6_IS_ADDR_LOOPBACK(a) && !IN6_IS_ADDR_LINKLOCAL(a))
+
+/* Add management addresses for the given family. We only take one of each
+ address family, unless a pattern is provided and is not all negative. For
+ example !*:*,!10.* will only deny addresses. We will pick the first IPv4
+ address not matching 10.*.
+*/
+static int
+interfaces_helper_mgmt_for_af(struct lldpd *cfg, int af,
+ struct interfaces_address_list *addrs, struct interfaces_device_list *interfaces,
+ int global, int allnegative)
+{
+ struct interfaces_address *addr;
+ struct interfaces_device *device;
+ struct lldpd_mgmt *mgmt;
+ char addrstrbuf[INET6_ADDRSTRLEN];
+ int found = 0;
+ union lldpd_address in_addr;
+ size_t in_addr_size;
+
+ TAILQ_FOREACH (addr, addrs, next) {
+ if (addr->address.ss_family != lldpd_af(af)) continue;
+
+ switch (af) {
+ case LLDPD_AF_IPV4:
+ in_addr_size = sizeof(struct in_addr);
+ memcpy(&in_addr,
+ &((struct sockaddr_in *)&addr->address)->sin_addr,
+ in_addr_size);
+ if (global) {
+ if (!IN_IS_ADDR_GLOBAL(&in_addr.inet)) continue;
+ } else {
+ if (!IN_IS_ADDR_LINKLOCAL(&in_addr.inet)) continue;
+ }
+ break;
+ case LLDPD_AF_IPV6:
+ in_addr_size = sizeof(struct in6_addr);
+ memcpy(&in_addr,
+ &((struct sockaddr_in6 *)&addr->address)->sin6_addr,
+ in_addr_size);
+ if (global) {
+ if (!IN6_IS_ADDR_GLOBAL(&in_addr.inet6)) continue;
+ } else {
+ if (!IN6_IS_ADDR_LINKLOCAL(&in_addr.inet6)) continue;
+ }
+ break;
+ default:
+ assert(0);
+ continue;
+ }
+ if (inet_ntop(lldpd_af(af), &in_addr, addrstrbuf, sizeof(addrstrbuf)) ==
+ NULL) {
+ log_warn("interfaces",
+ "unable to convert IP address to a string");
+ continue;
+ }
+ if (cfg->g_config.c_mgmt_pattern == NULL ||
+ /* Match on IP address */
+ pattern_match(addrstrbuf, cfg->g_config.c_mgmt_pattern,
+ allnegative) ||
+ /* Match on interface name */
+ ((device = interfaces_indextointerface(interfaces, addr->index)) &&
+ pattern_match(device->name, cfg->g_config.c_mgmt_pattern,
+ allnegative))) {
+ mgmt =
+ lldpd_alloc_mgmt(af, &in_addr, in_addr_size, addr->index);
+ if (mgmt == NULL) {
+ assert(errno == ENOMEM); /* anything else is a bug */
+ log_warn("interfaces", "out of memory error");
+ return found;
+ }
+ log_debug("interfaces", "add management address %s",
+ addrstrbuf);
+ TAILQ_INSERT_TAIL(&LOCAL_CHASSIS(cfg)->c_mgmt, mgmt, m_entries);
+ found = 1;
+
+ /* Don't take additional address if the pattern is all negative.
+ */
+ if (allnegative) break;
+ }
+ }
+ return found;
+}
+
+/* Find a management address in all available interfaces, even those that were
+ already handled. This is a special interface handler because it does not
+ really handle interface related information (management address is attached
+ to the local chassis). */
+void
+interfaces_helper_mgmt(struct lldpd *cfg, struct interfaces_address_list *addrs,
+ struct interfaces_device_list *interfaces)
+{
+ int allnegative = 0;
+ int af;
+ const char *pattern = cfg->g_config.c_mgmt_pattern;
+
+ lldpd_chassis_mgmt_cleanup(LOCAL_CHASSIS(cfg));
+ if (!cfg->g_config.c_mgmt_advertise) return;
+
+ /* Is the pattern provided an actual IP address? */
+ if (pattern && strpbrk(pattern, "!,*?") == NULL) {
+ unsigned char addr[sizeof(struct in6_addr)];
+ size_t addr_size;
+ struct lldpd_mgmt *mgmt;
+ struct interfaces_address *ifaddr;
+
+ for (af = LLDPD_AF_UNSPEC + 1; af != LLDPD_AF_LAST; af++) {
+ switch (af) {
+ case LLDPD_AF_IPV4:
+ addr_size = sizeof(struct in_addr);
+ break;
+ case LLDPD_AF_IPV6:
+ addr_size = sizeof(struct in6_addr);
+ break;
+ default:
+ assert(0);
+ }
+ if (inet_pton(lldpd_af(af), pattern, addr) == 1) break;
+ }
+ if (af != LLDPD_AF_LAST) {
+ /* Try to get the index if possible. */
+ TAILQ_FOREACH (ifaddr, addrs, next) {
+ if (ifaddr->address.ss_family != lldpd_af(af)) continue;
+ if (LLDPD_AF_IPV4 == af) {
+ struct sockaddr_in *sa_sin;
+ sa_sin = (struct sockaddr_in *)&ifaddr->address;
+ if (0 ==
+ memcmp(addr, &(sa_sin->sin_addr),
+ addr_size))
+ break;
+ } else if (LLDPD_AF_IPV6 == af) {
+ if (0 ==
+ memcmp(addr,
+ &((struct sockaddr_in6 *)&ifaddr
+ ->address)
+ ->sin6_addr,
+ addr_size))
+ break;
+ }
+ }
+
+ mgmt = lldpd_alloc_mgmt(af, addr, addr_size,
+ ifaddr ? ifaddr->index : 0);
+ if (mgmt == NULL) {
+ log_warn("interfaces", "out of memory error");
+ return;
+ }
+ log_debug("interfaces", "add exact management address %s",
+ pattern);
+ TAILQ_INSERT_TAIL(&LOCAL_CHASSIS(cfg)->c_mgmt, mgmt, m_entries);
+ return;
+ }
+ /* else: could be an interface name */
+ }
+
+ /* Is the pattern provided all negative? */
+ if (pattern == NULL)
+ allnegative = 1;
+ else if (pattern[0] == '!') {
+ /* If each comma is followed by '!', its an all
+ negative pattern */
+ const char *sep = pattern;
+ while ((sep = strchr(sep, ',')) && (*(++sep) == '!'))
+ ;
+ if (sep == NULL) allnegative = 1;
+ }
+
+ /* Find management addresses */
+ for (af = LLDPD_AF_UNSPEC + 1; af != LLDPD_AF_LAST; af++) {
+ (void)(interfaces_helper_mgmt_for_af(cfg, af, addrs, interfaces, 1,
+ allnegative) ||
+ interfaces_helper_mgmt_for_af(cfg, af, addrs, interfaces, 0,
+ allnegative));
+ }
+}
+
+/* Fill up port name and description */
+void
+interfaces_helper_port_name_desc(struct lldpd *cfg, struct lldpd_hardware *hardware,
+ struct interfaces_device *iface)
+{
+ struct lldpd_port *port = &hardware->h_lport;
+
+ /* We need to set the portid to what the client configured.
+ This can be done from the CLI.
+ */
+ int has_alias = (iface->alias != NULL && strlen(iface->alias) != 0 &&
+ strncmp("lldpd: ", iface->alias, 7));
+ int portid_type = cfg->g_config.c_lldp_portid_type;
+ if (portid_type == LLDP_PORTID_SUBTYPE_IFNAME ||
+ (portid_type == LLDP_PORTID_SUBTYPE_UNKNOWN && has_alias) ||
+ (port->p_id_subtype == LLDP_PORTID_SUBTYPE_LOCAL && has_alias)) {
+ if (port->p_id_subtype != LLDP_PORTID_SUBTYPE_LOCAL) {
+ log_debug("interfaces", "use ifname for %s",
+ hardware->h_ifname);
+ port->p_id_subtype = LLDP_PORTID_SUBTYPE_IFNAME;
+ port->p_id_len = strlen(hardware->h_ifname);
+ free(port->p_id);
+ if ((port->p_id = calloc(1, port->p_id_len)) == NULL)
+ fatal("interfaces", NULL);
+ memcpy(port->p_id, hardware->h_ifname, port->p_id_len);
+ }
+
+ if (port->p_descr_force == 0) {
+ /* use the actual alias in the port description */
+ log_debug("interfaces", "using alias in description for %s",
+ hardware->h_ifname);
+ free(port->p_descr);
+ if (has_alias) {
+ port->p_descr = strdup(iface->alias);
+ } else {
+ /* We don't have anything else to put here and for CDP
+ * with need something non-NULL */
+ port->p_descr = strdup(hardware->h_ifname);
+ }
+ }
+ } else {
+ if (port->p_id_subtype != LLDP_PORTID_SUBTYPE_LOCAL) {
+ log_debug("interfaces", "use MAC address for %s",
+ hardware->h_ifname);
+ port->p_id_subtype = LLDP_PORTID_SUBTYPE_LLADDR;
+ free(port->p_id);
+ if ((port->p_id = calloc(1, ETHER_ADDR_LEN)) == NULL)
+ fatal("interfaces", NULL);
+ memcpy(port->p_id, hardware->h_lladdr, ETHER_ADDR_LEN);
+ port->p_id_len = ETHER_ADDR_LEN;
+ }
+
+ if (port->p_descr_force == 0) {
+ /* use the ifname in the port description until alias is set */
+ log_debug("interfaces", "using ifname in description for %s",
+ hardware->h_ifname);
+ free(port->p_descr);
+ port->p_descr = strdup(hardware->h_ifname);
+ }
+ }
+}
+
+void
+interfaces_helper_add_hardware(struct lldpd *cfg, struct lldpd_hardware *hardware)
+{
+ TRACE(LLDPD_INTERFACES_NEW(hardware->h_ifname));
+ TAILQ_INSERT_TAIL(&cfg->g_hardware, hardware, h_entries);
+}
+
+void
+interfaces_helper_physical(struct lldpd *cfg, struct interfaces_device_list *interfaces,
+ struct lldpd_ops *ops, int (*init)(struct lldpd *, struct lldpd_hardware *))
+{
+ struct interfaces_device *iface;
+ struct lldpd_hardware *hardware;
+ int created;
+
+ TAILQ_FOREACH (iface, interfaces, next) {
+ if (!(iface->type & IFACE_PHYSICAL_T)) continue;
+ if (iface->ignore) continue;
+
+ log_debug("interfaces", "%s is an acceptable ethernet device",
+ iface->name);
+ created = 0;
+ if ((hardware = lldpd_get_hardware(cfg, iface->name, iface->index)) ==
+ NULL) {
+ if ((hardware = lldpd_alloc_hardware(cfg, iface->name,
+ iface->index)) == NULL) {
+ log_warnx("interfaces",
+ "Unable to allocate space for %s", iface->name);
+ continue;
+ }
+ created = 1;
+ }
+ if (hardware->h_flags) continue;
+ if (hardware->h_ops != ops || hardware->h_ifindex_changed) {
+ if (!created) {
+ log_debug("interfaces",
+ "interface %s is converted from another type of interface",
+ hardware->h_ifname);
+ if (hardware->h_ops && hardware->h_ops->cleanup) {
+ hardware->h_ops->cleanup(cfg, hardware);
+ levent_hardware_release(hardware);
+ levent_hardware_init(hardware);
+ }
+ }
+ if (init(cfg, hardware) != 0) {
+ log_warnx("interfaces", "unable to initialize %s",
+ hardware->h_ifname);
+ lldpd_hardware_cleanup(cfg, hardware);
+ continue;
+ }
+ hardware->h_ops = ops;
+ hardware->h_mangle =
+ (iface->upper && iface->upper->type & IFACE_BOND_T);
+ }
+ if (created)
+ interfaces_helper_add_hardware(cfg, hardware);
+ else
+ lldpd_port_cleanup(&hardware->h_lport, 0);
+
+ hardware->h_flags = iface->flags; /* Should be non-zero */
+ iface->ignore = 1; /* Future handlers
+ don't have to
+ care about this
+ interface. */
+
+ /* Get local address */
+ memcpy(&hardware->h_lladdr, iface->address, ETHER_ADDR_LEN);
+
+ /* Fill information about port */
+ interfaces_helper_port_name_desc(cfg, hardware, iface);
+
+ /* Fill additional info */
+ hardware->h_mtu = iface->mtu ? iface->mtu : 1500;
+
+#ifdef ENABLE_DOT3
+ if (iface->upper && iface->upper->type & IFACE_BOND_T)
+ hardware->h_lport.p_aggregid = iface->upper->index;
+ else
+ hardware->h_lport.p_aggregid = 0;
+#endif
+ }
+}
+
+void
+interfaces_helper_promisc(struct lldpd *cfg, struct lldpd_hardware *hardware)
+{
+ if (!cfg->g_config.c_promisc) return;
+ if (priv_iface_promisc(hardware->h_ifname) != 0) {
+ log_warnx("interfaces", "unable to enable promiscuous mode for %s",
+ hardware->h_ifname);
+ }
+}
+
+/**
+ * Send the packet using the hardware function. Optionnaly mangle the MAC address.
+ *
+ * With bonds, we have duplicate MAC address on different physical
+ * interfaces. We need to alter the source MAC address when we send on an
+ * inactive slave. The `h_mangle` flah is used to know if we need to do
+ * something like that.
+ */
+int
+interfaces_send_helper(struct lldpd *cfg, struct lldpd_hardware *hardware, char *buffer,
+ size_t size)
+{
+ if (size < 2 * ETHER_ADDR_LEN) {
+ log_warnx("interfaces", "packet to send on %s is too small!",
+ hardware->h_ifname);
+ return 0;
+ }
+ if (hardware->h_mangle) {
+#define MAC_UL_ADMINISTERED_BIT_MASK 0x02
+ char *src_mac = buffer + ETHER_ADDR_LEN;
+ char arbitrary[] = { 0x00, 0x60, 0x08, 0x69, 0x97, 0xef };
+
+ switch (cfg->g_config.c_bond_slave_src_mac_type) {
+ case LLDP_BOND_SLAVE_SRC_MAC_TYPE_LOCALLY_ADMINISTERED:
+ if (!(*src_mac & MAC_UL_ADMINISTERED_BIT_MASK)) {
+ *src_mac |= MAC_UL_ADMINISTERED_BIT_MASK;
+ break;
+ }
+ /* Fallback to fixed value */
+ memcpy(src_mac, arbitrary, ETHER_ADDR_LEN);
+ break;
+ case LLDP_BOND_SLAVE_SRC_MAC_TYPE_FIXED:
+ memcpy(src_mac, arbitrary, ETHER_ADDR_LEN);
+ break;
+ case LLDP_BOND_SLAVE_SRC_MAC_TYPE_ZERO:
+ memset(src_mac, 0, ETHER_ADDR_LEN);
+ break;
+ }
+ }
+ return hardware->h_ops->send(cfg, hardware, buffer, size);
+}
diff --git a/src/daemon/lldp-tlv.h b/src/daemon/lldp-tlv.h
new file mode 100644
index 0000000..a9bf7cf
--- /dev/null
+++ b/src/daemon/lldp-tlv.h
@@ -0,0 +1,83 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2012 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _LLDP_TLV_H
+#define _LLDP_TLV_H
+
+#define LLDP_ADDR_NEAREST_BRIDGE \
+ { \
+ 0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e \
+ }
+#define LLDP_ADDR_NEAREST_NONTPMR_BRIDGE \
+ { \
+ 0x01, 0x80, 0xc2, 0x00, 0x00, 0x03 \
+ }
+#define LLDP_ADDR_NEAREST_CUSTOMER_BRIDGE \
+ { \
+ 0x01, 0x80, 0xc2, 0x00, 0x00, 0x00 \
+ }
+
+#define LLDP_TLV_END 0
+#define LLDP_TLV_CHASSIS_ID 1
+#define LLDP_TLV_PORT_ID 2
+#define LLDP_TLV_TTL 3
+#define LLDP_TLV_PORT_DESCR 4
+#define LLDP_TLV_SYSTEM_NAME 5
+#define LLDP_TLV_SYSTEM_DESCR 6
+#define LLDP_TLV_SYSTEM_CAP 7
+#define LLDP_TLV_MGMT_ADDR 8
+
+#define LLDP_TLV_ORG_DOT1 \
+ { \
+ 0x00, 0x80, 0xc2 \
+ }
+#define LLDP_TLV_ORG_DOT3 \
+ { \
+ 0x00, 0x12, 0x0f \
+ }
+#define LLDP_TLV_ORG_MED \
+ { \
+ 0x00, 0x12, 0xbb \
+ }
+#define LLDP_TLV_ORG_DCBX \
+ { \
+ 0x00, 0x1b, 0x21 \
+ }
+
+#define LLDP_TLV_DOT1_PVID 1
+#define LLDP_TLV_DOT1_PPVID 2
+#define LLDP_TLV_DOT1_VLANNAME 3
+#define LLDP_TLV_DOT1_PI 4
+
+#define LLDP_TLV_DOT3_MAC 1
+#define LLDP_TLV_DOT3_POWER 2
+#define LLDP_TLV_DOT3_LA 3
+#define LLDP_TLV_DOT3_MFS 4
+
+#define LLDP_TLV_MED_CAP 1
+#define LLDP_TLV_MED_POLICY 2
+#define LLDP_TLV_MED_LOCATION 3
+#define LLDP_TLV_MED_MDI 4
+#define LLDP_TLV_MED_IV_HW 5
+#define LLDP_TLV_MED_IV_FW 6
+#define LLDP_TLV_MED_IV_SW 7
+#define LLDP_TLV_MED_IV_SN 8
+#define LLDP_TLV_MED_IV_MANUF 9
+#define LLDP_TLV_MED_IV_MODEL 10
+#define LLDP_TLV_MED_IV_ASSET 11
+
+#endif
diff --git a/src/daemon/lldpd.8.in b/src/daemon/lldpd.8.in
new file mode 100644
index 0000000..32d57a6
--- /dev/null
+++ b/src/daemon/lldpd.8.in
@@ -0,0 +1,424 @@
+.\" Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org>
+.\" Copyright (c) 2008 Vincent Bernat <bernat@luffy.cx>
+.\"
+.\" Permission to use, copy, modify, and/or distribute this software for any
+.\" purpose with or without fee is hereby granted, provided that the above
+.\" copyright notice and this permission notice appear in all copies.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+.\"
+.Dd $Mdocdate: August 21 2008 $
+.Dt LLDPD 8
+.Os
+.Sh NAME
+.Nm lldpd
+.Nd LLDP daemon
+.Sh SYNOPSIS
+.Nm
+.Op Fl dxcseiklrv
+.Op Fl D Ar debug
+.Op Fl p Ar pidfile
+.Op Fl S Ar description
+.Op Fl P Ar platform
+.Op Fl X Ar socket
+.Op Fl m Ar management
+.Op Fl u Ar file
+.Op Fl I Ar interfaces
+.Op Fl C Ar interfaces
+.Op Fl M Ar class
+.Op Fl H Ar hide
+.Op Fl L Ar lldpcli
+.Op Fl O Ar configfile
+.Sh DESCRIPTION
+.Nm
+is a daemon able to receive and send
+.Em LLDP
+frames. The Link Layer Discovery Protocol is a vendor-neutral Layer 2
+protocol that allows a network device to advertise its identity and
+capabilities on the local network.
+.Pp
+.Nm
+also implements an SNMP subagent using AgentX protocol to interface to
+a regular SNMP agent like Net-SNMP. To enable this subagent, you need
+something like that in your
+.Xr snmpd.conf 5 :
+.Bd -literal -offset indent
+master agentx
+.Ed
+.Pp
+This daemon implements both reception and sending. It will collect
+various information to send LLDP frames to all Ethernet interfaces,
+including management address, speed and VLAN names.
+.Pp
+The options are as follows:
+.Bl -tag -width Ds
+.It Fl d
+Do not daemonize.
+If this option is specified,
+.Nm
+will run in the foreground. When specified one more time,
+.Nm
+will not log to syslog but only to stderr. Then, this option can be
+specified many times to increase verbosity. When specified four times,
+debug logs will be enabled. They can be filtered with
+.Fl D
+flag.
+.It Fl D Ar debug
+This option allows the user to filter out debugging information by
+specifying allowed tokens. This option can be repeated several times
+to allow several tokens. This option must be combined with the
+.Fl d
+flag to have some effect. Only debugging logs can be filtered. Here is
+a list of allowed tokens with their description:
+.Bl -tag -width "XXXXXXXXXX" -offset "XXXX" -compact
+.It Sy main
+Main daemon.
+.It Sy interfaces
+Discovery of local interfaces.
+.It Sy lldp
+LLDP PDU encoding/decoding.
+.It Sy edp
+EDP PDU encoding/decoding.
+.It Sy cdp
+CDP/FDP PDU encoding/decoding.
+.It Sy sonmp
+SONMP PDU encoding/decoding.
+.It Sy event
+Events management.
+.It Sy libevent
+Events management but for logs generated by libevent.
+.It Sy privsep
+Privilege separation.
+.It Sy localchassis
+Retrieval of information related to the local chassis.
+.It Sy rpc
+Client communication.
+.It Sy control
+Management of the Unix control socket.
+.It Sy snmp
+SNMP subagent.
+.It Sy libsnmp
+SNMP subagent but for logs generated by NetSNMP.
+.It Sy decode
+Generic PDU decoding.
+.It Sy marshal
+Low-level serialization mechanisms.
+.It Sy alloc
+Low-level allocation mechanisms.
+.It Sy send
+Sending PDU to some interface.
+.It Sy receive
+Receiving PDU from some interface.
+.It Sy loop
+Main loop.
+.It Sy smartfilter
+Smart filtering of different protocols on the same port.
+.It Sy netlink
+Netlink subsystem.
+.El
+.It Fl p Ar pidfile
+Use the provided PID file to record
+.Nm
+PID instead of @LLDPD_PID_FILE@.
+.It Fl k
+Disable advertising of kernel release, version and machine. Kernel name
+(ie: Linux) will still be shared, and Inventory software version will be set
+to 'Unknown'.
+.It Fl S Ar description
+Override system description with the provided description. The default
+description is the kernel name, the node name, the kernel version, the
+build date and the architecture (except if you use the
+.Fl k
+flag described above).
+.It Fl P Ar platform
+Override the CDP platform name with the provided value. The default
+description is the kernel name (Linux).
+.It Fl x
+Enable SNMP subagent.
+With this option,
+.Nm
+will enable an SNMP subagent using AgentX protocol. This allows you to
+get information about local system and remote systems through SNMP.
+.It Fl X Ar socket
+Enable SNMP subagent using the specified socket.
+.Nm
+will enable an SNMP subagent using AgentX protocol for the given
+socket. This option implies the previous one. The default socket is
+usually
+.Em /var/agentx/master .
+You can specify a socket like
+.Em tcp:127.0.0.1:705
+for example. Since the process that will open this socket is enclosed
+in a chroot, you need to specify an IP address (not a hostname) when
+using a TCP or UDP socket.
+.It Fl c
+Enable the support of CDP protocol to deal with Cisco routers that do
+not speak LLDP. If repeated, CDPv1 packets will be sent even when
+there is no CDP peer detected. If repeated once again, CDPv2 packets
+will be sent even when there is no CDP peer detected. If repeated once
+again (i.e.
+.Fl cccc ) ,
+CDPv1 will be disabled and CDPv2 will be enabled. If repeated once
+again (i.e.
+.Fl ccccc ) ,
+CDPv1 will be disabled and CDPv2 will be forced.
+.It Fl f
+Enable the support of FDP protocol to deal with Foundry routers that do
+not speak LLDP. If repeated, FDP packets will be sent even when there
+is no FDP peer detected.
+.It Fl s
+Enable the support of SONMP protocol to deal with Nortel routers and
+switches that do not speak LLDP. If repeated, SONMP packets will be
+sent even when there is no SONMP peer detected.
+.It Fl e
+Enable the support of EDP protocol to deal with Extreme routers and
+switches that do not speak LLDP. If repeated, EDP packets will be sent
+even when there is no EDP peer detected.
+.It Fl l
+Force to send LLDP packets even when there is no LLDP peer detected
+but there is a peer speaking another protocol detected. By default,
+LLDP packets are sent when there is a peer speaking LLDP detected or
+when there is no peer at all. If repeated, LLDP is disabled.
+.It Fl r
+Receive-only mode. With this switch,
+.Nm
+will not send any frame. It will only listen to neighbors.
+.It Fl m Ar management
+Specify the management addresses of this system. As for interfaces
+(described below), this option can use wildcards and inversions.
+Without this option, the first IPv4 and the first IPv6 are used. If an
+exact IP address is provided, it is used as a management address
+without any check. If only negative patterns are provided, only one
+IPv4 and one IPv6 addresses are chosen. Otherwise, many of them can be
+selected. If you want to remove IPv6 addresses, you can use
+.Em !*:* .
+If an interface name is matched, the first IPv4 address and the first
+IPv6 address associated to this interface will be chosen.
+.It Fl u Ar file
+Specify the Unix-domain socket used for communication with
+.Xr lldpctl 8 .
+.It Fl I Ar interfaces
+Specify which interface to listen and send LLDPDU to. Without this
+option,
+.Nm
+will use all available physical interfaces. This option can use
+wildcards. Several interfaces can be specified separated by commas.
+It is also possible to remove an interface by prefixing it with an
+exclamation mark. It is possible to allow an interface by
+prefixing it with two exclamation marks. An allowed interface beats
+a forbidden interface which beats a simple matched interface. For
+example, with
+.Em eth*,!eth1,!eth2
+.Nm
+will only use interfaces starting by
+.Em eth
+with the exception of
+.Em eth1
+and
+.Em eth2 .
+While with
+.Em *,!eth*,!!eth1
+.Nm
+will use all interfaces, except interfaces starting by
+.Em eth
+with the exception of
+.Em eth1 .
+When an exact match is found, it will circumvent some tests. For example, if
+.Em eth0.12
+is specified, it will be accepted even if this is a VLAN interface.
+.It Fl C Ar interfaces
+Specify which interfaces to use for computing chassis ID. Without this
+option, all interfaces are considered.
+.Nm
+will take the first MAC address from all the considered interfaces
+to compute the chassis ID. The logic of this option is the same as for
+.Fl I
+flag: you can exclude interfaces with an exclamation mark and use
+globbing to specify several interfaces. If all interfaces are
+removed (with
+.Em !* ) ,
+the system name is used as a chassis ID instead.
+.It Fl M Ar class
+Enable emission of LLDP-MED frame. Depending on the selected class,
+the standard defines which set of TLV should be transmitted. See
+section 10.2.1. Some devices may be strict about this aspect. The
+class should be one of the following value:
+.Bl -tag -width "0:XX" -compact
+.It Sy 1
+Generic Endpoint (Class I)
+.It Sy 2
+Media Endpoint (Class II). In this case, the standard requires to
+define at least one network policy through
+.Nm lldpcli .
+.It Sy 3
+Communication Device Endpoints (Class III). In this case, the standard
+requires to define at least one network policy through
+.Nm lldpcli .
+.It Sy 4
+Network Connectivity Device
+.El
+.It Fl i
+Disable LLDP-MED inventory TLV transmission.
+.Nm
+will still receive (and publish using SNMP if enabled) those LLDP-MED
+TLV but will not send them. Use this option if you don't want to
+transmit sensible information like serial numbers.
+.It Fl H Ar hide
+Filter neighbors. See section
+.Sx FILTERING NEIGHBORS
+for details.
+.It Fl L Ar lldpcli
+Provide an alternative path to
+.Nm lldpcli
+for configuration. If empty, does not use
+.Nm lldpcli
+for configuration.
+.It Fl O Ar configfile
+Override default configuration locations processed by
+.Nm lldpcli
+at start. If a directory is provided, each file contained in it will be read if ending by
+.Sy .conf.
+Order is alphabetical.
+.It Fl v
+Show
+.Nm
+version. When repeated, show more build information.
+.El
+.Sh FILTERING NEIGHBORS
+In a heterogeneous network, you may see several different hosts on the
+same port, even if there is only one physically plugged to this
+port. For example, if you have a Nortel switch running LLDP which is
+plugged to a Cisco switch running CDP and your host is plugged to the
+Cisco switch, you will see the Nortel switch as well because LLDP
+frames are forwarded by the Cisco switch. This may not be what you
+want. The
+.Fl H Ar hide
+parameter will allow you to tell
+.Nm
+to discard some frames that it receives and to avoid to send some
+other frames.
+.Pp
+Incoming filtering and outgoing filtering are
+unrelated. Incoming filtering will hide some remote ports to get you a
+chance to know exactly what equipment is on the other side of the
+network cable. Outgoing filtering will avoid to use some protocols to
+avoid flooding your network with a protocol that is not handled by the
+nearest equipment. Keep in mind that even without filtering,
+.Nm
+will speak protocols for which at least one frame has been received
+and LLDP otherwise (there are other options to change this behaviour,
+for example
+.Fl cc , ss , ee , ll
+and
+.Fl ff
+).
+.Pp
+When enabling incoming filtering,
+.Nm
+will try to select one protocol and filter out neighbors using other
+protocols. To select this protocol, the rule is to take the less used
+protocol. If on one port, you get 12 CDP neighbors and 1 LLDP
+neighbor, this mean that the remote switch speaks LLDP and does not
+filter CDP. Therefore, we select LLDP. When enabling outgoing
+filtering,
+.Nm
+will also try to select one protocol and only speaks this
+protocol. The filtering is done per port. Each port may select a
+different protocol.
+.Pp
+There are two additional criteria when enabling filtering: allowing
+one or several protocols to be selected (in case of a tie) and
+allowing one or several neighbors to be selected. Even when allowing
+several protocols, the rule of selecting the protocols with the less
+neighbors still apply. If
+.Nm
+selects LLDP and CDP, this means they have the same number of
+neighbors. The selection of the neighbor is random. Incoming filtering
+will select a set of neighbors to be displayed while outgoing
+filtering will use the selected set of neighbors to decide which
+protocols to use: if a selected neighbor speaks LLDP and another one
+CDP,
+.Nm
+will speak both CDP and LLDP on this port.
+.Pp
+There are some corner cases. A typical example is a switch speaking
+two protocols (CDP and LLDP for example). You want to get the
+information from the best protocol but you want to speak both
+protocols because some tools use the CDP table and some other the LLDP
+table.
+.Pp
+The table below summarize all accepted values for the
+.Fl H Ar hide
+parameter. The default value is
+.Em 15
+which corresponds to the corner case described above. The
+.Em filter
+column means that filtering is enabled. The
+.Em 1proto
+column tells that only one protocol will be kept. The
+.Em 1neigh
+column tells that only one neighbor will be kept.
+.Pp
+.Bl -column -compact -offset indent "HXXX" "filterX" "1protoX" "1neighX" "filterX" "1protoX" "1neighX"
+.It Ta Ta incoming Ta Ta outgoing Ta
+.It Ta Em filter Ta Em 1proto Ta Em 1neigh Ta Em filter Ta Em 1proto Ta Em 1neigh
+.It Em 0 Ta Ta Ta Ta Ta Ta
+.It Em 1 Ta x Ta x Ta Ta x Ta x Ta
+.It Em 2 Ta x Ta x Ta Ta Ta Ta
+.It Em 3 Ta Ta Ta Ta x Ta x Ta
+.It Em 4 Ta x Ta Ta Ta x Ta Ta
+.It Em 5 Ta x Ta Ta Ta Ta Ta
+.It Em 6 Ta Ta Ta Ta x Ta Ta
+.It Em 7 Ta x Ta x Ta x Ta x Ta x Ta
+.It Em 8 Ta x Ta x Ta x Ta Ta Ta
+.It Em 9 Ta x Ta Ta x Ta x Ta x Ta
+.It Em 10 Ta Ta Ta Ta x Ta Ta x
+.It Em 11 Ta x Ta Ta x Ta Ta Ta
+.It Em 12 Ta x Ta Ta x Ta x Ta Ta x
+.It Em 13 Ta x Ta Ta x Ta x Ta Ta
+.It Em 14 Ta x Ta x Ta Ta x Ta Ta x
+.It Em 15 Ta x Ta x Ta Ta x Ta Ta
+.It Em 16 Ta x Ta x Ta x Ta x Ta Ta x
+.It Em 17 Ta x Ta x Ta x Ta x Ta Ta
+.It Em 18 Ta x Ta Ta Ta x Ta Ta x
+.It Em 19 Ta x Ta Ta Ta x Ta x Ta
+.El
+.Sh FILES
+.Bl -tag -width "@LLDPD_CTL_SOCKET@XX" -compact
+.It @LLDPD_CTL_SOCKET@
+Unix-domain socket used for communication with
+.Xr lldpctl 8 .
+.It @sysconfdir@/lldpd.conf
+Configuration file for
+.Nm .
+Commands in this files are executed by
+.Xr lldpcli 8
+at start.
+.It @sysconfdir@/lldpd.d
+Directory containing configuration files whose commands are executed
+by
+.Xr lldpcli 8
+at start.
+.El
+.Sh SEE ALSO
+.Xr lldpctl 8 ,
+.Xr lldpcli 8 ,
+.Xr snmpd 8
+.Sh HISTORY
+The
+.Nm
+program is inspired from a preliminary work of Reyk Floeter.
+.Sh AUTHORS
+.An -nosplit
+The
+.Nm
+program was written by
+.An Pierre-Yves Ritschard Aq pyr@openbsd.org ,
+and
+.An Vincent Bernat Aq bernat@luffy.cx .
diff --git a/src/daemon/lldpd.c b/src/daemon/lldpd.c
new file mode 100644
index 0000000..4859fb8
--- /dev/null
+++ b/src/daemon/lldpd.c
@@ -0,0 +1,2020 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2008 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "lldpd.h"
+#include "trace.h"
+
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+#include <limits.h>
+#include <signal.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <time.h>
+#include <libgen.h>
+#include <assert.h>
+#include <sys/utsname.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/socket.h>
+#include <sys/select.h>
+#include <sys/time.h>
+#include <sys/ioctl.h>
+#include <arpa/inet.h>
+#include <netinet/if_ether.h>
+#include <pwd.h>
+#include <grp.h>
+
+#if HAVE_VFORK_H
+# include <vfork.h>
+#endif
+#if HAVE_WORKING_FORK
+# define vfork fork
+#endif
+
+static void usage(void);
+
+static struct protocol protos[] = {
+ { LLDPD_MODE_LLDP, 1, "LLDP", 'l', lldp_send, lldp_decode, NULL,
+ { LLDP_ADDR_NEAREST_BRIDGE, LLDP_ADDR_NEAREST_NONTPMR_BRIDGE,
+ LLDP_ADDR_NEAREST_CUSTOMER_BRIDGE } },
+#ifdef ENABLE_CDP
+ { LLDPD_MODE_CDPV1, 0, "CDPv1", 'c', cdpv1_send, cdp_decode, cdpv1_guess,
+ { CDP_MULTICAST_ADDR } },
+ { LLDPD_MODE_CDPV2, 0, "CDPv2", 'c', cdpv2_send, cdp_decode, cdpv2_guess,
+ { CDP_MULTICAST_ADDR } },
+#endif
+#ifdef ENABLE_SONMP
+ { LLDPD_MODE_SONMP, 0, "SONMP", 's', sonmp_send, sonmp_decode, NULL,
+ { SONMP_MULTICAST_ADDR } },
+#endif
+#ifdef ENABLE_EDP
+ { LLDPD_MODE_EDP, 0, "EDP", 'e', edp_send, edp_decode, NULL,
+ { EDP_MULTICAST_ADDR } },
+#endif
+#ifdef ENABLE_FDP
+ { LLDPD_MODE_FDP, 0, "FDP", 'f', fdp_send, cdp_decode, NULL,
+ { FDP_MULTICAST_ADDR } },
+#endif
+ { 0, 0, "any", ' ', NULL, NULL, NULL, { { 0, 0, 0, 0, 0, 0 } } }
+};
+
+static char **saved_argv;
+#ifdef HAVE___PROGNAME
+extern const char *__progname;
+#else
+# define __progname "lldpd"
+#endif
+
+static void
+usage(void)
+{
+ fprintf(stderr, "Usage: %s [OPTIONS ...]\n", __progname);
+ fprintf(stderr, "Version: %s\n", PACKAGE_STRING);
+
+ fprintf(stderr, "\n");
+
+ fprintf(stderr, "-d Do not daemonize.\n");
+ fprintf(stderr, "-r Receive-only mode\n");
+ fprintf(stderr, "-i Disable LLDP-MED inventory TLV transmission.\n");
+ fprintf(stderr,
+ "-k Disable advertising of kernel release, version, machine.\n");
+ fprintf(stderr, "-S descr Override the default system description.\n");
+ fprintf(stderr, "-P name Override the default hardware platform.\n");
+ fprintf(stderr,
+ "-m IP Specify the IP management addresses of this system.\n");
+ fprintf(stderr,
+ "-u file Specify the Unix-domain socket used for communication with lldpctl(8).\n");
+ fprintf(stderr,
+ "-H mode Specify the behaviour when detecting multiple neighbors.\n");
+ fprintf(stderr, "-I iface Limit interfaces to use.\n");
+ fprintf(stderr, "-C iface Limit interfaces to use for computing chassis ID.\n");
+ fprintf(stderr, "-L path Override path for lldpcli command.\n");
+ fprintf(stderr,
+ "-O file Override default configuration locations processed by lldpcli(8) at start.\n");
+#ifdef ENABLE_LLDPMED
+ fprintf(stderr,
+ "-M class Enable emission of LLDP-MED frame. 'class' should be one of:\n");
+ fprintf(stderr, " 1 Generic Endpoint (Class I)\n");
+ fprintf(stderr, " 2 Media Endpoint (Class II)\n");
+ fprintf(stderr, " 3 Communication Device Endpoints (Class III)\n");
+ fprintf(stderr, " 4 Network Connectivity Device\n");
+#endif
+#ifdef USE_SNMP
+ fprintf(stderr, "-x Enable SNMP subagent.\n");
+ fprintf(stderr, "-X sock Specify the SNMP subagent socket.\n");
+#endif
+ fprintf(stderr, "\n");
+
+#if defined ENABLE_CDP || defined ENABLE_EDP || defined ENABLE_FDP || \
+ defined ENABLE_SONMP
+ fprintf(stderr, "Additional protocol support.\n");
+# ifdef ENABLE_CDP
+ fprintf(stderr, "-c Enable the support of CDP protocol. (Cisco)\n");
+# endif
+# ifdef ENABLE_EDP
+ fprintf(stderr, "-e Enable the support of EDP protocol. (Extreme)\n");
+# endif
+# ifdef ENABLE_FDP
+ fprintf(stderr, "-f Enable the support of FDP protocol. (Foundry)\n");
+# endif
+# ifdef ENABLE_SONMP
+ fprintf(stderr, "-s Enable the support of SONMP protocol. (Nortel)\n");
+# endif
+
+ fprintf(stderr, "\n");
+#endif
+
+ fprintf(stderr, "See manual page lldpd(8) for more information\n");
+ exit(1);
+}
+
+struct lldpd_hardware *
+lldpd_get_hardware(struct lldpd *cfg, char *name, int index)
+{
+ struct lldpd_hardware *hardware;
+ TAILQ_FOREACH (hardware, &cfg->g_hardware, h_entries) {
+ if (strcmp(hardware->h_ifname, name) == 0) {
+ if (hardware->h_flags == 0) {
+ if (hardware->h_ifindex != 0 &&
+ hardware->h_ifindex != index) {
+ log_debug("interfaces",
+ "%s changed index: from %d to %d",
+ hardware->h_ifname, hardware->h_ifindex,
+ index);
+ hardware->h_ifindex_changed = 1;
+ }
+ hardware->h_ifindex = index;
+ break;
+ }
+ if (hardware->h_ifindex == index) break;
+ }
+ }
+ return hardware;
+}
+
+/**
+ * Allocate the default local port. This port will be cloned each time we need a
+ * new local port.
+ */
+static void
+lldpd_alloc_default_local_port(struct lldpd *cfg)
+{
+ struct lldpd_port *port;
+
+ if ((port = (struct lldpd_port *)calloc(1, sizeof(struct lldpd_port))) == NULL)
+ fatal("main", NULL);
+
+#ifdef ENABLE_DOT1
+ TAILQ_INIT(&port->p_vlans);
+ TAILQ_INIT(&port->p_ppvids);
+ TAILQ_INIT(&port->p_pids);
+#endif
+#ifdef ENABLE_CUSTOM
+ TAILQ_INIT(&port->p_custom_list);
+#endif
+ cfg->g_default_local_port = port;
+}
+
+/**
+ * Clone a given port. The destination needs to be already allocated.
+ */
+static int
+lldpd_clone_port(struct lldpd_port *destination, struct lldpd_port *source)
+{
+
+ u_int8_t *output = NULL;
+ ssize_t output_len;
+ struct lldpd_port *cloned = NULL;
+ output_len = lldpd_port_serialize(source, (void **)&output);
+ if (output_len == -1 ||
+ lldpd_port_unserialize(output, output_len, &cloned) <= 0) {
+ log_warnx("alloc", "unable to clone default port");
+ free(output);
+ return -1;
+ }
+ memcpy(destination, cloned, sizeof(struct lldpd_port));
+ free(cloned);
+ free(output);
+#ifdef ENABLE_DOT1
+ marshal_repair_tailq(lldpd_vlan, &destination->p_vlans, v_entries);
+ marshal_repair_tailq(lldpd_ppvid, &destination->p_ppvids, p_entries);
+ marshal_repair_tailq(lldpd_pi, &destination->p_pids, p_entries);
+#endif
+#ifdef ENABLE_CUSTOM
+ marshal_repair_tailq(lldpd_custom, &destination->p_custom_list, next);
+#endif
+ return 0;
+}
+
+struct lldpd_hardware *
+lldpd_alloc_hardware(struct lldpd *cfg, char *name, int index)
+{
+ struct lldpd_hardware *hardware;
+
+ log_debug("alloc", "allocate a new local port (%s)", name);
+
+ if ((hardware = (struct lldpd_hardware *)calloc(1,
+ sizeof(struct lldpd_hardware))) == NULL)
+ return NULL;
+
+ /* Clone default local port */
+ if (lldpd_clone_port(&hardware->h_lport, cfg->g_default_local_port) == -1) {
+ log_warnx("alloc", "unable to clone default port");
+ free(hardware);
+ return NULL;
+ }
+
+ hardware->h_cfg = cfg;
+ strlcpy(hardware->h_ifname, name, sizeof(hardware->h_ifname));
+ hardware->h_ifindex = index;
+ hardware->h_lport.p_chassis = LOCAL_CHASSIS(cfg);
+ hardware->h_lport.p_chassis->c_refcount++;
+ TAILQ_INIT(&hardware->h_rports);
+
+#ifdef ENABLE_LLDPMED
+ if (LOCAL_CHASSIS(cfg)->c_med_cap_available) {
+ hardware->h_lport.p_med_cap_enabled = LLDP_MED_CAP_CAP;
+ if (!cfg->g_config.c_noinventory)
+ hardware->h_lport.p_med_cap_enabled |= LLDP_MED_CAP_IV;
+ }
+#endif
+
+ levent_hardware_init(hardware);
+ return hardware;
+}
+
+struct lldpd_mgmt *
+lldpd_alloc_mgmt(int family, void *addrptr, size_t addrsize, u_int32_t iface)
+{
+ struct lldpd_mgmt *mgmt;
+
+ log_debug("alloc", "allocate a new management address (family: %d)", family);
+
+ if (family <= LLDPD_AF_UNSPEC || family >= LLDPD_AF_LAST) {
+ errno = EAFNOSUPPORT;
+ return NULL;
+ }
+ if (addrsize > LLDPD_MGMT_MAXADDRSIZE) {
+ errno = EOVERFLOW;
+ return NULL;
+ }
+ mgmt = calloc(1, sizeof(struct lldpd_mgmt));
+ if (mgmt == NULL) {
+ errno = ENOMEM;
+ return NULL;
+ }
+ mgmt->m_family = family;
+ memcpy(&mgmt->m_addr, addrptr, addrsize);
+ mgmt->m_addrsize = addrsize;
+ mgmt->m_iface = iface;
+ return mgmt;
+}
+
+void
+lldpd_hardware_cleanup(struct lldpd *cfg, struct lldpd_hardware *hardware)
+{
+ log_debug("alloc", "cleanup hardware port %s", hardware->h_ifname);
+
+ free(hardware->h_lport_previous);
+ free(hardware->h_lchassis_previous_id);
+ free(hardware->h_lport_previous_id);
+ free(hardware->h_ifdescr_previous);
+ lldpd_port_cleanup(&hardware->h_lport, 1);
+ if (hardware->h_ops && hardware->h_ops->cleanup)
+ hardware->h_ops->cleanup(cfg, hardware);
+ levent_hardware_release(hardware);
+ free(hardware);
+}
+
+static void
+lldpd_ifdescr_neighbors(struct lldpd *cfg)
+{
+ if (!cfg->g_config.c_set_ifdescr) return;
+ struct lldpd_hardware *hardware;
+ TAILQ_FOREACH (hardware, &cfg->g_hardware, h_entries) {
+ struct lldpd_port *port;
+ char *description;
+ const char *neighbor = NULL;
+ unsigned neighbors = 0;
+ TAILQ_FOREACH (port, &hardware->h_rports, p_entries) {
+ if (SMART_HIDDEN(port)) continue;
+ neighbors++;
+ neighbor = port->p_chassis->c_name;
+ }
+ if (neighbors == 0)
+ description = strdup("");
+ else if (neighbors == 1 && neighbor && *neighbor != '\0') {
+ if (asprintf(&description, "%s", neighbor) == -1) {
+ continue;
+ }
+ } else {
+ if (asprintf(&description, "%d neighbor%s", neighbors,
+ (neighbors > 1) ? "s" : "") == -1) {
+ continue;
+ }
+ }
+ if (hardware->h_ifdescr_previous == NULL ||
+ strcmp(hardware->h_ifdescr_previous, description)) {
+ priv_iface_description(hardware->h_ifname, description);
+ free(hardware->h_ifdescr_previous);
+ hardware->h_ifdescr_previous = description;
+ } else
+ free(description);
+ }
+}
+
+static void
+lldpd_count_neighbors(struct lldpd *cfg)
+{
+#if HAVE_SETPROCTITLE
+ struct lldpd_chassis *chassis;
+ const char *neighbor;
+ unsigned neighbors = 0;
+ TAILQ_FOREACH (chassis, &cfg->g_chassis, c_entries) {
+ neighbors++;
+ neighbor = chassis->c_name;
+ }
+ neighbors--;
+ if (neighbors == 0)
+ setproctitle("no neighbor.");
+ else if (neighbors == 1 && neighbor && *neighbor != '\0')
+ setproctitle("connected to %s.", neighbor);
+ else
+ setproctitle("%d neighbor%s.", neighbors, (neighbors > 1) ? "s" : "");
+#endif
+ lldpd_ifdescr_neighbors(cfg);
+}
+
+static void
+notify_clients_deletion(struct lldpd_hardware *hardware, struct lldpd_port *rport)
+{
+ TRACE(LLDPD_NEIGHBOR_DELETE(hardware->h_ifname, rport->p_chassis->c_name,
+ rport->p_descr));
+ levent_ctl_notify(hardware->h_ifname, NEIGHBOR_CHANGE_DELETED, rport);
+#ifdef USE_SNMP
+ agent_notify(hardware, NEIGHBOR_CHANGE_DELETED, rport);
+#endif
+}
+
+static void
+lldpd_reset_timer(struct lldpd *cfg)
+{
+ /* Reset timer for ports that have been changed. */
+ struct lldpd_hardware *hardware;
+ TAILQ_FOREACH (hardware, &cfg->g_hardware, h_entries) {
+ /* We keep a flat copy of the local port to see if there is any
+ * change. To do this, we zero out fields that are not
+ * significant, marshal the port, then restore. */
+ struct lldpd_port *port = &hardware->h_lport;
+ /* Take the current flags into account to detect a change. */
+ port->_p_hardware_flags = hardware->h_flags;
+ u_int8_t *output = NULL;
+ ssize_t output_len;
+ char save[LLDPD_PORT_START_MARKER];
+ memcpy(save, port, sizeof(save));
+ /* coverity[sizeof_mismatch]
+ We intentionally partially memset port */
+ memset(port, 0, sizeof(save));
+ output_len = lldpd_port_serialize(port, (void **)&output);
+ memcpy(port, save, sizeof(save));
+ if (output_len == -1) {
+ log_warnx("localchassis",
+ "unable to serialize local port %s to check for differences",
+ hardware->h_ifname);
+ continue;
+ }
+
+ /* Compare with the previous value */
+ if (!hardware->h_ifindex_changed && hardware->h_lport_previous &&
+ output_len == hardware->h_lport_previous_len &&
+ !memcmp(output, hardware->h_lport_previous, output_len)) {
+ log_debug("localchassis", "no change detected for port %s",
+ hardware->h_ifname);
+ } else {
+ log_debug("localchassis",
+ "change detected for port %s, resetting its timer",
+ hardware->h_ifname);
+ hardware->h_ifindex_changed = 0;
+ levent_schedule_pdu(hardware);
+ }
+
+ /* Update the value */
+ free(hardware->h_lport_previous);
+ hardware->h_lport_previous = output;
+ hardware->h_lport_previous_len = output_len;
+ }
+}
+
+static void
+lldpd_all_chassis_cleanup(struct lldpd *cfg)
+{
+ struct lldpd_chassis *chassis, *chassis_next;
+ log_debug("localchassis", "cleanup all chassis");
+
+ for (chassis = TAILQ_FIRST(&cfg->g_chassis); chassis; chassis = chassis_next) {
+ chassis_next = TAILQ_NEXT(chassis, c_entries);
+ if (chassis->c_refcount == 0) {
+ TAILQ_REMOVE(&cfg->g_chassis, chassis, c_entries);
+ lldpd_chassis_cleanup(chassis, 1);
+ }
+ }
+}
+
+void
+lldpd_cleanup(struct lldpd *cfg)
+{
+ struct lldpd_hardware *hardware, *hardware_next;
+
+ log_debug("localchassis", "cleanup all ports");
+
+ for (hardware = TAILQ_FIRST(&cfg->g_hardware); hardware != NULL;
+ hardware = hardware_next) {
+ hardware_next = TAILQ_NEXT(hardware, h_entries);
+ if (!hardware->h_flags) {
+ int m = cfg->g_config.c_perm_ifaces ?
+ pattern_match(hardware->h_ifname,
+ cfg->g_config.c_perm_ifaces, 0) :
+ 0;
+ switch (m) {
+ case PATTERN_MATCH_DENIED:
+ log_debug("localchassis",
+ "delete non-permanent interface %s",
+ hardware->h_ifname);
+ TRACE(LLDPD_INTERFACES_DELETE(hardware->h_ifname));
+ TAILQ_REMOVE(&cfg->g_hardware, hardware, h_entries);
+ lldpd_remote_cleanup(hardware, notify_clients_deletion,
+ 1);
+ lldpd_hardware_cleanup(cfg, hardware);
+ break;
+ case PATTERN_MATCH_ALLOWED:
+ case PATTERN_MATCH_ALLOWED_EXACT:
+ log_debug("localchassis", "do not delete %s, permanent",
+ hardware->h_ifname);
+ lldpd_remote_cleanup(hardware, notify_clients_deletion,
+ 1);
+ break;
+ }
+ } else {
+ lldpd_remote_cleanup(hardware, notify_clients_deletion,
+ !(hardware->h_flags & IFF_RUNNING));
+ }
+ }
+
+ levent_schedule_cleanup(cfg);
+ lldpd_all_chassis_cleanup(cfg);
+ lldpd_count_neighbors(cfg);
+}
+
+/* Update chassis `ochassis' with values from `chassis'. The later one is not
+ expected to be part of a list! It will also be wiped from memory. */
+static void
+lldpd_move_chassis(struct lldpd_chassis *ochassis, struct lldpd_chassis *chassis)
+{
+ struct lldpd_mgmt *mgmt, *mgmt_next;
+
+ /* We want to keep refcount, index and list stuff from the current
+ * chassis */
+ TAILQ_ENTRY(lldpd_chassis) entries;
+ int refcount = ochassis->c_refcount;
+ int index = ochassis->c_index;
+ memcpy(&entries, &ochassis->c_entries, sizeof(entries));
+ lldpd_chassis_cleanup(ochassis, 0);
+
+ /* Make the copy. */
+ /* WARNING: this is a kludgy hack, we need in-place copy and cannot use
+ * marshaling. */
+ memcpy(ochassis, chassis, sizeof(struct lldpd_chassis));
+ TAILQ_INIT(&ochassis->c_mgmt);
+
+ /* Copy of management addresses */
+ for (mgmt = TAILQ_FIRST(&chassis->c_mgmt); mgmt != NULL; mgmt = mgmt_next) {
+ mgmt_next = TAILQ_NEXT(mgmt, m_entries);
+ TAILQ_REMOVE(&chassis->c_mgmt, mgmt, m_entries);
+ TAILQ_INSERT_TAIL(&ochassis->c_mgmt, mgmt, m_entries);
+ }
+
+ /* Restore saved values */
+ ochassis->c_refcount = refcount;
+ ochassis->c_index = index;
+ memcpy(&ochassis->c_entries, &entries, sizeof(entries));
+
+ /* Get rid of the new chassis */
+ free(chassis);
+}
+
+static int
+lldpd_guess_type(struct lldpd *cfg, char *frame, int s)
+{
+ size_t i, j;
+ if (s < ETHER_ADDR_LEN) return -1;
+ for (i = 0; cfg->g_protocols[i].mode != 0; i++) {
+ if (!cfg->g_protocols[i].enabled) continue;
+ if (cfg->g_protocols[i].guess == NULL) {
+ for (j = 0; j < sizeof(cfg->g_protocols[0].mac) /
+ sizeof(cfg->g_protocols[0].mac[0]);
+ j++) {
+ if (memcmp(frame, cfg->g_protocols[i].mac[j],
+ ETHER_ADDR_LEN) == 0) {
+ log_debug("decode",
+ "guessed protocol is %s (from MAC address)",
+ cfg->g_protocols[i].name);
+ return cfg->g_protocols[i].mode;
+ }
+ }
+ } else {
+ if (cfg->g_protocols[i].guess(frame, s)) {
+ log_debug("decode",
+ "guessed protocol is %s (from detector function)",
+ cfg->g_protocols[i].name);
+ return cfg->g_protocols[i].mode;
+ }
+ }
+ }
+ return -1;
+}
+
+static void
+lldpd_decode(struct lldpd *cfg, char *frame, int s, struct lldpd_hardware *hardware)
+{
+ int i;
+ struct lldpd_chassis *chassis, *ochassis = NULL;
+ struct lldpd_port *port, *oport = NULL, *aport;
+ int guess = LLDPD_MODE_LLDP;
+
+ log_debug("decode", "decode a received frame on %s", hardware->h_ifname);
+
+ if (s < sizeof(struct ether_header) + 4) {
+ /* Too short, just discard it */
+ hardware->h_rx_discarded_cnt++;
+ return;
+ }
+
+ /* Decapsulate VLAN frames */
+ struct ether_header eheader;
+ memcpy(&eheader, frame, sizeof(struct ether_header));
+ if (eheader.ether_type == htons(ETHERTYPE_VLAN)) {
+ /* VLAN decapsulation means to shift 4 bytes left the frame from
+ * offset 2*ETHER_ADDR_LEN */
+ memmove(frame + 2 * ETHER_ADDR_LEN, frame + 2 * ETHER_ADDR_LEN + 4,
+ s - 2 * ETHER_ADDR_LEN);
+ s -= 4;
+ }
+
+ TAILQ_FOREACH (oport, &hardware->h_rports, p_entries) {
+ if ((oport->p_lastframe != NULL) && (oport->p_lastframe->size == s) &&
+ (memcmp(oport->p_lastframe->frame, frame, s) == 0)) {
+ /* Already received the same frame */
+ log_debug("decode", "duplicate frame, no need to decode");
+ oport->p_lastupdate = time(NULL);
+ return;
+ }
+ }
+
+ guess = lldpd_guess_type(cfg, frame, s);
+ for (i = 0; cfg->g_protocols[i].mode != 0; i++) {
+ if (!cfg->g_protocols[i].enabled) continue;
+ if (cfg->g_protocols[i].mode == guess) {
+ log_debug("decode", "using decode function for %s protocol",
+ cfg->g_protocols[i].name);
+ if (cfg->g_protocols[i].decode(cfg, frame, s, hardware,
+ &chassis, &port) == -1) {
+ log_debug("decode",
+ "function for %s protocol did not decode this frame",
+ cfg->g_protocols[i].name);
+ hardware->h_rx_discarded_cnt++;
+ return;
+ }
+ chassis->c_protocol = port->p_protocol =
+ cfg->g_protocols[i].mode;
+ break;
+ }
+ }
+ if (cfg->g_protocols[i].mode == 0) {
+ log_debug("decode", "unable to guess frame type on %s",
+ hardware->h_ifname);
+ return;
+ }
+ TRACE(LLDPD_FRAME_DECODED(hardware->h_ifname, cfg->g_protocols[i].name,
+ chassis->c_name, port->p_descr));
+
+ /* Do we already have the same MSAP somewhere? */
+ int count = 0;
+ log_debug("decode", "search for the same MSAP");
+ TAILQ_FOREACH (oport, &hardware->h_rports, p_entries) {
+ if (port->p_protocol == oport->p_protocol) {
+ count++;
+ if ((port->p_id_subtype == oport->p_id_subtype) &&
+ (port->p_id_len == oport->p_id_len) &&
+ (memcmp(port->p_id, oport->p_id, port->p_id_len) == 0) &&
+ (chassis->c_id_subtype == oport->p_chassis->c_id_subtype) &&
+ (chassis->c_id_len == oport->p_chassis->c_id_len) &&
+ (memcmp(chassis->c_id, oport->p_chassis->c_id,
+ chassis->c_id_len) == 0)) {
+ ochassis = oport->p_chassis;
+ log_debug("decode", "MSAP is already known");
+ break;
+ }
+ }
+ }
+ /* Do we have room for a new MSAP? */
+ if (!oport && cfg->g_config.c_max_neighbors) {
+ if (count == (cfg->g_config.c_max_neighbors - 1)) {
+ log_debug("decode",
+ "max neighbors %d reached for port %s, "
+ "dropping any new ones silently",
+ cfg->g_config.c_max_neighbors, hardware->h_ifname);
+ } else if (count > cfg->g_config.c_max_neighbors - 1) {
+ log_debug("decode",
+ "too many neighbors for port %s, drop this new one",
+ hardware->h_ifname);
+ lldpd_port_cleanup(port, 1);
+ lldpd_chassis_cleanup(chassis, 1);
+ free(port);
+ return;
+ }
+ }
+ /* No, but do we already know the system? */
+ if (!oport) {
+ log_debug("decode", "MSAP is unknown, search for the chassis");
+ TAILQ_FOREACH (ochassis, &cfg->g_chassis, c_entries) {
+ if ((chassis->c_protocol == ochassis->c_protocol) &&
+ (chassis->c_id_subtype == ochassis->c_id_subtype) &&
+ (chassis->c_id_len == ochassis->c_id_len) &&
+ (memcmp(chassis->c_id, ochassis->c_id, chassis->c_id_len) ==
+ 0))
+ break;
+ }
+ }
+
+ if (oport) {
+ /* The port is known, remove it before adding it back */
+ TAILQ_REMOVE(&hardware->h_rports, oport, p_entries);
+ lldpd_port_cleanup(oport, 1);
+ free(oport);
+ }
+ if (ochassis) {
+ if (port->p_ttl == 0) {
+ /* Shutdown LLDPDU is special. We do not want to replace
+ * the chassis. Free the new chassis (which is mostly empty) */
+ log_debug("decode", "received a shutdown LLDPDU");
+ lldpd_chassis_cleanup(chassis, 1);
+ } else {
+ lldpd_move_chassis(ochassis, chassis);
+ }
+ chassis = ochassis;
+ } else {
+ /* Chassis not known, add it */
+ log_debug("decode", "unknown chassis, add it to the list");
+ chassis->c_index = ++cfg->g_lastrid;
+ chassis->c_refcount = 0;
+ TAILQ_INSERT_TAIL(&cfg->g_chassis, chassis, c_entries);
+ i = 0;
+ TAILQ_FOREACH (ochassis, &cfg->g_chassis, c_entries)
+ i++;
+ log_debug("decode", "%d different systems are known", i);
+ }
+ /* Add port */
+ port->p_lastchange = port->p_lastupdate = time(NULL);
+ if ((port->p_lastframe = (struct lldpd_frame *)malloc(
+ s + sizeof(struct lldpd_frame))) != NULL) {
+ port->p_lastframe->size = s;
+ memcpy(port->p_lastframe->frame, frame, s);
+ }
+ TAILQ_INSERT_TAIL(&hardware->h_rports, port, p_entries);
+ port->p_chassis = chassis;
+ port->p_chassis->c_refcount++;
+ /* Several cases are possible :
+ 1. chassis is new, its refcount was 0. It is now attached
+ to this port, its refcount is 1.
+ 2. chassis already exists and was attached to another
+ port, we increase its refcount accordingly.
+ 3. chassis already exists and was attached to the same
+ port, its refcount was decreased with
+ lldpd_port_cleanup() and is now increased again.
+
+ In all cases, if the port already existed, it has been
+ freed with lldpd_port_cleanup() and therefore, the refcount
+ of the chassis that was attached to it is decreased.
+ */
+ i = 0;
+ /* coverity[use_after_free]
+ TAILQ_REMOVE does the right thing */
+ TAILQ_FOREACH (aport, &hardware->h_rports, p_entries)
+ i++;
+ log_debug("decode", "%d neighbors for %s", i, hardware->h_ifname);
+
+ if (!oport) hardware->h_insert_cnt++;
+
+ /* Notify */
+ log_debug("decode", "send notifications for changes on %s", hardware->h_ifname);
+ if (oport) {
+ TRACE(LLDPD_NEIGHBOR_UPDATE(hardware->h_ifname, chassis->c_name,
+ port->p_descr, i));
+ levent_ctl_notify(hardware->h_ifname, NEIGHBOR_CHANGE_UPDATED, port);
+#ifdef USE_SNMP
+ agent_notify(hardware, NEIGHBOR_CHANGE_UPDATED, port);
+#endif
+ } else {
+ TRACE(LLDPD_NEIGHBOR_NEW(hardware->h_ifname, chassis->c_name,
+ port->p_descr, i));
+ levent_ctl_notify(hardware->h_ifname, NEIGHBOR_CHANGE_ADDED, port);
+#ifdef USE_SNMP
+ agent_notify(hardware, NEIGHBOR_CHANGE_ADDED, port);
+#endif
+ }
+
+#ifdef ENABLE_LLDPMED
+ if (!oport && port->p_chassis->c_med_type) {
+ /* New neighbor, fast start */
+ if (hardware->h_cfg->g_config.c_enable_fast_start &&
+ !hardware->h_tx_fast) {
+ log_debug("decode",
+ "%s: entering fast start due to "
+ "new neighbor",
+ hardware->h_ifname);
+ hardware->h_tx_fast = hardware->h_cfg->g_config.c_tx_fast_init;
+ }
+
+ levent_schedule_pdu(hardware);
+ }
+#endif
+
+ return;
+}
+
+/* Get the output of lsb_release -s -d. This is a slow function. It should be
+ called once. It return NULL if any problem happens. Otherwise, this is a
+ statically allocated buffer. The result includes the trailing \n */
+static char *
+lldpd_get_lsb_release()
+{
+ static char release[1024];
+ char cmd[][12] = { "lsb_release", "-s", "-d" };
+ char *const command[] = { cmd[0], cmd[1], cmd[2], NULL };
+ int pid, status, devnull, count;
+ int pipefd[2];
+
+ log_debug("localchassis", "grab LSB release");
+
+ if (pipe(pipefd)) {
+ log_warn("localchassis", "unable to get a pair of pipes");
+ return NULL;
+ }
+
+ pid = vfork();
+ switch (pid) {
+ case -1:
+ log_warn("localchassis", "unable to fork");
+ return NULL;
+ case 0:
+ /* Child, exec lsb_release */
+ close(pipefd[0]);
+ if ((devnull = open("/dev/null", O_RDWR, 0)) != -1) {
+ dup2(devnull, STDIN_FILENO);
+ dup2(devnull, STDERR_FILENO);
+ dup2(pipefd[1], STDOUT_FILENO);
+ if (devnull > 2) close(devnull);
+ if (pipefd[1] > 2) close(pipefd[1]);
+ execvp("lsb_release", command);
+ }
+ _exit(127);
+ break;
+ default:
+ /* Father, read the output from the children */
+ close(pipefd[1]);
+ count = 0;
+ do {
+ status =
+ read(pipefd[0], release + count, sizeof(release) - count);
+ if ((status == -1) && (errno == EINTR)) continue;
+ if (status > 0) count += status;
+ } while (count < sizeof(release) && (status > 0));
+ if (status < 0) {
+ log_info("localchassis", "unable to read from lsb_release");
+ close(pipefd[0]);
+ waitpid(pid, &status, 0);
+ return NULL;
+ }
+ close(pipefd[0]);
+ if (count >= sizeof(release)) {
+ log_info("localchassis", "output of lsb_release is too large");
+ waitpid(pid, &status, 0);
+ return NULL;
+ }
+ status = -1;
+ if (waitpid(pid, &status, 0) != pid) return NULL;
+ if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) {
+ log_info("localchassis",
+ "lsb_release information not available");
+ return NULL;
+ }
+ if (!count) {
+ log_info("localchassis",
+ "lsb_release returned an empty string");
+ return NULL;
+ }
+ release[count] = '\0';
+ return release;
+ }
+ /* Should not be here */
+ return NULL;
+}
+
+/* Same like lldpd_get_lsb_release but reads /etc/os-release for PRETTY_NAME=. */
+static char *
+lldpd_get_os_release()
+{
+ static char release[1024];
+ char line[1024];
+ char *key, *val;
+ char *ptr1 = release;
+
+ log_debug("localchassis", "grab OS release");
+ FILE *fp = fopen("/etc/os-release", "r");
+ if (!fp) {
+ log_debug("localchassis", "could not open /etc/os-release");
+ fp = fopen("/usr/lib/os-release", "r");
+ }
+ if (!fp) {
+ log_info("localchassis",
+ "could not open either /etc/os-release or /usr/lib/os-release");
+ return NULL;
+ }
+
+ while ((fgets(line, sizeof(line), fp) != NULL)) {
+ key = strtok(line, "=");
+ val = strtok(NULL, "=");
+
+ if (strncmp(key, "PRETTY_NAME", sizeof(line)) == 0) {
+ strlcpy(release, val, sizeof(line));
+ break;
+ }
+ }
+ fclose(fp);
+
+ /* Remove trailing newline and all " in the string. */
+ ptr1 = release + strlen(release) - 1;
+ while (ptr1 != release && ((*ptr1 == '"') || (*ptr1 == '\n'))) {
+ *ptr1 = '\0';
+ ptr1--;
+ }
+ if (release[0] == '"') return release + 1;
+ return release;
+}
+
+static void
+lldpd_hide_ports(struct lldpd *cfg, struct lldpd_hardware *hardware, int mask)
+{
+ struct lldpd_port *port;
+ int protocols[LLDPD_MODE_MAX + 1];
+ char buffer[256];
+ int i, j, k, found;
+ unsigned int min;
+
+ log_debug("smartfilter", "apply smart filter for port %s", hardware->h_ifname);
+
+ /* Compute the number of occurrences of each protocol */
+ for (i = 0; i <= LLDPD_MODE_MAX; i++)
+ protocols[i] = 0;
+ TAILQ_FOREACH (port, &hardware->h_rports, p_entries)
+ protocols[port->p_protocol]++;
+
+ /* Turn the protocols[] array into an array of
+ enabled/disabled protocols. 1 means enabled, 0
+ means disabled. */
+ min = (unsigned int)-1;
+ for (i = 0; i <= LLDPD_MODE_MAX; i++)
+ if (protocols[i] && (protocols[i] < min)) min = protocols[i];
+ found = 0;
+ for (i = 0; i <= LLDPD_MODE_MAX; i++)
+ if ((protocols[i] == min) && !found) {
+ /* If we need a tie breaker, we take
+ the first protocol only */
+ if (cfg->g_config.c_smart & mask &
+ (SMART_OUTGOING_ONE_PROTO | SMART_INCOMING_ONE_PROTO))
+ found = 1;
+ protocols[i] = 1;
+ } else
+ protocols[i] = 0;
+
+ /* We set the p_hidden flag to 1 if the protocol is disabled */
+ TAILQ_FOREACH (port, &hardware->h_rports, p_entries) {
+ if (mask == SMART_OUTGOING)
+ port->p_hidden_out = protocols[port->p_protocol] ? 0 : 1;
+ else
+ port->p_hidden_in = protocols[port->p_protocol] ? 0 : 1;
+ }
+
+ /* If we want only one neighbor, we take the first one */
+ if (cfg->g_config.c_smart & mask &
+ (SMART_OUTGOING_ONE_NEIGH | SMART_INCOMING_ONE_NEIGH)) {
+ found = 0;
+ TAILQ_FOREACH (port, &hardware->h_rports, p_entries) {
+ if (mask == SMART_OUTGOING) {
+ if (found) port->p_hidden_out = 1;
+ if (!port->p_hidden_out) found = 1;
+ }
+ if (mask == SMART_INCOMING) {
+ if (found) port->p_hidden_in = 1;
+ if (!port->p_hidden_in) found = 1;
+ }
+ }
+ }
+
+ /* Print a debug message summarizing the operation */
+ for (i = 0; i <= LLDPD_MODE_MAX; i++)
+ protocols[i] = 0;
+ k = j = 0;
+ TAILQ_FOREACH (port, &hardware->h_rports, p_entries) {
+ if (!(((mask == SMART_OUTGOING) && port->p_hidden_out) ||
+ ((mask == SMART_INCOMING) && port->p_hidden_in))) {
+ k++;
+ protocols[port->p_protocol] = 1;
+ }
+ j++;
+ }
+ buffer[0] = '\0';
+ for (i = 0; cfg->g_protocols[i].mode != 0; i++) {
+ if (cfg->g_protocols[i].enabled &&
+ protocols[cfg->g_protocols[i].mode]) {
+ if (strlen(buffer) + strlen(cfg->g_protocols[i].name) + 3 >
+ sizeof(buffer)) {
+ /* Unlikely, our buffer is too small */
+ memcpy(buffer + sizeof(buffer) - 4, "...", 4);
+ break;
+ }
+ if (buffer[0])
+ strncat(buffer, ", ",
+ sizeof(buffer) - strlen(buffer) - 1);
+ strncat(buffer, cfg->g_protocols[i].name,
+ sizeof(buffer) - strlen(buffer) - 1);
+ }
+ }
+ log_debug("smartfilter", "%s: %s: %d visible neighbors (out of %d)",
+ hardware->h_ifname, (mask == SMART_OUTGOING) ? "out filter" : "in filter",
+ k, j);
+ log_debug("smartfilter", "%s: protocols: %s", hardware->h_ifname,
+ buffer[0] ? buffer : "(none)");
+}
+
+/* Hide unwanted ports depending on smart mode set by the user */
+static void
+lldpd_hide_all(struct lldpd *cfg)
+{
+ struct lldpd_hardware *hardware;
+
+ if (!cfg->g_config.c_smart) return;
+ log_debug("smartfilter", "apply smart filter results on all ports");
+ TAILQ_FOREACH (hardware, &cfg->g_hardware, h_entries) {
+ if (cfg->g_config.c_smart & SMART_INCOMING_FILTER)
+ lldpd_hide_ports(cfg, hardware, SMART_INCOMING);
+ if (cfg->g_config.c_smart & SMART_OUTGOING_FILTER)
+ lldpd_hide_ports(cfg, hardware, SMART_OUTGOING);
+ }
+}
+
+/* If PD device and PSE allocated power, echo back this change. If we have
+ * several LLDP neighbors, we use the latest updated. */
+static void
+lldpd_dot3_power_pd_pse(struct lldpd_hardware *hardware)
+{
+#ifdef ENABLE_DOT3
+ struct lldpd_port *port, *selected_port = NULL;
+ /* Are we a PD device? */
+ if (hardware->h_lport.p_power.devicetype != LLDP_DOT3_POWER_PD) return;
+ TAILQ_FOREACH (port, &hardware->h_rports, p_entries) {
+ if (port->p_hidden_in) continue;
+
+ if (port->p_protocol != LLDPD_MODE_LLDP &&
+ port->p_protocol != LLDPD_MODE_CDPV2)
+ continue;
+
+ if (port->p_power.devicetype != LLDP_DOT3_POWER_PSE) continue;
+ if (!selected_port || port->p_lastupdate > selected_port->p_lastupdate)
+ selected_port = port;
+ }
+ if (selected_port &&
+ selected_port->p_power.allocated != hardware->h_lport.p_power.allocated) {
+ log_info("receive",
+ "for %s, PSE told us allocated is now %d instead of %d",
+ hardware->h_ifname, selected_port->p_power.allocated,
+ hardware->h_lport.p_power.allocated);
+ hardware->h_lport.p_power.allocated = selected_port->p_power.allocated;
+ levent_schedule_pdu(hardware);
+ }
+
+# ifdef ENABLE_CDP
+ if (selected_port &&
+ selected_port->p_cdp_power.management_id !=
+ hardware->h_lport.p_cdp_power.management_id) {
+ hardware->h_lport.p_cdp_power.management_id =
+ selected_port->p_cdp_power.management_id;
+ }
+# endif
+
+#endif
+}
+
+void
+lldpd_recv(struct lldpd *cfg, struct lldpd_hardware *hardware, int fd)
+{
+ char *buffer = NULL;
+ int n;
+ log_debug("receive", "receive a frame on %s", hardware->h_ifname);
+ if ((buffer = (char *)malloc(hardware->h_mtu)) == NULL) {
+ log_warn("receive", "failed to alloc reception buffer");
+ return;
+ }
+ if ((n = hardware->h_ops->recv(cfg, hardware, fd, buffer, hardware->h_mtu)) ==
+ -1) {
+ log_debug("receive", "discard frame received on %s",
+ hardware->h_ifname);
+ free(buffer);
+ return;
+ }
+ if (hardware->h_lport.p_disable_rx) {
+ log_debug("receive", "RX disabled, ignore the frame on %s",
+ hardware->h_ifname);
+ free(buffer);
+ return;
+ }
+ if (cfg->g_config.c_paused) {
+ log_debug("receive", "paused, ignore the frame on %s",
+ hardware->h_ifname);
+ free(buffer);
+ return;
+ }
+ hardware->h_rx_cnt++;
+ log_debug("receive", "decode received frame on %s", hardware->h_ifname);
+ TRACE(LLDPD_FRAME_RECEIVED(hardware->h_ifname, buffer, (size_t)n));
+ lldpd_decode(cfg, buffer, n, hardware);
+ lldpd_hide_all(cfg); /* Immediatly hide */
+ lldpd_dot3_power_pd_pse(hardware);
+ lldpd_count_neighbors(cfg);
+ free(buffer);
+}
+
+static void
+lldpd_send_shutdown(struct lldpd_hardware *hardware)
+{
+ struct lldpd *cfg = hardware->h_cfg;
+ if (cfg->g_config.c_receiveonly || cfg->g_config.c_paused) return;
+ if (hardware->h_lport.p_disable_tx) return;
+ if ((hardware->h_flags & IFF_RUNNING) == 0) return;
+
+ /* It's safe to call `lldp_send_shutdown()` because shutdown LLDPU will
+ * only be emitted if LLDP was sent on that port. */
+ if (lldp_send_shutdown(hardware->h_cfg, hardware) != 0)
+ log_warnx("send", "unable to send shutdown LLDPDU on %s",
+ hardware->h_ifname);
+}
+
+void
+lldpd_send(struct lldpd_hardware *hardware)
+{
+ struct lldpd *cfg = hardware->h_cfg;
+ struct lldpd_port *port;
+ int i, sent;
+
+ if (cfg->g_config.c_receiveonly || cfg->g_config.c_paused) return;
+ if (hardware->h_lport.p_disable_tx) return;
+ if ((hardware->h_flags & IFF_RUNNING) == 0) return;
+
+ log_debug("send", "send PDU on %s", hardware->h_ifname);
+ sent = 0;
+ for (i = 0; cfg->g_protocols[i].mode != 0; i++) {
+ if (!cfg->g_protocols[i].enabled) continue;
+ /* We send only if we have at least one remote system
+ * speaking this protocol or if the protocol is forced */
+ if (cfg->g_protocols[i].enabled > 1) {
+ cfg->g_protocols[i].send(cfg, hardware);
+ sent++;
+ continue;
+ }
+ TAILQ_FOREACH (port, &hardware->h_rports, p_entries) {
+ /* If this remote port is disabled, we don't
+ * consider it */
+ if (port->p_hidden_out) continue;
+ if (port->p_protocol == cfg->g_protocols[i].mode) {
+ TRACE(LLDPD_FRAME_SEND(hardware->h_ifname,
+ cfg->g_protocols[i].name));
+ log_debug("send", "send PDU on %s with protocol %s",
+ hardware->h_ifname, cfg->g_protocols[i].name);
+ cfg->g_protocols[i].send(cfg, hardware);
+ hardware->h_lport.p_protocol = cfg->g_protocols[i].mode;
+ sent++;
+ break;
+ }
+ }
+ }
+
+ if (!sent) {
+ /* Nothing was sent for this port, let's speak the first
+ * available protocol. */
+ for (i = 0; cfg->g_protocols[i].mode != 0; i++) {
+ if (!cfg->g_protocols[i].enabled) continue;
+ TRACE(LLDPD_FRAME_SEND(hardware->h_ifname,
+ cfg->g_protocols[i].name));
+ log_debug("send", "fallback to protocol %s for %s",
+ cfg->g_protocols[i].name, hardware->h_ifname);
+ cfg->g_protocols[i].send(cfg, hardware);
+ break;
+ }
+ if (cfg->g_protocols[i].mode == 0)
+ log_warnx("send", "no protocol enabled, dunno what to send");
+ }
+}
+
+#ifdef ENABLE_LLDPMED
+static void
+lldpd_med(struct lldpd *cfg, struct utsname *un)
+{
+ static short int once = 0;
+ if (!once && cfg) {
+ LOCAL_CHASSIS(cfg)->c_med_hw = dmi_hw();
+ LOCAL_CHASSIS(cfg)->c_med_fw = dmi_fw();
+ LOCAL_CHASSIS(cfg)->c_med_sn = dmi_sn();
+ LOCAL_CHASSIS(cfg)->c_med_manuf = dmi_manuf();
+ LOCAL_CHASSIS(cfg)->c_med_model = dmi_model();
+ LOCAL_CHASSIS(cfg)->c_med_asset = dmi_asset();
+ if (un) {
+ if (LOCAL_CHASSIS(cfg)->c_med_sw)
+ free(LOCAL_CHASSIS(cfg)->c_med_sw);
+
+ if (cfg->g_config.c_advertise_version)
+ LOCAL_CHASSIS(cfg)->c_med_sw = strdup(un->release);
+ else
+ LOCAL_CHASSIS(cfg)->c_med_sw = strdup("Unknown");
+ }
+ once = 1;
+ }
+}
+#endif
+
+static int
+lldpd_routing_enabled(struct lldpd *cfg)
+{
+ int routing;
+
+ if ((LOCAL_CHASSIS(cfg)->c_cap_available & LLDP_CAP_ROUTER) == 0) return 0;
+
+ if ((routing = interfaces_routing_enabled(cfg)) == -1) {
+ log_debug("localchassis", "unable to check if routing is enabled");
+ return 0;
+ }
+ return routing;
+}
+
+void
+lldpd_update_localchassis(struct lldpd *cfg)
+{
+ struct utsname un;
+ char *hp;
+
+ log_debug("localchassis", "update information for local chassis");
+ assert(LOCAL_CHASSIS(cfg) != NULL);
+
+ /* Set system name and description */
+ if (uname(&un) < 0) fatal("localchassis", "failed to get system information");
+ if (cfg->g_config.c_hostname) {
+ log_debug("localchassis", "use overridden system name `%s`",
+ cfg->g_config.c_hostname);
+ hp = cfg->g_config.c_hostname;
+ } else {
+ if ((hp = priv_gethostname()) == NULL)
+ fatal("localchassis", "failed to get system name");
+ }
+ free(LOCAL_CHASSIS(cfg)->c_name);
+ free(LOCAL_CHASSIS(cfg)->c_descr);
+ if ((LOCAL_CHASSIS(cfg)->c_name = strdup(hp)) == NULL)
+ fatal("localchassis", NULL);
+ if (cfg->g_config.c_description) {
+ log_debug("localchassis", "use overridden description `%s`",
+ cfg->g_config.c_description);
+ if (asprintf(&LOCAL_CHASSIS(cfg)->c_descr, "%s",
+ cfg->g_config.c_description) == -1)
+ fatal("localchassis", "failed to set full system description");
+ } else {
+ if (cfg->g_config.c_advertise_version) {
+ log_debug("localchassis", "advertise system version");
+ if (asprintf(&LOCAL_CHASSIS(cfg)->c_descr, "%s %s %s %s %s",
+ cfg->g_lsb_release ? cfg->g_lsb_release : "",
+ un.sysname, un.release, un.version, un.machine) == -1)
+ fatal("localchassis",
+ "failed to set full system description");
+ } else {
+ log_debug("localchassis", "do not advertise system version");
+ if (asprintf(&LOCAL_CHASSIS(cfg)->c_descr, "%s",
+ cfg->g_lsb_release ? cfg->g_lsb_release : un.sysname) ==
+ -1)
+ fatal("localchassis",
+ "failed to set minimal system description");
+ }
+ }
+ if (cfg->g_config.c_platform == NULL)
+ cfg->g_config.c_platform = strdup(un.sysname);
+
+ if (!cfg->g_config.c_cap_override) {
+ /* Check routing */
+ if (lldpd_routing_enabled(cfg)) {
+ log_debug("localchassis",
+ "routing is enabled, enable router capability");
+ LOCAL_CHASSIS(cfg)->c_cap_enabled |= LLDP_CAP_ROUTER;
+ } else
+ LOCAL_CHASSIS(cfg)->c_cap_enabled &= ~LLDP_CAP_ROUTER;
+
+#ifdef ENABLE_LLDPMED
+ if (LOCAL_CHASSIS(cfg)->c_cap_available & LLDP_CAP_TELEPHONE)
+ LOCAL_CHASSIS(cfg)->c_cap_enabled |= LLDP_CAP_TELEPHONE;
+ lldpd_med(cfg, &un);
+#endif
+ if ((LOCAL_CHASSIS(cfg)->c_cap_available & LLDP_CAP_STATION) &&
+ (LOCAL_CHASSIS(cfg)->c_cap_enabled == 0))
+ LOCAL_CHASSIS(cfg)->c_cap_enabled = LLDP_CAP_STATION;
+ else if (LOCAL_CHASSIS(cfg)->c_cap_enabled != LLDP_CAP_STATION)
+ LOCAL_CHASSIS(cfg)->c_cap_enabled &= ~LLDP_CAP_STATION;
+ }
+
+ /* Set chassis ID if needed. This is only done if chassis ID
+ has not been set previously (with the MAC address of an
+ interface for example)
+ */
+ if (cfg->g_config.c_cid_string != NULL) {
+ log_debug("localchassis", "use specified chassis ID string");
+ free(LOCAL_CHASSIS(cfg)->c_id);
+ if (!(LOCAL_CHASSIS(cfg)->c_id = strdup(cfg->g_config.c_cid_string)))
+ fatal("localchassis", NULL);
+ LOCAL_CHASSIS(cfg)->c_id_len = strlen(cfg->g_config.c_cid_string);
+ LOCAL_CHASSIS(cfg)->c_id_subtype = LLDP_CHASSISID_SUBTYPE_LOCAL;
+ }
+ if (LOCAL_CHASSIS(cfg)->c_id == NULL) {
+ log_debug("localchassis",
+ "no chassis ID is currently set, use chassis name");
+ if (!(LOCAL_CHASSIS(cfg)->c_id = strdup(LOCAL_CHASSIS(cfg)->c_name)))
+ fatal("localchassis", NULL);
+ LOCAL_CHASSIS(cfg)->c_id_len = strlen(LOCAL_CHASSIS(cfg)->c_name);
+ LOCAL_CHASSIS(cfg)->c_id_subtype = LLDP_CHASSISID_SUBTYPE_LOCAL;
+ }
+}
+
+void
+lldpd_update_localports(struct lldpd *cfg)
+{
+ struct lldpd_hardware *hardware;
+
+ log_debug("localchassis", "update information for local ports");
+
+ /* h_flags is set to 0 for each port. If the port is updated, h_flags
+ * will be set to a non-zero value. This will allow us to clean up any
+ * non up-to-date port */
+ TAILQ_FOREACH (hardware, &cfg->g_hardware, h_entries)
+ hardware->h_flags = 0;
+
+ TRACE(LLDPD_INTERFACES_UPDATE());
+ interfaces_update(cfg);
+ lldpd_cleanup(cfg);
+ lldpd_reset_timer(cfg);
+}
+
+void
+lldpd_loop(struct lldpd *cfg)
+{
+ /* Main loop.
+ 1. Update local ports information
+ 2. Update local chassis information
+ */
+ log_debug("loop", "start new loop");
+ if (!cfg->g_config.c_cap_override) LOCAL_CHASSIS(cfg)->c_cap_enabled = 0;
+ /* Information for local ports is triggered even when it is possible to
+ * update them on some other event because we want to refresh them if we
+ * missed something. */
+ log_debug("loop", "update information for local ports");
+ lldpd_update_localports(cfg);
+ log_debug("loop", "update information for local chassis");
+ lldpd_update_localchassis(cfg);
+ lldpd_count_neighbors(cfg);
+}
+
+static void
+lldpd_exit(struct lldpd *cfg)
+{
+ char *lockname = NULL;
+ struct lldpd_hardware *hardware, *hardware_next;
+ log_debug("main", "exit lldpd");
+
+ TAILQ_FOREACH (hardware, &cfg->g_hardware, h_entries)
+ lldpd_send_shutdown(hardware);
+
+ if (asprintf(&lockname, "%s.lock", cfg->g_ctlname) != -1) {
+ priv_ctl_cleanup(lockname);
+ free(lockname);
+ }
+ close(cfg->g_ctl);
+ priv_ctl_cleanup(cfg->g_ctlname);
+ log_debug("main", "cleanup hardware information");
+ for (hardware = TAILQ_FIRST(&cfg->g_hardware); hardware != NULL;
+ hardware = hardware_next) {
+ hardware_next = TAILQ_NEXT(hardware, h_entries);
+ log_debug("main", "cleanup interface %s", hardware->h_ifname);
+ lldpd_remote_cleanup(hardware, NULL, 1);
+ lldpd_hardware_cleanup(cfg, hardware);
+ }
+ interfaces_cleanup(cfg);
+ lldpd_port_cleanup(cfg->g_default_local_port, 1);
+ lldpd_all_chassis_cleanup(cfg);
+ free(cfg->g_default_local_port);
+ free(cfg->g_config.c_platform);
+ levent_shutdown(cfg);
+}
+
+/**
+ * Run lldpcli to configure lldpd.
+ *
+ * @return PID of running lldpcli or -1 if error.
+ */
+static pid_t
+lldpd_configure(int use_syslog, int debug, const char *path, const char *ctlname,
+ const char *config_path)
+{
+ pid_t lldpcli = vfork();
+ int devnull;
+
+ char sdebug[debug + 4];
+ if (use_syslog)
+ strlcpy(sdebug, "-s", 3);
+ else {
+ /* debug = 0 -> -sd */
+ /* debug = 1 -> -sdd */
+ /* debug = 2 -> -sddd */
+ memset(sdebug, 'd', sizeof(sdebug));
+ sdebug[debug + 3] = '\0';
+ sdebug[0] = '-';
+ sdebug[1] = 's';
+ }
+ log_debug("main", "invoke %s %s", path, sdebug);
+
+ switch (lldpcli) {
+ case -1:
+ log_warn("main", "unable to fork");
+ return -1;
+ case 0:
+ /* Child, exec lldpcli */
+ if ((devnull = open("/dev/null", O_RDWR, 0)) != -1) {
+ dup2(devnull, STDIN_FILENO);
+ dup2(devnull, STDOUT_FILENO);
+ if (devnull > 2) close(devnull);
+
+ if (config_path) {
+ execl(path, "lldpcli", sdebug, "-u", ctlname, "-C",
+ config_path, "resume", (char *)NULL);
+ } else {
+ execl(path, "lldpcli", sdebug, "-u", ctlname, "-C",
+ SYSCONFDIR "/lldpd.conf", "-C",
+ SYSCONFDIR "/lldpd.d", "resume", (char *)NULL);
+ }
+
+ log_warn("main", "unable to execute %s", path);
+ log_warnx("main",
+ "configuration is incomplete, lldpd needs to be unpaused");
+ }
+ _exit(127);
+ break;
+ default:
+ /* Father, don't do anything stupid */
+ return lldpcli;
+ }
+ /* Should not be here */
+ return -1;
+}
+
+struct intint {
+ int a;
+ int b;
+};
+static const struct intint filters[] = { { 0, 0 },
+ { 1,
+ SMART_INCOMING_FILTER | SMART_INCOMING_ONE_PROTO | SMART_OUTGOING_FILTER |
+ SMART_OUTGOING_ONE_PROTO },
+ { 2, SMART_INCOMING_FILTER | SMART_INCOMING_ONE_PROTO },
+ { 3, SMART_OUTGOING_FILTER | SMART_OUTGOING_ONE_PROTO },
+ { 4, SMART_INCOMING_FILTER | SMART_OUTGOING_FILTER },
+ { 5, SMART_INCOMING_FILTER }, { 6, SMART_OUTGOING_FILTER },
+ { 7,
+ SMART_INCOMING_FILTER | SMART_INCOMING_ONE_PROTO |
+ SMART_INCOMING_ONE_NEIGH | SMART_OUTGOING_FILTER |
+ SMART_OUTGOING_ONE_PROTO },
+ { 8,
+ SMART_INCOMING_FILTER | SMART_INCOMING_ONE_PROTO |
+ SMART_INCOMING_ONE_NEIGH },
+ { 9,
+ SMART_INCOMING_FILTER | SMART_INCOMING_ONE_NEIGH | SMART_OUTGOING_FILTER |
+ SMART_OUTGOING_ONE_PROTO },
+ { 10, SMART_OUTGOING_FILTER | SMART_OUTGOING_ONE_NEIGH },
+ { 11, SMART_INCOMING_FILTER | SMART_INCOMING_ONE_NEIGH },
+ { 12,
+ SMART_INCOMING_FILTER | SMART_INCOMING_ONE_NEIGH | SMART_OUTGOING_FILTER |
+ SMART_OUTGOING_ONE_NEIGH },
+ { 13,
+ SMART_INCOMING_FILTER | SMART_INCOMING_ONE_NEIGH | SMART_OUTGOING_FILTER },
+ { 14,
+ SMART_INCOMING_FILTER | SMART_INCOMING_ONE_PROTO | SMART_OUTGOING_FILTER |
+ SMART_OUTGOING_ONE_NEIGH },
+ { 15,
+ SMART_INCOMING_FILTER | SMART_INCOMING_ONE_PROTO | SMART_OUTGOING_FILTER },
+ { 16,
+ SMART_INCOMING_FILTER | SMART_INCOMING_ONE_PROTO |
+ SMART_INCOMING_ONE_NEIGH | SMART_OUTGOING_FILTER |
+ SMART_OUTGOING_ONE_NEIGH },
+ { 17,
+ SMART_INCOMING_FILTER | SMART_INCOMING_ONE_PROTO |
+ SMART_INCOMING_ONE_NEIGH | SMART_OUTGOING_FILTER },
+ { 18,
+ SMART_INCOMING_FILTER | SMART_OUTGOING_FILTER | SMART_OUTGOING_ONE_NEIGH },
+ { 19,
+ SMART_INCOMING_FILTER | SMART_OUTGOING_FILTER | SMART_OUTGOING_ONE_PROTO },
+ { -1, 0 } };
+
+#ifndef HOST_OS_OSX
+/**
+ * Tell if we have been started by systemd.
+ */
+static int
+lldpd_started_by_systemd()
+{
+# ifdef HOST_OS_LINUX
+ int fd = -1;
+ const char *notifysocket = getenv("NOTIFY_SOCKET");
+ if (!notifysocket || !strchr("@/", notifysocket[0]) || strlen(notifysocket) < 2)
+ return 0;
+
+ log_debug("main", "running with systemd, don't fork but signal ready");
+ if ((fd = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) {
+ log_warn("main", "unable to open systemd notification socket %s",
+ notifysocket);
+ return 0;
+ }
+
+ struct sockaddr_un su = { .sun_family = AF_UNIX };
+ strlcpy(su.sun_path, notifysocket, sizeof(su.sun_path));
+ if (notifysocket[0] == '@') su.sun_path[0] = 0;
+
+ char ready[] = "READY=1";
+ struct iovec iov = { .iov_base = ready, .iov_len = sizeof ready - 1 };
+ struct msghdr hdr = { .msg_name = &su,
+ .msg_namelen =
+ offsetof(struct sockaddr_un, sun_path) + strlen(notifysocket),
+ .msg_iov = &iov,
+ .msg_iovlen = 1 };
+ unsetenv("NOTIFY_SOCKET");
+ if (sendmsg(fd, &hdr, MSG_NOSIGNAL) < 0) {
+ log_warn("main", "unable to send notification to systemd");
+ close(fd);
+ return 0;
+ }
+ close(fd);
+ return 1;
+# else
+ return 0;
+# endif
+}
+#endif
+
+#ifdef HOST_OS_LINUX
+static void
+version_convert(const char *sversion, unsigned iversion[], size_t n)
+{
+ const char *p = sversion;
+ char *end;
+ for (size_t i = 0; i < n; i++) {
+ iversion[i] = strtol(p, &end, 10);
+ if (*end != '.') break;
+ p = end + 1;
+ }
+}
+
+static void
+version_check(void)
+{
+ struct utsname uts;
+ if (uname(&uts) == -1) return;
+ unsigned version_min[3] = {};
+ unsigned version_cur[3] = {};
+ version_convert(uts.release, version_cur, 3);
+ version_convert(MIN_LINUX_KERNEL_VERSION, version_min, 3);
+ if (version_min[0] > version_cur[0] ||
+ (version_min[0] == version_cur[0] && version_min[1] > version_cur[1]) ||
+ (version_min[0] == version_cur[0] && version_min[1] == version_cur[1] &&
+ version_min[2] > version_cur[2])) {
+ log_warnx("lldpd", "minimal kernel version required is %s, got %s",
+ MIN_LINUX_KERNEL_VERSION, uts.release);
+ log_warnx("lldpd",
+ "lldpd may be unable to detect bonds and bridges correctly");
+# ifndef ENABLE_OLDIES
+ log_warnx("lldpd", "consider recompiling with --enable-oldies option");
+# endif
+ }
+}
+#else
+static void
+version_check(void)
+{
+}
+#endif
+
+int
+lldpd_main(int argc, char *argv[], char *envp[])
+{
+ struct lldpd *cfg;
+ struct lldpd_chassis *lchassis;
+ int ch, debug = 0, use_syslog = 1, daemonize = 1;
+ const char *errstr;
+#ifdef USE_SNMP
+ int snmp = 0;
+ const char *agentx = NULL; /* AgentX socket */
+#endif
+ const char *ctlname = NULL;
+ char *mgmtp = NULL;
+ char *cidp = NULL;
+ char *interfaces = NULL;
+ /* We do not want more options here. Please add them in lldpcli instead
+ * unless there is a very good reason. Most command-line options will
+ * get deprecated at some point. */
+ char *popt,
+ opts[] = "H:vhkrdD:p:xX:m:u:4:6:I:C:p:M:P:S:iL:O:@ ";
+ int i, found, advertise_version = 1;
+#ifdef ENABLE_LLDPMED
+ int lldpmed = 0, noinventory = 0;
+ int enable_fast_start = 1;
+#endif
+ char *descr_override = NULL;
+ char *platform_override = NULL;
+ char *lsb_release = NULL;
+ const char *lldpcli = LLDPCLI_PATH;
+ const char *pidfile = LLDPD_PID_FILE;
+ int smart = 15;
+ int receiveonly = 0, version = 0;
+ int ctl;
+ const char *config_file = NULL;
+
+#ifdef ENABLE_PRIVSEP
+ /* Non privileged user */
+ struct passwd *user;
+ struct group *group;
+ uid_t uid;
+ gid_t gid;
+#endif
+
+ saved_argv = argv;
+
+#if HAVE_SETPROCTITLE_INIT
+ setproctitle_init(argc, argv, envp);
+#endif
+
+ /*
+ * Get and parse command line options
+ */
+ if ((popt = strchr(opts, '@')) != NULL) {
+ for (i = 0; protos[i].mode != 0 && *popt != '\0'; i++)
+ *(popt++) = protos[i].arg;
+ *popt = '\0';
+ }
+ while ((ch = getopt(argc, argv, opts)) != -1) {
+ switch (ch) {
+ case 'h':
+ usage();
+ break;
+ case 'v':
+ version++;
+ break;
+ case 'd':
+ if (daemonize)
+ daemonize = 0;
+ else if (use_syslog)
+ use_syslog = 0;
+ else
+ debug++;
+ break;
+ case 'D':
+ log_accept(optarg);
+ break;
+ case 'p':
+ pidfile = optarg;
+ break;
+ case 'r':
+ receiveonly = 1;
+ break;
+ case 'm':
+ if (mgmtp) {
+ fprintf(stderr, "-m can only be used once\n");
+ usage();
+ }
+ mgmtp = strdup(optarg);
+ break;
+ case 'u':
+ if (ctlname) {
+ fprintf(stderr, "-u can only be used once\n");
+ usage();
+ }
+ ctlname = optarg;
+ break;
+ case 'I':
+ if (interfaces) {
+ fprintf(stderr, "-I can only be used once\n");
+ usage();
+ }
+ interfaces = strdup(optarg);
+ break;
+ case 'C':
+ if (cidp) {
+ fprintf(stderr, "-C can only be used once\n");
+ usage();
+ }
+ cidp = strdup(optarg);
+ break;
+ case 'L':
+ if (strlen(optarg))
+ lldpcli = optarg;
+ else
+ lldpcli = NULL;
+ break;
+ case 'k':
+ advertise_version = 0;
+ break;
+#ifdef ENABLE_LLDPMED
+ case 'M':
+ lldpmed = strtonum(optarg, 1, 4, &errstr);
+ if (errstr) {
+ fprintf(stderr,
+ "-M requires an argument between 1 and 4\n");
+ usage();
+ }
+ break;
+ case 'i':
+ noinventory = 1;
+ break;
+#else
+ case 'M':
+ case 'i':
+ fprintf(stderr, "LLDP-MED support is not built-in\n");
+ usage();
+ break;
+#endif
+#ifdef USE_SNMP
+ case 'x':
+ snmp = 1;
+ break;
+ case 'X':
+ if (agentx) {
+ fprintf(stderr, "-X can only be used once\n");
+ usage();
+ }
+ snmp = 1;
+ agentx = optarg;
+ break;
+#else
+ case 'x':
+ case 'X':
+ fprintf(stderr, "SNMP support is not built-in\n");
+ usage();
+#endif
+ break;
+ case 'S':
+ if (descr_override) {
+ fprintf(stderr, "-S can only be used once\n");
+ usage();
+ }
+ descr_override = strdup(optarg);
+ break;
+ case 'P':
+ if (platform_override) {
+ fprintf(stderr, "-P can only be used once\n");
+ usage();
+ }
+ platform_override = strdup(optarg);
+ break;
+ case 'H':
+ smart = strtonum(optarg, 0,
+ sizeof(filters) / sizeof(filters[0]), &errstr);
+ if (errstr) {
+ fprintf(stderr,
+ "-H requires an int between 0 and %zu\n",
+ sizeof(filters) / sizeof(filters[0]));
+ usage();
+ }
+ break;
+ case 'O':
+ if (config_file) {
+ fprintf(stderr, "-O can only be used once\n");
+ usage();
+ }
+ config_file = optarg;
+ break;
+ default:
+ found = 0;
+ for (i = 0; protos[i].mode != 0; i++) {
+ if (ch == protos[i].arg) {
+ found = 1;
+ protos[i].enabled++;
+ }
+ }
+ if (!found) usage();
+ }
+ }
+
+ if (version) {
+ version_display(stdout, "lldpd", version > 1);
+ exit(0);
+ }
+
+ if (ctlname == NULL) ctlname = LLDPD_CTL_SOCKET;
+
+ /* Set correct smart mode */
+ for (i = 0; (filters[i].a != -1) && (filters[i].a != smart); i++)
+ ;
+ if (filters[i].a == -1) {
+ fprintf(stderr, "Incorrect mode for -H\n");
+ usage();
+ }
+ smart = filters[i].b;
+
+ log_init(use_syslog, debug, __progname);
+ tzset(); /* Get timezone info before chroot */
+ if (use_syslog && daemonize) {
+ /* So, we use syslog and we daemonize (or we are started by
+ * systemd). No need to continue writing to stdout. */
+ int fd;
+ /* coverity[resource_leak]
+ fd may be leaked if < 2, it's expected */
+ if ((fd = open("/dev/null", O_RDWR, 0)) != -1) {
+ dup2(fd, STDIN_FILENO);
+ dup2(fd, STDOUT_FILENO);
+ dup2(fd, STDERR_FILENO);
+ if (fd > 2) close(fd);
+ }
+ }
+ log_debug("main", "lldpd " PACKAGE_VERSION " starting...");
+ version_check();
+#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
+ fatalx("main", "fuzzing enabled, unsafe for production");
+#endif
+
+ /* Grab uid and gid to use for priv sep */
+#ifdef ENABLE_PRIVSEP
+ if ((user = getpwnam(PRIVSEP_USER)) == NULL)
+ fatalx("main",
+ "no " PRIVSEP_USER
+ " user for privilege separation, please create it");
+ uid = user->pw_uid;
+ if ((group = getgrnam(PRIVSEP_GROUP)) == NULL)
+ fatalx("main",
+ "no " PRIVSEP_GROUP
+ " group for privilege separation, please create it");
+ gid = group->gr_gid;
+#endif
+
+ /* Create and setup socket */
+ int retry = 1;
+ log_debug("main", "creating control socket");
+ while ((ctl = ctl_create(ctlname)) == -1) {
+ if (retry-- && errno == EADDRINUSE) {
+ /* Check if a daemon is really listening */
+ int tfd;
+ log_info("main",
+ "unable to create control socket because it already exists");
+ log_info("main", "check if another instance is running");
+ if ((tfd = ctl_connect(ctlname)) != -1) {
+ /* Another instance is running */
+ close(tfd);
+ log_warnx("main",
+ "another instance is running, please stop it");
+ fatalx("main", "giving up");
+ } else if (errno == ECONNREFUSED) {
+ /* Nobody is listening */
+ log_info("main",
+ "old control socket is present, clean it");
+ ctl_cleanup(ctlname);
+ continue;
+ }
+ log_warn("main",
+ "cannot determine if another daemon is already running");
+ fatalx("main", "giving up");
+ }
+ log_warn("main", "unable to create control socket at %s", ctlname);
+ fatalx("main", "giving up");
+ }
+#ifdef ENABLE_PRIVSEP
+ if (chown(ctlname, uid, gid) == -1)
+ log_warn("main", "unable to chown control socket");
+ if (chmod(ctlname, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP) ==
+ -1)
+ log_warn("main", "unable to chmod control socket");
+#endif
+
+ /* Create associated advisory lock file */
+ char *lockname = NULL;
+ int fd;
+ if (asprintf(&lockname, "%s.lock", ctlname) == -1)
+ fatal("main", "cannot build lock name");
+ if ((fd = open(lockname, O_CREAT | O_RDWR, 0000)) == -1)
+ fatal("main", "cannot create lock file for control socket");
+ close(fd);
+#ifdef ENABLE_PRIVSEP
+ if (chown(lockname, uid, gid) == -1)
+ log_warn("main", "unable to chown control socket lock");
+ if (chmod(lockname,
+ S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP) == -1)
+ log_warn("main", "unable to chmod control socket lock");
+#endif
+ free(lockname);
+
+ /* Disable SIGPIPE */
+ signal(SIGPIPE, SIG_IGN);
+
+ /* Disable SIGHUP, until handlers are installed */
+ signal(SIGHUP, SIG_IGN);
+
+ /* Daemonization, unless started by systemd or launchd or debug */
+#ifndef HOST_OS_OSX
+ if (!lldpd_started_by_systemd() && daemonize) {
+ int pid;
+ char *spid;
+ log_debug("main", "going into background");
+ if (daemon(0, 1) != 0) fatal("main", "failed to detach daemon");
+ if ((pid = open(pidfile, O_TRUNC | O_CREAT | O_WRONLY, 0666)) == -1)
+ fatal("main",
+ "unable to open pid file " LLDPD_PID_FILE
+ " (or the specified one)");
+ if (asprintf(&spid, "%d\n", getpid()) == -1)
+ fatal("main",
+ "unable to create pid file " LLDPD_PID_FILE
+ " (or the specified one)");
+ if (write(pid, spid, strlen(spid)) == -1)
+ fatal("main",
+ "unable to write pid file " LLDPD_PID_FILE
+ " (or the specified one)");
+ free(spid);
+ close(pid);
+ }
+#endif
+
+ /* Configuration with lldpcli */
+ if (lldpcli) {
+ if (!config_file) {
+ log_debug("main",
+ "invoking lldpcli for default configuration locations");
+ } else {
+ log_debug("main",
+ "invoking lldpcli for user supplied configuration location");
+ }
+ if (lldpd_configure(use_syslog, debug, lldpcli, ctlname, config_file) ==
+ -1)
+ fatal("main", "unable to spawn lldpcli");
+ }
+
+ /* Try to read system information from /etc/os-release if possible.
+ Fall back to lsb_release for compatibility. */
+ log_debug("main", "get OS/LSB release information");
+ lsb_release = lldpd_get_os_release();
+ if (!lsb_release) {
+ lsb_release = lldpd_get_lsb_release();
+ }
+
+ log_debug("main", "initialize privilege separation");
+#ifdef ENABLE_PRIVSEP
+ priv_init(PRIVSEP_CHROOT, ctl, uid, gid);
+#else
+ priv_init();
+#endif
+
+ /* Initialization of global configuration */
+ if ((cfg = (struct lldpd *)calloc(1, sizeof(struct lldpd))) == NULL)
+ fatal("main", NULL);
+
+ lldpd_alloc_default_local_port(cfg);
+ cfg->g_ctlname = ctlname;
+ cfg->g_ctl = ctl;
+ cfg->g_config.c_mgmt_pattern = mgmtp;
+ cfg->g_config.c_cid_pattern = cidp;
+ cfg->g_config.c_iface_pattern = interfaces;
+ cfg->g_config.c_smart = smart;
+ if (lldpcli) cfg->g_config.c_paused = 1;
+ cfg->g_config.c_receiveonly = receiveonly;
+ cfg->g_config.c_tx_interval = LLDPD_TX_INTERVAL * 1000;
+ cfg->g_config.c_tx_hold = LLDPD_TX_HOLD;
+ cfg->g_config.c_ttl = cfg->g_config.c_tx_interval * cfg->g_config.c_tx_hold;
+ cfg->g_config.c_ttl = (cfg->g_config.c_ttl + 999) / 1000;
+ cfg->g_config.c_max_neighbors = LLDPD_MAX_NEIGHBORS;
+#ifdef ENABLE_LLDPMED
+ cfg->g_config.c_enable_fast_start = enable_fast_start;
+ cfg->g_config.c_tx_fast_init = LLDPD_FAST_INIT;
+ cfg->g_config.c_tx_fast_interval = LLDPD_FAST_TX_INTERVAL;
+#endif
+#ifdef USE_SNMP
+ cfg->g_snmp = snmp;
+ cfg->g_snmp_agentx = agentx;
+#endif /* USE_SNMP */
+ cfg->g_config.c_bond_slave_src_mac_type =
+ LLDP_BOND_SLAVE_SRC_MAC_TYPE_LOCALLY_ADMINISTERED;
+
+ /* Get ioctl socket */
+ log_debug("main", "get an ioctl socket");
+ if ((cfg->g_sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
+ fatal("main", "failed to get ioctl socket");
+
+ /* Description */
+ if (!(cfg->g_config.c_advertise_version = advertise_version) && lsb_release &&
+ lsb_release[strlen(lsb_release) - 1] == '\n')
+ lsb_release[strlen(lsb_release) - 1] = '\0';
+ cfg->g_lsb_release = lsb_release;
+ if (descr_override) cfg->g_config.c_description = descr_override;
+
+ if (platform_override) cfg->g_config.c_platform = platform_override;
+
+ /* Set system capabilities */
+ log_debug("main", "set system capabilities");
+ if ((lchassis = (struct lldpd_chassis *)calloc(1,
+ sizeof(struct lldpd_chassis))) == NULL)
+ fatal("localchassis", NULL);
+ cfg->g_config.c_cap_advertise = 1;
+ cfg->g_config.c_cap_override = 0;
+ lchassis->c_cap_available =
+ LLDP_CAP_BRIDGE | LLDP_CAP_WLAN | LLDP_CAP_ROUTER | LLDP_CAP_STATION;
+ cfg->g_config.c_mgmt_advertise = 1;
+ TAILQ_INIT(&lchassis->c_mgmt);
+#ifdef ENABLE_LLDPMED
+ if (lldpmed > 0) {
+ if (lldpmed == LLDP_MED_CLASS_III)
+ lchassis->c_cap_available |= LLDP_CAP_TELEPHONE;
+ lchassis->c_med_type = lldpmed;
+ lchassis->c_med_cap_available = LLDP_MED_CAP_CAP | LLDP_MED_CAP_IV |
+ LLDP_MED_CAP_LOCATION | LLDP_MED_CAP_POLICY | LLDP_MED_CAP_MDI_PSE |
+ LLDP_MED_CAP_MDI_PD;
+ cfg->g_config.c_noinventory = noinventory;
+ } else
+ cfg->g_config.c_noinventory = 1;
+#endif
+
+ log_debug("main", "initialize protocols");
+ cfg->g_protocols = protos;
+ for (i = 0; protos[i].mode != 0; i++) {
+
+ /* With -ll, disable LLDP */
+ if (protos[i].mode == LLDPD_MODE_LLDP) protos[i].enabled %= 3;
+ /* With -ccc force CDPV2, enable CDPV1 */
+ if (protos[i].mode == LLDPD_MODE_CDPV1 && protos[i].enabled == 3) {
+ protos[i].enabled = 1;
+ }
+ /* With -cc force CDPV1, enable CDPV2 */
+ if (protos[i].mode == LLDPD_MODE_CDPV2 && protos[i].enabled == 2) {
+ protos[i].enabled = 1;
+ }
+
+ /* With -cccc disable CDPV1, enable CDPV2 */
+ if (protos[i].mode == LLDPD_MODE_CDPV1 && protos[i].enabled >= 4) {
+ protos[i].enabled = 0;
+ }
+
+ /* With -cccc disable CDPV1, enable CDPV2; -ccccc will force CDPv2 */
+ if (protos[i].mode == LLDPD_MODE_CDPV2 && protos[i].enabled == 4) {
+ protos[i].enabled = 1;
+ }
+
+ if (protos[i].enabled > 1)
+ log_info("main", "protocol %s enabled and forced",
+ protos[i].name);
+ else if (protos[i].enabled)
+ log_info("main", "protocol %s enabled", protos[i].name);
+ else
+ log_info("main", "protocol %s disabled", protos[i].name);
+ }
+
+ TAILQ_INIT(&cfg->g_hardware);
+ TAILQ_INIT(&cfg->g_chassis);
+ TAILQ_INSERT_TAIL(&cfg->g_chassis, lchassis, c_entries);
+ lchassis->c_refcount++; /* We should always keep a reference to local chassis */
+
+ /* Main loop */
+ log_debug("main", "start main loop");
+ levent_loop(cfg);
+ lchassis->c_refcount--;
+ lldpd_exit(cfg);
+ free(cfg);
+
+ return (0);
+}
diff --git a/src/daemon/lldpd.h b/src/daemon/lldpd.h
new file mode 100644
index 0000000..2fc381b
--- /dev/null
+++ b/src/daemon/lldpd.h
@@ -0,0 +1,429 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2008 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _LLDPD_H
+#define _LLDPD_H
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#ifdef HAVE_VALGRIND_VALGRIND_H
+# include <valgrind/valgrind.h>
+#else
+# define RUNNING_ON_VALGRIND 0
+#endif
+
+#include <stdlib.h>
+#include <stddef.h>
+#include <string.h>
+#include <sys/queue.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <net/if_arp.h>
+#include <netinet/if_ether.h>
+#include <sys/un.h>
+
+#include "lldp-tlv.h"
+#if defined ENABLE_CDP || defined ENABLE_FDP
+# include "protocols/cdp.h"
+#endif
+#ifdef ENABLE_SONMP
+# include "protocols/sonmp.h"
+#endif
+#ifdef ENABLE_EDP
+# include "protocols/edp.h"
+#endif
+
+#include "../compat/compat.h"
+#include "../marshal.h"
+#include "../log.h"
+#include "../ctl.h"
+#include "../lldpd-structs.h"
+
+/* We don't want to import event2/event.h. We only need those as
+ opaque structs. */
+struct event;
+struct event_base;
+
+#define PROCFS_SYS_NET "/proc/sys/net/"
+#define SYSFS_CLASS_NET "/sys/class/net/"
+#define SYSFS_CLASS_DMI "/sys/class/dmi/id/"
+#define LLDPD_TX_INTERVAL 30
+#define LLDPD_TX_HOLD 4
+#define LLDPD_TTL LLDPD_TX_INTERVAL *LLDPD_TX_HOLD
+#define LLDPD_TX_MSGDELAY 1
+#define LLDPD_MAX_NEIGHBORS 32
+#define LLDPD_FAST_TX_INTERVAL 1
+#define LLDPD_FAST_INIT 4
+
+#define USING_AGENTX_SUBAGENT_MODULE 1
+
+#define PROTO_SEND_SIG struct lldpd *, struct lldpd_hardware *
+#define PROTO_DECODE_SIG \
+ struct lldpd *, char *, int, struct lldpd_hardware *, struct lldpd_chassis **, \
+ struct lldpd_port **
+#define PROTO_GUESS_SIG char *, int
+
+#define ALIGNED_CAST(TYPE, ATTR) ((TYPE)(void *)(ATTR))
+
+struct protocol {
+ int mode; /* > 0 mode identifier (unique per protocol) */
+ int enabled; /* Is this protocol enabled? */
+ const char *name; /* Name of protocol */
+ char arg; /* Argument to enable this protocol */
+ int (*send)(PROTO_SEND_SIG); /* How to send a frame */
+ int (*decode)(PROTO_DECODE_SIG); /* How to decode a frame */
+ int (*guess)(PROTO_GUESS_SIG); /* Can be NULL, use MAC address in this case */
+ u_int8_t mac[3][ETHER_ADDR_LEN]; /* Destination MAC addresses used by this
+ protocol */
+};
+
+#define SMART_HIDDEN(port) (port->p_hidden_in)
+
+struct lldpd;
+
+/* lldpd.c */
+struct lldpd_hardware *lldpd_get_hardware(struct lldpd *, char *, int);
+struct lldpd_hardware *lldpd_alloc_hardware(struct lldpd *, char *, int);
+void lldpd_hardware_cleanup(struct lldpd *, struct lldpd_hardware *);
+struct lldpd_mgmt *lldpd_alloc_mgmt(int family, void *addr, size_t addrsize,
+ u_int32_t iface);
+void lldpd_recv(struct lldpd *, struct lldpd_hardware *, int);
+void lldpd_send(struct lldpd_hardware *);
+void lldpd_loop(struct lldpd *);
+int lldpd_main(int, char **, char **);
+void lldpd_update_localports(struct lldpd *);
+void lldpd_update_localchassis(struct lldpd *);
+void lldpd_cleanup(struct lldpd *);
+
+/* frame.c */
+u_int16_t frame_checksum(const u_int8_t *, int, int);
+
+/* event.c */
+void levent_loop(struct lldpd *);
+void levent_shutdown(struct lldpd *);
+void levent_hardware_init(struct lldpd_hardware *);
+void levent_hardware_add_fd(struct lldpd_hardware *, int);
+void levent_hardware_release(struct lldpd_hardware *);
+void levent_ctl_notify(char *, int, struct lldpd_port *);
+void levent_send_now(struct lldpd *);
+void levent_update_now(struct lldpd *);
+int levent_iface_subscribe(struct lldpd *, int);
+void levent_schedule_pdu(struct lldpd_hardware *);
+void levent_schedule_cleanup(struct lldpd *);
+int levent_make_socket_nonblocking(int);
+int levent_make_socket_blocking(int);
+#ifdef HOST_OS_LINUX
+void levent_recv_error(int, const char *);
+#endif
+
+/* lldp.c */
+int lldp_send_shutdown(PROTO_SEND_SIG);
+int lldp_send(PROTO_SEND_SIG);
+int lldp_decode(PROTO_DECODE_SIG);
+
+/* cdp.c */
+#ifdef ENABLE_CDP
+int cdpv1_send(PROTO_SEND_SIG);
+int cdpv2_send(PROTO_SEND_SIG);
+int cdpv1_guess(PROTO_GUESS_SIG);
+int cdpv2_guess(PROTO_GUESS_SIG);
+#endif
+#if defined ENABLE_CDP || defined ENABLE_FDP
+int cdp_decode(PROTO_DECODE_SIG);
+#endif
+#ifdef ENABLE_FDP
+int fdp_send(PROTO_SEND_SIG);
+#endif
+
+#ifdef ENABLE_SONMP
+/* sonmp.c */
+int sonmp_send(PROTO_SEND_SIG);
+int sonmp_decode(PROTO_DECODE_SIG);
+#endif
+
+#ifdef ENABLE_EDP
+/* edp.c */
+int edp_send(PROTO_SEND_SIG);
+int edp_decode(PROTO_DECODE_SIG);
+#endif
+
+/* dmi.c */
+#ifdef ENABLE_LLDPMED
+char *dmi_hw(void);
+char *dmi_fw(void);
+char *dmi_sn(void);
+char *dmi_manuf(void);
+char *dmi_model(void);
+char *dmi_asset(void);
+#endif
+
+#ifdef USE_SNMP
+/* agent.c */
+void agent_shutdown(void);
+void agent_init(struct lldpd *, const char *);
+void agent_notify(struct lldpd_hardware *, int, struct lldpd_port *);
+#endif
+
+#ifdef ENABLE_PRIVSEP
+/* agent_priv.c */
+void agent_priv_register_domain(void);
+#endif
+
+/* client.c */
+int client_handle_client(struct lldpd *cfg,
+ ssize_t (*send)(void *, int, void *, size_t), void *, enum hmsg_type type,
+ void *buffer, size_t n, int *);
+
+/* priv.c */
+#ifdef ENABLE_PRIVSEP
+void priv_init(const char *, int, uid_t, gid_t);
+#else
+void priv_init(void);
+#endif
+void priv_wait(void);
+void priv_ctl_cleanup(const char *ctlname);
+char *priv_gethostname(void);
+#ifdef HOST_OS_LINUX
+int priv_open(const char *);
+void asroot_open(void);
+#endif
+int priv_iface_init(int, char *);
+int asroot_iface_init_os(int, char *, int *);
+int priv_iface_multicast(const char *, const u_int8_t *, int);
+int priv_iface_description(const char *, const char *);
+int asroot_iface_description_os(const char *, const char *);
+int priv_iface_promisc(const char *);
+int asroot_iface_promisc_os(const char *);
+int priv_snmp_socket(struct sockaddr_un *);
+
+enum priv_cmd {
+ PRIV_PING,
+ PRIV_DELETE_CTL_SOCKET,
+ PRIV_GET_HOSTNAME,
+ PRIV_OPEN,
+ PRIV_IFACE_INIT,
+ PRIV_IFACE_MULTICAST,
+ PRIV_IFACE_DESCRIPTION,
+ PRIV_IFACE_PROMISC,
+ PRIV_SNMP_SOCKET,
+};
+
+/* priv-seccomp.c */
+#if defined USE_SECCOMP && defined ENABLE_PRIVSEP
+int priv_seccomp_init(int, int);
+#endif
+
+/* privsep_io.c */
+enum priv_context { PRIV_PRIVILEGED, PRIV_UNPRIVILEGED };
+int may_read(enum priv_context, void *, size_t);
+void must_read(enum priv_context, void *, size_t);
+void must_write(enum priv_context, const void *, size_t);
+void priv_privileged_fd(int);
+void priv_unprivileged_fd(int);
+int priv_fd(enum priv_context);
+int receive_fd(enum priv_context);
+void send_fd(enum priv_context, int);
+
+/* interfaces-*.c */
+
+/* BPF filter to get revelant information from interfaces */
+/* LLDP: "ether proto 0x88cc and ether dst 01:80:c2:00:00:0e" */
+/* FDP: "ether dst 01:e0:52:cc:cc:cc" */
+/* CDP: "ether dst 01:00:0c:cc:cc:cc" */
+/* SONMP: "ether dst 01:00:81:00:01:00" */
+/* EDP: "ether dst 00:e0:2b:00:00:00" */
+/* For optimization purpose, we first check if the first bit of the
+ first byte is 1. if not, this can only be an EDP packet:
+
+ tcpdump -dd "(ether[0] & 1 = 1 and
+ ((ether proto 0x88cc and (ether dst 01:80:c2:00:00:0e or
+ ether dst 01:80:c2:00:00:03 or
+ ether dst 01:80:c2:00:00:00)) or
+ (ether dst 01:e0:52:cc:cc:cc) or
+ (ether dst 01:00:0c:cc:cc:cc) or
+ (ether dst 01:00:81:00:01:00))) or
+ (ether dst 00:e0:2b:00:00:00)"
+*/
+
+#ifndef ETH_P_LLDP
+# define ETH_P_LLDP 0x88cc
+#endif
+#define LLDPD_FILTER_F \
+ { 0x30, 0, 0, 0x00000000 }, { 0x54, 0, 0, 0x00000001 }, { 0x15, 0, 16, 0x00000001 }, \
+ { 0x28, 0, 0, 0x0000000c }, { 0x15, 0, 6, ETH_P_LLDP }, \
+ { 0x20, 0, 0, 0x00000002 }, { 0x15, 2, 0, 0xc200000e }, \
+ { 0x15, 1, 0, 0xc2000003 }, { 0x15, 0, 2, 0xc2000000 }, \
+ { 0x28, 0, 0, 0x00000000 }, { 0x15, 12, 13, 0x00000180 }, \
+ { 0x20, 0, 0, 0x00000002 }, { 0x15, 0, 2, 0x52cccccc }, \
+ { 0x28, 0, 0, 0x00000000 }, { 0x15, 8, 9, 0x000001e0 }, \
+ { 0x15, 1, 0, 0x0ccccccc }, { 0x15, 0, 2, 0x81000100 }, \
+ { 0x28, 0, 0, 0x00000000 }, { 0x15, 4, 5, 0x00000100 }, \
+ { 0x20, 0, 0, 0x00000002 }, { 0x15, 0, 3, 0x2b000000 }, \
+ { 0x28, 0, 0, 0x00000000 }, { 0x15, 0, 1, 0x000000e0 }, \
+ { 0x6, 0, 0, 0x00040000 }, \
+ { \
+ 0x6, 0, 0, 0x00000000 \
+ }
+
+/* This function is responsible to refresh information about interfaces. It is
+ * OS specific but should be present for each OS. It can use the functions in
+ * `interfaces.c` as helper by providing a list of OS-independent interface
+ * devices. */
+void interfaces_update(struct lldpd *);
+
+/* interfaces.c */
+/* An interface cannot be both physical and (bridge or bond or vlan) */
+#define IFACE_PHYSICAL_T (1 << 0) /* Physical interface */
+#define IFACE_BRIDGE_T (1 << 1) /* Bridge interface */
+#define IFACE_BOND_T (1 << 2) /* Bond interface */
+#define IFACE_VLAN_T (1 << 3) /* VLAN interface */
+#define IFACE_WIRELESS_T (1 << 4) /* Wireless interface */
+#define IFACE_BRIDGE_VLAN_T (1 << 5) /* Bridge-aware VLAN interface */
+
+#define MAX_VLAN 4096
+#define VLAN_BITMAP_LEN (MAX_VLAN / 32)
+struct interfaces_device {
+ TAILQ_ENTRY(interfaces_device) next;
+ int ignore; /* Ignore this interface */
+ int index; /* Index */
+ char *name; /* Name */
+ char *alias; /* Alias */
+ char *address; /* MAC address */
+ char *driver; /* Driver */
+ int flags; /* Flags (IFF_*) */
+ int mtu; /* MTU */
+ int type; /* Type (see IFACE_*_T) */
+ uint32_t vlan_bmap[VLAN_BITMAP_LEN]; /* If a VLAN, what are the VLAN ID? */
+ int pvid; /* If a VLAN, what is the default VLAN? */
+ struct interfaces_device *lower; /* Lower interface (for a VLAN for example) */
+ struct interfaces_device *upper; /* Upper interface (for a bridge or a bond) */
+
+ /* The following are OS specific. Should be static (no free function) */
+#ifdef HOST_OS_LINUX
+ int lower_idx; /* Index to lower interface */
+ int upper_idx; /* Index to upper interface */
+#endif
+};
+struct interfaces_address {
+ TAILQ_ENTRY(interfaces_address) next;
+ int index; /* Index */
+ int flags; /* Flags */
+ struct sockaddr_storage address; /* Address */
+
+ /* The following are OS specific. */
+ /* Nothing yet. */
+};
+TAILQ_HEAD(interfaces_device_list, interfaces_device);
+TAILQ_HEAD(interfaces_address_list, interfaces_address);
+void interfaces_free_device(struct interfaces_device *);
+void interfaces_free_address(struct interfaces_address *);
+void interfaces_free_devices(struct interfaces_device_list *);
+void interfaces_free_addresses(struct interfaces_address_list *);
+struct interfaces_device *interfaces_indextointerface(struct interfaces_device_list *,
+ int);
+struct interfaces_device *interfaces_nametointerface(struct interfaces_device_list *,
+ const char *);
+
+void interfaces_helper_promisc(struct lldpd *, struct lldpd_hardware *);
+void interfaces_helper_allowlist(struct lldpd *, struct interfaces_device_list *);
+void interfaces_helper_chassis(struct lldpd *, struct interfaces_device_list *);
+void interfaces_helper_add_hardware(struct lldpd *, struct lldpd_hardware *);
+void interfaces_helper_physical(struct lldpd *, struct interfaces_device_list *,
+ struct lldpd_ops *, int (*init)(struct lldpd *, struct lldpd_hardware *));
+void interfaces_helper_port_name_desc(struct lldpd *, struct lldpd_hardware *,
+ struct interfaces_device *);
+void interfaces_helper_mgmt(struct lldpd *, struct interfaces_address_list *,
+ struct interfaces_device_list *);
+#ifdef ENABLE_DOT1
+void interfaces_helper_vlan(struct lldpd *, struct interfaces_device_list *);
+#endif
+int interfaces_send_helper(struct lldpd *, struct lldpd_hardware *, char *, size_t);
+
+void interfaces_setup_multicast(struct lldpd *, const char *, int);
+int interfaces_routing_enabled(struct lldpd *);
+void interfaces_cleanup(struct lldpd *);
+
+#ifdef HOST_OS_LINUX
+/* netlink.c */
+struct interfaces_device_list *netlink_get_interfaces(struct lldpd *);
+struct interfaces_address_list *netlink_get_addresses(struct lldpd *);
+void netlink_cleanup(struct lldpd *);
+struct lldpd_netlink;
+#endif
+
+#ifndef HOST_OS_LINUX
+/* interfaces-bpf.c */
+int ifbpf_phys_init(struct lldpd *, struct lldpd_hardware *);
+#endif
+
+/* pattern.c */
+enum pattern_match_result {
+ PATTERN_MATCH_DENIED,
+ PATTERN_MATCH_ALLOWED,
+ PATTERN_MATCH_ALLOWED_EXACT
+};
+enum pattern_match_result pattern_match(char *, char *, int);
+
+/* bitmap.c */
+void bitmap_set(uint32_t *bmap, uint16_t vlan_id);
+int bitmap_isempty(uint32_t *bmap);
+unsigned int bitmap_numbits(uint32_t *bmap);
+
+struct lldpd {
+ int g_sock;
+ struct event_base *g_base;
+#ifdef USE_SNMP
+#endif
+
+ struct lldpd_config g_config;
+
+ struct protocol *g_protocols;
+ int g_lastrid;
+ struct event *g_main_loop;
+ struct event *g_cleanup_timer;
+#ifdef USE_SNMP
+ int g_snmp;
+ struct event *g_snmp_timeout;
+ void *g_snmp_fds;
+ const char *g_snmp_agentx;
+#endif /* USE_SNMP */
+
+ /* Unix socket handling */
+ const char *g_ctlname;
+ int g_ctl;
+ struct event *g_iface_event; /* Triggered when there is an interface change */
+ struct event
+ *g_iface_timer_event; /* Triggered one second after last interface change */
+ void (*g_iface_cb)(
+ struct lldpd *); /* Called when there is an interface change */
+
+ char *g_lsb_release;
+
+#ifdef HOST_OS_LINUX
+ struct lldpd_netlink *g_netlink;
+#endif
+
+ struct lldpd_port *g_default_local_port;
+#define LOCAL_CHASSIS(cfg) ((struct lldpd_chassis *)(TAILQ_FIRST(&cfg->g_chassis)))
+ TAILQ_HEAD(, lldpd_chassis) g_chassis;
+ TAILQ_HEAD(, lldpd_hardware) g_hardware;
+};
+
+#endif /* _LLDPD_H */
diff --git a/src/daemon/lldpd.service.in b/src/daemon/lldpd.service.in
new file mode 100644
index 0000000..80288a5
--- /dev/null
+++ b/src/daemon/lldpd.service.in
@@ -0,0 +1,22 @@
+[Unit]
+Description=LLDP daemon
+Documentation=man:lldpd(8)
+After=network.target
+RequiresMountsFor=@PRIVSEP_CHROOT@
+
+[Service]
+Type=notify
+NotifyAccess=main
+EnvironmentFile=-/etc/default/lldpd
+EnvironmentFile=-/etc/sysconfig/lldpd
+ExecStart=@sbindir@/lldpd $DAEMON_ARGS $LLDPD_OPTIONS
+Restart=on-failure
+PrivateTmp=yes
+ProtectHome=yes
+ProtectKernelTunables=no
+ProtectControlGroups=yes
+ProtectKernelModules=yes
+#ProtectSystem=full
+
+[Install]
+WantedBy=multi-user.target
diff --git a/src/daemon/lldpd.sysusers.conf.in b/src/daemon/lldpd.sysusers.conf.in
new file mode 100644
index 0000000..7cbf50a
--- /dev/null
+++ b/src/daemon/lldpd.sysusers.conf.in
@@ -0,0 +1,6 @@
+# System user and group for lldpd
+# @PRIVSEP_USER@:@PRIVSEP_GROUP@
+
+# Type Name ID GECOS Home
+u @PRIVSEP_USER@ - "lldpd user" @PRIVSEP_CHROOT@
+m @PRIVSEP_USER@ @PRIVSEP_GROUP@
diff --git a/src/daemon/main.c b/src/daemon/main.c
new file mode 100644
index 0000000..c2d9297
--- /dev/null
+++ b/src/daemon/main.c
@@ -0,0 +1,17 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+#include "lldpd.h"
+
+/**
+ * @mainpage
+ *
+ * lldpd is an implementation of 802.1AB (aka LLDP). It provides an interface
+ * for third party clients to interact with it: querying neighbors, setting some
+ * TLV. This interface is included into a library whose API can be found in @ref
+ * liblldpctl
+ */
+
+int
+main(int argc, char **argv, char **envp)
+{
+ return lldpd_main(argc, argv, envp);
+}
diff --git a/src/daemon/netlink.c b/src/daemon/netlink.c
new file mode 100644
index 0000000..32fee76
--- /dev/null
+++ b/src/daemon/netlink.c
@@ -0,0 +1,993 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2012 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/* Grabbing interfaces information with netlink only. */
+
+#include "lldpd.h"
+
+#include <errno.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <net/if_arp.h>
+#include <linux/netlink.h>
+#include <linux/rtnetlink.h>
+#include <linux/if_bridge.h>
+
+#define NETLINK_BUFFER 4096
+
+struct netlink_req {
+ struct nlmsghdr hdr;
+ struct ifinfomsg ifm;
+ /* attribute has to be NLMSG aligned */
+ struct rtattr ext_req __attribute__((aligned(NLMSG_ALIGNTO)));
+ __u32 ext_filter_mask;
+};
+
+struct lldpd_netlink {
+ int nl_socket_queries;
+ int nl_socket_changes;
+ int nl_socket_recv_size;
+ /* Cache */
+ struct interfaces_device_list *devices;
+ struct interfaces_address_list *addresses;
+};
+
+/**
+ * Set netlink socket buffer size.
+ *
+ * This returns the effective size on success. If the provided value is 0, this
+ * returns the current size instead. It returns -1 on system errors and -2 if
+ * the size was not changed appropriately (when reaching the max).
+ */
+static int
+netlink_socket_set_buffer_size(int s, int optname, const char *optname_str, int bufsize)
+{
+ socklen_t size = sizeof(int);
+ int got = 0;
+
+ if (bufsize > 0 &&
+ setsockopt(s, SOL_SOCKET, optname, &bufsize, sizeof(bufsize)) < 0) {
+ log_warn("netlink", "unable to set %s to '%d'", optname_str, bufsize);
+ return -1;
+ }
+
+ /* Now read them back from kernel.
+ * SO_SNDBUF & SO_RCVBUF are cap-ed at sysctl `net.core.rmem_max` &
+ * `net.core.wmem_max`. This it the easiest [probably sanest too]
+ * to validate that our socket buffers were set properly.
+ */
+ if (getsockopt(s, SOL_SOCKET, optname, &got, &size) < 0) {
+ log_warn("netlink", "unable to get %s", optname_str);
+ return -1;
+ }
+ if (bufsize > 0 && got < bufsize) {
+ log_warnx("netlink",
+ "tried to set %s to '%d' "
+ "but got '%d'",
+ optname_str, bufsize, got);
+ return -2;
+ }
+
+ return got;
+}
+
+/**
+ * Connect to netlink.
+ *
+ * Open a Netlink socket and connect to it.
+ *
+ * @param groups Which groups we want to subscribe to
+ * @return 0 on success, -1 otherwise
+ */
+static int
+netlink_connect(struct lldpd *cfg, unsigned groups)
+{
+ int s1 = -1, s2 = -1;
+ struct sockaddr_nl local = { .nl_family = AF_NETLINK,
+ .nl_pid = 0,
+ .nl_groups = groups };
+
+ /* Open Netlink socket for subscriptions */
+ log_debug("netlink", "opening netlink sockets");
+ s1 = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
+ if (s1 == -1) {
+ log_warn("netlink", "unable to open netlink socket for changes");
+ goto error;
+ }
+ if (NETLINK_SEND_BUFSIZE &&
+ netlink_socket_set_buffer_size(s1, SO_SNDBUF, "SO_SNDBUF",
+ NETLINK_SEND_BUFSIZE) == -1) {
+ log_warn("netlink", "unable to set send buffer size");
+ goto error;
+ }
+
+ int rc = netlink_socket_set_buffer_size(s1, SO_RCVBUF, "SO_RCVBUF",
+ NETLINK_RECEIVE_BUFSIZE);
+ switch (rc) {
+ case -1:
+ log_warn("netlink", "unable to set receiver buffer size");
+ goto error;
+ case -2:
+ /* Cannot set size */
+ cfg->g_netlink->nl_socket_recv_size = 0;
+ break;
+ default:
+ cfg->g_netlink->nl_socket_recv_size = rc;
+ break;
+ }
+ if (groups &&
+ bind(s1, (struct sockaddr *)&local, sizeof(struct sockaddr_nl)) < 0) {
+ log_warn("netlink", "unable to bind netlink socket");
+ goto error;
+ }
+
+ /* Opening Netlink socket to for queries */
+ s2 = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
+ if (s2 == -1) {
+ log_warn("netlink", "unable to open netlink socket for queries");
+ goto error;
+ }
+ cfg->g_netlink->nl_socket_changes = s1;
+ cfg->g_netlink->nl_socket_queries = s2;
+ return 0;
+error:
+ if (s1 != -1) close(s1);
+ if (s2 != -1) close(s2);
+ return -1;
+}
+
+/**
+ * Send a netlink message.
+ *
+ * The type of the message can be chosen as well the route family. The
+ * mesage will always be NLM_F_REQUEST | NLM_F_DUMP.
+ *
+ * @param s the netlink socket
+ * @param type the request type (eg RTM_GETLINK)
+ * @param family the rt family (eg AF_PACKET)
+ * @return 0 on success, -1 otherwise
+ */
+static int
+netlink_send(int s, int type, int family, int seq)
+{
+ struct netlink_req req = { .hdr = { .nlmsg_len =
+ NLMSG_LENGTH(sizeof(struct ifinfomsg)),
+ .nlmsg_type = type,
+ .nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP,
+ .nlmsg_seq = seq,
+ .nlmsg_pid = getpid() },
+ .ifm = { .ifi_family = family } };
+ struct iovec iov = { .iov_base = &req, .iov_len = req.hdr.nlmsg_len };
+ struct sockaddr_nl peer = { .nl_family = AF_NETLINK };
+ struct msghdr rtnl_msg = { .msg_iov = &iov,
+ .msg_iovlen = 1,
+ .msg_name = &peer,
+ .msg_namelen = sizeof(struct sockaddr_nl) };
+
+ if (family == AF_BRIDGE) {
+ unsigned int len = RTA_LENGTH(sizeof(__u32));
+ /* request bridge vlan attributes */
+ req.ext_req.rta_type = IFLA_EXT_MASK;
+ req.ext_req.rta_len = len;
+ req.ext_filter_mask = RTEXT_FILTER_BRVLAN;
+ req.hdr.nlmsg_len = NLMSG_ALIGN(req.hdr.nlmsg_len) + RTA_ALIGN(len);
+ iov.iov_len = req.hdr.nlmsg_len;
+ }
+
+ /* Send netlink message. This is synchronous but we are guaranteed
+ * to not block. */
+ log_debug("netlink", "sending netlink message");
+ if (sendmsg(s, (struct msghdr *)&rtnl_msg, 0) == -1) {
+ log_warn("netlink", "unable to send netlink message");
+ return -1;
+ }
+
+ return 0;
+}
+
+static void
+netlink_parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len)
+{
+ while (RTA_OK(rta, len)) {
+ if ((rta->rta_type <= max) && (!tb[rta->rta_type]))
+ tb[rta->rta_type] = rta;
+ rta = RTA_NEXT(rta, len);
+ }
+}
+
+/**
+ * Parse a `linkinfo` attributes.
+ *
+ * @param iff where to put the result
+ * @param rta linkinfo attribute
+ * @param len length of attributes
+ */
+static void
+netlink_parse_linkinfo(struct interfaces_device *iff, struct rtattr *rta, int len)
+{
+ struct rtattr *link_info_attrs[IFLA_INFO_MAX + 1] = {};
+ char *kind = NULL;
+ uint16_t vlan_id;
+
+ netlink_parse_rtattr(link_info_attrs, IFLA_INFO_MAX, rta, len);
+
+ if (link_info_attrs[IFLA_INFO_KIND]) {
+ kind = strdup(RTA_DATA(link_info_attrs[IFLA_INFO_KIND]));
+ if (kind) {
+ if (!strcmp(kind, "vlan")) {
+ log_debug("netlink", "interface %s is a VLAN",
+ iff->name);
+ iff->type |= IFACE_VLAN_T;
+ } else if (!strcmp(kind, "bridge")) {
+ log_debug("netlink", "interface %s is a bridge",
+ iff->name);
+ iff->type |= IFACE_BRIDGE_T;
+ } else if (!strcmp(kind, "bond")) {
+ log_debug("netlink", "interface %s is a bond",
+ iff->name);
+ iff->type |= IFACE_BOND_T;
+ } else if (!strcmp(kind, "team")) {
+ log_debug("netlink", "interface %s is a team",
+ iff->name);
+ iff->type |= IFACE_BOND_T;
+ }
+ }
+ }
+
+ if (kind && !strcmp(kind, "vlan") && link_info_attrs[IFLA_INFO_DATA]) {
+ struct rtattr *vlan_link_info_data_attrs[IFLA_VLAN_MAX + 1] = {};
+ netlink_parse_rtattr(vlan_link_info_data_attrs, IFLA_VLAN_MAX,
+ RTA_DATA(link_info_attrs[IFLA_INFO_DATA]),
+ RTA_PAYLOAD(link_info_attrs[IFLA_INFO_DATA]));
+
+ if (vlan_link_info_data_attrs[IFLA_VLAN_ID]) {
+ vlan_id = *(uint16_t *)RTA_DATA(
+ vlan_link_info_data_attrs[IFLA_VLAN_ID]);
+ bitmap_set(iff->vlan_bmap, vlan_id);
+ log_debug("netlink", "VLAN ID for interface %s is %d",
+ iff->name, vlan_id);
+ }
+ }
+
+ if (kind && !strcmp(kind, "bridge") && link_info_attrs[IFLA_INFO_DATA]) {
+ struct rtattr *bridge_link_info_data_attrs[IFLA_BR_MAX + 1] = {};
+ netlink_parse_rtattr(bridge_link_info_data_attrs, IFLA_BR_MAX,
+ RTA_DATA(link_info_attrs[IFLA_INFO_DATA]),
+ RTA_PAYLOAD(link_info_attrs[IFLA_INFO_DATA]));
+
+ if (bridge_link_info_data_attrs[IFLA_BR_VLAN_FILTERING] &&
+ *(uint8_t *)RTA_DATA(
+ bridge_link_info_data_attrs[IFLA_BR_VLAN_FILTERING]) > 0) {
+ iff->type |= IFACE_BRIDGE_VLAN_T;
+ }
+ }
+
+ free(kind);
+}
+
+/**
+ * Parse a `afspec` attributes.
+ *
+ * @param iff where to put the result
+ * @param rta afspec attribute
+ * @param len length of attributes
+ */
+static void
+netlink_parse_afspec(struct interfaces_device *iff, struct rtattr *rta, int len)
+{
+ while (RTA_OK(rta, len)) {
+ struct bridge_vlan_info *vinfo;
+ switch (rta->rta_type) {
+ case IFLA_BRIDGE_VLAN_INFO:
+ vinfo = RTA_DATA(rta);
+ log_debug("netlink", "found VLAN %d on interface %s",
+ vinfo->vid, iff->name ? iff->name : "(unknown)");
+
+ bitmap_set(iff->vlan_bmap, vinfo->vid);
+ if (vinfo->flags &
+ (BRIDGE_VLAN_INFO_PVID | BRIDGE_VLAN_INFO_UNTAGGED))
+ iff->pvid = vinfo->vid;
+ break;
+ default:
+ log_debug("netlink",
+ "unknown afspec attribute type %d for iface %s",
+ rta->rta_type, iff->name ? iff->name : "(unknown)");
+ break;
+ }
+ rta = RTA_NEXT(rta, len);
+ }
+ /* All enbridged interfaces will have VLAN 1 by default, ignore it */
+ if (iff->vlan_bmap[0] == 2 && (bitmap_numbits(iff->vlan_bmap) == 1) &&
+ iff->pvid == 1) {
+ log_debug("netlink",
+ "found only default VLAN 1 on interface %s, removing",
+ iff->name ? iff->name : "(unknown)");
+ iff->vlan_bmap[0] = iff->pvid = 0;
+ }
+}
+
+/**
+ * Parse a `link` netlink message.
+ *
+ * @param msg message to be parsed
+ * @param iff where to put the result
+ * return 0 if the interface is worth it, -1 otherwise
+ */
+static int
+netlink_parse_link(struct nlmsghdr *msg, struct interfaces_device *iff)
+{
+ struct ifinfomsg *ifi;
+ struct rtattr *attribute;
+ int len;
+ ifi = NLMSG_DATA(msg);
+ len = msg->nlmsg_len - NLMSG_LENGTH(sizeof(struct ifinfomsg));
+
+ if (ifi->ifi_type != ARPHRD_ETHER) {
+ log_debug("netlink", "skip non Ethernet interface at index %d",
+ ifi->ifi_index);
+ return -1;
+ }
+
+ iff->index = ifi->ifi_index;
+ iff->flags = ifi->ifi_flags;
+ iff->lower_idx = -1;
+ iff->upper_idx = -1;
+
+ for (attribute = IFLA_RTA(ifi); RTA_OK(attribute, len);
+ attribute = RTA_NEXT(attribute, len)) {
+ switch (attribute->rta_type) {
+ case IFLA_IFNAME:
+ /* Interface name */
+ iff->name = strdup(RTA_DATA(attribute));
+ break;
+ case IFLA_IFALIAS:
+ /* Interface alias */
+ iff->alias = strdup(RTA_DATA(attribute));
+ break;
+ case IFLA_ADDRESS:
+ /* Interface MAC address */
+ iff->address = malloc(RTA_PAYLOAD(attribute));
+ if (iff->address)
+ memcpy(iff->address, RTA_DATA(attribute),
+ RTA_PAYLOAD(attribute));
+ break;
+ case IFLA_LINK:
+ /* Index of "lower" interface */
+ if (iff->lower_idx == -1) {
+ iff->lower_idx = *(int *)RTA_DATA(attribute);
+ log_debug("netlink", "attribute IFLA_LINK for %s: %d",
+ iff->name ? iff->name : "(unknown)",
+ iff->lower_idx);
+ } else {
+ log_debug("netlink",
+ "attribute IFLA_LINK for %s: %d (ignored)",
+ iff->name ? iff->name : "(unknown)",
+ iff->lower_idx);
+ }
+ break;
+ case IFLA_LINK_NETNSID:
+ /* Is the lower interface into another namesapce? */
+ iff->lower_idx = -2;
+ log_debug("netlink",
+ "attribute IFLA_LINK_NETNSID received for %s",
+ iff->name ? iff->name : "(unknown)");
+ break;
+ case IFLA_MASTER:
+ /* Index of master interface */
+ iff->upper_idx = *(int *)RTA_DATA(attribute);
+ break;
+ case IFLA_MTU:
+ /* Maximum Transmission Unit */
+ iff->mtu = *(int *)RTA_DATA(attribute);
+ break;
+ case IFLA_LINKINFO:
+ netlink_parse_linkinfo(iff, RTA_DATA(attribute),
+ RTA_PAYLOAD(attribute));
+ break;
+ case IFLA_AF_SPEC:
+ if (ifi->ifi_family != AF_BRIDGE) break;
+ netlink_parse_afspec(iff, RTA_DATA(attribute),
+ RTA_PAYLOAD(attribute));
+ break;
+ default:
+ log_debug("netlink",
+ "unhandled link attribute type %d for iface %s",
+ attribute->rta_type, iff->name ? iff->name : "(unknown)");
+ break;
+ }
+ }
+ if (!iff->name || !iff->address) {
+ log_debug("netlink",
+ "interface %d does not have a name or an address, skip",
+ iff->index);
+ return -1;
+ }
+ if (iff->upper_idx == -1) {
+ /* No upper interface, we cannot be enslaved. We need to clear
+ * the flag because the appropriate information may come later
+ * and we don't want to miss it. */
+ iff->flags &= ~IFF_SLAVE;
+ }
+ if (iff->lower_idx == -2) iff->lower_idx = -1;
+
+ if (ifi->ifi_family == AF_BRIDGE && msg->nlmsg_type == RTM_DELLINK &&
+ iff->upper_idx != -1) {
+ log_debug("netlink", "removal of %s from bridge %d", iff->name,
+ iff->upper_idx);
+ msg->nlmsg_type = RTM_NEWLINK;
+ iff->upper_idx = -1;
+ }
+
+ log_debug("netlink", "parsed link %d (%s, flags: %d)", iff->index, iff->name,
+ iff->flags);
+ return 0;
+}
+
+/**
+ * Parse a `address` netlink message.
+ *
+ * @param msg message to be parsed
+ * @param ifa where to put the result
+ * return 0 if the address is worth it, -1 otherwise
+ */
+static int
+netlink_parse_address(struct nlmsghdr *msg, struct interfaces_address *ifa)
+{
+ struct ifaddrmsg *ifi;
+ struct rtattr *attribute;
+ int len;
+ ifi = NLMSG_DATA(msg);
+ len = msg->nlmsg_len - NLMSG_LENGTH(sizeof(struct ifaddrmsg));
+
+ ifa->index = ifi->ifa_index;
+ ifa->flags = ifi->ifa_flags;
+ switch (ifi->ifa_family) {
+ case AF_INET:
+ case AF_INET6:
+ break;
+ default:
+ log_debug("netlink", "got a non IP address on if %d (family: %d)",
+ ifa->index, ifi->ifa_family);
+ return -1;
+ }
+
+ for (attribute = IFA_RTA(ifi); RTA_OK(attribute, len);
+ attribute = RTA_NEXT(attribute, len)) {
+ switch (attribute->rta_type) {
+ case IFA_ADDRESS:
+ /* Address */
+ if (ifi->ifa_family == AF_INET) {
+ struct sockaddr_in ip;
+ memset(&ip, 0, sizeof(struct sockaddr_in));
+ ip.sin_family = AF_INET;
+ memcpy(&ip.sin_addr, RTA_DATA(attribute),
+ sizeof(struct in_addr));
+ memcpy(&ifa->address, &ip, sizeof(struct sockaddr_in));
+ } else {
+ struct sockaddr_in6 ip6;
+ memset(&ip6, 0, sizeof(struct sockaddr_in6));
+ ip6.sin6_family = AF_INET6;
+ memcpy(&ip6.sin6_addr, RTA_DATA(attribute),
+ sizeof(struct in6_addr));
+ memcpy(&ifa->address, &ip6,
+ sizeof(struct sockaddr_in6));
+ }
+ break;
+ default:
+ log_debug("netlink",
+ "unhandled address attribute type %d for iface %d",
+ attribute->rta_type, ifa->index);
+ break;
+ }
+ }
+ if (ifa->address.ss_family == AF_UNSPEC) {
+ log_debug("netlink", "no IP for interface %d", ifa->index);
+ return -1;
+ }
+ return 0;
+}
+
+/**
+ * Merge an old interface with a new one.
+ *
+ * Some properties may be absent in the new interface that should be copied over
+ * from the old one.
+ */
+static void
+netlink_merge(struct interfaces_device *old, struct interfaces_device *new)
+{
+ if (new->alias == NULL) {
+ new->alias = old->alias;
+ old->alias = NULL;
+ }
+ if (new->address == NULL) {
+ new->address = old->address;
+ old->address = NULL;
+ }
+ if (new->mtu == 0) new->mtu = old->mtu;
+ if (new->type == 0) new->type = old->type;
+
+ if (bitmap_isempty(new->vlan_bmap) && new->type == IFACE_VLAN_T)
+ memcpy((void *)new->vlan_bmap, (void *)old->vlan_bmap,
+ sizeof(uint32_t) * VLAN_BITMAP_LEN);
+
+ /* It's not possible for lower link to change */
+ new->lower_idx = old->lower_idx;
+}
+
+/**
+ * Receive netlink answer from the kernel.
+ *
+ * @param ifs list to store interface list or NULL if we don't
+ * @param ifas list to store address list or NULL if we don't
+ * @return 0 on success, -1 on error
+ */
+static int
+netlink_recv(struct lldpd *cfg, int s, struct interfaces_device_list *ifs,
+ struct interfaces_address_list *ifas)
+{
+ int end = 0, ret = 0, flags, retry = 0;
+ struct iovec iov;
+ int link_update = 0;
+
+ struct interfaces_device *ifdold;
+ struct interfaces_device *ifdnew;
+ struct interfaces_address *ifaold;
+ struct interfaces_address *ifanew;
+ char addr[INET6_ADDRSTRLEN + 1];
+
+ iov.iov_len = NETLINK_BUFFER;
+ iov.iov_base = malloc(iov.iov_len);
+ if (!iov.iov_base) {
+ log_warn("netlink", "not enough memory");
+ return -1;
+ }
+
+ while (!end) {
+ ssize_t len;
+ struct nlmsghdr *msg;
+ struct sockaddr_nl peer = { .nl_family = AF_NETLINK };
+ struct msghdr rtnl_reply = { .msg_iov = &iov,
+ .msg_iovlen = 1,
+ .msg_name = &peer,
+ .msg_namelen = sizeof(struct sockaddr_nl) };
+ flags = MSG_PEEK | MSG_TRUNC;
+ retry:
+ len = recvmsg(s, &rtnl_reply, flags);
+ if (len == -1) {
+ if (errno == EAGAIN || errno == EWOULDBLOCK) {
+ if (retry++ == 0) {
+ levent_recv_error(s, "netlink socket");
+ goto retry;
+ }
+ log_warnx("netlink",
+ "should have received something, but didn't");
+ ret = 0;
+ goto out;
+ }
+ int rsize = cfg->g_netlink->nl_socket_recv_size;
+ if (errno == ENOBUFS && rsize > 0 &&
+ rsize < NETLINK_MAX_RECEIVE_BUFSIZE &&
+ s == cfg->g_netlink->nl_socket_changes) {
+ /* Try to increase buffer size, only for the
+ * socket used to receive changes */
+ rsize *= 2;
+ if (rsize > NETLINK_MAX_RECEIVE_BUFSIZE) {
+ rsize = NETLINK_MAX_RECEIVE_BUFSIZE;
+ }
+ int rc = netlink_socket_set_buffer_size(s, SO_RCVBUF,
+ "SO_RCVBUF", rsize);
+ if (rc < 0)
+ cfg->g_netlink->nl_socket_recv_size = 0;
+ else
+ cfg->g_netlink->nl_socket_recv_size = rsize;
+ if (rc > 0 || rc == -2) {
+ log_info("netlink",
+ "netlink receive buffer too small, retry with larger one (%d)",
+ rsize);
+ flags = 0;
+ goto retry;
+ }
+ }
+ log_warn("netlink", "unable to receive netlink answer");
+ ret = -1;
+ goto out;
+ }
+ if (!len) {
+ ret = 0;
+ goto out;
+ }
+
+ if (iov.iov_len < len || (rtnl_reply.msg_flags & MSG_TRUNC)) {
+ void *tmp;
+
+ /* Provided buffer is not large enough, enlarge it
+ * to size of len (which should be total length of the message)
+ * and try again. */
+ iov.iov_len = len;
+ tmp = realloc(iov.iov_base, iov.iov_len);
+ if (!tmp) {
+ log_warn("netlink", "not enough memory");
+ ret = -1;
+ goto out;
+ }
+ log_debug("netlink", "enlarge message size to %zu bytes", len);
+ iov.iov_base = tmp;
+ flags = 0;
+ goto retry;
+ }
+
+ if (flags != 0) {
+ /* Buffer is big enough, do the actual reading */
+ flags = 0;
+ goto retry;
+ }
+
+ for (msg = (struct nlmsghdr *)(void *)(iov.iov_base);
+ NLMSG_OK(msg, len); msg = NLMSG_NEXT(msg, len)) {
+ if (!(msg->nlmsg_flags & NLM_F_MULTI)) end = 1;
+ switch (msg->nlmsg_type) {
+ case NLMSG_DONE:
+ log_debug("netlink", "received done message");
+ end = 1;
+ break;
+ case RTM_NEWLINK:
+ case RTM_DELLINK:
+ if (!ifs) break;
+ log_debug("netlink", "received link information");
+ ifdnew = calloc(1, sizeof(struct interfaces_device));
+ if (ifdnew == NULL) {
+ log_warn("netlink",
+ "not enough memory for another interface, give up what we have");
+ goto end;
+ }
+ if (netlink_parse_link(msg, ifdnew) == 0) {
+ /* We need to find if we already have this
+ * interface */
+ TAILQ_FOREACH (ifdold, ifs, next) {
+ if (ifdold->index == ifdnew->index)
+ break;
+ }
+
+ if (msg->nlmsg_type == RTM_NEWLINK) {
+ if (ifdold == NULL) {
+ log_debug("netlink",
+ "interface %s is new",
+ ifdnew->name);
+ TAILQ_INSERT_TAIL(ifs, ifdnew,
+ next);
+ } else {
+ log_debug("netlink",
+ "interface %s/%s is updated",
+ ifdold->name, ifdnew->name);
+ netlink_merge(ifdold, ifdnew);
+ TAILQ_INSERT_AFTER(ifs, ifdold,
+ ifdnew, next);
+ TAILQ_REMOVE(ifs, ifdold, next);
+ interfaces_free_device(ifdold);
+ }
+ } else {
+ if (ifdold == NULL) {
+ log_warnx("netlink",
+ "removal request for %s, but no knowledge of it",
+ ifdnew->name);
+ } else {
+ log_debug("netlink",
+ "interface %s is to be removed",
+ ifdold->name);
+ TAILQ_REMOVE(ifs, ifdold, next);
+ interfaces_free_device(ifdold);
+ }
+ interfaces_free_device(ifdnew);
+ }
+ link_update = 1;
+ } else {
+ interfaces_free_device(ifdnew);
+ }
+ break;
+ case RTM_NEWADDR:
+ case RTM_DELADDR:
+ if (!ifas) break;
+ log_debug("netlink", "received address information");
+ ifanew = calloc(1, sizeof(struct interfaces_address));
+ if (ifanew == NULL) {
+ log_warn("netlink",
+ "not enough memory for another address, give what we have");
+ goto end;
+ }
+ if (netlink_parse_address(msg, ifanew) == 0) {
+ if (ifanew->address.ss_family == AF_INET6 &&
+ ifanew->flags & IFA_F_TEMPORARY) {
+ interfaces_free_address(ifanew);
+ break;
+ }
+ TAILQ_FOREACH (ifaold, ifas, next) {
+ if ((ifaold->index == ifanew->index) &&
+ !memcmp(&ifaold->address,
+ &ifanew->address,
+ sizeof(ifaold->address)))
+ break;
+ }
+ if (getnameinfo(
+ (struct sockaddr *)&ifanew->address,
+ sizeof(ifanew->address), addr,
+ sizeof(addr), NULL, 0,
+ NI_NUMERICHOST) != 0) {
+ strlcpy(addr, "(unknown)",
+ sizeof(addr));
+ }
+
+ if (msg->nlmsg_type == RTM_NEWADDR) {
+ if (ifaold == NULL) {
+ log_debug("netlink",
+ "new address %s%%%d", addr,
+ ifanew->index);
+ TAILQ_INSERT_TAIL(ifas, ifanew,
+ next);
+ } else {
+ log_debug("netlink",
+ "updated address %s%%%d",
+ addr, ifaold->index);
+ TAILQ_INSERT_AFTER(ifas, ifaold,
+ ifanew, next);
+ TAILQ_REMOVE(ifas, ifaold,
+ next);
+ interfaces_free_address(ifaold);
+ }
+ } else {
+ if (ifaold == NULL) {
+ log_info("netlink",
+ "removal request for address of %s%%%d, but no knowledge of it",
+ addr, ifanew->index);
+ } else {
+ log_debug("netlink",
+ "address %s%%%d is to be removed",
+ addr, ifaold->index);
+ TAILQ_REMOVE(ifas, ifaold,
+ next);
+ interfaces_free_address(ifaold);
+ }
+ interfaces_free_address(ifanew);
+ }
+ } else {
+ interfaces_free_address(ifanew);
+ }
+ break;
+ default:
+ log_debug("netlink",
+ "received unhandled message type %d (len: %d)",
+ msg->nlmsg_type, msg->nlmsg_len);
+ }
+ }
+ }
+end:
+ if (link_update) {
+ /* Fill out lower/upper */
+ struct interfaces_device *iface1, *iface2;
+ TAILQ_FOREACH (iface1, ifs, next) {
+ if (iface1->upper_idx != -1 &&
+ iface1->upper_idx != iface1->index) {
+ TAILQ_FOREACH (iface2, ifs, next) {
+ if (iface1->upper_idx == iface2->index) {
+ log_debug("netlink",
+ "upper interface for %s is %s",
+ iface1->name, iface2->name);
+ iface1->upper = iface2;
+ break;
+ }
+ }
+ if (iface2 == NULL) iface1->upper = NULL;
+ } else {
+ iface1->upper = NULL;
+ }
+ if (iface1->lower_idx != -1 &&
+ iface1->lower_idx != iface1->index) {
+ TAILQ_FOREACH (iface2, ifs, next) {
+ if (iface1->lower_idx == iface2->index) {
+ /* Workaround a bug introduced
+ * in Linux 4.1: a pair of veth
+ * will be lower interface of
+ * each other. Do not modify
+ * index as if one of them is
+ * updated, we will loose the
+ * information about the
+ * loop. */
+ if (iface2->lower_idx ==
+ iface1->index) {
+ iface1->lower = NULL;
+ log_debug("netlink",
+ "link loop detected between %s(%d) and %s(%d)",
+ iface1->name, iface1->index,
+ iface2->name,
+ iface2->index);
+ } else {
+ log_debug("netlink",
+ "lower interface for %s is %s",
+ iface1->name, iface2->name);
+ iface1->lower = iface2;
+ }
+ break;
+ }
+ }
+ } else {
+ iface1->lower = NULL;
+ }
+ }
+ }
+
+out:
+ free(iov.iov_base);
+ return ret;
+}
+
+static int
+netlink_group_mask(int group)
+{
+ return group ? (1 << (group - 1)) : 0;
+}
+
+/**
+ * Subscribe to link changes.
+ *
+ * @return 0 on success, -1 otherwise
+ */
+static int
+netlink_subscribe_changes(struct lldpd *cfg)
+{
+ unsigned int groups;
+
+ log_debug("netlink", "listening on interface changes");
+
+ groups = netlink_group_mask(RTNLGRP_LINK) |
+ netlink_group_mask(RTNLGRP_IPV4_IFADDR) |
+ netlink_group_mask(RTNLGRP_IPV6_IFADDR);
+
+ return netlink_connect(cfg, groups);
+}
+
+/**
+ * Receive changes from netlink */
+static void
+netlink_change_cb(struct lldpd *cfg)
+{
+ if (cfg->g_netlink == NULL) return;
+ netlink_recv(cfg, cfg->g_netlink->nl_socket_changes, cfg->g_netlink->devices,
+ cfg->g_netlink->addresses);
+}
+
+/**
+ * Initialize netlink subsystem.
+ *
+ * This can be called several times but will have effect only the first time.
+ *
+ * @return 0 on success, -1 otherwise
+ */
+static int
+netlink_initialize(struct lldpd *cfg)
+{
+#ifdef ENABLE_DOT1
+ struct interfaces_device *iff;
+#endif
+
+ if (cfg->g_netlink) return 0;
+
+ log_debug("netlink", "initialize netlink subsystem");
+ if ((cfg->g_netlink = calloc(sizeof(struct lldpd_netlink), 1)) == NULL) {
+ log_warn("netlink", "unable to allocate memory for netlink subsystem");
+ goto end;
+ }
+
+ /* Connect to netlink (by requesting to get notified on updates) and
+ * request updated information right now */
+ if (netlink_subscribe_changes(cfg) == -1) goto end;
+
+ struct interfaces_address_list *ifaddrs = cfg->g_netlink->addresses =
+ malloc(sizeof(struct interfaces_address_list));
+ if (ifaddrs == NULL) {
+ log_warn("netlink", "not enough memory for address list");
+ goto end;
+ }
+ TAILQ_INIT(ifaddrs);
+
+ struct interfaces_device_list *ifs = cfg->g_netlink->devices =
+ malloc(sizeof(struct interfaces_device_list));
+ if (ifs == NULL) {
+ log_warn("netlink", "not enough memory for interface list");
+ goto end;
+ }
+ TAILQ_INIT(ifs);
+
+ if (netlink_send(cfg->g_netlink->nl_socket_queries, RTM_GETADDR, AF_UNSPEC,
+ 1) == -1)
+ goto end;
+ netlink_recv(cfg, cfg->g_netlink->nl_socket_queries, NULL, ifaddrs);
+ if (netlink_send(cfg->g_netlink->nl_socket_queries, RTM_GETLINK, AF_PACKET,
+ 2) == -1)
+ goto end;
+ netlink_recv(cfg, cfg->g_netlink->nl_socket_queries, ifs, NULL);
+#ifdef ENABLE_DOT1
+ /* If we have a bridge, search for VLAN-aware bridges */
+ TAILQ_FOREACH (iff, ifs, next) {
+ if (iff->type & IFACE_BRIDGE_T) {
+ log_debug("netlink",
+ "interface %s is a bridge, check for VLANs", iff->name);
+ if (netlink_send(cfg->g_netlink->nl_socket_queries, RTM_GETLINK,
+ AF_BRIDGE, 3) == -1)
+ goto end;
+ netlink_recv(cfg, cfg->g_netlink->nl_socket_queries, ifs, NULL);
+ break;
+ }
+ }
+#endif
+
+ /* Listen to any future change */
+ cfg->g_iface_cb = netlink_change_cb;
+ if (levent_iface_subscribe(cfg, cfg->g_netlink->nl_socket_changes) == -1) {
+ goto end;
+ }
+
+ return 0;
+end:
+ netlink_cleanup(cfg);
+ return -1;
+}
+
+/**
+ * Cleanup netlink subsystem.
+ */
+void
+netlink_cleanup(struct lldpd *cfg)
+{
+ if (cfg->g_netlink == NULL) return;
+ if (cfg->g_netlink->nl_socket_changes != -1)
+ close(cfg->g_netlink->nl_socket_changes);
+ if (cfg->g_netlink->nl_socket_queries != -1)
+ close(cfg->g_netlink->nl_socket_queries);
+ interfaces_free_devices(cfg->g_netlink->devices);
+ interfaces_free_addresses(cfg->g_netlink->addresses);
+
+ free(cfg->g_netlink);
+ cfg->g_netlink = NULL;
+}
+
+/**
+ * Receive the list of interfaces.
+ *
+ * @return a list of interfaces.
+ */
+struct interfaces_device_list *
+netlink_get_interfaces(struct lldpd *cfg)
+{
+ if (netlink_initialize(cfg) == -1) return NULL;
+ struct interfaces_device *ifd;
+ TAILQ_FOREACH (ifd, cfg->g_netlink->devices, next) {
+ ifd->ignore = 0;
+ }
+ return cfg->g_netlink->devices;
+}
+
+/**
+ * Receive the list of addresses.
+ *
+ * @return a list of addresses.
+ */
+struct interfaces_address_list *
+netlink_get_addresses(struct lldpd *cfg)
+{
+ if (netlink_initialize(cfg) == -1) return NULL;
+ return cfg->g_netlink->addresses;
+}
diff --git a/src/daemon/pattern.c b/src/daemon/pattern.c
new file mode 100644
index 0000000..0f9885d
--- /dev/null
+++ b/src/daemon/pattern.c
@@ -0,0 +1,80 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2008 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "lldpd.h"
+
+#include <string.h>
+#include <fnmatch.h>
+
+/**
+ * Match a list of patterns.
+ *
+ * @param string String to match against the list of patterns
+ * @param patterns List of comma separated patterns. A pattern may
+ * begin by `!` to negate it. In this case, it is
+ * denied. A pattern may begin with `!!`. In this
+ * case, it is allowed back. Each pattern will then be
+ * matched against `fnmatch()` function.
+ * @param found Value to return if the pattern isn't found. Should be either
+ * PATTERN_MATCH_DENIED or PATTERN_MACTH_DENIED.
+ *
+ * If a pattern is found matching and denied at the same time, it
+ * will be denied. If it is both allowed and denied, it
+ * will be allowed.
+ *
+ * @return PATTERN_MATCH_DENIED if the string matches a denied pattern which is not
+ * allowed or if the pattern wasn't found and `found` was set to
+ * PATTERN_MATCH_DENIED. Otherwise, return PATTERN_MATCH_ALLOWED unless the
+ * interface match is exact, in this case return PATTERN_MATCH_ALLOWED_EXACT.
+ */
+enum pattern_match_result
+pattern_match(char *string, char *patterns, int found)
+{
+ char *pattern;
+ int denied = 0;
+ found = found ? PATTERN_MATCH_ALLOWED : PATTERN_MATCH_DENIED;
+
+ if ((patterns = strdup(patterns)) == NULL) {
+ log_warnx("interfaces", "unable to allocate memory");
+ return PATTERN_MATCH_DENIED;
+ }
+
+ for (pattern = strtok(patterns, ","); pattern != NULL;
+ pattern = strtok(NULL, ",")) {
+ if ((pattern[0] == '!') && (pattern[1] == '!') &&
+ (fnmatch(pattern + 2, string, 0) == 0)) {
+ /* Allowed. No need to search further. */
+ found = (strcmp(pattern + 2, string)) ?
+ PATTERN_MATCH_ALLOWED :
+ PATTERN_MATCH_ALLOWED_EXACT;
+ break;
+ }
+ if ((pattern[0] == '!') && (fnmatch(pattern + 1, string, 0) == 0)) {
+ denied = 1;
+ found = PATTERN_MATCH_DENIED;
+ } else if (!denied && fnmatch(pattern, string, 0) == 0) {
+ if (!strcmp(pattern, string)) {
+ found = PATTERN_MATCH_ALLOWED_EXACT;
+ } else if (found < 2) {
+ found = PATTERN_MATCH_ALLOWED;
+ }
+ }
+ }
+
+ free(patterns);
+ return found;
+}
diff --git a/src/daemon/priv-bsd.c b/src/daemon/priv-bsd.c
new file mode 100644
index 0000000..61f332a
--- /dev/null
+++ b/src/daemon/priv-bsd.c
@@ -0,0 +1,202 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2008 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "lldpd.h"
+
+#include <unistd.h>
+#include <net/bpf.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
+
+int
+asroot_iface_init_os(int ifindex, char *name, int *fd)
+{
+ int enable, required, rc;
+ struct bpf_insn filter[] = { LLDPD_FILTER_F };
+ struct ifreq ifr = { .ifr_name = {} };
+ struct bpf_program fprog = { .bf_insns = filter,
+ .bf_len = sizeof(filter) / sizeof(struct bpf_insn) };
+
+#ifndef HOST_OS_SOLARIS
+ int n = 0;
+ char dev[20];
+ do {
+ snprintf(dev, sizeof(dev), "/dev/bpf%d", n++);
+ *fd = open(dev, O_RDWR);
+ } while (*fd < 0 && errno == EBUSY);
+#else
+ *fd = open("/dev/bpf", O_RDWR);
+#endif
+ if (*fd < 0) {
+ rc = errno;
+ log_warn("privsep", "unable to find a free BPF");
+ return rc;
+ }
+
+ /* Set buffer size */
+ required = ETHER_MAX_LEN + BPF_WORDALIGN(sizeof(struct bpf_hdr));
+ if (ioctl(*fd, BIOCSBLEN, (caddr_t)&required) < 0) {
+ rc = errno;
+ log_warn("privsep", "unable to set receive buffer size for BPF on %s",
+ name);
+ return rc;
+ }
+
+ /* Bind the interface to BPF device */
+ strlcpy(ifr.ifr_name, name, IFNAMSIZ);
+ if (ioctl(*fd, BIOCSETIF, (caddr_t)&ifr) < 0) {
+ rc = errno;
+ log_warn("privsep", "failed to bind interface %s to BPF", name);
+ return rc;
+ }
+
+ /* Disable buffering */
+ enable = 1;
+ if (ioctl(*fd, BIOCIMMEDIATE, (caddr_t)&enable) < 0) {
+ rc = errno;
+ log_warn("privsep", "unable to disable buffering for %s", name);
+ return rc;
+ }
+
+ /* Let us write the MAC address (raw packet mode) */
+ enable = 1;
+ if (ioctl(*fd, BIOCSHDRCMPLT, (caddr_t)&enable) < 0) {
+ rc = errno;
+ log_warn("privsep", "unable to set the `header complete` flag for %s",
+ name);
+ return rc;
+ }
+
+ /* Don't see sent packets */
+#ifdef HOST_OS_OPENBSD
+ enable = BPF_DIRECTION_OUT;
+ if (ioctl(*fd, BIOCSDIRFILT, (caddr_t)&enable) < 0)
+#else
+ enable = 0;
+ if (ioctl(*fd, BIOCSSEESENT, (caddr_t)&enable) < 0)
+#endif
+ {
+ rc = errno;
+ log_warn("privsep",
+ "unable to set packet direction for BPF filter on %s", name);
+ return rc;
+ }
+
+ /* Install read filter */
+ if (ioctl(*fd, BIOCSETF, (caddr_t)&fprog) < 0) {
+ rc = errno;
+ log_warn("privsep", "unable to setup BPF filter for %s", name);
+ return rc;
+ }
+#ifdef BIOCSETWF
+ /* Install write filter (optional) */
+ if (ioctl(*fd, BIOCSETWF, (caddr_t)&fprog) < 0) {
+ rc = errno;
+ log_info("privsep", "unable to setup write BPF filter for %s", name);
+ return rc;
+ }
+#endif
+
+#ifdef BIOCLOCK
+ /* Lock interface, but first make it non blocking since we cannot do
+ * this later */
+ levent_make_socket_nonblocking(*fd);
+ if (ioctl(*fd, BIOCLOCK, (caddr_t)&enable) < 0) {
+ rc = errno;
+ log_info("privsep", "unable to lock BPF interface %s", name);
+ return rc;
+ }
+#endif
+ return 0;
+}
+
+int
+asroot_iface_description_os(const char *name, const char *description)
+{
+#ifdef IFDESCRSIZE
+# if defined HOST_OS_FREEBSD || defined HOST_OS_OPENBSD
+ char descr[IFDESCRSIZE];
+ int rc, sock = -1;
+# if defined HOST_OS_FREEBSD
+ struct ifreq ifr = { .ifr_buffer = { .buffer = descr, .length = IFDESCRSIZE } };
+# else
+ struct ifreq ifr = { .ifr_data = (caddr_t)descr };
+# endif
+ strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+ if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == 1) {
+ rc = errno;
+ log_warnx("privsep", "unable to open inet socket");
+ return rc;
+ }
+ if (strlen(description) == 0) {
+ /* No neighbor, try to append "was" to the current description */
+ if (ioctl(sock, SIOCGIFDESCR, (caddr_t)&ifr) < 0) {
+ rc = errno;
+ log_warnx("privsep", "unable to get description of %s", name);
+ close(sock);
+ return rc;
+ }
+ if (strncmp(descr, "lldpd: ", 7) == 0) {
+ if (strncmp(descr + 7, "was ", 4) == 0) {
+ /* Already has an old neighbor */
+ close(sock);
+ return 0;
+ } else {
+ /* Append was */
+ memmove(descr + 11, descr + 7, sizeof(descr) - 11);
+ memcpy(descr, "lldpd: was ", 11);
+ }
+ } else {
+ /* No description, no neighbor */
+ strlcpy(descr, "lldpd: no neighbor", sizeof(descr));
+ }
+ } else
+ snprintf(descr, sizeof(descr), "lldpd: connected to %s", description);
+# if defined HOST_OS_FREEBSD
+ ift.ifr_buffer.length = strlen(descr);
+# endif
+ if (ioctl(sock, SIOCSIFDESCR, (caddr_t)&ifr) < 0) {
+ rc = errno;
+ log_warnx("privsep", "unable to set description of %s", name);
+ close(sock);
+ return rc;
+ }
+ close(sock);
+ return 0;
+# endif
+#endif /* IFDESCRSIZE */
+ static int once = 0;
+ if (!once) {
+ log_warnx("privsep", "cannot set interface description for this OS");
+ once = 1;
+ }
+ return 0;
+}
+
+int
+asroot_iface_promisc_os(const char *name)
+{
+ /* The promiscuous mode can be set when setting BPF
+ (BIOCPROMISC). Unfortunately, the interface is locked down and we
+ cannot change that without reopening a new socket. Let's do nothing
+ for now. */
+ return 0;
+}
diff --git a/src/daemon/priv-linux.c b/src/daemon/priv-linux.c
new file mode 100644
index 0000000..9a6f90a
--- /dev/null
+++ b/src/daemon/priv-linux.c
@@ -0,0 +1,337 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2008 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "lldpd.h"
+
+#include <unistd.h>
+#include <inttypes.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <limits.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <regex.h>
+#include <sys/ioctl.h>
+#include <netpacket/packet.h> /* For sockaddr_ll */
+#if defined(__clang__)
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wdocumentation"
+#endif
+#include <linux/filter.h> /* For BPF filtering */
+#include <linux/sockios.h>
+#include <linux/if_ether.h>
+#include <linux/ethtool.h>
+#if defined(__clang__)
+# pragma clang diagnostic pop
+#endif
+
+/* Defined in linux/pkt_sched.h */
+#define TC_PRIO_CONTROL 7
+/* Defined in sysfs/libsysfs.h */
+#define SYSFS_PATH_MAX 256
+
+/* Proxy for open */
+int
+priv_open(const char *file)
+{
+ int len, rc;
+ enum priv_cmd cmd = PRIV_OPEN;
+ must_write(PRIV_UNPRIVILEGED, &cmd, sizeof(enum priv_cmd));
+ len = strlen(file);
+ must_write(PRIV_UNPRIVILEGED, &len, sizeof(int));
+ must_write(PRIV_UNPRIVILEGED, file, len);
+ priv_wait();
+ must_read(PRIV_UNPRIVILEGED, &rc, sizeof(int));
+ if (rc == -1) return rc;
+ return receive_fd(PRIV_UNPRIVILEGED);
+}
+
+void
+asroot_open()
+{
+ const char *authorized[] = { PROCFS_SYS_NET "ipv4/ip_forward",
+ PROCFS_SYS_NET "ipv6/conf/all/forwarding",
+ "/proc/net/bonding/[^.][^/]*", "/proc/self/net/bonding/[^.][^/]*",
+#ifdef ENABLE_OLDIES
+ SYSFS_CLASS_NET "[^.][^/]*/brforward",
+ SYSFS_CLASS_NET "[^.][^/]*/brport",
+ SYSFS_CLASS_NET "[^.][^/]*/brif/[^.][^/]*/port_no",
+#endif
+ SYSFS_CLASS_DMI "product_version", SYSFS_CLASS_DMI "product_serial",
+ SYSFS_CLASS_DMI "product_name", SYSFS_CLASS_DMI "bios_version",
+ SYSFS_CLASS_DMI "sys_vendor", SYSFS_CLASS_DMI "chassis_asset_tag",
+ NULL };
+ const char **f;
+ char *file;
+ int fd, len, rc;
+ regex_t preg;
+
+ must_read(PRIV_PRIVILEGED, &len, sizeof(len));
+ if (len < 0 || len > PATH_MAX) fatalx("privsep", "too large value requested");
+ if ((file = (char *)malloc(len + 1)) == NULL) fatal("privsep", NULL);
+ must_read(PRIV_PRIVILEGED, file, len);
+ file[len] = '\0';
+
+ for (f = authorized; *f != NULL; f++) {
+ if (regcomp(&preg, *f, REG_NOSUB) != 0) /* Should not happen */
+ fatal("privsep", "unable to compile a regex");
+ if (regexec(&preg, file, 0, NULL, 0) == 0) {
+ regfree(&preg);
+ break;
+ }
+ regfree(&preg);
+ }
+ if (*f == NULL) {
+ log_warnx("privsep", "not authorized to open %s", file);
+ rc = -1;
+ must_write(PRIV_PRIVILEGED, &rc, sizeof(int));
+ free(file);
+ return;
+ }
+ if ((fd = open(file, O_RDONLY)) == -1) {
+ rc = -1;
+ must_write(PRIV_PRIVILEGED, &rc, sizeof(int));
+ free(file);
+ return;
+ }
+ free(file);
+ must_write(PRIV_PRIVILEGED, &fd, sizeof(int));
+ send_fd(PRIV_PRIVILEGED, fd);
+ close(fd);
+}
+
+/* Quirks needed by some additional interfaces. Currently, this is limited to
+ * disabling LLDP firmware for i40e. */
+static void
+asroot_iface_init_quirks(int ifindex, char *name)
+{
+ int s = -1;
+ int fd = -1;
+
+ /* Check driver. */
+ struct ethtool_drvinfo ethc = { .cmd = ETHTOOL_GDRVINFO };
+ struct ifreq ifr = { .ifr_data = (caddr_t)&ethc };
+ if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
+ log_warn("privsep", "unable to open a socket");
+ goto end;
+ }
+ strlcpy(ifr.ifr_name, name, IFNAMSIZ);
+ if (ioctl(s, SIOCETHTOOL, &ifr) != 0 ||
+ strncmp("i40e", ethc.driver, sizeof(ethc.driver))) {
+ /* Not i40e */
+ goto end;
+ }
+ log_info("interfaces",
+ "i40e driver detected for %s, disabling LLDP in firmware", name);
+
+ /* We assume debugfs is mounted. Otherwise, we would need to check if it
+ * is mounted, then unshare a new mount namespace, mount it, issues the
+ * command, leave the namespace. Let's see if there is such a need. */
+
+ /* Alternative is to use ethtool (ethtool --set-priv-flags ens5f0
+ * disable-fw-lldp on). However, this requires a recent firmware (from
+ * i40e_ethtool.c):
+ *
+ * If the driver detected FW LLDP was disabled on init, this flag could
+ * be set, however we do not support _changing_ the flag:
+ * - on XL710 if NPAR is enabled or FW API version < 1.7
+ * - on X722 with FW API version < 1.6
+ */
+
+ char command[] = "lldp stop";
+ char sysfs_path[SYSFS_PATH_MAX + 1];
+ if (snprintf(sysfs_path, SYSFS_PATH_MAX, "/sys/kernel/debug/i40e/%.*s/command",
+ (int)sizeof(ethc.bus_info), ethc.bus_info) >= SYSFS_PATH_MAX) {
+ log_warnx("interfaces", "path truncated");
+ goto end;
+ }
+ if ((fd = open(sysfs_path, O_WRONLY)) == -1) {
+ if (errno == ENOENT) {
+ log_info("interfaces",
+ "%s does not exist, "
+ "cannot disable LLDP in firmware for %s",
+ sysfs_path, name);
+ goto end;
+ }
+ log_warn("interfaces",
+ "cannot open %s to disable LLDP in firmware for %s", sysfs_path,
+ name);
+ goto end;
+ }
+ if (write(fd, command, sizeof(command) - 1) == -1) {
+ log_warn("interfaces", "cannot disable LLDP in firmware for %s", name);
+ goto end;
+ }
+end:
+ if (s != -1) close(s);
+ if (fd != -1) close(fd);
+}
+
+int
+asroot_iface_init_os(int ifindex, char *name, int *fd)
+{
+ int rc;
+ /* Open listening socket to receive/send frames */
+ if ((*fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) < 0) {
+ rc = errno;
+ return rc;
+ }
+
+ struct sockaddr_ll sa = { .sll_family = AF_PACKET, .sll_ifindex = ifindex };
+ if (bind(*fd, (struct sockaddr *)&sa, sizeof(sa)) < 0) {
+ rc = errno;
+ log_warn("privsep", "unable to bind to raw socket for interface %s",
+ name);
+ return rc;
+ }
+
+ /* Set filter */
+ log_debug("privsep", "set BPF filter for %s", name);
+ static struct sock_filter lldpd_filter_f[] = { LLDPD_FILTER_F };
+ struct sock_fprog prog = { .filter = lldpd_filter_f,
+ .len = sizeof(lldpd_filter_f) / sizeof(struct sock_filter) };
+ if (setsockopt(*fd, SOL_SOCKET, SO_ATTACH_FILTER, &prog, sizeof(prog)) < 0) {
+ rc = errno;
+ log_warn("privsep", "unable to change filter for %s", name);
+ return rc;
+ }
+
+ /* Set priority to TC_PRIO_CONTROL for ice Intel cards. See #444. */
+ int prio = TC_PRIO_CONTROL;
+ if (setsockopt(*fd, SOL_SOCKET, SO_PRIORITY, &prio, sizeof(prio)) < 0) {
+ rc = errno;
+ log_warn("privsep",
+ "unable to set priority \"control\" to socket for interface %s",
+ name);
+ return rc;
+ }
+
+#ifdef SO_LOCK_FILTER
+ int lock = 1;
+ if (setsockopt(*fd, SOL_SOCKET, SO_LOCK_FILTER, &lock, sizeof(lock)) < 0) {
+ if (errno != ENOPROTOOPT) {
+ rc = errno;
+ log_warn("privsep", "unable to lock filter for %s", name);
+ return rc;
+ }
+ }
+#endif
+#ifdef PACKET_IGNORE_OUTGOING
+ int ignore = 1;
+ if (setsockopt(*fd, SOL_PACKET, PACKET_IGNORE_OUTGOING, &ignore,
+ sizeof(ignore)) < 0) {
+ if (errno != ENOPROTOOPT) {
+ rc = errno;
+ log_warn("privsep",
+ "unable to set packet direction for BPF filter on %s",
+ name);
+ return rc;
+ }
+ }
+#endif
+
+ asroot_iface_init_quirks(ifindex, name);
+ return 0;
+}
+
+int
+asroot_iface_description_os(const char *name, const char *description)
+{
+ /* We could use netlink but this is a lot to do in a privileged
+ * process. Just write to /sys/class/net/XXXX/ifalias. */
+ char *file;
+ char descr[IFALIASZ];
+ FILE *fp;
+ int rc;
+ if (name[0] == '\0' || name[0] == '.') {
+ log_warnx("privsep", "odd interface name %s", name);
+ return -1;
+ }
+ if (asprintf(&file, SYSFS_CLASS_NET "%s/ifalias", name) == -1) {
+ log_warn("privsep",
+ "unable to allocate memory for setting description");
+ return -1;
+ }
+ if ((fp = fopen(file, "r+")) == NULL) {
+ rc = errno;
+ log_debug("privsep", "cannot open interface description for %s: %s",
+ name, strerror(errno));
+ free(file);
+ return rc;
+ }
+ free(file);
+ if (strlen(description) == 0 && fgets(descr, sizeof(descr), fp) != NULL) {
+ if (strncmp(descr, "lldpd: ", 7) == 0) {
+ if (strncmp(descr + 7, "was ", 4) == 0) {
+ /* Already has an old neighbor */
+ fclose(fp);
+ return 0;
+ } else {
+ /* Append was */
+ memmove(descr + 11, descr + 7, sizeof(descr) - 11);
+ memcpy(descr, "lldpd: was ", 11);
+ }
+ } else {
+ /* No description, no neighbor */
+ strlcpy(descr, "lldpd: no neighbor", sizeof(descr));
+ }
+ } else
+ snprintf(descr, sizeof(descr), "lldpd: connected to %s", description);
+ if (fputs(descr, fp) == EOF) {
+ log_debug("privsep", "cannot set interface description for %s", name);
+ fclose(fp);
+ return -1;
+ }
+ fclose(fp);
+ return 0;
+}
+
+int
+asroot_iface_promisc_os(const char *name)
+{
+ int s, rc;
+ if ((s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) < 0) {
+ rc = errno;
+ log_warn("privsep", "unable to open raw socket");
+ return rc;
+ }
+
+ struct ifreq ifr = {};
+ strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+
+ if (ioctl(s, SIOCGIFFLAGS, &ifr) == -1) {
+ rc = errno;
+ log_warn("privsep", "unable to get interface flags for %s", name);
+ close(s);
+ return rc;
+ }
+
+ if (ifr.ifr_flags & IFF_PROMISC) {
+ close(s);
+ return 0;
+ }
+ ifr.ifr_flags |= IFF_PROMISC;
+ if (ioctl(s, SIOCSIFFLAGS, &ifr) == -1) {
+ rc = errno;
+ log_warn("privsep", "unable to set promisc mode for %s", name);
+ close(s);
+ return rc;
+ }
+ log_info("privsep", "promiscuous mode enabled for %s", name);
+ close(s);
+ return 0;
+}
diff --git a/src/daemon/priv-seccomp.c b/src/daemon/priv-seccomp.c
new file mode 100644
index 0000000..8322cb2
--- /dev/null
+++ b/src/daemon/priv-seccomp.c
@@ -0,0 +1,210 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2008 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "lldpd.h"
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <signal.h>
+
+#include "syscall-names.h"
+#include <seccomp.h>
+
+#ifndef SYS_SECCOMP
+# define SYS_SECCOMP 1
+#endif
+
+#if defined(__i386__)
+# define REG_SYSCALL REG_EAX
+# define ARCH_NR AUDIT_ARCH_I386
+#elif defined(__x86_64__)
+# define REG_SYSCALL REG_RAX
+# define ARCH_NR AUDIT_ARCH_X86_64
+#else
+# error "Platform does not support seccomp filter yet"
+# define REG_SYSCALL 0
+# define ARCH_NR 0
+#endif
+
+/* If there is no privilege separation, seccomp is currently useless */
+#ifdef ENABLE_PRIVSEP
+static int monitored = -1;
+static int trapped = 0;
+/**
+ * SIGSYS signal handler
+ * @param nr the signal number
+ * @param info siginfo_t pointer
+ * @param void_context handler context
+ *
+ * Simple signal handler for SIGSYS displaying the error, killing the child and
+ * exiting.
+ *
+ */
+static void
+priv_seccomp_trap_handler(int signal, siginfo_t *info, void *vctx)
+{
+ ucontext_t *ctx = (ucontext_t *)(vctx);
+ unsigned int syscall;
+
+ if (trapped) _exit(161); /* Avoid loops */
+
+ /* Get details */
+ if (info->si_code != SYS_SECCOMP) return;
+ if (!ctx) _exit(161);
+ syscall = ctx->uc_mcontext.gregs[REG_SYSCALL];
+ trapped = 1;
+
+ /* Log them. Technically, `log_warnx()` is not signal safe, but we are
+ * unlikely to reenter here. */
+ log_warnx("seccomp", "invalid syscall attempted: %s(%d)",
+ (syscall < sizeof(syscall_names)) ? syscall_names[syscall] : "unknown",
+ syscall);
+
+ /* Kill children and exit */
+ kill(monitored, SIGTERM);
+ fatalx("seccomp", "invalid syscall not allowed: stop here");
+ _exit(161);
+}
+
+/**
+ * Install a TRAP action signal handler
+ *
+ * This function installs the TRAP action signal handler and is based on
+ * examples from Will Drewry and Kees Cook. Returns zero on success, negative
+ * values on failure.
+ *
+ */
+static int
+priv_seccomp_trap_install()
+{
+ struct sigaction signal_handler = {};
+ sigset_t signal_mask;
+
+ sigemptyset(&signal_mask);
+ sigaddset(&signal_mask, SIGSYS);
+
+ signal_handler.sa_sigaction = &priv_seccomp_trap_handler;
+ signal_handler.sa_flags = SA_SIGINFO;
+ if (sigaction(SIGSYS, &signal_handler, NULL) < 0) return -errno;
+ if (sigprocmask(SIG_UNBLOCK, &signal_mask, NULL)) return -errno;
+
+ return 0;
+}
+
+/**
+ * Initialize seccomp.
+ *
+ * @param remote file descriptor to talk with the unprivileged process
+ * @param monitored monitored child
+ * @return negative on failures or 0 if everything was setup
+ */
+int
+priv_seccomp_init(int remote, int child)
+{
+ int rc = -1;
+ scmp_filter_ctx ctx = NULL;
+
+ log_debug("seccomp", "initialize libseccomp filter");
+ monitored = child;
+ if (priv_seccomp_trap_install() < 0) {
+ log_warn("seccomp", "unable to install SIGSYS handler");
+ goto failure_scmp;
+ }
+
+ if ((ctx = seccomp_init(SCMP_ACT_TRAP)) == NULL) {
+ log_warnx("seccomp", "unable to initialize libseccomp subsystem");
+ goto failure_scmp;
+ }
+
+ if ((rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(read), 1,
+ SCMP_CMP(0, SCMP_CMP_EQ, remote))) < 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(write), 1,
+ SCMP_CMP(0, SCMP_CMP_EQ, remote))) < 0) {
+ errno = -rc;
+ log_warn("seccomp", "unable to allow read/write on remote socket");
+ goto failure_scmp;
+ }
+
+ /* We are far more generic from here. */
+ if ((rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(read), 0)) < 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(write), 0)) <
+ 0 || /* write needed for */
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(open), 0)) < 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(openat), 0)) < 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(lseek), 0)) < 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(fcntl), 0)) < 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(kill), 0)) < 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(socket), 0)) < 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(bind), 0)) < 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(setsockopt), 0)) < 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(getsockname), 0)) <
+ 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(uname), 0)) < 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(unlink), 0)) < 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(ioctl), 0)) < 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(sendmsg), 0)) < 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(sendmmsg), 0)) < 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(wait4), 0)) < 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(stat), 0)) < 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(brk), 0)) <
+ 0 || /* brk needed for newer libc */
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(getpid), 0)) < 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(rt_sigreturn), 0)) <
+ 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(close), 0)) < 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(sendto), 0)) < 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(poll), 0)) < 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(recvmsg), 0)) < 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(recvfrom), 0)) < 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(readv), 0)) < 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(mprotect), 0)) < 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(sendmmsg), 0)) < 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(clock_gettime), 0)) <
+ 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(gettimeofday), 0)) <
+ 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(newfstatat), 0)) < 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(pread64), 0)) < 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(access), 0)) < 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(rt_sigprocmask), 0)) <
+ 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(getsockopt), 0)) < 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(ppoll), 0)) < 0 ||
+ /* The following are for resolving addresses */
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(mmap), 0)) < 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(munmap), 0)) < 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(fstat), 0)) < 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(connect), 0)) < 0 ||
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(futex), 0)) < 0 ||
+
+ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(exit_group), 0)) < 0) {
+ errno = -rc;
+ log_warn("seccomp", "unable to build seccomp rules");
+ goto failure_scmp;
+ }
+
+ if ((rc = seccomp_load(ctx)) < 0) {
+ errno = -rc;
+ log_warn("seccomp", "unable to load libseccomp filter");
+ goto failure_scmp;
+ }
+
+failure_scmp:
+ seccomp_release(ctx);
+ return rc;
+}
+#endif
diff --git a/src/daemon/priv.c b/src/daemon/priv.c
new file mode 100644
index 0000000..d642328
--- /dev/null
+++ b/src/daemon/priv.c
@@ -0,0 +1,761 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2008 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/* This file contains code for privilege separation. When an error arises in
+ * monitor (which is running as root), it just stops instead of trying to
+ * recover. This module also contains proxies to privileged operations. In this
+ * case, error can be non fatal. */
+
+#include "lldpd.h"
+#include "trace.h"
+
+#include <stdio.h>
+#include <unistd.h>
+#include <signal.h>
+#include <errno.h>
+#include <limits.h>
+#include <sys/wait.h>
+#include <sys/stat.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <fcntl.h>
+#include <grp.h>
+#include <sys/utsname.h>
+#include <sys/ioctl.h>
+#include <netinet/if_ether.h>
+
+#ifdef HAVE_LINUX_CAPABILITIES
+# include <sys/capability.h>
+# include <sys/prctl.h>
+#endif
+
+#if defined HOST_OS_FREEBSD || defined HOST_OS_OSX || defined HOST_OS_DRAGONFLY
+# include <net/if_dl.h>
+#endif
+#if defined HOST_OS_SOLARIS
+# include <sys/sockio.h>
+#endif
+
+/* Use resolv.h */
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+# include <netinet/in.h>
+#endif
+#ifdef HAVE_ARPA_NAMESER_H
+# include <arpa/nameser.h> /* DNS HEADER struct */
+#endif
+#ifdef HAVE_NETDB_H
+# include <netdb.h>
+#endif
+#ifdef HAVE_RESOLV_H
+# include <resolv.h>
+#endif
+
+/* Bionic has res_init() but it's not in any header */
+#if defined HAVE_RES_INIT && defined __BIONIC__
+int res_init(void);
+#endif
+
+#ifdef ENABLE_PRIVSEP
+static int monitored = -1; /* Child */
+#endif
+
+/* Proxies */
+static void
+priv_ping()
+{
+ int rc;
+ enum priv_cmd cmd = PRIV_PING;
+ must_write(PRIV_UNPRIVILEGED, &cmd, sizeof(enum priv_cmd));
+ priv_wait();
+ must_read(PRIV_UNPRIVILEGED, &rc, sizeof(int));
+ log_debug("privsep", "monitor ready");
+}
+
+/* Proxy for ctl_cleanup */
+void
+priv_ctl_cleanup(const char *ctlname)
+{
+ int rc, len = strlen(ctlname);
+ enum priv_cmd cmd = PRIV_DELETE_CTL_SOCKET;
+ must_write(PRIV_UNPRIVILEGED, &cmd, sizeof(enum priv_cmd));
+ must_write(PRIV_UNPRIVILEGED, &len, sizeof(int));
+ must_write(PRIV_UNPRIVILEGED, ctlname, len);
+ priv_wait();
+ must_read(PRIV_UNPRIVILEGED, &rc, sizeof(int));
+}
+
+/* Proxy for gethostname */
+char *
+priv_gethostname()
+{
+ static char *buf = NULL;
+ int len;
+ enum priv_cmd cmd = PRIV_GET_HOSTNAME;
+ must_write(PRIV_UNPRIVILEGED, &cmd, sizeof(enum priv_cmd));
+ priv_wait();
+ must_read(PRIV_UNPRIVILEGED, &len, sizeof(int));
+ if (len < 0 || len > 255) fatalx("privsep", "too large value requested");
+ if ((buf = (char *)realloc(buf, len + 1)) == NULL) fatal("privsep", NULL);
+ must_read(PRIV_UNPRIVILEGED, buf, len);
+ buf[len] = '\0';
+ return buf;
+}
+
+int
+priv_iface_init(int index, char *iface)
+{
+ int rc;
+ char dev[IFNAMSIZ] = {};
+ enum priv_cmd cmd = PRIV_IFACE_INIT;
+ must_write(PRIV_UNPRIVILEGED, &cmd, sizeof(enum priv_cmd));
+ must_write(PRIV_UNPRIVILEGED, &index, sizeof(int));
+ strlcpy(dev, iface, IFNAMSIZ);
+ must_write(PRIV_UNPRIVILEGED, dev, IFNAMSIZ);
+ priv_wait();
+ must_read(PRIV_UNPRIVILEGED, &rc, sizeof(int));
+ if (rc != 0) return -1;
+ return receive_fd(PRIV_UNPRIVILEGED);
+}
+
+int
+priv_iface_multicast(const char *name, const u_int8_t *mac, int add)
+{
+ int rc;
+ enum priv_cmd cmd = PRIV_IFACE_MULTICAST;
+ must_write(PRIV_UNPRIVILEGED, &cmd, sizeof(enum priv_cmd));
+ must_write(PRIV_UNPRIVILEGED, name, IFNAMSIZ);
+ must_write(PRIV_UNPRIVILEGED, mac, ETHER_ADDR_LEN);
+ must_write(PRIV_UNPRIVILEGED, &add, sizeof(int));
+ priv_wait();
+ must_read(PRIV_UNPRIVILEGED, &rc, sizeof(int));
+ return rc;
+}
+
+int
+priv_iface_description(const char *name, const char *description)
+{
+ int rc, len = strlen(description);
+ enum priv_cmd cmd = PRIV_IFACE_DESCRIPTION;
+ must_write(PRIV_UNPRIVILEGED, &cmd, sizeof(enum priv_cmd));
+ must_write(PRIV_UNPRIVILEGED, name, IFNAMSIZ);
+ must_write(PRIV_UNPRIVILEGED, &len, sizeof(int));
+ must_write(PRIV_UNPRIVILEGED, description, len);
+ priv_wait();
+ must_read(PRIV_UNPRIVILEGED, &rc, sizeof(int));
+ return rc;
+}
+
+/* Proxy to set interface in promiscuous mode */
+int
+priv_iface_promisc(const char *ifname)
+{
+ int rc;
+ enum priv_cmd cmd = PRIV_IFACE_PROMISC;
+ must_write(PRIV_UNPRIVILEGED, &cmd, sizeof(enum priv_cmd));
+ must_write(PRIV_UNPRIVILEGED, ifname, IFNAMSIZ);
+ priv_wait();
+ must_read(PRIV_UNPRIVILEGED, &rc, sizeof(int));
+ return rc;
+}
+
+int
+priv_snmp_socket(struct sockaddr_un *addr)
+{
+ int rc;
+ enum priv_cmd cmd = PRIV_SNMP_SOCKET;
+ must_write(PRIV_UNPRIVILEGED, &cmd, sizeof(enum priv_cmd));
+ must_write(PRIV_UNPRIVILEGED, addr, sizeof(struct sockaddr_un));
+ priv_wait();
+ must_read(PRIV_UNPRIVILEGED, &rc, sizeof(int));
+ if (rc < 0) return rc;
+ return receive_fd(PRIV_UNPRIVILEGED);
+}
+
+static void
+asroot_ping()
+{
+ int rc = 1;
+ must_write(PRIV_PRIVILEGED, &rc, sizeof(int));
+}
+
+static void
+asroot_ctl_cleanup()
+{
+ int len;
+ char *ctlname;
+ int rc = 0;
+
+ must_read(PRIV_PRIVILEGED, &len, sizeof(int));
+ if (len < 0 || len > PATH_MAX) fatalx("privsep", "too large value requested");
+ if ((ctlname = (char *)malloc(len + 1)) == NULL) fatal("privsep", NULL);
+
+ must_read(PRIV_PRIVILEGED, ctlname, len);
+ ctlname[len] = 0;
+
+ ctl_cleanup(ctlname);
+ free(ctlname);
+
+ /* Ack */
+ must_write(PRIV_PRIVILEGED, &rc, sizeof(int));
+}
+
+static void
+asroot_gethostname()
+{
+ struct utsname un;
+ struct addrinfo hints = { .ai_flags = AI_CANONNAME };
+ struct addrinfo *res;
+ int len;
+ if (uname(&un) < 0) fatal("privsep", "failed to get system information");
+ if (getaddrinfo(un.nodename, NULL, &hints, &res) != 0) {
+ log_info("privsep", "unable to get system name");
+#ifdef HAVE_RES_INIT
+ res_init();
+#endif
+ len = strlen(un.nodename);
+ must_write(PRIV_PRIVILEGED, &len, sizeof(int));
+ must_write(PRIV_PRIVILEGED, un.nodename, len);
+ } else {
+ len = strlen(res->ai_canonname);
+ must_write(PRIV_PRIVILEGED, &len, sizeof(int));
+ must_write(PRIV_PRIVILEGED, res->ai_canonname, len);
+ freeaddrinfo(res);
+ }
+}
+
+static void
+asroot_iface_init()
+{
+ int rc = -1, fd = -1;
+ int ifindex;
+ char name[IFNAMSIZ];
+ must_read(PRIV_PRIVILEGED, &ifindex, sizeof(ifindex));
+ must_read(PRIV_PRIVILEGED, &name, sizeof(name));
+ name[sizeof(name) - 1] = '\0';
+
+ TRACE(LLDPD_PRIV_INTERFACE_INIT(name));
+ rc = asroot_iface_init_os(ifindex, name, &fd);
+ must_write(PRIV_PRIVILEGED, &rc, sizeof(rc));
+ if (rc == 0 && fd >= 0) send_fd(PRIV_PRIVILEGED, fd);
+ if (fd >= 0) close(fd);
+}
+
+static void
+asroot_iface_multicast()
+{
+ int sock = -1, add, rc = 0;
+ struct ifreq ifr = { .ifr_name = {} };
+ must_read(PRIV_PRIVILEGED, ifr.ifr_name, IFNAMSIZ);
+#if defined HOST_OS_LINUX
+ must_read(PRIV_PRIVILEGED, ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN);
+#elif defined HOST_OS_FREEBSD || defined HOST_OS_OSX || defined HOST_OS_DRAGONFLY
+ /* Black magic from mtest.c */
+ struct sockaddr_dl *dlp = ALIGNED_CAST(struct sockaddr_dl *, &ifr.ifr_addr);
+ dlp->sdl_len = sizeof(struct sockaddr_dl);
+ dlp->sdl_family = AF_LINK;
+ dlp->sdl_index = 0;
+ dlp->sdl_nlen = 0;
+ dlp->sdl_alen = ETHER_ADDR_LEN;
+ dlp->sdl_slen = 0;
+ must_read(PRIV_PRIVILEGED, LLADDR(dlp), ETHER_ADDR_LEN);
+#elif defined HOST_OS_OPENBSD || defined HOST_OS_NETBSD || defined HOST_OS_SOLARIS
+ struct sockaddr *sap = (struct sockaddr *)&ifr.ifr_addr;
+# if !defined HOST_OS_SOLARIS
+ sap->sa_len = sizeof(struct sockaddr);
+# endif
+ sap->sa_family = AF_UNSPEC;
+ must_read(PRIV_PRIVILEGED, sap->sa_data, ETHER_ADDR_LEN);
+#else
+# error Unsupported OS
+#endif
+
+ must_read(PRIV_PRIVILEGED, &add, sizeof(int));
+ if (((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) ||
+ ((ioctl(sock, (add) ? SIOCADDMULTI : SIOCDELMULTI, &ifr) < 0) &&
+ (errno != EADDRINUSE)))
+ rc = errno;
+
+ if (sock != -1) close(sock);
+ must_write(PRIV_PRIVILEGED, &rc, sizeof(rc));
+}
+
+static void
+asroot_iface_description()
+{
+ char name[IFNAMSIZ];
+ char *description;
+ int len, rc;
+ must_read(PRIV_PRIVILEGED, &name, sizeof(name));
+ name[sizeof(name) - 1] = '\0';
+ must_read(PRIV_PRIVILEGED, &len, sizeof(int));
+ if (len < 0 || len > PATH_MAX) fatalx("privsep", "too large value requested");
+ if ((description = (char *)malloc(len + 1)) == NULL) fatal("privsep", NULL);
+
+ must_read(PRIV_PRIVILEGED, description, len);
+ description[len] = 0;
+ TRACE(LLDPD_PRIV_INTERFACE_DESCRIPTION(name, description));
+ rc = asroot_iface_description_os(name, description);
+ must_write(PRIV_PRIVILEGED, &rc, sizeof(rc));
+ free(description);
+}
+
+static void
+asroot_iface_promisc()
+{
+ char name[IFNAMSIZ];
+ int rc;
+ must_read(PRIV_PRIVILEGED, &name, sizeof(name));
+ name[sizeof(name) - 1] = '\0';
+ rc = asroot_iface_promisc_os(name);
+ must_write(PRIV_PRIVILEGED, &rc, sizeof(rc));
+}
+
+static void
+asroot_snmp_socket()
+{
+ int sock, rc;
+ static struct sockaddr_un *addr = NULL;
+ struct sockaddr_un bogus;
+
+ if (!addr) {
+ addr = (struct sockaddr_un *)malloc(sizeof(struct sockaddr_un));
+ if (!addr) fatal("privsep", NULL);
+ must_read(PRIV_PRIVILEGED, addr, sizeof(struct sockaddr_un));
+ } else
+ /* We have already been asked to connect to a socket. We will
+ * connect to the same socket. */
+ must_read(PRIV_PRIVILEGED, &bogus, sizeof(struct sockaddr_un));
+ if (addr->sun_family != AF_UNIX)
+ fatal("privsep", "someone is trying to trick me");
+ addr->sun_path[sizeof(addr->sun_path) - 1] = '\0';
+
+ if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
+ log_warn("privsep", "cannot open socket");
+ must_write(PRIV_PRIVILEGED, &sock, sizeof(int));
+ return;
+ }
+ if ((rc = connect(sock, (struct sockaddr *)addr, sizeof(struct sockaddr_un))) !=
+ 0) {
+ log_info("privsep", "cannot connect to %s: %s", addr->sun_path,
+ strerror(errno));
+ close(sock);
+ rc = -1;
+ must_write(PRIV_PRIVILEGED, &rc, sizeof(int));
+ return;
+ }
+
+ int flags;
+ if ((flags = fcntl(sock, F_GETFL, NULL)) < 0 ||
+ fcntl(sock, F_SETFL, flags | O_NONBLOCK) < 0) {
+ log_warn("privsep", "cannot set sock %s to non-block : %s",
+ addr->sun_path, strerror(errno));
+
+ close(sock);
+ rc = -1;
+ must_write(PRIV_PRIVILEGED, &rc, sizeof(int));
+ return;
+ }
+
+ must_write(PRIV_PRIVILEGED, &rc, sizeof(int));
+ send_fd(PRIV_PRIVILEGED, sock);
+ close(sock);
+}
+
+struct dispatch_actions {
+ enum priv_cmd msg;
+ void (*function)(void);
+};
+
+static struct dispatch_actions actions[] = { { PRIV_PING, asroot_ping },
+ { PRIV_DELETE_CTL_SOCKET, asroot_ctl_cleanup },
+ { PRIV_GET_HOSTNAME, asroot_gethostname },
+#ifdef HOST_OS_LINUX
+ { PRIV_OPEN, asroot_open },
+#endif
+ { PRIV_IFACE_INIT, asroot_iface_init },
+ { PRIV_IFACE_MULTICAST, asroot_iface_multicast },
+ { PRIV_IFACE_DESCRIPTION, asroot_iface_description },
+ { PRIV_IFACE_PROMISC, asroot_iface_promisc },
+ { PRIV_SNMP_SOCKET, asroot_snmp_socket }, { -1, NULL } };
+
+/* Main loop, run as root */
+static void
+priv_loop(int privileged, int once)
+{
+ enum priv_cmd cmd;
+ struct dispatch_actions *a;
+
+#ifdef ENABLE_PRIVSEP
+ setproctitle("monitor.");
+# ifdef USE_SECCOMP
+ if (priv_seccomp_init(privileged, monitored) != 0)
+ fatal("privsep", "cannot continue without seccomp setup");
+# endif
+#endif
+ while (!may_read(PRIV_PRIVILEGED, &cmd, sizeof(enum priv_cmd))) {
+ log_debug("privsep", "received command %d", cmd);
+ for (a = actions; a->function != NULL; a++) {
+ if (cmd == a->msg) {
+ a->function();
+ break;
+ }
+ }
+ if (a->function == NULL) fatalx("privsep", "bogus message received");
+ if (once) break;
+ }
+}
+
+/* This function is a NOOP when privilege separation is enabled. In
+ * the other case, it should be called when we wait an action from the
+ * privileged side. */
+void
+priv_wait()
+{
+#ifndef ENABLE_PRIVSEP
+ /* We have no remote process on the other side. Let's emulate it. */
+ priv_loop(0, 1);
+#endif
+}
+
+#ifdef ENABLE_PRIVSEP
+static void
+priv_exit_rc_status(int rc, int status)
+{
+ switch (rc) {
+ case 0:
+ /* kill child */
+ kill(monitored, SIGTERM);
+ /* we will receive a sigchld in the future */
+ return;
+ case -1:
+ /* child doesn't exist anymore, we consider this is an error to
+ * be here */
+ _exit(1);
+ break;
+ default:
+ /* Monitored child has terminated */
+ /* Mimic the exit state of the child */
+ if (WIFEXITED(status)) {
+ /* Normal exit */
+ _exit(WEXITSTATUS(status));
+ }
+ if (WIFSIGNALED(status)) {
+ /* Terminated with signal */
+ signal(WTERMSIG(status), SIG_DFL);
+ raise(WTERMSIG(status));
+ _exit(1); /* We consider that not being killed is an error. */
+ }
+ /* Other cases, consider this as an error. */
+ _exit(1);
+ break;
+ }
+}
+
+static void
+priv_exit()
+{
+ int status;
+ int rc;
+ rc = waitpid(monitored, &status, WNOHANG);
+ priv_exit_rc_status(rc, status);
+}
+
+/* If priv parent gets a TERM or HUP, pass it through to child instead */
+static void
+sig_pass_to_chld(int sig)
+{
+ int oerrno = errno;
+ if (monitored != -1) kill(monitored, sig);
+ errno = oerrno;
+}
+
+/* If priv parent gets a SIGCHLD, it will exit if this is the monitored
+ * process. Other processes (including lldpcli)) are just reaped without
+ * consequences. */
+static void
+sig_chld(int sig)
+{
+ int status;
+ int rc = waitpid(monitored, &status, WNOHANG);
+ if (rc == 0) {
+ while ((rc = waitpid(-1, &status, WNOHANG)) > 0) {
+ if (rc == monitored) priv_exit_rc_status(rc, status);
+ }
+ return;
+ }
+ priv_exit_rc_status(rc, status);
+}
+
+/* Create a subdirectory and check if it's here. */
+static int
+_mkdir(const char *pathname, mode_t mode)
+{
+ int save_errno;
+ if (mkdir(pathname, mode) == 0 || errno == EEXIST) {
+ errno = 0;
+ return 0;
+ }
+
+ /* We can get EROFS on some platforms. Let's check if the directory exists. */
+ save_errno = errno;
+ if (chdir(pathname) == -1) {
+ errno = save_errno;
+ return -1;
+ }
+
+ /* We should restore current directory, but in the context we are
+ * running, we do not care. */
+ return 0;
+}
+
+/* Create a directory recursively. */
+static int
+mkdir_p(const char *pathname, mode_t mode)
+{
+ char path[PATH_MAX + 1];
+ char *current;
+
+ if (strlcpy(path, pathname, sizeof(path)) >= sizeof(path)) {
+ errno = ENAMETOOLONG;
+ return -1;
+ }
+
+ /* Use strtok which will provides non-empty tokens only. */
+ for (current = path + 1; *current; current++) {
+ if (*current != '/') continue;
+ *current = '\0';
+ if (_mkdir(path, mode) != 0) return -1;
+ *current = '/';
+ }
+ if (_mkdir(path, mode) != 0) return -1;
+
+ return 0;
+}
+
+/* Initialization */
+# define LOCALTIME "/etc/localtime"
+static void
+priv_setup_chroot(const char *chrootdir)
+{
+ /* Create chroot if it does not exist */
+ if (mkdir_p(chrootdir, 0755) == -1) {
+ fatal("privsep", "unable to create chroot directory");
+ }
+
+ /* Check if /etc/localtime exists in chroot or outside chroot */
+ char path[1024];
+ int source = -1, destination = -1;
+ if (snprintf(path, sizeof(path), "%s" LOCALTIME, chrootdir) >= sizeof(path))
+ return;
+ if ((source = open(LOCALTIME, O_RDONLY)) == -1) {
+ if (errno == ENOENT) return;
+ log_warn("privsep", "cannot read " LOCALTIME);
+ return;
+ }
+
+ /* Prepare copy of /etc/localtime */
+ path[strlen(chrootdir) + 4] = '\0';
+ if (mkdir(path, 0755) == -1) {
+ if (errno != EEXIST) {
+ log_warn("privsep", "unable to create %s directory", path);
+ close(source);
+ return;
+ }
+ }
+ path[strlen(chrootdir) + 4] = '/';
+
+ /* Do copy */
+ char buffer[1024];
+ ssize_t n;
+ mode_t old = umask(S_IWGRP | S_IWOTH);
+ if ((destination = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0666)) ==
+ -1) {
+ if (errno != EEXIST) log_warn("privsep", "cannot create %s", path);
+ close(source);
+ umask(old);
+ return;
+ }
+ umask(old);
+ while ((n = read(source, buffer, sizeof(buffer))) > 0) {
+ ssize_t nw, left = n;
+ char *p = buffer;
+ while (left > 0) {
+ if ((nw = write(destination, p, left)) == -1) {
+ if (errno == EINTR) continue;
+ log_warn("privsep", "cannot write to %s", path);
+ close(source);
+ close(destination);
+ unlink(path);
+ return;
+ }
+ left -= nw;
+ p += nw;
+ }
+ }
+ if (n == -1) {
+ log_warn("privsep", "cannot read " LOCALTIME);
+ unlink(path);
+ } else {
+ log_info("privsep", LOCALTIME " copied to chroot");
+ }
+ close(source);
+ close(destination);
+}
+#else /* !ENABLE_PRIVSEP */
+
+/* Reap any children. It should only be lldpcli since there is not monitored
+ * process. */
+static void
+sig_chld(int sig)
+{
+ int status = 0;
+ while (waitpid(-1, &status, WNOHANG) > 0)
+ ;
+}
+
+#endif
+
+#ifdef ENABLE_PRIVSEP
+static void
+priv_drop(uid_t uid, gid_t gid)
+{
+ gid_t gidset[1];
+ gidset[0] = gid;
+ log_debug("privsep", "dropping privileges");
+# ifdef HAVE_SETRESGID
+ if (setresgid(gid, gid, gid) == -1) fatal("privsep", "setresgid() failed");
+# else
+ if (setregid(gid, gid) == -1) fatal("privsep", "setregid() failed");
+# endif
+ if (setgroups(1, gidset) == -1) fatal("privsep", "setgroups() failed");
+# ifdef HAVE_SETRESUID
+ if (setresuid(uid, uid, uid) == -1) fatal("privsep", "setresuid() failed");
+# else
+ if (setreuid(uid, uid) == -1) fatal("privsep", "setreuid() failed");
+# endif
+}
+
+static void
+priv_caps(uid_t uid, gid_t gid)
+{
+# ifdef HAVE_LINUX_CAPABILITIES
+ cap_t caps;
+ const char *caps_strings[2] = {
+ "cap_dac_override,cap_net_raw,cap_net_admin,cap_setuid,cap_setgid=pe",
+ "cap_dac_override,cap_net_raw,cap_net_admin=pe"
+ };
+ log_debug("privsep",
+ "getting CAP_NET_RAW/ADMIN and CAP_DAC_OVERRIDE privilege");
+ if (!(caps = cap_from_text(caps_strings[0])))
+ fatal("privsep", "unable to convert caps");
+ if (cap_set_proc(caps) == -1) {
+ log_warn("privsep",
+ "unable to drop privileges, monitor running as root");
+ cap_free(caps);
+ return;
+ }
+ cap_free(caps);
+
+ if (prctl(PR_SET_KEEPCAPS, 1L, 0L, 0L, 0L) == -1)
+ fatal("privsep", "cannot keep capabilities");
+ priv_drop(uid, gid);
+
+ log_debug("privsep", "dropping extra capabilities");
+ if (!(caps = cap_from_text(caps_strings[1])))
+ fatal("privsep", "unable to convert caps");
+ if (cap_set_proc(caps) == -1)
+ fatal("privsep", "unable to drop extra privileges");
+ cap_free(caps);
+# else
+ log_info("privsep", "no libcap support, running monitor as root");
+# endif
+}
+#endif
+
+void
+#ifdef ENABLE_PRIVSEP
+priv_init(const char *chrootdir, int ctl, uid_t uid, gid_t gid)
+#else
+priv_init(void)
+#endif
+{
+
+ int pair[2];
+
+ /* Create socket pair */
+ if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pair) < 0) {
+ fatal("privsep",
+ "unable to create socket pair for privilege separation");
+ }
+
+ priv_unprivileged_fd(pair[0]);
+ priv_privileged_fd(pair[1]);
+
+#ifdef ENABLE_PRIVSEP
+ /* Spawn off monitor */
+ if ((monitored = fork()) < 0) fatal("privsep", "unable to fork monitor");
+ switch (monitored) {
+ case 0:
+ /* We are in the children, drop privileges */
+ if (RUNNING_ON_VALGRIND)
+ log_warnx("privsep", "running on valgrind, keep privileges");
+ else {
+ priv_setup_chroot(chrootdir);
+ if (chroot(chrootdir) == -1)
+ fatal("privsep", "unable to chroot");
+ if (chdir("/") != 0) fatal("privsep", "unable to chdir");
+ priv_drop(uid, gid);
+ }
+ close(pair[1]);
+ priv_ping();
+ break;
+ default:
+ /* We are in the monitor */
+ if (ctl != -1) close(ctl);
+ close(pair[0]);
+ if (atexit(priv_exit) != 0)
+ fatal("privsep", "unable to set exit function");
+
+ priv_caps(uid, gid);
+
+ /* Install signal handlers */
+ const struct sigaction pass_to_child = { .sa_handler = sig_pass_to_chld,
+ .sa_flags = SA_RESTART };
+ sigaction(SIGALRM, &pass_to_child, NULL);
+ sigaction(SIGTERM, &pass_to_child, NULL);
+ sigaction(SIGHUP, &pass_to_child, NULL);
+ sigaction(SIGINT, &pass_to_child, NULL);
+ sigaction(SIGQUIT, &pass_to_child, NULL);
+ const struct sigaction child = { .sa_handler = sig_chld,
+ .sa_flags = SA_RESTART };
+ sigaction(SIGCHLD, &child, NULL);
+ sig_chld(0); /* Reap already dead children */
+ priv_loop(pair[1], 0);
+ exit(0);
+ }
+#else
+ const struct sigaction child = { .sa_handler = sig_chld,
+ .sa_flags = SA_RESTART };
+ sigaction(SIGCHLD, &child, NULL);
+ sig_chld(0); /* Reap already dead children */
+ log_warnx("priv", "no privilege separation available");
+ priv_ping();
+#endif
+}
diff --git a/src/daemon/privsep.c b/src/daemon/privsep.c
new file mode 100644
index 0000000..04c49a9
--- /dev/null
+++ b/src/daemon/privsep.c
@@ -0,0 +1,26 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+
+#include "lldpd.h"
+
+static int privileged, unprivileged;
+void
+priv_privileged_fd(int fd)
+{
+ privileged = fd;
+}
+void
+priv_unprivileged_fd(int fd)
+{
+ unprivileged = fd;
+}
+int
+priv_fd(enum priv_context ctx)
+{
+ switch (ctx) {
+ case PRIV_PRIVILEGED:
+ return privileged;
+ case PRIV_UNPRIVILEGED:
+ return unprivileged;
+ }
+ return -1; /* Not possible */
+}
diff --git a/src/daemon/privsep_fd.c b/src/daemon/privsep_fd.c
new file mode 100644
index 0000000..fa98663
--- /dev/null
+++ b/src/daemon/privsep_fd.c
@@ -0,0 +1,129 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+
+#include "lldpd.h"
+
+#include <sys/param.h>
+#include <sys/uio.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+/*
+ * Copyright 2001 Niels Provos <provos@citi.umich.edu>
+ * All rights reserved.
+ *
+ * Copyright (c) 2002 Matthieu Herrb
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+void
+send_fd(enum priv_context ctx, int fd)
+{
+ struct msghdr msg;
+ union {
+ struct cmsghdr hdr;
+ char buf[CMSG_SPACE(sizeof(int))];
+ } cmsgbuf;
+ struct cmsghdr *cmsg;
+ struct iovec vec;
+ int result = 0;
+ ssize_t n;
+
+ memset(&msg, 0, sizeof(msg));
+ memset(&cmsgbuf.buf, 0, sizeof(cmsgbuf.buf));
+
+ if (fd >= 0) {
+ msg.msg_control = (caddr_t)&cmsgbuf.buf;
+ msg.msg_controllen = sizeof(cmsgbuf.buf);
+ cmsg = CMSG_FIRSTHDR(&msg);
+ cmsg->cmsg_len = CMSG_LEN(sizeof(int));
+ cmsg->cmsg_level = SOL_SOCKET;
+ cmsg->cmsg_type = SCM_RIGHTS;
+ memcpy(CMSG_DATA(cmsg), &fd, sizeof(int));
+ } else {
+ result = errno;
+ }
+
+ vec.iov_base = &result;
+ vec.iov_len = sizeof(int);
+ msg.msg_iov = &vec;
+ msg.msg_iovlen = 1;
+
+ if ((n = sendmsg(priv_fd(ctx), &msg, 0)) == -1)
+ log_warn("privsep", "sendmsg(%d)", priv_fd(ctx));
+ if (n != sizeof(int))
+ log_warnx("privsep", "sendmsg: expected sent 1 got %ld", (long)n);
+}
+
+int
+receive_fd(enum priv_context ctx)
+{
+ struct msghdr msg;
+ union {
+ struct cmsghdr hdr;
+ char buf[CMSG_SPACE(sizeof(int))];
+ } cmsgbuf;
+ struct cmsghdr *cmsg;
+ struct iovec vec;
+ ssize_t n;
+ int result;
+ int fd;
+
+ memset(&msg, 0, sizeof(msg));
+ vec.iov_base = &result;
+ vec.iov_len = sizeof(int);
+ msg.msg_iov = &vec;
+ msg.msg_iovlen = 1;
+ msg.msg_control = &cmsgbuf.buf;
+ msg.msg_controllen = sizeof(cmsgbuf.buf);
+
+ if ((n = recvmsg(priv_fd(ctx), &msg, 0)) == -1) log_warn("privsep", "recvmsg");
+ if (n != sizeof(int))
+ log_warnx("privsep", "recvmsg: expected received 1 got %ld", (long)n);
+ if (result == 0) {
+ cmsg = CMSG_FIRSTHDR(&msg);
+ if (cmsg == NULL) {
+ log_warnx("privsep", "no message header");
+ return -1;
+ }
+ if (cmsg->cmsg_type != SCM_RIGHTS)
+ log_warnx("privsep", "expected type %d got %d", SCM_RIGHTS,
+ cmsg->cmsg_type);
+ memcpy(&fd, CMSG_DATA(cmsg), sizeof(int));
+ return fd;
+ } else {
+ errno = result;
+ return -1;
+ }
+}
diff --git a/src/daemon/privsep_io.c b/src/daemon/privsep_io.c
new file mode 100644
index 0000000..9d0923a
--- /dev/null
+++ b/src/daemon/privsep_io.c
@@ -0,0 +1,100 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+
+#include "lldpd.h"
+
+#include <sys/param.h>
+#include <sys/uio.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+/* Stolen from sbin/pflogd/privsep.c from OpenBSD */
+/*
+ * Copyright (c) 2003 Can Erkin Acar
+ * Copyright (c) 2003 Anil Madhavapeddy <anil@recoil.org>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/* Read all data or return 1 for error. */
+int
+may_read(enum priv_context ctx, void *buf, size_t n)
+{
+ char *s = buf;
+ ssize_t res, pos = 0;
+
+ while (n > pos) {
+ res = read(priv_fd(ctx), s + pos, n - pos);
+ switch (res) {
+ case -1:
+ if (errno == EINTR || errno == EAGAIN) continue;
+ return 1;
+ case 0:
+ return 1;
+ default:
+ pos += res;
+ }
+ }
+ return (0);
+}
+
+/* Read data with the assertion that it all must come through, or
+ * else abort the process. Based on atomicio() from openssh. */
+void
+must_read(enum priv_context ctx, void *buf, size_t n)
+{
+ char *s = buf;
+ ssize_t res, pos = 0;
+
+ while (n > pos) {
+ res = read(priv_fd(ctx), s + pos, n - pos);
+ switch (res) {
+ case -1:
+ if (errno == EINTR || errno == EAGAIN) continue;
+ _exit(0);
+ case 0:
+ _exit(0);
+ default:
+ pos += res;
+ }
+ }
+}
+
+/* Write data with the assertion that it all has to be written, or
+ * else abort the process. Based on atomicio() from openssh. */
+void
+must_write(enum priv_context ctx, const void *buf, size_t n)
+{
+ const char *s = buf;
+ ssize_t res, pos = 0;
+
+ while (n > pos) {
+ res = write(priv_fd(ctx), s + pos, n - pos);
+ switch (res) {
+ case -1:
+ if (errno == EINTR || errno == EAGAIN) continue;
+ _exit(0);
+ case 0:
+ _exit(0);
+ default:
+ pos += res;
+ }
+ }
+}
diff --git a/src/daemon/probes.d b/src/daemon/probes.d
new file mode 100644
index 0000000..a4d7785
--- /dev/null
+++ b/src/daemon/probes.d
@@ -0,0 +1,115 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2013 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+provider lldpd {
+
+ /**
+ * Fired when a frame is received, before it is decoded.
+ * @param ifname the name of the interface
+ * @param frame the received frame
+ * @param len the len of the received frame
+ */
+ probe frame_received(char *ifname, void *frame, size_t len);
+
+ /**
+ * Fired when a frame is decoded.
+ * @param ifname the name of the interface
+ * @param protocol the name of the protocol
+ * @param chassis_name the name of chassis (may be NULL)
+ * @param port_descr the description of the port (may be NULL)
+ */
+ probe frame_decoded(char *ifname, char *protocol, char *chassis_name, char *port_descr);
+
+ /**
+ * Fired when a frame is sent.
+ * @param ifname the name of the interface
+ * @param protocol the name of the protocol
+ */
+ probe frame_send(char *ifname, char *protocol);
+
+ /**
+ * Fired when a neighbor is added.
+ * @param ifname the name of the interface where the neighbor appeared
+ * @param chassis_name the name of chassis (may be NULL)
+ * @param port_descr the description of the port (may be NULL)
+ * @param count the total number of neighbors known
+ */
+ probe neighbor_new(char *ifname, char *chassis_name, char *port_descr, int count);
+
+ /**
+ * Fired when a neighbor is updated.
+ * @param ifname the name of the interface where the neighbor updated
+ * @param chassis_name the name of chassis (may be NULL)
+ * @param port_descr the description of the port (may be NULL)
+ * @param count the total number of neighbors known
+ */
+ probe neighbor_update(char *ifname, char *chassis_name, char *port_descr, int count);
+
+ /**
+ * Fired when a neighbor is deleted.
+ * @param ifname the name of the interface where the neighbor deleted
+ * @param chassis_name the name of chassis (may be NULL)
+ * @param port_descr the description of the port (may be NULL)
+ * @param count the total number of neighbors known
+ */
+ probe neighbor_delete(char *ifname, char *chassis_name, char *port_descr);
+
+ /**
+ * Fired before handling a client request.
+ * @param name the name of the request
+ */
+ probe client_request(char *name);
+
+ /**
+ * Fired for each iteration of the event loop.
+ */
+ probe event_loop();
+
+ /**
+ * Fired when initializing a new interface in privileged mode.
+ * @param name the name of the interface
+ */
+ probe priv_interface_init(char *name);
+
+ /**
+ * Fired when setting description of an interface.
+ * @param name the name of the interface
+ * @param desc the description of the interface
+ */
+ probe priv_interface_description(char *name, char *description);
+
+ /**
+ * Fired when doing an interface updates.
+ */
+ probe interfaces_update();
+
+ /**
+ * Fired when receiving an interface update notification.
+ */
+ probe interfaces_notification();
+
+ /**
+ * Fired when an interface is removed.
+ * @param name the name of the interface
+ */
+ probe interfaces_delete(char *name);
+
+ /**
+ * Fired when an interface is added.
+ * @param name the name of the interface
+ */
+ probe interfaces_new(char *name);
+};
diff --git a/src/daemon/protocols/cdp.c b/src/daemon/protocols/cdp.c
new file mode 100644
index 0000000..620455b
--- /dev/null
+++ b/src/daemon/protocols/cdp.c
@@ -0,0 +1,711 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2008 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/* We also supports FDP which is very similar to CDPv1 */
+#include "../lldpd.h"
+#include "../frame.h"
+
+/*
+ * CDP Requests Power at the switch output and therefore has to take into
+ * account the loss in the PoE cable. This is done by the switch automatically
+ * if lldp is used as the protocol.
+ */
+#define CDP_CLASS_3_MAX_PSE_POE 154 /* 15.4W Max PoE at PSE class 3 */
+#define CDP_SWTICH_DEFAULT_POE_PD 130 /* 13.W default PoE at PD */
+#define CDP_SWTICH_DEFAULT_POE_PSE 154 /* 15.4W default PoE at PSE */
+#define CDP_SWITCH_POE_CLASS_4_OFFSET 45 /* 4.5W max loss from cable */
+#define CDP_SWITCH_POE_CLASS_3_OFFSET 24 /* 2.4W max loss from cable */
+
+#if defined ENABLE_CDP || defined ENABLE_FDP
+
+# include <stdio.h>
+# include <unistd.h>
+# include <errno.h>
+# include <arpa/inet.h>
+
+static int
+cdp_send(struct lldpd *global, struct lldpd_hardware *hardware, int version)
+{
+ const char *platform = "Unknown";
+ struct lldpd_chassis *chassis;
+ struct lldpd_mgmt *mgmt;
+ struct lldpd_port *port;
+ u_int8_t mcastaddr[] = CDP_MULTICAST_ADDR;
+ u_int8_t llcorg[] = LLC_ORG_CISCO;
+# ifdef ENABLE_FDP
+ const char *capstr;
+# endif
+ u_int16_t checksum;
+ int length, i;
+ u_int32_t cap;
+ u_int8_t *packet;
+ u_int8_t *pos, *pos_len_eh, *pos_llc, *pos_cdp, *pos_checksum, *tlv, *end;
+
+ log_debug("cdp", "send CDP frame on %s", hardware->h_ifname);
+
+ port = &(hardware->h_lport);
+ chassis = port->p_chassis;
+
+# ifdef ENABLE_FDP
+ if (version == 0) {
+ /* With FDP, change multicast address and LLC PID */
+ const u_int8_t fdpmcastaddr[] = FDP_MULTICAST_ADDR;
+ const u_int8_t fdpllcorg[] = LLC_ORG_FOUNDRY;
+ memcpy(mcastaddr, fdpmcastaddr, sizeof(mcastaddr));
+ memcpy(llcorg, fdpllcorg, sizeof(llcorg));
+ }
+# endif
+
+ length = hardware->h_mtu;
+ if ((packet = (u_int8_t *)calloc(1, length)) == NULL) return ENOMEM;
+ pos = packet;
+
+ /* Ethernet header */
+ if (!(POKE_BYTES(mcastaddr, sizeof(mcastaddr)) &&
+ POKE_BYTES(&hardware->h_lladdr, ETHER_ADDR_LEN) &&
+ POKE_SAVE(pos_len_eh) && /* We compute the len later */
+ POKE_UINT16(0)))
+ goto toobig;
+
+ /* LLC */
+ if (!(POKE_SAVE(pos_llc) && POKE_UINT8(0xaa) && /* SSAP */
+ POKE_UINT8(0xaa) && /* DSAP */
+ POKE_UINT8(0x03) && /* Control field */
+ POKE_BYTES(llcorg, sizeof(llcorg)) && POKE_UINT16(LLC_PID_CDP)))
+ goto toobig;
+
+ /* CDP header */
+ if (!(POKE_SAVE(pos_cdp) && POKE_UINT8((version == 0) ? 1 : version) &&
+ POKE_UINT8(global ? global->g_config.c_ttl : 180) &&
+ POKE_SAVE(pos_checksum) && /* Save checksum position */
+ POKE_UINT16(0)))
+ goto toobig;
+
+ /* Chassis ID */
+ const char *chassis_name = chassis->c_name ? chassis->c_name : "";
+ if (!(POKE_START_CDP_TLV(CDP_TLV_CHASSIS) &&
+ POKE_BYTES(chassis_name, strlen(chassis_name)) && POKE_END_CDP_TLV))
+ goto toobig;
+
+ /* Adresses */
+ /* See:
+ * http://www.cisco.com/univercd/cc/td/doc/product/lan/trsrb/frames.htm#xtocid12
+ *
+ * It seems that Cisco implies that CDP supports IPv6 using
+ * 802.2 address format with 0xAAAA03 0x000000 0x0800, but
+ * 0x0800 is the Ethernet protocol type for IPv4. Therefore,
+ * we support only IPv4. */
+ i = 0;
+ TAILQ_FOREACH (mgmt, &chassis->c_mgmt, m_entries)
+ if (mgmt->m_family == LLDPD_AF_IPV4) i++;
+ if (i > 0) {
+ if (!(POKE_START_CDP_TLV(CDP_TLV_ADDRESSES) && POKE_UINT32(i)))
+ goto toobig;
+ TAILQ_FOREACH (mgmt, &chassis->c_mgmt, m_entries) {
+ switch (mgmt->m_family) {
+ case LLDPD_AF_IPV4:
+ if (!(POKE_UINT8(1) && /* Type: NLPID */
+ POKE_UINT8(1) && /* Length: 1 */
+ POKE_UINT8(CDP_ADDRESS_PROTO_IP) && /* IP */
+ POKE_UINT16(sizeof(
+ struct in_addr)) && /* Address length */
+ POKE_BYTES(&mgmt->m_addr,
+ sizeof(struct in_addr))))
+ goto toobig;
+ break;
+ }
+ }
+ if (!(POKE_END_CDP_TLV)) goto toobig;
+ }
+
+ /* Port ID */
+ const char *port_descr =
+ hardware->h_lport.p_descr ? hardware->h_lport.p_descr : "";
+ if (!(POKE_START_CDP_TLV(CDP_TLV_PORT) &&
+ POKE_BYTES(port_descr, strlen(port_descr)) && POKE_END_CDP_TLV))
+ goto toobig;
+
+ /* Capabilities */
+ if (version != 0) {
+ cap = 0;
+ if (chassis->c_cap_enabled & LLDP_CAP_ROUTER) cap |= CDP_CAP_ROUTER;
+ if (chassis->c_cap_enabled & LLDP_CAP_BRIDGE) cap |= CDP_CAP_SWITCH;
+ cap |= CDP_CAP_HOST;
+ if (!(POKE_START_CDP_TLV(CDP_TLV_CAPABILITIES) && POKE_UINT32(cap) &&
+ POKE_END_CDP_TLV))
+ goto toobig;
+# ifdef ENABLE_FDP
+ } else {
+ /* With FDP, it seems that a string is used in place of an int */
+ if (chassis->c_cap_enabled & LLDP_CAP_ROUTER)
+ capstr = "Router";
+ else if (chassis->c_cap_enabled & LLDP_CAP_BRIDGE)
+ capstr = "Switch";
+ else if (chassis->c_cap_enabled & LLDP_CAP_REPEATER)
+ capstr = "Bridge";
+ else
+ capstr = "Host";
+ if (!(POKE_START_CDP_TLV(CDP_TLV_CAPABILITIES) &&
+ POKE_BYTES(capstr, strlen(capstr)) && POKE_END_CDP_TLV))
+ goto toobig;
+# endif
+ }
+
+ /* Native VLAN */
+# ifdef ENABLE_DOT1
+ if (version >= 2 && hardware->h_lport.p_pvid != 0) {
+ if (!(POKE_START_CDP_TLV(CDP_TLV_NATIVEVLAN) &&
+ POKE_UINT16(hardware->h_lport.p_pvid) && POKE_END_CDP_TLV))
+ goto toobig;
+ }
+# endif
+
+ /* Software version */
+ const char *chassis_descr = chassis->c_descr ? chassis->c_descr : "";
+ if (!(POKE_START_CDP_TLV(CDP_TLV_SOFTWARE) &&
+ POKE_BYTES(chassis_descr, strlen(chassis_descr)) && POKE_END_CDP_TLV))
+ goto toobig;
+
+ /* Platform */
+ if (global && global->g_config.c_platform)
+ platform = global->g_config.c_platform;
+
+ if (!(POKE_START_CDP_TLV(CDP_TLV_PLATFORM) &&
+ POKE_BYTES(platform, strlen(platform)) && POKE_END_CDP_TLV))
+ goto toobig;
+
+# ifdef ENABLE_DOT3
+ if ((version >= 2) && (port->p_power.powertype != LLDP_DOT3_POWER_8023AT_OFF) &&
+ (port->p_power.devicetype == LLDP_DOT3_POWER_PD) &&
+ (port->p_power.requested > 0) && (port->p_power.requested <= 655)) {
+ u_int16_t requested;
+ u_int16_t consumption;
+
+ if (port->p_power.requested != port->p_power.allocated) {
+ port->p_cdp_power.request_id++;
+ log_debug("cdp", "requested: %d, allocated:%d",
+ port->p_power.requested, port->p_power.allocated);
+ }
+ consumption = port->p_power.allocated ? port->p_power.allocated :
+ CDP_SWTICH_DEFAULT_POE_PD;
+ if (consumption > 130) {
+ consumption += CDP_SWITCH_POE_CLASS_4_OFFSET;
+ } else {
+ consumption += CDP_SWITCH_POE_CLASS_3_OFFSET;
+ }
+ if (port->p_power.requested > 130) { /* Class 4 */
+ requested =
+ port->p_power.requested + CDP_SWITCH_POE_CLASS_4_OFFSET;
+ } else { /* Class 3 */
+ requested =
+ port->p_power.requested + CDP_SWITCH_POE_CLASS_3_OFFSET;
+ }
+ if (!(POKE_START_CDP_TLV(CDP_TLV_POWER_CONSUMPTION) &&
+ POKE_UINT16(consumption * 100) && POKE_END_CDP_TLV))
+ goto toobig;
+ /* Avoid request id 0 from overflow */
+ if (!port->p_cdp_power.request_id) {
+ port->p_cdp_power.request_id = 1;
+ }
+ if (!port->p_cdp_power.management_id) {
+ port->p_cdp_power.management_id = 1;
+ }
+ if (!(POKE_START_CDP_TLV(CDP_TLV_POWER_REQUESTED) &&
+ POKE_UINT16(port->p_cdp_power.request_id) &&
+ POKE_UINT16(port->p_cdp_power.management_id) &&
+ POKE_UINT32(requested * 100) && POKE_END_CDP_TLV))
+ goto toobig;
+ }
+# elif defined ENABLE_LLDPMED
+ /* Power use */
+ if ((version >= 2) && port->p_med_cap_enabled &&
+ (port->p_med_power.source != LLDP_MED_POW_SOURCE_LOCAL) &&
+ (port->p_med_power.val > 0) && (port->p_med_power.val <= 655)) {
+ if (!(POKE_START_CDP_TLV(CDP_TLV_POWER_CONSUMPTION) &&
+ POKE_UINT16(port->p_med_power.val * 100) && POKE_END_CDP_TLV))
+ goto toobig;
+ }
+# endif
+
+ (void)POKE_SAVE(end);
+
+ /* Compute len and checksum */
+ POKE_RESTORE(pos_len_eh);
+ if (!(POKE_UINT16(end - pos_llc))) goto toobig;
+ checksum = frame_checksum(pos_cdp, end - pos_cdp, (version != 0) ? 1 : 0);
+ POKE_RESTORE(pos_checksum);
+ if (!(POKE_UINT16(checksum))) goto toobig;
+
+ if (interfaces_send_helper(global, hardware, (char *)packet, end - packet) ==
+ -1) {
+ log_warn("cdp", "unable to send packet on real device for %s",
+ hardware->h_ifname);
+ free(packet);
+ return ENETDOWN;
+ }
+
+ hardware->h_tx_cnt++;
+
+ free(packet);
+ return 0;
+toobig:
+ free(packet);
+ return -1;
+}
+
+# define CHECK_TLV_SIZE(x, name) \
+ do { \
+ if (tlv_len < (x)) { \
+ log_warnx("cdp", name " CDP/FDP TLV too short received on %s", \
+ hardware->h_ifname); \
+ goto malformed; \
+ } \
+ } while (0)
+/* cdp_decode also decodes FDP */
+int
+cdp_decode(struct lldpd *cfg, char *frame, int s, struct lldpd_hardware *hardware,
+ struct lldpd_chassis **newchassis, struct lldpd_port **newport)
+{
+ struct lldpd_chassis *chassis;
+ struct lldpd_port *port;
+ struct lldpd_mgmt *mgmt;
+ struct in_addr addr;
+# if 0
+ u_int16_t cksum;
+# endif
+ u_int8_t *software = NULL, *platform = NULL;
+ int software_len = 0, platform_len = 0, proto, version, nb, caps;
+ const unsigned char cdpaddr[] = CDP_MULTICAST_ADDR;
+# ifdef ENABLE_FDP
+ const unsigned char fdpaddr[] = CDP_MULTICAST_ADDR;
+ int fdp = 0;
+# endif
+ u_int8_t *pos, *tlv, *pos_address, *pos_next_address;
+ int length, len_eth, tlv_type, tlv_len, addresses_len, address_len;
+# ifdef ENABLE_DOT1
+ struct lldpd_vlan *vlan;
+# endif
+
+ log_debug("cdp", "decode CDP frame received on %s", hardware->h_ifname);
+
+ if ((chassis = calloc(1, sizeof(struct lldpd_chassis))) == NULL) {
+ log_warn("cdp", "failed to allocate remote chassis");
+ return -1;
+ }
+ TAILQ_INIT(&chassis->c_mgmt);
+ if ((port = calloc(1, sizeof(struct lldpd_port))) == NULL) {
+ log_warn("cdp", "failed to allocate remote port");
+ free(chassis);
+ return -1;
+ }
+# ifdef ENABLE_DOT1
+ TAILQ_INIT(&port->p_vlans);
+# endif
+
+ length = s;
+ pos = (u_int8_t *)frame;
+
+ if (length < 2 * ETHER_ADDR_LEN + sizeof(u_int16_t) /* Ethernet */ +
+ 8 /* LLC */ + 4 /* CDP header */) {
+ log_warn("cdp", "too short CDP/FDP frame received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+
+ if (PEEK_CMP(cdpaddr, sizeof(cdpaddr)) != 0) {
+# ifdef ENABLE_FDP
+ PEEK_RESTORE((u_int8_t *)frame);
+ if (PEEK_CMP(fdpaddr, sizeof(fdpaddr)) != 0)
+ fdp = 1;
+ else {
+# endif
+ log_info("cdp",
+ "frame not targeted at CDP/FDP multicast address received on %s",
+ hardware->h_ifname);
+ goto malformed;
+# ifdef ENABLE_FDP
+ }
+# endif
+ }
+ PEEK_DISCARD(ETHER_ADDR_LEN); /* Don't care of source address */
+ len_eth = PEEK_UINT16;
+ if (len_eth > length) {
+ log_warnx("cdp", "incorrect 802.3 frame size reported on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+
+ /* This is the correct length of the CDP + LLC packets */
+ length = len_eth;
+
+ PEEK_DISCARD(6); /* Skip beginning of LLC */
+ proto = PEEK_UINT16;
+ if (proto != LLC_PID_CDP) {
+ if ((proto != LLC_PID_DRIP) && (proto != LLC_PID_PAGP) &&
+ (proto != LLC_PID_PVSTP) && (proto != LLC_PID_UDLD) &&
+ (proto != LLC_PID_VTP) && (proto != LLC_PID_DTP) &&
+ (proto != LLC_PID_STP))
+ log_debug("cdp", "incorrect LLC protocol ID received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+
+# if 0
+ /* Check checksum */
+ cksum = frame_checksum(pos, len_eth - 8,
+# ifdef ENABLE_FDP
+ !fdp /* fdp = 0 -> cisco checksum */
+# else
+ 1 /* cisco checksum */
+# endif
+ );
+ if (cksum != 0) {
+ log_info("cdp", "incorrect CDP/FDP checksum for frame received on %s (%d)",
+ hardware->h_ifname, cksum);
+ goto malformed;
+ }
+# endif
+
+ /* Check version */
+ version = PEEK_UINT8;
+ if ((version != 1) && (version != 2)) {
+ log_warnx("cdp",
+ "incorrect CDP/FDP version (%d) for frame received on %s", version,
+ hardware->h_ifname);
+ goto malformed;
+ }
+ port->p_ttl = PEEK_UINT8; /* TTL */
+ PEEK_DISCARD_UINT16; /* Checksum, already checked */
+
+ while (length) {
+ if (length < 4) {
+ log_warnx("cdp",
+ "CDP/FDP TLV header is too large for "
+ "frame received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ tlv_type = PEEK_UINT16;
+ tlv_len = PEEK_UINT16 - 4;
+
+ (void)PEEK_SAVE(tlv);
+ if ((tlv_len < 0) || (length < tlv_len)) {
+ log_warnx("cdp",
+ "incorrect size in CDP/FDP TLV header for frame "
+ "received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ switch (tlv_type) {
+ case CDP_TLV_CHASSIS:
+ free(chassis->c_name);
+ if ((chassis->c_name = (char *)calloc(1, tlv_len + 1)) ==
+ NULL) {
+ log_warn("cdp",
+ "unable to allocate memory for chassis name");
+ goto malformed;
+ }
+ PEEK_BYTES(chassis->c_name, tlv_len);
+ chassis->c_id_subtype = LLDP_CHASSISID_SUBTYPE_LOCAL;
+ free(chassis->c_id);
+ if ((chassis->c_id = (char *)malloc(tlv_len)) == NULL) {
+ log_warn("cdp",
+ "unable to allocate memory for chassis ID");
+ goto malformed;
+ }
+ memcpy(chassis->c_id, chassis->c_name, tlv_len);
+ chassis->c_id_len = tlv_len;
+ break;
+ case CDP_TLV_ADDRESSES:
+ CHECK_TLV_SIZE(4, "Address");
+ addresses_len = tlv_len - 4;
+ for (nb = PEEK_UINT32; nb > 0; nb--) {
+ (void)PEEK_SAVE(pos_address);
+ /* We first try to get the real length of the packet */
+ if (addresses_len < 2) {
+ log_warn("cdp",
+ "too short address subframe "
+ "received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ PEEK_DISCARD_UINT8;
+ addresses_len--;
+ address_len = PEEK_UINT8;
+ addresses_len--;
+ if (addresses_len < address_len + 2) {
+ log_warn("cdp",
+ "too short address subframe "
+ "received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ PEEK_DISCARD(address_len);
+ addresses_len -= address_len;
+ address_len = PEEK_UINT16;
+ addresses_len -= 2;
+ if (addresses_len < address_len) {
+ log_warn("cdp",
+ "too short address subframe "
+ "received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ PEEK_DISCARD(address_len);
+ addresses_len -= address_len;
+ (void)PEEK_SAVE(pos_next_address);
+ /* Next, we go back and try to extract
+ IPv4 address */
+ PEEK_RESTORE(pos_address);
+ if ((PEEK_UINT8 == 1) && (PEEK_UINT8 == 1) &&
+ (PEEK_UINT8 == CDP_ADDRESS_PROTO_IP) &&
+ (PEEK_UINT16 == sizeof(struct in_addr))) {
+ PEEK_BYTES(&addr, sizeof(struct in_addr));
+ mgmt = lldpd_alloc_mgmt(LLDPD_AF_IPV4, &addr,
+ sizeof(struct in_addr), 0);
+ if (mgmt == NULL) {
+ if (errno == ENOMEM)
+ log_warn("cdp",
+ "unable to allocate memory for management address");
+ else
+ log_warn("cdp",
+ "too large management address received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ TAILQ_INSERT_TAIL(&chassis->c_mgmt, mgmt,
+ m_entries);
+ }
+ /* Go to the end of the address */
+ PEEK_RESTORE(pos_next_address);
+ }
+ break;
+ case CDP_TLV_PORT:
+ if (tlv_len == 0) {
+ log_warn("cdp", "too short port description received");
+ goto malformed;
+ }
+ free(port->p_descr);
+ if ((port->p_descr = (char *)calloc(1, tlv_len + 1)) == NULL) {
+ log_warn("cdp",
+ "unable to allocate memory for port description");
+ goto malformed;
+ }
+ PEEK_BYTES(port->p_descr, tlv_len);
+ port->p_id_subtype = LLDP_PORTID_SUBTYPE_IFNAME;
+ free(port->p_id);
+ if ((port->p_id = (char *)calloc(1, tlv_len)) == NULL) {
+ log_warn("cdp",
+ "unable to allocate memory for port ID");
+ goto malformed;
+ }
+ memcpy(port->p_id, port->p_descr, tlv_len);
+ port->p_id_len = tlv_len;
+ break;
+ case CDP_TLV_CAPABILITIES:
+# ifdef ENABLE_FDP
+ if (fdp) {
+ /* Capabilities are string with FDP */
+ if (!strncmp("Router", (char *)pos, tlv_len))
+ chassis->c_cap_enabled = LLDP_CAP_ROUTER;
+ else if (!strncmp("Switch", (char *)pos, tlv_len))
+ chassis->c_cap_enabled = LLDP_CAP_BRIDGE;
+ else if (!strncmp("Bridge", (char *)pos, tlv_len))
+ chassis->c_cap_enabled = LLDP_CAP_REPEATER;
+ else
+ chassis->c_cap_enabled = LLDP_CAP_STATION;
+ chassis->c_cap_available = chassis->c_cap_enabled;
+ break;
+ }
+# endif
+ CHECK_TLV_SIZE(4, "Capabilities");
+ caps = PEEK_UINT32;
+ if (caps & CDP_CAP_ROUTER)
+ chassis->c_cap_enabled |= LLDP_CAP_ROUTER;
+ if (caps & 0x0e) chassis->c_cap_enabled |= LLDP_CAP_BRIDGE;
+ if (chassis->c_cap_enabled == 0)
+ chassis->c_cap_enabled = LLDP_CAP_STATION;
+ chassis->c_cap_available = chassis->c_cap_enabled;
+ break;
+ case CDP_TLV_SOFTWARE:
+ software_len = tlv_len;
+ (void)PEEK_SAVE(software);
+ break;
+ case CDP_TLV_PLATFORM:
+ platform_len = tlv_len;
+ (void)PEEK_SAVE(platform);
+ break;
+# ifdef ENABLE_DOT1
+ case CDP_TLV_NATIVEVLAN:
+ CHECK_TLV_SIZE(2, "Native VLAN");
+ if ((vlan = (struct lldpd_vlan *)calloc(1,
+ sizeof(struct lldpd_vlan))) == NULL) {
+ log_warn("cdp",
+ "unable to alloc vlan "
+ "structure for "
+ "tlv received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ vlan->v_vid = port->p_pvid = PEEK_UINT16;
+ if (asprintf(&vlan->v_name, "VLAN #%d", vlan->v_vid) == -1) {
+ log_warn("cdp",
+ "unable to alloc VLAN name for "
+ "TLV received on %s",
+ hardware->h_ifname);
+ free(vlan);
+ goto malformed;
+ }
+ TAILQ_INSERT_TAIL(&port->p_vlans, vlan, v_entries);
+ break;
+# endif
+# ifdef ENABLE_DOT3
+ case CDP_TLV_POWER_AVAILABLE:
+ CHECK_TLV_SIZE(12, "Power Available");
+ /* check if it is a respone to a request id */
+ if (PEEK_UINT16 > 0) {
+ port->p_cdp_power.management_id = PEEK_UINT16;
+ port->p_power.allocated = PEEK_UINT32;
+ port->p_power.allocated /= 100;
+ port->p_power.supported = 1;
+ port->p_power.enabled = 1;
+ port->p_power.devicetype = LLDP_DOT3_POWER_PSE;
+ port->p_power.powertype = LLDP_DOT3_POWER_8023AT_TYPE2;
+ log_debug("cdp", "Allocated power %d00",
+ port->p_power.allocated);
+ if (port->p_power.allocated > CDP_CLASS_3_MAX_PSE_POE) {
+ port->p_power.allocated -=
+ CDP_SWITCH_POE_CLASS_4_OFFSET;
+ } else if (port->p_power.allocated >
+ CDP_SWITCH_POE_CLASS_3_OFFSET) {
+ port->p_power.allocated -=
+ CDP_SWITCH_POE_CLASS_3_OFFSET;
+ } else {
+ port->p_power.allocated = 0;
+ }
+ port->p_power.requested =
+ hardware->h_lport.p_power.requested;
+ }
+ break;
+# endif
+ default:
+ log_debug("cdp", "unknown CDP/FDP TLV type (%d) received on %s",
+ ntohs(tlv_type), hardware->h_ifname);
+ hardware->h_rx_unrecognized_cnt++;
+ }
+ PEEK_DISCARD(tlv + tlv_len - pos);
+ }
+ if (!software && platform) {
+ if ((chassis->c_descr = (char *)calloc(1, platform_len + 1)) == NULL) {
+ log_warn("cdp",
+ "unable to allocate memory for chassis description");
+ goto malformed;
+ }
+ memcpy(chassis->c_descr, platform, platform_len);
+ } else if (software && !platform) {
+ if ((chassis->c_descr = (char *)calloc(1, software_len + 1)) == NULL) {
+ log_warn("cdp",
+ "unable to allocate memory for chassis description");
+ goto malformed;
+ }
+ memcpy(chassis->c_descr, software, software_len);
+ } else if (software && platform) {
+# define CONCAT_PLATFORM " running on\n"
+ if ((chassis->c_descr = (char *)calloc(1,
+ software_len + platform_len + strlen(CONCAT_PLATFORM) + 1)) ==
+ NULL) {
+ log_warn("cdp",
+ "unable to allocate memory for chassis description");
+ goto malformed;
+ }
+ memcpy(chassis->c_descr, platform, platform_len);
+ memcpy(chassis->c_descr + platform_len, CONCAT_PLATFORM,
+ strlen(CONCAT_PLATFORM));
+ memcpy(chassis->c_descr + platform_len + strlen(CONCAT_PLATFORM),
+ software, software_len);
+ }
+ if ((chassis->c_id == NULL) || (port->p_id == NULL) ||
+ (chassis->c_name == NULL) || (chassis->c_descr == NULL) ||
+ (port->p_descr == NULL) || (port->p_ttl == 0) ||
+ (chassis->c_cap_enabled == 0)) {
+ log_warnx("cdp",
+ "some mandatory CDP/FDP tlv are missing for frame received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ *newchassis = chassis;
+ *newport = port;
+ return 1;
+
+malformed:
+ lldpd_chassis_cleanup(chassis, 1);
+ lldpd_port_cleanup(port, 1);
+ free(port);
+ return -1;
+}
+
+# ifdef ENABLE_CDP
+int
+cdpv1_send(struct lldpd *global, struct lldpd_hardware *hardware)
+{
+ return cdp_send(global, hardware, 1);
+}
+
+int
+cdpv2_send(struct lldpd *global, struct lldpd_hardware *hardware)
+{
+ return cdp_send(global, hardware, 2);
+}
+# endif
+
+# ifdef ENABLE_FDP
+int
+fdp_send(struct lldpd *global, struct lldpd_hardware *hardware)
+{
+ return cdp_send(global, hardware, 0);
+}
+# endif
+
+# ifdef ENABLE_CDP
+static int
+cdp_guess(char *pos, int length, int version)
+{
+ const u_int8_t mcastaddr[] = CDP_MULTICAST_ADDR;
+ if (length < 2 * ETHER_ADDR_LEN + sizeof(u_int16_t) /* Ethernet */ +
+ 8 /* LLC */ + 4 /* CDP header */)
+ return 0;
+ if (PEEK_CMP(mcastaddr, ETHER_ADDR_LEN) != 0) return 0;
+ PEEK_DISCARD(ETHER_ADDR_LEN);
+ PEEK_DISCARD_UINT16; /* Ethernet */
+ PEEK_DISCARD(8); /* LLC */
+ return (PEEK_UINT8 == version);
+}
+
+int
+cdpv1_guess(char *frame, int len)
+{
+ return cdp_guess(frame, len, 1);
+}
+
+int
+cdpv2_guess(char *frame, int len)
+{
+ return cdp_guess(frame, len, 2);
+}
+# endif
+
+#endif /* defined (ENABLE_CDP) || defined (ENABLE_FDP) */
diff --git a/src/daemon/protocols/cdp.h b/src/daemon/protocols/cdp.h
new file mode 100644
index 0000000..f83ffef
--- /dev/null
+++ b/src/daemon/protocols/cdp.h
@@ -0,0 +1,70 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2008 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _CDP_H
+#define _CDP_H
+
+#define CDP_MULTICAST_ADDR \
+ { \
+ 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc \
+ }
+#define FDP_MULTICAST_ADDR \
+ { \
+ 0x01, 0xe0, 0x52, 0xcc, 0xcc, 0xcc, \
+ }
+#define LLC_ORG_CISCO \
+ { \
+ 0x00, 0x00, 0x0c \
+ }
+#define LLC_ORG_FOUNDRY \
+ { \
+ 0x00, 0xe0, 0x52 \
+ }
+#define LLC_PID_CDP 0x2000
+/* Other protocols */
+#define LLC_PID_DRIP 0x102
+#define LLC_PID_PAGP 0x104
+#define LLC_PID_PVSTP 0x10b
+#define LLC_PID_UDLD 0x111
+#define LLC_PID_VTP 0x2003
+#define LLC_PID_DTP 0x2004
+#define LLC_PID_STP 0x200a
+
+enum {
+ CDP_TLV_CHASSIS = 1,
+ CDP_TLV_ADDRESSES = 2,
+ CDP_TLV_PORT = 3,
+ CDP_TLV_CAPABILITIES = 4,
+ CDP_TLV_SOFTWARE = 5,
+ CDP_TLV_PLATFORM = 6,
+ CDP_TLV_NATIVEVLAN = 10,
+ CDP_TLV_POWER_CONSUMPTION = 0x10,
+ CDP_TLV_POWER_REQUESTED = 0x19,
+ CDP_TLV_POWER_AVAILABLE = 0x1A
+};
+
+#define CDP_ADDRESS_PROTO_IP 0xcc
+
+#define CDP_CAP_ROUTER 0x01
+#define CDP_CAP_TRANSPARENT_BRIDGE 0x02
+#define CDP_CAP_SOURCE_BRIDGE 0x04
+#define CDP_CAP_SWITCH 0x08
+#define CDP_CAP_HOST 0x10
+#define CDP_CAP_IGMP 0x20
+#define CDP_CAP_REPEATER 0x40
+
+#endif /* _CDP_H */
diff --git a/src/daemon/protocols/edp.c b/src/daemon/protocols/edp.c
new file mode 100644
index 0000000..b55130b
--- /dev/null
+++ b/src/daemon/protocols/edp.c
@@ -0,0 +1,514 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2008 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "../lldpd.h"
+#include "../frame.h"
+
+#ifdef ENABLE_EDP
+
+# include <stdio.h>
+# include <unistd.h>
+# include <errno.h>
+# include <arpa/inet.h>
+# include <fnmatch.h>
+
+static int seq = 0;
+
+int
+edp_send(struct lldpd *global, struct lldpd_hardware *hardware)
+{
+ const u_int8_t mcastaddr[] = EDP_MULTICAST_ADDR;
+ const u_int8_t llcorg[] = LLC_ORG_EXTREME;
+ struct lldpd_chassis *chassis;
+ int length, i, v;
+ u_int8_t *packet, *pos, *pos_llc, *pos_len_eh, *pos_len_edp, *pos_edp, *tlv,
+ *end;
+ u_int16_t checksum;
+# ifdef ENABLE_DOT1
+ struct lldpd_vlan *vlan;
+ unsigned int state = 0;
+# endif
+ u_int8_t edp_fakeversion[] = { 7, 6, 4, 99 };
+ /* Subsequent XXX can be replaced by other values. We place
+ them here to ensure the position of "" to be a bit
+ invariant with version changes. */
+ const char *deviceslot[] = { "eth", "veth", "XXX", "XXX", "XXX", "XXX", "XXX",
+ "XXX", "", NULL };
+
+ log_debug("edp", "send EDP frame on port %s", hardware->h_ifname);
+
+ chassis = hardware->h_lport.p_chassis;
+# ifdef ENABLE_DOT1
+ while (state != 2) {
+# endif
+ length = hardware->h_mtu;
+ if ((packet = (u_int8_t *)calloc(1, length)) == NULL) return ENOMEM;
+ pos = packet;
+ v = 0;
+
+ /* Ethernet header */
+ if (!(POKE_BYTES(mcastaddr, sizeof(mcastaddr)) &&
+ POKE_BYTES(&hardware->h_lladdr, ETHER_ADDR_LEN) &&
+ POKE_SAVE(pos_len_eh) && /* We compute the len later */
+ POKE_UINT16(0)))
+ goto toobig;
+
+ /* LLC */
+ if (!(POKE_SAVE(pos_llc) && /* We need to save our
+ current position to
+ compute ethernet len */
+ /* SSAP and DSAP */
+ POKE_UINT8(0xaa) && POKE_UINT8(0xaa) &&
+ /* Control field */
+ POKE_UINT8(0x03) &&
+ /* ORG */
+ POKE_BYTES(llcorg, sizeof(llcorg)) && POKE_UINT16(LLC_PID_EDP)))
+ goto toobig;
+
+ /* EDP header */
+ if ((chassis->c_id_len != ETHER_ADDR_LEN) ||
+ (chassis->c_id_subtype != LLDP_CHASSISID_SUBTYPE_LLADDR)) {
+ log_warnx("edp",
+ "local chassis does not use MAC address as chassis ID!?");
+ free(packet);
+ return EINVAL;
+ }
+ if (!(POKE_SAVE(pos_edp) && /* Save the start of EDP frame */
+ POKE_UINT8(1) && POKE_UINT8(0) &&
+ POKE_SAVE(pos_len_edp) && /* We compute the len
+ and the checksum
+ later */
+ POKE_UINT32(0) && /* Len + Checksum */
+ POKE_UINT16(seq) && POKE_UINT16(0) &&
+ POKE_BYTES(chassis->c_id, ETHER_ADDR_LEN)))
+ goto toobig;
+ seq++;
+
+# ifdef ENABLE_DOT1
+ switch (state) {
+ case 0:
+# endif
+ /* Display TLV */
+ if (!(POKE_START_EDP_TLV(EDP_TLV_DISPLAY) &&
+ POKE_BYTES(chassis->c_name, strlen(chassis->c_name)) &&
+ POKE_UINT8(0) && /* Add a NULL character
+ for better
+ compatibility */
+ POKE_END_EDP_TLV))
+ goto toobig;
+
+ /* Info TLV */
+ if (!(POKE_START_EDP_TLV(EDP_TLV_INFO))) goto toobig;
+ /* We try to emulate the slot thing */
+ for (i = 0; deviceslot[i] != NULL; i++) {
+ if (strncmp(hardware->h_ifname, deviceslot[i],
+ strlen(deviceslot[i])) == 0) {
+ if (!(POKE_UINT16(i) &&
+ POKE_UINT16(atoi(hardware->h_ifname +
+ strlen(deviceslot[i])))))
+ goto toobig;
+ break;
+ }
+ }
+ /* If we don't find a "slot", we say that the
+ interface is in slot 8 */
+ if (deviceslot[i] == NULL) {
+ if (!(POKE_UINT16(8) &&
+ POKE_UINT16(hardware->h_ifindex)))
+ goto toobig;
+ }
+ if (!(POKE_UINT16(0) && /* vchassis */
+ POKE_UINT32(0) && POKE_UINT16(0) && /* Reserved */
+ /* Version */
+ POKE_BYTES(edp_fakeversion, sizeof(edp_fakeversion)) &&
+ /* Connections, we say that we won't
+ have more interfaces than this
+ mask. */
+ POKE_UINT32(0xffffffff) && POKE_UINT32(0) &&
+ POKE_UINT32(0) && POKE_UINT32(0) && POKE_END_EDP_TLV))
+ goto toobig;
+
+# ifdef ENABLE_DOT1
+ break;
+ case 1:
+ TAILQ_FOREACH (vlan, &hardware->h_lport.p_vlans, v_entries) {
+ v++;
+ if (!(POKE_START_EDP_TLV(EDP_TLV_VLAN) &&
+ POKE_UINT8(0) && /* Flags: no IP address */
+ POKE_UINT8(0) && /* Reserved */
+ POKE_UINT16(vlan->v_vid) &&
+ POKE_UINT32(0) && /* Reserved */
+ POKE_UINT32(0) && /* IP address */
+ /* VLAN name */
+ POKE_BYTES(vlan->v_name,
+ strlen(vlan->v_name)) &&
+ POKE_UINT8(0) && POKE_END_EDP_TLV))
+ goto toobig;
+ }
+ break;
+ }
+
+ if ((state == 1) && (v == 0)) {
+ /* No VLAN, no need to send another TLV */
+ free(packet);
+ break;
+ }
+# endif
+
+ /* Null TLV */
+ if (!(POKE_START_EDP_TLV(EDP_TLV_NULL) && POKE_END_EDP_TLV &&
+ POKE_SAVE(end)))
+ goto toobig;
+
+ /* Compute len and checksum */
+ i = end - pos_llc; /* Ethernet length */
+ v = end - pos_edp; /* EDP length */
+ POKE_RESTORE(pos_len_eh);
+ if (!(POKE_UINT16(i))) goto toobig;
+ POKE_RESTORE(pos_len_edp);
+ if (!(POKE_UINT16(v))) goto toobig;
+ checksum = frame_checksum(pos_edp, v, 0);
+ if (!(POKE_UINT16(checksum))) goto toobig;
+
+ if (interfaces_send_helper(global, hardware, (char *)packet,
+ end - packet) == -1) {
+ log_warn("edp", "unable to send packet on real device for %s",
+ hardware->h_ifname);
+ free(packet);
+ return ENETDOWN;
+ }
+ free(packet);
+
+# ifdef ENABLE_DOT1
+ state++;
+ }
+# endif
+
+ hardware->h_tx_cnt++;
+ return 0;
+toobig:
+ free(packet);
+ return E2BIG;
+}
+
+# define CHECK_TLV_SIZE(x, name) \
+ do { \
+ if (tlv_len < (x)) { \
+ log_warnx("edp", name " EDP TLV too short received on %s", \
+ hardware->h_ifname); \
+ goto malformed; \
+ } \
+ } while (0)
+
+int
+edp_decode(struct lldpd *cfg, char *frame, int s, struct lldpd_hardware *hardware,
+ struct lldpd_chassis **newchassis, struct lldpd_port **newport)
+{
+ struct lldpd_chassis *chassis;
+ struct lldpd_port *port;
+# ifdef ENABLE_DOT1
+ struct lldpd_mgmt *mgmt, *mgmt_next, *m;
+ struct lldpd_vlan *lvlan = NULL, *lvlan_next;
+# endif
+ const unsigned char edpaddr[] = EDP_MULTICAST_ADDR;
+ int length, gotend = 0, gotvlans = 0, edp_len, tlv_len, tlv_type;
+ int edp_port, edp_slot;
+ u_int8_t *pos, *pos_edp, *tlv;
+ u_int8_t version[4];
+# ifdef ENABLE_DOT1
+ struct in_addr address;
+ struct lldpd_port *oport;
+# endif
+
+ log_debug("edp", "decode EDP frame on port %s", hardware->h_ifname);
+
+ if ((chassis = calloc(1, sizeof(struct lldpd_chassis))) == NULL) {
+ log_warn("edp", "failed to allocate remote chassis");
+ return -1;
+ }
+ TAILQ_INIT(&chassis->c_mgmt);
+ if ((port = calloc(1, sizeof(struct lldpd_port))) == NULL) {
+ log_warn("edp", "failed to allocate remote port");
+ free(chassis);
+ return -1;
+ }
+# ifdef ENABLE_DOT1
+ TAILQ_INIT(&port->p_vlans);
+# endif
+
+ length = s;
+ pos = (u_int8_t *)frame;
+
+ if (length < 2 * ETHER_ADDR_LEN + sizeof(u_int16_t) + 8 /* LLC */ + 10 +
+ ETHER_ADDR_LEN /* EDP header */) {
+ log_warnx("edp", "too short EDP frame received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+
+ if (PEEK_CMP(edpaddr, sizeof(edpaddr)) != 0) {
+ log_info("edp",
+ "frame not targeted at EDP multicast address received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ PEEK_DISCARD(ETHER_ADDR_LEN);
+ PEEK_DISCARD_UINT16;
+ PEEK_DISCARD(6); /* LLC: DSAP + SSAP + control + org */
+ if (PEEK_UINT16 != LLC_PID_EDP) {
+ log_debug("edp", "incorrect LLC protocol ID received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+
+ (void)PEEK_SAVE(pos_edp); /* Save the start of EDP packet */
+ if (PEEK_UINT8 != 1) {
+ log_warnx("edp", "incorrect EDP version for frame received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ PEEK_DISCARD_UINT8; /* Reserved */
+ edp_len = PEEK_UINT16;
+ PEEK_DISCARD_UINT16; /* Checksum */
+ PEEK_DISCARD_UINT16; /* Sequence */
+ if (PEEK_UINT16 != 0) { /* ID Type = 0 = MAC */
+ log_warnx("edp", "incorrect device id type for frame received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ if (edp_len > length + 10) {
+ log_warnx("edp", "incorrect size for EDP frame received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ port->p_ttl = cfg ? cfg->g_config.c_tx_interval * cfg->g_config.c_tx_hold : 0;
+ port->p_ttl = (port->p_ttl + 999) / 1000;
+ chassis->c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR;
+ chassis->c_id_len = ETHER_ADDR_LEN;
+ if ((chassis->c_id = (char *)malloc(ETHER_ADDR_LEN)) == NULL) {
+ log_warn("edp", "unable to allocate memory for chassis ID");
+ goto malformed;
+ }
+ PEEK_BYTES(chassis->c_id, ETHER_ADDR_LEN);
+
+# ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
+ /* Let's check checksum */
+ if (frame_checksum(pos_edp, edp_len, 0) != 0) {
+ log_warnx("edp", "incorrect EDP checksum for frame received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+# endif
+
+ while (length && !gotend) {
+ if (length < 4) {
+ log_warnx("edp",
+ "EDP TLV header is too large for "
+ "frame received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ if (PEEK_UINT8 != EDP_TLV_MARKER) {
+ log_warnx("edp",
+ "incorrect marker starting EDP TLV header for frame "
+ "received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ tlv_type = PEEK_UINT8;
+ tlv_len = PEEK_UINT16 - 4;
+ (void)PEEK_SAVE(tlv);
+ if ((tlv_len < 0) || (tlv_len > length)) {
+ log_debug("edp",
+ "incorrect size in EDP TLV header for frame "
+ "received on %s",
+ hardware->h_ifname);
+ /* Some poor old Extreme Summit are quite bogus */
+ gotend = 1;
+ break;
+ }
+ switch (tlv_type) {
+ case EDP_TLV_INFO:
+ CHECK_TLV_SIZE(32, "Info");
+ port->p_id_subtype = LLDP_PORTID_SUBTYPE_IFNAME;
+ edp_slot = PEEK_UINT16;
+ edp_port = PEEK_UINT16;
+ free(port->p_id);
+ port->p_id_len =
+ asprintf(&port->p_id, "%d/%d", edp_slot + 1, edp_port + 1);
+ if (port->p_id_len == -1) {
+ log_warn("edp",
+ "unable to allocate memory for "
+ "port ID");
+ goto malformed;
+ }
+ free(port->p_descr);
+ if (asprintf(&port->p_descr, "Slot %d / Port %d", edp_slot + 1,
+ edp_port + 1) == -1) {
+ log_warn("edp",
+ "unable to allocate memory for "
+ "port description");
+ goto malformed;
+ }
+ PEEK_DISCARD_UINT16; /* vchassis */
+ PEEK_DISCARD(6); /* Reserved */
+ PEEK_BYTES(version, 4);
+ free(chassis->c_descr);
+ if (asprintf(&chassis->c_descr,
+ "EDP enabled device, version %d.%d.%d.%d", version[0],
+ version[1], version[2], version[3]) == -1) {
+ log_warn("edp",
+ "unable to allocate memory for "
+ "chassis description");
+ goto malformed;
+ }
+ break;
+ case EDP_TLV_DISPLAY:
+ free(chassis->c_name);
+ if ((chassis->c_name = (char *)calloc(1, tlv_len + 1)) ==
+ NULL) {
+ log_warn("edp",
+ "unable to allocate memory for chassis "
+ "name");
+ goto malformed;
+ }
+ /* TLV display contains a lot of garbage */
+ PEEK_BYTES(chassis->c_name, tlv_len);
+ break;
+ case EDP_TLV_NULL:
+ if (tlv_len != 0) {
+ log_warnx("edp",
+ "null tlv with incorrect size in frame "
+ "received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ if (length)
+ log_debug("edp", "extra data after edp frame on %s",
+ hardware->h_ifname);
+ gotend = 1;
+ break;
+ case EDP_TLV_VLAN:
+# ifdef ENABLE_DOT1
+ CHECK_TLV_SIZE(12, "VLAN");
+ if ((lvlan = (struct lldpd_vlan *)calloc(1,
+ sizeof(struct lldpd_vlan))) == NULL) {
+ log_warn("edp", "unable to allocate vlan");
+ goto malformed;
+ }
+ PEEK_DISCARD_UINT16; /* Flags + reserved */
+ lvlan->v_vid = PEEK_UINT16; /* VID */
+ PEEK_DISCARD(4); /* Reserved */
+ PEEK_BYTES(&address, sizeof(address));
+
+ if (address.s_addr != INADDR_ANY) {
+ mgmt = lldpd_alloc_mgmt(LLDPD_AF_IPV4, &address,
+ sizeof(struct in_addr), 0);
+ if (mgmt == NULL) {
+ log_warn("edp", "Out of memory");
+ goto malformed;
+ }
+ TAILQ_INSERT_TAIL(&chassis->c_mgmt, mgmt, m_entries);
+ }
+
+ if ((lvlan->v_name = (char *)calloc(1, tlv_len + 1 - 12)) ==
+ NULL) {
+ log_warn("edp", "unable to allocate vlan name");
+ goto malformed;
+ }
+ PEEK_BYTES(lvlan->v_name, tlv_len - 12);
+
+ TAILQ_INSERT_TAIL(&port->p_vlans, lvlan, v_entries);
+ lvlan = NULL;
+# endif
+ gotvlans = 1;
+ break;
+ default:
+ log_debug("edp", "unknown EDP TLV type (%d) received on %s",
+ tlv_type, hardware->h_ifname);
+ hardware->h_rx_unrecognized_cnt++;
+ }
+ PEEK_DISCARD(tlv + tlv_len - pos);
+ }
+ if ((chassis->c_id == NULL) || (port->p_id == NULL) ||
+ (chassis->c_name == NULL) || (chassis->c_descr == NULL) ||
+ (port->p_descr == NULL) || (gotend == 0)) {
+# ifdef ENABLE_DOT1
+ if (gotvlans && gotend) {
+ /* VLAN can be sent in a separate frames. We need to add
+ * those vlans to an existing port */
+ TAILQ_FOREACH (oport, &hardware->h_rports, p_entries) {
+ if (!((oport->p_protocol == LLDPD_MODE_EDP) &&
+ (oport->p_chassis->c_id_subtype ==
+ chassis->c_id_subtype) &&
+ (oport->p_chassis->c_id_len ==
+ chassis->c_id_len) &&
+ (memcmp(oport->p_chassis->c_id, chassis->c_id,
+ chassis->c_id_len) == 0)))
+ continue;
+ /* We attach the VLANs to the found port */
+ lldpd_vlan_cleanup(oport);
+ for (lvlan = TAILQ_FIRST(&port->p_vlans); lvlan != NULL;
+ lvlan = lvlan_next) {
+ lvlan_next = TAILQ_NEXT(lvlan, v_entries);
+ TAILQ_REMOVE(&port->p_vlans, lvlan, v_entries);
+ TAILQ_INSERT_TAIL(&oport->p_vlans, lvlan,
+ v_entries);
+ }
+ /* And the IP addresses */
+ for (mgmt = TAILQ_FIRST(&chassis->c_mgmt); mgmt != NULL;
+ mgmt = mgmt_next) {
+ mgmt_next = TAILQ_NEXT(mgmt, m_entries);
+ TAILQ_REMOVE(&chassis->c_mgmt, mgmt, m_entries);
+ /* Don't add an address that already exists! */
+ TAILQ_FOREACH (m, &chassis->c_mgmt, m_entries)
+ if (m->m_family == mgmt->m_family &&
+ !memcmp(&m->m_addr, &mgmt->m_addr,
+ sizeof(m->m_addr)))
+ break;
+ if (m == NULL)
+ TAILQ_INSERT_TAIL(
+ &oport->p_chassis->c_mgmt, mgmt,
+ m_entries);
+ }
+ }
+ /* We discard the remaining frame */
+ goto malformed;
+ }
+# else
+ if (gotvlans) goto malformed;
+# endif
+ log_warnx("edp",
+ "some mandatory tlv are missing for frame received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ *newchassis = chassis;
+ *newport = port;
+ return 1;
+
+malformed:
+# ifdef ENABLE_DOT1
+ free(lvlan);
+# endif
+ lldpd_chassis_cleanup(chassis, 1);
+ lldpd_port_cleanup(port, 1);
+ free(port);
+ return -1;
+}
+
+#endif /* ENABLE_EDP */
diff --git a/src/daemon/protocols/edp.h b/src/daemon/protocols/edp.h
new file mode 100644
index 0000000..f4ee183
--- /dev/null
+++ b/src/daemon/protocols/edp.h
@@ -0,0 +1,41 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2008 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _EDP_H
+#define _EDP_H
+
+#define EDP_MULTICAST_ADDR \
+ { \
+ 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00 \
+ }
+#define LLC_ORG_EXTREME \
+ { \
+ 0x00, 0xe0, 0x2b \
+ }
+#define LLC_PID_EDP 0x00bb
+
+#define EDP_TLV_MARKER 0x99
+
+enum {
+ EDP_TLV_NULL = 0,
+ EDP_TLV_DISPLAY = 1,
+ EDP_TLV_INFO = 2,
+ EDP_TLV_VLAN = 5,
+ EDP_TLV_ESRP = 8,
+};
+
+#endif /* _EDP_H */
diff --git a/src/daemon/protocols/lldp.c b/src/daemon/protocols/lldp.c
new file mode 100644
index 0000000..6e73237
--- /dev/null
+++ b/src/daemon/protocols/lldp.c
@@ -0,0 +1,1315 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2008 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "../lldpd.h"
+#include "../frame.h"
+
+#include <unistd.h>
+#include <errno.h>
+#include <time.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+
+static int
+lldpd_af_to_lldp_proto(int af)
+{
+ switch (af) {
+ case LLDPD_AF_IPV4:
+ return LLDP_MGMT_ADDR_IP4;
+ case LLDPD_AF_IPV6:
+ return LLDP_MGMT_ADDR_IP6;
+ default:
+ return LLDP_MGMT_ADDR_NONE;
+ }
+}
+
+static int
+lldpd_af_from_lldp_proto(int proto)
+{
+ switch (proto) {
+ case LLDP_MGMT_ADDR_IP4:
+ return LLDPD_AF_IPV4;
+ case LLDP_MGMT_ADDR_IP6:
+ return LLDPD_AF_IPV6;
+ default:
+ return LLDPD_AF_UNSPEC;
+ }
+}
+
+static int
+_lldp_send(struct lldpd *global, struct lldpd_hardware *hardware, u_int8_t c_id_subtype,
+ char *c_id, int c_id_len, u_int8_t p_id_subtype, char *p_id, int p_id_len,
+ int shutdown, int without_vlans)
+{
+ struct lldpd_port *port;
+ struct lldpd_chassis *chassis;
+ struct lldpd_frame *frame;
+ int length;
+ u_int8_t *packet, *pos, *tlv;
+ struct lldpd_mgmt *mgmt;
+ int proto;
+ int vlans = 0;
+
+ u_int8_t mcastaddr_regular[] = LLDP_ADDR_NEAREST_BRIDGE;
+ u_int8_t mcastaddr_nontpmr[] = LLDP_ADDR_NEAREST_NONTPMR_BRIDGE;
+ u_int8_t mcastaddr_customer[] = LLDP_ADDR_NEAREST_CUSTOMER_BRIDGE;
+ u_int8_t *mcastaddr;
+#ifdef ENABLE_DOT1
+ const u_int8_t dot1[] = LLDP_TLV_ORG_DOT1;
+ struct lldpd_vlan *vlan;
+ struct lldpd_ppvid *ppvid;
+ struct lldpd_pi *pi;
+#endif
+#ifdef ENABLE_DOT3
+ const u_int8_t dot3[] = LLDP_TLV_ORG_DOT3;
+#endif
+#ifdef ENABLE_LLDPMED
+ int i;
+ const u_int8_t med[] = LLDP_TLV_ORG_MED;
+#endif
+#ifdef ENABLE_CUSTOM
+ struct lldpd_custom *custom;
+#endif
+ port = &hardware->h_lport;
+ chassis = port->p_chassis;
+ length = hardware->h_mtu;
+ if ((packet = (u_int8_t *)calloc(1, length)) == NULL) return ENOMEM;
+ pos = packet;
+
+ /* Ethernet header */
+ switch (global->g_config.c_lldp_agent_type) {
+ case LLDP_AGENT_TYPE_NEAREST_NONTPMR_BRIDGE:
+ mcastaddr = mcastaddr_nontpmr;
+ break;
+ case LLDP_AGENT_TYPE_NEAREST_CUSTOMER_BRIDGE:
+ mcastaddr = mcastaddr_customer;
+ break;
+ case LLDP_AGENT_TYPE_NEAREST_BRIDGE:
+ default:
+ mcastaddr = mcastaddr_regular;
+ break;
+ }
+ if (!(
+ /* LLDP multicast address */
+ POKE_BYTES(mcastaddr, ETHER_ADDR_LEN) &&
+ /* Source MAC address */
+ POKE_BYTES(&hardware->h_lladdr, ETHER_ADDR_LEN)))
+ goto toobig;
+
+ /* Insert VLAN tag if needed */
+ if (port->p_vlan_tx_enabled) {
+ if (!(
+ /* VLAN ethertype */
+ POKE_UINT16(ETHERTYPE_VLAN) &&
+ /* VLAN Tag Control Information (TCI) */
+ /* Priority(3bits) | DEI(1bit) | VID(12bit) */
+ POKE_UINT16(port->p_vlan_tx_tag)))
+ goto toobig;
+ }
+
+ if (!(
+ /* LLDP frame */
+ POKE_UINT16(ETH_P_LLDP)))
+ goto toobig;
+
+ /* Chassis ID */
+ if (!(POKE_START_LLDP_TLV(LLDP_TLV_CHASSIS_ID) && POKE_UINT8(c_id_subtype) &&
+ POKE_BYTES(c_id, c_id_len) && POKE_END_LLDP_TLV))
+ goto toobig;
+
+ /* Port ID */
+ if (!(POKE_START_LLDP_TLV(LLDP_TLV_PORT_ID) && POKE_UINT8(p_id_subtype) &&
+ POKE_BYTES(p_id, p_id_len) && POKE_END_LLDP_TLV))
+ goto toobig;
+
+ /* Time to live */
+ if (!(POKE_START_LLDP_TLV(LLDP_TLV_TTL) &&
+ POKE_UINT16(shutdown ? 0 : (global ? global->g_config.c_ttl : 180)) &&
+ POKE_END_LLDP_TLV))
+ goto toobig;
+
+ if (shutdown) goto end;
+
+ /* System name */
+ if (chassis->c_name && *chassis->c_name != '\0') {
+ if (!(POKE_START_LLDP_TLV(LLDP_TLV_SYSTEM_NAME) &&
+ POKE_BYTES(chassis->c_name, strlen(chassis->c_name)) &&
+ POKE_END_LLDP_TLV))
+ goto toobig;
+ }
+
+ /* System description (skip it if empty) */
+ if (chassis->c_descr && *chassis->c_descr != '\0') {
+ if (!(POKE_START_LLDP_TLV(LLDP_TLV_SYSTEM_DESCR) &&
+ POKE_BYTES(chassis->c_descr, strlen(chassis->c_descr)) &&
+ POKE_END_LLDP_TLV))
+ goto toobig;
+ }
+
+ /* System capabilities */
+ if (global->g_config.c_cap_advertise && chassis->c_cap_available) {
+ if (!(POKE_START_LLDP_TLV(LLDP_TLV_SYSTEM_CAP) &&
+ POKE_UINT16(chassis->c_cap_available) &&
+ POKE_UINT16(chassis->c_cap_enabled) && POKE_END_LLDP_TLV))
+ goto toobig;
+ }
+
+ /* Management addresses */
+ TAILQ_FOREACH (mgmt, &chassis->c_mgmt, m_entries) {
+ proto = lldpd_af_to_lldp_proto(mgmt->m_family);
+ if (proto == LLDP_MGMT_ADDR_NONE) continue;
+ if (!(POKE_START_LLDP_TLV(LLDP_TLV_MGMT_ADDR) &&
+ /* Size of the address, including its type */
+ POKE_UINT8(mgmt->m_addrsize + 1) && POKE_UINT8(proto) &&
+ POKE_BYTES(&mgmt->m_addr, mgmt->m_addrsize)))
+ goto toobig;
+
+ /* Interface port type, OID */
+ if (mgmt->m_iface == 0) {
+ if (!(
+ /* We don't know the management interface */
+ POKE_UINT8(LLDP_MGMT_IFACE_UNKNOWN) && POKE_UINT32(0)))
+ goto toobig;
+ } else {
+ if (!(
+ /* We have the index of the management interface */
+ POKE_UINT8(LLDP_MGMT_IFACE_IFINDEX) &&
+ POKE_UINT32(mgmt->m_iface)))
+ goto toobig;
+ }
+ if (!(
+ /* We don't provide an OID for management */
+ POKE_UINT8(0) && POKE_END_LLDP_TLV))
+ goto toobig;
+ }
+
+ /* Port description */
+ if (port->p_descr && *port->p_descr != '\0') {
+ if (!(POKE_START_LLDP_TLV(LLDP_TLV_PORT_DESCR) &&
+ POKE_BYTES(port->p_descr, strlen(port->p_descr)) &&
+ POKE_END_LLDP_TLV))
+ goto toobig;
+ }
+
+#ifdef ENABLE_DOT1
+ /* Port VLAN ID */
+ if (port->p_pvid != 0) {
+ if (!(POKE_START_LLDP_TLV(LLDP_TLV_ORG) &&
+ POKE_BYTES(dot1, sizeof(dot1)) &&
+ POKE_UINT8(LLDP_TLV_DOT1_PVID) && POKE_UINT16(port->p_pvid) &&
+ POKE_END_LLDP_TLV)) {
+ goto toobig;
+ }
+ }
+ /* Port and Protocol VLAN IDs */
+ TAILQ_FOREACH (ppvid, &port->p_ppvids, p_entries) {
+ if (!(POKE_START_LLDP_TLV(LLDP_TLV_ORG) &&
+ POKE_BYTES(dot1, sizeof(dot1)) &&
+ POKE_UINT8(LLDP_TLV_DOT1_PPVID) &&
+ POKE_UINT8(ppvid->p_cap_status) &&
+ POKE_UINT16(ppvid->p_ppvid) && POKE_END_LLDP_TLV)) {
+ goto toobig;
+ }
+ }
+ /* VLANs */
+ if (!without_vlans) {
+ TAILQ_FOREACH (vlan, &port->p_vlans, v_entries) {
+ vlans++;
+ if (!(POKE_START_LLDP_TLV(LLDP_TLV_ORG) &&
+ POKE_BYTES(dot1, sizeof(dot1)) &&
+ POKE_UINT8(LLDP_TLV_DOT1_VLANNAME) &&
+ POKE_UINT16(vlan->v_vid) &&
+ POKE_UINT8(strlen(vlan->v_name)) &&
+ POKE_BYTES(vlan->v_name, strlen(vlan->v_name)) &&
+ POKE_END_LLDP_TLV))
+ goto toobig;
+ }
+ }
+ /* Protocol Identities */
+ TAILQ_FOREACH (pi, &port->p_pids, p_entries) {
+ if (!(POKE_START_LLDP_TLV(LLDP_TLV_ORG) &&
+ POKE_BYTES(dot1, sizeof(dot1)) &&
+ POKE_UINT8(LLDP_TLV_DOT1_PI) && POKE_UINT8(pi->p_pi_len) &&
+ POKE_BYTES(pi->p_pi, pi->p_pi_len) && POKE_END_LLDP_TLV))
+ goto toobig;
+ }
+#endif
+
+#ifdef ENABLE_DOT3
+ /* Aggregation status */
+ if (!(POKE_START_LLDP_TLV(LLDP_TLV_ORG) && POKE_BYTES(dot3, sizeof(dot3)) &&
+ POKE_UINT8(LLDP_TLV_DOT3_LA) &&
+ /* Bit 0 = capability ; Bit 1 = status */
+ POKE_UINT8((port->p_aggregid) ? 3 : 1) &&
+ POKE_UINT32(port->p_aggregid) && POKE_END_LLDP_TLV))
+ goto toobig;
+
+ /* MAC/PHY */
+ if (!(POKE_START_LLDP_TLV(LLDP_TLV_ORG) && POKE_BYTES(dot3, sizeof(dot3)) &&
+ POKE_UINT8(LLDP_TLV_DOT3_MAC) &&
+ POKE_UINT8(port->p_macphy.autoneg_support |
+ (port->p_macphy.autoneg_enabled << 1)) &&
+ POKE_UINT16(port->p_macphy.autoneg_advertised) &&
+ POKE_UINT16(port->p_macphy.mau_type) && POKE_END_LLDP_TLV))
+ goto toobig;
+
+ /* MFS */
+ if (port->p_mfs) {
+ if (!(POKE_START_LLDP_TLV(LLDP_TLV_ORG) &&
+ POKE_BYTES(dot3, sizeof(dot3)) &&
+ POKE_UINT8(LLDP_TLV_DOT3_MFS) && POKE_UINT16(port->p_mfs) &&
+ POKE_END_LLDP_TLV))
+ goto toobig;
+ }
+ /* Power */
+ if (port->p_power.devicetype) {
+ if (!((POKE_START_LLDP_TLV(LLDP_TLV_ORG)) &&
+ POKE_BYTES(dot3, sizeof(dot3)) &&
+ POKE_UINT8(LLDP_TLV_DOT3_POWER) &&
+ POKE_UINT8(((((2 - port->p_power.devicetype) % (1 << 1)) << 0) |
+ ((port->p_power.supported % (1 << 1)) << 1) |
+ ((port->p_power.enabled % (1 << 1)) << 2) |
+ ((port->p_power.paircontrol % (1 << 1)) << 3))) &&
+ POKE_UINT8(port->p_power.pairs) &&
+ POKE_UINT8(port->p_power.class)))
+ goto toobig;
+ /* 802.3at */
+ if (port->p_power.powertype != LLDP_DOT3_POWER_8023AT_OFF) {
+ if (!(POKE_UINT8(((((port->p_power.powertype ==
+ LLDP_DOT3_POWER_8023AT_TYPE1) ?
+ 1 :
+ 0)
+ << 7) |
+ (((port->p_power.devicetype == LLDP_DOT3_POWER_PSE) ?
+ 0 :
+ 1)
+ << 6) |
+ ((port->p_power.source % (1 << 2)) << 4) |
+ ((port->p_power.priority % (1 << 2)) << 0))) &&
+ POKE_UINT16(port->p_power.requested) &&
+ POKE_UINT16(port->p_power.allocated)))
+ goto toobig;
+ }
+ if (!(POKE_END_LLDP_TLV)) goto toobig;
+ }
+#endif
+
+#ifdef ENABLE_LLDPMED
+ if (port->p_med_cap_enabled) {
+ /* LLDP-MED cap */
+ if (port->p_med_cap_enabled & LLDP_MED_CAP_CAP) {
+ if (!(POKE_START_LLDP_TLV(LLDP_TLV_ORG) &&
+ POKE_BYTES(med, sizeof(med)) &&
+ POKE_UINT8(LLDP_TLV_MED_CAP) &&
+ POKE_UINT16(chassis->c_med_cap_available) &&
+ POKE_UINT8(chassis->c_med_type) && POKE_END_LLDP_TLV))
+ goto toobig;
+ }
+
+ /* LLDP-MED inventory */
+# define LLDP_INVENTORY(value, subtype) \
+ if (value) { \
+ if (!(POKE_START_LLDP_TLV(LLDP_TLV_ORG) && POKE_BYTES(med, sizeof(med)) && \
+ POKE_UINT8(subtype) && \
+ POKE_BYTES(value, (strlen(value) > 32) ? 32 : strlen(value)) && \
+ POKE_END_LLDP_TLV)) \
+ goto toobig; \
+ }
+
+ if (port->p_med_cap_enabled & LLDP_MED_CAP_IV) {
+ LLDP_INVENTORY(chassis->c_med_hw, LLDP_TLV_MED_IV_HW);
+ LLDP_INVENTORY(chassis->c_med_fw, LLDP_TLV_MED_IV_FW);
+ LLDP_INVENTORY(chassis->c_med_sw, LLDP_TLV_MED_IV_SW);
+ LLDP_INVENTORY(chassis->c_med_sn, LLDP_TLV_MED_IV_SN);
+ LLDP_INVENTORY(chassis->c_med_manuf, LLDP_TLV_MED_IV_MANUF);
+ LLDP_INVENTORY(chassis->c_med_model, LLDP_TLV_MED_IV_MODEL);
+ LLDP_INVENTORY(chassis->c_med_asset, LLDP_TLV_MED_IV_ASSET);
+ }
+
+ /* LLDP-MED location */
+ for (i = 0; i < LLDP_MED_LOCFORMAT_LAST; i++) {
+ if (port->p_med_location[i].format == i + 1) {
+ if (!(POKE_START_LLDP_TLV(LLDP_TLV_ORG) &&
+ POKE_BYTES(med, sizeof(med)) &&
+ POKE_UINT8(LLDP_TLV_MED_LOCATION) &&
+ POKE_UINT8(port->p_med_location[i].format) &&
+ POKE_BYTES(port->p_med_location[i].data,
+ port->p_med_location[i].data_len) &&
+ POKE_END_LLDP_TLV))
+ goto toobig;
+ }
+ }
+
+ /* LLDP-MED network policy */
+ for (i = 0; i < LLDP_MED_APPTYPE_LAST; i++) {
+ if (port->p_med_policy[i].type == i + 1) {
+ if (!(POKE_START_LLDP_TLV(LLDP_TLV_ORG) &&
+ POKE_BYTES(med, sizeof(med)) &&
+ POKE_UINT8(LLDP_TLV_MED_POLICY) &&
+ POKE_UINT32((
+ ((port->p_med_policy[i].type % (1 << 8))
+ << 24) |
+ ((port->p_med_policy[i].unknown % (1 << 1))
+ << 23) |
+ ((port->p_med_policy[i].tagged % (1 << 1))
+ << 22) |
+ /*((0 %(1<<
+ 1))<<21) |*/
+ ((port->p_med_policy[i].vid % (1 << 12))
+ << 9) |
+ ((port->p_med_policy[i].priority % (1 << 3))
+ << 6) |
+ ((port->p_med_policy[i].dscp % (1 << 6))
+ << 0))) &&
+ POKE_END_LLDP_TLV))
+ goto toobig;
+ }
+ }
+
+ /* LLDP-MED POE-MDI */
+ if ((port->p_med_power.devicetype == LLDP_MED_POW_TYPE_PSE) ||
+ (port->p_med_power.devicetype == LLDP_MED_POW_TYPE_PD)) {
+ int devicetype = 0, source = 0;
+ if (!(POKE_START_LLDP_TLV(LLDP_TLV_ORG) &&
+ POKE_BYTES(med, sizeof(med)) &&
+ POKE_UINT8(LLDP_TLV_MED_MDI)))
+ goto toobig;
+ switch (port->p_med_power.devicetype) {
+ case LLDP_MED_POW_TYPE_PSE:
+ devicetype = 0;
+ switch (port->p_med_power.source) {
+ case LLDP_MED_POW_SOURCE_PRIMARY:
+ source = 1;
+ break;
+ case LLDP_MED_POW_SOURCE_BACKUP:
+ source = 2;
+ break;
+ case LLDP_MED_POW_SOURCE_RESERVED:
+ source = 3;
+ break;
+ default:
+ source = 0;
+ break;
+ }
+ break;
+ case LLDP_MED_POW_TYPE_PD:
+ devicetype = 1;
+ switch (port->p_med_power.source) {
+ case LLDP_MED_POW_SOURCE_PSE:
+ source = 1;
+ break;
+ case LLDP_MED_POW_SOURCE_LOCAL:
+ source = 2;
+ break;
+ case LLDP_MED_POW_SOURCE_BOTH:
+ source = 3;
+ break;
+ default:
+ source = 0;
+ break;
+ }
+ break;
+ }
+ if (!(POKE_UINT8((((devicetype % (1 << 2)) << 6) |
+ ((source % (1 << 2)) << 4) |
+ ((port->p_med_power.priority % (1 << 4)) << 0))) &&
+ POKE_UINT16(port->p_med_power.val) &&
+ POKE_END_LLDP_TLV))
+ goto toobig;
+ }
+ }
+#endif
+
+#ifdef ENABLE_CUSTOM
+ TAILQ_FOREACH (custom, &port->p_custom_list, next) {
+ if (!(POKE_START_LLDP_TLV(LLDP_TLV_ORG) &&
+ POKE_BYTES(custom->oui, sizeof(custom->oui)) &&
+ POKE_UINT8(custom->subtype) &&
+ POKE_BYTES(custom->oui_info, custom->oui_info_len) &&
+ POKE_END_LLDP_TLV))
+ goto toobig;
+ }
+#endif
+
+end:
+ /* END */
+ if (!(POKE_START_LLDP_TLV(LLDP_TLV_END) && POKE_END_LLDP_TLV)) goto toobig;
+
+ if (interfaces_send_helper(global, hardware, (char *)packet, pos - packet) ==
+ -1) {
+ log_warn("lldp", "unable to send packet on real device for %s",
+ hardware->h_ifname);
+ free(packet);
+ return ENETDOWN;
+ }
+
+ hardware->h_tx_cnt++;
+
+ /* We assume that LLDP frame is the reference */
+ if (!shutdown &&
+ (frame = (struct lldpd_frame *)malloc(sizeof(int) + pos - packet)) !=
+ NULL) {
+ frame->size = pos - packet;
+ memcpy(&frame->frame, packet, frame->size);
+ if ((hardware->h_lport.p_lastframe == NULL) ||
+ (hardware->h_lport.p_lastframe->size != frame->size) ||
+ (memcmp(hardware->h_lport.p_lastframe->frame, frame->frame,
+ frame->size) != 0)) {
+ free(hardware->h_lport.p_lastframe);
+ hardware->h_lport.p_lastframe = frame;
+ hardware->h_lport.p_lastchange = time(NULL);
+ } else
+ free(frame);
+ }
+
+ free(packet);
+ return 0;
+
+toobig:
+ free(packet);
+ if (vlans > 0 && !without_vlans) {
+ /* Retry without VLANs */
+ return _lldp_send(global, hardware, c_id_subtype, c_id, c_id_len,
+ p_id_subtype, p_id, p_id_len, shutdown, 1);
+ }
+ log_info("lldp", "Cannot send LLDP packet for %s, too big message",
+ hardware->h_ifname);
+ return E2BIG;
+}
+
+/* Send a shutdown LLDPDU. */
+int
+lldp_send_shutdown(struct lldpd *global, struct lldpd_hardware *hardware)
+{
+ if (hardware->h_lchassis_previous_id == NULL ||
+ hardware->h_lport_previous_id == NULL)
+ return 0;
+ return _lldp_send(global, hardware, hardware->h_lchassis_previous_id_subtype,
+ hardware->h_lchassis_previous_id, hardware->h_lchassis_previous_id_len,
+ hardware->h_lport_previous_id_subtype, hardware->h_lport_previous_id,
+ hardware->h_lport_previous_id_len, 1, 0);
+}
+
+int
+lldp_send(struct lldpd *global, struct lldpd_hardware *hardware)
+{
+ struct lldpd_port *port = &hardware->h_lport;
+ struct lldpd_chassis *chassis = port->p_chassis;
+ int ret;
+
+ /* Check if we have a change. */
+ if (hardware->h_lchassis_previous_id != NULL &&
+ hardware->h_lport_previous_id != NULL &&
+ (hardware->h_lchassis_previous_id_subtype != chassis->c_id_subtype ||
+ hardware->h_lchassis_previous_id_len != chassis->c_id_len ||
+ hardware->h_lport_previous_id_subtype != port->p_id_subtype ||
+ hardware->h_lport_previous_id_len != port->p_id_len ||
+ memcmp(hardware->h_lchassis_previous_id, chassis->c_id,
+ chassis->c_id_len) ||
+ memcmp(hardware->h_lport_previous_id, port->p_id, port->p_id_len))) {
+ log_info("lldp",
+ "MSAP has changed for port %s, sending a shutdown LLDPDU",
+ hardware->h_ifname);
+ if ((ret = lldp_send_shutdown(global, hardware)) != 0) return ret;
+ }
+
+ log_debug("lldp", "send LLDP PDU to %s", hardware->h_ifname);
+
+ if ((ret = _lldp_send(global, hardware, chassis->c_id_subtype, chassis->c_id,
+ chassis->c_id_len, port->p_id_subtype, port->p_id, port->p_id_len, 0,
+ 0)) != 0)
+ return ret;
+
+ /* Record current chassis and port ID */
+ free(hardware->h_lchassis_previous_id);
+ hardware->h_lchassis_previous_id_subtype = chassis->c_id_subtype;
+ hardware->h_lchassis_previous_id_len = chassis->c_id_len;
+ if ((hardware->h_lchassis_previous_id = malloc(chassis->c_id_len)) != NULL)
+ memcpy(hardware->h_lchassis_previous_id, chassis->c_id,
+ chassis->c_id_len);
+ free(hardware->h_lport_previous_id);
+ hardware->h_lport_previous_id_subtype = port->p_id_subtype;
+ hardware->h_lport_previous_id_len = port->p_id_len;
+ if ((hardware->h_lport_previous_id = malloc(port->p_id_len)) != NULL)
+ memcpy(hardware->h_lport_previous_id, port->p_id, port->p_id_len);
+
+ return 0;
+}
+
+#define CHECK_TLV_SIZE(x, name) \
+ do { \
+ if (tlv_size < (x)) { \
+ log_warnx("lldp", name " TLV too short received on %s", hardware->h_ifname); \
+ goto malformed; \
+ } \
+ } while (0)
+#define CHECK_TLV_MAX_SIZE(x, name) \
+ do { \
+ if (tlv_size > (x)) { \
+ log_warnx("lldp", name " TLV too large received on %s", hardware->h_ifname); \
+ goto malformed; \
+ } \
+ } while (0)
+
+int
+lldp_decode(struct lldpd *cfg, char *frame, int s, struct lldpd_hardware *hardware,
+ struct lldpd_chassis **newchassis, struct lldpd_port **newport)
+{
+ struct lldpd_chassis *chassis;
+ struct lldpd_port *port;
+ char lldpaddr[ETHER_ADDR_LEN];
+ const char dot1[] = LLDP_TLV_ORG_DOT1;
+ const char dot3[] = LLDP_TLV_ORG_DOT3;
+ const char med[] = LLDP_TLV_ORG_MED;
+ const char dcbx[] = LLDP_TLV_ORG_DCBX;
+ unsigned char orgid[3];
+ int length, gotend = 0, ttl_received = 0;
+ int tlv_size, tlv_type, tlv_subtype, tlv_count = 0;
+ u_int8_t *pos, *tlv;
+ char *b;
+#ifdef ENABLE_DOT1
+ struct lldpd_vlan *vlan = NULL;
+ int vlan_len;
+ struct lldpd_ppvid *ppvid;
+ struct lldpd_pi *pi = NULL;
+#endif
+ struct lldpd_mgmt *mgmt;
+ int af;
+ u_int8_t addr_str_length, addr_str_buffer[32] = { 0 };
+ u_int8_t addr_family, addr_length, *addr_ptr, iface_subtype;
+ u_int32_t iface_number, iface;
+ int unrecognized;
+#ifdef ENABLE_CUSTOM
+ struct lldpd_custom *custom = NULL;
+#endif
+
+ log_debug("lldp", "receive LLDP PDU on %s", hardware->h_ifname);
+
+ if ((chassis = calloc(1, sizeof(struct lldpd_chassis))) == NULL) {
+ log_warn("lldp", "failed to allocate remote chassis");
+ return -1;
+ }
+ TAILQ_INIT(&chassis->c_mgmt);
+ if ((port = calloc(1, sizeof(struct lldpd_port))) == NULL) {
+ log_warn("lldp", "failed to allocate remote port");
+ free(chassis);
+ return -1;
+ }
+#ifdef ENABLE_DOT1
+ TAILQ_INIT(&port->p_vlans);
+ TAILQ_INIT(&port->p_ppvids);
+ TAILQ_INIT(&port->p_pids);
+#endif
+#ifdef ENABLE_CUSTOM
+ TAILQ_INIT(&port->p_custom_list);
+#endif
+
+ length = s;
+ pos = (u_int8_t *)frame;
+
+ if (length < 2 * ETHER_ADDR_LEN + sizeof(u_int16_t)) {
+ log_warnx("lldp", "too short frame received on %s", hardware->h_ifname);
+ goto malformed;
+ }
+ PEEK_BYTES(lldpaddr, ETHER_ADDR_LEN);
+ if (memcmp(lldpaddr, (const char[])LLDP_ADDR_NEAREST_BRIDGE, ETHER_ADDR_LEN) &&
+ memcmp(lldpaddr, (const char[])LLDP_ADDR_NEAREST_NONTPMR_BRIDGE,
+ ETHER_ADDR_LEN) &&
+ memcmp(lldpaddr, (const char[])LLDP_ADDR_NEAREST_CUSTOMER_BRIDGE,
+ ETHER_ADDR_LEN)) {
+ log_info("lldp",
+ "frame not targeted at LLDP multicast address received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ PEEK_DISCARD(ETHER_ADDR_LEN); /* Skip source address */
+ if (PEEK_UINT16 != ETH_P_LLDP) {
+ log_info("lldp", "non LLDP frame received on %s", hardware->h_ifname);
+ goto malformed;
+ }
+
+ while (length && (!gotend)) {
+ if (length < 2) {
+ log_warnx("lldp", "tlv header too short received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ tlv_size = PEEK_UINT16;
+ tlv_type = tlv_size >> 9;
+ tlv_size = tlv_size & 0x1ff;
+ (void)PEEK_SAVE(tlv);
+ if (length < tlv_size) {
+ log_warnx("lldp", "frame too short for tlv received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ /* Check order for mandatory TLVs */
+ tlv_count++;
+ switch (tlv_type) {
+ case LLDP_TLV_CHASSIS_ID:
+ if (tlv_count != 1) {
+ log_warnx("lldp",
+ "Chassis ID TLV should be first on %s, but it is on position %d",
+ hardware->h_ifname, tlv_count);
+ goto malformed;
+ }
+ break;
+ case LLDP_TLV_PORT_ID:
+ if (tlv_count != 2) {
+ log_warnx("lldp",
+ "Port ID TLV should be second on %s, but it is on position %d",
+ hardware->h_ifname, tlv_count);
+ goto malformed;
+ }
+ break;
+ case LLDP_TLV_TTL:
+ if (tlv_count != 3) {
+ log_warnx("lldp",
+ "TTL TLV should be third on %s, but it is on position %d",
+ hardware->h_ifname, tlv_count);
+ goto malformed;
+ }
+ break;
+ }
+
+ switch (tlv_type) {
+ case LLDP_TLV_END:
+ if (tlv_size != 0) {
+ log_warnx("lldp",
+ "lldp end received with size not null on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ if (length)
+ log_debug("lldp", "extra data after lldp end on %s",
+ hardware->h_ifname);
+ gotend = 1;
+ break;
+ case LLDP_TLV_CHASSIS_ID:
+ case LLDP_TLV_PORT_ID:
+ CHECK_TLV_SIZE(2, "Port/Chassis Id");
+ CHECK_TLV_MAX_SIZE(256, "Port/Chassis Id");
+ tlv_subtype = PEEK_UINT8;
+ if ((tlv_subtype == 0) || (tlv_subtype > 7)) {
+ log_warnx("lldp",
+ "unknown subtype for tlv id received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ if ((b = (char *)calloc(1, tlv_size - 1)) == NULL) {
+ log_warn("lldp",
+ "unable to allocate memory for id tlv "
+ "received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ PEEK_BYTES(b, tlv_size - 1);
+ if (tlv_type == LLDP_TLV_PORT_ID) {
+ if (port->p_id != NULL) {
+ log_warnx("lldp",
+ "Port ID TLV received twice on %s",
+ hardware->h_ifname);
+ free(b);
+ goto malformed;
+ }
+ port->p_id_subtype = tlv_subtype;
+ port->p_id = b;
+ port->p_id_len = tlv_size - 1;
+ } else {
+ if (chassis->c_id != NULL) {
+ log_warnx("lldp",
+ "Chassis ID TLV received twice on %s",
+ hardware->h_ifname);
+ free(b);
+ goto malformed;
+ }
+ chassis->c_id_subtype = tlv_subtype;
+ chassis->c_id = b;
+ chassis->c_id_len = tlv_size - 1;
+ }
+ break;
+ case LLDP_TLV_TTL:
+ if (ttl_received) {
+ log_warnx("lldp", "TTL TLV received twice on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ CHECK_TLV_SIZE(2, "TTL");
+ port->p_ttl = PEEK_UINT16;
+ ttl_received = 1;
+ break;
+ case LLDP_TLV_PORT_DESCR:
+ case LLDP_TLV_SYSTEM_NAME:
+ case LLDP_TLV_SYSTEM_DESCR:
+ if (tlv_size < 1) {
+ log_debug("lldp", "empty tlv received on %s",
+ hardware->h_ifname);
+ break;
+ }
+ if ((b = (char *)calloc(1, tlv_size + 1)) == NULL) {
+ log_warn("lldp",
+ "unable to allocate memory for string tlv "
+ "received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ PEEK_BYTES(b, tlv_size);
+ switch (tlv_type) {
+ case LLDP_TLV_PORT_DESCR:
+ free(port->p_descr);
+ port->p_descr = b;
+ break;
+ case LLDP_TLV_SYSTEM_NAME:
+ free(chassis->c_name);
+ chassis->c_name = b;
+ break;
+ case LLDP_TLV_SYSTEM_DESCR:
+ free(chassis->c_descr);
+ chassis->c_descr = b;
+ break;
+ default:
+ /* unreachable */
+ free(b);
+ break;
+ }
+ break;
+ case LLDP_TLV_SYSTEM_CAP:
+ CHECK_TLV_SIZE(4, "System capabilities");
+ chassis->c_cap_available = PEEK_UINT16;
+ chassis->c_cap_enabled = PEEK_UINT16;
+ break;
+ case LLDP_TLV_MGMT_ADDR:
+ CHECK_TLV_SIZE(1, "Management address");
+ addr_str_length = PEEK_UINT8;
+ if (addr_str_length > sizeof(addr_str_buffer)) {
+ log_warnx("lldp", "too large management address on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ CHECK_TLV_SIZE(1 + addr_str_length, "Management address");
+ PEEK_BYTES(addr_str_buffer, addr_str_length);
+ addr_length = addr_str_length - 1;
+ addr_family = addr_str_buffer[0];
+ addr_ptr = &addr_str_buffer[1];
+ CHECK_TLV_SIZE(1 + addr_str_length + 5, "Management address");
+ iface_subtype = PEEK_UINT8;
+ iface_number = PEEK_UINT32;
+
+ af = lldpd_af_from_lldp_proto(addr_family);
+ if (af == LLDPD_AF_UNSPEC) break;
+ if (iface_subtype == LLDP_MGMT_IFACE_IFINDEX)
+ iface = iface_number;
+ else
+ iface = 0;
+ mgmt = lldpd_alloc_mgmt(af, addr_ptr, addr_length, iface);
+ if (mgmt == NULL) {
+ if (errno == ENOMEM)
+ log_warn("lldp",
+ "unable to allocate memory "
+ "for management address");
+ else
+ log_warn("lldp",
+ "too large management address "
+ "received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ TAILQ_INSERT_TAIL(&chassis->c_mgmt, mgmt, m_entries);
+ break;
+ case LLDP_TLV_ORG:
+ CHECK_TLV_SIZE(1 + (int)sizeof(orgid), "Organisational");
+ PEEK_BYTES(orgid, sizeof(orgid));
+ unrecognized = 0;
+ tlv_subtype = PEEK_UINT8;
+ if (memcmp(dot1, orgid, sizeof(orgid)) == 0) {
+#ifndef ENABLE_DOT1
+ unrecognized = 1;
+#else
+ /* Dot1 */
+ switch (tlv_subtype) {
+ case LLDP_TLV_DOT1_VLANNAME:
+ CHECK_TLV_SIZE(7, "VLAN");
+ if ((vlan = (struct lldpd_vlan *)calloc(1,
+ sizeof(struct lldpd_vlan))) == NULL) {
+ log_warn("lldp",
+ "unable to alloc vlan "
+ "structure for "
+ "tlv received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ vlan->v_vid = PEEK_UINT16;
+ vlan_len = PEEK_UINT8;
+ CHECK_TLV_SIZE(7 + vlan_len, "VLAN");
+ if ((vlan->v_name = (char *)calloc(1,
+ vlan_len + 1)) == NULL) {
+ log_warn("lldp",
+ "unable to alloc vlan name for "
+ "tlv received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ PEEK_BYTES(vlan->v_name, vlan_len);
+ TAILQ_INSERT_TAIL(&port->p_vlans, vlan,
+ v_entries);
+ vlan = NULL;
+ break;
+ case LLDP_TLV_DOT1_PVID:
+ CHECK_TLV_SIZE(6, "PVID");
+ port->p_pvid = PEEK_UINT16;
+ break;
+ case LLDP_TLV_DOT1_PPVID:
+ CHECK_TLV_SIZE(7, "PPVID");
+ /* validation needed */
+ /* PPVID has to be unique if more than
+ one PPVID TLVs are received -
+ discard if duplicate */
+ /* if support bit is not set and
+ enabled bit is set - PPVID TLV is
+ considered error and discarded */
+ /* if PPVID > 4096 - bad and discard */
+ if ((ppvid = (struct lldpd_ppvid *)calloc(1,
+ sizeof(struct lldpd_ppvid))) == NULL) {
+ log_warn("lldp",
+ "unable to alloc ppvid "
+ "structure for "
+ "tlv received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ ppvid->p_cap_status = PEEK_UINT8;
+ ppvid->p_ppvid = PEEK_UINT16;
+ TAILQ_INSERT_TAIL(&port->p_ppvids, ppvid,
+ p_entries);
+ break;
+ case LLDP_TLV_DOT1_PI:
+ /* validation needed */
+ /* PI has to be unique if more than
+ one PI TLVs are received - discard
+ if duplicate ?? */
+ CHECK_TLV_SIZE(5, "PI");
+ if ((pi = (struct lldpd_pi *)calloc(1,
+ sizeof(struct lldpd_pi))) == NULL) {
+ log_warn("lldp",
+ "unable to alloc PI "
+ "structure for "
+ "tlv received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ pi->p_pi_len = PEEK_UINT8;
+ CHECK_TLV_SIZE(5 + pi->p_pi_len, "PI");
+ if ((pi->p_pi = (char *)calloc(1,
+ pi->p_pi_len)) == NULL) {
+ log_warn("lldp",
+ "unable to alloc pid name for "
+ "tlv received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ PEEK_BYTES(pi->p_pi, pi->p_pi_len);
+ TAILQ_INSERT_TAIL(&port->p_pids, pi, p_entries);
+ pi = NULL;
+ break;
+ default:
+ /* Unknown Dot1 TLV, ignore it */
+ unrecognized = 1;
+ }
+#endif
+ } else if (memcmp(dot3, orgid, sizeof(orgid)) == 0) {
+#ifndef ENABLE_DOT3
+ unrecognized = 1;
+#else
+ /* Dot3 */
+ switch (tlv_subtype) {
+ case LLDP_TLV_DOT3_MAC:
+ CHECK_TLV_SIZE(9, "MAC/PHY");
+ port->p_macphy.autoneg_support = PEEK_UINT8;
+ port->p_macphy.autoneg_enabled =
+ (port->p_macphy.autoneg_support & 0x2) >> 1;
+ port->p_macphy.autoneg_support =
+ port->p_macphy.autoneg_support & 0x1;
+ port->p_macphy.autoneg_advertised = PEEK_UINT16;
+ port->p_macphy.mau_type = PEEK_UINT16;
+ break;
+ case LLDP_TLV_DOT3_LA:
+ CHECK_TLV_SIZE(9, "Link aggregation");
+ PEEK_DISCARD_UINT8;
+ port->p_aggregid = PEEK_UINT32;
+ break;
+ case LLDP_TLV_DOT3_MFS:
+ CHECK_TLV_SIZE(6, "MFS");
+ port->p_mfs = PEEK_UINT16;
+ break;
+ case LLDP_TLV_DOT3_POWER:
+ CHECK_TLV_SIZE(7, "Power");
+ port->p_power.devicetype = PEEK_UINT8;
+ port->p_power.supported =
+ (port->p_power.devicetype & 0x2) >> 1;
+ port->p_power.enabled =
+ (port->p_power.devicetype & 0x4) >> 2;
+ port->p_power.paircontrol =
+ (port->p_power.devicetype & 0x8) >> 3;
+ port->p_power.devicetype =
+ (port->p_power.devicetype & 0x1) ?
+ LLDP_DOT3_POWER_PSE :
+ LLDP_DOT3_POWER_PD;
+ port->p_power.pairs = PEEK_UINT8;
+ port->p_power.class = PEEK_UINT8;
+ /* 802.3at? */
+ if (tlv_size >= 12) {
+ port->p_power.powertype = PEEK_UINT8;
+ port->p_power.source =
+ (port->p_power.powertype &
+ (1 << 5 | 1 << 4)) >>
+ 4;
+ port->p_power.priority =
+ (port->p_power.powertype &
+ (1 << 1 | 1 << 0));
+ port->p_power.powertype =
+ (port->p_power.powertype &
+ (1 << 7)) ?
+ LLDP_DOT3_POWER_8023AT_TYPE1 :
+ LLDP_DOT3_POWER_8023AT_TYPE2;
+ port->p_power.requested = PEEK_UINT16;
+ port->p_power.allocated = PEEK_UINT16;
+ } else
+ port->p_power.powertype =
+ LLDP_DOT3_POWER_8023AT_OFF;
+ /* 802.3bt? */
+ if (tlv_size >= 29) {
+ port->p_power.requested_a = PEEK_UINT16;
+ port->p_power.requested_b = PEEK_UINT16;
+ port->p_power.allocated_a = PEEK_UINT16;
+ port->p_power.allocated_b = PEEK_UINT16;
+ port->p_power.pse_status = PEEK_UINT16;
+ port->p_power.pd_status =
+ (port->p_power.pse_status &
+ (1 << 13 | 1 << 12)) >>
+ 12;
+ port->p_power.pse_pairs_ext =
+ (port->p_power.pse_status &
+ (1 << 11 | 1 << 10)) >>
+ 10;
+ port->p_power.class_a =
+ (port->p_power.pse_status &
+ (1 << 9 | 1 << 8 | 1 << 7)) >>
+ 7;
+ port->p_power.class_b =
+ (port->p_power.pse_status &
+ (1 << 6 | 1 << 5 | 1 << 4)) >>
+ 4;
+ port->p_power.class_ext =
+ (port->p_power.pse_status & 0xf);
+ port->p_power.pse_status =
+ (port->p_power.pse_status &
+ (1 << 15 | 1 << 14)) >>
+ 14;
+ port->p_power.type_ext = PEEK_UINT8;
+ port->p_power.pd_load =
+ (port->p_power.type_ext & 0x1);
+ port->p_power.type_ext =
+ ((port->p_power.type_ext &
+ (1 << 3 | 1 << 2 | 1 << 1)) +
+ 1);
+ port->p_power.pse_max = PEEK_UINT16;
+ } else {
+ port->p_power.type_ext =
+ LLDP_DOT3_POWER_8023BT_OFF;
+ }
+ break;
+ default:
+ /* Unknown Dot3 TLV, ignore it */
+ unrecognized = 1;
+ }
+#endif
+ } else if (memcmp(med, orgid, sizeof(orgid)) == 0) {
+ /* LLDP-MED */
+#ifndef ENABLE_LLDPMED
+ unrecognized = 1;
+#else
+ u_int32_t policy;
+ unsigned loctype;
+ unsigned power;
+
+ switch (tlv_subtype) {
+ case LLDP_TLV_MED_CAP:
+ CHECK_TLV_SIZE(7, "LLDP-MED capabilities");
+ chassis->c_med_cap_available = PEEK_UINT16;
+ chassis->c_med_type = PEEK_UINT8;
+ port->p_med_cap_enabled |= LLDP_MED_CAP_CAP;
+ break;
+ case LLDP_TLV_MED_POLICY:
+ CHECK_TLV_SIZE(8, "LLDP-MED policy");
+ policy = PEEK_UINT32;
+ if (((policy >> 24) < 1) ||
+ ((policy >> 24) > LLDP_MED_APPTYPE_LAST)) {
+ log_info("lldp",
+ "unknown policy field %d "
+ "received on %s",
+ policy, hardware->h_ifname);
+ break;
+ }
+ port->p_med_policy[(policy >> 24) - 1].type =
+ (policy >> 24);
+ port->p_med_policy[(policy >> 24) - 1].unknown =
+ ((policy & 0x800000) != 0);
+ port->p_med_policy[(policy >> 24) - 1].tagged =
+ ((policy & 0x400000) != 0);
+ port->p_med_policy[(policy >> 24) - 1].vid =
+ (policy & 0x001FFE00) >> 9;
+ port->p_med_policy[(policy >> 24) - 1]
+ .priority = (policy & 0x1C0) >> 6;
+ port->p_med_policy[(policy >> 24) - 1].dscp =
+ policy & 0x3F;
+ port->p_med_cap_enabled |= LLDP_MED_CAP_POLICY;
+ break;
+ case LLDP_TLV_MED_LOCATION:
+ CHECK_TLV_SIZE(5, "LLDP-MED Location");
+ loctype = PEEK_UINT8;
+ if ((loctype < 1) ||
+ (loctype > LLDP_MED_LOCFORMAT_LAST)) {
+ log_info("lldp",
+ "unknown location type "
+ "received on %s",
+ hardware->h_ifname);
+ break;
+ }
+ free(port->p_med_location[loctype - 1].data);
+ if ((port->p_med_location[loctype - 1].data =
+ (char *)malloc(tlv_size - 5)) ==
+ NULL) {
+ log_warn("lldp",
+ "unable to allocate memory "
+ "for LLDP-MED location for "
+ "frame received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ PEEK_BYTES(
+ port->p_med_location[loctype - 1].data,
+ tlv_size - 5);
+ port->p_med_location[loctype - 1].data_len =
+ tlv_size - 5;
+ port->p_med_location[loctype - 1].format =
+ loctype;
+ port->p_med_cap_enabled |=
+ LLDP_MED_CAP_LOCATION;
+ break;
+ case LLDP_TLV_MED_MDI:
+ CHECK_TLV_SIZE(7, "LLDP-MED PoE-MDI");
+ power = PEEK_UINT8;
+ switch (power & 0xC0) {
+ case 0x0:
+ port->p_med_power.devicetype =
+ LLDP_MED_POW_TYPE_PSE;
+ port->p_med_cap_enabled |=
+ LLDP_MED_CAP_MDI_PSE;
+ switch (power & 0x30) {
+ case 0x0:
+ port->p_med_power.source =
+ LLDP_MED_POW_SOURCE_UNKNOWN;
+ break;
+ case 0x10:
+ port->p_med_power.source =
+ LLDP_MED_POW_SOURCE_PRIMARY;
+ break;
+ case 0x20:
+ port->p_med_power.source =
+ LLDP_MED_POW_SOURCE_BACKUP;
+ break;
+ default:
+ port->p_med_power.source =
+ LLDP_MED_POW_SOURCE_RESERVED;
+ }
+ break;
+ case 0x40:
+ port->p_med_power.devicetype =
+ LLDP_MED_POW_TYPE_PD;
+ port->p_med_cap_enabled |=
+ LLDP_MED_CAP_MDI_PD;
+ switch (power & 0x30) {
+ case 0x0:
+ port->p_med_power.source =
+ LLDP_MED_POW_SOURCE_UNKNOWN;
+ break;
+ case 0x10:
+ port->p_med_power.source =
+ LLDP_MED_POW_SOURCE_PSE;
+ break;
+ case 0x20:
+ port->p_med_power.source =
+ LLDP_MED_POW_SOURCE_LOCAL;
+ break;
+ default:
+ port->p_med_power.source =
+ LLDP_MED_POW_SOURCE_BOTH;
+ }
+ break;
+ default:
+ port->p_med_power.devicetype =
+ LLDP_MED_POW_TYPE_RESERVED;
+ }
+ if ((power & 0x0F) > LLDP_MED_POW_PRIO_LOW)
+ port->p_med_power.priority =
+ LLDP_MED_POW_PRIO_UNKNOWN;
+ else
+ port->p_med_power.priority =
+ power & 0x0F;
+ port->p_med_power.val = PEEK_UINT16;
+ break;
+ case LLDP_TLV_MED_IV_HW:
+ case LLDP_TLV_MED_IV_SW:
+ case LLDP_TLV_MED_IV_FW:
+ case LLDP_TLV_MED_IV_SN:
+ case LLDP_TLV_MED_IV_MANUF:
+ case LLDP_TLV_MED_IV_MODEL:
+ case LLDP_TLV_MED_IV_ASSET:
+ if (tlv_size <= 4)
+ b = NULL;
+ else {
+ if ((b = (char *)malloc(
+ tlv_size - 3)) == NULL) {
+ log_warn("lldp",
+ "unable to allocate "
+ "memory for LLDP-MED "
+ "inventory for frame "
+ "received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ PEEK_BYTES(b, tlv_size - 4);
+ b[tlv_size - 4] = '\0';
+ }
+ switch (tlv_subtype) {
+ case LLDP_TLV_MED_IV_HW:
+ free(chassis->c_med_hw);
+ chassis->c_med_hw = b;
+ break;
+ case LLDP_TLV_MED_IV_FW:
+ free(chassis->c_med_fw);
+ chassis->c_med_fw = b;
+ break;
+ case LLDP_TLV_MED_IV_SW:
+ free(chassis->c_med_sw);
+ chassis->c_med_sw = b;
+ break;
+ case LLDP_TLV_MED_IV_SN:
+ free(chassis->c_med_sn);
+ chassis->c_med_sn = b;
+ break;
+ case LLDP_TLV_MED_IV_MANUF:
+ free(chassis->c_med_manuf);
+ chassis->c_med_manuf = b;
+ break;
+ case LLDP_TLV_MED_IV_MODEL:
+ free(chassis->c_med_model);
+ chassis->c_med_model = b;
+ break;
+ case LLDP_TLV_MED_IV_ASSET:
+ free(chassis->c_med_asset);
+ chassis->c_med_asset = b;
+ break;
+ default:
+ /* unreachable */
+ free(b);
+ break;
+ }
+ port->p_med_cap_enabled |= LLDP_MED_CAP_IV;
+ break;
+ default:
+ /* Unknown LLDP MED, ignore it */
+ hardware->h_rx_unrecognized_cnt++;
+ }
+#endif /* ENABLE_LLDPMED */
+ } else if (memcmp(dcbx, orgid, sizeof(orgid)) == 0) {
+ log_debug("lldp",
+ "unsupported DCBX tlv received on %s - ignore",
+ hardware->h_ifname);
+ unrecognized = 1;
+ } else {
+ log_debug("lldp",
+ "unknown org tlv [%02x:%02x:%02x] received on %s",
+ orgid[0], orgid[1], orgid[2], hardware->h_ifname);
+ unrecognized = 1;
+ }
+ if (unrecognized) {
+ hardware->h_rx_unrecognized_cnt++;
+#ifdef ENABLE_CUSTOM
+ custom = (struct lldpd_custom *)calloc(1,
+ sizeof(struct lldpd_custom));
+ if (!custom) {
+ log_warn("lldp",
+ "unable to allocate memory for custom TLV");
+ goto malformed;
+ }
+ custom->oui_info_len = tlv_size > 4 ? tlv_size - 4 : 0;
+ memcpy(custom->oui, orgid, sizeof(custom->oui));
+ custom->subtype = tlv_subtype;
+ if (custom->oui_info_len > 0) {
+ custom->oui_info = malloc(custom->oui_info_len);
+ if (!custom->oui_info) {
+ log_warn("lldp",
+ "unable to allocate memory for custom TLV data");
+ goto malformed;
+ }
+ PEEK_BYTES(custom->oui_info,
+ custom->oui_info_len);
+ }
+ TAILQ_INSERT_TAIL(&port->p_custom_list, custom, next);
+ custom = NULL;
+#endif
+ }
+ break;
+ default:
+ log_warnx("lldp", "unknown tlv (%d) received on %s", tlv_type,
+ hardware->h_ifname);
+ hardware->h_rx_unrecognized_cnt++;
+ break;
+ }
+ if (pos > tlv + tlv_size) {
+ log_warnx("lldp", "BUG: already past TLV!");
+ goto malformed;
+ }
+ PEEK_DISCARD(tlv + tlv_size - pos);
+ }
+
+ /* Some random check */
+ if ((chassis->c_id == NULL) || (port->p_id == NULL) || (!ttl_received) ||
+ (gotend == 0)) {
+ log_warnx("lldp",
+ "some mandatory tlv are missing for frame received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ *newchassis = chassis;
+ *newport = port;
+ return 1;
+malformed:
+#ifdef ENABLE_CUSTOM
+ free(custom);
+#endif
+#ifdef ENABLE_DOT1
+ free(vlan);
+ free(pi);
+#endif
+ lldpd_chassis_cleanup(chassis, 1);
+ lldpd_port_cleanup(port, 1);
+ free(port);
+ return -1;
+}
diff --git a/src/daemon/protocols/sonmp.c b/src/daemon/protocols/sonmp.c
new file mode 100644
index 0000000..34ebcd7
--- /dev/null
+++ b/src/daemon/protocols/sonmp.c
@@ -0,0 +1,410 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2008 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "../lldpd.h"
+#include "../frame.h"
+
+#ifdef ENABLE_SONMP
+
+# include <stdio.h>
+# include <unistd.h>
+# include <errno.h>
+# include <arpa/inet.h>
+
+static struct sonmp_chassis sonmp_chassis_types[] = {
+ { 1, "unknown (via SONMP)" },
+ { 2, "Nortel 3000" },
+ { 3, "Nortel 3030" },
+ { 4, "Nortel 2310" },
+ { 5, "Nortel 2810" },
+ { 6, "Nortel 2912" },
+ { 7, "Nortel 2914" },
+ { 8, "Nortel 271x" },
+ { 9, "Nortel 2813" },
+ { 10, "Nortel 2814" },
+ { 11, "Nortel 2915" },
+ { 12, "Nortel 5000" },
+ { 13, "Nortel 2813SA" },
+ { 14, "Nortel 2814SA" },
+ { 15, "Nortel 810M" },
+ { 16, "Nortel EtherCell" },
+ { 17, "Nortel 5005" },
+ { 18, "Alcatel Ethernet workgroup conc." },
+ { 20, "Nortel 2715SA" },
+ { 21, "Nortel 2486" },
+ { 22, "Nortel 28000 series" },
+ { 23, "Nortel 23000 series" },
+ { 24, "Nortel 5DN00x series" },
+ { 25, "BayStack Ethernet" },
+ { 26, "Nortel 23100 series" },
+ { 27, "Nortel 100Base-T Hub" },
+ { 28, "Nortel 3000 Fast Ethernet" },
+ { 29, "Nortel Orion switch" },
+ { 30, "unknown" },
+ { 31, "Nortel DDS " },
+ { 32, "Nortel Centillion" },
+ { 33, "Nortel Centillion" },
+ { 34, "Nortel Centillion" },
+ { 35, "BayStack 301" },
+ { 36, "BayStack TokenRing Hub" },
+ { 37, "Nortel FVC Multimedia Switch" },
+ { 38, "Nortel Switch Node" },
+ { 39, "BayStack 302 Switch" },
+ { 40, "BayStack 350 Switch" },
+ { 41, "BayStack 150 Ethernet Hub" },
+ { 42, "Nortel Centillion 50N switch" },
+ { 43, "Nortel Centillion 50T switch" },
+ { 44, "BayStack 303 and 304 Switches" },
+ { 45, "BayStack 200 Ethernet Hub" },
+ { 46, "BayStack 250 10/100 Ethernet Hub" },
+ { 48, "BayStack 450 10/100/1000 Switches" },
+ { 49, "BayStack 410 10/100 Switches" },
+ { 50, "Nortel Ethernet Routing 1200 L3 Switch" },
+ { 51, "Nortel Ethernet Routing 1250 L3 Switch" },
+ { 52, "Nortel Ethernet Routing 1100 L3 Switch" },
+ { 53, "Nortel Ethernet Routing 1150 L3 Switch" },
+ { 54, "Nortel Ethernet Routing 1050 L3 Switch" },
+ { 55, "Nortel Ethernet Routing 1051 L3 Switch" },
+ { 56, "Nortel Ethernet Routing 8610 L3 Switch" },
+ { 57, "Nortel Ethernet Routing 8606 L3 Switch" },
+ { 58, "Nortel Ethernet Routing Switch 8010" },
+ { 59, "Nortel Ethernet Routing Switch 8006" },
+ { 60, "BayStack 670 wireless access point" },
+ { 61, "Nortel Ethernet Routing Switch 740 " },
+ { 62, "Nortel Ethernet Routing Switch 750 " },
+ { 63, "Nortel Ethernet Routing Switch 790" },
+ { 64, "Nortel Business Policy Switch 2000 10/100 Switches" },
+ { 65, "Nortel Ethernet Routing 8110 L2 Switch" },
+ { 66, "Nortel Ethernet Routing 8106 L2 Switch" },
+ { 67, "BayStack 3580 Gig Switch" },
+ { 68, "BayStack 10 Power Supply Unit" },
+ { 69, "BayStack 420 10/100 Switch" },
+ { 70, "OPTera Metro 1200 Ethernet Service Module" },
+ { 71, "Nortel Ethernet Routing Switch 8010co" },
+ { 72, "Nortel Ethernet Routing 8610co L3 switch" },
+ { 73, "Nortel Ethernet Routing 8110co L2 switch" },
+ { 74, "Nortel Ethernet Routing 8003" },
+ { 75, "Nortel Ethernet Routing 8603 L3 switch" },
+ { 76, "Nortel Ethernet Routing 8103 L2 switch" },
+ { 77, "BayStack 380 10/100/1000 Switch" },
+ { 78, "Nortel Ethernet Switch 470-48T" },
+ { 79, "OPTera Metro 1450 Ethernet Service Module" },
+ { 80, "OPTera Metro 1400 Ethernet Service Module" },
+ { 81, "Alteon Switch Family" },
+ { 82, "Ethernet Switch 460-24T-PWR" },
+ { 83, "OPTera Metro 8010 OPM L2 Switch" },
+ { 84, "OPTera Metro 8010co OPM L2 Switch" },
+ { 85, "OPTera Metro 8006 OPM L2 Switch" },
+ { 86, "OPTera Metro 8003 OPM L2 Switch" },
+ { 87, "Alteon 180e" },
+ { 88, "Alteon AD3" },
+ { 89, "Alteon 184" },
+ { 90, "Alteon AD4" },
+ { 91, "Nortel Ethernet Routing 1424 L3 switch" },
+ { 92, "Nortel Ethernet Routing 1648 L3 switch" },
+ { 93, "Nortel Ethernet Routing 1612 L3 switch" },
+ { 94, "Nortel Ethernet Routing 1624 L3 switch " },
+ { 95, "BayStack 380-24F Fiber 1000 Switch" },
+ { 96, "Nortel Ethernet Routing Switch 5510-24T" },
+ { 97, "Nortel Ethernet Routing Switch 5510-48T" },
+ { 98, "Nortel Ethernet Switch 470-24T" },
+ { 99, "Nortel Networks Wireless LAN Access Point 2220" },
+ { 100, "Ethernet Routing RBS 2402 L3 switch" },
+ { 101, "Alteon Application Switch 2424 " },
+ { 102, "Alteon Application Switch 2224 " },
+ { 103, "Alteon Application Switch 2208 " },
+ { 104, "Alteon Application Switch 2216" },
+ { 105, "Alteon Application Switch 3408" },
+ { 106, "Alteon Application Switch 3416" },
+ { 107, "Nortel Networks Wireless LAN SecuritySwitch 2250" },
+ { 108, "Ethernet Switch 425-48T" },
+ { 109, "Ethernet Switch 425-24T" },
+ { 110, "Nortel Networks Wireless LAN Access Point 2221" },
+ { 111, "Nortel Metro Ethernet Service Unit 24-T SPF switch" },
+ { 112, "Nortel Metro Ethernet Service Unit 24-T LX DC switch" },
+ { 113, "Nortel Ethernet Routing Switch 8300 10-slot chassis" },
+ { 114, "Nortel Ethernet Routing Switch 8300 6-slot chassis" },
+ { 115, "Nortel Ethernet Routing Switch 5520-24T-PWR" },
+ { 116, "Nortel Ethernet Routing Switch 5520-48T-PWR" },
+ { 117, "Nortel Networks VPN Gateway 3050" },
+ { 118, "Alteon SSL 310 10/100" },
+ { 119, "Alteon SSL 310 10/100 Fiber" },
+ { 120, "Alteon SSL 310 10/100 FIPS" },
+ { 121, "Alteon SSL 410 10/100/1000" },
+ { 122, "Alteon SSL 410 10/100/1000 Fiber" },
+ { 123, "Alteon Application Switch 2424-SSL" },
+ { 124, "Nortel Ethernet Switch 325-24T" },
+ { 125, "Nortel Ethernet Switch 325-24G" },
+ { 126, "Nortel Networks Wireless LAN Access Point 2225" },
+ { 127, "Nortel Networks Wireless LAN SecuritySwitch 2270" },
+ { 128, "Nortel 24-port Ethernet Switch 470-24T-PWR" },
+ { 129, "Nortel 48-port Ethernet Switch 470-48T-PWR" },
+ { 130, "Nortel Ethernet Routing Switch 5530-24TFD" },
+ { 131, "Nortel Ethernet Switch 3510-24T" },
+ { 132, "Nortel Metro Ethernet Service Unit 12G AC L3 switch" },
+ { 133, "Nortel Metro Ethernet Service Unit 12G DC L3 switch" },
+ { 134, "Nortel Secure Access Switch" },
+ { 135, "Networks VPN Gateway 3070" },
+ { 136, "OPTera Metro 3500" },
+ { 137, "SMB BES 1010 24T" },
+ { 138, "SMB BES 1010 48T" },
+ { 139, "SMB BES 1020 24T PWR" },
+ { 140, "SMB BES 1020 48T PWR" },
+ { 141, "SMB BES 2010 24T" },
+ { 142, "SMB BES 2010 48T" },
+ { 143, "SMB BES 2020 24T PWR" },
+ { 144, "SMB BES 2020 48T PWR" },
+ { 145, "SMB BES 110 24T" },
+ { 146, "SMB BES 110 48T" },
+ { 147, "SMB BES 120 24T PWR" },
+ { 148, "SMB BES 120 48T PWR" },
+ { 149, "SMB BES 210 24T" },
+ { 150, "SMB BES 210 48T" },
+ { 151, "SMB BES 220 24T PWR" },
+ { 152, "SMB BES 220 48T PWR" },
+ { 153, "OME 6500" },
+ { 0, "unknown (via SONMP)" },
+};
+
+int
+sonmp_send(struct lldpd *global, struct lldpd_hardware *hardware)
+{
+ const u_int8_t mcastaddr[] = SONMP_MULTICAST_ADDR;
+ const u_int8_t llcorg[] = LLC_ORG_NORTEL;
+ struct lldpd_chassis *chassis;
+ struct lldpd_mgmt *mgmt;
+ u_int8_t *packet, *pos, *pos_pid, *end;
+ int length;
+ struct in_addr address;
+
+ log_debug("sonmp", "send SONMP PDU to %s", hardware->h_ifname);
+
+ chassis = hardware->h_lport.p_chassis;
+ length = hardware->h_mtu;
+ if ((packet = (u_int8_t *)calloc(1, length)) == NULL) return ENOMEM;
+ pos = packet;
+
+ /* Ethernet header */
+ if (!(
+ /* SONMP multicast address as target */
+ POKE_BYTES(mcastaddr, sizeof(mcastaddr)) &&
+ /* Source MAC addresss */
+ POKE_BYTES(&hardware->h_lladdr, ETHER_ADDR_LEN) &&
+ /* SONMP frame is of fixed size */
+ POKE_UINT16(SONMP_SIZE)))
+ goto toobig;
+
+ /* LLC header */
+ if (!(
+ /* DSAP and SSAP */
+ POKE_UINT8(0xaa) && POKE_UINT8(0xaa) &&
+ /* Control field */
+ POKE_UINT8(0x03) &&
+ /* ORG */
+ POKE_BYTES(llcorg, sizeof(llcorg)) &&
+ POKE_SAVE(pos_pid) && /* We will modify PID later to
+ create a new frame */
+ POKE_UINT16(LLC_PID_SONMP_HELLO)))
+ goto toobig;
+
+ address.s_addr = htonl(INADDR_ANY);
+ TAILQ_FOREACH (mgmt, &chassis->c_mgmt, m_entries) {
+ if (mgmt->m_family == LLDPD_AF_IPV4) {
+ address.s_addr = mgmt->m_addr.inet.s_addr;
+ }
+ break;
+ }
+
+ /* SONMP */
+ if (!(
+ /* Our IP address */
+ POKE_BYTES(&address, sizeof(struct in_addr)) &&
+ /* Segment on three bytes, we don't have slots, so we
+ skip the first two bytes */
+ POKE_UINT16(0) && POKE_UINT8(hardware->h_ifindex) &&
+ POKE_UINT8(1) && /* Chassis: Other */
+ POKE_UINT8(12) && /* Back: Ethernet, Fast Ethernet and Gigabit */
+ POKE_UINT8(SONMP_TOPOLOGY_NEW) && /* Should work. We have no state */
+ POKE_UINT8(1) && /* Links: Dunno what it is */
+ POKE_SAVE(end)))
+ goto toobig;
+
+ if (interfaces_send_helper(global, hardware, (char *)packet, end - packet) ==
+ -1) {
+ log_warn("sonmp", "unable to send packet on real device for %s",
+ hardware->h_ifname);
+ free(packet);
+ return ENETDOWN;
+ }
+
+ POKE_RESTORE(pos_pid); /* Modify LLC PID */
+ (void)POKE_UINT16(LLC_PID_SONMP_FLATNET);
+ POKE_RESTORE(packet); /* Go to the beginning */
+ PEEK_DISCARD(ETHER_ADDR_LEN - 1); /* Modify the last byte of the MAC address */
+ (void)POKE_UINT8(1);
+
+ if (interfaces_send_helper(global, hardware, (char *)packet, end - packet) ==
+ -1) {
+ log_warn("sonmp",
+ "unable to send second SONMP packet on real device for %s",
+ hardware->h_ifname);
+ free(packet);
+ return ENETDOWN;
+ }
+
+ free(packet);
+ hardware->h_tx_cnt++;
+ return 0;
+toobig:
+ free(packet);
+ return -1;
+}
+
+int
+sonmp_decode(struct lldpd *cfg, char *frame, int s, struct lldpd_hardware *hardware,
+ struct lldpd_chassis **newchassis, struct lldpd_port **newport)
+{
+ const u_int8_t mcastaddr[] = SONMP_MULTICAST_ADDR;
+ struct lldpd_chassis *chassis;
+ struct lldpd_port *port;
+ struct lldpd_mgmt *mgmt;
+ int length, i;
+ u_int8_t *pos;
+ u_int8_t seg[3], rchassis;
+ struct in_addr address;
+
+ log_debug("sonmp", "decode SONMP PDU from %s", hardware->h_ifname);
+
+ if ((chassis = calloc(1, sizeof(struct lldpd_chassis))) == NULL) {
+ log_warn("sonmp", "failed to allocate remote chassis");
+ return -1;
+ }
+ TAILQ_INIT(&chassis->c_mgmt);
+ if ((port = calloc(1, sizeof(struct lldpd_port))) == NULL) {
+ log_warn("sonmp", "failed to allocate remote port");
+ free(chassis);
+ return -1;
+ }
+# ifdef ENABLE_DOT1
+ TAILQ_INIT(&port->p_vlans);
+# endif
+
+ length = s;
+ pos = (u_int8_t *)frame;
+ if (length < SONMP_SIZE + 2 * ETHER_ADDR_LEN + sizeof(u_int16_t)) {
+ log_warnx("sonmp", "too short SONMP frame received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ if (PEEK_CMP(mcastaddr, sizeof(mcastaddr)) != 0)
+ /* There is two multicast address. We just handle only one of
+ * them. */
+ goto malformed;
+ /* We skip to LLC PID */
+ PEEK_DISCARD(ETHER_ADDR_LEN);
+ PEEK_DISCARD_UINT16;
+ PEEK_DISCARD(6);
+ if (PEEK_UINT16 != LLC_PID_SONMP_HELLO) {
+ log_debug("sonmp", "incorrect LLC protocol ID received for SONMP on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+
+ chassis->c_id_subtype = LLDP_CHASSISID_SUBTYPE_ADDR;
+ if ((chassis->c_id = calloc(1, sizeof(struct in_addr) + 1)) == NULL) {
+ log_warn("sonmp", "unable to allocate memory for chassis id on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ chassis->c_id_len = sizeof(struct in_addr) + 1;
+ chassis->c_id[0] = 1;
+ PEEK_BYTES(&address, sizeof(struct in_addr));
+ memcpy(chassis->c_id + 1, &address, sizeof(struct in_addr));
+ if (asprintf(&chassis->c_name, "%s", inet_ntoa(address)) == -1) {
+ log_warnx("sonmp", "unable to write chassis name for %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ PEEK_BYTES(seg, sizeof(seg));
+ rchassis = PEEK_UINT8;
+ for (i = 0; sonmp_chassis_types[i].type != 0; i++) {
+ if (sonmp_chassis_types[i].type == rchassis) break;
+ }
+ if (asprintf(&chassis->c_descr, "%s", sonmp_chassis_types[i].description) ==
+ -1) {
+ log_warnx("sonmp", "unable to write chassis description for %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ mgmt = lldpd_alloc_mgmt(LLDPD_AF_IPV4, &address, sizeof(struct in_addr), 0);
+ if (mgmt == NULL) {
+ if (errno == ENOMEM)
+ log_warn("sonmp",
+ "unable to allocate memory for management address");
+ else
+ log_warn("sonmp", "too large management address received on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ TAILQ_INSERT_TAIL(&chassis->c_mgmt, mgmt, m_entries);
+ port->p_ttl =
+ cfg ? (cfg->g_config.c_tx_interval * cfg->g_config.c_tx_hold) : LLDPD_TTL;
+ port->p_ttl = (port->p_ttl + 999) / 1000;
+
+ port->p_id_subtype = LLDP_PORTID_SUBTYPE_LOCAL;
+
+ port->p_id_len =
+ asprintf(&port->p_id, "%02x-%02x-%02x", seg[0], seg[1], seg[2]);
+ if (port->p_id_len == -1) {
+ log_warn("sonmp", "unable to allocate memory for port id on %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+
+ /* Port description depend on the number of segments */
+ if ((seg[0] == 0) && (seg[1] == 0)) {
+ if (asprintf(&port->p_descr, "port %d", seg[2]) == -1) {
+ log_warnx("sonmp", "unable to write port description for %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ } else if (seg[0] == 0) {
+ if (asprintf(&port->p_descr, "port %d/%d", seg[1], seg[2]) == -1) {
+ log_warnx("sonmp", "unable to write port description for %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ } else {
+ if (asprintf(&port->p_descr, "port %x:%x:%x", seg[0], seg[1], seg[2]) ==
+ -1) {
+ log_warnx("sonmp", "unable to write port description for %s",
+ hardware->h_ifname);
+ goto malformed;
+ }
+ }
+ *newchassis = chassis;
+ *newport = port;
+ return 1;
+
+malformed:
+ lldpd_chassis_cleanup(chassis, 1);
+ lldpd_port_cleanup(port, 1);
+ free(port);
+ return -1;
+}
+
+#endif /* ENABLE_SONMP */
diff --git a/src/daemon/protocols/sonmp.h b/src/daemon/protocols/sonmp.h
new file mode 100644
index 0000000..513c4bb
--- /dev/null
+++ b/src/daemon/protocols/sonmp.h
@@ -0,0 +1,42 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2008 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _SONMP_H
+#define _SONMP_H
+
+#define SONMP_MULTICAST_ADDR \
+ { \
+ 0x01, 0x00, 0x81, 0x00, 0x01, 0x00 \
+ }
+#define LLC_ORG_NORTEL \
+ { \
+ 0x00, 0x00, 0x81 \
+ }
+#define LLC_PID_SONMP_HELLO 0x01a2
+#define LLC_PID_SONMP_FLATNET 0x01a1
+#define SONMP_SIZE 19
+
+struct sonmp_chassis {
+ int type;
+ const char *description;
+};
+
+#define SONMP_TOPOLOGY_CHANGED 1
+#define SONMP_TOPOLOGY_UNCHANGED 2
+#define SONMP_TOPOLOGY_NEW 3
+
+#endif /* _SONMP_H */
diff --git a/src/daemon/trace.h b/src/daemon/trace.h
new file mode 100644
index 0000000..2e7c482
--- /dev/null
+++ b/src/daemon/trace.h
@@ -0,0 +1,8 @@
+#ifdef ENABLE_DTRACE
+# include "probes.h"
+# define TRACE(probe) probe
+# define TRACE_ENABLED(probe) probe##_ENABLED()
+#else
+# define TRACE(probe)
+# define TRACE_ENABLED(probe) (0)
+#endif
diff --git a/src/daemon/usr.sbin.lldpd.in b/src/daemon/usr.sbin.lldpd.in
new file mode 100644
index 0000000..d459cd4
--- /dev/null
+++ b/src/daemon/usr.sbin.lldpd.in
@@ -0,0 +1,65 @@
+#include <tunables/global>
+
+@sbindir@/lldpd {
+ #include <abstractions/base>
+ #include <abstractions/nameservice>
+
+ capability chown,
+ capability dac_override,
+ capability fowner,
+ capability fsetid,
+ capability kill,
+ capability net_admin,
+ capability net_raw,
+ capability setgid,
+ capability setuid,
+ capability sys_chroot,
+ capability sys_module,
+
+ # Need to receive/send raw packets
+ network packet raw,
+
+ @sbindir@/lldpd mr,
+ /run/systemd/notify w,
+
+ # Ability to run lldpcli for self-configuration
+ @sbindir@/lldpcli rix,
+ @sysconfdir@/lldpd.d/ r,
+ @sysconfdir@/lldpd.d/* r,
+ @sysconfdir@/lldpd.conf r,
+
+ # PID file and socket
+ @LLDPD_PID_FILE@ rw,
+ @LLDPD_CTL_SOCKET@ rw,
+
+ # Chroot setup
+ @PRIVSEP_CHROOT@ w,
+ @PRIVSEP_CHROOT@/etc/ rw,
+ @PRIVSEP_CHROOT@/etc/localtime rw,
+
+ # Gather system description
+ /etc/os-release r,
+ /usr/lib/os-release r,
+ /usr/bin/lsb_release Cxr -> lsb_release,
+ profile lsb_release {
+ #include <abstractions/base>
+ #include <abstractions/python>
+ /usr/bin/lsb_release r,
+ /bin/dash ixr,
+ /usr/bin/dpkg-query ixr,
+ /usr/include/python2.[4567]/pyconfig.h r,
+ /etc/lsb-release r,
+ /etc/debian_version r,
+ /var/lib/dpkg/** r,
+ /usr/local/lib/python3.[0-5]/dist-packages/ r,
+ /usr/bin/ r,
+ /usr/bin/python3.[0-5] r,
+ }
+
+ # Gather network information
+ @{PROC}/sys/net/ipv4/ip_forward r,
+ @{PROC}/net/bonding/* r,
+ @{PROC}/self/net/bonding/* r,
+ /sys/devices/virtual/dmi/** r,
+ /sys/devices/pci**/net/*/ifalias r,
+}