1 /* 2 pmacct (Promiscuous mode IP Accounting package) 3 pmacct is Copyright (C) 2003-2019 by Paolo Lucente 4 */ 5 6 /* 7 This program is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 2 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program; if not, write to the Free Software 19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 */ 21 22 #ifndef XFLOW_STATUS_H 23 #define XFLOW_STATUS_H 24 25 /* defines */ 26 #define XFLOW_RESET_BOUNDARY 50 27 #define XFLOW_STATUS_TABLE_SZ 9973 28 #define XFLOW_STATUS_TABLE_MAX_ENTRIES 100000 29 30 /* structures */ 31 struct xflow_status_entry_counters 32 { 33 // XXX: change to 64 bit? 34 u_int32_t good; 35 u_int32_t jumps_f; 36 u_int32_t jumps_b; 37 38 u_int64_t total; 39 u_int64_t bytes; 40 }; 41 42 struct xflow_status_entry_sampling 43 { 44 u_int32_t interface; /* sFlow/NetFlow v9: interface generating the sample */ 45 u_int32_t sample_pool; /* sampling rate */ 46 u_int32_t seqno; /* sFlow: flow samples sequence number */ 47 u_int32_t sampler_id; /* NetFlow v9: flow sampler ID field */ 48 struct xflow_status_entry_sampling *next; 49 }; 50 51 struct xflow_status_entry_class 52 { 53 pm_class_t class_id; /* NetFlow v9: classfier ID field */ 54 pm_class_t class_int_id; /* NetFlow v9: internal classfier ID field */ 55 char class_name[MAX_PROTOCOL_LEN]; /* NetFlow v9: classfier name field */ 56 struct xflow_status_entry_class *next; 57 }; 58 59 struct xflow_status_map_cache 60 { 61 pm_id_t tag; 62 pm_id_t tag2; 63 s_uint16_t port; /* BGP port */ 64 int ret; 65 struct timeval stamp; 66 }; 67 68 struct xflow_status_entry 69 { 70 struct host_addr agent_addr; /* NetFlow/IPFIX: socket IP address 71 sFlow: agentID IP address */ 72 struct host_addr exp_addr; /* NetFlow/IPFIX: exporter IP address, ie. #130/#131 (host_addr struct) */ 73 struct sockaddr exp_sa; /* NetFlow/IPFIX: exporter IP address, ie. #130/#131 (sockaddr struct) */ 74 u_int32_t seqno; /* Sequence number */ 75 u_int32_t aux1; /* Some more distinguishing fields: 76 NetFlow v5: Engine Type + Engine ID 77 NetFlow v9: Source ID 78 IPFIX: ObservedDomainID 79 sFlow v5: agentSubID */ 80 u_int32_t aux2; /* Some more distinguishing (internal) flags */ 81 u_int16_t inc; /* increment, NetFlow v5: required by flow sequence number */ 82 u_int32_t peer_v4_idx; /* last known BGP peer index for ipv4 address family */ 83 u_int32_t peer_v6_idx; /* last known BGP peer index for ipv6 address family */ 84 struct xflow_status_map_cache bta_v4; /* last known bgp_agent_map IPv4 result */ 85 struct xflow_status_map_cache bta_v6; /* last known bgp_agent_map IPv6 result */ 86 struct xflow_status_map_cache st; /* last known sampling_map result */ 87 struct xflow_status_entry_counters counters; 88 struct xflow_status_entry_sampling *sampling; 89 struct xflow_status_entry_class *class; 90 void *sf_cnt; /* struct (ab)used for sFlow counters logging */ 91 struct xflow_status_entry *next; 92 }; 93 94 /* prototypes */ 95 extern u_int32_t hash_status_table(u_int32_t, struct sockaddr *, u_int32_t); 96 extern struct xflow_status_entry *search_status_table(struct sockaddr *, u_int32_t, u_int32_t, int, int); 97 extern void update_good_status_table(struct xflow_status_entry *, u_int32_t); 98 extern void update_bad_status_table(struct xflow_status_entry *); 99 extern void print_status_table(time_t, int); 100 extern struct xflow_status_entry_sampling *search_smp_if_status_table(struct xflow_status_entry_sampling *, u_int32_t); 101 extern struct xflow_status_entry_sampling *search_smp_id_status_table(struct xflow_status_entry_sampling *, u_int32_t, u_int8_t); 102 extern struct xflow_status_entry_sampling *create_smp_entry_status_table(struct xflow_status_entry *); 103 extern struct xflow_status_entry_class *search_class_id_status_table(struct xflow_status_entry_class *, pm_class_t); 104 extern struct xflow_status_entry_class *create_class_entry_status_table(struct xflow_status_entry *); 105 106 extern struct xflow_status_entry *xflow_status_table[XFLOW_STATUS_TABLE_SZ]; 107 extern u_int32_t xflow_status_table_entries; 108 extern u_int8_t xflow_status_table_error; 109 extern u_int32_t xflow_tot_bad_datagrams; 110 extern u_int8_t smp_entry_status_table_memerr, class_entry_status_table_memerr; 111 extern void set_vector_f_status(struct packet_ptrs_vector *); 112 extern void set_vector_f_status_g(struct packet_ptrs_vector *); 113 extern void update_status_table(struct xflow_status_entry *, u_int32_t, int); 114 115 #endif // XFLOW_STATUS_H 116