[PATCH libnl 07/11] Add support for label stack in nl-route commands

David Ahern dsahern at gmail.com
Fri Jun 30 09:48:54 PDT 2017


Add support for MPLS labels in nexthop specification. Specifically, the
'as' keyword specifies the MPLS label stack and if the route address
family is MPLS then the nexthop via is added as a route via instead of
a gateway (subtle differences introduced for MPLS).

Signed-off-by: David Ahern <dsahern at gmail.com>
---
 src/lib/route.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/lib/route.c b/src/lib/route.c
index cd3e89783b33..2eac0a05c97e 100644
--- a/src/lib/route.c
+++ b/src/lib/route.c
@@ -141,11 +141,13 @@ void nl_cli_route_parse_nexthop(struct rtnl_route *route, char *subopts,
 		NH_DEV,
 		NH_VIA,
 		NH_WEIGHT,
+		NH_AS,
 	};
 	static char *const tokens[] = {
 		"dev",
 		"via",
 		"weight",
+		"as",
 		NULL,
 	};
 	struct rtnl_nexthop *nh;
@@ -175,8 +177,20 @@ void nl_cli_route_parse_nexthop(struct rtnl_route *route, char *subopts,
 			break;
 
 		case NH_VIA:
-			addr = nl_cli_addr_parse(arg,rtnl_route_get_family(route));
-			rtnl_route_nh_set_gateway(nh, addr);
+			if (rtnl_route_get_family(route) == AF_MPLS) {
+				addr = nl_cli_addr_parse(arg, 0);
+				rtnl_route_nh_set_via(nh, addr);
+			} else {
+				addr = nl_cli_addr_parse(arg,rtnl_route_get_family(route));
+				rtnl_route_nh_set_gateway(nh, addr);
+			}
+			nl_addr_put(addr);
+			break;
+
+		case NH_AS:
+			addr = nl_cli_addr_parse(arg,
+						 rtnl_route_get_family(route));
+			rtnl_route_nh_set_newdst(nh, addr);
 			nl_addr_put(addr);
 			break;
 
-- 
2.11.0 (Apple Git-81)




More information about the libnl mailing list