summaryrefslogtreecommitdiff
path: root/lib/librte_kni/rte_kni.c
diff options
context:
space:
mode:
authorHemant Agrawal <hemant.agrawal@nxp.com>2018-01-18 11:42:58 +0530
committerThomas Monjalon <thomas@monjalon.net>2018-02-01 01:02:50 +0100
commit1cfe212ed17a505be53d09845554cd51607dd2a6 (patch)
tree4d493049d9fb870e0ed2513922d8fa1f54e72ce7 /lib/librte_kni/rte_kni.c
parentfc29c712dd6758877bb10166d9a7866ee1fa6875 (diff)
downloaddpdk-1cfe212ed17a505be53d09845554cd51607dd2a6.zip
dpdk-1cfe212ed17a505be53d09845554cd51607dd2a6.tar.gz
dpdk-1cfe212ed17a505be53d09845554cd51607dd2a6.tar.xz
kni: support MAC address change
This patch adds following: 1. Option to configure the mac address during create. Generate random address only if the user has not provided any valid address. 2. Inform usespace, if mac address is being changed in linux. 3. Implement default handling of mac address change in the corresponding ethernet device. Signed-off-by: Hemant Agrawal <hemant.agrawal@nxp.com> Acked-by: Ferruh Yigit <ferruh.yigit@intel.com>
Diffstat (limited to 'lib/librte_kni/rte_kni.c')
-rw-r--r--lib/librte_kni/rte_kni.c42
1 files changed, 39 insertions, 3 deletions
diff --git a/lib/librte_kni/rte_kni.c b/lib/librte_kni/rte_kni.c
index f4fa994..a140dfc 100644
--- a/lib/librte_kni/rte_kni.c
+++ b/lib/librte_kni/rte_kni.c
@@ -327,6 +327,8 @@ rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
memset(ctx, 0, sizeof(struct rte_kni));
if (ops)
memcpy(&ctx->ops, ops, sizeof(struct rte_kni_ops));
+ else
+ ctx->ops.port_id = UINT16_MAX;
memset(&dev_info, 0, sizeof(dev_info));
dev_info.bus = conf->addr.bus;
@@ -339,6 +341,8 @@ rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
dev_info.group_id = conf->group_id;
dev_info.mbuf_size = conf->mbuf_size;
+ memcpy(dev_info.mac_addr, conf->mac_addr, ETHER_ADDR_LEN);
+
snprintf(ctx->name, RTE_KNI_NAMESIZE, "%s", intf_name);
snprintf(dev_info.name, RTE_KNI_NAMESIZE, "%s", intf_name);
@@ -499,6 +503,28 @@ rte_kni_release(struct rte_kni *kni)
return 0;
}
+/* default callback for request of configuring device mac address */
+static int
+kni_config_mac_address(uint16_t port_id, uint8_t mac_addr[])
+{
+ int ret = 0;
+
+ if (port_id >= rte_eth_dev_count() || port_id >= RTE_MAX_ETHPORTS) {
+ RTE_LOG(ERR, KNI, "Invalid port id %d\n", port_id);
+ return -EINVAL;
+ }
+
+ RTE_LOG(INFO, KNI, "Configure mac address of %d", port_id);
+
+ ret = rte_eth_dev_default_mac_addr_set(port_id,
+ (struct ether_addr *)mac_addr);
+ if (ret < 0)
+ RTE_LOG(ERR, KNI, "Failed to config mac_addr for port %d\n",
+ port_id);
+
+ return ret;
+}
+
int
rte_kni_handle_request(struct rte_kni *kni)
{
@@ -530,6 +556,14 @@ rte_kni_handle_request(struct rte_kni *kni)
req->result = kni->ops.config_network_if(\
kni->ops.port_id, req->if_up);
break;
+ case RTE_KNI_REQ_CHANGE_MAC_ADDR: /* Change MAC Address */
+ if (kni->ops.config_mac_address)
+ req->result = kni->ops.config_mac_address(
+ kni->ops.port_id, req->mac_addr);
+ else if (kni->ops.port_id != UINT16_MAX)
+ req->result = kni_config_mac_address(
+ kni->ops.port_id, req->mac_addr);
+ break;
default:
RTE_LOG(ERR, KNI, "Unknown request id %u\n", req->req_id);
req->result = -EINVAL;
@@ -678,7 +712,9 @@ kni_check_request_register(struct rte_kni_ops *ops)
if( NULL == ops )
return KNI_REQ_NO_REGISTER;
- if((NULL == ops->change_mtu) && (NULL == ops->config_network_if))
+ if ((ops->change_mtu == NULL)
+ && (ops->config_network_if == NULL)
+ && (ops->config_mac_address == NULL))
return KNI_REQ_NO_REGISTER;
return KNI_REQ_REGISTERED;
@@ -717,8 +753,8 @@ rte_kni_unregister_handlers(struct rte_kni *kni)
return -1;
}
- kni->ops.change_mtu = NULL;
- kni->ops.config_network_if = NULL;
+ memset(&kni->ops, 0, sizeof(struct rte_kni_ops));
+
return 0;
}
void