Skip to content

Commit 8a9c58d

Browse files
lxindavem330
authored andcommitted
sctp: add support for dscp and flowlabel per transport
Like some other per transport params, flowlabel and dscp are added in transport, asoc and sctp_sock. By default, transport sets its value from asoc's, and asoc does it from sctp_sock. flowlabel only works for ipv6 transport. Other than that they need to be passed down in sctp_xmit, flow4/6 also needs to set them before looking up route in get_dst. Note that it uses '& 0x100000' to check if flowlabel is set and '& 0x1' (tos 1st bit is unused) to check if dscp is set by users, so that they could be set to 0 by sockopt in next patch. Signed-off-by: Xin Long <lucien.xin@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 69b9e1e commit 8a9c58d

5 files changed

Lines changed: 44 additions & 6 deletions

File tree

‎include/linux/sctp.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,4 +801,11 @@ struct sctp_strreset_resptsn {
801801
__be32 receivers_next_tsn;
802802
};
803803

804+
enum {
805+
SCTP_DSCP_SET_MASK = 0x1,
806+
SCTP_DSCP_VAL_MASK = 0xfc,
807+
SCTP_FLOWLABEL_SET_MASK = 0x100000,
808+
SCTP_FLOWLABEL_VAL_MASK = 0xfffff
809+
};
810+
804811
#endif /* __LINUX_SCTP_H__ */

