1 #ifndef _GPXE_TCPIP_H 2 #define _GPXE_TCPIP_H 3 4 /** @file 5 * 6 * Transport-network layer interface 7 * 8 */ 9 10 FILE_LICENCE ( GPL2_OR_LATER ); 11 12 #include <stdint.h> 13 #include <gpxe/socket.h> 14 #include <gpxe/in.h> 15 #include <gpxe/tables.h> 16 17 struct io_buffer; 18 struct net_device; 19 20 /** Empty checksum value 21 * 22 * This is the TCP/IP checksum over a zero-length block of data. 23 */ 24 #define TCPIP_EMPTY_CSUM 0xffff 25 26 /** 27 * TCP/IP socket address 28 * 29 * This contains the fields common to socket addresses for all TCP/IP 30 * address families. 31 */ 32 struct sockaddr_tcpip { 33 /** Socket address family (part of struct @c sockaddr) */ 34 sa_family_t st_family; 35 /** TCP/IP port */ 36 uint16_t st_port; 37 /** Padding 38 * 39 * This ensures that a struct @c sockaddr_tcpip is large 40 * enough to hold a socket address for any TCP/IP address 41 * family. 42 */ 43 char pad[ sizeof ( struct sockaddr ) - 44 ( sizeof ( sa_family_t ) + sizeof ( uint16_t ) ) ]; 45 } __attribute__ (( may_alias )); 46 47 /** 48 * A transport-layer protocol of the TCP/IP stack (eg. UDP, TCP, etc) 49 */ 50 struct tcpip_protocol { 51 /** Protocol name */ 52 const char *name; 53 /** 54 * Process received packet 55 * 56 * @v iobuf I/O buffer 57 * @v st_src Partially-filled source address 58 * @v st_dest Partially-filled destination address 59 * @v pshdr_csum Pseudo-header checksum 60 * @ret rc Return status code 61 * 62 * This method takes ownership of the I/O buffer. 63 */ 64 int ( * rx ) ( struct io_buffer *iobuf, struct sockaddr_tcpip *st_src, 65 struct sockaddr_tcpip *st_dest, uint16_t pshdr_csum ); 66 /** 67 * Transport-layer protocol number 68 * 69 * This is a constant of the type IP_XXX 70 */ 71 uint8_t tcpip_proto; 72 }; 73 74 /** 75 * A network-layer protocol of the TCP/IP stack (eg. IPV4, IPv6, etc) 76 */ 77 struct tcpip_net_protocol { 78 /** Protocol name */ 79 const char *name; 80 /** Network address family */ 81 sa_family_t sa_family; 82 /** 83 * Transmit packet 84 * 85 * @v iobuf I/O buffer 86 * @v tcpip_protocol Transport-layer protocol 87 * @v st_src Source address, or NULL to use default 88 * @v st_dest Destination address 89 * @v netdev Network device (or NULL to route automatically) 90 * @v trans_csum Transport-layer checksum to complete, or NULL 91 * @ret rc Return status code 92 * 93 * This function takes ownership of the I/O buffer. 94 */ 95 int ( * tx ) ( struct io_buffer *iobuf, 96 struct tcpip_protocol *tcpip_protocol, 97 struct sockaddr_tcpip *st_src, 98 struct sockaddr_tcpip *st_dest, 99 struct net_device *netdev, 100 uint16_t *trans_csum ); 101 }; 102 103 /** TCP/IP transport-layer protocol table */ 104 #define TCPIP_PROTOCOLS __table ( struct tcpip_protocol, "tcpip_protocols" ) 105 106 /** Declare a TCP/IP transport-layer protocol */ 107 #define __tcpip_protocol __table_entry ( TCPIP_PROTOCOLS, 01 ) 108 109 /** TCP/IP network-layer protocol table */ 110 #define TCPIP_NET_PROTOCOLS \ 111 __table ( struct tcpip_net_protocol, "tcpip_net_protocols" ) 112 113 /** Declare a TCP/IP network-layer protocol */ 114 #define __tcpip_net_protocol __table_entry ( TCPIP_NET_PROTOCOLS, 01 ) 115 116 extern int tcpip_rx ( struct io_buffer *iobuf, uint8_t tcpip_proto, 117 struct sockaddr_tcpip *st_src, 118 struct sockaddr_tcpip *st_dest, uint16_t pshdr_csum ); 119 extern int tcpip_tx ( struct io_buffer *iobuf, struct tcpip_protocol *tcpip, 120 struct sockaddr_tcpip *st_src, 121 struct sockaddr_tcpip *st_dest, 122 struct net_device *netdev, 123 uint16_t *trans_csum ); 124 extern uint16_t tcpip_continue_chksum ( uint16_t partial, 125 const void *data, size_t len ); 126 extern uint16_t tcpip_chksum ( const void *data, size_t len ); 127 128 #endif /* _GPXE_TCPIP_H */ 129