You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tcpip.h 3.3KB

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