Commit 4c316069 authored by Gustavo A. R. Silva's avatar Gustavo A. R. Silva Committed by David S. Miller

net: netrom: nr_route: refactor code in nr_add_node

Code refactoring in order to make the code easier to read and maintain.
Signed-off-by: default avatarGustavo A. R. Silva <garsilva@embeddedor.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 31b102bb
...@@ -80,6 +80,19 @@ static struct nr_neigh *nr_neigh_get_dev(ax25_address *callsign, ...@@ -80,6 +80,19 @@ static struct nr_neigh *nr_neigh_get_dev(ax25_address *callsign,
static void nr_remove_neigh(struct nr_neigh *); static void nr_remove_neigh(struct nr_neigh *);
/* re-sort the routes in quality order. */
static void re_sort_routes(struct nr_node *nr_node, int x, int y)
{
if (nr_node->routes[y].quality > nr_node->routes[x].quality) {
if (nr_node->which == x)
nr_node->which = y;
else if (nr_node->which == y)
nr_node->which = x;
swap(nr_node->routes[x], nr_node->routes[y]);
}
}
/* /*
* Add a new route to a node, and in the process add the node and the * Add a new route to a node, and in the process add the node and the
* neighbour if it is new. * neighbour if it is new.
...@@ -90,7 +103,6 @@ static int __must_check nr_add_node(ax25_address *nr, const char *mnemonic, ...@@ -90,7 +103,6 @@ static int __must_check nr_add_node(ax25_address *nr, const char *mnemonic,
{ {
struct nr_node *nr_node; struct nr_node *nr_node;
struct nr_neigh *nr_neigh; struct nr_neigh *nr_neigh;
struct nr_route nr_route;
int i, found; int i, found;
struct net_device *odev; struct net_device *odev;
...@@ -251,49 +263,10 @@ static int __must_check nr_add_node(ax25_address *nr, const char *mnemonic, ...@@ -251,49 +263,10 @@ static int __must_check nr_add_node(ax25_address *nr, const char *mnemonic,
/* Now re-sort the routes in quality order */ /* Now re-sort the routes in quality order */
switch (nr_node->count) { switch (nr_node->count) {
case 3: case 3:
if (nr_node->routes[1].quality > nr_node->routes[0].quality) { re_sort_routes(nr_node, 0, 1);
switch (nr_node->which) { re_sort_routes(nr_node, 1, 2);
case 0:
nr_node->which = 1;
break;
case 1:
nr_node->which = 0;
break;
}
nr_route = nr_node->routes[0];
nr_node->routes[0] = nr_node->routes[1];
nr_node->routes[1] = nr_route;
}
if (nr_node->routes[2].quality > nr_node->routes[1].quality) {
switch (nr_node->which) {
case 1: nr_node->which = 2;
break;
case 2: nr_node->which = 1;
break;
default:
break;
}
nr_route = nr_node->routes[1];
nr_node->routes[1] = nr_node->routes[2];
nr_node->routes[2] = nr_route;
}
case 2: case 2:
if (nr_node->routes[1].quality > nr_node->routes[0].quality) { re_sort_routes(nr_node, 0, 1);
switch (nr_node->which) {
case 0: nr_node->which = 1;
break;
case 1: nr_node->which = 0;
break;
default: break;
}
nr_route = nr_node->routes[0];
nr_node->routes[0] = nr_node->routes[1];
nr_node->routes[1] = nr_route;
}
case 1: case 1:
break; break;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment