Skip to content

Commit

Permalink
ipv6: ipcm6_cookie initializer
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 <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
wdebruij authored and davem330 committed Jul 7, 2018
1 parent 3517820 commit b515430
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 18 deletions.
19 changes: 19 additions & 0 deletions include/net/ipv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 2 additions & 5 deletions net/ipv6/icmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,16 +545,14 @@ 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);
if (IS_ERR(dst))
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);
Expand Down Expand Up @@ -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),
Expand Down
4 changes: 1 addition & 3 deletions net/ipv6/ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand Down
5 changes: 1 addition & 4 deletions net/ipv6/raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions net/ipv6/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions net/l2tp/l2tp_ip6.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b515430

Please sign in to comment.