summaryrefslogtreecommitdiff
path: root/lib/ipmi_lanp.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ipmi_lanp.c')
-rw-r--r--lib/ipmi_lanp.c580
1 files changed, 330 insertions, 250 deletions
diff --git a/lib/ipmi_lanp.c b/lib/ipmi_lanp.c
index c3be3de..16c0d9a 100644
--- a/lib/ipmi_lanp.c
+++ b/lib/ipmi_lanp.c
@@ -57,6 +57,62 @@
extern int verbose;
+static struct lan_param {
+ int cmd;
+ int size;
+ char desc[24];
+ uint8_t *data;
+ int data_len;
+} ipmi_lan_params[] = {
+ { IPMI_LANP_SET_IN_PROGRESS, 1, "Set in Progress", NULL, 0 },
+ { IPMI_LANP_AUTH_TYPE, 1, "Auth Type Support", NULL, 0 },
+ { IPMI_LANP_AUTH_TYPE_ENABLE, 5, "Auth Type Enable", NULL, 0 },
+ { IPMI_LANP_IP_ADDR, 4, "IP Address", NULL, 0 },
+ { IPMI_LANP_IP_ADDR_SRC, 1, "IP Address Source", NULL, 0 },
+ { IPMI_LANP_MAC_ADDR, 6, "MAC Address", NULL, 0 }, /* 5 */
+ { IPMI_LANP_SUBNET_MASK, 4, "Subnet Mask", NULL, 0 },
+ { IPMI_LANP_IP_HEADER, 3, "IP Header", NULL, 0 },
+ { IPMI_LANP_PRI_RMCP_PORT, 2, "Primary RMCP Port", NULL, 0 },
+ { IPMI_LANP_SEC_RMCP_PORT, 2, "Secondary RMCP Port", NULL, 0 },
+ { IPMI_LANP_BMC_ARP, 1, "BMC ARP Control", NULL, 0}, /* 10 */
+ { IPMI_LANP_GRAT_ARP, 1, "Gratituous ARP Intrvl", NULL, 0 },
+ { IPMI_LANP_DEF_GATEWAY_IP, 4, "Default Gateway IP", NULL, 0 },
+ { IPMI_LANP_DEF_GATEWAY_MAC, 6, "Default Gateway MAC", NULL, 0 },
+ { IPMI_LANP_BAK_GATEWAY_IP, 4, "Backup Gateway IP", NULL, 0 },
+ { IPMI_LANP_BAK_GATEWAY_MAC, 6, "Backup Gateway MAC", NULL, 0 }, /* 15 */
+ { IPMI_LANP_SNMP_STRING, 18, "SNMP Community String", NULL, 0 },
+ { IPMI_LANP_NUM_DEST, 1, "Number of Destinations", NULL, 0 },
+ { IPMI_LANP_DEST_TYPE, 4, "Destination Type", NULL, 0 },
+ { IPMI_LANP_DEST_ADDR, 13, "Destination Addresses", NULL, 0 },
+ { IPMI_LANP_VLAN_ID, 2, "802.1q VLAN ID", NULL, 0 }, /* 20 */
+ { IPMI_LANP_VLAN_PRIORITY, 1, "802.1q VLAN Priority", NULL, 0 },
+ { IPMI_LANP_RMCP_CIPHER_SUPPORT,1, "RMCP+ Cipher Suite Count", NULL, 0 },
+ { IPMI_LANP_RMCP_CIPHERS, 16, "RMCP+ Cipher Suites", NULL, 0 },
+ { IPMI_LANP_RMCP_PRIV_LEVELS, 9, "Cipher Suite Priv Max", NULL, 0 },
+ { IPMI_LANP_BAD_PASS_THRESH, 6, "Bad Password Threshold", NULL, 0 },
+ { IPMI_LANP_OEM_ALERT_STRING, 28, "OEM Alert String", NULL, 0 }, /* 25 */
+ { IPMI_LANP_ALERT_RETRY, 1, "Alert Retry Algorithm", NULL, 0 },
+ { IPMI_LANP_UTC_OFFSET, 3, "UTC Offset", NULL, 0 },
+ { IPMI_LANP_DHCP_SERVER_IP, 4, "DHCP Server IP", NULL, 0 },
+ { IPMI_LANP_DHCP_SERVER_MAC, 6, "DHDP Server MAC", NULL, 0},
+ { IPMI_LANP_DHCP_ENABLE, 1, "DHCP Enable", NULL, 0 }, /* 30 */
+ { IPMI_LANP_CHAN_ACCESS_MODE, 2, "Channel Access Mode", NULL, 0 },
+ { -1, -1, "", NULL, -1 }
+};
+
+static const struct valstr set_lan_cc_vals[] = {
+ { 0x80, "Unsupported parameter" },
+ { 0x81, "Attempt to set 'in progress' while not in 'complete' state" },
+ { 0x82, "Parameter is read-only" },
+ { 0x83, "Parameter is wrote-only" },
+ { 0x00, NULL }
+};
+
+static const struct valstr get_lan_cc_vals[] = {
+ { 0x80, "Unsupported parameter" },
+ { 0x00, NULL }
+};
+
static void print_lan_alert_print_usage(void);
static void print_lan_alert_set_usage(void);
static void print_lan_set_usage(void);
@@ -80,7 +136,7 @@ static void print_lan_usage(void);
* @chan: channel number to check
*/
static int
-is_lan_channel(struct ipmi_intf * intf, uint8_t chan)
+is_lan_channel(struct ipmi_intf *intf, uint8_t chan)
{
uint8_t medium;
@@ -105,7 +161,7 @@ is_lan_channel(struct ipmi_intf * intf, uint8_t chan)
* @start: channel number to start searching from
*/
uint8_t
-find_lan_channel(struct ipmi_intf * intf, uint8_t start)
+find_lan_channel(struct ipmi_intf *intf, uint8_t start)
{
uint8_t chan = 0;
@@ -131,10 +187,11 @@ find_lan_channel(struct ipmi_intf * intf, uint8_t start)
* @select: lan parameter set selector
*/
static struct lan_param *
-get_lan_param_select(struct ipmi_intf * intf, uint8_t chan, int param, int select)
+get_lan_param_select(struct ipmi_intf *intf, uint8_t chan, int param, int select)
{
- struct lan_param * p = NULL;
- struct ipmi_rs * rsp;
+ struct lan_param *p = NULL;
+ struct lan_param *rc = NULL;
+ struct ipmi_rs *rsp;
struct ipmi_rq req;
int i = 0;
uint8_t msg_data[4];
@@ -146,9 +203,9 @@ get_lan_param_select(struct ipmi_intf * intf, uint8_t chan, int param, int selec
}
}
- if (p == NULL) {
+ if (!p) {
lprintf(LOG_INFO, "Get LAN Parameter failed: Unknown parameter.");
- return NULL;
+ return rc;
}
msg_data[0] = chan;
@@ -163,9 +220,9 @@ get_lan_param_select(struct ipmi_intf * intf, uint8_t chan, int param, int selec
req.msg.data_len = 4;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_INFO, "Get LAN Parameter '%s' command failed", p->desc);
- return NULL;
+ return rc;
}
switch (rsp->ccode)
@@ -176,19 +233,18 @@ get_lan_param_select(struct ipmi_intf * intf, uint8_t chan, int param, int selec
case 0x80: /* parameter not supported */
case 0xc9: /* parameter out of range */
case 0xcc: /* invalid data field in request */
-
- /* these completion codes usually mean parameter not supported */
- lprintf(LOG_INFO, "Get LAN Parameter '%s' command failed: %s",
- p->desc, val2str(rsp->ccode, completion_code_vals));
+ /* We treat them as valid but empty response */
p->data = NULL;
p->data_len = 0;
- return p;
-
+ rc = p;
+ /* fall through */
default:
-
/* other completion codes are treated as error */
lprintf(LOG_INFO, "Get LAN Parameter '%s' command failed: %s",
- p->desc, val2str(rsp->ccode, completion_code_vals));
+ p->desc,
+ specific_val2str(rsp->ccode,
+ get_lan_cc_vals,
+ completion_code_vals));
return NULL;
}
@@ -211,7 +267,7 @@ get_lan_param_select(struct ipmi_intf * intf, uint8_t chan, int param, int selec
* @param: lan parameter id
*/
static struct lan_param *
-get_lan_param(struct ipmi_intf * intf, uint8_t chan, int param)
+get_lan_param(struct ipmi_intf *intf, uint8_t chan, int param)
{
return get_lan_param_select(intf, chan, param, 0);
}
@@ -232,10 +288,10 @@ get_lan_param(struct ipmi_intf * intf, uint8_t chan, int param)
* @len: length of lan parameter data
*/
static int
-set_lan_param_wait(struct ipmi_intf * intf, uint8_t chan,
- int param, uint8_t * data, int len)
+set_lan_param_wait(struct ipmi_intf *intf, uint8_t chan,
+ int param, uint8_t *data, int len)
{
- struct lan_param * p;
+ struct lan_param *p;
int retry = 10; /* 10 retries */
lprintf(LOG_DEBUG, "Waiting for Set LAN Parameter to complete...");
@@ -244,7 +300,7 @@ set_lan_param_wait(struct ipmi_intf * intf, uint8_t chan,
for (;;) {
p = get_lan_param(intf, chan, param);
- if (p == NULL) {
+ if (!p) {
sleep(IPMI_LANP_TIMEOUT);
if (retry-- == 0)
return -1;
@@ -291,10 +347,10 @@ set_lan_param_wait(struct ipmi_intf * intf, uint8_t chan,
* @wait: whether to wait for write completion
*/
static int
-__set_lan_param(struct ipmi_intf * intf, uint8_t chan,
- int param, uint8_t * data, int len, int wait)
+__set_lan_param(struct ipmi_intf *intf, uint8_t chan,
+ int param, uint8_t *data, int len, int wait)
{
- struct ipmi_rs * rsp;
+ struct ipmi_rs *rsp;
struct ipmi_rq req;
uint8_t msg_data[32];
@@ -312,13 +368,15 @@ __set_lan_param(struct ipmi_intf * intf, uint8_t chan,
req.msg.data_len = len+2;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Set LAN Parameter failed");
return -1;
}
- if ((rsp->ccode > 0) && (wait != 0)) {
+ if (rsp->ccode && wait) {
lprintf(LOG_DEBUG, "Warning: Set LAN Parameter failed: %s",
- val2str(rsp->ccode, completion_code_vals));
+ specific_val2str(rsp->ccode,
+ set_lan_cc_vals,
+ completion_code_vals));
if (rsp->ccode == 0xcc) {
/* retry hack for invalid data field ccode */
int retry = 10; /* 10 retries */
@@ -328,9 +386,7 @@ __set_lan_param(struct ipmi_intf * intf, uint8_t chan,
break;
sleep(IPMI_LANP_TIMEOUT);
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL)
- continue;
- if (rsp->ccode > 0)
+ if (!rsp || rsp->ccode)
continue;
return set_lan_param_wait(intf, chan, param, data, len);
}
@@ -341,7 +397,7 @@ __set_lan_param(struct ipmi_intf * intf, uint8_t chan,
}
}
- if (wait == 0)
+ if (!wait)
return 0;
return set_lan_param_wait(intf, chan, param, data, len);
}
@@ -358,13 +414,13 @@ __set_lan_param(struct ipmi_intf * intf, uint8_t chan,
* @chan: ipmi channel
*/
static int
-ipmi_lanp_lock_state(struct ipmi_intf * intf, uint8_t chan)
+ipmi_lanp_lock_state(struct ipmi_intf *intf, uint8_t chan)
{
- struct lan_param * p;
+ struct lan_param *p;
p = get_lan_param(intf, chan, IPMI_LANP_SET_IN_PROGRESS);
- if (p == NULL)
+ if (!p)
return -1;
- if (p->data == NULL)
+ if (!p->data)
return -1;
return (p->data[0] & 3);
}
@@ -381,7 +437,7 @@ ipmi_lanp_lock_state(struct ipmi_intf * intf, uint8_t chan)
* @chan: ipmi channel
*/
static void
-ipmi_lanp_lock(struct ipmi_intf * intf, uint8_t chan)
+ipmi_lanp_lock(struct ipmi_intf *intf, uint8_t chan)
{
uint8_t val = IPMI_LANP_WRITE_LOCK;
int retry = 3;
@@ -411,7 +467,7 @@ ipmi_lanp_lock(struct ipmi_intf * intf, uint8_t chan)
* @chan: ipmi channel
*/
static void
-ipmi_lanp_unlock(struct ipmi_intf * intf, uint8_t chan)
+ipmi_lanp_unlock(struct ipmi_intf *intf, uint8_t chan)
{
uint8_t val = IPMI_LANP_WRITE_COMMIT;
int rc;
@@ -436,8 +492,8 @@ ipmi_lanp_unlock(struct ipmi_intf * intf, uint8_t chan)
* @len: length of lan parameter data
*/
static int
-set_lan_param(struct ipmi_intf * intf, uint8_t chan,
- int param, uint8_t * data, int len)
+set_lan_param(struct ipmi_intf *intf, uint8_t chan,
+ int param, uint8_t *data, int len)
{
int rc;
ipmi_lanp_lock(intf, chan);
@@ -457,8 +513,8 @@ set_lan_param(struct ipmi_intf * intf, uint8_t chan,
* @len: length of lan parameter data
*/
static int
-set_lan_param_nowait(struct ipmi_intf * intf, uint8_t chan,
- int param, uint8_t * data, int len)
+set_lan_param_nowait(struct ipmi_intf *intf, uint8_t chan,
+ int param, uint8_t *data, int len)
{
int rc;
ipmi_lanp_lock(intf, chan);
@@ -468,16 +524,16 @@ set_lan_param_nowait(struct ipmi_intf * intf, uint8_t chan,
}
static int
-lan_set_arp_interval(struct ipmi_intf * intf, uint8_t chan, uint8_t ival)
+lan_set_arp_interval(struct ipmi_intf *intf, uint8_t chan, uint8_t ival)
{
struct lan_param *lp;
uint8_t interval = 0;
int rc = 0;
lp = get_lan_param(intf, chan, IPMI_LANP_GRAT_ARP);
- if (lp == NULL)
+ if (!lp)
return -1;
- if (lp->data == NULL)
+ if (!lp->data)
return -1;
if (ival != 0) {
@@ -498,16 +554,16 @@ lan_set_arp_interval(struct ipmi_intf * intf, uint8_t chan, uint8_t ival)
}
static int
-lan_set_arp_generate(struct ipmi_intf * intf,
+lan_set_arp_generate(struct ipmi_intf *intf,
uint8_t chan, uint8_t ctl)
{
struct lan_param *lp;
uint8_t data;
lp = get_lan_param(intf, chan, IPMI_LANP_BMC_ARP);
- if (lp == NULL)
+ if (!lp)
return -1;
- if (lp->data == NULL)
+ if (!lp->data)
return -1;
data = lp->data[0];
@@ -522,16 +578,16 @@ lan_set_arp_generate(struct ipmi_intf * intf,
}
static int
-lan_set_arp_respond(struct ipmi_intf * intf,
+lan_set_arp_respond(struct ipmi_intf *intf,
uint8_t chan, uint8_t ctl)
{
struct lan_param *lp;
uint8_t data;
lp = get_lan_param(intf, chan, IPMI_LANP_BMC_ARP);
- if (lp == NULL)
+ if (!lp)
return -1;
- if (lp->data == NULL)
+ if (!lp->data)
return -1;
data = lp->data[0];
@@ -574,9 +630,9 @@ static char priv_level_to_char(unsigned char priv_level)
static int
-ipmi_lan_print(struct ipmi_intf * intf, uint8_t chan)
+ipmi_lan_print(struct ipmi_intf *intf, uint8_t chan)
{
- struct lan_param * p;
+ struct lan_param *p;
if (chan < 1 || chan > IPMI_CHANNEL_NUMBER_MAX) {
lprintf(LOG_ERR, "Invalid Channel %d", chan);
@@ -590,9 +646,9 @@ ipmi_lan_print(struct ipmi_intf * intf, uint8_t chan)
}
p = get_lan_param(intf, chan, IPMI_LANP_SET_IN_PROGRESS);
- if (p == NULL)
+ if (!p)
return -1;
- if (p->data != NULL) {
+ if (p->data) {
printf("%-24s: ", p->desc);
p->data[0] &= 3;
switch (p->data[0]) {
@@ -614,9 +670,9 @@ ipmi_lan_print(struct ipmi_intf * intf, uint8_t chan)
}
p = get_lan_param(intf, chan, IPMI_LANP_AUTH_TYPE);
- if (p == NULL)
+ if (!p)
return -1;
- if (p->data != NULL) {
+ if (p->data) {
printf("%-24s: %s%s%s%s%s\n", p->desc,
(p->data[0] & 1<<IPMI_SESSION_AUTHTYPE_NONE) ? "NONE " : "",
(p->data[0] & 1<<IPMI_SESSION_AUTHTYPE_MD2) ? "MD2 " : "",
@@ -626,9 +682,9 @@ ipmi_lan_print(struct ipmi_intf * intf, uint8_t chan)
}
p = get_lan_param(intf, chan, IPMI_LANP_AUTH_TYPE_ENABLE);
- if (p == NULL)
+ if (!p)
return -1;
- if (p->data != NULL) {
+ if (p->data) {
printf("%-24s: Callback : %s%s%s%s%s\n", p->desc,
(p->data[0] & 1<<IPMI_SESSION_AUTHTYPE_NONE) ? "NONE " : "",
(p->data[0] & 1<<IPMI_SESSION_AUTHTYPE_MD2) ? "MD2 " : "",
@@ -662,9 +718,9 @@ ipmi_lan_print(struct ipmi_intf * intf, uint8_t chan)
}
p = get_lan_param(intf, chan, IPMI_LANP_IP_ADDR_SRC);
- if (p == NULL)
+ if (!p)
return -1;
- if (p->data != NULL) {
+ if (p->data) {
printf("%-24s: ", p->desc);
p->data[0] &= 0xf;
switch (p->data[0]) {
@@ -687,79 +743,79 @@ ipmi_lan_print(struct ipmi_intf * intf, uint8_t chan)
}
p = get_lan_param(intf, chan, IPMI_LANP_IP_ADDR);
- if (p == NULL)
+ if (!p)
return -1;
- if (p->data != NULL)
+ if (p->data)
printf("%-24s: %d.%d.%d.%d\n", p->desc,
p->data[0], p->data[1], p->data[2], p->data[3]);
p = get_lan_param(intf, chan, IPMI_LANP_SUBNET_MASK);
- if (p == NULL)
+ if (!p)
return -1;
- if (p->data != NULL)
+ if (p->data)
printf("%-24s: %d.%d.%d.%d\n", p->desc,
p->data[0], p->data[1], p->data[2], p->data[3]);
p = get_lan_param(intf, chan, IPMI_LANP_MAC_ADDR);
- if (p == NULL)
+ if (!p)
return -1;
- if (p->data != NULL)
+ if (p->data)
printf("%-24s: %s\n", p->desc, mac2str(p->data));
p = get_lan_param(intf, chan, IPMI_LANP_SNMP_STRING);
- if (p == NULL)
+ if (!p)
return -1;
- if (p->data != NULL)
+ if (p->data)
printf("%-24s: %s\n", p->desc, p->data);
p = get_lan_param(intf, chan, IPMI_LANP_IP_HEADER);
- if (p == NULL)
+ if (!p)
return -1;
- if (p->data != NULL)
+ if (p->data)
printf("%-24s: TTL=0x%02x Flags=0x%02x Precedence=0x%02x TOS=0x%02x\n",
p->desc, p->data[0], p->data[1] & 0xe0, p->data[2] & 0xe0, p->data[2] & 0x1e);
p = get_lan_param(intf, chan, IPMI_LANP_BMC_ARP);
- if (p == NULL)
+ if (!p)
return -1;
- if (p->data != NULL)
+ if (p->data)
printf("%-24s: ARP Responses %sabled, Gratuitous ARP %sabled\n", p->desc,
(p->data[0] & 2) ? "En" : "Dis", (p->data[0] & 1) ? "En" : "Dis");
p = get_lan_param(intf, chan, IPMI_LANP_GRAT_ARP);
- if (p == NULL)
+ if (!p)
return -1;
- if (p->data != NULL)
+ if (p->data)
printf("%-24s: %.1f seconds\n", p->desc, (float)((p->data[0] + 1) / 2));
p = get_lan_param(intf, chan, IPMI_LANP_DEF_GATEWAY_IP);
- if (p == NULL)
+ if (!p)
return -1;
- if (p->data != NULL)
+ if (p->data)
printf("%-24s: %d.%d.%d.%d\n", p->desc,
p->data[0], p->data[1], p->data[2], p->data[3]);
p = get_lan_param(intf, chan, IPMI_LANP_DEF_GATEWAY_MAC);
- if (p == NULL)
+ if (!p)
return -1;
- if (p->data != NULL)
+ if (p->data)
printf("%-24s: %s\n", p->desc, mac2str(p->data));
p = get_lan_param(intf, chan, IPMI_LANP_BAK_GATEWAY_IP);
- if (p == NULL)
+ if (!p)
return -1;
- if (p->data != NULL)
+ if (p->data)
printf("%-24s: %d.%d.%d.%d\n", p->desc,
p->data[0], p->data[1], p->data[2], p->data[3]);
p = get_lan_param(intf, chan, IPMI_LANP_BAK_GATEWAY_MAC);
- if (p == NULL)
+ if (!p)
return -1;
- if (p->data != NULL)
+ if (p->data)
printf("%-24s: %s\n", p->desc, mac2str(p->data));
p = get_lan_param(intf, chan, IPMI_LANP_VLAN_ID);
- if (p != NULL && p->data != NULL) {
+ if (p && p->data) {
int id = ((p->data[1] & 0x0f) << 8) + p->data[0];
if (p->data[1] & 0x80)
printf("%-24s: %d\n", p->desc, id);
@@ -768,25 +824,25 @@ ipmi_lan_print(struct ipmi_intf * intf, uint8_t chan)
}
p = get_lan_param(intf, chan, IPMI_LANP_VLAN_PRIORITY);
- if (p != NULL && p->data != NULL)
+ if (p && p->data)
printf("%-24s: %d\n", p->desc, p->data[0] & 0x07);
/* Determine supported Cipher Suites -- Requires two calls */
p = get_lan_param(intf, chan, IPMI_LANP_RMCP_CIPHER_SUPPORT);
- if (p == NULL)
+ if (!p)
return -1;
- else if (p->data != NULL)
+ else if (p->data)
{
unsigned char cipher_suite_count = p->data[0];
p = get_lan_param(intf, chan, IPMI_LANP_RMCP_CIPHERS);
- if (p == NULL)
+ if (!p)
return -1;
printf("%-24s: ", p->desc);
/* Now we're dangerous. There are only 15 fixed cipher
suite IDs, but the spec allows for 16 in the return data.*/
- if ((p->data != NULL) && (p->data_len <= 17))
+ if (p->data && p->data_len <= 17)
{
unsigned int i;
for (i = 0; (i < 16) && (i < cipher_suite_count); ++i)
@@ -806,9 +862,9 @@ ipmi_lan_print(struct ipmi_intf * intf, uint8_t chan)
/* RMCP+ Messaging Cipher Suite Privilege Levels */
/* These are the privilege levels for the 15 fixed cipher suites */
p = get_lan_param(intf, chan, IPMI_LANP_RMCP_PRIV_LEVELS);
- if (p == NULL)
+ if (!p)
return -1;
- if ((p->data != NULL) && (p->data_len == 9))
+ if (p->data && 9 == p->data_len)
{
printf("%-24s: %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n", p->desc,
priv_level_to_char(p->data[1] & 0x0F),
@@ -840,9 +896,9 @@ ipmi_lan_print(struct ipmi_intf * intf, uint8_t chan)
/* Bad Password Threshold */
p = get_lan_param(intf, chan, IPMI_LANP_BAD_PASS_THRESH);
- if (p == NULL)
+ if (!p)
return -1;
- if ((p->data != NULL) && (p->data_len == 6)) {
+ if (p->data && 6 == p->data_len) {
int tmp;
printf("%-24s: %d\n", p->desc, p->data[1]);
@@ -862,20 +918,20 @@ ipmi_lan_print(struct ipmi_intf * intf, uint8_t chan)
/* Configure Authentication Types */
/* TODO - probably some code duplication going on ??? */
static int
-ipmi_lan_set_auth(struct ipmi_intf * intf, uint8_t chan, char * level, char * types)
+ipmi_lan_set_auth(struct ipmi_intf *intf, uint8_t chan, char *level, char *types)
{
uint8_t data[5];
uint8_t authtype = 0;
- char * p;
- struct lan_param * lp;
+ char *p;
+ struct lan_param *lp;
- if (level == NULL || types == NULL)
+ if (!level || !types)
return -1;
lp = get_lan_param(intf, chan, IPMI_LANP_AUTH_TYPE_ENABLE);
- if (lp == NULL)
+ if (!lp)
return -1;
- if (lp->data == NULL)
+ if (!lp->data)
return -1;
lprintf(LOG_DEBUG, "%-24s: callback=0x%02x user=0x%02x operator=0x%02x admin=0x%02x oem=0x%02x",
@@ -886,16 +942,16 @@ ipmi_lan_set_auth(struct ipmi_intf * intf, uint8_t chan, char * level, char * ty
p = types;
while (p) {
- if (strncasecmp(p, "none", 4) == 0)
+ if (strcasecmp(p, "none") == 0)
authtype |= 1 << IPMI_SESSION_AUTHTYPE_NONE;
- else if (strncasecmp(p, "md2", 3) == 0)
+ else if (strcasecmp(p, "md2") == 0)
authtype |= 1 << IPMI_SESSION_AUTHTYPE_MD2;
- else if (strncasecmp(p, "md5", 3) == 0)
+ else if (strcasecmp(p, "md5") == 0)
authtype |= 1 << IPMI_SESSION_AUTHTYPE_MD5;
- else if ((strncasecmp(p, "password", 8) == 0) ||
- (strncasecmp(p, "key", 3) == 0))
+ else if ((strcasecmp(p, "password") == 0) ||
+ (strcasecmp(p, "key") == 0))
authtype |= 1 << IPMI_SESSION_AUTHTYPE_KEY;
- else if (strncasecmp(p, "oem", 3) == 0)
+ else if (strcasecmp(p, "oem") == 0)
authtype |= 1 << IPMI_SESSION_AUTHTYPE_OEM;
else
lprintf(LOG_WARNING, "Invalid authentication type: %s", p);
@@ -906,13 +962,13 @@ ipmi_lan_set_auth(struct ipmi_intf * intf, uint8_t chan, char * level, char * ty
p = level;
while (p) {
- if (strncasecmp(p, "callback", 8) == 0)
+ if (strcasecmp(p, "callback") == 0)
data[0] = authtype;
- else if (strncasecmp(p, "user", 4) == 0)
+ else if (strcasecmp(p, "user") == 0)
data[1] = authtype;
- else if (strncasecmp(p, "operator", 8) == 0)
+ else if (strcasecmp(p, "operator") == 0)
data[2] = authtype;
- else if (strncasecmp(p, "admin", 5) == 0)
+ else if (strcasecmp(p, "admin") == 0)
data[3] = authtype;
else
lprintf(LOG_WARNING, "Invalid authentication level: %s", p);
@@ -944,7 +1000,7 @@ ipmi_lan_set_password(struct ipmi_intf *intf,
*/
ipmi_intf_session_set_password(intf, (char *)password);
printf("Password %s for user %d\n",
- (password == NULL) ? "cleared" : "set", user_id);
+ password ? "set" : "cleared", user_id);
return 0;
}
@@ -1103,7 +1159,7 @@ ipmi_set_user_access(struct ipmi_intf *intf, uint8_t channel, uint8_t user_id)
static int
-get_cmdline_cipher_suite_priv_data(char * arg, uint8_t * buf)
+get_cmdline_cipher_suite_priv_data(char *arg, uint8_t *buf)
{
int i, ret = 0;
@@ -1180,7 +1236,7 @@ get_cmdline_cipher_suite_priv_data(char * arg, uint8_t * buf)
static int
-get_cmdline_ipaddr(char * arg, uint8_t * buf)
+get_cmdline_ipaddr(char *arg, uint8_t *buf)
{
uint32_t ip1, ip2, ip3, ip4;
if (sscanf(arg,
@@ -1206,18 +1262,27 @@ ipmi_lan_set_vlan_id(struct ipmi_intf *intf, uint8_t chan, char *string)
{
struct lan_param *p;
uint8_t data[2];
- int rc;
+ int rc = -1;
- if (string == NULL) {
+ if (!string) { /* request to disable VLAN */
lprintf(LOG_DEBUG, "Get current VLAN ID from BMC.");
p = get_lan_param(intf, chan, IPMI_LANP_VLAN_ID);
- if (p != NULL && p->data != NULL && p->data_len > 1) {
+ if (p && p->data && p->data_len > 1) {
int id = ((p->data[1] & 0x0f) << 8) + p->data[0];
- if (id < 1 || id > 4094) {
+ if (IPMI_LANP_VLAN_DISABLE == id) {
+ printf("VLAN is already disabled for channel %"
+ PRIu8 "\n", chan);
+ rc = 0;
+ goto out;
+ }
+ if (!IPMI_LANP_IS_VLAN_VALID(id)) {
lprintf(LOG_ERR,
- "Retrieved VLAN ID %i is out of range <1..4094>.",
- id);
- return (-1);
+ "Retrieved VLAN ID %i is out of "
+ "range <%d..%d>.",
+ id,
+ IPMI_LANP_VLAN_ID_MIN,
+ IPMI_LANP_VLAN_ID_MAX);
+ goto out;
}
data[0] = p->data[0];
data[1] = p->data[1] & 0x0F;
@@ -1229,13 +1294,18 @@ ipmi_lan_set_vlan_id(struct ipmi_intf *intf, uint8_t chan, char *string)
else {
int id = 0;
if (str2int(string, &id) != 0) {
- lprintf(LOG_ERR, "Given VLAN ID '%s' is invalid.", string);
- return (-1);
+ lprintf(LOG_ERR,
+ "Given VLAN ID '%s' is invalid.",
+ string);
+ goto out;
}
- if (id < 1 || id > 4094) {
- lprintf(LOG_NOTICE, "VLAN ID must be between 1 and 4094.");
- return (-1);
+ if (!IPMI_LANP_IS_VLAN_VALID(id)) {
+ lprintf(LOG_NOTICE,
+ "VLAN ID must be between %d and %d.",
+ IPMI_LANP_VLAN_ID_MIN,
+ IPMI_LANP_VLAN_ID_MAX);
+ goto out;
}
else {
data[0] = (uint8_t)id;
@@ -1243,6 +1313,8 @@ ipmi_lan_set_vlan_id(struct ipmi_intf *intf, uint8_t chan, char *string)
}
}
rc = set_lan_param(intf, chan, IPMI_LANP_VLAN_ID, data, 2);
+
+out:
return rc;
}
@@ -1270,7 +1342,7 @@ static void
print_lan_set_bad_pass_thresh_usage(void)
{
lprintf(LOG_NOTICE,
-"lan set <chanel> bad_pass_thresh <thresh_num> <1|0> <reset_interval> <lockout_interval>\n"
+"lan set <channel> bad_pass_thresh <thresh_num> <1|0> <reset_interval> <lockout_interval>\n"
" <thresh_num> Bad Password Threshold number.\n"
" <1|0> 1 = generate a Session Audit sensor event.\n"
" 0 = do not generate an event.\n"
@@ -1316,7 +1388,7 @@ get_cmdline_bad_pass_thresh(char *argv[], uint8_t *buf)
}
static int
-ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
+ipmi_lan_set(struct ipmi_intf *intf, int argc, char **argv)
{
uint8_t data[32];
uint8_t chan;
@@ -1327,8 +1399,9 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
return (-1);
}
- if (strncmp(argv[0], "help", 4) == 0 ||
- strncmp(argv[1], "help", 4) == 0) {
+ if (!strcmp(argv[0], "help")
+ || !strcmp(argv[1], "help"))
+ {
print_lan_set_usage();
return 0;
}
@@ -1348,23 +1421,23 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
memset(&data, 0, sizeof(data));
/* set user access */
- if (strncmp(argv[1], "user", 4) == 0) {
+ if (!strcmp(argv[1], "user")) {
rc = ipmi_set_user_access(intf, chan, 1);
}
/* set channel access mode */
- else if (strncmp(argv[1], "access", 6) == 0) {
+ else if (!strcmp(argv[1], "access")) {
if (argc < 3) {
print_lan_set_access_usage();
return (-1);
}
- else if (strncmp(argv[2], "help", 4) == 0) {
+ else if (!strcmp(argv[2], "help")) {
print_lan_set_access_usage();
return 0;
}
- else if (strncmp(argv[2], "on", 2) == 0) {
+ else if (!strcmp(argv[2], "on")) {
rc = ipmi_set_channel_access(intf, chan, 1);
}
- else if (strncmp(argv[2], "off", 3) == 0) {
+ else if (!strcmp(argv[2], "off")) {
rc = ipmi_set_channel_access(intf, chan, 0);
}
else {
@@ -1373,15 +1446,15 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
}
}
/* set ARP control */
- else if (strncmp(argv[1], "arp", 3) == 0) {
+ else if (!strcmp(argv[1], "arp")) {
if (argc < 3) {
print_lan_set_arp_usage();
return (-1);
}
- else if (strncmp(argv[2], "help", 4) == 0) {
+ else if (!strcmp(argv[2], "help")) {
print_lan_set_arp_usage();
}
- else if (strncmp(argv[2], "interval", 8) == 0) {
+ else if (!strcmp(argv[2], "interval")) {
uint8_t interval = 0;
if (str2uchar(argv[3], &interval) != 0) {
lprintf(LOG_ERR, "Given ARP interval '%s' is invalid.", argv[3]);
@@ -1389,28 +1462,28 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
}
rc = lan_set_arp_interval(intf, chan, interval);
}
- else if (strncmp(argv[2], "generate", 8) == 0) {
+ else if (!strcmp(argv[2], "generate")) {
if (argc < 4) {
print_lan_set_arp_usage();
return (-1);
}
- else if (strncmp(argv[3], "on", 2) == 0)
+ else if (!strcmp(argv[3], "on"))
rc = lan_set_arp_generate(intf, chan, 1);
- else if (strncmp(argv[3], "off", 3) == 0)
+ else if (!strcmp(argv[3], "off"))
rc = lan_set_arp_generate(intf, chan, 0);
else {
print_lan_set_arp_usage();
return (-1);
}
}
- else if (strncmp(argv[2], "respond", 7) == 0) {
+ else if (!strcmp(argv[2], "respond")) {
if (argc < 4) {
print_lan_set_arp_usage();
return (-1);
}
- else if (strncmp(argv[3], "on", 2) == 0)
+ else if (!strcmp(argv[3], "on"))
rc = lan_set_arp_respond(intf, chan, 1);
- else if (strncmp(argv[3], "off", 3) == 0)
+ else if (!strcmp(argv[3], "off"))
rc = lan_set_arp_respond(intf, chan, 0);
else {
print_lan_set_arp_usage();
@@ -1422,12 +1495,12 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
}
}
/* set authentication types */
- else if (strncmp(argv[1], "auth", 4) == 0) {
+ else if (!strcmp(argv[1], "auth")) {
if (argc < 3) {
print_lan_set_auth_usage();
return (-1);
}
- else if (strncmp(argv[2], "help", 4) == 0) {
+ else if (!strcmp(argv[2], "help")) {
print_lan_set_auth_usage();
return 0;
} else {
@@ -1435,22 +1508,22 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
}
}
/* ip address source */
- else if (strncmp(argv[1], "ipsrc", 5) == 0) {
+ else if (!strcmp(argv[1], "ipsrc")) {
if (argc < 3) {
print_lan_set_ipsrc_usage();
return (-1);
}
- else if (strncmp(argv[2], "help", 4) == 0) {
+ else if (!strcmp(argv[2], "help")) {
print_lan_set_ipsrc_usage();
return 0;
}
- else if (strncmp(argv[2], "none", 4) == 0)
+ else if (!strcmp(argv[2], "none"))
data[0] = 0;
- else if (strncmp(argv[2], "static", 5) == 0)
+ else if (!strcmp(argv[2], "static"))
data[0] = 1;
- else if (strncmp(argv[2], "dhcp", 4) == 0)
+ else if (!strcmp(argv[2], "dhcp"))
data[0] = 2;
- else if (strncmp(argv[2], "bios", 4) == 0)
+ else if (!strcmp(argv[2], "bios"))
data[0] = 3;
else {
print_lan_set_ipsrc_usage();
@@ -1460,16 +1533,16 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
}
/* session password
* not strictly a lan setting, but its used for lan connections */
- else if (strncmp(argv[1], "password", 8) == 0) {
+ else if (!strcmp(argv[1], "password")) {
rc = ipmi_lan_set_password(intf, 1, argv[2]);
}
/* snmp community string */
- else if (strncmp(argv[1], "snmp", 4) == 0) {
+ else if (!strcmp(argv[1], "snmp")) {
if (argc < 3) {
print_lan_set_snmp_usage();
return (-1);
}
- else if (strncmp(argv[2], "help", 4) == 0) {
+ else if (!strcmp(argv[2], "help")) {
print_lan_set_snmp_usage();
return 0;
} else {
@@ -1480,7 +1553,7 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
}
}
/* ip address */
- else if (strncmp(argv[1], "ipaddr", 6) == 0) {
+ else if (!strcmp(argv[1], "ipaddr")) {
if(argc != 3)
{
print_lan_set_usage();
@@ -1495,7 +1568,7 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
}
}
/* network mask */
- else if (strncmp(argv[1], "netmask", 7) == 0) {
+ else if (!strcmp(argv[1], "netmask")) {
if(argc != 3)
{
print_lan_set_usage();
@@ -1510,7 +1583,7 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
}
}
/* mac address */
- else if (strncmp(argv[1], "macaddr", 7) == 0) {
+ else if (!strcmp(argv[1], "macaddr")) {
if(argc != 3)
{
print_lan_set_usage();
@@ -1525,24 +1598,26 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
}
}
/* default gateway settings */
- else if (strncmp(argv[1], "defgw", 5) == 0) {
+ else if (!strcmp(argv[1], "defgw")) {
if (argc < 4) {
print_lan_set_defgw_usage();
return (-1);
}
- else if (strncmp(argv[2], "help", 4) == 0) {
+ else if (!strcmp(argv[2], "help")) {
print_lan_set_defgw_usage();
return 0;
}
- else if ((strncmp(argv[2], "ipaddr", 5) == 0) &&
- (get_cmdline_ipaddr(argv[3], data) == 0)) {
+ else if (!strcmp(argv[2], "ipaddr")
+ && !get_cmdline_ipaddr(argv[3], data))
+ {
printf("Setting LAN %s to %d.%d.%d.%d\n",
ipmi_lan_params[IPMI_LANP_DEF_GATEWAY_IP].desc,
data[0], data[1], data[2], data[3]);
rc = set_lan_param(intf, chan, IPMI_LANP_DEF_GATEWAY_IP, data, 4);
}
- else if ((strncmp(argv[2], "macaddr", 7) == 0) &&
- (str2mac(argv[3], data) == 0)) {
+ else if (!strcmp(argv[2], "macaddr")
+ && !str2mac(argv[3], data))
+ {
printf("Setting LAN %s to %s\n",
ipmi_lan_params[IPMI_LANP_DEF_GATEWAY_MAC].desc,
mac2str(data));
@@ -1554,24 +1629,25 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
}
}
/* backup gateway settings */
- else if (strncmp(argv[1], "bakgw", 5) == 0) {
+ else if (!strcmp(argv[1], "bakgw")) {
if (argc < 4) {
print_lan_set_bakgw_usage();
return (-1);
}
- else if (strncmp(argv[2], "help", 4) == 0) {
+ else if (!strcmp(argv[2], "help")) {
print_lan_set_bakgw_usage();
return 0;
}
- else if ((strncmp(argv[2], "ipaddr", 5) == 0) &&
- (get_cmdline_ipaddr(argv[3], data) == 0)) {
+ else if (!strcmp(argv[2], "ipaddr")
+ && !get_cmdline_ipaddr(argv[3], data))
+ {
printf("Setting LAN %s to %d.%d.%d.%d\n",
ipmi_lan_params[IPMI_LANP_BAK_GATEWAY_IP].desc,
data[0], data[1], data[2], data[3]);
rc = set_lan_param(intf, chan, IPMI_LANP_BAK_GATEWAY_IP, data, 4);
}
- else if ((strncmp(argv[2], "macaddr", 7) == 0) &&
- (str2mac(argv[3], data) == 0)) {
+ else if (!strcmp(argv[2], "macaddr")
+ && !str2mac(argv[3], data)) {
printf("Setting LAN %s to %s\n",
ipmi_lan_params[IPMI_LANP_BAK_GATEWAY_MAC].desc,
mac2str(data));
@@ -1582,24 +1658,24 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
return -1;
}
}
- else if (strncasecmp(argv[1], "vlan", 4) == 0) {
+ else if (!strcmp(argv[1], "vlan")) {
if (argc < 4) {
print_lan_set_vlan_usage();
return (-1);
}
- else if (strncmp(argv[2], "help", 4) == 0) {
+ else if (!strcmp(argv[2], "help")) {
print_lan_set_vlan_usage();
return 0;
}
- else if (strncasecmp(argv[2], "id", 2) == 0) {
- if (strncasecmp(argv[3], "off", 3) == 0) {
+ else if (!strcmp(argv[2], "id")) {
+ if (!strcmp(argv[3], "off")) {
ipmi_lan_set_vlan_id(intf, chan, NULL);
}
else {
ipmi_lan_set_vlan_id(intf, chan, argv[3]);
}
}
- else if (strncasecmp(argv[2], "priority", 8) == 0) {
+ else if (!strcmp(argv[2], "priority")) {
ipmi_lan_set_vlan_priority(intf, chan, argv[3]);
}
else {
@@ -1608,18 +1684,18 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
}
}
/* set PEF alerting on or off */
- else if (strncasecmp(argv[1], "alert", 5) == 0) {
+ else if (!strcmp(argv[1], "alert")) {
if (argc < 3) {
lprintf(LOG_NOTICE, "LAN set alert must be 'on' or 'off'");
return (-1);
}
- else if (strncasecmp(argv[2], "on", 2) == 0 ||
- strncasecmp(argv[2], "enable", 6) == 0) {
+ else if (!strcmp(argv[2], "on") ||
+ !strcmp(argv[2], "enable")) {
printf("Enabling PEF alerts for LAN channel %d\n", chan);
rc = ipmi_set_alert_enable(intf, chan, 1);
}
- else if (strncasecmp(argv[2], "off", 3) == 0 ||
- strncasecmp(argv[2], "disable", 7) == 0) {
+ else if (!strcmp(argv[2], "off") ||
+ !strcmp(argv[2], "disable")) {
printf("Disabling PEF alerts for LAN channel %d\n", chan);
rc = ipmi_set_alert_enable(intf, chan, 0);
}
@@ -1629,14 +1705,14 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
}
}
/* RMCP+ cipher suite privilege levels */
- else if (strncmp(argv[1], "cipher_privs", 12) == 0)
+ else if (!strcmp(argv[1], "cipher_privs"))
{
if (argc != 3) {
print_lan_set_cipher_privs_usage();
return (-1);
}
- else if ((strncmp(argv[2], "help", 4) == 0) ||
- get_cmdline_cipher_suite_priv_data(argv[2], data))
+ else if (!strcmp(argv[2], "help")
+ || get_cmdline_cipher_suite_priv_data(argv[2], data))
{
print_lan_set_cipher_privs_usage();
return 0;
@@ -1646,9 +1722,9 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
rc = set_lan_param(intf, chan, IPMI_LANP_RMCP_PRIV_LEVELS, data, 9);
}
}
- else if (strncmp(argv[1], "bad_pass_thresh", 15) == 0)
+ else if (!strcmp(argv[1], "bad_pass_thresh"))
{
- if (argc == 3 && strncmp(argv[2], "help", 4) == 0) {
+ if (argc == 3 && !strcmp(argv[2], "help")) {
print_lan_set_bad_pass_thresh_usage();
return 0;
}
@@ -1668,14 +1744,14 @@ ipmi_lan_set(struct ipmi_intf * intf, int argc, char ** argv)
static int
-is_alert_destination(struct ipmi_intf * intf, uint8_t channel, uint8_t alert)
+is_alert_destination(struct ipmi_intf *intf, uint8_t channel, uint8_t alert)
{
- struct lan_param * p;
+ struct lan_param *p;
p = get_lan_param(intf, channel, IPMI_LANP_NUM_DEST);
- if (p == NULL)
+ if (!p)
return 0;
- if (p->data == NULL)
+ if (!p->data)
return 0;
if (alert <= (p->data[0] & 0xf))
@@ -1685,7 +1761,7 @@ is_alert_destination(struct ipmi_intf * intf, uint8_t channel, uint8_t alert)
}
static int
-ipmi_lan_alert_print(struct ipmi_intf * intf, uint8_t channel, uint8_t alert)
+ipmi_lan_alert_print(struct ipmi_intf *intf, uint8_t channel, uint8_t alert)
{
# define PTYPE_LEN 4
# define PADDR_LEN 13
@@ -1695,15 +1771,14 @@ ipmi_lan_alert_print(struct ipmi_intf * intf, uint8_t channel, uint8_t alert)
uint8_t paddr[PADDR_LEN];
lp_ptr = get_lan_param_select(intf, channel, IPMI_LANP_DEST_TYPE, alert);
- if (lp_ptr == NULL || lp_ptr->data == NULL
+ if (!lp_ptr || !lp_ptr->data
|| lp_ptr->data_len < PTYPE_LEN) {
return (-1);
}
memcpy(ptype, lp_ptr->data, PTYPE_LEN);
lp_ptr = get_lan_param_select(intf, channel, IPMI_LANP_DEST_ADDR, alert);
- if (lp_ptr == NULL || lp_ptr->data == NULL
- || lp_ptr->data_len < PADDR_LEN) {
+ if (!lp_ptr || !lp_ptr->data || lp_ptr->data_len < PADDR_LEN) {
return (-1);
}
memcpy(paddr, lp_ptr->data, PADDR_LEN);
@@ -1760,15 +1835,15 @@ ipmi_lan_alert_print(struct ipmi_intf * intf, uint8_t channel, uint8_t alert)
}
static int
-ipmi_lan_alert_print_all(struct ipmi_intf * intf, uint8_t channel)
+ipmi_lan_alert_print_all(struct ipmi_intf *intf, uint8_t channel)
{
int j, ndest;
- struct lan_param * p;
+ struct lan_param *p;
p = get_lan_param(intf, channel, IPMI_LANP_NUM_DEST);
- if (p == NULL)
+ if (!p)
return -1;
- if (p->data == NULL)
+ if (!p->data)
return -1;
ndest = p->data[0] & 0xf;
@@ -1780,10 +1855,10 @@ ipmi_lan_alert_print_all(struct ipmi_intf * intf, uint8_t channel)
}
static int
-ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert,
- int argc, char ** argv)
+ipmi_lan_alert_set(struct ipmi_intf *intf, uint8_t chan, uint8_t alert,
+ int argc, char **argv)
{
- struct lan_param * p;
+ struct lan_param *p;
uint8_t data[32], temp[32];
int rc = 0;
@@ -1792,8 +1867,9 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert,
return (-1);
}
- if (strncmp(argv[0], "help", 4) == 0 ||
- strncmp(argv[1], "help", 4) == 0) {
+ if (!strcmp(argv[0], "help")
+ || !strcmp(argv[1], "help"))
+ {
print_lan_alert_set_usage();
return 0;
}
@@ -1802,11 +1878,11 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert,
memset(temp, 0, sizeof(temp));
/* alert destination ip address */
- if (strncasecmp(argv[0], "ipaddr", 6) == 0 &&
+ if (strcasecmp(argv[0], "ipaddr") == 0 &&
(get_cmdline_ipaddr(argv[1], temp) == 0)) {
/* get current parameter */
p = get_lan_param_select(intf, chan, IPMI_LANP_DEST_ADDR, alert);
- if (p == NULL) {
+ if (!p) {
return (-1);
}
memcpy(data, p->data, __min(p->data_len, sizeof(data)));
@@ -1817,11 +1893,11 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert,
rc = set_lan_param_nowait(intf, chan, IPMI_LANP_DEST_ADDR, data, p->data_len);
}
/* alert destination mac address */
- else if (strncasecmp(argv[0], "macaddr", 7) == 0 &&
+ else if (strcasecmp(argv[0], "macaddr") == 0 &&
(str2mac(argv[1], temp) == 0)) {
/* get current parameter */
p = get_lan_param_select(intf, chan, IPMI_LANP_DEST_ADDR, alert);
- if (p == NULL) {
+ if (!p) {
return (-1);
}
memcpy(data, p->data, __min(p->data_len, sizeof(data)));
@@ -1832,21 +1908,21 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert,
rc = set_lan_param_nowait(intf, chan, IPMI_LANP_DEST_ADDR, data, p->data_len);
}
/* alert destination gateway selector */
- else if (strncasecmp(argv[0], "gateway", 7) == 0) {
+ else if (strcasecmp(argv[0], "gateway") == 0) {
/* get current parameter */
p = get_lan_param_select(intf, chan, IPMI_LANP_DEST_ADDR, alert);
- if (p == NULL) {
+ if (!p) {
return (-1);
}
memcpy(data, p->data, __min(p->data_len, sizeof(data)));
- if (strncasecmp(argv[1], "def", 3) == 0 ||
- strncasecmp(argv[1], "default", 7) == 0) {
+ if (strcasecmp(argv[1], "def") == 0 ||
+ strcasecmp(argv[1], "default") == 0) {
printf("Setting LAN Alert %d to use Default Gateway\n", alert);
data[2] = 0;
}
- else if (strncasecmp(argv[1], "bak", 3) == 0 ||
- strncasecmp(argv[1], "backup", 6) == 0) {
+ else if (strcasecmp(argv[1], "bak") == 0 ||
+ strcasecmp(argv[1], "backup") == 0) {
printf("Setting LAN Alert %d to use Backup Gateway\n", alert);
data[2] = 1;
}
@@ -1858,21 +1934,21 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert,
rc = set_lan_param_nowait(intf, chan, IPMI_LANP_DEST_ADDR, data, p->data_len);
}
/* alert acknowledgement */
- else if (strncasecmp(argv[0], "ack", 3) == 0) {
+ else if (strcasecmp(argv[0], "ack") == 0) {
/* get current parameter */
p = get_lan_param_select(intf, chan, IPMI_LANP_DEST_TYPE, alert);
- if (p == NULL) {
+ if (!p) {
return (-1);
}
memcpy(data, p->data, __min(p->data_len, sizeof(data)));
- if (strncasecmp(argv[1], "on", 2) == 0 ||
- strncasecmp(argv[1], "yes", 3) == 0) {
+ if (strcasecmp(argv[1], "on") == 0 ||
+ strcasecmp(argv[1], "yes") == 0) {
printf("Setting LAN Alert %d to Acknowledged\n", alert);
data[1] |= 0x80;
}
- else if (strncasecmp(argv[1], "off", 3) == 0 ||
- strncasecmp(argv[1], "no", 2) == 0) {
+ else if (strcasecmp(argv[1], "off") == 0 ||
+ strcasecmp(argv[1], "no") == 0) {
printf("Setting LAN Alert %d to Unacknowledged\n", alert);
data[1] &= ~0x80;
}
@@ -1883,24 +1959,24 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert,
rc = set_lan_param_nowait(intf, chan, IPMI_LANP_DEST_TYPE, data, p->data_len);
}
/* alert destination type */
- else if (strncasecmp(argv[0], "type", 4) == 0) {
+ else if (strcasecmp(argv[0], "type") == 0) {
/* get current parameter */
p = get_lan_param_select(intf, chan, IPMI_LANP_DEST_TYPE, alert);
- if (p == NULL) {
+ if (!p) {
return (-1);
}
memcpy(data, p->data, __min(p->data_len, sizeof(data)));
- if (strncasecmp(argv[1], "pet", 3) == 0) {
+ if (strcasecmp(argv[1], "pet") == 0) {
printf("Setting LAN Alert %d destination to PET Trap\n", alert);
data[1] &= ~0x07;
}
- else if (strncasecmp(argv[1], "oem1", 4) == 0) {
+ else if (strcasecmp(argv[1], "oem1") == 0) {
printf("Setting LAN Alert %d destination to OEM 1\n", alert);
data[1] &= ~0x07;
data[1] |= 0x06;
}
- else if (strncasecmp(argv[1], "oem2", 4) == 0) {
+ else if (strcasecmp(argv[1], "oem2") == 0) {
printf("Setting LAN Alert %d destination to OEM 2\n", alert);
data[1] |= 0x07;
}
@@ -1911,10 +1987,10 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert,
rc = set_lan_param_nowait(intf, chan, IPMI_LANP_DEST_TYPE, data, p->data_len);
}
/* alert acknowledge timeout or retry interval */
- else if (strncasecmp(argv[0], "time", 4) == 0) {
+ else if (strcasecmp(argv[0], "time") == 0) {
/* get current parameter */
p = get_lan_param_select(intf, chan, IPMI_LANP_DEST_TYPE, alert);
- if (p == NULL) {
+ if (!p) {
return (-1);
}
memcpy(data, p->data, __min(p->data_len, sizeof(data)));
@@ -1927,10 +2003,10 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert,
rc = set_lan_param_nowait(intf, chan, IPMI_LANP_DEST_TYPE, data, p->data_len);
}
/* number of retries */
- else if (strncasecmp(argv[0], "retry", 5) == 0) {
+ else if (strcasecmp(argv[0], "retry") == 0) {
/* get current parameter */
p = get_lan_param_select(intf, chan, IPMI_LANP_DEST_TYPE, alert);
- if (p == NULL) {
+ if (!p) {
return (-1);
}
memcpy(data, p->data, __min(p->data_len, sizeof(data)));
@@ -1952,7 +2028,7 @@ ipmi_lan_alert_set(struct ipmi_intf * intf, uint8_t chan, uint8_t alert,
}
static int
-ipmi_lan_alert(struct ipmi_intf * intf, int argc, char ** argv)
+ipmi_lan_alert(struct ipmi_intf *intf, int argc, char **argv)
{
uint8_t alert;
uint8_t channel = 1;
@@ -1962,14 +2038,14 @@ ipmi_lan_alert(struct ipmi_intf * intf, int argc, char ** argv)
print_lan_alert_set_usage();
return (-1);
}
- else if (strncasecmp(argv[0], "help", 4) == 0) {
+ else if (strcasecmp(argv[0], "help") == 0) {
print_lan_alert_print_usage();
print_lan_alert_set_usage();
return 0;
}
/* alert print [channel] [alert] */
- if (strncasecmp(argv[0], "print", 5) == 0) {
+ if (strcasecmp(argv[0], "print") == 0) {
if (argc < 2) {
channel = find_lan_channel(intf, 1);
if (!is_lan_channel(intf, channel)) {
@@ -1979,7 +2055,7 @@ ipmi_lan_alert(struct ipmi_intf * intf, int argc, char ** argv)
return ipmi_lan_alert_print_all(intf, channel);
}
- if (strncasecmp(argv[1], "help", 4) == 0) {
+ if (strcasecmp(argv[1], "help") == 0) {
print_lan_alert_print_usage();
return 0;
}
@@ -2008,12 +2084,12 @@ ipmi_lan_alert(struct ipmi_intf * intf, int argc, char ** argv)
}
/* alert set <channel> <alert> [option] */
- if (strncasecmp(argv[0], "set", 3) == 0) {
+ if (strcasecmp(argv[0], "set") == 0) {
if (argc < 5) {
print_lan_alert_set_usage();
return (-1);
}
- else if (strncasecmp(argv[1], "help", 4) == 0) {
+ else if (strcasecmp(argv[1], "help") == 0) {
print_lan_alert_set_usage();
return 0;
}
@@ -2044,10 +2120,10 @@ ipmi_lan_alert(struct ipmi_intf * intf, int argc, char ** argv)
static int
-ipmi_lan_stats_get(struct ipmi_intf * intf, uint8_t chan)
+ipmi_lan_stats_get(struct ipmi_intf *intf, uint8_t chan)
{
int rc = 0;
- struct ipmi_rs * rsp;
+ struct ipmi_rs *rsp;
struct ipmi_rq req;
uint8_t msg_data[2];
uint16_t statsTemp;
@@ -2069,14 +2145,16 @@ ipmi_lan_stats_get(struct ipmi_intf * intf, uint8_t chan)
req.msg.data_len = 2;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_ERR, "Get LAN Stats command failed");
return (-1);
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_ERR, "Get LAN Stats command failed: %s",
- val2str(rsp->ccode, completion_code_vals));
+ specific_val2str(rsp->ccode,
+ get_lan_cc_vals,
+ completion_code_vals));
return (-1);
}
@@ -2122,10 +2200,10 @@ ipmi_lan_stats_get(struct ipmi_intf * intf, uint8_t chan)
static int
-ipmi_lan_stats_clear(struct ipmi_intf * intf, uint8_t chan)
+ipmi_lan_stats_clear(struct ipmi_intf *intf, uint8_t chan)
{
int rc = 0;
- struct ipmi_rs * rsp;
+ struct ipmi_rs *rsp;
struct ipmi_rq req;
uint8_t msg_data[2];
@@ -2145,14 +2223,16 @@ ipmi_lan_stats_clear(struct ipmi_intf * intf, uint8_t chan)
req.msg.data_len = 2;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
lprintf(LOG_INFO, "Get LAN Stats command failed");
return (-1);
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
lprintf(LOG_INFO, "Get LAN Stats command failed: %s",
- val2str(rsp->ccode, completion_code_vals));
+ specific_val2str(rsp->ccode,
+ get_lan_cc_vals,
+ completion_code_vals));
return (-1);
}
@@ -2412,7 +2492,7 @@ print_lan_usage(void)
int
-ipmi_lanp_main(struct ipmi_intf * intf, int argc, char ** argv)
+ipmi_lanp_main(struct ipmi_intf *intf, int argc, char **argv)
{
int rc = 0;
uint8_t chan = 0;
@@ -2420,13 +2500,13 @@ ipmi_lanp_main(struct ipmi_intf * intf, int argc, char ** argv)
if (argc == 0) {
print_lan_usage();
return (-1);
- } else if (strncmp(argv[0], "help", 4) == 0) {
+ } else if (!strcmp(argv[0], "help")) {
print_lan_usage();
return 0;
}
- if (strncmp(argv[0], "printconf", 9) == 0 ||
- strncmp(argv[0], "print", 5) == 0)
+ if (!strcmp(argv[0], "printconf")
+ || !strcmp(argv[0], "print"))
{
if (argc > 2) {
print_lan_usage();
@@ -2444,11 +2524,11 @@ ipmi_lanp_main(struct ipmi_intf * intf, int argc, char ** argv)
return (-1);
}
rc = ipmi_lan_print(intf, chan);
- } else if (strncmp(argv[0], "set", 3) == 0) {
+ } else if (!strcmp(argv[0], "set")) {
rc = ipmi_lan_set(intf, argc-1, &(argv[1]));
- } else if (strncmp(argv[0], "alert", 5) == 0) {
+ } else if (!strcmp(argv[0], "alert")) {
rc = ipmi_lan_alert(intf, argc-1, &(argv[1]));
- } else if (strncmp(argv[0], "stats", 5) == 0) {
+ } else if (!strcmp(argv[0], "stats")) {
if (argc < 2) {
print_lan_usage();
return (-1);
@@ -2464,9 +2544,9 @@ ipmi_lanp_main(struct ipmi_intf * intf, int argc, char ** argv)
lprintf(LOG_ERR, "Invalid channel: %d", chan);
return (-1);
}
- if (strncmp(argv[1], "get", 3) == 0) {
+ if (!strcmp(argv[1], "get")) {
rc = ipmi_lan_stats_get(intf, chan);
- } else if (strncmp(argv[1], "clear", 5) == 0) {
+ } else if (!strcmp(argv[1], "clear")) {
rc = ipmi_lan_stats_clear(intf, chan);
} else {
print_lan_usage();