Skip to content

Commit

Permalink
ipv4: ipcm_cookie initializers
Browse files Browse the repository at this point in the history
Initialize the cookie in one location to reduce code duplication and
avoid bugs from inconsistent initialization, such as that fixed in
commit 9887cba ("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>
  • Loading branch information
Willem de Bruijn authored and David S. Miller committed Jul 7, 2018
1 parent ab8565a commit 3517820
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 39 deletions.
15 changes: 15 additions & 0 deletions include/net/ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
11 changes: 2 additions & 9 deletions net/ipv4/icmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 1 addition & 5 deletions net/ipv4/ip_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 1 addition & 8 deletions net/ipv4/ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 1 addition & 8 deletions net/ipv4/raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 1 addition & 9 deletions net/ipv4/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 3517820

Please sign in to comment.