[dpdk-dev,4/5] net/bnxt: check if MAC address is all zeros
Checks
Commit Message
In certain cases the MAC address of a port could be all zeros.
Catch it early, log a message and fail the initiaization.
Signed-off-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
---
drivers/net/bnxt/bnxt_ethdev.c | 10 ++++++++++
drivers/net/bnxt/bnxt_filter.c | 2 +-
drivers/net/bnxt/bnxt_filter.h | 1 +
3 files changed, 12 insertions(+), 1 deletion(-)
Comments
On 1/22/2018 6:20 AM, Ajit Khaparde wrote:
> In certain cases the MAC address of a port could be all zeros.
> Catch it early, log a message and fail the initiaization.
>
> Signed-off-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
<...>
> @@ -3247,6 +3247,16 @@ bnxt_dev_init(struct rte_eth_dev *eth_dev)
> rc = -ENOMEM;
> goto error_free;
> }
> +
> + if (check_zero_bytes(bp->dflt_mac_addr, ETHER_ADDR_LEN)) {
There is already a function is_zero_ether_addr() which can be used here that
prevents exposing your check_zero_bytes() function, up to you which one to use.
@@ -3247,6 +3247,16 @@ bnxt_dev_init(struct rte_eth_dev *eth_dev)
rc = -ENOMEM;
goto error_free;
}
+
+ if (check_zero_bytes(bp->dflt_mac_addr, ETHER_ADDR_LEN)) {
+ PMD_DRV_LOG(ERR,
+ "Invalid MAC addr %02X:%02X:%02X:%02X:%02X:%02X\n",
+ bp->dflt_mac_addr[0], bp->dflt_mac_addr[1],
+ bp->dflt_mac_addr[2], bp->dflt_mac_addr[3],
+ bp->dflt_mac_addr[4], bp->dflt_mac_addr[5]);
+ rc = -EINVAL;
+ goto error_free;
+ }
/* Copy the permanent MAC from the qcap response address now. */
memcpy(bp->mac_addr, bp->dflt_mac_addr, sizeof(bp->mac_addr));
memcpy(ð_dev->data->mac_addrs[0], bp->mac_addr, ETHER_ADDR_LEN);
@@ -250,7 +250,7 @@ nxt_non_void_action(const struct rte_flow_action *cur)
}
}
-static inline int check_zero_bytes(const uint8_t *bytes, int len)
+int check_zero_bytes(const uint8_t *bytes, int len)
{
int i;
for (i = 0; i < len; i++)
@@ -97,6 +97,7 @@ struct bnxt_filter_info *bnxt_get_unused_filter(struct bnxt *bp);
void bnxt_free_filter(struct bnxt *bp, struct bnxt_filter_info *filter);
struct bnxt_filter_info *bnxt_get_l2_filter(struct bnxt *bp,
struct bnxt_filter_info *nf, struct bnxt_vnic_info *vnic);
+int check_zero_bytes(const uint8_t *bytes, int len);
#define NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_MACADDR \
HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_MACADDR