diff options
author | Dave Barach <dave@barachs.net> | 2018-05-13 08:50:25 -0400 |
---|---|---|
committer | Florin Coras <florin.coras@gmail.com> | 2018-05-13 17:55:24 +0000 |
commit | 2be45813c757137000878dc711dd169fc2d414af (patch) | |
tree | a695bbb512468c9abff710a1542a75bc3cb95e9d /src/plugins/nat | |
parent | 078371e32c41c6c63d8e49964d2046a5dd90de48 (diff) |
Improve ipfix template packet rewrite construction
Instead of repeatedly cutting, pasting, and hacking to create a new
callback, use vnet_flow_rewrite_generic_callback(). Add three
arguments to the flow rewrite callback:
(in) pointer to an array of report elements,
(in) length of array,
(out) pointer to the stream index
Change existing code prototypes. Code owners encouraged to evaluate
whether they can use the generic callback or not, at leisure.
/* ipfix field definitions for a particular report */
typedef struct
{
u32 info_element;
u32 size;
} ipfix_report_element_t;
Best generated like so:
_(sourceIPv4Address, 4) \
_(destinationIPv4Address, 4) \
_(sourceTransportPort, 2) \
_(destinationTransportPort, 2) \
_(protocolIdentifier, 1) \
_(flowStartMicroseconds, 8) \
_(flowEndMicroseconds, 8)
static ipfix_report_element_t simple_report_elements[] = {
foreach_simple_report_ipfix_element
};
...
/* Set up the ipfix report */
memset (&a, 0, sizeof (a));
a.is_add = 1 /* to enable the report */ ;
a.domain_id = 1 /* pick a domain ID */ ;
a.src_port = UDP_DST_PORT_ipfix /* src port for reports */ ;
a.rewrite_callback = vnet_flow_rewrite_generic_callback;
a.report_elements = simple_report_elements;
a.n_report_elements = ARRAY_LEN (simple_report_elements);
a.stream_indexp = &jim->stream_index;
a.flow_data_callback = simple_flow_data_callback;
/* Create the report */
rv = vnet_flow_report_add_del (frm, &a, &template_id);
if (rv)
return rv;
...
Change-Id: If6131e6821d3a37a29269c0d58040cdf18ff05e4
Signed-off-by: Dave Barach <dave@barachs.net>
Diffstat (limited to 'src/plugins/nat')
-rw-r--r-- | src/plugins/nat/nat_ipfix_logging.c | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/src/plugins/nat/nat_ipfix_logging.c b/src/plugins/nat/nat_ipfix_logging.c index b4b940e7f92..0f291337b0c 100644 --- a/src/plugins/nat/nat_ipfix_logging.c +++ b/src/plugins/nat/nat_ipfix_logging.c @@ -403,7 +403,9 @@ snat_template_rewrite_addr_exhausted (flow_report_main_t * frm, flow_report_t * fr, ip4_address_t * collector_address, ip4_address_t * src_address, - u16 collector_port) + u16 collector_port, + ipfix_report_element_t *elts, + u32 n_elts, u32 *stream_index) { return snat_template_rewrite (frm, fr, collector_address, src_address, collector_port, NAT_ADDRESSES_EXHAUTED, 0); @@ -414,7 +416,9 @@ snat_template_rewrite_nat44_session (flow_report_main_t * frm, flow_report_t * fr, ip4_address_t * collector_address, ip4_address_t * src_address, - u16 collector_port) + u16 collector_port, + ipfix_report_element_t *elts, + u32 n_elts, u32 *stream_index) { return snat_template_rewrite (frm, fr, collector_address, src_address, collector_port, NAT44_SESSION_CREATE, 0); @@ -425,7 +429,9 @@ snat_template_rewrite_max_entries_per_usr (flow_report_main_t * frm, flow_report_t * fr, ip4_address_t * collector_address, ip4_address_t * src_address, - u16 collector_port) + u16 collector_port, + ipfix_report_element_t *elts, + u32 n_elts, u32 *stream_index) { return snat_template_rewrite (frm, fr, collector_address, src_address, collector_port, QUOTA_EXCEEDED, @@ -437,7 +443,9 @@ nat_template_rewrite_max_sessions (flow_report_main_t * frm, flow_report_t * fr, ip4_address_t * collector_address, ip4_address_t * src_address, - u16 collector_port) + u16 collector_port, + ipfix_report_element_t *elts, + u32 n_elts, u32 *stream_index) { return snat_template_rewrite (frm, fr, collector_address, src_address, collector_port, QUOTA_EXCEEDED, @@ -449,7 +457,9 @@ nat_template_rewrite_max_bibs (flow_report_main_t * frm, flow_report_t * fr, ip4_address_t * collector_address, ip4_address_t * src_address, - u16 collector_port) + u16 collector_port, + ipfix_report_element_t *elts, + u32 n_elts, u32 *stream_index) { return snat_template_rewrite (frm, fr, collector_address, src_address, collector_port, QUOTA_EXCEEDED, @@ -461,7 +471,9 @@ nat_template_rewrite_max_frags_ip4 (flow_report_main_t * frm, flow_report_t * fr, ip4_address_t * collector_address, ip4_address_t * src_address, - u16 collector_port) + u16 collector_port, + ipfix_report_element_t *elts, + u32 n_elts, u32 *stream_index) { return snat_template_rewrite (frm, fr, collector_address, src_address, collector_port, QUOTA_EXCEEDED, @@ -473,7 +485,9 @@ nat_template_rewrite_max_frags_ip6 (flow_report_main_t * frm, flow_report_t * fr, ip4_address_t * collector_address, ip4_address_t * src_address, - u16 collector_port) + u16 collector_port, + ipfix_report_element_t *elts, + u32 n_elts, u32 *stream_index) { return snat_template_rewrite (frm, fr, collector_address, src_address, collector_port, QUOTA_EXCEEDED, @@ -485,7 +499,9 @@ nat_template_rewrite_nat64_bib (flow_report_main_t * frm, flow_report_t * fr, ip4_address_t * collector_address, ip4_address_t * src_address, - u16 collector_port) + u16 collector_port, + ipfix_report_element_t *elts, + u32 n_elts, u32 *stream_index) { return snat_template_rewrite (frm, fr, collector_address, src_address, collector_port, NAT64_BIB_CREATE, 0); @@ -496,7 +512,9 @@ nat_template_rewrite_nat64_session (flow_report_main_t * frm, flow_report_t * fr, ip4_address_t * collector_address, ip4_address_t * src_address, - u16 collector_port) + u16 collector_port, + ipfix_report_element_t *elts, + u32 n_elts, u32 *stream_index) { return snat_template_rewrite (frm, fr, collector_address, src_address, collector_port, NAT64_SESSION_CREATE, 0); |