Skip to content

Commit 7474007

Browse files
jukkarhenrikbrixandersen
authored andcommitted
tests: net: udp: Add IPv6 unicast hop limit tests
Make sure that setting IPv6 unicast hop limit works as expected. Signed-off-by: Jukka Rissanen <[email protected]>
1 parent 96ac91d commit 7474007

File tree

1 file changed

+50
-0
lines changed
  • tests/net/socket/udp/src

1 file changed

+50
-0
lines changed

tests/net/socket/udp/src/main.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,6 +2132,56 @@ ZTEST(net_socket_udp, test_33_v6_mcast_hops)
21322132
AF_INET6, 0, mcast_hops);
21332133
}
21342134

2135+
ZTEST(net_socket_udp, test_34_v6_hops)
2136+
{
2137+
int ret;
2138+
int client_sock;
2139+
int server_sock;
2140+
int packet_sock;
2141+
int hops, verify;
2142+
socklen_t optlen;
2143+
struct sockaddr_in6 client_addr;
2144+
struct sockaddr_in6 server_addr;
2145+
2146+
Z_TEST_SKIP_IFNDEF(CONFIG_NET_SOCKETS_PACKET);
2147+
2148+
prepare_sock_udp_v6(MY_IPV6_ADDR, CLIENT_PORT, &client_sock, &client_addr);
2149+
prepare_sock_udp_v6(MY_IPV6_ADDR, SERVER_PORT, &server_sock, &server_addr);
2150+
2151+
packet_sock = socket(AF_PACKET, SOCK_RAW, ETH_P_ALL);
2152+
zassert_true(packet_sock >= 0, "Cannot create packet socket (%d)", -errno);
2153+
2154+
ret = bind_socket(packet_sock, lo0);
2155+
zassert_equal(ret, 0, "packet socket bind failed");
2156+
2157+
zassert_not_null(lo0->config.ip.ipv6,
2158+
"Interface %d (%p) no IPv6 configured",
2159+
net_if_get_by_iface(lo0), lo0);
2160+
2161+
hops = 16;
2162+
net_if_ipv6_set_hop_limit(lo0, hops);
2163+
verify = net_if_ipv6_get_hop_limit(lo0);
2164+
zassert_equal(verify, hops, "Different hop limit (%d vs %d)", hops, verify);
2165+
2166+
hops = 8;
2167+
ret = setsockopt(client_sock, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &hops,
2168+
sizeof(hops));
2169+
zassert_equal(ret, 0, "Cannot set unicast hops (%d)", -errno);
2170+
2171+
optlen = sizeof(verify);
2172+
ret = getsockopt(client_sock, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &verify,
2173+
&optlen);
2174+
zassert_equal(ret, 0, "Cannot get unicast hops (%d)", -errno);
2175+
zassert_equal(verify, hops, "Different unicast hops (%d vs %d)",
2176+
hops, verify);
2177+
2178+
test_check_ttl(client_sock, server_sock, packet_sock,
2179+
(struct sockaddr *)&client_addr, sizeof(client_addr),
2180+
(struct sockaddr *)&server_addr, sizeof(server_addr),
2181+
(struct sockaddr *)&server_addr, sizeof(server_addr),
2182+
AF_INET6, hops, 0);
2183+
}
2184+
21352185
static void after(void *arg)
21362186
{
21372187
ARG_UNUSED(arg);

0 commit comments

Comments
 (0)