1 /* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License. */
17 #include "ofproto/ofproto-dpif-xlate.h"
20 #include <arpa/inet.h>
22 #include <sys/socket.h>
23 #include <netinet/in.h>
25 #include "tnl-arp-cache.h"
30 #include "byte-order.h"
34 #include "dp-packet.h"
36 #include "dynamic-string.h"
42 #include "mac-learning.h"
43 #include "mcast-snooping.h"
44 #include "meta-flow.h"
45 #include "multipath.h"
46 #include "netdev-vport.h"
49 #include "odp-execute.h"
50 #include "ofp-actions.h"
51 #include "ofproto/ofproto-dpif-ipfix.h"
52 #include "ofproto/ofproto-dpif-mirror.h"
53 #include "ofproto/ofproto-dpif-monitor.h"
54 #include "ofproto/ofproto-dpif-sflow.h"
55 #include "ofproto/ofproto-dpif.h"
56 #include "ofproto/ofproto-provider.h"
57 #include "ovs-router.h"
58 #include "tnl-ports.h"
60 #include "openvswitch/vlog.h"
62 COVERAGE_DEFINE(xlate_actions
);
63 COVERAGE_DEFINE(xlate_actions_oversize
);
64 COVERAGE_DEFINE(xlate_actions_too_many_output
);
66 VLOG_DEFINE_THIS_MODULE(ofproto_dpif_xlate
);
68 /* Maximum depth of flow table recursion (due to resubmit actions) in a
69 * flow translation. */
70 #define MAX_RESUBMIT_RECURSION 64
71 #define MAX_INTERNAL_RESUBMITS 1 /* Max resbmits allowed using rules in
74 /* Maximum number of resubmit actions in a flow translation, whether they are
75 * recursive or not. */
76 #define MAX_RESUBMITS (MAX_RESUBMIT_RECURSION * MAX_RESUBMIT_RECURSION)
79 struct hmap_node hmap_node
; /* Node in global 'xbridges' map. */
80 struct ofproto_dpif
*ofproto
; /* Key in global 'xbridges' map. */
82 struct ovs_list xbundles
; /* Owned xbundles. */
83 struct hmap xports
; /* Indexed by ofp_port. */
85 char *name
; /* Name used in log messages. */
86 struct dpif
*dpif
; /* Datapath interface. */
87 struct mac_learning
*ml
; /* Mac learning handle. */
88 struct mcast_snooping
*ms
; /* Multicast Snooping handle. */
89 struct mbridge
*mbridge
; /* Mirroring. */
90 struct dpif_sflow
*sflow
; /* SFlow handle, or null. */
91 struct dpif_ipfix
*ipfix
; /* Ipfix handle, or null. */
92 struct netflow
*netflow
; /* Netflow handle, or null. */
93 struct stp
*stp
; /* STP or null if disabled. */
94 struct rstp
*rstp
; /* RSTP or null if disabled. */
96 bool has_in_band
; /* Bridge has in band control? */
97 bool forward_bpdu
; /* Bridge forwards STP BPDUs? */
99 /* Datapath feature support. */
100 struct dpif_backer_support support
;
104 struct hmap_node hmap_node
; /* In global 'xbundles' map. */
105 struct ofbundle
*ofbundle
; /* Key in global 'xbundles' map. */
107 struct ovs_list list_node
; /* In parent 'xbridges' list. */
108 struct xbridge
*xbridge
; /* Parent xbridge. */
110 struct ovs_list xports
; /* Contains "struct xport"s. */
112 char *name
; /* Name used in log messages. */
113 struct bond
*bond
; /* Nonnull iff more than one port. */
114 struct lacp
*lacp
; /* LACP handle or null. */
116 enum port_vlan_mode vlan_mode
; /* VLAN mode. */
117 int vlan
; /* -1=trunk port, else a 12-bit VLAN ID. */
118 unsigned long *trunks
; /* Bitmap of trunked VLANs, if 'vlan' == -1.
119 * NULL if all VLANs are trunked. */
120 bool use_priority_tags
; /* Use 802.1p tag for frames in VLAN 0? */
121 bool floodable
; /* No port has OFPUTIL_PC_NO_FLOOD set? */
125 struct hmap_node hmap_node
; /* Node in global 'xports' map. */
126 struct ofport_dpif
*ofport
; /* Key in global 'xports map. */
128 struct hmap_node ofp_node
; /* Node in parent xbridge 'xports' map. */
129 ofp_port_t ofp_port
; /* Key in parent xbridge 'xports' map. */
131 odp_port_t odp_port
; /* Datapath port number or ODPP_NONE. */
133 struct ovs_list bundle_node
; /* In parent xbundle (if it exists). */
134 struct xbundle
*xbundle
; /* Parent xbundle or null. */
136 struct netdev
*netdev
; /* 'ofport''s netdev. */
138 struct xbridge
*xbridge
; /* Parent bridge. */
139 struct xport
*peer
; /* Patch port peer or null. */
141 enum ofputil_port_config config
; /* OpenFlow port configuration. */
142 enum ofputil_port_state state
; /* OpenFlow port state. */
143 int stp_port_no
; /* STP port number or -1 if not in use. */
144 struct rstp_port
*rstp_port
; /* RSTP port or null. */
146 struct hmap skb_priorities
; /* Map of 'skb_priority_to_dscp's. */
148 bool may_enable
; /* May be enabled in bonds. */
149 bool is_tunnel
; /* Is a tunnel port. */
151 struct cfm
*cfm
; /* CFM handle or null. */
152 struct bfd
*bfd
; /* BFD handle or null. */
153 struct lldp
*lldp
; /* LLDP handle or null. */
157 struct xlate_in
*xin
;
158 struct xlate_out
*xout
;
160 const struct xbridge
*xbridge
;
162 /* Flow tables version at the beginning of the translation. */
163 cls_version_t tables_version
;
165 /* Flow at the last commit. */
166 struct flow base_flow
;
168 /* Tunnel IP destination address as received. This is stored separately
169 * as the base_flow.tunnel is cleared on init to reflect the datapath
170 * behavior. Used to make sure not to send tunneled output to ourselves,
171 * which might lead to an infinite loop. This could happen easily
172 * if a tunnel is marked as 'ip_remote=flow', and the flow does not
173 * actually set the tun_dst field. */
174 ovs_be32 orig_tunnel_ip_dst
;
176 /* Stack for the push and pop actions. Each stack element is of type
177 * "union mf_subvalue". */
180 /* The rule that we are currently translating, or NULL. */
181 struct rule_dpif
*rule
;
183 /* Flow translation populates this with wildcards relevant in translation.
184 * When 'xin->wc' is nonnull, this is the same pointer. When 'xin->wc' is
185 * null, this is a pointer to uninitialized scratch memory. This allows
186 * code to blindly write to 'ctx->wc' without worrying about whether the
187 * caller really wants wildcards. */
188 struct flow_wildcards
*wc
;
190 /* Output buffer for datapath actions. When 'xin->odp_actions' is nonnull,
191 * this is the same pointer. When 'xin->odp_actions' is null, this points
192 * to a scratch ofpbuf. This allows code to add actions to
193 * 'ctx->odp_actions' without worrying about whether the caller really
195 struct ofpbuf
*odp_actions
;
197 /* Resubmit statistics, via xlate_table_action(). */
198 int recurse
; /* Current resubmit nesting depth. */
199 int resubmits
; /* Total number of resubmits. */
200 bool in_group
; /* Currently translating ofgroup, if true. */
201 bool in_action_set
; /* Currently translating action_set, if true. */
203 uint8_t table_id
; /* OpenFlow table ID where flow was found. */
204 ovs_be64 rule_cookie
; /* Cookie of the rule being translated. */
205 uint32_t orig_skb_priority
; /* Priority when packet arrived. */
206 uint32_t sflow_n_outputs
; /* Number of output ports. */
207 odp_port_t sflow_odp_port
; /* Output port for composing sFlow action. */
208 ofp_port_t nf_output_iface
; /* Output interface index for NetFlow. */
209 bool exit
; /* No further actions should be processed. */
210 mirror_mask_t mirrors
; /* Bitmap of associated mirrors. */
212 /* These are used for non-bond recirculation. The recirculation IDs are
213 * stored in xout and must be associated with a datapath flow (ukey),
214 * otherwise they will be freed when the xout is uninitialized.
217 * Steps in Recirculation Translation
218 * ==================================
220 * At some point during translation, the code recognizes the need for
221 * recirculation. For example, recirculation is necessary when, after
222 * popping the last MPLS label, an action or a match tries to examine or
223 * modify a field that has been newly revealed following the MPLS label.
225 * The simplest part of the work to be done is to commit existing changes to
226 * the packet, which produces datapath actions corresponding to the changes,
227 * and after this, add an OVS_ACTION_ATTR_RECIRC datapath action.
229 * The main problem here is preserving state. When the datapath executes
230 * OVS_ACTION_ATTR_RECIRC, it will upcall to userspace to get a translation
231 * for the post-recirculation actions. At this point userspace has to
232 * resume the translation where it left off, which means that it has to
233 * execute the following:
235 * - The action that prompted recirculation, and any actions following
236 * it within the same flow.
238 * - If the action that prompted recirculation was invoked within a
239 * NXAST_RESUBMIT, then any actions following the resubmit. These
240 * "resubmit"s can be nested, so this has to go all the way up the
243 * - The OpenFlow 1.1+ action set.
245 * State that actions and flow table lookups can depend on, such as the
246 * following, must also be preserved:
248 * - Metadata fields (input port, registers, OF1.1+ metadata, ...).
250 * - Action set, stack
252 * - The table ID and cookie of the flow being translated at each level
253 * of the control stack (since OFPAT_CONTROLLER actions send these to
256 * Translation allows for the control of this state preservation via these
257 * members. When a need for recirculation is identified, the translation
260 * 1. Sets 'recirc_action_offset' to the current size of 'action_set'. The
261 * action set is part of what needs to be preserved, so this allows the
262 * action set and the additional state to share the 'action_set' buffer.
263 * Later steps can tell that setup for recirculation is in progress from
264 * the nonnegative value of 'recirc_action_offset'.
266 * 2. Sets 'exit' to true to tell later steps that we're exiting from the
267 * translation process.
269 * 3. Adds an OFPACT_UNROLL_XLATE action to 'action_set'. This action
270 * holds the current table ID and cookie so that they can be restored
271 * during a post-recirculation upcall translation.
273 * 4. Adds the action that prompted recirculation and any actions following
274 * it within the same flow to 'action_set', so that they can be executed
275 * during a post-recirculation upcall translation.
279 * 6. The action that prompted recirculation might be nested in a stack of
280 * nested "resubmit"s that have actions remaining. Each of these notices
281 * that we're exiting (from 'exit') and that recirculation setup is in
282 * progress (from 'recirc_action_offset') and responds by adding more
283 * OFPACT_UNROLL_XLATE actions to 'action_set', as necessary, and any
284 * actions that were yet unprocessed.
286 * The caller stores all the state produced by this process associated with
287 * the recirculation ID. For post-recirculation upcall translation, the
288 * caller passes it back in for the new translation to execute. The
289 * process yielded a set of ofpacts that can be translated directly, so it
290 * is not much of a special case at that point.
292 int recirc_action_offset
; /* Offset in 'action_set' to actions to be
293 * executed after recirculation, or -1. */
294 int last_unroll_offset
; /* Offset in 'action_set' to the latest unroll
297 /* True if a packet was but is no longer MPLS (due to an MPLS pop action).
298 * This is a trigger for recirculation in cases where translating an action
299 * or looking up a flow requires access to the fields of the packet after
300 * the MPLS label stack that was originally present. */
303 /* OpenFlow 1.1+ action set.
305 * 'action_set' accumulates "struct ofpact"s added by OFPACT_WRITE_ACTIONS.
306 * When translation is otherwise complete, ofpacts_execute_action_set()
307 * converts it to a set of "struct ofpact"s that can be translated into
308 * datapath actions. */
309 bool action_set_has_group
; /* Action set contains OFPACT_GROUP? */
310 struct ofpbuf action_set
; /* Action set. */
313 static void xlate_action_set(struct xlate_ctx
*ctx
);
314 static void xlate_commit_actions(struct xlate_ctx
*ctx
);
317 ctx_trigger_recirculation(struct xlate_ctx
*ctx
)
320 ctx
->recirc_action_offset
= ctx
->action_set
.size
;
324 ctx_first_recirculation_action(const struct xlate_ctx
*ctx
)
326 return ctx
->recirc_action_offset
== ctx
->action_set
.size
;
330 exit_recirculates(const struct xlate_ctx
*ctx
)
332 /* When recirculating the 'recirc_action_offset' has a non-negative value.
334 return ctx
->recirc_action_offset
>= 0;
337 static void compose_recirculate_action(struct xlate_ctx
*ctx
);
339 /* A controller may use OFPP_NONE as the ingress port to indicate that
340 * it did not arrive on a "real" port. 'ofpp_none_bundle' exists for
341 * when an input bundle is needed for validation (e.g., mirroring or
342 * OFPP_NORMAL processing). It is not connected to an 'ofproto' or have
343 * any 'port' structs, so care must be taken when dealing with it. */
344 static struct xbundle ofpp_none_bundle
= {
346 .vlan_mode
= PORT_VLAN_TRUNK
349 /* Node in 'xport''s 'skb_priorities' map. Used to maintain a map from
350 * 'priority' (the datapath's term for QoS queue) to the dscp bits which all
351 * traffic egressing the 'ofport' with that priority should be marked with. */
352 struct skb_priority_to_dscp
{
353 struct hmap_node hmap_node
; /* Node in 'ofport_dpif''s 'skb_priorities'. */
354 uint32_t skb_priority
; /* Priority of this queue (see struct flow). */
356 uint8_t dscp
; /* DSCP bits to mark outgoing traffic with. */
372 /* xlate_cache entries hold enough information to perform the side effects of
373 * xlate_actions() for a rule, without needing to perform rule translation
374 * from scratch. The primary usage of these is to submit statistics to objects
375 * that a flow relates to, although they may be used for other effects as well
376 * (for instance, refreshing hard timeouts for learned flows). */
380 struct rule_dpif
*rule
;
387 struct netflow
*netflow
;
392 struct mbridge
*mbridge
;
393 mirror_mask_t mirrors
;
401 struct ofproto_dpif
*ofproto
;
402 struct ofputil_flow_mod
*fm
;
403 struct ofpbuf
*ofpacts
;
406 struct ofproto_dpif
*ofproto
;
411 struct rule_dpif
*rule
;
416 struct group_dpif
*group
;
417 struct ofputil_bucket
*bucket
;
420 char br_name
[IFNAMSIZ
];
426 #define XC_ENTRY_FOR_EACH(entry, entries, xcache) \
427 entries = xcache->entries; \
428 for (entry = ofpbuf_try_pull(&entries, sizeof *entry); \
430 entry = ofpbuf_try_pull(&entries, sizeof *entry))
433 struct ofpbuf entries
;
436 /* Xlate config contains hash maps of all bridges, bundles and ports.
437 * Xcfgp contains the pointer to the current xlate configuration.
438 * When the main thread needs to change the configuration, it copies xcfgp to
439 * new_xcfg and edits new_xcfg. This enables the use of RCU locking which
440 * does not block handler and revalidator threads. */
442 struct hmap xbridges
;
443 struct hmap xbundles
;
446 static OVSRCU_TYPE(struct xlate_cfg
*) xcfgp
= OVSRCU_INITIALIZER(NULL
);
447 static struct xlate_cfg
*new_xcfg
= NULL
;
449 static bool may_receive(const struct xport
*, struct xlate_ctx
*);
450 static void do_xlate_actions(const struct ofpact
*, size_t ofpacts_len
,
452 static void xlate_normal(struct xlate_ctx
*);
453 static inline void xlate_report(struct xlate_ctx
*, const char *, ...)
454 OVS_PRINTF_FORMAT(2, 3);
455 static void xlate_table_action(struct xlate_ctx
*, ofp_port_t in_port
,
456 uint8_t table_id
, bool may_packet_in
,
457 bool honor_table_miss
);
458 static bool input_vid_is_valid(uint16_t vid
, struct xbundle
*, bool warn
);
459 static uint16_t input_vid_to_vlan(const struct xbundle
*, uint16_t vid
);
460 static void output_normal(struct xlate_ctx
*, const struct xbundle
*,
463 /* Optional bond recirculation parameter to compose_output_action(). */
464 struct xlate_bond_recirc
{
465 uint32_t recirc_id
; /* !0 Use recirculation instead of output. */
466 uint8_t hash_alg
; /* !0 Compute hash for recirc before. */
467 uint32_t hash_basis
; /* Compute hash for recirc before. */
470 static void compose_output_action(struct xlate_ctx
*, ofp_port_t ofp_port
,
471 const struct xlate_bond_recirc
*xr
);
473 static struct xbridge
*xbridge_lookup(struct xlate_cfg
*,
474 const struct ofproto_dpif
*);
475 static struct xbundle
*xbundle_lookup(struct xlate_cfg
*,
476 const struct ofbundle
*);
477 static struct xport
*xport_lookup(struct xlate_cfg
*,
478 const struct ofport_dpif
*);
479 static struct xport
*get_ofp_port(const struct xbridge
*, ofp_port_t ofp_port
);
480 static struct skb_priority_to_dscp
*get_skb_priority(const struct xport
*,
481 uint32_t skb_priority
);
482 static void clear_skb_priorities(struct xport
*);
483 static size_t count_skb_priorities(const struct xport
*);
484 static bool dscp_from_skb_priority(const struct xport
*, uint32_t skb_priority
,
487 static struct xc_entry
*xlate_cache_add_entry(struct xlate_cache
*xc
,
489 static void xlate_xbridge_init(struct xlate_cfg
*, struct xbridge
*);
490 static void xlate_xbundle_init(struct xlate_cfg
*, struct xbundle
*);
491 static void xlate_xport_init(struct xlate_cfg
*, struct xport
*);
492 static void xlate_xbridge_set(struct xbridge
*, struct dpif
*,
493 const struct mac_learning
*, struct stp
*,
494 struct rstp
*, const struct mcast_snooping
*,
495 const struct mbridge
*,
496 const struct dpif_sflow
*,
497 const struct dpif_ipfix
*,
498 const struct netflow
*,
499 bool forward_bpdu
, bool has_in_band
,
500 const struct dpif_backer_support
*);
501 static void xlate_xbundle_set(struct xbundle
*xbundle
,
502 enum port_vlan_mode vlan_mode
, int vlan
,
503 unsigned long *trunks
, bool use_priority_tags
,
504 const struct bond
*bond
, const struct lacp
*lacp
,
506 static void xlate_xport_set(struct xport
*xport
, odp_port_t odp_port
,
507 const struct netdev
*netdev
, const struct cfm
*cfm
,
508 const struct bfd
*bfd
, const struct lldp
*lldp
,
509 int stp_port_no
, const struct rstp_port
*rstp_port
,
510 enum ofputil_port_config config
,
511 enum ofputil_port_state state
, bool is_tunnel
,
513 static void xlate_xbridge_remove(struct xlate_cfg
*, struct xbridge
*);
514 static void xlate_xbundle_remove(struct xlate_cfg
*, struct xbundle
*);
515 static void xlate_xport_remove(struct xlate_cfg
*, struct xport
*);
516 static void xlate_xbridge_copy(struct xbridge
*);
517 static void xlate_xbundle_copy(struct xbridge
*, struct xbundle
*);
518 static void xlate_xport_copy(struct xbridge
*, struct xbundle
*,
520 static void xlate_xcfg_free(struct xlate_cfg
*);
523 xlate_report(struct xlate_ctx
*ctx
, const char *format
, ...)
525 if (OVS_UNLIKELY(ctx
->xin
->report_hook
)) {
528 va_start(args
, format
);
529 ctx
->xin
->report_hook(ctx
->xin
, ctx
->recurse
, format
, args
);
535 xlate_report_actions(struct xlate_ctx
*ctx
, const char *title
,
536 const struct ofpact
*ofpacts
, size_t ofpacts_len
)
538 if (OVS_UNLIKELY(ctx
->xin
->report_hook
)) {
539 struct ds s
= DS_EMPTY_INITIALIZER
;
540 ofpacts_format(ofpacts
, ofpacts_len
, &s
);
541 xlate_report(ctx
, "%s: %s", title
, ds_cstr(&s
));
547 xlate_xbridge_init(struct xlate_cfg
*xcfg
, struct xbridge
*xbridge
)
549 list_init(&xbridge
->xbundles
);
550 hmap_init(&xbridge
->xports
);
551 hmap_insert(&xcfg
->xbridges
, &xbridge
->hmap_node
,
552 hash_pointer(xbridge
->ofproto
, 0));
556 xlate_xbundle_init(struct xlate_cfg
*xcfg
, struct xbundle
*xbundle
)
558 list_init(&xbundle
->xports
);
559 list_insert(&xbundle
->xbridge
->xbundles
, &xbundle
->list_node
);
560 hmap_insert(&xcfg
->xbundles
, &xbundle
->hmap_node
,
561 hash_pointer(xbundle
->ofbundle
, 0));
565 xlate_xport_init(struct xlate_cfg
*xcfg
, struct xport
*xport
)
567 hmap_init(&xport
->skb_priorities
);
568 hmap_insert(&xcfg
->xports
, &xport
->hmap_node
,
569 hash_pointer(xport
->ofport
, 0));
570 hmap_insert(&xport
->xbridge
->xports
, &xport
->ofp_node
,
571 hash_ofp_port(xport
->ofp_port
));
575 xlate_xbridge_set(struct xbridge
*xbridge
,
577 const struct mac_learning
*ml
, struct stp
*stp
,
578 struct rstp
*rstp
, const struct mcast_snooping
*ms
,
579 const struct mbridge
*mbridge
,
580 const struct dpif_sflow
*sflow
,
581 const struct dpif_ipfix
*ipfix
,
582 const struct netflow
*netflow
,
583 bool forward_bpdu
, bool has_in_band
,
584 const struct dpif_backer_support
*support
)
586 if (xbridge
->ml
!= ml
) {
587 mac_learning_unref(xbridge
->ml
);
588 xbridge
->ml
= mac_learning_ref(ml
);
591 if (xbridge
->ms
!= ms
) {
592 mcast_snooping_unref(xbridge
->ms
);
593 xbridge
->ms
= mcast_snooping_ref(ms
);
596 if (xbridge
->mbridge
!= mbridge
) {
597 mbridge_unref(xbridge
->mbridge
);
598 xbridge
->mbridge
= mbridge_ref(mbridge
);
601 if (xbridge
->sflow
!= sflow
) {
602 dpif_sflow_unref(xbridge
->sflow
);
603 xbridge
->sflow
= dpif_sflow_ref(sflow
);
606 if (xbridge
->ipfix
!= ipfix
) {
607 dpif_ipfix_unref(xbridge
->ipfix
);
608 xbridge
->ipfix
= dpif_ipfix_ref(ipfix
);
611 if (xbridge
->stp
!= stp
) {
612 stp_unref(xbridge
->stp
);
613 xbridge
->stp
= stp_ref(stp
);
616 if (xbridge
->rstp
!= rstp
) {
617 rstp_unref(xbridge
->rstp
);
618 xbridge
->rstp
= rstp_ref(rstp
);
621 if (xbridge
->netflow
!= netflow
) {
622 netflow_unref(xbridge
->netflow
);
623 xbridge
->netflow
= netflow_ref(netflow
);
626 xbridge
->dpif
= dpif
;
627 xbridge
->forward_bpdu
= forward_bpdu
;
628 xbridge
->has_in_band
= has_in_band
;
629 xbridge
->support
= *support
;
633 xlate_xbundle_set(struct xbundle
*xbundle
,
634 enum port_vlan_mode vlan_mode
, int vlan
,
635 unsigned long *trunks
, bool use_priority_tags
,
636 const struct bond
*bond
, const struct lacp
*lacp
,
639 ovs_assert(xbundle
->xbridge
);
641 xbundle
->vlan_mode
= vlan_mode
;
642 xbundle
->vlan
= vlan
;
643 xbundle
->trunks
= trunks
;
644 xbundle
->use_priority_tags
= use_priority_tags
;
645 xbundle
->floodable
= floodable
;
647 if (xbundle
->bond
!= bond
) {
648 bond_unref(xbundle
->bond
);
649 xbundle
->bond
= bond_ref(bond
);
652 if (xbundle
->lacp
!= lacp
) {
653 lacp_unref(xbundle
->lacp
);
654 xbundle
->lacp
= lacp_ref(lacp
);
659 xlate_xport_set(struct xport
*xport
, odp_port_t odp_port
,
660 const struct netdev
*netdev
, const struct cfm
*cfm
,
661 const struct bfd
*bfd
, const struct lldp
*lldp
, int stp_port_no
,
662 const struct rstp_port
* rstp_port
,
663 enum ofputil_port_config config
, enum ofputil_port_state state
,
664 bool is_tunnel
, bool may_enable
)
666 xport
->config
= config
;
667 xport
->state
= state
;
668 xport
->stp_port_no
= stp_port_no
;
669 xport
->is_tunnel
= is_tunnel
;
670 xport
->may_enable
= may_enable
;
671 xport
->odp_port
= odp_port
;
673 if (xport
->rstp_port
!= rstp_port
) {
674 rstp_port_unref(xport
->rstp_port
);
675 xport
->rstp_port
= rstp_port_ref(rstp_port
);
678 if (xport
->cfm
!= cfm
) {
679 cfm_unref(xport
->cfm
);
680 xport
->cfm
= cfm_ref(cfm
);
683 if (xport
->bfd
!= bfd
) {
684 bfd_unref(xport
->bfd
);
685 xport
->bfd
= bfd_ref(bfd
);
688 if (xport
->lldp
!= lldp
) {
689 lldp_unref(xport
->lldp
);
690 xport
->lldp
= lldp_ref(lldp
);
693 if (xport
->netdev
!= netdev
) {
694 netdev_close(xport
->netdev
);
695 xport
->netdev
= netdev_ref(netdev
);
700 xlate_xbridge_copy(struct xbridge
*xbridge
)
702 struct xbundle
*xbundle
;
704 struct xbridge
*new_xbridge
= xzalloc(sizeof *xbridge
);
705 new_xbridge
->ofproto
= xbridge
->ofproto
;
706 new_xbridge
->name
= xstrdup(xbridge
->name
);
707 xlate_xbridge_init(new_xcfg
, new_xbridge
);
709 xlate_xbridge_set(new_xbridge
,
710 xbridge
->dpif
, xbridge
->ml
, xbridge
->stp
,
711 xbridge
->rstp
, xbridge
->ms
, xbridge
->mbridge
,
712 xbridge
->sflow
, xbridge
->ipfix
, xbridge
->netflow
,
713 xbridge
->forward_bpdu
, xbridge
->has_in_band
,
715 LIST_FOR_EACH (xbundle
, list_node
, &xbridge
->xbundles
) {
716 xlate_xbundle_copy(new_xbridge
, xbundle
);
719 /* Copy xports which are not part of a xbundle */
720 HMAP_FOR_EACH (xport
, ofp_node
, &xbridge
->xports
) {
721 if (!xport
->xbundle
) {
722 xlate_xport_copy(new_xbridge
, NULL
, xport
);
728 xlate_xbundle_copy(struct xbridge
*xbridge
, struct xbundle
*xbundle
)
731 struct xbundle
*new_xbundle
= xzalloc(sizeof *xbundle
);
732 new_xbundle
->ofbundle
= xbundle
->ofbundle
;
733 new_xbundle
->xbridge
= xbridge
;
734 new_xbundle
->name
= xstrdup(xbundle
->name
);
735 xlate_xbundle_init(new_xcfg
, new_xbundle
);
737 xlate_xbundle_set(new_xbundle
, xbundle
->vlan_mode
,
738 xbundle
->vlan
, xbundle
->trunks
,
739 xbundle
->use_priority_tags
, xbundle
->bond
, xbundle
->lacp
,
741 LIST_FOR_EACH (xport
, bundle_node
, &xbundle
->xports
) {
742 xlate_xport_copy(xbridge
, new_xbundle
, xport
);
747 xlate_xport_copy(struct xbridge
*xbridge
, struct xbundle
*xbundle
,
750 struct skb_priority_to_dscp
*pdscp
, *new_pdscp
;
751 struct xport
*new_xport
= xzalloc(sizeof *xport
);
752 new_xport
->ofport
= xport
->ofport
;
753 new_xport
->ofp_port
= xport
->ofp_port
;
754 new_xport
->xbridge
= xbridge
;
755 xlate_xport_init(new_xcfg
, new_xport
);
757 xlate_xport_set(new_xport
, xport
->odp_port
, xport
->netdev
, xport
->cfm
,
758 xport
->bfd
, xport
->lldp
, xport
->stp_port_no
,
759 xport
->rstp_port
, xport
->config
, xport
->state
,
760 xport
->is_tunnel
, xport
->may_enable
);
763 struct xport
*peer
= xport_lookup(new_xcfg
, xport
->peer
->ofport
);
765 new_xport
->peer
= peer
;
766 new_xport
->peer
->peer
= new_xport
;
771 new_xport
->xbundle
= xbundle
;
772 list_insert(&new_xport
->xbundle
->xports
, &new_xport
->bundle_node
);
775 HMAP_FOR_EACH (pdscp
, hmap_node
, &xport
->skb_priorities
) {
776 new_pdscp
= xmalloc(sizeof *pdscp
);
777 new_pdscp
->skb_priority
= pdscp
->skb_priority
;
778 new_pdscp
->dscp
= pdscp
->dscp
;
779 hmap_insert(&new_xport
->skb_priorities
, &new_pdscp
->hmap_node
,
780 hash_int(new_pdscp
->skb_priority
, 0));
784 /* Sets the current xlate configuration to new_xcfg and frees the old xlate
785 * configuration in xcfgp.
787 * This needs to be called after editing the xlate configuration.
789 * Functions that edit the new xlate configuration are
790 * xlate_<ofport/bundle/ofport>_set and xlate_<ofport/bundle/ofport>_remove.
796 * edit_xlate_configuration();
798 * xlate_txn_commit(); */
800 xlate_txn_commit(void)
802 struct xlate_cfg
*xcfg
= ovsrcu_get(struct xlate_cfg
*, &xcfgp
);
804 ovsrcu_set(&xcfgp
, new_xcfg
);
805 ovsrcu_synchronize();
806 xlate_xcfg_free(xcfg
);
810 /* Copies the current xlate configuration in xcfgp to new_xcfg.
812 * This needs to be called prior to editing the xlate configuration. */
814 xlate_txn_start(void)
816 struct xbridge
*xbridge
;
817 struct xlate_cfg
*xcfg
;
819 ovs_assert(!new_xcfg
);
821 new_xcfg
= xmalloc(sizeof *new_xcfg
);
822 hmap_init(&new_xcfg
->xbridges
);
823 hmap_init(&new_xcfg
->xbundles
);
824 hmap_init(&new_xcfg
->xports
);
826 xcfg
= ovsrcu_get(struct xlate_cfg
*, &xcfgp
);
831 HMAP_FOR_EACH (xbridge
, hmap_node
, &xcfg
->xbridges
) {
832 xlate_xbridge_copy(xbridge
);
838 xlate_xcfg_free(struct xlate_cfg
*xcfg
)
840 struct xbridge
*xbridge
, *next_xbridge
;
846 HMAP_FOR_EACH_SAFE (xbridge
, next_xbridge
, hmap_node
, &xcfg
->xbridges
) {
847 xlate_xbridge_remove(xcfg
, xbridge
);
850 hmap_destroy(&xcfg
->xbridges
);
851 hmap_destroy(&xcfg
->xbundles
);
852 hmap_destroy(&xcfg
->xports
);
857 xlate_ofproto_set(struct ofproto_dpif
*ofproto
, const char *name
,
859 const struct mac_learning
*ml
, struct stp
*stp
,
860 struct rstp
*rstp
, const struct mcast_snooping
*ms
,
861 const struct mbridge
*mbridge
,
862 const struct dpif_sflow
*sflow
,
863 const struct dpif_ipfix
*ipfix
,
864 const struct netflow
*netflow
,
865 bool forward_bpdu
, bool has_in_band
,
866 const struct dpif_backer_support
*support
)
868 struct xbridge
*xbridge
;
870 ovs_assert(new_xcfg
);
872 xbridge
= xbridge_lookup(new_xcfg
, ofproto
);
874 xbridge
= xzalloc(sizeof *xbridge
);
875 xbridge
->ofproto
= ofproto
;
877 xlate_xbridge_init(new_xcfg
, xbridge
);
881 xbridge
->name
= xstrdup(name
);
883 xlate_xbridge_set(xbridge
, dpif
, ml
, stp
, rstp
, ms
, mbridge
, sflow
, ipfix
,
884 netflow
, forward_bpdu
, has_in_band
, support
);
888 xlate_xbridge_remove(struct xlate_cfg
*xcfg
, struct xbridge
*xbridge
)
890 struct xbundle
*xbundle
, *next_xbundle
;
891 struct xport
*xport
, *next_xport
;
897 HMAP_FOR_EACH_SAFE (xport
, next_xport
, ofp_node
, &xbridge
->xports
) {
898 xlate_xport_remove(xcfg
, xport
);
901 LIST_FOR_EACH_SAFE (xbundle
, next_xbundle
, list_node
, &xbridge
->xbundles
) {
902 xlate_xbundle_remove(xcfg
, xbundle
);
905 hmap_remove(&xcfg
->xbridges
, &xbridge
->hmap_node
);
906 mac_learning_unref(xbridge
->ml
);
907 mcast_snooping_unref(xbridge
->ms
);
908 mbridge_unref(xbridge
->mbridge
);
909 dpif_sflow_unref(xbridge
->sflow
);
910 dpif_ipfix_unref(xbridge
->ipfix
);
911 stp_unref(xbridge
->stp
);
912 rstp_unref(xbridge
->rstp
);
913 hmap_destroy(&xbridge
->xports
);
919 xlate_remove_ofproto(struct ofproto_dpif
*ofproto
)
921 struct xbridge
*xbridge
;
923 ovs_assert(new_xcfg
);
925 xbridge
= xbridge_lookup(new_xcfg
, ofproto
);
926 xlate_xbridge_remove(new_xcfg
, xbridge
);
930 xlate_bundle_set(struct ofproto_dpif
*ofproto
, struct ofbundle
*ofbundle
,
931 const char *name
, enum port_vlan_mode vlan_mode
, int vlan
,
932 unsigned long *trunks
, bool use_priority_tags
,
933 const struct bond
*bond
, const struct lacp
*lacp
,
936 struct xbundle
*xbundle
;
938 ovs_assert(new_xcfg
);
940 xbundle
= xbundle_lookup(new_xcfg
, ofbundle
);
942 xbundle
= xzalloc(sizeof *xbundle
);
943 xbundle
->ofbundle
= ofbundle
;
944 xbundle
->xbridge
= xbridge_lookup(new_xcfg
, ofproto
);
946 xlate_xbundle_init(new_xcfg
, xbundle
);
950 xbundle
->name
= xstrdup(name
);
952 xlate_xbundle_set(xbundle
, vlan_mode
, vlan
, trunks
,
953 use_priority_tags
, bond
, lacp
, floodable
);
957 xlate_xbundle_remove(struct xlate_cfg
*xcfg
, struct xbundle
*xbundle
)
965 LIST_FOR_EACH_POP (xport
, bundle_node
, &xbundle
->xports
) {
966 xport
->xbundle
= NULL
;
969 hmap_remove(&xcfg
->xbundles
, &xbundle
->hmap_node
);
970 list_remove(&xbundle
->list_node
);
971 bond_unref(xbundle
->bond
);
972 lacp_unref(xbundle
->lacp
);
978 xlate_bundle_remove(struct ofbundle
*ofbundle
)
980 struct xbundle
*xbundle
;
982 ovs_assert(new_xcfg
);
984 xbundle
= xbundle_lookup(new_xcfg
, ofbundle
);
985 xlate_xbundle_remove(new_xcfg
, xbundle
);
989 xlate_ofport_set(struct ofproto_dpif
*ofproto
, struct ofbundle
*ofbundle
,
990 struct ofport_dpif
*ofport
, ofp_port_t ofp_port
,
991 odp_port_t odp_port
, const struct netdev
*netdev
,
992 const struct cfm
*cfm
, const struct bfd
*bfd
,
993 const struct lldp
*lldp
, struct ofport_dpif
*peer
,
994 int stp_port_no
, const struct rstp_port
*rstp_port
,
995 const struct ofproto_port_queue
*qdscp_list
, size_t n_qdscp
,
996 enum ofputil_port_config config
,
997 enum ofputil_port_state state
, bool is_tunnel
,
1001 struct xport
*xport
;
1003 ovs_assert(new_xcfg
);
1005 xport
= xport_lookup(new_xcfg
, ofport
);
1007 xport
= xzalloc(sizeof *xport
);
1008 xport
->ofport
= ofport
;
1009 xport
->xbridge
= xbridge_lookup(new_xcfg
, ofproto
);
1010 xport
->ofp_port
= ofp_port
;
1012 xlate_xport_init(new_xcfg
, xport
);
1015 ovs_assert(xport
->ofp_port
== ofp_port
);
1017 xlate_xport_set(xport
, odp_port
, netdev
, cfm
, bfd
, lldp
,
1018 stp_port_no
, rstp_port
, config
, state
, is_tunnel
,
1022 xport
->peer
->peer
= NULL
;
1024 xport
->peer
= xport_lookup(new_xcfg
, peer
);
1026 xport
->peer
->peer
= xport
;
1029 if (xport
->xbundle
) {
1030 list_remove(&xport
->bundle_node
);
1032 xport
->xbundle
= xbundle_lookup(new_xcfg
, ofbundle
);
1033 if (xport
->xbundle
) {
1034 list_insert(&xport
->xbundle
->xports
, &xport
->bundle_node
);
1037 clear_skb_priorities(xport
);
1038 for (i
= 0; i
< n_qdscp
; i
++) {
1039 struct skb_priority_to_dscp
*pdscp
;
1040 uint32_t skb_priority
;
1042 if (dpif_queue_to_priority(xport
->xbridge
->dpif
, qdscp_list
[i
].queue
,
1047 pdscp
= xmalloc(sizeof *pdscp
);
1048 pdscp
->skb_priority
= skb_priority
;
1049 pdscp
->dscp
= (qdscp_list
[i
].dscp
<< 2) & IP_DSCP_MASK
;
1050 hmap_insert(&xport
->skb_priorities
, &pdscp
->hmap_node
,
1051 hash_int(pdscp
->skb_priority
, 0));
1056 xlate_xport_remove(struct xlate_cfg
*xcfg
, struct xport
*xport
)
1063 xport
->peer
->peer
= NULL
;
1067 if (xport
->xbundle
) {
1068 list_remove(&xport
->bundle_node
);
1071 clear_skb_priorities(xport
);
1072 hmap_destroy(&xport
->skb_priorities
);
1074 hmap_remove(&xcfg
->xports
, &xport
->hmap_node
);
1075 hmap_remove(&xport
->xbridge
->xports
, &xport
->ofp_node
);
1077 netdev_close(xport
->netdev
);
1078 rstp_port_unref(xport
->rstp_port
);
1079 cfm_unref(xport
->cfm
);
1080 bfd_unref(xport
->bfd
);
1081 lldp_unref(xport
->lldp
);
1086 xlate_ofport_remove(struct ofport_dpif
*ofport
)
1088 struct xport
*xport
;
1090 ovs_assert(new_xcfg
);
1092 xport
= xport_lookup(new_xcfg
, ofport
);
1093 xlate_xport_remove(new_xcfg
, xport
);
1096 static struct ofproto_dpif
*
1097 xlate_lookup_ofproto_(const struct dpif_backer
*backer
, const struct flow
*flow
,
1098 ofp_port_t
*ofp_in_port
, const struct xport
**xportp
)
1100 struct xlate_cfg
*xcfg
= ovsrcu_get(struct xlate_cfg
*, &xcfgp
);
1101 const struct xport
*xport
;
1103 xport
= xport_lookup(xcfg
, tnl_port_should_receive(flow
)
1104 ? tnl_port_receive(flow
)
1105 : odp_port_to_ofport(backer
, flow
->in_port
.odp_port
));
1106 if (OVS_UNLIKELY(!xport
)) {
1111 *ofp_in_port
= xport
->ofp_port
;
1113 return xport
->xbridge
->ofproto
;
1116 /* Given a datapath and flow metadata ('backer', and 'flow' respectively)
1117 * returns the corresponding struct ofproto_dpif and OpenFlow port number. */
1118 struct ofproto_dpif
*
1119 xlate_lookup_ofproto(const struct dpif_backer
*backer
, const struct flow
*flow
,
1120 ofp_port_t
*ofp_in_port
)
1122 const struct xport
*xport
;
1124 return xlate_lookup_ofproto_(backer
, flow
, ofp_in_port
, &xport
);
1127 /* Given a datapath and flow metadata ('backer', and 'flow' respectively),
1128 * optionally populates 'ofproto' with the ofproto_dpif, 'ofp_in_port' with the
1129 * openflow in_port, and 'ipfix', 'sflow', and 'netflow' with the appropriate
1130 * handles for those protocols if they're enabled. Caller may use the returned
1131 * pointers until quiescing, for longer term use additional references must
1134 * Returns 0 if successful, ENODEV if the parsed flow has no associated ofproto.
1137 xlate_lookup(const struct dpif_backer
*backer
, const struct flow
*flow
,
1138 struct ofproto_dpif
**ofprotop
, struct dpif_ipfix
**ipfix
,
1139 struct dpif_sflow
**sflow
, struct netflow
**netflow
,
1140 ofp_port_t
*ofp_in_port
)
1142 struct ofproto_dpif
*ofproto
;
1143 const struct xport
*xport
;
1145 ofproto
= xlate_lookup_ofproto_(backer
, flow
, ofp_in_port
, &xport
);
1152 *ofprotop
= ofproto
;
1156 *ipfix
= xport
? xport
->xbridge
->ipfix
: NULL
;
1160 *sflow
= xport
? xport
->xbridge
->sflow
: NULL
;
1164 *netflow
= xport
? xport
->xbridge
->netflow
: NULL
;
1170 static struct xbridge
*
1171 xbridge_lookup(struct xlate_cfg
*xcfg
, const struct ofproto_dpif
*ofproto
)
1173 struct hmap
*xbridges
;
1174 struct xbridge
*xbridge
;
1176 if (!ofproto
|| !xcfg
) {
1180 xbridges
= &xcfg
->xbridges
;
1182 HMAP_FOR_EACH_IN_BUCKET (xbridge
, hmap_node
, hash_pointer(ofproto
, 0),
1184 if (xbridge
->ofproto
== ofproto
) {
1191 static struct xbundle
*
1192 xbundle_lookup(struct xlate_cfg
*xcfg
, const struct ofbundle
*ofbundle
)
1194 struct hmap
*xbundles
;
1195 struct xbundle
*xbundle
;
1197 if (!ofbundle
|| !xcfg
) {
1201 xbundles
= &xcfg
->xbundles
;
1203 HMAP_FOR_EACH_IN_BUCKET (xbundle
, hmap_node
, hash_pointer(ofbundle
, 0),
1205 if (xbundle
->ofbundle
== ofbundle
) {
1212 static struct xport
*
1213 xport_lookup(struct xlate_cfg
*xcfg
, const struct ofport_dpif
*ofport
)
1215 struct hmap
*xports
;
1216 struct xport
*xport
;
1218 if (!ofport
|| !xcfg
) {
1222 xports
= &xcfg
->xports
;
1224 HMAP_FOR_EACH_IN_BUCKET (xport
, hmap_node
, hash_pointer(ofport
, 0),
1226 if (xport
->ofport
== ofport
) {
1233 static struct stp_port
*
1234 xport_get_stp_port(const struct xport
*xport
)
1236 return xport
->xbridge
->stp
&& xport
->stp_port_no
!= -1
1237 ? stp_get_port(xport
->xbridge
->stp
, xport
->stp_port_no
)
1242 xport_stp_learn_state(const struct xport
*xport
)
1244 struct stp_port
*sp
= xport_get_stp_port(xport
);
1246 ? stp_learn_in_state(stp_port_get_state(sp
))
1251 xport_stp_forward_state(const struct xport
*xport
)
1253 struct stp_port
*sp
= xport_get_stp_port(xport
);
1255 ? stp_forward_in_state(stp_port_get_state(sp
))
1260 xport_stp_should_forward_bpdu(const struct xport
*xport
)
1262 struct stp_port
*sp
= xport_get_stp_port(xport
);
1263 return stp_should_forward_bpdu(sp
? stp_port_get_state(sp
) : STP_DISABLED
);
1266 /* Returns true if STP should process 'flow'. Sets fields in 'wc' that
1267 * were used to make the determination.*/
1269 stp_should_process_flow(const struct flow
*flow
, struct flow_wildcards
*wc
)
1271 /* is_stp() also checks dl_type, but dl_type is always set in 'wc'. */
1272 memset(&wc
->masks
.dl_dst
, 0xff, sizeof wc
->masks
.dl_dst
);
1273 return is_stp(flow
);
1277 stp_process_packet(const struct xport
*xport
, const struct dp_packet
*packet
)
1279 struct stp_port
*sp
= xport_get_stp_port(xport
);
1280 struct dp_packet payload
= *packet
;
1281 struct eth_header
*eth
= dp_packet_data(&payload
);
1283 /* Sink packets on ports that have STP disabled when the bridge has
1285 if (!sp
|| stp_port_get_state(sp
) == STP_DISABLED
) {
1289 /* Trim off padding on payload. */
1290 if (dp_packet_size(&payload
) > ntohs(eth
->eth_type
) + ETH_HEADER_LEN
) {
1291 dp_packet_set_size(&payload
, ntohs(eth
->eth_type
) + ETH_HEADER_LEN
);
1294 if (dp_packet_try_pull(&payload
, ETH_HEADER_LEN
+ LLC_HEADER_LEN
)) {
1295 stp_received_bpdu(sp
, dp_packet_data(&payload
), dp_packet_size(&payload
));
1299 static enum rstp_state
1300 xport_get_rstp_port_state(const struct xport
*xport
)
1302 return xport
->rstp_port
1303 ? rstp_port_get_state(xport
->rstp_port
)
1308 xport_rstp_learn_state(const struct xport
*xport
)
1310 return xport
->xbridge
->rstp
&& xport
->rstp_port
1311 ? rstp_learn_in_state(xport_get_rstp_port_state(xport
))
1316 xport_rstp_forward_state(const struct xport
*xport
)
1318 return xport
->xbridge
->rstp
&& xport
->rstp_port
1319 ? rstp_forward_in_state(xport_get_rstp_port_state(xport
))
1324 xport_rstp_should_manage_bpdu(const struct xport
*xport
)
1326 return rstp_should_manage_bpdu(xport_get_rstp_port_state(xport
));
1330 rstp_process_packet(const struct xport
*xport
, const struct dp_packet
*packet
)
1332 struct dp_packet payload
= *packet
;
1333 struct eth_header
*eth
= dp_packet_data(&payload
);
1335 /* Sink packets on ports that have no RSTP. */
1336 if (!xport
->rstp_port
) {
1340 /* Trim off padding on payload. */
1341 if (dp_packet_size(&payload
) > ntohs(eth
->eth_type
) + ETH_HEADER_LEN
) {
1342 dp_packet_set_size(&payload
, ntohs(eth
->eth_type
) + ETH_HEADER_LEN
);
1345 if (dp_packet_try_pull(&payload
, ETH_HEADER_LEN
+ LLC_HEADER_LEN
)) {
1346 rstp_port_received_bpdu(xport
->rstp_port
, dp_packet_data(&payload
),
1347 dp_packet_size(&payload
));
1351 static struct xport
*
1352 get_ofp_port(const struct xbridge
*xbridge
, ofp_port_t ofp_port
)
1354 struct xport
*xport
;
1356 HMAP_FOR_EACH_IN_BUCKET (xport
, ofp_node
, hash_ofp_port(ofp_port
),
1358 if (xport
->ofp_port
== ofp_port
) {
1366 ofp_port_to_odp_port(const struct xbridge
*xbridge
, ofp_port_t ofp_port
)
1368 const struct xport
*xport
= get_ofp_port(xbridge
, ofp_port
);
1369 return xport
? xport
->odp_port
: ODPP_NONE
;
1373 odp_port_is_alive(const struct xlate_ctx
*ctx
, ofp_port_t ofp_port
)
1375 struct xport
*xport
= get_ofp_port(ctx
->xbridge
, ofp_port
);
1376 return xport
&& xport
->may_enable
;
1379 static struct ofputil_bucket
*
1380 group_first_live_bucket(const struct xlate_ctx
*, const struct group_dpif
*,
1384 group_is_alive(const struct xlate_ctx
*ctx
, uint32_t group_id
, int depth
)
1386 struct group_dpif
*group
;
1388 if (group_dpif_lookup(ctx
->xbridge
->ofproto
, group_id
, &group
)) {
1389 struct ofputil_bucket
*bucket
;
1391 bucket
= group_first_live_bucket(ctx
, group
, depth
);
1392 group_dpif_unref(group
);
1393 return bucket
== NULL
;
1399 #define MAX_LIVENESS_RECURSION 128 /* Arbitrary limit */
1402 bucket_is_alive(const struct xlate_ctx
*ctx
,
1403 struct ofputil_bucket
*bucket
, int depth
)
1405 if (depth
>= MAX_LIVENESS_RECURSION
) {
1406 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 1);
1408 VLOG_WARN_RL(&rl
, "bucket chaining exceeded %d links",
1409 MAX_LIVENESS_RECURSION
);
1413 return (!ofputil_bucket_has_liveness(bucket
)
1414 || (bucket
->watch_port
!= OFPP_ANY
1415 && odp_port_is_alive(ctx
, bucket
->watch_port
))
1416 || (bucket
->watch_group
!= OFPG_ANY
1417 && group_is_alive(ctx
, bucket
->watch_group
, depth
+ 1)));
1420 static struct ofputil_bucket
*
1421 group_first_live_bucket(const struct xlate_ctx
*ctx
,
1422 const struct group_dpif
*group
, int depth
)
1424 struct ofputil_bucket
*bucket
;
1425 const struct ovs_list
*buckets
;
1427 group_dpif_get_buckets(group
, &buckets
);
1428 LIST_FOR_EACH (bucket
, list_node
, buckets
) {
1429 if (bucket_is_alive(ctx
, bucket
, depth
)) {
1437 static struct ofputil_bucket
*
1438 group_best_live_bucket(const struct xlate_ctx
*ctx
,
1439 const struct group_dpif
*group
,
1442 struct ofputil_bucket
*best_bucket
= NULL
;
1443 uint32_t best_score
= 0;
1446 struct ofputil_bucket
*bucket
;
1447 const struct ovs_list
*buckets
;
1449 group_dpif_get_buckets(group
, &buckets
);
1450 LIST_FOR_EACH (bucket
, list_node
, buckets
) {
1451 if (bucket_is_alive(ctx
, bucket
, 0)) {
1452 uint32_t score
= (hash_int(i
, basis
) & 0xffff) * bucket
->weight
;
1453 if (score
>= best_score
) {
1454 best_bucket
= bucket
;
1465 xbundle_trunks_vlan(const struct xbundle
*bundle
, uint16_t vlan
)
1467 return (bundle
->vlan_mode
!= PORT_VLAN_ACCESS
1468 && (!bundle
->trunks
|| bitmap_is_set(bundle
->trunks
, vlan
)));
1472 xbundle_includes_vlan(const struct xbundle
*xbundle
, uint16_t vlan
)
1474 return vlan
== xbundle
->vlan
|| xbundle_trunks_vlan(xbundle
, vlan
);
1477 static mirror_mask_t
1478 xbundle_mirror_out(const struct xbridge
*xbridge
, struct xbundle
*xbundle
)
1480 return xbundle
!= &ofpp_none_bundle
1481 ? mirror_bundle_out(xbridge
->mbridge
, xbundle
->ofbundle
)
1485 static mirror_mask_t
1486 xbundle_mirror_src(const struct xbridge
*xbridge
, struct xbundle
*xbundle
)
1488 return xbundle
!= &ofpp_none_bundle
1489 ? mirror_bundle_src(xbridge
->mbridge
, xbundle
->ofbundle
)
1493 static mirror_mask_t
1494 xbundle_mirror_dst(const struct xbridge
*xbridge
, struct xbundle
*xbundle
)
1496 return xbundle
!= &ofpp_none_bundle
1497 ? mirror_bundle_dst(xbridge
->mbridge
, xbundle
->ofbundle
)
1501 static struct xbundle
*
1502 lookup_input_bundle(const struct xbridge
*xbridge
, ofp_port_t in_port
,
1503 bool warn
, struct xport
**in_xportp
)
1505 struct xport
*xport
;
1507 /* Find the port and bundle for the received packet. */
1508 xport
= get_ofp_port(xbridge
, in_port
);
1512 if (xport
&& xport
->xbundle
) {
1513 return xport
->xbundle
;
1516 /* Special-case OFPP_NONE (OF1.0) and OFPP_CONTROLLER (OF1.1+),
1517 * which a controller may use as the ingress port for traffic that
1518 * it is sourcing. */
1519 if (in_port
== OFPP_CONTROLLER
|| in_port
== OFPP_NONE
) {
1520 return &ofpp_none_bundle
;
1523 /* Odd. A few possible reasons here:
1525 * - We deleted a port but there are still a few packets queued up
1528 * - Someone externally added a port (e.g. "ovs-dpctl add-if") that
1529 * we don't know about.
1531 * - The ofproto client didn't configure the port as part of a bundle.
1532 * This is particularly likely to happen if a packet was received on the
1533 * port after it was created, but before the client had a chance to
1534 * configure its bundle.
1537 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 5);
1539 VLOG_WARN_RL(&rl
, "bridge %s: received packet on unknown "
1540 "port %"PRIu16
, xbridge
->name
, in_port
);
1546 mirror_packet(struct xlate_ctx
*ctx
, struct xbundle
*xbundle
,
1547 mirror_mask_t mirrors
)
1549 bool warn
= ctx
->xin
->packet
!= NULL
;
1550 uint16_t vid
= vlan_tci_to_vid(ctx
->xin
->flow
.vlan_tci
);
1551 if (!input_vid_is_valid(vid
, xbundle
, warn
)) {
1554 uint16_t vlan
= input_vid_to_vlan(xbundle
, vid
);
1556 const struct xbridge
*xbridge
= ctx
->xbridge
;
1558 /* Don't mirror to destinations that we've already mirrored to. */
1559 mirrors
&= ~ctx
->mirrors
;
1564 /* Record these mirrors so that we don't mirror to them again. */
1565 ctx
->mirrors
|= mirrors
;
1567 if (ctx
->xin
->resubmit_stats
) {
1568 mirror_update_stats(xbridge
->mbridge
, mirrors
,
1569 ctx
->xin
->resubmit_stats
->n_packets
,
1570 ctx
->xin
->resubmit_stats
->n_bytes
);
1572 if (ctx
->xin
->xcache
) {
1573 struct xc_entry
*entry
;
1575 entry
= xlate_cache_add_entry(ctx
->xin
->xcache
, XC_MIRROR
);
1576 entry
->u
.mirror
.mbridge
= mbridge_ref(xbridge
->mbridge
);
1577 entry
->u
.mirror
.mirrors
= mirrors
;
1581 const unsigned long *vlans
;
1582 mirror_mask_t dup_mirrors
;
1583 struct ofbundle
*out
;
1586 bool has_mirror
= mirror_get(xbridge
->mbridge
, raw_ctz(mirrors
),
1587 &vlans
, &dup_mirrors
, &out
, &out_vlan
);
1588 ovs_assert(has_mirror
);
1591 ctx
->wc
->masks
.vlan_tci
|= htons(VLAN_CFI
| VLAN_VID_MASK
);
1594 if (vlans
&& !bitmap_is_set(vlans
, vlan
)) {
1595 mirrors
= zero_rightmost_1bit(mirrors
);
1599 mirrors
&= ~dup_mirrors
;
1600 ctx
->mirrors
|= dup_mirrors
;
1602 struct xlate_cfg
*xcfg
= ovsrcu_get(struct xlate_cfg
*, &xcfgp
);
1603 struct xbundle
*out_xbundle
= xbundle_lookup(xcfg
, out
);
1605 output_normal(ctx
, out_xbundle
, vlan
);
1607 } else if (vlan
!= out_vlan
1608 && !eth_addr_is_reserved(ctx
->xin
->flow
.dl_dst
)) {
1609 struct xbundle
*xbundle
;
1611 LIST_FOR_EACH (xbundle
, list_node
, &xbridge
->xbundles
) {
1612 if (xbundle_includes_vlan(xbundle
, out_vlan
)
1613 && !xbundle_mirror_out(xbridge
, xbundle
)) {
1614 output_normal(ctx
, xbundle
, out_vlan
);
1622 mirror_ingress_packet(struct xlate_ctx
*ctx
)
1624 if (mbridge_has_mirrors(ctx
->xbridge
->mbridge
)) {
1625 bool warn
= ctx
->xin
->packet
!= NULL
;
1626 struct xbundle
*xbundle
= lookup_input_bundle(
1627 ctx
->xbridge
, ctx
->xin
->flow
.in_port
.ofp_port
, warn
, NULL
);
1629 mirror_packet(ctx
, xbundle
,
1630 xbundle_mirror_src(ctx
->xbridge
, xbundle
));
1635 /* Given 'vid', the VID obtained from the 802.1Q header that was received as
1636 * part of a packet (specify 0 if there was no 802.1Q header), and 'in_xbundle',
1637 * the bundle on which the packet was received, returns the VLAN to which the
1640 * Both 'vid' and the return value are in the range 0...4095. */
1642 input_vid_to_vlan(const struct xbundle
*in_xbundle
, uint16_t vid
)
1644 switch (in_xbundle
->vlan_mode
) {
1645 case PORT_VLAN_ACCESS
:
1646 return in_xbundle
->vlan
;
1649 case PORT_VLAN_TRUNK
:
1652 case PORT_VLAN_NATIVE_UNTAGGED
:
1653 case PORT_VLAN_NATIVE_TAGGED
:
1654 return vid
? vid
: in_xbundle
->vlan
;
1661 /* Checks whether a packet with the given 'vid' may ingress on 'in_xbundle'.
1662 * If so, returns true. Otherwise, returns false and, if 'warn' is true, logs
1665 * 'vid' should be the VID obtained from the 802.1Q header that was received as
1666 * part of a packet (specify 0 if there was no 802.1Q header), in the range
1669 input_vid_is_valid(uint16_t vid
, struct xbundle
*in_xbundle
, bool warn
)
1671 /* Allow any VID on the OFPP_NONE port. */
1672 if (in_xbundle
== &ofpp_none_bundle
) {
1676 switch (in_xbundle
->vlan_mode
) {
1677 case PORT_VLAN_ACCESS
:
1680 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 5);
1681 VLOG_WARN_RL(&rl
, "dropping VLAN %"PRIu16
" tagged "
1682 "packet received on port %s configured as VLAN "
1683 "%"PRIu16
" access port", vid
, in_xbundle
->name
,
1690 case PORT_VLAN_NATIVE_UNTAGGED
:
1691 case PORT_VLAN_NATIVE_TAGGED
:
1693 /* Port must always carry its native VLAN. */
1697 case PORT_VLAN_TRUNK
:
1698 if (!xbundle_includes_vlan(in_xbundle
, vid
)) {
1700 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 5);
1701 VLOG_WARN_RL(&rl
, "dropping VLAN %"PRIu16
" packet "
1702 "received on port %s not configured for trunking "
1703 "VLAN %"PRIu16
, vid
, in_xbundle
->name
, vid
);
1715 /* Given 'vlan', the VLAN that a packet belongs to, and
1716 * 'out_xbundle', a bundle on which the packet is to be output, returns the VID
1717 * that should be included in the 802.1Q header. (If the return value is 0,
1718 * then the 802.1Q header should only be included in the packet if there is a
1721 * Both 'vlan' and the return value are in the range 0...4095. */
1723 output_vlan_to_vid(const struct xbundle
*out_xbundle
, uint16_t vlan
)
1725 switch (out_xbundle
->vlan_mode
) {
1726 case PORT_VLAN_ACCESS
:
1729 case PORT_VLAN_TRUNK
:
1730 case PORT_VLAN_NATIVE_TAGGED
:
1733 case PORT_VLAN_NATIVE_UNTAGGED
:
1734 return vlan
== out_xbundle
->vlan
? 0 : vlan
;
1742 output_normal(struct xlate_ctx
*ctx
, const struct xbundle
*out_xbundle
,
1745 ovs_be16
*flow_tci
= &ctx
->xin
->flow
.vlan_tci
;
1747 ovs_be16 tci
, old_tci
;
1748 struct xport
*xport
;
1749 struct xlate_bond_recirc xr
;
1750 bool use_recirc
= false;
1752 vid
= output_vlan_to_vid(out_xbundle
, vlan
);
1753 if (list_is_empty(&out_xbundle
->xports
)) {
1754 /* Partially configured bundle with no slaves. Drop the packet. */
1756 } else if (!out_xbundle
->bond
) {
1757 xport
= CONTAINER_OF(list_front(&out_xbundle
->xports
), struct xport
,
1760 struct xlate_cfg
*xcfg
= ovsrcu_get(struct xlate_cfg
*, &xcfgp
);
1761 struct flow_wildcards
*wc
= ctx
->wc
;
1762 struct ofport_dpif
*ofport
;
1764 if (ctx
->xbridge
->support
.odp
.recirc
) {
1765 use_recirc
= bond_may_recirc(
1766 out_xbundle
->bond
, &xr
.recirc_id
, &xr
.hash_basis
);
1769 /* Only TCP mode uses recirculation. */
1770 xr
.hash_alg
= OVS_HASH_ALG_L4
;
1771 bond_update_post_recirc_rules(out_xbundle
->bond
, false);
1773 /* Recirculation does not require unmasking hash fields. */
1778 ofport
= bond_choose_output_slave(out_xbundle
->bond
,
1779 &ctx
->xin
->flow
, wc
, vid
);
1780 xport
= xport_lookup(xcfg
, ofport
);
1783 /* No slaves enabled, so drop packet. */
1787 /* If use_recirc is set, the main thread will handle stats
1788 * accounting for this bond. */
1790 if (ctx
->xin
->resubmit_stats
) {
1791 bond_account(out_xbundle
->bond
, &ctx
->xin
->flow
, vid
,
1792 ctx
->xin
->resubmit_stats
->n_bytes
);
1794 if (ctx
->xin
->xcache
) {
1795 struct xc_entry
*entry
;
1798 flow
= &ctx
->xin
->flow
;
1799 entry
= xlate_cache_add_entry(ctx
->xin
->xcache
, XC_BOND
);
1800 entry
->u
.bond
.bond
= bond_ref(out_xbundle
->bond
);
1801 entry
->u
.bond
.flow
= xmemdup(flow
, sizeof *flow
);
1802 entry
->u
.bond
.vid
= vid
;
1807 old_tci
= *flow_tci
;
1809 if (tci
|| out_xbundle
->use_priority_tags
) {
1810 tci
|= *flow_tci
& htons(VLAN_PCP_MASK
);
1812 tci
|= htons(VLAN_CFI
);
1817 compose_output_action(ctx
, xport
->ofp_port
, use_recirc
? &xr
: NULL
);
1818 *flow_tci
= old_tci
;
1821 /* A VM broadcasts a gratuitous ARP to indicate that it has resumed after
1822 * migration. Older Citrix-patched Linux DomU used gratuitous ARP replies to
1823 * indicate this; newer upstream kernels use gratuitous ARP requests. */
1825 is_gratuitous_arp(const struct flow
*flow
, struct flow_wildcards
*wc
)
1827 if (flow
->dl_type
!= htons(ETH_TYPE_ARP
)) {
1831 memset(&wc
->masks
.dl_dst
, 0xff, sizeof wc
->masks
.dl_dst
);
1832 if (!eth_addr_is_broadcast(flow
->dl_dst
)) {
1836 memset(&wc
->masks
.nw_proto
, 0xff, sizeof wc
->masks
.nw_proto
);
1837 if (flow
->nw_proto
== ARP_OP_REPLY
) {
1839 } else if (flow
->nw_proto
== ARP_OP_REQUEST
) {
1840 memset(&wc
->masks
.nw_src
, 0xff, sizeof wc
->masks
.nw_src
);
1841 memset(&wc
->masks
.nw_dst
, 0xff, sizeof wc
->masks
.nw_dst
);
1843 return flow
->nw_src
== flow
->nw_dst
;
1849 /* Determines whether packets in 'flow' within 'xbridge' should be forwarded or
1850 * dropped. Returns true if they may be forwarded, false if they should be
1853 * 'in_port' must be the xport that corresponds to flow->in_port.
1854 * 'in_port' must be part of a bundle (e.g. in_port->bundle must be nonnull).
1856 * 'vlan' must be the VLAN that corresponds to flow->vlan_tci on 'in_port', as
1857 * returned by input_vid_to_vlan(). It must be a valid VLAN for 'in_port', as
1858 * checked by input_vid_is_valid().
1860 * May also add tags to '*tags', although the current implementation only does
1861 * so in one special case.
1864 is_admissible(struct xlate_ctx
*ctx
, struct xport
*in_port
,
1867 struct xbundle
*in_xbundle
= in_port
->xbundle
;
1868 const struct xbridge
*xbridge
= ctx
->xbridge
;
1869 struct flow
*flow
= &ctx
->xin
->flow
;
1871 /* Drop frames for reserved multicast addresses
1872 * only if forward_bpdu option is absent. */
1873 if (!xbridge
->forward_bpdu
&& eth_addr_is_reserved(flow
->dl_dst
)) {
1874 xlate_report(ctx
, "packet has reserved destination MAC, dropping");
1878 if (in_xbundle
->bond
) {
1879 struct mac_entry
*mac
;
1881 switch (bond_check_admissibility(in_xbundle
->bond
, in_port
->ofport
,
1887 xlate_report(ctx
, "bonding refused admissibility, dropping");
1890 case BV_DROP_IF_MOVED
:
1891 ovs_rwlock_rdlock(&xbridge
->ml
->rwlock
);
1892 mac
= mac_learning_lookup(xbridge
->ml
, flow
->dl_src
, vlan
);
1894 && mac_entry_get_port(xbridge
->ml
, mac
) != in_xbundle
->ofbundle
1895 && (!is_gratuitous_arp(flow
, ctx
->wc
)
1896 || mac_entry_is_grat_arp_locked(mac
))) {
1897 ovs_rwlock_unlock(&xbridge
->ml
->rwlock
);
1898 xlate_report(ctx
, "SLB bond thinks this packet looped back, "
1902 ovs_rwlock_unlock(&xbridge
->ml
->rwlock
);
1910 /* Checks whether a MAC learning update is necessary for MAC learning table
1911 * 'ml' given that a packet matching 'flow' was received on 'in_xbundle' in
1914 * Most packets processed through the MAC learning table do not actually
1915 * change it in any way. This function requires only a read lock on the MAC
1916 * learning table, so it is much cheaper in this common case.
1918 * Keep the code here synchronized with that in update_learning_table__()
1921 is_mac_learning_update_needed(const struct mac_learning
*ml
,
1922 const struct flow
*flow
,
1923 struct flow_wildcards
*wc
,
1924 int vlan
, struct xbundle
*in_xbundle
)
1925 OVS_REQ_RDLOCK(ml
->rwlock
)
1927 struct mac_entry
*mac
;
1929 if (!mac_learning_may_learn(ml
, flow
->dl_src
, vlan
)) {
1933 mac
= mac_learning_lookup(ml
, flow
->dl_src
, vlan
);
1934 if (!mac
|| mac_entry_age(ml
, mac
)) {
1938 if (is_gratuitous_arp(flow
, wc
)) {
1939 /* We don't want to learn from gratuitous ARP packets that are
1940 * reflected back over bond slaves so we lock the learning table. */
1941 if (!in_xbundle
->bond
) {
1943 } else if (mac_entry_is_grat_arp_locked(mac
)) {
1948 return mac_entry_get_port(ml
, mac
) != in_xbundle
->ofbundle
;
1952 /* Updates MAC learning table 'ml' given that a packet matching 'flow' was
1953 * received on 'in_xbundle' in 'vlan'.
1955 * This code repeats all the checks in is_mac_learning_update_needed() because
1956 * the lock was released between there and here and thus the MAC learning state
1957 * could have changed.
1959 * Keep the code here synchronized with that in is_mac_learning_update_needed()
1962 update_learning_table__(const struct xbridge
*xbridge
,
1963 const struct flow
*flow
, struct flow_wildcards
*wc
,
1964 int vlan
, struct xbundle
*in_xbundle
)
1965 OVS_REQ_WRLOCK(xbridge
->ml
->rwlock
)
1967 struct mac_entry
*mac
;
1969 if (!mac_learning_may_learn(xbridge
->ml
, flow
->dl_src
, vlan
)) {
1973 mac
= mac_learning_insert(xbridge
->ml
, flow
->dl_src
, vlan
);
1974 if (is_gratuitous_arp(flow
, wc
)) {
1975 /* We don't want to learn from gratuitous ARP packets that are
1976 * reflected back over bond slaves so we lock the learning table. */
1977 if (!in_xbundle
->bond
) {
1978 mac_entry_set_grat_arp_lock(mac
);
1979 } else if (mac_entry_is_grat_arp_locked(mac
)) {
1984 if (mac_entry_get_port(xbridge
->ml
, mac
) != in_xbundle
->ofbundle
) {
1985 /* The log messages here could actually be useful in debugging,
1986 * so keep the rate limit relatively high. */
1987 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(30, 300);
1989 VLOG_DBG_RL(&rl
, "bridge %s: learned that "ETH_ADDR_FMT
" is "
1990 "on port %s in VLAN %d",
1991 xbridge
->name
, ETH_ADDR_ARGS(flow
->dl_src
),
1992 in_xbundle
->name
, vlan
);
1994 mac_entry_set_port(xbridge
->ml
, mac
, in_xbundle
->ofbundle
);
1999 update_learning_table(const struct xbridge
*xbridge
,
2000 const struct flow
*flow
, struct flow_wildcards
*wc
,
2001 int vlan
, struct xbundle
*in_xbundle
)
2005 /* Don't learn the OFPP_NONE port. */
2006 if (in_xbundle
== &ofpp_none_bundle
) {
2010 /* First try the common case: no change to MAC learning table. */
2011 ovs_rwlock_rdlock(&xbridge
->ml
->rwlock
);
2012 need_update
= is_mac_learning_update_needed(xbridge
->ml
, flow
, wc
, vlan
,
2014 ovs_rwlock_unlock(&xbridge
->ml
->rwlock
);
2017 /* Slow path: MAC learning table might need an update. */
2018 ovs_rwlock_wrlock(&xbridge
->ml
->rwlock
);
2019 update_learning_table__(xbridge
, flow
, wc
, vlan
, in_xbundle
);
2020 ovs_rwlock_unlock(&xbridge
->ml
->rwlock
);
2024 /* Updates multicast snooping table 'ms' given that a packet matching 'flow'
2025 * was received on 'in_xbundle' in 'vlan' and is either Report or Query. */
2027 update_mcast_snooping_table4__(const struct xbridge
*xbridge
,
2028 const struct flow
*flow
,
2029 struct mcast_snooping
*ms
, int vlan
,
2030 struct xbundle
*in_xbundle
,
2031 const struct dp_packet
*packet
)
2032 OVS_REQ_WRLOCK(ms
->rwlock
)
2034 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(60, 30);
2036 ovs_be32 ip4
= flow
->igmp_group_ip4
;
2038 switch (ntohs(flow
->tp_src
)) {
2039 case IGMP_HOST_MEMBERSHIP_REPORT
:
2040 case IGMPV2_HOST_MEMBERSHIP_REPORT
:
2041 if (mcast_snooping_add_group4(ms
, ip4
, vlan
, in_xbundle
->ofbundle
)) {
2042 VLOG_DBG_RL(&rl
, "bridge %s: multicast snooping learned that "
2043 IP_FMT
" is on port %s in VLAN %d",
2044 xbridge
->name
, IP_ARGS(ip4
), in_xbundle
->name
, vlan
);
2047 case IGMP_HOST_LEAVE_MESSAGE
:
2048 if (mcast_snooping_leave_group4(ms
, ip4
, vlan
, in_xbundle
->ofbundle
)) {
2049 VLOG_DBG_RL(&rl
, "bridge %s: multicast snooping leaving "
2050 IP_FMT
" is on port %s in VLAN %d",
2051 xbridge
->name
, IP_ARGS(ip4
), in_xbundle
->name
, vlan
);
2054 case IGMP_HOST_MEMBERSHIP_QUERY
:
2055 if (flow
->nw_src
&& mcast_snooping_add_mrouter(ms
, vlan
,
2056 in_xbundle
->ofbundle
)) {
2057 VLOG_DBG_RL(&rl
, "bridge %s: multicast snooping query from "
2058 IP_FMT
" is on port %s in VLAN %d",
2059 xbridge
->name
, IP_ARGS(flow
->nw_src
),
2060 in_xbundle
->name
, vlan
);
2063 case IGMPV3_HOST_MEMBERSHIP_REPORT
:
2064 if ((count
= mcast_snooping_add_report(ms
, packet
, vlan
,
2065 in_xbundle
->ofbundle
))) {
2066 VLOG_DBG_RL(&rl
, "bridge %s: multicast snooping processed %d "
2067 "addresses on port %s in VLAN %d",
2068 xbridge
->name
, count
, in_xbundle
->name
, vlan
);
2075 update_mcast_snooping_table6__(const struct xbridge
*xbridge
,
2076 const struct flow
*flow
,
2077 struct mcast_snooping
*ms
, int vlan
,
2078 struct xbundle
*in_xbundle
,
2079 const struct dp_packet
*packet
)
2080 OVS_REQ_WRLOCK(ms
->rwlock
)
2082 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(60, 30);
2085 switch (ntohs(flow
->tp_src
)) {
2087 if (!ipv6_addr_equals(&flow
->ipv6_src
, &in6addr_any
)
2088 && mcast_snooping_add_mrouter(ms
, vlan
, in_xbundle
->ofbundle
)) {
2089 VLOG_DBG_RL(&rl
, "bridge %s: multicast snooping query on port %s"
2091 xbridge
->name
, in_xbundle
->name
, vlan
);
2097 count
= mcast_snooping_add_mld(ms
, packet
, vlan
, in_xbundle
->ofbundle
);
2099 VLOG_DBG_RL(&rl
, "bridge %s: multicast snooping processed %d "
2100 "addresses on port %s in VLAN %d",
2101 xbridge
->name
, count
, in_xbundle
->name
, vlan
);
2107 /* Updates multicast snooping table 'ms' given that a packet matching 'flow'
2108 * was received on 'in_xbundle' in 'vlan'. */
2110 update_mcast_snooping_table(const struct xbridge
*xbridge
,
2111 const struct flow
*flow
, int vlan
,
2112 struct xbundle
*in_xbundle
,
2113 const struct dp_packet
*packet
)
2115 struct mcast_snooping
*ms
= xbridge
->ms
;
2116 struct xlate_cfg
*xcfg
;
2117 struct xbundle
*mcast_xbundle
;
2118 struct mcast_port_bundle
*fport
;
2120 /* Don't learn the OFPP_NONE port. */
2121 if (in_xbundle
== &ofpp_none_bundle
) {
2125 /* Don't learn from flood ports */
2126 mcast_xbundle
= NULL
;
2127 ovs_rwlock_wrlock(&ms
->rwlock
);
2128 xcfg
= ovsrcu_get(struct xlate_cfg
*, &xcfgp
);
2129 LIST_FOR_EACH(fport
, node
, &ms
->fport_list
) {
2130 mcast_xbundle
= xbundle_lookup(xcfg
, fport
->port
);
2131 if (mcast_xbundle
== in_xbundle
) {
2136 if (!mcast_xbundle
|| mcast_xbundle
!= in_xbundle
) {
2137 if (flow
->dl_type
== htons(ETH_TYPE_IP
)) {
2138 update_mcast_snooping_table4__(xbridge
, flow
, ms
, vlan
,
2139 in_xbundle
, packet
);
2141 update_mcast_snooping_table6__(xbridge
, flow
, ms
, vlan
,
2142 in_xbundle
, packet
);
2145 ovs_rwlock_unlock(&ms
->rwlock
);
2148 /* send the packet to ports having the multicast group learned */
2150 xlate_normal_mcast_send_group(struct xlate_ctx
*ctx
,
2151 struct mcast_snooping
*ms OVS_UNUSED
,
2152 struct mcast_group
*grp
,
2153 struct xbundle
*in_xbundle
, uint16_t vlan
)
2154 OVS_REQ_RDLOCK(ms
->rwlock
)
2156 struct xlate_cfg
*xcfg
;
2157 struct mcast_group_bundle
*b
;
2158 struct xbundle
*mcast_xbundle
;
2160 xcfg
= ovsrcu_get(struct xlate_cfg
*, &xcfgp
);
2161 LIST_FOR_EACH(b
, bundle_node
, &grp
->bundle_lru
) {
2162 mcast_xbundle
= xbundle_lookup(xcfg
, b
->port
);
2163 if (mcast_xbundle
&& mcast_xbundle
!= in_xbundle
) {
2164 xlate_report(ctx
, "forwarding to mcast group port");
2165 output_normal(ctx
, mcast_xbundle
, vlan
);
2166 } else if (!mcast_xbundle
) {
2167 xlate_report(ctx
, "mcast group port is unknown, dropping");
2169 xlate_report(ctx
, "mcast group port is input port, dropping");
2174 /* send the packet to ports connected to multicast routers */
2176 xlate_normal_mcast_send_mrouters(struct xlate_ctx
*ctx
,
2177 struct mcast_snooping
*ms
,
2178 struct xbundle
*in_xbundle
, uint16_t vlan
)
2179 OVS_REQ_RDLOCK(ms
->rwlock
)
2181 struct xlate_cfg
*xcfg
;
2182 struct mcast_mrouter_bundle
*mrouter
;
2183 struct xbundle
*mcast_xbundle
;
2185 xcfg
= ovsrcu_get(struct xlate_cfg
*, &xcfgp
);
2186 LIST_FOR_EACH(mrouter
, mrouter_node
, &ms
->mrouter_lru
) {
2187 mcast_xbundle
= xbundle_lookup(xcfg
, mrouter
->port
);
2188 if (mcast_xbundle
&& mcast_xbundle
!= in_xbundle
) {
2189 xlate_report(ctx
, "forwarding to mcast router port");
2190 output_normal(ctx
, mcast_xbundle
, vlan
);
2191 } else if (!mcast_xbundle
) {
2192 xlate_report(ctx
, "mcast router port is unknown, dropping");
2194 xlate_report(ctx
, "mcast router port is input port, dropping");
2199 /* send the packet to ports flagged to be flooded */
2201 xlate_normal_mcast_send_fports(struct xlate_ctx
*ctx
,
2202 struct mcast_snooping
*ms
,
2203 struct xbundle
*in_xbundle
, uint16_t vlan
)
2204 OVS_REQ_RDLOCK(ms
->rwlock
)
2206 struct xlate_cfg
*xcfg
;
2207 struct mcast_port_bundle
*fport
;
2208 struct xbundle
*mcast_xbundle
;
2210 xcfg
= ovsrcu_get(struct xlate_cfg
*, &xcfgp
);
2211 LIST_FOR_EACH(fport
, node
, &ms
->fport_list
) {
2212 mcast_xbundle
= xbundle_lookup(xcfg
, fport
->port
);
2213 if (mcast_xbundle
&& mcast_xbundle
!= in_xbundle
) {
2214 xlate_report(ctx
, "forwarding to mcast flood port");
2215 output_normal(ctx
, mcast_xbundle
, vlan
);
2216 } else if (!mcast_xbundle
) {
2217 xlate_report(ctx
, "mcast flood port is unknown, dropping");
2219 xlate_report(ctx
, "mcast flood port is input port, dropping");
2224 /* forward the Reports to configured ports */
2226 xlate_normal_mcast_send_rports(struct xlate_ctx
*ctx
,
2227 struct mcast_snooping
*ms
,
2228 struct xbundle
*in_xbundle
, uint16_t vlan
)
2229 OVS_REQ_RDLOCK(ms
->rwlock
)
2231 struct xlate_cfg
*xcfg
;
2232 struct mcast_port_bundle
*rport
;
2233 struct xbundle
*mcast_xbundle
;
2235 xcfg
= ovsrcu_get(struct xlate_cfg
*, &xcfgp
);
2236 LIST_FOR_EACH(rport
, node
, &ms
->rport_list
) {
2237 mcast_xbundle
= xbundle_lookup(xcfg
, rport
->port
);
2238 if (mcast_xbundle
&& mcast_xbundle
!= in_xbundle
) {
2239 xlate_report(ctx
, "forwarding Report to mcast flagged port");
2240 output_normal(ctx
, mcast_xbundle
, vlan
);
2241 } else if (!mcast_xbundle
) {
2242 xlate_report(ctx
, "mcast port is unknown, dropping the Report");
2244 xlate_report(ctx
, "mcast port is input port, dropping the Report");
2250 xlate_normal_flood(struct xlate_ctx
*ctx
, struct xbundle
*in_xbundle
,
2253 struct xbundle
*xbundle
;
2255 LIST_FOR_EACH (xbundle
, list_node
, &ctx
->xbridge
->xbundles
) {
2256 if (xbundle
!= in_xbundle
2257 && xbundle_includes_vlan(xbundle
, vlan
)
2258 && xbundle
->floodable
2259 && !xbundle_mirror_out(ctx
->xbridge
, xbundle
)) {
2260 output_normal(ctx
, xbundle
, vlan
);
2263 ctx
->nf_output_iface
= NF_OUT_FLOOD
;
2267 xlate_normal(struct xlate_ctx
*ctx
)
2269 struct flow_wildcards
*wc
= ctx
->wc
;
2270 struct flow
*flow
= &ctx
->xin
->flow
;
2271 struct xbundle
*in_xbundle
;
2272 struct xport
*in_port
;
2273 struct mac_entry
*mac
;
2278 memset(&wc
->masks
.dl_src
, 0xff, sizeof wc
->masks
.dl_src
);
2279 memset(&wc
->masks
.dl_dst
, 0xff, sizeof wc
->masks
.dl_dst
);
2280 wc
->masks
.vlan_tci
|= htons(VLAN_VID_MASK
| VLAN_CFI
);
2282 in_xbundle
= lookup_input_bundle(ctx
->xbridge
, flow
->in_port
.ofp_port
,
2283 ctx
->xin
->packet
!= NULL
, &in_port
);
2285 xlate_report(ctx
, "no input bundle, dropping");
2289 /* Drop malformed frames. */
2290 if (flow
->dl_type
== htons(ETH_TYPE_VLAN
) &&
2291 !(flow
->vlan_tci
& htons(VLAN_CFI
))) {
2292 if (ctx
->xin
->packet
!= NULL
) {
2293 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 5);
2294 VLOG_WARN_RL(&rl
, "bridge %s: dropping packet with partial "
2295 "VLAN tag received on port %s",
2296 ctx
->xbridge
->name
, in_xbundle
->name
);
2298 xlate_report(ctx
, "partial VLAN tag, dropping");
2302 /* Drop frames on bundles reserved for mirroring. */
2303 if (xbundle_mirror_out(ctx
->xbridge
, in_xbundle
)) {
2304 if (ctx
->xin
->packet
!= NULL
) {
2305 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 5);
2306 VLOG_WARN_RL(&rl
, "bridge %s: dropping packet received on port "
2307 "%s, which is reserved exclusively for mirroring",
2308 ctx
->xbridge
->name
, in_xbundle
->name
);
2310 xlate_report(ctx
, "input port is mirror output port, dropping");
2315 vid
= vlan_tci_to_vid(flow
->vlan_tci
);
2316 if (!input_vid_is_valid(vid
, in_xbundle
, ctx
->xin
->packet
!= NULL
)) {
2317 xlate_report(ctx
, "disallowed VLAN VID for this input port, dropping");
2320 vlan
= input_vid_to_vlan(in_xbundle
, vid
);
2322 /* Check other admissibility requirements. */
2323 if (in_port
&& !is_admissible(ctx
, in_port
, vlan
)) {
2327 /* Learn source MAC. */
2328 if (ctx
->xin
->may_learn
) {
2329 update_learning_table(ctx
->xbridge
, flow
, wc
, vlan
, in_xbundle
);
2331 if (ctx
->xin
->xcache
) {
2332 struct xc_entry
*entry
;
2334 /* Save enough info to update mac learning table later. */
2335 entry
= xlate_cache_add_entry(ctx
->xin
->xcache
, XC_NORMAL
);
2336 entry
->u
.normal
.ofproto
= ctx
->xbridge
->ofproto
;
2337 entry
->u
.normal
.flow
= xmemdup(flow
, sizeof *flow
);
2338 entry
->u
.normal
.vlan
= vlan
;
2341 /* Determine output bundle. */
2342 if (mcast_snooping_enabled(ctx
->xbridge
->ms
)
2343 && !eth_addr_is_broadcast(flow
->dl_dst
)
2344 && eth_addr_is_multicast(flow
->dl_dst
)
2345 && is_ip_any(flow
)) {
2346 struct mcast_snooping
*ms
= ctx
->xbridge
->ms
;
2347 struct mcast_group
*grp
= NULL
;
2349 if (is_igmp(flow
)) {
2350 if (mcast_snooping_is_membership(flow
->tp_src
) ||
2351 mcast_snooping_is_query(flow
->tp_src
)) {
2352 if (ctx
->xin
->may_learn
) {
2353 update_mcast_snooping_table(ctx
->xbridge
, flow
, vlan
,
2354 in_xbundle
, ctx
->xin
->packet
);
2357 * IGMP packets need to take the slow path, in order to be
2358 * processed for mdb updates. That will prevent expires
2359 * firing off even after hosts have sent reports.
2361 ctx
->xout
->slow
|= SLOW_ACTION
;
2364 if (mcast_snooping_is_membership(flow
->tp_src
)) {
2365 ovs_rwlock_rdlock(&ms
->rwlock
);
2366 xlate_normal_mcast_send_mrouters(ctx
, ms
, in_xbundle
, vlan
);
2367 /* RFC4541: section 2.1.1, item 1: A snooping switch should
2368 * forward IGMP Membership Reports only to those ports where
2369 * multicast routers are attached. Alternatively stated: a
2370 * snooping switch should not forward IGMP Membership Reports
2371 * to ports on which only hosts are attached.
2372 * An administrative control may be provided to override this
2373 * restriction, allowing the report messages to be flooded to
2375 xlate_normal_mcast_send_rports(ctx
, ms
, in_xbundle
, vlan
);
2376 ovs_rwlock_unlock(&ms
->rwlock
);
2378 xlate_report(ctx
, "multicast traffic, flooding");
2379 xlate_normal_flood(ctx
, in_xbundle
, vlan
);
2382 } else if (is_mld(flow
)) {
2383 ctx
->xout
->slow
|= SLOW_ACTION
;
2384 if (ctx
->xin
->may_learn
) {
2385 update_mcast_snooping_table(ctx
->xbridge
, flow
, vlan
,
2386 in_xbundle
, ctx
->xin
->packet
);
2388 if (is_mld_report(flow
)) {
2389 ovs_rwlock_rdlock(&ms
->rwlock
);
2390 xlate_normal_mcast_send_mrouters(ctx
, ms
, in_xbundle
, vlan
);
2391 xlate_normal_mcast_send_rports(ctx
, ms
, in_xbundle
, vlan
);
2392 ovs_rwlock_unlock(&ms
->rwlock
);
2394 xlate_report(ctx
, "MLD query, flooding");
2395 xlate_normal_flood(ctx
, in_xbundle
, vlan
);
2398 if ((flow
->dl_type
== htons(ETH_TYPE_IP
)
2399 && ip_is_local_multicast(flow
->nw_dst
))
2400 || (flow
->dl_type
== htons(ETH_TYPE_IPV6
)
2401 && ipv6_is_all_hosts(&flow
->ipv6_dst
))) {
2402 /* RFC4541: section 2.1.2, item 2: Packets with a dst IP
2403 * address in the 224.0.0.x range which are not IGMP must
2404 * be forwarded on all ports */
2405 xlate_report(ctx
, "RFC4541: section 2.1.2, item 2, flooding");
2406 xlate_normal_flood(ctx
, in_xbundle
, vlan
);
2411 /* forwarding to group base ports */
2412 ovs_rwlock_rdlock(&ms
->rwlock
);
2413 if (flow
->dl_type
== htons(ETH_TYPE_IP
)) {
2414 grp
= mcast_snooping_lookup4(ms
, flow
->nw_dst
, vlan
);
2415 } else if (flow
->dl_type
== htons(ETH_TYPE_IPV6
)) {
2416 grp
= mcast_snooping_lookup(ms
, &flow
->ipv6_dst
, vlan
);
2419 xlate_normal_mcast_send_group(ctx
, ms
, grp
, in_xbundle
, vlan
);
2420 xlate_normal_mcast_send_fports(ctx
, ms
, in_xbundle
, vlan
);
2421 xlate_normal_mcast_send_mrouters(ctx
, ms
, in_xbundle
, vlan
);
2423 if (mcast_snooping_flood_unreg(ms
)) {
2424 xlate_report(ctx
, "unregistered multicast, flooding");
2425 xlate_normal_flood(ctx
, in_xbundle
, vlan
);
2427 xlate_normal_mcast_send_mrouters(ctx
, ms
, in_xbundle
, vlan
);
2428 xlate_normal_mcast_send_fports(ctx
, ms
, in_xbundle
, vlan
);
2431 ovs_rwlock_unlock(&ms
->rwlock
);
2433 ovs_rwlock_rdlock(&ctx
->xbridge
->ml
->rwlock
);
2434 mac
= mac_learning_lookup(ctx
->xbridge
->ml
, flow
->dl_dst
, vlan
);
2435 mac_port
= mac
? mac_entry_get_port(ctx
->xbridge
->ml
, mac
) : NULL
;
2436 ovs_rwlock_unlock(&ctx
->xbridge
->ml
->rwlock
);
2439 struct xlate_cfg
*xcfg
= ovsrcu_get(struct xlate_cfg
*, &xcfgp
);
2440 struct xbundle
*mac_xbundle
= xbundle_lookup(xcfg
, mac_port
);
2441 if (mac_xbundle
&& mac_xbundle
!= in_xbundle
) {
2442 xlate_report(ctx
, "forwarding to learned port");
2443 output_normal(ctx
, mac_xbundle
, vlan
);
2444 } else if (!mac_xbundle
) {
2445 xlate_report(ctx
, "learned port is unknown, dropping");
2447 xlate_report(ctx
, "learned port is input port, dropping");
2450 xlate_report(ctx
, "no learned MAC for destination, flooding");
2451 xlate_normal_flood(ctx
, in_xbundle
, vlan
);
2456 /* Appends a "sample" action for sFlow or IPFIX to 'ctx->odp_actions'. The
2457 * 'probability' is the number of packets out of UINT32_MAX to sample. The
2458 * 'cookie' (of length 'cookie_size' bytes) is passed back in the callback for
2459 * each sampled packet. 'tunnel_out_port', if not ODPP_NONE, is added as the
2460 * OVS_USERSPACE_ATTR_EGRESS_TUN_PORT attribute. If 'include_actions', an
2461 * OVS_USERSPACE_ATTR_ACTIONS attribute is added.
2464 compose_sample_action(struct xlate_ctx
*ctx
,
2465 const uint32_t probability
,
2466 const union user_action_cookie
*cookie
,
2467 const size_t cookie_size
,
2468 const odp_port_t tunnel_out_port
,
2469 bool include_actions
)
2471 size_t sample_offset
= nl_msg_start_nested(ctx
->odp_actions
,
2472 OVS_ACTION_ATTR_SAMPLE
);
2474 nl_msg_put_u32(ctx
->odp_actions
, OVS_SAMPLE_ATTR_PROBABILITY
, probability
);
2476 size_t actions_offset
= nl_msg_start_nested(ctx
->odp_actions
,
2477 OVS_SAMPLE_ATTR_ACTIONS
);
2479 odp_port_t odp_port
= ofp_port_to_odp_port(
2480 ctx
->xbridge
, ctx
->xin
->flow
.in_port
.ofp_port
);
2481 uint32_t pid
= dpif_port_get_pid(ctx
->xbridge
->dpif
, odp_port
,
2482 flow_hash_5tuple(&ctx
->xin
->flow
, 0));
2483 int cookie_offset
= odp_put_userspace_action(pid
, cookie
, cookie_size
,
2488 nl_msg_end_nested(ctx
->odp_actions
, actions_offset
);
2489 nl_msg_end_nested(ctx
->odp_actions
, sample_offset
);
2491 return cookie_offset
;
2494 /* If sFLow is not enabled, returns 0 without doing anything.
2496 * If sFlow is enabled, appends a template "sample" action to the ODP actions
2497 * in 'ctx'. This action is a template because some of the information needed
2498 * to fill it out is not available until flow translation is complete. In this
2499 * case, this functions returns an offset, which is always nonzero, to pass
2500 * later to fix_sflow_action() to fill in the rest of the template. */
2502 compose_sflow_action(struct xlate_ctx
*ctx
)
2504 struct dpif_sflow
*sflow
= ctx
->xbridge
->sflow
;
2505 if (!sflow
|| ctx
->xin
->flow
.in_port
.ofp_port
== OFPP_NONE
) {
2509 union user_action_cookie cookie
= { .type
= USER_ACTION_COOKIE_SFLOW
};
2510 return compose_sample_action(ctx
, dpif_sflow_get_probability(sflow
),
2511 &cookie
, sizeof cookie
.sflow
, ODPP_NONE
,
2515 /* If IPFIX is enabled, this appends a "sample" action to implement IPFIX to
2516 * 'ctx->odp_actions'. */
2518 compose_ipfix_action(struct xlate_ctx
*ctx
, odp_port_t output_odp_port
)
2520 struct dpif_ipfix
*ipfix
= ctx
->xbridge
->ipfix
;
2521 odp_port_t tunnel_out_port
= ODPP_NONE
;
2523 if (!ipfix
|| ctx
->xin
->flow
.in_port
.ofp_port
== OFPP_NONE
) {
2527 /* For input case, output_odp_port is ODPP_NONE, which is an invalid port
2529 if (output_odp_port
== ODPP_NONE
&&
2530 !dpif_ipfix_get_bridge_exporter_input_sampling(ipfix
)) {
2534 /* For output case, output_odp_port is valid*/
2535 if (output_odp_port
!= ODPP_NONE
) {
2536 if (!dpif_ipfix_get_bridge_exporter_output_sampling(ipfix
)) {
2539 /* If tunnel sampling is enabled, put an additional option attribute:
2540 * OVS_USERSPACE_ATTR_TUNNEL_OUT_PORT
2542 if (dpif_ipfix_get_bridge_exporter_tunnel_sampling(ipfix
) &&
2543 dpif_ipfix_get_tunnel_port(ipfix
, output_odp_port
) ) {
2544 tunnel_out_port
= output_odp_port
;
2548 union user_action_cookie cookie
= {
2550 .type
= USER_ACTION_COOKIE_IPFIX
,
2551 .output_odp_port
= output_odp_port
,
2554 compose_sample_action(ctx
,
2555 dpif_ipfix_get_bridge_exporter_probability(ipfix
),
2556 &cookie
, sizeof cookie
.ipfix
, tunnel_out_port
,
2560 /* Fix "sample" action according to data collected while composing ODP actions,
2561 * as described in compose_sflow_action().
2563 * 'user_cookie_offset' must be the offset returned by add_sflow_action(). */
2565 fix_sflow_action(struct xlate_ctx
*ctx
, unsigned int user_cookie_offset
)
2567 const struct flow
*base
= &ctx
->base_flow
;
2568 union user_action_cookie
*cookie
;
2570 cookie
= ofpbuf_at(ctx
->odp_actions
, user_cookie_offset
,
2571 sizeof cookie
->sflow
);
2572 ovs_assert(cookie
->type
== USER_ACTION_COOKIE_SFLOW
);
2574 cookie
->type
= USER_ACTION_COOKIE_SFLOW
;
2575 cookie
->sflow
.vlan_tci
= base
->vlan_tci
;
2577 /* See http://www.sflow.org/sflow_version_5.txt (search for "Input/output
2578 * port information") for the interpretation of cookie->output. */
2579 switch (ctx
->sflow_n_outputs
) {
2581 /* 0x40000000 | 256 means "packet dropped for unknown reason". */
2582 cookie
->sflow
.output
= 0x40000000 | 256;
2586 cookie
->sflow
.output
= dpif_sflow_odp_port_to_ifindex(
2587 ctx
->xbridge
->sflow
, ctx
->sflow_odp_port
);
2588 if (cookie
->sflow
.output
) {
2593 /* 0x80000000 means "multiple output ports. */
2594 cookie
->sflow
.output
= 0x80000000 | ctx
->sflow_n_outputs
;
2600 process_special(struct xlate_ctx
*ctx
, const struct xport
*xport
)
2602 const struct flow
*flow
= &ctx
->xin
->flow
;
2603 struct flow_wildcards
*wc
= ctx
->wc
;
2604 const struct xbridge
*xbridge
= ctx
->xbridge
;
2605 const struct dp_packet
*packet
= ctx
->xin
->packet
;
2606 enum slow_path_reason slow
;
2610 } else if (xport
->cfm
&& cfm_should_process_flow(xport
->cfm
, flow
, wc
)) {
2612 cfm_process_heartbeat(xport
->cfm
, packet
);
2615 } else if (xport
->bfd
&& bfd_should_process_flow(xport
->bfd
, flow
, wc
)) {
2617 bfd_process_packet(xport
->bfd
, flow
, packet
);
2618 /* If POLL received, immediately sends FINAL back. */
2619 if (bfd_should_send_packet(xport
->bfd
)) {
2620 ofproto_dpif_monitor_port_send_soon(xport
->ofport
);
2624 } else if (xport
->xbundle
&& xport
->xbundle
->lacp
2625 && flow
->dl_type
== htons(ETH_TYPE_LACP
)) {
2627 lacp_process_packet(xport
->xbundle
->lacp
, xport
->ofport
, packet
);
2630 } else if ((xbridge
->stp
|| xbridge
->rstp
) &&
2631 stp_should_process_flow(flow
, wc
)) {
2634 ? stp_process_packet(xport
, packet
)
2635 : rstp_process_packet(xport
, packet
);
2638 } else if (xport
->lldp
&& lldp_should_process_flow(xport
->lldp
, flow
)) {
2640 lldp_process_packet(xport
->lldp
, packet
);
2648 ctx
->xout
->slow
|= slow
;
2656 tnl_route_lookup_flow(const struct flow
*oflow
,
2657 ovs_be32
*ip
, struct xport
**out_port
)
2659 char out_dev
[IFNAMSIZ
];
2660 struct xbridge
*xbridge
;
2661 struct xlate_cfg
*xcfg
;
2664 if (!ovs_router_lookup(oflow
->tunnel
.ip_dst
, out_dev
, &gw
)) {
2671 *ip
= oflow
->tunnel
.ip_dst
;
2674 xcfg
= ovsrcu_get(struct xlate_cfg
*, &xcfgp
);
2677 HMAP_FOR_EACH (xbridge
, hmap_node
, &xcfg
->xbridges
) {
2678 if (!strncmp(xbridge
->name
, out_dev
, IFNAMSIZ
)) {
2681 HMAP_FOR_EACH (port
, ofp_node
, &xbridge
->xports
) {
2682 if (!strncmp(netdev_get_name(port
->netdev
), out_dev
, IFNAMSIZ
)) {
2693 compose_table_xlate(struct xlate_ctx
*ctx
, const struct xport
*out_dev
,
2694 struct dp_packet
*packet
)
2696 struct xbridge
*xbridge
= out_dev
->xbridge
;
2697 struct ofpact_output output
;
2700 ofpact_init(&output
.ofpact
, OFPACT_OUTPUT
, sizeof output
);
2701 flow_extract(packet
, &flow
);
2702 flow
.in_port
.ofp_port
= out_dev
->ofp_port
;
2703 output
.port
= OFPP_TABLE
;
2706 return ofproto_dpif_execute_actions__(xbridge
->ofproto
, &flow
, NULL
,
2707 &output
.ofpact
, sizeof output
,
2708 ctx
->recurse
, ctx
->resubmits
, packet
);
2712 tnl_send_arp_request(struct xlate_ctx
*ctx
, const struct xport
*out_dev
,
2713 const struct eth_addr eth_src
,
2714 ovs_be32 ip_src
, ovs_be32 ip_dst
)
2716 struct dp_packet packet
;
2718 dp_packet_init(&packet
, 0);
2719 compose_arp(&packet
, ARP_OP_REQUEST
,
2720 eth_src
, eth_addr_zero
, true, ip_src
, ip_dst
);
2722 compose_table_xlate(ctx
, out_dev
, &packet
);
2723 dp_packet_uninit(&packet
);
2727 build_tunnel_send(struct xlate_ctx
*ctx
, const struct xport
*xport
,
2728 const struct flow
*flow
, odp_port_t tunnel_odp_port
)
2730 struct ovs_action_push_tnl tnl_push_data
;
2731 struct xport
*out_dev
= NULL
;
2732 ovs_be32 s_ip
, d_ip
= 0;
2733 struct eth_addr smac
;
2734 struct eth_addr dmac
;
2737 err
= tnl_route_lookup_flow(flow
, &d_ip
, &out_dev
);
2739 xlate_report(ctx
, "native tunnel routing failed");
2742 xlate_report(ctx
, "tunneling to "IP_FMT
" via %s",
2743 IP_ARGS(d_ip
), netdev_get_name(out_dev
->netdev
));
2745 /* Use mac addr of bridge port of the peer. */
2746 err
= netdev_get_etheraddr(out_dev
->netdev
, &smac
);
2748 xlate_report(ctx
, "tunnel output device lacks Ethernet address");
2752 err
= netdev_get_in4(out_dev
->netdev
, (struct in_addr
*) &s_ip
, NULL
);
2754 xlate_report(ctx
, "tunnel output device lacks IPv4 address");
2758 err
= tnl_arp_lookup(out_dev
->xbridge
->name
, d_ip
, &dmac
);
2760 xlate_report(ctx
, "ARP cache miss for "IP_FMT
" on bridge %s, "
2761 "sending ARP request",
2762 IP_ARGS(d_ip
), out_dev
->xbridge
->name
);
2763 tnl_send_arp_request(ctx
, out_dev
, smac
, s_ip
, d_ip
);
2766 if (ctx
->xin
->xcache
) {
2767 struct xc_entry
*entry
;
2769 entry
= xlate_cache_add_entry(ctx
->xin
->xcache
, XC_TNL_ARP
);
2770 ovs_strlcpy(entry
->u
.tnl_arp_cache
.br_name
, out_dev
->xbridge
->name
,
2771 sizeof entry
->u
.tnl_arp_cache
.br_name
);
2772 entry
->u
.tnl_arp_cache
.d_ip
= d_ip
;
2775 xlate_report(ctx
, "tunneling from "ETH_ADDR_FMT
" "IP_FMT
2776 " to "ETH_ADDR_FMT
" "IP_FMT
,
2777 ETH_ADDR_ARGS(smac
), IP_ARGS(s_ip
),
2778 ETH_ADDR_ARGS(dmac
), IP_ARGS(d_ip
));
2779 err
= tnl_port_build_header(xport
->ofport
, flow
,
2780 dmac
, smac
, s_ip
, &tnl_push_data
);
2784 tnl_push_data
.tnl_port
= odp_to_u32(tunnel_odp_port
);
2785 tnl_push_data
.out_port
= odp_to_u32(out_dev
->odp_port
);
2786 odp_put_tnl_push_action(ctx
->odp_actions
, &tnl_push_data
);
2791 xlate_commit_actions(struct xlate_ctx
*ctx
)
2793 bool use_masked
= ctx
->xbridge
->support
.masked_set_action
;
2795 ctx
->xout
->slow
|= commit_odp_actions(&ctx
->xin
->flow
, &ctx
->base_flow
,
2796 ctx
->odp_actions
, ctx
->wc
,
2801 compose_output_action__(struct xlate_ctx
*ctx
, ofp_port_t ofp_port
,
2802 const struct xlate_bond_recirc
*xr
, bool check_stp
)
2804 const struct xport
*xport
= get_ofp_port(ctx
->xbridge
, ofp_port
);
2805 struct flow_wildcards
*wc
= ctx
->wc
;
2806 struct flow
*flow
= &ctx
->xin
->flow
;
2807 struct flow_tnl flow_tnl
;
2808 ovs_be16 flow_vlan_tci
;
2809 uint32_t flow_pkt_mark
;
2810 uint8_t flow_nw_tos
;
2811 odp_port_t out_port
, odp_port
;
2812 bool tnl_push_pop_send
= false;
2815 /* If 'struct flow' gets additional metadata, we'll need to zero it out
2816 * before traversing a patch port. */
2817 BUILD_ASSERT_DECL(FLOW_WC_SEQ
== 33);
2818 memset(&flow_tnl
, 0, sizeof flow_tnl
);
2821 xlate_report(ctx
, "Nonexistent output port");
2823 } else if (xport
->config
& OFPUTIL_PC_NO_FWD
) {
2824 xlate_report(ctx
, "OFPPC_NO_FWD set, skipping output");
2826 } else if (check_stp
) {
2827 if (is_stp(&ctx
->base_flow
)) {
2828 if (!xport_stp_should_forward_bpdu(xport
) &&
2829 !xport_rstp_should_manage_bpdu(xport
)) {
2830 if (ctx
->xbridge
->stp
!= NULL
) {
2831 xlate_report(ctx
, "STP not in listening state, "
2832 "skipping bpdu output");
2833 } else if (ctx
->xbridge
->rstp
!= NULL
) {
2834 xlate_report(ctx
, "RSTP not managing BPDU in this state, "
2835 "skipping bpdu output");
2839 } else if (!xport_stp_forward_state(xport
) ||
2840 !xport_rstp_forward_state(xport
)) {
2841 if (ctx
->xbridge
->stp
!= NULL
) {
2842 xlate_report(ctx
, "STP not in forwarding state, "
2844 } else if (ctx
->xbridge
->rstp
!= NULL
) {
2845 xlate_report(ctx
, "RSTP not in forwarding state, "
2853 const struct xport
*peer
= xport
->peer
;
2854 struct flow old_flow
= ctx
->xin
->flow
;
2855 bool old_was_mpls
= ctx
->was_mpls
;
2856 cls_version_t old_version
= ctx
->tables_version
;
2857 struct ofpbuf old_stack
= ctx
->stack
;
2858 union mf_subvalue new_stack
[1024 / sizeof(union mf_subvalue
)];
2859 struct ofpbuf old_action_set
= ctx
->action_set
;
2860 uint64_t actset_stub
[1024 / 8];
2862 ofpbuf_use_stub(&ctx
->stack
, new_stack
, sizeof new_stack
);
2863 ofpbuf_use_stub(&ctx
->action_set
, actset_stub
, sizeof actset_stub
);
2864 ctx
->xbridge
= peer
->xbridge
;
2865 flow
->in_port
.ofp_port
= peer
->ofp_port
;
2866 flow
->metadata
= htonll(0);
2867 memset(&flow
->tunnel
, 0, sizeof flow
->tunnel
);
2868 memset(flow
->regs
, 0, sizeof flow
->regs
);
2869 flow
->actset_output
= OFPP_UNSET
;
2871 /* The bridge is now known so obtain its table version. */
2873 = ofproto_dpif_get_tables_version(ctx
->xbridge
->ofproto
);
2875 if (!process_special(ctx
, peer
) && may_receive(peer
, ctx
)) {
2876 if (xport_stp_forward_state(peer
) && xport_rstp_forward_state(peer
)) {
2877 xlate_table_action(ctx
, flow
->in_port
.ofp_port
, 0, true, true);
2878 if (ctx
->action_set
.size
) {
2879 /* Translate action set only if not dropping the packet and
2880 * not recirculating. */
2881 if (!exit_recirculates(ctx
)) {
2882 xlate_action_set(ctx
);
2885 /* Check if need to recirculate. */
2886 if (exit_recirculates(ctx
)) {
2887 compose_recirculate_action(ctx
);
2890 /* Forwarding is disabled by STP and RSTP. Let OFPP_NORMAL and
2891 * the learning action look at the packet, then drop it. */
2892 struct flow old_base_flow
= ctx
->base_flow
;
2893 size_t old_size
= ctx
->odp_actions
->size
;
2894 mirror_mask_t old_mirrors
= ctx
->mirrors
;
2896 xlate_table_action(ctx
, flow
->in_port
.ofp_port
, 0, true, true);
2897 ctx
->mirrors
= old_mirrors
;
2898 ctx
->base_flow
= old_base_flow
;
2899 ctx
->odp_actions
->size
= old_size
;
2901 /* Undo changes that may have been done for recirculation. */
2902 if (exit_recirculates(ctx
)) {
2903 ctx
->action_set
.size
= ctx
->recirc_action_offset
;
2904 ctx
->recirc_action_offset
= -1;
2905 ctx
->last_unroll_offset
= -1;
2910 ctx
->xin
->flow
= old_flow
;
2911 ctx
->xbridge
= xport
->xbridge
;
2912 ofpbuf_uninit(&ctx
->action_set
);
2913 ctx
->action_set
= old_action_set
;
2914 ofpbuf_uninit(&ctx
->stack
);
2915 ctx
->stack
= old_stack
;
2917 /* Restore calling bridge's lookup version. */
2918 ctx
->tables_version
= old_version
;
2920 /* The peer bridge popping MPLS should have no effect on the original
2922 ctx
->was_mpls
= old_was_mpls
;
2924 /* The fact that the peer bridge exits (for any reason) does not mean
2925 * that the original bridge should exit. Specifically, if the peer
2926 * bridge recirculates (which typically modifies the packet), the
2927 * original bridge must continue processing with the original, not the
2928 * recirculated packet! */
2931 if (ctx
->xin
->resubmit_stats
) {
2932 netdev_vport_inc_tx(xport
->netdev
, ctx
->xin
->resubmit_stats
);
2933 netdev_vport_inc_rx(peer
->netdev
, ctx
->xin
->resubmit_stats
);
2935 bfd_account_rx(peer
->bfd
, ctx
->xin
->resubmit_stats
);
2938 if (ctx
->xin
->xcache
) {
2939 struct xc_entry
*entry
;
2941 entry
= xlate_cache_add_entry(ctx
->xin
->xcache
, XC_NETDEV
);
2942 entry
->u
.dev
.tx
= netdev_ref(xport
->netdev
);
2943 entry
->u
.dev
.rx
= netdev_ref(peer
->netdev
);
2944 entry
->u
.dev
.bfd
= bfd_ref(peer
->bfd
);
2949 flow_vlan_tci
= flow
->vlan_tci
;
2950 flow_pkt_mark
= flow
->pkt_mark
;
2951 flow_nw_tos
= flow
->nw_tos
;
2953 if (count_skb_priorities(xport
)) {
2954 memset(&wc
->masks
.skb_priority
, 0xff, sizeof wc
->masks
.skb_priority
);
2955 if (dscp_from_skb_priority(xport
, flow
->skb_priority
, &dscp
)) {
2956 wc
->masks
.nw_tos
|= IP_DSCP_MASK
;
2957 flow
->nw_tos
&= ~IP_DSCP_MASK
;
2958 flow
->nw_tos
|= dscp
;
2962 if (xport
->is_tunnel
) {
2963 /* Save tunnel metadata so that changes made due to
2964 * the Logical (tunnel) Port are not visible for any further
2965 * matches, while explicit set actions on tunnel metadata are.
2967 flow_tnl
= flow
->tunnel
;
2968 odp_port
= tnl_port_send(xport
->ofport
, flow
, ctx
->wc
);
2969 if (odp_port
== ODPP_NONE
) {
2970 xlate_report(ctx
, "Tunneling decided against output");
2971 goto out
; /* restore flow_nw_tos */
2973 if (flow
->tunnel
.ip_dst
== ctx
->orig_tunnel_ip_dst
) {
2974 xlate_report(ctx
, "Not tunneling to our own address");
2975 goto out
; /* restore flow_nw_tos */
2977 if (ctx
->xin
->resubmit_stats
) {
2978 netdev_vport_inc_tx(xport
->netdev
, ctx
->xin
->resubmit_stats
);
2980 if (ctx
->xin
->xcache
) {
2981 struct xc_entry
*entry
;
2983 entry
= xlate_cache_add_entry(ctx
->xin
->xcache
, XC_NETDEV
);
2984 entry
->u
.dev
.tx
= netdev_ref(xport
->netdev
);
2986 out_port
= odp_port
;
2987 if (ovs_native_tunneling_is_on(ctx
->xbridge
->ofproto
)) {
2988 xlate_report(ctx
, "output to native tunnel");
2989 tnl_push_pop_send
= true;
2991 xlate_report(ctx
, "output to kernel tunnel");
2992 commit_odp_tunnel_action(flow
, &ctx
->base_flow
, ctx
->odp_actions
);
2993 flow
->tunnel
= flow_tnl
; /* Restore tunnel metadata */
2996 odp_port
= xport
->odp_port
;
2997 out_port
= odp_port
;
2998 if (ofproto_has_vlan_splinters(ctx
->xbridge
->ofproto
)) {
2999 ofp_port_t vlandev_port
;
3001 wc
->masks
.vlan_tci
|= htons(VLAN_VID_MASK
| VLAN_CFI
);
3002 vlandev_port
= vsp_realdev_to_vlandev(ctx
->xbridge
->ofproto
,
3003 ofp_port
, flow
->vlan_tci
);
3004 if (vlandev_port
!= ofp_port
) {
3005 out_port
= ofp_port_to_odp_port(ctx
->xbridge
, vlandev_port
);
3006 flow
->vlan_tci
= htons(0);
3011 if (out_port
!= ODPP_NONE
) {
3012 xlate_commit_actions(ctx
);
3015 struct ovs_action_hash
*act_hash
;
3018 act_hash
= nl_msg_put_unspec_uninit(ctx
->odp_actions
,
3019 OVS_ACTION_ATTR_HASH
,
3021 act_hash
->hash_alg
= xr
->hash_alg
;
3022 act_hash
->hash_basis
= xr
->hash_basis
;
3024 /* Recirc action. */
3025 nl_msg_put_u32(ctx
->odp_actions
, OVS_ACTION_ATTR_RECIRC
,
3029 if (tnl_push_pop_send
) {
3030 build_tunnel_send(ctx
, xport
, flow
, odp_port
);
3031 flow
->tunnel
= flow_tnl
; /* Restore tunnel metadata */
3033 odp_port_t odp_tnl_port
= ODPP_NONE
;
3035 /* XXX: Write better Filter for tunnel port. We can use inport
3036 * int tunnel-port flow to avoid these checks completely. */
3037 if (ofp_port
== OFPP_LOCAL
&&
3038 ovs_native_tunneling_is_on(ctx
->xbridge
->ofproto
)) {
3040 odp_tnl_port
= tnl_port_map_lookup(flow
, wc
);
3043 if (odp_tnl_port
!= ODPP_NONE
) {
3044 nl_msg_put_odp_port(ctx
->odp_actions
,
3045 OVS_ACTION_ATTR_TUNNEL_POP
,
3048 /* Tunnel push-pop action is not compatible with
3050 compose_ipfix_action(ctx
, out_port
);
3051 nl_msg_put_odp_port(ctx
->odp_actions
,
3052 OVS_ACTION_ATTR_OUTPUT
,
3058 ctx
->sflow_odp_port
= odp_port
;
3059 ctx
->sflow_n_outputs
++;
3060 ctx
->nf_output_iface
= ofp_port
;
3063 if (mbridge_has_mirrors(ctx
->xbridge
->mbridge
) && xport
->xbundle
) {
3064 mirror_packet(ctx
, xport
->xbundle
,
3065 xbundle_mirror_dst(xport
->xbundle
->xbridge
,
3071 flow
->vlan_tci
= flow_vlan_tci
;
3072 flow
->pkt_mark
= flow_pkt_mark
;
3073 flow
->nw_tos
= flow_nw_tos
;
3077 compose_output_action(struct xlate_ctx
*ctx
, ofp_port_t ofp_port
,
3078 const struct xlate_bond_recirc
*xr
)
3080 compose_output_action__(ctx
, ofp_port
, xr
, true);
3084 xlate_recursively(struct xlate_ctx
*ctx
, struct rule_dpif
*rule
)
3086 struct rule_dpif
*old_rule
= ctx
->rule
;
3087 ovs_be64 old_cookie
= ctx
->rule_cookie
;
3088 const struct rule_actions
*actions
;
3090 if (ctx
->xin
->resubmit_stats
) {
3091 rule_dpif_credit_stats(rule
, ctx
->xin
->resubmit_stats
);
3097 ctx
->rule_cookie
= rule_dpif_get_flow_cookie(rule
);
3098 actions
= rule_dpif_get_actions(rule
);
3099 do_xlate_actions(actions
->ofpacts
, actions
->ofpacts_len
, ctx
);
3100 ctx
->rule_cookie
= old_cookie
;
3101 ctx
->rule
= old_rule
;
3106 xlate_resubmit_resource_check(struct xlate_ctx
*ctx
)
3108 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 1);
3110 if (ctx
->recurse
>= MAX_RESUBMIT_RECURSION
+ MAX_INTERNAL_RESUBMITS
) {
3111 VLOG_ERR_RL(&rl
, "resubmit actions recursed over %d times",
3112 MAX_RESUBMIT_RECURSION
);
3113 } else if (ctx
->resubmits
>= MAX_RESUBMITS
+ MAX_INTERNAL_RESUBMITS
) {
3114 VLOG_ERR_RL(&rl
, "over %d resubmit actions", MAX_RESUBMITS
);
3115 } else if (ctx
->odp_actions
->size
> UINT16_MAX
) {
3116 VLOG_ERR_RL(&rl
, "resubmits yielded over 64 kB of actions");
3117 } else if (ctx
->stack
.size
>= 65536) {
3118 VLOG_ERR_RL(&rl
, "resubmits yielded over 64 kB of stack");
3127 xlate_table_action(struct xlate_ctx
*ctx
, ofp_port_t in_port
, uint8_t table_id
,
3128 bool may_packet_in
, bool honor_table_miss
)
3130 /* Check if we need to recirculate before matching in a table. */
3131 if (ctx
->was_mpls
) {
3132 ctx_trigger_recirculation(ctx
);
3135 if (xlate_resubmit_resource_check(ctx
)) {
3136 uint8_t old_table_id
= ctx
->table_id
;
3137 struct rule_dpif
*rule
;
3139 ctx
->table_id
= table_id
;
3141 rule
= rule_dpif_lookup_from_table(ctx
->xbridge
->ofproto
,
3142 ctx
->tables_version
,
3143 &ctx
->xin
->flow
, ctx
->xin
->wc
,
3144 ctx
->xin
->resubmit_stats
,
3145 &ctx
->table_id
, in_port
,
3146 may_packet_in
, honor_table_miss
);
3148 if (OVS_UNLIKELY(ctx
->xin
->resubmit_hook
)) {
3149 ctx
->xin
->resubmit_hook(ctx
->xin
, rule
, ctx
->recurse
+ 1);
3153 /* Fill in the cache entry here instead of xlate_recursively
3154 * to make the reference counting more explicit. We take a
3155 * reference in the lookups above if we are going to cache the
3157 if (ctx
->xin
->xcache
) {
3158 struct xc_entry
*entry
;
3160 entry
= xlate_cache_add_entry(ctx
->xin
->xcache
, XC_RULE
);
3161 entry
->u
.rule
= rule
;
3162 rule_dpif_ref(rule
);
3164 xlate_recursively(ctx
, rule
);
3167 ctx
->table_id
= old_table_id
;
3175 xlate_group_stats(struct xlate_ctx
*ctx
, struct group_dpif
*group
,
3176 struct ofputil_bucket
*bucket
)
3178 if (ctx
->xin
->resubmit_stats
) {
3179 group_dpif_credit_stats(group
, bucket
, ctx
->xin
->resubmit_stats
);
3181 if (ctx
->xin
->xcache
) {
3182 struct xc_entry
*entry
;
3184 entry
= xlate_cache_add_entry(ctx
->xin
->xcache
, XC_GROUP
);
3185 entry
->u
.group
.group
= group_dpif_ref(group
);
3186 entry
->u
.group
.bucket
= bucket
;
3191 xlate_group_bucket(struct xlate_ctx
*ctx
, struct ofputil_bucket
*bucket
)
3193 uint64_t action_list_stub
[1024 / 8];
3194 struct ofpbuf action_list
, action_set
;
3195 struct flow old_flow
= ctx
->xin
->flow
;
3196 bool old_was_mpls
= ctx
->was_mpls
;
3198 ofpbuf_use_const(&action_set
, bucket
->ofpacts
, bucket
->ofpacts_len
);
3199 ofpbuf_use_stub(&action_list
, action_list_stub
, sizeof action_list_stub
);
3201 ofpacts_execute_action_set(&action_list
, &action_set
);
3203 do_xlate_actions(action_list
.data
, action_list
.size
, ctx
);
3206 ofpbuf_uninit(&action_set
);
3207 ofpbuf_uninit(&action_list
);
3209 /* Check if need to recirculate. */
3210 if (exit_recirculates(ctx
)) {
3211 compose_recirculate_action(ctx
);
3214 /* Roll back flow to previous state.
3215 * This is equivalent to cloning the packet for each bucket.
3217 * As a side effect any subsequently applied actions will
3218 * also effectively be applied to a clone of the packet taken
3219 * just before applying the all or indirect group.
3221 * Note that group buckets are action sets, hence they cannot modify the
3222 * main action set. Also any stack actions are ignored when executing an
3223 * action set, so group buckets cannot change the stack either.
3224 * However, we do allow resubmit actions in group buckets, which could
3225 * break the above assumptions. It is up to the controller to not mess up
3226 * with the action_set and stack in the tables resubmitted to from
3228 ctx
->xin
->flow
= old_flow
;
3230 /* The group bucket popping MPLS should have no effect after bucket
3232 ctx
->was_mpls
= old_was_mpls
;
3234 /* The fact that the group bucket exits (for any reason) does not mean that
3235 * the translation after the group action should exit. Specifically, if
3236 * the group bucket recirculates (which typically modifies the packet), the
3237 * actions after the group action must continue processing with the
3238 * original, not the recirculated packet! */
3243 xlate_all_group(struct xlate_ctx
*ctx
, struct group_dpif
*group
)
3245 struct ofputil_bucket
*bucket
;
3246 const struct ovs_list
*buckets
;
3248 group_dpif_get_buckets(group
, &buckets
);
3250 LIST_FOR_EACH (bucket
, list_node
, buckets
) {
3251 xlate_group_bucket(ctx
, bucket
);
3253 xlate_group_stats(ctx
, group
, NULL
);
3257 xlate_ff_group(struct xlate_ctx
*ctx
, struct group_dpif
*group
)
3259 struct ofputil_bucket
*bucket
;
3261 bucket
= group_first_live_bucket(ctx
, group
, 0);
3263 xlate_group_bucket(ctx
, bucket
);
3264 xlate_group_stats(ctx
, group
, bucket
);
3269 xlate_default_select_group(struct xlate_ctx
*ctx
, struct group_dpif
*group
)
3271 struct flow_wildcards
*wc
= ctx
->wc
;
3272 struct ofputil_bucket
*bucket
;
3275 basis
= flow_hash_symmetric_l4(&ctx
->xin
->flow
, 0);
3276 flow_mask_hash_fields(&ctx
->xin
->flow
, wc
, NX_HASH_FIELDS_SYMMETRIC_L4
);
3277 bucket
= group_best_live_bucket(ctx
, group
, basis
);
3279 xlate_group_bucket(ctx
, bucket
);
3280 xlate_group_stats(ctx
, group
, bucket
);
3285 xlate_hash_fields_select_group(struct xlate_ctx
*ctx
, struct group_dpif
*group
)
3287 struct mf_bitmap hash_fields
= MF_BITMAP_INITIALIZER
;
3288 const struct field_array
*fields
;
3289 struct ofputil_bucket
*bucket
;
3293 fields
= group_dpif_get_fields(group
);
3294 basis
= hash_uint64(group_dpif_get_selection_method_param(group
));
3296 /* Determine which fields to hash */
3297 for (i
= 0; i
< MFF_N_IDS
; i
++) {
3298 if (bitmap_is_set(fields
->used
.bm
, i
)) {
3299 const struct mf_field
*mf
;
3301 /* If the field is already present in 'hash_fields' then
3302 * this loop has already checked that it and its pre-requisites
3303 * are present in the flow and its pre-requisites have
3304 * already been added to 'hash_fields'. There is nothing more
3305 * to do here and as an optimisation the loop can continue. */
3306 if (bitmap_is_set(hash_fields
.bm
, i
)) {
3312 /* Only hash a field if it and its pre-requisites are present
3314 if (!mf_are_prereqs_ok(mf
, &ctx
->xin
->flow
)) {
3318 /* Hash both the field and its pre-requisites */
3319 mf_bitmap_set_field_and_prereqs(mf
, &hash_fields
);
3323 /* Hash the fields */
3324 for (i
= 0; i
< MFF_N_IDS
; i
++) {
3325 if (bitmap_is_set(hash_fields
.bm
, i
)) {
3326 const struct mf_field
*mf
= mf_from_id(i
);
3327 union mf_value value
;
3330 mf_get_value(mf
, &ctx
->xin
->flow
, &value
);
3331 /* This seems inefficient but so does apply_mask() */
3332 for (j
= 0; j
< mf
->n_bytes
; j
++) {
3333 ((uint8_t *) &value
)[j
] &= ((uint8_t *) &fields
->value
[i
])[j
];
3335 basis
= hash_bytes(&value
, mf
->n_bytes
, basis
);
3337 /* For tunnels, hash in whether the field is present. */
3338 if (mf_is_tun_metadata(mf
)) {
3339 basis
= hash_boolean(mf_is_set(mf
, &ctx
->xin
->flow
), basis
);
3342 mf_mask_field(mf
, &ctx
->wc
->masks
);
3346 bucket
= group_best_live_bucket(ctx
, group
, basis
);
3348 xlate_group_bucket(ctx
, bucket
);
3349 xlate_group_stats(ctx
, group
, bucket
);
3354 xlate_select_group(struct xlate_ctx
*ctx
, struct group_dpif
*group
)
3356 const char *selection_method
= group_dpif_get_selection_method(group
);
3358 if (selection_method
[0] == '\0') {
3359 xlate_default_select_group(ctx
, group
);
3360 } else if (!strcasecmp("hash", selection_method
)) {
3361 xlate_hash_fields_select_group(ctx
, group
);
3363 /* Parsing of groups should ensure this never happens */
3369 xlate_group_action__(struct xlate_ctx
*ctx
, struct group_dpif
*group
)
3371 bool was_in_group
= ctx
->in_group
;
3372 ctx
->in_group
= true;
3374 switch (group_dpif_get_type(group
)) {
3376 case OFPGT11_INDIRECT
:
3377 xlate_all_group(ctx
, group
);
3379 case OFPGT11_SELECT
:
3380 xlate_select_group(ctx
, group
);
3383 xlate_ff_group(ctx
, group
);
3388 group_dpif_unref(group
);
3390 ctx
->in_group
= was_in_group
;
3394 xlate_group_action(struct xlate_ctx
*ctx
, uint32_t group_id
)
3396 if (xlate_resubmit_resource_check(ctx
)) {
3397 struct group_dpif
*group
;
3400 got_group
= group_dpif_lookup(ctx
->xbridge
->ofproto
, group_id
, &group
);
3402 xlate_group_action__(ctx
, group
);
3412 xlate_ofpact_resubmit(struct xlate_ctx
*ctx
,
3413 const struct ofpact_resubmit
*resubmit
)
3417 bool may_packet_in
= false;
3418 bool honor_table_miss
= false;
3420 if (ctx
->rule
&& rule_dpif_is_internal(ctx
->rule
)) {
3421 /* Still allow missed packets to be sent to the controller
3422 * if resubmitting from an internal table. */
3423 may_packet_in
= true;
3424 honor_table_miss
= true;
3427 in_port
= resubmit
->in_port
;
3428 if (in_port
== OFPP_IN_PORT
) {
3429 in_port
= ctx
->xin
->flow
.in_port
.ofp_port
;
3432 table_id
= resubmit
->table_id
;
3433 if (table_id
== 255) {
3434 table_id
= ctx
->table_id
;
3437 xlate_table_action(ctx
, in_port
, table_id
, may_packet_in
,
3442 flood_packets(struct xlate_ctx
*ctx
, bool all
)
3444 const struct xport
*xport
;
3446 HMAP_FOR_EACH (xport
, ofp_node
, &ctx
->xbridge
->xports
) {
3447 if (xport
->ofp_port
== ctx
->xin
->flow
.in_port
.ofp_port
) {
3452 compose_output_action__(ctx
, xport
->ofp_port
, NULL
, false);
3453 } else if (!(xport
->config
& OFPUTIL_PC_NO_FLOOD
)) {
3454 compose_output_action(ctx
, xport
->ofp_port
, NULL
);
3458 ctx
->nf_output_iface
= NF_OUT_FLOOD
;
3462 execute_controller_action(struct xlate_ctx
*ctx
, int len
,
3463 enum ofp_packet_in_reason reason
,
3464 uint16_t controller_id
)
3466 struct ofproto_packet_in
*pin
;
3467 struct dp_packet
*packet
;
3469 ctx
->xout
->slow
|= SLOW_CONTROLLER
;
3470 if (!ctx
->xin
->packet
) {
3474 packet
= dp_packet_clone(ctx
->xin
->packet
);
3476 xlate_commit_actions(ctx
);
3478 odp_execute_actions(NULL
, &packet
, 1, false,
3479 ctx
->odp_actions
->data
, ctx
->odp_actions
->size
, NULL
);
3481 pin
= xmalloc(sizeof *pin
);
3482 pin
->up
.packet_len
= dp_packet_size(packet
);
3483 pin
->up
.packet
= dp_packet_steal_data(packet
);
3484 pin
->up
.reason
= reason
;
3485 pin
->up
.table_id
= ctx
->table_id
;
3486 pin
->up
.cookie
= ctx
->rule_cookie
;
3488 flow_get_metadata(&ctx
->xin
->flow
, &pin
->up
.flow_metadata
);
3490 pin
->controller_id
= controller_id
;
3491 pin
->send_len
= len
;
3492 /* If a rule is a table-miss rule then this is
3493 * a table-miss handled by a table-miss rule.
3495 * Else, if rule is internal and has a controller action,
3496 * the later being implied by the rule being processed here,
3497 * then this is a table-miss handled without a table-miss rule.
3499 * Otherwise this is not a table-miss. */
3500 pin
->miss_type
= OFPROTO_PACKET_IN_NO_MISS
;
3502 if (rule_dpif_is_table_miss(ctx
->rule
)) {
3503 pin
->miss_type
= OFPROTO_PACKET_IN_MISS_FLOW
;
3504 } else if (rule_dpif_is_internal(ctx
->rule
)) {
3505 pin
->miss_type
= OFPROTO_PACKET_IN_MISS_WITHOUT_FLOW
;
3508 ofproto_dpif_send_packet_in(ctx
->xbridge
->ofproto
, pin
);
3509 dp_packet_delete(packet
);
3512 /* Called only when ctx->recirc_action_offset is set. */
3514 compose_recirculate_action(struct xlate_ctx
*ctx
)
3516 struct recirc_metadata md
;
3519 xlate_commit_actions(ctx
);
3520 recirc_metadata_from_flow(&md
, &ctx
->xin
->flow
);
3522 ovs_assert(ctx
->recirc_action_offset
>= 0);
3524 struct recirc_state state
= {
3526 .ofproto
= ctx
->xbridge
->ofproto
,
3528 .stack
= &ctx
->stack
,
3529 .mirrors
= ctx
->mirrors
,
3530 .action_set_len
= ctx
->recirc_action_offset
,
3531 .ofpacts_len
= ctx
->action_set
.size
,
3532 .ofpacts
= ctx
->action_set
.data
,
3535 /* Only allocate recirculation ID if we have a packet. */
3536 if (ctx
->xin
->packet
) {
3537 /* Allocate a unique recirc id for the given metadata state in the
3538 * flow. The life-cycle of this recirc id is managed by associating it
3539 * with the udpif key ('ukey') created for each new datapath flow. */
3540 id
= recirc_alloc_id_ctx(&state
);
3542 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 5);
3543 VLOG_ERR_RL(&rl
, "Failed to allocate recirculation id");
3546 xlate_out_add_recirc(ctx
->xout
, id
);
3548 /* Look up an existing recirc id for the given metadata state in the
3549 * flow. No new reference is taken, as the ID is RCU protected and is
3550 * only required temporarily for verification.
3552 * This might fail and return 0. We let zero 'id' to be used in the
3553 * RECIRC action below, which will fail all revalidations as zero is
3554 * not a valid recirculation ID. */
3555 id
= recirc_find_id(&state
);
3558 nl_msg_put_u32(ctx
->odp_actions
, OVS_ACTION_ATTR_RECIRC
, id
);
3560 /* Undo changes done by recirculation. */
3561 ctx
->action_set
.size
= ctx
->recirc_action_offset
;
3562 ctx
->recirc_action_offset
= -1;
3563 ctx
->last_unroll_offset
= -1;
3567 compose_mpls_push_action(struct xlate_ctx
*ctx
, struct ofpact_push_mpls
*mpls
)
3569 struct flow
*flow
= &ctx
->xin
->flow
;
3572 ovs_assert(eth_type_mpls(mpls
->ethertype
));
3574 n
= flow_count_mpls_labels(flow
, ctx
->wc
);
3576 xlate_commit_actions(ctx
);
3577 } else if (n
>= FLOW_MAX_MPLS_LABELS
) {
3578 if (ctx
->xin
->packet
!= NULL
) {
3579 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 5);
3580 VLOG_WARN_RL(&rl
, "bridge %s: dropping packet on which an "
3581 "MPLS push action can't be performed as it would "
3582 "have more MPLS LSEs than the %d supported.",
3583 ctx
->xbridge
->name
, FLOW_MAX_MPLS_LABELS
);
3589 flow_push_mpls(flow
, n
, mpls
->ethertype
, ctx
->wc
);
3593 compose_mpls_pop_action(struct xlate_ctx
*ctx
, ovs_be16 eth_type
)
3595 struct flow
*flow
= &ctx
->xin
->flow
;
3596 int n
= flow_count_mpls_labels(flow
, ctx
->wc
);
3598 if (flow_pop_mpls(flow
, n
, eth_type
, ctx
->wc
)) {
3599 if (ctx
->xbridge
->support
.odp
.recirc
) {
3600 ctx
->was_mpls
= true;
3602 } else if (n
>= FLOW_MAX_MPLS_LABELS
) {
3603 if (ctx
->xin
->packet
!= NULL
) {
3604 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 5);
3605 VLOG_WARN_RL(&rl
, "bridge %s: dropping packet on which an "
3606 "MPLS pop action can't be performed as it has "
3607 "more MPLS LSEs than the %d supported.",
3608 ctx
->xbridge
->name
, FLOW_MAX_MPLS_LABELS
);
3611 ofpbuf_clear(ctx
->odp_actions
);
3616 compose_dec_ttl(struct xlate_ctx
*ctx
, struct ofpact_cnt_ids
*ids
)
3618 struct flow
*flow
= &ctx
->xin
->flow
;
3620 if (!is_ip_any(flow
)) {
3624 ctx
->wc
->masks
.nw_ttl
= 0xff;
3625 if (flow
->nw_ttl
> 1) {
3631 for (i
= 0; i
< ids
->n_controllers
; i
++) {
3632 execute_controller_action(ctx
, UINT16_MAX
, OFPR_INVALID_TTL
,
3636 /* Stop processing for current table. */
3642 compose_set_mpls_label_action(struct xlate_ctx
*ctx
, ovs_be32 label
)
3644 if (eth_type_mpls(ctx
->xin
->flow
.dl_type
)) {
3645 ctx
->wc
->masks
.mpls_lse
[0] |= htonl(MPLS_LABEL_MASK
);
3646 set_mpls_lse_label(&ctx
->xin
->flow
.mpls_lse
[0], label
);
3651 compose_set_mpls_tc_action(struct xlate_ctx
*ctx
, uint8_t tc
)
3653 if (eth_type_mpls(ctx
->xin
->flow
.dl_type
)) {
3654 ctx
->wc
->masks
.mpls_lse
[0] |= htonl(MPLS_TC_MASK
);
3655 set_mpls_lse_tc(&ctx
->xin
->flow
.mpls_lse
[0], tc
);
3660 compose_set_mpls_ttl_action(struct xlate_ctx
*ctx
, uint8_t ttl
)
3662 if (eth_type_mpls(ctx
->xin
->flow
.dl_type
)) {
3663 ctx
->wc
->masks
.mpls_lse
[0] |= htonl(MPLS_TTL_MASK
);
3664 set_mpls_lse_ttl(&ctx
->xin
->flow
.mpls_lse
[0], ttl
);
3669 compose_dec_mpls_ttl_action(struct xlate_ctx
*ctx
)
3671 struct flow
*flow
= &ctx
->xin
->flow
;
3673 if (eth_type_mpls(flow
->dl_type
)) {
3674 uint8_t ttl
= mpls_lse_to_ttl(flow
->mpls_lse
[0]);
3676 ctx
->wc
->masks
.mpls_lse
[0] |= htonl(MPLS_TTL_MASK
);
3679 set_mpls_lse_ttl(&flow
->mpls_lse
[0], ttl
);
3682 execute_controller_action(ctx
, UINT16_MAX
, OFPR_INVALID_TTL
, 0);
3686 /* Stop processing for current table. */
3691 xlate_output_action(struct xlate_ctx
*ctx
,
3692 ofp_port_t port
, uint16_t max_len
, bool may_packet_in
)
3694 ofp_port_t prev_nf_output_iface
= ctx
->nf_output_iface
;
3696 ctx
->nf_output_iface
= NF_OUT_DROP
;
3700 compose_output_action(ctx
, ctx
->xin
->flow
.in_port
.ofp_port
, NULL
);
3703 xlate_table_action(ctx
, ctx
->xin
->flow
.in_port
.ofp_port
,
3704 0, may_packet_in
, true);
3710 flood_packets(ctx
, false);
3713 flood_packets(ctx
, true);
3715 case OFPP_CONTROLLER
:
3716 execute_controller_action(ctx
, max_len
,
3717 (ctx
->in_group
? OFPR_GROUP
3718 : ctx
->in_action_set
? OFPR_ACTION_SET
3726 if (port
!= ctx
->xin
->flow
.in_port
.ofp_port
) {
3727 compose_output_action(ctx
, port
, NULL
);
3729 xlate_report(ctx
, "skipping output to input port");
3734 if (prev_nf_output_iface
== NF_OUT_FLOOD
) {
3735 ctx
->nf_output_iface
= NF_OUT_FLOOD
;
3736 } else if (ctx
->nf_output_iface
== NF_OUT_DROP
) {
3737 ctx
->nf_output_iface
= prev_nf_output_iface
;
3738 } else if (prev_nf_output_iface
!= NF_OUT_DROP
&&
3739 ctx
->nf_output_iface
!= NF_OUT_FLOOD
) {
3740 ctx
->nf_output_iface
= NF_OUT_MULTI
;
3745 xlate_output_reg_action(struct xlate_ctx
*ctx
,
3746 const struct ofpact_output_reg
*or)
3748 uint64_t port
= mf_get_subfield(&or->src
, &ctx
->xin
->flow
);
3749 if (port
<= UINT16_MAX
) {
3750 union mf_subvalue value
;
3752 memset(&value
, 0xff, sizeof value
);
3753 mf_write_subfield_flow(&or->src
, &value
, &ctx
->wc
->masks
);
3754 xlate_output_action(ctx
, u16_to_ofp(port
),
3755 or->max_len
, false);
3760 xlate_enqueue_action(struct xlate_ctx
*ctx
,
3761 const struct ofpact_enqueue
*enqueue
)
3763 ofp_port_t ofp_port
= enqueue
->port
;
3764 uint32_t queue_id
= enqueue
->queue
;
3765 uint32_t flow_priority
, priority
;
3768 /* Translate queue to priority. */
3769 error
= dpif_queue_to_priority(ctx
->xbridge
->dpif
, queue_id
, &priority
);
3771 /* Fall back to ordinary output action. */
3772 xlate_output_action(ctx
, enqueue
->port
, 0, false);
3776 /* Check output port. */
3777 if (ofp_port
== OFPP_IN_PORT
) {
3778 ofp_port
= ctx
->xin
->flow
.in_port
.ofp_port
;
3779 } else if (ofp_port
== ctx
->xin
->flow
.in_port
.ofp_port
) {
3783 /* Add datapath actions. */
3784 flow_priority
= ctx
->xin
->flow
.skb_priority
;
3785 ctx
->xin
->flow
.skb_priority
= priority
;
3786 compose_output_action(ctx
, ofp_port
, NULL
);
3787 ctx
->xin
->flow
.skb_priority
= flow_priority
;
3789 /* Update NetFlow output port. */
3790 if (ctx
->nf_output_iface
== NF_OUT_DROP
) {
3791 ctx
->nf_output_iface
= ofp_port
;
3792 } else if (ctx
->nf_output_iface
!= NF_OUT_FLOOD
) {
3793 ctx
->nf_output_iface
= NF_OUT_MULTI
;
3798 xlate_set_queue_action(struct xlate_ctx
*ctx
, uint32_t queue_id
)
3800 uint32_t skb_priority
;
3802 if (!dpif_queue_to_priority(ctx
->xbridge
->dpif
, queue_id
, &skb_priority
)) {
3803 ctx
->xin
->flow
.skb_priority
= skb_priority
;
3805 /* Couldn't translate queue to a priority. Nothing to do. A warning
3806 * has already been logged. */
3811 slave_enabled_cb(ofp_port_t ofp_port
, void *xbridge_
)
3813 const struct xbridge
*xbridge
= xbridge_
;
3824 case OFPP_CONTROLLER
: /* Not supported by the bundle action. */
3827 port
= get_ofp_port(xbridge
, ofp_port
);
3828 return port
? port
->may_enable
: false;
3833 xlate_bundle_action(struct xlate_ctx
*ctx
,
3834 const struct ofpact_bundle
*bundle
)
3838 port
= bundle_execute(bundle
, &ctx
->xin
->flow
, ctx
->wc
, slave_enabled_cb
,
3839 CONST_CAST(struct xbridge
*, ctx
->xbridge
));
3840 if (bundle
->dst
.field
) {
3841 nxm_reg_load(&bundle
->dst
, ofp_to_u16(port
), &ctx
->xin
->flow
, ctx
->wc
);
3843 xlate_output_action(ctx
, port
, 0, false);
3848 xlate_learn_action__(struct xlate_ctx
*ctx
, const struct ofpact_learn
*learn
,
3849 struct ofputil_flow_mod
*fm
, struct ofpbuf
*ofpacts
)
3851 learn_execute(learn
, &ctx
->xin
->flow
, fm
, ofpacts
);
3852 if (ctx
->xin
->may_learn
) {
3853 ofproto_dpif_flow_mod(ctx
->xbridge
->ofproto
, fm
);
3858 xlate_learn_action(struct xlate_ctx
*ctx
, const struct ofpact_learn
*learn
)
3860 learn_mask(learn
, ctx
->wc
);
3862 if (ctx
->xin
->xcache
) {
3863 struct xc_entry
*entry
;
3865 entry
= xlate_cache_add_entry(ctx
->xin
->xcache
, XC_LEARN
);
3866 entry
->u
.learn
.ofproto
= ctx
->xbridge
->ofproto
;
3867 entry
->u
.learn
.fm
= xmalloc(sizeof *entry
->u
.learn
.fm
);
3868 entry
->u
.learn
.ofpacts
= ofpbuf_new(64);
3869 xlate_learn_action__(ctx
, learn
, entry
->u
.learn
.fm
,
3870 entry
->u
.learn
.ofpacts
);
3871 } else if (ctx
->xin
->may_learn
) {
3872 uint64_t ofpacts_stub
[1024 / 8];
3873 struct ofputil_flow_mod fm
;
3874 struct ofpbuf ofpacts
;
3876 ofpbuf_use_stub(&ofpacts
, ofpacts_stub
, sizeof ofpacts_stub
);
3877 xlate_learn_action__(ctx
, learn
, &fm
, &ofpacts
);
3878 ofpbuf_uninit(&ofpacts
);
3883 xlate_fin_timeout__(struct rule_dpif
*rule
, uint16_t tcp_flags
,
3884 uint16_t idle_timeout
, uint16_t hard_timeout
)
3886 if (tcp_flags
& (TCP_FIN
| TCP_RST
)) {
3887 rule_dpif_reduce_timeouts(rule
, idle_timeout
, hard_timeout
);
3892 xlate_fin_timeout(struct xlate_ctx
*ctx
,
3893 const struct ofpact_fin_timeout
*oft
)
3896 xlate_fin_timeout__(ctx
->rule
, ctx
->xin
->tcp_flags
,
3897 oft
->fin_idle_timeout
, oft
->fin_hard_timeout
);
3898 if (ctx
->xin
->xcache
) {
3899 struct xc_entry
*entry
;
3901 entry
= xlate_cache_add_entry(ctx
->xin
->xcache
, XC_FIN_TIMEOUT
);
3902 /* XC_RULE already holds a reference on the rule, none is taken
3904 entry
->u
.fin
.rule
= ctx
->rule
;
3905 entry
->u
.fin
.idle
= oft
->fin_idle_timeout
;
3906 entry
->u
.fin
.hard
= oft
->fin_hard_timeout
;
3912 xlate_sample_action(struct xlate_ctx
*ctx
,
3913 const struct ofpact_sample
*os
)
3915 /* Scale the probability from 16-bit to 32-bit while representing
3916 * the same percentage. */
3917 uint32_t probability
= (os
->probability
<< 16) | os
->probability
;
3919 if (!ctx
->xbridge
->support
.variable_length_userdata
) {
3920 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 1);
3922 VLOG_ERR_RL(&rl
, "ignoring NXAST_SAMPLE action because datapath "
3923 "lacks support (needs Linux 3.10+ or kernel module from "
3928 xlate_commit_actions(ctx
);
3930 union user_action_cookie cookie
= {
3932 .type
= USER_ACTION_COOKIE_FLOW_SAMPLE
,
3933 .probability
= os
->probability
,
3934 .collector_set_id
= os
->collector_set_id
,
3935 .obs_domain_id
= os
->obs_domain_id
,
3936 .obs_point_id
= os
->obs_point_id
,
3939 compose_sample_action(ctx
, probability
, &cookie
, sizeof cookie
.flow_sample
,
3944 may_receive(const struct xport
*xport
, struct xlate_ctx
*ctx
)
3946 if (xport
->config
& (is_stp(&ctx
->xin
->flow
)
3947 ? OFPUTIL_PC_NO_RECV_STP
3948 : OFPUTIL_PC_NO_RECV
)) {
3952 /* Only drop packets here if both forwarding and learning are
3953 * disabled. If just learning is enabled, we need to have
3954 * OFPP_NORMAL and the learning action have a look at the packet
3955 * before we can drop it. */
3956 if ((!xport_stp_forward_state(xport
) && !xport_stp_learn_state(xport
)) ||
3957 (!xport_rstp_forward_state(xport
) && !xport_rstp_learn_state(xport
))) {
3965 xlate_write_actions(struct xlate_ctx
*ctx
, const struct ofpact
*a
)
3967 const struct ofpact_nest
*on
= ofpact_get_WRITE_ACTIONS(a
);
3968 size_t on_len
= ofpact_nest_get_action_len(on
);
3969 const struct ofpact
*inner
;
3971 /* Maintain actset_output depending on the contents of the action set:
3973 * - OFPP_UNSET, if there is no "output" action.
3975 * - The output port, if there is an "output" action and no "group"
3978 * - OFPP_UNSET, if there is a "group" action.
3980 if (!ctx
->action_set_has_group
) {
3981 OFPACT_FOR_EACH (inner
, on
->actions
, on_len
) {
3982 if (inner
->type
== OFPACT_OUTPUT
) {
3983 ctx
->xin
->flow
.actset_output
= ofpact_get_OUTPUT(inner
)->port
;
3984 } else if (inner
->type
== OFPACT_GROUP
) {
3985 ctx
->xin
->flow
.actset_output
= OFPP_UNSET
;
3986 ctx
->action_set_has_group
= true;
3992 ofpbuf_put(&ctx
->action_set
, on
->actions
, on_len
);
3993 ofpact_pad(&ctx
->action_set
);
3997 xlate_action_set(struct xlate_ctx
*ctx
)
3999 uint64_t action_list_stub
[1024 / 64];
4000 struct ofpbuf action_list
;
4002 ctx
->in_action_set
= true;
4003 ofpbuf_use_stub(&action_list
, action_list_stub
, sizeof action_list_stub
);
4004 ofpacts_execute_action_set(&action_list
, &ctx
->action_set
);
4005 /* Clear the action set, as it is not needed any more. */
4006 ofpbuf_clear(&ctx
->action_set
);
4007 do_xlate_actions(action_list
.data
, action_list
.size
, ctx
);
4008 ctx
->in_action_set
= false;
4009 ofpbuf_uninit(&action_list
);
4013 recirc_put_unroll_xlate(struct xlate_ctx
*ctx
)
4015 struct ofpact_unroll_xlate
*unroll
;
4017 unroll
= ctx
->last_unroll_offset
< 0
4019 : ALIGNED_CAST(struct ofpact_unroll_xlate
*,
4020 (char *)ctx
->action_set
.data
+ ctx
->last_unroll_offset
);
4022 /* Restore the table_id and rule cookie for a potential PACKET
4025 (ctx
->table_id
!= unroll
->rule_table_id
4026 || ctx
->rule_cookie
!= unroll
->rule_cookie
)) {
4028 ctx
->last_unroll_offset
= ctx
->action_set
.size
;
4029 unroll
= ofpact_put_UNROLL_XLATE(&ctx
->action_set
);
4030 unroll
->rule_table_id
= ctx
->table_id
;
4031 unroll
->rule_cookie
= ctx
->rule_cookie
;
4036 /* Copy remaining actions to the action_set to be executed after recirculation.
4037 * UNROLL_XLATE action is inserted, if not already done so, before actions that
4038 * may generate PACKET_INs from the current table and without matching another
4041 recirc_unroll_actions(const struct ofpact
*ofpacts
, size_t ofpacts_len
,
4042 struct xlate_ctx
*ctx
)
4044 const struct ofpact
*a
;
4046 OFPACT_FOR_EACH (a
, ofpacts
, ofpacts_len
) {
4048 /* May generate PACKET INs. */
4049 case OFPACT_OUTPUT_REG
:
4052 case OFPACT_CONTROLLER
:
4053 case OFPACT_DEC_MPLS_TTL
:
4054 case OFPACT_DEC_TTL
:
4055 recirc_put_unroll_xlate(ctx
);
4058 /* These may not generate PACKET INs. */
4059 case OFPACT_SET_TUNNEL
:
4060 case OFPACT_REG_MOVE
:
4061 case OFPACT_SET_FIELD
:
4062 case OFPACT_STACK_PUSH
:
4063 case OFPACT_STACK_POP
:
4065 case OFPACT_WRITE_METADATA
:
4066 case OFPACT_RESUBMIT
: /* May indirectly generate PACKET INs, */
4067 case OFPACT_GOTO_TABLE
: /* but from a different table and rule. */
4068 case OFPACT_ENQUEUE
:
4069 case OFPACT_SET_VLAN_VID
:
4070 case OFPACT_SET_VLAN_PCP
:
4071 case OFPACT_STRIP_VLAN
:
4072 case OFPACT_PUSH_VLAN
:
4073 case OFPACT_SET_ETH_SRC
:
4074 case OFPACT_SET_ETH_DST
:
4075 case OFPACT_SET_IPV4_SRC
:
4076 case OFPACT_SET_IPV4_DST
:
4077 case OFPACT_SET_IP_DSCP
:
4078 case OFPACT_SET_IP_ECN
:
4079 case OFPACT_SET_IP_TTL
:
4080 case OFPACT_SET_L4_SRC_PORT
:
4081 case OFPACT_SET_L4_DST_PORT
:
4082 case OFPACT_SET_QUEUE
:
4083 case OFPACT_POP_QUEUE
:
4084 case OFPACT_PUSH_MPLS
:
4085 case OFPACT_POP_MPLS
:
4086 case OFPACT_SET_MPLS_LABEL
:
4087 case OFPACT_SET_MPLS_TC
:
4088 case OFPACT_SET_MPLS_TTL
:
4089 case OFPACT_MULTIPATH
:
4092 case OFPACT_UNROLL_XLATE
:
4093 case OFPACT_FIN_TIMEOUT
:
4094 case OFPACT_CLEAR_ACTIONS
:
4095 case OFPACT_WRITE_ACTIONS
:
4098 case OFPACT_DEBUG_RECIRC
:
4101 /* These need not be copied for restoration. */
4103 case OFPACT_CONJUNCTION
:
4106 /* Copy the action over. */
4107 ofpbuf_put(&ctx
->action_set
, a
, OFPACT_ALIGN(a
->len
));
4111 #define CHECK_MPLS_RECIRCULATION() \
4112 if (ctx->was_mpls) { \
4113 ctx_trigger_recirculation(ctx); \
4116 #define CHECK_MPLS_RECIRCULATION_IF(COND) \
4118 CHECK_MPLS_RECIRCULATION(); \
4122 do_xlate_actions(const struct ofpact
*ofpacts
, size_t ofpacts_len
,
4123 struct xlate_ctx
*ctx
)
4125 struct flow_wildcards
*wc
= ctx
->wc
;
4126 struct flow
*flow
= &ctx
->xin
->flow
;
4127 const struct ofpact
*a
;
4129 if (ovs_native_tunneling_is_on(ctx
->xbridge
->ofproto
)) {
4130 tnl_arp_snoop(flow
, wc
, ctx
->xbridge
->name
);
4132 /* dl_type already in the mask, not set below. */
4134 OFPACT_FOR_EACH (a
, ofpacts
, ofpacts_len
) {
4135 struct ofpact_controller
*controller
;
4136 const struct ofpact_metadata
*metadata
;
4137 const struct ofpact_set_field
*set_field
;
4138 const struct mf_field
*mf
;
4141 /* Check if need to store the remaining actions for later
4143 if (exit_recirculates(ctx
)) {
4144 recirc_unroll_actions(a
, OFPACT_ALIGN(ofpacts_len
-
4146 (uint8_t *)ofpacts
)),
4154 xlate_output_action(ctx
, ofpact_get_OUTPUT(a
)->port
,
4155 ofpact_get_OUTPUT(a
)->max_len
, true);
4159 if (xlate_group_action(ctx
, ofpact_get_GROUP(a
)->group_id
)) {
4160 /* Group could not be found. */
4165 case OFPACT_CONTROLLER
:
4166 controller
= ofpact_get_CONTROLLER(a
);
4167 execute_controller_action(ctx
, controller
->max_len
,
4169 controller
->controller_id
);
4172 case OFPACT_ENQUEUE
:
4173 memset(&wc
->masks
.skb_priority
, 0xff,
4174 sizeof wc
->masks
.skb_priority
);
4175 xlate_enqueue_action(ctx
, ofpact_get_ENQUEUE(a
));
4178 case OFPACT_SET_VLAN_VID
:
4179 wc
->masks
.vlan_tci
|= htons(VLAN_VID_MASK
| VLAN_CFI
);
4180 if (flow
->vlan_tci
& htons(VLAN_CFI
) ||
4181 ofpact_get_SET_VLAN_VID(a
)->push_vlan_if_needed
) {
4182 flow
->vlan_tci
&= ~htons(VLAN_VID_MASK
);
4183 flow
->vlan_tci
|= (htons(ofpact_get_SET_VLAN_VID(a
)->vlan_vid
)
4188 case OFPACT_SET_VLAN_PCP
:
4189 wc
->masks
.vlan_tci
|= htons(VLAN_PCP_MASK
| VLAN_CFI
);
4190 if (flow
->vlan_tci
& htons(VLAN_CFI
) ||
4191 ofpact_get_SET_VLAN_PCP(a
)->push_vlan_if_needed
) {
4192 flow
->vlan_tci
&= ~htons(VLAN_PCP_MASK
);
4193 flow
->vlan_tci
|= htons((ofpact_get_SET_VLAN_PCP(a
)->vlan_pcp
4194 << VLAN_PCP_SHIFT
) | VLAN_CFI
);
4198 case OFPACT_STRIP_VLAN
:
4199 memset(&wc
->masks
.vlan_tci
, 0xff, sizeof wc
->masks
.vlan_tci
);
4200 flow
->vlan_tci
= htons(0);
4203 case OFPACT_PUSH_VLAN
:
4204 /* XXX 802.1AD(QinQ) */
4205 memset(&wc
->masks
.vlan_tci
, 0xff, sizeof wc
->masks
.vlan_tci
);
4206 flow
->vlan_tci
= htons(VLAN_CFI
);
4209 case OFPACT_SET_ETH_SRC
:
4210 WC_MASK_FIELD(wc
, dl_src
);
4211 flow
->dl_src
= ofpact_get_SET_ETH_SRC(a
)->mac
;
4214 case OFPACT_SET_ETH_DST
:
4215 WC_MASK_FIELD(wc
, dl_dst
);
4216 flow
->dl_dst
= ofpact_get_SET_ETH_DST(a
)->mac
;
4219 case OFPACT_SET_IPV4_SRC
:
4220 CHECK_MPLS_RECIRCULATION();
4221 if (flow
->dl_type
== htons(ETH_TYPE_IP
)) {
4222 memset(&wc
->masks
.nw_src
, 0xff, sizeof wc
->masks
.nw_src
);
4223 flow
->nw_src
= ofpact_get_SET_IPV4_SRC(a
)->ipv4
;
4227 case OFPACT_SET_IPV4_DST
:
4228 CHECK_MPLS_RECIRCULATION();
4229 if (flow
->dl_type
== htons(ETH_TYPE_IP
)) {
4230 memset(&wc
->masks
.nw_dst
, 0xff, sizeof wc
->masks
.nw_dst
);
4231 flow
->nw_dst
= ofpact_get_SET_IPV4_DST(a
)->ipv4
;
4235 case OFPACT_SET_IP_DSCP
:
4236 CHECK_MPLS_RECIRCULATION();
4237 if (is_ip_any(flow
)) {
4238 wc
->masks
.nw_tos
|= IP_DSCP_MASK
;
4239 flow
->nw_tos
&= ~IP_DSCP_MASK
;
4240 flow
->nw_tos
|= ofpact_get_SET_IP_DSCP(a
)->dscp
;
4244 case OFPACT_SET_IP_ECN
:
4245 CHECK_MPLS_RECIRCULATION();
4246 if (is_ip_any(flow
)) {
4247 wc
->masks
.nw_tos
|= IP_ECN_MASK
;
4248 flow
->nw_tos
&= ~IP_ECN_MASK
;
4249 flow
->nw_tos
|= ofpact_get_SET_IP_ECN(a
)->ecn
;
4253 case OFPACT_SET_IP_TTL
:
4254 CHECK_MPLS_RECIRCULATION();
4255 if (is_ip_any(flow
)) {
4256 wc
->masks
.nw_ttl
= 0xff;
4257 flow
->nw_ttl
= ofpact_get_SET_IP_TTL(a
)->ttl
;
4261 case OFPACT_SET_L4_SRC_PORT
:
4262 CHECK_MPLS_RECIRCULATION();
4263 if (is_ip_any(flow
) && !(flow
->nw_frag
& FLOW_NW_FRAG_LATER
)) {
4264 memset(&wc
->masks
.nw_proto
, 0xff, sizeof wc
->masks
.nw_proto
);
4265 memset(&wc
->masks
.tp_src
, 0xff, sizeof wc
->masks
.tp_src
);
4266 flow
->tp_src
= htons(ofpact_get_SET_L4_SRC_PORT(a
)->port
);
4270 case OFPACT_SET_L4_DST_PORT
:
4271 CHECK_MPLS_RECIRCULATION();
4272 if (is_ip_any(flow
) && !(flow
->nw_frag
& FLOW_NW_FRAG_LATER
)) {
4273 memset(&wc
->masks
.nw_proto
, 0xff, sizeof wc
->masks
.nw_proto
);
4274 memset(&wc
->masks
.tp_dst
, 0xff, sizeof wc
->masks
.tp_dst
);
4275 flow
->tp_dst
= htons(ofpact_get_SET_L4_DST_PORT(a
)->port
);
4279 case OFPACT_RESUBMIT
:
4280 xlate_ofpact_resubmit(ctx
, ofpact_get_RESUBMIT(a
));
4283 case OFPACT_SET_TUNNEL
:
4284 flow
->tunnel
.tun_id
= htonll(ofpact_get_SET_TUNNEL(a
)->tun_id
);
4287 case OFPACT_SET_QUEUE
:
4288 memset(&wc
->masks
.skb_priority
, 0xff,
4289 sizeof wc
->masks
.skb_priority
);
4290 xlate_set_queue_action(ctx
, ofpact_get_SET_QUEUE(a
)->queue_id
);
4293 case OFPACT_POP_QUEUE
:
4294 memset(&wc
->masks
.skb_priority
, 0xff,
4295 sizeof wc
->masks
.skb_priority
);
4296 flow
->skb_priority
= ctx
->orig_skb_priority
;
4299 case OFPACT_REG_MOVE
:
4300 CHECK_MPLS_RECIRCULATION_IF(
4301 mf_is_l3_or_higher(ofpact_get_REG_MOVE(a
)->dst
.field
) ||
4302 mf_is_l3_or_higher(ofpact_get_REG_MOVE(a
)->src
.field
));
4303 nxm_execute_reg_move(ofpact_get_REG_MOVE(a
), flow
, wc
);
4306 case OFPACT_SET_FIELD
:
4307 CHECK_MPLS_RECIRCULATION_IF(
4308 mf_is_l3_or_higher(ofpact_get_SET_FIELD(a
)->field
));
4309 set_field
= ofpact_get_SET_FIELD(a
);
4310 mf
= set_field
->field
;
4312 /* Set field action only ever overwrites packet's outermost
4313 * applicable header fields. Do nothing if no header exists. */
4314 if (mf
->id
== MFF_VLAN_VID
) {
4315 wc
->masks
.vlan_tci
|= htons(VLAN_CFI
);
4316 if (!(flow
->vlan_tci
& htons(VLAN_CFI
))) {
4319 } else if ((mf
->id
== MFF_MPLS_LABEL
|| mf
->id
== MFF_MPLS_TC
)
4320 /* 'dl_type' is already unwildcarded. */
4321 && !eth_type_mpls(flow
->dl_type
)) {
4324 /* A flow may wildcard nw_frag. Do nothing if setting a trasport
4325 * header field on a packet that does not have them. */
4326 mf_mask_field_and_prereqs(mf
, wc
);
4327 if (mf_are_prereqs_ok(mf
, flow
)) {
4328 mf_set_flow_value_masked(mf
, &set_field
->value
,
4329 &set_field
->mask
, flow
);
4333 case OFPACT_STACK_PUSH
:
4334 CHECK_MPLS_RECIRCULATION_IF(
4335 mf_is_l3_or_higher(ofpact_get_STACK_PUSH(a
)->subfield
.field
));
4336 nxm_execute_stack_push(ofpact_get_STACK_PUSH(a
), flow
, wc
,
4340 case OFPACT_STACK_POP
:
4341 CHECK_MPLS_RECIRCULATION_IF(
4342 mf_is_l3_or_higher(ofpact_get_STACK_POP(a
)->subfield
.field
));
4343 nxm_execute_stack_pop(ofpact_get_STACK_POP(a
), flow
, wc
,
4347 case OFPACT_PUSH_MPLS
:
4348 /* Recirculate if it is an IP packet with a zero ttl. This may
4349 * indicate that the packet was previously MPLS and an MPLS pop
4350 * action converted it to IP. In this case recirculating should
4351 * reveal the IP TTL which is used as the basis for a new MPLS
4353 CHECK_MPLS_RECIRCULATION_IF(
4354 !flow_count_mpls_labels(flow
, wc
)
4355 && flow
->nw_ttl
== 0
4356 && is_ip_any(flow
));
4357 compose_mpls_push_action(ctx
, ofpact_get_PUSH_MPLS(a
));
4360 case OFPACT_POP_MPLS
:
4361 CHECK_MPLS_RECIRCULATION();
4362 compose_mpls_pop_action(ctx
, ofpact_get_POP_MPLS(a
)->ethertype
);
4365 case OFPACT_SET_MPLS_LABEL
:
4366 CHECK_MPLS_RECIRCULATION();
4367 compose_set_mpls_label_action(
4368 ctx
, ofpact_get_SET_MPLS_LABEL(a
)->label
);
4371 case OFPACT_SET_MPLS_TC
:
4372 CHECK_MPLS_RECIRCULATION();
4373 compose_set_mpls_tc_action(ctx
, ofpact_get_SET_MPLS_TC(a
)->tc
);
4376 case OFPACT_SET_MPLS_TTL
:
4377 CHECK_MPLS_RECIRCULATION();
4378 compose_set_mpls_ttl_action(ctx
, ofpact_get_SET_MPLS_TTL(a
)->ttl
);
4381 case OFPACT_DEC_MPLS_TTL
:
4382 CHECK_MPLS_RECIRCULATION();
4383 if (compose_dec_mpls_ttl_action(ctx
)) {
4388 case OFPACT_DEC_TTL
:
4389 CHECK_MPLS_RECIRCULATION();
4390 wc
->masks
.nw_ttl
= 0xff;
4391 if (compose_dec_ttl(ctx
, ofpact_get_DEC_TTL(a
))) {
4397 /* Nothing to do. */
4400 case OFPACT_MULTIPATH
:
4401 CHECK_MPLS_RECIRCULATION();
4402 multipath_execute(ofpact_get_MULTIPATH(a
), flow
, wc
);
4406 CHECK_MPLS_RECIRCULATION();
4407 xlate_bundle_action(ctx
, ofpact_get_BUNDLE(a
));
4410 case OFPACT_OUTPUT_REG
:
4411 xlate_output_reg_action(ctx
, ofpact_get_OUTPUT_REG(a
));
4415 CHECK_MPLS_RECIRCULATION();
4416 xlate_learn_action(ctx
, ofpact_get_LEARN(a
));
4419 case OFPACT_CONJUNCTION
: {
4420 /* A flow with a "conjunction" action represents part of a special
4421 * kind of "set membership match". Such a flow should not actually
4422 * get executed, but it could via, say, a "packet-out", even though
4423 * that wouldn't be useful. Log it to help debugging. */
4424 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 1);
4425 VLOG_INFO_RL(&rl
, "executing no-op conjunction action");
4433 case OFPACT_UNROLL_XLATE
: {
4434 struct ofpact_unroll_xlate
*unroll
= ofpact_get_UNROLL_XLATE(a
);
4436 /* Restore translation context data that was stored earlier. */
4437 ctx
->table_id
= unroll
->rule_table_id
;
4438 ctx
->rule_cookie
= unroll
->rule_cookie
;
4441 case OFPACT_FIN_TIMEOUT
:
4442 CHECK_MPLS_RECIRCULATION();
4443 memset(&wc
->masks
.nw_proto
, 0xff, sizeof wc
->masks
.nw_proto
);
4444 xlate_fin_timeout(ctx
, ofpact_get_FIN_TIMEOUT(a
));
4447 case OFPACT_CLEAR_ACTIONS
:
4448 ofpbuf_clear(&ctx
->action_set
);
4449 ctx
->xin
->flow
.actset_output
= OFPP_UNSET
;
4450 ctx
->action_set_has_group
= false;
4453 case OFPACT_WRITE_ACTIONS
:
4454 xlate_write_actions(ctx
, a
);
4457 case OFPACT_WRITE_METADATA
:
4458 metadata
= ofpact_get_WRITE_METADATA(a
);
4459 flow
->metadata
&= ~metadata
->mask
;
4460 flow
->metadata
|= metadata
->metadata
& metadata
->mask
;
4464 /* Not implemented yet. */
4467 case OFPACT_GOTO_TABLE
: {
4468 struct ofpact_goto_table
*ogt
= ofpact_get_GOTO_TABLE(a
);
4470 /* Allow ctx->table_id == TBL_INTERNAL, which will be greater
4471 * than ogt->table_id. This is to allow goto_table actions that
4472 * triggered recirculation: ctx->table_id will be TBL_INTERNAL
4473 * after recirculation. */
4474 ovs_assert(ctx
->table_id
== TBL_INTERNAL
4475 || ctx
->table_id
< ogt
->table_id
);
4476 xlate_table_action(ctx
, ctx
->xin
->flow
.in_port
.ofp_port
,
4477 ogt
->table_id
, true, true);
4482 xlate_sample_action(ctx
, ofpact_get_SAMPLE(a
));
4485 case OFPACT_DEBUG_RECIRC
:
4486 ctx_trigger_recirculation(ctx
);
4491 /* Check if need to store this and the remaining actions for later
4493 if (ctx
->exit
&& ctx_first_recirculation_action(ctx
)) {
4494 recirc_unroll_actions(a
, OFPACT_ALIGN(ofpacts_len
-
4496 (uint8_t *)ofpacts
)),
4504 xlate_in_init(struct xlate_in
*xin
, struct ofproto_dpif
*ofproto
,
4505 const struct flow
*flow
, ofp_port_t in_port
,
4506 struct rule_dpif
*rule
, uint16_t tcp_flags
,
4507 const struct dp_packet
*packet
, struct flow_wildcards
*wc
,
4508 struct ofpbuf
*odp_actions
)
4510 xin
->ofproto
= ofproto
;
4512 xin
->flow
.in_port
.ofp_port
= in_port
;
4513 xin
->flow
.actset_output
= OFPP_UNSET
;
4514 xin
->packet
= packet
;
4515 xin
->may_learn
= packet
!= NULL
;
4518 xin
->ofpacts
= NULL
;
4519 xin
->ofpacts_len
= 0;
4520 xin
->tcp_flags
= tcp_flags
;
4521 xin
->resubmit_hook
= NULL
;
4522 xin
->report_hook
= NULL
;
4523 xin
->resubmit_stats
= NULL
;
4527 xin
->odp_actions
= odp_actions
;
4529 /* Do recirc lookup. */
4530 xin
->recirc
= flow
->recirc_id
4531 ? recirc_id_node_find(flow
->recirc_id
)
4536 xlate_out_uninit(struct xlate_out
*xout
)
4539 xlate_out_free_recircs(xout
);
4543 /* Translates the 'ofpacts_len' bytes of "struct ofpact"s starting at 'ofpacts'
4544 * into datapath actions, using 'ctx', and discards the datapath actions. */
4546 xlate_actions_for_side_effects(struct xlate_in
*xin
)
4548 struct xlate_out xout
;
4550 xlate_actions(xin
, &xout
);
4551 xlate_out_uninit(&xout
);
4554 static struct skb_priority_to_dscp
*
4555 get_skb_priority(const struct xport
*xport
, uint32_t skb_priority
)
4557 struct skb_priority_to_dscp
*pdscp
;
4560 hash
= hash_int(skb_priority
, 0);
4561 HMAP_FOR_EACH_IN_BUCKET (pdscp
, hmap_node
, hash
, &xport
->skb_priorities
) {
4562 if (pdscp
->skb_priority
== skb_priority
) {
4570 dscp_from_skb_priority(const struct xport
*xport
, uint32_t skb_priority
,
4573 struct skb_priority_to_dscp
*pdscp
= get_skb_priority(xport
, skb_priority
);
4574 *dscp
= pdscp
? pdscp
->dscp
: 0;
4575 return pdscp
!= NULL
;
4579 count_skb_priorities(const struct xport
*xport
)
4581 return hmap_count(&xport
->skb_priorities
);
4585 clear_skb_priorities(struct xport
*xport
)
4587 struct skb_priority_to_dscp
*pdscp
, *next
;
4589 HMAP_FOR_EACH_SAFE (pdscp
, next
, hmap_node
, &xport
->skb_priorities
) {
4590 hmap_remove(&xport
->skb_priorities
, &pdscp
->hmap_node
);
4596 actions_output_to_local_port(const struct xlate_ctx
*ctx
)
4598 odp_port_t local_odp_port
= ofp_port_to_odp_port(ctx
->xbridge
, OFPP_LOCAL
);
4599 const struct nlattr
*a
;
4602 NL_ATTR_FOR_EACH_UNSAFE (a
, left
, ctx
->odp_actions
->data
,
4603 ctx
->odp_actions
->size
) {
4604 if (nl_attr_type(a
) == OVS_ACTION_ATTR_OUTPUT
4605 && nl_attr_get_odp_port(a
) == local_odp_port
) {
4612 #if defined(__linux__)
4613 /* Returns the maximum number of packets that the Linux kernel is willing to
4614 * queue up internally to certain kinds of software-implemented ports, or the
4615 * default (and rarely modified) value if it cannot be determined. */
4617 netdev_max_backlog(void)
4619 static struct ovsthread_once once
= OVSTHREAD_ONCE_INITIALIZER
;
4620 static int max_backlog
= 1000; /* The normal default value. */
4622 if (ovsthread_once_start(&once
)) {
4623 static const char filename
[] = "/proc/sys/net/core/netdev_max_backlog";
4627 stream
= fopen(filename
, "r");
4629 VLOG_INFO("%s: open failed (%s)", filename
, ovs_strerror(errno
));
4631 if (fscanf(stream
, "%d", &n
) != 1) {
4632 VLOG_WARN("%s: read error", filename
);
4633 } else if (n
<= 100) {
4634 VLOG_WARN("%s: unexpectedly small value %d", filename
, n
);
4640 ovsthread_once_done(&once
);
4642 VLOG_DBG("%s: using %d max_backlog", filename
, max_backlog
);
4648 /* Counts and returns the number of OVS_ACTION_ATTR_OUTPUT actions in
4651 count_output_actions(const struct ofpbuf
*odp_actions
)
4653 const struct nlattr
*a
;
4657 NL_ATTR_FOR_EACH_UNSAFE (a
, left
, odp_actions
->data
, odp_actions
->size
) {
4658 if (a
->nla_type
== OVS_ACTION_ATTR_OUTPUT
) {
4664 #endif /* defined(__linux__) */
4666 /* Returns true if 'odp_actions' contains more output actions than the datapath
4667 * can reliably handle in one go. On Linux, this is the value of the
4668 * net.core.netdev_max_backlog sysctl, which limits the maximum number of
4669 * packets that the kernel is willing to queue up for processing while the
4670 * datapath is processing a set of actions. */
4672 too_many_output_actions(const struct ofpbuf
*odp_actions OVS_UNUSED
)
4675 return (odp_actions
->size
/ NL_A_U32_SIZE
> netdev_max_backlog()
4676 && count_output_actions(odp_actions
) > netdev_max_backlog());
4678 /* OSes other than Linux might have similar limits, but we don't know how
4679 * to determine them.*/
4685 xlate_wc_init(struct xlate_ctx
*ctx
)
4687 flow_wildcards_init_catchall(ctx
->wc
);
4689 /* Some fields we consider to always be examined. */
4690 WC_MASK_FIELD(ctx
->wc
, in_port
);
4691 WC_MASK_FIELD(ctx
->wc
, dl_type
);
4692 if (is_ip_any(&ctx
->xin
->flow
)) {
4693 WC_MASK_FIELD_MASK(ctx
->wc
, nw_frag
, FLOW_NW_FRAG_MASK
);
4696 if (ctx
->xbridge
->support
.odp
.recirc
) {
4697 /* Always exactly match recirc_id when datapath supports
4699 WC_MASK_FIELD(ctx
->wc
, recirc_id
);
4702 if (ctx
->xbridge
->netflow
) {
4703 netflow_mask_wc(&ctx
->xin
->flow
, ctx
->wc
);
4706 tnl_wc_init(&ctx
->xin
->flow
, ctx
->wc
);
4710 xlate_wc_finish(struct xlate_ctx
*ctx
)
4712 /* Clear the metadata and register wildcard masks, because we won't
4713 * use non-header fields as part of the cache. */
4714 flow_wildcards_clear_non_packet_fields(ctx
->wc
);
4716 /* ICMPv4 and ICMPv6 have 8-bit "type" and "code" fields. struct flow
4717 * uses the low 8 bits of the 16-bit tp_src and tp_dst members to
4718 * represent these fields. The datapath interface, on the other hand,
4719 * represents them with just 8 bits each. This means that if the high
4720 * 8 bits of the masks for these fields somehow become set, then they
4721 * will get chopped off by a round trip through the datapath, and
4722 * revalidation will spot that as an inconsistency and delete the flow.
4723 * Avoid the problem here by making sure that only the low 8 bits of
4724 * either field can be unwildcarded for ICMP.
4726 if (is_icmpv4(&ctx
->xin
->flow
) || is_icmpv6(&ctx
->xin
->flow
)) {
4727 ctx
->wc
->masks
.tp_src
&= htons(UINT8_MAX
);
4728 ctx
->wc
->masks
.tp_dst
&= htons(UINT8_MAX
);
4730 /* VLAN_TCI CFI bit must be matched if any of the TCI is matched. */
4731 if (ctx
->wc
->masks
.vlan_tci
) {
4732 ctx
->wc
->masks
.vlan_tci
|= htons(VLAN_CFI
);
4736 /* Translates the flow, actions, or rule in 'xin' into datapath actions in
4738 * The caller must take responsibility for eventually freeing 'xout', with
4739 * xlate_out_uninit(). */
4741 xlate_actions(struct xlate_in
*xin
, struct xlate_out
*xout
)
4743 *xout
= (struct xlate_out
) {
4749 struct xlate_cfg
*xcfg
= ovsrcu_get(struct xlate_cfg
*, &xcfgp
);
4750 struct xbridge
*xbridge
= xbridge_lookup(xcfg
, xin
->ofproto
);
4755 struct flow
*flow
= &xin
->flow
;
4757 union mf_subvalue stack_stub
[1024 / sizeof(union mf_subvalue
)];
4758 uint64_t action_set_stub
[1024 / 8];
4759 struct flow_wildcards scratch_wc
;
4760 uint64_t actions_stub
[256 / 8];
4761 struct ofpbuf scratch_actions
= OFPBUF_STUB_INITIALIZER(actions_stub
);
4762 struct xlate_ctx ctx
= {
4766 .orig_tunnel_ip_dst
= flow
->tunnel
.ip_dst
,
4768 .stack
= OFPBUF_STUB_INITIALIZER(stack_stub
),
4770 .wc
= xin
->wc
? xin
->wc
: &scratch_wc
,
4771 .odp_actions
= xin
->odp_actions
? xin
->odp_actions
: &scratch_actions
,
4773 .recurse
= xin
->recurse
,
4774 .resubmits
= xin
->resubmits
,
4776 .in_action_set
= false,
4779 .rule_cookie
= OVS_BE64_MAX
,
4780 .orig_skb_priority
= flow
->skb_priority
,
4781 .sflow_n_outputs
= 0,
4782 .sflow_odp_port
= 0,
4783 .nf_output_iface
= NF_OUT_DROP
,
4787 .recirc_action_offset
= -1,
4788 .last_unroll_offset
= -1,
4792 .action_set_has_group
= false,
4793 .action_set
= OFPBUF_STUB_INITIALIZER(action_set_stub
),
4796 /* 'base_flow' reflects the packet as it came in, but we need it to reflect
4797 * the packet as the datapath will treat it for output actions:
4799 * - Our datapath doesn't retain tunneling information without us
4800 * re-setting it, so clear the tunnel data.
4802 * - For VLAN splinters, a higher layer may pretend that the packet
4803 * came in on 'flow->in_port.ofp_port' with 'flow->vlan_tci'
4804 * attached, because that's how we want to treat it from an OpenFlow
4805 * perspective. But from the datapath's perspective it actually came
4806 * in on a VLAN device without any VLAN attached. So here we put the
4807 * datapath's view of the VLAN information in 'base_flow' to ensure
4808 * correct treatment.
4810 memset(&ctx
.base_flow
.tunnel
, 0, sizeof ctx
.base_flow
.tunnel
);
4811 if (flow
->in_port
.ofp_port
4812 != vsp_realdev_to_vlandev(xbridge
->ofproto
,
4813 flow
->in_port
.ofp_port
,
4815 ctx
.base_flow
.vlan_tci
= 0;
4818 ofpbuf_reserve(ctx
.odp_actions
, NL_A_U32_SIZE
);
4820 xlate_wc_init(&ctx
);
4823 COVERAGE_INC(xlate_actions
);
4826 const struct recirc_state
*state
= &xin
->recirc
->state
;
4828 xlate_report(&ctx
, "Restoring state post-recirculation:");
4830 if (xin
->ofpacts_len
> 0 || ctx
.rule
) {
4831 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 1);
4832 const char *conflict
= xin
->ofpacts_len
? "actions" : "rule";
4834 VLOG_WARN_RL(&rl
, "Recirculation conflict (%s)!", conflict
);
4835 xlate_report(&ctx
, "- Recirculation conflict (%s)!", conflict
);
4839 /* Set the bridge for post-recirculation processing if needed. */
4840 if (ctx
.xbridge
->ofproto
!= state
->ofproto
) {
4841 struct xlate_cfg
*xcfg
= ovsrcu_get(struct xlate_cfg
*, &xcfgp
);
4842 const struct xbridge
*new_bridge
4843 = xbridge_lookup(xcfg
, state
->ofproto
);
4845 if (OVS_UNLIKELY(!new_bridge
)) {
4846 /* Drop the packet if the bridge cannot be found. */
4847 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 1);
4848 VLOG_WARN_RL(&rl
, "Recirculation bridge no longer exists.");
4849 xlate_report(&ctx
, "- Recirculation bridge no longer exists.");
4852 ctx
.xbridge
= new_bridge
;
4855 /* Set the post-recirculation table id. Note: A table lookup is done
4856 * only if there are no post-recirculation actions. */
4857 ctx
.table_id
= state
->table_id
;
4858 xlate_report(&ctx
, "- Resuming from table %"PRIu8
, ctx
.table_id
);
4860 /* Restore pipeline metadata. May change flow's in_port and other
4861 * metadata to the values that existed when recirculation was
4863 recirc_metadata_to_flow(&state
->metadata
, flow
);
4865 /* Restore stack, if any. */
4867 ofpbuf_put(&ctx
.stack
, state
->stack
->data
, state
->stack
->size
);
4870 /* Restore mirror state. */
4871 ctx
.mirrors
= state
->mirrors
;
4873 /* Restore action set, if any. */
4874 if (state
->action_set_len
) {
4875 const struct ofpact
*a
;
4877 xlate_report_actions(&ctx
, "- Restoring action set",
4878 state
->ofpacts
, state
->action_set_len
);
4880 ofpbuf_put(&ctx
.action_set
, state
->ofpacts
, state
->action_set_len
);
4882 OFPACT_FOR_EACH(a
, state
->ofpacts
, state
->action_set_len
) {
4883 if (a
->type
== OFPACT_GROUP
) {
4884 ctx
.action_set_has_group
= true;
4890 /* Restore recirculation actions. If there are no actions, processing
4891 * will start with a lookup in the table set above. */
4892 if (state
->ofpacts_len
> state
->action_set_len
) {
4893 xin
->ofpacts_len
= state
->ofpacts_len
- state
->action_set_len
;
4894 xin
->ofpacts
= state
->ofpacts
+
4895 state
->action_set_len
/ sizeof *state
->ofpacts
;
4897 xlate_report_actions(&ctx
, "- Restoring actions",
4898 xin
->ofpacts
, xin
->ofpacts_len
);
4900 } else if (OVS_UNLIKELY(flow
->recirc_id
)) {
4901 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 1);
4903 VLOG_WARN_RL(&rl
, "Recirculation context not found for ID %"PRIx32
,
4907 /* The bridge is now known so obtain its table version. */
4908 ctx
.tables_version
= ofproto_dpif_get_tables_version(ctx
.xbridge
->ofproto
);
4910 if (!xin
->ofpacts
&& !ctx
.rule
) {
4911 ctx
.rule
= rule_dpif_lookup_from_table(
4912 ctx
.xbridge
->ofproto
, ctx
.tables_version
, flow
, xin
->wc
,
4913 ctx
.xin
->resubmit_stats
, &ctx
.table_id
,
4914 flow
->in_port
.ofp_port
, true, true);
4915 if (ctx
.xin
->resubmit_stats
) {
4916 rule_dpif_credit_stats(ctx
.rule
, ctx
.xin
->resubmit_stats
);
4918 if (ctx
.xin
->xcache
) {
4919 struct xc_entry
*entry
;
4921 entry
= xlate_cache_add_entry(ctx
.xin
->xcache
, XC_RULE
);
4922 entry
->u
.rule
= ctx
.rule
;
4923 rule_dpif_ref(ctx
.rule
);
4926 if (OVS_UNLIKELY(ctx
.xin
->resubmit_hook
)) {
4927 ctx
.xin
->resubmit_hook(ctx
.xin
, ctx
.rule
, 0);
4930 xout
->fail_open
= ctx
.rule
&& rule_dpif_is_fail_open(ctx
.rule
);
4932 /* Get the proximate input port of the packet. (If xin->recirc,
4933 * flow->in_port is the ultimate input port of the packet.) */
4934 struct xport
*in_port
= get_ofp_port(xbridge
,
4935 ctx
.base_flow
.in_port
.ofp_port
);
4937 /* Tunnel stats only for non-recirculated packets. */
4938 if (!xin
->recirc
&& in_port
&& in_port
->is_tunnel
) {
4939 if (ctx
.xin
->resubmit_stats
) {
4940 netdev_vport_inc_rx(in_port
->netdev
, ctx
.xin
->resubmit_stats
);
4942 bfd_account_rx(in_port
->bfd
, ctx
.xin
->resubmit_stats
);
4945 if (ctx
.xin
->xcache
) {
4946 struct xc_entry
*entry
;
4948 entry
= xlate_cache_add_entry(ctx
.xin
->xcache
, XC_NETDEV
);
4949 entry
->u
.dev
.rx
= netdev_ref(in_port
->netdev
);
4950 entry
->u
.dev
.bfd
= bfd_ref(in_port
->bfd
);
4954 if (!xin
->recirc
&& process_special(&ctx
, in_port
)) {
4955 /* process_special() did all the processing for this packet.
4957 * We do not perform special processing on recirculated packets, as
4958 * recirculated packets are not really received by the bridge.*/
4959 } else if (in_port
&& in_port
->xbundle
4960 && xbundle_mirror_out(xbridge
, in_port
->xbundle
)) {
4961 if (ctx
.xin
->packet
!= NULL
) {
4962 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 5);
4963 VLOG_WARN_RL(&rl
, "bridge %s: dropping packet received on port "
4964 "%s, which is reserved exclusively for mirroring",
4965 ctx
.xbridge
->name
, in_port
->xbundle
->name
);
4968 /* Sampling is done only for packets really received by the bridge. */
4969 unsigned int user_cookie_offset
= 0;
4971 user_cookie_offset
= compose_sflow_action(&ctx
);
4972 compose_ipfix_action(&ctx
, ODPP_NONE
);
4974 size_t sample_actions_len
= ctx
.odp_actions
->size
;
4976 if (tnl_process_ecn(flow
)
4977 && (!in_port
|| may_receive(in_port
, &ctx
))) {
4978 const struct ofpact
*ofpacts
;
4982 ofpacts
= xin
->ofpacts
;
4983 ofpacts_len
= xin
->ofpacts_len
;
4984 } else if (ctx
.rule
) {
4985 const struct rule_actions
*actions
4986 = rule_dpif_get_actions(ctx
.rule
);
4987 ofpacts
= actions
->ofpacts
;
4988 ofpacts_len
= actions
->ofpacts_len
;
4989 ctx
.rule_cookie
= rule_dpif_get_flow_cookie(ctx
.rule
);
4994 mirror_ingress_packet(&ctx
);
4995 do_xlate_actions(ofpacts
, ofpacts_len
, &ctx
);
4997 /* We've let OFPP_NORMAL and the learning action look at the
4998 * packet, so drop it now if forwarding is disabled. */
4999 if (in_port
&& (!xport_stp_forward_state(in_port
) ||
5000 !xport_rstp_forward_state(in_port
))) {
5001 /* Drop all actions added by do_xlate_actions() above. */
5002 ctx
.odp_actions
->size
= sample_actions_len
;
5004 /* Undo changes that may have been done for recirculation. */
5005 if (exit_recirculates(&ctx
)) {
5006 ctx
.action_set
.size
= ctx
.recirc_action_offset
;
5007 ctx
.recirc_action_offset
= -1;
5008 ctx
.last_unroll_offset
= -1;
5010 } else if (ctx
.action_set
.size
) {
5011 /* Translate action set only if not dropping the packet and
5012 * not recirculating. */
5013 if (!exit_recirculates(&ctx
)) {
5014 xlate_action_set(&ctx
);
5017 /* Check if need to recirculate. */
5018 if (exit_recirculates(&ctx
)) {
5019 compose_recirculate_action(&ctx
);
5023 /* Output only fully processed packets. */
5024 if (!exit_recirculates(&ctx
)
5025 && xbridge
->has_in_band
5026 && in_band_must_output_to_local_port(flow
)
5027 && !actions_output_to_local_port(&ctx
)) {
5028 compose_output_action(&ctx
, OFPP_LOCAL
, NULL
);
5031 if (user_cookie_offset
) {
5032 fix_sflow_action(&ctx
, user_cookie_offset
);
5036 if (nl_attr_oversized(ctx
.odp_actions
->size
)) {
5037 /* These datapath actions are too big for a Netlink attribute, so we
5038 * can't hand them to the kernel directly. dpif_execute() can execute
5039 * them one by one with help, so just mark the result as SLOW_ACTION to
5040 * prevent the flow from being installed. */
5041 COVERAGE_INC(xlate_actions_oversize
);
5042 ctx
.xout
->slow
|= SLOW_ACTION
;
5043 } else if (too_many_output_actions(ctx
.odp_actions
)) {
5044 COVERAGE_INC(xlate_actions_too_many_output
);
5045 ctx
.xout
->slow
|= SLOW_ACTION
;
5048 /* Do netflow only for packets really received by the bridge and not sent
5049 * to the controller. We consider packets sent to the controller to be
5050 * part of the control plane rather than the data plane. */
5051 if (!xin
->recirc
&& xbridge
->netflow
&& !(xout
->slow
& SLOW_CONTROLLER
)) {
5052 if (ctx
.xin
->resubmit_stats
) {
5053 netflow_flow_update(xbridge
->netflow
, flow
,
5054 ctx
.nf_output_iface
,
5055 ctx
.xin
->resubmit_stats
);
5057 if (ctx
.xin
->xcache
) {
5058 struct xc_entry
*entry
;
5060 entry
= xlate_cache_add_entry(ctx
.xin
->xcache
, XC_NETFLOW
);
5061 entry
->u
.nf
.netflow
= netflow_ref(xbridge
->netflow
);
5062 entry
->u
.nf
.flow
= xmemdup(flow
, sizeof *flow
);
5063 entry
->u
.nf
.iface
= ctx
.nf_output_iface
;
5068 xlate_wc_finish(&ctx
);
5072 ofpbuf_uninit(&ctx
.stack
);
5073 ofpbuf_uninit(&ctx
.action_set
);
5074 ofpbuf_uninit(&scratch_actions
);
5077 /* Sends 'packet' out 'ofport'.
5078 * May modify 'packet'.
5079 * Returns 0 if successful, otherwise a positive errno value. */
5081 xlate_send_packet(const struct ofport_dpif
*ofport
, struct dp_packet
*packet
)
5083 struct xlate_cfg
*xcfg
= ovsrcu_get(struct xlate_cfg
*, &xcfgp
);
5084 struct xport
*xport
;
5085 struct ofpact_output output
;
5088 ofpact_init(&output
.ofpact
, OFPACT_OUTPUT
, sizeof output
);
5089 /* Use OFPP_NONE as the in_port to avoid special packet processing. */
5090 flow_extract(packet
, &flow
);
5091 flow
.in_port
.ofp_port
= OFPP_NONE
;
5093 xport
= xport_lookup(xcfg
, ofport
);
5097 output
.port
= xport
->ofp_port
;
5100 return ofproto_dpif_execute_actions(xport
->xbridge
->ofproto
, &flow
, NULL
,
5101 &output
.ofpact
, sizeof output
,
5105 struct xlate_cache
*
5106 xlate_cache_new(void)
5108 struct xlate_cache
*xcache
= xmalloc(sizeof *xcache
);
5110 ofpbuf_init(&xcache
->entries
, 512);
5114 static struct xc_entry
*
5115 xlate_cache_add_entry(struct xlate_cache
*xcache
, enum xc_type type
)
5117 struct xc_entry
*entry
;
5119 entry
= ofpbuf_put_zeros(&xcache
->entries
, sizeof *entry
);
5126 xlate_cache_netdev(struct xc_entry
*entry
, const struct dpif_flow_stats
*stats
)
5128 if (entry
->u
.dev
.tx
) {
5129 netdev_vport_inc_tx(entry
->u
.dev
.tx
, stats
);
5131 if (entry
->u
.dev
.rx
) {
5132 netdev_vport_inc_rx(entry
->u
.dev
.rx
, stats
);
5134 if (entry
->u
.dev
.bfd
) {
5135 bfd_account_rx(entry
->u
.dev
.bfd
, stats
);
5140 xlate_cache_normal(struct ofproto_dpif
*ofproto
, struct flow
*flow
, int vlan
)
5142 struct xlate_cfg
*xcfg
= ovsrcu_get(struct xlate_cfg
*, &xcfgp
);
5143 struct xbridge
*xbridge
;
5144 struct xbundle
*xbundle
;
5145 struct flow_wildcards wc
;
5147 xbridge
= xbridge_lookup(xcfg
, ofproto
);
5152 xbundle
= lookup_input_bundle(xbridge
, flow
->in_port
.ofp_port
, false,
5158 update_learning_table(xbridge
, flow
, &wc
, vlan
, xbundle
);
5161 /* Push stats and perform side effects of flow translation. */
5163 xlate_push_stats(struct xlate_cache
*xcache
,
5164 const struct dpif_flow_stats
*stats
)
5166 struct xc_entry
*entry
;
5167 struct ofpbuf entries
= xcache
->entries
;
5168 struct eth_addr dmac
;
5170 if (!stats
->n_packets
) {
5174 XC_ENTRY_FOR_EACH (entry
, entries
, xcache
) {
5175 switch (entry
->type
) {
5177 rule_dpif_credit_stats(entry
->u
.rule
, stats
);
5180 bond_account(entry
->u
.bond
.bond
, entry
->u
.bond
.flow
,
5181 entry
->u
.bond
.vid
, stats
->n_bytes
);
5184 xlate_cache_netdev(entry
, stats
);
5187 netflow_flow_update(entry
->u
.nf
.netflow
, entry
->u
.nf
.flow
,
5188 entry
->u
.nf
.iface
, stats
);
5191 mirror_update_stats(entry
->u
.mirror
.mbridge
,
5192 entry
->u
.mirror
.mirrors
,
5193 stats
->n_packets
, stats
->n_bytes
);
5196 ofproto_dpif_flow_mod(entry
->u
.learn
.ofproto
, entry
->u
.learn
.fm
);
5199 xlate_cache_normal(entry
->u
.normal
.ofproto
, entry
->u
.normal
.flow
,
5200 entry
->u
.normal
.vlan
);
5202 case XC_FIN_TIMEOUT
:
5203 xlate_fin_timeout__(entry
->u
.fin
.rule
, stats
->tcp_flags
,
5204 entry
->u
.fin
.idle
, entry
->u
.fin
.hard
);
5207 group_dpif_credit_stats(entry
->u
.group
.group
, entry
->u
.group
.bucket
,
5211 /* Lookup arp to avoid arp timeout. */
5212 tnl_arp_lookup(entry
->u
.tnl_arp_cache
.br_name
,
5213 entry
->u
.tnl_arp_cache
.d_ip
, &dmac
);
5222 xlate_dev_unref(struct xc_entry
*entry
)
5224 if (entry
->u
.dev
.tx
) {
5225 netdev_close(entry
->u
.dev
.tx
);
5227 if (entry
->u
.dev
.rx
) {
5228 netdev_close(entry
->u
.dev
.rx
);
5230 if (entry
->u
.dev
.bfd
) {
5231 bfd_unref(entry
->u
.dev
.bfd
);
5236 xlate_cache_clear_netflow(struct netflow
*netflow
, struct flow
*flow
)
5238 netflow_flow_clear(netflow
, flow
);
5239 netflow_unref(netflow
);
5244 xlate_cache_clear(struct xlate_cache
*xcache
)
5246 struct xc_entry
*entry
;
5247 struct ofpbuf entries
;
5253 XC_ENTRY_FOR_EACH (entry
, entries
, xcache
) {
5254 switch (entry
->type
) {
5256 rule_dpif_unref(entry
->u
.rule
);
5259 free(entry
->u
.bond
.flow
);
5260 bond_unref(entry
->u
.bond
.bond
);
5263 xlate_dev_unref(entry
);
5266 xlate_cache_clear_netflow(entry
->u
.nf
.netflow
, entry
->u
.nf
.flow
);
5269 mbridge_unref(entry
->u
.mirror
.mbridge
);
5272 free(entry
->u
.learn
.fm
);
5273 ofpbuf_delete(entry
->u
.learn
.ofpacts
);
5276 free(entry
->u
.normal
.flow
);
5278 case XC_FIN_TIMEOUT
:
5279 /* 'u.fin.rule' is always already held as a XC_RULE, which
5280 * has already released it's reference above. */
5283 group_dpif_unref(entry
->u
.group
.group
);
5292 ofpbuf_clear(&xcache
->entries
);
5296 xlate_cache_delete(struct xlate_cache
*xcache
)
5298 xlate_cache_clear(xcache
);
5299 ofpbuf_uninit(&xcache
->entries
);