diff options
author | Michael Shalayeff <mickey@cvs.openbsd.org> | 2002-01-22 18:33:08 +0000 |
---|---|---|
committer | Michael Shalayeff <mickey@cvs.openbsd.org> | 2002-01-22 18:33:08 +0000 |
commit | 75f57b74f63a511e763199d2192dacdf0a62efa0 (patch) | |
tree | a26c96985703d2831f867b77c7e4ef0e96392484 | |
parent | 237a861cf8b12913ea0ac70a0869c7361823b75b (diff) |
HSRP dissector, from Julian Cowley <julian@lava.net> via tcpdump.org
-rw-r--r-- | usr.sbin/tcpdump/Makefile | 4 | ||||
-rw-r--r-- | usr.sbin/tcpdump/interface.h | 5 | ||||
-rw-r--r-- | usr.sbin/tcpdump/print-hsrp.c | 142 | ||||
-rw-r--r-- | usr.sbin/tcpdump/print-udp.c | 7 |
4 files changed, 152 insertions, 6 deletions
diff --git a/usr.sbin/tcpdump/Makefile b/usr.sbin/tcpdump/Makefile index 36198cdadce..bf1b09742a4 100644 --- a/usr.sbin/tcpdump/Makefile +++ b/usr.sbin/tcpdump/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.33 2001/11/06 23:03:12 art Exp $ +# $OpenBSD: Makefile,v 1.34 2002/01/22 18:33:07 mickey Exp $ # # Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994 # The Regents of the University of California. All rights reserved. @@ -39,7 +39,7 @@ SRCS= tcpdump.c addrtoname.c \ print-atalk.c print-domain.c print-tftp.c print-bootp.c print-nfs.c \ print-icmp.c print-sl.c print-ppp.c print-rip.c print-timed.c \ print-snmp.c print-ntp.c print-null.c print-egp.c print-ospf.c \ - print-fddi.c print-llc.c print-sunrpc.c \ + print-fddi.c print-llc.c print-sunrpc.c print-hsrp.c \ print-vrrp.c print-wb.c print-decnet.c print-isoclns.c print-ipx.c \ print-atm.c print-dvmrp.c print-krb.c print-pim.c print-netbios.c \ util.c bpf_dump.c parsenfsfh.c version.c machdep.c print-igrp.c \ diff --git a/usr.sbin/tcpdump/interface.h b/usr.sbin/tcpdump/interface.h index dd5bf236c2b..9a8e857fc70 100644 --- a/usr.sbin/tcpdump/interface.h +++ b/usr.sbin/tcpdump/interface.h @@ -1,4 +1,4 @@ -/* $OpenBSD: interface.h,v 1.28 2001/10/02 18:04:35 deraadt Exp $ */ +/* $OpenBSD: interface.h,v 1.29 2002/01/22 18:33:07 mickey Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 @@ -20,7 +20,7 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/interface.h,v 1.28 2001/10/02 18:04:35 deraadt Exp $ (LBL) + * @(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/interface.h,v 1.29 2002/01/22 18:33:07 mickey Exp $ (LBL) */ #ifndef tcpdump_interface_h @@ -213,6 +213,7 @@ extern char *smb_errstr(int, int); extern void print_data(const unsigned char *, int); extern void l2tp_print(const u_char *dat, u_int length); extern void vrrp_print(const u_char *bp, u_int len, int ttl); +extern void hsrp_print(const u_char *, u_int); extern void nfsreply_print(const u_char *, u_int, const u_char *); extern void nfsreq_print(const u_char *, u_int, const u_char *); extern void ns_print(const u_char *, u_int); diff --git a/usr.sbin/tcpdump/print-hsrp.c b/usr.sbin/tcpdump/print-hsrp.c new file mode 100644 index 00000000000..d5ec38e6cb9 --- /dev/null +++ b/usr.sbin/tcpdump/print-hsrp.c @@ -0,0 +1,142 @@ +/* $OpenBSD: print-hsrp.c,v 1.1 2002/01/22 18:33:07 mickey Exp $ */ + +/* + * Copyright (C) 2001 Julian Cowley + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* Cisco Hot Standby Router Protocol (HSRP). */ + +#ifndef lint +static const char rcsid[] = + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-hsrp.c,v 1.1 2002/01/22 18:33:07 mickey Exp $"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <sys/types.h> + +#include <stdio.h> +#include <netinet/in.h> + +#include "interface.h" +#include "addrtoname.h" + +/* HSRP op code types. */ +static const char *op_code_str[] = { + "hello", + "coup", + "resign" +}; + +/* HSRP states and associated names. */ +static struct tok states[] = { + { 0, "initial" }, + { 1, "learn" }, + { 2, "listen" }, + { 4, "speak" }, + { 8, "standby" }, + { 16, "active" }, + { 0, NULL } +}; + +/* + * RFC 2281: + * + * 0 1 2 3 + * 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 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Version | Op Code | State | Hellotime | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Holdtime | Priority | Group | Reserved | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Authentication Data | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Authentication Data | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Virtual IP Address | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + +#define HSRP_AUTH_SIZE 8 + +/* HSRP protocol header. */ +struct hsrp { + u_char hsrp_version; + u_char hsrp_op_code; + u_char hsrp_state; + u_char hsrp_hellotime; + u_char hsrp_holdtime; + u_char hsrp_priority; + u_char hsrp_group; + u_char hsrp_reserved; + u_char hsrp_authdata[HSRP_AUTH_SIZE]; + struct in_addr hsrp_virtaddr; +}; + +void +hsrp_print(register const u_char *bp, register u_int len) +{ + struct hsrp *hp = (struct hsrp *) bp; + + TCHECK(hp->hsrp_version); + printf("HSRPv%d", hp->hsrp_version); + if (hp->hsrp_version != 0) + return; + TCHECK(hp->hsrp_op_code); + printf("-"); + if (hp->hsrp_op_code >= sizeof(op_code_str)/sizeof(*op_code_str)) + printf("unknown (%d) ", hp->hsrp_op_code); + else + printf("%s ", op_code_str[hp->hsrp_op_code]); + printf("%d: ", len); + TCHECK(hp->hsrp_state); + printf("state=%s ", tok2str(states, "Unknown (%d)", hp->hsrp_state)); + TCHECK(hp->hsrp_group); + printf("group=%d ", hp->hsrp_group); + TCHECK(hp->hsrp_reserved); + if (hp->hsrp_reserved != 0) { + printf("[reserved=%d!] ", hp->hsrp_reserved); + } + TCHECK2(hp->hsrp_virtaddr, sizeof(hp->hsrp_virtaddr)); + printf("addr=%s", ipaddr_string(&hp->hsrp_virtaddr)); + if (vflag) { + printf(" hellotime="); + relts_print(hp->hsrp_hellotime); + printf(" holdtime="); + relts_print(hp->hsrp_holdtime); + printf(" priority=%d", hp->hsrp_priority); + printf(" auth=\""); + fn_printn(hp->hsrp_authdata, sizeof(hp->hsrp_authdata), NULL); + printf("\""); + } + return; +trunc: + printf("[|hsrp]"); +} diff --git a/usr.sbin/tcpdump/print-udp.c b/usr.sbin/tcpdump/print-udp.c index e057348bb84..c87dd554787 100644 --- a/usr.sbin/tcpdump/print-udp.c +++ b/usr.sbin/tcpdump/print-udp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: print-udp.c,v 1.20 2001/06/25 19:56:12 itojun Exp $ */ +/* $OpenBSD: print-udp.c,v 1.21 2002/01/22 18:33:07 mickey Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996 @@ -23,7 +23,7 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-udp.c,v 1.20 2001/06/25 19:56:12 itojun Exp $ (LBL)"; + "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-udp.c,v 1.21 2002/01/22 18:33:07 mickey Exp $ (LBL)"; #endif #include <sys/param.h> @@ -356,6 +356,7 @@ static int udp_cksum(register const struct ip *ip, #define OLD_RADIUS_ACCT_PORT 1646 #define RADIUS_AUTH_PORT 1812 #define RADIUS_ACCT_PORT 1813 +#define HSRP_PORT 1985 /*XXX*/ #define LWRES_PORT 921 #ifdef INET6 @@ -610,6 +611,8 @@ udp_print(register const u_char *bp, u_int length, register const u_char *bp2) */ else if (dport == 4567) wb_print((const void *)(up + 1), length); + else if (dport == HSRP_PORT) + hsrp_print((const u_char *)(up + 1), length); else (void)printf(" udp %u", (u_int32_t)(ulen - sizeof(*up))); |