From 4051d863f86f343c06f8bcb985b7648fd3ef6250 Mon Sep 17 00:00:00 2001 From: Martin Pieuchot Date: Tue, 5 Sep 2017 11:15:40 +0000 Subject: Simplify rtable_mpath_insert(). ok jmatthew@ --- sys/net/rtable.c | 41 +++++++++++++++-------------------------- 1 file 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); } -- cgit v1.2.3