2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2012 Markus Amend <markus@netsniff-ng.org>, Deutsche Flugsicherung GmbH
4 * Subject to the GPL, version 2.
6 * IP Authentication Header described in RFC4302
11 #include <netinet/in.h> /* for ntohs() */
15 #include "dissector_eth.h"
20 uint8_t h_next_header
;
21 uint8_t h_payload_len
;
27 static void auth_hdr(struct pkt_buff
*pkt
)
30 struct auth_hdr
*auth_ops
;
32 auth_ops
= (struct auth_hdr
*) pkt_pull(pkt
, sizeof(*auth_ops
));
36 hdr_len
= (auth_ops
->h_payload_len
* 4) + 8;
38 tprintf(" [ Authentication Header ");
39 tprintf("NextHdr (%u), ", auth_ops
->h_next_header
);
40 if (hdr_len
> pkt_len(pkt
) || hdr_len
< 0){
41 tprintf("HdrLen (%u, %zd Bytes %s), ",
42 auth_ops
->h_payload_len
, hdr_len
,
43 colorize_start_full(black
, red
)
44 "invalid" colorize_end());
47 tprintf("HdrLen (%u, %zd Bytes), ",auth_ops
->h_payload_len
, hdr_len
);
48 tprintf("Reserved (0x%x), ", ntohs(auth_ops
->h_reserved
));
50 * Upgrade for Extended (64-bit) Sequence Number
51 * http://tools.ietf.org/html/rfc4302#section-2.5.1
53 tprintf("SPI (0x%x), ", ntohl(auth_ops
->h_spi
));
54 tprintf("SNF (0x%x), ", ntohl(auth_ops
->h_snf
));
56 for (size_t i
= sizeof(struct auth_hdr
); i
< hdr_len
; i
++)
57 tprintf("%02x", *pkt_pull(pkt
, 1));
60 pkt_set_proto(pkt
, ð_lay3
, auth_ops
->h_next_header
);
63 static void auth_hdr_less(struct pkt_buff
*pkt
)
66 struct auth_hdr
*auth_ops
;
68 auth_ops
= (struct auth_hdr
*) pkt_pull(pkt
, sizeof(*auth_ops
));
72 hdr_len
= (auth_ops
->h_payload_len
* 4) + 8;
73 if (hdr_len
> pkt_len(pkt
) || hdr_len
< 0)
78 pkt_pull(pkt
, hdr_len
- sizeof(*auth_ops
));
79 pkt_set_proto(pkt
, ð_lay3
, auth_ops
->h_next_header
);
82 struct protocol ip_auth_ops
= {
84 .print_full
= auth_hdr
,
85 .print_less
= auth_hdr_less
,
88 EXPORT_SYMBOL(ip_auth_ops
);