mirror of https://github.com/OISF/suricata
initial PPPoE decoder commit
parent
3cf7e2e94e
commit
8817364ef6
@ -0,0 +1,80 @@
|
||||
/**
|
||||
* \file Copyright (c) 2009 Open Infosec Foundation
|
||||
* \author James Riden <jamesr@europe.com>
|
||||
*
|
||||
* PPPoE Decoder
|
||||
*/
|
||||
|
||||
#include "eidps.h"
|
||||
|
||||
#include "packet-queue.h"
|
||||
|
||||
#include "decode.h"
|
||||
#include "decode-ppp.h"
|
||||
#include "decode-pppoe.h"
|
||||
#include "decode-events.h"
|
||||
|
||||
#include "util-unittest.h"
|
||||
|
||||
/**
|
||||
* \brief Main decoding function for PPPoE packets
|
||||
*/
|
||||
void DecodePPPoE(ThreadVars *t, Packet *p, u_int8_t *pkt, u_int16_t len, PacketQueue *pq)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf("DecodePPPoEPacket\n");
|
||||
#endif
|
||||
|
||||
if (len < PPPOE_HEADER_LEN) {
|
||||
DECODER_SET_EVENT(p, PPPOE_PKT_TOO_SMALL);
|
||||
return;
|
||||
}
|
||||
|
||||
p->pppoeh = (PPPoEHdr *)pkt;
|
||||
|
||||
if (p->pppoeh == NULL)
|
||||
return;
|
||||
|
||||
if (p->pppoeh->pppoe_length>0) {
|
||||
/* decode contained PPP packet */
|
||||
PerfCounterIncr(COUNTER_DECODER_PPP, t->pca);
|
||||
DecodePPP(t, p, pkt + PPPOE_HEADER_LEN, len - PPPOE_HEADER_LEN, pq);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** DecodePPPoEtest01
|
||||
* /brief Decode malformed PPPoE packet (too short)
|
||||
* /retval Expected test value: 1
|
||||
*/
|
||||
static int DecodePPPoEtest01 (void) {
|
||||
|
||||
/* 0000 ff ff ff ff ff ff 00 0a e4 13 31 a3 81 00 03 98 ..........1.....
|
||||
0010 81 00 00 80 88 63 11 09 00 00 00 08 01 01 00 00 .....c..........
|
||||
0020 01 00 00 00 */
|
||||
|
||||
u_int8_t raw_pppoe[] = { 0x11, 0x00, 0x00, 0x00, 0x00 };
|
||||
Packet p;
|
||||
ThreadVars tv;
|
||||
|
||||
memset(&tv, 0, sizeof(ThreadVars));
|
||||
memset(&p, 0, sizeof(Packet));
|
||||
|
||||
DecodePPPoE(&tv, &p, raw_pppoe, sizeof(raw_pppoe), NULL);
|
||||
|
||||
/* Function my returns here with expected value */
|
||||
|
||||
if(DECODER_ISSET_EVENT(&p,PPPOE_PKT_TOO_SMALL)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Registers PPPoE unit test
|
||||
* \todo More PPPoE tests
|
||||
*/
|
||||
void DecodePPPoERegisterTests(void) {
|
||||
UtRegisterTest("DecodePPPoEtest01", DecodePPPoEtest01, 1);
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
/**
|
||||
* \file Copyright (c) 2009 Open Infosec Foundation
|
||||
* \author James Riden <jamesr@europe.com>
|
||||
*
|
||||
* PPPoE Decoder header file
|
||||
*/
|
||||
|
||||
#ifndef __DECODE_PPPOE_H__
|
||||
#define __DECODE_PPPOE_H__
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <pcap.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <net/if.h>
|
||||
|
||||
#include "decode.h"
|
||||
#include "threadvars.h"
|
||||
|
||||
#define PPPOE_HEADER_LEN 6
|
||||
|
||||
typedef struct _PPPoEHdr
|
||||
{
|
||||
unsigned pppoe_version :4;
|
||||
unsigned pppoe_type :4;
|
||||
u_int8_t pppoe_code;
|
||||
u_int16_t sessin_id;
|
||||
u_int16_t pppoe_length;
|
||||
} PPPoEHdr;
|
||||
|
||||
#define PPPOE_CODE_PADI 0x09
|
||||
#define PPPOE_CODE_PADO 0x07
|
||||
#define PPPOE_CODE_PADR 0x19
|
||||
#define PPPOE_CODE_PADS 0x65
|
||||
#define PPPOE_CODE_PADT 0xa7
|
||||
|
||||
void DecodePPPoERegisterTests(void);
|
||||
|
||||
#endif /* __DECODE_PPPOE_H__ */
|
||||
Loading…
Reference in New Issue