IMHO this big statement could be moved/mutualized in the if(transport->settings->GatewayEnabled) that is below, as this is just in TSG mode