53 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
55 #include <linux/types.h>
56 #include <linux/kernel.h>
58 #include <linux/ipv6.h>
59 #include <linux/net.h>
63 #include <linux/slab.h>
67 #include <linux/random.h>
78 const __u8 *raw_addrs,
int addrs_len);
124 err.
cause = cause_code;
142 err.
cause = cause_code;
146 if (skb_tailroom(chunk->
skb) < len)
199 gfp_t gfp,
int vparam_len)
206 int num_types, addrs_len = 0;
234 sp = sctp_sk(asoc->
base.sk);
235 num_types = sp->
pf->supported_addrs(sp, types);
237 chunksize =
sizeof(
init) + addrs_len;
239 chunksize +=
sizeof(ecap_param);
241 if (net->sctp.prsctp_enable)
242 chunksize +=
sizeof(prsctp_param);
249 if (net->sctp.addip_enable) {
256 chunksize +=
sizeof(aiparam);
258 chunksize += vparam_len;
261 if (net->sctp.auth_enable) {
263 chunksize +=
sizeof(asoc->
c.auth_random);
267 if (auth_hmacs->length)
332 sctp_addto_param(retval, num_ext, extensions);
335 if (net->sctp.prsctp_enable)
346 if (net->sctp.auth_enable) {
348 asoc->
c.auth_random);
363 gfp_t gfp,
int unkparam_len)
395 cookie = sctp_pack_cookie(asoc->
ep, asoc, chunk, &cookie_len,
403 sp = sctp_sk(asoc->
base.sk);
404 chunksize =
sizeof(initack) + addrs_len + cookie_len + unkparam_len;
407 if (asoc->
peer.ecn_capable)
408 chunksize +=
sizeof(ecap_param);
410 if (asoc->
peer.prsctp_capable)
411 chunksize +=
sizeof(prsctp_param);
413 if (asoc->
peer.asconf_capable) {
420 chunksize +=
sizeof(aiparam);
422 if (asoc->
peer.auth_capable) {
424 chunksize +=
ntohs(auth_random->length);
427 if (auth_hmacs->length)
466 if (asoc->
peer.ecn_capable)
474 sctp_addto_param(retval, num_ext, extensions);
476 if (asoc->
peer.prsctp_capable)
486 if (asoc->
peer.auth_capable) {
548 cookie = asoc->
peer.cookie;
549 cookie_len = asoc->
peer.cookie_len;
638 const __u32 lowest_tsn,
673 const __u32 lowest_tsn)
715 chunk_len =
sizeof(
dp) + data_len;
743 memset(gabs, 0,
sizeof(gabs));
744 ctsn = sctp_tsnmap_get_ctsn(map);
749 num_dup_tsns = sctp_tsnmap_num_dups(map);
759 +
sizeof(
__u32) * num_dup_tsns;
796 retval->transport = asoc->
peer.last_data_from;
798 retval->subh.sack_hdr =
809 sctp_tsnmap_get_dups(map));
819 if (++aptr->
peer.sack_generation == 0) {
822 trans->sack_generation = 0;
823 aptr->
peer.sack_generation = 1;
837 ctsn = sctp_tsnmap_get_ctsn(&asoc->
peer.tsn_map);
959 payload =
htonl(tsn);
1023 static void *sctp_addto_param(
struct sctp_chunk *chunk,
int len,
1032 memcpy(target, data, len);
1048 const size_t paylen)
1076 static const char error[] =
"The following parameter had invalid length:";
1124 const void *
payload,
const size_t paylen)
1153 static struct sctp_chunk *sctp_make_op_error_space(
1186 static inline struct sctp_chunk *sctp_make_op_error_fixed(
1190 size_t size = asoc ? asoc->
pathmtu : 0;
1195 return sctp_make_op_error_space(asoc, chunk, size);
1202 size_t paylen,
size_t reserve_tail)
1206 retval = sctp_make_op_error_space(asoc, chunk, paylen + reserve_tail);
1213 sctp_addto_param(retval, reserve_tail,
NULL);
1267 retval = kmem_cache_zalloc(sctp_chunk_cachep,
GFP_ATOMIC);
1276 INIT_LIST_HEAD(&retval->
list);
1381 static void sctp_chunk_destroy(
struct sctp_chunk *chunk)
1387 dev_kfree_skb(chunk->
skb);
1413 sctp_chunk_destroy(ch);
1424 int padlen =
WORD_ROUND(chunklen) - chunklen;
1429 memset(padding, 0, padlen);
1430 memcpy(target, data, len);
1443 int len,
const void *data)
1445 if (skb_tailroom(chunk->
skb) >= len)
1493 stream = &chunk->
asoc->ssnmap->out;
1504 ssn = sctp_ssn_next(stream, sid);
1506 ssn = sctp_ssn_peek(stream, sid);
1550 af->
from_skb(&asoc->
c.peer_addr, skb, 1);
1566 const __u8 *raw_addrs,
int addrs_len)
1571 int headersize, bodysize;
1572 unsigned int keylen;
1582 +
ntohs(init_chunk->chunk_hdr->
length) + addrs_len;
1588 bodysize += SCTP_COOKIE_MULTIPLE
1590 *cookie_len = headersize + bodysize;
1606 cookie->
c = asoc->
c;
1608 cookie->
c.raw_addr_list_len = addrs_len;
1611 cookie->
c.prsctp_capable = asoc->
peer.prsctp_capable;
1614 cookie->
c.adaptation_ind = asoc->
peer.adaptation_ind;
1628 if (sctp_sk(ep->
base.sk)->hmac) {
1635 desc.tfm = sctp_sk(ep->
base.sk)->hmac;
1638 if (crypto_hash_setkey(
desc.tfm, key, keylen) ||
1662 int headersize, bodysize, fixed_size;
1665 unsigned int keylen, len;
1679 fixed_size = headersize +
sizeof(
struct sctp_cookie);
1690 if (bodysize % SCTP_COOKIE_MULTIPLE)
1695 bear_cookie = &cookie->
c;
1697 if (!sctp_sk(ep->
base.sk)->hmac)
1704 desc.
tfm = sctp_sk(ep->
base.sk)->hmac;
1708 if (crypto_hash_setkey(desc.
tfm, key, keylen) ||
1709 crypto_hash_digest(&desc, &sg, bodysize, digest)) {
1718 if (crypto_hash_setkey(desc.
tfm, key, keylen) ||
1719 crypto_hash_digest(&desc, &sg, bodysize, digest)) {
1759 skb_get_timestamp(skb, &tv);
1773 *errp = sctp_make_op_error_space(asoc, chunk, len);
1802 memcpy(&retval->
c, bear_cookie,
sizeof(*bear_cookie));
1811 if (list_empty(&retval->
base.bind_addr.address_list)) {
1816 retval->
next_tsn = retval->
c.initial_tsn;
1820 retval->
peer.prsctp_capable = retval->
c.prsctp_capable;
1821 retval->
peer.adaptation_ind = retval->
c.adaptation_ind;
1866 *errp = sctp_make_op_error_space(asoc, chunk, len);
1870 report.
type = paramtype;
1888 *errp = sctp_make_op_error_space(asoc, chunk, 0);
1897 static int sctp_process_inv_paramlength(
const struct sctp_association *asoc,
1933 *errp = sctp_make_op_error_space(asoc, chunk, len);
1948 int have_asconf = 0;
1951 for (i = 0; i < num_ext; i++) {
1952 switch (param.
ext->chunks[i]) {
1968 if (net->sctp.addip_noauth)
1971 if (net->sctp.addip_enable && !have_auth && have_asconf)
1980 struct net *net = sock_net(asoc->
base.sk);
1984 for (i = 0; i < num_ext; i++) {
1985 switch (param.
ext->chunks[i]) {
1987 if (net->sctp.prsctp_enable &&
1988 !asoc->
peer.prsctp_capable)
1989 asoc->
peer.prsctp_capable = 1;
1995 if (net->sctp.auth_enable)
1996 asoc->
peer.auth_capable = 1;
2000 if (net->sctp.addip_enable)
2001 asoc->
peer.asconf_capable = 1;
2055 *errp = sctp_make_op_error_fixed(asoc, chunk);
2095 __u16 n_elt,
id = 0;
2103 switch (param.
p->type) {
2116 if (!sctp_verify_ext_param(net, param))
2121 if (net->sctp.addip_enable)
2127 sctp_process_hn_param(asoc, param, chunk, err_chunk);
2132 if (net->sctp.prsctp_enable)
2137 if (!net->sctp.auth_enable)
2147 sctp_process_inv_paramlength(asoc, param.
p,
2154 if (!net->sctp.auth_enable)
2162 if (260 <
ntohs(param.
p->length)) {
2163 sctp_process_inv_paramlength(asoc, param.
p,
2170 if (!net->sctp.auth_enable)
2180 for (i = 0; i < n_elt; i++) {
2188 sctp_process_inv_paramlength(asoc, param.
p, chunk,
2196 ntohs(param.
p->type), cid);
2197 retval = sctp_process_unk_param(asoc, param, chunk, err_chunk);
2220 return sctp_process_inv_mandatory(asoc, chunk, errp);
2239 return sctp_process_inv_paramlength(asoc, param.
p, chunk, errp);
2251 result = sctp_verify_param(net, asoc, param, cid, chunk, errp);
2276 struct net *net = sock_net(asoc->
base.sk);
2312 if (!sctp_process_param(asoc, param, peer_addr, gfp))
2323 if (asoc->
peer.auth_capable && (!asoc->
peer.peer_random ||
2324 !asoc->
peer.peer_hmacs))
2325 asoc->
peer.auth_capable = 0;
2333 if (!net->sctp.addip_noauth &&
2334 (asoc->
peer.asconf_capable && !asoc->
peer.auth_capable)) {
2338 asoc->
peer.asconf_capable = 0;
2353 asoc->
peer.i.init_tag =
2355 asoc->
peer.i.a_rwnd =
2357 asoc->
peer.i.num_outbound_streams =
2359 asoc->
peer.i.num_inbound_streams =
2361 asoc->
peer.i.initial_tsn =
2367 if (asoc->
c.sinit_num_ostreams >
2369 asoc->
c.sinit_num_ostreams =
2373 if (asoc->
c.sinit_max_instreams >
2375 asoc->
c.sinit_max_instreams =
2380 asoc->
c.peer_vtag = asoc->
peer.i.init_tag;
2383 asoc->
peer.rwnd = asoc->
peer.i.a_rwnd;
2386 cookie = asoc->
peer.cookie;
2389 if (!asoc->
peer.cookie)
2404 asoc->
peer.i.initial_tsn, gfp))
2422 asoc->
c.sinit_num_ostreams, gfp);
2441 asoc->
peer.addip_serial = asoc->
peer.i.initial_tsn - 1;
2473 struct net *net = sock_net(asoc->
base.sk);
2488 switch (param.
p->type) {
2508 if (!net->sctp.cookie_preserve_enable)
2511 stale =
ntohl(param.
life->lifespan_increment);
2517 asoc->
cookie_life.tv_usec += (stale % 1000) * 1000;
2528 asoc->
peer.ipv4_address = 0;
2529 asoc->
peer.ipv6_address = 0;
2535 asoc->
peer.ipv6_address = 1;
2536 else if (peer_addr->
sa.sa_family ==
AF_INET)
2537 asoc->
peer.ipv4_address = 1;
2542 sat /=
sizeof(
__u16);
2544 for (i = 0; i <
sat; ++
i) {
2545 switch (param.
sat->types[i]) {
2547 asoc->
peer.ipv4_address = 1;
2552 asoc->
peer.ipv6_address = 1;
2556 asoc->
peer.hostname_address = 1;
2566 asoc->
peer.cookie_len =
2580 asoc->
peer.ecn_capable = 1;
2584 asoc->
peer.adaptation_ind =
ntohl(param.
aind->adaptation_ind);
2588 if (!net->sctp.addip_enable)
2611 sctp_process_ext_param(asoc, param);
2615 if (net->sctp.prsctp_enable) {
2616 asoc->
peer.prsctp_capable = 1;
2623 if (!net->sctp.auth_enable)
2628 ntohs(param.
p->length), gfp);
2629 if (!asoc->
peer.peer_random) {
2636 if (!net->sctp.auth_enable)
2641 ntohs(param.
p->length), gfp);
2642 if (!asoc->
peer.peer_hmacs) {
2652 if (!net->sctp.auth_enable)
2656 ntohs(param.
p->length), gfp);
2657 if (!asoc->
peer.peer_chunks)
2668 ntohs(param.
p->type), asoc);
2727 int length =
sizeof(asconf) + vparam_len;
2788 int paramlen =
sizeof(
param);
2789 int addr_param_len = 0;
2796 for (i = 0; i < addrcnt; i++) {
2801 totallen += paramlen;
2802 totallen += addr_param_len;
2807 totallen += paramlen;
2808 totallen += addr_param_len;
2810 SCTP_DEBUG_PRINTK(
"mkasconf_update_ip: picked same-scope del_pending addr, totallen for all addresses is %d\n", totallen);
2815 retval = sctp_make_asconf(asoc, laddr, totallen);
2821 for (i = 0; i < addrcnt; i++) {
2867 int len =
sizeof(
param);
2878 retval = sctp_make_asconf(asoc, addr, len);
2916 int length =
sizeof(asconf) + vparam_len;
2932 static void sctp_add_asconf_response(
struct sctp_chunk *chunk,
__be32 crr_id,
2937 int asconf_param_len = 0;
2938 int err_param_len = 0;
2945 err_param_len =
sizeof(err_param);
2956 ack_param.
crr_id = crr_id;
2964 err_param.
length =
htons(err_param_len + asconf_param_len);
2989 switch (addr_param->
p.type) {
2991 if (!asoc->
peer.ipv6_address)
2995 if (!asoc->
peer.ipv4_address)
3047 if (asoc->
peer.transport_count == 1)
3102 length =
ntohs(param.
p->length);
3105 if (param.
v > chunk_end - length ||
3109 switch (param.
p->type) {
3132 if (param.
v != chunk_end)
3153 int all_param_pass = 1;
3167 length =
ntohs(addr_param->
p.length);
3168 asconf_param = (
void *)addr_param + length;
3176 asconf_ack = sctp_make_asconf_ack(asoc, serial, chunk_len * 4);
3181 while (chunk_len > 0) {
3182 err_code = sctp_process_asconf_param(asoc, asconf,
3194 if (!all_param_pass)
3195 sctp_add_asconf_response(asconf_ack,
3196 asconf_param->
crr_id, err_code,
3209 asconf_param = (
void *)asconf_param + length;
3214 asoc->
peer.addip_serial++;
3315 asconf_ack_len -=
length;
3317 while (asconf_ack_len > 0) {
3318 if (asconf_ack_param->
crr_id == asconf_param->
crr_id) {
3324 err_param = (
void *)asconf_ack_param + length;
3325 asconf_ack_len -=
length;
3326 if (asconf_ack_len > 0)
3327 return err_param->
cause;
3337 asconf_ack_param = (
void *)asconf_ack_param + length;
3338 asconf_ack_len -=
length;
3352 int asconf_len = asconf->
skb->len;
3353 int all_param_pass = 0;
3368 length =
ntohs(addr_param->
p.length);
3369 asconf_param = (
void *)addr_param + length;
3381 while (asconf_len > 0) {
3385 err_code = sctp_get_asconf_response(asconf_ack,
3394 sctp_asconf_param_success(asoc, asconf_param);
3405 asoc->
peer.addip_disabled_mask |=
3420 asconf_param = (
void *)asconf_param + length;
3439 __u32 new_cum_tsn,
size_t nstreams,
3448 hint = (nstreams + 1) *
sizeof(
__u32);
3459 for (i = 0; i < nstreams; i++) {