Skip to content

Commit fa4c956

Browse files
committed
AH: Update in accordance with RFC4302
Remove the obsolete RFC1826 AH header. Use nd_print_protocol_caps(). Print the fields in header order. Fix the length field and print the bytes count of header (verbose mode). Print the Reserved field if non-zero. Add/update some comments. Fix spaces. Update the outputs of two tests accordingly.
1 parent e1d33d8 commit fa4c956

File tree

4 files changed

+110
-85
lines changed

4 files changed

+110
-85
lines changed

ah.h

+24-14
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,37 @@
3131
*/
3232

3333
/*
34-
* RFC1826/2402 authentication header.
34+
* RFC4302 authentication header.
3535
*/
3636

3737
#ifndef ND_AH_H_
3838
#define ND_AH_H_
3939

40-
struct ah {
41-
nd_uint8_t ah_nxt; /* Next Header */
42-
nd_uint8_t ah_len; /* Length of data, in 32bit */
43-
nd_uint16_t ah_reserve; /* Reserved for future use */
44-
nd_uint32_t ah_spi; /* Security parameter index */
45-
/* variable size, 32bit bound*/ /* Authentication data */
46-
};
40+
/*
41+
* 0 1 2 3
42+
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
43+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44+
* | Next Header | Payload Len | RESERVED |
45+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46+
* | Security Parameters Index (SPI) |
47+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
48+
* | Sequence Number Field |
49+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
50+
* | |
51+
* + Integrity Check Value-ICV (variable) |
52+
* | |
53+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
54+
*
55+
* Figure 1. AH Format
56+
*/
4757

48-
struct newah {
58+
struct ah {
4959
nd_uint8_t ah_nxt; /* Next Header */
50-
nd_uint8_t ah_len; /* Length of data + 1, in 32bit */
51-
nd_uint16_t ah_reserve; /* Reserved for future use */
52-
nd_uint32_t ah_spi; /* Security parameter index */
53-
nd_uint32_t ah_seq; /* Sequence number field */
54-
/* variable size, 32bit bound*/ /* Authentication data */
60+
nd_uint8_t ah_len; /* Payload Len in 32bit words minus 2 */
61+
nd_uint16_t ah_reserved; /* Reserved for future use */
62+
nd_uint32_t ah_spi; /* Security Parameters Index */
63+
nd_uint32_t ah_seq; /* Sequence Number Field */
64+
/* variable size, 32bit bound*/ /* Integrity Check Value-ICV */
5565
};
5666

5767
#endif /* ND_AH_H_ */

print-ah.c

+24-9
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,39 @@ int
3838
ah_print(netdissect_options *ndo, const u_char *bp)
3939
{
4040
const struct ah *ah;
41-
u_int sumlen;
41+
uint8_t ah_len;
42+
u_int ah_hdr_len;
43+
uint16_t reserved;
4244

4345
ndo->ndo_protocol = "ah";
4446
ah = (const struct ah *)bp;
4547

4648
ND_TCHECK_SIZE(ah);
49+
nd_print_protocol_caps(ndo);
50+
/*
51+
* RFC4302
52+
*
53+
* 2.2. Payload Length
54+
*
55+
* This 8-bit field specifies the length of AH in 32-bit words (4-byte
56+
* units), minus "2".
57+
*/
58+
ah_len = GET_U_1(ah->ah_len);
59+
ah_hdr_len = (ah_len + 2) * 4;
4760

48-
sumlen = GET_U_1(ah->ah_len) << 2;
49-
50-
ND_PRINT("AH(spi=0x%08x", GET_BE_U_4(ah->ah_spi));
61+
ND_PRINT("(");
5162
if (ndo->ndo_vflag)
52-
ND_PRINT(",sumlen=%u", sumlen);
53-
ND_PRINT(",seq=0x%x", GET_BE_U_4(ah + 1));
54-
ND_TCHECK_LEN(bp, sizeof(struct ah) + sumlen);
63+
ND_PRINT("length=%u(%u-bytes),", ah_len, ah_hdr_len);
64+
reserved = GET_BE_U_2(ah->ah_reserved);
65+
if (reserved)
66+
ND_PRINT("reserved=0x%x[MustBeZero],", reserved);
67+
ND_PRINT("spi=0x%08x,", GET_BE_U_4(ah->ah_spi));
68+
ND_PRINT("seq=0x%x", GET_BE_U_4(ah->ah_seq));
69+
ND_TCHECK_LEN(bp, ah_hdr_len);
5570
ND_PRINT("): ");
5671

57-
return sizeof(struct ah) + sumlen;
58-
trunc:
72+
return ah_hdr_len;
73+
trunc:
5974
nd_print_trunc(ndo);
6075
return -1;
6176
}

tests/heapoverflow-ip_demux_print.out

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
0x0010: 3030 3030 3030 3030 3030 3030 3030 3030 0000000000000000
44
0x0020: 3030 00
55
2 05:27:12.808464432 IP (tos 0x30, ttl 48, id 12336, offset 0, flags [none], proto AH (51), length 12336, bad cksum 3030 (->697b)!)
6-
48.48.48.48 > 48.48.48.48: AH(spi=0x30303030,sumlen=192,seq=0x30303030 [|ah]
6+
48.48.48.48 > 48.48.48.48: AH(length=48(200-bytes),reserved=0x3030[MustBeZero],spi=0x30303030,seq=0x30303030 [|ah]

0 commit comments

Comments
 (0)