1235427Sdelphij/* $OpenBSD: print-carp.c,v 1.6 2009/10/27 23:59:55 deraadt Exp $ */ 2235427Sdelphij 3235427Sdelphij/* 4235427Sdelphij * Copyright (c) 2000 William C. Fenner. 5235427Sdelphij * All rights reserved. 6235427Sdelphij * 7235427Sdelphij * Kevin Steves <ks@hp.se> July 2000 8235427Sdelphij * Modified to: 9235427Sdelphij * - print version, type string and packet length 10235427Sdelphij * - print IP address count if > 1 (-v) 11235427Sdelphij * - verify checksum (-v) 12235427Sdelphij * - print authentication string (-v) 13235427Sdelphij * 14235427Sdelphij * Copyright (c) 2011 Advanced Computing Technologies 15235427Sdelphij * George V. Neille-Neil 16235427Sdelphij * 17235427Sdelphij * Modified to: 18235427Sdelphij * - work correctly with CARP 19235427Sdelphij * - compile into the latest tcpdump 20235427Sdelphij * - print out the counter 21235427Sdelphij * 22235427Sdelphij * Redistribution and use in source and binary forms, with or without 23235427Sdelphij * modification, are permitted provided that: (1) source code 24235427Sdelphij * distributions retain the above copyright notice and this paragraph 25235427Sdelphij * in its entirety, and (2) distributions including binary code include 26235427Sdelphij * the above copyright notice and this paragraph in its entirety in 27235427Sdelphij * the documentation or other materials provided with the distribution. 28235427Sdelphij * The name of William C. Fenner may not be used to endorse or 29235427Sdelphij * promote products derived from this software without specific prior 30235427Sdelphij * written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND 31235427Sdelphij * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT 32235427Sdelphij * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 33235427Sdelphij * FOR A PARTICULAR PURPOSE. 34235427Sdelphij * 35235427Sdelphij */ 36235427Sdelphij 37235427Sdelphij#ifdef HAVE_CONFIG_H 38235427Sdelphij#include "config.h" 39235427Sdelphij#endif 40235427Sdelphij 41235427Sdelphij#include <tcpdump-stdinc.h> 42235427Sdelphij 43235427Sdelphij#include <stdio.h> 44235427Sdelphij#include <stdlib.h> 45235427Sdelphij#include <unistd.h> 46235427Sdelphij 47235427Sdelphij#include <netinet/in.h> 48235427Sdelphij 49235427Sdelphij#include "interface.h" 50235427Sdelphij#include "extract.h" 51235427Sdelphij#include "addrtoname.h" 52235427Sdelphij 53235427Sdelphijvoid 54235427Sdelphijcarp_print(register const u_char *bp, register u_int len, int ttl) 55235427Sdelphij{ 56235427Sdelphij int version, type; 57235427Sdelphij const char *type_s; 58235427Sdelphij 59235427Sdelphij TCHECK(bp[0]); 60235427Sdelphij version = (bp[0] & 0xf0) >> 4; 61235427Sdelphij type = bp[0] & 0x0f; 62235427Sdelphij if (type == 1) 63235427Sdelphij type_s = "advertise"; 64235427Sdelphij else 65235427Sdelphij type_s = "unknown"; 66235427Sdelphij printf("CARPv%d-%s %d: ", version, type_s, len); 67235427Sdelphij if (ttl != 255) 68235427Sdelphij printf("[ttl=%d!] ", ttl); 69235427Sdelphij if (version != 2 || type != 1) 70235427Sdelphij return; 71235427Sdelphij TCHECK(bp[2]); 72235427Sdelphij TCHECK(bp[5]); 73235427Sdelphij printf("vhid=%d advbase=%d advskew=%d authlen=%d ", 74235427Sdelphij bp[1], bp[5], bp[2], bp[3]); 75235427Sdelphij if (vflag) { 76235427Sdelphij struct cksum_vec vec[1]; 77235427Sdelphij vec[0].ptr = (const u_int8_t *)bp; 78235427Sdelphij vec[0].len = len; 79235427Sdelphij if (TTEST2(bp[0], len) && in_cksum(vec, 1)) 80235427Sdelphij printf(" (bad carp cksum %x!)", 81235427Sdelphij EXTRACT_16BITS(&bp[6])); 82235427Sdelphij } 83235427Sdelphij printf("counter=%" PRIu64, EXTRACT_64BITS(&bp[8])); 84235427Sdelphij 85235427Sdelphij return; 86235427Sdelphijtrunc: 87235427Sdelphij printf("[|carp]"); 88235427Sdelphij} 89