]>
Commit | Line | Data |
---|---|---|
2d9b49dd | 1 | /* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Nicira, Inc. |
9583bc14 EJ |
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 | ||
e1ec7dd4 EJ |
15 | #ifndef OFPROTO_DPIF_XLATE_H |
16 | #define OFPROTO_DPIF_XLATE_H 1 | |
9583bc14 | 17 | |
cf62fa4c | 18 | #include "dp-packet.h" |
9583bc14 | 19 | #include "flow.h" |
064d7f84 | 20 | #include "openvswitch/meta-flow.h" |
9583bc14 | 21 | #include "odp-util.h" |
64c96779 | 22 | #include "openvswitch/ofpbuf.h" |
ec7ceaed | 23 | #include "ofproto-dpif-mirror.h" |
e672ff9b | 24 | #include "ofproto-dpif-rid.h" |
9583bc14 | 25 | #include "ofproto-dpif.h" |
70742c7f EJ |
26 | #include "ofproto.h" |
27 | #include "stp.h" | |
0477baa9 | 28 | #include "ovs-lldp.h" |
43e73536 | 29 | #include "uuid.h" |
9583bc14 | 30 | |
46c88433 EJ |
31 | struct bfd; |
32 | struct bond; | |
89a8a7f0 | 33 | struct dpif; |
46c88433 EJ |
34 | struct lacp; |
35 | struct dpif_ipfix; | |
36 | struct dpif_sflow; | |
37 | struct mac_learning; | |
6d95c4e8 | 38 | struct mcast_snooping; |
b256dc52 | 39 | struct xlate_cache; |
46c88433 | 40 | |
9583bc14 | 41 | struct xlate_out { |
4c71600d DDP |
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; | |
9583bc14 | 61 | |
4c71600d DDP |
62 | /* Recirc action IDs on which references are held. */ |
63 | struct recirc_refs recircs; | |
9583bc14 EJ |
64 | }; |
65 | ||
66 | struct xlate_in { | |
67 | struct ofproto_dpif *ofproto; | |
1f4a8933 | 68 | ovs_version_t tables_version; /* Lookup in this version. */ |
9583bc14 EJ |
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 | ||
8d8ab6c2 JG |
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 | ||
9583bc14 EJ |
78 | /* The packet corresponding to 'flow', or a null pointer if we are |
79 | * revalidating without a packet to refer to. */ | |
cf62fa4c | 80 | const struct dp_packet *packet; |
9583bc14 EJ |
81 | |
82 | /* Should OFPP_NORMAL update the MAC learning table? Should "learn" | |
df70a773 JR |
83 | * actions update the flow table? Should FIN_TIMEOUT change the |
84 | * timeouts? Or should controller action send packet to the controller? | |
9583bc14 EJ |
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 | |
df70a773 JR |
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; | |
9583bc14 | 91 | |
10c44245 EJ |
92 | /* The rule initiating translation or NULL. If both 'rule' and 'ofpacts' |
93 | * are NULL, xlate_actions() will do the initial rule lookup itself. */ | |
9583bc14 EJ |
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.) */ | |
a66733a8 | 103 | uint16_t tcp_flags; |
9583bc14 | 104 | |
2d9b49dd BP |
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; | |
9583bc14 EJ |
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; | |
b256dc52 | 116 | |
790c5d26 BP |
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. | |
cdd42eda JG |
124 | * |
125 | * These fields are normally set to zero, so the client has to set them | |
790c5d26 BP |
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. */ | |
790c5d26 | 132 | int depth; |
cdd42eda JG |
133 | int resubmits; |
134 | ||
b256dc52 JS |
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; | |
cc377352 | 143 | |
1520ef4f BP |
144 | /* If nonnull, flow translation puts the resulting datapath actions in this |
145 | * buffer. If null, flow translation will not produce datapath actions. */ | |
cc377352 | 146 | struct ofpbuf *odp_actions; |
e672ff9b | 147 | |
49a73e0c BP |
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 | ||
1d361a81 BP |
157 | /* The frozen state to be resumed, as returned by xlate_lookup(). */ |
158 | const struct frozen_state *frozen_state; | |
331c07ac YHW |
159 | |
160 | /* If true, the packet to be translated is from a packet_out msg. */ | |
161 | bool in_packet_out; | |
e6bc8e74 YHW |
162 | |
163 | /* ofproto/trace maintains this queue to trace flows that require | |
164 | * recirculation. */ | |
165 | struct ovs_list *recirc_queue; | |
43e73536 ZB |
166 | |
167 | /* UUID of first non-patch port packet was received on.*/ | |
168 | struct uuid xport_uuid; | |
9583bc14 EJ |
169 | }; |
170 | ||
34dd0d78 | 171 | void xlate_ofproto_set(struct ofproto_dpif *, const char *name, struct dpif *, |
ec89fc6f | 172 | const struct mac_learning *, struct stp *, |
9efd308e | 173 | struct rstp *, const struct mcast_snooping *, |
ec89fc6f | 174 | const struct mbridge *, const struct dpif_sflow *, |
ce3955be | 175 | const struct dpif_ipfix *, const struct netflow *, |
b440dd8c JS |
176 | bool forward_bpdu, bool has_in_band, |
177 | const struct dpif_backer_support *support); | |
84f0f298 | 178 | void xlate_remove_ofproto(struct ofproto_dpif *); |
46c88433 EJ |
179 | |
180 | void xlate_bundle_set(struct ofproto_dpif *, struct ofbundle *, | |
f0fb825a | 181 | const char *name, enum port_vlan_mode, |
fed8962a EG |
182 | uint16_t qinq_ethtype, int vlan, |
183 | unsigned long *trunks, unsigned long *cvlans, | |
f0fb825a | 184 | bool use_priority_tags, |
46c88433 | 185 | const struct bond *, const struct lacp *, |
c005f976 | 186 | bool floodable, bool protected); |
84f0f298 | 187 | void xlate_bundle_remove(struct ofbundle *); |
46c88433 EJ |
188 | |
189 | void xlate_ofport_set(struct ofproto_dpif *, struct ofbundle *, | |
190 | struct ofport_dpif *, ofp_port_t, odp_port_t, | |
0477baa9 DF |
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, | |
9efd308e | 194 | const struct ofproto_port_queue *qdscp, |
dd8cd4b4 SH |
195 | size_t n_qdscp, enum ofputil_port_config, |
196 | enum ofputil_port_state, bool is_tunnel, | |
84f0f298 RW |
197 | bool may_enable); |
198 | void xlate_ofport_remove(struct ofport_dpif *); | |
46c88433 | 199 | |
ef377a58 JR |
200 | struct ofproto_dpif * xlate_lookup_ofproto(const struct dpif_backer *, |
201 | const struct flow *, | |
202 | ofp_port_t *ofp_in_port); | |
5c476ea3 JR |
203 | int xlate_lookup(const struct dpif_backer *, const struct flow *, |
204 | struct ofproto_dpif **, struct dpif_ipfix **, | |
205 | struct dpif_sflow **, struct netflow **, | |
206 | ofp_port_t *ofp_in_port); | |
8449c4d6 | 207 | |
fff1b9c0 JR |
208 | enum xlate_error { |
209 | XLATE_OK = 0, | |
210 | XLATE_BRIDGE_NOT_FOUND, | |
211 | XLATE_RECURSION_TOO_DEEP, | |
212 | XLATE_TOO_MANY_RESUBMITS, | |
213 | XLATE_STACK_TOO_DEEP, | |
214 | XLATE_NO_RECIRCULATION_CONTEXT, | |
215 | XLATE_RECIRCULATION_CONFLICT, | |
216 | XLATE_TOO_MANY_MPLS_LABELS, | |
8d8ab6c2 | 217 | XLATE_INVALID_TUNNEL_METADATA, |
7873e106 | 218 | XLATE_UNSUPPORTED_PACKET_TYPE, |
fff1b9c0 JR |
219 | }; |
220 | ||
221 | const char *xlate_strerror(enum xlate_error error); | |
222 | ||
223 | enum xlate_error xlate_actions(struct xlate_in *, struct xlate_out *); | |
224 | ||
1f4a8933 | 225 | void xlate_in_init(struct xlate_in *, struct ofproto_dpif *, ovs_version_t, |
cc377352 | 226 | const struct flow *, ofp_port_t in_port, struct rule_dpif *, |
49a73e0c | 227 | uint16_t tcp_flags, const struct dp_packet *packet, |
1520ef4f | 228 | struct flow_wildcards *, struct ofpbuf *odp_actions); |
9583bc14 | 229 | void xlate_out_uninit(struct xlate_out *); |
10e57640 | 230 | |
77ab5fd2 BP |
231 | enum ofperr xlate_resume(struct ofproto_dpif *, |
232 | const struct ofputil_packet_in_private *, | |
233 | struct ofpbuf *odp_actions, enum slow_path_reason *); | |
234 | ||
2eb79142 | 235 | int xlate_send_packet(const struct ofport_dpif *, bool oam, struct dp_packet *); |
91d6cd12 | 236 | |
901a517e JR |
237 | void xlate_mac_learning_update(const struct ofproto_dpif *ofproto, |
238 | ofp_port_t in_port, struct eth_addr dl_src, | |
239 | int vlan, bool is_grat_arp); | |
b256dc52 | 240 | |
88186383 AZ |
241 | void xlate_set_support(const struct ofproto_dpif *, |
242 | const struct dpif_backer_support *); | |
bef503e8 | 243 | |
84f0f298 RW |
244 | void xlate_txn_start(void); |
245 | void xlate_txn_commit(void); | |
246 | ||
9583bc14 | 247 | #endif /* ofproto-dpif-xlate.h */ |