tcpip.h

Go to the documentation of this file.
00001 #ifndef _GPXE_TCPIP_H
00002 #define _GPXE_TCPIP_H
00003 
00004 /** @file
00005  *
00006  * Transport-network layer interface
00007  *
00008  */
00009 
00010 FILE_LICENCE ( GPL2_OR_LATER );
00011 
00012 #include <stdint.h>
00013 #include <gpxe/socket.h>
00014 #include <gpxe/in.h>
00015 #include <gpxe/tables.h>
00016 
00017 struct io_buffer;
00018 struct net_device;
00019 
00020 /** Empty checksum value
00021  *
00022  * This is the TCP/IP checksum over a zero-length block of data.
00023  */
00024 #define TCPIP_EMPTY_CSUM 0xffff
00025 
00026 /**
00027  * TCP/IP socket address
00028  *
00029  * This contains the fields common to socket addresses for all TCP/IP
00030  * address families.
00031  */
00032 struct sockaddr_tcpip {
00033         /** Socket address family (part of struct @c sockaddr) */
00034         sa_family_t st_family;
00035         /** TCP/IP port */
00036         uint16_t st_port;
00037         /** Padding
00038          *
00039          * This ensures that a struct @c sockaddr_tcpip is large
00040          * enough to hold a socket address for any TCP/IP address
00041          * family.
00042          */
00043         char pad[ sizeof ( struct sockaddr ) -
00044                   ( sizeof ( sa_family_t ) + sizeof ( uint16_t ) ) ];
00045 } __attribute__ (( may_alias ));
00046 
00047 /** 
00048  * A transport-layer protocol of the TCP/IP stack (eg. UDP, TCP, etc)
00049  */
00050 struct tcpip_protocol {
00051         /** Protocol name */
00052         const char *name;
00053         /**
00054          * Process received packet
00055          *
00056          * @v iobuf             I/O buffer
00057          * @v st_src            Partially-filled source address
00058          * @v st_dest           Partially-filled destination address
00059          * @v pshdr_csum        Pseudo-header checksum
00060          * @ret rc              Return status code
00061          *
00062          * This method takes ownership of the I/O buffer.
00063          */
00064         int ( * rx ) ( struct io_buffer *iobuf, struct sockaddr_tcpip *st_src,
00065                        struct sockaddr_tcpip *st_dest, uint16_t pshdr_csum );
00066         /** 
00067          * Transport-layer protocol number
00068          *
00069          * This is a constant of the type IP_XXX
00070          */
00071         uint8_t tcpip_proto;
00072 };
00073 
00074 /**
00075  * A network-layer protocol of the TCP/IP stack (eg. IPV4, IPv6, etc)
00076  */
00077 struct tcpip_net_protocol {
00078         /** Protocol name */
00079         const char *name;
00080         /** Network address family */
00081         sa_family_t sa_family;
00082         /**
00083          * Transmit packet
00084          *
00085          * @v iobuf             I/O buffer
00086          * @v tcpip_protocol    Transport-layer protocol
00087          * @v st_src            Source address, or NULL to use default
00088          * @v st_dest           Destination address
00089          * @v netdev            Network device (or NULL to route automatically)
00090          * @v trans_csum        Transport-layer checksum to complete, or NULL
00091          * @ret rc              Return status code
00092          *
00093          * This function takes ownership of the I/O buffer.
00094          */
00095         int ( * tx ) ( struct io_buffer *iobuf,
00096                        struct tcpip_protocol *tcpip_protocol,
00097                        struct sockaddr_tcpip *st_src,
00098                        struct sockaddr_tcpip *st_dest,
00099                        struct net_device *netdev,
00100                        uint16_t *trans_csum );
00101 };
00102 
00103 /** TCP/IP transport-layer protocol table */
00104 #define TCPIP_PROTOCOLS __table ( struct tcpip_protocol, "tcpip_protocols" )
00105 
00106 /** Declare a TCP/IP transport-layer protocol */
00107 #define __tcpip_protocol __table_entry ( TCPIP_PROTOCOLS, 01 )
00108 
00109 /** TCP/IP network-layer protocol table */
00110 #define TCPIP_NET_PROTOCOLS \
00111         __table ( struct tcpip_net_protocol, "tcpip_net_protocols" )
00112 
00113 /** Declare a TCP/IP network-layer protocol */
00114 #define __tcpip_net_protocol __table_entry ( TCPIP_NET_PROTOCOLS, 01 )
00115 
00116 extern int tcpip_rx ( struct io_buffer *iobuf, uint8_t tcpip_proto,
00117                       struct sockaddr_tcpip *st_src,
00118                       struct sockaddr_tcpip *st_dest, uint16_t pshdr_csum );
00119 extern int tcpip_tx ( struct io_buffer *iobuf, struct tcpip_protocol *tcpip,
00120                       struct sockaddr_tcpip *st_src,
00121                       struct sockaddr_tcpip *st_dest,
00122                       struct net_device *netdev,
00123                       uint16_t *trans_csum );
00124 extern uint16_t tcpip_continue_chksum ( uint16_t partial,
00125                                         const void *data, size_t len );
00126 extern uint16_t tcpip_chksum ( const void *data, size_t len );
00127 
00128 #endif /* _GPXE_TCPIP_H */

Generated on Tue Apr 6 20:01:09 2010 for gPXE by  doxygen 1.5.7.1