Skip to content

Commit b8de339

Browse files
committed
GRE: integrate into parser
1 parent c20d25a commit b8de339

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

input/parser.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,21 @@ inline uint16_t parse_ipv4_hdr(const u_char *data_ptr, uint16_t data_len, Packet
305305
throw "Parser detected malformed packet";
306306
}
307307

308+
const int ihl = ip->ihl << 2;
309+
310+
if (ip->protocol == IPPROTO_GRE) {
311+
DEBUG_MSG("Parse GRE in ipv4 header\n");
312+
if (data_len < ihl) {
313+
throw "Parser detected malformed packet";
314+
}
315+
return parse_gre(data_ptr + ihl, data_len - ihl, pkt) + ihl;
316+
}
317+
308318
pkt->ip_version = IP::v4;
309319
pkt->ip_proto = ip->protocol;
310320
pkt->ip_tos = ip->tos;
311321
pkt->ip_len = ntohs(ip->tot_len);
312-
pkt->ip_payload_len = pkt->ip_len - (ip->ihl << 2);
322+
pkt->ip_payload_len = pkt->ip_len - ihl;
313323
pkt->ip_ttl = ip->ttl;
314324
pkt->ip_flags = (ntohs(ip->frag_off) & 0xE000) >> 13;
315325
pkt->src_ip.v4 = ip->saddr;
@@ -329,7 +339,7 @@ inline uint16_t parse_ipv4_hdr(const u_char *data_ptr, uint16_t data_len, Packet
329339
DEBUG_MSG("\tSrc addr:\t%s\n", inet_ntoa(*(struct in_addr *) (&ip->saddr)));
330340
DEBUG_MSG("\tDest addr:\t%s\n", inet_ntoa(*(struct in_addr *) (&ip->daddr)));
331341

332-
return (ip->ihl << 2);
342+
return ihl;
333343
}
334344

335345
/**

0 commit comments

Comments
 (0)