Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: ip_tunnel: clean up endianness conversions

sparse complains about some harmless endianness issues:

> net/ipv4/ip_tunnel_core.c:225:43: warning: cast to restricted __be16
> net/ipv4/ip_tunnel_core.c:225:43: warning: incorrect type in initializer (different base types)
> net/ipv4/ip_tunnel_core.c:225:43: expected restricted __be16 [usertype] mtu
> net/ipv4/ip_tunnel_core.c:225:43: got unsigned short [usertype]

iptunnel_pmtud_build_icmp() uses the wrong flavour of byte-order conversion
when storing the MTU into the ICMPv4 packet. Use htons(), just like
iptunnel_pmtud_build_icmpv6() does.

> net/ipv4/ip_tunnel_core.c:248:35: warning: cast from restricted __be16
> net/ipv4/ip_tunnel_core.c:248:35: warning: incorrect type in argument 3 (different base types)
> net/ipv4/ip_tunnel_core.c:248:35: expected unsigned short type
> net/ipv4/ip_tunnel_core.c:248:35: got restricted __be16 [usertype]
> net/ipv4/ip_tunnel_core.c:341:35: warning: cast from restricted __be16
> net/ipv4/ip_tunnel_core.c:341:35: warning: incorrect type in argument 3 (different base types)
> net/ipv4/ip_tunnel_core.c:341:35: expected unsigned short type
> net/ipv4/ip_tunnel_core.c:341:35: got restricted __be16 [usertype]

eth_header() wants the Ethertype in host-order, use the correct flavour of
byte-order conversion.

> net/ipv4/ip_tunnel_core.c:600:45: warning: restricted __be16 degrades to integer
> net/ipv4/ip_tunnel_core.c:609:30: warning: incorrect type in assignment (different base types)
> net/ipv4/ip_tunnel_core.c:609:30: expected int type
> net/ipv4/ip_tunnel_core.c:609:30: got restricted __be16 [usertype]
> net/ipv4/ip_tunnel_core.c:619:30: warning: incorrect type in assignment (different base types)
> net/ipv4/ip_tunnel_core.c:619:30: expected int type
> net/ipv4/ip_tunnel_core.c:619:30: got restricted __be16 [usertype]
> net/ipv4/ip_tunnel_core.c:629:30: warning: incorrect type in assignment (different base types)
> net/ipv4/ip_tunnel_core.c:629:30: expected int type
> net/ipv4/ip_tunnel_core.c:629:30: got restricted __be16 [usertype]

The TUNNEL_* types are big-endian, so adjust the type of the local
variable in ip_tun_parse_opts().

Signed-off-by: Julian Wiedmann <jwi@linux.ibm.com>
Link: https://lore.kernel.org/r/20210107144008.25777-1-jwi@linux.ibm.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Julian Wiedmann and committed by
Jakub Kicinski
fda4fde2 f67b4ff2

+5 -4
+5 -4
net/ipv4/ip_tunnel_core.c
··· 222 222 .code = ICMP_FRAG_NEEDED, 223 223 .checksum = 0, 224 224 .un.frag.__unused = 0, 225 - .un.frag.mtu = ntohs(mtu), 225 + .un.frag.mtu = htons(mtu), 226 226 }; 227 227 icmph->checksum = ip_compute_csum(icmph, len); 228 228 skb_reset_transport_header(skb); ··· 245 245 246 246 skb->ip_summed = CHECKSUM_NONE; 247 247 248 - eth_header(skb, skb->dev, htons(eh.h_proto), eh.h_source, eh.h_dest, 0); 248 + eth_header(skb, skb->dev, ntohs(eh.h_proto), eh.h_source, eh.h_dest, 0); 249 249 skb_reset_mac_header(skb); 250 250 251 251 return skb->len; ··· 338 338 339 339 skb->ip_summed = CHECKSUM_NONE; 340 340 341 - eth_header(skb, skb->dev, htons(eh.h_proto), eh.h_source, eh.h_dest, 0); 341 + eth_header(skb, skb->dev, ntohs(eh.h_proto), eh.h_source, eh.h_dest, 0); 342 342 skb_reset_mac_header(skb); 343 343 344 344 return skb->len; ··· 583 583 static int ip_tun_parse_opts(struct nlattr *attr, struct ip_tunnel_info *info, 584 584 struct netlink_ext_ack *extack) 585 585 { 586 - int err, rem, opt_len, opts_len = 0, type = 0; 586 + int err, rem, opt_len, opts_len = 0; 587 587 struct nlattr *nla; 588 + __be16 type = 0; 588 589 589 590 if (!attr) 590 591 return 0;