iPXE
|
IPv4 protocol. More...
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <byteswap.h>
#include <ipxe/list.h>
#include <ipxe/in.h>
#include <ipxe/arp.h>
#include <ipxe/if_ether.h>
#include <ipxe/iobuf.h>
#include <ipxe/netdevice.h>
#include <ipxe/ip.h>
#include <ipxe/tcpip.h>
#include <ipxe/dhcp.h>
#include <ipxe/settings.h>
#include <ipxe/fragment.h>
#include <ipxe/ipstat.h>
#include <ipxe/profile.h>
Go to the source code of this file.
Functions | |
FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) | |
struct ip_statistics_family ipv4_stats_family | __ip_statistics_family (IP_STATISTICS_IPV4) |
IPv4 statistics family. More... | |
static int | add_ipv4_miniroute (struct net_device *netdev, struct in_addr address, struct in_addr netmask, struct in_addr gateway) |
Add IPv4 minirouting table entry. More... | |
static void | del_ipv4_miniroute (struct ipv4_miniroute *miniroute) |
Delete IPv4 minirouting table entry. More... | |
static struct ipv4_miniroute * | ipv4_route (unsigned int scope_id, struct in_addr *dest) |
Perform IPv4 routing. More... | |
static struct net_device * | ipv4_netdev (struct sockaddr_tcpip *st_dest) |
Determine transmitting network device. More... | |
static int | ipv4_is_fragment (struct fragment *fragment, struct io_buffer *iobuf, size_t hdrlen __unused) |
Check if IPv4 fragment matches fragment reassembly buffer. More... | |
static size_t | ipv4_fragment_offset (struct io_buffer *iobuf, size_t hdrlen __unused) |
Get IPv4 fragment offset. More... | |
static int | ipv4_more_fragments (struct io_buffer *iobuf, size_t hdrlen __unused) |
Check if more fragments exist. More... | |
static uint16_t | ipv4_pshdr_chksum (struct io_buffer *iobuf, uint16_t csum) |
Add IPv4 pseudo-header checksum to existing checksum. More... | |
static int | ipv4_tx (struct io_buffer *iobuf, struct tcpip_protocol *tcpip_protocol, struct sockaddr_tcpip *st_src, struct sockaddr_tcpip *st_dest, struct net_device *netdev, uint16_t *trans_csum) |
Transmit IP packet. More... | |
int | ipv4_has_any_addr (struct net_device *netdev) |
Check if network device has any IPv4 address. More... | |
static int | ipv4_has_addr (struct net_device *netdev, struct in_addr addr) |
Check if network device has a specific IPv4 address. More... | |
static int | ipv4_rx (struct io_buffer *iobuf, struct net_device *netdev, const void *ll_dest __unused, const void *ll_source __unused, unsigned int flags) |
Process incoming packets. More... | |
static int | ipv4_arp_check (struct net_device *netdev, const void *net_addr) |
Check existence of IPv4 address for ARP. More... | |
int | inet_aton (const char *string, struct in_addr *in) |
Parse IPv4 address. More... | |
char * | inet_ntoa (struct in_addr in) |
Convert IPv4 address to dotted-quad notation. More... | |
static const char * | ipv4_ntoa (const void *net_addr) |
Transcribe IPv4 address. More... | |
static const char * | ipv4_sock_ntoa (struct sockaddr *sa) |
Transcribe IPv4 socket address. More... | |
static int | ipv4_sock_aton (const char *string, struct sockaddr *sa) |
Parse IPv4 socket address. More... | |
int | parse_ipv4_setting (const struct setting_type *type __unused, const char *value, void *buf, size_t len) |
Parse IPv4 address setting value. More... | |
int | format_ipv4_setting (const struct setting_type *type __unused, const void *raw, size_t raw_len, char *buf, size_t len) |
Format IPv4 address setting value. More... | |
const struct setting ip_setting | __setting (SETTING_IP4, ip) |
IPv4 address setting. More... | |
const struct setting netmask_setting | __setting (SETTING_IP4, netmask) |
IPv4 subnet mask setting. More... | |
const struct setting gateway_setting | __setting (SETTING_IP4, gateway) |
Default gateway setting. More... | |
static int | ipv4_gratuitous_arp (struct net_device *netdev, struct in_addr address, struct in_addr netmask __unused, struct in_addr gateway __unused) |
Send gratuitous ARP, if applicable. More... | |
static int | ipv4_settings (int(*apply)(struct net_device *netdev, struct in_addr address, struct in_addr netmask, struct in_addr gateway)) |
Process IPv4 network device settings. More... | |
static int | ipv4_create_routes (void) |
Create IPv4 routing table based on configured settings. More... | |
REQUIRING_SYMBOL (ipv4_protocol) | |
REQUIRE_OBJECT (icmpv4) | |
Variables | |
static uint8_t | next_ident_high = 0 |
struct list_head | ipv4_miniroutes = LIST_HEAD_INIT ( ipv4_miniroutes ) |
List of IPv4 miniroutes. More... | |
static struct ip_statistics | ipv4_stats |
IPv4 statistics. More... | |
static struct profiler ipv4_tx_profiler | __profiler = { .name = "ipv4.tx" } |
Transmit profiler. More... | |
static struct fragment_reassembler | ipv4_reassembler |
IPv4 fragment reassembler. More... | |
struct net_protocol ipv4_protocol | __net_protocol |
IPv4 protocol. More... | |
struct tcpip_net_protocol ipv4_tcpip_protocol | __tcpip_net_protocol |
IPv4 TCPIP net protocol. More... | |
struct arp_net_protocol ipv4_arp_protocol | __arp_net_protocol |
IPv4 ARP protocol. More... | |
struct sockaddr_converter ipv4_sockaddr_converter | __sockaddr_converter |
IPv4 socket address converter. More... | |
struct settings_applicator ipv4_settings_applicator | __settings_applicator |
IPv4 settings applicator. More... | |
IPv4 protocol.
Definition in file ipv4.c.
FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
struct ip_statistics_family ipv4_stats_family __ip_statistics_family | ( | IP_STATISTICS_IPV4 | ) |
IPv4 statistics family.
|
static |
Add IPv4 minirouting table entry.
netdev | Network device |
address | IPv4 address |
netmask | Subnet mask |
gateway | Gateway address (if any) |
rc | Return status code |
Definition at line 84 of file ipv4.c.
References address, ipv4_miniroute::address, DBGC, ENOMEM, ipv4_miniroute::gateway, ipv4_miniroute::hostmask, IN_IS_SMALL, INADDR_NONE, inet_ntoa(), ipv4_miniroutes, ipv4_miniroute::list, list_add, list_add_tail, malloc(), net_device::name, netdev, ipv4_miniroute::netdev, netdev_get(), ipv4_miniroute::netmask, and in_addr::s_addr.
Referenced by ipv4_create_routes().
|
static |
Delete IPv4 minirouting table entry.
miniroute | Routing table entry |
Definition at line 135 of file ipv4.c.
References ipv4_miniroute::address, DBGC, free, ipv4_miniroute::gateway, inet_ntoa(), ipv4_miniroute::list, list_del, net_device::name, netdev, ipv4_miniroute::netdev, netdev_put(), ipv4_miniroute::netmask, and in_addr::s_addr.
Referenced by ipv4_create_routes().
|
static |
Perform IPv4 routing.
scope_id | Destination address scope ID |
dest | Final destination address |
dest | Next hop destination address |
miniroute | Routing table entry to use, or NULL if no route |
If the route requires use of a gateway, the next hop destination address will be overwritten with the gateway address.
Definition at line 160 of file ipv4.c.
References ipv4_miniroute::address, dest, ipv4_miniroute::gateway, IN_IS_MULTICAST, ipv4_miniroutes, ipv4_miniroute::list, list_for_each_entry, ipv4_miniroute::netdev, netdev_is_open(), ipv4_miniroute::netmask, NULL, in_addr::s_addr, and net_device::scope_id.
Referenced by ipv4_netdev(), and ipv4_tx().
|
static |
Determine transmitting network device.
st_dest | Destination network-layer address |
netdev | Transmitting network device, or NULL |
Definition at line 208 of file ipv4.c.
References dest, ipv4_route(), ipv4_miniroute::netdev, NULL, sockaddr_in::sin_addr, and sockaddr_in::sin_scope_id.
|
static |
Check if IPv4 fragment matches fragment reassembly buffer.
fragment | Fragment reassembly buffer |
iobuf | I/O buffer |
hdrlen | Length of non-fragmentable potion of I/O buffer |
is_fragment | Fragment matches this reassembly buffer |
Definition at line 229 of file ipv4.c.
References io_buffer::data, iphdr::ident, fragment::iobuf, in_addr::s_addr, and iphdr::src.
Get IPv4 fragment offset.
iobuf | I/O buffer |
hdrlen | Length of non-fragmentable potion of I/O buffer |
offset | Offset |
Definition at line 246 of file ipv4.c.
References io_buffer::data, iphdr::frags, IP_MASK_OFFSET, and ntohs.
Check if more fragments exist.
iobuf | I/O buffer |
hdrlen | Length of non-fragmentable potion of I/O buffer |
more_frags | More fragments exist |
Definition at line 260 of file ipv4.c.
References io_buffer::data, iphdr::frags, htons, and IP_MASK_MOREFRAGS.
Add IPv4 pseudo-header checksum to existing checksum.
iobuf | I/O buffer |
csum | Existing checksum |
csum | Updated checksum |
Definition at line 283 of file ipv4.c.
References io_buffer::data, ipv4_pseudo_header::dest, iphdr::dest, htons, iob_len(), IP_MASK_HLEN, ipv4_pseudo_header::len, iphdr::protocol, ipv4_pseudo_header::protocol, ipv4_pseudo_header::src, iphdr::src, tcpip_continue_chksum(), iphdr::verhdrlen, and ipv4_pseudo_header::zero_padding.
|
static |
Transmit IP packet.
iobuf | I/O buffer |
tcpip | Transport-layer protocol |
st_src | Source network-layer address |
st_dest | Destination network-layer address |
netdev | Network device to use if no route found, or NULL |
trans_csum | Transport-layer checksum to complete, or NULL |
rc | Status |
This function expects a transport-layer segment and prepends the IP header
Definition at line 312 of file ipv4.c.
References ipv4_miniroute::address, AF_INET, arp_tx(), net_device_stats::bad, iphdr::chksum, DBGC, DBGC2, iphdr::dest, ENETUNREACH, free_iob(), net_device_stats::good, ipv4_miniroute::hostmask, htons, iphdr::ident, IN_IS_MULTICAST, INADDR_BROADCAST, INADDR_NONE, inet_ntoa(), iob_len(), iob_push, IP_TOS, IP_TTL, IP_VER, ipv4_pshdr_chksum(), ipv4_route(), ipv4_stats, iphdr::len, net_device::ll_addr, net_device::ll_broadcast, net_device::ll_protocol, MAX_LL_ADDR_LEN, ll_protocol::mc_hash, memset(), net_device::name, net_tx(), netdev, ipv4_miniroute::netdev, next_ident_high, ntohs, NULL, ip_statistics::out_bcast_pkts, ip_statistics::out_mcast_pkts, ip_statistics::out_no_routes, ip_statistics::out_octets, ip_statistics::out_requests, ip_statistics::out_transmits, profile_start(), profile_stop(), iphdr::protocol, rc, net_device::rx_stats, in_addr::s_addr, iphdr::service, sockaddr_in::sin_addr, sockaddr_in::sin_scope_id, iphdr::src, strerror(), tcpip_chksum(), tcpip_protocol::tcpip_proto, iphdr::ttl, iphdr::verhdrlen, and tcpip_protocol::zero_csum.
int ipv4_has_any_addr | ( | struct net_device * | netdev | ) |
Check if network device has any IPv4 address.
netdev | Network device |
has_any_addr | Network device has any IPv4 address |
Definition at line 443 of file ipv4.c.
References ipv4_miniroutes, ipv4_miniroute::list, list_for_each_entry, netdev, and ipv4_miniroute::netdev.
Referenced by dhcp_create_packet(), and ipv4_rx().
|
static |
Check if network device has a specific IPv4 address.
netdev | Network device |
addr | IPv4 address |
has_addr | Network device has this IPv4 address |
Definition at line 460 of file ipv4.c.
References addr, ipv4_miniroute::address, ipv4_miniroutes, ipv4_miniroute::list, list_for_each_entry, netdev, ipv4_miniroute::netdev, and in_addr::s_addr.
Referenced by ipv4_arp_check(), ipv4_gratuitous_arp(), and ipv4_rx().
|
static |
Process incoming packets.
iobuf | I/O buffer |
netdev | Network device |
ll_dest | Link-layer destination address |
ll_source | Link-layer destination source |
flags | Packet flags |
rc | Return status code |
This function expects an IP4 network datagram. It processes the headers and sends it to the transport layer.
Definition at line 486 of file ipv4.c.
References AF_INET, iphdr::chksum, io_buffer::data, DBGC, DBGC2, iphdr::dest, dest, EINVAL, flags, fragment_reassemble(), iphdr::frags, free_iob(), htons, iphdr::ident, ip_statistics::in_addr_errors, ip_statistics::in_bcast_pkts, ip_statistics::in_hdr_errors, ip_statistics::in_mcast_pkts, ip_statistics::in_octets, ip_statistics::in_receives, ip_statistics::in_truncated_pkts, INADDR_BROADCAST, inet_ntoa(), iob_len(), iob_pull, iob_unput, IP_MASK_HLEN, IP_MASK_MOREFRAGS, IP_MASK_OFFSET, IP_MASK_VER, IP_VER, ipv4_has_addr(), ipv4_has_any_addr(), ipv4_pshdr_chksum(), ipv4_reassembler, ipv4_stats, len, iphdr::len, LL_BROADCAST, LL_MULTICAST, memset(), netdev, ntohs, profile_start(), profile_stop(), iphdr::protocol, rc, in_addr::s_addr, sin, iphdr::src, src, st, strerror(), tcpip_chksum(), TCPIP_EMPTY_CSUM, tcpip_rx(), and iphdr::verhdrlen.
|
static |
Check existence of IPv4 address for ARP.
netdev | Network device |
net_addr | Network-layer address |
rc | Return status code |
Definition at line 621 of file ipv4.c.
References address, ENOENT, ipv4_has_addr(), and netdev.
int inet_aton | ( | const char * | string, |
struct in_addr * | in | ||
) |
Parse IPv4 address.
string | IPv4 address string |
in | IPv4 address to fill in |
ok | IPv4 address is valid |
Note that this function returns nonzero iff the address is valid, to match the standard BSD API function of the same name. Unlike most other iPXE functions, a zero therefore indicates failure.
Definition at line 641 of file ipv4.c.
References in, strtoul(), and value.
Referenced by inet_aton_fail_okx(), inet_aton_okx(), ipv4_sock_aton(), parse_ipv4_setting(), and tftp_process_multicast().
char* inet_ntoa | ( | struct in_addr | in | ) |
Convert IPv4 address to dotted-quad notation.
in | IPv4 address |
string | IPv4 address in dotted-quad notation |
Definition at line 668 of file ipv4.c.
References bytes, in, and sprintf.
Referenced by add_ipv4_miniroute(), del_ipv4_miniroute(), dhcp_deliver(), dhcp_discovery_rx(), dhcp_proxy_rx(), dhcp_proxy_tx(), dhcp_pxebs_accept(), dhcp_pxebs_rx(), dhcp_pxebs_tx(), dhcp_request_rx(), dhcp_request_tx(), efi_snp_mcast_ip_to_mac(), fetch_next_server_and_filename(), format_ipv4_setting(), gve_describe(), ibft_ipaddr(), inet_aton_okx(), inet_ntoa_okx(), ipoib_transmit(), ipv4_gratuitous_arp(), ipv4_ntoa(), ipv4_rx(), ipv4_sock_ntoa(), ipv4_tx(), pxenv_udp_open(), pxenv_udp_read(), pxenv_udp_write(), pxenv_undi_get_mcast_address(), route_ipv4_print(), start_pxebs(), tftp_apply_settings(), and tftp_process_multicast().
|
static |
Transcribe IPv4 address.
net_addr | IPv4 address |
string | IPv4 address in dotted-quad notation |
Definition at line 683 of file ipv4.c.
References inet_ntoa().
|
static |
Transcribe IPv4 socket address.
sa | Socket address |
string | Socket address in standard notation |
Definition at line 693 of file ipv4.c.
References inet_ntoa(), sa, sin, and sockaddr_in::sin_addr.
|
static |
Parse IPv4 socket address.
string | Socket address string |
sa | Socket address to fill in |
rc | Return status code |
Definition at line 706 of file ipv4.c.
References EINVAL, in, inet_aton(), sa, sin, and sockaddr_in::sin_addr.
int parse_ipv4_setting | ( | const struct setting_type *type | __unused, |
const char * | value, | ||
void * | buf, | ||
size_t | len | ||
) |
Parse IPv4 address setting value.
type | Setting type |
value | Formatted setting value |
buf | Buffer to contain raw value |
len | Length of buffer |
len | Length of raw value, or negative error |
Definition at line 765 of file ipv4.c.
References EINVAL, inet_aton(), len, memcpy(), and value.
int format_ipv4_setting | ( | const struct setting_type *type | __unused, |
const void * | raw, | ||
size_t | raw_len, | ||
char * | buf, | ||
size_t | len | ||
) |
Format IPv4 address setting value.
type | Setting type |
raw | Raw setting value |
raw_len | Length of raw setting value |
buf | Buffer to contain formatted value |
len | Length of buffer |
len | Length of formatted value, or negative error |
Definition at line 791 of file ipv4.c.
References EINVAL, inet_ntoa(), len, raw, raw_len, and snprintf().
const struct setting ip_setting __setting | ( | SETTING_IP4 | , |
ip | |||
) |
IPv4 address setting.
const struct setting netmask_setting __setting | ( | SETTING_IP4 | , |
netmask | |||
) |
IPv4 subnet mask setting.
const struct setting gateway_setting __setting | ( | SETTING_IP4 | , |
gateway | |||
) |
Default gateway setting.
|
static |
Send gratuitous ARP, if applicable.
netdev | Network device |
address | IPv4 address |
netmask | Subnet mask |
gateway | Gateway address (if any) |
rc | Return status code |
Definition at line 834 of file ipv4.c.
References address, arp_tx_request(), DBGC, inet_ntoa(), ipv4_has_addr(), net_device::name, netdev, rc, and strerror().
Referenced by ipv4_create_routes().
|
static |
Process IPv4 network device settings.
apply | Application method |
rc | Return status code |
Definition at line 863 of file ipv4.c.
References address, fetch_ipv4_setting(), for_each_netdev, IN_IS_CLASSA, IN_IS_CLASSB, IN_IS_CLASSC, INADDR_NET_CLASSA, INADDR_NET_CLASSB, INADDR_NET_CLASSC, netdev, netdev_settings(), rc, and in_addr::s_addr.
Referenced by ipv4_create_routes().
|
static |
Create IPv4 routing table based on configured settings.
rc | Return status code |
Definition at line 916 of file ipv4.c.
References add_ipv4_miniroute(), del_ipv4_miniroute(), ipv4_gratuitous_arp(), ipv4_miniroutes, ipv4_settings(), ipv4_miniroute::list, list_for_each_entry_safe, rc, and tmp.
REQUIRING_SYMBOL | ( | ipv4_protocol | ) |
REQUIRE_OBJECT | ( | icmpv4 | ) |
struct list_head ipv4_miniroutes = LIST_HEAD_INIT ( ipv4_miniroutes ) |
List of IPv4 miniroutes.
Definition at line 57 of file ipv4.c.
Referenced by add_ipv4_miniroute(), ipv4_create_routes(), ipv4_has_addr(), ipv4_has_any_addr(), ipv4_route(), and route_ipv4_print().
|
static |
|
static |
IPv4 fragment reassembler.
Definition at line 268 of file ipv4.c.
Referenced by ipv4_rx().
struct net_protocol ipv4_protocol __net_protocol |
IPv4 protocol.
AoE protocol.
struct tcpip_net_protocol ipv4_tcpip_protocol __tcpip_net_protocol |
IPv4 TCPIP net protocol.
struct arp_net_protocol ipv4_arp_protocol __arp_net_protocol |
IPv4 ARP protocol.
struct sockaddr_converter ipv4_sockaddr_converter __sockaddr_converter |
IPv4 socket address converter.
struct settings_applicator ipv4_settings_applicator __settings_applicator |
IPv4 settings applicator.