@@ -76,6 +76,7 @@ struct eth_context {
76
76
};
77
77
78
78
static const char * if_name_cmd_opt ;
79
+ static const char * mac_addr_cmd_opt ;
79
80
#ifdef CONFIG_NET_IPV4
80
81
static const char * ipv4_addr_cmd_opt ;
81
82
static const char * ipv4_nm_cmd_opt ;
@@ -307,6 +308,10 @@ static void eth_iface_init(struct net_if *iface)
307
308
{
308
309
struct eth_context * ctx = net_if_get_device (iface )-> data ;
309
310
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
310
315
#ifdef CONFIG_NET_IPV4
311
316
struct in_addr addr , netmask ;
312
317
#endif
@@ -343,11 +348,9 @@ static void eth_iface_init(struct net_if *iface)
343
348
BUILD_ASSERT (CONFIG_ETH_NATIVE_TAP_INTERFACE_COUNT == 1 ,
344
349
"Cannot have static MAC if interface count > 1" );
345
350
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 );
351
354
}
352
355
}
353
356
#endif
@@ -642,6 +645,14 @@ static void add_native_tap_options(void)
642
645
.dest = (void * )& if_name_cmd_opt ,
643
646
.descript = "Name of the eth interface to use" ,
644
647
},
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
+ },
645
656
#ifdef CONFIG_NET_IPV4
646
657
{
647
658
.is_mandatory = false,
0 commit comments