Skip to content

Commit

Permalink
[MPLS][libnl3] libnl patches for supporting MPLS
Browse files Browse the repository at this point in the history
* New accessors in libnl3 for MPLS attributes
* contains patch files for bug fixes in libnl3 for MPLS attribute parsing
  • Loading branch information
qbdwlr committed Jun 16, 2021
1 parent 2960136 commit 3d62923
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 1 deletion.
3 changes: 2 additions & 1 deletion files/build_templates/init_cfg.json.j2
Expand Up @@ -11,7 +11,8 @@
"polling_interval": "300",
{%- for crm_res in ["ipv4_route", "ipv6_route", "ipv4_nexthop", "ipv6_nexthop", "ipv4_neighbor",
"ipv6_neighbor", "nexthop_group_member", "nexthop_group", "acl_table",
"acl_group", "acl_entry", "acl_counter", "fdb_entry", "snat_entry", "dnat_entry", "ipmc_entry"] %}
"acl_group", "acl_entry", "acl_counter", "fdb_entry", "snat_entry", "dnat_entry",
"ipmc_entry", "mpls_inseg", "mpls_nexthop"] %}
"{{crm_res}}_threshold_type": "percentage",
"{{crm_res}}_low_threshold": "70",
"{{crm_res}}_high_threshold": "85"{% if not loop.last %},{% endif -%}
Expand Down
1 change: 1 addition & 0 deletions src/libnl3/.gitignore
Expand Up @@ -3,3 +3,4 @@
!debian/
debian/libnl-*/
!Makefile
!patch
4 changes: 4 additions & 0 deletions src/libnl3/Makefile
Expand Up @@ -20,6 +20,10 @@ $(addprefix $(DEST)/, $(MAIN_TARGET)): $(DEST)/% :
pushd libnl3-$(LIBNL3_VERSION_BASE)
git checkout tags/libnl$(subst .,_,$(LIBNL3_VERSION_BASE))

git checkout -b sonic
stg init
stg import -s ../patch/series

ln -s ../debian debian
dpkg-buildpackage -rfakeroot -b -us -uc -j$(SONIC_CONFIG_MAKE_JOBS) --admindir $(SONIC_DPKG_ADMINDIR)
popd
Expand Down
77 changes: 77 additions & 0 deletions src/libnl3/patch/0001-mpls-encap-accessors.patch
@@ -0,0 +1,77 @@
From 701122c539d6da3fbd3367be6e62141328ebeb07 Mon Sep 17 00:00:00 2001
From: Ann Pokora <apokora@juniper.net>
Date: Tue, 25 May 2021 18:07:37 -0700
Subject: [PATCH 1/2] mpls encap accessors

Signed-off-by: Ann Pokora <apokora@juniper.net>
---
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

63 changes: 63 additions & 0 deletions src/libnl3/patch/0002-mpls-remove-nl_addr_valid.patch
@@ -0,0 +1,63 @@
From c89d1a129f71d3d2f76e6cbadb11ef41d8941a73 Mon Sep 17 00:00:00 2001
From: Ann Pokora <apokora@juniper.net>
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 <apokora@juniper.net>
---
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),
- 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

2 changes: 2 additions & 0 deletions src/libnl3/patch/series
@@ -0,0 +1,2 @@
0001-mpls-encap-accessors.patch
0002-mpls-remove-nl_addr_valid.patch

0 comments on commit 3d62923

Please sign in to comment.