1IBV_CREATE_FLOW(3)      Libibverbs Programmer's Manual      IBV_CREATE_FLOW(3)
2
3
4

NAME

6       ibv_create_flow,  ibv_destroy_flow  -  create  or destroy flow steering
7       rules
8

SYNOPSIS

10       #include <infiniband/verbs.h>
11
12       struct ibv_flow *ibv_create_flow(struct ibv_qp *qp,
13                                        struct ibv_flow_attr *flow_attr);
14       int ibv_destroy_flow(struct ibv_flow *flow_id);
15
16

DESCRIPTION

18   ibv_create_flow()
19       allows a user application QP qp to be attached into  a  specified  flow
20       flow which is defined in <infiniband/verbs.h>
21
22       struct ibv_flow_attr {
23               uint32_t comp_mask;                     /* Future extendibility */
24               enum ibv_flow_attr_type type;           /* Rule type - see below */
25               uint16_t size;                          /* Size of command */
26               uint16_t priority;                      /* Rule priority - see below */
27               uint8_t num_of_specs;                   /* Number of ibv_flow_spec_xxx */
28               uint8_t port;                           /* The uplink port number */
29               uint32_t flags;                         /* Extra flags for rule - see below */
30               /* Following are the optional layers according to user request
31                * struct ibv_flow_spec_xxx
32                * struct ibv_flow_spec_yyy
33                */
34       };
35
36       enum ibv_flow_attr_type {
37               IBV_FLOW_ATTR_NORMAL          = 0x0,         /* Steering according to rule specifications */
38               IBV_FLOW_ATTR_ALL_DEFAULT     = 0x1,         /* Default unicast and multicast rule - receive all Eth traffic which isn't steered to any QP */
39               IBV_FLOW_ATTR_MC_DEFAULT      = 0x2,         /* Default multicast rule - receive all Eth multicast traffic which isn't steered to any QP */
40               IBV_FLOW_ATTR_SNIFFER         = 0x3,         /* Sniffer rule - receive all port traffic */
41       };
42
43       enum ibv_flow_flags {
44               IBV_FLOW_ATTR_FLAGS_ALLOW_LOOP_BACK = 1 << 0,     /* Apply the rules on packets that were sent from the attached QP through loopback */
45               IBV_FLOW_ATTR_FLAGS_DONT_TRAP       = 1 << 1,     /* Rule doesn't trap received packets, allowing them to match lower prioritized rules */
46               IBV_FLOW_ATTR_FLAGS_EGRESS          = 1 << 2,     /* Match sent packets against EGRESS rules and carry associated actions if required */
47       };
48
49       enum ibv_flow_spec_type {
50               IBV_FLOW_SPEC_ETH                       = 0x20,   /* Flow specification of L2 header */
51               IBV_FLOW_SPEC_IPV4                      = 0x30,   /* Flow specification of IPv4 header */
52               IBV_FLOW_SPEC_IPV6                      = 0x31,   /* Flow specification of IPv6 header */
53               IBV_FLOW_SPEC_IPV4_EXT                  = 0x32,   /* Extended flow specification of IPv4 */
54               IBV_FLOW_SPEC_ESP                       = 0x34,   /* Flow specification of ESP (IPSec) header */
55               IBV_FLOW_SPEC_TCP                       = 0x40,   /* Flow specification of TCP header */
56               IBV_FLOW_SPEC_UDP                       = 0x41,   /* Flow specification of UDP header */
57               IBV_FLOW_SPEC_VXLAN_TUNNEL              = 0x50,   /* Flow specification of VXLAN header */
58               IBV_FLOW_SPEC_GRE                       = 0x51,   /* Flow specification of GRE header */
59               IBV_FLOW_SPEC_MPLS                      = 0x60,   /* Flow specification of MPLS header */
60               IBV_FLOW_SPEC_INNER                     = 0x100,  /* Flag making L2/L3/L4 specifications to be applied on the inner header */
61               IBV_FLOW_SPEC_ACTION_TAG                = 0x1000, /* Action tagging matched packet */
62               IBV_FLOW_SPEC_ACTION_DROP               = 0x1001, /* Action dropping matched packet */
63               IBV_FLOW_SPEC_ACTION_HANDLE             = 0x1002, /* Carry out an action created by ibv_create_flow_action_xxxx verb */
64               IBV_FLOW_SPEC_ACTION_COUNT              = 0x1003, /* Action count matched packet with a ibv_counters handle */
65       };
66
67       Flow specification general structure:
68
69       struct ibv_flow_spec_xxx {
70               enum ibv_flow_spec_type  type;
71               uint16_t  size;                  /* Flow specification size = sizeof(struct ibv_flow_spec_xxx) */
72               struct ibv_flow_xxx_filter val;
73               struct ibv_flow_xxx_filter mask; /* Defines which bits from the filter value are applicable when looking for a match in the incoming packet */
74       };
75
76       Each spec struct holds the relevant network layer parameters for matching. To enforce the match, the user sets a mask for each parameter.
77       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.
78       In ingress flows, the QP parameter is treated as another action of scattering the packet to the respected QP.
79       If the bit is set in the mask, the corresponding bit in the value should be matched.
80       Note that most vendors support either full mask (all "1"s) or zero mask (all "0"s).
81       Network parameters in the relevant network structs should be given in network order (big endian).
82
83
84   Flow domains and priority
85       Flow  steering  defines the concept of domain and priority. Each domain
86       represents an application that can attach a flow.  Domains are  priori‐
87       tized.  A higher priority domain will always supersede a lower priority
88       domain when their flow specifications overlap.
89       IB verbs have the higher priority domain.
90       In addition to the  domain,  there  is  priority  within  each  of  the
91       domains.  A lower priority numeric value (higher priority) takes prece‐
92       dence over matching rules with higher  numeric  priority  value  (lower
93       priority).   It  is important to note that the priority value of a flow
94       spec is used not only to establish the precedence of  conflicting  flow
95       matches but also as a way to abstract the order on which flow specs are
96       tested for matches. Flows with higher priorities will be tested  before
97       flows with lower priorities.
98
99
100   Rules definition ordering
101       An application can provide the ibv_flow_spec_xxx rules in an un-ordered
102       scheme. In this case, each spec should be well defined and match a spe‐
103       cific  network  header  layer.   In  some cases, when certain flow spec
104       types are present in the spec list, it is required to provide the  list
105       in an ordered manner so that the position of that flow spec type in the
106       protocol stack is strictly defined.  When the certain spec type,  which
107       requires  the ordering, resides in the inner network protocol stack (in
108       tunnel protocols) the ordering should be applied to the  inner  network
109       specs  and  should be combined with the inner spec indication using the
110       IBV_FLOW_SPEC_INNER flag.  For example: An MPLS spec which attempts  to
111       match   an   MPLS   tag   in   the   inner   network  should  have  the
112       IBV_FLOW_SPEC_INNER flag set and so do the rest of  the  inner  network
113       specs.  On  top of that, all the inner network specs should be provided
114       in an ordered manner.  This is  essential  to  represent  many  of  the
115       encapsulation tunnel protocols.
116
117       The flow spec types which require this sort of ordering are:
118       1. IBV_FLOW_SPEC_MPLS -
119       Since MPLS header can appear at several locations in the protocol stack
120       and can also be encapsulated on top of different layers, it is required
121       to  place  this  spec  according  to its exact location in the protocol
122       stack.
123
124   ibv_destroy_flow()
125       destroys the flow flow_id.
126

