diff options
| author | Nicolò | 2025-05-04 15:19:50 +0000 |
|---|---|---|
| committer | Robert Marko | 2025-05-17 09:33:16 +0000 |
| commit | a1b6386a20a6352fea626345a044b538c1473a49 (patch) | |
| tree | 5c3440e3b9f234dbcb2fe68e9a05e9235d664566 | |
| parent | d610d68c71b82b987c665a922c10084d5cf89f8c (diff) | |
| download | netifd-a1b6386a20a6352fea626345a044b538c1473a49.tar.gz | |
device: fix bonding primary port selection
The confuguration of the primary port was read
but never used to properly configure the right port.
This patch fix this, and another small fix suggested
by nbd to properly handle the "reload" of the
primary interface when is changed.
Co-developed-by: Felix Fietkau <nbd@nbd.name>
Signed-off-by: Nicolò Veronese <nicveronese@gmail.com>
Link: https://github.com/openwrt/netifd/pull/49
Signed-off-by: Robert Marko <robimarko@gmail.com>
| -rw-r--r-- | bonding.c | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -35,6 +35,7 @@ struct bonding_device { struct blob_attr *config_data; bool has_macaddr; bool force_active; + bool reset_primary; bool active; }; @@ -322,6 +323,7 @@ bonding_create_port(struct bonding_device *bdev, const char *name, struct device *dev, bool hotplug) { struct bonding_port *bp; + struct bonding_config *cfg = &bdev->config; bp = calloc(1, sizeof(*bp) + strlen(name) + 1); if (!bp) @@ -332,6 +334,11 @@ bonding_create_port(struct bonding_device *bdev, const char *name, bp->dev.hotplug = hotplug; strcpy(bp->name, name); bp->dev.dev = dev; + + if (cfg->primary != NULL) { + bp->set_primary = strcmp(cfg->primary, name) == 0; + } + vlist_add(&bdev->ports, &bp->node, bp->name); /* * Need to look up the bonding port again as the above @@ -371,6 +378,11 @@ bonding_config_init(struct device *dev) } vlist_flush(&bdev->ports); + if (bdev->reset_primary) { + bonding_reset_primary(bdev); + bdev->reset_primary = false; + } + if (bdev->n_failed) uloop_timeout_set(&bdev->retry, 100); } @@ -588,11 +600,20 @@ bonding_port_update(struct vlist_tree *tree, struct vlist_node *node_new, { struct bonding_port *bp; struct device *dev; + struct bonding_device *bdev = container_of(tree, struct bonding_device, ports); if (node_new) { bp = container_of(node_new, struct bonding_port, node); if (node_old) { + struct bonding_port *bp_old; + + bp_old = container_of(node_old, struct bonding_port, node); + if (bp_old->set_primary != bp->set_primary) { + bp_old->set_primary = bp->set_primary; + bdev->reset_primary = true; + } + free(bp); return; } |