1a752e82dSGleb Smirnoff /*- 2a752e82dSGleb Smirnoff * Copyright (c) 2004 Gleb Smirnoff <glebius@cell.sick.ru> 3a752e82dSGleb Smirnoff * All rights reserved. 4a752e82dSGleb Smirnoff * 5a752e82dSGleb Smirnoff * Redistribution and use in source and binary forms, with or without 6a752e82dSGleb Smirnoff * modification, are permitted provided that the following conditions 7a752e82dSGleb Smirnoff * are met: 8a752e82dSGleb Smirnoff * 1. Redistributions of source code must retain the above copyright 9a752e82dSGleb Smirnoff * notice, this list of conditions and the following disclaimer. 10a752e82dSGleb Smirnoff * 2. Redistributions in binary form must reproduce the above copyright 11a752e82dSGleb Smirnoff * notice, this list of conditions and the following disclaimer in the 12a752e82dSGleb Smirnoff * documentation and/or other materials provided with the distribution. 13a752e82dSGleb Smirnoff * 3. All advertising materials mentioning features or use of this software 14a752e82dSGleb Smirnoff * must display the following acknowledgement: 15a752e82dSGleb Smirnoff * This product includes software developed by Gleb Smirnoff and 16a752e82dSGleb Smirnoff * contributors. 17a752e82dSGleb Smirnoff * 4. Neither the name of the author nor the names of its contributors 18a752e82dSGleb Smirnoff * may be used to endorse or promote products derived from this software 19a752e82dSGleb Smirnoff * without specific prior written permission. 20a752e82dSGleb Smirnoff * 21a752e82dSGleb Smirnoff * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 22a752e82dSGleb Smirnoff * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23a752e82dSGleb Smirnoff * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24a752e82dSGleb Smirnoff * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 25a752e82dSGleb Smirnoff * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26a752e82dSGleb Smirnoff * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27a752e82dSGleb Smirnoff * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28a752e82dSGleb Smirnoff * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29a752e82dSGleb Smirnoff * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30a752e82dSGleb Smirnoff * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31a752e82dSGleb Smirnoff * SUCH DAMAGE. 32a752e82dSGleb Smirnoff * 33a752e82dSGleb Smirnoff * $SourceForge: netflow.h,v 1.8 2004/09/16 17:05:11 glebius Exp $ 34a752e82dSGleb Smirnoff * $FreeBSD$ 35a752e82dSGleb Smirnoff */ 36a752e82dSGleb Smirnoff 37a752e82dSGleb Smirnoff /* netflow timeouts in seconds */ 38a752e82dSGleb Smirnoff 39a752e82dSGleb Smirnoff #define ACTIVE_TIMEOUT (30*60) /* maximum flow lifetime is 30 min */ 40a752e82dSGleb Smirnoff #define INACTIVE_TIMEOUT 15 41a752e82dSGleb Smirnoff 42a752e82dSGleb Smirnoff /* More info can be found in these two Cisco documents: 43a752e82dSGleb Smirnoff * http://www.cisco.com/warp/public/cc/pd/iosw/ioft/neflct/tech/napps_wp.htm 44a752e82dSGleb Smirnoff * http://www.cisco.com/en/US/products/sw/netmgtsw/ps1964/prod_installation_guide09186a00800fea56.html#wp1006186 45a752e82dSGleb Smirnoff * However, they say quite different things. 46a752e82dSGleb Smirnoff */ 47a752e82dSGleb Smirnoff 48a752e82dSGleb Smirnoff #define NETFLOW_V1 1 49a752e82dSGleb Smirnoff #define NETFLOW_V5 5 50a752e82dSGleb Smirnoff 51a752e82dSGleb Smirnoff struct netflow_v1_header 52a752e82dSGleb Smirnoff { 53a752e82dSGleb Smirnoff uint16_t version; /* NetFlow version */ 54a752e82dSGleb Smirnoff uint16_t count; /* Number of records in flow */ 55a752e82dSGleb Smirnoff uint32_t sys_uptime; /* System uptime */ 56a752e82dSGleb Smirnoff uint32_t unix_secs; /* Current seconds since 0000 UTC 1970 */ 57a752e82dSGleb Smirnoff uint32_t unix_nsecs; /* Remaining nanoseconds since 0000 UTC 1970 */ 58a752e82dSGleb Smirnoff } __attribute__((__packed__)); 59a752e82dSGleb Smirnoff 60a752e82dSGleb Smirnoff struct netflow_v5_header 61a752e82dSGleb Smirnoff { 62a752e82dSGleb Smirnoff uint16_t version; /* NetFlow version */ 63a752e82dSGleb Smirnoff uint16_t count; /* Number of records in flow */ 64a752e82dSGleb Smirnoff uint32_t sys_uptime; /* System uptime */ 65a752e82dSGleb Smirnoff uint32_t unix_secs; /* Current seconds since 0000 UTC 1970 */ 66a752e82dSGleb Smirnoff uint32_t unix_nsecs; /* Remaining nanoseconds since 0000 UTC 1970 */ 67a752e82dSGleb Smirnoff uint32_t flow_seq; /* Sequence number of the first record */ 68a752e82dSGleb Smirnoff uint8_t engine_type; /* Type of flow switching engine (RP,VIP,etc.) */ 69a752e82dSGleb Smirnoff uint8_t engine_id; /* Slot number of the flow switching engine */ 70a752e82dSGleb Smirnoff uint16_t pad; /* Pad to word boundary */ 71a752e82dSGleb Smirnoff } __attribute__((__packed__)); 72a752e82dSGleb Smirnoff 73a752e82dSGleb Smirnoff struct netflow_v1_record 74a752e82dSGleb Smirnoff { 75a752e82dSGleb Smirnoff uint32_t src_addr; /* Source IP address */ 76a752e82dSGleb Smirnoff uint32_t dst_addr; /* Destination IP address */ 77a752e82dSGleb Smirnoff uint32_t next_hop; /* Next hop IP address */ 78a752e82dSGleb Smirnoff uint16_t in_ifx; /* Source interface index */ 79a752e82dSGleb Smirnoff uint16_t out_ifx; /* Destination interface index */ 80a752e82dSGleb Smirnoff uint32_t packets; /* Number of packets in a flow */ 81a752e82dSGleb Smirnoff uint32_t octets; /* Number of octets in a flow */ 82a752e82dSGleb Smirnoff uint32_t first; /* System uptime at start of a flow */ 83a752e82dSGleb Smirnoff uint32_t last; /* System uptime at end of a flow */ 84a752e82dSGleb Smirnoff uint16_t s_port; /* Source port */ 85a752e82dSGleb Smirnoff uint16_t d_port; /* Destination port */ 86a752e82dSGleb Smirnoff uint16_t pad1; /* Pad to word boundary */ 87a752e82dSGleb Smirnoff uint8_t prot; /* IP protocol */ 88a752e82dSGleb Smirnoff uint8_t tos; /* IP type of service */ 89a752e82dSGleb Smirnoff uint8_t flags; /* Cumulative OR of tcp flags */ 90a752e82dSGleb Smirnoff uint8_t pad2; /* pad to word boundary */ 91a752e82dSGleb Smirnoff uint16_t pad3; /* Pad to word boundary */ 92a752e82dSGleb Smirnoff uint8_t reserved[5]; /* Reserved for future use */ 93a752e82dSGleb Smirnoff } __attribute__((__packed__)); 94a752e82dSGleb Smirnoff 95a752e82dSGleb Smirnoff struct netflow_v5_record 96a752e82dSGleb Smirnoff { 97a752e82dSGleb Smirnoff uint32_t src_addr; /* Source IP address */ 98a752e82dSGleb Smirnoff uint32_t dst_addr; /* Destination IP address */ 99a752e82dSGleb Smirnoff uint32_t next_hop; /* Next hop IP address */ 100a752e82dSGleb Smirnoff uint16_t i_ifx; /* Source interface index */ 101a752e82dSGleb Smirnoff uint16_t o_ifx; /* Destination interface index */ 102a752e82dSGleb Smirnoff uint32_t packets; /* Number of packets in a flow */ 103a752e82dSGleb Smirnoff uint32_t octets; /* Number of octets in a flow */ 104a752e82dSGleb Smirnoff uint32_t first; /* System uptime at start of a flow */ 105a752e82dSGleb Smirnoff uint32_t last; /* System uptime at end of a flow */ 106a752e82dSGleb Smirnoff uint16_t s_port; /* Source port */ 107a752e82dSGleb Smirnoff uint16_t d_port; /* Destination port */ 108a752e82dSGleb Smirnoff uint8_t pad1; /* pad to word boundary */ 109a752e82dSGleb Smirnoff uint8_t flags; /* Cumulative OR of tcp flags */ 110a752e82dSGleb Smirnoff uint8_t prot; /* IP protocol */ 111a752e82dSGleb Smirnoff uint8_t tos; /* IP type of service */ 112a752e82dSGleb Smirnoff uint16_t src_as; /* Src peer/origin Autonomous System */ 113a752e82dSGleb Smirnoff uint16_t dst_as; /* Dst peer/origin Autonomous System */ 114a752e82dSGleb Smirnoff uint8_t src_mask; /* Source route's mask bits */ 115a752e82dSGleb Smirnoff uint8_t dst_mask; /* Destination route's mask bits */ 116a752e82dSGleb Smirnoff uint16_t pad2; /* Pad to word boundary */ 117a752e82dSGleb Smirnoff } __attribute__((__packed__)); 118a752e82dSGleb Smirnoff 119a752e82dSGleb Smirnoff #define NETFLOW_V1_MAX_RECORDS 24 120a752e82dSGleb Smirnoff #define NETFLOW_V5_MAX_RECORDS 30 121a752e82dSGleb Smirnoff 122a752e82dSGleb Smirnoff #define NETFLOW_V1_MAX_SIZE (sizeof(netflow_v1_header)+ \ 123a752e82dSGleb Smirnoff sizeof(netflow_v1_record)*NETFLOW_V1_MAX_RECORDS) 124a752e82dSGleb Smirnoff #define NETFLOW_V5_MAX_SIZE (sizeof(netflow_v5_header)+ \ 125a752e82dSGleb Smirnoff sizeof(netflow_v5_record)*NETFLOW_V5_MAX_RECORDS) 126