From fa0874ac0258fe335baa8c96d8f4955ebe2736a5 Mon Sep 17 00:00:00 2001 From: Shankara Pailoor Date: Wed, 9 Jan 2019 09:09:04 -0800 Subject: [PATCH] sockaddr: print sin6_flowinfo field before sin6_addr The sin6_flowinfo field comes before sin6_addr in the sockaddr_in6 defintion, but for some reason we switch the order when decoding. This patch fixes the order of decoding. * sockaddr.c (print_sockaddr_data_in6): Print sin6_flowinfo field before sin6_addr. * NEWS: Mention this fix. * tests/group_req.c (main): Update expected output. * tests/net-sockaddr.c (check_in6_linklocal, check_in6): Likewise. * tests/net-yy-inet6.c (INADDR_STR, SA_FIELDS): Likewise. * tests/sockaddr_xlat.c (validate_in6): Likewise. --- NEWS | 1 + sockaddr.c | 2 +- tests/group_req.c | 4 ++-- tests/net-sockaddr.c | 26 ++++++++++++++------------ tests/net-yy-inet6.c | 5 +++-- tests/sockaddr_xlat.c | 27 ++++++++++++--------------- 6 files changed, 33 insertions(+), 32 deletions(-) diff --git a/NEWS b/NEWS index 2e813840..4d7d5696 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,7 @@ Noteworthy changes in release ?.?? (????-??-??) constants. * Bug fixes + * Fixed ordering of sockaddr_in6 fields. * Fixed strace-k test on alpha. * Fixed build on mips o32. * Fixed build on NOMMU architectures. diff --git a/sockaddr.c b/sockaddr.c index b5abb5b7..4c306c1a 100644 --- a/sockaddr.c +++ b/sockaddr.c @@ -188,7 +188,6 @@ print_sockaddr_data_in6(const void *const buf, const int addrlen) const struct sockaddr_in6 *const sa_in6 = buf; PRINT_FIELD_NET_PORT("", *sa_in6, sin6_port); - PRINT_FIELD_INET_ADDR(", ", *sa_in6, sin6_addr, AF_INET6); tprints(", sin6_flowinfo="); if (xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV) print_quoted_string((const char*) &sa_in6->sin6_flowinfo, @@ -201,6 +200,7 @@ print_sockaddr_data_in6(const void *const buf, const int addrlen) if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_ABBREV) tprintf("htonl(%u)", ntohl(sa_in6->sin6_flowinfo)); + PRINT_FIELD_INET_ADDR(", ", *sa_in6, sin6_addr, AF_INET6); if (addrlen <= (int) SIN6_MIN_LEN) return; diff --git a/tests/group_req.c b/tests/group_req.c index 575e1569..1a29d1a5 100644 --- a/tests/group_req.c +++ b/tests/group_req.c @@ -76,15 +76,15 @@ main(void) { ARG_STR(SOL_IPV6), ARG_STR(MCAST_JOIN_GROUP), greq6, "gr_group={sa_family=AF_INET6, sin6_port=htons(65535)" - ", inet_pton(AF_INET6, \"" multi6addr "\", &sin6_addr)" ", sin6_flowinfo=htonl(4294967295)" + ", inet_pton(AF_INET6, \"" multi6addr "\", &sin6_addr)" ", sin6_scope_id=4294967295}" }, { ARG_STR(SOL_IPV6), ARG_STR(MCAST_LEAVE_GROUP), greq6, "gr_group={sa_family=AF_INET6, sin6_port=htons(65535)" - ", inet_pton(AF_INET6, \"" multi6addr "\", &sin6_addr)" ", sin6_flowinfo=htonl(4294967295)" + ", inet_pton(AF_INET6, \"" multi6addr "\", &sin6_addr)" ", sin6_scope_id=4294967295}" } }; diff --git a/tests/net-sockaddr.c b/tests/net-sockaddr.c index 95c10f14..dec1d875 100644 --- a/tests/net-sockaddr.c +++ b/tests/net-sockaddr.c @@ -156,22 +156,22 @@ check_in6_linklocal(struct sockaddr_in6 *const in6, const char *const h_addr) unsigned int len = sizeof(*in6); int ret = connect(-1, (void *) in6, len); printf("connect(-1, {sa_family=AF_INET6, sin6_port=htons(%hu)" - ", inet_pton(AF_INET6, \"%s\", &sin6_addr)" ", sin6_flowinfo=htonl(%u)" + ", inet_pton(AF_INET6, \"%s\", &sin6_addr)" ", sin6_scope_id=%u}, %u)" " = %d EBADF (%m)\n", - ntohs(in6->sin6_port), h_addr, - ntohl(in6->sin6_flowinfo), in6->sin6_scope_id, len, ret); + ntohs(in6->sin6_port), ntohl(in6->sin6_flowinfo), + h_addr, in6->sin6_scope_id, len, ret); in6->sin6_scope_id = ifindex_lo(); if (in6->sin6_scope_id) { ret = connect(-1, (void *) in6, len); printf("connect(-1, {sa_family=AF_INET6, sin6_port=htons(%hu)" - ", inet_pton(AF_INET6, \"%s\", &sin6_addr)" ", sin6_flowinfo=htonl(%u)" + ", inet_pton(AF_INET6, \"%s\", &sin6_addr)" ", sin6_scope_id=%s}, %u)" " = %d EBADF (%m)\n", - ntohs(in6->sin6_port), h_addr, ntohl(in6->sin6_flowinfo), + ntohs(in6->sin6_port), ntohl(in6->sin6_flowinfo), h_addr, IFINDEX_LO_STR, len, ret); } } @@ -192,10 +192,11 @@ check_in6(void) unsigned int len = sizeof(*in6); int ret = connect(-1, (void *) in6, len); printf("connect(-1, {sa_family=AF_INET6, sin6_port=htons(%hu)" + ", sin6_flowinfo=htonl(%u)" ", inet_pton(AF_INET6, \"%s\", &sin6_addr)" - ", sin6_flowinfo=htonl(%u), sin6_scope_id=%u}, %u)" + ", sin6_scope_id=%u}, %u)" " = %d EBADF (%m)\n", - h_port, h_addr, h_flowinfo, in6->sin6_scope_id, len, ret); + h_port, h_flowinfo, h_addr, in6->sin6_scope_id, len, ret); check_in6_linklocal(in6, "fe80::"); check_in6_linklocal(in6, "ff42::"); @@ -209,10 +210,11 @@ check_in6(void) len = sizeof(*in6) + 4; ret = connect(-1, (void *) in6, len); printf("connect(-1, {sa_family=AF_INET6, sin6_port=htons(%hu)" + ", sin6_flowinfo=htonl(%u)" ", inet_pton(AF_INET6, \"%s\", &sin6_addr)" - ", sin6_flowinfo=htonl(%u), sin6_scope_id=%u}, %u)" + ", sin6_scope_id=%u}, %u)" " = %d EBADF (%m)\n", - h_port, h_addr, h_flowinfo, in6->sin6_scope_id, len, ret); + h_port, h_flowinfo, h_addr, in6->sin6_scope_id, len, ret); in6 = ((void *) in6) + 4 + sizeof(in6->sin6_scope_id); in6->sin6_family = AF_INET6; @@ -222,10 +224,10 @@ check_in6(void) len = sizeof(*in6) - sizeof(in6->sin6_scope_id); ret = connect(-1, (void *) in6, len); printf("connect(-1, {sa_family=AF_INET6, sin6_port=htons(%hu)" - ", inet_pton(AF_INET6, \"%s\", &sin6_addr)" - ", sin6_flowinfo=htonl(%u)}, %u)" + ", sin6_flowinfo=htonl(%u)" + ", inet_pton(AF_INET6, \"%s\", &sin6_addr)}, %u)" " = %d EBADF (%m)\n", - h_port, h_addr, h_flowinfo, len, ret); + h_port, h_flowinfo, h_addr, len, ret); in6 = ((void *) in6) + 4; in6->sin6_family = AF_INET6; diff --git a/tests/net-yy-inet6.c b/tests/net-yy-inet6.c index a993c660..7040c12e 100644 --- a/tests/net-yy-inet6.c +++ b/tests/net-yy-inet6.c @@ -14,7 +14,8 @@ #define TCP_STR "TCPv6" #define INPORT sin6_port #define INPORT_STR "sin6_port" -#define INADDR_STR "inet_pton(AF_INET6, \"::1\", &sin6_addr)" -#define SA_FIELDS ", sin6_flowinfo=htonl(0), sin6_scope_id=0" +#define INADDR_STR "sin6_flowinfo=htonl(0)" \ + ", inet_pton(AF_INET6, \"::1\", &sin6_addr)" +#define SA_FIELDS ", sin6_scope_id=0" #include "net-yy-inet.c" diff --git a/tests/sockaddr_xlat.c b/tests/sockaddr_xlat.c index a4cb109c..420dcfef 100644 --- a/tests/sockaddr_xlat.c +++ b/tests/sockaddr_xlat.c @@ -125,36 +125,33 @@ validate_in6(struct sockaddr_in6 *const in6, const char *const h_addr) #if XLAT_RAW printf("connect(-1, {sa_family=%#x, sin6_port=", AF_INET6); print_quoted_hex(&in6->sin6_port, sizeof(in6->sin6_port)); - printf(", sin6_addr="); - print_quoted_hex(&in6->sin6_addr, sizeof(struct in6_addr)); printf(", sin6_flowinfo="); print_quoted_hex(&in6->sin6_flowinfo, sizeof(in6->sin6_flowinfo)); - printf(", sin6_scope_id=%u}, %u)" - " = %s\n", in6->sin6_scope_id, len, errstr); + printf(", sin6_addr="); + print_quoted_hex(&in6->sin6_addr, sizeof(struct in6_addr)); + printf(", sin6_scope_id=%u}, %u) = %s\n", + in6->sin6_scope_id, len, errstr); #elif XLAT_VERBOSE printf("connect(-1, {sa_family=%#x /* AF_INET6 */", AF_INET6); printf(", sin6_port="); print_quoted_hex(&in6->sin6_port, sizeof(in6->sin6_port)); printf(" /* htons(%hu) */", ntohs(in6->sin6_port)); + printf(", sin6_flowinfo="); + print_quoted_hex(&in6->sin6_flowinfo, sizeof(in6->sin6_flowinfo)); + printf(" /* htonl(%u) */", ntohl(in6->sin6_flowinfo)); printf(", sin6_addr="); print_quoted_hex(&in6->sin6_addr, sizeof(struct in6_addr)); printf(" /* inet_pton(AF_INET6, \"%s\") */", h_addr); - printf(", sin6_flowinfo="); - print_quoted_hex(&in6->sin6_flowinfo, sizeof(in6->sin6_flowinfo)); - printf(" /* htonl(%u) */" - ", sin6_scope_id=%u}, %u)" - " = %s\n", - ntohl(in6->sin6_flowinfo), in6->sin6_scope_id, - len, errstr); + printf(", sin6_scope_id=%u}, %u) = %s\n", + in6->sin6_scope_id, len, errstr); #else printf("connect(-1, {sa_family=AF_INET6, sin6_port=htons(%hu)" - ", inet_pton(AF_INET6, \"%s\", &sin6_addr)" ", sin6_flowinfo=htonl(%u)" + ", inet_pton(AF_INET6, \"%s\", &sin6_addr)" ", sin6_scope_id=%u}, %u)" " = %s\n", - ntohs(in6->sin6_port), h_addr, - ntohl(in6->sin6_flowinfo), in6->sin6_scope_id, - len, errstr); + ntohs(in6->sin6_port), ntohl(in6->sin6_flowinfo), + h_addr, in6->sin6_scope_id, len, errstr); #endif } -- 2.40.0