@@ -131,6 +131,7 @@ function create_wg_interface(nsid, ifname, ifcfg, netns) {
131131 return true ;
132132 }
133133
134+
134135 if (!interface_exists_netns (ifname , netns )) {
135136 // TODO: use once ucode-mod-rtnl supports target_netnsid
136137 //
@@ -377,7 +378,7 @@ function wireguard_maintenance(st, cfg) {
377378 continue ;
378379 }
379380
380- // refill candidates if neccessary , but skip servers that are already in use
381+ // refill candidates if necessary , but skip servers that are already in use
381382 if (length (st .candidates ) == 0 ) {
382383 st .candidates = filter (keys (cfg .wireguard_servers ), function (name ) {
383384 return index (in_use , name ) == -1 && !cfg .wireguard_servers [name ].disabled ;
@@ -456,7 +457,23 @@ function uplink_maintenance(cfg) {
456457 shell_command ("ip -n " +netns +" link set " +netnsifname +" up" );
457458 } else if (mode == "bridge" ) {
458459 // or create a macvlan bridge:
459- shell_command ("ip link add " +netnsifname +" link " +ifname +" type macvlan mode bridge" );
460+
461+ // Generate a deterministic mac first
462+ let mac = split (trim (fs .readfile ("/sys/class/net/" +ifname +"/address" )), ":" );
463+ let changedpart = hex (mac [5 ]);
464+ // Adds 2 to the hex-value, but subtracts 2 if we are to high to avoid counting over ff
465+ if (changedpart <= 167 ){
466+ changedpart = changedpart + 2 ;
467+ } else {
468+ changedpart = changedpart - 2 ;
469+ }
470+
471+ changedpart = sprintf ("%x" ,changedpart ); // convert dec to hex
472+ pop (mac );
473+ push (mac , changedpart );
474+ mac = join (":" ,mac );
475+
476+ shell_command ("ip link add " +netnsifname +" address " +mac +" link " +ifname +" type macvlan mode bridge" );
460477 shell_command ("ip link set dev " +netnsifname +" netns " +netns );
461478 shell_command ("ip -n " +netns +" link set up " +netnsifname +"" );
462479 } else {
0 commit comments