6 * Transport-network layer interface
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
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 * For link-local or multicast addresses, this is the network
59 * This ensures that a struct @c sockaddr_tcpip is large
60 * enough to hold a socket address for any TCP/IP address
63 char pad[ sizeof ( struct sockaddr ) -
64 ( sizeof ( sa_family_t ) /* st_family */ +
65 sizeof ( uint16_t ) /* st_flags */ +
66 sizeof ( uint16_t ) /* st_port */ +
67 sizeof ( uint16_t ) /* st_scope_id */ ) ];
68 } __attribute__ (( packed, may_alias ));
71 * A transport-layer protocol of the TCP/IP stack (eg. UDP, TCP, etc)
73 struct tcpip_protocol {
77 * Process received packet
80 * @v netdev Network device
81 * @v st_src Partially-filled source address
82 * @v st_dest Partially-filled destination address
83 * @v pshdr_csum Pseudo-header checksum
84 * @ret rc Return status code
86 * This method takes ownership of the I/O buffer.
88 int ( * rx ) ( struct io_buffer *iobuf, struct net_device *netdev,
89 struct sockaddr_tcpip *st_src,
90 struct sockaddr_tcpip *st_dest, uint16_t pshdr_csum );
92 * Transport-layer protocol number
94 * This is a constant of the type IP_XXX
100 * A network-layer protocol of the TCP/IP stack (eg. IPV4, IPv6, etc)
102 struct tcpip_net_protocol {
105 /** Network address family */
106 sa_family_t sa_family;
107 /** Fixed header length */
112 * @v iobuf I/O buffer
113 * @v tcpip_protocol Transport-layer protocol
114 * @v st_src Source address, or NULL to use default
115 * @v st_dest Destination address
116 * @v netdev Network device (or NULL to route automatically)
117 * @v trans_csum Transport-layer checksum to complete, or NULL
118 * @ret rc Return status code
120 * This function takes ownership of the I/O buffer.
122 int ( * tx ) ( struct io_buffer *iobuf,
123 struct tcpip_protocol *tcpip_protocol,
124 struct sockaddr_tcpip *st_src,
125 struct sockaddr_tcpip *st_dest,
126 struct net_device *netdev,
127 uint16_t *trans_csum );
129 * Determine transmitting network device
131 * @v st_dest Destination address
132 * @ret netdev Network device, or NULL
134 struct net_device * ( * netdev ) ( struct sockaddr_tcpip *dest );
137 /** TCP/IP transport-layer protocol table */
138 #define TCPIP_PROTOCOLS __table ( struct tcpip_protocol, "tcpip_protocols" )
140 /** Declare a TCP/IP transport-layer protocol */
141 #define __tcpip_protocol __table_entry ( TCPIP_PROTOCOLS, 01 )
143 /** TCP/IP network-layer protocol table */
144 #define TCPIP_NET_PROTOCOLS \
145 __table ( struct tcpip_net_protocol, "tcpip_net_protocols" )
147 /** Declare a TCP/IP network-layer protocol */
148 #define __tcpip_net_protocol __table_entry ( TCPIP_NET_PROTOCOLS, 01 )
150 extern int tcpip_rx ( struct io_buffer *iobuf, struct net_device *netdev,
151 uint8_t tcpip_proto, struct sockaddr_tcpip *st_src,
152 struct sockaddr_tcpip *st_dest, uint16_t pshdr_csum,
153 struct ip_statistics *stats );
154 extern int tcpip_tx ( struct io_buffer *iobuf, struct tcpip_protocol *tcpip,
155 struct sockaddr_tcpip *st_src,
156 struct sockaddr_tcpip *st_dest,
157 struct net_device *netdev,
158 uint16_t *trans_csum );
159 extern struct net_device * tcpip_netdev ( struct sockaddr_tcpip *st_dest );
160 extern size_t tcpip_mtu ( struct sockaddr_tcpip *st_dest );
161 extern uint16_t generic_tcpip_continue_chksum ( uint16_t partial,
162 const void *data, size_t len );
163 extern uint16_t tcpip_chksum ( const void *data, size_t len );
164 extern int tcpip_bind ( struct sockaddr_tcpip *st_local,
165 int ( * available ) ( int port ) );
167 /* Use generic_tcpip_continue_chksum() if no architecture-specific
168 * version is available
170 #ifndef tcpip_continue_chksum
171 #define tcpip_continue_chksum generic_tcpip_continue_chksum
174 #endif /* _IPXE_TCPIP_H */