From efe8aad98ce341d98f0431b5bfb665e33593c299 Mon Sep 17 00:00:00 2001 From: Ann Pokora Date: Fri, 4 Mar 2022 12:17:42 +0100 Subject: [PATCH 1/2] route: remove incorrect nl_addr_valid() from rtnl_route_nh_set_newdst(), etc. nl_addr_valid() expects an address family as argument, not the length. It also expects an address in string form, not in binary. Those checks were wrong. Also, it seems not necessary to validate the argument, purely based on some criteria of the argument alone. Just set the provided address. Drop those checks. This is relevant for NEWDST and ENCAP_MPLS DST processing. Fixes: 760d74f99c88 ('route: Add support for MPLS encap') Fixes: 0a6d27ce90a1 ('route: Add support for MPLS address family') [thaller@redhat.com: split original patch and rewrite commit message]. --- lib/route/nexthop.c | 8 -------- lib/route/nh_encap_mpls.c | 4 ---- 2 files changed, 12 deletions(-) diff --git a/lib/route/nexthop.c b/lib/route/nexthop.c index 6accf0d1f..683513711 100644 --- a/lib/route/nexthop.c +++ b/lib/route/nexthop.c @@ -344,10 +344,6 @@ int rtnl_route_nh_set_newdst(struct rtnl_nexthop *nh, struct nl_addr *addr) { struct nl_addr *old = nh->rtnh_newdst; - if (!nl_addr_valid(nl_addr_get_binary_addr(addr), - nl_addr_get_len(addr))) - return -NLE_INVAL; - if (addr) { nh->rtnh_newdst = nl_addr_get(addr); nh->ce_mask |= NH_ATTR_NEWDST; @@ -371,10 +367,6 @@ int rtnl_route_nh_set_via(struct rtnl_nexthop *nh, struct nl_addr *addr) { struct nl_addr *old = nh->rtnh_via; - if (!nl_addr_valid(nl_addr_get_binary_addr(addr), - nl_addr_get_len(addr))) - return -NLE_INVAL; - if (addr) { nh->rtnh_via = nl_addr_get(addr); nh->ce_mask |= NH_ATTR_VIA; diff --git a/lib/route/nh_encap_mpls.c b/lib/route/nh_encap_mpls.c index 89972bbd1..65355a76b 100644 --- a/lib/route/nh_encap_mpls.c +++ b/lib/route/nh_encap_mpls.c @@ -108,10 +108,6 @@ int rtnl_route_nh_encap_mpls(struct rtnl_nexthop *nh, if (!addr) return -NLE_INVAL; - if (!nl_addr_valid(nl_addr_get_binary_addr(addr), - nl_addr_get_len(addr))) - return -NLE_INVAL; - rtnh_encap = calloc(1, sizeof(*rtnh_encap)); if (!rtnh_encap) return -NLE_NOMEM; From cc680d43fafc42c07df96401cfa0bf03b3c84e7c Mon Sep 17 00:00:00 2001 From: Ann Pokora Date: Tue, 25 May 2021 09:58:29 -0700 Subject: [PATCH 2/2] route: add accessors for setting/getting ENCAP_MPLS attributes [thaller@redhat.com: split original patch, reword commit message and fix symbols in "libnl-route-3.sym"] --- include/netlink/route/nexthop.h | 2 ++ lib/route/nh_encap_mpls.c | 28 ++++++++++++++++++++++++++++ libnl-route-3.sym | 4 +++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/include/netlink/route/nexthop.h b/include/netlink/route/nexthop.h index d43ebf42b..c4a2604aa 100644 --- a/include/netlink/route/nexthop.h +++ b/include/netlink/route/nexthop.h @@ -64,6 +64,8 @@ extern int rtnl_route_nh_str2flags(const char *); extern int rtnl_route_nh_encap_mpls(struct rtnl_nexthop *nh, struct nl_addr *addr, uint8_t ttl); +extern struct nl_addr * rtnl_route_nh_get_encap_mpls_dst(struct rtnl_nexthop *); +extern uint8_t rtnl_route_nh_get_encap_mpls_ttl(struct rtnl_nexthop *); #ifdef __cplusplus } #endif diff --git a/lib/route/nh_encap_mpls.c b/lib/route/nh_encap_mpls.c index 65355a76b..d30acc2cf 100644 --- a/lib/route/nh_encap_mpls.c +++ b/lib/route/nh_encap_mpls.c @@ -128,3 +128,31 @@ int rtnl_route_nh_encap_mpls(struct rtnl_nexthop *nh, return 0; } + +struct nl_addr *rtnl_route_nh_get_encap_mpls_dst(struct rtnl_nexthop *nh) +{ + struct mpls_iptunnel_encap *mpls_encap; + + if (!nh->rtnh_encap || nh->rtnh_encap->ops->encap_type != LWTUNNEL_ENCAP_MPLS) + return NULL; + + mpls_encap = (struct mpls_iptunnel_encap *)nh->rtnh_encap->priv; + if (!mpls_encap) + return NULL; + + return mpls_encap->dst; +} + +uint8_t rtnl_route_nh_get_encap_mpls_ttl(struct rtnl_nexthop *nh) +{ + struct mpls_iptunnel_encap *mpls_encap; + + if (!nh->rtnh_encap || nh->rtnh_encap->ops->encap_type != LWTUNNEL_ENCAP_MPLS) + return 0; + + mpls_encap = (struct mpls_iptunnel_encap *)nh->rtnh_encap->priv; + if (!mpls_encap) + return 0; + + return mpls_encap->ttl; +} diff --git a/libnl-route-3.sym b/libnl-route-3.sym index 584dd5ad1..bb3b80792 100644 --- a/libnl-route-3.sym +++ b/libnl-route-3.sym @@ -1152,6 +1152,8 @@ global: } libnl_3_4; libnl_3_6 { - rtnl_link_macsec_set_offload; rtnl_link_macsec_get_offload; + rtnl_link_macsec_set_offload; + rtnl_route_nh_get_encap_mpls_dst; + rtnl_route_nh_get_encap_mpls_ttl; } libnl_3_5;