diff mbox series

[netifd] device: restore cleared flags on device down

Message ID 20230712213934.586291-1-erik.r.karlsson@gmail.com
State New
Headers show
Series [netifd] device: restore cleared flags on device down | expand

Commit Message

Erik Karlsson July 12, 2023, 9:39 p.m. UTC
From: Erik Karlsson <erik.karlsson@genexis.eu>

In case flags have been cleared because settings failed to apply,
restore them when the device is brought down so that they will be
re-attempted the next time the device is brought up.

Signed-off-by: Erik Karlsson <erik.karlsson@genexis.eu>
---
 device.c | 9 +++++++++
 1 file changed, 9 insertions(+)
diff mbox series

Patch

diff --git a/device.c b/device.c
index 92c814c..720b504 100644
--- a/device.c
+++ b/device.c
@@ -159,6 +159,11 @@  static int set_device_state(struct device *dev, bool state)
 	} else {
 		system_if_down(dev);
 		system_if_apply_settings(dev, &dev->orig_settings, dev->orig_settings.flags);
+
+		/* Restore any settings present in UCI which may have
+		 * failed to apply so that they will be re-attempted
+		 * the next time the device is brought up */
+		dev->settings.flags |= dev->settings.valid_flags;
 	}
 
 	return 0;
@@ -505,6 +510,10 @@  device_init_settings(struct device *dev, struct blob_attr **tb)
 		s->duplex = blobmsg_get_bool(cur);
 		s->flags |= DEV_OPT_DUPLEX;
 	}
+
+	/* Remember the settings present in UCI */
+	s->valid_flags = s->flags;
+
 	device_set_extra_vlans(dev, tb[DEV_ATTR_VLAN]);
 	device_set_disabled(dev, disabled);
 }