53 if (
len <
sizeof(NshHdr)) {
57 if (!PacketIncreaseCheckLayers(p)) {
62 const NshHdr *hdr = (
const NshHdr *)pkt;
70 uint16_t length = (
SCNtohs(hdr->ver_flags_len) & 0x003f) * 4;
99 uint32_t
spi = ((
spi_si & 0xFFFFFF00) >> 8);
100 uint8_t si = (uint8_t)(
spi_si & 0xFF);
109 if (
len - length > USHRT_MAX) {
114 if (
len - length > USHRT_MAX) {
133static uint8_t valid_nsh_packet[] = { 0x00, 0x04, 0x02, 0x01, 0x00, 0x00, 0x02, 0x02, 0x45, 0x10,
134 0x00, 0x3c, 0x78, 0x8f, 0x40, 0x00, 0x3f, 0x06, 0x79, 0x05, 0x0b, 0x06, 0x06, 0x06, 0x33, 0x06,
135 0x06, 0x06, 0xbd, 0x2e, 0x00, 0x16, 0xc9, 0xee, 0x07, 0x62, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x02,
136 0x16, 0xd0, 0x2f, 0x36, 0x00, 0x00, 0x02, 0x04, 0x05, 0xb4, 0x04, 0x02, 0x08, 0x0a, 0xa9, 0x5f,
137 0x7f, 0xed, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x07 };
139static int DecodeNSHTestHeaderTooSmall(
void)
158static int DecodeNSHTestUnsupportedVersion(
void)
170 valid_nsh_packet[0] = 0xFF;
171 DecodeNSH(&
tv, &
dtv, p, valid_nsh_packet,
sizeof(valid_nsh_packet));
172 valid_nsh_packet[0] = 0x00;
179static int DecodeNSHTestPacketTooSmall(
void)
198static int DecodeNSHTestReservedType(
void)
210 valid_nsh_packet[2] = 0x00;
211 DecodeNSH(&
tv, &
dtv, p, valid_nsh_packet,
sizeof(valid_nsh_packet));
212 valid_nsh_packet[2] = 0x02;
219static int DecodeNSHTestInvalidType(
void)
231 valid_nsh_packet[2] = 0x01;
232 DecodeNSH(&
tv, &
dtv, p, valid_nsh_packet,
sizeof(valid_nsh_packet));
233 valid_nsh_packet[2] = 0x02;
239static int DecodeNSHTestUnsupportedType(
void)
251 valid_nsh_packet[2] = 0x03;
252 DecodeNSH(&
tv, &
dtv, p, valid_nsh_packet,
sizeof(valid_nsh_packet));
253 valid_nsh_packet[2] = 0x02;
260static int DecodeNSHTestUnknownPayload(
void)
272 valid_nsh_packet[3] = 0x99;
273 DecodeNSH(&
tv, &
dtv, p, valid_nsh_packet,
sizeof(valid_nsh_packet));
274 valid_nsh_packet[3] = 0x01;
286 UtRegisterTest(
"DecodeNSHTestHeaderTooSmall", DecodeNSHTestHeaderTooSmall);
287 UtRegisterTest(
"DecodeNSHTestUnsupportedVersion", DecodeNSHTestUnsupportedVersion);
288 UtRegisterTest(
"DecodeNSHTestPacketTooSmall", DecodeNSHTestPacketTooSmall);
289 UtRegisterTest(
"DecodeNSHTestReservedType", DecodeNSHTestReservedType);
290 UtRegisterTest(
"DecodeNSHTestInvalidType", DecodeNSHTestInvalidType);
291 UtRegisterTest(
"DecodeNSHTestUnsupportedType", DecodeNSHTestUnsupportedType);
292 UtRegisterTest(
"DecodeNSHTestUnknownPayload", DecodeNSHTestUnknownPayload);
void StatsIncr(ThreadVars *tv, uint16_t id)
Increments the local counter.
int DecodeEthernet(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint32_t len)
@ NSH_UNSUPPORTED_VERSION
int DecodeIPV4(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint16_t len)
int DecodeIPV6(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint16_t len)
int DecodeMPLS(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint32_t len)
int DecodeNSH(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint32_t len)
Function to decode NSH packets.
void DecodeNSHRegisterTests(void)
#define NSH_NEXT_PROTO_MPLS
#define NSH_NEXT_PROTO_ETHERNET
#define NSH_NEXT_PROTO_IPV6
#define NSH_NEXT_PROTO_IPV4
#define NSH_NEXT_PROTO_NSH
#define ENGINE_SET_INVALID_EVENT(p, e)
#define ENGINE_ISSET_EVENT(p, e)
#define ENGINE_SET_EVENT(p, e)
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
#define FAIL_IF_NOT(expr)
Fail a test if expression evaluates to false.
#define PASS
Pass the test.
Packet * PacketGetFromAlloc(void)
Get a malloced packet.
Structure to hold thread specific data for all decode modules.
Per thread variable structure.
int SCLogDebugEnabled(void)
Returns whether debug messages are enabled to be logged or not.
#define DEBUG_VALIDATE_BUG_ON(exp)