d6_common.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 iphdr) - 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. #define D6_OPT_IA_NA 3
  56. #define D6_OPT_IA_TA 4
  57. #define D6_OPT_IAADDR 5
  58. #define D6_OPT_ORO 6
  59. #define D6_OPT_PREFERENCE 7
  60. #define D6_OPT_ELAPSED_TIME 8
  61. #define D6_OPT_RELAY_MSG 9
  62. #define D6_OPT_AUTH 11
  63. #define D6_OPT_UNICAST 12
  64. #define D6_OPT_STATUS_CODE 13
  65. #define D6_OPT_RAPID_COMMIT 14
  66. #define D6_OPT_USER_CLASS 15
  67. #define D6_OPT_VENDOR_CLASS 16
  68. #define D6_OPT_VENDOR_OPTS 17
  69. #define D6_OPT_INTERFACE_ID 18
  70. #define D6_OPT_RECONF_MSG 19
  71. #define D6_OPT_RECONF_ACCEPT 20
  72. #define D6_OPT_DNS_SERVERS 23
  73. #define D6_OPT_DOMAIN_LIST 24
  74. #define D6_OPT_IA_PD 25
  75. #define D6_OPT_IAPREFIX 26
  76. /* RFC 4704 "The DHCPv6 Client FQDN Option"
  77. * uint16 option-code OPTION_CLIENT_FQDN (39)
  78. * uint16 option-len 1 + length of domain name
  79. * uint8 flags
  80. * char[] domain-name partial or fully qualified domain name
  81. *
  82. * Flags format is |MBZ|N|O|S|
  83. * The "S" bit indicates whether the server SHOULD or SHOULD NOT perform
  84. * the AAAA RR (FQDN-to-address) DNS updates. A client sets the bit to
  85. * 0 to indicate that the server SHOULD NOT perform the updates and 1 to
  86. * indicate that the server SHOULD perform the updates. The state of
  87. * the bit in the reply from the server indicates the action to be taken
  88. * by the server; if it is 1, the server has taken responsibility for
  89. * AAAA RR updates for the FQDN.
  90. * The "O" bit indicates whether the server has overridden the client's
  91. * preference for the "S" bit. A client MUST set this bit to 0. A
  92. * server MUST set this bit to 1 if the "S" bit in its reply to the
  93. * client does not match the "S" bit received from the client.
  94. * The "N" bit indicates whether the server SHOULD NOT perform any DNS
  95. * updates. A client sets this bit to 0 to request that the server
  96. * SHOULD perform updates (the PTR RR and possibly the AAAA RR based on
  97. * the "S" bit) or to 1 to request that the server SHOULD NOT perform
  98. * any DNS updates. A server sets the "N" bit to indicate whether the
  99. * server SHALL (0) or SHALL NOT (1) perform DNS updates. If the "N"
  100. * bit is 1, the "S" bit MUST be 0.
  101. *
  102. * If a client knows only part of its name, it MAY send a name that is not
  103. * fully qualified, indicating that it knows part of the name but does not
  104. * necessarily know the zone in which the name is to be embedded.
  105. * To send a fully qualified domain name, the Domain Name field is set
  106. * to the DNS-encoded domain name including the terminating zero-length
  107. * label. To send a partial name, the Domain Name field is set to the
  108. * DNS-encoded domain name without the terminating zero-length label.
  109. * A client MAY also leave the Domain Name field empty if it desires the
  110. * server to provide a name.
  111. */
  112. #define D6_OPT_CLIENT_FQDN 39
  113. #define D6_OPT_TZ_POSIX 41
  114. #define D6_OPT_TZ_NAME 42
  115. #define D6_OPT_BOOT_URL 59
  116. #define D6_OPT_BOOT_PARAM 60
  117. /*** Other shared functions ***/
  118. struct client6_data_t {
  119. struct d6_option *server_id;
  120. struct d6_option *ia_na;
  121. struct d6_option *ia_pd;
  122. char **env_ptr;
  123. unsigned env_idx;
  124. /* link-local IPv6 address */
  125. struct in6_addr ll_ip6;
  126. };
  127. #define client6_data (*(struct client6_data_t*)(&bb_common_bufsiz1[COMMON_BUFSIZE - sizeof(struct client6_data_t)]))
  128. int FAST_FUNC d6_read_interface(const char *interface, int *ifindex, struct in6_addr *nip6, uint8_t *mac);
  129. int FAST_FUNC d6_listen_socket(int port, const char *inf);
  130. int FAST_FUNC d6_recv_kernel_packet(
  131. struct in6_addr *peer_ipv6,
  132. struct d6_packet *packet, int fd
  133. );
  134. int FAST_FUNC d6_send_raw_packet(
  135. struct d6_packet *d6_pkt, unsigned d6_pkt_size,
  136. struct in6_addr *src_ipv6, int source_port,
  137. struct in6_addr *dst_ipv6, int dest_port, const uint8_t *dest_arp,
  138. int ifindex
  139. );
  140. int FAST_FUNC d6_send_kernel_packet(
  141. struct d6_packet *d6_pkt, unsigned d6_pkt_size,
  142. struct in6_addr *src_ipv6, int source_port,
  143. struct in6_addr *dst_ipv6, int dest_port,
  144. int ifindex
  145. );
  146. #if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 2
  147. void FAST_FUNC d6_dump_packet(struct d6_packet *packet);
  148. #else
  149. # define d6_dump_packet(packet) ((void)0)
  150. #endif
  151. POP_SAVED_FUNCTION_VISIBILITY
  152. #endif