From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-f195.google.com (mail-qk1-f195.google.com [209.85.222.195]) by dpdk.org (Postfix) with ESMTP id 041794CA2 for ; Wed, 17 Oct 2018 03:04:38 +0200 (CEST) Received: by mail-qk1-f195.google.com with SMTP id m8-v6so15432357qka.12 for ; Tue, 16 Oct 2018 18:04:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kajm2DsQimx0cTUYq2+GByK6yINDQv2WFTOI11ERKtk=; b=eZsASNI8wpBsntWnZmZ5QDB8a5lFZjbhnhr1MqJBjrCzV6kyUGNPYE/jng6nGatkRU NolFVfCmxsnIFliY/LLTjvWj1PuFUsvPn2XbJZAGOKH578yQg2O1mmKgcQAZjD0Rg8GV qwVtvE4tcXak0XMkLbuJ6upaUjMbEt1eUh0TLAFDOeq7DOa+1z2BZfw7qKyHmPiX9HxN 2YXUGWHhIFaYPKUsZbXwhyU0uBmYvHoFkHlz0c4Nnggru3AFx1PeVBM6NpUn7gmdMcVh tr4xDf1sj3RiJKlQFojPfBY97l6RwRLzWIw0egWP8TeOfIiRAEsiHhtJqlaNLJ4BssOv Ua7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=kajm2DsQimx0cTUYq2+GByK6yINDQv2WFTOI11ERKtk=; b=sAjJ2VBL+gcgfG3x4Da8A+507Ka+fsLhDo+riQk2bW+V4baI/ZqjJ1KQb1qGMetuly 5JXC9/a5ERaAWpRKQUD00vj1AP9O6ilcfuKld21yPiUFe1Ya2PBFUHKmrRzeNoQL6/C8 n3t7j5q9QgMl/tDSV7QohEDyjKaFtoxCSESJEanQJg1YmkRNVFe9DcF2CN5WGt2dznPA eLeuQSWJShtREJ2Kqz7FR7dZkZRsxiqA+Et28b5VEMCnmTUZRGLDzZFRX5tWrqZ5zyOA tOfV3ZB8qUtdDmIW04Y5/w91G6G8rJFVqybxO7cAan493YOEwqjHLo2MrQBiGfhlUQ3z VDUA== X-Gm-Message-State: ABuFfogFNpumBrmOHMWjEl/mCUjatOxnTu+TJoAw3SwGAliu0pNGnYdN gquMzaVY9goMT3UhBfyfzljB2U8m8qA= X-Google-Smtp-Source: ACcGV63zTxkUIW91RAjWwnFMTcOmwvex/xCxkUDcxNR0Cjn4tOdU1P1F77xzxhqHT74wWT/23KtpUQ== X-Received: by 2002:a37:3245:: with SMTP id y66-v6mr22208117qky.205.1539738277897; Tue, 16 Oct 2018 18:04:37 -0700 (PDT) Received: from snappy.local.lan ([187.74.142.5]) by smtp.gmail.com with ESMTPSA id v54-v6sm19547508qtc.81.2018.10.16.18.04.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Oct 2018 18:04:37 -0700 (PDT) Sender: Dan Gora From: Dan Gora To: dev@dpdk.org Cc: Igor Ryzhov , Stephen Hemminger , Ferruh Yigit , Dan Gora Date: Tue, 16 Oct 2018 22:04:08 -0300 Message-Id: <20181017010412.23141-2-dg@adax.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180911232906.18352-1-dg@adax.com> References: <20180911232906.18352-1-dg@adax.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v4 1/6] kni: add API to set link status on kernel interface 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: Wed, 17 Oct 2018 01:04:39 -0000 Add a new API function to KNI, rte_kni_update_link() to allow DPDK applications to update the link status for KNI network interfaces in the linux kernel. Signed-off-by: Dan Gora --- lib/librte_kni/rte_kni.c | 41 ++++++++++++++++++++++++++++++ lib/librte_kni/rte_kni.h | 20 +++++++++++++++ lib/librte_kni/rte_kni_version.map | 6 +++++ 3 files changed, 67 insertions(+) diff --git a/lib/librte_kni/rte_kni.c b/lib/librte_kni/rte_kni.c index b8edd40f4..c9726d4f8 100644 --- a/lib/librte_kni/rte_kni.c +++ b/lib/librte_kni/rte_kni.c @@ -717,6 +717,47 @@ rte_kni_unregister_handlers(struct rte_kni *kni) return 0; } + +int __rte_experimental +rte_kni_update_link(struct rte_kni *kni, unsigned int linkup) +{ + char path[64]; + char old_carrier[2]; + const char *new_carrier; + int old_linkup; + int fd, ret; + + if (kni == NULL) + return -1; + + snprintf(path, sizeof(path), "/sys/devices/virtual/net/%s/carrier", + kni->name); + + fd = open(path, O_RDWR); + if (fd == -1) { + RTE_LOG(ERR, KNI, "Failed to open file: %s.\n", path); + return -1; + } + + ret = read(fd, old_carrier, 2); + if (ret < 1) { + close(fd); + return -1; + } + old_linkup = (old_carrier[0] == '1'); + + new_carrier = linkup ? "1" : "0"; + ret = write(fd, new_carrier, 1); + if (ret < 1) { + RTE_LOG(ERR, KNI, "Failed to write file: %s.\n", path); + close(fd); + return -1; + } + + close(fd); + return old_linkup; +} + void rte_kni_close(void) { diff --git a/lib/librte_kni/rte_kni.h b/lib/librte_kni/rte_kni.h index 601abdfc6..02ca43b4b 100644 --- a/lib/librte_kni/rte_kni.h +++ b/lib/librte_kni/rte_kni.h @@ -232,6 +232,26 @@ int rte_kni_register_handlers(struct rte_kni *kni, struct rte_kni_ops *ops); */ int rte_kni_unregister_handlers(struct rte_kni *kni); +/** + * Update link carrier state for KNI port. + * + * Update the linkup/linkdown state of a KNI interface in the kernel. + * + * @param kni + * pointer to struct rte_kni. + * @param linkup + * New link state: + * 0 for linkdown. + * > 0 for linkup. + * + * @return + * On failure: -1 + * Previous link state == linkdown: 0 + * Previous link state == linkup: 1 + */ +int __rte_experimental +rte_kni_update_link(struct rte_kni *kni, unsigned int linkup); + /** * Close KNI device. */ diff --git a/lib/librte_kni/rte_kni_version.map b/lib/librte_kni/rte_kni_version.map index acd515eb0..c877dc6aa 100644 --- a/lib/librte_kni/rte_kni_version.map +++ b/lib/librte_kni/rte_kni_version.map @@ -15,3 +15,9 @@ DPDK_2.0 { local: *; }; + +EXPERIMENTAL { + global: + + rte_kni_update_link; +}; -- 2.19.0