netdev
[Top] [All Lists]

2.2.19 backport of devinet.c 4.4BSD compatibility patch to ioctl SIOCGIF

To: Linux-Kernel mailing list <linux-kernel@xxxxxxxxxxxxxxx>
Subject: 2.2.19 backport of devinet.c 4.4BSD compatibility patch to ioctl SIOCGIF*
From: Matthias Andree <matthias.andree@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 2 Oct 2001 05:06:52 +0200
Cc: Alan Cox <alan@xxxxxxxxxxxxxxxxxxx>, "David S. Miller" <davem@xxxxxxxxxx>, "netdev@xxxxxxxxxxx" <netdev@xxxxxxxxxxx>, Alexey Kuznetsov <kuznet@xxxxxxxxxxxxx>, ak@xxxxxx
In-reply-to: <20011001121931.B15943@emma1.emma.line.org>
Mail-followup-to: Linux-Kernel mailing list <linux-kernel@xxxxxxxxxxxxxxx>, Alan Cox <alan@xxxxxxxxxxxxxxxxxxx>, "David S. Miller" <davem@xxxxxxxxxx>, "netdev@xxxxxxxxxxx" <netdev@xxxxxxxxxxx>, Alexey Kuznetsov <kuznet@xxxxxxxxxxxxx>, ak@xxxxxx
References: <20011001121931.B15943@emma1.emma.line.org>
Sender: owner-netdev@xxxxxxxxxxx
User-agent: Mutt/1.3.22.1i
Here's that 2.4.9 patch to devinet.c backported to 2.2.19. Same
functionality, but caters for CONFIG_IP_ALIAS:

The patch is also available at
http://mandree.home.pages.de/linux/kernel/2.2/

Alan, please consider this for inclusion into your current 2.2.20pre*
series.

--- devinet.c.orig      Fri Dec 22 12:36:33 2000
+++ devinet.c   Tue Oct  2 04:29:03 2001
@@ -20,6 +20,10 @@
  *     Changes:
  *             Alexey Kuznetsov:       pa_* fields are replaced with ifaddr 
lists.
  *             Cyrus Durgin:           updated for kmod
+ *             Matthias Andree:        in devinet_ioctl, compare label and 
+ *                                     address (4.4BSD alias style support),
+ *                                     fall back to comparing just the label
+ *                                     if no match found.
  */
 
 #include <linux/config.h>
@@ -405,6 +409,8 @@
        struct device *dev;
 #ifdef CONFIG_IP_ALIAS
        char *colon;
+       struct sockaddr_in sin_orig;
+       int tryaddrmatch = 0;
 #endif
        int exclusive = 0;
        int ret = 0;
@@ -418,6 +424,9 @@
        ifr.ifr_name[IFNAMSIZ-1] = 0;
 
 #ifdef CONFIG_IP_ALIAS
+        /* save original address for comparison */
+       memcpy(&sin_orig, sin, sizeof(*sin));
+       
        colon = strchr(ifr.ifr_name, ':');
        if (colon)
                *colon = 0;
@@ -436,6 +445,9 @@
                   so that we do not impose a lock.
                   One day we will be forced to put shlock here (I mean SMP)
                 */
+#ifdef CONFIG_IP_ALIAS
+               tryaddrmatch = (sin_orig.sin_family == AF_INET);
+#endif
                memset(sin, 0, sizeof(*sin));
                sin->sin_family = AF_INET;
                break;
@@ -473,6 +485,25 @@
 #endif
 
        if ((in_dev=dev->ip_ptr) != NULL) {
+#ifdef CONFIG_IP_ALIAS
+               if (tryaddrmatch) {
+                       /* Matthias Andree */
+                       /* compare label and address (4.4BSD style) */
+                       /* note: we only do this for a limited set of ioctls
+                          and only if the original address family was AF_INET.
+                          This is checked above. */
+                       for (ifap=&in_dev->ifa_list; (ifa=*ifap) != NULL; 
ifap=&ifa->ifa_next) {
+                               if ((strcmp(ifr.ifr_name, ifa->ifa_label) == 0)
+                                   && (sin_orig.sin_addr.s_addr == 
ifa->ifa_address)) {
+                                       break; /* found */
+                               } /* if */
+                       } /* for */
+               }
+               /* we didn't get a match, maybe the application is
+                  4.3BSD-style and passed in junk so we fall back to 
+                  comparing just the label */
+               if (ifa == NULL) 
+#endif
                for (ifap=&in_dev->ifa_list; (ifa=*ifap) != NULL; 
ifap=&ifa->ifa_next)
                        if (strcmp(ifr.ifr_name, ifa->ifa_label) == 0)
                                break;

-- 
Matthias Andree

<Prev in Thread] Current Thread [Next in Thread>