Skip to content

Commit

Permalink
Merge pull request FRRouting#10151 from pguibert6WIND/ensure_routing_…
Browse files Browse the repository at this point in the history
…protocols_good_bw

zebra: avoid having speed set to UINT32_MAX
  • Loading branch information
donaldsharp authored Feb 2, 2024
2 parents 0800546 + 42c1652 commit 3d57f04
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 13 deletions.
5 changes: 2 additions & 3 deletions doc/user/zebra.rst
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,9 @@ Standard Commands
Enable or disable multicast flag for the interface.


.. clicmd:: bandwidth (1-10000000)
.. clicmd:: bandwidth (1-1000000)


Set bandwidth value of the interface in kilobits/sec. This is for
Set bandwidth value of the interface in Megabits/sec. This is for
calculating OSPF cost. This command does not affect the actual device
configuration.

Expand Down
2 changes: 1 addition & 1 deletion lib/libospf.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ extern "C" {
#define OSPF_TRANSMIT_DELAY_DEFAULT 1
#define OSPF_DEFAULT_BANDWIDTH 10000 /* Mbps */

#define OSPF_DEFAULT_REF_BANDWIDTH 100000 /* Mbps */
#define OSPF_DEFAULT_REF_BANDWIDTH 100000 /* Kbps */

#define OSPF_POLL_INTERVAL_DEFAULT 60
#define OSPF_NEIGHBOR_PRIORITY_DEFAULT 0
Expand Down
2 changes: 1 addition & 1 deletion ospf6d/ospf6_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ extern const char *const ospf6_interface_state_str[];
#define OSPF6_INTERFACE_TRANSDELAY 1
#define OSPF6_INTERFACE_INSTANCE_ID 0
#define OSPF6_INTERFACE_BANDWIDTH 10000 /* Mbps */
#define OSPF6_REFERENCE_BANDWIDTH 100000 /* Mbps */
#define OSPF6_REFERENCE_BANDWIDTH 100000 /* Kbps */
#define OSPF6_INTERFACE_SSO_RETRY_INT 1
#define OSPF6_INTERFACE_SSO_RETRY_MAX 5

Expand Down
2 changes: 1 addition & 1 deletion yang/frr-zebra.yang
Original file line number Diff line number Diff line change
Expand Up @@ -2050,7 +2050,7 @@ module frr-zebra {

leaf bandwidth {
type uint32 {
range "1..100000";
range "1..1000000";
}
units "megabits/sec";
description
Expand Down
13 changes: 10 additions & 3 deletions zebra/if_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ static uint32_t get_iflink_speed(struct interface *interface, int *error)
int sd;
int rc;
const char *ifname = interface->name;
uint32_t ret;

if (error)
*error = 0;
Expand All @@ -285,7 +286,7 @@ static uint32_t get_iflink_speed(struct interface *interface, int *error)
ifname, errno, safe_strerror(errno));
/* no vrf socket creation may probably mean vrf issue */
if (error)
*error = -1;
*error = INTERFACE_SPEED_ERROR_READ;
return 0;
}
/* Get the current link state for the interface */
Expand All @@ -299,14 +300,20 @@ static uint32_t get_iflink_speed(struct interface *interface, int *error)
ifname, errno, safe_strerror(errno));
/* no device means interface unreachable */
if (errno == ENODEV && error)
*error = -1;
*error = INTERFACE_SPEED_ERROR_READ;
ecmd.speed_hi = 0;
ecmd.speed = 0;
}

close(sd);

return ((uint32_t)ecmd.speed_hi << 16) | ecmd.speed;
ret = ((uint32_t)ecmd.speed_hi << 16) | ecmd.speed;
if (ret == UINT32_MAX) {
if (error)
*error = INTERFACE_SPEED_ERROR_UNKNOWN;
ret = 0;
}
return ret;
}

uint32_t kernel_get_speed(struct interface *ifp, int *error)
Expand Down
6 changes: 3 additions & 3 deletions zebra/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static void if_zebra_speed_update(struct event *thread)
* interfaces not available.
* note that loopback & virtual interfaces can return 0 as speed
*/
if (error < 0)
if (error == INTERFACE_SPEED_ERROR_READ)
return;

if (new_speed != ifp->speed) {
Expand All @@ -73,7 +73,7 @@ static void if_zebra_speed_update(struct event *thread)
changed = true;
}

if (changed || new_speed == UINT32_MAX) {
if (changed || error == INTERFACE_SPEED_ERROR_UNKNOWN) {
#define SPEED_UPDATE_SLEEP_TIME 5
#define SPEED_UPDATE_COUNT_MAX (4 * 60 / SPEED_UPDATE_SLEEP_TIME)
/*
Expand All @@ -88,7 +88,7 @@ static void if_zebra_speed_update(struct event *thread)
* to not update the system to keep track of that. This
* is far simpler to just stop trying after 4 minutes
*/
if (new_speed == UINT32_MAX &&
if (error == INTERFACE_SPEED_ERROR_UNKNOWN &&
zif->speed_update_count == SPEED_UPDATE_COUNT_MAX)
return;

Expand Down
3 changes: 3 additions & 0 deletions zebra/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ struct zebra_if {
ifindex_t link_ifindex;
struct interface *link;

#define INTERFACE_SPEED_ERROR_READ -1
#define INTERFACE_SPEED_ERROR_UNKNOWN -2

uint8_t speed_update_count;
struct event *speed_update;

Expand Down
2 changes: 1 addition & 1 deletion zebra/zebra_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ static void lib_interface_zebra_enabled_cli_write(struct vty *vty,

DEFPY_YANG (bandwidth_if,
bandwidth_if_cmd,
"[no] bandwidth ![(1-100000)]$bw",
"[no] bandwidth ![(1-1000000)]$bw",
NO_STR
"Set bandwidth informational parameter\n"
"Bandwidth in megabits\n")
Expand Down

0 comments on commit 3d57f04

Please sign in to comment.