From 0b993fd4508b06ff9427ccd947d7813965155925 Mon Sep 17 00:00:00 2001 From: Rajashekar Gade Reddy Date: Tue, 24 Dec 2019 16:37:15 +0530 Subject: Fix cc issue in setLan cmd for MAC addr parametr. Issue: set lan command for MAC address parameter returns invalid completion code for invalid MAC address. Fix: added proper conditional check. Tested: Note: While setting the mac addr using "ipmitool lan set 1 macaddr " internaly tool valiadtes the completion code and shows generic error. Previouly the completion code is 0XFF(unspecified error) and now it returns 0xCC(Invalid data field in request). // setting mac addr to 00:00:00:00:00:00(invalid) ipmitool lan set 1 macaddr "00:00:00:00:00:00" Setting LAN MAC Address to 00:00:00:00:00:00 LAN Parameter Data does not match! Write may have failed. // setting mac addr to FF:FF:FF:FF:FF:FF(invalid) ipmitool lan set 1 macaddr "FF:FF:FF:FF:FF:FF" Setting LAN MAC Address to ff:ff:ff:ff:ff:ff LAN Parameter Data does not match! Write may have failed. // setting mac addr to "2a:6c:72:42:f3:a4"(valid) ipmitool lan set 1 macaddr "2a:6c:72:42:f3:a4" Setting LAN MAC Address to 2a:6c:72:42:f3:a4 Signed-off-by: Rajashekar Gade Reddy Change-Id: I4de54e68a7bb5ff2c64f515e40d06c59535825e5 --- transporthandler.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/transporthandler.cpp b/transporthandler.cpp index c8dccb3..d7eef14 100644 --- a/transporthandler.cpp +++ b/transporthandler.cpp @@ -1313,6 +1313,30 @@ RspType getLanOem(uint8_t channel, uint8_t parameter, { return response(ccParamNotSupported); } +/** + * @brief is MAC address valid. + * + * This function checks whether the MAC address is valid or not. + * + * @param[in] mac - MAC address. + * @return true if MAC address is valid else retun false. + **/ +bool isValidMACAddress(const ether_addr& mac) +{ + // check if mac address is empty + if (equal(mac, ether_addr{})) + { + return false; + } + // we accept only unicast MAC addresses and same thing has been checked in + // phosphor-network layer. If the least significant bit of the first octet + // is set to 1, it is multicast MAC else it is unicast MAC address. + if (mac.ether_addr_octet[0] & 1) + { + return false; + } + return true; +} RspType<> setLan(uint4_t channelBits, uint4_t, uint8_t parameter, message::Payload& req) @@ -1426,6 +1450,11 @@ RspType<> setLan(uint4_t channelBits, uint4_t, uint8_t parameter, return responseReqDataLenInvalid(); } copyInto(mac, bytes); + + if (!isValidMACAddress(mac)) + { + return responseInvalidFieldRequest(); + } channelCall(channel, mac); return responseSuccess(); } -- cgit v1.2.1