Skip to content

Commit c32e06f

Browse files
jukkarhenrikbrixandersen
authored andcommitted
tests: net: udp: Add IPv6 hop limit 0 test
Make sure packet is dropped if IPv6 hop limit 0 packet is tried to send. Signed-off-by: Jukka Rissanen <[email protected]>
1 parent 28a8c6c commit c32e06f

File tree

1 file changed

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

1 file changed

+27
-0
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,6 +2033,33 @@ static void test_check_ttl(int sock_c, int sock_s, int sock_p,
20332033
zassert_true(ret < 0 && errno == EAGAIN, "recv succeed (%d)", -errno);
20342034
}
20352035

2036+
if (family == AF_INET6) {
2037+
/* Set hoplimit to 0 and make sure the packet is dropped and not
2038+
* received.
2039+
*/
2040+
int option;
2041+
2042+
if (expected_ttl > 0) {
2043+
option = IPV6_UNICAST_HOPS;
2044+
} else {
2045+
option = IPV6_MULTICAST_HOPS;
2046+
}
2047+
2048+
opt = 0;
2049+
ret = setsockopt(sock_c, IPPROTO_IPV6, option,
2050+
&opt, sizeof(opt));
2051+
zassert_equal(ret, 0, "Cannot set %s hops (%d)",
2052+
option == IPV6_UNICAST_HOPS ? "unicast" : "multicast",
2053+
-errno);
2054+
2055+
ret = sendto(sock_c, &tx_buf, sizeof(tx_buf), 0,
2056+
addr_sendto, addrlen_sendto);
2057+
zassert_equal(ret, sizeof(tx_buf), "send failed (%d)", -errno);
2058+
2059+
ret = recv(sock_s, &rx_buf, sizeof(rx_buf), 0);
2060+
zassert_true(ret < 0 && errno == EAGAIN, "recv succeed (%d)", -errno);
2061+
}
2062+
20362063
ret = close(sock_c);
20372064
zassert_equal(ret, 0, "close failed");
20382065
ret = close(sock_s);

0 commit comments

Comments
 (0)