Changeset 48403 in vbox
- Timestamp:
- Sep 10, 2013 12:02:22 PM (11 years ago)
- Location:
- trunk/src/VBox/NetworkServices/NAT
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/NetworkServices/NAT/VBoxNetLwipNAT.cpp
r48376 r48403 138 138 struct sockaddr_in m_src4; 139 139 struct sockaddr_in6 m_src6; 140 /** 141 * place for registered local interfaces. 142 */ 143 ip4_lomap m_lo2off[10]; 144 ip4_lomap_desc m_loOptDescriptor; 140 145 141 146 uint16_t m_u16Mtu; … … 890 895 m_vecPortForwardRule6.push_back(Rule); 891 896 } 897 898 com::SafeArray<BSTR> strs; 899 int count_strs; 900 hrc = net->COMGETTER(LocalMappings)(ComSafeArrayAsOutParam(strs)); 901 if ( SUCCEEDED(hrc) 902 && (count_strs = strs.size())) 903 { 904 unsigned int j = 0; 905 int i; 906 907 for (i = 0; i < count_strs && j < RT_ELEMENTS(m_lo2off); ++i) 908 { 909 char aszAddr[17]; 910 RTNETADDRIPV4 ip4addr; 911 char *pszTerm; 912 uint32_t u32Off; 913 const char *pszLo2Off = com::Utf8Str(strs[i]).c_str(); 914 915 RT_ZERO(aszAddr); 916 917 pszTerm = RTStrStr(pszLo2Off, ";"); 918 919 if ( !pszTerm 920 || (pszTerm - pszLo2Off) >= 17) 921 continue; 922 923 memcpy(aszAddr, pszLo2Off, (pszTerm - pszLo2Off)); 924 rc = RTNetStrToIPv4Addr(aszAddr, &ip4addr); 925 if (RT_FAILURE(rc)) 926 continue; 927 928 u32Off = RTStrToUInt32(pszTerm + 1); 929 if (u32Off == 0) 930 continue; 931 932 ip4_addr_set_u32(&m_lo2off[j].loaddr, ip4addr.u); 933 m_lo2off[j].off = u32Off; 934 ++j; 935 } 936 937 m_loOptDescriptor.lomap = m_lo2off; 938 m_loOptDescriptor.num_lomap = j; 939 m_ProxyOptions.lomap_desc = &m_loOptDescriptor; 940 } 941 892 942 } /* if (!fDontLoadRulesOnStartup) */ 893 943 -
trunk/src/VBox/NetworkServices/NAT/proxytest.c
r48338 r48403 38 38 static sys_thread_t pollmgr_tid; 39 39 40 40 /* XXX: for mapping loopbacks to addresses in our network (ip4) */ 41 struct netif *g_proxy_netif; 41 42 /* 42 43 * Called on the lwip thread (aka tcpip thread) from tcpip_init() via … … 53 54 54 55 g_proxy_options = opts; 56 g_proxy_netif = proxy_netif; 55 57 56 58 #if 1 -
trunk/src/VBox/NetworkServices/NAT/proxytest.h
r48241 r48403 18 18 struct sockaddr_in6; 19 19 20 struct ip4_lomap 21 { 22 ip_addr_t loaddr; 23 uint32_t off; 24 }; 25 26 struct ip4_lomap_desc 27 { 28 const struct ip4_lomap *lomap; 29 unsigned int num_lomap; 30 }; 31 20 32 struct proxy_options { 21 33 const char *tftp_root; 22 34 const struct sockaddr_in *src4; 23 35 const struct sockaddr_in6 *src6; 36 const struct ip4_lomap_desc *lomap_desc; 24 37 }; 38 39 extern volatile const struct proxy_options *g_proxy_options; 40 extern struct netif *g_proxy_netif; 25 41 26 42 void proxy_init(struct netif *, const struct proxy_options *); -
trunk/src/VBox/NetworkServices/NAT/pxremap.c
r48001 r48403 26 26 27 27 /** 28 * Check if "dst" is an IPv4 address from the network that netif is29 * on, and that it's an address that proxy remaps to host'sloopback.28 * Check if "dst" is an IPv4 address that proxy remaps to host's 29 * loopback. 30 30 */ 31 31 static int 32 proxy_ip4_is_mapped_loopback(struct netif *netif, ip_addr_t *dst) 33 { 32 proxy_ip4_is_mapped_loopback(struct netif *netif, const ip_addr_t *dst, ip_addr_t *lo) 33 { 34 ip_addr_t net; 35 u32_t off; 36 const struct ip4_lomap *lomap; 37 size_t i; 38 39 LWIP_ASSERT1(dst != NULL); 40 41 if (g_proxy_options->lomap_desc == NULL) { 42 return 0; 43 } 44 45 if (!ip_addr_netcmp(dst, &netif->ip_addr, &netif->netmask)) { 46 return 0; 47 } 48 34 49 /* XXX: TODO: check netif is a proxying netif! */ 35 50 36 LWIP_ASSERT1(dst != NULL);37 38 if (ip4_addr1(dst) == ip4_addr1(&netif->ip_addr)39 && ip4_addr2(dst) == ip4_addr2(&netif->ip_addr)40 && ip4_addr3(dst) == ip4_addr3(&netif->ip_addr)41 && ip4_addr4(dst) == ip4_addr4(&netif->ip_addr) + 1)42 {43 return 1;44 }45 51 off = ntohl(ip4_addr_get_u32(dst) & ~ip4_addr_get_u32(&netif->netmask)); 52 lomap = g_proxy_options->lomap_desc->lomap; 53 for (i = 0; i < g_proxy_options->lomap_desc->num_lomap; ++i) { 54 if (off == lomap[i].off) { 55 if (lo != NULL) { 56 ip_addr_copy(*lo, lomap[i].loaddr); 57 } 58 return 1; 59 } 60 } 46 61 return 0; 47 62 } … … 56 71 pxremap_proxy_arp(struct netif *netif, ip_addr_t *dst) 57 72 { 58 return proxy_ip4_is_mapped_loopback(netif, dst );73 return proxy_ip4_is_mapped_loopback(netif, dst, NULL); 59 74 } 60 75 #endif /* ARP_PROXY */ … … 68 83 pxremap_ip4_divert(struct netif *netif, ip_addr_t *dst) 69 84 { 70 return proxy_ip4_is_mapped_loopback(netif, dst );85 return proxy_ip4_is_mapped_loopback(netif, dst, NULL); 71 86 } 72 87 … … 89 104 for (netif = netif_list; netif != NULL; netif = netif->next) { 90 105 if (netif_is_up(netif) /* && this is a proxy netif */) { 91 if (ip4_addr1(src) == ip4_addr1(&netif->ip_addr) 92 && ip4_addr2(src) == ip4_addr2(&netif->ip_addr) 93 && ip4_addr3(src) == ip4_addr3(&netif->ip_addr)) 94 { 95 if (ip4_addr4(src) == ip4_addr4(&netif->ip_addr) + 1) { 96 ip_addr_set_loopback(dst); /* 127.0.0.1 */ 97 return PXREMAP_MAPPED; 98 } 99 #if 0 /* XXX: not yet; make this table driven... */ 100 else if (ip4_addr4(src) == ip4_addr4(&netif->ip_addr) + 2) { 101 IP4_ADDR(dst, 127, 0, 1, 1); /* 127.0.1.1 */ 102 return PXREMAP_MAPPED; 103 } 104 #endif 106 if (proxy_ip4_is_mapped_loopback(netif, src, dst)) { 107 return PXREMAP_MAPPED; 105 108 } 106 109 } … … 124 127 pxremap_inbound_ip4(ip_addr_t *dst, ip_addr_t *src) 125 128 { 129 struct netif *netif; 130 const struct ip4_lomap *lomap; 131 unsigned int i; 132 126 133 if (ip4_addr1(src) != IP_LOOPBACKNET) { 127 134 ip_addr_set(dst, src); … … 129 136 } 130 137 131 if (ip4_addr2(src) == 0 && ip4_addr3(src) == 0 && ip4_addr4(src) == 1) { 132 struct netif *netif; 138 if (g_proxy_options->lomap_desc == NULL) { 139 return PXREMAP_FAILED; 140 } 133 141 134 142 #if 0 /* ?TODO: with multiple interfaces we need to consider fwspec::dst */ 135 136 137 138 143 netif = ip_route(target); 144 if (netif == NULL) { 145 return PXREMAP_FAILED; 146 } 139 147 #else 140 141 142 148 netif = netif_list; 149 LWIP_ASSERT1(netif != NULL); 150 LWIP_ASSERT1(netif->next == NULL); 143 151 #endif 144 IP4_ADDR(dst, 145 ip4_addr1(&netif->ip_addr), 146 ip4_addr2(&netif->ip_addr), 147 ip4_addr3(&netif->ip_addr), 148 ip4_addr4(&netif->ip_addr) + 1); 149 return PXREMAP_MAPPED; 152 153 lomap = g_proxy_options->lomap_desc->lomap; 154 for (i = 0; i < g_proxy_options->lomap_desc->num_lomap; ++i) { 155 if (ip_addr_cmp(src, &lomap[i].loaddr)) { 156 ip_addr_t net; 157 158 ip_addr_get_network(&net, &netif->ip_addr, &netif->netmask); 159 ip4_addr_set_u32(dst, 160 htonl(ntohl(ip4_addr_get_u32(&net)) 161 + lomap[i].off)); 162 return PXREMAP_MAPPED; 163 } 150 164 } 151 165
Note:
See TracChangeset
for help on using the changeset viewer.