Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

tcpip.h 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. };
  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_dest Destination address
  79. * @v netdev Network device (or NULL to route automatically)
  80. * @v trans_csum Transport-layer checksum to complete, or NULL
  81. * @ret rc Return status code
  82. *
  83. * This function takes ownership of the I/O buffer.
  84. */
  85. int ( * tx ) ( struct io_buffer *iobuf,
  86. struct tcpip_protocol *tcpip_protocol,
  87. struct sockaddr_tcpip *st_dest,
  88. struct net_device *netdev,
  89. uint16_t *trans_csum );
  90. };
  91. /** Declare a TCP/IP transport-layer protocol */
  92. #define __tcpip_protocol \
  93. __table ( struct tcpip_protocol, tcpip_protocols, 01 )
  94. /** Declare a TCP/IP network-layer protocol */
  95. #define __tcpip_net_protocol \
  96. __table ( struct tcpip_net_protocol, tcpip_net_protocols, 01 )
  97. extern int tcpip_rx ( struct io_buffer *iobuf, uint8_t tcpip_proto,
  98. struct sockaddr_tcpip *st_src,
  99. struct sockaddr_tcpip *st_dest, uint16_t pshdr_csum );
  100. extern int tcpip_tx ( struct io_buffer *iobuf, struct tcpip_protocol *tcpip,
  101. struct sockaddr_tcpip *st_dest,
  102. struct net_device *netdev,
  103. uint16_t *trans_csum );
  104. extern uint16_t tcpip_continue_chksum ( uint16_t partial,
  105. const void *data, size_t len );
  106. extern uint16_t tcpip_chksum ( const void *data, size_t len );
  107. #endif /* _GPXE_TCPIP_H */