diff options
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/gpxe/in.h | 42 | ||||
| -rw-r--r-- | src/include/gpxe/ip.h | 4 | ||||
| -rw-r--r-- | src/include/gpxe/tcp.h | 12 | ||||
| -rw-r--r-- | src/include/gpxe/tcpip.h | 95 | ||||
| -rw-r--r-- | src/include/gpxe/udp.h | 37 | ||||
| -rw-r--r-- | src/include/proto.h | 2 | ||||
| -rw-r--r-- | src/include/tftp.h | 2 |
7 files changed, 100 insertions, 94 deletions
diff --git a/src/include/gpxe/in.h b/src/include/gpxe/in.h index d7b44795e..eed9c09b3 100644 --- a/src/include/gpxe/in.h +++ b/src/include/gpxe/in.h @@ -2,6 +2,7 @@ #define _GPXE_IN_H #include <stdint.h> +#include <gpxe/socket.h> /* Protocol numbers */ @@ -10,15 +11,6 @@ #define IP_TCP 6 #define IP_UDP 17 -/* Network address family numbers */ - -#define AF_INET 1 -#define AF_INET6 2 -#define AF_802 6 -#define AF_IPX 11 - -typedef uint16_t sa_family_t; - /* IP address constants */ #define INADDR_NONE 0xffffffff @@ -50,35 +42,37 @@ struct in6_addr { #define s6_addr32 in6_u.u6_addr32 }; -typedef uint16_t in_port_t; - /** - * IP socket address + * IPv4 socket address */ struct sockaddr_in { - struct in_addr sin_addr; - in_port_t sin_port; + /** Socket address family (part of struct @c sockaddr) + * + * Always set to @c AF_INET for IPv4 addresses + */ + sa_family_t sin_family; + /** TCP/IP port (part of struct @c sockaddr_tcpip) */ + uint16_t sin_port; + /** IPv4 address */ + struct in_addr sin_addr; }; /** * IPv6 socket address */ struct sockaddr_in6 { - in_port_t sin6_port; /* Destination port */ + /** Socket address family (part of struct @c sockaddr) + * + * Always set to @c AF_INET6 for IPv6 addresses + */ + sa_family_t sin_family; + /** TCP/IP port (part of struct @c sockaddr_tcpip) */ + uint16_t sin_port; uint32_t sin6_flowinfo; /* Flow number */ struct in6_addr sin6_addr; /* 128-bit destination address */ uint32_t sin6_scope_id; /* Scope ID */ }; -/** - * Generalized socket address structure - */ -struct sockaddr { - sa_family_t sa_family; /* Socket address family */ - struct sockaddr_in sin; /* IP4 socket address */ - struct sockaddr_in6 sin6; /* IP6 socket address */ -}; - extern int inet_aton ( const char *cp, struct in_addr *inp ); extern char * inet_ntoa ( struct in_addr in ); diff --git a/src/include/gpxe/ip.h b/src/include/gpxe/ip.h index 17aa3ceb7..bec7c9020 100644 --- a/src/include/gpxe/ip.h +++ b/src/include/gpxe/ip.h @@ -64,8 +64,4 @@ extern int add_ipv4_address ( struct net_device *netdev, struct in_addr gateway ); extern void del_ipv4_address ( struct net_device *netdev ); -extern int ipv4_uip_tx ( struct pk_buff *pkb ); -extern int ipv4_tx ( struct pk_buff *pkb, struct tcpip_protocol *tcpip, - struct sockaddr *sock ); - #endif /* _GPXE_IP_H */ diff --git a/src/include/gpxe/tcp.h b/src/include/gpxe/tcp.h index cc7d666c2..2056afdc9 100644 --- a/src/include/gpxe/tcp.h +++ b/src/include/gpxe/tcp.h @@ -10,8 +10,8 @@ */ #include <stddef.h> -#include <gpxe/in.h> #include <gpxe/list.h> +#include <gpxe/tcpip.h> #include <gpxe/pkbuff.h> struct tcp_connection; @@ -142,8 +142,11 @@ extern void tcp_close ( struct tcp_connection *conn ); * A TCP connection */ struct tcp_connection { - struct sockaddr sa; /* Remote socket address */ - struct sockaddr_in sin; /* Internet socket address */ + struct sockaddr_tcpip peer; /* Remote socket address */ + + /* FIXME: this field should no longer be present */ + struct sockaddr_in sin; + uint16_t local_port; /* Local port, in network byte order */ int tcp_state; /* TCP state */ int tcp_lstate; /* Last TCP state */ @@ -200,7 +203,8 @@ extern struct tcpip_protocol tcp_protocol; extern void tcp_init_conn ( struct tcp_connection *conn ); extern int tcp_connect ( struct tcp_connection *conn ); -extern int tcp_connectto ( struct tcp_connection *conn, struct sockaddr *peer ); +extern int tcp_connectto ( struct tcp_connection *conn, + struct sockaddr_tcpip *peer ); extern int tcp_listen ( struct tcp_connection *conn, uint16_t port ); extern int tcp_senddata ( struct tcp_connection *conn ); extern int tcp_close ( struct tcp_connection *conn ); diff --git a/src/include/gpxe/tcpip.h b/src/include/gpxe/tcpip.h index 4134de751..daed7da53 100644 --- a/src/include/gpxe/tcpip.h +++ b/src/include/gpxe/tcpip.h @@ -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 ); diff --git a/src/include/gpxe/udp.h b/src/include/gpxe/udp.h index 006bc0b38..a0e054da9 100644 --- a/src/include/gpxe/udp.h +++ b/src/include/gpxe/udp.h @@ -10,8 +10,8 @@ */ #include <stddef.h> -#include <gpxe/in.h> #include <gpxe/pkbuff.h> +#include <gpxe/tcpip.h> #include <gpxe/if_ether.h> /** @@ -65,8 +65,9 @@ struct udp_operations { * @v data Data * @v len Length of data */ - void ( * newdata ) ( struct udp_connection *conn, - void *data, size_t len ); + int ( * newdata ) ( struct udp_connection *conn, void *data, + size_t len, struct sockaddr_tcpip *st_src, + struct sockaddr_tcpip *st_dest ); }; /** @@ -75,7 +76,7 @@ struct udp_operations { */ struct udp_connection { /** Address of the remote end of the connection */ - struct sockaddr sa; + struct sockaddr_tcpip peer; /** Local port on which the connection receives packets */ port_t local_port; /** Transmit buffer */ @@ -86,31 +87,21 @@ struct udp_connection { struct udp_operations *udp_op; }; -/** - * UDP protocol - */ -extern struct tcpip_protocol udp_protocol; - -/** +/* * Functions provided to the application layer */ -extern void udp_init ( struct udp_connection *conn, struct udp_operations *udp_op ); +extern int udp_bind ( struct udp_connection *conn, uint16_t local_port ); +extern void udp_connect ( struct udp_connection *conn, + struct sockaddr_tcpip *peer ); extern int udp_open ( struct udp_connection *conn, uint16_t local_port ); - -extern void udp_connect ( struct udp_connection *conn, struct sockaddr *peer ); extern void udp_close ( struct udp_connection *conn ); extern int udp_senddata ( struct udp_connection *conn ); -extern int udp_send ( struct udp_connection *conn, const void *data, size_t len ); -extern int udp_sendto ( struct udp_connection *conn, struct sockaddr *peer, const void *data, size_t len ); - -static inline void * udp_buffer ( struct udp_connection *conn ) { - return conn->tx_pkb->data; -} - -static inline int udp_buflen ( struct udp_connection *conn ) { - return pkb_len ( conn->tx_pkb ); -} +extern int udp_send ( struct udp_connection *conn, + const void *data, size_t len ); +extern int udp_sendto ( struct udp_connection *conn, + struct sockaddr_tcpip *peer, + const void *data, size_t len ); #endif /* _GPXE_UDP_H */ diff --git a/src/include/proto.h b/src/include/proto.h index 89b7c1736..7bceef9d9 100644 --- a/src/include/proto.h +++ b/src/include/proto.h @@ -7,7 +7,7 @@ struct protocol { char *name; - in_port_t default_port; + uint16_t default_port; int ( * load ) ( char *url, struct sockaddr_in *server, char *file, struct buffer *buffer ); }; diff --git a/src/include/tftp.h b/src/include/tftp.h index ae8f35192..ed99035ed 100644 --- a/src/include/tftp.h +++ b/src/include/tftp.h @@ -105,7 +105,7 @@ struct tftp_state { * This is the UDP port from which the open request will be * sent, and to which any unicast data packets will be sent. */ - in_port_t lport; + uint16_t lport; /** TFTP multicast address * * This is the IP address and UDP port to which multicast data |
