[dpdk-dev,RFC,1/5] kni: change and configure mac address

Message ID 1493810472-668-1-git-send-email-hemant.agrawal@nxp.com (mailing list archive)
State Changes Requested, archived
Delegated to: Ferruh Yigit
Headers

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/Intel-compilation success Compilation OK

Commit Message

Hemant Agrawal May 3, 2017, 11:21 a.m. UTC
  This patch adds following:
1. option to configure the mac address during create
2. inform usespace, if mac address is being changed in linux

Signed-off-by: Hemant Agrawal <hemant.agrawal@nxp.com>
---
 .../linuxapp/eal/include/exec-env/rte_kni_common.h        |  3 +++
 lib/librte_eal/linuxapp/kni/kni_misc.c                    |  6 +++++-
 lib/librte_eal/linuxapp/kni/kni_net.c                     | 15 +++++++++++++--
 lib/librte_kni/rte_kni.c                                  | 12 ++++++++++++
 lib/librte_kni/rte_kni.h                                  |  8 ++++++++
 5 files changed, 41 insertions(+), 3 deletions(-)
  

Comments

Ferruh Yigit May 5, 2017, 11:28 a.m. UTC | #1
On 5/3/2017 12:21 PM, Hemant Agrawal wrote:
> This patch adds following:
> 1. option to configure the mac address during create
> 2. inform usespace, if mac address is being changed in linux
> 
> Signed-off-by: Hemant Agrawal <hemant.agrawal@nxp.com>
> ---
>  .../linuxapp/eal/include/exec-env/rte_kni_common.h        |  3 +++
>  lib/librte_eal/linuxapp/kni/kni_misc.c                    |  6 +++++-
>  lib/librte_eal/linuxapp/kni/kni_net.c                     | 15 +++++++++++++--
>  lib/librte_kni/rte_kni.c                                  | 12 ++++++++++++
>  lib/librte_kni/rte_kni.h                                  |  8 ++++++++
>  5 files changed, 41 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h b/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h
> index 2ac879f..e9fdc73 100644
> --- a/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h
> +++ b/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h
> @@ -80,6 +80,7 @@ enum rte_kni_req_id {
>  	RTE_KNI_REQ_UNKNOWN = 0,
>  	RTE_KNI_REQ_CHANGE_MTU,
>  	RTE_KNI_REQ_CFG_NETWORK_IF,
> +	RTE_KNI_REQ_CHANGE_MAC_ADDR,
>  	RTE_KNI_REQ_MAX,
>  };
>  
> @@ -92,6 +93,7 @@ struct rte_kni_request {
>  	union {
>  		uint32_t new_mtu;    /**< New MTU */
>  		uint8_t if_up;       /**< 1: interface up, 0: interface down */
> +		uint8_t mac_addr[6]; /**< MAC address for interface */
>  	};
>  	int32_t result;               /**< Result for processing request */
>  } __attribute__((__packed__));
> @@ -168,6 +170,7 @@ struct rte_kni_device_info {
>  
>  	/* mbuf size */
>  	unsigned mbuf_size;
> +	char macaddr[6];              /**< Mac Address */

I think it is good to use same variable name for same reason, above uses
"mac_addr" here "macaddr", please pick one.

And perhaps field comment can be removed, it is not adding any extra
information.

>  };
>  
>  #define KNI_DEVICE "kni"
> diff --git a/lib/librte_eal/linuxapp/kni/kni_misc.c b/lib/librte_eal/linuxapp/kni/kni_misc.c
> index 7590f1f..90879fa 100644
> --- a/lib/librte_eal/linuxapp/kni/kni_misc.c
> +++ b/lib/librte_eal/linuxapp/kni/kni_misc.c
> @@ -458,12 +458,16 @@ struct kni_net {
>  
>  	if (kni->lad_dev)
>  		ether_addr_copy(net_dev->dev_addr, kni->lad_dev->dev_addr);
> -	else
> +	else {
>  		/*
>  		 * Generate random mac address. eth_random_addr() is the newer
>  		 * version of generating mac address in linux kernel.
>  		 */
>  		random_ether_addr(net_dev->dev_addr);
> +		
> +		/* todo - check if user supplied mac address is available*/

Can we implement todo J

> +		memcpy(net_dev->dev_addr, dev_info.macaddr, ETH_ALEN);
> +	}
>  
>  	ret = register_netdev(net_dev);
>  	if (ret) {
> diff --git a/lib/librte_eal/linuxapp/kni/kni_net.c b/lib/librte_eal/linuxapp/kni/kni_net.c
> index db9f489..866cbdd 100644
> --- a/lib/librte_eal/linuxapp/kni/kni_net.c
> +++ b/lib/librte_eal/linuxapp/kni/kni_net.c
> @@ -668,12 +668,23 @@
>  static int
>  kni_net_set_mac(struct net_device *netdev, void *p)
>  {
> +	int ret;
> +	struct rte_kni_request req;
>  	struct sockaddr *addr = p;
> +	struct kni_dev *kni;
> +
> +	kni = netdev_priv(netdev);
> +	memset(&req, 0, sizeof(req));
> +	req.req_id = RTE_KNI_REQ_CHANGE_MAC_ADDR;
>  
> -	if (!is_valid_ether_addr((unsigned char *)(addr->sa_data)))
> +	if (!is_valid_ether_addr((unsigned char *)(addr->sa_data))) {

Not required to add {

>  		return -EADDRNOTAVAIL;
> +	}
> +	memcpy(req.mac_addr, addr->sa_data, netdev->addr_len);
>  	memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
> -	return 0;
> +	ret = kni_net_process_request(kni, &req);
> +
> +	return (ret == 0 ? req.result : ret);

If config_mac_address() is not defined, req.result will be undefined.
You should give initial value to req.

>  }
>  
>  #ifdef HAVE_CHANGE_CARRIER_CB
> diff --git a/lib/librte_kni/rte_kni.c b/lib/librte_kni/rte_kni.c
> index 52fcd4b..d5a717b 100644
> --- a/lib/librte_kni/rte_kni.c
> +++ b/lib/librte_kni/rte_kni.c
> @@ -52,6 +52,10 @@
>  
>  #define MAX_MBUF_BURST_NUM            32
>  
> +#ifndef ETH_ADDR_LEN
> +#define ETH_ADDR_LEN                  6
> +#endif

This is redundant, rte_kni.h has something similar.

> +
>  /* Maximum number of ring entries */
>  #define KNI_FIFO_COUNT_MAX     1024
>  #define KNI_FIFO_SIZE          (KNI_FIFO_COUNT_MAX * sizeof(void *) + \
> @@ -368,6 +372,8 @@ struct rte_kni *
>  	dev_info.group_id = conf->group_id;
>  	dev_info.mbuf_size = conf->mbuf_size;
>  
> +	memcpy(dev_info.macaddr, conf->macaddr, ETH_ADDR_LEN);
> +
>  	snprintf(ctx->name, RTE_KNI_NAMESIZE, "%s", intf_name);
>  	snprintf(dev_info.name, RTE_KNI_NAMESIZE, "%s", intf_name);
>  
> @@ -541,6 +547,11 @@ struct rte_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);
> +		break;
>  	default:
>  		RTE_LOG(ERR, KNI, "Unknown request id %u\n", req->req_id);
>  		req->result = -EINVAL;
> @@ -735,6 +746,7 @@ struct rte_kni *
>  
>  	kni->ops.change_mtu = NULL;
>  	kni->ops.config_network_if = NULL;
> +	kni->ops.config_mac_address = NULL;

Can do memset here perhaps?

Also need to update kni_check_request_register(), it only checks
change_mtu and config_network_if pointers to decide if ops registered,
since there are more ops now, that logic needs to be updated.

>  	return 0;
>  }
>  void
> diff --git a/lib/librte_kni/rte_kni.h b/lib/librte_kni/rte_kni.h
> index 37deb47..5d2a233 100644
> --- a/lib/librte_kni/rte_kni.h
> +++ b/lib/librte_kni/rte_kni.h
> @@ -59,6 +59,10 @@
>  struct rte_kni;
>  struct rte_mbuf;
>  
> +#ifndef ETH_ADDR_LEN
> +#define ETH_ADDR_LEN                  6
> +#endif
> +

Can include rte_ether.h, and use ETHER_ADDR_LEN here.

>  /**
>   * Structure which has the function pointers for KNI interface.
>   */
> @@ -70,6 +74,9 @@ struct rte_kni_ops {
>  
>  	/* Pointer to function of configuring network interface */
>  	int (*config_network_if)(uint8_t port_id, uint8_t if_up);
> +
> +	/* Pointer to function of configuring mac address */
> +	int (*config_mac_address)(uint8_t port_id, uint8_t mac_addr[6]);

Can replace "6" with ETHER_ADDR_LEN

Two things here:

1) Providing rte_kni_ops interface during creating a KNI interface links
KNI interface a backing DPDK port. And kni_ops applied on to this port.

For the case "config_mac_address", it is obvious that what we want to do
on to DPDK port. Why not provide a default implementation for this
function in librte_kni (via this patch) and set it by default.
Application still can overwrite it if it has something else to do. This
saves effort for others.

2) Can you please update sample application with this new kni_ops, again
in this patch?


