-/* Compute flow hash. We'll use it to select which adjacency to use for this
- flow. And other things. */
-always_inline u32
-ip4_compute_flow_hash (const ip4_header_t * ip,
- flow_hash_config_t flow_hash_config)
-{
- tcp_header_t *tcp = (void *) (ip + 1);
- u32 a, b, c, t1, t2;
- uword is_tcp_udp = (ip->protocol == IP_PROTOCOL_TCP
- || ip->protocol == IP_PROTOCOL_UDP);
-
- t1 = (flow_hash_config & IP_FLOW_HASH_SRC_ADDR)
- ? ip->src_address.data_u32 : 0;
- t2 = (flow_hash_config & IP_FLOW_HASH_DST_ADDR)
- ? ip->dst_address.data_u32 : 0;
-
- a = (flow_hash_config & IP_FLOW_HASH_REVERSE_SRC_DST) ? t2 : t1;
- b = (flow_hash_config & IP_FLOW_HASH_REVERSE_SRC_DST) ? t1 : t2;
- b ^= (flow_hash_config & IP_FLOW_HASH_PROTO) ? ip->protocol : 0;
-
- t1 = is_tcp_udp ? tcp->src : 0;
- t2 = is_tcp_udp ? tcp->dst : 0;
-
- t1 = (flow_hash_config & IP_FLOW_HASH_SRC_PORT) ? t1 : 0;
- t2 = (flow_hash_config & IP_FLOW_HASH_DST_PORT) ? t2 : 0;
-
- c = (flow_hash_config & IP_FLOW_HASH_REVERSE_SRC_DST) ?
- (t1 << 16) | t2 : (t2 << 16) | t1;
-
- hash_v3_mix32 (a, b, c);
- hash_v3_finalize32 (a, b, c);