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