summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorMichael Shalayeff <mickey@cvs.openbsd.org>1998-06-25 19:42:49 +0000
committerMichael Shalayeff <mickey@cvs.openbsd.org>1998-06-25 19:42:49 +0000
commitb450519b5135e110a57c7e9ff6ca98ef7b4005e7 (patch)
treebdb45aad819e0c9cd9edcb87d7d4e803cbc83b57 /usr.sbin
parentf7502f1aee86c9a3ebb4d6814e47a52727bc2d42 (diff)
add cisco netflow proto printing; not tested w/ version 5, but should work anyways
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/tcpdump/Makefile4
-rw-r--r--usr.sbin/tcpdump/interface.h3
-rw-r--r--usr.sbin/tcpdump/print-cnfp.c157
-rw-r--r--usr.sbin/tcpdump/print-udp.c5
-rw-r--r--usr.sbin/tcpdump/tcpdump.c4
5 files changed, 168 insertions, 5 deletions
diff --git a/usr.sbin/tcpdump/Makefile b/usr.sbin/tcpdump/Makefile
index 648256b4e20..7470c8736fa 100644
--- a/usr.sbin/tcpdump/Makefile
+++ b/usr.sbin/tcpdump/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.12 1998/06/11 00:01:22 provos Exp $
+# $OpenBSD: Makefile,v 1.13 1998/06/25 19:42:43 mickey Exp $
#
# Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994
# The Regents of the University of California. All rights reserved.
@@ -40,7 +40,7 @@ SRCS= tcpdump.c addrtoname.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 \
- print-gre.c print-radius.c print-enc.c
+ print-gre.c print-radius.c print-enc.c print-cnfp.c
AWKS = atime.awk packetdat.awk send-ack.awk stime.awk
diff --git a/usr.sbin/tcpdump/interface.h b/usr.sbin/tcpdump/interface.h
index f4c3dfa1924..bbe66dc817c 100644
--- a/usr.sbin/tcpdump/interface.h
+++ b/usr.sbin/tcpdump/interface.h
@@ -18,7 +18,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.8 1998/06/11 00:01:23 provos Exp $ (LBL)
+ * @(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/interface.h,v 1.9 1998/06/25 19:42:45 mickey Exp $ (LBL)
*/
#ifndef tcpdump_interface_h
@@ -50,6 +50,7 @@ extern int packettype; /* as specified by -T */
#define PT_RPC 3 /* Remote Procedure Call */
#define PT_RTP 4 /* Real-Time Applications protocol */
#define PT_RTCP 5 /* Real-Time Applications control protocol */
+#define PT_CNFP 6 /* Cisco NetFlow protocol */
#ifndef min
#define min(a,b) ((a)>(b)?(b):(a))
diff --git a/usr.sbin/tcpdump/print-cnfp.c b/usr.sbin/tcpdump/print-cnfp.c
new file mode 100644
index 00000000000..32d45b27e41
--- /dev/null
+++ b/usr.sbin/tcpdump/print-cnfp.c
@@ -0,0 +1,157 @@
+/* $OpenBSD: print-cnfp.c,v 1.1 1998/06/25 19:42:46 mickey Exp $ */
+
+/*
+ * Copyright (c) 1998 Michael Shalayeff
+ * 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Michael Shalayeff.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 NetFlow protocol */
+
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/socket.h>
+#include <netdb.h>
+
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+
+#include <stdio.h>
+#include <string.h>
+
+#include "interface.h"
+
+struct nfhdr {
+ u_int32_t ver_cnt; /* version [15], and # of records */
+ u_int32_t msys_uptime;
+ u_int32_t utc_sec;
+ u_int32_t utc_nsec;
+ u_int32_t sequence; /* v5 flow sequence number */
+ u_int32_t reserved; /* v5 only */
+};
+
+struct nfrec {
+ in_addr_t src_ina;
+ in_addr_t dst_ina;
+ in_addr_t nhop_ina;
+ u_int32_t ifaces; /* src,dst ifaces */
+ u_int32_t packets;
+ u_int32_t octets;
+ u_int32_t start_time; /* sys_uptime value */
+ u_int32_t last_time; /* sys_uptime value */
+ u_int32_t ports; /* src,dst ports */
+ u_int32_t proto_tos; /* proto, tos, pad, flags(v5) */
+ u_int32_t asses; /* v1: flags; v5: src,dst AS */
+ u_int32_t masks; /* src,dst addr prefix */
+
+};
+
+void
+cnfp_print(register const u_char *cp, u_int len, register const u_char *bp)
+{
+ register const struct nfhdr *nh;
+ register const struct nfrec *nr;
+ register const struct ip *ip;
+ struct protoent *pent;
+ int nrecs, ver;
+ time_t t;
+ char *p;
+
+ ip = (struct ip *)bp;
+ nh = (struct nfhdr *)cp;
+
+ nrecs = ntohl(nh->ver_cnt) & 0xffff;
+ ver = (ntohl(nh->ver_cnt) & 0xffff0000) >> 16;
+ t = ntohl(nh->utc_sec);
+/* (p = ctime(&t))[24] = '\0'; */
+
+ printf("NetFlow v%x, %u.%03u uptime, %u.%09u, ", ver,
+ ntohl(nh->msys_uptime)/1000, ntohl(nh->msys_uptime)%1000,
+ ntohl(nh->utc_sec), ntohl(nh->utc_nsec));
+
+ if (ver == 5) {
+ printf("#%u, ", htonl(nh->sequence));
+ nr = (struct nfrec *)&nh[1];
+ } else
+ nr = (struct nfrec *)&nh->sequence;
+
+ printf("%2u recs:", nrecs);
+ for (; nrecs--; nr++) {
+ char buf[5];
+ char asbuf[7];
+
+ printf("\n started %u.%03u, last %u.%03u",
+ ntohl(nr->start_time)/1000, ntohl(nr->start_time)%1000,
+ ntohl(nr->last_time)/1000, ntohl(nr->last_time)%1000);
+
+ asbuf[0] = buf[0] = '\0';
+ if (ver == 5) {
+ sprintf(buf, "/%d", (ntohl(nr->masks) >> 24) & 0xff);
+ sprintf(asbuf, "%d:", (ntohl(nr->asses) >> 16) & 0xffff);
+ }
+ printf("\n %s%s%s:%u ", inet_ntoa(nr->src_ina), buf, asbuf,
+ ntohl(nr->ports) >> 16);
+
+ if (ver == 5) {
+ sprintf(buf, "/%d", (ntohl(nr->masks) >> 16) & 0xff);
+ sprintf(asbuf, "%d:", ntohl(nr->asses) & 0xffff);
+ }
+ printf("> %s%s%s:%u ", inet_ntoa(nr->dst_ina), buf, asbuf,
+ ntohl(nr->ports) & 0xffff);
+
+ printf(">> %s\n ", inet_ntoa(nr->nhop_ina));
+
+ pent = getprotobynumber((ntohl(nr->proto_tos) >> 8) & 0xff);
+ if (!pent || nflag)
+ printf("%u ", (ntohl(nr->proto_tos) >> 8) & 0xff);
+ else
+ printf("%s ", pent->p_name);
+
+ /* tcp flags for tcp only */
+ if (pent && pent->p_proto == IPPROTO_TCP) {
+ int flags;
+ if (ver == 1)
+ flags = (ntohl(nr->asses) >> 24) & 0xff;
+ else
+ flags = (ntohl(nr->proto_tos) >> 16) & 0xff;
+ if (flags & TH_FIN) putchar('F');
+ if (flags & TH_SYN) putchar('S');
+ if (flags & TH_RST) putchar('R');
+ if (flags & TH_PUSH) putchar('P');
+ if (flags & TH_ACK) putchar('A');
+ if (flags & TH_URG) putchar('U');
+ if (flags)
+ putchar(' ');
+ }
+ printf("tos %u, %u (%u octets)", ntohl(nr->proto_tos) & 0xff,
+ ntohl(nr->packets), ntohl(nr->octets));
+
+
+ }
+
+}
+
diff --git a/usr.sbin/tcpdump/print-udp.c b/usr.sbin/tcpdump/print-udp.c
index c315fa34e81..373d30b3b5b 100644
--- a/usr.sbin/tcpdump/print-udp.c
+++ b/usr.sbin/tcpdump/print-udp.c
@@ -21,7 +21,7 @@
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-udp.c,v 1.7 1997/07/31 09:49:13 tqbf Exp $ (LBL)";
+ "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-udp.c,v 1.8 1998/06/25 19:42:47 mickey Exp $ (LBL)";
#endif
#include <sys/param.h>
@@ -372,6 +372,9 @@ udp_print(register const u_char *bp, u_int length, register const u_char *bp2)
while (cp < ep)
cp = rtcp_print(cp, ep);
break;
+ case PT_CNFP:
+ cnfp_print(cp, length, ip);
+ break;
}
return;
}
diff --git a/usr.sbin/tcpdump/tcpdump.c b/usr.sbin/tcpdump/tcpdump.c
index 15c00f4a87f..8840e0953c7 100644
--- a/usr.sbin/tcpdump/tcpdump.c
+++ b/usr.sbin/tcpdump/tcpdump.c
@@ -24,7 +24,7 @@ static const char copyright[] =
"@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996\n\
The Regents of the University of California. All rights reserved.\n";
static const char rcsid[] =
- "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/tcpdump.c,v 1.9 1998/06/11 00:01:24 provos Exp $ (LBL)";
+ "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/tcpdump.c,v 1.10 1998/06/25 19:42:48 mickey Exp $ (LBL)";
#endif
/*
@@ -233,6 +233,8 @@ main(int argc, char **argv)
packettype = PT_RTP;
else if (strcasecmp(optarg, "rtcp") == 0)
packettype = PT_RTCP;
+ else if (strcasecmp(optarg, "cnfp") == 0)
+ packettype = PT_CNFP;
else
error("unknown packet type `%s'", optarg);
break;