ring: built_in: fix if cacheline_aligned is not defined
[netsniff-ng.git] / src / proto_ip_authentication_hdr.h
blob040c56afc1774a447fd822cf6ad69ad6f09860cf
1 /*
2 * IP Authentication Header described in RFC4302
3 * programmed by Markus Amend 2012 as a contribution to
4 * netsniff-ng - the packet sniffing beast
5 * Copyright 2012 Markus Amend.
6 * Subject to the GPL, version 2.
7 */
9 #ifndef AUTHENTICATION_HEADER_H
10 #define AUTHENTICATION_HEADER_H
12 #include <stdio.h>
13 #include <stdint.h>
14 #include <netinet/in.h> /* for ntohs() */
16 #include "proto_struct.h"
17 #include "dissector_eth.h"
19 struct auth_hdrhdr {
20 uint8_t h_next_header;
21 uint8_t h_payload_len;
22 uint16_t h_reserved;
23 uint32_t h_spi;
24 uint32_t h_snf;
25 } __attribute__((packed));
27 static inline void auth_hdr(uint8_t *packet, size_t len)
29 uint8_t hdr_payload_len;
30 struct auth_hdrhdr *auth_hdr = (struct auth_hdrhdr *) packet;
32 hdr_payload_len = (auth_hdr->h_payload_len * 4) + 8;
33 if (len < hdr_payload_len || len < sizeof(struct auth_hdrhdr))
34 return;
36 tprintf(" [ Authentication Header ");
37 tprintf("NextHdr (%u), ", auth_hdr->h_next_header);
38 tprintf("HdrLen (%u), ", hdr_payload_len);
39 tprintf("Reserved (0x%x), ", ntohs(auth_hdr->h_reserved));
40 tprintf("SPI (0x%x), ", ntohl(auth_hdr->h_spi));
41 tprintf("SNF (0x%x), ", ntohl(auth_hdr->h_snf));
42 tprintf("ICV 0x");
43 for (uint8_t i = sizeof(struct auth_hdrhdr); i < hdr_payload_len; i++)
44 tprintf("%02x",(uint8_t) packet[i]);
45 tprintf(" ]\n");
48 static inline void auth_hdr_less(uint8_t *packet, size_t len)
50 uint8_t hdr_payload_len;
51 struct auth_hdrhdr *auth_hdr = (struct auth_hdrhdr *) packet;
53 hdr_payload_len = (auth_hdr->h_payload_len * 4) + 8;
54 if (len < hdr_payload_len || len < sizeof(struct auth_hdrhdr))
55 return;
57 tprintf(" AH");
60 static inline void auth_hdr_next(uint8_t *packet, size_t len,
61 struct hash_table **table,
62 unsigned int *key, size_t *off)
64 uint8_t hdr_payload_len;
65 struct auth_hdrhdr *auth_hdr = (struct auth_hdrhdr *) packet;
67 hdr_payload_len = (auth_hdr->h_payload_len * 4) + 8;
68 if (len < hdr_payload_len || len < sizeof(struct auth_hdrhdr))
69 return;
71 (*off) = hdr_payload_len;
72 (*key) = auth_hdr->h_next_header;
73 (*table) = &eth_lay3;
76 struct protocol ip_auth_hdr_ops = {
77 .key = 0x33,
78 .print_full = auth_hdr,
79 .print_less = auth_hdr_less,
80 .print_pay_ascii = empty,
81 .print_pay_hex = empty,
82 .print_pay_none = auth_hdr,
83 .print_all_hex = hex,
84 .proto_next = auth_hdr_next,
87 #endif /* AUTHENTICATION_HEADER_H */