Coverage Report

Created: 2023-03-26 07:42

/src/openvswitch/lib/nx-match.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2010-2017, 2020 Nicira, Inc.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at:
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef NX_MATCH_H
18
#define NX_MATCH_H 1
19
20
#include <stdint.h>
21
#include <sys/types.h>
22
#include <netinet/in.h>
23
#include "compiler.h"
24
#include "flow.h"
25
#include "openvswitch/meta-flow.h"
26
#include "openvswitch/ofp-errors.h"
27
#include "openvswitch/types.h"
28
29
struct ds;
30
struct match;
31
struct ofpact_reg_move;
32
struct ofpact_reg_load;
33
struct ofpact_stack;
34
struct ofpbuf;
35
struct nx_action_reg_load;
36
struct nx_action_reg_move;
37
struct vl_mff_map;
38
39
40
/* Nicira Extended Match (NXM) flexible flow match helper functions.
41
 *
42
 * See include/openflow/nicira-ext.h for NXM specification.
43
 */
44
45
char * mf_parse_field(const struct mf_field **field, const char *s)
46
    OVS_WARN_UNUSED_RESULT;
47
void mf_format_subfield(const struct mf_subfield *, struct ds *);
48
char *mf_parse_subfield__(struct mf_subfield *sf, const char **s)
49
    OVS_WARN_UNUSED_RESULT;
50
char *mf_parse_subfield(struct mf_subfield *, const char *s)
51
    OVS_WARN_UNUSED_RESULT;
52
53
/* Decoding matches. */
54
enum ofperr nx_pull_match(struct ofpbuf *, unsigned int match_len,
55
                          struct match *, ovs_be64 *cookie,
56
                          ovs_be64 *cookie_mask, bool pipeline_fields_only,
57
                          const struct tun_table *, const struct vl_mff_map *);
58
enum ofperr nx_pull_match_loose(struct ofpbuf *, unsigned int match_len,
59
                                struct match *, ovs_be64 *cookie,
60
                                ovs_be64 *cookie_mask,
61
                                bool pipeline_fields_only,
62
                                const struct tun_table *);
63
enum ofperr oxm_pull_match(struct ofpbuf *, bool pipeline_fields_only,
64
                           const struct tun_table *, const struct vl_mff_map *,
65
                           struct match *);
66
enum ofperr oxm_pull_match_loose(struct ofpbuf *, bool pipeline_fields_only,
67
                                 const struct tun_table *, struct match *);
68
enum ofperr oxm_decode_match(const void *, size_t, bool,
69
                             const struct tun_table *,
70
                             const struct vl_mff_map *, struct match *);
71
enum ofperr oxm_pull_field_array(const void *, size_t fields_len,
72
                                 struct field_array *);
73
74
/* Encoding matches. */
75
int nx_put_match(struct ofpbuf *, const struct match *,
76
                 ovs_be64 cookie, ovs_be64 cookie_mask);
77
int oxm_put_match(struct ofpbuf *, const struct match *, enum ofp_version);
78
void oxm_put_raw(struct ofpbuf *, const struct match *, enum ofp_version);
79
void oxm_format_field_array(struct ds *, const struct field_array *);
80
int oxm_put_field_array(struct ofpbuf *, const struct field_array *,
81
                        enum ofp_version version);
82
83
/* Decoding and encoding OXM/NXM headers (just a field ID) or entries (a field
84
 * ID followed by a value and possibly a mask). */
85
enum ofperr nx_pull_entry(struct ofpbuf *, const struct vl_mff_map *,
86
                          const struct mf_field **, union mf_value *value,
87
                          union mf_value *mask, bool is_action);
88
enum ofperr nx_pull_header(struct ofpbuf *, const struct vl_mff_map *,
89
                           const struct mf_field **, bool *masked);
90
void nxm_put_entry_raw(struct ofpbuf *, enum mf_field_id field,
91
                       enum ofp_version version, const void *value,
92
                       const void *mask, size_t n_bytes);
93
void nx_put_entry(struct ofpbuf *, const struct mf_field *, enum ofp_version,
94
                  const union mf_value *value, const union mf_value *mask);
