sock cookie initializers
Subsystems (8)
Willem de Bruijn
maintainercover sock cookie initializers
From: Willem de Bruijn <[email protected]>
Recent UDP GSO and SO_TXTIME features added new fields to cookie structs.
When adding a field, all sites where a struct is initialized have to be updated, which is a lot of boilerplate. Alternatively, a field can be initialized selectively, but this is fragile. I introduced a bug in udp gso where an uninitialized field was read. See also fix commit ("9887cba19978 ip: limit use of gso_size to udp").
Introduce initializers for structs ipcm(6)_cookie and sockc_cookie.
patch 1..3 do exactly this.
patch 4..5 make ipv4 and ipv6 handle cookies the same way and
remove some boilerplate in doing so.
patch 6 removes the udp gso branch that needed the above fix
Willem de Bruijn (6):
ipv4: ipcm_cookie initializers
ipv6: ipcm6_cookie initializer
sock: sockc cookie initializer
ipv6: fold sockcm_cookie into ipcm6_cookie
ip: remove tx_flags from ipcm_cookie and use same logic for v4 and v6
ip: unconditionally set cork gso_size
include/net/ip.h | 16 ++++++++++++++- include/net/ipv6.h | 26 ++++++++++++++++++++---- include/net/sock.h | 6 ++++++ include/net/transp_v6.h | 3 +-- net/ipv4/icmp.c | 11 ++-------- net/ipv4/ip_output.c | 12 ++++------- net/ipv4/ping.c | 11 +--------- net/ipv4/raw.c | 11 +--------- net/ipv4/tcp.c | 2 +- net/ipv4/udp.c | 12 +---------- net/ipv6/datagram.c | 4 ++-- net/ipv6/icmp.c | 14 ++++--------- net/ipv6/ip6_flowlabel.c | 3 +-- net/ipv6/ip6_output.c | 43 +++++++++++++++++----------------------- net/ipv6/ipv6_sockglue.c | 3 +-- net/ipv6/ping.c | 7 ++----- net/ipv6/raw.c | 15 +++++--------- net/ipv6/udp.c | 14 +++++-------- net/l2tp/l2tp_ip6.c | 10 +++------- net/packet/af_packet.c | 9 +++------ 20 files changed, 98 insertions(+), 134 deletions(-)
Signature · 1 line
2.18.0.399.gad0ab374a1-goog
Willem de Bruijn
maintainerPATCH 1/6 ipv4: ipcm_cookie initializers
From: Willem de Bruijn <[email protected]>
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").
--- include/net/ip.h | 15 +++++++++++++++ net/ipv4/icmp.c | 11 ++--------- net/ipv4/ip_output.c | 6 +----- net/ipv4/ping.c | 9 +-------- net/ipv4/raw.c | 9 +-------- net/ipv4/udp.c | 10 +--------- 6 files changed, 21 insertions(+), 39 deletions(-)
include/net/ip.h +15 -0
@@ -79,6 +79,21 @@ struct ipcm_cookie {__u16 gso_size; }; +static inline void ipcm_init (struct ipcm_cookie *ipcm) +{ + *ipcm = (struct ipcm_cookie ) { .tos =-1 }; +} + +static inline void ipcm_init_sk (struct ipcm_cookie *ipcm, +const struct inet_sock *inet) +{ +ipcm_init (ipcm); + + ipcm->sockc.tsflags = inet->sk.sk_tsflags; + ipcm->oif = inet->sk.sk_bound_dev_if; + ipcm->addr = inet->inet_saddr; +} +#define IPCB (skb) ((struct inet_skb_parm*)((skb)->cb))#define PKTINFO_SKB_CB (skb) ((struct in_pktinfo *)((skb)->cb))
net/ipv4/icmp.c +2 -9
@@ -429,15 +429,11 @@ static void icmp_reply(struct icmp_bxm *icmp_param, struct sk_buff *skb) icmp_param->data.icmph.checksum =0 ; +ipcm_init (&ipc); inet->tos =ip_hdr (skb)->tos; sk->sk_mark = mark; daddr = ipc.addr =ip_hdr (skb)->saddr; saddr =fib_compute_spec_dst (skb); - ipc.opt =NULL ; - ipc.tx_flags =0 ; - ipc.ttl =0 ; - ipc.tos =-1 ; - ipc.sockc.transmit_time =0 ;if (icmp_param->replyopts.opt.opt.optlen) { ipc.opt = &icmp_param->replyopts.opt;
@@ -711,12 +707,9 @@ void icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info) icmp_param.offset =skb_network_offset (skb_in);inet_sk (sk)->tos = tos; sk->sk_mark = mark; +ipcm_init (&ipc); ipc.addr = iph->saddr; ipc.opt = &icmp_param.replyopts.opt; - ipc.tx_flags =0 ; - ipc.ttl =0 ; - ipc.tos =-1 ; - ipc.sockc.transmit_time =0 ; rt =icmp_route_lookup (net, &fl4, skb_in, iph, saddr, tos, mark, type, code, &icmp_param);
net/ipv4/ip_output.c +1 -5
@@ -1548,12 +1548,8 @@ void ip_send_unicast_reply(struct sock *sk, struct sk_buff *skb,if (__ip_options_echo (net, &replyopts.opt.opt, skb, sopt))return ; +ipcm_init (&ipc); ipc.addr = daddr; - ipc.opt =NULL ; - ipc.tx_flags =0 ; - ipc.ttl =0 ; - ipc.tos =-1 ; - ipc.sockc.transmit_time =0 ;if (replyopts.opt.opt.optlen) { ipc.opt = &replyopts.opt;
net/ipv4/ping.c +1 -8
@@ -739,14 +739,7 @@ static int ping_v4_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)/* no remote port */ } - ipc.sockc.tsflags = sk->sk_tsflags; - ipc.addr = inet->inet_saddr; - ipc.opt =NULL ; - ipc.oif = sk->sk_bound_dev_if; - ipc.tx_flags =0 ; - ipc.ttl =0 ; - ipc.tos =-1 ; - ipc.sockc.transmit_time =0 ; +ipcm_init_sk (&ipc, inet);if (msg->msg_controllen) { err =ip_cmsg_send (sk, msg, &ipc, false);
net/ipv4/raw.c +1 -8
@@ -562,14 +562,7 @@ static int raw_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) daddr = inet->inet_daddr; } - ipc.sockc.tsflags = sk->sk_tsflags; - ipc.sockc.transmit_time =0 ; - ipc.addr = inet->inet_saddr; - ipc.opt =NULL ; - ipc.tx_flags =0 ; - ipc.ttl =0 ; - ipc.tos =-1 ; - ipc.oif = sk->sk_bound_dev_if; +ipcm_init_sk (&ipc, inet);if (msg->msg_controllen) { err =ip_cmsg_send (sk, msg, &ipc, false);
net/ipv4/udp.c +1 -9
@@ -926,12 +926,6 @@ int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)if (msg->msg_flags &MSG_OOB )/* Mirror BSD error message compatibility */ return -EOPNOTSUPP ; - ipc.opt =NULL ; - ipc.tx_flags =0 ; - ipc.ttl =0 ; - ipc.tos =-1 ; - ipc.sockc.transmit_time =0 ; - getfrag = is_udplite ? udplite_getfrag : ip_generic_getfrag; fl4 = &inet->cork.fl.u.ip4;
@@ -978,9 +972,7 @@ int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) connected =1 ; } - ipc.sockc.tsflags = sk->sk_tsflags; - ipc.addr = inet->inet_saddr; - ipc.oif = sk->sk_bound_dev_if; +ipcm_init_sk (&ipc, inet); ipc.gso_size = up->gso_size;if (msg->msg_controllen) {
Signature · 1 line
2.18.0.399.gad0ab374a1-goog
Willem de Bruijn
maintainerPATCH 2/6 ipv6: ipcm6_cookie initializer
In reply to Willem de BruijnFrom: Willem de Bruijn <[email protected]>
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").
--- include/net/ipv6.h | 19 +++++++++++++++++++ net/ipv6/icmp.c | 7 ++----- net/ipv6/ping.c | 4 +--- net/ipv6/raw.c | 5 +---- net/ipv6/udp.c | 4 +--- net/l2tp/l2tp_ip6.c | 4 +--- 6 files changed, 25 insertions(+), 18 deletions(-)
include/net/ipv6.h +19 -0
@@ -301,6 +301,25 @@ struct ipcm6_cookie {__u16 gso_size; }; +static inline void ipcm6_init (struct ipcm6_cookie *ipc6) +{ + *ipc6 = (struct ipcm6_cookie ) { + .hlimit =-1 , + .tclass =-1 , + .dontfrag =-1 , + }; +} + +static inline void ipcm6_init_sk (struct ipcm6_cookie *ipc6, +const struct ipv6_pinfo *np) +{ + *ipc6 = (struct ipcm6_cookie ) { + .hlimit =-1 , + .tclass = np->tclass, + .dontfrag = np->dontfrag, + }; +} +static inline struct ipv6_txoptions *txopt_get (const struct ipv6_pinfo *np) {struct ipv6_txoptions *opt;
net/ipv6/icmp.c +2 -5
@@ -545,7 +545,7 @@ static void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,else if (!fl6.flowi6_oif) fl6.flowi6_oif = np->ucast_oif; - ipc6.tclass = np->tclass; +ipcm6_init_sk (&ipc6, np); fl6.flowlabel =ip6_make_flowinfo (ipc6.tclass, fl6.flowlabel); dst =icmpv6_route_lookup (net, skb, sk, &fl6);
@@ -553,8 +553,6 @@ static void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info, goto out; ipc6.hlimit =ip6_sk_dst_hoplimit (np, &fl6, dst); - ipc6.dontfrag = np->dontfrag; - ipc6.opt =NULL ; msg.skb = skb; msg.offset =skb_network_offset (skb);
@@ -726,10 +724,9 @@ static void icmpv6_echo_reply(struct sk_buff *skb) msg.offset =0 ; msg.type =ICMPV6_ECHO_REPLY ; +ipcm6_init_sk (&ipc6, np); ipc6.hlimit =ip6_sk_dst_hoplimit (np, &fl6, dst); ipc6.tclass =ipv6_get_dsfield (ipv6_hdr (skb)); - ipc6.dontfrag = np->dontfrag; - ipc6.opt =NULL ; if (ip6_append_data(sk, icmpv6_getfrag, &msg, skb->len + sizeof(struct icmp6hdr),
net/ipv6/ping.c +1 -3
@@ -119,7 +119,7 @@ static int ping_v6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) fl6.fl6_icmp_code = user_icmph.icmp6_code;security_sk_classify_flow (sk,flowi6_to_flowi (&fl6)); - ipc6.tclass = np->tclass; +ipcm6_init_sk (&ipc6, np); fl6.flowlabel =ip6_make_flowinfo (ipc6.tclass, fl6.flowlabel); dst =ip6_sk_dst_lookup_flow (sk, &fl6, daddr, false);
@@ -142,8 +142,6 @@ static int ping_v6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) pfh.family =AF_INET6 ; ipc6.hlimit =ip6_sk_dst_hoplimit (np, &fl6, dst); - ipc6.dontfrag = np->dontfrag; - ipc6.opt =NULL ;lock_sock (sk); err = ip6_append_data(sk, ping_getfrag, &pfh, len,
net/ipv6/raw.c +1 -4
@@ -791,10 +791,7 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) fl6.flowi6_mark = sk->sk_mark; fl6.flowi6_uid = sk->sk_uid; - ipc6.hlimit =-1 ; - ipc6.tclass =-1 ; - ipc6.dontfrag =-1 ; - ipc6.opt =NULL ; +ipcm6_init (&ipc6);if (sin6) {if (addr_len <SIN6_LEN_RFC2133 )
net/ipv6/udp.c +1 -3
@@ -1143,9 +1143,7 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)int (*getfrag)(void *,char *,int ,int ,int ,struct sk_buff *);struct sockcm_cookie sockc; - ipc6.hlimit =-1 ; - ipc6.tclass =-1 ; - ipc6.dontfrag =-1 ; +ipcm6_init (&ipc6); ipc6.gso_size = up->gso_size; sockc.tsflags = sk->sk_tsflags; sockc.transmit_time =0 ;
net/l2tp/l2tp_ip6.c +1 -3
@@ -525,9 +525,7 @@ static int l2tp_ip6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) fl6.flowi6_mark = sk->sk_mark; fl6.flowi6_uid = sk->sk_uid; - ipc6.hlimit =-1 ; - ipc6.tclass =-1 ; - ipc6.dontfrag =-1 ; +ipcm6_init (&ipc6);if (lsa) {if (addr_len <SIN6_LEN_RFC2133 )
Signature · 1 line
2.18.0.399.gad0ab374a1-goog
Willem de Bruijn
maintainerPATCH 3/6 sock: sockc cookie initializer
In reply to Willem de BruijnFrom: Willem de Bruijn <[email protected]>
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").
--- include/net/sock.h | 6 ++++++ net/ipv4/tcp.c | 2 +- net/packet/af_packet.c | 9 +++------ 3 files changed, 10 insertions(+), 7 deletions(-)
include/net/sock.h +6 -0
@@ -1600,6 +1600,12 @@ struct sockcm_cookie {u16 tsflags; }; +static inline void sockcm_init (struct sockcm_cookie *sockc, +const struct sock *sk) +{ + *sockc = (struct sockcm_cookie ) { .tsflags = sk->sk_tsflags }; +} +int __sock_cmsg_send (struct sock *sk,struct msghdr *msg,struct cmsghdr *cmsg,struct sockcm_cookie *sockc); int sock_cmsg_send(struct sock *sk, struct msghdr *msg,
net/ipv4/tcp.c +1 -1
@@ -1241,7 +1241,7 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)/* 'common' sending to sendq */ } - sockc.tsflags = sk->sk_tsflags; +sockcm_init (&sockc, sk);if (msg->msg_controllen) { err =sock_cmsg_send (sk, msg, &sockc);if (unlikely (err)) {
net/packet/af_packet.c +3 -6
@@ -1951,8 +1951,7 @@ static int packet_sendmsg_spkt(struct socket *sock, struct msghdr *msg, goto out_unlock; } - sockc.transmit_time =0 ; - sockc.tsflags = sk->sk_tsflags; +sockcm_init (&sockc, sk);if (msg->msg_controllen) { err =sock_cmsg_send (sk, msg, &sockc);if (unlikely (err))
@@ -2636,8 +2635,7 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)if (unlikely (!(dev->flags &IFF_UP ))) goto out_put; - sockc.transmit_time =0 ; - sockc.tsflags = po->sk.sk_tsflags; +sockcm_init (&sockc, &po->sk);if (msg->msg_controllen) { err =sock_cmsg_send (&po->sk, msg, &sockc);if (unlikely (err))
@@ -2833,8 +2831,7 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)if (unlikely (!(dev->flags &IFF_UP ))) goto out_unlock; - sockc.transmit_time =0 ; - sockc.tsflags = sk->sk_tsflags; +sockcm_init (&sockc, sk); sockc.mark = sk->sk_mark;if (msg->msg_controllen) { err =sock_cmsg_send (sk, msg, &sockc);
Signature · 1 line
2.18.0.399.gad0ab374a1-goog
Willem de Bruijn
maintainerPATCH 4/6 ipv6: fold sockcm_cookie into ipcm6_cookie
In reply to Willem de BruijnFrom: Willem de Bruijn <[email protected]>
ipcm_cookie includes sockcm_cookie. Do the same for ipcm6_cookie.
This reduces the number of arguments that need to be passed around, applies ipcm6_init to all cookie fields at once and reduces code differentiation between ipv4 and ipv6.
--- include/net/ipv6.h | 7 +++---- include/net/transp_v6.h | 3 +-- net/ipv6/datagram.c | 4 ++-- net/ipv6/icmp.c | 7 ++----- net/ipv6/ip6_flowlabel.c | 3 +-- net/ipv6/ip6_output.c | 24 ++++++++++-------------- net/ipv6/ipv6_sockglue.c | 3 +-- net/ipv6/ping.c | 3 +-- net/ipv6/raw.c | 10 ++++------ net/ipv6/udp.c | 10 ++++------ net/l2tp/l2tp_ip6.c | 6 ++---- 11 files changed, 31 insertions(+), 49 deletions(-)
include/net/ipv6.h +3 -4
@@ -294,6 +294,7 @@ struct ipv6_fl_socklist { };struct ipcm6_cookie { +struct sockcm_cookie sockc;__s16 hlimit;__s16 tclass;__s8 dontfrag;
@@ -959,8 +960,7 @@ int ip6_append_data(struct sock *sk, int odd, struct sk_buff *skb), void *from, int length, int transhdrlen, struct ipcm6_cookie *ipc6, struct flowi6 *fl6, - struct rt6_info *rt, unsigned int flags, - const struct sockcm_cookie *sockc); + struct rt6_info *rt, unsigned int flags);int ip6_push_pending_frames (struct sock *sk);
@@ -977,8 +977,7 @@ struct sk_buff *ip6_make_skb(struct sock *sk, void *from, int length, int transhdrlen, struct ipcm6_cookie *ipc6, struct flowi6 *fl6, struct rt6_info *rt, unsigned int flags, - struct inet_cork_full *cork, - const struct sockcm_cookie *sockc); + struct inet_cork_full *cork);static inline struct sk_buff *ip6_finish_skb (struct sock *sk) {
include/net/transp_v6.h +1 -2
@@ -42,8 +42,7 @@ void ip6_datagram_recv_specific_ctl(struct sock *sk, struct msghdr *msg, struct sk_buff *skb);int ip6_datagram_send_ctl (struct net *net,struct sock *sk,struct msghdr *msg, -struct flowi6 *fl6,struct ipcm6_cookie *ipc6, -struct sockcm_cookie *sockc); +struct flowi6 *fl6,struct ipcm6_cookie *ipc6);void __ip6_dgram_sock_seq_show (struct seq_file *seq,struct sock *sp,__u16 srcp,__u16 destp,int rqueue,int bucket);
net/ipv6/datagram.c +2 -2
@@ -736,7 +736,7 @@ EXPORT_SYMBOL_GPL(ip6_datagram_recv_ctl);int ip6_datagram_send_ctl (struct net *net,struct sock *sk,struct msghdr *msg,struct flowi6 *fl6, -struct ipcm6_cookie *ipc6,struct sockcm_cookie *sockc) +struct ipcm6_cookie *ipc6) {struct in6_pktinfo *src_info;struct cmsghdr *cmsg;
@@ -755,7 +755,7 @@ int ip6_datagram_send_ctl(struct net *net, struct sock *sk, }if (cmsg->cmsg_level ==SOL_SOCKET ) { - err =__sock_cmsg_send (sk, msg, cmsg, sockc); + err =__sock_cmsg_send (sk, msg, cmsg, &ipc6->sockc);if (err)return err;continue ;
net/ipv6/icmp.c +2 -5
@@ -430,7 +430,6 @@ static void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,struct icmp6hdr tmp_hdr;struct flowi6 fl6;struct icmpv6_msg msg; -struct sockcm_cookie sockc_unused = {0 };struct ipcm6_cookie ipc6;int iif =0 ;int addr_type =0 ;
@@ -573,7 +572,7 @@ static void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info, len + sizeof(struct icmp6hdr), sizeof(struct icmp6hdr), &ipc6, &fl6, (struct rt6_info *)dst, - MSG_DONTWAIT, &sockc_unused)) { + MSG_DONTWAIT)) { ICMP6_INC_STATS(net, idev, ICMP6_MIB_OUTERRORS); ip6_flush_pending_frames(sk); } else {
@@ -677,7 +676,6 @@ static void icmpv6_echo_reply(struct sk_buff *skb)struct dst_entry *dst;struct ipcm6_cookie ipc6;u32 mark =IP6_REPLY_MARK (net, skb->mark); -struct sockcm_cookie sockc_unused = {0 }; saddr = &ipv6_hdr (skb)->daddr;
@@ -731,8 +729,7 @@ static void icmpv6_echo_reply(struct sk_buff *skb)if (ip6_append_data (sk, icmpv6_getfrag, &msg, skb->len +sizeof (struct icmp6hdr ),sizeof (struct icmp6hdr ), &ipc6, &fl6, - (struct rt6_info *)dst,MSG_DONTWAIT , - &sockc_unused)) { + (struct rt6_info *)dst,MSG_DONTWAIT )) {__ICMP6_INC_STATS (net, idev,ICMP6_MIB_OUTERRORS );ip6_flush_pending_frames (sk); }else {
net/ipv6/ip6_flowlabel.c +1 -2
@@ -373,7 +373,6 @@ fl_create(struct net *net, struct sock *sk, struct in6_flowlabel_req *freq,if (olen >0 ) {struct msghdr msg;struct flowi6 flowi6; -struct sockcm_cookie sockc_junk;struct ipcm6_cookie ipc6; err = -ENOMEM ;
@@ -392,7 +391,7 @@ fl_create(struct net *net, struct sock *sk, struct in6_flowlabel_req *freq,memset (&flowi6,0 ,sizeof (flowi6)); ipc6.opt = fl->opt; - err =ip6_datagram_send_ctl (net, sk, &msg, &flowi6, &ipc6, &sockc_junk); + err =ip6_datagram_send_ctl (net, sk, &msg, &flowi6, &ipc6);if (err) goto done; err = -EINVAL ;
net/ipv6/ip6_output.c +10 -14
@@ -1158,8 +1158,7 @@ static void ip6_append_data_mtu(unsigned int *mtu,static int ip6_setup_cork (struct sock *sk,struct inet_cork_full *cork,struct inet6_cork *v6_cork,struct ipcm6_cookie *ipc6, -struct rt6_info *rt,struct flowi6 *fl6, -const struct sockcm_cookie *sockc) +struct rt6_info *rt,struct flowi6 *fl6) {struct ipv6_pinfo *np =inet6_sk (sk);unsigned int mtu;
@@ -1227,7 +1226,7 @@ static int ip6_setup_cork(struct sock *sk, struct inet_cork_full *cork, cork->base.flags |=IPCORK_ALLFRAG ; cork->base.length =0 ; - cork->base.transmit_time = sockc->transmit_time; + cork->base.transmit_time = ipc6->sockc.transmit_time;return 0 ; }
@@ -1241,8 +1240,7 @@ static int __ip6_append_data(struct sock *sk,int getfrag (void *from,char *to,int offset,int len,int odd,struct sk_buff *skb), void *from, int length, int transhdrlen, - unsigned int flags, struct ipcm6_cookie *ipc6, - const struct sockcm_cookie *sockc) + unsigned int flags, struct ipcm6_cookie *ipc6) { struct sk_buff *skb, *skb_prev = NULL;unsigned int maxfraglen, fragheaderlen, mtu, orig_mtu, pmtu;
@@ -1321,7 +1319,7 @@ static int __ip6_append_data(struct sock *sk, csummode =CHECKSUM_PARTIAL ;if (sk->sk_type ==SOCK_DGRAM || sk->sk_type ==SOCK_RAW ) { -sock_tx_timestamp (sk, sockc->tsflags, &tx_flags); +sock_tx_timestamp (sk, ipc6->sockc.tsflags, &tx_flags);if (tx_flags &SKBTX_ANY_SW_TSTAMP && sk->sk_tsflags &SOF_TIMESTAMPING_OPT_ID ) tskey = sk->sk_tskey++;
@@ -1563,8 +1561,7 @@ int ip6_append_data(struct sock *sk, int odd, struct sk_buff *skb), void *from, int length, int transhdrlen, struct ipcm6_cookie *ipc6, struct flowi6 *fl6, - struct rt6_info *rt, unsigned int flags, - const struct sockcm_cookie *sockc) + struct rt6_info *rt, unsigned int flags) { struct inet_sock *inet = inet_sk(sk);struct ipv6_pinfo *np =inet6_sk (sk);
@@ -1578,7 +1575,7 @@ int ip6_append_data(struct sock *sk,* setup for corking */ err =ip6_setup_cork (sk, &inet->cork, &np->cork, - ipc6, rt, fl6, sockc); + ipc6, rt, fl6);if (err)return err;
@@ -1592,7 +1589,7 @@ int ip6_append_data(struct sock *sk,return __ip6_append_data (sk, fl6, &sk->sk_write_queue, &inet->cork.base, &np->cork,sk_page_frag (sk), getfrag, - from, length, transhdrlen, flags, ipc6, sockc); + from, length, transhdrlen, flags, ipc6); }EXPORT_SYMBOL_GPL (ip6_append_data);
@@ -1752,8 +1749,7 @@ struct sk_buff *ip6_make_skb(struct sock *sk, void *from, int length, int transhdrlen, struct ipcm6_cookie *ipc6, struct flowi6 *fl6, struct rt6_info *rt, unsigned int flags, - struct inet_cork_full *cork, - const struct sockcm_cookie *sockc) + struct inet_cork_full *cork) { struct inet6_cork v6_cork;struct sk_buff_head queue;
@@ -1770,7 +1766,7 @@ struct sk_buff *ip6_make_skb(struct sock *sk, cork->base.opt =NULL ; cork->base.dst =NULL ; v6_cork.opt =NULL ; - err =ip6_setup_cork (sk, cork, &v6_cork, ipc6, rt, fl6, sockc); + err =ip6_setup_cork (sk, cork, &v6_cork, ipc6, rt, fl6);if (err) {ip6_cork_release (cork, &v6_cork);return ERR_PTR (err);
@@ -1781,7 +1777,7 @@ struct sk_buff *ip6_make_skb(struct sock *sk, err =__ip6_append_data (sk, fl6, &queue, &cork->base, &v6_cork, ¤t->task_frag, getfrag, from, length + exthdrlen, transhdrlen + exthdrlen, - flags, ipc6, sockc); + flags, ipc6);if (err) {__ip6_flush_pending_frames (sk, &queue, cork, &v6_cork);return ERR_PTR (err);
net/ipv6/ipv6_sockglue.c +1 -2
@@ -489,7 +489,6 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,struct ipv6_txoptions *opt =NULL ;struct msghdr msg;struct flowi6 fl6; -struct sockcm_cookie sockc_junk;struct ipcm6_cookie ipc6;memset (&fl6,0 ,sizeof (fl6));
@@ -522,7 +521,7 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname, msg.msg_control = (void *)(opt+1 ); ipc6.opt = opt; - retv =ip6_datagram_send_ctl (net, sk, &msg, &fl6, &ipc6, &sockc_junk); + retv =ip6_datagram_send_ctl (net, sk, &msg, &fl6, &ipc6);if (retv) goto done; update:
net/ipv6/ping.c +1 -2
@@ -62,7 +62,6 @@ static int ping_v6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)struct dst_entry *dst;struct rt6_info *rt;struct pingfakehdr pfh; -struct sockcm_cookie junk = {0 };struct ipcm6_cookie ipc6;pr_debug ("ping_v6_sendmsg(sk=%p,sk->num=%u)\n" , inet, inet->inet_num);
@@ -146,7 +145,7 @@ static int ping_v6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)lock_sock (sk); err =ip6_append_data (sk, ping_getfrag, &pfh, len,0 , &ipc6, &fl6, rt, -MSG_DONTWAIT , &junk); +MSG_DONTWAIT );if (err) { ICMP6_INC_STATS(sock_net(sk), rt->rt6i_idev,
net/ipv6/raw.c +4 -6
@@ -767,7 +767,6 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)struct dst_entry *dst =NULL ;struct raw6_frag_vec rfv;struct flowi6 fl6; -struct sockcm_cookie sockc;struct ipcm6_cookie ipc6;int addr_len = msg->msg_namelen;u16 proto;
@@ -792,6 +791,7 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) fl6.flowi6_uid = sk->sk_uid;ipcm6_init (&ipc6); + ipc6.sockc.tsflags = sk->sk_tsflags;if (sin6) {if (addr_len <SIN6_LEN_RFC2133 )
@@ -845,15 +845,13 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)if (fl6.flowi6_oif ==0 ) fl6.flowi6_oif = sk->sk_bound_dev_if; - sockc.tsflags = sk->sk_tsflags; - sockc.transmit_time =0 ;if (msg->msg_controllen) { opt = &opt_space;memset (opt,0 ,sizeof (struct ipv6_txoptions )); opt->tot_len =sizeof (struct ipv6_txoptions ); ipc6.opt = opt; - err =ip6_datagram_send_ctl (sock_net (sk), sk, msg, &fl6, &ipc6, &sockc); + err =ip6_datagram_send_ctl (sock_net (sk), sk, msg, &fl6, &ipc6);if (err <0 ) {fl6_sock_release (flowlabel);return err;
@@ -921,13 +919,13 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) back_from_confirm:if (inet->hdrincl) err =rawv6_send_hdrinc (sk, msg, len, &fl6, &dst, - msg->msg_flags, &sockc); + msg->msg_flags, &ipc6.sockc);else { ipc6.opt = opt;lock_sock (sk); err =ip6_append_data (sk, raw6_getfrag, &rfv, len,0 , &ipc6, &fl6, (struct rt6_info *)dst, - msg->msg_flags, &sockc); + msg->msg_flags);if (err)ip6_flush_pending_frames (sk);
net/ipv6/udp.c +4 -6
@@ -1141,12 +1141,10 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)int err;int is_udplite =IS_UDPLITE (sk);int (*getfrag)(void *,char *,int ,int ,int ,struct sk_buff *); -struct sockcm_cookie sockc;ipcm6_init (&ipc6); ipc6.gso_size = up->gso_size; - sockc.tsflags = sk->sk_tsflags; - sockc.transmit_time =0 ; + ipc6.sockc.tsflags = sk->sk_tsflags;/* destination address check */ if (sin6) {
@@ -1281,7 +1279,7 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) err =udp_cmsg_send (sk, msg, &ipc6.gso_size);if (err >0 ) err =ip6_datagram_send_ctl (sock_net (sk), sk, msg, &fl6, - &ipc6, &sockc); + &ipc6);if (err <0 ) {fl6_sock_release (flowlabel);return err;
@@ -1375,7 +1373,7 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) skb =ip6_make_skb (sk, getfrag, msg, ulen,sizeof (struct udphdr ), &ipc6, &fl6, (struct rt6_info *)dst, - msg->msg_flags, &cork, &sockc); + msg->msg_flags, &cork); err =PTR_ERR (skb);if (!IS_ERR_OR_NULL (skb)) err =udp_v6_send_skb (skb, &fl6, &cork.base);
@@ -1401,7 +1399,7 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) up->len += ulen; err =ip6_append_data (sk, getfrag, msg, ulen,sizeof (struct udphdr ), &ipc6, &fl6, (struct rt6_info *)dst, - corkreq ? msg->msg_flags|MSG_MORE : msg->msg_flags, &sockc); + corkreq ? msg->msg_flags|MSG_MORE : msg->msg_flags);if (err)udp_v6_flush_pending_frames (sk);else if (!corkreq)
net/l2tp/l2tp_ip6.c +2 -4
@@ -500,7 +500,6 @@ static int l2tp_ip6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)struct ip6_flowlabel *flowlabel =NULL ;struct dst_entry *dst =NULL ;struct flowi6 fl6; -struct sockcm_cookie sockc_unused = {0 };struct ipcm6_cookie ipc6;int addr_len = msg->msg_namelen;int transhdrlen =4 ;/* zero session-id */
@@ -573,8 +572,7 @@ static int l2tp_ip6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) opt->tot_len =sizeof (struct ipv6_txoptions ); ipc6.opt = opt; - err =ip6_datagram_send_ctl (sock_net (sk), sk, msg, &fl6, &ipc6, - &sockc_unused); + err =ip6_datagram_send_ctl (sock_net (sk), sk, msg, &fl6, &ipc6);if (err <0 ) {fl6_sock_release (flowlabel);return err;
@@ -639,7 +637,7 @@ static int l2tp_ip6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) err =ip6_append_data (sk, ip_generic_getfrag, msg, ulen, transhdrlen, &ipc6, &fl6, (struct rt6_info *)dst, - msg->msg_flags, &sockc_unused); + msg->msg_flags);if (err)ip6_flush_pending_frames (sk);else if (!(msg->msg_flags &MSG_MORE ))
Signature · 1 line
2.18.0.399.gad0ab374a1-goog
Willem de Bruijn
maintainerPATCH 5/6 ip: remove tx_flags from ipcm_cookie and use same logic for v4 and v6
In reply to Willem de BruijnFrom: Willem de Bruijn <[email protected]>
skb_shinfo(skb)->tx_flags is derived from sk->sk_tsflags, possibly after modification by __sock_cmsg_send, by calling sock_tx_timestamp.
The IPv4 and IPv6 paths do this conversion differently. In IPv4, the individual protocols that support tx timestamps call this function and store the result in ipc.tx_flags. In IPv6, sock_tx_timestamp is called in __ip6_append_data.
There is no need to store both tx_flags and ts_flags in the cookie as one is derived from the other. Convert when setting up the cork and remove the redundant field. This is similar to IPv6, only have the conversion happen only once per datagram, in ip(6)_setup_cork.
Also change __ip6_append_data to match __ip_append_data. Only update tskey if timestamping is enabled with OPT_ID. The SOCK_.. test is
redundant: only valid protocols can have non-zero cork->tx_flags.
After this change the IPv4 and IPv6 logic is the same.
--- include/net/ip.h | 1 - net/ipv4/ip_output.c | 3 ++- net/ipv4/ping.c | 2 -- net/ipv4/raw.c | 2 -- net/ipv4/udp.c | 2 -- net/ipv6/ip6_output.c | 18 ++++++++---------- 6 files changed, 10 insertions(+), 18 deletions(-)
include/net/ip.h +0 -1
@@ -72,7 +72,6 @@ struct ipcm_cookie {__be32 addr;int oif;struct ip_options_rcu *opt; -__u8 tx_flags;__u8 ttl;__s16 tos;char priority;
net/ipv4/ip_output.c +2 -1
@@ -1153,8 +1153,9 @@ static int ip_setup_cork(struct sock *sk, struct inet_cork *cork, cork->ttl = ipc->ttl; cork->tos = ipc->tos; cork->priority = ipc->priority; - cork->tx_flags = ipc->tx_flags; cork->transmit_time = ipc->sockc.transmit_time; + cork->tx_flags =0 ; +sock_tx_timestamp (sk, ipc->sockc.tsflags, &cork->tx_flags);return 0 ; }
net/ipv4/ping.c +0 -2
@@ -763,8 +763,6 @@ static int ping_v4_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)rcu_read_unlock (); } -sock_tx_timestamp (sk, ipc.sockc.tsflags, &ipc.tx_flags); - saddr = ipc.addr; ipc.addr = faddr = daddr;
net/ipv4/raw.c +0 -2
@@ -665,8 +665,6 @@ static int raw_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) &rt, msg->msg_flags, &ipc.sockc); else { -sock_tx_timestamp (sk, ipc.sockc.tsflags, &ipc.tx_flags); -if (!ipc.addr) ipc.addr = fl4.daddr;lock_sock (sk);
net/ipv4/udp.c +0 -2
@@ -1020,8 +1020,6 @@ int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) saddr = ipc.addr; ipc.addr = faddr = daddr; -sock_tx_timestamp (sk, ipc.sockc.tsflags, &ipc.tx_flags); -if (ipc.opt && ipc.opt->opt.srr) {if (!daddr) { err = -EINVAL ;
net/ipv6/ip6_output.c +8 -10
@@ -1221,6 +1221,8 @@ static int ip6_setup_cork(struct sock *sk, struct inet_cork_full *cork, cork->base.fragsize = mtu; cork->base.gso_size = sk->sk_type ==SOCK_DGRAM && sk->sk_protocol ==IPPROTO_UDP ? ipc6->gso_size :0 ; + cork->base.tx_flags =0 ; +sock_tx_timestamp (sk, ipc6->sockc.tsflags, &cork->base.tx_flags);if (dst_allfrag (xfrm_dst_path (&rt->dst))) cork->base.flags |=IPCORK_ALLFRAG ;
@@ -1250,7 +1252,6 @@ static int __ip6_append_data(struct sock *sk,int copy;int err;int offset =0 ; -__u8 tx_flags =0 ;u32 tskey =0 ;struct rt6_info *rt = (struct rt6_info *)cork->dst;struct ipv6_txoptions *opt = v6_cork->opt;
@@ -1269,6 +1270,10 @@ static int __ip6_append_data(struct sock *sk, mtu = cork->gso_size ?IP6_MAX_MTU : cork->fragsize; orig_mtu = mtu; +if (cork->tx_flags &SKBTX_ANY_SW_TSTAMP && + sk->sk_tsflags &SOF_TIMESTAMPING_OPT_ID ) + tskey = sk->sk_tskey++; + hh_len =LL_RESERVED_SPACE (rt->dst.dev); fragheaderlen = sizeof(struct ipv6hdr) + rt->rt6i_nfheader_len +
@@ -1318,13 +1323,6 @@ static int __ip6_append_data(struct sock *sk, rt->dst.dev->features & (NETIF_F_IPV6_CSUM | NETIF_F_HW_CSUM)) csummode =CHECKSUM_PARTIAL ; -if (sk->sk_type ==SOCK_DGRAM || sk->sk_type ==SOCK_RAW ) { -sock_tx_timestamp (sk, ipc6->sockc.tsflags, &tx_flags); -if (tx_flags &SKBTX_ANY_SW_TSTAMP && - sk->sk_tsflags &SOF_TIMESTAMPING_OPT_ID ) - tskey = sk->sk_tskey++; - } -/* * Let's try using as much space as possible. * Use MTU if total length of the message fits into the MTU.
@@ -1443,8 +1441,8 @@ static int __ip6_append_data(struct sock *sk, dst_exthdrlen);/* Only the initial fragment is time stamped */ -skb_shinfo (skb)->tx_flags = tx_flags; - tx_flags =0 ; +skb_shinfo (skb)->tx_flags = cork->tx_flags; + cork->tx_flags =0 ;skb_shinfo (skb)->tskey = tskey; tskey =0 ;
Signature · 1 line
2.18.0.399.gad0ab374a1-goog
Willem de Bruijn
maintainerPATCH 6/6 ip: unconditionally set cork gso_size
In reply to Willem de BruijnFrom: Willem de Bruijn <[email protected]>
Now that ipc(6)->gso_size is correctly initialized in all callers of ip(6)_setup_cork, it is safe to unconditionally pass it to the cork.
--- net/ipv4/ip_output.c | 3 +-- net/ipv6/ip6_output.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-)
net/ipv4/ip_output.c +1 -2
@@ -1146,8 +1146,7 @@ static int ip_setup_cork(struct sock *sk, struct inet_cork *cork, cork->fragsize =ip_sk_use_pmtu (sk) ?dst_mtu (&rt->dst) : rt->dst.dev->mtu; - cork->gso_size = sk->sk_type ==SOCK_DGRAM && - sk->sk_protocol ==IPPROTO_UDP ? ipc->gso_size :0 ; + cork->gso_size = ipc->gso_size; cork->dst = &rt->dst; cork->length =0 ; cork->ttl = ipc->ttl;
net/ipv6/ip6_output.c +1 -2
@@ -1219,8 +1219,7 @@ static int ip6_setup_cork(struct sock *sk, struct inet_cork_full *cork,if (mtu <IPV6_MIN_MTU )return -EINVAL ; cork->base.fragsize = mtu; - cork->base.gso_size = sk->sk_type ==SOCK_DGRAM && - sk->sk_protocol ==IPPROTO_UDP ? ipc6->gso_size :0 ; + cork->base.gso_size = ipc6->gso_size; cork->base.tx_flags =0 ;sock_tx_timestamp (sk, ipc6->sockc.tsflags, &cork->base.tx_flags);
Signature · 1 line
2.18.0.399.gad0ab374a1-goog
Quoted 11 lines · Willem de Bruijn
From: Willem de Bruijn <[email protected]>
Recent UDP GSO and
SO_TXTIMEfeatures added new fields to cookie structs.When adding a field, all sites where a struct is initialized have to be updated, which is a lot of boilerplate. Alternatively, a field can be initialized selectively, but this is fragile. I introduced a bug in udp gso where an uninitialized field was read. See also fix commit ("
9887cba19978ip: limit use ofgso_sizeto udp").
Quoted 6 lines
Introduce initializers for structs ipcm(6)_cookie and
sockc_cookie.patch 1..3 do exactly this.
patch 4..5 make ipv4 and ipv6 handle cookies the same way and
remove some boilerplate in doing so.
patch 6 removes the udp gso branch that needed the above fix
I've applied this series and tested SO_TXTIME + the etf qdisc and everything is working just fine.
Thanks,
Jesus
Quoted 31 lines
Willem de Bruijn (6):
ipv4:ipcm_cookieinitializers
ipv6:ipcm6_cookieinitializer
sock: sockc cookie initializer
ipv6: foldsockcm_cookieintoipcm6_cookie
ip: removetx_flagsfromipcm_cookieand use same logic for v4 and v6
ip: unconditionally set corkgso_sizeinclude/net/ip.h | 16 ++++++++++++++- include/net/ipv6.h | 26 ++++++++++++++++++++---- include/net/sock.h | 6 ++++++ include/net/transp_v6.h | 3 +-- net/ipv4/icmp.c | 11 ++-------- net/ipv4/ip_output.c | 12 ++++------- net/ipv4/ping.c | 11 +--------- net/ipv4/raw.c | 11 +--------- net/ipv4/tcp.c | 2 +- net/ipv4/udp.c | 12 +---------- net/ipv6/datagram.c | 4 ++-- net/ipv6/icmp.c | 14 ++++--------- net/ipv6/ip6_flowlabel.c | 3 +-- net/ipv6/ip6_output.c | 43 +++++++++++++++++----------------------- net/ipv6/ipv6_sockglue.c | 3 +-- net/ipv6/ping.c | 7 ++----- net/ipv6/raw.c | 15 +++++--------- net/ipv6/udp.c | 14 +++++-------- net/l2tp/l2tp_ip6.c | 10 +++------- net/packet/af_packet.c | 9 +++------ 20 files changed, 98 insertions(+), 134 deletions(-)
Willem de Bruijn
maintainerQuoted 23 lines · Jesus Sanchez-Palencia
Quoted 11 lines · Willem de Bruijn
From: Willem de Bruijn <[email protected]>
Recent UDP GSO and
SO_TXTIMEfeatures added new fields to cookie structs.When adding a field, all sites where a struct is initialized have to be updated, which is a lot of boilerplate. Alternatively, a field can be initialized selectively, but this is fragile. I introduced a bug in udp gso where an uninitialized field was read. See also fix commit ("
9887cba19978ip: limit use ofgso_sizeto udp").Quoted 6 lines
Introduce initializers for structs ipcm(6)_cookie and
sockc_cookie.patch 1..3 do exactly this.
patch 4..5 make ipv4 and ipv6 handle cookies the same way and
remove some boilerplate in doing so.
patch 6 removes the udp gso branch that needed the above fix
Quoted 4 lines
I've applied this series and tested
SO_TXTIME+ the etf qdisc and everything is working just fine.
Thanks for testing, Jesus!
I also ran the udpgso and txtimestamp tests (and am expanding the second to run as part of kselftest, and have ipv6 and cmsg support).
David Miller
maintainerFrom: Willem de Bruijn <[email protected]>
Date: Fri, 6 Jul 2018 10:12:53 -0400
Quoted 11 lines
From: Willem de Bruijn <[email protected]>
Recent UDP GSO and
SO_TXTIMEfeatures added new fields to cookie structs.When adding a field, all sites where a struct is initialized have to be updated, which is a lot of boilerplate. Alternatively, a field can be initialized selectively, but this is fragile. I introduced a bug in udp gso where an uninitialized field was read. See also fix commit ("
9887cba19978ip: limit use ofgso_sizeto udp").
Quoted 6 lines
Introduce initializers for structs ipcm(6)_cookie and
sockc_cookie.patch 1..3 do exactly this.
patch 4..5 make ipv4 and ipv6 handle cookies the same way and
remove some boilerplate in doing so.
patch 6 removes the udp gso branch that needed the above fix
Series applied, thanks Willem.