-
Notifications
You must be signed in to change notification settings - Fork 45
Add LLDP AF_PACKET example #341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
sorry, it's not clear to me what you want to implement here. The referred issue is for implementing a proper LLDP parser, not only to match it's ether type. If you want to extend this implementing a patch, I will be glad to merge; but please, keep this PR as draft while it's not intended to be merged. |
989e2bc to
60b940c
Compare
|
Thanks for the clarification. I’ve now updated the example to include a minimal LLDP TLV parser (Chassis ID, Port ID, TTL, System Name, plus generic TLV handling). I’ll keep the PR as draft for now, please let me know if this level of parsing aligns with what you had in mind, or if you’d prefer additional TLVs or structure before merging. (Tested this script via a veth pair: |
examples/lldp.lua
Outdated
| if tlv_type == 1 then | ||
| table.insert(out, "chassis id") | ||
| elseif tlv_type == 2 then | ||
| table.insert(out, "port id") | ||
| elseif tlv_type == 3 then | ||
| local ttl = string.unpack(">I2", value) | ||
| table.insert(out, "ttl: " .. ttl) | ||
| elseif tlv_type == 5 then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of having this long if-then-else block, you can have a table indexed by tlv_type
indeed it's more aligned now, you're on the right path.. but, we try to have self-contained examples.. in the sense they should be "useful" apps with a specific purpose.. I think to make this example useful, we should have a actual LLDP client or server.. or having a netfilter filter, for instance.. to block or scrap some info.. |
|
I understand what you mean by making a lldp server client pair but could you clarify what a netfilter filter would do? Do we want to block certain tlv? The client receives lldp frames, inspects them, and then decides whether to allow or drop them. Please tell me in what direction I should drive this PR. |
I see three different paths to make it a useful app:
It's actually up to you to decide what to implement =). I found a LLDP server more useful perhaps. However, my only requirement is to make it a "full" example. A useful app ;-). You are equally free to choose another path. I just don't find the current approach of having another sniffer that useful. You could also extend the sniffer example we already have with a LLDP parser, enriching it. It's up to you =). |
60b940c to
759f44c
Compare
|
Hi @lneto I did a little bit of tinkering with netfilter hooks to filter LLDP frames and put them on a shared RCU table. Right now the reader prints nothing, where can I find good documentation on netfilter? I think the parameters passed in netfilter hook need to be tweaked Regarding the server, just to confirm, did you mean a thread emitting LLDP frames on a specified interface (will need to get source MAC of the interface somehow to do this)? |
759f44c to
95bc004
Compare
examples/lldp/monitor.lua
Outdated
| local lunatik = require("lunatik") | ||
| local rcu = require("rcu") | ||
| local linux = require("linux") | ||
| local string = require("string") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unneeded
examples/lldp/monitor.lua
Outdated
| end | ||
|
|
||
| local function lldp_hook(skb) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please, mind our code style.
examples/lldp/monitor.lua
Outdated
| pf = family.BRIDGE, | ||
| hooknum = hooks.PRE_ROUTING, | ||
| priority = pri.FILTER, | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| } | |
| } | |
examples/lldp/reader.lua
Outdated
| return table.concat(out, "\n") .. "\n" | ||
| end | ||
|
|
||
| device.new(lldp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| device.new(lldp) | |
| device.new(lldp) | |
did you try to put some prints on your hook? are you generating LLDP traffic? are you are running the daemon locally? if so, you probably need to use LOCAL_IN. did you take a look at this https://luainkernel.github.io/lunatik/modules/netfilter.html? or are you referring to general netfilter doc? if so, I think it's a good place to get started https://thermalcircle.de/doku.php?id=blog:linux:nftables_packet_flow_netfilter_hooks_detail.
Yes, I meant to implement an lldpd on Lunatik ;-). You can get the MAC address from the frames, right? What's missing? |
|
For the netfilter filter, which family should we use for capturing LLDP frames? I think NETDEV should be used but my kernel seem to not support it (arch linux kernel v6.12.63-1-lts) by default (cant see
Nothing, I'll add the server implementation soon after I figure out the netfilter part |
I don't see why you can't run on BRIDGE.
I think we are mixing up things here; my suggestion to implement a server here was by using raw sockets as you were doing before. I suggested 3 different paths, not a mix of them ;-). |
A minimal LLDP example implemented as a Lunatik Lua script. The example uses a thread to emit LLDP (EtherType 0x88cc) frames and send them on a specified network interface. Signed-off-by: Ashwani Kumar Kamal <ashwanikamal.im421@gmail.com>
95bc004 to
debcd26
Compare
You are right. A server makes the most sense here. I have added a simple daemon which emits LLDP frames every 30 seconds. |
This PR add a minimal LLDP example implemented as a Lunatik Lua script. The example uses an AF_PACKET socket to receive and filter LLDP (EtherType 0x88cc) frames and demonstrates raw Ethernet access.
Addresses #126