diff options
author | Stephen Hemminger <shemminger@linux-foundation.org> | 2007-04-10 23:10:33 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2007-04-26 01:24:09 -0400 |
commit | e71a4783aae059931f63b2d4e7013e36529badef (patch) | |
tree | d9c2bad69b8d0512e12c8ff786237319990fbd00 /net/core/sock.c | |
parent | add459aa1afe05472abc96f6a29aefd0c84e73d6 (diff) |
[NET] core: whitespace cleanup
Fix whitespace around keywords. Fix indentation especially of switch
statements.
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core/sock.c')
-rw-r--r-- | net/core/sock.c | 712 |
1 files changed, 354 insertions, 358 deletions
diff --git a/net/core/sock.c b/net/core/sock.c index cb48fa0e1249..792ae39804a2 100644 --- a/net/core/sock.c +++ b/net/core/sock.c | |||
@@ -361,8 +361,8 @@ int sock_setsockopt(struct socket *sock, int level, int optname, | |||
361 | } | 361 | } |
362 | #endif | 362 | #endif |
363 | 363 | ||
364 | if(optlen<sizeof(int)) | 364 | if (optlen < sizeof(int)) |
365 | return(-EINVAL); | 365 | return -EINVAL; |
366 | 366 | ||
367 | if (get_user(val, (int __user *)optval)) | 367 | if (get_user(val, (int __user *)optval)) |
368 | return -EFAULT; | 368 | return -EFAULT; |
@@ -371,265 +371,263 @@ int sock_setsockopt(struct socket *sock, int level, int optname, | |||
371 | 371 | ||
372 | lock_sock(sk); | 372 | lock_sock(sk); |
373 | 373 | ||
374 | switch(optname) | 374 | switch(optname) { |
375 | { | 375 | case SO_DEBUG: |
376 | case SO_DEBUG: | 376 | if (val && !capable(CAP_NET_ADMIN)) { |
377 | if(val && !capable(CAP_NET_ADMIN)) | 377 | ret = -EACCES; |
378 | { | 378 | } |
379 | ret = -EACCES; | 379 | else if (valbool) |
380 | } | 380 | sock_set_flag(sk, SOCK_DBG); |
381 | else if (valbool) | 381 | else |
382 | sock_set_flag(sk, SOCK_DBG); | 382 | sock_reset_flag(sk, SOCK_DBG); |
383 | else | 383 | break; |
384 | sock_reset_flag(sk, SOCK_DBG); | 384 | case SO_REUSEADDR: |
385 | break; | 385 | sk->sk_reuse = valbool; |
386 | case SO_REUSEADDR: | 386 | break; |
387 | sk->sk_reuse = valbool; | 387 | case SO_TYPE: |
388 | break; | 388 | case SO_ERROR: |
389 | case SO_TYPE: | 389 | ret = -ENOPROTOOPT; |
390 | case SO_ERROR: | 390 | break; |
391 | ret = -ENOPROTOOPT; | 391 | case SO_DONTROUTE: |
392 | break; | 392 | if (valbool) |
393 | case SO_DONTROUTE: | 393 | sock_set_flag(sk, SOCK_LOCALROUTE); |
394 | if (valbool) | 394 | else |
395 | sock_set_flag(sk, SOCK_LOCALROUTE); | 395 | sock_reset_flag(sk, SOCK_LOCALROUTE); |
396 | else | 396 | break; |
397 | sock_reset_flag(sk, SOCK_LOCALROUTE); | 397 | case SO_BROADCAST: |
398 | break; | 398 | sock_valbool_flag(sk, SOCK_BROADCAST, valbool); |
399 | case SO_BROADCAST: | 399 | break; |
400 | sock_valbool_flag(sk, SOCK_BROADCAST, valbool); | 400 | case SO_SNDBUF: |
401 | break; | 401 | /* Don't error on this BSD doesn't and if you think |
402 | case SO_SNDBUF: | 402 | about it this is right. Otherwise apps have to |
403 | /* Don't error on this BSD doesn't and if you think | 403 | play 'guess the biggest size' games. RCVBUF/SNDBUF |
404 | about it this is right. Otherwise apps have to | 404 | are treated in BSD as hints */ |
405 | play 'guess the biggest size' games. RCVBUF/SNDBUF | 405 | |
406 | are treated in BSD as hints */ | 406 | if (val > sysctl_wmem_max) |
407 | 407 | val = sysctl_wmem_max; | |
408 | if (val > sysctl_wmem_max) | ||
409 | val = sysctl_wmem_max; | ||
410 | set_sndbuf: | 408 | set_sndbuf: |
411 | sk->sk_userlocks |= SOCK_SNDBUF_LOCK; | 409 | sk->sk_userlocks |= SOCK_SNDBUF_LOCK; |
412 | if ((val * 2) < SOCK_MIN_SNDBUF) | 410 | if ((val * 2) < SOCK_MIN_SNDBUF) |
413 | sk->sk_sndbuf = SOCK_MIN_SNDBUF; | 411 | sk->sk_sndbuf = SOCK_MIN_SNDBUF; |
414 | else | 412 | else |
415 | sk->sk_sndbuf = val * 2; | 413 | sk->sk_sndbuf = val * 2; |
416 | 414 | ||
417 | /* | 415 | /* |
418 | * Wake up sending tasks if we | 416 | * Wake up sending tasks if we |
419 | * upped the value. | 417 | * upped the value. |
420 | */ | 418 | */ |
421 | sk->sk_write_space(sk); | 419 | sk->sk_write_space(sk); |
422 | break; | 420 | break; |
423 | 421 | ||
424 | case SO_SNDBUFFORCE: | 422 | case SO_SNDBUFFORCE: |
425 | if (!capable(CAP_NET_ADMIN)) { | 423 | if (!capable(CAP_NET_ADMIN)) { |
426 | ret = -EPERM; | 424 | ret = -EPERM; |
427 | break; | 425 | break; |
428 | } | 426 | } |
429 | goto set_sndbuf; | 427 | goto set_sndbuf; |
430 | 428 | ||
431 | case SO_RCVBUF: | 429 | case SO_RCVBUF: |
432 | /* Don't error on this BSD doesn't and if you think | 430 | /* Don't error on this BSD doesn't and if you think |
433 | about it this is right. Otherwise apps have to | 431 | about it this is right. Otherwise apps have to |
434 | play 'guess the biggest size' games. RCVBUF/SNDBUF | 432 | play 'guess the biggest size' games. RCVBUF/SNDBUF |
435 | are treated in BSD as hints */ | 433 | are treated in BSD as hints */ |
436 | 434 | ||
437 | if (val > sysctl_rmem_max) | 435 | if (val > sysctl_rmem_max) |
438 | val = sysctl_rmem_max; | 436 | val = sysctl_rmem_max; |
439 | set_rcvbuf: | 437 | set_rcvbuf: |
440 | sk->sk_userlocks |= SOCK_RCVBUF_LOCK; | 438 | sk->sk_userlocks |= SOCK_RCVBUF_LOCK; |
441 | /* | 439 | /* |
442 | * We double it on the way in to account for | 440 | * We double it on the way in to account for |
443 | * "struct sk_buff" etc. overhead. Applications | 441 | * "struct sk_buff" etc. overhead. Applications |
444 | * assume that the SO_RCVBUF setting they make will | 442 | * assume that the SO_RCVBUF setting they make will |
445 | * allow that much actual data to be received on that | 443 | * allow that much actual data to be received on that |
446 | * socket. | 444 | * socket. |
447 | * | 445 | * |
448 | * Applications are unaware that "struct sk_buff" and | 446 | * Applications are unaware that "struct sk_buff" and |
449 | * other overheads allocate from the receive buffer | 447 | * other overheads allocate from the receive buffer |
450 | * during socket buffer allocation. | 448 | * during socket buffer allocation. |
451 | * | 449 | * |
452 | * And after considering the possible alternatives, | 450 | * And after considering the possible alternatives, |
453 | * returning the value we actually used in getsockopt | 451 | * returning the value we actually used in getsockopt |
454 | * is the most desirable behavior. | 452 | * is the most desirable behavior. |
455 | */ | 453 | */ |
456 | if ((val * 2) < SOCK_MIN_RCVBUF) | 454 | if ((val * 2) < SOCK_MIN_RCVBUF) |
457 | sk->sk_rcvbuf = SOCK_MIN_RCVBUF; | 455 | sk->sk_rcvbuf = SOCK_MIN_RCVBUF; |
458 | else | 456 | else |
459 | sk->sk_rcvbuf = val * 2; | 457 | sk->sk_rcvbuf = val * 2; |
458 | break; | ||
459 | |||
460 | case SO_RCVBUFFORCE: | ||
461 | if (!capable(CAP_NET_ADMIN)) { | ||
462 | ret = -EPERM; | ||
460 | break; | 463 | break; |
464 | } | ||
465 | goto set_rcvbuf; | ||
461 | 466 | ||
462 | case SO_RCVBUFFORCE: | 467 | case SO_KEEPALIVE: |
463 | if (!capable(CAP_NET_ADMIN)) { | ||
464 | ret = -EPERM; | ||
465 | break; | ||
466 | } | ||
467 | goto set_rcvbuf; | ||
468 | |||
469 | case SO_KEEPALIVE: | ||
470 | #ifdef CONFIG_INET | 468 | #ifdef CONFIG_INET |
471 | if (sk->sk_protocol == IPPROTO_TCP) | 469 | if (sk->sk_protocol == IPPROTO_TCP) |
472 | tcp_set_keepalive(sk, valbool); | 470 | tcp_set_keepalive(sk, valbool); |
473 | #endif | 471 | #endif |
474 | sock_valbool_flag(sk, SOCK_KEEPOPEN, valbool); | 472 | sock_valbool_flag(sk, SOCK_KEEPOPEN, valbool); |
475 | break; | 473 | break; |
476 | 474 | ||
477 | case SO_OOBINLINE: | 475 | case SO_OOBINLINE: |
478 | sock_valbool_flag(sk, SOCK_URGINLINE, valbool); | 476 | sock_valbool_flag(sk, SOCK_URGINLINE, valbool); |
477 | break; | ||
478 | |||
479 | case SO_NO_CHECK: | ||
480 | sk->sk_no_check = valbool; | ||
481 | break; | ||
482 | |||
483 | case SO_PRIORITY: | ||
484 | if ((val >= 0 && val <= 6) || capable(CAP_NET_ADMIN)) | ||
485 | sk->sk_priority = val; | ||
486 | else | ||
487 | ret = -EPERM; | ||
488 | break; | ||
489 | |||
490 | case SO_LINGER: | ||
491 | if (optlen < sizeof(ling)) { | ||
492 | ret = -EINVAL; /* 1003.1g */ | ||
479 | break; | 493 | break; |
480 | 494 | } | |
481 | case SO_NO_CHECK: | 495 | if (copy_from_user(&ling,optval,sizeof(ling))) { |
482 | sk->sk_no_check = valbool; | 496 | ret = -EFAULT; |
483 | break; | ||
484 | |||
485 | case SO_PRIORITY: | ||
486 | if ((val >= 0 && val <= 6) || capable(CAP_NET_ADMIN)) | ||
487 | sk->sk_priority = val; | ||
488 | else | ||
489 | ret = -EPERM; | ||
490 | break; | 497 | break; |
491 | 498 | } | |
492 | case SO_LINGER: | 499 | if (!ling.l_onoff) |
493 | if(optlen<sizeof(ling)) { | 500 | sock_reset_flag(sk, SOCK_LINGER); |
494 | ret = -EINVAL; /* 1003.1g */ | 501 | else { |
495 | break; | ||
496 | } | ||
497 | if (copy_from_user(&ling,optval,sizeof(ling))) { | ||
498 | ret = -EFAULT; | ||
499 | break; | ||
500 | } | ||
501 | if (!ling.l_onoff) | ||
502 | sock_reset_flag(sk, SOCK_LINGER); | ||
503 | else { | ||
504 | #if (BITS_PER_LONG == 32) | 502 | #if (BITS_PER_LONG == 32) |
505 | if ((unsigned int)ling.l_linger >= MAX_SCHEDULE_TIMEOUT/HZ) | 503 | if ((unsigned int)ling.l_linger >= MAX_SCHEDULE_TIMEOUT/HZ) |
506 | sk->sk_lingertime = MAX_SCHEDULE_TIMEOUT; | 504 | sk->sk_lingertime = MAX_SCHEDULE_TIMEOUT; |
507 | else | ||
508 | #endif | ||
509 | sk->sk_lingertime = (unsigned int)ling.l_linger * HZ; | ||
510 | sock_set_flag(sk, SOCK_LINGER); | ||
511 | } | ||
512 | break; | ||
513 | |||
514 | case SO_BSDCOMPAT: | ||
515 | sock_warn_obsolete_bsdism("setsockopt"); | ||
516 | break; | ||
517 | |||
518 | case SO_PASSCRED: | ||
519 | if (valbool) | ||
520 | set_bit(SOCK_PASSCRED, &sock->flags); | ||
521 | else | 505 | else |
522 | clear_bit(SOCK_PASSCRED, &sock->flags); | 506 | #endif |
523 | break; | 507 | sk->sk_lingertime = (unsigned int)ling.l_linger * HZ; |
524 | 508 | sock_set_flag(sk, SOCK_LINGER); | |
525 | case SO_TIMESTAMP: | 509 | } |
526 | if (valbool) { | 510 | break; |
527 | sock_set_flag(sk, SOCK_RCVTSTAMP); | 511 | |
528 | sock_enable_timestamp(sk); | 512 | case SO_BSDCOMPAT: |
529 | } else | 513 | sock_warn_obsolete_bsdism("setsockopt"); |
530 | sock_reset_flag(sk, SOCK_RCVTSTAMP); | 514 | break; |
531 | break; | 515 | |
532 | 516 | case SO_PASSCRED: | |
533 | case SO_RCVLOWAT: | 517 | if (valbool) |
534 | if (val < 0) | 518 | set_bit(SOCK_PASSCRED, &sock->flags); |
535 | val = INT_MAX; | 519 | else |
536 | sk->sk_rcvlowat = val ? : 1; | 520 | clear_bit(SOCK_PASSCRED, &sock->flags); |
537 | break; | 521 | break; |
522 | |||
523 | case SO_TIMESTAMP: | ||
524 | if (valbool) { | ||
525 | sock_set_flag(sk, SOCK_RCVTSTAMP); | ||
526 | sock_enable_timestamp(sk); | ||
527 | } else | ||
528 | sock_reset_flag(sk, SOCK_RCVTSTAMP); | ||
529 | break; | ||
530 | |||
531 | case SO_RCVLOWAT: | ||
532 | if (val < 0) | ||
533 | val = INT_MAX; | ||
534 | sk->sk_rcvlowat = val ? : 1; | ||
535 | break; | ||
536 | |||
537 | case SO_RCVTIMEO: | ||
538 | ret = sock_set_timeout(&sk->sk_rcvtimeo, optval, optlen); | ||
539 | break; | ||
540 | |||
541 | case SO_SNDTIMEO: | ||
542 | ret = sock_set_timeout(&sk->sk_sndtimeo, optval, optlen); | ||
543 | break; | ||
538 | 544 | ||
539 | case SO_RCVTIMEO: | 545 | #ifdef CONFIG_NETDEVICES |
540 | ret = sock_set_timeout(&sk->sk_rcvtimeo, optval, optlen); | 546 | case SO_BINDTODEVICE: |
541 | break; | 547 | { |
548 | char devname[IFNAMSIZ]; | ||
542 | 549 | ||
543 | case SO_SNDTIMEO: | 550 | /* Sorry... */ |
544 | ret = sock_set_timeout(&sk->sk_sndtimeo, optval, optlen); | 551 | if (!capable(CAP_NET_RAW)) { |
552 | ret = -EPERM; | ||
545 | break; | 553 | break; |
554 | } | ||
546 | 555 | ||
547 | #ifdef CONFIG_NETDEVICES | 556 | /* Bind this socket to a particular device like "eth0", |
548 | case SO_BINDTODEVICE: | 557 | * as specified in the passed interface name. If the |
549 | { | 558 | * name is "" or the option length is zero the socket |
550 | char devname[IFNAMSIZ]; | 559 | * is not bound. |
560 | */ | ||
551 | 561 | ||
552 | /* Sorry... */ | 562 | if (!valbool) { |
553 | if (!capable(CAP_NET_RAW)) { | 563 | sk->sk_bound_dev_if = 0; |
554 | ret = -EPERM; | 564 | } else { |
565 | if (optlen > IFNAMSIZ - 1) | ||
566 | optlen = IFNAMSIZ - 1; | ||
567 | memset(devname, 0, sizeof(devname)); | ||
568 | if (copy_from_user(devname, optval, optlen)) { | ||
569 | ret = -EFAULT; | ||
555 | break; | 570 | break; |
556 | } | 571 | } |
557 | 572 | ||
558 | /* Bind this socket to a particular device like "eth0", | 573 | /* Remove any cached route for this socket. */ |
559 | * as specified in the passed interface name. If the | 574 | sk_dst_reset(sk); |
560 | * name is "" or the option length is zero the socket | ||
561 | * is not bound. | ||
562 | */ | ||
563 | 575 | ||
564 | if (!valbool) { | 576 | if (devname[0] == '\0') { |
565 | sk->sk_bound_dev_if = 0; | 577 | sk->sk_bound_dev_if = 0; |
566 | } else { | 578 | } else { |
567 | if (optlen > IFNAMSIZ - 1) | 579 | struct net_device *dev = dev_get_by_name(devname); |
568 | optlen = IFNAMSIZ - 1; | 580 | if (!dev) { |
569 | memset(devname, 0, sizeof(devname)); | 581 | ret = -ENODEV; |
570 | if (copy_from_user(devname, optval, optlen)) { | ||
571 | ret = -EFAULT; | ||
572 | break; | 582 | break; |
573 | } | 583 | } |
574 | 584 | sk->sk_bound_dev_if = dev->ifindex; | |
575 | /* Remove any cached route for this socket. */ | 585 | dev_put(dev); |
576 | sk_dst_reset(sk); | ||
577 | |||
578 | if (devname[0] == '\0') { | ||
579 | sk->sk_bound_dev_if = 0; | ||
580 | } else { | ||
581 | struct net_device *dev = dev_get_by_name(devname); | ||
582 | if (!dev) { | ||
583 | ret = -ENODEV; | ||
584 | break; | ||
585 | } | ||
586 | sk->sk_bound_dev_if = dev->ifindex; | ||
587 | dev_put(dev); | ||
588 | } | ||
589 | } | 586 | } |
590 | break; | ||
591 | } | 587 | } |
588 | break; | ||
589 | } | ||
592 | #endif | 590 | #endif |
593 | 591 | ||
594 | 592 | ||
595 | case SO_ATTACH_FILTER: | 593 | case SO_ATTACH_FILTER: |
596 | ret = -EINVAL; | 594 | ret = -EINVAL; |
597 | if (optlen == sizeof(struct sock_fprog)) { | 595 | if (optlen == sizeof(struct sock_fprog)) { |
598 | struct sock_fprog fprog; | 596 | struct sock_fprog fprog; |
599 | |||
600 | ret = -EFAULT; | ||
601 | if (copy_from_user(&fprog, optval, sizeof(fprog))) | ||
602 | break; | ||
603 | |||
604 | ret = sk_attach_filter(&fprog, sk); | ||
605 | } | ||
606 | break; | ||
607 | 597 | ||
608 | case SO_DETACH_FILTER: | 598 | ret = -EFAULT; |
609 | rcu_read_lock_bh(); | 599 | if (copy_from_user(&fprog, optval, sizeof(fprog))) |
610 | filter = rcu_dereference(sk->sk_filter); | ||
611 | if (filter) { | ||
612 | rcu_assign_pointer(sk->sk_filter, NULL); | ||
613 | sk_filter_release(sk, filter); | ||
614 | rcu_read_unlock_bh(); | ||
615 | break; | 600 | break; |
616 | } | 601 | |
602 | ret = sk_attach_filter(&fprog, sk); | ||
603 | } | ||
604 | break; | ||
605 | |||
606 | case SO_DETACH_FILTER: | ||
607 | rcu_read_lock_bh(); | ||
608 | filter = rcu_dereference(sk->sk_filter); | ||
609 | if (filter) { | ||
610 | rcu_assign_pointer(sk->sk_filter, NULL); | ||
611 | sk_filter_release(sk, filter); | ||
617 | rcu_read_unlock_bh(); | 612 | rcu_read_unlock_bh(); |
618 | ret = -ENONET; | ||
619 | break; | 613 | break; |
614 | } | ||
615 | rcu_read_unlock_bh(); | ||
616 | ret = -ENONET; | ||
617 | break; | ||
620 | 618 | ||
621 | case SO_PASSSEC: | 619 | case SO_PASSSEC: |
622 | if (valbool) | 620 | if (valbool) |
623 | set_bit(SOCK_PASSSEC, &sock->flags); | 621 | set_bit(SOCK_PASSSEC, &sock->flags); |
624 | else | 622 | else |
625 | clear_bit(SOCK_PASSSEC, &sock->flags); | 623 | clear_bit(SOCK_PASSSEC, &sock->flags); |
626 | break; | 624 | break; |
627 | 625 | ||
628 | /* We implement the SO_SNDLOWAT etc to | 626 | /* We implement the SO_SNDLOWAT etc to |
629 | not be settable (1003.1g 5.3) */ | 627 | not be settable (1003.1g 5.3) */ |
630 | default: | 628 | default: |
631 | ret = -ENOPROTOOPT; | 629 | ret = -ENOPROTOOPT; |
632 | break; | 630 | break; |
633 | } | 631 | } |
634 | release_sock(sk); | 632 | release_sock(sk); |
635 | return ret; | 633 | return ret; |
@@ -641,8 +639,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname, | |||
641 | { | 639 | { |
642 | struct sock *sk = sock->sk; | 640 | struct sock *sk = sock->sk; |
643 | 641 | ||
644 | union | 642 | union { |
645 | { | ||
646 | int val; | 643 | int val; |
647 | struct linger ling; | 644 | struct linger ling; |
648 | struct timeval tm; | 645 | struct timeval tm; |
@@ -651,148 +648,148 @@ int sock_getsockopt(struct socket *sock, int level, int optname, | |||
651 | unsigned int lv = sizeof(int); | 648 | unsigned int lv = sizeof(int); |
652 | int len; | 649 | int len; |
653 | 650 | ||
654 | if(get_user(len,optlen)) | 651 | if (get_user(len, optlen)) |
655 | return -EFAULT; | 652 | return -EFAULT; |
656 | if(len < 0) | 653 | if (len < 0) |
657 | return -EINVAL; | 654 | return -EINVAL; |
658 | 655 | ||
659 | switch(optname) | 656 | switch(optname) { |
660 | { | 657 | case SO_DEBUG: |
661 | case SO_DEBUG: | 658 | v.val = sock_flag(sk, SOCK_DBG); |
662 | v.val = sock_flag(sk, SOCK_DBG); | 659 | break; |
663 | break; | 660 | |
664 | 661 | case SO_DONTROUTE: | |
665 | case SO_DONTROUTE: | 662 | v.val = sock_flag(sk, SOCK_LOCALROUTE); |
666 | v.val = sock_flag(sk, SOCK_LOCALROUTE); | 663 | break; |
667 | break; | 664 | |
668 | 665 | case SO_BROADCAST: | |
669 | case SO_BROADCAST: | 666 | v.val = !!sock_flag(sk, SOCK_BROADCAST); |
670 | v.val = !!sock_flag(sk, SOCK_BROADCAST); | 667 | break; |
671 | break; | 668 | |
672 | 669 | case SO_SNDBUF: | |
673 | case SO_SNDBUF: | 670 | v.val = sk->sk_sndbuf; |
674 | v.val = sk->sk_sndbuf; | 671 | break; |
675 | break; | 672 | |
676 | 673 | case SO_RCVBUF: | |
677 | case SO_RCVBUF: | 674 | v.val = sk->sk_rcvbuf; |
678 | v.val = sk->sk_rcvbuf; | 675 | break; |
679 | break; | 676 | |
680 | 677 | case SO_REUSEADDR: | |
681 | case SO_REUSEADDR: | 678 | v.val = sk->sk_reuse; |
682 | v.val = sk->sk_reuse; | 679 | break; |
683 | break; | 680 | |
684 | 681 | case SO_KEEPALIVE: | |
685 | case SO_KEEPALIVE: | 682 | v.val = !!sock_flag(sk, SOCK_KEEPOPEN); |
686 | v.val = !!sock_flag(sk, SOCK_KEEPOPEN); | 683 | break; |
687 | break; | 684 | |
688 | 685 | case SO_TYPE: | |
689 | case SO_TYPE: | 686 | v.val = sk->sk_type; |
690 | v.val = sk->sk_type; | 687 | break; |
691 | break; | 688 | |
692 | 689 | case SO_ERROR: | |
693 | case SO_ERROR: | 690 | v.val = -sock_error(sk); |
694 | v.val = -sock_error(sk); | 691 | if (v.val==0) |
695 | if(v.val==0) | 692 | v.val = xchg(&sk->sk_err_soft, 0); |
696 | v.val = xchg(&sk->sk_err_soft, 0); | 693 | break; |
697 | break; | 694 | |
698 | 695 | case SO_OOBINLINE: | |
699 | case SO_OOBINLINE: | 696 | v.val = !!sock_flag(sk, SOCK_URGINLINE); |
700 | v.val = !!sock_flag(sk, SOCK_URGINLINE); | 697 | break; |
701 | break; | 698 | |
702 | 699 | case SO_NO_CHECK: | |
703 | case SO_NO_CHECK: | 700 | v.val = sk->sk_no_check; |
704 | v.val = sk->sk_no_check; | 701 | break; |
705 | break; | 702 | |
706 | 703 | case SO_PRIORITY: | |
707 | case SO_PRIORITY: | 704 | v.val = sk->sk_priority; |
708 | v.val = sk->sk_priority; | 705 | break; |
709 | break; | 706 | |
710 | 707 | case SO_LINGER: | |
711 | case SO_LINGER: | 708 | lv = sizeof(v.ling); |
712 | lv = sizeof(v.ling); | 709 | v.ling.l_onoff = !!sock_flag(sk, SOCK_LINGER); |
713 | v.ling.l_onoff = !!sock_flag(sk, SOCK_LINGER); | 710 | v.ling.l_linger = sk->sk_lingertime / HZ; |
714 | v.ling.l_linger = sk->sk_lingertime / HZ; | 711 | break; |
715 | break; | 712 | |
716 | 713 | case SO_BSDCOMPAT: | |
717 | case SO_BSDCOMPAT: | 714 | sock_warn_obsolete_bsdism("getsockopt"); |
718 | sock_warn_obsolete_bsdism("getsockopt"); | 715 | break; |
719 | break; | 716 | |
720 | 717 | case SO_TIMESTAMP: | |
721 | case SO_TIMESTAMP: | 718 | v.val = sock_flag(sk, SOCK_RCVTSTAMP); |
722 | v.val = sock_flag(sk, SOCK_RCVTSTAMP); | 719 | break; |
723 | break; | 720 | |
724 | 721 | case SO_RCVTIMEO: | |
725 | case SO_RCVTIMEO: | 722 | lv=sizeof(struct timeval); |
726 | lv=sizeof(struct timeval); | 723 | if (sk->sk_rcvtimeo == MAX_SCHEDULE_TIMEOUT) { |
727 | if (sk->sk_rcvtimeo == MAX_SCHEDULE_TIMEOUT) { | 724 | v.tm.tv_sec = 0; |
728 | v.tm.tv_sec = 0; | 725 | v.tm.tv_usec = 0; |
729 | v.tm.tv_usec = 0; | 726 | } else { |
730 | } else { | 727 | v.tm.tv_sec = sk->sk_rcvtimeo / HZ; |
731 | v.tm.tv_sec = sk->sk_rcvtimeo / HZ; | 728 | v.tm.tv_usec = ((sk->sk_rcvtimeo % HZ) * 1000000) / HZ; |
732 | v.tm.tv_usec = ((sk->sk_rcvtimeo % HZ) * 1000000) / HZ; | 729 | } |
733 | } | 730 | break; |
734 | break; | 731 | |
732 | case SO_SNDTIMEO: | ||
733 | lv=sizeof(struct timeval); | ||
734 | if (sk->sk_sndtimeo == MAX_SCHEDULE_TIMEOUT) { | ||
735 | v.tm.tv_sec = 0; | ||
736 | v.tm.tv_usec = 0; | ||
737 | } else { | ||
738 | v.tm.tv_sec = sk->sk_sndtimeo / HZ; | ||
739 | v.tm.tv_usec = ((sk->sk_sndtimeo % HZ) * 1000000) / HZ; | ||
740 | } | ||
741 | break; | ||
735 | 742 | ||
736 | case SO_SNDTIMEO: | 743 | case SO_RCVLOWAT: |
737 | lv=sizeof(struct timeval); | 744 | v.val = sk->sk_rcvlowat; |
738 | if (sk->sk_sndtimeo == MAX_SCHEDULE_TIMEOUT) { | 745 | break; |
739 | v.tm.tv_sec = 0; | ||
740 | v.tm.tv_usec = 0; | ||
741 | } else { | ||
742 | v.tm.tv_sec = sk->sk_sndtimeo / HZ; | ||
743 | v.tm.tv_usec = ((sk->sk_sndtimeo % HZ) * 1000000) / HZ; | ||
744 | } | ||
745 | break; | ||
746 | 746 | ||
747 | case SO_RCVLOWAT: | 747 | case SO_SNDLOWAT: |
748 | v.val = sk->sk_rcvlowat; | 748 | v.val=1; |
749 | break; | 749 | break; |
750 | 750 | ||
751 | case SO_SNDLOWAT: | 751 | case SO_PASSCRED: |
752 | v.val=1; | 752 | v.val = test_bit(SOCK_PASSCRED, &sock->flags) ? 1 : 0; |
753 | break; | 753 | break; |
754 | 754 | ||
755 | case SO_PASSCRED: | 755 | case SO_PEERCRED: |
756 | v.val = test_bit(SOCK_PASSCRED, &sock->flags) ? 1 : 0; | 756 | if (len > sizeof(sk->sk_peercred)) |
757 | break; | 757 | len = sizeof(sk->sk_peercred); |
758 | if (copy_to_user(optval, &sk->sk_peercred, len)) | ||
759 | return -EFAULT; | ||
760 | goto lenout; | ||
758 | 761 | ||
759 | case SO_PEERCRED: | 762 | case SO_PEERNAME: |
760 | if (len > sizeof(sk->sk_peercred)) | 763 | { |
761 | len = sizeof(sk->sk_peercred); | 764 | char address[128]; |
762 | if (copy_to_user(optval, &sk->sk_peercred, len)) | 765 | |
763 | return -EFAULT; | 766 | if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2)) |
764 | goto lenout; | 767 | return -ENOTCONN; |
765 | 768 | if (lv < len) | |
766 | case SO_PEERNAME: | 769 | return -EINVAL; |
767 | { | 770 | if (copy_to_user(optval, address, len)) |
768 | char address[128]; | 771 | return -EFAULT; |
769 | 772 | goto lenout; | |
770 | if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2)) | 773 | } |
771 | return -ENOTCONN; | ||
772 | if (lv < len) | ||
773 | return -EINVAL; | ||
774 | if (copy_to_user(optval, address, len)) | ||
775 | return -EFAULT; | ||
776 | goto lenout; | ||
777 | } | ||
778 | 774 | ||
779 | /* Dubious BSD thing... Probably nobody even uses it, but | 775 | /* Dubious BSD thing... Probably nobody even uses it, but |
780 | * the UNIX standard wants it for whatever reason... -DaveM | 776 | * the UNIX standard wants it for whatever reason... -DaveM |
781 | */ | 777 | */ |
782 | case SO_ACCEPTCONN: | 778 | case SO_ACCEPTCONN: |
783 | v.val = sk->sk_state == TCP_LISTEN; | 779 | v.val = sk->sk_state == TCP_LISTEN; |
784 | break; | 780 | break; |
785 | 781 | ||
786 | case SO_PASSSEC: | 782 | case SO_PASSSEC: |
787 | v.val = test_bit(SOCK_PASSSEC, &sock->flags) ? 1 : 0; | 783 | v.val = test_bit(SOCK_PASSSEC, &sock->flags) ? 1 : 0; |
788 | break; | 784 | break; |
789 | 785 | ||
790 | case SO_PEERSEC: | 786 | case SO_PEERSEC: |
791 | return security_socket_getpeersec_stream(sock, optval, optlen, len); | 787 | return security_socket_getpeersec_stream(sock, optval, optlen, len); |
792 | 788 | ||
793 | default: | 789 | default: |
794 | return(-ENOPROTOOPT); | 790 | return -ENOPROTOOPT; |
795 | } | 791 | } |
792 | |||
796 | if (len > lv) | 793 | if (len > lv) |
797 | len = lv; | 794 | len = lv; |
798 | if (copy_to_user(optval, &v, len)) | 795 | if (copy_to_user(optval, &v, len)) |
@@ -1220,13 +1217,13 @@ static void __lock_sock(struct sock *sk) | |||
1220 | { | 1217 | { |
1221 | DEFINE_WAIT(wait); | 1218 | DEFINE_WAIT(wait); |
1222 | 1219 | ||
1223 | for(;;) { | 1220 | for (;;) { |
1224 | prepare_to_wait_exclusive(&sk->sk_lock.wq, &wait, | 1221 | prepare_to_wait_exclusive(&sk->sk_lock.wq, &wait, |
1225 | TASK_UNINTERRUPTIBLE); | 1222 | TASK_UNINTERRUPTIBLE); |
1226 | spin_unlock_bh(&sk->sk_lock.slock); | 1223 | spin_unlock_bh(&sk->sk_lock.slock); |
1227 | schedule(); | 1224 | schedule(); |
1228 | spin_lock_bh(&sk->sk_lock.slock); | 1225 | spin_lock_bh(&sk->sk_lock.slock); |
1229 | if(!sock_owned_by_user(sk)) | 1226 | if (!sock_owned_by_user(sk)) |
1230 | break; | 1227 | break; |
1231 | } | 1228 | } |
1232 | finish_wait(&sk->sk_lock.wq, &wait); | 1229 | finish_wait(&sk->sk_lock.wq, &wait); |
@@ -1258,7 +1255,7 @@ static void __release_sock(struct sock *sk) | |||
1258 | } while (skb != NULL); | 1255 | } while (skb != NULL); |
1259 | 1256 | ||
1260 | bh_lock_sock(sk); | 1257 | bh_lock_sock(sk); |
1261 | } while((skb = sk->sk_backlog.head) != NULL); | 1258 | } while ((skb = sk->sk_backlog.head) != NULL); |
1262 | } | 1259 | } |
1263 | 1260 | ||
1264 | /** | 1261 | /** |
@@ -1420,7 +1417,7 @@ static void sock_def_write_space(struct sock *sk) | |||
1420 | /* Do not wake up a writer until he can make "significant" | 1417 | /* Do not wake up a writer until he can make "significant" |
1421 | * progress. --DaveM | 1418 | * progress. --DaveM |
1422 | */ | 1419 | */ |
1423 | if((atomic_read(&sk->sk_wmem_alloc) << 1) <= sk->sk_sndbuf) { | 1420 | if ((atomic_read(&sk->sk_wmem_alloc) << 1) <= sk->sk_sndbuf) { |
1424 | if (sk->sk_sleep && waitqueue_active(sk->sk_sleep)) | 1421 | if (sk->sk_sleep && waitqueue_active(sk->sk_sleep)) |
1425 | wake_up_interruptible(sk->sk_sleep); | 1422 | wake_up_interruptible(sk->sk_sleep); |
1426 | 1423 | ||
@@ -1482,8 +1479,7 @@ void sock_init_data(struct socket *sock, struct sock *sk) | |||
1482 | 1479 | ||
1483 | sock_set_flag(sk, SOCK_ZAPPED); | 1480 | sock_set_flag(sk, SOCK_ZAPPED); |
1484 | 1481 | ||
1485 | if(sock) | 1482 | if (sock) { |
1486 | { | ||
1487 | sk->sk_type = sock->type; | 1483 | sk->sk_type = sock->type; |
1488 | sk->sk_sleep = &sock->wait; | 1484 | sk->sk_sleep = &sock->wait; |
1489 | sock->sk = sk; | 1485 | sock->sk = sk; |