#define LACP_RX_MULTIPLIER 3 /* Multiply by TX rate to get RX rate. */
#define LACP_INFO_LEN 15
+OVS_PACKED(
struct lacp_info {
ovs_be16 sys_priority; /* System priority. */
uint8_t sys_id[ETH_ADDR_LEN]; /* System ID. */
ovs_be16 port_priority; /* Port priority. */
ovs_be16 port_id; /* Port ID. */
uint8_t state; /* State mask. See LACP_STATE macros. */
-} __attribute__((packed));
+});
BUILD_ASSERT_DECL(LACP_INFO_LEN == sizeof(struct lacp_info));
#define LACP_PDU_LEN 110
+OVS_PACKED(
struct lacp_pdu {
uint8_t subtype; /* Always 1. */
uint8_t version; /* Always 1. */
uint8_t collector_len; /* Always 16. */
ovs_be16 collector_delay; /* Maximum collector delay. Set to UINT16_MAX. */
uint8_t z3[64]; /* Combination of several fields. Always 0. */
-} __attribute__((packed));
+});
BUILD_ASSERT_DECL(LACP_PDU_LEN == sizeof(struct lacp_pdu));
\f
/* Implementation. */
bool fast; /* True if using fast probe interval. */
bool negotiated; /* True if LACP negotiations were successful. */
bool update; /* True if lacp_update() needs to be called. */
+
+ int ref_cnt;
};
struct slave {
lacp = xzalloc(sizeof *lacp);
hmap_init(&lacp->slaves);
list_push_back(&all_lacps, &lacp->node);
+ lacp->ref_cnt = 1;
+ return lacp;
+}
+
+struct lacp *
+lacp_ref(const struct lacp *lacp_)
+{
+ struct lacp *lacp = CONST_CAST(struct lacp *, lacp_);
+ if (lacp) {
+ ovs_assert(lacp->ref_cnt > 0);
+ lacp->ref_cnt++;
+ }
return lacp;
}
/* Destroys 'lacp' and its slaves. Does nothing if 'lacp' is NULL. */
void
-lacp_destroy(struct lacp *lacp)
+lacp_unref(struct lacp *lacp)
{
- if (lacp) {
+ if (!lacp) {
+ return;
+ }
+
+ ovs_assert(lacp->ref_cnt > 0);
+ if (!--lacp->ref_cnt) {
struct slave *slave, *next;
HMAP_FOR_EACH_SAFE (slave, next, node, &lacp->slaves) {
const struct lacp_pdu *pdu;
long long int tx_rate;
+ if (!slave) {
+ return;
+ }
+
pdu = parse_lacp_packet(packet);
if (!pdu) {
VLOG_WARN_RL(&rl, "%s: received an unparsable LACP PDU.", lacp->name);
if (lacp) {
struct slave *slave = slave_lookup(lacp, slave_);
+ if (!slave) {
+ return;
+ }
+
if (slave->status == LACP_CURRENT || slave->lacp->active) {
slave_set_expired(slave);
}
lacp_slave_may_enable(const struct lacp *lacp, const void *slave_)
{
if (lacp) {
- return slave_may_enable__(slave_lookup(lacp, slave_));
+ struct slave *slave = slave_lookup(lacp, slave_);
+ return slave ? slave_may_enable__(slave) : false;
} else {
return true;
}
bool
lacp_slave_is_current(const struct lacp *lacp, const void *slave_)
{
- return slave_lookup(lacp, slave_)->status != LACP_DEFAULTED;
+ struct slave *slave = slave_lookup(lacp, slave_);
+ return slave ? slave->status != LACP_DEFAULTED : false;
}
/* This function should be called periodically to update 'lacp'. */