Home | History | Annotate | Line # | Download | only in dist
print-cnfp.c revision 1.1.1.4
      1      1.1  christos /*	$OpenBSD: print-cnfp.c,v 1.2 1998/06/25 20:26:59 mickey Exp $	*/
      2      1.1  christos 
      3      1.1  christos /*
      4      1.1  christos  * Copyright (c) 1998 Michael Shalayeff
      5      1.1  christos  * All rights reserved.
      6      1.1  christos  *
      7      1.1  christos  * Redistribution and use in source and binary forms, with or without
      8      1.1  christos  * modification, are permitted provided that the following conditions
      9      1.1  christos  * are met:
     10      1.1  christos  * 1. Redistributions of source code must retain the above copyright
     11      1.1  christos  *    notice, this list of conditions and the following disclaimer.
     12      1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     13      1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     14      1.1  christos  *    documentation and/or other materials provided with the distribution.
     15      1.1  christos  * 3. All advertising materials mentioning features or use of this software
     16      1.1  christos  *    must display the following acknowledgement:
     17      1.1  christos  *	This product includes software developed by Michael Shalayeff.
     18      1.1  christos  * 4. The name of the author may not be used to endorse or promote products
     19      1.1  christos  *    derived from this software without specific prior written permission.
     20      1.1  christos  *
     21      1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22      1.1  christos  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23      1.1  christos  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24      1.1  christos  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25      1.1  christos  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26      1.1  christos  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27      1.1  christos  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28      1.1  christos  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29      1.1  christos  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30      1.1  christos  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31      1.1  christos  */
     32      1.1  christos 
     33  1.1.1.4  christos /*
     34  1.1.1.4  christos  * Cisco NetFlow protocol
     35  1.1.1.4  christos  *
     36  1.1.1.4  christos  * See
     37  1.1.1.4  christos  *
     38  1.1.1.4  christos  *    http://www.cisco.com/c/en/us/td/docs/net_mgmt/netflow_collection_engine/3-6/user/guide/format.html#wp1005892
     39  1.1.1.4  christos  */
     40      1.1  christos 
     41  1.1.1.3  christos #define NETDISSECT_REWORKED
     42      1.1  christos #ifdef HAVE_CONFIG_H
     43      1.1  christos #include "config.h"
     44      1.1  christos #endif
     45      1.1  christos 
     46      1.1  christos #include <tcpdump-stdinc.h>
     47      1.1  christos 
     48      1.1  christos #include <stdio.h>
     49      1.1  christos #include <string.h>
     50      1.1  christos 
     51      1.1  christos #include "interface.h"
     52      1.1  christos #include "addrtoname.h"
     53      1.1  christos #include "extract.h"
     54      1.1  christos 
     55      1.1  christos #include "tcp.h"
     56      1.1  christos #include "ipproto.h"
     57      1.1  christos 
     58  1.1.1.4  christos struct nfhdr_v1 {
     59  1.1.1.4  christos 	uint16_t	version;	/* version number */
     60  1.1.1.4  christos 	uint16_t	count;		/* # of records */
     61  1.1.1.4  christos 	uint32_t	msys_uptime;
     62  1.1.1.4  christos 	uint32_t	utc_sec;
     63  1.1.1.4  christos 	uint32_t	utc_nsec;
     64  1.1.1.4  christos };
     65  1.1.1.4  christos 
     66  1.1.1.4  christos struct nfrec_v1 {
     67  1.1.1.4  christos 	struct in_addr	src_ina;
     68  1.1.1.4  christos 	struct in_addr	dst_ina;
     69  1.1.1.4  christos 	struct in_addr	nhop_ina;
     70  1.1.1.4  christos 	uint16_t	input;		/* SNMP index of input interface */
     71  1.1.1.4  christos 	uint16_t	output;		/* SNMP index of output interface */
     72  1.1.1.4  christos 	uint32_t	packets;	/* packets in the flow */
     73  1.1.1.4  christos 	uint32_t	octets;		/* layer 3 octets in the packets of the flow */
     74  1.1.1.4  christos 	uint32_t	start_time;	/* sys_uptime value at start of flow */
     75  1.1.1.4  christos 	uint32_t	last_time;	/* sys_uptime value when last packet of flow was received */
     76  1.1.1.4  christos 	uint16_t	srcport;	/* TCP/UDP source port or equivalent */
     77  1.1.1.4  christos 	uint16_t	dstport;	/* TCP/UDP source port or equivalent */
     78  1.1.1.4  christos 	uint16_t	pad1;		/* pad */
     79  1.1.1.4  christos 	uint8_t		proto;		/* IP protocol type */
     80  1.1.1.4  christos 	uint8_t		tos;		/* IP type of service */
     81  1.1.1.4  christos 	uint8_t		tcp_flags;	/* cumulative OR of TCP flags */
     82  1.1.1.4  christos 	uint8_t		pad[3];		/* padding */
     83  1.1.1.4  christos 	uint32_t	reserved;	/* unused */
     84  1.1.1.4  christos };
     85  1.1.1.4  christos 
     86  1.1.1.4  christos struct nfhdr_v5 {
     87  1.1.1.4  christos 	uint16_t	version;	/* version number */
     88  1.1.1.4  christos 	uint16_t	count;		/* # of records */
     89  1.1.1.4  christos 	uint32_t	msys_uptime;
     90  1.1.1.4  christos 	uint32_t	utc_sec;
     91  1.1.1.4  christos 	uint32_t	utc_nsec;
     92  1.1.1.4  christos 	uint32_t	sequence;	/* flow sequence number */
     93  1.1.1.4  christos 	uint8_t		engine_type;	/* type of flow-switching engine */
     94  1.1.1.4  christos 	uint8_t		engine_id;	/* slot number of the flow-switching engine */
     95  1.1.1.4  christos 	uint16_t	sampling_interval; /* sampling mode and interval */
     96  1.1.1.4  christos };
     97  1.1.1.4  christos 
     98  1.1.1.4  christos struct nfrec_v5 {
     99  1.1.1.4  christos 	struct in_addr	src_ina;
    100  1.1.1.4  christos 	struct in_addr	dst_ina;
    101  1.1.1.4  christos 	struct in_addr	nhop_ina;
    102  1.1.1.4  christos 	uint16_t	input;		/* SNMP index of input interface */
    103  1.1.1.4  christos 	uint16_t	output;		/* SNMP index of output interface */
    104  1.1.1.4  christos 	uint32_t	packets;	/* packets in the flow */
    105  1.1.1.4  christos 	uint32_t	octets;		/* layer 3 octets in the packets of the flow */
    106  1.1.1.4  christos 	uint32_t	start_time;	/* sys_uptime value at start of flow */
    107  1.1.1.4  christos 	uint32_t	last_time;	/* sys_uptime value when last packet of flow was received */
    108  1.1.1.4  christos 	uint16_t	srcport;	/* TCP/UDP source port or equivalent */
    109  1.1.1.4  christos 	uint16_t	dstport;	/* TCP/UDP source port or equivalent */
    110  1.1.1.4  christos 	uint8_t		pad1;		/* pad */
    111  1.1.1.4  christos 	uint8_t		tcp_flags;	/* cumulative OR of TCP flags */
    112  1.1.1.4  christos 	uint8_t		proto;		/* IP protocol type */
    113  1.1.1.4  christos 	uint8_t		tos;		/* IP type of service */
    114  1.1.1.4  christos 	uint16_t	src_as;		/* AS number of the source */
    115  1.1.1.4  christos 	uint16_t	dst_as;		/* AS number of the destination */
    116  1.1.1.4  christos 	uint8_t		src_mask;	/* source address mask bits */
    117  1.1.1.4  christos 	uint8_t		dst_mask;	/* destination address prefix mask bits */
    118  1.1.1.4  christos 	uint16_t	pad2;
    119  1.1.1.4  christos 	struct in_addr	peer_nexthop;	/* v6: IP address of the nexthop within the peer (FIB)*/
    120  1.1.1.4  christos };
    121  1.1.1.4  christos 
    122  1.1.1.4  christos struct nfhdr_v6 {
    123  1.1.1.4  christos 	uint16_t	version;	/* version number */
    124  1.1.1.4  christos 	uint16_t	count;		/* # of records */
    125  1.1.1.3  christos 	uint32_t	msys_uptime;
    126  1.1.1.3  christos 	uint32_t	utc_sec;
    127  1.1.1.3  christos 	uint32_t	utc_nsec;
    128  1.1.1.3  christos 	uint32_t	sequence;	/* v5 flow sequence number */
    129  1.1.1.3  christos 	uint32_t	reserved;	/* v5 only */
    130      1.1  christos };
    131      1.1  christos 
    132  1.1.1.4  christos struct nfrec_v6 {
    133      1.1  christos 	struct in_addr	src_ina;
    134      1.1  christos 	struct in_addr	dst_ina;
    135      1.1  christos 	struct in_addr	nhop_ina;
    136  1.1.1.4  christos 	uint16_t	input;		/* SNMP index of input interface */
    137  1.1.1.4  christos 	uint16_t	output;		/* SNMP index of output interface */
    138  1.1.1.4  christos 	uint32_t	packets;	/* packets in the flow */
    139  1.1.1.4  christos 	uint32_t	octets;		/* layer 3 octets in the packets of the flow */
    140  1.1.1.4  christos 	uint32_t	start_time;	/* sys_uptime value at start of flow */
    141  1.1.1.4  christos 	uint32_t	last_time;	/* sys_uptime value when last packet of flow was received */
    142  1.1.1.4  christos 	uint16_t	srcport;	/* TCP/UDP source port or equivalent */
    143  1.1.1.4  christos 	uint16_t	dstport;	/* TCP/UDP source port or equivalent */
    144  1.1.1.4  christos 	uint8_t		pad1;		/* pad */
    145  1.1.1.4  christos 	uint8_t		tcp_flags;	/* cumulative OR of TCP flags */
    146  1.1.1.4  christos 	uint8_t		proto;		/* IP protocol type */
    147  1.1.1.4  christos 	uint8_t		tos;		/* IP type of service */
    148  1.1.1.4  christos 	uint16_t	src_as;		/* AS number of the source */
    149  1.1.1.4  christos 	uint16_t	dst_as;		/* AS number of the destination */
    150  1.1.1.4  christos 	uint8_t		src_mask;	/* source address mask bits */
    151  1.1.1.4  christos 	uint8_t		dst_mask;	/* destination address prefix mask bits */
    152  1.1.1.4  christos 	uint16_t	flags;
    153      1.1  christos 	struct in_addr	peer_nexthop;	/* v6: IP address of the nexthop within the peer (FIB)*/
    154      1.1  christos };
    155      1.1  christos 
    156  1.1.1.4  christos static void
    157  1.1.1.4  christos cnfp_v1_print(netdissect_options *ndo, const u_char *cp)
    158      1.1  christos {
    159  1.1.1.4  christos 	register const struct nfhdr_v1 *nh;
    160  1.1.1.4  christos 	register const struct nfrec_v1 *nr;
    161      1.1  christos 	struct protoent *pent;
    162      1.1  christos 	int nrecs, ver;
    163      1.1  christos #if 0
    164      1.1  christos 	time_t t;
    165      1.1  christos #endif
    166      1.1  christos 
    167  1.1.1.4  christos 	nh = (const struct nfhdr_v1 *)cp;
    168  1.1.1.4  christos 	ND_TCHECK(*nh);
    169      1.1  christos 
    170  1.1.1.4  christos 	ver = EXTRACT_16BITS(&nh->version);
    171  1.1.1.4  christos 	nrecs = EXTRACT_32BITS(&nh->count);
    172      1.1  christos #if 0
    173      1.1  christos 	/*
    174      1.1  christos 	 * This is seconds since the UN*X epoch, and is followed by
    175      1.1  christos 	 * nanoseconds.  XXX - format it, rather than just dumping the
    176      1.1  christos 	 * raw seconds-since-the-Epoch.
    177      1.1  christos 	 */
    178      1.1  christos 	t = EXTRACT_32BITS(&nh->utc_sec);
    179      1.1  christos #endif
    180      1.1  christos 
    181  1.1.1.3  christos 	ND_PRINT((ndo, "NetFlow v%x, %u.%03u uptime, %u.%09u, ", ver,
    182      1.1  christos 	       EXTRACT_32BITS(&nh->msys_uptime)/1000,
    183      1.1  christos 	       EXTRACT_32BITS(&nh->msys_uptime)%1000,
    184  1.1.1.3  christos 	       EXTRACT_32BITS(&nh->utc_sec), EXTRACT_32BITS(&nh->utc_nsec)));
    185      1.1  christos 
    186  1.1.1.4  christos 	nr = (const struct nfrec_v1 *)&nh[1];
    187      1.1  christos 
    188  1.1.1.3  christos 	ND_PRINT((ndo, "%2u recs", nrecs));
    189      1.1  christos 
    190  1.1.1.4  christos 	for (; nrecs != 0; nr++, nrecs--) {
    191      1.1  christos 		char buf[20];
    192      1.1  christos 		char asbuf[20];
    193      1.1  christos 
    194  1.1.1.4  christos 		/*
    195  1.1.1.4  christos 		 * Make sure we have the entire record.
    196  1.1.1.4  christos 		 */
    197  1.1.1.4  christos 		ND_TCHECK(*nr);
    198  1.1.1.3  christos 		ND_PRINT((ndo, "\n  started %u.%03u, last %u.%03u",
    199      1.1  christos 		       EXTRACT_32BITS(&nr->start_time)/1000,
    200      1.1  christos 		       EXTRACT_32BITS(&nr->start_time)%1000,
    201      1.1  christos 		       EXTRACT_32BITS(&nr->last_time)/1000,
    202  1.1.1.3  christos 		       EXTRACT_32BITS(&nr->last_time)%1000));
    203      1.1  christos 
    204      1.1  christos 		asbuf[0] = buf[0] = '\0';
    205  1.1.1.3  christos 		ND_PRINT((ndo, "\n    %s%s%s:%u ", intoa(nr->src_ina.s_addr), buf, asbuf,
    206  1.1.1.4  christos 			EXTRACT_16BITS(&nr->srcport)));
    207  1.1.1.4  christos 
    208  1.1.1.4  christos 		ND_PRINT((ndo, "> %s%s%s:%u ", intoa(nr->dst_ina.s_addr), buf, asbuf,
    209  1.1.1.4  christos 			EXTRACT_16BITS(&nr->dstport)));
    210      1.1  christos 
    211  1.1.1.4  christos 		ND_PRINT((ndo, ">> %s\n    ", intoa(nr->nhop_ina.s_addr)));
    212  1.1.1.4  christos 
    213  1.1.1.4  christos 		pent = getprotobynumber(nr->proto);
    214  1.1.1.4  christos 		if (!pent || ndo->ndo_nflag)
    215  1.1.1.4  christos 			ND_PRINT((ndo, "%u ", nr->proto));
    216  1.1.1.4  christos 		else
    217  1.1.1.4  christos 			ND_PRINT((ndo, "%s ", pent->p_name));
    218  1.1.1.4  christos 
    219  1.1.1.4  christos 		/* tcp flags for tcp only */
    220  1.1.1.4  christos 		if (pent && pent->p_proto == IPPROTO_TCP) {
    221  1.1.1.4  christos 			int flags;
    222  1.1.1.4  christos 			flags = nr->tcp_flags;
    223  1.1.1.4  christos 			ND_PRINT((ndo, "%s%s%s%s%s%s%s",
    224  1.1.1.4  christos 				flags & TH_FIN  ? "F" : "",
    225  1.1.1.4  christos 				flags & TH_SYN  ? "S" : "",
    226  1.1.1.4  christos 				flags & TH_RST  ? "R" : "",
    227  1.1.1.4  christos 				flags & TH_PUSH ? "P" : "",
    228  1.1.1.4  christos 				flags & TH_ACK  ? "A" : "",
    229  1.1.1.4  christos 				flags & TH_URG  ? "U" : "",
    230  1.1.1.4  christos 				flags           ? " " : ""));
    231      1.1  christos 		}
    232  1.1.1.4  christos 
    233  1.1.1.4  christos 		buf[0]='\0';
    234  1.1.1.4  christos 		ND_PRINT((ndo, "tos %u, %u (%u octets) %s",
    235  1.1.1.4  christos 		       nr->tos,
    236  1.1.1.4  christos 		       EXTRACT_32BITS(&nr->packets),
    237  1.1.1.4  christos 		       EXTRACT_32BITS(&nr->octets), buf));
    238  1.1.1.4  christos 	}
    239  1.1.1.4  christos 	return;
    240  1.1.1.4  christos 
    241  1.1.1.4  christos trunc:
    242  1.1.1.4  christos 	ND_PRINT((ndo, "[|cnfp]"));
    243  1.1.1.4  christos 	return;
    244  1.1.1.4  christos }
    245  1.1.1.4  christos 
    246  1.1.1.4  christos static void
    247  1.1.1.4  christos cnfp_v5_print(netdissect_options *ndo, const u_char *cp)
    248  1.1.1.4  christos {
    249  1.1.1.4  christos 	register const struct nfhdr_v5 *nh;
    250  1.1.1.4  christos 	register const struct nfrec_v5 *nr;
    251  1.1.1.4  christos 	struct protoent *pent;
    252  1.1.1.4  christos 	int nrecs, ver;
    253  1.1.1.4  christos #if 0
    254  1.1.1.4  christos 	time_t t;
    255  1.1.1.4  christos #endif
    256  1.1.1.4  christos 
    257  1.1.1.4  christos 	nh = (const struct nfhdr_v5 *)cp;
    258  1.1.1.4  christos 	ND_TCHECK(*nh);
    259  1.1.1.4  christos 
    260  1.1.1.4  christos 	ver = EXTRACT_16BITS(&nh->version);
    261  1.1.1.4  christos 	nrecs = EXTRACT_32BITS(&nh->count);
    262  1.1.1.4  christos #if 0
    263  1.1.1.4  christos 	/*
    264  1.1.1.4  christos 	 * This is seconds since the UN*X epoch, and is followed by
    265  1.1.1.4  christos 	 * nanoseconds.  XXX - format it, rather than just dumping the
    266  1.1.1.4  christos 	 * raw seconds-since-the-Epoch.
    267  1.1.1.4  christos 	 */
    268  1.1.1.4  christos 	t = EXTRACT_32BITS(&nh->utc_sec);
    269  1.1.1.4  christos #endif
    270  1.1.1.4  christos 
    271  1.1.1.4  christos 	ND_PRINT((ndo, "NetFlow v%x, %u.%03u uptime, %u.%09u, ", ver,
    272  1.1.1.4  christos 	       EXTRACT_32BITS(&nh->msys_uptime)/1000,
    273  1.1.1.4  christos 	       EXTRACT_32BITS(&nh->msys_uptime)%1000,
    274  1.1.1.4  christos 	       EXTRACT_32BITS(&nh->utc_sec), EXTRACT_32BITS(&nh->utc_nsec)));
    275  1.1.1.4  christos 
    276  1.1.1.4  christos 	ND_PRINT((ndo, "#%u, ", EXTRACT_32BITS(&nh->sequence)));
    277  1.1.1.4  christos 	nr = (const struct nfrec_v5 *)&nh[1];
    278  1.1.1.4  christos 
    279  1.1.1.4  christos 	ND_PRINT((ndo, "%2u recs", nrecs));
    280  1.1.1.4  christos 
    281  1.1.1.4  christos 	for (; nrecs != 0; nr++, nrecs--) {
    282  1.1.1.4  christos 		char buf[20];
    283  1.1.1.4  christos 		char asbuf[20];
    284  1.1.1.4  christos 
    285  1.1.1.4  christos 		/*
    286  1.1.1.4  christos 		 * Make sure we have the entire record.
    287  1.1.1.4  christos 		 */
    288  1.1.1.4  christos 		ND_TCHECK(*nr);
    289  1.1.1.4  christos 		ND_PRINT((ndo, "\n  started %u.%03u, last %u.%03u",
    290  1.1.1.4  christos 		       EXTRACT_32BITS(&nr->start_time)/1000,
    291  1.1.1.4  christos 		       EXTRACT_32BITS(&nr->start_time)%1000,
    292  1.1.1.4  christos 		       EXTRACT_32BITS(&nr->last_time)/1000,
    293  1.1.1.4  christos 		       EXTRACT_32BITS(&nr->last_time)%1000));
    294  1.1.1.4  christos 
    295  1.1.1.4  christos 		asbuf[0] = buf[0] = '\0';
    296  1.1.1.4  christos 		snprintf(buf, sizeof(buf), "/%u", nr->src_mask);
    297  1.1.1.4  christos 		snprintf(asbuf, sizeof(asbuf), ":%u",
    298  1.1.1.4  christos 			EXTRACT_16BITS(&nr->src_as));
    299  1.1.1.4  christos 		ND_PRINT((ndo, "\n    %s%s%s:%u ", intoa(nr->src_ina.s_addr), buf, asbuf,
    300  1.1.1.4  christos 			EXTRACT_16BITS(&nr->srcport)));
    301  1.1.1.4  christos 
    302  1.1.1.4  christos 		snprintf(buf, sizeof(buf), "/%d", nr->dst_mask);
    303  1.1.1.4  christos 		snprintf(asbuf, sizeof(asbuf), ":%u",
    304  1.1.1.4  christos 			 EXTRACT_16BITS(&nr->dst_as));
    305  1.1.1.3  christos 		ND_PRINT((ndo, "> %s%s%s:%u ", intoa(nr->dst_ina.s_addr), buf, asbuf,
    306  1.1.1.4  christos 			EXTRACT_16BITS(&nr->dstport)));
    307      1.1  christos 
    308  1.1.1.3  christos 		ND_PRINT((ndo, ">> %s\n    ", intoa(nr->nhop_ina.s_addr)));
    309      1.1  christos 
    310  1.1.1.4  christos 		pent = getprotobynumber(nr->proto);
    311  1.1.1.3  christos 		if (!pent || ndo->ndo_nflag)
    312  1.1.1.4  christos 			ND_PRINT((ndo, "%u ", nr->proto));
    313      1.1  christos 		else
    314  1.1.1.3  christos 			ND_PRINT((ndo, "%s ", pent->p_name));
    315      1.1  christos 
    316      1.1  christos 		/* tcp flags for tcp only */
    317      1.1  christos 		if (pent && pent->p_proto == IPPROTO_TCP) {
    318      1.1  christos 			int flags;
    319  1.1.1.4  christos 			flags = nr->tcp_flags;
    320  1.1.1.3  christos 			ND_PRINT((ndo, "%s%s%s%s%s%s%s",
    321  1.1.1.3  christos 				flags & TH_FIN  ? "F" : "",
    322  1.1.1.3  christos 				flags & TH_SYN  ? "S" : "",
    323  1.1.1.3  christos 				flags & TH_RST  ? "R" : "",
    324  1.1.1.3  christos 				flags & TH_PUSH ? "P" : "",
    325  1.1.1.3  christos 				flags & TH_ACK  ? "A" : "",
    326  1.1.1.3  christos 				flags & TH_URG  ? "U" : "",
    327  1.1.1.3  christos 				flags           ? " " : ""));
    328      1.1  christos 		}
    329      1.1  christos 
    330      1.1  christos 		buf[0]='\0';
    331  1.1.1.4  christos 		ND_PRINT((ndo, "tos %u, %u (%u octets) %s",
    332  1.1.1.4  christos 		       nr->tos,
    333  1.1.1.4  christos 		       EXTRACT_32BITS(&nr->packets),
    334  1.1.1.4  christos 		       EXTRACT_32BITS(&nr->octets), buf));
    335  1.1.1.4  christos 	}
    336  1.1.1.4  christos 	return;
    337  1.1.1.4  christos 
    338  1.1.1.4  christos trunc:
    339  1.1.1.4  christos 	ND_PRINT((ndo, "[|cnfp]"));
    340  1.1.1.4  christos 	return;
    341  1.1.1.4  christos }
    342  1.1.1.4  christos 
    343  1.1.1.4  christos static void
    344  1.1.1.4  christos cnfp_v6_print(netdissect_options *ndo, const u_char *cp)
    345  1.1.1.4  christos {
    346  1.1.1.4  christos 	register const struct nfhdr_v6 *nh;
    347  1.1.1.4  christos 	register const struct nfrec_v6 *nr;
    348  1.1.1.4  christos 	struct protoent *pent;
    349  1.1.1.4  christos 	int nrecs, ver;
    350  1.1.1.4  christos #if 0
    351  1.1.1.4  christos 	time_t t;
    352  1.1.1.4  christos #endif
    353  1.1.1.4  christos 
    354  1.1.1.4  christos 	nh = (const struct nfhdr_v6 *)cp;
    355  1.1.1.4  christos 	ND_TCHECK(*nh);
    356  1.1.1.4  christos 
    357  1.1.1.4  christos 	ver = EXTRACT_16BITS(&nh->version);
    358  1.1.1.4  christos 	nrecs = EXTRACT_32BITS(&nh->count);
    359  1.1.1.4  christos #if 0
    360  1.1.1.4  christos 	/*
    361  1.1.1.4  christos 	 * This is seconds since the UN*X epoch, and is followed by
    362  1.1.1.4  christos 	 * nanoseconds.  XXX - format it, rather than just dumping the
    363  1.1.1.4  christos 	 * raw seconds-since-the-Epoch.
    364  1.1.1.4  christos 	 */
    365  1.1.1.4  christos 	t = EXTRACT_32BITS(&nh->utc_sec);
    366  1.1.1.4  christos #endif
    367  1.1.1.4  christos 
    368  1.1.1.4  christos 	ND_PRINT((ndo, "NetFlow v%x, %u.%03u uptime, %u.%09u, ", ver,
    369  1.1.1.4  christos 	       EXTRACT_32BITS(&nh->msys_uptime)/1000,
    370  1.1.1.4  christos 	       EXTRACT_32BITS(&nh->msys_uptime)%1000,
    371  1.1.1.4  christos 	       EXTRACT_32BITS(&nh->utc_sec), EXTRACT_32BITS(&nh->utc_nsec)));
    372  1.1.1.4  christos 
    373  1.1.1.4  christos 	ND_PRINT((ndo, "#%u, ", EXTRACT_32BITS(&nh->sequence)));
    374  1.1.1.4  christos 	nr = (const struct nfrec_v6 *)&nh[1];
    375  1.1.1.4  christos 
    376  1.1.1.4  christos 	ND_PRINT((ndo, "%2u recs", nrecs));
    377  1.1.1.4  christos 
    378  1.1.1.4  christos 	for (; nrecs != 0; nr++, nrecs--) {
    379  1.1.1.4  christos 		char buf[20];
    380  1.1.1.4  christos 		char asbuf[20];
    381  1.1.1.4  christos 
    382  1.1.1.4  christos 		/*
    383  1.1.1.4  christos 		 * Make sure we have the entire record.
    384  1.1.1.4  christos 		 */
    385  1.1.1.4  christos 		ND_TCHECK(*nr);
    386  1.1.1.4  christos 		ND_PRINT((ndo, "\n  started %u.%03u, last %u.%03u",
    387  1.1.1.4  christos 		       EXTRACT_32BITS(&nr->start_time)/1000,
    388  1.1.1.4  christos 		       EXTRACT_32BITS(&nr->start_time)%1000,
    389  1.1.1.4  christos 		       EXTRACT_32BITS(&nr->last_time)/1000,
    390  1.1.1.4  christos 		       EXTRACT_32BITS(&nr->last_time)%1000));
    391  1.1.1.4  christos 
    392  1.1.1.4  christos 		asbuf[0] = buf[0] = '\0';
    393  1.1.1.4  christos 		snprintf(buf, sizeof(buf), "/%u", nr->src_mask);
    394  1.1.1.4  christos 		snprintf(asbuf, sizeof(asbuf), ":%u",
    395  1.1.1.4  christos 			EXTRACT_16BITS(&nr->src_as));
    396  1.1.1.4  christos 		ND_PRINT((ndo, "\n    %s%s%s:%u ", intoa(nr->src_ina.s_addr), buf, asbuf,
    397  1.1.1.4  christos 			EXTRACT_16BITS(&nr->srcport)));
    398  1.1.1.4  christos 
    399  1.1.1.4  christos 		snprintf(buf, sizeof(buf), "/%d", nr->dst_mask);
    400  1.1.1.4  christos 		snprintf(asbuf, sizeof(asbuf), ":%u",
    401  1.1.1.4  christos 			 EXTRACT_16BITS(&nr->dst_as));
    402  1.1.1.4  christos 		ND_PRINT((ndo, "> %s%s%s:%u ", intoa(nr->dst_ina.s_addr), buf, asbuf,
    403  1.1.1.4  christos 			EXTRACT_16BITS(&nr->dstport)));
    404  1.1.1.4  christos 
    405  1.1.1.4  christos 		ND_PRINT((ndo, ">> %s\n    ", intoa(nr->nhop_ina.s_addr)));
    406  1.1.1.4  christos 
    407  1.1.1.4  christos 		pent = getprotobynumber(nr->proto);
    408  1.1.1.4  christos 		if (!pent || ndo->ndo_nflag)
    409  1.1.1.4  christos 			ND_PRINT((ndo, "%u ", nr->proto));
    410  1.1.1.4  christos 		else
    411  1.1.1.4  christos 			ND_PRINT((ndo, "%s ", pent->p_name));
    412  1.1.1.4  christos 
    413  1.1.1.4  christos 		/* tcp flags for tcp only */
    414  1.1.1.4  christos 		if (pent && pent->p_proto == IPPROTO_TCP) {
    415  1.1.1.4  christos 			int flags;
    416  1.1.1.4  christos 			flags = nr->tcp_flags;
    417  1.1.1.4  christos 			ND_PRINT((ndo, "%s%s%s%s%s%s%s",
    418  1.1.1.4  christos 				flags & TH_FIN  ? "F" : "",
    419  1.1.1.4  christos 				flags & TH_SYN  ? "S" : "",
    420  1.1.1.4  christos 				flags & TH_RST  ? "R" : "",
    421  1.1.1.4  christos 				flags & TH_PUSH ? "P" : "",
    422  1.1.1.4  christos 				flags & TH_ACK  ? "A" : "",
    423  1.1.1.4  christos 				flags & TH_URG  ? "U" : "",
    424  1.1.1.4  christos 				flags           ? " " : ""));
    425      1.1  christos 		}
    426  1.1.1.4  christos 
    427  1.1.1.4  christos 		buf[0]='\0';
    428  1.1.1.4  christos 		snprintf(buf, sizeof(buf), "(%u<>%u encaps)",
    429  1.1.1.4  christos 			 (EXTRACT_16BITS(&nr->flags) >> 8) & 0xff,
    430  1.1.1.4  christos 			 (EXTRACT_16BITS(&nr->flags)) & 0xff);
    431  1.1.1.3  christos 		ND_PRINT((ndo, "tos %u, %u (%u octets) %s",
    432  1.1.1.4  christos 		       nr->tos,
    433      1.1  christos 		       EXTRACT_32BITS(&nr->packets),
    434  1.1.1.3  christos 		       EXTRACT_32BITS(&nr->octets), buf));
    435      1.1  christos 	}
    436  1.1.1.4  christos 	return;
    437  1.1.1.4  christos 
    438  1.1.1.4  christos trunc:
    439  1.1.1.4  christos 	ND_PRINT((ndo, "[|cnfp]"));
    440  1.1.1.4  christos 	return;
    441  1.1.1.4  christos }
    442  1.1.1.4  christos 
    443  1.1.1.4  christos void
    444  1.1.1.4  christos cnfp_print(netdissect_options *ndo, const u_char *cp)
    445  1.1.1.4  christos {
    446  1.1.1.4  christos 	int ver;
    447  1.1.1.4  christos 
    448  1.1.1.4  christos 	/*
    449  1.1.1.4  christos 	 * First 2 bytes are the version number.
    450  1.1.1.4  christos 	 */
    451  1.1.1.4  christos 	ND_TCHECK2(*cp, 2);
    452  1.1.1.4  christos 	ver = EXTRACT_16BITS(cp);
    453  1.1.1.4  christos 	switch (ver) {
    454  1.1.1.4  christos 
    455  1.1.1.4  christos 	case 1:
    456  1.1.1.4  christos 		cnfp_v1_print(ndo, cp);
    457  1.1.1.4  christos 		break;
    458  1.1.1.4  christos 
    459  1.1.1.4  christos 	case 5:
    460  1.1.1.4  christos 		cnfp_v5_print(ndo, cp);
    461  1.1.1.4  christos 		break;
    462  1.1.1.4  christos 
    463  1.1.1.4  christos 	case 6:
    464  1.1.1.4  christos 		cnfp_v6_print(ndo, cp);
    465  1.1.1.4  christos 		break;
    466  1.1.1.4  christos 
    467  1.1.1.4  christos 	default:
    468  1.1.1.4  christos 		ND_PRINT((ndo, "NetFlow v%x", ver));
    469  1.1.1.4  christos 		break;
    470  1.1.1.4  christos 	}
    471  1.1.1.4  christos 	return;
    472  1.1.1.4  christos 
    473  1.1.1.4  christos trunc:
    474  1.1.1.4  christos 	ND_PRINT((ndo, "[|cnfp]"));
    475  1.1.1.4  christos 	return;
    476      1.1  christos }
    477