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 /* Freezing Translation
214 * ====================
216 * At some point during translation, the code may recognize the need to halt
217 * and checkpoint the translation in a way that it can be restarted again
218 * later. We call the checkpointing process "freezing" and the restarting
221 * The use cases for freezing are:
223 * - "Recirculation", where the translation process discovers that it
224 * doesn't have enough information to complete translation without
225 * actually executing the actions that have already been translated,
226 * which provides the additionally needed information. In these
227 * situations, translation freezes translation and assigns the frozen
228 * data a unique "recirculation ID", which it associates with the data
229 * in a table in userspace (see ofproto-dpif-rid.h). It also adds a
230 * OVS_ACTION_ATTR_RECIRC action specifying that ID to the datapath
231 * actions. When a packet hits that action, the datapath looks its
232 * flow up again using the ID. If there's a miss, it comes back to
233 * userspace, which find the recirculation table entry for the ID,
234 * thaws the associated frozen data, and continues translation from
235 * that point given the additional information that is now known.
237 * The archetypal example is MPLS. As MPLS is implemented in
238 * OpenFlow, the protocol that follows the last MPLS label becomes
239 * known only when that label is popped by an OpenFlow action. That
240 * means that Open vSwitch can't extract the headers beyond the MPLS
241 * labels until the pop action is executed. Thus, at that point
242 * translation uses the recirculation process to extract the headers
243 * beyond the MPLS labels.
245 * (OVS also uses OVS_ACTION_ATTR_RECIRC to implement hashing for
246 * output to bonds. OVS pre-populates all the datapath flows for bond
247 * output in the datapath, though, which means that the elaborate
248 * process of coming back to userspace for a second round of
249 * translation isn't needed, and so bonds don't follow the above
253 * The main problem of freezing translation is preserving state, so that
254 * when the translation is thawed later it resumes from where it left off,
255 * without disruption. In particular, actions must be preserved as follows:
257 * - If we're freezing because an action needed more information, the
258 * action that prompted it.
260 * - Any actions remaining to be translated within the current flow.
262 * - If translation was frozen within a NXAST_RESUBMIT, then any actions
263 * following the resubmit action. Resubmit actions can be nested, so
264 * this has to go all the way up the control stack.
266 * - The OpenFlow 1.1+ action set.
268 * State that actions and flow table lookups can depend on, such as the
269 * following, must also be preserved:
271 * - Metadata fields (input port, registers, OF1.1+ metadata, ...).
273 * - The stack used by NXAST_STACK_PUSH and NXAST_STACK_POP actions.
275 * - The table ID and cookie of the flow being translated at each level
276 * of the control stack, because these can become visible through
277 * OFPAT_CONTROLLER actions (and other ways).
279 * Translation allows for the control of this state preservation via these
280 * members. When a need to freeze translation is identified, the
281 * translation process:
283 * 1. Sets 'freezing' to true.
285 * 2. Sets 'exit' to true to tell later steps that we're exiting from the
286 * translation process.
288 * 3. Adds an OFPACT_UNROLL_XLATE action to 'frozen_actions', and points
289 * frozen_actions.header to the action to make it easy to find it later.
290 * This action holds the current table ID and cookie so that they can be
291 * restored during a post-recirculation upcall translation.
293 * 4. Adds the action that prompted recirculation and any actions following
294 * it within the same flow to 'frozen_actions', so that they can be
295 * executed during a post-recirculation upcall translation.
299 * 6. The action that prompted recirculation might be nested in a stack of
300 * nested "resubmit"s that have actions remaining. Each of these notices
301 * that we're exiting and freezing and responds by adding more
302 * OFPACT_UNROLL_XLATE actions to 'frozen_actions', as necessary,
303 * followed by any actions that were yet unprocessed.
305 * If we're freezing because of recirculation, the caller generates a
306 * recirculation ID and associates all the state produced by this process
307 * with it. For post-recirculation upcall translation, the caller passes it
308 * back in for the new translation to execute. The process yielded a set of
309 * ofpacts that can be translated directly, so it is not much of a special
310 * case at that point.
313 struct ofpbuf frozen_actions;
315 /* True if a packet was but is no longer MPLS (due to an MPLS pop action).
316 * This is a trigger for recirculation in cases where translating an action
317 * or looking up a flow requires access to the fields of the packet after
318 * the MPLS label stack that was originally present. */
321 /* True if conntrack has been performed on this packet during processing
322 * on the current bridge. This is used to determine whether conntrack
323 * state from the datapath should be honored after thawing. */
326 /* Pointer to an embedded NAT action in a conntrack action, or NULL. */
327 struct ofpact_nat *ct_nat_action;
329 /* OpenFlow 1.1+ action set.
331 * 'action_set' accumulates "struct ofpact"s added by OFPACT_WRITE_ACTIONS.
332 * When translation is otherwise complete, ofpacts_execute_action_set()
333 * converts it to a set of "struct ofpact"s that can be translated into
334 * datapath actions. */
335 bool action_set_has_group; /* Action set contains OFPACT_GROUP? */
336 struct ofpbuf action_set; /* Action set. */
338 enum xlate_error error; /* Translation failed. */
341 const char *xlate_strerror(enum xlate_error error)
346 case XLATE_BRIDGE_NOT_FOUND:
347 return "Bridge not found";
348 case XLATE_RECURSION_TOO_DEEP:
349 return "Recursion too deep";
350 case XLATE_TOO_MANY_RESUBMITS:
351 return "Too many resubmits";
352 case XLATE_STACK_TOO_DEEP:
353 return "Stack too deep";
354 case XLATE_NO_RECIRCULATION_CONTEXT:
355 return "No recirculation context";
356 case XLATE_RECIRCULATION_CONFLICT:
357 return "Recirculation conflict";
358 case XLATE_TOO_MANY_MPLS_LABELS:
359 return "Too many MPLS labels";
361 return "Unknown error";
364 static void xlate_action_set(struct xlate_ctx *ctx);
365 static void xlate_commit_actions(struct xlate_ctx *ctx);
368 ctx_trigger_freeze(struct xlate_ctx *ctx)
371 ctx->freezing = true;
375 ctx_first_frozen_action(const struct xlate_ctx *ctx)
377 return !ctx->frozen_actions.size;
381 ctx_cancel_freeze(struct xlate_ctx *ctx)
384 ctx->freezing = false;
385 ofpbuf_clear(&ctx->frozen_actions);
386 ctx->frozen_actions.header = NULL;
390 static void compose_recirculate_action(struct xlate_ctx *ctx);
392 /* A controller may use OFPP_NONE as the ingress port to indicate that
393 * it did not arrive on a "real" port. 'ofpp_none_bundle' exists for
394 * when an input bundle is needed for validation (e.g., mirroring or
395 * OFPP_NORMAL processing). It is not connected to an 'ofproto' or have
396 * any 'port' structs, so care must be taken when dealing with it. */
397 static struct xbundle ofpp_none_bundle = {
399 .vlan_mode = PORT_VLAN_TRUNK
402 /* Node in 'xport''s 'skb_priorities' map. Used to maintain a map from
403 * 'priority' (the datapath's term for QoS queue) to the dscp bits which all
404 * traffic egressing the 'ofport' with that priority should be marked with. */
405 struct skb_priority_to_dscp {
406 struct hmap_node hmap_node; /* Node in 'ofport_dpif''s 'skb_priorities'. */
407 uint32_t skb_priority; /* Priority of this queue (see struct flow). */
409 uint8_t dscp; /* DSCP bits to mark outgoing traffic with. */
425 /* xlate_cache entries hold enough information to perform the side effects of
426 * xlate_actions() for a rule, without needing to perform rule translation
427 * from scratch. The primary usage of these is to submit statistics to objects
428 * that a flow relates to, although they may be used for other effects as well
429 * (for instance, refreshing hard timeouts for learned flows). */
433 struct rule_dpif *rule;
440 struct netflow *netflow;
445 struct mbridge *mbridge;
446 mirror_mask_t mirrors;
454 struct ofproto_dpif *ofproto;
455 struct ofputil_flow_mod *fm;
456 struct ofpbuf *ofpacts;
459 struct ofproto_dpif *ofproto;
464 struct rule_dpif *rule;
469 struct group_dpif *group;
470 struct ofputil_bucket *bucket;
473 char br_name[IFNAMSIZ];
474 struct in6_addr d_ipv6;
479 #define XC_ENTRY_FOR_EACH(ENTRY, ENTRIES, XCACHE) \
480 ENTRIES = XCACHE->entries; \
481 for (ENTRY = ofpbuf_try_pull(&ENTRIES, sizeof *ENTRY); \
483 ENTRY = ofpbuf_try_pull(&ENTRIES, sizeof *ENTRY))
486 struct ofpbuf entries;
489 /* Xlate config contains hash maps of all bridges, bundles and ports.
490 * Xcfgp contains the pointer to the current xlate configuration.
491 * When the main thread needs to change the configuration, it copies xcfgp to
492 * new_xcfg and edits new_xcfg. This enables the use of RCU locking which
493 * does not block handler and revalidator threads. */
495 struct hmap xbridges;
496 struct hmap xbundles;
499 static OVSRCU_TYPE(struct xlate_cfg *) xcfgp = OVSRCU_INITIALIZER(NULL);
500 static struct xlate_cfg *new_xcfg = NULL;
502 static bool may_receive(const struct xport *, struct xlate_ctx *);
503 static void do_xlate_actions(const struct ofpact *, size_t ofpacts_len,
505 static void xlate_normal(struct xlate_ctx *);
506 static inline void xlate_report(struct xlate_ctx *, const char *, ...)
507 OVS_PRINTF_FORMAT(2, 3);
508 static void xlate_table_action(struct xlate_ctx *, ofp_port_t in_port,
509 uint8_t table_id, bool may_packet_in,
510 bool honor_table_miss);
511 static bool input_vid_is_valid(uint16_t vid, struct xbundle *, bool warn);
512 static uint16_t input_vid_to_vlan(const struct xbundle *, uint16_t vid);
513 static void output_normal(struct xlate_ctx *, const struct xbundle *,
516 /* Optional bond recirculation parameter to compose_output_action(). */
517 struct xlate_bond_recirc {
518 uint32_t recirc_id; /* !0 Use recirculation instead of output. */
519 uint8_t hash_alg; /* !0 Compute hash for recirc before. */
520 uint32_t hash_basis; /* Compute hash for recirc before. */
523 static void compose_output_action(struct xlate_ctx *, ofp_port_t ofp_port,
524 const struct xlate_bond_recirc *xr);
526 static struct xbridge *xbridge_lookup(struct xlate_cfg *,
527 const struct ofproto_dpif *);
528 static struct xbridge *xbridge_lookup_by_uuid(struct xlate_cfg *,
529 const struct uuid *);
530 static struct xbundle *xbundle_lookup(struct xlate_cfg *,
531 const struct ofbundle *);
532 static struct xport *xport_lookup(struct xlate_cfg *,
533 const struct ofport_dpif *);
534 static struct xport *get_ofp_port(const struct xbridge *, ofp_port_t ofp_port);
535 static struct skb_priority_to_dscp *get_skb_priority(const struct xport *,
536 uint32_t skb_priority);
537 static void clear_skb_priorities(struct xport *);
538 static size_t count_skb_priorities(const struct xport *);
539 static bool dscp_from_skb_priority(const struct xport *, uint32_t skb_priority,
542 static struct xc_entry *xlate_cache_add_entry(struct xlate_cache *xc,
544 static void xlate_xbridge_init(struct xlate_cfg *, struct xbridge *);
545 static void xlate_xbundle_init(struct xlate_cfg *, struct xbundle *);
546 static void xlate_xport_init(struct xlate_cfg *, struct xport *);
547 static void xlate_xbridge_set(struct xbridge *, struct dpif *,
548 const struct mac_learning *, struct stp *,
549 struct rstp *, const struct mcast_snooping *,
550 const struct mbridge *,
551 const struct dpif_sflow *,
552 const struct dpif_ipfix *,
553 const struct netflow *,
554 bool forward_bpdu, bool has_in_band,
555 const struct dpif_backer_support *);
556 static void xlate_xbundle_set(struct xbundle *xbundle,
557 enum port_vlan_mode vlan_mode, int vlan,
558 unsigned long *trunks, bool use_priority_tags,
559 const struct bond *bond, const struct lacp *lacp,
561 static void xlate_xport_set(struct xport *xport, odp_port_t odp_port,
562 const struct netdev *netdev, const struct cfm *cfm,
563 const struct bfd *bfd, const struct lldp *lldp,
564 int stp_port_no, const struct rstp_port *rstp_port,
565 enum ofputil_port_config config,
566 enum ofputil_port_state state, bool is_tunnel,
568 static void xlate_xbridge_remove(struct xlate_cfg *, struct xbridge *);
569 static void xlate_xbundle_remove(struct xlate_cfg *, struct xbundle *);
570 static void xlate_xport_remove(struct xlate_cfg *, struct xport *);
571 static void xlate_xbridge_copy(struct xbridge *);
572 static void xlate_xbundle_copy(struct xbridge *, struct xbundle *);
573 static void xlate_xport_copy(struct xbridge *, struct xbundle *,
575 static void xlate_xcfg_free(struct xlate_cfg *);
578 xlate_report(struct xlate_ctx *ctx, const char *format, ...)
580 if (OVS_UNLIKELY(ctx->xin->report_hook)) {
583 va_start(args, format);
584 ctx->xin->report_hook(ctx->xin, ctx->recurse, format, args);
589 static struct vlog_rate_limit error_report_rl = VLOG_RATE_LIMIT_INIT(1, 5);
591 #define XLATE_REPORT_ERROR(CTX, ...) \
593 if (OVS_UNLIKELY((CTX)->xin->report_hook)) { \
594 xlate_report(CTX, __VA_ARGS__); \
596 VLOG_ERR_RL(&error_report_rl, __VA_ARGS__); \
601 xlate_report_actions(struct xlate_ctx *ctx, const char *title,
602 const struct ofpact *ofpacts, size_t ofpacts_len)
604 if (OVS_UNLIKELY(ctx->xin->report_hook)) {
605 struct ds s = DS_EMPTY_INITIALIZER;
606 ofpacts_format(ofpacts, ofpacts_len, &s);
607 xlate_report(ctx, "%s: %s", title, ds_cstr(&s));
613 xlate_xbridge_init(struct xlate_cfg *xcfg, struct xbridge *xbridge)
615 list_init(&xbridge->xbundles);
616 hmap_init(&xbridge->xports);
617 hmap_insert(&xcfg->xbridges, &xbridge->hmap_node,
618 hash_pointer(xbridge->ofproto, 0));
622 xlate_xbundle_init(struct xlate_cfg *xcfg, struct xbundle *xbundle)
624 list_init(&xbundle->xports);
625 list_insert(&xbundle->xbridge->xbundles, &xbundle->list_node);
626 hmap_insert(&xcfg->xbundles, &xbundle->hmap_node,
627 hash_pointer(xbundle->ofbundle, 0));
631 xlate_xport_init(struct xlate_cfg *xcfg, struct xport *xport)
633 hmap_init(&xport->skb_priorities);
634 hmap_insert(&xcfg->xports, &xport->hmap_node,
635 hash_pointer(xport->ofport, 0));
636 hmap_insert(&xport->xbridge->xports, &xport->ofp_node,
637 hash_ofp_port(xport->ofp_port));
641 xlate_xbridge_set(struct xbridge *xbridge,
643 const struct mac_learning *ml, struct stp *stp,
644 struct rstp *rstp, const struct mcast_snooping *ms,
645 const struct mbridge *mbridge,
646 const struct dpif_sflow *sflow,
647 const struct dpif_ipfix *ipfix,
648 const struct netflow *netflow,
649 bool forward_bpdu, bool has_in_band,
650 const struct dpif_backer_support *support)
652 if (xbridge->ml != ml) {
653 mac_learning_unref(xbridge->ml);
654 xbridge->ml = mac_learning_ref(ml);
657 if (xbridge->ms != ms) {
658 mcast_snooping_unref(xbridge->ms);
659 xbridge->ms = mcast_snooping_ref(ms);
662 if (xbridge->mbridge != mbridge) {
663 mbridge_unref(xbridge->mbridge);
664 xbridge->mbridge = mbridge_ref(mbridge);
667 if (xbridge->sflow != sflow) {
668 dpif_sflow_unref(xbridge->sflow);
669 xbridge->sflow = dpif_sflow_ref(sflow);
672 if (xbridge->ipfix != ipfix) {
673 dpif_ipfix_unref(xbridge->ipfix);
674 xbridge->ipfix = dpif_ipfix_ref(ipfix);
677 if (xbridge->stp != stp) {
678 stp_unref(xbridge->stp);
679 xbridge->stp = stp_ref(stp);
682 if (xbridge->rstp != rstp) {
683 rstp_unref(xbridge->rstp);
684 xbridge->rstp = rstp_ref(rstp);
687 if (xbridge->netflow != netflow) {
688 netflow_unref(xbridge->netflow);
689 xbridge->netflow = netflow_ref(netflow);
692 xbridge->dpif = dpif;
693 xbridge->forward_bpdu = forward_bpdu;
694 xbridge->has_in_band = has_in_band;
695 xbridge->support = *support;
699 xlate_xbundle_set(struct xbundle *xbundle,
700 enum port_vlan_mode vlan_mode, int vlan,
701 unsigned long *trunks, bool use_priority_tags,
702 const struct bond *bond, const struct lacp *lacp,
705 ovs_assert(xbundle->xbridge);
707 xbundle->vlan_mode = vlan_mode;
708 xbundle->vlan = vlan;
709 xbundle->trunks = trunks;
710 xbundle->use_priority_tags = use_priority_tags;
711 xbundle->floodable = floodable;
713 if (xbundle->bond != bond) {
714 bond_unref(xbundle->bond);
715 xbundle->bond = bond_ref(bond);
718 if (xbundle->lacp != lacp) {
719 lacp_unref(xbundle->lacp);
720 xbundle->lacp = lacp_ref(lacp);
725 xlate_xport_set(struct xport *xport, odp_port_t odp_port,
726 const struct netdev *netdev, const struct cfm *cfm,
727 const struct bfd *bfd, const struct lldp *lldp, int stp_port_no,
728 const struct rstp_port* rstp_port,
729 enum ofputil_port_config config, enum ofputil_port_state state,
730 bool is_tunnel, bool may_enable)
732 xport->config = config;
733 xport->state = state;
734 xport->stp_port_no = stp_port_no;
735 xport->is_tunnel = is_tunnel;
736 xport->may_enable = may_enable;
737 xport->odp_port = odp_port;
739 if (xport->rstp_port != rstp_port) {
740 rstp_port_unref(xport->rstp_port);
741 xport->rstp_port = rstp_port_ref(rstp_port);
744 if (xport->cfm != cfm) {
745 cfm_unref(xport->cfm);
746 xport->cfm = cfm_ref(cfm);
749 if (xport->bfd != bfd) {
750 bfd_unref(xport->bfd);
751 xport->bfd = bfd_ref(bfd);
754 if (xport->lldp != lldp) {
755 lldp_unref(xport->lldp);
756 xport->lldp = lldp_ref(lldp);
759 if (xport->netdev != netdev) {
760 netdev_close(xport->netdev);
761 xport->netdev = netdev_ref(netdev);
766 xlate_xbridge_copy(struct xbridge *xbridge)
768 struct xbundle *xbundle;
770 struct xbridge *new_xbridge = xzalloc(sizeof *xbridge);
771 new_xbridge->ofproto = xbridge->ofproto;
772 new_xbridge->name = xstrdup(xbridge->name);
773 xlate_xbridge_init(new_xcfg, new_xbridge);
775 xlate_xbridge_set(new_xbridge,
776 xbridge->dpif, xbridge->ml, xbridge->stp,
777 xbridge->rstp, xbridge->ms, xbridge->mbridge,
778 xbridge->sflow, xbridge->ipfix, xbridge->netflow,
779 xbridge->forward_bpdu, xbridge->has_in_band,
781 LIST_FOR_EACH (xbundle, list_node, &xbridge->xbundles) {
782 xlate_xbundle_copy(new_xbridge, xbundle);
785 /* Copy xports which are not part of a xbundle */
786 HMAP_FOR_EACH (xport, ofp_node, &xbridge->xports) {
787 if (!xport->xbundle) {
788 xlate_xport_copy(new_xbridge, NULL, xport);
794 xlate_xbundle_copy(struct xbridge *xbridge, struct xbundle *xbundle)
797 struct xbundle *new_xbundle = xzalloc(sizeof *xbundle);
798 new_xbundle->ofbundle = xbundle->ofbundle;
799 new_xbundle->xbridge = xbridge;
800 new_xbundle->name = xstrdup(xbundle->name);
801 xlate_xbundle_init(new_xcfg, new_xbundle);
803 xlate_xbundle_set(new_xbundle, xbundle->vlan_mode,
804 xbundle->vlan, xbundle->trunks,
805 xbundle->use_priority_tags, xbundle->bond, xbundle->lacp,
807 LIST_FOR_EACH (xport, bundle_node, &xbundle->xports) {
808 xlate_xport_copy(xbridge, new_xbundle, xport);
813 xlate_xport_copy(struct xbridge *xbridge, struct xbundle *xbundle,
816 struct skb_priority_to_dscp *pdscp, *new_pdscp;
817 struct xport *new_xport = xzalloc(sizeof *xport);
818 new_xport->ofport = xport->ofport;
819 new_xport->ofp_port = xport->ofp_port;
820 new_xport->xbridge = xbridge;
821 xlate_xport_init(new_xcfg, new_xport);
823 xlate_xport_set(new_xport, xport->odp_port, xport->netdev, xport->cfm,
824 xport->bfd, xport->lldp, xport->stp_port_no,
825 xport->rstp_port, xport->config, xport->state,
826 xport->is_tunnel, xport->may_enable);
829 struct xport *peer = xport_lookup(new_xcfg, xport->peer->ofport);
831 new_xport->peer = peer;
832 new_xport->peer->peer = new_xport;
837 new_xport->xbundle = xbundle;
838 list_insert(&new_xport->xbundle->xports, &new_xport->bundle_node);
841 HMAP_FOR_EACH (pdscp, hmap_node, &xport->skb_priorities) {
842 new_pdscp = xmalloc(sizeof *pdscp);
843 new_pdscp->skb_priority = pdscp->skb_priority;
844 new_pdscp->dscp = pdscp->dscp;
845 hmap_insert(&new_xport->skb_priorities, &new_pdscp->hmap_node,
846 hash_int(new_pdscp->skb_priority, 0));
850 /* Sets the current xlate configuration to new_xcfg and frees the old xlate
851 * configuration in xcfgp.
853 * This needs to be called after editing the xlate configuration.
855 * Functions that edit the new xlate configuration are
856 * xlate_<ofport/bundle/ofport>_set and xlate_<ofport/bundle/ofport>_remove.
862 * edit_xlate_configuration();
864 * xlate_txn_commit(); */
866 xlate_txn_commit(void)
868 struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
870 ovsrcu_set(&xcfgp, new_xcfg);
871 ovsrcu_synchronize();
872 xlate_xcfg_free(xcfg);
876 /* Copies the current xlate configuration in xcfgp to new_xcfg.
878 * This needs to be called prior to editing the xlate configuration. */
880 xlate_txn_start(void)
882 struct xbridge *xbridge;
883 struct xlate_cfg *xcfg;
885 ovs_assert(!new_xcfg);
887 new_xcfg = xmalloc(sizeof *new_xcfg);
888 hmap_init(&new_xcfg->xbridges);
889 hmap_init(&new_xcfg->xbundles);
890 hmap_init(&new_xcfg->xports);
892 xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
897 HMAP_FOR_EACH (xbridge, hmap_node, &xcfg->xbridges) {
898 xlate_xbridge_copy(xbridge);
904 xlate_xcfg_free(struct xlate_cfg *xcfg)
906 struct xbridge *xbridge, *next_xbridge;
912 HMAP_FOR_EACH_SAFE (xbridge, next_xbridge, hmap_node, &xcfg->xbridges) {
913 xlate_xbridge_remove(xcfg, xbridge);
916 hmap_destroy(&xcfg->xbridges);
917 hmap_destroy(&xcfg->xbundles);
918 hmap_destroy(&xcfg->xports);
923 xlate_ofproto_set(struct ofproto_dpif *ofproto, const char *name,
925 const struct mac_learning *ml, struct stp *stp,
926 struct rstp *rstp, const struct mcast_snooping *ms,
927 const struct mbridge *mbridge,
928 const struct dpif_sflow *sflow,
929 const struct dpif_ipfix *ipfix,
930 const struct netflow *netflow,
931 bool forward_bpdu, bool has_in_band,
932 const struct dpif_backer_support *support)
934 struct xbridge *xbridge;
936 ovs_assert(new_xcfg);
938 xbridge = xbridge_lookup(new_xcfg, ofproto);
940 xbridge = xzalloc(sizeof *xbridge);
941 xbridge->ofproto = ofproto;
943 xlate_xbridge_init(new_xcfg, xbridge);
947 xbridge->name = xstrdup(name);
949 xlate_xbridge_set(xbridge, dpif, ml, stp, rstp, ms, mbridge, sflow, ipfix,
950 netflow, forward_bpdu, has_in_band, support);
954 xlate_xbridge_remove(struct xlate_cfg *xcfg, struct xbridge *xbridge)
956 struct xbundle *xbundle, *next_xbundle;
957 struct xport *xport, *next_xport;
963 HMAP_FOR_EACH_SAFE (xport, next_xport, ofp_node, &xbridge->xports) {
964 xlate_xport_remove(xcfg, xport);
967 LIST_FOR_EACH_SAFE (xbundle, next_xbundle, list_node, &xbridge->xbundles) {
968 xlate_xbundle_remove(xcfg, xbundle);
971 hmap_remove(&xcfg->xbridges, &xbridge->hmap_node);
972 mac_learning_unref(xbridge->ml);
973 mcast_snooping_unref(xbridge->ms);
974 mbridge_unref(xbridge->mbridge);
975 dpif_sflow_unref(xbridge->sflow);
976 dpif_ipfix_unref(xbridge->ipfix);
977 stp_unref(xbridge->stp);
978 rstp_unref(xbridge->rstp);
979 hmap_destroy(&xbridge->xports);
985 xlate_remove_ofproto(struct ofproto_dpif *ofproto)
987 struct xbridge *xbridge;
989 ovs_assert(new_xcfg);
991 xbridge = xbridge_lookup(new_xcfg, ofproto);
992 xlate_xbridge_remove(new_xcfg, xbridge);
996 xlate_bundle_set(struct ofproto_dpif *ofproto, struct ofbundle *ofbundle,
997 const char *name, enum port_vlan_mode vlan_mode, int vlan,
998 unsigned long *trunks, bool use_priority_tags,
999 const struct bond *bond, const struct lacp *lacp,
1002 struct xbundle *xbundle;
1004 ovs_assert(new_xcfg);
1006 xbundle = xbundle_lookup(new_xcfg, ofbundle);
1008 xbundle = xzalloc(sizeof *xbundle);
1009 xbundle->ofbundle = ofbundle;
1010 xbundle->xbridge = xbridge_lookup(new_xcfg, ofproto);
1012 xlate_xbundle_init(new_xcfg, xbundle);
1015 free(xbundle->name);
1016 xbundle->name = xstrdup(name);
1018 xlate_xbundle_set(xbundle, vlan_mode, vlan, trunks,
1019 use_priority_tags, bond, lacp, floodable);
1023 xlate_xbundle_remove(struct xlate_cfg *xcfg, struct xbundle *xbundle)
1025 struct xport *xport;
1031 LIST_FOR_EACH_POP (xport, bundle_node, &xbundle->xports) {
1032 xport->xbundle = NULL;
1035 hmap_remove(&xcfg->xbundles, &xbundle->hmap_node);
1036 list_remove(&xbundle->list_node);
1037 bond_unref(xbundle->bond);
1038 lacp_unref(xbundle->lacp);
1039 free(xbundle->name);
1044 xlate_bundle_remove(struct ofbundle *ofbundle)
1046 struct xbundle *xbundle;
1048 ovs_assert(new_xcfg);
1050 xbundle = xbundle_lookup(new_xcfg, ofbundle);
1051 xlate_xbundle_remove(new_xcfg, xbundle);
1055 xlate_ofport_set(struct ofproto_dpif *ofproto, struct ofbundle *ofbundle,
1056 struct ofport_dpif *ofport, ofp_port_t ofp_port,
1057 odp_port_t odp_port, const struct netdev *netdev,
1058 const struct cfm *cfm, const struct bfd *bfd,
1059 const struct lldp *lldp, struct ofport_dpif *peer,
1060 int stp_port_no, const struct rstp_port *rstp_port,
1061 const struct ofproto_port_queue *qdscp_list, size_t n_qdscp,
1062 enum ofputil_port_config config,
1063 enum ofputil_port_state state, bool is_tunnel,
1067 struct xport *xport;
1069 ovs_assert(new_xcfg);
1071 xport = xport_lookup(new_xcfg, ofport);
1073 xport = xzalloc(sizeof *xport);
1074 xport->ofport = ofport;
1075 xport->xbridge = xbridge_lookup(new_xcfg, ofproto);
1076 xport->ofp_port = ofp_port;
1078 xlate_xport_init(new_xcfg, xport);
1081 ovs_assert(xport->ofp_port == ofp_port);
1083 xlate_xport_set(xport, odp_port, netdev, cfm, bfd, lldp,
1084 stp_port_no, rstp_port, config, state, is_tunnel,
1088 xport->peer->peer = NULL;
1090 xport->peer = xport_lookup(new_xcfg, peer);
1092 xport->peer->peer = xport;
1095 if (xport->xbundle) {
1096 list_remove(&xport->bundle_node);
1098 xport->xbundle = xbundle_lookup(new_xcfg, ofbundle);
1099 if (xport->xbundle) {
1100 list_insert(&xport->xbundle->xports, &xport->bundle_node);
1103 clear_skb_priorities(xport);
1104 for (i = 0; i < n_qdscp; i++) {
1105 struct skb_priority_to_dscp *pdscp;
1106 uint32_t skb_priority;
1108 if (dpif_queue_to_priority(xport->xbridge->dpif, qdscp_list[i].queue,
1113 pdscp = xmalloc(sizeof *pdscp);
1114 pdscp->skb_priority = skb_priority;
1115 pdscp->dscp = (qdscp_list[i].dscp << 2) & IP_DSCP_MASK;
1116 hmap_insert(&xport->skb_priorities, &pdscp->hmap_node,
1117 hash_int(pdscp->skb_priority, 0));
1122 xlate_xport_remove(struct xlate_cfg *xcfg, struct xport *xport)
1129 xport->peer->peer = NULL;
1133 if (xport->xbundle) {
1134 list_remove(&xport->bundle_node);
1137 clear_skb_priorities(xport);
1138 hmap_destroy(&xport->skb_priorities);
1140 hmap_remove(&xcfg->xports, &xport->hmap_node);
1141 hmap_remove(&xport->xbridge->xports, &xport->ofp_node);
1143 netdev_close(xport->netdev);
1144 rstp_port_unref(xport->rstp_port);
1145 cfm_unref(xport->cfm);
1146 bfd_unref(xport->bfd);
1147 lldp_unref(xport->lldp);
1152 xlate_ofport_remove(struct ofport_dpif *ofport)
1154 struct xport *xport;
1156 ovs_assert(new_xcfg);
1158 xport = xport_lookup(new_xcfg, ofport);
1159 xlate_xport_remove(new_xcfg, xport);
1162 static struct ofproto_dpif *
1163 xlate_lookup_ofproto_(const struct dpif_backer *backer, const struct flow *flow,
1164 ofp_port_t *ofp_in_port, const struct xport **xportp)
1166 struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
1167 const struct xport *xport;
1169 xport = xport_lookup(xcfg, tnl_port_should_receive(flow)
1170 ? tnl_port_receive(flow)
1171 : odp_port_to_ofport(backer, flow->in_port.odp_port));
1172 if (OVS_UNLIKELY(!xport)) {
1177 *ofp_in_port = xport->ofp_port;
1179 return xport->xbridge->ofproto;
1182 /* Given a datapath and flow metadata ('backer', and 'flow' respectively)
1183 * returns the corresponding struct ofproto_dpif and OpenFlow port number. */
1184 struct ofproto_dpif *
1185 xlate_lookup_ofproto(const struct dpif_backer *backer, const struct flow *flow,
1186 ofp_port_t *ofp_in_port)
1188 const struct xport *xport;
1190 return xlate_lookup_ofproto_(backer, flow, ofp_in_port, &xport);
1193 /* Given a datapath and flow metadata ('backer', and 'flow' respectively),
1194 * optionally populates 'ofproto' with the ofproto_dpif, 'ofp_in_port' with the
1195 * openflow in_port, and 'ipfix', 'sflow', and 'netflow' with the appropriate
1196 * handles for those protocols if they're enabled. Caller may use the returned
1197 * pointers until quiescing, for longer term use additional references must
1200 * Returns 0 if successful, ENODEV if the parsed flow has no associated ofproto.
1203 xlate_lookup(const struct dpif_backer *backer, const struct flow *flow,
1204 struct ofproto_dpif **ofprotop, struct dpif_ipfix **ipfix,
1205 struct dpif_sflow **sflow, struct netflow **netflow,
1206 ofp_port_t *ofp_in_port)
1208 struct ofproto_dpif *ofproto;
1209 const struct xport *xport;
1211 ofproto = xlate_lookup_ofproto_(backer, flow, ofp_in_port, &xport);
1218 *ofprotop = ofproto;
1222 *ipfix = xport ? xport->xbridge->ipfix : NULL;
1226 *sflow = xport ? xport->xbridge->sflow : NULL;
1230 *netflow = xport ? xport->xbridge->netflow : NULL;
1236 static struct xbridge *
1237 xbridge_lookup(struct xlate_cfg *xcfg, const struct ofproto_dpif *ofproto)
1239 struct hmap *xbridges;
1240 struct xbridge *xbridge;
1242 if (!ofproto || !xcfg) {
1246 xbridges = &xcfg->xbridges;
1248 HMAP_FOR_EACH_IN_BUCKET (xbridge, hmap_node, hash_pointer(ofproto, 0),
1250 if (xbridge->ofproto == ofproto) {
1257 static struct xbridge *
1258 xbridge_lookup_by_uuid(struct xlate_cfg *xcfg, const struct uuid *uuid)
1260 struct xbridge *xbridge;
1262 HMAP_FOR_EACH (xbridge, hmap_node, &xcfg->xbridges) {
1263 if (uuid_equals(ofproto_dpif_get_uuid(xbridge->ofproto), uuid)) {
1270 static struct xbundle *
1271 xbundle_lookup(struct xlate_cfg *xcfg, const struct ofbundle *ofbundle)
1273 struct hmap *xbundles;
1274 struct xbundle *xbundle;
1276 if (!ofbundle || !xcfg) {
1280 xbundles = &xcfg->xbundles;
1282 HMAP_FOR_EACH_IN_BUCKET (xbundle, hmap_node, hash_pointer(ofbundle, 0),
1284 if (xbundle->ofbundle == ofbundle) {
1291 static struct xport *
1292 xport_lookup(struct xlate_cfg *xcfg, const struct ofport_dpif *ofport)
1294 struct hmap *xports;
1295 struct xport *xport;
1297 if (!ofport || !xcfg) {
1301 xports = &xcfg->xports;
1303 HMAP_FOR_EACH_IN_BUCKET (xport, hmap_node, hash_pointer(ofport, 0),
1305 if (xport->ofport == ofport) {
1312 static struct stp_port *
1313 xport_get_stp_port(const struct xport *xport)
1315 return xport->xbridge->stp && xport->stp_port_no != -1
1316 ? stp_get_port(xport->xbridge->stp, xport->stp_port_no)
1321 xport_stp_learn_state(const struct xport *xport)
1323 struct stp_port *sp = xport_get_stp_port(xport);
1325 ? stp_learn_in_state(stp_port_get_state(sp))
1330 xport_stp_forward_state(const struct xport *xport)
1332 struct stp_port *sp = xport_get_stp_port(xport);
1334 ? stp_forward_in_state(stp_port_get_state(sp))
1339 xport_stp_should_forward_bpdu(const struct xport *xport)
1341 struct stp_port *sp = xport_get_stp_port(xport);
1342 return stp_should_forward_bpdu(sp ? stp_port_get_state(sp) : STP_DISABLED);
1345 /* Returns true if STP should process 'flow'. Sets fields in 'wc' that
1346 * were used to make the determination.*/
1348 stp_should_process_flow(const struct flow *flow, struct flow_wildcards *wc)
1350 /* is_stp() also checks dl_type, but dl_type is always set in 'wc'. */
1351 memset(&wc->masks.dl_dst, 0xff, sizeof wc->masks.dl_dst);
1352 return is_stp(flow);
1356 stp_process_packet(const struct xport *xport, const struct dp_packet *packet)
1358 struct stp_port *sp = xport_get_stp_port(xport);
1359 struct dp_packet payload = *packet;
1360 struct eth_header *eth = dp_packet_data(&payload);
1362 /* Sink packets on ports that have STP disabled when the bridge has
1364 if (!sp || stp_port_get_state(sp) == STP_DISABLED) {
1368 /* Trim off padding on payload. */
1369 if (dp_packet_size(&payload) > ntohs(eth->eth_type) + ETH_HEADER_LEN) {
1370 dp_packet_set_size(&payload, ntohs(eth->eth_type) + ETH_HEADER_LEN);
1373 if (dp_packet_try_pull(&payload, ETH_HEADER_LEN + LLC_HEADER_LEN)) {
1374 stp_received_bpdu(sp, dp_packet_data(&payload), dp_packet_size(&payload));
1378 static enum rstp_state
1379 xport_get_rstp_port_state(const struct xport *xport)
1381 return xport->rstp_port
1382 ? rstp_port_get_state(xport->rstp_port)
1387 xport_rstp_learn_state(const struct xport *xport)
1389 return xport->xbridge->rstp && xport->rstp_port
1390 ? rstp_learn_in_state(xport_get_rstp_port_state(xport))
1395 xport_rstp_forward_state(const struct xport *xport)
1397 return xport->xbridge->rstp && xport->rstp_port
1398 ? rstp_forward_in_state(xport_get_rstp_port_state(xport))
1403 xport_rstp_should_manage_bpdu(const struct xport *xport)
1405 return rstp_should_manage_bpdu(xport_get_rstp_port_state(xport));
1409 rstp_process_packet(const struct xport *xport, const struct dp_packet *packet)
1411 struct dp_packet payload = *packet;
1412 struct eth_header *eth = dp_packet_data(&payload);
1414 /* Sink packets on ports that have no RSTP. */
1415 if (!xport->rstp_port) {
1419 /* Trim off padding on payload. */
1420 if (dp_packet_size(&payload) > ntohs(eth->eth_type) + ETH_HEADER_LEN) {
1421 dp_packet_set_size(&payload, ntohs(eth->eth_type) + ETH_HEADER_LEN);
1424 if (dp_packet_try_pull(&payload, ETH_HEADER_LEN + LLC_HEADER_LEN)) {
1425 rstp_port_received_bpdu(xport->rstp_port, dp_packet_data(&payload),
1426 dp_packet_size(&payload));
1430 static struct xport *
1431 get_ofp_port(const struct xbridge *xbridge, ofp_port_t ofp_port)
1433 struct xport *xport;
1435 HMAP_FOR_EACH_IN_BUCKET (xport, ofp_node, hash_ofp_port(ofp_port),
1437 if (xport->ofp_port == ofp_port) {
1445 ofp_port_to_odp_port(const struct xbridge *xbridge, ofp_port_t ofp_port)
1447 const struct xport *xport = get_ofp_port(xbridge, ofp_port);
1448 return xport ? xport->odp_port : ODPP_NONE;
1452 odp_port_is_alive(const struct xlate_ctx *ctx, ofp_port_t ofp_port)
1454 struct xport *xport = get_ofp_port(ctx->xbridge, ofp_port);
1455 return xport && xport->may_enable;
1458 static struct ofputil_bucket *
1459 group_first_live_bucket(const struct xlate_ctx *, const struct group_dpif *,
1463 group_is_alive(const struct xlate_ctx *ctx, uint32_t group_id, int depth)
1465 struct group_dpif *group;
1467 if (group_dpif_lookup(ctx->xbridge->ofproto, group_id, &group)) {
1468 struct ofputil_bucket *bucket;
1470 bucket = group_first_live_bucket(ctx, group, depth);
1471 group_dpif_unref(group);
1472 return bucket == NULL;
1478 #define MAX_LIVENESS_RECURSION 128 /* Arbitrary limit */
1481 bucket_is_alive(const struct xlate_ctx *ctx,
1482 struct ofputil_bucket *bucket, int depth)
1484 if (depth >= MAX_LIVENESS_RECURSION) {
1485 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
1487 VLOG_WARN_RL(&rl, "bucket chaining exceeded %d links",
1488 MAX_LIVENESS_RECURSION);
1492 return (!ofputil_bucket_has_liveness(bucket)
1493 || (bucket->watch_port != OFPP_ANY
1494 && odp_port_is_alive(ctx, bucket->watch_port))
1495 || (bucket->watch_group != OFPG_ANY
1496 && group_is_alive(ctx, bucket->watch_group, depth + 1)));
1499 static struct ofputil_bucket *
1500 group_first_live_bucket(const struct xlate_ctx *ctx,
1501 const struct group_dpif *group, int depth)
1503 struct ofputil_bucket *bucket;
1504 const struct ovs_list *buckets;
1506 group_dpif_get_buckets(group, &buckets);
1507 LIST_FOR_EACH (bucket, list_node, buckets) {
1508 if (bucket_is_alive(ctx, bucket, depth)) {
1516 static struct ofputil_bucket *
1517 group_best_live_bucket(const struct xlate_ctx *ctx,
1518 const struct group_dpif *group,
1521 struct ofputil_bucket *best_bucket = NULL;
1522 uint32_t best_score = 0;
1525 struct ofputil_bucket *bucket;
1526 const struct ovs_list *buckets;
1528 group_dpif_get_buckets(group, &buckets);
1529 LIST_FOR_EACH (bucket, list_node, buckets) {
1530 if (bucket_is_alive(ctx, bucket, 0)) {
1531 uint32_t score = (hash_int(i, basis) & 0xffff) * bucket->weight;
1532 if (score >= best_score) {
1533 best_bucket = bucket;
1544 xbundle_trunks_vlan(const struct xbundle *bundle, uint16_t vlan)
1546 return (bundle->vlan_mode != PORT_VLAN_ACCESS
1547 && (!bundle->trunks || bitmap_is_set(bundle->trunks, vlan)));
1551 xbundle_includes_vlan(const struct xbundle *xbundle, uint16_t vlan)
1553 return vlan == xbundle->vlan || xbundle_trunks_vlan(xbundle, vlan);
1556 static mirror_mask_t
1557 xbundle_mirror_out(const struct xbridge *xbridge, struct xbundle *xbundle)
1559 return xbundle != &ofpp_none_bundle
1560 ? mirror_bundle_out(xbridge->mbridge, xbundle->ofbundle)
1564 static mirror_mask_t
1565 xbundle_mirror_src(const struct xbridge *xbridge, struct xbundle *xbundle)
1567 return xbundle != &ofpp_none_bundle
1568 ? mirror_bundle_src(xbridge->mbridge, xbundle->ofbundle)
1572 static mirror_mask_t
1573 xbundle_mirror_dst(const struct xbridge *xbridge, struct xbundle *xbundle)
1575 return xbundle != &ofpp_none_bundle
1576 ? mirror_bundle_dst(xbridge->mbridge, xbundle->ofbundle)
1580 static struct xbundle *
1581 lookup_input_bundle(const struct xbridge *xbridge, ofp_port_t in_port,
1582 bool warn, struct xport **in_xportp)
1584 struct xport *xport;
1586 /* Find the port and bundle for the received packet. */
1587 xport = get_ofp_port(xbridge, in_port);
1591 if (xport && xport->xbundle) {
1592 return xport->xbundle;
1595 /* Special-case OFPP_NONE (OF1.0) and OFPP_CONTROLLER (OF1.1+),
1596 * which a controller may use as the ingress port for traffic that
1597 * it is sourcing. */
1598 if (in_port == OFPP_CONTROLLER || in_port == OFPP_NONE) {
1599 return &ofpp_none_bundle;
1602 /* Odd. A few possible reasons here:
1604 * - We deleted a port but there are still a few packets queued up
1607 * - Someone externally added a port (e.g. "ovs-dpctl add-if") that
1608 * we don't know about.
1610 * - The ofproto client didn't configure the port as part of a bundle.
1611 * This is particularly likely to happen if a packet was received on the
1612 * port after it was created, but before the client had a chance to
1613 * configure its bundle.
1616 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
1618 VLOG_WARN_RL(&rl, "bridge %s: received packet on unknown "
1619 "port %"PRIu16, xbridge->name, in_port);
1624 /* Mirrors the packet represented by 'ctx' to appropriate mirror destinations,
1625 * given the packet is ingressing or egressing on 'xbundle', which has ingress
1626 * or egress (as appropriate) mirrors 'mirrors'. */
1628 mirror_packet(struct xlate_ctx *ctx, struct xbundle *xbundle,
1629 mirror_mask_t mirrors)
1631 /* Figure out what VLAN the packet is in (because mirrors can select
1632 * packets on basis of VLAN). */
1633 bool warn = ctx->xin->packet != NULL;
1634 uint16_t vid = vlan_tci_to_vid(ctx->xin->flow.vlan_tci);
1635 if (!input_vid_is_valid(vid, xbundle, warn)) {
1638 uint16_t vlan = input_vid_to_vlan(xbundle, vid);
1640 const struct xbridge *xbridge = ctx->xbridge;
1642 /* Don't mirror to destinations that we've already mirrored to. */
1643 mirrors &= ~ctx->mirrors;
1648 if (ctx->xin->resubmit_stats) {
1649 mirror_update_stats(xbridge->mbridge, mirrors,
1650 ctx->xin->resubmit_stats->n_packets,
1651 ctx->xin->resubmit_stats->n_bytes);
1653 if (ctx->xin->xcache) {
1654 struct xc_entry *entry;
1656 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_MIRROR);
1657 entry->u.mirror.mbridge = mbridge_ref(xbridge->mbridge);
1658 entry->u.mirror.mirrors = mirrors;
1661 /* 'mirrors' is a bit-mask of candidates for mirroring. Iterate as long as
1662 * some candidates remain. */
1664 const unsigned long *vlans;
1665 mirror_mask_t dup_mirrors;
1666 struct ofbundle *out;
1669 /* Get the details of the mirror represented by the rightmost 1-bit. */
1670 bool has_mirror = mirror_get(xbridge->mbridge, raw_ctz(mirrors),
1671 &vlans, &dup_mirrors, &out, &out_vlan);
1672 ovs_assert(has_mirror);
1674 /* If this mirror selects on the basis of VLAN, and it does not select
1675 * 'vlan', then discard this mirror and go on to the next one. */
1677 ctx->wc->masks.vlan_tci |= htons(VLAN_CFI | VLAN_VID_MASK);
1679 if (vlans && !bitmap_is_set(vlans, vlan)) {
1680 mirrors = zero_rightmost_1bit(mirrors);
1684 /* Record the mirror, and the mirrors that output to the same
1685 * destination, so that we don't mirror to them again. This must be
1686 * done now to ensure that output_normal(), below, doesn't recursively
1687 * output to the same mirrors. */
1688 ctx->mirrors |= dup_mirrors;
1690 /* Send the packet to the mirror. */
1692 struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
1693 struct xbundle *out_xbundle = xbundle_lookup(xcfg, out);
1695 output_normal(ctx, out_xbundle, vlan);
1697 } else if (vlan != out_vlan
1698 && !eth_addr_is_reserved(ctx->xin->flow.dl_dst)) {
1699 struct xbundle *xbundle;
1701 LIST_FOR_EACH (xbundle, list_node, &xbridge->xbundles) {
1702 if (xbundle_includes_vlan(xbundle, out_vlan)
1703 && !xbundle_mirror_out(xbridge, xbundle)) {
1704 output_normal(ctx, xbundle, out_vlan);
1709 /* output_normal() could have recursively output (to different
1710 * mirrors), so make sure that we don't send duplicates. */
1711 mirrors &= ~ctx->mirrors;
1716 mirror_ingress_packet(struct xlate_ctx *ctx)
1718 if (mbridge_has_mirrors(ctx->xbridge->mbridge)) {
1719 bool warn = ctx->xin->packet != NULL;
1720 struct xbundle *xbundle = lookup_input_bundle(
1721 ctx->xbridge, ctx->xin->flow.in_port.ofp_port, warn, NULL);
1723 mirror_packet(ctx, xbundle,
1724 xbundle_mirror_src(ctx->xbridge, xbundle));
1729 /* Given 'vid', the VID obtained from the 802.1Q header that was received as
1730 * part of a packet (specify 0 if there was no 802.1Q header), and 'in_xbundle',
1731 * the bundle on which the packet was received, returns the VLAN to which the
1734 * Both 'vid' and the return value are in the range 0...4095. */
1736 input_vid_to_vlan(const struct xbundle *in_xbundle, uint16_t vid)
1738 switch (in_xbundle->vlan_mode) {
1739 case PORT_VLAN_ACCESS:
1740 return in_xbundle->vlan;
1743 case PORT_VLAN_TRUNK:
1746 case PORT_VLAN_NATIVE_UNTAGGED:
1747 case PORT_VLAN_NATIVE_TAGGED:
1748 return vid ? vid : in_xbundle->vlan;
1755 /* Checks whether a packet with the given 'vid' may ingress on 'in_xbundle'.
1756 * If so, returns true. Otherwise, returns false and, if 'warn' is true, logs
1759 * 'vid' should be the VID obtained from the 802.1Q header that was received as
1760 * part of a packet (specify 0 if there was no 802.1Q header), in the range
1763 input_vid_is_valid(uint16_t vid, struct xbundle *in_xbundle, bool warn)
1765 /* Allow any VID on the OFPP_NONE port. */
1766 if (in_xbundle == &ofpp_none_bundle) {
1770 switch (in_xbundle->vlan_mode) {
1771 case PORT_VLAN_ACCESS:
1774 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
1775 VLOG_WARN_RL(&rl, "dropping VLAN %"PRIu16" tagged "
1776 "packet received on port %s configured as VLAN "
1777 "%"PRIu16" access port", vid, in_xbundle->name,
1784 case PORT_VLAN_NATIVE_UNTAGGED:
1785 case PORT_VLAN_NATIVE_TAGGED:
1787 /* Port must always carry its native VLAN. */
1791 case PORT_VLAN_TRUNK:
1792 if (!xbundle_includes_vlan(in_xbundle, vid)) {
1794 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
1795 VLOG_WARN_RL(&rl, "dropping VLAN %"PRIu16" packet "
1796 "received on port %s not configured for trunking "
1797 "VLAN %"PRIu16, vid, in_xbundle->name, vid);
1809 /* Given 'vlan', the VLAN that a packet belongs to, and
1810 * 'out_xbundle', a bundle on which the packet is to be output, returns the VID
1811 * that should be included in the 802.1Q header. (If the return value is 0,
1812 * then the 802.1Q header should only be included in the packet if there is a
1815 * Both 'vlan' and the return value are in the range 0...4095. */
1817 output_vlan_to_vid(const struct xbundle *out_xbundle, uint16_t vlan)
1819 switch (out_xbundle->vlan_mode) {
1820 case PORT_VLAN_ACCESS:
1823 case PORT_VLAN_TRUNK:
1824 case PORT_VLAN_NATIVE_TAGGED:
1827 case PORT_VLAN_NATIVE_UNTAGGED:
1828 return vlan == out_xbundle->vlan ? 0 : vlan;
1836 output_normal(struct xlate_ctx *ctx, const struct xbundle *out_xbundle,
1839 ovs_be16 *flow_tci = &ctx->xin->flow.vlan_tci;
1841 ovs_be16 tci, old_tci;
1842 struct xport *xport;
1843 struct xlate_bond_recirc xr;
1844 bool use_recirc = false;
1846 vid = output_vlan_to_vid(out_xbundle, vlan);
1847 if (list_is_empty(&out_xbundle->xports)) {
1848 /* Partially configured bundle with no slaves. Drop the packet. */
1850 } else if (!out_xbundle->bond) {
1851 xport = CONTAINER_OF(list_front(&out_xbundle->xports), struct xport,
1854 struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
1855 struct flow_wildcards *wc = ctx->wc;
1856 struct ofport_dpif *ofport;
1858 if (ctx->xbridge->support.odp.recirc) {
1859 use_recirc = bond_may_recirc(
1860 out_xbundle->bond, &xr.recirc_id, &xr.hash_basis);
1863 /* Only TCP mode uses recirculation. */
1864 xr.hash_alg = OVS_HASH_ALG_L4;
1865 bond_update_post_recirc_rules(out_xbundle->bond, false);
1867 /* Recirculation does not require unmasking hash fields. */
1872 ofport = bond_choose_output_slave(out_xbundle->bond,
1873 &ctx->xin->flow, wc, vid);
1874 xport = xport_lookup(xcfg, ofport);
1877 /* No slaves enabled, so drop packet. */
1881 /* If use_recirc is set, the main thread will handle stats
1882 * accounting for this bond. */
1884 if (ctx->xin->resubmit_stats) {
1885 bond_account(out_xbundle->bond, &ctx->xin->flow, vid,
1886 ctx->xin->resubmit_stats->n_bytes);
1888 if (ctx->xin->xcache) {
1889 struct xc_entry *entry;
1892 flow = &ctx->xin->flow;
1893 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_BOND);
1894 entry->u.bond.bond = bond_ref(out_xbundle->bond);
1895 entry->u.bond.flow = xmemdup(flow, sizeof *flow);
1896 entry->u.bond.vid = vid;
1901 old_tci = *flow_tci;
1903 if (tci || out_xbundle->use_priority_tags) {
1904 tci |= *flow_tci & htons(VLAN_PCP_MASK);
1906 tci |= htons(VLAN_CFI);
1911 compose_output_action(ctx, xport->ofp_port, use_recirc ? &xr : NULL);
1912 *flow_tci = old_tci;
1915 /* A VM broadcasts a gratuitous ARP to indicate that it has resumed after
1916 * migration. Older Citrix-patched Linux DomU used gratuitous ARP replies to
1917 * indicate this; newer upstream kernels use gratuitous ARP requests. */
1919 is_gratuitous_arp(const struct flow *flow, struct flow_wildcards *wc)
1921 if (flow->dl_type != htons(ETH_TYPE_ARP)) {
1925 memset(&wc->masks.dl_dst, 0xff, sizeof wc->masks.dl_dst);
1926 if (!eth_addr_is_broadcast(flow->dl_dst)) {
1930 memset(&wc->masks.nw_proto, 0xff, sizeof wc->masks.nw_proto);
1931 if (flow->nw_proto == ARP_OP_REPLY) {
1933 } else if (flow->nw_proto == ARP_OP_REQUEST) {
1934 memset(&wc->masks.nw_src, 0xff, sizeof wc->masks.nw_src);
1935 memset(&wc->masks.nw_dst, 0xff, sizeof wc->masks.nw_dst);
1937 return flow->nw_src == flow->nw_dst;
1943 /* Determines whether packets in 'flow' within 'xbridge' should be forwarded or
1944 * dropped. Returns true if they may be forwarded, false if they should be
1947 * 'in_port' must be the xport that corresponds to flow->in_port.
1948 * 'in_port' must be part of a bundle (e.g. in_port->bundle must be nonnull).
1950 * 'vlan' must be the VLAN that corresponds to flow->vlan_tci on 'in_port', as
1951 * returned by input_vid_to_vlan(). It must be a valid VLAN for 'in_port', as
1952 * checked by input_vid_is_valid().
1954 * May also add tags to '*tags', although the current implementation only does
1955 * so in one special case.
1958 is_admissible(struct xlate_ctx *ctx, struct xport *in_port,
1961 struct xbundle *in_xbundle = in_port->xbundle;
1962 const struct xbridge *xbridge = ctx->xbridge;
1963 struct flow *flow = &ctx->xin->flow;
1965 /* Drop frames for reserved multicast addresses
1966 * only if forward_bpdu option is absent. */
1967 if (!xbridge->forward_bpdu && eth_addr_is_reserved(flow->dl_dst)) {
1968 xlate_report(ctx, "packet has reserved destination MAC, dropping");
1972 if (in_xbundle->bond) {
1973 struct mac_entry *mac;
1975 switch (bond_check_admissibility(in_xbundle->bond, in_port->ofport,
1981 xlate_report(ctx, "bonding refused admissibility, dropping");
1984 case BV_DROP_IF_MOVED:
1985 ovs_rwlock_rdlock(&xbridge->ml->rwlock);
1986 mac = mac_learning_lookup(xbridge->ml, flow->dl_src, vlan);
1988 && mac_entry_get_port(xbridge->ml, mac) != in_xbundle->ofbundle
1989 && (!is_gratuitous_arp(flow, ctx->wc)
1990 || mac_entry_is_grat_arp_locked(mac))) {
1991 ovs_rwlock_unlock(&xbridge->ml->rwlock);
1992 xlate_report(ctx, "SLB bond thinks this packet looped back, "
1996 ovs_rwlock_unlock(&xbridge->ml->rwlock);
2004 /* Checks whether a MAC learning update is necessary for MAC learning table
2005 * 'ml' given that a packet matching 'flow' was received on 'in_xbundle' in
2008 * Most packets processed through the MAC learning table do not actually
2009 * change it in any way. This function requires only a read lock on the MAC
2010 * learning table, so it is much cheaper in this common case.
2012 * Keep the code here synchronized with that in update_learning_table__()
2015 is_mac_learning_update_needed(const struct mac_learning *ml,
2016 const struct flow *flow,
2017 struct flow_wildcards *wc,
2018 int vlan, struct xbundle *in_xbundle)
2019 OVS_REQ_RDLOCK(ml->rwlock)
2021 struct mac_entry *mac;
2023 if (!mac_learning_may_learn(ml, flow->dl_src, vlan)) {
2027 mac = mac_learning_lookup(ml, flow->dl_src, vlan);
2028 if (!mac || mac_entry_age(ml, mac)) {
2032 if (is_gratuitous_arp(flow, wc)) {
2033 /* We don't want to learn from gratuitous ARP packets that are
2034 * reflected back over bond slaves so we lock the learning table. */
2035 if (!in_xbundle->bond) {
2037 } else if (mac_entry_is_grat_arp_locked(mac)) {
2042 return mac_entry_get_port(ml, mac) != in_xbundle->ofbundle;
2046 /* Updates MAC learning table 'ml' given that a packet matching 'flow' was
2047 * received on 'in_xbundle' in 'vlan'.
2049 * This code repeats all the checks in is_mac_learning_update_needed() because
2050 * the lock was released between there and here and thus the MAC learning state
2051 * could have changed.
2053 * Keep the code here synchronized with that in is_mac_learning_update_needed()
2056 update_learning_table__(const struct xbridge *xbridge,
2057 const struct flow *flow, struct flow_wildcards *wc,
2058 int vlan, struct xbundle *in_xbundle)
2059 OVS_REQ_WRLOCK(xbridge->ml->rwlock)
2061 struct mac_entry *mac;
2063 if (!mac_learning_may_learn(xbridge->ml, flow->dl_src, vlan)) {
2067 mac = mac_learning_insert(xbridge->ml, flow->dl_src, vlan);
2068 if (is_gratuitous_arp(flow, wc)) {
2069 /* We don't want to learn from gratuitous ARP packets that are
2070 * reflected back over bond slaves so we lock the learning table. */
2071 if (!in_xbundle->bond) {
2072 mac_entry_set_grat_arp_lock(mac);
2073 } else if (mac_entry_is_grat_arp_locked(mac)) {
2078 if (mac_entry_get_port(xbridge->ml, mac) != in_xbundle->ofbundle) {
2079 /* The log messages here could actually be useful in debugging,
2080 * so keep the rate limit relatively high. */
2081 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(30, 300);
2083 VLOG_DBG_RL(&rl, "bridge %s: learned that "ETH_ADDR_FMT" is "
2084 "on port %s in VLAN %d",
2085 xbridge->name, ETH_ADDR_ARGS(flow->dl_src),
2086 in_xbundle->name, vlan);
2088 mac_entry_set_port(xbridge->ml, mac, in_xbundle->ofbundle);
2093 update_learning_table(const struct xbridge *xbridge,
2094 const struct flow *flow, struct flow_wildcards *wc,
2095 int vlan, struct xbundle *in_xbundle)
2099 /* Don't learn the OFPP_NONE port. */
2100 if (in_xbundle == &ofpp_none_bundle) {
2104 /* First try the common case: no change to MAC learning table. */
2105 ovs_rwlock_rdlock(&xbridge->ml->rwlock);
2106 need_update = is_mac_learning_update_needed(xbridge->ml, flow, wc, vlan,
2108 ovs_rwlock_unlock(&xbridge->ml->rwlock);
2111 /* Slow path: MAC learning table might need an update. */
2112 ovs_rwlock_wrlock(&xbridge->ml->rwlock);
2113 update_learning_table__(xbridge, flow, wc, vlan, in_xbundle);
2114 ovs_rwlock_unlock(&xbridge->ml->rwlock);
2118 /* Updates multicast snooping table 'ms' given that a packet matching 'flow'
2119 * was received on 'in_xbundle' in 'vlan' and is either Report or Query. */
2121 update_mcast_snooping_table4__(const struct xbridge *xbridge,
2122 const struct flow *flow,
2123 struct mcast_snooping *ms, int vlan,
2124 struct xbundle *in_xbundle,
2125 const struct dp_packet *packet)
2126 OVS_REQ_WRLOCK(ms->rwlock)
2128 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(60, 30);
2130 ovs_be32 ip4 = flow->igmp_group_ip4;
2132 switch (ntohs(flow->tp_src)) {
2133 case IGMP_HOST_MEMBERSHIP_REPORT:
2134 case IGMPV2_HOST_MEMBERSHIP_REPORT:
2135 if (mcast_snooping_add_group4(ms, ip4, vlan, in_xbundle->ofbundle)) {
2136 VLOG_DBG_RL(&rl, "bridge %s: multicast snooping learned that "
2137 IP_FMT" is on port %s in VLAN %d",
2138 xbridge->name, IP_ARGS(ip4), in_xbundle->name, vlan);
2141 case IGMP_HOST_LEAVE_MESSAGE:
2142 if (mcast_snooping_leave_group4(ms, ip4, vlan, in_xbundle->ofbundle)) {
2143 VLOG_DBG_RL(&rl, "bridge %s: multicast snooping leaving "
2144 IP_FMT" is on port %s in VLAN %d",
2145 xbridge->name, IP_ARGS(ip4), in_xbundle->name, vlan);
2148 case IGMP_HOST_MEMBERSHIP_QUERY:
2149 if (flow->nw_src && mcast_snooping_add_mrouter(ms, vlan,
2150 in_xbundle->ofbundle)) {
2151 VLOG_DBG_RL(&rl, "bridge %s: multicast snooping query from "
2152 IP_FMT" is on port %s in VLAN %d",
2153 xbridge->name, IP_ARGS(flow->nw_src),
2154 in_xbundle->name, vlan);
2157 case IGMPV3_HOST_MEMBERSHIP_REPORT:
2158 if ((count = mcast_snooping_add_report(ms, packet, vlan,
2159 in_xbundle->ofbundle))) {
2160 VLOG_DBG_RL(&rl, "bridge %s: multicast snooping processed %d "
2161 "addresses on port %s in VLAN %d",
2162 xbridge->name, count, in_xbundle->name, vlan);
2169 update_mcast_snooping_table6__(const struct xbridge *xbridge,
2170 const struct flow *flow,
2171 struct mcast_snooping *ms, int vlan,
2172 struct xbundle *in_xbundle,
2173 const struct dp_packet *packet)
2174 OVS_REQ_WRLOCK(ms->rwlock)
2176 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(60, 30);
2179 switch (ntohs(flow->tp_src)) {
2181 if (!ipv6_addr_equals(&flow->ipv6_src, &in6addr_any)
2182 && mcast_snooping_add_mrouter(ms, vlan, in_xbundle->ofbundle)) {
2183 VLOG_DBG_RL(&rl, "bridge %s: multicast snooping query on port %s"
2185 xbridge->name, in_xbundle->name, vlan);
2191 count = mcast_snooping_add_mld(ms, packet, vlan, in_xbundle->ofbundle);
2193 VLOG_DBG_RL(&rl, "bridge %s: multicast snooping processed %d "
2194 "addresses on port %s in VLAN %d",
2195 xbridge->name, count, in_xbundle->name, vlan);
2201 /* Updates multicast snooping table 'ms' given that a packet matching 'flow'
2202 * was received on 'in_xbundle' in 'vlan'. */
2204 update_mcast_snooping_table(const struct xbridge *xbridge,
2205 const struct flow *flow, int vlan,
2206 struct xbundle *in_xbundle,
2207 const struct dp_packet *packet)
2209 struct mcast_snooping *ms = xbridge->ms;
2210 struct xlate_cfg *xcfg;
2211 struct xbundle *mcast_xbundle;
2212 struct mcast_port_bundle *fport;
2214 /* Don't learn the OFPP_NONE port. */
2215 if (in_xbundle == &ofpp_none_bundle) {
2219 /* Don't learn from flood ports */
2220 mcast_xbundle = NULL;
2221 ovs_rwlock_wrlock(&ms->rwlock);
2222 xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
2223 LIST_FOR_EACH(fport, node, &ms->fport_list) {
2224 mcast_xbundle = xbundle_lookup(xcfg, fport->port);
2225 if (mcast_xbundle == in_xbundle) {
2230 if (!mcast_xbundle || mcast_xbundle != in_xbundle) {
2231 if (flow->dl_type == htons(ETH_TYPE_IP)) {
2232 update_mcast_snooping_table4__(xbridge, flow, ms, vlan,
2233 in_xbundle, packet);
2235 update_mcast_snooping_table6__(xbridge, flow, ms, vlan,
2236 in_xbundle, packet);
2239 ovs_rwlock_unlock(&ms->rwlock);
2242 /* send the packet to ports having the multicast group learned */
2244 xlate_normal_mcast_send_group(struct xlate_ctx *ctx,
2245 struct mcast_snooping *ms OVS_UNUSED,
2246 struct mcast_group *grp,
2247 struct xbundle *in_xbundle, uint16_t vlan)
2248 OVS_REQ_RDLOCK(ms->rwlock)
2250 struct xlate_cfg *xcfg;
2251 struct mcast_group_bundle *b;
2252 struct xbundle *mcast_xbundle;
2254 xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
2255 LIST_FOR_EACH(b, bundle_node, &grp->bundle_lru) {
2256 mcast_xbundle = xbundle_lookup(xcfg, b->port);
2257 if (mcast_xbundle && mcast_xbundle != in_xbundle) {
2258 xlate_report(ctx, "forwarding to mcast group port");
2259 output_normal(ctx, mcast_xbundle, vlan);
2260 } else if (!mcast_xbundle) {
2261 xlate_report(ctx, "mcast group port is unknown, dropping");
2263 xlate_report(ctx, "mcast group port is input port, dropping");
2268 /* send the packet to ports connected to multicast routers */
2270 xlate_normal_mcast_send_mrouters(struct xlate_ctx *ctx,
2271 struct mcast_snooping *ms,
2272 struct xbundle *in_xbundle, uint16_t vlan)
2273 OVS_REQ_RDLOCK(ms->rwlock)
2275 struct xlate_cfg *xcfg;
2276 struct mcast_mrouter_bundle *mrouter;
2277 struct xbundle *mcast_xbundle;
2279 xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
2280 LIST_FOR_EACH(mrouter, mrouter_node, &ms->mrouter_lru) {
2281 mcast_xbundle = xbundle_lookup(xcfg, mrouter->port);
2282 if (mcast_xbundle && mcast_xbundle != in_xbundle) {
2283 xlate_report(ctx, "forwarding to mcast router port");
2284 output_normal(ctx, mcast_xbundle, vlan);
2285 } else if (!mcast_xbundle) {
2286 xlate_report(ctx, "mcast router port is unknown, dropping");
2288 xlate_report(ctx, "mcast router port is input port, dropping");
2293 /* send the packet to ports flagged to be flooded */
2295 xlate_normal_mcast_send_fports(struct xlate_ctx *ctx,
2296 struct mcast_snooping *ms,
2297 struct xbundle *in_xbundle, uint16_t vlan)
2298 OVS_REQ_RDLOCK(ms->rwlock)
2300 struct xlate_cfg *xcfg;
2301 struct mcast_port_bundle *fport;
2302 struct xbundle *mcast_xbundle;
2304 xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
2305 LIST_FOR_EACH(fport, node, &ms->fport_list) {
2306 mcast_xbundle = xbundle_lookup(xcfg, fport->port);
2307 if (mcast_xbundle && mcast_xbundle != in_xbundle) {
2308 xlate_report(ctx, "forwarding to mcast flood port");
2309 output_normal(ctx, mcast_xbundle, vlan);
2310 } else if (!mcast_xbundle) {
2311 xlate_report(ctx, "mcast flood port is unknown, dropping");
2313 xlate_report(ctx, "mcast flood port is input port, dropping");
2318 /* forward the Reports to configured ports */
2320 xlate_normal_mcast_send_rports(struct xlate_ctx *ctx,
2321 struct mcast_snooping *ms,
2322 struct xbundle *in_xbundle, uint16_t vlan)
2323 OVS_REQ_RDLOCK(ms->rwlock)
2325 struct xlate_cfg *xcfg;
2326 struct mcast_port_bundle *rport;
2327 struct xbundle *mcast_xbundle;
2329 xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
2330 LIST_FOR_EACH(rport, node, &ms->rport_list) {
2331 mcast_xbundle = xbundle_lookup(xcfg, rport->port);
2332 if (mcast_xbundle && mcast_xbundle != in_xbundle) {
2333 xlate_report(ctx, "forwarding Report to mcast flagged port");
2334 output_normal(ctx, mcast_xbundle, vlan);
2335 } else if (!mcast_xbundle) {
2336 xlate_report(ctx, "mcast port is unknown, dropping the Report");
2338 xlate_report(ctx, "mcast port is input port, dropping the Report");
2344 xlate_normal_flood(struct xlate_ctx *ctx, struct xbundle *in_xbundle,
2347 struct xbundle *xbundle;
2349 LIST_FOR_EACH (xbundle, list_node, &ctx->xbridge->xbundles) {
2350 if (xbundle != in_xbundle
2351 && xbundle_includes_vlan(xbundle, vlan)
2352 && xbundle->floodable
2353 && !xbundle_mirror_out(ctx->xbridge, xbundle)) {
2354 output_normal(ctx, xbundle, vlan);
2357 ctx->nf_output_iface = NF_OUT_FLOOD;
2361 xlate_normal(struct xlate_ctx *ctx)
2363 struct flow_wildcards *wc = ctx->wc;
2364 struct flow *flow = &ctx->xin->flow;
2365 struct xbundle *in_xbundle;
2366 struct xport *in_port;
2367 struct mac_entry *mac;
2372 memset(&wc->masks.dl_src, 0xff, sizeof wc->masks.dl_src);
2373 memset(&wc->masks.dl_dst, 0xff, sizeof wc->masks.dl_dst);
2374 wc->masks.vlan_tci |= htons(VLAN_VID_MASK | VLAN_CFI);
2376 in_xbundle = lookup_input_bundle(ctx->xbridge, flow->in_port.ofp_port,
2377 ctx->xin->packet != NULL, &in_port);
2379 xlate_report(ctx, "no input bundle, dropping");
2383 /* Drop malformed frames. */
2384 if (flow->dl_type == htons(ETH_TYPE_VLAN) &&
2385 !(flow->vlan_tci & htons(VLAN_CFI))) {
2386 if (ctx->xin->packet != NULL) {
2387 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
2388 VLOG_WARN_RL(&rl, "bridge %s: dropping packet with partial "
2389 "VLAN tag received on port %s",
2390 ctx->xbridge->name, in_xbundle->name);
2392 xlate_report(ctx, "partial VLAN tag, dropping");
2396 /* Drop frames on bundles reserved for mirroring. */
2397 if (xbundle_mirror_out(ctx->xbridge, in_xbundle)) {
2398 if (ctx->xin->packet != NULL) {
2399 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
2400 VLOG_WARN_RL(&rl, "bridge %s: dropping packet received on port "
2401 "%s, which is reserved exclusively for mirroring",
2402 ctx->xbridge->name, in_xbundle->name);
2404 xlate_report(ctx, "input port is mirror output port, dropping");
2409 vid = vlan_tci_to_vid(flow->vlan_tci);
2410 if (!input_vid_is_valid(vid, in_xbundle, ctx->xin->packet != NULL)) {
2411 xlate_report(ctx, "disallowed VLAN VID for this input port, dropping");
2414 vlan = input_vid_to_vlan(in_xbundle, vid);
2416 /* Check other admissibility requirements. */
2417 if (in_port && !is_admissible(ctx, in_port, vlan)) {
2421 /* Learn source MAC. */
2422 if (ctx->xin->may_learn) {
2423 update_learning_table(ctx->xbridge, flow, wc, vlan, in_xbundle);
2425 if (ctx->xin->xcache) {
2426 struct xc_entry *entry;
2428 /* Save enough info to update mac learning table later. */
2429 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_NORMAL);
2430 entry->u.normal.ofproto = ctx->xbridge->ofproto;
2431 entry->u.normal.flow = xmemdup(flow, sizeof *flow);
2432 entry->u.normal.vlan = vlan;
2435 /* Determine output bundle. */
2436 if (mcast_snooping_enabled(ctx->xbridge->ms)
2437 && !eth_addr_is_broadcast(flow->dl_dst)
2438 && eth_addr_is_multicast(flow->dl_dst)
2439 && is_ip_any(flow)) {
2440 struct mcast_snooping *ms = ctx->xbridge->ms;
2441 struct mcast_group *grp = NULL;
2443 if (is_igmp(flow)) {
2444 if (mcast_snooping_is_membership(flow->tp_src) ||
2445 mcast_snooping_is_query(flow->tp_src)) {
2446 if (ctx->xin->may_learn) {
2447 update_mcast_snooping_table(ctx->xbridge, flow, vlan,
2448 in_xbundle, ctx->xin->packet);
2451 * IGMP packets need to take the slow path, in order to be
2452 * processed for mdb updates. That will prevent expires
2453 * firing off even after hosts have sent reports.
2455 ctx->xout->slow |= SLOW_ACTION;
2458 if (mcast_snooping_is_membership(flow->tp_src)) {
2459 ovs_rwlock_rdlock(&ms->rwlock);
2460 xlate_normal_mcast_send_mrouters(ctx, ms, in_xbundle, vlan);
2461 /* RFC4541: section 2.1.1, item 1: A snooping switch should
2462 * forward IGMP Membership Reports only to those ports where
2463 * multicast routers are attached. Alternatively stated: a
2464 * snooping switch should not forward IGMP Membership Reports
2465 * to ports on which only hosts are attached.
2466 * An administrative control may be provided to override this
2467 * restriction, allowing the report messages to be flooded to
2469 xlate_normal_mcast_send_rports(ctx, ms, in_xbundle, vlan);
2470 ovs_rwlock_unlock(&ms->rwlock);
2472 xlate_report(ctx, "multicast traffic, flooding");
2473 xlate_normal_flood(ctx, in_xbundle, vlan);
2476 } else if (is_mld(flow)) {
2477 ctx->xout->slow |= SLOW_ACTION;
2478 if (ctx->xin->may_learn) {
2479 update_mcast_snooping_table(ctx->xbridge, flow, vlan,
2480 in_xbundle, ctx->xin->packet);
2482 if (is_mld_report(flow)) {
2483 ovs_rwlock_rdlock(&ms->rwlock);
2484 xlate_normal_mcast_send_mrouters(ctx, ms, in_xbundle, vlan);
2485 xlate_normal_mcast_send_rports(ctx, ms, in_xbundle, vlan);
2486 ovs_rwlock_unlock(&ms->rwlock);
2488 xlate_report(ctx, "MLD query, flooding");
2489 xlate_normal_flood(ctx, in_xbundle, vlan);
2492 if ((flow->dl_type == htons(ETH_TYPE_IP)
2493 && ip_is_local_multicast(flow->nw_dst))
2494 || (flow->dl_type == htons(ETH_TYPE_IPV6)
2495 && ipv6_is_all_hosts(&flow->ipv6_dst))) {
2496 /* RFC4541: section 2.1.2, item 2: Packets with a dst IP
2497 * address in the 224.0.0.x range which are not IGMP must
2498 * be forwarded on all ports */
2499 xlate_report(ctx, "RFC4541: section 2.1.2, item 2, flooding");
2500 xlate_normal_flood(ctx, in_xbundle, vlan);
2505 /* forwarding to group base ports */
2506 ovs_rwlock_rdlock(&ms->rwlock);
2507 if (flow->dl_type == htons(ETH_TYPE_IP)) {
2508 grp = mcast_snooping_lookup4(ms, flow->nw_dst, vlan);
2509 } else if (flow->dl_type == htons(ETH_TYPE_IPV6)) {
2510 grp = mcast_snooping_lookup(ms, &flow->ipv6_dst, vlan);
2513 xlate_normal_mcast_send_group(ctx, ms, grp, in_xbundle, vlan);
2514 xlate_normal_mcast_send_fports(ctx, ms, in_xbundle, vlan);
2515 xlate_normal_mcast_send_mrouters(ctx, ms, in_xbundle, vlan);
2517 if (mcast_snooping_flood_unreg(ms)) {
2518 xlate_report(ctx, "unregistered multicast, flooding");
2519 xlate_normal_flood(ctx, in_xbundle, vlan);
2521 xlate_normal_mcast_send_mrouters(ctx, ms, in_xbundle, vlan);
2522 xlate_normal_mcast_send_fports(ctx, ms, in_xbundle, vlan);
2525 ovs_rwlock_unlock(&ms->rwlock);
2527 ovs_rwlock_rdlock(&ctx->xbridge->ml->rwlock);
2528 mac = mac_learning_lookup(ctx->xbridge->ml, flow->dl_dst, vlan);
2529 mac_port = mac ? mac_entry_get_port(ctx->xbridge->ml, mac) : NULL;
2530 ovs_rwlock_unlock(&ctx->xbridge->ml->rwlock);
2533 struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
2534 struct xbundle *mac_xbundle = xbundle_lookup(xcfg, mac_port);
2535 if (mac_xbundle && mac_xbundle != in_xbundle) {
2536 xlate_report(ctx, "forwarding to learned port");
2537 output_normal(ctx, mac_xbundle, vlan);
2538 } else if (!mac_xbundle) {
2539 xlate_report(ctx, "learned port is unknown, dropping");
2541 xlate_report(ctx, "learned port is input port, dropping");
2544 xlate_report(ctx, "no learned MAC for destination, flooding");
2545 xlate_normal_flood(ctx, in_xbundle, vlan);
2550 /* Appends a "sample" action for sFlow or IPFIX to 'ctx->odp_actions'. The
2551 * 'probability' is the number of packets out of UINT32_MAX to sample. The
2552 * 'cookie' (of length 'cookie_size' bytes) is passed back in the callback for
2553 * each sampled packet. 'tunnel_out_port', if not ODPP_NONE, is added as the
2554 * OVS_USERSPACE_ATTR_EGRESS_TUN_PORT attribute. If 'include_actions', an
2555 * OVS_USERSPACE_ATTR_ACTIONS attribute is added.
2558 compose_sample_action(struct xlate_ctx *ctx,
2559 const uint32_t probability,
2560 const union user_action_cookie *cookie,
2561 const size_t cookie_size,
2562 const odp_port_t tunnel_out_port,
2563 bool include_actions)
2565 size_t sample_offset = nl_msg_start_nested(ctx->odp_actions,
2566 OVS_ACTION_ATTR_SAMPLE);
2568 nl_msg_put_u32(ctx->odp_actions, OVS_SAMPLE_ATTR_PROBABILITY, probability);
2570 size_t actions_offset = nl_msg_start_nested(ctx->odp_actions,
2571 OVS_SAMPLE_ATTR_ACTIONS);
2573 odp_port_t odp_port = ofp_port_to_odp_port(
2574 ctx->xbridge, ctx->xin->flow.in_port.ofp_port);
2575 uint32_t pid = dpif_port_get_pid(ctx->xbridge->dpif, odp_port,
2576 flow_hash_5tuple(&ctx->xin->flow, 0));
2577 int cookie_offset = odp_put_userspace_action(pid, cookie, cookie_size,
2582 nl_msg_end_nested(ctx->odp_actions, actions_offset);
2583 nl_msg_end_nested(ctx->odp_actions, sample_offset);
2585 return cookie_offset;
2588 /* If sFLow is not enabled, returns 0 without doing anything.
2590 * If sFlow is enabled, appends a template "sample" action to the ODP actions
2591 * in 'ctx'. This action is a template because some of the information needed
2592 * to fill it out is not available until flow translation is complete. In this
2593 * case, this functions returns an offset, which is always nonzero, to pass
2594 * later to fix_sflow_action() to fill in the rest of the template. */
2596 compose_sflow_action(struct xlate_ctx *ctx)
2598 struct dpif_sflow *sflow = ctx->xbridge->sflow;
2599 if (!sflow || ctx->xin->flow.in_port.ofp_port == OFPP_NONE) {
2603 union user_action_cookie cookie = { .type = USER_ACTION_COOKIE_SFLOW };
2604 return compose_sample_action(ctx, dpif_sflow_get_probability(sflow),
2605 &cookie, sizeof cookie.sflow, ODPP_NONE,
2609 /* If IPFIX is enabled, this appends a "sample" action to implement IPFIX to
2610 * 'ctx->odp_actions'. */
2612 compose_ipfix_action(struct xlate_ctx *ctx, odp_port_t output_odp_port)
2614 struct dpif_ipfix *ipfix = ctx->xbridge->ipfix;
2615 odp_port_t tunnel_out_port = ODPP_NONE;
2617 if (!ipfix || ctx->xin->flow.in_port.ofp_port == OFPP_NONE) {
2621 /* For input case, output_odp_port is ODPP_NONE, which is an invalid port
2623 if (output_odp_port == ODPP_NONE &&
2624 !dpif_ipfix_get_bridge_exporter_input_sampling(ipfix)) {
2628 /* For output case, output_odp_port is valid*/
2629 if (output_odp_port != ODPP_NONE) {
2630 if (!dpif_ipfix_get_bridge_exporter_output_sampling(ipfix)) {
2633 /* If tunnel sampling is enabled, put an additional option attribute:
2634 * OVS_USERSPACE_ATTR_TUNNEL_OUT_PORT
2636 if (dpif_ipfix_get_bridge_exporter_tunnel_sampling(ipfix) &&
2637 dpif_ipfix_get_tunnel_port(ipfix, output_odp_port) ) {
2638 tunnel_out_port = output_odp_port;
2642 union user_action_cookie cookie = {
2644 .type = USER_ACTION_COOKIE_IPFIX,
2645 .output_odp_port = output_odp_port,
2648 compose_sample_action(ctx,
2649 dpif_ipfix_get_bridge_exporter_probability(ipfix),
2650 &cookie, sizeof cookie.ipfix, tunnel_out_port,
2654 /* Fix "sample" action according to data collected while composing ODP actions,
2655 * as described in compose_sflow_action().
2657 * 'user_cookie_offset' must be the offset returned by add_sflow_action(). */
2659 fix_sflow_action(struct xlate_ctx *ctx, unsigned int user_cookie_offset)
2661 const struct flow *base = &ctx->base_flow;
2662 union user_action_cookie *cookie;
2664 cookie = ofpbuf_at(ctx->odp_actions, user_cookie_offset,
2665 sizeof cookie->sflow);
2666 ovs_assert(cookie->type == USER_ACTION_COOKIE_SFLOW);
2668 cookie->type = USER_ACTION_COOKIE_SFLOW;
2669 cookie->sflow.vlan_tci = base->vlan_tci;
2671 /* See http://www.sflow.org/sflow_version_5.txt (search for "Input/output
2672 * port information") for the interpretation of cookie->output. */
2673 switch (ctx->sflow_n_outputs) {
2675 /* 0x40000000 | 256 means "packet dropped for unknown reason". */
2676 cookie->sflow.output = 0x40000000 | 256;
2680 cookie->sflow.output = dpif_sflow_odp_port_to_ifindex(
2681 ctx->xbridge->sflow, ctx->sflow_odp_port);
2682 if (cookie->sflow.output) {
2687 /* 0x80000000 means "multiple output ports. */
2688 cookie->sflow.output = 0x80000000 | ctx->sflow_n_outputs;
2694 process_special(struct xlate_ctx *ctx, const struct xport *xport)
2696 const struct flow *flow = &ctx->xin->flow;
2697 struct flow_wildcards *wc = ctx->wc;
2698 const struct xbridge *xbridge = ctx->xbridge;
2699 const struct dp_packet *packet = ctx->xin->packet;
2700 enum slow_path_reason slow;
2704 } else if (xport->cfm && cfm_should_process_flow(xport->cfm, flow, wc)) {
2706 cfm_process_heartbeat(xport->cfm, packet);
2709 } else if (xport->bfd && bfd_should_process_flow(xport->bfd, flow, wc)) {
2711 bfd_process_packet(xport->bfd, flow, packet);
2712 /* If POLL received, immediately sends FINAL back. */
2713 if (bfd_should_send_packet(xport->bfd)) {
2714 ofproto_dpif_monitor_port_send_soon(xport->ofport);
2718 } else if (xport->xbundle && xport->xbundle->lacp
2719 && flow->dl_type == htons(ETH_TYPE_LACP)) {
2721 lacp_process_packet(xport->xbundle->lacp, xport->ofport, packet);
2724 } else if ((xbridge->stp || xbridge->rstp) &&
2725 stp_should_process_flow(flow, wc)) {
2728 ? stp_process_packet(xport, packet)
2729 : rstp_process_packet(xport, packet);
2732 } else if (xport->lldp && lldp_should_process_flow(xport->lldp, flow)) {
2734 lldp_process_packet(xport->lldp, packet);
2742 ctx->xout->slow |= slow;
2750 tnl_route_lookup_flow(const struct flow *oflow,
2751 struct in6_addr *ip, struct xport **out_port)
2753 char out_dev[IFNAMSIZ];
2754 struct xbridge *xbridge;
2755 struct xlate_cfg *xcfg;
2757 struct in6_addr dst;
2759 dst = flow_tnl_dst(&oflow->tunnel);
2760 if (!ovs_router_lookup(&dst, out_dev, &gw)) {
2764 if (ipv6_addr_is_set(&gw) &&
2765 (!IN6_IS_ADDR_V4MAPPED(&gw) || in6_addr_get_mapped_ipv4(&gw))) {
2771 xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
2774 HMAP_FOR_EACH (xbridge, hmap_node, &xcfg->xbridges) {
2775 if (!strncmp(xbridge->name, out_dev, IFNAMSIZ)) {
2778 HMAP_FOR_EACH (port, ofp_node, &xbridge->xports) {
2779 if (!strncmp(netdev_get_name(port->netdev), out_dev, IFNAMSIZ)) {
2790 compose_table_xlate(struct xlate_ctx *ctx, const struct xport *out_dev,
2791 struct dp_packet *packet)
2793 struct xbridge *xbridge = out_dev->xbridge;
2794 struct ofpact_output output;
2797 ofpact_init(&output.ofpact, OFPACT_OUTPUT, sizeof output);
2798 flow_extract(packet, &flow);
2799 flow.in_port.ofp_port = out_dev->ofp_port;
2800 output.port = OFPP_TABLE;
2803 return ofproto_dpif_execute_actions__(xbridge->ofproto, &flow, NULL,
2804 &output.ofpact, sizeof output,
2805 ctx->recurse, ctx->resubmits, packet);
2809 tnl_send_nd_request(struct xlate_ctx *ctx, const struct xport *out_dev,
2810 const struct eth_addr eth_src,
2811 struct in6_addr * ipv6_src, struct in6_addr * ipv6_dst)
2813 struct dp_packet packet;
2815 dp_packet_init(&packet, 0);
2816 compose_nd(&packet, eth_src, ipv6_src, ipv6_dst);
2817 compose_table_xlate(ctx, out_dev, &packet);
2818 dp_packet_uninit(&packet);
2822 tnl_send_arp_request(struct xlate_ctx *ctx, const struct xport *out_dev,
2823 const struct eth_addr eth_src,
2824 ovs_be32 ip_src, ovs_be32 ip_dst)
2826 struct dp_packet packet;
2828 dp_packet_init(&packet, 0);
2829 compose_arp(&packet, ARP_OP_REQUEST,
2830 eth_src, eth_addr_zero, true, ip_src, ip_dst);
2832 compose_table_xlate(ctx, out_dev, &packet);
2833 dp_packet_uninit(&packet);
2837 build_tunnel_send(struct xlate_ctx *ctx, const struct xport *xport,
2838 const struct flow *flow, odp_port_t tunnel_odp_port)
2840 struct ovs_action_push_tnl tnl_push_data;
2841 struct xport *out_dev = NULL;
2842 ovs_be32 s_ip = 0, d_ip = 0;
2843 struct in6_addr s_ip6 = in6addr_any;
2844 struct in6_addr d_ip6 = in6addr_any;
2845 struct eth_addr smac;
2846 struct eth_addr dmac;
2848 char buf_sip6[INET6_ADDRSTRLEN];
2849 char buf_dip6[INET6_ADDRSTRLEN];
2851 err = tnl_route_lookup_flow(flow, &d_ip6, &out_dev);
2853 xlate_report(ctx, "native tunnel routing failed");
2857 xlate_report(ctx, "tunneling to %s via %s",
2858 ipv6_string_mapped(buf_dip6, &d_ip6),
2859 netdev_get_name(out_dev->netdev));
2861 /* Use mac addr of bridge port of the peer. */
2862 err = netdev_get_etheraddr(out_dev->netdev, &smac);
2864 xlate_report(ctx, "tunnel output device lacks Ethernet address");
2868 d_ip = in6_addr_get_mapped_ipv4(&d_ip6);
2870 err = netdev_get_in4(out_dev->netdev, (struct in_addr *) &s_ip, NULL);
2872 xlate_report(ctx, "tunnel output device lacks IPv4 address");
2875 in6_addr_set_mapped_ipv4(&s_ip6, s_ip);
2877 err = netdev_get_in6(out_dev->netdev, &s_ip6);
2879 xlate_report(ctx, "tunnel output device lacks IPv6 address");
2884 err = tnl_neigh_lookup(out_dev->xbridge->name, &d_ip6, &dmac);
2886 xlate_report(ctx, "neighbor cache miss for %s on bridge %s, "
2887 "sending %s request",
2888 buf_dip6, out_dev->xbridge->name, d_ip ? "ARP" : "ND");
2890 tnl_send_arp_request(ctx, out_dev, smac, s_ip, d_ip);
2892 tnl_send_nd_request(ctx, out_dev, smac, &s_ip6, &d_ip6);
2897 if (ctx->xin->xcache) {
2898 struct xc_entry *entry;
2900 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_TNL_NEIGH);
2901 ovs_strlcpy(entry->u.tnl_neigh_cache.br_name, out_dev->xbridge->name,
2902 sizeof entry->u.tnl_neigh_cache.br_name);
2903 entry->u.tnl_neigh_cache.d_ipv6 = d_ip6;
2906 xlate_report(ctx, "tunneling from "ETH_ADDR_FMT" %s"
2907 " to "ETH_ADDR_FMT" %s",
2908 ETH_ADDR_ARGS(smac), ipv6_string_mapped(buf_sip6, &s_ip6),
2909 ETH_ADDR_ARGS(dmac), buf_dip6);
2911 err = tnl_port_build_header(xport->ofport, flow,
2912 dmac, smac, &s_ip6, &tnl_push_data);
2916 tnl_push_data.tnl_port = odp_to_u32(tunnel_odp_port);
2917 tnl_push_data.out_port = odp_to_u32(out_dev->odp_port);
2918 odp_put_tnl_push_action(ctx->odp_actions, &tnl_push_data);
2923 xlate_commit_actions(struct xlate_ctx *ctx)
2925 bool use_masked = ctx->xbridge->support.masked_set_action;
2927 ctx->xout->slow |= commit_odp_actions(&ctx->xin->flow, &ctx->base_flow,
2928 ctx->odp_actions, ctx->wc,
2933 clear_conntrack(struct flow *flow)
2938 memset(&flow->ct_label, 0, sizeof flow->ct_label);
2942 compose_output_action__(struct xlate_ctx *ctx, ofp_port_t ofp_port,
2943 const struct xlate_bond_recirc *xr, bool check_stp)
2945 const struct xport *xport = get_ofp_port(ctx->xbridge, ofp_port);
2946 struct flow_wildcards *wc = ctx->wc;
2947 struct flow *flow = &ctx->xin->flow;
2948 struct flow_tnl flow_tnl;
2949 ovs_be16 flow_vlan_tci;
2950 uint32_t flow_pkt_mark;
2951 uint8_t flow_nw_tos;
2952 odp_port_t out_port, odp_port;
2953 bool tnl_push_pop_send = false;
2956 /* If 'struct flow' gets additional metadata, we'll need to zero it out
2957 * before traversing a patch port. */
2958 BUILD_ASSERT_DECL(FLOW_WC_SEQ == 35);
2959 memset(&flow_tnl, 0, sizeof flow_tnl);
2962 xlate_report(ctx, "Nonexistent output port");
2964 } else if (xport->config & OFPUTIL_PC_NO_FWD) {
2965 xlate_report(ctx, "OFPPC_NO_FWD set, skipping output");
2967 } else if (check_stp) {
2968 if (is_stp(&ctx->base_flow)) {
2969 if (!xport_stp_should_forward_bpdu(xport) &&
2970 !xport_rstp_should_manage_bpdu(xport)) {
2971 if (ctx->xbridge->stp != NULL) {
2972 xlate_report(ctx, "STP not in listening state, "
2973 "skipping bpdu output");
2974 } else if (ctx->xbridge->rstp != NULL) {
2975 xlate_report(ctx, "RSTP not managing BPDU in this state, "
2976 "skipping bpdu output");
2980 } else if (!xport_stp_forward_state(xport) ||
2981 !xport_rstp_forward_state(xport)) {
2982 if (ctx->xbridge->stp != NULL) {
2983 xlate_report(ctx, "STP not in forwarding state, "
2985 } else if (ctx->xbridge->rstp != NULL) {
2986 xlate_report(ctx, "RSTP not in forwarding state, "
2994 const struct xport *peer = xport->peer;
2995 struct flow old_flow = ctx->xin->flow;
2996 bool old_conntrack = ctx->conntracked;
2997 bool old_was_mpls = ctx->was_mpls;
2998 cls_version_t old_version = ctx->tables_version;
2999 struct ofpbuf old_stack = ctx->stack;
3000 union mf_subvalue new_stack[1024 / sizeof(union mf_subvalue)];
3001 struct ofpbuf old_action_set = ctx->action_set;
3002 uint64_t actset_stub[1024 / 8];
3004 ofpbuf_use_stub(&ctx->stack, new_stack, sizeof new_stack);
3005 ofpbuf_use_stub(&ctx->action_set, actset_stub, sizeof actset_stub);
3006 ctx->xbridge = peer->xbridge;
3007 flow->in_port.ofp_port = peer->ofp_port;
3008 flow->metadata = htonll(0);
3009 memset(&flow->tunnel, 0, sizeof flow->tunnel);
3010 memset(flow->regs, 0, sizeof flow->regs);
3011 flow->actset_output = OFPP_UNSET;
3012 ctx->conntracked = false;
3013 clear_conntrack(flow);
3015 /* The bridge is now known so obtain its table version. */
3017 = ofproto_dpif_get_tables_version(ctx->xbridge->ofproto);
3019 if (!process_special(ctx, peer) && may_receive(peer, ctx)) {
3020 if (xport_stp_forward_state(peer) && xport_rstp_forward_state(peer)) {
3021 xlate_table_action(ctx, flow->in_port.ofp_port, 0, true, true);
3022 if (!ctx->freezing) {
3023 xlate_action_set(ctx);
3025 if (ctx->freezing) {
3026 compose_recirculate_action(ctx);
3029 /* Forwarding is disabled by STP and RSTP. Let OFPP_NORMAL and
3030 * the learning action look at the packet, then drop it. */
3031 struct flow old_base_flow = ctx->base_flow;
3032 size_t old_size = ctx->odp_actions->size;
3033 mirror_mask_t old_mirrors = ctx->mirrors;
3035 xlate_table_action(ctx, flow->in_port.ofp_port, 0, true, true);
3036 ctx->mirrors = old_mirrors;
3037 ctx->base_flow = old_base_flow;
3038 ctx->odp_actions->size = old_size;
3040 /* Undo changes that may have been done for freezing. */
3041 ctx_cancel_freeze(ctx);
3045 ctx->xin->flow = old_flow;
3046 ctx->xbridge = xport->xbridge;
3047 ofpbuf_uninit(&ctx->action_set);
3048 ctx->action_set = old_action_set;
3049 ofpbuf_uninit(&ctx->stack);
3050 ctx->stack = old_stack;
3052 /* Restore calling bridge's lookup version. */
3053 ctx->tables_version = old_version;
3055 /* The peer bridge popping MPLS should have no effect on the original
3057 ctx->was_mpls = old_was_mpls;
3059 /* The peer bridge's conntrack execution should have no effect on the
3060 * original bridge. */
3061 ctx->conntracked = old_conntrack;
3063 /* The fact that the peer bridge exits (for any reason) does not mean
3064 * that the original bridge should exit. Specifically, if the peer
3065 * bridge freezes translation, the original bridge must continue
3066 * processing with the original, not the frozen packet! */
3069 /* Peer bridge errors do not propagate back. */
3070 ctx->error = XLATE_OK;
3072 if (ctx->xin->resubmit_stats) {
3073 netdev_vport_inc_tx(xport->netdev, ctx->xin->resubmit_stats);
3074 netdev_vport_inc_rx(peer->netdev, ctx->xin->resubmit_stats);
3076 bfd_account_rx(peer->bfd, ctx->xin->resubmit_stats);
3079 if (ctx->xin->xcache) {
3080 struct xc_entry *entry;
3082 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_NETDEV);
3083 entry->u.dev.tx = netdev_ref(xport->netdev);
3084 entry->u.dev.rx = netdev_ref(peer->netdev);
3085 entry->u.dev.bfd = bfd_ref(peer->bfd);
3090 flow_vlan_tci = flow->vlan_tci;
3091 flow_pkt_mark = flow->pkt_mark;
3092 flow_nw_tos = flow->nw_tos;
3094 if (count_skb_priorities(xport)) {
3095 memset(&wc->masks.skb_priority, 0xff, sizeof wc->masks.skb_priority);
3096 if (dscp_from_skb_priority(xport, flow->skb_priority, &dscp)) {
3097 wc->masks.nw_tos |= IP_DSCP_MASK;
3098 flow->nw_tos &= ~IP_DSCP_MASK;
3099 flow->nw_tos |= dscp;
3103 if (xport->is_tunnel) {
3104 struct in6_addr dst;
3105 /* Save tunnel metadata so that changes made due to
3106 * the Logical (tunnel) Port are not visible for any further
3107 * matches, while explicit set actions on tunnel metadata are.
3109 flow_tnl = flow->tunnel;
3110 odp_port = tnl_port_send(xport->ofport, flow, ctx->wc);
3111 if (odp_port == ODPP_NONE) {
3112 xlate_report(ctx, "Tunneling decided against output");
3113 goto out; /* restore flow_nw_tos */
3115 dst = flow_tnl_dst(&flow->tunnel);
3116 if (ipv6_addr_equals(&dst, &ctx->orig_tunnel_ipv6_dst)) {
3117 xlate_report(ctx, "Not tunneling to our own address");
3118 goto out; /* restore flow_nw_tos */
3120 if (ctx->xin->resubmit_stats) {
3121 netdev_vport_inc_tx(xport->netdev, ctx->xin->resubmit_stats);
3123 if (ctx->xin->xcache) {
3124 struct xc_entry *entry;
3126 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_NETDEV);
3127 entry->u.dev.tx = netdev_ref(xport->netdev);
3129 out_port = odp_port;
3130 if (ovs_native_tunneling_is_on(ctx->xbridge->ofproto)) {
3131 xlate_report(ctx, "output to native tunnel");
3132 tnl_push_pop_send = true;
3134 xlate_report(ctx, "output to kernel tunnel");
3135 commit_odp_tunnel_action(flow, &ctx->base_flow, ctx->odp_actions);
3136 flow->tunnel = flow_tnl; /* Restore tunnel metadata */
3139 odp_port = xport->odp_port;
3140 out_port = odp_port;
3141 if (ofproto_has_vlan_splinters(ctx->xbridge->ofproto)) {
3142 ofp_port_t vlandev_port;
3144 wc->masks.vlan_tci |= htons(VLAN_VID_MASK | VLAN_CFI);
3145 vlandev_port = vsp_realdev_to_vlandev(ctx->xbridge->ofproto,
3146 ofp_port, flow->vlan_tci);
3147 if (vlandev_port != ofp_port) {
3148 out_port = ofp_port_to_odp_port(ctx->xbridge, vlandev_port);
3149 flow->vlan_tci = htons(0);
3154 if (out_port != ODPP_NONE) {
3155 xlate_commit_actions(ctx);
3158 struct ovs_action_hash *act_hash;
3161 act_hash = nl_msg_put_unspec_uninit(ctx->odp_actions,
3162 OVS_ACTION_ATTR_HASH,
3164 act_hash->hash_alg = xr->hash_alg;
3165 act_hash->hash_basis = xr->hash_basis;
3167 /* Recirc action. */
3168 nl_msg_put_u32(ctx->odp_actions, OVS_ACTION_ATTR_RECIRC,
3172 if (tnl_push_pop_send) {
3173 build_tunnel_send(ctx, xport, flow, odp_port);
3174 flow->tunnel = flow_tnl; /* Restore tunnel metadata */
3176 odp_port_t odp_tnl_port = ODPP_NONE;
3178 /* XXX: Write better Filter for tunnel port. We can use inport
3179 * int tunnel-port flow to avoid these checks completely. */
3180 if (ofp_port == OFPP_LOCAL &&
3181 ovs_native_tunneling_is_on(ctx->xbridge->ofproto)) {
3183 odp_tnl_port = tnl_port_map_lookup(flow, wc);
3186 if (odp_tnl_port != ODPP_NONE) {
3187 nl_msg_put_odp_port(ctx->odp_actions,
3188 OVS_ACTION_ATTR_TUNNEL_POP,
3191 /* Tunnel push-pop action is not compatible with
3193 compose_ipfix_action(ctx, out_port);
3194 nl_msg_put_odp_port(ctx->odp_actions,
3195 OVS_ACTION_ATTR_OUTPUT,
3201 ctx->sflow_odp_port = odp_port;
3202 ctx->sflow_n_outputs++;
3203 ctx->nf_output_iface = ofp_port;
3206 if (mbridge_has_mirrors(ctx->xbridge->mbridge) && xport->xbundle) {
3207 mirror_packet(ctx, xport->xbundle,
3208 xbundle_mirror_dst(xport->xbundle->xbridge,
3214 flow->vlan_tci = flow_vlan_tci;
3215 flow->pkt_mark = flow_pkt_mark;
3216 flow->nw_tos = flow_nw_tos;
3220 compose_output_action(struct xlate_ctx *ctx, ofp_port_t ofp_port,
3221 const struct xlate_bond_recirc *xr)
3223 compose_output_action__(ctx, ofp_port, xr, true);
3227 xlate_recursively(struct xlate_ctx *ctx, struct rule_dpif *rule)
3229 struct rule_dpif *old_rule = ctx->rule;
3230 ovs_be64 old_cookie = ctx->rule_cookie;
3231 const struct rule_actions *actions;
3233 if (ctx->xin->resubmit_stats) {
3234 rule_dpif_credit_stats(rule, ctx->xin->resubmit_stats);
3240 ctx->rule_cookie = rule_dpif_get_flow_cookie(rule);
3241 actions = rule_dpif_get_actions(rule);
3242 do_xlate_actions(actions->ofpacts, actions->ofpacts_len, ctx);
3243 ctx->rule_cookie = old_cookie;
3244 ctx->rule = old_rule;
3249 xlate_resubmit_resource_check(struct xlate_ctx *ctx)
3251 if (ctx->recurse >= MAX_RESUBMIT_RECURSION + MAX_INTERNAL_RESUBMITS) {
3252 XLATE_REPORT_ERROR(ctx, "resubmit actions recursed over %d times",
3253 MAX_RESUBMIT_RECURSION);
3254 ctx->error = XLATE_RECURSION_TOO_DEEP;
3255 } else if (ctx->resubmits >= MAX_RESUBMITS + MAX_INTERNAL_RESUBMITS) {
3256 XLATE_REPORT_ERROR(ctx, "over %d resubmit actions", MAX_RESUBMITS);
3257 ctx->error = XLATE_TOO_MANY_RESUBMITS;
3258 } else if (ctx->odp_actions->size > UINT16_MAX) {
3259 XLATE_REPORT_ERROR(ctx, "resubmits yielded over 64 kB of actions");
3260 /* NOT an error, as we'll be slow-pathing the flow in this case? */
3261 ctx->exit = true; /* XXX: translation still terminated! */
3262 } else if (ctx->stack.size >= 65536) {
3263 XLATE_REPORT_ERROR(ctx, "resubmits yielded over 64 kB of stack");
3264 ctx->error = XLATE_STACK_TOO_DEEP;
3273 xlate_table_action(struct xlate_ctx *ctx, ofp_port_t in_port, uint8_t table_id,
3274 bool may_packet_in, bool honor_table_miss)
3276 /* Check if we need to recirculate before matching in a table. */
3277 if (ctx->was_mpls) {
3278 ctx_trigger_freeze(ctx);
3281 if (xlate_resubmit_resource_check(ctx)) {
3282 uint8_t old_table_id = ctx->table_id;
3283 struct rule_dpif *rule;
3285 ctx->table_id = table_id;
3287 rule = rule_dpif_lookup_from_table(ctx->xbridge->ofproto,
3288 ctx->tables_version,
3289 &ctx->xin->flow, ctx->xin->wc,
3290 ctx->xin->resubmit_stats,
3291 &ctx->table_id, in_port,
3292 may_packet_in, honor_table_miss);
3294 if (OVS_UNLIKELY(ctx->xin->resubmit_hook)) {
3295 ctx->xin->resubmit_hook(ctx->xin, rule, ctx->recurse + 1);
3299 /* Fill in the cache entry here instead of xlate_recursively
3300 * to make the reference counting more explicit. We take a
3301 * reference in the lookups above if we are going to cache the
3303 if (ctx->xin->xcache) {
3304 struct xc_entry *entry;
3306 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_RULE);
3307 entry->u.rule = rule;
3308 rule_dpif_ref(rule);
3310 xlate_recursively(ctx, rule);
3313 ctx->table_id = old_table_id;
3319 xlate_group_stats(struct xlate_ctx *ctx, struct group_dpif *group,
3320 struct ofputil_bucket *bucket)
3322 if (ctx->xin->resubmit_stats) {
3323 group_dpif_credit_stats(group, bucket, ctx->xin->resubmit_stats);
3325 if (ctx->xin->xcache) {
3326 struct xc_entry *entry;
3328 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_GROUP);
3329 entry->u.group.group = group_dpif_ref(group);
3330 entry->u.group.bucket = bucket;
3335 xlate_group_bucket(struct xlate_ctx *ctx, struct ofputil_bucket *bucket)
3337 uint64_t action_list_stub[1024 / 8];
3338 struct ofpbuf action_list = OFPBUF_STUB_INITIALIZER(action_list_stub);
3339 struct ofpbuf action_set = ofpbuf_const_initializer(bucket->ofpacts,
3340 bucket->ofpacts_len);
3341 struct flow old_flow = ctx->xin->flow;
3342 bool old_was_mpls = ctx->was_mpls;
3344 ofpacts_execute_action_set(&action_list, &action_set);
3346 do_xlate_actions(action_list.data, action_list.size, ctx);
3349 ofpbuf_uninit(&action_list);
3351 /* Check if need to recirculate. */
3352 if (ctx->freezing) {
3353 compose_recirculate_action(ctx);
3356 /* Roll back flow to previous state.
3357 * This is equivalent to cloning the packet for each bucket.
3359 * As a side effect any subsequently applied actions will
3360 * also effectively be applied to a clone of the packet taken
3361 * just before applying the all or indirect group.
3363 * Note that group buckets are action sets, hence they cannot modify the
3364 * main action set. Also any stack actions are ignored when executing an
3365 * action set, so group buckets cannot change the stack either.
3366 * However, we do allow resubmit actions in group buckets, which could
3367 * break the above assumptions. It is up to the controller to not mess up
3368 * with the action_set and stack in the tables resubmitted to from
3370 ctx->xin->flow = old_flow;
3372 /* The group bucket popping MPLS should have no effect after bucket
3374 ctx->was_mpls = old_was_mpls;
3376 /* The fact that the group bucket exits (for any reason) does not mean that
3377 * the translation after the group action should exit. Specifically, if
3378 * the group bucket freezes translation, the actions after the group action
3379 * must continue processing with the original, not the frozen packet! */
3384 xlate_all_group(struct xlate_ctx *ctx, struct group_dpif *group)
3386 struct ofputil_bucket *bucket;
3387 const struct ovs_list *buckets;
3389 group_dpif_get_buckets(group, &buckets);
3391 LIST_FOR_EACH (bucket, list_node, buckets) {
3392 xlate_group_bucket(ctx, bucket);
3394 xlate_group_stats(ctx, group, NULL);
3398 xlate_ff_group(struct xlate_ctx *ctx, struct group_dpif *group)
3400 struct ofputil_bucket *bucket;
3402 bucket = group_first_live_bucket(ctx, group, 0);
3404 xlate_group_bucket(ctx, bucket);
3405 xlate_group_stats(ctx, group, bucket);
3410 xlate_default_select_group(struct xlate_ctx *ctx, struct group_dpif *group)
3412 struct flow_wildcards *wc = ctx->wc;
3413 struct ofputil_bucket *bucket;
3416 basis = flow_hash_symmetric_l4(&ctx->xin->flow, 0);
3417 flow_mask_hash_fields(&ctx->xin->flow, wc, NX_HASH_FIELDS_SYMMETRIC_L4);
3418 bucket = group_best_live_bucket(ctx, group, basis);
3420 xlate_group_bucket(ctx, bucket);
3421 xlate_group_stats(ctx, group, bucket);
3426 xlate_hash_fields_select_group(struct xlate_ctx *ctx, struct group_dpif *group)
3428 struct mf_bitmap hash_fields = MF_BITMAP_INITIALIZER;
3429 const struct field_array *fields;
3430 struct ofputil_bucket *bucket;
3434 fields = group_dpif_get_fields(group);
3435 basis = hash_uint64(group_dpif_get_selection_method_param(group));
3437 /* Determine which fields to hash */
3438 for (i = 0; i < MFF_N_IDS; i++) {
3439 if (bitmap_is_set(fields->used.bm, i)) {
3440 const struct mf_field *mf;
3442 /* If the field is already present in 'hash_fields' then
3443 * this loop has already checked that it and its pre-requisites
3444 * are present in the flow and its pre-requisites have
3445 * already been added to 'hash_fields'. There is nothing more
3446 * to do here and as an optimisation the loop can continue. */
3447 if (bitmap_is_set(hash_fields.bm, i)) {
3453 /* Only hash a field if it and its pre-requisites are present
3455 if (!mf_are_prereqs_ok(mf, &ctx->xin->flow)) {
3459 /* Hash both the field and its pre-requisites */
3460 mf_bitmap_set_field_and_prereqs(mf, &hash_fields);
3464 /* Hash the fields */
3465 for (i = 0; i < MFF_N_IDS; i++) {
3466 if (bitmap_is_set(hash_fields.bm, i)) {
3467 const struct mf_field *mf = mf_from_id(i);
3468 union mf_value value;
3471 mf_get_value(mf, &ctx->xin->flow, &value);
3472 /* This seems inefficient but so does apply_mask() */
3473 for (j = 0; j < mf->n_bytes; j++) {
3474 ((uint8_t *) &value)[j] &= ((uint8_t *) &fields->value[i])[j];
3476 basis = hash_bytes(&value, mf->n_bytes, basis);
3478 /* For tunnels, hash in whether the field is present. */
3479 if (mf_is_tun_metadata(mf)) {
3480 basis = hash_boolean(mf_is_set(mf, &ctx->xin->flow), basis);
3483 mf_mask_field(mf, &ctx->wc->masks);
3487 bucket = group_best_live_bucket(ctx, group, basis);
3489 xlate_group_bucket(ctx, bucket);
3490 xlate_group_stats(ctx, group, bucket);
3495 xlate_select_group(struct xlate_ctx *ctx, struct group_dpif *group)
3497 const char *selection_method = group_dpif_get_selection_method(group);
3499 if (selection_method[0] == '\0') {
3500 xlate_default_select_group(ctx, group);
3501 } else if (!strcasecmp("hash", selection_method)) {
3502 xlate_hash_fields_select_group(ctx, group);
3504 /* Parsing of groups should ensure this never happens */
3510 xlate_group_action__(struct xlate_ctx *ctx, struct group_dpif *group)
3512 bool was_in_group = ctx->in_group;
3513 ctx->in_group = true;
3515 switch (group_dpif_get_type(group)) {
3517 case OFPGT11_INDIRECT:
3518 xlate_all_group(ctx, group);
3520 case OFPGT11_SELECT:
3521 xlate_select_group(ctx, group);
3524 xlate_ff_group(ctx, group);
3529 group_dpif_unref(group);
3531 ctx->in_group = was_in_group;
3535 xlate_group_action(struct xlate_ctx *ctx, uint32_t group_id)
3537 if (xlate_resubmit_resource_check(ctx)) {
3538 struct group_dpif *group;
3541 got_group = group_dpif_lookup(ctx->xbridge->ofproto, group_id, &group);
3543 xlate_group_action__(ctx, group);
3553 xlate_ofpact_resubmit(struct xlate_ctx *ctx,
3554 const struct ofpact_resubmit *resubmit)
3558 bool may_packet_in = false;
3559 bool honor_table_miss = false;
3561 if (ctx->rule && rule_dpif_is_internal(ctx->rule)) {
3562 /* Still allow missed packets to be sent to the controller
3563 * if resubmitting from an internal table. */
3564 may_packet_in = true;
3565 honor_table_miss = true;
3568 in_port = resubmit->in_port;
3569 if (in_port == OFPP_IN_PORT) {
3570 in_port = ctx->xin->flow.in_port.ofp_port;
3573 table_id = resubmit->table_id;
3574 if (table_id == 255) {
3575 table_id = ctx->table_id;
3578 xlate_table_action(ctx, in_port, table_id, may_packet_in,
3583 flood_packets(struct xlate_ctx *ctx, bool all)
3585 const struct xport *xport;
3587 HMAP_FOR_EACH (xport, ofp_node, &ctx->xbridge->xports) {
3588 if (xport->ofp_port == ctx->xin->flow.in_port.ofp_port) {
3593 compose_output_action__(ctx, xport->ofp_port, NULL, false);
3594 } else if (!(xport->config & OFPUTIL_PC_NO_FLOOD)) {
3595 compose_output_action(ctx, xport->ofp_port, NULL);
3599 ctx->nf_output_iface = NF_OUT_FLOOD;
3603 execute_controller_action(struct xlate_ctx *ctx, int len,
3604 enum ofp_packet_in_reason reason,
3605 uint16_t controller_id)
3607 struct dp_packet *packet;
3609 ctx->xout->slow |= SLOW_CONTROLLER;
3610 xlate_commit_actions(ctx);
3611 if (!ctx->xin->packet) {
3615 packet = dp_packet_clone(ctx->xin->packet);
3617 odp_execute_actions(NULL, &packet, 1, false,
3618 ctx->odp_actions->data, ctx->odp_actions->size, NULL);
3620 /* A packet sent by an action in a table-miss rule is considered an
3621 * explicit table miss. OpenFlow before 1.3 doesn't have that concept so
3622 * it will get translated back to OFPR_ACTION for those versions. */
3623 if (reason == OFPR_ACTION
3624 && ctx->rule && rule_dpif_is_table_miss(ctx->rule)) {
3625 reason = OFPR_EXPLICIT_MISS;
3628 size_t packet_len = dp_packet_size(packet);
3630 struct ofproto_async_msg *am = xmalloc(sizeof *am);
3631 *am = (struct ofproto_async_msg) {
3632 .controller_id = controller_id,
3633 .oam = OAM_PACKET_IN,
3636 .packet = dp_packet_steal_data(packet),
3639 .table_id = ctx->table_id,
3640 .cookie = ctx->rule_cookie,
3645 flow_get_metadata(&ctx->xin->flow, &am->pin.up.flow_metadata);
3647 ofproto_dpif_send_async_msg(ctx->xbridge->ofproto, am);
3648 dp_packet_delete(packet);
3652 compose_recirculate_action__(struct xlate_ctx *ctx, uint8_t table)
3654 struct frozen_metadata md;
3657 frozen_metadata_from_flow(&md, &ctx->xin->flow);
3659 ovs_assert(ctx->freezing);
3661 struct frozen_state state = {
3663 .ofproto_uuid = *ofproto_dpif_get_uuid(ctx->xbridge->ofproto),
3665 .stack = ctx->stack.data,
3666 .n_stack = ctx->stack.size / sizeof(union mf_subvalue),
3667 .mirrors = ctx->mirrors,
3668 .conntracked = ctx->conntracked,
3669 .ofpacts = ctx->frozen_actions.data,
3670 .ofpacts_len = ctx->frozen_actions.size,
3671 .action_set = ctx->action_set.data,
3672 .action_set_len = ctx->action_set.size,
3675 /* Allocate a unique recirc id for the given metadata state in the
3676 * flow. An existing id, with a new reference to the corresponding
3677 * recirculation context, will be returned if possible.
3678 * The life-cycle of this recirc id is managed by associating it
3679 * with the udpif key ('ukey') created for each new datapath flow. */
3680 id = recirc_alloc_id_ctx(&state);
3682 XLATE_REPORT_ERROR(ctx, "Failed to allocate recirculation id");
3683 ctx->error = XLATE_NO_RECIRCULATION_CONTEXT;
3686 recirc_refs_add(&ctx->xout->recircs, id);
3688 nl_msg_put_u32(ctx->odp_actions, OVS_ACTION_ATTR_RECIRC, id);
3690 /* Undo changes done by freezing. */
3691 ctx_cancel_freeze(ctx);
3694 /* Called only when we're freezing. */
3696 compose_recirculate_action(struct xlate_ctx *ctx)
3698 xlate_commit_actions(ctx);
3699 compose_recirculate_action__(ctx, 0);
3702 /* Fork the pipeline here. The current packet will continue processing the
3703 * current action list. A clone of the current packet will recirculate, skip
3704 * the remainder of the current action list and asynchronously resume pipeline
3705 * processing in 'table' with the current metadata and action set. */
3707 compose_recirculate_and_fork(struct xlate_ctx *ctx, uint8_t table)
3709 ctx->freezing = true;
3710 compose_recirculate_action__(ctx, table);
3714 compose_mpls_push_action(struct xlate_ctx *ctx, struct ofpact_push_mpls *mpls)
3716 struct flow *flow = &ctx->xin->flow;
3719 ovs_assert(eth_type_mpls(mpls->ethertype));
3721 n = flow_count_mpls_labels(flow, ctx->wc);
3723 xlate_commit_actions(ctx);
3724 } else if (n >= FLOW_MAX_MPLS_LABELS) {
3725 if (ctx->xin->packet != NULL) {
3726 XLATE_REPORT_ERROR(ctx, "bridge %s: dropping packet on which an "
3727 "MPLS push action can't be performed as it would "
3728 "have more MPLS LSEs than the %d supported.",
3729 ctx->xbridge->name, FLOW_MAX_MPLS_LABELS);
3731 ctx->error = XLATE_TOO_MANY_MPLS_LABELS;
3735 flow_push_mpls(flow, n, mpls->ethertype, ctx->wc);
3739 compose_mpls_pop_action(struct xlate_ctx *ctx, ovs_be16 eth_type)
3741 struct flow *flow = &ctx->xin->flow;
3742 int n = flow_count_mpls_labels(flow, ctx->wc);
3744 if (flow_pop_mpls(flow, n, eth_type, ctx->wc)) {
3745 if (ctx->xbridge->support.odp.recirc) {
3746 ctx->was_mpls = true;
3748 } else if (n >= FLOW_MAX_MPLS_LABELS) {
3749 if (ctx->xin->packet != NULL) {
3750 XLATE_REPORT_ERROR(ctx, "bridge %s: dropping packet on which an "
3751 "MPLS pop action can't be performed as it has "
3752 "more MPLS LSEs than the %d supported.",
3753 ctx->xbridge->name, FLOW_MAX_MPLS_LABELS);
3755 ctx->error = XLATE_TOO_MANY_MPLS_LABELS;
3756 ofpbuf_clear(ctx->odp_actions);
3761 compose_dec_ttl(struct xlate_ctx *ctx, struct ofpact_cnt_ids *ids)
3763 struct flow *flow = &ctx->xin->flow;
3765 if (!is_ip_any(flow)) {
3769 ctx->wc->masks.nw_ttl = 0xff;
3770 if (flow->nw_ttl > 1) {
3776 for (i = 0; i < ids->n_controllers; i++) {
3777 execute_controller_action(ctx, UINT16_MAX, OFPR_INVALID_TTL,
3781 /* Stop processing for current table. */
3787 compose_set_mpls_label_action(struct xlate_ctx *ctx, ovs_be32 label)
3789 if (eth_type_mpls(ctx->xin->flow.dl_type)) {
3790 ctx->wc->masks.mpls_lse[0] |= htonl(MPLS_LABEL_MASK);
3791 set_mpls_lse_label(&ctx->xin->flow.mpls_lse[0], label);
3796 compose_set_mpls_tc_action(struct xlate_ctx *ctx, uint8_t tc)
3798 if (eth_type_mpls(ctx->xin->flow.dl_type)) {
3799 ctx->wc->masks.mpls_lse[0] |= htonl(MPLS_TC_MASK);
3800 set_mpls_lse_tc(&ctx->xin->flow.mpls_lse[0], tc);
3805 compose_set_mpls_ttl_action(struct xlate_ctx *ctx, uint8_t ttl)
3807 if (eth_type_mpls(ctx->xin->flow.dl_type)) {
3808 ctx->wc->masks.mpls_lse[0] |= htonl(MPLS_TTL_MASK);
3809 set_mpls_lse_ttl(&ctx->xin->flow.mpls_lse[0], ttl);
3814 compose_dec_mpls_ttl_action(struct xlate_ctx *ctx)
3816 struct flow *flow = &ctx->xin->flow;
3818 if (eth_type_mpls(flow->dl_type)) {
3819 uint8_t ttl = mpls_lse_to_ttl(flow->mpls_lse[0]);
3821 ctx->wc->masks.mpls_lse[0] |= htonl(MPLS_TTL_MASK);
3824 set_mpls_lse_ttl(&flow->mpls_lse[0], ttl);
3827 execute_controller_action(ctx, UINT16_MAX, OFPR_INVALID_TTL, 0);
3831 /* Stop processing for current table. */
3836 xlate_output_action(struct xlate_ctx *ctx,
3837 ofp_port_t port, uint16_t max_len, bool may_packet_in)
3839 ofp_port_t prev_nf_output_iface = ctx->nf_output_iface;
3841 ctx->nf_output_iface = NF_OUT_DROP;
3845 compose_output_action(ctx, ctx->xin->flow.in_port.ofp_port, NULL);
3848 xlate_table_action(ctx, ctx->xin->flow.in_port.ofp_port,
3849 0, may_packet_in, true);
3855 flood_packets(ctx, false);
3858 flood_packets(ctx, true);
3860 case OFPP_CONTROLLER:
3861 execute_controller_action(ctx, max_len,
3862 (ctx->in_group ? OFPR_GROUP
3863 : ctx->in_action_set ? OFPR_ACTION_SET
3871 if (port != ctx->xin->flow.in_port.ofp_port) {
3872 compose_output_action(ctx, port, NULL);
3874 xlate_report(ctx, "skipping output to input port");
3879 if (prev_nf_output_iface == NF_OUT_FLOOD) {
3880 ctx->nf_output_iface = NF_OUT_FLOOD;
3881 } else if (ctx->nf_output_iface == NF_OUT_DROP) {
3882 ctx->nf_output_iface = prev_nf_output_iface;
3883 } else if (prev_nf_output_iface != NF_OUT_DROP &&
3884 ctx->nf_output_iface != NF_OUT_FLOOD) {
3885 ctx->nf_output_iface = NF_OUT_MULTI;
3890 xlate_output_reg_action(struct xlate_ctx *ctx,
3891 const struct ofpact_output_reg *or)
3893 uint64_t port = mf_get_subfield(&or->src, &ctx->xin->flow);
3894 if (port <= UINT16_MAX) {
3895 union mf_subvalue value;
3897 memset(&value, 0xff, sizeof value);
3898 mf_write_subfield_flow(&or->src, &value, &ctx->wc->masks);
3899 xlate_output_action(ctx, u16_to_ofp(port),
3900 or->max_len, false);
3905 xlate_enqueue_action(struct xlate_ctx *ctx,
3906 const struct ofpact_enqueue *enqueue)
3908 ofp_port_t ofp_port = enqueue->port;
3909 uint32_t queue_id = enqueue->queue;
3910 uint32_t flow_priority, priority;
3913 /* Translate queue to priority. */
3914 error = dpif_queue_to_priority(ctx->xbridge->dpif, queue_id, &priority);
3916 /* Fall back to ordinary output action. */
3917 xlate_output_action(ctx, enqueue->port, 0, false);
3921 /* Check output port. */
3922 if (ofp_port == OFPP_IN_PORT) {
3923 ofp_port = ctx->xin->flow.in_port.ofp_port;
3924 } else if (ofp_port == ctx->xin->flow.in_port.ofp_port) {
3928 /* Add datapath actions. */
3929 flow_priority = ctx->xin->flow.skb_priority;
3930 ctx->xin->flow.skb_priority = priority;
3931 compose_output_action(ctx, ofp_port, NULL);
3932 ctx->xin->flow.skb_priority = flow_priority;
3934 /* Update NetFlow output port. */
3935 if (ctx->nf_output_iface == NF_OUT_DROP) {
3936 ctx->nf_output_iface = ofp_port;
3937 } else if (ctx->nf_output_iface != NF_OUT_FLOOD) {
3938 ctx->nf_output_iface = NF_OUT_MULTI;
3943 xlate_set_queue_action(struct xlate_ctx *ctx, uint32_t queue_id)
3945 uint32_t skb_priority;
3947 if (!dpif_queue_to_priority(ctx->xbridge->dpif, queue_id, &skb_priority)) {
3948 ctx->xin->flow.skb_priority = skb_priority;
3950 /* Couldn't translate queue to a priority. Nothing to do. A warning
3951 * has already been logged. */
3956 slave_enabled_cb(ofp_port_t ofp_port, void *xbridge_)
3958 const struct xbridge *xbridge = xbridge_;
3969 case OFPP_CONTROLLER: /* Not supported by the bundle action. */
3972 port = get_ofp_port(xbridge, ofp_port);
3973 return port ? port->may_enable : false;
3978 xlate_bundle_action(struct xlate_ctx *ctx,
3979 const struct ofpact_bundle *bundle)
3983 port = bundle_execute(bundle, &ctx->xin->flow, ctx->wc, slave_enabled_cb,
3984 CONST_CAST(struct xbridge *, ctx->xbridge));
3985 if (bundle->dst.field) {
3986 nxm_reg_load(&bundle->dst, ofp_to_u16(port), &ctx->xin->flow, ctx->wc);
3988 xlate_output_action(ctx, port, 0, false);
3993 xlate_learn_action__(struct xlate_ctx *ctx, const struct ofpact_learn *learn,
3994 struct ofputil_flow_mod *fm, struct ofpbuf *ofpacts)
3996 learn_execute(learn, &ctx->xin->flow, fm, ofpacts);
3997 if (ctx->xin->may_learn) {
3998 ofproto_dpif_flow_mod(ctx->xbridge->ofproto, fm);
4003 xlate_learn_action(struct xlate_ctx *ctx, const struct ofpact_learn *learn)
4005 learn_mask(learn, ctx->wc);
4007 if (ctx->xin->xcache) {
4008 struct xc_entry *entry;
4010 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_LEARN);
4011 entry->u.learn.ofproto = ctx->xbridge->ofproto;
4012 entry->u.learn.fm = xmalloc(sizeof *entry->u.learn.fm);
4013 entry->u.learn.ofpacts = ofpbuf_new(64);
4014 xlate_learn_action__(ctx, learn, entry->u.learn.fm,
4015 entry->u.learn.ofpacts);
4016 } else if (ctx->xin->may_learn) {
4017 uint64_t ofpacts_stub[1024 / 8];
4018 struct ofputil_flow_mod fm;
4019 struct ofpbuf ofpacts;
4021 ofpbuf_use_stub(&ofpacts, ofpacts_stub, sizeof ofpacts_stub);
4022 xlate_learn_action__(ctx, learn, &fm, &ofpacts);
4023 ofpbuf_uninit(&ofpacts);
4028 xlate_fin_timeout__(struct rule_dpif *rule, uint16_t tcp_flags,
4029 uint16_t idle_timeout, uint16_t hard_timeout)
4031 if (tcp_flags & (TCP_FIN | TCP_RST)) {
4032 rule_dpif_reduce_timeouts(rule, idle_timeout, hard_timeout);
4037 xlate_fin_timeout(struct xlate_ctx *ctx,
4038 const struct ofpact_fin_timeout *oft)
4041 xlate_fin_timeout__(ctx->rule, ctx->xin->tcp_flags,
4042 oft->fin_idle_timeout, oft->fin_hard_timeout);
4043 if (ctx->xin->xcache) {
4044 struct xc_entry *entry;
4046 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_FIN_TIMEOUT);
4047 /* XC_RULE already holds a reference on the rule, none is taken
4049 entry->u.fin.rule = ctx->rule;
4050 entry->u.fin.idle = oft->fin_idle_timeout;
4051 entry->u.fin.hard = oft->fin_hard_timeout;
4057 xlate_sample_action(struct xlate_ctx *ctx,
4058 const struct ofpact_sample *os)
4060 /* Scale the probability from 16-bit to 32-bit while representing
4061 * the same percentage. */
4062 uint32_t probability = (os->probability << 16) | os->probability;
4064 if (!ctx->xbridge->support.variable_length_userdata) {
4065 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
4067 VLOG_ERR_RL(&rl, "ignoring NXAST_SAMPLE action because datapath "
4068 "lacks support (needs Linux 3.10+ or kernel module from "
4073 xlate_commit_actions(ctx);
4075 union user_action_cookie cookie = {
4077 .type = USER_ACTION_COOKIE_FLOW_SAMPLE,
4078 .probability = os->probability,
4079 .collector_set_id = os->collector_set_id,
4080 .obs_domain_id = os->obs_domain_id,
4081 .obs_point_id = os->obs_point_id,
4084 compose_sample_action(ctx, probability, &cookie, sizeof cookie.flow_sample,
4089 may_receive(const struct xport *xport, struct xlate_ctx *ctx)
4091 if (xport->config & (is_stp(&ctx->xin->flow)
4092 ? OFPUTIL_PC_NO_RECV_STP
4093 : OFPUTIL_PC_NO_RECV)) {
4097 /* Only drop packets here if both forwarding and learning are
4098 * disabled. If just learning is enabled, we need to have
4099 * OFPP_NORMAL and the learning action have a look at the packet
4100 * before we can drop it. */
4101 if ((!xport_stp_forward_state(xport) && !xport_stp_learn_state(xport)) ||
4102 (!xport_rstp_forward_state(xport) && !xport_rstp_learn_state(xport))) {
4110 xlate_write_actions__(struct xlate_ctx *ctx,
4111 const struct ofpact *ofpacts, size_t ofpacts_len)
4113 /* Maintain actset_output depending on the contents of the action set:
4115 * - OFPP_UNSET, if there is no "output" action.
4117 * - The output port, if there is an "output" action and no "group"
4120 * - OFPP_UNSET, if there is a "group" action.
4122 if (!ctx->action_set_has_group) {
4123 const struct ofpact *a;
4124 OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
4125 if (a->type == OFPACT_OUTPUT) {
4126 ctx->xin->flow.actset_output = ofpact_get_OUTPUT(a)->port;
4127 } else if (a->type == OFPACT_GROUP) {
4128 ctx->xin->flow.actset_output = OFPP_UNSET;
4129 ctx->action_set_has_group = true;
4135 ofpbuf_put(&ctx->action_set, ofpacts, ofpacts_len);
4139 xlate_write_actions(struct xlate_ctx *ctx, const struct ofpact_nest *a)
4141 xlate_write_actions__(ctx, a->actions, ofpact_nest_get_action_len(a));
4145 xlate_action_set(struct xlate_ctx *ctx)
4147 uint64_t action_list_stub[1024 / 64];
4148 struct ofpbuf action_list;
4150 ctx->in_action_set = true;
4151 ofpbuf_use_stub(&action_list, action_list_stub, sizeof action_list_stub);
4152 ofpacts_execute_action_set(&action_list, &ctx->action_set);
4153 /* Clear the action set, as it is not needed any more. */
4154 ofpbuf_clear(&ctx->action_set);
4155 do_xlate_actions(action_list.data, action_list.size, ctx);
4156 ctx->in_action_set = false;
4157 ofpbuf_uninit(&action_list);
4161 freeze_put_unroll_xlate(struct xlate_ctx *ctx)
4163 struct ofpact_unroll_xlate *unroll = ctx->frozen_actions.header;
4165 /* Restore the table_id and rule cookie for a potential PACKET
4168 (ctx->table_id != unroll->rule_table_id
4169 || ctx->rule_cookie != unroll->rule_cookie)) {
4170 unroll = ofpact_put_UNROLL_XLATE(&ctx->frozen_actions);
4171 unroll->rule_table_id = ctx->table_id;
4172 unroll->rule_cookie = ctx->rule_cookie;
4173 ctx->frozen_actions.header = unroll;
4178 /* Copy actions 'a' through 'end' to ctx->frozen_actions, which will be
4179 * executed after thawing. Inserts an UNROLL_XLATE action, if none is already
4180 * present, before any action that may depend on the current table ID or flow
4183 freeze_unroll_actions(const struct ofpact *a, const struct ofpact *end,
4184 struct xlate_ctx *ctx)
4186 for (; a < end; a = ofpact_next(a)) {
4188 case OFPACT_OUTPUT_REG:
4191 case OFPACT_CONTROLLER:
4192 case OFPACT_DEC_MPLS_TTL:
4193 case OFPACT_DEC_TTL:
4194 /* These actions may generate asynchronous messages, which include
4195 * table ID and flow cookie information. */
4196 freeze_put_unroll_xlate(ctx);
4199 case OFPACT_RESUBMIT:
4200 if (ofpact_get_RESUBMIT(a)->table_id == 0xff) {
4201 /* This resubmit action is relative to the current table, so we
4202 * need to track what table that is.*/
4203 freeze_put_unroll_xlate(ctx);
4207 case OFPACT_SET_TUNNEL:
4208 case OFPACT_REG_MOVE:
4209 case OFPACT_SET_FIELD:
4210 case OFPACT_STACK_PUSH:
4211 case OFPACT_STACK_POP:
4213 case OFPACT_WRITE_METADATA:
4214 case OFPACT_GOTO_TABLE:
4215 case OFPACT_ENQUEUE:
4216 case OFPACT_SET_VLAN_VID:
4217 case OFPACT_SET_VLAN_PCP:
4218 case OFPACT_STRIP_VLAN:
4219 case OFPACT_PUSH_VLAN:
4220 case OFPACT_SET_ETH_SRC:
4221 case OFPACT_SET_ETH_DST:
4222 case OFPACT_SET_IPV4_SRC:
4223 case OFPACT_SET_IPV4_DST:
4224 case OFPACT_SET_IP_DSCP:
4225 case OFPACT_SET_IP_ECN:
4226 case OFPACT_SET_IP_TTL:
4227 case OFPACT_SET_L4_SRC_PORT:
4228 case OFPACT_SET_L4_DST_PORT:
4229 case OFPACT_SET_QUEUE:
4230 case OFPACT_POP_QUEUE:
4231 case OFPACT_PUSH_MPLS:
4232 case OFPACT_POP_MPLS:
4233 case OFPACT_SET_MPLS_LABEL:
4234 case OFPACT_SET_MPLS_TC:
4235 case OFPACT_SET_MPLS_TTL:
4236 case OFPACT_MULTIPATH:
4239 case OFPACT_UNROLL_XLATE:
4240 case OFPACT_FIN_TIMEOUT:
4241 case OFPACT_CLEAR_ACTIONS:
4242 case OFPACT_WRITE_ACTIONS:
4245 case OFPACT_DEBUG_RECIRC:
4248 /* These may not generate PACKET INs. */
4252 case OFPACT_CONJUNCTION:
4253 /* These need not be copied for restoration. */
4256 /* Copy the action over. */
4257 ofpbuf_put(&ctx->frozen_actions, a, OFPACT_ALIGN(a->len));
4261 #define CHECK_MPLS_RECIRCULATION() \
4262 if (ctx->was_mpls) { \
4263 ctx_trigger_freeze(ctx); \
4266 #define CHECK_MPLS_RECIRCULATION_IF(COND) \
4268 CHECK_MPLS_RECIRCULATION(); \
4272 put_ct_mark(const struct flow *flow, struct flow *base_flow,
4273 struct ofpbuf *odp_actions, struct flow_wildcards *wc)
4280 odp_attr.key = flow->ct_mark;
4281 odp_attr.mask = wc->masks.ct_mark;
4283 if (odp_attr.mask && odp_attr.key != base_flow->ct_mark) {
4284 nl_msg_put_unspec(odp_actions, OVS_CT_ATTR_MARK, &odp_attr,
4290 put_ct_label(const struct flow *flow, struct flow *base_flow,
4291 struct ofpbuf *odp_actions, struct flow_wildcards *wc)
4293 if (!ovs_u128_is_zero(&wc->masks.ct_label)
4294 && !ovs_u128_equals(&flow->ct_label, &base_flow->ct_label)) {
4300 odp_ct_label = nl_msg_put_unspec_uninit(odp_actions,
4302 sizeof(*odp_ct_label));
4303 odp_ct_label->key = flow->ct_label;
4304 odp_ct_label->mask = wc->masks.ct_label;
4309 put_ct_helper(struct ofpbuf *odp_actions, struct ofpact_conntrack *ofc)
4312 if (ofc->alg == IPPORT_FTP) {
4313 nl_msg_put_string(odp_actions, OVS_CT_ATTR_HELPER, "ftp");
4315 VLOG_WARN("Cannot serialize ct_helper %d\n", ofc->alg);
4321 put_ct_nat(struct xlate_ctx *ctx)
4323 struct ofpact_nat *ofn = ctx->ct_nat_action;
4330 nat_offset = nl_msg_start_nested(ctx->odp_actions, OVS_CT_ATTR_NAT);
4331 if (ofn->flags & NX_NAT_F_SRC || ofn->flags & NX_NAT_F_DST) {
4332 nl_msg_put_flag(ctx->odp_actions, ofn->flags & NX_NAT_F_SRC
4333 ? OVS_NAT_ATTR_SRC : OVS_NAT_ATTR_DST);
4334 if (ofn->flags & NX_NAT_F_PERSISTENT) {
4335 nl_msg_put_flag(ctx->odp_actions, OVS_NAT_ATTR_PERSISTENT);
4337 if (ofn->flags & NX_NAT_F_PROTO_HASH) {
4338 nl_msg_put_flag(ctx->odp_actions, OVS_NAT_ATTR_PROTO_HASH);
4339 } else if (ofn->flags & NX_NAT_F_PROTO_RANDOM) {
4340 nl_msg_put_flag(ctx->odp_actions, OVS_NAT_ATTR_PROTO_RANDOM);
4342 if (ofn->range_af == AF_INET) {
4343 nl_msg_put_be32(ctx->odp_actions, OVS_NAT_ATTR_IP_MIN,
4344 ofn->range.addr.ipv4.min);
4345 if (ofn->range.addr.ipv4.max &&
4346 (ntohl(ofn->range.addr.ipv4.max)
4347 > ntohl(ofn->range.addr.ipv4.min))) {
4348 nl_msg_put_be32(ctx->odp_actions, OVS_NAT_ATTR_IP_MAX,
4349 ofn->range.addr.ipv4.max);
4351 } else if (ofn->range_af == AF_INET6) {
4352 nl_msg_put_unspec(ctx->odp_actions, OVS_NAT_ATTR_IP_MIN,
4353 &ofn->range.addr.ipv6.min,
4354 sizeof ofn->range.addr.ipv6.min);
4355 if (!ipv6_mask_is_any(&ofn->range.addr.ipv6.max) &&
4356 memcmp(&ofn->range.addr.ipv6.max, &ofn->range.addr.ipv6.min,
4357 sizeof ofn->range.addr.ipv6.max) > 0) {
4358 nl_msg_put_unspec(ctx->odp_actions, OVS_NAT_ATTR_IP_MAX,
4359 &ofn->range.addr.ipv6.max,
4360 sizeof ofn->range.addr.ipv6.max);
4363 if (ofn->range_af != AF_UNSPEC && ofn->range.proto.min) {
4364 nl_msg_put_u16(ctx->odp_actions, OVS_NAT_ATTR_PROTO_MIN,
4365 ofn->range.proto.min);
4366 if (ofn->range.proto.max &&
4367 ofn->range.proto.max > ofn->range.proto.min) {
4368 nl_msg_put_u16(ctx->odp_actions, OVS_NAT_ATTR_PROTO_MAX,
4369 ofn->range.proto.max);
4373 nl_msg_end_nested(ctx->odp_actions, nat_offset);
4377 compose_conntrack_action(struct xlate_ctx *ctx, struct ofpact_conntrack *ofc)
4379 ovs_u128 old_ct_label = ctx->base_flow.ct_label;
4380 uint32_t old_ct_mark = ctx->base_flow.ct_mark;
4384 /* Ensure that any prior actions are applied before composing the new
4385 * conntrack action. */
4386 xlate_commit_actions(ctx);
4388 /* Process nested actions first, to populate the key. */
4389 ctx->ct_nat_action = NULL;
4390 do_xlate_actions(ofc->actions, ofpact_ct_get_action_len(ofc), ctx);
4392 if (ofc->zone_src.field) {
4393 zone = mf_get_subfield(&ofc->zone_src, &ctx->xin->flow);
4395 zone = ofc->zone_imm;
4398 ct_offset = nl_msg_start_nested(ctx->odp_actions, OVS_ACTION_ATTR_CT);
4399 if (ofc->flags & NX_CT_F_COMMIT) {
4400 nl_msg_put_flag(ctx->odp_actions, OVS_CT_ATTR_COMMIT);
4402 nl_msg_put_u16(ctx->odp_actions, OVS_CT_ATTR_ZONE, zone);
4403 put_ct_mark(&ctx->xin->flow, &ctx->base_flow, ctx->odp_actions, ctx->wc);
4404 put_ct_label(&ctx->xin->flow, &ctx->base_flow, ctx->odp_actions, ctx->wc);
4405 put_ct_helper(ctx->odp_actions, ofc);
4407 ctx->ct_nat_action = NULL;
4408 nl_msg_end_nested(ctx->odp_actions, ct_offset);
4410 /* Restore the original ct fields in the key. These should only be exposed
4411 * after recirculation to another table. */
4412 ctx->base_flow.ct_mark = old_ct_mark;
4413 ctx->base_flow.ct_label = old_ct_label;
4415 if (ofc->recirc_table == NX_CT_RECIRC_NONE) {
4416 /* If we do not recirculate as part of this action, hide the results of
4417 * connection tracking from subsequent recirculations. */
4418 ctx->conntracked = false;
4420 /* Use ct_* fields from datapath during recirculation upcall. */
4421 ctx->conntracked = true;
4422 compose_recirculate_and_fork(ctx, ofc->recirc_table);
4427 do_xlate_actions(const struct ofpact *ofpacts, size_t ofpacts_len,
4428 struct xlate_ctx *ctx)
4430 struct flow_wildcards *wc = ctx->wc;
4431 struct flow *flow = &ctx->xin->flow;
4432 const struct ofpact *a;
4434 if (ovs_native_tunneling_is_on(ctx->xbridge->ofproto)) {
4435 tnl_neigh_snoop(flow, wc, ctx->xbridge->name);
4437 /* dl_type already in the mask, not set below. */
4439 OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
4440 struct ofpact_controller *controller;
4441 const struct ofpact_metadata *metadata;
4442 const struct ofpact_set_field *set_field;
4443 const struct mf_field *mf;
4450 /* Check if need to store the remaining actions for later
4452 if (ctx->freezing) {
4453 freeze_unroll_actions(a, ofpact_end(ofpacts, ofpacts_len),
4461 xlate_output_action(ctx, ofpact_get_OUTPUT(a)->port,
4462 ofpact_get_OUTPUT(a)->max_len, true);
4466 if (xlate_group_action(ctx, ofpact_get_GROUP(a)->group_id)) {
4467 /* Group could not be found. */
4472 case OFPACT_CONTROLLER:
4473 controller = ofpact_get_CONTROLLER(a);
4474 execute_controller_action(ctx, controller->max_len,
4476 controller->controller_id);
4479 case OFPACT_ENQUEUE:
4480 memset(&wc->masks.skb_priority, 0xff,
4481 sizeof wc->masks.skb_priority);
4482 xlate_enqueue_action(ctx, ofpact_get_ENQUEUE(a));
4485 case OFPACT_SET_VLAN_VID:
4486 wc->masks.vlan_tci |= htons(VLAN_VID_MASK | VLAN_CFI);
4487 if (flow->vlan_tci & htons(VLAN_CFI) ||
4488 ofpact_get_SET_VLAN_VID(a)->push_vlan_if_needed) {
4489 flow->vlan_tci &= ~htons(VLAN_VID_MASK);
4490 flow->vlan_tci |= (htons(ofpact_get_SET_VLAN_VID(a)->vlan_vid)
4495 case OFPACT_SET_VLAN_PCP:
4496 wc->masks.vlan_tci |= htons(VLAN_PCP_MASK | VLAN_CFI);
4497 if (flow->vlan_tci & htons(VLAN_CFI) ||
4498 ofpact_get_SET_VLAN_PCP(a)->push_vlan_if_needed) {
4499 flow->vlan_tci &= ~htons(VLAN_PCP_MASK);
4500 flow->vlan_tci |= htons((ofpact_get_SET_VLAN_PCP(a)->vlan_pcp
4501 << VLAN_PCP_SHIFT) | VLAN_CFI);
4505 case OFPACT_STRIP_VLAN:
4506 memset(&wc->masks.vlan_tci, 0xff, sizeof wc->masks.vlan_tci);
4507 flow->vlan_tci = htons(0);
4510 case OFPACT_PUSH_VLAN:
4511 /* XXX 802.1AD(QinQ) */
4512 memset(&wc->masks.vlan_tci, 0xff, sizeof wc->masks.vlan_tci);
4513 flow->vlan_tci = htons(VLAN_CFI);
4516 case OFPACT_SET_ETH_SRC:
4517 WC_MASK_FIELD(wc, dl_src);
4518 flow->dl_src = ofpact_get_SET_ETH_SRC(a)->mac;
4521 case OFPACT_SET_ETH_DST:
4522 WC_MASK_FIELD(wc, dl_dst);
4523 flow->dl_dst = ofpact_get_SET_ETH_DST(a)->mac;
4526 case OFPACT_SET_IPV4_SRC:
4527 CHECK_MPLS_RECIRCULATION();
4528 if (flow->dl_type == htons(ETH_TYPE_IP)) {
4529 memset(&wc->masks.nw_src, 0xff, sizeof wc->masks.nw_src);
4530 flow->nw_src = ofpact_get_SET_IPV4_SRC(a)->ipv4;
4534 case OFPACT_SET_IPV4_DST:
4535 CHECK_MPLS_RECIRCULATION();
4536 if (flow->dl_type == htons(ETH_TYPE_IP)) {
4537 memset(&wc->masks.nw_dst, 0xff, sizeof wc->masks.nw_dst);
4538 flow->nw_dst = ofpact_get_SET_IPV4_DST(a)->ipv4;
4542 case OFPACT_SET_IP_DSCP:
4543 CHECK_MPLS_RECIRCULATION();
4544 if (is_ip_any(flow)) {
4545 wc->masks.nw_tos |= IP_DSCP_MASK;
4546 flow->nw_tos &= ~IP_DSCP_MASK;
4547 flow->nw_tos |= ofpact_get_SET_IP_DSCP(a)->dscp;
4551 case OFPACT_SET_IP_ECN:
4552 CHECK_MPLS_RECIRCULATION();
4553 if (is_ip_any(flow)) {
4554 wc->masks.nw_tos |= IP_ECN_MASK;
4555 flow->nw_tos &= ~IP_ECN_MASK;
4556 flow->nw_tos |= ofpact_get_SET_IP_ECN(a)->ecn;
4560 case OFPACT_SET_IP_TTL:
4561 CHECK_MPLS_RECIRCULATION();
4562 if (is_ip_any(flow)) {
4563 wc->masks.nw_ttl = 0xff;
4564 flow->nw_ttl = ofpact_get_SET_IP_TTL(a)->ttl;
4568 case OFPACT_SET_L4_SRC_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_src, 0xff, sizeof wc->masks.tp_src);
4573 flow->tp_src = htons(ofpact_get_SET_L4_SRC_PORT(a)->port);
4577 case OFPACT_SET_L4_DST_PORT:
4578 CHECK_MPLS_RECIRCULATION();
4579 if (is_ip_any(flow) && !(flow->nw_frag & FLOW_NW_FRAG_LATER)) {
4580 memset(&wc->masks.nw_proto, 0xff, sizeof wc->masks.nw_proto);
4581 memset(&wc->masks.tp_dst, 0xff, sizeof wc->masks.tp_dst);
4582 flow->tp_dst = htons(ofpact_get_SET_L4_DST_PORT(a)->port);
4586 case OFPACT_RESUBMIT:
4587 /* Freezing complicates resubmit. There are two cases:
4589 * - If mpls_pop has been executed, then the flow table lookup
4590 * as part of resubmit might depend on fields that can only
4591 * be obtained via recirculation, so the resubmit itself
4592 * triggers recirculation and we need to make sure that the
4593 * resubmit is executed again after recirculation.
4594 * Therefore, in this case we trigger recirculation and let
4595 * the code following this "switch" append the resubmit to
4596 * the post-recirculation actions.
4598 * - Otherwise, some action in the flow entry found by resubmit
4599 * might trigger freezing. If that happens, then we do not
4600 * want to execute the resubmit again during thawing, so we
4601 * want to skip back to the head of the loop to avoid that,
4602 * only adding any actions that follow the resubmit to the
4605 if (ctx->was_mpls) {
4606 ctx_trigger_freeze(ctx);
4609 xlate_ofpact_resubmit(ctx, ofpact_get_RESUBMIT(a));
4612 case OFPACT_SET_TUNNEL:
4613 flow->tunnel.tun_id = htonll(ofpact_get_SET_TUNNEL(a)->tun_id);
4616 case OFPACT_SET_QUEUE:
4617 memset(&wc->masks.skb_priority, 0xff,
4618 sizeof wc->masks.skb_priority);
4619 xlate_set_queue_action(ctx, ofpact_get_SET_QUEUE(a)->queue_id);
4622 case OFPACT_POP_QUEUE:
4623 memset(&wc->masks.skb_priority, 0xff,
4624 sizeof wc->masks.skb_priority);
4625 flow->skb_priority = ctx->orig_skb_priority;
4628 case OFPACT_REG_MOVE:
4629 CHECK_MPLS_RECIRCULATION_IF(
4630 mf_is_l3_or_higher(ofpact_get_REG_MOVE(a)->dst.field) ||
4631 mf_is_l3_or_higher(ofpact_get_REG_MOVE(a)->src.field));
4632 nxm_execute_reg_move(ofpact_get_REG_MOVE(a), flow, wc);
4635 case OFPACT_SET_FIELD:
4636 CHECK_MPLS_RECIRCULATION_IF(
4637 mf_is_l3_or_higher(ofpact_get_SET_FIELD(a)->field));
4638 set_field = ofpact_get_SET_FIELD(a);
4639 mf = set_field->field;
4641 /* Set field action only ever overwrites packet's outermost
4642 * applicable header fields. Do nothing if no header exists. */
4643 if (mf->id == MFF_VLAN_VID) {
4644 wc->masks.vlan_tci |= htons(VLAN_CFI);
4645 if (!(flow->vlan_tci & htons(VLAN_CFI))) {
4648 } else if ((mf->id == MFF_MPLS_LABEL || mf->id == MFF_MPLS_TC)
4649 /* 'dl_type' is already unwildcarded. */
4650 && !eth_type_mpls(flow->dl_type)) {
4653 /* A flow may wildcard nw_frag. Do nothing if setting a transport
4654 * header field on a packet that does not have them. */
4655 mf_mask_field_and_prereqs(mf, wc);
4656 if (mf_are_prereqs_ok(mf, flow)) {
4657 mf_set_flow_value_masked(mf, &set_field->value,
4658 &set_field->mask, flow);
4662 case OFPACT_STACK_PUSH:
4663 CHECK_MPLS_RECIRCULATION_IF(
4664 mf_is_l3_or_higher(ofpact_get_STACK_PUSH(a)->subfield.field));
4665 nxm_execute_stack_push(ofpact_get_STACK_PUSH(a), flow, wc,
4669 case OFPACT_STACK_POP:
4670 CHECK_MPLS_RECIRCULATION_IF(
4671 mf_is_l3_or_higher(ofpact_get_STACK_POP(a)->subfield.field));
4672 nxm_execute_stack_pop(ofpact_get_STACK_POP(a), flow, wc,
4676 case OFPACT_PUSH_MPLS:
4677 /* Recirculate if it is an IP packet with a zero ttl. This may
4678 * indicate that the packet was previously MPLS and an MPLS pop
4679 * action converted it to IP. In this case recirculating should
4680 * reveal the IP TTL which is used as the basis for a new MPLS
4682 CHECK_MPLS_RECIRCULATION_IF(
4683 !flow_count_mpls_labels(flow, wc)
4684 && flow->nw_ttl == 0
4685 && is_ip_any(flow));
4686 compose_mpls_push_action(ctx, ofpact_get_PUSH_MPLS(a));
4689 case OFPACT_POP_MPLS:
4690 CHECK_MPLS_RECIRCULATION();
4691 compose_mpls_pop_action(ctx, ofpact_get_POP_MPLS(a)->ethertype);
4694 case OFPACT_SET_MPLS_LABEL:
4695 CHECK_MPLS_RECIRCULATION();
4696 compose_set_mpls_label_action(
4697 ctx, ofpact_get_SET_MPLS_LABEL(a)->label);
4700 case OFPACT_SET_MPLS_TC:
4701 CHECK_MPLS_RECIRCULATION();
4702 compose_set_mpls_tc_action(ctx, ofpact_get_SET_MPLS_TC(a)->tc);
4705 case OFPACT_SET_MPLS_TTL:
4706 CHECK_MPLS_RECIRCULATION();
4707 compose_set_mpls_ttl_action(ctx, ofpact_get_SET_MPLS_TTL(a)->ttl);
4710 case OFPACT_DEC_MPLS_TTL:
4711 CHECK_MPLS_RECIRCULATION();
4712 if (compose_dec_mpls_ttl_action(ctx)) {
4717 case OFPACT_DEC_TTL:
4718 CHECK_MPLS_RECIRCULATION();
4719 wc->masks.nw_ttl = 0xff;
4720 if (compose_dec_ttl(ctx, ofpact_get_DEC_TTL(a))) {
4726 /* Nothing to do. */
4729 case OFPACT_MULTIPATH:
4730 CHECK_MPLS_RECIRCULATION();
4731 multipath_execute(ofpact_get_MULTIPATH(a), flow, wc);
4735 CHECK_MPLS_RECIRCULATION();
4736 xlate_bundle_action(ctx, ofpact_get_BUNDLE(a));
4739 case OFPACT_OUTPUT_REG:
4740 xlate_output_reg_action(ctx, ofpact_get_OUTPUT_REG(a));
4744 CHECK_MPLS_RECIRCULATION();
4745 xlate_learn_action(ctx, ofpact_get_LEARN(a));
4748 case OFPACT_CONJUNCTION: {
4749 /* A flow with a "conjunction" action represents part of a special
4750 * kind of "set membership match". Such a flow should not actually
4751 * get executed, but it could via, say, a "packet-out", even though
4752 * that wouldn't be useful. Log it to help debugging. */
4753 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
4754 VLOG_INFO_RL(&rl, "executing no-op conjunction action");
4762 case OFPACT_UNROLL_XLATE: {
4763 struct ofpact_unroll_xlate *unroll = ofpact_get_UNROLL_XLATE(a);
4765 /* Restore translation context data that was stored earlier. */
4766 ctx->table_id = unroll->rule_table_id;
4767 ctx->rule_cookie = unroll->rule_cookie;
4770 case OFPACT_FIN_TIMEOUT:
4771 CHECK_MPLS_RECIRCULATION();
4772 memset(&wc->masks.nw_proto, 0xff, sizeof wc->masks.nw_proto);
4773 xlate_fin_timeout(ctx, ofpact_get_FIN_TIMEOUT(a));
4776 case OFPACT_CLEAR_ACTIONS:
4777 ofpbuf_clear(&ctx->action_set);
4778 ctx->xin->flow.actset_output = OFPP_UNSET;
4779 ctx->action_set_has_group = false;
4782 case OFPACT_WRITE_ACTIONS:
4783 xlate_write_actions(ctx, ofpact_get_WRITE_ACTIONS(a));
4786 case OFPACT_WRITE_METADATA:
4787 metadata = ofpact_get_WRITE_METADATA(a);
4788 flow->metadata &= ~metadata->mask;
4789 flow->metadata |= metadata->metadata & metadata->mask;
4793 /* Not implemented yet. */
4796 case OFPACT_GOTO_TABLE: {
4797 struct ofpact_goto_table *ogt = ofpact_get_GOTO_TABLE(a);
4799 ovs_assert(ctx->table_id < ogt->table_id);
4801 xlate_table_action(ctx, ctx->xin->flow.in_port.ofp_port,
4802 ogt->table_id, true, true);
4807 xlate_sample_action(ctx, ofpact_get_SAMPLE(a));
4811 CHECK_MPLS_RECIRCULATION();
4812 compose_conntrack_action(ctx, ofpact_get_CT(a));
4816 /* This will be processed by compose_conntrack_action(). */
4817 ctx->ct_nat_action = ofpact_get_NAT(a);
4820 case OFPACT_DEBUG_RECIRC:
4821 ctx_trigger_freeze(ctx);
4826 /* Check if need to store this and the remaining actions for later
4828 if (!ctx->error && ctx->exit && ctx_first_frozen_action(ctx)) {
4829 freeze_unroll_actions(a, ofpact_end(ofpacts, ofpacts_len), ctx);
4836 xlate_in_init(struct xlate_in *xin, struct ofproto_dpif *ofproto,
4837 const struct flow *flow, ofp_port_t in_port,
4838 struct rule_dpif *rule, uint16_t tcp_flags,
4839 const struct dp_packet *packet, struct flow_wildcards *wc,
4840 struct ofpbuf *odp_actions)
4842 xin->ofproto = ofproto;
4844 xin->flow.in_port.ofp_port = in_port;
4845 xin->flow.actset_output = OFPP_UNSET;
4846 xin->packet = packet;
4847 xin->may_learn = packet != NULL;
4850 xin->ofpacts = NULL;
4851 xin->ofpacts_len = 0;
4852 xin->tcp_flags = tcp_flags;
4853 xin->resubmit_hook = NULL;
4854 xin->report_hook = NULL;
4855 xin->resubmit_stats = NULL;
4859 xin->odp_actions = odp_actions;
4861 /* Do recirc lookup. */
4862 xin->frozen_state = NULL;
4863 if (flow->recirc_id) {
4864 const struct recirc_id_node *node
4865 = recirc_id_node_find(flow->recirc_id);
4867 xin->frozen_state = &node->state;
4873 xlate_out_uninit(struct xlate_out *xout)
4876 recirc_refs_unref(&xout->recircs);
4880 /* Translates the 'ofpacts_len' bytes of "struct ofpact"s starting at 'ofpacts'
4881 * into datapath actions, using 'ctx', and discards the datapath actions. */
4883 xlate_actions_for_side_effects(struct xlate_in *xin)
4885 struct xlate_out xout;
4886 enum xlate_error error;
4888 error = xlate_actions(xin, &xout);
4890 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
4892 VLOG_WARN_RL(&rl, "xlate_actions failed (%s)!", xlate_strerror(error));
4895 xlate_out_uninit(&xout);
4898 static struct skb_priority_to_dscp *
4899 get_skb_priority(const struct xport *xport, uint32_t skb_priority)
4901 struct skb_priority_to_dscp *pdscp;
4904 hash = hash_int(skb_priority, 0);
4905 HMAP_FOR_EACH_IN_BUCKET (pdscp, hmap_node, hash, &xport->skb_priorities) {
4906 if (pdscp->skb_priority == skb_priority) {
4914 dscp_from_skb_priority(const struct xport *xport, uint32_t skb_priority,
4917 struct skb_priority_to_dscp *pdscp = get_skb_priority(xport, skb_priority);
4918 *dscp = pdscp ? pdscp->dscp : 0;
4919 return pdscp != NULL;
4923 count_skb_priorities(const struct xport *xport)
4925 return hmap_count(&xport->skb_priorities);
4929 clear_skb_priorities(struct xport *xport)
4931 struct skb_priority_to_dscp *pdscp, *next;
4933 HMAP_FOR_EACH_SAFE (pdscp, next, hmap_node, &xport->skb_priorities) {
4934 hmap_remove(&xport->skb_priorities, &pdscp->hmap_node);
4940 actions_output_to_local_port(const struct xlate_ctx *ctx)
4942 odp_port_t local_odp_port = ofp_port_to_odp_port(ctx->xbridge, OFPP_LOCAL);
4943 const struct nlattr *a;
4946 NL_ATTR_FOR_EACH_UNSAFE (a, left, ctx->odp_actions->data,
4947 ctx->odp_actions->size) {
4948 if (nl_attr_type(a) == OVS_ACTION_ATTR_OUTPUT
4949 && nl_attr_get_odp_port(a) == local_odp_port) {
4956 #if defined(__linux__)
4957 /* Returns the maximum number of packets that the Linux kernel is willing to
4958 * queue up internally to certain kinds of software-implemented ports, or the
4959 * default (and rarely modified) value if it cannot be determined. */
4961 netdev_max_backlog(void)
4963 static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
4964 static int max_backlog = 1000; /* The normal default value. */
4966 if (ovsthread_once_start(&once)) {
4967 static const char filename[] = "/proc/sys/net/core/netdev_max_backlog";
4971 stream = fopen(filename, "r");
4973 VLOG_INFO("%s: open failed (%s)", filename, ovs_strerror(errno));
4975 if (fscanf(stream, "%d", &n) != 1) {
4976 VLOG_WARN("%s: read error", filename);
4977 } else if (n <= 100) {
4978 VLOG_WARN("%s: unexpectedly small value %d", filename, n);
4984 ovsthread_once_done(&once);
4986 VLOG_DBG("%s: using %d max_backlog", filename, max_backlog);
4992 /* Counts and returns the number of OVS_ACTION_ATTR_OUTPUT actions in
4995 count_output_actions(const struct ofpbuf *odp_actions)
4997 const struct nlattr *a;
5001 NL_ATTR_FOR_EACH_UNSAFE (a, left, odp_actions->data, odp_actions->size) {
5002 if (a->nla_type == OVS_ACTION_ATTR_OUTPUT) {
5008 #endif /* defined(__linux__) */
5010 /* Returns true if 'odp_actions' contains more output actions than the datapath
5011 * can reliably handle in one go. On Linux, this is the value of the
5012 * net.core.netdev_max_backlog sysctl, which limits the maximum number of
5013 * packets that the kernel is willing to queue up for processing while the
5014 * datapath is processing a set of actions. */
5016 too_many_output_actions(const struct ofpbuf *odp_actions OVS_UNUSED)
5019 return (odp_actions->size / NL_A_U32_SIZE > netdev_max_backlog()
5020 && count_output_actions(odp_actions) > netdev_max_backlog());
5022 /* OSes other than Linux might have similar limits, but we don't know how
5023 * to determine them.*/
5029 xlate_wc_init(struct xlate_ctx *ctx)
5031 flow_wildcards_init_catchall(ctx->wc);
5033 /* Some fields we consider to always be examined. */
5034 WC_MASK_FIELD(ctx->wc, in_port);
5035 WC_MASK_FIELD(ctx->wc, dl_type);
5036 if (is_ip_any(&ctx->xin->flow)) {
5037 WC_MASK_FIELD_MASK(ctx->wc, nw_frag, FLOW_NW_FRAG_MASK);
5040 if (ctx->xbridge->support.odp.recirc) {
5041 /* Always exactly match recirc_id when datapath supports
5043 WC_MASK_FIELD(ctx->wc, recirc_id);
5046 if (ctx->xbridge->netflow) {
5047 netflow_mask_wc(&ctx->xin->flow, ctx->wc);
5050 tnl_wc_init(&ctx->xin->flow, ctx->wc);
5054 xlate_wc_finish(struct xlate_ctx *ctx)
5056 /* Clear the metadata and register wildcard masks, because we won't
5057 * use non-header fields as part of the cache. */
5058 flow_wildcards_clear_non_packet_fields(ctx->wc);
5060 /* ICMPv4 and ICMPv6 have 8-bit "type" and "code" fields. struct flow
5061 * uses the low 8 bits of the 16-bit tp_src and tp_dst members to
5062 * represent these fields. The datapath interface, on the other hand,
5063 * represents them with just 8 bits each. This means that if the high
5064 * 8 bits of the masks for these fields somehow become set, then they
5065 * will get chopped off by a round trip through the datapath, and
5066 * revalidation will spot that as an inconsistency and delete the flow.
5067 * Avoid the problem here by making sure that only the low 8 bits of
5068 * either field can be unwildcarded for ICMP.
5070 if (is_icmpv4(&ctx->xin->flow) || is_icmpv6(&ctx->xin->flow)) {
5071 ctx->wc->masks.tp_src &= htons(UINT8_MAX);
5072 ctx->wc->masks.tp_dst &= htons(UINT8_MAX);
5074 /* VLAN_TCI CFI bit must be matched if any of the TCI is matched. */
5075 if (ctx->wc->masks.vlan_tci) {
5076 ctx->wc->masks.vlan_tci |= htons(VLAN_CFI);
5080 /* Translates the flow, actions, or rule in 'xin' into datapath actions in
5082 * The caller must take responsibility for eventually freeing 'xout', with
5083 * xlate_out_uninit().
5084 * Returns 'XLATE_OK' if translation was successful. In case of an error an
5085 * empty set of actions will be returned in 'xin->odp_actions' (if non-NULL),
5086 * so that most callers may ignore the return value and transparently install a
5087 * drop flow when the translation fails. */
5089 xlate_actions(struct xlate_in *xin, struct xlate_out *xout)
5091 *xout = (struct xlate_out) {
5093 .recircs = RECIRC_REFS_EMPTY_INITIALIZER,
5096 struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
5097 struct xbridge *xbridge = xbridge_lookup(xcfg, xin->ofproto);
5099 return XLATE_BRIDGE_NOT_FOUND;
5102 struct flow *flow = &xin->flow;
5104 union mf_subvalue stack_stub[1024 / sizeof(union mf_subvalue)];
5105 uint64_t action_set_stub[1024 / 8];
5106 uint64_t frozen_actions_stub[1024 / 8];
5107 struct flow_wildcards scratch_wc;
5108 uint64_t actions_stub[256 / 8];
5109 struct ofpbuf scratch_actions = OFPBUF_STUB_INITIALIZER(actions_stub);
5110 struct xlate_ctx ctx = {
5114 .orig_tunnel_ipv6_dst = flow_tnl_dst(&flow->tunnel),
5116 .stack = OFPBUF_STUB_INITIALIZER(stack_stub),
5118 .wc = xin->wc ? xin->wc : &scratch_wc,
5119 .odp_actions = xin->odp_actions ? xin->odp_actions : &scratch_actions,
5121 .recurse = xin->recurse,
5122 .resubmits = xin->resubmits,
5124 .in_action_set = false,
5127 .rule_cookie = OVS_BE64_MAX,
5128 .orig_skb_priority = flow->skb_priority,
5129 .sflow_n_outputs = 0,
5130 .sflow_odp_port = 0,
5131 .nf_output_iface = NF_OUT_DROP,
5137 .frozen_actions = OFPBUF_STUB_INITIALIZER(frozen_actions_stub),
5140 .conntracked = false,
5142 .ct_nat_action = NULL,
5144 .action_set_has_group = false,
5145 .action_set = OFPBUF_STUB_INITIALIZER(action_set_stub),
5148 /* 'base_flow' reflects the packet as it came in, but we need it to reflect
5149 * the packet as the datapath will treat it for output actions:
5151 * - Our datapath doesn't retain tunneling information without us
5152 * re-setting it, so clear the tunnel data.
5154 * - For VLAN splinters, a higher layer may pretend that the packet
5155 * came in on 'flow->in_port.ofp_port' with 'flow->vlan_tci'
5156 * attached, because that's how we want to treat it from an OpenFlow
5157 * perspective. But from the datapath's perspective it actually came
5158 * in on a VLAN device without any VLAN attached. So here we put the
5159 * datapath's view of the VLAN information in 'base_flow' to ensure
5160 * correct treatment.
5162 memset(&ctx.base_flow.tunnel, 0, sizeof ctx.base_flow.tunnel);
5163 if (flow->in_port.ofp_port
5164 != vsp_realdev_to_vlandev(xbridge->ofproto,
5165 flow->in_port.ofp_port,
5167 ctx.base_flow.vlan_tci = 0;
5170 ofpbuf_reserve(ctx.odp_actions, NL_A_U32_SIZE);
5172 xlate_wc_init(&ctx);
5175 COVERAGE_INC(xlate_actions);
5177 if (xin->frozen_state) {
5178 const struct frozen_state *state = xin->frozen_state;
5180 xlate_report(&ctx, "Thawing frozen state:");
5182 if (xin->ofpacts_len > 0 || ctx.rule) {
5183 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
5184 const char *conflict = xin->ofpacts_len ? "actions" : "rule";
5186 VLOG_WARN_RL(&rl, "Recirculation conflict (%s)!", conflict);
5187 xlate_report(&ctx, "- Recirculation conflict (%s)!", conflict);
5188 ctx.error = XLATE_RECIRCULATION_CONFLICT;
5192 /* Set the bridge for post-recirculation processing if needed. */
5193 if (!uuid_equals(ofproto_dpif_get_uuid(ctx.xbridge->ofproto),
5194 &state->ofproto_uuid)) {
5195 struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
5196 const struct xbridge *new_bridge
5197 = xbridge_lookup_by_uuid(xcfg, &state->ofproto_uuid);
5199 if (OVS_UNLIKELY(!new_bridge)) {
5200 /* Drop the packet if the bridge cannot be found. */
5201 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
5202 VLOG_WARN_RL(&rl, "Frozen bridge no longer exists.");
5203 xlate_report(&ctx, "- Frozen bridge no longer exists.");
5204 ctx.error = XLATE_BRIDGE_NOT_FOUND;
5207 ctx.xbridge = new_bridge;
5210 /* Set the thawed table id. Note: A table lookup is done only if there
5211 * are no frozen actions. */
5212 ctx.table_id = state->table_id;
5213 xlate_report(&ctx, "- Resuming from table %"PRIu8, ctx.table_id);
5215 if (!state->conntracked) {
5216 clear_conntrack(flow);
5219 /* Restore pipeline metadata. May change flow's in_port and other
5220 * metadata to the values that existed when freezing was triggered. */
5221 frozen_metadata_to_flow(&state->metadata, flow);
5223 /* Restore stack, if any. */
5225 ofpbuf_put(&ctx.stack, state->stack,
5226 state->n_stack * sizeof *state->stack);
5229 /* Restore mirror state. */
5230 ctx.mirrors = state->mirrors;
5232 /* Restore action set, if any. */
5233 if (state->action_set_len) {
5234 xlate_report_actions(&ctx, "- Restoring action set",
5235 state->action_set, state->action_set_len);
5237 flow->actset_output = OFPP_UNSET;
5238 xlate_write_actions__(&ctx, state->action_set,
5239 state->action_set_len);
5242 /* Restore frozen actions. If there are no actions, processing will
5243 * start with a lookup in the table set above. */
5244 xin->ofpacts = state->ofpacts;
5245 xin->ofpacts_len = state->ofpacts_len;
5246 if (state->ofpacts_len) {
5247 xlate_report_actions(&ctx, "- Restoring actions",
5248 xin->ofpacts, xin->ofpacts_len);
5250 } else if (OVS_UNLIKELY(flow->recirc_id)) {
5251 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
5253 VLOG_WARN_RL(&rl, "Recirculation context not found for ID %"PRIx32,
5255 ctx.error = XLATE_NO_RECIRCULATION_CONTEXT;
5258 /* The bridge is now known so obtain its table version. */
5259 ctx.tables_version = ofproto_dpif_get_tables_version(ctx.xbridge->ofproto);
5261 if (!xin->ofpacts && !ctx.rule) {
5262 ctx.rule = rule_dpif_lookup_from_table(
5263 ctx.xbridge->ofproto, ctx.tables_version, flow, xin->wc,
5264 ctx.xin->resubmit_stats, &ctx.table_id,
5265 flow->in_port.ofp_port, true, true);
5266 if (ctx.xin->resubmit_stats) {
5267 rule_dpif_credit_stats(ctx.rule, ctx.xin->resubmit_stats);
5269 if (ctx.xin->xcache) {
5270 struct xc_entry *entry;
5272 entry = xlate_cache_add_entry(ctx.xin->xcache, XC_RULE);
5273 entry->u.rule = ctx.rule;
5274 rule_dpif_ref(ctx.rule);
5277 if (OVS_UNLIKELY(ctx.xin->resubmit_hook)) {
5278 ctx.xin->resubmit_hook(ctx.xin, ctx.rule, 0);
5282 /* Get the proximate input port of the packet. (If xin->frozen_state,
5283 * flow->in_port is the ultimate input port of the packet.) */
5284 struct xport *in_port = get_ofp_port(xbridge,
5285 ctx.base_flow.in_port.ofp_port);
5287 /* Tunnel stats only for not-thawed packets. */
5288 if (!xin->frozen_state && in_port && in_port->is_tunnel) {
5289 if (ctx.xin->resubmit_stats) {
5290 netdev_vport_inc_rx(in_port->netdev, ctx.xin->resubmit_stats);
5292 bfd_account_rx(in_port->bfd, ctx.xin->resubmit_stats);
5295 if (ctx.xin->xcache) {
5296 struct xc_entry *entry;
5298 entry = xlate_cache_add_entry(ctx.xin->xcache, XC_NETDEV);
5299 entry->u.dev.rx = netdev_ref(in_port->netdev);
5300 entry->u.dev.bfd = bfd_ref(in_port->bfd);
5304 if (!xin->frozen_state && process_special(&ctx, in_port)) {
5305 /* process_special() did all the processing for this packet.
5307 * We do not perform special processing on thawed packets, since that
5308 * was done before they were frozen and should not be redone. */
5309 } else if (in_port && in_port->xbundle
5310 && xbundle_mirror_out(xbridge, in_port->xbundle)) {
5311 if (ctx.xin->packet != NULL) {
5312 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
5313 VLOG_WARN_RL(&rl, "bridge %s: dropping packet received on port "
5314 "%s, which is reserved exclusively for mirroring",
5315 ctx.xbridge->name, in_port->xbundle->name);
5318 /* Sampling is done on initial reception; don't redo after thawing. */
5319 unsigned int user_cookie_offset = 0;
5320 if (!xin->frozen_state) {
5321 user_cookie_offset = compose_sflow_action(&ctx);
5322 compose_ipfix_action(&ctx, ODPP_NONE);
5324 size_t sample_actions_len = ctx.odp_actions->size;
5326 if (tnl_process_ecn(flow)
5327 && (!in_port || may_receive(in_port, &ctx))) {
5328 const struct ofpact *ofpacts;
5332 ofpacts = xin->ofpacts;
5333 ofpacts_len = xin->ofpacts_len;
5334 } else if (ctx.rule) {
5335 const struct rule_actions *actions
5336 = rule_dpif_get_actions(ctx.rule);
5337 ofpacts = actions->ofpacts;
5338 ofpacts_len = actions->ofpacts_len;
5339 ctx.rule_cookie = rule_dpif_get_flow_cookie(ctx.rule);
5344 mirror_ingress_packet(&ctx);
5345 do_xlate_actions(ofpacts, ofpacts_len, &ctx);
5350 /* We've let OFPP_NORMAL and the learning action look at the
5351 * packet, so cancel all actions and freezing if forwarding is
5353 if (in_port && (!xport_stp_forward_state(in_port) ||
5354 !xport_rstp_forward_state(in_port))) {
5355 ctx.odp_actions->size = sample_actions_len;
5356 ctx_cancel_freeze(&ctx);
5357 ofpbuf_clear(&ctx.action_set);
5360 if (!ctx.freezing) {
5361 xlate_action_set(&ctx);
5364 compose_recirculate_action(&ctx);
5368 /* Output only fully processed packets. */
5370 && xbridge->has_in_band
5371 && in_band_must_output_to_local_port(flow)
5372 && !actions_output_to_local_port(&ctx)) {
5373 compose_output_action(&ctx, OFPP_LOCAL, NULL);
5376 if (user_cookie_offset) {
5377 fix_sflow_action(&ctx, user_cookie_offset);
5381 if (nl_attr_oversized(ctx.odp_actions->size)) {
5382 /* These datapath actions are too big for a Netlink attribute, so we
5383 * can't hand them to the kernel directly. dpif_execute() can execute
5384 * them one by one with help, so just mark the result as SLOW_ACTION to
5385 * prevent the flow from being installed. */
5386 COVERAGE_INC(xlate_actions_oversize);
5387 ctx.xout->slow |= SLOW_ACTION;
5388 } else if (too_many_output_actions(ctx.odp_actions)) {
5389 COVERAGE_INC(xlate_actions_too_many_output);
5390 ctx.xout->slow |= SLOW_ACTION;
5393 /* Do netflow only for packets on initial reception, that are not sent to
5394 * the controller. We consider packets sent to the controller to be part
5395 * of the control plane rather than the data plane. */
5396 if (!xin->frozen_state
5398 && !(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(&ctx.frozen_actions);
5422 ofpbuf_uninit(&scratch_actions);
5424 /* Make sure we return a "drop flow" in case of an error. */
5427 if (xin->odp_actions) {
5428 ofpbuf_clear(xin->odp_actions);
5434 /* Sends 'packet' out 'ofport'.
5435 * May modify 'packet'.
5436 * Returns 0 if successful, otherwise a positive errno value. */
5438 xlate_send_packet(const struct ofport_dpif *ofport, struct dp_packet *packet)
5440 struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
5441 struct xport *xport;
5442 struct ofpact_output output;
5445 ofpact_init(&output.ofpact, OFPACT_OUTPUT, sizeof output);
5446 /* Use OFPP_NONE as the in_port to avoid special packet processing. */
5447 flow_extract(packet, &flow);
5448 flow.in_port.ofp_port = OFPP_NONE;
5450 xport = xport_lookup(xcfg, ofport);
5454 output.port = xport->ofp_port;
5457 return ofproto_dpif_execute_actions(xport->xbridge->ofproto, &flow, NULL,
5458 &output.ofpact, sizeof output,
5462 struct xlate_cache *
5463 xlate_cache_new(void)
5465 struct xlate_cache *xcache = xmalloc(sizeof *xcache);
5467 ofpbuf_init(&xcache->entries, 512);
5471 static struct xc_entry *
5472 xlate_cache_add_entry(struct xlate_cache *xcache, enum xc_type type)
5474 struct xc_entry *entry;
5476 entry = ofpbuf_put_zeros(&xcache->entries, sizeof *entry);
5483 xlate_cache_netdev(struct xc_entry *entry, const struct dpif_flow_stats *stats)
5485 if (entry->u.dev.tx) {
5486 netdev_vport_inc_tx(entry->u.dev.tx, stats);
5488 if (entry->u.dev.rx) {
5489 netdev_vport_inc_rx(entry->u.dev.rx, stats);
5491 if (entry->u.dev.bfd) {
5492 bfd_account_rx(entry->u.dev.bfd, stats);
5497 xlate_cache_normal(struct ofproto_dpif *ofproto, struct flow *flow, int vlan)
5499 struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
5500 struct xbridge *xbridge;
5501 struct xbundle *xbundle;
5502 struct flow_wildcards wc;
5504 xbridge = xbridge_lookup(xcfg, ofproto);
5509 xbundle = lookup_input_bundle(xbridge, flow->in_port.ofp_port, false,
5515 update_learning_table(xbridge, flow, &wc, vlan, xbundle);
5518 /* Push stats and perform side effects of flow translation. */
5520 xlate_push_stats(struct xlate_cache *xcache,
5521 const struct dpif_flow_stats *stats)
5523 struct xc_entry *entry;
5524 struct ofpbuf entries = xcache->entries;
5525 struct eth_addr dmac;
5527 if (!stats->n_packets) {
5531 XC_ENTRY_FOR_EACH (entry, entries, xcache) {
5532 switch (entry->type) {
5534 rule_dpif_credit_stats(entry->u.rule, stats);
5537 bond_account(entry->u.bond.bond, entry->u.bond.flow,
5538 entry->u.bond.vid, stats->n_bytes);
5541 xlate_cache_netdev(entry, stats);
5544 netflow_flow_update(entry->u.nf.netflow, entry->u.nf.flow,
5545 entry->u.nf.iface, stats);
5548 mirror_update_stats(entry->u.mirror.mbridge,
5549 entry->u.mirror.mirrors,
5550 stats->n_packets, stats->n_bytes);
5553 ofproto_dpif_flow_mod(entry->u.learn.ofproto, entry->u.learn.fm);
5556 xlate_cache_normal(entry->u.normal.ofproto, entry->u.normal.flow,
5557 entry->u.normal.vlan);
5559 case XC_FIN_TIMEOUT:
5560 xlate_fin_timeout__(entry->u.fin.rule, stats->tcp_flags,
5561 entry->u.fin.idle, entry->u.fin.hard);
5564 group_dpif_credit_stats(entry->u.group.group, entry->u.group.bucket,
5568 /* Lookup neighbor to avoid timeout. */
5569 tnl_neigh_lookup(entry->u.tnl_neigh_cache.br_name,
5570 &entry->u.tnl_neigh_cache.d_ipv6, &dmac);
5579 xlate_dev_unref(struct xc_entry *entry)
5581 if (entry->u.dev.tx) {
5582 netdev_close(entry->u.dev.tx);
5584 if (entry->u.dev.rx) {
5585 netdev_close(entry->u.dev.rx);
5587 if (entry->u.dev.bfd) {
5588 bfd_unref(entry->u.dev.bfd);
5593 xlate_cache_clear_netflow(struct netflow *netflow, struct flow *flow)
5595 netflow_flow_clear(netflow, flow);
5596 netflow_unref(netflow);
5601 xlate_cache_clear(struct xlate_cache *xcache)
5603 struct xc_entry *entry;
5604 struct ofpbuf entries;
5610 XC_ENTRY_FOR_EACH (entry, entries, xcache) {
5611 switch (entry->type) {
5613 rule_dpif_unref(entry->u.rule);
5616 free(entry->u.bond.flow);
5617 bond_unref(entry->u.bond.bond);
5620 xlate_dev_unref(entry);
5623 xlate_cache_clear_netflow(entry->u.nf.netflow, entry->u.nf.flow);
5626 mbridge_unref(entry->u.mirror.mbridge);
5629 free(entry->u.learn.fm);
5630 ofpbuf_delete(entry->u.learn.ofpacts);
5633 free(entry->u.normal.flow);
5635 case XC_FIN_TIMEOUT:
5636 /* 'u.fin.rule' is always already held as a XC_RULE, which
5637 * has already released it's reference above. */
5640 group_dpif_unref(entry->u.group.group);
5649 ofpbuf_clear(&xcache->entries);
5653 xlate_cache_delete(struct xlate_cache *xcache)
5655 xlate_cache_clear(xcache);
5656 ofpbuf_uninit(&xcache->entries);