xref: /dflybsd-src/contrib/tcpdump/print-carp.c (revision 59c07fbdf8168fa08c76c515186d561b5a92690c)
127bfbee1SPeter Avalos /*	$OpenBSD: print-carp.c,v 1.6 2009/10/27 23:59:55 deraadt Exp $	*/
227bfbee1SPeter Avalos 
327bfbee1SPeter Avalos /*
427bfbee1SPeter Avalos  * Copyright (c) 2000 William C. Fenner.
527bfbee1SPeter Avalos  *                All rights reserved.
627bfbee1SPeter Avalos  *
727bfbee1SPeter Avalos  * Kevin Steves <ks@hp.se> July 2000
827bfbee1SPeter Avalos  * Modified to:
927bfbee1SPeter Avalos  * - print version, type string and packet length
1027bfbee1SPeter Avalos  * - print IP address count if > 1 (-v)
1127bfbee1SPeter Avalos  * - verify checksum (-v)
1227bfbee1SPeter Avalos  * - print authentication string (-v)
1327bfbee1SPeter Avalos  *
1427bfbee1SPeter Avalos  * Copyright (c) 2011 Advanced Computing Technologies
1527bfbee1SPeter Avalos  * George V. Neille-Neil
1627bfbee1SPeter Avalos  *
1727bfbee1SPeter Avalos  * Modified to:
1827bfbee1SPeter Avalos  * - work correctly with CARP
1927bfbee1SPeter Avalos  * - compile into the latest tcpdump
2027bfbee1SPeter Avalos  * - print out the counter
2127bfbee1SPeter Avalos  *
2227bfbee1SPeter Avalos  * Redistribution and use in source and binary forms, with or without
2327bfbee1SPeter Avalos  * modification, are permitted provided that: (1) source code
2427bfbee1SPeter Avalos  * distributions retain the above copyright notice and this paragraph
2527bfbee1SPeter Avalos  * in its entirety, and (2) distributions including binary code include
2627bfbee1SPeter Avalos  * the above copyright notice and this paragraph in its entirety in
2727bfbee1SPeter Avalos  * the documentation or other materials provided with the distribution.
2827bfbee1SPeter Avalos  * The name of William C. Fenner may not be used to endorse or
2927bfbee1SPeter Avalos  * promote products derived from this software without specific prior
3027bfbee1SPeter Avalos  * written permission.  THIS SOFTWARE IS PROVIDED ``AS IS'' AND
3127bfbee1SPeter Avalos  * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
3227bfbee1SPeter Avalos  * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
3327bfbee1SPeter Avalos  * FOR A PARTICULAR PURPOSE.
3427bfbee1SPeter Avalos  *
3527bfbee1SPeter Avalos  */
3627bfbee1SPeter Avalos 
37411677aeSAaron LI /* \summary: Common Address Redundancy Protocol (CARP) printer */
38411677aeSAaron LI 
3927bfbee1SPeter Avalos #ifdef HAVE_CONFIG_H
40*ed775ee7SAntonio Huete Jimenez #include <config.h>
4127bfbee1SPeter Avalos #endif
4227bfbee1SPeter Avalos 
43*ed775ee7SAntonio Huete Jimenez #include "netdissect-stdinc.h"
4427bfbee1SPeter Avalos 
45411677aeSAaron LI #include "netdissect.h" /* for checksum structure and functions */
4627bfbee1SPeter Avalos #include "extract.h"
4727bfbee1SPeter Avalos 
4827bfbee1SPeter Avalos void
carp_print(netdissect_options * ndo,const u_char * bp,u_int len,u_int ttl)49*ed775ee7SAntonio Huete Jimenez carp_print(netdissect_options *ndo, const u_char *bp, u_int len, u_int ttl)
5027bfbee1SPeter Avalos {
51*ed775ee7SAntonio Huete Jimenez 	u_int version, type;
5227bfbee1SPeter Avalos 	const char *type_s;
5327bfbee1SPeter Avalos 
54*ed775ee7SAntonio Huete Jimenez 	ndo->ndo_protocol = "carp";
55*ed775ee7SAntonio Huete Jimenez 	version = (GET_U_1(bp) & 0xf0) >> 4;
56*ed775ee7SAntonio Huete Jimenez 	type = GET_U_1(bp) & 0x0f;
5727bfbee1SPeter Avalos 	if (type == 1)
5827bfbee1SPeter Avalos 		type_s = "advertise";
5927bfbee1SPeter Avalos 	else
6027bfbee1SPeter Avalos 		type_s = "unknown";
61*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("CARPv%u-%s %u: ", version, type_s, len);
6227bfbee1SPeter Avalos 	if (ttl != 255)
63*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("[ttl=%u!] ", ttl);
6427bfbee1SPeter Avalos 	if (version != 2 || type != 1)
6527bfbee1SPeter Avalos 		return;
66*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("vhid=%u advbase=%u advskew=%u authlen=%u ",
67*ed775ee7SAntonio Huete Jimenez 	    GET_U_1(bp + 1), GET_U_1(bp + 5), GET_U_1(bp + 2),
68*ed775ee7SAntonio Huete Jimenez 	    GET_U_1(bp + 3));
69411677aeSAaron LI 	if (ndo->ndo_vflag) {
7027bfbee1SPeter Avalos 		struct cksum_vec vec[1];
71411677aeSAaron LI 		vec[0].ptr = (const uint8_t *)bp;
7227bfbee1SPeter Avalos 		vec[0].len = len;
73*ed775ee7SAntonio Huete Jimenez 		if (ND_TTEST_LEN(bp, len) && in_cksum(vec, 1))
74*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(" (bad carp cksum %x!)",
75*ed775ee7SAntonio Huete Jimenez 				GET_BE_U_2(bp + 6));
7627bfbee1SPeter Avalos 	}
77*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("counter=%" PRIu64, GET_BE_U_8(bp + 8));
7827bfbee1SPeter Avalos }
79