Skip to content

Commit 286c234

Browse files
iamkafaidavem330
authored andcommitted
ipv6: Clean up ipv6_select_ident() and ip6_fragment()
This patch changes the ipv6_select_ident() signature to return a fragment id instead of taking a whole frag_hdr as a param to only set the frag_hdr->identification. It also cleans up ip6_fragment() to obtain the fragment id at the beginning instead of using multiple "if" later to check fragment id has been generated or not. Signed-off-by: Martin KaFai Lau <[email protected]> Cc: Hannes Frederic Sowa <[email protected]> Cc: Steffen Klassert <[email protected]> Cc: Julian Anastasov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 01b6961 commit 286c234

File tree

3 files changed

+9
-16
lines changed

3 files changed

+9
-16
lines changed

include/net/ipv6.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,7 @@ static inline int ipv6_addr_diff(const struct in6_addr *a1, const struct in6_add
671671
return __ipv6_addr_diff(a1, a2, sizeof(struct in6_addr));
672672
}
673673

674-
void ipv6_select_ident(struct net *net, struct frag_hdr *fhdr,
675-
struct rt6_info *rt);
674+
u32 ipv6_select_ident(struct net *net, struct rt6_info *rt);
676675
void ipv6_proxy_select_ident(struct net *net, struct sk_buff *skb);
677676

678677
int ip6_dst_hoplimit(struct dst_entry *dst);

net/ipv6/ip6_output.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ int ip6_fragment(struct sock *sk, struct sk_buff *skb,
551551
struct frag_hdr *fh;
552552
unsigned int mtu, hlen, left, len;
553553
int hroom, troom;
554-
__be32 frag_id = 0;
554+
__be32 frag_id;
555555
int ptr, offset = 0, err = 0;
556556
u8 *prevhdr, nexthdr = 0;
557557
struct net *net = dev_net(skb_dst(skb)->dev);
@@ -584,6 +584,8 @@ int ip6_fragment(struct sock *sk, struct sk_buff *skb,
584584
}
585585
mtu -= hlen + sizeof(struct frag_hdr);
586586

587+
frag_id = ipv6_select_ident(net, rt);
588+
587589
if (skb_has_frag_list(skb)) {
588590
int first_len = skb_pagelen(skb);
589591
struct sk_buff *frag2;
@@ -632,11 +634,10 @@ int ip6_fragment(struct sock *sk, struct sk_buff *skb,
632634
skb_reset_network_header(skb);
633635
memcpy(skb_network_header(skb), tmp_hdr, hlen);
634636

635-
ipv6_select_ident(net, fh, rt);
636637
fh->nexthdr = nexthdr;
637638
fh->reserved = 0;
638639
fh->frag_off = htons(IP6_MF);
639-
frag_id = fh->identification;
640+
fh->identification = frag_id;
640641

641642
first_len = skb_pagelen(skb);
642643
skb->data_len = first_len - skb_headlen(skb);
@@ -778,11 +779,7 @@ int ip6_fragment(struct sock *sk, struct sk_buff *skb,
778779
*/
779780
fh->nexthdr = nexthdr;
780781
fh->reserved = 0;
781-
if (!frag_id) {
782-
ipv6_select_ident(net, fh, rt);
783-
frag_id = fh->identification;
784-
} else
785-
fh->identification = frag_id;
782+
fh->identification = frag_id;
786783

787784
/*
788785
* Copy a block of the IP datagram.
@@ -1064,7 +1061,6 @@ static inline int ip6_ufo_append_data(struct sock *sk,
10641061

10651062
{
10661063
struct sk_buff *skb;
1067-
struct frag_hdr fhdr;
10681064
int err;
10691065

10701066
/* There is support for UDP large send offload by network
@@ -1106,8 +1102,7 @@ static inline int ip6_ufo_append_data(struct sock *sk,
11061102
skb_shinfo(skb)->gso_size = (mtu - fragheaderlen -
11071103
sizeof(struct frag_hdr)) & ~7;
11081104
skb_shinfo(skb)->gso_type = SKB_GSO_UDP;
1109-
ipv6_select_ident(sock_net(sk), &fhdr, rt);
1110-
skb_shinfo(skb)->ip6_frag_id = fhdr.identification;
1105+
skb_shinfo(skb)->ip6_frag_id = ipv6_select_ident(sock_net(sk), rt);
11111106

11121107
append:
11131108
return skb_append_datato_frags(sk, skb, getfrag, from,

net/ipv6/output_core.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ void ipv6_proxy_select_ident(struct net *net, struct sk_buff *skb)
6060
}
6161
EXPORT_SYMBOL_GPL(ipv6_proxy_select_ident);
6262

63-
void ipv6_select_ident(struct net *net, struct frag_hdr *fhdr,
64-
struct rt6_info *rt)
63+
u32 ipv6_select_ident(struct net *net, struct rt6_info *rt)
6564
{
6665
static u32 ip6_idents_hashrnd __read_mostly;
6766
u32 id;
@@ -70,7 +69,7 @@ void ipv6_select_ident(struct net *net, struct frag_hdr *fhdr,
7069

7170
id = __ipv6_select_ident(net, ip6_idents_hashrnd, &rt->rt6i_dst.addr,
7271
&rt->rt6i_src.addr);
73-
fhdr->identification = htonl(id);
72+
return htonl(id);
7473
}
7574
EXPORT_SYMBOL(ipv6_select_ident);
7675

0 commit comments

Comments
 (0)