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 6DC7E43F19; Fri, 26 Apr 2024 17:52:50 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 50C1143F3F; Fri, 26 Apr 2024 17:51:52 +0200 (CEST) Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) by mails.dpdk.org (Postfix) with ESMTP id AA92743F11 for ; Fri, 26 Apr 2024 17:51:44 +0200 (CEST) Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-2a484f772e2so1620495a91.3 for ; Fri, 26 Apr 2024 08:51:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1714146704; x=1714751504; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CASiGeiYMOqJ2aivudSsgIq3JXXBscw18MAvjgHM6LA=; b=IF486AijkvAGOTKw3CSBpdUu/bvjhHJoV8Z1QLb8aMIuWM3rXzc4b5oXqw4ojpcDhn rew3rgeu27H22DUBQ4VszF0NZAI1SQi24XbKLcZ5+FNLVl25vjN6VmAdgEs8iFh2dbcA aGaPbJgD05bUn9bF344nxPPwA//ipswjJpHgV7l+NAxouLmiLFAEel6Ova4wmNPPAfFq +te+U+80rt1T4GcYb93fNpj02KbZSeGFc7iIhDnCynxnr8XfiI6vxFzMfyyKlXqCt/XV 4p5PLKC/1ms8ZDUUQuOkoaedfupPu3s4naV0430SJ49lUGu6he7OFbdE2qz7HzuECawO b4Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714146704; x=1714751504; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CASiGeiYMOqJ2aivudSsgIq3JXXBscw18MAvjgHM6LA=; b=VDUwZu2JMheKVMzhi4oAcFM/UtEC9c7vYw0fGJPJpgFdZHB5R+sKTin1nvCwk3qPby IfeELs23hqsTCtyRRZHnRp8J4P3AmgpPf0+m2vN9Ko1IGJwC3IKsRFE4MRSSr4vM3uqP A4F6glXySzWFwpewZfhRIGVIAjlejnqlSDGuAv4wRvjJOyPpfRcledwzDMMXTxibgTrA gOTi4n5TzaGeAyLFaPA9exVZoIBIS9DXD8h5xwjyMx0tcg3AxOjtWmh7xozD9Oeucc/i suzd2Z0aOok3zUWij1r5Bq/md0T9YHUbFPcA1NdcBC9M4ZtlLD8IV7Uo+i9Gsx/G1Dyv Irfw== X-Gm-Message-State: AOJu0Yy//gZTpijMBFU+KqvTkubjgnXSw1j1wSqc8uL6D6oY4hQ0I6Sq kGlp9+dmyre0R2aEywzf4YAg30iLNjZ+KINw6da26Z0pdjlvYdfjyZO5txBxeULOAOXA1VyBQie auaI= X-Google-Smtp-Source: AGHT+IHEPspmWeDM7tQ9QynDnSDfQPwpBYXOPrM0RCgis1K0wqQQnDTFyMw+Z2LiGiK3g/IXl2EEiA== X-Received: by 2002:a17:90a:d397:b0:2af:6ce2:bd2f with SMTP id q23-20020a17090ad39700b002af6ce2bd2fmr3232163pju.1.1714146703888; Fri, 26 Apr 2024 08:51:43 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id ns5-20020a17090b250500b002a5f44353d2sm16770978pjb.7.2024.04.26.08.51.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 08:51:43 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v9 9/9] net/tap: simplify the internal structure Date: Fri, 26 Apr 2024 08:48:59 -0700 Message-ID: <20240426155125.125910-10-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240426155125.125910-1-stephen@networkplumber.org> References: <20240130034925.44869-1-stephen@networkplumber.org> <20240426155125.125910-1-stephen@networkplumber.org> 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 The names of Linux network devices are IFNAMSIZ(16) not the same as DPDK which has up to 64 characters. Don't need to hold onto the whole ifreq to save the remote interface flags. Rearrange internal structure for locality. Signed-off-by: Stephen Hemminger --- drivers/net/tap/rte_eth_tap.c | 42 ++++++++++++++++++++++------------- drivers/net/tap/rte_eth_tap.h | 12 +++++----- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c index 793730de08..b066a8acd1 100644 --- a/drivers/net/tap/rte_eth_tap.c +++ b/drivers/net/tap/rte_eth_tap.c @@ -212,7 +212,7 @@ tun_alloc(struct pmd_internals *pmd, int is_keepalive, int persistent) * and need to find the resulting device. */ TAP_LOG(DEBUG, "Device name is '%s'", ifr.ifr_name); - strlcpy(pmd->name, ifr.ifr_name, RTE_ETH_NAME_MAX_LEN); + strlcpy(pmd->name, ifr.ifr_name, IFNAMSIZ); if (is_keepalive) { /* @@ -1151,9 +1151,13 @@ tap_dev_close(struct rte_eth_dev *dev) } if (internals->remote_if_index) { + struct ifreq remote_ifr; + + strlcpy(remote_ifr.ifr_name, internals->remote_iface, IFNAMSIZ); + remote_ifr.ifr_flags = internals->remote_flags; + /* Restore initial remote state */ - int ret = ioctl(internals->ioctl_sock, SIOCSIFFLAGS, - &internals->remote_initial_flags); + int ret = ioctl(internals->ioctl_sock, SIOCSIFFLAGS, &remote_ifr); if (ret) TAP_LOG(ERR, "restore remote state failed: %d", ret); @@ -2074,16 +2078,22 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name, LIST_INIT(&pmd->flows); if (strlen(remote_iface)) { + struct ifreq remote_ifr; + pmd->remote_if_index = if_nametoindex(remote_iface); if (!pmd->remote_if_index) { TAP_LOG(ERR, "%s: failed to get %s if_index.", pmd->name, remote_iface); goto error_remote; } - strlcpy(pmd->remote_iface, remote_iface, RTE_ETH_NAME_MAX_LEN); + strlcpy(pmd->remote_iface, remote_iface, IFNAMSIZ); + + memset(&remote_ifr, 0, sizeof(ifr)); + strlcpy(remote_ifr.ifr_name, remote_iface, IFNAMSIZ); /* Save state of remote device */ - tap_ioctl(pmd, SIOCGIFFLAGS, &pmd->remote_initial_flags, 0, REMOTE_ONLY); + tap_ioctl(pmd, SIOCGIFFLAGS, &remote_ifr, 0, REMOTE_ONLY); + pmd->remote_flags = remote_ifr.ifr_flags; /* Replicate remote MAC address */ if (tap_ioctl(pmd, SIOCGIFHWADDR, &ifr, 0, REMOTE_ONLY) < 0) { @@ -2197,10 +2207,10 @@ set_interface_name(const char *key __rte_unused, value); return -1; } - strlcpy(name, value, RTE_ETH_NAME_MAX_LEN); + strlcpy(name, value, IFNAMSIZ); } else { /* use tap%d which causes kernel to choose next available */ - strlcpy(name, DEFAULT_TAP_NAME "%d", RTE_ETH_NAME_MAX_LEN); + strlcpy(name, DEFAULT_TAP_NAME "%d", IFNAMSIZ); } return 0; } @@ -2218,7 +2228,7 @@ set_remote_iface(const char *key __rte_unused, value); return -1; } - strlcpy(name, value, RTE_ETH_NAME_MAX_LEN); + strlcpy(name, value, IFNAMSIZ); } return 0; @@ -2269,13 +2279,13 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev) const char *name, *params; int ret; struct rte_kvargs *kvlist = NULL; - char tun_name[RTE_ETH_NAME_MAX_LEN]; - char remote_iface[RTE_ETH_NAME_MAX_LEN]; + char tun_name[IFNAMSIZ]; + char remote_iface[IFNAMSIZ]; struct rte_eth_dev *eth_dev; name = rte_vdev_device_name(dev); params = rte_vdev_device_args(dev); - memset(remote_iface, 0, RTE_ETH_NAME_MAX_LEN); + memset(remote_iface, 0, IFNAMSIZ); if (rte_eal_process_type() == RTE_PROC_SECONDARY && strlen(params) == 0) { @@ -2291,7 +2301,7 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev) } /* use tun%d which causes kernel to choose next available */ - strlcpy(tun_name, DEFAULT_TUN_NAME "%d", RTE_ETH_NAME_MAX_LEN); + strlcpy(tun_name, DEFAULT_TUN_NAME "%d", IFNAMSIZ); if (params && (params[0] != '\0')) { TAP_LOG(DEBUG, "parameters (%s)", params); @@ -2431,8 +2441,8 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev) int ret; struct rte_kvargs *kvlist = NULL; int speed; - char tap_name[RTE_ETH_NAME_MAX_LEN]; - char remote_iface[RTE_ETH_NAME_MAX_LEN]; + char tap_name[IFNAMSIZ]; + char remote_iface[IFNAMSIZ]; struct rte_ether_addr user_mac = { .addr_bytes = {0} }; struct rte_eth_dev *eth_dev; int tap_devices_count_increased = 0; @@ -2486,8 +2496,8 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev) speed = RTE_ETH_SPEED_NUM_10G; /* use tap%d which causes kernel to choose next available */ - strlcpy(tap_name, DEFAULT_TAP_NAME "%d", RTE_ETH_NAME_MAX_LEN); - memset(remote_iface, 0, RTE_ETH_NAME_MAX_LEN); + strlcpy(tap_name, DEFAULT_TAP_NAME "%d", IFNAMSIZ); + memset(remote_iface, 0, IFNAMSIZ); if (params && (params[0] != '\0')) { TAP_LOG(DEBUG, "parameters (%s)", params); diff --git a/drivers/net/tap/rte_eth_tap.h b/drivers/net/tap/rte_eth_tap.h index ce4322ad04..ca510e2c6b 100644 --- a/drivers/net/tap/rte_eth_tap.h +++ b/drivers/net/tap/rte_eth_tap.h @@ -68,15 +68,16 @@ struct tx_queue { struct pmd_internals { struct rte_eth_dev *dev; /* Ethernet device. */ - char remote_iface[RTE_ETH_NAME_MAX_LEN]; /* Remote netdevice name */ - char name[RTE_ETH_NAME_MAX_LEN]; /* Internal Tap device name */ + char remote_iface[IFNAMSIZ]; /* Remote netdevice name */ + char name[IFNAMSIZ]; /* Internal Tap device name */ int type; /* Type field - TUN|TAP */ int persist; /* 1 if keep link up, else 0 */ struct rte_ether_addr eth_addr; /* Mac address of the device port */ - struct ifreq remote_initial_flags;/* Remote netdevice flags on init */ + uint16_t remote_flags; /* Remote netdevice flags on init */ int remote_if_index; /* remote netdevice IF_INDEX */ int if_index; /* IF_INDEX for the port */ int ioctl_sock; /* socket for ioctl calls */ + int ka_fd; /* keep-alive file descriptor */ #ifdef HAVE_TCA_FLOWER int nlsk_fd; /* Netlink socket fd */ @@ -88,12 +89,11 @@ struct pmd_internals { /* implicit rte_flow rules set when a remote device is active */ LIST_HEAD(tap_implicit_flows, rte_flow) implicit_flows; #endif + struct rte_intr_handle *intr_handle; /* LSC interrupt handle. */ + struct rte_mempool *gso_ctx_mp; /* Mempool for GSO packets */ struct rx_queue rxq[RTE_PMD_TAP_MAX_QUEUES]; /* List of RX queues */ struct tx_queue txq[RTE_PMD_TAP_MAX_QUEUES]; /* List of TX queues */ - struct rte_intr_handle *intr_handle; /* LSC interrupt handle. */ - int ka_fd; /* keep-alive file descriptor */ - struct rte_mempool *gso_ctx_mp; /* Mempool for GSO packets */ }; struct pmd_process_private { -- 2.43.0