>  };
>  
>  /**
> @@ -87,6 +94,7 @@ struct rte_kni_conf {
>  	unsigned mbuf_size; /* mbuf size */
>  	struct rte_pci_addr addr;
>  	struct rte_pci_id id;
> +	char macaddr[ETH_ADDR_LEN]; /* MAC address assigned to KNI */
>  
>  	__extension__
>  	uint8_t force_bind : 1; /* Flag to bind kernel thread */
>
  
Hemant Agrawal May 8, 2017, 9:59 a.m. UTC | #2
On 5/5/2017 4:58 PM, Ferruh Yigit wrote:
> On 5/3/2017 12:21 PM, Hemant Agrawal wrote:
>> This patch adds following:
>> 1. option to configure the mac address during create
>> 2. inform usespace, if mac address is being changed in linux
>>
>> Signed-off-by: Hemant Agrawal <hemant.agrawal@nxp.com>
>> ---
>>  .../linuxapp/eal/include/exec-env/rte_kni_common.h        |  3 +++
>>  lib/librte_eal/linuxapp/kni/kni_misc.c                    |  6 +++++-
>>  lib/librte_eal/linuxapp/kni/kni_net.c                     | 15 +++++++++++++--
>>  lib/librte_kni/rte_kni.c                                  | 12 ++++++++++++
>>  lib/librte_kni/rte_kni.h                                  |  8 ++++++++
>>  5 files changed, 41 insertions(+), 3 deletions(-)
>>
>> diff --git a/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h b/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h
>> index 2ac879f..e9fdc73 100644
>> --- a/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h
>> +++ b/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h
>> @@ -80,6 +80,7 @@ enum rte_kni_req_id {
>>  	RTE_KNI_REQ_UNKNOWN = 0,
>>  	RTE_KNI_REQ_CHANGE_MTU,
>>  	RTE_KNI_REQ_CFG_NETWORK_IF,
>> +	RTE_KNI_REQ_CHANGE_MAC_ADDR,
>>  	RTE_KNI_REQ_MAX,
>>  };
>>
>> @@ -92,6 +93,7 @@ struct rte_kni_request {
>>  	union {
>>  		uint32_t new_mtu;    /**< New MTU */
>>  		uint8_t if_up;       /**< 1: interface up, 0: interface down */
>> +		uint8_t mac_addr[6]; /**< MAC address for interface */
>>  	};
>>  	int32_t result;               /**< Result for processing request */
>>  } __attribute__((__packed__));
>> @@ -168,6 +170,7 @@ struct rte_kni_device_info {
>>
>>  	/* mbuf size */
>>  	unsigned mbuf_size;
>> +	char macaddr[6];              /**< Mac Address */
>
> I think it is good to use same variable name for same reason, above uses
> "mac_addr" here "macaddr", please pick one.
>
> And perhaps field comment can be removed, it is not adding any extra
> information.

ok

>
>>  };
>>
>>  #define KNI_DEVICE "kni"
>> diff --git a/lib/librte_eal/linuxapp/kni/kni_misc.c b/lib/librte_eal/linuxapp/kni/kni_misc.c
>> index 7590f1f..90879fa 100644
>> --- a/lib/librte_eal/linuxapp/kni/kni_misc.c
>> +++ b/lib/librte_eal/linuxapp/kni/kni_misc.c
>> @@ -458,12 +458,16 @@ struct kni_net {
>>
>>  	if (kni->lad_dev)
>>  		ether_addr_copy(net_dev->dev_addr, kni->lad_dev->dev_addr);
>> -	else
>> +	else {
>>  		/*
>>  		 * Generate random mac address. eth_random_addr() is the newer
>>  		 * version of generating mac address in linux kernel.
>>  		 */
>>  		random_ether_addr(net_dev->dev_addr);
>> +		
>> +		/* todo - check if user supplied mac address is available*/
>
> Can we implement todo J

I am just thinking about how to check, if user has provided the mac 
address or he want the random address.

Can we make it mandatory for user to supply the mac address always?
>
>> +		memcpy(net_dev->dev_addr, dev_info.macaddr, ETH_ALEN);
>> +	}
>>
>>  	ret = register_netdev(net_dev);
>>  	if (ret) {
>> diff --git a/lib/librte_eal/linuxapp/kni/kni_net.c b/lib/librte_eal/linuxapp/kni/kni_net.c
>> index db9f489..866cbdd 100644
>> --- a/lib/librte_eal/linuxapp/kni/kni_net.c
>> +++ b/lib/librte_eal/linuxapp/kni/kni_net.c
>> @@ -668,12 +668,23 @@
>>  static int
>>  kni_net_set_mac(struct net_device *netdev, void *p)
>>  {
>> +	int ret;
>> +	struct rte_kni_request req;
>>  	struct sockaddr *addr = p;
>> +	struct kni_dev *kni;
>> +
>> +	kni = netdev_priv(netdev);
>> +	memset(&req, 0, sizeof(req));
>> +	req.req_id = RTE_KNI_REQ_CHANGE_MAC_ADDR;
>>
>> -	if (!is_valid_ether_addr((unsigned char *)(addr->sa_data)))
>> +	if (!is_valid_ether_addr((unsigned char *)(addr->sa_data))) {
>
> Not required to add {
ok
>
>>  		return -EADDRNOTAVAIL;
>> +	}
>> +	memcpy(req.mac_addr, addr->sa_data, netdev->addr_len);
>>  	memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
>> -	return 0;
>> +	ret = kni_net_process_request(kni, &req);
>> +
>> +	return (ret == 0 ? req.result : ret);
>
> If config_mac_address() is not defined, req.result will be undefined.
> You should give initial value to req.

I am doing a memset to req. so req.result will be '0'.

>
>>  }
>>
>>  #ifdef HAVE_CHANGE_CARRIER_CB
>> diff --git a/lib/librte_kni/rte_kni.c b/lib/librte_kni/rte_kni.c
>> index 52fcd4b..d5a717b 100644
>> --- a/lib/librte_kni/rte_kni.c
>> +++ b/lib/librte_kni/rte_kni.c
>> @@ -52,6 +52,10 @@
>>
>>  #define MAX_MBUF_BURST_NUM            32
>>
>> +#ifndef ETH_ADDR_LEN
>> +#define ETH_ADDR_LEN                  6
>> +#endif
>
> This is redundant, rte_kni.h has something similar.
ok
>
>> +
>>  /* Maximum number of ring entries */
>>  #define KNI_FIFO_COUNT_MAX     1024
>>  #define KNI_FIFO_SIZE          (KNI_FIFO_COUNT_MAX * sizeof(void *) + \
>> @@ -368,6 +372,8 @@ struct rte_kni *
>>  	dev_info.group_id = conf->group_id;
>>  	dev_info.mbuf_size = conf->mbuf_size;
>>
>> +	memcpy(dev_info.macaddr, conf->macaddr, ETH_ADDR_LEN);
>> +
>>  	snprintf(ctx->name, RTE_KNI_NAMESIZE, "%s", intf_name);
>>  	snprintf(dev_info.name, RTE_KNI_NAMESIZE, "%s", intf_name);
>>
>> @@ -541,6 +547,11 @@ struct rte_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);
>> +		break;
>>  	default:
>>  		RTE_LOG(ERR, KNI, "Unknown request id %u\n", req->req_id);
>>  		req->result = -EINVAL;
>> @@ -735,6 +746,7 @@ struct rte_kni *
>>
>>  	kni->ops.change_mtu = NULL;
>>  	kni->ops.config_network_if = NULL;
>> +	kni->ops.config_mac_address = NULL;
>
> Can do memset here perhaps?
>
> Also need to update kni_check_request_register(), it only checks
> change_mtu and config_network_if pointers to decide if ops registered,
> since there are more ops now, that logic needs to be updated.
>
ok

>>  	return 0;
>>  }
>>  void
>> diff --git a/lib/librte_kni/rte_kni.h b/lib/librte_kni/rte_kni.h
>> index 37deb47..5d2a233 100644
>> --- a/lib/librte_kni/rte_kni.h
>> +++ b/lib/librte_kni/rte_kni.h
>> @@ -59,6 +59,10 @@
>>  struct rte_kni;
>>  struct rte_mbuf;
>>
>> +#ifndef ETH_ADDR_LEN
>> +#define ETH_ADDR_LEN                  6
>> +#endif
>> +
>
> Can include rte_ether.h, and use ETHER_ADDR_LEN here.
ok

>
>>  /**
>>   * Structure which has the function pointers for KNI interface.
>>   */
>> @@ -70,6 +74,9 @@ struct rte_kni_ops {
>>
>>  	/* Pointer to function of configuring network interface */
>>  	int (*config_network_if)(uint8_t port_id, uint8_t if_up);
>> +
>> +	/* Pointer to function of configuring mac address */
>> +	int (*config_mac_address)(uint8_t port_id, uint8_t mac_addr[6]);
>
> Can replace "6" with ETHER_ADDR_LEN
>
> Two things here:
>
> 1) Providing rte_kni_ops interface during creating a KNI interface links
> KNI interface a backing DPDK port. And kni_ops applied on to this port.
>
> For the case "config_mac_address", it is obvious that what we want to do
> on to DPDK port. Why not provide a default implementation for this
> function in librte_kni (via this patch) and set it by default.
> Application still can overwrite it if it has something else to do. This
> saves effort for others.
>
There are two things:
1. application changing it or initially configuring
2. Change it via Linux - use ifconfig to change it. Application  need to 
implement the ops to get this information, so that it can update it in 
net driver.

> 2) Can you please update sample application with this new kni_ops, again
> in this patch?
>

