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 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 pk_buff;
  13. #define SA_TCPIP_LEN 32
  14. /**
  15. * TCP/IP socket address
  16. *
  17. * This contains the fields common to socket addresses for all TCP/IP
  18. * address families.
  19. */
  20. struct sockaddr_tcpip {
  21. /** Socket address family (part of struct @c sockaddr) */
  22. sa_family_t st_family;
  23. /** TCP/IP port */
  24. uint16_t st_port;
  25. /** Padding
  26. *
  27. * This ensures that a struct @c sockaddr_tcpip is large
  28. * enough to hold a socket address for any TCP/IP address
  29. * family.
  30. */
  31. char pad[SA_TCPIP_LEN - sizeof ( sa_family_t ) - sizeof ( uint16_t )];
  32. };
  33. /**
  34. * A transport-layer protocol of the TCP/IP stack (eg. UDP, TCP, etc)
  35. */
  36. struct tcpip_protocol {
  37. /** Protocol name */
  38. const char *name;
  39. /**
  40. * Process received packet
  41. *
  42. * @v pkb Packet buffer
  43. * @v st_src Partially-filled source address
  44. * @v st_dest Partially-filled destination address
  45. * @ret rc Return status code
  46. *
  47. * This method takes ownership of the packet buffer.
  48. */
  49. int ( * rx ) ( struct pk_buff *pkb, struct sockaddr_tcpip *st_src,
  50. struct sockaddr_tcpip *st_dest );
  51. /**
  52. * Transport-layer protocol number
  53. *
  54. * This is a constant of the type IP_XXX
  55. */
  56. uint8_t tcpip_proto;
  57. /**
  58. * Checksum offset
  59. *
  60. * A negative number indicates that the protocol does not
  61. * require checksumming to be performed by the network layer.
  62. * A positive number is the offset of the checksum field in
  63. * the transport-layer header.
  64. */
  65. int csum_offset;
  66. };
  67. /**
  68. * A network-layer protocol of the TCP/IP stack (eg. IPV4, IPv6, etc)
  69. */
  70. struct tcpip_net_protocol {
  71. /** Protocol name */
  72. const char *name;
  73. /** Network address family */
  74. sa_family_t sa_family;
  75. /**
  76. * Transmit packet
  77. *
  78. * @v pkb Packet buffer
  79. * @v tcpip_protocol Transport-layer protocol
  80. * @v st_dest Destination address
  81. * @ret rc Return status code
  82. *
  83. * This function takes ownership of the packet buffer.
  84. */
  85. int ( * tx ) ( struct pk_buff *pkb,
  86. struct tcpip_protocol *tcpip_protocol,
  87. struct sockaddr_tcpip *st_dest );
  88. };
  89. /** Declare a TCP/IP transport-layer protocol */
  90. #define __tcpip_protocol __table ( tcpip_protocols, 01 )
  91. /** Declare a TCP/IP network-layer protocol */
  92. #define __tcpip_net_protocol __table ( tcpip_net_protocols, 01 )
  93. extern int tcpip_rx ( struct pk_buff *pkb, uint8_t tcpip_proto,
  94. struct sockaddr_tcpip *st_src,
  95. struct sockaddr_tcpip *st_dest );
  96. extern int tcpip_tx ( struct pk_buff *pkb, struct tcpip_protocol *tcpip,
  97. struct sockaddr_tcpip *st_dest );
  98. extern unsigned int tcpip_continue_chksum ( unsigned int partial,
  99. const void *data, size_t len );
  100. extern unsigned int tcpip_chksum ( const void *data, size_t len );
  101. #endif /* _GPXE_TCPIP_H */