d6_common.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Copyright (C) 2011 Denys Vlasenko.
  4. *
  5. * Licensed under GPLv2, see file LICENSE in this source tree.
  6. */
  7. #ifndef UDHCP_D6_COMMON_H
  8. #define UDHCP_D6_COMMON_H 1
  9. #include <netinet/ip6.h>
  10. PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
  11. /*** DHCPv6 packet ***/
  12. /* DHCPv6 protocol. See RFC 3315 */
  13. #define D6_MSG_SOLICIT 1
  14. #define D6_MSG_ADVERTISE 2
  15. #define D6_MSG_REQUEST 3
  16. #define D6_MSG_CONFIRM 4
  17. #define D6_MSG_RENEW 5
  18. #define D6_MSG_REBIND 6
  19. #define D6_MSG_REPLY 7
  20. #define D6_MSG_RELEASE 8
  21. #define D6_MSG_DECLINE 9
  22. #define D6_MSG_RECONFIGURE 10
  23. #define D6_MSG_INFORMATION_REQUEST 11
  24. #define D6_MSG_RELAY_FORW 12
  25. #define D6_MSG_RELAY_REPL 13
  26. struct d6_packet {
  27. union {
  28. uint8_t d6_msg_type;
  29. uint32_t d6_xid32;
  30. } d6_u;
  31. uint8_t d6_options[576 - sizeof(struct ip6_hdr) - sizeof(struct udphdr) - 4
  32. + CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS];
  33. } PACKED;
  34. #define d6_msg_type d6_u.d6_msg_type
  35. #define d6_xid32 d6_u.d6_xid32
  36. struct ip6_udp_d6_packet {
  37. struct ip6_hdr ip6;
  38. struct udphdr udp;
  39. struct d6_packet data;
  40. } PACKED;
  41. struct udp_d6_packet {
  42. struct udphdr udp;
  43. struct d6_packet data;
  44. } PACKED;
  45. /*** Options ***/
  46. struct d6_option {
  47. uint8_t code_hi;
  48. uint8_t code;
  49. uint8_t len_hi;
  50. uint8_t len;
  51. uint8_t data[1];
  52. } PACKED;
  53. #define D6_OPT_CLIENTID 1
  54. #define D6_OPT_SERVERID 2
  55. /* "Identity Association for Non-temporary Addresses",
  56. * also known as a "network interface" in plain English */
  57. #define D6_OPT_IA_NA 3
  58. /* "Identity Association for the Temporary Addresses".
  59. * Presumably this is a "network interface with only link-local addresses".
  60. * Why would DHCPv6 server assign such addresses, I have no idea. */
  61. //#define D6_OPT_IA_TA 4
  62. /* "IA Address", an IPv6 address */
  63. #define D6_OPT_IAADDR 5
  64. /* Option "Option Request Option". From the owners of a doggy dog named Dog? */
  65. #define D6_OPT_ORO 6
  66. //#define D6_OPT_PREFERENCE 7
  67. #define D6_OPT_ELAPSED_TIME 8
  68. //#define D6_OPT_RELAY_MSG 9
  69. //#define D6_OPT_AUTH 11
  70. /* "The server sends this option to a client to indicate to the client
  71. * that it is allowed to unicast messages to the server."
  72. * Contains IPv6 address to send packets to. */
  73. //#define D6_OPT_UNICAST 12
  74. /* "A Status Code option may appear in the options field of a DHCP
  75. * message and/or in the options field of another option." */
  76. #define D6_OPT_STATUS_CODE 13
  77. /* "A client MAY include this option in a Solicit message if the client
  78. * is prepared to perform the Solicit-Reply message exchange..." */
  79. //#define D6_OPT_RAPID_COMMIT 14 /* zero-length option */
  80. //#define D6_OPT_USER_CLASS 15
  81. //#define D6_OPT_VENDOR_CLASS 16
  82. //#define D6_OPT_VENDOR_OPTS 17
  83. //#define D6_OPT_INTERFACE_ID 18
  84. //#define D6_OPT_RECONF_MSG 19
  85. //#define D6_OPT_RECONF_ACCEPT 20
  86. #define D6_OPT_DNS_SERVERS 23
  87. #define D6_OPT_DOMAIN_LIST 24
  88. /* RFC 3633 "Identity Association for Prefix Delegation".
  89. * This option says that client wants to get an IPv6 prefix */
  90. #define D6_OPT_IA_PD 25
  91. /* Response from the server comes in this one */
  92. #define D6_OPT_IAPREFIX 26
  93. /* RFC 4704 "The DHCPv6 Client FQDN Option"
  94. * uint16 option-code OPTION_CLIENT_FQDN (39)
  95. * uint16 option-len 1 + length of domain name
  96. * uint8 flags
  97. * char[] domain-name partial or fully qualified domain name
  98. *
  99. * Flags format is |MBZ|N|O|S|
  100. * The "S" bit indicates whether the server SHOULD or SHOULD NOT perform
  101. * the AAAA RR (FQDN-to-address) DNS updates. A client sets the bit to
  102. * 0 to indicate that the server SHOULD NOT perform the updates and 1 to
  103. * indicate that the server SHOULD perform the updates. The state of
  104. * the bit in the reply from the server indicates the action to be taken
  105. * by the server; if it is 1, the server has taken responsibility for
  106. * AAAA RR updates for the FQDN.
  107. * The "O" bit indicates whether the server has overridden the client's
  108. * preference for the "S" bit. A client MUST set this bit to 0. A
  109. * server MUST set this bit to 1 if the "S" bit in its reply to the
  110. * client does not match the "S" bit received from the client.
  111. * The "N" bit indicates whether the server SHOULD NOT perform any DNS
  112. * updates. A client sets this bit to 0 to request that the server
  113. * SHOULD perform updates (the PTR RR and possibly the AAAA RR based on
  114. * the "S" bit) or to 1 to request that the server SHOULD NOT perform
  115. * any DNS updates. A server sets the "N" bit to indicate whether the
  116. * server SHALL (0) or SHALL NOT (1) perform DNS updates. If the "N"
  117. * bit is 1, the "S" bit MUST be 0.
  118. *
  119. * If a client knows only part of its name, it MAY send a name that is not
  120. * fully qualified, indicating that it knows part of the name but does not
  121. * necessarily know the zone in which the name is to be embedded.
  122. * To send a fully qualified domain name, the Domain Name field is set
  123. * to the DNS-encoded domain name including the terminating zero-length
  124. * label. To send a partial name, the Domain Name field is set to the
  125. * DNS-encoded domain name without the terminating zero-length label.
  126. * A client MAY also leave the Domain Name field empty if it desires the
  127. * server to provide a name.
  128. */
  129. #define D6_OPT_CLIENT_FQDN 39
  130. #define D6_OPT_TZ_POSIX 41
  131. #define D6_OPT_TZ_NAME 42
  132. #define D6_OPT_BOOT_URL 59
  133. #define D6_OPT_BOOT_PARAM 60
  134. /*** Other shared functions ***/
  135. struct client6_data_t {
  136. struct d6_option *server_id;
  137. struct d6_option *ia_na;
  138. struct d6_option *ia_pd;
  139. char **env_ptr;
  140. unsigned env_idx;
  141. /* link-local IPv6 address */
  142. struct in6_addr ll_ip6;
  143. } FIX_ALIASING;
  144. #define client6_data (*(struct client6_data_t*)(&bb_common_bufsiz1[COMMON_BUFSIZE - sizeof(struct client6_data_t)]))
  145. int FAST_FUNC d6_read_interface(
  146. const char *interface,
  147. int *ifindex,
  148. struct in6_addr *nip6,
  149. uint8_t *mac
  150. );
  151. int FAST_FUNC d6_listen_socket(int port, const char *inf);
  152. int FAST_FUNC d6_recv_kernel_packet(
  153. struct in6_addr *peer_ipv6,
  154. struct d6_packet *packet, int fd
  155. );
  156. int FAST_FUNC d6_send_raw_packet_from_client_data_ifindex(
  157. struct d6_packet *d6_pkt, unsigned d6_pkt_size,
  158. struct in6_addr *src_ipv6, int source_port,
  159. struct in6_addr *dst_ipv6, int dest_port, const uint8_t *dest_arp
  160. );
  161. int FAST_FUNC d6_send_kernel_packet_from_client_data_ifindex(
  162. struct d6_packet *d6_pkt, unsigned d6_pkt_size,
  163. struct in6_addr *src_ipv6, int source_port,
  164. struct in6_addr *dst_ipv6, int dest_port
  165. );
  166. #if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 2
  167. void FAST_FUNC d6_dump_packet(struct d6_packet *packet);
  168. #else
  169. # define d6_dump_packet(packet) ((void)0)
  170. #endif
  171. POP_SAVED_FUNCTION_VISIBILITY
  172. #endif