iPXE
ndp.h
Go to the documentation of this file.
00001 #ifndef _IPXE_NDP_H
00002 #define _IPXE_NDP_H
00003 
00004 /** @file
00005  *
00006  * Neighbour discovery protocol
00007  *
00008  */
00009 
00010 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00011 
00012 #include <stdint.h>
00013 #include <ipxe/in.h>
00014 #include <ipxe/ipv6.h>
00015 #include <ipxe/icmpv6.h>
00016 #include <ipxe/neighbour.h>
00017 
00018 /** An NDP option header */
00019 struct ndp_option_header {
00020         /** Type */
00021         uint8_t type;
00022         /** Length (in blocks of 8 bytes) */
00023         uint8_t blocks;
00024 } __attribute__ (( packed ));
00025 
00026 /** NDP option block size */
00027 #define NDP_OPTION_BLKSZ 8U
00028 
00029 /** NDP source link-layer address option */
00030 #define NDP_OPT_LL_SOURCE 1
00031 
00032 /** NDP target link-layer address option */
00033 #define NDP_OPT_LL_TARGET 2
00034 
00035 /** NDP source or target link-layer address option */
00036 struct ndp_ll_addr_option {
00037         /** NDP option header */
00038         struct ndp_option_header header;
00039         /** Link-layer address */
00040         uint8_t ll_addr[0];
00041 } __attribute__ (( packed ));
00042 
00043 /** NDP prefix information option */
00044 #define NDP_OPT_PREFIX 3
00045 
00046 /** NDP prefix information */
00047 struct ndp_prefix_information_option {
00048         /** NDP option header */
00049         struct ndp_option_header header;
00050         /** Prefix length */
00051         uint8_t prefix_len;
00052         /** Flags */
00053         uint8_t flags;
00054         /** Valid lifetime */
00055         uint32_t valid;
00056         /** Preferred lifetime */
00057         uint32_t preferred;
00058         /** Reserved */
00059         uint32_t reserved;
00060         /** Prefix */
00061         struct in6_addr prefix;
00062 } __attribute__ (( packed ));
00063 
00064 /** NDP on-link flag */
00065 #define NDP_PREFIX_ON_LINK 0x80
00066 
00067 /** NDP autonomous address configuration flag */
00068 #define NDP_PREFIX_AUTONOMOUS 0x40
00069 
00070 /** NDP recursive DNS server option */
00071 #define NDP_OPT_RDNSS 25
00072 
00073 /** NDP recursive DNS server */
00074 struct ndp_rdnss_option {
00075         /** NDP option header */
00076         struct ndp_option_header header;
00077         /** Reserved */
00078         uint16_t reserved;
00079         /** Lifetime */
00080         uint32_t lifetime;
00081         /** Addresses */
00082         struct in6_addr addresses[0];
00083 } __attribute__ (( packed ));
00084 
00085 /** NDP DNS search list option */
00086 #define NDP_OPT_DNSSL 31
00087 
00088 /** NDP DNS search list */
00089 struct ndp_dnssl_option {
00090         /** NDP option header */
00091         struct ndp_option_header header;
00092         /** Reserved */
00093         uint16_t reserved;
00094         /** Lifetime */
00095         uint32_t lifetime;
00096         /** Domain names */
00097         uint8_t names[0];
00098 } __attribute__ (( packed ));
00099 
00100 /** An NDP option */
00101 union ndp_option {
00102         /** Option header */
00103         struct ndp_option_header header;
00104         /** Source or target link-layer address option */
00105         struct ndp_ll_addr_option ll_addr;
00106         /** Prefix information option */
00107         struct ndp_prefix_information_option prefix;
00108         /** Recursive DNS server option */
00109         struct ndp_rdnss_option rdnss;
00110         /** DNS search list option */
00111         struct ndp_dnssl_option dnssl;
00112 } __attribute__ (( packed ));
00113 
00114 /** An NDP neighbour solicitation or advertisement header */
00115 struct ndp_neighbour_header {
00116         /** ICMPv6 header */
00117         struct icmp_header icmp;
00118         /** Flags */
00119         uint8_t flags;
00120         /** Reserved */
00121         uint8_t reserved[3];
00122         /** Target address */
00123         struct in6_addr target;
00124         /** Options */
00125         union ndp_option option[0];
00126 } __attribute__ (( packed ));
00127 
00128 /** NDP router flag */
00129 #define NDP_NEIGHBOUR_ROUTER 0x80
00130 
00131 /** NDP solicited flag */
00132 #define NDP_NEIGHBOUR_SOLICITED 0x40
00133 
00134 /** NDP override flag */
00135 #define NDP_NEIGHBOUR_OVERRIDE 0x20
00136 
00137 /** An NDP router advertisement header */
00138 struct ndp_router_advertisement_header {
00139         /** ICMPv6 header */
00140         struct icmp_header icmp;
00141         /** Current hop limit */
00142         uint8_t hop_limit;
00143         /** Flags */
00144         uint8_t flags;
00145         /** Router lifetime */
00146         uint16_t lifetime;
00147         /** Reachable time */
00148         uint32_t reachable;
00149         /** Retransmission timer */
00150         uint32_t retransmit;
00151         /** Options */
00152         union ndp_option option[0];
00153 } __attribute__ (( packed ));
00154 
00155 /** NDP managed address configuration */
00156 #define NDP_ROUTER_MANAGED 0x80
00157 
00158 /** NDP other configuration */
00159 #define NDP_ROUTER_OTHER 0x40
00160 
00161 /** An NDP router solicitation header */
00162 struct ndp_router_solicitation_header {
00163         /** ICMPv6 header */
00164         struct icmp_header icmp;
00165         /** Reserved */
00166         uint32_t reserved;
00167         /** Options */
00168         union ndp_option option[0];
00169 } __attribute__ (( packed ));
00170 
00171 /** An NDP header */
00172 union ndp_header {
00173         /** ICMPv6 header */
00174         struct icmp_header icmp;
00175         /** Neighbour solicitation or advertisement header */
00176         struct ndp_neighbour_header neigh;
00177         /** Router solicitation header */
00178         struct ndp_router_solicitation_header rsol;
00179         /** Router advertisement header */
00180         struct ndp_router_advertisement_header radv;
00181 } __attribute__ (( packed ));
00182 
00183 extern struct neighbour_discovery ndp_discovery;
00184 
00185 /**
00186  * Transmit packet, determining link-layer address via NDP
00187  *
00188  * @v iobuf             I/O buffer
00189  * @v netdev            Network device
00190  * @v net_dest          Destination network-layer address
00191  * @v net_source        Source network-layer address
00192  * @v ll_source         Source link-layer address
00193  * @ret rc              Return status code
00194  */
00195 static inline int ndp_tx ( struct io_buffer *iobuf, struct net_device *netdev,
00196                            const void *net_dest, const void *net_source,
00197                            const void *ll_source ) {
00198 
00199         return neighbour_tx ( iobuf, netdev, &ipv6_protocol, net_dest,
00200                               &ndp_discovery, net_source, ll_source );
00201 }
00202 
00203 /** NDP settings block name */
00204 #define NDP_SETTINGS_NAME "ndp"
00205 
00206 #endif /* _IPXE_NDP_H */