xref: /aosp_15_r20/external/tcpdump/print-carp.c (revision 05b00f6010a2396e3db2409989fc67270046269f)
1*05b00f60SXin Li /*	$OpenBSD: print-carp.c,v 1.6 2009/10/27 23:59:55 deraadt Exp $	*/
2*05b00f60SXin Li 
3*05b00f60SXin Li /*
4*05b00f60SXin Li  * Copyright (c) 2000 William C. Fenner.
5*05b00f60SXin Li  *                All rights reserved.
6*05b00f60SXin Li  *
7*05b00f60SXin Li  * Kevin Steves <[email protected]> July 2000
8*05b00f60SXin Li  * Modified to:
9*05b00f60SXin Li  * - print version, type string and packet length
10*05b00f60SXin Li  * - print IP address count if > 1 (-v)
11*05b00f60SXin Li  * - verify checksum (-v)
12*05b00f60SXin Li  * - print authentication string (-v)
13*05b00f60SXin Li  *
14*05b00f60SXin Li  * Copyright (c) 2011 Advanced Computing Technologies
15*05b00f60SXin Li  * George V. Neille-Neil
16*05b00f60SXin Li  *
17*05b00f60SXin Li  * Modified to:
18*05b00f60SXin Li  * - work correctly with CARP
19*05b00f60SXin Li  * - compile into the latest tcpdump
20*05b00f60SXin Li  * - print out the counter
21*05b00f60SXin Li  *
22*05b00f60SXin Li  * Redistribution and use in source and binary forms, with or without
23*05b00f60SXin Li  * modification, are permitted provided that: (1) source code
24*05b00f60SXin Li  * distributions retain the above copyright notice and this paragraph
25*05b00f60SXin Li  * in its entirety, and (2) distributions including binary code include
26*05b00f60SXin Li  * the above copyright notice and this paragraph in its entirety in
27*05b00f60SXin Li  * the documentation or other materials provided with the distribution.
28*05b00f60SXin Li  * The name of William C. Fenner may not be used to endorse or
29*05b00f60SXin Li  * promote products derived from this software without specific prior
30*05b00f60SXin Li  * written permission.  THIS SOFTWARE IS PROVIDED ``AS IS'' AND
31*05b00f60SXin Li  * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
32*05b00f60SXin Li  * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
33*05b00f60SXin Li  * FOR A PARTICULAR PURPOSE.
34*05b00f60SXin Li  *
35*05b00f60SXin Li  */
36*05b00f60SXin Li 
37*05b00f60SXin Li /* \summary: Common Address Redundancy Protocol (CARP) printer */
38*05b00f60SXin Li 
39*05b00f60SXin Li #ifdef HAVE_CONFIG_H
40*05b00f60SXin Li #include <config.h>
41*05b00f60SXin Li #endif
42*05b00f60SXin Li 
43*05b00f60SXin Li #include "netdissect-stdinc.h"
44*05b00f60SXin Li 
45*05b00f60SXin Li #include "netdissect.h" /* for checksum structure and functions */
46*05b00f60SXin Li #include "extract.h"
47*05b00f60SXin Li 
48*05b00f60SXin Li void
carp_print(netdissect_options * ndo,const u_char * bp,u_int len,u_int ttl)49*05b00f60SXin Li carp_print(netdissect_options *ndo, const u_char *bp, u_int len, u_int ttl)
50*05b00f60SXin Li {
51*05b00f60SXin Li 	u_int version, type;
52*05b00f60SXin Li 	const char *type_s;
53*05b00f60SXin Li 
54*05b00f60SXin Li 	ndo->ndo_protocol = "carp";
55*05b00f60SXin Li 	version = (GET_U_1(bp) & 0xf0) >> 4;
56*05b00f60SXin Li 	type = GET_U_1(bp) & 0x0f;
57*05b00f60SXin Li 	if (type == 1)
58*05b00f60SXin Li 		type_s = "advertise";
59*05b00f60SXin Li 	else
60*05b00f60SXin Li 		type_s = "unknown";
61*05b00f60SXin Li 	ND_PRINT("CARPv%u-%s %u: ", version, type_s, len);
62*05b00f60SXin Li 	if (ttl != 255)
63*05b00f60SXin Li 		ND_PRINT("[ttl=%u!] ", ttl);
64*05b00f60SXin Li 	if (version != 2 || type != 1)
65*05b00f60SXin Li 		return;
66*05b00f60SXin Li 	ND_PRINT("vhid=%u advbase=%u advskew=%u authlen=%u ",
67*05b00f60SXin Li 	    GET_U_1(bp + 1), GET_U_1(bp + 5), GET_U_1(bp + 2),
68*05b00f60SXin Li 	    GET_U_1(bp + 3));
69*05b00f60SXin Li 	if (ndo->ndo_vflag) {
70*05b00f60SXin Li 		struct cksum_vec vec[1];
71*05b00f60SXin Li 		vec[0].ptr = (const uint8_t *)bp;
72*05b00f60SXin Li 		vec[0].len = len;
73*05b00f60SXin Li 		if (ND_TTEST_LEN(bp, len) && in_cksum(vec, 1))
74*05b00f60SXin Li 			ND_PRINT(" (bad carp cksum %x!)",
75*05b00f60SXin Li 				GET_BE_U_2(bp + 6));
76*05b00f60SXin Li 	}
77*05b00f60SXin Li 	ND_PRINT("counter=%" PRIu64, GET_BE_U_8(bp + 8));
78*05b00f60SXin Li }
79