// Release the packet adapter void VLanPaFree(SESSION *s) { VLAN *v; ROUTE_TRACKING *t; // Validate arguments if ((s == NULL) || ((v = s->PacketAdapter->Param) == NULL)) { return; } // Release the IP address if you are using DHCP if (IsNt()) { char tmp[MAX_SIZE]; MS_ADAPTER *a; UINT64 now = Tick64(); UINT64 suspend_tick = MsGetSuspendModeBeginTick(); if (suspend_tick == 0 || (suspend_tick + (UINT64)(30 * 1000)) < now) { Format(tmp, sizeof(tmp), VLAN_ADAPTER_NAME_TAG, v->InstanceName); a = MsGetAdapter(tmp); if (a != NULL) { if (a->UseDhcp) { bool ret = Win32ReleaseAddressByGuidEx(a->Guid, 50); Debug("*** Win32ReleaseAddressByGuid = %u\n", ret); } MsFreeAdapter(a); } } } t = v->RouteState; // End the virtual LAN card FreeVLan(v); // End the routing table tracking if (s->ClientModeAndUseVLan) { RouteTrackingStop(s, t); } s->PacketAdapter->Param = NULL; }
// Start tracking of the routing table void RouteTrackingStart(SESSION *s) { VLAN *v; ROUTE_TRACKING *t; UINT if_id = 0; ROUTE_ENTRY *e; ROUTE_ENTRY *dns = NULL; ROUTE_ENTRY *route_to_real_server_global = NULL; char tmp[64]; UINT exclude_if_id = 0; bool already_exists = false; bool already_exists_by_other_account = false; IP eight; // Validate arguments if (s == NULL) { return; } v = (VLAN *)s->PacketAdapter->Param; if (v->RouteState != NULL) { return; } // Get the interface ID of the virtual LAN card if_id = GetInstanceId(v->InstanceName); Debug("[InstanceId of %s] = 0x%x\n", v->InstanceName, if_id); if (MsIsVista()) { // The routing table by the virtual LAN card body should be // excluded explicitly in Windows Vista exclude_if_id = if_id; } // Get the route to the server e = GetBestRouteEntryEx(&s->ServerIP, exclude_if_id); if (e == NULL) { // Acquisition failure Debug("Failed to get GetBestRouteEntry().\n"); return; } IPToStr(tmp, sizeof(tmp), &e->GatewayIP); Debug("GetBestRouteEntry() Succeed. [Gateway: %s]\n", tmp); // Add a route if (MsIsVista()) { e->Metric = e->OldIfMetric; } if (AddRouteEntryEx(e, &already_exists) == false) { FreeRouteEntry(e); e = NULL; } Debug("already_exists: %u\n", already_exists); if (already_exists) { 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 && e != NULL) { if (Cmp(tr->RouteToServer, e, sizeof(ROUTE_ENTRY)) == 0) { already_exists_by_other_account = true; } } } } } Unlock(a->lock); } } if (already_exists_by_other_account) { Debug("already_exists_by_other_account = %u\n", already_exists_by_other_account); already_exists = false; } } // Get the routing table to the DNS server // (If the DNS server is this PC itself, there's no need to get) if (IsZeroIP(&s->DefaultDns) == false) { if (IsMyIPAddress(&s->DefaultDns) == false) { dns = GetBestRouteEntryEx(&s->DefaultDns, exclude_if_id); if (dns == NULL) { // Getting failure Debug("Failed to get GetBestRouteEntry DNS.\n"); } else { // Add a route if (MsIsVista()) { dns->Metric = dns->OldIfMetric; if (AddRouteEntry(dns) == false) { FreeRouteEntry(dns); dns = NULL; } } } } } if (s->IsAzureSession && IsZeroIP(&s->AzureRealServerGlobalIp) == false) { // Add also a static route to the real server in the case of via VPN Azure if (IsMyIPAddress(&s->AzureRealServerGlobalIp) == false) { route_to_real_server_global = GetBestRouteEntryEx(&s->AzureRealServerGlobalIp, exclude_if_id); if (route_to_real_server_global != NULL) { if (MsIsVista()) { route_to_real_server_global->Metric = route_to_real_server_global->OldIfMetric; } if (AddRouteEntry(route_to_real_server_global) == false) { FreeRouteEntry(route_to_real_server_global); route_to_real_server_global = NULL; } } } } // Initialize if (s->Cedar->Client != NULL && s->Account != NULL) { Lock(s->Account->lock); } t = ZeroMalloc(sizeof(ROUTE_TRACKING)); v->RouteState = t; t->RouteToServerAlreadyExists = already_exists; t->RouteToServer = e; t->RouteToDefaultDns = dns; t->RouteToRealServerGlobal = route_to_real_server_global; t->VLanInterfaceId = if_id; t->NextTrackingTime = 0; t->DeletedDefaultGateway = NewQueue(); t->OldDefaultGatewayMetric = 0x7fffffff; if (s->Cedar->Client != NULL && s->Account != NULL) { Unlock(s->Account->lock); } // Get the route to 8.8.8.8 SetIP(&eight, 8, 8, 8, 8); t->RouteToEight = GetBestRouteEntryEx(&eight, exclude_if_id); // Get the current default DNS server to detect network changes GetDefaultDns(&t->OldDnsServer); // Get as soon as releasing the IP address in the case of using DHCP if (IsNt()) { char tmp[MAX_SIZE]; MS_ADAPTER *a; Format(tmp, sizeof(tmp), VLAN_ADAPTER_NAME_TAG, v->InstanceName); a = MsGetAdapter(tmp); if (a != NULL) { if (a->UseDhcp) { bool ret = Win32ReleaseAddressByGuidEx(a->Guid, 100); Debug("*** Win32ReleaseAddressByGuidEx = %u\n", ret); ret = Win32RenewAddressByGuidEx(a->Guid, 100); Debug("*** Win32RenewAddressByGuidEx = %u\n", ret); } MsFreeAdapter(a); } } else { // For Win9x Win32RenewDhcp9x(if_id); } // Clear the DNS cache Win32FlushDnsCache(); // Detect a change in the routing table (for only supported OS) t->RouteChange = NewRouteChange(); Debug("t->RouteChange = 0x%p\n", t->RouteChange); }
// Update status void UtSpeedMeterDlgRefreshStatus(HWND hWnd) { char *title; MS_ADAPTER *a; UINT i; // Validate arguments if (hWnd == NULL) { return; } title = selected_adapter; a = MsGetAdapter(title); if (a == NULL) { LbReset(hWnd, L_STATUS); Disable(hWnd, L_STATUS); } else { LVB *b; wchar_t tmp[MAX_SIZE]; wchar_t tmp2[MAX_SIZE]; char str[MAX_SIZE]; b = LvInsertStart(); UniStrCpy(tmp, sizeof(tmp), a->TitleW); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_TITLE"), tmp); StrToUni(tmp, sizeof(tmp), a->Guid); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_GUID"), tmp); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_TYPE"), MsGetAdapterTypeStr(a->Type)); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_TYPE2"), (!a->IsNotEthernetLan ? _UU("SEC_YES") : _UU("SEC_NO"))); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_STATUS"), MsGetAdapterStatusStr(a->Status)); UniToStr3(tmp, sizeof(tmp), a->Mtu); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_MTU"), tmp); UniToStr3(tmp, sizeof(tmp), a->Speed); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_SPEED"), tmp); Zero(str, sizeof(str)); BinToStrEx2(str, sizeof(str), a->Address, a->AddressSize, '-'); StrToUni(tmp, sizeof(tmp), str); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_ADDRESS"), tmp); UniToStr3(tmp, sizeof(tmp), a->RecvBytes); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_RECV_BYTES"), tmp); UniToStr3(tmp, sizeof(tmp), a->RecvPacketsBroadcast); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_RECV_BCASTS"), tmp); UniToStr3(tmp, sizeof(tmp), a->RecvPacketsUnicast); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_RECV_UNICASTS"), tmp); UniToStr3(tmp, sizeof(tmp), a->SendBytes); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_SEND_BYTES"), tmp); UniToStr3(tmp, sizeof(tmp), a->SendPacketsBroadcast); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_SEND_BCASTS"), tmp); UniToStr3(tmp, sizeof(tmp), a->SendPacketsUnicast); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_SEND_UNICASTS"), tmp); for (i = 0;i < a->NumIpAddress;i++) { UniFormat(tmp2, sizeof(tmp2), _UU("UT_SM_ST_IP"), i + 1); IPToUniStr(tmp, sizeof(tmp), &a->IpAddresses[i]); LvInsertAdd(b, 0, NULL, 2, tmp2, tmp); UniFormat(tmp2, sizeof(tmp2), _UU("UT_SM_ST_SUBNET"), i + 1); IPToUniStr(tmp, sizeof(tmp), &a->SubnetMasks[i]); LvInsertAdd(b, 0, NULL, 2, tmp2, tmp); } for (i = 0;i < a->NumGateway;i++) { UniFormat(tmp2, sizeof(tmp2), _UU("UT_SM_ST_GATEWAY"), i + 1); IPToUniStr(tmp, sizeof(tmp), &a->Gateways[i]); LvInsertAdd(b, 0, NULL, 2, tmp2, tmp); } if (a->UseDhcp) { IPToUniStr(tmp, sizeof(tmp), &a->DhcpServer); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_DHCP"), tmp); GetDateTimeStrEx64(tmp, sizeof(tmp), a->DhcpLeaseStart, NULL); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_DHCP_1"), tmp); GetDateTimeStrEx64(tmp, sizeof(tmp), a->DhcpLeaseExpires, NULL); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_DHCP_2"), tmp); } if (a->UseWins) { IPToUniStr(tmp, sizeof(tmp), &a->PrimaryWinsServer); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_WINS_1"), tmp); IPToUniStr(tmp, sizeof(tmp), &a->SecondaryWinsServer); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_WINS_2"), tmp); } LvInsertEnd(b, hWnd, L_STATUS); Enable(hWnd, L_STATUS); MsFreeAdapter(a); } }