iPXE
|
Transport-network layer interface. More...
#include <stdint.h>
#include <ipxe/socket.h>
#include <ipxe/in.h>
#include <ipxe/tables.h>
#include <bits/tcpip.h>
Go to the source code of this file.
Data Structures | |
struct | sockaddr_tcpip |
TCP/IP socket address. More... | |
struct | tcpip_protocol |
A transport-layer protocol of the TCP/IP stack (eg. More... | |
struct | tcpip_net_protocol |
A network-layer protocol of the TCP/IP stack (eg. More... | |
Macros | |
#define | TCPIP_POSITIVE_ZERO_CSUM 0x0000 |
Positive zero checksum value. More... | |
#define | TCPIP_NEGATIVE_ZERO_CSUM 0xffff |
Negative zero checksum value. More... | |
#define | TCPIP_EMPTY_CSUM TCPIP_POSITIVE_ZERO_CSUM |
Empty checksum value. More... | |
#define | TCPIP_PROTOCOLS __table ( struct tcpip_protocol, "tcpip_protocols" ) |
TCP/IP transport-layer protocol table. More... | |
#define | __tcpip_protocol __table_entry ( TCPIP_PROTOCOLS, 01 ) |
Declare a TCP/IP transport-layer protocol. More... | |
#define | TCPIP_NET_PROTOCOLS __table ( struct tcpip_net_protocol, "tcpip_net_protocols" ) |
TCP/IP network-layer protocol table. More... | |
#define | __tcpip_net_protocol __table_entry ( TCPIP_NET_PROTOCOLS, 01 ) |
Declare a TCP/IP network-layer protocol. More... | |
Enumerations | |
enum | tcpip_st_flags { TCPIP_BIND_PRIVILEGED = 0x0400 } |
TCP/IP address flags. More... | |
Functions | |
FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) | |
uint16_t | generic_tcpip_continue_chksum (uint16_t partial, const void *data, size_t len) |
Calculate continued TCP/IP checkum. More... | |
int | tcpip_rx (struct io_buffer *iobuf, struct net_device *netdev, uint8_t tcpip_proto, struct sockaddr_tcpip *st_src, struct sockaddr_tcpip *st_dest, uint16_t pshdr_csum, struct ip_statistics *stats) |
Process a received TCP/IP packet. More... | |
int | tcpip_tx (struct io_buffer *iobuf, struct tcpip_protocol *tcpip, struct sockaddr_tcpip *st_src, struct sockaddr_tcpip *st_dest, struct net_device *netdev, uint16_t *trans_csum) |
Transmit a TCP/IP packet. More... | |
struct tcpip_net_protocol * | tcpip_net_protocol (sa_family_t sa_family) |
Find TCP/IP network-layer protocol. More... | |
struct net_device * | tcpip_netdev (struct sockaddr_tcpip *st_dest) |
Determine transmitting network device. More... | |
size_t | tcpip_mtu (struct sockaddr_tcpip *st_dest) |
Determine maximum transmission unit. More... | |
uint16_t | tcpip_chksum (const void *data, size_t len) |
Calculate TCP/IP checkum. More... | |
int | tcpip_bind (struct sockaddr_tcpip *st_local, int(*available)(int port)) |
Bind to local TCP/IP port. More... | |
Transport-network layer interface.
Definition in file tcpip.h.
#define TCPIP_POSITIVE_ZERO_CSUM 0x0000 |
#define TCPIP_NEGATIVE_ZERO_CSUM 0xffff |
#define TCPIP_EMPTY_CSUM TCPIP_POSITIVE_ZERO_CSUM |
Empty checksum value.
All of our TCP/IP checksum algorithms will return only the positive representation of zero (0x0000) for a zero checksum over non-zero input data. This property arises since the end-around carry used to mimic one's complement addition using unsigned arithmetic prevents the running total from ever returning to 0x0000. The running total will therefore use only the negative representation of zero (0xffff). Since the return value is the one's complement negation of the running total (calculated by simply bit-inverting the running total), the return value will therefore use only the positive representation of zero (0x0000).
It is a very common misconception (found in many places such as RFC1624) that this is a property guaranteed by the underlying mathematics. It is not; the choice of which zero representation is used is merely an artifact of the software implementation of the checksum algorithm.
For consistency, we choose to use the positive representation of zero (0x0000) for the checksum of a zero-length block of data. This ensures that all of our TCP/IP checksum algorithms will return only the positive representation of zero (0x0000) for a zero checksum (regardless of the input data).
#define TCPIP_PROTOCOLS __table ( struct tcpip_protocol, "tcpip_protocols" ) |
struct tcpip_protocol udp_protocol __tcpip_protocol __table_entry ( TCPIP_PROTOCOLS, 01 ) |
#define TCPIP_NET_PROTOCOLS __table ( struct tcpip_net_protocol, "tcpip_net_protocols" ) |
#define __tcpip_net_protocol __table_entry ( TCPIP_NET_PROTOCOLS, 01 ) |
enum tcpip_st_flags |
FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
Calculate continued TCP/IP checkum.
partial | Checksum of already-summed data, in network byte order |
data | Data buffer |
len | Length of data buffer |
cksum | Updated checksum, in network byte order |
Calculates a TCP/IP-style 16-bit checksum over the data block. The checksum is returned in network byte order.
This function may be used to add new data to an existing checksum. The function assumes that both the old data and the new data start on even byte offsets; if this is not the case then you will need to byte-swap either the input partial checksum, the output checksum, or both. Deciding which to swap is left as an exercise for the interested reader.
Definition at line 170 of file tcpip.c.
References be16_to_cpu, data, le16_to_cpu, len, and value.
Referenced by tcpip_okx(), and tcpip_random_okx().
int tcpip_rx | ( | struct io_buffer * | iobuf, |
struct net_device * | netdev, | ||
uint8_t | tcpip_proto, | ||
struct sockaddr_tcpip * | st_src, | ||
struct sockaddr_tcpip * | st_dest, | ||
uint16_t | pshdr_csum, | ||
struct ip_statistics * | stats | ||
) |
Process a received TCP/IP packet.
iobuf | I/O buffer |
netdev | Network device |
tcpip_proto | Transport-layer protocol number |
st_src | Partially-filled source address |
st_dest | Partially-filled destination address |
pshdr_csum | Pseudo-header checksum |
stats | IP statistics |
rc | Return status code |
This function expects a transport-layer segment from the network layer. The network layer should fill in as much as it can of the source and destination addresses (i.e. it should fill in the address family and the network-layer addresses, but leave the ports and the rest of the structures as zero).
Definition at line 40 of file tcpip.c.
References DBG, EPROTONOSUPPORT, for_each_table_entry, free_iob(), ip_statistics::in_delivers, ip_statistics::in_unknown_protos, tcpip_protocol::name, netdev, tcpip_protocol::rx, tcpip_protocol::tcpip_proto, and TCPIP_PROTOCOLS.
int tcpip_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 a TCP/IP packet.
iobuf | I/O buffer |
tcpip_protocol | Transport-layer protocol |
st_src | Source address, or NULL to use route default |
st_dest | Destination address |
netdev | Network device to use if no route found, or NULL |
trans_csum | Transport-layer checksum to complete, or NULL |
rc | Return status code |
Definition at line 91 of file tcpip.c.
References DBG, EAFNOSUPPORT, free_iob(), tcpip_net_protocol::name, netdev, sockaddr_tcpip::st_family, tcpip_net_protocol(), and tcpip_net_protocol::tx.
Referenced by icmp_tx_echo(), ndp_tx_ll_addr(), tcp_xmit_reset(), tcp_xmit_sack(), and udp_tx().
struct tcpip_net_protocol* tcpip_net_protocol | ( | sa_family_t | sa_family | ) |
Find TCP/IP network-layer protocol.
sa_family | Address family |
tcpip_net | TCP/IP network-layer protocol, or NULL if not found |
Definition at line 68 of file tcpip.c.
References DBG, for_each_table_entry, NULL, tcpip_net_protocol::sa_family, and TCPIP_NET_PROTOCOLS.
Referenced by efi_pxe_install(), efi_pxe_start(), efi_pxe_udp_deliver(), tcpip_mtu(), tcpip_netdev(), and tcpip_tx().
struct net_device* tcpip_netdev | ( | struct sockaddr_tcpip * | st_dest | ) |
Determine transmitting network device.
st_dest | Destination address |
netdev | Network device, or NULL |
Definition at line 114 of file tcpip.c.
References tcpip_net_protocol::netdev, NULL, sockaddr_tcpip::st_family, and tcpip_net_protocol().
Referenced by efi_iscsi_path(), ibft_fill_target_nic_association(), and ibft_netdev_is_required().
size_t tcpip_mtu | ( | struct sockaddr_tcpip * | st_dest | ) |
Determine maximum transmission unit.
st_dest | Destination address |
mtu | Maximum transmission unit |
Definition at line 131 of file tcpip.c.
References tcpip_net_protocol::header_len, mtu, net_device::mtu, netdev, tcpip_net_protocol::netdev, sockaddr_tcpip::st_family, and tcpip_net_protocol().
Referenced by tcp_open().
Calculate TCP/IP checkum.
data | Data buffer |
len | Length of data buffer |
cksum | Checksum, in network byte order |
Calculates a TCP/IP-style 16-bit checksum over the data block. The checksum is returned in network byte order.
Definition at line 203 of file tcpip.c.
References data, len, tcpip_continue_chksum(), and TCPIP_EMPTY_CSUM.
Referenced by gdbudp_send(), icmp_tx_echo(), icmpv4_rx(), ipv4_rx(), ipv4_tx(), ndp_tx_ll_addr(), tcp_xmit_reset(), tcp_xmit_sack(), and udp_tx().
int tcpip_bind | ( | struct sockaddr_tcpip * | st_local, |
int(*)(int port) | available | ||
) |
Bind to local TCP/IP port.
st_local | Local TCP/IP socket address, or NULL |
available | Function to check port availability |
port | Local port number, or negative error |
Definition at line 214 of file tcpip.c.
References EADDRINUSE, flags, ntohs, offset, random(), sockaddr_tcpip::st_flags, sockaddr_tcpip::st_port, and TCPIP_BIND_PRIVILEGED.
Referenced by ping_open(), tcp_open(), and udp_open_common().