{"id":466,"date":"2019-02-19T16:00:48","date_gmt":"2019-02-19T08:00:48","guid":{"rendered":"http:\/\/www.freezhongzi.info\/?p=466"},"modified":"2019-02-19T16:00:48","modified_gmt":"2019-02-19T08:00:48","slug":"openwrt-wifi%e9%a9%b1%e5%8a%a8%e7%9a%84iwpriv%e5%85%bc%e5%ae%b9","status":"publish","type":"post","link":"https:\/\/bl4kraven.com\/index.php\/2019\/02\/19\/openwrt-wifi%e9%a9%b1%e5%8a%a8%e7%9a%84iwpriv%e5%85%bc%e5%ae%b9\/","title":{"rendered":"OpenWRT WIFI\u9a71\u52a8\u7684iwpriv\u517c\u5bb9"},"content":{"rendered":"<p>\u6700\u8fd1OpenWRT\u5347\u7ea7\u523018.06.2\u540e\uff0c\u5185\u6838\u53d8\u4e3a4.14\uff0c\u79fb\u690dWIFI\u9a71\u52a8\u7684\u8fc7\u7a0b\u4e2d\u9047\u5230\u4e86\u56f0\u96be\uff0c\u539f\u56e0\u662fWIFI\u9a71\u52a8\u6bd4\u8f83\u8001\u4f9d\u8d56WEXT\u7684\u65e7\u63a5\u53e3<strong>ndo_do_ioctl<\/strong>\u65b9\u5f0f\uff0c\u5bfc\u81f4\u8fd0\u884ciwpriv\u51fa\u9519\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u89e3\u51b3\u95ee\u9898\u7684\u601d\u8def\uff1a<\/p>\n<p>\u4e00\u3001\u7528strace\u8c03\u8bd5iwpriv<\/p>\n<pre><code>root@XXX:~# strace iwpriv ra0\nexecve(\"\/usr\/sbin\/iwpriv\", [\"iwpriv\", \"ra0\"], 0x7feeb574 \/* 12 vars *\/) = 0\nset_thread_area(0x77fc4dc0)             = 0\nset_tid_address(0x77fbdd28)             = 5485\nopen(\"\/etc\/ld-musl-mipsel-sf.path\", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = -1 ENOENT (No such file or directory)\nopen(\"\/lib\/libgcc_s.so.1\", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 3\nfcntl64(3, F_SETFD, FD_CLOEXEC)         = 0\nfstat64(3, {st_mode=S_IFREG|0644, st_size=78095, ...}) = 0\nread(3, \"\\177ELF\\1\\1\\1\\0\\0\\0\\0\\0\\0\\0\\0\\0\\3\\0\\10\\0\\1\\0\\0\\0p(\\0\\0004\\0\\0\\0\"..., 936) = 936\nmmap2(NULL, 147456, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0x77ef5000\nmmap2(0x77f18000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0x13000) = 0x77f18000\nclose(3)                                = 0\nmprotect(0x418000, 4096, PROT_READ)     = 0\nsocket(AF_INET, SOCK_DGRAM, IPPROTO_IP) = 3\nioctl(3, SIOCGIWPRIV, 0x7f8e699c)       = -1 EOPNOTSUPP (Not supported)\nwritev(2, [{iov_base=\"eth0.2    no private ioctls.\\n\\n\", iov_len=30}, {iov_base=NULL, iov_len=0}], 2eth0.2    no private ioctls.\n\n) = 30\nclose(3)                                = 0\nexit_group(0)                           = ?\n+++ exited with 0 +++\n<\/code><\/pre>\n<p>\u5206\u6790\u5230iwpriv\u8c03\u7528\u4e86socket ioctl \u83b7\u53d6SIOCGIWPRIV\u8fd4\u56de\u7684\u79c1\u6709ioctl\u4fe1\u606f\uff0c\u4f46\u662f\u8fd4\u56deEOPNOTSUPP\u4e0d\u652f\u6301\uff0c\u4e0b\u4e00\u6b65\u91cd\u70b9\u5c31\u5728\u5185\u6838\u7684sock_ioctl\u662f\u600e\u4e48\u5904\u7406SIOCGIWPRIV?<\/p>\n<p>\u4e8c\u3001\u67e5\u770b\u5185\u6838\u4ee3\u7801(4.14)\uff1a<\/p>\n<pre><code>    static long sock_ioctl(struct file *file, unsigned cmd, unsigned long arg)\n    {\n        struct socket *sock;\n        struct sock *sk;\n        void __user *argp = (void __user *)arg;\n        int pid, err;\n        struct net *net;\n\n        sock = file-&gt;private_data;\n        sk = sock-&gt;sk;\n        net = sock_net(sk);\n        if (cmd &gt;= SIOCDEVPRIVATE &amp;&amp; cmd &lt;= (SIOCDEVPRIVATE + 15)) {\n            err = dev_ioctl(net, cmd, argp);\n        } else\n    #ifdef CONFIG_WEXT_CORE\n        if (cmd &gt;= SIOCIWFIRST &amp;&amp; cmd &lt;= SIOCIWLAST) {\n            err = dev_ioctl(net, cmd, argp); \/\/ \u770b\u8fd9\u91cc\n        } else\n    #endif\n    ......\n<\/code><\/pre>\n<p>\u53d1\u73b0sock_ioctl\u6709WEXT\u7684\u7279\u6b8a\u5904\u7406\uff0c\u56e0\u4e3aSIOCGIWPRIV\u662f\u5728SIOCIWFIRST\u548cSIOCIWLAST\u4e4b\u95f4\uff0c\u76f4\u63a5\u8c03\u7528\u4e86dev_ioctl(\u597d\u50cf\u662f\/dev\/\u4e0b\u8bbe\u5907\u6587\u4ef6\u7684ioctl)\uff0c\u76f4\u63a5\u770bdev_ioctl:<\/p>\n<pre><code>    int dev_ioctl(struct net *net, unsigned int cmd, void __user *arg)\n    {\n        struct ifreq ifr;\n        int ret;\n        char *colon;\n\n        \/* One special case: SIOCGIFCONF takes ifconf argument\n           and requires shared lock, because it sleeps writing\n           to user space.\n         *\/\n\n        if (cmd == SIOCGIFCONF) {\n            rtnl_lock();\n            ret = dev_ifconf(net, (char __user *) arg);\n            rtnl_unlock();\n            return ret;\n        }\n        if (cmd == SIOCGIFNAME)\n            return dev_ifname(net, (struct ifreq __user *)arg);\n\n        \/*\n         * Take care of Wireless Extensions. Unfortunately struct iwreq\n         * isn't a proper subset of struct ifreq (it's 8 byte shorter)\n         * so we need to treat it specially, otherwise applications may\n         * fault if the struct they're passing happens to land at the\n         * end of a mapped page.\n         *\/\n        if (cmd &gt;= SIOCIWFIRST &amp;&amp; cmd &lt;= SIOCIWLAST) {\n            struct iwreq iwr;\n\n            if (copy_from_user(&amp;iwr, arg, sizeof(iwr)))\n                return -EFAULT;\n\n            iwr.ifr_name[sizeof(iwr.ifr_name) - 1] = 0;\n\n            return wext_handle_ioctl(net, &amp;iwr, cmd, arg);  \/\/\u770b\u8fd9\u91cc\n        }\n<\/code><\/pre>\n<p>\u8fd9\u91cc\u76f4\u63a5\u8c03\u7528\u4e86wext_handle_ioctl\uff0c\u6ce8\u610f\u7528\u4e86iwreq\u7684\u7ed3\u6784\uff0c\u8fd9\u4e2a\u662f\u548cifreq\u7ed3\u6784\u7c7b\u4f3c\u7684\uff0c\u4f46\u662f\u6bd4ifreq\u5c0f8\u4e2a\u5b57\u8282\uff08\u8fd9\u4e2a\u5bfc\u81f4\u540e\u9762\u7684\u89e3\u51b3\u8865\u4e01\u6709\u9690\u60a3\uff0c\u56e0\u4e3a\u8865\u4e01\u662f\u76f4\u63a5\u628aiwreq\u8f6c\u6362\u6210\u4e86ifreq\uff0c\u5982\u679c\u8d85\u8fc732\u4e2a\u5b57\u8282\u76f4\u63a5\u5c31\u622a\u6389\u4e86\uff09\u3002<\/p>\n<p>\u4e2d\u95f4\u7701\u7565\u6b65\u9aa4\uff0c\u6700\u540e\u8ddf\u8e2a\u5230wireless_process_ioctl\u51fd\u6570\u91cc\uff1a<\/p>\n<pre><code>\/*\n * Main IOCTl dispatcher.\n * Check the type of IOCTL and call the appropriate wrapper...\n *\/\nstatic int wireless_process_ioctl(struct net *net, struct iwreq *iwr,\n                  unsigned int cmd,\n                  struct iw_request_info *info,\n                  wext_ioctl_func standard,\n                  wext_ioctl_func private)\n{\n    struct net_device *dev;\n    iw_handler  handler;\n\n    \/* Permissions are already checked in dev_ioctl() before calling us.\n     * The copy_to\/from_user() of ifr is also dealt with in there *\/\n\n    \/* Make sure the device exist *\/\n    if ((dev = __dev_get_by_name(net, iwr-&gt;ifr_name)) == NULL)\n        return -ENODEV;\n\n    \/* A bunch of special cases, then the generic case...\n     * Note that 'cmd' is already filtered in dev_ioctl() with\n     * (cmd &gt;= SIOCIWFIRST &amp;&amp; cmd &lt;= SIOCIWLAST) *\/\n    if (cmd == SIOCGIWSTATS)\n        return standard(dev, iwr, cmd, info,\n                &amp;iw_handler_get_iwstats);\n\n#ifdef CONFIG_WEXT_PRIV\n    if (cmd == SIOCGIWPRIV &amp;&amp; dev-&gt;wireless_handlers) \/\/\u770b\u8fd9\u91cc---------\n        return standard(dev, iwr, cmd, info,\n                iw_handler_get_private);\n#endif\n\n    \/* Basic check *\/\n    if (!netif_device_present(dev))\n        return -ENODEV;\n\n    \/* New driver API : try to find the handler *\/\n    handler = get_handler(dev, cmd);\n    if (handler) {\n        \/* Standard and private are not the same *\/\n        if (cmd &lt; SIOCIWFIRSTPRIV)\n            return standard(dev, iwr, cmd, info, handler);\n        else if (private)\n            return private(dev, iwr, cmd, info, handler);\n    }\n    return -EOPNOTSUPP;\n}\n<\/code><\/pre>\n<p>\u8fd9\u91cc\u538b\u6839\u770b\u4e0d\u5230\u54ea\u91cc\u8c03\u7528\u4e86WIFI\u9a71\u52a8\u914d\u7f6e\u7528\u7684ndo_do_ioctl\u5165\u53e3\uff0c\u53ef\u4ee5\u786e\u5b9a\u7684\u662f\u7528\u4e86net_device->wireless_handlers\u83b7\u53d6private\u548cstandard\u7684handler\u65b9\u5f0f\u5904\u7406\uff0c\u4f46\u6ca1\u6709ndo_do_ioctl\u4ec0\u4e48\u4e8b\u60c5\uff0c\u4e00\u756agoogle\u540e\u53d1\u73b02017\u5e74\u7684\u65f6\u5019\u67d0\u4e00\u7248\u5185\u6838<a href=\"https:\/\/patchwork.kernel.org\/patch\/9786149\/\">\u5220\u6389\u4e86ndo_do_ioctl\u652f\u6301<\/a>\uff1a<\/p>\n<pre><code>diff --git a\/net\/wireless\/wext-core.c b\/net\/wireless\/wext-core.c\nindex 1a4db6790e20..24ba8a99b946 100644\n--- a\/net\/wireless\/wext-core.c\n+++ b\/net\/wireless\/wext-core.c\n@@ -957,9 +957,6 @@  static int wireless_process_ioctl(struct net *net, struct ifreq *ifr,\n        else if (private)\n            return private(dev, iwr, cmd, info, handler);\n    }\n-   \/* Old driver API : call driver ioctl handler *\/\n-   if (dev-&gt;netdev_ops-&gt;ndo_do_ioctl)\n-       return dev-&gt;netdev_ops-&gt;ndo_do_ioctl(dev, ifr, cmd);\n    return -EOPNOTSUPP;\n }\n<\/code><\/pre>\n<p>\u6700\u540e\u7684\u89e3\u51b3\u529e\u6cd5\u4e3a\u4e86\u517c\u5bb9\uff0c\u52a0\u4e0a\u4e0a\u9762\u5220\u6389\u7684\u4ee3\u7801\uff0c\u4e0d\u8fc7\u8981\u628aifr\u66ff\u6362\u6210(struct iwreq *)iwr\uff0c\u9690\u60a3\u662f\u6bd5\u7adfiwreq\u548cifreq\u76f8\u4f3c\u4f46\u662f\u5927\u5c0f\u4e0d\u540c\uff0c\u4e00\u4e2a\u662f32\u4e2a\u5b57\u8282\uff0c\u4e00\u4e2a\u662f40\u4e2a\uff0c\u53ef\u80fd\u4f1a\u6709\u95ee\u9898\uff0c\u4e0d\u8fc7\u6211\u6d4b\u8bd5\u4e86\u4e00\u4e0b\u8c8c\u4f3cOK\uff0c\u90a3\u5c31\u4e0d\u7ba1\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1OpenWRT\u5347\u7ea7\u523018.06.2\u540e\uff0c\u5185\u6838\u53d8\u4e3a4.14\uff0c\u79fb\u690dWIFI\u9a71\u52a8\u7684\u8fc7 &hellip; <a href=\"https:\/\/bl4kraven.com\/index.php\/2019\/02\/19\/openwrt-wifi%e9%a9%b1%e5%8a%a8%e7%9a%84iwpriv%e5%85%bc%e5%ae%b9\/\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a> <a href=\"https:\/\/bl4kraven.com\/index.php\/2019\/02\/19\/openwrt-wifi%e9%a9%b1%e5%8a%a8%e7%9a%84iwpriv%e5%85%bc%e5%ae%b9\/\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-466","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/posts\/466","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/comments?post=466"}],"version-history":[{"count":0,"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/posts\/466\/revisions"}],"wp:attachment":[{"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/media?parent=466"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/categories?post=466"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/tags?post=466"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}