RHEL 9.0.0 Alpha bootstrap

The content of this branch was automatically imported from Fedora ELN
with the following as its source:
https://src.fedoraproject.org/rpms/lldpd#dac3c9398481e5b7f9afb87e726f95595abf640f
This commit is contained in:
Petr Šabata 2020-10-15 18:26:28 +02:00
parent ff0800927f
commit a19345f6ba
11 changed files with 673 additions and 0 deletions

4
.gitignore vendored
View File

@ -0,0 +1,4 @@
/lldpd-0.9.7.tar.gz
/lldpd-0.9.8.tar.gz
/lldpd-1.0.1.tar.gz
/lldpd-1.0.4.tar.gz

104
lldpd-el6.init Normal file
View File

@ -0,0 +1,104 @@
#!/bin/bash
# lldpd init file
#
# chkconfig: - 60 20
# description: 802.1ab (LLDP) daemon
#
# processname: lldpd
# pidfile: /var/run/lldpd.pid
### BEGIN INIT INFO
# Provides: lldpd
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Should-Start: $syslog $network $net-snmp
# Should-Stop: $syslog $network $net-snmp
# Default-Stop: 0 1 6
# Short-Description: LLDP daemon
# Description: 802.1ab (LLDP) daemon
### END INIT INFO
# source function library
. /etc/rc.d/init.d/functions
exec="/usr/sbin/lldpd"
prog="lldpd"
config="/etc/lldpd.d"
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
lockfile=/var/lock/subsys/$prog
start() {
[ -x $exec ] || exit 4
[ -d $config ] || exit 6
echo -n $"Starting $prog: "
daemon $exec $LLDPD_OPTIONS
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $exec
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $RETVAL
}
restart() {
stop
start
}
reload() {
restart
}
force_reload() {
restart
}
rh_status() {
# run checks to determine if the service is running or use generic status
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
exit 2
esac
exit $?

20
lldpd-el7.service Normal file
View File

@ -0,0 +1,20 @@
[Unit]
Description=LLDP daemon
Documentation=man:lldpd(8)
After=network.target
[Service]
Type=notify
NotifyAccess=main
EnvironmentFile=-/etc/sysconfig/lldpd
ExecStart=/usr/sbin/lldpd $DAEMON_ARGS $LLDPD_OPTIONS
Restart=on-failure
PrivateTmp=yes
RestrictAddressFamilies=AF_INET AF_INET6 AF_PACKET AF_NETLINK AF_UNIX
ProtectHome=yes
ReadWriteDirectories=/var/run/lldpd
ProtectSystem=full
[Install]
WantedBy=multi-user.target

23
lldpd-fedora.service Normal file
View File

@ -0,0 +1,23 @@
[Unit]
Description=LLDP daemon
Documentation=man:lldpd(8)
After=network.target
[Service]
Type=notify
NotifyAccess=main
EnvironmentFile=-/etc/sysconfig/lldpd
ExecStart=/usr/sbin/lldpd $DAEMON_ARGS $LLDPD_OPTIONS
Restart=on-failure
PrivateTmp=yes
RestrictAddressFamilies=AF_INET AF_INET6 AF_PACKET AF_NETLINK AF_UNIX
ProtectHome=yes
ReadWritePaths=/var/run/lldpd
ProtectSystem=strict
ProtectKernelTunables=yes
ProtectControlGroups=yes
ProtectKernelModules=yes
[Install]
WantedBy=multi-user.target

8
lldpd-fedora.sysconfig Normal file
View File

@ -0,0 +1,8 @@
## Path: Network/Discovery
## Description: lldpd configuration
## Type: string(-x,-c,-s,-e,-f)
## Default: ""
## ServiceRestart: lldpd
# Parameters for lldpd. See the manual page for the
# accepted parameters.
LLDPD_OPTIONS=""

2
lldpd-tmpfiles Normal file
View File

@ -0,0 +1,2 @@
d /run/lldpd 0755 root root -
d /run/lldpd/chroot 0755 root root -

243
lldpd.spec Normal file
View File

@ -0,0 +1,243 @@
%if 0%{?el6}
%bcond_with systemd
%global rundir /var/run/
%else
%bcond_without systemd
%global rundir /run/
%endif
%global gh_owner vincentbernat
Name: lldpd
Version: 1.0.4
Release: 5%{?dist}
Summary: ISC-licensed implementation of LLDP
License: ISC
URL: https://%{gh_owner}.github.io/%{name}/
Source0: https://media.luffy.cx/files/lldpd/lldpd-%{version}.tar.gz
Source1: %{name}-fedora.service
Source2: %{name}-tmpfiles
Source3: %{name}-fedora.sysconfig
Source4: %{name}-el6.init
Source5: %{name}-el7.service
BuildRequires: gcc
BuildRequires: readline-devel
BuildRequires: check-devel
BuildRequires: net-snmp-devel
BuildRequires: libxml2-devel
# EL6 needs libevent2 as the package
%if 0%{?el6}
BuildRequires: libevent2-devel
%else
BuildRequires: libevent-devel
%endif
%if 0%{?with_systemd}
# For systemd stuff
BuildRequires: systemd
%{?systemd_requires}
%else
Requires(post): chkconfig
Requires(preun): chkconfig
# This is for /sbin/service
Requires(preun): initscripts
%endif
Requires(pre): shadow-utils
%description
LLDP is an industry standard protocol designed to supplant proprietary
Link-Layer protocols such as EDP or CDP. The goal of LLDP is to provide
an inter-vendor compatible mechanism to deliver Link-Layer notifications
to adjacent network devices.
%package devel
Requires: %{name}%{?_isa} = %{version}-%{release}
Summary: %{summary}
%description devel
%{name} development libraries and headers
%prep
%autosetup
%build
%configure --disable-static --with-snmp --disable-silent-rules \
--with-privsep-user=%{name} --with-privsep-group=%{name} \
--with-privsep-chroot=%{rundir}%{name}/chroot \
--with-lldpd-ctl-socket=%{rundir}%{name}/%{name}.socket \
%if 0%{?with_systemd}
--with-systemdsystemunitdir=%{_unitdir} --with-sysusersdir=no
%endif
make %{?_smp_mflags}
%install
%make_install
%if 0%{?with_systemd}
%if 0%{?fedora} >= 26
install -p -D -m644 %{SOURCE1} %{buildroot}%{_unitdir}/%{name}.service
%else
install -p -D -m644 %{SOURCE5} %{buildroot}%{_unitdir}/%{name}.service
%endif
install -p -D -m644 %{SOURCE2} %{buildroot}%{_tmpfilesdir}/%{name}.conf
%else
install -p -D -m755 %{SOURCE4} %{buildroot}%{_initddir}/%{name}
%endif
install -p -D -m644 %{SOURCE3} %{buildroot}/etc/sysconfig/%{name}
install -d -D -m 0755 %{buildroot}%{rundir}%{name}/chroot
install -d -m 0755 %{buildroot}%{_sharedstatedir}/%{name}
# remove the docs from buildroot
rm -rf %{buildroot}/usr/share/doc/%{name}
# don't include completion conf yet
rm -f %{buildroot}/usr/share/bash-completion/completions/lldpcli
rm -f %{buildroot}/usr/share/zsh/vendor-completions/_lldpcli
rm -f %{buildroot}/usr/share/zsh/site-functions/_lldpcli
# remove static libtool archive
rm -f %{buildroot}%{_libdir}/liblldpctl.la
%pre
getent group %{name} >/dev/null || groupadd -r %{name}
getent passwd %{name} >/dev/null || \
useradd -r -g %{name} -d %{_sharedstatedir}/%{name} -s /sbin/nologin \
-c "Used by the %{name} daemon" %{name}
exit 0
%post
/sbin/ldconfig
%if 0%{?with_systemd}
%systemd_post %{name}.service
%else
# This adds the proper /etc/rc*.d links for the script
/sbin/chkconfig --add %{name}
%endif
%preun
%if 0%{?with_systemd}
%systemd_preun %{name}.service
%else
if [ $1 -eq 0 ] ; then
/sbin/service %{name} stop >/dev/null 2>&1
/sbin/chkconfig --del %{name}
fi
%endif
%postun
/sbin/ldconfig
%if 0%{?with_systemd}
%systemd_postun_with_restart %{name}.service
%else
if [ "$1" -ge "1" ] ; then
/sbin/service %{name} condrestart >/dev/null 2>&1 || :
fi
%endif
%files
%doc NEWS README.md
%license LICENSE
%{_sbindir}/lldpcli
%{_sbindir}/lldpctl
%{_sbindir}/%{name}
%config %{_sysconfdir}/%{name}.d
%config(noreplace) %{_sysconfdir}/sysconfig/%{name}
%{_mandir}/man8/lldpcli.8*
%{_mandir}/man8/lldpctl.8*
%{_mandir}/man8/%{name}.8*
%{_libdir}/liblldpctl.so.4
%{_libdir}/liblldpctl.so.4.8.0
%dir %{rundir}%{name}
%dir %{rundir}%{name}/chroot
%if 0%{?with_systemd}
%{_unitdir}/%{name}.service
%{_tmpfilesdir}/%{name}.conf
%else
%{_initddir}/%{name}
%endif
%dir %attr(-,lldpd,lldpd) %{_sharedstatedir}/%{name}
%files devel
%{_includedir}/lldp-const.h
%{_includedir}/lldpctl.h
%{_libdir}/liblldpctl.so
%{_libdir}/pkgconfig/lldpctl.pc
%changelog
* Tue Sep 29 20:35:23 CEST 2020 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> - 1.0.4-5
- Rebuilt for libevent 2.1.12
* Wed Sep 02 2020 Josef Ridky <jridky@redhat.com> - 1.0.4-4
- Rebuilt for new net-snmp release
* Tue Jul 28 2020 Fedora Release Engineering <releng@fedoraproject.org> - 1.0.4-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild
* Wed Jan 29 2020 Fedora Release Engineering <releng@fedoraproject.org> - 1.0.4-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_32_Mass_Rebuild
* Tue Aug 13 2019 James Hogarth <james.hogarth@gmail.com> - 1.0.4-1
- Updated to new upstream release 1.0.4
* Thu Jul 25 2019 Fedora Release Engineering <releng@fedoraproject.org> - 1.0.1-6
- Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild
* Sun Feb 17 2019 Igor Gnatenko <ignatenkobrain@fedoraproject.org> - 1.0.1-5
- Rebuild for readline 8.0
* Fri Feb 01 2019 Fedora Release Engineering <releng@fedoraproject.org> - 1.0.1-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild
* Tue Jul 24 2018 Adam Williamson <awilliam@redhat.com> - 1.0.1-3
- Rebuild for new net-snmp
* Fri Jul 13 2018 Fedora Release Engineering <releng@fedoraproject.org> - 1.0.1-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_29_Mass_Rebuild
* Tue Apr 17 2018 James Hogarth <james.hogarth@gmail.com> - 1.0.1-1
- Update to 1.0.1
* Thu Feb 08 2018 Fedora Release Engineering <releng@fedoraproject.org> - 0.9.8-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild
* Mon Aug 21 2017 James Hogarth <james.hogarth@gmail.com> - 0.9.8-1
- Update to 0.9.8
* Fri Aug 11 2017 Igor Gnatenko <ignatenko@redhat.com> - 0.9.7-10
- Rebuilt after RPM update (№ 3)
* Thu Aug 10 2017 Igor Gnatenko <ignatenko@redhat.com> - 0.9.7-9
- Rebuilt for RPM soname bump
* Thu Aug 10 2017 Igor Gnatenko <ignatenko@redhat.com> - 0.9.7-8
- Rebuilt for RPM soname bump
* Thu Aug 03 2017 Fedora Release Engineering <releng@fedoraproject.org> - 0.9.7-7
- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Binutils_Mass_Rebuild
* Wed Jul 26 2017 Fedora Release Engineering <releng@fedoraproject.org> - 0.9.7-6
- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Mass_Rebuild
* Thu Apr 06 2017 James Hogarth <james.hogarth@gmail.com> - 0.9.7-5
- Older fedora needs the older syntax matching EPEL7
* Wed Apr 05 2017 James Hogarth <james.hogarth@gmail.com> - 0.9.7-4
- EPEL7 systemd needs an older syntax
* Wed Apr 05 2017 James Hogarth <james.hogarth@gmail.com> - 0.9.7-3
- Use the official release tarball rather than the github snapshot
- Add EPEL6 conditionals
* Wed Apr 05 2017 James Hogarth <james.hogarth@gmail.com> - 0.9.7-2
- Tweaks to spec requested in review
* Tue Apr 04 2017 James Hogarth <james.hogarth@gmail.com> - 0.9.7-1
- Initial package

1
sources Normal file
View File

@ -0,0 +1 @@
SHA512 (lldpd-1.0.4.tar.gz) = a5537acf2ca3be22a70124101c1c70713e655aee8d6344d25901aa5eff1efd5afb221364b9c92388bf3edf74c4cd5841fb7c9ba77745ac3cd80051bc0bad1ac9

View File

@ -0,0 +1,220 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: LGPL-2.1+
# ~~~
# lldpd-test.py integration test
# Description: Test for lldpd: implementation of IEEE 802.1ab (LLDP)
#
# Author: Susant Sahani <susant@redhat.com>
# Copyright (c) 2018 Red Hat, Inc.
#~~~
import errno
import os
import sys
import time
import unittest
import subprocess
import signal
import shutil
import re
import psutil
import socket
LLDPD_TCP_DUMP_FILE='/tmp/lldpd-tcp-dump.pcap'
LLDPD_PID_FILE='/var/run/lldpd.pid'
SERVICE_UNITDIR = '/run/systemd/system'
NETWORK_UNITDIR = '/run/systemd/network'
def setUpModule():
"""Initialize the environment, and perform sanity checks on it."""
if shutil.which('lldpd') is None:
raise OSError(errno.ENOENT, 'lldpd not found')
# Ensure the unit directory exists so tests can dump files into it.
os.makedirs(NETWORK_UNITDIR, exist_ok=True)
class lldpdUtilities():
"""Provide a set of utility functions start stop lldpd ."""
def Startlldpd(self):
"""Start lldpd interface lldpd-peer """
subprocess.check_output(['/usr/sbin/lldpd', '-cfse', '-D', '-C', 'lldpd-peer', '-I', 'lldpd-peer', '-S', 'lldpd-system-name','-m', '192.168.50.6'])
def Stoplldpd(self):
try:
with open(LLDPD_PID_FILE, 'r') as f:
pid = f.read().rstrip(' \t\r\n\0')
os.kill(int(pid), signal.SIGTERM)
os.remove(LLDPD_PID_FILE)
except IOError:
pass
def StartCaptureLLDPPackets(self):
"""Start tcpdump to capture packets"""
self.WriteServiceFile('tcpdump.service', '''\
[Unit]
Description=TCPDumpd
After=multi-user.target network.target
[Service]
Type=simple
ExecStart=/usr/sbin/tcpdump -pnnli lldpd ether proto 0x88cc -vvv -w "/tmp/lldpd-tcp-dump.pcap"
[Install]
WantedBy=multi-user.target
''')
subprocess.check_output(['systemctl','daemon-reload'])
subprocess.check_output(['systemctl','restart', 'tcpdump.service'])
def StopCapturingPackets(self):
subprocess.check_output(['systemctl', 'stop', 'tcpdump.service'])
time.sleep(3);
def SetupVethInterface(self):
"""Setup veth interface"""
subprocess.check_output(['ip', 'link', 'add', 'lldpd', 'type', 'veth', 'peer', 'name', 'lldpd-peer'])
subprocess.check_output(['ip', 'link', 'set', 'lldpd', 'address', '02:01:02:03:04:08'])
subprocess.check_output(['ip', 'link', 'set', 'lldpd-peer', 'address', '02:01:02:03:04:09'])
subprocess.check_output(['ip', 'link', 'set', 'lldpd', 'up'])
subprocess.check_output(['ip', 'link', 'set', 'lldpd-peer', 'up'])
time.sleep(3);
self.addCleanup(subprocess.call, ['ip', 'link', 'del', 'dev', 'lldpd'])
def WriteServiceFile(self, unit_name, contents):
"""Write a tcpdump unit file, and queue it to be removed."""
unit_path = os.path.join(SERVICE_UNITDIR, unit_name)
with open(unit_path, 'w') as unit:
unit.write(contents)
self.addCleanup(os.remove, unit_path)
def WriteNetworkFile(self, unit_name, contents):
"""Write a networkd unit file, and queue it to be removed."""
unit_path = os.path.join(NETWORK_UNITDIR, unit_name)
with open(unit_path, 'w') as unit:
unit.write(contents)
self.addCleanup(os.remove, unit_path)
def FindProtocolFieldsinTCPDump(self, **kwargs):
"""Look attributes in lldpd logs."""
contents = subprocess.check_output(['tcpdump', '-v', '-r', LLDPD_TCP_DUMP_FILE]).rstrip().decode('utf-8')
if kwargs is not None:
for key in kwargs:
self.assertRegex(contents, kwargs[key])
class lldpdTestsViaNetworkd(unittest.TestCase, lldpdUtilities):
def setUp(self):
""" Setup veth interface """
self.WriteNetworkFile('lldpd-veth.netdev', '''\
[NetDev]
Name=lldpd
Kind=veth
MACAddress=12:34:56:78:9a:bc
[Peer]
Name=lldpd-peer
MACAddress=12:34:56:78:9a:bd
''')
""" Receive LLDP packets via networkd """
self.WriteNetworkFile('lldp.network', '''\
[Match]
Name=lldpd
[Network]
DHCP=no
IPv6AcceptRA=false
LLDP=yes
EmitLLDP=yes
''')
""" Receive LLDP packets via networkd """
self.WriteNetworkFile('lldp-peer.network', '''\
[Match]
Name=lldpd-peer
''')
subprocess.check_output(['systemctl', 'restart', 'systemd-networkd'])
time.sleep(5)
def tearDown(self):
self.Stoplldpd()
subprocess.check_output(['ip', 'link', 'del', 'lldpd'])
def test_lldpd_received_lldp_packets_sent_by_systemd_networkd(self):
self.Startlldpd()
time.sleep(10)
''' Test whether lldpd receved LLDP packets from networkd '''
output=subprocess.check_output(['lldpctl']).rstrip().decode('utf-8')
self.assertRegex(output, "ifname lldpd")
self.assertRegex(output, socket.gethostname())
def test_systemd_networkd_received_lldp_packets(self):
self.Startlldpd()
time.sleep(10)
# lldpd 02:01:02:03:04:09 [hostname] 02:01:02:03:04:09 lldpd-peer
output=subprocess.check_output(['networkctl', 'lldp', '--no-legend', '--no-pager']).rstrip().decode('utf-8')
self.assertRegex(output, "lldpd")
self.assertRegex(output, "lldpd-peer")
self.assertRegex(output, "12:34:56:78:9a:bd")
self.assertRegex(output, socket.gethostname())
# Port ID and Chasiss id count should be 2
self.assertEqual(2, output.count("12:34:56:78:9a:bd"))
class lldpdTests(unittest.TestCase, lldpdUtilities):
def setUp(self):
""" Setup """
self.SetupVethInterface()
def tearDown(self):
self.Stoplldpd()
os.remove(LLDPD_TCP_DUMP_FILE)
def test_lldpd_trasmitted_lldp_attributes(self):
""" verify at the other end of veth received LLDP packets that contains attibutes (link address, hostname, TTL, system desc). tcpdump """
self.StartCaptureLLDPPackets()
self.Startlldpd()
""" capture for 10 seconds """
time.sleep(10)
self.StopCapturingPackets()
self.FindProtocolFieldsinTCPDump(Chassis='Subtype MAC address \(4\): 02:01:02:03:04:09',
Port='Subtype MAC address \(3\): 02:01:02:03:04:09',
PortDesc='lldpd-peer',
TTL='TTL.*120s',
HostName=socket.gethostname() ,
System_Description='lldpd-system-name',
ManagementAddress='192.168.50.6')
def test_lldpd_trasmitted_lldp_packets(self):
""" verify at the other end of veth ifname lldpd has received LLDP packets. tcpdump """
self.StartCaptureLLDPPackets()
self.Startlldpd()
""" capture for 10 seconds """
time.sleep(10)
self.StopCapturingPackets()
self.FindProtocolFieldsinTCPDump(MAC='02:01:02:03:04:09',
TTL='TTL 120s')
if __name__ == '__main__':
unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout,
verbosity=2))

