X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=vnet%2Fvnet%2Fmap%2Fip4_map.c;h=c8ee2764f2365c6b2fd2528ee583952525dea39b;hb=366ac6ecdea0214363f523967830c370697c8944;hp=6ed176c8e60ab81d636e871c33fbba9b3c994ad6;hpb=1bc56f7fa162eab44214e5e2fa02f8b3a5ccb021;p=vpp.git diff --git a/vnet/vnet/map/ip4_map.c b/vnet/vnet/map/ip4_map.c index 6ed176c8e60..c8ee2764f23 100644 --- a/vnet/vnet/map/ip4_map.c +++ b/vnet/vnet/map/ip4_map.c @@ -155,6 +155,28 @@ ip4_map_ip6_lookup_bypass (vlib_buffer_t *p0, ip4_header_t *ip) return (false); } +/* + * ip4_map_ttl + */ +static inline void +ip4_map_decrement_ttl (ip4_header_t *ip, u8 *error) +{ + i32 ttl = ip->ttl; + + /* Input node should have reject packets with ttl 0. */ + ASSERT (ip->ttl > 0); + + u32 checksum = ip->checksum + clib_host_to_net_u16(0x0100); + checksum += checksum >= 0xffff; + ip->checksum = checksum; + ttl -= 1; + ip->ttl = ttl; + *error = ttl <= 0 ? IP4_ERROR_TIME_EXPIRED : *error; + + /* Verify checksum. */ + ASSERT (ip->checksum == ip4_header_checksum(ip)); +} + /* * ip4_map */ @@ -345,6 +367,9 @@ ip4_map (vlib_main_t *vm, */ port0 = ip4_map_port_and_security_check(d0, ip40, &next0, &error0); + /* Decrement IPv4 TTL */ + ip4_map_decrement_ttl(ip40, &error0); + /* MAP calc */ u32 da40 = clib_net_to_host_u32(ip40->dst_address.as_u32); u16 dp40 = clib_net_to_host_u16(port0);