dhcp_proto.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /**
  2. * @file dhcp_proto.h
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of the author nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * @section DESCRIPTION
  30. *
  31. * Definitions for the DHCP protocol.
  32. */
  33. #ifndef BADVPN_MISC_DHCP_PROTO_H
  34. #define BADVPN_MISC_DHCP_PROTO_H
  35. #include <stdint.h>
  36. #include <misc/packed.h>
  37. #define DHCP_OP_BOOTREQUEST 1
  38. #define DHCP_OP_BOOTREPLY 2
  39. #define DHCP_HARDWARE_ADDRESS_TYPE_ETHERNET 1
  40. #define DHCP_MAGIC 0x63825363
  41. #define DHCP_OPTION_PAD 0
  42. #define DHCP_OPTION_END 255
  43. #define DHCP_OPTION_SUBNET_MASK 1
  44. #define DHCP_OPTION_ROUTER 3
  45. #define DHCP_OPTION_DOMAIN_NAME_SERVER 6
  46. #define DHCP_OPTION_HOST_NAME 12
  47. #define DHCP_OPTION_REQUESTED_IP_ADDRESS 50
  48. #define DHCP_OPTION_IP_ADDRESS_LEASE_TIME 51
  49. #define DHCP_OPTION_DHCP_MESSAGE_TYPE 53
  50. #define DHCP_OPTION_DHCP_SERVER_IDENTIFIER 54
  51. #define DHCP_OPTION_PARAMETER_REQUEST_LIST 55
  52. #define DHCP_OPTION_MAXIMUM_MESSAGE_SIZE 57
  53. #define DHCP_OPTION_RENEWAL_TIME_VALUE 58
  54. #define DHCP_OPTION_REBINDING_TIME_VALUE 59
  55. #define DHCP_OPTION_VENDOR_CLASS_IDENTIFIER 60
  56. #define DHCP_OPTION_CLIENT_IDENTIFIER 61
  57. #define DHCP_MESSAGE_TYPE_DISCOVER 1
  58. #define DHCP_MESSAGE_TYPE_OFFER 2
  59. #define DHCP_MESSAGE_TYPE_REQUEST 3
  60. #define DHCP_MESSAGE_TYPE_DECLINE 4
  61. #define DHCP_MESSAGE_TYPE_ACK 5
  62. #define DHCP_MESSAGE_TYPE_NAK 6
  63. #define DHCP_MESSAGE_TYPE_RELEASE 7
  64. B_START_PACKED
  65. struct dhcp_header {
  66. uint8_t op;
  67. uint8_t htype;
  68. uint8_t hlen;
  69. uint8_t hops;
  70. uint32_t xid;
  71. uint16_t secs;
  72. uint16_t flags;
  73. uint32_t ciaddr;
  74. uint32_t yiaddr;
  75. uint32_t siaddr;
  76. uint32_t giaddr;
  77. uint8_t chaddr[16];
  78. uint8_t sname[64];
  79. uint8_t file[128];
  80. uint32_t magic;
  81. } B_PACKED;
  82. B_END_PACKED
  83. B_START_PACKED
  84. struct dhcp_option_header {
  85. uint8_t type;
  86. uint8_t len;
  87. } B_PACKED;
  88. B_END_PACKED
  89. B_START_PACKED
  90. struct dhcp_option_dhcp_message_type {
  91. uint8_t type;
  92. } B_PACKED;
  93. B_END_PACKED
  94. B_START_PACKED
  95. struct dhcp_option_maximum_message_size {
  96. uint16_t size;
  97. } B_PACKED;
  98. B_END_PACKED
  99. B_START_PACKED
  100. struct dhcp_option_dhcp_server_identifier {
  101. uint32_t id;
  102. } B_PACKED;
  103. B_END_PACKED
  104. B_START_PACKED
  105. struct dhcp_option_time {
  106. uint32_t time;
  107. } B_PACKED;
  108. B_END_PACKED
  109. B_START_PACKED
  110. struct dhcp_option_addr {
  111. uint32_t addr;
  112. } B_PACKED;
  113. B_END_PACKED
  114. #endif