-
Notifications
You must be signed in to change notification settings - Fork 188
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
Add --filter-ifname #257
Add --filter-ifname #257
Conversation
@jschwinger233 Maybe let's resolve ifname to ifindex from the user space, and then use ifindex in the kprobe? |
@brb That was my idea, but I ended up giving it up because I didn't know how to switch netns using ID. I know how to switch netns: https://www.weave.works/blog/linux-namespaces-golang-followup, I don't know how to get NsHandle from ID. I looked up vishvananda/netns, there are 5 functions to get a NsHandle: |
A netns ID is just an inode number. Have you tried passing it to https://github.com/vishvananda/netns/blob/master/netns_linux.go#L29, i.e. |
I think NsHandle is a wrapper of fd: The value should be a small integer like 5, 6, 7, instead of something like 4026531834 |
Hmm, you are right. And on Linux getting FD by inode is not possible :-/ Maybe we should change the semantics of |
I agree that netnsPath improves UX, but (For me, I can use Speaking of output fields, one more thing is ifindex field in output of |
My main worry with the current ifname approach is that in the critical path we have a slow operation (string vs int cmp). WDYT about having |
It's been on my list since forever 😅 When the prog starts, we could fetch ifindices from all netns, and then build a cache (prone to races, but it's fine) - |
That will do. Another option is like
So how about letting
|
SGTM! Just maybe let's make |
ee1667c
to
a10a79d
Compare
a10a79d
to
b2a25f8
Compare
internal/pwru/types.go
Outdated
@@ -53,15 +54,16 @@ func (f *Flags) SetFlags() { | |||
flag.StringSliceVar(&f.KMods, "kmods", nil, "list of kernel modules names to attach to") | |||
flag.BoolVar(&f.AllKMods, "all-kmods", false, "attach to all available kernel modules") | |||
flag.StringVar(&f.FilterFunc, "filter-func", "", "filter kernel functions to be probed by name (exact match, supports RE2 regular expression)") | |||
flag.Uint32Var(&f.FilterNetns, "filter-netns", 0, "filter netns inode") | |||
flag.StringVar(&f.FilterNetns, "filter-netns", "", "filter netns (\"proc/<pid>/ns/net\", \"inode:<inode>\")") |
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.
Nit: s/proc//proc/
@jschwinger233 Very nice! One nit, and then we can |
b2a25f8
to
5692086
Compare
@jschwinger233 Could you rebase to resolve the conflict? |
Set this flag to filter skbs whose dev->ifindex equals to user specified one, under the netns set by --filter-netns. If --filter-netns is not set, pwru automatically detects current netns. Pwru has to switch netns in order to parse ifindex from ifname. To achieve that, --filer-netns accepts multi-forms arguments: 1. By path: --filter-netns /proc/<pid>/ns/net 2. By inode: --filter-netns inode:4026533332 --filter-ifname can only work with --filter-netns by path, otherwise pwru cannot switch to target netns by inode. Signed-off-by: Zhichuan Liang <[email protected]>
Signed-off-by: Zhichuan Liang <[email protected]>
Signed-off-by: Zhichuan Liang <[email protected]>
Signed-off-by: Zhichuan Liang <[email protected]>
5692086
to
8666747
Compare
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.
🚀
Set this flag to filter skb from/to the specific interface under the specific netns. If flag --filter-netns is not set, pwru uses current netns.
Signed-off-by: Zhichuan Liang [email protected]