Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ping: Lower max allowed -s value to 65507 (IPv4) or 65527 (IPv6)
Maximum value for ping -s option cannot be higher than maximum IPv4/v6 packet size, which is 65535. More precisely, the value should respect maximum IPv4/v6 ICMP data length. Therefore limit: * ICMP payload: 65507 = 65535 (IPv4 packet size) - 20 (min IPv4 header size) - 8 (ICMP header size) * ICMPv6 payload: 65527 = 65535 (IPv6 packet size) - 8 (ICMPv6 header size) Use the higher value unless user chose the protocol. Linux kernel limits IPv4/6 packet size size exactly to these values: * ICMP datagram socket net/ipv4/ping.c in ping_common_sendmsg() (used in both ping_v4_sendmsg() and ping_v6_sendmsg()): if (len > 0xFFFF) return -EMSGSIZE; * raw socket IPv4 in raw_sendmsg() in net/ipv4/raw.c: err = -EMSGSIZE; if (len > 0xFFFF) goto out; * raw IPv6 socket is limited similarly in __ip6_append_data() in net/ipv6/ip6_output.c, where it more data could be passed if bigger MTU is respected (but for ping to be working also jumboheader is needed to be added): @@ -1473,7 +1473,7 @@ static int __ip6_append_data(struct sock *sk, } if (ip6_sk_ignore_df(sk)) - maxnonfragsize = sizeof(struct ipv6hdr) + IPV6_MAXPLEN; + maxnonfragsize = max_t(u32, mtu, sizeof(struct ipv6hdr) + IPV6_MAXPLEN); Because Big TCP support is limited only to TCP (ping uses UDP on both raw socket and ICMP datagram socket), it would have to be for IPv4 sent as multiple packets (IPv4 fragmentation), for IPv6 support IPv6 jumbograms (Hop-by-Hop option aka "Jumbo Payload option", see RFC 2675). Other ping implementations on Linux also limit it to similar values (Busybox: 65535, fping: 65507, inetutils: IPv4: 65399, IPv6: 65527, likely kernel limitation, FreeBSD limits on IPv4: 65507). Closes: iputils#550 Signed-off-by: Petr Vorel <[email protected]>
- Loading branch information