Changeset 50487 in vbox
- Timestamp:
- Feb 17, 2014 6:44:33 PM (11 years ago)
- svn:sync-xref-src-repo-rev:
- 92328
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/NetworkServices/NAT/VBoxNetLwipNAT.cpp
r50484 r50487 49 49 #include <iprt/file.h> 50 50 #include <iprt/semaphore.h> 51 #include <iprt/cpp/mem.h> 51 52 #include <iprt/cpp/utils.h> 52 53 #define LOG_GROUP LOG_GROUP_NAT_SERVICE … … 239 240 ComPtr<INATNetworkPortForwardEvent> pfEvt = pEvent; 240 241 242 hrc = pfEvt->COMGETTER(Create)(&fCreateFW); 243 AssertReturn(SUCCEEDED(hrc), hrc); 244 245 hrc = pfEvt->COMGETTER(Ipv6)(&fIPv6FW); 246 AssertReturn(SUCCEEDED(hrc), hrc); 247 241 248 hrc = pfEvt->COMGETTER(Name)(name.asOutParam()); 242 249 AssertReturn(SUCCEEDED(hrc), hrc); … … 255 262 256 263 hrc = pfEvt->COMGETTER(GuestPort)(&lGuestPort); 257 AssertReturn(SUCCEEDED(hrc), hrc);258 259 hrc = pfEvt->COMGETTER(Create)(&fCreateFW);260 AssertReturn(SUCCEEDED(hrc), hrc);261 262 hrc = pfEvt->COMGETTER(Ipv6)(&fIPv6FW);263 264 AssertReturn(SUCCEEDED(hrc), hrc); 264 265 … … 268 269 269 270 NATSEVICEPORTFORWARDRULE r; 270 271 271 RT_ZERO(r); 272 273 if (name.length() > sizeof(r.Pfr.szPfrName))274 {275 hrc = E_INVALIDARG;276 goto port_forward_done;277 }278 272 279 273 r.Pfr.fPfrIPv6 = fIPv6FW; … … 287 281 r.Pfr.iPfrProto = IPPROTO_UDP; 288 282 break; 283 289 284 default: 285 LogRel(("Event: %s %s rule \"%s\": unknown protocol %d\n", 286 fCreateFW ? "Add" : "Remove", 287 fIPv6FW ? "IPv6" : "IPv4", 288 com::Utf8Str(name).c_str(), 289 (int)proto)); 290 290 goto port_forward_done; 291 291 } 292 292 293 LogRel(("Event: %s %s rule \"%s\": %s %s%s%s:%d -> %s%s%s:%d\n", 294 fCreateFW ? "Add" : "Remove", 295 fIPv6FW ? "IPv6" : "IPv4", 296 com::Utf8Str(name).c_str(), 297 proto == NATProtocol_TCP ? "TCP" : "UDP", 298 /* from */ 299 fIPv6FW ? "[" : "", 300 com::Utf8Str(strHostAddr).c_str(), 301 fIPv6FW ? "]" : "", 302 lHostPort, 303 /* to */ 304 fIPv6FW ? "[" : "", 305 com::Utf8Str(strGuestAddr).c_str(), 306 fIPv6FW ? "]" : "", 307 lGuestPort)); 308 309 if (name.length() > sizeof(r.Pfr.szPfrName)) 310 { 311 hrc = E_INVALIDARG; 312 goto port_forward_done; 313 } 293 314 294 315 RTStrPrintf(r.Pfr.szPfrName, sizeof(r.Pfr.szPfrName), … … 309 330 if (fCreateFW) /* Addition */ 310 331 { 311 rules.push_back(r);312 313 natServicePfRegister(rules.back());332 int rc = natServicePfRegister(r); 333 if (RT_SUCCESS(rc)) 334 rules.push_back(r); 314 335 } 315 336 else /* Deletion */ … … 326 347 && (strncmp(natFw.Pfr.szPfrGuestAddr, r.Pfr.szPfrGuestAddr, INET6_ADDRSTRLEN) == 0)) 327 348 { 328 fwspec *pFwCopy = (fwspec *)RTMemAllocZ(sizeof(fwspec)); 329 if (!pFwCopy) 330 { 349 RTCMemAutoPtr<fwspec> pFwCopy; 350 if (RT_UNLIKELY(!pFwCopy.alloc())) 331 351 break; 332 } 333 memcpy(pFwCopy , &natFw.FWSpec, sizeof(fwspec));334 335 /* We shouldn't care about pFwCopy this memory will be freed when336 * will message will arrive to the destination.337 */338 portfwd_rule_del(pFwCopy); 339 352 353 memcpy(pFwCopy.get(), &natFw.FWSpec, sizeof(natFw.FWSpec)); 354 355 int status = portfwd_rule_del(pFwCopy.get()); 356 if (status != 0) 357 break; 358 359 pFwCopy.release(); /* owned by lwip thread now */ 340 360 rules.erase(it); 341 361 break; … … 647 667 int VBoxNetLwipNAT::natServicePfRegister(NATSEVICEPORTFORWARDRULE& natPf) 648 668 { 649 int lrc = 0; 650 int rc = VINF_SUCCESS; 651 int socketSpec = SOCK_STREAM; 652 const char *pszHostAddr; 669 int lrc; 670 653 671 int sockFamily = (natPf.Pfr.fPfrIPv6 ? PF_INET6 : PF_INET); 654 672 int socketSpec; 655 673 switch(natPf.Pfr.iPfrProto) 656 674 { … … 662 680 break; 663 681 default: 664 return VERR_IGNORED; /* Ah, just ignore the garbage */ 665 } 666 667 pszHostAddr = natPf.Pfr.szPfrHostAddr; 668 if (sockFamily == PF_INET && pszHostAddr[0] == '\0') 669 pszHostAddr = "0.0.0.0"; 682 return VERR_IGNORED; 683 } 684 685 const char *pszHostAddr = natPf.Pfr.szPfrHostAddr; 686 if (pszHostAddr[0] == '\0') 687 { 688 if (sockFamily == PF_INET) 689 pszHostAddr = "0.0.0.0"; 690 else 691 pszHostAddr = "::"; 692 } 670 693 671 694 lrc = fwspec_set(&natPf.FWSpec, … … 676 699 natPf.Pfr.szPfrGuestAddr, 677 700 natPf.Pfr.u16PfrGuestPort); 678 679 AssertReturn(!lrc, VERR_IGNORED); 680 681 fwspec *pFwCopy = (fwspec *)RTMemAllocZ(sizeof(fwspec)); 682 AssertPtrReturn(pFwCopy, VERR_IGNORED); 683 684 /* 685 * We need pass the copy, because we can't be sure 686 * how much this pointer will be valid in LWIP environment. 687 */ 688 memcpy(pFwCopy, &natPf.FWSpec, sizeof(fwspec)); 689 690 lrc = portfwd_rule_add(pFwCopy); 691 692 AssertReturn(!lrc, VERR_IGNORED); 693 701 if (lrc != 0) 702 return VERR_IGNORED; 703 704 RTCMemAutoPtr<fwspec> pFwCopy; 705 if (RT_UNLIKELY(!pFwCopy.alloc())) 706 return VERR_IGNORED; 707 708 memcpy(pFwCopy.get(), &natPf.FWSpec, sizeof(natPf.FWSpec)); 709 710 lrc = portfwd_rule_add(pFwCopy.get()); 711 if (lrc != 0) 712 return VERR_IGNORED; 713 714 pFwCopy.release(); /* owned by lwip thread now */ 694 715 return VINF_SUCCESS; 695 716 }
Note:
See TracChangeset
for help on using the changeset viewer.