examples: add linkflap (link-flap detection in the kernel) - #621
Open
lneto wants to merge 1 commit into
Open
Conversation
lneto
force-pushed
the
claude_linkflap
branch
2 times, most recently
from
July 4, 2026 18:17
0779e64 to
70b1c87
Compare
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A
notifier.netdevicecallback 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 thelinkflapgeneric netlink family.subscriber.cconsumes 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.channelexample in the tree (it had only test coverage).Validated end to end in the kernel: running
watch.luaand bouncing a dummy interface past the threshold,subscriber.c(joined to the family's multicast group) receives and decodes the event. Noprintkinvolved; the point is the netlink path.Rebased onto master now that #620 (multicast rename) is merged.