aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet
diff options
context:
space:
mode:
Diffstat (limited to 'src/vnet')
-rw-r--r--src/vnet/flow/flow_report.c442
-rw-r--r--src/vnet/flow/flow_report.h73
-rw-r--r--src/vnet/flow/flow_report_classify.c588
-rw-r--r--src/vnet/flow/flow_report_classify.h64
-rw-r--r--src/vnet/flow/ipfix_info_elements.h11
-rw-r--r--src/vnet/flow/ipfix_packet.h48
6 files changed, 663 insertions, 563 deletions
diff --git a/src/vnet/flow/flow_report.c b/src/vnet/flow/flow_report.c
index ccc84235695..f912618ec75 100644
--- a/src/vnet/flow/flow_report.c
+++ b/src/vnet/flow/flow_report.c
@@ -20,77 +20,84 @@
flow_report_main_t flow_report_main;
-static_always_inline u8 stream_index_valid (u32 index)
+static_always_inline u8
+stream_index_valid (u32 index)
{
- flow_report_main_t * frm = &flow_report_main;
- return index < vec_len(frm->streams) &&
- frm->streams[index].domain_id != ~0;
+ flow_report_main_t *frm = &flow_report_main;
+ return index < vec_len (frm->streams) &&
+ frm->streams[index].domain_id != ~0;
}
-static_always_inline flow_report_stream_t * add_stream (void)
+static_always_inline flow_report_stream_t *
+add_stream (void)
{
- flow_report_main_t * frm = &flow_report_main;
+ flow_report_main_t *frm = &flow_report_main;
u32 i;
- for (i = 0; i < vec_len(frm->streams); i++)
- if (!stream_index_valid(i))
+ for (i = 0; i < vec_len (frm->streams); i++)
+ if (!stream_index_valid (i))
return &frm->streams[i];
- u32 index = vec_len(frm->streams);
- vec_validate(frm->streams, index);
+ u32 index = vec_len (frm->streams);
+ vec_validate (frm->streams, index);
return &frm->streams[index];
}
-static_always_inline void delete_stream (u32 index)
+static_always_inline void
+delete_stream (u32 index)
{
- flow_report_main_t * frm = &flow_report_main;
- ASSERT (index < vec_len(frm->streams));
+ flow_report_main_t *frm = &flow_report_main;
+ ASSERT (index < vec_len (frm->streams));
ASSERT (frm->streams[index].domain_id != ~0);
frm->streams[index].domain_id = ~0;
}
-static i32 find_stream (u32 domain_id, u16 src_port)
+static i32
+find_stream (u32 domain_id, u16 src_port)
{
- flow_report_main_t * frm = &flow_report_main;
- flow_report_stream_t * stream;
+ flow_report_main_t *frm = &flow_report_main;
+ flow_report_stream_t *stream;
u32 i;
- for (i = 0; i < vec_len(frm->streams); i++)
- if (stream_index_valid(i)) {
- stream = &frm->streams[i];
- if (domain_id == stream->domain_id) {
- if (src_port != stream->src_port)
- return -2;
- return i;
- } else if (src_port == stream->src_port) {
- return -2;
+ for (i = 0; i < vec_len (frm->streams); i++)
+ if (stream_index_valid (i))
+ {
+ stream = &frm->streams[i];
+ if (domain_id == stream->domain_id)
+ {
+ if (src_port != stream->src_port)
+ return -2;
+ return i;
+ }
+ else if (src_port == stream->src_port)
+ {
+ return -2;
+ }
}
- }
return -1;
}
-int send_template_packet (flow_report_main_t *frm,
- flow_report_t *fr,
- u32 * buffer_indexp)
+int
+send_template_packet (flow_report_main_t * frm,
+ flow_report_t * fr, u32 * buffer_indexp)
{
u32 bi0;
- vlib_buffer_t * b0;
- ip4_ipfix_template_packet_t * tp;
- ipfix_message_header_t * h;
- ip4_header_t * ip;
- udp_header_t * udp;
- vlib_main_t * vm = frm->vlib_main;
- flow_report_stream_t * stream;
+ vlib_buffer_t *b0;
+ ip4_ipfix_template_packet_t *tp;
+ ipfix_message_header_t *h;
+ ip4_header_t *ip;
+ udp_header_t *udp;
+ vlib_main_t *vm = frm->vlib_main;
+ flow_report_stream_t *stream;
vlib_buffer_free_list_t *fl;
ASSERT (buffer_indexp);
if (fr->update_rewrite || fr->rewrite == 0)
{
- if (frm->ipfix_collector.as_u32 == 0
- || frm->src_address.as_u32 == 0)
- {
- vlib_node_set_state (frm->vlib_main, flow_report_process_node.index,
- VLIB_NODE_STATE_DISABLED);
- return -1;
- }
+ if (frm->ipfix_collector.as_u32 == 0 || frm->src_address.as_u32 == 0)
+ {
+ vlib_node_set_state (frm->vlib_main, flow_report_process_node.index,
+ VLIB_NODE_STATE_DISABLED);
+ return -1;
+ }
vec_free (fr->rewrite);
fr->update_rewrite = 1;
}
@@ -98,15 +105,15 @@ int send_template_packet (flow_report_main_t *frm,
if (fr->update_rewrite)
{
fr->rewrite = fr->rewrite_callback (frm, fr,
- &frm->ipfix_collector,
- &frm->src_address,
- frm->collector_port);
+ &frm->ipfix_collector,
+ &frm->src_address,
+ frm->collector_port);
fr->update_rewrite = 0;
}
if (vlib_buffer_alloc (vm, &bi0, 1) != 1)
return -1;
-
+
b0 = vlib_get_buffer (vm, bi0);
/* Initialize the buffer */
@@ -115,7 +122,7 @@ int send_template_packet (flow_report_main_t *frm,
VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0);
ASSERT (vec_len (fr->rewrite) < VLIB_BUFFER_DEFAULT_FREE_LIST_BYTES);
-
+
clib_memcpy (b0->data, fr->rewrite, vec_len (fr->rewrite));
b0->current_data = 0;
b0->current_length = vec_len (fr->rewrite);
@@ -124,20 +131,20 @@ int send_template_packet (flow_report_main_t *frm,
vnet_buffer (b0)->sw_if_index[VLIB_TX] = frm->fib_index;
tp = vlib_buffer_get_current (b0);
- ip = (ip4_header_t *) &tp->ip4;
- udp = (udp_header_t *) (ip+1);
- h = (ipfix_message_header_t *)(udp+1);
+ ip = (ip4_header_t *) & tp->ip4;
+ udp = (udp_header_t *) (ip + 1);
+ h = (ipfix_message_header_t *) (udp + 1);
- /* FIXUP: message header export_time */
- h->export_time = (u32)
- (((f64)frm->unix_time_0) +
- (vlib_time_now(frm->vlib_main) - frm->vlib_time_0));
- h->export_time = clib_host_to_net_u32(h->export_time);
+ /* FIXUP: message header export_time */
+ h->export_time = (u32)
+ (((f64) frm->unix_time_0) +
+ (vlib_time_now (frm->vlib_main) - frm->vlib_time_0));
+ h->export_time = clib_host_to_net_u32 (h->export_time);
stream = &frm->streams[fr->stream_index];
/* FIXUP: message header sequence_number. Templates do not increase it */
- h->sequence_number = clib_host_to_net_u32(stream->sequence_number);
+ h->sequence_number = clib_host_to_net_u32 (stream->sequence_number);
/* FIXUP: udp length */
udp->length = clib_host_to_net_u16 (b0->current_length - sizeof (*ip));
@@ -147,7 +154,7 @@ int send_template_packet (flow_report_main_t *frm,
/* RFC 7011 section 10.3.2. */
udp->checksum = ip4_tcp_udp_compute_checksum (vm, b0, ip);
if (udp->checksum == 0)
- udp->checksum = 0xffff;
+ udp->checksum = 0xffff;
}
*buffer_indexp = bi0;
@@ -159,16 +166,15 @@ int send_template_packet (flow_report_main_t *frm,
static uword
flow_report_process (vlib_main_t * vm,
- vlib_node_runtime_t * rt,
- vlib_frame_t * f)
+ vlib_node_runtime_t * rt, vlib_frame_t * f)
{
- flow_report_main_t * frm = &flow_report_main;
- flow_report_t * fr;
+ flow_report_main_t *frm = &flow_report_main;
+ flow_report_t *fr;
u32 ip4_lookup_node_index;
- vlib_node_t * ip4_lookup_node;
- vlib_frame_t * nf = 0;
+ vlib_node_t *ip4_lookup_node;
+ vlib_frame_t *nf = 0;
u32 template_bi;
- u32 * to_next;
+ u32 *to_next;
int send_template;
f64 now;
int rv;
@@ -179,104 +185,107 @@ flow_report_process (vlib_main_t * vm,
vlib_process_wait_for_event_or_clock (vm, 1e9);
event_type = vlib_process_get_events (vm, &event_data);
if (event_type != 1)
- clib_warning ("bogus kickoff event received, %d", event_type);
+ clib_warning ("bogus kickoff event received, %d", event_type);
vec_reset_length (event_data);
/* Enqueue pkts to ip4-lookup */
ip4_lookup_node = vlib_get_node_by_name (vm, (u8 *) "ip4-lookup");
ip4_lookup_node_index = ip4_lookup_node->index;
- while (1)
+ while (1)
{
vlib_process_wait_for_event_or_clock (vm, 5.0);
event_type = vlib_process_get_events (vm, &event_data);
vec_reset_length (event_data);
-
+
vec_foreach (fr, frm->reports)
- {
- now = vlib_time_now (vm);
-
- /* Need to send a template packet? */
- send_template =
- now > (fr->last_template_sent + frm->template_interval);
- send_template += fr->last_template_sent == 0;
- template_bi = ~0;
- rv = 0;
-
- if (send_template)
- rv = send_template_packet (frm, fr, &template_bi);
-
- if (rv < 0)
- continue;
-
- nf = vlib_get_frame_to_node (vm, ip4_lookup_node_index);
- nf->n_vectors = 0;
- to_next = vlib_frame_vector_args (nf);
-
- if (template_bi != ~0)
- {
- to_next[0] = template_bi;
- to_next++;
- nf->n_vectors++;
- }
-
- nf = fr->flow_data_callback (frm, fr,
- nf, to_next, ip4_lookup_node_index);
- if (nf)
- vlib_put_frame_to_node (vm, ip4_lookup_node_index, nf);
- }
+ {
+ now = vlib_time_now (vm);
+
+ /* Need to send a template packet? */
+ send_template =
+ now > (fr->last_template_sent + frm->template_interval);
+ send_template += fr->last_template_sent == 0;
+ template_bi = ~0;
+ rv = 0;
+
+ if (send_template)
+ rv = send_template_packet (frm, fr, &template_bi);
+
+ if (rv < 0)
+ continue;
+
+ nf = vlib_get_frame_to_node (vm, ip4_lookup_node_index);
+ nf->n_vectors = 0;
+ to_next = vlib_frame_vector_args (nf);
+
+ if (template_bi != ~0)
+ {
+ to_next[0] = template_bi;
+ to_next++;
+ nf->n_vectors++;
+ }
+
+ nf = fr->flow_data_callback (frm, fr,
+ nf, to_next, ip4_lookup_node_index);
+ if (nf)
+ vlib_put_frame_to_node (vm, ip4_lookup_node_index, nf);
+ }
}
- return 0; /* not so much */
+ return 0; /* not so much */
}
+/* *INDENT-OFF* */
VLIB_REGISTER_NODE (flow_report_process_node) = {
.function = flow_report_process,
.type = VLIB_NODE_TYPE_PROCESS,
.name = "flow-report-process",
};
+/* *INDENT-ON* */
-int vnet_flow_report_add_del (flow_report_main_t *frm,
- vnet_flow_report_add_del_args_t *a,
- u16 *template_id)
+int
+vnet_flow_report_add_del (flow_report_main_t * frm,
+ vnet_flow_report_add_del_args_t * a,
+ u16 * template_id)
{
int i;
int found_index = ~0;
flow_report_t *fr;
- flow_report_stream_t * stream;
+ flow_report_stream_t *stream;
u32 si;
-
- si = find_stream(a->domain_id, a->src_port);
+
+ si = find_stream (a->domain_id, a->src_port);
if (si == -2)
return VNET_API_ERROR_INVALID_VALUE;
if (si == -1 && a->is_add == 0)
return VNET_API_ERROR_NO_SUCH_ENTRY;
- for (i = 0; i < vec_len(frm->reports); i++)
+ for (i = 0; i < vec_len (frm->reports); i++)
{
fr = vec_elt_at_index (frm->reports, i);
if (fr->opaque.as_uword == a->opaque.as_uword
- && fr->rewrite_callback == a->rewrite_callback
- && fr->flow_data_callback == a->flow_data_callback)
- {
- found_index = i;
- if (template_id)
- *template_id = fr->template_id;
- break;
- }
+ && fr->rewrite_callback == a->rewrite_callback
+ && fr->flow_data_callback == a->flow_data_callback)
+ {
+ found_index = i;
+ if (template_id)
+ *template_id = fr->template_id;
+ break;
+ }
}
if (a->is_add == 0)
{
if (found_index != ~0)
- {
- vec_delete (frm->reports, 1, found_index);
- stream = &frm->streams[si];
- stream->n_reports--;
- if (stream->n_reports == 0)
- delete_stream(si);
- return 0;
- }
+ {
+ vec_delete (frm->reports, 1, found_index);
+ stream = &frm->streams[si];
+ stream->n_reports--;
+ if (stream->n_reports == 0)
+ delete_stream (si);
+ return 0;
+ }
return VNET_API_ERROR_NO_SUCH_ENTRY;
}
@@ -285,7 +294,7 @@ int vnet_flow_report_add_del (flow_report_main_t *frm,
if (si == -1)
{
- stream = add_stream();
+ stream = add_stream ();
stream->domain_id = a->domain_id;
stream->src_port = a->src_port;
stream->sequence_number = 0;
@@ -313,63 +322,68 @@ int vnet_flow_report_add_del (flow_report_main_t *frm,
return 0;
}
-clib_error_t * flow_report_add_del_error_to_clib_error (int error)
+clib_error_t *
+flow_report_add_del_error_to_clib_error (int error)
{
- switch (error)
- {
- case 0:
- return 0;
- case VNET_API_ERROR_NO_SUCH_ENTRY:
- return clib_error_return (0, "Flow report not found");
- case VNET_API_ERROR_VALUE_EXIST:
- return clib_error_return (0, "Flow report already exists");
- case VNET_API_ERROR_INVALID_VALUE:
- return clib_error_return (0, "Expecting either still unused values "
- "for both domain_id and src_port "
- "or already used values for both fields");
- default:
- return clib_error_return (0, "vnet_flow_report_add_del returned %d",
- error);
- }
+ switch (error)
+ {
+ case 0:
+ return 0;
+ case VNET_API_ERROR_NO_SUCH_ENTRY:
+ return clib_error_return (0, "Flow report not found");
+ case VNET_API_ERROR_VALUE_EXIST:
+ return clib_error_return (0, "Flow report already exists");
+ case VNET_API_ERROR_INVALID_VALUE:
+ return clib_error_return (0, "Expecting either still unused values "
+ "for both domain_id and src_port "
+ "or already used values for both fields");
+ default:
+ return clib_error_return (0, "vnet_flow_report_add_del returned %d",
+ error);
+ }
}
-void vnet_flow_reports_reset (flow_report_main_t * frm)
+void
+vnet_flow_reports_reset (flow_report_main_t * frm)
{
flow_report_t *fr;
u32 i;
- for (i = 0; i < vec_len(frm->streams); i++)
- if (stream_index_valid(i))
+ for (i = 0; i < vec_len (frm->streams); i++)
+ if (stream_index_valid (i))
frm->streams[i].sequence_number = 0;
vec_foreach (fr, frm->reports)
- {
- fr->update_rewrite = 1;
- fr->last_template_sent = 0;
- }
+ {
+ fr->update_rewrite = 1;
+ fr->last_template_sent = 0;
+ }
}
-void vnet_stream_reset (flow_report_main_t * frm, u32 stream_index)
+void
+vnet_stream_reset (flow_report_main_t * frm, u32 stream_index)
{
flow_report_t *fr;
frm->streams[stream_index].sequence_number = 0;
vec_foreach (fr, frm->reports)
- if (frm->reports->stream_index == stream_index) {
+ if (frm->reports->stream_index == stream_index)
+ {
fr->update_rewrite = 1;
fr->last_template_sent = 0;
}
}
-int vnet_stream_change (flow_report_main_t * frm,
- u32 old_domain_id, u16 old_src_port,
- u32 new_domain_id, u16 new_src_port)
+int
+vnet_stream_change (flow_report_main_t * frm,
+ u32 old_domain_id, u16 old_src_port,
+ u32 new_domain_id, u16 new_src_port)
{
i32 stream_index = find_stream (old_domain_id, old_src_port);
if (stream_index < 0)
return 1;
- flow_report_stream_t * stream = &frm->streams[stream_index];
+ flow_report_stream_t *stream = &frm->streams[stream_index];
stream->domain_id = new_domain_id;
stream->src_port = new_src_port;
if (old_domain_id != new_domain_id || old_src_port != new_src_port)
@@ -379,61 +393,61 @@ int vnet_stream_change (flow_report_main_t * frm,
static clib_error_t *
set_ipfix_exporter_command_fn (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
+ unformat_input_t * input,
+ vlib_cli_command_t * cmd)
{
- flow_report_main_t * frm = &flow_report_main;
+ flow_report_main_t *frm = &flow_report_main;
ip4_address_t collector, src;
u16 collector_port = UDP_DST_PORT_ipfix;
u32 fib_id;
u32 fib_index = ~0;
-
+
collector.as_u32 = 0;
src.as_u32 = 0;
- u32 path_mtu = 512; // RFC 7011 section 10.3.3.
+ u32 path_mtu = 512; // RFC 7011 section 10.3.3.
u32 template_interval = 20;
u8 udp_checksum = 0;
- while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
- if (unformat (input, "collector %U", unformat_ip4_address, &collector))
- ;
- else if (unformat (input, "port %u", &collector_port))
- ;
- else if (unformat (input, "src %U", unformat_ip4_address, &src))
- ;
- else if (unformat (input, "fib-id %u", &fib_id))
- {
- ip4_main_t * im = &ip4_main;
- uword * p = hash_get (im->fib_index_by_table_id, fib_id);
- if (! p)
- return clib_error_return (0, "fib ID %d doesn't exist\n",
- fib_id);
- fib_index = p[0];
- }
- else if (unformat (input, "path-mtu %u", &path_mtu))
- ;
- else if (unformat (input, "template-interval %u", &template_interval))
- ;
- else if (unformat (input, "udp-checksum"))
- udp_checksum = 1;
- else
- break;
- }
-
+ while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (input, "collector %U", unformat_ip4_address, &collector))
+ ;
+ else if (unformat (input, "port %u", &collector_port))
+ ;
+ else if (unformat (input, "src %U", unformat_ip4_address, &src))
+ ;
+ else if (unformat (input, "fib-id %u", &fib_id))
+ {
+ ip4_main_t *im = &ip4_main;
+ uword *p = hash_get (im->fib_index_by_table_id, fib_id);
+ if (!p)
+ return clib_error_return (0, "fib ID %d doesn't exist\n", fib_id);
+ fib_index = p[0];
+ }
+ else if (unformat (input, "path-mtu %u", &path_mtu))
+ ;
+ else if (unformat (input, "template-interval %u", &template_interval))
+ ;
+ else if (unformat (input, "udp-checksum"))
+ udp_checksum = 1;
+ else
+ break;
+ }
+
if (collector.as_u32 != 0 && src.as_u32 == 0)
return clib_error_return (0, "src address required");
- if (path_mtu > 1450 /* vpp does not support fragmentation */)
- return clib_error_return (0, "too big path-mtu value, maximum is 1450");
+ if (path_mtu > 1450 /* vpp does not support fragmentation */ )
+ return clib_error_return (0, "too big path-mtu value, maximum is 1450");
if (path_mtu < 68)
- return clib_error_return (0, "too small path-mtu value, minimum is 68");
+ return clib_error_return (0, "too small path-mtu value, minimum is 68");
/* Reset report streams if we are reconfiguring IP addresses */
if (frm->ipfix_collector.as_u32 != collector.as_u32 ||
frm->src_address.as_u32 != src.as_u32 ||
frm->collector_port != collector_port)
- vnet_flow_reports_reset(frm);
+ vnet_flow_reports_reset (frm);
frm->ipfix_collector.as_u32 = collector.as_u32;
frm->collector_port = collector_port;
@@ -442,25 +456,25 @@ set_ipfix_exporter_command_fn (vlib_main_t * vm,
frm->path_mtu = path_mtu;
frm->template_interval = template_interval;
frm->udp_checksum = udp_checksum;
-
+
if (collector.as_u32)
vlib_cli_output (vm, "Collector %U, src address %U, "
- "fib index %d, path MTU %u, "
- "template resend interval %us, "
- "udp checksum %s",
- format_ip4_address, &frm->ipfix_collector,
- format_ip4_address, &frm->src_address,
- fib_index, path_mtu, template_interval,
- udp_checksum ? "enabled" : "disabled");
+ "fib index %d, path MTU %u, "
+ "template resend interval %us, "
+ "udp checksum %s",
+ format_ip4_address, &frm->ipfix_collector,
+ format_ip4_address, &frm->src_address,
+ fib_index, path_mtu, template_interval,
+ udp_checksum ? "enabled" : "disabled");
else
vlib_cli_output (vm, "IPFIX Collector is disabled");
/* Turn on the flow reporting process */
- vlib_process_signal_event (vm, flow_report_process_node.index,
- 1, 0);
+ vlib_process_signal_event (vm, flow_report_process_node.index, 1, 0);
return 0;
}
+/* *INDENT-OFF* */
VLIB_CLI_COMMAND (set_ipfix_exporter_command, static) = {
.path = "set ipfix exporter",
.short_help = "set ipfix exporter "
@@ -471,37 +485,45 @@ VLIB_CLI_COMMAND (set_ipfix_exporter_command, static) = {
"[udp-checksum]",
.function = set_ipfix_exporter_command_fn,
};
+/* *INDENT-ON* */
static clib_error_t *
ipfix_flush_command_fn (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
+ unformat_input_t * input, vlib_cli_command_t * cmd)
{
/* poke the flow reporting process */
- vlib_process_signal_event (vm, flow_report_process_node.index,
- 1, 0);
+ vlib_process_signal_event (vm, flow_report_process_node.index, 1, 0);
return 0;
}
+/* *INDENT-OFF* */
VLIB_CLI_COMMAND (ipfix_flush_command, static) = {
.path = "ipfix flush",
.short_help = "flush the current ipfix data [for make test]",
.function = ipfix_flush_command_fn,
};
+/* *INDENT-ON* */
-static clib_error_t *
-flow_report_init (vlib_main_t *vm)
+static clib_error_t *
+flow_report_init (vlib_main_t * vm)
{
- flow_report_main_t * frm = &flow_report_main;
+ flow_report_main_t *frm = &flow_report_main;
frm->vlib_main = vm;
- frm->vnet_main = vnet_get_main();
- frm->unix_time_0 = time(0);
- frm->vlib_time_0 = vlib_time_now(frm->vlib_main);
+ frm->vnet_main = vnet_get_main ();
+ frm->unix_time_0 = time (0);
+ frm->vlib_time_0 = vlib_time_now (frm->vlib_main);
frm->fib_index = ~0;
return 0;
}
VLIB_INIT_FUNCTION (flow_report_init)
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/vnet/flow/flow_report.h b/src/vnet/flow/flow_report.h
index 01859ce5888..b26345b86ed 100644
--- a/src/vnet/flow/flow_report.h
+++ b/src/vnet/flow/flow_report.h
@@ -32,7 +32,8 @@
#include <vnet/flow/ipfix_packet.h>
/* Used to build the rewrite */
-typedef struct {
+typedef struct
+{
ip4_header_t ip4;
udp_header_t udp;
ipfix_template_packet_t ipfix;
@@ -41,23 +42,24 @@ typedef struct {
struct flow_report_main;
struct flow_report;
-typedef u8 * (vnet_flow_rewrite_callback_t)(struct flow_report_main *,
- struct flow_report *,
- ip4_address_t *,
- ip4_address_t *,
- u16);
+typedef u8 *(vnet_flow_rewrite_callback_t) (struct flow_report_main *,
+ struct flow_report *,
+ ip4_address_t *,
+ ip4_address_t *, u16);
-typedef vlib_frame_t * (vnet_flow_data_callback_t) (struct flow_report_main *,
- struct flow_report *,
- vlib_frame_t *, u32 *,
- u32);
+typedef vlib_frame_t *(vnet_flow_data_callback_t) (struct flow_report_main *,
+ struct flow_report *,
+ vlib_frame_t *, u32 *,
+ u32);
-typedef union {
- void * as_ptr;
+typedef union
+{
+ void *as_ptr;
uword as_uword;
} opaque_t;
-typedef struct {
+typedef struct
+{
u32 domain_id;
u32 sequence_number;
u16 src_port;
@@ -65,16 +67,17 @@ typedef struct {
u16 next_template_no;
} flow_report_stream_t;
-typedef struct flow_report {
+typedef struct flow_report
+{
/* ipfix rewrite, set by callback */
- u8 * rewrite;
+ u8 *rewrite;
u16 template_id;
u32 stream_index;
f64 last_template_sent;
int update_rewrite;
/* Bitmap of fields to send */
- uword * fields_to_send;
+ uword *fields_to_send;
/* Opaque data */
opaque_t opaque;
@@ -86,9 +89,10 @@ typedef struct flow_report {
vnet_flow_data_callback_t *flow_data_callback;
} flow_report_t;
-typedef struct flow_report_main {
- flow_report_t * reports;
- flow_report_stream_t * streams;
+typedef struct flow_report_main
+{
+ flow_report_t *reports;
+ flow_report_stream_t *streams;
/* ipfix collector ip address, port, our ip address, fib index */
ip4_address_t ipfix_collector;
@@ -110,8 +114,8 @@ typedef struct flow_report_main {
f64 vlib_time_0;
/* convenience variables */
- vlib_main_t * vlib_main;
- vnet_main_t * vnet_main;
+ vlib_main_t *vlib_main;
+ vnet_main_t *vnet_main;
} flow_report_main_t;
extern flow_report_main_t flow_report_main;
@@ -119,28 +123,37 @@ extern flow_report_main_t flow_report_main;
extern vlib_node_registration_t flow_report_process_node;
int vnet_flow_report_enable_disable (u32 sw_if_index, u32 table_index,
- int enable_disable);
-typedef struct {
+ int enable_disable);
+typedef struct
+{
vnet_flow_data_callback_t *flow_data_callback;
vnet_flow_rewrite_callback_t *rewrite_callback;
opaque_t opaque;
int is_add;
u32 domain_id;
u16 src_port;
-} vnet_flow_report_add_del_args_t;
+} vnet_flow_report_add_del_args_t;
-int vnet_flow_report_add_del (flow_report_main_t *frm,
- vnet_flow_report_add_del_args_t *a,
- u16 *template_id);
+int vnet_flow_report_add_del (flow_report_main_t * frm,
+ vnet_flow_report_add_del_args_t * a,
+ u16 * template_id);
-clib_error_t * flow_report_add_del_error_to_clib_error (int error);
+clib_error_t *flow_report_add_del_error_to_clib_error (int error);
void vnet_flow_reports_reset (flow_report_main_t * frm);
void vnet_stream_reset (flow_report_main_t * frm, u32 stream_index);
int vnet_stream_change (flow_report_main_t * frm,
- u32 old_domain_id, u16 old_src_port,
- u32 new_domain_id, u16 new_src_port);
+ u32 old_domain_id, u16 old_src_port,
+ u32 new_domain_id, u16 new_src_port);
#endif /* __included_vnet_flow_report_h__ */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/vnet/flow/flow_report_classify.c b/src/vnet/flow/flow_report_classify.c
index d4c30492e2d..163ce10a369 100644
--- a/src/vnet/flow/flow_report_classify.c
+++ b/src/vnet/flow/flow_report_classify.c
@@ -18,56 +18,58 @@
/* Common prefix of tcp and udp headers
* containing only source and destination port fields */
-typedef struct {
+typedef struct
+{
u16 src_port, dst_port;
} tcpudp_header_t;
flow_report_classify_main_t flow_report_classify_main;
-u8 * ipfix_classify_template_rewrite (flow_report_main_t * frm,
- flow_report_t * fr,
- ip4_address_t * collector_address,
- ip4_address_t * src_address,
- u16 collector_port)
+u8 *
+ipfix_classify_template_rewrite (flow_report_main_t * frm,
+ flow_report_t * fr,
+ ip4_address_t * collector_address,
+ ip4_address_t * src_address,
+ u16 collector_port)
{
- flow_report_classify_main_t * fcm = &flow_report_classify_main;
- vnet_classify_table_t * tblp;
- vnet_classify_main_t * vcm = &vnet_classify_main;
+ flow_report_classify_main_t *fcm = &flow_report_classify_main;
+ vnet_classify_table_t *tblp;
+ vnet_classify_main_t *vcm = &vnet_classify_main;
u32 flow_table_index = fr->opaque.as_uword;
- u8 * ip_start;
- ip4_header_t * ip;
- ip6_header_t * ip6;
- tcpudp_header_t * tcpudp;
- udp_header_t * udp;
- ipfix_message_header_t * h;
- ipfix_set_header_t * s;
- ipfix_template_header_t * t;
- ipfix_field_specifier_t * f;
- ipfix_field_specifier_t * first_field;
- u8 * rewrite = 0;
- ip4_ipfix_template_packet_t * tp;
+ u8 *ip_start;
+ ip4_header_t *ip;
+ ip6_header_t *ip6;
+ tcpudp_header_t *tcpudp;
+ udp_header_t *udp;
+ ipfix_message_header_t *h;
+ ipfix_set_header_t *s;
+ ipfix_template_header_t *t;
+ ipfix_field_specifier_t *f;
+ ipfix_field_specifier_t *first_field;
+ u8 *rewrite = 0;
+ ip4_ipfix_template_packet_t *tp;
u32 field_count = 0;
u32 field_index = 0;
- flow_report_stream_t * stream;
+ flow_report_stream_t *stream;
u8 ip_version;
u8 transport_protocol;
- u8 * virt_mask;
- u8 * real_mask;
+ u8 *virt_mask;
+ u8 *real_mask;
stream = &frm->streams[fr->stream_index];
- ipfix_classify_table_t * table = &fcm->tables[flow_table_index];
+ ipfix_classify_table_t *table = &fcm->tables[flow_table_index];
ip_version = table->ip_version;
transport_protocol = table->transport_protocol;
tblp = pool_elt_at_index (vcm->tables, table->classify_table_index);
- virt_mask = (u8 *)(tblp->mask - tblp->skip_n_vectors);
- real_mask = (u8 *)(tblp->mask);
+ virt_mask = (u8 *) (tblp->mask - tblp->skip_n_vectors);
+ real_mask = (u8 *) (tblp->mask);
/* Determine field count */
- ip_start = virt_mask + sizeof(ethernet_header_t);
+ ip_start = virt_mask + sizeof (ethernet_header_t);
#define _(field,mask,item,length) \
if (((u8 *)&field >= real_mask) && (memcmp(&field, &mask, length) == 0)) \
{ \
@@ -86,18 +88,18 @@ u8 * ipfix_classify_template_rewrite (flow_report_main_t * frm,
/* $$$ enterprise fields, at some later date */
/* allocate rewrite space */
- vec_validate_aligned (rewrite,
- sizeof (ip4_ipfix_template_packet_t)
- + field_count * sizeof (ipfix_field_specifier_t) - 1,
- CLIB_CACHE_LINE_BYTES);
+ vec_validate_aligned (rewrite,
+ sizeof (ip4_ipfix_template_packet_t)
+ + field_count * sizeof (ipfix_field_specifier_t) - 1,
+ CLIB_CACHE_LINE_BYTES);
tp = (ip4_ipfix_template_packet_t *) rewrite;
- ip = (ip4_header_t *) &tp->ip4;
- udp = (udp_header_t *) (ip+1);
- h = (ipfix_message_header_t *)(udp+1);
- s = (ipfix_set_header_t *)(h+1);
- t = (ipfix_template_header_t *)(s+1);
- first_field = f = (ipfix_field_specifier_t *)(t+1);
+ ip = (ip4_header_t *) & tp->ip4;
+ udp = (udp_header_t *) (ip + 1);
+ h = (ipfix_message_header_t *) (udp + 1);
+ s = (ipfix_set_header_t *) (h + 1);
+ t = (ipfix_template_header_t *) (s + 1);
+ first_field = f = (ipfix_field_specifier_t *) (t + 1);
ip->ip_version_and_header_length = 0x45;
ip->ttl = 254;
@@ -106,14 +108,14 @@ u8 * ipfix_classify_template_rewrite (flow_report_main_t * frm,
ip->dst_address.as_u32 = collector_address->as_u32;
udp->src_port = clib_host_to_net_u16 (stream->src_port);
udp->dst_port = clib_host_to_net_u16 (collector_port);
- udp->length = clib_host_to_net_u16 (vec_len(rewrite) - sizeof (*ip));
+ udp->length = clib_host_to_net_u16 (vec_len (rewrite) - sizeof (*ip));
- /* FIXUP: message header export_time */
+ /* FIXUP: message header export_time */
/* FIXUP: message header sequence_number */
h->domain_id = clib_host_to_net_u32 (stream->domain_id);
/* Take another trip through the mask and build the template */
- ip_start = virt_mask + sizeof(ethernet_header_t);
+ ip_start = virt_mask + sizeof (ethernet_header_t);
#define _(field,mask,item,length) \
if (((u8 *)&field >= real_mask) && (memcmp(&field, &mask, length) == 0)) \
{ \
@@ -125,134 +127,135 @@ u8 * ipfix_classify_template_rewrite (flow_report_main_t * frm,
#undef _
/* Add packetTotalCount manually */
- f->e_id_length = ipfix_e_id_length (0 /* enterprise */, packetTotalCount, 8);
+ f->e_id_length =
+ ipfix_e_id_length (0 /* enterprise */ , packetTotalCount, 8);
f++;
/* Back to the template packet... */
- ip = (ip4_header_t *) &tp->ip4;
- udp = (udp_header_t *) (ip+1);
-
+ ip = (ip4_header_t *) & tp->ip4;
+ udp = (udp_header_t *) (ip + 1);
+
ASSERT (f - first_field);
/* Field count in this template */
t->id_count = ipfix_id_count (fr->template_id, f - first_field);
- /* set length in octets*/
- s->set_id_length = ipfix_set_id_length (2 /* set_id */, (u8 *) f - (u8 *)s);
+ /* set length in octets */
+ s->set_id_length =
+ ipfix_set_id_length (2 /* set_id */ , (u8 *) f - (u8 *) s);
/* message length in octets */
- h->version_length = version_length ((u8 *)f - (u8 *)h);
+ h->version_length = version_length ((u8 *) f - (u8 *) h);
- ip->length = clib_host_to_net_u16 ((u8 *)f - (u8 *)ip);
+ ip->length = clib_host_to_net_u16 ((u8 *) f - (u8 *) ip);
ip->checksum = ip4_header_checksum (ip);
return rewrite;
}
-vlib_frame_t * ipfix_classify_send_flows (flow_report_main_t * frm,
- flow_report_t * fr,
- vlib_frame_t * f,
- u32 * to_next,
- u32 node_index)
+vlib_frame_t *
+ipfix_classify_send_flows (flow_report_main_t * frm,
+ flow_report_t * fr,
+ vlib_frame_t * f, u32 * to_next, u32 node_index)
{
- flow_report_classify_main_t * fcm = &flow_report_classify_main;
- vnet_classify_main_t * vcm = &vnet_classify_main;
+ flow_report_classify_main_t *fcm = &flow_report_classify_main;
+ vnet_classify_main_t *vcm = &vnet_classify_main;
u32 flow_table_index = fr->opaque.as_uword;
- vnet_classify_table_t * t;
- vnet_classify_bucket_t * b;
- vnet_classify_entry_t * v, * save_v;
+ vnet_classify_table_t *t;
+ vnet_classify_bucket_t *b;
+ vnet_classify_entry_t *v, *save_v;
vlib_buffer_t *b0 = 0;
u32 next_offset = 0;
u32 record_offset = 0;
u32 bi0 = ~0;
int i, j, k;
- ip4_ipfix_template_packet_t * tp;
- ipfix_message_header_t * h = 0;
- ipfix_set_header_t * s = 0;
- u8 * ip_start;
- ip4_header_t * ip;
- ip6_header_t * ip6;
- tcpudp_header_t * tcpudp;
- udp_header_t * udp;
+ ip4_ipfix_template_packet_t *tp;
+ ipfix_message_header_t *h = 0;
+ ipfix_set_header_t *s = 0;
+ u8 *ip_start;
+ ip4_header_t *ip;
+ ip6_header_t *ip6;
+ tcpudp_header_t *tcpudp;
+ udp_header_t *udp;
int field_index;
u32 records_this_buffer;
u16 new_l0, old_l0;
ip_csum_t sum0;
- vlib_main_t * vm = frm->vlib_main;
- flow_report_stream_t * stream;
+ vlib_main_t *vm = frm->vlib_main;
+ flow_report_stream_t *stream;
u8 ip_version;
u8 transport_protocol;
- u8 * virt_key;
+ u8 *virt_key;
stream = &frm->streams[fr->stream_index];
- ipfix_classify_table_t * table = &fcm->tables[flow_table_index];
+ ipfix_classify_table_t *table = &fcm->tables[flow_table_index];
ip_version = table->ip_version;
transport_protocol = table->transport_protocol;
t = pool_elt_at_index (vcm->tables, table->classify_table_index);
-
+
while (__sync_lock_test_and_set (t->writer_lock, 1))
- ;
-
+ ;
+
for (i = 0; i < t->nbuckets; i++)
{
- b = &t->buckets [i];
+ b = &t->buckets[i];
if (b->offset == 0)
- continue;
-
+ continue;
+
save_v = vnet_classify_get_entry (t, b->offset);
- for (j = 0; j < (1<<b->log2_pages); j++)
- {
- for (k = 0; k < t->entries_per_page; k++)
- {
- v = vnet_classify_entry_at_index
- (t, save_v, j*t->entries_per_page + k);
-
- if (vnet_classify_entry_is_free (v))
- continue;
-
- /* OK, we have something to send... */
- if (PREDICT_FALSE (b0 == 0))
- {
- if (vlib_buffer_alloc (vm, &bi0, 1) != 1)
- goto flush;
- b0 = vlib_get_buffer (vm, bi0);
-
- u32 copy_len = sizeof(ip4_header_t) +
- sizeof(udp_header_t) +
- sizeof(ipfix_message_header_t);
- clib_memcpy (b0->data, fr->rewrite, copy_len);
- b0->current_data = 0;
- b0->current_length = copy_len;
- b0->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
- vnet_buffer (b0)->sw_if_index[VLIB_RX] = 0;
- vnet_buffer (b0)->sw_if_index[VLIB_TX] = frm->fib_index;
-
- tp = vlib_buffer_get_current (b0);
- ip = (ip4_header_t *) &tp->ip4;
- udp = (udp_header_t *) (ip+1);
- h = (ipfix_message_header_t *)(udp+1);
- s = (ipfix_set_header_t *)(h+1);
-
- /* FIXUP: message header export_time */
- h->export_time = (u32)
- (((f64)frm->unix_time_0) +
- (vlib_time_now(frm->vlib_main) - frm->vlib_time_0));
- h->export_time = clib_host_to_net_u32(h->export_time);
-
- /* FIXUP: message header sequence_number */
- h->sequence_number = stream->sequence_number;
- h->sequence_number = clib_host_to_net_u32 (h->sequence_number);
-
- next_offset = (u32) (((u8 *)(s+1)) - (u8 *)tp);
- record_offset = next_offset;
- records_this_buffer = 0;
- }
-
- field_index = 0;
- virt_key = (u8 *)(v->key - t->skip_n_vectors);
- ip_start = virt_key + sizeof(ethernet_header_t);
+ for (j = 0; j < (1 << b->log2_pages); j++)
+ {
+ for (k = 0; k < t->entries_per_page; k++)
+ {
+ v = vnet_classify_entry_at_index
+ (t, save_v, j * t->entries_per_page + k);
+
+ if (vnet_classify_entry_is_free (v))
+ continue;
+
+ /* OK, we have something to send... */
+ if (PREDICT_FALSE (b0 == 0))
+ {
+ if (vlib_buffer_alloc (vm, &bi0, 1) != 1)
+ goto flush;
+ b0 = vlib_get_buffer (vm, bi0);
+
+ u32 copy_len = sizeof (ip4_header_t) +
+ sizeof (udp_header_t) + sizeof (ipfix_message_header_t);
+ clib_memcpy (b0->data, fr->rewrite, copy_len);
+ b0->current_data = 0;
+ b0->current_length = copy_len;
+ b0->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
+ vnet_buffer (b0)->sw_if_index[VLIB_RX] = 0;
+ vnet_buffer (b0)->sw_if_index[VLIB_TX] = frm->fib_index;
+
+ tp = vlib_buffer_get_current (b0);
+ ip = (ip4_header_t *) & tp->ip4;
+ udp = (udp_header_t *) (ip + 1);
+ h = (ipfix_message_header_t *) (udp + 1);
+ s = (ipfix_set_header_t *) (h + 1);
+
+ /* FIXUP: message header export_time */
+ h->export_time = (u32)
+ (((f64) frm->unix_time_0) +
+ (vlib_time_now (frm->vlib_main) - frm->vlib_time_0));
+ h->export_time = clib_host_to_net_u32 (h->export_time);
+
+ /* FIXUP: message header sequence_number */
+ h->sequence_number = stream->sequence_number;
+ h->sequence_number =
+ clib_host_to_net_u32 (h->sequence_number);
+
+ next_offset = (u32) (((u8 *) (s + 1)) - (u8 *) tp);
+ record_offset = next_offset;
+ records_this_buffer = 0;
+ }
+
+ field_index = 0;
+ virt_key = (u8 *) (v->key - t->skip_n_vectors);
+ ip_start = virt_key + sizeof (ethernet_header_t);
#define _(field,mask,item,length) \
if (clib_bitmap_get (fr->fields_to_send, field_index)) \
{ \
@@ -261,166 +264,170 @@ vlib_frame_t * ipfix_classify_send_flows (flow_report_main_t * frm,
next_offset += length; \
} \
field_index++;
- foreach_ipfix_field;
+ foreach_ipfix_field;
#undef _
- /* Add packetTotalCount manually */
- {
- u64 packets = clib_host_to_net_u64 (v->hits);
- clib_memcpy (b0->data + next_offset, &packets, sizeof (packets));
- next_offset += sizeof (packets);
- }
- records_this_buffer++;
- stream->sequence_number++;
-
- /* Next record will have the same size as this record */
- u32 next_record_size = next_offset - record_offset;
- record_offset = next_offset;
-
- if (next_offset + next_record_size > frm->path_mtu)
- {
- s->set_id_length = ipfix_set_id_length (fr->template_id,
- next_offset -
- (sizeof (*ip) + sizeof (*udp) +
- sizeof (*h)));
- h->version_length = version_length (next_offset -
- (sizeof (*ip) + sizeof (*udp)));
- b0->current_length = next_offset;
- b0->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
-
- tp = vlib_buffer_get_current (b0);
- ip = (ip4_header_t *) &tp->ip4;
- udp = (udp_header_t *) (ip+1);
-
- sum0 = ip->checksum;
- old_l0 = ip->length;
- new_l0 =
- clib_host_to_net_u16 ((u16)next_offset);
-
- sum0 = ip_csum_update (sum0, old_l0, new_l0, ip4_header_t,
- length /* changed member */);
-
- ip->checksum = ip_csum_fold (sum0);
- ip->length = new_l0;
- udp->length =
- clib_host_to_net_u16 (b0->current_length - sizeof (*ip));
-
- if (frm->udp_checksum)
- {
- /* RFC 7011 section 10.3.2. */
- udp->checksum = ip4_tcp_udp_compute_checksum (vm, b0, ip);
- if (udp->checksum == 0)
- udp->checksum = 0xffff;
- }
-
- ASSERT (ip->checksum == ip4_header_checksum (ip));
-
- to_next[0] = bi0;
- f->n_vectors++;
- to_next++;
-
- if (f->n_vectors == VLIB_FRAME_SIZE)
- {
- vlib_put_frame_to_node (vm, node_index, f);
- f = vlib_get_frame_to_node (vm, node_index);
- f->n_vectors = 0;
- to_next = vlib_frame_vector_args (f);
- }
- b0 = 0;
- bi0 = ~0;
- }
- }
- }
+ /* Add packetTotalCount manually */
+ {
+ u64 packets = clib_host_to_net_u64 (v->hits);
+ clib_memcpy (b0->data + next_offset, &packets,
+ sizeof (packets));
+ next_offset += sizeof (packets);
+ }
+ records_this_buffer++;
+ stream->sequence_number++;
+
+ /* Next record will have the same size as this record */
+ u32 next_record_size = next_offset - record_offset;
+ record_offset = next_offset;
+
+ if (next_offset + next_record_size > frm->path_mtu)
+ {
+ s->set_id_length = ipfix_set_id_length (fr->template_id,
+ next_offset -
+ (sizeof (*ip) +
+ sizeof (*udp) +
+ sizeof (*h)));
+ h->version_length =
+ version_length (next_offset -
+ (sizeof (*ip) + sizeof (*udp)));
+ b0->current_length = next_offset;
+ b0->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
+
+ tp = vlib_buffer_get_current (b0);
+ ip = (ip4_header_t *) & tp->ip4;
+ udp = (udp_header_t *) (ip + 1);
+
+ sum0 = ip->checksum;
+ old_l0 = ip->length;
+ new_l0 = clib_host_to_net_u16 ((u16) next_offset);
+
+ sum0 = ip_csum_update (sum0, old_l0, new_l0, ip4_header_t,
+ length /* changed member */ );
+
+ ip->checksum = ip_csum_fold (sum0);
+ ip->length = new_l0;
+ udp->length =
+ clib_host_to_net_u16 (b0->current_length - sizeof (*ip));
+
+ if (frm->udp_checksum)
+ {
+ /* RFC 7011 section 10.3.2. */
+ udp->checksum =
+ ip4_tcp_udp_compute_checksum (vm, b0, ip);
+ if (udp->checksum == 0)
+ udp->checksum = 0xffff;
+ }
+
+ ASSERT (ip->checksum == ip4_header_checksum (ip));
+
+ to_next[0] = bi0;
+ f->n_vectors++;
+ to_next++;
+
+ if (f->n_vectors == VLIB_FRAME_SIZE)
+ {
+ vlib_put_frame_to_node (vm, node_index, f);
+ f = vlib_get_frame_to_node (vm, node_index);
+ f->n_vectors = 0;
+ to_next = vlib_frame_vector_args (f);
+ }
+ b0 = 0;
+ bi0 = ~0;
+ }
+ }
+ }
}
-
- flush:
+
+flush:
if (b0)
{
- s->set_id_length = ipfix_set_id_length (fr->template_id,
- next_offset -
- (sizeof (*ip) + sizeof (*udp) +
- sizeof (*h)));
- h->version_length = version_length (next_offset -
- (sizeof (*ip) + sizeof (*udp)));
+ s->set_id_length = ipfix_set_id_length (fr->template_id,
+ next_offset -
+ (sizeof (*ip) + sizeof (*udp) +
+ sizeof (*h)));
+ h->version_length = version_length (next_offset -
+ (sizeof (*ip) + sizeof (*udp)));
b0->current_length = next_offset;
b0->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
-
+
tp = vlib_buffer_get_current (b0);
- ip = (ip4_header_t *) &tp->ip4;
- udp = (udp_header_t *) (ip+1);
-
+ ip = (ip4_header_t *) & tp->ip4;
+ udp = (udp_header_t *) (ip + 1);
+
sum0 = ip->checksum;
old_l0 = ip->length;
- new_l0 = clib_host_to_net_u16 ((u16)next_offset);
-
+ new_l0 = clib_host_to_net_u16 ((u16) next_offset);
+
sum0 = ip_csum_update (sum0, old_l0, new_l0, ip4_header_t,
- length /* changed member */);
-
+ length /* changed member */ );
+
ip->checksum = ip_csum_fold (sum0);
ip->length = new_l0;
udp->length = clib_host_to_net_u16 (b0->current_length - sizeof (*ip));
if (frm->udp_checksum)
- {
- /* RFC 7011 section 10.3.2. */
- udp->checksum = ip4_tcp_udp_compute_checksum (vm, b0, ip);
- if (udp->checksum == 0)
- udp->checksum = 0xffff;
- }
+ {
+ /* RFC 7011 section 10.3.2. */
+ udp->checksum = ip4_tcp_udp_compute_checksum (vm, b0, ip);
+ if (udp->checksum == 0)
+ udp->checksum = 0xffff;
+ }
ASSERT (ip->checksum == ip4_header_checksum (ip));
-
+
to_next[0] = bi0;
f->n_vectors++;
-
+
b0 = 0;
bi0 = ~0;
}
-
+
*(t->writer_lock) = 0;
return f;
}
static clib_error_t *
ipfix_classify_table_add_del_command_fn (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
+ unformat_input_t * input,
+ vlib_cli_command_t * cmd)
{
flow_report_classify_main_t *fcm = &flow_report_classify_main;
flow_report_main_t *frm = &flow_report_main;
vnet_flow_report_add_del_args_t args;
- ipfix_classify_table_t * table;
+ ipfix_classify_table_t *table;
int rv;
int is_add = -1;
u32 classify_table_index = ~0;
u8 ip_version = 0;
u8 transport_protocol = 255;
- clib_error_t * error = 0;
+ clib_error_t *error = 0;
if (fcm->src_port == 0)
clib_error_return (0, "call 'set ipfix classify stream' first");
memset (&args, 0, sizeof (args));
- while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
- if (unformat (input, "add"))
- is_add = 1;
- else if (unformat (input, "del"))
- is_add = 0;
- else if (unformat (input, "%d", &classify_table_index))
- ;
- else if (unformat (input, "ip4"))
- ip_version = 4;
- else if (unformat (input, "ip6"))
- ip_version = 6;
- else if (unformat (input, "tcp"))
- transport_protocol = 6;
- else if (unformat (input, "udp"))
- transport_protocol = 17;
- else
- return clib_error_return (0, "unknown input `%U'",
- format_unformat_error, input);
- }
+ while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (input, "add"))
+ is_add = 1;
+ else if (unformat (input, "del"))
+ is_add = 0;
+ else if (unformat (input, "%d", &classify_table_index))
+ ;
+ else if (unformat (input, "ip4"))
+ ip_version = 4;
+ else if (unformat (input, "ip6"))
+ ip_version = 6;
+ else if (unformat (input, "tcp"))
+ transport_protocol = 6;
+ else if (unformat (input, "udp"))
+ transport_protocol = 17;
+ else
+ return clib_error_return (0, "unknown input `%U'",
+ format_unformat_error, input);
+ }
if (is_add == -1)
return clib_error_return (0, "expecting: add|del");
@@ -431,22 +438,28 @@ ipfix_classify_table_add_del_command_fn (vlib_main_t * vm,
table = 0;
int i;
- for (i = 0; i < vec_len(fcm->tables); i++)
- if (ipfix_classify_table_index_valid(i))
- if (fcm->tables[i].classify_table_index == classify_table_index) {
- table = &fcm->tables[i];
- break;
- }
-
- if (is_add) {
- if (table)
- return clib_error_return (0, "Specified classifier table already used");
- table = ipfix_classify_add_table();
- table->classify_table_index = classify_table_index;
- } else {
- if (!table)
- return clib_error_return (0, "Specified classifier table not registered");
- }
+ for (i = 0; i < vec_len (fcm->tables); i++)
+ if (ipfix_classify_table_index_valid (i))
+ if (fcm->tables[i].classify_table_index == classify_table_index)
+ {
+ table = &fcm->tables[i];
+ break;
+ }
+
+ if (is_add)
+ {
+ if (table)
+ return clib_error_return (0,
+ "Specified classifier table already used");
+ table = ipfix_classify_add_table ();
+ table->classify_table_index = classify_table_index;
+ }
+ else
+ {
+ if (!table)
+ return clib_error_return (0,
+ "Specified classifier table not registered");
+ }
table->ip_version = ip_version;
table->transport_protocol = transport_protocol;
@@ -460,7 +473,7 @@ ipfix_classify_table_add_del_command_fn (vlib_main_t * vm,
rv = vnet_flow_report_add_del (frm, &args, NULL);
- error = flow_report_add_del_error_to_clib_error(rv);
+ error = flow_report_add_del_error_to_clib_error (rv);
/* If deleting, or add failed */
if (is_add == 0 || (rv && is_add))
@@ -469,57 +482,62 @@ ipfix_classify_table_add_del_command_fn (vlib_main_t * vm,
return error;
}
+/* *INDENT-OFF* */
VLIB_CLI_COMMAND (ipfix_classify_table_add_del_command, static) = {
.path = "ipfix classify table",
.short_help = "ipfix classify table add|del <table-index>",
.function = ipfix_classify_table_add_del_command_fn,
};
+/* *INDENT-ON* */
static clib_error_t *
set_ipfix_classify_stream_command_fn (vlib_main_t * vm,
- unformat_input_t * input,
- vlib_cli_command_t * cmd)
+ unformat_input_t * input,
+ vlib_cli_command_t * cmd)
{
flow_report_classify_main_t *fcm = &flow_report_classify_main;
flow_report_main_t *frm = &flow_report_main;
u32 domain_id = 1;
u32 src_port = UDP_DST_PORT_ipfix;
- while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
- if (unformat (input, "domain %d", &domain_id))
- ;
- else if (unformat (input, "src-port %d", &src_port))
- ;
- else
- return clib_error_return (0, "unknown input `%U'",
- format_unformat_error, input);
- }
+ while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (input, "domain %d", &domain_id))
+ ;
+ else if (unformat (input, "src-port %d", &src_port))
+ ;
+ else
+ return clib_error_return (0, "unknown input `%U'",
+ format_unformat_error, input);
+ }
if (fcm->src_port != 0 &&
- (fcm->domain_id != domain_id ||
- fcm->src_port != (u16)src_port)) {
- int rv = vnet_stream_change (frm, fcm->domain_id, fcm->src_port,
- domain_id, (u16)src_port);
- ASSERT (rv == 0);
- }
+ (fcm->domain_id != domain_id || fcm->src_port != (u16) src_port))
+ {
+ int rv = vnet_stream_change (frm, fcm->domain_id, fcm->src_port,
+ domain_id, (u16) src_port);
+ ASSERT (rv == 0);
+ }
fcm->domain_id = domain_id;
- fcm->src_port = (u16)src_port;
+ fcm->src_port = (u16) src_port;
return 0;
}
+/* *INDENT-OFF* */
VLIB_CLI_COMMAND (set_ipfix_classify_stream_command, static) = {
.path = "set ipfix classify stream",
.short_help = "set ipfix classify stream"
"[domain <domain-id>] [src-port <src-port>]",
.function = set_ipfix_classify_stream_command_fn,
};
+/* *INDENT-ON* */
static clib_error_t *
-flow_report_classify_init (vlib_main_t *vm)
+flow_report_classify_init (vlib_main_t * vm)
{
- clib_error_t * error;
+ clib_error_t *error;
if ((error = vlib_call_init_function (vm, flow_report_init)))
return error;
@@ -528,3 +546,11 @@ flow_report_classify_init (vlib_main_t *vm)
}
VLIB_INIT_FUNCTION (flow_report_classify_init);
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/vnet/flow/flow_report_classify.h b/src/vnet/flow/flow_report_classify.h
index 77d98b586ca..0533b450122 100644
--- a/src/vnet/flow/flow_report_classify.h
+++ b/src/vnet/flow/flow_report_classify.h
@@ -66,57 +66,69 @@ _(tcpudp->dst_port, ((u16[]){0xFFFF}), udpDestinationPort, 2)
} \
foreach_ipfix_transport_protocol_field
-typedef struct {
+typedef struct
+{
u32 classify_table_index;
u8 ip_version;
u8 transport_protocol;
} ipfix_classify_table_t;
-typedef struct {
+typedef struct
+{
u32 domain_id;
u16 src_port;
- ipfix_classify_table_t * tables;
+ ipfix_classify_table_t *tables;
} flow_report_classify_main_t;
extern flow_report_classify_main_t flow_report_classify_main;
-static_always_inline u8 ipfix_classify_table_index_valid (u32 index)
+static_always_inline u8
+ipfix_classify_table_index_valid (u32 index)
{
- flow_report_classify_main_t * fcm = &flow_report_classify_main;
- return index < vec_len(fcm->tables) &&
- fcm->tables[index].classify_table_index != ~0;
+ flow_report_classify_main_t *fcm = &flow_report_classify_main;
+ return index < vec_len (fcm->tables) &&
+ fcm->tables[index].classify_table_index != ~0;
}
-static_always_inline ipfix_classify_table_t * ipfix_classify_add_table (void)
+static_always_inline ipfix_classify_table_t *
+ipfix_classify_add_table (void)
{
- flow_report_classify_main_t * fcm = &flow_report_classify_main;
+ flow_report_classify_main_t *fcm = &flow_report_classify_main;
u32 i;
- for (i = 0; i < vec_len(fcm->tables); i++)
- if (!ipfix_classify_table_index_valid(i))
+ for (i = 0; i < vec_len (fcm->tables); i++)
+ if (!ipfix_classify_table_index_valid (i))
return &fcm->tables[i];
- u32 index = vec_len(fcm->tables);
- vec_validate(fcm->tables, index);
+ u32 index = vec_len (fcm->tables);
+ vec_validate (fcm->tables, index);
return &fcm->tables[index];
}
-static_always_inline void ipfix_classify_delete_table (u32 index)
+static_always_inline void
+ipfix_classify_delete_table (u32 index)
{
- flow_report_classify_main_t * fcm = &flow_report_classify_main;
- ASSERT (index < vec_len(fcm->tables));
+ flow_report_classify_main_t *fcm = &flow_report_classify_main;
+ ASSERT (index < vec_len (fcm->tables));
ASSERT (fcm->tables[index].classify_table_index != ~0);
fcm->tables[index].classify_table_index = ~0;
}
-u8 * ipfix_classify_template_rewrite (flow_report_main_t * frm,
- flow_report_t * fr,
- ip4_address_t * collector_address,
- ip4_address_t * src_address,
- u16 collector_port);
+u8 *ipfix_classify_template_rewrite (flow_report_main_t * frm,
+ flow_report_t * fr,
+ ip4_address_t * collector_address,
+ ip4_address_t * src_address,
+ u16 collector_port);
-vlib_frame_t * ipfix_classify_send_flows (flow_report_main_t * frm,
- flow_report_t * fr,
- vlib_frame_t * f,
- u32 * to_next,
- u32 node_index);
+vlib_frame_t *ipfix_classify_send_flows (flow_report_main_t * frm,
+ flow_report_t * fr,
+ vlib_frame_t * f,
+ u32 * to_next, u32 node_index);
#endif /* __included_flow_report_classify_h__ */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/vnet/flow/ipfix_info_elements.h b/src/vnet/flow/ipfix_info_elements.h
index 1403db4393b..ee6f53804bf 100644
--- a/src/vnet/flow/ipfix_info_elements.h
+++ b/src/vnet/flow/ipfix_info_elements.h
@@ -421,10 +421,19 @@ _(pseudoWireDestinationIPv4Address, 432, ip4_address_t) \
_(ignoredLayer2FrameTotalCount, 433, u64) \
_(natQuotaExceededEvent, 466, u32)
-typedef enum {
+typedef enum
+{
#define _(n,v,t) n = v,
foreach_ipfix_info_element_t
#undef _
} ipfix_info_element_id_t;
#endif /* __included_ipfix_info_elements_h__ */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/vnet/flow/ipfix_packet.h b/src/vnet/flow/ipfix_packet.h
index 329796191de..a50d86ea379 100644
--- a/src/vnet/flow/ipfix_packet.h
+++ b/src/vnet/flow/ipfix_packet.h
@@ -21,14 +21,16 @@
* https://tools.ietf.org/html/rfc7011
*/
-typedef struct {
+typedef struct
+{
u32 version_length;
u32 export_time;
u32 sequence_number;
u32 domain_id;
} ipfix_message_header_t;
-static inline u32 version_length (u16 length)
+static inline u32
+version_length (u16 length)
{
return clib_host_to_net_u32 (0x000a0000 | length);
}
@@ -60,23 +62,26 @@ static inline u32 version_length (u16 length)
* present.
*/
-typedef struct {
+typedef struct
+{
u32 e_id_length;
u32 enterprise;
} ipfix_enterprise_field_specifier_t;
-typedef struct {
+typedef struct
+{
u32 e_id_length;
} ipfix_field_specifier_t;
-static inline u32 ipfix_e_id_length (int e, u16 id, u16 length)
+static inline u32
+ipfix_e_id_length (int e, u16 id, u16 length)
{
u32 value;
- value = (e<<31) | ((id&0x7FFF) <<16) | length;
+ value = (e << 31) | ((id & 0x7FFF) << 16) | length;
return clib_host_to_net_u32 (value);
}
-/*
+/*
* Every Set contains a common header. This header is defined in
* Figure I.
*
@@ -107,16 +112,18 @@ static inline u32 ipfix_e_id_length (int e, u16 id, u16 length)
* determine the position of the next Set.
*/
-typedef struct {
+typedef struct
+{
u32 set_id_length;
} ipfix_set_header_t;
-static inline u32 ipfix_set_id_length (u16 set_id, u16 length)
+static inline u32
+ipfix_set_id_length (u16 set_id, u16 length)
{
- return clib_host_to_net_u32 ((set_id<<16) | length);
+ return clib_host_to_net_u32 ((set_id << 16) | length);
}
-/*
+/*
* The format of the Template Record is shown in Figure J. It consists
* of a Template Record Header and one or more Field Specifiers. Field
* Specifiers are defined in Figure G above.
@@ -168,17 +175,20 @@ static inline u32 ipfix_set_id_length (u16 set_id, u16 length)
* Number of fields in this Template Record.
*/
-typedef struct {
+typedef struct
+{
u32 id_count;
} ipfix_template_header_t;
-static inline u32 ipfix_id_count (u16 id, u16 count)
+static inline u32
+ipfix_id_count (u16 id, u16 count)
{
- return clib_host_to_net_u32 ((id<<16) | count);
+ return clib_host_to_net_u32 ((id << 16) | count);
}
/* Template packet */
-typedef struct {
+typedef struct
+{
ipfix_message_header_t h;
ipfix_set_header_t s;
ipfix_template_header_t t;
@@ -186,3 +196,11 @@ typedef struct {
} ipfix_template_packet_t;
#endif /* __included_ipfix_packet_h__ */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */