]> granicus.if.org Git - strace/commitdiff
tests: use ifindex_lo and IFINDEX_LO_STR
authorDmitry V. Levin <ldv@altlinux.org>
Tue, 15 Aug 2017 20:08:39 +0000 (20:08 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Tue, 15 Aug 2017 20:08:39 +0000 (20:08 +0000)
* tests/netlink_route.c: Do not check for HAVE_IF_INDEXTONAME.
(if_nametoindex, IFINDEX_LO): Remove.
(test_rtnl_link, test_rtnl_addr, test_rtnl_neigh, test_rtnl_tc,
test_rtnl_addrlabel, test_rtnl_mdb): Use ifindex_lo instead
of if_nametoindex, use IFINDEX_LO_STR instead of hardcoded string.
* tests/netlink_sock_diag.c: Do not check for HAVE_IF_INDEXTONAME.
(if_nametoindex, IFINDEX_LO): Remove.
(test_inet_diag_sockid, test_inet_diag_req, test_inet_diag_req_v2,
test_inet_diag_msg, test_smc_diag_req): Use ifindex_lo instead
of if_nametoindex, use IFINDEX_LO_STR instead of hardcoded string.
* tests/nlattr_inet_diag_msg.c: Do not check for HAVE_IF_INDEXTONAME.
(if_nametoindex, IFINDEX_LO): Remove.
(init_inet_diag_msg): Use ifindex_lo instead of if_nametoindex.
(print_inet_diag_msg): Use IFINDEX_LO_STR instead of hardcoded string.
* tests/nlattr_inet_diag_req_compat.c: Do not check
for HAVE_IF_INDEXTONAME.
(if_nametoindex, IFINDEX_LO): Remove.
(init_inet_diag_req): Use ifindex_lo instead of if_nametoindex.
(print_inet_diag_req): Use IFINDEX_LO_STR instead of hardcoded string.
* tests/nlattr_inet_diag_req_v2.c: Do not check for HAVE_IF_INDEXTONAME.
(if_nametoindex, IFINDEX_LO): Remove.
(init_inet_diag_req_v2, print_inet_diag_req_v2,
test_inet_diag_bc_dev_cond): Use ifindex_lo instead of if_nametoindex,
use IFINDEX_LO_STR instead of hardcoded string.
* tests/nlattr_packet_diag_msg.c: Do not check for HAVE_IF_INDEXTONAME.
(if_nametoindex, IFINDEX_LO): Remove.
(main): Use ifindex_lo instead of if_nametoindex.
(print_packet_diag_mclist): Use IFINDEX_LO_STR instead of hardcoded
string.

tests/netlink_route.c
tests/netlink_sock_diag.c
tests/nlattr_inet_diag_msg.c
tests/nlattr_inet_diag_req_compat.c
tests/nlattr_inet_diag_req_v2.c
tests/nlattr_packet_diag_msg.c

index 68d0fc7a884776a512ef49bc453c05ce8a526346..f9bd0d8efe3a84954ea544878b6028281474c864 100644 (file)
 #endif
 #include <linux/rtnetlink.h>
 
-#ifdef HAVE_IF_INDEXTONAME
-/* <linux/if.h> used to conflict with <net/if.h> */
-extern unsigned int if_nametoindex(const char *);
-# define IFINDEX_LO    (if_nametoindex("lo"))
-#else
-# define IFINDEX_LO    1
-#endif
-
 #define TEST_NL_ROUTE(fd_, nlh0_, type_, obj_, print_family_, ...)     \
        do {                                                            \
                /* family and string */                                 \
@@ -217,7 +209,7 @@ test_rtnl_link(const int fd)
        const struct ifinfomsg ifinfo = {
                .ifi_family = AF_UNIX,
                .ifi_type = ARPHRD_LOOPBACK,
-               .ifi_index = IFINDEX_LO,
+               .ifi_index = ifindex_lo(),
                .ifi_flags = IFF_UP,
                .ifi_change = 0xfabcdeba
        };
@@ -225,7 +217,7 @@ test_rtnl_link(const int fd)
        TEST_NL_ROUTE(fd, nlh0, RTM_GETLINK, ifinfo,
                      printf("{ifi_family=AF_UNIX"),
                      printf(", ifi_type=ARPHRD_LOOPBACK"
-                            ", ifi_index=if_nametoindex(\"lo\")"
+                            ", ifi_index=" IFINDEX_LO_STR
                             ", ifi_flags=IFF_UP");
                      PRINT_FIELD_X(", ", ifinfo, ifi_change);
                      printf("}"));
@@ -240,7 +232,7 @@ test_rtnl_addr(const int fd)
                .ifa_prefixlen = 0xde,
                .ifa_flags = IFA_F_SECONDARY,
                .ifa_scope = RT_SCOPE_UNIVERSE,
-               .ifa_index = IFINDEX_LO
+               .ifa_index = ifindex_lo()
        };
 
        TEST_NL_ROUTE(fd, nlh0, RTM_GETADDR, msg,
@@ -248,7 +240,7 @@ test_rtnl_addr(const int fd)
                      PRINT_FIELD_U(", ", msg, ifa_prefixlen);
                      printf(", ifa_flags=IFA_F_SECONDARY"
                             ", ifa_scope=RT_SCOPE_UNIVERSE"
-                            ", ifa_index=if_nametoindex(\"lo\")");
+                            ", ifa_index=" IFINDEX_LO_STR);
                      printf("}"));
 }
 
@@ -313,7 +305,7 @@ test_rtnl_neigh(const int fd)
        void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
        const struct ndmsg msg = {
                .ndm_family = AF_UNIX,
-               .ndm_ifindex = IFINDEX_LO,
+               .ndm_ifindex = ifindex_lo(),
                .ndm_state = NUD_PERMANENT,
                .ndm_flags = NTF_PROXY,
                .ndm_type = NDA_UNSPEC
@@ -321,7 +313,7 @@ test_rtnl_neigh(const int fd)
 
        TEST_NL_ROUTE(fd, nlh0, RTM_GETNEIGH, msg,
                      printf("{ndm_family=AF_UNIX"),
-                     printf(", ndm_ifindex=if_nametoindex(\"lo\")"
+                     printf(", ndm_ifindex=" IFINDEX_LO_STR
                             ", ndm_state=NUD_PERMANENT"
                             ", ndm_flags=NTF_PROXY"
                             ", ndm_type=NDA_UNSPEC}"));
@@ -347,7 +339,7 @@ test_rtnl_tc(const int fd)
        void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
        const struct tcmsg msg = {
                .tcm_family = AF_UNIX,
-               .tcm_ifindex = IFINDEX_LO,
+               .tcm_ifindex = ifindex_lo(),
                .tcm_handle = 0xfadcdafb,
                .tcm_parent = 0xafbcadab,
                .tcm_info = 0xbcaedafa
@@ -355,7 +347,7 @@ test_rtnl_tc(const int fd)
 
        TEST_NL_ROUTE(fd, nlh0, RTM_GETQDISC, msg,
                      printf("{tcm_family=AF_UNIX"),
-                     printf(", tcm_ifindex=if_nametoindex(\"lo\")");
+                     printf(", tcm_ifindex=" IFINDEX_LO_STR);
                      PRINT_FIELD_U(", ", msg, tcm_handle);
                      PRINT_FIELD_U(", ", msg, tcm_parent);
                      PRINT_FIELD_U(", ", msg, tcm_info);
@@ -385,7 +377,7 @@ test_rtnl_addrlabel(const int fd)
                .ifal_family = AF_UNIX,
                .ifal_prefixlen = 0xaf,
                .ifal_flags = 0xbd,
-               .ifal_index = IFINDEX_LO,
+               .ifal_index = ifindex_lo(),
                .ifal_seq = 0xfadcdafb
        };
 
@@ -393,7 +385,7 @@ test_rtnl_addrlabel(const int fd)
                      printf("{ifal_family=AF_UNIX"),
                      PRINT_FIELD_U(", ", msg, ifal_prefixlen);
                      PRINT_FIELD_U(", ", msg, ifal_flags);
-                     printf(", ifal_index=if_nametoindex(\"lo\")");
+                     printf(", ifal_index=" IFINDEX_LO_STR);
                      PRINT_FIELD_U(", ", msg, ifal_seq);
                      printf("}"));
 }
@@ -438,12 +430,12 @@ test_rtnl_mdb(const int fd)
        void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
        const struct br_port_msg msg = {
                .family = AF_UNIX,
-               .ifindex = IFINDEX_LO
+               .ifindex = ifindex_lo()
        };
 
        TEST_NL_ROUTE(fd, nlh0, RTM_GETMDB, msg,
                      printf("{family=AF_UNIX"),
-                     printf(", ifindex=if_nametoindex(\"lo\")}"));
+                     printf(", ifindex=" IFINDEX_LO_STR "}"));
 }
 #endif
 
