From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5705B459BE; Tue, 17 Sep 2024 14:14:27 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 44CAB40261; Tue, 17 Sep 2024 14:14:27 +0200 (CEST) Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by mails.dpdk.org (Postfix) with ESMTP id 2578C4025F for ; Tue, 17 Sep 2024 14:14:26 +0200 (CEST) Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-201d5af11a4so61693695ad.3 for ; Tue, 17 Sep 2024 05:14:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726575265; x=1727180065; darn=dpdk.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=UfHhkRPYZYRP00zLBRBB+bnByGLIPQvB+xvV22PDTBA=; b=lo8fpoQ/1sm996BiosfsWANYy8//Y1+pz5RHKAP3yOnI/0Zsd+D9kE5I96/wkY/iVx quPWTg4beyzyd1sejh8eJ2pI6LSfu2TsbyfZN2YgqhalI+Eu7fTgdFu48ExHq99OFoi4 YLxJ164gpfO7AanmVvqdxNHuZ/a1MAtvNYIb8MicRSPb1sDXE4hnwsku2WkSTA5BF/+3 Zr+WQWkNtBrIrPpF0SP58lPjg4YcO1ABYMY6rRRekSjDj3jvvd6kvdDk/WXRmP31Z8RW rmVgrI0vKhz5AMW1Su+C1D84pccSdKBiiv0pUc/tUBIVWL8V3p6hGP4g8MF1yRq4N1ZT gdSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726575265; x=1727180065; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UfHhkRPYZYRP00zLBRBB+bnByGLIPQvB+xvV22PDTBA=; b=a1b0lOuyFabDGPcbxVyusq3dS/wk54Uy12TomNuJKgBW7ZW4RgR23s5DtIVnaHjPSF IX2nUvhxJvP3uT0uZqEZI4y42XD8xb5Q+3pEswSYxafG/aYoMnNxk+JppiaWbdvgZSOA xM1bfaOeMErjL9rkK/pAg4Wrl3M50PgWtsNBfu9ZSblxfNFp+yNJ0XPEQBpx8CUsniUE Z9BJtCW0oaguWI9qgJS1+Wf0KjWqFO/5EzpQrYyRdXes7UuyWIb2DPYF3O6kTlRdtDWA Nn1fizETLPe4DIufx0L7tohUAgT7aIoU8ecF+9mKfO83oZggv8UcJVz3kAW3+9Pz/4gR EnAg== X-Gm-Message-State: AOJu0YwKmgJMmIlsPZ3Hwy5zzBbstiXq9D3I2tijw55ySg1kUB4k5NC3 ms6LuGKuPsge/otM6HR5Hs3nt83/CAmK197J5TmRvGsKz6e0UrXAWpEL4fOyaHrmDuavND6iZNz enODrgPyfsLO8DKrO8VxzCIPgTzIkEw== X-Google-Smtp-Source: AGHT+IEV+2I9oXu/xqVCl9W1HsskNH57eLPEjq/gytvXtCNX3GHKM8J9ZPB5OhPERI3hyugZfT+22UWhNgzezcoh9sI= X-Received: by 2002:a17:903:228f:b0:205:63c5:74e1 with SMTP id d9443c01a7336-2076e30a7f1mr301677005ad.5.1726575264729; Tue, 17 Sep 2024 05:14:24 -0700 (PDT) MIME-Version: 1.0 References: <20240917115147.378146-1-iboukris@gmail.com> In-Reply-To: <20240917115147.378146-1-iboukris@gmail.com> From: Isaac Boukris Date: Tue, 17 Sep 2024 15:14:13 +0300 Message-ID: Subject: Re: [PATCH] net/tap: add new macpair option for split MAC address To: dev@dpdk.org Cc: stephen@networkplumber.org, mb@smartsharesystems.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Hi, This is a V2 addressing previous comments, I mistakenly passed the -v2 to send-mail instead of format-patch.. Thanks! On Tue, Sep 17, 2024 at 2:52=E2=80=AFPM Isaac Boukris = wrote: > > Normally, the MAC address of the kernel interface is the same as in the > interface in dpdk, as they represent the same interface. It is useful > to allow viewing them as separate connected interfaces (like ip's veth). > > This solves a problem I have running a freebsd-based IPv6 stack on top > of dpdk and using the tap interface, as both the kernel and freebsd > stacks configure the MAC derived IPv6 address on the interface (as can > be seen with ifconfig for the kernel), and they both complain about > duplicate IPv6 address and the freebsd disables IPv6 as a result. > > Signed-off-by: Isaac Boukris > --- > doc/guides/nics/tap.rst | 18 +++++++++++++++++ > drivers/net/tap/rte_eth_tap.c | 37 ++++++++++++++++++++++++++++++----- > drivers/net/tap/rte_eth_tap.h | 1 + > 3 files changed, 51 insertions(+), 5 deletions(-) > > diff --git a/doc/guides/nics/tap.rst b/doc/guides/nics/tap.rst > index f01663c700..fd936c6084 100644 > --- a/doc/guides/nics/tap.rst > +++ b/doc/guides/nics/tap.rst > @@ -71,6 +71,24 @@ But this behavior can be overridden by the use of the = persist flag, example:: > > --vdev=3Dnet_tap0,iface=3Dtap0,persist ... > > +Normally, the MAC address of the kernel interface is the same as in the > +interface in dpdk, as they represent the same interface. If a MAC addres= s is set > +by the dpdk application using ``rte_eth_dev_default_mac_addr_set()`` the= n the > +kernel interface changes accordingly (but not vice versa). > + > +If the ``macpair`` option is given, then the MAC address of the kernel > +interface is initially set to a different random MAC address and it is n= o > +longer altered by dpdk. This allows to view the two interfaces as separa= te > +connected interfaces, similar to linux's veth pair interfaces. For insta= nce, > +you can configure an IP address on the kernel interface with the ``ip`` = command > +in the same subnet as the one used in dpdk and use it as next gateway. > + > +The ``macpair`` options is incompatible with the ``remote`` option (see = above). > + > +Example:: > + > + --vdev=3Dnet_tap0,iface=3Dtap0,macpair > + > > TUN devices > ----------- > diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.= c > index c5af5751f6..3cdd130092 100644 > --- a/drivers/net/tap/rte_eth_tap.c > +++ b/drivers/net/tap/rte_eth_tap.c > @@ -56,6 +56,7 @@ > #define ETH_TAP_MAC_ARG "mac" > #define ETH_TAP_MAC_FIXED "fixed" > #define ETH_TAP_PERSIST_ARG "persist" > +#define ETH_TAP_MACPAIR_ARG "macpair" > > #define ETH_TAP_USR_MAC_FMT "xx:xx:xx:xx:xx:xx" > #define ETH_TAP_CMP_MAC_FMT "0123456789ABCDEFabcdef" > @@ -95,6 +96,7 @@ static const char *valid_arguments[] =3D { > ETH_TAP_REMOTE_ARG, > ETH_TAP_MAC_ARG, > ETH_TAP_PERSIST_ARG, > + ETH_TAP_MACPAIR_ARG, > NULL > }; > > @@ -1391,6 +1393,12 @@ tap_mac_set(struct rte_eth_dev *dev, struct rte_et= her_addr *mac_addr) > dev->device->name); > return -EINVAL; > } > + > + if (pmd->mac_pair) { > + rte_ether_addr_copy(&pmd->eth_addr, mac_addr); > + return 0; > + } > + > /* Check the actual current MAC address on the tap netdevice */ > ret =3D tap_ioctl(pmd, SIOCGIFHWADDR, &ifr, 0, LOCAL_ONLY); > if (ret < 0) > @@ -1915,7 +1923,7 @@ static const struct eth_dev_ops ops =3D { > static int > eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name, > char *remote_iface, struct rte_ether_addr *mac_addr, > - enum rte_tuntap_type type, int persist) > + enum rte_tuntap_type type, int persist, int mac_pair) > { > int numa_node =3D rte_socket_id(); > struct rte_eth_dev *dev; > @@ -2023,12 +2031,20 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, = const char *tap_name, > if (pmd->type =3D=3D ETH_TUNTAP_TYPE_TAP) { > memset(&ifr, 0, sizeof(struct ifreq)); > ifr.ifr_hwaddr.sa_family =3D AF_LOCAL; > - rte_memcpy(ifr.ifr_hwaddr.sa_data, &pmd->eth_addr, > - RTE_ETHER_ADDR_LEN); > + > + if (mac_pair) { > + rte_eth_random_addr((uint8_t *)ifr.ifr_hwaddr.sa_= data); > + } else { > + memcpy(ifr.ifr_hwaddr.sa_data, &pmd->eth_addr, > + RTE_ETHER_ADDR_LEN); > + } > + > if (tap_ioctl(pmd, SIOCSIFHWADDR, &ifr, 0, LOCAL_ONLY) < = 0) > goto error_exit; > } > > + pmd->mac_pair =3D mac_pair; > + > /* Make network device persist after application exit */ > pmd->persist =3D persist; > > @@ -2306,7 +2322,7 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev) > TAP_LOG(DEBUG, "Initializing pmd_tun for %s", name); > > ret =3D eth_dev_tap_create(dev, tun_name, remote_iface, 0, > - ETH_TUNTAP_TYPE_TUN, 0); > + ETH_TUNTAP_TYPE_TUN, 0, 0); > > leave: > if (ret =3D=3D -1) { > @@ -2429,6 +2445,7 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev) > struct rte_eth_dev *eth_dev; > int tap_devices_count_increased =3D 0; > int persist =3D 0; > + int mac_pair =3D 0; > > name =3D rte_vdev_device_name(dev); > params =3D rte_vdev_device_args(dev); > @@ -2504,6 +2521,16 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev) > goto leave; > } > > + if (rte_kvargs_count(kvlist, ETH_TAP_MACPAIR_ARG)= =3D=3D 1) { > + if (strlen(remote_iface)) { > + TAP_LOG(ERR, "mac pair not suppor= ted " > + "with remote interfa= ce."); > + ret =3D -1; > + goto leave; > + } > + mac_pair =3D 1; > + } > + > if (rte_kvargs_count(kvlist, ETH_TAP_MAC_ARG) =3D= =3D 1) { > ret =3D rte_kvargs_process(kvlist, > ETH_TAP_MAC_ARG, > @@ -2533,7 +2560,7 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev) > tap_devices_count++; > tap_devices_count_increased =3D 1; > ret =3D eth_dev_tap_create(dev, tap_name, remote_iface, &user_mac= , > - ETH_TUNTAP_TYPE_TAP, persist); > + ETH_TUNTAP_TYPE_TAP, persist, mac_pair); > > leave: > if (ret =3D=3D -1) { > diff --git a/drivers/net/tap/rte_eth_tap.h b/drivers/net/tap/rte_eth_tap.= h > index ce4322ad04..5a33698f76 100644 > --- a/drivers/net/tap/rte_eth_tap.h > +++ b/drivers/net/tap/rte_eth_tap.h > @@ -72,6 +72,7 @@ struct pmd_internals { > char name[RTE_ETH_NAME_MAX_LEN]; /* Internal Tap device name */ > int type; /* Type field - TUN|TAP */ > int persist; /* 1 if keep link up, else 0 */ > + int mac_pair; /* 1 if mac pair enabled, else = 0 */ > struct rte_ether_addr eth_addr; /* Mac address of the device po= rt */ > struct ifreq remote_initial_flags;/* Remote netdevice flags on in= it */ > int remote_if_index; /* remote netdevice IF_INDEX */ > -- > 2.45.0 >