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.
What do you mean? I think it's good: first we scan `]last, end]` and then we try `[begin, last[`, isn't it?