From patchwork Fri Dec 2 11:25:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Vadai X-Patchwork-Id: 701931 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3tVWzf6Lzpz9t0J for ; Fri, 2 Dec 2016 22:25:34 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760366AbcLBLZb (ORCPT ); Fri, 2 Dec 2016 06:25:31 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:36298 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759232AbcLBLZ3 (ORCPT ); Fri, 2 Dec 2016 06:25:29 -0500 Received: by mail-wm0-f65.google.com with SMTP id m203so2218887wma.3 for ; Fri, 02 Dec 2016 03:25:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=P8t/h/eS9tk8c+EXIrmoY+69cSO8VfFGqZGOSiBb/q0=; b=fECy6Ph7S1XX3K5TA6UuUEREYcHVqE9CE5adp5xF4bZbzpiobJgKv/yrVHMo+bK1E/ mqiTzO1iM/A66f08rf+yUZlm3srh7TADTEpOCVzDo0pV5FHKN7KvWzGWD8jWW7bZc4qT o/4e30VRKSPFfENLWDG+C+HcGv5KlZOK53ahMo8Wdmm78tS6Md6Y3qQOrP90IzOvech3 zfpNRxsFI+bORHmTOSDJ99JwfOJC0FMwUDne1t4ZpVFAGrjqLi2UkcwhqU9L/diSjgOA S65XswfuAhPmDMiaEPWFQTkbWdEadapwSL3d9wJaxvyajSp7vAkzh28l0Anf6ilugwhZ FU6Q== X-Gm-Message-State: AKaTC03VhQVcAcgFTBzPZV9EYNTEP26H/lGo5vyaU5KcR6NLub8ZvU0VA+ElbljqNZw1pA== X-Received: by 10.28.209.7 with SMTP id i7mr913644wmg.62.1480677928131; Fri, 02 Dec 2016 03:25:28 -0800 (PST) Received: from office.vadai.me ([192.116.94.210]) by smtp.gmail.com with ESMTPSA id cl6sm5084236wjc.10.2016.12.02.03.25.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Dec 2016 03:25:27 -0800 (PST) From: Amir Vadai To: Stephen Hemminger Cc: netdev@vger.kernel.org, "David S. Miller" , Or Gerlitz , Hadar Har-Zion , Roi Dayan , Amir Vadai Subject: [PATCH iproute2 V5 1/3] libnetlink: Introduce rta_getattr_be*() Date: Fri, 2 Dec 2016 13:25:13 +0200 Message-Id: <20161202112515.11705-2-amir@vadai.me> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161202112515.11705-1-amir@vadai.me> References: <20161202112515.11705-1-amir@vadai.me> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Add the utility functions rta_getattr_be16() and rta_getattr_be32(), and change existing code to use it. Signed-off-by: Amir Vadai --- bridge/fdb.c | 4 ++-- include/libnetlink.h | 9 +++++++++ ip/iplink_geneve.c | 2 +- ip/iplink_vxlan.c | 2 +- tc/f_flower.c | 2 +- 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/bridge/fdb.c b/bridge/fdb.c index 90f4b154c5dc..a91521776e99 100644 --- a/bridge/fdb.c +++ b/bridge/fdb.c @@ -168,10 +168,10 @@ int print_fdb(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) if (tb[NDA_PORT]) { if (jw_global) jsonw_uint_field(jw_global, "port", - ntohs(rta_getattr_u16(tb[NDA_PORT]))); + rta_getattr_be16(tb[NDA_PORT])); else fprintf(fp, "port %d ", - ntohs(rta_getattr_u16(tb[NDA_PORT]))); + rta_getattr_be16(tb[NDA_PORT])); } if (tb[NDA_VNI]) { diff --git a/include/libnetlink.h b/include/libnetlink.h index 483509ca9635..751ebf186dd4 100644 --- a/include/libnetlink.h +++ b/include/libnetlink.h @@ -10,6 +10,7 @@ #include #include #include +#include struct rtnl_handle { int fd; @@ -140,10 +141,18 @@ static inline __u16 rta_getattr_u16(const struct rtattr *rta) { return *(__u16 *)RTA_DATA(rta); } +static inline __be16 rta_getattr_be16(const struct rtattr *rta) +{ + return ntohs(rta_getattr_u16(rta)); +} static inline __u32 rta_getattr_u32(const struct rtattr *rta) { return *(__u32 *)RTA_DATA(rta); } +static inline __be32 rta_getattr_be32(const struct rtattr *rta) +{ + return ntohl(rta_getattr_u32(rta)); +} static inline __u64 rta_getattr_u64(const struct rtattr *rta) { __u64 tmp; diff --git a/ip/iplink_geneve.c b/ip/iplink_geneve.c index 3bfba91c644c..1e6669d07d60 100644 --- a/ip/iplink_geneve.c +++ b/ip/iplink_geneve.c @@ -234,7 +234,7 @@ static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) if (tb[IFLA_GENEVE_PORT]) fprintf(f, "dstport %u ", - ntohs(rta_getattr_u16(tb[IFLA_GENEVE_PORT]))); + rta_getattr_be16(tb[IFLA_GENEVE_PORT])); if (tb[IFLA_GENEVE_COLLECT_METADATA]) fputs("external ", f); diff --git a/ip/iplink_vxlan.c b/ip/iplink_vxlan.c index 93af979a1e97..6d02bb47b2f0 100644 --- a/ip/iplink_vxlan.c +++ b/ip/iplink_vxlan.c @@ -413,7 +413,7 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) if (tb[IFLA_VXLAN_PORT]) fprintf(f, "dstport %u ", - ntohs(rta_getattr_u16(tb[IFLA_VXLAN_PORT]))); + rta_getattr_be16(tb[IFLA_VXLAN_PORT])); if (tb[IFLA_VXLAN_LEARNING] && !rta_getattr_u8(tb[IFLA_VXLAN_LEARNING])) diff --git a/tc/f_flower.c b/tc/f_flower.c index 1555764b9996..e132974e0d1d 100644 --- a/tc/f_flower.c +++ b/tc/f_flower.c @@ -511,7 +511,7 @@ static void flower_print_ip_addr(FILE *f, char *name, __be16 eth_type, static void flower_print_port(FILE *f, char *name, struct rtattr *attr) { - fprintf(f, "\n %s %d", name, ntohs(rta_getattr_u16(attr))); + fprintf(f, "\n %s %d", name, rta_getattr_be16(attr)); } static int flower_print_opt(struct filter_util *qu, FILE *f,