View File

@ -0,0 +1,35 @@
#!/bin/bash
# SPDX-License-Identifier: LGPL-2.1+
# ~~~
# LLDPD integration test
# Description: Test for ladpd:implementation of IEEE 802.1ab (LLDP)
#
# Author: Susant Sahani <susant@redhat.com>
# Copyright (c) 2018 Red Hat, Inc.
#~~~
# Include Beaker environment
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE="lldpd"
LadpdPidFile="/var/run/lldpd.pid"
rlJournalStart
rlPhaseStartSetup
rlAssertRpm $PACKAGE
rlRun "cp lldpd-tests.py /usr/bin/"
rlPhaseEnd
rlPhaseStartTest
rlLog "lladpd tests"
rlRun "/usr/bin/python3 /usr/bin/lldpd-tests.py"
rlPhaseEnd
rlPhaseStartCleanup
rlRun "rm /usr/bin/lldpd-tests.py"
rlLog "lladpd tests done"
rlPhaseEnd
rlJournalPrintText
rlJournalEnd
rlGetTestState

13
tests/tests.yml Normal file
View File

@ -0,0 +1,13 @@
- hosts: localhost
roles:
- role: standard-test-beakerlib
tags:
- classic
tests:
- miscellaneous-tests
required_packages:
- lldpd
- python3
- tcpdump
- systemd
- iproute