From e369a7590be342ed32b5fa241dd76f242d0f54ca Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Fri, 17 Mar 2017 13:23:10 +0100 Subject: [PATCH] libnetlink: Introduce rta_getattr_be*() Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1422629 Upstream Status: iproute2.git commit aab0f61043098 Conflicts: Changes to bridge code applied manually due to missing json output support. commit aab0f61043098e1384b5161ba78f583599a87e12 Author: Amir Vadai Date: Fri Dec 2 13:25:13 2016 +0200 libnetlink: Introduce rta_getattr_be*() 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 | 2 +- include/libnetlink.h | 9 +++++++++ ip/iplink_geneve.c | 2 +- ip/iplink_vxlan.c | 2 +- tc/f_flower.c | 2 +- 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/bridge/fdb.c b/bridge/fdb.c index 4b536f9..a1bc45f 100644 --- a/bridge/fdb.c +++ b/bridge/fdb.c @@ -125,7 +125,7 @@ int print_fdb(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) fprintf(fp, "vlan %hu ", vid); if (tb[NDA_PORT]) - fprintf(fp, "port %d ", ntohs(rta_getattr_u16(tb[NDA_PORT]))); + fprintf(fp, "port %d ", rta_getattr_be16(tb[NDA_PORT])); if (tb[NDA_VNI]) fprintf(fp, "vni %d ", rta_getattr_u32(tb[NDA_VNI])); if (tb[NDA_IFINDEX]) { diff --git a/include/libnetlink.h b/include/libnetlink.h index 7ea3f4a..9a25ec4 100644 --- a/include/libnetlink.h +++ b/include/libnetlink.h @@ -10,6 +10,7 @@ #include #include #include +#include struct rtnl_handle { @@ -131,10 +132,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 2e15a1d..8f130a3 100644 --- a/ip/iplink_geneve.c +++ b/ip/iplink_geneve.c @@ -231,7 +231,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 6cae35b..bf56864 100644 --- a/ip/iplink_vxlan.c +++ b/ip/iplink_vxlan.c @@ -348,7 +348,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 805e841..75e64ae 100644 --- a/tc/f_flower.c +++ b/tc/f_flower.c @@ -512,7 +512,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, -- 1.8.3.1