diff options
author | Willem de Bruijn <willemb@google.com> | 2018-07-06 10:12:56 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2018-07-06 21:58:49 -0400 |
commit | 657a0667025e77cc17f8a38b93e60a2bc24d830c (patch) | |
tree | 394fbb294b0ff5a62ff14e306ef727b21f4b2352 | |
parent | b515430ac9c25d5192cf498af3c6be6c4f51caad (diff) |
sock: sockc cookie initializer
Initialize the cookie in one location to reduce code duplication and
avoid bugs from inconsistent initialization, such as that fixed in
commit 9887cba19978 ("ip: limit use of gso_size to udp").
Signed-off-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | include/net/sock.h | 6 | ||||
-rw-r--r-- | net/ipv4/tcp.c | 2 | ||||
-rw-r--r-- | net/packet/af_packet.c | 9 |
3 files changed, 10 insertions, 7 deletions
diff --git a/include/net/sock.h b/include/net/sock.h index e0eac9ef44b5..83b747538bd0 100644 --- a/include/net/sock.h +++ b/include/net/sock.h | |||
@@ -1600,6 +1600,12 @@ struct sockcm_cookie { | |||
1600 | u16 tsflags; | 1600 | u16 tsflags; |
1601 | }; | 1601 | }; |
1602 | 1602 | ||
1603 | static inline void sockcm_init(struct sockcm_cookie *sockc, | ||
1604 | const struct sock *sk) | ||
1605 | { | ||
1606 | *sockc = (struct sockcm_cookie) { .tsflags = sk->sk_tsflags }; | ||
1607 | } | ||
1608 | |||
1603 | int __sock_cmsg_send(struct sock *sk, struct msghdr *msg, struct cmsghdr *cmsg, | 1609 | int __sock_cmsg_send(struct sock *sk, struct msghdr *msg, struct cmsghdr *cmsg, |
1604 | struct sockcm_cookie *sockc); | 1610 | struct sockcm_cookie *sockc); |
1605 | int sock_cmsg_send(struct sock *sk, struct msghdr *msg, | 1611 | int sock_cmsg_send(struct sock *sk, struct msghdr *msg, |
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index bf461fa77ed6..850dc8f15afc 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c | |||
@@ -1241,7 +1241,7 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size) | |||
1241 | /* 'common' sending to sendq */ | 1241 | /* 'common' sending to sendq */ |
1242 | } | 1242 | } |
1243 | 1243 | ||
1244 | sockc.tsflags = sk->sk_tsflags; | 1244 | sockcm_init(&sockc, sk); |
1245 | if (msg->msg_controllen) { | 1245 | if (msg->msg_controllen) { |
1246 | err = sock_cmsg_send(sk, msg, &sockc); | 1246 | err = sock_cmsg_send(sk, msg, &sockc); |
1247 | if (unlikely(err)) { | 1247 | if (unlikely(err)) { |
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index 3428f7739ae9..47931ebfaef3 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c | |||
@@ -1951,8 +1951,7 @@ retry: | |||
1951 | goto out_unlock; | 1951 | goto out_unlock; |
1952 | } | 1952 | } |
1953 | 1953 | ||
1954 | sockc.transmit_time = 0; | 1954 | sockcm_init(&sockc, sk); |
1955 | sockc.tsflags = sk->sk_tsflags; | ||
1956 | if (msg->msg_controllen) { | 1955 | if (msg->msg_controllen) { |
1957 | err = sock_cmsg_send(sk, msg, &sockc); | 1956 | err = sock_cmsg_send(sk, msg, &sockc); |
1958 | if (unlikely(err)) | 1957 | if (unlikely(err)) |
@@ -2636,8 +2635,7 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg) | |||
2636 | if (unlikely(!(dev->flags & IFF_UP))) | 2635 | if (unlikely(!(dev->flags & IFF_UP))) |
2637 | goto out_put; | 2636 | goto out_put; |
2638 | 2637 | ||
2639 | sockc.transmit_time = 0; | 2638 | sockcm_init(&sockc, &po->sk); |
2640 | sockc.tsflags = po->sk.sk_tsflags; | ||
2641 | if (msg->msg_controllen) { | 2639 | if (msg->msg_controllen) { |
2642 | err = sock_cmsg_send(&po->sk, msg, &sockc); | 2640 | err = sock_cmsg_send(&po->sk, msg, &sockc); |
2643 | if (unlikely(err)) | 2641 | if (unlikely(err)) |
@@ -2833,8 +2831,7 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len) | |||
2833 | if (unlikely(!(dev->flags & IFF_UP))) | 2831 | if (unlikely(!(dev->flags & IFF_UP))) |
2834 | goto out_unlock; | 2832 | goto out_unlock; |
2835 | 2833 | ||
2836 | sockc.transmit_time = 0; | 2834 | sockcm_init(&sockc, sk); |
2837 | sockc.tsflags = sk->sk_tsflags; | ||
2838 | sockc.mark = sk->sk_mark; | 2835 | sockc.mark = sk->sk_mark; |
2839 | if (msg->msg_controllen) { | 2836 | if (msg->msg_controllen) { |
2840 | err = sock_cmsg_send(sk, msg, &sockc); | 2837 | err = sock_cmsg_send(sk, msg, &sockc); |