|
37 | 37 | /* *INDENT-ON* */
|
38 | 38 |
|
39 | 39 | /* The maximum UDP payload length. */
|
40 |
| -#define ipMAX_UDP_PAYLOAD_LENGTH ( ( ipconfigNETWORK_MTU - ipSIZE_OF_IPv4_HEADER ) - ipSIZE_OF_UDP_HEADER ) |
| 40 | +#define ipMAX_UDP_PAYLOAD_LENGTH ( ( ipconfigNETWORK_MTU - ipSIZE_OF_IPv4_HEADER ) - ipSIZE_OF_UDP_HEADER ) |
41 | 41 |
|
42 |
| -#define TCP_PACKET_SIZE ( sizeof( TCPPacket_t ) ) |
| 42 | +#define TCP_PACKET_SIZE ( sizeof( TCPPacket_t ) ) |
43 | 43 |
|
44 | 44 | /* The offset into an IP packet into which the IP data (payload) starts. */
|
45 |
| -#define ipIP_PAYLOAD_OFFSET ( sizeof( IPPacket_t ) ) |
| 45 | +#define ipIP_PAYLOAD_OFFSET ( sizeof( IPPacket_t ) ) |
46 | 46 | /* The offset into a UDP packet at which the UDP data (payload) starts. */
|
47 |
| -#define ipUDP_PAYLOAD_OFFSET_IPv4 ( sizeof( UDPPacket_t ) ) |
48 |
| -/* The value of 'ipUDP_PAYLOAD_IP_TYPE_OFFSET' is 42 + 6 = 48 bytes. */ |
49 |
| -/* __HT_ just to get it compiled. */ |
50 |
| -#if !defined( ipIP_TYPE_OFFSET ) |
51 |
| - #define ipIP_TYPE_OFFSET ( 6U ) |
52 |
| -#endif |
53 |
| -#define ipUDP_PAYLOAD_IP_TYPE_OFFSET ( sizeof( UDPPacket_t ) + ipIP_TYPE_OFFSET ) |
| 47 | +#define ipUDP_PAYLOAD_OFFSET_IPv4 ( sizeof( UDPPacket_t ) ) |
| 48 | +/* The value of 'ipUDP_PAYLOAD_IP_TYPE_OFFSET' is 8 + 40 = 48 bytes. */ |
| 49 | +#define ipUDP_PAYLOAD_IP_TYPE_OFFSET ( sizeof( UDPHeader_t ) + sizeof( IPHeader_IPv6_t ) ) |
| 50 | + |
| 51 | +/* ipIP_TYPE_OFFSET is involved in some sorcery. pxUDPPayloadBuffer_to_NetworkBuffer() must be able to convert |
| 52 | + * a payload pointer ( like for example a pointer to the DNS payload of a packet ) back to a NetworkBufferDescriptor_t. |
| 53 | + * This must work for both IPv4 and IPv6 packets. The pointer conversion is done by subtracting a constant from the payload pointer. |
| 54 | + * For IPv6, this magic number is ( sizeof( UDPHeader_t ) + sizeof( IPHeader_IPv6_t ) ) which equals 48 bytes. |
| 55 | + * If however we use that same constant for an IPv4 packet, we end up somewhere in front of the Ethernet header. |
| 56 | + * In order to accommodate that, the Ethernet frame buffer gets allocated a bit larger than needed. |
| 57 | + * For IPv4 frames, prvProcessIPPacket() stores the version header field at a negative offset, a few bytes before the start |
| 58 | + * of the Ethernet header. That IPv4 version field MUST be stored the same distance from the payload as in IPv6. |
| 59 | + * ipIP_TYPE_OFFSET must be equal to: sizeof( UDPHeader_t ) + sizeof( IPHeader_IPv6_t ) - ( sizeof( UDPPacket_t ) |
| 60 | + * In most situations, ipIP_TYPE_OFFSET will end up being equal to 6. If the Ethernet header is enlarged to include VLAN |
| 61 | + * tag support, ipIP_TYPE_OFFSET will shrink to 2. With the current design, the Ethernet header cannot be expanded to contain |
| 62 | + * more than one VLAN tag or ipIP_TYPE_OFFSET will become less than zero. ipIP_TYPE_OFFSET should never be allowed to be <= 0 |
| 63 | + * or storing of the IPv4 version byte will overwrite the Ethernet header of the frame. |
| 64 | + */ |
| 65 | +#define ipIP_TYPE_OFFSET ( ( int32_t ) sizeof( UDPHeader_t ) + ( int32_t ) sizeof( IPHeader_IPv6_t ) - ( int32_t ) sizeof( UDPPacket_t ) ) |
54 | 66 |
|
55 | 67 | #include "pack_struct_start.h"
|
56 | 68 | struct xIP_HEADER
|
|
0 commit comments