Project

General

Profile

Bug #6099 » patch-src_ifvc.c

Jorge M. Oliveira, 09/04/2016 02:49 PM

 
1
--- src/ifvc.c.orig
2
+++ src/ifvc.c
3
@@ -41,8 +41,10 @@
4
 **          
5
 */
6
 void buildIfVc() {
7
-    struct ifreq IfVc[ sizeof( IfDescVc ) / sizeof( IfDescVc[ 0 ] )  ];
8
+    struct ifreq IfVc[ MAX_IF * 2 ]; /* allocate in double in order to get as much information as possible */
9
     struct ifreq *IfEp;
10
+    struct IfDesc *dp;
11
+    struct SubnetList *allowednet, *currsubnet;
12
 
13
     int Sock;
14
 
15
@@ -82,9 +84,24 @@
16
 				    sizeof(struct sockaddr_in)
17
 #endif
18
 		    );
19
+
20
 	    if (IfNext < IfPt + 1)
21
 		    IfNext = IfPt + 1;
22
 
23
+            /* don't retrieve any further info if MAX_IF is reached
24
+             */
25
+            if ( IfDescEp >= &IfDescVc[ MAX_IF ] ) {
26
+                my_log(LOG_DEBUG, 0, "Too many interfaces, skipping all since %s", IfPt->ifr_name);
27
+                break;
28
+            }
29
+
30
+            /* don't retrieve any info from non-IPv4 interfaces
31
+             */
32
+            if ( IfPt->ifr_addr.sa_family != AF_INET ) {
33
+                my_log(LOG_DEBUG, 0, "Interface is not AF_INET, skipping %s (family %d)", IfPt->ifr_name, IfPt->ifr_addr.sa_family);
34
+                continue;
35
+            }
36
+
37
             strncpy( IfDescEp->Name, IfPt->ifr_name, sizeof( IfDescEp->Name ) );
38
 
39
             // Currently don't set any allowed nets...
40
@@ -93,14 +110,6 @@
41
             // Set the index to -1 by default.
42
             IfDescEp->index = -1;
43
 
44
-            /* don't retrieve more info for non-IP interfaces
45
-             */
46
-            if ( IfPt->ifr_addr.sa_family != AF_INET ) {
47
-                IfDescEp->InAdr.s_addr = 0;  /* mark as non-IP interface */
48
-                IfDescEp++;
49
-                continue;
50
-            }
51
-
52
             // Get the interface adress...
53
             IfDescEp->InAdr = ((struct sockaddr_in *)&IfPt->ifr_addr)->sin_addr;
54
             addr = IfDescEp->InAdr.s_addr;
55
@@ -115,6 +124,20 @@
56
             mask = ((struct sockaddr_in *)&IfReq.ifr_addr)->sin_addr.s_addr;
57
             subnet = addr & mask;
58
 
59
+            dp = getIfByName(IfPt->ifr_name, 1);
60
+            if (dp != NULL && dp->allowednets != NULL) {
61
+                allowednet = (struct SubnetList *)malloc(sizeof(struct SubnetList));
62
+                if (allowednet == NULL) my_log(LOG_ERR, 0, "Out of memory !");
63
+                allowednet->next = NULL;
64
+                allowednet->subnet_mask = mask;
65
+                allowednet->subnet_addr = subnet;
66
+                currsubnet = dp->allowednets;
67
+                while (currsubnet->next != NULL)
68
+                    currsubnet = currsubnet->next;
69
+                currsubnet->next = allowednet;
70
+                continue;
71
+            }
72
+
73
             /* get if flags
74
             **
75
             ** typical flags:
76
@@ -166,12 +189,15 @@
77
 **          - NULL if no interface 'IfName' exists
78
 **          
79
 */
80
-struct IfDesc *getIfByName( const char *IfName ) {
81
+struct IfDesc *getIfByName( const char *IfName, int iponly ) {
82
     struct IfDesc *Dp;
83
 
84
-    for ( Dp = IfDescVc; Dp < IfDescEp; Dp++ )
85
+    for ( Dp = IfDescVc; Dp < IfDescEp; Dp++ ) {
86
+        if (iponly && Dp->InAdr.s_addr == 0)
87
+            continue;
88
         if ( ! strcmp( IfName, Dp->Name ) )
89
             return Dp;
90
+    }
91
 
92
     return NULL;
93
 }
(6-6/10)