6 * Transport-network layer interface
11 #include <gpxe/socket.h>
13 #include <gpxe/tables.h>
18 /** Empty checksum value
20 * This is the TCP/IP checksum over a zero-length block of data.
22 #define TCPIP_EMPTY_CSUM 0xffff
25 * TCP/IP socket address
27 * This contains the fields common to socket addresses for all TCP/IP
30 struct sockaddr_tcpip
{
31 /** Socket address family (part of struct @c sockaddr) */
32 sa_family_t st_family
;
37 * This ensures that a struct @c sockaddr_tcpip is large
38 * enough to hold a socket address for any TCP/IP address
41 char pad
[ sizeof ( struct sockaddr
) -
42 ( sizeof ( sa_family_t
) + sizeof ( uint16_t ) ) ];
43 } __attribute__ (( may_alias
));
46 * A transport-layer protocol of the TCP/IP stack (eg. UDP, TCP, etc)
48 struct tcpip_protocol
{
52 * Process received packet
55 * @v st_src Partially-filled source address
56 * @v st_dest Partially-filled destination address
57 * @v pshdr_csum Pseudo-header checksum
58 * @ret rc Return status code
60 * This method takes ownership of the I/O buffer.
62 int ( * rx
) ( struct io_buffer
*iobuf
, struct sockaddr_tcpip
*st_src
,
63 struct sockaddr_tcpip
*st_dest
, uint16_t pshdr_csum
);
65 * Transport-layer protocol number
67 * This is a constant of the type IP_XXX
73 * A network-layer protocol of the TCP/IP stack (eg. IPV4, IPv6, etc)
75 struct tcpip_net_protocol
{
78 /** Network address family */
79 sa_family_t sa_family
;
84 * @v tcpip_protocol Transport-layer protocol
85 * @v st_src Source address, or NULL to use default
86 * @v st_dest Destination address
87 * @v netdev Network device (or NULL to route automatically)
88 * @v trans_csum Transport-layer checksum to complete, or NULL
89 * @ret rc Return status code
91 * This function takes ownership of the I/O buffer.
93 int ( * tx
) ( struct io_buffer
*iobuf
,
94 struct tcpip_protocol
*tcpip_protocol
,
95 struct sockaddr_tcpip
*st_src
,
96 struct sockaddr_tcpip
*st_dest
,
97 struct net_device
*netdev
,
98 uint16_t *trans_csum
);
101 /** Declare a TCP/IP transport-layer protocol */
102 #define __tcpip_protocol \
103 __table ( struct tcpip_protocol, tcpip_protocols, 01 )
105 /** Declare a TCP/IP network-layer protocol */
106 #define __tcpip_net_protocol \
107 __table ( struct tcpip_net_protocol, tcpip_net_protocols, 01 )
109 extern int tcpip_rx ( struct io_buffer
*iobuf
, uint8_t tcpip_proto
,
110 struct sockaddr_tcpip
*st_src
,
111 struct sockaddr_tcpip
*st_dest
, uint16_t pshdr_csum
);
112 extern int tcpip_tx ( struct io_buffer
*iobuf
, struct tcpip_protocol
*tcpip
,
113 struct sockaddr_tcpip
*st_src
,
114 struct sockaddr_tcpip
*st_dest
,
115 struct net_device
*netdev
,
116 uint16_t *trans_csum
);
117 extern uint16_t tcpip_continue_chksum ( uint16_t partial
,
118 const void *data
, size_t len
);
119 extern uint16_t tcpip_chksum ( const void *data
, size_t len
);
121 #endif /* _GPXE_TCPIP_H */