Skip to content

Commit

Permalink
net: use skb_is_gso_sctp() instead of open-coding
Browse files Browse the repository at this point in the history
As well as the basic conversion, I noticed that a lot of the
SCTP code checks gso_type without first checking skb_is_gso()
so I have added that where appropriate.

Also, document the helper.

Cc: Daniel Borkmann <[email protected]>
Cc: Marcelo Ricardo Leitner <[email protected]>
Signed-off-by: Daniel Axtens <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
daxtens authored and davem330 committed Mar 9, 2018
1 parent ca0edb1 commit 1dd27cd
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 9 deletions.
5 changes: 4 additions & 1 deletion Documentation/networking/segmentation-offloads.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ Therefore, any code in the core networking stack must be aware of the
possibility that gso_size will be GSO_BY_FRAGS and handle that case
appropriately.

There are a couple of helpers to make this easier:
There are some helpers to make this easier:

- skb_is_gso(skb) && skb_is_gso_sctp(skb) is the best way to see if
an skb is an SCTP GSO skb.

- For size checks, the skb_gso_validate_*_len family of helpers correctly
considers GSO_BY_FRAGS.
Expand Down
2 changes: 1 addition & 1 deletion net/core/skbuff.c
Original file line number Diff line number Diff line change
Expand Up @@ -4904,7 +4904,7 @@ static unsigned int skb_gso_transport_seglen(const struct sk_buff *skb)
thlen += inner_tcp_hdrlen(skb);
} else if (likely(shinfo->gso_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6))) {
thlen = tcp_hdrlen(skb);
} else if (unlikely(shinfo->gso_type & SKB_GSO_SCTP)) {
} else if (unlikely(skb_is_gso_sctp(skb))) {
thlen = sizeof(struct sctphdr);
}
/* UFO sets gso_size to the size of the fragmentation
Expand Down
2 changes: 1 addition & 1 deletion net/sched/act_csum.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ static int tcf_csum_sctp(struct sk_buff *skb, unsigned int ihl,
{
struct sctphdr *sctph;

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

sctph = tcf_csum_skb_nextlayer(skb, ihl, ipl, sizeof(*sctph));
Expand Down
8 changes: 4 additions & 4 deletions net/sctp/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ int sctp_rcv(struct sk_buff *skb)
int family;
struct sctp_af *af;
struct net *net = dev_net(skb->dev);
bool is_gso = skb_is_gso(skb) && skb_is_gso_sctp(skb);

if (skb->pkt_type != PACKET_HOST)
goto discard_it;
Expand All @@ -123,8 +124,7 @@ int sctp_rcv(struct sk_buff *skb)
* it's better to just linearize it otherwise crc computing
* takes longer.
*/
if ((!(skb_shinfo(skb)->gso_type & SKB_GSO_SCTP) &&
skb_linearize(skb)) ||
if ((!is_gso && skb_linearize(skb)) ||
!pskb_may_pull(skb, sizeof(struct sctphdr)))
goto discard_it;

Expand All @@ -135,7 +135,7 @@ int sctp_rcv(struct sk_buff *skb)
if (skb_csum_unnecessary(skb))
__skb_decr_checksum_unnecessary(skb);
else if (!sctp_checksum_disable &&
!(skb_shinfo(skb)->gso_type & SKB_GSO_SCTP) &&
!is_gso &&
sctp_rcv_checksum(net, skb) < 0)
goto discard_it;
skb->csum_valid = 1;
Expand Down Expand Up @@ -1218,7 +1218,7 @@ static struct sctp_association *__sctp_rcv_lookup_harder(struct net *net,
* issue as packets hitting this are mostly INIT or INIT-ACK and
* those cannot be on GSO-style anyway.
*/
if ((skb_shinfo(skb)->gso_type & SKB_GSO_SCTP) == SKB_GSO_SCTP)
if (skb_is_gso(skb) && skb_is_gso_sctp(skb))
return NULL;

ch = (struct sctp_chunkhdr *)skb->data;
Expand Down
2 changes: 1 addition & 1 deletion net/sctp/inqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ struct sctp_chunk *sctp_inq_pop(struct sctp_inq *queue)

chunk = list_entry(entry, struct sctp_chunk, list);

if ((skb_shinfo(chunk->skb)->gso_type & SKB_GSO_SCTP) == SKB_GSO_SCTP) {
if (skb_is_gso(chunk->skb) && skb_is_gso_sctp(chunk->skb)) {
/* GSO-marked skbs but without frags, handle
* them normally
*/
Expand Down
2 changes: 1 addition & 1 deletion net/sctp/offload.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static struct sk_buff *sctp_gso_segment(struct sk_buff *skb,
struct sk_buff *segs = ERR_PTR(-EINVAL);
struct sctphdr *sh;

if (!(skb_shinfo(skb)->gso_type & SKB_GSO_SCTP))
if (!skb_is_gso_sctp(skb))
goto out;

sh = sctp_hdr(skb);
Expand Down

0 comments on commit 1dd27cd

Please sign in to comment.