2006-08-01 16:26:02 +02:00
|
|
|
#ifndef _GPXE_TCPIP_H
|
|
|
|
#define _GPXE_TCPIP_H
|
2006-06-28 17:43:08 +02:00
|
|
|
|
|
|
|
/** @file
|
|
|
|
*
|
|
|
|
* Transport-network layer interface
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2006-08-02 02:02:21 +02:00
|
|
|
#include <gpxe/socket.h>
|
2006-06-28 17:43:08 +02:00
|
|
|
#include <gpxe/in.h>
|
|
|
|
#include <gpxe/tables.h>
|
|
|
|
|
|
|
|
struct pk_buff;
|
2006-08-02 02:02:21 +02:00
|
|
|
|
2007-01-03 21:48:52 +01:00
|
|
|
/** Empty checksum value
|
|
|
|
*
|
|
|
|
* This is the TCP/IP checksum over a zero-length block of data.
|
|
|
|
*/
|
|
|
|
#define TCPIP_EMPTY_CSUM 0xffff
|
|
|
|
|
|
|
|
/** Length of a @c struct @c sockaddr_tcpip */
|
2006-08-02 02:02:21 +02:00
|
|
|
#define SA_TCPIP_LEN 32
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TCP/IP socket address
|
|
|
|
*
|
|
|
|
* This contains the fields common to socket addresses for all TCP/IP
|
|
|
|
* address families.
|
|
|
|
*/
|
|
|
|
struct sockaddr_tcpip {
|
|
|
|
/** Socket address family (part of struct @c sockaddr) */
|
|
|
|
sa_family_t st_family;
|
|
|
|
/** TCP/IP port */
|
|
|
|
uint16_t st_port;
|
|
|
|
/** Padding
|
|
|
|
*
|
|
|
|
* This ensures that a struct @c sockaddr_tcpip is large
|
|
|
|
* enough to hold a socket address for any TCP/IP address
|
|
|
|
* family.
|
|
|
|
*/
|
|
|
|
char pad[SA_TCPIP_LEN - sizeof ( sa_family_t ) - sizeof ( uint16_t )];
|
|
|
|
};
|
2006-06-28 17:43:08 +02:00
|
|
|
|
|
|
|
/**
|
2006-08-02 02:02:21 +02:00
|
|
|
* A transport-layer protocol of the TCP/IP stack (eg. UDP, TCP, etc)
|
2006-06-28 17:43:08 +02:00
|
|
|
*/
|
|
|
|
struct tcpip_protocol {
|
|
|
|
/** Protocol name */
|
|
|
|
const char *name;
|
|
|
|
/**
|
|
|
|
* Process received packet
|
|
|
|
*
|
2007-01-03 21:48:52 +01:00
|
|
|
* @v pkb Packet buffer
|
|
|
|
* @v st_src Partially-filled source address
|
|
|
|
* @v st_dest Partially-filled destination address
|
|
|
|
* @v pshdr_csum Pseudo-header checksum
|
|
|
|
* @ret rc Return status code
|
2006-06-28 17:43:08 +02:00
|
|
|
*
|
|
|
|
* This method takes ownership of the packet buffer.
|
|
|
|
*/
|
2006-08-02 02:02:21 +02:00
|
|
|
int ( * rx ) ( struct pk_buff *pkb, struct sockaddr_tcpip *st_src,
|
2007-01-03 21:48:52 +01:00
|
|
|
struct sockaddr_tcpip *st_dest, uint16_t pshdr_csum );
|
2006-06-28 17:43:08 +02:00
|
|
|
/**
|
|
|
|
* Transport-layer protocol number
|
|
|
|
*
|
|
|
|
* This is a constant of the type IP_XXX
|
|
|
|
*/
|
2006-08-02 02:02:21 +02:00
|
|
|
uint8_t tcpip_proto;
|
2006-06-28 17:43:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2006-08-02 02:02:21 +02:00
|
|
|
* A network-layer protocol of the TCP/IP stack (eg. IPV4, IPv6, etc)
|
2006-06-28 17:43:08 +02:00
|
|
|
*/
|
|
|
|
struct tcpip_net_protocol {
|
2006-08-02 02:02:21 +02:00
|
|
|
/** Protocol name */
|
|
|
|
const char *name;
|
2006-06-28 17:43:08 +02:00
|
|
|
/** Network address family */
|
|
|
|
sa_family_t sa_family;
|
2006-08-01 22:27:26 +02:00
|
|
|
/**
|
|
|
|
* Transmit packet
|
|
|
|
*
|
|
|
|
* @v pkb Packet buffer
|
2006-08-02 02:02:21 +02:00
|
|
|
* @v tcpip_protocol Transport-layer protocol
|
|
|
|
* @v st_dest Destination address
|
2007-01-03 21:48:52 +01:00
|
|
|
* @v trans_csum Transport-layer checksum to complete, or NULL
|
2006-08-02 02:02:21 +02:00
|
|
|
* @ret rc Return status code
|
2006-06-28 17:43:08 +02:00
|
|
|
*
|
2006-08-02 02:02:21 +02:00
|
|
|
* This function takes ownership of the packet buffer.
|
2006-06-28 17:43:08 +02:00
|
|
|
*/
|
2006-08-02 02:02:21 +02:00
|
|
|
int ( * tx ) ( struct pk_buff *pkb,
|
|
|
|
struct tcpip_protocol *tcpip_protocol,
|
2007-01-03 21:48:52 +01:00
|
|
|
struct sockaddr_tcpip *st_dest, uint16_t *trans_csum );
|
2006-06-28 17:43:08 +02:00
|
|
|
};
|
|
|
|
|
2006-08-09 06:42:14 +02:00
|
|
|
/** Declare a TCP/IP transport-layer protocol */
|
|
|
|
#define __tcpip_protocol __table ( tcpip_protocols, 01 )
|
2006-06-28 17:43:08 +02:00
|
|
|
|
2006-08-09 06:42:14 +02:00
|
|
|
/** Declare a TCP/IP network-layer protocol */
|
|
|
|
#define __tcpip_net_protocol __table ( tcpip_net_protocols, 01 )
|
2006-06-28 17:43:08 +02:00
|
|
|
|
2006-08-02 02:02:21 +02:00
|
|
|
extern int tcpip_rx ( struct pk_buff *pkb, uint8_t tcpip_proto,
|
|
|
|
struct sockaddr_tcpip *st_src,
|
2007-01-03 21:48:52 +01:00
|
|
|
struct sockaddr_tcpip *st_dest, uint16_t pshdr_csum );
|
2006-08-01 16:22:04 +02:00
|
|
|
extern int tcpip_tx ( struct pk_buff *pkb, struct tcpip_protocol *tcpip,
|
2007-01-03 21:48:52 +01:00
|
|
|
struct sockaddr_tcpip *st_dest, uint16_t *trans_csum );
|
|
|
|
extern uint16_t tcpip_continue_chksum ( uint16_t partial,
|
|
|
|
const void *data, size_t len );
|
|
|
|
extern uint16_t tcpip_chksum ( const void *data, size_t len );
|
2006-06-28 17:43:08 +02:00
|
|
|
|
2006-08-01 16:26:02 +02:00
|
|
|
#endif /* _GPXE_TCPIP_H */
|