[netcf-devel] [PATCH 2/2] Implement MAC lookup using normalize_if
Jonas Eriksson
jonas.j.eriksson at ericsson.com
Wed Aug 5 07:37:50 UTC 2009
src/drv_initscripts.c: Run interface name and mac through normalize_if
and generate a new augeas path with the new interface name.
---
src/drv_initscripts.c | 31 ++++++++++++++++++++++++++++---
1 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/src/drv_initscripts.c b/src/drv_initscripts.c
index 550df65..3c61212 100644
--- a/src/drv_initscripts.c
+++ b/src/drv_initscripts.c
@@ -435,6 +435,7 @@ static xmlDocPtr aug_get_xml(struct netcf *ncf, int nint, char **intf) {
static int aug_put_xml(struct netcf *ncf, xmlDocPtr xml) {
xmlNodePtr forest;
char *path = NULL, *lpath = NULL, *label = NULL, *value = NULL;
+ char *name, *mac = NULL, *npath = NULL;
struct augeas *aug = NULL;
int result = -1;
int r;
@@ -451,11 +452,31 @@ static int aug_put_xml(struct netcf *ncf, xmlDocPtr xml) {
ERR_THROW(! xmlStrEqual(tree->name, BAD_CAST "tree"), ncf,
EINTERNAL, "expected node labeled 'tree', not '%s'",
tree->name);
+
+ /* Find HWADDR */
+ list_for_each(node, tree->children) {
+ label = xml_prop(node, "label");
+ value = xml_prop(node, "value");
+ if (STREQ(label, "HWADDR") && mac == NULL) {
+ mac = strdup(value);
+ ERR_COND_BAIL(mac == NULL, ncf, ENOMEM);
+ }
+ xmlFree(label);
+ xmlFree(value);
+ }
+
path = xml_prop(tree, "path");
+ name = normalize_if(ncf, &path[strlen(ifcfg_path) + 5], mac);
+ ERR_BAIL(ncf);
+
+ r = xasprintf(&npath, "/files/etc/sysconfig/network-scripts/ifcfg-%s",
+ name);
+ ERR_COND_BAIL(r < 0, ncf, ENOMEM);
+
int toplevel = 1;
/* This is a little drastic, since it clears out the file entirely */
- r = aug_rm(aug, path);
- ERR_THROW(r < 0, ncf, EINTERNAL, "aug_rm of '%s' failed", path);
+ r = aug_rm(aug, npath);
+ ERR_THROW(r < 0, ncf, EINTERNAL, "aug_rm of '%s' failed", npath);
list_for_each(node, tree->children) {
label = xml_prop(node, "label");
value = xml_prop(node, "value");
@@ -463,7 +484,7 @@ static int aug_put_xml(struct netcf *ncf, xmlDocPtr xml) {
if (STREQ(label, "BRIDGE") || STREQ(label, "MASTER")) {
toplevel = 0;
}
- r = xasprintf(&lpath, "%s/%s", path, label);
+ r = xasprintf(&lpath, "%s/%s", npath, label);
ERR_THROW(r < 0, ncf, ENOMEM, NULL);
r = aug_set(aug, lpath, value);
@@ -475,6 +496,8 @@ static int aug_put_xml(struct netcf *ncf, xmlDocPtr xml) {
label = value = NULL;
}
xmlFree(path);
+ FREE(npath);
+ FREE(mac);
path = NULL;
}
result = 0;
@@ -483,6 +506,8 @@ static int aug_put_xml(struct netcf *ncf, xmlDocPtr xml) {
xmlFree(value);
xmlFree(path);
FREE(lpath);
+ FREE(mac);
+ FREE(npath);
return result;
}
--
1.6.2
More information about the netcf-devel
mailing list