Reorganize and fix VLAN header stripping and accounting. Also fix
network layer protocol after VLAN header stripping.
Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
---
src/packet.c | 19 +++++++------------
src/packet.h | 7 -------
2 files changed, 7 insertions(+), 19 deletions(-)
diff --git a/src/packet.c b/src/packet.c
index 0a1f0ff..1299fbb 100644
--- a/src/packet.c
+++ b/src/packet.c
@@ -53,15 +53,15 @@ static void adjustpacket(char *tpacket, struct sockaddr_ll *fromaddr,
switch (fromaddr->sll_hatype) {
case ARPHRD_ETHER:
case ARPHRD_LOOPBACK:
- if (fromaddr->sll_protocol == ETH_P_8021Q) {
- /* 0x8100 802.1Q VLAN Extended Header */
- *packet = tpacket + VLAN_ETH_HLEN;
- *readlen -= VLAN_ETH_HLEN;
- break;
- }
-
*packet = tpacket + ETH_HLEN;
*readlen -= ETH_HLEN;
+ if (fromaddr->sll_protocol == ETH_P_8021Q) {
+ /* strip 0x8100 802.1Q VLAN Extended Header */
+ *packet += 4;
+ *readlen -= 4;
+ /* update network protocol */
+ fromaddr->sll_protocol = *((unsigned short *) *packet);
+ }
break;
case ARPHRD_SLIP:
case ARPHRD_CSLIP:
@@ -179,11 +179,6 @@ int processpacket(char *tpacket, char **packet, unsigned int *br,
* data link header.
*/
fromaddr->sll_protocol = ntohs(fromaddr->sll_protocol);
- if (fromaddr->sll_protocol == ETH_P_8021Q)
- fromaddr->sll_protocol =
- ntohs(*((unsigned short *) (tpacket + ETH_HLEN + 2)));
-
-
adjustpacket(tpacket, fromaddr, packet, br);
if (*packet == NULL)
diff --git a/src/packet.h b/src/packet.h
index 5a5629d..b3bea27 100644
--- a/src/packet.h
+++ b/src/packet.h
@@ -23,18 +23,11 @@ Written by Gerard Paul Java
#define PACKET_FILTERED 3
#define MORE_FRAGMENTS 4
-
-#ifndef VLAN_ETH_HLEN
-#define VLAN_ETH_HLEN 18
-#endif
-
extern int isdnfd;
void open_socket(int *fd);
-
void getpacket(int fd, char *buf, struct sockaddr_ll *fromaddr, int *ch,
int *br, char *ifname, WINDOW * win);
-
int processpacket(char *tpacket, char **packet, unsigned int *br,
unsigned int *total_br, unsigned int *sport,
unsigned int *dport, struct sockaddr_ll *fromaddr,
--
1.7.8.4