dhcp.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. #if 0
  25. #pragma pack(1)
  26. //===================================================
  27. // How many bad DHCPREQUESTs do we receive before we
  28. // return a NAK?
  29. //
  30. // A bad DHCPREQUEST is defined to be one where the
  31. // requestor doesn't know its IP address.
  32. //===================================================
  33. #define BAD_DHCPREQUEST_NAK_THRESHOLD 3
  34. //==============================================
  35. // Maximum number of DHCP options bytes supplied
  36. //==============================================
  37. #define DHCP_USER_SUPPLIED_OPTIONS_BUFFER_SIZE 256
  38. #define DHCP_OPTIONS_BUFFER_SIZE 256
  39. //===================================
  40. // UDP port numbers of DHCP messages.
  41. //===================================
  42. #define BOOTPS_PORT 67
  43. #define BOOTPC_PORT 68
  44. //===========================
  45. // The DHCP message structure
  46. //===========================
  47. typedef struct {
  48. # define BOOTREQUEST 1
  49. # define BOOTREPLY 2
  50. UCHAR op; /* message op */
  51. UCHAR htype; /* hardware address type (e.g. '1' = 10Mb Ethernet) */
  52. UCHAR hlen; /* hardware address length (e.g. '6' for 10Mb Ethernet) */
  53. UCHAR hops; /* client sets to 0, may be used by relay agents */
  54. ULONG xid; /* transaction ID, chosen by client */
  55. USHORT secs; /* seconds since request process began, set by client */
  56. USHORT flags;
  57. ULONG ciaddr; /* client IP address, client sets if known */
  58. ULONG yiaddr; /* 'your' IP address -- server's response to client */
  59. ULONG siaddr; /* server IP address */
  60. ULONG giaddr; /* relay agent IP address */
  61. UCHAR chaddr[16]; /* client hardware address */
  62. UCHAR sname[64]; /* optional server host name */
  63. UCHAR file[128]; /* boot file name */
  64. ULONG magic; /* must be 0x63825363 (network order) */
  65. } DHCP;
  66. typedef struct {
  67. ETH_HEADER eth;
  68. IPHDR ip;
  69. UDPHDR udp;
  70. DHCP dhcp;
  71. } DHCPPre;
  72. typedef struct {
  73. DHCPPre pre;
  74. UCHAR options[DHCP_OPTIONS_BUFFER_SIZE];
  75. } DHCPFull;
  76. typedef struct {
  77. unsigned int optlen;
  78. BOOLEAN overflow;
  79. DHCPFull msg;
  80. } DHCPMsg;
  81. //===================
  82. // Macros for DHCPMSG
  83. //===================
  84. #define DHCPMSG_LEN_BASE(p) (sizeof (DHCPPre))
  85. #define DHCPMSG_LEN_OPT(p) ((p)->optlen)
  86. #define DHCPMSG_LEN_FULL(p) (DHCPMSG_LEN_BASE(p) + DHCPMSG_LEN_OPT(p))
  87. #define DHCPMSG_BUF(p) ((UCHAR*) &(p)->msg)
  88. #define DHCPMSG_OVERFLOW(p) ((p)->overflow)
  89. //========================================
  90. // structs to hold individual DHCP options
  91. //========================================
  92. typedef struct {
  93. UCHAR type;
  94. } DHCPOPT0;
  95. typedef struct {
  96. UCHAR type;
  97. UCHAR len;
  98. UCHAR data;
  99. } DHCPOPT8;
  100. typedef struct {
  101. UCHAR type;
  102. UCHAR len;
  103. ULONG data;
  104. } DHCPOPT32;
  105. #pragma pack()
  106. //==================
  107. // DHCP Option types
  108. //==================
  109. #define DHCP_MSG_TYPE 53 /* message type (u8) */
  110. #define DHCP_PARM_REQ 55 /* parameter request list: c1 (u8), ... */
  111. #define DHCP_CLIENT_ID 61 /* client ID: type (u8), i1 (u8), ... */
  112. #define DHCP_IP 50 /* requested IP addr (u32) */
  113. #define DHCP_NETMASK 1 /* subnet mask (u32) */
  114. #define DHCP_LEASE_TIME 51 /* lease time sec (u32) */
  115. #define DHCP_RENEW_TIME 58 /* renewal time sec (u32) */
  116. #define DHCP_REBIND_TIME 59 /* rebind time sec (u32) */
  117. #define DHCP_SERVER_ID 54 /* server ID: IP addr (u32) */
  118. #define DHCP_PAD 0
  119. #define DHCP_END 255
  120. //====================
  121. // DHCP Messages types
  122. //====================
  123. #define DHCPDISCOVER 1
  124. #define DHCPOFFER 2
  125. #define DHCPREQUEST 3
  126. #define DHCPDECLINE 4
  127. #define DHCPACK 5
  128. #define DHCPNAK 6
  129. #define DHCPRELEASE 7
  130. #define DHCPINFORM 8
  131. #if DBG
  132. VOID
  133. DumpDHCP (const ETH_HEADER *eth,
  134. const IPHDR *ip,
  135. const UDPHDR *udp,
  136. const DHCP *dhcp,
  137. const int optlen);
  138. #endif
  139. #endif