aboutsummaryrefslogtreecommitdiffstats
path: root/net/sctp/socket.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/sctp/socket.c')
-rw-r--r--net/sctp/socket.c383
1 files changed, 267 insertions, 116 deletions
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 0dbcde6758ea..79bece16aede 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -116,7 +116,7 @@ static int sctp_memory_pressure;
116static atomic_t sctp_memory_allocated; 116static atomic_t sctp_memory_allocated;
117static atomic_t sctp_sockets_allocated; 117static atomic_t sctp_sockets_allocated;
118 118
119static void sctp_enter_memory_pressure(void) 119static void sctp_enter_memory_pressure(struct sock *sk)
120{ 120{
121 sctp_memory_pressure = 1; 121 sctp_memory_pressure = 1;
122} 122}
@@ -308,9 +308,16 @@ static struct sctp_af *sctp_sockaddr_af(struct sctp_sock *opt,
308 if (len < sizeof (struct sockaddr)) 308 if (len < sizeof (struct sockaddr))
309 return NULL; 309 return NULL;
310 310
311 /* Does this PF support this AF? */ 311 /* V4 mapped address are really of AF_INET family */
312 if (!opt->pf->af_supported(addr->sa.sa_family, opt)) 312 if (addr->sa.sa_family == AF_INET6 &&
313 return NULL; 313 ipv6_addr_v4mapped(&addr->v6.sin6_addr)) {
314 if (!opt->pf->af_supported(AF_INET, opt))
315 return NULL;
316 } else {
317 /* Does this PF support this AF? */
318 if (!opt->pf->af_supported(addr->sa.sa_family, opt))
319 return NULL;
320 }
314 321
315 /* If we get this far, af is valid. */ 322 /* If we get this far, af is valid. */
316 af = sctp_get_af_specific(addr->sa.sa_family); 323 af = sctp_get_af_specific(addr->sa.sa_family);
@@ -370,18 +377,19 @@ SCTP_STATIC int sctp_do_bind(struct sock *sk, union sctp_addr *addr, int len)
370 if (snum && snum < PROT_SOCK && !capable(CAP_NET_BIND_SERVICE)) 377 if (snum && snum < PROT_SOCK && !capable(CAP_NET_BIND_SERVICE))
371 return -EACCES; 378 return -EACCES;
372 379
380 /* See if the address matches any of the addresses we may have
381 * already bound before checking against other endpoints.
382 */
383 if (sctp_bind_addr_match(bp, addr, sp))
384 return -EINVAL;
385
373 /* Make sure we are allowed to bind here. 386 /* Make sure we are allowed to bind here.
374 * The function sctp_get_port_local() does duplicate address 387 * The function sctp_get_port_local() does duplicate address
375 * detection. 388 * detection.
376 */ 389 */
377 addr->v4.sin_port = htons(snum); 390 addr->v4.sin_port = htons(snum);
378 if ((ret = sctp_get_port_local(sk, addr))) { 391 if ((ret = sctp_get_port_local(sk, addr))) {
379 if (ret == (long) sk) { 392 return -EADDRINUSE;
380 /* This endpoint has a conflicting address. */
381 return -EINVAL;
382 } else {
383 return -EADDRINUSE;
384 }
385 } 393 }
386 394
387 /* Refresh ephemeral port. */ 395 /* Refresh ephemeral port. */
@@ -956,7 +964,8 @@ out:
956 */ 964 */
957static int __sctp_connect(struct sock* sk, 965static int __sctp_connect(struct sock* sk,
958 struct sockaddr *kaddrs, 966 struct sockaddr *kaddrs,
959 int addrs_size) 967 int addrs_size,
968 sctp_assoc_t *assoc_id)
960{ 969{
961 struct sctp_sock *sp; 970 struct sctp_sock *sp;
962 struct sctp_endpoint *ep; 971 struct sctp_endpoint *ep;
@@ -1111,6 +1120,8 @@ static int __sctp_connect(struct sock* sk,
1111 timeo = sock_sndtimeo(sk, f_flags & O_NONBLOCK); 1120 timeo = sock_sndtimeo(sk, f_flags & O_NONBLOCK);
1112 1121
1113 err = sctp_wait_for_connect(asoc, &timeo); 1122 err = sctp_wait_for_connect(asoc, &timeo);
1123 if (!err && assoc_id)
1124 *assoc_id = asoc->assoc_id;
1114 1125
1115 /* Don't free association on exit. */ 1126 /* Don't free association on exit. */
1116 asoc = NULL; 1127 asoc = NULL;
@@ -1128,7 +1139,8 @@ out_free:
1128/* Helper for tunneling sctp_connectx() requests through sctp_setsockopt() 1139/* Helper for tunneling sctp_connectx() requests through sctp_setsockopt()
1129 * 1140 *
1130 * API 8.9 1141 * API 8.9
1131 * int sctp_connectx(int sd, struct sockaddr *addrs, int addrcnt); 1142 * int sctp_connectx(int sd, struct sockaddr *addrs, int addrcnt,
1143 * sctp_assoc_t *asoc);
1132 * 1144 *
1133 * If sd is an IPv4 socket, the addresses passed must be IPv4 addresses. 1145 * If sd is an IPv4 socket, the addresses passed must be IPv4 addresses.
1134 * If the sd is an IPv6 socket, the addresses passed can either be IPv4 1146 * If the sd is an IPv6 socket, the addresses passed can either be IPv4
@@ -1144,8 +1156,10 @@ out_free:
1144 * representation is termed a "packed array" of addresses). The caller 1156 * representation is termed a "packed array" of addresses). The caller
1145 * specifies the number of addresses in the array with addrcnt. 1157 * specifies the number of addresses in the array with addrcnt.
1146 * 1158 *
1147 * On success, sctp_connectx() returns 0. On failure, sctp_connectx() returns 1159 * On success, sctp_connectx() returns 0. It also sets the assoc_id to
1148 * -1, and sets errno to the appropriate error code. 1160 * the association id of the new association. On failure, sctp_connectx()
1161 * returns -1, and sets errno to the appropriate error code. The assoc_id
1162 * is not touched by the kernel.
1149 * 1163 *
1150 * For SCTP, the port given in each socket address must be the same, or 1164 * For SCTP, the port given in each socket address must be the same, or
1151 * sctp_connectx() will fail, setting errno to EINVAL. 1165 * sctp_connectx() will fail, setting errno to EINVAL.
@@ -1182,11 +1196,12 @@ out_free:
1182 * addrs The pointer to the addresses in user land 1196 * addrs The pointer to the addresses in user land
1183 * addrssize Size of the addrs buffer 1197 * addrssize Size of the addrs buffer
1184 * 1198 *
1185 * Returns 0 if ok, <0 errno code on error. 1199 * Returns >=0 if ok, <0 errno code on error.
1186 */ 1200 */
1187SCTP_STATIC int sctp_setsockopt_connectx(struct sock* sk, 1201SCTP_STATIC int __sctp_setsockopt_connectx(struct sock* sk,
1188 struct sockaddr __user *addrs, 1202 struct sockaddr __user *addrs,
1189 int addrs_size) 1203 int addrs_size,
1204 sctp_assoc_t *assoc_id)
1190{ 1205{
1191 int err = 0; 1206 int err = 0;
1192 struct sockaddr *kaddrs; 1207 struct sockaddr *kaddrs;
@@ -1209,13 +1224,46 @@ SCTP_STATIC int sctp_setsockopt_connectx(struct sock* sk,
1209 if (__copy_from_user(kaddrs, addrs, addrs_size)) { 1224 if (__copy_from_user(kaddrs, addrs, addrs_size)) {
1210 err = -EFAULT; 1225 err = -EFAULT;
1211 } else { 1226 } else {
1212 err = __sctp_connect(sk, kaddrs, addrs_size); 1227 err = __sctp_connect(sk, kaddrs, addrs_size, assoc_id);
1213 } 1228 }
1214 1229
1215 kfree(kaddrs); 1230 kfree(kaddrs);
1231
1216 return err; 1232 return err;
1217} 1233}
1218 1234
1235/*
1236 * This is an older interface. It's kept for backward compatibility
1237 * to the option that doesn't provide association id.
1238 */
1239SCTP_STATIC int sctp_setsockopt_connectx_old(struct sock* sk,
1240 struct sockaddr __user *addrs,
1241 int addrs_size)
1242{
1243 return __sctp_setsockopt_connectx(sk, addrs, addrs_size, NULL);
1244}
1245
1246/*
1247 * New interface for the API. The since the API is done with a socket
1248 * option, to make it simple we feed back the association id is as a return
1249 * indication to the call. Error is always negative and association id is
1250 * always positive.
1251 */
1252SCTP_STATIC int sctp_setsockopt_connectx(struct sock* sk,
1253 struct sockaddr __user *addrs,
1254 int addrs_size)
1255{
1256 sctp_assoc_t assoc_id = 0;
1257 int err = 0;
1258
1259 err = __sctp_setsockopt_connectx(sk, addrs, addrs_size, &assoc_id);
1260
1261 if (err)
1262 return err;
1263 else
1264 return assoc_id;
1265}
1266
1219/* API 3.1.4 close() - UDP Style Syntax 1267/* API 3.1.4 close() - UDP Style Syntax
1220 * Applications use close() to perform graceful shutdown (as described in 1268 * Applications use close() to perform graceful shutdown (as described in
1221 * Section 10.1 of [SCTP]) on ALL the associations currently represented 1269 * Section 10.1 of [SCTP]) on ALL the associations currently represented
@@ -2305,74 +2353,98 @@ static int sctp_setsockopt_peer_addr_params(struct sock *sk,
2305 return 0; 2353 return 0;
2306} 2354}
2307 2355
2308/* 7.1.23. Delayed Ack Timer (SCTP_DELAYED_ACK_TIME) 2356/*
2309 * 2357 * 7.1.23. Get or set delayed ack timer (SCTP_DELAYED_SACK)
2310 * This options will get or set the delayed ack timer. The time is set 2358 *
2311 * in milliseconds. If the assoc_id is 0, then this sets or gets the 2359 * This option will effect the way delayed acks are performed. This
2312 * endpoints default delayed ack timer value. If the assoc_id field is 2360 * option allows you to get or set the delayed ack time, in
2313 * non-zero, then the set or get effects the specified association. 2361 * milliseconds. It also allows changing the delayed ack frequency.
2314 * 2362 * Changing the frequency to 1 disables the delayed sack algorithm. If
2315 * struct sctp_assoc_value { 2363 * the assoc_id is 0, then this sets or gets the endpoints default
2316 * sctp_assoc_t assoc_id; 2364 * values. If the assoc_id field is non-zero, then the set or get
2317 * uint32_t assoc_value; 2365 * effects the specified association for the one to many model (the
2318 * }; 2366 * assoc_id field is ignored by the one to one model). Note that if
2367 * sack_delay or sack_freq are 0 when setting this option, then the
2368 * current values will remain unchanged.
2369 *
2370 * struct sctp_sack_info {
2371 * sctp_assoc_t sack_assoc_id;
2372 * uint32_t sack_delay;
2373 * uint32_t sack_freq;
2374 * };
2319 * 2375 *
2320 * assoc_id - This parameter, indicates which association the 2376 * sack_assoc_id - This parameter, indicates which association the user
2321 * user is preforming an action upon. Note that if 2377 * is performing an action upon. Note that if this field's value is
2322 * this field's value is zero then the endpoints 2378 * zero then the endpoints default value is changed (effecting future
2323 * default value is changed (effecting future 2379 * associations only).
2324 * associations only).
2325 * 2380 *
2326 * assoc_value - This parameter contains the number of milliseconds 2381 * sack_delay - This parameter contains the number of milliseconds that
2327 * that the user is requesting the delayed ACK timer 2382 * the user is requesting the delayed ACK timer be set to. Note that
2328 * be set to. Note that this value is defined in 2383 * this value is defined in the standard to be between 200 and 500
2329 * the standard to be between 200 and 500 milliseconds. 2384 * milliseconds.
2330 * 2385 *
2331 * Note: a value of zero will leave the value alone, 2386 * sack_freq - This parameter contains the number of packets that must
2332 * but disable SACK delay. A non-zero value will also 2387 * be received before a sack is sent without waiting for the delay
2333 * enable SACK delay. 2388 * timer to expire. The default value for this is 2, setting this
2389 * value to 1 will disable the delayed sack algorithm.
2334 */ 2390 */
2335 2391
2336static int sctp_setsockopt_delayed_ack_time(struct sock *sk, 2392static int sctp_setsockopt_delayed_ack(struct sock *sk,
2337 char __user *optval, int optlen) 2393 char __user *optval, int optlen)
2338{ 2394{
2339 struct sctp_assoc_value params; 2395 struct sctp_sack_info params;
2340 struct sctp_transport *trans = NULL; 2396 struct sctp_transport *trans = NULL;
2341 struct sctp_association *asoc = NULL; 2397 struct sctp_association *asoc = NULL;
2342 struct sctp_sock *sp = sctp_sk(sk); 2398 struct sctp_sock *sp = sctp_sk(sk);
2343 2399
2344 if (optlen != sizeof(struct sctp_assoc_value)) 2400 if (optlen == sizeof(struct sctp_sack_info)) {
2345 return - EINVAL; 2401 if (copy_from_user(&params, optval, optlen))
2402 return -EFAULT;
2346 2403
2347 if (copy_from_user(&params, optval, optlen)) 2404 if (params.sack_delay == 0 && params.sack_freq == 0)
2348 return -EFAULT; 2405 return 0;
2406 } else if (optlen == sizeof(struct sctp_assoc_value)) {
2407 printk(KERN_WARNING "SCTP: Use of struct sctp_sack_info "
2408 "in delayed_ack socket option deprecated\n");
2409 printk(KERN_WARNING "SCTP: struct sctp_sack_info instead\n");
2410 if (copy_from_user(&params, optval, optlen))
2411 return -EFAULT;
2412
2413 if (params.sack_delay == 0)
2414 params.sack_freq = 1;
2415 else
2416 params.sack_freq = 0;
2417 } else
2418 return - EINVAL;
2349 2419
2350 /* Validate value parameter. */ 2420 /* Validate value parameter. */
2351 if (params.assoc_value > 500) 2421 if (params.sack_delay > 500)
2352 return -EINVAL; 2422 return -EINVAL;
2353 2423
2354 /* Get association, if assoc_id != 0 and the socket is a one 2424 /* Get association, if sack_assoc_id != 0 and the socket is a one
2355 * to many style socket, and an association was not found, then 2425 * to many style socket, and an association was not found, then
2356 * the id was invalid. 2426 * the id was invalid.
2357 */ 2427 */
2358 asoc = sctp_id2assoc(sk, params.assoc_id); 2428 asoc = sctp_id2assoc(sk, params.sack_assoc_id);
2359 if (!asoc && params.assoc_id && sctp_style(sk, UDP)) 2429 if (!asoc && params.sack_assoc_id && sctp_style(sk, UDP))
2360 return -EINVAL; 2430 return -EINVAL;
2361 2431
2362 if (params.assoc_value) { 2432 if (params.sack_delay) {
2363 if (asoc) { 2433 if (asoc) {
2364 asoc->sackdelay = 2434 asoc->sackdelay =
2365 msecs_to_jiffies(params.assoc_value); 2435 msecs_to_jiffies(params.sack_delay);
2366 asoc->param_flags = 2436 asoc->param_flags =
2367 (asoc->param_flags & ~SPP_SACKDELAY) | 2437 (asoc->param_flags & ~SPP_SACKDELAY) |
2368 SPP_SACKDELAY_ENABLE; 2438 SPP_SACKDELAY_ENABLE;
2369 } else { 2439 } else {
2370 sp->sackdelay = params.assoc_value; 2440 sp->sackdelay = params.sack_delay;
2371 sp->param_flags = 2441 sp->param_flags =
2372 (sp->param_flags & ~SPP_SACKDELAY) | 2442 (sp->param_flags & ~SPP_SACKDELAY) |
2373 SPP_SACKDELAY_ENABLE; 2443 SPP_SACKDELAY_ENABLE;
2374 } 2444 }
2375 } else { 2445 }
2446
2447 if (params.sack_freq == 1) {
2376 if (asoc) { 2448 if (asoc) {
2377 asoc->param_flags = 2449 asoc->param_flags =
2378 (asoc->param_flags & ~SPP_SACKDELAY) | 2450 (asoc->param_flags & ~SPP_SACKDELAY) |
@@ -2382,22 +2454,40 @@ static int sctp_setsockopt_delayed_ack_time(struct sock *sk,
2382 (sp->param_flags & ~SPP_SACKDELAY) | 2454 (sp->param_flags & ~SPP_SACKDELAY) |
2383 SPP_SACKDELAY_DISABLE; 2455 SPP_SACKDELAY_DISABLE;
2384 } 2456 }
2457 } else if (params.sack_freq > 1) {
2458 if (asoc) {
2459 asoc->sackfreq = params.sack_freq;
2460 asoc->param_flags =
2461 (asoc->param_flags & ~SPP_SACKDELAY) |
2462 SPP_SACKDELAY_ENABLE;
2463 } else {
2464 sp->sackfreq = params.sack_freq;
2465 sp->param_flags =
2466 (sp->param_flags & ~SPP_SACKDELAY) |
2467 SPP_SACKDELAY_ENABLE;
2468 }
2385 } 2469 }
2386 2470
2387 /* If change is for association, also apply to each transport. */ 2471 /* If change is for association, also apply to each transport. */
2388 if (asoc) { 2472 if (asoc) {
2389 list_for_each_entry(trans, &asoc->peer.transport_addr_list, 2473 list_for_each_entry(trans, &asoc->peer.transport_addr_list,
2390 transports) { 2474 transports) {
2391 if (params.assoc_value) { 2475 if (params.sack_delay) {
2392 trans->sackdelay = 2476 trans->sackdelay =
2393 msecs_to_jiffies(params.assoc_value); 2477 msecs_to_jiffies(params.sack_delay);
2394 trans->param_flags = 2478 trans->param_flags =
2395 (trans->param_flags & ~SPP_SACKDELAY) | 2479 (trans->param_flags & ~SPP_SACKDELAY) |
2396 SPP_SACKDELAY_ENABLE; 2480 SPP_SACKDELAY_ENABLE;
2397 } else { 2481 }
2482 if (params.sack_freq == 1) {
2398 trans->param_flags = 2483 trans->param_flags =
2399 (trans->param_flags & ~SPP_SACKDELAY) | 2484 (trans->param_flags & ~SPP_SACKDELAY) |
2400 SPP_SACKDELAY_DISABLE; 2485 SPP_SACKDELAY_DISABLE;
2486 } else if (params.sack_freq > 1) {
2487 trans->sackfreq = params.sack_freq;
2488 trans->param_flags =
2489 (trans->param_flags & ~SPP_SACKDELAY) |
2490 SPP_SACKDELAY_ENABLE;
2401 } 2491 }
2402 } 2492 }
2403 } 2493 }
@@ -3164,10 +3254,18 @@ SCTP_STATIC int sctp_setsockopt(struct sock *sk, int level, int optname,
3164 optlen, SCTP_BINDX_REM_ADDR); 3254 optlen, SCTP_BINDX_REM_ADDR);
3165 break; 3255 break;
3166 3256
3257 case SCTP_SOCKOPT_CONNECTX_OLD:
3258 /* 'optlen' is the size of the addresses buffer. */
3259 retval = sctp_setsockopt_connectx_old(sk,
3260 (struct sockaddr __user *)optval,
3261 optlen);
3262 break;
3263
3167 case SCTP_SOCKOPT_CONNECTX: 3264 case SCTP_SOCKOPT_CONNECTX:
3168 /* 'optlen' is the size of the addresses buffer. */ 3265 /* 'optlen' is the size of the addresses buffer. */
3169 retval = sctp_setsockopt_connectx(sk, (struct sockaddr __user *)optval, 3266 retval = sctp_setsockopt_connectx(sk,
3170 optlen); 3267 (struct sockaddr __user *)optval,
3268 optlen);
3171 break; 3269 break;
3172 3270
3173 case SCTP_DISABLE_FRAGMENTS: 3271 case SCTP_DISABLE_FRAGMENTS:
@@ -3186,8 +3284,8 @@ SCTP_STATIC int sctp_setsockopt(struct sock *sk, int level, int optname,
3186 retval = sctp_setsockopt_peer_addr_params(sk, optval, optlen); 3284 retval = sctp_setsockopt_peer_addr_params(sk, optval, optlen);
3187 break; 3285 break;
3188 3286
3189 case SCTP_DELAYED_ACK_TIME: 3287 case SCTP_DELAYED_ACK:
3190 retval = sctp_setsockopt_delayed_ack_time(sk, optval, optlen); 3288 retval = sctp_setsockopt_delayed_ack(sk, optval, optlen);
3191 break; 3289 break;
3192 case SCTP_PARTIAL_DELIVERY_POINT: 3290 case SCTP_PARTIAL_DELIVERY_POINT:
3193 retval = sctp_setsockopt_partial_delivery_point(sk, optval, optlen); 3291 retval = sctp_setsockopt_partial_delivery_point(sk, optval, optlen);
@@ -3294,7 +3392,7 @@ SCTP_STATIC int sctp_connect(struct sock *sk, struct sockaddr *addr,
3294 /* Pass correct addr len to common routine (so it knows there 3392 /* Pass correct addr len to common routine (so it knows there
3295 * is only one address being passed. 3393 * is only one address being passed.
3296 */ 3394 */
3297 err = __sctp_connect(sk, addr, af->sockaddr_len); 3395 err = __sctp_connect(sk, addr, af->sockaddr_len, NULL);
3298 } 3396 }
3299 3397
3300 sctp_release_sock(sk); 3398 sctp_release_sock(sk);
@@ -3446,6 +3544,7 @@ SCTP_STATIC int sctp_init_sock(struct sock *sk)
3446 sp->pathmaxrxt = sctp_max_retrans_path; 3544 sp->pathmaxrxt = sctp_max_retrans_path;
3447 sp->pathmtu = 0; // allow default discovery 3545 sp->pathmtu = 0; // allow default discovery
3448 sp->sackdelay = sctp_sack_timeout; 3546 sp->sackdelay = sctp_sack_timeout;
3547 sp->sackfreq = 2;
3449 sp->param_flags = SPP_HB_ENABLE | 3548 sp->param_flags = SPP_HB_ENABLE |
3450 SPP_PMTUD_ENABLE | 3549 SPP_PMTUD_ENABLE |
3451 SPP_SACKDELAY_ENABLE; 3550 SPP_SACKDELAY_ENABLE;
@@ -3497,7 +3596,7 @@ SCTP_STATIC int sctp_init_sock(struct sock *sk)
3497} 3596}
3498 3597
3499/* Cleanup any SCTP per socket resources. */ 3598/* Cleanup any SCTP per socket resources. */
3500SCTP_STATIC int sctp_destroy_sock(struct sock *sk) 3599SCTP_STATIC void sctp_destroy_sock(struct sock *sk)
3501{ 3600{
3502 struct sctp_endpoint *ep; 3601 struct sctp_endpoint *ep;
3503 3602
@@ -3507,7 +3606,6 @@ SCTP_STATIC int sctp_destroy_sock(struct sock *sk)
3507 ep = sctp_sk(sk)->ep; 3606 ep = sctp_sk(sk)->ep;
3508 sctp_endpoint_free(ep); 3607 sctp_endpoint_free(ep);
3509 atomic_dec(&sctp_sockets_allocated); 3608 atomic_dec(&sctp_sockets_allocated);
3510 return 0;
3511} 3609}
3512 3610
3513/* API 4.1.7 shutdown() - TCP Style Syntax 3611/* API 4.1.7 shutdown() - TCP Style Syntax
@@ -3999,70 +4097,91 @@ static int sctp_getsockopt_peer_addr_params(struct sock *sk, int len,
3999 return 0; 4097 return 0;
4000} 4098}
4001 4099
4002/* 7.1.23. Delayed Ack Timer (SCTP_DELAYED_ACK_TIME) 4100/*
4003 * 4101 * 7.1.23. Get or set delayed ack timer (SCTP_DELAYED_SACK)
4004 * This options will get or set the delayed ack timer. The time is set 4102 *
4005 * in milliseconds. If the assoc_id is 0, then this sets or gets the 4103 * This option will effect the way delayed acks are performed. This
4006 * endpoints default delayed ack timer value. If the assoc_id field is 4104 * option allows you to get or set the delayed ack time, in
4007 * non-zero, then the set or get effects the specified association. 4105 * milliseconds. It also allows changing the delayed ack frequency.
4008 * 4106 * Changing the frequency to 1 disables the delayed sack algorithm. If
4009 * struct sctp_assoc_value { 4107 * the assoc_id is 0, then this sets or gets the endpoints default
4010 * sctp_assoc_t assoc_id; 4108 * values. If the assoc_id field is non-zero, then the set or get
4011 * uint32_t assoc_value; 4109 * effects the specified association for the one to many model (the
4012 * }; 4110 * assoc_id field is ignored by the one to one model). Note that if
4111 * sack_delay or sack_freq are 0 when setting this option, then the
4112 * current values will remain unchanged.
4113 *
4114 * struct sctp_sack_info {
4115 * sctp_assoc_t sack_assoc_id;
4116 * uint32_t sack_delay;
4117 * uint32_t sack_freq;
4118 * };
4013 * 4119 *
4014 * assoc_id - This parameter, indicates which association the 4120 * sack_assoc_id - This parameter, indicates which association the user
4015 * user is preforming an action upon. Note that if 4121 * is performing an action upon. Note that if this field's value is
4016 * this field's value is zero then the endpoints 4122 * zero then the endpoints default value is changed (effecting future
4017 * default value is changed (effecting future 4123 * associations only).
4018 * associations only).
4019 * 4124 *
4020 * assoc_value - This parameter contains the number of milliseconds 4125 * sack_delay - This parameter contains the number of milliseconds that
4021 * that the user is requesting the delayed ACK timer 4126 * the user is requesting the delayed ACK timer be set to. Note that
4022 * be set to. Note that this value is defined in 4127 * this value is defined in the standard to be between 200 and 500
4023 * the standard to be between 200 and 500 milliseconds. 4128 * milliseconds.
4024 * 4129 *
4025 * Note: a value of zero will leave the value alone, 4130 * sack_freq - This parameter contains the number of packets that must
4026 * but disable SACK delay. A non-zero value will also 4131 * be received before a sack is sent without waiting for the delay
4027 * enable SACK delay. 4132 * timer to expire. The default value for this is 2, setting this
4133 * value to 1 will disable the delayed sack algorithm.
4028 */ 4134 */
4029static int sctp_getsockopt_delayed_ack_time(struct sock *sk, int len, 4135static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
4030 char __user *optval, 4136 char __user *optval,
4031 int __user *optlen) 4137 int __user *optlen)
4032{ 4138{
4033 struct sctp_assoc_value params; 4139 struct sctp_sack_info params;
4034 struct sctp_association *asoc = NULL; 4140 struct sctp_association *asoc = NULL;
4035 struct sctp_sock *sp = sctp_sk(sk); 4141 struct sctp_sock *sp = sctp_sk(sk);
4036 4142
4037 if (len < sizeof(struct sctp_assoc_value)) 4143 if (len >= sizeof(struct sctp_sack_info)) {
4038 return - EINVAL; 4144 len = sizeof(struct sctp_sack_info);
4039 4145
4040 len = sizeof(struct sctp_assoc_value); 4146 if (copy_from_user(&params, optval, len))
4041 4147 return -EFAULT;
4042 if (copy_from_user(&params, optval, len)) 4148 } else if (len == sizeof(struct sctp_assoc_value)) {
4043 return -EFAULT; 4149 printk(KERN_WARNING "SCTP: Use of struct sctp_sack_info "
4150 "in delayed_ack socket option deprecated\n");
4151 printk(KERN_WARNING "SCTP: struct sctp_sack_info instead\n");
4152 if (copy_from_user(&params, optval, len))
4153 return -EFAULT;
4154 } else
4155 return - EINVAL;
4044 4156
4045 /* Get association, if assoc_id != 0 and the socket is a one 4157 /* Get association, if sack_assoc_id != 0 and the socket is a one
4046 * to many style socket, and an association was not found, then 4158 * to many style socket, and an association was not found, then
4047 * the id was invalid. 4159 * the id was invalid.
4048 */ 4160 */
4049 asoc = sctp_id2assoc(sk, params.assoc_id); 4161 asoc = sctp_id2assoc(sk, params.sack_assoc_id);
4050 if (!asoc && params.assoc_id && sctp_style(sk, UDP)) 4162 if (!asoc && params.sack_assoc_id && sctp_style(sk, UDP))
4051 return -EINVAL; 4163 return -EINVAL;
4052 4164
4053 if (asoc) { 4165 if (asoc) {
4054 /* Fetch association values. */ 4166 /* Fetch association values. */
4055 if (asoc->param_flags & SPP_SACKDELAY_ENABLE) 4167 if (asoc->param_flags & SPP_SACKDELAY_ENABLE) {
4056 params.assoc_value = jiffies_to_msecs( 4168 params.sack_delay = jiffies_to_msecs(
4057 asoc->sackdelay); 4169 asoc->sackdelay);
4058 else 4170 params.sack_freq = asoc->sackfreq;
4059 params.assoc_value = 0; 4171
4172 } else {
4173 params.sack_delay = 0;
4174 params.sack_freq = 1;
4175 }
4060 } else { 4176 } else {
4061 /* Fetch socket values. */ 4177 /* Fetch socket values. */
4062 if (sp->param_flags & SPP_SACKDELAY_ENABLE) 4178 if (sp->param_flags & SPP_SACKDELAY_ENABLE) {
4063 params.assoc_value = sp->sackdelay; 4179 params.sack_delay = sp->sackdelay;
4064 else 4180 params.sack_freq = sp->sackfreq;
4065 params.assoc_value = 0; 4181 } else {
4182 params.sack_delay = 0;
4183 params.sack_freq = 1;
4184 }
4066 } 4185 }
4067 4186
4068 if (copy_to_user(optval, &params, len)) 4187 if (copy_to_user(optval, &params, len))
@@ -4112,6 +4231,8 @@ static int sctp_getsockopt_peer_addrs_num_old(struct sock *sk, int len,
4112 if (copy_from_user(&id, optval, sizeof(sctp_assoc_t))) 4231 if (copy_from_user(&id, optval, sizeof(sctp_assoc_t)))
4113 return -EFAULT; 4232 return -EFAULT;
4114 4233
4234 printk(KERN_WARNING "SCTP: Use of SCTP_GET_PEER_ADDRS_NUM_OLD "
4235 "socket option deprecated\n");
4115 /* For UDP-style sockets, id specifies the association to query. */ 4236 /* For UDP-style sockets, id specifies the association to query. */
4116 asoc = sctp_id2assoc(sk, id); 4237 asoc = sctp_id2assoc(sk, id);
4117 if (!asoc) 4238 if (!asoc)
@@ -4151,6 +4272,9 @@ static int sctp_getsockopt_peer_addrs_old(struct sock *sk, int len,
4151 4272
4152 if (getaddrs.addr_num <= 0) return -EINVAL; 4273 if (getaddrs.addr_num <= 0) return -EINVAL;
4153 4274
4275 printk(KERN_WARNING "SCTP: Use of SCTP_GET_PEER_ADDRS_OLD "
4276 "socket option deprecated\n");
4277
4154 /* For UDP-style sockets, id specifies the association to query. */ 4278 /* For UDP-style sockets, id specifies the association to query. */
4155 asoc = sctp_id2assoc(sk, getaddrs.assoc_id); 4279 asoc = sctp_id2assoc(sk, getaddrs.assoc_id);
4156 if (!asoc) 4280 if (!asoc)
@@ -4244,6 +4368,9 @@ static int sctp_getsockopt_local_addrs_num_old(struct sock *sk, int len,
4244 if (copy_from_user(&id, optval, sizeof(sctp_assoc_t))) 4368 if (copy_from_user(&id, optval, sizeof(sctp_assoc_t)))
4245 return -EFAULT; 4369 return -EFAULT;
4246 4370
4371 printk(KERN_WARNING "SCTP: Use of SCTP_GET_LOCAL_ADDRS_NUM_OLD "
4372 "socket option deprecated\n");
4373
4247 /* 4374 /*
4248 * For UDP-style sockets, id specifies the association to query. 4375 * For UDP-style sockets, id specifies the association to query.
4249 * If the id field is set to the value '0' then the locally bound 4376 * If the id field is set to the value '0' then the locally bound
@@ -4276,6 +4403,11 @@ static int sctp_getsockopt_local_addrs_num_old(struct sock *sk, int len,
4276 (AF_INET6 == addr->a.sa.sa_family)) 4403 (AF_INET6 == addr->a.sa.sa_family))
4277 continue; 4404 continue;
4278 4405
4406 if ((PF_INET6 == sk->sk_family) &&
4407 inet_v6_ipv6only(sk) &&
4408 (AF_INET == addr->a.sa.sa_family))
4409 continue;
4410
4279 cnt++; 4411 cnt++;
4280 } 4412 }
4281 rcu_read_unlock(); 4413 rcu_read_unlock();
@@ -4316,6 +4448,10 @@ static int sctp_copy_laddrs_old(struct sock *sk, __u16 port,
4316 if ((PF_INET == sk->sk_family) && 4448 if ((PF_INET == sk->sk_family) &&
4317 (AF_INET6 == addr->a.sa.sa_family)) 4449 (AF_INET6 == addr->a.sa.sa_family))
4318 continue; 4450 continue;
4451 if ((PF_INET6 == sk->sk_family) &&
4452 inet_v6_ipv6only(sk) &&
4453 (AF_INET == addr->a.sa.sa_family))
4454 continue;
4319 memcpy(&temp, &addr->a, sizeof(temp)); 4455 memcpy(&temp, &addr->a, sizeof(temp));
4320 if (!temp.v4.sin_port) 4456 if (!temp.v4.sin_port)
4321 temp.v4.sin_port = htons(port); 4457 temp.v4.sin_port = htons(port);
@@ -4351,6 +4487,10 @@ static int sctp_copy_laddrs(struct sock *sk, __u16 port, void *to,
4351 if ((PF_INET == sk->sk_family) && 4487 if ((PF_INET == sk->sk_family) &&
4352 (AF_INET6 == addr->a.sa.sa_family)) 4488 (AF_INET6 == addr->a.sa.sa_family))
4353 continue; 4489 continue;
4490 if ((PF_INET6 == sk->sk_family) &&
4491 inet_v6_ipv6only(sk) &&
4492 (AF_INET == addr->a.sa.sa_family))
4493 continue;
4354 memcpy(&temp, &addr->a, sizeof(temp)); 4494 memcpy(&temp, &addr->a, sizeof(temp));
4355 if (!temp.v4.sin_port) 4495 if (!temp.v4.sin_port)
4356 temp.v4.sin_port = htons(port); 4496 temp.v4.sin_port = htons(port);
@@ -4404,6 +4544,10 @@ static int sctp_getsockopt_local_addrs_old(struct sock *sk, int len,
4404 if (getaddrs.addr_num <= 0 || 4544 if (getaddrs.addr_num <= 0 ||
4405 getaddrs.addr_num >= (INT_MAX / sizeof(union sctp_addr))) 4545 getaddrs.addr_num >= (INT_MAX / sizeof(union sctp_addr)))
4406 return -EINVAL; 4546 return -EINVAL;
4547
4548 printk(KERN_WARNING "SCTP: Use of SCTP_GET_LOCAL_ADDRS_OLD "
4549 "socket option deprecated\n");
4550
4407 /* 4551 /*
4408 * For UDP-style sockets, id specifies the association to query. 4552 * For UDP-style sockets, id specifies the association to query.
4409 * If the id field is set to the value '0' then the locally bound 4553 * If the id field is set to the value '0' then the locally bound
@@ -5220,8 +5364,8 @@ SCTP_STATIC int sctp_getsockopt(struct sock *sk, int level, int optname,
5220 retval = sctp_getsockopt_peer_addr_params(sk, len, optval, 5364 retval = sctp_getsockopt_peer_addr_params(sk, len, optval,
5221 optlen); 5365 optlen);
5222 break; 5366 break;
5223 case SCTP_DELAYED_ACK_TIME: 5367 case SCTP_DELAYED_ACK:
5224 retval = sctp_getsockopt_delayed_ack_time(sk, len, optval, 5368 retval = sctp_getsockopt_delayed_ack(sk, len, optval,
5225 optlen); 5369 optlen);
5226 break; 5370 break;
5227 case SCTP_INITMSG: 5371 case SCTP_INITMSG:
@@ -5441,12 +5585,13 @@ pp_found:
5441 struct sctp_endpoint *ep2; 5585 struct sctp_endpoint *ep2;
5442 ep2 = sctp_sk(sk2)->ep; 5586 ep2 = sctp_sk(sk2)->ep;
5443 5587
5444 if (reuse && sk2->sk_reuse && 5588 if (sk == sk2 ||
5445 sk2->sk_state != SCTP_SS_LISTENING) 5589 (reuse && sk2->sk_reuse &&
5590 sk2->sk_state != SCTP_SS_LISTENING))
5446 continue; 5591 continue;
5447 5592
5448 if (sctp_bind_addr_match(&ep2->base.bind_addr, addr, 5593 if (sctp_bind_addr_conflict(&ep2->base.bind_addr, addr,
5449 sctp_sk(sk))) { 5594 sctp_sk(sk2), sctp_sk(sk))) {
5450 ret = (long)sk2; 5595 ret = (long)sk2;
5451 goto fail_unlock; 5596 goto fail_unlock;
5452 } 5597 }
@@ -5559,8 +5704,13 @@ SCTP_STATIC int sctp_seqpacket_listen(struct sock *sk, int backlog)
5559 if (!ep->base.bind_addr.port) { 5704 if (!ep->base.bind_addr.port) {
5560 if (sctp_autobind(sk)) 5705 if (sctp_autobind(sk))
5561 return -EAGAIN; 5706 return -EAGAIN;
5562 } else 5707 } else {
5708 if (sctp_get_port(sk, inet_sk(sk)->num)) {
5709 sk->sk_state = SCTP_SS_CLOSED;
5710 return -EADDRINUSE;
5711 }
5563 sctp_sk(sk)->bind_hash->fastreuse = 0; 5712 sctp_sk(sk)->bind_hash->fastreuse = 0;
5713 }
5564 5714
5565 sctp_hash_endpoint(ep); 5715 sctp_hash_endpoint(ep);
5566 return 0; 5716 return 0;
@@ -5630,7 +5780,7 @@ int sctp_inet_listen(struct socket *sock, int backlog)
5630 goto out; 5780 goto out;
5631 5781
5632 /* Allocate HMAC for generating cookie. */ 5782 /* Allocate HMAC for generating cookie. */
5633 if (sctp_hmac_alg) { 5783 if (!sctp_sk(sk)->hmac && sctp_hmac_alg) {
5634 tfm = crypto_alloc_hash(sctp_hmac_alg, 0, CRYPTO_ALG_ASYNC); 5784 tfm = crypto_alloc_hash(sctp_hmac_alg, 0, CRYPTO_ALG_ASYNC);
5635 if (IS_ERR(tfm)) { 5785 if (IS_ERR(tfm)) {
5636 if (net_ratelimit()) { 5786 if (net_ratelimit()) {
@@ -5658,7 +5808,8 @@ int sctp_inet_listen(struct socket *sock, int backlog)
5658 goto cleanup; 5808 goto cleanup;
5659 5809
5660 /* Store away the transform reference. */ 5810 /* Store away the transform reference. */
5661 sctp_sk(sk)->hmac = tfm; 5811 if (!sctp_sk(sk)->hmac)
5812 sctp_sk(sk)->hmac = tfm;
5662out: 5813out:
5663 sctp_release_sock(sk); 5814 sctp_release_sock(sk);
5664 return err; 5815 return err;