#include <stdint.h>
#include <gpxe/socket.h>
#include <gpxe/in.h>
#include <gpxe/tables.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... | |
Defines | |
| #define | TCPIP_EMPTY_CSUM 0xffff |
| Empty checksum value. | |
| #define | TCPIP_PROTOCOLS __table ( struct tcpip_protocol, "tcpip_protocols" ) |
| TCP/IP transport-layer protocol table. | |
| #define | __tcpip_protocol __table_entry ( TCPIP_PROTOCOLS, 01 ) |
| Declare a TCP/IP transport-layer protocol. | |
| #define | TCPIP_NET_PROTOCOLS __table ( struct tcpip_net_protocol, "tcpip_net_protocols" ) |
| TCP/IP network-layer protocol table. | |
| #define | __tcpip_net_protocol __table_entry ( TCPIP_NET_PROTOCOLS, 01 ) |
| Declare a TCP/IP network-layer protocol. | |
Functions | |
| FILE_LICENCE (GPL2_OR_LATER) | |
| int | tcpip_rx (struct io_buffer *iobuf, uint8_t tcpip_proto, struct sockaddr_tcpip *st_src, struct sockaddr_tcpip *st_dest, uint16_t pshdr_csum) |
| Process a received TCP/IP packet. | |
| 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. | |
| uint16_t | tcpip_continue_chksum (uint16_t partial, const void *data, size_t len) |
| Calculate continued TCP/IP checkum. | |
| uint16_t | tcpip_chksum (const void *data, size_t len) |
| Calculate TCP/IP checkum. | |
Definition in file tcpip.h.
| #define TCPIP_EMPTY_CSUM 0xffff |
Empty checksum value.
This is the TCP/IP checksum over a zero-length block of data.
Definition at line 24 of file tcpip.h.
Referenced by ipv4_rx(), and tcpip_chksum().
| #define TCPIP_PROTOCOLS __table ( struct tcpip_protocol, "tcpip_protocols" ) |
TCP/IP transport-layer protocol table.
Definition at line 104 of file tcpip.h.
Referenced by tcpip_rx().
struct tcpip_protocol icmp_protocol __tcpip_protocol __table_entry ( TCPIP_PROTOCOLS, 01 ) [read] |
| #define TCPIP_NET_PROTOCOLS __table ( struct tcpip_net_protocol, "tcpip_net_protocols" ) |
TCP/IP network-layer protocol table.
Definition at line 110 of file tcpip.h.
Referenced by tcpip_tx().
| #define __tcpip_net_protocol __table_entry ( TCPIP_NET_PROTOCOLS, 01 ) |
| FILE_LICENCE | ( | GPL2_OR_LATER | ) |
| int tcpip_rx | ( | struct io_buffer * | iobuf, | |
| uint8_t | tcpip_proto, | |||
| struct sockaddr_tcpip * | st_src, | |||
| struct sockaddr_tcpip * | st_dest, | |||
| uint16_t | pshdr_csum | |||
| ) |
Process a received TCP/IP packet.
| iobuf | I/O buffer | |
| tcpip_proto | Transport-layer protocol number | |
| st_src | Partially-filled source address | |
| st_dest | Partially-filled destination address | |
| pshdr_csum | Pseudo-header checksum |
| rc | Return status code |
Definition at line 34 of file tcpip.c.
References DBG, EPROTONOSUPPORT, for_each_table_entry, free_iob(), tcpip_protocol::name, tcpip_protocol::rx, tcpip_protocol::tcpip_proto, and TCPIP_PROTOCOLS.
Referenced by ipv4_rx(), and ipv6_process_nxt_hdr().
00037 { 00038 struct tcpip_protocol *tcpip; 00039 00040 /* Hand off packet to the appropriate transport-layer protocol */ 00041 for_each_table_entry ( tcpip, TCPIP_PROTOCOLS ) { 00042 if ( tcpip->tcpip_proto == tcpip_proto ) { 00043 DBG ( "TCP/IP received %s packet\n", tcpip->name ); 00044 return tcpip->rx ( iobuf, st_src, st_dest, pshdr_csum ); 00045 } 00046 } 00047 00048 DBG ( "Unrecognised TCP/IP protocol %d\n", tcpip_proto ); 00049 free_iob ( iobuf ); 00050 return -EPROTONOSUPPORT; 00051 }
| 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 63 of file tcpip.c.
References DBG, EAFNOSUPPORT, for_each_table_entry, free_iob(), tcpip_net_protocol::name, tcpip_net_protocol::sa_family, sockaddr_tcpip::st_family, TCPIP_NET_PROTOCOLS, and tcpip_net_protocol::tx.
Referenced by icmp6_send_solicit(), icmp_rx(), tcp_xmit(), tcp_xmit_reset(), and udp_tx().
00065 { 00066 struct tcpip_net_protocol *tcpip_net; 00067 00068 /* Hand off packet to the appropriate network-layer protocol */ 00069 for_each_table_entry ( tcpip_net, TCPIP_NET_PROTOCOLS ) { 00070 if ( tcpip_net->sa_family == st_dest->st_family ) { 00071 DBG ( "TCP/IP sending %s packet\n", tcpip_net->name ); 00072 return tcpip_net->tx ( iobuf, tcpip_protocol, st_src, 00073 st_dest, netdev, trans_csum ); 00074 } 00075 } 00076 00077 DBG ( "Unrecognised TCP/IP address family %d\n", st_dest->st_family ); 00078 free_iob ( iobuf ); 00079 return -EAFNOSUPPORT; 00080 }
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 |
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 100 of file tcpip.c.
References be16_to_cpu, and le16_to_cpu.
Referenced by ipv4_pshdr_chksum(), ipv6_tx_csum(), tcp_rx(), tcpip_chksum(), and udp_rx().
00101 { 00102 unsigned int cksum = ( ( ~partial ) & 0xffff ); 00103 unsigned int value; 00104 unsigned int i; 00105 00106 for ( i = 0 ; i < len ; i++ ) { 00107 value = * ( ( uint8_t * ) data + i ); 00108 if ( i & 1 ) { 00109 /* Odd bytes: swap on little-endian systems */ 00110 value = be16_to_cpu ( value ); 00111 } else { 00112 /* Even bytes: swap on big-endian systems */ 00113 value = le16_to_cpu ( value ); 00114 } 00115 cksum += value; 00116 if ( cksum > 0xffff ) 00117 cksum -= 0xffff; 00118 } 00119 00120 return ( ~cksum ); 00121 }
Calculate TCP/IP checkum.
| data | Data buffer | |
| len | Length of data buffer |
| cksum | Checksum, in network byte order |
Definition at line 133 of file tcpip.c.
References tcpip_continue_chksum(), and TCPIP_EMPTY_CSUM.
Referenced by gdbudp_send(), icmp6_send_solicit(), icmp_rx(), ipv4_rx(), ipv4_tx(), tcp_xmit(), tcp_xmit_reset(), and udp_tx().
00133 { 00134 return tcpip_continue_chksum ( TCPIP_EMPTY_CSUM, data, len ); 00135 }
1.5.7.1