Skip to content

Commit d890630

Browse files
IVandeVeirekartben
authored andcommitted
drivers: eth: native_tap: Add MAC parameter input from cmd line
Add the ability to set the MAC address from the command line when running a native sim build. Signed-off-by: Ibe Van de Veire <ibe.vandeveire@basalte.be>
1 parent 8a63970 commit d890630

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

drivers/ethernet/eth_native_tap.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ struct eth_context {
7676
};
7777

7878
static const char *if_name_cmd_opt;
79+
static const char *mac_addr_cmd_opt;
7980
#ifdef CONFIG_NET_IPV4
8081
static const char *ipv4_addr_cmd_opt;
8182
static const char *ipv4_nm_cmd_opt;
@@ -307,6 +308,10 @@ static void eth_iface_init(struct net_if *iface)
307308
{
308309
struct eth_context *ctx = net_if_get_device(iface)->data;
309310
struct net_linkaddr *ll_addr = eth_get_mac(ctx);
311+
#if !defined(CONFIG_ETH_NATIVE_TAP_RANDOM_MAC)
312+
const char *mac_addr =
313+
mac_addr_cmd_opt ? mac_addr_cmd_opt : CONFIG_ETH_NATIVE_TAP_MAC_ADDR;
314+
#endif
310315
#ifdef CONFIG_NET_IPV4
311316
struct in_addr addr, netmask;
312317
#endif
@@ -343,11 +348,9 @@ static void eth_iface_init(struct net_if *iface)
343348
BUILD_ASSERT(CONFIG_ETH_NATIVE_TAP_INTERFACE_COUNT == 1,
344349
"Cannot have static MAC if interface count > 1");
345350

346-
if (CONFIG_ETH_NATIVE_TAP_MAC_ADDR[0] != 0) {
347-
if (net_bytes_from_str(ctx->mac_addr, sizeof(ctx->mac_addr),
348-
CONFIG_ETH_NATIVE_TAP_MAC_ADDR) < 0) {
349-
LOG_ERR("Invalid MAC address %s",
350-
CONFIG_ETH_NATIVE_TAP_MAC_ADDR);
351+
if (mac_addr[0] != 0) {
352+
if (net_bytes_from_str(ctx->mac_addr, sizeof(ctx->mac_addr), mac_addr) < 0) {
353+
LOG_ERR("Invalid MAC address %s", mac_addr);
351354
}
352355
}
353356
#endif
@@ -642,6 +645,14 @@ static void add_native_tap_options(void)
642645
.dest = (void *)&if_name_cmd_opt,
643646
.descript = "Name of the eth interface to use",
644647
},
648+
{
649+
.is_mandatory = false,
650+
.option = "mac-addr",
651+
.name = "mac",
652+
.type = 's',
653+
.dest = (void *)&mac_addr_cmd_opt,
654+
.descript = "MAC address",
655+
},
645656
#ifdef CONFIG_NET_IPV4
646657
{
647658
.is_mandatory = false,

0 commit comments

Comments
 (0)