* Copyright (c) 2000 William C. Fenner.
* All rights reserved.
*
+ * Modified to:
+ * - print version, type string and packet length
+ * - print IP address count if > 1 (-v)
+ * - verify checksum (-v)
+ * - print authentication string (-v)
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that: (1) source code
* distributions retain the above copyright notice and this paragraph
*/
#ifndef lint
-static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/tcpdump/print-vrrp.c,v 1.1 2000-05-01 17:35:44 fenner Exp $";
+static const char rcsid[] _U_ =
+ "@(#) $Header: /tcpdump/master/tcpdump/print-vrrp.c,v 1.10 2005-05-06 07:56:54 guy Exp $";
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
+#include <tcpdump-stdinc.h>
+
#include <stdio.h>
#include <stdlib.h>
-#include <unistd.h>
#include "interface.h"
#include "extract.h"
* | Authentication Data (2) |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
+
+/* Type */
+#define VRRP_TYPE_ADVERTISEMENT 1
+
+static const struct tok type2str[] = {
+ { VRRP_TYPE_ADVERTISEMENT, "Advertisement" },
+ { 0, NULL }
+};
+
+/* Auth Type */
+#define VRRP_AUTH_NONE 0
+#define VRRP_AUTH_SIMPLE 1
+#define VRRP_AUTH_AH 2
+
+static const struct tok auth2str[] = {
+ { VRRP_AUTH_NONE, "none" },
+ { VRRP_AUTH_SIMPLE, "simple" },
+ { VRRP_AUTH_AH, "ah" },
+ { 0, NULL }
+};
+
void
vrrp_print(register const u_char *bp, register u_int len, int ttl)
{
- printf("vrrp ");
+ int version, type, auth_type;
+ const char *type_s;
+
+ TCHECK(bp[0]);
+ version = (bp[0] & 0xf0) >> 4;
+ type = bp[0] & 0x0f;
+ type_s = tok2str(type2str, "unknown type (%u)", type);
+ printf("VRRPv%u, %s", version, type_s);
if (ttl != 255)
- printf("[ttl=%d!] ", ttl);
- TCHECK(bp[3]);
- if ((bp[0] & 0xf0) != 0x20) {
- printf("[v=%d]", bp[0] >> 4);
+ printf(", (ttl %u)", ttl);
+ if (version != 2 || type != VRRP_TYPE_ADVERTISEMENT)
return;
- }
- if ((bp[0] & 0x0f) != 1) {
- printf("[t=%d]", bp[0] & 0x0f);
- return;
- }
- printf("vrid=%d prio=%d", bp[1], bp[2]);
+ TCHECK(bp[2]);
+ printf(", vrid %u, prio %u", bp[1], bp[2]);
TCHECK(bp[5]);
- if (bp[4] != 0) {
- printf(" [authtype %d]", bp[4]);
- }
- printf(" intvl=%d", bp[5]);
+ auth_type = bp[4];
+ printf(", authtype %s", tok2str(auth2str, NULL, auth_type));
+ printf(", intvl %us, length %u", bp[5],len);
if (vflag) {
int naddrs = bp[3];
int i;
char c;
- /* check checksum? */
- printf(" addrs:");
+ if (TTEST2(bp[0], len)) {
+ struct cksum_vec vec[1];
+
+ vec[0].ptr = bp;
+ vec[0].len = len;
+ if (in_cksum(vec, 1))
+ printf(", (bad vrrp cksum %x)",
+ EXTRACT_16BITS(&bp[6]));
+ }
+ printf(", addrs");
+ if (naddrs > 1)
+ printf("(%d)", naddrs);
+ printf(":");
c = ' ';
bp += 8;
for (i = 0; i < naddrs; i++) {
c = ',';
bp += 4;
}
- /* auth data? */
+ if (auth_type == VRRP_AUTH_SIMPLE) { /* simple text password */
+ TCHECK(bp[7]);
+ printf(" auth \"");
+ if (fn_printn(bp, 8, snapend)) {
+ printf("\"");
+ goto trunc;
+ }
+ printf("\"");
+ }
}
return;
trunc: