* 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.
#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 */ \
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
};
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("}"));
.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,
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("}"));
}
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
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}"));
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
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);
.ifal_family = AF_UNIX,
.ifal_prefixlen = 0xaf,
.ifal_flags = 0xbd,
- .ifal_index = IFINDEX_LO,
+ .ifal_index = ifindex_lo(),
.ifal_seq = 0xfadcdafb
};
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("}"));
}
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
#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_, ...) \
.id = {
.idiag_sport = 0xfacd,
.idiag_dport = 0xdead,
- .idiag_if = IFINDEX_LO,
+ .idiag_if = ifindex_lo(),
.idiag_cookie = { 0xdeadbeef, 0xbadc0ded }
},
};
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("}}"));
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("}}"));
}
.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,
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);
.id = {
.idiag_sport = 0xfacd,
.idiag_dport = 0xdead,
- .idiag_if = IFINDEX_LO,
+ .idiag_if = ifindex_lo(),
.idiag_cookie = { 0xdeadbeef, 0xbadc0ded }
},
};
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("}}"));
}
.id = {
.idiag_sport = 0xfacf,
.idiag_dport = 0xdead,
- .idiag_if = IFINDEX_LO,
+ .idiag_if = ifindex_lo(),
.idiag_cookie = { 0xdeadbeef, 0xbadc0ded }
},
.idiag_expires = 0xfacefeed,
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);
.id = {
.idiag_sport = 0xdead,
.idiag_dport = 0xadcd,
- .idiag_if = IFINDEX_LO,
+ .idiag_if = ifindex_lo(),
.idiag_cookie = { 0xdeadbeef, 0xbadc0ded },
},
};
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("}}"));
}
.id = {
.idiag_sport = 0xdead,
.idiag_dport = 0xadcd,
- .idiag_if = IFINDEX_LO,
+ .idiag_if = ifindex_lo(),
.idiag_cookie = { 0xdeadbeef, 0xbadc0ded },
},
.diag_uid = 0xadcdfafc,
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);
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)
{
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) ||
", 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);
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)
{
.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) ||
", 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);
#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;
.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) ||
", 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);
}
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));
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
#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)
{
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);
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,