This makes it easier to pass configuration between modules.
-/* Configures 'lacp' with the given 'name', 'sys_id', 'sys_priority', and
- * 'active' parameters. */
+/* Configures 'lacp' with settings from 's'. */
-lacp_configure(struct lacp *lacp, const char *name,
- const uint8_t sys_id[ETH_ADDR_LEN], uint16_t sys_priority,
- bool active, bool fast)
+lacp_configure(struct lacp *lacp, const struct lacp_settings *s)
- if (!lacp->name || strcmp(name, lacp->name)) {
+ if (!lacp->name || strcmp(s->name, lacp->name)) {
- lacp->name = xstrdup(name);
+ lacp->name = xstrdup(s->name);
- memcpy(lacp->sys_id, sys_id, ETH_ADDR_LEN);
- lacp->sys_priority = sys_priority;
- lacp->active = active;
- lacp->fast = fast;
+ memcpy(lacp->sys_id, s->id, ETH_ADDR_LEN);
+ lacp->sys_priority = s->priority;
+ lacp->active = s->active;
+ lacp->fast = s->fast;
}
/* Returns true if 'lacp' is configured in active mode, false if 'lacp' is
}
/* Returns true if 'lacp' is configured in active mode, false if 'lacp' is
/* Registers 'slave_' as subordinate to 'lacp'. This should be called at least
* once per slave in a LACP managed bond. Should also be called whenever a
/* Registers 'slave_' as subordinate to 'lacp'. This should be called at least
* once per slave in a LACP managed bond. Should also be called whenever a
- * slave's name, port_id, or port_priority change. */
+ * slave's settings change. */
-lacp_slave_register(struct lacp *lacp, void *slave_, const char *name,
- uint16_t port_id, uint16_t port_priority)
+lacp_slave_register(struct lacp *lacp, void *slave_,
+ const struct lacp_slave_settings *s)
{
struct slave *slave = slave_lookup(lacp, slave_);
{
struct slave *slave = slave_lookup(lacp, slave_);
- if (!slave->name || strcmp(name, slave->name)) {
+ if (!slave->name || strcmp(s->name, slave->name)) {
- slave->name = xstrdup(name);
+ slave->name = xstrdup(s->name);
- if (slave->port_id != port_id || slave->port_priority != port_priority) {
-
- slave->port_id = port_id;
- slave->port_priority = port_priority;
+ if (slave->port_id != s->id || slave->port_priority != s->priority) {
+ slave->port_id = s->id;
+ slave->port_priority = s->priority;
#include <stdint.h>
#include "packets.h"
#include <stdint.h>
#include "packets.h"
-/* Function called when a LACP PDU is ready to be sent out the given slave */
-typedef void lacp_send_pdu(void *slave, const struct lacp_pdu *);
+struct lacp_settings {
+ char *name;
+ uint8_t id[ETH_ADDR_LEN];
+ uint16_t priority;
+ bool active;
+ bool fast;
+};
void lacp_init(void);
struct lacp *lacp_create(void);
void lacp_destroy(struct lacp *);
void lacp_init(void);
struct lacp *lacp_create(void);
void lacp_destroy(struct lacp *);
-void lacp_configure(struct lacp *, const char *name,
- const uint8_t sys_id[ETH_ADDR_LEN],
- uint16_t sys_priority, bool active, bool fast);
+void lacp_configure(struct lacp *, const struct lacp_settings *);
bool lacp_is_active(const struct lacp *);
void lacp_process_pdu(struct lacp *, const void *slave,
const struct lacp_pdu *);
bool lacp_negotiated(const struct lacp *);
bool lacp_is_active(const struct lacp *);
void lacp_process_pdu(struct lacp *, const void *slave,
const struct lacp_pdu *);
bool lacp_negotiated(const struct lacp *);
-void lacp_slave_register(struct lacp *, void *slave_, const char *name,
- uint16_t port_id, uint16_t port_priority);
+struct lacp_slave_settings {
+ char *name;
+ uint16_t id;
+ uint16_t priority;
+};
+
+void lacp_slave_register(struct lacp *, void *slave_,
+ const struct lacp_slave_settings *);
void lacp_slave_unregister(struct lacp *, const void *slave);
void lacp_slave_enable(struct lacp *lacp, void *slave_, bool enabled);
void lacp_slave_carrier_changed(const struct lacp *, const void *slave);
bool lacp_slave_may_enable(const struct lacp *, const void *slave);
void lacp_slave_unregister(struct lacp *, const void *slave);
void lacp_slave_enable(struct lacp *lacp, void *slave_, bool enabled);
void lacp_slave_carrier_changed(const struct lacp *, const void *slave);
bool lacp_slave_may_enable(const struct lacp *, const void *slave);
+/* Callback function for lacp_run() for sending a LACP PDU. */
+typedef void lacp_send_pdu(void *slave, const struct lacp_pdu *);
+
void lacp_run(struct lacp *, lacp_send_pdu *);
void lacp_wait(struct lacp *);
void lacp_run(struct lacp *, lacp_send_pdu *);
void lacp_wait(struct lacp *);
+static void
+iface_update_lacp(struct iface *iface)
+{
+ struct lacp_slave_settings s;
+ int priority;
+
+ s.name = iface->name;
+ s.id = iface->dp_ifidx;
+ priority = atoi(get_interface_other_config(
+ iface->cfg, "lacp-port-priority", "0"));
+ s.priority = (priority >= 0 && priority <= UINT16_MAX ? priority
+ : UINT16_MAX);
+
+ lacp_slave_register(iface->port->lacp, iface, &s);
+}
+
static void
port_update_lacp(struct port *port)
{
static void
port_update_lacp(struct port *port)
{
+ struct lacp_settings s;
- int priority;
- bool active;
- bool fast;
- if (!enable_lacp(port, &active)) {
+ if (!enable_lacp(port, &s.active)) {
lacp_destroy(port->lacp);
port->lacp = NULL;
return;
lacp_destroy(port->lacp);
port->lacp = NULL;
return;
port->lacp = lacp_create();
}
port->lacp = lacp_create();
}
- fast = !strcmp(get_port_other_config(port->cfg, "lacp-time", "slow"),
- "fast");
-
- priority = atoi(get_port_other_config(port->cfg, "lacp-system-priority",
+ 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",
- if (priority <= 0 || priority > UINT16_MAX) {
+ 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. */
/* Prefer bondable links if unspecified. */
- priority = UINT16_MAX - (port->n_ifaces > 1);
+ s.priority = UINT16_MAX - (port->n_ifaces > 1);
- lacp_configure(port->lacp, port->name, port->bridge->ea, priority,
- active, fast);
-
+ lacp_configure(port->lacp, &s);
LIST_FOR_EACH (iface, port_elem, &port->ifaces) {
LIST_FOR_EACH (iface, port_elem, &port->ifaces) {
- priority = atoi(get_interface_other_config(
- iface->cfg, "lacp-port-priority", "0"));
- if (priority <= 0 || priority > UINT16_MAX) {
- priority = UINT16_MAX;
- }
-
- lacp_slave_register(port->lacp, iface, iface->name,
- iface->dp_ifidx, priority);
+ iface_update_lacp(iface);