1685295f4SBill Fenner /* 2685295f4SBill Fenner * Copyright (c) 2000 William C. Fenner. 3685295f4SBill Fenner * All rights reserved. 4685295f4SBill Fenner * 5685295f4SBill Fenner * Kevin Steves <ks@hp.se> July 2000 6685295f4SBill Fenner * Modified to: 7685295f4SBill Fenner * - print version, type string and packet length 8685295f4SBill Fenner * - print IP address count if > 1 (-v) 9685295f4SBill Fenner * - verify checksum (-v) 10685295f4SBill Fenner * - print authentication string (-v) 11685295f4SBill Fenner * 12685295f4SBill Fenner * Redistribution and use in source and binary forms, with or without 13685295f4SBill Fenner * modification, are permitted provided that: (1) source code 14685295f4SBill Fenner * distributions retain the above copyright notice and this paragraph 15685295f4SBill Fenner * in its entirety, and (2) distributions including binary code include 16685295f4SBill Fenner * the above copyright notice and this paragraph in its entirety in 17685295f4SBill Fenner * the documentation or other materials provided with the distribution. 18685295f4SBill Fenner * The name of William C. Fenner may not be used to endorse or 19685295f4SBill Fenner * promote products derived from this software without specific prior 20685295f4SBill Fenner * written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND 21685295f4SBill Fenner * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT 22685295f4SBill Fenner * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23685295f4SBill Fenner * FOR A PARTICULAR PURPOSE. 24685295f4SBill Fenner */ 25685295f4SBill Fenner 26685295f4SBill Fenner #ifndef lint 27685295f4SBill Fenner static const char rcsid[] = 28a90e161bSBill Fenner "@(#) $Header: /tcpdump/master/tcpdump/print-vrrp.c,v 1.5 2001/07/23 22:27:30 fenner Exp $"; 29685295f4SBill Fenner #endif 30685295f4SBill Fenner 31685295f4SBill Fenner #ifdef HAVE_CONFIG_H 32685295f4SBill Fenner #include "config.h" 33685295f4SBill Fenner #endif 34685295f4SBill Fenner 35685295f4SBill Fenner #include <stdio.h> 36685295f4SBill Fenner #include <stdlib.h> 37685295f4SBill Fenner #include <unistd.h> 38685295f4SBill Fenner 39685295f4SBill Fenner #include <netinet/in.h> 40685295f4SBill Fenner 41685295f4SBill Fenner #include "interface.h" 42685295f4SBill Fenner #include "extract.h" 43685295f4SBill Fenner #include "addrtoname.h" 44685295f4SBill Fenner 45685295f4SBill Fenner /* 46685295f4SBill Fenner * RFC 2338: 47685295f4SBill Fenner * 0 1 2 3 48685295f4SBill Fenner * 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 49685295f4SBill Fenner * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 50685295f4SBill Fenner * |Version| Type | Virtual Rtr ID| Priority | Count IP Addrs| 51685295f4SBill Fenner * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 52685295f4SBill Fenner * | Auth Type | Adver Int | Checksum | 53685295f4SBill Fenner * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 54685295f4SBill Fenner * | IP Address (1) | 55685295f4SBill Fenner * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 56685295f4SBill Fenner * | . | 57685295f4SBill Fenner * | . | 58685295f4SBill Fenner * | . | 59685295f4SBill Fenner * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 60685295f4SBill Fenner * | IP Address (n) | 61685295f4SBill Fenner * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 62685295f4SBill Fenner * | Authentication Data (1) | 63685295f4SBill Fenner * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 64685295f4SBill Fenner * | Authentication Data (2) | 65685295f4SBill Fenner * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 66685295f4SBill Fenner */ 67a90e161bSBill Fenner 68a90e161bSBill Fenner /* Type */ 69a90e161bSBill Fenner #define VRRP_TYPE_ADVERTISEMENT 1 70a90e161bSBill Fenner 71a90e161bSBill Fenner static const struct tok type2str[] = { 72a90e161bSBill Fenner { VRRP_TYPE_ADVERTISEMENT, "advertisement" }, 73a90e161bSBill Fenner { 0, NULL } 74a90e161bSBill Fenner }; 75a90e161bSBill Fenner 76a90e161bSBill Fenner /* Auth Type */ 77a90e161bSBill Fenner #define VRRP_AUTH_NONE 0 78a90e161bSBill Fenner #define VRRP_AUTH_SIMPLE 1 79a90e161bSBill Fenner #define VRRP_AUTH_AH 2 80a90e161bSBill Fenner 81a90e161bSBill Fenner static const struct tok auth2str[] = { 82a90e161bSBill Fenner { VRRP_AUTH_NONE, "none" }, 83a90e161bSBill Fenner { VRRP_AUTH_SIMPLE, "simple" }, 84a90e161bSBill Fenner { VRRP_AUTH_AH, "ah" }, 85a90e161bSBill Fenner { 0, NULL } 86a90e161bSBill Fenner }; 87a90e161bSBill Fenner 88685295f4SBill Fenner void 89685295f4SBill Fenner vrrp_print(register const u_char *bp, register u_int len, int ttl) 90685295f4SBill Fenner { 91685295f4SBill Fenner int version, type, auth_type; 92a90e161bSBill Fenner const char *type_s; 93685295f4SBill Fenner 94685295f4SBill Fenner TCHECK(bp[0]); 95685295f4SBill Fenner version = (bp[0] & 0xf0) >> 4; 96685295f4SBill Fenner type = bp[0] & 0x0f; 97a90e161bSBill Fenner type_s = tok2str(type2str, "type#%d", type); 98685295f4SBill Fenner printf("VRRPv%d-%s %d: ", version, type_s, len); 99685295f4SBill Fenner if (ttl != 255) 100685295f4SBill Fenner printf("[ttl=%d!] ", ttl); 101a90e161bSBill Fenner if (version != 2 || type != VRRP_TYPE_ADVERTISEMENT) 102685295f4SBill Fenner return; 103685295f4SBill Fenner TCHECK(bp[2]); 104685295f4SBill Fenner printf("vrid=%d prio=%d", bp[1], bp[2]); 105685295f4SBill Fenner TCHECK(bp[5]); 106685295f4SBill Fenner auth_type = bp[4]; 107a90e161bSBill Fenner printf(" authtype=%s", tok2str(auth2str, NULL, auth_type)); 108685295f4SBill Fenner printf(" intvl=%d", bp[5]); 109685295f4SBill Fenner if (vflag) { 110685295f4SBill Fenner int naddrs = bp[3]; 111685295f4SBill Fenner int i; 112685295f4SBill Fenner char c; 113685295f4SBill Fenner 114685295f4SBill Fenner if (TTEST2(bp[0], len) && in_cksum((const u_short*)bp, len, 0)) 115685295f4SBill Fenner printf(" (bad vrrp cksum %x!)", 116685295f4SBill Fenner EXTRACT_16BITS(&bp[6])); 117685295f4SBill Fenner printf(" addrs"); 118685295f4SBill Fenner if (naddrs > 1) 119685295f4SBill Fenner printf("(%d)", naddrs); 120685295f4SBill Fenner printf(":"); 121685295f4SBill Fenner c = ' '; 122685295f4SBill Fenner bp += 8; 123685295f4SBill Fenner for (i = 0; i < naddrs; i++) { 124685295f4SBill Fenner TCHECK(bp[3]); 125685295f4SBill Fenner printf("%c%s", c, ipaddr_string(bp)); 126685295f4SBill Fenner c = ','; 127685295f4SBill Fenner bp += 4; 128685295f4SBill Fenner } 129a90e161bSBill Fenner if (auth_type == VRRP_AUTH_SIMPLE) { /* simple text password */ 130685295f4SBill Fenner TCHECK(bp[7]); 131a90e161bSBill Fenner printf(" auth \""); 132a90e161bSBill Fenner fn_printn(bp, 8, NULL); 133a90e161bSBill Fenner printf("\""); 134685295f4SBill Fenner } 135685295f4SBill Fenner } 136685295f4SBill Fenner return; 137685295f4SBill Fenner trunc: 138685295f4SBill Fenner printf("[|vrrp]"); 139685295f4SBill Fenner } 140