Skip to content

Commit df2729c

Browse files
lxindavem330
authored andcommitted
sctp: check for dst and pathmtu update in sctp_packet_config
This patch is to move sctp_transport_dst_check into sctp_packet_config from sctp_packet_transmit and add pathmtu check in sctp_packet_config. With this fix, sctp can update dst or pathmtu before appending chunks, which can void dropping packets in sctp_packet_transmit when dst is obsolete or dst's mtu is changed. This patch is also to improve some other codes in sctp_packet_config. It updates packet max_size with gso_max_size, checks for dst and pathmtu, and appends ecne chunk only when packet is empty and asoc is not NULL. It makes sctp flush work better, as we only need to set up them once for one flush schedule. It's also safe, since asoc is NULL only when the packet is created by sctp_ootb_pkt_new in which it just gets the new dst, no need to do more things for it other than set packet with transport's pathmtu. Signed-off-by: Xin Long <lucien.xin@gmail.com> Acked-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> Acked-by: Neil Horman <nhorman@tuxdriver.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent ac6a372 commit df2729c

2 files changed

Lines changed: 50 additions & 34 deletions

File tree

‎include/net/sctp/sctp.h‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -596,12 +596,23 @@ static inline void sctp_v4_map_v6(union sctp_addr *addr)
596596
*/
597597
static inline struct dst_entry *sctp_transport_dst_check(struct sctp_transport *t)
598598
{
599-
if (t->dst && (!dst_check(t->dst, t->dst_cookie) ||
600-
t->pathmtu != max_t(size_t, SCTP_TRUNC4(dst_mtu(t->dst)),
601-
SCTP_DEFAULT_MINSEGMENT)))
599+
if (t->dst && !dst_check(t->dst, t->dst_cookie))
602600
sctp_transport_dst_release(t);
603601

604602
return t->dst;
605603
}
606604

605+
static inline bool sctp_transport_pmtu_check(struct sctp_transport *t)
606+
{
607+
__u32 pmtu = max_t(size_t, SCTP_TRUNC4(dst_mtu(t->dst)),
608+
SCTP_DEFAULT_MINSEGMENT);
609+
610+
if (t->pathmtu == pmtu)
611+
return true;
612+
613+
t->pathmtu = pmtu;
614+
615+
return false;
616+
}
617+
607618
#endif /* __net_sctp_h__ */

‎net/sctp/output.c‎

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -86,43 +86,53 @@ void sctp_packet_config(struct sctp_packet *packet, __u32 vtag,
8686
{
8787
struct sctp_transport *tp = packet->transport;
8888
struct sctp_association *asoc = tp->asoc;
89+
struct sock *sk;
8990

9091
pr_debug("%s: packet:%p vtag:0x%x\n", __func__, packet, vtag);
91-
9292
packet->vtag = vtag;
9393

94-
if (asoc && tp->dst) {
95-
struct sock *sk = asoc->base.sk;
96-
97-
rcu_read_lock();
98-
if (__sk_dst_get(sk) != tp->dst) {
99-
dst_hold(tp->dst);
100-
sk_setup_caps(sk, tp->dst);
101-
}
102-
103-
if (sk_can_gso(sk)) {
104-
struct net_device *dev = tp->dst->dev;
94+
/* do the following jobs only once for a flush schedule */
95+
if (!sctp_packet_empty(packet))
96+
return;
10597

106-
packet->max_size = dev->gso_max_size;
107-
} else {
108-
packet->max_size = asoc->pathmtu;
109-
}
110-
rcu_read_unlock();
98+
/* set packet max_size with pathmtu */
99+
packet->max_size = tp->pathmtu;
100+
if (!asoc)
101+
return;
111102

112-
} else {
113-
packet->max_size = tp->pathmtu;
103+
/* update dst or transport pathmtu if in need */
104+
sk = asoc->base.sk;
105+
if (!sctp_transport_dst_check(tp)) {
106+
sctp_transport_route(tp, NULL, sctp_sk(sk));
107+
if (asoc->param_flags & SPP_PMTUD_ENABLE)
108+
sctp_assoc_sync_pmtu(sk, asoc);
109+
} else if (!sctp_transport_pmtu_check(tp)) {
110+
if (asoc->param_flags & SPP_PMTUD_ENABLE)
111+
sctp_assoc_sync_pmtu(sk, asoc);
114112
}
115113

116-
if (ecn_capable && sctp_packet_empty(packet)) {
117-
struct sctp_chunk *chunk;
114+
/* If there a is a prepend chunk stick it on the list before
115+
* any other chunks get appended.
116+
*/
117+
if (ecn_capable) {
118+
struct sctp_chunk *chunk = sctp_get_ecne_prepend(asoc);
118119

119-
/* If there a is a prepend chunk stick it on the list before
120-
* any other chunks get appended.
121-
*/
122-
chunk = sctp_get_ecne_prepend(asoc);
123120
if (chunk)
124121
sctp_packet_append_chunk(packet, chunk);
125122
}
123+
124+
if (!tp->dst)
125+
return;
126+
127+
/* set packet max_size with gso_max_size if gso is enabled*/
128+
rcu_read_lock();
129+
if (__sk_dst_get(sk) != tp->dst) {
130+
dst_hold(tp->dst);
131+
sk_setup_caps(sk, tp->dst);
132+
}
133+
packet->max_size = sk_can_gso(sk) ? tp->dst->dev->gso_max_size
134+
: asoc->pathmtu;
135+
rcu_read_unlock();
126136
}
127137

128138
/* Initialize the packet structure. */
@@ -582,12 +592,7 @@ int sctp_packet_transmit(struct sctp_packet *packet, gfp_t gfp)
582592
sh->vtag = htonl(packet->vtag);
583593
sh->checksum = 0;
584594

585-
/* update dst if in need */
586-
if (!sctp_transport_dst_check(tp)) {
587-
sctp_transport_route(tp, NULL, sctp_sk(sk));
588-
if (asoc && asoc->param_flags & SPP_PMTUD_ENABLE)
589-
sctp_assoc_sync_pmtu(sk, asoc);
590-
}
595+
/* drop packet if no dst */
591596
dst = dst_clone(tp->dst);
592597
if (!dst) {
593598
IP_INC_STATS(sock_net(sk), IPSTATS_MIB_OUTNOROUTES);

0 commit comments

Comments
 (0)