I will, I want to first get comment on the idea.

>
>>  };
>>
>>  /**
>> @@ -87,6 +94,7 @@ struct rte_kni_conf {
>>  	unsigned mbuf_size; /* mbuf size */
>>  	struct rte_pci_addr addr;
>>  	struct rte_pci_id id;
>> +	char macaddr[ETH_ADDR_LEN]; /* MAC address assigned to KNI */
>>
>>  	__extension__
>>  	uint8_t force_bind : 1; /* Flag to bind kernel thread */
>>
>
>
  
Ferruh Yigit Nov. 28, 2017, 10:31 p.m. UTC | #3
On 5/3/2017 4:21 AM, Hemant Agrawal wrote:
> This patch adds following:
> 1. option to configure the mac address during create
> 2. inform usespace, if mac address is being changed in linux
> 
> Signed-off-by: Hemant Agrawal <hemant.agrawal@nxp.com>

Hi Hemant,

This RFC is waiting in patchwork for a while, is there plan to send a v1? I will
mark patchset as RFC in patchwork.

As far as I can follow latest patchset status is:

provide initial value and add capability to change
1/5: MAC address
2/5: promisc mode
3/5: MTU

There is a change request for 1/5, other two looks OK.
But for all three the action done in kni_ops, which means application needs to
implement these features.
Not sure about pushing these common tasks to application, instead of all
applications implement same thing, does it make sense to implement them in kni
library?

