Skip to content

Commit

Permalink
Merge branch 'act_csum-sctp'
Browse files Browse the repository at this point in the history
Davide Caratti says:

====================
net/sched: act_csum: add support for SCTP checksum

This series extends current act_csum functionality to allow computation of
SCTP checksums. Patch 1 ensures LIBCRC32C will be selected if NET_ACT_CSUM
is selected. Patch 2 extends act_csum to handle IPPROTO_SCTP protocol in
IPv4/IPv6 header, and eventually compute the CRC32c value.

v2:
- style fix in tc_csum.h
- avoid nested if statement in act_csum.c
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Jan 9, 2017
2 parents 07e0e04 + c008b33 commit 5126560
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
3 changes: 2 additions & 1 deletion include/uapi/linux/tc_act/tc_csum.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ enum {
TCA_CSUM_UPDATE_FLAG_IGMP = 4,
TCA_CSUM_UPDATE_FLAG_TCP = 8,
TCA_CSUM_UPDATE_FLAG_UDP = 16,
TCA_CSUM_UPDATE_FLAG_UDPLITE = 32
TCA_CSUM_UPDATE_FLAG_UDPLITE = 32,
TCA_CSUM_UPDATE_FLAG_SCTP = 64,
};

struct tc_csum {
Expand Down
1 change: 1 addition & 0 deletions net/sched/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ config NET_ACT_SKBEDIT
config NET_ACT_CSUM
tristate "Checksum Updating"
depends on NET_CLS_ACT && INET
select LIBCRC32C
---help---
Say Y here to update some common checksum after some direct
packet alterations.
Expand Down
30 changes: 30 additions & 0 deletions net/sched/act_csum.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <net/tcp.h>
#include <net/udp.h>
#include <net/ip6_checksum.h>
#include <net/sctp/checksum.h>

#include <net/act_api.h>

Expand Down Expand Up @@ -322,6 +323,25 @@ static int tcf_csum_ipv6_udp(struct sk_buff *skb, unsigned int ihl,
return 1;
}

static int tcf_csum_sctp(struct sk_buff *skb, unsigned int ihl,
unsigned int ipl)
{
struct sctphdr *sctph;

if (skb_is_gso(skb) && skb_shinfo(skb)->gso_type & SKB_GSO_SCTP)
return 1;

sctph = tcf_csum_skb_nextlayer(skb, ihl, ipl, sizeof(*sctph));
if (!sctph)
return 0;

sctph->checksum = sctp_compute_cksum(skb,
skb_network_offset(skb) + ihl);
skb->ip_summed = CHECKSUM_NONE;

return 1;
}

static int tcf_csum_ipv4(struct sk_buff *skb, u32 update_flags)
{
const struct iphdr *iph;
Expand Down Expand Up @@ -365,6 +385,11 @@ static int tcf_csum_ipv4(struct sk_buff *skb, u32 update_flags)
ntohs(iph->tot_len), 1))
goto fail;
break;
case IPPROTO_SCTP:
if ((update_flags & TCA_CSUM_UPDATE_FLAG_SCTP) &&
!tcf_csum_sctp(skb, iph->ihl * 4, ntohs(iph->tot_len)))
goto fail;
break;
}

if (update_flags & TCA_CSUM_UPDATE_FLAG_IPV4HDR) {
Expand Down Expand Up @@ -481,6 +506,11 @@ static int tcf_csum_ipv6(struct sk_buff *skb, u32 update_flags)
pl + sizeof(*ip6h), 1))
goto fail;
goto done;
case IPPROTO_SCTP:
if ((update_flags & TCA_CSUM_UPDATE_FLAG_SCTP) &&
!tcf_csum_sctp(skb, hl, pl + sizeof(*ip6h)))
goto fail;
goto done;
default:
goto ignore_skb;
}
Expand Down

0 comments on commit 5126560

Please sign in to comment.