#include <infiniband/verbs.h> struct ibv_flow *ibv_create_flow(struct ibv_qp *qp, struct ibv_flow_attr *flow_attr); int ibv_destroy_flow(struct ibv_flow *flow_id);
struct ibv_flow_attr { uint32_t comp_mask; /* Future extendibility */ enum ibv_flow_attr_type type; /* Rule type - see below */ uint16_t size; /* Size of command */ uint16_t priority; /* Rule priority - see below */ uint8_t num_of_specs; /* Number of ibv_flow_spec_xxx */ uint8_t port; /* The uplink port number */ uint32_t flags; /* Extra flags for rule - see below */ /* Following are the optional layers according to user request * struct ibv_flow_spec_xxx * struct ibv_flow_spec_yyy */ }; enum ibv_flow_attr_type { IBV_FLOW_ATTR_NORMAL = 0x0, /* Steering according to rule specifications */ IBV_FLOW_ATTR_ALL_DEFAULT = 0x1, /* Default unicast and multicast rule - receive all Eth traffic which isn't steered to any QP */ IBV_FLOW_ATTR_MC_DEFAULT = 0x2, /* Default multicast rule - receive all Eth multicast traffic which isn't steered to any QP */ IBV_FLOW_ATTR_SNIFFER = 0x3, /* Sniffer rule - receive all port traffic */ }; enum ibv_flow_flags { IBV_FLOW_ATTR_FLAGS_DONT_TRAP = 1 << 1, /* Rule doesn't trap received packets, allowing them to match lower prioritized rules */ IBV_FLOW_ATTR_FLAGS_EGRESS = 1 << 2, /* Match sent packets against EGRESS rules and carry associated actions if required */ };
enum ibv_flow_spec_type { IBV_FLOW_SPEC_ETH = 0x20, /* Flow specification of L2 header */ IBV_FLOW_SPEC_IPV4 = 0x30, /* Flow specification of IPv4 header */ IBV_FLOW_SPEC_IPV6 = 0x31, /* Flow specification of IPv6 header */ IBV_FLOW_SPEC_IPV4_EXT = 0x32, /* Extended flow specification of IPv4 */ IBV_FLOW_SPEC_ESP = 0x34, /* Flow specification of ESP (IPSec) header */ IBV_FLOW_SPEC_TCP = 0x40, /* Flow specification of TCP header */ IBV_FLOW_SPEC_UDP = 0x41, /* Flow specification of UDP header */ IBV_FLOW_SPEC_VXLAN_TUNNEL = 0x50, /* Flow specification of VXLAN header */ IBV_FLOW_SPEC_GRE = 0x51, /* Flow specification of GRE header */ IBV_FLOW_SPEC_MPLS = 0x60, /* Flow specification of MPLS header */ IBV_FLOW_SPEC_INNER = 0x100, /* Flag making L2/L3/L4 specifications to be applied on the inner header */ IBV_FLOW_SPEC_ACTION_TAG = 0x1000, /* Action tagging matched packet */ IBV_FLOW_SPEC_ACTION_DROP = 0x1001, /* Action dropping matched packet */ IBV_FLOW_SPEC_ACTION_HANDLE = 0x1002, /* Carry out an action created by ibv_create_flow_action_xxxx verb */ IBV_FLOW_SPEC_ACTION_COUNT = 0x1003, /* Action count matched packet with a ibv_counters handle */ };
Flow specification general structure: struct ibv_flow_spec_xxx { enum ibv_flow_spec_type type; uint16_t size; /* Flow specification size = sizeof(struct ibv_flow_spec_xxx) */ struct ibv_flow_xxx_filter val; struct ibv_flow_xxx_filter mask; /* Defines which bits from the filter value are applicable when looking for a match in the incoming packet */ }; Each spec struct holds the relevant network layer parameters for matching. To enforce the match, the user sets a mask for each parameter.
Packets coming from the wire are matched against the flow specification. If a match is found, the associated flow actions are executed on the packet.
In ingress flows, the QP parameter is treated as another action of scattering the packet to the respected QP.
If the bit is set in the mask, the corresponding bit in the value should be matched.
Note that most vendors support either full mask (all "1"s) or zero mask (all "0"s).
Network parameters in the relevant network structs should be given in network order (big endian).
The flow spec types which require this sort of ordering are:
1. IBV_FLOW_SPEC_MPLS -
Since MPLS header can appear at several locations in the protocol stack and can also be
encapsulated on top of different layers, it is required to place this spec according to its exact location in the
protocol stack.
ibv_destroy_flow() returns 0 on success, or the value of errno on failure (which indicates the failure reason).
ibv_destroy_flow() flow_id is invalid
struct raw_eth_flow_attr { struct ibv_flow_attr attr; struct ibv_flow_spec_eth spec_eth; struct ibv_flow_spec_ipv4 spec_ipv4; } __attribute__((packed)); struct raw_eth_flow_attr flow_attr = { .attr = { .comp_mask = 0, .type = IBV_FLOW_ATTR_NORMAL, .size = sizeof(flow_attr), .priority = 0, .num_of_specs = 2, .port = 1, .flags = 0, }, .spec_eth = { .type = IBV_FLOW_SPEC_ETH, .size = sizeof(struct ibv_flow_spec_eth), .val = { .dst_mac = {0x66, 0x11, 0x22, 0x33, 0x44, 0x55}, .src_mac = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, .ether_type = 0, .vlan_tag = 0, }, .mask = { .dst_mac = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, .src_mac = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, .ether_type = 0, .vlan_tag = 0, } }, .spec_ipv4 = { .type = IBV_FLOW_SPEC_IPV4, .size = sizeof(struct ibv_flow_spec_ipv4), .val = { .src_ip = 0x0B86C806, .dst_ip = 0, }, .mask = { .src_ip = 0xFFFFFFFF, .dst_ip = 0, } } };