print-vrrp.c revision 147899
122347Spst/* 222347Spst * Copyright (c) 2000 William C. Fenner. 329964Sache * All rights reserved. 429964Sache * 522347Spst * Kevin Steves <ks@hp.se> July 2000 622347Spst * Modified to: 722347Spst * - print version, type string and packet length 822347Spst * - print IP address count if > 1 (-v) 922347Spst * - verify checksum (-v) 1022347Spst * - print authentication string (-v) 1122347Spst * 1222347Spst * Redistribution and use in source and binary forms, with or without 1322347Spst * modification, are permitted provided that: (1) source code 1422347Spst * distributions retain the above copyright notice and this paragraph 1522347Spst * in its entirety, and (2) distributions including binary code include 1622347Spst * the above copyright notice and this paragraph in its entirety in 1722347Spst * the documentation or other materials provided with the distribution. 1822347Spst * The name of William C. Fenner may not be used to endorse or 1922347Spst * promote products derived from this software without specific prior 2022347Spst * written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND 2122347Spst * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT 2222347Spst * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 2322347Spst * FOR A PARTICULAR PURPOSE. 2422347Spst */ 2522347Spst 2622347Spst#ifndef lint 2722347Spststatic const char rcsid[] _U_ = 2822347Spst "@(#) $Header: /tcpdump/master/tcpdump/print-vrrp.c,v 1.9.2.1 2005/05/06 07:57:20 guy Exp $"; 2922347Spst#endif 3022347Spst 3122347Spst#ifdef HAVE_CONFIG_H 3222347Spst#include "config.h" 3322347Spst#endif 3422347Spst 3522347Spst#include <tcpdump-stdinc.h> 3622347Spst 3722347Spst#include <stdio.h> 3822347Spst#include <stdlib.h> 3922347Spst 4022347Spst#include "interface.h" 4122347Spst#include "extract.h" 4222347Spst#include "addrtoname.h" 4322347Spst 4422347Spst/* 4522347Spst * RFC 2338: 4622347Spst * 0 1 2 3 4722347Spst * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 4822347Spst * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 4922347Spst * |Version| Type | Virtual Rtr ID| Priority | Count IP Addrs| 5022347Spst * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 5122347Spst * | Auth Type | Adver Int | Checksum | 5222347Spst * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 5322347Spst * | IP Address (1) | 5422347Spst * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 5522347Spst * | . | 5622347Spst * | . | 5722347Spst * | . | 5822347Spst * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 5922347Spst * | IP Address (n) | 6022347Spst * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 6122347Spst * | Authentication Data (1) | 6222347Spst * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 6322347Spst * | Authentication Data (2) | 6422347Spst * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 6522347Spst */ 6622347Spst 6722347Spst/* Type */ 6822347Spst#define VRRP_TYPE_ADVERTISEMENT 1 6922347Spst 7022347Spststatic const struct tok type2str[] = { 7122347Spst { VRRP_TYPE_ADVERTISEMENT, "Advertisement" }, 7222347Spst { 0, NULL } 7322347Spst}; 7422347Spst 75/* Auth Type */ 76#define VRRP_AUTH_NONE 0 77#define VRRP_AUTH_SIMPLE 1 78#define VRRP_AUTH_AH 2 79 80static const struct tok auth2str[] = { 81 { VRRP_AUTH_NONE, "none" }, 82 { VRRP_AUTH_SIMPLE, "simple" }, 83 { VRRP_AUTH_AH, "ah" }, 84 { 0, NULL } 85}; 86 87void 88vrrp_print(register const u_char *bp, register u_int len, int ttl) 89{ 90 int version, type, auth_type; 91 const char *type_s; 92 93 TCHECK(bp[0]); 94 version = (bp[0] & 0xf0) >> 4; 95 type = bp[0] & 0x0f; 96 type_s = tok2str(type2str, "unknown type (%u)", type); 97 printf("VRRPv%u, %s", version, type_s); 98 if (ttl != 255) 99 printf(", (ttl %u)", ttl); 100 if (version != 2 || type != VRRP_TYPE_ADVERTISEMENT) 101 return; 102 TCHECK(bp[2]); 103 printf(", vrid %u, prio %u", bp[1], bp[2]); 104 TCHECK(bp[5]); 105 auth_type = bp[4]; 106 printf(", authtype %s", tok2str(auth2str, NULL, auth_type)); 107 printf(", intvl %us, length %u", bp[5],len); 108 if (vflag) { 109 int naddrs = bp[3]; 110 int i; 111 char c; 112 113 if (TTEST2(bp[0], len) && in_cksum((const u_short*)bp, len, 0)) 114 printf(", (bad vrrp cksum %x)", 115 EXTRACT_16BITS(&bp[6])); 116 printf(", addrs"); 117 if (naddrs > 1) 118 printf("(%d)", naddrs); 119 printf(":"); 120 c = ' '; 121 bp += 8; 122 for (i = 0; i < naddrs; i++) { 123 TCHECK(bp[3]); 124 printf("%c%s", c, ipaddr_string(bp)); 125 c = ','; 126 bp += 4; 127 } 128 if (auth_type == VRRP_AUTH_SIMPLE) { /* simple text password */ 129 TCHECK(bp[7]); 130 printf(" auth \""); 131 if (fn_printn(bp, 8, snapend)) { 132 printf("\""); 133 goto trunc; 134 } 135 printf("\""); 136 } 137 } 138 return; 139trunc: 140 printf("[|vrrp]"); 141} 142