4/5: add gso_size info
Nak because it uses mbuf field with another meaning

5/5: Add cleanup fix for multi process
Multi process support is not supported in KNI at first place, if there is a need
first it needs to be introduced and tested.


Thanks,
ferruh
  
Hemant Agrawal Nov. 30, 2017, 6:44 a.m. UTC | #4
On 11/29/2017 4:01 AM, Ferruh Yigit wrote:
> On 5/3/2017 4:21 AM, Hemant Agrawal wrote:
>> This patch adds following:
>> 1. option to configure the mac address during create
>> 2. inform usespace, if mac address is being changed in linux
>>
>> Signed-off-by: Hemant Agrawal <hemant.agrawal@nxp.com>
>
> Hi Hemant,
Hi Ferruh,

Thanks for looking into it. It is a just a co-incidence that I started 
working on these again yesterday :)

I plan to send the updated patch along with application change in next 
few days.

>
> This RFC is waiting in patchwork for a while, is there plan to send a v1? I will
> mark patchset as RFC in patchwork.
>
> As far as I can follow latest patchset status is:
>
> provide initial value and add capability to change
> 1/5: MAC address
> 2/5: promisc mode
> 3/5: MTU
>
> There is a change request for 1/5, other two looks OK.

I am taking care of comments.

> But for all three the action done in kni_ops, which means application needs to
> implement these features.
> Not sure about pushing these common tasks to application, instead of all
> applications implement same thing, does it make sense to implement them in kni
> library?

