Two ways of doing it...

Create multiple instances of the network stack

Pack all global variables into a container and
pass reference to the container along

Each network stack is completely independent

FreeBSD vimage is based on this idea