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