-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
libnl3 updates for MPLS #7195
libnl3 updates for MPLS #7195
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
!debian/ | ||
debian/libnl-*/ | ||
!Makefile | ||
!patch |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
From 701122c539d6da3fbd3367be6e62141328ebeb07 Mon Sep 17 00:00:00 2001 | ||
From: Ann Pokora <[email protected]> | ||
Date: Tue, 25 May 2021 18:07:37 -0700 | ||
Subject: [PATCH 1/2] mpls encap accessors | ||
|
||
Signed-off-by: Ann Pokora <[email protected]> | ||
--- | ||
include/netlink/route/nexthop.h | 2 ++ | ||
lib/route/nh_encap_mpls.c | 28 ++++++++++++++++++++++++++++ | ||
libnl-route-3.sym | 2 ++ | ||
3 files changed, 32 insertions(+) | ||
|
||
diff --git a/include/netlink/route/nexthop.h b/include/netlink/route/nexthop.h | ||
index 5b422dd..a502005 100644 | ||
--- a/include/netlink/route/nexthop.h | ||
+++ b/include/netlink/route/nexthop.h | ||
@@ -70,6 +70,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 081661e..18336ac 100644 | ||
--- a/lib/route/nh_encap_mpls.c | ||
+++ b/lib/route/nh_encap_mpls.c | ||
@@ -133,3 +133,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 4a65503..ce6d714 100644 | ||
--- a/libnl-route-3.sym | ||
+++ b/libnl-route-3.sym | ||
@@ -1127,6 +1127,8 @@ global: | ||
rtnl_qdisc_mqprio_set_priomap; | ||
rtnl_qdisc_mqprio_set_queue; | ||
rtnl_qdisc_mqprio_set_shaper; | ||
+ rtnl_route_nh_get_encap_mpls_dst; | ||
+ rtnl_route_nh_get_encap_mpls_ttl; | ||
rtnl_rule_get_dport; | ||
rtnl_rule_get_ipproto; | ||
rtnl_rule_get_protocol; | ||
-- | ||
2.7.4 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
From c89d1a129f71d3d2f76e6cbadb11ef41d8941a73 Mon Sep 17 00:00:00 2001 | ||
From: Ann Pokora <[email protected]> | ||
Date: Tue, 25 May 2021 18:10:04 -0700 | ||
Subject: [PATCH 2/2] mpls remove nl_addr_valid | ||
|
||
The removed calls to nl_addr_valid() are passing in a pointer to a binary address | ||
and the length of the binary address, which does not match expected arguments for | ||
nl_addr_valid(). | ||
nl_addr_valid() expects a pointer to an ASCII string and the address family of | ||
the string format. | ||
The incorrect arguments cause unexpected failures and the expected arguments are | ||
not available in the context. | ||
|
||
Signed-off-by: Ann Pokora <[email protected]> | ||
--- | ||
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 7a9904c..ac0095e 100644 | ||
--- a/lib/route/nexthop.c | ||
+++ b/lib/route/nexthop.c | ||
@@ -351,10 +351,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), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of removing the validation, can we fix the arguments.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @smahesh That still isn't valid. Look at the code for nl_addr_valid() in libnl3. It is looking for an ASCII string and validating the string format. addr does not container a string, The return from nl_addr_get_binary_addr() is not a string. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nl_addr_valid() is using the route_nh_set which is not mpls specific. this is the IP functions. how can this function pass now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lguohan RTA_NEWDST is specific to MPLS. NEWDST contains the MPLS labelstack associated with the NH. |
||
- nl_addr_get_len(addr))) | ||
- return -NLE_INVAL; | ||
- | ||
if (addr) { | ||
nh->rtnh_newdst = nl_addr_get(addr); | ||
nh->ce_mask |= NH_ATTR_NEWDST; | ||
@@ -378,10 +374,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 18336ac..6c5a3c7 100644 | ||
--- a/lib/route/nh_encap_mpls.c | ||
+++ b/lib/route/nh_encap_mpls.c | ||
@@ -109,10 +109,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; | ||
-- | ||
2.7.4 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
0001-mpls-encap-accessors.patch | ||
0002-mpls-remove-nl_addr_valid.patch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we remove the validation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lguohan nl_addr_valid() arguments are supposed to be a pointer to an ASCII string and an address family value (AF_MPLS, AF_INET, AF_INET6)... it then uses these to validate that the string format contains an address for the specified family.
The removed calls to nl_addr_valid() were instead passing in a pointer to a binary address and the length of the binary address... this is completely wrong. For most cases, the length of the binary address would not match any of the values of supported address families, so nl_addr_valid() would return true. But if the binary address was an MPLS label stack with 3 labels, then the length would match the value of AF_DECnet (12) and it attempts to parse the binary address as if it were an ASCII string... this fails and nl_addr_valid() returns false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you put the above explaination into the this patch file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lguohan explanation is added to patch file.