summaryrefslogtreecommitdiff
path: root/net-dialup/rp-pppoe/files/rp-pppoe-3.15-no_max_interfaces.patch
blob: ecf70f09ddc6de885f7874932c02093330325148 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
pppoe-server: MAX_INTERFACES 64 is a problem for ULS.

We currently require 77 interfaces, this code just lifts the limit entirely and
will keep adding interfaces for as much RAM as you have to store an array as
required.

Signed-off-by: Jaco Kroon <jaco@uls.co.za>

diff -rau rp-pppoe-3.15/src.o/pppoe-server.c rp-pppoe-3.15/src/pppoe-server.c
--- rp-pppoe-3.15.o/src/pppoe-server.c	2021-05-07 15:18:00.000000000 +0200
+++ rp-pppoe-3.15/src/pppoe-server.c	2021-12-07 21:53:46.755693003 +0200
@@ -115,8 +115,9 @@
 ClientSession *BusySessions = NULL;
 
 /* Interfaces we're listening on */
-Interface interfaces[MAX_INTERFACES];
+Interface *interfaces = NULL;
 int NumInterfaces = 0;
+int MaxInterfaces = 0;
 
 /* The number of session slots */
 size_t NumSessionSlots;
@@ -1235,11 +1236,16 @@
 	exit(1);
     }
 
-    memset(interfaces, 0, sizeof(interfaces));
-
     /* Initialize syslog */
     openlog("pppoe-server", LOG_PID, LOG_DAEMON);
 
+    MaxInterfaces = INIT_INTERFACES;
+    interfaces = malloc(sizeof(*interfaces) * INIT_INTERFACES);
+    if (!interfaces) {
+	fprintf(stderr, "Out of memory allocating initial interfaces.\n");
+	exit(1);
+    }
+
     /* Default number of session slots */
     NumSessionSlots = DEFAULT_MAX_SESSIONS;
     MaxSessionsPerMac = 0; /* No limit */
@@ -1406,10 +1412,14 @@
 	    break;
 
 	case 'I':
-	    if (NumInterfaces >= MAX_INTERFACES) {
-		fprintf(stderr, "Too many -I options (max %d)\n",
-			MAX_INTERFACES);
-		exit(EXIT_FAILURE);
+	    if (NumInterfaces >= MaxInterfaces) {
+		MaxInterfaces *= 2;
+		interfaces = realloc(interfaces, sizeof(*interfaces) * MaxInterfaces);
+		if (!interfaces) {
+		    fprintf(stderr, "Memory allocation failure trying to increase MaxInterfaces to %d\n",
+			    MaxInterfaces);
+		    exit(EXIT_FAILURE);
+		}
 	    }
 	    found = 0;
 	    for (i=0; i<NumInterfaces; i++) {
@@ -1419,6 +1429,7 @@
 		}
 	    }
 	    if (!found) {
+		memset(&interfaces[NumInterfaces], 0, sizeof(*interfaces));
 		strncpy(interfaces[NumInterfaces].name, optarg, IFNAMSIZ);
 		NumInterfaces++;
 	    }
diff -rau rp-pppoe-3.15/src.o/pppoe-server.h rp-pppoe-3.15/src/pppoe-server.h
--- rp-pppoe-3.15/src.o/pppoe-server.h	2021-05-07 15:18:00.000000000 +0200
+++ rp-pppoe-3.15/src/pppoe-server.h	2021-12-07 21:44:09.945578094 +0200
@@ -97,8 +97,8 @@
 /* Hack for daemonizing */
 #define CLOSEFD 64
 
-/* Max. number of interfaces to listen on */
-#define MAX_INTERFACES 64
+/* Initial Max. number of interfaces to listen on */
+#define INIT_INTERFACES 8
 
 /* Max. 64 sessions by default */
 #define DEFAULT_MAX_SESSIONS 64
@@ -107,7 +107,7 @@
 extern ClientSession *Sessions;
 
 /* Interfaces we're listening on */
-extern Interface interfaces[MAX_INTERFACES];
+extern Interface *interfaces;
 extern int NumInterfaces;
 
 /* The number of session slots */