-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsflow_collect.c
More file actions
3873 lines (3386 loc) · 129 KB
/
sflow_collect.c
File metadata and controls
3873 lines (3386 loc) · 129 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* nProbe - a Netflow v5/v9/IPFIX probe for IPv4/v6
*
* Copyright (C) 2009-13 Luca Deri <deri@ntop.org>
*
* http://www.ntop.org/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/*
* ntop includes sFlow(TM), freely available from http://www.inmon.com/".
*
* Some code has been copied from the InMon sflowtool
*/
#include "f2k.h"
/* #define DEBUG_FLOWS */
#define INET6 1
uint32_t numsFlowsV2Rcvd = 0, numsFlowsV4Rcvd = 0, numsFlowsV5Rcvd = 0, numBadsFlowsVersionsRcvd = 0;
typedef struct {
uint32_t addr;
} SFLIPv4;
typedef struct {
uint8_t addr[16];
} SFLIPv6;
typedef union _SFLAddress_value {
SFLIPv4 ip_v4;
SFLIPv6 ip_v6;
} SFLAddress_value;
enum SFLAddress_type {
SFLADDRESSTYPE_UNDEFINED = 0,
SFLADDRESSTYPE_IP_V4 = 1,
SFLADDRESSTYPE_IP_V6 = 2
};
typedef struct _SFLAddress {
uint32_t type; /* enum SFLAddress_type */
SFLAddress_value address;
} SFLAddress;
/* Packet header data */
#define SFL_DEFAULT_HEADER_SIZE 128
#define SFL_DEFAULT_COLLECTOR_PORT 6343
#define SFL_DEFAULT_SAMPLING_RATE 400
/* The header protocol describes the format of the sampled header */
enum SFLHeader_protocol {
SFLHEADER_ETHERNET_ISO8023 = 1,
SFLHEADER_ISO88024_TOKENBUS = 2,
SFLHEADER_ISO88025_TOKENRING = 3,
SFLHEADER_FDDI = 4,
SFLHEADER_FRAME_RELAY = 5,
SFLHEADER_X25 = 6,
SFLHEADER_PPP = 7,
SFLHEADER_SMDS = 8,
SFLHEADER_AAL5 = 9,
SFLHEADER_AAL5_IP = 10, /* e.g. Cisco AAL5 mux */
SFLHEADER_IPv4 = 11,
SFLHEADER_IPv6 = 12,
SFLHEADER_MPLS = 13,
SFLHEADER_POS = 14,
SFLHEADER_IEEE80211MAC = 15,
SFLHEADER_IEEE80211_AMPDU = 16,
SFLHEADER_IEEE80211_AMSDU_SUBFRAME = 17
};
/* raw sampled header */
typedef struct _SFLSampled_header {
uint32_t header_protocol; /* (enum SFLHeader_protocol) */
uint32_t frame_length; /* Original length of packet before sampling */
uint32_t stripped; /* header/trailer bytes stripped by sender */
uint32_t header_length; /* length of sampled header bytes to follow */
uint8_t *header_bytes; /* Header bytes */
} SFLSampled_header;
/* decoded ethernet header */
typedef struct _SFLSampled_ethernet {
uint32_t eth_len; /* The length of the MAC packet excluding
lower layer encapsulations */
uint8_t src_mac[8]; /* 6 bytes + 2 pad */
uint8_t dst_mac[8];
uint32_t eth_type;
} SFLSampled_ethernet;
/* decoded IP version 4 header */
typedef struct _SFLSampled_ipv4 {
uint32_t length; /* The length of the IP packet
excluding lower layer encapsulations */
uint32_t protocol; /* IP Protocol type (for example, TCP = 6, UDP = 17) */
SFLIPv4 src_ip; /* Source IP Address */
SFLIPv4 dst_ip; /* Destination IP Address */
uint32_t src_port; /* TCP/UDP source port number or equivalent */
uint32_t dst_port; /* TCP/UDP destination port number or equivalent */
uint32_t tcp_flags; /* TCP flags */
uint32_t tos; /* IP type of service */
} SFLSampled_ipv4;
/* decoded IP version 6 data */
typedef struct _SFLSampled_ipv6 {
uint32_t length; /* The length of the IP packet
excluding lower layer encapsulations */
uint32_t protocol; /* IP Protocol type (for example, TCP = 6, UDP = 17) */
SFLIPv6 src_ip; /* Source IP Address */
SFLIPv6 dst_ip; /* Destination IP Address */
uint32_t src_port; /* TCP/UDP source port number or equivalent */
uint32_t dst_port; /* TCP/UDP destination port number or equivalent */
uint32_t tcp_flags; /* TCP flags */
uint32_t priority; /* IP priority */
} SFLSampled_ipv6;
/* Extended data types */
/* Extended switch data */
typedef struct _SFLExtended_switch {
uint32_t src_vlan; /* The 802.1Q VLAN id of incomming frame */
uint32_t src_priority; /* The 802.1p priority */
uint32_t dst_vlan; /* The 802.1Q VLAN id of outgoing frame */
uint32_t dst_priority; /* The 802.1p priority */
} SFLExtended_switch;
/* Extended router data */
typedef struct _SFLExtended_router {
SFLAddress nexthop; /* IP address of next hop router */
uint32_t src_mask; /* Source address prefix mask bits */
uint32_t dst_mask; /* Destination address prefix mask bits */
} SFLExtended_router;
/* Extended gateway data */
enum SFLExtended_as_path_segment_type {
SFLEXTENDED_AS_SET = 1, /* Unordered set of ASs */
SFLEXTENDED_AS_SEQUENCE = 2 /* Ordered sequence of ASs */
};
typedef struct _SFLExtended_as_path_segment {
uint32_t type; /* enum SFLExtended_as_path_segment_type */
uint32_t length; /* number of AS numbers in set/sequence */
union {
uint32_t *set;
uint32_t *seq;
} as;
} SFLExtended_as_path_segment;
typedef struct _SFLExtended_gateway {
SFLAddress nexthop; /* Address of the border router that should
be used for the destination network */
uint32_t as; /* AS number for this gateway */
uint32_t src_as; /* AS number of source (origin) */
uint32_t src_peer_as; /* AS number of source peer */
uint32_t dst_as_path_segments; /* number of segments in path */
SFLExtended_as_path_segment *dst_as_path; /* list of seqs or sets */
uint32_t communities_length; /* number of communities */
uint32_t *communities; /* set of communities */
uint32_t localpref; /* LocalPref associated with this route */
} SFLExtended_gateway;
typedef struct _SFLString {
uint32_t len;
char *str;
} SFLString;
/* Extended user data */
typedef struct _SFLExtended_user {
uint32_t src_charset; /* MIBEnum value of character set used to encode a string - See RFC 2978
Where possible UTF-8 encoding (MIBEnum=106) should be used. A value
of zero indicates an unknown encoding. */
SFLString src_user;
uint32_t dst_charset;
SFLString dst_user;
} SFLExtended_user;
/* Extended URL data */
enum SFLExtended_url_direction {
SFLEXTENDED_URL_SRC = 1, /* URL is associated with source address */
SFLEXTENDED_URL_DST = 2 /* URL is associated with destination address */
};
typedef struct _SFLExtended_url {
uint32_t direction; /* enum SFLExtended_url_direction */
SFLString url; /* URL associated with the packet flow.
Must be URL encoded */
SFLString host; /* The host field from the HTTP header */
} SFLExtended_url;
/* Extended MPLS data */
typedef struct _SFLLabelStack {
uint32_t depth;
uint32_t *stack; /* first entry is top of stack - see RFC 3032 for encoding */
} SFLLabelStack;
typedef struct _SFLExtended_mpls {
SFLAddress nextHop; /* Address of the next hop */
SFLLabelStack in_stack;
SFLLabelStack out_stack;
} SFLExtended_mpls;
/* Extended NAT data
Packet header records report addresses as seen at the sFlowDataSource.
The extended_nat structure reports on translated source and/or destination
addesses for this packet. If an address was not translated it should
be equal to that reported for the header. */
typedef struct _SFLExtended_nat {
SFLAddress src; /* Source address */
SFLAddress dst; /* Destination address */
} SFLExtended_nat;
/* additional Extended MPLS stucts */
typedef struct _SFLExtended_mpls_tunnel {
SFLString tunnel_lsp_name; /* Tunnel name */
uint32_t tunnel_id; /* Tunnel ID */
uint32_t tunnel_cos; /* Tunnel COS value */
} SFLExtended_mpls_tunnel;
typedef struct _SFLExtended_mpls_vc {
SFLString vc_instance_name; /* VC instance name */
uint32_t vll_vc_id; /* VLL/VC instance ID */
uint32_t vc_label_cos; /* VC Label COS value */
} SFLExtended_mpls_vc;
/* Extended MPLS FEC
- Definitions from MPLS-FTN-STD-MIB mplsFTNTable */
typedef struct _SFLExtended_mpls_FTN {
SFLString mplsFTNDescr;
uint32_t mplsFTNMask;
} SFLExtended_mpls_FTN;
/* Extended MPLS LVP FEC
- Definition from MPLS-LDP-STD-MIB mplsFecTable
Note: mplsFecAddrType, mplsFecAddr information available
from packet header */
typedef struct _SFLExtended_mpls_LDP_FEC {
uint32_t mplsFecAddrPrefixLength;
} SFLExtended_mpls_LDP_FEC;
/* Extended VLAN tunnel information
Record outer VLAN encapsulations that have
been stripped. extended_vlantunnel information
should only be reported if all the following conditions are satisfied:
1. The packet has nested vlan tags, AND
2. The reporting device is VLAN aware, AND
3. One or more VLAN tags have been stripped, either
because they represent proprietary encapsulations, or
because switch hardware automatically strips the outer VLAN
encapsulation.
Reporting extended_vlantunnel information is not a substitute for
reporting extended_switch information. extended_switch data must
always be reported to describe the ingress/egress VLAN information
for the packet. The extended_vlantunnel information only applies to
nested VLAN tags, and then only when one or more tags has been
stripped. */
typedef SFLLabelStack SFLVlanStack;
typedef struct _SFLExtended_vlan_tunnel {
SFLVlanStack stack; /* List of stripped 802.1Q TPID/TCI layers. Each
TPID,TCI pair is represented as a single 32 bit
integer. Layers listed from outermost to
innermost. */
} SFLExtended_vlan_tunnel;
////////////////// IEEE 802.11 Extension structs ////////////////////
/* The 4-byte cipher_suite identifier follows the format of the cipher suite
selector value from the 802.11i (TKIP/CCMP amendment to 802.11i)
The most significant three bytes contain the OUI and the least significant
byte contains the Suite Type.
The currently assigned values are:
OUI |Suite type |Meaning
----------------------------------------------------
00-0F-AC | 0 | Use group cipher suite
00-0F-AC | 1 | WEP-40
00-0F-AC | 2 | TKIP
00-0F-AC | 3 | Reserved
00-0F-AC | 4 | CCMP
00-0F-AC | 5 | WEP-104
00-0F-AC | 6-255 | Reserved
Vendor OUI | Other | Vendor specific
Other | Any | Reserved
----------------------------------------------------
*/
typedef uint32_t SFLCipherSuite;
/* Extended wifi Payload
Used to provide unencrypted version of 802.11 MAC data. If the
MAC data is not encrypted then the agent must not include an
extended_wifi_payload structure.
If 802.11 MAC data is encrypted then the sampled_header structure
should only contain the MAC header (since encrypted data cannot
be decoded by the sFlow receiver). If the sFlow agent has access to
the unencrypted payload, it should add an extended_wifi_payload
structure containing the unencrypted data bytes from the sampled
packet header, starting at the beginning of the 802.2 LLC and not
including any trailing encryption footers. */
/* opaque = flow_data; enterprise = 0; format = 1013 */
typedef struct _SFLExtended_wifi_payload {
SFLCipherSuite cipherSuite;
SFLSampled_header header;
} SFLExtended_wifi_payload;
typedef enum {
IEEE80211_A=1,
IEEE80211_B=2,
IEEE80211_G=3,
IEEE80211_N=4,
} SFL_IEEE80211_version;
/* opaque = flow_data; enterprise = 0; format = 1014 */
#define SFL_MAX_SSID_LEN 256
typedef struct _SFLExtended_wifi_rx {
uint32_t ssid_len;
char *ssid;
char bssid[6]; /* BSSID */
SFL_IEEE80211_version version; /* version */
uint32_t channel; /* channel number */
uint64_t speed;
uint32_t rsni; /* received signal to noise ratio, see dot11FrameRprtRSNI */
uint32_t rcpi; /* received channel power, see dot11FrameRprtLastRCPI */
uint32_t packet_duration_us; /* amount of time that the successfully received pkt occupied RF medium.*/
} SFLExtended_wifi_rx;
/* opaque = flow_data; enterprise = 0; format = 1015 */
typedef struct _SFLExtended_wifi_tx {
uint32_t ssid_len;
char *ssid; /* SSID string */
char bssid[6]; /* BSSID */
SFL_IEEE80211_version version; /* version */
uint32_t transmissions; /* number of transmissions for sampled
packet.
0 = unkown
1 = packet was successfully transmitted
on first attempt
n > 1 = n - 1 retransmissions */
uint32_t packet_duration_us; /* amount of time that the successfully
transmitted packet occupied the
RF medium */
uint32_t retrans_duration_us; /* amount of time that failed transmission
attempts occupied the RF medium */
uint32_t channel; /* channel number */
uint64_t speed;
uint32_t power_mw; /* transmit power in mW. */
} SFLExtended_wifi_tx;
/* Extended 802.11 Aggregation Data */
/* A flow_sample of an aggregated frame would consist of a packet
header for the whole frame + any other extended structures that
apply (e.g. 80211_tx/rx etc.) + an extended_wifi_aggregation
structure which would contain an array of pdu structures (one
for each PDU in the aggregate). A pdu is simply an array of
flow records, in the simplest case a packet header for each PDU,
but extended structures could be included as well. */
/* opaque = flow_data; enterprise = 0; format = 1016 */
struct _SFLFlow_Pdu; // forward decl
typedef struct _SFLExtended_aggregation {
uint32_t num_pdus;
struct _SFFlow_Pdu *pdus;
} SFLExtended_aggregation;
/* Extended socket information,
Must be filled in for all application transactions associated with a network socket
Omit if transaction associated with non-network IPC */
/* IPv4 Socket */
/* opaque = flow_data; enterprise = 0; format = 2100 */
typedef struct _SFLExtended_socket_ipv4 {
uint32_t protocol; /* IP Protocol (e.g. TCP = 6, UDP = 17) */
SFLIPv4 local_ip; /* local IP address */
SFLIPv4 remote_ip; /* remote IP address */
uint32_t local_port; /* TCP/UDP local port number or equivalent */
uint32_t remote_port; /* TCP/UDP remote port number of equivalent */
} SFLExtended_socket_ipv4;
#define XDRSIZ_SFLEXTENDED_SOCKET4 20
/* IPv6 Socket */
/* opaque = flow_data; enterprise = 0; format = 2101 */
typedef struct _SFLExtended_socket_ipv6 {
uint32_t protocol; /* IP Protocol (e.g. TCP = 6, UDP = 17) */
SFLIPv6 local_ip; /* local IP address */
SFLIPv6 remote_ip; /* remote IP address */
uint32_t local_port; /* TCP/UDP local port number or equivalent */
uint32_t remote_port; /* TCP/UDP remote port number of equivalent */
} SFLExtended_socket_ipv6;
#define XDRSIZ_SFLEXTENDED_SOCKET6 44
typedef enum {
MEMCACHE_PROT_OTHER = 0,
MEMCACHE_PROT_ASCII = 1,
MEMCACHE_PROT_BINARY = 2,
} SFLMemcache_prot;
typedef enum {
MEMCACHE_CMD_OTHER = 0,
MEMCACHE_CMD_SET = 1,
MEMCACHE_CMD_ADD = 2,
MEMCACHE_CMD_REPLACE = 3,
MEMCACHE_CMD_APPEND = 4,
MEMCACHE_CMD_PREPEND = 5,
MEMCACHE_CMD_CAS = 6,
MEMCACHE_CMD_GET = 7,
MEMCACHE_CMD_GETS = 8,
} SFLMemcache_cmd;
enum SFLMemcache_operation_status {
MEMCACHE_OP_UNKNOWN = 0,
MEMCACHE_OP_OK = 1,
MEMCACHE_OP_ERROR = 2,
MEMCACHE_OP_CLIENT_ERROR = 3,
MEMCACHE_OP_SERVER_ERROR = 4,
MEMCACHE_OP_STORED = 5,
MEMCACHE_OP_NOT_STORED = 6,
MEMCACHE_OP_EXISTS = 7,
MEMCACHE_OP_NOT_FOUND = 8,
MEMCACHE_OP_DELETED = 9,
};
#define SFL_MAX_MEMCACHE_KEY 255
typedef struct _SFLSampled_memcache {
uint32_t protocol; /* SFLMemcache_prot */
uint32_t command; /* SFLMemcache_cmd */
SFLString key; /* up to 255 chars */
uint32_t nkeys;
uint32_t value_bytes;
uint32_t duration_uS;
uint32_t status; /* SFLMemcache_operation_status */
} SFLSampled_memcache;
typedef enum {
SFHTTP_OTHER = 0,
SFHTTP_OPTIONS = 1,
SFHTTP_GET = 2,
SFHTTP_HEAD = 3,
SFHTTP_POST = 4,
SFHTTP_PUT = 5,
SFHTTP_DELETE = 6,
SFHTTP_TRACE = 7,
SFHTTP_CONNECT = 8,
} SFLHTTP_method;
#define SFL_MAX_HTTP_URI 255
#define SFL_MAX_HTTP_HOST 32
#define SFL_MAX_HTTP_REFERRER 255
#define SFL_MAX_HTTP_USERAGENT 64
#define SFL_MAX_HTTP_AUTHUSER 32
#define SFL_MAX_HTTP_MIMETYPE 32
typedef struct _SFLSampled_http {
SFLHTTP_method method;
uint32_t protocol; /* 1.1=1001 */
SFLString uri; /* URI exactly as it came from the client (up to 255 bytes) */
SFLString host; /* Host value from request header (<= 32 bytes) */
SFLString referrer; /* Referer value from request header (<=255 bytes) */
SFLString useragent; /* User-Agent value from request header (<= 64 bytes)*/
SFLString authuser; /* RFC 1413 identity of user (<=32 bytes)*/
SFLString mimetype; /* Mime-Type (<=32 bytes) */
uint64_t bytes; /* Content-Length of document transferred */
uint32_t uS; /* duration of the operation (microseconds) */
uint32_t status; /* HTTP status code */
} SFLSampled_http;
typedef enum {
SFLOW_CAL_TRANSACTION_OTHER=0,
SFLOW_CAL_TRANSACTION_START,
SFLOW_CAL_TRANSACTION_END,
SFLOW_CAL_TRANSACTION_ATOMIC,
SFLOW_CAL_TRANSACTION_EVENT,
SFLOW_CAL_NUM_TRANSACTION_TYPES
} EnumSFLCALTransaction;
static const char *CALTransactionNames[] = {"OTHER", "START", "END","ATOMIC", "EVENT" };
typedef struct _SFLSampled_CAL {
EnumSFLCALTransaction type;
uint32_t depth;
SFLString pool;
SFLString transaction;
SFLString operation;
SFLString status;
uint64_t duration_uS;
} SFLSampled_CAL;
#define SFLCAL_MAX_POOL_LEN 32
#define SFLCAL_MAX_TRANSACTION_LEN 128
#define SFLCAL_MAX_OPERATION_LEN 128
#define SFLCAL_MAX_STATUS_LEN 64
enum SFLFlow_type_tag {
/* enterprise = 0, format = ... */
SFLFLOW_HEADER = 1, /* Packet headers are sampled */
SFLFLOW_ETHERNET = 2, /* MAC layer information */
SFLFLOW_IPV4 = 3, /* IP version 4 data */
SFLFLOW_IPV6 = 4, /* IP version 6 data */
SFLFLOW_EX_SWITCH = 1001, /* Extended switch information */
SFLFLOW_EX_ROUTER = 1002, /* Extended router information */
SFLFLOW_EX_GATEWAY = 1003, /* Extended gateway router information */
SFLFLOW_EX_USER = 1004, /* Extended TACAS/RADIUS user information */
SFLFLOW_EX_URL = 1005, /* Extended URL information */
SFLFLOW_EX_MPLS = 1006, /* Extended MPLS information */
SFLFLOW_EX_NAT = 1007, /* Extended NAT information */
SFLFLOW_EX_MPLS_TUNNEL = 1008, /* additional MPLS information */
SFLFLOW_EX_MPLS_VC = 1009,
SFLFLOW_EX_MPLS_FTN = 1010,
SFLFLOW_EX_MPLS_LDP_FEC = 1011,
SFLFLOW_EX_VLAN_TUNNEL = 1012, /* VLAN stack */
SFLFLOW_EX_80211_PAYLOAD = 1013,
SFLFLOW_EX_80211_RX = 1014,
SFLFLOW_EX_80211_TX = 1015,
SFLFLOW_EX_AGGREGATION = 1016,
SFLFLOW_EX_SOCKET4 = 2100,
SFLFLOW_EX_SOCKET6 = 2101,
SFLFLOW_MEMCACHE = 2200,
SFLFLOW_HTTP = 2201,
SFLFLOW_CAL = (4300 << 12) + 5, /* 4300 is InMon enterprise no. */
};
typedef union _SFLFlow_type {
SFLSampled_header header;
SFLSampled_ethernet ethernet;
SFLSampled_ipv4 ipv4;
SFLSampled_ipv6 ipv6;
SFLSampled_memcache memcache;
SFLSampled_http http;
SFLSampled_CAL cal;
SFLExtended_switch sw;
SFLExtended_router router;
SFLExtended_gateway gateway;
SFLExtended_user user;
SFLExtended_url url;
SFLExtended_mpls mpls;
SFLExtended_nat nat;
SFLExtended_mpls_tunnel mpls_tunnel;
SFLExtended_mpls_vc mpls_vc;
SFLExtended_mpls_FTN mpls_ftn;
SFLExtended_mpls_LDP_FEC mpls_ldp_fec;
SFLExtended_vlan_tunnel vlan_tunnel;
SFLExtended_wifi_payload wifi_payload;
SFLExtended_wifi_rx wifi_rx;
SFLExtended_wifi_tx wifi_tx;
SFLExtended_aggregation aggregation;
SFLExtended_socket_ipv4 socket4;
SFLExtended_socket_ipv6 socket6;
} SFLFlow_type;
typedef struct _SFLFlow_sample_element {
struct _SFLFlow_sample_element *nxt;
uint32_t tag; /* SFLFlow_type_tag */
uint32_t length;
SFLFlow_type flowType;
} SFLFlow_sample_element;
enum SFL_sample_tag {
SFLFLOW_SAMPLE = 1, /* enterprise = 0 : format = 1 */
SFLCOUNTERS_SAMPLE = 2, /* enterprise = 0 : format = 2 */
SFLFLOW_SAMPLE_EXPANDED = 3, /* enterprise = 0 : format = 3 */
SFLCOUNTERS_SAMPLE_EXPANDED = 4 /* enterprise = 0 : format = 4 */
};
typedef struct _SFLFlow_Pdu {
struct _SFLFlow_Pdu *nxt;
uint32_t num_elements;
SFLFlow_sample_element *elements;
} SFLFlow_Pdu;
/* Format of a single flow sample */
typedef struct _SFLFlow_sample {
/* uint32_t tag; */ /* SFL_sample_tag -- enterprise = 0 : format = 1 */
/* uint32_t length; */
uint32_t sequence_number; /* Incremented with each flow sample
generated */
uint32_t source_id; /* fsSourceId */
uint32_t sampling_rate; /* fsPacketSamplingRate */
uint32_t sample_pool; /* Total number of packets that could have been
sampled (i.e. packets skipped by sampling
process + total number of samples) */
uint32_t drops; /* Number of times a packet was dropped due to
lack of resources */
uint32_t input; /* SNMP ifIndex of input interface.
0 if interface is not known. */
uint32_t output; /* SNMP ifIndex of output interface,
0 if interface is not known.
Set most significant bit to indicate
multiple destination interfaces
(i.e. in case of broadcast or multicast)
and set lower order bits to indicate
number of destination interfaces.
Examples:
0x00000002 indicates ifIndex = 2
0x00000000 ifIndex unknown.
0x80000007 indicates a packet sent
to 7 interfaces.
0x80000000 indicates a packet sent to
an unknown number of
interfaces greater than 1.*/
uint32_t num_elements;
SFLFlow_sample_element *elements;
} SFLFlow_sample;
/* same thing, but the expanded version (for full 32-bit ifIndex numbers) */
typedef struct _SFLFlow_sample_expanded {
/* uint32_t tag; */ /* SFL_sample_tag -- enterprise = 0 : format = 1 */
/* uint32_t length; */
uint32_t sequence_number; /* Incremented with each flow sample
generated */
uint32_t ds_class; /* EXPANDED */
uint32_t ds_index; /* EXPANDED */
uint32_t sampling_rate; /* fsPacketSamplingRate */
uint32_t sample_pool; /* Total number of packets that could have been
sampled (i.e. packets skipped by sampling
process + total number of samples) */
uint32_t drops; /* Number of times a packet was dropped due to
lack of resources */
uint32_t inputFormat; /* EXPANDED */
uint32_t input; /* SNMP ifIndex of input interface.
0 if interface is not known. */
uint32_t outputFormat; /* EXPANDED */
uint32_t output; /* SNMP ifIndex of output interface,
0 if interface is not known. */
uint32_t num_elements;
SFLFlow_sample_element *elements;
} SFLFlow_sample_expanded;
/* Counter types */
/* Generic interface counters - see RFC 1573, 2233 */
typedef struct _SFLIf_counters {
uint32_t ifIndex;
uint32_t ifType;
uint64_t ifSpeed;
uint32_t ifDirection; /* Derived from MAU MIB (RFC 2668)
0 = unknown, 1 = full-duplex,
2 = half-duplex, 3 = in, 4 = out */
uint32_t ifStatus; /* bit field with the following bits assigned:
bit 0 = ifAdminStatus (0 = down, 1 = up)
bit 1 = ifOperStatus (0 = down, 1 = up) */
uint64_t ifInOctets;
uint32_t ifInUcastPkts;
uint32_t ifInMulticastPkts;
uint32_t ifInBroadcastPkts;
uint32_t ifInDiscards;
uint32_t ifInErrors;
uint32_t ifInUnknownProtos;
uint64_t ifOutOctets;
uint32_t ifOutUcastPkts;
uint32_t ifOutMulticastPkts;
uint32_t ifOutBroadcastPkts;
uint32_t ifOutDiscards;
uint32_t ifOutErrors;
uint32_t ifPromiscuousMode;
} SFLIf_counters;
/* Ethernet interface counters - see RFC 2358 */
typedef struct _SFLEthernet_counters {
uint32_t dot3StatsAlignmentErrors;
uint32_t dot3StatsFCSErrors;
uint32_t dot3StatsSingleCollisionFrames;
uint32_t dot3StatsMultipleCollisionFrames;
uint32_t dot3StatsSQETestErrors;
uint32_t dot3StatsDeferredTransmissions;
uint32_t dot3StatsLateCollisions;
uint32_t dot3StatsExcessiveCollisions;
uint32_t dot3StatsInternalMacTransmitErrors;
uint32_t dot3StatsCarrierSenseErrors;
uint32_t dot3StatsFrameTooLongs;
uint32_t dot3StatsInternalMacReceiveErrors;
uint32_t dot3StatsSymbolErrors;
} SFLEthernet_counters;
/* Token ring counters - see RFC 1748 */
typedef struct _SFLTokenring_counters {
uint32_t dot5StatsLineErrors;
uint32_t dot5StatsBurstErrors;
uint32_t dot5StatsACErrors;
uint32_t dot5StatsAbortTransErrors;
uint32_t dot5StatsInternalErrors;
uint32_t dot5StatsLostFrameErrors;
uint32_t dot5StatsReceiveCongestions;
uint32_t dot5StatsFrameCopiedErrors;
uint32_t dot5StatsTokenErrors;
uint32_t dot5StatsSoftErrors;
uint32_t dot5StatsHardErrors;
uint32_t dot5StatsSignalLoss;
uint32_t dot5StatsTransmitBeacons;
uint32_t dot5StatsRecoverys;
uint32_t dot5StatsLobeWires;
uint32_t dot5StatsRemoves;
uint32_t dot5StatsSingles;
uint32_t dot5StatsFreqErrors;
} SFLTokenring_counters;
/* 100 BaseVG interface counters - see RFC 2020 */
typedef struct _SFLVg_counters {
uint32_t dot12InHighPriorityFrames;
uint64_t dot12InHighPriorityOctets;
uint32_t dot12InNormPriorityFrames;
uint64_t dot12InNormPriorityOctets;
uint32_t dot12InIPMErrors;
uint32_t dot12InOversizeFrameErrors;
uint32_t dot12InDataErrors;
uint32_t dot12InNullAddressedFrames;
uint32_t dot12OutHighPriorityFrames;
uint64_t dot12OutHighPriorityOctets;
uint32_t dot12TransitionIntoTrainings;
uint64_t dot12HCInHighPriorityOctets;
uint64_t dot12HCInNormPriorityOctets;
uint64_t dot12HCOutHighPriorityOctets;
} SFLVg_counters;
typedef struct _SFLVlan_counters {
uint32_t vlan_id;
uint64_t octets;
uint32_t ucastPkts;
uint32_t multicastPkts;
uint32_t broadcastPkts;
uint32_t discards;
} SFLVlan_counters;
typedef struct _SFLWifi_counters {
uint32_t dot11TransmittedFragmentCount;
uint32_t dot11MulticastTransmittedFrameCount;
uint32_t dot11FailedCount;
uint32_t dot11RetryCount;
uint32_t dot11MultipleRetryCount;
uint32_t dot11FrameDuplicateCount;
uint32_t dot11RTSSuccessCount;
uint32_t dot11RTSFailureCount;
uint32_t dot11ACKFailureCount;
uint32_t dot11ReceivedFragmentCount;
uint32_t dot11MulticastReceivedFrameCount;
uint32_t dot11FCSErrorCount;
uint32_t dot11TransmittedFrameCount;
uint32_t dot11WEPUndecryptableCount;
uint32_t dot11QoSDiscardedFragmentCount;
uint32_t dot11AssociatedStationCount;
uint32_t dot11QoSCFPollsReceivedCount;
uint32_t dot11QoSCFPollsUnusedCount;
uint32_t dot11QoSCFPollsUnusableCount;
uint32_t dot11QoSCFPollsLostCount;
} SFLWifi_counters;
/* Processor Information */
/* opaque = counter_data; enterprise = 0; format = 1001 */
typedef struct _SFLProcessor_counters {
uint32_t five_sec_cpu; /* 5 second average CPU utilization */
uint32_t one_min_cpu; /* 1 minute average CPU utilization */
uint32_t five_min_cpu; /* 5 minute average CPU utilization */
uint64_t total_memory; /* total memory (in bytes) */
uint64_t free_memory; /* free memory (in bytes) */
} SFLProcessor_counters;
typedef struct _SFLRadio_counters {
uint32_t elapsed_time; /* elapsed time in ms */
uint32_t on_channel_time; /* time in ms spent on channel */
uint32_t on_channel_busy_time; /* time in ms spent on channel and busy */
} SFLRadio_counters;
/* host sflow */
enum SFLMachine_type {
SFLMT_unknown = 0,
SFLMT_other = 1,
SFLMT_x86 = 2,
SFLMT_x86_64 = 3,
SFLMT_ia64 = 4,
SFLMT_sparc = 5,
SFLMT_alpha = 6,
SFLMT_powerpc = 7,
SFLMT_m68k = 8,
SFLMT_mips = 9,
SFLMT_arm = 10,
SFLMT_hppa = 11,
SFLMT_s390 = 12
};
enum SFLOS_name {
SFLOS_unknown = 0,
SFLOS_other = 1,
SFLOS_linux = 2,
SFLOS_windows = 3,
SFLOS_darwin = 4,
SFLOS_hpux = 5,
SFLOS_aix = 6,
SFLOS_dragonfly = 7,
SFLOS_freebsd = 8,
SFLOS_netbsd = 9,
SFLOS_openbsd = 10,
SFLOS_osf = 11,
SFLOS_solaris = 12
};
typedef struct _SFLMacAddress {
uint8_t mac[8];
} SFLMacAddress;
typedef struct _SFLAdaptor {
uint32_t ifIndex;
uint32_t num_macs;
SFLMacAddress macs[1];
} SFLAdaptor;
typedef struct _SFLAdaptorList {
uint32_t capacity;
uint32_t num_adaptors;
SFLAdaptor **adaptors;
} SFLAdaptorList;
typedef struct _SFLHost_parent {
uint32_t dsClass; /* sFlowDataSource class */
uint32_t dsIndex; /* sFlowDataSource index */
} SFLHost_parent;
#define SFL_MAX_HOSTNAME_LEN 64
#define SFL_MAX_OSRELEASE_LEN 32
typedef struct _SFLHostId {
SFLString hostname;
uint8_t uuid[16];
uint32_t machine_type; /* enum SFLMachine_type */
uint32_t os_name; /* enum SFLOS_name */
SFLString os_release; /* max len 32 bytes */
} SFLHostId;
typedef struct _SFLHost_nio_counters {
uint64_t bytes_in;
uint32_t pkts_in;
uint32_t errs_in;
uint32_t drops_in;
uint64_t bytes_out;
uint32_t pkts_out;
uint32_t errs_out;
uint32_t drops_out;
} SFLHost_nio_counters;
typedef struct _SFLHost_cpu_counters {
float load_one; /* 1 minute load avg. */
float load_five; /* 5 minute load avg. */
float load_fifteen; /* 15 minute load avg. */
uint32_t proc_run; /* running threads */
uint32_t proc_total; /* total threads */
uint32_t cpu_num; /* # CPU cores */
uint32_t cpu_speed; /* speed in MHz of CPU */
uint32_t uptime; /* seconds since last reboot */
uint32_t cpu_user; /* time executing in user mode processes (ms) */
uint32_t cpu_nice; /* time executing niced processs (ms) */
uint32_t cpu_system; /* time executing kernel mode processes (ms) */
uint32_t cpu_idle; /* idle time (ms) */
uint32_t cpu_wio; /* time waiting for I/O to complete (ms) */
uint32_t cpu_intr; /* time servicing interrupts (ms) */
uint32_t cpu_sintr; /* time servicing softirqs (ms) */
uint32_t interrupts; /* interrupt count */
uint32_t contexts; /* context switch count */
} SFLHost_cpu_counters;
typedef struct _SFLHost_mem_counters {
uint64_t mem_total; /* total bytes */
uint64_t mem_free; /* free bytes */
uint64_t mem_shared; /* shared bytes */
uint64_t mem_buffers; /* buffers bytes */
uint64_t mem_cached; /* cached bytes */
uint64_t swap_total; /* swap total bytes */
uint64_t swap_free; /* swap free bytes */
uint32_t page_in; /* page in count */
uint32_t page_out; /* page out count */
uint32_t swap_in; /* swap in count */
uint32_t swap_out; /* swap out count */
} SFLHost_mem_counters;
typedef struct _SFLHost_dsk_counters {
uint64_t disk_total;
uint64_t disk_free;
uint32_t part_max_used; /* as percent * 100, so 100==1% */
uint32_t reads; /* reads issued */
uint64_t bytes_read; /* bytes read */
uint32_t read_time; /* read time (ms) */
uint32_t writes; /* writes completed */
uint64_t bytes_written; /* bytes written */
uint32_t write_time; /* write time (ms) */
} SFLHost_dsk_counters;
/* Virtual Node Statistics */
/* opaque = counter_data; enterprise = 0; format = 2100 */
typedef struct _SFLHost_vrt_node_counters {
uint32_t mhz; /* expected CPU frequency */
uint32_t cpus; /* the number of active CPUs */
uint64_t memory; /* memory size in bytes */
uint64_t memory_free; /* unassigned memory in bytes */
uint32_t num_domains; /* number of active domains */
} SFLHost_vrt_node_counters;
/* Virtual Domain Statistics */
/* opaque = counter_data; enterprise = 0; format = 2101 */
/* virDomainState imported from libvirt.h */
enum SFLVirDomainState {
SFL_VIR_DOMAIN_NOSTATE = 0, /* no state */
SFL_VIR_DOMAIN_RUNNING = 1, /* the domain is running */
SFL_VIR_DOMAIN_BLOCKED = 2, /* the domain is blocked on resource */
SFL_VIR_DOMAIN_PAUSED = 3, /* the domain is paused by user */
SFL_VIR_DOMAIN_SHUTDOWN= 4, /* the domain is being shut down */
SFL_VIR_DOMAIN_SHUTOFF = 5, /* the domain is shut off */
SFL_VIR_DOMAIN_CRASHED = 6 /* the domain is crashed */
};
typedef struct _SFLHost_vrt_cpu_counters {
uint32_t state; /* virtDomainState */
uint32_t cpuTime; /* the CPU time used in mS */
uint32_t cpuCount; /* number of virtual CPUs for the domain */
} SFLHost_vrt_cpu_counters;
/* Virtual Domain Memory statistics */
/* opaque = counter_data; enterprise = 0; format = 2102 */
typedef struct _SFLHost_vrt_mem_counters {
uint64_t memory; /* memory in bytes used by domain */
uint64_t maxMemory; /* memory in bytes allowed */
} SFLHost_vrt_mem_counters;
/* Virtual Domain Disk statistics */
/* opaque = counter_data; enterprise = 0; format = 2103 */
typedef struct _SFLHost_vrt_dsk_counters {
uint64_t capacity; /* logical size in bytes */
uint64_t allocation; /* current allocation in bytes */
uint64_t available; /* remaining free bytes */
uint32_t rd_req; /* number of read requests */
uint64_t rd_bytes; /* number of read bytes */
uint32_t wr_req; /* number of write requests */
uint64_t wr_bytes; /* number of written bytes */
uint32_t errs; /* read/write errors */
} SFLHost_vrt_dsk_counters;
/* Virtual Domain Network statistics */
/* opaque = counter_data; enterprise = 0; format = 2104 */
typedef struct _SFLHost_vrt_nio_counters {
uint64_t bytes_in;
uint32_t pkts_in;
uint32_t errs_in;
uint32_t drops_in;
uint64_t bytes_out;
uint32_t pkts_out;
uint32_t errs_out;
uint32_t drops_out;
} SFLHost_vrt_nio_counters;
typedef struct _SFLMemcache_counters {
uint32_t uptime; /* Number of seconds this server has been running */
uint32_t rusage_user; /* Accumulated user time for this process (ms)*/