struct lldpd_hardware *hw;
LIST_FOR_EACH (hw, h_entries, &cfg->g_hardware.h_entries) {
- if ((strcmp(hw->h_ifname, name) == 0) &&
- (hw->h_ifindex == index) &&
- ((!ops) || (ops == hw->h_ops))) {
+ if (!strcmp(hw->h_ifname, name) && hw->h_ifindex == index
+ && (!ops || ops == hw->h_ops)) {
return hw;
}
}
hw->h_cfg = cfg;
ovs_strlcpy(hw->h_ifname, name, sizeof hw->h_ifname);
hw->h_ifindex = index;
- hw->h_lport.p_chassis = (struct lldpd_chassis *)
- list_front(&cfg->g_chassis.list);
+ hw->h_lport.p_chassis = CONTAINER_OF(list_front(&cfg->g_chassis.list),
+ struct lldpd_chassis, list);
hw->h_lport.p_chassis->c_refcount++;
- list_init(&hw->h_rports.p_entries);
+ list_init(&hw->h_rports);
return hw;
}
* marshaling.
*/
memcpy(ochassis, chassis, sizeof *ochassis);
- list_init(&ochassis->c_mgmt.m_entries);
+ list_init(&ochassis->c_mgmt);
/* Copy of management addresses */
- LIST_FOR_EACH_SAFE (mgmt,
- mgmt_next,
- m_entries,
- &chassis->c_mgmt.m_entries) {
+ LIST_FOR_EACH_SAFE (mgmt, mgmt_next, m_entries, &chassis->c_mgmt) {
list_remove(&mgmt->m_entries);
- list_insert(&ochassis->c_mgmt.m_entries, &mgmt->m_entries);
+ list_insert(&ochassis->c_mgmt, &mgmt->m_entries);
}
/* Restore saved values */
s -= 4;
}
- LIST_FOR_EACH (oport, p_entries, &hw->h_rports.p_entries) {
- if ((oport->p_lastframe != NULL) &&
- (oport->p_lastframe->size == s) &&
- (memcmp(oport->p_lastframe->frame, frame, s) == 0)) {
+ LIST_FOR_EACH (oport, p_entries, &hw->h_rports) {
+ if (oport->p_lastframe &&
+ oport->p_lastframe->size == s &&
+ !memcmp(oport->p_lastframe->frame, frame, s)) {
/* Already received the same frame */
VLOG_DBG("duplicate frame, no need to decode");
oport->p_lastupdate = time_now();
/* Do we already have the same MSAP somewhere? */
VLOG_DBG("search for the same MSAP");
- LIST_FOR_EACH (oport, p_entries, &hw->h_rports.p_entries) {
+ LIST_FOR_EACH (oport, p_entries, &hw->h_rports) {
if (port->p_protocol == oport->p_protocol) {
count++;
- if ((port->p_id_subtype == oport->p_id_subtype) &&
- (port->p_id_len == oport->p_id_len) &&
- (memcmp(port->p_id, oport->p_id, port->p_id_len) == 0) &&
- (chassis->c_id_subtype == oport->p_chassis->c_id_subtype) &&
- (chassis->c_id_len == oport->p_chassis->c_id_len) &&
- (memcmp(chassis->c_id, oport->p_chassis->c_id,
- chassis->c_id_len) == 0)) {
+ if (port->p_id_subtype == oport->p_id_subtype &&
+ port->p_id_len == oport->p_id_len &&
+ !memcmp(port->p_id, oport->p_id, port->p_id_len) &&
+ chassis->c_id_subtype == oport->p_chassis->c_id_subtype &&
+ chassis->c_id_len == oport->p_chassis->c_id_len &&
+ !memcmp(chassis->c_id, oport->p_chassis->c_id,
+ chassis->c_id_len)) {
ochassis = oport->p_chassis;
VLOG_DBG("MSAP is already known");
found = true;
port->p_lastframe = xmalloc(s + sizeof(struct lldpd_frame));
port->p_lastframe->size = s;
memcpy(port->p_lastframe->frame, frame, s);
- list_insert(&hw->h_rports.p_entries, &port->p_entries);
+ list_insert(&hw->h_rports, &port->p_entries);
port->p_chassis = chassis;
port->p_chassis->c_refcount++;
* freed with lldpd_port_cleanup() and therefore, the refcount
* of the chassis that was attached to it is decreased.
*/
- /* coverity[use_after_free] TAILQ_REMOVE does the right thing */
- i = list_size((struct ovs_list *) &hw->h_rports);
+ i = list_size(&hw->h_rports);
VLOG_DBG("%"PRIuSIZE " neighbors for %s", i, hw->h_ifname);
if (!oport) {
protocols[i] = 0;
}
- LIST_FOR_EACH (port, p_entries, &hw->h_rports.p_entries) {
+ LIST_FOR_EACH (port, p_entries, &hw->h_rports) {
protocols[port->p_protocol]++;
}
}
}
for (i = 0; i <= LLDPD_MODE_MAX; i++) {
- if ((protocols[i] == min) && !found) {
+ if (protocols[i] == min && !found) {
/* If we need a tie breaker, we take the first protocol only */
if (cfg->g_config.c_smart & mask &
(SMART_OUTGOING_ONE_PROTO | SMART_INCOMING_ONE_PROTO)) {
}
/* We set the p_hidden flag to 1 if the protocol is disabled */
- LIST_FOR_EACH (port, p_entries, &hw->h_rports.p_entries) {
+ LIST_FOR_EACH (port, p_entries, &hw->h_rports) {
if (mask == SMART_OUTGOING) {
port->p_hidden_out = protocols[port->p_protocol] ? false : true;
} else {
(SMART_OUTGOING_ONE_NEIGH | SMART_INCOMING_ONE_NEIGH)) {
found = false;
- LIST_FOR_EACH (port, p_entries, &hw->h_rports.p_entries) {
+ LIST_FOR_EACH (port, p_entries, &hw->h_rports) {
if (mask == SMART_OUTGOING) {
if (found) {
port->p_hidden_out = true;
}
k = j = 0;
- LIST_FOR_EACH (port, p_entries, &hw->h_rports.p_entries) {
- if (!(((mask == SMART_OUTGOING) && port->p_hidden_out) ||
- ((mask == SMART_INCOMING) && port->p_hidden_in))) {
+ LIST_FOR_EACH (port, p_entries, &hw->h_rports) {
+ if (!((mask == SMART_OUTGOING && port->p_hidden_out) ||
+ (mask == SMART_INCOMING && port->p_hidden_in))) {
k++;
protocols[port->p_protocol] = 1;
}
/* We send only if we have at least one remote system
* speaking this protocol or if the protocol is forced */
if (cfg->g_protocols[i].enabled > 1) {
- if ((lldp_size = cfg->g_protocols[i].send(cfg, hw, p)) != E2BIG) {
+ if ((lldp_size = cfg->g_protocols[i].send(cfg, hw, p)) != -E2BIG) {
sent++;
continue;
} else {
}
}
- LIST_FOR_EACH (port, p_entries, &hw->h_rports.p_entries) {
+ LIST_FOR_EACH (port, p_entries, &hw->h_rports) {
/* If this remote port is disabled, we don't consider it */
if (port->p_hidden_out) {
continue;