I don't think it is a good thing to implement them in library itself.
Libary may not know about the equivalent Ethernet port and it may be a 
logical kni port also.

>
> 4/5: add gso_size info
> Nak because it uses mbuf field with another meaning
>
ok, I will try to find other means.

> 5/5: Add cleanup fix for multi process
> Multi process support is not supported in KNI at first place, if there is a need
> first it needs to be introduced and tested.

ok
>
>
> Thanks,
> ferruh
>
  

Patch

diff --git a/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h b/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h
index 2ac879f..e9fdc73 100644
--- a/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h
+++ b/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h
@@ -80,6 +80,7 @@  enum rte_kni_req_id {
 	RTE_KNI_REQ_UNKNOWN = 0,
 	RTE_KNI_REQ_CHANGE_MTU,
 	RTE_KNI_REQ_CFG_NETWORK_IF,
+	RTE_KNI_REQ_CHANGE_MAC_ADDR,
 	RTE_KNI_REQ_MAX,
 };
 
@@ -92,6 +93,7 @@  struct rte_kni_request {
 	union {
 		uint32_t new_mtu;    /**< New MTU */
 		uint8_t if_up;       /**< 1: interface up, 0: interface down */
+		uint8_t mac_addr[6]; /**< MAC address for interface */
 	};
 	int32_t result;               /**< Result for processing request */
 } __attribute__((__packed__));
