A userspace application that filters DHCP floods to protect a DHCP server. It uses the Netfilter userspace packet queuing API.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

dhcp_protect.h 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 usage (char*);
  46. int dhcp_check (struct nfq_data*, dp_conf*);
  47. dp_conf *load_config (dp_conf*, char*);
  48. void nfq_start (dp_conf*);
  49. void dp_accounting_add (dp_conf*, unsigned char *, int);
  50. int dp_accounting_check (dp_conf*, unsigned char *, int);
  51. void dp_blacklist_add (dp_conf*, unsigned char *, int);
  52. int dp_blacklist_check (dp_conf*, unsigned char *, int);
  53. void dp_hash_cleanup (dp_conf*);
  54. void dp_log (unsigned char *, int, char *, ...);