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

pcap-linux: Obtain VLAN TPID from the kernel when available #346

Merged
merged 2 commits into from Feb 15, 2015

Conversation

atzm
Copy link
Contributor

@atzm atzm commented Mar 31, 2014

The VLAN TPID was hardcoded in pcap-linux.c but recent Linux kernel
supports 802.1ad Q-in-Q.
Since Linux 3.14, kernel gives the TPID value to the userspace when
available.

The VLAN TPID was hardcoded in pcap-linux.c but recent Linux kernel
supports 802.1ad Q-in-Q.
Since Linux 3.14, kernel gives the TPID value to the userspace when
available.
Unify the VLAN TPID selection logic into a helper macro VLAN_TPID().
@hkwi
Copy link

hkwi commented Jul 8, 2014

Looks good to me.

@@ -366,6 +366,12 @@ static void pcap_oneshot_mmap(u_char *user, const struct pcap_pkthdr *h,
const u_char *bytes);
#endif

#ifdef TP_STATUS_VLAN_TPID_VALID
# define VLAN_TPID(hdr, hv) (((hv)->tp_vlan_tpid || ((hdr)->tp_status & TP_STATUS_VLAN_TPID_VALID)) ? (hv)->tp_vlan_tpid : ETH_P_8021Q)
Copy link

Choose a reason for hiding this comment

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

Should this be as following?

# define VLAN_TPID(hdr, hv) ((((hv)->tp_vlan_tpid != 0) && ((hdr)->tp_status & TP_STATUS_VLAN_TPID_VALID)) ? (hv)->tp_vlan_tpid : ETH_P_8021Q)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the tp_vlan_tpid is always defined as the unsigned (__u16) in TPACKET structures, that change is not needed, IMHO. And if the definition is changed to the signed in the future, I think this is a kernel's bug...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for the noise, I was misreading your points.
The logic for the selecting TPID is same as the TCI, but should it be different logic only in case of the TPID? It seems pcap-linux uses the value when the kernel gives any value if TP_STATUS_*_VALID is defined.

Copy link

Choose a reason for hiding this comment

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

The reason I posted question was that second TP_STATUS_VLAN_TPID_VALID does nothing meaningful when conbined with series of past linux kernels. If a packet has tpid, then first condition will be met, because tpid won't be 0.

Anyway, vlan tag existence will be checked by vlan_tci, and not vlan_tpid. If TP_STATUS_VLAN_TPID_VALID is defined, then we need just check that bit without checking tp_vlan_tpid is 0 or not, IMHO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's right. But then I think the macro just should be as following:

# define VLAN_TPID(hdr, hv) ((hdr)->tp_status & TP_STATUS_VLAN_TPID_VALID ? (hv)->tp_vlan_tpid : ETH_P_8021Q)

Of course the tp_vlan_tpid will be used in this case even if the TPID is 0, but it ought to be right in the userspace, because the kernel set the TP_STATUS_VLAN_TPID_VALID.

mcr added a commit that referenced this pull request Feb 15, 2015
pcap-linux: Obtain VLAN TPID from the kernel when available
@mcr mcr merged commit 697458e into the-tcpdump-group:master Feb 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

5 participants