This patch adds a new option to enable/disable the
MAC addresses updating done at forwarding time: --[no-]mac-updating

By default, MAC address updating remains enabled, to keep consistency
with previous usage.

Signed-off-by: Kuba Kozak <kubax.ko...@intel.com>
---
 doc/guides/sample_app_ug/l2_forward_crypto.rst |  7 ++--
 examples/l2fwd-crypto/main.c                   | 50 ++++++++++++++++++++++----
 2 files changed, 48 insertions(+), 9 deletions(-)

diff --git a/doc/guides/sample_app_ug/l2_forward_crypto.rst 
b/doc/guides/sample_app_ug/l2_forward_crypto.rst
index 2a61af7..91ce278 100644
--- a/doc/guides/sample_app_ug/l2_forward_crypto.rst
+++ b/doc/guides/sample_app_ug/l2_forward_crypto.rst
@@ -46,7 +46,7 @@ for each packet that is received on a RX_PORT and performs L2 
forwarding.
 The destination port is the adjacent port from the enabled portmask, that is,
 if the first four ports are enabled (portmask 0xf),
 ports 0 and 1 forward into each other, and ports 2 and 3 forward into each 
other.
-Also, the MAC addresses are affected as follows:
+Also, if MAC addresses updating is enabled, the MAC addresses are affected as 
follows:
 
 *   The source MAC address is replaced by the TX_PORT MAC address
 
@@ -90,7 +90,8 @@ The application requires a number of command line options:
     [--auth_algo ALGO] [--auth_op GENERATE/VERIFY] [--auth_key KEY] /
     [--auth_key_random_size SIZE] [--auth_iv IV] [--auth_iv_random_size SIZE] /
     [--aad AAD] [--aad_random_size SIZE] /
-    [--digest size SIZE] [--sessionless] [--cryptodev_mask MASK]
+    [--digest size SIZE] [--sessionless] [--cryptodev_mask MASK] /
+    [--mac-updating] [--no-mac-updating]
 
 where,
 
@@ -191,6 +192,8 @@ where,
 
     (default is all cryptodevs).
 
+*   [no-]mac-updating: Enable or disable MAC addresses updating (enabled by 
default).
+
 
 The application requires that crypto devices capable of performing
 the specified crypto operation are available on application initialization.
diff --git a/examples/l2fwd-crypto/main.c b/examples/l2fwd-crypto/main.c
index 71cb133..a347ad6 100644
--- a/examples/l2fwd-crypto/main.c
+++ b/examples/l2fwd-crypto/main.c
@@ -193,6 +193,8 @@ struct l2fwd_crypto_options {
        char string_type[MAX_STR_LEN];
 
        uint64_t cryptodev_mask;
+
+       unsigned int mac_updating;
 };
 
 /** l2fwd crypto lcore params */
@@ -608,21 +610,31 @@ l2fwd_send_packet(struct rte_mbuf *m, uint8_t port)
 }
 
 static void
-l2fwd_simple_forward(struct rte_mbuf *m, unsigned portid)
+l2fwd_mac_updating(struct rte_mbuf *m, unsigned int dest_portid)
 {
        struct ether_hdr *eth;
        void *tmp;
-       unsigned dst_port;
 
-       dst_port = l2fwd_dst_ports[portid];
        eth = rte_pktmbuf_mtod(m, struct ether_hdr *);
 
        /* 02:00:00:00:00:xx */
        tmp = &eth->d_addr.addr_bytes[0];
-       *((uint64_t *)tmp) = 0x000000000002 + ((uint64_t)dst_port << 40);
+       *((uint64_t *)tmp) = 0x000000000002 + ((uint64_t)dest_portid << 40);
 
        /* src addr */
-       ether_addr_copy(&l2fwd_ports_eth_addr[dst_port], &eth->s_addr);
+       ether_addr_copy(&l2fwd_ports_eth_addr[dest_portid], &eth->s_addr);
+}
+
+static void
+l2fwd_simple_forward(struct rte_mbuf *m, unsigned int portid,
+               struct l2fwd_crypto_options *options)
+{
+       unsigned int dst_port;
+
+       dst_port = l2fwd_dst_ports[portid];
+
+       if (options->mac_updating)
+               l2fwd_mac_updating(m, dst_port);
 
        l2fwd_send_packet(m, (uint8_t) dst_port);
 }
@@ -920,7 +932,8 @@ l2fwd_main_loop(struct l2fwd_crypto_options *options)
                                        m = ops_burst[j]->sym->m_src;
 
                                        rte_crypto_op_free(ops_burst[j]);
-                                       l2fwd_simple_forward(m, portid);
+                                       l2fwd_simple_forward(m, portid,
+                                                       options);
                                }
                        } while (nb_rx == MAX_PKT_BURST);
                }
@@ -975,7 +988,12 @@ l2fwd_crypto_usage(const char *prgname)
                "  --digest_size SIZE: size of digest to be 
generated/verified\n"
 
                "  --sessionless\n"
-               "  --cryptodev_mask MASK: hexadecimal bitmask of crypto devices 
to configure\n",
+               "  --cryptodev_mask MASK: hexadecimal bitmask of crypto devices 
to configure\n"
+
+               "  --[no-]mac-updating: Enable or disable MAC addresses 
updating (enabled by default)\n"
+               "      When enabled:\n"
+               "       - The source MAC address is replaced by the TX port MAC 
address\n"
+               "       - The destination MAC address is replaced by 
02:00:00:00:00:TX_PORT_ID\n",
               prgname);
 }
 
@@ -1322,6 +1340,16 @@ l2fwd_crypto_parse_args_long_options(struct 
l2fwd_crypto_options *options,
        else if (strcmp(lgopts[option_index].name, "cryptodev_mask") == 0)
                return parse_cryptodev_mask(options, optarg);
 
+       else if (strcmp(lgopts[option_index].name, "mac-updating") == 0) {
+               options->mac_updating = 1;
+               return 0;
+       }
+
+       else if (strcmp(lgopts[option_index].name, "no-mac-updating") == 0) {
+               options->mac_updating = 0;
+               return 0;
+       }
+
        return -1;
 }
 
@@ -1455,6 +1483,8 @@ l2fwd_crypto_default_options(struct l2fwd_crypto_options 
*options)
 
        options->type = CDEV_TYPE_ANY;
        options->cryptodev_mask = UINT64_MAX;
+
+       options->mac_updating = 1;
 }
 
 static void
@@ -1616,6 +1646,9 @@ l2fwd_crypto_parse_args(struct l2fwd_crypto_options 
*options,
                        { "sessionless", no_argument, 0, 0 },
                        { "cryptodev_mask", required_argument, 0, 0},
 
+                       { "mac-updating", no_argument, 0, 0},
+                       { "no-mac-updating", no_argument, 0, 0},
+
                        { NULL, 0, 0, 0 }
        };
 
@@ -2438,6 +2471,9 @@ main(int argc, char **argv)
        if (ret < 0)
                rte_exit(EXIT_FAILURE, "Invalid L2FWD-CRYPTO arguments\n");
 
+       printf("MAC updating %s\n",
+                       options.mac_updating ? "enabled" : "disabled");
+
        /* create the mbuf pool */
        l2fwd_pktmbuf_pool = rte_pktmbuf_pool_create("mbuf_pool", NB_MBUF, 512,
                        sizeof(struct rte_crypto_op),
-- 
2.7.4

Reply via email to