From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Charles (Chas) Williams" Subject: [PATCH v2 2/4] net/af_packet: add support to change mtu Date: Thu, 5 Jan 2017 08:53:42 -0500 Message-ID: <1483624424-2806-2-git-send-email-ciwillia@brocade.com> References: <1483624424-2806-1-git-send-email-ciwillia@brocade.com> Mime-Version: 1.0 Content-Type: text/plain Cc: , "Charles (Chas) Williams" To: Return-path: Received: from mx0a-000f0801.pphosted.com (mx0b-000f0801.pphosted.com [67.231.152.113]) by dpdk.org (Postfix) with ESMTP id 89BE1D586 for ; Thu, 5 Jan 2017 14:54:00 +0100 (CET) In-Reply-To: <1483624424-2806-1-git-send-email-ciwillia@brocade.com> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The underlying linux device's MTU is changed subject to the frame size limitations during device creation. Signed-off-by: Charles (Chas) Williams --- drivers/net/af_packet/rte_eth_af_packet.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c index 4ef61a2..a700b96 100644 --- a/drivers/net/af_packet/rte_eth_af_packet.c +++ b/drivers/net/af_packet/rte_eth_af_packet.c @@ -412,12 +412,41 @@ eth_tx_queue_setup(struct rte_eth_dev *dev, return 0; } +static int +eth_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu) +{ + struct pmd_internals *internals = dev->data->dev_private; + struct ifreq ifr = { .ifr_mtu = mtu }; + int ret; + int s; + unsigned int data_size = internals->req.tp_frame_size - + TPACKET2_HDRLEN - + sizeof(struct sockaddr_ll); + + if (mtu > data_size) + return -EINVAL; + + s = socket(PF_INET, SOCK_DGRAM, 0); + if (s < 0) + return -EINVAL; + + strncpy(ifr.ifr_name, internals->if_name, IFNAMSIZ); + ret = ioctl(s, SIOCSIFMTU, &ifr); + close(s); + + if (ret < 0) + return -EINVAL; + + return 0; +} + static const struct eth_dev_ops ops = { .dev_start = eth_dev_start, .dev_stop = eth_dev_stop, .dev_close = eth_dev_close, .dev_configure = eth_dev_configure, .dev_infos_get = eth_dev_info, + .mtu_set = eth_dev_mtu_set, .rx_queue_setup = eth_rx_queue_setup, .tx_queue_setup = eth_tx_queue_setup, .rx_queue_release = eth_queue_release, -- 2.1.4