- for (; mirrors; mirrors &= mirrors - 1) {
- struct ofmirror *m = ofproto->mirrors[mirror_mask_ffs(mirrors) - 1];
- if (vlan_is_mirrored(m, vlan)) {
- struct dst dst;
-
- if (m->out) {
- if (set_dst(ctx, &dst, in_bundle, m->out)
- && !dst_is_duplicate(set, &dst)) {
- dst_set_add(set, &dst);
- }
- } else if (eth_dst_may_rspan(ctx->flow.dl_dst)) {
- struct ofbundle *bundle;
-
- HMAP_FOR_EACH (bundle, hmap_node, &ofproto->bundles) {
- if (ofbundle_includes_vlan(bundle, m->out_vlan)
- && !bundle->mirror_out
- && set_dst(ctx, &dst, in_bundle, bundle))
- {
- /* set_dst() got dst->vid from the input packet's VLAN,
- * not from m->out_vlan, so recompute it. */
- dst.vid = output_vlan_to_vid(bundle, m->out_vlan);
-
- if (dst_is_duplicate(set, &dst)) {
- continue;
- }
-
- if (bundle == in_bundle && dst.vid == flow_vid) {
- /* Don't send out input port on same VLAN. */
- continue;
- }
- dst_set_add(set, &dst);
+ while (mirrors) {
+ struct ofmirror *m;
+ struct dst dst;
+
+ m = ofproto->mirrors[mirror_mask_ffs(mirrors) - 1];
+
+ if (!vlan_is_mirrored(m, vlan)) {
+ mirrors &= mirrors - 1;
+ continue;
+ }
+
+ mirrors &= ~m->dup_mirrors;
+ if (m->out) {
+ if (set_dst(ctx, &dst, in_bundle, m->out)) {
+ dst_set_add(set, &dst);
+ }
+ } else if (eth_dst_may_rspan(ctx->flow.dl_dst)
+ && vlan != m->out_vlan) {
+ struct ofbundle *bundle;
+
+ HMAP_FOR_EACH (bundle, hmap_node, &ofproto->bundles) {
+ if (ofbundle_includes_vlan(bundle, m->out_vlan)
+ && !bundle->mirror_out
+ && set_dst(ctx, &dst, in_bundle, bundle))
+ {
+ /* set_dst() got dst->vid from the input packet's VLAN,
+ * not from m->out_vlan, so recompute it. */
+ dst.vid = output_vlan_to_vid(bundle, m->out_vlan);
+
+ if (bundle == in_bundle && dst.vid == flow_vid) {
+ /* Don't send out input port on same VLAN. */
+ continue;