Skip to content
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

A new filter "ifindex" for LINUX_SLL2 and live Linux captures #829

Merged
merged 1 commit into from
May 19, 2020

Conversation

fenner
Copy link
Collaborator

@fenner fenner commented Jul 11, 2019

Create a filter for the ifIndex field in the LINUX_SLL2 pcap format, and convert it to the right SKF_AD_ value for live captures.

@fxlb
Copy link
Member

fxlb commented May 10, 2020

As a user, I’d rather be able to filter by interface name like in some BSD's but in and out.

Something like ifname eth0.

Way to have 'eth0' -> 'ifindex N' to build a filter?

See https://www.tcpdump.org/manpages/pcap-filter.7.html:

"ifname interface
True if the packet was logged as coming from the specified interface (applies only to packets logged by OpenBSD's or FreeBSD's pf(4))."

@fenner
Copy link
Collaborator Author

fenner commented May 10, 2020

As a user, I’d rather be able to filter by interface name like in some BSD's but in and out.

You can't do this on a savefile since the interface name is not stored in the savefile. ifindex works in both live captures and savefile mode, even if it's less friendly.

Reworking the grammar so that "ifname" is not PF-specific is on my to-do list, but that'd be a different pull request.

@mcr
Copy link
Member

mcr commented May 10, 2020

As a user, I’d rather be able to filter by interface name like in some BSD's but in and out.

You can't do this on a savefile since the interface name is not stored in the savefile. ifindex works in both live captures and savefile mode, even if it's less friendly.

Reworking the grammar so that "ifname" is not PF-specific is on my to-do list, but that'd be a different pull request.

And even if you were on the same machine, the ifindex can change after interfaces come/go, or after a reboot. This is a case where pcapng would be better.

@fxlb fxlb requested a review from guyharris May 12, 2020 08:15
@fxlb
Copy link
Member

fxlb commented May 12, 2020

I suggest to rebase this PR on top of master.

@fenner
Copy link
Collaborator Author

fenner commented May 12, 2020

Looks like 8c263fd introduced problems with the FreeBSD build.

@guyharris
Copy link
Member

Looks like 8c263fd introduced problems with the FreeBSD build.

Should be fixed by 00f29be.

gencode.c Show resolved Hide resolved
gencode.c Outdated
b0 = gen_cmp(cstate, OR_LINKHDR, 4, BPF_W, ifindex);
break;
default:
#if defined(linux) && defined(PF_PACKET) && defined(SO_ATTACH_FILTER)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point, if we're building for Linux and neither PF_PACKET nor SO_ATTACH_FILTER are defined, libpcap won't build - we require a newer kernel - so it's sufficient to test whether linux is defined.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I first posted this way before bfbe856 . Thanks for pointing this out.

@guyharris guyharris merged commit 150516b into the-tcpdump-group:master May 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants