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