-/*
- * ip4_map_get_port
- */
-u16
-ip4_map_get_port (ip4_header_t * ip, map_dir_e dir)
-{
- /* Find port information */
- if (PREDICT_TRUE ((ip->protocol == IP_PROTOCOL_TCP) ||
- (ip->protocol == IP_PROTOCOL_UDP)))
- {
- udp_header_t *udp = (void *) (ip + 1);
- return (dir == MAP_SENDER ? udp->src_port : udp->dst_port);
- }
- else if (ip->protocol == IP_PROTOCOL_ICMP)
- {
- /*
- * 1) ICMP Echo request or Echo reply
- * 2) ICMP Error with inner packet being UDP or TCP
- * 3) ICMP Error with inner packet being ICMP Echo request or Echo reply
- */
- icmp46_header_t *icmp = (void *) (ip + 1);
- if (icmp->type == ICMP4_echo_request || icmp->type == ICMP4_echo_reply)
- {
- return *((u16 *) (icmp + 1));
- }
- else if (clib_net_to_host_u16 (ip->length) >= 56)
- { // IP + ICMP + IP + L4 header
- ip4_header_t *icmp_ip = (ip4_header_t *) (icmp + 2);
- if (PREDICT_TRUE ((icmp_ip->protocol == IP_PROTOCOL_TCP) ||
- (icmp_ip->protocol == IP_PROTOCOL_UDP)))
- {
- udp_header_t *udp = (void *) (icmp_ip + 1);
- return (dir == MAP_SENDER ? udp->dst_port : udp->src_port);
- }
- else if (icmp_ip->protocol == IP_PROTOCOL_ICMP)
- {
- icmp46_header_t *inner_icmp = (void *) (icmp_ip + 1);
- if (inner_icmp->type == ICMP4_echo_request
- || inner_icmp->type == ICMP4_echo_reply)
- return (*((u16 *) (inner_icmp + 1)));
- }
- }
- }
- return (0);
-}
-