Skip to content

Commit 035a3c6

Browse files
committed
nexthop group support
Signed-off-by: nakano.kanji <[email protected]>
1 parent 07cd4ff commit 035a3c6

File tree

5 files changed

+341
-1
lines changed

5 files changed

+341
-1
lines changed

dockers/docker-fpm-frr/frr/zebra/zebra.conf.j2

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,17 @@
77
{% endblock banner %}
88
!
99
{% block fpm %}
10+
{% if ( ('localhost' in DEVICE_METADATA) and ('nexthop_group' in DEVICE_METADATA['localhost']) and
11+
(DEVICE_METADATA['localhost']['nexthop_group'] == 'enabled') ) %}
12+
! enable next hop group support
13+
zebra nexthop kernel enable
14+
fpm use-next-hop-groups
15+
{% else %}
1016
! Force disable next hop group support
1117
no zebra nexthop kernel enable
1218
! Uses the old known FPM behavior of including next hop information in the route (e.g. RTM_NEWROUTE) messages
13-
no fpm use-next-hop-groups
19+
no fpm use-next-hop-groupss
20+
{% endif %}
1421
!
1522
fpm address 127.0.0.1
1623
{% endblock fpm %}
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
diff --git a/src/libnl3/patch/0003-Adding-support-for-RTA_NH_ID-attribute.patch b/src/libnl3/patch/0003-Adding-support-for-RTA_NH_ID-attribute.patch
2+
new file mode 100644
3+
index 000000000..09ceed803
4+
--- /dev/null
5+
+++ b/src/libnl3/patch/0003-Adding-support-for-RTA_NH_ID-attribute.patch
6+
@@ -0,0 +1,154 @@
7+
+From 70e995bd076b5027414e1332a453f366f20c7002 Mon Sep 17 00:00:00 2001
8+
+From: Fernando <[email protected]>
9+
+Date: Mon, 19 Sep 2022 12:56:46 -0300
10+
+Subject: Adding support for RTA_NH_ID attribute
11+
+
12+
+---
13+
+ include/netlink-private/types.h | 1 +
14+
+ include/netlink/route/route.h | 2 ++
15+
+ lib/route/route_obj.c | 23 +++++++++++++++++++++++
16+
+ 3 files changed, 26 insertions(+)
17+
+
18+
+diff --git a/include/netlink-private/types.h b/include/netlink-private/types.h
19+
+index 97af3e5..51e58b1 100644
20+
+--- a/include/netlink-private/types.h
21+
++++ b/include/netlink-private/types.h
22+
+@@ -348,6 +348,7 @@ struct rtnl_route
23+
+ uint32_t rt_metrics[RTAX_MAX];
24+
+ uint32_t rt_metrics_mask;
25+
+ uint32_t rt_nr_nh;
26+
++ uint32_t rt_nh_id;
27+
+ struct nl_addr * rt_pref_src;
28+
+ struct nl_list_head rt_nexthops;
29+
+ struct rtnl_rtcacheinfo rt_cacheinfo;
30+
+diff --git a/include/netlink/route/route.h b/include/netlink/route/route.h
31+
+index 824dae3..9cfa393 100644
32+
+--- a/include/netlink/route/route.h
33+
++++ b/include/netlink/route/route.h
34+
+@@ -93,6 +93,8 @@ extern int rtnl_route_set_pref_src(struct rtnl_route *, struct nl_addr *);
35+
+ extern struct nl_addr *rtnl_route_get_pref_src(struct rtnl_route *);
36+
+ extern void rtnl_route_set_iif(struct rtnl_route *, int);
37+
+ extern int rtnl_route_get_iif(struct rtnl_route *);
38+
++extern void rtnl_route_set_nh_id(struct rtnl_route *, uint32_t);
39+
++extern uint32_t rtnl_route_get_nh_id(struct rtnl_route *);
40+
+ extern int rtnl_route_get_src_len(struct rtnl_route *);
41+
+ extern void rtnl_route_set_ttl_propagate(struct rtnl_route *route,
42+
+ uint8_t ttl_prop);
43+
+diff --git a/lib/route/route_obj.c b/lib/route/route_obj.c
44+
+index bacabe8..5d9d4ce 100644
45+
+--- a/lib/route/route_obj.c
46+
++++ b/lib/route/route_obj.c
47+
+@@ -65,6 +65,7 @@
48+
+ #define ROUTE_ATTR_REALMS 0x010000
49+
+ #define ROUTE_ATTR_CACHEINFO 0x020000
50+
+ #define ROUTE_ATTR_TTL_PROPAGATE 0x040000
51+
++#define ROUTE_ATTR_NH_ID 0x080000
52+
+ /** @endcond */
53+
+
54+
+ static void route_constructor(struct nl_object *c)
55+
+@@ -252,6 +253,8 @@ static void route_dump_details(struct nl_object *a, struct nl_dump_params *p)
56+
+ nl_dump(p, " ttl-propagate %s",
57+
+ r->rt_ttl_propagate ? "enabled" : "disabled");
58+
+ }
59+
++ if (r->ce_mask & ROUTE_ATTR_NH_ID)
60+
++ nl_dump(p, "nh id %d ", r->rt_nh_id);
61+
+
62+
+ nl_dump(p, "\n");
63+
+
64+
+@@ -391,6 +394,7 @@ static uint64_t route_compare(struct nl_object *_a, struct nl_object *_b,
65+
+ b->rt_pref_src));
66+
+ diff |= ROUTE_DIFF(TTL_PROPAGATE,
67+
+ a->rt_ttl_propagate != b->rt_ttl_propagate);
68+
++ diff |= ROUTE_DIFF(NH_ID, a->rt_nh_id != b->rt_nh_id);
69+
+
70+
+ if (flags & LOOSE_COMPARISON) {
71+
+ nl_list_for_each_entry(nh_b, &b->rt_nexthops, rtnh_list) {
72+
+@@ -589,6 +593,7 @@ static const struct trans_tbl route_attrs[] = {
73+
+ __ADD(ROUTE_ATTR_REALMS, realms),
74+
+ __ADD(ROUTE_ATTR_CACHEINFO, cacheinfo),
75+
+ __ADD(ROUTE_ATTR_TTL_PROPAGATE, ttl_propagate),
76+
++ __ADD(ROUTE_ATTR_NH_ID, nh_id),
77+
+ };
78+
+
79+
+ static char *route_attrs2str(int attrs, char *buf, size_t len)
80+
+@@ -862,6 +867,17 @@ int rtnl_route_get_iif(struct rtnl_route *route)
81+
+ return route->rt_iif;
82+
+ }
83+
+
84+
++void rtnl_route_set_nh_id(struct rtnl_route *route, uint32_t nhid)
85+
++{
86+
++ route->rt_nh_id = nhid;
87+
++ route->ce_mask |= ROUTE_ATTR_NH_ID;
88+
++}
89+
++
90+
++uint32_t rtnl_route_get_nh_id(struct rtnl_route *route)
91+
++{
92+
++ return route->rt_nh_id;
93+
++}
94+
++
95+
+ void rtnl_route_add_nexthop(struct rtnl_route *route, struct rtnl_nexthop *nh)
96+
+ {
97+
+ nl_list_add_tail(&nh->rtnh_list, &route->rt_nexthops);
98+
+@@ -1018,6 +1034,7 @@ static struct nla_policy route_policy[RTA_MAX+1] = {
99+
+ [RTA_TTL_PROPAGATE] = { .type = NLA_U8 },
100+
+ [RTA_ENCAP] = { .type = NLA_NESTED },
101+
+ [RTA_ENCAP_TYPE] = { .type = NLA_U16 },
102+
++ [RTA_NH_ID] = { .type = NLA_U32 },
103+
+ };
104+
+
105+
+ static int parse_multipath(struct rtnl_route *route, struct nlattr *attr)
106+
+@@ -1201,6 +1218,9 @@ int rtnl_route_parse(struct nlmsghdr *nlh, struct rtnl_route **result)
107+
+ nl_addr_put(addr);
108+
+ }
109+
+
110+
++ if (tb[RTA_NH_ID])
111+
++ rtnl_route_set_nh_id(route, nla_get_u32(tb[RTA_NH_ID]));
112+
++
113+
+ if (tb[RTA_METRICS]) {
114+
+ struct nlattr *mtb[RTAX_MAX + 1];
115+
+ int i;
116+
+@@ -1404,6 +1424,9 @@ int rtnl_route_build_msg(struct nl_msg *msg, struct rtnl_route *route)
117+
+ if (route->ce_mask & ROUTE_ATTR_TTL_PROPAGATE)
118+
+ NLA_PUT_U8(msg, RTA_TTL_PROPAGATE, route->rt_ttl_propagate);
119+
+
120+
++ if (route->ce_mask & ROUTE_ATTR_NH_ID)
121+
++ NLA_PUT_U32(msg, RTA_NH_ID, route->rt_nh_id);
122+
++
123+
+ if (route->rt_nmetrics > 0) {
124+
+ uint32_t val;
125+
+
126+
+--
127+
+2.25.1
128+
+
129+
+diff --git a/include/linux-private/linux/rtnetlink.h b/include/linux-private/linux/rtnetlink.h
130+
+index 8c1d600..82fb56b 100644
131+
+--- a/include/linux-private/linux/rtnetlink.h
132+
++++ b/include/linux-private/linux/rtnetlink.h
133+
+@@ -342,6 +342,7 @@ enum rtattr_type_t {
134+
+ RTA_IP_PROTO,
135+
+ RTA_SPORT,
136+
+ RTA_DPORT,
137+
++ RTA_NH_ID,
138+
+ __RTA_MAX
139+
+ };
140+
+
141+
+diff --git a/libnl-route-3.sym b/libnl-route-3.sym
142+
+index ce6d714..fb81b7f 100644
143+
+--- a/libnl-route-3.sym
144+
++++ b/libnl-route-3.sym
145+
+@@ -690,6 +690,7 @@ global:
146+
+ rtnl_route_get_family;
147+
+ rtnl_route_get_flags;
148+
+ rtnl_route_get_iif;
149+
++ rtnl_route_get_nh_id;
150+
+ rtnl_route_get_metric;
151+
+ rtnl_route_get_nexthops;
152+
+ rtnl_route_get_nnexthops;
153+
+@@ -732,6 +733,7 @@ global:
154+
+ rtnl_route_set_family;
155+
+ rtnl_route_set_flags;
156+
+ rtnl_route_set_iif;
157+
++ rtnl_route_set_nh_id;
158+
+ rtnl_route_set_metric;
159+
+ rtnl_route_set_pref_src;
160+
+ rtnl_route_set_priority;
161+
diff --git a/src/libnl3/patch/series b/src/libnl3/patch/series
162+
index 4508b1dd6..4c7c2d8e2 100644
163+
--- a/src/libnl3/patch/series
164+
+++ b/src/libnl3/patch/series
165+
@@ -1,2 +1,3 @@
166+
0001-mpls-encap-accessors.patch
167+
0002-mpls-remove-nl_addr_valid.patch
168+
+0003-Adding-support-for-RTA_NH_ID-attribute.patch
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
From 70e995bd076b5027414e1332a453f366f20c7002 Mon Sep 17 00:00:00 2001
2+
From: Fernando <[email protected]>
3+
Date: Mon, 19 Sep 2022 12:56:46 -0300
4+
Subject: Adding support for RTA_NH_ID attribute
5+
6+
---
7+
include/netlink-private/types.h | 1 +
8+
include/netlink/route/route.h | 2 ++
9+
lib/route/route_obj.c | 23 +++++++++++++++++++++++
10+
3 files changed, 26 insertions(+)
11+
12+
diff --git a/include/netlink-private/types.h b/include/netlink-private/types.h
13+
index 97af3e5..51e58b1 100644
14+
--- a/include/netlink-private/types.h
15+
+++ b/include/netlink-private/types.h
16+
@@ -348,6 +348,7 @@ struct rtnl_route
17+
uint32_t rt_metrics[RTAX_MAX];
18+
uint32_t rt_metrics_mask;
19+
uint32_t rt_nr_nh;
20+
+ uint32_t rt_nh_id;
21+
struct nl_addr * rt_pref_src;
22+
struct nl_list_head rt_nexthops;
23+
struct rtnl_rtcacheinfo rt_cacheinfo;
24+
diff --git a/include/netlink/route/route.h b/include/netlink/route/route.h
25+
index 824dae3..9cfa393 100644
26+
--- a/include/netlink/route/route.h
27+
+++ b/include/netlink/route/route.h
28+
@@ -93,6 +93,8 @@ extern int rtnl_route_set_pref_src(struct rtnl_route *, struct nl_addr *);
29+
extern struct nl_addr *rtnl_route_get_pref_src(struct rtnl_route *);
30+
extern void rtnl_route_set_iif(struct rtnl_route *, int);
31+
extern int rtnl_route_get_iif(struct rtnl_route *);
32+
+extern void rtnl_route_set_nh_id(struct rtnl_route *, uint32_t);
33+
+extern uint32_t rtnl_route_get_nh_id(struct rtnl_route *);
34+
extern int rtnl_route_get_src_len(struct rtnl_route *);
35+
extern void rtnl_route_set_ttl_propagate(struct rtnl_route *route,
36+
uint8_t ttl_prop);
37+
diff --git a/lib/route/route_obj.c b/lib/route/route_obj.c
38+
index bacabe8..5d9d4ce 100644
39+
--- a/lib/route/route_obj.c
40+
+++ b/lib/route/route_obj.c
41+
@@ -65,6 +65,7 @@
42+
#define ROUTE_ATTR_REALMS 0x010000
43+
#define ROUTE_ATTR_CACHEINFO 0x020000
44+
#define ROUTE_ATTR_TTL_PROPAGATE 0x040000
45+
+#define ROUTE_ATTR_NH_ID 0x080000
46+
/** @endcond */
47+
48+
static void route_constructor(struct nl_object *c)
49+
@@ -252,6 +253,8 @@ static void route_dump_details(struct nl_object *a, struct nl_dump_params *p)
50+
nl_dump(p, " ttl-propagate %s",
51+
r->rt_ttl_propagate ? "enabled" : "disabled");
52+
}
53+
+ if (r->ce_mask & ROUTE_ATTR_NH_ID)
54+
+ nl_dump(p, "nh id %d ", r->rt_nh_id);
55+
56+
nl_dump(p, "\n");
57+
58+
@@ -391,6 +394,7 @@ static uint64_t route_compare(struct nl_object *_a, struct nl_object *_b,
59+
b->rt_pref_src));
60+
diff |= ROUTE_DIFF(TTL_PROPAGATE,
61+
a->rt_ttl_propagate != b->rt_ttl_propagate);
62+
+ diff |= ROUTE_DIFF(NH_ID, a->rt_nh_id != b->rt_nh_id);
63+
64+
if (flags & LOOSE_COMPARISON) {
65+
nl_list_for_each_entry(nh_b, &b->rt_nexthops, rtnh_list) {
66+
@@ -589,6 +593,7 @@ static const struct trans_tbl route_attrs[] = {
67+
__ADD(ROUTE_ATTR_REALMS, realms),
68+
__ADD(ROUTE_ATTR_CACHEINFO, cacheinfo),
69+
__ADD(ROUTE_ATTR_TTL_PROPAGATE, ttl_propagate),
70+
+ __ADD(ROUTE_ATTR_NH_ID, nh_id),
71+
};
72+
73+
static char *route_attrs2str(int attrs, char *buf, size_t len)
74+
@@ -862,6 +867,17 @@ int rtnl_route_get_iif(struct rtnl_route *route)
75+
return route->rt_iif;
76+
}
77+
78+
+void rtnl_route_set_nh_id(struct rtnl_route *route, uint32_t nhid)
79+
+{
80+
+ route->rt_nh_id = nhid;
81+
+ route->ce_mask |= ROUTE_ATTR_NH_ID;
82+
+}
83+
+
84+
+uint32_t rtnl_route_get_nh_id(struct rtnl_route *route)
85+
+{
86+
+ return route->rt_nh_id;
87+
+}
88+
+
89+
void rtnl_route_add_nexthop(struct rtnl_route *route, struct rtnl_nexthop *nh)
90+
{
91+
nl_list_add_tail(&nh->rtnh_list, &route->rt_nexthops);
92+
@@ -1018,6 +1034,7 @@ static struct nla_policy route_policy[RTA_MAX+1] = {
93+
[RTA_TTL_PROPAGATE] = { .type = NLA_U8 },
94+
[RTA_ENCAP] = { .type = NLA_NESTED },
95+
[RTA_ENCAP_TYPE] = { .type = NLA_U16 },
96+
+ [RTA_NH_ID] = { .type = NLA_U32 },
97+
};
98+
99+
static int parse_multipath(struct rtnl_route *route, struct nlattr *attr)
100+
@@ -1201,6 +1218,9 @@ int rtnl_route_parse(struct nlmsghdr *nlh, struct rtnl_route **result)
101+
nl_addr_put(addr);
102+
}
103+
104+
+ if (tb[RTA_NH_ID])
105+
+ rtnl_route_set_nh_id(route, nla_get_u32(tb[RTA_NH_ID]));
106+
+
107+
if (tb[RTA_METRICS]) {
108+
struct nlattr *mtb[RTAX_MAX + 1];
109+
int i;
110+
@@ -1404,6 +1424,9 @@ int rtnl_route_build_msg(struct nl_msg *msg, struct rtnl_route *route)
111+
if (route->ce_mask & ROUTE_ATTR_TTL_PROPAGATE)
112+
NLA_PUT_U8(msg, RTA_TTL_PROPAGATE, route->rt_ttl_propagate);
113+
114+
+ if (route->ce_mask & ROUTE_ATTR_NH_ID)
115+
+ NLA_PUT_U32(msg, RTA_NH_ID, route->rt_nh_id);
116+
+
117+
if (route->rt_nmetrics > 0) {
118+
uint32_t val;
119+
120+
--
121+
2.25.1
122+
123+
diff --git a/include/linux-private/linux/rtnetlink.h b/include/linux-private/linux/rtnetlink.h
124+
index 8c1d600..82fb56b 100644
125+
--- a/include/linux-private/linux/rtnetlink.h
126+
+++ b/include/linux-private/linux/rtnetlink.h
127+
@@ -342,6 +342,7 @@ enum rtattr_type_t {
128+
RTA_IP_PROTO,
129+
RTA_SPORT,
130+
RTA_DPORT,
131+
+ RTA_NH_ID,
132+
__RTA_MAX
133+
};
134+
135+
diff --git a/libnl-route-3.sym b/libnl-route-3.sym
136+
index ce6d714..fb81b7f 100644
137+
--- a/libnl-route-3.sym
138+
+++ b/libnl-route-3.sym
139+
@@ -690,6 +690,7 @@ global:
140+
rtnl_route_get_family;
141+
rtnl_route_get_flags;
142+
rtnl_route_get_iif;
143+
+ rtnl_route_get_nh_id;
144+
rtnl_route_get_metric;
145+
rtnl_route_get_nexthops;
146+
rtnl_route_get_nnexthops;
147+
@@ -732,6 +733,7 @@ global:
148+
rtnl_route_set_family;
149+
rtnl_route_set_flags;
150+
rtnl_route_set_iif;
151+
+ rtnl_route_set_nh_id;
152+
rtnl_route_set_metric;
153+
rtnl_route_set_pref_src;
154+
rtnl_route_set_priority;

src/libnl3/patch/series

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
0001-mpls-encap-accessors.patch
22
0002-mpls-remove-nl_addr_valid.patch
3+
0003-Adding-support-for-RTA_NH_ID-attribute.patch

src/sonic-yang-models/yang-models/sonic-device_metadata.yang

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,16 @@ module sonic-device_metadata {
254254
type inet:ipv4-address;
255255
description "BGP Router identifier";
256256
}
257+
258+
leaf nexthop_group {
259+
description "Enable or disable Nexthop Group feature. This value only takes effect during boot time.";
260+
type enumeration {
261+
enum enabled;
262+
enum disabled;
263+
}
264+
default disabled;
265+
}
266+
257267
}
258268
/* end of container localhost */
259269
}

0 commit comments

Comments
 (0)