Commit cafbe182 authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller
Browse files

inet: move inet->hdrincl to inet->inet_flags



IP_HDRINCL socket option can now be set/read
without locking the socket.

Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Acked-by: default avatarSoheil Hassas Yeganeh <soheil@google.com>
Reviewed-by: default avatarSimon Horman <horms@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 3f7e7532
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -231,7 +231,6 @@ struct inet_sock {
	__u8			mc_ttl;
	__u8			pmtudisc;
	__u8			is_icsk:1,
				hdrincl:1,
				mc_loop:1,
				transparent:1,
				mc_all:1,
@@ -271,6 +270,7 @@ enum {
	INET_FLAGS_RECVERR	= 9,
	INET_FLAGS_RECVERR_RFC4884 = 10,
	INET_FLAGS_FREEBIND	= 11,
	INET_FLAGS_HDRINCL	= 12,
};

/* cmsg flags for inet */
@@ -397,7 +397,7 @@ static inline __u8 inet_sk_flowi_flags(const struct sock *sk)
{
	__u8 flags = 0;

	if (inet_sk(sk)->transparent || inet_sk(sk)->hdrincl)
	if (inet_sk(sk)->transparent || inet_test_bit(HDRINCL, sk))
		flags |= FLOWI_FLAG_ANYSRC;
	return flags;
}
+1 −1
Original line number Diff line number Diff line
@@ -338,7 +338,7 @@ static int inet_create(struct net *net, struct socket *sock, int protocol,
	if (SOCK_RAW == sock->type) {
		inet->inet_num = protocol;
		if (IPPROTO_RAW == protocol)
			inet->hdrincl = 1;
			inet_set_bit(HDRINCL, sk);
	}

	if (READ_ONCE(net->ipv4.sysctl_ip_no_pmtu_disc))
+1 −1
Original line number Diff line number Diff line
@@ -185,7 +185,7 @@ int inet_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb,
	inet_sockopt.recverr	= inet_test_bit(RECVERR, sk);
	inet_sockopt.is_icsk	= inet->is_icsk;
	inet_sockopt.freebind	= inet_test_bit(FREEBIND, sk);
	inet_sockopt.hdrincl	= inet->hdrincl;
	inet_sockopt.hdrincl	= inet_test_bit(HDRINCL, sk);
	inet_sockopt.mc_loop	= inet->mc_loop;
	inet_sockopt.transparent = inet->transparent;
	inet_sockopt.mc_all	= inet->mc_all;
+3 −2
Original line number Diff line number Diff line
@@ -1039,7 +1039,7 @@ static int __ip_append_data(struct sock *sk,
			}
		}
	} else if ((flags & MSG_SPLICE_PAGES) && length) {
		if (inet->hdrincl)
		if (inet_test_bit(HDRINCL, sk))
			return -EPERM;
		if (rt->dst.dev->features & NETIF_F_SG &&
		    getfrag == ip_generic_getfrag)
@@ -1467,7 +1467,8 @@ struct sk_buff *__ip_make_skb(struct sock *sk,
		 * so icmphdr does not in skb linear region and can not get icmp_type
		 * by icmp_hdr(skb)->type.
		 */
		if (sk->sk_type == SOCK_RAW && !inet_sk(sk)->hdrincl)
		if (sk->sk_type == SOCK_RAW &&
		    !inet_test_bit(HDRINCL, sk))
			icmp_type = fl4->fl4_icmp_type;
		else
			icmp_type = icmp_hdr(skb)->type;
+8 −10
Original line number Diff line number Diff line
@@ -988,6 +988,11 @@ int do_ip_setsockopt(struct sock *sk, int level, int optname,
			return -EINVAL;
		inet_assign_bit(FREEBIND, sk, val);
		return 0;
	case IP_HDRINCL:
		if (sk->sk_type != SOCK_RAW)
			return -ENOPROTOOPT;
		inet_assign_bit(HDRINCL, sk, val);
		return 0;
	}

	err = 0;
@@ -1052,13 +1057,6 @@ int do_ip_setsockopt(struct sock *sk, int level, int optname,
			goto e_inval;
		inet->uc_ttl = val;
		break;
	case IP_HDRINCL:
		if (sk->sk_type != SOCK_RAW) {
			err = -ENOPROTOOPT;
			break;
		}
		inet->hdrincl = val ? 1 : 0;
		break;
	case IP_NODEFRAG:
		if (sk->sk_type != SOCK_RAW) {
			err = -ENOPROTOOPT;
@@ -1578,6 +1576,9 @@ int do_ip_getsockopt(struct sock *sk, int level, int optname,
	case IP_FREEBIND:
		val = inet_test_bit(FREEBIND, sk);
		goto copyval;
	case IP_HDRINCL:
		val = inet_test_bit(HDRINCL, sk);
		goto copyval;
	}

	if (needs_rtnl)
@@ -1625,9 +1626,6 @@ int do_ip_getsockopt(struct sock *sk, int level, int optname,
		       inet->uc_ttl);
		break;
	}
	case IP_HDRINCL:
		val = inet->hdrincl;
		break;
	case IP_NODEFRAG:
		val = inet->nodefrag;
		break;
Loading