@@ -168,6 +170,7 @@  struct rte_kni_device_info {
 
 	/* mbuf size */
 	unsigned mbuf_size;
+	char macaddr[6];              /**< Mac Address */
 };
 
 #define KNI_DEVICE "kni"
diff --git a/lib/librte_eal/linuxapp/kni/kni_misc.c b/lib/librte_eal/linuxapp/kni/kni_misc.c
index 7590f1f..90879fa 100644
--- a/lib/librte_eal/linuxapp/kni/kni_misc.c
+++ b/lib/librte_eal/linuxapp/kni/kni_misc.c
@@ -458,12 +458,16 @@  struct kni_net {
 
 	if (kni->lad_dev)
 		ether_addr_copy(net_dev->dev_addr, kni->lad_dev->dev_addr);
-	else
+	else {
 		/*
 		 * Generate random mac address. eth_random_addr() is the newer
 		 * version of generating mac address in linux kernel.
 		 */
 		random_ether_addr(net_dev->dev_addr);
+		
+		/* todo - check if user supplied mac address is available*/
+		memcpy(net_dev->dev_addr, dev_info.macaddr, ETH_ALEN);
+	}
 
 	ret = register_netdev(net_dev);
 	if (ret) {
diff --git a/lib/librte_eal/linuxapp/kni/kni_net.c b/lib/librte_eal/linuxapp/kni/kni_net.c
index db9f489..866cbdd 100644
--- a/lib/librte_eal/linuxapp/kni/kni_net.c
+++ b/lib/librte_eal/linuxapp/kni/kni_net.c
@@ -668,12 +668,23 @@ 
 static int
 kni_net_set_mac(struct net_device *netdev, void *p)
 {
+	int ret;
+	struct rte_kni_request req;
 	struct sockaddr *addr = p;
+	struct kni_dev *kni;
+
+	kni = netdev_priv(netdev);
+	memset(&req, 0, sizeof(req));
+	req.req_id = RTE_KNI_REQ_CHANGE_MAC_ADDR;
 
-	if (!is_valid_ether_addr((unsigned char *)(addr->sa_data)))
+	if (!is_valid_ether_addr((unsigned char *)(addr->sa_data))) {
 		return -EADDRNOTAVAIL;
+	}
+	memcpy(req.mac_addr, addr->sa_data, netdev->addr_len);
 	memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
-	return 0;
+	ret = kni_net_process_request(kni, &req);
+
+	return (ret == 0 ? req.result : ret);
 }
 
 #ifdef HAVE_CHANGE_CARRIER_CB
diff --git a/lib/librte_kni/rte_kni.c b/lib/librte_kni/rte_kni.c
index 52fcd4b..d5a717b 100644
--- a/lib/librte_kni/rte_kni.c
+++ b/lib/librte_kni/rte_kni.c
@@ -52,6 +52,10 @@ 
 
 #define MAX_MBUF_BURST_NUM            32
 
+#ifndef ETH_ADDR_LEN
+#define ETH_ADDR_LEN                  6
+#endif
+
 /* Maximum number of ring entries */
 #define KNI_FIFO_COUNT_MAX     1024
 #define KNI_FIFO_SIZE          (KNI_FIFO_COUNT_MAX * sizeof(void *) + \
@@ -368,6 +372,8 @@  struct rte_kni *
 	dev_info.group_id = conf->group_id;
 	dev_info.mbuf_size = conf->mbuf_size;
 
+	memcpy(dev_info.macaddr, conf->macaddr, ETH_ADDR_LEN);
+
 	snprintf(ctx->name, RTE_KNI_NAMESIZE, "%s", intf_name);
 	snprintf(dev_info.name, RTE_KNI_NAMESIZE, "%s", intf_name);
 
@@ -541,6 +547,11 @@  struct rte_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);
+		break;
 	default:
 		RTE_LOG(ERR, KNI, "Unknown request id %u\n", req->req_id);
 		req->result = -EINVAL;
@@ -735,6 +746,7 @@  struct rte_kni *
 
 	kni->ops.change_mtu = NULL;
 	kni->ops.config_network_if = NULL;
+	kni->ops.config_mac_address = NULL;
 	return 0;
 }
 void
