1 /* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014 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"
25 #include "byte-order.h"
30 #include "dynamic-string.h"
35 #include "mac-learning.h"
36 #include "meta-flow.h"
37 #include "multipath.h"
38 #include "netdev-vport.h"
41 #include "odp-execute.h"
42 #include "ofp-actions.h"
43 #include "ofproto/ofproto-dpif-ipfix.h"
44 #include "ofproto/ofproto-dpif-mirror.h"
45 #include "ofproto/ofproto-dpif-monitor.h"
46 #include "ofproto/ofproto-dpif-sflow.h"
47 #include "ofproto/ofproto-dpif.h"
48 #include "ofproto/ofproto-provider.h"
52 COVERAGE_DEFINE(xlate_actions);
53 COVERAGE_DEFINE(xlate_actions_oversize);
54 COVERAGE_DEFINE(xlate_actions_mpls_overflow);
56 VLOG_DEFINE_THIS_MODULE(ofproto_dpif_xlate);
58 /* Maximum depth of flow table recursion (due to resubmit actions) in a
59 * flow translation. */
60 #define MAX_RESUBMIT_RECURSION 64
61 #define MAX_INTERNAL_RESUBMITS 1 /* Max resbmits allowed using rules in
64 /* Maximum number of resubmit actions in a flow translation, whether they are
65 * recursive or not. */
66 #define MAX_RESUBMITS (MAX_RESUBMIT_RECURSION * MAX_RESUBMIT_RECURSION)
68 struct ovs_rwlock xlate_rwlock = OVS_RWLOCK_INITIALIZER;
71 struct hmap_node hmap_node; /* Node in global 'xbridges' map. */
72 struct ofproto_dpif *ofproto; /* Key in global 'xbridges' map. */
74 struct list xbundles; /* Owned xbundles. */
75 struct hmap xports; /* Indexed by ofp_port. */
77 char *name; /* Name used in log messages. */
78 struct dpif *dpif; /* Datapath interface. */
79 struct mac_learning *ml; /* Mac learning handle. */
80 struct mbridge *mbridge; /* Mirroring. */
81 struct dpif_sflow *sflow; /* SFlow handle, or null. */
82 struct dpif_ipfix *ipfix; /* Ipfix handle, or null. */
83 struct netflow *netflow; /* Netflow handle, or null. */
84 struct stp *stp; /* STP or null if disabled. */
86 /* Special rules installed by ofproto-dpif. */
87 struct rule_dpif *miss_rule;
88 struct rule_dpif *no_packet_in_rule;
90 enum ofp_config_flags frag; /* Fragmentation handling. */
91 bool has_in_band; /* Bridge has in band control? */
92 bool forward_bpdu; /* Bridge forwards STP BPDUs? */
94 /* True if the datapath supports recirculation. */
97 /* True if the datapath supports variable-length
98 * OVS_USERSPACE_ATTR_USERDATA in OVS_ACTION_ATTR_USERSPACE actions.
99 * False if the datapath supports only 8-byte (or shorter) userdata. */
100 bool variable_length_userdata;
102 /* Number of MPLS label stack entries that the datapath supports
104 size_t max_mpls_depth;
108 struct hmap_node hmap_node; /* In global 'xbundles' map. */
109 struct ofbundle *ofbundle; /* Key in global 'xbundles' map. */
111 struct list list_node; /* In parent 'xbridges' list. */
112 struct xbridge *xbridge; /* Parent xbridge. */
114 struct list xports; /* Contains "struct xport"s. */
116 char *name; /* Name used in log messages. */
117 struct bond *bond; /* Nonnull iff more than one port. */
118 struct lacp *lacp; /* LACP handle or null. */
120 enum port_vlan_mode vlan_mode; /* VLAN mode. */
121 int vlan; /* -1=trunk port, else a 12-bit VLAN ID. */
122 unsigned long *trunks; /* Bitmap of trunked VLANs, if 'vlan' == -1.
123 * NULL if all VLANs are trunked. */
124 bool use_priority_tags; /* Use 802.1p tag for frames in VLAN 0? */
125 bool floodable; /* No port has OFPUTIL_PC_NO_FLOOD set? */
129 struct hmap_node hmap_node; /* Node in global 'xports' map. */
130 struct ofport_dpif *ofport; /* Key in global 'xports map. */
132 struct hmap_node ofp_node; /* Node in parent xbridge 'xports' map. */
133 ofp_port_t ofp_port; /* Key in parent xbridge 'xports' map. */
135 odp_port_t odp_port; /* Datapath port number or ODPP_NONE. */
137 struct list bundle_node; /* In parent xbundle (if it exists). */
138 struct xbundle *xbundle; /* Parent xbundle or null. */
140 struct netdev *netdev; /* 'ofport''s netdev. */
142 struct xbridge *xbridge; /* Parent bridge. */
143 struct xport *peer; /* Patch port peer or null. */
145 enum ofputil_port_config config; /* OpenFlow port configuration. */
146 enum ofputil_port_state state; /* OpenFlow port state. */
147 int stp_port_no; /* STP port number or -1 if not in use. */
149 struct hmap skb_priorities; /* Map of 'skb_priority_to_dscp's. */
151 bool may_enable; /* May be enabled in bonds. */
152 bool is_tunnel; /* Is a tunnel port. */
154 struct cfm *cfm; /* CFM handle or null. */
155 struct bfd *bfd; /* BFD handle or null. */
159 struct xlate_in *xin;
160 struct xlate_out *xout;
162 const struct xbridge *xbridge;
164 /* Flow at the last commit. */
165 struct flow base_flow;
167 /* Tunnel IP destination address as received. This is stored separately
168 * as the base_flow.tunnel is cleared on init to reflect the datapath
169 * behavior. Used to make sure not to send tunneled output to ourselves,
170 * which might lead to an infinite loop. This could happen easily
171 * if a tunnel is marked as 'ip_remote=flow', and the flow does not
172 * actually set the tun_dst field. */
173 ovs_be32 orig_tunnel_ip_dst;
175 /* Stack for the push and pop actions. Each stack element is of type
176 * "union mf_subvalue". */
177 union mf_subvalue init_stack[1024 / sizeof(union mf_subvalue)];
180 /* The rule that we are currently translating, or NULL. */
181 struct rule_dpif *rule;
183 /* Resubmit statistics, via xlate_table_action(). */
184 int recurse; /* Current resubmit nesting depth. */
185 int resubmits; /* Total number of resubmits. */
186 bool in_group; /* Currently translating ofgroup, if true. */
188 uint32_t orig_skb_priority; /* Priority when packet arrived. */
189 uint8_t table_id; /* OpenFlow table ID where flow was found. */
190 uint32_t sflow_n_outputs; /* Number of output ports. */
191 odp_port_t sflow_odp_port; /* Output port for composing sFlow action. */
192 uint16_t user_cookie_offset;/* Used for user_action_cookie fixup. */
193 bool exit; /* No further actions should be processed. */
195 bool use_recirc; /* Should generate recirc? */
196 struct xlate_recirc recirc; /* Information used for generating
197 * recirculation actions */
199 /* OpenFlow 1.1+ action set.
201 * 'action_set' accumulates "struct ofpact"s added by OFPACT_WRITE_ACTIONS.
202 * When translation is otherwise complete, ofpacts_execute_action_set()
203 * converts it to a set of "struct ofpact"s that can be translated into
204 * datapath actions. */
205 struct ofpbuf action_set; /* Action set. */
206 uint64_t action_set_stub[1024 / 8];
209 /* A controller may use OFPP_NONE as the ingress port to indicate that
210 * it did not arrive on a "real" port. 'ofpp_none_bundle' exists for
211 * when an input bundle is needed for validation (e.g., mirroring or
212 * OFPP_NORMAL processing). It is not connected to an 'ofproto' or have
213 * any 'port' structs, so care must be taken when dealing with it. */
214 static struct xbundle ofpp_none_bundle = {
216 .vlan_mode = PORT_VLAN_TRUNK
219 /* Node in 'xport''s 'skb_priorities' map. Used to maintain a map from
220 * 'priority' (the datapath's term for QoS queue) to the dscp bits which all
221 * traffic egressing the 'ofport' with that priority should be marked with. */
222 struct skb_priority_to_dscp {
223 struct hmap_node hmap_node; /* Node in 'ofport_dpif''s 'skb_priorities'. */
224 uint32_t skb_priority; /* Priority of this queue (see struct flow). */
226 uint8_t dscp; /* DSCP bits to mark outgoing traffic with. */
241 /* xlate_cache entries hold enough information to perform the side effects of
242 * xlate_actions() for a rule, without needing to perform rule translation
243 * from scratch. The primary usage of these is to submit statistics to objects
244 * that a flow relates to, although they may be used for other effects as well
245 * (for instance, refreshing hard timeouts for learned flows). */
249 struct rule_dpif *rule;
256 struct netflow *netflow;
261 struct mbridge *mbridge;
262 mirror_mask_t mirrors;
270 struct ofproto_dpif *ofproto;
271 struct rule_dpif *rule;
274 struct ofproto_dpif *ofproto;
279 struct rule_dpif *rule;
284 struct group_dpif *group;
285 struct ofputil_bucket *bucket;
290 #define XC_ENTRY_FOR_EACH(entry, entries, xcache) \
291 entries = xcache->entries; \
292 for (entry = ofpbuf_try_pull(&entries, sizeof *entry); \
294 entry = ofpbuf_try_pull(&entries, sizeof *entry))
297 struct ofpbuf entries;
300 static struct hmap xbridges = HMAP_INITIALIZER(&xbridges);
301 static struct hmap xbundles = HMAP_INITIALIZER(&xbundles);
302 static struct hmap xports = HMAP_INITIALIZER(&xports);
304 static bool may_receive(const struct xport *, struct xlate_ctx *);
305 static void do_xlate_actions(const struct ofpact *, size_t ofpacts_len,
307 static void xlate_actions__(struct xlate_in *, struct xlate_out *)
308 OVS_REQ_RDLOCK(xlate_rwlock);
309 static void xlate_normal(struct xlate_ctx *);
310 static void xlate_report(struct xlate_ctx *, const char *);
311 static void xlate_table_action(struct xlate_ctx *, ofp_port_t in_port,
312 uint8_t table_id, bool may_packet_in,
313 bool honor_table_miss);
314 static bool input_vid_is_valid(uint16_t vid, struct xbundle *, bool warn);
315 static uint16_t input_vid_to_vlan(const struct xbundle *, uint16_t vid);
316 static void output_normal(struct xlate_ctx *, const struct xbundle *,
318 static void compose_output_action(struct xlate_ctx *, ofp_port_t ofp_port);
320 static struct xbridge *xbridge_lookup(const struct ofproto_dpif *);
321 static struct xbundle *xbundle_lookup(const struct ofbundle *);
322 static struct xport *xport_lookup(const struct ofport_dpif *);
323 static struct xport *get_ofp_port(const struct xbridge *, ofp_port_t ofp_port);
324 static struct skb_priority_to_dscp *get_skb_priority(const struct xport *,
325 uint32_t skb_priority);
326 static void clear_skb_priorities(struct xport *);
327 static bool dscp_from_skb_priority(const struct xport *, uint32_t skb_priority,
330 static struct xc_entry *xlate_cache_add_entry(struct xlate_cache *xc,
334 xlate_ofproto_set(struct ofproto_dpif *ofproto, const char *name,
335 struct dpif *dpif, struct rule_dpif *miss_rule,
336 struct rule_dpif *no_packet_in_rule,
337 const struct mac_learning *ml, struct stp *stp,
338 const struct mbridge *mbridge,
339 const struct dpif_sflow *sflow,
340 const struct dpif_ipfix *ipfix,
341 const struct netflow *netflow, enum ofp_config_flags frag,
342 bool forward_bpdu, bool has_in_band,
344 bool variable_length_userdata,
345 size_t max_mpls_depth)
347 struct xbridge *xbridge = xbridge_lookup(ofproto);
350 xbridge = xzalloc(sizeof *xbridge);
351 xbridge->ofproto = ofproto;
353 hmap_insert(&xbridges, &xbridge->hmap_node, hash_pointer(ofproto, 0));
354 hmap_init(&xbridge->xports);
355 list_init(&xbridge->xbundles);
358 if (xbridge->ml != ml) {
359 mac_learning_unref(xbridge->ml);
360 xbridge->ml = mac_learning_ref(ml);
363 if (xbridge->mbridge != mbridge) {
364 mbridge_unref(xbridge->mbridge);
365 xbridge->mbridge = mbridge_ref(mbridge);
368 if (xbridge->sflow != sflow) {
369 dpif_sflow_unref(xbridge->sflow);
370 xbridge->sflow = dpif_sflow_ref(sflow);
373 if (xbridge->ipfix != ipfix) {
374 dpif_ipfix_unref(xbridge->ipfix);
375 xbridge->ipfix = dpif_ipfix_ref(ipfix);
378 if (xbridge->stp != stp) {
379 stp_unref(xbridge->stp);
380 xbridge->stp = stp_ref(stp);
383 if (xbridge->netflow != netflow) {
384 netflow_unref(xbridge->netflow);
385 xbridge->netflow = netflow_ref(netflow);
389 xbridge->name = xstrdup(name);
391 xbridge->dpif = dpif;
392 xbridge->forward_bpdu = forward_bpdu;
393 xbridge->has_in_band = has_in_band;
394 xbridge->frag = frag;
395 xbridge->miss_rule = miss_rule;
396 xbridge->no_packet_in_rule = no_packet_in_rule;
397 xbridge->enable_recirc = enable_recirc;
398 xbridge->variable_length_userdata = variable_length_userdata;
399 xbridge->max_mpls_depth = max_mpls_depth;
403 xlate_remove_ofproto(struct ofproto_dpif *ofproto)
405 struct xbridge *xbridge = xbridge_lookup(ofproto);
406 struct xbundle *xbundle, *next_xbundle;
407 struct xport *xport, *next_xport;
413 HMAP_FOR_EACH_SAFE (xport, next_xport, ofp_node, &xbridge->xports) {
414 xlate_ofport_remove(xport->ofport);
417 LIST_FOR_EACH_SAFE (xbundle, next_xbundle, list_node, &xbridge->xbundles) {
418 xlate_bundle_remove(xbundle->ofbundle);
421 hmap_remove(&xbridges, &xbridge->hmap_node);
422 mac_learning_unref(xbridge->ml);
423 mbridge_unref(xbridge->mbridge);
424 dpif_sflow_unref(xbridge->sflow);
425 dpif_ipfix_unref(xbridge->ipfix);
426 stp_unref(xbridge->stp);
427 hmap_destroy(&xbridge->xports);
433 xlate_bundle_set(struct ofproto_dpif *ofproto, struct ofbundle *ofbundle,
434 const char *name, enum port_vlan_mode vlan_mode, int vlan,
435 unsigned long *trunks, bool use_priority_tags,
436 const struct bond *bond, const struct lacp *lacp,
439 struct xbundle *xbundle = xbundle_lookup(ofbundle);
442 xbundle = xzalloc(sizeof *xbundle);
443 xbundle->ofbundle = ofbundle;
444 xbundle->xbridge = xbridge_lookup(ofproto);
446 hmap_insert(&xbundles, &xbundle->hmap_node, hash_pointer(ofbundle, 0));
447 list_insert(&xbundle->xbridge->xbundles, &xbundle->list_node);
448 list_init(&xbundle->xports);
451 ovs_assert(xbundle->xbridge);
454 xbundle->name = xstrdup(name);
456 xbundle->vlan_mode = vlan_mode;
457 xbundle->vlan = vlan;
458 xbundle->trunks = trunks;
459 xbundle->use_priority_tags = use_priority_tags;
460 xbundle->floodable = floodable;
462 if (xbundle->bond != bond) {
463 bond_unref(xbundle->bond);
464 xbundle->bond = bond_ref(bond);
467 if (xbundle->lacp != lacp) {
468 lacp_unref(xbundle->lacp);
469 xbundle->lacp = lacp_ref(lacp);
474 xlate_bundle_remove(struct ofbundle *ofbundle)
476 struct xbundle *xbundle = xbundle_lookup(ofbundle);
477 struct xport *xport, *next;
483 LIST_FOR_EACH_SAFE (xport, next, bundle_node, &xbundle->xports) {
484 list_remove(&xport->bundle_node);
485 xport->xbundle = NULL;
488 hmap_remove(&xbundles, &xbundle->hmap_node);
489 list_remove(&xbundle->list_node);
490 bond_unref(xbundle->bond);
491 lacp_unref(xbundle->lacp);
497 xlate_ofport_set(struct ofproto_dpif *ofproto, struct ofbundle *ofbundle,
498 struct ofport_dpif *ofport, ofp_port_t ofp_port,
499 odp_port_t odp_port, const struct netdev *netdev,
500 const struct cfm *cfm, const struct bfd *bfd,
501 struct ofport_dpif *peer, int stp_port_no,
502 const struct ofproto_port_queue *qdscp_list, size_t n_qdscp,
503 enum ofputil_port_config config,
504 enum ofputil_port_state state, bool is_tunnel,
507 struct xport *xport = xport_lookup(ofport);
511 xport = xzalloc(sizeof *xport);
512 xport->ofport = ofport;
513 xport->xbridge = xbridge_lookup(ofproto);
514 xport->ofp_port = ofp_port;
516 hmap_init(&xport->skb_priorities);
517 hmap_insert(&xports, &xport->hmap_node, hash_pointer(ofport, 0));
518 hmap_insert(&xport->xbridge->xports, &xport->ofp_node,
519 hash_ofp_port(xport->ofp_port));
522 ovs_assert(xport->ofp_port == ofp_port);
524 xport->config = config;
525 xport->state = state;
526 xport->stp_port_no = stp_port_no;
527 xport->is_tunnel = is_tunnel;
528 xport->may_enable = may_enable;
529 xport->odp_port = odp_port;
531 if (xport->netdev != netdev) {
532 netdev_close(xport->netdev);
533 xport->netdev = netdev_ref(netdev);
536 if (xport->cfm != cfm) {
537 cfm_unref(xport->cfm);
538 xport->cfm = cfm_ref(cfm);
541 if (xport->bfd != bfd) {
542 bfd_unref(xport->bfd);
543 xport->bfd = bfd_ref(bfd);
547 xport->peer->peer = NULL;
549 xport->peer = xport_lookup(peer);
551 xport->peer->peer = xport;
554 if (xport->xbundle) {
555 list_remove(&xport->bundle_node);
557 xport->xbundle = xbundle_lookup(ofbundle);
558 if (xport->xbundle) {
559 list_insert(&xport->xbundle->xports, &xport->bundle_node);
562 clear_skb_priorities(xport);
563 for (i = 0; i < n_qdscp; i++) {
564 struct skb_priority_to_dscp *pdscp;
565 uint32_t skb_priority;
567 if (dpif_queue_to_priority(xport->xbridge->dpif, qdscp_list[i].queue,
572 pdscp = xmalloc(sizeof *pdscp);
573 pdscp->skb_priority = skb_priority;
574 pdscp->dscp = (qdscp_list[i].dscp << 2) & IP_DSCP_MASK;
575 hmap_insert(&xport->skb_priorities, &pdscp->hmap_node,
576 hash_int(pdscp->skb_priority, 0));
581 xlate_ofport_remove(struct ofport_dpif *ofport)
583 struct xport *xport = xport_lookup(ofport);
590 xport->peer->peer = NULL;
594 if (xport->xbundle) {
595 list_remove(&xport->bundle_node);
598 clear_skb_priorities(xport);
599 hmap_destroy(&xport->skb_priorities);
601 hmap_remove(&xports, &xport->hmap_node);
602 hmap_remove(&xport->xbridge->xports, &xport->ofp_node);
604 netdev_close(xport->netdev);
605 cfm_unref(xport->cfm);
606 bfd_unref(xport->bfd);
610 /* Given a datpath, packet, and flow metadata ('backer', 'packet', and 'key'
611 * respectively), populates 'flow' with the result of odp_flow_key_to_flow().
612 * Optionally populates 'ofproto' with the ofproto_dpif, 'odp_in_port' with
613 * the datapath in_port, that 'packet' ingressed, and 'ipfix', 'sflow', and
614 * 'netflow' with the appropriate handles for those protocols if they're
615 * enabled. Caller is responsible for unrefing them.
617 * If 'ofproto' is nonnull, requires 'flow''s in_port to exist. Otherwise sets
618 * 'flow''s in_port to OFPP_NONE.
620 * This function does post-processing on data returned from
621 * odp_flow_key_to_flow() to help make VLAN splinters transparent to the rest
622 * of the upcall processing logic. In particular, if the extracted in_port is
623 * a VLAN splinter port, it replaces flow->in_port by the "real" port, sets
624 * flow->vlan_tci correctly for the VLAN of the VLAN splinter port, and pushes
625 * a VLAN header onto 'packet' (if it is nonnull).
627 * Similarly, this function also includes some logic to help with tunnels. It
628 * may modify 'flow' as necessary to make the tunneling implementation
629 * transparent to the upcall processing logic.
631 * Returns 0 if successful, ENODEV if the parsed flow has no associated ofport,
632 * or some other positive errno if there are other problems. */
634 xlate_receive(const struct dpif_backer *backer, struct ofpbuf *packet,
635 const struct nlattr *key, size_t key_len, struct flow *flow,
636 struct ofproto_dpif **ofproto, struct dpif_ipfix **ipfix,
637 struct dpif_sflow **sflow, struct netflow **netflow,
638 odp_port_t *odp_in_port)
640 const struct xport *xport;
643 ovs_rwlock_rdlock(&xlate_rwlock);
644 if (odp_flow_key_to_flow(key, key_len, flow) == ODP_FIT_ERROR) {
650 *odp_in_port = flow->in_port.odp_port;
653 xport = xport_lookup(tnl_port_should_receive(flow)
654 ? tnl_port_receive(flow)
655 : odp_port_to_ofport(backer, flow->in_port.odp_port));
657 flow->in_port.ofp_port = xport ? xport->ofp_port : OFPP_NONE;
662 if (vsp_adjust_flow(xport->xbridge->ofproto, flow)) {
664 /* Make the packet resemble the flow, so that it gets sent to
665 * an OpenFlow controller properly, so that it looks correct
666 * for sFlow, and so that flow_extract() will get the correct
667 * vlan_tci if it is called on 'packet'. */
668 eth_push_vlan(packet, htons(ETH_TYPE_VLAN), flow->vlan_tci);
674 *ofproto = xport->xbridge->ofproto;
678 *ipfix = dpif_ipfix_ref(xport->xbridge->ipfix);
682 *sflow = dpif_sflow_ref(xport->xbridge->sflow);
686 *netflow = netflow_ref(xport->xbridge->netflow);
690 ovs_rwlock_unlock(&xlate_rwlock);
694 static struct xbridge *
695 xbridge_lookup(const struct ofproto_dpif *ofproto)
697 struct xbridge *xbridge;
703 HMAP_FOR_EACH_IN_BUCKET (xbridge, hmap_node, hash_pointer(ofproto, 0),
705 if (xbridge->ofproto == ofproto) {
712 static struct xbundle *
713 xbundle_lookup(const struct ofbundle *ofbundle)
715 struct xbundle *xbundle;
721 HMAP_FOR_EACH_IN_BUCKET (xbundle, hmap_node, hash_pointer(ofbundle, 0),
723 if (xbundle->ofbundle == ofbundle) {
730 static struct xport *
731 xport_lookup(const struct ofport_dpif *ofport)
739 HMAP_FOR_EACH_IN_BUCKET (xport, hmap_node, hash_pointer(ofport, 0),
741 if (xport->ofport == ofport) {
748 static struct stp_port *
749 xport_get_stp_port(const struct xport *xport)
751 return xport->xbridge->stp && xport->stp_port_no != -1
752 ? stp_get_port(xport->xbridge->stp, xport->stp_port_no)
757 xport_stp_learn_state(const struct xport *xport)
759 struct stp_port *sp = xport_get_stp_port(xport);
760 return stp_learn_in_state(sp ? stp_port_get_state(sp) : STP_DISABLED);
764 xport_stp_forward_state(const struct xport *xport)
766 struct stp_port *sp = xport_get_stp_port(xport);
767 return stp_forward_in_state(sp ? stp_port_get_state(sp) : STP_DISABLED);
771 xport_stp_listen_state(const struct xport *xport)
773 struct stp_port *sp = xport_get_stp_port(xport);
774 return stp_listen_in_state(sp ? stp_port_get_state(sp) : STP_DISABLED);
777 /* Returns true if STP should process 'flow'. Sets fields in 'wc' that
778 * were used to make the determination.*/
780 stp_should_process_flow(const struct flow *flow, struct flow_wildcards *wc)
782 /* is_stp() also checks dl_type, but dl_type is always set in 'wc'. */
783 memset(&wc->masks.dl_dst, 0xff, sizeof wc->masks.dl_dst);
788 stp_process_packet(const struct xport *xport, const struct ofpbuf *packet)
790 struct stp_port *sp = xport_get_stp_port(xport);
791 struct ofpbuf payload = *packet;
792 struct eth_header *eth = ofpbuf_data(&payload);
794 /* Sink packets on ports that have STP disabled when the bridge has
796 if (!sp || stp_port_get_state(sp) == STP_DISABLED) {
800 /* Trim off padding on payload. */
801 if (ofpbuf_size(&payload) > ntohs(eth->eth_type) + ETH_HEADER_LEN) {
802 ofpbuf_set_size(&payload, ntohs(eth->eth_type) + ETH_HEADER_LEN);
805 if (ofpbuf_try_pull(&payload, ETH_HEADER_LEN + LLC_HEADER_LEN)) {
806 stp_received_bpdu(sp, ofpbuf_data(&payload), ofpbuf_size(&payload));
810 static struct xport *
811 get_ofp_port(const struct xbridge *xbridge, ofp_port_t ofp_port)
815 HMAP_FOR_EACH_IN_BUCKET (xport, ofp_node, hash_ofp_port(ofp_port),
817 if (xport->ofp_port == ofp_port) {
825 ofp_port_to_odp_port(const struct xbridge *xbridge, ofp_port_t ofp_port)
827 const struct xport *xport = get_ofp_port(xbridge, ofp_port);
828 return xport ? xport->odp_port : ODPP_NONE;
832 odp_port_is_alive(const struct xlate_ctx *ctx, ofp_port_t ofp_port)
836 xport = get_ofp_port(ctx->xbridge, ofp_port);
837 if (!xport || xport->config & OFPUTIL_PC_PORT_DOWN ||
838 xport->state & OFPUTIL_PS_LINK_DOWN) {
845 static struct ofputil_bucket *
846 group_first_live_bucket(const struct xlate_ctx *, const struct group_dpif *,
850 group_is_alive(const struct xlate_ctx *ctx, uint32_t group_id, int depth)
852 struct group_dpif *group;
854 if (group_dpif_lookup(ctx->xbridge->ofproto, group_id, &group)) {
855 struct ofputil_bucket *bucket;
857 bucket = group_first_live_bucket(ctx, group, depth);
858 group_dpif_unref(group);
859 return bucket == NULL;
865 #define MAX_LIVENESS_RECURSION 128 /* Arbitrary limit */
868 bucket_is_alive(const struct xlate_ctx *ctx,
869 struct ofputil_bucket *bucket, int depth)
871 if (depth >= MAX_LIVENESS_RECURSION) {
872 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
874 VLOG_WARN_RL(&rl, "bucket chaining exceeded %d links",
875 MAX_LIVENESS_RECURSION);
879 return !ofputil_bucket_has_liveness(bucket) ||
880 (bucket->watch_port != OFPP_ANY &&
881 odp_port_is_alive(ctx, bucket->watch_port)) ||
882 (bucket->watch_group != OFPG_ANY &&
883 group_is_alive(ctx, bucket->watch_group, depth + 1));
886 static struct ofputil_bucket *
887 group_first_live_bucket(const struct xlate_ctx *ctx,
888 const struct group_dpif *group, int depth)
890 struct ofputil_bucket *bucket;
891 const struct list *buckets;
893 group_dpif_get_buckets(group, &buckets);
894 LIST_FOR_EACH (bucket, list_node, buckets) {
895 if (bucket_is_alive(ctx, bucket, depth)) {
903 static struct ofputil_bucket *
904 group_best_live_bucket(const struct xlate_ctx *ctx,
905 const struct group_dpif *group,
908 struct ofputil_bucket *best_bucket = NULL;
909 uint32_t best_score = 0;
912 struct ofputil_bucket *bucket;
913 const struct list *buckets;
915 group_dpif_get_buckets(group, &buckets);
916 LIST_FOR_EACH (bucket, list_node, buckets) {
917 if (bucket_is_alive(ctx, bucket, 0)) {
918 uint32_t score = (hash_int(i, basis) & 0xffff) * bucket->weight;
919 if (score >= best_score) {
920 best_bucket = bucket;
931 xbundle_trunks_vlan(const struct xbundle *bundle, uint16_t vlan)
933 return (bundle->vlan_mode != PORT_VLAN_ACCESS
934 && (!bundle->trunks || bitmap_is_set(bundle->trunks, vlan)));
938 xbundle_includes_vlan(const struct xbundle *xbundle, uint16_t vlan)
940 return vlan == xbundle->vlan || xbundle_trunks_vlan(xbundle, vlan);
944 xbundle_mirror_out(const struct xbridge *xbridge, struct xbundle *xbundle)
946 return xbundle != &ofpp_none_bundle
947 ? mirror_bundle_out(xbridge->mbridge, xbundle->ofbundle)
952 xbundle_mirror_src(const struct xbridge *xbridge, struct xbundle *xbundle)
954 return xbundle != &ofpp_none_bundle
955 ? mirror_bundle_src(xbridge->mbridge, xbundle->ofbundle)
960 xbundle_mirror_dst(const struct xbridge *xbridge, struct xbundle *xbundle)
962 return xbundle != &ofpp_none_bundle
963 ? mirror_bundle_dst(xbridge->mbridge, xbundle->ofbundle)
967 static struct xbundle *
968 lookup_input_bundle(const struct xbridge *xbridge, ofp_port_t in_port,
969 bool warn, struct xport **in_xportp)
973 /* Find the port and bundle for the received packet. */
974 xport = get_ofp_port(xbridge, in_port);
978 if (xport && xport->xbundle) {
979 return xport->xbundle;
982 /* Special-case OFPP_NONE (OF1.0) and OFPP_CONTROLLER (OF1.1+),
983 * which a controller may use as the ingress port for traffic that
985 if (in_port == OFPP_CONTROLLER || in_port == OFPP_NONE) {
986 return &ofpp_none_bundle;
989 /* Odd. A few possible reasons here:
991 * - We deleted a port but there are still a few packets queued up
994 * - Someone externally added a port (e.g. "ovs-dpctl add-if") that
995 * we don't know about.
997 * - The ofproto client didn't configure the port as part of a bundle.
998 * This is particularly likely to happen if a packet was received on the
999 * port after it was created, but before the client had a chance to
1000 * configure its bundle.
1003 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
1005 VLOG_WARN_RL(&rl, "bridge %s: received packet on unknown "
1006 "port %"PRIu16, xbridge->name, in_port);
1012 add_mirror_actions(struct xlate_ctx *ctx, const struct flow *orig_flow)
1014 const struct xbridge *xbridge = ctx->xbridge;
1015 mirror_mask_t mirrors;
1016 struct xbundle *in_xbundle;
1020 mirrors = ctx->xout->mirrors;
1021 ctx->xout->mirrors = 0;
1023 in_xbundle = lookup_input_bundle(xbridge, orig_flow->in_port.ofp_port,
1024 ctx->xin->packet != NULL, NULL);
1028 mirrors |= xbundle_mirror_src(xbridge, in_xbundle);
1030 /* Drop frames on bundles reserved for mirroring. */
1031 if (xbundle_mirror_out(xbridge, in_xbundle)) {
1032 if (ctx->xin->packet != NULL) {
1033 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
1034 VLOG_WARN_RL(&rl, "bridge %s: dropping packet received on port "
1035 "%s, which is reserved exclusively for mirroring",
1036 ctx->xbridge->name, in_xbundle->name);
1038 ofpbuf_clear(&ctx->xout->odp_actions);
1043 vid = vlan_tci_to_vid(orig_flow->vlan_tci);
1044 if (!input_vid_is_valid(vid, in_xbundle, ctx->xin->packet != NULL)) {
1047 vlan = input_vid_to_vlan(in_xbundle, vid);
1053 /* Restore the original packet before adding the mirror actions. */
1054 ctx->xin->flow = *orig_flow;
1057 mirror_mask_t dup_mirrors;
1058 struct ofbundle *out;
1059 unsigned long *vlans;
1064 has_mirror = mirror_get(xbridge->mbridge, raw_ctz(mirrors),
1065 &vlans, &dup_mirrors, &out, &out_vlan);
1066 ovs_assert(has_mirror);
1069 ctx->xout->wc.masks.vlan_tci |= htons(VLAN_CFI | VLAN_VID_MASK);
1071 vlan_mirrored = !vlans || bitmap_is_set(vlans, vlan);
1074 if (!vlan_mirrored) {
1075 mirrors = zero_rightmost_1bit(mirrors);
1079 mirrors &= ~dup_mirrors;
1080 ctx->xout->mirrors |= dup_mirrors;
1082 struct xbundle *out_xbundle = xbundle_lookup(out);
1084 output_normal(ctx, out_xbundle, vlan);
1086 } else if (vlan != out_vlan
1087 && !eth_addr_is_reserved(orig_flow->dl_dst)) {
1088 struct xbundle *xbundle;
1090 LIST_FOR_EACH (xbundle, list_node, &xbridge->xbundles) {
1091 if (xbundle_includes_vlan(xbundle, out_vlan)
1092 && !xbundle_mirror_out(xbridge, xbundle)) {
1093 output_normal(ctx, xbundle, out_vlan);
1100 /* Given 'vid', the VID obtained from the 802.1Q header that was received as
1101 * part of a packet (specify 0 if there was no 802.1Q header), and 'in_xbundle',
1102 * the bundle on which the packet was received, returns the VLAN to which the
1105 * Both 'vid' and the return value are in the range 0...4095. */
1107 input_vid_to_vlan(const struct xbundle *in_xbundle, uint16_t vid)
1109 switch (in_xbundle->vlan_mode) {
1110 case PORT_VLAN_ACCESS:
1111 return in_xbundle->vlan;
1114 case PORT_VLAN_TRUNK:
1117 case PORT_VLAN_NATIVE_UNTAGGED:
1118 case PORT_VLAN_NATIVE_TAGGED:
1119 return vid ? vid : in_xbundle->vlan;
1126 /* Checks whether a packet with the given 'vid' may ingress on 'in_xbundle'.
1127 * If so, returns true. Otherwise, returns false and, if 'warn' is true, logs
1130 * 'vid' should be the VID obtained from the 802.1Q header that was received as
1131 * part of a packet (specify 0 if there was no 802.1Q header), in the range
1134 input_vid_is_valid(uint16_t vid, struct xbundle *in_xbundle, bool warn)
1136 /* Allow any VID on the OFPP_NONE port. */
1137 if (in_xbundle == &ofpp_none_bundle) {
1141 switch (in_xbundle->vlan_mode) {
1142 case PORT_VLAN_ACCESS:
1145 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
1146 VLOG_WARN_RL(&rl, "dropping VLAN %"PRIu16" tagged "
1147 "packet received on port %s configured as VLAN "
1148 "%"PRIu16" access port", vid, in_xbundle->name,
1155 case PORT_VLAN_NATIVE_UNTAGGED:
1156 case PORT_VLAN_NATIVE_TAGGED:
1158 /* Port must always carry its native VLAN. */
1162 case PORT_VLAN_TRUNK:
1163 if (!xbundle_includes_vlan(in_xbundle, vid)) {
1165 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
1166 VLOG_WARN_RL(&rl, "dropping VLAN %"PRIu16" packet "
1167 "received on port %s not configured for trunking "
1168 "VLAN %"PRIu16, vid, in_xbundle->name, vid);
1180 /* Given 'vlan', the VLAN that a packet belongs to, and
1181 * 'out_xbundle', a bundle on which the packet is to be output, returns the VID
1182 * that should be included in the 802.1Q header. (If the return value is 0,
1183 * then the 802.1Q header should only be included in the packet if there is a
1186 * Both 'vlan' and the return value are in the range 0...4095. */
1188 output_vlan_to_vid(const struct xbundle *out_xbundle, uint16_t vlan)
1190 switch (out_xbundle->vlan_mode) {
1191 case PORT_VLAN_ACCESS:
1194 case PORT_VLAN_TRUNK:
1195 case PORT_VLAN_NATIVE_TAGGED:
1198 case PORT_VLAN_NATIVE_UNTAGGED:
1199 return vlan == out_xbundle->vlan ? 0 : vlan;
1207 output_normal(struct xlate_ctx *ctx, const struct xbundle *out_xbundle,
1210 ovs_be16 *flow_tci = &ctx->xin->flow.vlan_tci;
1212 ovs_be16 tci, old_tci;
1213 struct xport *xport;
1215 vid = output_vlan_to_vid(out_xbundle, vlan);
1216 if (list_is_empty(&out_xbundle->xports)) {
1217 /* Partially configured bundle with no slaves. Drop the packet. */
1219 } else if (!out_xbundle->bond) {
1220 ctx->use_recirc = false;
1221 xport = CONTAINER_OF(list_front(&out_xbundle->xports), struct xport,
1224 struct ofport_dpif *ofport;
1225 struct xlate_recirc *xr = &ctx->recirc;
1226 struct flow_wildcards *wc = &ctx->xout->wc;
1228 if (ctx->xbridge->enable_recirc) {
1229 ctx->use_recirc = bond_may_recirc(
1230 out_xbundle->bond, &xr->recirc_id, &xr->hash_basis);
1232 if (ctx->use_recirc) {
1233 /* Only TCP mode uses recirculation. */
1234 xr->hash_alg = OVS_HASH_ALG_L4;
1235 bond_update_post_recirc_rules(out_xbundle->bond, false);
1237 /* Recirculation does not require unmasking hash fields. */
1242 ofport = bond_choose_output_slave(out_xbundle->bond,
1243 &ctx->xin->flow, wc, vid);
1244 xport = xport_lookup(ofport);
1247 /* No slaves enabled, so drop packet. */
1251 /* If ctx->xout->use_recirc is set, the main thread will handle stats
1252 * accounting for this bond. */
1253 if (!ctx->use_recirc) {
1254 if (ctx->xin->resubmit_stats) {
1255 bond_account(out_xbundle->bond, &ctx->xin->flow, vid,
1256 ctx->xin->resubmit_stats->n_bytes);
1258 if (ctx->xin->xcache) {
1259 struct xc_entry *entry;
1262 flow = &ctx->xin->flow;
1263 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_BOND);
1264 entry->u.bond.bond = bond_ref(out_xbundle->bond);
1265 entry->u.bond.flow = xmemdup(flow, sizeof *flow);
1266 entry->u.bond.vid = vid;
1271 old_tci = *flow_tci;
1273 if (tci || out_xbundle->use_priority_tags) {
1274 tci |= *flow_tci & htons(VLAN_PCP_MASK);
1276 tci |= htons(VLAN_CFI);
1281 compose_output_action(ctx, xport->ofp_port);
1282 *flow_tci = old_tci;
1285 /* A VM broadcasts a gratuitous ARP to indicate that it has resumed after
1286 * migration. Older Citrix-patched Linux DomU used gratuitous ARP replies to
1287 * indicate this; newer upstream kernels use gratuitous ARP requests. */
1289 is_gratuitous_arp(const struct flow *flow, struct flow_wildcards *wc)
1291 if (flow->dl_type != htons(ETH_TYPE_ARP)) {
1295 memset(&wc->masks.dl_dst, 0xff, sizeof wc->masks.dl_dst);
1296 if (!eth_addr_is_broadcast(flow->dl_dst)) {
1300 memset(&wc->masks.nw_proto, 0xff, sizeof wc->masks.nw_proto);
1301 if (flow->nw_proto == ARP_OP_REPLY) {
1303 } else if (flow->nw_proto == ARP_OP_REQUEST) {
1304 memset(&wc->masks.nw_src, 0xff, sizeof wc->masks.nw_src);
1305 memset(&wc->masks.nw_dst, 0xff, sizeof wc->masks.nw_dst);
1307 return flow->nw_src == flow->nw_dst;
1313 /* Determines whether packets in 'flow' within 'xbridge' should be forwarded or
1314 * dropped. Returns true if they may be forwarded, false if they should be
1317 * 'in_port' must be the xport that corresponds to flow->in_port.
1318 * 'in_port' must be part of a bundle (e.g. in_port->bundle must be nonnull).
1320 * 'vlan' must be the VLAN that corresponds to flow->vlan_tci on 'in_port', as
1321 * returned by input_vid_to_vlan(). It must be a valid VLAN for 'in_port', as
1322 * checked by input_vid_is_valid().
1324 * May also add tags to '*tags', although the current implementation only does
1325 * so in one special case.
1328 is_admissible(struct xlate_ctx *ctx, struct xport *in_port,
1331 struct xbundle *in_xbundle = in_port->xbundle;
1332 const struct xbridge *xbridge = ctx->xbridge;
1333 struct flow *flow = &ctx->xin->flow;
1335 /* Drop frames for reserved multicast addresses
1336 * only if forward_bpdu option is absent. */
1337 if (!xbridge->forward_bpdu && eth_addr_is_reserved(flow->dl_dst)) {
1338 xlate_report(ctx, "packet has reserved destination MAC, dropping");
1342 if (in_xbundle->bond) {
1343 struct mac_entry *mac;
1345 switch (bond_check_admissibility(in_xbundle->bond, in_port->ofport,
1351 xlate_report(ctx, "bonding refused admissibility, dropping");
1354 case BV_DROP_IF_MOVED:
1355 ovs_rwlock_rdlock(&xbridge->ml->rwlock);
1356 mac = mac_learning_lookup(xbridge->ml, flow->dl_src, vlan);
1357 if (mac && mac->port.p != in_xbundle->ofbundle &&
1358 (!is_gratuitous_arp(flow, &ctx->xout->wc)
1359 || mac_entry_is_grat_arp_locked(mac))) {
1360 ovs_rwlock_unlock(&xbridge->ml->rwlock);
1361 xlate_report(ctx, "SLB bond thinks this packet looped back, "
1365 ovs_rwlock_unlock(&xbridge->ml->rwlock);
1373 /* Checks whether a MAC learning update is necessary for MAC learning table
1374 * 'ml' given that a packet matching 'flow' was received on 'in_xbundle' in
1377 * Most packets processed through the MAC learning table do not actually
1378 * change it in any way. This function requires only a read lock on the MAC
1379 * learning table, so it is much cheaper in this common case.
1381 * Keep the code here synchronized with that in update_learning_table__()
1384 is_mac_learning_update_needed(const struct mac_learning *ml,
1385 const struct flow *flow,
1386 struct flow_wildcards *wc,
1387 int vlan, struct xbundle *in_xbundle)
1388 OVS_REQ_RDLOCK(ml->rwlock)
1390 struct mac_entry *mac;
1392 if (!mac_learning_may_learn(ml, flow->dl_src, vlan)) {
1396 mac = mac_learning_lookup(ml, flow->dl_src, vlan);
1397 if (!mac || mac_entry_age(ml, mac)) {
1401 if (is_gratuitous_arp(flow, wc)) {
1402 /* We don't want to learn from gratuitous ARP packets that are
1403 * reflected back over bond slaves so we lock the learning table. */
1404 if (!in_xbundle->bond) {
1406 } else if (mac_entry_is_grat_arp_locked(mac)) {
1411 return mac->port.p != in_xbundle->ofbundle;
1415 /* Updates MAC learning table 'ml' given that a packet matching 'flow' was
1416 * received on 'in_xbundle' in 'vlan'.
1418 * This code repeats all the checks in is_mac_learning_update_needed() because
1419 * the lock was released between there and here and thus the MAC learning state
1420 * could have changed.
1422 * Keep the code here synchronized with that in is_mac_learning_update_needed()
1425 update_learning_table__(const struct xbridge *xbridge,
1426 const struct flow *flow, struct flow_wildcards *wc,
1427 int vlan, struct xbundle *in_xbundle)
1428 OVS_REQ_WRLOCK(xbridge->ml->rwlock)
1430 struct mac_entry *mac;
1432 if (!mac_learning_may_learn(xbridge->ml, flow->dl_src, vlan)) {
1436 mac = mac_learning_insert(xbridge->ml, flow->dl_src, vlan);
1437 if (is_gratuitous_arp(flow, wc)) {
1438 /* We don't want to learn from gratuitous ARP packets that are
1439 * reflected back over bond slaves so we lock the learning table. */
1440 if (!in_xbundle->bond) {
1441 mac_entry_set_grat_arp_lock(mac);
1442 } else if (mac_entry_is_grat_arp_locked(mac)) {
1447 if (mac->port.p != in_xbundle->ofbundle) {
1448 /* The log messages here could actually be useful in debugging,
1449 * so keep the rate limit relatively high. */
1450 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(30, 300);
1452 VLOG_DBG_RL(&rl, "bridge %s: learned that "ETH_ADDR_FMT" is "
1453 "on port %s in VLAN %d",
1454 xbridge->name, ETH_ADDR_ARGS(flow->dl_src),
1455 in_xbundle->name, vlan);
1457 mac->port.p = in_xbundle->ofbundle;
1458 mac_learning_changed(xbridge->ml);
1463 update_learning_table(const struct xbridge *xbridge,
1464 const struct flow *flow, struct flow_wildcards *wc,
1465 int vlan, struct xbundle *in_xbundle)
1469 /* Don't learn the OFPP_NONE port. */
1470 if (in_xbundle == &ofpp_none_bundle) {
1474 /* First try the common case: no change to MAC learning table. */
1475 ovs_rwlock_rdlock(&xbridge->ml->rwlock);
1476 need_update = is_mac_learning_update_needed(xbridge->ml, flow, wc, vlan,
1478 ovs_rwlock_unlock(&xbridge->ml->rwlock);
1481 /* Slow path: MAC learning table might need an update. */
1482 ovs_rwlock_wrlock(&xbridge->ml->rwlock);
1483 update_learning_table__(xbridge, flow, wc, vlan, in_xbundle);
1484 ovs_rwlock_unlock(&xbridge->ml->rwlock);
1489 xlate_normal_flood(struct xlate_ctx *ctx, struct xbundle *in_xbundle,
1492 struct xbundle *xbundle;
1494 LIST_FOR_EACH (xbundle, list_node, &ctx->xbridge->xbundles) {
1495 if (xbundle != in_xbundle
1496 && xbundle_includes_vlan(xbundle, vlan)
1497 && xbundle->floodable
1498 && !xbundle_mirror_out(ctx->xbridge, xbundle)) {
1499 output_normal(ctx, xbundle, vlan);
1502 ctx->xout->nf_output_iface = NF_OUT_FLOOD;
1506 xlate_normal(struct xlate_ctx *ctx)
1508 struct flow_wildcards *wc = &ctx->xout->wc;
1509 struct flow *flow = &ctx->xin->flow;
1510 struct xbundle *in_xbundle;
1511 struct xport *in_port;
1512 struct mac_entry *mac;
1517 ctx->xout->has_normal = true;
1519 memset(&wc->masks.dl_src, 0xff, sizeof wc->masks.dl_src);
1520 memset(&wc->masks.dl_dst, 0xff, sizeof wc->masks.dl_dst);
1521 wc->masks.vlan_tci |= htons(VLAN_VID_MASK | VLAN_CFI);
1523 in_xbundle = lookup_input_bundle(ctx->xbridge, flow->in_port.ofp_port,
1524 ctx->xin->packet != NULL, &in_port);
1526 xlate_report(ctx, "no input bundle, dropping");
1530 /* Drop malformed frames. */
1531 if (flow->dl_type == htons(ETH_TYPE_VLAN) &&
1532 !(flow->vlan_tci & htons(VLAN_CFI))) {
1533 if (ctx->xin->packet != NULL) {
1534 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
1535 VLOG_WARN_RL(&rl, "bridge %s: dropping packet with partial "
1536 "VLAN tag received on port %s",
1537 ctx->xbridge->name, in_xbundle->name);
1539 xlate_report(ctx, "partial VLAN tag, dropping");
1543 /* Drop frames on bundles reserved for mirroring. */
1544 if (xbundle_mirror_out(ctx->xbridge, in_xbundle)) {
1545 if (ctx->xin->packet != NULL) {
1546 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
1547 VLOG_WARN_RL(&rl, "bridge %s: dropping packet received on port "
1548 "%s, which is reserved exclusively for mirroring",
1549 ctx->xbridge->name, in_xbundle->name);
1551 xlate_report(ctx, "input port is mirror output port, dropping");
1556 vid = vlan_tci_to_vid(flow->vlan_tci);
1557 if (!input_vid_is_valid(vid, in_xbundle, ctx->xin->packet != NULL)) {
1558 xlate_report(ctx, "disallowed VLAN VID for this input port, dropping");
1561 vlan = input_vid_to_vlan(in_xbundle, vid);
1563 /* Check other admissibility requirements. */
1564 if (in_port && !is_admissible(ctx, in_port, vlan)) {
1568 /* Learn source MAC. */
1569 if (ctx->xin->may_learn) {
1570 update_learning_table(ctx->xbridge, flow, wc, vlan, in_xbundle);
1572 if (ctx->xin->xcache) {
1573 struct xc_entry *entry;
1575 /* Save enough info to update mac learning table later. */
1576 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_NORMAL);
1577 entry->u.normal.ofproto = ctx->xbridge->ofproto;
1578 entry->u.normal.flow = xmemdup(flow, sizeof *flow);
1579 entry->u.normal.vlan = vlan;
1582 /* Determine output bundle. */
1583 ovs_rwlock_rdlock(&ctx->xbridge->ml->rwlock);
1584 mac = mac_learning_lookup(ctx->xbridge->ml, flow->dl_dst, vlan);
1585 mac_port = mac ? mac->port.p : NULL;
1586 ovs_rwlock_unlock(&ctx->xbridge->ml->rwlock);
1589 struct xbundle *mac_xbundle = xbundle_lookup(mac_port);
1590 if (mac_xbundle && mac_xbundle != in_xbundle) {
1591 xlate_report(ctx, "forwarding to learned port");
1592 output_normal(ctx, mac_xbundle, vlan);
1593 } else if (!mac_xbundle) {
1594 xlate_report(ctx, "learned port is unknown, dropping");
1596 xlate_report(ctx, "learned port is input port, dropping");
1599 xlate_report(ctx, "no learned MAC for destination, flooding");
1600 xlate_normal_flood(ctx, in_xbundle, vlan);
1604 /* Compose SAMPLE action for sFlow or IPFIX. The given probability is
1605 * the number of packets out of UINT32_MAX to sample. The given
1606 * cookie is passed back in the callback for each sampled packet.
1609 compose_sample_action(const struct xbridge *xbridge,
1610 struct ofpbuf *odp_actions,
1611 const struct flow *flow,
1612 const uint32_t probability,
1613 const union user_action_cookie *cookie,
1614 const size_t cookie_size)
1616 size_t sample_offset, actions_offset;
1617 odp_port_t odp_port;
1621 sample_offset = nl_msg_start_nested(odp_actions, OVS_ACTION_ATTR_SAMPLE);
1623 nl_msg_put_u32(odp_actions, OVS_SAMPLE_ATTR_PROBABILITY, probability);
1625 actions_offset = nl_msg_start_nested(odp_actions, OVS_SAMPLE_ATTR_ACTIONS);
1627 odp_port = ofp_port_to_odp_port(xbridge, flow->in_port.ofp_port);
1628 pid = dpif_port_get_pid(xbridge->dpif, odp_port,
1629 flow_hash_5tuple(flow, 0));
1630 cookie_offset = odp_put_userspace_action(pid, cookie, cookie_size,
1633 nl_msg_end_nested(odp_actions, actions_offset);
1634 nl_msg_end_nested(odp_actions, sample_offset);
1635 return cookie_offset;
1639 compose_sflow_cookie(const struct xbridge *xbridge, ovs_be16 vlan_tci,
1640 odp_port_t odp_port, unsigned int n_outputs,
1641 union user_action_cookie *cookie)
1645 cookie->type = USER_ACTION_COOKIE_SFLOW;
1646 cookie->sflow.vlan_tci = vlan_tci;
1648 /* See http://www.sflow.org/sflow_version_5.txt (search for "Input/output
1649 * port information") for the interpretation of cookie->output. */
1650 switch (n_outputs) {
1652 /* 0x40000000 | 256 means "packet dropped for unknown reason". */
1653 cookie->sflow.output = 0x40000000 | 256;
1657 ifindex = dpif_sflow_odp_port_to_ifindex(xbridge->sflow, odp_port);
1659 cookie->sflow.output = ifindex;
1664 /* 0x80000000 means "multiple output ports. */
1665 cookie->sflow.output = 0x80000000 | n_outputs;
1670 /* Compose SAMPLE action for sFlow bridge sampling. */
1672 compose_sflow_action(const struct xbridge *xbridge,
1673 struct ofpbuf *odp_actions,
1674 const struct flow *flow,
1675 odp_port_t odp_port)
1677 uint32_t probability;
1678 union user_action_cookie cookie;
1680 if (!xbridge->sflow || flow->in_port.ofp_port == OFPP_NONE) {
1684 probability = dpif_sflow_get_probability(xbridge->sflow);
1685 compose_sflow_cookie(xbridge, htons(0), odp_port,
1686 odp_port == ODPP_NONE ? 0 : 1, &cookie);
1688 return compose_sample_action(xbridge, odp_actions, flow, probability,
1689 &cookie, sizeof cookie.sflow);
1693 compose_flow_sample_cookie(uint16_t probability, uint32_t collector_set_id,
1694 uint32_t obs_domain_id, uint32_t obs_point_id,
1695 union user_action_cookie *cookie)
1697 cookie->type = USER_ACTION_COOKIE_FLOW_SAMPLE;
1698 cookie->flow_sample.probability = probability;
1699 cookie->flow_sample.collector_set_id = collector_set_id;
1700 cookie->flow_sample.obs_domain_id = obs_domain_id;
1701 cookie->flow_sample.obs_point_id = obs_point_id;
1705 compose_ipfix_cookie(union user_action_cookie *cookie)
1707 cookie->type = USER_ACTION_COOKIE_IPFIX;
1710 /* Compose SAMPLE action for IPFIX bridge sampling. */
1712 compose_ipfix_action(const struct xbridge *xbridge,
1713 struct ofpbuf *odp_actions,
1714 const struct flow *flow)
1716 uint32_t probability;
1717 union user_action_cookie cookie;
1719 if (!xbridge->ipfix || flow->in_port.ofp_port == OFPP_NONE) {
1723 probability = dpif_ipfix_get_bridge_exporter_probability(xbridge->ipfix);
1724 compose_ipfix_cookie(&cookie);
1726 compose_sample_action(xbridge, odp_actions, flow, probability,
1727 &cookie, sizeof cookie.ipfix);
1730 /* SAMPLE action for sFlow must be first action in any given list of
1731 * actions. At this point we do not have all information required to
1732 * build it. So try to build sample action as complete as possible. */
1734 add_sflow_action(struct xlate_ctx *ctx)
1736 ctx->user_cookie_offset = compose_sflow_action(ctx->xbridge,
1737 &ctx->xout->odp_actions,
1738 &ctx->xin->flow, ODPP_NONE);
1739 ctx->sflow_odp_port = 0;
1740 ctx->sflow_n_outputs = 0;
1743 /* SAMPLE action for IPFIX must be 1st or 2nd action in any given list
1744 * of actions, eventually after the SAMPLE action for sFlow. */
1746 add_ipfix_action(struct xlate_ctx *ctx)
1748 compose_ipfix_action(ctx->xbridge, &ctx->xout->odp_actions,
1752 /* Fix SAMPLE action according to data collected while composing ODP actions.
1753 * We need to fix SAMPLE actions OVS_SAMPLE_ATTR_ACTIONS attribute, i.e. nested
1754 * USERSPACE action's user-cookie which is required for sflow. */
1756 fix_sflow_action(struct xlate_ctx *ctx)
1758 const struct flow *base = &ctx->base_flow;
1759 union user_action_cookie *cookie;
1761 if (!ctx->user_cookie_offset) {
1765 cookie = ofpbuf_at(&ctx->xout->odp_actions, ctx->user_cookie_offset,
1766 sizeof cookie->sflow);
1767 ovs_assert(cookie->type == USER_ACTION_COOKIE_SFLOW);
1769 compose_sflow_cookie(ctx->xbridge, base->vlan_tci,
1770 ctx->sflow_odp_port, ctx->sflow_n_outputs, cookie);
1773 static enum slow_path_reason
1774 process_special(struct xlate_ctx *ctx, const struct flow *flow,
1775 const struct xport *xport, const struct ofpbuf *packet)
1777 struct flow_wildcards *wc = &ctx->xout->wc;
1778 const struct xbridge *xbridge = ctx->xbridge;
1782 } else if (xport->cfm && cfm_should_process_flow(xport->cfm, flow, wc)) {
1784 cfm_process_heartbeat(xport->cfm, packet);
1787 } else if (xport->bfd && bfd_should_process_flow(xport->bfd, flow, wc)) {
1789 bfd_process_packet(xport->bfd, flow, packet);
1790 /* If POLL received, immediately sends FINAL back. */
1791 if (bfd_should_send_packet(xport->bfd)) {
1792 ofproto_dpif_monitor_port_send_soon(xport->ofport);
1796 } else if (xport->xbundle && xport->xbundle->lacp
1797 && flow->dl_type == htons(ETH_TYPE_LACP)) {
1799 lacp_process_packet(xport->xbundle->lacp, xport->ofport, packet);
1802 } else if (xbridge->stp && stp_should_process_flow(flow, wc)) {
1804 stp_process_packet(xport, packet);
1813 compose_output_action__(struct xlate_ctx *ctx, ofp_port_t ofp_port,
1816 const struct xport *xport = get_ofp_port(ctx->xbridge, ofp_port);
1817 struct flow_wildcards *wc = &ctx->xout->wc;
1818 struct flow *flow = &ctx->xin->flow;
1819 ovs_be16 flow_vlan_tci;
1820 uint32_t flow_pkt_mark;
1821 uint8_t flow_nw_tos;
1822 odp_port_t out_port, odp_port;
1825 /* If 'struct flow' gets additional metadata, we'll need to zero it out
1826 * before traversing a patch port. */
1827 BUILD_ASSERT_DECL(FLOW_WC_SEQ == 26);
1830 xlate_report(ctx, "Nonexistent output port");
1832 } else if (xport->config & OFPUTIL_PC_NO_FWD) {
1833 xlate_report(ctx, "OFPPC_NO_FWD set, skipping output");
1835 } else if (check_stp) {
1836 if (is_stp(&ctx->base_flow)) {
1837 if (!xport_stp_listen_state(xport)) {
1838 xlate_report(ctx, "STP not in listening state, "
1839 "skipping bpdu output");
1842 } else if (!xport_stp_forward_state(xport)) {
1843 xlate_report(ctx, "STP not in forwarding state, "
1849 if (mbridge_has_mirrors(ctx->xbridge->mbridge) && xport->xbundle) {
1850 ctx->xout->mirrors |= xbundle_mirror_dst(xport->xbundle->xbridge,
1855 const struct xport *peer = xport->peer;
1856 struct flow old_flow = ctx->xin->flow;
1857 enum slow_path_reason special;
1859 ctx->xbridge = peer->xbridge;
1860 flow->in_port.ofp_port = peer->ofp_port;
1861 flow->metadata = htonll(0);
1862 memset(&flow->tunnel, 0, sizeof flow->tunnel);
1863 memset(flow->regs, 0, sizeof flow->regs);
1865 special = process_special(ctx, &ctx->xin->flow, peer,
1868 ctx->xout->slow |= special;
1869 } else if (may_receive(peer, ctx)) {
1870 if (xport_stp_forward_state(peer)) {
1871 xlate_table_action(ctx, flow->in_port.ofp_port, 0, true, true);
1873 /* Forwarding is disabled by STP. Let OFPP_NORMAL and the
1874 * learning action look at the packet, then drop it. */
1875 struct flow old_base_flow = ctx->base_flow;
1876 size_t old_size = ofpbuf_size(&ctx->xout->odp_actions);
1877 mirror_mask_t old_mirrors = ctx->xout->mirrors;
1878 xlate_table_action(ctx, flow->in_port.ofp_port, 0, true, true);
1879 ctx->xout->mirrors = old_mirrors;
1880 ctx->base_flow = old_base_flow;
1881 ofpbuf_set_size(&ctx->xout->odp_actions, old_size);
1885 ctx->xin->flow = old_flow;
1886 ctx->xbridge = xport->xbridge;
1888 if (ctx->xin->resubmit_stats) {
1889 netdev_vport_inc_tx(xport->netdev, ctx->xin->resubmit_stats);
1890 netdev_vport_inc_rx(peer->netdev, ctx->xin->resubmit_stats);
1892 bfd_account_rx(peer->bfd, ctx->xin->resubmit_stats);
1895 if (ctx->xin->xcache) {
1896 struct xc_entry *entry;
1898 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_NETDEV);
1899 entry->u.dev.tx = netdev_ref(xport->netdev);
1900 entry->u.dev.rx = netdev_ref(peer->netdev);
1901 entry->u.dev.bfd = bfd_ref(peer->bfd);
1907 flow_vlan_tci = flow->vlan_tci;
1908 flow_pkt_mark = flow->pkt_mark;
1909 flow_nw_tos = flow->nw_tos;
1911 if (dscp_from_skb_priority(xport, flow->skb_priority, &dscp)) {
1912 wc->masks.nw_tos |= IP_DSCP_MASK;
1913 flow->nw_tos &= ~IP_DSCP_MASK;
1914 flow->nw_tos |= dscp;
1917 if (xport->is_tunnel) {
1918 /* Save tunnel metadata so that changes made due to
1919 * the Logical (tunnel) Port are not visible for any further
1920 * matches, while explicit set actions on tunnel metadata are.
1922 struct flow_tnl flow_tnl = flow->tunnel;
1923 odp_port = tnl_port_send(xport->ofport, flow, &ctx->xout->wc);
1924 if (odp_port == ODPP_NONE) {
1925 xlate_report(ctx, "Tunneling decided against output");
1926 goto out; /* restore flow_nw_tos */
1928 if (flow->tunnel.ip_dst == ctx->orig_tunnel_ip_dst) {
1929 xlate_report(ctx, "Not tunneling to our own address");
1930 goto out; /* restore flow_nw_tos */
1932 if (ctx->xin->resubmit_stats) {
1933 netdev_vport_inc_tx(xport->netdev, ctx->xin->resubmit_stats);
1935 if (ctx->xin->xcache) {
1936 struct xc_entry *entry;
1938 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_NETDEV);
1939 entry->u.dev.tx = netdev_ref(xport->netdev);
1941 out_port = odp_port;
1942 commit_odp_tunnel_action(flow, &ctx->base_flow,
1943 &ctx->xout->odp_actions);
1944 flow->tunnel = flow_tnl; /* Restore tunnel metadata */
1946 odp_port = xport->odp_port;
1947 out_port = odp_port;
1948 if (ofproto_has_vlan_splinters(ctx->xbridge->ofproto)) {
1949 ofp_port_t vlandev_port;
1951 wc->masks.vlan_tci |= htons(VLAN_VID_MASK | VLAN_CFI);
1952 vlandev_port = vsp_realdev_to_vlandev(ctx->xbridge->ofproto,
1953 ofp_port, flow->vlan_tci);
1954 if (vlandev_port != ofp_port) {
1955 out_port = ofp_port_to_odp_port(ctx->xbridge, vlandev_port);
1956 flow->vlan_tci = htons(0);
1961 if (out_port != ODPP_NONE) {
1962 ctx->xout->slow |= commit_odp_actions(flow, &ctx->base_flow,
1963 &ctx->xout->odp_actions,
1966 if (ctx->use_recirc) {
1967 struct ovs_action_hash *act_hash;
1968 struct xlate_recirc *xr = &ctx->recirc;
1971 act_hash = nl_msg_put_unspec_uninit(&ctx->xout->odp_actions,
1972 OVS_ACTION_ATTR_HASH,
1974 act_hash->hash_alg = xr->hash_alg;
1975 act_hash->hash_basis = xr->hash_basis;
1977 /* Recirc action. */
1978 nl_msg_put_u32(&ctx->xout->odp_actions, OVS_ACTION_ATTR_RECIRC,
1981 nl_msg_put_odp_port(&ctx->xout->odp_actions, OVS_ACTION_ATTR_OUTPUT,
1985 ctx->sflow_odp_port = odp_port;
1986 ctx->sflow_n_outputs++;
1987 ctx->xout->nf_output_iface = ofp_port;
1992 flow->vlan_tci = flow_vlan_tci;
1993 flow->pkt_mark = flow_pkt_mark;
1994 flow->nw_tos = flow_nw_tos;
1998 compose_output_action(struct xlate_ctx *ctx, ofp_port_t ofp_port)
2000 compose_output_action__(ctx, ofp_port, true);
2004 xlate_recursively(struct xlate_ctx *ctx, struct rule_dpif *rule)
2006 struct rule_dpif *old_rule = ctx->rule;
2007 const struct rule_actions *actions;
2009 if (ctx->xin->resubmit_stats) {
2010 rule_dpif_credit_stats(rule, ctx->xin->resubmit_stats);
2016 actions = rule_dpif_get_actions(rule);
2017 do_xlate_actions(actions->ofpacts, actions->ofpacts_len, ctx);
2018 ctx->rule = old_rule;
2023 xlate_resubmit_resource_check(struct xlate_ctx *ctx)
2025 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
2027 if (ctx->recurse >= MAX_RESUBMIT_RECURSION + MAX_INTERNAL_RESUBMITS) {
2028 VLOG_ERR_RL(&rl, "resubmit actions recursed over %d times",
2029 MAX_RESUBMIT_RECURSION);
2030 } else if (ctx->resubmits >= MAX_RESUBMITS + MAX_INTERNAL_RESUBMITS) {
2031 VLOG_ERR_RL(&rl, "over %d resubmit actions", MAX_RESUBMITS);
2032 } else if (ofpbuf_size(&ctx->xout->odp_actions) > UINT16_MAX) {
2033 VLOG_ERR_RL(&rl, "resubmits yielded over 64 kB of actions");
2034 } else if (ofpbuf_size(&ctx->stack) >= 65536) {
2035 VLOG_ERR_RL(&rl, "resubmits yielded over 64 kB of stack");
2044 xlate_table_action(struct xlate_ctx *ctx, ofp_port_t in_port, uint8_t table_id,
2045 bool may_packet_in, bool honor_table_miss)
2047 if (xlate_resubmit_resource_check(ctx)) {
2048 ofp_port_t old_in_port = ctx->xin->flow.in_port.ofp_port;
2049 bool skip_wildcards = ctx->xin->skip_wildcards;
2050 uint8_t old_table_id = ctx->table_id;
2051 struct rule_dpif *rule;
2052 enum rule_dpif_lookup_verdict verdict;
2053 enum ofputil_port_config config = 0;
2055 ctx->table_id = table_id;
2057 /* Look up a flow with 'in_port' as the input port. Then restore the
2058 * original input port (otherwise OFPP_NORMAL and OFPP_IN_PORT will
2059 * have surprising behavior). */
2060 ctx->xin->flow.in_port.ofp_port = in_port;
2061 verdict = rule_dpif_lookup_from_table(ctx->xbridge->ofproto,
2064 ? &ctx->xout->wc : NULL,
2066 &ctx->table_id, &rule,
2067 ctx->xin->xcache != NULL,
2068 ctx->xin->resubmit_stats);
2069 ctx->xin->flow.in_port.ofp_port = old_in_port;
2071 if (ctx->xin->resubmit_hook) {
2072 ctx->xin->resubmit_hook(ctx->xin, rule, ctx->recurse);
2076 case RULE_DPIF_LOOKUP_VERDICT_MATCH:
2078 case RULE_DPIF_LOOKUP_VERDICT_CONTROLLER:
2079 if (may_packet_in) {
2080 struct xport *xport;
2082 xport = get_ofp_port(ctx->xbridge,
2083 ctx->xin->flow.in_port.ofp_port);
2084 config = xport ? xport->config : 0;
2087 /* Fall through to drop */
2088 case RULE_DPIF_LOOKUP_VERDICT_DROP:
2089 config = OFPUTIL_PC_NO_PACKET_IN;
2091 case RULE_DPIF_LOOKUP_VERDICT_DEFAULT:
2092 if (!ofproto_dpif_wants_packet_in_on_miss(ctx->xbridge->ofproto)) {
2093 config = OFPUTIL_PC_NO_PACKET_IN;
2100 choose_miss_rule(config, ctx->xbridge->miss_rule,
2101 ctx->xbridge->no_packet_in_rule, &rule,
2102 ctx->xin->xcache != NULL);
2106 /* Fill in the cache entry here instead of xlate_recursively
2107 * to make the reference counting more explicit. We take a
2108 * reference in the lookups above if we are going to cache the
2110 if (ctx->xin->xcache) {
2111 struct xc_entry *entry;
2113 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_RULE);
2114 entry->u.rule = rule;
2116 xlate_recursively(ctx, rule);
2119 ctx->table_id = old_table_id;
2127 xlate_group_stats(struct xlate_ctx *ctx, struct group_dpif *group,
2128 struct ofputil_bucket *bucket)
2130 if (ctx->xin->resubmit_stats) {
2131 group_dpif_credit_stats(group, bucket, ctx->xin->resubmit_stats);
2133 if (ctx->xin->xcache) {
2134 struct xc_entry *entry;
2136 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_GROUP);
2137 entry->u.group.group = group_dpif_ref(group);
2138 entry->u.group.bucket = bucket;
2143 xlate_group_bucket(struct xlate_ctx *ctx, struct ofputil_bucket *bucket)
2145 uint64_t action_list_stub[1024 / 8];
2146 struct ofpbuf action_list, action_set;
2148 ofpbuf_use_const(&action_set, bucket->ofpacts, bucket->ofpacts_len);
2149 ofpbuf_use_stub(&action_list, action_list_stub, sizeof action_list_stub);
2151 ofpacts_execute_action_set(&action_list, &action_set);
2153 do_xlate_actions(ofpbuf_data(&action_list), ofpbuf_size(&action_list), ctx);
2156 ofpbuf_uninit(&action_set);
2157 ofpbuf_uninit(&action_list);
2161 xlate_all_group(struct xlate_ctx *ctx, struct group_dpif *group)
2163 struct ofputil_bucket *bucket;
2164 const struct list *buckets;
2165 struct flow old_flow = ctx->xin->flow;
2167 group_dpif_get_buckets(group, &buckets);
2169 LIST_FOR_EACH (bucket, list_node, buckets) {
2170 xlate_group_bucket(ctx, bucket);
2171 /* Roll back flow to previous state.
2172 * This is equivalent to cloning the packet for each bucket.
2174 * As a side effect any subsequently applied actions will
2175 * also effectively be applied to a clone of the packet taken
2176 * just before applying the all or indirect group. */
2177 ctx->xin->flow = old_flow;
2179 xlate_group_stats(ctx, group, NULL);
2183 xlate_ff_group(struct xlate_ctx *ctx, struct group_dpif *group)
2185 struct ofputil_bucket *bucket;
2187 bucket = group_first_live_bucket(ctx, group, 0);
2189 xlate_group_bucket(ctx, bucket);
2190 xlate_group_stats(ctx, group, bucket);
2195 xlate_select_group(struct xlate_ctx *ctx, struct group_dpif *group)
2197 struct flow_wildcards *wc = &ctx->xout->wc;
2198 struct ofputil_bucket *bucket;
2201 basis = hash_mac(ctx->xin->flow.dl_dst, 0, 0);
2202 bucket = group_best_live_bucket(ctx, group, basis);
2204 memset(&wc->masks.dl_dst, 0xff, sizeof wc->masks.dl_dst);
2205 xlate_group_bucket(ctx, bucket);
2206 xlate_group_stats(ctx, group, bucket);
2211 xlate_group_action__(struct xlate_ctx *ctx, struct group_dpif *group)
2213 ctx->in_group = true;
2215 switch (group_dpif_get_type(group)) {
2217 case OFPGT11_INDIRECT:
2218 xlate_all_group(ctx, group);
2220 case OFPGT11_SELECT:
2221 xlate_select_group(ctx, group);
2224 xlate_ff_group(ctx, group);
2229 group_dpif_unref(group);
2231 ctx->in_group = false;
2235 xlate_group_resource_check(struct xlate_ctx *ctx)
2237 if (!xlate_resubmit_resource_check(ctx)) {
2239 } else if (ctx->in_group) {
2240 /* Prevent nested translation of OpenFlow groups.
2242 * OpenFlow allows this restriction. We enforce this restriction only
2243 * because, with the current architecture, we would otherwise have to
2244 * take a possibly recursive read lock on the ofgroup rwlock, which is
2245 * unsafe given that POSIX allows taking a read lock to block if there
2246 * is a thread blocked on taking the write lock. Other solutions
2247 * without this restriction are also possible, but seem unwarranted
2248 * given the current limited use of groups. */
2249 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
2251 VLOG_ERR_RL(&rl, "cannot recursively translate OpenFlow group");
2259 xlate_group_action(struct xlate_ctx *ctx, uint32_t group_id)
2261 if (xlate_group_resource_check(ctx)) {
2262 struct group_dpif *group;
2265 got_group = group_dpif_lookup(ctx->xbridge->ofproto, group_id, &group);
2267 xlate_group_action__(ctx, group);
2277 xlate_ofpact_resubmit(struct xlate_ctx *ctx,
2278 const struct ofpact_resubmit *resubmit)
2282 bool may_packet_in = false;
2283 bool honor_table_miss = false;
2285 if (ctx->rule && rule_dpif_is_internal(ctx->rule)) {
2286 /* Still allow missed packets to be sent to the controller
2287 * if resubmitting from an internal table. */
2288 may_packet_in = true;
2289 honor_table_miss = true;
2292 in_port = resubmit->in_port;
2293 if (in_port == OFPP_IN_PORT) {
2294 in_port = ctx->xin->flow.in_port.ofp_port;
2297 table_id = resubmit->table_id;
2298 if (table_id == 255) {
2299 table_id = ctx->table_id;
2302 xlate_table_action(ctx, in_port, table_id, may_packet_in,
2307 flood_packets(struct xlate_ctx *ctx, bool all)
2309 const struct xport *xport;
2311 HMAP_FOR_EACH (xport, ofp_node, &ctx->xbridge->xports) {
2312 if (xport->ofp_port == ctx->xin->flow.in_port.ofp_port) {
2317 compose_output_action__(ctx, xport->ofp_port, false);
2318 } else if (!(xport->config & OFPUTIL_PC_NO_FLOOD)) {
2319 compose_output_action(ctx, xport->ofp_port);
2323 ctx->xout->nf_output_iface = NF_OUT_FLOOD;
2327 execute_controller_action(struct xlate_ctx *ctx, int len,
2328 enum ofp_packet_in_reason reason,
2329 uint16_t controller_id)
2331 struct ofproto_packet_in *pin;
2332 struct ofpbuf *packet;
2333 struct pkt_metadata md = PKT_METADATA_INITIALIZER(0);
2335 ctx->xout->slow |= SLOW_CONTROLLER;
2336 if (!ctx->xin->packet) {
2340 packet = ofpbuf_clone(ctx->xin->packet);
2342 ctx->xout->slow |= commit_odp_actions(&ctx->xin->flow, &ctx->base_flow,
2343 &ctx->xout->odp_actions,
2346 odp_execute_actions(NULL, packet, false, &md,
2347 ofpbuf_data(&ctx->xout->odp_actions),
2348 ofpbuf_size(&ctx->xout->odp_actions), NULL);
2350 pin = xmalloc(sizeof *pin);
2351 pin->up.packet_len = ofpbuf_size(packet);
2352 pin->up.packet = ofpbuf_steal_data(packet);
2353 pin->up.reason = reason;
2354 pin->up.table_id = ctx->table_id;
2355 pin->up.cookie = (ctx->rule
2356 ? rule_dpif_get_flow_cookie(ctx->rule)
2359 flow_get_metadata(&ctx->xin->flow, &pin->up.fmd);
2361 pin->controller_id = controller_id;
2362 pin->send_len = len;
2363 /* If a rule is a table-miss rule then this is
2364 * a table-miss handled by a table-miss rule.
2366 * Else, if rule is internal and has a controller action,
2367 * the later being implied by the rule being processed here,
2368 * then this is a table-miss handled without a table-miss rule.
2370 * Otherwise this is not a table-miss. */
2371 pin->miss_type = OFPROTO_PACKET_IN_NO_MISS;
2373 if (rule_dpif_is_table_miss(ctx->rule)) {
2374 pin->miss_type = OFPROTO_PACKET_IN_MISS_FLOW;
2375 } else if (rule_dpif_is_internal(ctx->rule)) {
2376 pin->miss_type = OFPROTO_PACKET_IN_MISS_WITHOUT_FLOW;
2379 ofproto_dpif_send_packet_in(ctx->xbridge->ofproto, pin);
2380 ofpbuf_delete(packet);
2384 compose_mpls_push_action(struct xlate_ctx *ctx, struct ofpact_push_mpls *mpls)
2386 struct flow_wildcards *wc = &ctx->xout->wc;
2387 struct flow *flow = &ctx->xin->flow;
2390 ovs_assert(eth_type_mpls(mpls->ethertype));
2392 n = flow_count_mpls_labels(flow, wc);
2394 ctx->xout->slow |= commit_odp_actions(flow, &ctx->base_flow,
2395 &ctx->xout->odp_actions,
2397 } else if (n >= FLOW_MAX_MPLS_LABELS) {
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 on which an "
2401 "MPLS push action can't be performed as it would "
2402 "have more MPLS LSEs than the %d supported.",
2403 ctx->xbridge->name, FLOW_MAX_MPLS_LABELS);
2407 } else if (n >= ctx->xbridge->max_mpls_depth) {
2408 COVERAGE_INC(xlate_actions_mpls_overflow);
2409 ctx->xout->slow |= SLOW_ACTION;
2412 flow_push_mpls(flow, n, mpls->ethertype, wc);
2416 compose_mpls_pop_action(struct xlate_ctx *ctx, ovs_be16 eth_type)
2418 struct flow_wildcards *wc = &ctx->xout->wc;
2419 struct flow *flow = &ctx->xin->flow;
2420 int n = flow_count_mpls_labels(flow, wc);
2422 if (!flow_pop_mpls(flow, n, eth_type, wc) && n >= FLOW_MAX_MPLS_LABELS) {
2423 if (ctx->xin->packet != NULL) {
2424 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
2425 VLOG_WARN_RL(&rl, "bridge %s: dropping packet on which an "
2426 "MPLS pop action can't be performed as it has "
2427 "more MPLS LSEs than the %d supported.",
2428 ctx->xbridge->name, FLOW_MAX_MPLS_LABELS);
2431 ofpbuf_clear(&ctx->xout->odp_actions);
2436 compose_dec_ttl(struct xlate_ctx *ctx, struct ofpact_cnt_ids *ids)
2438 struct flow *flow = &ctx->xin->flow;
2440 if (!is_ip_any(flow)) {
2444 ctx->xout->wc.masks.nw_ttl = 0xff;
2445 if (flow->nw_ttl > 1) {
2451 for (i = 0; i < ids->n_controllers; i++) {
2452 execute_controller_action(ctx, UINT16_MAX, OFPR_INVALID_TTL,
2456 /* Stop processing for current table. */
2462 compose_set_mpls_label_action(struct xlate_ctx *ctx, ovs_be32 label)
2464 if (eth_type_mpls(ctx->xin->flow.dl_type)) {
2465 ctx->xout->wc.masks.mpls_lse[0] |= htonl(MPLS_LABEL_MASK);
2466 set_mpls_lse_label(&ctx->xin->flow.mpls_lse[0], label);
2471 compose_set_mpls_tc_action(struct xlate_ctx *ctx, uint8_t tc)
2473 if (eth_type_mpls(ctx->xin->flow.dl_type)) {
2474 ctx->xout->wc.masks.mpls_lse[0] |= htonl(MPLS_TC_MASK);
2475 set_mpls_lse_tc(&ctx->xin->flow.mpls_lse[0], tc);
2480 compose_set_mpls_ttl_action(struct xlate_ctx *ctx, uint8_t ttl)
2482 if (eth_type_mpls(ctx->xin->flow.dl_type)) {
2483 ctx->xout->wc.masks.mpls_lse[0] |= htonl(MPLS_TTL_MASK);
2484 set_mpls_lse_ttl(&ctx->xin->flow.mpls_lse[0], ttl);
2489 compose_dec_mpls_ttl_action(struct xlate_ctx *ctx)
2491 struct flow *flow = &ctx->xin->flow;
2492 uint8_t ttl = mpls_lse_to_ttl(flow->mpls_lse[0]);
2493 struct flow_wildcards *wc = &ctx->xout->wc;
2495 memset(&wc->masks.mpls_lse, 0xff, sizeof wc->masks.mpls_lse);
2496 if (eth_type_mpls(flow->dl_type)) {
2499 set_mpls_lse_ttl(&flow->mpls_lse[0], ttl);
2502 execute_controller_action(ctx, UINT16_MAX, OFPR_INVALID_TTL, 0);
2504 /* Stop processing for current table. */
2513 xlate_output_action(struct xlate_ctx *ctx,
2514 ofp_port_t port, uint16_t max_len, bool may_packet_in)
2516 ofp_port_t prev_nf_output_iface = ctx->xout->nf_output_iface;
2518 ctx->xout->nf_output_iface = NF_OUT_DROP;
2522 compose_output_action(ctx, ctx->xin->flow.in_port.ofp_port);
2525 xlate_table_action(ctx, ctx->xin->flow.in_port.ofp_port,
2526 0, may_packet_in, true);
2532 flood_packets(ctx, false);
2535 flood_packets(ctx, true);
2537 case OFPP_CONTROLLER:
2538 execute_controller_action(ctx, max_len, OFPR_ACTION, 0);
2544 if (port != ctx->xin->flow.in_port.ofp_port) {
2545 compose_output_action(ctx, port);
2547 xlate_report(ctx, "skipping output to input port");
2552 if (prev_nf_output_iface == NF_OUT_FLOOD) {
2553 ctx->xout->nf_output_iface = NF_OUT_FLOOD;
2554 } else if (ctx->xout->nf_output_iface == NF_OUT_DROP) {
2555 ctx->xout->nf_output_iface = prev_nf_output_iface;
2556 } else if (prev_nf_output_iface != NF_OUT_DROP &&
2557 ctx->xout->nf_output_iface != NF_OUT_FLOOD) {
2558 ctx->xout->nf_output_iface = NF_OUT_MULTI;
2563 xlate_output_reg_action(struct xlate_ctx *ctx,
2564 const struct ofpact_output_reg *or)
2566 uint64_t port = mf_get_subfield(&or->src, &ctx->xin->flow);
2567 if (port <= UINT16_MAX) {
2568 union mf_subvalue value;
2570 memset(&value, 0xff, sizeof value);
2571 mf_write_subfield_flow(&or->src, &value, &ctx->xout->wc.masks);
2572 xlate_output_action(ctx, u16_to_ofp(port),
2573 or->max_len, false);
2578 xlate_enqueue_action(struct xlate_ctx *ctx,
2579 const struct ofpact_enqueue *enqueue)
2581 ofp_port_t ofp_port = enqueue->port;
2582 uint32_t queue_id = enqueue->queue;
2583 uint32_t flow_priority, priority;
2586 /* Translate queue to priority. */
2587 error = dpif_queue_to_priority(ctx->xbridge->dpif, queue_id, &priority);
2589 /* Fall back to ordinary output action. */
2590 xlate_output_action(ctx, enqueue->port, 0, false);
2594 /* Check output port. */
2595 if (ofp_port == OFPP_IN_PORT) {
2596 ofp_port = ctx->xin->flow.in_port.ofp_port;
2597 } else if (ofp_port == ctx->xin->flow.in_port.ofp_port) {
2601 /* Add datapath actions. */
2602 flow_priority = ctx->xin->flow.skb_priority;
2603 ctx->xin->flow.skb_priority = priority;
2604 compose_output_action(ctx, ofp_port);
2605 ctx->xin->flow.skb_priority = flow_priority;
2607 /* Update NetFlow output port. */
2608 if (ctx->xout->nf_output_iface == NF_OUT_DROP) {
2609 ctx->xout->nf_output_iface = ofp_port;
2610 } else if (ctx->xout->nf_output_iface != NF_OUT_FLOOD) {
2611 ctx->xout->nf_output_iface = NF_OUT_MULTI;
2616 xlate_set_queue_action(struct xlate_ctx *ctx, uint32_t queue_id)
2618 uint32_t skb_priority;
2620 if (!dpif_queue_to_priority(ctx->xbridge->dpif, queue_id, &skb_priority)) {
2621 ctx->xin->flow.skb_priority = skb_priority;
2623 /* Couldn't translate queue to a priority. Nothing to do. A warning
2624 * has already been logged. */
2629 slave_enabled_cb(ofp_port_t ofp_port, void *xbridge_)
2631 const struct xbridge *xbridge = xbridge_;
2642 case OFPP_CONTROLLER: /* Not supported by the bundle action. */
2645 port = get_ofp_port(xbridge, ofp_port);
2646 return port ? port->may_enable : false;
2651 xlate_bundle_action(struct xlate_ctx *ctx,
2652 const struct ofpact_bundle *bundle)
2656 port = bundle_execute(bundle, &ctx->xin->flow, &ctx->xout->wc,
2658 CONST_CAST(struct xbridge *, ctx->xbridge));
2659 if (bundle->dst.field) {
2660 nxm_reg_load(&bundle->dst, ofp_to_u16(port), &ctx->xin->flow,
2663 xlate_output_action(ctx, port, 0, false);
2668 xlate_learn_action(struct xlate_ctx *ctx,
2669 const struct ofpact_learn *learn)
2671 uint64_t ofpacts_stub[1024 / 8];
2672 struct ofputil_flow_mod fm;
2673 struct ofpbuf ofpacts;
2675 ctx->xout->has_learn = true;
2677 learn_mask(learn, &ctx->xout->wc);
2679 if (!ctx->xin->may_learn) {
2683 ofpbuf_use_stub(&ofpacts, ofpacts_stub, sizeof ofpacts_stub);
2684 learn_execute(learn, &ctx->xin->flow, &fm, &ofpacts);
2685 ofproto_dpif_flow_mod(ctx->xbridge->ofproto, &fm);
2686 ofpbuf_uninit(&ofpacts);
2688 if (ctx->xin->xcache) {
2689 struct xc_entry *entry;
2691 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_LEARN);
2692 entry->u.learn.ofproto = ctx->xin->ofproto;
2693 /* Lookup the learned rule, taking a reference on it. The reference
2694 * is released when this cache entry is deleted. */
2695 rule_dpif_lookup(ctx->xbridge->ofproto, &ctx->xin->flow, NULL,
2696 &entry->u.learn.rule, true, NULL);
2701 xlate_fin_timeout__(struct rule_dpif *rule, uint16_t tcp_flags,
2702 uint16_t idle_timeout, uint16_t hard_timeout)
2704 if (tcp_flags & (TCP_FIN | TCP_RST)) {
2705 rule_dpif_reduce_timeouts(rule, idle_timeout, hard_timeout);
2710 xlate_fin_timeout(struct xlate_ctx *ctx,
2711 const struct ofpact_fin_timeout *oft)
2714 xlate_fin_timeout__(ctx->rule, ctx->xin->tcp_flags,
2715 oft->fin_idle_timeout, oft->fin_hard_timeout);
2716 if (ctx->xin->xcache) {
2717 struct xc_entry *entry;
2719 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_FIN_TIMEOUT);
2720 /* XC_RULE already holds a reference on the rule, none is taken
2722 entry->u.fin.rule = ctx->rule;
2723 entry->u.fin.idle = oft->fin_idle_timeout;
2724 entry->u.fin.hard = oft->fin_hard_timeout;
2730 xlate_sample_action(struct xlate_ctx *ctx,
2731 const struct ofpact_sample *os)
2733 union user_action_cookie cookie;
2734 /* Scale the probability from 16-bit to 32-bit while representing
2735 * the same percentage. */
2736 uint32_t probability = (os->probability << 16) | os->probability;
2738 if (!ctx->xbridge->variable_length_userdata) {
2739 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
2741 VLOG_ERR_RL(&rl, "ignoring NXAST_SAMPLE action because datapath "
2742 "lacks support (needs Linux 3.10+ or kernel module from "
2747 ctx->xout->slow |= commit_odp_actions(&ctx->xin->flow, &ctx->base_flow,
2748 &ctx->xout->odp_actions,
2751 compose_flow_sample_cookie(os->probability, os->collector_set_id,
2752 os->obs_domain_id, os->obs_point_id, &cookie);
2753 compose_sample_action(ctx->xbridge, &ctx->xout->odp_actions, &ctx->xin->flow,
2754 probability, &cookie, sizeof cookie.flow_sample);
2758 may_receive(const struct xport *xport, struct xlate_ctx *ctx)
2760 if (xport->config & (is_stp(&ctx->xin->flow)
2761 ? OFPUTIL_PC_NO_RECV_STP
2762 : OFPUTIL_PC_NO_RECV)) {
2766 /* Only drop packets here if both forwarding and learning are
2767 * disabled. If just learning is enabled, we need to have
2768 * OFPP_NORMAL and the learning action have a look at the packet
2769 * before we can drop it. */
2770 if (!xport_stp_forward_state(xport) && !xport_stp_learn_state(xport)) {
2778 xlate_write_actions(struct xlate_ctx *ctx, const struct ofpact *a)
2780 struct ofpact_nest *on = ofpact_get_WRITE_ACTIONS(a);
2781 ofpbuf_put(&ctx->action_set, on->actions, ofpact_nest_get_action_len(on));
2782 ofpact_pad(&ctx->action_set);
2786 xlate_action_set(struct xlate_ctx *ctx)
2788 uint64_t action_list_stub[1024 / 64];
2789 struct ofpbuf action_list;
2791 ofpbuf_use_stub(&action_list, action_list_stub, sizeof action_list_stub);
2792 ofpacts_execute_action_set(&action_list, &ctx->action_set);
2793 do_xlate_actions(ofpbuf_data(&action_list), ofpbuf_size(&action_list), ctx);
2794 ofpbuf_uninit(&action_list);
2798 do_xlate_actions(const struct ofpact *ofpacts, size_t ofpacts_len,
2799 struct xlate_ctx *ctx)
2801 struct flow_wildcards *wc = &ctx->xout->wc;
2802 struct flow *flow = &ctx->xin->flow;
2803 const struct ofpact *a;
2805 /* dl_type already in the mask, not set below. */
2807 OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
2808 struct ofpact_controller *controller;
2809 const struct ofpact_metadata *metadata;
2810 const struct ofpact_set_field *set_field;
2811 const struct mf_field *mf;
2819 xlate_output_action(ctx, ofpact_get_OUTPUT(a)->port,
2820 ofpact_get_OUTPUT(a)->max_len, true);
2824 if (xlate_group_action(ctx, ofpact_get_GROUP(a)->group_id)) {
2829 case OFPACT_CONTROLLER:
2830 controller = ofpact_get_CONTROLLER(a);
2831 execute_controller_action(ctx, controller->max_len,
2833 controller->controller_id);
2836 case OFPACT_ENQUEUE:
2837 xlate_enqueue_action(ctx, ofpact_get_ENQUEUE(a));
2840 case OFPACT_SET_VLAN_VID:
2841 wc->masks.vlan_tci |= htons(VLAN_VID_MASK | VLAN_CFI);
2842 if (flow->vlan_tci & htons(VLAN_CFI) ||
2843 ofpact_get_SET_VLAN_VID(a)->push_vlan_if_needed) {
2844 flow->vlan_tci &= ~htons(VLAN_VID_MASK);
2845 flow->vlan_tci |= (htons(ofpact_get_SET_VLAN_VID(a)->vlan_vid)
2850 case OFPACT_SET_VLAN_PCP:
2851 wc->masks.vlan_tci |= htons(VLAN_PCP_MASK | VLAN_CFI);
2852 if (flow->vlan_tci & htons(VLAN_CFI) ||
2853 ofpact_get_SET_VLAN_PCP(a)->push_vlan_if_needed) {
2854 flow->vlan_tci &= ~htons(VLAN_PCP_MASK);
2855 flow->vlan_tci |= htons((ofpact_get_SET_VLAN_PCP(a)->vlan_pcp
2856 << VLAN_PCP_SHIFT) | VLAN_CFI);
2860 case OFPACT_STRIP_VLAN:
2861 memset(&wc->masks.vlan_tci, 0xff, sizeof wc->masks.vlan_tci);
2862 flow->vlan_tci = htons(0);
2865 case OFPACT_PUSH_VLAN:
2866 /* XXX 802.1AD(QinQ) */
2867 memset(&wc->masks.vlan_tci, 0xff, sizeof wc->masks.vlan_tci);
2868 flow->vlan_tci = htons(VLAN_CFI);
2871 case OFPACT_SET_ETH_SRC:
2872 memset(&wc->masks.dl_src, 0xff, sizeof wc->masks.dl_src);
2873 memcpy(flow->dl_src, ofpact_get_SET_ETH_SRC(a)->mac, ETH_ADDR_LEN);
2876 case OFPACT_SET_ETH_DST:
2877 memset(&wc->masks.dl_dst, 0xff, sizeof wc->masks.dl_dst);
2878 memcpy(flow->dl_dst, ofpact_get_SET_ETH_DST(a)->mac, ETH_ADDR_LEN);
2881 case OFPACT_SET_IPV4_SRC:
2882 if (flow->dl_type == htons(ETH_TYPE_IP)) {
2883 memset(&wc->masks.nw_src, 0xff, sizeof wc->masks.nw_src);
2884 flow->nw_src = ofpact_get_SET_IPV4_SRC(a)->ipv4;
2888 case OFPACT_SET_IPV4_DST:
2889 if (flow->dl_type == htons(ETH_TYPE_IP)) {
2890 memset(&wc->masks.nw_dst, 0xff, sizeof wc->masks.nw_dst);
2891 flow->nw_dst = ofpact_get_SET_IPV4_DST(a)->ipv4;
2895 case OFPACT_SET_IP_DSCP:
2896 if (is_ip_any(flow)) {
2897 wc->masks.nw_tos |= IP_DSCP_MASK;
2898 flow->nw_tos &= ~IP_DSCP_MASK;
2899 flow->nw_tos |= ofpact_get_SET_IP_DSCP(a)->dscp;
2903 case OFPACT_SET_IP_ECN:
2904 if (is_ip_any(flow)) {
2905 wc->masks.nw_tos |= IP_ECN_MASK;
2906 flow->nw_tos &= ~IP_ECN_MASK;
2907 flow->nw_tos |= ofpact_get_SET_IP_ECN(a)->ecn;
2911 case OFPACT_SET_IP_TTL:
2912 if (is_ip_any(flow)) {
2913 wc->masks.nw_ttl = 0xff;
2914 flow->nw_ttl = ofpact_get_SET_IP_TTL(a)->ttl;
2918 case OFPACT_SET_L4_SRC_PORT:
2919 if (is_ip_any(flow)) {
2920 memset(&wc->masks.nw_proto, 0xff, sizeof wc->masks.nw_proto);
2921 memset(&wc->masks.tp_src, 0xff, sizeof wc->masks.tp_src);
2922 flow->tp_src = htons(ofpact_get_SET_L4_SRC_PORT(a)->port);
2926 case OFPACT_SET_L4_DST_PORT:
2927 if (is_ip_any(flow)) {
2928 memset(&wc->masks.nw_proto, 0xff, sizeof wc->masks.nw_proto);
2929 memset(&wc->masks.tp_dst, 0xff, sizeof wc->masks.tp_dst);
2930 flow->tp_dst = htons(ofpact_get_SET_L4_DST_PORT(a)->port);
2934 case OFPACT_RESUBMIT:
2935 xlate_ofpact_resubmit(ctx, ofpact_get_RESUBMIT(a));
2938 case OFPACT_SET_TUNNEL:
2939 flow->tunnel.tun_id = htonll(ofpact_get_SET_TUNNEL(a)->tun_id);
2942 case OFPACT_SET_QUEUE:
2943 xlate_set_queue_action(ctx, ofpact_get_SET_QUEUE(a)->queue_id);
2946 case OFPACT_POP_QUEUE:
2947 flow->skb_priority = ctx->orig_skb_priority;
2950 case OFPACT_REG_MOVE:
2951 nxm_execute_reg_move(ofpact_get_REG_MOVE(a), flow, wc);
2954 case OFPACT_REG_LOAD:
2955 nxm_execute_reg_load(ofpact_get_REG_LOAD(a), flow, wc);
2958 case OFPACT_SET_FIELD:
2959 set_field = ofpact_get_SET_FIELD(a);
2960 mf = set_field->field;
2962 /* Set field action only ever overwrites packet's outermost
2963 * applicable header fields. Do nothing if no header exists. */
2964 if (mf->id == MFF_VLAN_VID) {
2965 wc->masks.vlan_tci |= htons(VLAN_CFI);
2966 if (!(flow->vlan_tci & htons(VLAN_CFI))) {
2969 } else if ((mf->id == MFF_MPLS_LABEL || mf->id == MFF_MPLS_TC)
2970 /* 'dl_type' is already unwildcarded. */
2971 && !eth_type_mpls(flow->dl_type)) {
2975 mf_mask_field_and_prereqs(mf, &wc->masks);
2976 mf_set_flow_value(mf, &set_field->value, flow);
2979 case OFPACT_STACK_PUSH:
2980 nxm_execute_stack_push(ofpact_get_STACK_PUSH(a), flow, wc,
2984 case OFPACT_STACK_POP:
2985 nxm_execute_stack_pop(ofpact_get_STACK_POP(a), flow, wc,
2989 case OFPACT_PUSH_MPLS:
2990 compose_mpls_push_action(ctx, ofpact_get_PUSH_MPLS(a));
2993 case OFPACT_POP_MPLS:
2994 compose_mpls_pop_action(ctx, ofpact_get_POP_MPLS(a)->ethertype);
2997 case OFPACT_SET_MPLS_LABEL:
2998 compose_set_mpls_label_action(
2999 ctx, ofpact_get_SET_MPLS_LABEL(a)->label);
3002 case OFPACT_SET_MPLS_TC:
3003 compose_set_mpls_tc_action(ctx, ofpact_get_SET_MPLS_TC(a)->tc);
3006 case OFPACT_SET_MPLS_TTL:
3007 compose_set_mpls_ttl_action(ctx, ofpact_get_SET_MPLS_TTL(a)->ttl);
3010 case OFPACT_DEC_MPLS_TTL:
3011 if (compose_dec_mpls_ttl_action(ctx)) {
3016 case OFPACT_DEC_TTL:
3017 wc->masks.nw_ttl = 0xff;
3018 if (compose_dec_ttl(ctx, ofpact_get_DEC_TTL(a))) {
3024 /* Nothing to do. */
3027 case OFPACT_MULTIPATH:
3028 multipath_execute(ofpact_get_MULTIPATH(a), flow, wc);
3032 xlate_bundle_action(ctx, ofpact_get_BUNDLE(a));
3035 case OFPACT_OUTPUT_REG:
3036 xlate_output_reg_action(ctx, ofpact_get_OUTPUT_REG(a));
3040 xlate_learn_action(ctx, ofpact_get_LEARN(a));
3047 case OFPACT_FIN_TIMEOUT:
3048 memset(&wc->masks.nw_proto, 0xff, sizeof wc->masks.nw_proto);
3049 ctx->xout->has_fin_timeout = true;
3050 xlate_fin_timeout(ctx, ofpact_get_FIN_TIMEOUT(a));
3053 case OFPACT_CLEAR_ACTIONS:
3054 ofpbuf_clear(&ctx->action_set);
3057 case OFPACT_WRITE_ACTIONS:
3058 xlate_write_actions(ctx, a);
3061 case OFPACT_WRITE_METADATA:
3062 metadata = ofpact_get_WRITE_METADATA(a);
3063 flow->metadata &= ~metadata->mask;
3064 flow->metadata |= metadata->metadata & metadata->mask;
3068 /* Not implemented yet. */
3071 case OFPACT_GOTO_TABLE: {
3072 struct ofpact_goto_table *ogt = ofpact_get_GOTO_TABLE(a);
3074 ovs_assert(ctx->table_id < ogt->table_id);
3075 xlate_table_action(ctx, ctx->xin->flow.in_port.ofp_port,
3076 ogt->table_id, true, true);
3081 xlate_sample_action(ctx, ofpact_get_SAMPLE(a));
3088 xlate_in_init(struct xlate_in *xin, struct ofproto_dpif *ofproto,
3089 const struct flow *flow, struct rule_dpif *rule,
3090 uint16_t tcp_flags, const struct ofpbuf *packet)
3092 xin->ofproto = ofproto;
3094 xin->packet = packet;
3095 xin->may_learn = packet != NULL;
3098 xin->ofpacts = NULL;
3099 xin->ofpacts_len = 0;
3100 xin->tcp_flags = tcp_flags;
3101 xin->resubmit_hook = NULL;
3102 xin->report_hook = NULL;
3103 xin->resubmit_stats = NULL;
3104 xin->skip_wildcards = false;
3108 xlate_out_uninit(struct xlate_out *xout)
3111 ofpbuf_uninit(&xout->odp_actions);
3115 /* Translates the 'ofpacts_len' bytes of "struct ofpact"s starting at 'ofpacts'
3116 * into datapath actions, using 'ctx', and discards the datapath actions. */
3118 xlate_actions_for_side_effects(struct xlate_in *xin)
3120 struct xlate_out xout;
3122 xlate_actions(xin, &xout);
3123 xlate_out_uninit(&xout);
3127 xlate_report(struct xlate_ctx *ctx, const char *s)
3129 if (ctx->xin->report_hook) {
3130 ctx->xin->report_hook(ctx->xin, s, ctx->recurse);
3135 xlate_out_copy(struct xlate_out *dst, const struct xlate_out *src)
3138 dst->slow = src->slow;
3139 dst->has_learn = src->has_learn;
3140 dst->has_normal = src->has_normal;
3141 dst->has_fin_timeout = src->has_fin_timeout;
3142 dst->nf_output_iface = src->nf_output_iface;
3143 dst->mirrors = src->mirrors;
3145 ofpbuf_use_stub(&dst->odp_actions, dst->odp_actions_stub,
3146 sizeof dst->odp_actions_stub);
3147 ofpbuf_put(&dst->odp_actions, ofpbuf_data(&src->odp_actions),
3148 ofpbuf_size(&src->odp_actions));
3151 static struct skb_priority_to_dscp *
3152 get_skb_priority(const struct xport *xport, uint32_t skb_priority)
3154 struct skb_priority_to_dscp *pdscp;
3157 hash = hash_int(skb_priority, 0);
3158 HMAP_FOR_EACH_IN_BUCKET (pdscp, hmap_node, hash, &xport->skb_priorities) {
3159 if (pdscp->skb_priority == skb_priority) {
3167 dscp_from_skb_priority(const struct xport *xport, uint32_t skb_priority,
3170 struct skb_priority_to_dscp *pdscp = get_skb_priority(xport, skb_priority);
3171 *dscp = pdscp ? pdscp->dscp : 0;
3172 return pdscp != NULL;
3176 clear_skb_priorities(struct xport *xport)
3178 struct skb_priority_to_dscp *pdscp, *next;
3180 HMAP_FOR_EACH_SAFE (pdscp, next, hmap_node, &xport->skb_priorities) {
3181 hmap_remove(&xport->skb_priorities, &pdscp->hmap_node);
3187 actions_output_to_local_port(const struct xlate_ctx *ctx)
3189 odp_port_t local_odp_port = ofp_port_to_odp_port(ctx->xbridge, OFPP_LOCAL);
3190 const struct nlattr *a;
3193 NL_ATTR_FOR_EACH_UNSAFE (a, left, ofpbuf_data(&ctx->xout->odp_actions),
3194 ofpbuf_size(&ctx->xout->odp_actions)) {
3195 if (nl_attr_type(a) == OVS_ACTION_ATTR_OUTPUT
3196 && nl_attr_get_odp_port(a) == local_odp_port) {
3203 /* Thread safe call to xlate_actions__(). */
3205 xlate_actions(struct xlate_in *xin, struct xlate_out *xout)
3206 OVS_EXCLUDED(xlate_rwlock)
3208 ovs_rwlock_rdlock(&xlate_rwlock);
3209 xlate_actions__(xin, xout);
3210 ovs_rwlock_unlock(&xlate_rwlock);
3213 /* Translates the 'ofpacts_len' bytes of "struct ofpacts" starting at 'ofpacts'
3214 * into datapath actions in 'odp_actions', using 'ctx'.
3216 * The caller must take responsibility for eventually freeing 'xout', with
3217 * xlate_out_uninit(). */
3219 xlate_actions__(struct xlate_in *xin, struct xlate_out *xout)
3220 OVS_REQ_RDLOCK(xlate_rwlock)
3222 struct flow_wildcards *wc = &xout->wc;
3223 struct flow *flow = &xin->flow;
3224 struct rule_dpif *rule = NULL;
3226 const struct rule_actions *actions = NULL;
3227 enum slow_path_reason special;
3228 const struct ofpact *ofpacts;
3229 struct xport *in_port;
3230 struct flow orig_flow;
3231 struct xlate_ctx ctx;
3236 COVERAGE_INC(xlate_actions);
3238 /* Flow initialization rules:
3239 * - 'base_flow' must match the kernel's view of the packet at the
3240 * time that action processing starts. 'flow' represents any
3241 * transformations we wish to make through actions.
3242 * - By default 'base_flow' and 'flow' are the same since the input
3243 * packet matches the output before any actions are applied.
3244 * - When using VLAN splinters, 'base_flow''s VLAN is set to the value
3245 * of the received packet as seen by the kernel. If we later output
3246 * to another device without any modifications this will cause us to
3247 * insert a new tag since the original one was stripped off by the
3249 * - Tunnel metadata as received is retained in 'flow'. This allows
3250 * tunnel metadata matching also in later tables.
3251 * Since a kernel action for setting the tunnel metadata will only be
3252 * generated with actual tunnel output, changing the tunnel metadata
3253 * values in 'flow' (such as tun_id) will only have effect with a later
3254 * tunnel output action.
3255 * - Tunnel 'base_flow' is completely cleared since that is what the
3256 * kernel does. If we wish to maintain the original values an action
3257 * needs to be generated. */
3262 ctx.xout->has_learn = false;
3263 ctx.xout->has_normal = false;
3264 ctx.xout->has_fin_timeout = false;
3265 ctx.xout->nf_output_iface = NF_OUT_DROP;
3266 ctx.xout->mirrors = 0;
3267 ofpbuf_use_stub(&ctx.xout->odp_actions, ctx.xout->odp_actions_stub,
3268 sizeof ctx.xout->odp_actions_stub);
3269 ofpbuf_reserve(&ctx.xout->odp_actions, NL_A_U32_SIZE);
3271 ctx.xbridge = xbridge_lookup(xin->ofproto);
3276 ctx.rule = xin->rule;
3278 ctx.base_flow = *flow;
3279 memset(&ctx.base_flow.tunnel, 0, sizeof ctx.base_flow.tunnel);
3280 ctx.orig_tunnel_ip_dst = flow->tunnel.ip_dst;
3282 flow_wildcards_init_catchall(wc);
3283 memset(&wc->masks.in_port, 0xff, sizeof wc->masks.in_port);
3284 memset(&wc->masks.skb_priority, 0xff, sizeof wc->masks.skb_priority);
3285 memset(&wc->masks.dl_type, 0xff, sizeof wc->masks.dl_type);
3286 if (is_ip_any(flow)) {
3287 wc->masks.nw_frag |= FLOW_NW_FRAG_MASK;
3289 is_icmp = is_icmpv4(flow) || is_icmpv6(flow);
3291 tnl_may_send = tnl_xlate_init(&ctx.base_flow, flow, wc);
3292 if (ctx.xbridge->netflow) {
3293 netflow_mask_wc(flow, wc);
3298 ctx.in_group = false;
3299 ctx.orig_skb_priority = flow->skb_priority;
3302 ctx.use_recirc = false;
3304 if (!xin->ofpacts && !ctx.rule) {
3305 ctx.table_id = rule_dpif_lookup(ctx.xbridge->ofproto, flow,
3306 !xin->skip_wildcards ? wc : NULL,
3307 &rule, ctx.xin->xcache != NULL,
3308 ctx.xin->resubmit_stats);
3309 if (ctx.xin->resubmit_stats) {
3310 rule_dpif_credit_stats(rule, ctx.xin->resubmit_stats);
3312 if (ctx.xin->xcache) {
3313 struct xc_entry *entry;
3315 entry = xlate_cache_add_entry(ctx.xin->xcache, XC_RULE);
3316 entry->u.rule = rule;
3320 xout->fail_open = ctx.rule && rule_dpif_is_fail_open(ctx.rule);
3323 ofpacts = xin->ofpacts;
3324 ofpacts_len = xin->ofpacts_len;
3325 } else if (ctx.rule) {
3326 actions = rule_dpif_get_actions(ctx.rule);
3327 ofpacts = actions->ofpacts;
3328 ofpacts_len = actions->ofpacts_len;
3333 ofpbuf_use_stub(&ctx.stack, ctx.init_stack, sizeof ctx.init_stack);
3334 ofpbuf_use_stub(&ctx.action_set,
3335 ctx.action_set_stub, sizeof ctx.action_set_stub);
3337 if (mbridge_has_mirrors(ctx.xbridge->mbridge)) {
3338 /* Do this conditionally because the copy is expensive enough that it
3339 * shows up in profiles. */
3343 if (flow->nw_frag & FLOW_NW_FRAG_ANY) {
3344 switch (ctx.xbridge->frag) {
3345 case OFPC_FRAG_NORMAL:
3346 /* We must pretend that transport ports are unavailable. */
3347 flow->tp_src = ctx.base_flow.tp_src = htons(0);
3348 flow->tp_dst = ctx.base_flow.tp_dst = htons(0);
3351 case OFPC_FRAG_DROP:
3354 case OFPC_FRAG_REASM:
3357 case OFPC_FRAG_NX_MATCH:
3358 /* Nothing to do. */
3361 case OFPC_INVALID_TTL_TO_CONTROLLER:
3366 in_port = get_ofp_port(ctx.xbridge, flow->in_port.ofp_port);
3367 if (in_port && in_port->is_tunnel) {
3368 if (ctx.xin->resubmit_stats) {
3369 netdev_vport_inc_rx(in_port->netdev, ctx.xin->resubmit_stats);
3371 bfd_account_rx(in_port->bfd, ctx.xin->resubmit_stats);
3374 if (ctx.xin->xcache) {
3375 struct xc_entry *entry;
3377 entry = xlate_cache_add_entry(ctx.xin->xcache, XC_NETDEV);
3378 entry->u.dev.rx = netdev_ref(in_port->netdev);
3379 entry->u.dev.bfd = bfd_ref(in_port->bfd);
3383 special = process_special(&ctx, flow, in_port, ctx.xin->packet);
3385 ctx.xout->slow |= special;
3387 size_t sample_actions_len;
3389 if (flow->in_port.ofp_port
3390 != vsp_realdev_to_vlandev(ctx.xbridge->ofproto,
3391 flow->in_port.ofp_port,
3393 ctx.base_flow.vlan_tci = 0;
3396 add_sflow_action(&ctx);
3397 add_ipfix_action(&ctx);
3398 sample_actions_len = ofpbuf_size(&ctx.xout->odp_actions);
3400 if (tnl_may_send && (!in_port || may_receive(in_port, &ctx))) {
3401 do_xlate_actions(ofpacts, ofpacts_len, &ctx);
3403 /* We've let OFPP_NORMAL and the learning action look at the
3404 * packet, so drop it now if forwarding is disabled. */
3405 if (in_port && !xport_stp_forward_state(in_port)) {
3406 ofpbuf_set_size(&ctx.xout->odp_actions, sample_actions_len);
3410 if (ofpbuf_size(&ctx.action_set)) {
3411 xlate_action_set(&ctx);
3414 if (ctx.xbridge->has_in_band
3415 && in_band_must_output_to_local_port(flow)
3416 && !actions_output_to_local_port(&ctx)) {
3417 compose_output_action(&ctx, OFPP_LOCAL);
3420 fix_sflow_action(&ctx);
3422 if (mbridge_has_mirrors(ctx.xbridge->mbridge)) {
3423 add_mirror_actions(&ctx, &orig_flow);
3427 if (nl_attr_oversized(ofpbuf_size(&ctx.xout->odp_actions))) {
3428 /* These datapath actions are too big for a Netlink attribute, so we
3429 * can't hand them to the kernel directly. dpif_execute() can execute
3430 * them one by one with help, so just mark the result as SLOW_ACTION to
3431 * prevent the flow from being installed. */
3432 COVERAGE_INC(xlate_actions_oversize);
3433 ctx.xout->slow |= SLOW_ACTION;
3436 if (mbridge_has_mirrors(ctx.xbridge->mbridge)) {
3437 if (ctx.xin->resubmit_stats) {
3438 mirror_update_stats(ctx.xbridge->mbridge, xout->mirrors,
3439 ctx.xin->resubmit_stats->n_packets,
3440 ctx.xin->resubmit_stats->n_bytes);
3442 if (ctx.xin->xcache) {
3443 struct xc_entry *entry;
3445 entry = xlate_cache_add_entry(ctx.xin->xcache, XC_MIRROR);
3446 entry->u.mirror.mbridge = mbridge_ref(ctx.xbridge->mbridge);
3447 entry->u.mirror.mirrors = xout->mirrors;
3451 if (ctx.xbridge->netflow) {
3452 /* Only update netflow if we don't have controller flow. We don't
3453 * report NetFlow expiration messages for such facets because they
3454 * are just part of the control logic for the network, not real
3456 if (ofpacts_len == 0
3457 || ofpacts->type != OFPACT_CONTROLLER
3458 || ofpact_next(ofpacts) < ofpact_end(ofpacts, ofpacts_len)) {
3459 if (ctx.xin->resubmit_stats) {
3460 netflow_flow_update(ctx.xbridge->netflow, flow,
3461 xout->nf_output_iface,
3462 ctx.xin->resubmit_stats);
3464 if (ctx.xin->xcache) {
3465 struct xc_entry *entry;
3467 entry = xlate_cache_add_entry(ctx.xin->xcache, XC_NETFLOW);
3468 entry->u.nf.netflow = netflow_ref(ctx.xbridge->netflow);
3469 entry->u.nf.flow = xmemdup(flow, sizeof *flow);
3470 entry->u.nf.iface = xout->nf_output_iface;
3475 ofpbuf_uninit(&ctx.stack);
3476 ofpbuf_uninit(&ctx.action_set);
3478 /* Clear the metadata and register wildcard masks, because we won't
3479 * use non-header fields as part of the cache. */
3480 flow_wildcards_clear_non_packet_fields(wc);
3482 /* ICMPv4 and ICMPv6 have 8-bit "type" and "code" fields. struct flow uses
3483 * the low 8 bits of the 16-bit tp_src and tp_dst members to represent
3484 * these fields. The datapath interface, on the other hand, represents
3485 * them with just 8 bits each. This means that if the high 8 bits of the
3486 * masks for these fields somehow become set, then they will get chopped
3487 * off by a round trip through the datapath, and revalidation will spot
3488 * that as an inconsistency and delete the flow. Avoid the problem here by
3489 * making sure that only the low 8 bits of either field can be unwildcarded
3493 wc->masks.tp_src &= htons(UINT8_MAX);
3494 wc->masks.tp_dst &= htons(UINT8_MAX);
3498 /* Sends 'packet' out 'ofport'.
3499 * May modify 'packet'.
3500 * Returns 0 if successful, otherwise a positive errno value. */
3502 xlate_send_packet(const struct ofport_dpif *ofport, struct ofpbuf *packet)
3504 struct xport *xport;
3505 struct ofpact_output output;
3508 ofpact_init(&output.ofpact, OFPACT_OUTPUT, sizeof output);
3509 /* Use OFPP_NONE as the in_port to avoid special packet processing. */
3510 flow_extract(packet, NULL, &flow);
3511 flow.in_port.ofp_port = OFPP_NONE;
3513 ovs_rwlock_rdlock(&xlate_rwlock);
3514 xport = xport_lookup(ofport);
3516 ovs_rwlock_unlock(&xlate_rwlock);
3519 output.port = xport->ofp_port;
3521 ovs_rwlock_unlock(&xlate_rwlock);
3523 return ofproto_dpif_execute_actions(xport->xbridge->ofproto, &flow, NULL,
3524 &output.ofpact, sizeof output,
3528 struct xlate_cache *
3529 xlate_cache_new(void)
3531 struct xlate_cache *xcache = xmalloc(sizeof *xcache);
3533 ofpbuf_init(&xcache->entries, 512);
3537 static struct xc_entry *
3538 xlate_cache_add_entry(struct xlate_cache *xcache, enum xc_type type)
3540 struct xc_entry *entry;
3542 entry = ofpbuf_put_zeros(&xcache->entries, sizeof *entry);
3549 xlate_cache_netdev(struct xc_entry *entry, const struct dpif_flow_stats *stats)
3551 if (entry->u.dev.tx) {
3552 netdev_vport_inc_tx(entry->u.dev.tx, stats);
3554 if (entry->u.dev.rx) {
3555 netdev_vport_inc_rx(entry->u.dev.rx, stats);
3557 if (entry->u.dev.bfd) {
3558 bfd_account_rx(entry->u.dev.bfd, stats);
3563 xlate_cache_normal(struct ofproto_dpif *ofproto, struct flow *flow, int vlan)
3565 struct xbridge *xbridge;
3566 struct xbundle *xbundle;
3567 struct flow_wildcards wc;
3569 xbridge = xbridge_lookup(ofproto);
3574 xbundle = lookup_input_bundle(xbridge, flow->in_port.ofp_port, false,
3580 update_learning_table(xbridge, flow, &wc, vlan, xbundle);
3583 /* Push stats and perform side effects of flow translation. */
3585 xlate_push_stats(struct xlate_cache *xcache, bool may_learn,
3586 const struct dpif_flow_stats *stats)
3588 struct xc_entry *entry;
3589 struct ofpbuf entries = xcache->entries;
3591 XC_ENTRY_FOR_EACH (entry, entries, xcache) {
3592 switch (entry->type) {
3594 rule_dpif_credit_stats(entry->u.rule, stats);
3597 bond_account(entry->u.bond.bond, entry->u.bond.flow,
3598 entry->u.bond.vid, stats->n_bytes);
3601 xlate_cache_netdev(entry, stats);
3604 netflow_flow_update(entry->u.nf.netflow, entry->u.nf.flow,
3605 entry->u.nf.iface, stats);
3608 mirror_update_stats(entry->u.mirror.mbridge,
3609 entry->u.mirror.mirrors,
3610 stats->n_packets, stats->n_bytes);
3614 struct rule_dpif *rule = entry->u.learn.rule;
3616 /* Reset the modified time for a rule that is equivalent to
3617 * the currently cached rule. If the rule is not the exact
3618 * rule we have cached, update the reference that we have. */
3619 entry->u.learn.rule = ofproto_dpif_refresh_rule(rule);
3623 xlate_cache_normal(entry->u.normal.ofproto, entry->u.normal.flow,
3624 entry->u.normal.vlan);
3626 case XC_FIN_TIMEOUT:
3627 xlate_fin_timeout__(entry->u.fin.rule, stats->tcp_flags,
3628 entry->u.fin.idle, entry->u.fin.hard);
3631 group_dpif_credit_stats(entry->u.group.group, entry->u.group.bucket,
3641 xlate_dev_unref(struct xc_entry *entry)
3643 if (entry->u.dev.tx) {
3644 netdev_close(entry->u.dev.tx);
3646 if (entry->u.dev.rx) {
3647 netdev_close(entry->u.dev.rx);
3649 if (entry->u.dev.bfd) {
3650 bfd_unref(entry->u.dev.bfd);
3655 xlate_cache_clear_netflow(struct netflow *netflow, struct flow *flow)
3657 netflow_expire(netflow, flow);
3658 netflow_flow_clear(netflow, flow);
3659 netflow_unref(netflow);
3664 xlate_cache_clear(struct xlate_cache *xcache)
3666 struct xc_entry *entry;
3667 struct ofpbuf entries;
3673 XC_ENTRY_FOR_EACH (entry, entries, xcache) {
3674 switch (entry->type) {
3676 rule_dpif_unref(entry->u.rule);
3679 free(entry->u.bond.flow);
3680 bond_unref(entry->u.bond.bond);
3683 xlate_dev_unref(entry);
3686 xlate_cache_clear_netflow(entry->u.nf.netflow, entry->u.nf.flow);
3689 mbridge_unref(entry->u.mirror.mbridge);
3692 /* 'u.learn.rule' is the learned rule. */
3693 rule_dpif_unref(entry->u.learn.rule);
3696 free(entry->u.normal.flow);
3698 case XC_FIN_TIMEOUT:
3699 /* 'u.fin.rule' is always already held as a XC_RULE, which
3700 * has already released it's reference above. */
3703 group_dpif_unref(entry->u.group.group);
3710 ofpbuf_clear(&xcache->entries);
3714 xlate_cache_delete(struct xlate_cache *xcache)
3716 xlate_cache_clear(xcache);
3717 ofpbuf_uninit(&xcache->entries);