@@ -115,7 +115,14 @@ static struct in6_addr peer_addr = { { { 0x20, 0x01, 0x0d, 0xb8, 0, 0, 0, 0,
115
115
116
116
/* Keep track of all ethernet interfaces */
117
117
static struct net_if * eth_interfaces [NET_ETH_MAX_COUNT ];
118
- static struct net_if * vlan_interfaces [NET_VLAN_MAX_COUNT ];
118
+
119
+ #if NET_VLAN_MAX_COUNT > 0
120
+ #define MAX_IFACE_VLAN_COUNT NET_VLAN_MAX_COUNT
121
+ #else
122
+ #define MAX_IFACE_VLAN_COUNT 1
123
+ #endif
124
+
125
+ static struct net_if * vlan_interfaces [MAX_IFACE_VLAN_COUNT ];
119
126
static struct net_if * dummy_interfaces [2 ];
120
127
static struct net_if * embed_ll_interface ;
121
128
static struct net_if * test_iface ;
@@ -433,7 +440,7 @@ static void iface_cb(struct net_if *iface, void *user_data)
433
440
if (net_if_l2 (iface ) == & NET_L2_GET_NAME (VIRTUAL )) {
434
441
vlan_interfaces [ud -> vlan_if_count ++ ] = iface ;
435
442
436
- zassert_true (ud -> vlan_if_count <= NET_VLAN_MAX_COUNT ,
443
+ zassert_true (ud -> vlan_if_count <= MAX_IFACE_VLAN_COUNT ,
437
444
"Too many VLAN interfaces" );
438
445
}
439
446
@@ -458,16 +465,20 @@ static void test_vlan_setup(void)
458
465
/* Make sure we have enough virtual interfaces */
459
466
net_if_foreach (iface_cb , & ud );
460
467
468
+ if (NET_VLAN_MAX_COUNT == 0 ) {
469
+ return ;
470
+ }
471
+
461
472
/* One extra eth interface without vlan support */
462
- zassert_equal (ud .vlan_if_count , NET_VLAN_MAX_COUNT ,
473
+ zassert_equal (ud .vlan_if_count , MAX_IFACE_VLAN_COUNT ,
463
474
"Invalid number of VLANs %d vs %d" ,
464
- ud .vlan_if_count , NET_VLAN_MAX_COUNT );
475
+ ud .vlan_if_count , MAX_IFACE_VLAN_COUNT );
465
476
466
- remaining = ud .total_if_count - NET_VLAN_MAX_COUNT -
477
+ remaining = ud .total_if_count - MAX_IFACE_VLAN_COUNT -
467
478
ud .eth_if_count - ud .dummy_if_count ;
468
479
zassert_equal (remaining , 0 ,
469
480
"Invalid number of interfaces expecting %d got %d+%d+%d" ,
470
- ud .total_if_count , NET_VLAN_MAX_COUNT ,
481
+ ud .total_if_count , MAX_IFACE_VLAN_COUNT ,
471
482
ud .eth_if_count , ud .dummy_if_count );
472
483
}
473
484
@@ -478,11 +489,14 @@ static void test_address_setup(void)
478
489
479
490
iface1 = eth_interfaces [1 ]; /* This has VLAN enabled */
480
491
iface2 = eth_interfaces [0 ]; /* and this one not */
481
- iface3 = vlan_interfaces [0 ]; /* and this is the virtual VLAN interface */
482
492
483
493
zassert_not_null (iface1 , "Interface 1" );
484
494
zassert_not_null (iface2 , "Interface 2" );
485
- zassert_not_null (iface3 , "Interface 3" );
495
+
496
+ if (NET_VLAN_MAX_COUNT > 0 ) {
497
+ iface3 = vlan_interfaces [0 ]; /* and this is the virtual VLAN interface */
498
+ zassert_not_null (iface3 , "Interface 3" );
499
+ }
486
500
487
501
ifaddr = net_if_ipv6_addr_add (iface1 , & my_addr1 ,
488
502
NET_ADDR_MANUAL , 0 );
@@ -515,15 +529,17 @@ static void test_address_setup(void)
515
529
516
530
ifaddr -> addr_state = NET_ADDR_PREFERRED ;
517
531
518
- ifaddr = net_if_ipv6_addr_add (iface3 , & my_addr3 ,
519
- NET_ADDR_MANUAL , 0 );
520
- if (!ifaddr ) {
521
- DBG ("Cannot add IPv6 address %s\n" ,
522
- net_sprint_ipv6_addr (& my_addr3 ));
523
- zassert_not_null (ifaddr , "addr3" );
524
- }
532
+ if (NET_VLAN_MAX_COUNT > 0 ) {
533
+ ifaddr = net_if_ipv6_addr_add (iface3 , & my_addr3 ,
534
+ NET_ADDR_MANUAL , 0 );
535
+ if (!ifaddr ) {
536
+ DBG ("Cannot add IPv6 address %s\n" ,
537
+ net_sprint_ipv6_addr (& my_addr3 ));
538
+ zassert_not_null (ifaddr , "addr3" );
539
+ }
525
540
526
- ifaddr -> addr_state = NET_ADDR_PREFERRED ;
541
+ ifaddr -> addr_state = NET_ADDR_PREFERRED ;
542
+ }
527
543
528
544
net_if_up (iface1 );
529
545
net_if_up (iface2 );
@@ -639,6 +655,10 @@ static void test_vlan_enable(void)
639
655
struct net_if * iface ;
640
656
int ret ;
641
657
658
+ if (NET_VLAN_MAX_COUNT == 0 ) {
659
+ return ;
660
+ }
661
+
642
662
ret = net_eth_vlan_enable (eth_interfaces [0 ], VLAN_TAG_1 );
643
663
zassert_equal (ret , 0 , "Cannot enable %d (%d)" , VLAN_TAG_1 , ret );
644
664
ret = net_eth_vlan_enable (eth_interfaces [0 ], VLAN_TAG_2 );
@@ -714,6 +734,10 @@ static void test_vlan_disable(void)
714
734
struct net_if * iface ;
715
735
int ret ;
716
736
737
+ if (NET_VLAN_MAX_COUNT == 0 ) {
738
+ return ;
739
+ }
740
+
717
741
ret = net_eth_vlan_disable (eth_interfaces [1 ], VLAN_TAG_1 );
718
742
zassert_not_equal (ret , 0 , "Could disable %d (%d)" , VLAN_TAG_1 , ret );
719
743
@@ -759,6 +783,10 @@ static void test_vlan_enable_all(void)
759
783
struct net_if * iface ;
760
784
int ret ;
761
785
786
+ if (NET_VLAN_MAX_COUNT == 0 ) {
787
+ return ;
788
+ }
789
+
762
790
ret = net_eth_vlan_enable (eth_interfaces [0 ], VLAN_TAG_1 );
763
791
zassert_true (ret == 0 || ret == - EALREADY , "Cannot enable %d" , VLAN_TAG_1 );
764
792
ret = net_eth_vlan_enable (eth_interfaces [0 ], VLAN_TAG_2 );
@@ -798,6 +826,10 @@ static void test_vlan_disable_all(void)
798
826
struct net_if * iface ;
799
827
int ret ;
800
828
829
+ if (NET_VLAN_MAX_COUNT == 0 ) {
830
+ return ;
831
+ }
832
+
801
833
ret = net_eth_vlan_disable (eth_interfaces [0 ], VLAN_TAG_1 );
802
834
zassert_equal (ret , 0 , "Cannot disable %d" , VLAN_TAG_1 );
803
835
ret = net_eth_vlan_disable (eth_interfaces [0 ], VLAN_TAG_2 );
@@ -903,6 +935,10 @@ ZTEST(net_vlan, test_vlan_ipv6_sendto_recvfrom)
903
935
struct sockaddr_in6 server_addr ;
904
936
struct eth_context * ctx ;
905
937
938
+ if (NET_VLAN_MAX_COUNT == 0 ) {
939
+ return ;
940
+ }
941
+
906
942
/* Setup the interfaces */
907
943
test_vlan_enable ();
908
944
test_vlan_disable_all ();
@@ -966,6 +1002,10 @@ ZTEST(net_vlan, test_zz_vlan_embed_ll_hdr)
966
1002
static struct in6_addr peer_vlan_addr = { { { 0x20 , 0x01 , 0x0d , 0xb8 , 0x90 , 0 , 0 , 0 ,
967
1003
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0x1 } } };
968
1004
1005
+ if (NET_VLAN_MAX_COUNT == 0 ) {
1006
+ return ;
1007
+ }
1008
+
969
1009
ret = net_eth_vlan_enable (embed_ll_interface , VLAN_TAG_6 );
970
1010
zassert_equal (ret , 0 , "Could not enable %d (%d)" , VLAN_TAG_6 , ret );
971
1011
@@ -1068,7 +1108,11 @@ ZTEST(net_vlan, test_vlan_tag_0)
1068
1108
struct net_pkt * pkt ;
1069
1109
int ret ;
1070
1110
1071
- iface = vlan_interfaces [0 ];
1111
+ if (NET_VLAN_MAX_COUNT > 0 ) {
1112
+ iface = vlan_interfaces [0 ];
1113
+ } else {
1114
+ iface = eth_interfaces [0 ];
1115
+ }
1072
1116
1073
1117
dev = net_if_get_device (eth_interfaces [0 ]);
1074
1118
context = dev -> data ;
@@ -1077,14 +1121,20 @@ ZTEST(net_vlan, test_vlan_tag_0)
1077
1121
memcpy (& icmpv6_echo_request [0 ], context -> mac_addr , 6 );
1078
1122
1079
1123
net_if_down (eth_interfaces [0 ]);
1080
- net_if_down (vlan_interfaces [0 ]);
1081
1124
1082
- /* Setup the interfaces */
1083
- ret = net_eth_vlan_enable (eth_interfaces [0 ], VLAN_TAG_7 );
1084
- zassert_equal (ret , 0 , "Cannot enable %d (%d)" , VLAN_TAG_7 , ret );
1125
+ if (NET_VLAN_MAX_COUNT > 0 ) {
1126
+ net_if_down (vlan_interfaces [0 ]);
1127
+
1128
+ /* Setup the interfaces */
1129
+ ret = net_eth_vlan_enable (eth_interfaces [0 ], VLAN_TAG_7 );
1130
+ zassert_equal (ret , 0 , "Cannot enable %d (%d)" , VLAN_TAG_7 , ret );
1131
+ }
1085
1132
1086
1133
net_if_up (eth_interfaces [0 ]);
1087
- net_if_up (vlan_interfaces [0 ]);
1134
+
1135
+ if (NET_VLAN_MAX_COUNT > 0 ) {
1136
+ net_if_up (vlan_interfaces [0 ]);
1137
+ }
1088
1138
1089
1139
ret = add_peer_neighbor (iface , & peer_addr , & icmpv6_echo_request [0 ]);
1090
1140
zassert_true (ret , "Cannot add neighbor" );
0 commit comments