]> git.ozlabs.org Git - yaboot.git/commitdiff
This part creates the cfg_set_default_by_mac() function.
authorPaul Nasrat <pnasrat@redhat.com>
Tue, 15 May 2007 13:25:55 +0000 (14:25 +0100)
committerPaul Nasrat <pauln@enki.eridu>
Tue, 15 May 2007 13:25:55 +0000 (14:25 +0100)
This function sets the default cf_option if there is an image label if
the same MAC address of the machine is netbooting.

Signed-off-by: Paulo Ricardo Paz Vital <vital@br.ibm.com>
include/cfg.h
second/cfg.c

index be34e0faa67c5f18e1e467610dacf94f3fbccfb2..1053f9ac8fb4a54eb37801ef9e503af316ed449a 100644 (file)
@@ -28,5 +28,6 @@ extern char*  cfg_get_strg(char *image, char *item);
 extern int     cfg_get_flag(char *image, char *item);
 extern void    cfg_print_images(void);
 extern char*   cfg_get_default(void);
+extern char*    cfg_set_default_by_mac(char *mac_addr);
 
 #endif
index d7f4084abb6b8e0d2e716873fda7510760f82ed2..fe3f1e1b40d8c78ed4d8d396d42792582ff63904 100644 (file)
@@ -585,6 +585,43 @@ char *cfg_get_default (void)
      return ret;
 }
 
+/*
+ * cfg_set_default_by_mac ()
+ * return 1 if the default cf_option was changed to label with the MAC addr
+ * return 0 if not changed
+ */
+int cfg_set_default_by_mac (char *mac_addr)
+{
+     CONFIG *walk;
+     struct IMAGES *tmp;
+     char * label = NULL;
+     int haslabel = 0;
+
+     /* check if there is an image label equal to mac_addr */
+     for (tmp = images; tmp; tmp = tmp->next) {
+        label = cfg_get_strg_i (tmp->table, "label");
+        if (!strcmp(label,mac_addr)){
+            haslabel = 1;
+        }
+     }
+
+     if (!haslabel)
+         return 0;
+     else {
+         /*
+          * if there is an image label equal to mac_addr, change the default
+          * cf_options to this image label
+          */
+         for (walk = cf_options; walk->type != cft_end; walk++) {
+             if (!strcasecmp(walk->name,"default")) {
+                 walk->data = mac_addr;
+                 return 1;
+             }
+         }
+         return 0;
+     }
+}
+
 /*
  * Local variables:
  * c-file-style: "k&r"