You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ndp.h 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. #ifndef _IPXE_NDP_H
  2. #define _IPXE_NDP_H
  3. /** @file
  4. *
  5. * Neighbour discovery protocol
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  9. #include <stdint.h>
  10. #include <ipxe/in.h>
  11. #include <ipxe/ipv6.h>
  12. #include <ipxe/icmpv6.h>
  13. #include <ipxe/neighbour.h>
  14. /** An NDP option header */
  15. struct ndp_option_header {
  16. /** Type */
  17. uint8_t type;
  18. /** Length (in blocks of 8 bytes) */
  19. uint8_t blocks;
  20. } __attribute__ (( packed ));
  21. /** NDP option block size */
  22. #define NDP_OPTION_BLKSZ 8U
  23. /** NDP source link-layer address option */
  24. #define NDP_OPT_LL_SOURCE 1
  25. /** NDP target link-layer address option */
  26. #define NDP_OPT_LL_TARGET 2
  27. /** NDP source or target link-layer address option */
  28. struct ndp_ll_addr_option {
  29. /** NDP option header */
  30. struct ndp_option_header header;
  31. /** Link-layer address */
  32. uint8_t ll_addr[0];
  33. } __attribute__ (( packed ));
  34. /** NDP prefix information option */
  35. #define NDP_OPT_PREFIX 3
  36. /** NDP prefix information */
  37. struct ndp_prefix_information_option {
  38. /** NDP option header */
  39. struct ndp_option_header header;
  40. /** Prefix length */
  41. uint8_t prefix_len;
  42. /** Flags */
  43. uint8_t flags;
  44. /** Valid lifetime */
  45. uint32_t valid;
  46. /** Preferred lifetime */
  47. uint32_t preferred;
  48. /** Reserved */
  49. uint32_t reserved;
  50. /** Prefix */
  51. struct in6_addr prefix;
  52. } __attribute__ (( packed ));
  53. /** NDP on-link flag */
  54. #define NDP_PREFIX_ON_LINK 0x80
  55. /** NDP autonomous address configuration flag */
  56. #define NDP_PREFIX_AUTONOMOUS 0x40
  57. /** NDP recursive DNS server option */
  58. #define NDP_OPT_RDNSS 25
  59. /** NDP recursive DNS server */
  60. struct ndp_rdnss_option {
  61. /** NDP option header */
  62. struct ndp_option_header header;
  63. /** Reserved */
  64. uint16_t reserved;
  65. /** Lifetime */
  66. uint32_t lifetime;
  67. /** Addresses */
  68. struct in6_addr addresses[0];
  69. } __attribute__ (( packed ));
  70. /** NDP DNS search list option */
  71. #define NDP_OPT_DNSSL 31
  72. /** NDP DNS search list */
  73. struct ndp_dnssl_option {
  74. /** NDP option header */
  75. struct ndp_option_header header;
  76. /** Reserved */
  77. uint16_t reserved;
  78. /** Lifetime */
  79. uint32_t lifetime;
  80. /** Domain names */
  81. uint8_t names[0];
  82. } __attribute__ (( packed ));
  83. /** An NDP option */
  84. union ndp_option {
  85. /** Option header */
  86. struct ndp_option_header header;
  87. /** Source or target link-layer address option */
  88. struct ndp_ll_addr_option ll_addr;
  89. /** Prefix information option */
  90. struct ndp_prefix_information_option prefix;
  91. /** Recursive DNS server option */
  92. struct ndp_rdnss_option rdnss;
  93. /** DNS search list option */
  94. struct ndp_dnssl_option dnssl;
  95. } __attribute__ (( packed ));
  96. /** An NDP neighbour solicitation or advertisement header */
  97. struct ndp_neighbour_header {
  98. /** ICMPv6 header */
  99. struct icmp_header icmp;
  100. /** Flags */
  101. uint8_t flags;
  102. /** Reserved */
  103. uint8_t reserved[3];
  104. /** Target address */
  105. struct in6_addr target;
  106. /** Options */
  107. union ndp_option option[0];
  108. } __attribute__ (( packed ));
  109. /** NDP router flag */
  110. #define NDP_NEIGHBOUR_ROUTER 0x80
  111. /** NDP solicited flag */
  112. #define NDP_NEIGHBOUR_SOLICITED 0x40
  113. /** NDP override flag */
  114. #define NDP_NEIGHBOUR_OVERRIDE 0x20
  115. /** An NDP router advertisement header */
  116. struct ndp_router_advertisement_header {
  117. /** ICMPv6 header */
  118. struct icmp_header icmp;
  119. /** Current hop limit */
  120. uint8_t hop_limit;
  121. /** Flags */
  122. uint8_t flags;
  123. /** Router lifetime */
  124. uint16_t lifetime;
  125. /** Reachable time */
  126. uint32_t reachable;
  127. /** Retransmission timer */
  128. uint32_t retransmit;
  129. /** Options */
  130. union ndp_option option[0];
  131. } __attribute__ (( packed ));
  132. /** NDP managed address configuration */
  133. #define NDP_ROUTER_MANAGED 0x80
  134. /** NDP other configuration */
  135. #define NDP_ROUTER_OTHER 0x40
  136. /** An NDP router solicitation header */
  137. struct ndp_router_solicitation_header {
  138. /** ICMPv6 header */
  139. struct icmp_header icmp;
  140. /** Reserved */
  141. uint32_t reserved;
  142. /** Options */
  143. union ndp_option option[0];
  144. } __attribute__ (( packed ));
  145. /** An NDP header */
  146. union ndp_header {
  147. /** ICMPv6 header */
  148. struct icmp_header icmp;
  149. /** Neighbour solicitation or advertisement header */
  150. struct ndp_neighbour_header neigh;
  151. /** Router solicitation header */
  152. struct ndp_router_solicitation_header rsol;
  153. /** Router advertisement header */
  154. struct ndp_router_advertisement_header radv;
  155. } __attribute__ (( packed ));
  156. extern struct neighbour_discovery ndp_discovery;
  157. /**
  158. * Transmit packet, determining link-layer address via NDP
  159. *
  160. * @v iobuf I/O buffer
  161. * @v netdev Network device
  162. * @v net_dest Destination network-layer address
  163. * @v net_source Source network-layer address
  164. * @v ll_source Source link-layer address
  165. * @ret rc Return status code
  166. */
  167. static inline int ndp_tx ( struct io_buffer *iobuf, struct net_device *netdev,
  168. const void *net_dest, const void *net_source,
  169. const void *ll_source ) {
  170. return neighbour_tx ( iobuf, netdev, &ipv6_protocol, net_dest,
  171. &ndp_discovery, net_source, ll_source );
  172. }
  173. /** NDP settings block name */
  174. #define NDP_SETTINGS_NAME "ndp"
  175. #endif /* _IPXE_NDP_H */