95
void nx_put_header(struct ofpbuf *, enum mf_field_id, enum ofp_version,
96
                   bool masked);
97
void nx_put_mff_header(struct ofpbuf *, const struct mf_field *,
98
                       enum ofp_version, bool);
99
100
/* NXM and OXM protocol headers values.
101
 *
102
 * These are often alternatives to nx_pull_entry/header() and
103
 * nx_put_entry/header() for decoding and encoding OXM/NXM.  In those cases,
104
 * the nx_*() functions should be preferred because they can support the 64-bit
105
 * "experimenter" OXM format (even though it is not yet implemented). */
106
uint32_t mf_nxm_header(enum mf_field_id);
107
uint32_t nxm_header_from_mff(const struct mf_field *);
108
const struct mf_field *mf_from_nxm_header(uint32_t nxm_header,
109
                                          const struct vl_mff_map *);
110
111
char *nx_match_to_string(const uint8_t *, unsigned int match_len);
112
char *oxm_match_to_string(const struct ofpbuf *, unsigned int match_len);
113
int nx_match_from_string(const char *, struct ofpbuf *);
114
int oxm_match_from_string(const char *, struct ofpbuf *);
115
116
void nx_format_field_name(enum mf_field_id, enum ofp_version, struct ds *);
117
118
char *nxm_parse_reg_move(struct ofpact_reg_move *, const char *)
119
    OVS_WARN_UNUSED_RESULT;
120
121
void nxm_format_reg_move(const struct ofpact_reg_move *, struct ds *);
122
123
enum ofperr nxm_reg_move_check(const struct ofpact_reg_move *,
124
                               const struct match *);
125
126
void nxm_reg_load(const struct mf_subfield *, uint64_t src_data,
127
                  struct flow *, struct flow_wildcards *);
128
129
char *nxm_parse_stack_action(struct ofpact_stack *, const char *)
130
    OVS_WARN_UNUSED_RESULT;
131
132
void nxm_format_stack_push(const struct ofpact_stack *, struct ds *);
133
void nxm_format_stack_pop(const struct ofpact_stack *, struct ds *);
134
135
enum ofperr nxm_stack_push_check(const struct ofpact_stack *,
136
                                 const  struct match *);
137
enum ofperr nxm_stack_pop_check(const struct ofpact_stack *,
138
                                const struct match *);
139
void nx_stack_push(struct ofpbuf *stack, const void *v, uint8_t bytes);
140
void nx_stack_push_bottom(struct ofpbuf *stack, const void *v, uint8_t bytes);
141
void *nx_stack_pop(struct ofpbuf *stack, uint8_t *bytes);
142
143
void nxm_execute_stack_push(const struct ofpact_stack *,
144
                            const struct flow *, struct flow_wildcards *,
145
                            struct ofpbuf *);
146
bool nxm_execute_stack_pop(const struct ofpact_stack *,
147
                           struct flow *, struct flow_wildcards *,
148
                           struct ofpbuf *);
149
150
ovs_be64 oxm_bitmap_from_mf_bitmap(const struct mf_bitmap *, enum ofp_version);
151
struct mf_bitmap oxm_bitmap_to_mf_bitmap(ovs_be64 oxm_bitmap,
152
                                         enum ofp_version);