index 8f935c0334c11a2a1cfab94fd80229bfaa8f381d..c2ebf129cdcf3235154582198680ee0e6a421588 100644 (file)
 
 #define SMC_ACTIVE 1
 
-#ifdef HAVE_IF_INDEXTONAME
-/* <linux/if.h> used to conflict with <net/if.h> */
-extern unsigned int if_nametoindex(const char *);
-# define IFINDEX_LO    (if_nametoindex("lo"))
-#else
-# define IFINDEX_LO    1
-#endif
-
 #define TEST_SOCK_DIAG(fd_, nlh0_,                                     \
                       family_, type_, flags_,                          \
                       obj_, print_family_, ...)                        \
@@ -388,7 +380,7 @@ test_inet_diag_sockid(const int fd)
                .id = {
                        .idiag_sport = 0xfacd,
                        .idiag_dport = 0xdead,
-                       .idiag_if = IFINDEX_LO,
+                       .idiag_if = ifindex_lo(),
                        .idiag_cookie = { 0xdeadbeef, 0xbadc0ded }
                },
        };
@@ -411,7 +403,7 @@ test_inet_diag_sockid(const int fd)
                            ntohs(req.id.idiag_sport),
                            ntohs(req.id.idiag_dport),
                            address, address);
-                    printf(", idiag_if=if_nametoindex(\"lo\")");
+                    printf(", idiag_if=" IFINDEX_LO_STR);
                     PRINT_FIELD_COOKIE(", ", req.id, idiag_cookie);
                     printf("}}"));
 
@@ -434,7 +426,7 @@ test_inet_diag_sockid(const int fd)
                            ntohs(req.id.idiag_sport),
                            ntohs(req.id.idiag_dport),
                            address6, address6);
-                    printf(", idiag_if=if_nametoindex(\"lo\")");
+                    printf(", idiag_if=" IFINDEX_LO_STR);
                     PRINT_FIELD_COOKIE(", ", req.id, idiag_cookie);
                     printf("}}"));
 }
@@ -452,7 +444,7 @@ test_inet_diag_req(const int fd)
                .id = {
                        .idiag_sport = 0xdead,
                        .idiag_dport = 0xadcd,
-                       .idiag_if = IFINDEX_LO,
+                       .idiag_if = ifindex_lo(),
                        .idiag_cookie = { 0xdeadbeef, 0xbadc0ded }
                },
                .idiag_states = 1 << TCP_LAST_ACK,
@@ -476,7 +468,7 @@ test_inet_diag_req(const int fd)
                              ntohs(req.id.idiag_sport),
                              ntohs(req.id.idiag_dport),
                              address, address);
