From b397a330e244a94019dd88d5c98b805568cf5a8a Mon Sep 17 00:00:00 2001 From: Peter Delevoryas Date: Wed, 1 Dec 2021 23:54:04 -0800 Subject: slirp: Add manufacturer's ID The manufacturer's ID is used in NC-SI commands such as "Get Version ID" [1]. It is also essential to providing a path towards adding OEM (non-standardized) NC-SI commands. This field should be derived from the IANA Private Enterprise Numbers list, per the NC-SI specification. It may be useful for things besides NC-SI, but NC-SI responses for BMC's in QEMU are the main use case I have in mind. Note: I did not add this attribute to slirp_init, since it is deprecated. [1] https://www.dmtf.org/sites/default/files/standards/documents/DSP0222_1.0.0.pdf [2] https://www.iana.org/assignments/enterprise-numbers/enterprise-numbers Signed-off-by: Peter Delevoryas --- src/libslirp.h | 6 +++++- src/slirp.c | 6 ++++++ src/slirp.h | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/libslirp.h b/src/libslirp.h index 77396f0..35ddab6 100644 --- a/src/libslirp.h +++ b/src/libslirp.h @@ -90,7 +90,7 @@ typedef struct SlirpCb { } SlirpCb; #define SLIRP_CONFIG_VERSION_MIN 1 -#define SLIRP_CONFIG_VERSION_MAX 4 +#define SLIRP_CONFIG_VERSION_MAX 5 typedef struct SlirpConfig { /* Version must be provided */ @@ -140,6 +140,10 @@ typedef struct SlirpConfig { * Fields introduced in SlirpConfig version 4 begin */ bool disable_dhcp; /* slirp will not reply to any DHCP requests */ + /* + * Fields introduced in SlirpConfig version 5 begin + */ + uint32_t mfr_id; /* Manufacturer ID (IANA Private Enterprise number) */ } SlirpConfig; /* Create a new instance of a slirp stack */ diff --git a/src/slirp.c b/src/slirp.c index 04bce41..588cada 100644 --- a/src/slirp.c +++ b/src/slirp.c @@ -648,6 +648,12 @@ Slirp *slirp_new(const SlirpConfig *cfg, const SlirpCb *callbacks, void *opaque) slirp->cb->init_completed(slirp, slirp->opaque); } + if (cfg->version >= 5) { + slirp->mfr_id = cfg->mfr_id; + } else { + slirp->mfr_id = 0; + } + ip6_post_init(slirp); return slirp; } diff --git a/src/slirp.h b/src/slirp.h index 35c2be3..a61ea15 100644 --- a/src/slirp.h +++ b/src/slirp.h @@ -151,6 +151,8 @@ struct Slirp { bool disable_host_loopback; + uint32_t mfr_id; + /* mbuf states */ struct slirp_quehead m_freelist; struct slirp_quehead m_usedlist; -- cgit v1.1 From 5025b871c36fd5b9daf3085f0a8c73d7d34c692d Mon Sep 17 00:00:00 2001 From: Peter Delevoryas Date: Thu, 2 Dec 2021 21:13:39 -0800 Subject: ncsi: Pass Slirp structure to response handlers This will let us use Slirp fields to generate more interesting NC-SI responses. Signed-off-by: Peter Delevoryas --- src/ncsi.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ncsi.c b/src/ncsi.c index f3427bd..e556193 100644 --- a/src/ncsi.c +++ b/src/ncsi.c @@ -56,7 +56,7 @@ static uint32_t ncsi_calculate_checksum(uint8_t *data, int len) } /* Get Capabilities */ -static int ncsi_rsp_handler_gc(struct ncsi_rsp_pkt_hdr *rnh) +static int ncsi_rsp_handler_gc(Slirp *slirp, struct ncsi_rsp_pkt_hdr *rnh) { struct ncsi_rsp_gc_pkt *rsp = (struct ncsi_rsp_gc_pkt *)rnh; @@ -71,7 +71,7 @@ static int ncsi_rsp_handler_gc(struct ncsi_rsp_pkt_hdr *rnh) } /* Get Link status */ -static int ncsi_rsp_handler_gls(struct ncsi_rsp_pkt_hdr *rnh) +static int ncsi_rsp_handler_gls(Slirp *slirp, struct ncsi_rsp_pkt_hdr *rnh) { struct ncsi_rsp_gls_pkt *rsp = (struct ncsi_rsp_gls_pkt *)rnh; @@ -80,7 +80,7 @@ static int ncsi_rsp_handler_gls(struct ncsi_rsp_pkt_hdr *rnh) } /* Get Parameters */ -static int ncsi_rsp_handler_gp(struct ncsi_rsp_pkt_hdr *rnh) +static int ncsi_rsp_handler_gp(Slirp *slirp, struct ncsi_rsp_pkt_hdr *rnh) { struct ncsi_rsp_gp_pkt *rsp = (struct ncsi_rsp_gp_pkt *)rnh; @@ -96,7 +96,7 @@ static int ncsi_rsp_handler_gp(struct ncsi_rsp_pkt_hdr *rnh) static const struct ncsi_rsp_handler { unsigned char type; int payload; - int (*handler)(struct ncsi_rsp_pkt_hdr *rnh); + int (*handler)(Slirp *slirp, struct ncsi_rsp_pkt_hdr *rnh); } ncsi_rsp_handlers[] = { { NCSI_PKT_RSP_CIS, 4, NULL }, { NCSI_PKT_RSP_SP, 4, NULL }, { NCSI_PKT_RSP_DP, 4, NULL }, @@ -178,7 +178,7 @@ void ncsi_input(Slirp *slirp, const uint8_t *pkt, int pkt_len) if (handler->handler) { /* TODO: handle errors */ - handler->handler(rnh); + handler->handler(slirp, rnh); } ncsi_rsp_len += handler->payload; } else { -- cgit v1.1 From a3efc04dbeee57a6857adf7597bdb7f1c44fb288 Mon Sep 17 00:00:00 2001 From: Peter Delevoryas Date: Thu, 2 Dec 2021 21:20:56 -0800 Subject: ncsi: Add Get Version ID command Get Version ID is one of the first commands used in NC-SI, because BMC's use a lot of OEM NC-SI extensions, and you need to query the device's manufacturer through Get Version ID before you can decide which OEM NC-SI extensions to use. The response format is documented in the NC-SI spec[1]. We're just setting the NC-SI version supported to 1.0.0 (BCD-encoded[2]) and returning the manufacturer's ID in network byte-order. [1] https://www.dmtf.org/sites/default/files/standards/documents/DSP0222_1.0.0.pdf [2] https://en.wikipedia.org/wiki/Binary-coded_decimal Signed-off-by: Peter Delevoryas --- src/ncsi.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/ncsi.c b/src/ncsi.c index e556193..5bf731b 100644 --- a/src/ncsi.c +++ b/src/ncsi.c @@ -55,6 +55,17 @@ static uint32_t ncsi_calculate_checksum(uint8_t *data, int len) return checksum; } +/* Get Version ID */ +static int ncsi_rsp_handler_gvi(Slirp *slirp, struct ncsi_rsp_pkt_hdr *rnh) +{ + struct ncsi_rsp_gvi_pkt *rsp = (struct ncsi_rsp_gvi_pkt *)rnh; + + rsp->ncsi_version = htonl(0xF1F0F000); + rsp->mf_id = htonl(slirp->mfr_id); + + return 0; +} + /* Get Capabilities */ static int ncsi_rsp_handler_gc(Slirp *slirp, struct ncsi_rsp_pkt_hdr *rnh) { @@ -117,7 +128,7 @@ static const struct ncsi_rsp_handler { { NCSI_PKT_RSP_EGMF, 4, NULL }, { NCSI_PKT_RSP_DGMF, 4, NULL }, { NCSI_PKT_RSP_SNFC, 4, NULL }, - { NCSI_PKT_RSP_GVI, 40, NULL }, + { NCSI_PKT_RSP_GVI, 40, ncsi_rsp_handler_gvi }, { NCSI_PKT_RSP_GC, 32, ncsi_rsp_handler_gc }, { NCSI_PKT_RSP_GP, 40, ncsi_rsp_handler_gp }, { NCSI_PKT_RSP_GCPS, 172, NULL }, -- cgit v1.1