iPXE
|
IPv6 neighbour discovery protocol. More...
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <byteswap.h>
#include <ipxe/in.h>
#include <ipxe/iobuf.h>
#include <ipxe/tcpip.h>
#include <ipxe/ipv6.h>
#include <ipxe/icmpv6.h>
#include <ipxe/neighbour.h>
#include <ipxe/dhcpv6.h>
#include <ipxe/timer.h>
#include <ipxe/ndp.h>
Go to the source code of this file.
Data Structures | |
struct | ndp_option_handler |
An NDP option handler. More... | |
struct | ndp_prefix_settings |
An NDP prefix settings block. More... | |
struct | ndp_settings |
An NDP settings block. More... | |
struct | ndp_prefix_operation |
An NDP per-prefix setting operation. More... | |
struct | ipv6conf |
An IPv6 configurator. More... | |
Macros | |
#define | IPV6CONF_MIN_TIMEOUT ( TICKS_PER_SEC / 8 ) |
Router discovery minimum timeout. More... | |
#define | IPV6CONF_MAX_TIMEOUT ( TICKS_PER_SEC * 3 ) |
Router discovery maximum timeout. More... | |
#define | IPV6CONF_BLOCK_TIMEOUT ( TICKS_PER_SEC ) |
Router discovery blocked link retry timeout. More... | |
#define | IPV6CONF_MAX_DEFERRALS 180 |
Router discovery maximum number of deferrals. More... | |
#define | NDP_TAG(type, offset, len) ( ( (len) << 16 ) | ( (offset) << 8 ) | (type) ) |
Construct NDP tag. More... | |
#define | NDP_TAG_TYPE(tag) ( ( (tag) >> 0 ) & 0xff ) |
Extract NDP tag type. More... | |
#define | NDP_TAG_OFFSET(tag) ( ( (tag) >> 8 ) & 0xff ) |
Extract NDP tag offset. More... | |
#define | NDP_TAG_LEN(tag) ( ( (tag) >> 16 ) & 0xff ) |
Extract NDP tag length. More... | |
#define | NDP_TAG_INSTANCE(tag) ( ( (tag) >> 24 ) & 0xff ) |
Extract NDP tag instance. More... | |
Functions | |
FILE_LICENCE (GPL2_OR_LATER) | |
static struct ipv6conf * | ipv6conf_demux (struct net_device *netdev) |
Identify IPv6 configurator by network device. More... | |
static int | ipv6conf_rx_router_advertisement (struct net_device *netdev, struct in6_addr *router, struct ndp_router_advertisement_header *radv, size_t len) |
Handle router advertisement during IPv6 autoconfiguration. More... | |
static int | ndp_tx_ll_addr (struct net_device *netdev, struct sockaddr_in6 *sin6_src, struct sockaddr_in6 *sin6_dest, const void *data, size_t len, unsigned int option_type) |
Transmit NDP packet with link-layer address option. More... | |
static int | ndp_tx_request (struct net_device *netdev, struct net_protocol *net_protocol __unused, const void *net_dest, const void *net_source) |
Transmit NDP neighbour discovery request. More... | |
static int | ndp_tx_router_solicitation (struct net_device *netdev) |
Transmit NDP router solicitation. More... | |
static int | ndp_rx_neighbour_solicitation_ll_source (struct net_device *netdev, struct sockaddr_in6 *sin6_src, union ndp_header *ndp, union ndp_option *option, size_t len) |
Process NDP neighbour solicitation source link-layer address option. More... | |
static int | ndp_rx_neighbour_advertisement_ll_target (struct net_device *netdev, struct sockaddr_in6 *sin6_src __unused, union ndp_header *ndp, union ndp_option *option, size_t len) |
Process NDP neighbour advertisement target link-layer address option. More... | |
static int | ndp_rx_router_advertisement_ll_source (struct net_device *netdev, struct sockaddr_in6 *sin6_src, union ndp_header *ndp __unused, union ndp_option *option, size_t len) |
Process NDP router advertisement source link-layer address option. More... | |
static int | ndp_rx_router_advertisement_prefix (struct net_device *netdev, struct sockaddr_in6 *sin6_src, union ndp_header *ndp, union ndp_option *option, size_t len) |
Process NDP router advertisement prefix information option. More... | |
static int | ndp_rx_option (struct net_device *netdev, struct sockaddr_in6 *sin6_src, union ndp_header *ndp, union ndp_option *option, size_t len) |
Process received NDP option. More... | |
static int | ndp_rx_options (struct net_device *netdev, struct sockaddr_in6 *sin6_src, union ndp_header *ndp, size_t offset, size_t len) |
Process received NDP packet options. More... | |
static int | ndp_rx_neighbour (struct io_buffer *iobuf, struct net_device *netdev, struct sockaddr_in6 *sin6_src, struct sockaddr_in6 *sin6_dest __unused) |
Process received NDP neighbour solicitation or advertisement. More... | |
static int | ndp_rx_router_advertisement (struct io_buffer *iobuf, struct net_device *netdev, struct sockaddr_in6 *sin6_src, struct sockaddr_in6 *sin6_dest __unused) |
Process received NDP router advertisement. More... | |
static int | ndp_applies (struct settings *settings __unused, const struct setting *setting) |
Check applicability of NDP setting. More... | |
static int | ndp_fetch (struct settings *settings, struct setting *setting, void *data, size_t len) |
Fetch value of NDP setting. More... | |
static int | ndp_prefix_applies (struct settings *settings __unused, const struct setting *setting) |
Check applicability of NDP per-prefix setting. More... | |
static int | ndp_prefix_fetch_ip6 (struct settings *settings, void *data, size_t len) |
Fetch value of NDP IPv6 address setting. More... | |
static int | ndp_prefix_fetch_len6 (struct settings *settings, void *data, size_t len) |
Fetch value of NDP prefix length setting. More... | |
static int | ndp_prefix_fetch_gateway6 (struct settings *settings, void *data, size_t len) |
Fetch value of NDP router address setting. More... | |
static int | ndp_prefix_fetch (struct settings *settings, struct setting *setting, void *data, size_t len) |
Fetch value of NDP pre-prefix setting. More... | |
static int | ndp_register_settings (struct net_device *netdev, struct in6_addr *router, unsigned int lifetime, union ndp_option *options, size_t len) |
Register NDP settings. More... | |
const struct setting ndp_dns6_setting | __setting (SETTING_IP6_EXTRA, dns6) |
DNS server setting. More... | |
const struct setting ndp_dnssl_setting | __setting (SETTING_IP_EXTRA, dnssl) |
DNS search list setting. More... | |
static | LIST_HEAD (ipv6confs) |
List of IPv6 configurators. More... | |
static void | ipv6conf_free (struct refcnt *refcnt) |
Free IPv6 configurator. More... | |
static void | ipv6conf_done (struct ipv6conf *ipv6conf, int rc) |
Finish IPv6 autoconfiguration. More... | |
static void | ipv6conf_expired (struct retry_timer *timer, int fail) |
Handle IPv6 configurator timer expiry. More... | |
int | start_ipv6conf (struct interface *job, struct net_device *netdev) |
Start IPv6 autoconfiguration. More... | |
Variables | |
struct neighbour_discovery | ndp_discovery |
NDP neighbour discovery protocol. More... | |
static struct ndp_option_handler | ndp_option_handlers [] |
NDP option handlers. More... | |
struct icmpv6_handler ndp_handlers [] | __icmpv6_handler |
NDP ICMPv6 handlers. More... | |
static const struct settings_scope | ndp_settings_scope |
NDP settings scope. More... | |
static struct settings_operations | ndp_settings_operations |
NDP settings operations. More... | |
static struct ndp_prefix_operation | ndp_prefix_operations [] |
NDP per-prefix settings operations. More... | |
static struct settings_operations | ndp_prefix_settings_operations |
NDP per-prefix settings operations. More... | |
static struct interface_operation | ipv6conf_job_op [] |
IPv6 configurator job interface operations. More... | |
static struct interface_descriptor | ipv6conf_job_desc |
IPv6 configurator job interface descriptor. More... | |
static struct interface_operation | ipv6conf_dhcp_op [] |
IPv6 configurator DHCPv6 interface operations. More... | |
static struct interface_descriptor | ipv6conf_dhcp_desc |
IPv6 configurator DHCPv6 interface descriptor. More... | |
struct net_device_configurator ipv6_configurator | __net_device_configurator |
IPv6 network device configurator. More... | |
IPv6 neighbour discovery protocol.
Definition in file ndp.c.
#define IPV6CONF_MIN_TIMEOUT ( TICKS_PER_SEC / 8 ) |
#define IPV6CONF_MAX_TIMEOUT ( TICKS_PER_SEC * 3 ) |
#define IPV6CONF_BLOCK_TIMEOUT ( TICKS_PER_SEC ) |
#define IPV6CONF_MAX_DEFERRALS 180 |
FILE_LICENCE | ( | GPL2_OR_LATER | ) |
|
static |
Identify IPv6 configurator by network device.
netdev | Network device |
ipv6 | IPv6 configurator, or NULL |
Definition at line 1118 of file ndp.c.
References ipv6conf::list, list_for_each_entry, netdev, ipv6conf::netdev, and NULL.
Referenced by ipv6conf_rx_router_advertisement().
|
static |
Handle router advertisement during IPv6 autoconfiguration.
netdev | Network device |
router | Router address |
radv | Router advertisement |
len | Length of router advertisement |
rc | Return status code |
This function assumes that the router advertisement is well-formed, since it must have already passed through option processing.
Definition at line 1191 of file ndp.c.
References DBGC, ipv6conf::dhcp, ndp_router_advertisement_header::flags, ipv6conf_demux(), ipv6conf_done(), len, ndp_router_advertisement_header::lifetime, net_device::name, ndp_register_settings(), NDP_ROUTER_MANAGED, NDP_ROUTER_OTHER, netdev, ntohl, offsetof, ndp_router_advertisement_header::option, rc, start_dhcpv6(), stop_timer(), strerror(), ipv6conf::timer, and typeof().
Referenced by ndp_rx_router_advertisement().
|
static |
Transmit NDP packet with link-layer address option.
netdev | Network device |
sin6_src | Source socket address |
sin6_dest | Destination socket address |
data | NDP header |
len | Size of NDP header |
option_type | NDP option type |
rc | Return status code |
Definition at line 73 of file ndp.c.
References alloc_iob(), ndp_option_header::blocks, icmp_header::chksum, data, io_buffer::data, DBGC, ENOMEM, ndp_ll_addr_option::header, ndp_header::icmp, iob_put, iob_reserve, len, ndp_ll_addr_option::ll_addr, net_device::ll_addr, ll_protocol::ll_addr_len, net_device::ll_protocol, MAX_LL_NET_HEADER_LEN, memcpy(), net_device::name, NDP_OPTION_BLKSZ, netdev, rc, strerror(), tcpip_chksum(), tcpip_tx(), and ndp_option_header::type.
Referenced by ndp_rx_neighbour_solicitation_ll_source(), ndp_tx_request(), and ndp_tx_router_solicitation().
|
static |
Transmit NDP neighbour discovery request.
netdev | Network device |
net_protocol | Network-layer protocol |
net_dest | Destination network-layer address |
net_source | Source network-layer address |
rc | Return status code |
Definition at line 126 of file ndp.c.
References AF_INET6, ndp_neighbour_header::icmp, ICMPV6_NEIGHBOUR_SOLICITATION, ipv6_solicited_node(), memcpy(), memset(), NDP_OPT_LL_SOURCE, ndp_tx_ll_addr(), netdev, rc, net_device::scope_id, sockaddr_in6::sin6_addr, sockaddr_in6::sin6_family, sockaddr_in6::sin6_scope_id, ndp_neighbour_header::target, and icmp_header::type.
|
static |
Transmit NDP router solicitation.
netdev | Network device |
rc | Return status code |
Definition at line 172 of file ndp.c.
References AF_INET6, ndp_router_solicitation_header::icmp, ICMPV6_ROUTER_SOLICITATION, ipv6_all_routers(), memset(), NDP_OPT_LL_SOURCE, ndp_tx_ll_addr(), netdev, NULL, rc, net_device::scope_id, sockaddr_in6::sin6_addr, sockaddr_in6::sin6_family, sockaddr_in6::sin6_scope_id, and icmp_header::type.
Referenced by ipv6conf_expired().
|
static |
Process NDP neighbour solicitation source link-layer address option.
netdev | Network device |
sin6_src | Source socket address |
ndp | NDP packet |
option | NDP option |
len | NDP option length |
rc | Return status code |
Definition at line 206 of file ndp.c.
References DBGC, EINVAL, ndp_neighbour_header::flags, ndp_neighbour_header::icmp, ICMPV6_NEIGHBOUR_ADVERTISEMENT, inet6_ntoa(), ipv6_has_addr(), len, ndp_ll_addr_option::ll_addr, ll_protocol::ll_addr_len, net_device::ll_protocol, memset(), net_device::name, NDP_NEIGHBOUR_OVERRIDE, NDP_NEIGHBOUR_SOLICITED, NDP_OPT_LL_TARGET, ndp_tx_ll_addr(), ndp_header::neigh, neighbour_define(), netdev, ll_protocol::ntoa, NULL, offsetof, rc, sockaddr_in6::sin6_addr, strerror(), ndp_neighbour_header::target, icmp_header::type, and typeof().
|
static |
Process NDP neighbour advertisement target link-layer address option.
netdev | Network device |
sin6_src | Source socket address |
ndp | NDP packet |
option | NDP option |
len | NDP option length |
rc | Return status code |
Definition at line 267 of file ndp.c.
References DBGC, EINVAL, inet6_ntoa(), len, ndp_ll_addr_option::ll_addr, ll_protocol::ll_addr_len, net_device::ll_protocol, net_device::name, ndp_header::neigh, neighbour_update(), netdev, ll_protocol::ntoa, offsetof, rc, strerror(), ndp_neighbour_header::target, and typeof().
|
static |
Process NDP router advertisement source link-layer address option.
netdev | Network device |
sin6_src | Source socket address |
ndp | NDP packet |
option | NDP option |
len | NDP option length |
rc | Return status code |
Definition at line 311 of file ndp.c.
References DBGC, EINVAL, inet6_ntoa(), len, ndp_ll_addr_option::ll_addr, ll_protocol::ll_addr_len, net_device::ll_protocol, net_device::name, neighbour_define(), netdev, ll_protocol::ntoa, offsetof, rc, sockaddr_in6::sin6_addr, strerror(), and typeof().
|
static |
Process NDP router advertisement prefix information option.
netdev | Network device |
sin6_src | Source socket address |
ndp | NDP packet |
option | NDP option |
len | NDP option length |
rc | Return status code |
Definition at line 352 of file ndp.c.
References DBGC, EINVAL, ndp_prefix_information_option::flags, inet6_ntoa(), len, ndp_router_advertisement_header::lifetime, net_device::name, NDP_PREFIX_AUTONOMOUS, NDP_PREFIX_ON_LINK, netdev, ndp_prefix_information_option::prefix, ndp_prefix_information_option::prefix_len, ndp_header::radv, and sockaddr_in6::sin6_addr.
|
static |
Process received NDP option.
netdev | Network device |
sin6_src | Source socket address |
ndp | NDP packet |
option | NDP option |
len | Option length |
rc | Return status code |
Definition at line 431 of file ndp.c.
References ndp_header::icmp, ndp_option_handler::icmp_type, len, ndp_option_handlers, netdev, ndp_option_handler::option_type, ndp_option_handler::rx, and icmp_header::type.
Referenced by ndp_rx_options().
|
static |
Process received NDP packet options.
netdev | Network device |
sin6_src | Source socket address |
ndp | NDP header |
offset | Offset to NDP options |
len | Length of NDP packet |
rc | Return status code |
Definition at line 462 of file ndp.c.
References DBGC, DBGC_HDA, EINVAL, len, net_device::name, NDP_OPTION_BLKSZ, ndp_rx_option(), netdev, offset, and rc.
Referenced by ndp_rx_neighbour(), and ndp_rx_router_advertisement().
|
static |
Process received NDP neighbour solicitation or advertisement.
iobuf | I/O buffer |
netdev | Network device |
sin6_src | Source socket address |
sin6_dest | Destination socket address |
rc | Return status code |
Definition at line 516 of file ndp.c.
References io_buffer::data, free_iob(), iob_len(), len, ndp_rx_options(), ndp_header::neigh, netdev, offsetof, rc, and typeof().
|
static |
Process received NDP router advertisement.
iobuf | I/O buffer |
netdev | Network device |
sin6_src | Source socket address |
sin6_dest | Destination socket address |
rc | Return status code |
Definition at line 546 of file ndp.c.
References io_buffer::data, free_iob(), iob_len(), ipv6conf_rx_router_advertisement(), len, ndp_rx_options(), netdev, offsetof, ndp_header::radv, rc, sockaddr_in6::sin6_addr, and typeof().
|
static |
Check applicability of NDP setting.
settings | Settings block |
setting | Setting to fetch |
applies | Setting applies within this settings block |
Definition at line 674 of file ndp.c.
References ndp_settings_scope, and setting::scope.
|
static |
Fetch value of NDP setting.
settings | Settings block |
setting | Setting to fetch |
data | Buffer to fill with setting data |
len | Length of buffer |
len | Length of setting data, or negative error |
Definition at line 689 of file ndp.c.
References container_of, data, DBGC, EINVAL, ENOENT, len, ndp_settings::len, memcpy(), net_device::name, NDP_OPTION_BLKSZ, NDP_TAG_INSTANCE, NDP_TAG_LEN, NDP_TAG_OFFSET, NDP_TAG_TYPE, netdev, offset, ndp_settings::options, settings::parent, setting::tag, and setting::type.
|
static |
Check applicability of NDP per-prefix setting.
settings | Settings block |
setting | Setting to fetch |
applies | Setting applies within this settings block |
Definition at line 768 of file ndp.c.
References ipv6_settings_scope, and setting::scope.
Fetch value of NDP IPv6 address setting.
settings | Settings block |
data | Buffer to fill with setting data |
len | Length of buffer |
len | Length of setting data, or negative error |
Definition at line 782 of file ndp.c.
References container_of, data, DBGC, ENOENT, inet6_ntoa(), ipv6_eui64(), len, memcpy(), net_device::name, NDP_PREFIX_AUTONOMOUS, netdev, settings::parent, prefix, ndp_prefix_settings::prefix, rc, ndp_settings::settings, and strerror().
Fetch value of NDP prefix length setting.
settings | Settings block |
data | Buffer to fill with setting data |
len | Length of buffer |
len | Length of setting data, or negative error |
Definition at line 839 of file ndp.c.
References container_of, data, len, NDP_PREFIX_ON_LINK, prefix, and ndp_prefix_settings::prefix.
Fetch value of NDP router address setting.
settings | Settings block |
data | Buffer to fill with setting data |
len | Length of buffer |
len | Length of setting data, or negative error |
Definition at line 867 of file ndp.c.
References container_of, data, ENOENT, len, ndp_settings::lifetime, memcpy(), settings::parent, and ndp_settings::router.
|
static |
Fetch value of NDP pre-prefix setting.
settings | Settings block |
setting | Setting to fetch |
data | Buffer to fill with setting data |
len | Length of buffer |
len | Length of setting data, or negative error |
Definition at line 915 of file ndp.c.
References data, ENOENT, len, ndp_prefix_operations, op, and setting_cmp().
|
static |
Register NDP settings.
netdev | Network device |
router | Router address |
lifetime | Router lifetime |
options | NDP options |
len | Length of options |
rc | Return status code |
Definition at line 948 of file ndp.c.
References assert(), ENOMEM, IPV6_ORDER_PREFIX_ONLY, IPV6_ORDER_SLAAC, len, ndp_settings::len, lifetime, ndp_settings::lifetime, memcpy(), ndp_prefix_settings::name, NDP_OPT_PREFIX, NDP_OPTION_BLKSZ, NDP_PREFIX_AUTONOMOUS, ndp_prefix_settings_operations, NDP_SETTINGS_NAME, ndp_settings_operations, ndp_settings_scope, netdev, netdev_settings(), NULL, offset, options, ndp_settings::options, settings::order, settings::parent, ndp_prefix_settings::prefix, rc, ref_init, ref_put, ndp_settings::refcnt, register_settings(), ndp_settings::router, ndp_prefix_settings::settings, ndp_settings::settings, settings_init(), snprintf(), unregister_settings(), and zalloc().
Referenced by ipv6conf_rx_router_advertisement().
const struct setting ndp_dns6_setting __setting | ( | SETTING_IP6_EXTRA | , |
dns6 | |||
) |
DNS server setting.
const struct setting ndp_dnssl_setting __setting | ( | SETTING_IP_EXTRA | , |
dnssl | |||
) |
DNS search list setting.
|
static |
List of IPv6 configurators.
|
static |
Free IPv6 configurator.
refcnt | Reference count |
Definition at line 1104 of file ndp.c.
References container_of, free, ipv6conf::netdev, and netdev_put().
Referenced by start_ipv6conf().
|
static |
Finish IPv6 autoconfiguration.
ipv6 | IPv6 configurator |
rc | Reason for finishing |
Definition at line 1134 of file ndp.c.
References ipv6conf::dhcp, intf_shutdown(), ipv6conf::job, ipv6conf::list, list_del, rc, ref_put, ipv6conf::refcnt, stop_timer(), and ipv6conf::timer.
Referenced by ipv6conf_expired(), and ipv6conf_rx_router_advertisement().
|
static |
Handle IPv6 configurator timer expiry.
timer | Retry timer |
fail | Failure indicator |
Definition at line 1154 of file ndp.c.
References container_of, DBGC, ipv6conf::deferred, ETIMEDOUT, IPV6CONF_BLOCK_TIMEOUT, ipv6conf_done(), IPV6CONF_MAX_DEFERRALS, net_device::name, ndp_tx_router_solicitation(), netdev, ipv6conf::netdev, netdev_link_blocked(), start_timer(), start_timer_fixed(), and ipv6conf::timer.
Referenced by start_ipv6conf().
int start_ipv6conf | ( | struct interface * | job, |
struct net_device * | netdev | ||
) |
Start IPv6 autoconfiguration.
job | Job control interface |
netdev | Network device |
rc | Return status code |
Definition at line 1266 of file ndp.c.
References ipv6conf::dhcp, ENOMEM, intf_init(), intf_plug_plug(), ipv6conf_dhcp_desc, ipv6conf_expired(), ipv6conf_free(), ipv6conf_job_desc, IPV6CONF_MAX_TIMEOUT, IPV6CONF_MIN_TIMEOUT, ipv6conf::job, ipv6conf::list, list_add, netdev, ipv6conf::netdev, netdev_get(), ref_init, ipv6conf::refcnt, start_timer_nodelay(), ipv6conf::timer, and zalloc().
struct neighbour_discovery ndp_discovery |
NDP neighbour discovery protocol.
Definition at line 161 of file ndp.c.
Referenced by ndp_tx().
|
static |
NDP option handlers.
Definition at line 398 of file ndp.c.
Referenced by ndp_rx_option().
struct icmpv6_handler ndp_handlers [] __icmpv6_handler |
NDP ICMPv6 handlers.
|
static |
NDP settings scope.
Definition at line 622 of file ndp.c.
Referenced by ndp_applies(), and ndp_register_settings().
|
static |
NDP settings operations.
Definition at line 756 of file ndp.c.
Referenced by ndp_register_settings().
|
static |
NDP per-prefix settings operations.
Definition at line 900 of file ndp.c.
Referenced by ndp_prefix_fetch().
|
static |
NDP per-prefix settings operations.
Definition at line 933 of file ndp.c.
Referenced by ndp_register_settings().
|
static |
IPv6 configurator job interface operations.
|
static |
IPv6 configurator job interface descriptor.
Definition at line 1247 of file ndp.c.
Referenced by start_ipv6conf().
|
static |
IPv6 configurator DHCPv6 interface operations.
|
static |
IPv6 configurator DHCPv6 interface descriptor.
Definition at line 1256 of file ndp.c.
Referenced by start_ipv6conf().
struct net_device_configurator ipv6_configurator __net_device_configurator |
IPv6 network device configurator.