-                      printf(", idiag_if=if_nametoindex(\"lo\")");
+                      printf(", idiag_if=" IFINDEX_LO_STR);
                       PRINT_FIELD_COOKIE(", ", req.id, idiag_cookie);
                       printf("}, idiag_states=1<<TCP_LAST_ACK");
                       PRINT_FIELD_U(", ", req, idiag_dbs);
@@ -496,7 +488,7 @@ test_inet_diag_req_v2(const int fd)
                .id = {
                        .idiag_sport = 0xfacd,
                        .idiag_dport = 0xdead,
-                       .idiag_if = IFINDEX_LO,
+                       .idiag_if = ifindex_lo(),
                        .idiag_cookie = { 0xdeadbeef, 0xbadc0ded }
                },
        };
@@ -518,7 +510,7 @@ test_inet_diag_req_v2(const int fd)
                              ntohs(req.id.idiag_sport),
                              ntohs(req.id.idiag_dport),
                              address, address);
-                      printf(", idiag_if=if_nametoindex(\"lo\")");
+                      printf(", idiag_if=" IFINDEX_LO_STR);
                       PRINT_FIELD_COOKIE(", ", req.id, idiag_cookie);
                       printf("}}"));
 }
@@ -536,7 +528,7 @@ test_inet_diag_msg(const int fd)
                .id = {
                        .idiag_sport = 0xfacf,
                        .idiag_dport = 0xdead,
-                       .idiag_if = IFINDEX_LO,
+                       .idiag_if = ifindex_lo(),
                        .idiag_cookie = { 0xdeadbeef, 0xbadc0ded }
                },
                .idiag_expires = 0xfacefeed,
@@ -563,7 +555,7 @@ test_inet_diag_msg(const int fd)
                              ntohs(msg.id.idiag_sport),
                              ntohs(msg.id.idiag_dport),
                              address, address);
-                      printf(", idiag_if=if_nametoindex(\"lo\")");
+                      printf(", idiag_if=" IFINDEX_LO_STR);
                       PRINT_FIELD_COOKIE(", ", msg.id, idiag_cookie);
                       PRINT_FIELD_U("}, ", msg, idiag_expires);
                       PRINT_FIELD_U(", ", msg, idiag_rqueue);
@@ -585,7 +577,7 @@ test_smc_diag_req(const int fd)
                .id = {
                        .idiag_sport = 0xdead,
                        .idiag_dport = 0xadcd,
-                       .idiag_if = IFINDEX_LO,
+                       .idiag_if = ifindex_lo(),
                        .idiag_cookie = { 0xdeadbeef, 0xbadc0ded },
                },
        };
@@ -605,7 +597,7 @@ test_smc_diag_req(const int fd)
                              ntohs(req.id.idiag_sport),
                              ntohs(req.id.idiag_dport),
                              address, address);
-                      printf(", idiag_if=if_nametoindex(\"lo\")");
+                      printf(", idiag_if=" IFINDEX_LO_STR);
                       PRINT_FIELD_COOKIE(", ", req.id, idiag_cookie);
                       printf("}}"));
 }
@@ -623,7 +615,7 @@ test_smc_diag_msg(const int fd)
                .id = {
                        .idiag_sport = 0xdead,
                        .idiag_dport = 0xadcd,
-                       .idiag_if = IFINDEX_LO,
+                       .idiag_if = ifindex_lo(),
                        .idiag_cookie = { 0xdeadbeef, 0xbadc0ded },
                },
                .diag_uid = 0xadcdfafc,
@@ -647,7 +639,7 @@ test_smc_diag_msg(const int fd)
                              ntohs(msg.id.idiag_sport),
                              ntohs(msg.id.idiag_dport),
                              address, address);
-                      printf(", idiag_if=if_nametoindex(\"lo\")");
+                      printf(", idiag_if=" IFINDEX_LO_STR);
                       PRINT_FIELD_COOKIE(", ", msg.id, idiag_cookie);
                       PRINT_FIELD_U("}, ", msg, diag_uid);
                       PRINT_FIELD_U(", ", msg, diag_inode);