‎include/net/sctp/structs.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ struct sctp_sock {
193193
/* This is the max_retrans value for new associations. */
194194
__u16 pathmaxrxt;
195195

196+
__u32 flowlabel;
197+
__u8 dscp;
198+
196199
/* The initial Path MTU to use for new associations. */
197200
__u32 pathmtu;
198201

@@ -895,6 +898,9 @@ struct sctp_transport {
895898
*/
896899
__u16 pathmaxrxt;
897900

901+
__u32 flowlabel;
902+
__u8 dscp;
903+
898904
/* This is the partially failed retrans value for the transport
899905
* and will be initialized from the assocs value. This can be changed
900906
* using the SCTP_PEER_ADDR_THLDS socket option
@@ -1772,6 +1778,9 @@ struct sctp_association {
17721778
*/
17731779
__u16 pathmaxrxt;
17741780

1781+
__u32 flowlabel;
1782+
__u8 dscp;
1783+
17751784
/* Flag that path mtu update is pending */
17761785
__u8 pmtu_pending;
17771786

‎net/sctp/associola.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ static struct sctp_association *sctp_association_init(
115115
/* Initialize path max retrans value. */
116116
asoc->pathmaxrxt = sp->pathmaxrxt;
117117

118+
asoc->flowlabel = sp->flowlabel;
119+
asoc->dscp = sp->dscp;
120+
118121
/* Initialize default path MTU. */
119122
asoc->pathmtu = sp->pathmtu;
120123

@@ -647,6 +650,10 @@ struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc,
647650
peer->sackdelay = asoc->sackdelay;
648651
peer->sackfreq = asoc->sackfreq;
649652

653+
if (addr->sa.sa_family == AF_INET6)
654+
peer->flowlabel = asoc->flowlabel;
655+
peer->dscp = asoc->dscp;
656+
650657
/* Enable/disable heartbeat, SACK delay, and path MTU discovery
651658
* based on association setting.
652659
*/

‎net/sctp/ipv6.c‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,17 @@ static int sctp_v6_xmit(struct sk_buff *skb, struct sctp_transport *transport)
209209
struct sock *sk = skb->sk;
210210
struct ipv6_pinfo *np = inet6_sk(sk);
211211
struct flowi6 *fl6 = &transport->fl.u.ip6;
212+
__u8 tclass = np->tclass;
212213
int res;
213214

214215
pr_debug("%s: skb:%p, len:%d, src:%pI6 dst:%pI6\n", __func__, skb,
215216
skb->len, &fl6->saddr, &fl6->daddr);
216217

217-
IP6_ECN_flow_xmit(sk, fl6->flowlabel);
218+
if (transport->dscp & SCTP_DSCP_SET_MASK)
219+
tclass = transport->dscp & SCTP_DSCP_VAL_MASK;
220+
221+
if (INET_ECN_is_capable(tclass))
222+
IP6_ECN_flow_xmit(sk, fl6->flowlabel);
218223

219224
if (!(transport->param_flags & SPP_PMTUD_ENABLE))
220225
skb->ignore_df = 1;
@@ -223,7 +228,7 @@ static int sctp_v6_xmit(struct sk_buff *skb, struct sctp_transport *transport)
223228

224229
rcu_read_lock();
225230
res = ip6_xmit(sk, skb, fl6, sk->sk_mark, rcu_dereference(np->opt),
226-
np->tclass);
231+
tclass);
227232
rcu_read_unlock();
228233
return res;
229234
}
@@ -254,6 +259,8 @@ static void sctp_v6_get_dst(struct sctp_transport *t, union sctp_addr *saddr,
254259
fl6->flowi6_oif = daddr->v6.sin6_scope_id;
255260
else if (asoc)
256261
fl6->flowi6_oif = asoc->base.sk->sk_bound_dev_if;
262+
if (t->flowlabel & SCTP_FLOWLABEL_SET_MASK)
263+
fl6->flowlabel = htonl(t->flowlabel & SCTP_FLOWLABEL_VAL_MASK);
257264

258265
pr_debug("%s: dst=%pI6 ", __func__, &fl6->daddr);
259266

‎net/sctp/protocol.c‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,13 +426,16 @@ static void sctp_v4_get_dst(struct sctp_transport *t, union sctp_addr *saddr,
426426
struct dst_entry *dst = NULL;
427427
union sctp_addr *daddr = &t->ipaddr;
428428
union sctp_addr dst_saddr;
429+
__u8 tos = inet_sk(sk)->tos;
429430

431+
if (t->dscp & SCTP_DSCP_SET_MASK)
432+
tos = t->dscp & SCTP_DSCP_VAL_MASK;
430433
memset(fl4, 0x0, sizeof(struct flowi4));
431434
fl4->daddr = daddr->v4.sin_addr.s_addr;
432435
fl4->fl4_dport = daddr->v4.sin_port;
433436
fl4->flowi4_proto = IPPROTO_SCTP;
434437
if (asoc) {
435-
fl4->flowi4_tos = RT_CONN_FLAGS(asoc->base.sk);
438+
fl4->flowi4_tos = RT_CONN_FLAGS_TOS(asoc->base.sk, tos);
436439
fl4->flowi4_oif = asoc->base.sk->sk_bound_dev_if;
437440
fl4->fl4_sport = htons(asoc->base.bind_addr.port);
438441
}
@@ -495,7 +498,7 @@ static void sctp_v4_get_dst(struct sctp_transport *t, union sctp_addr *saddr,
495498
fl4->fl4_sport = laddr->a.v4.sin_port;
496499
flowi4_update_output(fl4,
497500
asoc->base.sk->sk_bound_dev_if,
498-
RT_CONN_FLAGS(asoc->base.sk),
501+
RT_CONN_FLAGS_TOS(asoc->base.sk, tos),
499502
daddr->v4.sin_addr.s_addr,
500503
laddr->a.v4.sin_addr.s_addr);
501504

@@ -971,16 +974,21 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
971974
struct sctp_transport *transport)
972975
{
973976
struct inet_sock *inet = inet_sk(skb->sk);
977+
__u8 dscp = inet->tos;
974978

975979
pr_debug("%s: skb:%p, len:%d, src:%pI4, dst:%pI4\n", __func__, skb,
976-
skb->len, &transport->fl.u.ip4.saddr, &transport->fl.u.ip4.daddr);
980+
skb->len, &transport->fl.u.ip4.saddr,
981+
&transport->fl.u.ip4.daddr);
982+
983+
if (transport->dscp & SCTP_DSCP_SET_MASK)
984+
dscp = transport->dscp & SCTP_DSCP_VAL_MASK;
977985

978986
inet->pmtudisc = transport->param_flags & SPP_PMTUD_ENABLE ?
979987
IP_PMTUDISC_DO : IP_PMTUDISC_DONT;
980988

981989
SCTP_INC_STATS(sock_net(&inet->sk), SCTP_MIB_OUTSCTPPACKS);
982990

983-
return ip_queue_xmit(&inet->sk, skb, &transport->fl);
991+
return __ip_queue_xmit(&inet->sk, skb, &transport->fl, dscp);
984992
}
985993

986994
static struct sctp_af sctp_af_inet;

0 commit comments

Comments
 (0)