aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4
diff options
context:
space:
mode:
authorTom Herbert <therbert@google.com>2014-06-04 20:19:48 -0400
committerDavid S. Miller <davem@davemloft.net>2014-06-05 01:46:38 -0400
commitaf5fcba7f38f3166392f4087ab734433c84f160b (patch)
tree8a6deba10cd458a72e159112ab6381bcaa352b3e /net/ipv4
parent6579867c8b02606e101a6c511c2511b027ed3f4a (diff)
udp: Generic functions to set checksum
Added udp_set_csum and udp6_set_csum functions to set UDP checksums in packets. These are for simple UDP packets such as those that might be created in UDP tunnels. Signed-off-by: Tom Herbert <therbert@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4')
-rw-r--r--net/ipv4/udp.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index e07d52b8617a..a84f6762ea9e 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -762,6 +762,43 @@ void udp4_hwcsum(struct sk_buff *skb, __be32 src, __be32 dst)
762} 762}
763EXPORT_SYMBOL_GPL(udp4_hwcsum); 763EXPORT_SYMBOL_GPL(udp4_hwcsum);
764 764
765/* Function to set UDP checksum for an IPv4 UDP packet. This is intended
766 * for the simple case like when setting the checksum for a UDP tunnel.
767 */
768void udp_set_csum(bool nocheck, struct sk_buff *skb,
769 __be32 saddr, __be32 daddr, int len)
770{
771 struct udphdr *uh = udp_hdr(skb);
772
773 if (nocheck)
774 uh->check = 0;
775 else if (skb_is_gso(skb))
776 uh->check = ~udp_v4_check(len, saddr, daddr, 0);
777 else if (skb_dst(skb) && skb_dst(skb)->dev &&
778 (skb_dst(skb)->dev->features & NETIF_F_V4_CSUM)) {
779
780 BUG_ON(skb->ip_summed == CHECKSUM_PARTIAL);
781
782 skb->ip_summed = CHECKSUM_PARTIAL;
783 skb->csum_start = skb_transport_header(skb) - skb->head;
784 skb->csum_offset = offsetof(struct udphdr, check);
785 uh->check = ~udp_v4_check(len, saddr, daddr, 0);
786 } else {
787 __wsum csum;
788
789 BUG_ON(skb->ip_summed == CHECKSUM_PARTIAL);
790
791 uh->check = 0;
792 csum = skb_checksum(skb, 0, len, 0);
793 uh->check = udp_v4_check(len, saddr, daddr, csum);
794 if (uh->check == 0)
795 uh->check = CSUM_MANGLED_0;
796
797 skb->ip_summed = CHECKSUM_UNNECESSARY;
798 }
799}
800EXPORT_SYMBOL(udp_set_csum);
801
765static int udp_send_skb(struct sk_buff *skb, struct flowi4 *fl4) 802static int udp_send_skb(struct sk_buff *skb, struct flowi4 *fl4)
766{ 803{
767 struct sock *sk = skb->sk; 804 struct sock *sk = skb->sk;