Vitezslav Samel (2): centralize layer 3 packet handling add 802.1ad and QinQ VLAN handling
src/packet.c | 31 ++++++++++++++++++------------- 1 files changed, 18 insertions(+), 13 deletions(-)
Signed-off-by: Vitezslav Samel vitezslav@samel.cz --- src/packet.c | 27 ++++++++++++++------------- 1 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/src/packet.c b/src/packet.c index d0b04e4..33dc5e3 100644 --- a/src/packet.c +++ b/src/packet.c @@ -67,13 +67,6 @@ static int packet_adjust(struct pkt_hdr *pkt) pkt->pkt_payload = pkt->pkt_buf; pkt->pkt_payload += ETH_HLEN; pkt->pkt_len -= ETH_HLEN; - if (pkt->pkt_protocol == ETH_P_8021Q) { - /* strip 0x8100 802.1Q VLAN Extended Header */ - pkt->pkt_payload += 4; - pkt->pkt_len -= 4; - /* update network protocol */ - pkt->pkt_protocol = ntohs(*((unsigned short *) pkt->pkt_payload)); - } break; case ARPHRD_SLIP: case ARPHRD_CSLIP: @@ -192,9 +185,9 @@ int packet_process(struct pkt_hdr *pkt, unsigned int *total_br, if (packet_adjust(pkt) != 0) return INVALID_PACKET;
-again: - packet_set_l3_hdrp(pkt); - if (pkt->pkt_protocol == ETH_P_IP) { +again: packet_set_l3_hdrp(pkt); + switch (pkt->pkt_protocol) { + case ETH_P_IP: { struct iphdr *ip = pkt->iphdr; int hdr_check; register int ip_checksum; @@ -287,8 +280,8 @@ again: pkt->pkt_len -= pkt_iph_len(pkt); goto again; } - return PACKET_OK; - } else if (pkt->pkt_protocol == ETH_P_IPV6) { + break; } + case ETH_P_IPV6: { struct tcphdr *tcp; struct udphdr *udp; struct ip6_hdr *ip6 = pkt->ip6_hdr; @@ -317,7 +310,15 @@ again: *dport = 0; break; } - } else { + break; } + case ETH_P_8021Q: + /* strip 0x8100 802.1Q VLAN Extended Header */ + pkt->pkt_payload += 4; + pkt->pkt_len -= 4; + /* update network protocol */ + pkt->pkt_protocol = ntohs(*((unsigned short *) pkt->pkt_payload)); + goto again; + default: /* not IPv4 and not IPv6: apply non-IP packet filter */ if (!nonipfilter(filter, pkt->pkt_protocol)) { return PACKET_FILTERED;
Signed-off-by: Vitezslav Samel vitezslav@samel.cz --- src/packet.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/src/packet.c b/src/packet.c index 33dc5e3..470da87 100644 --- a/src/packet.c +++ b/src/packet.c @@ -312,7 +312,11 @@ again: packet_set_l3_hdrp(pkt); } break; } case ETH_P_8021Q: - /* strip 0x8100 802.1Q VLAN Extended Header */ + case ETH_P_QINQ1: /* ETH_P_QINQx are not officially */ + case ETH_P_QINQ2: /* registered IDs */ + case ETH_P_QINQ3: + case ETH_P_8021AD: + /* strip 802.1Q/QinQ/802.1ad VLAN header */ pkt->pkt_payload += 4; pkt->pkt_len -= 4; /* update network protocol */
iptraf-ng@lists.fedorahosted.org