LCOV - code coverage report
Current view: top level - ofproto - ofproto-dpif-xlate.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 2003 2443 82.0 %
Date: 2016-09-14 01:02:56 Functions: 165 185 89.2 %
Branches: 981 1529 64.2 %

           Branch data     Line data    Source code
       1                 :            : /* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Nicira, Inc.
       2                 :            :  *
       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:
       6                 :            :  *
       7                 :            :  *     http://www.apache.org/licenses/LICENSE-2.0
       8                 :            :  *
       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. */
      14                 :            : 
      15                 :            : #include <config.h>
      16                 :            : 
      17                 :            : #include "ofproto/ofproto-dpif-xlate.h"
      18                 :            : 
      19                 :            : #include <errno.h>
      20                 :            : #include <arpa/inet.h>
      21                 :            : #include <net/if.h>
      22                 :            : #include <sys/socket.h>
      23                 :            : #include <netinet/in.h>
      24                 :            : 
      25                 :            : #include "bfd.h"
      26                 :            : #include "bitmap.h"
      27                 :            : #include "bond.h"
      28                 :            : #include "bundle.h"
      29                 :            : #include "byte-order.h"
      30                 :            : #include "cfm.h"
      31                 :            : #include "connmgr.h"
      32                 :            : #include "coverage.h"
      33                 :            : #include "dp-packet.h"
      34                 :            : #include "dpif.h"
      35                 :            : #include "in-band.h"
      36                 :            : #include "lacp.h"
      37                 :            : #include "learn.h"
      38                 :            : #include "mac-learning.h"
      39                 :            : #include "mcast-snooping.h"
      40                 :            : #include "multipath.h"
      41                 :            : #include "netdev-vport.h"
      42                 :            : #include "netlink.h"
      43                 :            : #include "nx-match.h"
      44                 :            : #include "odp-execute.h"
      45                 :            : #include "ofproto/ofproto-dpif-ipfix.h"
      46                 :            : #include "ofproto/ofproto-dpif-mirror.h"
      47                 :            : #include "ofproto/ofproto-dpif-monitor.h"
      48                 :            : #include "ofproto/ofproto-dpif-sflow.h"
      49                 :            : #include "ofproto/ofproto-dpif.h"
      50                 :            : #include "ofproto/ofproto-provider.h"
      51                 :            : #include "openvswitch/dynamic-string.h"
      52                 :            : #include "openvswitch/meta-flow.h"
      53                 :            : #include "openvswitch/list.h"
      54                 :            : #include "openvswitch/ofp-actions.h"
      55                 :            : #include "openvswitch/vlog.h"
      56                 :            : #include "ovs-lldp.h"
      57                 :            : #include "ovs-router.h"
      58                 :            : #include "packets.h"
      59                 :            : #include "tnl-neigh-cache.h"
      60                 :            : #include "tnl-ports.h"
      61                 :            : #include "tunnel.h"
      62                 :            : #include "util.h"
      63                 :            : 
      64                 :     579442 : COVERAGE_DEFINE(xlate_actions);
      65                 :      71674 : COVERAGE_DEFINE(xlate_actions_oversize);
      66                 :      71668 : COVERAGE_DEFINE(xlate_actions_too_many_output);
      67                 :            : 
      68                 :       1288 : VLOG_DEFINE_THIS_MODULE(ofproto_dpif_xlate);
      69                 :            : 
      70                 :            : /* Maximum depth of flow table recursion (due to resubmit actions) in a
      71                 :            :  * flow translation.
      72                 :            :  *
      73                 :            :  * The goal of limiting the depth of resubmits is to ensure that flow
      74                 :            :  * translation eventually terminates.  Only resubmits to the same table or an
      75                 :            :  * earlier table count against the maximum depth.  This is because resubmits to
      76                 :            :  * strictly monotonically increasing table IDs will eventually terminate, since
      77                 :            :  * any OpenFlow switch has a finite number of tables.  OpenFlow tables are most
      78                 :            :  * commonly traversed in numerically increasing order, so this limit has little
      79                 :            :  * effect on conventionally designed OpenFlow pipelines.
      80                 :            :  *
      81                 :            :  * Outputs to patch ports and to groups also count against the depth limit. */
      82                 :            : #define MAX_DEPTH 64
      83                 :            : 
      84                 :            : /* Maximum number of resubmit actions in a flow translation, whether they are
      85                 :            :  * recursive or not. */
      86                 :            : #define MAX_RESUBMITS (MAX_DEPTH * MAX_DEPTH)
      87                 :            : 
      88                 :            : struct xbridge {
      89                 :            :     struct hmap_node hmap_node;   /* Node in global 'xbridges' map. */
      90                 :            :     struct ofproto_dpif *ofproto; /* Key in global 'xbridges' map. */
      91                 :            : 
      92                 :            :     struct ovs_list xbundles;     /* Owned xbundles. */
      93                 :            :     struct hmap xports;           /* Indexed by ofp_port. */
      94                 :            : 
      95                 :            :     char *name;                   /* Name used in log messages. */
      96                 :            :     struct dpif *dpif;            /* Datapath interface. */
      97                 :            :     struct mac_learning *ml;      /* Mac learning handle. */
      98                 :            :     struct mcast_snooping *ms;    /* Multicast Snooping handle. */
      99                 :            :     struct mbridge *mbridge;      /* Mirroring. */
     100                 :            :     struct dpif_sflow *sflow;     /* SFlow handle, or null. */
     101                 :            :     struct dpif_ipfix *ipfix;     /* Ipfix handle, or null. */
     102                 :            :     struct netflow *netflow;      /* Netflow handle, or null. */
     103                 :            :     struct stp *stp;              /* STP or null if disabled. */
     104                 :            :     struct rstp *rstp;            /* RSTP or null if disabled. */
     105                 :            : 
     106                 :            :     bool has_in_band;             /* Bridge has in band control? */
     107                 :            :     bool forward_bpdu;            /* Bridge forwards STP BPDUs? */
     108                 :            : 
     109                 :            :     /* Datapath feature support. */
     110                 :            :     struct dpif_backer_support support;
     111                 :            : };
     112                 :            : 
     113                 :            : struct xbundle {
     114                 :            :     struct hmap_node hmap_node;    /* In global 'xbundles' map. */
     115                 :            :     struct ofbundle *ofbundle;     /* Key in global 'xbundles' map. */
     116                 :            : 
     117                 :            :     struct ovs_list list_node;     /* In parent 'xbridges' list. */
     118                 :            :     struct xbridge *xbridge;       /* Parent xbridge. */
     119                 :            : 
     120                 :            :     struct ovs_list xports;        /* Contains "struct xport"s. */
     121                 :            : 
     122                 :            :     char *name;                    /* Name used in log messages. */
     123                 :            :     struct bond *bond;             /* Nonnull iff more than one port. */
     124                 :            :     struct lacp *lacp;             /* LACP handle or null. */
     125                 :            : 
     126                 :            :     enum port_vlan_mode vlan_mode; /* VLAN mode. */
     127                 :            :     int vlan;                      /* -1=trunk port, else a 12-bit VLAN ID. */
     128                 :            :     unsigned long *trunks;         /* Bitmap of trunked VLANs, if 'vlan' == -1.
     129                 :            :                                     * NULL if all VLANs are trunked. */
     130                 :            :     bool use_priority_tags;        /* Use 802.1p tag for frames in VLAN 0? */
     131                 :            :     bool floodable;                /* No port has OFPUTIL_PC_NO_FLOOD set? */
     132                 :            : };
     133                 :            : 
     134                 :            : struct xport {
     135                 :            :     struct hmap_node hmap_node;      /* Node in global 'xports' map. */
     136                 :            :     struct ofport_dpif *ofport;      /* Key in global 'xports map. */
     137                 :            : 
     138                 :            :     struct hmap_node ofp_node;       /* Node in parent xbridge 'xports' map. */
     139                 :            :     ofp_port_t ofp_port;             /* Key in parent xbridge 'xports' map. */
     140                 :            : 
     141                 :            :     odp_port_t odp_port;             /* Datapath port number or ODPP_NONE. */
     142                 :            : 
     143                 :            :     struct ovs_list bundle_node;     /* In parent xbundle (if it exists). */
     144                 :            :     struct xbundle *xbundle;         /* Parent xbundle or null. */
     145                 :            : 
     146                 :            :     struct netdev *netdev;           /* 'ofport''s netdev. */
     147                 :            : 
     148                 :            :     struct xbridge *xbridge;         /* Parent bridge. */
     149                 :            :     struct xport *peer;              /* Patch port peer or null. */
     150                 :            : 
     151                 :            :     enum ofputil_port_config config; /* OpenFlow port configuration. */
     152                 :            :     enum ofputil_port_state state;   /* OpenFlow port state. */
     153                 :            :     int stp_port_no;                 /* STP port number or -1 if not in use. */
     154                 :            :     struct rstp_port *rstp_port;     /* RSTP port or null. */
     155                 :            : 
     156                 :            :     struct hmap skb_priorities;      /* Map of 'skb_priority_to_dscp's. */
     157                 :            : 
     158                 :            :     bool may_enable;                 /* May be enabled in bonds. */
     159                 :            :     bool is_tunnel;                  /* Is a tunnel port. */
     160                 :            : 
     161                 :            :     struct cfm *cfm;                 /* CFM handle or null. */
     162                 :            :     struct bfd *bfd;                 /* BFD handle or null. */
     163                 :            :     struct lldp *lldp;               /* LLDP handle or null. */
     164                 :            : };
     165                 :            : 
     166                 :            : struct xlate_ctx {
     167                 :            :     struct xlate_in *xin;
     168                 :            :     struct xlate_out *xout;
     169                 :            : 
     170                 :            :     const struct xbridge *xbridge;
     171                 :            : 
     172                 :            :     /* Flow tables version at the beginning of the translation. */
     173                 :            :     ovs_version_t tables_version;
     174                 :            : 
     175                 :            :     /* Flow at the last commit. */
     176                 :            :     struct flow base_flow;
     177                 :            : 
     178                 :            :     /* Tunnel IP destination address as received.  This is stored separately
     179                 :            :      * as the base_flow.tunnel is cleared on init to reflect the datapath
     180                 :            :      * behavior.  Used to make sure not to send tunneled output to ourselves,
     181                 :            :      * which might lead to an infinite loop.  This could happen easily
     182                 :            :      * if a tunnel is marked as 'ip_remote=flow', and the flow does not
     183                 :            :      * actually set the tun_dst field. */
     184                 :            :     struct in6_addr orig_tunnel_ipv6_dst;
     185                 :            : 
     186                 :            :     /* Stack for the push and pop actions.  Each stack element is of type
     187                 :            :      * "union mf_subvalue". */
     188                 :            :     struct ofpbuf stack;
     189                 :            : 
     190                 :            :     /* The rule that we are currently translating, or NULL. */
     191                 :            :     struct rule_dpif *rule;
     192                 :            : 
     193                 :            :     /* Flow translation populates this with wildcards relevant in translation.
     194                 :            :      * When 'xin->wc' is nonnull, this is the same pointer.  When 'xin->wc' is
     195                 :            :      * null, this is a pointer to a temporary buffer. */
     196                 :            :     struct flow_wildcards *wc;
     197                 :            : 
     198                 :            :     /* Output buffer for datapath actions.  When 'xin->odp_actions' is nonnull,
     199                 :            :      * this is the same pointer.  When 'xin->odp_actions' is null, this points
     200                 :            :      * to a scratch ofpbuf.  This allows code to add actions to
     201                 :            :      * 'ctx->odp_actions' without worrying about whether the caller really
     202                 :            :      * wants actions. */
     203                 :            :     struct ofpbuf *odp_actions;
     204                 :            : 
     205                 :            :     /* Statistics maintained by xlate_table_action().
     206                 :            :      *
     207                 :            :      * 'indentation' is the nesting level for resubmits.  It is used to indent
     208                 :            :      * the output of resubmit_hook (e.g. for the "ofproto/trace" feature).
     209                 :            :      *
     210                 :            :      * The other statistics limit the amount of work that a single flow
     211                 :            :      * translation can perform.  The goal of the first of these, 'depth', is
     212                 :            :      * primarily to prevent translation from performing an infinite amount of
     213                 :            :      * work.  It counts the current depth of nested "resubmit"s (and a few
     214                 :            :      * other activities); when a resubmit returns, it decreases.  Resubmits to
     215                 :            :      * tables in strictly monotonically increasing order don't contribute to
     216                 :            :      * 'depth' because they cannot cause a flow translation to take an infinite
     217                 :            :      * amount of time (because the number of tables is finite).  Translation
     218                 :            :      * aborts when 'depth' exceeds MAX_DEPTH.
     219                 :            :      *
     220                 :            :      * 'resubmits', on the other hand, prevents flow translation from
     221                 :            :      * performing an extraordinarily large while still finite amount of work.
     222                 :            :      * It counts the total number of resubmits (and a few other activities)
     223                 :            :      * that have been executed.  Returning from a resubmit does not affect this
     224                 :            :      * counter.  Thus, this limits the amount of work that a particular
     225                 :            :      * translation can perform.  Translation aborts when 'resubmits' exceeds
     226                 :            :      * MAX_RESUBMITS (which is much larger than MAX_DEPTH).
     227                 :            :      */
     228                 :            :     int indentation;            /* Indentation level for resubmit_hook. */
     229                 :            :     int depth;                  /* Current resubmit nesting depth. */
     230                 :            :     int resubmits;              /* Total number of resubmits. */
     231                 :            :     bool in_group;              /* Currently translating ofgroup, if true. */
     232                 :            :     bool in_action_set;         /* Currently translating action_set, if true. */
     233                 :            : 
     234                 :            :     uint8_t table_id;           /* OpenFlow table ID where flow was found. */
     235                 :            :     ovs_be64 rule_cookie;       /* Cookie of the rule being translated. */
     236                 :            :     uint32_t orig_skb_priority; /* Priority when packet arrived. */
     237                 :            :     uint32_t sflow_n_outputs;   /* Number of output ports. */
     238                 :            :     odp_port_t sflow_odp_port;  /* Output port for composing sFlow action. */
     239                 :            :     ofp_port_t nf_output_iface; /* Output interface index for NetFlow. */
     240                 :            :     bool exit;                  /* No further actions should be processed. */
     241                 :            :     mirror_mask_t mirrors;      /* Bitmap of associated mirrors. */
     242                 :            :     int mirror_snaplen;         /* Max size of a mirror packet in byte. */
     243                 :            : 
     244                 :            :    /* Freezing Translation
     245                 :            :     * ====================
     246                 :            :     *
     247                 :            :     * At some point during translation, the code may recognize the need to halt
     248                 :            :     * and checkpoint the translation in a way that it can be restarted again
     249                 :            :     * later.  We call the checkpointing process "freezing" and the restarting
     250                 :            :     * process "thawing".
     251                 :            :     *
     252                 :            :     * The use cases for freezing are:
     253                 :            :     *
     254                 :            :     *     - "Recirculation", where the translation process discovers that it
     255                 :            :     *       doesn't have enough information to complete translation without
     256                 :            :     *       actually executing the actions that have already been translated,
     257                 :            :     *       which provides the additionally needed information.  In these
     258                 :            :     *       situations, translation freezes translation and assigns the frozen
     259                 :            :     *       data a unique "recirculation ID", which it associates with the data
     260                 :            :     *       in a table in userspace (see ofproto-dpif-rid.h).  It also adds a
     261                 :            :     *       OVS_ACTION_ATTR_RECIRC action specifying that ID to the datapath
     262                 :            :     *       actions.  When a packet hits that action, the datapath looks its
     263                 :            :     *       flow up again using the ID.  If there's a miss, it comes back to
     264                 :            :     *       userspace, which find the recirculation table entry for the ID,
     265                 :            :     *       thaws the associated frozen data, and continues translation from
     266                 :            :     *       that point given the additional information that is now known.
     267                 :            :     *
     268                 :            :     *       The archetypal example is MPLS.  As MPLS is implemented in
     269                 :            :     *       OpenFlow, the protocol that follows the last MPLS label becomes
     270                 :            :     *       known only when that label is popped by an OpenFlow action.  That
     271                 :            :     *       means that Open vSwitch can't extract the headers beyond the MPLS
     272                 :            :     *       labels until the pop action is executed.  Thus, at that point
     273                 :            :     *       translation uses the recirculation process to extract the headers
     274                 :            :     *       beyond the MPLS labels.
     275                 :            :     *
     276                 :            :     *       (OVS also uses OVS_ACTION_ATTR_RECIRC to implement hashing for
     277                 :            :     *       output to bonds.  OVS pre-populates all the datapath flows for bond
     278                 :            :     *       output in the datapath, though, which means that the elaborate
     279                 :            :     *       process of coming back to userspace for a second round of
     280                 :            :     *       translation isn't needed, and so bonds don't follow the above
     281                 :            :     *       process.)
     282                 :            :     *
     283                 :            :     *     - "Continuation".  A continuation is a way for an OpenFlow controller
     284                 :            :     *       to interpose on a packet's traversal of the OpenFlow tables.  When
     285                 :            :     *       the translation process encounters a "controller" action with the
     286                 :            :     *       "pause" flag, it freezes translation, serializes the frozen data,
     287                 :            :     *       and sends it to an OpenFlow controller.  The controller then
     288                 :            :     *       examines and possibly modifies the frozen data and eventually sends
     289                 :            :     *       it back to the switch, which thaws it and continues translation.
     290                 :            :     *
     291                 :            :     * The main problem of freezing translation is preserving state, so that
     292                 :            :     * when the translation is thawed later it resumes from where it left off,
     293                 :            :     * without disruption.  In particular, actions must be preserved as follows:
     294                 :            :     *
     295                 :            :     *     - If we're freezing because an action needed more information, the
     296                 :            :     *       action that prompted it.
     297                 :            :     *
     298                 :            :     *     - Any actions remaining to be translated within the current flow.
     299                 :            :     *
     300                 :            :     *     - If translation was frozen within a NXAST_RESUBMIT, then any actions
     301                 :            :     *       following the resubmit action.  Resubmit actions can be nested, so
     302                 :            :     *       this has to go all the way up the control stack.
     303                 :            :     *
     304                 :            :     *     - The OpenFlow 1.1+ action set.
     305                 :            :     *
     306                 :            :     * State that actions and flow table lookups can depend on, such as the
     307                 :            :     * following, must also be preserved:
     308                 :            :     *
     309                 :            :     *     - Metadata fields (input port, registers, OF1.1+ metadata, ...).
     310                 :            :     *
     311                 :            :     *     - The stack used by NXAST_STACK_PUSH and NXAST_STACK_POP actions.
     312                 :            :     *
     313                 :            :     *     - The table ID and cookie of the flow being translated at each level
     314                 :            :     *       of the control stack, because these can become visible through
     315                 :            :     *       OFPAT_CONTROLLER actions (and other ways).
     316                 :            :     *
     317                 :            :     * Translation allows for the control of this state preservation via these
     318                 :            :     * members.  When a need to freeze translation is identified, the
     319                 :            :     * translation process:
     320                 :            :     *
     321                 :            :     * 1. Sets 'freezing' to true.
     322                 :            :     *
     323                 :            :     * 2. Sets 'exit' to true to tell later steps that we're exiting from the
     324                 :            :     *    translation process.
     325                 :            :     *
     326                 :            :     * 3. Adds an OFPACT_UNROLL_XLATE action to 'frozen_actions', and points
     327                 :            :     *    frozen_actions.header to the action to make it easy to find it later.
     328                 :            :     *    This action holds the current table ID and cookie so that they can be
     329                 :            :     *    restored during a post-recirculation upcall translation.
     330                 :            :     *
     331                 :            :     * 4. Adds the action that prompted recirculation and any actions following
     332                 :            :     *    it within the same flow to 'frozen_actions', so that they can be
     333                 :            :     *    executed during a post-recirculation upcall translation.
     334                 :            :     *
     335                 :            :     * 5. Returns.
     336                 :            :     *
     337                 :            :     * 6. The action that prompted recirculation might be nested in a stack of
     338                 :            :     *    nested "resubmit"s that have actions remaining.  Each of these notices
     339                 :            :     *    that we're exiting and freezing and responds by adding more
     340                 :            :     *    OFPACT_UNROLL_XLATE actions to 'frozen_actions', as necessary,
     341                 :            :     *    followed by any actions that were yet unprocessed.
     342                 :            :     *
     343                 :            :     * If we're freezing because of recirculation, the caller generates a
     344                 :            :     * recirculation ID and associates all the state produced by this process
     345                 :            :     * with it.  For post-recirculation upcall translation, the caller passes it
     346                 :            :     * back in for the new translation to execute.  The process yielded a set of
     347                 :            :     * ofpacts that can be translated directly, so it is not much of a special
     348                 :            :     * case at that point.
     349                 :            :     */
     350                 :            :     bool freezing;
     351                 :            :     struct ofpbuf frozen_actions;
     352                 :            :     const struct ofpact_controller *pause;
     353                 :            : 
     354                 :            :     /* True if a packet was but is no longer MPLS (due to an MPLS pop action).
     355                 :            :      * This is a trigger for recirculation in cases where translating an action
     356                 :            :      * or looking up a flow requires access to the fields of the packet after
     357                 :            :      * the MPLS label stack that was originally present. */
     358                 :            :     bool was_mpls;
     359                 :            : 
     360                 :            :     /* True if conntrack has been performed on this packet during processing
     361                 :            :      * on the current bridge. This is used to determine whether conntrack
     362                 :            :      * state from the datapath should be honored after thawing. */
     363                 :            :     bool conntracked;
     364                 :            : 
     365                 :            :     /* Pointer to an embedded NAT action in a conntrack action, or NULL. */
     366                 :            :     struct ofpact_nat *ct_nat_action;
     367                 :            : 
     368                 :            :     /* OpenFlow 1.1+ action set.
     369                 :            :      *
     370                 :            :      * 'action_set' accumulates "struct ofpact"s added by OFPACT_WRITE_ACTIONS.
     371                 :            :      * When translation is otherwise complete, ofpacts_execute_action_set()
     372                 :            :      * converts it to a set of "struct ofpact"s that can be translated into
     373                 :            :      * datapath actions. */
     374                 :            :     bool action_set_has_group;  /* Action set contains OFPACT_GROUP? */
     375                 :            :     struct ofpbuf action_set;   /* Action set. */
     376                 :            : 
     377                 :            :     enum xlate_error error;     /* Translation failed. */
     378                 :            : };
     379                 :            : 
     380                 :          4 : const char *xlate_strerror(enum xlate_error error)
     381                 :            : {
     382   [ -  -  +  +  :          4 :     switch (error) {
             +  -  -  -  
                      - ]
     383                 :            :     case XLATE_OK:
     384                 :          0 :         return "OK";
     385                 :            :     case XLATE_BRIDGE_NOT_FOUND:
     386                 :          0 :         return "Bridge not found";
     387                 :            :     case XLATE_RECURSION_TOO_DEEP:
     388                 :          2 :         return "Recursion too deep";
     389                 :            :     case XLATE_TOO_MANY_RESUBMITS:
     390                 :          1 :         return "Too many resubmits";
     391                 :            :     case XLATE_STACK_TOO_DEEP:
     392                 :          1 :         return "Stack too deep";
     393                 :            :     case XLATE_NO_RECIRCULATION_CONTEXT:
     394                 :          0 :         return "No recirculation context";
     395                 :            :     case XLATE_RECIRCULATION_CONFLICT:
     396                 :          0 :         return "Recirculation conflict";
     397                 :            :     case XLATE_TOO_MANY_MPLS_LABELS:
     398                 :          0 :         return "Too many MPLS labels";
     399                 :            :     }
     400                 :          0 :     return "Unknown error";
     401                 :            : }
     402                 :            : 
     403                 :            : static void xlate_action_set(struct xlate_ctx *ctx);
     404                 :            : static void xlate_commit_actions(struct xlate_ctx *ctx);
     405                 :            : 
     406                 :            : static void
     407                 :        317 : ctx_trigger_freeze(struct xlate_ctx *ctx)
     408                 :            : {
     409                 :        317 :     ctx->exit = true;
     410                 :        317 :     ctx->freezing = true;
     411                 :        317 : }
     412                 :            : 
     413                 :            : static bool
     414                 :        280 : ctx_first_frozen_action(const struct xlate_ctx *ctx)
     415                 :            : {
     416                 :        280 :     return !ctx->frozen_actions.size;
     417                 :            : }
     418                 :            : 
     419                 :            : static void
     420                 :       1220 : ctx_cancel_freeze(struct xlate_ctx *ctx)
     421                 :            : {
     422         [ +  - ]:       1220 :     if (ctx->freezing) {
     423                 :       1220 :         ctx->freezing = false;
     424                 :       1220 :         ofpbuf_clear(&ctx->frozen_actions);
     425                 :       1220 :         ctx->frozen_actions.header = NULL;
     426                 :            :     }
     427                 :       1220 : }
     428                 :            : 
     429                 :            : static void finish_freezing(struct xlate_ctx *ctx);
     430                 :            : 
     431                 :            : /* A controller may use OFPP_NONE as the ingress port to indicate that
     432                 :            :  * it did not arrive on a "real" port.  'ofpp_none_bundle' exists for
     433                 :            :  * when an input bundle is needed for validation (e.g., mirroring or
     434                 :            :  * OFPP_NORMAL processing).  It is not connected to an 'ofproto' or have
     435                 :            :  * any 'port' structs, so care must be taken when dealing with it. */
     436                 :            : static struct xbundle ofpp_none_bundle = {
     437                 :            :     .name      = "OFPP_NONE",
     438                 :            :     .vlan_mode = PORT_VLAN_TRUNK
     439                 :            : };
     440                 :            : 
     441                 :            : /* Node in 'xport''s 'skb_priorities' map.  Used to maintain a map from
     442                 :            :  * 'priority' (the datapath's term for QoS queue) to the dscp bits which all
     443                 :            :  * traffic egressing the 'ofport' with that priority should be marked with. */
     444                 :            : struct skb_priority_to_dscp {
     445                 :            :     struct hmap_node hmap_node; /* Node in 'ofport_dpif''s 'skb_priorities'. */
     446                 :            :     uint32_t skb_priority;      /* Priority of this queue (see struct flow). */
     447                 :            : 
     448                 :            :     uint8_t dscp;               /* DSCP bits to mark outgoing traffic with. */
     449                 :            : };
     450                 :            : 
     451                 :            : enum xc_type {
     452                 :            :     XC_RULE,
     453                 :            :     XC_BOND,
     454                 :            :     XC_NETDEV,
     455                 :            :     XC_NETFLOW,
     456                 :            :     XC_MIRROR,
     457                 :            :     XC_LEARN,
     458                 :            :     XC_NORMAL,
     459                 :            :     XC_FIN_TIMEOUT,
     460                 :            :     XC_GROUP,
     461                 :            :     XC_TNL_NEIGH,
     462                 :            : };
     463                 :            : 
     464                 :            : /* xlate_cache entries hold enough information to perform the side effects of
     465                 :            :  * xlate_actions() for a rule, without needing to perform rule translation
     466                 :            :  * from scratch. The primary usage of these is to submit statistics to objects
     467                 :            :  * that a flow relates to, although they may be used for other effects as well
     468                 :            :  * (for instance, refreshing hard timeouts for learned flows). */
     469                 :            : struct xc_entry {
     470                 :            :     enum xc_type type;
     471                 :            :     union {
     472                 :            :         struct rule_dpif *rule;
     473                 :            :         struct {
     474                 :            :             struct netdev *tx;
     475                 :            :             struct netdev *rx;
     476                 :            :             struct bfd *bfd;
     477                 :            :         } dev;
     478                 :            :         struct {
     479                 :            :             struct netflow *netflow;
     480                 :            :             struct flow *flow;
     481                 :            :             ofp_port_t iface;
     482                 :            :         } nf;
     483                 :            :         struct {
     484                 :            :             struct mbridge *mbridge;
     485                 :            :             mirror_mask_t mirrors;
     486                 :            :         } mirror;
     487                 :            :         struct {
     488                 :            :             struct bond *bond;
     489                 :            :             struct flow *flow;
     490                 :            :             uint16_t vid;
     491                 :            :         } bond;
     492                 :            :         struct {
     493                 :            :             struct ofproto_dpif *ofproto;
     494                 :            :             struct ofputil_flow_mod *fm;
     495                 :            :             struct ofpbuf *ofpacts;
     496                 :            :         } learn;
     497                 :            :         struct {
     498                 :            :             struct ofproto_dpif *ofproto;
     499                 :            :             struct flow *flow;
     500                 :            :             int vlan;
     501                 :            :         } normal;
     502                 :            :         struct {
     503                 :            :             struct rule_dpif *rule;
     504                 :            :             uint16_t idle;
     505                 :            :             uint16_t hard;
     506                 :            :         } fin;
     507                 :            :         struct {
     508                 :            :             struct group_dpif *group;
     509                 :            :             struct ofputil_bucket *bucket;
     510                 :            :         } group;
     511                 :            :         struct {
     512                 :            :             char br_name[IFNAMSIZ];
     513                 :            :             struct in6_addr d_ipv6;
     514                 :            :         } tnl_neigh_cache;
     515                 :            :     } u;
     516                 :            : };
     517                 :            : 
     518                 :            : #define XC_ENTRY_FOR_EACH(ENTRY, ENTRIES, XCACHE)               \
     519                 :            :     ENTRIES = XCACHE->entries;                                  \
     520                 :            :     for (ENTRY = ofpbuf_try_pull(&ENTRIES, sizeof *ENTRY);      \
     521                 :            :          ENTRY;                                                 \
     522                 :            :          ENTRY = ofpbuf_try_pull(&ENTRIES, sizeof *ENTRY))
     523                 :            : 
     524                 :            : struct xlate_cache {
     525                 :            :     struct ofpbuf entries;
     526                 :            : };
     527                 :            : 
     528                 :            : /* Xlate config contains hash maps of all bridges, bundles and ports.
     529                 :            :  * Xcfgp contains the pointer to the current xlate configuration.
     530                 :            :  * When the main thread needs to change the configuration, it copies xcfgp to
     531                 :            :  * new_xcfg and edits new_xcfg. This enables the use of RCU locking which
     532                 :            :  * does not block handler and revalidator threads. */
     533                 :            : struct xlate_cfg {
     534                 :            :     struct hmap xbridges;
     535                 :            :     struct hmap xbundles;
     536                 :            :     struct hmap xports;
     537                 :            : };
     538                 :            : static OVSRCU_TYPE(struct xlate_cfg *) xcfgp = OVSRCU_INITIALIZER(NULL);
     539                 :            : static struct xlate_cfg *new_xcfg = NULL;
     540                 :            : 
     541                 :            : static bool may_receive(const struct xport *, struct xlate_ctx *);
     542                 :            : static void do_xlate_actions(const struct ofpact *, size_t ofpacts_len,
     543                 :            :                              struct xlate_ctx *);
     544                 :            : static void xlate_normal(struct xlate_ctx *);
     545                 :            : static inline void xlate_report(struct xlate_ctx *, const char *, ...)
     546                 :            :     OVS_PRINTF_FORMAT(2, 3);
     547                 :            : static void xlate_table_action(struct xlate_ctx *, ofp_port_t in_port,
     548                 :            :                                uint8_t table_id, bool may_packet_in,
     549                 :            :                                bool honor_table_miss);
     550                 :            : static bool input_vid_is_valid(uint16_t vid, struct xbundle *, bool warn);
     551                 :            : static uint16_t input_vid_to_vlan(const struct xbundle *, uint16_t vid);
     552                 :            : static void output_normal(struct xlate_ctx *, const struct xbundle *,
     553                 :            :                           uint16_t vlan);
     554                 :            : 
     555                 :            : /* Optional bond recirculation parameter to compose_output_action(). */
     556                 :            : struct xlate_bond_recirc {
     557                 :            :     uint32_t recirc_id;  /* !0 Use recirculation instead of output. */
     558                 :            :     uint8_t  hash_alg;   /* !0 Compute hash for recirc before. */
     559                 :            :     uint32_t hash_basis;  /* Compute hash for recirc before. */
     560                 :            : };
     561                 :            : 
     562                 :            : static void compose_output_action(struct xlate_ctx *, ofp_port_t ofp_port,
     563                 :            :                                   const struct xlate_bond_recirc *xr);
     564                 :            : 
     565                 :            : static struct xbridge *xbridge_lookup(struct xlate_cfg *,
     566                 :            :                                       const struct ofproto_dpif *);
     567                 :            : static struct xbridge *xbridge_lookup_by_uuid(struct xlate_cfg *,
     568                 :            :                                               const struct uuid *);
     569                 :            : static struct xbundle *xbundle_lookup(struct xlate_cfg *,
     570                 :            :                                       const struct ofbundle *);
     571                 :            : static struct xport *xport_lookup(struct xlate_cfg *,
     572                 :            :                                   const struct ofport_dpif *);
     573                 :            : static struct xport *get_ofp_port(const struct xbridge *, ofp_port_t ofp_port);
     574                 :            : static struct skb_priority_to_dscp *get_skb_priority(const struct xport *,
     575                 :            :                                                      uint32_t skb_priority);
     576                 :            : static void clear_skb_priorities(struct xport *);
     577                 :            : static size_t count_skb_priorities(const struct xport *);
     578                 :            : static bool dscp_from_skb_priority(const struct xport *, uint32_t skb_priority,
     579                 :            :                                    uint8_t *dscp);
     580                 :            : 
     581                 :            : static struct xc_entry *xlate_cache_add_entry(struct xlate_cache *xc,
     582                 :            :                                               enum xc_type type);
     583                 :            : static void xlate_xbridge_init(struct xlate_cfg *, struct xbridge *);
     584                 :            : static void xlate_xbundle_init(struct xlate_cfg *, struct xbundle *);
     585                 :            : static void xlate_xport_init(struct xlate_cfg *, struct xport *);
     586                 :            : static void xlate_xbridge_set(struct xbridge *, struct dpif *,
     587                 :            :                               const struct mac_learning *, struct stp *,
     588                 :            :                               struct rstp *, const struct mcast_snooping *,
     589                 :            :                               const struct mbridge *,
     590                 :            :                               const struct dpif_sflow *,
     591                 :            :                               const struct dpif_ipfix *,
     592                 :            :                               const struct netflow *,
     593                 :            :                               bool forward_bpdu, bool has_in_band,
     594                 :            :                               const struct dpif_backer_support *);
     595                 :            : static void xlate_xbundle_set(struct xbundle *xbundle,
     596                 :            :                               enum port_vlan_mode vlan_mode, int vlan,
     597                 :            :                               unsigned long *trunks, bool use_priority_tags,
     598                 :            :                               const struct bond *bond, const struct lacp *lacp,
     599                 :            :                               bool floodable);
     600                 :            : static void xlate_xport_set(struct xport *xport, odp_port_t odp_port,
     601                 :            :                             const struct netdev *netdev, const struct cfm *cfm,
     602                 :            :                             const struct bfd *bfd, const struct lldp *lldp,
     603                 :            :                             int stp_port_no, const struct rstp_port *rstp_port,
     604                 :            :                             enum ofputil_port_config config,
     605                 :            :                             enum ofputil_port_state state, bool is_tunnel,
     606                 :            :                             bool may_enable);
     607                 :            : static void xlate_xbridge_remove(struct xlate_cfg *, struct xbridge *);
     608                 :            : static void xlate_xbundle_remove(struct xlate_cfg *, struct xbundle *);
     609                 :            : static void xlate_xport_remove(struct xlate_cfg *, struct xport *);
     610                 :            : static void xlate_xbridge_copy(struct xbridge *);
     611                 :            : static void xlate_xbundle_copy(struct xbridge *, struct xbundle *);
     612                 :            : static void xlate_xport_copy(struct xbridge *, struct xbundle *,
     613                 :            :                              struct xport *);
     614                 :            : static void xlate_xcfg_free(struct xlate_cfg *);
     615                 :            : 
     616                 :            : static inline void
     617                 :      48581 : xlate_report(struct xlate_ctx *ctx, const char *format, ...)
     618                 :            : {
     619         [ +  + ]:      48581 :     if (OVS_UNLIKELY(ctx->xin->report_hook)) {
     620                 :            :         va_list args;
     621                 :            : 
     622                 :        266 :         va_start(args, format);
     623                 :        266 :         ctx->xin->report_hook(ctx->xin, ctx->indentation, format, args);
     624                 :        266 :         va_end(args);
     625                 :            :     }
     626                 :      48581 : }
     627                 :            : 
     628                 :            : static struct vlog_rate_limit error_report_rl = VLOG_RATE_LIMIT_INIT(1, 5);
     629                 :            : 
     630                 :            : #define XLATE_REPORT_ERROR(CTX, ...)                            \
     631                 :            :     do {                                                        \
     632                 :            :         if (OVS_UNLIKELY((CTX)->xin->report_hook)) {            \
     633                 :            :             xlate_report(CTX, __VA_ARGS__);                     \
     634                 :            :         } else {                                                \
     635                 :            :             struct ds ds = DS_EMPTY_INITIALIZER;                \
     636                 :            :                                                                 \
     637                 :            :             ds_put_format(&ds, __VA_ARGS__);                    \
     638                 :            :             ds_put_cstr(&ds, ": ");                             \
     639                 :            :             flow_format(&ds, &(CTX)->base_flow);                \
     640                 :            :             VLOG_ERR_RL(&error_report_rl, "%s", ds_cstr(&ds));  \
     641                 :            :             ds_destroy(&ds);                                    \
     642                 :            :         }                                                       \
     643                 :            :     } while (0)
     644                 :            : 
     645                 :            : static inline void
     646                 :        279 : xlate_report_actions(struct xlate_ctx *ctx, const char *title,
     647                 :            :                      const struct ofpact *ofpacts, size_t ofpacts_len)
     648                 :            : {
     649         [ +  + ]:        279 :     if (OVS_UNLIKELY(ctx->xin->report_hook)) {
     650                 :          7 :         struct ds s = DS_EMPTY_INITIALIZER;
     651                 :          7 :         ofpacts_format(ofpacts, ofpacts_len, &s);
     652                 :          7 :         xlate_report(ctx, "%s: %s", title, ds_cstr(&s));
     653                 :          7 :         ds_destroy(&s);
     654                 :            :     }
     655                 :        279 : }
     656                 :            : 
     657                 :            : static void
     658                 :      41774 : xlate_xbridge_init(struct xlate_cfg *xcfg, struct xbridge *xbridge)
     659                 :            : {
     660                 :      41774 :     ovs_list_init(&xbridge->xbundles);
     661                 :      41774 :     hmap_init(&xbridge->xports);
     662                 :      41774 :     hmap_insert(&xcfg->xbridges, &xbridge->hmap_node,
     663                 :            :                 hash_pointer(xbridge->ofproto, 0));
     664                 :      41774 : }
     665                 :            : 
     666                 :            : static void
     667                 :     193723 : xlate_xbundle_init(struct xlate_cfg *xcfg, struct xbundle *xbundle)
     668                 :            : {
     669                 :     193723 :     ovs_list_init(&xbundle->xports);
     670                 :     193723 :     ovs_list_insert(&xbundle->xbridge->xbundles, &xbundle->list_node);
     671                 :     193723 :     hmap_insert(&xcfg->xbundles, &xbundle->hmap_node,
     672                 :            :                 hash_pointer(xbundle->ofbundle, 0));
     673                 :     193723 : }
     674                 :            : 
     675                 :            : static void
     676                 :     246497 : xlate_xport_init(struct xlate_cfg *xcfg, struct xport *xport)
     677                 :            : {
     678                 :     246497 :     hmap_init(&xport->skb_priorities);
     679                 :     246497 :     hmap_insert(&xcfg->xports, &xport->hmap_node,
     680                 :            :                 hash_pointer(xport->ofport, 0));
     681                 :     246497 :     hmap_insert(&xport->xbridge->xports, &xport->ofp_node,
     682                 :            :                 hash_ofp_port(xport->ofp_port));
     683                 :     246497 : }
     684                 :            : 
     685                 :            : static void
     686                 :      64084 : xlate_xbridge_set(struct xbridge *xbridge,
     687                 :            :                   struct dpif *dpif,
     688                 :            :                   const struct mac_learning *ml, struct stp *stp,
     689                 :            :                   struct rstp *rstp, const struct mcast_snooping *ms,
     690                 :            :                   const struct mbridge *mbridge,
     691                 :            :                   const struct dpif_sflow *sflow,
     692                 :            :                   const struct dpif_ipfix *ipfix,
     693                 :            :                   const struct netflow *netflow,
     694                 :            :                   bool forward_bpdu, bool has_in_band,
     695                 :            :                   const struct dpif_backer_support *support)
     696                 :            : {
     697         [ +  + ]:      64084 :     if (xbridge->ml != ml) {
     698                 :      41774 :         mac_learning_unref(xbridge->ml);
     699                 :      41774 :         xbridge->ml = mac_learning_ref(ml);
     700                 :            :     }
     701                 :            : 
     702         [ -  + ]:      64084 :     if (xbridge->ms != ms) {
     703                 :          0 :         mcast_snooping_unref(xbridge->ms);
     704                 :          0 :         xbridge->ms = mcast_snooping_ref(ms);
     705                 :            :     }
     706                 :            : 
     707         [ +  + ]:      64084 :     if (xbridge->mbridge != mbridge) {
     708                 :      41774 :         mbridge_unref(xbridge->mbridge);
     709                 :      41774 :         xbridge->mbridge = mbridge_ref(mbridge);
     710                 :            :     }
     711                 :            : 
     712         [ +  + ]:      64084 :     if (xbridge->sflow != sflow) {
     713                 :         58 :         dpif_sflow_unref(xbridge->sflow);
     714                 :         58 :         xbridge->sflow = dpif_sflow_ref(sflow);
     715                 :            :     }
     716                 :            : 
     717         [ +  + ]:      64084 :     if (xbridge->ipfix != ipfix) {
     718                 :         32 :         dpif_ipfix_unref(xbridge->ipfix);
     719                 :         32 :         xbridge->ipfix = dpif_ipfix_ref(ipfix);
     720                 :            :     }
     721                 :            : 
     722         [ +  + ]:      64084 :     if (xbridge->stp != stp) {
     723                 :         64 :         stp_unref(xbridge->stp);
     724                 :         64 :         xbridge->stp = stp_ref(stp);
     725                 :            :     }
     726                 :            : 
     727         [ +  + ]:      64084 :     if (xbridge->rstp != rstp) {
     728                 :         77 :         rstp_unref(xbridge->rstp);
     729                 :         77 :         xbridge->rstp = rstp_ref(rstp);
     730                 :            :     }
     731                 :            : 
     732         [ +  + ]:      64084 :     if (xbridge->netflow != netflow) {
     733                 :         62 :         netflow_unref(xbridge->netflow);
     734                 :         62 :         xbridge->netflow = netflow_ref(netflow);
     735                 :            :     }
     736                 :            : 
     737                 :      64084 :     xbridge->dpif = dpif;
     738                 :      64084 :     xbridge->forward_bpdu = forward_bpdu;
     739                 :      64084 :     xbridge->has_in_band = has_in_band;
     740                 :      64084 :     xbridge->support = *support;
     741                 :      64084 : }
     742                 :            : 
     743                 :            : static void
     744                 :     290718 : xlate_xbundle_set(struct xbundle *xbundle,
     745                 :            :                   enum port_vlan_mode vlan_mode, int vlan,
     746                 :            :                   unsigned long *trunks, bool use_priority_tags,
     747                 :            :                   const struct bond *bond, const struct lacp *lacp,
     748                 :            :                   bool floodable)
     749                 :            : {
     750         [ -  + ]:     290718 :     ovs_assert(xbundle->xbridge);
     751                 :            : 
     752                 :     290718 :     xbundle->vlan_mode = vlan_mode;
     753                 :     290718 :     xbundle->vlan = vlan;
     754                 :     290718 :     xbundle->trunks = trunks;
     755                 :     290718 :     xbundle->use_priority_tags = use_priority_tags;
     756                 :     290718 :     xbundle->floodable = floodable;
     757                 :            : 
     758         [ +  + ]:     290718 :     if (xbundle->bond != bond) {
     759                 :        747 :         bond_unref(xbundle->bond);
     760                 :        747 :         xbundle->bond = bond_ref(bond);
     761                 :            :     }
     762                 :            : 
     763         [ +  + ]:     290718 :     if (xbundle->lacp != lacp) {
     764                 :        229 :         lacp_unref(xbundle->lacp);
     765                 :        229 :         xbundle->lacp = lacp_ref(lacp);
     766                 :            :     }
     767                 :     290718 : }
     768                 :            : 
     769                 :            : static void
     770                 :     344117 : xlate_xport_set(struct xport *xport, odp_port_t odp_port,
     771                 :            :                 const struct netdev *netdev, const struct cfm *cfm,
     772                 :            :                 const struct bfd *bfd, const struct lldp *lldp, int stp_port_no,
     773                 :            :                 const struct rstp_port* rstp_port,
     774                 :            :                 enum ofputil_port_config config, enum ofputil_port_state state,
     775                 :            :                 bool is_tunnel, bool may_enable)
     776                 :            : {
     777                 :     344117 :     xport->config = config;
     778                 :     344117 :     xport->state = state;
     779                 :     344117 :     xport->stp_port_no = stp_port_no;
     780                 :     344117 :     xport->is_tunnel = is_tunnel;
     781                 :     344117 :     xport->may_enable = may_enable;
     782                 :     344117 :     xport->odp_port = odp_port;
     783                 :            : 
     784         [ +  + ]:     344117 :     if (xport->rstp_port != rstp_port) {
     785                 :         60 :         rstp_port_unref(xport->rstp_port);
     786                 :         60 :         xport->rstp_port = rstp_port_ref(rstp_port);
     787                 :            :     }
     788                 :            : 
     789         [ +  + ]:     344117 :     if (xport->cfm != cfm) {
     790                 :        183 :         cfm_unref(xport->cfm);
     791                 :        183 :         xport->cfm = cfm_ref(cfm);
     792                 :            :     }
     793                 :            : 
     794         [ +  + ]:     344117 :     if (xport->bfd != bfd) {
     795                 :      80441 :         bfd_unref(xport->bfd);
     796                 :      80441 :         xport->bfd = bfd_ref(bfd);
     797                 :            :     }
     798                 :            : 
     799         [ -  + ]:     344117 :     if (xport->lldp != lldp) {
     800                 :          0 :         lldp_unref(xport->lldp);
     801                 :          0 :         xport->lldp = lldp_ref(lldp);
     802                 :            :     }
     803                 :            : 
     804         [ +  + ]:     344117 :     if (xport->netdev != netdev) {
     805                 :     246497 :         netdev_close(xport->netdev);
     806                 :     246497 :         xport->netdev = netdev_ref(netdev);
     807                 :            :     }
     808                 :     344117 : }
     809                 :            : 
     810                 :            : static void
     811                 :      41025 : xlate_xbridge_copy(struct xbridge *xbridge)
     812                 :            : {
     813                 :            :     struct xbundle *xbundle;
     814                 :            :     struct xport *xport;
     815                 :      41025 :     struct xbridge *new_xbridge = xzalloc(sizeof *xbridge);
     816                 :      41025 :     new_xbridge->ofproto = xbridge->ofproto;
     817                 :      41025 :     new_xbridge->name = xstrdup(xbridge->name);
     818                 :      41025 :     xlate_xbridge_init(new_xcfg, new_xbridge);
     819                 :            : 
     820                 :      41025 :     xlate_xbridge_set(new_xbridge,
     821                 :      41025 :                       xbridge->dpif, xbridge->ml, xbridge->stp,
     822                 :      41025 :                       xbridge->rstp, xbridge->ms, xbridge->mbridge,
     823                 :      41025 :                       xbridge->sflow, xbridge->ipfix, xbridge->netflow,
     824                 :      82050 :                       xbridge->forward_bpdu, xbridge->has_in_band,
     825                 :      41025 :                       &xbridge->support);
     826         [ +  + ]:     232081 :     LIST_FOR_EACH (xbundle, list_node, &xbridge->xbundles) {
     827                 :     191056 :         xlate_xbundle_copy(new_xbridge, xbundle);
     828                 :            :     }
     829                 :            : 
     830                 :            :     /* Copy xports which are not part of a xbundle */
     831 [ +  + ][ -  + ]:     284833 :     HMAP_FOR_EACH (xport, ofp_node, &xbridge->xports) {
     832         [ +  + ]:     243808 :         if (!xport->xbundle) {
     833                 :      51566 :             xlate_xport_copy(new_xbridge, NULL, xport);
     834                 :            :         }
     835                 :            :     }
     836                 :      41025 : }
     837                 :            : 
     838                 :            : static void
     839                 :     191056 : xlate_xbundle_copy(struct xbridge *xbridge, struct xbundle *xbundle)
     840                 :            : {
     841                 :            :     struct xport *xport;
     842                 :     191056 :     struct xbundle *new_xbundle = xzalloc(sizeof *xbundle);
     843                 :     191056 :     new_xbundle->ofbundle = xbundle->ofbundle;
     844                 :     191056 :     new_xbundle->xbridge = xbridge;
     845                 :     191056 :     new_xbundle->name = xstrdup(xbundle->name);
     846                 :     191056 :     xlate_xbundle_init(new_xcfg, new_xbundle);
     847                 :            : 
     848                 :     191056 :     xlate_xbundle_set(new_xbundle, xbundle->vlan_mode,
     849                 :            :                       xbundle->vlan, xbundle->trunks,
     850                 :     191056 :                       xbundle->use_priority_tags, xbundle->bond, xbundle->lacp,
     851                 :     191056 :                       xbundle->floodable);
     852         [ +  + ]:     383298 :     LIST_FOR_EACH (xport, bundle_node, &xbundle->xports) {
     853                 :     192242 :         xlate_xport_copy(xbridge, new_xbundle, xport);
     854                 :            :     }
     855                 :     191056 : }
     856                 :            : 
     857                 :            : static void
     858                 :     243808 : xlate_xport_copy(struct xbridge *xbridge, struct xbundle *xbundle,
     859                 :            :                  struct xport *xport)
     860                 :            : {
     861                 :            :     struct skb_priority_to_dscp *pdscp, *new_pdscp;
     862                 :     243808 :     struct xport *new_xport = xzalloc(sizeof *xport);
     863                 :     243808 :     new_xport->ofport = xport->ofport;
     864                 :     243808 :     new_xport->ofp_port = xport->ofp_port;
     865                 :     243808 :     new_xport->xbridge = xbridge;
     866                 :     243808 :     xlate_xport_init(new_xcfg, new_xport);
     867                 :            : 
     868                 :     243808 :     xlate_xport_set(new_xport, xport->odp_port, xport->netdev, xport->cfm,
     869                 :     243808 :                     xport->bfd, xport->lldp, xport->stp_port_no,
     870                 :     243808 :                     xport->rstp_port, xport->config, xport->state,
     871                 :     487616 :                     xport->is_tunnel, xport->may_enable);
     872                 :            : 
     873         [ +  + ]:     243808 :     if (xport->peer) {
     874                 :      61234 :         struct xport *peer = xport_lookup(new_xcfg, xport->peer->ofport);
     875         [ +  + ]:      61234 :         if (peer) {
     876                 :      30617 :             new_xport->peer = peer;
     877                 :      30617 :             new_xport->peer->peer = new_xport;
     878                 :            :         }
     879                 :            :     }
     880                 :            : 
     881         [ +  + ]:     243808 :     if (xbundle) {
     882                 :     192242 :         new_xport->xbundle = xbundle;
     883                 :     192242 :         ovs_list_insert(&new_xport->xbundle->xports, &new_xport->bundle_node);
     884                 :            :     }
     885                 :            : 
     886 [ +  + ][ -  + ]:     243818 :     HMAP_FOR_EACH (pdscp, hmap_node, &xport->skb_priorities) {
     887                 :         10 :         new_pdscp = xmalloc(sizeof *pdscp);
     888                 :         10 :         new_pdscp->skb_priority = pdscp->skb_priority;
     889                 :         10 :         new_pdscp->dscp = pdscp->dscp;
     890                 :         10 :         hmap_insert(&new_xport->skb_priorities, &new_pdscp->hmap_node,
     891                 :            :                     hash_int(new_pdscp->skb_priority, 0));
     892                 :            :     }
     893                 :     243808 : }
     894                 :            : 
     895                 :            : /* Sets the current xlate configuration to new_xcfg and frees the old xlate
     896                 :            :  * configuration in xcfgp.
     897                 :            :  *
     898                 :            :  * This needs to be called after editing the xlate configuration.
     899                 :            :  *
     900                 :            :  * Functions that edit the new xlate configuration are
     901                 :            :  * xlate_<ofproto/bundle/ofport>_set and xlate_<ofproto/bundle/ofport>_remove.
     902                 :            :  *
     903                 :            :  * A sample workflow:
     904                 :            :  *
     905                 :            :  * xlate_txn_start();
     906                 :            :  * ...
     907                 :            :  * edit_xlate_configuration();
     908                 :            :  * ...
     909                 :            :  * xlate_txn_commit(); */
     910                 :            : void
     911                 :      29164 : xlate_txn_commit(void)
     912                 :            : {
     913                 :      29164 :     struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
     914                 :            : 
     915                 :      29164 :     ovsrcu_set(&xcfgp, new_xcfg);
     916                 :      29164 :     ovsrcu_synchronize();
     917                 :      29164 :     xlate_xcfg_free(xcfg);
     918                 :      29164 :     new_xcfg = NULL;
     919                 :      29164 : }
     920                 :            : 
     921                 :            : /* Copies the current xlate configuration in xcfgp to new_xcfg.
     922                 :            :  *
     923                 :            :  * This needs to be called prior to editing the xlate configuration. */
     924                 :            : void
     925                 :      29164 : xlate_txn_start(void)
     926                 :            : {
     927                 :            :     struct xbridge *xbridge;
     928                 :            :     struct xlate_cfg *xcfg;
     929                 :            : 
     930         [ -  + ]:      29164 :     ovs_assert(!new_xcfg);
     931                 :            : 
     932                 :      29164 :     new_xcfg = xmalloc(sizeof *new_xcfg);
     933                 :      29164 :     hmap_init(&new_xcfg->xbridges);
     934                 :      29164 :     hmap_init(&new_xcfg->xbundles);
     935                 :      29164 :     hmap_init(&new_xcfg->xports);
     936                 :            : 
     937                 :      29164 :     xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
     938         [ +  + ]:      29164 :     if (!xcfg) {
     939                 :        614 :         return;
     940                 :            :     }
     941                 :            : 
     942 [ +  + ][ -  + ]:      69575 :     HMAP_FOR_EACH (xbridge, hmap_node, &xcfg->xbridges) {
     943                 :      41025 :         xlate_xbridge_copy(xbridge);
     944                 :            :     }
     945                 :            : }
     946                 :            : 
     947                 :            : 
     948                 :            : static void
     949                 :      29164 : xlate_xcfg_free(struct xlate_cfg *xcfg)
     950                 :            : {
     951                 :            :     struct xbridge *xbridge, *next_xbridge;
     952                 :            : 
     953         [ +  + ]:      29164 :     if (!xcfg) {
     954                 :        614 :         return;
     955                 :            :     }
     956                 :            : 
     957 [ +  + ][ -  + ]:      69575 :     HMAP_FOR_EACH_SAFE (xbridge, next_xbridge, hmap_node, &xcfg->xbridges) {
                 [ +  + ]
     958                 :      41025 :         xlate_xbridge_remove(xcfg, xbridge);
     959                 :            :     }
     960                 :            : 
     961                 :      28550 :     hmap_destroy(&xcfg->xbridges);
     962                 :      28550 :     hmap_destroy(&xcfg->xbundles);
     963                 :      28550 :     hmap_destroy(&xcfg->xports);
     964                 :      28550 :     free(xcfg);
     965                 :            : }
     966                 :            : 
     967                 :            : void
     968                 :      23059 : xlate_ofproto_set(struct ofproto_dpif *ofproto, const char *name,
     969                 :            :                   struct dpif *dpif,
     970                 :            :                   const struct mac_learning *ml, struct stp *stp,
     971                 :            :                   struct rstp *rstp, const struct mcast_snooping *ms,
     972                 :            :                   const struct mbridge *mbridge,
     973                 :            :                   const struct dpif_sflow *sflow,
     974                 :            :                   const struct dpif_ipfix *ipfix,
     975                 :            :                   const struct netflow *netflow,
     976                 :            :                   bool forward_bpdu, bool has_in_band,
     977                 :            :                   const struct dpif_backer_support *support)
     978                 :            : {
     979                 :            :     struct xbridge *xbridge;
     980                 :            : 
     981         [ -  + ]:      23059 :     ovs_assert(new_xcfg);
     982                 :            : 
     983                 :      23059 :     xbridge = xbridge_lookup(new_xcfg, ofproto);
     984         [ +  + ]:      23059 :     if (!xbridge) {
     985                 :        749 :         xbridge = xzalloc(sizeof *xbridge);
     986                 :        749 :         xbridge->ofproto = ofproto;
     987                 :            : 
     988                 :        749 :         xlate_xbridge_init(new_xcfg, xbridge);
     989                 :            :     }
     990                 :            : 
     991                 :      23059 :     free(xbridge->name);
     992                 :      23059 :     xbridge->name = xstrdup(name);
     993                 :            : 
     994                 :      23059 :     xlate_xbridge_set(xbridge, dpif, ml, stp, rstp, ms, mbridge, sflow, ipfix,
     995                 :            :                       netflow, forward_bpdu, has_in_band, support);
     996                 :      23059 : }
     997                 :            : 
     998                 :            : static void
     999                 :      41774 : xlate_xbridge_remove(struct xlate_cfg *xcfg, struct xbridge *xbridge)
    1000                 :            : {
    1001                 :            :     struct xbundle *xbundle, *next_xbundle;
    1002                 :            :     struct xport *xport, *next_xport;
    1003                 :            : 
    1004         [ -  + ]:      41774 :     if (!xbridge) {
    1005                 :          0 :         return;
    1006                 :            :     }
    1007                 :            : 
    1008 [ +  + ][ -  + ]:     285582 :     HMAP_FOR_EACH_SAFE (xport, next_xport, ofp_node, &xbridge->xports) {
                 [ +  + ]
    1009                 :     243808 :         xlate_xport_remove(xcfg, xport);
    1010                 :            :     }
    1011                 :            : 
    1012 [ +  + ][ +  + ]:     232830 :     LIST_FOR_EACH_SAFE (xbundle, next_xbundle, list_node, &xbridge->xbundles) {
    1013                 :     191056 :         xlate_xbundle_remove(xcfg, xbundle);
    1014                 :            :     }
    1015                 :            : 
    1016                 :      41774 :     hmap_remove(&xcfg->xbridges, &xbridge->hmap_node);
    1017                 :      41774 :     mac_learning_unref(xbridge->ml);
    1018                 :      41774 :     mcast_snooping_unref(xbridge->ms);
    1019                 :      41774 :     mbridge_unref(xbridge->mbridge);
    1020                 :      41774 :     dpif_sflow_unref(xbridge->sflow);
    1021                 :      41774 :     dpif_ipfix_unref(xbridge->ipfix);
    1022                 :      41774 :     stp_unref(xbridge->stp);
    1023                 :      41774 :     rstp_unref(xbridge->rstp);
    1024                 :      41774 :     hmap_destroy(&xbridge->xports);
    1025                 :      41774 :     free(xbridge->name);
    1026                 :      41774 :     free(xbridge);
    1027                 :            : }
    1028                 :            : 
    1029                 :            : void
    1030                 :        749 : xlate_remove_ofproto(struct ofproto_dpif *ofproto)
    1031                 :            : {
    1032                 :            :     struct xbridge *xbridge;
    1033                 :            : 
    1034         [ -  + ]:        749 :     ovs_assert(new_xcfg);
    1035                 :            : 
    1036                 :        749 :     xbridge = xbridge_lookup(new_xcfg, ofproto);
    1037                 :        749 :     xlate_xbridge_remove(new_xcfg, xbridge);
    1038                 :        749 : }
    1039                 :            : 
    1040                 :            : void
    1041                 :      99662 : xlate_bundle_set(struct ofproto_dpif *ofproto, struct ofbundle *ofbundle,
    1042                 :            :                  const char *name, enum port_vlan_mode vlan_mode, int vlan,
    1043                 :            :                  unsigned long *trunks, bool use_priority_tags,
    1044                 :            :                  const struct bond *bond, const struct lacp *lacp,
    1045                 :            :                  bool floodable)
    1046                 :            : {
    1047                 :            :     struct xbundle *xbundle;
    1048                 :            : 
    1049         [ -  + ]:      99662 :     ovs_assert(new_xcfg);
    1050                 :            : 
    1051                 :      99662 :     xbundle = xbundle_lookup(new_xcfg, ofbundle);
    1052         [ +  + ]:      99662 :     if (!xbundle) {
    1053                 :       2667 :         xbundle = xzalloc(sizeof *xbundle);
    1054                 :       2667 :         xbundle->ofbundle = ofbundle;
    1055                 :       2667 :         xbundle->xbridge = xbridge_lookup(new_xcfg, ofproto);
    1056                 :            : 
    1057                 :       2667 :         xlate_xbundle_init(new_xcfg, xbundle);
    1058                 :            :     }
    1059                 :            : 
    1060                 :      99662 :     free(xbundle->name);
    1061                 :      99662 :     xbundle->name = xstrdup(name);
    1062                 :            : 
    1063                 :      99662 :     xlate_xbundle_set(xbundle, vlan_mode, vlan, trunks,
    1064                 :            :                       use_priority_tags, bond, lacp, floodable);
    1065                 :      99662 : }
    1066                 :            : 
    1067                 :            : static void
    1068                 :     193723 : xlate_xbundle_remove(struct xlate_cfg *xcfg, struct xbundle *xbundle)
    1069                 :            : {
    1070                 :            :     struct xport *xport;
    1071                 :            : 
    1072         [ -  + ]:     193723 :     if (!xbundle) {
    1073                 :          0 :         return;
    1074                 :            :     }
    1075                 :            : 
    1076         [ +  + ]:     196411 :     LIST_FOR_EACH_POP (xport, bundle_node, &xbundle->xports) {
    1077                 :       2688 :         xport->xbundle = NULL;
    1078                 :            :     }
    1079                 :            : 
    1080                 :     193723 :     hmap_remove(&xcfg->xbundles, &xbundle->hmap_node);
    1081                 :     193723 :     ovs_list_remove(&xbundle->list_node);
    1082                 :     193723 :     bond_unref(xbundle->bond);
    1083                 :     193723 :     lacp_unref(xbundle->lacp);
    1084                 :     193723 :     free(xbundle->name);
    1085                 :     193723 :     free(xbundle);
    1086                 :            : }
    1087                 :            : 
    1088                 :            : void
    1089                 :       2667 : xlate_bundle_remove(struct ofbundle *ofbundle)
    1090                 :            : {
    1091                 :            :     struct xbundle *xbundle;
    1092                 :            : 
    1093         [ -  + ]:       2667 :     ovs_assert(new_xcfg);
    1094                 :            : 
    1095                 :       2667 :     xbundle = xbundle_lookup(new_xcfg, ofbundle);
    1096                 :       2667 :     xlate_xbundle_remove(new_xcfg, xbundle);
    1097                 :       2667 : }
    1098                 :            : 
    1099                 :            : void
    1100                 :     100309 : xlate_ofport_set(struct ofproto_dpif *ofproto, struct ofbundle *ofbundle,
    1101                 :            :                  struct ofport_dpif *ofport, ofp_port_t ofp_port,
    1102                 :            :                  odp_port_t odp_port, const struct netdev *netdev,
    1103                 :            :                  const struct cfm *cfm, const struct bfd *bfd,
    1104                 :            :                  const struct lldp *lldp, struct ofport_dpif *peer,
    1105                 :            :                  int stp_port_no, const struct rstp_port *rstp_port,
    1106                 :            :                  const struct ofproto_port_queue *qdscp_list, size_t n_qdscp,
    1107                 :            :                  enum ofputil_port_config config,
    1108                 :            :                  enum ofputil_port_state state, bool is_tunnel,
    1109                 :            :                  bool may_enable)
    1110                 :            : {
    1111                 :            :     size_t i;
    1112                 :            :     struct xport *xport;
    1113                 :            : 
    1114         [ -  + ]:     100309 :     ovs_assert(new_xcfg);
    1115                 :            : 
    1116                 :     100309 :     xport = xport_lookup(new_xcfg, ofport);
    1117         [ +  + ]:     100309 :     if (!xport) {
    1118                 :       2689 :         xport = xzalloc(sizeof *xport);
    1119                 :       2689 :         xport->ofport = ofport;
    1120                 :       2689 :         xport->xbridge = xbridge_lookup(new_xcfg, ofproto);
    1121                 :       2689 :         xport->ofp_port = ofp_port;
    1122                 :            : 
    1123                 :       2689 :         xlate_xport_init(new_xcfg, xport);
    1124                 :            :     }
    1125                 :            : 
    1126         [ -  + ]:     100309 :     ovs_assert(xport->ofp_port == ofp_port);
    1127                 :            : 
    1128                 :     100309 :     xlate_xport_set(xport, odp_port, netdev, cfm, bfd, lldp,
    1129                 :            :                     stp_port_no, rstp_port, config, state, is_tunnel,
    1130                 :            :                     may_enable);
    1131                 :            : 
    1132         [ +  + ]:     100309 :     if (xport->peer) {
    1133                 :      27008 :         xport->peer->peer = NULL;
    1134                 :            :     }
    1135                 :     100309 :     xport->peer = xport_lookup(new_xcfg, peer);
    1136         [ +  + ]:     100309 :     if (xport->peer) {
    1137                 :      27166 :         xport->peer->peer = xport;
    1138                 :            :     }
    1139                 :            : 
    1140         [ +  + ]:     100309 :     if (xport->xbundle) {
    1141                 :      97540 :         ovs_list_remove(&xport->bundle_node);
    1142                 :            :     }
    1143                 :     100309 :     xport->xbundle = xbundle_lookup(new_xcfg, ofbundle);
    1144         [ +  + ]:     100309 :     if (xport->xbundle) {
    1145                 :     100229 :         ovs_list_insert(&xport->xbundle->xports, &xport->bundle_node);
    1146                 :            :     }
    1147                 :            : 
    1148                 :     100309 :     clear_skb_priorities(xport);
    1149         [ +  + ]:     100311 :     for (i = 0; i < n_qdscp; i++) {
    1150                 :            :         struct skb_priority_to_dscp *pdscp;
    1151                 :            :         uint32_t skb_priority;
    1152                 :            : 
    1153         [ -  + ]:          2 :         if (dpif_queue_to_priority(xport->xbridge->dpif, qdscp_list[i].queue,
    1154                 :            :                                    &skb_priority)) {
    1155                 :          0 :             continue;
    1156                 :            :         }
    1157                 :            : 
    1158                 :          2 :         pdscp = xmalloc(sizeof *pdscp);
    1159                 :          2 :         pdscp->skb_priority = skb_priority;
    1160                 :          2 :         pdscp->dscp = (qdscp_list[i].dscp << 2) & IP_DSCP_MASK;
    1161                 :          2 :         hmap_insert(&xport->skb_priorities, &pdscp->hmap_node,
    1162                 :            :                     hash_int(pdscp->skb_priority, 0));
    1163                 :            :     }
    1164                 :     100309 : }
    1165                 :            : 
    1166                 :            : static void
    1167                 :     246497 : xlate_xport_remove(struct xlate_cfg *xcfg, struct xport *xport)
    1168                 :            : {
    1169         [ -  + ]:     246497 :     if (!xport) {
    1170                 :          0 :         return;
    1171                 :            :     }
    1172                 :            : 
    1173         [ +  + ]:     246497 :     if (xport->peer) {
    1174                 :      30775 :         xport->peer->peer = NULL;
    1175                 :      30775 :         xport->peer = NULL;
    1176                 :            :     }
    1177                 :            : 
    1178         [ +  + ]:     246497 :     if (xport->xbundle) {
    1179                 :     192243 :         ovs_list_remove(&xport->bundle_node);
    1180                 :            :     }
    1181                 :            : 
    1182                 :     246497 :     clear_skb_priorities(xport);
    1183                 :     246497 :     hmap_destroy(&xport->skb_priorities);
    1184                 :            : 
    1185                 :     246497 :     hmap_remove(&xcfg->xports, &xport->hmap_node);
    1186                 :     246497 :     hmap_remove(&xport->xbridge->xports, &xport->ofp_node);
    1187                 :            : 
    1188                 :     246497 :     netdev_close(xport->netdev);
    1189                 :     246497 :     rstp_port_unref(xport->rstp_port);
    1190                 :     246497 :     cfm_unref(xport->cfm);
    1191                 :     246497 :     bfd_unref(xport->bfd);
    1192                 :     246497 :     lldp_unref(xport->lldp);
    1193                 :     246497 :     free(xport);
    1194                 :            : }
    1195                 :            : 
    1196                 :            : void
    1197                 :       2689 : xlate_ofport_remove(struct ofport_dpif *ofport)
    1198                 :            : {
    1199                 :            :     struct xport *xport;
    1200                 :            : 
    1201         [ -  + ]:       2689 :     ovs_assert(new_xcfg);
    1202                 :            : 
    1203                 :       2689 :     xport = xport_lookup(new_xcfg, ofport);
    1204                 :       2689 :     xlate_xport_remove(new_xcfg, xport);
    1205                 :       2689 : }
    1206                 :            : 
    1207                 :            : static struct ofproto_dpif *
    1208                 :      78704 : xlate_lookup_ofproto_(const struct dpif_backer *backer, const struct flow *flow,
    1209                 :            :                       ofp_port_t *ofp_in_port, const struct xport **xportp)
    1210                 :            : {
    1211                 :      78704 :     struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
    1212                 :            :     const struct xport *xport;
    1213                 :            : 
    1214         [ +  + ]:      78704 :     xport = xport_lookup(xcfg, tnl_port_should_receive(flow)
    1215                 :            :                          ? tnl_port_receive(flow)
    1216                 :      69380 :                          : odp_port_to_ofport(backer, flow->in_port.odp_port));
    1217         [ +  + ]:      78704 :     if (OVS_UNLIKELY(!xport)) {
    1218                 :        780 :         return NULL;
    1219                 :            :     }
    1220                 :      77924 :     *xportp = xport;
    1221         [ +  + ]:      77924 :     if (ofp_in_port) {
    1222                 :      75866 :         *ofp_in_port = xport->ofp_port;
    1223                 :            :     }
    1224                 :      77924 :     return xport->xbridge->ofproto;
    1225                 :            : }
    1226                 :            : 
    1227                 :            : /* Given a datapath and flow metadata ('backer', and 'flow' respectively)
    1228                 :            :  * returns the corresponding struct ofproto_dpif and OpenFlow port number. */
    1229                 :            : struct ofproto_dpif *
    1230                 :       2378 : xlate_lookup_ofproto(const struct dpif_backer *backer, const struct flow *flow,
    1231                 :            :                      ofp_port_t *ofp_in_port)
    1232                 :            : {
    1233                 :            :     const struct xport *xport;
    1234                 :            : 
    1235                 :       2378 :     return xlate_lookup_ofproto_(backer, flow, ofp_in_port, &xport);
    1236                 :            : }
    1237                 :            : 
    1238                 :            : /* Given a datapath and flow metadata ('backer', and 'flow' respectively),
    1239                 :            :  * optionally populates 'ofproto' with the ofproto_dpif, 'ofp_in_port' with the
    1240                 :            :  * openflow in_port, and 'ipfix', 'sflow', and 'netflow' with the appropriate
    1241                 :            :  * handles for those protocols if they're enabled.  Caller may use the returned
    1242                 :            :  * pointers until quiescing, for longer term use additional references must
    1243                 :            :  * be taken.
    1244                 :            :  *
    1245                 :            :  * Returns 0 if successful, ENODEV if the parsed flow has no associated ofproto.
    1246                 :            :  */
    1247                 :            : int
    1248                 :      76326 : xlate_lookup(const struct dpif_backer *backer, const struct flow *flow,
    1249                 :            :              struct ofproto_dpif **ofprotop, struct dpif_ipfix **ipfix,
    1250                 :            :              struct dpif_sflow **sflow, struct netflow **netflow,
    1251                 :            :              ofp_port_t *ofp_in_port)
    1252                 :            : {
    1253                 :            :     struct ofproto_dpif *ofproto;
    1254                 :            :     const struct xport *xport;
    1255                 :            : 
    1256                 :      76326 :     ofproto = xlate_lookup_ofproto_(backer, flow, ofp_in_port, &xport);
    1257                 :            : 
    1258         [ +  + ]:      76326 :     if (!ofproto) {
    1259                 :        778 :         return ENODEV;
    1260                 :            :     }
    1261                 :            : 
    1262         [ +  - ]:      75548 :     if (ofprotop) {
    1263                 :      75548 :         *ofprotop = ofproto;
    1264                 :            :     }
    1265                 :            : 
    1266         [ +  + ]:      75548 :     if (ipfix) {
    1267         [ +  - ]:       6943 :         *ipfix = xport ? xport->xbridge->ipfix : NULL;
    1268                 :            :     }
    1269                 :            : 
    1270         [ +  + ]:      75548 :     if (sflow) {
    1271         [ +  - ]:       6943 :         *sflow = xport ? xport->xbridge->sflow : NULL;
    1272                 :            :     }
    1273                 :            : 
    1274         [ +  + ]:      75548 :     if (netflow) {
    1275         [ +  - ]:      68605 :         *netflow = xport ? xport->xbridge->netflow : NULL;
    1276                 :            :     }
    1277                 :            : 
    1278                 :      76326 :     return 0;
    1279                 :            : }
    1280                 :            : 
    1281                 :            : static struct xbridge *
    1282                 :     116178 : xbridge_lookup(struct xlate_cfg *xcfg, const struct ofproto_dpif *ofproto)
    1283                 :            : {
    1284                 :            :     struct hmap *xbridges;
    1285                 :            :     struct xbridge *xbridge;
    1286                 :            : 
    1287 [ +  - ][ -  + ]:     116178 :     if (!ofproto || !xcfg) {
    1288                 :          0 :         return NULL;
    1289                 :            :     }
    1290                 :            : 
    1291                 :     116178 :     xbridges = &xcfg->xbridges;
    1292                 :            : 
    1293 [ +  + ][ -  + ]:     144680 :     HMAP_FOR_EACH_IN_BUCKET (xbridge, hmap_node, hash_pointer(ofproto, 0),
    1294                 :            :                              xbridges) {
    1295         [ +  + ]:     143931 :         if (xbridge->ofproto == ofproto) {
    1296                 :     115429 :             return xbridge;
    1297                 :            :         }
    1298                 :            :     }
    1299                 :        749 :     return NULL;
    1300                 :            : }
    1301                 :            : 
    1302                 :            : static struct xbridge *
    1303                 :         19 : xbridge_lookup_by_uuid(struct xlate_cfg *xcfg, const struct uuid *uuid)
    1304                 :            : {
    1305                 :            :     struct xbridge *xbridge;
    1306                 :            : 
    1307 [ +  - ][ #  # ]:         33 :     HMAP_FOR_EACH (xbridge, hmap_node, &xcfg->xbridges) {
    1308         [ +  + ]:         33 :         if (uuid_equals(ofproto_dpif_get_uuid(xbridge->ofproto), uuid)) {
    1309                 :         19 :             return xbridge;
    1310                 :            :         }
    1311                 :            :     }
    1312                 :          0 :     return NULL;
    1313                 :            : }
    1314                 :            : 
    1315                 :            : static struct xbundle *
    1316                 :     205637 : xbundle_lookup(struct xlate_cfg *xcfg, const struct ofbundle *ofbundle)
    1317                 :            : {
    1318                 :            :     struct hmap *xbundles;
    1319                 :            :     struct xbundle *xbundle;
    1320                 :            : 
    1321 [ +  + ][ -  + ]:     205637 :     if (!ofbundle || !xcfg) {
    1322                 :         80 :         return NULL;
    1323                 :            :     }
    1324                 :            : 
    1325                 :     205557 :     xbundles = &xcfg->xbundles;
    1326                 :            : 
    1327 [ +  + ][ -  + ]:     314189 :     HMAP_FOR_EACH_IN_BUCKET (xbundle, hmap_node, hash_pointer(ofbundle, 0),
    1328                 :            :                              xbundles) {
    1329         [ +  + ]:     311522 :         if (xbundle->ofbundle == ofbundle) {
    1330                 :     202890 :             return xbundle;
    1331                 :            :         }
    1332                 :            :     }
    1333                 :       2667 :     return NULL;
    1334                 :            : }
    1335                 :            : 
    1336                 :            : static struct xport *
    1337                 :     356199 : xport_lookup(struct xlate_cfg *xcfg, const struct ofport_dpif *ofport)
    1338                 :            : {
    1339                 :            :     struct hmap *xports;
    1340                 :            :     struct xport *xport;
    1341                 :            : 
    1342 [ +  + ][ +  + ]:     356199 :     if (!ofport || !xcfg) {
    1343                 :      73811 :         return NULL;
    1344                 :            :     }
    1345                 :            : 
    1346                 :     282388 :     xports = &xcfg->xports;
    1347                 :            : 
    1348 [ +  + ][ -  + ]:     453087 :     HMAP_FOR_EACH_IN_BUCKET (xport, hmap_node, hash_pointer(ofport, 0),
    1349                 :            :                              xports) {
    1350         [ +  + ]:     419597 :         if (xport->ofport == ofport) {
    1351                 :     248898 :             return xport;
    1352                 :            :         }
    1353                 :            :     }
    1354                 :      33489 :     return NULL;
    1355                 :            : }
    1356                 :            : 
    1357                 :            : static struct stp_port *
    1358                 :     343283 : xport_get_stp_port(const struct xport *xport)
    1359                 :            : {
    1360         [ +  + ]:     343321 :     return xport->xbridge->stp && xport->stp_port_no != -1
    1361                 :         30 :         ? stp_get_port(xport->xbridge->stp, xport->stp_port_no)
    1362         [ +  + ]:     343321 :         : NULL;
    1363                 :            : }
    1364                 :            : 
    1365                 :            : static bool
    1366                 :          0 : xport_stp_learn_state(const struct xport *xport)
    1367                 :            : {
    1368                 :          0 :     struct stp_port *sp = xport_get_stp_port(xport);
    1369                 :          0 :     return sp
    1370                 :          0 :         ? stp_learn_in_state(stp_port_get_state(sp))
    1371   [ #  #  #  # ]:          0 :         : true;
    1372                 :            : }
    1373                 :            : 
    1374                 :            : static bool
    1375                 :     343250 : xport_stp_forward_state(const struct xport *xport)
    1376                 :            : {
    1377                 :     343250 :     struct stp_port *sp = xport_get_stp_port(xport);
    1378                 :     343250 :     return sp
    1379                 :          4 :         ? stp_forward_in_state(stp_port_get_state(sp))
    1380   [ +  +  +  + ]:     343254 :         : true;
    1381                 :            : }
    1382                 :            : 
    1383                 :            : static bool
    1384                 :         20 : xport_stp_should_forward_bpdu(const struct xport *xport)
    1385                 :            : {
    1386                 :         20 :     struct stp_port *sp = xport_get_stp_port(xport);
    1387         [ +  + ]:         20 :     return stp_should_forward_bpdu(sp ? stp_port_get_state(sp) : STP_DISABLED);
    1388                 :            : }
    1389                 :            : 
    1390                 :            : /* Returns true if STP should process 'flow'.  Sets fields in 'wc' that
    1391                 :            :  * were used to make the determination.*/
    1392                 :            : static bool
    1393                 :         34 : stp_should_process_flow(const struct flow *flow, struct flow_wildcards *wc)
    1394                 :            : {
    1395                 :            :     /* is_stp() also checks dl_type, but dl_type is always set in 'wc'. */
    1396                 :         34 :     memset(&wc->masks.dl_dst, 0xff, sizeof wc->masks.dl_dst);
    1397                 :         34 :     return is_stp(flow);
    1398                 :            : }
    1399                 :            : 
    1400                 :            : static void
    1401                 :         13 : stp_process_packet(const struct xport *xport, const struct dp_packet *packet)
    1402                 :            : {
    1403                 :         13 :     struct stp_port *sp = xport_get_stp_port(xport);
    1404                 :         13 :     struct dp_packet payload = *packet;
    1405                 :         13 :     struct eth_header *eth = dp_packet_data(&payload);
    1406                 :            : 
    1407                 :            :     /* Sink packets on ports that have STP disabled when the bridge has
    1408                 :            :      * STP enabled. */
    1409 [ +  - ][ -  + ]:         13 :     if (!sp || stp_port_get_state(sp) == STP_DISABLED) {
    1410                 :          0 :         return;
    1411                 :            :     }
    1412                 :            : 
    1413                 :            :     /* Trim off padding on payload. */
    1414         [ -  + ]:         13 :     if (dp_packet_size(&payload) > ntohs(eth->eth_type) + ETH_HEADER_LEN) {
    1415                 :          0 :         dp_packet_set_size(&payload, ntohs(eth->eth_type) + ETH_HEADER_LEN);
    1416                 :            :     }
    1417                 :            : 
    1418         [ +  - ]:         13 :     if (dp_packet_try_pull(&payload, ETH_HEADER_LEN + LLC_HEADER_LEN)) {
    1419                 :         13 :         stp_received_bpdu(sp, dp_packet_data(&payload), dp_packet_size(&payload));
    1420                 :            :     }
    1421                 :            : }
    1422                 :            : 
    1423                 :            : static enum rstp_state
    1424                 :          4 : xport_get_rstp_port_state(const struct xport *xport)
    1425                 :            : {
    1426         [ +  - ]:          4 :     return xport->rstp_port
    1427                 :          4 :         ? rstp_port_get_state(xport->rstp_port)
    1428                 :            :         : RSTP_DISABLED;
    1429                 :            : }
    1430                 :            : 
    1431                 :            : static bool
    1432                 :          0 : xport_rstp_learn_state(const struct xport *xport)
    1433                 :            : {
    1434 [ #  # ][ #  # ]:          0 :     return xport->xbridge->rstp && xport->rstp_port
    1435                 :          0 :         ? rstp_learn_in_state(xport_get_rstp_port_state(xport))
    1436   [ #  #  #  # ]:          0 :         : true;
    1437                 :            : }
    1438                 :            : 
    1439                 :            : static bool
    1440                 :     343248 : xport_rstp_forward_state(const struct xport *xport)
    1441                 :            : {
    1442 [ +  + ][ +  + ]:     686496 :     return xport->xbridge->rstp && xport->rstp_port
    1443                 :          4 :         ? rstp_forward_in_state(xport_get_rstp_port_state(xport))
    1444   [ +  +  +  + ]:     343252 :         : true;
    1445                 :            : }
    1446                 :            : 
    1447                 :            : static bool
    1448                 :          0 : xport_rstp_should_manage_bpdu(const struct xport *xport)
    1449                 :            : {
    1450                 :          0 :     return rstp_should_manage_bpdu(xport_get_rstp_port_state(xport));
    1451                 :            : }
    1452                 :            : 
    1453                 :            : static void
    1454                 :          6 : rstp_process_packet(const struct xport *xport, const struct dp_packet *packet)
    1455                 :            : {
    1456                 :          6 :     struct dp_packet payload = *packet;
    1457                 :          6 :     struct eth_header *eth = dp_packet_data(&payload);
    1458                 :            : 
    1459                 :            :     /* Sink packets on ports that have no RSTP. */
    1460         [ -  + ]:          6 :     if (!xport->rstp_port) {
    1461                 :          0 :         return;
    1462                 :            :     }
    1463                 :            : 
    1464                 :            :     /* Trim off padding on payload. */
    1465         [ -  + ]:          6 :     if (dp_packet_size(&payload) > ntohs(eth->eth_type) + ETH_HEADER_LEN) {
    1466                 :          0 :         dp_packet_set_size(&payload, ntohs(eth->eth_type) + ETH_HEADER_LEN);
    1467                 :            :     }
    1468                 :            : 
    1469         [ +  - ]:          6 :     if (dp_packet_try_pull(&payload, ETH_HEADER_LEN + LLC_HEADER_LEN)) {
    1470                 :          6 :         rstp_port_received_bpdu(xport->rstp_port, dp_packet_data(&payload),
    1471                 :          6 :                                 dp_packet_size(&payload));
    1472                 :            :     }
    1473                 :            : }
    1474                 :            : 
    1475                 :            : static struct xport *
    1476                 :     242127 : get_ofp_port(const struct xbridge *xbridge, ofp_port_t ofp_port)
    1477                 :            : {
    1478                 :            :     struct xport *xport;
    1479                 :            : 
    1480 [ +  + ][ -  + ]:     395705 :     HMAP_FOR_EACH_IN_BUCKET (xport, ofp_node, hash_ofp_port(ofp_port),
    1481                 :            :                              &xbridge->xports) {
    1482         [ +  + ]:     387467 :         if (xport->ofp_port == ofp_port) {
    1483                 :     233889 :             return xport;
    1484                 :            :         }
    1485                 :            :     }
    1486                 :       8236 :     return NULL;
    1487                 :            : }
    1488                 :            : 
    1489                 :            : static odp_port_t
    1490                 :         34 : ofp_port_to_odp_port(const struct xbridge *xbridge, ofp_port_t ofp_port)
    1491                 :            : {
    1492                 :         34 :     const struct xport *xport = get_ofp_port(xbridge, ofp_port);
    1493         [ +  - ]:         34 :     return xport ? xport->odp_port : ODPP_NONE;
    1494                 :            : }
    1495                 :            : 
    1496                 :            : static bool
    1497                 :          0 : odp_port_is_alive(const struct xlate_ctx *ctx, ofp_port_t ofp_port)
    1498                 :            : {
    1499                 :          0 :     struct xport *xport = get_ofp_port(ctx->xbridge, ofp_port);
    1500 [ #  # ][ #  # ]:          0 :     return xport && xport->may_enable;
    1501                 :            : }
    1502                 :            : 
    1503                 :            : static struct ofputil_bucket *
    1504                 :            : group_first_live_bucket(const struct xlate_ctx *, const struct group_dpif *,
    1505                 :            :                         int depth);
    1506                 :            : 
    1507                 :            : static bool
    1508                 :          0 : group_is_alive(const struct xlate_ctx *ctx, uint32_t group_id, int depth)
    1509                 :            : {
    1510                 :            :     struct group_dpif *group;
    1511                 :            : 
    1512                 :          0 :     group = group_dpif_lookup(ctx->xbridge->ofproto, group_id,
    1513                 :            :                               ctx->tables_version, false);
    1514         [ #  # ]:          0 :     if (group) {
    1515                 :          0 :         return group_first_live_bucket(ctx, group, depth) != NULL;
    1516                 :            :     }
    1517                 :            : 
    1518                 :          0 :     return false;
    1519                 :            : }
    1520                 :            : 
    1521                 :            : #define MAX_LIVENESS_RECURSION 128 /* Arbitrary limit */
    1522                 :            : 
    1523                 :            : static bool
    1524                 :        666 : bucket_is_alive(const struct xlate_ctx *ctx,
    1525                 :            :                 struct ofputil_bucket *bucket, int depth)
    1526                 :            : {
    1527         [ -  + ]:        666 :     if (depth >= MAX_LIVENESS_RECURSION) {
    1528                 :            :         static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
    1529                 :            : 
    1530         [ #  # ]:          0 :         VLOG_WARN_RL(&rl, "bucket chaining exceeded %d links",
    1531                 :            :                      MAX_LIVENESS_RECURSION);
    1532                 :          0 :         return false;
    1533                 :            :     }
    1534                 :            : 
    1535                 :       1332 :     return (!ofputil_bucket_has_liveness(bucket)
    1536         [ #  # ]:          0 :             || (bucket->watch_port != OFPP_ANY
    1537         [ #  # ]:          0 :                && odp_port_is_alive(ctx, bucket->watch_port))
    1538 [ -  + ][ #  # ]:        666 :             || (bucket->watch_group != OFPG_ANY
    1539         [ #  # ]:          0 :                && group_is_alive(ctx, bucket->watch_group, depth + 1)));
    1540                 :            : }
    1541                 :            : 
    1542                 :            : static struct ofputil_bucket *
    1543                 :          0 : group_first_live_bucket(const struct xlate_ctx *ctx,
    1544                 :            :                         const struct group_dpif *group, int depth)
    1545                 :            : {
    1546                 :            :     struct ofputil_bucket *bucket;
    1547                 :            :     const struct ovs_list *buckets;
    1548                 :            : 
    1549                 :          0 :     buckets = group_dpif_get_buckets(group);
    1550         [ #  # ]:          0 :     LIST_FOR_EACH (bucket, list_node, buckets) {
    1551         [ #  # ]:          0 :         if (bucket_is_alive(ctx, bucket, depth)) {
    1552                 :          0 :             return bucket;
    1553                 :            :         }
    1554                 :            :     }
    1555                 :            : 
    1556                 :          0 :     return NULL;
    1557                 :            : }
    1558                 :            : 
    1559                 :            : static struct ofputil_bucket *
    1560                 :        250 : group_best_live_bucket(const struct xlate_ctx *ctx,
    1561                 :            :                        const struct group_dpif *group,
    1562                 :            :                        uint32_t basis)
    1563                 :            : {
    1564                 :        250 :     struct ofputil_bucket *best_bucket = NULL;
    1565                 :        250 :     uint32_t best_score = 0;
    1566                 :            : 
    1567                 :            :     struct ofputil_bucket *bucket;
    1568                 :            :     const struct ovs_list *buckets;
    1569                 :            : 
    1570                 :        250 :     buckets = group_dpif_get_buckets(group);
    1571         [ +  + ]:        916 :     LIST_FOR_EACH (bucket, list_node, buckets) {
    1572         [ +  - ]:        666 :         if (bucket_is_alive(ctx, bucket, 0)) {
    1573                 :        666 :             uint32_t score =
    1574                 :        666 :                 (hash_int(bucket->bucket_id, basis) & 0xffff) * bucket->weight;
    1575         [ +  + ]:        666 :             if (score >= best_score) {
    1576                 :        425 :                 best_bucket = bucket;
    1577                 :        425 :                 best_score = score;
    1578                 :            :             }
    1579                 :            :         }
    1580                 :            :     }
    1581                 :            : 
    1582                 :        250 :     return best_bucket;
    1583                 :            : }
    1584                 :            : 
    1585                 :            : static bool
    1586                 :      72846 : xbundle_trunks_vlan(const struct xbundle *bundle, uint16_t vlan)
    1587                 :            : {
    1588                 :      72846 :     return (bundle->vlan_mode != PORT_VLAN_ACCESS
    1589 [ +  + ][ +  + ]:      72846 :             && (!bundle->trunks || bitmap_is_set(bundle->trunks, vlan)));
                 [ +  + ]
    1590                 :            : }
    1591                 :            : 
    1592                 :            : static bool
    1593                 :      72990 : xbundle_includes_vlan(const struct xbundle *xbundle, uint16_t vlan)
    1594                 :            : {
    1595 [ +  + ][ +  + ]:      72990 :     return vlan == xbundle->vlan || xbundle_trunks_vlan(xbundle, vlan);
    1596                 :            : }
    1597                 :            : 
    1598                 :            : static mirror_mask_t
    1599                 :     148918 : xbundle_mirror_out(const struct xbridge *xbridge, struct xbundle *xbundle)
    1600                 :            : {
    1601                 :     148919 :     return xbundle != &ofpp_none_bundle
    1602                 :     148917 :         ? mirror_bundle_out(xbridge->mbridge, xbundle->ofbundle)
    1603         [ +  + ]:     148918 :         : 0;
    1604                 :            : }
    1605                 :            : 
    1606                 :            : static mirror_mask_t
    1607                 :         57 : xbundle_mirror_src(const struct xbridge *xbridge, struct xbundle *xbundle)
    1608                 :            : {
    1609                 :         57 :     return xbundle != &ofpp_none_bundle
    1610                 :         55 :         ? mirror_bundle_src(xbridge->mbridge, xbundle->ofbundle)
    1611         [ +  + ]:         57 :         : 0;
    1612                 :            : }
    1613                 :            : 
    1614                 :            : static mirror_mask_t
    1615                 :        101 : xbundle_mirror_dst(const struct xbridge *xbridge, struct xbundle *xbundle)
    1616                 :            : {
    1617                 :        101 :     return xbundle != &ofpp_none_bundle
    1618                 :        101 :         ? mirror_bundle_dst(xbridge->mbridge, xbundle->ofbundle)
    1619         [ +  - ]:        101 :         : 0;
    1620                 :            : }
    1621                 :            : 
    1622                 :            : static struct xbundle *
    1623                 :      32906 : lookup_input_bundle(const struct xbridge *xbridge, ofp_port_t in_port,
    1624                 :            :                     bool warn, struct xport **in_xportp)
    1625                 :            : {
    1626                 :            :     struct xport *xport;
    1627                 :            : 
    1628                 :            :     /* Find the port and bundle for the received packet. */
    1629                 :      32906 :     xport = get_ofp_port(xbridge, in_port);
    1630         [ +  + ]:      32906 :     if (in_xportp) {
    1631                 :      30464 :         *in_xportp = xport;
    1632                 :            :     }
    1633 [ +  + ][ +  + ]:      32906 :     if (xport && xport->xbundle) {
    1634                 :      32843 :         return xport->xbundle;
    1635                 :            :     }
    1636                 :            : 
    1637                 :            :     /* Special-case OFPP_NONE (OF1.0) and OFPP_CONTROLLER (OF1.1+),
    1638                 :            :      * which a controller may use as the ingress port for traffic that
    1639                 :            :      * it is sourcing. */
    1640 [ +  - ][ +  + ]:         63 :     if (in_port == OFPP_CONTROLLER || in_port == OFPP_NONE) {
    1641                 :          3 :         return &ofpp_none_bundle;
    1642                 :            :     }
    1643                 :            : 
    1644                 :            :     /* Odd.  A few possible reasons here:
    1645                 :            :      *
    1646                 :            :      * - We deleted a port but there are still a few packets queued up
    1647                 :            :      *   from it.
    1648                 :            :      *
    1649                 :            :      * - Someone externally added a port (e.g. "ovs-dpctl add-if") that
    1650                 :            :      *   we don't know about.
    1651                 :            :      *
    1652                 :            :      * - The ofproto client didn't configure the port as part of a bundle.
    1653                 :            :      *   This is particularly likely to happen if a packet was received on the
    1654                 :            :      *   port after it was created, but before the client had a chance to
    1655                 :            :      *   configure its bundle.
    1656                 :            :      */
    1657         [ -  + ]:         60 :     if (warn) {
    1658                 :            :         static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
    1659                 :            : 
    1660         [ #  # ]:          0 :         VLOG_WARN_RL(&rl, "bridge %s: received packet on unknown "
    1661                 :            :                      "port %"PRIu16, xbridge->name, in_port);
    1662                 :            :     }
    1663                 :         60 :     return NULL;
    1664                 :            : }
    1665                 :            : 
    1666                 :            : /* Mirrors the packet represented by 'ctx' to appropriate mirror destinations,
    1667                 :            :  * given the packet is ingressing or egressing on 'xbundle', which has ingress
    1668                 :            :  * or egress (as appropriate) mirrors 'mirrors'. */
    1669                 :            : static void
    1670                 :        158 : mirror_packet(struct xlate_ctx *ctx, struct xbundle *xbundle,
    1671                 :            :               mirror_mask_t mirrors)
    1672                 :            : {
    1673                 :            :     /* Figure out what VLAN the packet is in (because mirrors can select
    1674                 :            :      * packets on basis of VLAN). */
    1675                 :        158 :     bool warn = ctx->xin->packet != NULL;
    1676                 :        158 :     uint16_t vid = vlan_tci_to_vid(ctx->xin->flow.vlan_tci);
    1677         [ -  + ]:        158 :     if (!input_vid_is_valid(vid, xbundle, warn)) {
    1678                 :          0 :         return;
    1679                 :            :     }
    1680                 :        158 :     uint16_t vlan = input_vid_to_vlan(xbundle, vid);
    1681                 :            : 
    1682                 :        158 :     const struct xbridge *xbridge = ctx->xbridge;
    1683                 :            : 
    1684                 :            :     /* Don't mirror to destinations that we've already mirrored to. */
    1685                 :        158 :     mirrors &= ~ctx->mirrors;
    1686         [ +  + ]:        158 :     if (!mirrors) {
    1687                 :        112 :         return;
    1688                 :            :     }
    1689                 :            : 
    1690         [ +  + ]:         46 :     if (ctx->xin->resubmit_stats) {
    1691                 :          5 :         mirror_update_stats(xbridge->mbridge, mirrors,
    1692                 :          5 :                             ctx->xin->resubmit_stats->n_packets,
    1693                 :          5 :                             ctx->xin->resubmit_stats->n_bytes);
    1694                 :            :     }
    1695         [ +  + ]:         46 :     if (ctx->xin->xcache) {
    1696                 :            :         struct xc_entry *entry;
    1697                 :            : 
    1698                 :          5 :         entry = xlate_cache_add_entry(ctx->xin->xcache, XC_MIRROR);
    1699                 :          5 :         entry->u.mirror.mbridge = mbridge_ref(xbridge->mbridge);
    1700                 :          5 :         entry->u.mirror.mirrors = mirrors;
    1701                 :            :     }
    1702                 :            : 
    1703                 :            :     /* 'mirrors' is a bit-mask of candidates for mirroring.  Iterate as long as
    1704                 :            :      * some candidates remain.  */
    1705         [ +  + ]:         92 :     while (mirrors) {
    1706                 :            :         const unsigned long *vlans;
    1707                 :            :         mirror_mask_t dup_mirrors;
    1708                 :            :         struct ofbundle *out;
    1709                 :            :         int out_vlan;
    1710                 :            :         int snaplen;
    1711                 :            : 
    1712                 :            :         /* Get the details of the mirror represented by the rightmost 1-bit. */
    1713                 :         46 :         bool has_mirror = mirror_get(xbridge->mbridge, raw_ctz(mirrors),
    1714                 :            :                                      &vlans, &dup_mirrors,
    1715                 :            :                                      &out, &snaplen, &out_vlan);
    1716         [ -  + ]:         46 :         ovs_assert(has_mirror);
    1717                 :            : 
    1718                 :            : 
    1719                 :            :         /* If this mirror selects on the basis of VLAN, and it does not select
    1720                 :            :          * 'vlan', then discard this mirror and go on to the next one. */
    1721         [ +  + ]:         46 :         if (vlans) {
    1722                 :         13 :             ctx->wc->masks.vlan_tci |= htons(VLAN_CFI | VLAN_VID_MASK);
    1723                 :            :         }
    1724 [ +  + ][ +  + ]:         46 :         if (vlans && !bitmap_is_set(vlans, vlan)) {
    1725                 :         10 :             mirrors = zero_rightmost_1bit(mirrors);
    1726                 :         10 :             continue;
    1727                 :            :         }
    1728                 :            : 
    1729                 :            :         /* Record the mirror, and the mirrors that output to the same
    1730                 :            :          * destination, so that we don't mirror to them again.  This must be
    1731                 :            :          * done now to ensure that output_normal(), below, doesn't recursively
    1732                 :            :          * output to the same mirrors. */
    1733                 :         36 :         ctx->mirrors |= dup_mirrors;
    1734                 :         36 :         ctx->mirror_snaplen = snaplen;
    1735                 :            : 
    1736                 :            :         /* Send the packet to the mirror. */
    1737         [ +  + ]:         36 :         if (out) {
    1738                 :         28 :             struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
    1739                 :         28 :             struct xbundle *out_xbundle = xbundle_lookup(xcfg, out);
    1740         [ +  - ]:         28 :             if (out_xbundle) {
    1741                 :         28 :                 output_normal(ctx, out_xbundle, vlan);
    1742                 :            :             }
    1743         [ +  - ]:          8 :         } else if (vlan != out_vlan
    1744         [ +  - ]:          8 :                    && !eth_addr_is_reserved(ctx->xin->flow.dl_dst)) {
    1745                 :            :             struct xbundle *xbundle;
    1746                 :            : 
    1747         [ +  + ]:         36 :             LIST_FOR_EACH (xbundle, list_node, &xbridge->xbundles) {
    1748         [ +  + ]:         28 :                 if (xbundle_includes_vlan(xbundle, out_vlan)
    1749         [ +  - ]:         16 :                     && !xbundle_mirror_out(xbridge, xbundle)) {
    1750                 :         16 :                     output_normal(ctx, xbundle, out_vlan);
    1751                 :            :                 }
    1752                 :            :             }
    1753                 :            :         }
    1754                 :            : 
    1755                 :            :         /* output_normal() could have recursively output (to different
    1756                 :            :          * mirrors), so make sure that we don't send duplicates. */
    1757                 :         36 :         mirrors &= ~ctx->mirrors;
    1758                 :         36 :         ctx->mirror_snaplen = 0;
    1759                 :            :     }
    1760                 :            : }
    1761                 :            : 
    1762                 :            : static void
    1763                 :      84526 : mirror_ingress_packet(struct xlate_ctx *ctx)
    1764                 :            : {
    1765         [ +  + ]:      84526 :     if (mbridge_has_mirrors(ctx->xbridge->mbridge)) {
    1766                 :         57 :         bool warn = ctx->xin->packet != NULL;
    1767                 :         57 :         struct xbundle *xbundle = lookup_input_bundle(
    1768                 :         57 :             ctx->xbridge, ctx->xin->flow.in_port.ofp_port, warn, NULL);
    1769         [ +  - ]:         57 :         if (xbundle) {
    1770                 :         57 :             mirror_packet(ctx, xbundle,
    1771                 :            :                           xbundle_mirror_src(ctx->xbridge, xbundle));
    1772                 :            :         }
    1773                 :            :     }
    1774                 :      84526 : }
    1775                 :            : 
    1776                 :            : /* Given 'vid', the VID obtained from the 802.1Q header that was received as
    1777                 :            :  * part of a packet (specify 0 if there was no 802.1Q header), and 'in_xbundle',
    1778                 :            :  * the bundle on which the packet was received, returns the VLAN to which the
    1779                 :            :  * packet belongs.
    1780                 :            :  *
    1781                 :            :  * Both 'vid' and the return value are in the range 0...4095. */
    1782                 :            : static uint16_t
    1783                 :      30594 : input_vid_to_vlan(const struct xbundle *in_xbundle, uint16_t vid)
    1784                 :            : {
    1785   [ +  +  +  - ]:      30594 :     switch (in_xbundle->vlan_mode) {
    1786                 :            :     case PORT_VLAN_ACCESS:
    1787                 :         19 :         return in_xbundle->vlan;
    1788                 :            :         break;
    1789                 :            : 
    1790                 :            :     case PORT_VLAN_TRUNK:
    1791                 :      30543 :         return vid;
    1792                 :            : 
    1793                 :            :     case PORT_VLAN_NATIVE_UNTAGGED:
    1794                 :            :     case PORT_VLAN_NATIVE_TAGGED:
    1795         [ +  + ]:         32 :         return vid ? vid : in_xbundle->vlan;
    1796                 :            : 
    1797                 :            :     default:
    1798                 :          0 :         OVS_NOT_REACHED();
    1799                 :            :     }
    1800                 :            : }
    1801                 :            : 
    1802                 :            : /* Checks whether a packet with the given 'vid' may ingress on 'in_xbundle'.
    1803                 :            :  * If so, returns true.  Otherwise, returns false and, if 'warn' is true, logs
    1804                 :            :  * a warning.
    1805                 :            :  *
    1806                 :            :  * 'vid' should be the VID obtained from the 802.1Q header that was received as
    1807                 :            :  * part of a packet (specify 0 if there was no 802.1Q header), in the range
    1808                 :            :  * 0...4095. */
    1809                 :            : static bool
    1810                 :      30621 : input_vid_is_valid(uint16_t vid, struct xbundle *in_xbundle, bool warn)
    1811                 :            : {
    1812                 :            :     /* Allow any VID on the OFPP_NONE port. */
    1813         [ +  + ]:      30621 :     if (in_xbundle == &ofpp_none_bundle) {
    1814                 :          3 :         return true;
    1815                 :            :     }
    1816                 :            : 
    1817   [ +  +  +  - ]:      30618 :     switch (in_xbundle->vlan_mode) {
    1818                 :            :     case PORT_VLAN_ACCESS:
    1819         [ +  + ]:         37 :         if (vid) {
    1820         [ -  + ]:         18 :             if (warn) {
    1821                 :            :                 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
    1822         [ #  # ]:          0 :                 VLOG_WARN_RL(&rl, "dropping VLAN %"PRIu16" tagged "
    1823                 :            :                              "packet received on port %s configured as VLAN "
    1824                 :            :                              "%"PRIu16" access port", vid, in_xbundle->name,
    1825                 :            :                              in_xbundle->vlan);
    1826                 :            :             }
    1827                 :         18 :             return false;
    1828                 :            :         }
    1829                 :         19 :         return true;
    1830                 :            : 
    1831                 :            :     case PORT_VLAN_NATIVE_UNTAGGED:
    1832                 :            :     case PORT_VLAN_NATIVE_TAGGED:
    1833         [ +  + ]:         36 :         if (!vid) {
    1834                 :            :             /* Port must always carry its native VLAN. */
    1835                 :         12 :             return true;
    1836                 :            :         }
    1837                 :            :         /* Fall through. */
    1838                 :            :     case PORT_VLAN_TRUNK:
    1839         [ +  + ]:      30569 :         if (!xbundle_includes_vlan(in_xbundle, vid)) {
    1840         [ -  + ]:          9 :             if (warn) {
    1841                 :            :                 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
    1842         [ #  # ]:          0 :                 VLOG_WARN_RL(&rl, "dropping VLAN %"PRIu16" packet "
    1843                 :            :                              "received on port %s not configured for trunking "
    1844                 :            :                              "VLAN %"PRIu16, vid, in_xbundle->name, vid);
    1845                 :            :             }
    1846                 :          9 :             return false;
    1847                 :            :         }
    1848                 :      30560 :         return true;
    1849                 :            : 
    1850                 :            :     default:
    1851                 :          0 :         OVS_NOT_REACHED();
    1852                 :            :     }
    1853                 :            : 
    1854                 :            : }
    1855                 :            : 
    1856                 :            : /* Given 'vlan', the VLAN that a packet belongs to, and
    1857                 :            :  * 'out_xbundle', a bundle on which the packet is to be output, returns the VID
    1858                 :            :  * that should be included in the 802.1Q header.  (If the return value is 0,
    1859                 :            :  * then the 802.1Q header should only be included in the packet if there is a
    1860                 :            :  * nonzero PCP.)
    1861                 :            :  *
    1862                 :            :  * Both 'vlan' and the return value are in the range 0...4095. */
    1863                 :            : static uint16_t
    1864                 :      45204 : output_vlan_to_vid(const struct xbundle *out_xbundle, uint16_t vlan)
    1865                 :            : {
    1866   [ +  +  +  - ]:      45204 :     switch (out_xbundle->vlan_mode) {
    1867                 :            :     case PORT_VLAN_ACCESS:
    1868                 :         66 :         return 0;
    1869                 :            : 
    1870                 :            :     case PORT_VLAN_TRUNK:
    1871                 :            :     case PORT_VLAN_NATIVE_TAGGED:
    1872                 :      45058 :         return vlan;
    1873                 :            : 
    1874                 :            :     case PORT_VLAN_NATIVE_UNTAGGED:
    1875         [ +  + ]:         80 :         return vlan == out_xbundle->vlan ? 0 : vlan;
    1876                 :            : 
    1877                 :            :     default:
    1878                 :          0 :         OVS_NOT_REACHED();
    1879                 :            :     }
    1880                 :            : }
    1881                 :            : 
    1882                 :            : static void
    1883                 :      45204 : output_normal(struct xlate_ctx *ctx, const struct xbundle *out_xbundle,
    1884                 :            :               uint16_t vlan)
    1885                 :            : {
    1886                 :      45204 :     ovs_be16 *flow_tci = &ctx->xin->flow.vlan_tci;
    1887                 :            :     uint16_t vid;
    1888                 :            :     ovs_be16 tci, old_tci;
    1889                 :            :     struct xport *xport;
    1890                 :            :     struct xlate_bond_recirc xr;
    1891                 :      45204 :     bool use_recirc = false;
    1892                 :            : 
    1893                 :      45204 :     vid = output_vlan_to_vid(out_xbundle, vlan);
    1894         [ -  + ]:      45204 :     if (ovs_list_is_empty(&out_xbundle->xports)) {
    1895                 :            :         /* Partially configured bundle with no slaves.  Drop the packet. */
    1896                 :         25 :         return;
    1897         [ +  + ]:      45204 :     } else if (!out_xbundle->bond) {
    1898                 :      38784 :         xport = CONTAINER_OF(ovs_list_front(&out_xbundle->xports), struct xport,
    1899                 :            :                              bundle_node);
    1900                 :            :     } else {
    1901                 :       6420 :         struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
    1902                 :       6420 :         struct flow_wildcards *wc = ctx->wc;
    1903                 :            :         struct ofport_dpif *ofport;
    1904                 :            : 
    1905         [ +  - ]:       6420 :         if (ctx->xbridge->support.odp.recirc) {
    1906                 :       6420 :             use_recirc = bond_may_recirc(
    1907                 :       6420 :                 out_xbundle->bond, &xr.recirc_id, &xr.hash_basis);
    1908                 :            : 
    1909         [ +  + ]:       6420 :             if (use_recirc) {
    1910                 :            :                 /* Only TCP mode uses recirculation. */
    1911                 :        309 :                 xr.hash_alg = OVS_HASH_ALG_L4;
    1912                 :        309 :                 bond_update_post_recirc_rules(out_xbundle->bond, false);
    1913                 :            : 
    1914                 :            :                 /* Recirculation does not require unmasking hash fields. */
    1915                 :        309 :                 wc = NULL;
    1916                 :            :             }
    1917                 :            :         }
    1918                 :            : 
    1919                 :       6420 :         ofport = bond_choose_output_slave(out_xbundle->bond,
    1920                 :       6420 :                                           &ctx->xin->flow, wc, vid);
    1921                 :       6420 :         xport = xport_lookup(xcfg, ofport);
    1922                 :            : 
    1923         [ +  + ]:       6420 :         if (!xport) {
    1924                 :            :             /* No slaves enabled, so drop packet. */
    1925                 :         25 :             return;
    1926                 :            :         }
    1927                 :            : 
    1928                 :            :         /* If use_recirc is set, the main thread will handle stats
    1929                 :            :          * accounting for this bond. */
    1930         [ +  + ]:       6395 :         if (!use_recirc) {
    1931         [ +  + ]:       6111 :             if (ctx->xin->resubmit_stats) {
    1932                 :        111 :                 bond_account(out_xbundle->bond, &ctx->xin->flow, vid,
    1933                 :        111 :                              ctx->xin->resubmit_stats->n_bytes);
    1934                 :            :             }
    1935         [ +  + ]:       6111 :             if (ctx->xin->xcache) {
    1936                 :            :                 struct xc_entry *entry;
    1937                 :            :                 struct flow *flow;
    1938                 :            : 
    1939                 :       6000 :                 flow = &ctx->xin->flow;
    1940                 :       6000 :                 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_BOND);
    1941                 :       6000 :                 entry->u.bond.bond = bond_ref(out_xbundle->bond);
    1942                 :       6000 :                 entry->u.bond.flow = xmemdup(flow, sizeof *flow);
    1943                 :       6000 :                 entry->u.bond.vid = vid;
    1944                 :            :             }
    1945                 :            :         }
    1946                 :            :     }
    1947                 :            : 
    1948                 :      45179 :     old_tci = *flow_tci;
    1949                 :      45179 :     tci = htons(vid);
    1950 [ +  + ][ +  + ]:      45179 :     if (tci || out_xbundle->use_priority_tags) {
    1951                 :        675 :         tci |= *flow_tci & htons(VLAN_PCP_MASK);
    1952         [ +  + ]:        675 :         if (tci) {
    1953                 :        652 :             tci |= htons(VLAN_CFI);
    1954                 :            :         }
    1955                 :            :     }
    1956                 :      45179 :     *flow_tci = tci;
    1957                 :            : 
    1958         [ +  + ]:      45179 :     compose_output_action(ctx, xport->ofp_port, use_recirc ? &xr : NULL);
    1959                 :      45179 :     *flow_tci = old_tci;
    1960                 :            : }
    1961                 :            : 
    1962                 :            : /* A VM broadcasts a gratuitous ARP to indicate that it has resumed after
    1963                 :            :  * migration.  Older Citrix-patched Linux DomU used gratuitous ARP replies to
    1964                 :            :  * indicate this; newer upstream kernels use gratuitous ARP requests. */
    1965                 :            : static bool
    1966                 :      16789 : is_gratuitous_arp(const struct flow *flow, struct flow_wildcards *wc)
    1967                 :            : {
    1968         [ +  + ]:      16789 :     if (flow->dl_type != htons(ETH_TYPE_ARP)) {
    1969                 :      16485 :         return false;
    1970                 :            :     }
    1971                 :            : 
    1972                 :        304 :     memset(&wc->masks.dl_dst, 0xff, sizeof wc->masks.dl_dst);
    1973         [ +  + ]:        304 :     if (!eth_addr_is_broadcast(flow->dl_dst)) {
    1974                 :        129 :         return false;
    1975                 :            :     }
    1976                 :            : 
    1977                 :        175 :     memset(&wc->masks.nw_proto, 0xff, sizeof wc->masks.nw_proto);
    1978         [ +  + ]:        175 :     if (flow->nw_proto == ARP_OP_REPLY) {
    1979                 :          4 :         return true;
    1980         [ +  - ]:        171 :     } else if (flow->nw_proto == ARP_OP_REQUEST) {
    1981                 :        171 :         memset(&wc->masks.nw_src, 0xff, sizeof wc->masks.nw_src);
    1982                 :        171 :         memset(&wc->masks.nw_dst, 0xff, sizeof wc->masks.nw_dst);
    1983                 :            : 
    1984                 :        171 :         return flow->nw_src == flow->nw_dst;
    1985                 :            :     } else {
    1986                 :          0 :         return false;
    1987                 :            :     }
    1988                 :            : }
    1989                 :            : 
    1990                 :            : /* Determines whether packets in 'flow' within 'xbridge' should be forwarded or
    1991                 :            :  * dropped.  Returns true if they may be forwarded, false if they should be
    1992                 :            :  * dropped.
    1993                 :            :  *
    1994                 :            :  * 'in_port' must be the xport that corresponds to flow->in_port.
    1995                 :            :  * 'in_port' must be part of a bundle (e.g. in_port->bundle must be nonnull).
    1996                 :            :  *
    1997                 :            :  * 'vlan' must be the VLAN that corresponds to flow->vlan_tci on 'in_port', as
    1998                 :            :  * returned by input_vid_to_vlan().  It must be a valid VLAN for 'in_port', as
    1999                 :            :  * checked by input_vid_is_valid().
    2000                 :            :  *
    2001                 :            :  * May also add tags to '*tags', although the current implementation only does
    2002                 :            :  * so in one special case.
    2003                 :            :  */
    2004                 :            : static bool
    2005                 :      30435 : is_admissible(struct xlate_ctx *ctx, struct xport *in_port,
    2006                 :            :               uint16_t vlan)
    2007                 :            : {
    2008                 :      30435 :     struct xbundle *in_xbundle = in_port->xbundle;
    2009                 :      30435 :     const struct xbridge *xbridge = ctx->xbridge;
    2010                 :      30435 :     struct flow *flow = &ctx->xin->flow;
    2011                 :            : 
    2012                 :            :     /* Drop frames for reserved multicast addresses
    2013                 :            :      * only if forward_bpdu option is absent. */
    2014 [ +  - ][ -  + ]:      30435 :     if (!xbridge->forward_bpdu && eth_addr_is_reserved(flow->dl_dst)) {
    2015                 :          0 :         xlate_report(ctx, "packet has reserved destination MAC, dropping");
    2016                 :          0 :         return false;
    2017                 :            :     }
    2018                 :            : 
    2019         [ +  + ]:      30435 :     if (in_xbundle->bond) {
    2020                 :            :         struct mac_entry *mac;
    2021                 :            : 
    2022   [ +  +  +  - ]:      12363 :         switch (bond_check_admissibility(in_xbundle->bond, in_port->ofport,
    2023                 :            :                                          flow->dl_dst)) {
    2024                 :            :         case BV_ACCEPT:
    2025                 :        284 :             break;
    2026                 :            : 
    2027                 :            :         case BV_DROP:
    2028                 :         65 :             xlate_report(ctx, "bonding refused admissibility, dropping");
    2029                 :         65 :             return false;
    2030                 :            : 
    2031                 :            :         case BV_DROP_IF_MOVED:
    2032                 :      12014 :             ovs_rwlock_rdlock(&xbridge->ml->rwlock);
    2033                 :      12014 :             mac = mac_learning_lookup(xbridge->ml, flow->dl_src, vlan);
    2034         [ +  - ]:      12014 :             if (mac
    2035         [ +  - ]:      12014 :                 && mac_entry_get_port(xbridge->ml, mac) != in_xbundle->ofbundle
    2036         [ -  + ]:      12014 :                 && (!is_gratuitous_arp(flow, ctx->wc)
    2037         [ #  # ]:          0 :                     || mac_entry_is_grat_arp_locked(mac))) {
    2038                 :      12014 :                 ovs_rwlock_unlock(&xbridge->ml->rwlock);
    2039                 :      12014 :                 xlate_report(ctx, "SLB bond thinks this packet looped back, "
    2040                 :            :                              "dropping");
    2041                 :      12014 :                 return false;
    2042                 :            :             }
    2043                 :          0 :             ovs_rwlock_unlock(&xbridge->ml->rwlock);
    2044                 :          0 :             break;
    2045                 :            :         }
    2046                 :            :     }
    2047                 :            : 
    2048                 :      18356 :     return true;
    2049                 :            : }
    2050                 :            : 
    2051                 :            : /* Checks whether a MAC learning update is necessary for MAC learning table
    2052                 :            :  * 'ml' given that a packet matching 'flow' was received  on 'in_xbundle' in
    2053                 :            :  * 'vlan'.
    2054                 :            :  *
    2055                 :            :  * Most packets processed through the MAC learning table do not actually
    2056                 :            :  * change it in any way.  This function requires only a read lock on the MAC
    2057                 :            :  * learning table, so it is much cheaper in this common case.
    2058                 :            :  *
    2059                 :            :  * Keep the code here synchronized with that in update_learning_table__()
    2060                 :            :  * below. */
    2061                 :            : static bool
    2062                 :       4774 : is_mac_learning_update_needed(const struct mac_learning *ml,
    2063                 :            :                               const struct flow *flow,
    2064                 :            :                               struct flow_wildcards *wc,
    2065                 :            :                               int vlan, struct xbundle *in_xbundle)
    2066                 :            : OVS_REQ_RDLOCK(ml->rwlock)
    2067                 :            : {
    2068                 :            :     struct mac_entry *mac;
    2069                 :            : 
    2070         [ -  + ]:       4774 :     if (!mac_learning_may_learn(ml, flow->dl_src, vlan)) {
    2071                 :          0 :         return false;
    2072                 :            :     }
    2073                 :            : 
    2074                 :       4774 :     mac = mac_learning_lookup(ml, flow->dl_src, vlan);
    2075 [ +  + ][ +  + ]:       4774 :     if (!mac || mac_entry_age(ml, mac)) {
    2076                 :       2202 :         return true;
    2077                 :            :     }
    2078                 :            : 
    2079         [ -  + ]:       2572 :     if (is_gratuitous_arp(flow, wc)) {
    2080                 :            :         /* Gratuitous ARP packets received over non-bond interfaces could be
    2081                 :            :          * reflected back over bond slaves.  We don't want to learn from these
    2082                 :            :          * reflected packets, so we lock each entry for which a gratuitous ARP
    2083                 :            :          * packet was received over a non-bond interface and refrain from
    2084                 :            :          * learning from gratuitous ARP packets that arrive over bond
    2085                 :            :          * interfaces for this entry while the lock is in effect.  See
    2086                 :            :          * vswitchd/INTERNALS for more in-depth discussion on this topic. */
    2087         [ #  # ]:          0 :         if (!in_xbundle->bond) {
    2088                 :          0 :             return true;
    2089         [ #  # ]:          0 :         } else if (mac_entry_is_grat_arp_locked(mac)) {
    2090                 :          0 :             return false;
    2091                 :            :         }
    2092                 :            :     }
    2093                 :            : 
    2094                 :       2572 :     return mac_entry_get_port(ml, mac) != in_xbundle->ofbundle;
    2095                 :            : }
    2096                 :            : 
    2097                 :            : 
    2098                 :            : /* Updates MAC learning table 'ml' given that a packet matching 'flow' was
    2099                 :            :  * received on 'in_xbundle' in 'vlan'.
    2100                 :            :  *
    2101                 :            :  * This code repeats all the checks in is_mac_learning_update_needed() because
    2102                 :            :  * the lock was released between there and here and thus the MAC learning state
    2103                 :            :  * could have changed.
    2104                 :            :  *
    2105                 :            :  * Keep the code here synchronized with that in is_mac_learning_update_needed()
    2106                 :            :  * above. */
    2107                 :            : static void
    2108                 :       2203 : update_learning_table__(const struct xbridge *xbridge,
    2109                 :            :                         const struct flow *flow, struct flow_wildcards *wc,
    2110                 :            :                         int vlan, struct xbundle *in_xbundle)
    2111                 :            : OVS_REQ_WRLOCK(xbridge->ml->rwlock)
    2112                 :            : {
    2113                 :            :     struct mac_entry *mac;
    2114                 :            : 
    2115         [ -  + ]:       2203 :     if (!mac_learning_may_learn(xbridge->ml, flow->dl_src, vlan)) {
    2116                 :          0 :         return;
    2117                 :            :     }
    2118                 :            : 
    2119                 :       2203 :     mac = mac_learning_insert(xbridge->ml, flow->dl_src, vlan);
    2120         [ +  + ]:       2203 :     if (is_gratuitous_arp(flow, wc)) {
    2121                 :            :         /* We don't want to learn from gratuitous ARP packets that are
    2122                 :            :          * reflected back over bond slaves so we lock the learning table. */
    2123         [ +  - ]:          6 :         if (!in_xbundle->bond) {
    2124                 :          6 :             mac_entry_set_grat_arp_lock(mac);
    2125         [ #  # ]:          0 :         } else if (mac_entry_is_grat_arp_locked(mac)) {
    2126                 :          0 :             return;
    2127                 :            :         }
    2128                 :            :     }
    2129                 :            : 
    2130         [ +  + ]:       2203 :     if (mac_entry_get_port(xbridge->ml, mac) != in_xbundle->ofbundle) {
    2131                 :            :         /* The log messages here could actually be useful in debugging,
    2132                 :            :          * so keep the rate limit relatively high. */
    2133                 :            :         static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(30, 300);
    2134                 :            : 
    2135         [ -  + ]:        645 :         VLOG_DBG_RL(&rl, "bridge %s: learned that "ETH_ADDR_FMT" is "
    2136                 :            :                     "on port %s in VLAN %d",
    2137                 :            :                     xbridge->name, ETH_ADDR_ARGS(flow->dl_src),
    2138                 :            :                     in_xbundle->name, vlan);
    2139                 :            : 
    2140                 :        645 :         mac_entry_set_port(xbridge->ml, mac, in_xbundle->ofbundle);
    2141                 :            :     }
    2142                 :            : }
    2143                 :            : 
    2144                 :            : static void
    2145                 :       4774 : update_learning_table(const struct xbridge *xbridge,
    2146                 :            :                       const struct flow *flow, struct flow_wildcards *wc,
    2147                 :            :                       int vlan, struct xbundle *in_xbundle)
    2148                 :            : {
    2149                 :            :     bool need_update;
    2150                 :            : 
    2151                 :            :     /* Don't learn the OFPP_NONE port. */
    2152         [ -  + ]:       4774 :     if (in_xbundle == &ofpp_none_bundle) {
    2153                 :          0 :         return;
    2154                 :            :     }
    2155                 :            : 
    2156                 :            :     /* First try the common case: no change to MAC learning table. */
    2157                 :       4774 :     ovs_rwlock_rdlock(&xbridge->ml->rwlock);
    2158                 :       4774 :     need_update = is_mac_learning_update_needed(xbridge->ml, flow, wc, vlan,
    2159                 :            :                                                 in_xbundle);
    2160                 :       4774 :     ovs_rwlock_unlock(&xbridge->ml->rwlock);
    2161                 :            : 
    2162         [ +  + ]:       4774 :     if (need_update) {
    2163                 :            :         /* Slow path: MAC learning table might need an update. */
    2164                 :       2203 :         ovs_rwlock_wrlock(&xbridge->ml->rwlock);
    2165                 :       2203 :         update_learning_table__(xbridge, flow, wc, vlan, in_xbundle);
    2166                 :       2203 :         ovs_rwlock_unlock(&xbridge->ml->rwlock);
    2167                 :            :     }
    2168                 :            : }
    2169                 :            : 
    2170                 :            : /* Updates multicast snooping table 'ms' given that a packet matching 'flow'
    2171                 :            :  * was received on 'in_xbundle' in 'vlan' and is either Report or Query. */
    2172                 :            : static void
    2173                 :          0 : update_mcast_snooping_table4__(const struct xbridge *xbridge,
    2174                 :            :                                const struct flow *flow,
    2175                 :            :                                struct mcast_snooping *ms, int vlan,
    2176                 :            :                                struct xbundle *in_xbundle,
    2177                 :            :                                const struct dp_packet *packet)
    2178                 :            :     OVS_REQ_WRLOCK(ms->rwlock)
    2179                 :            : {
    2180                 :            :     static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(60, 30);
    2181                 :            :     int count;
    2182                 :          0 :     ovs_be32 ip4 = flow->igmp_group_ip4;
    2183                 :            : 
    2184   [ #  #  #  #  :          0 :     switch (ntohs(flow->tp_src)) {
                      # ]
    2185                 :            :     case IGMP_HOST_MEMBERSHIP_REPORT:
    2186                 :            :     case IGMPV2_HOST_MEMBERSHIP_REPORT:
    2187         [ #  # ]:          0 :         if (mcast_snooping_add_group4(ms, ip4, vlan, in_xbundle->ofbundle)) {
    2188         [ #  # ]:          0 :             VLOG_DBG_RL(&rl, "bridge %s: multicast snooping learned that "
    2189                 :            :                         IP_FMT" is on port %s in VLAN %d",
    2190                 :            :                         xbridge->name, IP_ARGS(ip4), in_xbundle->name, vlan);
    2191                 :            :         }
    2192                 :          0 :         break;
    2193                 :            :     case IGMP_HOST_LEAVE_MESSAGE:
    2194         [ #  # ]:          0 :         if (mcast_snooping_leave_group4(ms, ip4, vlan, in_xbundle->ofbundle)) {
    2195         [ #  # ]:          0 :             VLOG_DBG_RL(&rl, "bridge %s: multicast snooping leaving "
    2196                 :            :                         IP_FMT" is on port %s in VLAN %d",
    2197                 :            :                         xbridge->name, IP_ARGS(ip4), in_xbundle->name, vlan);
    2198                 :            :         }
    2199                 :          0 :         break;
    2200                 :            :     case IGMP_HOST_MEMBERSHIP_QUERY:
    2201 [ #  # ][ #  # ]:          0 :         if (flow->nw_src && mcast_snooping_add_mrouter(ms, vlan,
    2202                 :          0 :             in_xbundle->ofbundle)) {
    2203         [ #  # ]:          0 :             VLOG_DBG_RL(&rl, "bridge %s: multicast snooping query from "
    2204                 :            :                         IP_FMT" is on port %s in VLAN %d",
    2205                 :            :                         xbridge->name, IP_ARGS(flow->nw_src),
    2206                 :            :                         in_xbundle->name, vlan);
    2207                 :            :         }
    2208                 :          0 :         break;
    2209                 :            :     case IGMPV3_HOST_MEMBERSHIP_REPORT:
    2210         [ #  # ]:          0 :         if ((count = mcast_snooping_add_report(ms, packet, vlan,
    2211                 :          0 :                                                in_xbundle->ofbundle))) {
    2212         [ #  # ]:          0 :             VLOG_DBG_RL(&rl, "bridge %s: multicast snooping processed %d "
    2213                 :            :                         "addresses on port %s in VLAN %d",
    2214                 :            :                         xbridge->name, count, in_xbundle->name, vlan);
    2215                 :            :         }
    2216                 :          0 :         break;
    2217                 :            :     }
    2218                 :          0 : }
    2219                 :            : 
    2220                 :            : static void
    2221                 :          0 : update_mcast_snooping_table6__(const struct xbridge *xbridge,
    2222                 :            :                                const struct flow *flow,
    2223                 :            :                                struct mcast_snooping *ms, int vlan,
    2224                 :            :                                struct xbundle *in_xbundle,
    2225                 :            :                                const struct dp_packet *packet)
    2226                 :            :     OVS_REQ_WRLOCK(ms->rwlock)
    2227                 :            : {
    2228                 :            :     static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(60, 30);
    2229                 :            :     int count;
    2230                 :            : 
    2231      [ #  #  # ]:          0 :     switch (ntohs(flow->tp_src)) {
    2232                 :            :     case MLD_QUERY:
    2233         [ #  # ]:          0 :         if (!ipv6_addr_equals(&flow->ipv6_src, &in6addr_any)
    2234         [ #  # ]:          0 :             && mcast_snooping_add_mrouter(ms, vlan, in_xbundle->ofbundle)) {
    2235         [ #  # ]:          0 :             VLOG_DBG_RL(&rl, "bridge %s: multicast snooping query on port %s"
    2236                 :            :                         "in VLAN %d",
    2237                 :            :                         xbridge->name, in_xbundle->name, vlan);
    2238                 :            :         }
    2239                 :          0 :         break;
    2240                 :            :     case MLD_REPORT:
    2241                 :            :     case MLD_DONE:
    2242                 :            :     case MLD2_REPORT:
    2243                 :          0 :         count = mcast_snooping_add_mld(ms, packet, vlan, in_xbundle->ofbundle);
    2244         [ #  # ]:          0 :         if (count) {
    2245         [ #  # ]:          0 :             VLOG_DBG_RL(&rl, "bridge %s: multicast snooping processed %d "
    2246                 :            :                         "addresses on port %s in VLAN %d",
    2247                 :            :                         xbridge->name, count, in_xbundle->name, vlan);
    2248                 :            :         }
    2249                 :          0 :         break;
    2250                 :            :     }
    2251                 :          0 : }
    2252                 :            : 
    2253                 :            : /* Updates multicast snooping table 'ms' given that a packet matching 'flow'
    2254                 :            :  * was received on 'in_xbundle' in 'vlan'. */
    2255                 :            : static void
    2256                 :          0 : update_mcast_snooping_table(const struct xbridge *xbridge,
    2257                 :            :                             const struct flow *flow, int vlan,
    2258                 :            :                             struct xbundle *in_xbundle,
    2259                 :            :                             const struct dp_packet *packet)
    2260                 :            : {
    2261                 :          0 :     struct mcast_snooping *ms = xbridge->ms;
    2262                 :            :     struct xlate_cfg *xcfg;
    2263                 :            :     struct xbundle *mcast_xbundle;
    2264                 :            :     struct mcast_port_bundle *fport;
    2265                 :            : 
    2266                 :            :     /* Don't learn the OFPP_NONE port. */
    2267         [ #  # ]:          0 :     if (in_xbundle == &ofpp_none_bundle) {
    2268                 :          0 :         return;
    2269                 :            :     }
    2270                 :            : 
    2271                 :            :     /* Don't learn from flood ports */
    2272                 :          0 :     mcast_xbundle = NULL;
    2273                 :          0 :     ovs_rwlock_wrlock(&ms->rwlock);
    2274                 :          0 :     xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
    2275         [ #  # ]:          0 :     LIST_FOR_EACH(fport, node, &ms->fport_list) {
    2276                 :          0 :         mcast_xbundle = xbundle_lookup(xcfg, fport->port);
    2277         [ #  # ]:          0 :         if (mcast_xbundle == in_xbundle) {
    2278                 :          0 :             break;
    2279                 :            :         }
    2280                 :            :     }
    2281                 :            : 
    2282 [ #  # ][ #  # ]:          0 :     if (!mcast_xbundle || mcast_xbundle != in_xbundle) {
    2283         [ #  # ]:          0 :         if (flow->dl_type == htons(ETH_TYPE_IP)) {
    2284                 :          0 :             update_mcast_snooping_table4__(xbridge, flow, ms, vlan,
    2285                 :            :                                            in_xbundle, packet);
    2286                 :            :         } else {
    2287                 :          0 :             update_mcast_snooping_table6__(xbridge, flow, ms, vlan,
    2288                 :            :                                            in_xbundle, packet);
    2289                 :            :         }
    2290                 :            :     }
    2291                 :          0 :     ovs_rwlock_unlock(&ms->rwlock);
    2292                 :            : }
    2293                 :            : 
    2294                 :            : /* send the packet to ports having the multicast group learned */
    2295                 :            : static void
    2296                 :          0 : xlate_normal_mcast_send_group(struct xlate_ctx *ctx,
    2297                 :            :                               struct mcast_snooping *ms OVS_UNUSED,
    2298                 :            :                               struct mcast_group *grp,
    2299                 :            :                               struct xbundle *in_xbundle, uint16_t vlan)
    2300                 :            :     OVS_REQ_RDLOCK(ms->rwlock)
    2301                 :            : {
    2302                 :            :     struct xlate_cfg *xcfg;
    2303                 :            :     struct mcast_group_bundle *b;
    2304                 :            :     struct xbundle *mcast_xbundle;
    2305                 :            : 
    2306                 :          0 :     xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
    2307         [ #  # ]:          0 :     LIST_FOR_EACH(b, bundle_node, &grp->bundle_lru) {
    2308                 :          0 :         mcast_xbundle = xbundle_lookup(xcfg, b->port);
    2309 [ #  # ][ #  # ]:          0 :         if (mcast_xbundle && mcast_xbundle != in_xbundle) {
    2310                 :          0 :             xlate_report(ctx, "forwarding to mcast group port");
    2311                 :          0 :             output_normal(ctx, mcast_xbundle, vlan);
    2312         [ #  # ]:          0 :         } else if (!mcast_xbundle) {
    2313                 :          0 :             xlate_report(ctx, "mcast group port is unknown, dropping");
    2314                 :            :         } else {
    2315                 :          0 :             xlate_report(ctx, "mcast group port is input port, dropping");
    2316                 :            :         }
    2317                 :            :     }
    2318                 :          0 : }
    2319                 :            : 
    2320                 :            : /* send the packet to ports connected to multicast routers */
    2321                 :            : static void
    2322                 :          0 : xlate_normal_mcast_send_mrouters(struct xlate_ctx *ctx,
    2323                 :            :                                  struct mcast_snooping *ms,
    2324                 :            :                                  struct xbundle *in_xbundle, uint16_t vlan)
    2325                 :            :     OVS_REQ_RDLOCK(ms->rwlock)
    2326                 :            : {
    2327                 :            :     struct xlate_cfg *xcfg;
    2328                 :            :     struct mcast_mrouter_bundle *mrouter;
    2329                 :            :     struct xbundle *mcast_xbundle;
    2330                 :            : 
    2331                 :          0 :     xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
    2332         [ #  # ]:          0 :     LIST_FOR_EACH(mrouter, mrouter_node, &ms->mrouter_lru) {
    2333                 :          0 :         mcast_xbundle = xbundle_lookup(xcfg, mrouter->port);
    2334 [ #  # ][ #  # ]:          0 :         if (mcast_xbundle && mcast_xbundle != in_xbundle) {
    2335                 :          0 :             xlate_report(ctx, "forwarding to mcast router port");
    2336                 :          0 :             output_normal(ctx, mcast_xbundle, vlan);
    2337         [ #  # ]:          0 :         } else if (!mcast_xbundle) {
    2338                 :          0 :             xlate_report(ctx, "mcast router port is unknown, dropping");
    2339                 :            :         } else {
    2340                 :          0 :             xlate_report(ctx, "mcast router port is input port, dropping");
    2341                 :            :         }
    2342                 :            :     }
    2343                 :          0 : }
    2344                 :            : 
    2345                 :            : /* send the packet to ports flagged to be flooded */
    2346                 :            : static void
    2347                 :          0 : xlate_normal_mcast_send_fports(struct xlate_ctx *ctx,
    2348                 :            :                                struct mcast_snooping *ms,
    2349                 :            :                                struct xbundle *in_xbundle, uint16_t vlan)
    2350                 :            :     OVS_REQ_RDLOCK(ms->rwlock)
    2351                 :            : {
    2352                 :            :     struct xlate_cfg *xcfg;
    2353                 :            :     struct mcast_port_bundle *fport;
    2354                 :            :     struct xbundle *mcast_xbundle;
    2355                 :            : 
    2356                 :          0 :     xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
    2357         [ #  # ]:          0 :     LIST_FOR_EACH(fport, node, &ms->fport_list) {
    2358                 :          0 :         mcast_xbundle = xbundle_lookup(xcfg, fport->port);
    2359 [ #  # ][ #  # ]:          0 :         if (mcast_xbundle && mcast_xbundle != in_xbundle) {
    2360                 :          0 :             xlate_report(ctx, "forwarding to mcast flood port");
    2361                 :          0 :             output_normal(ctx, mcast_xbundle, vlan);
    2362         [ #  # ]:          0 :         } else if (!mcast_xbundle) {
    2363                 :          0 :             xlate_report(ctx, "mcast flood port is unknown, dropping");
    2364                 :            :         } else {
    2365                 :          0 :             xlate_report(ctx, "mcast flood port is input port, dropping");
    2366                 :            :         }
    2367                 :            :     }
    2368                 :          0 : }
    2369                 :            : 
    2370                 :            : /* forward the Reports to configured ports */
    2371                 :            : static void
    2372                 :          0 : xlate_normal_mcast_send_rports(struct xlate_ctx *ctx,
    2373                 :            :                                struct mcast_snooping *ms,
    2374                 :            :                                struct xbundle *in_xbundle, uint16_t vlan)
    2375                 :            :     OVS_REQ_RDLOCK(ms->rwlock)
    2376                 :            : {
    2377                 :            :     struct xlate_cfg *xcfg;
    2378                 :            :     struct mcast_port_bundle *rport;
    2379                 :            :     struct xbundle *mcast_xbundle;
    2380                 :            : 
    2381                 :          0 :     xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
    2382         [ #  # ]:          0 :     LIST_FOR_EACH(rport, node, &ms->rport_list) {
    2383                 :          0 :         mcast_xbundle = xbundle_lookup(xcfg, rport->port);
    2384 [ #  # ][ #  # ]:          0 :         if (mcast_xbundle && mcast_xbundle != in_xbundle) {
    2385                 :          0 :             xlate_report(ctx, "forwarding Report to mcast flagged port");
    2386                 :          0 :             output_normal(ctx, mcast_xbundle, vlan);
    2387         [ #  # ]:          0 :         } else if (!mcast_xbundle) {
    2388                 :          0 :             xlate_report(ctx, "mcast port is unknown, dropping the Report");
    2389                 :            :         } else {
    2390                 :          0 :             xlate_report(ctx, "mcast port is input port, dropping the Report");
    2391                 :            :         }
    2392                 :            :     }
    2393                 :          0 : }
    2394                 :            : 
    2395                 :            : static void
    2396                 :      15386 : xlate_normal_flood(struct xlate_ctx *ctx, struct xbundle *in_xbundle,
    2397                 :            :                    uint16_t vlan)
    2398                 :            : {
    2399                 :            :     struct xbundle *xbundle;
    2400                 :            : 
    2401         [ +  + ]:      73164 :     LIST_FOR_EACH (xbundle, list_node, &ctx->xbridge->xbundles) {
    2402         [ +  + ]:      57778 :         if (xbundle != in_xbundle
    2403         [ +  + ]:      42393 :             && xbundle_includes_vlan(xbundle, vlan)
    2404         [ +  - ]:      42263 :             && xbundle->floodable
    2405         [ +  - ]:      42263 :             && !xbundle_mirror_out(ctx->xbridge, xbundle)) {
    2406                 :      42263 :             output_normal(ctx, xbundle, vlan);
    2407                 :            :         }
    2408                 :            :     }
    2409                 :      15386 :     ctx->nf_output_iface = NF_OUT_FLOOD;
    2410                 :      15386 : }
    2411                 :            : 
    2412                 :            : static bool
    2413                 :          0 : is_ip_local_multicast(const struct flow *flow, struct flow_wildcards *wc)
    2414                 :            : {
    2415         [ #  # ]:          0 :     if (flow->dl_type == htons(ETH_TYPE_IP)) {
    2416                 :          0 :         memset(&wc->masks.nw_dst, 0xff, sizeof wc->masks.nw_dst);
    2417                 :          0 :         return ip_is_local_multicast(flow->nw_dst);
    2418         [ #  # ]:          0 :     } else if (flow->dl_type == htons(ETH_TYPE_IPV6)) {
    2419                 :          0 :         memset(&wc->masks.ipv6_dst, 0xff, sizeof wc->masks.ipv6_dst);
    2420                 :          0 :         return ipv6_is_all_hosts(&flow->ipv6_dst);
    2421                 :            :     } else {
    2422                 :          0 :         return false;
    2423                 :            :     }
    2424                 :            : }
    2425                 :            : 
    2426                 :            : static void
    2427                 :      30464 : xlate_normal(struct xlate_ctx *ctx)
    2428                 :            : {
    2429                 :      30464 :     struct flow_wildcards *wc = ctx->wc;
    2430                 :      30464 :     struct flow *flow = &ctx->xin->flow;
    2431                 :            :     struct xbundle *in_xbundle;
    2432                 :            :     struct xport *in_port;
    2433                 :            :     struct mac_entry *mac;
    2434                 :            :     void *mac_port;
    2435                 :            :     uint16_t vlan;
    2436                 :            :     uint16_t vid;
    2437                 :            : 
    2438                 :      30464 :     memset(&wc->masks.dl_src, 0xff, sizeof wc->masks.dl_src);
    2439                 :      30464 :     memset(&wc->masks.dl_dst, 0xff, sizeof wc->masks.dl_dst);
    2440                 :      30464 :     wc->masks.vlan_tci |= htons(VLAN_VID_MASK | VLAN_CFI);
    2441                 :            : 
    2442                 :      30464 :     in_xbundle = lookup_input_bundle(ctx->xbridge, flow->in_port.ofp_port,
    2443                 :      30464 :                                      ctx->xin->packet != NULL, &in_port);
    2444         [ +  + ]:      30464 :     if (!in_xbundle) {
    2445                 :          1 :         xlate_report(ctx, "no input bundle, dropping");
    2446                 :      12107 :         return;
    2447                 :            :     }
    2448                 :            : 
    2449                 :            :     /* Drop malformed frames. */
    2450   [ -  +  #  # ]:      30463 :     if (flow->dl_type == htons(ETH_TYPE_VLAN) &&
    2451                 :          0 :         !(flow->vlan_tci & htons(VLAN_CFI))) {
    2452         [ #  # ]:          0 :         if (ctx->xin->packet != NULL) {
    2453                 :            :             static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
    2454         [ #  # ]:          0 :             VLOG_WARN_RL(&rl, "bridge %s: dropping packet with partial "
    2455                 :            :                          "VLAN tag received on port %s",
    2456                 :            :                          ctx->xbridge->name, in_xbundle->name);
    2457                 :            :         }
    2458                 :          0 :         xlate_report(ctx, "partial VLAN tag, dropping");
    2459                 :          0 :         return;
    2460                 :            :     }
    2461                 :            : 
    2462                 :            :     /* Drop frames on bundles reserved for mirroring. */
    2463         [ -  + ]:      30463 :     if (xbundle_mirror_out(ctx->xbridge, in_xbundle)) {
    2464         [ #  # ]:          0 :         if (ctx->xin->packet != NULL) {
    2465                 :            :             static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
    2466         [ #  # ]:          0 :             VLOG_WARN_RL(&rl, "bridge %s: dropping packet received on port "
    2467                 :            :                          "%s, which is reserved exclusively for mirroring",
    2468                 :            :                          ctx->xbridge->name, in_xbundle->name);
    2469                 :            :         }
    2470                 :          0 :         xlate_report(ctx, "input port is mirror output port, dropping");
    2471                 :          0 :         return;
    2472                 :            :     }
    2473                 :            : 
    2474                 :            :     /* Check VLAN. */
    2475                 :      30463 :     vid = vlan_tci_to_vid(flow->vlan_tci);
    2476         [ +  + ]:      30463 :     if (!input_vid_is_valid(vid, in_xbundle, ctx->xin->packet != NULL)) {
    2477                 :         27 :         xlate_report(ctx, "disallowed VLAN VID for this input port, dropping");
    2478                 :         27 :         return;
    2479                 :            :     }
    2480                 :      30436 :     vlan = input_vid_to_vlan(in_xbundle, vid);
    2481                 :            : 
    2482                 :            :     /* Check other admissibility requirements. */
    2483 [ +  + ][ +  + ]:      30436 :     if (in_port && !is_admissible(ctx, in_port, vlan)) {
    2484                 :      12079 :         return;
    2485                 :            :     }
    2486                 :            : 
    2487                 :            :     /* Learn source MAC. */
    2488         [ +  + ]:      18357 :     if (ctx->xin->may_learn) {
    2489                 :       2448 :         update_learning_table(ctx->xbridge, flow, wc, vlan, in_xbundle);
    2490                 :            :     }
    2491         [ +  + ]:      18357 :     if (ctx->xin->xcache) {
    2492                 :            :         struct xc_entry *entry;
    2493                 :            : 
    2494                 :            :         /* Save enough info to update mac learning table later. */
    2495                 :      16153 :         entry = xlate_cache_add_entry(ctx->xin->xcache, XC_NORMAL);
    2496                 :      16153 :         entry->u.normal.ofproto = ctx->xbridge->ofproto;
    2497                 :      16153 :         entry->u.normal.flow = xmemdup(flow, sizeof *flow);
    2498                 :      16153 :         entry->u.normal.vlan = vlan;
    2499                 :            :     }
    2500                 :            : 
    2501                 :            :     /* Determine output bundle. */
    2502         [ -  + ]:      18357 :     if (mcast_snooping_enabled(ctx->xbridge->ms)
    2503         [ #  # ]:          0 :         && !eth_addr_is_broadcast(flow->dl_dst)
    2504         [ #  # ]:          0 :         && eth_addr_is_multicast(flow->dl_dst)
    2505         [ #  # ]:          0 :         && is_ip_any(flow)) {
    2506                 :          0 :         struct mcast_snooping *ms = ctx->xbridge->ms;
    2507                 :          0 :         struct mcast_group *grp = NULL;
    2508                 :            : 
    2509         [ #  # ]:          0 :         if (is_igmp(flow, wc)) {
    2510                 :          0 :             memset(&wc->masks.tp_src, 0xff, sizeof wc->masks.tp_src);
    2511   [ #  #  #  # ]:          0 :             if (mcast_snooping_is_membership(flow->tp_src) ||
    2512                 :          0 :                 mcast_snooping_is_query(flow->tp_src)) {
    2513 [ #  # ][ #  # ]:          0 :                 if (ctx->xin->may_learn && ctx->xin->packet) {
    2514                 :          0 :                     update_mcast_snooping_table(ctx->xbridge, flow, vlan,
    2515                 :          0 :                                                 in_xbundle, ctx->xin->packet);
    2516                 :            :                 }
    2517                 :            :                 /*
    2518                 :            :                  * IGMP packets need to take the slow path, in order to be
    2519                 :            :                  * processed for mdb updates. That will prevent expires
    2520                 :            :                  * firing off even after hosts have sent reports.
    2521                 :            :                  */
    2522                 :          0 :                 ctx->xout->slow |= SLOW_ACTION;
    2523                 :            :             }
    2524                 :            : 
    2525         [ #  # ]:          0 :             if (mcast_snooping_is_membership(flow->tp_src)) {
    2526                 :          0 :                 ovs_rwlock_rdlock(&ms->rwlock);
    2527                 :          0 :                 xlate_normal_mcast_send_mrouters(ctx, ms, in_xbundle, vlan);
    2528                 :            :                 /* RFC4541: section 2.1.1, item 1: A snooping switch should
    2529                 :            :                  * forward IGMP Membership Reports only to those ports where
    2530                 :            :                  * multicast routers are attached.  Alternatively stated: a
    2531                 :            :                  * snooping switch should not forward IGMP Membership Reports
    2532                 :            :                  * to ports on which only hosts are attached.
    2533                 :            :                  * An administrative control may be provided to override this
    2534                 :            :                  * restriction, allowing the report messages to be flooded to
    2535                 :            :                  * other ports. */
    2536                 :          0 :                 xlate_normal_mcast_send_rports(ctx, ms, in_xbundle, vlan);
    2537                 :          0 :                 ovs_rwlock_unlock(&ms->rwlock);
    2538                 :            :             } else {
    2539                 :          0 :                 xlate_report(ctx, "multicast traffic, flooding");
    2540                 :          0 :                 xlate_normal_flood(ctx, in_xbundle, vlan);
    2541                 :            :             }
    2542                 :          0 :             return;
    2543         [ #  # ]:          0 :         } else if (is_mld(flow, wc)) {
    2544                 :          0 :             ctx->xout->slow |= SLOW_ACTION;
    2545 [ #  # ][ #  # ]:          0 :             if (ctx->xin->may_learn && ctx->xin->packet) {
    2546                 :          0 :                 update_mcast_snooping_table(ctx->xbridge, flow, vlan,
    2547                 :          0 :                                             in_xbundle, ctx->xin->packet);
    2548                 :            :             }
    2549         [ #  # ]:          0 :             if (is_mld_report(flow, wc)) {
    2550                 :          0 :                 ovs_rwlock_rdlock(&ms->rwlock);
    2551                 :          0 :                 xlate_normal_mcast_send_mrouters(ctx, ms, in_xbundle, vlan);
    2552                 :          0 :                 xlate_normal_mcast_send_rports(ctx, ms, in_xbundle, vlan);
    2553                 :          0 :                 ovs_rwlock_unlock(&ms->rwlock);
    2554                 :            :             } else {
    2555                 :          0 :                 xlate_report(ctx, "MLD query, flooding");
    2556                 :          0 :                 xlate_normal_flood(ctx, in_xbundle, vlan);
    2557                 :            :             }
    2558                 :            :         } else {
    2559         [ #  # ]:          0 :             if (is_ip_local_multicast(flow, wc)) {
    2560                 :            :                 /* RFC4541: section 2.1.2, item 2: Packets with a dst IP
    2561                 :            :                  * address in the 224.0.0.x range which are not IGMP must
    2562                 :            :                  * be forwarded on all ports */
    2563                 :          0 :                 xlate_report(ctx, "RFC4541: section 2.1.2, item 2, flooding");
    2564                 :          0 :                 xlate_normal_flood(ctx, in_xbundle, vlan);
    2565                 :          0 :                 return;
    2566                 :            :             }
    2567                 :            :         }
    2568                 :            : 
    2569                 :            :         /* forwarding to group base ports */
    2570                 :          0 :         ovs_rwlock_rdlock(&ms->rwlock);
    2571         [ #  # ]:          0 :         if (flow->dl_type == htons(ETH_TYPE_IP)) {
    2572                 :          0 :             grp = mcast_snooping_lookup4(ms, flow->nw_dst, vlan);
    2573         [ #  # ]:          0 :         } else if (flow->dl_type == htons(ETH_TYPE_IPV6)) {
    2574                 :          0 :             grp = mcast_snooping_lookup(ms, &flow->ipv6_dst, vlan);
    2575                 :            :         }
    2576         [ #  # ]:          0 :         if (grp) {
    2577                 :          0 :             xlate_normal_mcast_send_group(ctx, ms, grp, in_xbundle, vlan);
    2578                 :          0 :             xlate_normal_mcast_send_fports(ctx, ms, in_xbundle, vlan);
    2579                 :          0 :             xlate_normal_mcast_send_mrouters(ctx, ms, in_xbundle, vlan);
    2580                 :            :         } else {
    2581         [ #  # ]:          0 :             if (mcast_snooping_flood_unreg(ms)) {
    2582                 :          0 :                 xlate_report(ctx, "unregistered multicast, flooding");
    2583                 :          0 :                 xlate_normal_flood(ctx, in_xbundle, vlan);
    2584                 :            :             } else {
    2585                 :          0 :                 xlate_normal_mcast_send_mrouters(ctx, ms, in_xbundle, vlan);
    2586                 :          0 :                 xlate_normal_mcast_send_fports(ctx, ms, in_xbundle, vlan);
    2587                 :            :             }
    2588                 :            :         }
    2589                 :          0 :         ovs_rwlock_unlock(&ms->rwlock);
    2590                 :            :     } else {
    2591                 :      18357 :         ovs_rwlock_rdlock(&ctx->xbridge->ml->rwlock);
    2592                 :      18357 :         mac = mac_learning_lookup(ctx->xbridge->ml, flow->dl_dst, vlan);
    2593         [ +  + ]:      18357 :         mac_port = mac ? mac_entry_get_port(ctx->xbridge->ml, mac) : NULL;
    2594                 :      18357 :         ovs_rwlock_unlock(&ctx->xbridge->ml->rwlock);
    2595                 :            : 
    2596         [ +  + ]:      18357 :         if (mac_port) {
    2597                 :       2971 :             struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
    2598                 :       2971 :             struct xbundle *mac_xbundle = xbundle_lookup(xcfg, mac_port);
    2599 [ +  - ][ +  + ]:       2971 :             if (mac_xbundle && mac_xbundle != in_xbundle) {
    2600                 :       2897 :                 xlate_report(ctx, "forwarding to learned port");
    2601                 :       2897 :                 output_normal(ctx, mac_xbundle, vlan);
    2602         [ -  + ]:         74 :             } else if (!mac_xbundle) {
    2603                 :          0 :                 xlate_report(ctx, "learned port is unknown, dropping");
    2604                 :            :             } else {
    2605                 :       2971 :                 xlate_report(ctx, "learned port is input port, dropping");
    2606                 :            :             }
    2607                 :            :         } else {
    2608                 :      15386 :             xlate_report(ctx, "no learned MAC for destination, flooding");
    2609                 :      18357 :             xlate_normal_flood(ctx, in_xbundle, vlan);
    2610                 :            :         }
    2611                 :            :     }
    2612                 :            : }
    2613                 :            : 
    2614                 :            : /* Appends a "sample" action for sFlow or IPFIX to 'ctx->odp_actions'.  The
    2615                 :            :  * 'probability' is the number of packets out of UINT32_MAX to sample.  The
    2616                 :            :  * 'cookie' (of length 'cookie_size' bytes) is passed back in the callback for
    2617                 :            :  * each sampled packet.  'tunnel_out_port', if not ODPP_NONE, is added as the
    2618                 :            :  * OVS_USERSPACE_ATTR_EGRESS_TUN_PORT attribute.  If 'include_actions', an
    2619                 :            :  * OVS_USERSPACE_ATTR_ACTIONS attribute is added.  If 'emit_set_tunnel',
    2620                 :            :  * sample(sampling_port=1) would translate into datapath sample action
    2621                 :            :  * set(tunnel(...)), sample(...) and it is used for sampling egress tunnel
    2622                 :            :  * information.
    2623                 :            :  */
    2624                 :            : static size_t
    2625                 :         31 : compose_sample_action(struct xlate_ctx *ctx,
    2626                 :            :                       const uint32_t probability,
    2627                 :            :                       const union user_action_cookie *cookie,
    2628                 :            :                       const size_t cookie_size,
    2629                 :            :                       const odp_port_t tunnel_out_port,
    2630                 :            :                       bool include_actions)
    2631                 :            : {
    2632                 :         31 :     size_t sample_offset = nl_msg_start_nested(ctx->odp_actions,
    2633                 :            :                                                OVS_ACTION_ATTR_SAMPLE);
    2634                 :            : 
    2635                 :         31 :     nl_msg_put_u32(ctx->odp_actions, OVS_SAMPLE_ATTR_PROBABILITY, probability);
    2636                 :            : 
    2637                 :         31 :     size_t actions_offset = nl_msg_start_nested(ctx->odp_actions,
    2638                 :            :                                                 OVS_SAMPLE_ATTR_ACTIONS);
    2639                 :            : 
    2640                 :         31 :     odp_port_t odp_port = ofp_port_to_odp_port(
    2641                 :         31 :         ctx->xbridge, ctx->xin->flow.in_port.ofp_port);
    2642                 :         31 :     uint32_t pid = dpif_port_get_pid(ctx->xbridge->dpif, odp_port,
    2643                 :         31 :                                      flow_hash_5tuple(&ctx->xin->flow, 0));
    2644                 :         31 :     int cookie_offset = odp_put_userspace_action(pid, cookie, cookie_size,
    2645                 :            :                                                  tunnel_out_port,
    2646                 :            :                                                  include_actions,
    2647                 :            :                                                  ctx->odp_actions);
    2648                 :            : 
    2649                 :         31 :     nl_msg_end_nested(ctx->odp_actions, actions_offset);
    2650                 :         31 :     nl_msg_end_nested(ctx->odp_actions, sample_offset);
    2651                 :            : 
    2652                 :         31 :     return cookie_offset;
    2653                 :            : }
    2654                 :            : 
    2655                 :            : /* If sFLow is not enabled, returns 0 without doing anything.
    2656                 :            :  *
    2657                 :            :  * If sFlow is enabled, appends a template "sample" action to the ODP actions
    2658                 :            :  * in 'ctx'.  This action is a template because some of the information needed
    2659                 :            :  * to fill it out is not available until flow translation is complete.  In this
    2660                 :            :  * case, this functions returns an offset, which is always nonzero, to pass
    2661                 :            :  * later to fix_sflow_action() to fill in the rest of the template. */
    2662                 :            : static size_t
    2663                 :      83024 : compose_sflow_action(struct xlate_ctx *ctx)
    2664                 :            : {
    2665                 :      83024 :     struct dpif_sflow *sflow = ctx->xbridge->sflow;
    2666 [ +  + ][ +  + ]:      83024 :     if (!sflow || ctx->xin->flow.in_port.ofp_port == OFPP_NONE) {
    2667                 :      83003 :         return 0;
    2668                 :            :     }
    2669                 :            : 
    2670                 :         21 :     union user_action_cookie cookie = { .type = USER_ACTION_COOKIE_SFLOW };
    2671                 :      83024 :     return compose_sample_action(ctx, dpif_sflow_get_probability(sflow),
    2672                 :            :                                  &cookie, sizeof cookie.sflow, ODPP_NONE,
    2673                 :            :                                  true);
    2674                 :            : }
    2675                 :            : 
    2676                 :            : /* If flow IPFIX is enabled, make sure IPFIX flow sample action
    2677                 :            :  * at egress point of tunnel port is just in front of corresponding
    2678                 :            :  * output action. If bridge IPFIX is enabled, this appends an IPFIX
    2679                 :            :  * sample action to 'ctx->odp_actions'. */
    2680                 :            : static void
    2681                 :     164568 : compose_ipfix_action(struct xlate_ctx *ctx, odp_port_t output_odp_port)
    2682                 :            : {
    2683                 :     164568 :     struct dpif_ipfix *ipfix = ctx->xbridge->ipfix;
    2684                 :     164568 :     odp_port_t tunnel_out_port = ODPP_NONE;
    2685                 :            : 
    2686 [ +  + ][ -  + ]:     164568 :     if (!ipfix || ctx->xin->flow.in_port.ofp_port == OFPP_NONE) {
    2687                 :     164565 :         return;
    2688                 :            :     }
    2689                 :            : 
    2690                 :            :     /* For input case, output_odp_port is ODPP_NONE, which is an invalid port
    2691                 :            :      * number. */
    2692   [ +  +  +  + ]:         33 :     if (output_odp_port == ODPP_NONE &&
    2693                 :         13 :         !dpif_ipfix_get_bridge_exporter_input_sampling(ipfix)) {
    2694                 :         10 :         return;
    2695                 :            :     }
    2696                 :            : 
    2697                 :            :     /* For output case, output_odp_port is valid. */
    2698         [ +  + ]:         10 :     if (output_odp_port != ODPP_NONE) {
    2699         [ +  - ]:          7 :         if (!dpif_ipfix_get_bridge_exporter_output_sampling(ipfix)) {
    2700                 :          7 :             return;
    2701                 :            :         }
    2702                 :            :         /* If tunnel sampling is enabled, put an additional option attribute:
    2703                 :            :          * OVS_USERSPACE_ATTR_TUNNEL_OUT_PORT
    2704                 :            :          */
    2705   [ #  #  #  # ]:          0 :         if (dpif_ipfix_get_bridge_exporter_tunnel_sampling(ipfix) &&
    2706                 :          0 :             dpif_ipfix_get_tunnel_port(ipfix, output_odp_port) ) {
    2707                 :          0 :            tunnel_out_port = output_odp_port;
    2708                 :            :         }
    2709                 :            :     }
    2710                 :            : 
    2711                 :          3 :     union user_action_cookie cookie = {
    2712                 :            :         .ipfix = {
    2713                 :            :             .type = USER_ACTION_COOKIE_IPFIX,
    2714                 :            :             .output_odp_port = output_odp_port,
    2715                 :            :         }
    2716                 :            :     };
    2717                 :          3 :     compose_sample_action(ctx,
    2718                 :            :                           dpif_ipfix_get_bridge_exporter_probability(ipfix),
    2719                 :            :                           &cookie, sizeof cookie.ipfix, tunnel_out_port,
    2720                 :            :                           false);
    2721                 :            : }
    2722                 :            : 
    2723                 :            : /* Fix "sample" action according to data collected while composing ODP actions,
    2724                 :            :  * as described in compose_sflow_action().
    2725                 :            :  *
    2726                 :            :  * 'user_cookie_offset' must be the offset returned by add_sflow_action(). */
    2727                 :            : static void
    2728                 :         21 : fix_sflow_action(struct xlate_ctx *ctx, unsigned int user_cookie_offset)
    2729                 :            : {
    2730                 :         21 :     const struct flow *base = &ctx->base_flow;
    2731                 :            :     union user_action_cookie *cookie;
    2732                 :            : 
    2733                 :         21 :     cookie = ofpbuf_at(ctx->odp_actions, user_cookie_offset,
    2734                 :            :                        sizeof cookie->sflow);
    2735         [ -  + ]:         21 :     ovs_assert(cookie->type == USER_ACTION_COOKIE_SFLOW);
    2736                 :            : 
    2737                 :         21 :     cookie->type = USER_ACTION_COOKIE_SFLOW;
    2738                 :         21 :     cookie->sflow.vlan_tci = base->vlan_tci;
    2739                 :            : 
    2740                 :            :     /* See http://www.sflow.org/sflow_version_5.txt (search for "Input/output
    2741                 :            :      * port information") for the interpretation of cookie->output. */
    2742      [ -  +  + ]:         21 :     switch (ctx->sflow_n_outputs) {
    2743                 :            :     case 0:
    2744                 :            :         /* 0x40000000 | 256 means "packet dropped for unknown reason". */
    2745                 :          0 :         cookie->sflow.output = 0x40000000 | 256;
    2746                 :          0 :         break;
    2747                 :            : 
    2748                 :            :     case 1:
    2749                 :         11 :         cookie->sflow.output = dpif_sflow_odp_port_to_ifindex(
    2750                 :         11 :             ctx->xbridge->sflow, ctx->sflow_odp_port);
    2751         [ +  + ]:         11 :         if (cookie->sflow.output) {
    2752                 :          6 :             break;
    2753                 :            :         }
    2754                 :            :         /* Fall through. */
    2755                 :            :     default:
    2756                 :            :         /* 0x80000000 means "multiple output ports. */
    2757                 :         15 :         cookie->sflow.output = 0x80000000 | ctx->sflow_n_outputs;
    2758                 :         15 :         break;
    2759                 :            :     }
    2760                 :         21 : }
    2761                 :            : 
    2762                 :            : static bool
    2763                 :     118323 : process_special(struct xlate_ctx *ctx, const struct xport *xport)
    2764                 :            : {
    2765                 :     118323 :     const struct flow *flow = &ctx->xin->flow;
    2766                 :     118323 :     struct flow_wildcards *wc = ctx->wc;
    2767                 :     118323 :     const struct xbridge *xbridge = ctx->xbridge;
    2768                 :     118323 :     const struct dp_packet *packet = ctx->xin->packet;
    2769                 :            :     enum slow_path_reason slow;
    2770                 :            : 
    2771         [ +  + ]:     118323 :     if (!xport) {
    2772                 :       8012 :         slow = 0;
    2773 [ +  + ][ +  + ]:     110311 :     } else if (xport->cfm && cfm_should_process_flow(xport->cfm, flow, wc)) {
    2774         [ +  - ]:        917 :         if (packet) {
    2775                 :        917 :             cfm_process_heartbeat(xport->cfm, packet);
    2776                 :            :         }
    2777                 :        917 :         slow = SLOW_CFM;
    2778 [ +  + ][ +  + ]:     109394 :     } else if (xport->bfd && bfd_should_process_flow(xport->bfd, flow, wc)) {
    2779         [ +  - ]:       1128 :         if (packet) {
    2780                 :       1128 :             bfd_process_packet(xport->bfd, flow, packet);
    2781                 :            :             /* If POLL received, immediately sends FINAL back. */
    2782         [ +  + ]:       1128 :             if (bfd_should_send_packet(xport->bfd)) {
    2783                 :        449 :                 ofproto_dpif_monitor_port_send_soon(xport->ofport);
    2784                 :            :             }
    2785                 :            :         }
    2786                 :       1128 :         slow = SLOW_BFD;
    2787 [ +  + ][ +  + ]:     108266 :     } else if (xport->xbundle && xport->xbundle->lacp
    2788         [ +  + ]:        419 :                && flow->dl_type == htons(ETH_TYPE_LACP)) {
    2789         [ +  + ]:        106 :         if (packet) {
    2790                 :         54 :             lacp_process_packet(xport->xbundle->lacp, xport->ofport, packet);
    2791                 :            :         }
    2792                 :        106 :         slow = SLOW_LACP;
    2793         [ +  + ]:     108194 :     } else if ((xbridge->stp || xbridge->rstp) &&
           [ +  +  +  + ]
    2794                 :         34 :                stp_should_process_flow(flow, wc)) {
    2795         [ +  + ]:         26 :         if (packet) {
    2796                 :         19 :             xbridge->stp
    2797                 :         13 :                 ? stp_process_packet(xport, packet)
    2798         [ +  + ]:         19 :                 : rstp_process_packet(xport, packet);
    2799                 :            :         }
    2800                 :         26 :         slow = SLOW_STP;
    2801 [ -  + ][ #  # ]:     108134 :     } else if (xport->lldp && lldp_should_process_flow(xport->lldp, flow)) {
    2802         [ #  # ]:          0 :         if (packet) {
    2803                 :          0 :             lldp_process_packet(xport->lldp, packet);
    2804                 :            :         }
    2805                 :          0 :         slow = SLOW_LLDP;
    2806                 :            :     } else {
    2807                 :     108134 :         slow = 0;
    2808                 :            :     }
    2809                 :            : 
    2810         [ +  + ]:     118323 :     if (slow) {
    2811                 :       2177 :         ctx->xout->slow |= slow;
    2812                 :       2177 :         return true;
    2813                 :            :     } else {
    2814                 :     116146 :         return false;
    2815                 :            :     }
    2816                 :            : }
    2817                 :            : 
    2818                 :            : static int
    2819                 :       6248 : tnl_route_lookup_flow(const struct flow *oflow,
    2820                 :            :                       struct in6_addr *ip, struct in6_addr *src,
    2821                 :            :                       struct xport **out_port)
    2822                 :            : {
    2823                 :            :     char out_dev[IFNAMSIZ];
    2824                 :            :     struct xbridge *xbridge;
    2825                 :            :     struct xlate_cfg *xcfg;
    2826                 :            :     struct in6_addr gw;
    2827                 :            :     struct in6_addr dst;
    2828                 :            : 
    2829                 :       6248 :     dst = flow_tnl_dst(&oflow->tunnel);
    2830         [ -  + ]:       6248 :     if (!ovs_router_lookup(&dst, out_dev, src, &gw)) {
    2831                 :          0 :         return -ENOENT;
    2832                 :            :     }
    2833                 :            : 
    2834 [ +  + ][ +  - ]:      12367 :     if (ipv6_addr_is_set(&gw) &&
    2835 [ +  - ][ +  - ]:      12238 :         (!IN6_IS_ADDR_V4MAPPED(&gw) || in6_addr_get_mapped_ipv4(&gw))) {
         [ +  - ][ +  + ]
    2836                 :       3830 :         *ip = gw;
    2837                 :            :     } else {
    2838                 :       2418 :         *ip = dst;
    2839                 :            :     }
    2840                 :            : 
    2841                 :       6248 :     xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
    2842         [ -  + ]:       6248 :     ovs_assert(xcfg);
    2843                 :            : 
    2844 [ +  + ][ -  + ]:      10421 :     HMAP_FOR_EACH (xbridge, hmap_node, &xcfg->xbridges) {
    2845         [ +  + ]:       6591 :         if (!strncmp(xbridge->name, out_dev, IFNAMSIZ)) {
    2846                 :            :             struct xport *port;
    2847                 :            : 
    2848 [ +  - ][ #  # ]:       2418 :             HMAP_FOR_EACH (port, ofp_node, &xbridge->xports) {
    2849         [ +  - ]:       2418 :                 if (!strncmp(netdev_get_name(port->netdev), out_dev, IFNAMSIZ)) {
    2850                 :       2418 :                     *out_port = port;
    2851                 :       2418 :                     return 0;
    2852                 :            :                 }
    2853                 :            :             }
    2854                 :            :         }
    2855                 :            :     }
    2856                 :       6248 :     return -ENOENT;
    2857                 :            : }
    2858                 :            : 
    2859                 :            : static int
    2860                 :         11 : compose_table_xlate(struct xlate_ctx *ctx, const struct xport *out_dev,
    2861                 :            :                     struct dp_packet *packet)
    2862                 :            : {
    2863                 :         11 :     struct xbridge *xbridge = out_dev->xbridge;
    2864                 :            :     struct ofpact_output output;
    2865                 :            :     struct flow flow;
    2866                 :            : 
    2867                 :         11 :     ofpact_init(&output.ofpact, OFPACT_OUTPUT, sizeof output);
    2868                 :         11 :     flow_extract(packet, &flow);
    2869                 :         11 :     flow.in_port.ofp_port = out_dev->ofp_port;
    2870                 :         11 :     output.port = OFPP_TABLE;
    2871                 :         11 :     output.max_len = 0;
    2872                 :            : 
    2873                 :         11 :     return ofproto_dpif_execute_actions__(xbridge->ofproto, &flow, NULL,
    2874                 :            :                                           &output.ofpact, sizeof output,
    2875                 :            :                                           ctx->indentation, ctx->depth,
    2876                 :            :                                           ctx->resubmits, packet);
    2877                 :            : }
    2878                 :            : 
    2879                 :            : static void
    2880                 :          4 : tnl_send_nd_request(struct xlate_ctx *ctx, const struct xport *out_dev,
    2881                 :            :                      const struct eth_addr eth_src,
    2882                 :            :                      struct in6_addr * ipv6_src, struct in6_addr * ipv6_dst)
    2883                 :            : {
    2884                 :            :     struct dp_packet packet;
    2885                 :            : 
    2886                 :          4 :     dp_packet_init(&packet, 0);
    2887                 :          4 :     compose_nd_ns(&packet, eth_src, ipv6_src, ipv6_dst);
    2888                 :          4 :     compose_table_xlate(ctx, out_dev, &packet);
    2889                 :          4 :     dp_packet_uninit(&packet);
    2890                 :          4 : }
    2891                 :            : 
    2892                 :            : static void
    2893                 :          7 : tnl_send_arp_request(struct xlate_ctx *ctx, const struct xport *out_dev,
    2894                 :            :                      const struct eth_addr eth_src,
    2895                 :            :                      ovs_be32 ip_src, ovs_be32 ip_dst)
    2896                 :            : {
    2897                 :            :     struct dp_packet packet;
    2898                 :            : 
    2899                 :          7 :     dp_packet_init(&packet, 0);
    2900                 :          7 :     compose_arp(&packet, ARP_OP_REQUEST,
    2901                 :            :                 eth_src, eth_addr_zero, true, ip_src, ip_dst);
    2902                 :            : 
    2903                 :          7 :     compose_table_xlate(ctx, out_dev, &packet);
    2904                 :          7 :     dp_packet_uninit(&packet);
    2905                 :          7 : }
    2906                 :            : 
    2907                 :            : static int
    2908                 :       6248 : build_tunnel_send(struct xlate_ctx *ctx, const struct xport *xport,
    2909                 :            :                   const struct flow *flow, odp_port_t tunnel_odp_port)
    2910                 :            : {
    2911                 :            :     struct netdev_tnl_build_header_params tnl_params;
    2912                 :            :     struct ovs_action_push_tnl tnl_push_data;
    2913                 :       6248 :     struct xport *out_dev = NULL;
    2914                 :       6248 :     ovs_be32 s_ip = 0, d_ip = 0;
    2915                 :       6248 :     struct in6_addr s_ip6 = in6addr_any;
    2916                 :       6248 :     struct in6_addr d_ip6 = in6addr_any;
    2917                 :            :     struct eth_addr smac;
    2918                 :            :     struct eth_addr dmac;
    2919                 :            :     int err;
    2920                 :            :     char buf_sip6[INET6_ADDRSTRLEN];
    2921                 :            :     char buf_dip6[INET6_ADDRSTRLEN];
    2922                 :            : 
    2923                 :       6248 :     err = tnl_route_lookup_flow(flow, &d_ip6, &s_ip6, &out_dev);
    2924         [ +  + ]:       6248 :     if (err) {
    2925                 :       3830 :         xlate_report(ctx, "native tunnel routing failed");
    2926                 :       3830 :         return err;
    2927                 :            :     }
    2928                 :            : 
    2929                 :       2418 :     xlate_report(ctx, "tunneling to %s via %s",
    2930                 :            :                  ipv6_string_mapped(buf_dip6, &d_ip6),
    2931                 :       2418 :                  netdev_get_name(out_dev->netdev));
    2932                 :            : 
    2933                 :            :     /* Use mac addr of bridge port of the peer. */
    2934                 :       2418 :     err = netdev_get_etheraddr(out_dev->netdev, &smac);
    2935         [ -  + ]:       2418 :     if (err) {
    2936                 :          0 :         xlate_report(ctx, "tunnel output device lacks Ethernet address");
    2937                 :          0 :         return err;
    2938                 :            :     }
    2939                 :            : 
    2940                 :       2418 :     d_ip = in6_addr_get_mapped_ipv4(&d_ip6);
    2941         [ +  + ]:       2418 :     if (d_ip) {
    2942                 :       2398 :         s_ip = in6_addr_get_mapped_ipv4(&s_ip6);
    2943                 :            :     }
    2944                 :            : 
    2945                 :       2418 :     err = tnl_neigh_lookup(out_dev->xbridge->name, &d_ip6, &dmac);
    2946         [ +  + ]:       2418 :     if (err) {
    2947         [ +  + ]:         11 :         xlate_report(ctx, "neighbor cache miss for %s on bridge %s, "
    2948                 :            :                      "sending %s request",
    2949                 :         11 :                      buf_dip6, out_dev->xbridge->name, d_ip ? "ARP" : "ND");
    2950         [ +  + ]:         11 :         if (d_ip) {
    2951                 :          7 :             tnl_send_arp_request(ctx, out_dev, smac, s_ip, d_ip);
    2952                 :            :         } else {
    2953                 :          4 :             tnl_send_nd_request(ctx, out_dev, smac, &s_ip6, &d_ip6);
    2954                 :            :         }
    2955                 :         11 :         return err;
    2956                 :            :     }
    2957                 :            : 
    2958         [ +  + ]:       2407 :     if (ctx->xin->xcache) {
    2959                 :            :         struct xc_entry *entry;
    2960                 :            : 
    2961                 :        706 :         entry = xlate_cache_add_entry(ctx->xin->xcache, XC_TNL_NEIGH);
    2962                 :        706 :         ovs_strlcpy(entry->u.tnl_neigh_cache.br_name, out_dev->xbridge->name,
    2963                 :            :                     sizeof entry->u.tnl_neigh_cache.br_name);
    2964                 :        706 :         entry->u.tnl_neigh_cache.d_ipv6 = d_ip6;
    2965                 :            :     }
    2966                 :            : 
    2967                 :       2407 :     xlate_report(ctx, "tunneling from "ETH_ADDR_FMT" %s"
    2968                 :            :                  " to "ETH_ADDR_FMT" %s",
    2969                 :      14442 :                  ETH_ADDR_ARGS(smac), ipv6_string_mapped(buf_sip6, &s_ip6),
    2970                 :      14442 :                  ETH_ADDR_ARGS(dmac), buf_dip6);
    2971                 :            : 
    2972                 :       2407 :     netdev_init_tnl_build_header_params(&tnl_params, flow, &s_ip6, dmac, smac);
    2973                 :       2407 :     err = tnl_port_build_header(xport->ofport, &tnl_push_data, &tnl_params);
    2974         [ -  + ]:       2407 :     if (err) {
    2975                 :          0 :         return err;
    2976                 :            :     }
    2977                 :       2407 :     tnl_push_data.tnl_port = odp_to_u32(tunnel_odp_port);
    2978                 :       2407 :     tnl_push_data.out_port = odp_to_u32(out_dev->odp_port);
    2979                 :       2407 :     odp_put_tnl_push_action(ctx->odp_actions, &tnl_push_data);
    2980                 :       6248 :     return 0;
    2981                 :            : }
    2982                 :            : 
    2983                 :            : static void
    2984                 :     116809 : xlate_commit_actions(struct xlate_ctx *ctx)
    2985                 :            : {
    2986                 :     116809 :     bool use_masked = ctx->xbridge->support.masked_set_action;
    2987                 :            : 
    2988                 :     116809 :     ctx->xout->slow |= commit_odp_actions(&ctx->xin->flow, &ctx->base_flow,
    2989                 :            :                                           ctx->odp_actions, ctx->wc,
    2990                 :            :                                           use_masked);
    2991                 :     116809 : }
    2992                 :            : 
    2993                 :            : static void
    2994                 :      35752 : clear_conntrack(struct flow *flow)
    2995                 :            : {
    2996                 :      35752 :     flow->ct_state = 0;
    2997                 :      35752 :     flow->ct_zone = 0;
    2998                 :      35752 :     flow->ct_mark = 0;
    2999                 :      35752 :     memset(&flow->ct_label, 0, sizeof flow->ct_label);
    3000                 :      35752 : }
    3001                 :            : 
    3002                 :            : static void
    3003                 :     124425 : compose_output_action__(struct xlate_ctx *ctx, ofp_port_t ofp_port,
    3004                 :            :                         const struct xlate_bond_recirc *xr, bool check_stp)
    3005                 :            : {
    3006                 :     124425 :     const struct xport *xport = get_ofp_port(ctx->xbridge, ofp_port);
    3007                 :     124425 :     struct flow_wildcards *wc = ctx->wc;
    3008                 :     124425 :     struct flow *flow = &ctx->xin->flow;
    3009                 :            :     struct flow_tnl flow_tnl;
    3010                 :            :     ovs_be16 flow_vlan_tci;
    3011                 :            :     uint32_t flow_pkt_mark;
    3012                 :            :     uint8_t flow_nw_tos;
    3013                 :            :     odp_port_t out_port, odp_port;
    3014                 :     124425 :     bool tnl_push_pop_send = false;
    3015                 :            :     uint8_t dscp;
    3016                 :            : 
    3017                 :            :     /* If 'struct flow' gets additional metadata, we'll need to zero it out
    3018                 :            :      * before traversing a patch port. */
    3019                 :            :     BUILD_ASSERT_DECL(FLOW_WC_SEQ == 36);
    3020                 :     124425 :     memset(&flow_tnl, 0, sizeof flow_tnl);
    3021                 :            : 
    3022         [ +  + ]:     124425 :     if (!xport) {
    3023                 :         18 :         xlate_report(ctx, "Nonexistent output port");
    3024                 :      35225 :         return;
    3025         [ +  + ]:     124407 :     } else if (xport->config & OFPUTIL_PC_NO_FWD) {
    3026                 :          5 :         xlate_report(ctx, "OFPPC_NO_FWD set, skipping output");
    3027                 :          5 :         return;
    3028 [ +  + ][ -  + ]:     124402 :     } else if (ctx->mirror_snaplen != 0 && xport->odp_port == ODPP_NONE) {
    3029                 :          0 :         xlate_report(ctx, "Mirror truncate to ODPP_NONE, skipping output");
    3030                 :          0 :         return;
    3031         [ +  + ]:     124402 :     } else if (check_stp) {
    3032         [ +  + ]:     124396 :         if (is_stp(&ctx->base_flow)) {
    3033   [ -  +  #  # ]:         20 :             if (!xport_stp_should_forward_bpdu(xport) &&
    3034                 :          0 :                 !xport_rstp_should_manage_bpdu(xport)) {
    3035         [ #  # ]:          0 :                 if (ctx->xbridge->stp != NULL) {
    3036                 :          0 :                     xlate_report(ctx, "STP not in listening state, "
    3037                 :            :                             "skipping bpdu output");
    3038         [ #  # ]:          0 :                 } else if (ctx->xbridge->rstp != NULL) {
    3039                 :          0 :                     xlate_report(ctx, "RSTP not managing BPDU in this state, "
    3040                 :            :                             "skipping bpdu output");
    3041                 :            :                 }
    3042                 :          0 :                 return;
    3043                 :            :             }
    3044   [ +  +  +  + ]:     248750 :         } else if (!xport_stp_forward_state(xport) ||
    3045                 :     124374 :                    !xport_rstp_forward_state(xport)) {
    3046         [ +  + ]:          4 :             if (ctx->xbridge->stp != NULL) {
    3047                 :          2 :                 xlate_report(ctx, "STP not in forwarding state, "
    3048                 :            :                         "skipping output");
    3049         [ +  - ]:          2 :             } else if (ctx->xbridge->rstp != NULL) {
    3050                 :          2 :                 xlate_report(ctx, "RSTP not in forwarding state, "
    3051                 :            :                         "skipping output");
    3052                 :            :             }
    3053                 :          4 :             return;
    3054                 :            :         }
    3055                 :            :     }
    3056                 :            : 
    3057         [ +  + ]:     124398 :     if (xport->peer) {
    3058                 :      35198 :         const struct xport *peer = xport->peer;
    3059                 :      35198 :         struct flow old_flow = ctx->xin->flow;
    3060                 :      35198 :         bool old_conntrack = ctx->conntracked;
    3061                 :      35198 :         bool old_was_mpls = ctx->was_mpls;
    3062                 :      35198 :         ovs_version_t old_version = ctx->tables_version;
    3063                 :      35198 :         struct ofpbuf old_stack = ctx->stack;
    3064                 :            :         union mf_subvalue new_stack[1024 / sizeof(union mf_subvalue)];
    3065                 :      35198 :         struct ofpbuf old_action_set = ctx->action_set;
    3066                 :            :         uint64_t actset_stub[1024 / 8];
    3067                 :            : 
    3068                 :      35198 :         ofpbuf_use_stub(&ctx->stack, new_stack, sizeof new_stack);
    3069                 :      35198 :         ofpbuf_use_stub(&ctx->action_set, actset_stub, sizeof actset_stub);
    3070                 :      35198 :         ctx->xbridge = peer->xbridge;
    3071                 :      35198 :         flow->in_port.ofp_port = peer->ofp_port;
    3072                 :      35198 :         flow->metadata = htonll(0);
    3073                 :      35198 :         memset(&flow->tunnel, 0, sizeof flow->tunnel);
    3074                 :      35198 :         memset(flow->regs, 0, sizeof flow->regs);
    3075                 :      35198 :         flow->actset_output = OFPP_UNSET;
    3076                 :      35198 :         ctx->conntracked = false;
    3077                 :      35198 :         clear_conntrack(flow);
    3078                 :            : 
    3079                 :            :         /* The bridge is now known so obtain its table version. */
    3080                 :            :         ctx->tables_version
    3081                 :      35198 :             = ofproto_dpif_get_tables_version(ctx->xbridge->ofproto);
    3082                 :            : 
    3083 [ +  + ][ +  - ]:      35198 :         if (!process_special(ctx, peer) && may_receive(peer, ctx)) {
    3084 [ +  - ][ +  - ]:      33123 :             if (xport_stp_forward_state(peer) && xport_rstp_forward_state(peer)) {
    3085                 :      33123 :                 xlate_table_action(ctx, flow->in_port.ofp_port, 0, true, true);
    3086         [ +  + ]:      33123 :                 if (!ctx->freezing) {
    3087                 :      33114 :                     xlate_action_set(ctx);
    3088                 :            :                 }
    3089         [ +  + ]:      33132 :                 if (ctx->freezing) {
    3090                 :          9 :                     finish_freezing(ctx);
    3091                 :            :                 }
    3092                 :            :             } else {
    3093                 :            :                 /* Forwarding is disabled by STP and RSTP.  Let OFPP_NORMAL and
    3094                 :            :                  * the learning action look at the packet, then drop it. */
    3095                 :          0 :                 struct flow old_base_flow = ctx->base_flow;
    3096                 :          0 :                 size_t old_size = ctx->odp_actions->size;
    3097                 :          0 :                 mirror_mask_t old_mirrors = ctx->mirrors;
    3098                 :            : 
    3099                 :          0 :                 xlate_table_action(ctx, flow->in_port.ofp_port, 0, true, true);
    3100                 :          0 :                 ctx->mirrors = old_mirrors;
    3101                 :          0 :                 ctx->base_flow = old_base_flow;
    3102                 :          0 :                 ctx->odp_actions->size = old_size;
    3103                 :            : 
    3104                 :            :                 /* Undo changes that may have been done for freezing. */
    3105                 :          0 :                 ctx_cancel_freeze(ctx);
    3106                 :            :             }
    3107                 :            :         }
    3108                 :            : 
    3109                 :      35198 :         ctx->xin->flow = old_flow;
    3110                 :      35198 :         ctx->xbridge = xport->xbridge;
    3111                 :      35198 :         ofpbuf_uninit(&ctx->action_set);
    3112                 :      35198 :         ctx->action_set = old_action_set;
    3113                 :      35198 :         ofpbuf_uninit(&ctx->stack);
    3114                 :      35198 :         ctx->stack = old_stack;
    3115                 :            : 
    3116                 :            :         /* Restore calling bridge's lookup version. */
    3117                 :      35198 :         ctx->tables_version = old_version;
    3118                 :            : 
    3119                 :            :         /* The peer bridge popping MPLS should have no effect on the original
    3120                 :            :          * bridge. */
    3121                 :      35198 :         ctx->was_mpls = old_was_mpls;
    3122                 :            : 
    3123                 :            :         /* The peer bridge's conntrack execution should have no effect on the
    3124                 :            :          * original bridge. */
    3125                 :      35198 :         ctx->conntracked = old_conntrack;
    3126                 :            : 
    3127                 :            :         /* The fact that the peer bridge exits (for any reason) does not mean
    3128                 :            :          * that the original bridge should exit.  Specifically, if the peer
    3129                 :            :          * bridge freezes translation, the original bridge must continue
    3130                 :            :          * processing with the original, not the frozen packet! */
    3131                 :      35198 :         ctx->exit = false;
    3132                 :            : 
    3133                 :            :         /* Peer bridge errors do not propagate back. */
    3134                 :      35198 :         ctx->error = XLATE_OK;
    3135                 :            : 
    3136         [ +  + ]:      35198 :         if (ctx->xin->resubmit_stats) {
    3137                 :       7263 :             netdev_vport_inc_tx(xport->netdev, ctx->xin->resubmit_stats);
    3138                 :       7263 :             netdev_vport_inc_rx(peer->netdev, ctx->xin->resubmit_stats);
    3139         [ +  + ]:       7263 :             if (peer->bfd) {
    3140                 :       1564 :                 bfd_account_rx(peer->bfd, ctx->xin->resubmit_stats);
    3141                 :            :             }
    3142                 :            :         }
    3143         [ +  + ]:      35198 :         if (ctx->xin->xcache) {
    3144                 :            :             struct xc_entry *entry;
    3145                 :            : 
    3146                 :      28038 :             entry = xlate_cache_add_entry(ctx->xin->xcache, XC_NETDEV);
    3147                 :      28038 :             entry->u.dev.tx = netdev_ref(xport->netdev);
    3148                 :      28038 :             entry->u.dev.rx = netdev_ref(peer->netdev);
    3149                 :      28038 :             entry->u.dev.bfd = bfd_ref(peer->bfd);
    3150                 :            :         }
    3151                 :      35198 :         return;
    3152                 :            :     }
    3153                 :            : 
    3154                 :      89200 :     flow_vlan_tci = flow->vlan_tci;
    3155                 :      89200 :     flow_pkt_mark = flow->pkt_mark;
    3156                 :      89200 :     flow_nw_tos = flow->nw_tos;
    3157                 :            : 
    3158         [ +  + ]:      89200 :     if (count_skb_priorities(xport)) {
    3159                 :          6 :         memset(&wc->masks.skb_priority, 0xff, sizeof wc->masks.skb_priority);
    3160         [ +  + ]:          6 :         if (dscp_from_skb_priority(xport, flow->skb_priority, &dscp)) {
    3161                 :          4 :             wc->masks.nw_tos |= IP_DSCP_MASK;
    3162                 :          4 :             flow->nw_tos &= ~IP_DSCP_MASK;
    3163                 :          4 :             flow->nw_tos |= dscp;
    3164                 :            :         }
    3165                 :            :     }
    3166                 :            : 
    3167         [ +  + ]:      89200 :     if (xport->is_tunnel) {
    3168                 :            :         struct in6_addr dst;
    3169                 :            :          /* Save tunnel metadata so that changes made due to
    3170                 :            :           * the Logical (tunnel) Port are not visible for any further
    3171                 :            :           * matches, while explicit set actions on tunnel metadata are.
    3172                 :            :           */
    3173                 :       6365 :         flow_tnl = flow->tunnel;
    3174                 :       6365 :         odp_port = tnl_port_send(xport->ofport, flow, ctx->wc);
    3175         [ -  + ]:       6365 :         if (odp_port == ODPP_NONE) {
    3176                 :          0 :             xlate_report(ctx, "Tunneling decided against output");
    3177                 :          6 :             goto out; /* restore flow_nw_tos */
    3178                 :            :         }
    3179                 :       6365 :         dst = flow_tnl_dst(&flow->tunnel);
    3180         [ +  + ]:       6365 :         if (ipv6_addr_equals(&dst, &ctx->orig_tunnel_ipv6_dst)) {
    3181                 :          6 :             xlate_report(ctx, "Not tunneling to our own address");
    3182                 :          6 :             goto out; /* restore flow_nw_tos */
    3183                 :            :         }
    3184         [ +  + ]:       6359 :         if (ctx->xin->resubmit_stats) {
    3185                 :       5647 :             netdev_vport_inc_tx(xport->netdev, ctx->xin->resubmit_stats);
    3186                 :            :         }
    3187         [ +  + ]:       6359 :         if (ctx->xin->xcache) {
    3188                 :            :             struct xc_entry *entry;
    3189                 :            : 
    3190                 :        753 :             entry = xlate_cache_add_entry(ctx->xin->xcache, XC_NETDEV);
    3191                 :        753 :             entry->u.dev.tx = netdev_ref(xport->netdev);
    3192                 :            :         }
    3193                 :       6359 :         out_port = odp_port;
    3194         [ +  + ]:       6359 :         if (ovs_native_tunneling_is_on(ctx->xbridge->ofproto)) {
    3195                 :       6248 :             xlate_report(ctx, "output to native tunnel");
    3196                 :       6248 :             tnl_push_pop_send = true;
    3197                 :            :         } else {
    3198                 :        111 :             xlate_report(ctx, "output to kernel tunnel");
    3199                 :        111 :             commit_odp_tunnel_action(flow, &ctx->base_flow, ctx->odp_actions);
    3200                 :       6359 :             flow->tunnel = flow_tnl; /* Restore tunnel metadata */
    3201                 :            :         }
    3202                 :            :     } else {
    3203                 :      82835 :         odp_port = xport->odp_port;
    3204                 :      82835 :         out_port = odp_port;
    3205                 :            :     }
    3206                 :            : 
    3207         [ +  + ]:      89194 :     if (out_port != ODPP_NONE) {
    3208                 :      89166 :         xlate_commit_actions(ctx);
    3209                 :            : 
    3210         [ +  + ]:      89166 :         if (xr) {
    3211                 :            :             struct ovs_action_hash *act_hash;
    3212                 :            : 
    3213                 :            :             /* Hash action. */
    3214                 :        279 :             act_hash = nl_msg_put_unspec_uninit(ctx->odp_actions,
    3215                 :            :                                                 OVS_ACTION_ATTR_HASH,
    3216                 :            :                                                 sizeof *act_hash);
    3217                 :        279 :             act_hash->hash_alg = xr->hash_alg;
    3218                 :        279 :             act_hash->hash_basis = xr->hash_basis;
    3219                 :            : 
    3220                 :            :             /* Recirc action. */
    3221                 :        279 :             nl_msg_put_u32(ctx->odp_actions, OVS_ACTION_ATTR_RECIRC,
    3222                 :            :                            xr->recirc_id);
    3223                 :            :         } else {
    3224                 :            : 
    3225         [ +  + ]:      88887 :             if (tnl_push_pop_send) {
    3226                 :       6248 :                 build_tunnel_send(ctx, xport, flow, odp_port);
    3227                 :       6248 :                 flow->tunnel = flow_tnl; /* Restore tunnel metadata */
    3228                 :            :             } else {
    3229                 :      82639 :                 odp_port_t odp_tnl_port = ODPP_NONE;
    3230                 :            : 
    3231                 :            :                 /* XXX: Write better Filter for tunnel port. We can use inport
    3232                 :            :                 * int tunnel-port flow to avoid these checks completely. */
    3233   [ +  +  +  + ]:     111142 :                 if (ofp_port == OFPP_LOCAL &&
    3234                 :      28503 :                     ovs_native_tunneling_is_on(ctx->xbridge->ofproto)) {
    3235                 :            : 
    3236                 :       1506 :                     odp_tnl_port = tnl_port_map_lookup(flow, wc);
    3237                 :            :                 }
    3238                 :            : 
    3239         [ +  + ]:      82639 :                 if (odp_tnl_port != ODPP_NONE) {
    3240                 :       1095 :                     nl_msg_put_odp_port(ctx->odp_actions,
    3241                 :            :                                         OVS_ACTION_ATTR_TUNNEL_POP,
    3242                 :            :                                         odp_tnl_port);
    3243                 :            :                 } else {
    3244                 :            :                     /* Tunnel push-pop action is not compatible with
    3245                 :            :                      * IPFIX action. */
    3246                 :      81544 :                     compose_ipfix_action(ctx, out_port);
    3247                 :            : 
    3248                 :            :                     /* Handle truncation of the mirrored packet. */
    3249 [ +  + ][ +  - ]:      81544 :                     if (ctx->mirror_snaplen > 0 &&
    3250                 :         16 :                         ctx->mirror_snaplen < UINT16_MAX) {
    3251                 :            :                         struct ovs_action_trunc *trunc;
    3252                 :            : 
    3253                 :         16 :                         trunc = nl_msg_put_unspec_uninit(ctx->odp_actions,
    3254                 :            :                                                          OVS_ACTION_ATTR_TRUNC,
    3255                 :            :                                                          sizeof *trunc);
    3256                 :         16 :                         trunc->max_len = ctx->mirror_snaplen;
    3257         [ -  + ]:         16 :                         if (!ctx->xbridge->support.trunc) {
    3258                 :          0 :                             ctx->xout->slow |= SLOW_ACTION;
    3259                 :            :                         }
    3260                 :            :                     }
    3261                 :            : 
    3262                 :      81544 :                     nl_msg_put_odp_port(ctx->odp_actions,
    3263                 :            :                                         OVS_ACTION_ATTR_OUTPUT,
    3264                 :            :                                         out_port);
    3265                 :            :                 }
    3266                 :            :             }
    3267                 :            :         }
    3268                 :            : 
    3269                 :      89166 :         ctx->sflow_odp_port = odp_port;
    3270                 :      89166 :         ctx->sflow_n_outputs++;
    3271                 :      89166 :         ctx->nf_output_iface = ofp_port;
    3272                 :            :     }
    3273                 :            : 
    3274 [ +  + ][ +  - ]:      89194 :     if (mbridge_has_mirrors(ctx->xbridge->mbridge) && xport->xbundle) {
    3275                 :        101 :         mirror_packet(ctx, xport->xbundle,
    3276                 :        101 :                       xbundle_mirror_dst(xport->xbundle->xbridge,
    3277                 :            :                                          xport->xbundle));
    3278                 :            :     }
    3279                 :            : 
    3280                 :            :  out:
    3281                 :            :     /* Restore flow */
    3282                 :      89200 :     flow->vlan_tci = flow_vlan_tci;
    3283                 :      89200 :     flow->pkt_mark = flow_pkt_mark;
    3284                 :      89200 :     flow->nw_tos = flow_nw_tos;
    3285                 :            : }
    3286                 :            : 
    3287                 :            : static void
    3288                 :     124418 : compose_output_action(struct xlate_ctx *ctx, ofp_port_t ofp_port,
    3289                 :            :                       const struct xlate_bond_recirc *xr)
    3290                 :            : {
    3291                 :     124418 :     compose_output_action__(ctx, ofp_port, xr, true);
    3292                 :     124418 : }
    3293                 :            : 
    3294                 :            : static void
    3295                 :    1210491 : xlate_recursively(struct xlate_ctx *ctx, struct rule_dpif *rule, bool deepens)
    3296                 :            : {
    3297                 :    1210491 :     struct rule_dpif *old_rule = ctx->rule;
    3298                 :    1210491 :     ovs_be64 old_cookie = ctx->rule_cookie;
    3299                 :            :     const struct rule_actions *actions;
    3300                 :            : 
    3301         [ +  + ]:    1210491 :     if (ctx->xin->resubmit_stats) {
    3302                 :     144305 :         rule_dpif_credit_stats(rule, ctx->xin->resubmit_stats);
    3303                 :            :     }
    3304                 :            : 
    3305                 :    1210491 :     ctx->resubmits++;
    3306                 :            : 
    3307                 :    1210491 :     ctx->indentation++;
    3308                 :    1210491 :     ctx->depth += deepens;
    3309                 :    1210491 :     ctx->rule = rule;
    3310                 :    1210491 :     ctx->rule_cookie = rule_dpif_get_flow_cookie(rule);
    3311                 :    1210491 :     actions = rule_dpif_get_actions(rule);
    3312                 :    1210490 :     do_xlate_actions(actions->ofpacts, actions->ofpacts_len, ctx);
    3313                 :    1210492 :     ctx->rule_cookie = old_cookie;
    3314                 :    1210492 :     ctx->rule = old_rule;
    3315                 :    1210492 :     ctx->depth -= deepens;
    3316                 :    1210492 :     ctx->indentation--;
    3317                 :    1210492 : }
    3318                 :            : 
    3319                 :            : static bool
    3320                 :    1210760 : xlate_resubmit_resource_check(struct xlate_ctx *ctx)
    3321                 :            : {
    3322         [ +  + ]:    1210760 :     if (ctx->depth >= MAX_DEPTH) {
    3323 [ +  - ][ #  # ]:          2 :         XLATE_REPORT_ERROR(ctx, "over max translation depth %d", MAX_DEPTH);
    3324                 :          2 :         ctx->error = XLATE_RECURSION_TOO_DEEP;
    3325         [ +  + ]:    1210758 :     } else if (ctx->resubmits >= MAX_RESUBMITS) {
    3326 [ +  - ][ #  # ]:          1 :         XLATE_REPORT_ERROR(ctx, "over %d resubmit actions", MAX_RESUBMITS);
    3327                 :          1 :         ctx->error = XLATE_TOO_MANY_RESUBMITS;
    3328         [ +  + ]:    1210757 :     } else if (ctx->odp_actions->size > UINT16_MAX) {
    3329 [ +  - ][ #  # ]:          1 :         XLATE_REPORT_ERROR(ctx, "resubmits yielded over 64 kB of actions");
    3330                 :            :         /* NOT an error, as we'll be slow-pathing the flow in this case? */
    3331                 :          1 :         ctx->exit = true; /* XXX: translation still terminated! */
    3332         [ +  + ]:    1210756 :     } else if (ctx->stack.size >= 65536) {
    3333 [ +  - ][ #  # ]:          1 :         XLATE_REPORT_ERROR(ctx, "resubmits yielded over 64 kB of stack");
    3334                 :          1 :         ctx->error = XLATE_STACK_TOO_DEEP;
    3335                 :            :     } else {
    3336                 :    1210755 :         return true;
    3337                 :            :     }
    3338                 :            : 
    3339                 :          5 :     return false;
    3340                 :            : }
    3341                 :            : 
    3342                 :            : static void
    3343                 :    1210497 : xlate_table_action(struct xlate_ctx *ctx, ofp_port_t in_port, uint8_t table_id,
    3344                 :            :                    bool may_packet_in, bool honor_table_miss)
    3345                 :            : {
    3346                 :            :     /* Check if we need to recirculate before matching in a table. */
    3347         [ +  + ]:    1210497 :     if (ctx->was_mpls) {
    3348                 :          1 :         ctx_trigger_freeze(ctx);
    3349                 :          1 :         return;
    3350                 :            :     }
    3351         [ +  + ]:    1210496 :     if (xlate_resubmit_resource_check(ctx)) {
    3352                 :    1210491 :         uint8_t old_table_id = ctx->table_id;
    3353                 :            :         struct rule_dpif *rule;
    3354                 :            : 
    3355                 :    1210491 :         ctx->table_id = table_id;
    3356                 :            : 
    3357                 :    1210491 :         rule = rule_dpif_lookup_from_table(ctx->xbridge->ofproto,
    3358                 :            :                                            ctx->tables_version,
    3359                 :    1210491 :                                            &ctx->xin->flow, ctx->wc,
    3360                 :    1210491 :                                            ctx->xin->resubmit_stats,
    3361                 :            :                                            &ctx->table_id, in_port,
    3362                 :            :                                            may_packet_in, honor_table_miss);
    3363                 :            : 
    3364         [ +  + ]:    1210490 :         if (OVS_UNLIKELY(ctx->xin->resubmit_hook)) {
    3365                 :       6612 :             ctx->xin->resubmit_hook(ctx->xin, rule, ctx->indentation + 1);
    3366                 :            :         }
    3367                 :            : 
    3368         [ +  - ]:    1210490 :         if (rule) {
    3369                 :            :             /* Fill in the cache entry here instead of xlate_recursively
    3370                 :            :              * to make the reference counting more explicit.  We take a
    3371                 :            :              * reference in the lookups above if we are going to cache the
    3372                 :            :              * rule. */
    3373         [ +  + ]:    1210490 :             if (ctx->xin->xcache) {
    3374                 :            :                 struct xc_entry *entry;
    3375                 :            : 
    3376                 :    1070420 :                 entry = xlate_cache_add_entry(ctx->xin->xcache, XC_RULE);
    3377                 :    1070420 :                 entry->u.rule = rule;
    3378                 :    1070420 :                 rule_dpif_ref(rule);
    3379                 :            :             }
    3380                 :    1210490 :             xlate_recursively(ctx, rule, table_id <= old_table_id);
    3381                 :            :         }
    3382                 :            : 
    3383                 :    1210492 :         ctx->table_id = old_table_id;
    3384                 :    1210492 :         return;
    3385                 :            :     }
    3386                 :            : }
    3387                 :            : 
    3388                 :            : /* Consumes the group reference, which is only taken if xcache exists. */
    3389                 :            : static void
    3390                 :        264 : xlate_group_stats(struct xlate_ctx *ctx, struct group_dpif *group,
    3391                 :            :                   struct ofputil_bucket *bucket)
    3392                 :            : {
    3393         [ +  + ]:        264 :     if (ctx->xin->resubmit_stats) {
    3394                 :        245 :         group_dpif_credit_stats(group, bucket, ctx->xin->resubmit_stats);
    3395                 :            :     }
    3396         [ +  + ]:        264 :     if (ctx->xin->xcache) {
    3397                 :            :         struct xc_entry *entry;
    3398                 :            : 
    3399                 :         50 :         entry = xlate_cache_add_entry(ctx->xin->xcache, XC_GROUP);
    3400                 :         50 :         entry->u.group.group = group;
    3401                 :         50 :         entry->u.group.bucket = bucket;
    3402                 :            :     }
    3403                 :        264 : }
    3404                 :            : 
    3405                 :            : static void
    3406                 :        274 : xlate_group_bucket(struct xlate_ctx *ctx, struct ofputil_bucket *bucket)
    3407                 :            : {
    3408                 :            :     uint64_t action_list_stub[1024 / 8];
    3409                 :        274 :     struct ofpbuf action_list = OFPBUF_STUB_INITIALIZER(action_list_stub);
    3410                 :        274 :     struct ofpbuf action_set = ofpbuf_const_initializer(bucket->ofpacts,
    3411                 :            :                                                         bucket->ofpacts_len);
    3412                 :        274 :     struct flow old_flow = ctx->xin->flow;
    3413                 :        274 :     bool old_was_mpls = ctx->was_mpls;
    3414                 :            : 
    3415                 :        274 :     ofpacts_execute_action_set(&action_list, &action_set);
    3416                 :        274 :     ctx->indentation++;
    3417                 :        274 :     ctx->depth++;
    3418                 :        274 :     do_xlate_actions(action_list.data, action_list.size, ctx);
    3419                 :        274 :     ctx->depth--;
    3420                 :        274 :     ctx->indentation--;
    3421                 :            : 
    3422                 :        274 :     ofpbuf_uninit(&action_list);
    3423                 :            : 
    3424                 :            :     /* Check if need to freeze. */
    3425         [ +  + ]:        274 :     if (ctx->freezing) {
    3426                 :          2 :         finish_freezing(ctx);
    3427                 :            :     }
    3428                 :            : 
    3429                 :            :     /* Roll back flow to previous state.
    3430                 :            :      * This is equivalent to cloning the packet for each bucket.
    3431                 :            :      *
    3432                 :            :      * As a side effect any subsequently applied actions will
    3433                 :            :      * also effectively be applied to a clone of the packet taken
    3434                 :            :      * just before applying the all or indirect group.
    3435                 :            :      *
    3436                 :            :      * Note that group buckets are action sets, hence they cannot modify the
    3437                 :            :      * main action set.  Also any stack actions are ignored when executing an
    3438                 :            :      * action set, so group buckets cannot change the stack either.
    3439                 :            :      * However, we do allow resubmit actions in group buckets, which could
    3440                 :            :      * break the above assumptions.  It is up to the controller to not mess up
    3441                 :            :      * with the action_set and stack in the tables resubmitted to from
    3442                 :            :      * group buckets. */
    3443                 :        274 :     ctx->xin->flow = old_flow;
    3444                 :            : 
    3445                 :            :     /* The group bucket popping MPLS should have no effect after bucket
    3446                 :            :      * execution. */
    3447                 :        274 :     ctx->was_mpls = old_was_mpls;
    3448                 :            : 
    3449                 :            :     /* The fact that the group bucket exits (for any reason) does not mean that
    3450                 :            :      * the translation after the group action should exit.  Specifically, if
    3451                 :            :      * the group bucket freezes translation, the actions after the group action
    3452                 :            :      * must continue processing with the original, not the frozen packet! */
    3453                 :        274 :     ctx->exit = false;
    3454                 :        274 : }
    3455                 :            : 
    3456                 :            : static void
    3457                 :         14 : xlate_all_group(struct xlate_ctx *ctx, struct group_dpif *group)
    3458                 :            : {
    3459                 :            :     struct ofputil_bucket *bucket;
    3460                 :            :     const struct ovs_list *buckets;
    3461                 :            : 
    3462                 :         14 :     buckets = group_dpif_get_buckets(group);
    3463         [ +  + ]:         38 :     LIST_FOR_EACH (bucket, list_node, buckets) {
    3464                 :         24 :         xlate_group_bucket(ctx, bucket);
    3465                 :            :     }
    3466                 :         14 :     xlate_group_stats(ctx, group, NULL);
    3467                 :         14 : }
    3468                 :            : 
    3469                 :            : static void
    3470                 :          0 : xlate_ff_group(struct xlate_ctx *ctx, struct group_dpif *group)
    3471                 :            : {
    3472                 :            :     struct ofputil_bucket *bucket;
    3473                 :            : 
    3474                 :          0 :     bucket = group_first_live_bucket(ctx, group, 0);
    3475         [ #  # ]:          0 :     if (bucket) {
    3476                 :          0 :         xlate_group_bucket(ctx, bucket);
    3477                 :          0 :         xlate_group_stats(ctx, group, bucket);
    3478         [ #  # ]:          0 :     } else if (ctx->xin->xcache) {
    3479                 :          0 :         group_dpif_unref(group);
    3480                 :            :     }
    3481                 :          0 : }
    3482                 :            : 
    3483                 :            : static void
    3484                 :        250 : xlate_default_select_group(struct xlate_ctx *ctx, struct group_dpif *group)
    3485                 :            : {
    3486                 :        250 :     struct flow_wildcards *wc = ctx->wc;
    3487                 :            :     struct ofputil_bucket *bucket;
    3488                 :            :     uint32_t basis;
    3489                 :            : 
    3490                 :        250 :     basis = flow_hash_symmetric_l4(&ctx->xin->flow, 0);
    3491                 :        250 :     flow_mask_hash_fields(&ctx->xin->flow, wc, NX_HASH_FIELDS_SYMMETRIC_L4);
    3492                 :        250 :     bucket = group_best_live_bucket(ctx, group, basis);
    3493         [ +  - ]:        250 :     if (bucket) {
    3494                 :        250 :         xlate_group_bucket(ctx, bucket);
    3495                 :        250 :         xlate_group_stats(ctx, group, bucket);
    3496         [ #  # ]:          0 :     } else if (ctx->xin->xcache) {
    3497                 :          0 :         group_dpif_unref(group);
    3498                 :            :     }
    3499                 :        250 : }
    3500                 :            : 
    3501                 :            : static void
    3502                 :          0 : xlate_hash_fields_select_group(struct xlate_ctx *ctx, struct group_dpif *group)
    3503                 :            : {
    3504                 :            :     const struct field_array *fields;
    3505                 :            :     struct ofputil_bucket *bucket;
    3506                 :            :     const uint8_t *mask_values;
    3507                 :            :     uint32_t basis;
    3508                 :            :     size_t i;
    3509                 :            : 
    3510                 :          0 :     fields = group_dpif_get_fields(group);
    3511                 :          0 :     mask_values = fields->values;
    3512                 :          0 :     basis = hash_uint64(group_dpif_get_selection_method_param(group));
    3513                 :            : 
    3514         [ #  # ]:          0 :     BITMAP_FOR_EACH_1 (i, MFF_N_IDS, fields->used.bm) {
    3515                 :          0 :         const struct mf_field *mf = mf_from_id(i);
    3516                 :            : 
    3517                 :            :         /* Skip fields for which prerequisities are not met. */
    3518         [ #  # ]:          0 :         if (!mf_are_prereqs_ok(mf, &ctx->xin->flow, ctx->wc)) {
    3519                 :            :             /* Skip the mask bytes for this field. */
    3520                 :          0 :             mask_values += mf->n_bytes;
    3521                 :          0 :             continue;
    3522                 :            :         }
    3523                 :            : 
    3524                 :            :         union mf_value value;
    3525                 :            :         union mf_value mask;
    3526                 :            : 
    3527                 :          0 :         mf_get_value(mf, &ctx->xin->flow, &value);
    3528                 :            :         /* Mask the value. */
    3529         [ #  # ]:          0 :         for (int j = 0; j < mf->n_bytes; j++) {
    3530                 :          0 :             mask.b[j] = *mask_values++;
    3531                 :          0 :             value.b[j] &= mask.b[j];
    3532                 :            :         }
    3533                 :          0 :         basis = hash_bytes(&value, mf->n_bytes, basis);
    3534                 :            : 
    3535                 :            :         /* For tunnels, hash in whether the field is present. */
    3536         [ #  # ]:          0 :         if (mf_is_tun_metadata(mf)) {
    3537                 :          0 :             basis = hash_boolean(mf_is_set(mf, &ctx->xin->flow), basis);
    3538                 :            :         }
    3539                 :            : 
    3540                 :          0 :         mf_mask_field_masked(mf, &mask, ctx->wc);
    3541                 :            :     }
    3542                 :            : 
    3543                 :          0 :     bucket = group_best_live_bucket(ctx, group, basis);
    3544         [ #  # ]:          0 :     if (bucket) {
    3545                 :          0 :         xlate_group_bucket(ctx, bucket);
    3546                 :          0 :         xlate_group_stats(ctx, group, bucket);
    3547         [ #  # ]:          0 :     } else if (ctx->xin->xcache) {
    3548                 :          0 :         group_dpif_unref(group);
    3549                 :            :     }
    3550                 :          0 : }
    3551                 :            : 
    3552                 :            : static void
    3553                 :        250 : xlate_select_group(struct xlate_ctx *ctx, struct group_dpif *group)
    3554                 :            : {
    3555                 :        250 :     const char *selection_method = group_dpif_get_selection_method(group);
    3556                 :            : 
    3557                 :            :     /* Select groups may access flow keys beyond L2 in order to
    3558                 :            :      * select a bucket. Recirculate as appropriate to make this possible.
    3559                 :            :      */
    3560         [ +  + ]:        250 :     if (ctx->was_mpls) {
    3561                 :          1 :         ctx_trigger_freeze(ctx);
    3562                 :            :     }
    3563                 :            : 
    3564         [ +  - ]:        250 :     if (selection_method[0] == '\0') {
    3565                 :        250 :         xlate_default_select_group(ctx, group);
    3566         [ #  # ]:          0 :     } else if (!strcasecmp("hash", selection_method)) {
    3567                 :          0 :         xlate_hash_fields_select_group(ctx, group);
    3568                 :            :     } else {
    3569                 :            :         /* Parsing of groups should ensure this never happens */
    3570                 :          0 :         OVS_NOT_REACHED();
    3571                 :            :     }
    3572                 :        250 : }
    3573                 :            : 
    3574                 :            : static void
    3575                 :        264 : xlate_group_action__(struct xlate_ctx *ctx, struct group_dpif *group)
    3576                 :            : {
    3577                 :        264 :     bool was_in_group = ctx->in_group;
    3578                 :        264 :     ctx->in_group = true;
    3579                 :            : 
    3580   [ +  +  -  - ]:        264 :     switch (group_dpif_get_type(group)) {
    3581                 :            :     case OFPGT11_ALL:
    3582                 :            :     case OFPGT11_INDIRECT:
    3583                 :         14 :         xlate_all_group(ctx, group);
    3584                 :         14 :         break;
    3585                 :            :     case OFPGT11_SELECT:
    3586                 :        250 :         xlate_select_group(ctx, group);
    3587                 :        250 :         break;
    3588                 :            :     case OFPGT11_FF:
    3589                 :          0 :         xlate_ff_group(ctx, group);
    3590                 :          0 :         break;
    3591                 :            :     default:
    3592                 :          0 :         OVS_NOT_REACHED();
    3593                 :            :     }
    3594                 :            : 
    3595                 :        264 :     ctx->in_group = was_in_group;
    3596                 :        264 : }
    3597                 :            : 
    3598                 :            : static bool
    3599                 :        264 : xlate_group_action(struct xlate_ctx *ctx, uint32_t group_id)
    3600                 :            : {
    3601         [ +  - ]:        264 :     if (xlate_resubmit_resource_check(ctx)) {
    3602                 :            :         struct group_dpif *group;
    3603                 :            : 
    3604                 :            :         /* Take ref only if xcache exists. */
    3605                 :        264 :         group = group_dpif_lookup(ctx->xbridge->ofproto, group_id,
    3606                 :        264 :                                   ctx->tables_version, ctx->xin->xcache);
    3607         [ -  + ]:        264 :         if (!group) {
    3608                 :            :             /* XXX: Should set ctx->error ? */
    3609                 :          0 :             return true;
    3610                 :            :         }
    3611                 :        264 :         xlate_group_action__(ctx, group);
    3612                 :            :     }
    3613                 :            : 
    3614                 :        264 :     return false;
    3615                 :            : }
    3616                 :            : 
    3617                 :            : static void
    3618                 :    1177160 : xlate_ofpact_resubmit(struct xlate_ctx *ctx,
    3619                 :            :                       const struct ofpact_resubmit *resubmit)
    3620                 :            : {
    3621                 :            :     ofp_port_t in_port;
    3622                 :            :     uint8_t table_id;
    3623                 :    1177160 :     bool may_packet_in = false;
    3624                 :    1177160 :     bool honor_table_miss = false;
    3625                 :            : 
    3626 [ +  + ][ -  + ]:    1177160 :     if (ctx->rule && rule_dpif_is_internal(ctx->rule)) {
    3627                 :            :         /* Still allow missed packets to be sent to the controller
    3628                 :            :          * if resubmitting from an internal table. */
    3629                 :          0 :         may_packet_in = true;
    3630                 :          0 :         honor_table_miss = true;
    3631                 :            :     }
    3632                 :            : 
    3633                 :    1177159 :     in_port = resubmit->in_port;
    3634         [ +  + ]:    1177159 :     if (in_port == OFPP_IN_PORT) {
    3635                 :    1170926 :         in_port = ctx->xin->flow.in_port.ofp_port;
    3636                 :            :     }
    3637                 :            : 
    3638                 :    1177159 :     table_id = resubmit->table_id;
    3639         [ +  + ]:    1177159 :     if (table_id == 255) {
    3640                 :       6196 :         table_id = ctx->table_id;
    3641                 :            :     }
    3642                 :            : 
    3643                 :    1177159 :     xlate_table_action(ctx, in_port, table_id, may_packet_in,
    3644                 :            :                        honor_table_miss);
    3645                 :    1177160 : }
    3646                 :            : 
    3647                 :            : static void
    3648                 :         34 : flood_packets(struct xlate_ctx *ctx, bool all)
    3649                 :            : {
    3650                 :            :     const struct xport *xport;
    3651                 :            : 
    3652 [ +  + ][ -  + ]:        179 :     HMAP_FOR_EACH (xport, ofp_node, &ctx->xbridge->xports) {
    3653         [ +  + ]:        145 :         if (xport->ofp_port == ctx->xin->flow.in_port.ofp_port) {
    3654                 :         34 :             continue;
    3655                 :            :         }
    3656                 :            : 
    3657         [ +  + ]:        111 :         if (all) {
    3658                 :          7 :             compose_output_action__(ctx, xport->ofp_port, NULL, false);
    3659         [ +  + ]:        104 :         } else if (!(xport->config & OFPUTIL_PC_NO_FLOOD)) {
    3660                 :        102 :             compose_output_action(ctx, xport->ofp_port, NULL);
    3661                 :            :         }
    3662                 :            :     }
    3663                 :            : 
    3664                 :         34 :     ctx->nf_output_iface = NF_OUT_FLOOD;
    3665                 :         34 : }
    3666                 :            : 
    3667                 :            : static void
    3668                 :      26009 : execute_controller_action(struct xlate_ctx *ctx, int len,
    3669                 :            :                           enum ofp_packet_in_reason reason,
    3670                 :            :                           uint16_t controller_id,
    3671                 :            :                           const uint8_t *userdata, size_t userdata_len)
    3672                 :            : {
    3673                 :            :     struct dp_packet_batch batch;
    3674                 :            :     struct dp_packet *packet;
    3675                 :            : 
    3676                 :      26009 :     ctx->xout->slow |= SLOW_CONTROLLER;
    3677                 :      26009 :     xlate_commit_actions(ctx);
    3678         [ +  + ]:      26009 :     if (!ctx->xin->packet) {
    3679                 :      25152 :         return;
    3680                 :            :     }
    3681                 :            : 
    3682                 :        857 :     packet = dp_packet_clone(ctx->xin->packet);
    3683                 :        857 :     packet_batch_init_packet(&batch, packet);
    3684                 :        857 :     odp_execute_actions(NULL, &batch, false,
    3685                 :       1714 :                         ctx->odp_actions->data, ctx->odp_actions->size, NULL);
    3686                 :            : 
    3687                 :            :     /* A packet sent by an action in a table-miss rule is considered an
    3688                 :            :      * explicit table miss.  OpenFlow before 1.3 doesn't have that concept so
    3689                 :            :      * it will get translated back to OFPR_ACTION for those versions. */
    3690         [ +  + ]:        857 :     if (reason == OFPR_ACTION
    3691 [ +  + ][ +  + ]:        767 :         && ctx->rule && rule_dpif_is_table_miss(ctx->rule)) {
    3692                 :         12 :         reason = OFPR_EXPLICIT_MISS;
    3693                 :            :     }
    3694                 :            : 
    3695                 :        857 :     size_t packet_len = dp_packet_size(packet);
    3696                 :            : 
    3697                 :        857 :     struct ofproto_async_msg *am = xmalloc(sizeof *am);
    3698                 :        857 :     *am = (struct ofproto_async_msg) {
    3699                 :            :         .controller_id = controller_id,
    3700                 :            :         .oam = OAM_PACKET_IN,
    3701                 :            :         .pin = {
    3702                 :            :             .up = {
    3703                 :            :                 .public = {
    3704                 :        857 :                     .packet = dp_packet_steal_data(packet),
    3705                 :            :                     .packet_len = packet_len,
    3706                 :            :                     .reason = reason,
    3707                 :        857 :                     .table_id = ctx->table_id,
    3708                 :        857 :                     .cookie = ctx->rule_cookie,
    3709                 :            :                     .userdata = (userdata_len
    3710                 :            :                                  ? xmemdup(userdata, userdata_len)
    3711         [ +  + ]:        857 :                                  : NULL),
    3712                 :            :                     .userdata_len = userdata_len,
    3713                 :            :                 }
    3714                 :            :             },
    3715                 :            :             .max_len = len,
    3716                 :            :         },
    3717                 :            :     };
    3718                 :        857 :     flow_get_metadata(&ctx->xin->flow, &am->pin.up.public.flow_metadata);
    3719                 :            : 
    3720                 :        857 :     ofproto_dpif_send_async_msg(ctx->xbridge->ofproto, am);
    3721                 :        857 :     dp_packet_delete(packet);
    3722                 :            : }
    3723                 :            : 
    3724                 :            : static void
    3725                 :        194 : emit_continuation(struct xlate_ctx *ctx, const struct frozen_state *state)
    3726                 :            : {
    3727                 :        194 :     struct ofproto_async_msg *am = xmalloc(sizeof *am);
    3728                 :        582 :     *am = (struct ofproto_async_msg) {
    3729                 :        194 :         .controller_id = ctx->pause->controller_id,
    3730                 :            :         .oam = OAM_PACKET_IN,
    3731                 :            :         .pin = {
    3732                 :            :             .up = {
    3733                 :            :                 .public = {
    3734                 :        194 :                     .userdata = xmemdup(ctx->pause->userdata,
    3735                 :        194 :                                         ctx->pause->userdata_len),
    3736                 :        194 :                     .userdata_len = ctx->pause->userdata_len,
    3737                 :        194 :                     .packet = xmemdup(dp_packet_data(ctx->xin->packet),
    3738                 :        194 :                                       dp_packet_size(ctx->xin->packet)),
    3739                 :        194 :                     .packet_len = dp_packet_size(ctx->xin->packet),
    3740                 :        194 :                     .reason = ctx->pause->reason,
    3741                 :            :                 },
    3742                 :        194 :                 .bridge = *ofproto_dpif_get_uuid(ctx->xbridge->ofproto),
    3743                 :        194 :                 .stack = xmemdup(state->stack,
    3744                 :        194 :                                  state->n_stack * sizeof *state->stack),
    3745                 :        194 :                 .n_stack = state->n_stack,
    3746                 :        194 :                 .mirrors = state->mirrors,
    3747                 :        194 :                 .conntracked = state->conntracked,
    3748                 :        194 :                 .actions = xmemdup(state->ofpacts, state->ofpacts_len),
    3749                 :        194 :                 .actions_len = state->ofpacts_len,
    3750                 :        194 :                 .action_set = xmemdup(state->action_set,
    3751                 :            :                                       state->action_set_len),
    3752                 :        194 :                 .action_set_len = state->action_set_len,
    3753                 :            :             },
    3754                 :            :             .max_len = UINT16_MAX,
    3755                 :            :         },
    3756                 :            :     };
    3757                 :        194 :     flow_get_metadata(&ctx->xin->flow, &am->pin.up.public.flow_metadata);
    3758                 :        194 :     ofproto_dpif_send_async_msg(ctx->xbridge->ofproto, am);
    3759                 :        194 : }
    3760                 :            : 
    3761                 :            : static void
    3762                 :       1220 : finish_freezing__(struct xlate_ctx *ctx, uint8_t table)
    3763                 :            : {
    3764         [ -  + ]:       1220 :     ovs_assert(ctx->freezing);
    3765                 :            : 
    3766                 :      12200 :     struct frozen_state state = {
    3767                 :            :         .table_id = table,
    3768                 :       1220 :         .ofproto_uuid = *ofproto_dpif_get_uuid(ctx->xbridge->ofproto),
    3769                 :       1220 :         .stack = ctx->stack.data,
    3770                 :       1220 :         .n_stack = ctx->stack.size / sizeof(union mf_subvalue),
    3771                 :       1220 :         .mirrors = ctx->mirrors,
    3772                 :       1220 :         .conntracked = ctx->conntracked,
    3773                 :       1220 :         .ofpacts = ctx->frozen_actions.data,
    3774                 :       1220 :         .ofpacts_len = ctx->frozen_actions.size,
    3775                 :       1220 :         .action_set = ctx->action_set.data,
    3776                 :       1220 :         .action_set_len = ctx->action_set.size,
    3777                 :            :     };
    3778                 :       1220 :     frozen_metadata_from_flow(&state.metadata, &ctx->xin->flow);
    3779                 :            : 
    3780         [ +  + ]:       1220 :     if (ctx->pause) {
    3781         [ +  + ]:        273 :         if (ctx->xin->packet) {
    3782                 :        273 :             emit_continuation(ctx, &state);
    3783                 :            :         }
    3784                 :            :     } else {
    3785                 :            :         /* Allocate a unique recirc id for the given metadata state in the
    3786                 :            :          * flow.  An existing id, with a new reference to the corresponding
    3787                 :            :          * recirculation context, will be returned if possible.
    3788                 :            :          * The life-cycle of this recirc id is managed by associating it
    3789                 :            :          * with the udpif key ('ukey') created for each new datapath flow. */
    3790                 :        947 :         uint32_t id = recirc_alloc_id_ctx(&state);
    3791         [ -  + ]:        947 :         if (!id) {
    3792 [ #  # ][ #  # ]:          0 :             XLATE_REPORT_ERROR(ctx, "Failed to allocate recirculation id");
    3793                 :          0 :             ctx->error = XLATE_NO_RECIRCULATION_CONTEXT;
    3794                 :          0 :             return;
    3795                 :            :         }
    3796                 :        947 :         recirc_refs_add(&ctx->xout->recircs, id);
    3797                 :            : 
    3798                 :        947 :         nl_msg_put_u32(ctx->odp_actions, OVS_ACTION_ATTR_RECIRC, id);
    3799                 :            :     }
    3800                 :            : 
    3801                 :            :     /* Undo changes done by freezing. */
    3802                 :       1220 :     ctx_cancel_freeze(ctx);
    3803                 :            : }
    3804                 :            : 
    3805                 :            : /* Called only when we're freezing. */
    3806                 :            : static void
    3807                 :        317 : finish_freezing(struct xlate_ctx *ctx)
    3808                 :            : {
    3809                 :        317 :     xlate_commit_actions(ctx);
    3810                 :        317 :     finish_freezing__(ctx, 0);
    3811                 :        317 : }
    3812                 :            : 
    3813                 :            : /* Fork the pipeline here. The current packet will continue processing the
    3814                 :            :  * current action list. A clone of the current packet will recirculate, skip
    3815                 :            :  * the remainder of the current action list and asynchronously resume pipeline
    3816                 :            :  * processing in 'table' with the current metadata and action set. */
    3817                 :            : static void
    3818                 :        903 : compose_recirculate_and_fork(struct xlate_ctx *ctx, uint8_t table)
    3819                 :            : {
    3820                 :        903 :     ctx->freezing = true;
    3821                 :        903 :     finish_freezing__(ctx, table);
    3822                 :        903 : }
    3823                 :            : 
    3824                 :            : static void
    3825                 :        124 : compose_mpls_push_action(struct xlate_ctx *ctx, struct ofpact_push_mpls *mpls)
    3826                 :            : {
    3827                 :        124 :     struct flow *flow = &ctx->xin->flow;
    3828                 :            :     int n;
    3829                 :            : 
    3830         [ -  + ]:        124 :     ovs_assert(eth_type_mpls(mpls->ethertype));
    3831                 :            : 
    3832                 :        124 :     n = flow_count_mpls_labels(flow, ctx->wc);
    3833         [ +  + ]:        124 :     if (!n) {
    3834                 :         91 :         xlate_commit_actions(ctx);
    3835         [ -  + ]:         33 :     } else if (n >= FLOW_MAX_MPLS_LABELS) {
    3836         [ #  # ]:          0 :         if (ctx->xin->packet != NULL) {
    3837 [ #  # ][ #  # ]:          0 :             XLATE_REPORT_ERROR(ctx, "bridge %s: dropping packet on which an "
    3838                 :            :                          "MPLS push action can't be performed as it would "
    3839                 :            :                          "have more MPLS LSEs than the %d supported.",
    3840                 :            :                          ctx->xbridge->name, FLOW_MAX_MPLS_LABELS);
    3841                 :            :         }
    3842                 :          0 :         ctx->error = XLATE_TOO_MANY_MPLS_LABELS;
    3843                 :          0 :         return;
    3844                 :            :     }
    3845                 :            : 
    3846                 :        124 :     flow_push_mpls(flow, n, mpls->ethertype, ctx->wc);
    3847                 :            : }
    3848                 :            : 
    3849                 :            : static void
    3850                 :        115 : compose_mpls_pop_action(struct xlate_ctx *ctx, ovs_be16 eth_type)
    3851                 :            : {
    3852                 :        115 :     struct flow *flow = &ctx->xin->flow;
    3853                 :        115 :     int n = flow_count_mpls_labels(flow, ctx->wc);
    3854                 :            : 
    3855         [ +  - ]:        115 :     if (flow_pop_mpls(flow, n, eth_type, ctx->wc)) {
    3856 [ +  + ][ +  - ]:        115 :         if (!eth_type_mpls(eth_type) && ctx->xbridge->support.odp.recirc) {
    3857                 :        115 :             ctx->was_mpls = true;
    3858                 :            :         }
    3859         [ #  # ]:          0 :     } else if (n >= FLOW_MAX_MPLS_LABELS) {
    3860         [ #  # ]:          0 :         if (ctx->xin->packet != NULL) {
    3861 [ #  # ][ #  # ]:          0 :             XLATE_REPORT_ERROR(ctx, "bridge %s: dropping packet on which an "
    3862                 :            :                          "MPLS pop action can't be performed as it has "
    3863                 :            :                          "more MPLS LSEs than the %d supported.",
    3864                 :            :                          ctx->xbridge->name, FLOW_MAX_MPLS_LABELS);
    3865                 :            :         }
    3866                 :          0 :         ctx->error = XLATE_TOO_MANY_MPLS_LABELS;
    3867                 :          0 :         ofpbuf_clear(ctx->odp_actions);
    3868                 :            :     }
    3869                 :        115 : }
    3870                 :            : 
    3871                 :            : static bool
    3872                 :       3777 : compose_dec_ttl(struct xlate_ctx *ctx, struct ofpact_cnt_ids *ids)
    3873                 :            : {
    3874                 :       3777 :     struct flow *flow = &ctx->xin->flow;
    3875                 :            : 
    3876         [ -  + ]:       3777 :     if (!is_ip_any(flow)) {
    3877                 :          0 :         return false;
    3878                 :            :     }
    3879                 :            : 
    3880                 :       3777 :     ctx->wc->masks.nw_ttl = 0xff;
    3881         [ +  + ]:       3777 :     if (flow->nw_ttl > 1) {
    3882                 :       3749 :         flow->nw_ttl--;
    3883                 :       3749 :         return false;
    3884                 :            :     } else {
    3885                 :            :         size_t i;
    3886                 :            : 
    3887         [ +  + ]:         56 :         for (i = 0; i < ids->n_controllers; i++) {
    3888                 :         28 :             execute_controller_action(ctx, UINT16_MAX, OFPR_INVALID_TTL,
    3889                 :         28 :                                       ids->cnt_ids[i], NULL, 0);
    3890                 :            :         }
    3891                 :            : 
    3892                 :            :         /* Stop processing for current table. */
    3893                 :         28 :         return true;
    3894                 :            :     }
    3895                 :            : }
    3896                 :            : 
    3897                 :            : static void
    3898                 :          2 : compose_set_mpls_label_action(struct xlate_ctx *ctx, ovs_be32 label)
    3899                 :            : {
    3900         [ +  - ]:          2 :     if (eth_type_mpls(ctx->xin->flow.dl_type)) {
    3901                 :          2 :         ctx->wc->masks.mpls_lse[0] |= htonl(MPLS_LABEL_MASK);
    3902                 :          2 :         set_mpls_lse_label(&ctx->xin->flow.mpls_lse[0], label);
    3903                 :            :     }
    3904                 :          2 : }
    3905                 :            : 
    3906                 :            : static void
    3907                 :          2 : compose_set_mpls_tc_action(struct xlate_ctx *ctx, uint8_t tc)
    3908                 :            : {
    3909         [ +  - ]:          2 :     if (eth_type_mpls(ctx->xin->flow.dl_type)) {
    3910                 :          2 :         ctx->wc->masks.mpls_lse[0] |= htonl(MPLS_TC_MASK);
    3911                 :          2 :         set_mpls_lse_tc(&ctx->xin->flow.mpls_lse[0], tc);
    3912                 :            :     }
    3913                 :          2 : }
    3914                 :            : 
    3915                 :            : static void
    3916                 :         14 : compose_set_mpls_ttl_action(struct xlate_ctx *ctx, uint8_t ttl)
    3917                 :            : {
    3918         [ +  - ]:         14 :     if (eth_type_mpls(ctx->xin->flow.dl_type)) {
    3919                 :         14 :         ctx->wc->masks.mpls_lse[0] |= htonl(MPLS_TTL_MASK);
    3920                 :         14 :         set_mpls_lse_ttl(&ctx->xin->flow.mpls_lse[0], ttl);
    3921                 :            :     }
    3922                 :         14 : }
    3923                 :            : 
    3924                 :            : static bool
    3925                 :         50 : compose_dec_mpls_ttl_action(struct xlate_ctx *ctx)
    3926                 :            : {
    3927                 :         50 :     struct flow *flow = &ctx->xin->flow;
    3928                 :            : 
    3929         [ +  - ]:         50 :     if (eth_type_mpls(flow->dl_type)) {
    3930                 :         50 :         uint8_t ttl = mpls_lse_to_ttl(flow->mpls_lse[0]);
    3931                 :            : 
    3932                 :         50 :         ctx->wc->masks.mpls_lse[0] |= htonl(MPLS_TTL_MASK);
    3933         [ +  - ]:         50 :         if (ttl > 1) {
    3934                 :         50 :             ttl--;
    3935                 :         50 :             set_mpls_lse_ttl(&flow->mpls_lse[0], ttl);
    3936                 :         50 :             return false;
    3937                 :            :         } else {
    3938                 :          0 :             execute_controller_action(ctx, UINT16_MAX, OFPR_INVALID_TTL, 0,
    3939                 :            :                                       NULL, 0);
    3940                 :            :         }
    3941                 :            :     }
    3942                 :            : 
    3943                 :            :     /* Stop processing for current table. */
    3944                 :          0 :     return true;
    3945                 :            : }
    3946                 :            : 
    3947                 :            : static void
    3948                 :     110084 : xlate_output_action(struct xlate_ctx *ctx,
    3949                 :            :                     ofp_port_t port, uint16_t max_len, bool may_packet_in)
    3950                 :            : {
    3951                 :     110084 :     ofp_port_t prev_nf_output_iface = ctx->nf_output_iface;
    3952                 :            : 
    3953                 :     110084 :     ctx->nf_output_iface = NF_OUT_DROP;
    3954                 :            : 
    3955   [ +  +  +  +  :     110084 :     switch (port) {
             +  +  -  + ]
    3956                 :            :     case OFPP_IN_PORT:
    3957                 :          8 :         compose_output_action(ctx, ctx->xin->flow.in_port.ofp_port, NULL);
    3958                 :          8 :         break;
    3959                 :            :     case OFPP_TABLE:
    3960                 :         11 :         xlate_table_action(ctx, ctx->xin->flow.in_port.ofp_port,
    3961                 :            :                            0, may_packet_in, true);
    3962                 :         11 :         break;
    3963                 :            :     case OFPP_NORMAL:
    3964                 :      30464 :         xlate_normal(ctx);
    3965                 :      30464 :         break;
    3966                 :            :     case OFPP_FLOOD:
    3967                 :         33 :         flood_packets(ctx,  false);
    3968                 :         33 :         break;
    3969                 :            :     case OFPP_ALL:
    3970                 :          1 :         flood_packets(ctx, true);
    3971                 :          1 :         break;
    3972                 :            :     case OFPP_CONTROLLER:
    3973 [ +  + ][ +  + ]:        409 :         execute_controller_action(ctx, max_len,
    3974                 :        409 :                                   (ctx->in_group ? OFPR_GROUP
    3975                 :        401 :                                    : ctx->in_action_set ? OFPR_ACTION_SET
    3976                 :            :                                    : OFPR_ACTION),
    3977                 :            :                                   0, NULL, 0);
    3978                 :        409 :         break;
    3979                 :            :     case OFPP_NONE:
    3980                 :          0 :         break;
    3981                 :            :     case OFPP_LOCAL:
    3982                 :            :     default:
    3983         [ +  + ]:      79158 :         if (port != ctx->xin->flow.in_port.ofp_port) {
    3984                 :      79118 :             compose_output_action(ctx, port, NULL);
    3985                 :            :         } else {
    3986                 :         40 :             xlate_report(ctx, "skipping output to input port");
    3987                 :            :         }
    3988                 :      79158 :         break;
    3989                 :            :     }
    3990                 :            : 
    3991         [ -  + ]:     110084 :     if (prev_nf_output_iface == NF_OUT_FLOOD) {
    3992                 :          0 :         ctx->nf_output_iface = NF_OUT_FLOOD;
    3993         [ +  + ]:     110084 :     } else if (ctx->nf_output_iface == NF_OUT_DROP) {
    3994                 :      44455 :         ctx->nf_output_iface = prev_nf_output_iface;
    3995 [ +  + ][ +  + ]:      65629 :     } else if (prev_nf_output_iface != NF_OUT_DROP &&
    3996                 :      25457 :                ctx->nf_output_iface != NF_OUT_FLOOD) {
    3997                 :      25450 :         ctx->nf_output_iface = NF_OUT_MULTI;
    3998                 :            :     }
    3999                 :     110084 : }
    4000                 :            : 
    4001                 :            : static void
    4002                 :         57 : xlate_output_reg_action(struct xlate_ctx *ctx,
    4003                 :            :                         const struct ofpact_output_reg *or)
    4004                 :            : {
    4005                 :         57 :     uint64_t port = mf_get_subfield(&or->src, &ctx->xin->flow);
    4006         [ +  + ]:         57 :     if (port <= UINT16_MAX) {
    4007                 :            :         union mf_subvalue value;
    4008                 :            : 
    4009                 :         56 :         memset(&value, 0xff, sizeof value);
    4010                 :         56 :         mf_write_subfield_flow(&or->src, &value, &ctx->wc->masks);
    4011                 :         56 :         xlate_output_action(ctx, u16_to_ofp(port),
    4012                 :         56 :                             or->max_len, false);
    4013                 :            :     }
    4014                 :         57 : }
    4015                 :            : 
    4016                 :            : static void
    4017                 :        122 : xlate_output_trunc_action(struct xlate_ctx *ctx,
    4018                 :            :                     ofp_port_t port, uint32_t max_len)
    4019                 :            : {
    4020                 :        122 :     bool support_trunc = ctx->xbridge->support.trunc;
    4021                 :            :     struct ovs_action_trunc *trunc;
    4022                 :            :     char name[OFP_MAX_PORT_NAME_LEN];
    4023                 :            : 
    4024         [ -  + ]:        122 :     switch (port) {
    4025                 :            :     case OFPP_TABLE:
    4026                 :            :     case OFPP_NORMAL:
    4027                 :            :     case OFPP_FLOOD:
    4028                 :            :     case OFPP_ALL:
    4029                 :            :     case OFPP_CONTROLLER:
    4030                 :            :     case OFPP_NONE:
    4031                 :          0 :         ofputil_port_to_string(port, name, sizeof name);
    4032                 :          0 :         xlate_report(ctx, "output_trunc does not support port: %s", name);
    4033                 :          0 :         break;
    4034                 :            :     case OFPP_LOCAL:
    4035                 :            :     case OFPP_IN_PORT:
    4036                 :            :     default:
    4037         [ +  - ]:        122 :         if (port != ctx->xin->flow.in_port.ofp_port) {
    4038                 :        122 :             const struct xport *xport = get_ofp_port(ctx->xbridge, port);
    4039                 :            : 
    4040 [ +  - ][ +  + ]:        122 :             if (xport == NULL || xport->odp_port == ODPP_NONE) {
    4041                 :            :                 /* Since truncate happens at its following output action, if
    4042                 :            :                  * the output port is a patch port, the behavior is somehow
    4043                 :            :                  * unpredicable. For simpilicity, disallow this case. */
    4044                 :          1 :                 ofputil_port_to_string(port, name, sizeof name);
    4045 [ +  - ][ #  # ]:          1 :                 XLATE_REPORT_ERROR(ctx, "bridge %s: "
    4046                 :            :                          "output_trunc does not support port: %s",
    4047                 :            :                          ctx->xbridge->name, name);
    4048                 :          1 :                 break;
    4049                 :            :             }
    4050                 :            : 
    4051                 :        121 :             trunc = nl_msg_put_unspec_uninit(ctx->odp_actions,
    4052                 :            :                                 OVS_ACTION_ATTR_TRUNC,
    4053                 :            :                                 sizeof *trunc);
    4054                 :        121 :             trunc->max_len = max_len;
    4055                 :        121 :             xlate_output_action(ctx, port, max_len, false);
    4056         [ +  + ]:        121 :             if (!support_trunc) {
    4057                 :        121 :                 ctx->xout->slow |= SLOW_ACTION;
    4058                 :            :             }
    4059                 :            :         } else {
    4060                 :          0 :             xlate_report(ctx, "skipping output to input port");
    4061                 :            :         }
    4062                 :        121 :         break;
    4063                 :            :     }
    4064                 :        122 : }
    4065                 :            : 
    4066                 :            : static void
    4067                 :         12 : xlate_enqueue_action(struct xlate_ctx *ctx,
    4068                 :            :                      const struct ofpact_enqueue *enqueue)
    4069                 :            : {
    4070                 :         12 :     ofp_port_t ofp_port = enqueue->port;
    4071                 :         12 :     uint32_t queue_id = enqueue->queue;
    4072                 :            :     uint32_t flow_priority, priority;
    4073                 :            :     int error;
    4074                 :            : 
    4075                 :            :     /* Translate queue to priority. */
    4076                 :         12 :     error = dpif_queue_to_priority(ctx->xbridge->dpif, queue_id, &priority);
    4077         [ -  + ]:         12 :     if (error) {
    4078                 :            :         /* Fall back to ordinary output action. */
    4079                 :          0 :         xlate_output_action(ctx, enqueue->port, 0, false);
    4080                 :          1 :         return;
    4081                 :            :     }
    4082                 :            : 
    4083                 :            :     /* Check output port. */
    4084         [ -  + ]:         12 :     if (ofp_port == OFPP_IN_PORT) {
    4085                 :          0 :         ofp_port = ctx->xin->flow.in_port.ofp_port;
    4086         [ +  + ]:         12 :     } else if (ofp_port == ctx->xin->flow.in_port.ofp_port) {
    4087                 :          1 :         return;
    4088                 :            :     }
    4089                 :            : 
    4090                 :            :     /* Add datapath actions. */
    4091                 :         11 :     flow_priority = ctx->xin->flow.skb_priority;
    4092                 :         11 :     ctx->xin->flow.skb_priority = priority;
    4093                 :         11 :     compose_output_action(ctx, ofp_port, NULL);
    4094                 :         11 :     ctx->xin->flow.skb_priority = flow_priority;
    4095                 :            : 
    4096                 :            :     /* Update NetFlow output port. */
    4097         [ -  + ]:         11 :     if (ctx->nf_output_iface == NF_OUT_DROP) {
    4098                 :          0 :         ctx->nf_output_iface = ofp_port;
    4099         [ +  - ]:         11 :     } else if (ctx->nf_output_iface != NF_OUT_FLOOD) {
    4100                 :         11 :         ctx->nf_output_iface = NF_OUT_MULTI;
    4101                 :            :     }
    4102                 :            : }
    4103                 :            : 
    4104                 :            : static void
    4105                 :          0 : xlate_set_queue_action(struct xlate_ctx *ctx, uint32_t queue_id)
    4106                 :            : {
    4107                 :            :     uint32_t skb_priority;
    4108                 :            : 
    4109         [ #  # ]:          0 :     if (!dpif_queue_to_priority(ctx->xbridge->dpif, queue_id, &skb_priority)) {
    4110                 :          0 :         ctx->xin->flow.skb_priority = skb_priority;
    4111                 :            :     } else {
    4112                 :            :         /* Couldn't translate queue to a priority.  Nothing to do.  A warning
    4113                 :            :          * has already been logged. */
    4114                 :            :     }
    4115                 :          0 : }
    4116                 :            : 
    4117                 :            : static bool
    4118                 :          8 : slave_enabled_cb(ofp_port_t ofp_port, void *xbridge_)
    4119                 :            : {
    4120                 :          8 :     const struct xbridge *xbridge = xbridge_;
    4121                 :            :     struct xport *port;
    4122                 :            : 
    4123      [ -  -  + ]:          8 :     switch (ofp_port) {
    4124                 :            :     case OFPP_IN_PORT:
    4125                 :            :     case OFPP_TABLE:
    4126                 :            :     case OFPP_NORMAL:
    4127                 :            :     case OFPP_FLOOD:
    4128                 :            :     case OFPP_ALL:
    4129                 :            :     case OFPP_NONE:
    4130                 :          0 :         return true;
    4131                 :            :     case OFPP_CONTROLLER: /* Not supported by the bundle action. */
    4132                 :          0 :         return false;
    4133                 :            :     default:
    4134                 :          8 :         port = get_ofp_port(xbridge, ofp_port);
    4135 [ +  + ][ -  + ]:          8 :         return port ? port->may_enable : false;
    4136                 :            :     }
    4137                 :            : }
    4138                 :            : 
    4139                 :            : static void
    4140                 :          4 : xlate_bundle_action(struct xlate_ctx *ctx,
    4141                 :            :                     const struct ofpact_bundle *bundle)
    4142                 :            : {
    4143                 :            :     ofp_port_t port;
    4144                 :            : 
    4145                 :          4 :     port = bundle_execute(bundle, &ctx->xin->flow, ctx->wc, slave_enabled_cb,
    4146                 :          4 :                           CONST_CAST(struct xbridge *, ctx->xbridge));
    4147         [ +  - ]:          4 :     if (bundle->dst.field) {
    4148                 :          4 :         nxm_reg_load(&bundle->dst, ofp_to_u16(port), &ctx->xin->flow, ctx->wc);
    4149                 :            :     } else {
    4150                 :          0 :         xlate_output_action(ctx, port, 0, false);
    4151                 :            :     }
    4152                 :          4 : }
    4153                 :            : 
    4154                 :            : static void
    4155                 :         58 : xlate_learn_action__(struct xlate_ctx *ctx, const struct ofpact_learn *learn,
    4156                 :            :                      struct ofputil_flow_mod *fm, struct ofpbuf *ofpacts)
    4157                 :            : {
    4158                 :         58 :     learn_execute(learn, &ctx->xin->flow, fm, ofpacts);
    4159         [ +  + ]:         58 :     if (ctx->xin->may_learn) {
    4160                 :         48 :         ofproto_dpif_flow_mod(ctx->xbridge->ofproto, fm);
    4161                 :            :     }
    4162                 :         58 : }
    4163                 :            : 
    4164                 :            : static void
    4165                 :         58 : xlate_learn_action(struct xlate_ctx *ctx, const struct ofpact_learn *learn)
    4166                 :            : {
    4167                 :         58 :     learn_mask(learn, ctx->wc);
    4168                 :            : 
    4169         [ +  + ]:         58 :     if (ctx->xin->xcache) {
    4170                 :            :         struct xc_entry *entry;
    4171                 :            : 
    4172                 :         11 :         entry = xlate_cache_add_entry(ctx->xin->xcache, XC_LEARN);
    4173                 :         11 :         entry->u.learn.ofproto = ctx->xbridge->ofproto;
    4174                 :         11 :         entry->u.learn.fm = xmalloc(sizeof *entry->u.learn.fm);
    4175                 :         11 :         entry->u.learn.ofpacts = ofpbuf_new(64);
    4176                 :         11 :         xlate_learn_action__(ctx, learn, entry->u.learn.fm,
    4177                 :            :                              entry->u.learn.ofpacts);
    4178         [ +  - ]:         47 :     } else if (ctx->xin->may_learn) {
    4179                 :            :         uint64_t ofpacts_stub[1024 / 8];
    4180                 :            :         struct ofputil_flow_mod fm;
    4181                 :            :         struct ofpbuf ofpacts;
    4182                 :            : 
    4183                 :         47 :         ofpbuf_use_stub(&ofpacts, ofpacts_stub, sizeof ofpacts_stub);
    4184                 :         47 :         xlate_learn_action__(ctx, learn, &fm, &ofpacts);
    4185                 :         47 :         ofpbuf_uninit(&ofpacts);
    4186                 :            :     }
    4187                 :         58 : }
    4188                 :            : 
    4189                 :            : static void
    4190                 :          2 : xlate_fin_timeout__(struct rule_dpif *rule, uint16_t tcp_flags,
    4191                 :            :                     uint16_t idle_timeout, uint16_t hard_timeout)
    4192                 :            : {
    4193         [ +  + ]:          2 :     if (tcp_flags & (TCP_FIN | TCP_RST)) {
    4194                 :          1 :         rule_dpif_reduce_timeouts(rule, idle_timeout, hard_timeout);
    4195                 :            :     }
    4196                 :          2 : }
    4197                 :            : 
    4198                 :            : static void
    4199                 :          2 : xlate_fin_timeout(struct xlate_ctx *ctx,
    4200                 :            :                   const struct ofpact_fin_timeout *oft)
    4201                 :            : {
    4202         [ +  - ]:          2 :     if (ctx->rule) {
    4203                 :          2 :         xlate_fin_timeout__(ctx->rule, ctx->xin->tcp_flags,
    4204                 :          4 :                             oft->fin_idle_timeout, oft->fin_hard_timeout);
    4205         [ -  + ]:          2 :         if (ctx->xin->xcache) {
    4206                 :            :             struct xc_entry *entry;
    4207                 :            : 
    4208                 :          0 :             entry = xlate_cache_add_entry(ctx->xin->xcache, XC_FIN_TIMEOUT);
    4209                 :            :             /* XC_RULE already holds a reference on the rule, none is taken
    4210                 :            :              * here. */
    4211                 :          0 :             entry->u.fin.rule = ctx->rule;
    4212                 :          0 :             entry->u.fin.idle = oft->fin_idle_timeout;
    4213                 :          0 :             entry->u.fin.hard = oft->fin_hard_timeout;
    4214                 :            :         }
    4215                 :            :     }
    4216                 :          2 : }
    4217                 :            : 
    4218                 :            : static void
    4219                 :          7 : xlate_sample_action(struct xlate_ctx *ctx,
    4220                 :            :                     const struct ofpact_sample *os)
    4221                 :            : {
    4222                 :          7 :     odp_port_t output_odp_port = ODPP_NONE;
    4223                 :          7 :     odp_port_t tunnel_out_port = ODPP_NONE;
    4224                 :          7 :     struct dpif_ipfix *ipfix = ctx->xbridge->ipfix;
    4225                 :          7 :     bool emit_set_tunnel = false;
    4226                 :            : 
    4227 [ +  - ][ -  + ]:          7 :     if (!ipfix || ctx->xin->flow.in_port.ofp_port == OFPP_NONE) {
    4228                 :          0 :         return;
    4229                 :            :     }
    4230                 :            : 
    4231                 :            :     /* Scale the probability from 16-bit to 32-bit while representing
    4232                 :            :      * the same percentage. */
    4233                 :          7 :     uint32_t probability = (os->probability << 16) | os->probability;
    4234                 :            : 
    4235         [ -  + ]:          7 :     if (!ctx->xbridge->support.variable_length_userdata) {
    4236                 :            :         static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
    4237                 :            : 
    4238         [ #  # ]:          0 :         VLOG_ERR_RL(&rl, "ignoring NXAST_SAMPLE action because datapath "
    4239                 :            :                     "lacks support (needs Linux 3.10+ or kernel module from "
    4240                 :            :                     "OVS 1.11+)");
    4241                 :          0 :         return;
    4242                 :            :     }
    4243                 :            : 
    4244                 :            :     /* If ofp_port in flow sample action is equel to ofp_port,
    4245                 :            :      * this sample action is a input port action. */
    4246 [ +  + ][ +  - ]:          7 :     if (os->sampling_port != OFPP_NONE &&
    4247                 :          3 :         os->sampling_port != ctx->xin->flow.in_port.ofp_port) {
    4248                 :          3 :         output_odp_port = ofp_port_to_odp_port(ctx->xbridge,
    4249                 :            :                                                os->sampling_port);
    4250         [ -  + ]:          3 :         if (output_odp_port == ODPP_NONE) {
    4251                 :            :             static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
    4252         [ #  # ]:          0 :             VLOG_WARN_RL(&rl, "can't use unknown port %d in flow sample "
    4253                 :            :                          "action", os->sampling_port);
    4254                 :          0 :             return;
    4255                 :            :         }
    4256                 :            : 
    4257         [ +  - ]:          3 :         if (dpif_ipfix_get_flow_exporter_tunnel_sampling(ipfix,
    4258                 :            :                                                          os->collector_set_id)
    4259         [ +  - ]:          3 :             && dpif_ipfix_get_tunnel_port(ipfix, output_odp_port)) {
    4260                 :          3 :             tunnel_out_port = output_odp_port;
    4261                 :          3 :             emit_set_tunnel = true;
    4262                 :            :         }
    4263                 :            :     }
    4264                 :            : 
    4265                 :          7 :      xlate_commit_actions(ctx);
    4266                 :            :     /* If 'emit_set_tunnel', sample(sampling_port=1) would translate
    4267                 :            :      * into datapath sample action set(tunnel(...)), sample(...) and
    4268                 :            :      * it is used for sampling egress tunnel information. */
    4269         [ +  + ]:          7 :     if (emit_set_tunnel) {
    4270                 :          3 :         const struct xport *xport = get_ofp_port(ctx->xbridge,
    4271                 :            :                                                  os->sampling_port);
    4272                 :            : 
    4273 [ +  - ][ +  - ]:          6 :         if (xport && xport->is_tunnel) {
    4274                 :          3 :             struct flow *flow = &ctx->xin->flow;
    4275                 :          3 :             tnl_port_send(xport->ofport, flow, ctx->wc);
    4276         [ +  - ]:          3 :             if (!ovs_native_tunneling_is_on(ctx->xbridge->ofproto)) {
    4277                 :          3 :                 struct flow_tnl flow_tnl = flow->tunnel;
    4278                 :            : 
    4279                 :          3 :                 commit_odp_tunnel_action(flow, &ctx->base_flow,
    4280                 :            :                                          ctx->odp_actions);
    4281                 :          3 :                 flow->tunnel = flow_tnl;
    4282                 :            :             }
    4283                 :            :         } else {
    4284                 :            :             static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
    4285         [ #  # ]:          0 :             VLOG_WARN_RL(&rl, "sampling_port:%d should be a tunnel port.",
    4286                 :            :                          os->sampling_port);
    4287                 :            :         }
    4288                 :            :     }
    4289                 :            : 
    4290                 :         35 :     union user_action_cookie cookie = {
    4291                 :            :         .flow_sample = {
    4292                 :            :             .type = USER_ACTION_COOKIE_FLOW_SAMPLE,
    4293                 :          7 :             .probability = os->probability,
    4294                 :          7 :             .collector_set_id = os->collector_set_id,
    4295                 :          7 :             .obs_domain_id = os->obs_domain_id,
    4296                 :          7 :             .obs_point_id = os->obs_point_id,
    4297                 :            :             .output_odp_port = output_odp_port,
    4298                 :            :         }
    4299                 :            :     };
    4300                 :          7 :     compose_sample_action(ctx, probability, &cookie, sizeof cookie.flow_sample,
    4301                 :            :                           tunnel_out_port, false);
    4302                 :            : }
    4303                 :            : 
    4304                 :            : static bool
    4305                 :     109438 : may_receive(const struct xport *xport, struct xlate_ctx *ctx)
    4306                 :            : {
    4307 [ +  + ][ -  + ]:     109438 :     if (xport->config & (is_stp(&ctx->xin->flow)
    4308                 :            :                          ? OFPUTIL_PC_NO_RECV_STP
    4309                 :            :                          : OFPUTIL_PC_NO_RECV)) {
    4310                 :          0 :         return false;
    4311                 :            :     }
    4312                 :            : 
    4313                 :            :     /* Only drop packets here if both forwarding and learning are
    4314                 :            :      * disabled.  If just learning is enabled, we need to have
    4315                 :            :      * OFPP_NORMAL and the learning action have a look at the packet
    4316                 :            :      * before we can drop it. */
    4317         [ -  + ]:     218876 :     if ((!xport_stp_forward_state(xport) && !xport_stp_learn_state(xport)) ||
           [ #  #  -  + ]
    4318         [ #  # ]:     109438 :         (!xport_rstp_forward_state(xport) && !xport_rstp_learn_state(xport))) {
    4319                 :          0 :         return false;
    4320                 :            :     }
    4321                 :            : 
    4322                 :     109438 :     return true;
    4323                 :            : }
    4324                 :            : 
    4325                 :            : static void
    4326                 :         23 : xlate_write_actions__(struct xlate_ctx *ctx,
    4327                 :            :                       const struct ofpact *ofpacts, size_t ofpacts_len)
    4328                 :            : {
    4329                 :            :     /* Maintain actset_output depending on the contents of the action set:
    4330                 :            :      *
    4331                 :            :      *   - OFPP_UNSET, if there is no "output" action.
    4332                 :            :      *
    4333                 :            :      *   - The output port, if there is an "output" action and no "group"
    4334                 :            :      *     action.
    4335                 :            :      *
    4336                 :            :      *   - OFPP_UNSET, if there is a "group" action.
    4337                 :            :      */
    4338         [ +  - ]:         23 :     if (!ctx->action_set_has_group) {
    4339                 :            :         const struct ofpact *a;
    4340         [ +  + ]:         54 :         OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
    4341         [ +  + ]:         31 :             if (a->type == OFPACT_OUTPUT) {
    4342                 :         23 :                 ctx->xin->flow.actset_output = ofpact_get_OUTPUT(a)->port;
    4343         [ -  + ]:          8 :             } else if (a->type == OFPACT_GROUP) {
    4344                 :          0 :                 ctx->xin->flow.actset_output = OFPP_UNSET;
    4345                 :          0 :                 ctx->action_set_has_group = true;
    4346                 :          0 :                 break;
    4347                 :            :             }
    4348                 :            :         }
    4349                 :            :     }
    4350                 :            : 
    4351                 :         23 :     ofpbuf_put(&ctx->action_set, ofpacts, ofpacts_len);
    4352                 :         23 : }
    4353                 :            : 
    4354                 :            : static void
    4355                 :         21 : xlate_write_actions(struct xlate_ctx *ctx, const struct ofpact_nest *a)
    4356                 :            : {
    4357                 :         21 :     xlate_write_actions__(ctx, a->actions, ofpact_nest_get_action_len(a));
    4358                 :         21 : }
    4359                 :            : 
    4360                 :            : static void
    4361                 :     117330 : xlate_action_set(struct xlate_ctx *ctx)
    4362                 :            : {
    4363                 :            :     uint64_t action_list_stub[1024 / 64];
    4364                 :            :     struct ofpbuf action_list;
    4365                 :            : 
    4366                 :     117330 :     ctx->in_action_set = true;
    4367                 :     117330 :     ofpbuf_use_stub(&action_list, action_list_stub, sizeof action_list_stub);
    4368                 :     117330 :     ofpacts_execute_action_set(&action_list, &ctx->action_set);
    4369                 :            :     /* Clear the action set, as it is not needed any more. */
    4370                 :     117330 :     ofpbuf_clear(&ctx->action_set);
    4371                 :     117330 :     do_xlate_actions(action_list.data, action_list.size, ctx);
    4372                 :     117330 :     ctx->in_action_set = false;
    4373                 :     117330 :     ofpbuf_uninit(&action_list);
    4374                 :     117330 : }
    4375                 :            : 
    4376                 :            : static void
    4377                 :       1394 : freeze_put_unroll_xlate(struct xlate_ctx *ctx)
    4378                 :            : {
    4379                 :       1394 :     struct ofpact_unroll_xlate *unroll = ctx->frozen_actions.header;
    4380                 :            : 
    4381                 :            :     /* Restore the table_id and rule cookie for a potential PACKET
    4382                 :            :      * IN if needed. */
    4383 [ +  + ][ +  + ]:       1394 :     if (!unroll ||
    4384                 :       1124 :         (ctx->table_id != unroll->rule_table_id
    4385         [ -  + ]:       1013 :          || ctx->rule_cookie != unroll->rule_cookie)) {
    4386                 :        381 :         unroll = ofpact_put_UNROLL_XLATE(&ctx->frozen_actions);
    4387                 :        381 :         unroll->rule_table_id = ctx->table_id;
    4388                 :        381 :         unroll->rule_cookie = ctx->rule_cookie;
    4389                 :        381 :         ctx->frozen_actions.header = unroll;
    4390                 :            :     }
    4391                 :       1394 : }
    4392                 :            : 
    4393                 :            : 
    4394                 :            : /* Copy actions 'a' through 'end' to ctx->frozen_actions, which will be
    4395                 :            :  * executed after thawing.  Inserts an UNROLL_XLATE action, if none is already
    4396                 :            :  * present, before any action that may depend on the current table ID or flow
    4397                 :            :  * cookie. */
    4398                 :            : static void
    4399                 :        457 : freeze_unroll_actions(const struct ofpact *a, const struct ofpact *end,
    4400                 :            :                       struct xlate_ctx *ctx)
    4401                 :            : {
    4402         [ +  + ]:       2220 :     for (; a < end; a = ofpact_next(a)) {
    4403   [ +  +  +  -  :       1763 :         switch (a->type) {
                      - ]
    4404                 :            :         case OFPACT_OUTPUT_REG:
    4405                 :            :         case OFPACT_OUTPUT_TRUNC:
    4406                 :            :         case OFPACT_GROUP:
    4407                 :            :         case OFPACT_OUTPUT:
    4408                 :            :         case OFPACT_CONTROLLER:
    4409                 :            :         case OFPACT_DEC_MPLS_TTL:
    4410                 :            :         case OFPACT_DEC_TTL:
    4411                 :            :             /* These actions may generate asynchronous messages, which include
    4412                 :            :              * table ID and flow cookie information. */
    4413                 :       1366 :             freeze_put_unroll_xlate(ctx);
    4414                 :       1366 :             break;
    4415                 :            : 
    4416                 :            :         case OFPACT_RESUBMIT:
    4417         [ +  + ]:         90 :             if (ofpact_get_RESUBMIT(a)->table_id == 0xff) {
    4418                 :            :                 /* This resubmit action is relative to the current table, so we
    4419                 :            :                  * need to track what table that is.*/
    4420                 :         28 :                 freeze_put_unroll_xlate(ctx);
    4421                 :            :             }
    4422                 :         90 :             break;
    4423                 :            : 
    4424                 :            :         case OFPACT_SET_TUNNEL:
    4425                 :            :         case OFPACT_REG_MOVE:
    4426                 :            :         case OFPACT_SET_FIELD:
    4427                 :            :         case OFPACT_STACK_PUSH:
    4428                 :            :         case OFPACT_STACK_POP:
    4429                 :            :         case OFPACT_LEARN:
    4430                 :            :         case OFPACT_WRITE_METADATA:
    4431                 :            :         case OFPACT_GOTO_TABLE:
    4432                 :            :         case OFPACT_ENQUEUE:
    4433                 :            :         case OFPACT_SET_VLAN_VID:
    4434                 :            :         case OFPACT_SET_VLAN_PCP:
    4435                 :            :         case OFPACT_STRIP_VLAN:
    4436                 :            :         case OFPACT_PUSH_VLAN:
    4437                 :            :         case OFPACT_SET_ETH_SRC:
    4438                 :            :         case OFPACT_SET_ETH_DST:
    4439                 :            :         case OFPACT_SET_IPV4_SRC:
    4440                 :            :         case OFPACT_SET_IPV4_DST:
    4441                 :            :         case OFPACT_SET_IP_DSCP:
    4442                 :            :         case OFPACT_SET_IP_ECN:
    4443                 :            :         case OFPACT_SET_IP_TTL:
    4444                 :            :         case OFPACT_SET_L4_SRC_PORT:
    4445                 :            :         case OFPACT_SET_L4_DST_PORT:
    4446                 :            :         case OFPACT_SET_QUEUE:
    4447                 :            :         case OFPACT_POP_QUEUE:
    4448                 :            :         case OFPACT_PUSH_MPLS:
    4449                 :            :         case OFPACT_POP_MPLS:
    4450                 :            :         case OFPACT_SET_MPLS_LABEL:
    4451                 :            :         case OFPACT_SET_MPLS_TC:
    4452                 :            :         case OFPACT_SET_MPLS_TTL:
    4453                 :            :         case OFPACT_MULTIPATH:
    4454                 :            :         case OFPACT_BUNDLE:
    4455                 :            :         case OFPACT_EXIT:
    4456                 :            :         case OFPACT_UNROLL_XLATE:
    4457                 :            :         case OFPACT_FIN_TIMEOUT:
    4458                 :            :         case OFPACT_CLEAR_ACTIONS:
    4459                 :            :         case OFPACT_WRITE_ACTIONS:
    4460                 :            :         case OFPACT_METER:
    4461                 :            :         case OFPACT_SAMPLE:
    4462                 :            :         case OFPACT_DEBUG_RECIRC:
    4463                 :            :         case OFPACT_CT:
    4464                 :            :         case OFPACT_NAT:
    4465                 :            :             /* These may not generate PACKET INs. */
    4466                 :        307 :             break;
    4467                 :            : 
    4468                 :            :         case OFPACT_NOTE:
    4469                 :            :         case OFPACT_CONJUNCTION:
    4470                 :            :             /* These need not be copied for restoration. */
    4471                 :          0 :             continue;
    4472                 :            :         }
    4473                 :            :         /* Copy the action over. */
    4474                 :       1763 :         ofpbuf_put(&ctx->frozen_actions, a, OFPACT_ALIGN(a->len));
    4475                 :            :     }
    4476                 :        457 : }
    4477                 :            : 
    4478                 :            : static void
    4479                 :       1219 : put_ct_mark(const struct flow *flow, struct ofpbuf *odp_actions,
    4480                 :            :             struct flow_wildcards *wc)
    4481                 :            : {
    4482         [ +  + ]:       1219 :     if (wc->masks.ct_mark) {
    4483                 :            :         struct {
    4484                 :            :             uint32_t key;
    4485                 :            :             uint32_t mask;
    4486                 :            :         } *odp_ct_mark;
    4487                 :            : 
    4488                 :         54 :         odp_ct_mark = nl_msg_put_unspec_uninit(odp_actions, OVS_CT_ATTR_MARK,
    4489                 :            :                                                sizeof(*odp_ct_mark));
    4490                 :         54 :         odp_ct_mark->key = flow->ct_mark & wc->masks.ct_mark;
    4491                 :         54 :         odp_ct_mark->mask = wc->masks.ct_mark;
    4492                 :            :     }
    4493                 :       1219 : }
    4494                 :            : 
    4495                 :            : static void
    4496                 :       1219 : put_ct_label(const struct flow *flow, struct ofpbuf *odp_actions,
    4497                 :            :              struct flow_wildcards *wc)
    4498                 :            : {
    4499         [ +  + ]:       1219 :     if (!ovs_u128_is_zero(wc->masks.ct_label)) {
    4500                 :            :         struct {
    4501                 :            :             ovs_u128 key;
    4502                 :            :             ovs_u128 mask;
    4503                 :            :         } *odp_ct_label;
    4504                 :            : 
    4505                 :         36 :         odp_ct_label = nl_msg_put_unspec_uninit(odp_actions,
    4506                 :            :                                                 OVS_CT_ATTR_LABELS,
    4507                 :            :                                                 sizeof(*odp_ct_label));
    4508                 :         36 :         odp_ct_label->key = ovs_u128_and(flow->ct_label, wc->masks.ct_label);
    4509                 :         36 :         odp_ct_label->mask = wc->masks.ct_label;
    4510                 :            :     }
    4511                 :       1219 : }
    4512                 :            : 
    4513                 :            : static void
    4514                 :       1219 : put_ct_helper(struct ofpbuf *odp_actions, struct ofpact_conntrack *ofc)
    4515                 :            : {
    4516         [ +  + ]:       1219 :     if (ofc->alg) {
    4517         [ +  - ]:         13 :         if (ofc->alg == IPPORT_FTP) {
    4518                 :         13 :             nl_msg_put_string(odp_actions, OVS_CT_ATTR_HELPER, "ftp");
    4519                 :            :         } else {
    4520         [ #  # ]:          0 :             VLOG_WARN("Cannot serialize ct_helper %d\n", ofc->alg);
    4521                 :            :         }
    4522                 :            :     }
    4523                 :       1219 : }
    4524                 :            : 
    4525                 :            : static void
    4526                 :       1219 : put_ct_nat(struct xlate_ctx *ctx)
    4527                 :            : {
    4528                 :       1219 :     struct ofpact_nat *ofn = ctx->ct_nat_action;
    4529                 :            :     size_t nat_offset;
    4530                 :            : 
    4531         [ +  + ]:       1219 :     if (!ofn) {
    4532                 :        815 :         return;
    4533                 :            :     }
    4534                 :            : 
    4535                 :        404 :     nat_offset = nl_msg_start_nested(ctx->odp_actions, OVS_CT_ATTR_NAT);
    4536 [ +  + ][ +  + ]:        404 :     if (ofn->flags & NX_NAT_F_SRC || ofn->flags & NX_NAT_F_DST) {
    4537         [ +  + ]:        278 :         nl_msg_put_flag(ctx->odp_actions, ofn->flags & NX_NAT_F_SRC
    4538                 :            :                         ? OVS_NAT_ATTR_SRC : OVS_NAT_ATTR_DST);
    4539         [ -  + ]:        278 :         if (ofn->flags & NX_NAT_F_PERSISTENT) {
    4540                 :          0 :             nl_msg_put_flag(ctx->odp_actions, OVS_NAT_ATTR_PERSISTENT);
    4541                 :            :         }
    4542         [ -  + ]:        278 :         if (ofn->flags & NX_NAT_F_PROTO_HASH) {
    4543                 :          0 :             nl_msg_put_flag(ctx->odp_actions, OVS_NAT_ATTR_PROTO_HASH);
    4544         [ +  + ]:        278 :         } else if (ofn->flags & NX_NAT_F_PROTO_RANDOM) {
    4545                 :          2 :             nl_msg_put_flag(ctx->odp_actions, OVS_NAT_ATTR_PROTO_RANDOM);
    4546                 :            :         }
    4547         [ +  + ]:        278 :         if (ofn->range_af == AF_INET) {
    4548                 :        274 :             nl_msg_put_be32(ctx->odp_actions, OVS_NAT_ATTR_IP_MIN,
    4549                 :            :                            ofn->range.addr.ipv4.min);
    4550   [ +  +  +  - ]:        281 :             if (ofn->range.addr.ipv4.max &&
    4551                 :          7 :                 (ntohl(ofn->range.addr.ipv4.max)
    4552                 :          7 :                  > ntohl(ofn->range.addr.ipv4.min))) {
    4553                 :        274 :                 nl_msg_put_be32(ctx->odp_actions, OVS_NAT_ATTR_IP_MAX,
    4554                 :            :                                 ofn->range.addr.ipv4.max);
    4555                 :            :             }
    4556         [ +  - ]:          4 :         } else if (ofn->range_af == AF_INET6) {
    4557                 :          4 :             nl_msg_put_unspec(ctx->odp_actions, OVS_NAT_ATTR_IP_MIN,
    4558                 :          4 :                               &ofn->range.addr.ipv6.min,
    4559                 :            :                               sizeof ofn->range.addr.ipv6.min);
    4560 [ -  + ][ #  # ]:          4 :             if (!ipv6_mask_is_any(&ofn->range.addr.ipv6.max) &&
    4561                 :          0 :                 memcmp(&ofn->range.addr.ipv6.max, &ofn->range.addr.ipv6.min,
    4562                 :            :                        sizeof ofn->range.addr.ipv6.max) > 0) {
    4563                 :          0 :                 nl_msg_put_unspec(ctx->odp_actions, OVS_NAT_ATTR_IP_MAX,
    4564                 :          0 :                                   &ofn->range.addr.ipv6.max,
    4565                 :            :                                   sizeof ofn->range.addr.ipv6.max);
    4566                 :            :             }
    4567                 :            :         }
    4568 [ +  - ][ +  + ]:        278 :         if (ofn->range_af != AF_UNSPEC && ofn->range.proto.min) {
    4569                 :         82 :             nl_msg_put_u16(ctx->odp_actions, OVS_NAT_ATTR_PROTO_MIN,
    4570                 :         82 :                            ofn->range.proto.min);
    4571 [ +  + ][ +  - ]:         82 :             if (ofn->range.proto.max &&
    4572                 :          2 :                 ofn->range.proto.max > ofn->range.proto.min) {
    4573                 :          2 :                 nl_msg_put_u16(ctx->odp_actions, OVS_NAT_ATTR_PROTO_MAX,
    4574                 :          2 :                                ofn->range.proto.max);
    4575                 :            :             }
    4576                 :            :         }
    4577                 :            :     }
    4578                 :        404 :     nl_msg_end_nested(ctx->odp_actions, nat_offset);
    4579                 :            : }
    4580                 :            : 
    4581                 :            : static void
    4582                 :       1219 : compose_conntrack_action(struct xlate_ctx *ctx, struct ofpact_conntrack *ofc)
    4583                 :            : {
    4584                 :       1219 :     ovs_u128 old_ct_label = ctx->base_flow.ct_label;
    4585                 :       1219 :     ovs_u128 old_ct_label_mask = ctx->wc->masks.ct_label;
    4586                 :       1219 :     uint32_t old_ct_mark = ctx->base_flow.ct_mark;
    4587                 :       1219 :     uint32_t old_ct_mark_mask = ctx->wc->masks.ct_mark;
    4588                 :            :     size_t ct_offset;
    4589                 :            :     uint16_t zone;
    4590                 :            : 
    4591                 :            :     /* Ensure that any prior actions are applied before composing the new
    4592                 :            :      * conntrack action. */
    4593                 :       1219 :     xlate_commit_actions(ctx);
    4594                 :            : 
    4595                 :            :     /* Process nested actions first, to populate the key. */
    4596                 :       1219 :     ctx->ct_nat_action = NULL;
    4597                 :       1219 :     ctx->wc->masks.ct_mark = 0;
    4598                 :       1219 :     ctx->wc->masks.ct_label.u64.hi = ctx->wc->masks.ct_label.u64.lo = 0;
    4599                 :       1219 :     do_xlate_actions(ofc->actions, ofpact_ct_get_action_len(ofc), ctx);
    4600                 :            : 
    4601         [ +  + ]:       1219 :     if (ofc->zone_src.field) {
    4602                 :        444 :         zone = mf_get_subfield(&ofc->zone_src, &ctx->xin->flow);
    4603                 :            :     } else {
    4604                 :        775 :         zone = ofc->zone_imm;
    4605                 :            :     }
    4606                 :            : 
    4607                 :       1219 :     ct_offset = nl_msg_start_nested(ctx->odp_actions, OVS_ACTION_ATTR_CT);
    4608         [ +  + ]:       1219 :     if (ofc->flags & NX_CT_F_COMMIT) {
    4609                 :        610 :         nl_msg_put_flag(ctx->odp_actions, OVS_CT_ATTR_COMMIT);
    4610                 :            :     }
    4611                 :       1219 :     nl_msg_put_u16(ctx->odp_actions, OVS_CT_ATTR_ZONE, zone);
    4612                 :       1219 :     put_ct_mark(&ctx->xin->flow, ctx->odp_actions, ctx->wc);
    4613                 :       1219 :     put_ct_label(&ctx->xin->flow, ctx->odp_actions, ctx->wc);
    4614                 :       1219 :     put_ct_helper(ctx->odp_actions, ofc);
    4615                 :       1219 :     put_ct_nat(ctx);
    4616                 :       1219 :     ctx->ct_nat_action = NULL;
    4617                 :       1219 :     nl_msg_end_nested(ctx->odp_actions, ct_offset);
    4618                 :            : 
    4619                 :            :     /* Restore the original ct fields in the key. These should only be exposed
    4620                 :            :      * after recirculation to another table. */
    4621                 :       1219 :     ctx->base_flow.ct_mark = old_ct_mark;
    4622                 :       1219 :     ctx->wc->masks.ct_mark = old_ct_mark_mask;
    4623                 :       1219 :     ctx->base_flow.ct_label = old_ct_label;
    4624                 :       1219 :     ctx->wc->masks.ct_label = old_ct_label_mask;
    4625                 :            : 
    4626         [ +  + ]:       1219 :     if (ofc->recirc_table == NX_CT_RECIRC_NONE) {
    4627                 :            :         /* If we do not recirculate as part of this action, hide the results of
    4628                 :            :          * connection tracking from subsequent recirculations. */
    4629                 :        316 :         ctx->conntracked = false;
    4630                 :            :     } else {
    4631                 :            :         /* Use ct_* fields from datapath during recirculation upcall. */
    4632                 :        903 :         ctx->conntracked = true;
    4633                 :        903 :         compose_recirculate_and_fork(ctx, ofc->recirc_table);
    4634                 :            :     }
    4635                 :       1219 : }
    4636                 :            : 
    4637                 :            : static void
    4638                 :    2392371 : recirc_for_mpls(const struct ofpact *a, struct xlate_ctx *ctx)
    4639                 :            : {
    4640                 :            :     /* No need to recirculate if already exiting. */
    4641         [ +  + ]:    2392371 :     if (ctx->exit) {
    4642                 :        154 :         return;
    4643                 :            :     }
    4644                 :            : 
    4645                 :            :     /* Do not consider recirculating unless the packet was previously MPLS. */
    4646         [ +  + ]:    2392217 :     if (!ctx->was_mpls) {
    4647                 :    2392159 :         return;
    4648                 :            :     }
    4649                 :            : 
    4650                 :            :     /* Special case these actions, only recirculating if necessary.
    4651                 :            :      * This avoids the overhead of recirculation in common use-cases.
    4652                 :            :      */
    4653      [ +  +  + ]:         58 :     switch (a->type) {
    4654                 :            : 
    4655                 :            :     /* Output actions  do not require recirculation. */
    4656                 :            :     case OFPACT_OUTPUT:
    4657                 :            :     case OFPACT_OUTPUT_TRUNC:
    4658                 :            :     case OFPACT_ENQUEUE:
    4659                 :            :     case OFPACT_OUTPUT_REG:
    4660                 :            :     /* Set actions that don't touch L3+ fields do not require recirculation. */
    4661                 :            :     case OFPACT_SET_VLAN_VID:
    4662                 :            :     case OFPACT_SET_VLAN_PCP:
    4663                 :            :     case OFPACT_SET_ETH_SRC:
    4664                 :            :     case OFPACT_SET_ETH_DST:
    4665                 :            :     case OFPACT_SET_TUNNEL:
    4666                 :            :     case OFPACT_SET_QUEUE:
    4667                 :            :     /* If actions of a group require recirculation that can be detected
    4668                 :            :      * when translating them. */
    4669                 :            :     case OFPACT_GROUP:
    4670                 :         19 :         return;
    4671                 :            : 
    4672                 :            :     /* Set field that don't touch L3+ fields don't require recirculation. */
    4673                 :            :     case OFPACT_SET_FIELD:
    4674         [ +  - ]:          3 :         if (mf_is_l3_or_higher(ofpact_get_SET_FIELD(a)->field)) {
    4675                 :          3 :             break;
    4676                 :            :         }
    4677                 :          0 :         return;
    4678                 :            : 
    4679                 :            :     /* For simplicity, recirculate in all other cases. */
    4680                 :            :     case OFPACT_CONTROLLER:
    4681                 :            :     case OFPACT_BUNDLE:
    4682                 :            :     case OFPACT_STRIP_VLAN:
    4683                 :            :     case OFPACT_PUSH_VLAN:
    4684                 :            :     case OFPACT_SET_IPV4_SRC:
    4685                 :            :     case OFPACT_SET_IPV4_DST:
    4686                 :            :     case OFPACT_SET_IP_DSCP:
    4687                 :            :     case OFPACT_SET_IP_ECN:
    4688                 :            :     case OFPACT_SET_IP_TTL:
    4689                 :            :     case OFPACT_SET_L4_SRC_PORT:
    4690                 :            :     case OFPACT_SET_L4_DST_PORT:
    4691                 :            :     case OFPACT_REG_MOVE:
    4692                 :            :     case OFPACT_STACK_PUSH:
    4693                 :            :     case OFPACT_STACK_POP:
    4694                 :            :     case OFPACT_DEC_TTL:
    4695                 :            :     case OFPACT_SET_MPLS_LABEL:
    4696                 :            :     case OFPACT_SET_MPLS_TC:
    4697                 :            :     case OFPACT_SET_MPLS_TTL:
    4698                 :            :     case OFPACT_DEC_MPLS_TTL:
    4699                 :            :     case OFPACT_PUSH_MPLS:
    4700                 :            :     case OFPACT_POP_MPLS:
    4701                 :            :     case OFPACT_POP_QUEUE:
    4702                 :            :     case OFPACT_FIN_TIMEOUT:
    4703                 :            :     case OFPACT_RESUBMIT:
    4704                 :            :     case OFPACT_LEARN:
    4705                 :            :     case OFPACT_CONJUNCTION:
    4706                 :            :     case OFPACT_MULTIPATH:
    4707                 :            :     case OFPACT_NOTE:
    4708                 :            :     case OFPACT_EXIT:
    4709                 :            :     case OFPACT_SAMPLE:
    4710                 :            :     case OFPACT_UNROLL_XLATE:
    4711                 :            :     case OFPACT_CT:
    4712                 :            :     case OFPACT_NAT:
    4713                 :            :     case OFPACT_DEBUG_RECIRC:
    4714                 :            :     case OFPACT_METER:
    4715                 :            :     case OFPACT_CLEAR_ACTIONS:
    4716                 :            :     case OFPACT_WRITE_ACTIONS:
    4717                 :            :     case OFPACT_WRITE_METADATA:
    4718                 :            :     case OFPACT_GOTO_TABLE:
    4719                 :            :     default:
    4720                 :         36 :         break;
    4721                 :            :     }
    4722                 :            : 
    4723                 :            :     /* Recirculate */
    4724                 :         39 :     ctx_trigger_freeze(ctx);
    4725                 :            : }
    4726                 :            : 
    4727                 :            : static void
    4728                 :    1413839 : do_xlate_actions(const struct ofpact *ofpacts, size_t ofpacts_len,
    4729                 :            :                  struct xlate_ctx *ctx)
    4730                 :            : {
    4731                 :    1413839 :     struct flow_wildcards *wc = ctx->wc;
    4732                 :    1413839 :     struct flow *flow = &ctx->xin->flow;
    4733                 :            :     const struct ofpact *a;
    4734                 :            : 
    4735         [ +  + ]:    1413839 :     if (ovs_native_tunneling_is_on(ctx->xbridge->ofproto)) {
    4736                 :    1282070 :         tnl_neigh_snoop(flow, wc, ctx->xbridge->name);
    4737                 :            :     }
    4738                 :            :     /* dl_type already in the mask, not set below. */
    4739                 :            : 
    4740         [ +  + ]:    3805711 :     OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
    4741                 :            :         struct ofpact_controller *controller;
    4742                 :            :         const struct ofpact_metadata *metadata;
    4743                 :            :         const struct ofpact_set_field *set_field;
    4744                 :            :         const struct mf_field *mf;
    4745                 :            : 
    4746         [ +  + ]:    2392505 :         if (ctx->error) {
    4747                 :        135 :             break;
    4748                 :            :         }
    4749                 :            : 
    4750                 :    2392370 :         recirc_for_mpls(a, ctx);
    4751                 :            : 
    4752         [ +  + ]:    2392371 :         if (ctx->exit) {
    4753                 :            :             /* Check if need to store the remaining actions for later
    4754                 :            :              * execution. */
    4755         [ +  + ]:        193 :             if (ctx->freezing) {
    4756                 :        178 :                 freeze_unroll_actions(a, ofpact_end(ofpacts, ofpacts_len),
    4757                 :            :                                       ctx);
    4758                 :            :             }
    4759                 :        193 :             break;
    4760                 :            :         }
    4761                 :            : 
    4762   [ +  +  +  +  :    2392178 :         switch (a->type) {
          +  +  +  +  +  
          +  +  +  +  -  
          -  +  +  +  +  
          -  -  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  -  
          +  +  +  +  +  
          -  -  +  +  +  
                +  +  - ]
    4763                 :            :         case OFPACT_OUTPUT:
    4764                 :     109907 :             xlate_output_action(ctx, ofpact_get_OUTPUT(a)->port,
    4765                 :     109907 :                                 ofpact_get_OUTPUT(a)->max_len, true);
    4766                 :     109907 :             break;
    4767                 :            : 
    4768                 :            :         case OFPACT_GROUP:
    4769         [ -  + ]:        264 :             if (xlate_group_action(ctx, ofpact_get_GROUP(a)->group_id)) {
    4770                 :            :                 /* Group could not be found. */
    4771                 :            : 
    4772                 :            :                 /* XXX: Terminates action list translation, but does not
    4773                 :            :                  * terminate the pipeline. */
    4774                 :          0 :                 return;
    4775                 :            :             }
    4776                 :        264 :             break;
    4777                 :            : 
    4778                 :            :         case OFPACT_CONTROLLER:
    4779                 :      25845 :             controller = ofpact_get_CONTROLLER(a);
    4780         [ +  + ]:      25845 :             if (controller->pause) {
    4781                 :        273 :                 ctx->pause = controller;
    4782                 :        273 :                 ctx->xout->slow |= SLOW_CONTROLLER;
    4783                 :        273 :                 ctx_trigger_freeze(ctx);
    4784                 :        273 :                 a = ofpact_next(a);
    4785                 :            :             } else {
    4786                 :      25572 :                 execute_controller_action(ctx, controller->max_len,
    4787                 :            :                                           controller->reason,
    4788                 :      25572 :                                           controller->controller_id,
    4789                 :      25572 :                                           controller->userdata,
    4790                 :      25572 :                                           controller->userdata_len);
    4791                 :            :             }
    4792                 :      25845 :             break;
    4793                 :            : 
    4794                 :            :         case OFPACT_ENQUEUE:
    4795                 :         12 :             memset(&wc->masks.skb_priority, 0xff,
    4796                 :            :                    sizeof wc->masks.skb_priority);
    4797                 :         12 :             xlate_enqueue_action(ctx, ofpact_get_ENQUEUE(a));
    4798                 :         12 :             break;
    4799                 :            : 
    4800                 :            :         case OFPACT_SET_VLAN_VID:
    4801                 :         20 :             wc->masks.vlan_tci |= htons(VLAN_VID_MASK | VLAN_CFI);
    4802   [ +  -  +  - ]:         40 :             if (flow->vlan_tci & htons(VLAN_CFI) ||
    4803                 :         20 :                 ofpact_get_SET_VLAN_VID(a)->push_vlan_if_needed) {
    4804                 :         20 :                 flow->vlan_tci &= ~htons(VLAN_VID_MASK);
    4805                 :         40 :                 flow->vlan_tci |= (htons(ofpact_get_SET_VLAN_VID(a)->vlan_vid)
    4806                 :         20 :                                    | htons(VLAN_CFI));
    4807                 :            :             }
    4808                 :         20 :             break;
    4809                 :            : 
    4810                 :            :         case OFPACT_SET_VLAN_PCP:
    4811                 :          4 :             wc->masks.vlan_tci |= htons(VLAN_PCP_MASK | VLAN_CFI);
    4812   [ -  +  #  # ]:          4 :             if (flow->vlan_tci & htons(VLAN_CFI) ||
    4813                 :          0 :                 ofpact_get_SET_VLAN_PCP(a)->push_vlan_if_needed) {
    4814                 :          4 :                 flow->vlan_tci &= ~htons(VLAN_PCP_MASK);
    4815                 :          4 :                 flow->vlan_tci |= htons((ofpact_get_SET_VLAN_PCP(a)->vlan_pcp
    4816                 :          4 :                                          << VLAN_PCP_SHIFT) | VLAN_CFI);
    4817                 :            :             }
    4818                 :          4 :             break;
    4819                 :            : 
    4820                 :            :         case OFPACT_STRIP_VLAN:
    4821                 :         58 :             memset(&wc->masks.vlan_tci, 0xff, sizeof wc->masks.vlan_tci);
    4822                 :         58 :             flow->vlan_tci = htons(0);
    4823                 :         58 :             break;
    4824                 :            : 
    4825                 :            :         case OFPACT_PUSH_VLAN:
    4826                 :            :             /* XXX 802.1AD(QinQ) */
    4827                 :         59 :             memset(&wc->masks.vlan_tci, 0xff, sizeof wc->masks.vlan_tci);
    4828                 :         59 :             flow->vlan_tci = htons(VLAN_CFI);
    4829                 :         59 :             break;
    4830                 :            : 
    4831                 :            :         case OFPACT_SET_ETH_SRC:
    4832                 :          3 :             WC_MASK_FIELD(wc, dl_src);
    4833                 :          3 :             flow->dl_src = ofpact_get_SET_ETH_SRC(a)->mac;
    4834                 :          3 :             break;
    4835                 :            : 
    4836                 :            :         case OFPACT_SET_ETH_DST:
    4837                 :          5 :             WC_MASK_FIELD(wc, dl_dst);
    4838                 :          5 :             flow->dl_dst = ofpact_get_SET_ETH_DST(a)->mac;
    4839                 :          5 :             break;
    4840                 :            : 
    4841                 :            :         case OFPACT_SET_IPV4_SRC:
    4842         [ +  - ]:          7 :             if (flow->dl_type == htons(ETH_TYPE_IP)) {
    4843                 :          7 :                 memset(&wc->masks.nw_src, 0xff, sizeof wc->masks.nw_src);
    4844                 :          7 :                 flow->nw_src = ofpact_get_SET_IPV4_SRC(a)->ipv4;
    4845                 :            :             }
    4846                 :          7 :             break;
    4847                 :            : 
    4848                 :            :         case OFPACT_SET_IPV4_DST:
    4849         [ +  - ]:          7 :             if (flow->dl_type == htons(ETH_TYPE_IP)) {
    4850                 :          7 :                 memset(&wc->masks.nw_dst, 0xff, sizeof wc->masks.nw_dst);
    4851                 :          7 :                 flow->nw_dst = ofpact_get_SET_IPV4_DST(a)->ipv4;
    4852                 :            :             }
    4853                 :          7 :             break;
    4854                 :            : 
    4855                 :            :         case OFPACT_SET_IP_DSCP:
    4856         [ +  - ]:          5 :             if (is_ip_any(flow)) {
    4857                 :          5 :                 wc->masks.nw_tos |= IP_DSCP_MASK;
    4858                 :          5 :                 flow->nw_tos &= ~IP_DSCP_MASK;
    4859                 :          5 :                 flow->nw_tos |= ofpact_get_SET_IP_DSCP(a)->dscp;
    4860                 :            :             }
    4861                 :          5 :             break;
    4862                 :            : 
    4863                 :            :         case OFPACT_SET_IP_ECN:
    4864         [ #  # ]:          0 :             if (is_ip_any(flow)) {
    4865                 :          0 :                 wc->masks.nw_tos |= IP_ECN_MASK;
    4866                 :          0 :                 flow->nw_tos &= ~IP_ECN_MASK;
    4867                 :          0 :                 flow->nw_tos |= ofpact_get_SET_IP_ECN(a)->ecn;
    4868                 :            :             }
    4869                 :          0 :             break;
    4870                 :            : 
    4871                 :            :         case OFPACT_SET_IP_TTL:
    4872         [ #  # ]:          0 :             if (is_ip_any(flow)) {
    4873                 :          0 :                 wc->masks.nw_ttl = 0xff;
    4874                 :          0 :                 flow->nw_ttl = ofpact_get_SET_IP_TTL(a)->ttl;
    4875                 :            :             }
    4876                 :          0 :             break;
    4877                 :            : 
    4878                 :            :         case OFPACT_SET_L4_SRC_PORT:
    4879 [ +  - ][ +  - ]:          3 :             if (is_ip_any(flow) && !(flow->nw_frag & FLOW_NW_FRAG_LATER)) {
    4880                 :          3 :                 memset(&wc->masks.nw_proto, 0xff, sizeof wc->masks.nw_proto);
    4881                 :          3 :                 memset(&wc->masks.tp_src, 0xff, sizeof wc->masks.tp_src);
    4882                 :          3 :                 flow->tp_src = htons(ofpact_get_SET_L4_SRC_PORT(a)->port);
    4883                 :            :             }
    4884                 :          3 :             break;
    4885                 :            : 
    4886                 :            :         case OFPACT_SET_L4_DST_PORT:
    4887 [ +  - ][ +  - ]:          8 :             if (is_ip_any(flow) && !(flow->nw_frag & FLOW_NW_FRAG_LATER)) {
    4888                 :          8 :                 memset(&wc->masks.nw_proto, 0xff, sizeof wc->masks.nw_proto);
    4889                 :          8 :                 memset(&wc->masks.tp_dst, 0xff, sizeof wc->masks.tp_dst);
    4890                 :          8 :                 flow->tp_dst = htons(ofpact_get_SET_L4_DST_PORT(a)->port);
    4891                 :            :             }
    4892                 :          8 :             break;
    4893                 :            : 
    4894                 :            :         case OFPACT_RESUBMIT:
    4895                 :            :             /* Freezing complicates resubmit.  Some action in the flow
    4896                 :            :              * entry found by resubmit might trigger freezing.  If that
    4897                 :            :              * happens, then we do not want to execute the resubmit again after
    4898                 :            :              * during thawing, so we want to skip back to the head of the loop
    4899                 :            :              * to avoid that, only adding any actions that follow the resubmit
    4900                 :            :              * to the frozen actions.
    4901                 :            :              */
    4902                 :    1177160 :             xlate_ofpact_resubmit(ctx, ofpact_get_RESUBMIT(a));
    4903                 :    1177160 :             continue;
    4904                 :            : 
    4905                 :            :         case OFPACT_SET_TUNNEL:
    4906                 :         12 :             flow->tunnel.tun_id = htonll(ofpact_get_SET_TUNNEL(a)->tun_id);
    4907                 :         12 :             break;
    4908                 :            : 
    4909                 :            :         case OFPACT_SET_QUEUE:
    4910                 :          0 :             memset(&wc->masks.skb_priority, 0xff,
    4911                 :            :                    sizeof wc->masks.skb_priority);
    4912                 :          0 :             xlate_set_queue_action(ctx, ofpact_get_SET_QUEUE(a)->queue_id);
    4913                 :          0 :             break;
    4914                 :            : 
    4915                 :            :         case OFPACT_POP_QUEUE:
    4916                 :          0 :             memset(&wc->masks.skb_priority, 0xff,
    4917                 :            :                    sizeof wc->masks.skb_priority);
    4918                 :          0 :             flow->skb_priority = ctx->orig_skb_priority;
    4919                 :          0 :             break;
    4920                 :            : 
    4921                 :            :         case OFPACT_REG_MOVE:
    4922                 :      39047 :             mf_subfield_copy(&ofpact_get_REG_MOVE(a)->src,
    4923                 :      39047 :                              &ofpact_get_REG_MOVE(a)->dst, flow, wc);
    4924                 :      39047 :             break;
    4925                 :            : 
    4926                 :            :         case OFPACT_SET_FIELD:
    4927                 :     825368 :             set_field = ofpact_get_SET_FIELD(a);
    4928                 :     825368 :             mf = set_field->field;
    4929                 :            : 
    4930                 :            :             /* Set the field only if the packet actually has it. */
    4931         [ +  + ]:     825368 :             if (mf_are_prereqs_ok(mf, flow, wc)) {
    4932                 :     825360 :                 mf_mask_field_masked(mf, ofpact_set_field_mask(set_field), wc);
    4933                 :     825360 :                 mf_set_flow_value_masked(mf, set_field->value,
    4934                 :     825360 :                                          ofpact_set_field_mask(set_field),
    4935                 :            :                                          flow);
    4936                 :            :             }
    4937                 :     825367 :             break;
    4938                 :            : 
    4939                 :            :         case OFPACT_STACK_PUSH:
    4940                 :     104207 :             nxm_execute_stack_push(ofpact_get_STACK_PUSH(a), flow, wc,
    4941                 :            :                                    &ctx->stack);
    4942                 :     104207 :             break;
    4943                 :            : 
    4944                 :            :         case OFPACT_STACK_POP:
    4945                 :     103693 :             nxm_execute_stack_pop(ofpact_get_STACK_POP(a), flow, wc,
    4946                 :            :                                   &ctx->stack);
    4947                 :     103693 :             break;
    4948                 :            : 
    4949                 :            :         case OFPACT_PUSH_MPLS:
    4950                 :        124 :             compose_mpls_push_action(ctx, ofpact_get_PUSH_MPLS(a));
    4951                 :        124 :             break;
    4952                 :            : 
    4953                 :            :         case OFPACT_POP_MPLS:
    4954                 :        115 :             compose_mpls_pop_action(ctx, ofpact_get_POP_MPLS(a)->ethertype);
    4955                 :        115 :             break;
    4956                 :            : 
    4957                 :            :         case OFPACT_SET_MPLS_LABEL:
    4958                 :          2 :             compose_set_mpls_label_action(
    4959                 :          2 :                 ctx, ofpact_get_SET_MPLS_LABEL(a)->label);
    4960                 :          2 :             break;
    4961                 :            : 
    4962                 :            :         case OFPACT_SET_MPLS_TC:
    4963                 :          2 :             compose_set_mpls_tc_action(ctx, ofpact_get_SET_MPLS_TC(a)->tc);
    4964                 :          2 :             break;
    4965                 :            : 
    4966                 :            :         case OFPACT_SET_MPLS_TTL:
    4967                 :         14 :             compose_set_mpls_ttl_action(ctx, ofpact_get_SET_MPLS_TTL(a)->ttl);
    4968                 :         14 :             break;
    4969                 :            : 
    4970                 :            :         case OFPACT_DEC_MPLS_TTL:
    4971         [ -  + ]:         50 :             if (compose_dec_mpls_ttl_action(ctx)) {
    4972                 :          0 :                 return;
    4973                 :            :             }
    4974                 :         50 :             break;
    4975                 :            : 
    4976                 :            :         case OFPACT_DEC_TTL:
    4977                 :       3777 :             wc->masks.nw_ttl = 0xff;
    4978         [ +  + ]:       3777 :             if (compose_dec_ttl(ctx, ofpact_get_DEC_TTL(a))) {
    4979                 :         28 :                 return;
    4980                 :            :             }
    4981                 :       3749 :             break;
    4982                 :            : 
    4983                 :            :         case OFPACT_NOTE:
    4984                 :            :             /* Nothing to do. */
    4985                 :         14 :             break;
    4986                 :            : 
    4987                 :            :         case OFPACT_MULTIPATH:
    4988                 :          4 :             multipath_execute(ofpact_get_MULTIPATH(a), flow, wc);
    4989                 :          4 :             break;
    4990                 :            : 
    4991                 :            :         case OFPACT_BUNDLE:
    4992                 :          4 :             xlate_bundle_action(ctx, ofpact_get_BUNDLE(a));
    4993                 :          4 :             break;
    4994                 :            : 
    4995                 :            :         case OFPACT_OUTPUT_REG:
    4996                 :         57 :             xlate_output_reg_action(ctx, ofpact_get_OUTPUT_REG(a));
    4997                 :         57 :             break;
    4998                 :            : 
    4999                 :            :         case OFPACT_OUTPUT_TRUNC:
    5000                 :        122 :             xlate_output_trunc_action(ctx, ofpact_get_OUTPUT_TRUNC(a)->port,
    5001                 :        122 :                                 ofpact_get_OUTPUT_TRUNC(a)->max_len);
    5002                 :        122 :             break;
    5003                 :            : 
    5004                 :            :         case OFPACT_LEARN:
    5005                 :         58 :             xlate_learn_action(ctx, ofpact_get_LEARN(a));
    5006                 :         58 :             break;
    5007                 :            : 
    5008                 :            :         case OFPACT_CONJUNCTION: {
    5009                 :            :             /* A flow with a "conjunction" action represents part of a special
    5010                 :            :              * kind of "set membership match".  Such a flow should not actually
    5011                 :            :              * get executed, but it could via, say, a "packet-out", even though
    5012                 :            :              * that wouldn't be useful.  Log it to help debugging. */
    5013                 :            :             static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
    5014         [ #  # ]:          0 :             VLOG_INFO_RL(&rl, "executing no-op conjunction action");
    5015                 :          0 :             break;
    5016                 :            :         }
    5017                 :            : 
    5018                 :            :         case OFPACT_EXIT:
    5019                 :          3 :             ctx->exit = true;
    5020                 :          3 :             break;
    5021                 :            : 
    5022                 :            :         case OFPACT_UNROLL_XLATE: {
    5023                 :        277 :             struct ofpact_unroll_xlate *unroll = ofpact_get_UNROLL_XLATE(a);
    5024                 :            : 
    5025                 :            :             /* Restore translation context data that was stored earlier. */
    5026                 :        277 :             ctx->table_id = unroll->rule_table_id;
    5027                 :        277 :             ctx->rule_cookie = unroll->rule_cookie;
    5028                 :        277 :             break;
    5029                 :            :         }
    5030                 :            :         case OFPACT_FIN_TIMEOUT:
    5031                 :          2 :             memset(&wc->masks.nw_proto, 0xff, sizeof wc->masks.nw_proto);
    5032                 :          2 :             xlate_fin_timeout(ctx, ofpact_get_FIN_TIMEOUT(a));
    5033                 :          2 :             break;
    5034                 :            : 
    5035                 :            :         case OFPACT_CLEAR_ACTIONS:
    5036                 :          1 :             ofpbuf_clear(&ctx->action_set);
    5037                 :          1 :             ctx->xin->flow.actset_output = OFPP_UNSET;
    5038                 :          1 :             ctx->action_set_has_group = false;
    5039                 :          1 :             break;
    5040                 :            : 
    5041                 :            :         case OFPACT_WRITE_ACTIONS:
    5042                 :         21 :             xlate_write_actions(ctx, ofpact_get_WRITE_ACTIONS(a));
    5043                 :         21 :             break;
    5044                 :            : 
    5045                 :            :         case OFPACT_WRITE_METADATA:
    5046                 :          0 :             metadata = ofpact_get_WRITE_METADATA(a);
    5047                 :          0 :             flow->metadata &= ~metadata->mask;
    5048                 :          0 :             flow->metadata |= metadata->metadata & metadata->mask;
    5049                 :          0 :             break;
    5050                 :            : 
    5051                 :            :         case OFPACT_METER:
    5052                 :            :             /* Not implemented yet. */
    5053                 :          0 :             break;
    5054                 :            : 
    5055                 :            :         case OFPACT_GOTO_TABLE: {
    5056                 :        204 :             struct ofpact_goto_table *ogt = ofpact_get_GOTO_TABLE(a);
    5057                 :            : 
    5058         [ -  + ]:        204 :             ovs_assert(ctx->table_id < ogt->table_id);
    5059                 :            : 
    5060                 :        204 :             xlate_table_action(ctx, ctx->xin->flow.in_port.ofp_port,
    5061                 :        204 :                                ogt->table_id, true, true);
    5062                 :        204 :             break;
    5063                 :            :         }
    5064                 :            : 
    5065                 :            :         case OFPACT_SAMPLE:
    5066                 :          7 :             xlate_sample_action(ctx, ofpact_get_SAMPLE(a));
    5067                 :          7 :             break;
    5068                 :            : 
    5069                 :            :         case OFPACT_CT:
    5070                 :       1219 :             compose_conntrack_action(ctx, ofpact_get_CT(a));
    5071                 :       1219 :             break;
    5072                 :            : 
    5073                 :            :         case OFPACT_NAT:
    5074                 :            :             /* This will be processed by compose_conntrack_action(). */
    5075                 :        404 :             ctx->ct_nat_action = ofpact_get_NAT(a);
    5076                 :        404 :             break;
    5077                 :            : 
    5078                 :            :         case OFPACT_DEBUG_RECIRC:
    5079                 :          3 :             ctx_trigger_freeze(ctx);
    5080                 :          3 :             a = ofpact_next(a);
    5081                 :          3 :             break;
    5082                 :            :         }
    5083                 :            : 
    5084                 :            :         /* Check if need to store this and the remaining actions for later
    5085                 :            :          * execution. */
    5086 [ +  - ][ +  + ]:    1214989 :         if (!ctx->error && ctx->exit && ctx_first_frozen_action(ctx)) {
                 [ +  + ]
    5087                 :        279 :             freeze_unroll_actions(a, ofpact_end(ofpacts, ofpacts_len), ctx);
    5088                 :        279 :             break;
    5089                 :            :         }
    5090                 :            :     }
    5091                 :            : }
    5092                 :            : 
    5093                 :            : void
    5094                 :      84629 : xlate_in_init(struct xlate_in *xin, struct ofproto_dpif *ofproto,
    5095                 :            :               const struct flow *flow, ofp_port_t in_port,
    5096                 :            :               struct rule_dpif *rule, uint16_t tcp_flags,
    5097                 :            :               const struct dp_packet *packet, struct flow_wildcards *wc,
    5098                 :            :               struct ofpbuf *odp_actions)
    5099                 :            : {
    5100                 :      84629 :     xin->ofproto = ofproto;
    5101                 :      84629 :     xin->flow = *flow;
    5102                 :      84629 :     xin->flow.in_port.ofp_port = in_port;
    5103                 :      84629 :     xin->flow.actset_output = OFPP_UNSET;
    5104                 :      84629 :     xin->packet = packet;
    5105                 :      84629 :     xin->may_learn = packet != NULL;
    5106                 :      84629 :     xin->rule = rule;
    5107                 :      84629 :     xin->xcache = NULL;
    5108                 :      84629 :     xin->ofpacts = NULL;
    5109                 :      84629 :     xin->ofpacts_len = 0;
    5110                 :      84629 :     xin->tcp_flags = tcp_flags;
    5111                 :      84629 :     xin->resubmit_hook = NULL;
    5112                 :      84629 :     xin->report_hook = NULL;
    5113                 :      84629 :     xin->resubmit_stats = NULL;
    5114                 :      84629 :     xin->indentation = 0;
    5115                 :      84629 :     xin->depth = 0;
    5116                 :      84629 :     xin->resubmits = 0;
    5117                 :      84629 :     xin->wc = wc;
    5118                 :      84629 :     xin->odp_actions = odp_actions;
    5119                 :            : 
    5120                 :            :     /* Do recirc lookup. */
    5121                 :      84629 :     xin->frozen_state = NULL;
    5122         [ +  + ]:      84629 :     if (flow->recirc_id) {
    5123                 :       1304 :         const struct recirc_id_node *node
    5124                 :       1304 :             = recirc_id_node_find(flow->recirc_id);
    5125         [ +  - ]:       1304 :         if (node) {
    5126                 :       1304 :             xin->frozen_state = &node->state;
    5127                 :            :         }
    5128                 :            :     }
    5129                 :      84629 : }
    5130                 :            : 
    5131                 :            : void
    5132                 :     180785 : xlate_out_uninit(struct xlate_out *xout)
    5133                 :            : {
    5134         [ +  + ]:     180785 :     if (xout) {
    5135                 :      84629 :         recirc_refs_unref(&xout->recircs);
    5136                 :            :     }
    5137                 :     180785 : }
    5138                 :            : 
    5139                 :            : /* Translates the 'ofpacts_len' bytes of "struct ofpact"s starting at 'ofpacts'
    5140                 :            :  * into datapath actions, using 'ctx', and discards the datapath actions. */
    5141                 :            : void
    5142                 :        197 : xlate_actions_for_side_effects(struct xlate_in *xin)
    5143                 :            : {
    5144                 :            :     struct xlate_out xout;
    5145                 :            :     enum xlate_error error;
    5146                 :            : 
    5147                 :        197 :     error = xlate_actions(xin, &xout);
    5148         [ -  + ]:        197 :     if (error) {
    5149                 :            :         static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
    5150                 :            : 
    5151         [ #  # ]:          0 :         VLOG_WARN_RL(&rl, "xlate_actions failed (%s)!", xlate_strerror(error));
    5152                 :            :     }
    5153                 :            : 
    5154                 :        197 :     xlate_out_uninit(&xout);
    5155                 :        197 : }
    5156                 :            : 
    5157                 :            : static struct skb_priority_to_dscp *
    5158                 :          6 : get_skb_priority(const struct xport *xport, uint32_t skb_priority)
    5159                 :            : {
    5160                 :            :     struct skb_priority_to_dscp *pdscp;
    5161                 :            :     uint32_t hash;
    5162                 :            : 
    5163                 :          6 :     hash = hash_int(skb_priority, 0);
    5164 [ +  + ][ -  + ]:          6 :     HMAP_FOR_EACH_IN_BUCKET (pdscp, hmap_node, hash, &xport->skb_priorities) {
    5165         [ +  - ]:          4 :         if (pdscp->skb_priority == skb_priority) {
    5166                 :          4 :             return pdscp;
    5167                 :            :         }
    5168                 :            :     }
    5169                 :          2 :     return NULL;
    5170                 :            : }
    5171                 :            : 
    5172                 :            : static bool
    5173                 :          6 : dscp_from_skb_priority(const struct xport *xport, uint32_t skb_priority,
    5174                 :            :                        uint8_t *dscp)
    5175                 :            : {
    5176                 :          6 :     struct skb_priority_to_dscp *pdscp = get_skb_priority(xport, skb_priority);
    5177         [ +  + ]:          6 :     *dscp = pdscp ? pdscp->dscp : 0;
    5178                 :          6 :     return pdscp != NULL;
    5179                 :            : }
    5180                 :            : 
    5181                 :            : static size_t
    5182                 :      89200 : count_skb_priorities(const struct xport *xport)
    5183                 :            : {
    5184                 :      89200 :     return hmap_count(&xport->skb_priorities);
    5185                 :            : }
    5186                 :            : 
    5187                 :            : static void
    5188                 :     346806 : clear_skb_priorities(struct xport *xport)
    5189                 :            : {
    5190                 :            :     struct skb_priority_to_dscp *pdscp;
    5191                 :            : 
    5192 [ +  + ][ -  + ]:     346818 :     HMAP_FOR_EACH_POP (pdscp, hmap_node, &xport->skb_priorities) {
                 [ +  + ]
    5193                 :         12 :         free(pdscp);
    5194                 :            :     }
    5195                 :     346806 : }
    5196                 :            : 
    5197                 :            : static bool
    5198                 :          0 : actions_output_to_local_port(const struct xlate_ctx *ctx)
    5199                 :            : {
    5200                 :          0 :     odp_port_t local_odp_port = ofp_port_to_odp_port(ctx->xbridge, OFPP_LOCAL);
    5201                 :            :     const struct nlattr *a;
    5202                 :            :     unsigned int left;
    5203                 :            : 
    5204         [ #  # ]:          0 :     NL_ATTR_FOR_EACH_UNSAFE (a, left, ctx->odp_actions->data,
    5205                 :            :                              ctx->odp_actions->size) {
    5206         [ #  # ]:          0 :         if (nl_attr_type(a) == OVS_ACTION_ATTR_OUTPUT
    5207         [ #  # ]:          0 :             && nl_attr_get_odp_port(a) == local_odp_port) {
    5208                 :          0 :             return true;
    5209                 :            :         }
    5210                 :            :     }
    5211                 :          0 :     return false;
    5212                 :            : }
    5213                 :            : 
    5214                 :            : #if defined(__linux__)
    5215                 :            : /* Returns the maximum number of packets that the Linux kernel is willing to
    5216                 :            :  * queue up internally to certain kinds of software-implemented ports, or the
    5217                 :            :  * default (and rarely modified) value if it cannot be determined. */
    5218                 :            : static int
    5219                 :      84624 : netdev_max_backlog(void)
    5220                 :            : {
    5221                 :            :     static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
    5222                 :            :     static int max_backlog = 1000; /* The normal default value. */
    5223                 :            : 
    5224         [ +  + ]:      84624 :     if (ovsthread_once_start(&once)) {
    5225                 :            :         static const char filename[] = "/proc/sys/net/core/netdev_max_backlog";
    5226                 :            :         FILE *stream;
    5227                 :            :         int n;
    5228                 :            : 
    5229                 :        388 :         stream = fopen(filename, "r");
    5230         [ -  + ]:        388 :         if (!stream) {
    5231         [ #  # ]:          0 :             VLOG_INFO("%s: open failed (%s)", filename, ovs_strerror(errno));
    5232                 :            :         } else {
    5233         [ -  + ]:        388 :             if (fscanf(stream, "%d", &n) != 1) {
    5234         [ #  # ]:          0 :                 VLOG_WARN("%s: read error", filename);
    5235         [ -  + ]:        388 :             } else if (n <= 100) {
    5236         [ #  # ]:          0 :                 VLOG_WARN("%s: unexpectedly small value %d", filename, n);
    5237                 :            :             } else {
    5238                 :        388 :                 max_backlog = n;
    5239                 :            :             }
    5240                 :        388 :             fclose(stream);
    5241                 :            :         }
    5242                 :        388 :         ovsthread_once_done(&once);
    5243                 :            : 
    5244         [ -  + ]:        388 :         VLOG_DBG("%s: using %d max_backlog", filename, max_backlog);
    5245                 :            :     }
    5246                 :            : 
    5247                 :      84624 :     return max_backlog;
    5248                 :            : }
    5249                 :            : 
    5250                 :            : /* Counts and returns the number of OVS_ACTION_ATTR_OUTPUT actions in
    5251                 :            :  * 'odp_actions'. */
    5252                 :            : static int
    5253                 :          0 : count_output_actions(const struct ofpbuf *odp_actions)
    5254                 :            : {
    5255                 :            :     const struct nlattr *a;
    5256                 :            :     size_t left;
    5257                 :          0 :     int n = 0;
    5258                 :            : 
    5259         [ #  # ]:          0 :     NL_ATTR_FOR_EACH_UNSAFE (a, left, odp_actions->data, odp_actions->size) {
    5260         [ #  # ]:          0 :         if (a->nla_type == OVS_ACTION_ATTR_OUTPUT) {
    5261                 :          0 :             n++;
    5262                 :            :         }
    5263                 :            :     }
    5264                 :          0 :     return n;
    5265                 :            : }
    5266                 :            : #endif /* defined(__linux__) */
    5267                 :            : 
    5268                 :            : /* Returns true if 'odp_actions' contains more output actions than the datapath
    5269                 :            :  * can reliably handle in one go.  On Linux, this is the value of the
    5270                 :            :  * net.core.netdev_max_backlog sysctl, which limits the maximum number of
    5271                 :            :  * packets that the kernel is willing to queue up for processing while the
    5272                 :            :  * datapath is processing a set of actions. */
    5273                 :            : static bool
    5274                 :      84624 : too_many_output_actions(const struct ofpbuf *odp_actions OVS_UNUSED)
    5275                 :            : {
    5276                 :            : #ifdef __linux__
    5277                 :     169248 :     return (odp_actions->size / NL_A_U32_SIZE > netdev_max_backlog()
    5278 [ -  + ][ #  # ]:      84624 :             && count_output_actions(odp_actions) > netdev_max_backlog());
    5279                 :            : #else
    5280                 :            :     /* OSes other than Linux might have similar limits, but we don't know how
    5281                 :            :      * to determine them.*/
    5282                 :            :     return false;
    5283                 :            : #endif
    5284                 :            : }
    5285                 :            : 
    5286                 :            : static void
    5287                 :      84629 : xlate_wc_init(struct xlate_ctx *ctx)
    5288                 :            : {
    5289                 :      84629 :     flow_wildcards_init_catchall(ctx->wc);
    5290                 :            : 
    5291                 :            :     /* Some fields we consider to always be examined. */
    5292                 :      84629 :     WC_MASK_FIELD(ctx->wc, in_port);
    5293                 :      84629 :     WC_MASK_FIELD(ctx->wc, dl_type);
    5294         [ +  + ]:      84629 :     if (is_ip_any(&ctx->xin->flow)) {
    5295                 :      45634 :         WC_MASK_FIELD_MASK(ctx->wc, nw_frag, FLOW_NW_FRAG_MASK);
    5296                 :            :     }
    5297                 :            : 
    5298         [ +  - ]:      84629 :     if (ctx->xbridge->support.odp.recirc) {
    5299                 :            :         /* Always exactly match recirc_id when datapath supports
    5300                 :            :          * recirculation.  */
    5301                 :      84629 :         WC_MASK_FIELD(ctx->wc, recirc_id);
    5302                 :            :     }
    5303                 :            : 
    5304         [ +  + ]:      84629 :     if (ctx->xbridge->netflow) {
    5305                 :         26 :         netflow_mask_wc(&ctx->xin->flow, ctx->wc);
    5306                 :            :     }
    5307                 :            : 
    5308                 :      84629 :     tnl_wc_init(&ctx->xin->flow, ctx->wc);
    5309                 :      84629 : }
    5310                 :            : 
    5311                 :            : static void
    5312                 :      84625 : xlate_wc_finish(struct xlate_ctx *ctx)
    5313                 :            : {
    5314                 :            :     /* Clear the metadata and register wildcard masks, because we won't
    5315                 :            :      * use non-header fields as part of the cache. */
    5316                 :      84625 :     flow_wildcards_clear_non_packet_fields(ctx->wc);
    5317                 :            : 
    5318                 :            :     /* ICMPv4 and ICMPv6 have 8-bit "type" and "code" fields.  struct flow
    5319                 :            :      * uses the low 8 bits of the 16-bit tp_src and tp_dst members to
    5320                 :            :      * represent these fields.  The datapath interface, on the other hand,
    5321                 :            :      * represents them with just 8 bits each.  This means that if the high
    5322                 :            :      * 8 bits of the masks for these fields somehow become set, then they
    5323                 :            :      * will get chopped off by a round trip through the datapath, and
    5324                 :            :      * revalidation will spot that as an inconsistency and delete the flow.
    5325                 :            :      * Avoid the problem here by making sure that only the low 8 bits of
    5326                 :            :      * either field can be unwildcarded for ICMP.
    5327                 :            :      */
    5328 [ +  + ][ +  + ]:      84625 :     if (is_icmpv4(&ctx->xin->flow, NULL) || is_icmpv6(&ctx->xin->flow, NULL)) {
    5329                 :      29847 :         ctx->wc->masks.tp_src &= htons(UINT8_MAX);
    5330                 :      29847 :         ctx->wc->masks.tp_dst &= htons(UINT8_MAX);
    5331                 :            :     }
    5332                 :            :     /* VLAN_TCI CFI bit must be matched if any of the TCI is matched. */
    5333         [ +  + ]:      84625 :     if (ctx->wc->masks.vlan_tci) {
    5334                 :      62136 :         ctx->wc->masks.vlan_tci |= htons(VLAN_CFI);
    5335                 :            :     }
    5336                 :      84625 : }
    5337                 :            : 
    5338                 :            : /* Translates the flow, actions, or rule in 'xin' into datapath actions in
    5339                 :            :  * 'xout'.
    5340                 :            :  * The caller must take responsibility for eventually freeing 'xout', with
    5341                 :            :  * xlate_out_uninit().
    5342                 :            :  * Returns 'XLATE_OK' if translation was successful.  In case of an error an
    5343                 :            :  * empty set of actions will be returned in 'xin->odp_actions' (if non-NULL),
    5344                 :            :  * so that most callers may ignore the return value and transparently install a
    5345                 :            :  * drop flow when the translation fails. */
    5346                 :            : enum xlate_error
    5347                 :      84629 : xlate_actions(struct xlate_in *xin, struct xlate_out *xout)
    5348                 :            : {
    5349                 :      84629 :     *xout = (struct xlate_out) {
    5350                 :            :         .slow = 0,
    5351                 :            :         .recircs = RECIRC_REFS_EMPTY_INITIALIZER,
    5352                 :            :     };
    5353                 :            : 
    5354                 :      84629 :     struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
    5355                 :      84629 :     struct xbridge *xbridge = xbridge_lookup(xcfg, xin->ofproto);
    5356         [ -  + ]:      84629 :     if (!xbridge) {
    5357                 :          0 :         return XLATE_BRIDGE_NOT_FOUND;
    5358                 :            :     }
    5359                 :            : 
    5360                 :      84629 :     struct flow *flow = &xin->flow;
    5361                 :            : 
    5362                 :            :     union mf_subvalue stack_stub[1024 / sizeof(union mf_subvalue)];
    5363                 :            :     uint64_t action_set_stub[1024 / 8];
    5364                 :            :     uint64_t frozen_actions_stub[1024 / 8];
    5365                 :            :     uint64_t actions_stub[256 / 8];
    5366                 :      84629 :     struct ofpbuf scratch_actions = OFPBUF_STUB_INITIALIZER(actions_stub);
    5367                 :      84629 :     struct xlate_ctx ctx = {
    5368                 :            :         .xin = xin,
    5369                 :            :         .xout = xout,
    5370                 :            :         .base_flow = *flow,
    5371                 :      84629 :         .orig_tunnel_ipv6_dst = flow_tnl_dst(&flow->tunnel),
    5372                 :            :         .xbridge = xbridge,
    5373                 :            :         .stack = OFPBUF_STUB_INITIALIZER(stack_stub),
    5374                 :      84629 :         .rule = xin->rule,
    5375                 :      84629 :         .wc = (xin->wc
    5376                 :            :                ? xin->wc
    5377         [ +  + ]:      84629 :                : &(struct flow_wildcards) { .masks = { .dl_type = 0 } }),
    5378         [ +  + ]:      84629 :         .odp_actions = xin->odp_actions ? xin->odp_actions : &scratch_actions,
    5379                 :            : 
    5380                 :      84629 :         .indentation = xin->indentation,
    5381                 :      84629 :         .depth = xin->depth,
    5382                 :      84629 :         .resubmits = xin->resubmits,
    5383                 :            :         .in_group = false,
    5384                 :            :         .in_action_set = false,
    5385                 :            : 
    5386                 :            :         .table_id = 0,
    5387                 :            :         .rule_cookie = OVS_BE64_MAX,
    5388                 :      84629 :         .orig_skb_priority = flow->skb_priority,
    5389                 :            :         .sflow_n_outputs = 0,
    5390                 :            :         .sflow_odp_port = 0,
    5391                 :            :         .nf_output_iface = NF_OUT_DROP,
    5392                 :            :         .exit = false,
    5393                 :            :         .error = XLATE_OK,
    5394                 :            :         .mirrors = 0,
    5395                 :            : 
    5396                 :            :         .freezing = false,
    5397                 :            :         .frozen_actions = OFPBUF_STUB_INITIALIZER(frozen_actions_stub),
    5398                 :            :         .pause = NULL,
    5399                 :            : 
    5400                 :            :         .was_mpls = false,
    5401                 :            :         .conntracked = false,
    5402                 :            : 
    5403                 :            :         .ct_nat_action = NULL,
    5404                 :            : 
    5405                 :            :         .action_set_has_group = false,
    5406                 :            :         .action_set = OFPBUF_STUB_INITIALIZER(action_set_stub),
    5407                 :            :     };
    5408                 :            : 
    5409                 :            :     /* 'base_flow' reflects the packet as it came in, but we need it to reflect
    5410                 :            :      * the packet as the datapath will treat it for output actions. Our
    5411                 :            :      * datapath doesn't retain tunneling information without us re-setting
    5412                 :            :      * it, so clear the tunnel data.
    5413                 :            :      */
    5414                 :            : 
    5415                 :      84629 :     memset(&ctx.base_flow.tunnel, 0, sizeof ctx.base_flow.tunnel);
    5416                 :            : 
    5417                 :      84629 :     ofpbuf_reserve(ctx.odp_actions, NL_A_U32_SIZE);
    5418                 :      84629 :     xlate_wc_init(&ctx);
    5419                 :            : 
    5420                 :      84629 :     COVERAGE_INC(xlate_actions);
    5421                 :            : 
    5422         [ +  + ]:      84629 :     if (xin->frozen_state) {
    5423                 :       1503 :         const struct frozen_state *state = xin->frozen_state;
    5424                 :            : 
    5425                 :       1503 :         xlate_report(&ctx, "Thawing frozen state:");
    5426                 :            : 
    5427 [ +  - ][ -  + ]:       1503 :         if (xin->ofpacts_len > 0 || ctx.rule) {
    5428                 :            :             static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
    5429         [ #  # ]:          0 :             const char *conflict = xin->ofpacts_len ? "actions" : "rule";
    5430                 :            : 
    5431         [ #  # ]:          0 :             VLOG_WARN_RL(&rl, "Recirculation conflict (%s)!", conflict);
    5432                 :          0 :             xlate_report(&ctx, "- Recirculation conflict (%s)!", conflict);
    5433                 :          0 :             ctx.error = XLATE_RECIRCULATION_CONFLICT;
    5434                 :          0 :             goto exit;
    5435                 :            :         }
    5436                 :            : 
    5437                 :            :         /* Set the bridge for post-recirculation processing if needed. */
    5438         [ +  + ]:       1503 :         if (!uuid_equals(ofproto_dpif_get_uuid(ctx.xbridge->ofproto),
    5439                 :            :                          &state->ofproto_uuid)) {
    5440                 :         19 :             struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
    5441                 :         19 :             const struct xbridge *new_bridge
    5442                 :         19 :                 = xbridge_lookup_by_uuid(xcfg, &state->ofproto_uuid);
    5443                 :            : 
    5444         [ -  + ]:         19 :             if (OVS_UNLIKELY(!new_bridge)) {
    5445                 :            :                 /* Drop the packet if the bridge cannot be found. */
    5446                 :            :                 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
    5447         [ #  # ]:          0 :                 VLOG_WARN_RL(&rl, "Frozen bridge no longer exists.");
    5448                 :          0 :                 xlate_report(&ctx, "- Frozen bridge no longer exists.");
    5449                 :          0 :                 ctx.error = XLATE_BRIDGE_NOT_FOUND;
    5450                 :          0 :                 goto exit;
    5451                 :            :             }
    5452                 :         19 :             ctx.xbridge = new_bridge;
    5453                 :            :         }
    5454                 :            : 
    5455                 :            :         /* Set the thawed table id.  Note: A table lookup is done only if there
    5456                 :            :          * are no frozen actions. */
    5457                 :       1503 :         ctx.table_id = state->table_id;
    5458                 :       1503 :         xlate_report(&ctx, "- Resuming from table %"PRIu8, ctx.table_id);
    5459                 :            : 
    5460         [ +  + ]:       1503 :         if (!state->conntracked) {
    5461                 :        554 :             clear_conntrack(flow);
    5462                 :            :         }
    5463                 :            : 
    5464                 :            :         /* Restore pipeline metadata. May change flow's in_port and other
    5465                 :            :          * metadata to the values that existed when freezing was triggered. */
    5466                 :       1503 :         frozen_metadata_to_flow(&state->metadata, flow);
    5467                 :            : 
    5468                 :            :         /* Restore stack, if any. */
    5469         [ +  + ]:       1503 :         if (state->stack) {
    5470                 :          1 :             ofpbuf_put(&ctx.stack, state->stack,
    5471                 :          1 :                        state->n_stack * sizeof *state->stack);
    5472                 :            :         }
    5473                 :            : 
    5474                 :            :         /* Restore mirror state. */
    5475                 :       1503 :         ctx.mirrors = state->mirrors;
    5476                 :            : 
    5477                 :            :         /* Restore action set, if any. */
    5478         [ +  + ]:       1503 :         if (state->action_set_len) {
    5479                 :          2 :             xlate_report_actions(&ctx, "- Restoring action set",
    5480                 :          2 :                                  state->action_set, state->action_set_len);
    5481                 :            : 
    5482                 :          2 :             flow->actset_output = OFPP_UNSET;
    5483                 :          2 :             xlate_write_actions__(&ctx, state->action_set,
    5484                 :            :                                   state->action_set_len);
    5485                 :            :         }
    5486                 :            : 
    5487                 :            :         /* Restore frozen actions.  If there are no actions, processing will
    5488                 :            :          * start with a lookup in the table set above. */
    5489                 :       1503 :         xin->ofpacts = state->ofpacts;
    5490                 :       1503 :         xin->ofpacts_len = state->ofpacts_len;
    5491         [ +  + ]:       1503 :         if (state->ofpacts_len) {
    5492                 :       1503 :             xlate_report_actions(&ctx, "- Restoring actions",
    5493                 :            :                                  xin->ofpacts, xin->ofpacts_len);
    5494                 :            :         }
    5495         [ -  + ]:      83126 :     } else if (OVS_UNLIKELY(flow->recirc_id)) {
    5496                 :            :         static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
    5497                 :            : 
    5498         [ #  # ]:          0 :         VLOG_WARN_RL(&rl, "Recirculation context not found for ID %"PRIx32,
    5499                 :            :                      flow->recirc_id);
    5500                 :          0 :         ctx.error = XLATE_NO_RECIRCULATION_CONTEXT;
    5501                 :          0 :         goto exit;
    5502                 :            :     }
    5503                 :            :     /* The bridge is now known so obtain its table version. */
    5504                 :      84629 :     ctx.tables_version = ofproto_dpif_get_tables_version(ctx.xbridge->ofproto);
    5505                 :            : 
    5506 [ +  + ][ +  - ]:      84629 :     if (!xin->ofpacts && !ctx.rule) {
    5507                 :      76290 :         ctx.rule = rule_dpif_lookup_from_table(
    5508                 :      76290 :             ctx.xbridge->ofproto, ctx.tables_version, flow, ctx.wc,
    5509                 :      76290 :             ctx.xin->resubmit_stats, &ctx.table_id,
    5510                 :            :             flow->in_port.ofp_port, true, true);
    5511         [ +  + ]:      76290 :         if (ctx.xin->resubmit_stats) {
    5512                 :       8064 :             rule_dpif_credit_stats(ctx.rule, ctx.xin->resubmit_stats);
    5513                 :            :         }
    5514         [ +  + ]:      76290 :         if (ctx.xin->xcache) {
    5515                 :            :             struct xc_entry *entry;
    5516                 :            : 
    5517                 :      68405 :             entry = xlate_cache_add_entry(ctx.xin->xcache, XC_RULE);
    5518                 :      68405 :             entry->u.rule = ctx.rule;
    5519                 :      68405 :             rule_dpif_ref(ctx.rule);
    5520                 :            :         }
    5521                 :            : 
    5522         [ +  + ]:      76290 :         if (OVS_UNLIKELY(ctx.xin->resubmit_hook)) {
    5523                 :        873 :             ctx.xin->resubmit_hook(ctx.xin, ctx.rule, 0);
    5524                 :            :         }
    5525                 :            :     }
    5526                 :            : 
    5527                 :            :     /* Get the proximate input port of the packet.  (If xin->frozen_state,
    5528                 :            :      * flow->in_port is the ultimate input port of the packet.) */
    5529                 :      84629 :     struct xport *in_port = get_ofp_port(xbridge,
    5530                 :            :                                          ctx.base_flow.in_port.ofp_port);
    5531                 :            : 
    5532                 :            :     /* Tunnel stats only for not-thawed packets. */
    5533 [ +  + ][ +  + ]:      84628 :     if (!xin->frozen_state && in_port && in_port->is_tunnel) {
                 [ +  + ]
    5534         [ +  + ]:       9218 :         if (ctx.xin->resubmit_stats) {
    5535                 :       1120 :             netdev_vport_inc_rx(in_port->netdev, ctx.xin->resubmit_stats);
    5536         [ -  + ]:       1120 :             if (in_port->bfd) {
    5537                 :          0 :                 bfd_account_rx(in_port->bfd, ctx.xin->resubmit_stats);
    5538                 :            :             }
    5539                 :            :         }
    5540         [ +  + ]:       9218 :         if (ctx.xin->xcache) {
    5541                 :            :             struct xc_entry *entry;
    5542                 :            : 
    5543                 :       8327 :             entry = xlate_cache_add_entry(ctx.xin->xcache, XC_NETDEV);
    5544                 :       8327 :             entry->u.dev.rx = netdev_ref(in_port->netdev);
    5545                 :       8327 :             entry->u.dev.bfd = bfd_ref(in_port->bfd);
    5546                 :            :         }
    5547                 :            :     }
    5548                 :            : 
    5549 [ +  + ][ +  + ]:      84628 :     if (!xin->frozen_state && process_special(&ctx, in_port)) {
    5550                 :            :         /* process_special() did all the processing for this packet.
    5551                 :            :          *
    5552                 :            :          * We do not perform special processing on thawed packets, since that
    5553                 :            :          * was done before they were frozen and should not be redone. */
    5554 [ +  + ][ +  + ]:      84526 :     } else if (in_port && in_port->xbundle
    5555         [ -  + ]:      76176 :                && xbundle_mirror_out(xbridge, in_port->xbundle)) {
    5556         [ #  # ]:          0 :         if (ctx.xin->packet != NULL) {
    5557                 :            :             static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
    5558         [ #  # ]:          0 :             VLOG_WARN_RL(&rl, "bridge %s: dropping packet received on port "
    5559                 :            :                          "%s, which is reserved exclusively for mirroring",
    5560                 :            :                          ctx.xbridge->name, in_port->xbundle->name);
    5561                 :            :         }
    5562                 :            :     } else {
    5563                 :            :         /* Sampling is done on initial reception; don't redo after thawing. */
    5564                 :      84527 :         unsigned int user_cookie_offset = 0;
    5565         [ +  + ]:      84527 :         if (!xin->frozen_state) {
    5566                 :      83024 :             user_cookie_offset = compose_sflow_action(&ctx);
    5567                 :      83024 :             compose_ipfix_action(&ctx, ODPP_NONE);
    5568                 :            :         }
    5569                 :      84527 :         size_t sample_actions_len = ctx.odp_actions->size;
    5570                 :            : 
    5571         [ +  + ]:      84527 :         if (tnl_process_ecn(flow)
    5572 [ +  + ][ +  - ]:      84526 :             && (!in_port || may_receive(in_port, &ctx))) {
    5573                 :            :             const struct ofpact *ofpacts;
    5574                 :            :             size_t ofpacts_len;
    5575                 :            : 
    5576         [ +  + ]:      84526 :             if (xin->ofpacts) {
    5577                 :       8339 :                 ofpacts = xin->ofpacts;
    5578                 :       8339 :                 ofpacts_len = xin->ofpacts_len;
    5579         [ +  - ]:      76187 :             } else if (ctx.rule) {
    5580                 :      76187 :                 const struct rule_actions *actions
    5581                 :      76187 :                     = rule_dpif_get_actions(ctx.rule);
    5582                 :      76187 :                 ofpacts = actions->ofpacts;
    5583                 :      76187 :                 ofpacts_len = actions->ofpacts_len;
    5584                 :      76187 :                 ctx.rule_cookie = rule_dpif_get_flow_cookie(ctx.rule);
    5585                 :            :             } else {
    5586                 :          0 :                 OVS_NOT_REACHED();
    5587                 :            :             }
    5588                 :            : 
    5589                 :      84526 :             mirror_ingress_packet(&ctx);
    5590                 :      84526 :             do_xlate_actions(ofpacts, ofpacts_len, &ctx);
    5591         [ +  + ]:      84526 :             if (ctx.error) {
    5592                 :          4 :                 goto exit;
    5593                 :            :             }
    5594                 :            : 
    5595                 :            :             /* We've let OFPP_NORMAL and the learning action look at the
    5596                 :            :              * packet, so cancel all actions and freezing if forwarding is
    5597                 :            :              * disabled. */
    5598         [ +  + ]:     160835 :             if (in_port && (!xport_stp_forward_state(in_port) ||
           [ +  -  -  + ]
    5599                 :      76313 :                             !xport_rstp_forward_state(in_port))) {
    5600                 :          0 :                 ctx.odp_actions->size = sample_actions_len;
    5601                 :          0 :                 ctx_cancel_freeze(&ctx);
    5602                 :          0 :                 ofpbuf_clear(&ctx.action_set);
    5603                 :            :             }
    5604                 :            : 
    5605         [ +  + ]:      84522 :             if (!ctx.freezing) {
    5606                 :      84216 :                 xlate_action_set(&ctx);
    5607                 :            :             }
    5608         [ +  + ]:      84522 :             if (ctx.freezing) {
    5609                 :        306 :                 finish_freezing(&ctx);
    5610                 :            :             }
    5611                 :            :         }
    5612                 :            : 
    5613                 :            :         /* Output only fully processed packets. */
    5614         [ +  - ]:      84523 :         if (!ctx.freezing
    5615         [ -  + ]:      84523 :             && xbridge->has_in_band
    5616         [ #  # ]:          0 :             && in_band_must_output_to_local_port(flow)
    5617         [ #  # ]:          0 :             && !actions_output_to_local_port(&ctx)) {
    5618                 :          0 :             compose_output_action(&ctx, OFPP_LOCAL, NULL);
    5619                 :            :         }
    5620                 :            : 
    5621         [ +  + ]:      84523 :         if (user_cookie_offset) {
    5622                 :         21 :             fix_sflow_action(&ctx, user_cookie_offset);
    5623                 :            :         }
    5624                 :            :     }
    5625                 :            : 
    5626         [ +  + ]:      84625 :     if (nl_attr_oversized(ctx.odp_actions->size)) {
    5627                 :            :         /* These datapath actions are too big for a Netlink attribute, so we
    5628                 :            :          * can't hand them to the kernel directly.  dpif_execute() can execute
    5629                 :            :          * them one by one with help, so just mark the result as SLOW_ACTION to
    5630                 :            :          * prevent the flow from being installed. */
    5631                 :          1 :         COVERAGE_INC(xlate_actions_oversize);
    5632                 :          1 :         ctx.xout->slow |= SLOW_ACTION;
    5633         [ -  + ]:      84624 :     } else if (too_many_output_actions(ctx.odp_actions)) {
    5634                 :          0 :         COVERAGE_INC(xlate_actions_too_many_output);
    5635                 :          0 :         ctx.xout->slow |= SLOW_ACTION;
    5636                 :            :     }
    5637                 :            : 
    5638                 :            :     /* Do netflow only for packets on initial reception, that are not sent to
    5639                 :            :      * the controller.  We consider packets sent to the controller to be part
    5640                 :            :      * of the control plane rather than the data plane. */
    5641         [ +  + ]:      84625 :     if (!xin->frozen_state
    5642         [ +  + ]:      83122 :         && xbridge->netflow
    5643         [ +  - ]:         26 :         && !(xout->slow & SLOW_CONTROLLER)) {
    5644         [ +  + ]:         26 :         if (ctx.xin->resubmit_stats) {
    5645                 :         12 :             netflow_flow_update(xbridge->netflow, flow,
    5646                 :            :                                 ctx.nf_output_iface,
    5647                 :         12 :                                 ctx.xin->resubmit_stats);
    5648                 :            :         }
    5649         [ +  + ]:         26 :         if (ctx.xin->xcache) {
    5650                 :            :             struct xc_entry *entry;
    5651                 :            : 
    5652                 :         14 :             entry = xlate_cache_add_entry(ctx.xin->xcache, XC_NETFLOW);
    5653                 :         14 :             entry->u.nf.netflow = netflow_ref(xbridge->netflow);
    5654                 :         14 :             entry->u.nf.flow = xmemdup(flow, sizeof *flow);
    5655                 :         14 :             entry->u.nf.iface = ctx.nf_output_iface;
    5656                 :            :         }
    5657                 :            :     }
    5658                 :            : 
    5659                 :      84625 :     xlate_wc_finish(&ctx);
    5660                 :            : 
    5661                 :            : exit:
    5662                 :      84629 :     ofpbuf_uninit(&ctx.stack);
    5663                 :      84629 :     ofpbuf_uninit(&ctx.action_set);
    5664                 :      84629 :     ofpbuf_uninit(&ctx.frozen_actions);
    5665                 :      84629 :     ofpbuf_uninit(&scratch_actions);
    5666                 :            : 
    5667                 :            :     /* Make sure we return a "drop flow" in case of an error. */
    5668         [ +  + ]:      84629 :     if (ctx.error) {
    5669                 :          4 :         xout->slow = 0;
    5670         [ +  - ]:          4 :         if (xin->odp_actions) {
    5671                 :          4 :             ofpbuf_clear(xin->odp_actions);
    5672                 :            :         }
    5673                 :            :     }
    5674                 :      84629 :     return ctx.error;
    5675                 :            : }
    5676                 :            : 
    5677                 :            : enum ofperr
    5678                 :        199 : xlate_resume(struct ofproto_dpif *ofproto,
    5679                 :            :              const struct ofputil_packet_in_private *pin,
    5680                 :            :              struct ofpbuf *odp_actions,
    5681                 :            :              enum slow_path_reason *slow)
    5682                 :            : {
    5683                 :            :     struct dp_packet packet;
    5684                 :        199 :     dp_packet_use_const(&packet, pin->public.packet,
    5685                 :            :                         pin->public.packet_len);
    5686                 :            : 
    5687                 :            :     struct flow flow;
    5688                 :        199 :     flow_extract(&packet, &flow);
    5689                 :            : 
    5690                 :            :     struct xlate_in xin;
    5691                 :        199 :     xlate_in_init(&xin, ofproto, &flow, 0, NULL, ntohs(flow.tcp_flags),
    5692                 :            :                   &packet, NULL, odp_actions);
    5693                 :            : 
    5694                 :            :     struct ofpact_note noop;
    5695                 :        199 :     ofpact_init_NOTE(&noop);
    5696                 :        199 :     noop.length = 0;
    5697                 :            : 
    5698                 :        199 :     bool any_actions = pin->actions_len > 0;
    5699                 :       1791 :     struct frozen_state state = {
    5700                 :            :         .table_id = 0,     /* Not the table where NXAST_PAUSE was executed. */
    5701                 :            :         .ofproto_uuid = pin->bridge,
    5702                 :        199 :         .stack = pin->stack,
    5703                 :        199 :         .n_stack = pin->n_stack,
    5704                 :        199 :         .mirrors = pin->mirrors,
    5705                 :        199 :         .conntracked = pin->conntracked,
    5706                 :            : 
    5707                 :            :         /* When there are no actions, xlate_actions() will search the flow
    5708                 :            :          * table.  We don't want it to do that (we want it to resume), so
    5709                 :            :          * supply a no-op action if there aren't any.
    5710                 :            :          *
    5711                 :            :          * (We can't necessarily avoid translating actions entirely if there
    5712                 :            :          * aren't any actions, because there might be some finishing-up to do
    5713                 :            :          * at the end of the pipeline, and we don't check for those
    5714                 :            :          * conditions.) */
    5715         [ +  + ]:        199 :         .ofpacts = any_actions ? pin->actions : &noop.ofpact,
    5716         [ +  + ]:        199 :         .ofpacts_len = any_actions ? pin->actions_len : sizeof noop,
    5717                 :            : 
    5718                 :        199 :         .action_set = pin->action_set,
    5719                 :        199 :         .action_set_len = pin->action_set_len,
    5720                 :            :     };
    5721                 :        199 :     frozen_metadata_from_flow(&state.metadata,
    5722                 :            :                               &pin->public.flow_metadata.flow);
    5723                 :        199 :     xin.frozen_state = &state;
    5724                 :            : 
    5725                 :            :     struct xlate_out xout;
    5726                 :        199 :     enum xlate_error error = xlate_actions(&xin, &xout);
    5727                 :        199 :     *slow = xout.slow;
    5728                 :        199 :     xlate_out_uninit(&xout);
    5729                 :            : 
    5730                 :            :     /* xlate_actions() can generate a number of errors, but only
    5731                 :            :      * XLATE_BRIDGE_NOT_FOUND really stands out to me as one that we should be
    5732                 :            :      * sure to report over OpenFlow.  The others could come up in packet-outs
    5733                 :            :      * or regular flow translation and I don't think that it's going to be too
    5734                 :            :      * useful to report them to the controller. */
    5735         [ -  + ]:        199 :     return error == XLATE_BRIDGE_NOT_FOUND ? OFPERR_NXR_STALE : 0;
    5736                 :            : }
    5737                 :            : 
    5738                 :            : /* Sends 'packet' out 'ofport'. If 'port' is a tunnel and that tunnel type
    5739                 :            :  * supports a notion of an OAM flag, sets it if 'oam' is true.
    5740                 :            :  * May modify 'packet'.
    5741                 :            :  * Returns 0 if successful, otherwise a positive errno value. */
    5742                 :            : int
    5743                 :       6534 : xlate_send_packet(const struct ofport_dpif *ofport, bool oam,
    5744                 :            :                   struct dp_packet *packet)
    5745                 :            : {
    5746                 :       6534 :     struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
    5747                 :            :     struct xport *xport;
    5748                 :            :     uint64_t ofpacts_stub[1024 / 8];
    5749                 :            :     struct ofpbuf ofpacts;
    5750                 :            :     struct flow flow;
    5751                 :            : 
    5752                 :       6534 :     ofpbuf_use_stack(&ofpacts, ofpacts_stub, sizeof ofpacts_stub);
    5753                 :            :     /* Use OFPP_NONE as the in_port to avoid special packet processing. */
    5754                 :       6534 :     flow_extract(packet, &flow);
    5755                 :       6534 :     flow.in_port.ofp_port = OFPP_NONE;
    5756                 :            : 
    5757                 :       6534 :     xport = xport_lookup(xcfg, ofport);
    5758         [ +  + ]:       6534 :     if (!xport) {
    5759                 :         46 :         return EINVAL;
    5760                 :            :     }
    5761                 :            : 
    5762         [ -  + ]:       6488 :     if (oam) {
    5763                 :          0 :         const ovs_be16 oam = htons(NX_TUN_FLAG_OAM);
    5764                 :          0 :         ofpact_put_set_field(&ofpacts, mf_from_id(MFF_TUN_FLAGS), &oam, &oam);
    5765                 :            :     }
    5766                 :            : 
    5767                 :       6488 :     ofpact_put_OUTPUT(&ofpacts)->port = xport->ofp_port;
    5768                 :            : 
    5769                 :       6534 :     return ofproto_dpif_execute_actions(xport->xbridge->ofproto, &flow, NULL,
    5770                 :      12976 :                                         ofpacts.data, ofpacts.size, packet);
    5771                 :            : }
    5772                 :            : 
    5773                 :            : struct xlate_cache *
    5774                 :       3611 : xlate_cache_new(void)
    5775                 :            : {
    5776                 :       3611 :     struct xlate_cache *xcache = xmalloc(sizeof *xcache);
    5777                 :            : 
    5778                 :       3611 :     ofpbuf_init(&xcache->entries, 512);
    5779                 :       3611 :     return xcache;
    5780                 :            : }
    5781                 :            : 
    5782                 :            : static struct xc_entry *
    5783                 :    1198882 : xlate_cache_add_entry(struct xlate_cache *xcache, enum xc_type type)
    5784                 :            : {
    5785                 :            :     struct xc_entry *entry;
    5786                 :            : 
    5787                 :    1198882 :     entry = ofpbuf_put_zeros(&xcache->entries, sizeof *entry);
    5788                 :    1198882 :     entry->type = type;
    5789                 :            : 
    5790                 :    1198882 :     return entry;
    5791                 :            : }
    5792                 :            : 
    5793                 :            : static void
    5794                 :       1039 : xlate_cache_netdev(struct xc_entry *entry, const struct dpif_flow_stats *stats)
    5795                 :            : {
    5796         [ +  + ]:       1039 :     if (entry->u.dev.tx) {
    5797                 :        332 :         netdev_vport_inc_tx(entry->u.dev.tx, stats);
    5798                 :            :     }
    5799         [ +  + ]:       1039 :     if (entry->u.dev.rx) {
    5800                 :        898 :         netdev_vport_inc_rx(entry->u.dev.rx, stats);
    5801                 :            :     }
    5802         [ -  + ]:       1039 :     if (entry->u.dev.bfd) {
    5803                 :          0 :         bfd_account_rx(entry->u.dev.bfd, stats);
    5804                 :            :     }
    5805                 :       1039 : }
    5806                 :            : 
    5807                 :            : static void
    5808                 :       2385 : xlate_cache_normal(struct ofproto_dpif *ofproto, struct flow *flow, int vlan)
    5809                 :            : {
    5810                 :       2385 :     struct xlate_cfg *xcfg = ovsrcu_get(struct xlate_cfg *, &xcfgp);
    5811                 :            :     struct xbridge *xbridge;
    5812                 :            :     struct xbundle *xbundle;
    5813                 :            :     struct flow_wildcards wc;
    5814                 :            : 
    5815                 :       2385 :     xbridge = xbridge_lookup(xcfg, ofproto);
    5816         [ -  + ]:       2385 :     if (!xbridge) {
    5817                 :         59 :         return;
    5818                 :            :     }
    5819                 :            : 
    5820                 :       2385 :     xbundle = lookup_input_bundle(xbridge, flow->in_port.ofp_port, false,
    5821                 :            :                                   NULL);
    5822         [ +  + ]:       2385 :     if (!xbundle) {
    5823                 :         59 :         return;
    5824                 :            :     }
    5825                 :            : 
    5826                 :       2326 :     update_learning_table(xbridge, flow, &wc, vlan, xbundle);
    5827                 :            : }
    5828                 :            : 
    5829                 :            : /* Push stats and perform side effects of flow translation. */
    5830                 :            : void
    5831                 :       4210 : xlate_push_stats(struct xlate_cache *xcache,
    5832                 :            :                  const struct dpif_flow_stats *stats)
    5833                 :            : {
    5834                 :            :     struct xc_entry *entry;
    5835                 :       4210 :     struct ofpbuf entries = xcache->entries;
    5836                 :            :     struct eth_addr dmac;
    5837                 :            : 
    5838         [ +  + ]:       4210 :     if (!stats->n_packets) {
    5839                 :         10 :         return;
    5840                 :            :     }
    5841                 :            : 
    5842         [ +  + ]:      35436 :     XC_ENTRY_FOR_EACH (entry, entries, xcache) {
    5843   [ +  -  +  +  :      31236 :         switch (entry->type) {
          +  +  +  -  -  
                   +  - ]
    5844                 :            :         case XC_RULE:
    5845                 :      27448 :             rule_dpif_credit_stats(entry->u.rule, stats);
    5846                 :      27448 :             break;
    5847                 :            :         case XC_BOND:
    5848                 :          0 :             bond_account(entry->u.bond.bond, entry->u.bond.flow,
    5849                 :          0 :                          entry->u.bond.vid, stats->n_bytes);
    5850                 :          0 :             break;
    5851                 :            :         case XC_NETDEV:
    5852                 :       1039 :             xlate_cache_netdev(entry, stats);
    5853                 :       1039 :             break;
    5854                 :            :         case XC_NETFLOW:
    5855                 :        240 :             netflow_flow_update(entry->u.nf.netflow, entry->u.nf.flow,
    5856                 :            :                                 entry->u.nf.iface, stats);
    5857                 :        240 :             break;
    5858                 :            :         case XC_MIRROR:
    5859                 :          1 :             mirror_update_stats(entry->u.mirror.mbridge,
    5860                 :            :                                 entry->u.mirror.mirrors,
    5861                 :            :                                 stats->n_packets, stats->n_bytes);
    5862                 :          1 :             break;
    5863                 :            :         case XC_LEARN:
    5864                 :          3 :             ofproto_dpif_flow_mod(entry->u.learn.ofproto, entry->u.learn.fm);
    5865                 :          3 :             break;
    5866                 :            :         case XC_NORMAL:
    5867                 :       2385 :             xlate_cache_normal(entry->u.normal.ofproto, entry->u.normal.flow,
    5868                 :            :                                entry->u.normal.vlan);
    5869                 :       2385 :             break;
    5870                 :            :         case XC_FIN_TIMEOUT:
    5871                 :          0 :             xlate_fin_timeout__(entry->u.fin.rule, stats->tcp_flags,
    5872                 :          0 :                                 entry->u.fin.idle, entry->u.fin.hard);
    5873                 :          0 :             break;
    5874                 :            :         case XC_GROUP:
    5875                 :          0 :             group_dpif_credit_stats(entry->u.group.group, entry->u.group.bucket,
    5876                 :            :                                     stats);
    5877                 :          0 :             break;
    5878                 :            :         case XC_TNL_NEIGH:
    5879                 :            :             /* Lookup neighbor to avoid timeout. */
    5880                 :        120 :             tnl_neigh_lookup(entry->u.tnl_neigh_cache.br_name,
    5881                 :        120 :                              &entry->u.tnl_neigh_cache.d_ipv6, &dmac);
    5882                 :        120 :             break;
    5883                 :            :         default:
    5884                 :          0 :             OVS_NOT_REACHED();
    5885                 :            :         }
    5886                 :            :     }
    5887                 :            : }
    5888                 :            : 
    5889                 :            : static void
    5890                 :      37118 : xlate_dev_unref(struct xc_entry *entry)
    5891                 :            : {
    5892         [ +  + ]:      37118 :     if (entry->u.dev.tx) {
    5893                 :      28791 :         netdev_close(entry->u.dev.tx);
    5894                 :            :     }
    5895         [ +  + ]:      37118 :     if (entry->u.dev.rx) {
    5896                 :      36365 :         netdev_close(entry->u.dev.rx);
    5897                 :            :     }
    5898         [ -  + ]:      37118 :     if (entry->u.dev.bfd) {
    5899                 :          0 :         bfd_unref(entry->u.dev.bfd);
    5900                 :            :     }
    5901                 :      37118 : }
    5902                 :            : 
    5903                 :            : static void
    5904                 :         12 : xlate_cache_clear_netflow(struct netflow *netflow, struct flow *flow)
    5905                 :            : {
    5906                 :         12 :     netflow_flow_clear(netflow, flow);
    5907                 :         12 :     netflow_unref(netflow);
    5908                 :         12 :     free(flow);
    5909                 :         12 : }
    5910                 :            : 
    5911                 :            : void
    5912                 :      74464 : xlate_cache_clear(struct xlate_cache *xcache)
    5913                 :            : {
    5914                 :            :     struct xc_entry *entry;
    5915                 :            :     struct ofpbuf entries;
    5916                 :            : 
    5917         [ +  + ]:      74464 :     if (!xcache) {
    5918                 :       6075 :         return;
    5919                 :            :     }
    5920                 :            : 
    5921         [ +  + ]:    1267240 :     XC_ENTRY_FOR_EACH (entry, entries, xcache) {
    5922   [ +  +  +  +  :    1198851 :         switch (entry->type) {
          +  +  +  -  +  
                   +  - ]
    5923                 :            :         case XC_RULE:
    5924                 :    1138806 :             rule_dpif_unref(entry->u.rule);
    5925                 :    1138806 :             break;
    5926                 :            :         case XC_BOND:
    5927                 :       5998 :             free(entry->u.bond.flow);
    5928                 :       5998 :             bond_unref(entry->u.bond.bond);
    5929                 :       5998 :             break;
    5930                 :            :         case XC_NETDEV:
    5931                 :      37118 :             xlate_dev_unref(entry);
    5932                 :      37118 :             break;
    5933                 :            :         case XC_NETFLOW:
    5934                 :         12 :             xlate_cache_clear_netflow(entry->u.nf.netflow, entry->u.nf.flow);
    5935                 :         12 :             break;
    5936                 :            :         case XC_MIRROR:
    5937                 :          5 :             mbridge_unref(entry->u.mirror.mbridge);
    5938                 :          5 :             break;
    5939                 :            :         case XC_LEARN:
    5940                 :         11 :             free(entry->u.learn.fm);
    5941                 :         11 :             ofpbuf_delete(entry->u.learn.ofpacts);
    5942                 :         11 :             break;
    5943                 :            :         case XC_NORMAL:
    5944                 :      16145 :             free(entry->u.normal.flow);
    5945                 :      16145 :             break;
    5946                 :            :         case XC_FIN_TIMEOUT:
    5947                 :            :             /* 'u.fin.rule' is always already held as a XC_RULE, which
    5948                 :            :              * has already released it's reference above. */
    5949                 :          0 :             break;
    5950                 :            :         case XC_GROUP:
    5951                 :         50 :             group_dpif_unref(entry->u.group.group);
    5952                 :         50 :             break;
    5953                 :            :         case XC_TNL_NEIGH:
    5954                 :        706 :             break;
    5955                 :            :         default:
    5956                 :          0 :             OVS_NOT_REACHED();
    5957                 :            :         }
    5958                 :            :     }
    5959                 :            : 
    5960                 :      68389 :     ofpbuf_clear(&xcache->entries);
    5961                 :            : }
    5962                 :            : 
    5963                 :            : void
    5964                 :       6723 : xlate_cache_delete(struct xlate_cache *xcache)
    5965                 :            : {
    5966                 :       6723 :     xlate_cache_clear(xcache);
    5967                 :       6723 :     ofpbuf_uninit(&xcache->entries);
    5968                 :       6723 :     free(xcache);
    5969                 :       6723 : }

Generated by: LCOV version 1.12