index 6a8ffa277b98d0e53aef5ea6ca3c916fdc1fe78d..5666d74bf90ee227fde5a14846d95374ec771448 100644 (file)
 
 static const char address[] = "10.11.12.13";
 
-#ifdef HAVE_IF_INDEXTONAME
-# define IFINDEX_LO    (if_nametoindex("lo"))
-#else
-# define IFINDEX_LO    1
-#endif
-
 static void
 init_inet_diag_msg(struct nlmsghdr *const nlh, const unsigned int msg_len)
 {
@@ -58,7 +52,7 @@ init_inet_diag_msg(struct nlmsghdr *const nlh, const unsigned int msg_len)
        SET_STRUCT(struct inet_diag_msg, msg,
                .idiag_family = AF_INET,
                .idiag_state = TCP_LISTEN,
-               .id.idiag_if = IFINDEX_LO
+               .id.idiag_if = ifindex_lo()
        );
 
        if (!inet_pton(AF_INET, address, msg->id.idiag_src) ||
@@ -75,7 +69,8 @@ print_inet_diag_msg(const unsigned int msg_len)
               ", id={idiag_sport=htons(0), idiag_dport=htons(0)"
               ", idiag_src=inet_addr(\"%s\")"
               ", idiag_dst=inet_addr(\"%s\")"
-              ", idiag_if=if_nametoindex(\"lo\"), idiag_cookie=[0, 0]}"
+              ", idiag_if=" IFINDEX_LO_STR
+              ", idiag_cookie=[0, 0]}"
               ", idiag_expires=0, idiag_rqueue=0, idiag_wqueue=0"
               ", idiag_uid=0, idiag_inode=0}",
               msg_len, address, address);
index 76b798896c6008c4626caaab726366bea7073ae8..b0b217138666ac4928f83fb14bcc9b3442f88a79 100644 (file)
 
 static const char address[] = "10.11.12.13";
 
-#ifdef HAVE_IF_INDEXTONAME
-# define IFINDEX_LO    (if_nametoindex("lo"))
-#else
-# define IFINDEX_LO    1
-#endif
-
 static void
 init_inet_diag_req(struct nlmsghdr *const nlh, const unsigned int msg_len)
 {
@@ -61,7 +55,7 @@ init_inet_diag_req(struct nlmsghdr *const nlh, const unsigned int msg_len)
                .idiag_family = AF_INET,
                .idiag_ext = 1 << (INET_DIAG_TOS - 1),
                .idiag_states = 1 << TCP_LAST_ACK,
-               .id.idiag_if = IFINDEX_LO
+               .id.idiag_if = ifindex_lo()
        );
 
        if (!inet_pton(AF_INET, address, req->id.idiag_src) ||
@@ -79,7 +73,7 @@ print_inet_diag_req(const unsigned int msg_len)
               ", id={idiag_sport=htons(0), idiag_dport=htons(0)"
               ", idiag_src=inet_addr(\"%s\")"
               ", idiag_dst=inet_addr(\"%s\")"
-              ", idiag_if=if_nametoindex(\"lo\")"
+              ", idiag_if=" IFINDEX_LO_STR
               ", idiag_cookie=[0, 0]}"
               ", idiag_states=1<<TCP_LAST_ACK, idiag_dbs=0}",
               msg_len, address, address);
index 2d98c5bbfc90c342c3eb3938c02a7a805dd1afb0..1e09abe685fb73352049159ba9d07fd65bc3ae31 100644 (file)
 #include <linux/rtnetlink.h>
 #include <linux/sock_diag.h>
 
-#ifdef HAVE_IF_INDEXTONAME
-# define IFINDEX_LO    (if_nametoindex("lo"))
-#else
-# define IFINDEX_LO    1
-#endif
-
 static const char address[] = "10.11.12.13";
 static const unsigned int hdrlen = sizeof(struct inet_diag_req_v2);
 static void *nlh0;
@@ -65,7 +59,7 @@ init_inet_diag_req_v2(struct nlmsghdr *const nlh, const unsigned int msg_len)
                .idiag_ext = 1 << (INET_DIAG_CONG - 1),
                .sdiag_protocol = IPPROTO_TCP,
                .idiag_states = 1 << TCP_CLOSE,
-               .id.idiag_if = IFINDEX_LO
+               .id.idiag_if = ifindex_lo()
        );
 
        if (!inet_pton(AF_INET, address, req->id.idiag_src) ||
@@ -84,7 +78,8 @@ print_inet_diag_req_v2(const unsigned int msg_len)
               ", id={idiag_sport=htons(0), idiag_dport=htons(0)"
               ", idiag_src=inet_addr(\"%s\")"
               ", idiag_dst=inet_addr(\"%s\")"
-              ", idiag_if=if_nametoindex(\"lo\"), idiag_cookie=[0, 0]}}",
+              ", idiag_if=" IFINDEX_LO_STR
+              ", idiag_cookie=[0, 0]}}",
               msg_len, address, address);
 }
 
