0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-11-17 16:48:43 +00:00

Netlink: Handle alien routes with unsorted nexthops

Nest requires that nexthops are sorted, the kernel protocol have to
ensure that for alien routes.
This commit is contained in:
Ondrej Zajicek (work) 2019-07-02 18:23:06 +02:00
parent 1187627a1d
commit 59d3a3611f
3 changed files with 24 additions and 1 deletions

View File

@ -628,6 +628,7 @@ int nexthop__same(struct nexthop *x, struct nexthop *y); /* Compare multipath ne
static inline int nexthop_same(struct nexthop *x, struct nexthop *y) static inline int nexthop_same(struct nexthop *x, struct nexthop *y)
{ return (x == y) || nexthop__same(x, y); } { return (x == y) || nexthop__same(x, y); }
struct nexthop *nexthop_merge(struct nexthop *x, struct nexthop *y, int rx, int ry, int max, linpool *lp); struct nexthop *nexthop_merge(struct nexthop *x, struct nexthop *y, int rx, int ry, int max, linpool *lp);
struct nexthop *nexthop_sort(struct nexthop *x);
static inline void nexthop_link(struct rta *a, struct nexthop *from) static inline void nexthop_link(struct rta *a, struct nexthop *from)
{ memcpy(&a->nh, from, nexthop_size(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);

View File

@ -200,7 +200,7 @@ nexthop__same(struct nexthop *x, struct nexthop *y)
} }
static int static int
nexthop_compare_node(struct nexthop *x, struct nexthop *y) nexthop_compare_node(const struct nexthop *x, const struct nexthop *y)
{ {
int r; int r;
@ -318,6 +318,24 @@ nexthop_insert(struct nexthop **n, struct nexthop *x)
*n = x; *n = x;
} }
struct nexthop *
nexthop_sort(struct nexthop *x)
{
struct nexthop *s = NULL;
/* Simple insert-sort */
while (x)
{
struct nexthop *n = x;
x = n->next;
n->next = NULL;
nexthop_insert(&s, n);
}
return s;
}
int int
nexthop_is_sorted(struct nexthop *x) nexthop_is_sorted(struct nexthop *x)
{ {

View File

@ -725,6 +725,10 @@ nl_parse_multipath(struct nl_parse_state *s, struct krt_proto *p, struct rtattr
nh = RTNH_NEXT(nh); nh = RTNH_NEXT(nh);
} }
/* Ensure nexthops are sorted to satisfy nest invariant */
if (!nexthop_is_sorted(first))
first = nexthop_sort(first);
return first; return first;
} }