From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by dpdk.org (Postfix) with ESMTP id 01D9E1B40C for ; Mon, 5 Feb 2018 16:59:01 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Feb 2018 07:59:00 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,465,1511856000"; d="scan'208";a="15544861" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by fmsmga008.fm.intel.com with ESMTP; 05 Feb 2018 07:59:00 -0800 Received: from bgsmsx104.gar.corp.intel.com (10.223.4.190) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 5 Feb 2018 07:59:00 -0800 Received: from bgsmsx101.gar.corp.intel.com ([169.254.1.25]) by BGSMSX104.gar.corp.intel.com ([169.254.5.135]) with mapi id 14.03.0319.002; Mon, 5 Feb 2018 21:28:57 +0530 From: "Varghese, Vipin" To: Pascal Mazon , "dev@dpdk.org" CC: "Yigit, Ferruh" , "Jain, Deepak K" Thread-Topic: [PATCH v2] net/tap: allow user MAC to be passed as args Thread-Index: AQHTnpjhLyZajPJtF02KZsQbkLRF2KOV9rIg Date: Mon, 5 Feb 2018 15:58:56 +0000 Message-ID: <4C9E0AB70F954A408CC4ADDBF0F8FA7D4D194E83@BGSMSX101.gar.corp.intel.com> References: <1517422961-21284-1-git-send-email-vipin.varghese@intel.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ctpclassification: CTP_NT x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiM2I4MWMwMDUtZWJlOC00YjI3LTljNDktYjkyNTdhNDFiOGZhIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjIuNS4xOCIsIlRydXN0ZWRMYWJlbEhhc2giOiJcL0RtbFBTMTlDa2Jjbk1pd3hRcEdveG9zeHRYbkJicU9ocGgyczE0VXl5ektRSG1aVnBVRncrZGd5QU1IOGFscSJ9 dlp-product: dlpe-windows dlp-version: 11.0.0.116 dlp-reaction: no-action x-originating-ip: [10.223.10.10] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v2] net/tap: allow user MAC to be passed as args X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 Feb 2018 15:59:02 -0000 Hi Pascal, Thanks for the update, I see your point instead of mixing up with int32_t a= nd uint64_t; converting to ' struct ether_addr' makes sense. I will check internally and thanks once again for the suggestion. Thanks Vipin Varghese > -----Original Message----- > From: Pascal Mazon [mailto:pascal.mazon@6wind.com] > Sent: Monday, February 5, 2018 3:55 PM > To: dev@dpdk.org; Varghese, Vipin > Cc: Yigit, Ferruh ; Jain, Deepak K > ; Pascal Mazon > Subject: [PATCH v2] net/tap: allow user MAC to be passed as args >=20 > From: Vipin Varghese >=20 > Allow TAP PMD to pass user desired MAC address as argument. > The argument value is processed as string, where each 2 bytes are convert= ed to > HEX MAC address after validation. >=20 > Signed-off-by: Vipin Varghese > Signed-off-by: Pascal Mazon > --- >=20 > Hi Vipin, >=20 > I suggest the following patch for your MAC address argument, if that suit= s you. > I removed ETH_TAP_MAC_STR_FXD and ETH_TAP_MAC_STR_USR that were not > really useful. I find it nicer to deal with MAC mostly inside set_mac_typ= e(). > What do you think? Can you test that it fits your needs? >=20 > Best regards, > Pascal >=20 > doc/guides/nics/tap.rst | 6 ++++ > drivers/net/tap/rte_eth_tap.c | 80 +++++++++++++++++++++++++++++--------= --- > --- > 2 files changed, 60 insertions(+), 26 deletions(-) >=20 > diff --git a/doc/guides/nics/tap.rst b/doc/guides/nics/tap.rst index > dc6f834ca0a1..6b083c846b21 100644 > --- a/doc/guides/nics/tap.rst > +++ b/doc/guides/nics/tap.rst > @@ -69,6 +69,12 @@ for each interface string containing ``mac=3Dfixed``. = The > MAC address is formatted as 00:'d':'t':'a':'p':[00-FF]. Convert the char= acters to > hex and you get the actual MAC address: ``00:64:74:61:70:[00-FF]``. >=20 > + --vdev=3Dnet_tap0,mac=3D"00:64:74:61:70:11" > + > +The MAC address will have a user value passed as string. The MAC > +address is in format with delimeter ``:``. The string is byte converted > +to hex and you get the actual MAC address: ``00:64:74:61:70:11``. > + > It is possible to specify a remote netdevice to capture packets from by = adding > ``remote=3Dfoo1``, for example:: >=20 > diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.= c index > 29d635613c0b..d9e5ec92b8f0 100644 > --- a/drivers/net/tap/rte_eth_tap.c > +++ b/drivers/net/tap/rte_eth_tap.c > @@ -49,6 +49,10 @@ > #define ETH_TAP_MAC_ARG "mac" > #define ETH_TAP_MAC_FIXED "fixed" >=20 > +#define ETH_TAP_USR_MAC_FMT "xx:xx:xx:xx:xx:xx" > +#define ETH_TAP_CMP_MAC_FMT "0123456789ABCDEFabcdef" > +#define ETH_TAP_MAC_ARG_FMT "["ETH_TAP_MAC_FIXED "|" > ETH_TAP_USR_MAC_FMT"]" > + > static struct rte_vdev_driver pmd_tap_drv; >=20 > static const char *valid_arguments[] =3D { @@ -278,15 +282,8 @@ > tap_rx_offload_get_queue_capa(void) > static bool > tap_rxq_are_offloads_valid(struct rte_eth_dev *dev, uint64_t offloads) = { > - uint64_t port_offloads =3D dev->data->dev_conf.rxmode.offloads; > - uint64_t queue_supp_offloads =3D tap_rx_offload_get_queue_capa(); > - uint64_t port_supp_offloads =3D tap_rx_offload_get_port_capa(); > - > - if ((offloads & (queue_supp_offloads | port_supp_offloads)) !=3D > - offloads) > - return false; > - if ((port_offloads ^ offloads) & port_supp_offloads) > - return false; > + (void)dev; > + (void)offloads; > return true; > } >=20 > @@ -1335,7 +1332,7 @@ static const struct eth_dev_ops ops =3D { >=20 > static int > eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name, > - char *remote_iface, int fixed_mac_type) > + char *remote_iface, struct ether_addr *mac_addr) > { > int numa_node =3D rte_socket_id(); > struct rte_eth_dev *dev; > @@ -1397,16 +1394,10 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, > char *tap_name, > pmd->txq[i].fd =3D -1; > } >=20 > - if (fixed_mac_type) { > - /* fixed mac =3D 00:64:74:61:70: */ > - static int iface_idx; > - char mac[ETHER_ADDR_LEN] =3D "\0dtap"; > - > - mac[ETHER_ADDR_LEN - 1] =3D iface_idx++; > - rte_memcpy(&pmd->eth_addr, mac, ETHER_ADDR_LEN); > - } else { > + if (is_zero_ether_addr(mac_addr)) > eth_random_addr((uint8_t *)&pmd->eth_addr); > - } > + else > + rte_memcpy(&pmd->eth_addr, mac_addr, sizeof(mac_addr)); >=20 > /* Immediately create the netdevice (this will create the 1st queue). *= / > /* rx queue */ > @@ -1577,10 +1568,47 @@ set_mac_type(const char *key __rte_unused, > const char *value, > void *extra_args) > { > - if (value && > - !strncasecmp(ETH_TAP_MAC_FIXED, value, > strlen(ETH_TAP_MAC_FIXED))) > - *(int *)extra_args =3D 1; > + char mac_temp[strlen(ETH_TAP_USR_MAC_FMT) + 1], *mac_byte =3D > NULL; > + struct ether_addr *user_mac =3D extra_args; > + unsigned int index =3D 0; > + > + if (!value) > + return 0; > + > + if (!strncasecmp(ETH_TAP_MAC_FIXED, value, > + strlen(ETH_TAP_MAC_FIXED))) { > + static int iface_idx; > + > + /* fixed mac =3D 00:64:74:61:70: */ > + memcpy((char *)user_mac->addr_bytes, "\0dtap", > ETHER_ADDR_LEN); > + user_mac->addr_bytes[ETHER_ADDR_LEN - 1] =3D iface_idx++ + > '0'; > + goto success; > + } > + > + if (strlen(value) !=3D strlen(ETH_TAP_USR_MAC_FMT)) > + goto error; > + > + snprintf(mac_temp, sizeof(mac_temp), "%s", value); > + mac_byte =3D strtok(mac_temp, ":"); > + > + while ((mac_byte !=3D NULL) && > + strspn(mac_byte, ETH_TAP_CMP_MAC_FMT) && > + strlen(mac_byte) =3D=3D 2) { > + user_mac->addr_bytes[index++] =3D (char) strtoul(mac_byte, > NULL, 16); > + mac_byte =3D strtok(NULL, ":"); > + } > + > + if (index !=3D 6) > + goto error; > + > +success: > + RTE_LOG(DEBUG, PMD, "TAP user MAC param (%s)\n", value); > return 0; > + > +error: > + RTE_LOG(ERR, PMD, "TAP user MAC (%s) is not in format (%s|%s)\n", > + value, ETH_TAP_MAC_FIXED, ETH_TAP_USR_MAC_FMT); > + return -1; > } >=20 > /* Open a TAP interface device. > @@ -1594,7 +1622,7 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev) > int speed; > char tap_name[RTE_ETH_NAME_MAX_LEN]; > char remote_iface[RTE_ETH_NAME_MAX_LEN]; > - int fixed_mac_type =3D 0; > + struct ether_addr user_mac =3D {0}; >=20 > name =3D rte_vdev_device_name(dev); > params =3D rte_vdev_device_args(dev); > @@ -1640,7 +1668,7 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev) > ret =3D rte_kvargs_process(kvlist, > ETH_TAP_MAC_ARG, > &set_mac_type, > - &fixed_mac_type); > + &user_mac); > if (ret =3D=3D -1) > goto leave; > } > @@ -1651,7 +1679,7 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev) > RTE_LOG(NOTICE, PMD, "Initializing pmd_tap for %s as %s\n", > name, tap_name); >=20 > - ret =3D eth_dev_tap_create(dev, tap_name, remote_iface, > fixed_mac_type); > + ret =3D eth_dev_tap_create(dev, tap_name, remote_iface, &user_mac); >=20 > leave: > if (ret =3D=3D -1) { > @@ -1716,5 +1744,5 @@ RTE_PMD_REGISTER_ALIAS(net_tap, eth_tap); > RTE_PMD_REGISTER_PARAM_STRING(net_tap, > ETH_TAP_IFACE_ARG "=3D " > ETH_TAP_SPEED_ARG "=3D " > - ETH_TAP_MAC_ARG "=3D" ETH_TAP_MAC_FIXED " " > + ETH_TAP_MAC_ARG "=3D" ETH_TAP_MAC_ARG_FMT > ETH_TAP_REMOTE_ARG "=3D"); > -- > 2.11.0