A userspace application that filters DHCP floods to protect a DHCP server. It uses the Netfilter userspace packet queuing API.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

dp_dhcpv6.c 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #include <netinet/in.h>
  4. #include "dp_dhcpv6.h"
  5. #include "dp_helpers.h"
  6. void dp_dhcpv6_check(dp_conf *conf, unsigned char *pkt, int pktlen, int offset, unsigned char **remoteid, int *remoteidlen) {
  7. uint8_t msgtype = (uint8_t)pkt[offset];
  8. if ( conf->debug ) printf("offset=%i\n",offset);
  9. switch(msgtype) {
  10. case 12: // RELAY-FORW
  11. case 13: // RELAY-REPL
  12. offset += 2 + 16 + 16; // msg-type, hop-count, link-addr, peer-addr
  13. if ( conf->debug ) printf("this is a relay msg\n");
  14. break;
  15. default: // all other msgtypes
  16. offset += 4; // msg-type, transaction-id
  17. }
  18. if ( conf->debug ) printf("offset=%i\n",offset);
  19. while(offset+4<=pktlen) {
  20. uint16_t code = ntohs(*(uint16_t*)(pkt+offset));
  21. uint16_t len = ntohs(*(uint16_t*)(pkt+offset+2));
  22. if ( conf->debug ) printf("code %i len %i\n", code, len);
  23. offset+=4;
  24. if ( code == 9 ) { // relay message
  25. if ( conf->debug ) printf("option 9, relay msg\n");
  26. offset+=4;
  27. continue;
  28. }
  29. if ( code == 1 ) { // Client identifier / DUID
  30. // make sure there's enough space
  31. if ( offset + len <= pktlen ) {
  32. *remoteid = pkt+offset;
  33. *remoteidlen = len;
  34. break;
  35. }
  36. }
  37. offset+=len;
  38. }
  39. }