@@ -268,7 +263,7 @@ test_inet_diag_bc_dev_cond(const int fd)
        static const struct inet_diag_bc_op op = {
                .code = INET_DIAG_BC_DEV_COND,
        };
-       const uint32_t ifindex = IFINDEX_LO;
+       const uint32_t ifindex = ifindex_lo();
        char buf[sizeof(op) + sizeof(ifindex)];
        memcpy(buf, &op, sizeof(op));
        memcpy(buf + sizeof(op), pattern, sizeof(ifindex));
@@ -294,7 +289,7 @@ test_inet_diag_bc_dev_cond(const int fd)
                    INET_DIAG_REQ_BYTECODE,
                    sizeof(buf), buf, sizeof(buf),
                    print_inet_diag_bc_op("INET_DIAG_BC_DEV_COND");
-                   printf("if_nametoindex(\"lo\")}"));
+                   printf(IFINDEX_LO_STR "}"));
 }
 
 static void
index 55b4144d7c5f6ece9d9ddd5f8e5f49b2dc7da888..4211e201198c4e3c0d0f558f5bf259f707c69ca0 100644 (file)
 #include <linux/rtnetlink.h>
 #include <linux/sock_diag.h>
 
-#ifdef HAVE_IF_INDEXTONAME
-# define IFINDEX_LO    (if_nametoindex("lo"))
-#else
-# define IFINDEX_LO    1
-#endif
-
 static void
 init_packet_diag_msg(struct nlmsghdr *const nlh, const unsigned int msg_len)
 {
@@ -75,7 +69,7 @@ print_packet_diag_msg(const unsigned int msg_len)
 static void
 print_packet_diag_mclist(const struct packet_diag_mclist *const dml)
 {
-       printf("{pdmc_index=if_nametoindex(\"lo\")");
+       printf("{pdmc_index=" IFINDEX_LO_STR);
        PRINT_FIELD_U(", ", *dml, pdmc_count);
        PRINT_FIELD_U(", ", *dml, pdmc_type);
        PRINT_FIELD_U(", ", *dml, pdmc_alen);
@@ -131,14 +125,14 @@ main(void)
 
        const struct packet_diag_mclist dml[] = {
                {
-                       .pdmc_index = IFINDEX_LO,
+                       .pdmc_index = ifindex_lo(),
                        .pdmc_count = 0xabcdaefc,
                        .pdmc_type = 0xcdaf,
                        .pdmc_alen = 4,
                        .pdmc_addr = "1234"
                },
                {
-                       .pdmc_index = IFINDEX_LO,
+                       .pdmc_index = ifindex_lo(),
                        .pdmc_count = 0xdaefeafc,
                        .pdmc_type = 0xadef,
                        .pdmc_alen = 4,