summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2017-09-05 11:15:40 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2017-09-05 11:15:40 +0000
commit4051d863f86f343c06f8bcb985b7648fd3ef6250 (patch)
tree7bfc2aa1d3282ffd2263619a5e9f3631880a441c
parent40aaf5623ba3817857164588ff150122c2d0866e (diff)
Simplify rtable_mpath_insert().
ok jmatthew@
-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);
}