153
struct mf_bitmap oxm_writable_fields(void);
154
struct mf_bitmap oxm_matchable_fields(void);
155
struct mf_bitmap oxm_maskable_fields(void);
156
157
/* Dealing with the 'ofs_nbits' members in several Nicira extensions. */
158
159
static inline ovs_be16
160
nxm_encode_ofs_nbits(int ofs, int n_bits)
161
0
{
162
0
    return htons((ofs << 6) | (n_bits - 1));
163
0
}
Unexecuted instantiation: ofp-print.c:nxm_encode_ofs_nbits
Unexecuted instantiation: ofp-table.c:nxm_encode_ofs_nbits
Unexecuted instantiation: ofp-util.c:nxm_encode_ofs_nbits
Unexecuted instantiation: meta-flow.c:nxm_encode_ofs_nbits
Unexecuted instantiation: nx-match.c:nxm_encode_ofs_nbits
Unexecuted instantiation: ofp-actions.c:nxm_encode_ofs_nbits
Unexecuted instantiation: ofp-flow.c:nxm_encode_ofs_nbits
Unexecuted instantiation: ofp-group.c:nxm_encode_ofs_nbits
Unexecuted instantiation: ofp-match.c:nxm_encode_ofs_nbits
Unexecuted instantiation: ofp-meter.c:nxm_encode_ofs_nbits
Unexecuted instantiation: ofp-monitor.c:nxm_encode_ofs_nbits
Unexecuted instantiation: ofp-packet.c:nxm_encode_ofs_nbits
Unexecuted instantiation: tun-metadata.c:nxm_encode_ofs_nbits
Unexecuted instantiation: bundle.c:nxm_encode_ofs_nbits
Unexecuted instantiation: learn.c:nxm_encode_ofs_nbits
Unexecuted instantiation: multipath.c:nxm_encode_ofs_nbits
164
165
static inline int
166
nxm_decode_ofs(ovs_be16 ofs_nbits)
167
36.5k
{
168
36.5k
    return ntohs(ofs_nbits) >> 6;
169
36.5k
}
Unexecuted instantiation: ofp-print.c:nxm_decode_ofs
Unexecuted instantiation: ofp-table.c:nxm_decode_ofs
Unexecuted instantiation: ofp-util.c:nxm_decode_ofs
Unexecuted instantiation: meta-flow.c:nxm_decode_ofs
Unexecuted instantiation: nx-match.c:nxm_decode_ofs
ofp-actions.c:nxm_decode_ofs
Line
Count
Source
167
36.5k
{
168
36.5k
    return ntohs(ofs_nbits) >> 6;
169
36.5k
}
Unexecuted instantiation: ofp-flow.c:nxm_decode_ofs
Unexecuted instantiation: ofp-group.c:nxm_decode_ofs
Unexecuted instantiation: ofp-match.c:nxm_decode_ofs
Unexecuted instantiation: ofp-meter.c:nxm_decode_ofs
Unexecuted instantiation: ofp-monitor.c:nxm_decode_ofs
Unexecuted instantiation: ofp-packet.c:nxm_decode_ofs
Unexecuted instantiation: tun-metadata.c:nxm_decode_ofs
Unexecuted instantiation: bundle.c:nxm_decode_ofs
Unexecuted instantiation: learn.c:nxm_decode_ofs
Unexecuted instantiation: multipath.c:nxm_decode_ofs
170
171
static inline int
172
nxm_decode_n_bits(ovs_be16 ofs_nbits)
173
36.5k
{
174
36.5k
    return (ntohs(ofs_nbits) & 0x3f) + 1;
175
36.5k
}
Unexecuted instantiation: ofp-print.c:nxm_decode_n_bits
Unexecuted instantiation: ofp-table.c:nxm_decode_n_bits
Unexecuted instantiation: ofp-util.c:nxm_decode_n_bits
Unexecuted instantiation: meta-flow.c:nxm_decode_n_bits
Unexecuted instantiation: nx-match.c:nxm_decode_n_bits
ofp-actions.c:nxm_decode_n_bits
Line
Count
Source
173
36.5k
{
174
36.5k
    return (ntohs(ofs_nbits) & 0x3f) + 1;
175
36.5k
}
Unexecuted instantiation: ofp-flow.c:nxm_decode_n_bits
Unexecuted instantiation: ofp-group.c:nxm_decode_n_bits
Unexecuted instantiation: ofp-match.c:nxm_decode_n_bits
Unexecuted instantiation: ofp-meter.c:nxm_decode_n_bits
Unexecuted instantiation: ofp-monitor.c:nxm_decode_n_bits
Unexecuted instantiation: ofp-packet.c:nxm_decode_n_bits
Unexecuted instantiation: tun-metadata.c:nxm_decode_n_bits
Unexecuted instantiation: bundle.c:nxm_decode_n_bits
Unexecuted instantiation: learn.c:nxm_decode_n_bits
Unexecuted instantiation: multipath.c:nxm_decode_n_bits
176

177
/* This is my guess at the length of a "typical" nx_match, for use in
178
 * predicting space requirements. */
179
0
#define NXM_TYPICAL_LEN 64
180
181
#endif /* nx-match.h */