FreeBSD/sys/netgraph/netflow/netflow_v9.c
/*
 * Pre-compiles flow exporter for all possible FlowSets
 * so we can add flowset to packet via simple memcpy()
 */
Pre-compiles flow exporter for all possible FlowSets
so we can add flowset to packet via simple memcpy()
Pre - compiles flow exporter for all possible FlowSets so we can add flowset to packet via simple memcpy ()
static void
generate_v9_templates(priv_p priv)
{
	uint16_t *p, *template_fields_cnt;
	int cnt;
	int flowset_size = sizeof(struct netflow_v9_flowset_header) +
		_NETFLOW_V9_TEMPLATE_SIZE(_netflow_v9_record_ipv4_tcp) + 
		_NETFLOW_V9_TEMPLATE_SIZE(_netflow_v9_record_ipv6_tcp); 
	priv->v9_flowsets[0] = malloc(flowset_size, M_NETFLOW_GENERAL, M_WAITOK | M_ZERO);
	if (flowset_size % 4)
		flowset_size += 4 - (flowset_size % 4); 
	priv->flowsets_count = 1;
	p = (uint16_t *)priv->v9_flowsets[0];
	*p++ = 0; 
	*p++ = htons(flowset_size); 
	*p++ = htons(NETFLOW_V9_MAX_RESERVED_FLOWSET + NETFLOW_V9_FLOW_V4_L4);
	template_fields_cnt = p++;
	for (cnt = 0; _netflow_v9_record_ipv4_tcp[cnt].field_id != 0; cnt++) {
		*p++ = htons(_netflow_v9_record_ipv4_tcp[cnt].field_id);
		*p++ = htons(_netflow_v9_record_ipv4_tcp[cnt].field_length);
	}
	*template_fields_cnt = htons(cnt);
	*p++ = htons(NETFLOW_V9_MAX_RESERVED_FLOWSET + NETFLOW_V9_FLOW_V6_L4);
	template_fields_cnt = p++;
	for (cnt = 0; _netflow_v9_record_ipv6_tcp[cnt].field_id != 0; cnt++) {
		*p++ = htons(_netflow_v9_record_ipv6_tcp[cnt].field_id);
		*p++ = htons(_netflow_v9_record_ipv6_tcp[cnt].field_length);
	}
	*template_fields_cnt = htons(cnt);
	priv->flowset_records[0] = 2;
}
static void generate_v9_templates ( priv_p priv ) { uint16_t * p , * template_fields_cnt ; int cnt ; int flowset_size = sizeof ( struct netflow_v9_flowset_header ) + _NETFLOW_V9_TEMPLATE_SIZE ( _netflow_v9_record_ipv4_tcp ) + _NETFLOW_V9_TEMPLATE_SIZE ( _netflow_v9_record_ipv6_tcp ) ; priv -> v9_flowsets [ 0 ] = malloc ( flowset_size , M_NETFLOW_GENERAL , M_WAITOK | M_ZERO ) ; if ( flowset_size % 4 ) flowset_size += 4 - ( flowset_size % 4 ) ; priv -> flowsets_count = 1 ; p = ( uint16_t * ) priv -> v9_flowsets [ 0 ] ; * p ++ = 0 ; * p ++ = htons ( flowset_size ) ; * p ++ = htons ( NETFLOW_V9_MAX_RESERVED_FLOWSET + NETFLOW_V9_FLOW_V4_L4 ) ; template_fields_cnt = p ++ ; for ( cnt = 0 ; _netflow_v9_record_ipv4_tcp [ cnt ] . field_id != 0 ; cnt ++ ) { * p ++ = htons ( _netflow_v9_record_ipv4_tcp [ cnt ] . field_id ) ; * p ++ = htons ( _netflow_v9_record_ipv4_tcp [ cnt ] . field_length ) ; } * template_fields_cnt = htons ( cnt ) ; * p ++ = htons ( NETFLOW_V9_MAX_RESERVED_FLOWSET + NETFLOW_V9_FLOW_V6_L4 ) ; template_fields_cnt = p ++ ; for ( cnt = 0 ; _netflow_v9_record_ipv6_tcp [ cnt ] . field_id != 0 ; cnt ++ ) { * p ++ = htons ( _netflow_v9_record_ipv6_tcp [ cnt ] . field_id ) ; * p ++ = htons ( _netflow_v9_record_ipv6_tcp [ cnt ] . field_length ) ; } * template_fields_cnt = htons ( cnt ) ; priv -> flowset_records [ 0 ] = 2 ; }
Pre-compiles flow exporter for all possible FlowSets
 so we can add flowset to packet via simple memcpy()
Pre - compiles flow exporter for all possible FlowSets so we can add flowset to packet via simple memcpy ()
/* netflow_v9_record_ipv4_tcp */ /* netflow_v9_record_ipv6_tcp */ /* Padding to 4-byte boundary */ /* Flowset ID, 0 is reserved for Template FlowSets  */ /* Total FlowSet length */ /*
	 * Most common TCP/UDP IPv4 template, ID = 256
	 */ /*
	 * TCP/UDP IPv6 template, ID = 257
	 */