Skip to content

Commit 5cea045

Browse files
committed
prefix_tags: improve performance by skipping prefix search unless necessary
1 parent acdbea2 commit 5cea045

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

prefix_tags/prefix_tags.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,17 @@ int prefix_tags(ipps_context_t *config) {
9393
ip_addr_t dst_ip = ur_get(template_in, data_in, F_DST_IP);
9494
prefix_tag = 0;
9595
prefix_tag_dst = 0;
96-
97-
int src_res = is_from_configured_prefix(config, &src_ip, &prefix_tag);
98-
int dst_res = is_from_configured_prefix(config, &dst_ip, &prefix_tag_dst);
96+
int src_res = 0;
97+
int dst_res = 0;
9998

100-
if ((CHECK_SRC_IP && src_res) || (CHECK_DST_IP && dst_res)) {
99+
if (CHECK_SRC_IP || CHECK_BOTH){
100+
src_res = is_from_configured_prefix(config, &src_ip, &prefix_tag);
101+
}
102+
if ((!src_res && CHECK_DST_IP) || CHECK_BOTH){
103+
dst_res = is_from_configured_prefix(config, &dst_ip, &prefix_tag_dst);
104+
}
105+
106+
if (src_res || dst_res) {
101107
debug_print("tagging %d\n", prefix_tag);
102108
// data_out should have the right size since TRAP_E_FORMAT_CHANGED _had_ to be returned before getting here
103109
ur_copy_fields(template_out, data_out, template_in, data_in);

0 commit comments

Comments
 (0)