19546e36dSchristos /* $OpenBSD: print-carp.c,v 1.6 2009/10/27 23:59:55 deraadt Exp $ */ 29546e36dSchristos 39546e36dSchristos /* 49546e36dSchristos * Copyright (c) 2000 William C. Fenner. 59546e36dSchristos * All rights reserved. 69546e36dSchristos * 79546e36dSchristos * Kevin Steves <ks@hp.se> July 2000 89546e36dSchristos * Modified to: 99546e36dSchristos * - print version, type string and packet length 109546e36dSchristos * - print IP address count if > 1 (-v) 119546e36dSchristos * - verify checksum (-v) 129546e36dSchristos * - print authentication string (-v) 139546e36dSchristos * 149546e36dSchristos * Copyright (c) 2011 Advanced Computing Technologies 159546e36dSchristos * George V. Neille-Neil 169546e36dSchristos * 179546e36dSchristos * Modified to: 189546e36dSchristos * - work correctly with CARP 199546e36dSchristos * - compile into the latest tcpdump 209546e36dSchristos * - print out the counter 219546e36dSchristos * 229546e36dSchristos * Redistribution and use in source and binary forms, with or without 239546e36dSchristos * modification, are permitted provided that: (1) source code 249546e36dSchristos * distributions retain the above copyright notice and this paragraph 259546e36dSchristos * in its entirety, and (2) distributions including binary code include 269546e36dSchristos * the above copyright notice and this paragraph in its entirety in 279546e36dSchristos * the documentation or other materials provided with the distribution. 289546e36dSchristos * The name of William C. Fenner may not be used to endorse or 299546e36dSchristos * promote products derived from this software without specific prior 309546e36dSchristos * written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND 319546e36dSchristos * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT 329546e36dSchristos * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 339546e36dSchristos * FOR A PARTICULAR PURPOSE. 349546e36dSchristos * 359546e36dSchristos */ 369546e36dSchristos 37fdccd7e4Schristos #include <sys/cdefs.h> 38fdccd7e4Schristos #ifndef lint 39*26ba0b50Schristos __RCSID("$NetBSD: print-carp.c,v 1.5 2024/09/02 16:15:30 christos Exp $"); 40fdccd7e4Schristos #endif 41fdccd7e4Schristos 42dc860a36Sspz /* \summary: Common Address Redundancy Protocol (CARP) printer */ 43dc860a36Sspz 44c74ad251Schristos #include <config.h> 459546e36dSchristos 46c74ad251Schristos #include "netdissect-stdinc.h" 479546e36dSchristos 48784088dfSchristos #include "netdissect.h" /* for checksum structure and functions */ 499546e36dSchristos #include "extract.h" 509546e36dSchristos 519546e36dSchristos void 52c74ad251Schristos carp_print(netdissect_options *ndo, const u_char *bp, u_int len, u_int ttl) 539546e36dSchristos { 54c74ad251Schristos u_int version, type; 559546e36dSchristos const char *type_s; 569546e36dSchristos 57c74ad251Schristos ndo->ndo_protocol = "carp"; 58*26ba0b50Schristos nd_print_protocol_caps(ndo); 59c74ad251Schristos version = (GET_U_1(bp) & 0xf0) >> 4; 60c74ad251Schristos type = GET_U_1(bp) & 0x0f; 619546e36dSchristos if (type == 1) 629546e36dSchristos type_s = "advertise"; 639546e36dSchristos else 649546e36dSchristos type_s = "unknown"; 65*26ba0b50Schristos ND_PRINT("v%u-%s %u: ", version, type_s, len); 669546e36dSchristos if (ttl != 255) 67c74ad251Schristos ND_PRINT("[ttl=%u!] ", ttl); 689546e36dSchristos if (version != 2 || type != 1) 699546e36dSchristos return; 70c74ad251Schristos ND_PRINT("vhid=%u advbase=%u advskew=%u authlen=%u ", 71c74ad251Schristos GET_U_1(bp + 1), GET_U_1(bp + 5), GET_U_1(bp + 2), 72c74ad251Schristos GET_U_1(bp + 3)); 73c47fd378Schristos if (ndo->ndo_vflag) { 749546e36dSchristos struct cksum_vec vec[1]; 75c47fd378Schristos vec[0].ptr = (const uint8_t *)bp; 769546e36dSchristos vec[0].len = len; 77c74ad251Schristos if (ND_TTEST_LEN(bp, len) && in_cksum(vec, 1)) 78c74ad251Schristos ND_PRINT(" (bad carp cksum %x!)", 79c74ad251Schristos GET_BE_U_2(bp + 6)); 809546e36dSchristos } 81c74ad251Schristos ND_PRINT("counter=%" PRIu64, GET_BE_U_8(bp + 8)); 829546e36dSchristos } 83