diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2022-10-30 18:12:02 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2022-10-30 18:12:02 +0100 |
commit | 1f3c9b4ae26ce1d46d954d509b83b8684ada5625 (patch) | |
tree | 260b922ec4d5d153cc6db745e27931cfd464472f /src/plugins/ipmi_intf.c | |
parent | 8fcf0ba6f182918bd584bb80bf0b8998acad26a8 (diff) | |
parent | 8b758ee941f4c1ffea0532caa74b1fcd8101d1d8 (diff) |
Merge branch 'release/debian/1.8.19-1'debian/1.8.19-1
Diffstat (limited to 'src/plugins/ipmi_intf.c')
-rw-r--r-- | src/plugins/ipmi_intf.c | 123 |
1 files changed, 85 insertions, 38 deletions
diff --git a/src/plugins/ipmi_intf.c b/src/plugins/ipmi_intf.c index 9225a34..e424a64 100644 --- a/src/plugins/ipmi_intf.c +++ b/src/plugins/ipmi_intf.c @@ -29,9 +29,6 @@ * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. */ -#define _XOPEN_SOURCE 700 -#define _GNU_SOURCE 1 -#define _DARWIN_C_SOURCE 1 #include <stdio.h> #include <stdlib.h> @@ -89,6 +86,9 @@ extern struct ipmi_intf ipmi_dummy_intf; #ifdef IPMI_INTF_USB extern struct ipmi_intf ipmi_usb_intf; #endif +#ifdef IPMI_INTF_DBUS +extern struct ipmi_intf ipmi_dbus_intf; +#endif struct ipmi_intf * ipmi_intf_table[] = { #ifdef IPMI_INTF_OPEN @@ -122,9 +122,32 @@ struct ipmi_intf * ipmi_intf_table[] = { #ifdef IPMI_INTF_USB &ipmi_usb_intf, #endif +#ifdef IPMI_INTF_DBUS + &ipmi_dbus_intf, +#endif NULL }; +/* get_default_interface - return the interface that was chosen by configure + * + * returns a valid interface pointer + */ +static struct ipmi_intf *get_default_interface(void) +{ + static const char *default_intf_name = DEFAULT_INTF; + struct ipmi_intf ** intf; + for (intf = ipmi_intf_table; intf && *intf; intf++) { + if (!strcmp(default_intf_name, (*intf)->name)) { + return *intf; + } + } + /* code should never reach this because the configure script checks + * to see that the default interface is actually enabled, but we have + * to return some valid value here, so the first entry works + */ + return ipmi_intf_table[0]; +} + /* ipmi_intf_print - Print list of interfaces * * no meaningful return code @@ -132,20 +155,20 @@ struct ipmi_intf * ipmi_intf_table[] = { void ipmi_intf_print(struct ipmi_intf_support * intflist) { struct ipmi_intf ** intf; + struct ipmi_intf *def_intf; struct ipmi_intf_support * sup; - int def = 1; int found; + def_intf = get_default_interface(); lprintf(LOG_NOTICE, "Interfaces:"); for (intf = ipmi_intf_table; intf && *intf; intf++) { - if (intflist != NULL) { + if (intflist) { found = 0; - for (sup=intflist; sup->name != NULL; sup++) { - if (strncmp(sup->name, (*intf)->name, strlen(sup->name)) == 0 && - strncmp(sup->name, (*intf)->name, strlen((*intf)->name)) == 0 && - sup->supported == 1) + for (sup=intflist; sup->name; sup++) { + if (!strcmp(sup->name, (*intf)->name) + && sup->supported) found = 1; } if (found == 0) @@ -154,8 +177,7 @@ void ipmi_intf_print(struct ipmi_intf_support * intflist) lprintf(LOG_NOTICE, "\t%-12s %s %s", (*intf)->name, (*intf)->desc, - def ? "[default]" : ""); - def = 0; + def_intf == (*intf) ? "[default]" : ""); } lprintf(LOG_NOTICE, ""); } @@ -173,9 +195,9 @@ struct ipmi_intf * ipmi_intf_load(char * name) struct ipmi_intf ** intf; struct ipmi_intf * i; - if (name == NULL) { - i = ipmi_intf_table[0]; - if (i->setup != NULL && (i->setup(i) < 0)) { + if (!name) { + i = get_default_interface(); + if (i->setup && (i->setup(i) < 0)) { lprintf(LOG_ERR, "Unable to setup " "interface %s", name); return NULL; @@ -184,11 +206,12 @@ struct ipmi_intf * ipmi_intf_load(char * name) } for (intf = ipmi_intf_table; - ((intf != NULL) && (*intf != NULL)); - intf++) { + intf && *intf; + intf++) + { i = *intf; - if (strncmp(name, i->name, strlen(name)) == 0) { - if (i->setup != NULL && (i->setup(i) < 0)) { + if (!strcmp(name, i->name)) { + if (i->setup && (i->setup(i) < 0)) { lprintf(LOG_ERR, "Unable to setup " "interface %s", name); return NULL; @@ -203,11 +226,11 @@ struct ipmi_intf * ipmi_intf_load(char * name) void ipmi_intf_session_set_hostname(struct ipmi_intf * intf, char * hostname) { - if (intf->ssn_params.hostname != NULL) { + if (intf->ssn_params.hostname) { free(intf->ssn_params.hostname); intf->ssn_params.hostname = NULL; } - if (hostname == NULL) { + if (!hostname) { return; } intf->ssn_params.hostname = strdup(hostname); @@ -218,7 +241,7 @@ ipmi_intf_session_set_username(struct ipmi_intf * intf, char * username) { memset(intf->ssn_params.username, 0, 17); - if (username == NULL) + if (!username) return; memcpy(intf->ssn_params.username, username, __min(strlen(username), 16)); @@ -229,7 +252,7 @@ ipmi_intf_session_set_password(struct ipmi_intf * intf, char * password) { memset(intf->ssn_params.authcode_set, 0, IPMI_AUTHCODE_BUFFER_SIZE); - if (password == NULL) { + if (!password) { intf->ssn_params.password = 0; return; } @@ -251,11 +274,14 @@ ipmi_intf_session_set_lookupbit(struct ipmi_intf * intf, uint8_t lookupbit) intf->ssn_params.lookupbit = lookupbit; } +#ifdef IPMI_INTF_LANPLUS void -ipmi_intf_session_set_cipher_suite_id(struct ipmi_intf * intf, uint8_t cipher_suite_id) +ipmi_intf_session_set_cipher_suite_id(struct ipmi_intf * intf, + enum cipher_suite_ids cipher_suite_id) { intf->ssn_params.cipher_suite_id = cipher_suite_id; } +#endif /* IPMI_INTF_LANPLUS */ void ipmi_intf_session_set_sol_escape_char(struct ipmi_intf * intf, char sol_escape_char) @@ -302,7 +328,7 @@ ipmi_intf_session_set_retry(struct ipmi_intf * intf, int retry) void ipmi_intf_session_cleanup(struct ipmi_intf *intf) { - if (intf->session == NULL) { + if (!intf->session) { return; } @@ -313,7 +339,7 @@ ipmi_intf_session_cleanup(struct ipmi_intf *intf) void ipmi_cleanup(struct ipmi_intf * intf) { - ipmi_sdr_list_empty(intf); + ipmi_sdr_list_empty(); ipmi_intf_session_set_hostname(intf, NULL); } @@ -334,7 +360,7 @@ ipmi_intf_socket_connect(struct ipmi_intf * intf) params = &intf->ssn_params; - if (params->hostname == NULL || strlen((const char *)params->hostname) == 0) { + if (!params->hostname || strlen((const char *)params->hostname) == 0) { lprintf(LOG_ERR, "No hostname specified!"); return -1; } @@ -362,7 +388,7 @@ ipmi_intf_socket_connect(struct ipmi_intf * intf) * and) try the next address. */ - for (rp = rp0; rp != NULL; rp = rp->ai_next) { + for (rp = rp0; rp; rp = rp->ai_next) { /* We are only interested in IPv4 and IPv6 */ if ((rp->ai_family != AF_INET6) && (rp->ai_family != AF_INET)) { continue; @@ -406,8 +432,8 @@ ipmi_intf_socket_connect(struct ipmi_intf * intf) break; } - for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) { - if (ifa->ifa_addr == NULL) { + for (ifa = ifaddrs; ifa; ifa = ifa->ifa_next) { + if (!ifa->ifa_addr) { continue; } @@ -424,7 +450,7 @@ ipmi_intf_socket_connect(struct ipmi_intf * intf) len = sizeof(struct sockaddr_in6); if ( getnameinfo((struct sockaddr *)tmp6, len, hbuf, sizeof(hbuf), NULL, 0, NI_NUMERICHOST) == 0) { lprintf(LOG_DEBUG, "Testing %s interface address: %s scope=%d", - ifa->ifa_name != NULL ? ifa->ifa_name : "???", + ifa->ifa_name ? ifa->ifa_name : "???", hbuf, tmp6->sin6_scope_id); } @@ -476,13 +502,14 @@ uint16_t ipmi_intf_get_max_request_data_size(struct ipmi_intf * intf) { int16_t size; + uint8_t bridging_level = ipmi_intf_get_bridging_level(intf); size = intf->max_request_data_size; /* check if request size is not specified */ if (!size) { /* - * The IPMB standard overall message length for ‘non -bridging’ + * The IPMB standard overall message length for non-bridging * messages is specified as 32 bytes, maximum, including slave * address. This sets the upper limit for typical IPMI messages. * With the exception of messages used for bridging messages to @@ -495,14 +522,14 @@ ipmi_intf_get_max_request_data_size(struct ipmi_intf * intf) size = IPMI_DEFAULT_PAYLOAD_SIZE; /* check if message is forwarded */ - if (intf->target_addr && intf->target_addr != intf->my_addr) { + if (bridging_level) { /* add Send Message request size */ size += 8; } } /* check if message is forwarded */ - if (intf->target_addr && intf->target_addr != intf->my_addr) { + if (bridging_level) { /* subtract send message request size */ size -= 8; @@ -515,7 +542,7 @@ ipmi_intf_get_max_request_data_size(struct ipmi_intf * intf) } /* check for double bridging */ - if (intf->transit_addr && intf->transit_addr != intf->target_addr) { + if (bridging_level == 2) { /* subtract inner send message request size */ size -= 8; } @@ -533,13 +560,14 @@ uint16_t ipmi_intf_get_max_response_data_size(struct ipmi_intf * intf) { int16_t size; + uint8_t bridging_level = ipmi_intf_get_bridging_level(intf); size = intf->max_response_data_size; /* check if response size is not specified */ if (!size) { /* - * The IPMB standard overall message length for ‘non -bridging’ + * The IPMB standard overall message length for non-bridging * messages is specified as 32 bytes, maximum, including slave * address. This sets the upper limit for typical IPMI messages. * With the exception of messages used for bridging messages to @@ -552,14 +580,14 @@ ipmi_intf_get_max_response_data_size(struct ipmi_intf * intf) size = IPMI_DEFAULT_PAYLOAD_SIZE; /* response length with subtracted header and checksum byte */ /* check if message is forwarded */ - if (intf->target_addr && intf->target_addr != intf->my_addr) { + if (bridging_level) { /* add Send Message header size */ size += 7; } } /* check if message is forwarded */ - if (intf->target_addr && intf->target_addr != intf->my_addr) { + if (bridging_level) { /* * Some IPMI controllers like PICMG AMC Carriers embed responses * to the forwarded messages into the Send Message response. @@ -577,7 +605,7 @@ ipmi_intf_get_max_response_data_size(struct ipmi_intf * intf) } /* check for double bridging */ - if (intf->transit_addr && intf->transit_addr != intf->target_addr) { + if (bridging_level == 2) { /* subtract inner send message header size */ size -= 8; } @@ -591,6 +619,25 @@ ipmi_intf_get_max_response_data_size(struct ipmi_intf * intf) return size; } +uint8_t +ipmi_intf_get_bridging_level(const struct ipmi_intf *intf) +{ + uint8_t bridging_level; + + if (intf->target_addr && (intf->target_addr != intf->my_addr)) { + if (intf->transit_addr && + (intf->transit_addr != intf->target_addr || intf->transit_channel != intf->target_channel)) { + bridging_level = 2; + } else { + bridging_level = 1; + } + } else { + bridging_level = 0; + } + + return bridging_level; +} + void ipmi_intf_set_max_request_data_size(struct ipmi_intf * intf, uint16_t size) { |