here's the logic of it from the routeros client, near this line - https://github.com/ispapp/ispapp-routeros-client/blob/master/ispapp.rsc#L1937
here's the logic of it from the routeros client, near this line - https://github.com/ispapp/ispapp-routeros-client/blob/master/ispapp.rsc#L1937