fix svn patch breakage in glib
[librecmc/librecmc.git] / obsolete-buildroot / sources / openwrt / patches / ppp / 057_pppoe-interface-change
1 --- ppp/pppd/plugins/rp-pppoe/plugin.c.orig     2003-04-07 02:09:05.000000000 +0200
2 +++ ppp/pppd/plugins/rp-pppoe/plugin.c  2003-12-03 22:15:07.000000000 +0100
3 @@ -114,6 +114,57 @@
4      return 1;
5  }
6  
7 +/* from <linux/if.h> */
8 +#define IFF_UP          0x1
9 +#define IFF_RUNNING     0x40
10 +
11 +static short ifrflags_old;
12 +
13 +static int interface_change(const char* ifname, int up)
14 +{
15 +    int fd;
16 +    struct ifreq ifr;
17 +
18 +    if (!up && ifrflags_old != 0) {
19 +        return 0;
20 +    }
21 +
22 +    fd = socket(AF_INET, SOCK_DGRAM, 0);
23 +    if (fd < 0) {
24 +       warn("socket(AF_INET, SOCK_DGRAM, 0): %s", strerror(errno));
25 +       return -1;
26 +    }
27 +
28 +    strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
29 +    if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
30 +       warn("%s: unknown interface: %s", ifname, strerror(errno));
31 +       return -1;
32 +    }
33 +    strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
34 +    if (up) {
35 +        ifrflags_old = ifr.ifr_flags & (IFF_UP | IFF_RUNNING);
36 +       ifr.ifr_flags |= (IFF_UP | IFF_RUNNING);
37 +    } else {
38 +        ifr.ifr_flags &= ~(IFF_UP | IFF_RUNNING);
39 +    }
40 +    if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
41 +       warn("SIOCSIFFLAGS: %s", strerror(errno));
42 +       return -1;
43 +    }
44 +    close(fd);
45 +    return 0;
46 +}
47 +
48 +static int interface_up (const char *ifname)
49 +{
50 +    return interface_change(ifname,1);
51 +}
52 +
53 +static int interface_down (const char* ifname)
54 +{
55 +    return interface_change(ifname,0);
56 +}
57 +
58  /**********************************************************************
59   * %FUNCTION: PPPOEConnectDevice
60   * %ARGUMENTS:
61 @@ -142,6 +193,8 @@
62             conn->peerEth[i] = (unsigned char) mac[i];
63         }
64      } else {
65 +       if (interface_up(conn->ifName) < 0)
66 +           return -1;
67         discovery(conn);
68         if (conn->discoveryState != STATE_SESSION) {
69             fatal("Unable to complete PPPoE Discovery");
70 @@ -243,6 +296,8 @@
71         return;
72      }
73      close(conn->sessionSocket);
74 +    if (interface_down(conn->ifName) < 0)
75 +       warn("We brought %s up but failed to take it down",conn->ifName);
76  }
77  
78  static void