protos: remove wrong inlining
[netsniff-ng.git] / src / proto_ip_authentication_hdr.c
blob1975c1f859cee802185fed9609220ea553f937b9
1 /*
2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2012 Markus Amend <markus@netsniff-ng.org>
4 * Subject to the GPL, version 2.
6 * IP Authentication Header described in RFC4302
7 */
9 #include <stdio.h>
10 #include <stdint.h>
11 #include <netinet/in.h> /* for ntohs() */
13 #include "proto.h"
14 #include "protos.h"
15 #include "dissector_eth.h"
16 #include "built_in.h"
17 #include "pkt_buff.h"
19 struct auth_hdr {
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 } __packed;
27 static void auth_hdr(struct pkt_buff *pkt)
29 uint16_t hdr_len;
30 struct auth_hdr *auth_ops;
32 auth_ops = (struct auth_hdr *) pkt_pull(pkt, sizeof(*auth_ops));
33 hdr_len = (auth_ops->h_payload_len * 4) + 8;
34 if (auth_ops == NULL)
35 return;
37 tprintf(" [ Authentication Header ");
38 tprintf("NextHdr (%u), ", auth_ops->h_next_header);
39 if (hdr_len > pkt_len(pkt)) {
40 tprintf("HdrLen (%u, %s), ", hdr_len,
41 colorize_start_full(black, red),
42 "invalid" colorize_end());
43 return;
45 tprintf("HdrLen (%u), ", hdr_len);
46 tprintf("Reserved (0x%x), ", ntohs(auth_ops->h_reserved));
47 /* TODO
48 * Upgrade for Extended (64-bit) Sequence Number
49 * http://tools.ietf.org/html/rfc4302#section-2.5.1
51 tprintf("SPI (0x%x), ", ntohl(auth_ops->h_spi));
52 tprintf("SNF (0x%x), ", ntohl(auth_ops->h_snf));
53 tprintf("ICV 0x");
54 for (size_t i = sizeof(struct auth_hdr); i < hdr_len; i++)
55 tprintf("%02x", *pkt_pull(pkt, 1));
56 tprintf(" ]\n");
58 pkt_set_proto(pkt, &eth_lay3, auth_ops->h_next_header);
61 static void auth_hdr_less(struct pkt_buff *pkt)
63 uint16_t hdr_len;
64 struct auth_hdr *auth_ops;
66 auth_ops = (struct auth_hdr *) pkt_pull(pkt, sizeof(*auth_ops));
67 hdr_len = (auth_ops->h_payload_len * 4) + 8;
68 if (auth_ops == NULL || hdr_len > pkt_len(pkt))
69 return;
71 tprintf(" AH");
73 pkt_pull(pkt, hdr_len - sizeof(*auth_ops));
74 pkt_set_proto(pkt, &eth_lay3, auth_ops->h_next_header);
77 struct protocol ip_auth_ops = {
78 .key = 0x33,
79 .print_full = auth_hdr,
80 .print_less = auth_hdr_less,
83 EXPORT_SYMBOL(ip_auth_hdr_ops);