RETURN VALUE

128       ibv_create_flow() returns a pointer to the flow, or NULL if the request
129       fails. In case of an error, errno is updated.
130
131       ibv_destroy_flow() returns 0 on success, or the value of errno on fail‐
132       ure (which indicates the failure reason).
133

ERRORS

135   EINVAL
136       ibv_create_flow() flow specification, QP or priority are invalid
137
138       ibv_destroy_flow() flow_id is invalid
139
140   ENOMEM
141       Couldn't create/destroy flow, not enough memory
142
143   ENXIO
144       Device managed flow steering isn't currently supported
145
146   EPERM
147       No permissions to add the flow steering rule
148

NOTES

150       1. These verbs are available only for devices supporting
151          IBV_DEVICE_MANAGED_FLOW_STEERING and only for QPs of Transport  Ser‐
152       vice Type IBV_QPT_UD or IBV_QPT_RAW_PACKET
153       2. User must memset the spec struct with zeros before using it.
154       3.  ether_type  field in ibv_flow_eth_filter is the ethertype following
155       the last VLAN tag of the packet.
156       4.     Only      rule      type      IBV_FLOW_ATTR_NORMAL      supports
157       IBV_FLOW_ATTR_FLAGS_DONT_TRAP flag.
158       5. No specifications are needed for IBV_FLOW_ATTR_SNIFFER rule type.
159       6.  When  IBV_FLOW_ATTR_FLAGS_EGRESS  flag  is set, the qp parameter is
160       used only as a mean to get the device.
161

EXAMPLE

163       Below flow_attr defines a rule in priority 0 to match a destination mac
164       address and a source ipv4 address. For that, L2 and L3 specs are used.
165       If  there is a hit on this rule, means the received packet has destina‐
166       tion mac: 66:11:22:33:44:55 and source ip: 0x0B86C806,  the  packet  is
167       steered to its attached qp.
168
169       struct raw_eth_flow_attr {
170               struct ibv_flow_attr            attr;
171               struct ibv_flow_spec_eth        spec_eth;
172               struct ibv_flow_spec_ipv4       spec_ipv4;
173       } __attribute__((packed));
174
175       struct raw_eth_flow_attr flow_attr = {
176                       .attr = {
177                               .comp_mask      = 0,
178                               .type           = IBV_FLOW_ATTR_NORMAL,
179                               .size           = sizeof(flow_attr),
180                               .priority       = 0,
181                               .num_of_specs   = 2,
182                               .port           = 1,
183                               .flags          = 0,
184                       },
185                       .spec_eth = {
186                               .type   = IBV_FLOW_SPEC_ETH,
187                               .size   = sizeof(struct ibv_flow_spec_eth),
188                               .val = {
189                                       .dst_mac = {0x66, 0x11, 0x22, 0x33, 0x44, 0x55},
190                                       .src_mac = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
191                                       .ether_type = 0,
192                                       .vlan_tag = 0,
193                               },
194                               .mask = {
195                                       .dst_mac = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
196                                       .src_mac = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
197                                       .ether_type = 0,
198                                       .vlan_tag = 0,
199                               }
200                       },
201                       .spec_ipv4 = {
202                               .type   = IBV_FLOW_SPEC_IPV4,
203                               .size   = sizeof(struct ibv_flow_spec_ipv4),
204                               .val = {
205                                       .src_ip = 0x0B86C806,
206                                       .dst_ip = 0,
207                               },
208                               .mask = {
209                                       .src_ip = 0xFFFFFFFF,
210                                       .dst_ip = 0,
211                               }
212                       }
213       };
214
215

AUTHORS

217       Hadar Hen Zion <hadarh@mellanox.com>
218
219       Matan Barak <matanb@mellanox.com>
220
221       Yishai Hadas <yishaih@mellanox.com>
222
223       Maor Gottlieb <maorg@mellanox.com>
224
225
226
227libibverbs                        2016-03-15                IBV_CREATE_FLOW(3)
Impressum