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.

tcpip.h 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #ifndef _GPXE_TCPIP_H
  2. #define _GPXE_TCPIP_H
  3. /** @file
  4. *
  5. * Transport-network layer interface
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER );
  9. #include <stdint.h>
  10. #include <gpxe/socket.h>
  11. #include <gpxe/in.h>
  12. #include <gpxe/tables.h>
  13. struct io_buffer;
  14. struct net_device;
  15. /** Empty checksum value
  16. *
  17. * This is the TCP/IP checksum over a zero-length block of data.
  18. */
  19. #define TCPIP_EMPTY_CSUM 0xffff
  20. /**
  21. * TCP/IP socket address
  22. *
  23. * This contains the fields common to socket addresses for all TCP/IP
  24. * address families.
  25. */
  26. struct sockaddr_tcpip {
  27. /** Socket address family (part of struct @c sockaddr) */
  28. sa_family_t st_family;
  29. /** TCP/IP port */
  30. uint16_t st_port;
  31. /** Padding
  32. *
  33. * This ensures that a struct @c sockaddr_tcpip is large
  34. * enough to hold a socket address for any TCP/IP address
  35. * family.
  36. */
  37. char pad[ sizeof ( struct sockaddr ) -
  38. ( sizeof ( sa_family_t ) + sizeof ( uint16_t ) ) ];
  39. } __attribute__ (( may_alias ));
  40. /**
  41. * A transport-layer protocol of the TCP/IP stack (eg. UDP, TCP, etc)
  42. */
  43. struct tcpip_protocol {
  44. /** Protocol name */
  45. const char *name;
  46. /**
  47. * Process received packet
  48. *
  49. * @v iobuf I/O buffer
  50. * @v st_src Partially-filled source address
  51. * @v st_dest Partially-filled destination address
  52. * @v pshdr_csum Pseudo-header checksum
  53. * @ret rc Return status code
  54. *
  55. * This method takes ownership of the I/O buffer.
  56. */
  57. int ( * rx ) ( struct io_buffer *iobuf, struct sockaddr_tcpip *st_src,
  58. struct sockaddr_tcpip *st_dest, uint16_t pshdr_csum );
  59. /**
  60. * Transport-layer protocol number
  61. *
  62. * This is a constant of the type IP_XXX
  63. */
  64. uint8_t tcpip_proto;
  65. };
  66. /**
  67. * A network-layer protocol of the TCP/IP stack (eg. IPV4, IPv6, etc)
  68. */
  69. struct tcpip_net_protocol {
  70. /** Protocol name */
  71. const char *name;
  72. /** Network address family */
  73. sa_family_t sa_family;
  74. /**
  75. * Transmit packet
  76. *
  77. * @v iobuf I/O buffer
  78. * @v tcpip_protocol Transport-layer protocol
  79. * @v st_src Source address, or NULL to use default
  80. * @v st_dest Destination address
  81. * @v netdev Network device (or NULL to route automatically)
  82. * @v trans_csum Transport-layer checksum to complete, or NULL
  83. * @ret rc Return status code
  84. *
  85. * This function takes ownership of the I/O buffer.
  86. */
  87. int ( * tx ) ( struct io_buffer *iobuf,
  88. struct tcpip_protocol *tcpip_protocol,
  89. struct sockaddr_tcpip *st_src,
  90. struct sockaddr_tcpip *st_dest,
  91. struct net_device *netdev,
  92. uint16_t *trans_csum );
  93. };
  94. /** TCP/IP transport-layer protocol table */
  95. #define TCPIP_PROTOCOLS __table ( struct tcpip_protocol, "tcpip_protocols" )
  96. /** Declare a TCP/IP transport-layer protocol */
  97. #define __tcpip_protocol __table_entry ( TCPIP_PROTOCOLS, 01 )
  98. /** TCP/IP network-layer protocol table */
  99. #define TCPIP_NET_PROTOCOLS \
  100. __table ( struct tcpip_net_protocol, "tcpip_net_protocols" )
  101. /** Declare a TCP/IP network-layer protocol */
  102. #define __tcpip_net_protocol __table_entry ( TCPIP_NET_PROTOCOLS, 01 )
  103. extern int tcpip_rx ( struct io_buffer *iobuf, 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 io_buffer *iobuf, struct tcpip_protocol *tcpip,
  107. struct sockaddr_tcpip *st_src,
  108. struct sockaddr_tcpip *st_dest,
  109. struct net_device *netdev,
  110. uint16_t *trans_csum );
  111. extern uint16_t tcpip_continue_chksum ( uint16_t partial,
  112. const void *data, size_t len );
  113. extern uint16_t tcpip_chksum ( const void *data, size_t len );
  114. #endif /* _GPXE_TCPIP_H */