Skip to content

Commit 398aae2

Browse files
committed
Merge branch 'sctp-gso-frags-from-chunk'
Marcelo Ricardo Leitner says: ==================== sctp: allow GSO frags to access the chunk too Patchset is named after the most important fix in it. First two patches are preparing the grounds for the 3rd patch. After the 3rd, they are not strictly logically related to the patchset, but I kept them together as they depend on each other. More details on patch changelogs. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents ce3a380 + 2d47fd1 commit 398aae2

10 files changed

Lines changed: 68 additions & 51 deletions

File tree

‎include/net/sctp/structs.h‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#include <linux/workqueue.h> /* We need tq_struct. */
6060
#include <linux/sctp.h> /* We need sctp* header structs. */
6161
#include <net/sctp/auth.h> /* We need auth specific structs */
62+
#include <net/ip.h> /* For inet_skb_parm */
6263

6364
/* A convenience structure for handling sockaddr structures.
6465
* We should wean ourselves off this.
@@ -1092,6 +1093,28 @@ static inline void sctp_outq_cork(struct sctp_outq *q)
10921093
q->cork = 1;
10931094
}
10941095

1096+
/* SCTP skb control block.
1097+
* sctp_input_cb is currently used on rx and sock rx queue
1098+
*/
1099+
struct sctp_input_cb {
1100+
union {
1101+
struct inet_skb_parm h4;
1102+
#if IS_ENABLED(CONFIG_IPV6)
1103+
struct inet6_skb_parm h6;
1104+
#endif
1105+
} header;
1106+
struct sctp_chunk *chunk;
1107+
struct sctp_af *af;
1108+
};
1109+
#define SCTP_INPUT_CB(__skb) ((struct sctp_input_cb *)&((__skb)->cb[0]))
1110+
1111+
static inline const struct sk_buff *sctp_gso_headskb(const struct sk_buff *skb)
1112+
{
1113+
const struct sctp_chunk *chunk = SCTP_INPUT_CB(skb)->chunk;
1114+
1115+
return chunk->head_skb ? : skb;
1116+
}
1117+
10951118
/* These bind address data fields common between endpoints and associations */
10961119
struct sctp_bind_addr {
10971120

‎include/net/sctp/ulpevent.h‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@
4848
*/
4949
struct sctp_ulpevent {
5050
struct sctp_association *asoc;
51-
__u16 stream;
52-
__u16 ssn;
53-
__u16 flags;
51+
struct sctp_chunk *chunk;
52+
unsigned int rmem_len;
5453
__u32 ppid;
5554
__u32 tsn;
5655
__u32 cumtsn;
57-
int msg_flags;
58-
int iif;
59-
unsigned int rmem_len;
56+
__u16 stream;
57+
__u16 ssn;
58+
__u16 flags;
59+
__u16 msg_flags;
6060
};
6161

6262
/* Retrieve the skb this event sits inside of. */

‎net/sctp/input.c‎

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,6 @@ static inline int sctp_rcv_checksum(struct net *net, struct sk_buff *skb)
9090
return 0;
9191
}
9292

93-
struct sctp_input_cb {
94-
union {
95-
struct inet_skb_parm h4;
96-
#if IS_ENABLED(CONFIG_IPV6)
97-
struct inet6_skb_parm h6;
98-
#endif
99-
} header;
100-
struct sctp_chunk *chunk;
101-
};
102-
#define SCTP_INPUT_CB(__skb) ((struct sctp_input_cb *)&((__skb)->cb[0]))
103-
10493
/*
10594
* This is the routine which IP calls when receiving an SCTP packet.
10695
*/
@@ -151,6 +140,7 @@ int sctp_rcv(struct sk_buff *skb)
151140
af = sctp_get_af_specific(family);
152141
if (unlikely(!af))
153142
goto discard_it;
143+
SCTP_INPUT_CB(skb)->af = af;
154144

155145
/* Initialize local addresses for lookups. */
156146
af->from_skb(&src, skb, 1);

‎net/sctp/inqueue.c‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,14 @@ struct sctp_chunk *sctp_inq_pop(struct sctp_inq *queue)
217217
chunk->auth = 0;
218218
chunk->has_asconf = 0;
219219
chunk->end_of_packet = 0;
220-
chunk->ecn_ce_done = 0;
220+
if (chunk->head_skb) {
221+
struct sctp_input_cb
222+
*cb = SCTP_INPUT_CB(chunk->skb),
223+
*head_cb = SCTP_INPUT_CB(chunk->head_skb);
224+
225+
cb->chunk = head_cb->chunk;
226+
cb->af = head_cb->af;
227+
}
221228
}
222229

223230
chunk->chunk_hdr = ch;

