diff options
author | Arnd Bergmann <arnd@arndb.de> | 2009-11-07 02:00:29 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-11-07 02:00:29 -0500 |
commit | 7a229387d317df525ebd19e146493db7f2694b8b (patch) | |
tree | bb3c730da54ca7bdc5f731a96eeb1caf17a5801b /net/socket.c | |
parent | 9646e7ce3d1955478aa0573b36c151ab4b649486 (diff) |
net: copy socket ioctl code to net/socket.h
This makes an identical copy of the socket compat_ioctl code
from fs/compat_ioctl.c to net/socket.c, as a preparation
for moving the functionality in a way that can be easily
reviewed.
The code is hidden inside of #if 0 and gets activated in the
patch that will make it work.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/socket.c')
-rw-r--r-- | net/socket.c | 716 |
1 files changed, 716 insertions, 0 deletions
diff --git a/net/socket.c b/net/socket.c index 4f3e0f0c156b..344bd230b831 100644 --- a/net/socket.c +++ b/net/socket.c | |||
@@ -2459,6 +2459,722 @@ void socket_seq_show(struct seq_file *seq) | |||
2459 | #endif /* CONFIG_PROC_FS */ | 2459 | #endif /* CONFIG_PROC_FS */ |
2460 | 2460 | ||
2461 | #ifdef CONFIG_COMPAT | 2461 | #ifdef CONFIG_COMPAT |
2462 | #if 0 | ||
2463 | static int do_siocgstamp(unsigned int fd, unsigned int cmd, unsigned long arg) | ||
2464 | { | ||
2465 | struct compat_timeval __user *up = compat_ptr(arg); | ||
2466 | mm_segment_t old_fs = get_fs(); | ||
2467 | struct timeval ktv; | ||
2468 | int err; | ||
2469 | |||
2470 | set_fs(KERNEL_DS); | ||
2471 | err = sys_ioctl(fd, cmd, (unsigned long)&ktv); | ||
2472 | set_fs(old_fs); | ||
2473 | if (!err) { | ||
2474 | err = put_user(ktv.tv_sec, &up->tv_sec); | ||
2475 | err |= __put_user(ktv.tv_usec, &up->tv_usec); | ||
2476 | } | ||
2477 | return err; | ||
2478 | } | ||
2479 | |||
2480 | static int do_siocgstampns(unsigned int fd, unsigned int cmd, unsigned long arg) | ||
2481 | { | ||
2482 | struct compat_timespec __user *up = compat_ptr(arg); | ||
2483 | mm_segment_t old_fs = get_fs(); | ||
2484 | struct timespec kts; | ||
2485 | int err; | ||
2486 | |||
2487 | set_fs(KERNEL_DS); | ||
2488 | err = sys_ioctl(fd, cmd, (unsigned long)&kts); | ||
2489 | set_fs(old_fs); | ||
2490 | if (!err) { | ||
2491 | err = put_user(kts.tv_sec, &up->tv_sec); | ||
2492 | err |= __put_user(kts.tv_nsec, &up->tv_nsec); | ||
2493 | } | ||
2494 | return err; | ||
2495 | } | ||
2496 | |||
2497 | struct ifmap32 { | ||
2498 | compat_ulong_t mem_start; | ||
2499 | compat_ulong_t mem_end; | ||
2500 | unsigned short base_addr; | ||
2501 | unsigned char irq; | ||
2502 | unsigned char dma; | ||
2503 | unsigned char port; | ||
2504 | }; | ||
2505 | |||
2506 | struct ifreq32 { | ||
2507 | #define IFHWADDRLEN 6 | ||
2508 | #define IFNAMSIZ 16 | ||
2509 | union { | ||
2510 | char ifrn_name[IFNAMSIZ]; /* if name, e.g. "en0" */ | ||
2511 | } ifr_ifrn; | ||
2512 | union { | ||
2513 | struct sockaddr ifru_addr; | ||
2514 | struct sockaddr ifru_dstaddr; | ||
2515 | struct sockaddr ifru_broadaddr; | ||
2516 | struct sockaddr ifru_netmask; | ||
2517 | struct sockaddr ifru_hwaddr; | ||
2518 | short ifru_flags; | ||
2519 | compat_int_t ifru_ivalue; | ||
2520 | compat_int_t ifru_mtu; | ||
2521 | struct ifmap32 ifru_map; | ||
2522 | char ifru_slave[IFNAMSIZ]; /* Just fits the size */ | ||
2523 | char ifru_newname[IFNAMSIZ]; | ||
2524 | compat_caddr_t ifru_data; | ||
2525 | /* XXXX? ifru_settings should be here */ | ||
2526 | } ifr_ifru; | ||
2527 | }; | ||
2528 | |||
2529 | struct ifconf32 { | ||
2530 | compat_int_t ifc_len; /* size of buffer */ | ||
2531 | compat_caddr_t ifcbuf; | ||
2532 | }; | ||
2533 | |||
2534 | static int dev_ifname32(unsigned int fd, unsigned int cmd, unsigned long arg) | ||
2535 | { | ||
2536 | struct ifreq __user *uifr; | ||
2537 | int err; | ||
2538 | |||
2539 | uifr = compat_alloc_user_space(sizeof(struct ifreq)); | ||
2540 | if (copy_in_user(uifr, compat_ptr(arg), sizeof(struct ifreq32))) | ||
2541 | return -EFAULT; | ||
2542 | |||
2543 | err = sys_ioctl(fd, SIOCGIFNAME, (unsigned long)uifr); | ||
2544 | if (err) | ||
2545 | return err; | ||
2546 | |||
2547 | if (copy_in_user(compat_ptr(arg), uifr, sizeof(struct ifreq32))) | ||
2548 | return -EFAULT; | ||
2549 | |||
2550 | return 0; | ||
2551 | } | ||
2552 | |||
2553 | static int dev_ifconf(unsigned int fd, unsigned int cmd, unsigned long arg) | ||
2554 | { | ||
2555 | struct ifconf32 ifc32; | ||
2556 | struct ifconf ifc; | ||
2557 | struct ifconf __user *uifc; | ||
2558 | struct ifreq32 __user *ifr32; | ||
2559 | struct ifreq __user *ifr; | ||
2560 | unsigned int i, j; | ||
2561 | int err; | ||
2562 | |||
2563 | if (copy_from_user(&ifc32, compat_ptr(arg), sizeof(struct ifconf32))) | ||
2564 | return -EFAULT; | ||
2565 | |||
2566 | if (ifc32.ifcbuf == 0) { | ||
2567 | ifc32.ifc_len = 0; | ||
2568 | ifc.ifc_len = 0; | ||
2569 | ifc.ifc_req = NULL; | ||
2570 | uifc = compat_alloc_user_space(sizeof(struct ifconf)); | ||
2571 | } else { | ||
2572 | size_t len =((ifc32.ifc_len / sizeof (struct ifreq32)) + 1) * | ||
2573 | sizeof (struct ifreq); | ||
2574 | uifc = compat_alloc_user_space(sizeof(struct ifconf) + len); | ||
2575 | ifc.ifc_len = len; | ||
2576 | ifr = ifc.ifc_req = (void __user *)(uifc + 1); | ||
2577 | ifr32 = compat_ptr(ifc32.ifcbuf); | ||
2578 | for (i = 0; i < ifc32.ifc_len; i += sizeof (struct ifreq32)) { | ||
2579 | if (copy_in_user(ifr, ifr32, sizeof(struct ifreq32))) | ||
2580 | return -EFAULT; | ||
2581 | ifr++; | ||
2582 | ifr32++; | ||
2583 | } | ||
2584 | } | ||
2585 | if (copy_to_user(uifc, &ifc, sizeof(struct ifconf))) | ||
2586 | return -EFAULT; | ||
2587 | |||
2588 | err = sys_ioctl (fd, SIOCGIFCONF, (unsigned long)uifc); | ||
2589 | if (err) | ||
2590 | return err; | ||
2591 | |||
2592 | if (copy_from_user(&ifc, uifc, sizeof(struct ifconf))) | ||
2593 | return -EFAULT; | ||
2594 | |||
2595 | ifr = ifc.ifc_req; | ||
2596 | ifr32 = compat_ptr(ifc32.ifcbuf); | ||
2597 | for (i = 0, j = 0; | ||
2598 | i + sizeof (struct ifreq32) <= ifc32.ifc_len && j < ifc.ifc_len; | ||
2599 | i += sizeof (struct ifreq32), j += sizeof (struct ifreq)) { | ||
2600 | if (copy_in_user(ifr32, ifr, sizeof (struct ifreq32))) | ||
2601 | return -EFAULT; | ||
2602 | ifr32++; | ||
2603 | ifr++; | ||
2604 | } | ||
2605 | |||
2606 | if (ifc32.ifcbuf == 0) { | ||
2607 | /* Translate from 64-bit structure multiple to | ||
2608 | * a 32-bit one. | ||
2609 | */ | ||
2610 | i = ifc.ifc_len; | ||
2611 | i = ((i / sizeof(struct ifreq)) * sizeof(struct ifreq32)); | ||
2612 | ifc32.ifc_len = i; | ||
2613 | } else { | ||
2614 | ifc32.ifc_len = i; | ||
2615 | } | ||
2616 | if (copy_to_user(compat_ptr(arg), &ifc32, sizeof(struct ifconf32))) | ||
2617 | return -EFAULT; | ||
2618 | |||
2619 | return 0; | ||
2620 | } | ||
2621 | |||
2622 | static int ethtool_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) | ||
2623 | { | ||
2624 | struct ifreq __user *ifr; | ||
2625 | struct ifreq32 __user *ifr32; | ||
2626 | u32 data; | ||
2627 | void __user *datap; | ||
2628 | |||
2629 | ifr = compat_alloc_user_space(sizeof(*ifr)); | ||
2630 | ifr32 = compat_ptr(arg); | ||
2631 | |||
2632 | if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ)) | ||
2633 | return -EFAULT; | ||
2634 | |||
2635 | if (get_user(data, &ifr32->ifr_ifru.ifru_data)) | ||
2636 | return -EFAULT; | ||
2637 | |||
2638 | datap = compat_ptr(data); | ||
2639 | if (put_user(datap, &ifr->ifr_ifru.ifru_data)) | ||
2640 | return -EFAULT; | ||
2641 | |||
2642 | return sys_ioctl(fd, cmd, (unsigned long) ifr); | ||
2643 | } | ||
2644 | |||
2645 | static int bond_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) | ||
2646 | { | ||
2647 | struct ifreq kifr; | ||
2648 | struct ifreq __user *uifr; | ||
2649 | struct ifreq32 __user *ifr32 = compat_ptr(arg); | ||
2650 | mm_segment_t old_fs; | ||
2651 | int err; | ||
2652 | u32 data; | ||
2653 | void __user *datap; | ||
2654 | |||
2655 | switch (cmd) { | ||
2656 | case SIOCBONDENSLAVE: | ||
2657 | case SIOCBONDRELEASE: | ||
2658 | case SIOCBONDSETHWADDR: | ||
2659 | case SIOCBONDCHANGEACTIVE: | ||
2660 | if (copy_from_user(&kifr, ifr32, sizeof(struct ifreq32))) | ||
2661 | return -EFAULT; | ||
2662 | |||
2663 | old_fs = get_fs(); | ||
2664 | set_fs (KERNEL_DS); | ||
2665 | err = sys_ioctl (fd, cmd, (unsigned long)&kifr); | ||
2666 | set_fs (old_fs); | ||
2667 | |||
2668 | return err; | ||
2669 | case SIOCBONDSLAVEINFOQUERY: | ||
2670 | case SIOCBONDINFOQUERY: | ||
2671 | uifr = compat_alloc_user_space(sizeof(*uifr)); | ||
2672 | if (copy_in_user(&uifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ)) | ||
2673 | return -EFAULT; | ||
2674 | |||
2675 | if (get_user(data, &ifr32->ifr_ifru.ifru_data)) | ||
2676 | return -EFAULT; | ||
2677 | |||
2678 | datap = compat_ptr(data); | ||
2679 | if (put_user(datap, &uifr->ifr_ifru.ifru_data)) | ||
2680 | return -EFAULT; | ||
2681 | |||
2682 | return sys_ioctl (fd, cmd, (unsigned long)uifr); | ||
2683 | default: | ||
2684 | return -EINVAL; | ||
2685 | }; | ||
2686 | } | ||
2687 | |||
2688 | static int siocdevprivate_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) | ||
2689 | { | ||
2690 | struct ifreq __user *u_ifreq64; | ||
2691 | struct ifreq32 __user *u_ifreq32 = compat_ptr(arg); | ||
2692 | char tmp_buf[IFNAMSIZ]; | ||
2693 | void __user *data64; | ||
2694 | u32 data32; | ||
2695 | |||
2696 | if (copy_from_user(&tmp_buf[0], &(u_ifreq32->ifr_ifrn.ifrn_name[0]), | ||
2697 | IFNAMSIZ)) | ||
2698 | return -EFAULT; | ||
2699 | if (__get_user(data32, &u_ifreq32->ifr_ifru.ifru_data)) | ||
2700 | return -EFAULT; | ||
2701 | data64 = compat_ptr(data32); | ||
2702 | |||
2703 | u_ifreq64 = compat_alloc_user_space(sizeof(*u_ifreq64)); | ||
2704 | |||
2705 | /* Don't check these user accesses, just let that get trapped | ||
2706 | * in the ioctl handler instead. | ||
2707 | */ | ||
2708 | if (copy_to_user(&u_ifreq64->ifr_ifrn.ifrn_name[0], &tmp_buf[0], | ||
2709 | IFNAMSIZ)) | ||
2710 | return -EFAULT; | ||
2711 | if (__put_user(data64, &u_ifreq64->ifr_ifru.ifru_data)) | ||
2712 | return -EFAULT; | ||
2713 | |||
2714 | return sys_ioctl(fd, cmd, (unsigned long) u_ifreq64); | ||
2715 | } | ||
2716 | |||
2717 | static int dev_ifsioc(unsigned int fd, unsigned int cmd, unsigned long arg) | ||
2718 | { | ||
2719 | struct ifreq ifr; | ||
2720 | struct ifreq32 __user *uifr32; | ||
2721 | struct ifmap32 __user *uifmap32; | ||
2722 | mm_segment_t old_fs; | ||
2723 | int err; | ||
2724 | |||
2725 | uifr32 = compat_ptr(arg); | ||
2726 | uifmap32 = &uifr32->ifr_ifru.ifru_map; | ||
2727 | switch (cmd) { | ||
2728 | case SIOCSIFMAP: | ||
2729 | err = copy_from_user(&ifr, uifr32, sizeof(ifr.ifr_name)); | ||
2730 | err |= __get_user(ifr.ifr_map.mem_start, &uifmap32->mem_start); | ||
2731 | err |= __get_user(ifr.ifr_map.mem_end, &uifmap32->mem_end); | ||
2732 | err |= __get_user(ifr.ifr_map.base_addr, &uifmap32->base_addr); | ||
2733 | err |= __get_user(ifr.ifr_map.irq, &uifmap32->irq); | ||
2734 | err |= __get_user(ifr.ifr_map.dma, &uifmap32->dma); | ||
2735 | err |= __get_user(ifr.ifr_map.port, &uifmap32->port); | ||
2736 | if (err) | ||
2737 | return -EFAULT; | ||
2738 | break; | ||
2739 | case SIOCSHWTSTAMP: | ||
2740 | if (copy_from_user(&ifr, uifr32, sizeof(*uifr32))) | ||
2741 | return -EFAULT; | ||
2742 | ifr.ifr_data = compat_ptr(uifr32->ifr_ifru.ifru_data); | ||
2743 | break; | ||
2744 | default: | ||
2745 | if (copy_from_user(&ifr, uifr32, sizeof(*uifr32))) | ||
2746 | return -EFAULT; | ||
2747 | break; | ||
2748 | } | ||
2749 | old_fs = get_fs(); | ||
2750 | set_fs (KERNEL_DS); | ||
2751 | err = sys_ioctl (fd, cmd, (unsigned long)&ifr); | ||
2752 | set_fs (old_fs); | ||
2753 | if (!err) { | ||
2754 | switch (cmd) { | ||
2755 | case SIOCGIFFLAGS: | ||
2756 | case SIOCGIFMETRIC: | ||
2757 | case SIOCGIFMTU: | ||
2758 | case SIOCGIFMEM: | ||
2759 | case SIOCGIFHWADDR: | ||
2760 | case SIOCGIFINDEX: | ||
2761 | case SIOCGIFADDR: | ||
2762 | case SIOCGIFBRDADDR: | ||
2763 | case SIOCGIFDSTADDR: | ||
2764 | case SIOCGIFNETMASK: | ||
2765 | case SIOCGIFTXQLEN: | ||
2766 | if (copy_to_user(uifr32, &ifr, sizeof(*uifr32))) | ||
2767 | return -EFAULT; | ||
2768 | break; | ||
2769 | case SIOCGIFMAP: | ||
2770 | err = copy_to_user(uifr32, &ifr, sizeof(ifr.ifr_name)); | ||
2771 | err |= __put_user(ifr.ifr_map.mem_start, &uifmap32->mem_start); | ||
2772 | err |= __put_user(ifr.ifr_map.mem_end, &uifmap32->mem_end); | ||
2773 | err |= __put_user(ifr.ifr_map.base_addr, &uifmap32->base_addr); | ||
2774 | err |= __put_user(ifr.ifr_map.irq, &uifmap32->irq); | ||
2775 | err |= __put_user(ifr.ifr_map.dma, &uifmap32->dma); | ||
2776 | err |= __put_user(ifr.ifr_map.port, &uifmap32->port); | ||
2777 | if (err) | ||
2778 | err = -EFAULT; | ||
2779 | break; | ||
2780 | } | ||
2781 | } | ||
2782 | return err; | ||
2783 | } | ||
2784 | |||
2785 | struct rtentry32 { | ||
2786 | u32 rt_pad1; | ||
2787 | struct sockaddr rt_dst; /* target address */ | ||
2788 | struct sockaddr rt_gateway; /* gateway addr (RTF_GATEWAY) */ | ||
2789 | struct sockaddr rt_genmask; /* target network mask (IP) */ | ||
2790 | unsigned short rt_flags; | ||
2791 | short rt_pad2; | ||
2792 | u32 rt_pad3; | ||
2793 | unsigned char rt_tos; | ||
2794 | unsigned char rt_class; | ||
2795 | short rt_pad4; | ||
2796 | short rt_metric; /* +1 for binary compatibility! */ | ||
2797 | /* char * */ u32 rt_dev; /* forcing the device at add */ | ||
2798 | u32 rt_mtu; /* per route MTU/Window */ | ||
2799 | u32 rt_window; /* Window clamping */ | ||
2800 | unsigned short rt_irtt; /* Initial RTT */ | ||
2801 | }; | ||
2802 | |||
2803 | struct in6_rtmsg32 { | ||
2804 | struct in6_addr rtmsg_dst; | ||
2805 | struct in6_addr rtmsg_src; | ||
2806 | struct in6_addr rtmsg_gateway; | ||
2807 | u32 rtmsg_type; | ||
2808 | u16 rtmsg_dst_len; | ||
2809 | u16 rtmsg_src_len; | ||
2810 | u32 rtmsg_metric; | ||
2811 | u32 rtmsg_info; | ||
2812 | u32 rtmsg_flags; | ||
2813 | s32 rtmsg_ifindex; | ||
2814 | }; | ||
2815 | |||
2816 | static int routing_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) | ||
2817 | { | ||
2818 | int ret; | ||
2819 | void *r = NULL; | ||
2820 | struct in6_rtmsg r6; | ||
2821 | struct rtentry r4; | ||
2822 | char devname[16]; | ||
2823 | u32 rtdev; | ||
2824 | mm_segment_t old_fs = get_fs(); | ||
2825 | |||
2826 | struct socket *mysock = sockfd_lookup(fd, &ret); | ||
2827 | |||
2828 | if (mysock && mysock->sk && mysock->sk->sk_family == AF_INET6) { /* ipv6 */ | ||
2829 | struct in6_rtmsg32 __user *ur6 = compat_ptr(arg); | ||
2830 | ret = copy_from_user (&r6.rtmsg_dst, &(ur6->rtmsg_dst), | ||
2831 | 3 * sizeof(struct in6_addr)); | ||
2832 | ret |= __get_user (r6.rtmsg_type, &(ur6->rtmsg_type)); | ||
2833 | ret |= __get_user (r6.rtmsg_dst_len, &(ur6->rtmsg_dst_len)); | ||
2834 | ret |= __get_user (r6.rtmsg_src_len, &(ur6->rtmsg_src_len)); | ||
2835 | ret |= __get_user (r6.rtmsg_metric, &(ur6->rtmsg_metric)); | ||
2836 | ret |= __get_user (r6.rtmsg_info, &(ur6->rtmsg_info)); | ||
2837 | ret |= __get_user (r6.rtmsg_flags, &(ur6->rtmsg_flags)); | ||
2838 | ret |= __get_user (r6.rtmsg_ifindex, &(ur6->rtmsg_ifindex)); | ||
2839 | |||
2840 | r = (void *) &r6; | ||
2841 | } else { /* ipv4 */ | ||
2842 | struct rtentry32 __user *ur4 = compat_ptr(arg); | ||
2843 | ret = copy_from_user (&r4.rt_dst, &(ur4->rt_dst), | ||
2844 | 3 * sizeof(struct sockaddr)); | ||
2845 | ret |= __get_user (r4.rt_flags, &(ur4->rt_flags)); | ||
2846 | ret |= __get_user (r4.rt_metric, &(ur4->rt_metric)); | ||
2847 | ret |= __get_user (r4.rt_mtu, &(ur4->rt_mtu)); | ||
2848 | ret |= __get_user (r4.rt_window, &(ur4->rt_window)); | ||
2849 | ret |= __get_user (r4.rt_irtt, &(ur4->rt_irtt)); | ||
2850 | ret |= __get_user (rtdev, &(ur4->rt_dev)); | ||
2851 | if (rtdev) { | ||
2852 | ret |= copy_from_user (devname, compat_ptr(rtdev), 15); | ||
2853 | r4.rt_dev = devname; devname[15] = 0; | ||
2854 | } else | ||
2855 | r4.rt_dev = NULL; | ||
2856 | |||
2857 | r = (void *) &r4; | ||
2858 | } | ||
2859 | |||
2860 | if (ret) { | ||
2861 | ret = -EFAULT; | ||
2862 | goto out; | ||
2863 | } | ||
2864 | |||
2865 | set_fs (KERNEL_DS); | ||
2866 | ret = sys_ioctl (fd, cmd, (unsigned long) r); | ||
2867 | set_fs (old_fs); | ||
2868 | |||
2869 | out: | ||
2870 | if (mysock) | ||
2871 | sockfd_put(mysock); | ||
2872 | |||
2873 | return ret; | ||
2874 | } | ||
2875 | |||
2876 | /* Since old style bridge ioctl's endup using SIOCDEVPRIVATE | ||
2877 | * for some operations; this forces use of the newer bridge-utils that | ||
2878 | * use compatiable ioctls | ||
2879 | */ | ||
2880 | static int old_bridge_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) | ||
2881 | { | ||
2882 | u32 tmp; | ||
2883 | |||
2884 | if (get_user(tmp, (u32 __user *) arg)) | ||
2885 | return -EFAULT; | ||
2886 | if (tmp == BRCTL_GET_VERSION) | ||
2887 | return BRCTL_VERSION + 1; | ||
2888 | return -EINVAL; | ||
2889 | } | ||
2890 | |||
2891 | struct atmif_sioc32 { | ||
2892 | compat_int_t number; | ||
2893 | compat_int_t length; | ||
2894 | compat_caddr_t arg; | ||
2895 | }; | ||
2896 | |||
2897 | struct atm_iobuf32 { | ||
2898 | compat_int_t length; | ||
2899 | compat_caddr_t buffer; | ||
2900 | }; | ||
2901 | |||
2902 | #define ATM_GETLINKRATE32 _IOW('a', ATMIOC_ITF+1, struct atmif_sioc32) | ||
2903 | #define ATM_GETNAMES32 _IOW('a', ATMIOC_ITF+3, struct atm_iobuf32) | ||
2904 | #define ATM_GETTYPE32 _IOW('a', ATMIOC_ITF+4, struct atmif_sioc32) | ||
2905 | #define ATM_GETESI32 _IOW('a', ATMIOC_ITF+5, struct atmif_sioc32) | ||
2906 | #define ATM_GETADDR32 _IOW('a', ATMIOC_ITF+6, struct atmif_sioc32) | ||
2907 | #define ATM_RSTADDR32 _IOW('a', ATMIOC_ITF+7, struct atmif_sioc32) | ||
2908 | #define ATM_ADDADDR32 _IOW('a', ATMIOC_ITF+8, struct atmif_sioc32) | ||
2909 | #define ATM_DELADDR32 _IOW('a', ATMIOC_ITF+9, struct atmif_sioc32) | ||
2910 | #define ATM_GETCIRANGE32 _IOW('a', ATMIOC_ITF+10, struct atmif_sioc32) | ||
2911 | #define ATM_SETCIRANGE32 _IOW('a', ATMIOC_ITF+11, struct atmif_sioc32) | ||
2912 | #define ATM_SETESI32 _IOW('a', ATMIOC_ITF+12, struct atmif_sioc32) | ||
2913 | #define ATM_SETESIF32 _IOW('a', ATMIOC_ITF+13, struct atmif_sioc32) | ||
2914 | #define ATM_GETSTAT32 _IOW('a', ATMIOC_SARCOM+0, struct atmif_sioc32) | ||
2915 | #define ATM_GETSTATZ32 _IOW('a', ATMIOC_SARCOM+1, struct atmif_sioc32) | ||
2916 | #define ATM_GETLOOP32 _IOW('a', ATMIOC_SARCOM+2, struct atmif_sioc32) | ||
2917 | #define ATM_SETLOOP32 _IOW('a', ATMIOC_SARCOM+3, struct atmif_sioc32) | ||
2918 | #define ATM_QUERYLOOP32 _IOW('a', ATMIOC_SARCOM+4, struct atmif_sioc32) | ||
2919 | |||
2920 | static struct { | ||
2921 | unsigned int cmd32; | ||
2922 | unsigned int cmd; | ||
2923 | } atm_ioctl_map[] = { | ||
2924 | { ATM_GETLINKRATE32, ATM_GETLINKRATE }, | ||
2925 | { ATM_GETNAMES32, ATM_GETNAMES }, | ||
2926 | { ATM_GETTYPE32, ATM_GETTYPE }, | ||
2927 | { ATM_GETESI32, ATM_GETESI }, | ||
2928 | { ATM_GETADDR32, ATM_GETADDR }, | ||
2929 | { ATM_RSTADDR32, ATM_RSTADDR }, | ||
2930 | { ATM_ADDADDR32, ATM_ADDADDR }, | ||
2931 | { ATM_DELADDR32, ATM_DELADDR }, | ||
2932 | { ATM_GETCIRANGE32, ATM_GETCIRANGE }, | ||
2933 | { ATM_SETCIRANGE32, ATM_SETCIRANGE }, | ||
2934 | { ATM_SETESI32, ATM_SETESI }, | ||
2935 | { ATM_SETESIF32, ATM_SETESIF }, | ||
2936 | { ATM_GETSTAT32, ATM_GETSTAT }, | ||
2937 | { ATM_GETSTATZ32, ATM_GETSTATZ }, | ||
2938 | { ATM_GETLOOP32, ATM_GETLOOP }, | ||
2939 | { ATM_SETLOOP32, ATM_SETLOOP }, | ||
2940 | { ATM_QUERYLOOP32, ATM_QUERYLOOP } | ||
2941 | }; | ||
2942 | |||
2943 | #define NR_ATM_IOCTL ARRAY_SIZE(atm_ioctl_map) | ||
2944 | |||
2945 | static int do_atm_iobuf(unsigned int fd, unsigned int cmd, unsigned long arg) | ||
2946 | { | ||
2947 | struct atm_iobuf __user *iobuf; | ||
2948 | struct atm_iobuf32 __user *iobuf32; | ||
2949 | u32 data; | ||
2950 | void __user *datap; | ||
2951 | int len, err; | ||
2952 | |||
2953 | iobuf = compat_alloc_user_space(sizeof(*iobuf)); | ||
2954 | iobuf32 = compat_ptr(arg); | ||
2955 | |||
2956 | if (get_user(len, &iobuf32->length) || | ||
2957 | get_user(data, &iobuf32->buffer)) | ||
2958 | return -EFAULT; | ||
2959 | datap = compat_ptr(data); | ||
2960 | if (put_user(len, &iobuf->length) || | ||
2961 | put_user(datap, &iobuf->buffer)) | ||
2962 | return -EFAULT; | ||
2963 | |||
2964 | err = sys_ioctl(fd, cmd, (unsigned long)iobuf); | ||
2965 | |||
2966 | if (!err) { | ||
2967 | if (copy_in_user(&iobuf32->length, &iobuf->length, | ||
2968 | sizeof(int))) | ||
2969 | err = -EFAULT; | ||
2970 | } | ||
2971 | |||
2972 | return err; | ||
2973 | } | ||
2974 | |||
2975 | static int do_atmif_sioc(unsigned int fd, unsigned int cmd, unsigned long arg) | ||
2976 | { | ||
2977 | struct atmif_sioc __user *sioc; | ||
2978 | struct atmif_sioc32 __user *sioc32; | ||
2979 | u32 data; | ||
2980 | void __user *datap; | ||
2981 | int err; | ||
2982 | |||
2983 | sioc = compat_alloc_user_space(sizeof(*sioc)); | ||
2984 | sioc32 = compat_ptr(arg); | ||
2985 | |||
2986 | if (copy_in_user(&sioc->number, &sioc32->number, 2 * sizeof(int)) || | ||
2987 | get_user(data, &sioc32->arg)) | ||
2988 | return -EFAULT; | ||
2989 | datap = compat_ptr(data); | ||
2990 | if (put_user(datap, &sioc->arg)) | ||
2991 | return -EFAULT; | ||
2992 | |||
2993 | err = sys_ioctl(fd, cmd, (unsigned long) sioc); | ||
2994 | |||
2995 | if (!err) { | ||
2996 | if (copy_in_user(&sioc32->length, &sioc->length, | ||
2997 | sizeof(int))) | ||
2998 | err = -EFAULT; | ||
2999 | } | ||
3000 | return err; | ||
3001 | } | ||
3002 | |||
3003 | static int do_atm_ioctl(unsigned int fd, unsigned int cmd32, unsigned long arg) | ||
3004 | { | ||
3005 | int i; | ||
3006 | unsigned int cmd = 0; | ||
3007 | |||
3008 | switch (cmd32) { | ||
3009 | case SONET_GETSTAT: | ||
3010 | case SONET_GETSTATZ: | ||
3011 | case SONET_GETDIAG: | ||
3012 | case SONET_SETDIAG: | ||
3013 | case SONET_CLRDIAG: | ||
3014 | case SONET_SETFRAMING: | ||
3015 | case SONET_GETFRAMING: | ||
3016 | case SONET_GETFRSENSE: | ||
3017 | return do_atmif_sioc(fd, cmd32, arg); | ||
3018 | } | ||
3019 | |||
3020 | for (i = 0; i < NR_ATM_IOCTL; i++) { | ||
3021 | if (cmd32 == atm_ioctl_map[i].cmd32) { | ||
3022 | cmd = atm_ioctl_map[i].cmd; | ||
3023 | break; | ||
3024 | } | ||
3025 | } | ||
3026 | if (i == NR_ATM_IOCTL) | ||
3027 | return -EINVAL; | ||
3028 | |||
3029 | switch (cmd) { | ||
3030 | case ATM_GETNAMES: | ||
3031 | return do_atm_iobuf(fd, cmd, arg); | ||
3032 | |||
3033 | case ATM_GETLINKRATE: | ||
3034 | case ATM_GETTYPE: | ||
3035 | case ATM_GETESI: | ||
3036 | case ATM_GETADDR: | ||
3037 | case ATM_RSTADDR: | ||
3038 | case ATM_ADDADDR: | ||
3039 | case ATM_DELADDR: | ||
3040 | case ATM_GETCIRANGE: | ||
3041 | case ATM_SETCIRANGE: | ||
3042 | case ATM_SETESI: | ||
3043 | case ATM_SETESIF: | ||
3044 | case ATM_GETSTAT: | ||
3045 | case ATM_GETSTATZ: | ||
3046 | case ATM_GETLOOP: | ||
3047 | case ATM_SETLOOP: | ||
3048 | case ATM_QUERYLOOP: | ||
3049 | return do_atmif_sioc(fd, cmd, arg); | ||
3050 | } | ||
3051 | |||
3052 | return -EINVAL; | ||
3053 | } | ||
3054 | |||
3055 | |||
3056 | /* bridge */ | ||
3057 | HANDLE_IOCTL(SIOCSIFBR, old_bridge_ioctl) | ||
3058 | HANDLE_IOCTL(SIOCGIFBR, old_bridge_ioctl) | ||
3059 | #ifdef CONFIG_NET | ||
3060 | HANDLE_IOCTL(SIOCGIFNAME, dev_ifname32) | ||
3061 | HANDLE_IOCTL(SIOCGIFCONF, dev_ifconf) | ||
3062 | HANDLE_IOCTL(SIOCGIFFLAGS, dev_ifsioc) | ||
3063 | HANDLE_IOCTL(SIOCSIFFLAGS, dev_ifsioc) | ||
3064 | HANDLE_IOCTL(SIOCGIFMETRIC, dev_ifsioc) | ||
3065 | HANDLE_IOCTL(SIOCSIFMETRIC, dev_ifsioc) | ||
3066 | HANDLE_IOCTL(SIOCGIFMTU, dev_ifsioc) | ||
3067 | HANDLE_IOCTL(SIOCSIFMTU, dev_ifsioc) | ||
3068 | HANDLE_IOCTL(SIOCGIFMEM, dev_ifsioc) | ||
3069 | HANDLE_IOCTL(SIOCSIFMEM, dev_ifsioc) | ||
3070 | HANDLE_IOCTL(SIOCGIFHWADDR, dev_ifsioc) | ||
3071 | HANDLE_IOCTL(SIOCSIFHWADDR, dev_ifsioc) | ||
3072 | HANDLE_IOCTL(SIOCADDMULTI, dev_ifsioc) | ||
3073 | HANDLE_IOCTL(SIOCDELMULTI, dev_ifsioc) | ||
3074 | HANDLE_IOCTL(SIOCGIFINDEX, dev_ifsioc) | ||
3075 | HANDLE_IOCTL(SIOCGIFMAP, dev_ifsioc) | ||
3076 | HANDLE_IOCTL(SIOCSIFMAP, dev_ifsioc) | ||
3077 | HANDLE_IOCTL(SIOCGIFADDR, dev_ifsioc) | ||
3078 | HANDLE_IOCTL(SIOCSIFADDR, dev_ifsioc) | ||
3079 | HANDLE_IOCTL(SIOCSIFHWBROADCAST, dev_ifsioc) | ||
3080 | HANDLE_IOCTL(SIOCSHWTSTAMP, dev_ifsioc) | ||
3081 | |||
3082 | HANDLE_IOCTL(SIOCDIFADDR, dev_ifsioc) | ||
3083 | HANDLE_IOCTL(SIOCSARP, dev_ifsioc) | ||
3084 | HANDLE_IOCTL(SIOCDARP, dev_ifsioc) | ||
3085 | |||
3086 | HANDLE_IOCTL(SIOCGIFBRDADDR, dev_ifsioc) | ||
3087 | HANDLE_IOCTL(SIOCSIFBRDADDR, dev_ifsioc) | ||
3088 | HANDLE_IOCTL(SIOCGIFDSTADDR, dev_ifsioc) | ||
3089 | HANDLE_IOCTL(SIOCSIFDSTADDR, dev_ifsioc) | ||
3090 | HANDLE_IOCTL(SIOCGIFNETMASK, dev_ifsioc) | ||
3091 | HANDLE_IOCTL(SIOCSIFNETMASK, dev_ifsioc) | ||
3092 | HANDLE_IOCTL(SIOCSIFPFLAGS, dev_ifsioc) | ||
3093 | HANDLE_IOCTL(SIOCGIFPFLAGS, dev_ifsioc) | ||
3094 | HANDLE_IOCTL(SIOCGIFTXQLEN, dev_ifsioc) | ||
3095 | HANDLE_IOCTL(SIOCSIFTXQLEN, dev_ifsioc) | ||
3096 | HANDLE_IOCTL(SIOCETHTOOL, ethtool_ioctl) | ||
3097 | HANDLE_IOCTL(SIOCBONDENSLAVE, bond_ioctl) | ||
3098 | HANDLE_IOCTL(SIOCBONDRELEASE, bond_ioctl) | ||
3099 | HANDLE_IOCTL(SIOCBONDSETHWADDR, bond_ioctl) | ||
3100 | HANDLE_IOCTL(SIOCBONDSLAVEINFOQUERY, bond_ioctl) | ||
3101 | HANDLE_IOCTL(SIOCBONDINFOQUERY, bond_ioctl) | ||
3102 | HANDLE_IOCTL(SIOCBONDCHANGEACTIVE, bond_ioctl) | ||
3103 | HANDLE_IOCTL(SIOCADDRT, routing_ioctl) | ||
3104 | HANDLE_IOCTL(SIOCDELRT, routing_ioctl) | ||
3105 | HANDLE_IOCTL(SIOCBRADDIF, dev_ifsioc) | ||
3106 | HANDLE_IOCTL(SIOCBRDELIF, dev_ifsioc) | ||
3107 | /* Note SIOCRTMSG is no longer, so this is safe and * the user would have seen just an -EINVAL anyways. */ | ||
3108 | HANDLE_IOCTL(SIOCRTMSG, ret_einval) | ||
3109 | HANDLE_IOCTL(SIOCGSTAMP, do_siocgstamp) | ||
3110 | HANDLE_IOCTL(SIOCGSTAMPNS, do_siocgstampns) | ||
3111 | #endif | ||
3112 | IGNORE_IOCTL(SIOCGIFCOUNT) | ||
3113 | /* Little a */ | ||
3114 | COMPATIBLE_IOCTL(ATMSIGD_CTRL) | ||
3115 | COMPATIBLE_IOCTL(ATMARPD_CTRL) | ||
3116 | COMPATIBLE_IOCTL(ATMLEC_CTRL) | ||
3117 | COMPATIBLE_IOCTL(ATMLEC_MCAST) | ||
3118 | COMPATIBLE_IOCTL(ATMLEC_DATA) | ||
3119 | COMPATIBLE_IOCTL(ATM_SETSC) | ||
3120 | COMPATIBLE_IOCTL(SIOCSIFATMTCP) | ||
3121 | COMPATIBLE_IOCTL(SIOCMKCLIP) | ||
3122 | COMPATIBLE_IOCTL(ATMARP_MKIP) | ||
3123 | COMPATIBLE_IOCTL(ATMARP_SETENTRY) | ||
3124 | COMPATIBLE_IOCTL(ATMARP_ENCAP) | ||
3125 | COMPATIBLE_IOCTL(ATMTCP_CREATE) | ||
3126 | COMPATIBLE_IOCTL(ATMTCP_REMOVE) | ||
3127 | COMPATIBLE_IOCTL(ATMMPC_CTRL) | ||
3128 | COMPATIBLE_IOCTL(ATMMPC_DATA) | ||
3129 | HANDLE_IOCTL(ATM_GETLINKRATE32, do_atm_ioctl) | ||
3130 | HANDLE_IOCTL(ATM_GETNAMES32, do_atm_ioctl) | ||
3131 | HANDLE_IOCTL(ATM_GETTYPE32, do_atm_ioctl) | ||
3132 | HANDLE_IOCTL(ATM_GETESI32, do_atm_ioctl) | ||
3133 | HANDLE_IOCTL(ATM_GETADDR32, do_atm_ioctl) | ||
3134 | HANDLE_IOCTL(ATM_RSTADDR32, do_atm_ioctl) | ||
3135 | HANDLE_IOCTL(ATM_ADDADDR32, do_atm_ioctl) | ||
3136 | HANDLE_IOCTL(ATM_DELADDR32, do_atm_ioctl) | ||
3137 | HANDLE_IOCTL(ATM_GETCIRANGE32, do_atm_ioctl) | ||
3138 | HANDLE_IOCTL(ATM_SETCIRANGE32, do_atm_ioctl) | ||
3139 | HANDLE_IOCTL(ATM_SETESI32, do_atm_ioctl) | ||
3140 | HANDLE_IOCTL(ATM_SETESIF32, do_atm_ioctl) | ||
3141 | HANDLE_IOCTL(ATM_GETSTAT32, do_atm_ioctl) | ||
3142 | HANDLE_IOCTL(ATM_GETSTATZ32, do_atm_ioctl) | ||
3143 | HANDLE_IOCTL(ATM_GETLOOP32, do_atm_ioctl) | ||
3144 | HANDLE_IOCTL(ATM_SETLOOP32, do_atm_ioctl) | ||
3145 | HANDLE_IOCTL(ATM_QUERYLOOP32, do_atm_ioctl) | ||
3146 | HANDLE_IOCTL(SONET_GETSTAT, do_atm_ioctl) | ||
3147 | HANDLE_IOCTL(SONET_GETSTATZ, do_atm_ioctl) | ||
3148 | HANDLE_IOCTL(SONET_GETDIAG, do_atm_ioctl) | ||
3149 | HANDLE_IOCTL(SONET_SETDIAG, do_atm_ioctl) | ||
3150 | HANDLE_IOCTL(SONET_CLRDIAG, do_atm_ioctl) | ||
3151 | HANDLE_IOCTL(SONET_SETFRAMING, do_atm_ioctl) | ||
3152 | HANDLE_IOCTL(SONET_GETFRAMING, do_atm_ioctl) | ||
3153 | HANDLE_IOCTL(SONET_GETFRSENSE, do_atm_ioctl) | ||
3154 | COMPATIBLE_IOCTL(FIOSETOWN) | ||
3155 | COMPATIBLE_IOCTL(SIOCSPGRP) | ||
3156 | COMPATIBLE_IOCTL(FIOGETOWN) | ||
3157 | COMPATIBLE_IOCTL(SIOCGPGRP) | ||
3158 | COMPATIBLE_IOCTL(SIOCATMARK) | ||
3159 | COMPATIBLE_IOCTL(SIOCSIFLINK) | ||
3160 | COMPATIBLE_IOCTL(SIOCSIFNAME) | ||
3161 | COMPATIBLE_IOCTL(SIOCSARP) | ||
3162 | COMPATIBLE_IOCTL(SIOCGARP) | ||
3163 | COMPATIBLE_IOCTL(SIOCDARP) | ||
3164 | COMPATIBLE_IOCTL(SIOCSRARP) | ||
3165 | COMPATIBLE_IOCTL(SIOCGRARP) | ||
3166 | COMPATIBLE_IOCTL(SIOCDRARP) | ||
3167 | COMPATIBLE_IOCTL(SIOCADDDLCI) | ||
3168 | COMPATIBLE_IOCTL(SIOCDELDLCI) | ||
3169 | COMPATIBLE_IOCTL(SIOCGMIIPHY) | ||
3170 | COMPATIBLE_IOCTL(SIOCGMIIREG) | ||
3171 | COMPATIBLE_IOCTL(SIOCSMIIREG) | ||
3172 | COMPATIBLE_IOCTL(SIOCGIFVLAN) | ||
3173 | COMPATIBLE_IOCTL(SIOCSIFVLAN) | ||
3174 | COMPATIBLE_IOCTL(SIOCBRADDBR) | ||
3175 | COMPATIBLE_IOCTL(SIOCBRDELBR) | ||
3176 | #endif | ||
3177 | |||
2462 | static long compat_sock_ioctl(struct file *file, unsigned cmd, | 3178 | static long compat_sock_ioctl(struct file *file, unsigned cmd, |
2463 | unsigned long arg) | 3179 | unsigned long arg) |
2464 | { | 3180 | { |