From: Nicolò Date: Sun, 4 May 2025 15:19:50 +0000 (+0200) Subject: device: fix bonding primary port selection X-Git-Url: http://git.openwrt.org/?a=commitdiff_plain;h=a1b6386a20a6352fea626345a044b538c1473a49;p=project%2Fnetifd.git 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 Signed-off-by: Nicolò Veronese Link: https://github.com/openwrt/netifd/pull/49 Signed-off-by: Robert Marko --- diff --git a/bonding.c b/bonding.c index 3b25751..00a7b28 100644 --- a/bonding.c +++ b/bonding.c @@ -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; }