function_name
stringlengths
1
80
function
stringlengths
14
10.6k
comment
stringlengths
12
8.02k
normalized_comment
stringlengths
6
6.55k
GetCommandLineUniStr
wchar_t *GetCommandLineUniStr() { if (uni_cmdline == NULL) { return UniCopyStr(L""); } else { return UniCopyStr(uni_cmdline); } }
/* Get the Unicode command line string*/
Get the Unicode command line string
GetCommandLineStr
char *GetCommandLineStr() { if (cmdline == NULL) { return CopyStr(""); } else { return CopyStr(cmdline); } }
/* Get the command line string*/
Get the command line string
SetCommandLineUniStr
void SetCommandLineUniStr(wchar_t *str) { if (uni_cmdline != NULL) { Free(uni_cmdline); } if (str == NULL) { uni_cmdline = NULL; } else { uni_cmdline = CopyUniStr(str); } ParseCommandLineTokens(); }
/* Set the Unicode command line string*/
Set the Unicode command line string
SetCommandLineStr
void SetCommandLineStr(char *str) { // Validate arguments if (str == NULL) { if (cmdline != NULL) { Free(cmdline); } cmdline = NULL; } else { if (cmdline != NULL) { Free(cmdline); } cmdline = CopyStr(str); } if (cmdline == NULL) { if (uni_cmdline != NULL) { Free(uni_cmdline); uni_cmdline = NULL; } } else { if (uni_cmdline != NULL) { Free(uni_cmdline); } uni_cmdline = CopyStrToUni(cmdline); } ParseCommandLineTokens(); }
/* Set the command-line string*/
Set the command-line string
InitKernelStatus
void InitKernelStatus() { UINT i; // Memory initialization Zero(kernel_status, sizeof(kernel_status)); Zero(kernel_status_max, sizeof(kernel_status_max)); // Lock initialization for (i = 0;i < NUM_KERNEL_STATUS;i++) { kernel_status_lock[i] = OSNewLock(); } kernel_status_inited = true; }
/* Initialize Kernel status*/
Initialize Kernel status
FreeKernelStatus
void FreeKernelStatus() { UINT i; kernel_status_inited = false; // Lock release for (i = 0;i < NUM_KERNEL_STATUS;i++) { OSDeleteLock(kernel_status_lock[i]); } }
/* Release of the kernel status*/
Release of the kernel status
LockKernelStatus
void LockKernelStatus(UINT id) { // Validate arguments if (id >= NUM_KERNEL_STATUS) { return; } OSLock(kernel_status_lock[id]); }
/* Lock the kernel status*/
Lock the kernel status
UnlockKernelStatus
void UnlockKernelStatus(UINT id) { // Validate arguments if (id >= NUM_KERNEL_STATUS) { return; } OSUnlock(kernel_status_lock[id]); }
/* Unlock the kernel status*/
Unlock the kernel status
PrintDebugInformation
void PrintDebugInformation() { MEMORY_STATUS memory_status; GetMemoryStatus(&memory_status); // Header Print("====== " CEDAR_PRODUCT_STR " VPN System Debug Information ======\n"); // Memory information Print(" <Memory Status>\n" " Number of Allocated Memory Blocks: %u\n" " Total Size of Allocated Memory Blocks: %u bytes\n", memory_status.MemoryBlocksNum, memory_status.MemorySize); // Footer Print("====================================================\n"); if (KS_GET(KS_CURRENT_MEM_COUNT) != 0 || KS_GET(KS_CURRENT_LOCK_COUNT) != 0 || KS_GET(KS_CURRENT_LOCKED_COUNT) != 0 || KS_GET(KS_CURRENT_REF_COUNT) != 0) { // Show a debug menu because memory leaks suspected MemoryDebugMenu(); } }
/* Display the debug information*/
Display the debug information
ViUrlToFileName
char *ViUrlToFileName(char *url) { UINT i, len; char *ret = url; bool b = true; len = lstrlen(url); for (i = 0;i < len;i++) { char c = url[i]; if (c == '?' || c == '#') { b = false; } if (b) { if (c == '/' || c == '\\') { if (lstrlen(url + i + 1) > 1) { ret = url + i + 1; } } } } return ret; }
/* Convert the URL to the file name*/
Convert the URL to the file name
ViEulaDlg
bool ViEulaDlg(HWND hWnd, wchar_t *text) { // Validate arguments if (text == NULL) { return false; } if (Dialog(hWnd, D_EULA, ViEulaDlgProc, text) == 0) { return false; } return true; }
/* Display the End User License Agreement*/
Display the End User License Agreement
ViExtractEula
wchar_t *ViExtractEula(char *exe) { BUF *b; UINT tmp_size; char *tmp; wchar_t *ret; // Validate arguments if (exe == NULL) { return false; } b = ViExtractResource(exe, RT_RCDATA, "LICENSE"); if (b == NULL) { return NULL; } tmp_size = b->Size + 1; tmp = ZeroMalloc(tmp_size); Copy(tmp, b->Buf, b->Size); FreeBuf(b); ret = CopyStrToUni(tmp); Free(tmp); return ret; }
/* Extract the license agreement from the EXE file*/
Extract the license agreement from the EXE file
ViExtractCabinetFile
bool ViExtractCabinetFile(char *exe, char *cab) { BUF *b; // Validate arguments if (exe == NULL || cab == NULL) { return false; } b = ViExtractResource(exe, RT_RCDATA, "CABINET"); if (b == NULL) { return false; } if (DumpBuf(b, cab) == false) { FreeBuf(b); return false; } FreeBuf(b); return true; }
/* Extract the Cabinet file from the EXE file*/
Extract the Cabinet file from the EXE file
ViGetFileSize
UINT ViGetFileSize(VI_FILE *f) { // Validate arguments if (f == NULL) { return 0; } return f->FileSize; }
/* Get the file size*/
Get the file size
ViCloseFile
void ViCloseFile(VI_FILE *f) { // Validate arguments if (f == NULL) { return; } if (f->InternetFile == false) { FileClose(f->io); } else { InternetCloseHandle(f->hHttpFile); InternetCloseHandle(f->hInternet); } Free(f); }
/* Close the file*/
Close the file
ViIsInternetFile
bool ViIsInternetFile(char *path) { // Validate arguments if (path == NULL) { return false; } if (StartWith(path, "http://") || StartWith(path, "https://") || StartWith(path, "ftp://")) { return true; } return false; }
/* Determine whether the specified file name is the file on the Internet*/
Determine whether the specified file name is the file on the Internet
ViDownloadThreadStart
void ViDownloadThreadStart(VI_INSTALL_DLG *d) { // Validate arguments if (d == NULL) { return; } d->DownloadStarted = true; d->DownloadThread = NewThread(ViDownloadThread, d); }
/* Start the download thread*/
Start the download thread
ViDownloadThreadStop
void ViDownloadThreadStop(VI_INSTALL_DLG *d) { // Validate arguments if (d == NULL) { return; } if (d->DownloadStarted == false) { return; } d->DownloadStarted = false; d->Halt = true; while (true) { if (WaitThread(d->DownloadThread, 50)) { break; } DoEvents(NULL); } ReleaseThread(d->DownloadThread); }
/* Stop the download thread*/
Stop the download thread
ViInstallDlgSetPos
void ViInstallDlgSetPos(HWND hWnd, UINT pos) { PostMessage(hWnd, WM_VI_SETPOS, 0, pos); }
/* Operation of the progress bar*/
Operation of the progress bar
ViInstallDlgSetText
void ViInstallDlgSetText(VI_INSTALL_DLG *d, HWND hWnd, UINT id, wchar_t *text) { DWORD value = 0; // Validate arguments if (d == NULL) { return; } if (d->Halt) { return; } SendMessageTimeout(hWnd, WM_VI_SETTEXT, id, (LPARAM)text, SMTO_BLOCK, 200, &value); }
/* Set the text*/
Set the text
ViInstallDlgOnStart
void ViInstallDlgOnStart(HWND hWnd, VI_INSTALL_DLG *d) { // Validate arguments if (hWnd == NULL || d == NULL) { return; } // Start the download thread ViDownloadThreadStart(d); }
/* Installer operation start*/
Installer operation start
ViInstallDlgOnClose
void ViInstallDlgOnClose(HWND hWnd, VI_INSTALL_DLG *d) { // Validate arguments if (hWnd == NULL || d == NULL) { return; } if (d->DialogCanceling) { return; } if (d->NoClose) { return; } d->DialogCanceling = true; // Disable the cancel button Disable(hWnd, IDCANCEL); // Stop the download thread if it runs ViDownloadThreadStop(d); // Exit the dialog EndDialog(hWnd, 0); }
/* Cancel the installation*/
Cancel the installation
ViInstallDlg
void ViInstallDlg() { VI_INSTALL_DLG d; Zero(&d, sizeof(d)); d.BufSize = 65535; d.Buf = Malloc(d.BufSize); Dialog(NULL, D_INSTALL, ViInstallDlgProc, &d); Free(d.Buf); }
/* Show the dialog*/
Show the dialog
ViLoadInf
bool ViLoadInf(VI_SETTING *set, char *filename) { BUF *b; bool ret = false; // Validate arguments if (set == NULL || filename == NULL) { return false; } b = ReadDump(filename); if (b == NULL) { return false; } ret = ViLoadInfFromBuf(set, b); FreeBuf(b); return ret; }
/* Read the inf file*/
Read the inf file
ViMsiGetProductInfo
bool ViMsiGetProductInfo(char *product_code, char *name, char *buf, UINT size) { UINT ret; char tmp[MAX_SIZE]; DWORD sz; // Validate arguments if (product_code == NULL || name == NULL || buf == NULL) { return false; } sz = sizeof(tmp); ret = MsiGetProductInfoA(product_code, name, tmp, &sz); if (ret != ERROR_SUCCESS) { return false; } StrCpy(buf, size, tmp); return true; }
/* Get the product information from the Msi*/
Get the product information from the Msi
ViVersionStrToBuild
UINT ViVersionStrToBuild(char *str) { TOKEN_LIST *t; UINT ret; // Validate arguments if (str == NULL) { return 0; } t = ParseToken(str, "."); if (t == NULL) { return 0; } ret = 0; if (t->NumTokens == 3) { ret = ToInt(t->Token[2]); } FreeToken(t); return ret; }
/* Extract the build number from the version string*/
Extract the build number from the version string
ViGetSuitableArchForCpu
VI_SETTING_ARCH *ViGetSuitableArchForCpu() { return &setting.x86; }
/* Get the best architecture for the current CPU*/
Get the best architecture for the current CPU
ViLoadCurrentInstalledStates
void ViLoadCurrentInstalledStates() { ViLoadCurrentInstalledStatusForArch(&setting.x86); }
/* Get the current installation state*/
Get the current installation state
ViGenerateVpnSMgrTempDirName
void ViGenerateVpnSMgrTempDirName(char *name, UINT size, UINT build) { // Validate arguments if (name == NULL) { return; } Format(name, size, "%s\\px_" GC_SW_SOFTETHER_PREFIX "vpnsmgr_%u", MsGetTempDir(), build); }
/* Generate the temporary directory name for vpnsmgr*/
Generate the temporary directory name for vpnsmgr
ViCompareString
int ViCompareString(void *p1, void *p2) { VI_STRING *s1, *s2; if (p1 == NULL || p2 == NULL) { return 0; } s1 = *(VI_STRING **)p1; s2 = *(VI_STRING **)p2; if (s1 == NULL || s2 == NULL) { return 0; } if (s1->Id > s2->Id) { return 1; } else if (s1->Id < s2->Id) { return -1; } return 0; }
/* Compare the string resources*/
Compare the string resources
ViLoadString
wchar_t *ViLoadString(HINSTANCE hInst, UINT id) { wchar_t *ret = NULL; if (OS_IS_WINDOWS_9X(GetOsInfo()->OsType)) { char *a = ViLoadStringA(hInst, id); if (a != NULL) { ret = CopyStrToUni(a); Free(a); } } else { UINT tmp_size = 60000; wchar_t *tmp = Malloc(tmp_size); if (LoadStringW(hInst, id, tmp, tmp_size) != 0) { ret = CopyUniStr(tmp); } Free(tmp); } return ret; }
/* Reading a string resource*/
Reading a string resource
ViGetString
wchar_t *ViGetString(UINT id) { VI_STRING t, *s; wchar_t *ret = NULL; Zero(&t, sizeof(t)); t.Id = id; LockList(string_table); { s = Search(string_table, &t); if (s != NULL) { ret = s->String; } } UnlockList(string_table); return ret; }
/* Acquisition of string*/
Acquisition of string
ViSetSkip
void ViSetSkip() { skip = 0; if (MsIsCurrentUserLocaleIdJapanese() == false) { skip = MESSAGE_OFFSET_EN - MESSAGE_OFFSET_JP; } }
/* Calculate the difference between the the current language configuration and the base of the string table*/
Calculate the difference between the the current language configuration and the base of the string table
ViLoadStringTables
void ViLoadStringTables() { UINT i, n; HINSTANCE hInst = GetModuleHandle(NULL); string_table = NewList(ViCompareString); n = 0; for (i = 1;;i++) { wchar_t *str = ViLoadString(hInst, i); if (str != NULL) { VI_STRING *s; n = 0; s = ZeroMalloc(sizeof(VI_STRING)); s->Id = i; s->String = str; s->StringA = CopyUniToStr(str); Insert(string_table, s); } else { n++; if (n >= 1500) { break; } } } }
/* Read the string table*/
Read the string table
ViFreeStringTables
void ViFreeStringTables() { UINT i; if (string_table == NULL) { return; } for (i = 0;i < LIST_NUM(string_table);i++) { VI_STRING *s = LIST_DATA(string_table, i); Free(s->String); Free(s->StringA); Free(s); } ReleaseList(string_table); string_table = NULL; }
/* Release the string table*/
Release the string table
L3PollingIpQueue
void L3PollingIpQueue(L3IF *f) { L3PACKET *p; // Validate arguments if (f == NULL) { return; } // Process the packet came from another session while (p = GetNext(f->IpPacketQueue)) { PKT *pkt = p->Packet; // Send as an IP packet L3SendIp(f, p); } }
/* Process the IP queue*/
Process the IP queue
L3StoreIpPacketToIf
void L3StoreIpPacketToIf(L3IF *src_if, L3IF *dst_if, L3PACKET *p) { // Validate arguments if (src_if == NULL || p == NULL || dst_if == NULL) { return; } // Add to the queue of store-destination session InsertQueue(dst_if->IpPacketQueue, p); // Hit the Cancel object of the store-destination session AddCancelList(src_if->CancelList, dst_if->Session->Cancel1); }
/* Store the IP packet to a different interface*/
Store the IP packet to a different interface
L3KnownArp
void L3KnownArp(L3IF *f, UINT ip, UCHAR *mac) { L3ARPWAIT t, *w; // Validate arguments if (f == NULL || ip == 0 || ip == 0xffffffff || mac == NULL) { return; } if (!((f->IpAddress & f->SubnetMask) == (ip & f->SubnetMask))) { // Outside the subnet return; } // Delete an ARP query entry to this IP address Zero(&t, sizeof(t)); t.IpAddress = ip; w = Search(f->IpWaitList, &t); if (w != NULL) { Delete(f->IpWaitList, w); Free(w); } // Register in the ARP table L3InsertArpTable(f, ip, mac); }
/* Function to be called when the ARP resolved*/
Function to be called when the ARP resolved
L3SendArp
void L3SendArp(L3IF *f, UINT ip) { L3ARPWAIT t, *w; // Validate arguments if (f == NULL || ip == 0 || ip == 0xffffffff) { return; } // Examine whether it has not already registered Zero(&t, sizeof(t)); t.IpAddress = ip; w = Search(f->ArpWaitTable, &t); if (w != NULL) { // Do not do anything because it is already registered in the waiting list return; } else { // Register in the waiting list newly w = ZeroMalloc(sizeof(L3ARPWAIT)); w->Expire = Tick64() + ARP_REQUEST_GIVEUP; w->IpAddress = ip; Insert(f->ArpWaitTable, w); } }
/* Issue an ARP query*/
Issue an ARP query
L3RecvArpRequest
void L3RecvArpRequest(L3IF *f, PKT *p) { ARPV4_HEADER *a; // Validate arguments if (f == NULL || p == NULL) { return; } a = p->L3.ARPv4Header; L3KnownArp(f, a->SrcIP, a->SrcAddress); if (a->TargetIP == f->IpAddress) { // Respond only if the ARP packet addressed to myself L3SendArpResponseNow(f, a->SrcAddress, a->SrcIP, f->IpAddress); } }
/* Received an ARP request*/
Received an ARP request
L3RecvArpResponse
void L3RecvArpResponse(L3IF *f, PKT *p) { ARPV4_HEADER *a; // Validate arguments if (f == NULL || p == NULL) { return; } a = p->L3.ARPv4Header; L3KnownArp(f, a->SrcIP, a->SrcAddress); }
/* Received an ARP response*/
Received an ARP response
L3SendIpNow
void L3SendIpNow(L3IF *f, L3ARPENTRY *a, L3PACKET *p) { // Validate arguments if (f == NULL || p == NULL) { return; } L3SendL2Now(f, a != NULL ? a->MacAddress : broadcast, f->MacAddress, Endian16(p->Packet->MacHeader->Protocol), p->Packet->L3.PointerL3, p->Packet->PacketSize - sizeof(MAC_HEADER)); }
/* Send the IP packet immediately*/
Send the IP packet immediately
L3SearchArpTable
L3ARPENTRY *L3SearchArpTable(L3IF *f, UINT ip) { L3ARPENTRY *e, t; // Validate arguments if (f == NULL || ip == 0 || ip == 0xffffffff) { return NULL; } Zero(&t, sizeof(t)); t.IpAddress = ip; e = Search(f->ArpTable, &t); return e; }
/* Search in the ARP table*/
Search in the ARP table
L3SendArpRequestNow
void L3SendArpRequestNow(L3IF *f, UINT dest_ip) { ARPV4_HEADER arp; // Validate arguments if (f == NULL) { return; } // Build an ARP header arp.HardwareType = Endian16(ARP_HARDWARE_TYPE_ETHERNET); arp.ProtocolType = Endian16(MAC_PROTO_IPV4); arp.HardwareSize = 6; arp.ProtocolSize = 4; arp.Operation = Endian16(ARP_OPERATION_REQUEST); Copy(arp.SrcAddress, f->MacAddress, 6); arp.SrcIP = f->IpAddress; Zero(&arp.TargetAddress, 6); arp.TargetIP = dest_ip; // Transmission L3SendL2Now(f, broadcast, f->MacAddress, MAC_PROTO_ARPV4, &arp, sizeof(arp)); }
/* Send an ARP request packet*/
Send an ARP request packet
L3GenerateMacAddress
void L3GenerateMacAddress(L3IF *f) { BUF *b; UCHAR hash[SHA1_SIZE]; // Validate arguments if (f == NULL) { return; } b = NewBuf(); WriteBuf(b, f->Switch->Name, StrLen(f->Switch->Name)); WriteBuf(b, f->HubName, StrLen(f->HubName)); WriteBuf(b, &f->IpAddress, sizeof(f->IpAddress)); GenMacAddress(f->MacAddress); Sha0(hash, b->Buf, b->Size); Copy(f->MacAddress + 2, hash, 4); f->MacAddress[1] = 0xA3; FreeBuf(b); }
/* Generate a MAC address of the interface*/
Generate a MAC address of the interface
L3GetNextPacket
UINT L3GetNextPacket(L3IF *f, void **data) { UINT ret = 0; // Validate arguments if (f == NULL || data == NULL) { return 0; } START: // Examine the send queue LockQueue(f->SendQueue); { PKT *p = GetNext(f->SendQueue); if (p != NULL) { // There is a packet ret = p->PacketSize; *data = p->PacketData; // Packet structure may be discarded Free(p); } } UnlockQueue(f->SendQueue); if (ret == 0) { // Polling process L3Polling(f); // Examine whether a new packet is queued for results of the polling process if (f->SendQueue->num_item != 0) { // Get the packet immediately if it's in the queue goto START; } } return ret; }
/* Get the next packet*/
Get the next packet
L3InitInterface
void L3InitInterface(L3IF *f) { // Validate arguments if (f == NULL) { return; } // MAC address generation L3GenerateMacAddress(f); // List generation f->ArpTable = NewList(CmpL3ArpEntry); f->ArpWaitTable = NewList(CmpL3ArpWaitTable); f->IpPacketQueue = NewQueue(); f->IpWaitList = NewList(NULL); f->SendQueue = NewQueue(); }
/* Initialize the Layer-3 interface*/
Initialize the Layer-3 interface
L3InitAllInterfaces
void L3InitAllInterfaces(L3SW *s) { UINT i; // Validate arguments if (s == NULL) { return; } for (i = 0;i < LIST_NUM(s->IfList);i++) { L3IF *f = LIST_DATA(s->IfList, i); THREAD *t; L3InitInterface(f); f->Hub = GetHub(s->Cedar, f->HubName); t = NewThread(L3IfThread, f); WaitThreadInit(t); ReleaseThread(t); } }
/* Initialize all Layer-3 interfaces*/
Initialize all Layer-3 interfaces
L3FreeAllInterfaces
void L3FreeAllInterfaces(L3SW *s) { UINT i; // Validate arguments if (s == NULL) { return; } for (i = 0;i < LIST_NUM(s->IfList);i++) { L3IF *f = LIST_DATA(s->IfList, i); ReleaseHub(f->Hub); f->Hub = NULL; ReleaseSession(f->Session); f->Session = NULL; L3FreeInterface(f); } }
/* Release all Layer-3 interfaces*/
Release all Layer-3 interfaces
L3Test
void L3Test(SERVER *s) { L3SW *ss = L3AddSw(s->Cedar, "TEST"); L3AddIf(ss, "DEFAULT", 0x0101a8c0, 0x00ffffff); L3AddIf(ss, "DEFAULT2", 0x0102a8c0, 0x00ffffff); L3SwStart(ss); ReleaseL3Sw(ss); }
/* Layer-3 test*/
Layer-3 test
L3SwStart
void L3SwStart(L3SW *s) { // Validate arguments if (s == NULL) { return; } Lock(s->lock); { if (s->Active == false) { // Start if there is registered interface if (LIST_NUM(s->IfList) >= 1) { s->Halt = false; // Create a thread s->Thread = NewThread(L3SwThread, s); WaitThreadInit(s->Thread); } } } Unlock(s->lock); }
/* Start a Layer-3 switch*/
Start a Layer-3 switch
L3SwStop
void L3SwStop(L3SW *s) { THREAD *t = NULL; // Validate arguments if (s == NULL) { return; } Lock(s->lock); { if (s->Active == false) { Unlock(s->lock); return; } s->Halt = true; t = s->Thread; s->Active = false; } Unlock(s->lock); WaitThread(t, INFINITE); ReleaseThread(t); }
/* Stop the Layer-3 switch*/
Stop the Layer-3 switch
L3AddSw
L3SW *L3AddSw(CEDAR *c, char *name) { L3SW *s = NULL; // Validate arguments if (c == NULL || name == NULL) { return NULL; } LockList(c->L3SwList); { s = L3GetSw(c, name); if (s == NULL) { s = NewL3Sw(c, name); Insert(c->L3SwList, s); AddRef(s->ref); } else { ReleaseL3Sw(s); s = NULL; } } UnlockList(c->L3SwList); return s; }
/* Add a Layer-3 switch*/
Add a Layer-3 switch
L3DelSw
bool L3DelSw(CEDAR *c, char *name) { L3SW *s; bool ret = false; // Validate arguments if (c == NULL || name == NULL) { return false; } LockList(c->L3SwList); { s = L3GetSw(c, name); if (s != NULL) { // Stop and delete L3SwStop(s); Delete(c->L3SwList, s); ReleaseL3Sw(s); ReleaseL3Sw(s); ret = true; } } UnlockList(c->L3SwList); return ret; }
/* Delete the Layer-3 switch*/
Delete the Layer-3 switch
L3DelTable
bool L3DelTable(L3SW *s, L3TABLE *tbl) { bool ret = false; // Validate arguments if (s == NULL || tbl == NULL) { return false; } Lock(s->lock); { if (s->Active == false) { L3TABLE *t = Search(s->TableList, tbl); if (t != NULL) { Delete(s->TableList, t); Free(t); ret = true; } } } Unlock(s->lock); return ret; }
/* Delete the routing table*/
Delete the routing table
L3GetSw
L3SW *L3GetSw(CEDAR *c, char *name) { L3SW t, *s; // Validate arguments if (c == NULL || name == NULL) { return NULL; } Zero(&t, sizeof(t)); StrCpy(t.Name, sizeof(t.Name), name); LockList(c->L3SwList); { s = Search(c->L3SwList, &t); } UnlockList(c->L3SwList); if (s != NULL) { AddRef(s->ref); } return s; }
/* Get the L3 switch*/
Get the L3 switch
L3SearchIf
L3IF *L3SearchIf(L3SW *s, char *hubname) { L3IF t, *f; // Validate arguments if (s == NULL || hubname == NULL) { return NULL; } Zero(&t, sizeof(t)); StrCpy(t.HubName, sizeof(t.HubName), hubname); f = Search(s->IfList, &t); return f; }
/* Get the interface that is connected to the specified Virtual HUB from the L3 switch*/
Get the interface that is connected to the specified Virtual HUB from the L3 switch
L3DelIf
bool L3DelIf(L3SW *s, char *hubname) { L3IF *f; bool ret = false; // Validate arguments if (s == NULL || hubname == NULL) { return false; } Lock(s->lock); { if (s->Active == false) { f = L3SearchIf(s, hubname); if (f != NULL) { // Remove Delete(s->IfList, f); Free(f); ret = true; } } } Unlock(s->lock); return ret; }
/* Delete the interface*/
Delete the interface
CleanupL3Sw
void CleanupL3Sw(L3SW *s) { UINT i; // Validate arguments if (s == NULL) { return; } for (i = 0;i < LIST_NUM(s->IfList);i++) { L3IF *f = LIST_DATA(s->IfList, i); Free(f); } ReleaseList(s->IfList); for (i = 0;i < LIST_NUM(s->TableList);i++) { L3TABLE *t = LIST_DATA(s->TableList, i); Free(t); } ReleaseList(s->TableList); DeleteLock(s->lock); Free(s); }
/* Clean-up the L3 switch*/
Clean-up the L3 switch
ReleaseL3Sw
void ReleaseL3Sw(L3SW *s) { // Validate arguments if (s == NULL) { return; } if (Release(s->ref) == 0) { CleanupL3Sw(s); } }
/* Release the L3 switch*/
Release the L3 switch
NewL3Sw
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; }
/* Create a new L3 switch*/
Create a new L3 switch
FreeCedarLayer3
void FreeCedarLayer3(CEDAR *c) { // Validate arguments if (c == NULL) { return; } ReleaseList(c->L3SwList); c->L3SwList = NULL; }
/* Stop the L3 switch function of the Cedar*/
Stop the L3 switch function of the Cedar
InitCedarLayer3
void InitCedarLayer3(CEDAR *c) { // Validate arguments if (c == NULL) { return; } c->L3SwList = NewList(CmpL3Sw); }
/* Start the L3 switch function of the Cedar*/
Start the L3 switch function of the Cedar
CmpL3If
int CmpL3If(void *p1, void *p2) { L3IF *f1, *f2; if (p1 == NULL || p2 == NULL) { return 0; } f1 = *(L3IF **)p1; f2 = *(L3IF **)p2; if (f1 == NULL || f2 == NULL) { return 0; } return StrCmpi(f1->HubName, f2->HubName); }
/* Interface comparison function*/
Interface comparison function
CmpL3Sw
int CmpL3Sw(void *p1, void *p2) { L3SW *s1, *s2; if (p1 == NULL || p2 == NULL) { return 0; } s1 = *(L3SW **)p1; s2 = *(L3SW **)p2; if (s1 == NULL || s2 == NULL) { return 0; } return StrCmpi(s1->Name, s2->Name); }
/* L3SW comparison function*/
L3SW comparison function
CmpL3ArpWaitTable
int CmpL3ArpWaitTable(void *p1, void *p2) { L3ARPWAIT *w1, *w2; if (p1 == NULL || p2 == NULL) { return 0; } w1 = *(L3ARPWAIT **)p1; w2 = *(L3ARPWAIT **)p2; if (w1 == NULL || w2 == NULL) { return 0; } if (w1->IpAddress > w2->IpAddress) { return 1; } else if (w1->IpAddress < w2->IpAddress) { return -1; } else { return 0; } }
/* ARP waiting entry comparison function*/
ARP waiting entry comparison function
CmpL3ArpEntry
int CmpL3ArpEntry(void *p1, void *p2) { L3ARPENTRY *e1, *e2; if (p1 == NULL || p2 == NULL) { return 0; } e1 = *(L3ARPENTRY **)p1; e2 = *(L3ARPENTRY **)p2; if (e1 == NULL || e2 == NULL) { return 0; } if (e1->IpAddress > e2->IpAddress) { return 1; } else if (e1->IpAddress < e2->IpAddress) { return -1; } else { return 0; } }
/* ARP entries comparison function*/
ARP entries comparison function
VLanGetPacketAdapter
PACKET_ADAPTER *VLanGetPacketAdapter() { PACKET_ADAPTER *pa; pa = NewPacketAdapter(VLanPaInit, VLanPaGetCancel, VLanPaGetNextPacket, VLanPaPutPacket, VLanPaFree); if (pa == NULL) { return NULL; } return pa; }
/* Get the PACKET_ADAPTER*/
Get the PACKET_ADAPTER
VLanPaGetCancel
CANCEL *VLanPaGetCancel(SESSION *s) { VLAN *v; // Validate arguments if ((s == NULL) || ((v = s->PacketAdapter->Param) == NULL)) { return NULL; } return VLanGetCancel(v); }
/* Get the cancel object*/
Get the cancel object
VLanPaFree
void VLanPaFree(SESSION *s) { VLAN *v; // Validate arguments if ((s == NULL) || ((v = s->PacketAdapter->Param) == NULL)) { return; } // End the virtual LAN card FreeVLan(v); s->PacketAdapter->Param = NULL; }
/* Release the packet adapter*/
Release the packet adapter
VLanPaPutPacket
bool VLanPaPutPacket(SESSION *s, void *data, UINT size) { VLAN *v; // Validate arguments if ((s == NULL) || ((v = s->PacketAdapter->Param) == NULL)) { return false; } return VLanPutPacket(v, data, size); }
/* Write a packet*/
Write a packet
VLanPaGetNextPacket
UINT VLanPaGetNextPacket(SESSION *s, void **data) { VLAN *v; UINT size; // Validate arguments if (data == NULL || (s == NULL) || ((v = s->PacketAdapter->Param) == NULL)) { return INFINITE; } if (VLanGetNextPacket(v, data, &size) == false) { return INFINITE; } return size; }
/* Get the next packet*/
Get the next packet
VLanPutPacket
bool VLanPutPacket(VLAN *v, void *buf, UINT size) { UINT ret; // Validate arguments if (v == NULL) { return false; } if (v->Halt) { return false; } if (size > MAX_PACKET_SIZE) { return false; } if (buf == NULL || size == 0) { if (buf != NULL) { Free(buf); } return true; } ret = write(v->fd, buf, size); if (ret >= 1) { Free(buf); return true; } if (errno == EAGAIN || ret == 0) { Free(buf); return true; } return false; }
/* Write a packet to the virtual LAN card*/
Write a packet to the virtual LAN card
VLanGetCancel
CANCEL *VLanGetCancel(VLAN *v) { CANCEL *c; int fd; int yes = 0; // Validate arguments if (v == NULL) { return NULL; } c = NewCancel(); UnixDeletePipe(c->pipe_read, c->pipe_write); c->pipe_read = c->pipe_write = -1; fd = v->fd; UnixSetSocketNonBlockingMode(fd, true); c->SpecialFlag = true; c->pipe_read = fd; return c; }
/* Get the cancel object*/
Get the cancel object
FreeVLan
void FreeVLan(VLAN *v) { // Validate arguments if (v == NULL) { return; } Free(v->InstanceName); Free(v); }
/* Close the Virtual LAN card*/
Close the Virtual LAN card
NewTap
VLAN *NewTap(char *name, char *mac_address, bool create_up) { int fd; VLAN *v; // Validate arguments if (name == NULL || mac_address == NULL) { return NULL; } fd = UnixCreateTapDeviceEx(name, "tap", mac_address, create_up); if (fd == -1) { return NULL; } v = ZeroMalloc(sizeof(VLAN)); v->Halt = false; v->InstanceName = CopyStr(name); v->fd = fd; return v; }
/* Create a tap*/
Create a tap
FreeTap
void FreeTap(VLAN *v) { // Validate arguments if (v == NULL) { return; } close(v->fd); FreeVLan(v); }
/* Close the tap*/
Close the tap
NewVLan
VLAN *NewVLan(char *instance_name, VLAN_PARAM *param) { int fd; VLAN *v; // Validate arguments if (instance_name == NULL) { return NULL; } // Open the tap fd = UnixVLanGet(instance_name); if (fd == -1) { return NULL; } v = ZeroMalloc(sizeof(VLAN)); v->Halt = false; v->InstanceName = CopyStr(instance_name); v->fd = fd; return v; }
/* Get the Virtual LAN card list*/
Get the Virtual LAN card list
GenerateTunName
void GenerateTunName(char *name, char *prefix, char *tun_name, size_t tun_name_len) { char instance_name_lower[MAX_SIZE]; // Generate the device name StrCpy(instance_name_lower, sizeof(instance_name_lower), name); Trim(instance_name_lower); StrLower(instance_name_lower); Format(tun_name, tun_name_len, "%s_%s", prefix, instance_name_lower); tun_name[15] = 0; }
/* Generate TUN interface name*/
Generate TUN interface name
UnixCloseTapDevice
void UnixCloseTapDevice(int fd) { // Validate arguments if (fd == -1) { return; } close(fd); }
/* Close the tap device*/
Close the tap device
UnixCompareVLan
int UnixCompareVLan(void *p1, void *p2) { UNIX_VLAN_LIST *v1, *v2; if (p1 == NULL || p2 == NULL) { return 0; } v1 = *(UNIX_VLAN_LIST **)p1; v2 = *(UNIX_VLAN_LIST **)p2; if (v1 == NULL || v2 == NULL) { return 0; } return StrCmpi(v1->Name, v2->Name); }
/* Comparison of the VLAN list entries*/
Comparison of the VLAN list entries
UnixVLanInit
void UnixVLanInit() { unix_vlan = NewList(UnixCompareVLan); }
/* Initialize the VLAN list*/
Initialize the VLAN list
UnixVLanDelete
void UnixVLanDelete(char *name) { // Validate arguments if (name == NULL || unix_vlan == NULL) { return; } LockList(unix_vlan); { UINT i; UNIX_VLAN_LIST *t, tt; Zero(&tt, sizeof(tt)); StrCpy(tt.Name, sizeof(tt.Name), name); t = Search(unix_vlan, &tt); if (t != NULL) { UnixCloseTapDevice(t->fd); Delete(unix_vlan, t); Free(t); } } UnlockList(unix_vlan); }
/* Delete the VLAN*/
Delete the VLAN
UnixVLanGet
int UnixVLanGet(char *name) { int fd = -1; // Validate arguments if (name == NULL || unix_vlan == NULL) { return -1; } LockList(unix_vlan); { UINT i; UNIX_VLAN_LIST *t, tt; Zero(&tt, sizeof(tt)); StrCpy(tt.Name, sizeof(tt.Name), name); t = Search(unix_vlan, &tt); if (t != NULL) { fd = t->fd; } } UnlockList(unix_vlan); return fd; }
/* Get the VLAN*/
Get the VLAN
UnixVLanFree
void UnixVLanFree() { UINT i; for (i = 0;i < LIST_NUM(unix_vlan);i++) { UNIX_VLAN_LIST *t = LIST_DATA(unix_vlan, i); UnixCloseTapDevice(t->fd); Free(t); } ReleaseList(unix_vlan); unix_vlan = NULL; }
/* Release the VLAN list*/
Release the VLAN list
AcSetEnable
void AcSetEnable(AZURE_CLIENT *ac, bool enabled) { bool old_status; // Validate arguments if (ac == NULL) { return; } old_status = ac->IsEnabled; ac->IsEnabled = enabled; if (ac->IsEnabled && (ac->IsEnabled != old_status)) { ac->DDnsTriggerInt++; } AcApplyCurrentConfig(ac, NULL); }
/* Enable or disable VPN Azure client*/
Enable or disable VPN Azure client
NewAzureClient
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 VPN Azure client*/
Create new VPN Azure client
IsPriorityHighestPacketForQoS
bool IsPriorityHighestPacketForQoS(void *data, UINT size) { UCHAR *buf; // Validate arguments if (data == NULL) { return false; } buf = (UCHAR *)data; if (size >= 16) { if (buf[12] == 0x08 && buf[13] == 0x00 && buf[15] != 0x00 && buf[15] != 0x08) { // IPv4 packet and ToS != 0 return true; } if (size >= 34 && size <= 128) { if (buf[12] == 0x08 && buf[13] == 0x00 && buf[23] == 0x01) { // IMCPv4 packet return true; } } } return false; }
/* Determine whether the packet have priority in the VoIP / QoS function*/
Determine whether the packet have priority in the VoIP / QoS function
FreePacketAdapter
void FreePacketAdapter(PACKET_ADAPTER *pa) { // Validate arguments if (pa == NULL) { return; } Free(pa); }
/* Release the packet adapter*/
Release the packet adapter
NewPacketAdapter
PACKET_ADAPTER *NewPacketAdapter(PA_INIT *init, PA_GETCANCEL *getcancel, PA_GETNEXTPACKET *getnext, PA_PUTPACKET *put, PA_FREE *free) { PACKET_ADAPTER *pa; // Validate arguments if (init == NULL || getcancel == NULL || getnext == NULL || put == NULL || free == NULL) { return NULL; } pa = ZeroMalloc(sizeof(PACKET_ADAPTER)); pa->Init = init; pa->Free = free; pa->GetCancel = getcancel; pa->GetNextPacket = getnext; pa->PutPacket = put; return pa; }
/* Create a new packet adapter*/
Create a new packet adapter
SessionAdditionalConnect
void SessionAdditionalConnect(SESSION *s) { THREAD *t; // Validate arguments if (s == NULL) { return; } // s->LastTryAddConnectTime = Tick64(); AddRef(s->ref); t = NewThread(ClientAdditionalThread, (void *)s); WaitThreadInit(t); ReleaseThread(t); }
/* Put an additional connection from the client to the server*/
Put an additional connection from the client to the server
StopSession
void StopSession(SESSION *s) { StopSessionEx(s, false); }
/* Stop the session*/
Stop the session
ReleaseSession
void ReleaseSession(SESSION *s) { // Validate arguments if (s == NULL) { return; } if (Release(s->ref) == 0) { CleanupSession(s); } }
/* Release the session*/
Release the session
PrintSessionTotalDataSize
void PrintSessionTotalDataSize(SESSION *s) { // Validate arguments if (s == NULL) { return; } Debug( "-- SESSION TOTAL PKT INFORMATION --\n\n" " TotalSendSize: %I64u\n" " TotalSendSizeReal: %I64u\n" " TotalRecvSize: %I64u\n" " TotalRecvSizeReal: %I64u\n" " Compression Rate: %.2f%% (Send)\n" " %.2f%% (Recv)\n", s->TotalSendSize, s->TotalSendSizeReal, s->TotalRecvSize, s->TotalRecvSizeReal, (float)((double)s->TotalSendSizeReal / (double)s->TotalSendSize * 100.0f), (float)((double)s->TotalRecvSizeReal / (double)s->TotalRecvSize * 100.0f) ); }
/* Display the total data transfer size of the session*/
Display the total data transfer size of the session
NewRpcSession
SESSION *NewRpcSession(CEDAR *cedar, CLIENT_OPTION *option) { return NewRpcSessionEx(cedar, option, NULL, NULL); }
/* Create an RPC session*/
Create an RPC session
NewSessionKey
void NewSessionKey(CEDAR *cedar, UCHAR *session_key, UINT *session_key_32) { // Validate arguments if (cedar == NULL || session_key == NULL || session_key_32 == NULL) { return; } Rand(session_key, SHA1_SIZE); *session_key_32 = Rand32(); }
/* Create a new session key*/
Create a new session key
NewServerSession
SESSION *NewServerSession(CEDAR *cedar, CONNECTION *c, HUB *h, char *username, POLICY *policy) { return NewServerSessionEx(cedar, c, h, username, policy, false, NULL); }
/* Create a server session*/
Create a server session
IsIpcMacAddress
bool IsIpcMacAddress(UCHAR *mac) { // Validate arguments if (mac == NULL) { return false; } if (mac[0] == 0xCA) { return true; } return false; }
/* Check whether the specified MAC address is IPC address*/
Check whether the specified MAC address is IPC address
PrintStatus
void PrintStatus(SESSION *s, wchar_t *str) { // Validate arguments if (s == NULL || str == NULL || s->Account == NULL || s->Cedar->Client == NULL || s->Account->StatusPrinter == NULL) { return; } // Inform the status to the callback function s->Account->StatusPrinter(s, str); }
/* Display the status on the client*/
Display the status on the client
NewCancelList
LIST *NewCancelList() { return NewList(NULL); }
/* Create a cancellation list*/
Create a cancellation list