CFG_RW *NewCfgRwEx2W(FOLDER **root, wchar_t *cfg_name, bool dont_backup, wchar_t *template_name) { CFG_RW *rw; FOLDER *f; bool loaded_from_template = false; // Validate arguments if (cfg_name == NULL || root == NULL) { return NULL; } f = CfgReadW(cfg_name); if (f == NULL) { // Load from template if (UniIsEmptyStr(template_name) == false) { f = CfgReadW(template_name); if (f != NULL) { loaded_from_template = true; goto LABEL_CONTIUNE; } } rw = ZeroMalloc(sizeof(CFG_RW)); rw->lock = NewLock(); rw->FileNameW = CopyUniStr(cfg_name); rw->FileName = CopyUniToStr(cfg_name); rw->Io = FileCreateW(cfg_name); *root = NULL; rw->DontBackup = dont_backup; return rw; } LABEL_CONTIUNE: rw = ZeroMalloc(sizeof(CFG_RW)); rw->FileNameW = CopyUniStr(cfg_name); rw->FileName = CopyUniToStr(cfg_name); if (loaded_from_template == false) { rw->Io = FileOpenW(cfg_name, false); } else { rw->Io = FileCreateW(cfg_name); } rw->lock = NewLock(); *root = f; rw->DontBackup = dont_backup; return rw; }
// Create new VPN Azure client AZURE_CLIENT *NewAzureClient(CEDAR *cedar, SERVER *server) { AZURE_CLIENT *ac; // Validate arguments if (cedar == NULL || server == NULL) { return NULL; } ac = ZeroMalloc(sizeof(AZURE_CLIENT)); ac->Cedar = cedar; ac->Server = server; ac->Lock = NewLock(); ac->IsEnabled = false; ac->Event = NewEvent(); // Start main thread ac->MainThread = NewThread(AcMainThread, ac); return ac; }
// Create new user object USER *NewUser(char *name, wchar_t *realname, wchar_t *note, UINT authtype, void *authdata) { USER *u; // Validate arguments if (name == NULL || realname == NULL || note == NULL) { return NULL; } if (authtype != AUTHTYPE_ANONYMOUS && authdata == NULL) { return NULL; } u = ZeroMalloc(sizeof(USER)); u->lock = NewLock(); u->ref = NewRef(); u->Name = CopyStr(name); u->RealName = CopyUniStr(realname); u->Note = CopyUniStr(note); u->GroupName = NULL; u->Group = NULL; u->AuthType = authtype; u->AuthData = authdata; u->CreatedTime = SystemTime64(); u->UpdatedTime = SystemTime64(); u->Policy = NULL; u->Traffic = NewTraffic(); return u; }
// Create a new dynamic listener DYNAMIC_LISTENER *NewDynamicListener(CEDAR *c, bool *enable_ptr, UINT protocol, UINT port) { DYNAMIC_LISTENER *d; // Validate arguments if (c == NULL || enable_ptr == NULL) { return NULL; } d = ZeroMalloc(sizeof(DYNAMIC_LISTENER)); d->Cedar = c; AddRef(d->Cedar->ref); d->Lock = NewLock(); d->EnablePtr = enable_ptr; d->Listener = NULL; d->Protocol = protocol; d->Port = port; ApplyDynamicListener(d); return d; }
// Create the EL EL *NewEl() { EL *e; #ifdef OS_WIN32 RegistWindowsFirewallAll(); #endif e = ZeroMalloc(sizeof(EL)); e->lock = NewLock(); e->ref = NewRef(); e->Cedar = NewCedar(NULL, NULL); // Ethernet initialization InitEth(); // Setting initialization ElInitConfig(e); // Listener start ElStartListener(e); // Initialize the license status ElParseCurrentLicenseStatus(e->LicenseSystem, e->LicenseStatus); // Eraser start e->Eraser = NewEraser(NULL, e->AutoDeleteCheckDiskFreeSpaceMin); return e; }
// Initialize the IPsec server IPSEC_SERVER *NewIPsecServer(CEDAR *cedar) { IPSEC_SERVER *s; // Validate arguments if (cedar == NULL) { return NULL; } s = ZeroMalloc(sizeof(IPSEC_SERVER)); s->LockSettings = NewLock(); s->Cedar = cedar; AddRef(s->Cedar->ref); s->L2TP = NewL2TPServer(cedar); s->Ike = NewIKEServer(cedar, s); StrCpy(s->Ike->Secret, sizeof(s->Ike->Secret), IPSEC_DEFAULT_SECRET); s->UdpListener = NewUdpListener(IPsecServerUdpPacketRecvProc, s, &cedar->Server->ListenIP); s->EtherIPIdList = NewList(CmpEtherIPId); // Start an OS service monitoring thread s->OsServiceCheckThreadEvent = NewEvent(); s->OsServiceCheckThread = NewThread(IPsecOsServiceCheckThread, s); return s; }
// Create a new SecureNAT SNAT *SnNewSecureNAT(HUB *h, VH_OPTION *o) { SNAT *s; THREAD *t; // Validate arguments if (h == NULL || o == NULL) { return NULL; } s = ZeroMalloc(sizeof(SNAT)); s->Cedar = h->Cedar; s->Hub = h; s->lock = NewLock(); // Create a NAT s->Nat = NiNewNatEx(s, o); // Initialize the virtual machine VirtualInit(s->Nat->Virtual); // Create a thread t = NewThread(SnSecureNATThread, s); WaitThreadInit(t); ReleaseThread(t); return s; }
// Initialize the NtXxx function void NtInit() { if (nat_lock != NULL) { return; } nat_lock = NewLock(); }
bool ShardLockManager::TryLock(ReadBuffer key, ClientSession* session) { int cmpres; Buffer keyBuffer; ShardLock* lock; ShardLock* newLock; keyBuffer.Write(key); lock = lockTree.Locate(keyBuffer, cmpres); if (!FOUND_IN_TREE(lock, cmpres)) { // not in tree newLock = NewLock(); newLock->key.Write(key); lockTree.InsertAt(newLock, lock, cmpres); lock = newLock; } else if (lock->locked) return false; else { // in tree, not locked // in lock cache list ASSERT(lock->listCacheNode.next != lock); lockCacheList.Remove(lock); // not in lock expiry list ASSERT(lock->listExpiryNode.next == lock); // not in lock pool list ASSERT(lock->listPoolNode.next == lock); } // in tree, not locked lock->locked = true; lock->session = session; numLocked++; lock->expireTime = EventLoop::Now() + lockExpireTime; // add to expiry list lockExpiryList.Append(lock); UpdateExpireLockTimeout(); // in lock tree ASSERT(lock->treeNode.IsInTree()); // not in lock cache list ASSERT(lock->listCacheNode.next == lock); // in lock expiry list ASSERT(lock->listExpiryNode.next != lock); // not in lock pool list ASSERT(lock->listPoolNode.next == lock); Log_Debug("Lock %R acquired.", &key); return true; }
// Open a secure device SECURE *OpenSec(UINT id) { SECURE_DEVICE *dev = GetSecureDevice(id); SECURE *sec; UINT err; if (dev == NULL) { return NULL; } sec = ZeroMalloc(sizeof(SECURE)); sec->lock = NewLock(); sec->Error = SEC_ERROR_NOERROR; sec->Dev = dev; // Get whether it's a ePass or not if (SearchStrEx(dev->DeviceName, "epass", 0, false) != INFINITE) { sec->IsEPass1000 = true; } // Load the module if (LoadSecModule(sec) == false) { CloseSec(sec); return NULL; } // Get the slot list sec->NumSlot = 0; if ((err = sec->Api->C_GetSlotList(true, NULL, &sec->NumSlot)) != CKR_OK || sec->NumSlot == 0) { // Failure FreeSecModule(sec); CloseSec(sec); return NULL; } sec->SlotIdList = (UINT *)ZeroMalloc(sizeof(UINT *) * sec->NumSlot); if (sec->Api->C_GetSlotList(TRUE, sec->SlotIdList, &sec->NumSlot) != CKR_OK) { // Failure Free(sec->SlotIdList); sec->SlotIdList = NULL; FreeSecModule(sec); CloseSec(sec); return NULL; } return sec; }
// Initialize Ethernet void InitEth() { HINSTANCE h; if (wp != NULL) { // Already initialized return; } eth_list_lock = NewLock(); wp = ZeroMalloc(sizeof(WP)); is_see_mode = false; if (IsPcdSupported()) { // PCD is supported in this OS h = InstallPcdDriver(); if (h != NULL) { // Try to initialize with PCD if (InitWpWithLoadLibrary(wp, h) == false) { Debug("InitEth: SEE Failed.\n"); FreeLibrary(h); } else { Debug("InitEth: SEE Loaded.\n"); is_see_mode = true; } } } if (wp->Inited == false) { // Try to initialize with Packet.dll of WinPcap h = LoadLibrary(BRIDGE_WIN32_PACKET_DLL); if (h != NULL) { if (InitWpWithLoadLibrary(wp, h) == false) { Debug("InitEth: Packet.dll Failed.\n"); FreeLibrary(h); } else { Debug("InitEth: Packet.dll Loaded.\n"); } } } }
Connection* NewConnection(BufferPool* pool, Address* address, bool freeAddress) { Connection* connection = NULL; if ((connection = aio4c_malloc(sizeof(Connection))) == NULL) { return NULL; } connection->readBuffer = AllocateBuffer(pool); connection->writeBuffer = AllocateBuffer(pool); BufferLimit(connection->writeBuffer, 0); connection->dataBuffer = NULL; connection->socket = -1; connection->state = AIO4C_CONNECTION_STATE_NONE; connection->stateLock = NewLock(); connection->systemHandlers = NewEventQueue(); connection->userHandlers = NewEventQueue(); connection->address = address; connection->closedForError = false; connection->string = AddressGetString(address); connection->stringAllocated = false; memset(connection->closedBy, 0, AIO4C_CONNECTION_OWNER_MAX * sizeof(bool)); connection->closedBy[AIO4C_CONNECTION_OWNER_ACCEPTOR] = true; connection->closedByLock = NewLock(); memset(connection->managedBy, 0, AIO4C_CONNECTION_OWNER_MAX * sizeof(bool)); connection->managedBy[AIO4C_CONNECTION_OWNER_ACCEPTOR] = true; connection->managedBy[AIO4C_CONNECTION_OWNER_CLIENT] = true; connection->managedByLock = NewLock(); connection->readKey = NULL; connection->writeKey = NULL; connection->pool = NULL; connection->freeAddress = freeAddress; connection->dataFactory = NULL; connection->dataFactoryArg = NULL; connection->canRead = false; connection->canWrite = false; connection->isFactory = false; return connection; }
// Create a new EtherIP server ETHERIP_SERVER *NewEtherIPServer(CEDAR *cedar, IPSEC_SERVER *ipsec, IKE_SERVER *ike, IP *client_ip, UINT client_port, IP *server_ip, UINT server_port, char *crypt_name, bool is_tunnel_mode, UINT crypt_block_size, char *client_id, UINT id) { ETHERIP_SERVER *s; // Validate arguments if (cedar == NULL || ipsec == NULL || ike == NULL || client_ip == NULL || server_ip == NULL || client_id == NULL) { return NULL; } s = ZeroMalloc(sizeof(ETHERIP_SERVER)); s->Ref = NewRef(); s->Id = id; s->Cedar = cedar; AddRef(s->Cedar->ref); s->IPsec = ipsec; s->Ike = ike; s->IsTunnelMode = is_tunnel_mode; StrCpy(s->ClientId, sizeof(s->ClientId), client_id); s->SendPacketList = NewList(NULL); s->Now = Tick64(); s->Lock = NewLock(); Copy(&s->ClientIP, client_ip, sizeof(IP)); s->ClientPort = client_port; Copy(&s->ServerIP, server_ip, sizeof(IP)); s->ServerPort = server_port; StrCpy(s->CryptName, sizeof(s->CryptName), crypt_name); s->CryptBlockSize = crypt_block_size; EtherIPLog(s, "LE_START_MODULE"); return s; }
// Creating a counter COUNTER *NewCounter() { COUNTER *c; // Memory allocation c = Malloc(sizeof(COUNTER)); // Initialization c->Ready = true; c->c = 0; // Lock created c->lock = NewLock(); // KS KS_INC(KS_NEW_COUNTER_COUNT); return c; }
// Initialize the string library void InitStringLibrary() { // Create a lock for token token_lock = NewLock(); // Initialization of the International Library InitInternational(); // Operation check if (CheckStringLibrary() == false) { #ifdef OS_WIN32 Alert("String Library Init Failed.\r\nPlease check your locale settings.", NULL); #else // OS_WIN32 Alert("String Library Init Failed.\r\nPlease check your locale settings and iconv() libraries.", NULL); #endif // OS_WIN32 exit(0); } }
// Creating a DDNS client DDNS_CLIENT *NewDDNSClient(CEDAR *cedar, UCHAR *key, INTERNET_SETTING *t) { DDNS_CLIENT *c; UCHAR key_hash[SHA1_SIZE]; // Validate arguments if (cedar == NULL) { return NULL; } c = ZeroMalloc(sizeof(DDNS_CLIENT)); c->Cedar = cedar; AddRef(c->Cedar->ref); c->Err_IPv4 = c->Err_IPv6 = ERR_TRYING_TO_CONNECT; if (key == NULL) { // Create a new key DCGenNewKey(c->Key); } else { // Set the key Copy(c->Key, key, SHA1_SIZE); } HashSha1(key_hash, c->Key, sizeof(c->Key)); if (t != NULL) { Copy(&c->InternetSetting, t, sizeof(INTERNET_SETTING)); } c->Lock = NewLock(); // Thread creation c->Event = NewEvent(); c->Thread = NewThread(DCThread, c); return c; }
// 文字列ライブラリの初期化 void InitStringLibrary() { // トークン用ロックの作成 token_lock = NewLock(); // 国際ライブラリの初期化 InitInternational(); // 動作チェック if (CheckStringLibrary() == false) { #ifdef OS_WIN32 Alert("String Library Init Failed.\r\nPlease check your locale settings.", NULL); #else // OS_WIN32 Alert("String Library Init Failed.\r\nPlease check your locale settings and iconv() libraries.", NULL); #endif // OS_WIN32 exit(0); } }
// Start the RPC client RPC *StartRpcClient(SOCK *s, void *param) { RPC *r; // Validate arguments if (s == NULL) { return NULL; } r = ZeroMalloc(sizeof(RPC)); r->Sock = s; r->Param = param; r->Lock = NewLock(); AddRef(s->ref); r->ServerMode = false; return r; }
// Initialization of the Tick64 void InitTick64() { if (tk64 != NULL) { // Already initialized return; } halt_tick_event = NewEvent(); // Initialize the structure tk64 = ZeroMalloc(sizeof(TICK64)); tk64->TickLock = NewLock(); tk64->AdjustTime = NewList(NULL); // Creating a thread tk64->Thread = NewThread(Tick64Thread, NULL); WaitThreadInit(tk64->Thread); }
// Create new group object USERGROUP *NewGroup(char *name, wchar_t *realname, wchar_t *note) { USERGROUP *g; // Validate arguments if (name == NULL || realname == NULL || note == NULL) { return NULL; } g = ZeroMalloc(sizeof(USERGROUP)); g->lock = NewLock(); g->ref = NewRef(); g->Name = CopyStr(name); g->RealName = CopyUniStr(realname); g->Note = CopyUniStr(note); g->Policy = NULL; g->Traffic = NewTraffic(); return g; }
// Initialize tiny log TINY_LOG *NewTinyLog() { char name[MAX_PATH]; SYSTEMTIME st; TINY_LOG *t; LocalTime(&st); MakeDir(TINY_LOG_DIRNAME); Format(name, sizeof(name), TINY_LOG_FILENAME, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond); t = ZeroMalloc(sizeof(TINY_LOG)); StrCpy(t->FileName, sizeof(t->FileName), name); t->io = FileCreate(name); t->Lock = NewLock(); return t; }
// NAT の作成 NAT *NiNewNatEx(SNAT *snat, VH_OPTION *o) { NAT *n = ZeroMalloc(sizeof(NAT)); n->lock = NewLock(); Hash(n->HashedPassword, "", 0, true); n->HaltEvent = NewEvent(); //n->Cedar = NewCedar(NULL, NULL); n->SecureNAT = snat; // 優先順位を上げる //OSSetHighPriority(); // 設定の初期化 NiInitConfig(n); #if 0 // 仮想ホストの動作を開始 if (n->Online && n->ClientOption != NULL) { n->Virtual = NewVirtualHostEx(n->Cedar, n->ClientOption, n->ClientAuth, &n->Option, n); } else { n->Online = false; n->Virtual = NULL; } #else n->Virtual = NewVirtualHostEx(n->Cedar, NULL, NULL, o, n); n->Online = true; #endif // 管理コマンド開始 //NiInitAdminAccept(n); return n; }
// Create a NAT NAT *NiNewNatEx(SNAT *snat, VH_OPTION *o) { NAT *n = ZeroMalloc(sizeof(NAT)); n->lock = NewLock(); Hash(n->HashedPassword, "", 0, true); n->HaltEvent = NewEvent(); //n->Cedar = NewCedar(NULL, NULL); n->SecureNAT = snat; // Raise the priority //OSSetHighPriority(); // Initialize the settings NiInitConfig(n); #if 0 // Start the operation of the virtual host if (n->Online && n->ClientOption != NULL) { n->Virtual = NewVirtualHostEx(n->Cedar, n->ClientOption, n->ClientAuth, &n->Option, n); } else { n->Online = false; n->Virtual = NULL; } #else n->Virtual = NewVirtualHostEx(n->Cedar, NULL, NULL, o, n); n->Online = true; #endif // Start management command //NiInitAdminAccept(n); return n; }
// Start the RPC server RPC *StartRpcServer(SOCK *s, RPC_DISPATCHER *dispatch, void *param) { RPC *r; // Validate arguments if (s == NULL) { return NULL; } r = ZeroMallocEx(sizeof(RPC), true); r->Sock = s; r->Param = param; r->Lock = NewLock(); AddRef(s->ref); r->ServerMode = true; r->Dispatch = dispatch; // Name generation Format(r->Name, sizeof(r->Name), "RPC-%u", s->socket); return r; }
// Create a new L3 switch L3SW *NewL3Sw(CEDAR *c, char *name) { L3SW *o; // Validate arguments if (c == NULL || name == NULL) { return NULL; } o = ZeroMalloc(sizeof(L3SW)); StrCpy(o->Name, sizeof(o->Name), name); o->lock = NewLock(); o->ref = NewRef(); o->Cedar = c; o->Active = false; o->IfList = NewList(CmpL3If); o->TableList = NewList(CmpL3Table); return o; }
// EL initialization void ElInit() { // Lock initialization el_lock = NewLock(); }
LISTENER *NewListenerEx5(CEDAR *cedar, UINT proto, UINT port, THREAD_PROC *proc, void *thread_param, bool local_only, bool shadow_ipv6, volatile UINT *natt_global_udp_port, UCHAR rand_port_id, bool enable_ca) { LISTENER *r; THREAD *t; // Validate arguments if ((proto == LISTENER_TCP && port == 0) || cedar == NULL) { return NULL; } // Check the protocol number if (proto != LISTENER_TCP && proto != LISTENER_INPROC && proto != LISTENER_RUDP && proto != LISTENER_ICMP && proto != LISTENER_DNS && proto != LISTENER_REVERSE) { return NULL; } r = ZeroMalloc(sizeof(LISTENER)); r->ThreadProc = proc; r->ThreadParam = thread_param; r->Cedar = cedar; AddRef(r->Cedar->ref); r->lock = NewLock(); r->ref = NewRef(); r->Protocol = proto; r->Port = port; r->Event = NewEvent(); r->LocalOnly = local_only; r->ShadowIPv6 = shadow_ipv6; r->NatTGlobalUdpPort = natt_global_udp_port; r->RandPortId = rand_port_id; r->EnableConditionalAccept = enable_ca; if (r->ShadowIPv6 == false) { if (proto == LISTENER_TCP) { SLog(cedar, "LS_LISTENER_START_1", port); } } // Creating a thread t = NewThread(ListenerThread, r); WaitThreadInit(t); ReleaseThread(t); if (r->ShadowIPv6 == false && proto == LISTENER_TCP) { if (r->Cedar->DisableIPv6Listener == false) { // Add a shadow listener r->ShadowListener = NewListenerEx3(cedar, proto, port, proc, thread_param, local_only, true); } } if (r->ShadowIPv6 == false) { // Add to the Cedar AddListener(cedar, r); } return r; }
// Creating a new local console CONSOLE *NewLocalConsole(wchar_t *infile, wchar_t *outfile) { IO *in_io = NULL, *out_io = NULL; CONSOLE *c = ZeroMalloc(sizeof(CONSOLE)); LOCAL_CONSOLE_PARAM *p; UINT old_size = 0; #ifdef OS_WIN32 if (MsGetConsoleWidth() == 80) { //old_size = MsSetConsoleWidth(WIN32_DEFAULT_CONSOLE_WIDTH); } #endif // OS_WIN32 c->ConsoleType = CONSOLE_LOCAL; c->Free = ConsoleLocalFree; c->ReadLine = ConsoleLocalReadLine; c->ReadPassword = ConsoleLocalReadPassword; c->Write = ConsoleLocalWrite; c->GetWidth = ConsoleLocalGetWidth; c->OutputLock = NewLock(); if (UniIsEmptyStr(infile) == false) { // Input file is specified in_io = FileOpenW(infile, false); if (in_io == NULL) { wchar_t tmp[MAX_SIZE]; UniFormat(tmp, sizeof(tmp), _UU("CON_INFILE_ERROR"), infile); c->Write(c, tmp); Free(c); return NULL; } else { wchar_t tmp[MAX_SIZE]; UniFormat(tmp, sizeof(tmp), _UU("CON_INFILE_START"), infile); c->Write(c, tmp); } } if (UniIsEmptyStr(outfile) == false) { // Output file is specified out_io = FileCreateW(outfile); if (out_io == NULL) { wchar_t tmp[MAX_SIZE]; UniFormat(tmp, sizeof(tmp), _UU("CON_OUTFILE_ERROR"), outfile); c->Write(c, tmp); Free(c); if (in_io != NULL) { FileClose(in_io); } return NULL; } else { wchar_t tmp[MAX_SIZE]; UniFormat(tmp, sizeof(tmp), _UU("CON_OUTFILE_START"), outfile); c->Write(c, tmp); } } p = ZeroMalloc(sizeof(LOCAL_CONSOLE_PARAM)); c->Param = p; p->InFile = in_io; p->OutFile = out_io; p->Win32_OldConsoleWidth = old_size; if (in_io != NULL) { UINT size; void *buf; size = FileSize(in_io); buf = ZeroMalloc(size + 1); FileRead(in_io, buf, size); p->InBuf = NewBuf(); WriteBuf(p->InBuf, buf, size); Free(buf); p->InBuf->Current = 0; } return c; }
// Create a new UDP acceleration function UDP_ACCEL *NewUdpAccel(CEDAR *cedar, IP *ip, bool client_mode, bool random_port, bool no_nat_t) { UDP_ACCEL *a; SOCK *s; UINT max_udp_size; bool is_in_cedar_port_list = false; if (IsZeroIP(ip)) { ip = NULL; } if (client_mode || random_port) { // Use a appropriate vacant port number in the case of using random port or client mode s = NewUDPEx3(0, ip); } else { // Specify in the range in the case of server mode UINT i; s = NULL; LockList(cedar->UdpPortList); { for (i = UDP_SERVER_PORT_LOWER;i <= UDP_SERVER_PORT_HIGHER;i++) { if (IsIntInList(cedar->UdpPortList, i) == false) { s = NewUDPEx3(i, ip); if (s != NULL) { is_in_cedar_port_list = true; break; } } } if (s == NULL) { // Leave the port selection to the OS because the available port is not found within the range s = NewUDPEx3(0, ip); } if (s != NULL && is_in_cedar_port_list) { AddIntDistinct(cedar->UdpPortList, i); } } UnlockList(cedar->UdpPortList); } if (s == NULL) { return NULL; } a = ZeroMalloc(sizeof(UDP_ACCEL)); a->Cedar = cedar; AddRef(a->Cedar->ref); a->NoNatT = no_nat_t; a->NatT_TranId = Rand64(); a->CreatedTick = Tick64(); a->IsInCedarPortList = is_in_cedar_port_list; a->ClientMode = client_mode; a->Now = Tick64(); a->UdpSock = s; Rand(a->MyKey, sizeof(a->MyKey)); Rand(a->YourKey, sizeof(a->YourKey)); Copy(&a->MyIp, ip, sizeof(IP)); a->MyPort = s->LocalPort; a->IsIPv6 = IsIP6(ip); if (a->IsIPv6) { a->NoNatT = true; } a->RecvBlockQueue = NewQueue(); Rand(a->NextIv, sizeof(a->NextIv)); do { a->MyCookie = Rand32(); } while (a->MyCookie == 0); do { a->YourCookie = Rand32(); } while (a->MyCookie == 0 || a->MyCookie == a->YourCookie); // Calculate the maximum transmittable UDP packet size max_udp_size = MTU_FOR_PPPOE; if (a->IsIPv6 == false) { // IPv4 max_udp_size -= 20; } else { // IPv6 max_udp_size -= 40; } // UDP max_udp_size -= 8; a->MaxUdpPacketSize = max_udp_size; Debug("Udp Accel My Port = %u\n", a->MyPort); // Initialize the NAT-T server IP address acquisition thread a->NatT_Lock = NewLock(); a->NatT_HaltEvent = NewEvent(); if (a->NoNatT == false) { a->NatT_GetIpThread = NewThread(NatT_GetIpThread, a); } return a; }
// Create Cedar object CEDAR *NewCedar(X *server_x, K *server_k) { CEDAR *c; char tmp[MAX_SIZE]; char tmp2[MAX_SIZE]; char *beta_str; CedarForceLink(); c = ZeroMalloc(sizeof(CEDAR)); c->CurrentActiveLinks = NewCounter(); c->AcceptingSockets = NewCounter(); c->CedarSuperLock = NewLock(); c->CurrentRegionLock = NewLock(); StrCpy(c->OpenVPNDefaultClientOption, sizeof(c->OpenVPNDefaultClientOption), OVPN_DEF_CLIENT_OPTION_STRING); #ifdef BETA_NUMBER c->Beta = BETA_NUMBER; #endif // BETA_NUMBER InitNoSslList(c); c->AssignedBridgeLicense = NewCounter(); c->AssignedClientLicense = NewCounter(); c->CurrentTcpQueueSizeLock = NewLock(); c->QueueBudgetLock = NewLock(); c->FifoBudgetLock = NewLock(); Rand(c->UniqueId, sizeof(c->UniqueId)); c->CreatedTick = Tick64(); c->lock = NewLock(); c->ref = NewRef(); c->OpenVPNPublicPortsLock = NewLock(); c->CurrentTcpConnections = GetNumTcpConnectionsCounter(); c->ListenerList = NewList(CompareListener); c->UDPEntryList = NewList(CompareUDPEntry); c->HubList = NewList(CompareHub); c->ConnectionList = NewList(CompareConnection); c->ConnectionIncrement = NewCounter(); c->CurrentSessions = NewCounter(); if (server_k && server_x) { c->ServerK = CloneK(server_k); c->ServerX = CloneX(server_x); } c->Version = CEDAR_VER; c->Build = CEDAR_BUILD; c->ServerStr = CopyStr(CEDAR_SERVER_STR); GetMachineName(tmp, sizeof(tmp)); c->MachineName = CopyStr(tmp); c->HttpUserAgent = CopyStr(DEFAULT_USER_AGENT); c->HttpAccept = CopyStr(DEFAULT_ACCEPT); c->HttpAcceptLanguage = CopyStr("ja"); c->HttpAcceptEncoding = CopyStr(DEFAULT_ENCODING); c->Traffic = NewTraffic(); c->TrafficLock = NewLock(); c->CaList = NewList(CompareCert); c->TrafficDiffList = NewList(NULL); SetCedarCipherList(c, "RC4-MD5"); c->ClientId = _II("CLIENT_ID"); c->UdpPortList = NewIntList(false); InitNetSvcList(c); InitLocalBridgeList(c); InitCedarLayer3(c); c->WebUI = WuNewWebUI(c); #ifdef ALPHA_VERSION beta_str = "Alpha"; #else // ALPHA_VERSION #ifndef RELEASE_CANDIDATE beta_str = "Beta"; #else // RELEASE_CANDIDATE beta_str = "Release Candidate"; #endif // RELEASE_CANDIDATE #endif // ALPHA_VERSION ToStr(tmp2, c->Beta); Format(tmp, sizeof(tmp), "Version %u.%02u Build %u %s %s (%s)", CEDAR_VER / 100, CEDAR_VER - (CEDAR_VER / 100) * 100, CEDAR_BUILD, c->Beta == 0 ? "" : beta_str, c->Beta == 0 ? "" : tmp2, _SS("LANGSTR")); Trim(tmp); if (true) { SYSTEMTIME st; Zero(&st, sizeof(st)); st.wYear = BUILD_DATE_Y; st.wMonth = BUILD_DATE_M; st.wDay = BUILD_DATE_D; c->BuiltDate = SystemToUINT64(&st); } c->VerString = CopyStr(tmp); Format(tmp, sizeof(tmp), "Compiled %04u/%02u/%02u %02u:%02u:%02u by %s at %s", BUILD_DATE_Y, BUILD_DATE_M, BUILD_DATE_D, BUILD_DATE_HO, BUILD_DATE_MI, BUILD_DATE_SE, BUILDER_NAME, BUILD_PLACE); c->BuildInfo = CopyStr(tmp); return c; }