// Initialize the options for the virtual host void NiSetDefaultVhOption(NAT *n, VH_OPTION *o) { // Validate arguments if (o == NULL) { return; } Zero(o, sizeof(VH_OPTION)); GenMacAddress(o->MacAddress); // Set the virtual IP to 192.168.30.1/24 SetIP(&o->Ip, 192, 168, 30, 1); SetIP(&o->Mask, 255, 255, 255, 0); o->UseNat = true; o->Mtu = 1500; o->NatTcpTimeout = 1800; o->NatUdpTimeout = 60; o->UseDhcp = true; SetIP(&o->DhcpLeaseIPStart, 192, 168, 30, 10); SetIP(&o->DhcpLeaseIPEnd, 192, 168, 30, 200); SetIP(&o->DhcpSubnetMask, 255, 255, 255, 0); o->DhcpExpireTimeSpan = 7200; o->SaveLog = true; SetIP(&o->DhcpGatewayAddress, 192, 168, 30, 1); SetIP(&o->DhcpDnsServerAddress, 192, 168, 30, 1); GetDomainName(o->DhcpDomainName, sizeof(o->DhcpDomainName)); }
// 仮想ホストオプションの読み込み (拡張) void NiLoadVhOptionEx(VH_OPTION *o, FOLDER *root) { FOLDER *host, *nat, *dhcp; char mac_address[MAX_SIZE]; // 引数チェック if (o == NULL || root == NULL) { return; } host = CfgGetFolder(root, "VirtualHost"); nat = CfgGetFolder(root, "VirtualRouter"); dhcp = CfgGetFolder(root, "VirtualDhcpServer"); Zero(o, sizeof(VH_OPTION)); GenMacAddress(o->MacAddress); if (CfgGetStr(host, "VirtualHostMacAddress", mac_address, sizeof(mac_address))) { BUF *b = StrToBin(mac_address); if (b != NULL) { if (b->Size == 6) { Copy(o->MacAddress, b->Buf, 6); } } FreeBuf(b); } CfgGetIp(host, "VirtualHostIp", &o->Ip); CfgGetIp(host, "VirtualHostIpSubnetMask", &o->Mask); o->UseNat = CfgGetBool(nat, "NatEnabled"); o->Mtu = CfgGetInt(nat, "NatMtu"); o->NatTcpTimeout = CfgGetInt(nat, "NatTcpTimeout"); o->NatUdpTimeout = CfgGetInt(nat, "NatUdpTimeout"); o->UseDhcp = CfgGetBool(dhcp, "DhcpEnabled"); CfgGetIp(dhcp, "DhcpLeaseIPStart", &o->DhcpLeaseIPStart); CfgGetIp(dhcp, "DhcpLeaseIPEnd", &o->DhcpLeaseIPEnd); CfgGetIp(dhcp, "DhcpSubnetMask", &o->DhcpSubnetMask); o->DhcpExpireTimeSpan = CfgGetInt(dhcp, "DhcpExpireTimeSpan"); CfgGetIp(dhcp, "DhcpGatewayAddress", &o->DhcpGatewayAddress); CfgGetIp(dhcp, "DhcpDnsServerAddress", &o->DhcpDnsServerAddress); CfgGetStr(dhcp, "DhcpDomainName", o->DhcpDomainName, sizeof(o->DhcpDomainName)); Trim(o->DhcpDomainName); if (StrLen(o->DhcpDomainName) == 0) { //GetDomainName(o->DhcpDomainName, sizeof(o->DhcpDomainName)); } o->SaveLog = CfgGetBool(root, "SaveLog"); }
// Generate a MAC address of the interface 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); Hash(hash, b->Buf, b->Size, true); Copy(f->MacAddress + 2, hash, 4); f->MacAddress[1] = 0xA3; FreeBuf(b); }
// Initialize the packet adapter bool NullPaInit(SESSION *s) { NULL_LAN *n; // Validate arguments if (s == NULL) { return false; } n = ZeroMalloc(sizeof(NULL_LAN)); s->PacketAdapter->Param = (void *)n; n->Cancel = NewCancel(); n->PacketQueue = NewQueue(); n->Event = NewEvent(); GenMacAddress(n->MacAddr); n->PacketGeneratorThread = NewThread(NullPacketGenerateThread, n); return true; }
// Create new local-bridge BRIDGE *BrNewBridge(HUB *h, char *name, POLICY *p, bool local, bool monitor, bool tapmode, char *tapaddr, bool limit_broadcast, LOCALBRIDGE *parent_local_bridge) { BRIDGE *b; POLICY *policy; THREAD *t; // Validate arguments if (h == NULL || name == NULL || parent_local_bridge == NULL) { return NULL; } if (p == NULL) { policy = ClonePolicy(GetDefaultPolicy()); } else { policy = ClonePolicy(p); } b = ZeroMalloc(sizeof(BRIDGE)); b->Cedar = h->Cedar; b->Hub = h; StrCpy(b->Name, sizeof(b->Name), name); b->Policy = policy; b->Local = local; b->Monitor = monitor; b->TapMode = tapmode; b->LimitBroadcast = limit_broadcast; b->ParentLocalBridge = parent_local_bridge; if (b->TapMode) { if (tapaddr != NULL && IsZero(tapaddr, 6) == false) { Copy(b->TapMacAddress, tapaddr, 6); } else { GenMacAddress(b->TapMacAddress); } } if (monitor) { // Enabling monitoring mode policy->MonitorPort = true; } if (b->LimitBroadcast == false) { // Disable broadcast limiter policy->NoBroadcastLimiter = true; } // Start thread t = NewThread(BrBridgeThread, b); WaitThreadInit(t); ReleaseThread(t); return b; }
// Add a local-bridge void AddLocalBridge(CEDAR *c, char *hubname, char *devicename, bool local, bool monitor, bool tapmode, char *tapaddr, bool limit_broadcast) { UINT i; HUB *h = NULL; LOCALBRIDGE *br = NULL; // Validate arguments if (c == NULL || hubname == NULL || devicename == NULL) { return; } if (OS_IS_UNIX(GetOsInfo()->OsType) == false) { tapmode = false; } LockList(c->HubList); { LockList(c->LocalBridgeList); { bool exists = false; // Ensure that the same configuration local-bridge doesn't exist already for (i = 0;i < LIST_NUM(c->LocalBridgeList);i++) { LOCALBRIDGE *br = LIST_DATA(c->LocalBridgeList, i); if (StrCmpi(br->DeviceName, devicename) == 0) { if (StrCmpi(br->HubName, hubname) == 0) { if (br->TapMode == tapmode) { exists = true; } } } } if (exists == false) { // Add configuration br = ZeroMalloc(sizeof(LOCALBRIDGE)); StrCpy(br->HubName, sizeof(br->HubName), hubname); StrCpy(br->DeviceName, sizeof(br->DeviceName), devicename); br->Bridge = NULL; br->Local = local; br->TapMode = tapmode; br->LimitBroadcast = limit_broadcast; br->Monitor = monitor; if (br->TapMode) { if (tapaddr != NULL && IsZero(tapaddr, 6) == false) { Copy(br->TapMacAddress, tapaddr, 6); } else { GenMacAddress(br->TapMacAddress); } } Add(c->LocalBridgeList, br); // Find the hub for (i = 0;i < LIST_NUM(c->HubList);i++) { HUB *hub = LIST_DATA(c->HubList, i); if (StrCmpi(hub->Name, br->HubName) == 0) { h = hub; AddRef(h->ref); break; } } } } UnlockList(c->LocalBridgeList); } UnlockList(c->HubList); // Start the local-bridge immediately if (h != NULL && br != NULL && h->Type != HUB_TYPE_FARM_DYNAMIC) { Lock(h->lock_online); { if (h->Offline == false) { LockList(c->LocalBridgeList); { if (IsInList(c->LocalBridgeList, br)) { if (br->Bridge == NULL) { br->Bridge = BrNewBridge(h, br->DeviceName, NULL, br->Local, br->Monitor, br->TapMode, br->TapMacAddress, br->LimitBroadcast, br); } } } UnlockList(c->LocalBridgeList); } } Unlock(h->lock_online); } ReleaseHub(h); }
// Read the virtual host option (extended) void NiLoadVhOptionEx(VH_OPTION *o, FOLDER *root) { FOLDER *host, *nat, *dhcp; char mac_address[MAX_SIZE]; // Validate arguments if (o == NULL || root == NULL) { return; } host = CfgGetFolder(root, "VirtualHost"); nat = CfgGetFolder(root, "VirtualRouter"); dhcp = CfgGetFolder(root, "VirtualDhcpServer"); Zero(o, sizeof(VH_OPTION)); GenMacAddress(o->MacAddress); if (CfgGetStr(host, "VirtualHostMacAddress", mac_address, sizeof(mac_address))) { BUF *b = StrToBin(mac_address); if (b != NULL) { if (b->Size == 6) { Copy(o->MacAddress, b->Buf, 6); } } FreeBuf(b); } CfgGetIp(host, "VirtualHostIp", &o->Ip); CfgGetIp(host, "VirtualHostIpSubnetMask", &o->Mask); o->UseNat = CfgGetBool(nat, "NatEnabled"); o->Mtu = CfgGetInt(nat, "NatMtu"); o->NatTcpTimeout = CfgGetInt(nat, "NatTcpTimeout"); o->NatUdpTimeout = CfgGetInt(nat, "NatUdpTimeout"); o->UseDhcp = CfgGetBool(dhcp, "DhcpEnabled"); CfgGetIp(dhcp, "DhcpLeaseIPStart", &o->DhcpLeaseIPStart); CfgGetIp(dhcp, "DhcpLeaseIPEnd", &o->DhcpLeaseIPEnd); CfgGetIp(dhcp, "DhcpSubnetMask", &o->DhcpSubnetMask); o->DhcpExpireTimeSpan = CfgGetInt(dhcp, "DhcpExpireTimeSpan"); CfgGetIp(dhcp, "DhcpGatewayAddress", &o->DhcpGatewayAddress); CfgGetIp(dhcp, "DhcpDnsServerAddress", &o->DhcpDnsServerAddress); CfgGetIp(dhcp, "DhcpDnsServerAddress2", &o->DhcpDnsServerAddress2); CfgGetStr(dhcp, "DhcpDomainName", o->DhcpDomainName, sizeof(o->DhcpDomainName)); CfgGetStr(dhcp, "DhcpPushRoutes", o->DhcpPushRoutes, sizeof(o->DhcpPushRoutes)); // Test code // StrCpy(o->DhcpPushRoutes, sizeof(o->DhcpPushRoutes), // "130.158.6.0/24/192.168.9.2 130.158.80.244/255.255.255.255/192.168.9.2"); NormalizeClasslessRouteTableStr(o->DhcpPushRoutes, sizeof(o->DhcpPushRoutes), o->DhcpPushRoutes); o->ApplyDhcpPushRoutes = true; Trim(o->DhcpDomainName); if (StrLen(o->DhcpDomainName) == 0) { //GetDomainName(o->DhcpDomainName, sizeof(o->DhcpDomainName)); } o->SaveLog = CfgGetBool(root, "SaveLog"); }