src/Cedar/VLanWin32.c
// End the tracking of the routing table

End the tracking of the routing table
End the tracking of the routing table
void RouteTrackingStop(SESSION *s, ROUTE_TRACKING *t)
{
	ROUTE_ENTRY *e;
	ROUTE_TABLE *table;
	IP dns_ip;
	bool network_has_changed = false;
	bool do_not_delete_routing_entry = false;
	if (s == NULL || t == NULL)
	{
		return;
	}
	Zero(&dns_ip, sizeof(dns_ip));
	if (MsIsVista() == false)
	{
		if (t->DefaultGatewayByVLan != NULL)
		{
			Debug("Default Gateway by VLAN was deleted.\n");
			DeleteRouteEntry(t->DefaultGatewayByVLan);
		}
		if (t->VistaOldDefaultGatewayByVLan != NULL)
		{
			FreeRouteEntry(t->VistaOldDefaultGatewayByVLan);
		}
	}
	if (t->DefaultGatewayByVLan != NULL)
	{
		FreeRouteEntry(t->DefaultGatewayByVLan);
		t->DefaultGatewayByVLan = NULL;
	}
	if (t->VistaDefaultGateway1 != NULL)
	{
		Debug("Vista PPP Fix Route Table Deleted.\n");
		DeleteRouteEntry(t->VistaDefaultGateway1);
		FreeRouteEntry(t->VistaDefaultGateway1);
		DeleteRouteEntry(t->VistaDefaultGateway2);
		FreeRouteEntry(t->VistaDefaultGateway2);
	}
	if (MsIsNt() == false)
	{
		Win32ReleaseDhcp9x(t->VLanInterfaceId, false);
	}
	Win32FlushDnsCache();
	if (s->Cedar->Client != NULL && s->Account != NULL)
	{
		UINT i;
		ACCOUNT *a;
		for (i = 0;i < LIST_NUM(s->Cedar->Client->AccountList);i++)
		{
			a = LIST_DATA(s->Cedar->Client->AccountList, i);
			Lock(a->lock);
			{
				SESSION *sess = a->ClientSession;
				if (sess != NULL && sess != s)
				{
					VLAN *v = sess->PacketAdapter->Param;
					if (v != NULL)
					{
						ROUTE_TRACKING *tr = v->RouteState;
						if (tr != NULL)
						{
							if (Cmp(tr->RouteToServer, t->RouteToServer, sizeof(ROUTE_ENTRY)) == 0)
							{
								do_not_delete_routing_entry = true;
							}
						}
					}
				}
			}
			Unlock(a->lock);
		}
		Lock(s->Account->lock);
	}
	if (do_not_delete_routing_entry == false)
	{
		if (t->RouteToServerAlreadyExists == false)
		{
			DeleteRouteEntry(t->RouteToServer);
		}
		DeleteRouteEntry(t->RouteToDefaultDns);
		DeleteRouteEntry(t->RouteToNatTServer);
		DeleteRouteEntry(t->RouteToRealServerGlobal);
	}
	FreeRouteEntry(t->RouteToDefaultDns);
	FreeRouteEntry(t->RouteToServer);
	FreeRouteEntry(t->RouteToEight);
	FreeRouteEntry(t->RouteToNatTServer);
	FreeRouteEntry(t->RouteToRealServerGlobal);
	t->RouteToDefaultDns = t->RouteToServer = t->RouteToEight =
		t->RouteToNatTServer = t->RouteToRealServerGlobal = NULL;
	if (s->Cedar->Client != NULL && s->Account != NULL)
	{
		Unlock(s->Account->lock);
	}
#if	0
	if (GetDefaultDns(&dns_ip))
	{
		if (IPToUINT(&t->OldDnsServer) != 0)
		{
			if (IPToUINT(&t->OldDnsServer) != IPToUINT(&dns_ip))
			{
				char s1[MAX_SIZE], s2[MAX_SIZE];
				network_has_changed = true;
				IPToStr(s1, sizeof(s1), &t->OldDnsServer);
				IPToStr(s2, sizeof(s2), &dns_ip);
				Debug("Old Dns: %s, New Dns: %s\n",
					s1, s2);
			}
		}
	}
	if (network_has_changed == false)
	{
		Debug("Network: not changed.\n");
	}
	else
	{
		Debug("Network: Changed.\n");
	}
#endif
	table = GetRouteTable();
	while (e = GetNext(t->DeletedDefaultGateway))
	{
		bool restore = true;
		UINT i;
		if (IPToUINT(&e->DestIP) == 0 && IPToUINT(&e->DestMask) == 0)
		{
			for (i = 0;i < table->NumEntry;i++)
			{
				ROUTE_ENTRY *r = table->Entry[i];
				if (IPToUINT(&r->DestIP) == 0 && IPToUINT(&r->DestMask) == 0)
				{
					if (r->InterfaceID == e->InterfaceID)
					{
						restore = false;
					}
				}
			}
			if (network_has_changed)
			{
				restore = false;
			}
		}
		if (restore)
		{
			AddRouteEntry(e);
		}
		FreeRouteEntry(e);
	}
	FreeRouteTable(table);
	ReleaseQueue(t->DeletedDefaultGateway);
	FreeRouteChange(t->RouteChange);
	Free(t);
}
void RouteTrackingStop ( SESSION * s , ROUTE_TRACKING * t ) { ROUTE_ENTRY * e ; ROUTE_TABLE * table ; IP dns_ip ; bool network_has_changed = false ; bool do_not_delete_routing_entry = false ; if ( s == NULL || t == NULL ) { return ; } Zero ( & dns_ip , sizeof ( dns_ip ) ) ; if ( MsIsVista ( ) == false ) { if ( t -> DefaultGatewayByVLan != NULL ) { Debug ( " \n " ) ; DeleteRouteEntry ( t -> DefaultGatewayByVLan ) ; } if ( t -> VistaOldDefaultGatewayByVLan != NULL ) { FreeRouteEntry ( t -> VistaOldDefaultGatewayByVLan ) ; } } if ( t -> DefaultGatewayByVLan != NULL ) { FreeRouteEntry ( t -> DefaultGatewayByVLan ) ; t -> DefaultGatewayByVLan = NULL ; } if ( t -> VistaDefaultGateway1 != NULL ) { Debug ( " \n " ) ; DeleteRouteEntry ( t -> VistaDefaultGateway1 ) ; FreeRouteEntry ( t -> VistaDefaultGateway1 ) ; DeleteRouteEntry ( t -> VistaDefaultGateway2 ) ; FreeRouteEntry ( t -> VistaDefaultGateway2 ) ; } if ( MsIsNt ( ) == false ) { Win32ReleaseDhcp9x ( t -> VLanInterfaceId , false ) ; } Win32FlushDnsCache ( ) ; if ( s -> Cedar -> Client != NULL && s -> Account != NULL ) { UINT i ; ACCOUNT * a ; for ( i = 0 ; i < LIST_NUM ( s -> Cedar -> Client -> AccountList ) ; i ++ ) { a = LIST_DATA ( s -> Cedar -> Client -> AccountList , i ) ; Lock ( a -> lock ) ; { SESSION * sess = a -> ClientSession ; if ( sess != NULL && sess != s ) { VLAN * v = sess -> PacketAdapter -> Param ; if ( v != NULL ) { ROUTE_TRACKING * tr = v -> RouteState ; if ( tr != NULL ) { if ( Cmp ( tr -> RouteToServer , t -> RouteToServer , sizeof ( ROUTE_ENTRY ) ) == 0 ) { do_not_delete_routing_entry = true ; } } } } } Unlock ( a -> lock ) ; } Lock ( s -> Account -> lock ) ; } if ( do_not_delete_routing_entry == false ) { if ( t -> RouteToServerAlreadyExists == false ) { DeleteRouteEntry ( t -> RouteToServer ) ; } DeleteRouteEntry ( t -> RouteToDefaultDns ) ; DeleteRouteEntry ( t -> RouteToNatTServer ) ; DeleteRouteEntry ( t -> RouteToRealServerGlobal ) ; } FreeRouteEntry ( t -> RouteToDefaultDns ) ; FreeRouteEntry ( t -> RouteToServer ) ; FreeRouteEntry ( t -> RouteToEight ) ; FreeRouteEntry ( t -> RouteToNatTServer ) ; FreeRouteEntry ( t -> RouteToRealServerGlobal ) ; t -> RouteToDefaultDns = t -> RouteToServer = t -> RouteToEight = t -> RouteToNatTServer = t -> RouteToRealServerGlobal = NULL ; if ( s -> Cedar -> Client != NULL && s -> Account != NULL ) { Unlock ( s -> Account -> lock ) ; } #if 0 if ( GetDefaultDns ( & dns_ip ) ) { if ( IPToUINT ( & t -> OldDnsServer ) != 0 ) { if ( IPToUINT ( & t -> OldDnsServer ) != IPToUINT ( & dns_ip ) ) { char s1 [ MAX_SIZE ] , s2 [ MAX_SIZE ] ; network_has_changed = true ; IPToStr ( s1 , sizeof ( s1 ) , & t -> OldDnsServer ) ; IPToStr ( s2 , sizeof ( s2 ) , & dns_ip ) ; Debug ( " \n " , s1 , s2 ) ; } } } if ( network_has_changed == false ) { Debug ( " \n " ) ; } else { Debug ( " \n " ) ; } #endif table = GetRouteTable ( ) ; while ( e = GetNext ( t -> DeletedDefaultGateway ) ) { bool restore = true ; UINT i ; if ( IPToUINT ( & e -> DestIP ) == 0 && IPToUINT ( & e -> DestMask ) == 0 ) { for ( i = 0 ; i < table -> NumEntry ; i ++ ) { ROUTE_ENTRY * r = table -> Entry [ i ] ; if ( IPToUINT ( & r -> DestIP ) == 0 && IPToUINT ( & r -> DestMask ) == 0 ) { if ( r -> InterfaceID == e -> InterfaceID ) { restore = false ; } } } if ( network_has_changed ) { restore = false ; } } if ( restore ) { AddRouteEntry ( e ) ; } FreeRouteEntry ( e ) ; } FreeRouteTable ( table ) ; ReleaseQueue ( t -> DeletedDefaultGateway ) ; FreeRouteChange ( t -> RouteChange ) ; Free ( t ) ; }
End the tracking of the routing table
End the tracking of the routing table
// Validate arguments
 // Remove the default gateway added by the virtual LAN card
 // Only in the case of Windows 9x, release the DHCP address of the virtual LAN card
 // Clear the DNS cache
 // Delete the route that is added firstly
 // Get the current DNS server
 // Get the current routing table
 // Restore the routing table which has been removed so far
 // If the restoring routing entry is a default gateway and
 // the existing routing table contains another default gateway
 // on the interface, give up restoring the entry
 // Routing table restoration
 // Memory release
 // Release
