6 * Transport-network layer interface
10 FILE_LICENCE ( GPL2_OR_LATER );
13 #include <ipxe/socket.h>
15 #include <ipxe/tables.h>
16 #include <bits/tcpip.h>
22 /** Empty checksum value
24 * This is the TCP/IP checksum over a zero-length block of data.
26 #define TCPIP_EMPTY_CSUM 0xffff
28 /** TCP/IP address flags */
30 /** Bind to a privileged port (less than 1024)
32 * This value is chosen as 1024 to optimise the calculations
35 TCPIP_BIND_PRIVILEGED = 0x0400,
39 * TCP/IP socket address
41 * This contains the fields common to socket addresses for all TCP/IP
44 struct sockaddr_tcpip {
45 /** Socket address family (part of struct @c sockaddr) */
46 sa_family_t st_family;
53 * This ensures that a struct @c sockaddr_tcpip is large
54 * enough to hold a socket address for any TCP/IP address
57 char pad[ sizeof ( struct sockaddr ) -
58 ( sizeof ( sa_family_t ) /* st_family */ +
59 sizeof ( uint16_t ) /* st_flags */ +
60 sizeof ( uint16_t ) /* st_port */ ) ];
61 } __attribute__ (( packed, may_alias ));
64 * A transport-layer protocol of the TCP/IP stack (eg. UDP, TCP, etc)
66 struct tcpip_protocol {
70 * Process received packet
73 * @v netdev Network device
74 * @v st_src Partially-filled source address
75 * @v st_dest Partially-filled destination address
76 * @v pshdr_csum Pseudo-header checksum
77 * @ret rc Return status code
79 * This method takes ownership of the I/O buffer.
81 int ( * rx ) ( struct io_buffer *iobuf, struct net_device *netdev,
82 struct sockaddr_tcpip *st_src,
83 struct sockaddr_tcpip *st_dest, uint16_t pshdr_csum );
85 * Transport-layer protocol number
87 * This is a constant of the type IP_XXX
93 * A network-layer protocol of the TCP/IP stack (eg. IPV4, IPv6, etc)
95 struct tcpip_net_protocol {
98 /** Network address family */
99 sa_family_t sa_family;
100 /** Fixed header length */
105 * @v iobuf I/O buffer
106 * @v tcpip_protocol Transport-layer protocol
107 * @v st_src Source address, or NULL to use default
108 * @v st_dest Destination address
109 * @v netdev Network device (or NULL to route automatically)
110 * @v trans_csum Transport-layer checksum to complete, or NULL
111 * @ret rc Return status code
113 * This function takes ownership of the I/O buffer.
115 int ( * tx ) ( struct io_buffer *iobuf,
116 struct tcpip_protocol *tcpip_protocol,
117 struct sockaddr_tcpip *st_src,
118 struct sockaddr_tcpip *st_dest,
119 struct net_device *netdev,
120 uint16_t *trans_csum );
122 * Determine transmitting network device
124 * @v st_dest Destination address
125 * @ret netdev Network device, or NULL
127 struct net_device * ( * netdev ) ( struct sockaddr_tcpip *dest );
130 /** TCP/IP transport-layer protocol table */
131 #define TCPIP_PROTOCOLS __table ( struct tcpip_protocol, "tcpip_protocols" )
133 /** Declare a TCP/IP transport-layer protocol */
134 #define __tcpip_protocol __table_entry ( TCPIP_PROTOCOLS, 01 )
136 /** TCP/IP network-layer protocol table */
137 #define TCPIP_NET_PROTOCOLS \
138 __table ( struct tcpip_net_protocol, "tcpip_net_protocols" )
140 /** Declare a TCP/IP network-layer protocol */
141 #define __tcpip_net_protocol __table_entry ( TCPIP_NET_PROTOCOLS, 01 )
143 extern int tcpip_rx ( struct io_buffer *iobuf, struct net_device *netdev,
144 uint8_t tcpip_proto, struct sockaddr_tcpip *st_src,
145 struct sockaddr_tcpip *st_dest, uint16_t pshdr_csum,
146 struct ip_statistics *stats );
147 extern int tcpip_tx ( struct io_buffer *iobuf, struct tcpip_protocol *tcpip,
148 struct sockaddr_tcpip *st_src,
149 struct sockaddr_tcpip *st_dest,
150 struct net_device *netdev,
151 uint16_t *trans_csum );
152 extern struct net_device * tcpip_netdev ( struct sockaddr_tcpip *st_dest );
153 extern size_t tcpip_mtu ( struct sockaddr_tcpip *st_dest );
154 extern uint16_t generic_tcpip_continue_chksum ( uint16_t partial,
155 const void *data, size_t len );
156 extern uint16_t tcpip_chksum ( const void *data, size_t len );
157 extern int tcpip_bind ( struct sockaddr_tcpip *st_local,
158 int ( * available ) ( int port ) );
160 /* Use generic_tcpip_continue_chksum() if no architecture-specific
161 * version is available
163 #ifndef tcpip_continue_chksum
164 #define tcpip_continue_chksum generic_tcpip_continue_chksum
167 #endif /* _IPXE_TCPIP_H */