aboutsummaryrefslogtreecommitdiffstats
path: root/net/socket.c
diff options
context:
space:
mode:
authorArnd Bergmann <arnd@arndb.de>2009-11-07 02:00:29 -0500
committerDavid S. Miller <davem@davemloft.net>2009-11-07 02:00:29 -0500
commit7a229387d317df525ebd19e146493db7f2694b8b (patch)
treebb3c730da54ca7bdc5f731a96eeb1caf17a5801b /net/socket.c
parent9646e7ce3d1955478aa0573b36c151ab4b649486 (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.c716
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
2463static 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
2480static 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
2497struct 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
2506struct 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
2529struct ifconf32 {
2530 compat_int_t ifc_len; /* size of buffer */
2531 compat_caddr_t ifcbuf;
2532};
2533
2534static 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
2553static 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
2622static 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
2645static 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
2688static 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
2717static 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
2785struct 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
2803struct 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
2816static 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
2869out:
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 */
2880static 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
2891struct atmif_sioc32 {
2892 compat_int_t number;
2893 compat_int_t length;
2894 compat_caddr_t arg;
2895};
2896
2897struct 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
2920static 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
2945static 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
2975static 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
3003static 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 */
3057HANDLE_IOCTL(SIOCSIFBR, old_bridge_ioctl)
3058HANDLE_IOCTL(SIOCGIFBR, old_bridge_ioctl)
3059#ifdef CONFIG_NET
3060HANDLE_IOCTL(SIOCGIFNAME, dev_ifname32)
3061HANDLE_IOCTL(SIOCGIFCONF, dev_ifconf)
3062HANDLE_IOCTL(SIOCGIFFLAGS, dev_ifsioc)
3063HANDLE_IOCTL(SIOCSIFFLAGS, dev_ifsioc)
3064HANDLE_IOCTL(SIOCGIFMETRIC, dev_ifsioc)
3065HANDLE_IOCTL(SIOCSIFMETRIC, dev_ifsioc)
3066HANDLE_IOCTL(SIOCGIFMTU, dev_ifsioc)
3067HANDLE_IOCTL(SIOCSIFMTU, dev_ifsioc)
3068HANDLE_IOCTL(SIOCGIFMEM, dev_ifsioc)
3069HANDLE_IOCTL(SIOCSIFMEM, dev_ifsioc)
3070HANDLE_IOCTL(SIOCGIFHWADDR, dev_ifsioc)
3071HANDLE_IOCTL(SIOCSIFHWADDR, dev_ifsioc)
3072HANDLE_IOCTL(SIOCADDMULTI, dev_ifsioc)
3073HANDLE_IOCTL(SIOCDELMULTI, dev_ifsioc)
3074HANDLE_IOCTL(SIOCGIFINDEX, dev_ifsioc)
3075HANDLE_IOCTL(SIOCGIFMAP, dev_ifsioc)
3076HANDLE_IOCTL(SIOCSIFMAP, dev_ifsioc)
3077HANDLE_IOCTL(SIOCGIFADDR, dev_ifsioc)
3078HANDLE_IOCTL(SIOCSIFADDR, dev_ifsioc)
3079HANDLE_IOCTL(SIOCSIFHWBROADCAST, dev_ifsioc)
3080HANDLE_IOCTL(SIOCSHWTSTAMP, dev_ifsioc)
3081
3082HANDLE_IOCTL(SIOCDIFADDR, dev_ifsioc)
3083HANDLE_IOCTL(SIOCSARP, dev_ifsioc)
3084HANDLE_IOCTL(SIOCDARP, dev_ifsioc)
3085
3086HANDLE_IOCTL(SIOCGIFBRDADDR, dev_ifsioc)
3087HANDLE_IOCTL(SIOCSIFBRDADDR, dev_ifsioc)
3088HANDLE_IOCTL(SIOCGIFDSTADDR, dev_ifsioc)
3089HANDLE_IOCTL(SIOCSIFDSTADDR, dev_ifsioc)
3090HANDLE_IOCTL(SIOCGIFNETMASK, dev_ifsioc)
3091HANDLE_IOCTL(SIOCSIFNETMASK, dev_ifsioc)
3092HANDLE_IOCTL(SIOCSIFPFLAGS, dev_ifsioc)
3093HANDLE_IOCTL(SIOCGIFPFLAGS, dev_ifsioc)
3094HANDLE_IOCTL(SIOCGIFTXQLEN, dev_ifsioc)
3095HANDLE_IOCTL(SIOCSIFTXQLEN, dev_ifsioc)
3096HANDLE_IOCTL(SIOCETHTOOL, ethtool_ioctl)
3097HANDLE_IOCTL(SIOCBONDENSLAVE, bond_ioctl)
3098HANDLE_IOCTL(SIOCBONDRELEASE, bond_ioctl)
3099HANDLE_IOCTL(SIOCBONDSETHWADDR, bond_ioctl)
3100HANDLE_IOCTL(SIOCBONDSLAVEINFOQUERY, bond_ioctl)
3101HANDLE_IOCTL(SIOCBONDINFOQUERY, bond_ioctl)
3102HANDLE_IOCTL(SIOCBONDCHANGEACTIVE, bond_ioctl)
3103HANDLE_IOCTL(SIOCADDRT, routing_ioctl)
3104HANDLE_IOCTL(SIOCDELRT, routing_ioctl)
3105HANDLE_IOCTL(SIOCBRADDIF, dev_ifsioc)
3106HANDLE_IOCTL(SIOCBRDELIF, dev_ifsioc)
3107/* Note SIOCRTMSG is no longer, so this is safe and * the user would have seen just an -EINVAL anyways. */
3108HANDLE_IOCTL(SIOCRTMSG, ret_einval)
3109HANDLE_IOCTL(SIOCGSTAMP, do_siocgstamp)
3110HANDLE_IOCTL(SIOCGSTAMPNS, do_siocgstampns)
3111#endif
3112IGNORE_IOCTL(SIOCGIFCOUNT)
3113/* Little a */
3114COMPATIBLE_IOCTL(ATMSIGD_CTRL)
3115COMPATIBLE_IOCTL(ATMARPD_CTRL)
3116COMPATIBLE_IOCTL(ATMLEC_CTRL)
3117COMPATIBLE_IOCTL(ATMLEC_MCAST)
3118COMPATIBLE_IOCTL(ATMLEC_DATA)
3119COMPATIBLE_IOCTL(ATM_SETSC)
3120COMPATIBLE_IOCTL(SIOCSIFATMTCP)
3121COMPATIBLE_IOCTL(SIOCMKCLIP)
3122COMPATIBLE_IOCTL(ATMARP_MKIP)
3123COMPATIBLE_IOCTL(ATMARP_SETENTRY)
3124COMPATIBLE_IOCTL(ATMARP_ENCAP)
3125COMPATIBLE_IOCTL(ATMTCP_CREATE)
3126COMPATIBLE_IOCTL(ATMTCP_REMOVE)
3127COMPATIBLE_IOCTL(ATMMPC_CTRL)
3128COMPATIBLE_IOCTL(ATMMPC_DATA)
3129HANDLE_IOCTL(ATM_GETLINKRATE32, do_atm_ioctl)
3130HANDLE_IOCTL(ATM_GETNAMES32, do_atm_ioctl)
3131HANDLE_IOCTL(ATM_GETTYPE32, do_atm_ioctl)
3132HANDLE_IOCTL(ATM_GETESI32, do_atm_ioctl)
3133HANDLE_IOCTL(ATM_GETADDR32, do_atm_ioctl)
3134HANDLE_IOCTL(ATM_RSTADDR32, do_atm_ioctl)
3135HANDLE_IOCTL(ATM_ADDADDR32, do_atm_ioctl)
3136HANDLE_IOCTL(ATM_DELADDR32, do_atm_ioctl)
3137HANDLE_IOCTL(ATM_GETCIRANGE32, do_atm_ioctl)
3138HANDLE_IOCTL(ATM_SETCIRANGE32, do_atm_ioctl)
3139HANDLE_IOCTL(ATM_SETESI32, do_atm_ioctl)
3140HANDLE_IOCTL(ATM_SETESIF32, do_atm_ioctl)
3141HANDLE_IOCTL(ATM_GETSTAT32, do_atm_ioctl)
3142HANDLE_IOCTL(ATM_GETSTATZ32, do_atm_ioctl)
3143HANDLE_IOCTL(ATM_GETLOOP32, do_atm_ioctl)
3144HANDLE_IOCTL(ATM_SETLOOP32, do_atm_ioctl)
3145HANDLE_IOCTL(ATM_QUERYLOOP32, do_atm_ioctl)
3146HANDLE_IOCTL(SONET_GETSTAT, do_atm_ioctl)
3147HANDLE_IOCTL(SONET_GETSTATZ, do_atm_ioctl)
3148HANDLE_IOCTL(SONET_GETDIAG, do_atm_ioctl)
3149HANDLE_IOCTL(SONET_SETDIAG, do_atm_ioctl)
3150HANDLE_IOCTL(SONET_CLRDIAG, do_atm_ioctl)
3151HANDLE_IOCTL(SONET_SETFRAMING, do_atm_ioctl)
3152HANDLE_IOCTL(SONET_GETFRAMING, do_atm_ioctl)
3153HANDLE_IOCTL(SONET_GETFRSENSE, do_atm_ioctl)
3154COMPATIBLE_IOCTL(FIOSETOWN)
3155COMPATIBLE_IOCTL(SIOCSPGRP)
3156COMPATIBLE_IOCTL(FIOGETOWN)
3157COMPATIBLE_IOCTL(SIOCGPGRP)
3158COMPATIBLE_IOCTL(SIOCATMARK)
3159COMPATIBLE_IOCTL(SIOCSIFLINK)
3160COMPATIBLE_IOCTL(SIOCSIFNAME)
3161COMPATIBLE_IOCTL(SIOCSARP)
3162COMPATIBLE_IOCTL(SIOCGARP)
3163COMPATIBLE_IOCTL(SIOCDARP)
3164COMPATIBLE_IOCTL(SIOCSRARP)
3165COMPATIBLE_IOCTL(SIOCGRARP)
3166COMPATIBLE_IOCTL(SIOCDRARP)
3167COMPATIBLE_IOCTL(SIOCADDDLCI)
3168COMPATIBLE_IOCTL(SIOCDELDLCI)
3169COMPATIBLE_IOCTL(SIOCGMIIPHY)
3170COMPATIBLE_IOCTL(SIOCGMIIREG)
3171COMPATIBLE_IOCTL(SIOCSMIIREG)
3172COMPATIBLE_IOCTL(SIOCGIFVLAN)
3173COMPATIBLE_IOCTL(SIOCSIFVLAN)
3174COMPATIBLE_IOCTL(SIOCBRADDBR)
3175COMPATIBLE_IOCTL(SIOCBRDELBR)
3176#endif
3177
2462static long compat_sock_ioctl(struct file *file, unsigned cmd, 3178static long compat_sock_ioctl(struct file *file, unsigned cmd,
2463 unsigned long arg) 3179 unsigned long arg)
2464{ 3180{