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>
25 #include "tnl-neigh-cache.h"
30 #include "byte-order.h"
34 #include "dp-packet.h"
36 #include "dynamic-string.h"
42 #include "mac-learning.h"
43 #include "mcast-snooping.h"
44 #include "meta-flow.h"
45 #include "multipath.h"
46 #include "netdev-vport.h"
49 #include "odp-execute.h"
50 #include "ofp-actions.h"
51 #include "ofproto/ofproto-dpif-ipfix.h"
52 #include "ofproto/ofproto-dpif-mirror.h"
53 #include "ofproto/ofproto-dpif-monitor.h"
54 #include "ofproto/ofproto-dpif-sflow.h"
55 #include "ofproto/ofproto-dpif.h"
56 #include "ofproto/ofproto-provider.h"
58 #include "ovs-router.h"
59 #include "tnl-ports.h"
61 #include "openvswitch/vlog.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
70 * flow translation. */
71 #define MAX_RESUBMIT_RECURSION 64
72 #define MAX_INTERNAL_RESUBMITS 1 /* Max resbmits allowed using rules in
75 /* Maximum number of resubmit actions in a flow translation, whether they are
76 * recursive or not. */
77 #define MAX_RESUBMITS (MAX_RESUBMIT_RECURSION * MAX_RESUBMIT_RECURSION)
80 struct hmap_node hmap_node; /* Node in global 'xbridges' map. */
81 struct ofproto_dpif *ofproto; /* Key in global 'xbridges' map. */
83 struct ovs_list xbundles; /* Owned xbundles. */
84 struct hmap xports; /* Indexed by ofp_port. */
86 char *name; /* Name used in log messages. */
87 struct dpif *dpif; /* Datapath interface. */
88 struct mac_learning *ml; /* Mac learning handle. */
89 struct mcast_snooping *ms; /* Multicast Snooping handle. */
90 struct mbridge *mbridge; /* Mirroring. */
91 struct dpif_sflow *sflow; /* SFlow handle, or null. */
92 struct dpif_ipfix *ipfix; /* Ipfix handle, or null. */
93 struct netflow *netflow; /* Netflow handle, or null. */
94 struct stp *stp; /* STP or null if disabled. */
95 struct rstp *rstp; /* RSTP or null if disabled. */
97 bool has_in_band; /* Bridge has in band control? */
98 bool forward_bpdu; /* Bridge forwards STP BPDUs? */
100 /* Datapath feature support. */
101 struct dpif_backer_support support;
105 struct hmap_node hmap_node; /* In global 'xbundles' map. */
106 struct ofbundle *ofbundle; /* Key in global 'xbundles' map. */
108 struct ovs_list list_node; /* In parent 'xbridges' list. */
109 struct xbridge *xbridge; /* Parent xbridge. */
111 struct ovs_list xports; /* Contains "struct xport"s. */
113 char *name; /* Name used in log messages. */
114 struct bond *bond; /* Nonnull iff more than one port. */
115 struct lacp *lacp; /* LACP handle or null. */
117 enum port_vlan_mode vlan_mode; /* VLAN mode. */
118 int vlan; /* -1=trunk port, else a 12-bit VLAN ID. */
119 unsigned long *trunks; /* Bitmap of trunked VLANs, if 'vlan' == -1.
120 * NULL if all VLANs are trunked. */
121 bool use_priority_tags; /* Use 802.1p tag for frames in VLAN 0? */
122 bool floodable; /* No port has OFPUTIL_PC_NO_FLOOD set? */
126 struct hmap_node hmap_node; /* Node in global 'xports' map. */
127 struct ofport_dpif *ofport; /* Key in global 'xports map. */
129 struct hmap_node ofp_node; /* Node in parent xbridge 'xports' map. */
130 ofp_port_t ofp_port; /* Key in parent xbridge 'xports' map. */
132 odp_port_t odp_port; /* Datapath port number or ODPP_NONE. */
134 struct ovs_list bundle_node; /* In parent xbundle (if it exists). */
135 struct xbundle *xbundle; /* Parent xbundle or null. */
137 struct netdev *netdev; /* 'ofport''s netdev. */
139 struct xbridge *xbridge; /* Parent bridge. */
140 struct xport *peer; /* Patch port peer or null. */
142 enum ofputil_port_config config; /* OpenFlow port configuration. */
143 enum ofputil_port_state state; /* OpenFlow port state. */
144 int stp_port_no; /* STP port number or -1 if not in use. */
145 struct rstp_port *rstp_port; /* RSTP port or null. */
147 struct hmap skb_priorities; /* Map of 'skb_priority_to_dscp's. */
149 bool may_enable; /* May be enabled in bonds. */
150 bool is_tunnel; /* Is a tunnel port. */
152 struct cfm *cfm; /* CFM handle or null. */
153 struct bfd *bfd; /* BFD handle or null. */
154 struct lldp *lldp; /* LLDP handle or null. */
158 struct xlate_in *xin;
159 struct xlate_out *xout;
161 const struct xbridge *xbridge;
163 /* Flow tables version at the beginning of the translation. */
164 cls_version_t tables_version;
166 /* Flow at the last commit. */
167 struct flow base_flow;
169 /* Tunnel IP destination address as received. This is stored separately
170 * as the base_flow.tunnel is cleared on init to reflect the datapath
171 * behavior. Used to make sure not to send tunneled output to ourselves,
172 * which might lead to an infinite loop. This could happen easily
173 * if a tunnel is marked as 'ip_remote=flow', and the flow does not
174 * actually set the tun_dst field. */
175 struct in6_addr orig_tunnel_ipv6_dst;
177 /* Stack for the push and pop actions. Each stack element is of type
178 * "union mf_subvalue". */
181 /* The rule that we are currently translating, or NULL. */
182 struct rule_dpif *rule;
184 /* Flow translation populates this with wildcards relevant in translation.
185 * When 'xin->wc' is nonnull, this is the same pointer. When 'xin->wc' is
186 * null, this is a pointer to uninitialized scratch memory. This allows
187 * code to blindly write to 'ctx->wc' without worrying about whether the
188 * caller really wants wildcards. */
189 struct flow_wildcards *wc;
191 /* Output buffer for datapath actions. When 'xin->odp_actions' is nonnull,
192 * this is the same pointer. When 'xin->odp_actions' is null, this points
193 * to a scratch ofpbuf. This allows code to add actions to
194 * 'ctx->odp_actions' without worrying about whether the caller really
196 struct ofpbuf *odp_actions;
198 /* Resubmit statistics, via xlate_table_action(). */
199 int recurse; /* Current resubmit nesting depth. */
200 int resubmits; /* Total number of resubmits. */
201 bool in_group; /* Currently translating ofgroup, if true. */
202 bool in_action_set; /* Currently translating action_set, if true. */
204 uint8_t table_id; /* OpenFlow table ID where flow was found. */
205 ovs_be64 rule_cookie; /* Cookie of the rule being translated. */
206 uint32_t orig_skb_priority; /* Priority when packet arrived. */
207 uint32_t sflow_n_outputs; /* Number of output ports. */
208 odp_port_t sflow_odp_port; /* Output port for composing sFlow action. */
209 ofp_port_t nf_output_iface; /* Output interface index for NetFlow. */
210 bool exit; /* No further actions should be processed. */
211 mirror_mask_t mirrors; /* Bitmap of associated mirrors. */
213 /* These are used for non-bond recirculation. The recirculation IDs are
214 * stored in xout and must be associated with a datapath flow (ukey),
215 * otherwise they will be freed when the xout is uninitialized.
218 * Steps in Recirculation Translation
219 * ==================================
221 * At some point during translation, the code recognizes the need for
222 * recirculation. For example, recirculation is necessary when, after
223 * popping the last MPLS label, an action or a match tries to examine or
224 * modify a field that has been newly revealed following the MPLS label.
226 * The simplest part of the work to be done is to commit existing changes to
227 * the packet, which produces datapath actions corresponding to the changes,
228 * and after this, add an OVS_ACTION_ATTR_RECIRC datapath action.
230 * The main problem here is preserving state. When the datapath executes
231 * OVS_ACTION_ATTR_RECIRC, it will upcall to userspace to get a translation
232 * for the post-recirculation actions. At this point userspace has to
233 * resume the translation where it left off, which means that it has to
234 * execute the following:
236 * - The action that prompted recirculation, and any actions following
237 * it within the same flow.
239 * - If the action that prompted recirculation was invoked within a
240 * NXAST_RESUBMIT, then any actions following the resubmit. These
241 * "resubmit"s can be nested, so this has to go all the way up the
244 * - The OpenFlow 1.1+ action set.
246 * State that actions and flow table lookups can depend on, such as the
247 * following, must also be preserved:
249 * - Metadata fields (input port, registers, OF1.1+ metadata, ...).
251 * - Action set, stack
253 * - The table ID and cookie of the flow being translated at each level
254 * of the control stack (since OFPAT_CONTROLLER actions send these to
257 * Translation allows for the control of this state preservation via these
258 * members. When a need for recirculation is identified, the translation
261 * 1. Sets 'recirc_action_offset' to the current size of 'action_set'. The
262 * action set is part of what needs to be preserved, so this allows the
263 * action set and the additional state to share the 'action_set' buffer.
264 * Later steps can tell that setup for recirculation is in progress from
265 * the nonnegative value of 'recirc_action_offset'.
267 * 2. Sets 'exit' to true to tell later steps that we're exiting from the
268 * translation process.
270 * 3. Adds an OFPACT_UNROLL_XLATE action to 'action_set'. This action
271 * holds the current table ID and cookie so that they can be restored
272 * during a post-recirculation upcall translation.
274 * 4. Adds the action that prompted recirculation and any actions following
275 * it within the same flow to 'action_set', so that they can be executed
276 * during a post-recirculation upcall translation.
280 * 6. The action that prompted recirculation might be nested in a stack of
281 * nested "resubmit"s that have actions remaining. Each of these notices
282 * that we're exiting (from 'exit') and that recirculation setup is in
283 * progress (from 'recirc_action_offset') and responds by adding more
284 * OFPACT_UNROLL_XLATE actions to 'action_set', as necessary, and any
285 * actions that were yet unprocessed.
287 * The caller stores all the state produced by this process associated with
288 * the recirculation ID. For post-recirculation upcall translation, the
289 * caller passes it back in for the new translation to execute. The
290 * process yielded a set of ofpacts that can be translated directly, so it
291 * is not much of a special case at that point.
293 int recirc_action_offset; /* Offset in 'action_set' to actions to be
294 * executed after recirculation, or -1. */
295 int last_unroll_offset; /* Offset in 'action_set' to the latest unroll
298 /* True if a packet was but is no longer MPLS (due to an MPLS pop action).
299 * This is a trigger for recirculation in cases where translating an action
300 * or looking up a flow requires access to the fields of the packet after
301 * the MPLS label stack that was originally present. */
304 /* True if conntrack has been performed on this packet during processing
305 * on the current bridge. This is used to determine whether conntrack
306 * state from the datapath should be honored after recirculation. */
309 /* Pointer to an embedded NAT action in a conntrack action, or NULL. */
310 struct ofpact_nat *ct_nat_action;
312 /* OpenFlow 1.1+ action set.
314 * 'action_set' accumulates "struct ofpact"s added by OFPACT_WRITE_ACTIONS.
315 * When translation is otherwise complete, ofpacts_execute_action_set()
316 * converts it to a set of "struct ofpact"s that can be translated into
317 * datapath actions. */
318 bool action_set_has_group; /* Action set contains OFPACT_GROUP? */
319 struct ofpbuf action_set; /* Action set. */
321 enum xlate_error error; /* Translation failed. */
324 const char *xlate_strerror(enum xlate_error error)
329 case XLATE_BRIDGE_NOT_FOUND:
330 return "Bridge not found";
331 case XLATE_RECURSION_TOO_DEEP:
332 return "Recursion too deep";
333 case XLATE_TOO_MANY_RESUBMITS:
334 return "Too many resubmits";
335 case XLATE_STACK_TOO_DEEP:
336 return "Stack too deep";
337 case XLATE_NO_RECIRCULATION_CONTEXT:
338 return "No recirculation context";
339 case XLATE_RECIRCULATION_CONFLICT:
340 return "Recirculation conflict";
341 case XLATE_TOO_MANY_MPLS_LABELS:
342 return "Too many MPLS labels";
344 return "Unknown error";
347 static void xlate_action_set(struct xlate_ctx *ctx);
348 static void xlate_commit_actions(struct xlate_ctx *ctx);
351 ctx_trigger_recirculation(struct xlate_ctx *ctx)
354 ctx->recirc_action_offset = ctx->action_set.size;
358 ctx_first_recirculation_action(const struct xlate_ctx *ctx)
360 return ctx->recirc_action_offset == ctx->action_set.size;
364 exit_recirculates(const struct xlate_ctx *ctx)
366 /* When recirculating the 'recirc_action_offset' has a non-negative value.
368 return ctx->recirc_action_offset >= 0;
371 static void compose_recirculate_action(struct xlate_ctx *ctx);
373 /* A controller may use OFPP_NONE as the ingress port to indicate that
374 * it did not arrive on a "real" port. 'ofpp_none_bundle' exists for
375 * when an input bundle is needed for validation (e.g., mirroring or
376 * OFPP_NORMAL processing). It is not connected to an 'ofproto' or have
377 * any 'port' structs, so care must be taken when dealing with it. */
378 static struct xbundle ofpp_none_bundle = {
380 .vlan_mode = PORT_VLAN_TRUNK
383 /* Node in 'xport''s 'skb_priorities' map. Used to maintain a map from
384 * 'priority' (the datapath's term for QoS queue) to the dscp bits which all
385 * traffic egressing the 'ofport' with that priority should be marked with. */
386 struct skb_priority_to_dscp {
387 struct hmap_node hmap_node; /* Node in 'ofport_dpif''s 'skb_priorities'. */
388 uint32_t skb_priority; /* Priority of this queue (see struct flow). */
390 uint8_t dscp; /* DSCP bits to mark outgoing traffic with. */
406 /* xlate_cache entries hold enough information to perform the side effects of
407 * xlate_actions() for a rule, without needing to perform rule translation
408 * from scratch. The primary usage of these is to submit statistics to objects
409 * that a flow relates to, although they may be used for other effects as well
410 * (for instance, refreshing hard timeouts for learned flows). */
414 struct rule_dpif *rule;
421 struct netflow *netflow;
426 struct mbridge *mbridge;
427 mirror_mask_t mirrors;
435 struct ofproto_dpif *ofproto;
436 struct ofputil_flow_mod *fm;
437 struct ofpbuf *ofpacts;
440 struct ofproto_dpif *ofproto;
445 struct rule_dpif *rule;
450 struct group_dpif *group;
451 struct ofputil_bucket *bucket;
454 char br_name[IFNAMSIZ];
455 struct in6_addr d_ipv6;
460 #define XC_ENTRY_FOR_EACH(ENTRY, ENTRIES, XCACHE) \
461 ENTRIES = XCACHE->entries; \
462 for (ENTRY = ofpbuf_try_pull(&ENTRIES, sizeof *ENTRY); \
464 ENTRY = ofpbuf_try_pull(&ENTRIES, sizeof *ENTRY))
467 struct ofpbuf entries;
470 /* Xlate config contains hash maps of all bridges, bundles and ports.
471 * Xcfgp contains the pointer to the current xlate configuration.
472 * When the main thread needs to change the configuration, it copies xcfgp to
473 * new_xcfg and edits new_xcfg. This enables the use of RCU locking which
474 * does not block handler and revalidator threads. */
476 struct hmap xbridges;
477 struct hmap xbundles;
480 static OVSRCU_TYPE(struct xlate_cfg *) xcfgp = OVSRCU_INITIALIZER(NULL);
481 static struct xlate_cfg *new_xcfg = NULL;
483 static bool may_receive(const struct xport *, struct xlate_ctx *);
484 static void do_xlate_actions(const struct ofpact *, size_t ofpacts_len,
486 static void xlate_normal(struct xlate_ctx *);
487 static inline void xlate_report(struct xlate_ctx *, const char *, ...)
488 OVS_PRINTF_FORMAT(2, 3);
489 static void xlate_table_action(struct xlate_ctx *, ofp_port_t in_port,
490 uint8_t table_id, bool may_packet_in,
491 bool honor_table_miss);
492 static bool input_vid_is_valid(uint16_t vid, struct xbundle *, bool warn);
493 static uint16_t input_vid_to_vlan(const struct xbundle *, uint16_t vid);
494 static void output_normal(struct xlate_ctx *, const struct xbundle *,
497 /* Optional bond recirculation parameter to compose_output_action(). */
498 struct xlate_bond_recirc {
499 uint32_t recirc_id; /* !0 Use recirculation instead of output. */
500 uint8_t hash_alg; /* !0 Compute hash for recirc before. */
501 uint32_t hash_basis; /* Compute hash for recirc before. */
504 static void compose_output_action(struct xlate_ctx *, ofp_port_t ofp_port,
505 const struct xlate_bond_recirc *xr);
507 static struct xbridge *xbridge_lookup(struct xlate_cfg *,
508 const struct ofproto_dpif *);
509 static struct xbridge *xbridge_lookup_by_uuid(struct xlate_cfg *,
510 const struct uuid *);
511 static struct xbundle *xbundle_lookup(struct xlate_cfg *,
512 const struct ofbundle *);
513 static struct xport *xport_lookup(struct xlate_cfg *,
514 const struct ofport_dpif *);
515 static struct xport *get_ofp_port(const struct xbridge *, ofp_port_t ofp_port);
516 static struct skb_priority_to_dscp *get_skb_priority(const struct xport *,
517 uint32_t skb_priority);
518 static void clear_skb_priorities(struct xport *);
519 static size_t count_skb_priorities(const struct xport *);
520 static bool dscp_from_skb_priority(const struct xport *, uint32_t skb_priority,
523 static struct xc_entry *xlate_cache_add_entry(struct xlate_cache *xc,
525 static void xlate_xbridge_init(struct xlate_cfg *, struct xbridge *);
526 static void xlate_xbundle_init(struct xlate_cfg *, struct xbundle *);
527 static void xlate_xport_init(struct xlate_cfg *, struct xport *);
528 static void xlate_xbridge_set(struct xbridge *, struct dpif *,
529 const struct mac_learning *, struct stp *,
530 struct rstp *, const struct mcast_snooping *,
531 const struct mbridge *,
532 const struct dpif_sflow *,
533 const struct dpif_ipfix *,
534 const struct netflow *,
535 bool forward_bpdu, bool has_in_band,
536 const struct dpif_backer_support *);
537 static void xlate_xbundle_set(struct xbundle *xbundle,
538 enum port_vlan_mode vlan_mode, int vlan,
539 unsigned long *trunks, bool use_priority_tags,
540 const struct bond *bond, const struct lacp *lacp,
542 static void xlate_xport_set(struct xport *xport, odp_port_t odp_port,
543 const struct netdev *netdev, const struct cfm *cfm,
544 const struct bfd *bfd, const struct lldp *lldp,
545 int stp_port_no, const struct rstp_port *rstp_port,
546 enum ofputil_port_config config,
547 enum ofputil_port_state state, bool is_tunnel,
549 static void xlate_xbridge_remove(struct xlate_cfg *, struct xbridge *);
550 static void xlate_xbundle_remove(struct xlate_cfg *, struct xbundle *);
551 static void xlate_xport_remove(struct xlate_cfg *, struct xport *);
552 static void xlate_xbridge_copy(struct xbridge *);
553 static void xlate_xbundle_copy(struct xbridge *, struct xbundle *);
554 static void xlate_xport_copy(struct xbridge *, struct xbundle *,
556 static void xlate_xcfg_free(struct xlate_cfg *);
559 xlate_report(struct xlate_ctx *ctx, const char *format, ...)
561 if (OVS_UNLIKELY(ctx->xin->report_hook)) {
564 va_start(args, format);
565 ctx->xin->report_hook(ctx->xin, ctx->recurse, format, args);
570 static struct vlog_rate_limit error_report_rl = VLOG_RATE_LIMIT_INIT(1, 5);
572 #define XLATE_REPORT_ERROR(CTX, ...) \
574 if (OVS_UNLIKELY((CTX)->xin->report_hook)) { \
575 xlate_report(CTX, __VA_ARGS__); \
577 VLOG_ERR_RL(&error_report_rl, __VA_ARGS__); \
582 xlate_report_actions(struct xlate_ctx *ctx, const char *title,
583 const struct ofpact *ofpacts, size_t ofpacts_len)
585 if (OVS_UNLIKELY(ctx->xin->report_hook)) {
586 struct ds s = DS_EMPTY_INITIALIZER;
587 ofpacts_format(ofpacts, ofpacts_len, &s);
588 xlate_report(ctx, "%s: %s", title, ds_cstr(&s));
594 xlate_xbridge_init(struct xlate_cfg *xcfg, struct xbridge *xbridge)
596 list_init(&xbridge->xbundles);
597 hmap_init(&xbridge->xports);
598 hmap_insert(&xcfg->xbridges, &xbridge->hmap_node,
599 hash_pointer(xbridge->ofproto, 0));
603 xlate_xbundle_init(struct xlate_cfg *xcfg, struct xbundle *xbundle)
605 list_init(&xbundle->xports);
606 list_insert(&xbundle->xbridge->xbundles, &xbundle->list_node);
607 hmap_insert(&xcfg->xbundles, &xbundle->hmap_node,
608 hash_pointer(xbundle->ofbundle, 0));
612 xlate_xport_init(struct xlate_cfg *xcfg, struct xport *xport)
614 hmap_init(&xport->skb_priorities);
615 hmap_insert(&xcfg->xports, &xport->hmap_node,
616 hash_pointer(xport->ofport, 0));
617 hmap_insert(&xport->xbridge->xports, &xport->ofp_node,
618 hash_ofp_port(xport->ofp_port));
622 xlate_xbridge_set(struct xbridge *xbridge,
624 const struct mac_learning *ml, struct stp *stp,
625 struct rstp *rstp, const struct mcast_snooping *ms,
626 const struct mbridge *mbridge,
627 const struct dpif_sflow *sflow,
628 const struct dpif_ipfix *ipfix,
629 const struct netflow *netflow,
630 bool forward_bpdu, bool has_in_band,
631 const struct dpif_backer_support *support)
633 if (xbridge->ml != ml) {
634 mac_learning_unref(xbridge->ml);
635 xbridge->ml = mac_learning_ref(ml);
638 if (xbridge->ms != ms) {
639 mcast_snooping_unref(xbridge->ms);
640 xbridge->ms = mcast_snooping_ref(ms);
643 if (xbridge->mbridge != mbridge) {
644 mbridge_unref(xbridge->mbridge);
645 xbridge->mbridge = mbridge_ref(mbridge);
648 if (xbridge->sflow != sflow) {
649 dpif_sflow_unref(xbridge->sflow);
650 xbridge->sflow = dpif_sflow_ref(sflow);
653 if (xbridge->ipfix != ipfix) {
654 dpif_ipfix_unref(xbridge->ipfix);
655 xbridge->ipfix = dpif_ipfix_ref(ipfix);
658 if (xbridge->stp != stp) {
659 stp_unref(xbridge->stp);
660 xbridge->stp = stp_ref(stp);
663 if (xbridge->rstp != rstp) {
664 rstp_unref(xbridge->rstp);
665 xbridge->rstp = rstp_ref(rstp);
668 if (xbridge->netflow != netflow) {
669 netflow_unref(xbridge->netflow);
670 xbridge->netflow = netflow_ref(netflow);
673 xbridge->dpif = dpif;
674 xbridge->forward_bpdu = forward_bpdu;
675 xbridge->has_in_band = has_in_band;
676 xbridge->support = *support;
680 xlate_xbundle_set(struct xbundle *xbundle,
681 enum port_vlan_mode vlan_mode, int vlan,
682 unsigned long *trunks, bool use_priority_tags,
683 const struct bond *bond, const struct lacp *lacp,
686 ovs_assert(xbundle->xbridge);
688 xbundle->vlan_mode = vlan_mode;
689 xbundle->vlan = vlan;
690 xbundle->trunks = trunks;
691 xbundle->use_priority_tags = use_priority_tags;
692 xbundle->floodable = floodable;
694 if (xbundle->bond != bond) {
695 bond_unref(xbundle->bond);
696 xbundle->bond = bond_ref(bond);
699 if (xbundle->lacp != lacp) {
700 lacp_unref(xbundle->lacp);
701 xbundle->lacp = lacp_ref(lacp);
706 xlate_xport_set(struct xport *xport, odp_port_t odp_port,
707 const struct netdev *netdev, const struct cfm *cfm,
708 const struct bfd *bfd, const struct lldp *lldp, int stp_port_no,
709 const struct rstp_port* rstp_port,
710 enum ofputil_port_config config, enum ofputil_port_state state,
711 bool is_tunnel, bool may_enable)
713 xport->config = config;
714 xport->state = state;
715 xport->stp_port_no = stp_port_no;
716 xport->is_tunnel = is_tunnel;
717 xport->may_enable = may_enable;
718 xport->odp_port = odp_port;
720 if (xport->rstp_port != rstp_port) {
721 rstp_port_unref(xport->rstp_port);
722 xport->rstp_port = rstp_port_ref(rstp_port);
725 if (xport->cfm != cfm) {
726 cfm_unref(xport->cfm);
727 xport->cfm = cfm_ref(cfm);
730 if (xport->bfd != bfd) {
731 bfd_unref(xport->bfd);
732 xport->bfd = bfd_ref(bfd);
735 if (xport->lldp != lldp) {
736 lldp_unref(xport->lldp);
737 xport->lldp = lldp_ref(lldp);
740 if (xport->netdev != netdev) {
741 netdev_close(xport->netdev);
742 xport->netdev = netdev_ref(netdev);
747 xlate_xbridge_copy(struct xbridge *xbridge)
749 struct xbundle *xbundle;
751 struct xbridge *new_xbridge = xzalloc(sizeof *xbridge);
752 new_xbridge->ofproto = xbridge->ofproto;
753 new_xbridge->name = xstrdup(xbridge->name);
754 xlate_xbridge_init(new_xcfg, new_xbridge);
756 xlate_xbridge_set(new_xbridge,
757 xbridge->dpif, xbridge->ml, xbridge->stp,
758 xbridge->rstp, xbridge->ms, xbridge->mbridge,
759 xbridge->sflow, xbridge->ipfix, xbridge->netflow,
760 xbridge->forward_bpdu, xbridge->has_in_band,
762 LIST_FOR_EACH (xbundle, list_node, &xbridge->xbundles) {
763 xlate_xbundle_copy(new_xbridge, xbundle);
766 /* Copy xports which are not part of a xbundle */
767 HMAP_FOR_EACH (xport, ofp_node, &xbridge->xports) {
768 if (!xport->xbundle) {
769 xlate_xport_copy(new_xbridge, NULL, xport);
775 xlate_xbundle_copy(struct xbridge *xbridge, struct xbundle *xbundle)
778 struct xbundle *new_xbundle = xzalloc(sizeof *xbundle);
779 new_xbundle->ofbundle = xbundle->ofbundle;
780 new_xbundle->xbridge = xbridge;
781 new_xbundle->name = xstrdup(xbundle->name);
782 xlate_xbundle_init(new_xcfg, new_xbundle);
784 xlate_xbundle_set(new_xbundle, xbundle->vlan_mode,
785 xbundle->vlan, xbundle->trunks,
786 xbundle->use_priority_tags, xbundle->bond, xbundle->lacp,
788 LIST_FOR_EACH (xport, bundle_node, &xbundle->xports) {
789 xlate_xport_copy(xbridge, new_xbundle, xport);
794 xlate_xport_copy(struct xbridge *xbridge, struct xbundle *xbundle,
797 struct skb_priority_to_dscp *pdscp, *new_pdscp;
798 struct xport *new_xport = xzalloc(sizeof *xport);
799 new_xport->ofport = xport->ofport;
800 new_xport->ofp_port = xport->ofp_port;
801 new_xport->xbridge = xbridge;
802 xlate_xport_init(new_xcfg, new_xport);
804 xlate_xport_set(new_xport, xport->odp_port, xport->netdev, xport->cfm,
805 xport->bfd, xport->lldp, xport->stp_port_no,
806 xport->rstp_port, xport->config, xport->state,
807 xport->is_tunnel, xport->may_enable);
810 struct xport *peer = xport_lookup(new_xcfg, xport->peer->ofport);
812 new_xport->peer = peer;
813 new_xport->peer->peer = new_xport;
818 new_xport->xbundle = xbundle;
819 list_insert(&new_xport->xbundle->xports, &new_xport->bundle_node);
822 HMAP_FOR_EACH (pdscp, hmap_node, &xport->skb_priorities) {
823 new_pdscp = xmalloc(sizeof *pdscp);
824 new_pdscp->skb_priority = pdscp->skb_priority;
825 new_pdscp->dscp = pdscp->dscp;
826 hmap_insert(&new_xport->skb_priorities, &new_pdscp->hmap_node,
827 hash_int(new_pdscp->skb_priority, 0));
831 /* Sets the current xlate configuration to new_xcfg and frees the old xlate
832 * configuration in xcfgp.
834 * This needs to be called after editing the xlate configuration.
836 * Functions that edit the new xlate configuration are
837 * xlate_<ofport/bundle/ofport>_set and xlate_<ofport/bundle/ofport>_remove.
843 * edit_xlate_configuration();
845 * xlate_txn_commit(); */
847 xlate_txn_commit(void)
849 struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
851 ovsrcu_set(&xcfgp, new_xcfg);
852 ovsrcu_synchronize();
853 xlate_xcfg_free(xcfg);
857 /* Copies the current xlate configuration in xcfgp to new_xcfg.
859 * This needs to be called prior to editing the xlate configuration. */
861 xlate_txn_start(void)
863 struct xbridge *xbridge;
864 struct xlate_cfg *xcfg;
866 ovs_assert(!new_xcfg);
868 new_xcfg = xmalloc(sizeof *new_xcfg);
869 hmap_init(&new_xcfg->xbridges);
870 hmap_init(&new_xcfg->xbundles);
871 hmap_init(&new_xcfg->xports);
873 xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
878 HMAP_FOR_EACH (xbridge, hmap_node, &xcfg->xbridges) {
879 xlate_xbridge_copy(xbridge);
885 xlate_xcfg_free(struct xlate_cfg *xcfg)
887 struct xbridge *xbridge, *next_xbridge;
893 HMAP_FOR_EACH_SAFE (xbridge, next_xbridge, hmap_node, &xcfg->xbridges) {
894 xlate_xbridge_remove(xcfg, xbridge);
897 hmap_destroy(&xcfg->xbridges);
898 hmap_destroy(&xcfg->xbundles);
899 hmap_destroy(&xcfg->xports);
904 xlate_ofproto_set(struct ofproto_dpif *ofproto, const char *name,
906 const struct mac_learning *ml, struct stp *stp,
907 struct rstp *rstp, const struct mcast_snooping *ms,
908 const struct mbridge *mbridge,
909 const struct dpif_sflow *sflow,
910 const struct dpif_ipfix *ipfix,
911 const struct netflow *netflow,
912 bool forward_bpdu, bool has_in_band,
913 const struct dpif_backer_support *support)
915 struct xbridge *xbridge;
917 ovs_assert(new_xcfg);
919 xbridge = xbridge_lookup(new_xcfg, ofproto);
921 xbridge = xzalloc(sizeof *xbridge);
922 xbridge->ofproto = ofproto;
924 xlate_xbridge_init(new_xcfg, xbridge);
928 xbridge->name = xstrdup(name);
930 xlate_xbridge_set(xbridge, dpif, ml, stp, rstp, ms, mbridge, sflow, ipfix,
931 netflow, forward_bpdu, has_in_band, support);
935 xlate_xbridge_remove(struct xlate_cfg *xcfg, struct xbridge *xbridge)
937 struct xbundle *xbundle, *next_xbundle;
938 struct xport *xport, *next_xport;
944 HMAP_FOR_EACH_SAFE (xport, next_xport, ofp_node, &xbridge->xports) {
945 xlate_xport_remove(xcfg, xport);
948 LIST_FOR_EACH_SAFE (xbundle, next_xbundle, list_node, &xbridge->xbundles) {
949 xlate_xbundle_remove(xcfg, xbundle);
952 hmap_remove(&xcfg->xbridges, &xbridge->hmap_node);
953 mac_learning_unref(xbridge->ml);
954 mcast_snooping_unref(xbridge->ms);
955 mbridge_unref(xbridge->mbridge);
956 dpif_sflow_unref(xbridge->sflow);
957 dpif_ipfix_unref(xbridge->ipfix);
958 stp_unref(xbridge->stp);
959 rstp_unref(xbridge->rstp);
960 hmap_destroy(&xbridge->xports);
966 xlate_remove_ofproto(struct ofproto_dpif *ofproto)
968 struct xbridge *xbridge;
970 ovs_assert(new_xcfg);
972 xbridge = xbridge_lookup(new_xcfg, ofproto);
973 xlate_xbridge_remove(new_xcfg, xbridge);
977 xlate_bundle_set(struct ofproto_dpif *ofproto, struct ofbundle *ofbundle,
978 const char *name, enum port_vlan_mode vlan_mode, int vlan,
979 unsigned long *trunks, bool use_priority_tags,
980 const struct bond *bond, const struct lacp *lacp,
983 struct xbundle *xbundle;
985 ovs_assert(new_xcfg);
987 xbundle = xbundle_lookup(new_xcfg, ofbundle);
989 xbundle = xzalloc(sizeof *xbundle);
990 xbundle->ofbundle = ofbundle;
991 xbundle->xbridge = xbridge_lookup(new_xcfg, ofproto);
993 xlate_xbundle_init(new_xcfg, xbundle);
997 xbundle->name = xstrdup(name);
999 xlate_xbundle_set(xbundle, vlan_mode, vlan, trunks,
1000 use_priority_tags, bond, lacp, floodable);
1004 xlate_xbundle_remove(struct xlate_cfg *xcfg, struct xbundle *xbundle)
1006 struct xport *xport;
1012 LIST_FOR_EACH_POP (xport, bundle_node, &xbundle->xports) {
1013 xport->xbundle = NULL;
1016 hmap_remove(&xcfg->xbundles, &xbundle->hmap_node);
1017 list_remove(&xbundle->list_node);
1018 bond_unref(xbundle->bond);
1019 lacp_unref(xbundle->lacp);
1020 free(xbundle->name);
1025 xlate_bundle_remove(struct ofbundle *ofbundle)
1027 struct xbundle *xbundle;
1029 ovs_assert(new_xcfg);
1031 xbundle = xbundle_lookup(new_xcfg, ofbundle);
1032 xlate_xbundle_remove(new_xcfg, xbundle);
1036 xlate_ofport_set(struct ofproto_dpif *ofproto, struct ofbundle *ofbundle,
1037 struct ofport_dpif *ofport, ofp_port_t ofp_port,
1038 odp_port_t odp_port, const struct netdev *netdev,
1039 const struct cfm *cfm, const struct bfd *bfd,
1040 const struct lldp *lldp, struct ofport_dpif *peer,
1041 int stp_port_no, const struct rstp_port *rstp_port,
1042 const struct ofproto_port_queue *qdscp_list, size_t n_qdscp,
1043 enum ofputil_port_config config,
1044 enum ofputil_port_state state, bool is_tunnel,
1048 struct xport *xport;
1050 ovs_assert(new_xcfg);
1052 xport = xport_lookup(new_xcfg, ofport);
1054 xport = xzalloc(sizeof *xport);
1055 xport->ofport = ofport;
1056 xport->xbridge = xbridge_lookup(new_xcfg, ofproto);
1057 xport->ofp_port = ofp_port;
1059 xlate_xport_init(new_xcfg, xport);
1062 ovs_assert(xport->ofp_port == ofp_port);
1064 xlate_xport_set(xport, odp_port, netdev, cfm, bfd, lldp,
1065 stp_port_no, rstp_port, config, state, is_tunnel,
1069 xport->peer->peer = NULL;
1071 xport->peer = xport_lookup(new_xcfg, peer);
1073 xport->peer->peer = xport;
1076 if (xport->xbundle) {
1077 list_remove(&xport->bundle_node);
1079 xport->xbundle = xbundle_lookup(new_xcfg, ofbundle);
1080 if (xport->xbundle) {
1081 list_insert(&xport->xbundle->xports, &xport->bundle_node);
1084 clear_skb_priorities(xport);
1085 for (i = 0; i < n_qdscp; i++) {
1086 struct skb_priority_to_dscp *pdscp;
1087 uint32_t skb_priority;
1089 if (dpif_queue_to_priority(xport->xbridge->dpif, qdscp_list[i].queue,
1094 pdscp = xmalloc(sizeof *pdscp);
1095 pdscp->skb_priority = skb_priority;
1096 pdscp->dscp = (qdscp_list[i].dscp << 2) & IP_DSCP_MASK;
1097 hmap_insert(&xport->skb_priorities, &pdscp->hmap_node,
1098 hash_int(pdscp->skb_priority, 0));
1103 xlate_xport_remove(struct xlate_cfg *xcfg, struct xport *xport)
1110 xport->peer->peer = NULL;
1114 if (xport->xbundle) {
1115 list_remove(&xport->bundle_node);
1118 clear_skb_priorities(xport);
1119 hmap_destroy(&xport->skb_priorities);
1121 hmap_remove(&xcfg->xports, &xport->hmap_node);
1122 hmap_remove(&xport->xbridge->xports, &xport->ofp_node);
1124 netdev_close(xport->netdev);
1125 rstp_port_unref(xport->rstp_port);
1126 cfm_unref(xport->cfm);
1127 bfd_unref(xport->bfd);
1128 lldp_unref(xport->lldp);
1133 xlate_ofport_remove(struct ofport_dpif *ofport)
1135 struct xport *xport;
1137 ovs_assert(new_xcfg);
1139 xport = xport_lookup(new_xcfg, ofport);
1140 xlate_xport_remove(new_xcfg, xport);
1143 static struct ofproto_dpif *
1144 xlate_lookup_ofproto_(const struct dpif_backer *backer, const struct flow *flow,
1145 ofp_port_t *ofp_in_port, const struct xport **xportp)
1147 struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
1148 const struct xport *xport;
1150 xport = xport_lookup(xcfg, tnl_port_should_receive(flow)
1151 ? tnl_port_receive(flow)
1152 : odp_port_to_ofport(backer, flow->in_port.odp_port));
1153 if (OVS_UNLIKELY(!xport)) {
1158 *ofp_in_port = xport->ofp_port;
1160 return xport->xbridge->ofproto;
1163 /* Given a datapath and flow metadata ('backer', and 'flow' respectively)
1164 * returns the corresponding struct ofproto_dpif and OpenFlow port number. */
1165 struct ofproto_dpif *
1166 xlate_lookup_ofproto(const struct dpif_backer *backer, const struct flow *flow,
1167 ofp_port_t *ofp_in_port)
1169 const struct xport *xport;
1171 return xlate_lookup_ofproto_(backer, flow, ofp_in_port, &xport);
1174 /* Given a datapath and flow metadata ('backer', and 'flow' respectively),
1175 * optionally populates 'ofproto' with the ofproto_dpif, 'ofp_in_port' with the
1176 * openflow in_port, and 'ipfix', 'sflow', and 'netflow' with the appropriate
1177 * handles for those protocols if they're enabled. Caller may use the returned
1178 * pointers until quiescing, for longer term use additional references must
1181 * Returns 0 if successful, ENODEV if the parsed flow has no associated ofproto.
1184 xlate_lookup(const struct dpif_backer *backer, const struct flow *flow,
1185 struct ofproto_dpif **ofprotop, struct dpif_ipfix **ipfix,
1186 struct dpif_sflow **sflow, struct netflow **netflow,
1187 ofp_port_t *ofp_in_port)
1189 struct ofproto_dpif *ofproto;
1190 const struct xport *xport;
1192 ofproto = xlate_lookup_ofproto_(backer, flow, ofp_in_port, &xport);
1199 *ofprotop = ofproto;
1203 *ipfix = xport ? xport->xbridge->ipfix : NULL;
1207 *sflow = xport ? xport->xbridge->sflow : NULL;
1211 *netflow = xport ? xport->xbridge->netflow : NULL;
1217 static struct xbridge *
1218 xbridge_lookup(struct xlate_cfg *xcfg, const struct ofproto_dpif *ofproto)
1220 struct hmap *xbridges;
1221 struct xbridge *xbridge;
1223 if (!ofproto || !xcfg) {
1227 xbridges = &xcfg->xbridges;
1229 HMAP_FOR_EACH_IN_BUCKET (xbridge, hmap_node, hash_pointer(ofproto, 0),
1231 if (xbridge->ofproto == ofproto) {
1238 static struct xbridge *
1239 xbridge_lookup_by_uuid(struct xlate_cfg *xcfg, const struct uuid *uuid)
1241 struct xbridge *xbridge;
1243 HMAP_FOR_EACH (xbridge, hmap_node, &xcfg->xbridges) {
1244 if (uuid_equals(ofproto_dpif_get_uuid(xbridge->ofproto), uuid)) {
1251 static struct xbundle *
1252 xbundle_lookup(struct xlate_cfg *xcfg, const struct ofbundle *ofbundle)
1254 struct hmap *xbundles;
1255 struct xbundle *xbundle;
1257 if (!ofbundle || !xcfg) {
1261 xbundles = &xcfg->xbundles;
1263 HMAP_FOR_EACH_IN_BUCKET (xbundle, hmap_node, hash_pointer(ofbundle, 0),
1265 if (xbundle->ofbundle == ofbundle) {
1272 static struct xport *
1273 xport_lookup(struct xlate_cfg *xcfg, const struct ofport_dpif *ofport)
1275 struct hmap *xports;
1276 struct xport *xport;
1278 if (!ofport || !xcfg) {
1282 xports = &xcfg->xports;
1284 HMAP_FOR_EACH_IN_BUCKET (xport, hmap_node, hash_pointer(ofport, 0),
1286 if (xport->ofport == ofport) {
1293 static struct stp_port *
1294 xport_get_stp_port(const struct xport *xport)
1296 return xport->xbridge->stp && xport->stp_port_no != -1
1297 ? stp_get_port(xport->xbridge->stp, xport->stp_port_no)
1302 xport_stp_learn_state(const struct xport *xport)
1304 struct stp_port *sp = xport_get_stp_port(xport);
1306 ? stp_learn_in_state(stp_port_get_state(sp))
1311 xport_stp_forward_state(const struct xport *xport)
1313 struct stp_port *sp = xport_get_stp_port(xport);
1315 ? stp_forward_in_state(stp_port_get_state(sp))
1320 xport_stp_should_forward_bpdu(const struct xport *xport)
1322 struct stp_port *sp = xport_get_stp_port(xport);
1323 return stp_should_forward_bpdu(sp ? stp_port_get_state(sp) : STP_DISABLED);
1326 /* Returns true if STP should process 'flow'. Sets fields in 'wc' that
1327 * were used to make the determination.*/
1329 stp_should_process_flow(const struct flow *flow, struct flow_wildcards *wc)
1331 /* is_stp() also checks dl_type, but dl_type is always set in 'wc'. */
1332 memset(&wc->masks.dl_dst, 0xff, sizeof wc->masks.dl_dst);
1333 return is_stp(flow);
1337 stp_process_packet(const struct xport *xport, const struct dp_packet *packet)
1339 struct stp_port *sp = xport_get_stp_port(xport);
1340 struct dp_packet payload = *packet;
1341 struct eth_header *eth = dp_packet_data(&payload);
1343 /* Sink packets on ports that have STP disabled when the bridge has
1345 if (!sp || stp_port_get_state(sp) == STP_DISABLED) {
1349 /* Trim off padding on payload. */
1350 if (dp_packet_size(&payload) > ntohs(eth->eth_type) + ETH_HEADER_LEN) {
1351 dp_packet_set_size(&payload, ntohs(eth->eth_type) + ETH_HEADER_LEN);
1354 if (dp_packet_try_pull(&payload, ETH_HEADER_LEN + LLC_HEADER_LEN)) {
1355 stp_received_bpdu(sp, dp_packet_data(&payload), dp_packet_size(&payload));
1359 static enum rstp_state
1360 xport_get_rstp_port_state(const struct xport *xport)
1362 return xport->rstp_port
1363 ? rstp_port_get_state(xport->rstp_port)
1368 xport_rstp_learn_state(const struct xport *xport)
1370 return xport->xbridge->rstp && xport->rstp_port
1371 ? rstp_learn_in_state(xport_get_rstp_port_state(xport))
1376 xport_rstp_forward_state(const struct xport *xport)
1378 return xport->xbridge->rstp && xport->rstp_port
1379 ? rstp_forward_in_state(xport_get_rstp_port_state(xport))
1384 xport_rstp_should_manage_bpdu(const struct xport *xport)
1386 return rstp_should_manage_bpdu(xport_get_rstp_port_state(xport));
1390 rstp_process_packet(const struct xport *xport, const struct dp_packet *packet)
1392 struct dp_packet payload = *packet;
1393 struct eth_header *eth = dp_packet_data(&payload);
1395 /* Sink packets on ports that have no RSTP. */
1396 if (!xport->rstp_port) {
1400 /* Trim off padding on payload. */
1401 if (dp_packet_size(&payload) > ntohs(eth->eth_type) + ETH_HEADER_LEN) {
1402 dp_packet_set_size(&payload, ntohs(eth->eth_type) + ETH_HEADER_LEN);
1405 if (dp_packet_try_pull(&payload, ETH_HEADER_LEN + LLC_HEADER_LEN)) {
1406 rstp_port_received_bpdu(xport->rstp_port, dp_packet_data(&payload),
1407 dp_packet_size(&payload));
1411 static struct xport *
1412 get_ofp_port(const struct xbridge *xbridge, ofp_port_t ofp_port)
1414 struct xport *xport;
1416 HMAP_FOR_EACH_IN_BUCKET (xport, ofp_node, hash_ofp_port(ofp_port),
1418 if (xport->ofp_port == ofp_port) {
1426 ofp_port_to_odp_port(const struct xbridge *xbridge, ofp_port_t ofp_port)
1428 const struct xport *xport = get_ofp_port(xbridge, ofp_port);
1429 return xport ? xport->odp_port : ODPP_NONE;
1433 odp_port_is_alive(const struct xlate_ctx *ctx, ofp_port_t ofp_port)
1435 struct xport *xport = get_ofp_port(ctx->xbridge, ofp_port);
1436 return xport && xport->may_enable;
1439 static struct ofputil_bucket *
1440 group_first_live_bucket(const struct xlate_ctx *, const struct group_dpif *,
1444 group_is_alive(const struct xlate_ctx *ctx, uint32_t group_id, int depth)
1446 struct group_dpif *group;
1448 if (group_dpif_lookup(ctx->xbridge->ofproto, group_id, &group)) {
1449 struct ofputil_bucket *bucket;
1451 bucket = group_first_live_bucket(ctx, group, depth);
1452 group_dpif_unref(group);
1453 return bucket == NULL;
1459 #define MAX_LIVENESS_RECURSION 128 /* Arbitrary limit */
1462 bucket_is_alive(const struct xlate_ctx *ctx,
1463 struct ofputil_bucket *bucket, int depth)
1465 if (depth >= MAX_LIVENESS_RECURSION) {
1466 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
1468 VLOG_WARN_RL(&rl, "bucket chaining exceeded %d links",
1469 MAX_LIVENESS_RECURSION);
1473 return (!ofputil_bucket_has_liveness(bucket)
1474 || (bucket->watch_port != OFPP_ANY
1475 && odp_port_is_alive(ctx, bucket->watch_port))
1476 || (bucket->watch_group != OFPG_ANY
1477 && group_is_alive(ctx, bucket->watch_group, depth + 1)));
1480 static struct ofputil_bucket *
1481 group_first_live_bucket(const struct xlate_ctx *ctx,
1482 const struct group_dpif *group, int depth)
1484 struct ofputil_bucket *bucket;
1485 const struct ovs_list *buckets;
1487 group_dpif_get_buckets(group, &buckets);
1488 LIST_FOR_EACH (bucket, list_node, buckets) {
1489 if (bucket_is_alive(ctx, bucket, depth)) {
1497 static struct ofputil_bucket *
1498 group_best_live_bucket(const struct xlate_ctx *ctx,
1499 const struct group_dpif *group,
1502 struct ofputil_bucket *best_bucket = NULL;
1503 uint32_t best_score = 0;
1506 struct ofputil_bucket *bucket;
1507 const struct ovs_list *buckets;
1509 group_dpif_get_buckets(group, &buckets);
1510 LIST_FOR_EACH (bucket, list_node, buckets) {
1511 if (bucket_is_alive(ctx, bucket, 0)) {
1512 uint32_t score = (hash_int(i, basis) & 0xffff) * bucket->weight;
1513 if (score >= best_score) {
1514 best_bucket = bucket;
1525 xbundle_trunks_vlan(const struct xbundle *bundle, uint16_t vlan)
1527 return (bundle->vlan_mode != PORT_VLAN_ACCESS
1528 && (!bundle->trunks || bitmap_is_set(bundle->trunks, vlan)));
1532 xbundle_includes_vlan(const struct xbundle *xbundle, uint16_t vlan)
1534 return vlan == xbundle->vlan || xbundle_trunks_vlan(xbundle, vlan);
1537 static mirror_mask_t
1538 xbundle_mirror_out(const struct xbridge *xbridge, struct xbundle *xbundle)
1540 return xbundle != &ofpp_none_bundle
1541 ? mirror_bundle_out(xbridge->mbridge, xbundle->ofbundle)
1545 static mirror_mask_t
1546 xbundle_mirror_src(const struct xbridge *xbridge, struct xbundle *xbundle)
1548 return xbundle != &ofpp_none_bundle
1549 ? mirror_bundle_src(xbridge->mbridge, xbundle->ofbundle)
1553 static mirror_mask_t
1554 xbundle_mirror_dst(const struct xbridge *xbridge, struct xbundle *xbundle)
1556 return xbundle != &ofpp_none_bundle
1557 ? mirror_bundle_dst(xbridge->mbridge, xbundle->ofbundle)
1561 static struct xbundle *
1562 lookup_input_bundle(const struct xbridge *xbridge, ofp_port_t in_port,
1563 bool warn, struct xport **in_xportp)
1565 struct xport *xport;
1567 /* Find the port and bundle for the received packet. */
1568 xport = get_ofp_port(xbridge, in_port);
1572 if (xport && xport->xbundle) {
1573 return xport->xbundle;
1576 /* Special-case OFPP_NONE (OF1.0) and OFPP_CONTROLLER (OF1.1+),
1577 * which a controller may use as the ingress port for traffic that
1578 * it is sourcing. */
1579 if (in_port == OFPP_CONTROLLER || in_port == OFPP_NONE) {
1580 return &ofpp_none_bundle;
1583 /* Odd. A few possible reasons here:
1585 * - We deleted a port but there are still a few packets queued up
1588 * - Someone externally added a port (e.g. "ovs-dpctl add-if") that
1589 * we don't know about.
1591 * - The ofproto client didn't configure the port as part of a bundle.
1592 * This is particularly likely to happen if a packet was received on the
1593 * port after it was created, but before the client had a chance to
1594 * configure its bundle.
1597 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
1599 VLOG_WARN_RL(&rl, "bridge %s: received packet on unknown "
1600 "port %"PRIu16, xbridge->name, in_port);
1606 mirror_packet(struct xlate_ctx *ctx, struct xbundle *xbundle,
1607 mirror_mask_t mirrors)
1609 bool warn = ctx->xin->packet != NULL;
1610 uint16_t vid = vlan_tci_to_vid(ctx->xin->flow.vlan_tci);
1611 if (!input_vid_is_valid(vid, xbundle, warn)) {
1614 uint16_t vlan = input_vid_to_vlan(xbundle, vid);
1616 const struct xbridge *xbridge = ctx->xbridge;
1618 /* Don't mirror to destinations that we've already mirrored to. */
1619 mirrors &= ~ctx->mirrors;
1624 /* Record these mirrors so that we don't mirror to them again. */
1625 ctx->mirrors |= mirrors;
1627 if (ctx->xin->resubmit_stats) {
1628 mirror_update_stats(xbridge->mbridge, mirrors,
1629 ctx->xin->resubmit_stats->n_packets,
1630 ctx->xin->resubmit_stats->n_bytes);
1632 if (ctx->xin->xcache) {
1633 struct xc_entry *entry;
1635 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_MIRROR);
1636 entry->u.mirror.mbridge = mbridge_ref(xbridge->mbridge);
1637 entry->u.mirror.mirrors = mirrors;
1641 const unsigned long *vlans;
1642 mirror_mask_t dup_mirrors;
1643 struct ofbundle *out;
1646 bool has_mirror = mirror_get(xbridge->mbridge, raw_ctz(mirrors),
1647 &vlans, &dup_mirrors, &out, &out_vlan);
1648 ovs_assert(has_mirror);
1651 ctx->wc->masks.vlan_tci |= htons(VLAN_CFI | VLAN_VID_MASK);
1654 if (vlans && !bitmap_is_set(vlans, vlan)) {
1655 mirrors = zero_rightmost_1bit(mirrors);
1659 mirrors &= ~dup_mirrors;
1660 ctx->mirrors |= dup_mirrors;
1662 struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
1663 struct xbundle *out_xbundle = xbundle_lookup(xcfg, out);
1665 output_normal(ctx, out_xbundle, vlan);
1667 } else if (vlan != out_vlan
1668 && !eth_addr_is_reserved(ctx->xin->flow.dl_dst)) {
1669 struct xbundle *xbundle;
1671 LIST_FOR_EACH (xbundle, list_node, &xbridge->xbundles) {
1672 if (xbundle_includes_vlan(xbundle, out_vlan)
1673 && !xbundle_mirror_out(xbridge, xbundle)) {
1674 output_normal(ctx, xbundle, out_vlan);
1682 mirror_ingress_packet(struct xlate_ctx *ctx)
1684 if (mbridge_has_mirrors(ctx->xbridge->mbridge)) {
1685 bool warn = ctx->xin->packet != NULL;
1686 struct xbundle *xbundle = lookup_input_bundle(
1687 ctx->xbridge, ctx->xin->flow.in_port.ofp_port, warn, NULL);
1689 mirror_packet(ctx, xbundle,
1690 xbundle_mirror_src(ctx->xbridge, xbundle));
1695 /* Given 'vid', the VID obtained from the 802.1Q header that was received as
1696 * part of a packet (specify 0 if there was no 802.1Q header), and 'in_xbundle',
1697 * the bundle on which the packet was received, returns the VLAN to which the
1700 * Both 'vid' and the return value are in the range 0...4095. */
1702 input_vid_to_vlan(const struct xbundle *in_xbundle, uint16_t vid)
1704 switch (in_xbundle->vlan_mode) {
1705 case PORT_VLAN_ACCESS:
1706 return in_xbundle->vlan;
1709 case PORT_VLAN_TRUNK:
1712 case PORT_VLAN_NATIVE_UNTAGGED:
1713 case PORT_VLAN_NATIVE_TAGGED:
1714 return vid ? vid : in_xbundle->vlan;
1721 /* Checks whether a packet with the given 'vid' may ingress on 'in_xbundle'.
1722 * If so, returns true. Otherwise, returns false and, if 'warn' is true, logs
1725 * 'vid' should be the VID obtained from the 802.1Q header that was received as
1726 * part of a packet (specify 0 if there was no 802.1Q header), in the range
1729 input_vid_is_valid(uint16_t vid, struct xbundle *in_xbundle, bool warn)
1731 /* Allow any VID on the OFPP_NONE port. */
1732 if (in_xbundle == &ofpp_none_bundle) {
1736 switch (in_xbundle->vlan_mode) {
1737 case PORT_VLAN_ACCESS:
1740 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
1741 VLOG_WARN_RL(&rl, "dropping VLAN %"PRIu16" tagged "
1742 "packet received on port %s configured as VLAN "
1743 "%"PRIu16" access port", vid, in_xbundle->name,
1750 case PORT_VLAN_NATIVE_UNTAGGED:
1751 case PORT_VLAN_NATIVE_TAGGED:
1753 /* Port must always carry its native VLAN. */
1757 case PORT_VLAN_TRUNK:
1758 if (!xbundle_includes_vlan(in_xbundle, vid)) {
1760 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
1761 VLOG_WARN_RL(&rl, "dropping VLAN %"PRIu16" packet "
1762 "received on port %s not configured for trunking "
1763 "VLAN %"PRIu16, vid, in_xbundle->name, vid);
1775 /* Given 'vlan', the VLAN that a packet belongs to, and
1776 * 'out_xbundle', a bundle on which the packet is to be output, returns the VID
1777 * that should be included in the 802.1Q header. (If the return value is 0,
1778 * then the 802.1Q header should only be included in the packet if there is a
1781 * Both 'vlan' and the return value are in the range 0...4095. */
1783 output_vlan_to_vid(const struct xbundle *out_xbundle, uint16_t vlan)
1785 switch (out_xbundle->vlan_mode) {
1786 case PORT_VLAN_ACCESS:
1789 case PORT_VLAN_TRUNK:
1790 case PORT_VLAN_NATIVE_TAGGED:
1793 case PORT_VLAN_NATIVE_UNTAGGED:
1794 return vlan == out_xbundle->vlan ? 0 : vlan;
1802 output_normal(struct xlate_ctx *ctx, const struct xbundle *out_xbundle,
1805 ovs_be16 *flow_tci = &ctx->xin->flow.vlan_tci;
1807 ovs_be16 tci, old_tci;
1808 struct xport *xport;
1809 struct xlate_bond_recirc xr;
1810 bool use_recirc = false;
1812 vid = output_vlan_to_vid(out_xbundle, vlan);
1813 if (list_is_empty(&out_xbundle->xports)) {
1814 /* Partially configured bundle with no slaves. Drop the packet. */
1816 } else if (!out_xbundle->bond) {
1817 xport = CONTAINER_OF(list_front(&out_xbundle->xports), struct xport,
1820 struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
1821 struct flow_wildcards *wc = ctx->wc;
1822 struct ofport_dpif *ofport;
1824 if (ctx->xbridge->support.odp.recirc) {
1825 use_recirc = bond_may_recirc(
1826 out_xbundle->bond, &xr.recirc_id, &xr.hash_basis);
1829 /* Only TCP mode uses recirculation. */
1830 xr.hash_alg = OVS_HASH_ALG_L4;
1831 bond_update_post_recirc_rules(out_xbundle->bond, false);
1833 /* Recirculation does not require unmasking hash fields. */
1838 ofport = bond_choose_output_slave(out_xbundle->bond,
1839 &ctx->xin->flow, wc, vid);
1840 xport = xport_lookup(xcfg, ofport);
1843 /* No slaves enabled, so drop packet. */
1847 /* If use_recirc is set, the main thread will handle stats
1848 * accounting for this bond. */
1850 if (ctx->xin->resubmit_stats) {
1851 bond_account(out_xbundle->bond, &ctx->xin->flow, vid,
1852 ctx->xin->resubmit_stats->n_bytes);
1854 if (ctx->xin->xcache) {
1855 struct xc_entry *entry;
1858 flow = &ctx->xin->flow;
1859 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_BOND);
1860 entry->u.bond.bond = bond_ref(out_xbundle->bond);
1861 entry->u.bond.flow = xmemdup(flow, sizeof *flow);
1862 entry->u.bond.vid = vid;
1867 old_tci = *flow_tci;
1869 if (tci || out_xbundle->use_priority_tags) {
1870 tci |= *flow_tci & htons(VLAN_PCP_MASK);
1872 tci |= htons(VLAN_CFI);
1877 compose_output_action(ctx, xport->ofp_port, use_recirc ? &xr : NULL);
1878 *flow_tci = old_tci;
1881 /* A VM broadcasts a gratuitous ARP to indicate that it has resumed after
1882 * migration. Older Citrix-patched Linux DomU used gratuitous ARP replies to
1883 * indicate this; newer upstream kernels use gratuitous ARP requests. */
1885 is_gratuitous_arp(const struct flow *flow, struct flow_wildcards *wc)
1887 if (flow->dl_type != htons(ETH_TYPE_ARP)) {
1891 memset(&wc->masks.dl_dst, 0xff, sizeof wc->masks.dl_dst);
1892 if (!eth_addr_is_broadcast(flow->dl_dst)) {
1896 memset(&wc->masks.nw_proto, 0xff, sizeof wc->masks.nw_proto);
1897 if (flow->nw_proto == ARP_OP_REPLY) {
1899 } else if (flow->nw_proto == ARP_OP_REQUEST) {
1900 memset(&wc->masks.nw_src, 0xff, sizeof wc->masks.nw_src);
1901 memset(&wc->masks.nw_dst, 0xff, sizeof wc->masks.nw_dst);
1903 return flow->nw_src == flow->nw_dst;
1909 /* Determines whether packets in 'flow' within 'xbridge' should be forwarded or
1910 * dropped. Returns true if they may be forwarded, false if they should be
1913 * 'in_port' must be the xport that corresponds to flow->in_port.
1914 * 'in_port' must be part of a bundle (e.g. in_port->bundle must be nonnull).
1916 * 'vlan' must be the VLAN that corresponds to flow->vlan_tci on 'in_port', as
1917 * returned by input_vid_to_vlan(). It must be a valid VLAN for 'in_port', as
1918 * checked by input_vid_is_valid().
1920 * May also add tags to '*tags', although the current implementation only does
1921 * so in one special case.
1924 is_admissible(struct xlate_ctx *ctx, struct xport *in_port,
1927 struct xbundle *in_xbundle = in_port->xbundle;
1928 const struct xbridge *xbridge = ctx->xbridge;
1929 struct flow *flow = &ctx->xin->flow;
1931 /* Drop frames for reserved multicast addresses
1932 * only if forward_bpdu option is absent. */
1933 if (!xbridge->forward_bpdu && eth_addr_is_reserved(flow->dl_dst)) {
1934 xlate_report(ctx, "packet has reserved destination MAC, dropping");
1938 if (in_xbundle->bond) {
1939 struct mac_entry *mac;
1941 switch (bond_check_admissibility(in_xbundle->bond, in_port->ofport,
1947 xlate_report(ctx, "bonding refused admissibility, dropping");
1950 case BV_DROP_IF_MOVED:
1951 ovs_rwlock_rdlock(&xbridge->ml->rwlock);
1952 mac = mac_learning_lookup(xbridge->ml, flow->dl_src, vlan);
1954 && mac_entry_get_port(xbridge->ml, mac) != in_xbundle->ofbundle
1955 && (!is_gratuitous_arp(flow, ctx->wc)
1956 || mac_entry_is_grat_arp_locked(mac))) {
1957 ovs_rwlock_unlock(&xbridge->ml->rwlock);
1958 xlate_report(ctx, "SLB bond thinks this packet looped back, "
1962 ovs_rwlock_unlock(&xbridge->ml->rwlock);
1970 /* Checks whether a MAC learning update is necessary for MAC learning table
1971 * 'ml' given that a packet matching 'flow' was received on 'in_xbundle' in
1974 * Most packets processed through the MAC learning table do not actually
1975 * change it in any way. This function requires only a read lock on the MAC
1976 * learning table, so it is much cheaper in this common case.
1978 * Keep the code here synchronized with that in update_learning_table__()
1981 is_mac_learning_update_needed(const struct mac_learning *ml,
1982 const struct flow *flow,
1983 struct flow_wildcards *wc,
1984 int vlan, struct xbundle *in_xbundle)
1985 OVS_REQ_RDLOCK(ml->rwlock)
1987 struct mac_entry *mac;
1989 if (!mac_learning_may_learn(ml, flow->dl_src, vlan)) {
1993 mac = mac_learning_lookup(ml, flow->dl_src, vlan);
1994 if (!mac || mac_entry_age(ml, mac)) {
1998 if (is_gratuitous_arp(flow, wc)) {
1999 /* We don't want to learn from gratuitous ARP packets that are
2000 * reflected back over bond slaves so we lock the learning table. */
2001 if (!in_xbundle->bond) {
2003 } else if (mac_entry_is_grat_arp_locked(mac)) {
2008 return mac_entry_get_port(ml, mac) != in_xbundle->ofbundle;
2012 /* Updates MAC learning table 'ml' given that a packet matching 'flow' was
2013 * received on 'in_xbundle' in 'vlan'.
2015 * This code repeats all the checks in is_mac_learning_update_needed() because
2016 * the lock was released between there and here and thus the MAC learning state
2017 * could have changed.
2019 * Keep the code here synchronized with that in is_mac_learning_update_needed()
2022 update_learning_table__(const struct xbridge *xbridge,
2023 const struct flow *flow, struct flow_wildcards *wc,
2024 int vlan, struct xbundle *in_xbundle)
2025 OVS_REQ_WRLOCK(xbridge->ml->rwlock)
2027 struct mac_entry *mac;
2029 if (!mac_learning_may_learn(xbridge->ml, flow->dl_src, vlan)) {
2033 mac = mac_learning_insert(xbridge->ml, flow->dl_src, vlan);
2034 if (is_gratuitous_arp(flow, wc)) {
2035 /* We don't want to learn from gratuitous ARP packets that are
2036 * reflected back over bond slaves so we lock the learning table. */
2037 if (!in_xbundle->bond) {
2038 mac_entry_set_grat_arp_lock(mac);
2039 } else if (mac_entry_is_grat_arp_locked(mac)) {
2044 if (mac_entry_get_port(xbridge->ml, mac) != in_xbundle->ofbundle) {
2045 /* The log messages here could actually be useful in debugging,
2046 * so keep the rate limit relatively high. */
2047 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(30, 300);
2049 VLOG_DBG_RL(&rl, "bridge %s: learned that "ETH_ADDR_FMT" is "
2050 "on port %s in VLAN %d",
2051 xbridge->name, ETH_ADDR_ARGS(flow->dl_src),
2052 in_xbundle->name, vlan);
2054 mac_entry_set_port(xbridge->ml, mac, in_xbundle->ofbundle);
2059 update_learning_table(const struct xbridge *xbridge,
2060 const struct flow *flow, struct flow_wildcards *wc,
2061 int vlan, struct xbundle *in_xbundle)
2065 /* Don't learn the OFPP_NONE port. */
2066 if (in_xbundle == &ofpp_none_bundle) {
2070 /* First try the common case: no change to MAC learning table. */
2071 ovs_rwlock_rdlock(&xbridge->ml->rwlock);
2072 need_update = is_mac_learning_update_needed(xbridge->ml, flow, wc, vlan,
2074 ovs_rwlock_unlock(&xbridge->ml->rwlock);
2077 /* Slow path: MAC learning table might need an update. */
2078 ovs_rwlock_wrlock(&xbridge->ml->rwlock);
2079 update_learning_table__(xbridge, flow, wc, vlan, in_xbundle);
2080 ovs_rwlock_unlock(&xbridge->ml->rwlock);
2084 /* Updates multicast snooping table 'ms' given that a packet matching 'flow'
2085 * was received on 'in_xbundle' in 'vlan' and is either Report or Query. */
2087 update_mcast_snooping_table4__(const struct xbridge *xbridge,
2088 const struct flow *flow,
2089 struct mcast_snooping *ms, int vlan,
2090 struct xbundle *in_xbundle,
2091 const struct dp_packet *packet)
2092 OVS_REQ_WRLOCK(ms->rwlock)
2094 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(60, 30);
2096 ovs_be32 ip4 = flow->igmp_group_ip4;
2098 switch (ntohs(flow->tp_src)) {
2099 case IGMP_HOST_MEMBERSHIP_REPORT:
2100 case IGMPV2_HOST_MEMBERSHIP_REPORT:
2101 if (mcast_snooping_add_group4(ms, ip4, vlan, in_xbundle->ofbundle)) {
2102 VLOG_DBG_RL(&rl, "bridge %s: multicast snooping learned that "
2103 IP_FMT" is on port %s in VLAN %d",
2104 xbridge->name, IP_ARGS(ip4), in_xbundle->name, vlan);
2107 case IGMP_HOST_LEAVE_MESSAGE:
2108 if (mcast_snooping_leave_group4(ms, ip4, vlan, in_xbundle->ofbundle)) {
2109 VLOG_DBG_RL(&rl, "bridge %s: multicast snooping leaving "
2110 IP_FMT" is on port %s in VLAN %d",
2111 xbridge->name, IP_ARGS(ip4), in_xbundle->name, vlan);
2114 case IGMP_HOST_MEMBERSHIP_QUERY:
2115 if (flow->nw_src && mcast_snooping_add_mrouter(ms, vlan,
2116 in_xbundle->ofbundle)) {
2117 VLOG_DBG_RL(&rl, "bridge %s: multicast snooping query from "
2118 IP_FMT" is on port %s in VLAN %d",
2119 xbridge->name, IP_ARGS(flow->nw_src),
2120 in_xbundle->name, vlan);
2123 case IGMPV3_HOST_MEMBERSHIP_REPORT:
2124 if ((count = mcast_snooping_add_report(ms, packet, vlan,
2125 in_xbundle->ofbundle))) {
2126 VLOG_DBG_RL(&rl, "bridge %s: multicast snooping processed %d "
2127 "addresses on port %s in VLAN %d",
2128 xbridge->name, count, in_xbundle->name, vlan);
2135 update_mcast_snooping_table6__(const struct xbridge *xbridge,
2136 const struct flow *flow,
2137 struct mcast_snooping *ms, int vlan,
2138 struct xbundle *in_xbundle,
2139 const struct dp_packet *packet)
2140 OVS_REQ_WRLOCK(ms->rwlock)
2142 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(60, 30);
2145 switch (ntohs(flow->tp_src)) {
2147 if (!ipv6_addr_equals(&flow->ipv6_src, &in6addr_any)
2148 && mcast_snooping_add_mrouter(ms, vlan, in_xbundle->ofbundle)) {
2149 VLOG_DBG_RL(&rl, "bridge %s: multicast snooping query on port %s"
2151 xbridge->name, in_xbundle->name, vlan);
2157 count = mcast_snooping_add_mld(ms, packet, vlan, in_xbundle->ofbundle);
2159 VLOG_DBG_RL(&rl, "bridge %s: multicast snooping processed %d "
2160 "addresses on port %s in VLAN %d",
2161 xbridge->name, count, in_xbundle->name, vlan);
2167 /* Updates multicast snooping table 'ms' given that a packet matching 'flow'
2168 * was received on 'in_xbundle' in 'vlan'. */
2170 update_mcast_snooping_table(const struct xbridge *xbridge,
2171 const struct flow *flow, int vlan,
2172 struct xbundle *in_xbundle,
2173 const struct dp_packet *packet)
2175 struct mcast_snooping *ms = xbridge->ms;
2176 struct xlate_cfg *xcfg;
2177 struct xbundle *mcast_xbundle;
2178 struct mcast_port_bundle *fport;
2180 /* Don't learn the OFPP_NONE port. */
2181 if (in_xbundle == &ofpp_none_bundle) {
2185 /* Don't learn from flood ports */
2186 mcast_xbundle = NULL;
2187 ovs_rwlock_wrlock(&ms->rwlock);
2188 xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
2189 LIST_FOR_EACH(fport, node, &ms->fport_list) {
2190 mcast_xbundle = xbundle_lookup(xcfg, fport->port);
2191 if (mcast_xbundle == in_xbundle) {
2196 if (!mcast_xbundle || mcast_xbundle != in_xbundle) {
2197 if (flow->dl_type == htons(ETH_TYPE_IP)) {
2198 update_mcast_snooping_table4__(xbridge, flow, ms, vlan,
2199 in_xbundle, packet);
2201 update_mcast_snooping_table6__(xbridge, flow, ms, vlan,
2202 in_xbundle, packet);
2205 ovs_rwlock_unlock(&ms->rwlock);
2208 /* send the packet to ports having the multicast group learned */
2210 xlate_normal_mcast_send_group(struct xlate_ctx *ctx,
2211 struct mcast_snooping *ms OVS_UNUSED,
2212 struct mcast_group *grp,
2213 struct xbundle *in_xbundle, uint16_t vlan)
2214 OVS_REQ_RDLOCK(ms->rwlock)
2216 struct xlate_cfg *xcfg;
2217 struct mcast_group_bundle *b;
2218 struct xbundle *mcast_xbundle;
2220 xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
2221 LIST_FOR_EACH(b, bundle_node, &grp->bundle_lru) {
2222 mcast_xbundle = xbundle_lookup(xcfg, b->port);
2223 if (mcast_xbundle && mcast_xbundle != in_xbundle) {
2224 xlate_report(ctx, "forwarding to mcast group port");
2225 output_normal(ctx, mcast_xbundle, vlan);
2226 } else if (!mcast_xbundle) {
2227 xlate_report(ctx, "mcast group port is unknown, dropping");
2229 xlate_report(ctx, "mcast group port is input port, dropping");
2234 /* send the packet to ports connected to multicast routers */
2236 xlate_normal_mcast_send_mrouters(struct xlate_ctx *ctx,
2237 struct mcast_snooping *ms,
2238 struct xbundle *in_xbundle, uint16_t vlan)
2239 OVS_REQ_RDLOCK(ms->rwlock)
2241 struct xlate_cfg *xcfg;
2242 struct mcast_mrouter_bundle *mrouter;
2243 struct xbundle *mcast_xbundle;
2245 xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
2246 LIST_FOR_EACH(mrouter, mrouter_node, &ms->mrouter_lru) {
2247 mcast_xbundle = xbundle_lookup(xcfg, mrouter->port);
2248 if (mcast_xbundle && mcast_xbundle != in_xbundle) {
2249 xlate_report(ctx, "forwarding to mcast router port");
2250 output_normal(ctx, mcast_xbundle, vlan);
2251 } else if (!mcast_xbundle) {
2252 xlate_report(ctx, "mcast router port is unknown, dropping");
2254 xlate_report(ctx, "mcast router port is input port, dropping");
2259 /* send the packet to ports flagged to be flooded */
2261 xlate_normal_mcast_send_fports(struct xlate_ctx *ctx,
2262 struct mcast_snooping *ms,
2263 struct xbundle *in_xbundle, uint16_t vlan)
2264 OVS_REQ_RDLOCK(ms->rwlock)
2266 struct xlate_cfg *xcfg;
2267 struct mcast_port_bundle *fport;
2268 struct xbundle *mcast_xbundle;
2270 xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
2271 LIST_FOR_EACH(fport, node, &ms->fport_list) {
2272 mcast_xbundle = xbundle_lookup(xcfg, fport->port);
2273 if (mcast_xbundle && mcast_xbundle != in_xbundle) {
2274 xlate_report(ctx, "forwarding to mcast flood port");
2275 output_normal(ctx, mcast_xbundle, vlan);
2276 } else if (!mcast_xbundle) {
2277 xlate_report(ctx, "mcast flood port is unknown, dropping");
2279 xlate_report(ctx, "mcast flood port is input port, dropping");
2284 /* forward the Reports to configured ports */
2286 xlate_normal_mcast_send_rports(struct xlate_ctx *ctx,
2287 struct mcast_snooping *ms,
2288 struct xbundle *in_xbundle, uint16_t vlan)
2289 OVS_REQ_RDLOCK(ms->rwlock)
2291 struct xlate_cfg *xcfg;
2292 struct mcast_port_bundle *rport;
2293 struct xbundle *mcast_xbundle;
2295 xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
2296 LIST_FOR_EACH(rport, node, &ms->rport_list) {
2297 mcast_xbundle = xbundle_lookup(xcfg, rport->port);
2298 if (mcast_xbundle && mcast_xbundle != in_xbundle) {
2299 xlate_report(ctx, "forwarding Report to mcast flagged port");
2300 output_normal(ctx, mcast_xbundle, vlan);
2301 } else if (!mcast_xbundle) {
2302 xlate_report(ctx, "mcast port is unknown, dropping the Report");
2304 xlate_report(ctx, "mcast port is input port, dropping the Report");
2310 xlate_normal_flood(struct xlate_ctx *ctx, struct xbundle *in_xbundle,
2313 struct xbundle *xbundle;
2315 LIST_FOR_EACH (xbundle, list_node, &ctx->xbridge->xbundles) {
2316 if (xbundle != in_xbundle
2317 && xbundle_includes_vlan(xbundle, vlan)
2318 && xbundle->floodable
2319 && !xbundle_mirror_out(ctx->xbridge, xbundle)) {
2320 output_normal(ctx, xbundle, vlan);
2323 ctx->nf_output_iface = NF_OUT_FLOOD;
2327 xlate_normal(struct xlate_ctx *ctx)
2329 struct flow_wildcards *wc = ctx->wc;
2330 struct flow *flow = &ctx->xin->flow;
2331 struct xbundle *in_xbundle;
2332 struct xport *in_port;
2333 struct mac_entry *mac;
2338 memset(&wc->masks.dl_src, 0xff, sizeof wc->masks.dl_src);
2339 memset(&wc->masks.dl_dst, 0xff, sizeof wc->masks.dl_dst);
2340 wc->masks.vlan_tci |= htons(VLAN_VID_MASK | VLAN_CFI);
2342 in_xbundle = lookup_input_bundle(ctx->xbridge, flow->in_port.ofp_port,
2343 ctx->xin->packet != NULL, &in_port);
2345 xlate_report(ctx, "no input bundle, dropping");
2349 /* Drop malformed frames. */
2350 if (flow->dl_type == htons(ETH_TYPE_VLAN) &&
2351 !(flow->vlan_tci & htons(VLAN_CFI))) {
2352 if (ctx->xin->packet != NULL) {
2353 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
2354 VLOG_WARN_RL(&rl, "bridge %s: dropping packet with partial "
2355 "VLAN tag received on port %s",
2356 ctx->xbridge->name, in_xbundle->name);
2358 xlate_report(ctx, "partial VLAN tag, dropping");
2362 /* Drop frames on bundles reserved for mirroring. */
2363 if (xbundle_mirror_out(ctx->xbridge, in_xbundle)) {
2364 if (ctx->xin->packet != NULL) {
2365 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
2366 VLOG_WARN_RL(&rl, "bridge %s: dropping packet received on port "
2367 "%s, which is reserved exclusively for mirroring",
2368 ctx->xbridge->name, in_xbundle->name);
2370 xlate_report(ctx, "input port is mirror output port, dropping");
2375 vid = vlan_tci_to_vid(flow->vlan_tci);
2376 if (!input_vid_is_valid(vid, in_xbundle, ctx->xin->packet != NULL)) {
2377 xlate_report(ctx, "disallowed VLAN VID for this input port, dropping");
2380 vlan = input_vid_to_vlan(in_xbundle, vid);
2382 /* Check other admissibility requirements. */
2383 if (in_port && !is_admissible(ctx, in_port, vlan)) {
2387 /* Learn source MAC. */
2388 if (ctx->xin->may_learn) {
2389 update_learning_table(ctx->xbridge, flow, wc, vlan, in_xbundle);
2391 if (ctx->xin->xcache) {
2392 struct xc_entry *entry;
2394 /* Save enough info to update mac learning table later. */
2395 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_NORMAL);
2396 entry->u.normal.ofproto = ctx->xbridge->ofproto;
2397 entry->u.normal.flow = xmemdup(flow, sizeof *flow);
2398 entry->u.normal.vlan = vlan;
2401 /* Determine output bundle. */
2402 if (mcast_snooping_enabled(ctx->xbridge->ms)
2403 && !eth_addr_is_broadcast(flow->dl_dst)
2404 && eth_addr_is_multicast(flow->dl_dst)
2405 && is_ip_any(flow)) {
2406 struct mcast_snooping *ms = ctx->xbridge->ms;
2407 struct mcast_group *grp = NULL;
2409 if (is_igmp(flow)) {
2410 if (mcast_snooping_is_membership(flow->tp_src) ||
2411 mcast_snooping_is_query(flow->tp_src)) {
2412 if (ctx->xin->may_learn) {
2413 update_mcast_snooping_table(ctx->xbridge, flow, vlan,
2414 in_xbundle, ctx->xin->packet);
2417 * IGMP packets need to take the slow path, in order to be
2418 * processed for mdb updates. That will prevent expires
2419 * firing off even after hosts have sent reports.
2421 ctx->xout->slow |= SLOW_ACTION;
2424 if (mcast_snooping_is_membership(flow->tp_src)) {
2425 ovs_rwlock_rdlock(&ms->rwlock);
2426 xlate_normal_mcast_send_mrouters(ctx, ms, in_xbundle, vlan);
2427 /* RFC4541: section 2.1.1, item 1: A snooping switch should
2428 * forward IGMP Membership Reports only to those ports where
2429 * multicast routers are attached. Alternatively stated: a
2430 * snooping switch should not forward IGMP Membership Reports
2431 * to ports on which only hosts are attached.
2432 * An administrative control may be provided to override this
2433 * restriction, allowing the report messages to be flooded to
2435 xlate_normal_mcast_send_rports(ctx, ms, in_xbundle, vlan);
2436 ovs_rwlock_unlock(&ms->rwlock);
2438 xlate_report(ctx, "multicast traffic, flooding");
2439 xlate_normal_flood(ctx, in_xbundle, vlan);
2442 } else if (is_mld(flow)) {
2443 ctx->xout->slow |= SLOW_ACTION;
2444 if (ctx->xin->may_learn) {
2445 update_mcast_snooping_table(ctx->xbridge, flow, vlan,
2446 in_xbundle, ctx->xin->packet);
2448 if (is_mld_report(flow)) {
2449 ovs_rwlock_rdlock(&ms->rwlock);
2450 xlate_normal_mcast_send_mrouters(ctx, ms, in_xbundle, vlan);
2451 xlate_normal_mcast_send_rports(ctx, ms, in_xbundle, vlan);
2452 ovs_rwlock_unlock(&ms->rwlock);
2454 xlate_report(ctx, "MLD query, flooding");
2455 xlate_normal_flood(ctx, in_xbundle, vlan);
2458 if ((flow->dl_type == htons(ETH_TYPE_IP)
2459 && ip_is_local_multicast(flow->nw_dst))
2460 || (flow->dl_type == htons(ETH_TYPE_IPV6)
2461 && ipv6_is_all_hosts(&flow->ipv6_dst))) {
2462 /* RFC4541: section 2.1.2, item 2: Packets with a dst IP
2463 * address in the 224.0.0.x range which are not IGMP must
2464 * be forwarded on all ports */
2465 xlate_report(ctx, "RFC4541: section 2.1.2, item 2, flooding");
2466 xlate_normal_flood(ctx, in_xbundle, vlan);
2471 /* forwarding to group base ports */
2472 ovs_rwlock_rdlock(&ms->rwlock);
2473 if (flow->dl_type == htons(ETH_TYPE_IP)) {
2474 grp = mcast_snooping_lookup4(ms, flow->nw_dst, vlan);
2475 } else if (flow->dl_type == htons(ETH_TYPE_IPV6)) {
2476 grp = mcast_snooping_lookup(ms, &flow->ipv6_dst, vlan);
2479 xlate_normal_mcast_send_group(ctx, ms, grp, in_xbundle, vlan);
2480 xlate_normal_mcast_send_fports(ctx, ms, in_xbundle, vlan);
2481 xlate_normal_mcast_send_mrouters(ctx, ms, in_xbundle, vlan);
2483 if (mcast_snooping_flood_unreg(ms)) {
2484 xlate_report(ctx, "unregistered multicast, flooding");
2485 xlate_normal_flood(ctx, in_xbundle, vlan);
2487 xlate_normal_mcast_send_mrouters(ctx, ms, in_xbundle, vlan);
2488 xlate_normal_mcast_send_fports(ctx, ms, in_xbundle, vlan);
2491 ovs_rwlock_unlock(&ms->rwlock);
2493 ovs_rwlock_rdlock(&ctx->xbridge->ml->rwlock);
2494 mac = mac_learning_lookup(ctx->xbridge->ml, flow->dl_dst, vlan);
2495 mac_port = mac ? mac_entry_get_port(ctx->xbridge->ml, mac) : NULL;
2496 ovs_rwlock_unlock(&ctx->xbridge->ml->rwlock);
2499 struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
2500 struct xbundle *mac_xbundle = xbundle_lookup(xcfg, mac_port);
2501 if (mac_xbundle && mac_xbundle != in_xbundle) {
2502 xlate_report(ctx, "forwarding to learned port");
2503 output_normal(ctx, mac_xbundle, vlan);
2504 } else if (!mac_xbundle) {
2505 xlate_report(ctx, "learned port is unknown, dropping");
2507 xlate_report(ctx, "learned port is input port, dropping");
2510 xlate_report(ctx, "no learned MAC for destination, flooding");
2511 xlate_normal_flood(ctx, in_xbundle, vlan);
2516 /* Appends a "sample" action for sFlow or IPFIX to 'ctx->odp_actions'. The
2517 * 'probability' is the number of packets out of UINT32_MAX to sample. The
2518 * 'cookie' (of length 'cookie_size' bytes) is passed back in the callback for
2519 * each sampled packet. 'tunnel_out_port', if not ODPP_NONE, is added as the
2520 * OVS_USERSPACE_ATTR_EGRESS_TUN_PORT attribute. If 'include_actions', an
2521 * OVS_USERSPACE_ATTR_ACTIONS attribute is added.
2524 compose_sample_action(struct xlate_ctx *ctx,
2525 const uint32_t probability,
2526 const union user_action_cookie *cookie,
2527 const size_t cookie_size,
2528 const odp_port_t tunnel_out_port,
2529 bool include_actions)
2531 size_t sample_offset = nl_msg_start_nested(ctx->odp_actions,
2532 OVS_ACTION_ATTR_SAMPLE);
2534 nl_msg_put_u32(ctx->odp_actions, OVS_SAMPLE_ATTR_PROBABILITY, probability);
2536 size_t actions_offset = nl_msg_start_nested(ctx->odp_actions,
2537 OVS_SAMPLE_ATTR_ACTIONS);
2539 odp_port_t odp_port = ofp_port_to_odp_port(
2540 ctx->xbridge, ctx->xin->flow.in_port.ofp_port);
2541 uint32_t pid = dpif_port_get_pid(ctx->xbridge->dpif, odp_port,
2542 flow_hash_5tuple(&ctx->xin->flow, 0));
2543 int cookie_offset = odp_put_userspace_action(pid, cookie, cookie_size,
2548 nl_msg_end_nested(ctx->odp_actions, actions_offset);
2549 nl_msg_end_nested(ctx->odp_actions, sample_offset);
2551 return cookie_offset;
2554 /* If sFLow is not enabled, returns 0 without doing anything.
2556 * If sFlow is enabled, appends a template "sample" action to the ODP actions
2557 * in 'ctx'. This action is a template because some of the information needed
2558 * to fill it out is not available until flow translation is complete. In this
2559 * case, this functions returns an offset, which is always nonzero, to pass
2560 * later to fix_sflow_action() to fill in the rest of the template. */
2562 compose_sflow_action(struct xlate_ctx *ctx)
2564 struct dpif_sflow *sflow = ctx->xbridge->sflow;
2565 if (!sflow || ctx->xin->flow.in_port.ofp_port == OFPP_NONE) {
2569 union user_action_cookie cookie = { .type = USER_ACTION_COOKIE_SFLOW };
2570 return compose_sample_action(ctx, dpif_sflow_get_probability(sflow),
2571 &cookie, sizeof cookie.sflow, ODPP_NONE,
2575 /* If IPFIX is enabled, this appends a "sample" action to implement IPFIX to
2576 * 'ctx->odp_actions'. */
2578 compose_ipfix_action(struct xlate_ctx *ctx, odp_port_t output_odp_port)
2580 struct dpif_ipfix *ipfix = ctx->xbridge->ipfix;
2581 odp_port_t tunnel_out_port = ODPP_NONE;
2583 if (!ipfix || ctx->xin->flow.in_port.ofp_port == OFPP_NONE) {
2587 /* For input case, output_odp_port is ODPP_NONE, which is an invalid port
2589 if (output_odp_port == ODPP_NONE &&
2590 !dpif_ipfix_get_bridge_exporter_input_sampling(ipfix)) {
2594 /* For output case, output_odp_port is valid*/
2595 if (output_odp_port != ODPP_NONE) {
2596 if (!dpif_ipfix_get_bridge_exporter_output_sampling(ipfix)) {
2599 /* If tunnel sampling is enabled, put an additional option attribute:
2600 * OVS_USERSPACE_ATTR_TUNNEL_OUT_PORT
2602 if (dpif_ipfix_get_bridge_exporter_tunnel_sampling(ipfix) &&
2603 dpif_ipfix_get_tunnel_port(ipfix, output_odp_port) ) {
2604 tunnel_out_port = output_odp_port;
2608 union user_action_cookie cookie = {
2610 .type = USER_ACTION_COOKIE_IPFIX,
2611 .output_odp_port = output_odp_port,
2614 compose_sample_action(ctx,
2615 dpif_ipfix_get_bridge_exporter_probability(ipfix),
2616 &cookie, sizeof cookie.ipfix, tunnel_out_port,
2620 /* Fix "sample" action according to data collected while composing ODP actions,
2621 * as described in compose_sflow_action().
2623 * 'user_cookie_offset' must be the offset returned by add_sflow_action(). */
2625 fix_sflow_action(struct xlate_ctx *ctx, unsigned int user_cookie_offset)
2627 const struct flow *base = &ctx->base_flow;
2628 union user_action_cookie *cookie;
2630 cookie = ofpbuf_at(ctx->odp_actions, user_cookie_offset,
2631 sizeof cookie->sflow);
2632 ovs_assert(cookie->type == USER_ACTION_COOKIE_SFLOW);
2634 cookie->type = USER_ACTION_COOKIE_SFLOW;
2635 cookie->sflow.vlan_tci = base->vlan_tci;
2637 /* See http://www.sflow.org/sflow_version_5.txt (search for "Input/output
2638 * port information") for the interpretation of cookie->output. */
2639 switch (ctx->sflow_n_outputs) {
2641 /* 0x40000000 | 256 means "packet dropped for unknown reason". */
2642 cookie->sflow.output = 0x40000000 | 256;
2646 cookie->sflow.output = dpif_sflow_odp_port_to_ifindex(
2647 ctx->xbridge->sflow, ctx->sflow_odp_port);
2648 if (cookie->sflow.output) {
2653 /* 0x80000000 means "multiple output ports. */
2654 cookie->sflow.output = 0x80000000 | ctx->sflow_n_outputs;
2660 process_special(struct xlate_ctx *ctx, const struct xport *xport)
2662 const struct flow *flow = &ctx->xin->flow;
2663 struct flow_wildcards *wc = ctx->wc;
2664 const struct xbridge *xbridge = ctx->xbridge;
2665 const struct dp_packet *packet = ctx->xin->packet;
2666 enum slow_path_reason slow;
2670 } else if (xport->cfm && cfm_should_process_flow(xport->cfm, flow, wc)) {
2672 cfm_process_heartbeat(xport->cfm, packet);
2675 } else if (xport->bfd && bfd_should_process_flow(xport->bfd, flow, wc)) {
2677 bfd_process_packet(xport->bfd, flow, packet);
2678 /* If POLL received, immediately sends FINAL back. */
2679 if (bfd_should_send_packet(xport->bfd)) {
2680 ofproto_dpif_monitor_port_send_soon(xport->ofport);
2684 } else if (xport->xbundle && xport->xbundle->lacp
2685 && flow->dl_type == htons(ETH_TYPE_LACP)) {
2687 lacp_process_packet(xport->xbundle->lacp, xport->ofport, packet);
2690 } else if ((xbridge->stp || xbridge->rstp) &&
2691 stp_should_process_flow(flow, wc)) {
2694 ? stp_process_packet(xport, packet)
2695 : rstp_process_packet(xport, packet);
2698 } else if (xport->lldp && lldp_should_process_flow(xport->lldp, flow)) {
2700 lldp_process_packet(xport->lldp, packet);
2708 ctx->xout->slow |= slow;
2716 tnl_route_lookup_flow(const struct flow *oflow,
2717 struct in6_addr *ip, struct xport **out_port)
2719 char out_dev[IFNAMSIZ];
2720 struct xbridge *xbridge;
2721 struct xlate_cfg *xcfg;
2723 struct in6_addr dst;
2725 dst = flow_tnl_dst(&oflow->tunnel);
2726 if (!ovs_router_lookup(&dst, out_dev, &gw)) {
2730 if (ipv6_addr_is_set(&gw) &&
2731 (!IN6_IS_ADDR_V4MAPPED(&gw) || in6_addr_get_mapped_ipv4(&gw))) {
2737 xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
2740 HMAP_FOR_EACH (xbridge, hmap_node, &xcfg->xbridges) {
2741 if (!strncmp(xbridge->name, out_dev, IFNAMSIZ)) {
2744 HMAP_FOR_EACH (port, ofp_node, &xbridge->xports) {
2745 if (!strncmp(netdev_get_name(port->netdev), out_dev, IFNAMSIZ)) {
2756 compose_table_xlate(struct xlate_ctx *ctx, const struct xport *out_dev,
2757 struct dp_packet *packet)
2759 struct xbridge *xbridge = out_dev->xbridge;
2760 struct ofpact_output output;
2763 ofpact_init(&output.ofpact, OFPACT_OUTPUT, sizeof output);
2764 flow_extract(packet, &flow);
2765 flow.in_port.ofp_port = out_dev->ofp_port;
2766 output.port = OFPP_TABLE;
2769 return ofproto_dpif_execute_actions__(xbridge->ofproto, &flow, NULL,
2770 &output.ofpact, sizeof output,
2771 ctx->recurse, ctx->resubmits, packet);
2775 tnl_send_nd_request(struct xlate_ctx *ctx, const struct xport *out_dev,
2776 const struct eth_addr eth_src,
2777 struct in6_addr * ipv6_src, struct in6_addr * ipv6_dst)
2779 struct dp_packet packet;
2781 dp_packet_init(&packet, 0);
2782 compose_nd(&packet, eth_src, ipv6_src, ipv6_dst);
2783 compose_table_xlate(ctx, out_dev, &packet);
2784 dp_packet_uninit(&packet);
2788 tnl_send_arp_request(struct xlate_ctx *ctx, const struct xport *out_dev,
2789 const struct eth_addr eth_src,
2790 ovs_be32 ip_src, ovs_be32 ip_dst)
2792 struct dp_packet packet;
2794 dp_packet_init(&packet, 0);
2795 compose_arp(&packet, ARP_OP_REQUEST,
2796 eth_src, eth_addr_zero, true, ip_src, ip_dst);
2798 compose_table_xlate(ctx, out_dev, &packet);
2799 dp_packet_uninit(&packet);
2803 build_tunnel_send(struct xlate_ctx *ctx, const struct xport *xport,
2804 const struct flow *flow, odp_port_t tunnel_odp_port)
2806 struct ovs_action_push_tnl tnl_push_data;
2807 struct xport *out_dev = NULL;
2808 ovs_be32 s_ip = 0, d_ip = 0;
2809 struct in6_addr s_ip6 = in6addr_any;
2810 struct in6_addr d_ip6 = in6addr_any;
2811 struct eth_addr smac;
2812 struct eth_addr dmac;
2814 char buf_sip6[INET6_ADDRSTRLEN];
2815 char buf_dip6[INET6_ADDRSTRLEN];
2817 err = tnl_route_lookup_flow(flow, &d_ip6, &out_dev);
2819 xlate_report(ctx, "native tunnel routing failed");
2823 xlate_report(ctx, "tunneling to %s via %s",
2824 ipv6_string_mapped(buf_dip6, &d_ip6),
2825 netdev_get_name(out_dev->netdev));
2827 /* Use mac addr of bridge port of the peer. */
2828 err = netdev_get_etheraddr(out_dev->netdev, &smac);
2830 xlate_report(ctx, "tunnel output device lacks Ethernet address");
2834 d_ip = in6_addr_get_mapped_ipv4(&d_ip6);
2836 err = netdev_get_in4(out_dev->netdev, (struct in_addr *) &s_ip, NULL);
2838 xlate_report(ctx, "tunnel output device lacks IPv4 address");
2841 in6_addr_set_mapped_ipv4(&s_ip6, s_ip);
2843 err = netdev_get_in6(out_dev->netdev, &s_ip6);
2845 xlate_report(ctx, "tunnel output device lacks IPv6 address");
2850 err = tnl_neigh_lookup(out_dev->xbridge->name, &d_ip6, &dmac);
2852 xlate_report(ctx, "neighbor cache miss for %s on bridge %s, "
2853 "sending %s request",
2854 buf_dip6, out_dev->xbridge->name, d_ip ? "ARP" : "ND");
2856 tnl_send_arp_request(ctx, out_dev, smac, s_ip, d_ip);
2858 tnl_send_nd_request(ctx, out_dev, smac, &s_ip6, &d_ip6);
2863 if (ctx->xin->xcache) {
2864 struct xc_entry *entry;
2866 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_TNL_NEIGH);
2867 ovs_strlcpy(entry->u.tnl_neigh_cache.br_name, out_dev->xbridge->name,
2868 sizeof entry->u.tnl_neigh_cache.br_name);
2869 entry->u.tnl_neigh_cache.d_ipv6 = d_ip6;
2872 xlate_report(ctx, "tunneling from "ETH_ADDR_FMT" %s"
2873 " to "ETH_ADDR_FMT" %s",
2874 ETH_ADDR_ARGS(smac), ipv6_string_mapped(buf_sip6, &s_ip6),
2875 ETH_ADDR_ARGS(dmac), buf_dip6);
2877 err = tnl_port_build_header(xport->ofport, flow,
2878 dmac, smac, &s_ip6, &tnl_push_data);
2882 tnl_push_data.tnl_port = odp_to_u32(tunnel_odp_port);
2883 tnl_push_data.out_port = odp_to_u32(out_dev->odp_port);
2884 odp_put_tnl_push_action(ctx->odp_actions, &tnl_push_data);
2889 xlate_commit_actions(struct xlate_ctx *ctx)
2891 bool use_masked = ctx->xbridge->support.masked_set_action;
2893 ctx->xout->slow |= commit_odp_actions(&ctx->xin->flow, &ctx->base_flow,
2894 ctx->odp_actions, ctx->wc,
2899 clear_conntrack(struct flow *flow)
2904 memset(&flow->ct_label, 0, sizeof flow->ct_label);
2908 compose_output_action__(struct xlate_ctx *ctx, ofp_port_t ofp_port,
2909 const struct xlate_bond_recirc *xr, bool check_stp)
2911 const struct xport *xport = get_ofp_port(ctx->xbridge, ofp_port);
2912 struct flow_wildcards *wc = ctx->wc;
2913 struct flow *flow = &ctx->xin->flow;
2914 struct flow_tnl flow_tnl;
2915 ovs_be16 flow_vlan_tci;
2916 uint32_t flow_pkt_mark;
2917 uint8_t flow_nw_tos;
2918 odp_port_t out_port, odp_port;
2919 bool tnl_push_pop_send = false;
2922 /* If 'struct flow' gets additional metadata, we'll need to zero it out
2923 * before traversing a patch port. */
2924 BUILD_ASSERT_DECL(FLOW_WC_SEQ == 35);
2925 memset(&flow_tnl, 0, sizeof flow_tnl);
2928 xlate_report(ctx, "Nonexistent output port");
2930 } else if (xport->config & OFPUTIL_PC_NO_FWD) {
2931 xlate_report(ctx, "OFPPC_NO_FWD set, skipping output");
2933 } else if (check_stp) {
2934 if (is_stp(&ctx->base_flow)) {
2935 if (!xport_stp_should_forward_bpdu(xport) &&
2936 !xport_rstp_should_manage_bpdu(xport)) {
2937 if (ctx->xbridge->stp != NULL) {
2938 xlate_report(ctx, "STP not in listening state, "
2939 "skipping bpdu output");
2940 } else if (ctx->xbridge->rstp != NULL) {
2941 xlate_report(ctx, "RSTP not managing BPDU in this state, "
2942 "skipping bpdu output");
2946 } else if (!xport_stp_forward_state(xport) ||
2947 !xport_rstp_forward_state(xport)) {
2948 if (ctx->xbridge->stp != NULL) {
2949 xlate_report(ctx, "STP not in forwarding state, "
2951 } else if (ctx->xbridge->rstp != NULL) {
2952 xlate_report(ctx, "RSTP not in forwarding state, "
2960 const struct xport *peer = xport->peer;
2961 struct flow old_flow = ctx->xin->flow;
2962 bool old_conntrack = ctx->conntracked;
2963 bool old_was_mpls = ctx->was_mpls;
2964 cls_version_t old_version = ctx->tables_version;
2965 struct ofpbuf old_stack = ctx->stack;
2966 union mf_subvalue new_stack[1024 / sizeof(union mf_subvalue)];
2967 struct ofpbuf old_action_set = ctx->action_set;
2968 uint64_t actset_stub[1024 / 8];
2970 ofpbuf_use_stub(&ctx->stack, new_stack, sizeof new_stack);
2971 ofpbuf_use_stub(&ctx->action_set, actset_stub, sizeof actset_stub);
2972 ctx->xbridge = peer->xbridge;
2973 flow->in_port.ofp_port = peer->ofp_port;
2974 flow->metadata = htonll(0);
2975 memset(&flow->tunnel, 0, sizeof flow->tunnel);
2976 memset(flow->regs, 0, sizeof flow->regs);
2977 flow->actset_output = OFPP_UNSET;
2978 ctx->conntracked = false;
2979 clear_conntrack(flow);
2981 /* The bridge is now known so obtain its table version. */
2983 = ofproto_dpif_get_tables_version(ctx->xbridge->ofproto);
2985 if (!process_special(ctx, peer) && may_receive(peer, ctx)) {
2986 if (xport_stp_forward_state(peer) && xport_rstp_forward_state(peer)) {
2987 xlate_table_action(ctx, flow->in_port.ofp_port, 0, true, true);
2988 if (ctx->action_set.size) {
2989 /* Translate action set only if not dropping the packet and
2990 * not recirculating. */
2991 if (!exit_recirculates(ctx)) {
2992 xlate_action_set(ctx);
2995 /* Check if need to recirculate. */
2996 if (exit_recirculates(ctx)) {
2997 compose_recirculate_action(ctx);
3000 /* Forwarding is disabled by STP and RSTP. Let OFPP_NORMAL and
3001 * the learning action look at the packet, then drop it. */
3002 struct flow old_base_flow = ctx->base_flow;
3003 size_t old_size = ctx->odp_actions->size;
3004 mirror_mask_t old_mirrors = ctx->mirrors;
3006 xlate_table_action(ctx, flow->in_port.ofp_port, 0, true, true);
3007 ctx->mirrors = old_mirrors;
3008 ctx->base_flow = old_base_flow;
3009 ctx->odp_actions->size = old_size;
3011 /* Undo changes that may have been done for recirculation. */
3012 if (exit_recirculates(ctx)) {
3013 ctx->action_set.size = ctx->recirc_action_offset;
3014 ctx->recirc_action_offset = -1;
3015 ctx->last_unroll_offset = -1;
3020 ctx->xin->flow = old_flow;
3021 ctx->xbridge = xport->xbridge;
3022 ofpbuf_uninit(&ctx->action_set);
3023 ctx->action_set = old_action_set;
3024 ofpbuf_uninit(&ctx->stack);
3025 ctx->stack = old_stack;
3027 /* Restore calling bridge's lookup version. */
3028 ctx->tables_version = old_version;
3030 /* The peer bridge popping MPLS should have no effect on the original
3032 ctx->was_mpls = old_was_mpls;
3034 /* The peer bridge's conntrack execution should have no effect on the
3035 * original bridge. */
3036 ctx->conntracked = old_conntrack;
3038 /* The fact that the peer bridge exits (for any reason) does not mean
3039 * that the original bridge should exit. Specifically, if the peer
3040 * bridge recirculates (which typically modifies the packet), the
3041 * original bridge must continue processing with the original, not the
3042 * recirculated packet! */
3045 /* Peer bridge errors do not propagate back. */
3046 ctx->error = XLATE_OK;
3048 if (ctx->xin->resubmit_stats) {
3049 netdev_vport_inc_tx(xport->netdev, ctx->xin->resubmit_stats);
3050 netdev_vport_inc_rx(peer->netdev, ctx->xin->resubmit_stats);
3052 bfd_account_rx(peer->bfd, ctx->xin->resubmit_stats);
3055 if (ctx->xin->xcache) {
3056 struct xc_entry *entry;
3058 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_NETDEV);
3059 entry->u.dev.tx = netdev_ref(xport->netdev);
3060 entry->u.dev.rx = netdev_ref(peer->netdev);
3061 entry->u.dev.bfd = bfd_ref(peer->bfd);
3066 flow_vlan_tci = flow->vlan_tci;
3067 flow_pkt_mark = flow->pkt_mark;
3068 flow_nw_tos = flow->nw_tos;
3070 if (count_skb_priorities(xport)) {
3071 memset(&wc->masks.skb_priority, 0xff, sizeof wc->masks.skb_priority);
3072 if (dscp_from_skb_priority(xport, flow->skb_priority, &dscp)) {
3073 wc->masks.nw_tos |= IP_DSCP_MASK;
3074 flow->nw_tos &= ~IP_DSCP_MASK;
3075 flow->nw_tos |= dscp;
3079 if (xport->is_tunnel) {
3080 struct in6_addr dst;
3081 /* Save tunnel metadata so that changes made due to
3082 * the Logical (tunnel) Port are not visible for any further
3083 * matches, while explicit set actions on tunnel metadata are.
3085 flow_tnl = flow->tunnel;
3086 odp_port = tnl_port_send(xport->ofport, flow, ctx->wc);
3087 if (odp_port == ODPP_NONE) {
3088 xlate_report(ctx, "Tunneling decided against output");
3089 goto out; /* restore flow_nw_tos */
3091 dst = flow_tnl_dst(&flow->tunnel);
3092 if (ipv6_addr_equals(&dst, &ctx->orig_tunnel_ipv6_dst)) {
3093 xlate_report(ctx, "Not tunneling to our own address");
3094 goto out; /* restore flow_nw_tos */
3096 if (ctx->xin->resubmit_stats) {
3097 netdev_vport_inc_tx(xport->netdev, ctx->xin->resubmit_stats);
3099 if (ctx->xin->xcache) {
3100 struct xc_entry *entry;
3102 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_NETDEV);
3103 entry->u.dev.tx = netdev_ref(xport->netdev);
3105 out_port = odp_port;
3106 if (ovs_native_tunneling_is_on(ctx->xbridge->ofproto)) {
3107 xlate_report(ctx, "output to native tunnel");
3108 tnl_push_pop_send = true;
3110 xlate_report(ctx, "output to kernel tunnel");
3111 commit_odp_tunnel_action(flow, &ctx->base_flow, ctx->odp_actions);
3112 flow->tunnel = flow_tnl; /* Restore tunnel metadata */
3115 odp_port = xport->odp_port;
3116 out_port = odp_port;
3117 if (ofproto_has_vlan_splinters(ctx->xbridge->ofproto)) {
3118 ofp_port_t vlandev_port;
3120 wc->masks.vlan_tci |= htons(VLAN_VID_MASK | VLAN_CFI);
3121 vlandev_port = vsp_realdev_to_vlandev(ctx->xbridge->ofproto,
3122 ofp_port, flow->vlan_tci);
3123 if (vlandev_port != ofp_port) {
3124 out_port = ofp_port_to_odp_port(ctx->xbridge, vlandev_port);
3125 flow->vlan_tci = htons(0);
3130 if (out_port != ODPP_NONE) {
3131 xlate_commit_actions(ctx);
3134 struct ovs_action_hash *act_hash;
3137 act_hash = nl_msg_put_unspec_uninit(ctx->odp_actions,
3138 OVS_ACTION_ATTR_HASH,
3140 act_hash->hash_alg = xr->hash_alg;
3141 act_hash->hash_basis = xr->hash_basis;
3143 /* Recirc action. */
3144 nl_msg_put_u32(ctx->odp_actions, OVS_ACTION_ATTR_RECIRC,
3148 if (tnl_push_pop_send) {
3149 build_tunnel_send(ctx, xport, flow, odp_port);
3150 flow->tunnel = flow_tnl; /* Restore tunnel metadata */
3152 odp_port_t odp_tnl_port = ODPP_NONE;
3154 /* XXX: Write better Filter for tunnel port. We can use inport
3155 * int tunnel-port flow to avoid these checks completely. */
3156 if (ofp_port == OFPP_LOCAL &&
3157 ovs_native_tunneling_is_on(ctx->xbridge->ofproto)) {
3159 odp_tnl_port = tnl_port_map_lookup(flow, wc);
3162 if (odp_tnl_port != ODPP_NONE) {
3163 nl_msg_put_odp_port(ctx->odp_actions,
3164 OVS_ACTION_ATTR_TUNNEL_POP,
3167 /* Tunnel push-pop action is not compatible with
3169 compose_ipfix_action(ctx, out_port);
3170 nl_msg_put_odp_port(ctx->odp_actions,
3171 OVS_ACTION_ATTR_OUTPUT,
3177 ctx->sflow_odp_port = odp_port;
3178 ctx->sflow_n_outputs++;
3179 ctx->nf_output_iface = ofp_port;
3182 if (mbridge_has_mirrors(ctx->xbridge->mbridge) && xport->xbundle) {
3183 mirror_packet(ctx, xport->xbundle,
3184 xbundle_mirror_dst(xport->xbundle->xbridge,
3190 flow->vlan_tci = flow_vlan_tci;
3191 flow->pkt_mark = flow_pkt_mark;
3192 flow->nw_tos = flow_nw_tos;
3196 compose_output_action(struct xlate_ctx *ctx, ofp_port_t ofp_port,
3197 const struct xlate_bond_recirc *xr)
3199 compose_output_action__(ctx, ofp_port, xr, true);
3203 xlate_recursively(struct xlate_ctx *ctx, struct rule_dpif *rule)
3205 struct rule_dpif *old_rule = ctx->rule;
3206 ovs_be64 old_cookie = ctx->rule_cookie;
3207 const struct rule_actions *actions;
3209 if (ctx->xin->resubmit_stats) {
3210 rule_dpif_credit_stats(rule, ctx->xin->resubmit_stats);
3216 ctx->rule_cookie = rule_dpif_get_flow_cookie(rule);
3217 actions = rule_dpif_get_actions(rule);
3218 do_xlate_actions(actions->ofpacts, actions->ofpacts_len, ctx);
3219 ctx->rule_cookie = old_cookie;
3220 ctx->rule = old_rule;
3225 xlate_resubmit_resource_check(struct xlate_ctx *ctx)
3227 if (ctx->recurse >= MAX_RESUBMIT_RECURSION + MAX_INTERNAL_RESUBMITS) {
3228 XLATE_REPORT_ERROR(ctx, "resubmit actions recursed over %d times",
3229 MAX_RESUBMIT_RECURSION);
3230 ctx->error = XLATE_RECURSION_TOO_DEEP;
3231 } else if (ctx->resubmits >= MAX_RESUBMITS + MAX_INTERNAL_RESUBMITS) {
3232 XLATE_REPORT_ERROR(ctx, "over %d resubmit actions", MAX_RESUBMITS);
3233 ctx->error = XLATE_TOO_MANY_RESUBMITS;
3234 } else if (ctx->odp_actions->size > UINT16_MAX) {
3235 XLATE_REPORT_ERROR(ctx, "resubmits yielded over 64 kB of actions");
3236 /* NOT an error, as we'll be slow-pathing the flow in this case? */
3237 ctx->exit = true; /* XXX: translation still terminated! */
3238 } else if (ctx->stack.size >= 65536) {
3239 XLATE_REPORT_ERROR(ctx, "resubmits yielded over 64 kB of stack");
3240 ctx->error = XLATE_STACK_TOO_DEEP;
3249 xlate_table_action(struct xlate_ctx *ctx, ofp_port_t in_port, uint8_t table_id,
3250 bool may_packet_in, bool honor_table_miss)
3252 /* Check if we need to recirculate before matching in a table. */
3253 if (ctx->was_mpls) {
3254 ctx_trigger_recirculation(ctx);
3257 if (xlate_resubmit_resource_check(ctx)) {
3258 uint8_t old_table_id = ctx->table_id;
3259 struct rule_dpif *rule;
3261 ctx->table_id = table_id;
3263 rule = rule_dpif_lookup_from_table(ctx->xbridge->ofproto,
3264 ctx->tables_version,
3265 &ctx->xin->flow, ctx->xin->wc,
3266 ctx->xin->resubmit_stats,
3267 &ctx->table_id, in_port,
3268 may_packet_in, honor_table_miss);
3270 if (OVS_UNLIKELY(ctx->xin->resubmit_hook)) {
3271 ctx->xin->resubmit_hook(ctx->xin, rule, ctx->recurse + 1);
3275 /* Fill in the cache entry here instead of xlate_recursively
3276 * to make the reference counting more explicit. We take a
3277 * reference in the lookups above if we are going to cache the
3279 if (ctx->xin->xcache) {
3280 struct xc_entry *entry;
3282 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_RULE);
3283 entry->u.rule = rule;
3284 rule_dpif_ref(rule);
3286 xlate_recursively(ctx, rule);
3289 ctx->table_id = old_table_id;
3295 xlate_group_stats(struct xlate_ctx *ctx, struct group_dpif *group,
3296 struct ofputil_bucket *bucket)
3298 if (ctx->xin->resubmit_stats) {
3299 group_dpif_credit_stats(group, bucket, ctx->xin->resubmit_stats);
3301 if (ctx->xin->xcache) {
3302 struct xc_entry *entry;
3304 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_GROUP);
3305 entry->u.group.group = group_dpif_ref(group);
3306 entry->u.group.bucket = bucket;
3311 xlate_group_bucket(struct xlate_ctx *ctx, struct ofputil_bucket *bucket)
3313 uint64_t action_list_stub[1024 / 8];
3314 struct ofpbuf action_list, action_set;
3315 struct flow old_flow = ctx->xin->flow;
3316 bool old_was_mpls = ctx->was_mpls;
3318 ofpbuf_use_const(&action_set, bucket->ofpacts, bucket->ofpacts_len);
3319 ofpbuf_use_stub(&action_list, action_list_stub, sizeof action_list_stub);
3321 ofpacts_execute_action_set(&action_list, &action_set);
3323 do_xlate_actions(action_list.data, action_list.size, ctx);
3326 ofpbuf_uninit(&action_set);
3327 ofpbuf_uninit(&action_list);
3329 /* Check if need to recirculate. */
3330 if (exit_recirculates(ctx)) {
3331 compose_recirculate_action(ctx);
3334 /* Roll back flow to previous state.
3335 * This is equivalent to cloning the packet for each bucket.
3337 * As a side effect any subsequently applied actions will
3338 * also effectively be applied to a clone of the packet taken
3339 * just before applying the all or indirect group.
3341 * Note that group buckets are action sets, hence they cannot modify the
3342 * main action set. Also any stack actions are ignored when executing an
3343 * action set, so group buckets cannot change the stack either.
3344 * However, we do allow resubmit actions in group buckets, which could
3345 * break the above assumptions. It is up to the controller to not mess up
3346 * with the action_set and stack in the tables resubmitted to from
3348 ctx->xin->flow = old_flow;
3350 /* The group bucket popping MPLS should have no effect after bucket
3352 ctx->was_mpls = old_was_mpls;
3354 /* The fact that the group bucket exits (for any reason) does not mean that
3355 * the translation after the group action should exit. Specifically, if
3356 * the group bucket recirculates (which typically modifies the packet), the
3357 * actions after the group action must continue processing with the
3358 * original, not the recirculated packet! */
3363 xlate_all_group(struct xlate_ctx *ctx, struct group_dpif *group)
3365 struct ofputil_bucket *bucket;
3366 const struct ovs_list *buckets;
3368 group_dpif_get_buckets(group, &buckets);
3370 LIST_FOR_EACH (bucket, list_node, buckets) {
3371 xlate_group_bucket(ctx, bucket);
3373 xlate_group_stats(ctx, group, NULL);
3377 xlate_ff_group(struct xlate_ctx *ctx, struct group_dpif *group)
3379 struct ofputil_bucket *bucket;
3381 bucket = group_first_live_bucket(ctx, group, 0);
3383 xlate_group_bucket(ctx, bucket);
3384 xlate_group_stats(ctx, group, bucket);
3389 xlate_default_select_group(struct xlate_ctx *ctx, struct group_dpif *group)
3391 struct flow_wildcards *wc = ctx->wc;
3392 struct ofputil_bucket *bucket;
3395 basis = flow_hash_symmetric_l4(&ctx->xin->flow, 0);
3396 flow_mask_hash_fields(&ctx->xin->flow, wc, NX_HASH_FIELDS_SYMMETRIC_L4);
3397 bucket = group_best_live_bucket(ctx, group, basis);
3399 xlate_group_bucket(ctx, bucket);
3400 xlate_group_stats(ctx, group, bucket);
3405 xlate_hash_fields_select_group(struct xlate_ctx *ctx, struct group_dpif *group)
3407 struct mf_bitmap hash_fields = MF_BITMAP_INITIALIZER;
3408 const struct field_array *fields;
3409 struct ofputil_bucket *bucket;
3413 fields = group_dpif_get_fields(group);
3414 basis = hash_uint64(group_dpif_get_selection_method_param(group));
3416 /* Determine which fields to hash */
3417 for (i = 0; i < MFF_N_IDS; i++) {
3418 if (bitmap_is_set(fields->used.bm, i)) {
3419 const struct mf_field *mf;
3421 /* If the field is already present in 'hash_fields' then
3422 * this loop has already checked that it and its pre-requisites
3423 * are present in the flow and its pre-requisites have
3424 * already been added to 'hash_fields'. There is nothing more
3425 * to do here and as an optimisation the loop can continue. */
3426 if (bitmap_is_set(hash_fields.bm, i)) {
3432 /* Only hash a field if it and its pre-requisites are present
3434 if (!mf_are_prereqs_ok(mf, &ctx->xin->flow)) {
3438 /* Hash both the field and its pre-requisites */
3439 mf_bitmap_set_field_and_prereqs(mf, &hash_fields);
3443 /* Hash the fields */
3444 for (i = 0; i < MFF_N_IDS; i++) {
3445 if (bitmap_is_set(hash_fields.bm, i)) {
3446 const struct mf_field *mf = mf_from_id(i);
3447 union mf_value value;
3450 mf_get_value(mf, &ctx->xin->flow, &value);
3451 /* This seems inefficient but so does apply_mask() */
3452 for (j = 0; j < mf->n_bytes; j++) {
3453 ((uint8_t *) &value)[j] &= ((uint8_t *) &fields->value[i])[j];
3455 basis = hash_bytes(&value, mf->n_bytes, basis);
3457 /* For tunnels, hash in whether the field is present. */
3458 if (mf_is_tun_metadata(mf)) {
3459 basis = hash_boolean(mf_is_set(mf, &ctx->xin->flow), basis);
3462 mf_mask_field(mf, &ctx->wc->masks);
3466 bucket = group_best_live_bucket(ctx, group, basis);
3468 xlate_group_bucket(ctx, bucket);
3469 xlate_group_stats(ctx, group, bucket);
3474 xlate_select_group(struct xlate_ctx *ctx, struct group_dpif *group)
3476 const char *selection_method = group_dpif_get_selection_method(group);
3478 if (selection_method[0] == '\0') {
3479 xlate_default_select_group(ctx, group);
3480 } else if (!strcasecmp("hash", selection_method)) {
3481 xlate_hash_fields_select_group(ctx, group);
3483 /* Parsing of groups should ensure this never happens */
3489 xlate_group_action__(struct xlate_ctx *ctx, struct group_dpif *group)
3491 bool was_in_group = ctx->in_group;
3492 ctx->in_group = true;
3494 switch (group_dpif_get_type(group)) {
3496 case OFPGT11_INDIRECT:
3497 xlate_all_group(ctx, group);
3499 case OFPGT11_SELECT:
3500 xlate_select_group(ctx, group);
3503 xlate_ff_group(ctx, group);
3508 group_dpif_unref(group);
3510 ctx->in_group = was_in_group;
3514 xlate_group_action(struct xlate_ctx *ctx, uint32_t group_id)
3516 if (xlate_resubmit_resource_check(ctx)) {
3517 struct group_dpif *group;
3520 got_group = group_dpif_lookup(ctx->xbridge->ofproto, group_id, &group);
3522 xlate_group_action__(ctx, group);
3532 xlate_ofpact_resubmit(struct xlate_ctx *ctx,
3533 const struct ofpact_resubmit *resubmit)
3537 bool may_packet_in = false;
3538 bool honor_table_miss = false;
3540 if (ctx->rule && rule_dpif_is_internal(ctx->rule)) {
3541 /* Still allow missed packets to be sent to the controller
3542 * if resubmitting from an internal table. */
3543 may_packet_in = true;
3544 honor_table_miss = true;
3547 in_port = resubmit->in_port;
3548 if (in_port == OFPP_IN_PORT) {
3549 in_port = ctx->xin->flow.in_port.ofp_port;
3552 table_id = resubmit->table_id;
3553 if (table_id == 255) {
3554 table_id = ctx->table_id;
3557 xlate_table_action(ctx, in_port, table_id, may_packet_in,
3562 flood_packets(struct xlate_ctx *ctx, bool all)
3564 const struct xport *xport;
3566 HMAP_FOR_EACH (xport, ofp_node, &ctx->xbridge->xports) {
3567 if (xport->ofp_port == ctx->xin->flow.in_port.ofp_port) {
3572 compose_output_action__(ctx, xport->ofp_port, NULL, false);
3573 } else if (!(xport->config & OFPUTIL_PC_NO_FLOOD)) {
3574 compose_output_action(ctx, xport->ofp_port, NULL);
3578 ctx->nf_output_iface = NF_OUT_FLOOD;
3582 execute_controller_action(struct xlate_ctx *ctx, int len,
3583 enum ofp_packet_in_reason reason,
3584 uint16_t controller_id)
3586 struct dp_packet *packet;
3588 ctx->xout->slow |= SLOW_CONTROLLER;
3589 xlate_commit_actions(ctx);
3590 if (!ctx->xin->packet) {
3594 packet = dp_packet_clone(ctx->xin->packet);
3596 odp_execute_actions(NULL, &packet, 1, false,
3597 ctx->odp_actions->data, ctx->odp_actions->size, NULL);
3599 /* A packet sent by an action in a table-miss rule is considered an
3600 * explicit table miss. OpenFlow before 1.3 doesn't have that concept so
3601 * it will get translated back to OFPR_ACTION for those versions. */
3602 if (reason == OFPR_ACTION
3603 && ctx->rule && rule_dpif_is_table_miss(ctx->rule)) {
3604 reason = OFPR_EXPLICIT_MISS;
3607 size_t packet_len = dp_packet_size(packet);
3609 struct ofproto_async_msg *am = xmalloc(sizeof *am);
3610 *am = (struct ofproto_async_msg) {
3611 .controller_id = controller_id,
3612 .oam = OAM_PACKET_IN,
3615 .packet = dp_packet_steal_data(packet),
3618 .table_id = ctx->table_id,
3619 .cookie = ctx->rule_cookie,
3624 flow_get_metadata(&ctx->xin->flow, &am->pin.up.flow_metadata);
3626 ofproto_dpif_send_async_msg(ctx->xbridge->ofproto, am);
3627 dp_packet_delete(packet);
3631 compose_recirculate_action__(struct xlate_ctx *ctx, uint8_t table)
3633 struct recirc_metadata md;
3636 recirc_metadata_from_flow(&md, &ctx->xin->flow);
3638 ovs_assert(ctx->recirc_action_offset >= 0);
3640 struct recirc_state state = {
3642 .ofproto_uuid = *ofproto_dpif_get_uuid(ctx->xbridge->ofproto),
3644 .stack = ctx->stack.data,
3645 .n_stack = ctx->stack.size / sizeof(union mf_subvalue),
3646 .mirrors = ctx->mirrors,
3647 .conntracked = ctx->conntracked,
3648 .ofpacts = ((struct ofpact *) ctx->action_set.data
3649 + ctx->recirc_action_offset / sizeof(struct ofpact)),
3650 .ofpacts_len = ctx->action_set.size - ctx->recirc_action_offset,
3651 .action_set = ctx->action_set.data,
3652 .action_set_len = ctx->recirc_action_offset,
3655 /* Allocate a unique recirc id for the given metadata state in the
3656 * flow. An existing id, with a new reference to the corresponding
3657 * recirculation context, will be returned if possible.
3658 * The life-cycle of this recirc id is managed by associating it
3659 * with the udpif key ('ukey') created for each new datapath flow. */
3660 id = recirc_alloc_id_ctx(&state);
3662 XLATE_REPORT_ERROR(ctx, "Failed to allocate recirculation id");
3663 ctx->error = XLATE_NO_RECIRCULATION_CONTEXT;
3666 recirc_refs_add(&ctx->xout->recircs, id);
3668 nl_msg_put_u32(ctx->odp_actions, OVS_ACTION_ATTR_RECIRC, id);
3670 /* Undo changes done by recirculation. */
3671 ctx->action_set.size = ctx->recirc_action_offset;
3672 ctx->recirc_action_offset = -1;
3673 ctx->last_unroll_offset = -1;
3676 /* Called only when ctx->recirc_action_offset is set. */
3678 compose_recirculate_action(struct xlate_ctx *ctx)
3680 xlate_commit_actions(ctx);
3681 compose_recirculate_action__(ctx, 0);
3684 /* Fork the pipeline here. The current packet will continue processing the
3685 * current action list. A clone of the current packet will recirculate, skip
3686 * the remainder of the current action list and asynchronously resume pipeline
3687 * processing in 'table' with the current metadata and action set. */
3689 compose_recirculate_and_fork(struct xlate_ctx *ctx, uint8_t table)
3691 ctx->recirc_action_offset = ctx->action_set.size;
3692 compose_recirculate_action__(ctx, table);
3696 compose_mpls_push_action(struct xlate_ctx *ctx, struct ofpact_push_mpls *mpls)
3698 struct flow *flow = &ctx->xin->flow;
3701 ovs_assert(eth_type_mpls(mpls->ethertype));
3703 n = flow_count_mpls_labels(flow, ctx->wc);
3705 xlate_commit_actions(ctx);
3706 } else if (n >= FLOW_MAX_MPLS_LABELS) {
3707 if (ctx->xin->packet != NULL) {
3708 XLATE_REPORT_ERROR(ctx, "bridge %s: dropping packet on which an "
3709 "MPLS push action can't be performed as it would "
3710 "have more MPLS LSEs than the %d supported.",
3711 ctx->xbridge->name, FLOW_MAX_MPLS_LABELS);
3713 ctx->error = XLATE_TOO_MANY_MPLS_LABELS;
3717 flow_push_mpls(flow, n, mpls->ethertype, ctx->wc);
3721 compose_mpls_pop_action(struct xlate_ctx *ctx, ovs_be16 eth_type)
3723 struct flow *flow = &ctx->xin->flow;
3724 int n = flow_count_mpls_labels(flow, ctx->wc);
3726 if (flow_pop_mpls(flow, n, eth_type, ctx->wc)) {
3727 if (ctx->xbridge->support.odp.recirc) {
3728 ctx->was_mpls = true;
3730 } else if (n >= FLOW_MAX_MPLS_LABELS) {
3731 if (ctx->xin->packet != NULL) {
3732 XLATE_REPORT_ERROR(ctx, "bridge %s: dropping packet on which an "
3733 "MPLS pop action can't be performed as it has "
3734 "more MPLS LSEs than the %d supported.",
3735 ctx->xbridge->name, FLOW_MAX_MPLS_LABELS);
3737 ctx->error = XLATE_TOO_MANY_MPLS_LABELS;
3738 ofpbuf_clear(ctx->odp_actions);
3743 compose_dec_ttl(struct xlate_ctx *ctx, struct ofpact_cnt_ids *ids)
3745 struct flow *flow = &ctx->xin->flow;
3747 if (!is_ip_any(flow)) {
3751 ctx->wc->masks.nw_ttl = 0xff;
3752 if (flow->nw_ttl > 1) {
3758 for (i = 0; i < ids->n_controllers; i++) {
3759 execute_controller_action(ctx, UINT16_MAX, OFPR_INVALID_TTL,
3763 /* Stop processing for current table. */
3769 compose_set_mpls_label_action(struct xlate_ctx *ctx, ovs_be32 label)
3771 if (eth_type_mpls(ctx->xin->flow.dl_type)) {
3772 ctx->wc->masks.mpls_lse[0] |= htonl(MPLS_LABEL_MASK);
3773 set_mpls_lse_label(&ctx->xin->flow.mpls_lse[0], label);
3778 compose_set_mpls_tc_action(struct xlate_ctx *ctx, uint8_t tc)
3780 if (eth_type_mpls(ctx->xin->flow.dl_type)) {
3781 ctx->wc->masks.mpls_lse[0] |= htonl(MPLS_TC_MASK);
3782 set_mpls_lse_tc(&ctx->xin->flow.mpls_lse[0], tc);
3787 compose_set_mpls_ttl_action(struct xlate_ctx *ctx, uint8_t ttl)
3789 if (eth_type_mpls(ctx->xin->flow.dl_type)) {
3790 ctx->wc->masks.mpls_lse[0] |= htonl(MPLS_TTL_MASK);
3791 set_mpls_lse_ttl(&ctx->xin->flow.mpls_lse[0], ttl);
3796 compose_dec_mpls_ttl_action(struct xlate_ctx *ctx)
3798 struct flow *flow = &ctx->xin->flow;
3800 if (eth_type_mpls(flow->dl_type)) {
3801 uint8_t ttl = mpls_lse_to_ttl(flow->mpls_lse[0]);
3803 ctx->wc->masks.mpls_lse[0] |= htonl(MPLS_TTL_MASK);
3806 set_mpls_lse_ttl(&flow->mpls_lse[0], ttl);
3809 execute_controller_action(ctx, UINT16_MAX, OFPR_INVALID_TTL, 0);
3813 /* Stop processing for current table. */
3818 xlate_output_action(struct xlate_ctx *ctx,
3819 ofp_port_t port, uint16_t max_len, bool may_packet_in)
3821 ofp_port_t prev_nf_output_iface = ctx->nf_output_iface;
3823 ctx->nf_output_iface = NF_OUT_DROP;
3827 compose_output_action(ctx, ctx->xin->flow.in_port.ofp_port, NULL);
3830 xlate_table_action(ctx, ctx->xin->flow.in_port.ofp_port,
3831 0, may_packet_in, true);
3837 flood_packets(ctx, false);
3840 flood_packets(ctx, true);
3842 case OFPP_CONTROLLER:
3843 execute_controller_action(ctx, max_len,
3844 (ctx->in_group ? OFPR_GROUP
3845 : ctx->in_action_set ? OFPR_ACTION_SET
3853 if (port != ctx->xin->flow.in_port.ofp_port) {
3854 compose_output_action(ctx, port, NULL);
3856 xlate_report(ctx, "skipping output to input port");
3861 if (prev_nf_output_iface == NF_OUT_FLOOD) {
3862 ctx->nf_output_iface = NF_OUT_FLOOD;
3863 } else if (ctx->nf_output_iface == NF_OUT_DROP) {
3864 ctx->nf_output_iface = prev_nf_output_iface;
3865 } else if (prev_nf_output_iface != NF_OUT_DROP &&
3866 ctx->nf_output_iface != NF_OUT_FLOOD) {
3867 ctx->nf_output_iface = NF_OUT_MULTI;
3872 xlate_output_reg_action(struct xlate_ctx *ctx,
3873 const struct ofpact_output_reg *or)
3875 uint64_t port = mf_get_subfield(&or->src, &ctx->xin->flow);
3876 if (port <= UINT16_MAX) {
3877 union mf_subvalue value;
3879 memset(&value, 0xff, sizeof value);
3880 mf_write_subfield_flow(&or->src, &value, &ctx->wc->masks);
3881 xlate_output_action(ctx, u16_to_ofp(port),
3882 or->max_len, false);
3887 xlate_enqueue_action(struct xlate_ctx *ctx,
3888 const struct ofpact_enqueue *enqueue)
3890 ofp_port_t ofp_port = enqueue->port;
3891 uint32_t queue_id = enqueue->queue;
3892 uint32_t flow_priority, priority;
3895 /* Translate queue to priority. */
3896 error = dpif_queue_to_priority(ctx->xbridge->dpif, queue_id, &priority);
3898 /* Fall back to ordinary output action. */
3899 xlate_output_action(ctx, enqueue->port, 0, false);
3903 /* Check output port. */
3904 if (ofp_port == OFPP_IN_PORT) {
3905 ofp_port = ctx->xin->flow.in_port.ofp_port;
3906 } else if (ofp_port == ctx->xin->flow.in_port.ofp_port) {
3910 /* Add datapath actions. */
3911 flow_priority = ctx->xin->flow.skb_priority;
3912 ctx->xin->flow.skb_priority = priority;
3913 compose_output_action(ctx, ofp_port, NULL);
3914 ctx->xin->flow.skb_priority = flow_priority;
3916 /* Update NetFlow output port. */
3917 if (ctx->nf_output_iface == NF_OUT_DROP) {
3918 ctx->nf_output_iface = ofp_port;
3919 } else if (ctx->nf_output_iface != NF_OUT_FLOOD) {
3920 ctx->nf_output_iface = NF_OUT_MULTI;
3925 xlate_set_queue_action(struct xlate_ctx *ctx, uint32_t queue_id)
3927 uint32_t skb_priority;
3929 if (!dpif_queue_to_priority(ctx->xbridge->dpif, queue_id, &skb_priority)) {
3930 ctx->xin->flow.skb_priority = skb_priority;
3932 /* Couldn't translate queue to a priority. Nothing to do. A warning
3933 * has already been logged. */
3938 slave_enabled_cb(ofp_port_t ofp_port, void *xbridge_)
3940 const struct xbridge *xbridge = xbridge_;
3951 case OFPP_CONTROLLER: /* Not supported by the bundle action. */
3954 port = get_ofp_port(xbridge, ofp_port);
3955 return port ? port->may_enable : false;
3960 xlate_bundle_action(struct xlate_ctx *ctx,
3961 const struct ofpact_bundle *bundle)
3965 port = bundle_execute(bundle, &ctx->xin->flow, ctx->wc, slave_enabled_cb,
3966 CONST_CAST(struct xbridge *, ctx->xbridge));
3967 if (bundle->dst.field) {
3968 nxm_reg_load(&bundle->dst, ofp_to_u16(port), &ctx->xin->flow, ctx->wc);
3970 xlate_output_action(ctx, port, 0, false);
3975 xlate_learn_action__(struct xlate_ctx *ctx, const struct ofpact_learn *learn,
3976 struct ofputil_flow_mod *fm, struct ofpbuf *ofpacts)
3978 learn_execute(learn, &ctx->xin->flow, fm, ofpacts);
3979 if (ctx->xin->may_learn) {
3980 ofproto_dpif_flow_mod(ctx->xbridge->ofproto, fm);
3985 xlate_learn_action(struct xlate_ctx *ctx, const struct ofpact_learn *learn)
3987 learn_mask(learn, ctx->wc);
3989 if (ctx->xin->xcache) {
3990 struct xc_entry *entry;
3992 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_LEARN);
3993 entry->u.learn.ofproto = ctx->xbridge->ofproto;
3994 entry->u.learn.fm = xmalloc(sizeof *entry->u.learn.fm);
3995 entry->u.learn.ofpacts = ofpbuf_new(64);
3996 xlate_learn_action__(ctx, learn, entry->u.learn.fm,
3997 entry->u.learn.ofpacts);
3998 } else if (ctx->xin->may_learn) {
3999 uint64_t ofpacts_stub[1024 / 8];
4000 struct ofputil_flow_mod fm;
4001 struct ofpbuf ofpacts;
4003 ofpbuf_use_stub(&ofpacts, ofpacts_stub, sizeof ofpacts_stub);
4004 xlate_learn_action__(ctx, learn, &fm, &ofpacts);
4005 ofpbuf_uninit(&ofpacts);
4010 xlate_fin_timeout__(struct rule_dpif *rule, uint16_t tcp_flags,
4011 uint16_t idle_timeout, uint16_t hard_timeout)
4013 if (tcp_flags & (TCP_FIN | TCP_RST)) {
4014 rule_dpif_reduce_timeouts(rule, idle_timeout, hard_timeout);
4019 xlate_fin_timeout(struct xlate_ctx *ctx,
4020 const struct ofpact_fin_timeout *oft)
4023 xlate_fin_timeout__(ctx->rule, ctx->xin->tcp_flags,
4024 oft->fin_idle_timeout, oft->fin_hard_timeout);
4025 if (ctx->xin->xcache) {
4026 struct xc_entry *entry;
4028 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_FIN_TIMEOUT);
4029 /* XC_RULE already holds a reference on the rule, none is taken
4031 entry->u.fin.rule = ctx->rule;
4032 entry->u.fin.idle = oft->fin_idle_timeout;
4033 entry->u.fin.hard = oft->fin_hard_timeout;
4039 xlate_sample_action(struct xlate_ctx *ctx,
4040 const struct ofpact_sample *os)
4042 /* Scale the probability from 16-bit to 32-bit while representing
4043 * the same percentage. */
4044 uint32_t probability = (os->probability << 16) | os->probability;
4046 if (!ctx->xbridge->support.variable_length_userdata) {
4047 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
4049 VLOG_ERR_RL(&rl, "ignoring NXAST_SAMPLE action because datapath "
4050 "lacks support (needs Linux 3.10+ or kernel module from "
4055 xlate_commit_actions(ctx);
4057 union user_action_cookie cookie = {
4059 .type = USER_ACTION_COOKIE_FLOW_SAMPLE,
4060 .probability = os->probability,
4061 .collector_set_id = os->collector_set_id,
4062 .obs_domain_id = os->obs_domain_id,
4063 .obs_point_id = os->obs_point_id,
4066 compose_sample_action(ctx, probability, &cookie, sizeof cookie.flow_sample,
4071 may_receive(const struct xport *xport, struct xlate_ctx *ctx)
4073 if (xport->config & (is_stp(&ctx->xin->flow)
4074 ? OFPUTIL_PC_NO_RECV_STP
4075 : OFPUTIL_PC_NO_RECV)) {
4079 /* Only drop packets here if both forwarding and learning are
4080 * disabled. If just learning is enabled, we need to have
4081 * OFPP_NORMAL and the learning action have a look at the packet
4082 * before we can drop it. */
4083 if ((!xport_stp_forward_state(xport) && !xport_stp_learn_state(xport)) ||
4084 (!xport_rstp_forward_state(xport) && !xport_rstp_learn_state(xport))) {
4092 xlate_write_actions__(struct xlate_ctx *ctx,
4093 const struct ofpact *ofpacts, size_t ofpacts_len)
4095 /* Maintain actset_output depending on the contents of the action set:
4097 * - OFPP_UNSET, if there is no "output" action.
4099 * - The output port, if there is an "output" action and no "group"
4102 * - OFPP_UNSET, if there is a "group" action.
4104 if (!ctx->action_set_has_group) {
4105 const struct ofpact *a;
4106 OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
4107 if (a->type == OFPACT_OUTPUT) {
4108 ctx->xin->flow.actset_output = ofpact_get_OUTPUT(a)->port;
4109 } else if (a->type == OFPACT_GROUP) {
4110 ctx->xin->flow.actset_output = OFPP_UNSET;
4111 ctx->action_set_has_group = true;
4117 ofpbuf_put(&ctx->action_set, ofpacts, ofpacts_len);
4121 xlate_write_actions(struct xlate_ctx *ctx, const struct ofpact_nest *a)
4123 xlate_write_actions__(ctx, a->actions, ofpact_nest_get_action_len(a));
4127 xlate_action_set(struct xlate_ctx *ctx)
4129 uint64_t action_list_stub[1024 / 64];
4130 struct ofpbuf action_list;
4132 ctx->in_action_set = true;
4133 ofpbuf_use_stub(&action_list, action_list_stub, sizeof action_list_stub);
4134 ofpacts_execute_action_set(&action_list, &ctx->action_set);
4135 /* Clear the action set, as it is not needed any more. */
4136 ofpbuf_clear(&ctx->action_set);
4137 do_xlate_actions(action_list.data, action_list.size, ctx);
4138 ctx->in_action_set = false;
4139 ofpbuf_uninit(&action_list);
4143 recirc_put_unroll_xlate(struct xlate_ctx *ctx)
4145 struct ofpact_unroll_xlate *unroll;
4147 unroll = ctx->last_unroll_offset < 0
4149 : ALIGNED_CAST(struct ofpact_unroll_xlate *,
4150 (char *)ctx->action_set.data + ctx->last_unroll_offset);
4152 /* Restore the table_id and rule cookie for a potential PACKET
4155 (ctx->table_id != unroll->rule_table_id
4156 || ctx->rule_cookie != unroll->rule_cookie)) {
4158 ctx->last_unroll_offset = ctx->action_set.size;
4159 unroll = ofpact_put_UNROLL_XLATE(&ctx->action_set);
4160 unroll->rule_table_id = ctx->table_id;
4161 unroll->rule_cookie = ctx->rule_cookie;
4166 /* Copy remaining actions to the action_set to be executed after recirculation.
4167 * UNROLL_XLATE action is inserted, if not already done so, before actions that
4168 * may depend on the current table ID or flow cookie. */
4170 recirc_unroll_actions(const struct ofpact *ofpacts, size_t ofpacts_len,
4171 struct xlate_ctx *ctx)
4173 const struct ofpact *a;
4175 OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
4177 case OFPACT_OUTPUT_REG:
4180 case OFPACT_CONTROLLER:
4181 case OFPACT_DEC_MPLS_TTL:
4182 case OFPACT_DEC_TTL:
4183 /* These actions may generate asynchronous messages, which include
4184 * table ID and flow cookie information. */
4185 recirc_put_unroll_xlate(ctx);
4188 case OFPACT_RESUBMIT:
4189 if (ofpact_get_RESUBMIT(a)->table_id == 0xff) {
4190 /* This resubmit action is relative to the current table, so we
4191 * need to track what table that is.*/
4192 recirc_put_unroll_xlate(ctx);
4196 case OFPACT_SET_TUNNEL:
4197 case OFPACT_REG_MOVE:
4198 case OFPACT_SET_FIELD:
4199 case OFPACT_STACK_PUSH:
4200 case OFPACT_STACK_POP:
4202 case OFPACT_WRITE_METADATA:
4203 case OFPACT_GOTO_TABLE:
4204 case OFPACT_ENQUEUE:
4205 case OFPACT_SET_VLAN_VID:
4206 case OFPACT_SET_VLAN_PCP:
4207 case OFPACT_STRIP_VLAN:
4208 case OFPACT_PUSH_VLAN:
4209 case OFPACT_SET_ETH_SRC:
4210 case OFPACT_SET_ETH_DST:
4211 case OFPACT_SET_IPV4_SRC:
4212 case OFPACT_SET_IPV4_DST:
4213 case OFPACT_SET_IP_DSCP:
4214 case OFPACT_SET_IP_ECN:
4215 case OFPACT_SET_IP_TTL:
4216 case OFPACT_SET_L4_SRC_PORT:
4217 case OFPACT_SET_L4_DST_PORT:
4218 case OFPACT_SET_QUEUE:
4219 case OFPACT_POP_QUEUE:
4220 case OFPACT_PUSH_MPLS:
4221 case OFPACT_POP_MPLS:
4222 case OFPACT_SET_MPLS_LABEL:
4223 case OFPACT_SET_MPLS_TC:
4224 case OFPACT_SET_MPLS_TTL:
4225 case OFPACT_MULTIPATH:
4228 case OFPACT_UNROLL_XLATE:
4229 case OFPACT_FIN_TIMEOUT:
4230 case OFPACT_CLEAR_ACTIONS:
4231 case OFPACT_WRITE_ACTIONS:
4234 case OFPACT_DEBUG_RECIRC:
4237 /* These may not generate PACKET INs. */
4241 case OFPACT_CONJUNCTION:
4242 /* These need not be copied for restoration. */
4245 /* Copy the action over. */
4246 ofpbuf_put(&ctx->action_set, a, OFPACT_ALIGN(a->len));
4250 #define CHECK_MPLS_RECIRCULATION() \
4251 if (ctx->was_mpls) { \
4252 ctx_trigger_recirculation(ctx); \
4255 #define CHECK_MPLS_RECIRCULATION_IF(COND) \
4257 CHECK_MPLS_RECIRCULATION(); \
4261 put_ct_mark(const struct flow *flow, struct flow *base_flow,
4262 struct ofpbuf *odp_actions, struct flow_wildcards *wc)
4269 odp_attr.key = flow->ct_mark;
4270 odp_attr.mask = wc->masks.ct_mark;
4272 if (odp_attr.mask && odp_attr.key != base_flow->ct_mark) {
4273 nl_msg_put_unspec(odp_actions, OVS_CT_ATTR_MARK, &odp_attr,
4279 put_ct_label(const struct flow *flow, struct flow *base_flow,
4280 struct ofpbuf *odp_actions, struct flow_wildcards *wc)
4282 if (!ovs_u128_is_zero(&wc->masks.ct_label)
4283 && !ovs_u128_equals(&flow->ct_label, &base_flow->ct_label)) {
4289 odp_ct_label = nl_msg_put_unspec_uninit(odp_actions,
4291 sizeof(*odp_ct_label));
4292 odp_ct_label->key = flow->ct_label;
4293 odp_ct_label->mask = wc->masks.ct_label;
4298 put_ct_helper(struct ofpbuf *odp_actions, struct ofpact_conntrack *ofc)
4301 if (ofc->alg == IPPORT_FTP) {
4302 nl_msg_put_string(odp_actions, OVS_CT_ATTR_HELPER, "ftp");
4304 VLOG_WARN("Cannot serialize ct_helper %d\n", ofc->alg);
4310 put_ct_nat(struct xlate_ctx *ctx)
4312 struct ofpact_nat *ofn = ctx->ct_nat_action;
4319 nat_offset = nl_msg_start_nested(ctx->odp_actions, OVS_CT_ATTR_NAT);
4320 if (ofn->flags & NX_NAT_F_SRC || ofn->flags & NX_NAT_F_DST) {
4321 nl_msg_put_flag(ctx->odp_actions, ofn->flags & NX_NAT_F_SRC
4322 ? OVS_NAT_ATTR_SRC : OVS_NAT_ATTR_DST);
4323 if (ofn->flags & NX_NAT_F_PERSISTENT) {
4324 nl_msg_put_flag(ctx->odp_actions, OVS_NAT_ATTR_PERSISTENT);
4326 if (ofn->flags & NX_NAT_F_PROTO_HASH) {
4327 nl_msg_put_flag(ctx->odp_actions, OVS_NAT_ATTR_PROTO_HASH);
4328 } else if (ofn->flags & NX_NAT_F_PROTO_RANDOM) {
4329 nl_msg_put_flag(ctx->odp_actions, OVS_NAT_ATTR_PROTO_RANDOM);
4331 if (ofn->range_af == AF_INET) {
4332 nl_msg_put_be32(ctx->odp_actions, OVS_NAT_ATTR_IP_MIN,
4333 ofn->range.addr.ipv4.min);
4334 if (ofn->range.addr.ipv4.max &&
4335 (ntohl(ofn->range.addr.ipv4.max)
4336 > ntohl(ofn->range.addr.ipv4.min))) {
4337 nl_msg_put_be32(ctx->odp_actions, OVS_NAT_ATTR_IP_MAX,
4338 ofn->range.addr.ipv4.max);
4340 } else if (ofn->range_af == AF_INET6) {
4341 nl_msg_put_unspec(ctx->odp_actions, OVS_NAT_ATTR_IP_MIN,
4342 &ofn->range.addr.ipv6.min,
4343 sizeof ofn->range.addr.ipv6.min);
4344 if (!ipv6_mask_is_any(&ofn->range.addr.ipv6.max) &&
4345 memcmp(&ofn->range.addr.ipv6.max, &ofn->range.addr.ipv6.min,
4346 sizeof ofn->range.addr.ipv6.max) > 0) {
4347 nl_msg_put_unspec(ctx->odp_actions, OVS_NAT_ATTR_IP_MAX,
4348 &ofn->range.addr.ipv6.max,
4349 sizeof ofn->range.addr.ipv6.max);
4352 if (ofn->range_af != AF_UNSPEC && ofn->range.proto.min) {
4353 nl_msg_put_u16(ctx->odp_actions, OVS_NAT_ATTR_PROTO_MIN,
4354 ofn->range.proto.min);
4355 if (ofn->range.proto.max &&
4356 ofn->range.proto.max > ofn->range.proto.min) {
4357 nl_msg_put_u16(ctx->odp_actions, OVS_NAT_ATTR_PROTO_MAX,
4358 ofn->range.proto.max);
4362 nl_msg_end_nested(ctx->odp_actions, nat_offset);
4366 compose_conntrack_action(struct xlate_ctx *ctx, struct ofpact_conntrack *ofc)
4368 ovs_u128 old_ct_label = ctx->base_flow.ct_label;
4369 uint32_t old_ct_mark = ctx->base_flow.ct_mark;
4373 /* Ensure that any prior actions are applied before composing the new
4374 * conntrack action. */
4375 xlate_commit_actions(ctx);
4377 /* Process nested actions first, to populate the key. */
4378 ctx->ct_nat_action = NULL;
4379 do_xlate_actions(ofc->actions, ofpact_ct_get_action_len(ofc), ctx);
4381 if (ofc->zone_src.field) {
4382 zone = mf_get_subfield(&ofc->zone_src, &ctx->xin->flow);
4384 zone = ofc->zone_imm;
4387 ct_offset = nl_msg_start_nested(ctx->odp_actions, OVS_ACTION_ATTR_CT);
4388 if (ofc->flags & NX_CT_F_COMMIT) {
4389 nl_msg_put_flag(ctx->odp_actions, OVS_CT_ATTR_COMMIT);
4391 nl_msg_put_u16(ctx->odp_actions, OVS_CT_ATTR_ZONE, zone);
4392 put_ct_mark(&ctx->xin->flow, &ctx->base_flow, ctx->odp_actions, ctx->wc);
4393 put_ct_label(&ctx->xin->flow, &ctx->base_flow, ctx->odp_actions, ctx->wc);
4394 put_ct_helper(ctx->odp_actions, ofc);
4396 ctx->ct_nat_action = NULL;
4397 nl_msg_end_nested(ctx->odp_actions, ct_offset);
4399 /* Restore the original ct fields in the key. These should only be exposed
4400 * after recirculation to another table. */
4401 ctx->base_flow.ct_mark = old_ct_mark;
4402 ctx->base_flow.ct_label = old_ct_label;
4404 if (ofc->recirc_table == NX_CT_RECIRC_NONE) {
4405 /* If we do not recirculate as part of this action, hide the results of
4406 * connection tracking from subsequent recirculations. */
4407 ctx->conntracked = false;
4409 /* Use ct_* fields from datapath during recirculation upcall. */
4410 ctx->conntracked = true;
4411 compose_recirculate_and_fork(ctx, ofc->recirc_table);
4416 do_xlate_actions(const struct ofpact *ofpacts, size_t ofpacts_len,
4417 struct xlate_ctx *ctx)
4419 struct flow_wildcards *wc = ctx->wc;
4420 struct flow *flow = &ctx->xin->flow;
4421 const struct ofpact *a;
4423 if (ovs_native_tunneling_is_on(ctx->xbridge->ofproto)) {
4424 tnl_neigh_snoop(flow, wc, ctx->xbridge->name);
4426 /* dl_type already in the mask, not set below. */
4428 OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
4429 struct ofpact_controller *controller;
4430 const struct ofpact_metadata *metadata;
4431 const struct ofpact_set_field *set_field;
4432 const struct mf_field *mf;
4439 /* Check if need to store the remaining actions for later
4441 if (exit_recirculates(ctx)) {
4442 recirc_unroll_actions(a, OFPACT_ALIGN(ofpacts_len -
4444 (uint8_t *)ofpacts)),
4452 xlate_output_action(ctx, ofpact_get_OUTPUT(a)->port,
4453 ofpact_get_OUTPUT(a)->max_len, true);
4457 if (xlate_group_action(ctx, ofpact_get_GROUP(a)->group_id)) {
4458 /* Group could not be found. */
4463 case OFPACT_CONTROLLER:
4464 controller = ofpact_get_CONTROLLER(a);
4465 execute_controller_action(ctx, controller->max_len,
4467 controller->controller_id);
4470 case OFPACT_ENQUEUE:
4471 memset(&wc->masks.skb_priority, 0xff,
4472 sizeof wc->masks.skb_priority);
4473 xlate_enqueue_action(ctx, ofpact_get_ENQUEUE(a));
4476 case OFPACT_SET_VLAN_VID:
4477 wc->masks.vlan_tci |= htons(VLAN_VID_MASK | VLAN_CFI);
4478 if (flow->vlan_tci & htons(VLAN_CFI) ||
4479 ofpact_get_SET_VLAN_VID(a)->push_vlan_if_needed) {
4480 flow->vlan_tci &= ~htons(VLAN_VID_MASK);
4481 flow->vlan_tci |= (htons(ofpact_get_SET_VLAN_VID(a)->vlan_vid)
4486 case OFPACT_SET_VLAN_PCP:
4487 wc->masks.vlan_tci |= htons(VLAN_PCP_MASK | VLAN_CFI);
4488 if (flow->vlan_tci & htons(VLAN_CFI) ||
4489 ofpact_get_SET_VLAN_PCP(a)->push_vlan_if_needed) {
4490 flow->vlan_tci &= ~htons(VLAN_PCP_MASK);
4491 flow->vlan_tci |= htons((ofpact_get_SET_VLAN_PCP(a)->vlan_pcp
4492 << VLAN_PCP_SHIFT) | VLAN_CFI);
4496 case OFPACT_STRIP_VLAN:
4497 memset(&wc->masks.vlan_tci, 0xff, sizeof wc->masks.vlan_tci);
4498 flow->vlan_tci = htons(0);
4501 case OFPACT_PUSH_VLAN:
4502 /* XXX 802.1AD(QinQ) */
4503 memset(&wc->masks.vlan_tci, 0xff, sizeof wc->masks.vlan_tci);
4504 flow->vlan_tci = htons(VLAN_CFI);
4507 case OFPACT_SET_ETH_SRC:
4508 WC_MASK_FIELD(wc, dl_src);
4509 flow->dl_src = ofpact_get_SET_ETH_SRC(a)->mac;
4512 case OFPACT_SET_ETH_DST:
4513 WC_MASK_FIELD(wc, dl_dst);
4514 flow->dl_dst = ofpact_get_SET_ETH_DST(a)->mac;
4517 case OFPACT_SET_IPV4_SRC:
4518 CHECK_MPLS_RECIRCULATION();
4519 if (flow->dl_type == htons(ETH_TYPE_IP)) {
4520 memset(&wc->masks.nw_src, 0xff, sizeof wc->masks.nw_src);
4521 flow->nw_src = ofpact_get_SET_IPV4_SRC(a)->ipv4;
4525 case OFPACT_SET_IPV4_DST:
4526 CHECK_MPLS_RECIRCULATION();
4527 if (flow->dl_type == htons(ETH_TYPE_IP)) {
4528 memset(&wc->masks.nw_dst, 0xff, sizeof wc->masks.nw_dst);
4529 flow->nw_dst = ofpact_get_SET_IPV4_DST(a)->ipv4;
4533 case OFPACT_SET_IP_DSCP:
4534 CHECK_MPLS_RECIRCULATION();
4535 if (is_ip_any(flow)) {
4536 wc->masks.nw_tos |= IP_DSCP_MASK;
4537 flow->nw_tos &= ~IP_DSCP_MASK;
4538 flow->nw_tos |= ofpact_get_SET_IP_DSCP(a)->dscp;
4542 case OFPACT_SET_IP_ECN:
4543 CHECK_MPLS_RECIRCULATION();
4544 if (is_ip_any(flow)) {
4545 wc->masks.nw_tos |= IP_ECN_MASK;
4546 flow->nw_tos &= ~IP_ECN_MASK;
4547 flow->nw_tos |= ofpact_get_SET_IP_ECN(a)->ecn;
4551 case OFPACT_SET_IP_TTL:
4552 CHECK_MPLS_RECIRCULATION();
4553 if (is_ip_any(flow)) {
4554 wc->masks.nw_ttl = 0xff;
4555 flow->nw_ttl = ofpact_get_SET_IP_TTL(a)->ttl;
4559 case OFPACT_SET_L4_SRC_PORT:
4560 CHECK_MPLS_RECIRCULATION();
4561 if (is_ip_any(flow) && !(flow->nw_frag & FLOW_NW_FRAG_LATER)) {
4562 memset(&wc->masks.nw_proto, 0xff, sizeof wc->masks.nw_proto);
4563 memset(&wc->masks.tp_src, 0xff, sizeof wc->masks.tp_src);
4564 flow->tp_src = htons(ofpact_get_SET_L4_SRC_PORT(a)->port);
4568 case OFPACT_SET_L4_DST_PORT:
4569 CHECK_MPLS_RECIRCULATION();
4570 if (is_ip_any(flow) && !(flow->nw_frag & FLOW_NW_FRAG_LATER)) {
4571 memset(&wc->masks.nw_proto, 0xff, sizeof wc->masks.nw_proto);
4572 memset(&wc->masks.tp_dst, 0xff, sizeof wc->masks.tp_dst);
4573 flow->tp_dst = htons(ofpact_get_SET_L4_DST_PORT(a)->port);
4577 case OFPACT_RESUBMIT:
4578 /* Recirculation complicates resubmit. There are two cases:
4580 * - If mpls_pop has been executed, then the flow table lookup
4581 * as part of resubmit might depend on fields that can only
4582 * be obtained via recirculation, so the resubmit itself
4583 * triggers recirculation and we need to make sure that the
4584 * resubmit is executed again after recirculation.
4585 * Therefore, in this case we trigger recirculation and let
4586 * the code following this "switch" append the resubmit to
4587 * the post-recirculation actions.
4589 * - Otherwise, some action in the flow entry found by resubmit
4590 * might trigger recirculation. If that happens, then we do
4591 * not want to execute the resubmit again after
4592 * recirculation, so we want to skip back to the head of the
4593 * loop to avoid that, only adding any actions that follow
4594 * the resubmit to the post-recirculation actions.
4596 if (ctx->was_mpls) {
4597 ctx_trigger_recirculation(ctx);
4600 xlate_ofpact_resubmit(ctx, ofpact_get_RESUBMIT(a));
4603 case OFPACT_SET_TUNNEL:
4604 flow->tunnel.tun_id = htonll(ofpact_get_SET_TUNNEL(a)->tun_id);
4607 case OFPACT_SET_QUEUE:
4608 memset(&wc->masks.skb_priority, 0xff,
4609 sizeof wc->masks.skb_priority);
4610 xlate_set_queue_action(ctx, ofpact_get_SET_QUEUE(a)->queue_id);
4613 case OFPACT_POP_QUEUE:
4614 memset(&wc->masks.skb_priority, 0xff,
4615 sizeof wc->masks.skb_priority);
4616 flow->skb_priority = ctx->orig_skb_priority;
4619 case OFPACT_REG_MOVE:
4620 CHECK_MPLS_RECIRCULATION_IF(
4621 mf_is_l3_or_higher(ofpact_get_REG_MOVE(a)->dst.field) ||
4622 mf_is_l3_or_higher(ofpact_get_REG_MOVE(a)->src.field));
4623 nxm_execute_reg_move(ofpact_get_REG_MOVE(a), flow, wc);
4626 case OFPACT_SET_FIELD:
4627 CHECK_MPLS_RECIRCULATION_IF(
4628 mf_is_l3_or_higher(ofpact_get_SET_FIELD(a)->field));
4629 set_field = ofpact_get_SET_FIELD(a);
4630 mf = set_field->field;
4632 /* Set field action only ever overwrites packet's outermost
4633 * applicable header fields. Do nothing if no header exists. */
4634 if (mf->id == MFF_VLAN_VID) {
4635 wc->masks.vlan_tci |= htons(VLAN_CFI);
4636 if (!(flow->vlan_tci & htons(VLAN_CFI))) {
4639 } else if ((mf->id == MFF_MPLS_LABEL || mf->id == MFF_MPLS_TC)
4640 /* 'dl_type' is already unwildcarded. */
4641 && !eth_type_mpls(flow->dl_type)) {
4644 /* A flow may wildcard nw_frag. Do nothing if setting a transport
4645 * header field on a packet that does not have them. */
4646 mf_mask_field_and_prereqs(mf, wc);
4647 if (mf_are_prereqs_ok(mf, flow)) {
4648 mf_set_flow_value_masked(mf, &set_field->value,
4649 &set_field->mask, flow);
4653 case OFPACT_STACK_PUSH:
4654 CHECK_MPLS_RECIRCULATION_IF(
4655 mf_is_l3_or_higher(ofpact_get_STACK_PUSH(a)->subfield.field));
4656 nxm_execute_stack_push(ofpact_get_STACK_PUSH(a), flow, wc,
4660 case OFPACT_STACK_POP:
4661 CHECK_MPLS_RECIRCULATION_IF(
4662 mf_is_l3_or_higher(ofpact_get_STACK_POP(a)->subfield.field));
4663 nxm_execute_stack_pop(ofpact_get_STACK_POP(a), flow, wc,
4667 case OFPACT_PUSH_MPLS:
4668 /* Recirculate if it is an IP packet with a zero ttl. This may
4669 * indicate that the packet was previously MPLS and an MPLS pop
4670 * action converted it to IP. In this case recirculating should
4671 * reveal the IP TTL which is used as the basis for a new MPLS
4673 CHECK_MPLS_RECIRCULATION_IF(
4674 !flow_count_mpls_labels(flow, wc)
4675 && flow->nw_ttl == 0
4676 && is_ip_any(flow));
4677 compose_mpls_push_action(ctx, ofpact_get_PUSH_MPLS(a));
4680 case OFPACT_POP_MPLS:
4681 CHECK_MPLS_RECIRCULATION();
4682 compose_mpls_pop_action(ctx, ofpact_get_POP_MPLS(a)->ethertype);
4685 case OFPACT_SET_MPLS_LABEL:
4686 CHECK_MPLS_RECIRCULATION();
4687 compose_set_mpls_label_action(
4688 ctx, ofpact_get_SET_MPLS_LABEL(a)->label);
4691 case OFPACT_SET_MPLS_TC:
4692 CHECK_MPLS_RECIRCULATION();
4693 compose_set_mpls_tc_action(ctx, ofpact_get_SET_MPLS_TC(a)->tc);
4696 case OFPACT_SET_MPLS_TTL:
4697 CHECK_MPLS_RECIRCULATION();
4698 compose_set_mpls_ttl_action(ctx, ofpact_get_SET_MPLS_TTL(a)->ttl);
4701 case OFPACT_DEC_MPLS_TTL:
4702 CHECK_MPLS_RECIRCULATION();
4703 if (compose_dec_mpls_ttl_action(ctx)) {
4708 case OFPACT_DEC_TTL:
4709 CHECK_MPLS_RECIRCULATION();
4710 wc->masks.nw_ttl = 0xff;
4711 if (compose_dec_ttl(ctx, ofpact_get_DEC_TTL(a))) {
4717 /* Nothing to do. */
4720 case OFPACT_MULTIPATH:
4721 CHECK_MPLS_RECIRCULATION();
4722 multipath_execute(ofpact_get_MULTIPATH(a), flow, wc);
4726 CHECK_MPLS_RECIRCULATION();
4727 xlate_bundle_action(ctx, ofpact_get_BUNDLE(a));
4730 case OFPACT_OUTPUT_REG:
4731 xlate_output_reg_action(ctx, ofpact_get_OUTPUT_REG(a));
4735 CHECK_MPLS_RECIRCULATION();
4736 xlate_learn_action(ctx, ofpact_get_LEARN(a));
4739 case OFPACT_CONJUNCTION: {
4740 /* A flow with a "conjunction" action represents part of a special
4741 * kind of "set membership match". Such a flow should not actually
4742 * get executed, but it could via, say, a "packet-out", even though
4743 * that wouldn't be useful. Log it to help debugging. */
4744 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
4745 VLOG_INFO_RL(&rl, "executing no-op conjunction action");
4753 case OFPACT_UNROLL_XLATE: {
4754 struct ofpact_unroll_xlate *unroll = ofpact_get_UNROLL_XLATE(a);
4756 /* Restore translation context data that was stored earlier. */
4757 ctx->table_id = unroll->rule_table_id;
4758 ctx->rule_cookie = unroll->rule_cookie;
4761 case OFPACT_FIN_TIMEOUT:
4762 CHECK_MPLS_RECIRCULATION();
4763 memset(&wc->masks.nw_proto, 0xff, sizeof wc->masks.nw_proto);
4764 xlate_fin_timeout(ctx, ofpact_get_FIN_TIMEOUT(a));
4767 case OFPACT_CLEAR_ACTIONS:
4768 ofpbuf_clear(&ctx->action_set);
4769 ctx->xin->flow.actset_output = OFPP_UNSET;
4770 ctx->action_set_has_group = false;
4773 case OFPACT_WRITE_ACTIONS:
4774 xlate_write_actions(ctx, ofpact_get_WRITE_ACTIONS(a));
4777 case OFPACT_WRITE_METADATA:
4778 metadata = ofpact_get_WRITE_METADATA(a);
4779 flow->metadata &= ~metadata->mask;
4780 flow->metadata |= metadata->metadata & metadata->mask;
4784 /* Not implemented yet. */
4787 case OFPACT_GOTO_TABLE: {
4788 struct ofpact_goto_table *ogt = ofpact_get_GOTO_TABLE(a);
4790 ovs_assert(ctx->table_id < ogt->table_id);
4792 xlate_table_action(ctx, ctx->xin->flow.in_port.ofp_port,
4793 ogt->table_id, true, true);
4798 xlate_sample_action(ctx, ofpact_get_SAMPLE(a));
4802 CHECK_MPLS_RECIRCULATION();
4803 compose_conntrack_action(ctx, ofpact_get_CT(a));
4807 /* This will be processed by compose_conntrack_action(). */
4808 ctx->ct_nat_action = ofpact_get_NAT(a);
4811 case OFPACT_DEBUG_RECIRC:
4812 ctx_trigger_recirculation(ctx);
4817 /* Check if need to store this and the remaining actions for later
4819 if (!ctx->error && ctx->exit && ctx_first_recirculation_action(ctx)) {
4820 recirc_unroll_actions(a, OFPACT_ALIGN(ofpacts_len -
4822 (uint8_t *)ofpacts)),
4830 xlate_in_init(struct xlate_in *xin, struct ofproto_dpif *ofproto,
4831 const struct flow *flow, ofp_port_t in_port,
4832 struct rule_dpif *rule, uint16_t tcp_flags,
4833 const struct dp_packet *packet, struct flow_wildcards *wc,
4834 struct ofpbuf *odp_actions)
4836 xin->ofproto = ofproto;
4838 xin->flow.in_port.ofp_port = in_port;
4839 xin->flow.actset_output = OFPP_UNSET;
4840 xin->packet = packet;
4841 xin->may_learn = packet != NULL;
4844 xin->ofpacts = NULL;
4845 xin->ofpacts_len = 0;
4846 xin->tcp_flags = tcp_flags;
4847 xin->resubmit_hook = NULL;
4848 xin->report_hook = NULL;
4849 xin->resubmit_stats = NULL;
4853 xin->odp_actions = odp_actions;
4855 /* Do recirc lookup. */
4857 if (flow->recirc_id) {
4858 const struct recirc_id_node *node
4859 = recirc_id_node_find(flow->recirc_id);
4861 xin->recirc = &node->state;
4867 xlate_out_uninit(struct xlate_out *xout)
4870 recirc_refs_unref(&xout->recircs);
4874 /* Translates the 'ofpacts_len' bytes of "struct ofpact"s starting at 'ofpacts'
4875 * into datapath actions, using 'ctx', and discards the datapath actions. */
4877 xlate_actions_for_side_effects(struct xlate_in *xin)
4879 struct xlate_out xout;
4880 enum xlate_error error;
4882 error = xlate_actions(xin, &xout);
4884 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
4886 VLOG_WARN_RL(&rl, "xlate_actions failed (%s)!", xlate_strerror(error));
4889 xlate_out_uninit(&xout);
4892 static struct skb_priority_to_dscp *
4893 get_skb_priority(const struct xport *xport, uint32_t skb_priority)
4895 struct skb_priority_to_dscp *pdscp;
4898 hash = hash_int(skb_priority, 0);
4899 HMAP_FOR_EACH_IN_BUCKET (pdscp, hmap_node, hash, &xport->skb_priorities) {
4900 if (pdscp->skb_priority == skb_priority) {
4908 dscp_from_skb_priority(const struct xport *xport, uint32_t skb_priority,
4911 struct skb_priority_to_dscp *pdscp = get_skb_priority(xport, skb_priority);
4912 *dscp = pdscp ? pdscp->dscp : 0;
4913 return pdscp != NULL;
4917 count_skb_priorities(const struct xport *xport)
4919 return hmap_count(&xport->skb_priorities);
4923 clear_skb_priorities(struct xport *xport)
4925 struct skb_priority_to_dscp *pdscp, *next;
4927 HMAP_FOR_EACH_SAFE (pdscp, next, hmap_node, &xport->skb_priorities) {
4928 hmap_remove(&xport->skb_priorities, &pdscp->hmap_node);
4934 actions_output_to_local_port(const struct xlate_ctx *ctx)
4936 odp_port_t local_odp_port = ofp_port_to_odp_port(ctx->xbridge, OFPP_LOCAL);
4937 const struct nlattr *a;
4940 NL_ATTR_FOR_EACH_UNSAFE (a, left, ctx->odp_actions->data,
4941 ctx->odp_actions->size) {
4942 if (nl_attr_type(a) == OVS_ACTION_ATTR_OUTPUT
4943 && nl_attr_get_odp_port(a) == local_odp_port) {
4950 #if defined(__linux__)
4951 /* Returns the maximum number of packets that the Linux kernel is willing to
4952 * queue up internally to certain kinds of software-implemented ports, or the
4953 * default (and rarely modified) value if it cannot be determined. */
4955 netdev_max_backlog(void)
4957 static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
4958 static int max_backlog = 1000; /* The normal default value. */
4960 if (ovsthread_once_start(&once)) {
4961 static const char filename[] = "/proc/sys/net/core/netdev_max_backlog";
4965 stream = fopen(filename, "r");
4967 VLOG_INFO("%s: open failed (%s)", filename, ovs_strerror(errno));
4969 if (fscanf(stream, "%d", &n) != 1) {
4970 VLOG_WARN("%s: read error", filename);
4971 } else if (n <= 100) {
4972 VLOG_WARN("%s: unexpectedly small value %d", filename, n);
4978 ovsthread_once_done(&once);
4980 VLOG_DBG("%s: using %d max_backlog", filename, max_backlog);
4986 /* Counts and returns the number of OVS_ACTION_ATTR_OUTPUT actions in
4989 count_output_actions(const struct ofpbuf *odp_actions)
4991 const struct nlattr *a;
4995 NL_ATTR_FOR_EACH_UNSAFE (a, left, odp_actions->data, odp_actions->size) {
4996 if (a->nla_type == OVS_ACTION_ATTR_OUTPUT) {
5002 #endif /* defined(__linux__) */
5004 /* Returns true if 'odp_actions' contains more output actions than the datapath
5005 * can reliably handle in one go. On Linux, this is the value of the
5006 * net.core.netdev_max_backlog sysctl, which limits the maximum number of
5007 * packets that the kernel is willing to queue up for processing while the
5008 * datapath is processing a set of actions. */
5010 too_many_output_actions(const struct ofpbuf *odp_actions OVS_UNUSED)
5013 return (odp_actions->size / NL_A_U32_SIZE > netdev_max_backlog()
5014 && count_output_actions(odp_actions) > netdev_max_backlog());
5016 /* OSes other than Linux might have similar limits, but we don't know how
5017 * to determine them.*/
5023 xlate_wc_init(struct xlate_ctx *ctx)
5025 flow_wildcards_init_catchall(ctx->wc);
5027 /* Some fields we consider to always be examined. */
5028 WC_MASK_FIELD(ctx->wc, in_port);
5029 WC_MASK_FIELD(ctx->wc, dl_type);
5030 if (is_ip_any(&ctx->xin->flow)) {
5031 WC_MASK_FIELD_MASK(ctx->wc, nw_frag, FLOW_NW_FRAG_MASK);
5034 if (ctx->xbridge->support.odp.recirc) {
5035 /* Always exactly match recirc_id when datapath supports
5037 WC_MASK_FIELD(ctx->wc, recirc_id);
5040 if (ctx->xbridge->netflow) {
5041 netflow_mask_wc(&ctx->xin->flow, ctx->wc);
5044 tnl_wc_init(&ctx->xin->flow, ctx->wc);
5048 xlate_wc_finish(struct xlate_ctx *ctx)
5050 /* Clear the metadata and register wildcard masks, because we won't
5051 * use non-header fields as part of the cache. */
5052 flow_wildcards_clear_non_packet_fields(ctx->wc);
5054 /* ICMPv4 and ICMPv6 have 8-bit "type" and "code" fields. struct flow
5055 * uses the low 8 bits of the 16-bit tp_src and tp_dst members to
5056 * represent these fields. The datapath interface, on the other hand,
5057 * represents them with just 8 bits each. This means that if the high
5058 * 8 bits of the masks for these fields somehow become set, then they
5059 * will get chopped off by a round trip through the datapath, and
5060 * revalidation will spot that as an inconsistency and delete the flow.
5061 * Avoid the problem here by making sure that only the low 8 bits of
5062 * either field can be unwildcarded for ICMP.
5064 if (is_icmpv4(&ctx->xin->flow) || is_icmpv6(&ctx->xin->flow)) {
5065 ctx->wc->masks.tp_src &= htons(UINT8_MAX);
5066 ctx->wc->masks.tp_dst &= htons(UINT8_MAX);
5068 /* VLAN_TCI CFI bit must be matched if any of the TCI is matched. */
5069 if (ctx->wc->masks.vlan_tci) {
5070 ctx->wc->masks.vlan_tci |= htons(VLAN_CFI);
5074 /* Translates the flow, actions, or rule in 'xin' into datapath actions in
5076 * The caller must take responsibility for eventually freeing 'xout', with
5077 * xlate_out_uninit().
5078 * Returns 'XLATE_OK' if translation was successful. In case of an error an
5079 * empty set of actions will be returned in 'xin->odp_actions' (if non-NULL),
5080 * so that most callers may ignore the return value and transparently install a
5081 * drop flow when the translation fails. */
5083 xlate_actions(struct xlate_in *xin, struct xlate_out *xout)
5085 *xout = (struct xlate_out) {
5087 .recircs = RECIRC_REFS_EMPTY_INITIALIZER,
5090 struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
5091 struct xbridge *xbridge = xbridge_lookup(xcfg, xin->ofproto);
5093 return XLATE_BRIDGE_NOT_FOUND;
5096 struct flow *flow = &xin->flow;
5098 union mf_subvalue stack_stub[1024 / sizeof(union mf_subvalue)];
5099 uint64_t action_set_stub[1024 / 8];
5100 struct flow_wildcards scratch_wc;
5101 uint64_t actions_stub[256 / 8];
5102 struct ofpbuf scratch_actions = OFPBUF_STUB_INITIALIZER(actions_stub);
5103 struct xlate_ctx ctx = {
5107 .orig_tunnel_ipv6_dst = flow_tnl_dst(&flow->tunnel),
5109 .stack = OFPBUF_STUB_INITIALIZER(stack_stub),
5111 .wc = xin->wc ? xin->wc : &scratch_wc,
5112 .odp_actions = xin->odp_actions ? xin->odp_actions : &scratch_actions,
5114 .recurse = xin->recurse,
5115 .resubmits = xin->resubmits,
5117 .in_action_set = false,
5120 .rule_cookie = OVS_BE64_MAX,
5121 .orig_skb_priority = flow->skb_priority,
5122 .sflow_n_outputs = 0,
5123 .sflow_odp_port = 0,
5124 .nf_output_iface = NF_OUT_DROP,
5129 .recirc_action_offset = -1,
5130 .last_unroll_offset = -1,
5133 .conntracked = false,
5135 .ct_nat_action = NULL,
5137 .action_set_has_group = false,
5138 .action_set = OFPBUF_STUB_INITIALIZER(action_set_stub),
5141 /* 'base_flow' reflects the packet as it came in, but we need it to reflect
5142 * the packet as the datapath will treat it for output actions:
5144 * - Our datapath doesn't retain tunneling information without us
5145 * re-setting it, so clear the tunnel data.
5147 * - For VLAN splinters, a higher layer may pretend that the packet
5148 * came in on 'flow->in_port.ofp_port' with 'flow->vlan_tci'
5149 * attached, because that's how we want to treat it from an OpenFlow
5150 * perspective. But from the datapath's perspective it actually came
5151 * in on a VLAN device without any VLAN attached. So here we put the
5152 * datapath's view of the VLAN information in 'base_flow' to ensure
5153 * correct treatment.
5155 memset(&ctx.base_flow.tunnel, 0, sizeof ctx.base_flow.tunnel);
5156 if (flow->in_port.ofp_port
5157 != vsp_realdev_to_vlandev(xbridge->ofproto,
5158 flow->in_port.ofp_port,
5160 ctx.base_flow.vlan_tci = 0;
5163 ofpbuf_reserve(ctx.odp_actions, NL_A_U32_SIZE);
5165 xlate_wc_init(&ctx);
5168 COVERAGE_INC(xlate_actions);
5171 const struct recirc_state *state = xin->recirc;
5173 xlate_report(&ctx, "Restoring state post-recirculation:");
5175 if (xin->ofpacts_len > 0 || ctx.rule) {
5176 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
5177 const char *conflict = xin->ofpacts_len ? "actions" : "rule";
5179 VLOG_WARN_RL(&rl, "Recirculation conflict (%s)!", conflict);
5180 xlate_report(&ctx, "- Recirculation conflict (%s)!", conflict);
5181 ctx.error = XLATE_RECIRCULATION_CONFLICT;
5185 /* Set the bridge for post-recirculation processing if needed. */
5186 if (!uuid_equals(ofproto_dpif_get_uuid(ctx.xbridge->ofproto),
5187 &state->ofproto_uuid)) {
5188 struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
5189 const struct xbridge *new_bridge
5190 = xbridge_lookup_by_uuid(xcfg, &state->ofproto_uuid);
5192 if (OVS_UNLIKELY(!new_bridge)) {
5193 /* Drop the packet if the bridge cannot be found. */
5194 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
5195 VLOG_WARN_RL(&rl, "Recirculation bridge no longer exists.");
5196 xlate_report(&ctx, "- Recirculation bridge no longer exists.");
5197 ctx.error = XLATE_BRIDGE_NOT_FOUND;
5200 ctx.xbridge = new_bridge;
5203 /* Set the post-recirculation table id. Note: A table lookup is done
5204 * only if there are no post-recirculation actions. */
5205 ctx.table_id = state->table_id;
5206 xlate_report(&ctx, "- Resuming from table %"PRIu8, ctx.table_id);
5208 if (!state->conntracked) {
5209 clear_conntrack(flow);
5212 /* Restore pipeline metadata. May change flow's in_port and other
5213 * metadata to the values that existed when recirculation was
5215 recirc_metadata_to_flow(&state->metadata, flow);
5217 /* Restore stack, if any. */
5219 ofpbuf_put(&ctx.stack, state->stack,
5220 state->n_stack * sizeof *state->stack);
5223 /* Restore mirror state. */
5224 ctx.mirrors = state->mirrors;
5226 /* Restore action set, if any. */
5227 if (state->action_set_len) {
5228 xlate_report_actions(&ctx, "- Restoring action set",
5229 state->action_set, state->action_set_len);
5231 flow->actset_output = OFPP_UNSET;
5232 xlate_write_actions__(&ctx, state->action_set,
5233 state->action_set_len);
5236 /* Restore recirculation actions. If there are no actions, processing
5237 * will start with a lookup in the table set above. */
5238 xin->ofpacts = state->ofpacts;
5239 xin->ofpacts_len = state->ofpacts_len;
5240 if (state->ofpacts_len) {
5241 xlate_report_actions(&ctx, "- Restoring actions",
5242 xin->ofpacts, xin->ofpacts_len);
5244 } else if (OVS_UNLIKELY(flow->recirc_id)) {
5245 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
5247 VLOG_WARN_RL(&rl, "Recirculation context not found for ID %"PRIx32,
5249 ctx.error = XLATE_NO_RECIRCULATION_CONTEXT;
5252 /* The bridge is now known so obtain its table version. */
5253 ctx.tables_version = ofproto_dpif_get_tables_version(ctx.xbridge->ofproto);
5255 if (!xin->ofpacts && !ctx.rule) {
5256 ctx.rule = rule_dpif_lookup_from_table(
5257 ctx.xbridge->ofproto, ctx.tables_version, flow, xin->wc,
5258 ctx.xin->resubmit_stats, &ctx.table_id,
5259 flow->in_port.ofp_port, true, true);
5260 if (ctx.xin->resubmit_stats) {
5261 rule_dpif_credit_stats(ctx.rule, ctx.xin->resubmit_stats);
5263 if (ctx.xin->xcache) {
5264 struct xc_entry *entry;
5266 entry = xlate_cache_add_entry(ctx.xin->xcache, XC_RULE);
5267 entry->u.rule = ctx.rule;
5268 rule_dpif_ref(ctx.rule);
5271 if (OVS_UNLIKELY(ctx.xin->resubmit_hook)) {
5272 ctx.xin->resubmit_hook(ctx.xin, ctx.rule, 0);
5276 /* Get the proximate input port of the packet. (If xin->recirc,
5277 * flow->in_port is the ultimate input port of the packet.) */
5278 struct xport *in_port = get_ofp_port(xbridge,
5279 ctx.base_flow.in_port.ofp_port);
5281 /* Tunnel stats only for non-recirculated packets. */
5282 if (!xin->recirc && in_port && in_port->is_tunnel) {
5283 if (ctx.xin->resubmit_stats) {
5284 netdev_vport_inc_rx(in_port->netdev, ctx.xin->resubmit_stats);
5286 bfd_account_rx(in_port->bfd, ctx.xin->resubmit_stats);
5289 if (ctx.xin->xcache) {
5290 struct xc_entry *entry;
5292 entry = xlate_cache_add_entry(ctx.xin->xcache, XC_NETDEV);
5293 entry->u.dev.rx = netdev_ref(in_port->netdev);
5294 entry->u.dev.bfd = bfd_ref(in_port->bfd);
5298 if (!xin->recirc && process_special(&ctx, in_port)) {
5299 /* process_special() did all the processing for this packet.
5301 * We do not perform special processing on recirculated packets, as
5302 * recirculated packets are not really received by the bridge.*/
5303 } else if (in_port && in_port->xbundle
5304 && xbundle_mirror_out(xbridge, in_port->xbundle)) {
5305 if (ctx.xin->packet != NULL) {
5306 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
5307 VLOG_WARN_RL(&rl, "bridge %s: dropping packet received on port "
5308 "%s, which is reserved exclusively for mirroring",
5309 ctx.xbridge->name, in_port->xbundle->name);
5312 /* Sampling is done only for packets really received by the bridge. */
5313 unsigned int user_cookie_offset = 0;
5315 user_cookie_offset = compose_sflow_action(&ctx);
5316 compose_ipfix_action(&ctx, ODPP_NONE);
5318 size_t sample_actions_len = ctx.odp_actions->size;
5320 if (tnl_process_ecn(flow)
5321 && (!in_port || may_receive(in_port, &ctx))) {
5322 const struct ofpact *ofpacts;
5326 ofpacts = xin->ofpacts;
5327 ofpacts_len = xin->ofpacts_len;
5328 } else if (ctx.rule) {
5329 const struct rule_actions *actions
5330 = rule_dpif_get_actions(ctx.rule);
5331 ofpacts = actions->ofpacts;
5332 ofpacts_len = actions->ofpacts_len;
5333 ctx.rule_cookie = rule_dpif_get_flow_cookie(ctx.rule);
5338 mirror_ingress_packet(&ctx);
5339 do_xlate_actions(ofpacts, ofpacts_len, &ctx);
5344 /* We've let OFPP_NORMAL and the learning action look at the
5345 * packet, so drop it now if forwarding is disabled. */
5346 if (in_port && (!xport_stp_forward_state(in_port) ||
5347 !xport_rstp_forward_state(in_port))) {
5348 /* Drop all actions added by do_xlate_actions() above. */
5349 ctx.odp_actions->size = sample_actions_len;
5351 /* Undo changes that may have been done for recirculation. */
5352 if (exit_recirculates(&ctx)) {
5353 ctx.action_set.size = ctx.recirc_action_offset;
5354 ctx.recirc_action_offset = -1;
5355 ctx.last_unroll_offset = -1;
5357 } else if (ctx.action_set.size) {
5358 /* Translate action set only if not dropping the packet and
5359 * not recirculating. */
5360 if (!exit_recirculates(&ctx)) {
5361 xlate_action_set(&ctx);
5364 /* Check if need to recirculate. */
5365 if (exit_recirculates(&ctx)) {
5366 compose_recirculate_action(&ctx);
5370 /* Output only fully processed packets. */
5371 if (!exit_recirculates(&ctx)
5372 && xbridge->has_in_band
5373 && in_band_must_output_to_local_port(flow)
5374 && !actions_output_to_local_port(&ctx)) {
5375 compose_output_action(&ctx, OFPP_LOCAL, NULL);
5378 if (user_cookie_offset) {
5379 fix_sflow_action(&ctx, user_cookie_offset);
5383 if (nl_attr_oversized(ctx.odp_actions->size)) {
5384 /* These datapath actions are too big for a Netlink attribute, so we
5385 * can't hand them to the kernel directly. dpif_execute() can execute
5386 * them one by one with help, so just mark the result as SLOW_ACTION to
5387 * prevent the flow from being installed. */
5388 COVERAGE_INC(xlate_actions_oversize);
5389 ctx.xout->slow |= SLOW_ACTION;
5390 } else if (too_many_output_actions(ctx.odp_actions)) {
5391 COVERAGE_INC(xlate_actions_too_many_output);
5392 ctx.xout->slow |= SLOW_ACTION;
5395 /* Do netflow only for packets really received by the bridge and not sent
5396 * to the controller. We consider packets sent to the controller to be
5397 * part of the control plane rather than the data plane. */
5398 if (!xin->recirc && xbridge->netflow && !(xout->slow & SLOW_CONTROLLER)) {
5399 if (ctx.xin->resubmit_stats) {
5400 netflow_flow_update(xbridge->netflow, flow,
5401 ctx.nf_output_iface,
5402 ctx.xin->resubmit_stats);
5404 if (ctx.xin->xcache) {
5405 struct xc_entry *entry;
5407 entry = xlate_cache_add_entry(ctx.xin->xcache, XC_NETFLOW);
5408 entry->u.nf.netflow = netflow_ref(xbridge->netflow);
5409 entry->u.nf.flow = xmemdup(flow, sizeof *flow);
5410 entry->u.nf.iface = ctx.nf_output_iface;
5415 xlate_wc_finish(&ctx);
5419 ofpbuf_uninit(&ctx.stack);
5420 ofpbuf_uninit(&ctx.action_set);
5421 ofpbuf_uninit(&scratch_actions);
5423 /* Make sure we return a "drop flow" in case of an error. */
5426 if (xin->odp_actions) {
5427 ofpbuf_clear(xin->odp_actions);
5433 /* Sends 'packet' out 'ofport'.
5434 * May modify 'packet'.
5435 * Returns 0 if successful, otherwise a positive errno value. */
5437 xlate_send_packet(const struct ofport_dpif *ofport, struct dp_packet *packet)
5439 struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
5440 struct xport *xport;
5441 struct ofpact_output output;
5444 ofpact_init(&output.ofpact, OFPACT_OUTPUT, sizeof output);
5445 /* Use OFPP_NONE as the in_port to avoid special packet processing. */
5446 flow_extract(packet, &flow);
5447 flow.in_port.ofp_port = OFPP_NONE;
5449 xport = xport_lookup(xcfg, ofport);
5453 output.port = xport->ofp_port;
5456 return ofproto_dpif_execute_actions(xport->xbridge->ofproto, &flow, NULL,
5457 &output.ofpact, sizeof output,
5461 struct xlate_cache *
5462 xlate_cache_new(void)
5464 struct xlate_cache *xcache = xmalloc(sizeof *xcache);
5466 ofpbuf_init(&xcache->entries, 512);
5470 static struct xc_entry *
5471 xlate_cache_add_entry(struct xlate_cache *xcache, enum xc_type type)
5473 struct xc_entry *entry;
5475 entry = ofpbuf_put_zeros(&xcache->entries, sizeof *entry);
5482 xlate_cache_netdev(struct xc_entry *entry, const struct dpif_flow_stats *stats)
5484 if (entry->u.dev.tx) {
5485 netdev_vport_inc_tx(entry->u.dev.tx, stats);
5487 if (entry->u.dev.rx) {
5488 netdev_vport_inc_rx(entry->u.dev.rx, stats);
5490 if (entry->u.dev.bfd) {
5491 bfd_account_rx(entry->u.dev.bfd, stats);
5496 xlate_cache_normal(struct ofproto_dpif *ofproto, struct flow *flow, int vlan)
5498 struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
5499 struct xbridge *xbridge;
5500 struct xbundle *xbundle;
5501 struct flow_wildcards wc;
5503 xbridge = xbridge_lookup(xcfg, ofproto);
5508 xbundle = lookup_input_bundle(xbridge, flow->in_port.ofp_port, false,
5514 update_learning_table(xbridge, flow, &wc, vlan, xbundle);
5517 /* Push stats and perform side effects of flow translation. */
5519 xlate_push_stats(struct xlate_cache *xcache,
5520 const struct dpif_flow_stats *stats)
5522 struct xc_entry *entry;
5523 struct ofpbuf entries = xcache->entries;
5524 struct eth_addr dmac;
5526 if (!stats->n_packets) {
5530 XC_ENTRY_FOR_EACH (entry, entries, xcache) {
5531 switch (entry->type) {
5533 rule_dpif_credit_stats(entry->u.rule, stats);
5536 bond_account(entry->u.bond.bond, entry->u.bond.flow,
5537 entry->u.bond.vid, stats->n_bytes);
5540 xlate_cache_netdev(entry, stats);
5543 netflow_flow_update(entry->u.nf.netflow, entry->u.nf.flow,
5544 entry->u.nf.iface, stats);
5547 mirror_update_stats(entry->u.mirror.mbridge,
5548 entry->u.mirror.mirrors,
5549 stats->n_packets, stats->n_bytes);
5552 ofproto_dpif_flow_mod(entry->u.learn.ofproto, entry->u.learn.fm);
5555 xlate_cache_normal(entry->u.normal.ofproto, entry->u.normal.flow,
5556 entry->u.normal.vlan);
5558 case XC_FIN_TIMEOUT:
5559 xlate_fin_timeout__(entry->u.fin.rule, stats->tcp_flags,
5560 entry->u.fin.idle, entry->u.fin.hard);
5563 group_dpif_credit_stats(entry->u.group.group, entry->u.group.bucket,
5567 /* Lookup neighbor to avoid timeout. */
5568 tnl_neigh_lookup(entry->u.tnl_neigh_cache.br_name,
5569 &entry->u.tnl_neigh_cache.d_ipv6, &dmac);
5578 xlate_dev_unref(struct xc_entry *entry)
5580 if (entry->u.dev.tx) {
5581 netdev_close(entry->u.dev.tx);
5583 if (entry->u.dev.rx) {
5584 netdev_close(entry->u.dev.rx);
5586 if (entry->u.dev.bfd) {
5587 bfd_unref(entry->u.dev.bfd);
5592 xlate_cache_clear_netflow(struct netflow *netflow, struct flow *flow)
5594 netflow_flow_clear(netflow, flow);
5595 netflow_unref(netflow);
5600 xlate_cache_clear(struct xlate_cache *xcache)
5602 struct xc_entry *entry;
5603 struct ofpbuf entries;
5609 XC_ENTRY_FOR_EACH (entry, entries, xcache) {
5610 switch (entry->type) {
5612 rule_dpif_unref(entry->u.rule);
5615 free(entry->u.bond.flow);
5616 bond_unref(entry->u.bond.bond);
5619 xlate_dev_unref(entry);
5622 xlate_cache_clear_netflow(entry->u.nf.netflow, entry->u.nf.flow);
5625 mbridge_unref(entry->u.mirror.mbridge);
5628 free(entry->u.learn.fm);
5629 ofpbuf_delete(entry->u.learn.ofpacts);
5632 free(entry->u.normal.flow);
5634 case XC_FIN_TIMEOUT:
5635 /* 'u.fin.rule' is always already held as a XC_RULE, which
5636 * has already released it's reference above. */
5639 group_dpif_unref(entry->u.group.group);
5648 ofpbuf_clear(&xcache->entries);
5652 xlate_cache_delete(struct xlate_cache *xcache)
5654 xlate_cache_clear(xcache);
5655 ofpbuf_uninit(&xcache->entries);