Skip to content

Commit ed70fcf

Browse files
Tom Herbertdavem330
authored andcommitted
net: Call skb_checksum_init in IPv4
Call skb_checksum_init instead of private functions. Signed-off-by: Tom Herbert <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 76ba0aa commit ed70fcf

File tree

3 files changed

+10
-40
lines changed

3 files changed

+10
-40
lines changed

include/net/ip.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,12 @@ static inline void ip_select_ident_more(struct sk_buff *skb, struct dst_entry *d
342342
__ip_select_ident(iph, dst, more);
343343
}
344344

345+
static inline __wsum inet_compute_pseudo(struct sk_buff *skb, int proto)
346+
{
347+
return csum_tcpudp_nofold(ip_hdr(skb)->saddr, ip_hdr(skb)->daddr,
348+
skb->len, proto, 0);
349+
}
350+
345351
/*
346352
* Map a multicast IP onto multicast MAC for type ethernet.
347353
*/

net/ipv4/tcp_ipv4.c

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,28 +1744,6 @@ static struct sock *tcp_v4_hnd_req(struct sock *sk, struct sk_buff *skb)
17441744
return sk;
17451745
}
17461746

1747-
static __sum16 tcp_v4_checksum_init(struct sk_buff *skb)
1748-
{
1749-
const struct iphdr *iph = ip_hdr(skb);
1750-
1751-
if (skb->ip_summed == CHECKSUM_COMPLETE) {
1752-
if (!tcp_v4_check(skb->len, iph->saddr,
1753-
iph->daddr, skb->csum)) {
1754-
skb->ip_summed = CHECKSUM_UNNECESSARY;
1755-
return 0;
1756-
}
1757-
}
1758-
1759-
skb->csum = csum_tcpudp_nofold(iph->saddr, iph->daddr,
1760-
skb->len, IPPROTO_TCP, 0);
1761-
1762-
if (skb->len <= 76) {
1763-
return __skb_checksum_complete(skb);
1764-
}
1765-
return 0;
1766-
}
1767-
1768-
17691747
/* The socket must have it's spinlock held when we get
17701748
* here.
17711749
*
@@ -1960,7 +1938,8 @@ int tcp_v4_rcv(struct sk_buff *skb)
19601938
* Packet length and doff are validated by header prediction,
19611939
* provided case of th->doff==0 is eliminated.
19621940
* So, we defer the checks. */
1963-
if (!skb_csum_unnecessary(skb) && tcp_v4_checksum_init(skb))
1941+
1942+
if (skb_checksum_init(skb, IPPROTO_TCP, inet_compute_pseudo))
19641943
goto csum_error;
19651944

19661945
th = tcp_hdr(skb);

net/ipv4/udp.c

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,7 +1672,6 @@ static int __udp4_lib_mcast_deliver(struct net *net, struct sk_buff *skb,
16721672
static inline int udp4_csum_init(struct sk_buff *skb, struct udphdr *uh,
16731673
int proto)
16741674
{
1675-
const struct iphdr *iph;
16761675
int err;
16771676

16781677
UDP_SKB_CB(skb)->partial_cov = 0;
@@ -1684,22 +1683,8 @@ static inline int udp4_csum_init(struct sk_buff *skb, struct udphdr *uh,
16841683
return err;
16851684
}
16861685

1687-
iph = ip_hdr(skb);
1688-
if (uh->check == 0) {
1689-
skb->ip_summed = CHECKSUM_UNNECESSARY;
1690-
} else if (skb->ip_summed == CHECKSUM_COMPLETE) {
1691-
if (!csum_tcpudp_magic(iph->saddr, iph->daddr, skb->len,
1692-
proto, skb->csum))
1693-
skb->ip_summed = CHECKSUM_UNNECESSARY;
1694-
}
1695-
if (!skb_csum_unnecessary(skb))
1696-
skb->csum = csum_tcpudp_nofold(iph->saddr, iph->daddr,
1697-
skb->len, proto, 0);
1698-
/* Probably, we should checksum udp header (it should be in cache
1699-
* in any case) and data in tiny packets (< rx copybreak).
1700-
*/
1701-
1702-
return 0;
1686+
return skb_checksum_init_zero_check(skb, proto, uh->check,
1687+
inet_compute_pseudo);
17031688
}
17041689

17051690
/*

0 commit comments

Comments
 (0)