1 /* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Nicira, Inc.
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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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. */
15 #ifndef OFPROTO_DPIF_XLATE_H
16 #define OFPROTO_DPIF_XLATE_H 1
18 #include "dp-packet.h"
20 #include "openvswitch/meta-flow.h"
22 #include "openvswitch/ofpbuf.h"
23 #include "ofproto-dpif-mirror.h"
24 #include "ofproto-dpif-rid.h"
25 #include "ofproto-dpif.h"
38 struct mcast_snooping
;
42 /* Caching exceptions:
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.
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.
55 * - Otherwise a datapath flow can be installed in the usual way.
57 * If 'avoid_caching' is true then 'slow' doesn't matter.
59 enum slow_path_reason slow
;
62 /* Recirc action IDs on which references are held. */
63 struct recirc_refs recircs
;
67 struct ofproto_dpif
*ofproto
;
68 ovs_version_t tables_version
; /* Lookup in this version. */
70 /* Flow to which the OpenFlow actions apply. xlate_actions() will modify
71 * this flow when actions change header fields. */
74 /* Pointer to the original flow received during the upcall. xlate_actions()
75 * will never modify this flow. */
76 const struct flow
*upcall_flow
;
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
;
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?
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
;
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
;
96 /* The actions to translate. If 'rule' is not NULL, these may be NULL. */
97 const struct ofpact
*ofpacts
;
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'
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
;
110 /* If nonnull, flow translation credits the specified statistics to each
111 * rule reached through a resubmit or OFPP_TABLE action.
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
;
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.
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.
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. */
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.
140 * This is normally null so the client has to set it manually after
141 * calling xlate_in_init(). */
142 struct xlate_cache
*xcache
;
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
;
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
155 struct flow_wildcards
*wc
;
157 /* The frozen state to be resumed, as returned by xlate_lookup(). */
158 const struct frozen_state
*frozen_state
;
160 /* If true, the packet to be translated is from a packet_out msg. */
163 /* ofproto/trace maintains this queue to trace flows that require
165 struct ovs_list
*recirc_queue
;
167 /* UUID of first non-patch port packet was received on.*/
168 struct uuid xport_uuid
;
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
*);
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
*);
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
,
198 void xlate_ofport_remove(struct ofport_dpif
*);
200 struct ofproto_dpif
* xlate_lookup_ofproto(const struct dpif_backer
*,
202 ofp_port_t
*ofp_in_port
,
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
);
209 const char *xlate_strerror(enum xlate_error error
);
211 enum xlate_error
xlate_actions(struct xlate_in
*, struct xlate_out
*);
213 void xlate_in_init(struct xlate_in
*, struct ofproto_dpif
*, ovs_version_t
,
214 const struct flow
*, ofp_port_t in_port
, struct rule_dpif
*,
215 uint16_t tcp_flags
, const struct dp_packet
*packet
,
216 struct flow_wildcards
*, struct ofpbuf
*odp_actions
);
217 void xlate_out_uninit(struct xlate_out
*);
219 enum ofperr
xlate_resume(struct ofproto_dpif
*,
220 const struct ofputil_packet_in_private
*,
221 struct ofpbuf
*odp_actions
, enum slow_path_reason
*,
222 struct flow
*, struct xlate_cache
*);
223 int xlate_send_packet(const struct ofport_dpif
*, bool oam
, struct dp_packet
*);
225 void xlate_mac_learning_update(const struct ofproto_dpif
*ofproto
,
226 ofp_port_t in_port
, struct eth_addr dl_src
,
227 int vlan
, bool is_grat_arp
);
229 void xlate_set_support(const struct ofproto_dpif
*,
230 const struct dpif_backer_support
*);
232 void xlate_txn_start(void);
233 void xlate_txn_commit(void);
235 #endif /* ofproto-dpif-xlate.h */