diff options
author | Ondrej Zajicek (work) <santiago@crfreenet.org> | 2017-02-20 02:26:45 +0100 |
---|---|---|
committer | Ondrej Zajicek (work) <santiago@crfreenet.org> | 2017-02-20 02:26:45 +0100 |
commit | 62e64905b76b88da72c522eac9276a74f60c9592 (patch) | |
tree | 8e489665d740f72eb8ed8622e9b012642c6b6ccf /nest | |
parent | d311368bc58842552e25744a0aae9a09c42cda9f (diff) |
Several minor fixes
Diffstat (limited to 'nest')
-rw-r--r-- | nest/route.h | 8 | ||||
-rw-r--r-- | nest/rt-attr.c | 42 | ||||
-rw-r--r-- | nest/rt-dev.c | 4 | ||||
-rw-r--r-- | nest/rt-table.c | 16 |
4 files changed, 29 insertions, 41 deletions
diff --git a/nest/route.h b/nest/route.h index eb98b609..1e0a14bc 100644 --- a/nest/route.h +++ b/nest/route.h @@ -390,11 +390,11 @@ typedef struct rta { #define RTC_MULTICAST 2 #define RTC_ANYCAST 3 /* IPv6 Anycast */ -#define RTD_UNICAST 0 /* Next hop is neighbor router */ +#define RTD_NONE 0 /* Undefined next hop */ +#define RTD_UNICAST 1 /* Next hop is neighbor router */ #define RTD_BLACKHOLE 2 /* Silently drop packets */ #define RTD_UNREACHABLE 3 /* Reject as unreachable */ #define RTD_PROHIBIT 4 /* Administratively prohibited */ -#define RTD_NONE 6 /* Invalid RTD */ /* Flags for net->n.flags, used by kernel syncer */ #define KRF_INSTALLED 0x80 /* This route should be installed in the kernel */ @@ -408,7 +408,7 @@ typedef struct rta { /* Route has regular, reachable nexthop (i.e. not RTD_UNREACHABLE and like) */ static inline int rte_is_reachable(rte *r) -{ uint d = r->attrs->dest; return (d == RTD_UNICAST); } +{ return r->attrs->dest == RTD_UNICAST; } /* @@ -523,7 +523,7 @@ static inline int nexthop_same(struct nexthop *x, struct nexthop *y) struct nexthop *nexthop_merge(struct nexthop *x, struct nexthop *y, int rx, int ry, int max, linpool *lp); static inline void nexthop_link(struct rta *a, struct nexthop *from) { memcpy(&a->nh, from, nexthop_size(from)); } -void nexthop_insert(struct nexthop *n, struct nexthop *y); +void nexthop_insert(struct nexthop **n, struct nexthop *y); int nexthop_is_sorted(struct nexthop *x); void rta_init(void); diff --git a/nest/rt-attr.c b/nest/rt-attr.c index 120a8e24..afc97e22 100644 --- a/nest/rt-attr.c +++ b/nest/rt-attr.c @@ -150,7 +150,8 @@ nexthop_hash(struct nexthop *x) for (; x; x = x->next) { h ^= ipa_hash(x->gw) ^ (h << 5) ^ (h >> 9); - for (int i=0; i<x->labels; i++) + + for (int i = 0; i < x->labels; i++) h ^= x->label[i] ^ (h << 6) ^ (h >> 7); } @@ -164,12 +165,13 @@ nexthop__same(struct nexthop *x, struct nexthop *y) { if (!ipa_equal(x->gw, y->gw) || (x->iface != y->iface) || (x->weight != y->weight) || (x->labels != y->labels)) return 0; - for (int i=0; i<x->labels; i++) + + for (int i = 0; i < x->labels; i++) if (x->label[i] != y->label[i]) return 0; } - return 1; + return x == y; } static int @@ -195,7 +197,7 @@ nexthop_compare_node(struct nexthop *x, struct nexthop *y) if (r) return r; - for (int i=0; i<y->labels; i++) + for (int i = 0; i < y->labels; i++) { r = ((int) y->label[i]) - ((int) x->label[i]); if (r) @@ -271,34 +273,22 @@ nexthop_merge(struct nexthop *x, struct nexthop *y, int rx, int ry, int max, lin } void -nexthop_insert(struct nexthop *n, struct nexthop *x) +nexthop_insert(struct nexthop **n, struct nexthop *x) { - struct nexthop tmp; - memcpy(&tmp, n, sizeof(struct nexthop)); - if (nexthop_compare_node(n, x) > 0) /* Insert to the included nexthop */ - { - memcpy(n, x, sizeof(struct nexthop)); - memcpy(x, &tmp, sizeof(struct nexthop)); - n->next = x; - return; - } - - for (struct nexthop **nn = &(n->next); *nn; nn = &((*nn)->next)) + for (; *n; n = &((*n)->next)) { - int cmp = nexthop_compare_node(*nn, x); + int cmp = nexthop_compare_node(*n, x); if (cmp < 0) continue; - - if (cmp > 0) - { - x->next = *nn; - *nn = x; - } - - return; + else if (cmp > 0) + break; + else + return; } + x->next = *n; + *n = x; } int @@ -314,7 +304,7 @@ nexthop_is_sorted(struct nexthop *x) static inline slab * nexthop_slab(struct nexthop *nh) { - return nexthop_slab_[nh->labels > 2 ? 3 : nh->labels]; + return nexthop_slab_[MIN(nh->labels, 3)]; } static struct nexthop * diff --git a/nest/rt-dev.c b/nest/rt-dev.c index 5edd1c5d..9993da24 100644 --- a/nest/rt-dev.c +++ b/nest/rt-dev.c @@ -79,9 +79,7 @@ dev_ifa_notify(struct proto *P, uint flags, struct ifa *ad) .source = RTS_DEVICE, .scope = SCOPE_UNIVERSE, .dest = RTD_UNICAST, - .nh = { - .iface = ad->iface - } + .nh.iface = ad->iface, }; a = rta_lookup(&a0); diff --git a/nest/rt-table.c b/nest/rt-table.c index ef402f28..a33b7909 100644 --- a/nest/rt-table.c +++ b/nest/rt-table.c @@ -1768,7 +1768,6 @@ static inline void rta_apply_hostentry(rta *a, struct hostentry *he) { a->hostentry = he; - a->dest = he->dest; a->igp_metric = he->igp_metric; @@ -1810,14 +1809,14 @@ rta_apply_hostentry(rta *a, struct hostentry *he) static inline rte * rt_next_hop_update_rte(rtable *tab UNUSED, rte *old) { - rta *ap = alloca(RTA_MAX_SIZE); - memcpy(ap, old->attrs, rta_size(old->attrs)); - rta_apply_hostentry(ap, old->attrs->hostentry); - ap->aflags = 0; + rta *a = alloca(RTA_MAX_SIZE); + memcpy(a, old->attrs, rta_size(old->attrs)); + rta_apply_hostentry(a, old->attrs->hostentry); + a->aflags = 0; rte *e = sl_alloc(rte_slab); memcpy(e, old, sizeof(rte)); - e->attrs = rta_lookup(ap); + e->attrs = rta_lookup(a); return e; } @@ -2373,7 +2372,8 @@ rt_update_hostentry(rtable *tab, struct hostentry *he) } if ((a->dest == RTD_UNICAST) && ipa_zero(a->nh.gw) && !a->next) - { /* We have singlepath device route */ + { + /* We have singlepath device route */ if (if_local_addr(he->addr, a->nh.iface)) { /* The host address is a local address, this is not valid */ @@ -2389,7 +2389,7 @@ rt_update_hostentry(rtable *tab, struct hostentry *he) else { /* The host is reachable through some route entry */ - he->nh = (&a->nh); + he->nh = &(a->nh); he->dest = a->dest; } |