How do you get VLAN information like addition and deletion of VLAN sub interface from kernel to userspace using NETLINK socket in C?
I did little study in NETLINK man as suggested in comments. I added and deleted a VLAN sub interface and monitored using netlink socket program. For addition & deletion each receiving 3 messages. Addition sends 3 NEWLINK message and deletion sends 2 NEWLINK & 1 DELLINK message. Why is that so?
For addition of new VLAN interface eth1.75:
RTM_NEWLINK Link eth2.75 Down
RTM_NEWLINK Link eth2 Up
RTM_NEWLINK Link eth2.75 Up
For Deletion of VLAN interface eth2.75:
RTM_NEWLINK Link eth2 Up
RTM_NEWLINK Link eth2.75 Down
RTM_DELLINK eth2.75
While creating a netlink socket, it create 3 devices. This is why you receive 3 events. Here is the 3 devices it creates while add
event.
net
subsystem is the upper level control device. Other two are queues
for handing data. You can verify it as below.
When I do a udevadm monitor --env
and create a vlan I get the following events from kernel:
UDEV [305215.045416] add /devices/virtual/net/vpn0 (net)
ACTION=add
DEVPATH=/devices/virtual/net/vpn0
ID_MM_CANDIDATE=1
IFINDEX=10
INTERFACE=vpn0
SEQNUM=3665
SUBSYSTEM=net
USEC_INITIALIZED=5215023319
UDEV [305215.046658] add /devices/virtual/net/vpn0/queues/rx-0 (queues)
ACTION=add
DEVPATH=/devices/virtual/net/vpn0/queues/rx-0
SEQNUM=3666
SUBSYSTEM=queues
USEC_INITIALIZED=15044665
UDEV [305215.047628] add /devices/virtual/net/vpn0/queues/tx-0 (queues)
ACTION=add
DEVPATH=/devices/virtual/net/vpn0/queues/tx-0
SEQNUM=3667
SUBSYSTEM=queues
USEC_INITIALIZED=5215044729
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With