From: Amir Vadai Date: Fri, 2 Dec 2016 11:25:13 +0000 (+0200) Subject: libnetlink: Introduce rta_getattr_be*() X-Git-Tag: v4.10.0~97 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aab0f61043098e1384b5161ba78f583599a87e12;p=thirdparty%2Fiproute2.git 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 --- diff --git a/bridge/fdb.c b/bridge/fdb.c index 90f4b154c..a91521776 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 483509ca9..751ebf186 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 3bfba91c6..1e6669d07 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 93af979a1..6d02bb47b 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 1555764b9..e132974e0 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,