[[RFC] v2 09/14] Retrieve IP address of BMC

Message ID 20180118050517.2442-10-sam@mendozajonas.com
State New
Headers show
Series
  • [[RFC] v2 09/14] Retrieve IP address of BMC
Related show

Commit Message

Samuel Mendoza-Jonas Jan. 18, 2018, 5:05 a.m.
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
---
 discover/platform-powerpc.c   | 27 ++++++++++++++++++++++++++-
 lib/pb-protocol/pb-protocol.c |  7 +++++++
 lib/types/types.h             |  1 +
 ui/ncurses/nc-sysinfo.c       |  3 +++
 4 files changed, 37 insertions(+), 1 deletion(-)

Patch

diff --git a/discover/platform-powerpc.c b/discover/platform-powerpc.c
index 2478a00..df95e02 100644
--- a/discover/platform-powerpc.c
+++ b/discover/platform-powerpc.c
@@ -983,6 +983,29 @@  static int set_ipmi_os_boot_sensor(struct platform_powerpc *platform)
 	return 0;
 }
 
+static void get_ipmi_bmc_ip(struct platform *p, char **buf)
+{
+	struct platform_powerpc *platform = p->platform_data;
+	uint16_t resp_len = 8;
+	uint8_t resp[8];
+	uint8_t req[] = { 0x1, 0x3, 0x0, 0x0 };
+	int 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 IP resp [%d][%d]:\n", rc, resp_len);
+
+	if (rc == 0 && resp_len >= 6)
+		*buf = talloc_asprintf(platform, "%u.%u.%u.%u",
+				resp[2], resp[3], resp[4], resp[5]);
+
+	pb_log("BMC IP: %s\n", rc ? "unknown" : *buf);
+}
+
 static void get_ipmi_bmc_mac(struct platform *p, uint8_t *buf)
 {
 	struct platform_powerpc *platform = p->platform_data;
@@ -1317,8 +1340,10 @@  static int get_sysinfo(struct platform *p, struct system_info *sysinfo)
 	talloc_free(filename);
 
 	sysinfo->bmc_mac = talloc_zero_size(sysinfo, HWADDR_SIZE);
-	if (platform->ipmi)
+	if (platform->ipmi) {
 		get_ipmi_bmc_mac(p, sysinfo->bmc_mac);
+		get_ipmi_bmc_ip(p, &sysinfo->bmc_ip);
+	}
 
 	if (platform->ipmi)
 		get_ipmi_bmc_versions(p, sysinfo);
diff --git a/lib/pb-protocol/pb-protocol.c b/lib/pb-protocol/pb-protocol.c
index cf4ddb4..cd258a5 100644
--- a/lib/pb-protocol/pb-protocol.c
+++ b/lib/pb-protocol/pb-protocol.c
@@ -287,6 +287,8 @@  int pb_protocol_system_info_len(const struct system_info *sysinfo)
 	/* BMC MAC */
 	len += HWADDR_SIZE;
 
+	len += 4 + optional_strlen(sysinfo->bmc_ip);
+
 	return len;
 }
 
@@ -557,6 +559,8 @@  int pb_protocol_serialise_system_info(const struct system_info *sysinfo,
 		memset(pos, 0, HWADDR_SIZE);
 	pos += HWADDR_SIZE;
 
+	pos += pb_protocol_serialise_string(pos, sysinfo->bmc_ip);
+
 	*(bool *)pos = __cpu_to_be32(sysinfo->update_support);
 	pos += sizeof(bool);
 
@@ -1131,6 +1135,9 @@  int pb_protocol_deserialise_system_info(struct system_info *sysinfo,
 	pos += HWADDR_SIZE;
 	len -= HWADDR_SIZE;
 
+	if (read_string(sysinfo, &pos, &len, &sysinfo->bmc_ip))
+		goto out;
+
 	sysinfo->update_support = *(bool *)pos;
 	pos += sizeof(sysinfo->update_support);
 
diff --git a/lib/types/types.h b/lib/types/types.h
index 03dad2b..434dbb4 100644
--- a/lib/types/types.h
+++ b/lib/types/types.h
@@ -147,6 +147,7 @@  struct system_info {
 	unsigned int		n_bmc_current;
 	unsigned int		n_bmc_golden;
 	uint8_t			*bmc_mac;
+	char			*bmc_ip;
 	struct interface_info	**interfaces;
 	unsigned int		n_interfaces;
 	struct blockdev_info	**blockdevs;
diff --git a/ui/ncurses/nc-sysinfo.c b/ui/ncurses/nc-sysinfo.c
index 2d3ce82..c2bcf5b 100644
--- a/ui/ncurses/nc-sysinfo.c
+++ b/ui/ncurses/nc-sysinfo.c
@@ -120,6 +120,9 @@  static void sysinfo_screen_populate(struct sysinfo_screen *screen,
 		line(_(" MAC:  %s"), macbuf);
 	}
 
+	if (sysinfo->bmc_ip)
+		line(_(" IP:  %s"), sysinfo->bmc_ip);
+
 	if (sysinfo->n_interfaces) {
 		line(NULL);
 		line(_("Network interfaces"));