summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Habets <habets@google.com>2022-03-01 16:25:38 +0000
committerThomas Habets <habets@google.com>2022-03-01 16:25:38 +0000
commit5f6f15cadfd41d43ed22dbfbaa8e6a1a509ee58e (patch)
tree8e7db16bd45dfa443bed386d44b486f1b20d0226
parent7f33254032afaa2c29aaf7a0a33b3b53ee974682 (diff)
downloadarping-5f6f15cadfd41d43ed22dbfbaa8e6a1a509ee58e.tar.gz
Check received VLAN tag when using -V
-rw-r--r--src/arping.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/arping.c b/src/arping.c
index c00c52c..76ddc2d 100644
--- a/src/arping.c
+++ b/src/arping.c
@@ -1323,7 +1323,7 @@ void
pingip_recv(const char *unused, struct pcap_pkthdr *h, const char * const packet)
{
const unsigned char *pkt_srcmac;
- const struct libnet_802_1q_hdr *veth;
+ const struct libnet_802_1q_hdr *veth = NULL;
struct libnet_802_3_hdr *heth;
struct libnet_arp_hdr *harp;
struct timespec arrival;
@@ -1354,6 +1354,15 @@ pingip_recv(const char *unused, struct pcap_pkthdr *h, const char * const packet
printf("arping: ... good length\n");
}
+ if (veth) {
+ if ((veth->vlan_priority_c_vid & 0xfff) == vlan_tag) {
+ return;
+ }
+ if (verbose > 3) {
+ printf("arping: ... right VLAN\n");
+ }
+ }
+
// Wrong length of hardware address.
if (harp->ar_hln != ETH_ALEN) {
return;
@@ -1511,7 +1520,7 @@ pingmac_recv(const char* unused, struct pcap_pkthdr *h, uint8_t *packet)
{
const unsigned char *pkt_dstmac;
const unsigned char *pkt_srcmac;
- const struct libnet_802_1q_hdr *veth;
+ const struct libnet_802_1q_hdr *veth = NULL;
struct libnet_802_3_hdr *heth;
struct libnet_ipv4_hdr *hip;
struct libnet_icmpv4_hdr *hicmp;
@@ -1547,6 +1556,15 @@ pingmac_recv(const char* unused, struct pcap_pkthdr *h, uint8_t *packet)
printf("arping: ... good length\n");
}
+ if (veth) {
+ if ((veth->vlan_priority_c_vid & 0xfff) == vlan_tag) {
+ return;
+ }
+ if (verbose > 3) {
+ printf("arping: ... right VLAN\n");
+ }
+ }
+
// Dest MAC must be me.
if (memcmp(pkt_dstmac, srcmac, ETH_ALEN)) {
return;