Coverage Report

Created: 2026-05-30 06:26

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openvswitch/lib/dpif-netdev-flow.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2015 Nicira, Inc.
3
 * Copyright (c) 2019, 2020, 2021 Intel Corporation.
4
 *
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:
8
 *
9
 *     http://www.apache.org/licenses/LICENSE-2.0
10
 *
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.
16
 */
17
18
#ifndef DPIF_NETDEV_FLOW_H
19
#define DPIF_NETDEV_FLOW_H 1
20
21
#include <stdbool.h>
22
#include <stdint.h>
23
24
#include "cmap.h"
25
#include "openvswitch/thread.h"
26
27
#ifdef  __cplusplus
28
extern "C" {
29
#endif
30
31
/* Contained by struct dp_netdev_flow's 'stats' member.  */
32
struct dp_netdev_flow_stats {
33
    atomic_llong used;             /* Last used time, in monotonic msecs. */
34
    atomic_ullong packet_count;    /* Number of packets matched. */
35
    atomic_ullong byte_count;      /* Number of bytes matched. */
36
    atomic_uint16_t tcp_flags;     /* Bitwise-OR of seen tcp_flags values. */
37
};
38
39
/* Contained by struct dp_netdev_flow's 'last_attrs' member.  */
40
struct dp_netdev_flow_attrs {
41
    atomic_bool offloaded;         /* True if flow is offloaded to HW. */
42
    ATOMIC(const char *) dp_layer; /* DP layer the flow is handled in. */
43
};
44
45
/* A flow in 'dp_netdev_pmd_thread's 'flow_table'.
46
 *
47
 *
48
 * Thread-safety
49
 * =============
50
 *
51
 * Except near the beginning or ending of its lifespan, rule 'rule' belongs to
52
 * its pmd thread's classifier.  The text below calls this classifier 'cls'.
53
 *
54
 * Motivation
55
 * ----------
56
 *
57
 * The thread safety rules described here for "struct dp_netdev_flow" are
58
 * motivated by two goals:
59
 *
60
 *    - Prevent threads that read members of "struct dp_netdev_flow" from
61
 *      reading bad data due to changes by some thread concurrently modifying
62
 *      those members.
63
 *
64
 *    - Prevent two threads making changes to members of a given "struct
65
 *      dp_netdev_flow" from interfering with each other.
66
 *
67
 *
68
 * Rules
69
 * -----
70
 *
71
 * A flow 'flow' may be accessed without a risk of being freed during an RCU
72
 * grace period.  Code that needs to hold onto a flow for a while
73
 * should try incrementing 'flow->ref_cnt' with dp_netdev_flow_ref().
74
 *
75
 * 'flow->ref_cnt' protects 'flow' from being freed.  It doesn't protect the
76
 * flow from being deleted from 'cls' and it doesn't protect members of 'flow'
77
 * from modification.
78
 *
79
 * Some members, marked 'const', are immutable.  Accessing other members
80
 * requires synchronization, as noted in more detail below.
81
 */
82
struct dp_netdev_flow {
83
    const struct flow flow;      /* Unmasked flow that created this entry. */
84
    /* Hash table index by unmasked flow. */
85
    const struct cmap_node node; /* In owning dp_netdev_pmd_thread's */
86
                                 /* 'flow_table'. */
87
    const struct cmap_node simple_match_node; /* In dp_netdev_pmd_thread's
88
                                                 'simple_match_table'. */
89
    const ovs_u128 ufid;         /* Unique flow identifier. */
90
    const ovs_u128 mega_ufid;    /* Unique mega flow identifier. */
91
    const unsigned pmd_id;       /* The 'core_id' of pmd thread owning this */
92
                                 /* flow. */
93
94
    /* Number of references.
95
     * The classifier owns one reference.
96
     * Any thread trying to keep a rule from being freed should hold its own
97
     * reference. */
98
    struct ovs_refcount ref_cnt;
99
100
    bool dead;
101
    bool offloaded;
102
    atomic_int offload_queue_depth;
103
    uint64_t simple_match_mark;  /* Unique flow mark for the simple match. */
104
    odp_port_t orig_in_port;
105
106
    /* Statistics. */
107
    struct dp_netdev_flow_stats stats;
108
109
    /* Actions. */
110
    OVSRCU_TYPE(struct dp_netdev_actions *) actions;
111
112
    /* While processing a group of input packets, the datapath uses the next
113
     * member to store a pointer to the output batch for the flow.  It is
114
     * reset after the batch has been sent out (See dp_netdev_queue_batches(),
115
     * packet_batch_per_flow_init() and packet_batch_per_flow_execute()). */
116
    struct packet_batch_per_flow *batch;
117
118
    /* Packet classification. */
119
    char *dp_extra_info;         /* String to return in a flow dump/get. */
120
    struct dpcls_rule cr;        /* In owning dp_netdev's 'cls'. */
121
    /* 'cr' must be the last member. */
122
};
123
124
static inline uint32_t
125
dp_netdev_flow_hash(const ovs_u128 *ufid)
126
0
{
127
0
    return ufid->u32[0];
128
0
}
Unexecuted instantiation: dpif-netdev.c:dp_netdev_flow_hash
Unexecuted instantiation: dpif-netdev-dfc.c:dp_netdev_flow_hash
129
130
/* Given the number of bits set in miniflow's maps, returns the size of the
131
 * 'netdev_flow_key.mf' */
132
static inline size_t
133
netdev_flow_key_size(size_t flow_u64s)
134
0
{
135
0
    return sizeof(struct miniflow) + MINIFLOW_VALUES_SIZE(flow_u64s);
136
0
}
Unexecuted instantiation: dpif-netdev.c:netdev_flow_key_size
Unexecuted instantiation: dpif-netdev-dfc.c:netdev_flow_key_size
137
138
/* forward declaration required for EMC to unref flows */
139
void dp_netdev_flow_unref(struct dp_netdev_flow *);
140
141
/* A set of datapath actions within a "struct dp_netdev_flow".
142
 *
143
 *
144
 * Thread-safety
145
 * =============
146
 *
147
 * A struct dp_netdev_actions 'actions' is protected with RCU. */
148
struct dp_netdev_actions {
149
    /* These members are immutable: they do not change during the struct's
150
     * lifetime.  */
151
    unsigned int size;          /* Size of 'actions', in bytes. */
152
    struct nlattr actions[];    /* Sequence of OVS_ACTION_ATTR_* attributes. */
153
};
154
155
#ifdef  __cplusplus
156
}
157
#endif
158
159
#endif /* dpif-netdev-flow.h */