‎net/sctp/ipv6.c‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ static void sctp_v6_from_skb(union sctp_addr *addr, struct sk_buff *skb,
420420
addr->v6.sin6_flowinfo = 0; /* FIXME */
421421
addr->v6.sin6_scope_id = ((struct inet6_skb_parm *)skb->cb)->iif;
422422

423+
/* Always called on head skb, so this is safe */
423424
sh = sctp_hdr(skb);
424425
if (is_saddr) {
425426
*port = sh->source;
@@ -710,8 +711,7 @@ static int sctp_v6_addr_to_user(struct sctp_sock *sp, union sctp_addr *addr)
710711
/* Where did this skb come from? */
711712
static int sctp_v6_skb_iif(const struct sk_buff *skb)
712713
{
713-
struct inet6_skb_parm *opt = (struct inet6_skb_parm *) skb->cb;
714-
return opt->iif;
714+
return IP6CB(skb)->iif;
715715
}
716716

717717
/* Was this packet marked by Explicit Congestion Notification? */
@@ -780,15 +780,14 @@ static void sctp_inet6_skb_msgname(struct sk_buff *skb, char *msgname,
780780
if (ip_hdr(skb)->version == 4) {
781781
addr->v4.sin_family = AF_INET;
782782
addr->v4.sin_port = sh->source;
783-
addr->v4.sin_addr.s_addr = ip_hdr(skb)->saddr;
783+
addr->v4.sin_addr.s_addr = ip_hdr(skb)->saddr;
784784
} else {
785785
addr->v6.sin6_family = AF_INET6;
786786
addr->v6.sin6_flowinfo = 0;
787787
addr->v6.sin6_port = sh->source;
788788
addr->v6.sin6_addr = ipv6_hdr(skb)->saddr;
789789
if (ipv6_addr_type(&addr->v6.sin6_addr) & IPV6_ADDR_LINKLOCAL) {
790-
struct sctp_ulpevent *ev = sctp_skb2event(skb);
791-
addr->v6.sin6_scope_id = ev->iif;
790+
addr->v6.sin6_scope_id = sctp_v6_skb_iif(skb);
792791
}
793792
}
794793

‎net/sctp/protocol.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ static void sctp_v4_from_skb(union sctp_addr *addr, struct sk_buff *skb,
240240
port = &addr->v4.sin_port;
241241
addr->v4.sin_family = AF_INET;
242242

243+
/* Always called on head skb, so this is safe */
243244
sh = sctp_hdr(skb);
244245
if (is_saddr) {
245246
*port = sh->source;

‎net/sctp/sm_make_chunk.c‎

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,9 @@ static void sctp_control_set_owner_w(struct sctp_chunk *chunk)
108108
/* What was the inbound interface for this chunk? */
109109
int sctp_chunk_iif(const struct sctp_chunk *chunk)
110110
{
111-
struct sctp_af *af;
112-
int iif = 0;
113-
114-
af = sctp_get_af_specific(ipver2af(ip_hdr(chunk->skb)->version));
115-
if (af)
116-
iif = af->skb_iif(chunk->skb);
111+
struct sk_buff *skb = chunk->skb;
117112

118-
return iif;
113+
return SCTP_INPUT_CB(skb)->af->skb_iif(skb);
119114
}
120115

121116
/* RFC 2960 3.3.2 Initiation (INIT) (1)
@@ -1600,7 +1595,6 @@ struct sctp_association *sctp_make_temp_asoc(const struct sctp_endpoint *ep,
16001595
struct sctp_association *asoc;
16011596
struct sk_buff *skb;
16021597
sctp_scope_t scope;
1603-
struct sctp_af *af;
16041598

16051599
/* Create the bare association. */
16061600
scope = sctp_scope(sctp_source(chunk));
@@ -1610,16 +1604,10 @@ struct sctp_association *sctp_make_temp_asoc(const struct sctp_endpoint *ep,
16101604
asoc->temp = 1;
16111605
skb = chunk->skb;
16121606
/* Create an entry for the source address of the packet. */
1613-
af = sctp_get_af_specific(ipver2af(ip_hdr(skb)->version));
1614-
if (unlikely(!af))
1615-
goto fail;
1616-
af->from_skb(&asoc->c.peer_addr, skb, 1);
1607+
SCTP_INPUT_CB(skb)->af->from_skb(&asoc->c.peer_addr, skb, 1);
1608+
16171609
nodata:
16181610
return asoc;
1619-
1620-
fail:
1621-
sctp_association_free(asoc);
1622-
return NULL;
16231611
}
16241612

16251613
/* Build a cookie representing asoc.

‎net/sctp/sm_statefuns.c‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6118,14 +6118,11 @@ static int sctp_eat_data(const struct sctp_association *asoc,
61186118
* chunk later.
61196119
*/
61206120

6121-
if (!chunk->ecn_ce_done) {
6122-
struct sctp_af *af;
6121+
if (asoc->peer.ecn_capable && !chunk->ecn_ce_done) {
6122+
struct sctp_af *af = SCTP_INPUT_CB(chunk->skb)->af;
61236123
chunk->ecn_ce_done = 1;
61246124

6125-
af = sctp_get_af_specific(
6126-
ipver2af(ip_hdr(chunk->skb)->version));
6127-
6128-
if (af && af->is_ce(chunk->skb) && asoc->peer.ecn_capable) {
6125+
if (af->is_ce(sctp_gso_headskb(chunk->skb))) {
61296126
/* Do real work as sideffect. */
61306127
sctp_add_cmd_sf(commands, SCTP_CMD_ECN_CE,
61316128
SCTP_U32(tsn));

‎net/sctp/socket.c‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2066,7 +2066,7 @@ static int sctp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
20662066
{
20672067
struct sctp_ulpevent *event = NULL;
20682068
struct sctp_sock *sp = sctp_sk(sk);
2069-
struct sk_buff *skb;
2069+
struct sk_buff *skb, *head_skb;
20702070
int copied;
20712071
int err = 0;
20722072
int skb_len;
@@ -2102,12 +2102,16 @@ static int sctp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
21022102
if (err)
21032103
goto out_free;
21042104

2105-
sock_recv_ts_and_drops(msg, sk, skb);
2105+
if (event->chunk && event->chunk->head_skb)
2106+
head_skb = event->chunk->head_skb;
2107+
else
2108+
head_skb = skb;
2109+
sock_recv_ts_and_drops(msg, sk, head_skb);
21062110
if (sctp_ulpevent_is_notification(event)) {
21072111
msg->msg_flags |= MSG_NOTIFICATION;
21082112
sp->pf->event_msgname(event, msg->msg_name, addr_len);
21092113
} else {
2110-
sp->pf->skb_msgname(skb, msg->msg_name, addr_len);
2114+
sp->pf->skb_msgname(head_skb, msg->msg_name, addr_len);
21112115
}
21122116

21132117
/* Check if we allow SCTP_NXTINFO. */

‎net/sctp/ulpevent.c‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static void sctp_ulpevent_release_frag_data(struct sctp_ulpevent *event);
5151

5252
/* Initialize an ULP event from an given skb. */
5353
static void sctp_ulpevent_init(struct sctp_ulpevent *event,
54-
int msg_flags,
54+
__u16 msg_flags,
5555
unsigned int len)
5656
{
5757
memset(event, 0, sizeof(struct sctp_ulpevent));
@@ -60,7 +60,7 @@ static void sctp_ulpevent_init(struct sctp_ulpevent *event,
6060
}
6161

6262
/* Create a new sctp_ulpevent. */
63-
static struct sctp_ulpevent *sctp_ulpevent_new(int size, int msg_flags,
63+
static struct sctp_ulpevent *sctp_ulpevent_new(int size, __u16 msg_flags,
6464
gfp_t gfp)
6565
{
6666
struct sctp_ulpevent *event;
@@ -701,6 +701,12 @@ struct sctp_ulpevent *sctp_ulpevent_make_rcvmsg(struct sctp_association *asoc,
701701

702702
sctp_ulpevent_receive_data(event, asoc);
703703

704+
/* And hold the chunk as we need it for getting the IP headers
705+
* later in recvmsg
706+
*/
707+
sctp_chunk_hold(chunk);
708+
event->chunk = chunk;
709+
704710
event->stream = ntohs(chunk->subh.data_hdr->stream);
705711
event->ssn = ntohs(chunk->subh.data_hdr->ssn);
706712
event->ppid = chunk->subh.data_hdr->ppid;
@@ -710,11 +716,11 @@ struct sctp_ulpevent *sctp_ulpevent_make_rcvmsg(struct sctp_association *asoc,
710716
}
711717
event->tsn = ntohl(chunk->subh.data_hdr->tsn);
712718
event->msg_flags |= chunk->chunk_hdr->flags;
713-
event->iif = sctp_chunk_iif(chunk);
714719

715720
return event;
716721

717722
fail_mark:
723+
sctp_chunk_put(chunk);
718724
kfree_skb(skb);
719725
fail:
720726
return NULL;
@@ -1007,6 +1013,7 @@ static void sctp_ulpevent_release_data(struct sctp_ulpevent *event)
10071013

10081014
done:
10091015
sctp_assoc_rwnd_increase(event->asoc, len);
1016+
sctp_chunk_put(event->chunk);
10101017
sctp_ulpevent_release_owner(event);
10111018
}
10121019

@@ -1029,6 +1036,7 @@ static void sctp_ulpevent_release_frag_data(struct sctp_ulpevent *event)
10291036
}
10301037

10311038
done:
1039+
sctp_chunk_put(event->chunk);
10321040
sctp_ulpevent_release_owner(event);
10331041
}
10341042

0 commit comments

Comments
 (0)