|
|
|
|
@ -7,25 +7,25 @@
|
|
|
|
|
#include "decode-events.h"
|
|
|
|
|
|
|
|
|
|
/* XXX */
|
|
|
|
|
static int DecodeIPV4Options(ThreadVars *t, Packet *p, uint8_t *pkt, uint16_t len)
|
|
|
|
|
static int DecodeIPV4Options(ThreadVars *tv, Packet *p, uint8_t *pkt, uint16_t len)
|
|
|
|
|
{
|
|
|
|
|
printf("*pkt %" PRIu32 "\n", *pkt);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int DecodeIPV4Packet(ThreadVars *t, Packet *p, uint8_t *pkt, uint16_t len)
|
|
|
|
|
static int DecodeIPV4Packet(ThreadVars *tv, Packet *p, uint8_t *pkt, uint16_t len)
|
|
|
|
|
{
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
printf("DecodeIPV4Packet\n");
|
|
|
|
|
#endif
|
|
|
|
|
p->ip4h = (IPV4Hdr *)pkt;
|
|
|
|
|
|
|
|
|
|
if (len < IPV4_HEADER_LEN) {
|
|
|
|
|
DECODER_SET_EVENT(p,IPV4_PKT_TOO_SMALL);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p->ip4h = (IPV4Hdr *)pkt;
|
|
|
|
|
|
|
|
|
|
if (IPV4_GET_HLEN(p) < IPV4_HEADER_LEN) {
|
|
|
|
|
DECODER_SET_EVENT(p,IPV4_HLEN_TOO_SMALL);
|
|
|
|
|
return -1;
|
|
|
|
|
@ -44,23 +44,20 @@ static int DecodeIPV4Packet(ThreadVars *t, Packet *p, uint8_t *pkt, uint16_t len
|
|
|
|
|
/* save the options len */
|
|
|
|
|
p->ip4vars.ip_opts_len = IPV4_GET_HLEN(p) - IPV4_HEADER_LEN;
|
|
|
|
|
if (p->ip4vars.ip_opts_len > 0) {
|
|
|
|
|
DecodeIPV4Options(t, p, pkt + IPV4_GET_HLEN(p), p->ip4vars.ip_opts_len);
|
|
|
|
|
DecodeIPV4Options(tv, p, pkt + IPV4_GET_HLEN(p), p->ip4vars.ip_opts_len);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* set the address struct */
|
|
|
|
|
SET_IPV4_SRC_ADDR(p,&p->src);
|
|
|
|
|
SET_IPV4_DST_ADDR(p,&p->dst);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DecodeIPV4(ThreadVars *t, Packet *p, u_int8_t *pkt, u_int16_t len,
|
|
|
|
|
PacketQueue *pq, void *data)
|
|
|
|
|
void DecodeIPV4(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, uint16_t len, PacketQueue *pq)
|
|
|
|
|
{
|
|
|
|
|
DecodeThreadVars *dtv = (DecodeThreadVars *)data;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
PerfCounterIncr(dtv->counter_ipv4, t->pca);
|
|
|
|
|
PerfCounterIncr(dtv->counter_ipv4, tv->pca);
|
|
|
|
|
|
|
|
|
|
/* reset the decoder cache flags */
|
|
|
|
|
IPV4_CACHE_INIT(p);
|
|
|
|
|
@ -70,11 +67,12 @@ void DecodeIPV4(ThreadVars *t, Packet *p, u_int8_t *pkt, u_int16_t len,
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* do the actual decoding */
|
|
|
|
|
ret = DecodeIPV4Packet (t, p, pkt, len);
|
|
|
|
|
ret = DecodeIPV4Packet (tv, p, pkt, len);
|
|
|
|
|
if (ret < 0) {
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
printf("DecodeIPV4 failed!\n");
|
|
|
|
|
#endif
|
|
|
|
|
p->ip4h = NULL;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -95,23 +93,23 @@ void DecodeIPV4(ThreadVars *t, Packet *p, u_int8_t *pkt, u_int16_t len,
|
|
|
|
|
case IPPROTO_IP:
|
|
|
|
|
/* check PPP VJ uncompressed packets and decode tcp dummy */
|
|
|
|
|
if(p->ppph != NULL && ntohs(p->ppph->protocol) == PPP_VJ_UCOMP) {
|
|
|
|
|
return(DecodeTCP(t, p, pkt + IPV4_GET_HLEN(p),
|
|
|
|
|
IPV4_GET_IPLEN(p) - IPV4_GET_HLEN(p), data));
|
|
|
|
|
return(DecodeTCP(tv, dtv, p, pkt + IPV4_GET_HLEN(p),
|
|
|
|
|
IPV4_GET_IPLEN(p) - IPV4_GET_HLEN(p), pq));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case IPPROTO_TCP:
|
|
|
|
|
return(DecodeTCP(t, p, pkt + IPV4_GET_HLEN(p),
|
|
|
|
|
IPV4_GET_IPLEN(p) - IPV4_GET_HLEN(p), data));
|
|
|
|
|
return(DecodeTCP(tv, dtv, p, pkt + IPV4_GET_HLEN(p),
|
|
|
|
|
IPV4_GET_IPLEN(p) - IPV4_GET_HLEN(p), pq));
|
|
|
|
|
break;
|
|
|
|
|
case IPPROTO_UDP:
|
|
|
|
|
//printf("DecodeIPV4: next layer is UDP\n");
|
|
|
|
|
return(DecodeUDP(t, p, pkt + IPV4_GET_HLEN(p),
|
|
|
|
|
IPV4_GET_IPLEN(p) - IPV4_GET_HLEN(p), data));
|
|
|
|
|
return(DecodeUDP(tv, dtv, p, pkt + IPV4_GET_HLEN(p),
|
|
|
|
|
IPV4_GET_IPLEN(p) - IPV4_GET_HLEN(p), pq));
|
|
|
|
|
break;
|
|
|
|
|
case IPPROTO_ICMP:
|
|
|
|
|
//printf("DecodeIPV4: next layer is ICMP\n");
|
|
|
|
|
return(DecodeICMPV4(t, p, pkt + IPV4_GET_HLEN(p),
|
|
|
|
|
IPV4_GET_IPLEN(p) - IPV4_GET_HLEN(p), data));
|
|
|
|
|
return(DecodeICMPV4(tv, dtv, p, pkt + IPV4_GET_HLEN(p),
|
|
|
|
|
IPV4_GET_IPLEN(p) - IPV4_GET_HLEN(p), pq));
|
|
|
|
|
break;
|
|
|
|
|
case IPPROTO_IPV6:
|
|
|
|
|
{
|
|
|
|
|
@ -120,11 +118,11 @@ void DecodeIPV4(ThreadVars *t, Packet *p, u_int8_t *pkt, u_int16_t len,
|
|
|
|
|
//printf("DecodeIPV4: we are p %p\n", p);
|
|
|
|
|
|
|
|
|
|
/* spawn off tunnel packet */
|
|
|
|
|
Packet *tp = TunnelPktSetup(t, p, pkt + IPV4_GET_HLEN(p), IPV4_GET_IPLEN(p) - IPV4_GET_HLEN(p), IPV4_GET_IPPROTO(p));
|
|
|
|
|
Packet *tp = TunnelPktSetup(tv, dtv, p, pkt + IPV4_GET_HLEN(p), IPV4_GET_IPLEN(p) - IPV4_GET_HLEN(p), IPV4_GET_IPPROTO(p));
|
|
|
|
|
//printf("DecodeIPV4: tunnel is tp %p\n", tp);
|
|
|
|
|
|
|
|
|
|
/* send that to the Tunnel decoder */
|
|
|
|
|
DecodeTunnel(t, tp, tp->pkt, tp->pktlen, pq, data);
|
|
|
|
|
DecodeTunnel(tv, dtv, tp, tp->pkt, tp->pktlen, pq);
|
|
|
|
|
/* add the tp to the packet queue. */
|
|
|
|
|
PacketEnqueue(pq,tp);
|
|
|
|
|
|
|
|
|
|
|