提交 19741023 编写于 作者: Y Yufeng Mo 提交者: Yang Yingliang

net: hns3: format the output of the MAC address

driver inclusion
category: cleanup
bugzilla: NA
CVE: NA

----------------------------

Printing the whole MAC addresse may bring security risks. Therefore,
the MAC address is partially encrypted to improve security.
Signed-off-by: NYufeng Mo <moyufeng@huawei.com>
Signed-off-by: NYonglong Liu <liuyonglong@huawei.com>
Reviewed-by: NYongxin Li <liyongxin1@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 7b351323
...@@ -604,6 +604,20 @@ struct hnae3_ae_algo { ...@@ -604,6 +604,20 @@ struct hnae3_ae_algo {
#define HNAE3_INT_NAME_LEN 32 #define HNAE3_INT_NAME_LEN 32
#define HNAE3_ITR_COUNTDOWN_START 100 #define HNAE3_ITR_COUNTDOWN_START 100
#define HNAE3_FORMAT_MAC_ADDR_LEN 18
#define HNAE3_FORMAT_MAC_ADDR_OFFSET_0 0
#define HNAE3_FORMAT_MAC_ADDR_OFFSET_4 4
#define HNAE3_FORMAT_MAC_ADDR_OFFSET_5 5
static inline void hnae3_format_mac_addr(char *format_mac_addr,
const u8 *mac_addr)
{
snprintf(format_mac_addr, HNAE3_FORMAT_MAC_ADDR_LEN, "%02x:**:**:**:%02x:%02x",
mac_addr[HNAE3_FORMAT_MAC_ADDR_OFFSET_0],
mac_addr[HNAE3_FORMAT_MAC_ADDR_OFFSET_4],
mac_addr[HNAE3_FORMAT_MAC_ADDR_OFFSET_5]);
}
struct hnae3_tc_info { struct hnae3_tc_info {
u16 tqp_offset; /* TQP offset from base TQP */ u16 tqp_offset; /* TQP offset from base TQP */
u16 tqp_count; /* Total TQPs */ u16 tqp_count; /* Total TQPs */
......
...@@ -1471,6 +1471,8 @@ netdev_tx_t hns3_nic_net_xmit(struct sk_buff *skb, struct net_device *netdev) ...@@ -1471,6 +1471,8 @@ netdev_tx_t hns3_nic_net_xmit(struct sk_buff *skb, struct net_device *netdev)
static int hns3_nic_net_set_mac_address(struct net_device *netdev, void *p) static int hns3_nic_net_set_mac_address(struct net_device *netdev, void *p)
{ {
char format_mac_addr_perm[HNAE3_FORMAT_MAC_ADDR_LEN];
char format_mac_addr_sa[HNAE3_FORMAT_MAC_ADDR_LEN];
struct hnae3_handle *h = hns3_get_handle(netdev); struct hnae3_handle *h = hns3_get_handle(netdev);
struct sockaddr *mac_addr = p; struct sockaddr *mac_addr = p;
int ret; int ret;
...@@ -1479,8 +1481,9 @@ static int hns3_nic_net_set_mac_address(struct net_device *netdev, void *p) ...@@ -1479,8 +1481,9 @@ static int hns3_nic_net_set_mac_address(struct net_device *netdev, void *p)
return -EADDRNOTAVAIL; return -EADDRNOTAVAIL;
if (ether_addr_equal(netdev->dev_addr, mac_addr->sa_data)) { if (ether_addr_equal(netdev->dev_addr, mac_addr->sa_data)) {
netdev_info(netdev, "already using mac address %pM\n", hnae3_format_mac_addr(format_mac_addr_sa, mac_addr->sa_data);
mac_addr->sa_data); netdev_info(netdev, "already using mac address %s\n",
format_mac_addr_sa);
return 0; return 0;
} }
...@@ -1489,8 +1492,10 @@ static int hns3_nic_net_set_mac_address(struct net_device *netdev, void *p) ...@@ -1489,8 +1492,10 @@ static int hns3_nic_net_set_mac_address(struct net_device *netdev, void *p)
*/ */
if (!hns3_is_phys_func(h->pdev) && if (!hns3_is_phys_func(h->pdev) &&
!is_zero_ether_addr(netdev->perm_addr)) { !is_zero_ether_addr(netdev->perm_addr)) {
netdev_err(netdev, "has permanent MAC %pM, user MAC %pM not allow\n", hnae3_format_mac_addr(format_mac_addr_perm, netdev->perm_addr);
netdev->perm_addr, mac_addr->sa_data); hnae3_format_mac_addr(format_mac_addr_sa, mac_addr->sa_data);
netdev_err(netdev, "has permanent MAC %s, user MAC %s not allow\n",
format_mac_addr_perm, format_mac_addr_sa);
return -EPERM; return -EPERM;
} }
...@@ -2022,14 +2027,16 @@ static int hns3_nic_set_vf_rate(struct net_device *ndev, int vf, ...@@ -2022,14 +2027,16 @@ static int hns3_nic_set_vf_rate(struct net_device *ndev, int vf,
static int hns3_nic_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac) static int hns3_nic_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac)
{ {
struct hnae3_handle *h = hns3_get_handle(netdev); struct hnae3_handle *h = hns3_get_handle(netdev);
char format_mac_addr[HNAE3_FORMAT_MAC_ADDR_LEN];
if (!h->ae_algo->ops->set_vf_mac) if (!h->ae_algo->ops->set_vf_mac)
return -EOPNOTSUPP; return -EOPNOTSUPP;
if (is_multicast_ether_addr(mac)) { if (is_multicast_ether_addr(mac)) {
hnae3_format_mac_addr(format_mac_addr, mac);
netdev_err(netdev, netdev_err(netdev,
"Invalid MAC:%pM specified. Could not set MAC\n", "Invalid MAC:%s specified. Could not set MAC\n",
mac); format_mac_addr);
return -EINVAL; return -EINVAL;
} }
...@@ -3960,6 +3967,7 @@ int hns3_uninit_all_ring(struct hns3_nic_priv *priv) ...@@ -3960,6 +3967,7 @@ int hns3_uninit_all_ring(struct hns3_nic_priv *priv)
static int hns3_init_mac_addr(struct net_device *netdev) static int hns3_init_mac_addr(struct net_device *netdev)
{ {
struct hns3_nic_priv *priv = netdev_priv(netdev); struct hns3_nic_priv *priv = netdev_priv(netdev);
char format_mac_addr[HNAE3_FORMAT_MAC_ADDR_LEN];
struct hnae3_handle *h = priv->ae_handle; struct hnae3_handle *h = priv->ae_handle;
u8 mac_addr_temp[ETH_ALEN] = { 0 }; u8 mac_addr_temp[ETH_ALEN] = { 0 };
int ret = 0; int ret = 0;
...@@ -3970,8 +3978,9 @@ static int hns3_init_mac_addr(struct net_device *netdev) ...@@ -3970,8 +3978,9 @@ static int hns3_init_mac_addr(struct net_device *netdev)
/* Check if the MAC address is valid, if not get a random one */ /* Check if the MAC address is valid, if not get a random one */
if (!is_valid_ether_addr(mac_addr_temp)) { if (!is_valid_ether_addr(mac_addr_temp)) {
eth_hw_addr_random(netdev); eth_hw_addr_random(netdev);
dev_warn(priv->dev, "using random MAC address %pM\n", hnae3_format_mac_addr(format_mac_addr, netdev->dev_addr);
netdev->dev_addr); dev_warn(priv->dev, "using random MAC address %s\n",
format_mac_addr);
} else if (!ether_addr_equal(netdev->dev_addr, mac_addr_temp)) { } else if (!ether_addr_equal(netdev->dev_addr, mac_addr_temp)) {
ether_addr_copy(netdev->dev_addr, mac_addr_temp); ether_addr_copy(netdev->dev_addr, mac_addr_temp);
ether_addr_copy(netdev->perm_addr, mac_addr_temp); ether_addr_copy(netdev->perm_addr, mac_addr_temp);
...@@ -4031,8 +4040,10 @@ static void hns3_client_stop(struct hnae3_handle *handle) ...@@ -4031,8 +4040,10 @@ static void hns3_client_stop(struct hnae3_handle *handle)
static void hns3_info_show(struct hns3_nic_priv *priv) static void hns3_info_show(struct hns3_nic_priv *priv)
{ {
struct hnae3_knic_private_info *kinfo = &priv->ae_handle->kinfo; struct hnae3_knic_private_info *kinfo = &priv->ae_handle->kinfo;
char format_mac_addr[HNAE3_FORMAT_MAC_ADDR_LEN];
dev_info(priv->dev, "MAC address: %pM\n", priv->netdev->dev_addr); hnae3_format_mac_addr(format_mac_addr, priv->netdev->dev_addr);
dev_info(priv->dev, "MAC address: %s\n", format_mac_addr);
dev_info(priv->dev, "Task queue pairs numbers: %u\n", kinfo->num_tqps); dev_info(priv->dev, "Task queue pairs numbers: %u\n", kinfo->num_tqps);
dev_info(priv->dev, "RSS size: %u\n", kinfo->rss_size); dev_info(priv->dev, "RSS size: %u\n", kinfo->rss_size);
dev_info(priv->dev, "Allocated RSS size: %u\n", kinfo->req_rss_size); dev_info(priv->dev, "Allocated RSS size: %u\n", kinfo->req_rss_size);
......
...@@ -7531,6 +7531,7 @@ static int hclge_add_uc_addr(struct hnae3_handle *handle, ...@@ -7531,6 +7531,7 @@ static int hclge_add_uc_addr(struct hnae3_handle *handle,
int hclge_add_uc_addr_common(struct hclge_vport *vport, int hclge_add_uc_addr_common(struct hclge_vport *vport,
const unsigned char *addr) const unsigned char *addr)
{ {
char format_mac_addr[HNAE3_FORMAT_MAC_ADDR_LEN];
struct hclge_dev *hdev = vport->back; struct hclge_dev *hdev = vport->back;
struct hclge_mac_vlan_tbl_entry_cmd req; struct hclge_mac_vlan_tbl_entry_cmd req;
u16 egress_port = 0; u16 egress_port = 0;
...@@ -7540,9 +7541,10 @@ int hclge_add_uc_addr_common(struct hclge_vport *vport, ...@@ -7540,9 +7541,10 @@ int hclge_add_uc_addr_common(struct hclge_vport *vport,
if (is_zero_ether_addr(addr) || if (is_zero_ether_addr(addr) ||
is_broadcast_ether_addr(addr) || is_broadcast_ether_addr(addr) ||
is_multicast_ether_addr(addr)) { is_multicast_ether_addr(addr)) {
hnae3_format_mac_addr(format_mac_addr, addr);
dev_err(&hdev->pdev->dev, dev_err(&hdev->pdev->dev,
"Set_uc mac err! invalid mac:%pM. is_zero:%d,is_br=%d,is_mul=%d\n", "Set_uc mac err! invalid mac:%s. is_zero:%d,is_br=%d,is_mul=%d\n",
addr, is_zero_ether_addr(addr), format_mac_addr, is_zero_ether_addr(addr),
is_broadcast_ether_addr(addr), is_broadcast_ether_addr(addr),
is_multicast_ether_addr(addr)); is_multicast_ether_addr(addr));
return -EINVAL; return -EINVAL;
...@@ -7587,6 +7589,7 @@ static int hclge_rm_uc_addr(struct hnae3_handle *handle, ...@@ -7587,6 +7589,7 @@ static int hclge_rm_uc_addr(struct hnae3_handle *handle,
int hclge_rm_uc_addr_common(struct hclge_vport *vport, int hclge_rm_uc_addr_common(struct hclge_vport *vport,
const unsigned char *addr) const unsigned char *addr)
{ {
char format_mac_addr[HNAE3_FORMAT_MAC_ADDR_LEN];
struct hclge_dev *hdev = vport->back; struct hclge_dev *hdev = vport->back;
struct hclge_mac_vlan_tbl_entry_cmd req; struct hclge_mac_vlan_tbl_entry_cmd req;
int ret; int ret;
...@@ -7595,8 +7598,9 @@ int hclge_rm_uc_addr_common(struct hclge_vport *vport, ...@@ -7595,8 +7598,9 @@ int hclge_rm_uc_addr_common(struct hclge_vport *vport,
if (is_zero_ether_addr(addr) || if (is_zero_ether_addr(addr) ||
is_broadcast_ether_addr(addr) || is_broadcast_ether_addr(addr) ||
is_multicast_ether_addr(addr)) { is_multicast_ether_addr(addr)) {
dev_dbg(&hdev->pdev->dev, "Remove mac err! invalid mac:%pM.\n", hnae3_format_mac_addr(format_mac_addr, addr);
addr); dev_dbg(&hdev->pdev->dev, "Remove mac err! invalid mac:%s.\n",
format_mac_addr);
return -EINVAL; return -EINVAL;
} }
...@@ -7626,6 +7630,7 @@ static int hclge_add_mc_addr(struct hnae3_handle *handle, ...@@ -7626,6 +7630,7 @@ static int hclge_add_mc_addr(struct hnae3_handle *handle,
int hclge_add_mc_addr_common(struct hclge_vport *vport, int hclge_add_mc_addr_common(struct hclge_vport *vport,
const unsigned char *addr) const unsigned char *addr)
{ {
char format_mac_addr[HNAE3_FORMAT_MAC_ADDR_LEN];
struct hclge_dev *hdev = vport->back; struct hclge_dev *hdev = vport->back;
struct hclge_mac_vlan_tbl_entry_cmd req; struct hclge_mac_vlan_tbl_entry_cmd req;
struct hclge_desc desc[3]; struct hclge_desc desc[3];
...@@ -7633,9 +7638,10 @@ int hclge_add_mc_addr_common(struct hclge_vport *vport, ...@@ -7633,9 +7638,10 @@ int hclge_add_mc_addr_common(struct hclge_vport *vport,
/* mac addr check */ /* mac addr check */
if (!is_multicast_ether_addr(addr)) { if (!is_multicast_ether_addr(addr)) {
hnae3_format_mac_addr(format_mac_addr, addr);
dev_err(&hdev->pdev->dev, dev_err(&hdev->pdev->dev,
"Add mc mac err! invalid mac:%pM.\n", "Add mc mac err! invalid mac:%s.\n",
addr); format_mac_addr);
return -EINVAL; return -EINVAL;
} }
memset(&req, 0, sizeof(req)); memset(&req, 0, sizeof(req));
...@@ -7673,6 +7679,7 @@ static int hclge_rm_mc_addr(struct hnae3_handle *handle, ...@@ -7673,6 +7679,7 @@ static int hclge_rm_mc_addr(struct hnae3_handle *handle,
int hclge_rm_mc_addr_common(struct hclge_vport *vport, int hclge_rm_mc_addr_common(struct hclge_vport *vport,
const unsigned char *addr) const unsigned char *addr)
{ {
char format_mac_addr[HNAE3_FORMAT_MAC_ADDR_LEN];
struct hclge_dev *hdev = vport->back; struct hclge_dev *hdev = vport->back;
struct hclge_mac_vlan_tbl_entry_cmd req; struct hclge_mac_vlan_tbl_entry_cmd req;
enum hclge_cmd_status status; enum hclge_cmd_status status;
...@@ -7680,9 +7687,10 @@ int hclge_rm_mc_addr_common(struct hclge_vport *vport, ...@@ -7680,9 +7687,10 @@ int hclge_rm_mc_addr_common(struct hclge_vport *vport,
/* mac addr check */ /* mac addr check */
if (!is_multicast_ether_addr(addr)) { if (!is_multicast_ether_addr(addr)) {
hnae3_format_mac_addr(format_mac_addr, addr);
dev_dbg(&hdev->pdev->dev, dev_dbg(&hdev->pdev->dev,
"Remove mc mac err! invalid mac:%pM.\n", "Remove mc mac err! invalid mac:%s.\n",
addr); format_mac_addr);
return -EINVAL; return -EINVAL;
} }
...@@ -8096,16 +8104,18 @@ static int hclge_set_vf_mac(struct hnae3_handle *handle, int vf, ...@@ -8096,16 +8104,18 @@ static int hclge_set_vf_mac(struct hnae3_handle *handle, int vf,
u8 *mac_addr) u8 *mac_addr)
{ {
struct hclge_vport *vport = hclge_get_vport(handle); struct hclge_vport *vport = hclge_get_vport(handle);
char format_mac_addr[HNAE3_FORMAT_MAC_ADDR_LEN];
struct hclge_dev *hdev = vport->back; struct hclge_dev *hdev = vport->back;
vport = hclge_get_vf_vport(hdev, vf); vport = hclge_get_vf_vport(hdev, vf);
if (!vport) if (!vport)
return -EINVAL; return -EINVAL;
hnae3_format_mac_addr(format_mac_addr, mac_addr);
if (ether_addr_equal(mac_addr, vport->vf_info.mac)) { if (ether_addr_equal(mac_addr, vport->vf_info.mac)) {
dev_info(&hdev->pdev->dev, dev_info(&hdev->pdev->dev,
"Specified MAC(=%pM) is same as before, no change committed!\n", "Specified MAC(=%s) is same as before, no change committed!\n",
mac_addr); format_mac_addr);
return 0; return 0;
} }
...@@ -8117,14 +8127,14 @@ static int hclge_set_vf_mac(struct hnae3_handle *handle, int vf, ...@@ -8117,14 +8127,14 @@ static int hclge_set_vf_mac(struct hnae3_handle *handle, int vf,
*/ */
if (test_bit(HCLGE_VPORT_STATE_ALIVE, &vport->state)) { if (test_bit(HCLGE_VPORT_STATE_ALIVE, &vport->state)) {
dev_info(&hdev->pdev->dev, dev_info(&hdev->pdev->dev,
"MAC of VF %d has been set to %pM, and it will be reinitialized!\n", "MAC of VF %d has been set to %s, and it will be reinitialized!\n",
vf, mac_addr); vf, format_mac_addr);
(void)hclge_inform_reset_assert_to_vf(vport); (void)hclge_inform_reset_assert_to_vf(vport);
return 0; return 0;
} }
dev_info(&hdev->pdev->dev, "MAC of VF %d has been set to %pM\n", dev_info(&hdev->pdev->dev, "MAC of VF %d has been set to %s\n",
vf, mac_addr); vf, format_mac_addr);
return 0; return 0;
} }
...@@ -8227,6 +8237,7 @@ static int hclge_set_mac_addr(struct hnae3_handle *handle, void *p, ...@@ -8227,6 +8237,7 @@ static int hclge_set_mac_addr(struct hnae3_handle *handle, void *p,
{ {
const unsigned char *new_addr = (const unsigned char *)p; const unsigned char *new_addr = (const unsigned char *)p;
struct hclge_vport *vport = hclge_get_vport(handle); struct hclge_vport *vport = hclge_get_vport(handle);
char format_mac_addr[HNAE3_FORMAT_MAC_ADDR_LEN];
struct hclge_dev *hdev = vport->back; struct hclge_dev *hdev = vport->back;
unsigned char *old_addr = NULL; unsigned char *old_addr = NULL;
int ret; int ret;
...@@ -8235,9 +8246,10 @@ static int hclge_set_mac_addr(struct hnae3_handle *handle, void *p, ...@@ -8235,9 +8246,10 @@ static int hclge_set_mac_addr(struct hnae3_handle *handle, void *p,
if (is_zero_ether_addr(new_addr) || if (is_zero_ether_addr(new_addr) ||
is_broadcast_ether_addr(new_addr) || is_broadcast_ether_addr(new_addr) ||
is_multicast_ether_addr(new_addr)) { is_multicast_ether_addr(new_addr)) {
hnae3_format_mac_addr(format_mac_addr, new_addr);
dev_err(&hdev->pdev->dev, dev_err(&hdev->pdev->dev,
"Change uc mac err! invalid mac:%pM.\n", "Change uc mac err! invalid mac:%s.\n",
new_addr); format_mac_addr);
return -EINVAL; return -EINVAL;
} }
...@@ -8255,9 +8267,10 @@ static int hclge_set_mac_addr(struct hnae3_handle *handle, void *p, ...@@ -8255,9 +8267,10 @@ static int hclge_set_mac_addr(struct hnae3_handle *handle, void *p,
spin_lock_bh(&vport->mac_list_lock); spin_lock_bh(&vport->mac_list_lock);
ret = hclge_update_mac_node_for_dev_addr(vport, old_addr, new_addr); ret = hclge_update_mac_node_for_dev_addr(vport, old_addr, new_addr);
if (ret) { if (ret) {
hnae3_format_mac_addr(format_mac_addr, new_addr);
dev_err(&hdev->pdev->dev, dev_err(&hdev->pdev->dev,
"Failed to change the mac addr:%pM, ret =%d\n", "Failed to change the mac addr:%s, ret =%d\n",
new_addr, ret); format_mac_addr, ret);
spin_unlock_bh(&vport->mac_list_lock); spin_unlock_bh(&vport->mac_list_lock);
return ret; return ret;
} }
......
...@@ -1417,15 +1417,18 @@ static void hclgevf_config_mac_list(struct hclgevf_dev *hdev, ...@@ -1417,15 +1417,18 @@ static void hclgevf_config_mac_list(struct hclgevf_dev *hdev,
struct list_head *list, struct list_head *list,
enum HCLGEVF_MAC_ADDR_TYPE mac_type) enum HCLGEVF_MAC_ADDR_TYPE mac_type)
{ {
char format_mac_addr[HNAE3_FORMAT_MAC_ADDR_LEN];
struct hclgevf_mac_addr_node *mac_node, *tmp; struct hclgevf_mac_addr_node *mac_node, *tmp;
int ret; int ret;
list_for_each_entry_safe(mac_node, tmp, list, node) { list_for_each_entry_safe(mac_node, tmp, list, node) {
ret = hclgevf_add_del_mac_addr(hdev, mac_node, mac_type); ret = hclgevf_add_del_mac_addr(hdev, mac_node, mac_type);
if (ret) { if (ret) {
hnae3_format_mac_addr(format_mac_addr,
mac_node->mac_addr);
dev_err(&hdev->pdev->dev, dev_err(&hdev->pdev->dev,
"request configure mac %pM failed, state=%d, ret=%d\n", "request configure mac %s failed, state=%d, ret=%d\n",
mac_node->mac_addr, mac_node->state, ret); format_mac_addr, mac_node->state, ret);
return; return;
} }
if (mac_node->state == HCLGEVF_MAC_TO_ADD) { if (mac_node->state == HCLGEVF_MAC_TO_ADD) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册