From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f193.google.com (mail-wr0-f193.google.com [209.85.128.193]) by dpdk.org (Postfix) with ESMTP id BEF2C6D45 for ; Tue, 13 Mar 2018 13:29:46 +0100 (CET) Received: by mail-wr0-f193.google.com with SMTP id l8so7792213wrg.5 for ; Tue, 13 Mar 2018 05:29:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=jz9ZgCEX4CV1kb3AXitmygiimjn2AeYljppg6yRuKFU=; b=fqj1YexDPOHdqyAvf4dBcfzEziP81y1u68N6MgAYYo5G6EUwcSP5oQnv2cFp4i9DBD UsrOus25qt8Z5odLIzvrfi1/qsRnS5cqt1BuPWhAI1ZmF5+gJWz6BbMoAkDxY6QF5m7J +q3+2KFGoc3YWzieK4cDfxLyIWqYeQdmcm9x80t2fzpZv50Tl+A8/0DEyoaxZyztnndP /PvMSAL5OebH+MDhBZpbqcuLWnjtd35MpxPA5aOs5a/JVdxxYZoYwxaX2NwkEj5kEOBr pViKgtbhx9v7s/iKLk4JcsgyGrbIus+8y6QrsGeSN8mLLqO5cH9gAiMOrZiED7STHS5b +8EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=jz9ZgCEX4CV1kb3AXitmygiimjn2AeYljppg6yRuKFU=; b=CZO5QpSfxoNB6Qw2Ch65udjON8HGc1dpBMO7mgG/Bv3Upb4FdO8Nf5zEcxrUTR8Du9 LP/TsA6scPYJ5WRX73Tx7+9mrMm8vct65iTwK88zozVeO2xADs0kpDFuw5k5tUbCqGIZ SXxkn6xaLV1N1GybgrZg08SvgsOUIzfEBTXJ6cVZgPIeVb4TWnNgIbogbAVP/hB25IR7 9caTwwGo8x73j66cr3QF9Ms5vJu6HqOxzhJ9ijLK6dEgNuyBsCGaT8GOnK5qcGWXZJ71 JxVhq3X/fxVX00xBSs/O+WwKESBFfYbpFiWeEnT6bBfRTqqvZevcVGMN2w05xz0vj7N/ +qZg== X-Gm-Message-State: AElRT7FTndrYGUz2JhTymYOfkDD1PK9SPzjJhrdCPv+nuftuexbvmjRH onER7WgbjmXIHHb2M3OdDe6wfO56ug== X-Google-Smtp-Source: AG47ELvB9m1bYVc9AErMBMIo8Vd25P5w5Tbz9jvGL8myrzS874NpHu80KlPkhTdMyPsEkWpzw/3ifA== X-Received: by 10.223.142.244 with SMTP id q107mr470064wrb.64.1520944186463; Tue, 13 Mar 2018 05:29:46 -0700 (PDT) Received: from laranjeiro-vm.dev.6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id s8sm176148wrg.5.2018.03.13.05.29.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Mar 2018 05:29:45 -0700 (PDT) From: Nelio Laranjeiro To: Pascal Mazon Cc: dev@dpdk.org Date: Tue, 13 Mar 2018 13:28:27 +0100 Message-Id: <9a637b4ddc33ff2cc7f5311f9a69643dc5abdc13.1520943890.git.nelio.laranjeiro@6wind.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH 2/2] lib: add request Netlink messages 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, 13 Mar 2018 12:29:46 -0000 rte_nl_send() generate a message without request. In some situation, the drivers needs to retrieve information from the Kernel before requesting modifications. Cc: Pascal Mazon Signed-off-by: Nelio Laranjeiro --- lib/librte_netlink/rte_netlink.c | 45 ++++++++++++++++++++++++++++++ lib/librte_netlink/rte_netlink.h | 1 + lib/librte_netlink/rte_netlink_version.map | 1 + 3 files changed, 47 insertions(+) diff --git a/lib/librte_netlink/rte_netlink.c b/lib/librte_netlink/rte_netlink.c index a4ed07d30..a2020f6f8 100644 --- a/lib/librte_netlink/rte_netlink.c +++ b/lib/librte_netlink/rte_netlink.c @@ -125,6 +125,51 @@ rte_nl_send(int nlsk_fd, struct nlmsghdr *nh) } /** + * Send a request message to the kernel on the netlink socket. + * + * @param[in] nlsk_fd + * The netlink socket file descriptor used for communication. + * @param[in] nh + * The netlink message send to the kernel. + * @param[in] req + * Pointer to the request structure. + * @param[in] len + * Length of the request in bytes. + * + * @return + * the number of sent bytes on success, -1 otherwise. + */ +int +rte_nl_request(int nlsk_fd, struct nlmsghdr *nh, void *req, int len) +{ + /* man 7 netlink EXAMPLE */ + struct sockaddr_nl sa = { + .nl_family = AF_NETLINK, + }; + struct iovec iov[2] = { + { .iov_base = nh, .iov_len = sizeof(*nh), }, + { .iov_base = req, .iov_len = len, }, + }; + struct msghdr msg = { + .msg_name = &sa, + .msg_namelen = sizeof(sa), + .msg_iov = iov, + .msg_iovlen = 2, + }; + int send_bytes; + + nh->nlmsg_pid = 0; /* communication with the kernel uses pid 0 */ + nh->nlmsg_seq = (uint32_t)rte_rand(); + send_bytes = sendmsg(nlsk_fd, &msg, 0); + if (send_bytes < 0) { + RTE_LOG(ERR, PMD, "Failed to send netlink message: %s (%d)\n", + strerror(errno), errno); + return -1; + } + return send_bytes; +} + +/** * Check that the kernel sends an appropriate ACK in response * to an rte_nl_send(). * diff --git a/lib/librte_netlink/rte_netlink.h b/lib/librte_netlink/rte_netlink.h index 29f7d64c5..9af03e738 100644 --- a/lib/librte_netlink/rte_netlink.h +++ b/lib/librte_netlink/rte_netlink.h @@ -28,6 +28,7 @@ struct nlmsg { int rte_nl_init(uint32_t nl_groups); int rte_nl_final(int nlsk_fd); int rte_nl_send(int nlsk_fd, struct nlmsghdr *nh); +int rte_nl_request(int nlsk_fd, struct nlmsghdr *nh, void *req, int len); int rte_nl_recv(int nlsk_fd, int (*callback)(struct nlmsghdr *, void *), void *arg); int rte_nl_recv_ack(int nlsk_fd); diff --git a/lib/librte_netlink/rte_netlink_version.map b/lib/librte_netlink/rte_netlink_version.map index 5aa9b6228..a52254b36 100644 --- a/lib/librte_netlink/rte_netlink_version.map +++ b/lib/librte_netlink/rte_netlink_version.map @@ -4,6 +4,7 @@ DPDK_18.05 { rte_nl_init; rte_nl_final; rte_nl_send; + rte_nl_request; rte_nl_recv; rte_nl_recv_ack; rte_nlattr_add; -- 2.11.0