Skip to content

examples: add linkflap (link-flap detection in the kernel) - #621

Open
lneto wants to merge 1 commit into
masterfrom
claude_linkflap
Open

examples: add linkflap (link-flap detection in the kernel)#621
lneto wants to merge 1 commit into
masterfrom
claude_linkflap

Conversation

@lneto

@lneto lneto commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

A notifier.netdevice callback keeps a per-interface sliding window of UP/DOWN transitions and, once an interface crosses the threshold within the window, multicasts a structured flapping event (interface name and transition count) over the linkflap generic netlink family. subscriber.c consumes the events in userspace, decoding the attributes and printing e.g. linkflap: dummy0 flapping (5 transitions).

It hooks the kernel's netdevice notifier chain, and the value is the stateful per-interface window in the handler (plain event forwarding cannot do that). The callback runs holding rtnl_lock, so it must not issue rtnetlink itself, but emitting a multicast is safe (it does not take the lock), so this is a single runtime.

Also the first netlink.channel example in the tree (it had only test coverage).

Validated end to end in the kernel: running watch.lua and bouncing a dummy interface past the threshold, subscriber.c (joined to the family's multicast group) receives and decodes the event. No printk involved; the point is the netlink path.

Rebased onto master now that #620 (multicast rename) is merged.

@lneto
lneto changed the base branch from claude_channel_multicast to master July 4, 2026 13:31
@lneto
lneto force-pushed the claude_linkflap branch 2 times, most recently from 0779e64 to 70b1c87 Compare July 4, 2026 18:17
@lneto
lneto force-pushed the claude_linkflap branch from 70b1c87 to d47e112 Compare July 26, 2026 12:28
A notifier.netdevice callback keeps a per-interface sliding window of UP/DOWN
transitions and, once an interface crosses the threshold within the window,
multicasts a structured flapping event (interface name and transition count)
over the "linkflap" generic netlink family. subscriber.c consumes the events in
userspace, decoding the attributes. It hooks the kernel's netdevice notifier
chain and runs stateful logic in the handler; emitting the multicast is safe
from the callback (it does not take rtnl_lock, unlike an rtnetlink write).

Also the first netlink.channel example (it had only test coverage).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@lneto
lneto force-pushed the claude_linkflap branch from d47e112 to dd081c4 Compare August 3, 2026 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant