Skip to content

Commit 2cf545e

Browse files
kaberummakynes
authored andcommitted
net: core: add function for incremental IPv6 pseudo header checksum updates
Add inet_proto_csum_replace16 for incrementally updating IPv6 pseudo header checksums for IPv6 NAT. Signed-off-by: Patrick McHardy <[email protected]> Acked-by: David S. Miller <[email protected]>
1 parent 0ad352c commit 2cf545e

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

include/net/checksum.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ static inline void csum_replace2(__sum16 *sum, __be16 from, __be16 to)
109109
struct sk_buff;
110110
extern void inet_proto_csum_replace4(__sum16 *sum, struct sk_buff *skb,
111111
__be32 from, __be32 to, int pseudohdr);
112+
extern void inet_proto_csum_replace16(__sum16 *sum, struct sk_buff *skb,
113+
const __be32 *from, const __be32 *to,
114+
int pseudohdr);
112115

113116
static inline void inet_proto_csum_replace2(__sum16 *sum, struct sk_buff *skb,
114117
__be16 from, __be16 to,

net/core/utils.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,26 @@ void inet_proto_csum_replace4(__sum16 *sum, struct sk_buff *skb,
294294
}
295295
EXPORT_SYMBOL(inet_proto_csum_replace4);
296296

297+
void inet_proto_csum_replace16(__sum16 *sum, struct sk_buff *skb,
298+
const __be32 *from, const __be32 *to,
299+
int pseudohdr)
300+
{
301+
__be32 diff[] = {
302+
~from[0], ~from[1], ~from[2], ~from[3],
303+
to[0], to[1], to[2], to[3],
304+
};
305+
if (skb->ip_summed != CHECKSUM_PARTIAL) {
306+
*sum = csum_fold(csum_partial(diff, sizeof(diff),
307+
~csum_unfold(*sum)));
308+
if (skb->ip_summed == CHECKSUM_COMPLETE && pseudohdr)
309+
skb->csum = ~csum_partial(diff, sizeof(diff),
310+
~skb->csum);
311+
} else if (pseudohdr)
312+
*sum = ~csum_fold(csum_partial(diff, sizeof(diff),
313+
csum_unfold(*sum)));
314+
}
315+
EXPORT_SYMBOL(inet_proto_csum_replace16);
316+
297317
int mac_pton(const char *s, u8 *mac)
298318
{
299319
int i;

0 commit comments

Comments
 (0)