1169689Skan/*- 2169689Skan * Copyright (c) 2010 Alexander V. Chernikov <melifaro@ipfw.ru> 3169689Skan * All rights reserved. 4169689Skan * 5169689Skan * Redistribution and use in source and binary forms, with or without 6169689Skan * modification, are permitted provided that the following conditions 7169689Skan * are met: 8169689Skan * 1. Redistributions of source code must retain the above copyright 9169689Skan * notice, this list of conditions and the following disclaimer. 10169689Skan * 2. Redistributions in binary form must reproduce the above copyright 11169689Skan * notice, this list of conditions and the following disclaimer in the 12169689Skan * documentation and/or other materials provided with the distribution. 13169689Skan * 14169689Skan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15169689Skan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16169689Skan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17169689Skan * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18169689Skan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19169689Skan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20169689Skan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21169689Skan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22169689Skan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23169689Skan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24169689Skan * SUCH DAMAGE. 25169689Skan * 26169689Skan * $FreeBSD: releng/11.0/sys/netgraph/netflow/netflow_v9.h 219182 2011-03-02 16:15:11Z glebius $ 27169689Skan */ 28169689Skan 29169689Skan#ifndef _NETFLOW_V9_H_ 30169689Skan#define _NETFLOW_V9_H_ 31169689Skan 32169689Skan#ifdef COUNTERS_64 33169689Skan#define CNTR uint64_t 34169689Skan#define CNTR_MAX UINT64_MAX 35169689Skan#else 36169689Skan#define CNTR uint32_t 37169689Skan#define CNTR_MAX UINT_MAX 38169689Skan#endif 39169689Skan 40169689Skanstruct netflow_v9_template 41169689Skan{ 42169689Skan int field_id; 43169689Skan int field_length; 44169689Skan}; 45169689Skan 46169689Skan/* Template ID for tcp/udp v4 streams ID:257 (0x100 + NETFLOW_V9_FLOW_V4_L4) */ 47169689Skanstruct netflow_v9_record_ipv4_tcp 48169689Skan{ 49169689Skan uint32_t src_addr; /* Source IPv4 address (IPV4_SRC_ADDR) */ 50169689Skan uint32_t dst_addr; /* Destination IPv4 address (IPV4_DST_ADDR) */ 51169689Skan uint32_t next_hop; /* Next hop IPv4 address (IPV4_NEXT_HOP) */ 52169689Skan uint16_t i_ifx; /* Source interface index (INPUT_SNMP) */ 53169689Skan uint16_t o_ifx; /* Destination interface index (OUTPUT_SNMP) */ 54169689Skan CNTR i_packets; /* Number of incoming packets in a flow (IN_PKTS) */ 55169689Skan CNTR i_octets; /* Number of incoming octets in a flow (IN_BYTES) */ 56169689Skan CNTR o_packets; /* Number of outgoing packets in a flow (OUT_PKTS) */ 57169689Skan CNTR o_octets; /* Number of outgoing octets in a flow (OUT_BYTES) */ 58169689Skan uint32_t first; /* System uptime at start of a flow (FIRST_SWITCHED) */ 59169689Skan uint32_t last; /* System uptime at end of a flow (LAST_SWITCHED) */ 60169689Skan uint16_t s_port; /* Source port (L4_SRC_PORT) */ 61169689Skan uint16_t d_port; /* Destination port (L4_DST_PORT) */ 62169689Skan uint8_t flags; /* Cumulative OR of tcp flags (TCP_FLAGS) */ 63169689Skan uint8_t prot; /* IP protocol */ 64169689Skan uint8_t tos; /* IP type of service IN (or OUT) (TOS) */ 65169689Skan uint32_t src_as; /* Src peer/origin Autonomous System (SRC_AS) */ 66169689Skan uint32_t dst_as; /* Dst peer/origin Autonomous System (DST_AS) */ 67169689Skan uint8_t src_mask; /* Source route's mask bits (SRC_MASK) */ 68169689Skan uint8_t dst_mask; /* Destination route's mask bits (DST_MASK) */ 69169689Skan} __attribute__((__packed__)); 70169689Skan 71169689Skan/* Template ID for tcp/udp v6 streams ID: 260 (0x100 + NETFLOW_V9_FLOW_V6_L4) */ 72169689Skanstruct netflow_v9_record_ipv6_tcp 73169689Skan{ 74169689Skan struct in6_addr src_addr; /* Source IPv6 address (IPV6_SRC_ADDR) */ 75169689Skan struct in6_addr dst_addr; /* Destination IPv6 address (IPV6_DST_ADDR) */ 76169689Skan struct in6_addr next_hop; /* Next hop IPv6 address (IPV6_NEXT_HOP) */ 77169689Skan uint16_t i_ifx; /* Source interface index (INPUT_SNMP) */ 78169689Skan uint16_t o_ifx; /* Destination interface index (OUTPUT_SNMP) */ 79169689Skan CNTR i_packets; /* Number of incoming packets in a flow (IN_PKTS) */ 80169689Skan CNTR i_octets; /* Number of incoming octets in a flow (IN_BYTES) */ 81169689Skan CNTR o_packets; /* Number of outgoing packets in a flow (OUT_PKTS) */ 82169689Skan CNTR o_octets; /* Number of outgoing octets in a flow (OUT_BYTES) */ 83169689Skan uint32_t first; /* System uptime at start of a flow (FIRST_SWITCHED) */ 84169689Skan uint32_t last; /* System uptime at end of a flow (LAST_SWITCHED) */ 85169689Skan uint16_t s_port; /* Source port (L4_SRC_PORT) */ 86169689Skan uint16_t d_port; /* Destination port (L4_DST_PORT) */ 87169689Skan uint8_t flags; /* Cumulative OR of tcp flags (TCP_FLAGS) */ 88169689Skan uint8_t prot; /* IP protocol */ 89169689Skan uint8_t tos; /* IP type of service IN (or OUT) (TOS) */ 90169689Skan uint32_t src_as; /* Src peer/origin Autonomous System (SRC_AS) */ 91169689Skan uint32_t dst_as; /* Dst peer/origin Autonomous System (DST_AS) */ 92169689Skan uint8_t src_mask; /* Source route's mask bits (SRC_MASK) */ 93169689Skan uint8_t dst_mask; /* Destination route's mask bits (DST_MASK) */ 94169689Skan} __attribute__((__packed__)); 95169689Skan 96169689Skan/* Used in export9_add to determine max record size */ 97169689Skanstruct netflow_v9_record_general 98169689Skan{ 99169689Skan union { 100169689Skan struct netflow_v9_record_ipv4_tcp v4_tcp; 101169689Skan struct netflow_v9_record_ipv6_tcp v6_tcp; 102169689Skan } rec; 103169689Skan}; 104169689Skan 105169689Skan#define BASE_MTU 1500 106169689Skan#define MIN_MTU sizeof(struct netflow_v5_header) 107169689Skan#define MAX_MTU 16384 108169689Skan#define NETFLOW_V9_MAX_SIZE _NETFLOW_V9_MAX_SIZE(BASE_MTU) 109169689Skan/* Decrease MSS by 16 since there can be some IPv[46] header options */ 110169689Skan#define _NETFLOW_V9_MAX_SIZE(x) (x) - sizeof(struct ip6_hdr) - sizeof(struct udphdr) - 16 111169689Skan 112169689Skan/* #define NETFLOW_V9_MAX_FLOWSETS 2 */ 113169689Skan 114169689Skan#define NETFLOW_V9_MAX_RECORD_SIZE sizeof(struct netflow_v9_record_ipv6_tcp) 115169689Skan#define NETFLOW_V9_MAX_PACKETS_TEMPL 500 /* Send data templates every ... packets */ 116169689Skan#define NETFLOW_V9_MAX_TIME_TEMPL 600 /* Send data templates every ... seconds */ 117169689Skan#define NETFLOW_V9_MAX_TEMPLATES 16 /* Not a real value */ 118169689Skan#define _NETFLOW_V9_TEMPLATE_SIZE(x) (sizeof(x) / sizeof(struct netflow_v9_template)) * 4 119169689Skan//#define _NETFLOW_V9_TEMPLATE_SIZE(x) ((x) + 1) * 4 120169689Skan 121169689Skan/* Flow Templates */ 122169689Skan#define NETFLOW_V9_FLOW_V4_L4 1 /* IPv4 TCP/UDP packet */ 123169689Skan#define NETFLOW_V9_FLOW_V4_ICMP 2 /* IPv4 ICMP packet, currently unused */ 124169689Skan#define NETFLOW_V9_FLOW_V4_L3 3 /* IPv4 IP packet */ 125169689Skan#define NETFLOW_V9_FLOW_V6_L4 4 /* IPv6 TCP/UDP packet */ 126169689Skan#define NETFLOW_V9_FLOW_V6_ICMP 5 /* IPv6 ICMP packet, currently unused */ 127169689Skan#define NETFLOW_V9_FLOW_V6_L3 6 /* IPv6 IP packet */ 128169689Skan 129169689Skan#define NETFLOW_V9_FLOW_FAKE 65535 /* Not uset used in real flowsets! */ 130169689Skan 131169689Skanstruct netflow_v9_export_dgram { 132169689Skan struct netflow_v9_header header; 133169689Skan char *data; /* MTU can change, record length is dynamic */ 134169689Skan}; 135169689Skan 136169689Skanstruct netflow_v9_flowset_header { 137169689Skan uint16_t id; /* FlowSet id */ 138169689Skan uint16_t length; /* FlowSet length */ 139169689Skan} __attribute__((__packed__)); 140169689Skan 141169689Skanstruct netflow_v9_packet_opt { 142169689Skan uint16_t length; /* current packet length */ 143169689Skan uint16_t count; /* current records count */ 144169689Skan uint16_t mtu; /* max MTU shapshot */ 145169689Skan uint16_t flow_type; /* current flowset */ 146169689Skan uint16_t flow_header; /* offset pointing to current flow header */ 147169689Skan}; 148169689Skan#endif 149169689Skan