Changeset 87399 in vbox
- Timestamp:
- Jan 23, 2021 1:17:40 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/NetworkServices/NAT/VBoxNetLwipNAT.cpp
r87398 r87399 192 192 const char **getHostNameservers(); 193 193 194 static int natServiceP fRegister(NATSERVICEPORTFORWARDRULE& natServicePf);195 static int natServiceP rocessRegisteredPf(VECNATSERVICEPF& vecPf);194 static int natServiceProcessRegisteredPf(VECNATSERVICEPF &vecPf); 195 static int natServicePfRegister(NATSERVICEPORTFORWARDRULE &natServicePf); 196 196 197 197 /* input from intnet */ … … 922 922 923 923 924 /*static*/ int VBoxNetLwipNAT::natServicePfRegister(NATSERVICEPORTFORWARDRULE& natPf) 925 { 926 int lrc; 927 928 int sockFamily = (natPf.Pfr.fPfrIPv6 ? PF_INET6 : PF_INET); 929 int socketSpec; 930 switch(natPf.Pfr.iPfrProto) 931 { 932 case IPPROTO_TCP: 933 socketSpec = SOCK_STREAM; 934 break; 935 case IPPROTO_UDP: 936 socketSpec = SOCK_DGRAM; 937 break; 938 default: 939 return VERR_IGNORED; 940 } 941 942 const char *pszHostAddr = natPf.Pfr.szPfrHostAddr; 943 if (pszHostAddr[0] == '\0') 944 { 945 if (sockFamily == PF_INET) 946 pszHostAddr = "0.0.0.0"; 947 else 948 pszHostAddr = "::"; 949 } 950 951 lrc = fwspec_set(&natPf.FWSpec, 952 sockFamily, 953 socketSpec, 954 pszHostAddr, 955 natPf.Pfr.u16PfrHostPort, 956 natPf.Pfr.szPfrGuestAddr, 957 natPf.Pfr.u16PfrGuestPort); 958 if (lrc != 0) 959 return VERR_IGNORED; 960 961 fwspec *pFwCopy = (fwspec *)RTMemDup(&natPf.FWSpec, sizeof(natPf.FWSpec)); 962 if (pFwCopy) 963 { 964 lrc = portfwd_rule_add(pFwCopy); 965 if (lrc == 0) 966 return VINF_SUCCESS; /* (pFwCopy is owned by lwip thread now.) */ 967 RTMemFree(pFwCopy); 968 } 924 static int fetchNatPortForwardRules(const ComNatPtr& nat, bool fIsIPv6, VECNATSERVICEPF& vec) 925 { 926 HRESULT hrc; 927 com::SafeArray<BSTR> rules; 928 if (fIsIPv6) 929 hrc = nat->COMGETTER(PortForwardRules6)(ComSafeArrayAsOutParam(rules)); 969 930 else 970 LogRel(("Unable to allocate memory for %s rule \"%s\"\n", 971 natPf.Pfr.fPfrIPv6 ? "IPv6" : "IPv4", 972 natPf.Pfr.szPfrName)); 973 return VERR_IGNORED; 974 } 975 976 977 /*static*/ int VBoxNetLwipNAT::natServiceProcessRegisteredPf(VECNATSERVICEPF& vecRules) 931 hrc = nat->COMGETTER(PortForwardRules4)(ComSafeArrayAsOutParam(rules)); 932 AssertComRCReturn(hrc, VERR_INTERNAL_ERROR); 933 934 NATSERVICEPORTFORWARDRULE Rule; 935 for (size_t idxRules = 0; idxRules < rules.size(); ++idxRules) 936 { 937 Log(("%d-%s rule: %ls\n", idxRules, (fIsIPv6 ? "IPv6" : "IPv4"), rules[idxRules])); 938 RT_ZERO(Rule); 939 940 int rc = netPfStrToPf(com::Utf8Str(rules[idxRules]).c_str(), fIsIPv6, 941 &Rule.Pfr); 942 if (RT_FAILURE(rc)) 943 continue; 944 945 vec.push_back(Rule); 946 } 947 948 return VINF_SUCCESS; 949 } 950 951 952 /* static */ 953 int VBoxNetLwipNAT::natServiceProcessRegisteredPf(VECNATSERVICEPF& vecRules) 978 954 { 979 955 ITERATORNATSERVICEPF it; … … 1001 977 1002 978 return VINF_SUCCESS; 979 } 980 981 982 /* static */ 983 int VBoxNetLwipNAT::natServicePfRegister(NATSERVICEPORTFORWARDRULE &natPf) 984 { 985 int lrc; 986 987 int sockFamily = (natPf.Pfr.fPfrIPv6 ? PF_INET6 : PF_INET); 988 int socketSpec; 989 switch(natPf.Pfr.iPfrProto) 990 { 991 case IPPROTO_TCP: 992 socketSpec = SOCK_STREAM; 993 break; 994 case IPPROTO_UDP: 995 socketSpec = SOCK_DGRAM; 996 break; 997 default: 998 return VERR_IGNORED; 999 } 1000 1001 const char *pszHostAddr = natPf.Pfr.szPfrHostAddr; 1002 if (pszHostAddr[0] == '\0') 1003 { 1004 if (sockFamily == PF_INET) 1005 pszHostAddr = "0.0.0.0"; 1006 else 1007 pszHostAddr = "::"; 1008 } 1009 1010 lrc = fwspec_set(&natPf.FWSpec, 1011 sockFamily, 1012 socketSpec, 1013 pszHostAddr, 1014 natPf.Pfr.u16PfrHostPort, 1015 natPf.Pfr.szPfrGuestAddr, 1016 natPf.Pfr.u16PfrGuestPort); 1017 if (lrc != 0) 1018 return VERR_IGNORED; 1019 1020 fwspec *pFwCopy = (fwspec *)RTMemDup(&natPf.FWSpec, sizeof(natPf.FWSpec)); 1021 if (pFwCopy) 1022 { 1023 lrc = portfwd_rule_add(pFwCopy); 1024 if (lrc == 0) 1025 return VINF_SUCCESS; /* (pFwCopy is owned by lwip thread now.) */ 1026 RTMemFree(pFwCopy); 1027 } 1028 else 1029 LogRel(("Unable to allocate memory for %s rule \"%s\"\n", 1030 natPf.Pfr.fPfrIPv6 ? "IPv6" : "IPv4", 1031 natPf.Pfr.szPfrName)); 1032 return VERR_IGNORED; 1003 1033 } 1004 1034 … … 1434 1464 1435 1465 1436 static int fetchNatPortForwardRules(const ComNatPtr& nat, bool fIsIPv6, VECNATSERVICEPF& vec)1437 {1438 HRESULT hrc;1439 com::SafeArray<BSTR> rules;1440 if (fIsIPv6)1441 hrc = nat->COMGETTER(PortForwardRules6)(ComSafeArrayAsOutParam(rules));1442 else1443 hrc = nat->COMGETTER(PortForwardRules4)(ComSafeArrayAsOutParam(rules));1444 AssertComRCReturn(hrc, VERR_INTERNAL_ERROR);1445 1446 NATSERVICEPORTFORWARDRULE Rule;1447 for (size_t idxRules = 0; idxRules < rules.size(); ++idxRules)1448 {1449 Log(("%d-%s rule: %ls\n", idxRules, (fIsIPv6 ? "IPv6" : "IPv4"), rules[idxRules]));1450 RT_ZERO(Rule);1451 1452 int rc = netPfStrToPf(com::Utf8Str(rules[idxRules]).c_str(), fIsIPv6,1453 &Rule.Pfr);1454 if (RT_FAILURE(rc))1455 continue;1456 1457 vec.push_back(Rule);1458 }1459 1460 return VINF_SUCCESS;1461 }1462 1463 1464 1466 #ifndef VBOX_WITH_HARDENING 1465 1467
Note:
See TracChangeset
for help on using the changeset viewer.