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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #ifndef _GPXE_INTERFACE_H
  2. #define _GPXE_INTERFACE_H
  3. /** @file
  4. *
  5. * Transport-network layer interface
  6. *
  7. */
  8. #include <stdint.h>
  9. #include <gpxe/in.h>
  10. #include <gpxe/tables.h>
  11. struct pk_buff;
  12. struct net_protocol;
  13. struct tcpip_protocol;
  14. struct tcpip_net_protocol;
  15. /**
  16. * A transport-layer protocol of the TCPIP stack (eg. UDP, TCP, etc)
  17. */
  18. struct tcpip_protocol {
  19. /** Protocol name */
  20. const char *name;
  21. /**
  22. * Process received packet
  23. *
  24. * @v pkb Packet buffer
  25. * @v netdev Network device
  26. * @v ll_source Link-layer source address
  27. *
  28. * This method takes ownership of the packet buffer.
  29. */
  30. void ( * rx ) ( struct pk_buff *pkb, struct in_addr *src_net_addr, struct in_addr *dest_net_addr );
  31. /**
  32. * Transport-layer protocol number
  33. *
  34. * This is a constant of the type IP_XXX
  35. */
  36. uint8_t trans_proto;
  37. /**
  38. * Checksum offset
  39. *
  40. * A negative number indicates that the protocol does not require
  41. * checksumming to be performed by the network layer. A positive number is
  42. * the offset of the checksum field in the transport-layer header.
  43. */
  44. int csum_offset;
  45. };
  46. /**
  47. * A TCPIP supporting network-layer protocol
  48. */
  49. struct tcpip_net_protocol {
  50. /** Network protocol */
  51. struct net_protocol *net_protocol;
  52. /** Network address family */
  53. sa_family_t sa_family;
  54. /** Complete transport-layer checksum calculation
  55. *
  56. * @v pkb Packet buffer
  57. * @v tcpip Transport-layer protocol
  58. *
  59. */
  60. void ( * tx_csum ) ( struct pk_buff *pkb,
  61. struct tcpip_protocol *tcpip );
  62. };
  63. /**
  64. * Register a transport-layer protocol
  65. *
  66. * @v protocol Transport-layer protocol
  67. */
  68. #define TCPIP_PROTOCOL( protocol ) \
  69. struct tcpip_protocol protocol __table ( tcpip_protocols, 01 )
  70. #define TCPIP_NET_PROTOCOL( protocol ) \
  71. struct tcpip_net_protocol protocol __table ( tcpip_net_protocols, 01 )
  72. extern void trans_rx ( struct pk_buff *pkb, uint8_t trans_proto,
  73. struct in_addr *src, struct in_addr *dest );
  74. extern int trans_tx ( struct pk_buff *pkb, struct tcpip_protocol *tcpip,
  75. struct sockaddr *dest );
  76. extern unsigned int tcpip_continue_chksum ( unsigned int partial,
  77. const void *data, size_t len );
  78. extern unsigned int tcpip_chksum ( const void *data, size_t len );
  79. extern struct tcpip_protocol * find_tcpip_protocol ( uint8_t trans_proto );
  80. extern struct tcpip_net_protocol * find_tcpip_net_protocol ( sa_family_t sa_family );
  81. #endif /* _GPXE_INTERFACE_H */