Determining whether a gateway is needed