Post Reply 
 
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
get mac from ipxe in different format (no delimiter at all)
2013-05-04, 12:39 (This post was last modified: 2013-05-04 14:43 by Torgeir.)
Post: #1
get mac from ipxe in different format (no delimiter at all)
Hi!

I found myself in need of getting the mac from iPXE with no delimiter at all.
Sanboot with the MAC address (no delimited), in an embedded script within iPXE.

Usage:
Code:
iPXE> show mac
net0/mac:hex 00:aa:11:bb:22:cc

iPXE> show mac:hexhyp
net0/mac:hexhyp 00-aa-11-bb-22-cc

# hex no delimiter
iPXE> show mac:hexnd
net0/mac:hexnd 00aa11bb22cc

So I made myself a little patch for this (don't know if anyone else would ever need it...), but here it goes.

settings.c.patch
Code:
--- a/src/core/settings.c    2013-05-04 12:41:09.828764000 +0200
+++ b/src/core/settings.cc    2013-05-04 12:39:54.476391000 +0200
@@ -1770,6 +1770,20 @@
    return format_hex_setting ( raw, raw_len, buf, len, "-" );
}

+/**
+ * Format hex string setting value (using no delimiter)
+ *
+ * @v raw        Raw setting value
+ * @v raw_len        Length of raw setting value
+ * @v buf        Buffer to contain formatted value
+ * @v len        Length of buffer
+ * @ret len        Length of formatted value, or negative error
+ */
+static int format_hex_no_delimiter_setting ( const void *raw, size_t raw_len,
+                       char *buf, size_t len ) {
+    return format_hex_setting ( raw, raw_len, buf, len, "" );
+}
+
/** A hex-string setting (colon-delimited) */
struct setting_type setting_type_hex __setting_type = {
    .name = "hex",
@@ -1784,6 +1798,13 @@
    .format = format_hex_hyphen_setting,
};

+/** A hex-string setting (no delimiter) */
+struct setting_type setting_type_hex_no_delimiter __setting_type = {
+    .name = "hexnd",
+    .parse = parse_hex_setting,
+    .format = format_hex_no_delimiter_setting,
+};
+
/**
  * Parse UUID setting value
  *
settings.h.patch
Code:
--- a/src/ipxe/include/settings.h    2013-05-04 12:41:09.928765000 +0200
+++ b/src/ipxe/include/settings.hh    2013-05-04 12:39:21.272226000 +0200
@@ -322,6 +322,7 @@
extern struct setting_type setting_type_uint32 __setting_type;
extern struct setting_type setting_type_hex __setting_type;
extern struct setting_type setting_type_hexhyp __setting_type;
+extern struct setting_type setting_type_hex_no_delimiter __setting_type;
extern struct setting_type setting_type_uuid __setting_type;

extern struct setting ip_setting __setting ( SETTING_IPv4 );

Torgeir
Find all posts by this user
Quote this message in a reply
2013-05-04, 14:08
Post: #2
RE: get mac from ipxe in different format (no delimiter at all)
A Good idea!

Since it is still in hex, may I suggest something like "mac:hexnd" (Hex, No Delimiter) to keep the syntax consistent?

"Thus far, you have been adrift within the sheltered harbor of my patience..."
Find all posts by this user
Quote this message in a reply
2013-05-04, 14:44 (This post was last modified: 2013-05-04 14:46 by Torgeir.)
Post: #3
RE: get mac from ipxe in different format (no delimiter at all)
Couldn't agree more!
That does sound and look better Smile
Find all posts by this user
Quote this message in a reply
2013-05-04, 17:00
Post: #4
RE: get mac from ipxe in different format (no delimiter at all)
Torgeir: I'd suggest you post this patch on the mailing-list, or submit a pull request on the ipxe/ipxe github project. Then it should hopefully be noticed at some point.
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 3 Guest(s)