6 * Transport-network layer interface
11 #include <gpxe/socket.h>
13 #include <gpxe/tables.h>
17 /** Empty checksum value
19 * This is the TCP/IP checksum over a zero-length block of data.
21 #define TCPIP_EMPTY_CSUM 0xffff
23 /** Length of a @c struct @c sockaddr_tcpip */
24 #define SA_TCPIP_LEN 32
27 * TCP/IP socket address
29 * This contains the fields common to socket addresses for all TCP/IP
32 struct sockaddr_tcpip {
33 /** Socket address family (part of struct @c sockaddr) */
34 sa_family_t st_family;
39 * This ensures that a struct @c sockaddr_tcpip is large
40 * enough to hold a socket address for any TCP/IP address
43 char pad[SA_TCPIP_LEN - sizeof ( sa_family_t ) - sizeof ( uint16_t )];
47 * A transport-layer protocol of the TCP/IP stack (eg. UDP, TCP, etc)
49 struct tcpip_protocol {
53 * Process received packet
55 * @v pkb Packet buffer
56 * @v st_src Partially-filled source address
57 * @v st_dest Partially-filled destination address
58 * @v pshdr_csum Pseudo-header checksum
59 * @ret rc Return status code
61 * This method takes ownership of the packet buffer.
63 int ( * rx ) ( struct pk_buff *pkb, struct sockaddr_tcpip *st_src,
64 struct sockaddr_tcpip *st_dest, uint16_t pshdr_csum );
66 * Transport-layer protocol number
68 * This is a constant of the type IP_XXX
74 * A network-layer protocol of the TCP/IP stack (eg. IPV4, IPv6, etc)
76 struct tcpip_net_protocol {
79 /** Network address family */
80 sa_family_t sa_family;
84 * @v pkb Packet buffer
85 * @v tcpip_protocol Transport-layer protocol
86 * @v st_dest Destination address
87 * @v trans_csum Transport-layer checksum to complete, or NULL
88 * @ret rc Return status code
90 * This function takes ownership of the packet buffer.
92 int ( * tx ) ( struct pk_buff *pkb,
93 struct tcpip_protocol *tcpip_protocol,
94 struct sockaddr_tcpip *st_dest, uint16_t *trans_csum );
97 /** Declare a TCP/IP transport-layer protocol */
98 #define __tcpip_protocol __table ( tcpip_protocols, 01 )
100 /** Declare a TCP/IP network-layer protocol */
101 #define __tcpip_net_protocol __table ( tcpip_net_protocols, 01 )
103 extern int tcpip_rx ( struct pk_buff *pkb, uint8_t tcpip_proto,
104 struct sockaddr_tcpip *st_src,
105 struct sockaddr_tcpip *st_dest, uint16_t pshdr_csum );
106 extern int tcpip_tx ( struct pk_buff *pkb, struct tcpip_protocol *tcpip,
107 struct sockaddr_tcpip *st_dest, uint16_t *trans_csum );
108 extern uint16_t tcpip_continue_chksum ( uint16_t partial,
109 const void *data, size_t len );
110 extern uint16_t tcpip_chksum ( const void *data, size_t len );
112 #endif /* _GPXE_TCPIP_H */