Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / include / ipxe / tcpip.h
1 #ifndef _IPXE_TCPIP_H
2 #define _IPXE_TCPIP_H
3
4 /** @file
5  *
6  * Transport-network layer interface
7  *
8  */
9
10 FILE_LICENCE ( GPL2_OR_LATER );
11
12 #include <stdint.h>
13 #include <ipxe/socket.h>
14 #include <ipxe/in.h>
15 #include <ipxe/tables.h>
16 #include <bits/tcpip.h>
17
18 struct io_buffer;
19 struct net_device;
20 struct ip_statistics;
21
22 /** Empty checksum value
23  *
24  * This is the TCP/IP checksum over a zero-length block of data.
25  */
26 #define TCPIP_EMPTY_CSUM 0xffff
27
28 /** TCP/IP address flags */
29 enum tcpip_st_flags {
30         /** Bind to a privileged port (less than 1024)
31          *
32          * This value is chosen as 1024 to optimise the calculations
33          * in tcpip_bind().
34          */
35         TCPIP_BIND_PRIVILEGED = 0x0400,
36 };
37
38 /**
39  * TCP/IP socket address
40  *
41  * This contains the fields common to socket addresses for all TCP/IP
42  * address families.
43  */
44 struct sockaddr_tcpip {
45         /** Socket address family (part of struct @c sockaddr) */
46         sa_family_t st_family;
47         /** Flags */
48         uint16_t st_flags;
49         /** TCP/IP port */
50         uint16_t st_port;
51         /** Padding
52          *
53          * This ensures that a struct @c sockaddr_tcpip is large
54          * enough to hold a socket address for any TCP/IP address
55          * family.
56          */
57         char pad[ sizeof ( struct sockaddr ) -
58                   ( sizeof ( sa_family_t ) /* st_family */ +
59                     sizeof ( uint16_t ) /* st_flags */ +
60                     sizeof ( uint16_t ) /* st_port */ ) ];
61 } __attribute__ (( packed, may_alias ));
62
63 /** 
64  * A transport-layer protocol of the TCP/IP stack (eg. UDP, TCP, etc)
65  */
66 struct tcpip_protocol {
67         /** Protocol name */
68         const char *name;
69         /**
70          * Process received packet
71          *
72          * @v iobuf             I/O buffer
73          * @v netdev            Network device
74          * @v st_src            Partially-filled source address
75          * @v st_dest           Partially-filled destination address
76          * @v pshdr_csum        Pseudo-header checksum
77          * @ret rc              Return status code
78          *
79          * This method takes ownership of the I/O buffer.
80          */
81         int ( * rx ) ( struct io_buffer *iobuf, struct net_device *netdev,
82                        struct sockaddr_tcpip *st_src,
83                        struct sockaddr_tcpip *st_dest, uint16_t pshdr_csum );
84         /** 
85          * Transport-layer protocol number
86          *
87          * This is a constant of the type IP_XXX
88          */
89         uint8_t tcpip_proto;
90 };
91
92 /**
93  * A network-layer protocol of the TCP/IP stack (eg. IPV4, IPv6, etc)
94  */
95 struct tcpip_net_protocol {
96         /** Protocol name */
97         const char *name;
98         /** Network address family */
99         sa_family_t sa_family;
100         /** Fixed header length */
101         size_t header_len;
102         /**
103          * Transmit packet
104          *
105          * @v iobuf             I/O buffer
106          * @v tcpip_protocol    Transport-layer protocol
107          * @v st_src            Source address, or NULL to use default
108          * @v st_dest           Destination address
109          * @v netdev            Network device (or NULL to route automatically)
110          * @v trans_csum        Transport-layer checksum to complete, or NULL
111          * @ret rc              Return status code
112          *
113          * This function takes ownership of the I/O buffer.
114          */
115         int ( * tx ) ( struct io_buffer *iobuf,
116                        struct tcpip_protocol *tcpip_protocol,
117                        struct sockaddr_tcpip *st_src,
118                        struct sockaddr_tcpip *st_dest,
119                        struct net_device *netdev,
120                        uint16_t *trans_csum );
121         /**
122          * Determine transmitting network device
123          *
124          * @v st_dest           Destination address
125          * @ret netdev          Network device, or NULL
126          */
127         struct net_device * ( * netdev ) ( struct sockaddr_tcpip *dest );
128 };
129
130 /** TCP/IP transport-layer protocol table */
131 #define TCPIP_PROTOCOLS __table ( struct tcpip_protocol, "tcpip_protocols" )
132
133 /** Declare a TCP/IP transport-layer protocol */
134 #define __tcpip_protocol __table_entry ( TCPIP_PROTOCOLS, 01 )
135
136 /** TCP/IP network-layer protocol table */
137 #define TCPIP_NET_PROTOCOLS \
138         __table ( struct tcpip_net_protocol, "tcpip_net_protocols" )
139
140 /** Declare a TCP/IP network-layer protocol */
141 #define __tcpip_net_protocol __table_entry ( TCPIP_NET_PROTOCOLS, 01 )
142
143 extern int tcpip_rx ( struct io_buffer *iobuf, struct net_device *netdev,
144                       uint8_t tcpip_proto, struct sockaddr_tcpip *st_src,
145                       struct sockaddr_tcpip *st_dest, uint16_t pshdr_csum,
146                       struct ip_statistics *stats );
147 extern int tcpip_tx ( struct io_buffer *iobuf, struct tcpip_protocol *tcpip,
148                       struct sockaddr_tcpip *st_src,
149                       struct sockaddr_tcpip *st_dest,
150                       struct net_device *netdev,
151                       uint16_t *trans_csum );
152 extern struct net_device * tcpip_netdev ( struct sockaddr_tcpip *st_dest );
153 extern size_t tcpip_mtu ( struct sockaddr_tcpip *st_dest );
154 extern uint16_t generic_tcpip_continue_chksum ( uint16_t partial,
155                                                 const void *data, size_t len );
156 extern uint16_t tcpip_chksum ( const void *data, size_t len );
157 extern int tcpip_bind ( struct sockaddr_tcpip *st_local,
158                         int ( * available ) ( int port ) );
159
160 /* Use generic_tcpip_continue_chksum() if no architecture-specific
161  * version is available
162  */
163 #ifndef tcpip_continue_chksum
164 #define tcpip_continue_chksum generic_tcpip_continue_chksum
165 #endif
166
167 #endif /* _IPXE_TCPIP_H */