Browse Source

allowed full matches only

pull/349/head
Logan007 4 years ago
parent
commit
f7e50e12c0
  1. 6
      src/n2n_regex.c
  2. 9
      src/sn_utils.c

6
src/n2n_regex.c

@ -50,6 +50,7 @@
#include "n2n_regex.h"
#include "n2n.h"
/* Definitions: */
@ -130,6 +131,8 @@ re_t re_compile(const char* pattern)
MAX_REGEXP_OBJECTS is the max number of symbols in the expression.
MAX_CHAR_CLASS_LEN determines the size of buffer for chars in all char-classes in the expression. */
static regex_t re_compiled[MAX_REGEXP_OBJECTS];
re_t re_p; /* pointer to (to be created) copy of compiled regex in re_compiled */
static unsigned char ccl_buf[MAX_CHAR_CLASS_LEN];
int ccl_bufidx = 1;
@ -248,7 +251,8 @@ re_t re_compile(const char* pattern)
}
/* 'UNUSED' is a sentinel used to indicate end-of-pattern */
re_compiled[j].type = UNUSED;
re_t re_p = (re_t)calloc(1, sizeof(re_compiled));
re_p = (re_t)calloc(1, sizeof(re_compiled));
memcpy (re_p, re_compiled, sizeof(re_compiled));
return (re_t) re_p;
}

9
src/sn_utils.c

@ -793,6 +793,7 @@ static int process_udp(n2n_sn_t * sss,
size_t encx=0;
struct sn_community_regular_expression *re, *tmp_re;
int8_t allowed_match = -1;
uint8_t match = 0;
int match_length = 0;
/* Edge requesting registration with us. */
sss->stats.last_reg_super=now;
@ -817,11 +818,15 @@ static int process_udp(n2n_sn_t * sss,
HASH_ITER(hh, sss->rules, re, tmp_re) {
allowed_match = re_matchp(re->rule, cmn.community, &match_length);
if(allowed_match != -1) // ... && match_len == strlen(cmn.community) --- if only full matches allowed
if( (allowed_match != -1)
&& (match_length == strlen(cmn.community)) // --- only full matches allowed (remove, if also partial matches wanted)
&& (allowed_match == 0)) { // --- only full matches allowed (remove, if also partial matches wanted)
match = 1;
break;
}
}
if(!comm && (!sss->lock_communities || (allowed_match != -1))) {
if(!comm && (!sss->lock_communities || (match == 1))) {
comm = calloc(1, sizeof(struct sn_community));
if(comm) {

Loading…
Cancel
Save