BDHCPClientCore.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. struct {
  58. uint32_t yiaddr;
  59. uint32_t dhcp_server_identifier;
  60. } offered;
  61. struct {
  62. uint32_t ip_address_lease_time;
  63. uint32_t subnet_mask;
  64. int have_router;
  65. uint32_t router;
  66. int domain_name_servers_count;
  67. uint32_t domain_name_servers[BDHCPCLIENTCORE_MAX_DOMAIN_NAME_SERVERS];
  68. } acked;
  69. DebugObject d_obj;
  70. } BDHCPClientCore;
  71. int BDHCPClientCore_Init (BDHCPClientCore *o, PacketPassInterface *send_if, PacketRecvInterface *recv_if, uint8_t *client_mac_addr, BReactor *reactor, BDHCPClientCore_handler handler, void *user);
  72. void BDHCPClientCore_Free (BDHCPClientCore *o);
  73. void BDHCPClientCore_GetClientIP (BDHCPClientCore *o, uint32_t *out_ip);
  74. void BDHCPClientCore_GetClientMask (BDHCPClientCore *o, uint32_t *out_mask);
  75. int BDHCPClientCore_GetRouter (BDHCPClientCore *o, uint32_t *out_router);
  76. int BDHCPClientCore_GetDNS (BDHCPClientCore *o, uint32_t *out_dns_servers, size_t max_dns_servers);
  77. #endif