mirror of
https://github.com/ipxe/ipxe
synced 2025-12-19 11:00:27 +03:00
Added features that will be required for PXE UDP support.
Introduced struct sockaddr_tcpip, to simplify code that deals with both IPv4 and IPv6 addresses. Reorganised parts of tcpip.c and udp.c.
This commit is contained in:
@@ -8,16 +8,36 @@
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <gpxe/socket.h>
|
||||
#include <gpxe/in.h>
|
||||
#include <gpxe/tables.h>
|
||||
|
||||
struct pk_buff;
|
||||
struct net_protocol;
|
||||
struct tcpip_protocol;
|
||||
struct tcpip_net_protocol;
|
||||
|
||||
#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 )];
|
||||
};
|
||||
|
||||
/**
|
||||
* A transport-layer protocol of the TCPIP stack (eg. UDP, TCP, etc)
|
||||
* A transport-layer protocol of the TCP/IP stack (eg. UDP, TCP, etc)
|
||||
*/
|
||||
struct tcpip_protocol {
|
||||
/** Protocol name */
|
||||
@@ -25,75 +45,76 @@ struct tcpip_protocol {
|
||||
/**
|
||||
* Process received packet
|
||||
*
|
||||
* @v pkb Packet buffer
|
||||
* @v netdev Network device
|
||||
* @v ll_source Link-layer source address
|
||||
* @v pkb Packet buffer
|
||||
* @v st_src Partially-filled source address
|
||||
* @v st_dest Partially-filled destination address
|
||||
* @ret rc Return status code
|
||||
*
|
||||
* This method takes ownership of the packet buffer.
|
||||
*/
|
||||
void ( * rx ) ( struct pk_buff *pkb, struct in_addr *src_net_addr,
|
||||
struct in_addr *dest_net_addr );
|
||||
|
||||
int ( * rx ) ( struct pk_buff *pkb, struct sockaddr_tcpip *st_src,
|
||||
struct sockaddr_tcpip *st_dest );
|
||||
/**
|
||||
* Transport-layer protocol number
|
||||
*
|
||||
* This is a constant of the type IP_XXX
|
||||
*/
|
||||
uint8_t trans_proto;
|
||||
uint8_t tcpip_proto;
|
||||
/**
|
||||
* Checksum offset
|
||||
*
|
||||
* A negative number indicates that the protocol does not require
|
||||
* checksumming to be performed by the network layer. A positive number
|
||||
* is the offset of the checksum field in the transport-layer header.
|
||||
* A negative number indicates that the protocol does not
|
||||
* require checksumming to be performed by the network layer.
|
||||
* A positive number is the offset of the checksum field in
|
||||
* the transport-layer header.
|
||||
*/
|
||||
int csum_offset;
|
||||
};
|
||||
|
||||
/**
|
||||
* A TCPIP supporting network-layer protocol
|
||||
* A network-layer protocol of the TCP/IP stack (eg. IPV4, IPv6, etc)
|
||||
*/
|
||||
struct tcpip_net_protocol {
|
||||
/** Network protocol */
|
||||
struct net_protocol *net_protocol;
|
||||
/** Protocol name */
|
||||
const char *name;
|
||||
/** Network address family */
|
||||
sa_family_t sa_family;
|
||||
/**
|
||||
* Transmit packet
|
||||
*
|
||||
* @v pkb Packet buffer
|
||||
* @v tcpip Transport-layer TCP/IP protocol
|
||||
* @v sock Socket address
|
||||
*/
|
||||
int ( * tx ) ( struct pk_buff *pkb, struct tcpip_protocol *tcpip,
|
||||
struct sockaddr *sock );
|
||||
/** Complete transport-layer checksum calculation
|
||||
*
|
||||
* @v pkb Packet buffer
|
||||
* @v tcpip Transport-layer protocol
|
||||
* @v tcpip_protocol Transport-layer protocol
|
||||
* @v st_dest Destination address
|
||||
* @ret rc Return status code
|
||||
*
|
||||
* This function takes ownership of the packet buffer.
|
||||
*/
|
||||
void ( * tx_csum ) ( struct pk_buff *pkb,
|
||||
struct tcpip_protocol *tcpip );
|
||||
int ( * tx ) ( struct pk_buff *pkb,
|
||||
struct tcpip_protocol *tcpip_protocol,
|
||||
struct sockaddr_tcpip *st_dest );
|
||||
};
|
||||
|
||||
/**
|
||||
* Register a transport-layer protocol
|
||||
* Register a TCP/IP transport-layer protocol
|
||||
*
|
||||
* @v protocol Transport-layer protocol
|
||||
* @v protocol Transport-layer protocol
|
||||
*/
|
||||
#define TCPIP_PROTOCOL( protocol ) \
|
||||
struct tcpip_protocol protocol __table ( tcpip_protocols, 01 )
|
||||
struct tcpip_protocol protocol __table ( tcpip_protocols, 01 )
|
||||
|
||||
/**
|
||||
* Register a TCP/IP network-layer protocol
|
||||
*
|
||||
* @v protocol Network-layer protocol
|
||||
*/
|
||||
#define TCPIP_NET_PROTOCOL( protocol ) \
|
||||
struct tcpip_net_protocol protocol __table ( tcpip_net_protocols, 01 )
|
||||
|
||||
extern void tcpip_rx ( struct pk_buff *pkb, uint8_t trans_proto,
|
||||
struct in_addr *src, struct in_addr *dest );
|
||||
struct tcpip_net_protocol protocol __table ( tcpip_net_protocols, 01 )
|
||||
|
||||
extern int tcpip_rx ( struct pk_buff *pkb, uint8_t tcpip_proto,
|
||||
struct sockaddr_tcpip *st_src,
|
||||
struct sockaddr_tcpip *st_dest );
|
||||
extern int tcpip_tx ( struct pk_buff *pkb, struct tcpip_protocol *tcpip,
|
||||
struct sockaddr *dest );
|
||||
|
||||
struct sockaddr_tcpip *st_dest );
|
||||
extern unsigned int tcpip_continue_chksum ( unsigned int partial,
|
||||
const void *data, size_t len );
|
||||
extern unsigned int tcpip_chksum ( const void *data, size_t len );
|
||||
|
||||
Reference in New Issue
Block a user