[1/2] discover: Avoid writing network overrides to NVRAM
diff mbox

Message ID 20160906042953.30304-1-sam@mendozajonas.com
State Accepted
Headers show

Commit Message

Samuel Mendoza-Jonas Sept. 6, 2016, 4:29 a.m. UTC
Explicitly keep track of whether the current interface config was set by
an IPMI network override, and avoid overwriting any saved config unless
the override was marked persistent.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
---
 discover/ipmi.c               | 1 +
 discover/platform-powerpc.c   | 9 +++++++++
 lib/pb-config/pb-config.c     | 1 +
 lib/pb-protocol/pb-protocol.c | 9 +++++++++
 lib/types/types.h             | 1 +
 5 files changed, 21 insertions(+)

Patch
diff mbox

diff --git a/discover/ipmi.c b/discover/ipmi.c
index 38423b2..2aaf114 100644
--- a/discover/ipmi.c
+++ b/discover/ipmi.c
@@ -309,6 +309,7 @@  int parse_ipmi_interface_override(struct config *config, uint8_t *buf,
 		i += ipsize;
 	}
 
+	ifconf->override = true;
 	pb_log("Applying IPMI network interface override\n");
 
 	/* Replace any existing interface config */
diff --git a/discover/platform-powerpc.c b/discover/platform-powerpc.c
index 8fca5bd..2b89121 100644
--- a/discover/platform-powerpc.c
+++ b/discover/platform-powerpc.c
@@ -635,6 +635,15 @@  static void update_network_config(struct platform_powerpc *platform,
 	unsigned int i;
 	char *val;
 
+	/*
+	 * Don't store IPMI overrides to NVRAM. If this was a persistent
+	 * override it was already stored in NVRAM by
+	 * get_ipmi_network_override()
+	 */
+	if (config->network.n_interfaces &&
+		config->network.interfaces[0]->override)
+		return;
+
 	val = talloc_strdup(platform, "");
 
 	for (i = 0; i < config->network.n_interfaces; i++) {
diff --git a/lib/pb-config/pb-config.c b/lib/pb-config/pb-config.c
index 52a43b1..581d70f 100644
--- a/lib/pb-config/pb-config.c
+++ b/lib/pb-config/pb-config.c
@@ -33,6 +33,7 @@  static struct interface_config *config_copy_interface(struct config *ctx,
 			talloc_strdup(dest, src->static_config.url);
 		break;
 	}
+	dest->override = src->override;
 
 	return dest;
 }
diff --git a/lib/pb-protocol/pb-protocol.c b/lib/pb-protocol/pb-protocol.c
index 1560ef7..706aec9 100644
--- a/lib/pb-protocol/pb-protocol.c
+++ b/lib/pb-protocol/pb-protocol.c
@@ -283,6 +283,8 @@  static int pb_protocol_interface_config_len(struct interface_config *conf)
 		len += 4 + optional_strlen(conf->static_config.url);
 	}
 
+	len += 4 /* conf->override */;
+
 	return len;
 }
 
@@ -511,6 +513,9 @@  static int pb_protocol_serialise_config_interface(char *buf,
 				conf->static_config.url);
 	}
 
+	*(uint32_t *)pos = conf->override;
+	pos += 4;
+
 	return pos - buf;
 }
 
@@ -1019,6 +1024,10 @@  static int pb_protocol_deserialise_config_interface(const char **buf,
 			return -1;
 	}
 
+	if (read_u32(buf, len, &tmp))
+		return -1;
+	iface->override = !!tmp;
+
 	return 0;
 }
 
diff --git a/lib/types/types.h b/lib/types/types.h
index 6b607cd..7b9269b 100644
--- a/lib/types/types.h
+++ b/lib/types/types.h
@@ -129,6 +129,7 @@  struct interface_config {
 			char *url;
 		} static_config;
 	};
+	bool	override;
 };
 
 struct network_config {