You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.6 KiB

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