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 4474D459B2; Mon, 16 Sep 2024 19:39:32 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 344CF427CB; Mon, 16 Sep 2024 19:39:32 +0200 (CEST) Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by mails.dpdk.org (Postfix) with ESMTP id 75996427C9 for ; Mon, 16 Sep 2024 19:39:31 +0200 (CEST) Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-42cb806623eso40613105e9.2 for ; Mon, 16 Sep 2024 10:39:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726508371; x=1727113171; darn=dpdk.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=aDM6essjrrcZfbwzGxgiJ1EnCKRUZndDP2ud7bre9Zg=; b=kFku/kIO953T3xa3V63suYvuleDnLpr8uvP2NhG4qQ+4QdL9IrqvWp3cD6WAcV2sx3 8CRdS1UoHvlmdTUdbehMZ7wXNRyZDc/GbnEJn+CB/56wbCmiNjI0NftmeLh1Z54pfzIK nniZtzQ67hTB9p/pqkxqgXaHrwkKUlKF1HmzD/1VVjRmeI79+zR6lWdDzqlucqn1inm5 DkU8OktG6XvhM04+VQ3fHMItlX8iCSV/B247++fhy/JTWcI2dyw6mnM7wz/UdRWu8Q01 vdSPlAkqOl1NKE9DQ0z72vCPAYkhzqqFZkRvpWET+2pWXg2ep2OjbAOZuvYntsG3n9SN UtJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726508371; x=1727113171; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=aDM6essjrrcZfbwzGxgiJ1EnCKRUZndDP2ud7bre9Zg=; b=jF7QM3jLkap+8fw5YBKPjHJnx258OpnZLcj22ThI+Bdb3hCCxkPqn6sdUDC74Le2iC JwYmSaJRyp7TgctXKOcyb8iH25O6Y+VmvNKKHDyPtvqguUUhkD1yyOn5ALLVEmd5FPvc 0+cnxDXfTlV5dhqAxOR71XGFsCBhBNQ5HT5Yh828OhtmIRzKW4cc2KaaDC3Uf1mv4zl9 yg8lA0P3jXFHnQQ50qs6VGQR5d8DDK9eCjX6iiTyue3Sm0YewyXNNdFcRsD/0O3+xGHv Vs/3xZt7s86+5jaeuX+PKe27BDWom6HsF8V8+I6vYtzUCZpp+F+dMTeqXeuHcN7jAkdY p6fw== X-Gm-Message-State: AOJu0Yy44VfC5Pencr69Mssq+g7YnMn3ZJkWJbm0vnI+1ccLInidJT6f sJpSrcayYgOqp2+7zMIIyq19WBQ/KANMtehurjRi/Gs0ftAgaW9c X-Google-Smtp-Source: AGHT+IHjhcJ3RsRJDFvZf43iaGPu/14EJLyE7TMSo2PAbQROQ9thnEKa5dzbyYSAhd2+5MMGeUa67A== X-Received: by 2002:a05:600c:4fcd:b0:42c:bf0b:c489 with SMTP id 5b1f17b1804b1-42cdb53bf72mr105715715e9.18.1726508370044; Mon, 16 Sep 2024 10:39:30 -0700 (PDT) Received: from localhost.localdomain ([176.13.132.173]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-42d9b05dee7sm115620065e9.18.2024.09.16.10.39.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 10:39:29 -0700 (PDT) From: Isaac Boukris To: stephen@networkplumber.org Cc: dev@dpdk.org, Isaac Boukris Subject: [PATCH] net/tap: add new macpair option for split MAC address Date: Mon, 16 Sep 2024 20:38:51 +0300 Message-ID: <20240916173851.369395-1-iboukris@gmail.com> X-Mailer: git-send-email 2.45.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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 | 19 +++++++++++++++++++ drivers/net/tap/rte_eth_tap.c | 34 +++++++++++++++++++++++++++++++--- drivers/net/tap/rte_eth_tap.h | 1 + 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/doc/guides/nics/tap.rst b/doc/guides/nics/tap.rst index f01663c700..c5b08f2470 100644 --- a/doc/guides/nics/tap.rst +++ b/doc/guides/nics/tap.rst @@ -71,6 +71,25 @@ But this behavior can be overridden by the use of the persist flag, example:: --vdev=net_tap0,iface=tap0,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 address is set +by the dpdk application using ``rte_eth_dev_default_mac_addr_set()`` then the +kernel interface changes accordingly (but not vice versa). + +If the ``macpair`` option is given, then the MAC address of the kernel is +initially set to a different MAC address than the dpdk one (the fourth octet is +increamented by 1) and calling ``rte_eth_dev_default_mac_addr_set()`` no longer +changes the MAC of the kernel interface. This allows to view the two interfaces +as separate connected interfaces, similar to linux's veth pair interfaces. For +instance, 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=net_tap0,iface=tap0,macpair + TUN devices ----------- diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c index c5af5751f6..1a70832baa 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[] = { 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_ether_addr *mac_addr) dev->device->name); return -EINVAL; } + + if (pmd->mac_pair) { + rte_memcpy(&pmd->eth_addr, mac_addr, RTE_ETHER_ADDR_LEN); + return 0; + } + /* Check the actual current MAC address on the tap netdevice */ ret = tap_ioctl(pmd, SIOCGIFHWADDR, &ifr, 0, LOCAL_ONLY); if (ret < 0) @@ -1915,7 +1923,7 @@ static const struct eth_dev_ops ops = { 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 = rte_socket_id(); struct rte_eth_dev *dev; @@ -2025,10 +2033,19 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name, ifr.ifr_hwaddr.sa_family = AF_LOCAL; rte_memcpy(ifr.ifr_hwaddr.sa_data, &pmd->eth_addr, RTE_ETHER_ADDR_LEN); + + if (mac_pair) { + struct rte_ether_addr *mac; + mac = (struct rte_ether_addr*)ifr.ifr_hwaddr.sa_data; + mac->addr_bytes[3]++; + } + if (tap_ioctl(pmd, SIOCSIFHWADDR, &ifr, 0, LOCAL_ONLY) < 0) goto error_exit; } + pmd->mac_pair = mac_pair; + /* Make network device persist after application exit */ pmd->persist = persist; @@ -2306,7 +2323,7 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev) TAP_LOG(DEBUG, "Initializing pmd_tun for %s", name); ret = eth_dev_tap_create(dev, tun_name, remote_iface, 0, - ETH_TUNTAP_TYPE_TUN, 0); + ETH_TUNTAP_TYPE_TUN, 0, 0); leave: if (ret == -1) { @@ -2429,6 +2446,7 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev) struct rte_eth_dev *eth_dev; int tap_devices_count_increased = 0; int persist = 0; + int mac_pair = 0; name = rte_vdev_device_name(dev); params = rte_vdev_device_args(dev); @@ -2504,6 +2522,16 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev) goto leave; } + if (rte_kvargs_count(kvlist, ETH_TAP_MACPAIR_ARG) == 1) { + if (strlen(remote_iface)) { + TAP_LOG(ERR, "mac pair not supported " + "with remote interface."); + ret = -1; + goto leave; + } + mac_pair = 1; + } + if (rte_kvargs_count(kvlist, ETH_TAP_MAC_ARG) == 1) { ret = rte_kvargs_process(kvlist, ETH_TAP_MAC_ARG, @@ -2533,7 +2561,7 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev) tap_devices_count++; tap_devices_count_increased = 1; ret = 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 == -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 port */ struct ifreq remote_initial_flags;/* Remote netdevice flags on init */ int remote_if_index; /* remote netdevice IF_INDEX */ -- 2.45.0