VirtualBox

Changeset 49616 in vbox for trunk/src/VBox/NetworkServices


Ignore:
Timestamp:
Nov 21, 2013 11:12:48 PM (11 years ago)
Author:
vboxsync
Message:

Delay TTL check until after loopback remapping check.
Fix loopback remapping logic for ICMP errors.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/NetworkServices/NAT/pxping.c

    r49613 r49616  
    877877    }
    878878
    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 
    885879    iplen = IPH_LEN(iph);
    886880#if !defined(RT_OS_DARWIN)
     
    931925    struct icmp_echo_hdr *icmph;
    932926    u16_t id, seq;
     927    ip_addr_t guest_ip, target_ip;
    933928    int mapped;
    934929    struct ping_pcb *pcb;
    935     ip_addr_t guest_ip, target_ip, unmapped_target_ip;
    936930    u16_t guest_id;
    937931    u32_t sum;
     
    953947
    954948    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);
    956950    if (mapped == PXREMAP_FAILED) {
    957951        return;
    958952    }
     953    if (mapped == PXREMAP_ASIS && IPH_TTL(iph) == 1) {
     954        DPRINTF2(("%s: dropping packet with ttl 1\n", __func__));
     955        return;
     956    }
    959957
    960958    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);
    962960    if (pcb == NULL) {
    963961        sys_mutex_unlock(&pxping->lock);
     
    986984    if (mapped == PXREMAP_MAPPED) {
    987985        sum += update32_with_chksum((u32_t *)&iph->src,
    988                                     ip4_addr_get_u32(&unmapped_target_ip));
     986                                    ip4_addr_get_u32(&target_ip));
    989987    }
    990988    else {
     
    10111009    u16_t oipoff, oiphlen, oiplen;
    10121010    u16_t id, seq;
     1011    ip_addr_t guest_ip, target_ip, error_ip;
     1012    int target_mapped, error_mapped;
    10131013    struct ping_pcb *pcb;
    1014     ip_addr_t pcb_src, pcb_dst;
    10151014    u16_t guest_id;
    1016     int mapped;
    10171015    u32_t sum;
    10181016
     
    10841082    }
    10851083
     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
    10861090    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);
    10881092    if (pcb == NULL) {
    10891093        sys_mutex_unlock(&pxping->lock);
     
    10951099
    10961100    /* 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));
    11001102    guest_id = pcb->guest_id;
    11011103
    11021104    sys_mutex_unlock(&pxping->lock);
    11031105
    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    }
    11081115
    11091116    /* rewrite inner ICMP echo header */
     
    11151122    /* rewrite inner IP header */
    11161123    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    }
    11191130    sum = FOLD_U32T(sum);
    11201131    IPH_CHKSUM_SET(oiph, ~sum);
    11211132
     1133    /* keep outer ICMP error header: checksum not affected by the above */
     1134
    11221135    /* rewrite outer IP header */
    11231136    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 {
    11261144        IPH_TTL_SET(iph, IPH_TTL(iph) - 1);
    11271145        sum += PP_NTOHS(~0x0100);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette