Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. #ifndef _IPXE_TCPIP_H
  2. #define _IPXE_TCPIP_H
  3. /** @file
  4. *
  5. * Transport-network layer interface
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  9. #include <stdint.h>
  10. #include <ipxe/socket.h>
  11. #include <ipxe/in.h>
  12. #include <ipxe/tables.h>
  13. extern uint16_t generic_tcpip_continue_chksum ( uint16_t partial,
  14. const void *data, size_t len );
  15. #include <bits/tcpip.h>
  16. struct io_buffer;
  17. struct net_device;
  18. struct ip_statistics;
  19. /** Positive zero checksum value */
  20. #define TCPIP_POSITIVE_ZERO_CSUM 0x0000
  21. /** Negative zero checksum value */
  22. #define TCPIP_NEGATIVE_ZERO_CSUM 0xffff
  23. /** Empty checksum value
  24. *
  25. * All of our TCP/IP checksum algorithms will return only the positive
  26. * representation of zero (0x0000) for a zero checksum over non-zero
  27. * input data. This property arises since the end-around carry used
  28. * to mimic one's complement addition using unsigned arithmetic
  29. * prevents the running total from ever returning to 0x0000. The
  30. * running total will therefore use only the negative representation
  31. * of zero (0xffff). Since the return value is the one's complement
  32. * negation of the running total (calculated by simply bit-inverting
  33. * the running total), the return value will therefore use only the
  34. * positive representation of zero (0x0000).
  35. *
  36. * It is a very common misconception (found in many places such as
  37. * RFC1624) that this is a property guaranteed by the underlying
  38. * mathematics. It is not; the choice of which zero representation is
  39. * used is merely an artifact of the software implementation of the
  40. * checksum algorithm.
  41. *
  42. * For consistency, we choose to use the positive representation of
  43. * zero (0x0000) for the checksum of a zero-length block of data.
  44. * This ensures that all of our TCP/IP checksum algorithms will return
  45. * only the positive representation of zero (0x0000) for a zero
  46. * checksum (regardless of the input data).
  47. */
  48. #define TCPIP_EMPTY_CSUM TCPIP_POSITIVE_ZERO_CSUM
  49. /** TCP/IP address flags */
  50. enum tcpip_st_flags {
  51. /** Bind to a privileged port (less than 1024)
  52. *
  53. * This value is chosen as 1024 to optimise the calculations
  54. * in tcpip_bind().
  55. */
  56. TCPIP_BIND_PRIVILEGED = 0x0400,
  57. };
  58. /**
  59. * TCP/IP socket address
  60. *
  61. * This contains the fields common to socket addresses for all TCP/IP
  62. * address families.
  63. */
  64. struct sockaddr_tcpip {
  65. /** Socket address family (part of struct @c sockaddr) */
  66. sa_family_t st_family;
  67. /** Flags */
  68. uint16_t st_flags;
  69. /** TCP/IP port */
  70. uint16_t st_port;
  71. /** Scope ID
  72. *
  73. * For link-local or multicast addresses, this is the network
  74. * device index.
  75. */
  76. uint16_t st_scope_id;
  77. /** Padding
  78. *
  79. * This ensures that a struct @c sockaddr_tcpip is large
  80. * enough to hold a socket address for any TCP/IP address
  81. * family.
  82. */
  83. char pad[ sizeof ( struct sockaddr ) -
  84. ( sizeof ( sa_family_t ) /* st_family */ +
  85. sizeof ( uint16_t ) /* st_flags */ +
  86. sizeof ( uint16_t ) /* st_port */ +
  87. sizeof ( uint16_t ) /* st_scope_id */ ) ];
  88. } __attribute__ (( packed, may_alias ));
  89. /**
  90. * A transport-layer protocol of the TCP/IP stack (eg. UDP, TCP, etc)
  91. */
  92. struct tcpip_protocol {
  93. /** Protocol name */
  94. const char *name;
  95. /**
  96. * Process received packet
  97. *
  98. * @v iobuf I/O buffer
  99. * @v netdev Network device
  100. * @v st_src Partially-filled source address
  101. * @v st_dest Partially-filled destination address
  102. * @v pshdr_csum Pseudo-header checksum
  103. * @ret rc Return status code
  104. *
  105. * This method takes ownership of the I/O buffer.
  106. */
  107. int ( * rx ) ( struct io_buffer *iobuf, struct net_device *netdev,
  108. struct sockaddr_tcpip *st_src,
  109. struct sockaddr_tcpip *st_dest, uint16_t pshdr_csum );
  110. /** Preferred zero checksum value
  111. *
  112. * The checksum is a one's complement value: zero may be
  113. * represented by either positive zero (0x0000) or negative
  114. * zero (0xffff).
  115. */
  116. uint16_t zero_csum;
  117. /**
  118. * Transport-layer protocol number
  119. *
  120. * This is a constant of the type IP_XXX
  121. */
  122. uint8_t tcpip_proto;
  123. };
  124. /**
  125. * A network-layer protocol of the TCP/IP stack (eg. IPV4, IPv6, etc)
  126. */
  127. struct tcpip_net_protocol {
  128. /** Protocol name */
  129. const char *name;
  130. /** Network address family */
  131. sa_family_t sa_family;
  132. /** Fixed header length */
  133. size_t header_len;
  134. /** Network-layer protocol */
  135. struct net_protocol *net_protocol;
  136. /**
  137. * Transmit packet
  138. *
  139. * @v iobuf I/O buffer
  140. * @v tcpip_protocol Transport-layer protocol
  141. * @v st_src Source address, or NULL to use default
  142. * @v st_dest Destination address
  143. * @v netdev Network device (or NULL to route automatically)
  144. * @v trans_csum Transport-layer checksum to complete, or NULL
  145. * @ret rc Return status code
  146. *
  147. * This function takes ownership of the I/O buffer.
  148. */
  149. int ( * tx ) ( struct io_buffer *iobuf,
  150. struct tcpip_protocol *tcpip_protocol,
  151. struct sockaddr_tcpip *st_src,
  152. struct sockaddr_tcpip *st_dest,
  153. struct net_device *netdev,
  154. uint16_t *trans_csum );
  155. /**
  156. * Determine transmitting network device
  157. *
  158. * @v st_dest Destination address
  159. * @ret netdev Network device, or NULL
  160. */
  161. struct net_device * ( * netdev ) ( struct sockaddr_tcpip *dest );
  162. };
  163. /** TCP/IP transport-layer protocol table */
  164. #define TCPIP_PROTOCOLS __table ( struct tcpip_protocol, "tcpip_protocols" )
  165. /** Declare a TCP/IP transport-layer protocol */
  166. #define __tcpip_protocol __table_entry ( TCPIP_PROTOCOLS, 01 )
  167. /** TCP/IP network-layer protocol table */
  168. #define TCPIP_NET_PROTOCOLS \
  169. __table ( struct tcpip_net_protocol, "tcpip_net_protocols" )
  170. /** Declare a TCP/IP network-layer protocol */
  171. #define __tcpip_net_protocol __table_entry ( TCPIP_NET_PROTOCOLS, 01 )
  172. extern int tcpip_rx ( struct io_buffer *iobuf, struct net_device *netdev,
  173. uint8_t tcpip_proto, struct sockaddr_tcpip *st_src,
  174. struct sockaddr_tcpip *st_dest, uint16_t pshdr_csum,
  175. struct ip_statistics *stats );
  176. extern int tcpip_tx ( struct io_buffer *iobuf, struct tcpip_protocol *tcpip,
  177. struct sockaddr_tcpip *st_src,
  178. struct sockaddr_tcpip *st_dest,
  179. struct net_device *netdev,
  180. uint16_t *trans_csum );
  181. extern struct tcpip_net_protocol * tcpip_net_protocol ( sa_family_t sa_family );
  182. extern struct net_device * tcpip_netdev ( struct sockaddr_tcpip *st_dest );
  183. extern size_t tcpip_mtu ( struct sockaddr_tcpip *st_dest );
  184. extern uint16_t tcpip_chksum ( const void *data, size_t len );
  185. extern int tcpip_bind ( struct sockaddr_tcpip *st_local,
  186. int ( * available ) ( int port ) );
  187. #endif /* _IPXE_TCPIP_H */