#include <rte_string_fns.h>
#include <rte_acl.h>
+#include <cmdline_parse.h>
+#include <cmdline_parse_etheraddr.h>
+
#if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
#define L3FWDACL_DEBUG
#endif
static uint16_t nb_rxd = RTE_TEST_RX_DESC_DEFAULT;
static uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT;
-/* ethernet addresses of ports */
-static struct rte_ether_addr ports_eth_addr[RTE_MAX_ETHPORTS];
-
/* mask of enabled ports */
static uint32_t enabled_port_mask;
static int promiscuous_on; /**< Ports set in promiscuous mode off by default. */
static struct rte_mempool *pktmbuf_pool[NB_SOCKETS];
+/* ethernet addresses of ports */
+static struct rte_ether_hdr port_l2hdr[RTE_MAX_ETHPORTS];
+
/***********************start of ACL part******************************/
#ifdef DO_RFC_1812_CHECKS
static inline int
#define OPTION_RULE_IPV4 "rule_ipv4"
#define OPTION_RULE_IPV6 "rule_ipv6"
#define OPTION_SCALAR "scalar"
+#define OPTION_ETH_DEST "eth-dest"
#define ACL_DENY_SIGNATURE 0xf0000000
#define RTE_LOGTYPE_L3FWDACL RTE_LOGTYPE_USER3
#define acl_log(format, ...) RTE_LOG(ERR, L3FWDACL, format, ##__VA_ARGS__)
{
uint32_t lcore_id;
struct lcore_conf *qconf;
+ struct rte_ether_hdr *eh;
lcore_id = rte_lcore_id();
+ /* update src and dst mac*/
+ eh = rte_pktmbuf_mtod(m, struct rte_ether_hdr *);
+ memcpy(eh, &port_l2hdr[port], sizeof(eh->d_addr) + sizeof(eh->s_addr));
+
qconf = &lcore_conf[lcore_id];
rte_eth_tx_buffer(port, qconf->tx_queue_id[port],
qconf->tx_buffer[port], m);
return 0;
}
+static const char *
+parse_eth_dest(const char *optarg)
+{
+ unsigned long portid;
+ char *port_end;
+
+ errno = 0;
+ portid = strtoul(optarg, &port_end, 0);
+ if (errno != 0 || port_end == optarg || *port_end++ != ',')
+ return "Invalid format";
+ else if (portid >= RTE_MAX_ETHPORTS)
+ return "port value exceeds RTE_MAX_ETHPORTS("
+ RTE_STR(RTE_MAX_ETHPORTS) ")";
+
+ if (cmdline_parse_etheraddr(NULL, port_end, &port_l2hdr[portid].d_addr,
+ sizeof(port_l2hdr[portid].d_addr)) < 0)
+ return "Invalid ethernet address";
+ return NULL;
+}
+
/* Parse the argument given in the command line of the application */
static int
parse_args(int argc, char **argv)
{OPTION_RULE_IPV4, 1, 0, 0},
{OPTION_RULE_IPV6, 1, 0, 0},
{OPTION_SCALAR, 0, 0, 0},
+ {OPTION_ETH_DEST, 1, 0, 0},
{NULL, 0, 0, 0}
};
OPTION_SCALAR, sizeof(OPTION_SCALAR)))
parm_config.scalar = 1;
+ if (!strncmp(lgopts[option_index].name, OPTION_ETH_DEST,
+ sizeof(OPTION_ETH_DEST))) {
+ const char *serr = parse_eth_dest(optarg);
+ if (serr != NULL) {
+ printf("invalid %s value:\"%s\": %s\n",
+ OPTION_ETH_DEST, optarg, serr);
+ print_usage(prgname);
+ return -1;
+ }
+ }
break;
}
}
+/*
+ * build-up default vaues for dest MACs.
+ */
+static void
+set_default_dest_mac(void)
+{
+ uint32_t i;
+
+ for (i = 0; i != RTE_DIM(port_l2hdr); i++) {
+ port_l2hdr[i].d_addr.addr_bytes[0] = RTE_ETHER_LOCAL_ADMIN_ADDR;
+ port_l2hdr[i].d_addr.addr_bytes[5] = i;
+ }
+}
+
int
main(int argc, char **argv)
{
argc -= ret;
argv += ret;
+ set_default_dest_mac();
+
/* parse application arguments (after the EAL ones) */
ret = parse_args(argc, argv);
if (ret < 0)
"rte_eth_dev_adjust_nb_rx_tx_desc: err=%d, port=%d\n",
ret, portid);
- ret = rte_eth_macaddr_get(portid, &ports_eth_addr[portid]);
+ ret = rte_eth_macaddr_get(portid, &port_l2hdr[portid].s_addr);
if (ret < 0)
rte_exit(EXIT_FAILURE,
"rte_eth_macaddr_get: err=%d, port=%d\n",
ret, portid);
- print_ethaddr(" Address:", &ports_eth_addr[portid]);
+ print_ethaddr("Dst MAC:", &port_l2hdr[portid].d_addr);
+ print_ethaddr(", Src MAC:", &port_l2hdr[portid].s_addr);
printf(", ");
/* init memory */