From: Eugene Syromyatnikov Date: Wed, 23 May 2018 16:48:26 +0000 (+0200) Subject: Leverage the fact that inet_protocols xlat is sorted X-Git-Tag: v4.23~54 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=27850e48f360f45578d1d6e09a07516580594198;p=strace Leverage the fact that inet_protocols xlat is sorted * defs.h (inet_protocols): Move up, add description. (inet_protocols_size): New declaration. * net.c (inet_protocols_size): New constant variable. * nlattr.c (decode_nla_ip_proto): Specify xlat_size, set xt to XT_SORTED. --- diff --git a/defs.h b/defs.h index 27a865ac..5b5434e9 100644 --- a/defs.h +++ b/defs.h @@ -304,12 +304,16 @@ extern const struct xlat ethernet_protocols[]; /** Ethernet protocols array size without terminating record. */ extern const size_t ethernet_protocols_size; +/** IP protocols list, sorted, defined in net.c. */ +extern const struct xlat inet_protocols[]; +/** IP protocols array size without terminating record. */ +extern const size_t inet_protocols_size; + extern const struct xlat evdev_abs[]; /** Number of elements in evdev_abs array without the terminating record. */ extern const size_t evdev_abs_size; extern const struct xlat iffflags[]; -extern const struct xlat inet_protocols[]; extern const struct xlat ip_type_of_services[]; extern const struct xlat ipc_private[]; extern const struct xlat msg_flags[]; diff --git a/net.c b/net.c index 70e6a139..489f38a5 100644 --- a/net.c +++ b/net.c @@ -97,6 +97,8 @@ #include "xlat/kcm_protocols.h" #include "xlat/smc_protocols.h" +const size_t inet_protocols_size = ARRAY_SIZE(inet_protocols) - 1; + static void decode_sockbuf(struct tcb *const tcp, const int fd, const kernel_ulong_t addr, const kernel_ulong_t addrlen) @@ -139,7 +141,7 @@ SYS_FUNC(socket) switch (tcp->u_arg[0]) { case AF_INET: case AF_INET6: - printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???"); + printxval_search(inet_protocols, tcp->u_arg[2], "IPPROTO_???"); break; case AF_NETLINK: diff --git a/nlattr.c b/nlattr.c index 057e051a..8dea4847 100644 --- a/nlattr.c +++ b/nlattr.c @@ -273,8 +273,11 @@ decode_nla_ip_proto(struct tcb *const tcp, const unsigned int len, const void *const opaque_data) { - static const struct decode_nla_xlat_opts opts = { - .xlat = inet_protocols, .dflt = "IPPROTO_???", + const struct decode_nla_xlat_opts opts = { + .xlat = inet_protocols, + .xlat_size = inet_protocols_size, + .xt = XT_SORTED, + .dflt = "IPPROTO_???", }; return decode_nla_xval(tcp, addr, len, &opts);