diff --git a/lib/librte_kni/rte_kni.h b/lib/librte_kni/rte_kni.h
index 37deb47..5d2a233 100644
--- a/lib/librte_kni/rte_kni.h
+++ b/lib/librte_kni/rte_kni.h
@@ -59,6 +59,10 @@ 
 struct rte_kni;
 struct rte_mbuf;
 
+#ifndef ETH_ADDR_LEN
+#define ETH_ADDR_LEN                  6
+#endif
+
 /**
  * Structure which has the function pointers for KNI interface.
  */
@@ -70,6 +74,9 @@  struct rte_kni_ops {
 
 	/* Pointer to function of configuring network interface */
 	int (*config_network_if)(uint8_t port_id, uint8_t if_up);
+
+	/* Pointer to function of configuring mac address */
+	int (*config_mac_address)(uint8_t port_id, uint8_t mac_addr[6]);
 };
 
 /**
@@ -87,6 +94,7 @@  struct rte_kni_conf {
 	unsigned mbuf_size; /* mbuf size */
 	struct rte_pci_addr addr;
 	struct rte_pci_id id;
+	char macaddr[ETH_ADDR_LEN]; /* MAC address assigned to KNI */
 
 	__extension__
 	uint8_t force_bind : 1; /* Flag to bind kernel thread */