1 /* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 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. */
17 #include "ofproto/ofproto-dpif-xlate.h"
20 #include <arpa/inet.h>
22 #include <sys/socket.h>
23 #include <netinet/in.h>
29 #include "byte-order.h"
33 #include "dp-packet.h"
38 #include "mac-learning.h"
39 #include "mcast-snooping.h"
40 #include "multipath.h"
41 #include "netdev-vport.h"
44 #include "odp-execute.h"
45 #include "ofproto/ofproto-dpif-ipfix.h"
46 #include "ofproto/ofproto-dpif-mirror.h"
47 #include "ofproto/ofproto-dpif-monitor.h"
48 #include "ofproto/ofproto-dpif-sflow.h"
49 #include "ofproto/ofproto-dpif.h"
50 #include "ofproto/ofproto-provider.h"
51 #include "openvswitch/dynamic-string.h"
52 #include "openvswitch/meta-flow.h"
53 #include "openvswitch/list.h"
54 #include "openvswitch/ofp-actions.h"
55 #include "openvswitch/vlog.h"
57 #include "ovs-router.h"
59 #include "tnl-neigh-cache.h"
60 #include "tnl-ports.h"
63 COVERAGE_DEFINE(xlate_actions);
64 COVERAGE_DEFINE(xlate_actions_oversize);
65 COVERAGE_DEFINE(xlate_actions_too_many_output);
67 VLOG_DEFINE_THIS_MODULE(ofproto_dpif_xlate);
69 /* Maximum depth of flow table recursion (due to resubmit actions) in a
72 * The goal of limiting the depth of resubmits is to ensure that flow
73 * translation eventually terminates. Only resubmits to the same table or an
74 * earlier table count against the maximum depth. This is because resubmits to
75 * strictly monotonically increasing table IDs will eventually terminate, since
76 * any OpenFlow switch has a finite number of tables. OpenFlow tables are most
77 * commonly traversed in numerically increasing order, so this limit has little
78 * effect on conventionally designed OpenFlow pipelines.
80 * Outputs to patch ports and to groups also count against the depth limit. */
83 /* Maximum number of resubmit actions in a flow translation, whether they are
84 * recursive or not. */
85 #define MAX_RESUBMITS (MAX_DEPTH * MAX_DEPTH)
88 struct hmap_node hmap_node; /* Node in global 'xbridges' map. */
89 struct ofproto_dpif *ofproto; /* Key in global 'xbridges' map. */
91 struct ovs_list xbundles; /* Owned xbundles. */
92 struct hmap xports; /* Indexed by ofp_port. */
94 char *name; /* Name used in log messages. */
95 struct dpif *dpif; /* Datapath interface. */
96 struct mac_learning *ml; /* Mac learning handle. */
97 struct mcast_snooping *ms; /* Multicast Snooping handle. */
98 struct mbridge *mbridge; /* Mirroring. */
99 struct dpif_sflow *sflow; /* SFlow handle, or null. */
100 struct dpif_ipfix *ipfix; /* Ipfix handle, or null. */
101 struct netflow *netflow; /* Netflow handle, or null. */
102 struct stp *stp; /* STP or null if disabled. */
103 struct rstp *rstp; /* RSTP or null if disabled. */
105 bool has_in_band; /* Bridge has in band control? */
106 bool forward_bpdu; /* Bridge forwards STP BPDUs? */
108 /* Datapath feature support. */
109 struct dpif_backer_support support;
113 struct hmap_node hmap_node; /* In global 'xbundles' map. */
114 struct ofbundle *ofbundle; /* Key in global 'xbundles' map. */
116 struct ovs_list list_node; /* In parent 'xbridges' list. */
117 struct xbridge *xbridge; /* Parent xbridge. */
119 struct ovs_list xports; /* Contains "struct xport"s. */
121 char *name; /* Name used in log messages. */
122 struct bond *bond; /* Nonnull iff more than one port. */
123 struct lacp *lacp; /* LACP handle or null. */
125 enum port_vlan_mode vlan_mode; /* VLAN mode. */
126 int vlan; /* -1=trunk port, else a 12-bit VLAN ID. */
127 unsigned long *trunks; /* Bitmap of trunked VLANs, if 'vlan' == -1.
128 * NULL if all VLANs are trunked. */
129 bool use_priority_tags; /* Use 802.1p tag for frames in VLAN 0? */
130 bool floodable; /* No port has OFPUTIL_PC_NO_FLOOD set? */
134 struct hmap_node hmap_node; /* Node in global 'xports' map. */
135 struct ofport_dpif *ofport; /* Key in global 'xports map. */
137 struct hmap_node ofp_node; /* Node in parent xbridge 'xports' map. */
138 ofp_port_t ofp_port; /* Key in parent xbridge 'xports' map. */
140 odp_port_t odp_port; /* Datapath port number or ODPP_NONE. */
142 struct ovs_list bundle_node; /* In parent xbundle (if it exists). */
143 struct xbundle *xbundle; /* Parent xbundle or null. */
145 struct netdev *netdev; /* 'ofport''s netdev. */
147 struct xbridge *xbridge; /* Parent bridge. */
148 struct xport *peer; /* Patch port peer or null. */
150 enum ofputil_port_config config; /* OpenFlow port configuration. */
151 enum ofputil_port_state state; /* OpenFlow port state. */
152 int stp_port_no; /* STP port number or -1 if not in use. */
153 struct rstp_port *rstp_port; /* RSTP port or null. */
155 struct hmap skb_priorities; /* Map of 'skb_priority_to_dscp's. */
157 bool may_enable; /* May be enabled in bonds. */
158 bool is_tunnel; /* Is a tunnel port. */
160 struct cfm *cfm; /* CFM handle or null. */
161 struct bfd *bfd; /* BFD handle or null. */
162 struct lldp *lldp; /* LLDP handle or null. */
166 struct xlate_in *xin;
167 struct xlate_out *xout;
169 const struct xbridge *xbridge;
171 /* Flow tables version at the beginning of the translation. */
172 cls_version_t tables_version;
174 /* Flow at the last commit. */
175 struct flow base_flow;
177 /* Tunnel IP destination address as received. This is stored separately
178 * as the base_flow.tunnel is cleared on init to reflect the datapath
179 * behavior. Used to make sure not to send tunneled output to ourselves,
180 * which might lead to an infinite loop. This could happen easily
181 * if a tunnel is marked as 'ip_remote=flow', and the flow does not
182 * actually set the tun_dst field. */
183 struct in6_addr orig_tunnel_ipv6_dst;
185 /* Stack for the push and pop actions. Each stack element is of type
186 * "union mf_subvalue". */
189 /* The rule that we are currently translating, or NULL. */
190 struct rule_dpif *rule;
192 /* Flow translation populates this with wildcards relevant in translation.
193 * When 'xin->wc' is nonnull, this is the same pointer. When 'xin->wc' is
194 * null, this is a pointer to uninitialized scratch memory. This allows
195 * code to blindly write to 'ctx->wc' without worrying about whether the
196 * caller really wants wildcards. */
197 struct flow_wildcards *wc;
199 /* Output buffer for datapath actions. When 'xin->odp_actions' is nonnull,
200 * this is the same pointer. When 'xin->odp_actions' is null, this points
201 * to a scratch ofpbuf. This allows code to add actions to
202 * 'ctx->odp_actions' without worrying about whether the caller really
204 struct ofpbuf *odp_actions;
206 /* Statistics maintained by xlate_table_action().
208 * 'indentation' is the nesting level for resubmits. It is used to indent
209 * the output of resubmit_hook (e.g. for the "ofproto/trace" feature).
211 * The other statistics limit the amount of work that a single flow
212 * translation can perform. The goal of the first of these, 'depth', is
213 * primarily to prevent translation from performing an infinite amount of
214 * work. It counts the current depth of nested "resubmit"s (and a few
215 * other activities); when a resubmit returns, it decreases. Resubmits to
216 * tables in strictly monotonically increasing order don't contribute to
217 * 'depth' because they cannot cause a flow translation to take an infinite
218 * amount of time (because the number of tables is finite). Translation
219 * aborts when 'depth' exceeds MAX_DEPTH.
221 * 'resubmits', on the other hand, prevents flow translation from
222 * performing an extraordinarily large while still finite amount of work.
223 * It counts the total number of resubmits (and a few other activities)
224 * that have been executed. Returning from a resubmit does not affect this
225 * counter. Thus, this limits the amount of work that a particular
226 * translation can perform. Translation aborts when 'resubmits' exceeds
227 * MAX_RESUBMITS (which is much larger than MAX_DEPTH).
229 int indentation; /* Indentation level for resubmit_hook. */
230 int depth; /* Current resubmit nesting depth. */
231 int resubmits; /* Total number of resubmits. */
232 bool in_group; /* Currently translating ofgroup, if true. */
233 bool in_action_set; /* Currently translating action_set, if true. */
235 uint8_t table_id; /* OpenFlow table ID where flow was found. */
236 ovs_be64 rule_cookie; /* Cookie of the rule being translated. */
237 uint32_t orig_skb_priority; /* Priority when packet arrived. */
238 uint32_t sflow_n_outputs; /* Number of output ports. */
239 odp_port_t sflow_odp_port; /* Output port for composing sFlow action. */
240 ofp_port_t nf_output_iface; /* Output interface index for NetFlow. */
241 bool exit; /* No further actions should be processed. */
242 mirror_mask_t mirrors; /* Bitmap of associated mirrors. */
244 /* Freezing Translation
245 * ====================
247 * At some point during translation, the code may recognize the need to halt
248 * and checkpoint the translation in a way that it can be restarted again
249 * later. We call the checkpointing process "freezing" and the restarting
252 * The use cases for freezing are:
254 * - "Recirculation", where the translation process discovers that it
255 * doesn't have enough information to complete translation without
256 * actually executing the actions that have already been translated,
257 * which provides the additionally needed information. In these
258 * situations, translation freezes translation and assigns the frozen
259 * data a unique "recirculation ID", which it associates with the data
260 * in a table in userspace (see ofproto-dpif-rid.h). It also adds a
261 * OVS_ACTION_ATTR_RECIRC action specifying that ID to the datapath
262 * actions. When a packet hits that action, the datapath looks its
263 * flow up again using the ID. If there's a miss, it comes back to
264 * userspace, which find the recirculation table entry for the ID,
265 * thaws the associated frozen data, and continues translation from
266 * that point given the additional information that is now known.
268 * The archetypal example is MPLS. As MPLS is implemented in
269 * OpenFlow, the protocol that follows the last MPLS label becomes
270 * known only when that label is popped by an OpenFlow action. That
271 * means that Open vSwitch can't extract the headers beyond the MPLS
272 * labels until the pop action is executed. Thus, at that point
273 * translation uses the recirculation process to extract the headers
274 * beyond the MPLS labels.
276 * (OVS also uses OVS_ACTION_ATTR_RECIRC to implement hashing for
277 * output to bonds. OVS pre-populates all the datapath flows for bond
278 * output in the datapath, though, which means that the elaborate
279 * process of coming back to userspace for a second round of
280 * translation isn't needed, and so bonds don't follow the above
283 * - "Continuation". A continuation is a way for an OpenFlow controller
284 * to interpose on a packet's traversal of the OpenFlow tables. When
285 * the translation process encounters a "controller" action with the
286 * "pause" flag, it freezes translation, serializes the frozen data,
287 * and sends it to an OpenFlow controller. The controller then
288 * examines and possibly modifies the frozen data and eventually sends
289 * it back to the switch, which thaws it and continues translation.
291 * The main problem of freezing translation is preserving state, so that
292 * when the translation is thawed later it resumes from where it left off,
293 * without disruption. In particular, actions must be preserved as follows:
295 * - If we're freezing because an action needed more information, the
296 * action that prompted it.
298 * - Any actions remaining to be translated within the current flow.
300 * - If translation was frozen within a NXAST_RESUBMIT, then any actions
301 * following the resubmit action. Resubmit actions can be nested, so
302 * this has to go all the way up the control stack.
304 * - The OpenFlow 1.1+ action set.
306 * State that actions and flow table lookups can depend on, such as the
307 * following, must also be preserved:
309 * - Metadata fields (input port, registers, OF1.1+ metadata, ...).
311 * - The stack used by NXAST_STACK_PUSH and NXAST_STACK_POP actions.
313 * - The table ID and cookie of the flow being translated at each level
314 * of the control stack, because these can become visible through
315 * OFPAT_CONTROLLER actions (and other ways).
317 * Translation allows for the control of this state preservation via these
318 * members. When a need to freeze translation is identified, the
319 * translation process:
321 * 1. Sets 'freezing' to true.
323 * 2. Sets 'exit' to true to tell later steps that we're exiting from the
324 * translation process.
326 * 3. Adds an OFPACT_UNROLL_XLATE action to 'frozen_actions', and points
327 * frozen_actions.header to the action to make it easy to find it later.
328 * This action holds the current table ID and cookie so that they can be
329 * restored during a post-recirculation upcall translation.
331 * 4. Adds the action that prompted recirculation and any actions following
332 * it within the same flow to 'frozen_actions', so that they can be
333 * executed during a post-recirculation upcall translation.
337 * 6. The action that prompted recirculation might be nested in a stack of
338 * nested "resubmit"s that have actions remaining. Each of these notices
339 * that we're exiting and freezing and responds by adding more
340 * OFPACT_UNROLL_XLATE actions to 'frozen_actions', as necessary,
341 * followed by any actions that were yet unprocessed.
343 * If we're freezing because of recirculation, the caller generates a
344 * recirculation ID and associates all the state produced by this process
345 * with it. For post-recirculation upcall translation, the caller passes it
346 * back in for the new translation to execute. The process yielded a set of
347 * ofpacts that can be translated directly, so it is not much of a special
348 * case at that point.
351 struct ofpbuf frozen_actions;
352 const struct ofpact_controller *pause;
354 /* True if conntrack has been performed on this packet during processing
355 * on the current bridge. This is used to determine whether conntrack
356 * state from the datapath should be honored after thawing. */
359 /* Pointer to an embedded NAT action in a conntrack action, or NULL. */
360 struct ofpact_nat *ct_nat_action;
362 /* OpenFlow 1.1+ action set.
364 * 'action_set' accumulates "struct ofpact"s added by OFPACT_WRITE_ACTIONS.
365 * When translation is otherwise complete, ofpacts_execute_action_set()
366 * converts it to a set of "struct ofpact"s that can be translated into
367 * datapath actions. */
368 bool action_set_has_group; /* Action set contains OFPACT_GROUP? */
369 struct ofpbuf action_set; /* Action set. */
371 enum xlate_error error; /* Translation failed. */
374 const char *xlate_strerror(enum xlate_error error)
379 case XLATE_BRIDGE_NOT_FOUND:
380 return "Bridge not found";
381 case XLATE_RECURSION_TOO_DEEP:
382 return "Recursion too deep";
383 case XLATE_TOO_MANY_RESUBMITS:
384 return "Too many resubmits";
385 case XLATE_STACK_TOO_DEEP:
386 return "Stack too deep";
387 case XLATE_NO_RECIRCULATION_CONTEXT:
388 return "No recirculation context";
389 case XLATE_RECIRCULATION_CONFLICT:
390 return "Recirculation conflict";
391 case XLATE_TOO_MANY_MPLS_LABELS:
392 return "Too many MPLS labels";
394 return "Unknown error";
397 static void xlate_action_set(struct xlate_ctx *ctx);
398 static void xlate_commit_actions(struct xlate_ctx *ctx);
401 ctx_trigger_freeze(struct xlate_ctx *ctx)
404 ctx->freezing = true;
408 ctx_first_frozen_action(const struct xlate_ctx *ctx)
410 return !ctx->frozen_actions.size;
414 ctx_cancel_freeze(struct xlate_ctx *ctx)
417 ctx->freezing = false;
418 ofpbuf_clear(&ctx->frozen_actions);
419 ctx->frozen_actions.header = NULL;
423 static void finish_freezing(struct xlate_ctx *ctx);
425 /* A controller may use OFPP_NONE as the ingress port to indicate that
426 * it did not arrive on a "real" port. 'ofpp_none_bundle' exists for
427 * when an input bundle is needed for validation (e.g., mirroring or
428 * OFPP_NORMAL processing). It is not connected to an 'ofproto' or have
429 * any 'port' structs, so care must be taken when dealing with it. */
430 static struct xbundle ofpp_none_bundle = {
432 .vlan_mode = PORT_VLAN_TRUNK
435 /* Node in 'xport''s 'skb_priorities' map. Used to maintain a map from
436 * 'priority' (the datapath's term for QoS queue) to the dscp bits which all
437 * traffic egressing the 'ofport' with that priority should be marked with. */
438 struct skb_priority_to_dscp {
439 struct hmap_node hmap_node; /* Node in 'ofport_dpif''s 'skb_priorities'. */
440 uint32_t skb_priority; /* Priority of this queue (see struct flow). */
442 uint8_t dscp; /* DSCP bits to mark outgoing traffic with. */
458 /* xlate_cache entries hold enough information to perform the side effects of
459 * xlate_actions() for a rule, without needing to perform rule translation
460 * from scratch. The primary usage of these is to submit statistics to objects
461 * that a flow relates to, although they may be used for other effects as well
462 * (for instance, refreshing hard timeouts for learned flows). */
466 struct rule_dpif *rule;
473 struct netflow *netflow;
478 struct mbridge *mbridge;
479 mirror_mask_t mirrors;
487 struct ofproto_dpif *ofproto;
488 struct ofputil_flow_mod *fm;
489 struct ofpbuf *ofpacts;
492 struct ofproto_dpif *ofproto;
497 struct rule_dpif *rule;
502 struct group_dpif *group;
503 struct ofputil_bucket *bucket;
506 char br_name[IFNAMSIZ];
507 struct in6_addr d_ipv6;
512 #define XC_ENTRY_FOR_EACH(ENTRY, ENTRIES, XCACHE) \
513 ENTRIES = XCACHE->entries; \
514 for (ENTRY = ofpbuf_try_pull(&ENTRIES, sizeof *ENTRY); \
516 ENTRY = ofpbuf_try_pull(&ENTRIES, sizeof *ENTRY))
519 struct ofpbuf entries;
522 /* Xlate config contains hash maps of all bridges, bundles and ports.
523 * Xcfgp contains the pointer to the current xlate configuration.
524 * When the main thread needs to change the configuration, it copies xcfgp to
525 * new_xcfg and edits new_xcfg. This enables the use of RCU locking which
526 * does not block handler and revalidator threads. */
528 struct hmap xbridges;
529 struct hmap xbundles;
532 static OVSRCU_TYPE(struct xlate_cfg *) xcfgp = OVSRCU_INITIALIZER(NULL);
533 static struct xlate_cfg *new_xcfg = NULL;
535 static bool may_receive(const struct xport *, struct xlate_ctx *);
536 static void do_xlate_actions(const struct ofpact *, size_t ofpacts_len,
538 static void xlate_normal(struct xlate_ctx *);
539 static inline void xlate_report(struct xlate_ctx *, const char *, ...)
540 OVS_PRINTF_FORMAT(2, 3);
541 static void xlate_table_action(struct xlate_ctx *, ofp_port_t in_port,
542 uint8_t table_id, bool may_packet_in,
543 bool honor_table_miss);
544 static bool input_vid_is_valid(uint16_t vid, struct xbundle *, bool warn);
545 static uint16_t input_vid_to_vlan(const struct xbundle *, uint16_t vid);
546 static void output_normal(struct xlate_ctx *, const struct xbundle *,
549 /* Optional bond recirculation parameter to compose_output_action(). */
550 struct xlate_bond_recirc {
551 uint32_t recirc_id; /* !0 Use recirculation instead of output. */
552 uint8_t hash_alg; /* !0 Compute hash for recirc before. */
553 uint32_t hash_basis; /* Compute hash for recirc before. */
556 static void compose_output_action(struct xlate_ctx *, ofp_port_t ofp_port,
557 const struct xlate_bond_recirc *xr);
559 static struct xbridge *xbridge_lookup(struct xlate_cfg *,
560 const struct ofproto_dpif *);
561 static struct xbridge *xbridge_lookup_by_uuid(struct xlate_cfg *,
562 const struct uuid *);
563 static struct xbundle *xbundle_lookup(struct xlate_cfg *,
564 const struct ofbundle *);
565 static struct xport *xport_lookup(struct xlate_cfg *,
566 const struct ofport_dpif *);
567 static struct xport *get_ofp_port(const struct xbridge *, ofp_port_t ofp_port);
568 static struct skb_priority_to_dscp *get_skb_priority(const struct xport *,
569 uint32_t skb_priority);
570 static void clear_skb_priorities(struct xport *);
571 static size_t count_skb_priorities(const struct xport *);
572 static bool dscp_from_skb_priority(const struct xport *, uint32_t skb_priority,
575 static struct xc_entry *xlate_cache_add_entry(struct xlate_cache *xc,
577 static void xlate_xbridge_init(struct xlate_cfg *, struct xbridge *);
578 static void xlate_xbundle_init(struct xlate_cfg *, struct xbundle *);
579 static void xlate_xport_init(struct xlate_cfg *, struct xport *);
580 static void xlate_xbridge_set(struct xbridge *, struct dpif *,
581 const struct mac_learning *, struct stp *,
582 struct rstp *, const struct mcast_snooping *,
583 const struct mbridge *,
584 const struct dpif_sflow *,
585 const struct dpif_ipfix *,
586 const struct netflow *,
587 bool forward_bpdu, bool has_in_band,
588 const struct dpif_backer_support *);
589 static void xlate_xbundle_set(struct xbundle *xbundle,
590 enum port_vlan_mode vlan_mode, int vlan,
591 unsigned long *trunks, bool use_priority_tags,
592 const struct bond *bond, const struct lacp *lacp,
594 static void xlate_xport_set(struct xport *xport, odp_port_t odp_port,
595 const struct netdev *netdev, const struct cfm *cfm,
596 const struct bfd *bfd, const struct lldp *lldp,
597 int stp_port_no, const struct rstp_port *rstp_port,
598 enum ofputil_port_config config,
599 enum ofputil_port_state state, bool is_tunnel,
601 static void xlate_xbridge_remove(struct xlate_cfg *, struct xbridge *);
602 static void xlate_xbundle_remove(struct xlate_cfg *, struct xbundle *);
603 static void xlate_xport_remove(struct xlate_cfg *, struct xport *);
604 static void xlate_xbridge_copy(struct xbridge *);
605 static void xlate_xbundle_copy(struct xbridge *, struct xbundle *);
606 static void xlate_xport_copy(struct xbridge *, struct xbundle *,
608 static void xlate_xcfg_free(struct xlate_cfg *);
611 xlate_report(struct xlate_ctx *ctx, const char *format, ...)
613 if (OVS_UNLIKELY(ctx->xin->report_hook)) {
616 va_start(args, format);
617 ctx->xin->report_hook(ctx->xin, ctx->indentation, format, args);
622 static struct vlog_rate_limit error_report_rl = VLOG_RATE_LIMIT_INIT(1, 5);
624 #define XLATE_REPORT_ERROR(CTX, ...) \
626 if (OVS_UNLIKELY((CTX)->xin->report_hook)) { \
627 xlate_report(CTX, __VA_ARGS__); \
629 VLOG_ERR_RL(&error_report_rl, __VA_ARGS__); \
634 xlate_report_actions(struct xlate_ctx *ctx, const char *title,
635 const struct ofpact *ofpacts, size_t ofpacts_len)
637 if (OVS_UNLIKELY(ctx->xin->report_hook)) {
638 struct ds s = DS_EMPTY_INITIALIZER;
639 ofpacts_format(ofpacts, ofpacts_len, &s);
640 xlate_report(ctx, "%s: %s", title, ds_cstr(&s));
646 xlate_xbridge_init(struct xlate_cfg *xcfg, struct xbridge *xbridge)
648 ovs_list_init(&xbridge->xbundles);
649 hmap_init(&xbridge->xports);
650 hmap_insert(&xcfg->xbridges, &xbridge->hmap_node,
651 hash_pointer(xbridge->ofproto, 0));
655 xlate_xbundle_init(struct xlate_cfg *xcfg, struct xbundle *xbundle)
657 ovs_list_init(&xbundle->xports);
658 ovs_list_insert(&xbundle->xbridge->xbundles, &xbundle->list_node);
659 hmap_insert(&xcfg->xbundles, &xbundle->hmap_node,
660 hash_pointer(xbundle->ofbundle, 0));
664 xlate_xport_init(struct xlate_cfg *xcfg, struct xport *xport)
666 hmap_init(&xport->skb_priorities);
667 hmap_insert(&xcfg->xports, &xport->hmap_node,
668 hash_pointer(xport->ofport, 0));
669 hmap_insert(&xport->xbridge->xports, &xport->ofp_node,
670 hash_ofp_port(xport->ofp_port));
674 xlate_xbridge_set(struct xbridge *xbridge,
676 const struct mac_learning *ml, struct stp *stp,
677 struct rstp *rstp, const struct mcast_snooping *ms,
678 const struct mbridge *mbridge,
679 const struct dpif_sflow *sflow,
680 const struct dpif_ipfix *ipfix,
681 const struct netflow *netflow,
682 bool forward_bpdu, bool has_in_band,
683 const struct dpif_backer_support *support)
685 if (xbridge->ml != ml) {
686 mac_learning_unref(xbridge->ml);
687 xbridge->ml = mac_learning_ref(ml);
690 if (xbridge->ms != ms) {
691 mcast_snooping_unref(xbridge->ms);
692 xbridge->ms = mcast_snooping_ref(ms);
695 if (xbridge->mbridge != mbridge) {
696 mbridge_unref(xbridge->mbridge);
697 xbridge->mbridge = mbridge_ref(mbridge);
700 if (xbridge->sflow != sflow) {
701 dpif_sflow_unref(xbridge->sflow);
702 xbridge->sflow = dpif_sflow_ref(sflow);
705 if (xbridge->ipfix != ipfix) {
706 dpif_ipfix_unref(xbridge->ipfix);
707 xbridge->ipfix = dpif_ipfix_ref(ipfix);
710 if (xbridge->stp != stp) {
711 stp_unref(xbridge->stp);
712 xbridge->stp = stp_ref(stp);
715 if (xbridge->rstp != rstp) {
716 rstp_unref(xbridge->rstp);
717 xbridge->rstp = rstp_ref(rstp);
720 if (xbridge->netflow != netflow) {
721 netflow_unref(xbridge->netflow);
722 xbridge->netflow = netflow_ref(netflow);
725 xbridge->dpif = dpif;
726 xbridge->forward_bpdu = forward_bpdu;
727 xbridge->has_in_band = has_in_band;
728 xbridge->support = *support;
732 xlate_xbundle_set(struct xbundle *xbundle,
733 enum port_vlan_mode vlan_mode, int vlan,
734 unsigned long *trunks, bool use_priority_tags,
735 const struct bond *bond, const struct lacp *lacp,
738 ovs_assert(xbundle->xbridge);
740 xbundle->vlan_mode = vlan_mode;
741 xbundle->vlan = vlan;
742 xbundle->trunks = trunks;
743 xbundle->use_priority_tags = use_priority_tags;
744 xbundle->floodable = floodable;
746 if (xbundle->bond != bond) {
747 bond_unref(xbundle->bond);
748 xbundle->bond = bond_ref(bond);
751 if (xbundle->lacp != lacp) {
752 lacp_unref(xbundle->lacp);
753 xbundle->lacp = lacp_ref(lacp);
758 xlate_xport_set(struct xport *xport, odp_port_t odp_port,
759 const struct netdev *netdev, const struct cfm *cfm,
760 const struct bfd *bfd, const struct lldp *lldp, int stp_port_no,
761 const struct rstp_port* rstp_port,
762 enum ofputil_port_config config, enum ofputil_port_state state,
763 bool is_tunnel, bool may_enable)
765 xport->config = config;
766 xport->state = state;
767 xport->stp_port_no = stp_port_no;
768 xport->is_tunnel = is_tunnel;
769 xport->may_enable = may_enable;
770 xport->odp_port = odp_port;
772 if (xport->rstp_port != rstp_port) {
773 rstp_port_unref(xport->rstp_port);
774 xport->rstp_port = rstp_port_ref(rstp_port);
777 if (xport->cfm != cfm) {
778 cfm_unref(xport->cfm);
779 xport->cfm = cfm_ref(cfm);
782 if (xport->bfd != bfd) {
783 bfd_unref(xport->bfd);
784 xport->bfd = bfd_ref(bfd);
787 if (xport->lldp != lldp) {
788 lldp_unref(xport->lldp);
789 xport->lldp = lldp_ref(lldp);
792 if (xport->netdev != netdev) {
793 netdev_close(xport->netdev);
794 xport->netdev = netdev_ref(netdev);
799 xlate_xbridge_copy(struct xbridge *xbridge)
801 struct xbundle *xbundle;
803 struct xbridge *new_xbridge = xzalloc(sizeof *xbridge);
804 new_xbridge->ofproto = xbridge->ofproto;
805 new_xbridge->name = xstrdup(xbridge->name);
806 xlate_xbridge_init(new_xcfg, new_xbridge);
808 xlate_xbridge_set(new_xbridge,
809 xbridge->dpif, xbridge->ml, xbridge->stp,
810 xbridge->rstp, xbridge->ms, xbridge->mbridge,
811 xbridge->sflow, xbridge->ipfix, xbridge->netflow,
812 xbridge->forward_bpdu, xbridge->has_in_band,
814 LIST_FOR_EACH (xbundle, list_node, &xbridge->xbundles) {
815 xlate_xbundle_copy(new_xbridge, xbundle);
818 /* Copy xports which are not part of a xbundle */
819 HMAP_FOR_EACH (xport, ofp_node, &xbridge->xports) {
820 if (!xport->xbundle) {
821 xlate_xport_copy(new_xbridge, NULL, xport);
827 xlate_xbundle_copy(struct xbridge *xbridge, struct xbundle *xbundle)
830 struct xbundle *new_xbundle = xzalloc(sizeof *xbundle);
831 new_xbundle->ofbundle = xbundle->ofbundle;
832 new_xbundle->xbridge = xbridge;
833 new_xbundle->name = xstrdup(xbundle->name);
834 xlate_xbundle_init(new_xcfg, new_xbundle);
836 xlate_xbundle_set(new_xbundle, xbundle->vlan_mode,
837 xbundle->vlan, xbundle->trunks,
838 xbundle->use_priority_tags, xbundle->bond, xbundle->lacp,
840 LIST_FOR_EACH (xport, bundle_node, &xbundle->xports) {
841 xlate_xport_copy(xbridge, new_xbundle, xport);
846 xlate_xport_copy(struct xbridge *xbridge, struct xbundle *xbundle,
849 struct skb_priority_to_dscp *pdscp, *new_pdscp;
850 struct xport *new_xport = xzalloc(sizeof *xport);
851 new_xport->ofport = xport->ofport;
852 new_xport->ofp_port = xport->ofp_port;
853 new_xport->xbridge = xbridge;
854 xlate_xport_init(new_xcfg, new_xport);
856 xlate_xport_set(new_xport, xport->odp_port, xport->netdev, xport->cfm,
857 xport->bfd, xport->lldp, xport->stp_port_no,
858 xport->rstp_port, xport->config, xport->state,
859 xport->is_tunnel, xport->may_enable);
862 struct xport *peer = xport_lookup(new_xcfg, xport->peer->ofport);
864 new_xport->peer = peer;
865 new_xport->peer->peer = new_xport;
870 new_xport->xbundle = xbundle;
871 ovs_list_insert(&new_xport->xbundle->xports, &new_xport->bundle_node);
874 HMAP_FOR_EACH (pdscp, hmap_node, &xport->skb_priorities) {
875 new_pdscp = xmalloc(sizeof *pdscp);
876 new_pdscp->skb_priority = pdscp->skb_priority;
877 new_pdscp->dscp = pdscp->dscp;
878 hmap_insert(&new_xport->skb_priorities, &new_pdscp->hmap_node,
879 hash_int(new_pdscp->skb_priority, 0));
883 /* Sets the current xlate configuration to new_xcfg and frees the old xlate
884 * configuration in xcfgp.
886 * This needs to be called after editing the xlate configuration.
888 * Functions that edit the new xlate configuration are
889 * xlate_<ofport/bundle/ofport>_set and xlate_<ofport/bundle/ofport>_remove.
895 * edit_xlate_configuration();
897 * xlate_txn_commit(); */
899 xlate_txn_commit(void)
901 struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
903 ovsrcu_set(&xcfgp, new_xcfg);
904 ovsrcu_synchronize();
905 xlate_xcfg_free(xcfg);
909 /* Copies the current xlate configuration in xcfgp to new_xcfg.
911 * This needs to be called prior to editing the xlate configuration. */
913 xlate_txn_start(void)
915 struct xbridge *xbridge;
916 struct xlate_cfg *xcfg;
918 ovs_assert(!new_xcfg);
920 new_xcfg = xmalloc(sizeof *new_xcfg);
921 hmap_init(&new_xcfg->xbridges);
922 hmap_init(&new_xcfg->xbundles);
923 hmap_init(&new_xcfg->xports);
925 xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
930 HMAP_FOR_EACH (xbridge, hmap_node, &xcfg->xbridges) {
931 xlate_xbridge_copy(xbridge);
937 xlate_xcfg_free(struct xlate_cfg *xcfg)
939 struct xbridge *xbridge, *next_xbridge;
945 HMAP_FOR_EACH_SAFE (xbridge, next_xbridge, hmap_node, &xcfg->xbridges) {
946 xlate_xbridge_remove(xcfg, xbridge);
949 hmap_destroy(&xcfg->xbridges);
950 hmap_destroy(&xcfg->xbundles);
951 hmap_destroy(&xcfg->xports);
956 xlate_ofproto_set(struct ofproto_dpif *ofproto, const char *name,
958 const struct mac_learning *ml, struct stp *stp,
959 struct rstp *rstp, const struct mcast_snooping *ms,
960 const struct mbridge *mbridge,
961 const struct dpif_sflow *sflow,
962 const struct dpif_ipfix *ipfix,
963 const struct netflow *netflow,
964 bool forward_bpdu, bool has_in_band,
965 const struct dpif_backer_support *support)
967 struct xbridge *xbridge;
969 ovs_assert(new_xcfg);
971 xbridge = xbridge_lookup(new_xcfg, ofproto);
973 xbridge = xzalloc(sizeof *xbridge);
974 xbridge->ofproto = ofproto;
976 xlate_xbridge_init(new_xcfg, xbridge);
980 xbridge->name = xstrdup(name);
982 xlate_xbridge_set(xbridge, dpif, ml, stp, rstp, ms, mbridge, sflow, ipfix,
983 netflow, forward_bpdu, has_in_band, support);
987 xlate_xbridge_remove(struct xlate_cfg *xcfg, struct xbridge *xbridge)
989 struct xbundle *xbundle, *next_xbundle;
990 struct xport *xport, *next_xport;
996 HMAP_FOR_EACH_SAFE (xport, next_xport, ofp_node, &xbridge->xports) {
997 xlate_xport_remove(xcfg, xport);
1000 LIST_FOR_EACH_SAFE (xbundle, next_xbundle, list_node, &xbridge->xbundles) {
1001 xlate_xbundle_remove(xcfg, xbundle);
1004 hmap_remove(&xcfg->xbridges, &xbridge->hmap_node);
1005 mac_learning_unref(xbridge->ml);
1006 mcast_snooping_unref(xbridge->ms);
1007 mbridge_unref(xbridge->mbridge);
1008 dpif_sflow_unref(xbridge->sflow);
1009 dpif_ipfix_unref(xbridge->ipfix);
1010 stp_unref(xbridge->stp);
1011 rstp_unref(xbridge->rstp);
1012 hmap_destroy(&xbridge->xports);
1013 free(xbridge->name);
1018 xlate_remove_ofproto(struct ofproto_dpif *ofproto)
1020 struct xbridge *xbridge;
1022 ovs_assert(new_xcfg);
1024 xbridge = xbridge_lookup(new_xcfg, ofproto);
1025 xlate_xbridge_remove(new_xcfg, xbridge);
1029 xlate_bundle_set(struct ofproto_dpif *ofproto, struct ofbundle *ofbundle,
1030 const char *name, enum port_vlan_mode vlan_mode, int vlan,
1031 unsigned long *trunks, bool use_priority_tags,
1032 const struct bond *bond, const struct lacp *lacp,
1035 struct xbundle *xbundle;
1037 ovs_assert(new_xcfg);
1039 xbundle = xbundle_lookup(new_xcfg, ofbundle);
1041 xbundle = xzalloc(sizeof *xbundle);
1042 xbundle->ofbundle = ofbundle;
1043 xbundle->xbridge = xbridge_lookup(new_xcfg, ofproto);
1045 xlate_xbundle_init(new_xcfg, xbundle);
1048 free(xbundle->name);
1049 xbundle->name = xstrdup(name);
1051 xlate_xbundle_set(xbundle, vlan_mode, vlan, trunks,
1052 use_priority_tags, bond, lacp, floodable);
1056 xlate_xbundle_remove(struct xlate_cfg *xcfg, struct xbundle *xbundle)
1058 struct xport *xport;
1064 LIST_FOR_EACH_POP (xport, bundle_node, &xbundle->xports) {
1065 xport->xbundle = NULL;
1068 hmap_remove(&xcfg->xbundles, &xbundle->hmap_node);
1069 ovs_list_remove(&xbundle->list_node);
1070 bond_unref(xbundle->bond);
1071 lacp_unref(xbundle->lacp);
1072 free(xbundle->name);
1077 xlate_bundle_remove(struct ofbundle *ofbundle)
1079 struct xbundle *xbundle;
1081 ovs_assert(new_xcfg);
1083 xbundle = xbundle_lookup(new_xcfg, ofbundle);
1084 xlate_xbundle_remove(new_xcfg, xbundle);
1088 xlate_ofport_set(struct ofproto_dpif *ofproto, struct ofbundle *ofbundle,
1089 struct ofport_dpif *ofport, ofp_port_t ofp_port,
1090 odp_port_t odp_port, const struct netdev *netdev,
1091 const struct cfm *cfm, const struct bfd *bfd,
1092 const struct lldp *lldp, struct ofport_dpif *peer,
1093 int stp_port_no, const struct rstp_port *rstp_port,
1094 const struct ofproto_port_queue *qdscp_list, size_t n_qdscp,
1095 enum ofputil_port_config config,
1096 enum ofputil_port_state state, bool is_tunnel,
1100 struct xport *xport;
1102 ovs_assert(new_xcfg);
1104 xport = xport_lookup(new_xcfg, ofport);
1106 xport = xzalloc(sizeof *xport);
1107 xport->ofport = ofport;
1108 xport->xbridge = xbridge_lookup(new_xcfg, ofproto);
1109 xport->ofp_port = ofp_port;
1111 xlate_xport_init(new_xcfg, xport);
1114 ovs_assert(xport->ofp_port == ofp_port);
1116 xlate_xport_set(xport, odp_port, netdev, cfm, bfd, lldp,
1117 stp_port_no, rstp_port, config, state, is_tunnel,
1121 xport->peer->peer = NULL;
1123 xport->peer = xport_lookup(new_xcfg, peer);
1125 xport->peer->peer = xport;
1128 if (xport->xbundle) {
1129 ovs_list_remove(&xport->bundle_node);
1131 xport->xbundle = xbundle_lookup(new_xcfg, ofbundle);
1132 if (xport->xbundle) {
1133 ovs_list_insert(&xport->xbundle->xports, &xport->bundle_node);
1136 clear_skb_priorities(xport);
1137 for (i = 0; i < n_qdscp; i++) {
1138 struct skb_priority_to_dscp *pdscp;
1139 uint32_t skb_priority;
1141 if (dpif_queue_to_priority(xport->xbridge->dpif, qdscp_list[i].queue,
1146 pdscp = xmalloc(sizeof *pdscp);
1147 pdscp->skb_priority = skb_priority;
1148 pdscp->dscp = (qdscp_list[i].dscp << 2) & IP_DSCP_MASK;
1149 hmap_insert(&xport->skb_priorities, &pdscp->hmap_node,
1150 hash_int(pdscp->skb_priority, 0));
1155 xlate_xport_remove(struct xlate_cfg *xcfg, struct xport *xport)
1162 xport->peer->peer = NULL;
1166 if (xport->xbundle) {
1167 ovs_list_remove(&xport->bundle_node);
1170 clear_skb_priorities(xport);
1171 hmap_destroy(&xport->skb_priorities);
1173 hmap_remove(&xcfg->xports, &xport->hmap_node);
1174 hmap_remove(&xport->xbridge->xports, &xport->ofp_node);
1176 netdev_close(xport->netdev);
1177 rstp_port_unref(xport->rstp_port);
1178 cfm_unref(xport->cfm);
1179 bfd_unref(xport->bfd);
1180 lldp_unref(xport->lldp);
1185 xlate_ofport_remove(struct ofport_dpif *ofport)
1187 struct xport *xport;
1189 ovs_assert(new_xcfg);
1191 xport = xport_lookup(new_xcfg, ofport);
1192 xlate_xport_remove(new_xcfg, xport);
1195 static struct ofproto_dpif *
1196 xlate_lookup_ofproto_(const struct dpif_backer *backer, const struct flow *flow,
1197 ofp_port_t *ofp_in_port, const struct xport **xportp)
1199 struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
1200 const struct xport *xport;
1202 xport = xport_lookup(xcfg, tnl_port_should_receive(flow)
1203 ? tnl_port_receive(flow)
1204 : odp_port_to_ofport(backer, flow->in_port.odp_port));
1205 if (OVS_UNLIKELY(!xport)) {
1210 *ofp_in_port = xport->ofp_port;
1212 return xport->xbridge->ofproto;
1215 /* Given a datapath and flow metadata ('backer', and 'flow' respectively)
1216 * returns the corresponding struct ofproto_dpif and OpenFlow port number. */
1217 struct ofproto_dpif *
1218 xlate_lookup_ofproto(const struct dpif_backer *backer, const struct flow *flow,
1219 ofp_port_t *ofp_in_port)
1221 const struct xport *xport;
1223 return xlate_lookup_ofproto_(backer, flow, ofp_in_port, &xport);
1226 /* Given a datapath and flow metadata ('backer', and 'flow' respectively),
1227 * optionally populates 'ofproto' with the ofproto_dpif, 'ofp_in_port' with the
1228 * openflow in_port, and 'ipfix', 'sflow', and 'netflow' with the appropriate
1229 * handles for those protocols if they're enabled. Caller may use the returned
1230 * pointers until quiescing, for longer term use additional references must
1233 * Returns 0 if successful, ENODEV if the parsed flow has no associated ofproto.
1236 xlate_lookup(const struct dpif_backer *backer, const struct flow *flow,
1237 struct ofproto_dpif **ofprotop, struct dpif_ipfix **ipfix,
1238 struct dpif_sflow **sflow, struct netflow **netflow,
1239 ofp_port_t *ofp_in_port)
1241 struct ofproto_dpif *ofproto;
1242 const struct xport *xport;
1244 ofproto = xlate_lookup_ofproto_(backer, flow, ofp_in_port, &xport);
1251 *ofprotop = ofproto;
1255 *ipfix = xport ? xport->xbridge->ipfix : NULL;
1259 *sflow = xport ? xport->xbridge->sflow : NULL;
1263 *netflow = xport ? xport->xbridge->netflow : NULL;
1269 static struct xbridge *
1270 xbridge_lookup(struct xlate_cfg *xcfg, const struct ofproto_dpif *ofproto)
1272 struct hmap *xbridges;
1273 struct xbridge *xbridge;
1275 if (!ofproto || !xcfg) {
1279 xbridges = &xcfg->xbridges;
1281 HMAP_FOR_EACH_IN_BUCKET (xbridge, hmap_node, hash_pointer(ofproto, 0),
1283 if (xbridge->ofproto == ofproto) {
1290 static struct xbridge *
1291 xbridge_lookup_by_uuid(struct xlate_cfg *xcfg, const struct uuid *uuid)
1293 struct xbridge *xbridge;
1295 HMAP_FOR_EACH (xbridge, hmap_node, &xcfg->xbridges) {
1296 if (uuid_equals(ofproto_dpif_get_uuid(xbridge->ofproto), uuid)) {
1303 static struct xbundle *
1304 xbundle_lookup(struct xlate_cfg *xcfg, const struct ofbundle *ofbundle)
1306 struct hmap *xbundles;
1307 struct xbundle *xbundle;
1309 if (!ofbundle || !xcfg) {
1313 xbundles = &xcfg->xbundles;
1315 HMAP_FOR_EACH_IN_BUCKET (xbundle, hmap_node, hash_pointer(ofbundle, 0),
1317 if (xbundle->ofbundle == ofbundle) {
1324 static struct xport *
1325 xport_lookup(struct xlate_cfg *xcfg, const struct ofport_dpif *ofport)
1327 struct hmap *xports;
1328 struct xport *xport;
1330 if (!ofport || !xcfg) {
1334 xports = &xcfg->xports;
1336 HMAP_FOR_EACH_IN_BUCKET (xport, hmap_node, hash_pointer(ofport, 0),
1338 if (xport->ofport == ofport) {
1345 static struct stp_port *
1346 xport_get_stp_port(const struct xport *xport)
1348 return xport->xbridge->stp && xport->stp_port_no != -1
1349 ? stp_get_port(xport->xbridge->stp, xport->stp_port_no)
1354 xport_stp_learn_state(const struct xport *xport)
1356 struct stp_port *sp = xport_get_stp_port(xport);
1358 ? stp_learn_in_state(stp_port_get_state(sp))
1363 xport_stp_forward_state(const struct xport *xport)
1365 struct stp_port *sp = xport_get_stp_port(xport);
1367 ? stp_forward_in_state(stp_port_get_state(sp))
1372 xport_stp_should_forward_bpdu(const struct xport *xport)
1374 struct stp_port *sp = xport_get_stp_port(xport);
1375 return stp_should_forward_bpdu(sp ? stp_port_get_state(sp) : STP_DISABLED);
1378 /* Returns true if STP should process 'flow'. Sets fields in 'wc' that
1379 * were used to make the determination.*/
1381 stp_should_process_flow(const struct flow *flow, struct flow_wildcards *wc)
1383 /* is_stp() also checks dl_type, but dl_type is always set in 'wc'. */
1384 memset(&wc->masks.dl_dst, 0xff, sizeof wc->masks.dl_dst);
1385 return is_stp(flow);
1389 stp_process_packet(const struct xport *xport, const struct dp_packet *packet)
1391 struct stp_port *sp = xport_get_stp_port(xport);
1392 struct dp_packet payload = *packet;
1393 struct eth_header *eth = dp_packet_data(&payload);
1395 /* Sink packets on ports that have STP disabled when the bridge has
1397 if (!sp || stp_port_get_state(sp) == STP_DISABLED) {
1401 /* Trim off padding on payload. */
1402 if (dp_packet_size(&payload) > ntohs(eth->eth_type) + ETH_HEADER_LEN) {
1403 dp_packet_set_size(&payload, ntohs(eth->eth_type) + ETH_HEADER_LEN);
1406 if (dp_packet_try_pull(&payload, ETH_HEADER_LEN + LLC_HEADER_LEN)) {
1407 stp_received_bpdu(sp, dp_packet_data(&payload), dp_packet_size(&payload));
1411 static enum rstp_state
1412 xport_get_rstp_port_state(const struct xport *xport)
1414 return xport->rstp_port
1415 ? rstp_port_get_state(xport->rstp_port)
1420 xport_rstp_learn_state(const struct xport *xport)
1422 return xport->xbridge->rstp && xport->rstp_port
1423 ? rstp_learn_in_state(xport_get_rstp_port_state(xport))
1428 xport_rstp_forward_state(const struct xport *xport)
1430 return xport->xbridge->rstp && xport->rstp_port
1431 ? rstp_forward_in_state(xport_get_rstp_port_state(xport))
1436 xport_rstp_should_manage_bpdu(const struct xport *xport)
1438 return rstp_should_manage_bpdu(xport_get_rstp_port_state(xport));
1442 rstp_process_packet(const struct xport *xport, const struct dp_packet *packet)
1444 struct dp_packet payload = *packet;
1445 struct eth_header *eth = dp_packet_data(&payload);
1447 /* Sink packets on ports that have no RSTP. */
1448 if (!xport->rstp_port) {
1452 /* Trim off padding on payload. */
1453 if (dp_packet_size(&payload) > ntohs(eth->eth_type) + ETH_HEADER_LEN) {
1454 dp_packet_set_size(&payload, ntohs(eth->eth_type) + ETH_HEADER_LEN);
1457 if (dp_packet_try_pull(&payload, ETH_HEADER_LEN + LLC_HEADER_LEN)) {
1458 rstp_port_received_bpdu(xport->rstp_port, dp_packet_data(&payload),
1459 dp_packet_size(&payload));
1463 static struct xport *
1464 get_ofp_port(const struct xbridge *xbridge, ofp_port_t ofp_port)
1466 struct xport *xport;
1468 HMAP_FOR_EACH_IN_BUCKET (xport, ofp_node, hash_ofp_port(ofp_port),
1470 if (xport->ofp_port == ofp_port) {
1478 ofp_port_to_odp_port(const struct xbridge *xbridge, ofp_port_t ofp_port)
1480 const struct xport *xport = get_ofp_port(xbridge, ofp_port);
1481 return xport ? xport->odp_port : ODPP_NONE;
1485 odp_port_is_alive(const struct xlate_ctx *ctx, ofp_port_t ofp_port)
1487 struct xport *xport = get_ofp_port(ctx->xbridge, ofp_port);
1488 return xport && xport->may_enable;
1491 static struct ofputil_bucket *
1492 group_first_live_bucket(const struct xlate_ctx *, const struct group_dpif *,
1496 group_is_alive(const struct xlate_ctx *ctx, uint32_t group_id, int depth)
1498 struct group_dpif *group;
1500 if (group_dpif_lookup(ctx->xbridge->ofproto, group_id, &group)) {
1501 struct ofputil_bucket *bucket;
1503 bucket = group_first_live_bucket(ctx, group, depth);
1504 group_dpif_unref(group);
1505 return bucket != NULL;
1511 #define MAX_LIVENESS_RECURSION 128 /* Arbitrary limit */
1514 bucket_is_alive(const struct xlate_ctx *ctx,
1515 struct ofputil_bucket *bucket, int depth)
1517 if (depth >= MAX_LIVENESS_RECURSION) {
1518 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
1520 VLOG_WARN_RL(&rl, "bucket chaining exceeded %d links",
1521 MAX_LIVENESS_RECURSION);
1525 return (!ofputil_bucket_has_liveness(bucket)
1526 || (bucket->watch_port != OFPP_ANY
1527 && odp_port_is_alive(ctx, bucket->watch_port))
1528 || (bucket->watch_group != OFPG_ANY
1529 && group_is_alive(ctx, bucket->watch_group, depth + 1)));
1532 static struct ofputil_bucket *
1533 group_first_live_bucket(const struct xlate_ctx *ctx,
1534 const struct group_dpif *group, int depth)
1536 struct ofputil_bucket *bucket;
1537 const struct ovs_list *buckets;
1539 group_dpif_get_buckets(group, &buckets);
1540 LIST_FOR_EACH (bucket, list_node, buckets) {
1541 if (bucket_is_alive(ctx, bucket, depth)) {
1549 static struct ofputil_bucket *
1550 group_best_live_bucket(const struct xlate_ctx *ctx,
1551 const struct group_dpif *group,
1554 struct ofputil_bucket *best_bucket = NULL;
1555 uint32_t best_score = 0;
1558 struct ofputil_bucket *bucket;
1559 const struct ovs_list *buckets;
1561 group_dpif_get_buckets(group, &buckets);
1562 LIST_FOR_EACH (bucket, list_node, buckets) {
1563 if (bucket_is_alive(ctx, bucket, 0)) {
1564 uint32_t score = (hash_int(i, basis) & 0xffff) * bucket->weight;
1565 if (score >= best_score) {
1566 best_bucket = bucket;
1577 xbundle_trunks_vlan(const struct xbundle *bundle, uint16_t vlan)
1579 return (bundle->vlan_mode != PORT_VLAN_ACCESS
1580 && (!bundle->trunks || bitmap_is_set(bundle->trunks, vlan)));
1584 xbundle_includes_vlan(const struct xbundle *xbundle, uint16_t vlan)
1586 return vlan == xbundle->vlan || xbundle_trunks_vlan(xbundle, vlan);
1589 static mirror_mask_t
1590 xbundle_mirror_out(const struct xbridge *xbridge, struct xbundle *xbundle)
1592 return xbundle != &ofpp_none_bundle
1593 ? mirror_bundle_out(xbridge->mbridge, xbundle->ofbundle)
1597 static mirror_mask_t
1598 xbundle_mirror_src(const struct xbridge *xbridge, struct xbundle *xbundle)
1600 return xbundle != &ofpp_none_bundle
1601 ? mirror_bundle_src(xbridge->mbridge, xbundle->ofbundle)
1605 static mirror_mask_t
1606 xbundle_mirror_dst(const struct xbridge *xbridge, struct xbundle *xbundle)
1608 return xbundle != &ofpp_none_bundle
1609 ? mirror_bundle_dst(xbridge->mbridge, xbundle->ofbundle)
1613 static struct xbundle *
1614 lookup_input_bundle(const struct xbridge *xbridge, ofp_port_t in_port,
1615 bool warn, struct xport **in_xportp)
1617 struct xport *xport;
1619 /* Find the port and bundle for the received packet. */
1620 xport = get_ofp_port(xbridge, in_port);
1624 if (xport && xport->xbundle) {
1625 return xport->xbundle;
1628 /* Special-case OFPP_NONE (OF1.0) and OFPP_CONTROLLER (OF1.1+),
1629 * which a controller may use as the ingress port for traffic that
1630 * it is sourcing. */
1631 if (in_port == OFPP_CONTROLLER || in_port == OFPP_NONE) {
1632 return &ofpp_none_bundle;
1635 /* Odd. A few possible reasons here:
1637 * - We deleted a port but there are still a few packets queued up
1640 * - Someone externally added a port (e.g. "ovs-dpctl add-if") that
1641 * we don't know about.
1643 * - The ofproto client didn't configure the port as part of a bundle.
1644 * This is particularly likely to happen if a packet was received on the
1645 * port after it was created, but before the client had a chance to
1646 * configure its bundle.
1649 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
1651 VLOG_WARN_RL(&rl, "bridge %s: received packet on unknown "
1652 "port %"PRIu16, xbridge->name, in_port);
1657 /* Mirrors the packet represented by 'ctx' to appropriate mirror destinations,
1658 * given the packet is ingressing or egressing on 'xbundle', which has ingress
1659 * or egress (as appropriate) mirrors 'mirrors'. */
1661 mirror_packet(struct xlate_ctx *ctx, struct xbundle *xbundle,
1662 mirror_mask_t mirrors)
1664 /* Figure out what VLAN the packet is in (because mirrors can select
1665 * packets on basis of VLAN). */
1666 bool warn = ctx->xin->packet != NULL;
1667 uint16_t vid = vlan_tci_to_vid(ctx->xin->flow.vlan_tci);
1668 if (!input_vid_is_valid(vid, xbundle, warn)) {
1671 uint16_t vlan = input_vid_to_vlan(xbundle, vid);
1673 const struct xbridge *xbridge = ctx->xbridge;
1675 /* Don't mirror to destinations that we've already mirrored to. */
1676 mirrors &= ~ctx->mirrors;
1681 if (ctx->xin->resubmit_stats) {
1682 mirror_update_stats(xbridge->mbridge, mirrors,
1683 ctx->xin->resubmit_stats->n_packets,
1684 ctx->xin->resubmit_stats->n_bytes);
1686 if (ctx->xin->xcache) {
1687 struct xc_entry *entry;
1689 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_MIRROR);
1690 entry->u.mirror.mbridge = mbridge_ref(xbridge->mbridge);
1691 entry->u.mirror.mirrors = mirrors;
1694 /* 'mirrors' is a bit-mask of candidates for mirroring. Iterate as long as
1695 * some candidates remain. */
1697 const unsigned long *vlans;
1698 mirror_mask_t dup_mirrors;
1699 struct ofbundle *out;
1702 /* Get the details of the mirror represented by the rightmost 1-bit. */
1703 bool has_mirror = mirror_get(xbridge->mbridge, raw_ctz(mirrors),
1704 &vlans, &dup_mirrors, &out, &out_vlan);
1705 ovs_assert(has_mirror);
1707 /* If this mirror selects on the basis of VLAN, and it does not select
1708 * 'vlan', then discard this mirror and go on to the next one. */
1710 ctx->wc->masks.vlan_tci |= htons(VLAN_CFI | VLAN_VID_MASK);
1712 if (vlans && !bitmap_is_set(vlans, vlan)) {
1713 mirrors = zero_rightmost_1bit(mirrors);
1717 /* Record the mirror, and the mirrors that output to the same
1718 * destination, so that we don't mirror to them again. This must be
1719 * done now to ensure that output_normal(), below, doesn't recursively
1720 * output to the same mirrors. */
1721 ctx->mirrors |= dup_mirrors;
1723 /* Send the packet to the mirror. */
1725 struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
1726 struct xbundle *out_xbundle = xbundle_lookup(xcfg, out);
1728 output_normal(ctx, out_xbundle, vlan);
1730 } else if (vlan != out_vlan
1731 && !eth_addr_is_reserved(ctx->xin->flow.dl_dst)) {
1732 struct xbundle *xbundle;
1734 LIST_FOR_EACH (xbundle, list_node, &xbridge->xbundles) {
1735 if (xbundle_includes_vlan(xbundle, out_vlan)
1736 && !xbundle_mirror_out(xbridge, xbundle)) {
1737 output_normal(ctx, xbundle, out_vlan);
1742 /* output_normal() could have recursively output (to different
1743 * mirrors), so make sure that we don't send duplicates. */
1744 mirrors &= ~ctx->mirrors;
1749 mirror_ingress_packet(struct xlate_ctx *ctx)
1751 if (mbridge_has_mirrors(ctx->xbridge->mbridge)) {
1752 bool warn = ctx->xin->packet != NULL;
1753 struct xbundle *xbundle = lookup_input_bundle(
1754 ctx->xbridge, ctx->xin->flow.in_port.ofp_port, warn, NULL);
1756 mirror_packet(ctx, xbundle,
1757 xbundle_mirror_src(ctx->xbridge, xbundle));
1762 /* Given 'vid', the VID obtained from the 802.1Q header that was received as
1763 * part of a packet (specify 0 if there was no 802.1Q header), and 'in_xbundle',
1764 * the bundle on which the packet was received, returns the VLAN to which the
1767 * Both 'vid' and the return value are in the range 0...4095. */
1769 input_vid_to_vlan(const struct xbundle *in_xbundle, uint16_t vid)
1771 switch (in_xbundle->vlan_mode) {
1772 case PORT_VLAN_ACCESS:
1773 return in_xbundle->vlan;
1776 case PORT_VLAN_TRUNK:
1779 case PORT_VLAN_NATIVE_UNTAGGED:
1780 case PORT_VLAN_NATIVE_TAGGED:
1781 return vid ? vid : in_xbundle->vlan;
1788 /* Checks whether a packet with the given 'vid' may ingress on 'in_xbundle'.
1789 * If so, returns true. Otherwise, returns false and, if 'warn' is true, logs
1792 * 'vid' should be the VID obtained from the 802.1Q header that was received as
1793 * part of a packet (specify 0 if there was no 802.1Q header), in the range
1796 input_vid_is_valid(uint16_t vid, struct xbundle *in_xbundle, bool warn)
1798 /* Allow any VID on the OFPP_NONE port. */
1799 if (in_xbundle == &ofpp_none_bundle) {
1803 switch (in_xbundle->vlan_mode) {
1804 case PORT_VLAN_ACCESS:
1807 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
1808 VLOG_WARN_RL(&rl, "dropping VLAN %"PRIu16" tagged "
1809 "packet received on port %s configured as VLAN "
1810 "%"PRIu16" access port", vid, in_xbundle->name,
1817 case PORT_VLAN_NATIVE_UNTAGGED:
1818 case PORT_VLAN_NATIVE_TAGGED:
1820 /* Port must always carry its native VLAN. */
1824 case PORT_VLAN_TRUNK:
1825 if (!xbundle_includes_vlan(in_xbundle, vid)) {
1827 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
1828 VLOG_WARN_RL(&rl, "dropping VLAN %"PRIu16" packet "
1829 "received on port %s not configured for trunking "
1830 "VLAN %"PRIu16, vid, in_xbundle->name, vid);
1842 /* Given 'vlan', the VLAN that a packet belongs to, and
1843 * 'out_xbundle', a bundle on which the packet is to be output, returns the VID
1844 * that should be included in the 802.1Q header. (If the return value is 0,
1845 * then the 802.1Q header should only be included in the packet if there is a
1848 * Both 'vlan' and the return value are in the range 0...4095. */
1850 output_vlan_to_vid(const struct xbundle *out_xbundle, uint16_t vlan)
1852 switch (out_xbundle->vlan_mode) {
1853 case PORT_VLAN_ACCESS:
1856 case PORT_VLAN_TRUNK:
1857 case PORT_VLAN_NATIVE_TAGGED:
1860 case PORT_VLAN_NATIVE_UNTAGGED:
1861 return vlan == out_xbundle->vlan ? 0 : vlan;
1869 output_normal(struct xlate_ctx *ctx, const struct xbundle *out_xbundle,
1872 ovs_be16 *flow_tci = &ctx->xin->flow.vlan_tci;
1874 ovs_be16 tci, old_tci;
1875 struct xport *xport;
1876 struct xlate_bond_recirc xr;
1877 bool use_recirc = false;
1879 vid = output_vlan_to_vid(out_xbundle, vlan);
1880 if (ovs_list_is_empty(&out_xbundle->xports)) {
1881 /* Partially configured bundle with no slaves. Drop the packet. */
1883 } else if (!out_xbundle->bond) {
1884 xport = CONTAINER_OF(ovs_list_front(&out_xbundle->xports), struct xport,
1887 struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
1888 struct flow_wildcards *wc = ctx->wc;
1889 struct ofport_dpif *ofport;
1891 if (ctx->xbridge->support.odp.recirc) {
1892 use_recirc = bond_may_recirc(
1893 out_xbundle->bond, &xr.recirc_id, &xr.hash_basis);
1896 /* Only TCP mode uses recirculation. */
1897 xr.hash_alg = OVS_HASH_ALG_L4;
1898 bond_update_post_recirc_rules(out_xbundle->bond, false);
1900 /* Recirculation does not require unmasking hash fields. */
1905 ofport = bond_choose_output_slave(out_xbundle->bond,
1906 &ctx->xin->flow, wc, vid);
1907 xport = xport_lookup(xcfg, ofport);
1910 /* No slaves enabled, so drop packet. */
1914 /* If use_recirc is set, the main thread will handle stats
1915 * accounting for this bond. */
1917 if (ctx->xin->resubmit_stats) {
1918 bond_account(out_xbundle->bond, &ctx->xin->flow, vid,
1919 ctx->xin->resubmit_stats->n_bytes);
1921 if (ctx->xin->xcache) {
1922 struct xc_entry *entry;
1925 flow = &ctx->xin->flow;
1926 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_BOND);
1927 entry->u.bond.bond = bond_ref(out_xbundle->bond);
1928 entry->u.bond.flow = xmemdup(flow, sizeof *flow);
1929 entry->u.bond.vid = vid;
1934 old_tci = *flow_tci;
1936 if (tci || out_xbundle->use_priority_tags) {
1937 tci |= *flow_tci & htons(VLAN_PCP_MASK);
1939 tci |= htons(VLAN_CFI);
1944 compose_output_action(ctx, xport->ofp_port, use_recirc ? &xr : NULL);
1945 *flow_tci = old_tci;
1948 /* A VM broadcasts a gratuitous ARP to indicate that it has resumed after
1949 * migration. Older Citrix-patched Linux DomU used gratuitous ARP replies to
1950 * indicate this; newer upstream kernels use gratuitous ARP requests. */
1952 is_gratuitous_arp(const struct flow *flow, struct flow_wildcards *wc)
1954 if (flow->dl_type != htons(ETH_TYPE_ARP)) {
1958 memset(&wc->masks.dl_dst, 0xff, sizeof wc->masks.dl_dst);
1959 if (!eth_addr_is_broadcast(flow->dl_dst)) {
1963 memset(&wc->masks.nw_proto, 0xff, sizeof wc->masks.nw_proto);
1964 if (flow->nw_proto == ARP_OP_REPLY) {
1966 } else if (flow->nw_proto == ARP_OP_REQUEST) {
1967 memset(&wc->masks.nw_src, 0xff, sizeof wc->masks.nw_src);
1968 memset(&wc->masks.nw_dst, 0xff, sizeof wc->masks.nw_dst);
1970 return flow->nw_src == flow->nw_dst;
1976 /* Determines whether packets in 'flow' within 'xbridge' should be forwarded or
1977 * dropped. Returns true if they may be forwarded, false if they should be
1980 * 'in_port' must be the xport that corresponds to flow->in_port.
1981 * 'in_port' must be part of a bundle (e.g. in_port->bundle must be nonnull).
1983 * 'vlan' must be the VLAN that corresponds to flow->vlan_tci on 'in_port', as
1984 * returned by input_vid_to_vlan(). It must be a valid VLAN for 'in_port', as
1985 * checked by input_vid_is_valid().
1987 * May also add tags to '*tags', although the current implementation only does
1988 * so in one special case.
1991 is_admissible(struct xlate_ctx *ctx, struct xport *in_port,
1994 struct xbundle *in_xbundle = in_port->xbundle;
1995 const struct xbridge *xbridge = ctx->xbridge;
1996 struct flow *flow = &ctx->xin->flow;
1998 /* Drop frames for reserved multicast addresses
1999 * only if forward_bpdu option is absent. */
2000 if (!xbridge->forward_bpdu && eth_addr_is_reserved(flow->dl_dst)) {
2001 xlate_report(ctx, "packet has reserved destination MAC, dropping");
2005 if (in_xbundle->bond) {
2006 struct mac_entry *mac;
2008 switch (bond_check_admissibility(in_xbundle->bond, in_port->ofport,
2014 xlate_report(ctx, "bonding refused admissibility, dropping");
2017 case BV_DROP_IF_MOVED:
2018 ovs_rwlock_rdlock(&xbridge->ml->rwlock);
2019 mac = mac_learning_lookup(xbridge->ml, flow->dl_src, vlan);
2021 && mac_entry_get_port(xbridge->ml, mac) != in_xbundle->ofbundle
2022 && (!is_gratuitous_arp(flow, ctx->wc)
2023 || mac_entry_is_grat_arp_locked(mac))) {
2024 ovs_rwlock_unlock(&xbridge->ml->rwlock);
2025 xlate_report(ctx, "SLB bond thinks this packet looped back, "
2029 ovs_rwlock_unlock(&xbridge->ml->rwlock);
2037 /* Checks whether a MAC learning update is necessary for MAC learning table
2038 * 'ml' given that a packet matching 'flow' was received on 'in_xbundle' in
2041 * Most packets processed through the MAC learning table do not actually
2042 * change it in any way. This function requires only a read lock on the MAC
2043 * learning table, so it is much cheaper in this common case.
2045 * Keep the code here synchronized with that in update_learning_table__()
2048 is_mac_learning_update_needed(const struct mac_learning *ml,
2049 const struct flow *flow,
2050 struct flow_wildcards *wc,
2051 int vlan, struct xbundle *in_xbundle)
2052 OVS_REQ_RDLOCK(ml->rwlock)
2054 struct mac_entry *mac;
2056 if (!mac_learning_may_learn(ml, flow->dl_src, vlan)) {
2060 mac = mac_learning_lookup(ml, flow->dl_src, vlan);
2061 if (!mac || mac_entry_age(ml, mac)) {
2065 if (is_gratuitous_arp(flow, wc)) {
2066 /* We don't want to learn from gratuitous ARP packets that are
2067 * reflected back over bond slaves so we lock the learning table. */
2068 if (!in_xbundle->bond) {
2070 } else if (mac_entry_is_grat_arp_locked(mac)) {
2075 return mac_entry_get_port(ml, mac) != in_xbundle->ofbundle;
2079 /* Updates MAC learning table 'ml' given that a packet matching 'flow' was
2080 * received on 'in_xbundle' in 'vlan'.
2082 * This code repeats all the checks in is_mac_learning_update_needed() because
2083 * the lock was released between there and here and thus the MAC learning state
2084 * could have changed.
2086 * Keep the code here synchronized with that in is_mac_learning_update_needed()
2089 update_learning_table__(const struct xbridge *xbridge,
2090 const struct flow *flow, struct flow_wildcards *wc,
2091 int vlan, struct xbundle *in_xbundle)
2092 OVS_REQ_WRLOCK(xbridge->ml->rwlock)
2094 struct mac_entry *mac;
2096 if (!mac_learning_may_learn(xbridge->ml, flow->dl_src, vlan)) {
2100 mac = mac_learning_insert(xbridge->ml, flow->dl_src, vlan);
2101 if (is_gratuitous_arp(flow, wc)) {
2102 /* We don't want to learn from gratuitous ARP packets that are
2103 * reflected back over bond slaves so we lock the learning table. */
2104 if (!in_xbundle->bond) {
2105 mac_entry_set_grat_arp_lock(mac);
2106 } else if (mac_entry_is_grat_arp_locked(mac)) {
2111 if (mac_entry_get_port(xbridge->ml, mac) != in_xbundle->ofbundle) {
2112 /* The log messages here could actually be useful in debugging,
2113 * so keep the rate limit relatively high. */
2114 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(30, 300);
2116 VLOG_DBG_RL(&rl, "bridge %s: learned that "ETH_ADDR_FMT" is "
2117 "on port %s in VLAN %d",
2118 xbridge->name, ETH_ADDR_ARGS(flow->dl_src),
2119 in_xbundle->name, vlan);
2121 mac_entry_set_port(xbridge->ml, mac, in_xbundle->ofbundle);
2126 update_learning_table(const struct xbridge *xbridge,
2127 const struct flow *flow, struct flow_wildcards *wc,
2128 int vlan, struct xbundle *in_xbundle)
2132 /* Don't learn the OFPP_NONE port. */
2133 if (in_xbundle == &ofpp_none_bundle) {
2137 /* First try the common case: no change to MAC learning table. */
2138 ovs_rwlock_rdlock(&xbridge->ml->rwlock);
2139 need_update = is_mac_learning_update_needed(xbridge->ml, flow, wc, vlan,
2141 ovs_rwlock_unlock(&xbridge->ml->rwlock);
2144 /* Slow path: MAC learning table might need an update. */
2145 ovs_rwlock_wrlock(&xbridge->ml->rwlock);
2146 update_learning_table__(xbridge, flow, wc, vlan, in_xbundle);
2147 ovs_rwlock_unlock(&xbridge->ml->rwlock);
2151 /* Updates multicast snooping table 'ms' given that a packet matching 'flow'
2152 * was received on 'in_xbundle' in 'vlan' and is either Report or Query. */
2154 update_mcast_snooping_table4__(const struct xbridge *xbridge,
2155 const struct flow *flow,
2156 struct mcast_snooping *ms, int vlan,
2157 struct xbundle *in_xbundle,
2158 const struct dp_packet *packet)
2159 OVS_REQ_WRLOCK(ms->rwlock)
2161 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(60, 30);
2163 ovs_be32 ip4 = flow->igmp_group_ip4;
2165 switch (ntohs(flow->tp_src)) {
2166 case IGMP_HOST_MEMBERSHIP_REPORT:
2167 case IGMPV2_HOST_MEMBERSHIP_REPORT:
2168 if (mcast_snooping_add_group4(ms, ip4, vlan, in_xbundle->ofbundle)) {
2169 VLOG_DBG_RL(&rl, "bridge %s: multicast snooping learned that "
2170 IP_FMT" is on port %s in VLAN %d",
2171 xbridge->name, IP_ARGS(ip4), in_xbundle->name, vlan);
2174 case IGMP_HOST_LEAVE_MESSAGE:
2175 if (mcast_snooping_leave_group4(ms, ip4, vlan, in_xbundle->ofbundle)) {
2176 VLOG_DBG_RL(&rl, "bridge %s: multicast snooping leaving "
2177 IP_FMT" is on port %s in VLAN %d",
2178 xbridge->name, IP_ARGS(ip4), in_xbundle->name, vlan);
2181 case IGMP_HOST_MEMBERSHIP_QUERY:
2182 if (flow->nw_src && mcast_snooping_add_mrouter(ms, vlan,
2183 in_xbundle->ofbundle)) {
2184 VLOG_DBG_RL(&rl, "bridge %s: multicast snooping query from "
2185 IP_FMT" is on port %s in VLAN %d",
2186 xbridge->name, IP_ARGS(flow->nw_src),
2187 in_xbundle->name, vlan);
2190 case IGMPV3_HOST_MEMBERSHIP_REPORT:
2191 if ((count = mcast_snooping_add_report(ms, packet, vlan,
2192 in_xbundle->ofbundle))) {
2193 VLOG_DBG_RL(&rl, "bridge %s: multicast snooping processed %d "
2194 "addresses on port %s in VLAN %d",
2195 xbridge->name, count, in_xbundle->name, vlan);
2202 update_mcast_snooping_table6__(const struct xbridge *xbridge,
2203 const struct flow *flow,
2204 struct mcast_snooping *ms, int vlan,
2205 struct xbundle *in_xbundle,
2206 const struct dp_packet *packet)
2207 OVS_REQ_WRLOCK(ms->rwlock)
2209 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(60, 30);
2212 switch (ntohs(flow->tp_src)) {
2214 if (!ipv6_addr_equals(&flow->ipv6_src, &in6addr_any)
2215 && mcast_snooping_add_mrouter(ms, vlan, in_xbundle->ofbundle)) {
2216 VLOG_DBG_RL(&rl, "bridge %s: multicast snooping query on port %s"
2218 xbridge->name, in_xbundle->name, vlan);
2224 count = mcast_snooping_add_mld(ms, packet, vlan, in_xbundle->ofbundle);
2226 VLOG_DBG_RL(&rl, "bridge %s: multicast snooping processed %d "
2227 "addresses on port %s in VLAN %d",
2228 xbridge->name, count, in_xbundle->name, vlan);
2234 /* Updates multicast snooping table 'ms' given that a packet matching 'flow'
2235 * was received on 'in_xbundle' in 'vlan'. */
2237 update_mcast_snooping_table(const struct xbridge *xbridge,
2238 const struct flow *flow, int vlan,
2239 struct xbundle *in_xbundle,
2240 const struct dp_packet *packet)
2242 struct mcast_snooping *ms = xbridge->ms;
2243 struct xlate_cfg *xcfg;
2244 struct xbundle *mcast_xbundle;
2245 struct mcast_port_bundle *fport;
2247 /* Don't learn the OFPP_NONE port. */
2248 if (in_xbundle == &ofpp_none_bundle) {
2252 /* Don't learn from flood ports */
2253 mcast_xbundle = NULL;
2254 ovs_rwlock_wrlock(&ms->rwlock);
2255 xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
2256 LIST_FOR_EACH(fport, node, &ms->fport_list) {
2257 mcast_xbundle = xbundle_lookup(xcfg, fport->port);
2258 if (mcast_xbundle == in_xbundle) {
2263 if (!mcast_xbundle || mcast_xbundle != in_xbundle) {
2264 if (flow->dl_type == htons(ETH_TYPE_IP)) {
2265 update_mcast_snooping_table4__(xbridge, flow, ms, vlan,
2266 in_xbundle, packet);
2268 update_mcast_snooping_table6__(xbridge, flow, ms, vlan,
2269 in_xbundle, packet);
2272 ovs_rwlock_unlock(&ms->rwlock);
2275 /* send the packet to ports having the multicast group learned */
2277 xlate_normal_mcast_send_group(struct xlate_ctx *ctx,
2278 struct mcast_snooping *ms OVS_UNUSED,
2279 struct mcast_group *grp,
2280 struct xbundle *in_xbundle, uint16_t vlan)
2281 OVS_REQ_RDLOCK(ms->rwlock)
2283 struct xlate_cfg *xcfg;
2284 struct mcast_group_bundle *b;
2285 struct xbundle *mcast_xbundle;
2287 xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
2288 LIST_FOR_EACH(b, bundle_node, &grp->bundle_lru) {
2289 mcast_xbundle = xbundle_lookup(xcfg, b->port);
2290 if (mcast_xbundle && mcast_xbundle != in_xbundle) {
2291 xlate_report(ctx, "forwarding to mcast group port");
2292 output_normal(ctx, mcast_xbundle, vlan);
2293 } else if (!mcast_xbundle) {
2294 xlate_report(ctx, "mcast group port is unknown, dropping");
2296 xlate_report(ctx, "mcast group port is input port, dropping");
2301 /* send the packet to ports connected to multicast routers */
2303 xlate_normal_mcast_send_mrouters(struct xlate_ctx *ctx,
2304 struct mcast_snooping *ms,
2305 struct xbundle *in_xbundle, uint16_t vlan)
2306 OVS_REQ_RDLOCK(ms->rwlock)
2308 struct xlate_cfg *xcfg;
2309 struct mcast_mrouter_bundle *mrouter;
2310 struct xbundle *mcast_xbundle;
2312 xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
2313 LIST_FOR_EACH(mrouter, mrouter_node, &ms->mrouter_lru) {
2314 mcast_xbundle = xbundle_lookup(xcfg, mrouter->port);
2315 if (mcast_xbundle && mcast_xbundle != in_xbundle) {
2316 xlate_report(ctx, "forwarding to mcast router port");
2317 output_normal(ctx, mcast_xbundle, vlan);
2318 } else if (!mcast_xbundle) {
2319 xlate_report(ctx, "mcast router port is unknown, dropping");
2321 xlate_report(ctx, "mcast router port is input port, dropping");
2326 /* send the packet to ports flagged to be flooded */
2328 xlate_normal_mcast_send_fports(struct xlate_ctx *ctx,
2329 struct mcast_snooping *ms,
2330 struct xbundle *in_xbundle, uint16_t vlan)
2331 OVS_REQ_RDLOCK(ms->rwlock)
2333 struct xlate_cfg *xcfg;
2334 struct mcast_port_bundle *fport;
2335 struct xbundle *mcast_xbundle;
2337 xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
2338 LIST_FOR_EACH(fport, node, &ms->fport_list) {
2339 mcast_xbundle = xbundle_lookup(xcfg, fport->port);
2340 if (mcast_xbundle && mcast_xbundle != in_xbundle) {
2341 xlate_report(ctx, "forwarding to mcast flood port");
2342 output_normal(ctx, mcast_xbundle, vlan);
2343 } else if (!mcast_xbundle) {
2344 xlate_report(ctx, "mcast flood port is unknown, dropping");
2346 xlate_report(ctx, "mcast flood port is input port, dropping");
2351 /* forward the Reports to configured ports */
2353 xlate_normal_mcast_send_rports(struct xlate_ctx *ctx,
2354 struct mcast_snooping *ms,
2355 struct xbundle *in_xbundle, uint16_t vlan)
2356 OVS_REQ_RDLOCK(ms->rwlock)
2358 struct xlate_cfg *xcfg;
2359 struct mcast_port_bundle *rport;
2360 struct xbundle *mcast_xbundle;
2362 xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
2363 LIST_FOR_EACH(rport, node, &ms->rport_list) {
2364 mcast_xbundle = xbundle_lookup(xcfg, rport->port);
2365 if (mcast_xbundle && mcast_xbundle != in_xbundle) {
2366 xlate_report(ctx, "forwarding Report to mcast flagged port");
2367 output_normal(ctx, mcast_xbundle, vlan);
2368 } else if (!mcast_xbundle) {
2369 xlate_report(ctx, "mcast port is unknown, dropping the Report");
2371 xlate_report(ctx, "mcast port is input port, dropping the Report");
2377 xlate_normal_flood(struct xlate_ctx *ctx, struct xbundle *in_xbundle,
2380 struct xbundle *xbundle;
2382 LIST_FOR_EACH (xbundle, list_node, &ctx->xbridge->xbundles) {
2383 if (xbundle != in_xbundle
2384 && xbundle_includes_vlan(xbundle, vlan)
2385 && xbundle->floodable
2386 && !xbundle_mirror_out(ctx->xbridge, xbundle)) {
2387 output_normal(ctx, xbundle, vlan);
2390 ctx->nf_output_iface = NF_OUT_FLOOD;
2394 xlate_normal(struct xlate_ctx *ctx)
2396 struct flow_wildcards *wc = ctx->wc;
2397 struct flow *flow = &ctx->xin->flow;
2398 struct xbundle *in_xbundle;
2399 struct xport *in_port;
2400 struct mac_entry *mac;
2405 memset(&wc->masks.dl_src, 0xff, sizeof wc->masks.dl_src);
2406 memset(&wc->masks.dl_dst, 0xff, sizeof wc->masks.dl_dst);
2407 wc->masks.vlan_tci |= htons(VLAN_VID_MASK | VLAN_CFI);
2409 in_xbundle = lookup_input_bundle(ctx->xbridge, flow->in_port.ofp_port,
2410 ctx->xin->packet != NULL, &in_port);
2412 xlate_report(ctx, "no input bundle, dropping");
2416 /* Drop malformed frames. */
2417 if (flow->dl_type == htons(ETH_TYPE_VLAN) &&
2418 !(flow->vlan_tci & htons(VLAN_CFI))) {
2419 if (ctx->xin->packet != NULL) {
2420 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
2421 VLOG_WARN_RL(&rl, "bridge %s: dropping packet with partial "
2422 "VLAN tag received on port %s",
2423 ctx->xbridge->name, in_xbundle->name);
2425 xlate_report(ctx, "partial VLAN tag, dropping");
2429 /* Drop frames on bundles reserved for mirroring. */
2430 if (xbundle_mirror_out(ctx->xbridge, in_xbundle)) {
2431 if (ctx->xin->packet != NULL) {
2432 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
2433 VLOG_WARN_RL(&rl, "bridge %s: dropping packet received on port "
2434 "%s, which is reserved exclusively for mirroring",
2435 ctx->xbridge->name, in_xbundle->name);
2437 xlate_report(ctx, "input port is mirror output port, dropping");
2442 vid = vlan_tci_to_vid(flow->vlan_tci);
2443 if (!input_vid_is_valid(vid, in_xbundle, ctx->xin->packet != NULL)) {
2444 xlate_report(ctx, "disallowed VLAN VID for this input port, dropping");
2447 vlan = input_vid_to_vlan(in_xbundle, vid);
2449 /* Check other admissibility requirements. */
2450 if (in_port && !is_admissible(ctx, in_port, vlan)) {
2454 /* Learn source MAC. */
2455 if (ctx->xin->may_learn) {
2456 update_learning_table(ctx->xbridge, flow, wc, vlan, in_xbundle);
2458 if (ctx->xin->xcache) {
2459 struct xc_entry *entry;
2461 /* Save enough info to update mac learning table later. */
2462 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_NORMAL);
2463 entry->u.normal.ofproto = ctx->xbridge->ofproto;
2464 entry->u.normal.flow = xmemdup(flow, sizeof *flow);
2465 entry->u.normal.vlan = vlan;
2468 /* Determine output bundle. */
2469 if (mcast_snooping_enabled(ctx->xbridge->ms)
2470 && !eth_addr_is_broadcast(flow->dl_dst)
2471 && eth_addr_is_multicast(flow->dl_dst)
2472 && is_ip_any(flow)) {
2473 struct mcast_snooping *ms = ctx->xbridge->ms;
2474 struct mcast_group *grp = NULL;
2476 if (is_igmp(flow)) {
2477 if (mcast_snooping_is_membership(flow->tp_src) ||
2478 mcast_snooping_is_query(flow->tp_src)) {
2479 if (ctx->xin->may_learn && ctx->xin->packet) {
2480 update_mcast_snooping_table(ctx->xbridge, flow, vlan,
2481 in_xbundle, ctx->xin->packet);
2484 * IGMP packets need to take the slow path, in order to be
2485 * processed for mdb updates. That will prevent expires
2486 * firing off even after hosts have sent reports.
2488 ctx->xout->slow |= SLOW_ACTION;
2491 if (mcast_snooping_is_membership(flow->tp_src)) {
2492 ovs_rwlock_rdlock(&ms->rwlock);
2493 xlate_normal_mcast_send_mrouters(ctx, ms, in_xbundle, vlan);
2494 /* RFC4541: section 2.1.1, item 1: A snooping switch should
2495 * forward IGMP Membership Reports only to those ports where
2496 * multicast routers are attached. Alternatively stated: a
2497 * snooping switch should not forward IGMP Membership Reports
2498 * to ports on which only hosts are attached.
2499 * An administrative control may be provided to override this
2500 * restriction, allowing the report messages to be flooded to
2502 xlate_normal_mcast_send_rports(ctx, ms, in_xbundle, vlan);
2503 ovs_rwlock_unlock(&ms->rwlock);
2505 xlate_report(ctx, "multicast traffic, flooding");
2506 xlate_normal_flood(ctx, in_xbundle, vlan);
2509 } else if (is_mld(flow)) {
2510 ctx->xout->slow |= SLOW_ACTION;
2511 if (ctx->xin->may_learn && ctx->xin->packet) {
2512 update_mcast_snooping_table(ctx->xbridge, flow, vlan,
2513 in_xbundle, ctx->xin->packet);
2515 if (is_mld_report(flow)) {
2516 ovs_rwlock_rdlock(&ms->rwlock);
2517 xlate_normal_mcast_send_mrouters(ctx, ms, in_xbundle, vlan);
2518 xlate_normal_mcast_send_rports(ctx, ms, in_xbundle, vlan);
2519 ovs_rwlock_unlock(&ms->rwlock);
2521 xlate_report(ctx, "MLD query, flooding");
2522 xlate_normal_flood(ctx, in_xbundle, vlan);
2525 if ((flow->dl_type == htons(ETH_TYPE_IP)
2526 && ip_is_local_multicast(flow->nw_dst))
2527 || (flow->dl_type == htons(ETH_TYPE_IPV6)
2528 && ipv6_is_all_hosts(&flow->ipv6_dst))) {
2529 /* RFC4541: section 2.1.2, item 2: Packets with a dst IP
2530 * address in the 224.0.0.x range which are not IGMP must
2531 * be forwarded on all ports */
2532 xlate_report(ctx, "RFC4541: section 2.1.2, item 2, flooding");
2533 xlate_normal_flood(ctx, in_xbundle, vlan);
2538 /* forwarding to group base ports */
2539 ovs_rwlock_rdlock(&ms->rwlock);
2540 if (flow->dl_type == htons(ETH_TYPE_IP)) {
2541 grp = mcast_snooping_lookup4(ms, flow->nw_dst, vlan);
2542 } else if (flow->dl_type == htons(ETH_TYPE_IPV6)) {
2543 grp = mcast_snooping_lookup(ms, &flow->ipv6_dst, vlan);
2546 xlate_normal_mcast_send_group(ctx, ms, grp, in_xbundle, vlan);
2547 xlate_normal_mcast_send_fports(ctx, ms, in_xbundle, vlan);
2548 xlate_normal_mcast_send_mrouters(ctx, ms, in_xbundle, vlan);
2550 if (mcast_snooping_flood_unreg(ms)) {
2551 xlate_report(ctx, "unregistered multicast, flooding");
2552 xlate_normal_flood(ctx, in_xbundle, vlan);
2554 xlate_normal_mcast_send_mrouters(ctx, ms, in_xbundle, vlan);
2555 xlate_normal_mcast_send_fports(ctx, ms, in_xbundle, vlan);
2558 ovs_rwlock_unlock(&ms->rwlock);
2560 ovs_rwlock_rdlock(&ctx->xbridge->ml->rwlock);
2561 mac = mac_learning_lookup(ctx->xbridge->ml, flow->dl_dst, vlan);
2562 mac_port = mac ? mac_entry_get_port(ctx->xbridge->ml, mac) : NULL;
2563 ovs_rwlock_unlock(&ctx->xbridge->ml->rwlock);
2566 struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
2567 struct xbundle *mac_xbundle = xbundle_lookup(xcfg, mac_port);
2568 if (mac_xbundle && mac_xbundle != in_xbundle) {
2569 xlate_report(ctx, "forwarding to learned port");
2570 output_normal(ctx, mac_xbundle, vlan);
2571 } else if (!mac_xbundle) {
2572 xlate_report(ctx, "learned port is unknown, dropping");
2574 xlate_report(ctx, "learned port is input port, dropping");
2577 xlate_report(ctx, "no learned MAC for destination, flooding");
2578 xlate_normal_flood(ctx, in_xbundle, vlan);
2583 /* Appends a "sample" action for sFlow or IPFIX to 'ctx->odp_actions'. The
2584 * 'probability' is the number of packets out of UINT32_MAX to sample. The
2585 * 'cookie' (of length 'cookie_size' bytes) is passed back in the callback for
2586 * each sampled packet. 'tunnel_out_port', if not ODPP_NONE, is added as the
2587 * OVS_USERSPACE_ATTR_EGRESS_TUN_PORT attribute. If 'include_actions', an
2588 * OVS_USERSPACE_ATTR_ACTIONS attribute is added.
2591 compose_sample_action(struct xlate_ctx *ctx,
2592 const uint32_t probability,
2593 const union user_action_cookie *cookie,
2594 const size_t cookie_size,
2595 const odp_port_t tunnel_out_port,
2596 bool include_actions)
2598 size_t sample_offset = nl_msg_start_nested(ctx->odp_actions,
2599 OVS_ACTION_ATTR_SAMPLE);
2601 nl_msg_put_u32(ctx->odp_actions, OVS_SAMPLE_ATTR_PROBABILITY, probability);
2603 size_t actions_offset = nl_msg_start_nested(ctx->odp_actions,
2604 OVS_SAMPLE_ATTR_ACTIONS);
2606 odp_port_t odp_port = ofp_port_to_odp_port(
2607 ctx->xbridge, ctx->xin->flow.in_port.ofp_port);
2608 uint32_t pid = dpif_port_get_pid(ctx->xbridge->dpif, odp_port,
2609 flow_hash_5tuple(&ctx->xin->flow, 0));
2610 int cookie_offset = odp_put_userspace_action(pid, cookie, cookie_size,
2615 nl_msg_end_nested(ctx->odp_actions, actions_offset);
2616 nl_msg_end_nested(ctx->odp_actions, sample_offset);
2618 return cookie_offset;
2621 /* If sFLow is not enabled, returns 0 without doing anything.
2623 * If sFlow is enabled, appends a template "sample" action to the ODP actions
2624 * in 'ctx'. This action is a template because some of the information needed
2625 * to fill it out is not available until flow translation is complete. In this
2626 * case, this functions returns an offset, which is always nonzero, to pass
2627 * later to fix_sflow_action() to fill in the rest of the template. */
2629 compose_sflow_action(struct xlate_ctx *ctx)
2631 struct dpif_sflow *sflow = ctx->xbridge->sflow;
2632 if (!sflow || ctx->xin->flow.in_port.ofp_port == OFPP_NONE) {
2636 union user_action_cookie cookie = { .type = USER_ACTION_COOKIE_SFLOW };
2637 return compose_sample_action(ctx, dpif_sflow_get_probability(sflow),
2638 &cookie, sizeof cookie.sflow, ODPP_NONE,
2642 /* If IPFIX is enabled, this appends a "sample" action to implement IPFIX to
2643 * 'ctx->odp_actions'. */
2645 compose_ipfix_action(struct xlate_ctx *ctx, odp_port_t output_odp_port)
2647 struct dpif_ipfix *ipfix = ctx->xbridge->ipfix;
2648 odp_port_t tunnel_out_port = ODPP_NONE;
2650 if (!ipfix || ctx->xin->flow.in_port.ofp_port == OFPP_NONE) {
2654 /* For input case, output_odp_port is ODPP_NONE, which is an invalid port
2656 if (output_odp_port == ODPP_NONE &&
2657 !dpif_ipfix_get_bridge_exporter_input_sampling(ipfix)) {
2661 /* For output case, output_odp_port is valid*/
2662 if (output_odp_port != ODPP_NONE) {
2663 if (!dpif_ipfix_get_bridge_exporter_output_sampling(ipfix)) {
2666 /* If tunnel sampling is enabled, put an additional option attribute:
2667 * OVS_USERSPACE_ATTR_TUNNEL_OUT_PORT
2669 if (dpif_ipfix_get_bridge_exporter_tunnel_sampling(ipfix) &&
2670 dpif_ipfix_get_tunnel_port(ipfix, output_odp_port) ) {
2671 tunnel_out_port = output_odp_port;
2675 union user_action_cookie cookie = {
2677 .type = USER_ACTION_COOKIE_IPFIX,
2678 .output_odp_port = output_odp_port,
2681 compose_sample_action(ctx,
2682 dpif_ipfix_get_bridge_exporter_probability(ipfix),
2683 &cookie, sizeof cookie.ipfix, tunnel_out_port,
2687 /* Fix "sample" action according to data collected while composing ODP actions,
2688 * as described in compose_sflow_action().
2690 * 'user_cookie_offset' must be the offset returned by add_sflow_action(). */
2692 fix_sflow_action(struct xlate_ctx *ctx, unsigned int user_cookie_offset)
2694 const struct flow *base = &ctx->base_flow;
2695 union user_action_cookie *cookie;
2697 cookie = ofpbuf_at(ctx->odp_actions, user_cookie_offset,
2698 sizeof cookie->sflow);
2699 ovs_assert(cookie->type == USER_ACTION_COOKIE_SFLOW);
2701 cookie->type = USER_ACTION_COOKIE_SFLOW;
2702 cookie->sflow.vlan_tci = base->vlan_tci;
2704 /* See http://www.sflow.org/sflow_version_5.txt (search for "Input/output
2705 * port information") for the interpretation of cookie->output. */
2706 switch (ctx->sflow_n_outputs) {
2708 /* 0x40000000 | 256 means "packet dropped for unknown reason". */
2709 cookie->sflow.output = 0x40000000 | 256;
2713 cookie->sflow.output = dpif_sflow_odp_port_to_ifindex(
2714 ctx->xbridge->sflow, ctx->sflow_odp_port);
2715 if (cookie->sflow.output) {
2720 /* 0x80000000 means "multiple output ports. */
2721 cookie->sflow.output = 0x80000000 | ctx->sflow_n_outputs;
2727 process_special(struct xlate_ctx *ctx, const struct xport *xport)
2729 const struct flow *flow = &ctx->xin->flow;
2730 struct flow_wildcards *wc = ctx->wc;
2731 const struct xbridge *xbridge = ctx->xbridge;
2732 const struct dp_packet *packet = ctx->xin->packet;
2733 enum slow_path_reason slow;
2737 } else if (xport->cfm && cfm_should_process_flow(xport->cfm, flow, wc)) {
2739 cfm_process_heartbeat(xport->cfm, packet);
2742 } else if (xport->bfd && bfd_should_process_flow(xport->bfd, flow, wc)) {
2744 bfd_process_packet(xport->bfd, flow, packet);
2745 /* If POLL received, immediately sends FINAL back. */
2746 if (bfd_should_send_packet(xport->bfd)) {
2747 ofproto_dpif_monitor_port_send_soon(xport->ofport);
2751 } else if (xport->xbundle && xport->xbundle->lacp
2752 && flow->dl_type == htons(ETH_TYPE_LACP)) {
2754 lacp_process_packet(xport->xbundle->lacp, xport->ofport, packet);
2757 } else if ((xbridge->stp || xbridge->rstp) &&
2758 stp_should_process_flow(flow, wc)) {
2761 ? stp_process_packet(xport, packet)
2762 : rstp_process_packet(xport, packet);
2765 } else if (xport->lldp && lldp_should_process_flow(xport->lldp, flow)) {
2767 lldp_process_packet(xport->lldp, packet);
2775 ctx->xout->slow |= slow;
2783 tnl_route_lookup_flow(const struct flow *oflow,
2784 struct in6_addr *ip, struct in6_addr *src,
2785 struct xport **out_port)
2787 char out_dev[IFNAMSIZ];
2788 struct xbridge *xbridge;
2789 struct xlate_cfg *xcfg;
2791 struct in6_addr dst;
2793 dst = flow_tnl_dst(&oflow->tunnel);
2794 if (!ovs_router_lookup(&dst, out_dev, src, &gw)) {
2798 if (ipv6_addr_is_set(&gw) &&
2799 (!IN6_IS_ADDR_V4MAPPED(&gw) || in6_addr_get_mapped_ipv4(&gw))) {
2805 xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
2808 HMAP_FOR_EACH (xbridge, hmap_node, &xcfg->xbridges) {
2809 if (!strncmp(xbridge->name, out_dev, IFNAMSIZ)) {
2812 HMAP_FOR_EACH (port, ofp_node, &xbridge->xports) {
2813 if (!strncmp(netdev_get_name(port->netdev), out_dev, IFNAMSIZ)) {
2824 compose_table_xlate(struct xlate_ctx *ctx, const struct xport *out_dev,
2825 struct dp_packet *packet)
2827 struct xbridge *xbridge = out_dev->xbridge;
2828 struct ofpact_output output;
2831 ofpact_init(&output.ofpact, OFPACT_OUTPUT, sizeof output);
2832 flow_extract(packet, &flow);
2833 flow.in_port.ofp_port = out_dev->ofp_port;
2834 output.port = OFPP_TABLE;
2837 return ofproto_dpif_execute_actions__(xbridge->ofproto, &flow, NULL,
2838 &output.ofpact, sizeof output,
2839 ctx->indentation, ctx->depth,
2840 ctx->resubmits, packet);
2844 tnl_send_nd_request(struct xlate_ctx *ctx, const struct xport *out_dev,
2845 const struct eth_addr eth_src,
2846 struct in6_addr * ipv6_src, struct in6_addr * ipv6_dst)
2848 struct dp_packet packet;
2850 dp_packet_init(&packet, 0);
2851 compose_nd(&packet, eth_src, ipv6_src, ipv6_dst);
2852 compose_table_xlate(ctx, out_dev, &packet);
2853 dp_packet_uninit(&packet);
2857 tnl_send_arp_request(struct xlate_ctx *ctx, const struct xport *out_dev,
2858 const struct eth_addr eth_src,
2859 ovs_be32 ip_src, ovs_be32 ip_dst)
2861 struct dp_packet packet;
2863 dp_packet_init(&packet, 0);
2864 compose_arp(&packet, ARP_OP_REQUEST,
2865 eth_src, eth_addr_zero, true, ip_src, ip_dst);
2867 compose_table_xlate(ctx, out_dev, &packet);
2868 dp_packet_uninit(&packet);
2872 build_tunnel_send(struct xlate_ctx *ctx, const struct xport *xport,
2873 const struct flow *flow, odp_port_t tunnel_odp_port)
2875 struct ovs_action_push_tnl tnl_push_data;
2876 struct xport *out_dev = NULL;
2877 ovs_be32 s_ip = 0, d_ip = 0;
2878 struct in6_addr s_ip6 = in6addr_any;
2879 struct in6_addr d_ip6 = in6addr_any;
2880 struct eth_addr smac;
2881 struct eth_addr dmac;
2883 char buf_sip6[INET6_ADDRSTRLEN];
2884 char buf_dip6[INET6_ADDRSTRLEN];
2886 err = tnl_route_lookup_flow(flow, &d_ip6, &s_ip6, &out_dev);
2888 xlate_report(ctx, "native tunnel routing failed");
2892 xlate_report(ctx, "tunneling to %s via %s",
2893 ipv6_string_mapped(buf_dip6, &d_ip6),
2894 netdev_get_name(out_dev->netdev));
2896 /* Use mac addr of bridge port of the peer. */
2897 err = netdev_get_etheraddr(out_dev->netdev, &smac);
2899 xlate_report(ctx, "tunnel output device lacks Ethernet address");
2903 d_ip = in6_addr_get_mapped_ipv4(&d_ip6);
2905 s_ip = in6_addr_get_mapped_ipv4(&s_ip6);
2908 err = tnl_neigh_lookup(out_dev->xbridge->name, &d_ip6, &dmac);
2910 xlate_report(ctx, "neighbor cache miss for %s on bridge %s, "
2911 "sending %s request",
2912 buf_dip6, out_dev->xbridge->name, d_ip ? "ARP" : "ND");
2914 tnl_send_arp_request(ctx, out_dev, smac, s_ip, d_ip);
2916 tnl_send_nd_request(ctx, out_dev, smac, &s_ip6, &d_ip6);
2921 if (ctx->xin->xcache) {
2922 struct xc_entry *entry;
2924 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_TNL_NEIGH);
2925 ovs_strlcpy(entry->u.tnl_neigh_cache.br_name, out_dev->xbridge->name,
2926 sizeof entry->u.tnl_neigh_cache.br_name);
2927 entry->u.tnl_neigh_cache.d_ipv6 = d_ip6;
2930 xlate_report(ctx, "tunneling from "ETH_ADDR_FMT" %s"
2931 " to "ETH_ADDR_FMT" %s",
2932 ETH_ADDR_ARGS(smac), ipv6_string_mapped(buf_sip6, &s_ip6),
2933 ETH_ADDR_ARGS(dmac), buf_dip6);
2935 err = tnl_port_build_header(xport->ofport, flow,
2936 dmac, smac, &s_ip6, &tnl_push_data);
2940 tnl_push_data.tnl_port = odp_to_u32(tunnel_odp_port);
2941 tnl_push_data.out_port = odp_to_u32(out_dev->odp_port);
2942 odp_put_tnl_push_action(ctx->odp_actions, &tnl_push_data);
2947 xlate_commit_actions(struct xlate_ctx *ctx)
2949 bool use_masked = ctx->xbridge->support.masked_set_action;
2951 ctx->xout->slow |= commit_odp_actions(&ctx->xin->flow, &ctx->base_flow,
2952 ctx->odp_actions, ctx->wc,
2957 clear_conntrack(struct flow *flow)
2962 memset(&flow->ct_label, 0, sizeof flow->ct_label);
2966 compose_output_action__(struct xlate_ctx *ctx, ofp_port_t ofp_port,
2967 const struct xlate_bond_recirc *xr, bool check_stp)
2969 const struct xport *xport = get_ofp_port(ctx->xbridge, ofp_port);
2970 struct flow_wildcards *wc = ctx->wc;
2971 struct flow *flow = &ctx->xin->flow;
2972 struct flow_tnl flow_tnl;
2973 ovs_be16 flow_vlan_tci;
2974 uint32_t flow_pkt_mark;
2975 uint8_t flow_nw_tos;
2976 odp_port_t out_port, odp_port;
2977 bool tnl_push_pop_send = false;
2980 /* If 'struct flow' gets additional metadata, we'll need to zero it out
2981 * before traversing a patch port. */
2982 BUILD_ASSERT_DECL(FLOW_WC_SEQ == 35);
2983 memset(&flow_tnl, 0, sizeof flow_tnl);
2986 xlate_report(ctx, "Nonexistent output port");
2988 } else if (xport->config & OFPUTIL_PC_NO_FWD) {
2989 xlate_report(ctx, "OFPPC_NO_FWD set, skipping output");
2991 } else if (check_stp) {
2992 if (is_stp(&ctx->base_flow)) {
2993 if (!xport_stp_should_forward_bpdu(xport) &&
2994 !xport_rstp_should_manage_bpdu(xport)) {
2995 if (ctx->xbridge->stp != NULL) {
2996 xlate_report(ctx, "STP not in listening state, "
2997 "skipping bpdu output");
2998 } else if (ctx->xbridge->rstp != NULL) {
2999 xlate_report(ctx, "RSTP not managing BPDU in this state, "
3000 "skipping bpdu output");
3004 } else if (!xport_stp_forward_state(xport) ||
3005 !xport_rstp_forward_state(xport)) {
3006 if (ctx->xbridge->stp != NULL) {
3007 xlate_report(ctx, "STP not in forwarding state, "
3009 } else if (ctx->xbridge->rstp != NULL) {
3010 xlate_report(ctx, "RSTP not in forwarding state, "
3018 const struct xport *peer = xport->peer;
3019 struct flow old_flow = ctx->xin->flow;
3020 bool old_conntrack = ctx->conntracked;
3021 cls_version_t old_version = ctx->tables_version;
3022 struct ofpbuf old_stack = ctx->stack;
3023 union mf_subvalue new_stack[1024 / sizeof(union mf_subvalue)];
3024 struct ofpbuf old_action_set = ctx->action_set;
3025 uint64_t actset_stub[1024 / 8];
3027 ofpbuf_use_stub(&ctx->stack, new_stack, sizeof new_stack);
3028 ofpbuf_use_stub(&ctx->action_set, actset_stub, sizeof actset_stub);
3029 ctx->xbridge = peer->xbridge;
3030 flow->in_port.ofp_port = peer->ofp_port;
3031 flow->metadata = htonll(0);
3032 memset(&flow->tunnel, 0, sizeof flow->tunnel);
3033 memset(flow->regs, 0, sizeof flow->regs);
3034 flow->actset_output = OFPP_UNSET;
3035 ctx->conntracked = false;
3036 clear_conntrack(flow);
3038 /* The bridge is now known so obtain its table version. */
3040 = ofproto_dpif_get_tables_version(ctx->xbridge->ofproto);
3042 if (!process_special(ctx, peer) && may_receive(peer, ctx)) {
3043 if (xport_stp_forward_state(peer) && xport_rstp_forward_state(peer)) {
3044 xlate_table_action(ctx, flow->in_port.ofp_port, 0, true, true);
3045 if (!ctx->freezing) {
3046 xlate_action_set(ctx);
3048 if (ctx->freezing) {
3049 finish_freezing(ctx);
3052 /* Forwarding is disabled by STP and RSTP. Let OFPP_NORMAL and
3053 * the learning action look at the packet, then drop it. */
3054 struct flow old_base_flow = ctx->base_flow;
3055 size_t old_size = ctx->odp_actions->size;
3056 mirror_mask_t old_mirrors = ctx->mirrors;
3058 xlate_table_action(ctx, flow->in_port.ofp_port, 0, true, true);
3059 ctx->mirrors = old_mirrors;
3060 ctx->base_flow = old_base_flow;
3061 ctx->odp_actions->size = old_size;
3063 /* Undo changes that may have been done for freezing. */
3064 ctx_cancel_freeze(ctx);
3068 ctx->xin->flow = old_flow;
3069 ctx->xbridge = xport->xbridge;
3070 ofpbuf_uninit(&ctx->action_set);
3071 ctx->action_set = old_action_set;
3072 ofpbuf_uninit(&ctx->stack);
3073 ctx->stack = old_stack;
3075 /* Restore calling bridge's lookup version. */
3076 ctx->tables_version = old_version;
3078 /* The peer bridge's conntrack execution should have no effect on the
3079 * original bridge. */
3080 ctx->conntracked = old_conntrack;
3082 /* The fact that the peer bridge exits (for any reason) does not mean
3083 * that the original bridge should exit. Specifically, if the peer
3084 * bridge freezes translation, the original bridge must continue
3085 * processing with the original, not the frozen packet! */
3088 /* Peer bridge errors do not propagate back. */
3089 ctx->error = XLATE_OK;
3091 if (ctx->xin->resubmit_stats) {
3092 netdev_vport_inc_tx(xport->netdev, ctx->xin->resubmit_stats);
3093 netdev_vport_inc_rx(peer->netdev, ctx->xin->resubmit_stats);
3095 bfd_account_rx(peer->bfd, ctx->xin->resubmit_stats);
3098 if (ctx->xin->xcache) {
3099 struct xc_entry *entry;
3101 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_NETDEV);
3102 entry->u.dev.tx = netdev_ref(xport->netdev);
3103 entry->u.dev.rx = netdev_ref(peer->netdev);
3104 entry->u.dev.bfd = bfd_ref(peer->bfd);
3109 flow_vlan_tci = flow->vlan_tci;
3110 flow_pkt_mark = flow->pkt_mark;
3111 flow_nw_tos = flow->nw_tos;
3113 if (count_skb_priorities(xport)) {
3114 memset(&wc->masks.skb_priority, 0xff, sizeof wc->masks.skb_priority);
3115 if (dscp_from_skb_priority(xport, flow->skb_priority, &dscp)) {
3116 wc->masks.nw_tos |= IP_DSCP_MASK;
3117 flow->nw_tos &= ~IP_DSCP_MASK;
3118 flow->nw_tos |= dscp;
3122 if (xport->is_tunnel) {
3123 struct in6_addr dst;
3124 /* Save tunnel metadata so that changes made due to
3125 * the Logical (tunnel) Port are not visible for any further
3126 * matches, while explicit set actions on tunnel metadata are.
3128 flow_tnl = flow->tunnel;
3129 odp_port = tnl_port_send(xport->ofport, flow, ctx->wc);
3130 if (odp_port == ODPP_NONE) {
3131 xlate_report(ctx, "Tunneling decided against output");
3132 goto out; /* restore flow_nw_tos */
3134 dst = flow_tnl_dst(&flow->tunnel);
3135 if (ipv6_addr_equals(&dst, &ctx->orig_tunnel_ipv6_dst)) {
3136 xlate_report(ctx, "Not tunneling to our own address");
3137 goto out; /* restore flow_nw_tos */
3139 if (ctx->xin->resubmit_stats) {
3140 netdev_vport_inc_tx(xport->netdev, ctx->xin->resubmit_stats);
3142 if (ctx->xin->xcache) {
3143 struct xc_entry *entry;
3145 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_NETDEV);
3146 entry->u.dev.tx = netdev_ref(xport->netdev);
3148 out_port = odp_port;
3149 if (ovs_native_tunneling_is_on(ctx->xbridge->ofproto)) {
3150 xlate_report(ctx, "output to native tunnel");
3151 tnl_push_pop_send = true;
3153 xlate_report(ctx, "output to kernel tunnel");
3154 commit_odp_tunnel_action(flow, &ctx->base_flow, ctx->odp_actions);
3155 flow->tunnel = flow_tnl; /* Restore tunnel metadata */
3158 odp_port = xport->odp_port;
3159 out_port = odp_port;
3162 if (out_port != ODPP_NONE) {
3163 xlate_commit_actions(ctx);
3166 struct ovs_action_hash *act_hash;
3169 act_hash = nl_msg_put_unspec_uninit(ctx->odp_actions,
3170 OVS_ACTION_ATTR_HASH,
3172 act_hash->hash_alg = xr->hash_alg;
3173 act_hash->hash_basis = xr->hash_basis;
3175 /* Recirc action. */
3176 nl_msg_put_u32(ctx->odp_actions, OVS_ACTION_ATTR_RECIRC,
3180 if (tnl_push_pop_send) {
3181 build_tunnel_send(ctx, xport, flow, odp_port);
3182 flow->tunnel = flow_tnl; /* Restore tunnel metadata */
3184 odp_port_t odp_tnl_port = ODPP_NONE;
3186 /* XXX: Write better Filter for tunnel port. We can use inport
3187 * int tunnel-port flow to avoid these checks completely. */
3188 if (ofp_port == OFPP_LOCAL &&
3189 ovs_native_tunneling_is_on(ctx->xbridge->ofproto)) {
3191 odp_tnl_port = tnl_port_map_lookup(flow, wc);
3194 if (odp_tnl_port != ODPP_NONE) {
3195 nl_msg_put_odp_port(ctx->odp_actions,
3196 OVS_ACTION_ATTR_TUNNEL_POP,
3199 /* Tunnel push-pop action is not compatible with
3201 compose_ipfix_action(ctx, out_port);
3202 nl_msg_put_odp_port(ctx->odp_actions,
3203 OVS_ACTION_ATTR_OUTPUT,
3209 ctx->sflow_odp_port = odp_port;
3210 ctx->sflow_n_outputs++;
3211 ctx->nf_output_iface = ofp_port;
3214 if (mbridge_has_mirrors(ctx->xbridge->mbridge) && xport->xbundle) {
3215 mirror_packet(ctx, xport->xbundle,
3216 xbundle_mirror_dst(xport->xbundle->xbridge,
3222 flow->vlan_tci = flow_vlan_tci;
3223 flow->pkt_mark = flow_pkt_mark;
3224 flow->nw_tos = flow_nw_tos;
3228 compose_output_action(struct xlate_ctx *ctx, ofp_port_t ofp_port,
3229 const struct xlate_bond_recirc *xr)
3231 compose_output_action__(ctx, ofp_port, xr, true);
3235 xlate_recursively(struct xlate_ctx *ctx, struct rule_dpif *rule, bool deepens)
3237 struct rule_dpif *old_rule = ctx->rule;
3238 ovs_be64 old_cookie = ctx->rule_cookie;
3239 const struct rule_actions *actions;
3241 if (ctx->xin->resubmit_stats) {
3242 rule_dpif_credit_stats(rule, ctx->xin->resubmit_stats);
3248 ctx->depth += deepens;
3250 ctx->rule_cookie = rule_dpif_get_flow_cookie(rule);
3251 actions = rule_dpif_get_actions(rule);
3252 do_xlate_actions(actions->ofpacts, actions->ofpacts_len, ctx);
3253 ctx->rule_cookie = old_cookie;
3254 ctx->rule = old_rule;
3255 ctx->depth -= deepens;
3260 xlate_resubmit_resource_check(struct xlate_ctx *ctx)
3262 if (ctx->depth >= MAX_DEPTH) {
3263 XLATE_REPORT_ERROR(ctx, "over max translation depth %d", MAX_DEPTH);
3264 ctx->error = XLATE_RECURSION_TOO_DEEP;
3265 } else if (ctx->resubmits >= MAX_RESUBMITS) {
3266 XLATE_REPORT_ERROR(ctx, "over %d resubmit actions", MAX_RESUBMITS);
3267 ctx->error = XLATE_TOO_MANY_RESUBMITS;
3268 } else if (ctx->odp_actions->size > UINT16_MAX) {
3269 XLATE_REPORT_ERROR(ctx, "resubmits yielded over 64 kB of actions");
3270 /* NOT an error, as we'll be slow-pathing the flow in this case? */
3271 ctx->exit = true; /* XXX: translation still terminated! */
3272 } else if (ctx->stack.size >= 65536) {
3273 XLATE_REPORT_ERROR(ctx, "resubmits yielded over 64 kB of stack");
3274 ctx->error = XLATE_STACK_TOO_DEEP;
3283 xlate_table_action(struct xlate_ctx *ctx, ofp_port_t in_port, uint8_t table_id,
3284 bool may_packet_in, bool honor_table_miss)
3286 if (xlate_resubmit_resource_check(ctx)) {
3287 uint8_t old_table_id = ctx->table_id;
3288 struct rule_dpif *rule;
3290 ctx->table_id = table_id;
3292 rule = rule_dpif_lookup_from_table(ctx->xbridge->ofproto,
3293 ctx->tables_version,
3294 &ctx->xin->flow, ctx->xin->wc,
3295 ctx->xin->resubmit_stats,
3296 &ctx->table_id, in_port,
3297 may_packet_in, honor_table_miss);
3299 if (OVS_UNLIKELY(ctx->xin->resubmit_hook)) {
3300 ctx->xin->resubmit_hook(ctx->xin, rule, ctx->indentation + 1);
3304 /* Fill in the cache entry here instead of xlate_recursively
3305 * to make the reference counting more explicit. We take a
3306 * reference in the lookups above if we are going to cache the
3308 if (ctx->xin->xcache) {
3309 struct xc_entry *entry;
3311 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_RULE);
3312 entry->u.rule = rule;
3313 rule_dpif_ref(rule);
3315 xlate_recursively(ctx, rule, table_id <= old_table_id);
3318 ctx->table_id = old_table_id;
3324 xlate_group_stats(struct xlate_ctx *ctx, struct group_dpif *group,
3325 struct ofputil_bucket *bucket)
3327 if (ctx->xin->resubmit_stats) {
3328 group_dpif_credit_stats(group, bucket, ctx->xin->resubmit_stats);
3330 if (ctx->xin->xcache) {
3331 struct xc_entry *entry;
3333 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_GROUP);
3334 entry->u.group.group = group_dpif_ref(group);
3335 entry->u.group.bucket = bucket;
3340 xlate_group_bucket(struct xlate_ctx *ctx, struct ofputil_bucket *bucket)
3342 uint64_t action_list_stub[1024 / 8];
3343 struct ofpbuf action_list = OFPBUF_STUB_INITIALIZER(action_list_stub);
3344 struct ofpbuf action_set = ofpbuf_const_initializer(bucket->ofpacts,
3345 bucket->ofpacts_len);
3346 struct flow old_flow = ctx->xin->flow;
3348 ofpacts_execute_action_set(&action_list, &action_set);
3351 do_xlate_actions(action_list.data, action_list.size, ctx);
3355 ofpbuf_uninit(&action_list);
3357 /* Check if need to freeze. */
3358 if (ctx->freezing) {
3359 finish_freezing(ctx);
3362 /* Roll back flow to previous state.
3363 * This is equivalent to cloning the packet for each bucket.
3365 * As a side effect any subsequently applied actions will
3366 * also effectively be applied to a clone of the packet taken
3367 * just before applying the all or indirect group.
3369 * Note that group buckets are action sets, hence they cannot modify the
3370 * main action set. Also any stack actions are ignored when executing an
3371 * action set, so group buckets cannot change the stack either.
3372 * However, we do allow resubmit actions in group buckets, which could
3373 * break the above assumptions. It is up to the controller to not mess up
3374 * with the action_set and stack in the tables resubmitted to from
3376 ctx->xin->flow = old_flow;
3378 /* The fact that the group bucket exits (for any reason) does not mean that
3379 * the translation after the group action should exit. Specifically, if
3380 * the group bucket freezes translation, the actions after the group action
3381 * must continue processing with the original, not the frozen packet! */
3386 xlate_all_group(struct xlate_ctx *ctx, struct group_dpif *group)
3388 struct ofputil_bucket *bucket;
3389 const struct ovs_list *buckets;
3391 group_dpif_get_buckets(group, &buckets);
3393 LIST_FOR_EACH (bucket, list_node, buckets) {
3394 xlate_group_bucket(ctx, bucket);
3396 xlate_group_stats(ctx, group, NULL);
3400 xlate_ff_group(struct xlate_ctx *ctx, struct group_dpif *group)
3402 struct ofputil_bucket *bucket;
3404 bucket = group_first_live_bucket(ctx, group, 0);
3406 xlate_group_bucket(ctx, bucket);
3407 xlate_group_stats(ctx, group, bucket);
3412 xlate_default_select_group(struct xlate_ctx *ctx, struct group_dpif *group)
3414 struct flow_wildcards *wc = ctx->wc;
3415 struct ofputil_bucket *bucket;
3418 basis = flow_hash_symmetric_l4(&ctx->xin->flow, 0);
3419 flow_mask_hash_fields(&ctx->xin->flow, wc, NX_HASH_FIELDS_SYMMETRIC_L4);
3420 bucket = group_best_live_bucket(ctx, group, basis);
3422 xlate_group_bucket(ctx, bucket);
3423 xlate_group_stats(ctx, group, bucket);
3428 xlate_hash_fields_select_group(struct xlate_ctx *ctx, struct group_dpif *group)
3430 struct mf_bitmap hash_fields = MF_BITMAP_INITIALIZER;
3431 const struct field_array *fields;
3432 struct ofputil_bucket *bucket;
3436 fields = group_dpif_get_fields(group);
3437 basis = hash_uint64(group_dpif_get_selection_method_param(group));
3439 /* Determine which fields to hash */
3440 for (i = 0; i < MFF_N_IDS; i++) {
3441 if (bitmap_is_set(fields->used.bm, i)) {
3442 const struct mf_field *mf;
3444 /* If the field is already present in 'hash_fields' then
3445 * this loop has already checked that it and its pre-requisites
3446 * are present in the flow and its pre-requisites have
3447 * already been added to 'hash_fields'. There is nothing more
3448 * to do here and as an optimisation the loop can continue. */
3449 if (bitmap_is_set(hash_fields.bm, i)) {
3455 /* Only hash a field if it and its pre-requisites are present
3457 if (!mf_are_prereqs_ok(mf, &ctx->xin->flow)) {
3461 /* Hash both the field and its pre-requisites */
3462 mf_bitmap_set_field_and_prereqs(mf, &hash_fields);
3466 /* Hash the fields */
3467 for (i = 0; i < MFF_N_IDS; i++) {
3468 if (bitmap_is_set(hash_fields.bm, i)) {
3469 const struct mf_field *mf = mf_from_id(i);
3470 union mf_value value;
3473 mf_get_value(mf, &ctx->xin->flow, &value);
3474 /* This seems inefficient but so does apply_mask() */
3475 for (j = 0; j < mf->n_bytes; j++) {
3476 ((uint8_t *) &value)[j] &= ((uint8_t *) &fields->value[i])[j];
3478 basis = hash_bytes(&value, mf->n_bytes, basis);
3480 /* For tunnels, hash in whether the field is present. */
3481 if (mf_is_tun_metadata(mf)) {
3482 basis = hash_boolean(mf_is_set(mf, &ctx->xin->flow), basis);
3485 mf_mask_field(mf, &ctx->wc->masks);
3489 bucket = group_best_live_bucket(ctx, group, basis);
3491 xlate_group_bucket(ctx, bucket);
3492 xlate_group_stats(ctx, group, bucket);
3497 xlate_select_group(struct xlate_ctx *ctx, struct group_dpif *group)
3499 const char *selection_method = group_dpif_get_selection_method(group);
3501 if (selection_method[0] == '\0') {
3502 xlate_default_select_group(ctx, group);
3503 } else if (!strcasecmp("hash", selection_method)) {
3504 xlate_hash_fields_select_group(ctx, group);
3506 /* Parsing of groups should ensure this never happens */
3512 xlate_group_action__(struct xlate_ctx *ctx, struct group_dpif *group)
3514 bool was_in_group = ctx->in_group;
3515 ctx->in_group = true;
3517 switch (group_dpif_get_type(group)) {
3519 case OFPGT11_INDIRECT:
3520 xlate_all_group(ctx, group);
3522 case OFPGT11_SELECT:
3523 xlate_select_group(ctx, group);
3526 xlate_ff_group(ctx, group);
3531 group_dpif_unref(group);
3533 ctx->in_group = was_in_group;
3537 xlate_group_action(struct xlate_ctx *ctx, uint32_t group_id)
3539 if (xlate_resubmit_resource_check(ctx)) {
3540 struct group_dpif *group;
3543 got_group = group_dpif_lookup(ctx->xbridge->ofproto, group_id, &group);
3545 xlate_group_action__(ctx, group);
3555 xlate_ofpact_resubmit(struct xlate_ctx *ctx,
3556 const struct ofpact_resubmit *resubmit)
3560 bool may_packet_in = false;
3561 bool honor_table_miss = false;
3563 if (ctx->rule && rule_dpif_is_internal(ctx->rule)) {
3564 /* Still allow missed packets to be sent to the controller
3565 * if resubmitting from an internal table. */
3566 may_packet_in = true;
3567 honor_table_miss = true;
3570 in_port = resubmit->in_port;
3571 if (in_port == OFPP_IN_PORT) {
3572 in_port = ctx->xin->flow.in_port.ofp_port;
3575 table_id = resubmit->table_id;
3576 if (table_id == 255) {
3577 table_id = ctx->table_id;
3580 xlate_table_action(ctx, in_port, table_id, may_packet_in,
3585 flood_packets(struct xlate_ctx *ctx, bool all)
3587 const struct xport *xport;
3589 HMAP_FOR_EACH (xport, ofp_node, &ctx->xbridge->xports) {
3590 if (xport->ofp_port == ctx->xin->flow.in_port.ofp_port) {
3595 compose_output_action__(ctx, xport->ofp_port, NULL, false);
3596 } else if (!(xport->config & OFPUTIL_PC_NO_FLOOD)) {
3597 compose_output_action(ctx, xport->ofp_port, NULL);
3601 ctx->nf_output_iface = NF_OUT_FLOOD;
3605 execute_controller_action(struct xlate_ctx *ctx, int len,
3606 enum ofp_packet_in_reason reason,
3607 uint16_t controller_id,
3608 const uint8_t *userdata, size_t userdata_len)
3610 struct dp_packet *packet;
3612 ctx->xout->slow |= SLOW_CONTROLLER;
3613 xlate_commit_actions(ctx);
3614 if (!ctx->xin->packet) {
3618 packet = dp_packet_clone(ctx->xin->packet);
3620 odp_execute_actions(NULL, &packet, 1, false,
3621 ctx->odp_actions->data, ctx->odp_actions->size, NULL);
3623 /* A packet sent by an action in a table-miss rule is considered an
3624 * explicit table miss. OpenFlow before 1.3 doesn't have that concept so
3625 * it will get translated back to OFPR_ACTION for those versions. */
3626 if (reason == OFPR_ACTION
3627 && ctx->rule && rule_dpif_is_table_miss(ctx->rule)) {
3628 reason = OFPR_EXPLICIT_MISS;
3631 size_t packet_len = dp_packet_size(packet);
3633 struct ofproto_async_msg *am = xmalloc(sizeof *am);
3634 *am = (struct ofproto_async_msg) {
3635 .controller_id = controller_id,
3636 .oam = OAM_PACKET_IN,
3640 .packet = dp_packet_steal_data(packet),
3641 .packet_len = packet_len,
3643 .table_id = ctx->table_id,
3644 .cookie = ctx->rule_cookie,
3645 .userdata = (userdata_len
3646 ? xmemdup(userdata, userdata_len)
3648 .userdata_len = userdata_len,
3654 flow_get_metadata(&ctx->xin->flow, &am->pin.up.public.flow_metadata);
3656 ofproto_dpif_send_async_msg(ctx->xbridge->ofproto, am);
3657 dp_packet_delete(packet);
3661 emit_continuation(struct xlate_ctx *ctx, const struct frozen_state *state)
3663 struct ofproto_async_msg *am = xmalloc(sizeof *am);
3664 *am = (struct ofproto_async_msg) {
3665 .controller_id = ctx->pause->controller_id,
3666 .oam = OAM_PACKET_IN,
3670 .userdata = xmemdup(ctx->pause->userdata,
3671 ctx->pause->userdata_len),
3672 .userdata_len = ctx->pause->userdata_len,
3673 .packet = xmemdup(dp_packet_data(ctx->xin->packet),
3674 dp_packet_size(ctx->xin->packet)),
3675 .packet_len = dp_packet_size(ctx->xin->packet),
3676 .reason = ctx->pause->reason,
3678 .bridge = *ofproto_dpif_get_uuid(ctx->xbridge->ofproto),
3679 .stack = xmemdup(state->stack,
3680 state->n_stack * sizeof *state->stack),
3681 .n_stack = state->n_stack,
3682 .mirrors = state->mirrors,
3683 .conntracked = state->conntracked,
3684 .actions = xmemdup(state->ofpacts, state->ofpacts_len),
3685 .actions_len = state->ofpacts_len,
3686 .action_set = xmemdup(state->action_set,
3687 state->action_set_len),
3688 .action_set_len = state->action_set_len,
3690 .max_len = UINT16_MAX,
3693 flow_get_metadata(&ctx->xin->flow, &am->pin.up.public.flow_metadata);
3694 ofproto_dpif_send_async_msg(ctx->xbridge->ofproto, am);
3698 finish_freezing__(struct xlate_ctx *ctx, uint8_t table)
3700 ovs_assert(ctx->freezing);
3702 struct frozen_state state = {
3704 .ofproto_uuid = *ofproto_dpif_get_uuid(ctx->xbridge->ofproto),
3705 .stack = ctx->stack.data,
3706 .n_stack = ctx->stack.size / sizeof(union mf_subvalue),
3707 .mirrors = ctx->mirrors,
3708 .conntracked = ctx->conntracked,
3709 .ofpacts = ctx->frozen_actions.data,
3710 .ofpacts_len = ctx->frozen_actions.size,
3711 .action_set = ctx->action_set.data,
3712 .action_set_len = ctx->action_set.size,
3714 frozen_metadata_from_flow(&state.metadata, &ctx->xin->flow);
3717 if (ctx->xin->packet) {
3718 emit_continuation(ctx, &state);
3721 /* Allocate a unique recirc id for the given metadata state in the
3722 * flow. An existing id, with a new reference to the corresponding
3723 * recirculation context, will be returned if possible.
3724 * The life-cycle of this recirc id is managed by associating it
3725 * with the udpif key ('ukey') created for each new datapath flow. */
3726 uint32_t id = recirc_alloc_id_ctx(&state);
3728 XLATE_REPORT_ERROR(ctx, "Failed to allocate recirculation id");
3729 ctx->error = XLATE_NO_RECIRCULATION_CONTEXT;
3732 recirc_refs_add(&ctx->xout->recircs, id);
3734 nl_msg_put_u32(ctx->odp_actions, OVS_ACTION_ATTR_RECIRC, id);
3737 /* Undo changes done by freezing. */
3738 ctx_cancel_freeze(ctx);
3741 /* Called only when we're freezing. */
3743 finish_freezing(struct xlate_ctx *ctx)
3745 xlate_commit_actions(ctx);
3746 finish_freezing__(ctx, 0);
3749 /* Fork the pipeline here. The current packet will continue processing the
3750 * current action list. A clone of the current packet will recirculate, skip
3751 * the remainder of the current action list and asynchronously resume pipeline
3752 * processing in 'table' with the current metadata and action set. */
3754 compose_recirculate_and_fork(struct xlate_ctx *ctx, uint8_t table)
3756 ctx->freezing = true;
3757 finish_freezing__(ctx, table);
3761 compose_mpls_push_action(struct xlate_ctx *ctx, struct ofpact_push_mpls *mpls)
3763 struct flow *flow = &ctx->xin->flow;
3766 ovs_assert(eth_type_mpls(mpls->ethertype));
3768 n = flow_count_mpls_labels(flow, ctx->wc);
3770 xlate_commit_actions(ctx);
3771 } else if (n >= FLOW_MAX_MPLS_LABELS) {
3772 if (ctx->xin->packet != NULL) {
3773 XLATE_REPORT_ERROR(ctx, "bridge %s: dropping packet on which an "
3774 "MPLS push action can't be performed as it would "
3775 "have more MPLS LSEs than the %d supported.",
3776 ctx->xbridge->name, FLOW_MAX_MPLS_LABELS);
3778 ctx->error = XLATE_TOO_MANY_MPLS_LABELS;
3782 flow_push_mpls(flow, n, mpls->ethertype, ctx->wc);
3786 compose_mpls_pop_action(struct xlate_ctx *ctx, ovs_be16 eth_type)
3788 struct flow *flow = &ctx->xin->flow;
3789 int n = flow_count_mpls_labels(flow, ctx->wc);
3791 if (flow_pop_mpls(flow, n, eth_type, ctx->wc)) {
3792 if (!eth_type_mpls(eth_type) && ctx->xbridge->support.odp.recirc) {
3793 ctx_trigger_freeze(ctx);
3795 } else if (n >= FLOW_MAX_MPLS_LABELS) {
3796 if (ctx->xin->packet != NULL) {
3797 XLATE_REPORT_ERROR(ctx, "bridge %s: dropping packet on which an "
3798 "MPLS pop action can't be performed as it has "
3799 "more MPLS LSEs than the %d supported.",
3800 ctx->xbridge->name, FLOW_MAX_MPLS_LABELS);
3802 ctx->error = XLATE_TOO_MANY_MPLS_LABELS;
3803 ofpbuf_clear(ctx->odp_actions);
3808 compose_dec_ttl(struct xlate_ctx *ctx, struct ofpact_cnt_ids *ids)
3810 struct flow *flow = &ctx->xin->flow;
3812 if (!is_ip_any(flow)) {
3816 ctx->wc->masks.nw_ttl = 0xff;
3817 if (flow->nw_ttl > 1) {
3823 for (i = 0; i < ids->n_controllers; i++) {
3824 execute_controller_action(ctx, UINT16_MAX, OFPR_INVALID_TTL,
3825 ids->cnt_ids[i], NULL, 0);
3828 /* Stop processing for current table. */
3834 compose_set_mpls_label_action(struct xlate_ctx *ctx, ovs_be32 label)
3836 if (eth_type_mpls(ctx->xin->flow.dl_type)) {
3837 ctx->wc->masks.mpls_lse[0] |= htonl(MPLS_LABEL_MASK);
3838 set_mpls_lse_label(&ctx->xin->flow.mpls_lse[0], label);
3843 compose_set_mpls_tc_action(struct xlate_ctx *ctx, uint8_t tc)
3845 if (eth_type_mpls(ctx->xin->flow.dl_type)) {
3846 ctx->wc->masks.mpls_lse[0] |= htonl(MPLS_TC_MASK);
3847 set_mpls_lse_tc(&ctx->xin->flow.mpls_lse[0], tc);
3852 compose_set_mpls_ttl_action(struct xlate_ctx *ctx, uint8_t ttl)
3854 if (eth_type_mpls(ctx->xin->flow.dl_type)) {
3855 ctx->wc->masks.mpls_lse[0] |= htonl(MPLS_TTL_MASK);
3856 set_mpls_lse_ttl(&ctx->xin->flow.mpls_lse[0], ttl);
3861 compose_dec_mpls_ttl_action(struct xlate_ctx *ctx)
3863 struct flow *flow = &ctx->xin->flow;
3865 if (eth_type_mpls(flow->dl_type)) {
3866 uint8_t ttl = mpls_lse_to_ttl(flow->mpls_lse[0]);
3868 ctx->wc->masks.mpls_lse[0] |= htonl(MPLS_TTL_MASK);
3871 set_mpls_lse_ttl(&flow->mpls_lse[0], ttl);
3874 execute_controller_action(ctx, UINT16_MAX, OFPR_INVALID_TTL, 0,
3879 /* Stop processing for current table. */
3884 xlate_output_action(struct xlate_ctx *ctx,
3885 ofp_port_t port, uint16_t max_len, bool may_packet_in)
3887 ofp_port_t prev_nf_output_iface = ctx->nf_output_iface;
3889 ctx->nf_output_iface = NF_OUT_DROP;
3893 compose_output_action(ctx, ctx->xin->flow.in_port.ofp_port, NULL);
3896 xlate_table_action(ctx, ctx->xin->flow.in_port.ofp_port,
3897 0, may_packet_in, true);
3903 flood_packets(ctx, false);
3906 flood_packets(ctx, true);
3908 case OFPP_CONTROLLER:
3909 execute_controller_action(ctx, max_len,
3910 (ctx->in_group ? OFPR_GROUP
3911 : ctx->in_action_set ? OFPR_ACTION_SET
3919 if (port != ctx->xin->flow.in_port.ofp_port) {
3920 compose_output_action(ctx, port, NULL);
3922 xlate_report(ctx, "skipping output to input port");
3927 if (prev_nf_output_iface == NF_OUT_FLOOD) {
3928 ctx->nf_output_iface = NF_OUT_FLOOD;
3929 } else if (ctx->nf_output_iface == NF_OUT_DROP) {
3930 ctx->nf_output_iface = prev_nf_output_iface;
3931 } else if (prev_nf_output_iface != NF_OUT_DROP &&
3932 ctx->nf_output_iface != NF_OUT_FLOOD) {
3933 ctx->nf_output_iface = NF_OUT_MULTI;
3938 xlate_output_reg_action(struct xlate_ctx *ctx,
3939 const struct ofpact_output_reg *or)
3941 uint64_t port = mf_get_subfield(&or->src, &ctx->xin->flow);
3942 if (port <= UINT16_MAX) {
3943 union mf_subvalue value;
3945 memset(&value, 0xff, sizeof value);
3946 mf_write_subfield_flow(&or->src, &value, &ctx->wc->masks);
3947 xlate_output_action(ctx, u16_to_ofp(port),
3948 or->max_len, false);
3953 xlate_enqueue_action(struct xlate_ctx *ctx,
3954 const struct ofpact_enqueue *enqueue)
3956 ofp_port_t ofp_port = enqueue->port;
3957 uint32_t queue_id = enqueue->queue;
3958 uint32_t flow_priority, priority;
3961 /* Translate queue to priority. */
3962 error = dpif_queue_to_priority(ctx->xbridge->dpif, queue_id, &priority);
3964 /* Fall back to ordinary output action. */
3965 xlate_output_action(ctx, enqueue->port, 0, false);
3969 /* Check output port. */
3970 if (ofp_port == OFPP_IN_PORT) {
3971 ofp_port = ctx->xin->flow.in_port.ofp_port;
3972 } else if (ofp_port == ctx->xin->flow.in_port.ofp_port) {
3976 /* Add datapath actions. */
3977 flow_priority = ctx->xin->flow.skb_priority;
3978 ctx->xin->flow.skb_priority = priority;
3979 compose_output_action(ctx, ofp_port, NULL);
3980 ctx->xin->flow.skb_priority = flow_priority;
3982 /* Update NetFlow output port. */
3983 if (ctx->nf_output_iface == NF_OUT_DROP) {
3984 ctx->nf_output_iface = ofp_port;
3985 } else if (ctx->nf_output_iface != NF_OUT_FLOOD) {
3986 ctx->nf_output_iface = NF_OUT_MULTI;
3991 xlate_set_queue_action(struct xlate_ctx *ctx, uint32_t queue_id)
3993 uint32_t skb_priority;
3995 if (!dpif_queue_to_priority(ctx->xbridge->dpif, queue_id, &skb_priority)) {
3996 ctx->xin->flow.skb_priority = skb_priority;
3998 /* Couldn't translate queue to a priority. Nothing to do. A warning
3999 * has already been logged. */
4004 slave_enabled_cb(ofp_port_t ofp_port, void *xbridge_)
4006 const struct xbridge *xbridge = xbridge_;
4017 case OFPP_CONTROLLER: /* Not supported by the bundle action. */
4020 port = get_ofp_port(xbridge, ofp_port);
4021 return port ? port->may_enable : false;
4026 xlate_bundle_action(struct xlate_ctx *ctx,
4027 const struct ofpact_bundle *bundle)
4031 port = bundle_execute(bundle, &ctx->xin->flow, ctx->wc, slave_enabled_cb,
4032 CONST_CAST(struct xbridge *, ctx->xbridge));
4033 if (bundle->dst.field) {
4034 nxm_reg_load(&bundle->dst, ofp_to_u16(port), &ctx->xin->flow, ctx->wc);
4036 xlate_output_action(ctx, port, 0, false);
4041 xlate_learn_action__(struct xlate_ctx *ctx, const struct ofpact_learn *learn,
4042 struct ofputil_flow_mod *fm, struct ofpbuf *ofpacts)
4044 learn_execute(learn, &ctx->xin->flow, fm, ofpacts);
4045 if (ctx->xin->may_learn) {
4046 ofproto_dpif_flow_mod(ctx->xbridge->ofproto, fm);
4051 xlate_learn_action(struct xlate_ctx *ctx, const struct ofpact_learn *learn)
4053 learn_mask(learn, ctx->wc);
4055 if (ctx->xin->xcache) {
4056 struct xc_entry *entry;
4058 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_LEARN);
4059 entry->u.learn.ofproto = ctx->xbridge->ofproto;
4060 entry->u.learn.fm = xmalloc(sizeof *entry->u.learn.fm);
4061 entry->u.learn.ofpacts = ofpbuf_new(64);
4062 xlate_learn_action__(ctx, learn, entry->u.learn.fm,
4063 entry->u.learn.ofpacts);
4064 } else if (ctx->xin->may_learn) {
4065 uint64_t ofpacts_stub[1024 / 8];
4066 struct ofputil_flow_mod fm;
4067 struct ofpbuf ofpacts;
4069 ofpbuf_use_stub(&ofpacts, ofpacts_stub, sizeof ofpacts_stub);
4070 xlate_learn_action__(ctx, learn, &fm, &ofpacts);
4071 ofpbuf_uninit(&ofpacts);
4076 xlate_fin_timeout__(struct rule_dpif *rule, uint16_t tcp_flags,
4077 uint16_t idle_timeout, uint16_t hard_timeout)
4079 if (tcp_flags & (TCP_FIN | TCP_RST)) {
4080 rule_dpif_reduce_timeouts(rule, idle_timeout, hard_timeout);
4085 xlate_fin_timeout(struct xlate_ctx *ctx,
4086 const struct ofpact_fin_timeout *oft)
4089 xlate_fin_timeout__(ctx->rule, ctx->xin->tcp_flags,
4090 oft->fin_idle_timeout, oft->fin_hard_timeout);
4091 if (ctx->xin->xcache) {
4092 struct xc_entry *entry;
4094 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_FIN_TIMEOUT);
4095 /* XC_RULE already holds a reference on the rule, none is taken
4097 entry->u.fin.rule = ctx->rule;
4098 entry->u.fin.idle = oft->fin_idle_timeout;
4099 entry->u.fin.hard = oft->fin_hard_timeout;
4105 xlate_sample_action(struct xlate_ctx *ctx,
4106 const struct ofpact_sample *os)
4108 /* Scale the probability from 16-bit to 32-bit while representing
4109 * the same percentage. */
4110 uint32_t probability = (os->probability << 16) | os->probability;
4112 if (!ctx->xbridge->support.variable_length_userdata) {
4113 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
4115 VLOG_ERR_RL(&rl, "ignoring NXAST_SAMPLE action because datapath "
4116 "lacks support (needs Linux 3.10+ or kernel module from "
4121 xlate_commit_actions(ctx);
4123 union user_action_cookie cookie = {
4125 .type = USER_ACTION_COOKIE_FLOW_SAMPLE,
4126 .probability = os->probability,
4127 .collector_set_id = os->collector_set_id,
4128 .obs_domain_id = os->obs_domain_id,
4129 .obs_point_id = os->obs_point_id,
4132 compose_sample_action(ctx, probability, &cookie, sizeof cookie.flow_sample,
4137 may_receive(const struct xport *xport, struct xlate_ctx *ctx)
4139 if (xport->config & (is_stp(&ctx->xin->flow)
4140 ? OFPUTIL_PC_NO_RECV_STP
4141 : OFPUTIL_PC_NO_RECV)) {
4145 /* Only drop packets here if both forwarding and learning are
4146 * disabled. If just learning is enabled, we need to have
4147 * OFPP_NORMAL and the learning action have a look at the packet
4148 * before we can drop it. */
4149 if ((!xport_stp_forward_state(xport) && !xport_stp_learn_state(xport)) ||
4150 (!xport_rstp_forward_state(xport) && !xport_rstp_learn_state(xport))) {
4158 xlate_write_actions__(struct xlate_ctx *ctx,
4159 const struct ofpact *ofpacts, size_t ofpacts_len)
4161 /* Maintain actset_output depending on the contents of the action set:
4163 * - OFPP_UNSET, if there is no "output" action.
4165 * - The output port, if there is an "output" action and no "group"
4168 * - OFPP_UNSET, if there is a "group" action.
4170 if (!ctx->action_set_has_group) {
4171 const struct ofpact *a;
4172 OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
4173 if (a->type == OFPACT_OUTPUT) {
4174 ctx->xin->flow.actset_output = ofpact_get_OUTPUT(a)->port;
4175 } else if (a->type == OFPACT_GROUP) {
4176 ctx->xin->flow.actset_output = OFPP_UNSET;
4177 ctx->action_set_has_group = true;
4183 ofpbuf_put(&ctx->action_set, ofpacts, ofpacts_len);
4187 xlate_write_actions(struct xlate_ctx *ctx, const struct ofpact_nest *a)
4189 xlate_write_actions__(ctx, a->actions, ofpact_nest_get_action_len(a));
4193 xlate_action_set(struct xlate_ctx *ctx)
4195 uint64_t action_list_stub[1024 / 64];
4196 struct ofpbuf action_list;
4198 ctx->in_action_set = true;
4199 ofpbuf_use_stub(&action_list, action_list_stub, sizeof action_list_stub);
4200 ofpacts_execute_action_set(&action_list, &ctx->action_set);
4201 /* Clear the action set, as it is not needed any more. */
4202 ofpbuf_clear(&ctx->action_set);
4203 do_xlate_actions(action_list.data, action_list.size, ctx);
4204 ctx->in_action_set = false;
4205 ofpbuf_uninit(&action_list);
4209 freeze_put_unroll_xlate(struct xlate_ctx *ctx)
4211 struct ofpact_unroll_xlate *unroll = ctx->frozen_actions.header;
4213 /* Restore the table_id and rule cookie for a potential PACKET
4216 (ctx->table_id != unroll->rule_table_id
4217 || ctx->rule_cookie != unroll->rule_cookie)) {
4218 unroll = ofpact_put_UNROLL_XLATE(&ctx->frozen_actions);
4219 unroll->rule_table_id = ctx->table_id;
4220 unroll->rule_cookie = ctx->rule_cookie;
4221 ctx->frozen_actions.header = unroll;
4226 /* Copy actions 'a' through 'end' to ctx->frozen_actions, which will be
4227 * executed after thawing. Inserts an UNROLL_XLATE action, if none is already
4228 * present, before any action that may depend on the current table ID or flow
4231 freeze_unroll_actions(const struct ofpact *a, const struct ofpact *end,
4232 struct xlate_ctx *ctx)
4234 for (; a < end; a = ofpact_next(a)) {
4236 case OFPACT_OUTPUT_REG:
4239 case OFPACT_CONTROLLER:
4240 case OFPACT_DEC_MPLS_TTL:
4241 case OFPACT_DEC_TTL:
4242 /* These actions may generate asynchronous messages, which include
4243 * table ID and flow cookie information. */
4244 freeze_put_unroll_xlate(ctx);
4247 case OFPACT_RESUBMIT:
4248 if (ofpact_get_RESUBMIT(a)->table_id == 0xff) {
4249 /* This resubmit action is relative to the current table, so we
4250 * need to track what table that is.*/
4251 freeze_put_unroll_xlate(ctx);
4255 case OFPACT_SET_TUNNEL:
4256 case OFPACT_REG_MOVE:
4257 case OFPACT_SET_FIELD:
4258 case OFPACT_STACK_PUSH:
4259 case OFPACT_STACK_POP:
4261 case OFPACT_WRITE_METADATA:
4262 case OFPACT_GOTO_TABLE:
4263 case OFPACT_ENQUEUE:
4264 case OFPACT_SET_VLAN_VID:
4265 case OFPACT_SET_VLAN_PCP:
4266 case OFPACT_STRIP_VLAN:
4267 case OFPACT_PUSH_VLAN:
4268 case OFPACT_SET_ETH_SRC:
4269 case OFPACT_SET_ETH_DST:
4270 case OFPACT_SET_IPV4_SRC:
4271 case OFPACT_SET_IPV4_DST:
4272 case OFPACT_SET_IP_DSCP:
4273 case OFPACT_SET_IP_ECN:
4274 case OFPACT_SET_IP_TTL:
4275 case OFPACT_SET_L4_SRC_PORT:
4276 case OFPACT_SET_L4_DST_PORT:
4277 case OFPACT_SET_QUEUE:
4278 case OFPACT_POP_QUEUE:
4279 case OFPACT_PUSH_MPLS:
4280 case OFPACT_POP_MPLS:
4281 case OFPACT_SET_MPLS_LABEL:
4282 case OFPACT_SET_MPLS_TC:
4283 case OFPACT_SET_MPLS_TTL:
4284 case OFPACT_MULTIPATH:
4287 case OFPACT_UNROLL_XLATE:
4288 case OFPACT_FIN_TIMEOUT:
4289 case OFPACT_CLEAR_ACTIONS:
4290 case OFPACT_WRITE_ACTIONS:
4293 case OFPACT_DEBUG_RECIRC:
4296 /* These may not generate PACKET INs. */
4300 case OFPACT_CONJUNCTION:
4301 /* These need not be copied for restoration. */
4304 /* Copy the action over. */
4305 ofpbuf_put(&ctx->frozen_actions, a, OFPACT_ALIGN(a->len));
4310 put_ct_mark(const struct flow *flow, struct ofpbuf *odp_actions,
4311 struct flow_wildcards *wc)
4313 if (wc->masks.ct_mark) {
4319 odp_ct_mark = nl_msg_put_unspec_uninit(odp_actions, OVS_CT_ATTR_MARK,
4320 sizeof(*odp_ct_mark));
4321 odp_ct_mark->key = flow->ct_mark & wc->masks.ct_mark;
4322 odp_ct_mark->mask = wc->masks.ct_mark;
4327 put_ct_label(const struct flow *flow, struct ofpbuf *odp_actions,
4328 struct flow_wildcards *wc)
4330 if (!ovs_u128_is_zero(wc->masks.ct_label)) {
4336 odp_ct_label = nl_msg_put_unspec_uninit(odp_actions,
4338 sizeof(*odp_ct_label));
4339 odp_ct_label->key = ovs_u128_and(flow->ct_label, wc->masks.ct_label);
4340 odp_ct_label->mask = wc->masks.ct_label;
4345 put_ct_helper(struct ofpbuf *odp_actions, struct ofpact_conntrack *ofc)
4348 if (ofc->alg == IPPORT_FTP) {
4349 nl_msg_put_string(odp_actions, OVS_CT_ATTR_HELPER, "ftp");
4351 VLOG_WARN("Cannot serialize ct_helper %d\n", ofc->alg);
4357 put_ct_nat(struct xlate_ctx *ctx)
4359 struct ofpact_nat *ofn = ctx->ct_nat_action;
4366 nat_offset = nl_msg_start_nested(ctx->odp_actions, OVS_CT_ATTR_NAT);
4367 if (ofn->flags & NX_NAT_F_SRC || ofn->flags & NX_NAT_F_DST) {
4368 nl_msg_put_flag(ctx->odp_actions, ofn->flags & NX_NAT_F_SRC
4369 ? OVS_NAT_ATTR_SRC : OVS_NAT_ATTR_DST);
4370 if (ofn->flags & NX_NAT_F_PERSISTENT) {
4371 nl_msg_put_flag(ctx->odp_actions, OVS_NAT_ATTR_PERSISTENT);
4373 if (ofn->flags & NX_NAT_F_PROTO_HASH) {
4374 nl_msg_put_flag(ctx->odp_actions, OVS_NAT_ATTR_PROTO_HASH);
4375 } else if (ofn->flags & NX_NAT_F_PROTO_RANDOM) {
4376 nl_msg_put_flag(ctx->odp_actions, OVS_NAT_ATTR_PROTO_RANDOM);
4378 if (ofn->range_af == AF_INET) {
4379 nl_msg_put_be32(ctx->odp_actions, OVS_NAT_ATTR_IP_MIN,
4380 ofn->range.addr.ipv4.min);
4381 if (ofn->range.addr.ipv4.max &&
4382 (ntohl(ofn->range.addr.ipv4.max)
4383 > ntohl(ofn->range.addr.ipv4.min))) {
4384 nl_msg_put_be32(ctx->odp_actions, OVS_NAT_ATTR_IP_MAX,
4385 ofn->range.addr.ipv4.max);
4387 } else if (ofn->range_af == AF_INET6) {
4388 nl_msg_put_unspec(ctx->odp_actions, OVS_NAT_ATTR_IP_MIN,
4389 &ofn->range.addr.ipv6.min,
4390 sizeof ofn->range.addr.ipv6.min);
4391 if (!ipv6_mask_is_any(&ofn->range.addr.ipv6.max) &&
4392 memcmp(&ofn->range.addr.ipv6.max, &ofn->range.addr.ipv6.min,
4393 sizeof ofn->range.addr.ipv6.max) > 0) {
4394 nl_msg_put_unspec(ctx->odp_actions, OVS_NAT_ATTR_IP_MAX,
4395 &ofn->range.addr.ipv6.max,
4396 sizeof ofn->range.addr.ipv6.max);
4399 if (ofn->range_af != AF_UNSPEC && ofn->range.proto.min) {
4400 nl_msg_put_u16(ctx->odp_actions, OVS_NAT_ATTR_PROTO_MIN,
4401 ofn->range.proto.min);
4402 if (ofn->range.proto.max &&
4403 ofn->range.proto.max > ofn->range.proto.min) {
4404 nl_msg_put_u16(ctx->odp_actions, OVS_NAT_ATTR_PROTO_MAX,
4405 ofn->range.proto.max);
4409 nl_msg_end_nested(ctx->odp_actions, nat_offset);
4413 compose_conntrack_action(struct xlate_ctx *ctx, struct ofpact_conntrack *ofc)
4415 ovs_u128 old_ct_label = ctx->base_flow.ct_label;
4416 ovs_u128 old_ct_label_mask = ctx->wc->masks.ct_label;
4417 uint32_t old_ct_mark = ctx->base_flow.ct_mark;
4418 uint32_t old_ct_mark_mask = ctx->wc->masks.ct_mark;
4422 /* Ensure that any prior actions are applied before composing the new
4423 * conntrack action. */
4424 xlate_commit_actions(ctx);
4426 /* Process nested actions first, to populate the key. */
4427 ctx->ct_nat_action = NULL;
4428 ctx->wc->masks.ct_mark = 0;
4429 ctx->wc->masks.ct_label.u64.hi = ctx->wc->masks.ct_label.u64.lo = 0;
4430 do_xlate_actions(ofc->actions, ofpact_ct_get_action_len(ofc), ctx);
4432 if (ofc->zone_src.field) {
4433 zone = mf_get_subfield(&ofc->zone_src, &ctx->xin->flow);
4435 zone = ofc->zone_imm;
4438 ct_offset = nl_msg_start_nested(ctx->odp_actions, OVS_ACTION_ATTR_CT);
4439 if (ofc->flags & NX_CT_F_COMMIT) {
4440 nl_msg_put_flag(ctx->odp_actions, OVS_CT_ATTR_COMMIT);
4442 nl_msg_put_u16(ctx->odp_actions, OVS_CT_ATTR_ZONE, zone);
4443 put_ct_mark(&ctx->xin->flow, ctx->odp_actions, ctx->wc);
4444 put_ct_label(&ctx->xin->flow, ctx->odp_actions, ctx->wc);
4445 put_ct_helper(ctx->odp_actions, ofc);
4447 ctx->ct_nat_action = NULL;
4448 nl_msg_end_nested(ctx->odp_actions, ct_offset);
4450 /* Restore the original ct fields in the key. These should only be exposed
4451 * after recirculation to another table. */
4452 ctx->base_flow.ct_mark = old_ct_mark;
4453 ctx->wc->masks.ct_mark = old_ct_mark_mask;
4454 ctx->base_flow.ct_label = old_ct_label;
4455 ctx->wc->masks.ct_label = old_ct_label_mask;
4457 if (ofc->recirc_table == NX_CT_RECIRC_NONE) {
4458 /* If we do not recirculate as part of this action, hide the results of
4459 * connection tracking from subsequent recirculations. */
4460 ctx->conntracked = false;
4462 /* Use ct_* fields from datapath during recirculation upcall. */
4463 ctx->conntracked = true;
4464 compose_recirculate_and_fork(ctx, ofc->recirc_table);
4469 do_xlate_actions(const struct ofpact *ofpacts, size_t ofpacts_len,
4470 struct xlate_ctx *ctx)
4472 struct flow_wildcards *wc = ctx->wc;
4473 struct flow *flow = &ctx->xin->flow;
4474 const struct ofpact *a;
4476 if (ovs_native_tunneling_is_on(ctx->xbridge->ofproto)) {
4477 tnl_neigh_snoop(flow, wc, ctx->xbridge->name);
4479 /* dl_type already in the mask, not set below. */
4481 OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
4482 struct ofpact_controller *controller;
4483 const struct ofpact_metadata *metadata;
4484 const struct ofpact_set_field *set_field;
4485 const struct mf_field *mf;
4492 /* Check if need to store the remaining actions for later
4494 if (ctx->freezing) {
4495 freeze_unroll_actions(a, ofpact_end(ofpacts, ofpacts_len),
4503 xlate_output_action(ctx, ofpact_get_OUTPUT(a)->port,
4504 ofpact_get_OUTPUT(a)->max_len, true);
4508 if (xlate_group_action(ctx, ofpact_get_GROUP(a)->group_id)) {
4509 /* Group could not be found. */
4514 case OFPACT_CONTROLLER:
4515 controller = ofpact_get_CONTROLLER(a);
4516 if (controller->pause) {
4517 ctx->pause = controller;
4518 ctx->xout->slow |= SLOW_CONTROLLER;
4519 ctx_trigger_freeze(ctx);
4522 execute_controller_action(ctx, controller->max_len,
4524 controller->controller_id,
4525 controller->userdata,
4526 controller->userdata_len);
4530 case OFPACT_ENQUEUE:
4531 memset(&wc->masks.skb_priority, 0xff,
4532 sizeof wc->masks.skb_priority);
4533 xlate_enqueue_action(ctx, ofpact_get_ENQUEUE(a));
4536 case OFPACT_SET_VLAN_VID:
4537 wc->masks.vlan_tci |= htons(VLAN_VID_MASK | VLAN_CFI);
4538 if (flow->vlan_tci & htons(VLAN_CFI) ||
4539 ofpact_get_SET_VLAN_VID(a)->push_vlan_if_needed) {
4540 flow->vlan_tci &= ~htons(VLAN_VID_MASK);
4541 flow->vlan_tci |= (htons(ofpact_get_SET_VLAN_VID(a)->vlan_vid)
4546 case OFPACT_SET_VLAN_PCP:
4547 wc->masks.vlan_tci |= htons(VLAN_PCP_MASK | VLAN_CFI);
4548 if (flow->vlan_tci & htons(VLAN_CFI) ||
4549 ofpact_get_SET_VLAN_PCP(a)->push_vlan_if_needed) {
4550 flow->vlan_tci &= ~htons(VLAN_PCP_MASK);
4551 flow->vlan_tci |= htons((ofpact_get_SET_VLAN_PCP(a)->vlan_pcp
4552 << VLAN_PCP_SHIFT) | VLAN_CFI);
4556 case OFPACT_STRIP_VLAN:
4557 memset(&wc->masks.vlan_tci, 0xff, sizeof wc->masks.vlan_tci);
4558 flow->vlan_tci = htons(0);
4561 case OFPACT_PUSH_VLAN:
4562 /* XXX 802.1AD(QinQ) */
4563 memset(&wc->masks.vlan_tci, 0xff, sizeof wc->masks.vlan_tci);
4564 flow->vlan_tci = htons(VLAN_CFI);
4567 case OFPACT_SET_ETH_SRC:
4568 WC_MASK_FIELD(wc, dl_src);
4569 flow->dl_src = ofpact_get_SET_ETH_SRC(a)->mac;
4572 case OFPACT_SET_ETH_DST:
4573 WC_MASK_FIELD(wc, dl_dst);
4574 flow->dl_dst = ofpact_get_SET_ETH_DST(a)->mac;
4577 case OFPACT_SET_IPV4_SRC:
4578 if (flow->dl_type == htons(ETH_TYPE_IP)) {
4579 memset(&wc->masks.nw_src, 0xff, sizeof wc->masks.nw_src);
4580 flow->nw_src = ofpact_get_SET_IPV4_SRC(a)->ipv4;
4584 case OFPACT_SET_IPV4_DST:
4585 if (flow->dl_type == htons(ETH_TYPE_IP)) {
4586 memset(&wc->masks.nw_dst, 0xff, sizeof wc->masks.nw_dst);
4587 flow->nw_dst = ofpact_get_SET_IPV4_DST(a)->ipv4;
4591 case OFPACT_SET_IP_DSCP:
4592 if (is_ip_any(flow)) {
4593 wc->masks.nw_tos |= IP_DSCP_MASK;
4594 flow->nw_tos &= ~IP_DSCP_MASK;
4595 flow->nw_tos |= ofpact_get_SET_IP_DSCP(a)->dscp;
4599 case OFPACT_SET_IP_ECN:
4600 if (is_ip_any(flow)) {
4601 wc->masks.nw_tos |= IP_ECN_MASK;
4602 flow->nw_tos &= ~IP_ECN_MASK;
4603 flow->nw_tos |= ofpact_get_SET_IP_ECN(a)->ecn;
4607 case OFPACT_SET_IP_TTL:
4608 if (is_ip_any(flow)) {
4609 wc->masks.nw_ttl = 0xff;
4610 flow->nw_ttl = ofpact_get_SET_IP_TTL(a)->ttl;
4614 case OFPACT_SET_L4_SRC_PORT:
4615 if (is_ip_any(flow) && !(flow->nw_frag & FLOW_NW_FRAG_LATER)) {
4616 memset(&wc->masks.nw_proto, 0xff, sizeof wc->masks.nw_proto);
4617 memset(&wc->masks.tp_src, 0xff, sizeof wc->masks.tp_src);
4618 flow->tp_src = htons(ofpact_get_SET_L4_SRC_PORT(a)->port);
4622 case OFPACT_SET_L4_DST_PORT:
4623 if (is_ip_any(flow) && !(flow->nw_frag & FLOW_NW_FRAG_LATER)) {
4624 memset(&wc->masks.nw_proto, 0xff, sizeof wc->masks.nw_proto);
4625 memset(&wc->masks.tp_dst, 0xff, sizeof wc->masks.tp_dst);
4626 flow->tp_dst = htons(ofpact_get_SET_L4_DST_PORT(a)->port);
4630 case OFPACT_RESUBMIT:
4631 /* Freezing complicates resubmit. Some action in the flow
4632 * entry found by resubmit might trigger freezing. If that
4633 * happens, then we do not want to execute the resubmit again after
4634 * during thawing, so we want to skip back to the head of the loop
4635 * to avoid that, only adding any actions that follow the resubmit
4636 * to the frozen actions.
4638 xlate_ofpact_resubmit(ctx, ofpact_get_RESUBMIT(a));
4641 case OFPACT_SET_TUNNEL:
4642 flow->tunnel.tun_id = htonll(ofpact_get_SET_TUNNEL(a)->tun_id);
4645 case OFPACT_SET_QUEUE:
4646 memset(&wc->masks.skb_priority, 0xff,
4647 sizeof wc->masks.skb_priority);
4648 xlate_set_queue_action(ctx, ofpact_get_SET_QUEUE(a)->queue_id);
4651 case OFPACT_POP_QUEUE:
4652 memset(&wc->masks.skb_priority, 0xff,
4653 sizeof wc->masks.skb_priority);
4654 flow->skb_priority = ctx->orig_skb_priority;
4657 case OFPACT_REG_MOVE:
4658 nxm_execute_reg_move(ofpact_get_REG_MOVE(a), flow, wc);
4661 case OFPACT_SET_FIELD:
4662 set_field = ofpact_get_SET_FIELD(a);
4663 mf = set_field->field;
4665 /* Set field action only ever overwrites packet's outermost
4666 * applicable header fields. Do nothing if no header exists. */
4667 if (mf->id == MFF_VLAN_VID) {
4668 wc->masks.vlan_tci |= htons(VLAN_CFI);
4669 if (!(flow->vlan_tci & htons(VLAN_CFI))) {
4672 } else if ((mf->id == MFF_MPLS_LABEL || mf->id == MFF_MPLS_TC)
4673 /* 'dl_type' is already unwildcarded. */
4674 && !eth_type_mpls(flow->dl_type)) {
4677 /* A flow may wildcard nw_frag. Do nothing if setting a transport
4678 * header field on a packet that does not have them. */
4679 mf_mask_field_and_prereqs__(mf, &set_field->mask, wc);
4680 if (mf_are_prereqs_ok(mf, flow)) {
4681 mf_set_flow_value_masked(mf, &set_field->value,
4682 &set_field->mask, flow);
4686 case OFPACT_STACK_PUSH:
4687 nxm_execute_stack_push(ofpact_get_STACK_PUSH(a), flow, wc,
4691 case OFPACT_STACK_POP:
4692 nxm_execute_stack_pop(ofpact_get_STACK_POP(a), flow, wc,
4696 case OFPACT_PUSH_MPLS:
4697 compose_mpls_push_action(ctx, ofpact_get_PUSH_MPLS(a));
4700 case OFPACT_POP_MPLS:
4701 compose_mpls_pop_action(ctx, ofpact_get_POP_MPLS(a)->ethertype);
4704 case OFPACT_SET_MPLS_LABEL:
4705 compose_set_mpls_label_action(
4706 ctx, ofpact_get_SET_MPLS_LABEL(a)->label);
4709 case OFPACT_SET_MPLS_TC:
4710 compose_set_mpls_tc_action(ctx, ofpact_get_SET_MPLS_TC(a)->tc);
4713 case OFPACT_SET_MPLS_TTL:
4714 compose_set_mpls_ttl_action(ctx, ofpact_get_SET_MPLS_TTL(a)->ttl);
4717 case OFPACT_DEC_MPLS_TTL:
4718 if (compose_dec_mpls_ttl_action(ctx)) {
4723 case OFPACT_DEC_TTL:
4724 wc->masks.nw_ttl = 0xff;
4725 if (compose_dec_ttl(ctx, ofpact_get_DEC_TTL(a))) {
4731 /* Nothing to do. */
4734 case OFPACT_MULTIPATH:
4735 multipath_execute(ofpact_get_MULTIPATH(a), flow, wc);
4739 xlate_bundle_action(ctx, ofpact_get_BUNDLE(a));
4742 case OFPACT_OUTPUT_REG:
4743 xlate_output_reg_action(ctx, ofpact_get_OUTPUT_REG(a));
4747 xlate_learn_action(ctx, ofpact_get_LEARN(a));
4750 case OFPACT_CONJUNCTION: {
4751 /* A flow with a "conjunction" action represents part of a special
4752 * kind of "set membership match". Such a flow should not actually
4753 * get executed, but it could via, say, a "packet-out", even though
4754 * that wouldn't be useful. Log it to help debugging. */
4755 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
4756 VLOG_INFO_RL(&rl, "executing no-op conjunction action");
4764 case OFPACT_UNROLL_XLATE: {
4765 struct ofpact_unroll_xlate *unroll = ofpact_get_UNROLL_XLATE(a);
4767 /* Restore translation context data that was stored earlier. */
4768 ctx->table_id = unroll->rule_table_id;
4769 ctx->rule_cookie = unroll->rule_cookie;
4772 case OFPACT_FIN_TIMEOUT:
4773 memset(&wc->masks.nw_proto, 0xff, sizeof wc->masks.nw_proto);
4774 xlate_fin_timeout(ctx, ofpact_get_FIN_TIMEOUT(a));
4777 case OFPACT_CLEAR_ACTIONS:
4778 ofpbuf_clear(&ctx->action_set);
4779 ctx->xin->flow.actset_output = OFPP_UNSET;
4780 ctx->action_set_has_group = false;
4783 case OFPACT_WRITE_ACTIONS:
4784 xlate_write_actions(ctx, ofpact_get_WRITE_ACTIONS(a));
4787 case OFPACT_WRITE_METADATA:
4788 metadata = ofpact_get_WRITE_METADATA(a);
4789 flow->metadata &= ~metadata->mask;
4790 flow->metadata |= metadata->metadata & metadata->mask;
4794 /* Not implemented yet. */
4797 case OFPACT_GOTO_TABLE: {
4798 struct ofpact_goto_table *ogt = ofpact_get_GOTO_TABLE(a);
4800 ovs_assert(ctx->table_id < ogt->table_id);
4802 xlate_table_action(ctx, ctx->xin->flow.in_port.ofp_port,
4803 ogt->table_id, true, true);
4808 xlate_sample_action(ctx, ofpact_get_SAMPLE(a));
4812 compose_conntrack_action(ctx, ofpact_get_CT(a));
4816 /* This will be processed by compose_conntrack_action(). */
4817 ctx->ct_nat_action = ofpact_get_NAT(a);
4820 case OFPACT_DEBUG_RECIRC:
4821 ctx_trigger_freeze(ctx);
4826 /* Check if need to store this and the remaining actions for later
4828 if (!ctx->error && ctx->exit && ctx_first_frozen_action(ctx)) {
4829 freeze_unroll_actions(a, ofpact_end(ofpacts, ofpacts_len), ctx);
4836 xlate_in_init(struct xlate_in *xin, struct ofproto_dpif *ofproto,
4837 const struct flow *flow, ofp_port_t in_port,
4838 struct rule_dpif *rule, uint16_t tcp_flags,
4839 const struct dp_packet *packet, struct flow_wildcards *wc,
4840 struct ofpbuf *odp_actions)
4842 xin->ofproto = ofproto;
4844 xin->flow.in_port.ofp_port = in_port;
4845 xin->flow.actset_output = OFPP_UNSET;
4846 xin->packet = packet;
4847 xin->may_learn = packet != NULL;
4850 xin->ofpacts = NULL;
4851 xin->ofpacts_len = 0;
4852 xin->tcp_flags = tcp_flags;
4853 xin->resubmit_hook = NULL;
4854 xin->report_hook = NULL;
4855 xin->resubmit_stats = NULL;
4856 xin->indentation = 0;
4860 xin->odp_actions = odp_actions;
4862 /* Do recirc lookup. */
4863 xin->frozen_state = NULL;
4864 if (flow->recirc_id) {
4865 const struct recirc_id_node *node
4866 = recirc_id_node_find(flow->recirc_id);
4868 xin->frozen_state = &node->state;
4874 xlate_out_uninit(struct xlate_out *xout)
4877 recirc_refs_unref(&xout->recircs);
4881 /* Translates the 'ofpacts_len' bytes of "struct ofpact"s starting at 'ofpacts'
4882 * into datapath actions, using 'ctx', and discards the datapath actions. */
4884 xlate_actions_for_side_effects(struct xlate_in *xin)
4886 struct xlate_out xout;
4887 enum xlate_error error;
4889 error = xlate_actions(xin, &xout);
4891 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
4893 VLOG_WARN_RL(&rl, "xlate_actions failed (%s)!", xlate_strerror(error));
4896 xlate_out_uninit(&xout);
4899 static struct skb_priority_to_dscp *
4900 get_skb_priority(const struct xport *xport, uint32_t skb_priority)
4902 struct skb_priority_to_dscp *pdscp;
4905 hash = hash_int(skb_priority, 0);
4906 HMAP_FOR_EACH_IN_BUCKET (pdscp, hmap_node, hash, &xport->skb_priorities) {
4907 if (pdscp->skb_priority == skb_priority) {
4915 dscp_from_skb_priority(const struct xport *xport, uint32_t skb_priority,
4918 struct skb_priority_to_dscp *pdscp = get_skb_priority(xport, skb_priority);
4919 *dscp = pdscp ? pdscp->dscp : 0;
4920 return pdscp != NULL;
4924 count_skb_priorities(const struct xport *xport)
4926 return hmap_count(&xport->skb_priorities);
4930 clear_skb_priorities(struct xport *xport)
4932 struct skb_priority_to_dscp *pdscp;
4934 HMAP_FOR_EACH_POP (pdscp, hmap_node, &xport->skb_priorities) {
4940 actions_output_to_local_port(const struct xlate_ctx *ctx)
4942 odp_port_t local_odp_port = ofp_port_to_odp_port(ctx->xbridge, OFPP_LOCAL);
4943 const struct nlattr *a;
4946 NL_ATTR_FOR_EACH_UNSAFE (a, left, ctx->odp_actions->data,
4947 ctx->odp_actions->size) {
4948 if (nl_attr_type(a) == OVS_ACTION_ATTR_OUTPUT
4949 && nl_attr_get_odp_port(a) == local_odp_port) {
4956 #if defined(__linux__)
4957 /* Returns the maximum number of packets that the Linux kernel is willing to
4958 * queue up internally to certain kinds of software-implemented ports, or the
4959 * default (and rarely modified) value if it cannot be determined. */
4961 netdev_max_backlog(void)
4963 static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
4964 static int max_backlog = 1000; /* The normal default value. */
4966 if (ovsthread_once_start(&once)) {
4967 static const char filename[] = "/proc/sys/net/core/netdev_max_backlog";
4971 stream = fopen(filename, "r");
4973 VLOG_INFO("%s: open failed (%s)", filename, ovs_strerror(errno));
4975 if (fscanf(stream, "%d", &n) != 1) {
4976 VLOG_WARN("%s: read error", filename);
4977 } else if (n <= 100) {
4978 VLOG_WARN("%s: unexpectedly small value %d", filename, n);
4984 ovsthread_once_done(&once);
4986 VLOG_DBG("%s: using %d max_backlog", filename, max_backlog);
4992 /* Counts and returns the number of OVS_ACTION_ATTR_OUTPUT actions in
4995 count_output_actions(const struct ofpbuf *odp_actions)
4997 const struct nlattr *a;
5001 NL_ATTR_FOR_EACH_UNSAFE (a, left, odp_actions->data, odp_actions->size) {
5002 if (a->nla_type == OVS_ACTION_ATTR_OUTPUT) {
5008 #endif /* defined(__linux__) */
5010 /* Returns true if 'odp_actions' contains more output actions than the datapath
5011 * can reliably handle in one go. On Linux, this is the value of the
5012 * net.core.netdev_max_backlog sysctl, which limits the maximum number of
5013 * packets that the kernel is willing to queue up for processing while the
5014 * datapath is processing a set of actions. */
5016 too_many_output_actions(const struct ofpbuf *odp_actions OVS_UNUSED)
5019 return (odp_actions->size / NL_A_U32_SIZE > netdev_max_backlog()
5020 && count_output_actions(odp_actions) > netdev_max_backlog());
5022 /* OSes other than Linux might have similar limits, but we don't know how
5023 * to determine them.*/
5029 xlate_wc_init(struct xlate_ctx *ctx)
5031 flow_wildcards_init_catchall(ctx->wc);
5033 /* Some fields we consider to always be examined. */
5034 WC_MASK_FIELD(ctx->wc, in_port);
5035 WC_MASK_FIELD(ctx->wc, dl_type);
5036 if (is_ip_any(&ctx->xin->flow)) {
5037 WC_MASK_FIELD_MASK(ctx->wc, nw_frag, FLOW_NW_FRAG_MASK);
5040 if (ctx->xbridge->support.odp.recirc) {
5041 /* Always exactly match recirc_id when datapath supports
5043 WC_MASK_FIELD(ctx->wc, recirc_id);
5046 if (ctx->xbridge->netflow) {
5047 netflow_mask_wc(&ctx->xin->flow, ctx->wc);
5050 tnl_wc_init(&ctx->xin->flow, ctx->wc);
5054 xlate_wc_finish(struct xlate_ctx *ctx)
5056 /* Clear the metadata and register wildcard masks, because we won't
5057 * use non-header fields as part of the cache. */
5058 flow_wildcards_clear_non_packet_fields(ctx->wc);
5060 /* ICMPv4 and ICMPv6 have 8-bit "type" and "code" fields. struct flow
5061 * uses the low 8 bits of the 16-bit tp_src and tp_dst members to
5062 * represent these fields. The datapath interface, on the other hand,
5063 * represents them with just 8 bits each. This means that if the high
5064 * 8 bits of the masks for these fields somehow become set, then they
5065 * will get chopped off by a round trip through the datapath, and
5066 * revalidation will spot that as an inconsistency and delete the flow.
5067 * Avoid the problem here by making sure that only the low 8 bits of
5068 * either field can be unwildcarded for ICMP.
5070 if (is_icmpv4(&ctx->xin->flow) || is_icmpv6(&ctx->xin->flow)) {
5071 ctx->wc->masks.tp_src &= htons(UINT8_MAX);
5072 ctx->wc->masks.tp_dst &= htons(UINT8_MAX);
5074 /* VLAN_TCI CFI bit must be matched if any of the TCI is matched. */
5075 if (ctx->wc->masks.vlan_tci) {
5076 ctx->wc->masks.vlan_tci |= htons(VLAN_CFI);
5080 /* Translates the flow, actions, or rule in 'xin' into datapath actions in
5082 * The caller must take responsibility for eventually freeing 'xout', with
5083 * xlate_out_uninit().
5084 * Returns 'XLATE_OK' if translation was successful. In case of an error an
5085 * empty set of actions will be returned in 'xin->odp_actions' (if non-NULL),
5086 * so that most callers may ignore the return value and transparently install a
5087 * drop flow when the translation fails. */
5089 xlate_actions(struct xlate_in *xin, struct xlate_out *xout)
5091 *xout = (struct xlate_out) {
5093 .recircs = RECIRC_REFS_EMPTY_INITIALIZER,
5096 struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
5097 struct xbridge *xbridge = xbridge_lookup(xcfg, xin->ofproto);
5099 return XLATE_BRIDGE_NOT_FOUND;
5102 struct flow *flow = &xin->flow;
5104 union mf_subvalue stack_stub[1024 / sizeof(union mf_subvalue)];
5105 uint64_t action_set_stub[1024 / 8];
5106 uint64_t frozen_actions_stub[1024 / 8];
5107 struct flow_wildcards scratch_wc;
5108 uint64_t actions_stub[256 / 8];
5109 struct ofpbuf scratch_actions = OFPBUF_STUB_INITIALIZER(actions_stub);
5110 struct xlate_ctx ctx = {
5114 .orig_tunnel_ipv6_dst = flow_tnl_dst(&flow->tunnel),
5116 .stack = OFPBUF_STUB_INITIALIZER(stack_stub),
5118 .wc = xin->wc ? xin->wc : &scratch_wc,
5119 .odp_actions = xin->odp_actions ? xin->odp_actions : &scratch_actions,
5121 .indentation = xin->indentation,
5122 .depth = xin->depth,
5123 .resubmits = xin->resubmits,
5125 .in_action_set = false,
5128 .rule_cookie = OVS_BE64_MAX,
5129 .orig_skb_priority = flow->skb_priority,
5130 .sflow_n_outputs = 0,
5131 .sflow_odp_port = 0,
5132 .nf_output_iface = NF_OUT_DROP,
5138 .frozen_actions = OFPBUF_STUB_INITIALIZER(frozen_actions_stub),
5141 .conntracked = false,
5143 .ct_nat_action = NULL,
5145 .action_set_has_group = false,
5146 .action_set = OFPBUF_STUB_INITIALIZER(action_set_stub),
5149 /* 'base_flow' reflects the packet as it came in, but we need it to reflect
5150 * the packet as the datapath will treat it for output actions. Our
5151 * datapath doesn't retain tunneling information without us re-setting
5152 * it, so clear the tunnel data.
5155 memset(&ctx.base_flow.tunnel, 0, sizeof ctx.base_flow.tunnel);
5157 ofpbuf_reserve(ctx.odp_actions, NL_A_U32_SIZE);
5159 xlate_wc_init(&ctx);
5162 COVERAGE_INC(xlate_actions);
5164 if (xin->frozen_state) {
5165 const struct frozen_state *state = xin->frozen_state;
5167 xlate_report(&ctx, "Thawing frozen state:");
5169 if (xin->ofpacts_len > 0 || ctx.rule) {
5170 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
5171 const char *conflict = xin->ofpacts_len ? "actions" : "rule";
5173 VLOG_WARN_RL(&rl, "Recirculation conflict (%s)!", conflict);
5174 xlate_report(&ctx, "- Recirculation conflict (%s)!", conflict);
5175 ctx.error = XLATE_RECIRCULATION_CONFLICT;
5179 /* Set the bridge for post-recirculation processing if needed. */
5180 if (!uuid_equals(ofproto_dpif_get_uuid(ctx.xbridge->ofproto),
5181 &state->ofproto_uuid)) {
5182 struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
5183 const struct xbridge *new_bridge
5184 = xbridge_lookup_by_uuid(xcfg, &state->ofproto_uuid);
5186 if (OVS_UNLIKELY(!new_bridge)) {
5187 /* Drop the packet if the bridge cannot be found. */
5188 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
5189 VLOG_WARN_RL(&rl, "Frozen bridge no longer exists.");
5190 xlate_report(&ctx, "- Frozen bridge no longer exists.");
5191 ctx.error = XLATE_BRIDGE_NOT_FOUND;
5194 ctx.xbridge = new_bridge;
5197 /* Set the thawed table id. Note: A table lookup is done only if there
5198 * are no frozen actions. */
5199 ctx.table_id = state->table_id;
5200 xlate_report(&ctx, "- Resuming from table %"PRIu8, ctx.table_id);
5202 if (!state->conntracked) {
5203 clear_conntrack(flow);
5206 /* Restore pipeline metadata. May change flow's in_port and other
5207 * metadata to the values that existed when freezing was triggered. */
5208 frozen_metadata_to_flow(&state->metadata, flow);
5210 /* Restore stack, if any. */
5212 ofpbuf_put(&ctx.stack, state->stack,
5213 state->n_stack * sizeof *state->stack);
5216 /* Restore mirror state. */
5217 ctx.mirrors = state->mirrors;
5219 /* Restore action set, if any. */
5220 if (state->action_set_len) {
5221 xlate_report_actions(&ctx, "- Restoring action set",
5222 state->action_set, state->action_set_len);
5224 flow->actset_output = OFPP_UNSET;
5225 xlate_write_actions__(&ctx, state->action_set,
5226 state->action_set_len);
5229 /* Restore frozen actions. If there are no actions, processing will
5230 * start with a lookup in the table set above. */
5231 xin->ofpacts = state->ofpacts;
5232 xin->ofpacts_len = state->ofpacts_len;
5233 if (state->ofpacts_len) {
5234 xlate_report_actions(&ctx, "- Restoring actions",
5235 xin->ofpacts, xin->ofpacts_len);
5237 } else if (OVS_UNLIKELY(flow->recirc_id)) {
5238 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
5240 VLOG_WARN_RL(&rl, "Recirculation context not found for ID %"PRIx32,
5242 ctx.error = XLATE_NO_RECIRCULATION_CONTEXT;
5245 /* The bridge is now known so obtain its table version. */
5246 ctx.tables_version = ofproto_dpif_get_tables_version(ctx.xbridge->ofproto);
5248 if (!xin->ofpacts && !ctx.rule) {
5249 ctx.rule = rule_dpif_lookup_from_table(
5250 ctx.xbridge->ofproto, ctx.tables_version, flow, xin->wc,
5251 ctx.xin->resubmit_stats, &ctx.table_id,
5252 flow->in_port.ofp_port, true, true);
5253 if (ctx.xin->resubmit_stats) {
5254 rule_dpif_credit_stats(ctx.rule, ctx.xin->resubmit_stats);
5256 if (ctx.xin->xcache) {
5257 struct xc_entry *entry;
5259 entry = xlate_cache_add_entry(ctx.xin->xcache, XC_RULE);
5260 entry->u.rule = ctx.rule;
5261 rule_dpif_ref(ctx.rule);
5264 if (OVS_UNLIKELY(ctx.xin->resubmit_hook)) {
5265 ctx.xin->resubmit_hook(ctx.xin, ctx.rule, 0);
5269 /* Get the proximate input port of the packet. (If xin->frozen_state,
5270 * flow->in_port is the ultimate input port of the packet.) */
5271 struct xport *in_port = get_ofp_port(xbridge,
5272 ctx.base_flow.in_port.ofp_port);
5274 /* Tunnel stats only for not-thawed packets. */
5275 if (!xin->frozen_state && in_port && in_port->is_tunnel) {
5276 if (ctx.xin->resubmit_stats) {
5277 netdev_vport_inc_rx(in_port->netdev, ctx.xin->resubmit_stats);
5279 bfd_account_rx(in_port->bfd, ctx.xin->resubmit_stats);
5282 if (ctx.xin->xcache) {
5283 struct xc_entry *entry;
5285 entry = xlate_cache_add_entry(ctx.xin->xcache, XC_NETDEV);
5286 entry->u.dev.rx = netdev_ref(in_port->netdev);
5287 entry->u.dev.bfd = bfd_ref(in_port->bfd);
5291 if (!xin->frozen_state && process_special(&ctx, in_port)) {
5292 /* process_special() did all the processing for this packet.
5294 * We do not perform special processing on thawed packets, since that
5295 * was done before they were frozen and should not be redone. */
5296 } else if (in_port && in_port->xbundle
5297 && xbundle_mirror_out(xbridge, in_port->xbundle)) {
5298 if (ctx.xin->packet != NULL) {
5299 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
5300 VLOG_WARN_RL(&rl, "bridge %s: dropping packet received on port "
5301 "%s, which is reserved exclusively for mirroring",
5302 ctx.xbridge->name, in_port->xbundle->name);
5305 /* Sampling is done on initial reception; don't redo after thawing. */
5306 unsigned int user_cookie_offset = 0;
5307 if (!xin->frozen_state) {
5308 user_cookie_offset = compose_sflow_action(&ctx);
5309 compose_ipfix_action(&ctx, ODPP_NONE);
5311 size_t sample_actions_len = ctx.odp_actions->size;
5313 if (tnl_process_ecn(flow)
5314 && (!in_port || may_receive(in_port, &ctx))) {
5315 const struct ofpact *ofpacts;
5319 ofpacts = xin->ofpacts;
5320 ofpacts_len = xin->ofpacts_len;
5321 } else if (ctx.rule) {
5322 const struct rule_actions *actions
5323 = rule_dpif_get_actions(ctx.rule);
5324 ofpacts = actions->ofpacts;
5325 ofpacts_len = actions->ofpacts_len;
5326 ctx.rule_cookie = rule_dpif_get_flow_cookie(ctx.rule);
5331 mirror_ingress_packet(&ctx);
5332 do_xlate_actions(ofpacts, ofpacts_len, &ctx);
5337 /* We've let OFPP_NORMAL and the learning action look at the
5338 * packet, so cancel all actions and freezing if forwarding is
5340 if (in_port && (!xport_stp_forward_state(in_port) ||
5341 !xport_rstp_forward_state(in_port))) {
5342 ctx.odp_actions->size = sample_actions_len;
5343 ctx_cancel_freeze(&ctx);
5344 ofpbuf_clear(&ctx.action_set);
5347 if (!ctx.freezing) {
5348 xlate_action_set(&ctx);
5351 finish_freezing(&ctx);
5355 /* Output only fully processed packets. */
5357 && xbridge->has_in_band
5358 && in_band_must_output_to_local_port(flow)
5359 && !actions_output_to_local_port(&ctx)) {
5360 compose_output_action(&ctx, OFPP_LOCAL, NULL);
5363 if (user_cookie_offset) {
5364 fix_sflow_action(&ctx, user_cookie_offset);
5368 if (nl_attr_oversized(ctx.odp_actions->size)) {
5369 /* These datapath actions are too big for a Netlink attribute, so we
5370 * can't hand them to the kernel directly. dpif_execute() can execute
5371 * them one by one with help, so just mark the result as SLOW_ACTION to
5372 * prevent the flow from being installed. */
5373 COVERAGE_INC(xlate_actions_oversize);
5374 ctx.xout->slow |= SLOW_ACTION;
5375 } else if (too_many_output_actions(ctx.odp_actions)) {
5376 COVERAGE_INC(xlate_actions_too_many_output);
5377 ctx.xout->slow |= SLOW_ACTION;
5380 /* Do netflow only for packets on initial reception, that are not sent to
5381 * the controller. We consider packets sent to the controller to be part
5382 * of the control plane rather than the data plane. */
5383 if (!xin->frozen_state
5385 && !(xout->slow & SLOW_CONTROLLER)) {
5386 if (ctx.xin->resubmit_stats) {
5387 netflow_flow_update(xbridge->netflow, flow,
5388 ctx.nf_output_iface,
5389 ctx.xin->resubmit_stats);
5391 if (ctx.xin->xcache) {
5392 struct xc_entry *entry;
5394 entry = xlate_cache_add_entry(ctx.xin->xcache, XC_NETFLOW);
5395 entry->u.nf.netflow = netflow_ref(xbridge->netflow);
5396 entry->u.nf.flow = xmemdup(flow, sizeof *flow);
5397 entry->u.nf.iface = ctx.nf_output_iface;
5402 xlate_wc_finish(&ctx);
5406 ofpbuf_uninit(&ctx.stack);
5407 ofpbuf_uninit(&ctx.action_set);
5408 ofpbuf_uninit(&ctx.frozen_actions);
5409 ofpbuf_uninit(&scratch_actions);
5411 /* Make sure we return a "drop flow" in case of an error. */
5414 if (xin->odp_actions) {
5415 ofpbuf_clear(xin->odp_actions);
5422 xlate_resume(struct ofproto_dpif *ofproto,
5423 const struct ofputil_packet_in_private *pin,
5424 struct ofpbuf *odp_actions,
5425 enum slow_path_reason *slow)
5427 struct dp_packet packet;
5428 dp_packet_use_const(&packet, pin->public.packet,
5429 pin->public.packet_len);
5432 flow_extract(&packet, &flow);
5434 struct xlate_in xin;
5435 xlate_in_init(&xin, ofproto, &flow, 0, NULL, ntohs(flow.tcp_flags),
5436 &packet, NULL, odp_actions);
5438 struct ofpact_note noop;
5439 ofpact_init_NOTE(&noop);
5442 bool any_actions = pin->actions_len > 0;
5443 struct frozen_state state = {
5444 .table_id = 0, /* Not the table where NXAST_PAUSE was executed. */
5445 .ofproto_uuid = pin->bridge,
5446 .stack = pin->stack,
5447 .n_stack = pin->n_stack,
5448 .mirrors = pin->mirrors,
5449 .conntracked = pin->conntracked,
5451 /* When there are no actions, xlate_actions() will search the flow
5452 * table. We don't want it to do that (we want it to resume), so
5453 * supply a no-op action if there aren't any.
5455 * (We can't necessarily avoid translating actions entirely if there
5456 * aren't any actions, because there might be some finishing-up to do
5457 * at the end of the pipeline, and we don't check for those
5459 .ofpacts = any_actions ? pin->actions : &noop.ofpact,
5460 .ofpacts_len = any_actions ? pin->actions_len : sizeof noop,
5462 .action_set = pin->action_set,
5463 .action_set_len = pin->action_set_len,
5465 frozen_metadata_from_flow(&state.metadata,
5466 &pin->public.flow_metadata.flow);
5467 xin.frozen_state = &state;
5469 struct xlate_out xout;
5470 enum xlate_error error = xlate_actions(&xin, &xout);
5472 xlate_out_uninit(&xout);
5474 /* xlate_actions() can generate a number of errors, but only
5475 * XLATE_BRIDGE_NOT_FOUND really stands out to me as one that we should be
5476 * sure to report over OpenFlow. The others could come up in packet-outs
5477 * or regular flow translation and I don't think that it's going to be too
5478 * useful to report them to the controller. */
5479 return error == XLATE_BRIDGE_NOT_FOUND ? OFPERR_NXR_STALE : 0;
5482 /* Sends 'packet' out 'ofport'.
5483 * May modify 'packet'.
5484 * Returns 0 if successful, otherwise a positive errno value. */
5486 xlate_send_packet(const struct ofport_dpif *ofport, struct dp_packet *packet)
5488 struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
5489 struct xport *xport;
5490 struct ofpact_output output;
5493 ofpact_init(&output.ofpact, OFPACT_OUTPUT, sizeof output);
5494 /* Use OFPP_NONE as the in_port to avoid special packet processing. */
5495 flow_extract(packet, &flow);
5496 flow.in_port.ofp_port = OFPP_NONE;
5498 xport = xport_lookup(xcfg, ofport);
5502 output.port = xport->ofp_port;
5505 return ofproto_dpif_execute_actions(xport->xbridge->ofproto, &flow, NULL,
5506 &output.ofpact, sizeof output,
5510 struct xlate_cache *
5511 xlate_cache_new(void)
5513 struct xlate_cache *xcache = xmalloc(sizeof *xcache);
5515 ofpbuf_init(&xcache->entries, 512);
5519 static struct xc_entry *
5520 xlate_cache_add_entry(struct xlate_cache *xcache, enum xc_type type)
5522 struct xc_entry *entry;
5524 entry = ofpbuf_put_zeros(&xcache->entries, sizeof *entry);
5531 xlate_cache_netdev(struct xc_entry *entry, const struct dpif_flow_stats *stats)
5533 if (entry->u.dev.tx) {
5534 netdev_vport_inc_tx(entry->u.dev.tx, stats);
5536 if (entry->u.dev.rx) {
5537 netdev_vport_inc_rx(entry->u.dev.rx, stats);
5539 if (entry->u.dev.bfd) {
5540 bfd_account_rx(entry->u.dev.bfd, stats);
5545 xlate_cache_normal(struct ofproto_dpif *ofproto, struct flow *flow, int vlan)
5547 struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
5548 struct xbridge *xbridge;
5549 struct xbundle *xbundle;
5550 struct flow_wildcards wc;
5552 xbridge = xbridge_lookup(xcfg, ofproto);
5557 xbundle = lookup_input_bundle(xbridge, flow->in_port.ofp_port, false,
5563 update_learning_table(xbridge, flow, &wc, vlan, xbundle);
5566 /* Push stats and perform side effects of flow translation. */
5568 xlate_push_stats(struct xlate_cache *xcache,
5569 const struct dpif_flow_stats *stats)
5571 struct xc_entry *entry;
5572 struct ofpbuf entries = xcache->entries;
5573 struct eth_addr dmac;
5575 if (!stats->n_packets) {
5579 XC_ENTRY_FOR_EACH (entry, entries, xcache) {
5580 switch (entry->type) {
5582 rule_dpif_credit_stats(entry->u.rule, stats);
5585 bond_account(entry->u.bond.bond, entry->u.bond.flow,
5586 entry->u.bond.vid, stats->n_bytes);
5589 xlate_cache_netdev(entry, stats);
5592 netflow_flow_update(entry->u.nf.netflow, entry->u.nf.flow,
5593 entry->u.nf.iface, stats);
5596 mirror_update_stats(entry->u.mirror.mbridge,
5597 entry->u.mirror.mirrors,
5598 stats->n_packets, stats->n_bytes);
5601 ofproto_dpif_flow_mod(entry->u.learn.ofproto, entry->u.learn.fm);
5604 xlate_cache_normal(entry->u.normal.ofproto, entry->u.normal.flow,
5605 entry->u.normal.vlan);
5607 case XC_FIN_TIMEOUT:
5608 xlate_fin_timeout__(entry->u.fin.rule, stats->tcp_flags,
5609 entry->u.fin.idle, entry->u.fin.hard);
5612 group_dpif_credit_stats(entry->u.group.group, entry->u.group.bucket,
5616 /* Lookup neighbor to avoid timeout. */
5617 tnl_neigh_lookup(entry->u.tnl_neigh_cache.br_name,
5618 &entry->u.tnl_neigh_cache.d_ipv6, &dmac);
5627 xlate_dev_unref(struct xc_entry *entry)
5629 if (entry->u.dev.tx) {
5630 netdev_close(entry->u.dev.tx);
5632 if (entry->u.dev.rx) {
5633 netdev_close(entry->u.dev.rx);
5635 if (entry->u.dev.bfd) {
5636 bfd_unref(entry->u.dev.bfd);
5641 xlate_cache_clear_netflow(struct netflow *netflow, struct flow *flow)
5643 netflow_flow_clear(netflow, flow);
5644 netflow_unref(netflow);
5649 xlate_cache_clear(struct xlate_cache *xcache)
5651 struct xc_entry *entry;
5652 struct ofpbuf entries;
5658 XC_ENTRY_FOR_EACH (entry, entries, xcache) {
5659 switch (entry->type) {
5661 rule_dpif_unref(entry->u.rule);
5664 free(entry->u.bond.flow);
5665 bond_unref(entry->u.bond.bond);
5668 xlate_dev_unref(entry);
5671 xlate_cache_clear_netflow(entry->u.nf.netflow, entry->u.nf.flow);
5674 mbridge_unref(entry->u.mirror.mbridge);
5677 free(entry->u.learn.fm);
5678 ofpbuf_delete(entry->u.learn.ofpacts);
5681 free(entry->u.normal.flow);
5683 case XC_FIN_TIMEOUT:
5684 /* 'u.fin.rule' is always already held as a XC_RULE, which
5685 * has already released it's reference above. */
5688 group_dpif_unref(entry->u.group.group);
5697 ofpbuf_clear(&xcache->entries);
5701 xlate_cache_delete(struct xlate_cache *xcache)
5703 xlate_cache_clear(xcache);
5704 ofpbuf_uninit(&xcache->entries);