Add BMC interface MAC to system info output
authorJack Miller <jack@codezen.org>
Wed, 9 Dec 2015 18:03:24 +0000 (12:03 -0600)
committerJack Miller <jack@codezen.org>
Tue, 15 Dec 2015 18:33:48 +0000 (12:33 -0600)
Useful for identifying the initial BMC traffic on the network.

Signed-off-by: Jack Miller <jack@codezen.org>
discover/ipmi.h
discover/platform-powerpc.c
lib/pb-protocol/pb-protocol.c
lib/types/types.h
ui/ncurses/nc-sysinfo.c

index 3b11683c0cbdb7ce7fcd7641bfccc3abef89acfb..eb2a1831638ed9c8350db4b4b11e1789df3661f4 100644 (file)
@@ -9,12 +9,14 @@
 enum ipmi_netfn {
        IPMI_NETFN_CHASSIS      = 0x0,
        IPMI_NETFN_SE           = 0x04,
+       IPMI_NETFN_TRANSPORT    = 0x0c,
 };
 
 enum ipmi_cmd {
        IPMI_CMD_CHASSIS_SET_SYSTEM_BOOT_OPTIONS        = 0x08,
        IPMI_CMD_CHASSIS_GET_SYSTEM_BOOT_OPTIONS        = 0x09,
        IPMI_CMD_SENSOR_SET                             = 0x30,
+       IPMI_CMD_TRANSPORT_GET_LAN_PARAMS               = 0x02,
 };
 
 enum ipmi_sensor_ids {
index 23e63c1be152bdbf7e1b4bc0cd3e0e69c4f20eda..280793425198a483ecea8c1e4217b9844728d842 100644 (file)
@@ -989,6 +989,31 @@ static int set_ipmi_os_boot_sensor(struct platform_powerpc *platform)
        return 0;
 }
 
+static void get_ipmi_bmc_mac(struct platform *p, uint8_t *buf)
+{
+       struct platform_powerpc *platform = p->platform_data;
+       uint16_t resp_len = 8;
+       uint8_t resp[8];
+       uint8_t req[] = { 0x1, 0x5, 0x0, 0x0 };
+       int i, rc;
+
+       rc = ipmi_transaction(platform->ipmi, IPMI_NETFN_TRANSPORT,
+                       IPMI_CMD_TRANSPORT_GET_LAN_PARAMS,
+                       req, sizeof(req),
+                       resp, &resp_len,
+                       ipmi_timeout);
+
+       pb_debug("BMC MAC resp [%d][%d]:\n", rc, resp_len);
+
+       if (rc == 0 && resp_len > 0) {
+               for (i = 2; i < resp_len; i++) {
+                       pb_debug(" %x", resp[i]);
+                       buf[i - 2] = resp[i];
+               }
+               pb_debug("\n");
+       }
+}
+
 static int load_config(struct platform *p, struct config *config)
 {
        struct platform_powerpc *platform = to_platform_powerpc(p);
@@ -1057,6 +1082,10 @@ static int get_sysinfo(struct platform *p, struct system_info *sysinfo)
                sysinfo->identifier = talloc_steal(sysinfo, buf);
        talloc_free(filename);
 
+       sysinfo->bmc_mac = talloc_zero_size(sysinfo, HWADDR_SIZE);
+       if (platform->ipmi)
+               get_ipmi_bmc_mac(p, sysinfo->bmc_mac);
+
        return 0;
 }
 
@@ -1085,7 +1114,6 @@ static bool probe(struct platform *p, void *ctx)
                platform->get_ipmi_bootdev = get_ipmi_bootdev_ipmi;
                platform->clear_ipmi_bootdev = clear_ipmi_bootdev_ipmi;
                platform->set_os_boot_sensor = set_ipmi_os_boot_sensor;
-
        } else if (!stat(sysparams_dir, &statbuf)) {
                pb_debug("platform: using sysparams for IPMI paramters\n");
                platform->get_ipmi_bootdev = get_ipmi_bootdev_sysparams;
index 7d45f512b0dcb81db6b83ba6223e6eb921dde30f..ab5ea8a376e1500895ba047b3e656e8ac114fd59 100644 (file)
@@ -239,6 +239,9 @@ int pb_protocol_system_info_len(const struct system_info *sysinfo)
                        4 + optional_strlen(bd_info->mountpoint);
        }
 
+       /* BMC MAC */
+       len += HWADDR_SIZE;
+
        return len;
 }
 
@@ -420,6 +423,9 @@ int pb_protocol_serialise_system_info(const struct system_info *sysinfo,
                pos += pb_protocol_serialise_string(pos, bd_info->mountpoint);
        }
 
+       memcpy(pos, sysinfo->bmc_mac, HWADDR_SIZE);
+       pos += HWADDR_SIZE;
+
        assert(pos <= buf + buf_len);
        (void)buf_len;
 
@@ -850,8 +856,18 @@ int pb_protocol_deserialise_system_info(struct system_info *sysinfo,
 
                sysinfo->blockdevs[i] = bd_info;
        }
-       rc = 0;
 
+       for (i = 0; i < HWADDR_SIZE; i++) {
+               if (pos[i] != 0) {
+                       sysinfo->bmc_mac = talloc_memdup(sysinfo, pos, HWADDR_SIZE);
+                       break;
+               }
+       }
+
+       pos += HWADDR_SIZE;
+       len -= HWADDR_SIZE;
+
+       rc = 0;
 out:
        return rc;
 }
index 6a2c25810fff5c80a07ad2f11af44924b225f469..702b6f5f82286605cc00303f11cb2f84d4610150 100644 (file)
@@ -93,6 +93,7 @@ struct blockdev_info {
 struct system_info {
        char                    *type;
        char                    *identifier;
+       uint8_t                 *bmc_mac;
        struct interface_info   **interfaces;
        unsigned int            n_interfaces;
        struct blockdev_info    **blockdevs;
index ac8ece785f6533a3708233de608c6652941e1cde..5ced871127b33a2ea01391a07a04e892a5af9e75 100644 (file)
@@ -51,6 +51,7 @@ static void if_info_mac_str(struct interface_info *info,
 static void sysinfo_screen_populate(struct sysinfo_screen *screen,
                const struct system_info *sysinfo)
 {
+       char macbuf[32];
        unsigned int i;
 
        text_screen_clear(&screen->text_scr);
@@ -78,6 +79,12 @@ static void sysinfo_screen_populate(struct sysinfo_screen *screen,
                line(NULL);
        }
 
+       if (sysinfo->bmc_mac) {
+               mac_str(sysinfo->bmc_mac, HWADDR_SIZE, macbuf, sizeof(macbuf));
+               line(_("Management (BMC) interface"));
+               line(_(" MAC:  %s"), macbuf);
+       }
+
        if (sysinfo->n_interfaces) {
                line(NULL);
                line(_("Network interfaces"));
@@ -85,7 +92,6 @@ static void sysinfo_screen_populate(struct sysinfo_screen *screen,
 
        for (i = 0; i < sysinfo->n_interfaces; i++) {
                struct interface_info *info = sysinfo->interfaces[i];
-               char macbuf[32];
 
                if_info_mac_str(info, macbuf, sizeof(macbuf));