1
/*************************************************************************
2
*** Authentication, authorization, accounting + firewalling package
3
*** Copyright 1998-2002 Anton Vinokurov <anton@netams.com>
4
*** Copyright 2002-2008 NeTAMS Development Team
5
*** This code is GPL v3
6
*** For latest version and more info, visit this project web page
7
*** located at http://www.netams.com
9
*************************************************************************/
10
/* $Id: flow.c,v 1.130 2008-02-23 08:35:02 anton Exp $ */
19
Flow::Flow(u_char instance, const u_char slots, const struct attribute *new_list) {
23
if((list = (struct attribute *)aMalloc(sizeof(struct attribute)*slots)) == NULL)
25
if(new_list != NULL) {
26
bcopy(new_list, list, sizeof(struct attribute)*slots);
27
freeSlot = totalSlots = slots;
42
const int Flow::grow_list(u_char new_size) {
43
struct attribute *new_list;
46
new_size = totalSlots+1;
48
new_list = (struct attribute *)aMalloc(sizeof(struct attribute)*new_size);
54
bcopy(list, new_list, sizeof(struct attribute)*totalSlots);
57
aDebug(DEBUG_FLOW, "Flow %p growth from %u to %u slots\n", this, totalSlots, new_size);
58
totalSlots = new_size;
64
void* Flow::put(const u_char id, const union attribute_value *value) {
65
struct attribute *tmp;
68
if((list == NULL) && !grow_list())
71
if((freeSlot == totalSlots) && !grow_list())
74
tmp = &list[freeSlot++];
79
return (void*)&tmp->value;
82
const union attribute_value *Flow::get(const u_char id) {
85
if((i = index(id)) != -1)
86
return &list[i].value;
90
const int Flow::contains(const u_char id) {
91
return (index(id) == -1) ? 0 : 1;
94
const unsigned int Flow::elements() {
98
const int Flow::index(const u_char id) {
105
for(i = 0, idx = -1; i < freeSlot; i++)
106
if(list[i].id == id) {
113
void Flow::removeAll() {
121
bzero(list, sizeof(struct attribute)*freeSlot);
125
void Flow::copy(Flow *src) {
126
freeSlot = src->freeSlot;
128
if(freeSlot > totalSlots)
131
bcopy(src->list, list, sizeof(struct attribute)*freeSlot);
135
void Flow::Debug(u_char debug) {
136
union attribute_value *value;
137
char buf1[32], buf2[32];
139
aDebug(debug, "ds:%u flow:%p slots:%u\n",ds_id, this, freeSlot);
140
for(u_char i=0; i< freeSlot; i++) {
141
value = &list[i].value;
143
case ATTR_FLOW_INFO: {
144
struct flow_info_value *flow_info=(struct flow_info_value *)value;
145
aDebug(debug, "FLOW_INFO: packets:%lu octets:%llu flow_first:%lu flow_last:%lu direction:%u\n",
146
flow_info->packets, flow_info->octets, flow_info->flow_first, flow_info->flow_last, flow_info->direction);
149
case ATTR_IPV4_INFO: {
150
struct ipv4_info_value *ipv4_info=(struct ipv4_info_value*)value;
151
inet_ntop(AF_INET, &(ipv4_info->ip_src), buf1, 32);
152
inet_ntop(AF_INET, &(ipv4_info->ip_dst), buf2, 32);
153
aDebug(debug,"IPV4_INFO: ip_src:%s ip_dst:%s ip_p:%u ip_tos:%u\n",
154
buf1, buf2, ipv4_info->ip_p, ipv4_info->ip_tos);
157
case ATTR_TCP_INFO: {
158
struct tcp_info_value *tcp_info=(struct tcp_info_value*)value;
159
aDebug(debug, "TCP_INFO: src_port:%u dst_port:%u\n",
160
ntohs(tcp_info->src_port), ntohs(tcp_info->dst_port));
163
case ATTR_MAC_INFO: {
164
struct mac_info_value *mac_info=(struct mac_info_value*)value;
165
aDebug(debug, "MAC_INFO: src:%s dst:%s\n",
166
ether_ntoa((struct ether_addr*)mac_info->src), ether_ntoa((struct ether_addr*)mac_info->dst));
169
case ATTR_VLAN_INFO: {
170
struct vlan_info_value *vlan_info=(struct vlan_info_value*)value;
171
aDebug(debug, "VLAN_INFO: dot1x:%u\n",
172
ntohs(vlan_info->dot1x));
176
struct as_info_value *as_info=(struct as_info_value*)value;
177
inet_ntop(AF_INET, &(as_info->as_src), buf1, 32);
178
inet_ntop(AF_INET, &(as_info->as_dst), buf2, 32);
179
aDebug(debug, "AS_INFO: as_src:%s as_dst:%s\n",
183
case ATTR_IFINDEX_INFO: {
184
struct ifindex_info_value *ifindex_info=(struct ifindex_info_value*)value;
185
aDebug(debug, "IFINDEX_INFO: if_in:%u if_out:%u\n",
186
ntohs(ifindex_info->if_in), ntohs(ifindex_info->if_out));
189
case ATTR_MULTICAST_INFO: {
190
struct multicast_info_value *multicast_info=(struct multicast_info_value*)value;
191
aDebug(debug, "MULTICAST_INFO: dst_packets:%llu dst_bytes:%llu igmp_type:%u\n",
192
multicast_info->dst_packets, multicast_info->dst_bytes, multicast_info->igmp_type);
195
case ATTR_NEXTHOP_INFO: {
196
struct nexthop_info_value *nexthop_info=(struct nexthop_info_value*)value;
197
inet_ntop(AF_INET, &(nexthop_info->ipv4_nexthop), buf1, 32);
198
inet_ntop(AF_INET, &(nexthop_info->bgpv4_nexthop), buf2, 32);
199
aDebug(debug, "NEXTHOP_INFO: ipv4_nexthop:%s bgpv4_nexthop:%s\n",
203
case ATTR_LAYER7_INFO: {
204
struct layer7_info_value *layer7_info=(struct layer7_info_value*)value;
205
aDebug(debug, "LAYER7_INFO: type:%u value:%s\n",
206
layer7_info->type, layer7_info->value);
210
aDebug(debug, "UNKNOWN: id:%u\n", list[i].id);