From 257a6b0b7e76e17bdd6e107ae643db4466960654 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Thu, 3 Aug 2023 17:19:42 +1000 Subject: netlink: Split nl_route() into separate operation functions nl_route() can perform 3 quite different operations based on the 'op' parameter. Split this into separate functions for each one. This requires more lines of code, but makes the internal logic of each operation much easier to follow. Signed-off-by: David Gibson Signed-off-by: Stefano Brivio --- pasta.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'pasta.c') diff --git a/pasta.c b/pasta.c index b55a1a2..52cfad7 100644 --- a/pasta.c +++ b/pasta.c @@ -281,8 +281,6 @@ void pasta_ns_conf(struct ctx *c) nl_link_set_mac(1, c->pasta_ifi, c->mac_guest); if (c->pasta_conf_ns) { - enum nl_op op_routes = c->no_copy_routes ? NL_SET : NL_DUP; - nl_link_up(1, c->pasta_ifi, c->mtu); if (c->ifi4) { @@ -293,8 +291,11 @@ void pasta_ns_conf(struct ctx *c) nl_addr_dup(c->ifi4, c->pasta_ifi, AF_INET); } - nl_route(op_routes, c->ifi4, c->pasta_ifi, AF_INET, - &c->ip4.gw); + if (c->no_copy_routes) + nl_route_set_def(c->pasta_ifi, AF_INET, + &c->ip4.gw); + else + nl_route_dup(c->ifi4, c->pasta_ifi, AF_INET); } if (c->ifi6) { @@ -305,8 +306,11 @@ void pasta_ns_conf(struct ctx *c) nl_addr_dup(c->ifi6, c->pasta_ifi, AF_INET6); } - nl_route(op_routes, c->ifi6, c->pasta_ifi, AF_INET6, - &c->ip6.gw); + if (c->no_copy_routes) + nl_route_set_def(c->pasta_ifi, AF_INET6, + &c->ip6.gw); + else + nl_route_dup(c->ifi6, c->pasta_ifi, AF_INET6); } } -- cgit v1.2.3