Commit 3223774e authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Allow simultaneous le and ge in single rule.

parent 25385b66
...@@ -158,6 +158,7 @@ parse_filter(gnc_t gnc, void *closure) ...@@ -158,6 +158,7 @@ parse_filter(gnc_t gnc, void *closure)
filter = calloc(1, sizeof(struct filter)); filter = calloc(1, sizeof(struct filter));
if(filter == NULL) if(filter == NULL)
goto error; goto error;
filter->plen_le = 128;
c = gnc(closure); c = gnc(closure);
if(c < -1) if(c < -1)
...@@ -183,22 +184,20 @@ parse_filter(gnc_t gnc, void *closure) ...@@ -183,22 +184,20 @@ parse_filter(gnc_t gnc, void *closure)
c = getint(c, &p, gnc, closure); c = getint(c, &p, gnc, closure);
if(c < -1) if(c < -1)
goto error; goto error;
filter->plen_type = FILTER_PLEN_EQ; filter->plen_ge = MAX(filter->plen_ge, p);
filter->filter_plen = p; filter->plen_le = MIN(filter->plen_le, p);
} else if(strcmp(token, "le") == 0) { } else if(strcmp(token, "le") == 0) {
int p; int p;
c = getint(c, &p, gnc, closure); c = getint(c, &p, gnc, closure);
if(c < -1) if(c < -1)
goto error; goto error;
filter->plen_type = FILTER_PLEN_LE; filter->plen_le = MIN(filter->plen_le, p);
filter->filter_plen = p;
} else if(strcmp(token, "ge") == 0) { } else if(strcmp(token, "ge") == 0) {
int p; int p;
c = getint(c, &p, gnc, closure); c = getint(c, &p, gnc, closure);
if(c < -1) if(c < -1)
goto error; goto error;
filter->plen_type = FILTER_PLEN_GE; filter->plen_ge = MAX(filter->plen_ge, p);
filter->filter_plen = p;
} else if(strcmp(token, "neigh") == 0) { } else if(strcmp(token, "neigh") == 0) {
unsigned char *neigh; unsigned char *neigh;
c = getip(c, &neigh, NULL, gnc, closure); c = getip(c, &neigh, NULL, gnc, closure);
...@@ -242,11 +241,11 @@ parse_filter(gnc_t gnc, void *closure) ...@@ -242,11 +241,11 @@ parse_filter(gnc_t gnc, void *closure)
free(token); free(token);
} }
if(filter->af == 0) { if(filter->af == 0) {
if(filter->plen_type) if(filter->plen_le < 128 || filter->plen_ge > 0)
filter->af = AF_INET6; filter->af = AF_INET6;
} else if(filter->af == AF_INET) { } else if(filter->af == AF_INET) {
if(filter->plen_type) filter->plen_le += 96;
filter->filter_plen += 96; filter->plen_ge += 96;
} }
return filter; return filter;
error: error:
...@@ -381,14 +380,12 @@ filter_match(struct filter *f, const unsigned char *id, ...@@ -381,14 +380,12 @@ filter_match(struct filter *f, const unsigned char *id,
if(!prefix || plen < f->plen || !in_prefix(prefix, f->prefix, f->plen)) if(!prefix || plen < f->plen || !in_prefix(prefix, f->prefix, f->plen))
return 0; return 0;
} }
if(f->plen_type) { if(f->plen_ge > 0 || f->plen_le < 128) {
if(!prefix) if(!prefix)
return 0; return 0;
if(f->plen_type == FILTER_PLEN_EQ && plen != f->filter_plen) if(plen > f->plen_le)
return 0; return 0;
if(f->plen_type == FILTER_PLEN_LE && plen > f->filter_plen) if(plen < f->plen_ge)
return 0;
if(f->plen_type == FILTER_PLEN_GE && plen < f->filter_plen)
return 0; return 0;
} }
if(f->neigh) { if(f->neigh) {
......
...@@ -20,10 +20,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN ...@@ -20,10 +20,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
*/ */
#define FILTER_PLEN_EQ 1
#define FILTER_PLEN_LE 2
#define FILTER_PLEN_GE 3
#define METRIC_INHERIT (INFINITY + 1) #define METRIC_INHERIT (INFINITY + 1)
struct filter { struct filter {
...@@ -32,8 +28,7 @@ struct filter { ...@@ -32,8 +28,7 @@ struct filter {
unsigned char *id; unsigned char *id;
unsigned char *prefix; unsigned char *prefix;
unsigned char plen; unsigned char plen;
unsigned char filter_plen; unsigned char plen_ge, plen_le;
unsigned char plen_type;
unsigned char *neigh; unsigned char *neigh;
int proto; int proto;
unsigned int result; unsigned int result;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment