BDHCPClientCore.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /**
  2. * @file BDHCPClientCore.h
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * This file is part of BadVPN.
  8. *
  9. * BadVPN is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * BadVPN is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. *
  22. * @section DESCRIPTION
  23. *
  24. * DHCP client, excluding system-dependent details.
  25. */
  26. #ifndef BADVPN_DHCPCLIENT_BDHCPCLIENTCORE_H
  27. #define BADVPN_DHCPCLIENT_BDHCPCLIENTCORE_H
  28. #include <stdint.h>
  29. #include <stddef.h>
  30. #include <misc/dhcp_proto.h>
  31. #include <system/BReactor.h>
  32. #include <system/DebugObject.h>
  33. #include <flow/PacketPassInterface.h>
  34. #include <flow/PacketRecvInterface.h>
  35. #define BDHCPCLIENTCORE_EVENT_UP 1
  36. #define BDHCPCLIENTCORE_EVENT_DOWN 2
  37. #define BDHCPCLIENTCORE_MAX_DOMAIN_NAME_SERVERS 16
  38. typedef void (*BDHCPClientCore_handler) (void *user, int event);
  39. typedef struct {
  40. PacketPassInterface *send_if;
  41. PacketRecvInterface *recv_if;
  42. uint8_t client_mac_addr[6];
  43. BReactor *reactor;
  44. BDHCPClientCore_handler handler;
  45. void *user;
  46. struct dhcp_header *send_buf;
  47. struct dhcp_header *recv_buf;
  48. int sending;
  49. BTimer reset_timer;
  50. BTimer request_timer;
  51. BTimer renew_timer;
  52. BTimer renew_request_timer;
  53. BTimer lease_timer;
  54. int state;
  55. int request_count;
  56. uint32_t xid;
  57. int xid_reuse_counter;
  58. struct {
  59. uint32_t yiaddr;
  60. uint32_t dhcp_server_identifier;
  61. } offered;
  62. struct {
  63. uint32_t ip_address_lease_time;
  64. uint32_t subnet_mask;
  65. int have_router;
  66. uint32_t router;
  67. int domain_name_servers_count;
  68. uint32_t domain_name_servers[BDHCPCLIENTCORE_MAX_DOMAIN_NAME_SERVERS];
  69. } acked;
  70. DebugObject d_obj;
  71. } BDHCPClientCore;
  72. int BDHCPClientCore_Init (BDHCPClientCore *o, PacketPassInterface *send_if, PacketRecvInterface *recv_if, uint8_t *client_mac_addr, BReactor *reactor, BDHCPClientCore_handler handler, void *user);
  73. void BDHCPClientCore_Free (BDHCPClientCore *o);
  74. void BDHCPClientCore_GetClientIP (BDHCPClientCore *o, uint32_t *out_ip);
  75. void BDHCPClientCore_GetClientMask (BDHCPClientCore *o, uint32_t *out_mask);
  76. int BDHCPClientCore_GetRouter (BDHCPClientCore *o, uint32_t *out_router);
  77. int BDHCPClientCore_GetDNS (BDHCPClientCore *o, uint32_t *out_dns_servers, size_t max_dns_servers);
  78. #endif