From f1a46cd225d0ad9c2428530e30f08aa23b4daafe Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Wed, 15 May 2019 16:52:37 +0000 Subject: Replace SCM_TIMESTAMP* constants with SO_TIMESTAMP* Besides the fact that SO_TIMESTAMP* constants appear to be more standardized than SCM_TIMESTAMP*, new SO_TIMESTAMP*_OLD and SO_TIMESTAMP*_NEW constants introduced in Linux 5.1 have no SCM_TIMESTAMP*_OLD and SCM_TIMESTAMP*_NEW analogues. * xlat/scmvals.in: Replace SCM_WIFI_STATUS, SCM_TXTIME, SCM_TIMESTAMP, SCM_TIMESTAMPNS, and SCM_TIMESTAMPING with SO_WIFI_STATUS, SO_TXTIME, SO_TIMESTAMP, SO_TIMESTAMPNS, and SO_TIMESTAMPING, respectively. * msghdr.c: Include "xlat/sock_options.h" in XLAT_MACROS_ONLY mode. (cmsg_socket_printers): Replace SCM_TIMESTAMP, SCM_TIMESTAMPNS, and SCM_TIMESTAMPING with SO_TIMESTAMP, SO_TIMESTAMPNS, and SO_TIMESTAMPING, respectively. * tests/msg_control.c: Include "xlat/sock_options.h" in XLAT_MACROS_ONLY mode. (test_scm_timestamp): Replace SCM_TIMESTAMP with SO_TIMESTAMP. (test_scm_timestampns): Replace SCM_TIMESTAMPNS with SO_TIMESTAMPNS. (test_scm_timestamping): Replace SCM_TIMESTAMPING with SO_TIMESTAMPING. * tests/sockopt-timestamp.c (main): Replace SCM_TIMESTAMP and SCM_TIMESTAMPNS with SO_TIMESTAMP and SO_TIMESTAMPNS, respectively. --- msghdr.c | 9 ++++-- tests/msg_control.c | 31 +++++++++--------- tests/sockopt-timestamp.c | 6 ++-- xlat/scmvals.in | 80 +++++++++++------------------------------------ 4 files changed, 42 insertions(+), 84 deletions(-) diff --git a/msghdr.c b/msghdr.c index 2515a2bea..e05c321e1 100644 --- a/msghdr.c +++ b/msghdr.c @@ -17,6 +17,9 @@ #include #include +#define XLAT_MACROS_ONLY +#include "xlat/sock_options.h" +#undef XLAT_MACROS_ONLY #include "xlat/msg_flags.h" #include "xlat/scmvals.h" #include "xlat/ip_cmsg_types.h" @@ -197,9 +200,9 @@ static const struct { [SCM_RIGHTS] = { print_scm_rights, sizeof(int) }, [SCM_CREDENTIALS] = { print_scm_creds, sizeof(struct ucred) }, [SCM_SECURITY] = { print_scm_security, 1 }, - [SCM_TIMESTAMP] = { print_scm_timestamp, 1 }, - [SCM_TIMESTAMPNS] = { print_scm_timestampns, 1 }, - [SCM_TIMESTAMPING] = { print_scm_timestamping, 1 } + [SO_TIMESTAMP] = { print_scm_timestamp, 1 }, + [SO_TIMESTAMPNS] = { print_scm_timestampns, 1 }, + [SO_TIMESTAMPING] = { print_scm_timestamping, 1 } }, cmsg_ip_printers[] = { [IP_PKTINFO] = { print_cmsg_ip_pktinfo, sizeof(struct in_pktinfo) }, [IP_TTL] = { print_cmsg_uint, sizeof(unsigned int) }, diff --git a/tests/msg_control.c b/tests/msg_control.c index f64e76bc9..76df37e27 100644 --- a/tests/msg_control.c +++ b/tests/msg_control.c @@ -21,7 +21,10 @@ #include #include "xlat.h" +#define XLAT_MACROS_ONLY +#include "xlat/sock_options.h" #include "xlat/scmvals.h" +#undef XLAT_MACROS_ONLY #ifndef SOL_IP # define SOL_IP 0 @@ -30,10 +33,6 @@ # define SOL_TCP 6 #endif -#ifndef SCM_SECURITY -# define SCM_SECURITY 3 -#endif - #define MIN_SIZE_OF(type, member) \ (offsetof(type, member) + sizeof(((type *) 0)->member)) @@ -218,7 +217,7 @@ test_scm_timestamp(struct msghdr *const mh, void *const page) cmsg->cmsg_len = CMSG_LEN(sizeof(struct timeval)); cmsg->cmsg_level = SOL_SOCKET; - cmsg->cmsg_type = SCM_TIMESTAMP; + cmsg->cmsg_type = SO_TIMESTAMP; struct timeval *tv = (struct timeval *) CMSG_DATA(cmsg); tv->tv_sec = 123456789; tv->tv_usec = 987654; @@ -229,7 +228,7 @@ test_scm_timestamp(struct msghdr *const mh, void *const page) int rc = sendmsg(-1, mh, 0); printf("sendmsg(-1, {msg_name=NULL, msg_namelen=0, msg_iov=NULL" ", msg_iovlen=0, msg_control=[{cmsg_len=%u" - ", cmsg_level=SOL_SOCKET, cmsg_type=SCM_TIMESTAMP" + ", cmsg_level=SOL_SOCKET, cmsg_type=SO_TIMESTAMP" ", cmsg_data={tv_sec=%lld, tv_usec=%llu}}]" ", msg_controllen=%lu, msg_flags=0}, 0) = %d %s (%m)\n", (unsigned) cmsg->cmsg_len, @@ -241,7 +240,7 @@ test_scm_timestamp(struct msghdr *const mh, void *const page) cmsg->cmsg_len = CMSG_LEN(sizeof(struct timeval) - sizeof(long)); cmsg->cmsg_level = SOL_SOCKET; - cmsg->cmsg_type = SCM_TIMESTAMP; + cmsg->cmsg_type = SO_TIMESTAMP; mh->msg_control = cmsg; mh->msg_controllen = len; @@ -249,7 +248,7 @@ test_scm_timestamp(struct msghdr *const mh, void *const page) rc = sendmsg(-1, mh, 0); printf("sendmsg(-1, {msg_name=NULL, msg_namelen=0, msg_iov=NULL" ", msg_iovlen=0, msg_control=[{cmsg_len=%u" - ", cmsg_level=SOL_SOCKET, cmsg_type=SCM_TIMESTAMP, cmsg_data=?}]" + ", cmsg_level=SOL_SOCKET, cmsg_type=SO_TIMESTAMP, cmsg_data=?}]" ", msg_controllen=%lu, msg_flags=0}, 0) = %d %s (%m)\n", (unsigned) cmsg->cmsg_len, (unsigned long) len, rc, errno2name()); @@ -263,7 +262,7 @@ test_scm_timestampns(struct msghdr *const mh, void *const page) cmsg->cmsg_len = CMSG_LEN(sizeof(struct timespec)); cmsg->cmsg_level = SOL_SOCKET; - cmsg->cmsg_type = SCM_TIMESTAMPNS; + cmsg->cmsg_type = SO_TIMESTAMPNS; struct timespec *ts = (struct timespec *) CMSG_DATA(cmsg); ts->tv_sec = 123456789; ts->tv_nsec = 987654321; @@ -274,7 +273,7 @@ test_scm_timestampns(struct msghdr *const mh, void *const page) int rc = sendmsg(-1, mh, 0); printf("sendmsg(-1, {msg_name=NULL, msg_namelen=0, msg_iov=NULL" ", msg_iovlen=0, msg_control=[{cmsg_len=%u" - ", cmsg_level=SOL_SOCKET, cmsg_type=SCM_TIMESTAMPNS" + ", cmsg_level=SOL_SOCKET, cmsg_type=SO_TIMESTAMPNS" ", cmsg_data={tv_sec=%lld, tv_nsec=%llu}}]" ", msg_controllen=%lu, msg_flags=0}, 0) = %d %s (%m)\n", (unsigned) cmsg->cmsg_len, @@ -286,7 +285,7 @@ test_scm_timestampns(struct msghdr *const mh, void *const page) cmsg->cmsg_len = CMSG_LEN(sizeof(struct timespec) - sizeof(long)); cmsg->cmsg_level = SOL_SOCKET; - cmsg->cmsg_type = SCM_TIMESTAMPNS; + cmsg->cmsg_type = SO_TIMESTAMPNS; mh->msg_control = cmsg; mh->msg_controllen = len; @@ -294,7 +293,7 @@ test_scm_timestampns(struct msghdr *const mh, void *const page) rc = sendmsg(-1, mh, 0); printf("sendmsg(-1, {msg_name=NULL, msg_namelen=0, msg_iov=NULL" ", msg_iovlen=0, msg_control=[{cmsg_len=%u" - ", cmsg_level=SOL_SOCKET, cmsg_type=SCM_TIMESTAMPNS" + ", cmsg_level=SOL_SOCKET, cmsg_type=SO_TIMESTAMPNS" ", cmsg_data=?}]" ", msg_controllen=%lu, msg_flags=0}, 0) = %d %s (%m)\n", (unsigned) cmsg->cmsg_len, @@ -309,7 +308,7 @@ test_scm_timestamping(struct msghdr *const mh, void *const page) cmsg->cmsg_len = CMSG_LEN(3 * sizeof(struct timespec)); cmsg->cmsg_level = SOL_SOCKET; - cmsg->cmsg_type = SCM_TIMESTAMPING; + cmsg->cmsg_type = SO_TIMESTAMPING; struct timespec *ts = (struct timespec *) CMSG_DATA(cmsg); ts[0].tv_sec = 123456789; ts[0].tv_nsec = 987654321; @@ -324,7 +323,7 @@ test_scm_timestamping(struct msghdr *const mh, void *const page) int rc = sendmsg(-1, mh, 0); printf("sendmsg(-1, {msg_name=NULL, msg_namelen=0, msg_iov=NULL" ", msg_iovlen=0, msg_control=[{cmsg_len=%u" - ", cmsg_level=SOL_SOCKET, cmsg_type=SCM_TIMESTAMPING" + ", cmsg_level=SOL_SOCKET, cmsg_type=SO_TIMESTAMPING" ", cmsg_data=[{tv_sec=%lld, tv_nsec=%llu}" ", {tv_sec=%lld, tv_nsec=%llu}, {tv_sec=%lld, tv_nsec=%llu}]}]" ", msg_controllen=%lu, msg_flags=0}, 0) = %d %s (%m)\n", @@ -341,7 +340,7 @@ test_scm_timestamping(struct msghdr *const mh, void *const page) cmsg->cmsg_len = CMSG_LEN(3 * sizeof(struct timespec) - sizeof(long)); cmsg->cmsg_level = SOL_SOCKET; - cmsg->cmsg_type = SCM_TIMESTAMPING; + cmsg->cmsg_type = SO_TIMESTAMPING; mh->msg_control = cmsg; mh->msg_controllen = len; @@ -349,7 +348,7 @@ test_scm_timestamping(struct msghdr *const mh, void *const page) rc = sendmsg(-1, mh, 0); printf("sendmsg(-1, {msg_name=NULL, msg_namelen=0, msg_iov=NULL" ", msg_iovlen=0, msg_control=[{cmsg_len=%u" - ", cmsg_level=SOL_SOCKET, cmsg_type=SCM_TIMESTAMPING" + ", cmsg_level=SOL_SOCKET, cmsg_type=SO_TIMESTAMPING" ", cmsg_data=?}]" ", msg_controllen=%lu, msg_flags=0}, 0) = %d %s (%m)\n", (unsigned) cmsg->cmsg_len, diff --git a/tests/sockopt-timestamp.c b/tests/sockopt-timestamp.c index 0f60d64c2..e9f3b0d57 100644 --- a/tests/sockopt-timestamp.c +++ b/tests/sockopt-timestamp.c @@ -116,7 +116,7 @@ test_sockopt(int so_val, const char *str, void (*fun)(const struct cmsghdr *)) } printf(", cmsg_type="); if (c->cmsg_type == so_val) { - printf("SCM_%s, cmsg_data=", str); + printf("%s, cmsg_data=", str); fun(c); tested = 1; } else { @@ -140,9 +140,9 @@ main(void) const char *str; void (*fun)(const struct cmsghdr *); } tests[] = { - { SO_TIMESTAMP_OLD, "TIMESTAMP", print_timestamp_old }, + { SO_TIMESTAMP_OLD, "SO_TIMESTAMP", print_timestamp_old }, #ifdef SO_TIMESTAMPNS_OLD - { SO_TIMESTAMPNS_OLD, "TIMESTAMPNS", print_timestampns_old }, + { SO_TIMESTAMPNS_OLD, "SO_TIMESTAMPNS", print_timestampns_old }, #endif }; unsigned int tested = 0; diff --git a/xlat/scmvals.in b/xlat/scmvals.in index ae9999c17..2a070c14d 100644 --- a/xlat/scmvals.in +++ b/xlat/scmvals.in @@ -2,68 +2,24 @@ SCM_RIGHTS 1 SCM_CREDENTIALS 2 SCM_SECURITY 3 -#ifndef SCM_TIMESTAMP -# if defined HPPA -# define SCM_TIMESTAMP 0x4012 -# elif defined SPARC || defined SPARC64 -# define SCM_TIMESTAMP 0x001d -# else -# define SCM_TIMESTAMP 29 -# endif -#endif -SCM_TIMESTAMP - -#ifndef SCM_TIMESTAMPNS -# if defined HPPA -# define SCM_TIMESTAMPNS 0x4013 -# elif defined SPARC || defined SPARC64 -# define SCM_TIMESTAMPNS 0x0021 -# else -# define SCM_TIMESTAMPNS 35 -# endif -#endif -SCM_TIMESTAMPNS - -#ifndef SCM_TIMESTAMPING -# if defined HPPA -# define SCM_TIMESTAMPING 0x4020 -# elif defined SPARC || defined SPARC64 -# define SCM_TIMESTAMPING 0x0023 -# else -# define SCM_TIMESTAMPING 37 -# endif -#endif -SCM_TIMESTAMPING - -#ifndef SCM_WIFI_STATUS -# if defined HPPA -# define SCM_WIFI_STATUS 0x4022 -# elif defined SPARC || defined SPARC64 -# define SCM_WIFI_STATUS 0x0025 -# else -# define SCM_WIFI_STATUS 41 -# endif -#endif -SCM_WIFI_STATUS +SO_WIFI_STATUS +SO_TXTIME +SO_TIMESTAMP +SO_TIMESTAMPNS +SO_TIMESTAMPING -#ifndef SCM_TIMESTAMPING_OPT_STATS -# if defined HPPA -# define SCM_TIMESTAMPING_OPT_STATS 0x402f -# elif defined SPARC || defined SPARC64 -# define SCM_TIMESTAMPING_OPT_STATS 0x0038 -# else -# define SCM_TIMESTAMPING_OPT_STATS 54 -# endif +/* Generated by maint/gen_xlat_defs.sh -f '#x' -p 'SCM_TIMESTAMPING_' -c 'asm-generic/socket.h' -a 'asm/socket.h' */ +#if defined __sparc__ +SCM_TIMESTAMPING_OPT_STATS 0x38 +#elif defined __hppa__ +SCM_TIMESTAMPING_OPT_STATS 0x402f +#else +SCM_TIMESTAMPING_OPT_STATS 0x36 #endif -SCM_TIMESTAMPING_OPT_STATS - -#ifndef SCM_TIMESTAMPING_PKTINFO -# if defined HPPA -# define SCM_TIMESTAMPING_PKTINFO 0x4033 -# elif defined SPARC || defined SPARC64 -# define SCM_TIMESTAMPING_PKTINFO 0x003c -# else -# define SCM_TIMESTAMPING_PKTINFO 58 -# endif +#if defined __sparc__ +SCM_TIMESTAMPING_PKTINFO 0x3c +#elif defined __hppa__ +SCM_TIMESTAMPING_PKTINFO 0x4033 +#else +SCM_TIMESTAMPING_PKTINFO 0x3a #endif -SCM_TIMESTAMPING_PKTINFO -- cgit v1.2.1