Skip to content

Commit

Permalink
* fix, SQL plugins: in_vlan not muxed anymore on vlan at configure ti…
Browse files Browse the repository at this point in the history
…me. To address Issues #695 , #696
  • Loading branch information
paololucente committed Jul 4, 2023
1 parent 4211f4f commit 5a5e272
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 65 deletions.
1 change: 0 additions & 1 deletion src/cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,6 @@ struct configuration {
int pcap_arista_trailer_flag_value;
int dump_max_writers;
int tmp_asa_bi_flow;
int tmp_vlan_legacy;
int tmp_bgp_lookup_compare_ports;
int tmp_bgp_daemon_route_refresh;
int tmp_bgp_daemon_origin_type_int;
Expand Down
7 changes: 2 additions & 5 deletions src/cfg_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,8 @@ int cfg_key_aggregate(char *filename, char *name, char *value_ptr)
else if (!strcmp(count_token, "src_mac")) cfg_set_aggregate(filename, value, COUNT_INT_SRC_MAC, count_token);
else if (!strcmp(count_token, "dst_mac")) cfg_set_aggregate(filename, value, COUNT_INT_DST_MAC, count_token);
else if (!strcmp(count_token, "out_vlan")) cfg_set_aggregate(filename, value, COUNT_INT_OUT_VLAN, count_token);
else if (!strcmp(count_token, "in_vlan")) cfg_set_aggregate(filename, value, COUNT_INT_VLAN, count_token);
else if (!strcmp(count_token, "vlan")) {
cfg_set_aggregate(filename, value, COUNT_INT_VLAN, count_token);
config.tmp_vlan_legacy = TRUE;
}
else if (!strcmp(count_token, "in_vlan")) cfg_set_aggregate(filename, value, COUNT_INT_IN_VLAN, count_token);
else if (!strcmp(count_token, "vlan")) cfg_set_aggregate(filename, value, COUNT_INT_VLAN, count_token);
else if (!strcmp(count_token, "sum_mac")) cfg_set_aggregate(filename, value, COUNT_INT_SUM_MAC, count_token);
#else
else if (!strcmp(count_token, "src_mac") || !strcmp(count_token, "dst_mac") ||
Expand Down
11 changes: 5 additions & 6 deletions src/mongodb_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,12 +514,11 @@ void MongoDB_cache_purge(struct chained_cache *queue[], int index, int safe_acti
}

if (config.what_to_count & COUNT_VLAN) {
if (config.tmp_vlan_legacy) {
bson_append_int(bson_elem, "vlan", data->vlan_id);
}
else {
bson_append_int(bson_elem, "vlan_in", data->vlan_id);
}
bson_append_int(bson_elem, "vlan", data->vlan_id);
}

if (config.what_to_count_3 & COUNT_IN_VLAN) {
bson_append_int(bson_elem, "vlan_in", data->vlan_id);
}

if (config.what_to_count_2 & COUNT_OUT_VLAN) {
Expand Down
23 changes: 11 additions & 12 deletions src/pkt_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,17 @@ void evaluate_packet_handlers()
}

if (channels_list[index].aggregation & COUNT_VLAN) {
if (config.tmp_vlan_legacy) {
if (config.acct_type == ACCT_PM) channels_list[index].phandler[primitives] = vlan_handler;
else if (config.acct_type == ACCT_NF) channels_list[index].phandler[primitives] = NF_vlan_handler;
else if (config.acct_type == ACCT_SF) channels_list[index].phandler[primitives] = SF_vlan_handler;
primitives++;
}
else {
if (config.acct_type == ACCT_PM) channels_list[index].phandler[primitives] = vlan_handler;
else if (config.acct_type == ACCT_NF) channels_list[index].phandler[primitives] = NF_in_vlan_handler;
else if (config.acct_type == ACCT_SF) channels_list[index].phandler[primitives] = SF_in_vlan_handler;
primitives++;
}
if (config.acct_type == ACCT_PM) channels_list[index].phandler[primitives] = vlan_handler;
else if (config.acct_type == ACCT_NF) channels_list[index].phandler[primitives] = NF_vlan_handler;
else if (config.acct_type == ACCT_SF) channels_list[index].phandler[primitives] = SF_vlan_handler;
primitives++;
}

if (channels_list[index].aggregation_3 & COUNT_IN_VLAN) {
if (config.acct_type == ACCT_PM) channels_list[index].phandler[primitives] = vlan_handler;
else if (config.acct_type == ACCT_NF) channels_list[index].phandler[primitives] = NF_in_vlan_handler;
else if (config.acct_type == ACCT_SF) channels_list[index].phandler[primitives] = SF_in_vlan_handler;
primitives++;
}

if (channels_list[index].aggregation_2 & COUNT_OUT_VLAN) {
Expand Down
28 changes: 12 additions & 16 deletions src/plugin_cmn_avro.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,11 @@ avro_schema_t p_avro_schema_build_acct_data(u_int64_t wtc, u_int64_t wtc_2, u_in
if (wtc & COUNT_DST_MAC)
avro_schema_record_field_append(schema, "mac_dst", avro_schema_string());

if (wtc & COUNT_VLAN) {
if (config.tmp_vlan_legacy) {
avro_schema_record_field_append(schema, "vlan", avro_schema_long());
}
else {
avro_schema_record_field_append(schema, "vlan_in", avro_schema_long());
}
}
if (wtc & COUNT_VLAN)
avro_schema_record_field_append(schema, "vlan", avro_schema_long());

if (wtc_3 & COUNT_IN_VLAN)
avro_schema_record_field_append(schema, "vlan_in", avro_schema_long());

if (wtc_2 & COUNT_OUT_VLAN)
avro_schema_record_field_append(schema, "vlan_out", avro_schema_long());
Expand Down Expand Up @@ -538,14 +535,13 @@ avro_value_t compose_avro_acct_data(u_int64_t wtc, u_int64_t wtc_2, u_int64_t wt
}

if (wtc & COUNT_VLAN) {
if (config.tmp_vlan_legacy) {
pm_avro_check(avro_value_get_by_name(&value, "vlan", &field, NULL));
pm_avro_check(avro_value_set_long(&field, pbase->vlan_id));
}
else {
pm_avro_check(avro_value_get_by_name(&value, "vlan_in", &field, NULL));
pm_avro_check(avro_value_set_long(&field, pbase->vlan_id));
}
pm_avro_check(avro_value_get_by_name(&value, "vlan", &field, NULL));
pm_avro_check(avro_value_set_long(&field, pbase->vlan_id));
}

if (wtc_3 & COUNT_VLAN) {
pm_avro_check(avro_value_get_by_name(&value, "vlan_in", &field, NULL));
pm_avro_check(avro_value_set_long(&field, pbase->vlan_id));
}

if (wtc_2 & COUNT_OUT_VLAN) {
Expand Down
17 changes: 11 additions & 6 deletions src/plugin_cmn_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ void compose_json(u_int64_t wtc, u_int64_t wtc_2, u_int64_t wtc_3)
idx++;
}

if (wtc_3 & COUNT_IN_VLAN) {
cjhandler[idx] = compose_json_in_vlan;
idx++;
}

if (wtc_2 & COUNT_OUT_VLAN) {
cjhandler[idx] = compose_json_out_vlan;
idx++;
Expand Down Expand Up @@ -606,12 +611,12 @@ void compose_json_dst_mac(json_t *obj, struct chained_cache *cc)

void compose_json_vlan(json_t *obj, struct chained_cache *cc)
{
if (config.tmp_vlan_legacy) {
json_object_set_new_nocheck(obj, "vlan", json_integer((json_int_t)cc->primitives.vlan_id));
}
else {
json_object_set_new_nocheck(obj, "vlan_in", json_integer((json_int_t)cc->primitives.vlan_id));
}
json_object_set_new_nocheck(obj, "vlan", json_integer((json_int_t)cc->primitives.vlan_id));
}

void compose_json_in_vlan(json_t *obj, struct chained_cache *cc)
{
json_object_set_new_nocheck(obj, "vlan_in", json_integer((json_int_t)cc->primitives.vlan_id));
}

void compose_json_out_vlan(json_t *obj, struct chained_cache *cc)
Expand Down
1 change: 1 addition & 0 deletions src/plugin_cmn_json.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ extern void compose_json_ndpi_class(json_t *, struct chained_cache *);
extern void compose_json_src_mac(json_t *, struct chained_cache *);
extern void compose_json_dst_mac(json_t *, struct chained_cache *);
extern void compose_json_vlan(json_t *, struct chained_cache *);
extern void compose_json_in_vlan(json_t *, struct chained_cache *);
extern void compose_json_out_vlan(json_t *, struct chained_cache *);
extern void compose_json_cos(json_t *, struct chained_cache *);
extern void compose_json_etype(json_t *, struct chained_cache *);
Expand Down
2 changes: 2 additions & 0 deletions src/pmacct-defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@
/* internal: third registry, ie. what_to_count_3, aggregation_3, etc. */
#define COUNT_INT_FLOW_LABEL 0x0003000000000001ULL
#define COUNT_INT_TUNNEL_FLOW_LABEL 0x0003000000000002ULL
#define COUNT_INT_IN_VLAN 0x0003000000000004ULL

#define COUNT_INDEX_MASK 0xFFFF
#define COUNT_INDEX_CP 0xFFFF000000000000ULL /* index 0xffff reserved to custom primitives */
Expand Down Expand Up @@ -372,6 +373,7 @@
#define COUNT_MPLS_LABEL_STACK (COUNT_INT_MPLS_LABEL_STACK & COUNT_REGISTRY_MASK)
#define COUNT_FW_EVENT (COUNT_INT_FW_EVENT & COUNT_REGISTRY_MASK)
#define COUNT_TUNNEL_TCPFLAGS (COUNT_INT_TUNNEL_TCPFLAGS & COUNT_REGISTRY_MASK)
#define COUNT_IN_VLAN (COUNT_INT_IN_VLAN & COUNT_REGISTRY_MASK)
#define COUNT_OUT_VLAN (COUNT_INT_OUT_VLAN & COUNT_REGISTRY_MASK)
#define COUNT_PATH_DELAY_AVG_USEC (COUNT_INT_PATH_DELAY_AVG_USEC & COUNT_REGISTRY_MASK)
#define COUNT_PATH_DELAY_MIN_USEC (COUNT_INT_PATH_DELAY_MIN_USEC & COUNT_REGISTRY_MASK)
Expand Down
22 changes: 6 additions & 16 deletions src/print_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ void P_cache_purge(struct chained_cache *queue[], int index, int safe_action)
fprintf(f, "%-17s ", empty_macaddress);
}
if (config.what_to_count & COUNT_VLAN) fprintf(f, "%-5u ", data->vlan_id);
if (config.what_to_count_3 & COUNT_IN_VLAN) fprintf(f, "%-7u ", data->vlan_id);
if (config.what_to_count_2 & COUNT_OUT_VLAN) fprintf(f, "%-8u ", data->out_vlan_id);
if (config.what_to_count & COUNT_COS) fprintf(f, "%-2u ", data->cos);
if (config.what_to_count & COUNT_ETHERTYPE) fprintf(f, "%-5x ", data->etype);
Expand Down Expand Up @@ -938,6 +939,7 @@ void P_cache_purge(struct chained_cache *queue[], int index, int safe_action)
fprintf(f, "%s%s", write_sep(sep, &count), dst_mac);
}
if (config.what_to_count & COUNT_VLAN) fprintf(f, "%s%u", write_sep(sep, &count), data->vlan_id);
if (config.what_to_count_3 & COUNT_IN_VLAN) fprintf(f, "%s%u", write_sep(sep, &count), data->vlan_id);
if (config.what_to_count_2 & COUNT_OUT_VLAN) fprintf(f, "%s%u", write_sep(sep, &count), data->out_vlan_id);
if (config.what_to_count & COUNT_COS) fprintf(f, "%s%u", write_sep(sep, &count), data->cos);
if (config.what_to_count & COUNT_ETHERTYPE) fprintf(f, "%s%x", write_sep(sep, &count), data->etype);
Expand Down Expand Up @@ -1443,14 +1445,8 @@ void P_write_stats_header_formatted(FILE *f, int is_event)
#if defined (HAVE_L2)
if (config.what_to_count & (COUNT_SRC_MAC|COUNT_SUM_MAC)) fprintf(f, "SRC_MAC ");
if (config.what_to_count & COUNT_DST_MAC) fprintf(f, "DST_MAC ");
if (config.what_to_count & COUNT_VLAN) {
if (config.tmp_vlan_legacy) {
fprintf(f, "VLAN ");
}
else {
fprintf(f, "IN_VLAN ");
}
}
if (config.what_to_count & COUNT_VLAN) fprintf(f, "VLAN ");
if (config.what_to_count_3 & COUNT_IN_VLAN) fprintf(f, "IN_VLAN ");
if (config.what_to_count_2 & COUNT_OUT_VLAN) fprintf(f, "OUT_VLAN ");
if (config.what_to_count & COUNT_COS) fprintf(f, "COS ");
if (config.what_to_count & COUNT_ETHERTYPE) fprintf(f, "ETYPE ");
Expand Down Expand Up @@ -1568,14 +1564,8 @@ void P_write_stats_header_csv(FILE *f, int is_event)
#if defined HAVE_L2
if (config.what_to_count & (COUNT_SRC_MAC|COUNT_SUM_MAC)) fprintf(f, "%sSRC_MAC", write_sep(sep, &count));
if (config.what_to_count & COUNT_DST_MAC) fprintf(f, "%sDST_MAC", write_sep(sep, &count));
if (config.what_to_count & COUNT_VLAN) {
if (config.tmp_vlan_legacy) {
fprintf(f, "%sVLAN", write_sep(sep, &count));
}
else {
fprintf(f, "%sIN_VLAN", write_sep(sep, &count));
}
}
if (config.what_to_count & COUNT_VLAN) fprintf(f, "%sVLAN", write_sep(sep, &count));
if (config.what_to_count_3 & COUNT_IN_VLAN) fprintf(f, "%sIN_VLAN", write_sep(sep, &count));
if (config.what_to_count_2 & COUNT_OUT_VLAN) fprintf(f, "%sOUT_VLAN", write_sep(sep, &count));
if (config.what_to_count & COUNT_COS) fprintf(f, "%sCOS", write_sep(sep, &count));
if (config.what_to_count & COUNT_ETHERTYPE) fprintf(f, "%sETYPE", write_sep(sep, &count));
Expand Down
8 changes: 5 additions & 3 deletions src/sql_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,8 @@ int sql_evaluate_primitives(int primitive)
if (config.what_to_count_2 & COUNT_EXPORT_PROTO_TIME) what_to_count_2 |= COUNT_EXPORT_PROTO_TIME;
if (config.what_to_count_2 & COUNT_LABEL) what_to_count_2 |= COUNT_LABEL;

if (config.what_to_count_3 & COUNT_IN_VLAN) what_to_count_3 |= COUNT_IN_VLAN;

#if defined (WITH_NDPI)
if (config.what_to_count_2 & COUNT_NDPI_CLASS) what_to_count_2 |= COUNT_NDPI_CLASS;
#endif
Expand Down Expand Up @@ -1323,7 +1325,7 @@ int sql_evaluate_primitives(int primitive)
}
}

if ((what_to_count & COUNT_VLAN) && config.tmp_vlan_legacy) {
if (what_to_count & COUNT_VLAN) {
int count_it = FALSE;

if ((config.sql_table_version < 2 || config.sql_table_version >= SQL_TABLE_VERSION_BGP) && !assume_custom_table) {
Expand All @@ -1350,7 +1352,7 @@ int sql_evaluate_primitives(int primitive)
}
}

if ((what_to_count & COUNT_VLAN) && !config.tmp_vlan_legacy) {
if (what_to_count_3 & COUNT_IN_VLAN) {
if (primitive) {
strncat(insert_clause, ", ", SPACELEFT(insert_clause));
strncat(values[primitive].string, delim_buf, SPACELEFT(values[primitive].string));
Expand All @@ -1359,7 +1361,7 @@ int sql_evaluate_primitives(int primitive)
strncat(insert_clause, "vlan_in", SPACELEFT(insert_clause));
strncat(values[primitive].string, "%u", SPACELEFT(values[primitive].string));
strncat(where[primitive].string, "vlan_in=%u", SPACELEFT(where[primitive].string));
values[primitive].type = where[primitive].type = COUNT_INT_VLAN;
values[primitive].type = where[primitive].type = COUNT_INT_IN_VLAN;
values[primitive].handler = where[primitive].handler = count_vlan_handler;
primitive++;
}
Expand Down

0 comments on commit 5a5e272

Please sign in to comment.