diff --git a/src/apps/ipv4/echo.lua b/src/apps/ipv4/echo.lua index 2bbc282b7c..9d422a81ea 100644 --- a/src/apps/ipv4/echo.lua +++ b/src/apps/ipv4/echo.lua @@ -121,6 +121,9 @@ function ICMPEcho:respond_to_echo_request(pkt) out_h.ipv4.flags_and_fragment_offset = bit.band(out_h.ipv4.flags_and_fragment_offset, ipv4_fragment_offset_mask) + -- Set TTL. + out_h.ipv4.ttl = 64 + -- Recalculate IPv4 checksum. out_h.ipv4.checksum = 0 out_h.ipv4.checksum = htons( diff --git a/src/apps/ipv6/echo.lua b/src/apps/ipv6/echo.lua index ad170b58fe..4817b63f18 100644 --- a/src/apps/ipv6/echo.lua +++ b/src/apps/ipv6/echo.lua @@ -112,6 +112,9 @@ function ICMPEcho:respond_to_echo_request(pkt) out_h.ether.dhost, out_h.ether.shost = h.ether.shost, h.ether.dhost out_h.ipv6.src_ip, out_h.ipv6.dst_ip = h.ipv6.dst_ip, h.ipv6.src_ip + -- Set hop limit. + out_h.ipv6.hop_limit = 64 + -- Change ICMP message type. icmp = ffi.cast(icmp_header_ptr_t, out_h.ipv6.payload) icmp.type = icmpv6_echo_reply diff --git a/src/program/lwaftr/tests/data/add-vlan.sh b/src/program/lwaftr/tests/data/add-vlan.sh index 3ce40ed452..ac74434529 100755 --- a/src/program/lwaftr/tests/data/add-vlan.sh +++ b/src/program/lwaftr/tests/data/add-vlan.sh @@ -47,6 +47,7 @@ V4=( udp-frominet-3frag-bound.pcap udp-frominet-bound.pcap ping-v4.pcap + ping-v4-ttl-32.pcap ping-v4-reply.pcap ping-v4-and-data.pcap ) @@ -110,6 +111,7 @@ V6=( udp-afteraftr-reassembled-ipv6-2frags.pcap udp-fromb4-2frags-bound.pcap ping-v6.pcap + ping-v6-hop-limit-32.pcap ping-v6-reply.pcap ping-v6-and-data.pcap ) diff --git a/src/program/lwaftr/tests/data/ping-v4-ttl-32.pcap b/src/program/lwaftr/tests/data/ping-v4-ttl-32.pcap new file mode 100644 index 0000000000..521d68d08a Binary files /dev/null and b/src/program/lwaftr/tests/data/ping-v4-ttl-32.pcap differ diff --git a/src/program/lwaftr/tests/data/ping-v6-hop-limit-32.pcap b/src/program/lwaftr/tests/data/ping-v6-hop-limit-32.pcap new file mode 100644 index 0000000000..90ddd23624 Binary files /dev/null and b/src/program/lwaftr/tests/data/ping-v6-hop-limit-32.pcap differ diff --git a/src/program/lwaftr/tests/data/vlan/ping-v4-ttl-32.pcap b/src/program/lwaftr/tests/data/vlan/ping-v4-ttl-32.pcap new file mode 100644 index 0000000000..b5ab942ba0 Binary files /dev/null and b/src/program/lwaftr/tests/data/vlan/ping-v4-ttl-32.pcap differ diff --git a/src/program/lwaftr/tests/data/vlan/ping-v6-hop-limit-32.pcap b/src/program/lwaftr/tests/data/vlan/ping-v6-hop-limit-32.pcap new file mode 100644 index 0000000000..f009d5de68 Binary files /dev/null and b/src/program/lwaftr/tests/data/vlan/ping-v6-hop-limit-32.pcap differ diff --git a/src/program/lwaftr/tests/end-to-end/test_env.sh b/src/program/lwaftr/tests/end-to-end/test_env.sh index e414381bdf..632f536a11 100755 --- a/src/program/lwaftr/tests/end-to-end/test_env.sh +++ b/src/program/lwaftr/tests/end-to-end/test_env.sh @@ -385,18 +385,30 @@ TEST_DATA=( "no_icmp_with_filters_drop.conf" "tcp-frominet-trafficclass.pcap" "" "" "" "in-1p-ipv4-out-0p-drop.lua" +# Ping to lwAFTR (IPv4). + "ICMP Echo to AFTR (IPv4)" "no_icmp.conf" "ping-v4.pcap" "" "ping-v4-reply.pcap" "" "nofrag4.lua" +"ICMP Echo to AFTR (IPv4) (ttl=32)" +"no_icmp.conf" "ping-v4-ttl-32.pcap" "" "ping-v4-reply.pcap" "" +"nofrag4.lua" + "ICMP Echo to AFTR (IPv4) + data" "no_icmp.conf" "ping-v4-and-data.pcap" "" "ping-v4-reply.pcap" "tcp-afteraftr-ipv6.pcap" "in-1p-ipv4-out-1p-ipv6-echo.lua" +# Ping to lwAFTR (IPv6). + "ICMP Echo to AFTR (IPv6)" "no_icmp.conf" "" "ping-v6.pcap" "" "ping-v6-reply.pcap" "icmpv6-ping-and-reply.lua" +"ICMP Echo to AFTR (IPv6) (hop-limit=32)" +"no_icmp.conf" "" "ping-v6-hop-limit-32.pcap" "" "ping-v6-reply.pcap" +"icmpv6-ping-and-reply.lua" + "ICMP Echo to AFTR (IPv6) + data" "no_icmp.conf" "" "ping-v6-and-data.pcap" "decap-ipv4.pcap" "ping-v6-reply.pcap" "in-1p-ipv6-out-1p-ipv4-4-and-echo.lua"