]> git.proxmox.com Git - mirror_ovs.git/blob - ofproto/ofproto-dpif-xlate.h
ofproto-dpif: Fix for recirc issue with mpls traffic with dp_hash
[mirror_ovs.git] / ofproto / ofproto-dpif-xlate.h
1 /* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Nicira, Inc.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License. */
14
15 #ifndef OFPROTO_DPIF_XLATE_H
16 #define OFPROTO_DPIF_XLATE_H 1
17
18 #include "dp-packet.h"
19 #include "flow.h"
20 #include "openvswitch/meta-flow.h"
21 #include "odp-util.h"
22 #include "openvswitch/ofpbuf.h"
23 #include "ofproto-dpif-mirror.h"
24 #include "ofproto-dpif-rid.h"
25 #include "ofproto-dpif.h"
26 #include "ofproto.h"
27 #include "stp.h"
28 #include "ovs-lldp.h"
29 #include "uuid.h"
30
31 struct bfd;
32 struct bond;
33 struct dpif;
34 struct lacp;
35 struct dpif_ipfix;
36 struct dpif_sflow;
37 struct mac_learning;
38 struct mcast_snooping;
39 struct xlate_cache;
40
41 struct xlate_out {
42 /* Caching exceptions:
43 *
44 * - If 'slow' is nonzero, the translation needs to be slow-pathed for
45 * one reason or another. (The particular value is only important for
46 * explaining to an administrator why the flow is slow-pathed.) This
47 * makes OVS install a datapath flow with a send-to-userspace action.
48 * Only on revalidation will the flow be replaced, if appropriate, by
49 * one that does something else with the traffic.
50 *
51 * - If 'avoid_caching' is true, then OVS won't install a datapath flow
52 * at all. If the reason to avoid caching goes away, the next upcall
53 * will immediately install a correct datapath flow.
54 *
55 * - Otherwise a datapath flow can be installed in the usual way.
56 *
57 * If 'avoid_caching' is true then 'slow' doesn't matter.
58 */
59 enum slow_path_reason slow;
60 bool avoid_caching;
61
62 /* Recirc action IDs on which references are held. */
63 struct recirc_refs recircs;
64 };
65
66 struct xlate_in {
67 struct ofproto_dpif *ofproto;
68 ovs_version_t tables_version; /* Lookup in this version. */
69
70 /* Flow to which the OpenFlow actions apply. xlate_actions() will modify
71 * this flow when actions change header fields. */
72 struct flow flow;
73
74 /* Pointer to the original flow received during the upcall. xlate_actions()
75 * will never modify this flow. */
76 const struct flow *upcall_flow;
77
78 /* The packet corresponding to 'flow', or a null pointer if we are
79 * revalidating without a packet to refer to. */
80 const struct dp_packet *packet;
81
82 /* Should OFPP_NORMAL update the MAC learning table? Should "learn"
83 * actions update the flow table? Should FIN_TIMEOUT change the
84 * timeouts? Or should controller action send packet to the controller?
85 *
86 * We want to update these tables if we are actually processing a packet,
87 * or if we are accounting for packets that the datapath has processed, but
88 * not if we are just revalidating, or if we want to execute the
89 * side-effects later via the xlate cache. */
90 bool allow_side_effects;
91
92 /* The rule initiating translation or NULL. If both 'rule' and 'ofpacts'
93 * are NULL, xlate_actions() will do the initial rule lookup itself. */
94 struct rule_dpif *rule;
95
96 /* The actions to translate. If 'rule' is not NULL, these may be NULL. */
97 const struct ofpact *ofpacts;
98 size_t ofpacts_len;
99
100 /* Union of the set of TCP flags seen so far in this flow. (Used only by
101 * NXAST_FIN_TIMEOUT. Set to zero to avoid updating updating rules'
102 * timeouts.) */
103 uint16_t tcp_flags;
104
105 /* Set to nonnull to trace the translation. See ofproto-dpif-trace.h for
106 * more information. This points to the list of oftrace nodes to which the
107 * translation should add tracing information (with oftrace_report()). */
108 struct ovs_list *trace;
109
110 /* If nonnull, flow translation credits the specified statistics to each
111 * rule reached through a resubmit or OFPP_TABLE action.
112 *
113 * This is normally null so the client has to set it manually after
114 * calling xlate_in_init(). */
115 const struct dpif_flow_stats *resubmit_stats;
116
117 /* Counters carried over from a pre-existing translation of a related flow.
118 * This can occur due to, e.g., the translation of an ARP packet that was
119 * generated as the result of outputting to a tunnel port. In that case,
120 * the original flow going to the tunnel is the related flow. Since the
121 * two flows are different, they should not use the same xlate_ctx
122 * structure. However, we still need limit the maximum recursion across
123 * the entire translation.
124 *
125 * These fields are normally set to zero, so the client has to set them
126 * manually after calling xlate_in_init(). In that case, they should be
127 * copied from the same-named fields in the related flow's xlate_ctx.
128 *
129 * These fields are really implementation details; the client doesn't care
130 * about what they mean. See the corresponding fields in xlate_ctx for
131 * real documentation. */
132 int depth;
133 int resubmits;
134
135 /* If nonnull, flow translation populates this cache with references to all
136 * modules that are affected by translation. This 'xlate_cache' may be
137 * passed to xlate_push_stats() to perform the same function as
138 * xlate_actions() without the full cost of translation.
139 *
140 * This is normally null so the client has to set it manually after
141 * calling xlate_in_init(). */
142 struct xlate_cache *xcache;
143
144 /* If nonnull, flow translation puts the resulting datapath actions in this
145 * buffer. If null, flow translation will not produce datapath actions. */
146 struct ofpbuf *odp_actions;
147
148 /* If nonnull, flow translation populates this with wildcards relevant in
149 * translation. Any fields that were used to calculate the action are set,
150 * to allow caching and kernel wildcarding to work. For example, if the
151 * flow lookup involved performing the "normal" action on IPv4 and ARP
152 * packets, 'wc' would have the 'in_port' (always set), 'dl_type' (flow
153 * match), 'vlan_tci' (normal action), and 'dl_dst' (normal action) fields
154 * set. */
155 struct flow_wildcards *wc;
156
157 /* The frozen state to be resumed, as returned by xlate_lookup(). */
158 const struct frozen_state *frozen_state;
159
160 /* If true, the packet to be translated is from a packet_out msg. */
161 bool in_packet_out;
162
163 /* ofproto/trace maintains this queue to trace flows that require
164 * recirculation. */
165 struct ovs_list *recirc_queue;
166
167 /* UUID of first non-patch port packet was received on.*/
168 struct uuid xport_uuid;
169 };
170
171 void xlate_ofproto_set(struct ofproto_dpif *, const char *name, struct dpif *,
172 const struct mac_learning *, struct stp *,
173 struct rstp *, const struct mcast_snooping *,
174 const struct mbridge *, const struct dpif_sflow *,
175 const struct dpif_ipfix *, const struct netflow *,
176 bool forward_bpdu, bool has_in_band,
177 const struct dpif_backer_support *support);
178 void xlate_remove_ofproto(struct ofproto_dpif *);
179
180 void xlate_bundle_set(struct ofproto_dpif *, struct ofbundle *,
181 const char *name, enum port_vlan_mode,
182 uint16_t qinq_ethtype, int vlan,
183 unsigned long *trunks, unsigned long *cvlans,
184 enum port_priority_tags_mode,
185 const struct bond *, const struct lacp *,
186 bool floodable, bool protected);
187 void xlate_bundle_remove(struct ofbundle *);
188
189 void xlate_ofport_set(struct ofproto_dpif *, struct ofbundle *,
190 struct ofport_dpif *, ofp_port_t, odp_port_t,
191 const struct netdev *, const struct cfm *, const struct bfd *,
192 const struct lldp *, struct ofport_dpif *peer,
193 int stp_port_no, const struct rstp_port *rstp_port,
194 const struct ofproto_port_queue *qdscp,
195 size_t n_qdscp, enum ofputil_port_config,
196 enum ofputil_port_state, bool is_tunnel,
197 bool may_enable);
198 void xlate_ofport_remove(struct ofport_dpif *);
199
200 struct ofproto_dpif * xlate_lookup_ofproto(const struct dpif_backer *,
201 const struct flow *,
202 ofp_port_t *ofp_in_port,
203 char **errorp);
204 int xlate_lookup(const struct dpif_backer *, const struct flow *,
205 struct ofproto_dpif **, struct dpif_ipfix **,
206 struct dpif_sflow **, struct netflow **,
207 ofp_port_t *ofp_in_port);
208
209 enum xlate_error {
210 XLATE_OK = 0,
211 XLATE_BRIDGE_NOT_FOUND,
212 XLATE_RECURSION_TOO_DEEP,
213 XLATE_TOO_MANY_RESUBMITS,
214 XLATE_STACK_TOO_DEEP,
215 XLATE_NO_RECIRCULATION_CONTEXT,
216 XLATE_RECIRCULATION_CONFLICT,
217 XLATE_TOO_MANY_MPLS_LABELS,
218 XLATE_INVALID_TUNNEL_METADATA,
219 XLATE_UNSUPPORTED_PACKET_TYPE,
220 };
221
222 const char *xlate_strerror(enum xlate_error error);
223
224 enum xlate_error xlate_actions(struct xlate_in *, struct xlate_out *);
225
226 void xlate_in_init(struct xlate_in *, struct ofproto_dpif *, ovs_version_t,
227 const struct flow *, ofp_port_t in_port, struct rule_dpif *,
228 uint16_t tcp_flags, const struct dp_packet *packet,
229 struct flow_wildcards *, struct ofpbuf *odp_actions);
230 void xlate_out_uninit(struct xlate_out *);
231
232 enum ofperr xlate_resume(struct ofproto_dpif *,
233 const struct ofputil_packet_in_private *,
234 struct ofpbuf *odp_actions, enum slow_path_reason *,
235 struct flow *, struct xlate_cache *);
236 int xlate_send_packet(const struct ofport_dpif *, bool oam, struct dp_packet *);
237
238 void xlate_mac_learning_update(const struct ofproto_dpif *ofproto,
239 ofp_port_t in_port, struct eth_addr dl_src,
240 int vlan, bool is_grat_arp);
241
242 void xlate_set_support(const struct ofproto_dpif *,
243 const struct dpif_backer_support *);
244
245 void xlate_txn_start(void);
246 void xlate_txn_commit(void);
247
248 #endif /* ofproto-dpif-xlate.h */