From patchwork Tue Sep 29 22:10:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thadeu Lima de Souza Cascardo X-Patchwork-Id: 524036 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (unknown [IPv6:2600:3c00::f03c:91ff:fe6e:bdf7]) by ozlabs.org (Postfix) with ESMTP id DA10B1400B7 for ; Wed, 30 Sep 2015 08:11:31 +1000 (AEST) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 63DBC108DE; Tue, 29 Sep 2015 15:11:24 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx1e4.cudamail.com (mx1.cudamail.com [69.90.118.67]) by archives.nicira.com (Postfix) with ESMTPS id E9FDD108C8 for ; Tue, 29 Sep 2015 15:11:22 -0700 (PDT) Received: from bar5.cudamail.com (unknown [192.168.21.12]) by mx1e4.cudamail.com (Postfix) with ESMTPS id 754491E043A for ; Tue, 29 Sep 2015 16:11:22 -0600 (MDT) X-ASG-Debug-ID: 1443564678-09eadd11dc6e0580001-byXFYA Received: from mx1-pf2.cudamail.com ([192.168.24.2]) by bar5.cudamail.com with ESMTP id MxmDEIZdW3YNXMd8 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 29 Sep 2015 16:11:18 -0600 (MDT) X-Barracuda-Envelope-From: cascardo@redhat.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.24.2 Received: from unknown (HELO mx1.redhat.com) (209.132.183.28) by mx1-pf2.cudamail.com with ESMTPS (DHE-RSA-AES256-SHA encrypted); 29 Sep 2015 22:11:17 -0000 Received-SPF: pass (mx1-pf2.cudamail.com: SPF record at _spf1.redhat.com designates 209.132.183.28 as permitted sender) X-Barracuda-Apparent-Source-IP: 209.132.183.28 X-Barracuda-RBL-IP: 209.132.183.28 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id C05492FD9D5 for ; Tue, 29 Sep 2015 22:11:16 +0000 (UTC) Received: from indiana.gru.redhat.com ([10.96.73.207]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t8TMBEdG014409 for ; Tue, 29 Sep 2015 18:11:16 -0400 X-CudaMail-Envelope-Sender: cascardo@redhat.com From: Thadeu Lima de Souza Cascardo To: dev@openvswitch.org X-CudaMail-MID: CM-E2-928112223 X-CudaMail-DTE: 092915 X-CudaMail-Originating-IP: 209.132.183.28 Date: Tue, 29 Sep 2015 19:10:55 -0300 X-ASG-Orig-Subj: [##CM-E2-928112223##][RFC PATCH 4/7] netlink: helper functions for ipv6 address in netlink attrs Message-Id: <1443564658-12251-2-git-send-email-cascardo@redhat.com> In-Reply-To: <1443564658-12251-1-git-send-email-cascardo@redhat.com> References: <1443564658-12251-1-git-send-email-cascardo@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-GBUdb-Analysis: 0, 209.132.183.28, Ugly c=0.264319 p=-0.0769231 Source Normal X-MessageSniffer-Rules: 0-0-0-8958-c X-Barracuda-Connect: UNKNOWN[192.168.24.2] X-Barracuda-Start-Time: 1443564678 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.60 X-Barracuda-Spam-Status: No, SCORE=0.60 using per-user scores of TAG_LEVEL=3.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=3.0 tests=BSF_SC5_MJ1963, RDNS_NONE X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.23026 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.10 RDNS_NONE Delivered to trusted network by a host with no rDNS 0.50 BSF_SC5_MJ1963 Custom Rule MJ1963 Subject: [ovs-dev] [RFC PATCH 4/7] netlink: helper functions for ipv6 address in netlink attrs X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" From: Jiri Benc [cascardo: add NL_A_IPV6, used in next patch] Signed-off-by: Jiri Benc Signed-off-by: Thadeu Lima de Souza Cascardo --- lib/netlink.c | 20 ++++++++++++++++++++ lib/netlink.h | 6 ++++++ 2 files changed, 26 insertions(+) diff --git a/lib/netlink.c b/lib/netlink.c index 09723b2..6bb3537 100644 --- a/lib/netlink.c +++ b/lib/netlink.c @@ -308,6 +308,15 @@ nl_msg_put_be64(struct ofpbuf *msg, uint16_t type, ovs_be64 value) nl_msg_put_unspec(msg, type, &value, sizeof value); } +/* Appends a Netlink attribute of the given 'type' and the given IPv6 + * address order 'value' to 'msg'. */ +void +nl_msg_put_in6_addr(struct ofpbuf *msg, uint16_t type, + const struct in6_addr *value) +{ + nl_msg_put_unspec(msg, type, value, sizeof *value); +} + /* Appends a Netlink attribute of the given 'type' and the given odp_port_t * 'value' to 'msg'. */ void @@ -603,6 +612,15 @@ nl_attr_get_be64(const struct nlattr *nla) return get_32aligned_be64(x); } +/* Returns the IPv6 address value in 'nla''s payload. + * + * Asserts that 'nla''s payload is at least 16 bytes long. */ +struct in6_addr +nl_attr_get_in6_addr(const struct nlattr *nla) +{ + return NL_ATTR_GET_AS(nla, struct in6_addr); +} + /* Returns the 32-bit odp_port_t value in 'nla''s payload. * * Asserts that 'nla''s payload is at least 4 bytes long. */ @@ -643,6 +661,7 @@ min_attr_len(enum nl_attr_type type) case NL_A_U64: return 8; case NL_A_STRING: return 1; case NL_A_FLAG: return 0; + case NL_A_IPV6: return 16; case NL_A_NESTED: return 0; case N_NL_ATTR_TYPES: default: OVS_NOT_REACHED(); } @@ -661,6 +680,7 @@ max_attr_len(enum nl_attr_type type) case NL_A_U64: return 8; case NL_A_STRING: return SIZE_MAX; case NL_A_FLAG: return SIZE_MAX; + case NL_A_IPV6: return 16; case NL_A_NESTED: return SIZE_MAX; case N_NL_ATTR_TYPES: default: OVS_NOT_REACHED(); } diff --git a/lib/netlink.h b/lib/netlink.h index 6068f5d..eed71dd 100644 --- a/lib/netlink.h +++ b/lib/netlink.h @@ -31,6 +31,7 @@ * Linux-specific definitions for Netlink sockets, see netlink-socket.h. */ +#include #include #include #include @@ -69,6 +70,8 @@ void nl_msg_put_u64(struct ofpbuf *, uint16_t type, uint64_t value); void nl_msg_put_be16(struct ofpbuf *, uint16_t type, ovs_be16 value); void nl_msg_put_be32(struct ofpbuf *, uint16_t type, ovs_be32 value); void nl_msg_put_be64(struct ofpbuf *, uint16_t type, ovs_be64 value); +void nl_msg_put_in6_addr(struct ofpbuf *msg, uint16_t type, + const struct in6_addr *value); void nl_msg_put_odp_port(struct ofpbuf *, uint16_t type, odp_port_t value); void nl_msg_put_string(struct ofpbuf *, uint16_t type, const char *value); @@ -111,6 +114,7 @@ struct nlmsghdr *nl_msg_next(struct ofpbuf *buffer, struct ofpbuf *msg); #define NL_A_BE32_SIZE NL_ATTR_SIZE(sizeof(ovs_be32)) #define NL_A_BE64_SIZE NL_ATTR_SIZE(sizeof(ovs_be64)) #define NL_A_FLAG_SIZE NL_ATTR_SIZE(0) +#define NL_A_IPV6_SIZE NL_ATTR_SIZE(sizeof(struct in6_addr)) bool nl_attr_oversized(size_t payload_size); @@ -128,6 +132,7 @@ enum nl_attr_type NL_A_BE64 = NL_A_U64, NL_A_STRING, NL_A_FLAG, + NL_A_IPV6, NL_A_NESTED, N_NL_ATTR_TYPES }; @@ -189,6 +194,7 @@ uint64_t nl_attr_get_u64(const struct nlattr *); ovs_be16 nl_attr_get_be16(const struct nlattr *); ovs_be32 nl_attr_get_be32(const struct nlattr *); ovs_be64 nl_attr_get_be64(const struct nlattr *); +struct in6_addr nl_attr_get_in6_addr(const struct nlattr *nla); odp_port_t nl_attr_get_odp_port(const struct nlattr *); const char *nl_attr_get_string(const struct nlattr *); void nl_attr_get_nested(const struct nlattr *, struct ofpbuf *);