@@ -93,35 +93,44 @@ func setEndpointOptions(cnsNwConfig *cns.GetNetworkContainerResponse, epInfo *ne
9393func addSnatInterface (nwCfg * cni.NetworkConfig , result * cniTypesCurr.Result ) {
9494}
9595
96- func updateSubnetPrefix (cnsNwConfig * cns.GetNetworkContainerResponse , subnetPrefix * net.IPNet ) {
96+ func updateSubnetPrefix (cnsNwConfig * cns.GetNetworkContainerResponse , subnetPrefix * net.IPNet ) error {
9797 if cnsNwConfig != nil && cnsNwConfig .MultiTenancyInfo .ID != 0 {
9898 ipconfig := cnsNwConfig .IPConfiguration
9999 ipAddr := net .ParseIP (ipconfig .IPSubnet .IPAddress )
100-
101100 if ipAddr .To4 () != nil {
102- * subnetPrefix = net.IPNet {IP : ipAddr , Mask : net .CIDRMask (int (ipconfig .IPSubnet .PrefixLength ), 32 )}
101+ * subnetPrefix = net.IPNet {Mask : net .CIDRMask (int (ipconfig .IPSubnet .PrefixLength ), 32 )}
102+ } else if ipAddr .To16 () != nil {
103+ * subnetPrefix = net.IPNet {Mask : net .CIDRMask (int (ipconfig .IPSubnet .PrefixLength ), 128 )}
103104 } else {
104- * subnetPrefix = net. IPNet { IP : ipAddr , Mask : net . CIDRMask ( int ( ipconfig . IPSubnet . PrefixLength ), 128 )}
105+ return fmt . Errorf ( "[cni-net] Failed to get mask from CNS network configuration" )
105106 }
106107
107- subnetPrefix .IP = subnetPrefix . IP .Mask (subnetPrefix .Mask )
108+ subnetPrefix .IP = ipAddr .Mask (subnetPrefix .Mask )
108109 log .Printf ("Updated subnetPrefix: %s" , subnetPrefix .String ())
109110 }
111+
112+ return nil
110113}
111114
112- func getNetworkName (podName , podNs , ifName string , nwCfg * cni.NetworkConfig ) (string , error ) {
115+ func getNetworkName (podName , podNs , ifName string , nwCfg * cni.NetworkConfig ) (networkName string , err error ) {
116+ networkName = nwCfg .Name
117+ err = nil
113118 if nwCfg .MultiTenancy {
114119 _ , cnsNetworkConfig , _ , err := getContainerNetworkConfiguration (nwCfg , podName , podNs , ifName )
115120 if err != nil {
116121 log .Printf ("GetContainerNetworkConfiguration failed for podname %v namespace %v with error %v" , podName , podNs , err )
117- return "" , err
122+ } else {
123+ var subnet net.IPNet
124+ if err = updateSubnetPrefix (cnsNetworkConfig , & subnet ); err == nil {
125+ // networkName will look like ~ azure-vlan1-172-28-1-0_24
126+ networkName = strings .Replace (subnet .String (), "." , "-" , - 1 )
127+ networkName = strings .Replace (networkName , "/" , "_" , - 1 )
128+ networkName = fmt .Sprintf ("%s-vlan%v-%v" , nwCfg .Name , cnsNetworkConfig .MultiTenancyInfo .ID , networkName )
129+ }
118130 }
119-
120- networkName := fmt .Sprintf ("%s-vlanid%v" , nwCfg .Name , cnsNetworkConfig .MultiTenancyInfo .ID )
121- return networkName , nil
122131 }
123132
124- return nwCfg . Name , nil
133+ return
125134}
126135
127136func setupInfraVnetRoutingForMultitenancy (
0 commit comments