Commit c96af640 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Simplify the interface to prefix_cmp.

parent 9f6b430b
...@@ -49,15 +49,15 @@ rt_cmp(const struct babel_route *rt1, const struct babel_route *rt2) ...@@ -49,15 +49,15 @@ rt_cmp(const struct babel_route *rt1, const struct babel_route *rt2)
enum prefix_status dst_st, src_st; enum prefix_status dst_st, src_st;
const struct source *r1 = rt1->src, *r2 = rt2->src; const struct source *r1 = rt1->src, *r2 = rt2->src;
dst_st = prefix_cmp(r1->prefix, r1->plen, r2->prefix, r2->plen); dst_st = prefix_cmp(r1->prefix, r1->plen, r2->prefix, r2->plen);
if(dst_st & PST_MORE_SPECIFIC) if(dst_st == PST_MORE_SPECIFIC)
return -1; return -1;
else if(dst_st & PST_LESS_SPECIFIC) else if(dst_st == PST_LESS_SPECIFIC)
return 1; return 1;
src_st = prefix_cmp(r1->src_prefix, r1->src_plen, src_st = prefix_cmp(r1->src_prefix, r1->src_plen,
r2->src_prefix, r2->src_plen); r2->src_prefix, r2->src_plen);
if(src_st & PST_MORE_SPECIFIC) if(src_st == PST_MORE_SPECIFIC)
return -1; return -1;
else if(src_st & PST_LESS_SPECIFIC) else if(src_st == PST_LESS_SPECIFIC)
return 1; return 1;
return 0; return 0;
} }
...@@ -78,7 +78,7 @@ conflicts(const struct babel_route *rt, const struct babel_route *rt1) ...@@ -78,7 +78,7 @@ conflicts(const struct babel_route *rt, const struct babel_route *rt1)
enum prefix_status dst_st, src_st; enum prefix_status dst_st, src_st;
const struct source *r = rt->src, *r1 = rt1->src; const struct source *r = rt->src, *r1 = rt1->src;
dst_st = prefix_cmp(r->prefix, r->plen, r1->prefix, r1->plen); dst_st = prefix_cmp(r->prefix, r->plen, r1->prefix, r1->plen);
if(dst_st & (PST_DISJOINT | PST_EQUALS)) if(dst_st == PST_DISJOINT || dst_st == PST_EQUALS)
return 0; return 0;
src_st = prefix_cmp(r->src_prefix, r->src_plen, src_st = prefix_cmp(r->src_prefix, r->src_plen,
r1->src_prefix, r1->src_plen); r1->src_prefix, r1->src_plen);
...@@ -105,20 +105,20 @@ inter(const struct babel_route *rt, const struct babel_route *rt1, ...@@ -105,20 +105,20 @@ inter(const struct babel_route *rt, const struct babel_route *rt1,
enum prefix_status dst_st, src_st; enum prefix_status dst_st, src_st;
const struct source *r = rt->src, *r1 = rt1->src; const struct source *r = rt->src, *r1 = rt1->src;
dst_st = prefix_cmp(r->prefix, r->plen, r1->prefix, r1->plen); dst_st = prefix_cmp(r->prefix, r->plen, r1->prefix, r1->plen);
if(dst_st & PST_DISJOINT) if(dst_st == PST_DISJOINT)
return NULL; return NULL;
src_st = prefix_cmp(r->src_prefix, r->src_plen, src_st = prefix_cmp(r->src_prefix, r->src_plen,
r1->src_prefix, r1->src_plen); r1->src_prefix, r1->src_plen);
if(src_st & PST_DISJOINT) if(src_st == PST_DISJOINT)
return NULL; return NULL;
if (dst_st & (PST_MORE_SPECIFIC | PST_EQUALS)) { if (dst_st == PST_MORE_SPECIFIC || dst_st == PST_EQUALS) {
zone->dst_prefix = r->prefix; zone->dst_prefix = r->prefix;
zone->dst_plen = r->plen; zone->dst_plen = r->plen;
} else { } else {
zone->dst_prefix = r1->prefix; zone->dst_prefix = r1->prefix;
zone->dst_plen = r1->plen; zone->dst_plen = r1->plen;
} }
if (src_st & (PST_MORE_SPECIFIC | PST_EQUALS)) { if (src_st == PST_MORE_SPECIFIC || src_st == PST_EQUALS) {
zone->src_prefix = r->src_prefix; zone->src_prefix = r->src_prefix;
zone->src_plen = r->src_plen; zone->src_plen = r->src_plen;
} else { } else {
......
...@@ -1961,8 +1961,7 @@ filter_kernel_rules(struct nlmsghdr *nh, void *data) ...@@ -1961,8 +1961,7 @@ filter_kernel_rules(struct nlmsghdr *nh, void *data)
return 1; return 1;
if(prefix_cmp(src, src_plen, if(prefix_cmp(src, src_plen,
kernel_tables[i].src, kernel_tables[i].plen) kernel_tables[i].src, kernel_tables[i].plen) == PST_EQUALS &&
== PST_EQUALS &&
table == kernel_tables[i].table && table == kernel_tables[i].table &&
!rule_exists[i]) { !rule_exists[i]) {
rule_exists[i] = 1; rule_exists[i] = 1;
......
...@@ -114,10 +114,10 @@ int daemonise(void); ...@@ -114,10 +114,10 @@ int daemonise(void);
int set_src_prefix(unsigned char *src_addr, unsigned char *src_plen); int set_src_prefix(unsigned char *src_addr, unsigned char *src_plen);
enum prefix_status { enum prefix_status {
PST_DISJOINT = 1 << 0, PST_EQUALS = 0,
PST_EQUALS = 1 << 1, PST_DISJOINT,
PST_MORE_SPECIFIC = 1 << 2, PST_MORE_SPECIFIC,
PST_LESS_SPECIFIC = 1 << 3 PST_LESS_SPECIFIC
}; };
enum prefix_status enum prefix_status
prefix_cmp(const unsigned char *p1, unsigned char plen1, prefix_cmp(const unsigned char *p1, unsigned char plen1,
......
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