mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-13 22:26:14 +00:00
lib: Add weight to nexthop for nexthop-group nexthops
Add the ability to read in the weight of a nexthop and store/handle it appropriately nexthop-group BLUE nexthop 192.168.201.44 weight 33 nexthop 192.168.201.45 weight 66 nexthop 192.168.201.46 weight 99 Is appropriately read in and handled as appropriate. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
This commit is contained in:
parent
bd054c1aa2
commit
597371a615
@ -42,6 +42,7 @@ struct nexthop_hold {
|
|||||||
union sockunion *addr;
|
union sockunion *addr;
|
||||||
char *intf;
|
char *intf;
|
||||||
char *labels;
|
char *labels;
|
||||||
|
uint32_t weight;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct nexthop_group_hooks {
|
struct nexthop_group_hooks {
|
||||||
@ -526,8 +527,8 @@ DEFUN_NOSH(no_nexthop_group, no_nexthop_group_cmd, "no nexthop-group NHGNAME",
|
|||||||
static void nexthop_group_save_nhop(struct nexthop_group_cmd *nhgc,
|
static void nexthop_group_save_nhop(struct nexthop_group_cmd *nhgc,
|
||||||
const char *nhvrf_name,
|
const char *nhvrf_name,
|
||||||
const union sockunion *addr,
|
const union sockunion *addr,
|
||||||
const char *intf,
|
const char *intf, const char *labels,
|
||||||
const char *labels)
|
const uint32_t weight)
|
||||||
{
|
{
|
||||||
struct nexthop_hold *nh;
|
struct nexthop_hold *nh;
|
||||||
|
|
||||||
@ -542,23 +543,26 @@ static void nexthop_group_save_nhop(struct nexthop_group_cmd *nhgc,
|
|||||||
if (labels)
|
if (labels)
|
||||||
nh->labels = XSTRDUP(MTYPE_TMP, labels);
|
nh->labels = XSTRDUP(MTYPE_TMP, labels);
|
||||||
|
|
||||||
|
nh->weight = weight;
|
||||||
|
|
||||||
listnode_add_sort(nhgc->nhg_list, nh);
|
listnode_add_sort(nhgc->nhg_list, nh);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void nexthop_group_unsave_nhop(struct nexthop_group_cmd *nhgc,
|
static void nexthop_group_unsave_nhop(struct nexthop_group_cmd *nhgc,
|
||||||
const char *nhvrf_name,
|
const char *nhvrf_name,
|
||||||
const union sockunion *addr,
|
const union sockunion *addr,
|
||||||
const char *intf,
|
const char *intf, const char *labels,
|
||||||
const char *labels)
|
const uint32_t weight)
|
||||||
{
|
{
|
||||||
struct nexthop_hold *nh;
|
struct nexthop_hold *nh;
|
||||||
struct listnode *node;
|
struct listnode *node;
|
||||||
|
|
||||||
for (ALL_LIST_ELEMENTS_RO(nhgc->nhg_list, node, nh)) {
|
for (ALL_LIST_ELEMENTS_RO(nhgc->nhg_list, node, nh)) {
|
||||||
if (nhgc_cmp_helper(nhvrf_name, nh->nhvrf_name) == 0 &&
|
if (nhgc_cmp_helper(nhvrf_name, nh->nhvrf_name) == 0
|
||||||
nhgc_addr_cmp_helper(addr, nh->addr) == 0 &&
|
&& nhgc_addr_cmp_helper(addr, nh->addr) == 0
|
||||||
nhgc_cmp_helper(intf, nh->intf) == 0 &&
|
&& nhgc_cmp_helper(intf, nh->intf) == 0
|
||||||
nhgc_cmp_helper(labels, nh->labels) == 0)
|
&& nhgc_cmp_helper(labels, nh->labels) == 0
|
||||||
|
&& weight == nh->weight)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -581,8 +585,8 @@ static void nexthop_group_unsave_nhop(struct nexthop_group_cmd *nhgc,
|
|||||||
static bool nexthop_group_parse_nexthop(struct nexthop *nhop,
|
static bool nexthop_group_parse_nexthop(struct nexthop *nhop,
|
||||||
const union sockunion *addr,
|
const union sockunion *addr,
|
||||||
const char *intf, const char *name,
|
const char *intf, const char *name,
|
||||||
const char *labels,
|
const char *labels, int *lbl_ret,
|
||||||
int *lbl_ret)
|
uint32_t weight)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
struct vrf *vrf;
|
struct vrf *vrf;
|
||||||
@ -639,6 +643,8 @@ static bool nexthop_group_parse_nexthop(struct nexthop *nhop,
|
|||||||
num, larray);
|
num, larray);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nhop->weight = weight;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -648,11 +654,9 @@ static bool nexthop_group_parse_nexthop(struct nexthop *nhop,
|
|||||||
static bool nexthop_group_parse_nhh(struct nexthop *nhop,
|
static bool nexthop_group_parse_nhh(struct nexthop *nhop,
|
||||||
const struct nexthop_hold *nhh)
|
const struct nexthop_hold *nhh)
|
||||||
{
|
{
|
||||||
return (nexthop_group_parse_nexthop(nhop, nhh->addr,
|
return (nexthop_group_parse_nexthop(nhop, nhh->addr, nhh->intf,
|
||||||
nhh->intf,
|
nhh->nhvrf_name, nhh->labels, NULL,
|
||||||
nhh->nhvrf_name,
|
nhh->weight));
|
||||||
nhh->labels,
|
|
||||||
NULL));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DEFPY(ecmp_nexthops, ecmp_nexthops_cmd,
|
DEFPY(ecmp_nexthops, ecmp_nexthops_cmd,
|
||||||
@ -664,6 +668,7 @@ DEFPY(ecmp_nexthops, ecmp_nexthops_cmd,
|
|||||||
[{ \
|
[{ \
|
||||||
nexthop-vrf NAME$vrf_name \
|
nexthop-vrf NAME$vrf_name \
|
||||||
|label WORD \
|
|label WORD \
|
||||||
|
|weight (1-255) \
|
||||||
}]",
|
}]",
|
||||||
NO_STR
|
NO_STR
|
||||||
"Specify one of the nexthops in this ECMP group\n"
|
"Specify one of the nexthops in this ECMP group\n"
|
||||||
@ -674,7 +679,9 @@ DEFPY(ecmp_nexthops, ecmp_nexthops_cmd,
|
|||||||
"If the nexthop is in a different vrf tell us\n"
|
"If the nexthop is in a different vrf tell us\n"
|
||||||
"The nexthop-vrf Name\n"
|
"The nexthop-vrf Name\n"
|
||||||
"Specify label(s) for this nexthop\n"
|
"Specify label(s) for this nexthop\n"
|
||||||
"One or more labels in the range (16-1048575) separated by '/'\n")
|
"One or more labels in the range (16-1048575) separated by '/'\n"
|
||||||
|
"Weight to be used by the nexthop for purposes of ECMP\n"
|
||||||
|
"Weight value to be used\n")
|
||||||
{
|
{
|
||||||
VTY_DECLVAR_CONTEXT(nexthop_group_cmd, nhgc);
|
VTY_DECLVAR_CONTEXT(nexthop_group_cmd, nhgc);
|
||||||
struct nexthop nhop;
|
struct nexthop nhop;
|
||||||
@ -682,8 +689,8 @@ DEFPY(ecmp_nexthops, ecmp_nexthops_cmd,
|
|||||||
int lbl_ret = 0;
|
int lbl_ret = 0;
|
||||||
bool legal;
|
bool legal;
|
||||||
|
|
||||||
legal = nexthop_group_parse_nexthop(&nhop, addr, intf, vrf_name,
|
legal = nexthop_group_parse_nexthop(&nhop, addr, intf, vrf_name, label,
|
||||||
label, &lbl_ret);
|
&lbl_ret, weight);
|
||||||
|
|
||||||
if (nhop.type == NEXTHOP_TYPE_IPV6
|
if (nhop.type == NEXTHOP_TYPE_IPV6
|
||||||
&& IN6_IS_ADDR_LINKLOCAL(&nhop.gate.ipv6)) {
|
&& IN6_IS_ADDR_LINKLOCAL(&nhop.gate.ipv6)) {
|
||||||
@ -716,7 +723,8 @@ DEFPY(ecmp_nexthops, ecmp_nexthops_cmd,
|
|||||||
nh = nexthop_exists(&nhgc->nhg, &nhop);
|
nh = nexthop_exists(&nhgc->nhg, &nhop);
|
||||||
|
|
||||||
if (no) {
|
if (no) {
|
||||||
nexthop_group_unsave_nhop(nhgc, vrf_name, addr, intf, label);
|
nexthop_group_unsave_nhop(nhgc, vrf_name, addr, intf, label,
|
||||||
|
weight);
|
||||||
if (nh) {
|
if (nh) {
|
||||||
_nexthop_del(&nhgc->nhg, nh);
|
_nexthop_del(&nhgc->nhg, nh);
|
||||||
|
|
||||||
@ -734,7 +742,8 @@ DEFPY(ecmp_nexthops, ecmp_nexthops_cmd,
|
|||||||
_nexthop_add(&nhgc->nhg.nexthop, nh);
|
_nexthop_add(&nhgc->nhg.nexthop, nh);
|
||||||
}
|
}
|
||||||
|
|
||||||
nexthop_group_save_nhop(nhgc, vrf_name, addr, intf, label);
|
nexthop_group_save_nhop(nhgc, vrf_name, addr, intf, label,
|
||||||
|
weight);
|
||||||
|
|
||||||
if (legal && nhg_hooks.add_nexthop)
|
if (legal && nhg_hooks.add_nexthop)
|
||||||
nhg_hooks.add_nexthop(nhgc, nh);
|
nhg_hooks.add_nexthop(nhgc, nh);
|
||||||
@ -794,6 +803,9 @@ void nexthop_group_write_nexthop(struct vty *vty, struct nexthop *nh)
|
|||||||
vty_out(vty, " label %s", buf);
|
vty_out(vty, " label %s", buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (nh->weight)
|
||||||
|
vty_out(vty, " weight %u", nh->weight);
|
||||||
|
|
||||||
vty_out(vty, "\n");
|
vty_out(vty, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -816,6 +828,9 @@ static void nexthop_group_write_nexthop_internal(struct vty *vty,
|
|||||||
if (nh->labels)
|
if (nh->labels)
|
||||||
vty_out(vty, " label %s", nh->labels);
|
vty_out(vty, " label %s", nh->labels);
|
||||||
|
|
||||||
|
if (nh->weight)
|
||||||
|
vty_out(vty, " weight %u", nh->weight);
|
||||||
|
|
||||||
vty_out(vty, "\n");
|
vty_out(vty, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user