When I send a tcp or udp packet from a network under symmetric nat I
expect the port to be different from the one chosen by my computer and
so it is.
That is the Network Address Port Translation (NAPT) version of NAT. Basic NAT does not do anything with the transport protocol. NAPT must have a different table for each transport protocol, which is why it only supports TCP, UDP and ICMP, because a TCP port is not a UDP port, and ICMP does not use ports, it uses query IDs.
I receive an error icmp packet which contains the udp packet that I
originally sent as a payload, but with the port generated by my system
.
That would be correct.
At this point my doubt is whether NAT does not get its hands on the
content of ICMP packets as well.
For ICMP error messages that must make their way back to the sending application, yes, NAPT must fix the content of the ICMP error messages so that the destination application gets the error. ICMP error message have the first part of the original packet as their payload so that it can be returned to the correct application. If NAPT has modified the outgoing packet, it must modify the returning ICMP error message payload to the original addressing, including the port numbers.
So in the case of an ICMP packet, only the source IP address and not,
as I think it happens, also the ip and port of the echo "subpacket".
This behavior is explained in RFC 2663, IP Network Address Translator (NAT) Terminology and Considerations:
3.3. ICMP error packet translation
All ICMP error messages (with the exception of Redirect message type)
will need to be modified, when passed through NAT. The ICMP error
message types needing NAT modification would include Destination-
Unreachable, Source-Quench, Time-Exceeded and Parameter-Problem. NAT
should not attempt to modify a Redirect message type.
Changes to ICMP error message will include changes to the original IP packet (or portions thereof) embedded in the payload of the ICMP
error message. In order for NAT to be completely transparent to end
hosts, the IP address of the IP header embedded in the payload of the
ICMP packet must be modified, the checksum field of the same IP header
must correspondingly be modified, and the accompanying transport
header. The ICMP header checksum must also be modified to reflect
changes made to the IP and transport headers in the payload.
Furthermore, the normal IP header must also be modified.
As you can see, NAT, and especially NAPT, is very resource intensive, which is why some vendors, such as Cisco, only allow NAT on devices that have a hardware assist for NAT.