ramips: move GPIO definitions into a separate header file
[openwrt.git] / package / libipfix / patches / 100-openimp_sync.patch
1 --- a/lib/ipfix.c
2 +++ b/lib/ipfix.c
3 @@ -37,6 +37,9 @@ $$LIC$$
4 #ifdef SCTPSUPPORT
5 #include <netinet/sctp.h>
6 #endif
7 +#ifndef NOTHREADS
8 +#include <pthread.h>
9 +#endif
10 #include <fcntl.h>
11 #include <netdb.h>
12
13 @@ -123,6 +126,18 @@ static uint16_t g_lasttid;
14 static ipfix_datarecord_t g_data = { NULL, NULL, 0 }; /* ipfix_export */
15
16 static ipfix_field_t *g_ipfix_fields;
17 +#ifndef NOTHREADS
18 +static pthread_mutex_t g_mutex;
19 +#define mod_lock() { \
20 + if ( pthread_mutex_lock( &g_mutex ) !=0 ) \
21 + mlogf( 0, "[ipfix] mutex_lock() failed: %s\n", \
22 + strerror( errno ) ); \
23 + }
24 +#define mod_unlock() { pthread_mutex_unlock( &g_mutex ); }
25 +#else
26 +#define mod_lock()
27 +#define mod_unlock()
28 +#endif
29
30 /*----- prototypes -------------------------------------------------------*/
31
32 @@ -133,6 +148,7 @@ int _ipfix_send_message( ipfix_t *ifh,
33 ipfix_message_t *message );
34 int _ipfix_write_msghdr( ipfix_t *ifh, ipfix_message_t *msg, iobuf_t *buf );
35 void _ipfix_disconnect( ipfix_collector_t *col );
36 +int _ipfix_export_flush( ipfix_t *ifh );
37
38
39 /* name : do_writeselect
40 @@ -576,16 +592,18 @@ int ipfix_decode_float( void *in, void *
41
42 int ipfix_snprint_float( char *str, size_t size, void *data, size_t len )
43 {
44 - float tmp32;
45 - double tmp64;
46 + uint32_t tmp32;
47 + uint64_t tmp64;
48
49 switch ( len ) {
50 case 4:
51 - ipfix_decode_float( data, &tmp32, 4);
52 - return snprintf( str, size, "%f", tmp32 );
53 + memcpy( &tmp32, data, len );
54 + tmp32 = htonl( tmp32 );
55 + return snprintf( str, size, "%f", (float)tmp32 );
56 case 8:
57 - ipfix_decode_float( data, &tmp64, 8);
58 - return snprintf( str, size, "%lf", tmp64);
59 + memcpy( &tmp64, data, len );
60 + tmp64 = HTONLL( tmp64 );
61 + return snprintf( str, size, "%lf", (double)tmp64 );
62 default:
63 break;
64 }
65 @@ -682,12 +700,19 @@ int ipfix_get_eno_ieid( char *field, int
66 * parameters:
67 * remarks: init module, read field type info.
68 */
69 -int ipfix_init ( void )
70 +int ipfix_init( void )
71 {
72 if ( g_tstart ) {
73 ipfix_cleanup();
74 }
75
76 +#ifndef NOTHREADS
77 + if ( pthread_mutex_init( &g_mutex, NULL ) !=0 ) {
78 + mlogf( 0, "[ipfix] pthread_mutex_init() failed: %s\n",
79 + strerror(errno) );
80 + return -1;
81 + }
82 +#endif
83 g_tstart = time(NULL);
84 signal( SIGPIPE, SIG_IGN );
85 g_lasttid = 255;
86 @@ -806,6 +831,9 @@ void ipfix_cleanup ( void )
87 g_data.maxfields = 0;
88 g_data.lens = NULL;
89 g_data.addrs = NULL;
90 +#ifndef NOTHREADS
91 + (void)pthread_mutex_destroy( &g_mutex );
92 +#endif
93 }
94
95 int _ipfix_connect ( ipfix_collector_t *col )
96 @@ -1465,7 +1493,7 @@ int _ipfix_write_template( ipfix_t
97 default:
98 /* check space */
99 if ( tsize+ifh->offset > IPFIX_DEFAULT_BUFLEN ) {
100 - if ( ipfix_export_flush( ifh ) < 0 )
101 + if ( _ipfix_export_flush( ifh ) < 0 )
102 return -1;
103 if ( tsize+ifh->offset > IPFIX_DEFAULT_BUFLEN )
104 return -1;
105 @@ -1474,6 +1502,8 @@ int _ipfix_write_template( ipfix_t
106 /* write template prior to data */
107 if ( ifh->offset > 0 ) {
108 memmove( ifh->buffer + tsize, ifh->buffer, ifh->offset );
109 + if ( ifh->cs_tid )
110 + ifh->cs_header += tsize;
111 }
112
113 buf = ifh->buffer;
114 @@ -1615,8 +1645,11 @@ int ipfix_open( ipfix_t **ipfixh, int so
115 return -1;
116 }
117 node->ifh = i;
118 +
119 + mod_lock();
120 node->next = g_ipfixlist;
121 g_ipfixlist = node;
122 + mod_unlock();
123
124 *ipfixh = i;
125 return 0;
126 @@ -1633,7 +1666,8 @@ void ipfix_close( ipfix_t *h )
127 {
128 ipfix_node_t *l, *n;
129
130 - ipfix_export_flush( h );
131 + mod_lock();
132 + _ipfix_export_flush( h );
133
134 while( h->collectors )
135 _ipfix_drop_collector( (ipfix_collector_t**)&h->collectors );
136 @@ -1659,6 +1693,7 @@ void ipfix_close( ipfix_t *h )
137 #endif
138 free(h->buffer);
139 free(h);
140 + mod_unlock();
141 }
142 }
143
144 @@ -2156,6 +2191,22 @@ void ipfix_release_template( ipfix_t *if
145 ipfix_delete_template( ifh, templ );
146 }
147
148 +static void _finish_cs( ipfix_t *ifh )
149 +{
150 + size_t buflen;
151 + uint8_t *buf;
152 +
153 + /* finish current dataset */
154 + if ( (buf=ifh->cs_header) ==NULL )
155 + return;
156 + buflen = 0;
157 + INSERTU16( buf+buflen, buflen, ifh->cs_tid );
158 + INSERTU16( buf+buflen, buflen, ifh->cs_bytes );
159 + ifh->cs_bytes = 0;
160 + ifh->cs_header = NULL;
161 + ifh->cs_tid = 0;
162 +}
163 +
164 int ipfix_export( ipfix_t *ifh, ipfix_template_t *templ, ... )
165 {
166 int i;
167 @@ -2199,13 +2250,14 @@ int ipfix_export( ipfix_t *ifh, ipfix_te
168 g_data.addrs, g_data.lens );
169 }
170
171 -int ipfix_export_array( ipfix_t *ifh,
172 - ipfix_template_t *templ,
173 - int nfields,
174 - void **fields,
175 - uint16_t *lengths )
176 +static int
177 +_ipfix_export_array( ipfix_t *ifh,
178 + ipfix_template_t *templ,
179 + int nfields,
180 + void **fields,
181 + uint16_t *lengths )
182 {
183 - int i;
184 + int i, newset_f=0;
185 size_t buflen, datasetlen;
186 uint8_t *p, *buf;
187
188 @@ -2249,7 +2301,19 @@ int ipfix_export_array( ipfix_t
189
190 /** get size of data set, check space
191 */
192 - for ( i=0, datasetlen=4; i<nfields; i++ ) {
193 + if ( templ->tid == ifh->cs_tid ) {
194 + newset_f = 0;
195 + datasetlen = 0;
196 + }
197 + else {
198 + if ( ifh->cs_tid > 0 ) {
199 + _finish_cs( ifh );
200 + }
201 + newset_f = 1;
202 + datasetlen = 4;
203 + }
204 +
205 + for ( i=0; i<nfields; i++ ) {
206 if ( templ->fields[i].flength == IPFIX_FT_VARLEN ) {
207 if ( lengths[i]>254 )
208 datasetlen += 3;
209 @@ -2263,21 +2327,29 @@ int ipfix_export_array( ipfix_t
210 }
211 datasetlen += lengths[i];
212 }
213 - if ( ((ifh->offset + datasetlen) > IPFIX_DEFAULT_BUFLEN )
214 - && (ipfix_export_flush( ifh ) <0) ) {
215 - return -1;
216 +
217 + if ( (ifh->offset + datasetlen) > IPFIX_DEFAULT_BUFLEN ) {
218 + if ( ifh->cs_tid )
219 + _finish_cs( ifh );
220 + newset_f = 1;
221 +
222 + if ( _ipfix_export_flush( ifh ) <0 )
223 + return -1;
224 }
225
226 - /* fill buffer
227 - */
228 + /* fill buffer */
229 buf = (uint8_t*)(ifh->buffer) + ifh->offset;
230 buflen = 0;
231
232 - /* insert data set
233 - */
234 - ifh->nrecords ++;
235 - INSERTU16( buf+buflen, buflen, templ->tid );
236 - INSERTU16( buf+buflen, buflen, datasetlen );
237 + if ( newset_f ) {
238 + /* insert data set
239 + */
240 + ifh->cs_bytes = 0;
241 + ifh->cs_header = buf;
242 + ifh->cs_tid = templ->tid;
243 + INSERTU16( buf+buflen, buflen, templ->tid );
244 + INSERTU16( buf+buflen, buflen, 4 );
245 + }
246
247 /* insert data record
248 */
249 @@ -2303,7 +2375,9 @@ int ipfix_export_array( ipfix_t
250 buflen += lengths[i];
251 }
252
253 + ifh->nrecords ++;
254 ifh->offset += buflen;
255 + ifh->cs_bytes += buflen;
256 if ( ifh->version == IPFIX_VERSION )
257 ifh->seqno ++;
258 return 0;
259 @@ -2313,7 +2387,7 @@ int ipfix_export_array( ipfix_t
260 * parameters:
261 * remarks: rewrite this func!
262 */
263 -int ipfix_export_flush( ipfix_t *ifh )
264 +int _ipfix_export_flush( ipfix_t *ifh )
265 {
266 iobuf_t *buf;
267 ipfix_collector_t *col;
268 @@ -2322,8 +2396,14 @@ int ipfix_export_flush( ipfix_t *ifh )
269 if ( (ifh==NULL) || (ifh->offset==0) )
270 return 0;
271
272 - if ( (buf=_ipfix_getbuf()) ==NULL )
273 + if ( ifh->cs_tid > 0 ) {
274 + /* finish current dataset */
275 + _finish_cs( ifh );
276 + }
277 +
278 + if ( (buf=_ipfix_getbuf()) ==NULL ) {
279 return -1;
280 + }
281
282 #ifdef DEBUG
283 mlogf( 0, "[ipfix_export_flush] msg has %d records, %d bytes\n",
284 @@ -2350,3 +2430,30 @@ int ipfix_export_flush( ipfix_t *ifh )
285 _ipfix_freebuf( buf );
286 return ret;
287 }
288 +
289 +int ipfix_export_array( ipfix_t *ifh,
290 + ipfix_template_t *templ,
291 + int nfields,
292 + void **fields,
293 + uint16_t *lengths )
294 +{
295 + int ret;
296 +
297 + mod_lock();
298 + ret = _ipfix_export_array( ifh, templ, nfields, fields, lengths );
299 + mod_unlock();
300 +
301 + return ret;
302 +}
303 +
304 +int ipfix_export_flush( ipfix_t *ifh )
305 +{
306 + int ret;
307 +
308 + mod_lock();
309 + ret = _ipfix_export_flush( ifh );
310 + mod_unlock();
311 +
312 + return ret;
313 +}
314 +
315 --- a/lib/ipfix.h
316 +++ b/lib/ipfix.h
317 @@ -142,6 +142,12 @@ typedef struct
318 int nrecords; /* no. of records in buffer */
319 size_t offset; /* output buffer fill level */
320 uint32_t seqno; /* sequence no. of next message */
321 +
322 + /* experimental */
323 + int cs_tid; /* template id of current dataset */
324 + int cs_bytes; /* size of current set */
325 + uint8_t *cs_header; /* start of current set */
326 +
327 } ipfix_t;
328
329 /** exporter funcs
330 --- a/lib/ipfix_col.c
331 +++ b/lib/ipfix_col.c
332 @@ -897,6 +897,8 @@ int ipfix_decode_datarecord( ipfixt_node
333 return -1;
334 }
335
336 + n->ipfixt->fields[i].elem->decode(p,p,len);
337 +
338 data->lens[i] = len;
339 data->addrs[i] = p;
340
341 @@ -907,7 +909,7 @@ int ipfix_decode_datarecord( ipfixt_node
342 return 0;
343 }
344
345 -static void do_free_datarecord( ipfix_datarecord_t *data )
346 +void ipfix_free_datarecord( ipfix_datarecord_t *data )
347 {
348 if ( data ) {
349 if ( data->addrs )
350 @@ -925,6 +927,7 @@ int ipfix_parse_msg( ipfix_input_t *inpu
351 ipfix_hdr_t hdr; /* ipfix packet header */
352 ipfixs_node_t *s;
353 ipfix_datarecord_t data = { NULL, NULL, 0 };
354 + ipfixe_node_t *e;
355 uint8_t *buf; /* ipfix payload */
356 uint16_t setid, setlen; /* set id, set lenght */
357 int i, nread, offset; /* counter */
358 @@ -1042,6 +1045,12 @@ int ipfix_parse_msg( ipfix_input_t *inpu
359 err_flag = 1;
360 }
361 else {
362 + for ( e=g_exporter; e!=NULL; e=e->next ) {
363 + if ( e->elem->export_dset )
364 + (void) e->elem->export_dset( t, buf+nread, setlen,
365 + e->elem->data );
366 + }
367 +
368 /** read data records
369 */
370 for ( offset=nread, bytesleft=setlen; bytesleft>4; ) {
371 @@ -1076,11 +1085,11 @@ int ipfix_parse_msg( ipfix_input_t *inpu
372 goto errend;
373
374 end:
375 - do_free_datarecord( &data );
376 + ipfix_free_datarecord( &data );
377 return nread;
378
379 errend:
380 - do_free_datarecord( &data );
381 + ipfix_free_datarecord( &data );
382 return -1;
383 }
384
385 @@ -1093,7 +1102,7 @@ void process_client_tcp( int fd, int mas
386 tcp_conn_t *tcon = (tcp_conn_t*)data;
387 char *func = "process_client_tcp";
388
389 - mlogf( 3, "[%s] fd %d mask %d called.\n", func, fd, mask );
390 + mlogf( 4, "[%s] fd %d mask %d called.\n", func, fd, mask );
391
392 /** read ipfix header
393 */
394 --- a/lib/ipfix_col.h
395 +++ b/lib/ipfix_col.h
396 @@ -88,6 +88,7 @@ typedef struct ipfix_col_info
397 int (*export_newsource)(ipfixs_node_t*,void*);
398 int (*export_newmsg)(ipfixs_node_t*,ipfix_hdr_t*,void*);
399 int (*export_trecord)(ipfixs_node_t*,ipfixt_node_t*,void*);
400 + int (*export_dset)(ipfixt_node_t*,uint8_t*,size_t,void*);
401 int (*export_drecord)(ipfixs_node_t*,ipfixt_node_t*,
402 ipfix_datarecord_t*,void*);
403 void (*export_cleanup)(void*);
404 --- a/lib/ipfix_col_files.c
405 +++ b/lib/ipfix_col_files.c
406 @@ -68,7 +68,7 @@ static int export_newsource_file( ipfixs
407 return -1;
408 }
409 snprintf( s->fname+strlen(s->fname), PATH_MAX-strlen(s->fname),
410 - "/%u", s->odid );
411 + "/%u", (unsigned int)s->odid );
412 if ( (access( s->fname, R_OK ) <0 )
413 && (mkdir( s->fname, S_IRWXU ) <0) ) {
414 mlogf( 0, "[%s] cannot access dir '%s': %s\n",
415 --- a/lib/ipfix_FOKUS_IEs.txt
416 +++ b/lib/ipfix_FOKUS_IEs.txt
417 @@ -24,6 +24,8 @@
418 196, IPFIX_FT_PKTID, 4, IPFIX_CODING_UINT, "pktId", "FOKUS packet id"
419 197, IPFIX_FT_STARTTIME, 4, IPFIX_CODING_INT, "startTime", "FOKUS interval start"
420 198, IPFIX_FT_ENDTIME, 4, IPFIX_CODING_INT, "endTime", "FOKUS interval end"
421 +199, IPFIX_FT_RTT_USEC, 8, IPFIX_CODING_UINT, "rtt_usec", "FOKUS rtt in us"
422 +
423 300, IPFIX_FT_FLOWCREATIONTIMEUSEC, 4, IPFIX_CODING_INT, "flowCreationTimeUsec", "FOKUS flow start usec fraction"
424 301, IPFIX_FT_FLOWENDTIMEUSEC, 4, IPFIX_CODING_INT, "flowEndTimeUsec", "FOKUS flow end usec fraction"
425 303, IPFIX_FT_TC_PACKETS, 4, IPFIX_CODING_UINT, "tcPackets", "DAIDALOS Packets seen"
426 @@ -39,3 +41,48 @@
427 313, IPFIX_FT_OWDVARMIN_NSEC, 4, IPFIX_CODING_INT, "owdvarmin_nsec", "FOKUS minimum owd variance in ns"
428 314, IPFIX_FT_OWDVARMAX_NSEC, 4, IPFIX_CODING_INT, "owdvarmax_nsec", "FOKUS maximum ow variance in ns"
429
430 +# Project INTERSECTION
431 +315, IPFIX_FT_SOURCEIPV4FANOUT, 4, IPFIX_CODING_UINT,"sourceIPv4FanOut", "FOKUS IPv4 fanout"
432 +316, IPFIX_FT_DESTINATIONIPV4FANIN, 4, IPFIX_CODING_UINT,"destinationIPv4FanIn", "FOKUS IPv4 fanin"
433 +
434 +# Project PRISM
435 +
436 +330, IPFIX_FT_PR_SESSIONID, 4, IPFIX_CODING_UINT, "sessionId", "PRISM Session ID"
437 +331, IPFIX_FT_PR_TRANSACTIONID, 4, IPFIX_CODING_UINT, "transactionId", "PRISM Transaction ID"
438 +332, IPFIX_FT_PR_ENCRYPTEDDATA, 65535, IPFIX_CODING_STRING, "encryptedData", "PRISM encrypted data"
439 +333, IPFIX_FT_PR_DECRYPTIONKEY, 65535, IPFIX_CODING_STRING, "decryptionKey", "PRISM decryption key"
440 +334, IPFIX_FT_PR_KEYSHARE, 65535, IPFIX_CODING_STRING, "keyShare", "PRISM key share"
441 +335, IPFIX_FT_PR_KEYSHAREADP, 65535, IPFIX_CODING_STRING, "keyShareAdp", "PRISM key share ADP"
442 +336, IPFIX_FT_PR_INITVECTOR, 65535, IPFIX_CODING_STRING, "cryptoInitVector", "PRISM crypto init vector"
443 +
444 +
445 +# these information elements have been defined by FOKUS for the Oracle project
446 +
447 +402, IPFIX_FT_ORsignalBandwidth, 4, IPFIX_CODING_UINT, "ORsignalBandwidth", "signal bandwidth"
448 +403, IPFIX_FT_ORsignalPower, 2, IPFIX_CODING_UINT, "ORsignalPower", "ERIP"
449 +404, IPFIX_FT_ORmodulationType, 2, IPFIX_CODING_UINT, "ORmodulationType", "AM/FM,.."
450 +405, IPFIX_FT_ORsymbolRate, 2, IPFIX_CODING_UINT, "ORsymbolRate", "symbol rate"
451 +406, IPFIX_FT_ORmodulationOrder, 1, IPFIX_CODING_UINT, "ORmodulationOrder", "number of levels"
452 +407, IPFIX_FT_ORrolloffFactor, 2, IPFIX_CODING_UINT, "ORrolloffFactor", "roll of factor"
453 +408, IPFIX_FT_ORgeopositionLon, 4, IPFIX_CODING_UINT, "ORgeopositionLon", "GPS coordinate, resolution 1 cm"
454 +409, IPFIX_FT_ORgeopositionLat, 4, IPFIX_CODING_UINT, "ORgeopositionLat", "GPS coordinate, resolution 1 cm"
455 +410, IPFIX_FT_ORgeopositionElev, 4, IPFIX_CODING_UINT, "ORgeopositionElev", "GPS coordinate, resolution 1 cm"
456 +411, IPFIX_FT_ORpolicyRecord, 65535, IPFIX_CODING_STRING, "ORpolicyRecord", "policy record has variable length, First 8 bits in data describe the length (in bytes) of the field"
457 +420, IPFIX_FT_channel_status, 1, IPFIX_CODING_UINT, "channel_status", vacancy of the scanned channel (1: channel busy, 0: channel idle)"
458 +421, IPFIX_FT_sensing_value, 2, IPFIX_CODING_UINT, "sensing_value", "Cost function output"
459 +422, IPFIX_FT_sensing_threshold, 2, IPFIX_CODING_UINT, "sensing_threshold", "Decision threshold"
460 +423, IPFIX_FT_OR_terminal_id, 1, IPFIX_CODING_UINT, "OR_terminal_id", "terminal identifier"
461 +424, IPFIX_FT_OR_terminal_id_list, 65535, IPFIX_CODING_STRING, "OR_terminal_id_list", "terminal identifier list"
462 +425, IPFIX_FT_Infrastructure_network_id, 1, IPFIX_CODING_UINT, "Infrastructure_network_id", "network identifier"
463 +426, IPFIX_FT_Infrastructure_network_type, 1, IPFIX_CODING_UINT, "Infrastructure_network_type", "network type (GSM - 1, UMTS - 2, WiMAX - 3, WiFi - 4)"
464 +427, IPFIX_FT_Battery_lifetime_min, 1, IPFIX_CODING_UINT, "Battery_lifetime_min", "expected battery lifetime to provide requested services or functionalities, in minutes"
465 +428, IPFIX_FT_Battery_lifetime_h, 1, IPFIX_CODING_UINT, "Battery_lifetime_h", "expected battery lifetime to provide requested services or functionalities, in hours"
466 +429, IPFIX_FT_Battery_status, 1, IPFIX_CODING_UINT, "Battery_status", "expected battery lifetime to provide requested services or functionalities, 1 bit status flag, values 1 or 0"
467 +430, IPFIX_FT_Cell_id_number, 4, IPFIX_CODING_UINT, "Cell_id_number", "16-32 bit cell id number, identifier"
468 +431, IPFIX_FT_Spectral_allocation_vector, 1, IPFIX_CODING_UINT, "Spectral_allocation_vector", "binary vector to indicate whether a band is free 1 bit 0 or not 1 bit 1"
469 +432, IPFIX_FT_Spectral_allocation_profile, 2, IPFIX_CODING_UINT, "Spectral_allocation_profile", "received power spectral density vs. frequency to indicate spectral activity in the band of interest (8-16 bits per discrete frequency value)"
470 +433, IPFIX_FT_Center_frequency, 2, IPFIX_CODING_UINT, "Center_frequency", "Center frequency of the sensed band"
471 +434, IPFIX_FT_Bandwidth_of_CAP, 2, IPFIX_CODING_UINT, "Bandwidth_of_CAP", "Bandwidth of the spectral allocation profile"
472 +435, IPFIX_FT_ORmodulation, 1, IPFIX_CODING_UINT, "ORmodulation", "CREST factor"
473 +436, IPFIX_FT_ORprofileRecord, 65535, IPFIX_CODING_STRING, "ORprofileRecord", "profile record has variable length, First 8 bits in data describe the length (in bytes) of the field"
474 +
This page took 0.063367 seconds and 5 git commands to generate.