1 /* Copyright (c) 2009, 2010, 2011, 2012, 2013 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-sflow.h"
46 #include "ofproto/ofproto-dpif.h"
47 #include "ofproto/ofproto-provider.h"
51 COVERAGE_DEFINE(xlate_actions);
53 VLOG_DEFINE_THIS_MODULE(ofproto_dpif_xlate);
55 /* Maximum depth of flow table recursion (due to resubmit actions) in a
56 * flow translation. */
57 #define MAX_RESUBMIT_RECURSION 64
59 /* Maximum number of resubmit actions in a flow translation, whether they are
60 * recursive or not. */
61 #define MAX_RESUBMITS (MAX_RESUBMIT_RECURSION * MAX_RESUBMIT_RECURSION)
63 struct ovs_rwlock xlate_rwlock = OVS_RWLOCK_INITIALIZER;
66 struct hmap_node hmap_node; /* Node in global 'xbridges' map. */
67 struct ofproto_dpif *ofproto; /* Key in global 'xbridges' map. */
69 struct list xbundles; /* Owned xbundles. */
70 struct hmap xports; /* Indexed by ofp_port. */
72 char *name; /* Name used in log messages. */
73 struct dpif *dpif; /* Datapath interface. */
74 struct mac_learning *ml; /* Mac learning handle. */
75 struct mbridge *mbridge; /* Mirroring. */
76 struct dpif_sflow *sflow; /* SFlow handle, or null. */
77 struct dpif_ipfix *ipfix; /* Ipfix handle, or null. */
78 struct stp *stp; /* STP or null if disabled. */
80 /* Special rules installed by ofproto-dpif. */
81 struct rule_dpif *miss_rule;
82 struct rule_dpif *no_packet_in_rule;
84 enum ofp_config_flags frag; /* Fragmentation handling. */
85 bool has_netflow; /* Bridge runs netflow? */
86 bool has_in_band; /* Bridge has in band control? */
87 bool forward_bpdu; /* Bridge forwards STP BPDUs? */
91 struct hmap_node hmap_node; /* In global 'xbundles' map. */
92 struct ofbundle *ofbundle; /* Key in global 'xbundles' map. */
94 struct list list_node; /* In parent 'xbridges' list. */
95 struct xbridge *xbridge; /* Parent xbridge. */
97 struct list xports; /* Contains "struct xport"s. */
99 char *name; /* Name used in log messages. */
100 struct bond *bond; /* Nonnull iff more than one port. */
101 struct lacp *lacp; /* LACP handle or null. */
103 enum port_vlan_mode vlan_mode; /* VLAN mode. */
104 int vlan; /* -1=trunk port, else a 12-bit VLAN ID. */
105 unsigned long *trunks; /* Bitmap of trunked VLANs, if 'vlan' == -1.
106 * NULL if all VLANs are trunked. */
107 bool use_priority_tags; /* Use 802.1p tag for frames in VLAN 0? */
108 bool floodable; /* No port has OFPUTIL_PC_NO_FLOOD set? */
112 struct hmap_node hmap_node; /* Node in global 'xports' map. */
113 struct ofport_dpif *ofport; /* Key in global 'xports map. */
115 struct hmap_node ofp_node; /* Node in parent xbridge 'xports' map. */
116 ofp_port_t ofp_port; /* Key in parent xbridge 'xports' map. */
118 odp_port_t odp_port; /* Datapath port number or ODPP_NONE. */
120 struct list bundle_node; /* In parent xbundle (if it exists). */
121 struct xbundle *xbundle; /* Parent xbundle or null. */
123 struct netdev *netdev; /* 'ofport''s netdev. */
125 struct xbridge *xbridge; /* Parent bridge. */
126 struct xport *peer; /* Patch port peer or null. */
128 enum ofputil_port_config config; /* OpenFlow port configuration. */
129 int stp_port_no; /* STP port number or -1 if not in use. */
131 struct hmap skb_priorities; /* Map of 'skb_priority_to_dscp's. */
133 bool may_enable; /* May be enabled in bonds. */
134 bool is_tunnel; /* Is a tunnel port. */
136 struct cfm *cfm; /* CFM handle or null. */
137 struct bfd *bfd; /* BFD handle or null. */
141 struct xlate_in *xin;
142 struct xlate_out *xout;
144 const struct xbridge *xbridge;
146 /* Flow at the last commit. */
147 struct flow base_flow;
149 /* Tunnel IP destination address as received. This is stored separately
150 * as the base_flow.tunnel is cleared on init to reflect the datapath
151 * behavior. Used to make sure not to send tunneled output to ourselves,
152 * which might lead to an infinite loop. This could happen easily
153 * if a tunnel is marked as 'ip_remote=flow', and the flow does not
154 * actually set the tun_dst field. */
155 ovs_be32 orig_tunnel_ip_dst;
157 /* Stack for the push and pop actions. Each stack element is of type
158 * "union mf_subvalue". */
159 union mf_subvalue init_stack[1024 / sizeof(union mf_subvalue)];
162 /* The rule that we are currently translating, or NULL. */
163 struct rule_dpif *rule;
165 int mpls_depth_delta; /* Delta of the mpls stack depth since
166 * actions were last committed.
167 * Must be between -1 and 1 inclusive. */
168 ovs_be32 pre_push_mpls_lse; /* Used to record the top-most MPLS LSE
169 * prior to an mpls_push so that it may be
170 * used for a subsequent mpls_pop. */
172 /* Resubmit statistics, via xlate_table_action(). */
173 int recurse; /* Current resubmit nesting depth. */
174 int resubmits; /* Total number of resubmits. */
176 uint32_t orig_skb_priority; /* Priority when packet arrived. */
177 uint8_t table_id; /* OpenFlow table ID where flow was found. */
178 uint32_t sflow_n_outputs; /* Number of output ports. */
179 odp_port_t sflow_odp_port; /* Output port for composing sFlow action. */
180 uint16_t user_cookie_offset;/* Used for user_action_cookie fixup. */
181 bool exit; /* No further actions should be processed. */
183 /* OpenFlow 1.1+ action set.
185 * 'action_set' accumulates "struct ofpact"s added by OFPACT_WRITE_ACTIONS.
186 * When translation is otherwise complete, ofpacts_execute_action_set()
187 * converts it to a set of "struct ofpact"s that can be translated into
188 * datapath actions. */
189 struct ofpbuf action_set; /* Action set. */
190 uint64_t action_set_stub[1024 / 8];
193 /* A controller may use OFPP_NONE as the ingress port to indicate that
194 * it did not arrive on a "real" port. 'ofpp_none_bundle' exists for
195 * when an input bundle is needed for validation (e.g., mirroring or
196 * OFPP_NORMAL processing). It is not connected to an 'ofproto' or have
197 * any 'port' structs, so care must be taken when dealing with it.
198 * The bundle's name and vlan mode are initialized in lookup_input_bundle() */
199 static struct xbundle ofpp_none_bundle;
201 /* Node in 'xport''s 'skb_priorities' map. Used to maintain a map from
202 * 'priority' (the datapath's term for QoS queue) to the dscp bits which all
203 * traffic egressing the 'ofport' with that priority should be marked with. */
204 struct skb_priority_to_dscp {
205 struct hmap_node hmap_node; /* Node in 'ofport_dpif''s 'skb_priorities'. */
206 uint32_t skb_priority; /* Priority of this queue (see struct flow). */
208 uint8_t dscp; /* DSCP bits to mark outgoing traffic with. */
211 static struct hmap xbridges = HMAP_INITIALIZER(&xbridges);
212 static struct hmap xbundles = HMAP_INITIALIZER(&xbundles);
213 static struct hmap xports = HMAP_INITIALIZER(&xports);
215 static bool may_receive(const struct xport *, struct xlate_ctx *);
216 static void do_xlate_actions(const struct ofpact *, size_t ofpacts_len,
218 static void xlate_actions__(struct xlate_in *, struct xlate_out *)
219 OVS_REQ_RDLOCK(xlate_rwlock);
220 static void xlate_normal(struct xlate_ctx *);
221 static void xlate_report(struct xlate_ctx *, const char *);
222 static void xlate_table_action(struct xlate_ctx *, ofp_port_t in_port,
223 uint8_t table_id, bool may_packet_in);
224 static bool input_vid_is_valid(uint16_t vid, struct xbundle *, bool warn);
225 static uint16_t input_vid_to_vlan(const struct xbundle *, uint16_t vid);
226 static void output_normal(struct xlate_ctx *, const struct xbundle *,
228 static void compose_output_action(struct xlate_ctx *, ofp_port_t ofp_port);
230 static struct xbridge *xbridge_lookup(const struct ofproto_dpif *);
231 static struct xbundle *xbundle_lookup(const struct ofbundle *);
232 static struct xport *xport_lookup(const struct ofport_dpif *);
233 static struct xport *get_ofp_port(const struct xbridge *, ofp_port_t ofp_port);
234 static struct skb_priority_to_dscp *get_skb_priority(const struct xport *,
235 uint32_t skb_priority);
236 static void clear_skb_priorities(struct xport *);
237 static bool dscp_from_skb_priority(const struct xport *, uint32_t skb_priority,
241 xlate_ofproto_set(struct ofproto_dpif *ofproto, const char *name,
242 struct dpif *dpif, struct rule_dpif *miss_rule,
243 struct rule_dpif *no_packet_in_rule,
244 const struct mac_learning *ml, struct stp *stp,
245 const struct mbridge *mbridge,
246 const struct dpif_sflow *sflow,
247 const struct dpif_ipfix *ipfix, enum ofp_config_flags frag,
248 bool forward_bpdu, bool has_in_band, bool has_netflow)
250 struct xbridge *xbridge = xbridge_lookup(ofproto);
253 xbridge = xzalloc(sizeof *xbridge);
254 xbridge->ofproto = ofproto;
256 hmap_insert(&xbridges, &xbridge->hmap_node, hash_pointer(ofproto, 0));
257 hmap_init(&xbridge->xports);
258 list_init(&xbridge->xbundles);
261 if (xbridge->ml != ml) {
262 mac_learning_unref(xbridge->ml);
263 xbridge->ml = mac_learning_ref(ml);
266 if (xbridge->mbridge != mbridge) {
267 mbridge_unref(xbridge->mbridge);
268 xbridge->mbridge = mbridge_ref(mbridge);
271 if (xbridge->sflow != sflow) {
272 dpif_sflow_unref(xbridge->sflow);
273 xbridge->sflow = dpif_sflow_ref(sflow);
276 if (xbridge->ipfix != ipfix) {
277 dpif_ipfix_unref(xbridge->ipfix);
278 xbridge->ipfix = dpif_ipfix_ref(ipfix);
281 if (xbridge->stp != stp) {
282 stp_unref(xbridge->stp);
283 xbridge->stp = stp_ref(stp);
287 xbridge->name = xstrdup(name);
289 xbridge->dpif = dpif;
290 xbridge->forward_bpdu = forward_bpdu;
291 xbridge->has_in_band = has_in_band;
292 xbridge->has_netflow = has_netflow;
293 xbridge->frag = frag;
294 xbridge->miss_rule = miss_rule;
295 xbridge->no_packet_in_rule = no_packet_in_rule;
299 xlate_remove_ofproto(struct ofproto_dpif *ofproto)
301 struct xbridge *xbridge = xbridge_lookup(ofproto);
302 struct xbundle *xbundle, *next_xbundle;
303 struct xport *xport, *next_xport;
309 HMAP_FOR_EACH_SAFE (xport, next_xport, ofp_node, &xbridge->xports) {
310 xlate_ofport_remove(xport->ofport);
313 LIST_FOR_EACH_SAFE (xbundle, next_xbundle, list_node, &xbridge->xbundles) {
314 xlate_bundle_remove(xbundle->ofbundle);
317 hmap_remove(&xbridges, &xbridge->hmap_node);
318 mac_learning_unref(xbridge->ml);
319 mbridge_unref(xbridge->mbridge);
320 dpif_sflow_unref(xbridge->sflow);
321 dpif_ipfix_unref(xbridge->ipfix);
322 stp_unref(xbridge->stp);
323 hmap_destroy(&xbridge->xports);
329 xlate_bundle_set(struct ofproto_dpif *ofproto, struct ofbundle *ofbundle,
330 const char *name, enum port_vlan_mode vlan_mode, int vlan,
331 unsigned long *trunks, bool use_priority_tags,
332 const struct bond *bond, const struct lacp *lacp,
335 struct xbundle *xbundle = xbundle_lookup(ofbundle);
338 xbundle = xzalloc(sizeof *xbundle);
339 xbundle->ofbundle = ofbundle;
340 xbundle->xbridge = xbridge_lookup(ofproto);
342 hmap_insert(&xbundles, &xbundle->hmap_node, hash_pointer(ofbundle, 0));
343 list_insert(&xbundle->xbridge->xbundles, &xbundle->list_node);
344 list_init(&xbundle->xports);
347 ovs_assert(xbundle->xbridge);
350 xbundle->name = xstrdup(name);
352 xbundle->vlan_mode = vlan_mode;
353 xbundle->vlan = vlan;
354 xbundle->trunks = trunks;
355 xbundle->use_priority_tags = use_priority_tags;
356 xbundle->floodable = floodable;
358 if (xbundle->bond != bond) {
359 bond_unref(xbundle->bond);
360 xbundle->bond = bond_ref(bond);
363 if (xbundle->lacp != lacp) {
364 lacp_unref(xbundle->lacp);
365 xbundle->lacp = lacp_ref(lacp);
370 xlate_bundle_remove(struct ofbundle *ofbundle)
372 struct xbundle *xbundle = xbundle_lookup(ofbundle);
373 struct xport *xport, *next;
379 LIST_FOR_EACH_SAFE (xport, next, bundle_node, &xbundle->xports) {
380 list_remove(&xport->bundle_node);
381 xport->xbundle = NULL;
384 hmap_remove(&xbundles, &xbundle->hmap_node);
385 list_remove(&xbundle->list_node);
386 bond_unref(xbundle->bond);
387 lacp_unref(xbundle->lacp);
393 xlate_ofport_set(struct ofproto_dpif *ofproto, struct ofbundle *ofbundle,
394 struct ofport_dpif *ofport, ofp_port_t ofp_port,
395 odp_port_t odp_port, const struct netdev *netdev,
396 const struct cfm *cfm, const struct bfd *bfd,
397 struct ofport_dpif *peer, int stp_port_no,
398 const struct ofproto_port_queue *qdscp_list, size_t n_qdscp,
399 enum ofputil_port_config config, bool is_tunnel,
402 struct xport *xport = xport_lookup(ofport);
406 xport = xzalloc(sizeof *xport);
407 xport->ofport = ofport;
408 xport->xbridge = xbridge_lookup(ofproto);
409 xport->ofp_port = ofp_port;
411 hmap_init(&xport->skb_priorities);
412 hmap_insert(&xports, &xport->hmap_node, hash_pointer(ofport, 0));
413 hmap_insert(&xport->xbridge->xports, &xport->ofp_node,
414 hash_ofp_port(xport->ofp_port));
417 ovs_assert(xport->ofp_port == ofp_port);
419 xport->config = config;
420 xport->stp_port_no = stp_port_no;
421 xport->is_tunnel = is_tunnel;
422 xport->may_enable = may_enable;
423 xport->odp_port = odp_port;
425 if (xport->netdev != netdev) {
426 netdev_close(xport->netdev);
427 xport->netdev = netdev_ref(netdev);
430 if (xport->cfm != cfm) {
431 cfm_unref(xport->cfm);
432 xport->cfm = cfm_ref(cfm);
435 if (xport->bfd != bfd) {
436 bfd_unref(xport->bfd);
437 xport->bfd = bfd_ref(bfd);
441 xport->peer->peer = NULL;
443 xport->peer = xport_lookup(peer);
445 xport->peer->peer = xport;
448 if (xport->xbundle) {
449 list_remove(&xport->bundle_node);
451 xport->xbundle = xbundle_lookup(ofbundle);
452 if (xport->xbundle) {
453 list_insert(&xport->xbundle->xports, &xport->bundle_node);
456 clear_skb_priorities(xport);
457 for (i = 0; i < n_qdscp; i++) {
458 struct skb_priority_to_dscp *pdscp;
459 uint32_t skb_priority;
461 if (dpif_queue_to_priority(xport->xbridge->dpif, qdscp_list[i].queue,
466 pdscp = xmalloc(sizeof *pdscp);
467 pdscp->skb_priority = skb_priority;
468 pdscp->dscp = (qdscp_list[i].dscp << 2) & IP_DSCP_MASK;
469 hmap_insert(&xport->skb_priorities, &pdscp->hmap_node,
470 hash_int(pdscp->skb_priority, 0));
475 xlate_ofport_remove(struct ofport_dpif *ofport)
477 struct xport *xport = xport_lookup(ofport);
484 xport->peer->peer = NULL;
488 if (xport->xbundle) {
489 list_remove(&xport->bundle_node);
492 clear_skb_priorities(xport);
493 hmap_destroy(&xport->skb_priorities);
495 hmap_remove(&xports, &xport->hmap_node);
496 hmap_remove(&xport->xbridge->xports, &xport->ofp_node);
498 netdev_close(xport->netdev);
499 cfm_unref(xport->cfm);
500 bfd_unref(xport->bfd);
504 /* Given a datpath, packet, and flow metadata ('backer', 'packet', and 'key'
505 * respectively), populates 'flow' with the result of odp_flow_key_to_flow().
506 * Optionally, if nonnull, populates 'fitnessp' with the fitness of 'flow' as
507 * returned by odp_flow_key_to_flow(). Also, optionally populates 'ofproto'
508 * with the ofproto_dpif, and 'odp_in_port' with the datapath in_port, that
509 * 'packet' ingressed.
511 * If 'ofproto' is nonnull, requires 'flow''s in_port to exist. Otherwise sets
512 * 'flow''s in_port to OFPP_NONE.
514 * This function does post-processing on data returned from
515 * odp_flow_key_to_flow() to help make VLAN splinters transparent to the rest
516 * of the upcall processing logic. In particular, if the extracted in_port is
517 * a VLAN splinter port, it replaces flow->in_port by the "real" port, sets
518 * flow->vlan_tci correctly for the VLAN of the VLAN splinter port, and pushes
519 * a VLAN header onto 'packet' (if it is nonnull).
521 * Similarly, this function also includes some logic to help with tunnels. It
522 * may modify 'flow' as necessary to make the tunneling implementation
523 * transparent to the upcall processing logic.
525 * Returns 0 if successful, ENODEV if the parsed flow has no associated ofport,
526 * or some other positive errno if there are other problems. */
528 xlate_receive(const struct dpif_backer *backer, struct ofpbuf *packet,
529 const struct nlattr *key, size_t key_len,
530 struct flow *flow, enum odp_key_fitness *fitnessp,
531 struct ofproto_dpif **ofproto, odp_port_t *odp_in_port)
533 enum odp_key_fitness fitness;
534 const struct xport *xport;
537 ovs_rwlock_rdlock(&xlate_rwlock);
538 fitness = odp_flow_key_to_flow(key, key_len, flow);
539 if (fitness == ODP_FIT_ERROR) {
545 *odp_in_port = flow->in_port.odp_port;
548 xport = xport_lookup(tnl_port_should_receive(flow)
549 ? tnl_port_receive(flow)
550 : odp_port_to_ofport(backer, flow->in_port.odp_port));
552 flow->in_port.ofp_port = xport ? xport->ofp_port : OFPP_NONE;
557 if (vsp_adjust_flow(xport->xbridge->ofproto, flow)) {
559 /* Make the packet resemble the flow, so that it gets sent to
560 * an OpenFlow controller properly, so that it looks correct
561 * for sFlow, and so that flow_extract() will get the correct
562 * vlan_tci if it is called on 'packet'.
564 * The allocated space inside 'packet' probably also contains
565 * 'key', that is, both 'packet' and 'key' are probably part of
566 * a struct dpif_upcall (see the large comment on that
567 * structure definition), so pushing data on 'packet' is in
568 * general not a good idea since it could overwrite 'key' or
569 * free it as a side effect. However, it's OK in this special
570 * case because we know that 'packet' is inside a Netlink
571 * attribute: pushing 4 bytes will just overwrite the 4-byte
572 * "struct nlattr", which is fine since we don't need that
574 eth_push_vlan(packet, flow->vlan_tci);
576 /* We can't reproduce 'key' from 'flow'. */
577 fitness = fitness == ODP_FIT_PERFECT ? ODP_FIT_TOO_MUCH : fitness;
582 *ofproto = xport->xbridge->ofproto;
589 ovs_rwlock_unlock(&xlate_rwlock);
593 static struct xbridge *
594 xbridge_lookup(const struct ofproto_dpif *ofproto)
596 struct xbridge *xbridge;
602 HMAP_FOR_EACH_IN_BUCKET (xbridge, hmap_node, hash_pointer(ofproto, 0),
604 if (xbridge->ofproto == ofproto) {
611 static struct xbundle *
612 xbundle_lookup(const struct ofbundle *ofbundle)
614 struct xbundle *xbundle;
620 HMAP_FOR_EACH_IN_BUCKET (xbundle, hmap_node, hash_pointer(ofbundle, 0),
622 if (xbundle->ofbundle == ofbundle) {
629 static struct xport *
630 xport_lookup(const struct ofport_dpif *ofport)
638 HMAP_FOR_EACH_IN_BUCKET (xport, hmap_node, hash_pointer(ofport, 0),
640 if (xport->ofport == ofport) {
647 static struct stp_port *
648 xport_get_stp_port(const struct xport *xport)
650 return xport->xbridge->stp && xport->stp_port_no != -1
651 ? stp_get_port(xport->xbridge->stp, xport->stp_port_no)
655 static enum stp_state
656 xport_stp_learn_state(const struct xport *xport)
658 struct stp_port *sp = xport_get_stp_port(xport);
659 return stp_learn_in_state(sp ? stp_port_get_state(sp) : STP_DISABLED);
663 xport_stp_forward_state(const struct xport *xport)
665 struct stp_port *sp = xport_get_stp_port(xport);
666 return stp_forward_in_state(sp ? stp_port_get_state(sp) : STP_DISABLED);
669 /* Returns true if STP should process 'flow'. Sets fields in 'wc' that
670 * were used to make the determination.*/
672 stp_should_process_flow(const struct flow *flow, struct flow_wildcards *wc)
674 memset(&wc->masks.dl_dst, 0xff, sizeof wc->masks.dl_dst);
675 return eth_addr_equals(flow->dl_dst, eth_addr_stp);
679 stp_process_packet(const struct xport *xport, const struct ofpbuf *packet)
681 struct stp_port *sp = xport_get_stp_port(xport);
682 struct ofpbuf payload = *packet;
683 struct eth_header *eth = payload.data;
685 /* Sink packets on ports that have STP disabled when the bridge has
687 if (!sp || stp_port_get_state(sp) == STP_DISABLED) {
691 /* Trim off padding on payload. */
692 if (payload.size > ntohs(eth->eth_type) + ETH_HEADER_LEN) {
693 payload.size = ntohs(eth->eth_type) + ETH_HEADER_LEN;
696 if (ofpbuf_try_pull(&payload, ETH_HEADER_LEN + LLC_HEADER_LEN)) {
697 stp_received_bpdu(sp, payload.data, payload.size);
701 static struct xport *
702 get_ofp_port(const struct xbridge *xbridge, ofp_port_t ofp_port)
706 HMAP_FOR_EACH_IN_BUCKET (xport, ofp_node, hash_ofp_port(ofp_port),
708 if (xport->ofp_port == ofp_port) {
716 ofp_port_to_odp_port(const struct xbridge *xbridge, ofp_port_t ofp_port)
718 const struct xport *xport = get_ofp_port(xbridge, ofp_port);
719 return xport ? xport->odp_port : ODPP_NONE;
723 xbundle_trunks_vlan(const struct xbundle *bundle, uint16_t vlan)
725 return (bundle->vlan_mode != PORT_VLAN_ACCESS
726 && (!bundle->trunks || bitmap_is_set(bundle->trunks, vlan)));
730 xbundle_includes_vlan(const struct xbundle *xbundle, uint16_t vlan)
732 return vlan == xbundle->vlan || xbundle_trunks_vlan(xbundle, vlan);
736 xbundle_mirror_out(const struct xbridge *xbridge, struct xbundle *xbundle)
738 return xbundle != &ofpp_none_bundle
739 ? mirror_bundle_out(xbridge->mbridge, xbundle->ofbundle)
744 xbundle_mirror_src(const struct xbridge *xbridge, struct xbundle *xbundle)
746 return xbundle != &ofpp_none_bundle
747 ? mirror_bundle_src(xbridge->mbridge, xbundle->ofbundle)
752 xbundle_mirror_dst(const struct xbridge *xbridge, struct xbundle *xbundle)
754 return xbundle != &ofpp_none_bundle
755 ? mirror_bundle_dst(xbridge->mbridge, xbundle->ofbundle)
759 static struct xbundle *
760 lookup_input_bundle(const struct xbridge *xbridge, ofp_port_t in_port,
761 bool warn, struct xport **in_xportp)
765 /* Find the port and bundle for the received packet. */
766 xport = get_ofp_port(xbridge, in_port);
770 if (xport && xport->xbundle) {
771 return xport->xbundle;
774 /* Special-case OFPP_NONE, which a controller may use as the ingress
775 * port for traffic that it is sourcing. */
776 if (in_port == OFPP_NONE) {
777 ofpp_none_bundle.name = "OFPP_NONE";
778 ofpp_none_bundle.vlan_mode = PORT_VLAN_TRUNK;
779 return &ofpp_none_bundle;
782 /* Odd. A few possible reasons here:
784 * - We deleted a port but there are still a few packets queued up
787 * - Someone externally added a port (e.g. "ovs-dpctl add-if") that
788 * we don't know about.
790 * - The ofproto client didn't configure the port as part of a bundle.
791 * This is particularly likely to happen if a packet was received on the
792 * port after it was created, but before the client had a chance to
793 * configure its bundle.
796 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
798 VLOG_WARN_RL(&rl, "bridge %s: received packet on unknown "
799 "port %"PRIu16, xbridge->name, in_port);
805 add_mirror_actions(struct xlate_ctx *ctx, const struct flow *orig_flow)
807 const struct xbridge *xbridge = ctx->xbridge;
808 mirror_mask_t mirrors;
809 struct xbundle *in_xbundle;
813 mirrors = ctx->xout->mirrors;
814 ctx->xout->mirrors = 0;
816 in_xbundle = lookup_input_bundle(xbridge, orig_flow->in_port.ofp_port,
817 ctx->xin->packet != NULL, NULL);
821 mirrors |= xbundle_mirror_src(xbridge, in_xbundle);
823 /* Drop frames on bundles reserved for mirroring. */
824 if (xbundle_mirror_out(xbridge, in_xbundle)) {
825 if (ctx->xin->packet != NULL) {
826 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
827 VLOG_WARN_RL(&rl, "bridge %s: dropping packet received on port "
828 "%s, which is reserved exclusively for mirroring",
829 ctx->xbridge->name, in_xbundle->name);
831 ofpbuf_clear(&ctx->xout->odp_actions);
836 vid = vlan_tci_to_vid(orig_flow->vlan_tci);
837 if (!input_vid_is_valid(vid, in_xbundle, ctx->xin->packet != NULL)) {
840 vlan = input_vid_to_vlan(in_xbundle, vid);
846 /* Restore the original packet before adding the mirror actions. */
847 ctx->xin->flow = *orig_flow;
850 mirror_mask_t dup_mirrors;
851 struct ofbundle *out;
852 unsigned long *vlans;
857 has_mirror = mirror_get(xbridge->mbridge, mirror_mask_ffs(mirrors) - 1,
858 &vlans, &dup_mirrors, &out, &out_vlan);
859 ovs_assert(has_mirror);
862 ctx->xout->wc.masks.vlan_tci |= htons(VLAN_CFI | VLAN_VID_MASK);
864 vlan_mirrored = !vlans || bitmap_is_set(vlans, vlan);
867 if (!vlan_mirrored) {
868 mirrors = zero_rightmost_1bit(mirrors);
872 mirrors &= ~dup_mirrors;
873 ctx->xout->mirrors |= dup_mirrors;
875 struct xbundle *out_xbundle = xbundle_lookup(out);
877 output_normal(ctx, out_xbundle, vlan);
879 } else if (vlan != out_vlan
880 && !eth_addr_is_reserved(orig_flow->dl_dst)) {
881 struct xbundle *xbundle;
883 LIST_FOR_EACH (xbundle, list_node, &xbridge->xbundles) {
884 if (xbundle_includes_vlan(xbundle, out_vlan)
885 && !xbundle_mirror_out(xbridge, xbundle)) {
886 output_normal(ctx, xbundle, out_vlan);
893 /* Given 'vid', the VID obtained from the 802.1Q header that was received as
894 * part of a packet (specify 0 if there was no 802.1Q header), and 'in_xbundle',
895 * the bundle on which the packet was received, returns the VLAN to which the
898 * Both 'vid' and the return value are in the range 0...4095. */
900 input_vid_to_vlan(const struct xbundle *in_xbundle, uint16_t vid)
902 switch (in_xbundle->vlan_mode) {
903 case PORT_VLAN_ACCESS:
904 return in_xbundle->vlan;
907 case PORT_VLAN_TRUNK:
910 case PORT_VLAN_NATIVE_UNTAGGED:
911 case PORT_VLAN_NATIVE_TAGGED:
912 return vid ? vid : in_xbundle->vlan;
919 /* Checks whether a packet with the given 'vid' may ingress on 'in_xbundle'.
920 * If so, returns true. Otherwise, returns false and, if 'warn' is true, logs
923 * 'vid' should be the VID obtained from the 802.1Q header that was received as
924 * part of a packet (specify 0 if there was no 802.1Q header), in the range
927 input_vid_is_valid(uint16_t vid, struct xbundle *in_xbundle, bool warn)
929 /* Allow any VID on the OFPP_NONE port. */
930 if (in_xbundle == &ofpp_none_bundle) {
934 switch (in_xbundle->vlan_mode) {
935 case PORT_VLAN_ACCESS:
938 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
939 VLOG_WARN_RL(&rl, "dropping VLAN %"PRIu16" tagged "
940 "packet received on port %s configured as VLAN "
941 "%"PRIu16" access port", vid, in_xbundle->name,
948 case PORT_VLAN_NATIVE_UNTAGGED:
949 case PORT_VLAN_NATIVE_TAGGED:
951 /* Port must always carry its native VLAN. */
955 case PORT_VLAN_TRUNK:
956 if (!xbundle_includes_vlan(in_xbundle, vid)) {
958 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
959 VLOG_WARN_RL(&rl, "dropping VLAN %"PRIu16" packet "
960 "received on port %s not configured for trunking "
961 "VLAN %"PRIu16, vid, in_xbundle->name, vid);
973 /* Given 'vlan', the VLAN that a packet belongs to, and
974 * 'out_xbundle', a bundle on which the packet is to be output, returns the VID
975 * that should be included in the 802.1Q header. (If the return value is 0,
976 * then the 802.1Q header should only be included in the packet if there is a
979 * Both 'vlan' and the return value are in the range 0...4095. */
981 output_vlan_to_vid(const struct xbundle *out_xbundle, uint16_t vlan)
983 switch (out_xbundle->vlan_mode) {
984 case PORT_VLAN_ACCESS:
987 case PORT_VLAN_TRUNK:
988 case PORT_VLAN_NATIVE_TAGGED:
991 case PORT_VLAN_NATIVE_UNTAGGED:
992 return vlan == out_xbundle->vlan ? 0 : vlan;
1000 output_normal(struct xlate_ctx *ctx, const struct xbundle *out_xbundle,
1003 ovs_be16 *flow_tci = &ctx->xin->flow.vlan_tci;
1005 ovs_be16 tci, old_tci;
1006 struct xport *xport;
1008 vid = output_vlan_to_vid(out_xbundle, vlan);
1009 if (list_is_empty(&out_xbundle->xports)) {
1010 /* Partially configured bundle with no slaves. Drop the packet. */
1012 } else if (!out_xbundle->bond) {
1013 xport = CONTAINER_OF(list_front(&out_xbundle->xports), struct xport,
1016 struct ofport_dpif *ofport;
1018 ofport = bond_choose_output_slave(out_xbundle->bond, &ctx->xin->flow,
1019 &ctx->xout->wc, vid);
1020 xport = xport_lookup(ofport);
1023 /* No slaves enabled, so drop packet. */
1028 old_tci = *flow_tci;
1030 if (tci || out_xbundle->use_priority_tags) {
1031 tci |= *flow_tci & htons(VLAN_PCP_MASK);
1033 tci |= htons(VLAN_CFI);
1038 compose_output_action(ctx, xport->ofp_port);
1039 *flow_tci = old_tci;
1042 /* A VM broadcasts a gratuitous ARP to indicate that it has resumed after
1043 * migration. Older Citrix-patched Linux DomU used gratuitous ARP replies to
1044 * indicate this; newer upstream kernels use gratuitous ARP requests. */
1046 is_gratuitous_arp(const struct flow *flow, struct flow_wildcards *wc)
1048 if (flow->dl_type != htons(ETH_TYPE_ARP)) {
1052 memset(&wc->masks.dl_dst, 0xff, sizeof wc->masks.dl_dst);
1053 if (!eth_addr_is_broadcast(flow->dl_dst)) {
1057 memset(&wc->masks.nw_proto, 0xff, sizeof wc->masks.nw_proto);
1058 if (flow->nw_proto == ARP_OP_REPLY) {
1060 } else if (flow->nw_proto == ARP_OP_REQUEST) {
1061 memset(&wc->masks.nw_src, 0xff, sizeof wc->masks.nw_src);
1062 memset(&wc->masks.nw_dst, 0xff, sizeof wc->masks.nw_dst);
1064 return flow->nw_src == flow->nw_dst;
1070 /* Checks whether a MAC learning update is necessary for MAC learning table
1071 * 'ml' given that a packet matching 'flow' was received on 'in_xbundle' in
1074 * Most packets processed through the MAC learning table do not actually
1075 * change it in any way. This function requires only a read lock on the MAC
1076 * learning table, so it is much cheaper in this common case.
1078 * Keep the code here synchronized with that in update_learning_table__()
1081 is_mac_learning_update_needed(const struct mac_learning *ml,
1082 const struct flow *flow,
1083 struct flow_wildcards *wc,
1084 int vlan, struct xbundle *in_xbundle)
1085 OVS_REQ_RDLOCK(ml->rwlock)
1087 struct mac_entry *mac;
1089 if (!mac_learning_may_learn(ml, flow->dl_src, vlan)) {
1093 mac = mac_learning_lookup(ml, flow->dl_src, vlan);
1094 if (!mac || mac_entry_age(ml, mac)) {
1098 if (is_gratuitous_arp(flow, wc)) {
1099 /* We don't want to learn from gratuitous ARP packets that are
1100 * reflected back over bond slaves so we lock the learning table. */
1101 if (!in_xbundle->bond) {
1103 } else if (mac_entry_is_grat_arp_locked(mac)) {
1108 return mac->port.p != in_xbundle->ofbundle;
1112 /* Updates MAC learning table 'ml' given that a packet matching 'flow' was
1113 * received on 'in_xbundle' in 'vlan'.
1115 * This code repeats all the checks in is_mac_learning_update_needed() because
1116 * the lock was released between there and here and thus the MAC learning state
1117 * could have changed.
1119 * Keep the code here synchronized with that in is_mac_learning_update_needed()
1122 update_learning_table__(const struct xbridge *xbridge,
1123 const struct flow *flow, struct flow_wildcards *wc,
1124 int vlan, struct xbundle *in_xbundle)
1125 OVS_REQ_WRLOCK(xbridge->ml->rwlock)
1127 struct mac_entry *mac;
1129 if (!mac_learning_may_learn(xbridge->ml, flow->dl_src, vlan)) {
1133 mac = mac_learning_insert(xbridge->ml, flow->dl_src, vlan);
1134 if (is_gratuitous_arp(flow, wc)) {
1135 /* We don't want to learn from gratuitous ARP packets that are
1136 * reflected back over bond slaves so we lock the learning table. */
1137 if (!in_xbundle->bond) {
1138 mac_entry_set_grat_arp_lock(mac);
1139 } else if (mac_entry_is_grat_arp_locked(mac)) {
1144 if (mac->port.p != in_xbundle->ofbundle) {
1145 /* The log messages here could actually be useful in debugging,
1146 * so keep the rate limit relatively high. */
1147 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(30, 300);
1149 VLOG_DBG_RL(&rl, "bridge %s: learned that "ETH_ADDR_FMT" is "
1150 "on port %s in VLAN %d",
1151 xbridge->name, ETH_ADDR_ARGS(flow->dl_src),
1152 in_xbundle->name, vlan);
1154 mac->port.p = in_xbundle->ofbundle;
1155 mac_learning_changed(xbridge->ml);
1160 update_learning_table(const struct xbridge *xbridge,
1161 const struct flow *flow, struct flow_wildcards *wc,
1162 int vlan, struct xbundle *in_xbundle)
1166 /* Don't learn the OFPP_NONE port. */
1167 if (in_xbundle == &ofpp_none_bundle) {
1171 /* First try the common case: no change to MAC learning table. */
1172 ovs_rwlock_rdlock(&xbridge->ml->rwlock);
1173 need_update = is_mac_learning_update_needed(xbridge->ml, flow, wc, vlan,
1175 ovs_rwlock_unlock(&xbridge->ml->rwlock);
1178 /* Slow path: MAC learning table might need an update. */
1179 ovs_rwlock_wrlock(&xbridge->ml->rwlock);
1180 update_learning_table__(xbridge, flow, wc, vlan, in_xbundle);
1181 ovs_rwlock_unlock(&xbridge->ml->rwlock);
1185 /* Determines whether packets in 'flow' within 'xbridge' should be forwarded or
1186 * dropped. Returns true if they may be forwarded, false if they should be
1189 * 'in_port' must be the xport that corresponds to flow->in_port.
1190 * 'in_port' must be part of a bundle (e.g. in_port->bundle must be nonnull).
1192 * 'vlan' must be the VLAN that corresponds to flow->vlan_tci on 'in_port', as
1193 * returned by input_vid_to_vlan(). It must be a valid VLAN for 'in_port', as
1194 * checked by input_vid_is_valid().
1196 * May also add tags to '*tags', although the current implementation only does
1197 * so in one special case.
1200 is_admissible(struct xlate_ctx *ctx, struct xport *in_port,
1203 struct xbundle *in_xbundle = in_port->xbundle;
1204 const struct xbridge *xbridge = ctx->xbridge;
1205 struct flow *flow = &ctx->xin->flow;
1207 /* Drop frames for reserved multicast addresses
1208 * only if forward_bpdu option is absent. */
1209 if (!xbridge->forward_bpdu && eth_addr_is_reserved(flow->dl_dst)) {
1210 xlate_report(ctx, "packet has reserved destination MAC, dropping");
1214 if (in_xbundle->bond) {
1215 struct mac_entry *mac;
1217 switch (bond_check_admissibility(in_xbundle->bond, in_port->ofport,
1223 xlate_report(ctx, "bonding refused admissibility, dropping");
1226 case BV_DROP_IF_MOVED:
1227 ovs_rwlock_rdlock(&xbridge->ml->rwlock);
1228 mac = mac_learning_lookup(xbridge->ml, flow->dl_src, vlan);
1229 if (mac && mac->port.p != in_xbundle->ofbundle &&
1230 (!is_gratuitous_arp(flow, &ctx->xout->wc)
1231 || mac_entry_is_grat_arp_locked(mac))) {
1232 ovs_rwlock_unlock(&xbridge->ml->rwlock);
1233 xlate_report(ctx, "SLB bond thinks this packet looped back, "
1237 ovs_rwlock_unlock(&xbridge->ml->rwlock);
1246 xlate_normal(struct xlate_ctx *ctx)
1248 struct flow_wildcards *wc = &ctx->xout->wc;
1249 struct flow *flow = &ctx->xin->flow;
1250 struct xbundle *in_xbundle;
1251 struct xport *in_port;
1252 struct mac_entry *mac;
1257 ctx->xout->has_normal = true;
1259 memset(&wc->masks.dl_src, 0xff, sizeof wc->masks.dl_src);
1260 memset(&wc->masks.dl_dst, 0xff, sizeof wc->masks.dl_dst);
1261 wc->masks.vlan_tci |= htons(VLAN_VID_MASK | VLAN_CFI);
1263 in_xbundle = lookup_input_bundle(ctx->xbridge, flow->in_port.ofp_port,
1264 ctx->xin->packet != NULL, &in_port);
1266 xlate_report(ctx, "no input bundle, dropping");
1270 /* Drop malformed frames. */
1271 if (flow->dl_type == htons(ETH_TYPE_VLAN) &&
1272 !(flow->vlan_tci & htons(VLAN_CFI))) {
1273 if (ctx->xin->packet != NULL) {
1274 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
1275 VLOG_WARN_RL(&rl, "bridge %s: dropping packet with partial "
1276 "VLAN tag received on port %s",
1277 ctx->xbridge->name, in_xbundle->name);
1279 xlate_report(ctx, "partial VLAN tag, dropping");
1283 /* Drop frames on bundles reserved for mirroring. */
1284 if (xbundle_mirror_out(ctx->xbridge, in_xbundle)) {
1285 if (ctx->xin->packet != NULL) {
1286 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
1287 VLOG_WARN_RL(&rl, "bridge %s: dropping packet received on port "
1288 "%s, which is reserved exclusively for mirroring",
1289 ctx->xbridge->name, in_xbundle->name);
1291 xlate_report(ctx, "input port is mirror output port, dropping");
1296 vid = vlan_tci_to_vid(flow->vlan_tci);
1297 if (!input_vid_is_valid(vid, in_xbundle, ctx->xin->packet != NULL)) {
1298 xlate_report(ctx, "disallowed VLAN VID for this input port, dropping");
1301 vlan = input_vid_to_vlan(in_xbundle, vid);
1303 /* Check other admissibility requirements. */
1304 if (in_port && !is_admissible(ctx, in_port, vlan)) {
1308 /* Learn source MAC. */
1309 if (ctx->xin->may_learn) {
1310 update_learning_table(ctx->xbridge, flow, wc, vlan, in_xbundle);
1313 /* Determine output bundle. */
1314 ovs_rwlock_rdlock(&ctx->xbridge->ml->rwlock);
1315 mac = mac_learning_lookup(ctx->xbridge->ml, flow->dl_dst, vlan);
1316 mac_port = mac ? mac->port.p : NULL;
1317 ovs_rwlock_unlock(&ctx->xbridge->ml->rwlock);
1320 struct xbundle *mac_xbundle = xbundle_lookup(mac_port);
1321 if (mac_xbundle && mac_xbundle != in_xbundle) {
1322 xlate_report(ctx, "forwarding to learned port");
1323 output_normal(ctx, mac_xbundle, vlan);
1324 } else if (!mac_xbundle) {
1325 xlate_report(ctx, "learned port is unknown, dropping");
1327 xlate_report(ctx, "learned port is input port, dropping");
1330 struct xbundle *xbundle;
1332 xlate_report(ctx, "no learned MAC for destination, flooding");
1333 LIST_FOR_EACH (xbundle, list_node, &ctx->xbridge->xbundles) {
1334 if (xbundle != in_xbundle
1335 && xbundle_includes_vlan(xbundle, vlan)
1336 && xbundle->floodable
1337 && !xbundle_mirror_out(ctx->xbridge, xbundle)) {
1338 output_normal(ctx, xbundle, vlan);
1341 ctx->xout->nf_output_iface = NF_OUT_FLOOD;
1345 /* Compose SAMPLE action for sFlow or IPFIX. The given probability is
1346 * the number of packets out of UINT32_MAX to sample. The given
1347 * cookie is passed back in the callback for each sampled packet.
1350 compose_sample_action(const struct xbridge *xbridge,
1351 struct ofpbuf *odp_actions,
1352 const struct flow *flow,
1353 const uint32_t probability,
1354 const union user_action_cookie *cookie,
1355 const size_t cookie_size)
1357 size_t sample_offset, actions_offset;
1358 odp_port_t odp_port;
1362 sample_offset = nl_msg_start_nested(odp_actions, OVS_ACTION_ATTR_SAMPLE);
1364 nl_msg_put_u32(odp_actions, OVS_SAMPLE_ATTR_PROBABILITY, probability);
1366 actions_offset = nl_msg_start_nested(odp_actions, OVS_SAMPLE_ATTR_ACTIONS);
1368 odp_port = ofp_port_to_odp_port(xbridge, flow->in_port.ofp_port);
1369 pid = dpif_port_get_pid(xbridge->dpif, odp_port);
1370 cookie_offset = odp_put_userspace_action(pid, cookie, cookie_size, odp_actions);
1372 nl_msg_end_nested(odp_actions, actions_offset);
1373 nl_msg_end_nested(odp_actions, sample_offset);
1374 return cookie_offset;
1378 compose_sflow_cookie(const struct xbridge *xbridge, ovs_be16 vlan_tci,
1379 odp_port_t odp_port, unsigned int n_outputs,
1380 union user_action_cookie *cookie)
1384 cookie->type = USER_ACTION_COOKIE_SFLOW;
1385 cookie->sflow.vlan_tci = vlan_tci;
1387 /* See http://www.sflow.org/sflow_version_5.txt (search for "Input/output
1388 * port information") for the interpretation of cookie->output. */
1389 switch (n_outputs) {
1391 /* 0x40000000 | 256 means "packet dropped for unknown reason". */
1392 cookie->sflow.output = 0x40000000 | 256;
1396 ifindex = dpif_sflow_odp_port_to_ifindex(xbridge->sflow, odp_port);
1398 cookie->sflow.output = ifindex;
1403 /* 0x80000000 means "multiple output ports. */
1404 cookie->sflow.output = 0x80000000 | n_outputs;
1409 /* Compose SAMPLE action for sFlow bridge sampling. */
1411 compose_sflow_action(const struct xbridge *xbridge,
1412 struct ofpbuf *odp_actions,
1413 const struct flow *flow,
1414 odp_port_t odp_port)
1416 uint32_t probability;
1417 union user_action_cookie cookie;
1419 if (!xbridge->sflow || flow->in_port.ofp_port == OFPP_NONE) {
1423 probability = dpif_sflow_get_probability(xbridge->sflow);
1424 compose_sflow_cookie(xbridge, htons(0), odp_port,
1425 odp_port == ODPP_NONE ? 0 : 1, &cookie);
1427 return compose_sample_action(xbridge, odp_actions, flow, probability,
1428 &cookie, sizeof cookie.sflow);
1432 compose_flow_sample_cookie(uint16_t probability, uint32_t collector_set_id,
1433 uint32_t obs_domain_id, uint32_t obs_point_id,
1434 union user_action_cookie *cookie)
1436 cookie->type = USER_ACTION_COOKIE_FLOW_SAMPLE;
1437 cookie->flow_sample.probability = probability;
1438 cookie->flow_sample.collector_set_id = collector_set_id;
1439 cookie->flow_sample.obs_domain_id = obs_domain_id;
1440 cookie->flow_sample.obs_point_id = obs_point_id;
1444 compose_ipfix_cookie(union user_action_cookie *cookie)
1446 cookie->type = USER_ACTION_COOKIE_IPFIX;
1449 /* Compose SAMPLE action for IPFIX bridge sampling. */
1451 compose_ipfix_action(const struct xbridge *xbridge,
1452 struct ofpbuf *odp_actions,
1453 const struct flow *flow)
1455 uint32_t probability;
1456 union user_action_cookie cookie;
1458 if (!xbridge->ipfix || flow->in_port.ofp_port == OFPP_NONE) {
1462 probability = dpif_ipfix_get_bridge_exporter_probability(xbridge->ipfix);
1463 compose_ipfix_cookie(&cookie);
1465 compose_sample_action(xbridge, odp_actions, flow, probability,
1466 &cookie, sizeof cookie.ipfix);
1469 /* SAMPLE action for sFlow must be first action in any given list of
1470 * actions. At this point we do not have all information required to
1471 * build it. So try to build sample action as complete as possible. */
1473 add_sflow_action(struct xlate_ctx *ctx)
1475 ctx->user_cookie_offset = compose_sflow_action(ctx->xbridge,
1476 &ctx->xout->odp_actions,
1477 &ctx->xin->flow, ODPP_NONE);
1478 ctx->sflow_odp_port = 0;
1479 ctx->sflow_n_outputs = 0;
1482 /* SAMPLE action for IPFIX must be 1st or 2nd action in any given list
1483 * of actions, eventually after the SAMPLE action for sFlow. */
1485 add_ipfix_action(struct xlate_ctx *ctx)
1487 compose_ipfix_action(ctx->xbridge, &ctx->xout->odp_actions,
1491 /* Fix SAMPLE action according to data collected while composing ODP actions.
1492 * We need to fix SAMPLE actions OVS_SAMPLE_ATTR_ACTIONS attribute, i.e. nested
1493 * USERSPACE action's user-cookie which is required for sflow. */
1495 fix_sflow_action(struct xlate_ctx *ctx)
1497 const struct flow *base = &ctx->base_flow;
1498 union user_action_cookie *cookie;
1500 if (!ctx->user_cookie_offset) {
1504 cookie = ofpbuf_at(&ctx->xout->odp_actions, ctx->user_cookie_offset,
1505 sizeof cookie->sflow);
1506 ovs_assert(cookie->type == USER_ACTION_COOKIE_SFLOW);
1508 compose_sflow_cookie(ctx->xbridge, base->vlan_tci,
1509 ctx->sflow_odp_port, ctx->sflow_n_outputs, cookie);
1512 static enum slow_path_reason
1513 process_special(struct xlate_ctx *ctx, const struct flow *flow,
1514 const struct xport *xport, const struct ofpbuf *packet)
1516 struct flow_wildcards *wc = &ctx->xout->wc;
1517 const struct xbridge *xbridge = ctx->xbridge;
1521 } else if (xport->cfm && cfm_should_process_flow(xport->cfm, flow, wc)) {
1523 cfm_process_heartbeat(xport->cfm, packet);
1526 } else if (xport->bfd && bfd_should_process_flow(xport->bfd, flow, wc)) {
1528 bfd_process_packet(xport->bfd, flow, packet);
1531 } else if (xport->xbundle && xport->xbundle->lacp
1532 && flow->dl_type == htons(ETH_TYPE_LACP)) {
1534 lacp_process_packet(xport->xbundle->lacp, xport->ofport, packet);
1537 } else if (xbridge->stp && stp_should_process_flow(flow, wc)) {
1539 stp_process_packet(xport, packet);
1548 compose_output_action__(struct xlate_ctx *ctx, ofp_port_t ofp_port,
1551 const struct xport *xport = get_ofp_port(ctx->xbridge, ofp_port);
1552 struct flow_wildcards *wc = &ctx->xout->wc;
1553 struct flow *flow = &ctx->xin->flow;
1554 ovs_be16 flow_vlan_tci;
1555 uint32_t flow_pkt_mark;
1556 uint8_t flow_nw_tos;
1557 odp_port_t out_port, odp_port;
1560 /* If 'struct flow' gets additional metadata, we'll need to zero it out
1561 * before traversing a patch port. */
1562 BUILD_ASSERT_DECL(FLOW_WC_SEQ == 21);
1565 xlate_report(ctx, "Nonexistent output port");
1567 } else if (xport->config & OFPUTIL_PC_NO_FWD) {
1568 xlate_report(ctx, "OFPPC_NO_FWD set, skipping output");
1570 } else if (check_stp && !xport_stp_forward_state(xport)) {
1571 xlate_report(ctx, "STP not in forwarding state, skipping output");
1575 if (mbridge_has_mirrors(ctx->xbridge->mbridge) && xport->xbundle) {
1576 ctx->xout->mirrors |= xbundle_mirror_dst(xport->xbundle->xbridge,
1581 const struct xport *peer = xport->peer;
1582 struct flow old_flow = ctx->xin->flow;
1583 enum slow_path_reason special;
1585 ctx->xbridge = peer->xbridge;
1586 flow->in_port.ofp_port = peer->ofp_port;
1587 flow->metadata = htonll(0);
1588 memset(&flow->tunnel, 0, sizeof flow->tunnel);
1589 memset(flow->regs, 0, sizeof flow->regs);
1591 special = process_special(ctx, &ctx->xin->flow, peer,
1594 ctx->xout->slow |= special;
1595 } else if (may_receive(peer, ctx)) {
1596 if (xport_stp_forward_state(peer)) {
1597 xlate_table_action(ctx, flow->in_port.ofp_port, 0, true);
1599 /* Forwarding is disabled by STP. Let OFPP_NORMAL and the
1600 * learning action look at the packet, then drop it. */
1601 struct flow old_base_flow = ctx->base_flow;
1602 size_t old_size = ctx->xout->odp_actions.size;
1603 mirror_mask_t old_mirrors = ctx->xout->mirrors;
1604 xlate_table_action(ctx, flow->in_port.ofp_port, 0, true);
1605 ctx->xout->mirrors = old_mirrors;
1606 ctx->base_flow = old_base_flow;
1607 ctx->xout->odp_actions.size = old_size;
1611 ctx->xin->flow = old_flow;
1612 ctx->xbridge = xport->xbridge;
1614 if (ctx->xin->resubmit_stats) {
1615 netdev_vport_inc_tx(xport->netdev, ctx->xin->resubmit_stats);
1616 netdev_vport_inc_rx(peer->netdev, ctx->xin->resubmit_stats);
1622 flow_vlan_tci = flow->vlan_tci;
1623 flow_pkt_mark = flow->pkt_mark;
1624 flow_nw_tos = flow->nw_tos;
1626 if (dscp_from_skb_priority(xport, flow->skb_priority, &dscp)) {
1627 wc->masks.nw_tos |= IP_ECN_MASK;
1628 flow->nw_tos &= ~IP_DSCP_MASK;
1629 flow->nw_tos |= dscp;
1632 if (xport->is_tunnel) {
1633 /* Save tunnel metadata so that changes made due to
1634 * the Logical (tunnel) Port are not visible for any further
1635 * matches, while explicit set actions on tunnel metadata are.
1637 struct flow_tnl flow_tnl = flow->tunnel;
1638 odp_port = tnl_port_send(xport->ofport, flow, &ctx->xout->wc);
1639 if (odp_port == ODPP_NONE) {
1640 xlate_report(ctx, "Tunneling decided against output");
1641 goto out; /* restore flow_nw_tos */
1643 if (flow->tunnel.ip_dst == ctx->orig_tunnel_ip_dst) {
1644 xlate_report(ctx, "Not tunneling to our own address");
1645 goto out; /* restore flow_nw_tos */
1647 if (ctx->xin->resubmit_stats) {
1648 netdev_vport_inc_tx(xport->netdev, ctx->xin->resubmit_stats);
1650 out_port = odp_port;
1651 commit_odp_tunnel_action(flow, &ctx->base_flow,
1652 &ctx->xout->odp_actions);
1653 flow->tunnel = flow_tnl; /* Restore tunnel metadata */
1655 ofp_port_t vlandev_port;
1657 odp_port = xport->odp_port;
1658 if (ofproto_has_vlan_splinters(ctx->xbridge->ofproto)) {
1659 wc->masks.vlan_tci |= htons(VLAN_VID_MASK | VLAN_CFI);
1661 vlandev_port = vsp_realdev_to_vlandev(ctx->xbridge->ofproto, ofp_port,
1663 if (vlandev_port == ofp_port) {
1664 out_port = odp_port;
1666 out_port = ofp_port_to_odp_port(ctx->xbridge, vlandev_port);
1667 flow->vlan_tci = htons(0);
1671 if (out_port != ODPP_NONE) {
1672 ctx->xout->slow |= commit_odp_actions(flow, &ctx->base_flow,
1673 &ctx->xout->odp_actions,
1675 &ctx->mpls_depth_delta);
1676 nl_msg_put_odp_port(&ctx->xout->odp_actions, OVS_ACTION_ATTR_OUTPUT,
1679 ctx->sflow_odp_port = odp_port;
1680 ctx->sflow_n_outputs++;
1681 ctx->xout->nf_output_iface = ofp_port;
1686 flow->vlan_tci = flow_vlan_tci;
1687 flow->pkt_mark = flow_pkt_mark;
1688 flow->nw_tos = flow_nw_tos;
1692 compose_output_action(struct xlate_ctx *ctx, ofp_port_t ofp_port)
1694 compose_output_action__(ctx, ofp_port, true);
1698 xlate_recursively(struct xlate_ctx *ctx, struct rule_dpif *rule)
1700 struct rule_dpif *old_rule = ctx->rule;
1701 struct rule_actions *actions;
1703 if (ctx->xin->resubmit_stats) {
1704 rule_dpif_credit_stats(rule, ctx->xin->resubmit_stats);
1710 actions = rule_dpif_get_actions(rule);
1711 do_xlate_actions(actions->ofpacts, actions->ofpacts_len, ctx);
1712 rule_actions_unref(actions);
1713 ctx->rule = old_rule;
1718 xlate_table_action(struct xlate_ctx *ctx,
1719 ofp_port_t in_port, uint8_t table_id, bool may_packet_in)
1721 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
1723 if (ctx->recurse >= MAX_RESUBMIT_RECURSION) {
1724 VLOG_ERR_RL(&rl, "resubmit actions recursed over %d times",
1725 MAX_RESUBMIT_RECURSION);
1726 } else if (ctx->resubmits >= MAX_RESUBMITS) {
1727 VLOG_ERR_RL(&rl, "over %d resubmit actions", MAX_RESUBMITS);
1728 } else if (ctx->xout->odp_actions.size > UINT16_MAX) {
1729 VLOG_ERR_RL(&rl, "resubmits yielded over 64 kB of actions");
1730 } else if (ctx->stack.size >= 65536) {
1731 VLOG_ERR_RL(&rl, "resubmits yielded over 64 kB of stack");
1733 struct rule_dpif *rule;
1734 ofp_port_t old_in_port = ctx->xin->flow.in_port.ofp_port;
1735 uint8_t old_table_id = ctx->table_id;
1737 ctx->table_id = table_id;
1739 /* Look up a flow with 'in_port' as the input port. Then restore the
1740 * original input port (otherwise OFPP_NORMAL and OFPP_IN_PORT will
1741 * have surprising behavior). */
1742 ctx->xin->flow.in_port.ofp_port = in_port;
1743 rule_dpif_lookup_in_table(ctx->xbridge->ofproto,
1744 &ctx->xin->flow, &ctx->xout->wc,
1746 ctx->xin->flow.in_port.ofp_port = old_in_port;
1748 if (ctx->xin->resubmit_hook) {
1749 ctx->xin->resubmit_hook(ctx->xin, rule, ctx->recurse);
1752 if (!rule && may_packet_in) {
1753 struct xport *xport;
1756 * check if table configuration flags
1757 * OFPTC_TABLE_MISS_CONTROLLER, default.
1758 * OFPTC_TABLE_MISS_CONTINUE,
1759 * OFPTC_TABLE_MISS_DROP
1760 * When OF1.0, OFPTC_TABLE_MISS_CONTINUE is used. What to do? */
1761 xport = get_ofp_port(ctx->xbridge, ctx->xin->flow.in_port.ofp_port);
1762 choose_miss_rule(xport ? xport->config : 0,
1763 ctx->xbridge->miss_rule,
1764 ctx->xbridge->no_packet_in_rule, &rule);
1767 xlate_recursively(ctx, rule);
1768 rule_dpif_unref(rule);
1771 ctx->table_id = old_table_id;
1779 xlate_ofpact_resubmit(struct xlate_ctx *ctx,
1780 const struct ofpact_resubmit *resubmit)
1785 in_port = resubmit->in_port;
1786 if (in_port == OFPP_IN_PORT) {
1787 in_port = ctx->xin->flow.in_port.ofp_port;
1790 table_id = resubmit->table_id;
1791 if (table_id == 255) {
1792 table_id = ctx->table_id;
1795 xlate_table_action(ctx, in_port, table_id, false);
1799 flood_packets(struct xlate_ctx *ctx, bool all)
1801 const struct xport *xport;
1803 HMAP_FOR_EACH (xport, ofp_node, &ctx->xbridge->xports) {
1804 if (xport->ofp_port == ctx->xin->flow.in_port.ofp_port) {
1809 compose_output_action__(ctx, xport->ofp_port, false);
1810 } else if (!(xport->config & OFPUTIL_PC_NO_FLOOD)) {
1811 compose_output_action(ctx, xport->ofp_port);
1815 ctx->xout->nf_output_iface = NF_OUT_FLOOD;
1819 execute_controller_action(struct xlate_ctx *ctx, int len,
1820 enum ofp_packet_in_reason reason,
1821 uint16_t controller_id)
1823 struct ofproto_packet_in *pin;
1824 struct ofpbuf *packet;
1827 ctx->xout->slow |= SLOW_CONTROLLER;
1828 if (!ctx->xin->packet) {
1832 packet = ofpbuf_clone(ctx->xin->packet);
1834 key.skb_priority = 0;
1836 memset(&key.tunnel, 0, sizeof key.tunnel);
1838 ctx->xout->slow |= commit_odp_actions(&ctx->xin->flow, &ctx->base_flow,
1839 &ctx->xout->odp_actions,
1841 &ctx->mpls_depth_delta);
1843 odp_execute_actions(NULL, packet, &key, ctx->xout->odp_actions.data,
1844 ctx->xout->odp_actions.size, NULL, NULL);
1846 pin = xmalloc(sizeof *pin);
1847 pin->up.packet_len = packet->size;
1848 pin->up.packet = ofpbuf_steal_data(packet);
1849 pin->up.reason = reason;
1850 pin->up.table_id = ctx->table_id;
1851 pin->up.cookie = (ctx->rule
1852 ? rule_dpif_get_flow_cookie(ctx->rule)
1855 flow_get_metadata(&ctx->xin->flow, &pin->up.fmd);
1857 pin->controller_id = controller_id;
1858 pin->send_len = len;
1859 pin->generated_by_table_miss = (ctx->rule
1860 && rule_dpif_is_table_miss(ctx->rule));
1861 ofproto_dpif_send_packet_in(ctx->xbridge->ofproto, pin);
1862 ofpbuf_delete(packet);
1866 compose_mpls_push_action(struct xlate_ctx *ctx, ovs_be16 eth_type)
1868 struct flow_wildcards *wc = &ctx->xout->wc;
1869 struct flow *flow = &ctx->xin->flow;
1871 ovs_assert(eth_type_mpls(eth_type));
1873 /* If mpls_depth_delta is negative then an MPLS POP action has been
1874 * composed and the resulting MPLS label stack is unknown. This means
1875 * an MPLS PUSH action can't be composed as it needs to know either the
1876 * top-most MPLS LSE to use as a template for the new MPLS LSE, or that
1877 * there is no MPLS label stack present. Thus, stop processing.
1879 * If mpls_depth_delta is positive then an MPLS PUSH action has been
1880 * composed and no further MPLS PUSH action may be performed without
1881 * losing MPLS LSE and ether type information held in xtx->xin->flow.
1882 * Thus, stop processing.
1884 * If the MPLS LSE of the flow and base_flow differ then the MPLS LSE
1885 * has been updated. Performing a MPLS PUSH action may be would result in
1886 * losing MPLS LSE and ether type information held in xtx->xin->flow.
1887 * Thus, stop processing.
1889 * It is planned that in the future this case will be handled
1890 * by recirculation */
1891 if (ctx->mpls_depth_delta ||
1892 ctx->xin->flow.mpls_lse != ctx->base_flow.mpls_lse) {
1896 memset(&wc->masks.mpls_lse, 0xff, sizeof wc->masks.mpls_lse);
1898 ctx->pre_push_mpls_lse = ctx->xin->flow.mpls_lse;
1900 if (eth_type_mpls(ctx->xin->flow.dl_type)) {
1901 flow->mpls_lse &= ~htonl(MPLS_BOS_MASK);
1906 if (flow->dl_type == htons(ETH_TYPE_IPV6)) {
1907 label = htonl(0x2); /* IPV6 Explicit Null. */
1909 label = htonl(0x0); /* IPV4 Explicit Null. */
1911 wc->masks.nw_tos |= IP_DSCP_MASK;
1912 wc->masks.nw_ttl = 0xff;
1913 tc = (flow->nw_tos & IP_DSCP_MASK) >> 2;
1914 ttl = flow->nw_ttl ? flow->nw_ttl : 0x40;
1915 flow->mpls_lse = set_mpls_lse_values(ttl, tc, 1, label);
1917 flow->dl_type = eth_type;
1918 ctx->mpls_depth_delta++;
1924 compose_mpls_pop_action(struct xlate_ctx *ctx, ovs_be16 eth_type)
1926 struct flow_wildcards *wc = &ctx->xout->wc;
1928 if (!eth_type_mpls(ctx->xin->flow.dl_type)) {
1932 /* If mpls_depth_delta is negative then an MPLS POP action has been
1933 * composed. Performing another MPLS POP action
1934 * would result in losing ether type that results from
1935 * the already composed MPLS POP. Thus, stop processing.
1937 * It is planned that in the future this case will be handled
1938 * by recirculation */
1939 if (ctx->mpls_depth_delta < 0) {
1943 memset(&wc->masks.mpls_lse, 0xff, sizeof wc->masks.mpls_lse);
1945 /* If mpls_depth_delta is positive then an MPLS PUSH action has been
1946 * executed and the previous MPLS LSE saved in ctx->pre_push_mpls_lse. The
1947 * flow's MPLS LSE should be restored to that value to allow any
1948 * subsequent actions that update of the LSE to be executed correctly.
1950 if (ctx->mpls_depth_delta > 0) {
1951 ctx->xin->flow.mpls_lse = ctx->pre_push_mpls_lse;
1954 ctx->xin->flow.dl_type = eth_type;
1955 ctx->mpls_depth_delta--;
1961 compose_dec_ttl(struct xlate_ctx *ctx, struct ofpact_cnt_ids *ids)
1963 struct flow *flow = &ctx->xin->flow;
1965 if (!is_ip_any(flow)) {
1969 ctx->xout->wc.masks.nw_ttl = 0xff;
1970 if (flow->nw_ttl > 1) {
1976 for (i = 0; i < ids->n_controllers; i++) {
1977 execute_controller_action(ctx, UINT16_MAX, OFPR_INVALID_TTL,
1981 /* Stop processing for current table. */
1987 compose_set_mpls_ttl_action(struct xlate_ctx *ctx, uint8_t ttl)
1989 if (!eth_type_mpls(ctx->xin->flow.dl_type)) {
1993 /* If mpls_depth_delta is negative then an MPLS POP action has been
1994 * executed and the resulting MPLS label stack is unknown. This means
1995 * a SET MPLS TTL push action can't be executed as it needs to manipulate
1996 * the top-most MPLS LSE. Thus, stop processing.
1998 * It is planned that in the future this case will be handled
2001 if (ctx->mpls_depth_delta < 0) {
2005 ctx->xout->wc.masks.mpls_lse |= htonl(MPLS_TTL_MASK);
2006 set_mpls_lse_ttl(&ctx->xin->flow.mpls_lse, ttl);
2011 compose_dec_mpls_ttl_action(struct xlate_ctx *ctx)
2013 struct flow *flow = &ctx->xin->flow;
2014 uint8_t ttl = mpls_lse_to_ttl(flow->mpls_lse);
2015 struct flow_wildcards *wc = &ctx->xout->wc;
2017 memset(&wc->masks.mpls_lse, 0xff, sizeof wc->masks.mpls_lse);
2019 if (!eth_type_mpls(flow->dl_type)) {
2025 set_mpls_lse_ttl(&flow->mpls_lse, ttl);
2028 execute_controller_action(ctx, UINT16_MAX, OFPR_INVALID_TTL, 0);
2030 /* Stop processing for current table. */
2036 xlate_output_action(struct xlate_ctx *ctx,
2037 ofp_port_t port, uint16_t max_len, bool may_packet_in)
2039 ofp_port_t prev_nf_output_iface = ctx->xout->nf_output_iface;
2041 ctx->xout->nf_output_iface = NF_OUT_DROP;
2045 compose_output_action(ctx, ctx->xin->flow.in_port.ofp_port);
2048 xlate_table_action(ctx, ctx->xin->flow.in_port.ofp_port,
2055 flood_packets(ctx, false);
2058 flood_packets(ctx, true);
2060 case OFPP_CONTROLLER:
2061 execute_controller_action(ctx, max_len, OFPR_ACTION, 0);
2067 if (port != ctx->xin->flow.in_port.ofp_port) {
2068 compose_output_action(ctx, port);
2070 xlate_report(ctx, "skipping output to input port");
2075 if (prev_nf_output_iface == NF_OUT_FLOOD) {
2076 ctx->xout->nf_output_iface = NF_OUT_FLOOD;
2077 } else if (ctx->xout->nf_output_iface == NF_OUT_DROP) {
2078 ctx->xout->nf_output_iface = prev_nf_output_iface;
2079 } else if (prev_nf_output_iface != NF_OUT_DROP &&
2080 ctx->xout->nf_output_iface != NF_OUT_FLOOD) {
2081 ctx->xout->nf_output_iface = NF_OUT_MULTI;
2086 xlate_output_reg_action(struct xlate_ctx *ctx,
2087 const struct ofpact_output_reg *or)
2089 uint64_t port = mf_get_subfield(&or->src, &ctx->xin->flow);
2090 if (port <= UINT16_MAX) {
2091 union mf_subvalue value;
2093 memset(&value, 0xff, sizeof value);
2094 mf_write_subfield_flow(&or->src, &value, &ctx->xout->wc.masks);
2095 xlate_output_action(ctx, u16_to_ofp(port),
2096 or->max_len, false);
2101 xlate_enqueue_action(struct xlate_ctx *ctx,
2102 const struct ofpact_enqueue *enqueue)
2104 ofp_port_t ofp_port = enqueue->port;
2105 uint32_t queue_id = enqueue->queue;
2106 uint32_t flow_priority, priority;
2109 /* Translate queue to priority. */
2110 error = dpif_queue_to_priority(ctx->xbridge->dpif, queue_id, &priority);
2112 /* Fall back to ordinary output action. */
2113 xlate_output_action(ctx, enqueue->port, 0, false);
2117 /* Check output port. */
2118 if (ofp_port == OFPP_IN_PORT) {
2119 ofp_port = ctx->xin->flow.in_port.ofp_port;
2120 } else if (ofp_port == ctx->xin->flow.in_port.ofp_port) {
2124 /* Add datapath actions. */
2125 flow_priority = ctx->xin->flow.skb_priority;
2126 ctx->xin->flow.skb_priority = priority;
2127 compose_output_action(ctx, ofp_port);
2128 ctx->xin->flow.skb_priority = flow_priority;
2130 /* Update NetFlow output port. */
2131 if (ctx->xout->nf_output_iface == NF_OUT_DROP) {
2132 ctx->xout->nf_output_iface = ofp_port;
2133 } else if (ctx->xout->nf_output_iface != NF_OUT_FLOOD) {
2134 ctx->xout->nf_output_iface = NF_OUT_MULTI;
2139 xlate_set_queue_action(struct xlate_ctx *ctx, uint32_t queue_id)
2141 uint32_t skb_priority;
2143 if (!dpif_queue_to_priority(ctx->xbridge->dpif, queue_id, &skb_priority)) {
2144 ctx->xin->flow.skb_priority = skb_priority;
2146 /* Couldn't translate queue to a priority. Nothing to do. A warning
2147 * has already been logged. */
2152 slave_enabled_cb(ofp_port_t ofp_port, void *xbridge_)
2154 const struct xbridge *xbridge = xbridge_;
2165 case OFPP_CONTROLLER: /* Not supported by the bundle action. */
2168 port = get_ofp_port(xbridge, ofp_port);
2169 return port ? port->may_enable : false;
2174 xlate_bundle_action(struct xlate_ctx *ctx,
2175 const struct ofpact_bundle *bundle)
2179 port = bundle_execute(bundle, &ctx->xin->flow, &ctx->xout->wc,
2181 CONST_CAST(struct xbridge *, ctx->xbridge));
2182 if (bundle->dst.field) {
2183 nxm_reg_load(&bundle->dst, ofp_to_u16(port), &ctx->xin->flow,
2186 xlate_output_action(ctx, port, 0, false);
2191 xlate_learn_action(struct xlate_ctx *ctx,
2192 const struct ofpact_learn *learn)
2194 uint64_t ofpacts_stub[1024 / 8];
2195 struct ofputil_flow_mod fm;
2196 struct ofpbuf ofpacts;
2198 ctx->xout->has_learn = true;
2200 learn_mask(learn, &ctx->xout->wc);
2202 if (!ctx->xin->may_learn) {
2206 ofpbuf_use_stub(&ofpacts, ofpacts_stub, sizeof ofpacts_stub);
2207 learn_execute(learn, &ctx->xin->flow, &fm, &ofpacts);
2208 ofproto_dpif_flow_mod(ctx->xbridge->ofproto, &fm);
2209 ofpbuf_uninit(&ofpacts);
2213 xlate_fin_timeout(struct xlate_ctx *ctx,
2214 const struct ofpact_fin_timeout *oft)
2216 if (ctx->xin->tcp_flags & (TCP_FIN | TCP_RST) && ctx->rule) {
2217 rule_dpif_reduce_timeouts(ctx->rule, oft->fin_idle_timeout,
2218 oft->fin_hard_timeout);
2223 xlate_sample_action(struct xlate_ctx *ctx,
2224 const struct ofpact_sample *os)
2226 union user_action_cookie cookie;
2227 /* Scale the probability from 16-bit to 32-bit while representing
2228 * the same percentage. */
2229 uint32_t probability = (os->probability << 16) | os->probability;
2231 ctx->xout->slow |= commit_odp_actions(&ctx->xin->flow, &ctx->base_flow,
2232 &ctx->xout->odp_actions,
2234 &ctx->mpls_depth_delta);
2236 compose_flow_sample_cookie(os->probability, os->collector_set_id,
2237 os->obs_domain_id, os->obs_point_id, &cookie);
2238 compose_sample_action(ctx->xbridge, &ctx->xout->odp_actions, &ctx->xin->flow,
2239 probability, &cookie, sizeof cookie.flow_sample);
2243 may_receive(const struct xport *xport, struct xlate_ctx *ctx)
2245 if (xport->config & (eth_addr_equals(ctx->xin->flow.dl_dst, eth_addr_stp)
2246 ? OFPUTIL_PC_NO_RECV_STP
2247 : OFPUTIL_PC_NO_RECV)) {
2251 /* Only drop packets here if both forwarding and learning are
2252 * disabled. If just learning is enabled, we need to have
2253 * OFPP_NORMAL and the learning action have a look at the packet
2254 * before we can drop it. */
2255 if (!xport_stp_forward_state(xport) && !xport_stp_learn_state(xport)) {
2263 xlate_write_actions(struct xlate_ctx *ctx, const struct ofpact *a)
2265 struct ofpact_nest *on = ofpact_get_WRITE_ACTIONS(a);
2266 ofpbuf_put(&ctx->action_set, on->actions, ofpact_nest_get_action_len(on));
2267 ofpact_pad(&ctx->action_set);
2271 xlate_action_set(struct xlate_ctx *ctx)
2273 uint64_t action_list_stub[1024 / 64];
2274 struct ofpbuf action_list;
2276 ofpbuf_use_stub(&action_list, action_list_stub, sizeof action_list_stub);
2277 ofpacts_execute_action_set(&action_list, &ctx->action_set);
2278 do_xlate_actions(action_list.data, action_list.size, ctx);
2279 ofpbuf_uninit(&action_list);
2283 do_xlate_actions(const struct ofpact *ofpacts, size_t ofpacts_len,
2284 struct xlate_ctx *ctx)
2286 struct flow_wildcards *wc = &ctx->xout->wc;
2287 struct flow *flow = &ctx->xin->flow;
2288 const struct ofpact *a;
2290 /* dl_type already in the mask, not set below. */
2292 OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
2293 struct ofpact_controller *controller;
2294 const struct ofpact_metadata *metadata;
2302 xlate_output_action(ctx, ofpact_get_OUTPUT(a)->port,
2303 ofpact_get_OUTPUT(a)->max_len, true);
2307 /* XXX not yet implemented */
2310 case OFPACT_CONTROLLER:
2311 controller = ofpact_get_CONTROLLER(a);
2312 execute_controller_action(ctx, controller->max_len,
2314 controller->controller_id);
2317 case OFPACT_ENQUEUE:
2318 xlate_enqueue_action(ctx, ofpact_get_ENQUEUE(a));
2321 case OFPACT_SET_VLAN_VID:
2322 wc->masks.vlan_tci |= htons(VLAN_VID_MASK | VLAN_CFI);
2323 flow->vlan_tci &= ~htons(VLAN_VID_MASK);
2324 flow->vlan_tci |= (htons(ofpact_get_SET_VLAN_VID(a)->vlan_vid)
2328 case OFPACT_SET_VLAN_PCP:
2329 wc->masks.vlan_tci |= htons(VLAN_PCP_MASK | VLAN_CFI);
2330 flow->vlan_tci &= ~htons(VLAN_PCP_MASK);
2332 htons((ofpact_get_SET_VLAN_PCP(a)->vlan_pcp << VLAN_PCP_SHIFT)
2336 case OFPACT_STRIP_VLAN:
2337 memset(&wc->masks.vlan_tci, 0xff, sizeof wc->masks.vlan_tci);
2338 flow->vlan_tci = htons(0);
2341 case OFPACT_PUSH_VLAN:
2342 /* XXX 802.1AD(QinQ) */
2343 memset(&wc->masks.vlan_tci, 0xff, sizeof wc->masks.vlan_tci);
2344 flow->vlan_tci = htons(VLAN_CFI);
2347 case OFPACT_SET_ETH_SRC:
2348 memset(&wc->masks.dl_src, 0xff, sizeof wc->masks.dl_src);
2349 memcpy(flow->dl_src, ofpact_get_SET_ETH_SRC(a)->mac, ETH_ADDR_LEN);
2352 case OFPACT_SET_ETH_DST:
2353 memset(&wc->masks.dl_dst, 0xff, sizeof wc->masks.dl_dst);
2354 memcpy(flow->dl_dst, ofpact_get_SET_ETH_DST(a)->mac, ETH_ADDR_LEN);
2357 case OFPACT_SET_IPV4_SRC:
2358 if (flow->dl_type == htons(ETH_TYPE_IP)) {
2359 memset(&wc->masks.nw_src, 0xff, sizeof wc->masks.nw_src);
2360 flow->nw_src = ofpact_get_SET_IPV4_SRC(a)->ipv4;
2364 case OFPACT_SET_IPV4_DST:
2365 if (flow->dl_type == htons(ETH_TYPE_IP)) {
2366 memset(&wc->masks.nw_dst, 0xff, sizeof wc->masks.nw_dst);
2367 flow->nw_dst = ofpact_get_SET_IPV4_DST(a)->ipv4;
2371 case OFPACT_SET_IP_DSCP:
2372 if (is_ip_any(flow)) {
2373 wc->masks.nw_tos |= IP_DSCP_MASK;
2374 flow->nw_tos &= ~IP_DSCP_MASK;
2375 flow->nw_tos |= ofpact_get_SET_IP_DSCP(a)->dscp;
2379 case OFPACT_SET_IP_ECN:
2380 if (is_ip_any(flow)) {
2381 wc->masks.nw_tos |= IP_ECN_MASK;
2382 flow->nw_tos &= ~IP_ECN_MASK;
2383 flow->nw_tos |= ofpact_get_SET_IP_ECN(a)->ecn;
2387 case OFPACT_SET_IP_TTL:
2388 if (is_ip_any(flow)) {
2389 wc->masks.nw_ttl = 0xff;
2390 flow->nw_ttl = ofpact_get_SET_IP_TTL(a)->ttl;
2394 case OFPACT_SET_L4_SRC_PORT:
2395 if (is_ip_any(flow)) {
2396 memset(&wc->masks.nw_proto, 0xff, sizeof wc->masks.nw_proto);
2397 memset(&wc->masks.tp_src, 0xff, sizeof wc->masks.tp_src);
2398 flow->tp_src = htons(ofpact_get_SET_L4_SRC_PORT(a)->port);
2402 case OFPACT_SET_L4_DST_PORT:
2403 if (is_ip_any(flow)) {
2404 memset(&wc->masks.nw_proto, 0xff, sizeof wc->masks.nw_proto);
2405 memset(&wc->masks.tp_dst, 0xff, sizeof wc->masks.tp_dst);
2406 flow->tp_dst = htons(ofpact_get_SET_L4_DST_PORT(a)->port);
2410 case OFPACT_RESUBMIT:
2411 xlate_ofpact_resubmit(ctx, ofpact_get_RESUBMIT(a));
2414 case OFPACT_SET_TUNNEL:
2415 flow->tunnel.tun_id = htonll(ofpact_get_SET_TUNNEL(a)->tun_id);
2418 case OFPACT_SET_QUEUE:
2419 xlate_set_queue_action(ctx, ofpact_get_SET_QUEUE(a)->queue_id);
2422 case OFPACT_POP_QUEUE:
2423 flow->skb_priority = ctx->orig_skb_priority;
2426 case OFPACT_REG_MOVE:
2427 nxm_execute_reg_move(ofpact_get_REG_MOVE(a), flow, wc);
2430 case OFPACT_REG_LOAD:
2431 nxm_execute_reg_load(ofpact_get_REG_LOAD(a), flow, wc);
2434 case OFPACT_STACK_PUSH:
2435 nxm_execute_stack_push(ofpact_get_STACK_PUSH(a), flow, wc,
2439 case OFPACT_STACK_POP:
2440 nxm_execute_stack_pop(ofpact_get_STACK_POP(a), flow, wc,
2444 case OFPACT_PUSH_MPLS:
2445 if (compose_mpls_push_action(ctx,
2446 ofpact_get_PUSH_MPLS(a)->ethertype)) {
2451 case OFPACT_POP_MPLS:
2452 if (compose_mpls_pop_action(ctx,
2453 ofpact_get_POP_MPLS(a)->ethertype)) {
2458 case OFPACT_SET_MPLS_TTL:
2459 if (compose_set_mpls_ttl_action(ctx,
2460 ofpact_get_SET_MPLS_TTL(a)->ttl)) {
2465 case OFPACT_DEC_MPLS_TTL:
2466 if (compose_dec_mpls_ttl_action(ctx)) {
2471 case OFPACT_DEC_TTL:
2472 wc->masks.nw_ttl = 0xff;
2473 if (compose_dec_ttl(ctx, ofpact_get_DEC_TTL(a))) {
2479 /* Nothing to do. */
2482 case OFPACT_MULTIPATH:
2483 multipath_execute(ofpact_get_MULTIPATH(a), flow, wc);
2487 xlate_bundle_action(ctx, ofpact_get_BUNDLE(a));
2490 case OFPACT_OUTPUT_REG:
2491 xlate_output_reg_action(ctx, ofpact_get_OUTPUT_REG(a));
2495 xlate_learn_action(ctx, ofpact_get_LEARN(a));
2502 case OFPACT_FIN_TIMEOUT:
2503 memset(&wc->masks.nw_proto, 0xff, sizeof wc->masks.nw_proto);
2504 ctx->xout->has_fin_timeout = true;
2505 xlate_fin_timeout(ctx, ofpact_get_FIN_TIMEOUT(a));
2508 case OFPACT_CLEAR_ACTIONS:
2509 ofpbuf_clear(&ctx->action_set);
2512 case OFPACT_WRITE_ACTIONS:
2513 xlate_write_actions(ctx, a);
2516 case OFPACT_WRITE_METADATA:
2517 metadata = ofpact_get_WRITE_METADATA(a);
2518 flow->metadata &= ~metadata->mask;
2519 flow->metadata |= metadata->metadata & metadata->mask;
2523 /* Not implemented yet. */
2526 case OFPACT_GOTO_TABLE: {
2527 /* It is assumed that goto-table is the last action. */
2528 struct ofpact_goto_table *ogt = ofpact_get_GOTO_TABLE(a);
2530 ovs_assert(ctx->table_id < ogt->table_id);
2531 xlate_table_action(ctx, ctx->xin->flow.in_port.ofp_port,
2532 ogt->table_id, true);
2537 xlate_sample_action(ctx, ofpact_get_SAMPLE(a));
2544 xlate_in_init(struct xlate_in *xin, struct ofproto_dpif *ofproto,
2545 const struct flow *flow, struct rule_dpif *rule,
2546 uint8_t tcp_flags, const struct ofpbuf *packet)
2548 xin->ofproto = ofproto;
2550 xin->packet = packet;
2551 xin->may_learn = packet != NULL;
2553 xin->ofpacts = NULL;
2554 xin->ofpacts_len = 0;
2555 xin->tcp_flags = tcp_flags;
2556 xin->resubmit_hook = NULL;
2557 xin->report_hook = NULL;
2558 xin->resubmit_stats = NULL;
2562 xlate_out_uninit(struct xlate_out *xout)
2565 ofpbuf_uninit(&xout->odp_actions);
2569 /* Translates the 'ofpacts_len' bytes of "struct ofpact"s starting at 'ofpacts'
2570 * into datapath actions, using 'ctx', and discards the datapath actions. */
2572 xlate_actions_for_side_effects(struct xlate_in *xin)
2574 struct xlate_out xout;
2576 xlate_actions(xin, &xout);
2577 xlate_out_uninit(&xout);
2581 xlate_report(struct xlate_ctx *ctx, const char *s)
2583 if (ctx->xin->report_hook) {
2584 ctx->xin->report_hook(ctx->xin, s, ctx->recurse);
2589 xlate_out_copy(struct xlate_out *dst, const struct xlate_out *src)
2592 dst->slow = src->slow;
2593 dst->has_learn = src->has_learn;
2594 dst->has_normal = src->has_normal;
2595 dst->has_fin_timeout = src->has_fin_timeout;
2596 dst->nf_output_iface = src->nf_output_iface;
2597 dst->mirrors = src->mirrors;
2599 ofpbuf_use_stub(&dst->odp_actions, dst->odp_actions_stub,
2600 sizeof dst->odp_actions_stub);
2601 ofpbuf_put(&dst->odp_actions, src->odp_actions.data,
2602 src->odp_actions.size);
2605 /* Returns a reference to the sflow handled associated with ofproto, or NULL if
2606 * there is none. The caller is responsible for decrementing the results ref
2607 * count with dpif_sflow_unref(). */
2609 xlate_get_sflow(const struct ofproto_dpif *ofproto)
2611 struct dpif_sflow *sflow = NULL;
2612 struct xbridge *xbridge;
2614 ovs_rwlock_rdlock(&xlate_rwlock);
2615 xbridge = xbridge_lookup(ofproto);
2617 sflow = dpif_sflow_ref(xbridge->sflow);
2619 ovs_rwlock_unlock(&xlate_rwlock);
2624 /* Returns a reference to the ipfix handled associated with ofproto, or NULL if
2625 * there is none. The caller is responsible for decrementing the results ref
2626 * count with dpif_ipfix_unref(). */
2628 xlate_get_ipfix(const struct ofproto_dpif *ofproto)
2630 struct dpif_ipfix *ipfix = NULL;
2631 struct xbridge *xbridge;
2633 ovs_rwlock_rdlock(&xlate_rwlock);
2634 xbridge = xbridge_lookup(ofproto);
2636 ipfix = dpif_ipfix_ref(xbridge->ipfix);
2638 ovs_rwlock_unlock(&xlate_rwlock);
2643 static struct skb_priority_to_dscp *
2644 get_skb_priority(const struct xport *xport, uint32_t skb_priority)
2646 struct skb_priority_to_dscp *pdscp;
2649 hash = hash_int(skb_priority, 0);
2650 HMAP_FOR_EACH_IN_BUCKET (pdscp, hmap_node, hash, &xport->skb_priorities) {
2651 if (pdscp->skb_priority == skb_priority) {
2659 dscp_from_skb_priority(const struct xport *xport, uint32_t skb_priority,
2662 struct skb_priority_to_dscp *pdscp = get_skb_priority(xport, skb_priority);
2663 *dscp = pdscp ? pdscp->dscp : 0;
2664 return pdscp != NULL;
2668 clear_skb_priorities(struct xport *xport)
2670 struct skb_priority_to_dscp *pdscp, *next;
2672 HMAP_FOR_EACH_SAFE (pdscp, next, hmap_node, &xport->skb_priorities) {
2673 hmap_remove(&xport->skb_priorities, &pdscp->hmap_node);
2679 actions_output_to_local_port(const struct xlate_ctx *ctx)
2681 odp_port_t local_odp_port = ofp_port_to_odp_port(ctx->xbridge, OFPP_LOCAL);
2682 const struct nlattr *a;
2685 NL_ATTR_FOR_EACH_UNSAFE (a, left, ctx->xout->odp_actions.data,
2686 ctx->xout->odp_actions.size) {
2687 if (nl_attr_type(a) == OVS_ACTION_ATTR_OUTPUT
2688 && nl_attr_get_odp_port(a) == local_odp_port) {
2695 /* Thread safe call to xlate_actions__(). */
2697 xlate_actions(struct xlate_in *xin, struct xlate_out *xout)
2699 ovs_rwlock_rdlock(&xlate_rwlock);
2700 xlate_actions__(xin, xout);
2701 ovs_rwlock_unlock(&xlate_rwlock);
2704 /* Translates the 'ofpacts_len' bytes of "struct ofpacts" starting at 'ofpacts'
2705 * into datapath actions in 'odp_actions', using 'ctx'.
2707 * The caller must take responsibility for eventually freeing 'xout', with
2708 * xlate_out_uninit(). */
2710 xlate_actions__(struct xlate_in *xin, struct xlate_out *xout)
2711 OVS_REQ_RDLOCK(xlate_rwlock)
2713 struct flow_wildcards *wc = &xout->wc;
2714 struct flow *flow = &xin->flow;
2715 struct rule_dpif *rule = NULL;
2717 struct rule_actions *actions = NULL;
2718 enum slow_path_reason special;
2719 const struct ofpact *ofpacts;
2720 struct xport *in_port;
2721 struct flow orig_flow;
2722 struct xlate_ctx ctx;
2726 COVERAGE_INC(xlate_actions);
2728 /* Flow initialization rules:
2729 * - 'base_flow' must match the kernel's view of the packet at the
2730 * time that action processing starts. 'flow' represents any
2731 * transformations we wish to make through actions.
2732 * - By default 'base_flow' and 'flow' are the same since the input
2733 * packet matches the output before any actions are applied.
2734 * - When using VLAN splinters, 'base_flow''s VLAN is set to the value
2735 * of the received packet as seen by the kernel. If we later output
2736 * to another device without any modifications this will cause us to
2737 * insert a new tag since the original one was stripped off by the
2739 * - Tunnel metadata as received is retained in 'flow'. This allows
2740 * tunnel metadata matching also in later tables.
2741 * Since a kernel action for setting the tunnel metadata will only be
2742 * generated with actual tunnel output, changing the tunnel metadata
2743 * values in 'flow' (such as tun_id) will only have effect with a later
2744 * tunnel output action.
2745 * - Tunnel 'base_flow' is completely cleared since that is what the
2746 * kernel does. If we wish to maintain the original values an action
2747 * needs to be generated. */
2752 ctx.xout->has_learn = false;
2753 ctx.xout->has_normal = false;
2754 ctx.xout->has_fin_timeout = false;
2755 ctx.xout->nf_output_iface = NF_OUT_DROP;
2756 ctx.xout->mirrors = 0;
2757 ofpbuf_use_stub(&ctx.xout->odp_actions, ctx.xout->odp_actions_stub,
2758 sizeof ctx.xout->odp_actions_stub);
2759 ofpbuf_reserve(&ctx.xout->odp_actions, NL_A_U32_SIZE);
2761 ctx.xbridge = xbridge_lookup(xin->ofproto);
2766 ctx.rule = xin->rule;
2768 ctx.base_flow = *flow;
2769 memset(&ctx.base_flow.tunnel, 0, sizeof ctx.base_flow.tunnel);
2770 ctx.orig_tunnel_ip_dst = flow->tunnel.ip_dst;
2772 flow_wildcards_init_catchall(wc);
2773 memset(&wc->masks.in_port, 0xff, sizeof wc->masks.in_port);
2774 memset(&wc->masks.skb_priority, 0xff, sizeof wc->masks.skb_priority);
2775 memset(&wc->masks.dl_type, 0xff, sizeof wc->masks.dl_type);
2776 wc->masks.nw_frag |= FLOW_NW_FRAG_MASK;
2778 tnl_may_send = tnl_xlate_init(&ctx.base_flow, flow, wc);
2779 if (ctx.xbridge->has_netflow) {
2780 netflow_mask_wc(flow, wc);
2785 ctx.orig_skb_priority = flow->skb_priority;
2788 ctx.mpls_depth_delta = 0;
2790 if (!xin->ofpacts && !ctx.rule) {
2791 rule_dpif_lookup(ctx.xbridge->ofproto, flow, wc, &rule);
2792 if (ctx.xin->resubmit_stats) {
2793 rule_dpif_credit_stats(rule, ctx.xin->resubmit_stats);
2797 xout->fail_open = ctx.rule && rule_dpif_is_fail_open(ctx.rule);
2800 ofpacts = xin->ofpacts;
2801 ofpacts_len = xin->ofpacts_len;
2802 } else if (ctx.rule) {
2803 actions = rule_dpif_get_actions(ctx.rule);
2804 ofpacts = actions->ofpacts;
2805 ofpacts_len = actions->ofpacts_len;
2810 ofpbuf_use_stub(&ctx.stack, ctx.init_stack, sizeof ctx.init_stack);
2811 ofpbuf_use_stub(&ctx.action_set,
2812 ctx.action_set_stub, sizeof ctx.action_set_stub);
2814 if (mbridge_has_mirrors(ctx.xbridge->mbridge)) {
2815 /* Do this conditionally because the copy is expensive enough that it
2816 * shows up in profiles. */
2820 if (flow->nw_frag & FLOW_NW_FRAG_ANY) {
2821 switch (ctx.xbridge->frag) {
2822 case OFPC_FRAG_NORMAL:
2823 /* We must pretend that transport ports are unavailable. */
2824 flow->tp_src = ctx.base_flow.tp_src = htons(0);
2825 flow->tp_dst = ctx.base_flow.tp_dst = htons(0);
2828 case OFPC_FRAG_DROP:
2831 case OFPC_FRAG_REASM:
2834 case OFPC_FRAG_NX_MATCH:
2835 /* Nothing to do. */
2838 case OFPC_INVALID_TTL_TO_CONTROLLER:
2843 in_port = get_ofp_port(ctx.xbridge, flow->in_port.ofp_port);
2844 special = process_special(&ctx, flow, in_port, ctx.xin->packet);
2846 ctx.xout->slow |= special;
2848 size_t sample_actions_len;
2850 if (flow->in_port.ofp_port
2851 != vsp_realdev_to_vlandev(ctx.xbridge->ofproto,
2852 flow->in_port.ofp_port,
2854 ctx.base_flow.vlan_tci = 0;
2857 add_sflow_action(&ctx);
2858 add_ipfix_action(&ctx);
2859 sample_actions_len = ctx.xout->odp_actions.size;
2861 if (tnl_may_send && (!in_port || may_receive(in_port, &ctx))) {
2862 do_xlate_actions(ofpacts, ofpacts_len, &ctx);
2864 /* We've let OFPP_NORMAL and the learning action look at the
2865 * packet, so drop it now if forwarding is disabled. */
2866 if (in_port && !xport_stp_forward_state(in_port)) {
2867 ctx.xout->odp_actions.size = sample_actions_len;
2871 if (ctx.action_set.size) {
2872 xlate_action_set(&ctx);
2875 if (ctx.xbridge->has_in_band
2876 && in_band_must_output_to_local_port(flow)
2877 && !actions_output_to_local_port(&ctx)) {
2878 compose_output_action(&ctx, OFPP_LOCAL);
2881 fix_sflow_action(&ctx);
2883 if (mbridge_has_mirrors(ctx.xbridge->mbridge)) {
2884 add_mirror_actions(&ctx, &orig_flow);
2888 if (nl_attr_oversized(ctx.xout->odp_actions.size)) {
2889 /* These datapath actions are too big for a Netlink attribute, so we
2890 * can't execute them. */
2891 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
2893 VLOG_ERR_RL(&rl, "discarding oversize datapath actions");
2894 ofpbuf_clear(&ctx.xout->odp_actions);
2897 ofpbuf_uninit(&ctx.stack);
2898 ofpbuf_uninit(&ctx.action_set);
2900 /* Clear the metadata and register wildcard masks, because we won't
2901 * use non-header fields as part of the cache. */
2902 memset(&wc->masks.metadata, 0, sizeof wc->masks.metadata);
2903 memset(&wc->masks.regs, 0, sizeof wc->masks.regs);
2906 rule_actions_unref(actions);
2907 rule_dpif_unref(rule);
2910 /* Sends 'packet' out 'ofport'.
2911 * May modify 'packet'.
2912 * Returns 0 if successful, otherwise a positive errno value. */
2914 xlate_send_packet(const struct ofport_dpif *ofport, struct ofpbuf *packet)
2916 struct xport *xport;
2917 struct ofpact_output output;
2919 union flow_in_port in_port_;
2922 ofpact_init(&output.ofpact, OFPACT_OUTPUT, sizeof output);
2923 /* Use OFPP_NONE as the in_port to avoid special packet processing. */
2924 in_port_.ofp_port = OFPP_NONE;
2925 flow_extract(packet, 0, 0, NULL, &in_port_, &flow);
2927 ovs_rwlock_rdlock(&xlate_rwlock);
2928 xport = xport_lookup(ofport);
2930 ovs_rwlock_unlock(&xlate_rwlock);
2933 output.port = xport->ofp_port;
2935 error = ofproto_dpif_execute_actions(xport->xbridge->ofproto, &flow, NULL,
2936 &output.ofpact, sizeof output,
2938 ovs_rwlock_unlock(&xlate_rwlock);