A userspace application that filters DHCP floods to protect a DHCP server. It uses the Netfilter userspace packet queuing API.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

dhcp_protect.h 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright 2019 Pascal Gloor
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. typedef struct dp_conf {
  15. int pktint;
  16. int interval;
  17. int debug;
  18. int bltime;
  19. int queue;
  20. int dryrun;
  21. } dp_conf;
  22. typedef struct dp_accounting {
  23. unsigned char remoteid[256];
  24. int len;
  25. int count;
  26. UT_hash_handle hh;
  27. } dp_accounting;
  28. typedef struct dp_blacklist {
  29. unsigned char remoteid[256];
  30. int len;
  31. time_t expire;
  32. UT_hash_handle hh;
  33. } dp_blacklist;
  34. // global hash lists
  35. static dp_accounting *accountings = NULL;
  36. static dp_blacklist *blacklists = NULL;
  37. // timestamp for cleanup interval
  38. static time_t dp_accountingtime = 0;
  39. static time_t dp_cleanuptime = 0;
  40. static int dp_callback (
  41. struct nfq_q_handle*,
  42. struct nfgenmsg*,
  43. struct nfq_data*,
  44. void*);
  45. void dp_usage (char*);
  46. dp_conf *dp_load_config (dp_conf*, char*);
  47. void dp_nfq_start (dp_conf*);
  48. void dp_accounting_add (dp_conf*, unsigned char *, int);
  49. int dp_accounting_check (dp_conf*, unsigned char *, int);
  50. void dp_blacklist_add (dp_conf*, unsigned char *, int);
  51. int dp_blacklist_check (dp_conf*, unsigned char *, int);
  52. void dp_hash_cleanup (dp_conf*);
  53. void dp_log (unsigned char *, int, char *, ...);
  54. int dp_dhcp_check (struct nfq_data*, dp_conf*);
  55. void dp_dhcpv4_check (
  56. dp_conf*,
  57. unsigned char*,
  58. int,
  59. int,
  60. unsigned char**,
  61. int*);
  62. void dp_dhcpv6_check (
  63. dp_conf*,
  64. unsigned char*,
  65. int,
  66. int,
  67. unsigned char**,
  68. int*);