]> granicus.if.org Git - strace/commitdiff
Leverage the fact that inet_protocols xlat is sorted
authorEugene Syromyatnikov <evgsyr@gmail.com>
Wed, 23 May 2018 16:48:26 +0000 (18:48 +0200)
committerDmitry V. Levin <ldv@altlinux.org>
Tue, 5 Jun 2018 11:04:09 +0000 (11:04 +0000)
* 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.

defs.h
net.c
nlattr.c

diff --git a/defs.h b/defs.h
index 27a865ac5ec1ac3e64651d08ea703fb457a0fa30..5b5434e9b2003e124297de91fde77311caeaf3e3 100644 (file)
--- 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 70e6a139cdeafedf3901961a2a0960ff335642da..489f38a52071cba818bfce588ddfd2a2d1dcb87f 100644 (file)
--- 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:
index 057e051a1c5dbe7e9ec77bed77f91c93fcbd05dc..8dea4847721514b69013b5db7fe363c0530c7677 100644 (file)
--- 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);