dhcp.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * TAP-Windows -- A kernel driver to provide virtual tap
  3. * device functionality on Windows.
  4. *
  5. * This code was inspired by the CIPE-Win32 driver by Damion K. Wilson.
  6. *
  7. * This source code is Copyright (C) 2002-2010 OpenVPN Technologies, Inc.,
  8. * and is released under the GPL version 2 (see below).
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program (see the file COPYING included with this
  21. * distribution); if not, write to the Free Software Foundation, Inc.,
  22. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. */
  24. #pragma pack(1)
  25. //===================================================
  26. // How many bad DHCPREQUESTs do we receive before we
  27. // return a NAK?
  28. //
  29. // A bad DHCPREQUEST is defined to be one where the
  30. // requestor doesn't know its IP address.
  31. //===================================================
  32. #define BAD_DHCPREQUEST_NAK_THRESHOLD 3
  33. //==============================================
  34. // Maximum number of DHCP options bytes supplied
  35. //==============================================
  36. #define DHCP_USER_SUPPLIED_OPTIONS_BUFFER_SIZE 256
  37. #define DHCP_OPTIONS_BUFFER_SIZE 256
  38. //===================================
  39. // UDP port numbers of DHCP messages.
  40. //===================================
  41. #define BOOTPS_PORT 67
  42. #define BOOTPC_PORT 68
  43. //===========================
  44. // The DHCP message structure
  45. //===========================
  46. typedef struct {
  47. # define BOOTREQUEST 1
  48. # define BOOTREPLY 2
  49. UCHAR op; /* message op */
  50. UCHAR htype; /* hardware address type (e.g. '1' = 10Mb Ethernet) */
  51. UCHAR hlen; /* hardware address length (e.g. '6' for 10Mb Ethernet) */
  52. UCHAR hops; /* client sets to 0, may be used by relay agents */
  53. ULONG xid; /* transaction ID, chosen by client */
  54. USHORT secs; /* seconds since request process began, set by client */
  55. USHORT flags;
  56. ULONG ciaddr; /* client IP address, client sets if known */
  57. ULONG yiaddr; /* 'your' IP address -- server's response to client */
  58. ULONG siaddr; /* server IP address */
  59. ULONG giaddr; /* relay agent IP address */
  60. UCHAR chaddr[16]; /* client hardware address */
  61. UCHAR sname[64]; /* optional server host name */
  62. UCHAR file[128]; /* boot file name */
  63. ULONG magic; /* must be 0x63825363 (network order) */
  64. } DHCP;
  65. typedef struct {
  66. ETH_HEADER eth;
  67. IPHDR ip;
  68. UDPHDR udp;
  69. DHCP dhcp;
  70. } DHCPPre;
  71. typedef struct {
  72. DHCPPre pre;
  73. UCHAR options[DHCP_OPTIONS_BUFFER_SIZE];
  74. } DHCPFull;
  75. typedef struct {
  76. unsigned int optlen;
  77. BOOLEAN overflow;
  78. DHCPFull msg;
  79. } DHCPMsg;
  80. //===================
  81. // Macros for DHCPMSG
  82. //===================
  83. #define DHCPMSG_LEN_BASE(p) (sizeof (DHCPPre))
  84. #define DHCPMSG_LEN_OPT(p) ((p)->optlen)
  85. #define DHCPMSG_LEN_FULL(p) (DHCPMSG_LEN_BASE(p) + DHCPMSG_LEN_OPT(p))
  86. #define DHCPMSG_BUF(p) ((UCHAR*) &(p)->msg)
  87. #define DHCPMSG_OVERFLOW(p) ((p)->overflow)
  88. //========================================
  89. // structs to hold individual DHCP options
  90. //========================================
  91. typedef struct {
  92. UCHAR type;
  93. } DHCPOPT0;
  94. typedef struct {
  95. UCHAR type;
  96. UCHAR len;
  97. UCHAR data;
  98. } DHCPOPT8;
  99. typedef struct {
  100. UCHAR type;
  101. UCHAR len;
  102. ULONG data;
  103. } DHCPOPT32;
  104. #pragma pack()
  105. //==================
  106. // DHCP Option types
  107. //==================
  108. #define DHCP_MSG_TYPE 53 /* message type (u8) */
  109. #define DHCP_PARM_REQ 55 /* parameter request list: c1 (u8), ... */
  110. #define DHCP_CLIENT_ID 61 /* client ID: type (u8), i1 (u8), ... */
  111. #define DHCP_IP 50 /* requested IP addr (u32) */
  112. #define DHCP_NETMASK 1 /* subnet mask (u32) */
  113. #define DHCP_LEASE_TIME 51 /* lease time sec (u32) */
  114. #define DHCP_RENEW_TIME 58 /* renewal time sec (u32) */
  115. #define DHCP_REBIND_TIME 59 /* rebind time sec (u32) */
  116. #define DHCP_SERVER_ID 54 /* server ID: IP addr (u32) */
  117. #define DHCP_PAD 0
  118. #define DHCP_END 255
  119. //====================
  120. // DHCP Messages types
  121. //====================
  122. #define DHCPDISCOVER 1
  123. #define DHCPOFFER 2
  124. #define DHCPREQUEST 3
  125. #define DHCPDECLINE 4
  126. #define DHCPACK 5
  127. #define DHCPNAK 6
  128. #define DHCPRELEASE 7
  129. #define DHCPINFORM 8
  130. #if DBG
  131. VOID
  132. DumpDHCP (const ETH_HEADER *eth,
  133. const IPHDR *ip,
  134. const UDPHDR *udp,
  135. const DHCP *dhcp,
  136. const int optlen);
  137. #endif