2 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2015 Nicira, Inc.
3 * Copyright (c) 2019 Intel Corporation.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #ifndef DPIF_NETDEV_PRIVATE_H
19 #define DPIF_NETDEV_PRIVATE_H 1
31 /* Forward declaration for lookup_func typedef. */
32 struct dpcls_subtable
;
35 /* Must be public as it is instantiated in subtable struct below. */
36 struct netdev_flow_key
{
37 uint32_t hash
; /* Hash function differs for different users. */
38 uint32_t len
; /* Length of the following miniflow (incl. map). */
40 uint64_t buf
[FLOW_MAX_PACKET_U64S
];
43 /* A rule to be inserted to the classifier. */
45 struct cmap_node cmap_node
; /* Within struct dpcls_subtable 'rules'. */
46 struct netdev_flow_key
*mask
; /* Subtable's mask. */
47 struct netdev_flow_key flow
; /* Matching key. */
48 /* 'flow' must be the last field, additional space is allocated here. */
51 /* Lookup function for a subtable in the dpcls. This function is called
52 * by each subtable with an array of packets, and a bitmask of packets to
53 * perform the lookup on. Using a function pointer gives flexibility to
54 * optimize the lookup function based on subtable properties and the
55 * CPU instruction set available at runtime.
58 uint32_t (*dpcls_subtable_lookup_func
)(struct dpcls_subtable
*subtable
,
60 const struct netdev_flow_key
*keys
[],
61 struct dpcls_rule
**rules
);
63 /* A set of rules that all have the same fields wildcarded. */
64 struct dpcls_subtable
{
65 /* The fields are only used by writers. */
66 struct cmap_node cmap_node OVS_GUARDED
; /* Within dpcls 'subtables_map'. */
68 /* These fields are accessed by readers. */
69 struct cmap rules
; /* Contains "struct dpcls_rule"s. */
70 uint32_t hit_cnt
; /* Number of match hits in subtable in current
71 optimization interval. */
73 /* Miniflow fingerprint that the subtable matches on. The miniflow "bits"
74 * are used to select the actual dpcls lookup implementation at subtable
77 uint8_t mf_bits_set_unit0
;
78 uint8_t mf_bits_set_unit1
;
80 /* The lookup function to use for this subtable. If there is a known
81 * property of the subtable (eg: only 3 bits of miniflow metadata is
82 * used for the lookup) then this can point at an optimized version of
83 * the lookup function for this particular subtable. */
84 dpcls_subtable_lookup_func lookup_func
;
86 /* Caches the masks to match a packet to, reducing runtime calculations. */
89 struct netdev_flow_key mask
; /* Wildcards for fields (const). */
90 /* 'mask' must be the last field, additional space is allocated here. */
93 /* Iterate through netdev_flow_key TNL u64 values specified by 'FLOWMAP'. */
94 #define NETDEV_FLOW_KEY_FOR_EACH_IN_FLOWMAP(VALUE, KEY, FLOWMAP) \
95 MINIFLOW_FOR_EACH_IN_FLOWMAP (VALUE, &(KEY)->mf, FLOWMAP)
97 /* Generates a mask for each bit set in the subtable's miniflow. */
99 netdev_flow_key_gen_masks(const struct netdev_flow_key
*tbl
,
101 const uint32_t mf_bits_u0
,
102 const uint32_t mf_bits_u1
);
104 /* Matches a dpcls rule against the incoming packet in 'target' */
105 bool dpcls_rule_matches_key(const struct dpcls_rule
*rule
,
106 const struct netdev_flow_key
*target
);
112 #endif /* netdev-private.h */