b2b22faa550e89e2b5f1c798b028bee7428c1b30
[feed/packages.git] / net / darkstat / patches / 101-allow-multiple-local-interfaces.patch
1 --- a/acct.c
2 +++ b/acct.c
3 @@ -37,8 +37,9 @@
4
5 uint64_t acct_total_packets = 0, acct_total_bytes = 0;
6
7 +#define LOCAL_NET_MAX 10
8 static int using_localnet4 = 0, using_localnet6 = 0;
9 -static struct addr localnet4, localmask4, localnet6, localmask6;
10 +static struct addr localnet4[LOCAL_NET_MAX], localmask4[LOCAL_NET_MAX], localnet6[LOCAL_NET_MAX], localmask6[LOCAL_NET_MAX];
11
12 /* Parse the net/mask specification into two IPs or die trying. */
13 void
14 @@ -120,13 +121,19 @@ acct_init_localnet(const char *spec)
15 /* Register the correct netmask and calculate the correct net. */
16 addr_mask(&localnet, &localmask);
17 if (localnet.family == IPv6) {
18 - using_localnet6 = 1;
19 - localnet6 = localnet;
20 - localmask6 = localmask;
21 + if(using_localnet6 >= LOCAL_NET_MAX){
22 + errx(1, "Exceeded maximum IPv6 local networks");
23 + }
24 + localnet6[using_localnet6] = localnet;
25 + localmask6[using_localnet6] = localmask;
26 + using_localnet6++;
27 } else {
28 - using_localnet4 = 1;
29 - localnet4 = localnet;
30 - localmask4 = localmask;
31 + if(using_localnet4 >= LOCAL_NET_MAX){
32 + errx(1, "Exceeded maximum IPv4 local networks");
33 + }
34 + localnet4[using_localnet4] = localnet;
35 + localmask4[using_localnet4] = localmask;
36 + using_localnet4++;
37 }
38
39 verbosef("local network address: %s", addr_to_str(&localnet));
40 @@ -138,11 +145,15 @@ static int addr_is_local(const struct addr * const a,
41 if (is_localip(a, local_ips))
42 return 1;
43 if (a->family == IPv4 && using_localnet4) {
44 - if (addr_inside(a, &localnet4, &localmask4))
45 - return 1;
46 + for (int i=0; i < using_localnet4; i++){
47 + if (addr_inside(a, &localnet4[i], &localmask4[i]))
48 + return 1;
49 + }
50 } else if (a->family == IPv6 && using_localnet6) {
51 - if (addr_inside(a, &localnet6, &localmask6))
52 - return 1;
53 + for (int i=0; i < using_localnet6; i++){
54 + if (addr_inside(a, &localnet6[i], &localmask6[i]))
55 + return 1;
56 + }
57 }
58 return 0;
59 }
60 --- a/darkstat.c
61 +++ b/darkstat.c
62 @@ -193,7 +193,7 @@ static struct cmdline_arg cmdline_args[] = {
63 {"-r", "capfile", cb_capfile, 0},
64 {"-p", "port", cb_port, 0},
65 {"-b", "bindaddr", cb_bindaddr, -1},
66 - {"-l", "network/netmask", cb_local, 0},
67 + {"-l", "network/netmask", cb_local, -1},
68 {"--base", "path", cb_base, 0},
69 {"--local-only", NULL, cb_local_only, 0},
70 {"--snaplen", "bytes", cb_snaplen, 0},