summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authormpi <mpi@openbsd.org>2017-09-05 11:15:39 +0000
committermpi <mpi@openbsd.org>2017-09-05 11:15:39 +0000
commitf76c3713407a06818019e5bd6ebc29b320484ef9 (patch)
tree2beeaf4ee82bd49ab5cd9aad2481dd52e9265637 /sys
parentTest that MPATH routes with different priorities are insterted respecting (diff)
downloadwireguard-openbsd-f76c3713407a06818019e5bd6ebc29b320484ef9.tar.xz
wireguard-openbsd-f76c3713407a06818019e5bd6ebc29b320484ef9.zip
Simplify rtable_mpath_insert().
ok jmatthew@
Diffstat (limited to 'sys')
-rw-r--r--sys/net/rtable.c41
1 files changed, 15 insertions, 26 deletions
diff --git a/sys/net/rtable.c b/sys/net/rtable.c
index 3a8027f537d..b16499ccd79 100644
--- a/sys/net/rtable.c
+++ b/sys/net/rtable.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rtable.c,v 1.62 2017/09/05 10:56:04 mpi Exp $ */
+/* $OpenBSD: rtable.c,v 1.63 2017/09/05 11:15:39 mpi Exp $ */
/*
* Copyright (c) 2014-2016 Martin Pieuchot
@@ -764,32 +764,21 @@ rtable_mpath_insert(struct art_node *an, struct rtentry *rt)
struct rtentry *mrt, *prt = NULL;
uint8_t prio = rt->rt_priority;
- if ((mrt = SRPL_FIRST_LOCKED(&an->an_rtlist)) != NULL) {
- /*
- * Select the order of the MPATH routes.
- */
- while (SRPL_NEXT_LOCKED(mrt, rt_next) != NULL) {
- if (mrt->rt_priority > prio)
- break;
- prt = mrt;
- mrt = SRPL_NEXT_LOCKED(mrt, rt_next);
- }
+ if ((mrt = SRPL_FIRST_LOCKED(&an->an_rtlist)) == NULL) {
+ SRPL_INSERT_HEAD_LOCKED(&rt_rc, &an->an_rtlist, rt, rt_next);
+ return;
+ }
- if (mrt->rt_priority > prio) {
- /*
- * ``rt'' has a higher (smaller) priority than
- * ``mrt'' so put it before in the list.
- */
- if (prt != NULL) {
- SRPL_INSERT_AFTER_LOCKED(&rt_rc, prt, rt,
- rt_next);
- } else {
- SRPL_INSERT_HEAD_LOCKED(&rt_rc, &an->an_rtlist,
- rt, rt_next);
- }
- } else {
- SRPL_INSERT_AFTER_LOCKED(&rt_rc, mrt, rt, rt_next);
- }
+ /* Iterate until we find the route to be placed after ``rt''. */
+ while (mrt->rt_priority <= prio && SRPL_NEXT_LOCKED(mrt, rt_next)) {
+ prt = mrt;
+ mrt = SRPL_NEXT_LOCKED(mrt, rt_next);
+ }
+
+ if (mrt->rt_priority <= prio) {
+ SRPL_INSERT_AFTER_LOCKED(&rt_rc, mrt, rt, rt_next);
+ } else if (prt != NULL) {
+ SRPL_INSERT_AFTER_LOCKED(&rt_rc, prt, rt, rt_next);
} else {
SRPL_INSERT_HEAD_LOCKED(&rt_rc, &an->an_rtlist, rt, rt_next);
}