runsisi's

technical notes

聚合口 LLDP 抓包

2019-12-03 runsisi#tcp/ip

Link Layer Discovery Protocol (LLDP) 是一个标准的链路层协议,它允许网络设备通过每一个连接的网口在本地子网中以固定的周期通告本端设备的标识、能力等,这些信息被组织成一系列的 TLV 结构,封装在 LLDPDU(Link Layer Discovery Protocol Data Unit)中进行传输。

需要注意的是,对于标准的 Linux 服务器,基于性能和可用性的考虑,通常会对网口进行聚合,此时 LLDP 报文中携带的网口 MAC 必须是物理网口 MAC,而不应该是聚合口 MAC。

聚合口信息

$ cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eno1
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eno1
MII Status: up
Speed: 10000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 28:7b:09:c9:c3:b4
Slave queue ID: 0

Slave Interface: ens2f0
MII Status: up
Speed: 10000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 28:7b:09:c6:18:44
Slave queue ID: 0

其中,Permanent HW addr 即为各成员口的物理 MAC 地址,对于 mode 4 802.3ad LACP 模式(802.3ad),System MAC address 为聚合口的 MAC 地址,对于主备模式,需要通过 ip 命令显式查看:

$ ip a show dev bond0
108: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000
    link/ether 28:7b:09:c9:c3:b4 brd ff:ff:ff:ff:ff:ff
    inet 100.100.9.33/16 brd 100.100.255.255 scope global bond0
       valid_lft forever preferred_lft forever
    inet6 fe80::2a7b:9ff:fec9:c3b4/64 scope link 
       valid_lft forever preferred_lft forever

显然,上面聚合口 bond0 为 mode 1 主备模式(active-backup),由成员口 eno1 和 ens2f0 组成,当前的主为 eno1,可以通过如下命令进行主备切换:

$ sudo ifenslave -c bond0 ens2f0

LLDP 抓包

LLDP 报文的以太网帧 EtherType 字段为 0x88cc,因此可以指定具体的成员口以及协议字段进行抓包:

$ sudo tcpdump -i eno1 -w eno1.pcap -v 'ether proto 0x88cc'
tcpdump: listening on eno1, link-type EN10MB (Ethernet), capture size 262144 bytes
Got 4

LLDP 报文

$ sudo dmidecode -s system-serial-number
210096152352

lldp

参考资料

Link Layer Discovery Protocol

https://en.wikipedia.org/wiki/Link_Layer_Discovery_Protocol

implementation of IEEE 802.1ab (LLDP)

http://vincentbernat.github.io/lldpd/

An open source real-time network topology and protocols analyzer

https://github.com/skydive-project/skydive

lldpad not working for some ports, when LLDP frames are sent in a vlan

https://bugzilla.redhat.com/show_bug.cgi?id=1487930