API: Decrementing IP Time to Live (TTL)

Link-Inline™ Software User Guide

Platform
Napatech SmartNIC
Content Type
User Guide
Capture Software Version
Link-Inline™ Software 3.2

The SmartNIC can be configured to decrement the value of the IPv4 time-to-live (TTL) field or the IPv6 hop-limit field. Use this DPDK API example to configure the SmartNIC to decrement IP TTL.

Modifying the time-to-live field

This is an example to create a flow rule that modifies the time-to-live (TTL) field on a matched frame, then transmits on port 1.
/* Create group 1 exact match 5-tuple to retransmit offloaded IPv4 UDP packets. */
struct rte_flow_attr attr = { .group = 1, .ingress = 1 };

struct rte_flow_item_ipv4 ipv4 = { .hdr = {
  .src_addr = RTE_BE32(0x12345678), .dst_addr = RTE_BE32(0xbaddecaf) }};
struct rte_flow_item_udp udp = { .hdr = {
  .src_port = RTE_BE16(0x1000), .dst_port = RTE_BE16(0x1001) }};
struct rte_flow_item pattern[] = {
  [0] = { .type = RTE_FLOW_ITEM_TYPE_IPV4, .spec = &ipv4, .mask = &rte_flow_item_ipv4_mask },
  [1] = { .type = RTE_FLOW_ITEM_TYPE_UDP, .spec = &udp, .mask = &rte_flow_item_udp_mask }};

struct rte_flow_action_modify_field modify_field = {
  .operation = RTE_FLOW_MODIFY_SUB,
  .dst = { .field = RTE_FLOW_FIELD_IPV4_TTL },
  .src = { .field = RTE_FLOW_FIELD_VALUE, .value = 1 },
  .width = 1};
struct rte_flow_action_port_id port_id = { .id = 1 };
struct rte_flow_action action[] = {
  [0] = { .type = RTE_FLOW_ACTION_TYPE_MODIFY_FIELD, .conf = &modify_field },
  [1] = { .type = RTE_FLOW_ACTION_TYPE_PORT_ID, .conf = &port_id },
  [2] = { .type = RTE_FLOW_ACTION_TYPE_END }};

struct rte_flow_error error;
struct rte_flow *flow = rte_flow_create(PORT_ID, &attr, pattern, action, &error);
if (!flow) {
  /* Error handling */
}
In this example, an action to modify the field of a frame is defined using the rte_flow_action_modify_field structure, which performs a subtraction operation on the TTL field of the matched frames, reducing by one.
Note: A flow rule with group 0 must be created before the flow rule in this API example is created. This step has been omitted in this example for brevity.