From b5a253896346849fdf515d0ed57fd3a2a9539753 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 15 Apr 2011 09:40:50 -0700 Subject: [PATCH] bridge: Properly test for out-of-range values. This code was trying to check for priorities greater than UINT16_MAX and reset them, but it assigned the value to a uint16_t before it checked it, which of course hid the problem. Fixes the following GCC warning: vswitchd/bridge.c:3034: warning: comparison is always false due to limited range of data type Reported-by: YAMAMOTO Takashi --- vswitchd/bridge.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c index ab4d5078..f5267156 100644 --- a/vswitchd/bridge.c +++ b/vswitchd/bridge.c @@ -3094,6 +3094,7 @@ port_reconfigure_lacp(struct port *port) { static struct lacp_settings s; struct iface *iface; + int priority; if (!enable_lacp(port, &s.active)) { lacp_destroy(port->lacp); @@ -3103,16 +3104,17 @@ port_reconfigure_lacp(struct port *port) s.name = port->name; memcpy(s.id, port->bridge->ea, ETH_ADDR_LEN); - s.priority = atoi(get_port_other_config(port->cfg, "lacp-system-priority", - "0")); + + /* Prefer bondable links if unspecified. */ + priority = atoi(get_port_other_config(port->cfg, "lacp-system-priority", + "0")); + s.priority = (priority > 0 && priority <= UINT16_MAX + ? priority + : UINT16_MAX - !list_is_short(&port->ifaces)); + s.fast = !strcmp(get_port_other_config(port->cfg, "lacp-time", "slow"), "fast"); - if (s.priority <= 0 || s.priority > UINT16_MAX) { - /* Prefer bondable links if unspecified. */ - s.priority = UINT16_MAX - !list_is_short(&port->ifaces); - } - if (!port->lacp) { port->lacp = lacp_create(); } -- 2.30.2