Changeset 49616 in vbox for trunk/src/VBox/NetworkServices
- Timestamp:
- Nov 21, 2013 11:12:48 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/NetworkServices/NAT/pxping.c
r49613 r49616 877 877 } 878 878 879 /* XXX: TODO: not for loopback */880 if (IPH_TTL(iph) == 1) {881 DPRINTF2(("%s: dropping packet with ttl 1\n", __func__));882 return;883 }884 885 879 iplen = IPH_LEN(iph); 886 880 #if !defined(RT_OS_DARWIN) … … 931 925 struct icmp_echo_hdr *icmph; 932 926 u16_t id, seq; 927 ip_addr_t guest_ip, target_ip; 933 928 int mapped; 934 929 struct ping_pcb *pcb; 935 ip_addr_t guest_ip, target_ip, unmapped_target_ip;936 930 u16_t guest_id; 937 931 u32_t sum; … … 953 947 954 948 ip_addr_copy(target_ip, iph->src); 955 mapped = pxremap_inbound_ip4(& unmapped_target_ip, &target_ip);949 mapped = pxremap_inbound_ip4(&target_ip, &target_ip); 956 950 if (mapped == PXREMAP_FAILED) { 957 951 return; 958 952 } 953 if (mapped == PXREMAP_ASIS && IPH_TTL(iph) == 1) { 954 DPRINTF2(("%s: dropping packet with ttl 1\n", __func__)); 955 return; 956 } 959 957 960 958 sys_mutex_lock(&pxping->lock); 961 pcb = pxping_pcb_for_reply(pxping, 0, ip_2_ipX(& unmapped_target_ip), id);959 pcb = pxping_pcb_for_reply(pxping, 0, ip_2_ipX(&target_ip), id); 962 960 if (pcb == NULL) { 963 961 sys_mutex_unlock(&pxping->lock); … … 986 984 if (mapped == PXREMAP_MAPPED) { 987 985 sum += update32_with_chksum((u32_t *)&iph->src, 988 ip4_addr_get_u32(& unmapped_target_ip));986 ip4_addr_get_u32(&target_ip)); 989 987 } 990 988 else { … … 1011 1009 u16_t oipoff, oiphlen, oiplen; 1012 1010 u16_t id, seq; 1011 ip_addr_t guest_ip, target_ip, error_ip; 1012 int target_mapped, error_mapped; 1013 1013 struct ping_pcb *pcb; 1014 ip_addr_t pcb_src, pcb_dst;1015 1014 u16_t guest_id; 1016 int mapped;1017 1015 u32_t sum; 1018 1016 … … 1084 1082 } 1085 1083 1084 ip_addr_copy(target_ip, oiph->dest); /* inner (failed) */ 1085 target_mapped = pxremap_inbound_ip4(&target_ip, &target_ip); 1086 if (target_mapped == PXREMAP_FAILED) { 1087 return; 1088 } 1089 1086 1090 sys_mutex_lock(&pxping->lock); 1087 pcb = pxping_pcb_for_reply(pxping, 0, ip_2_ipX(& oiph->dest), id);1091 pcb = pxping_pcb_for_reply(pxping, 0, ip_2_ipX(&target_ip), id); 1088 1092 if (pcb == NULL) { 1089 1093 sys_mutex_unlock(&pxping->lock); … … 1095 1099 1096 1100 /* save info before unlocking since pcb may expire */ 1097 mapped = pcb->is_mapped; 1098 ip_addr_copy(pcb_src, *ipX_2_ip(&pcb->src)); 1099 ip_addr_copy(pcb_dst, *ipX_2_ip(&pcb->dst)); 1101 ip_addr_copy(guest_ip, *ipX_2_ip(&pcb->src)); 1100 1102 guest_id = pcb->guest_id; 1101 1103 1102 1104 sys_mutex_unlock(&pxping->lock); 1103 1105 1104 /* 1105 * NB: Checksum in the outer ICMP error header is not affected by 1106 * changes to inner headers. 1107 */ 1106 ip_addr_copy(error_ip, iph->src); /* node that reports the error */ 1107 error_mapped = pxremap_inbound_ip4(&error_ip, &error_ip); 1108 if (error_mapped == PXREMAP_FAILED) { 1109 return; 1110 } 1111 if (error_mapped == PXREMAP_ASIS && IPH_TTL(iph) == 1) { 1112 DPRINTF2(("%s: dropping packet with ttl 1\n", __func__)); 1113 return; 1114 } 1108 1115 1109 1116 /* rewrite inner ICMP echo header */ … … 1115 1122 /* rewrite inner IP header */ 1116 1123 sum = (u16_t)~IPH_CHKSUM(oiph); 1117 sum += update32_with_chksum((u32_t *)&oiph->src, ip4_addr_get_u32(&pcb_src)); 1118 /* XXX: FIXME: rewrite dst if mapped */ 1124 sum += update32_with_chksum((u32_t *)&oiph->src, 1125 ip4_addr_get_u32(&guest_ip)); 1126 if (target_mapped == PXREMAP_MAPPED) { 1127 sum += update32_with_chksum((u32_t *)&oiph->dest, 1128 ip4_addr_get_u32(&target_ip)); 1129 } 1119 1130 sum = FOLD_U32T(sum); 1120 1131 IPH_CHKSUM_SET(oiph, ~sum); 1121 1132 1133 /* keep outer ICMP error header: checksum not affected by the above */ 1134 1122 1135 /* rewrite outer IP header */ 1123 1136 sum = (u16_t)~IPH_CHKSUM(iph); 1124 sum += update32_with_chksum((u32_t *)&iph->dest, ip4_addr_get_u32(&pcb_src)); 1125 if (!mapped) { /* XXX: FIXME: error may be from elsewhere */ 1137 sum += update32_with_chksum((u32_t *)&iph->dest, 1138 ip4_addr_get_u32(&guest_ip)); 1139 if (error_mapped == PXREMAP_MAPPED) { 1140 sum += update32_with_chksum((u32_t *)&iph->src, 1141 ip4_addr_get_u32(&error_ip)); 1142 } 1143 else { 1126 1144 IPH_TTL_SET(iph, IPH_TTL(iph) - 1); 1127 1145 sum += PP_NTOHS(~0x0100);
Note:
See TracChangeset
for help on using the changeset viewer.