From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from proxy.6wind.com (host.76.145.23.62.rev.coltfrance.com [62.23.145.76]) by dpdk.org (Postfix) with ESMTP id A3B2B3237 for ; Tue, 31 Jan 2017 10:45:01 +0100 (CET) Received: from 6wind.com (unknown [10.16.0.184]) by proxy.6wind.com (Postfix) with SMTP id 644A5265B0; Tue, 31 Jan 2017 10:44:56 +0100 (CET) Received: by 6wind.com (sSMTP sendmail emulation); Tue, 31 Jan 2017 10:43:19 +0100 From: Pascal Mazon To: keith.wiles@intel.com Cc: dev@dpdk.org, Pascal Mazon Date: Tue, 31 Jan 2017 10:42:58 +0100 Message-Id: <1485855778-15496-6-git-send-email-pascal.mazon@6wind.com> X-Mailer: git-send-email 2.8.0.rc0 In-Reply-To: <1485855778-15496-1-git-send-email-pascal.mazon@6wind.com> References: <1485855778-15496-1-git-send-email-pascal.mazon@6wind.com> Subject: [dpdk-dev] [PATCH 6/6] net/tap: implement link up and down callbacks 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: Tue, 31 Jan 2017 09:45:01 -0000 Signed-off-by: Pascal Mazon --- drivers/net/tap/rte_eth_tap.c | 59 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c index 734e3a579219..9b6bbff5fd81 100644 --- a/drivers/net/tap/rte_eth_tap.c +++ b/drivers/net/tap/rte_eth_tap.c @@ -405,6 +405,63 @@ tap_link_update(struct rte_eth_dev *dev __rte_unused, return 0; } +static int tap_link_set(struct pmd_internals *pmd, int state) +{ + struct ifreq ifr; + int err, s; + + /* + * An AF_INET/DGRAM socket is needed for + * SIOCGIFFLAGS/SIOCSIFFLAGS, using fd won't work. + */ + s = socket(AF_INET, SOCK_DGRAM, 0); + if (s < 0) { + RTE_LOG(ERR, PMD, + "Unable to get a socket to set flags: %s\n", + strerror(errno)); + return -1; + } + memset(&ifr, 0, sizeof(ifr)); + strncpy(ifr.ifr_name, pmd->name, IFNAMSIZ); + err = ioctl(s, SIOCGIFFLAGS, &ifr); + if (err < 0) { + RTE_LOG(ERR, PMD, "Unable to get tap netdevice flags: %s\n", + strerror(errno)); + close(s); + return -1; + } + if (state == ETH_LINK_UP) + ifr.ifr_flags |= IFF_UP | IFF_NOARP; + else + ifr.ifr_flags &= ~(IFF_UP | IFF_NOARP); + err = ioctl(s, SIOCSIFFLAGS, &ifr); + if (err < 0) { + RTE_LOG(ERR, PMD, "Unable to set flags %s: %s\n", + state == ETH_LINK_UP ? "UP" : "DOWN", strerror(errno)); + close(s); + return -1; + } + close(s); + + return 0; +} + +static int +tap_link_set_down(struct rte_eth_dev *dev) +{ + struct pmd_internals *pmd = dev->data->dev_private; + + return tap_link_set(pmd, ETH_LINK_DOWN); +} + +static int +tap_link_set_up(struct rte_eth_dev *dev) +{ + struct pmd_internals *pmd = dev->data->dev_private; + + return tap_link_set(pmd, ETH_LINK_UP); +} + static int tap_setup_queue(struct rte_eth_dev *dev, struct pmd_internals *internals, @@ -532,6 +589,8 @@ static const struct eth_dev_ops ops = { .rx_queue_release = tap_rx_queue_release, .tx_queue_release = tap_tx_queue_release, .link_update = tap_link_update, + .dev_set_link_up = tap_link_set_up, + .dev_set_link_down = tap_link_set_down, .stats_get = tap_stats_get, .stats_reset = tap_stats_reset, }; -- 2.8.0.rc0