These changes are the raw update to qemu-2.6.
[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_OR_UBDL );
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         /** Scope ID
52          *
53          * For link-local or multicast addresses, this is the network
54          * device index.
55          */
56         uint16_t st_scope_id;
57         /** Padding
58          *
59          * This ensures that a struct @c sockaddr_tcpip is large
60          * enough to hold a socket address for any TCP/IP address
61          * family.
62          */
63         char pad[ sizeof ( struct sockaddr ) -
64                   ( sizeof ( sa_family_t ) /* st_family */ +
65                     sizeof ( uint16_t ) /* st_flags */ +
66                     sizeof ( uint16_t ) /* st_port */ +
67                     sizeof ( uint16_t ) /* st_scope_id */ ) ];
68 } __attribute__ (( packed, may_alias ));
69
70 /** 
71  * A transport-layer protocol of the TCP/IP stack (eg. UDP, TCP, etc)
72  */
73 struct tcpip_protocol {
74         /** Protocol name */
75         const char *name;
76         /**
77          * Process received packet
78          *
79          * @v iobuf             I/O buffer
80          * @v netdev            Network device
81          * @v st_src            Partially-filled source address
82          * @v st_dest           Partially-filled destination address
83          * @v pshdr_csum        Pseudo-header checksum
84          * @ret rc              Return status code
85          *
86          * This method takes ownership of the I/O buffer.
87          */
88         int ( * rx ) ( struct io_buffer *iobuf, struct net_device *netdev,
89                        struct sockaddr_tcpip *st_src,
90                        struct sockaddr_tcpip *st_dest, uint16_t pshdr_csum );
91         /** 
92          * Transport-layer protocol number
93          *
94          * This is a constant of the type IP_XXX
95          */
96         uint8_t tcpip_proto;
97 };
98
99 /**
100  * A network-layer protocol of the TCP/IP stack (eg. IPV4, IPv6, etc)
101  */
102 struct tcpip_net_protocol {
103         /** Protocol name */
104         const char *name;
105         /** Network address family */
106         sa_family_t sa_family;
107         /** Fixed header length */
108         size_t header_len;
109         /**
110          * Transmit packet
111          *
112          * @v iobuf             I/O buffer
113          * @v tcpip_protocol    Transport-layer protocol
114          * @v st_src            Source address, or NULL to use default
115          * @v st_dest           Destination address
116          * @v netdev            Network device (or NULL to route automatically)
117          * @v trans_csum        Transport-layer checksum to complete, or NULL
118          * @ret rc              Return status code
119          *
120          * This function takes ownership of the I/O buffer.
121          */
122         int ( * tx ) ( struct io_buffer *iobuf,
123                        struct tcpip_protocol *tcpip_protocol,
124                        struct sockaddr_tcpip *st_src,
125                        struct sockaddr_tcpip *st_dest,
126                        struct net_device *netdev,
127                        uint16_t *trans_csum );
128         /**
129          * Determine transmitting network device
130          *
131          * @v st_dest           Destination address
132          * @ret netdev          Network device, or NULL
133          */
134         struct net_device * ( * netdev ) ( struct sockaddr_tcpip *dest );
135 };
136
137 /** TCP/IP transport-layer protocol table */
138 #define TCPIP_PROTOCOLS __table ( struct tcpip_protocol, "tcpip_protocols" )
139
140 /** Declare a TCP/IP transport-layer protocol */
141 #define __tcpip_protocol __table_entry ( TCPIP_PROTOCOLS, 01 )
142
143 /** TCP/IP network-layer protocol table */
144 #define TCPIP_NET_PROTOCOLS \
145         __table ( struct tcpip_net_protocol, "tcpip_net_protocols" )
146
147 /** Declare a TCP/IP network-layer protocol */
148 #define __tcpip_net_protocol __table_entry ( TCPIP_NET_PROTOCOLS, 01 )
149
150 extern int tcpip_rx ( struct io_buffer *iobuf, struct net_device *netdev,
151                       uint8_t tcpip_proto, struct sockaddr_tcpip *st_src,
152                       struct sockaddr_tcpip *st_dest, uint16_t pshdr_csum,
153                       struct ip_statistics *stats );
154 extern int tcpip_tx ( struct io_buffer *iobuf, struct tcpip_protocol *tcpip,
155                       struct sockaddr_tcpip *st_src,
156                       struct sockaddr_tcpip *st_dest,
157                       struct net_device *netdev,
158                       uint16_t *trans_csum );
159 extern struct net_device * tcpip_netdev ( struct sockaddr_tcpip *st_dest );
160 extern size_t tcpip_mtu ( struct sockaddr_tcpip *st_dest );
161 extern uint16_t generic_tcpip_continue_chksum ( uint16_t partial,
162                                                 const void *data, size_t len );
163 extern uint16_t tcpip_chksum ( const void *data, size_t len );
164 extern int tcpip_bind ( struct sockaddr_tcpip *st_local,
165                         int ( * available ) ( int port ) );
166
167 /* Use generic_tcpip_continue_chksum() if no architecture-specific
168  * version is available
169  */
170 #ifndef tcpip_continue_chksum
171 #define tcpip_continue_chksum generic_tcpip_continue_chksum
172 #endif
173
174 #endif /* _IPXE_TCPIP_H */