Extract allocation logic from ipallocator and portallocator

IP and ports allocation shared a same strategy for automatically assigning slots inside a given range: this strategy is extracted and refactored (this idea was raised while reviewing #8699). The `ipallocator` and `portallocator` logics remain unchanged (it's just adaptations). Benchmarks results with this patch are very similar.