Coverage Report

Created: 2025-07-11 06:12

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