Changeset 15207 in vbox for trunk/src/VBox/Devices/Network/slirp
- Timestamp:
- Dec 9, 2008 10:09:16 PM (16 years ago)
- Location:
- trunk/src/VBox/Devices/Network/slirp
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/slirp/bootp.c
r15054 r15207 289 289 if (*slirp_hostname) 290 290 { 291 val = strlen(slirp_hostname);291 val = (int)strlen(slirp_hostname); 292 292 *q++ = RFC1533_HOSTNAME; 293 293 *q++ = val; … … 298 298 if (pData->pszDomain && pData->fPassDomain) 299 299 { 300 val = strlen(pData->pszDomain);300 val = (int)strlen(pData->pszDomain); 301 301 *q++ = RFC1533_DOMAINNAME; 302 302 *q++ = val; -
trunk/src/VBox/Devices/Network/slirp/socket.c
r15190 r15207 97 97 int n, nn, lss, total; 98 98 struct sbuf *sb = &so->so_snd; 99 int len = sb->sb_datalen - sb->sb_cc;99 size_t len = sb->sb_datalen - sb->sb_cc; 100 100 struct iovec iov[2]; 101 101 int mss = so->so_tcpcb->t_maxseg; … … 128 128 iov[0].iov_len = (sb->sb_data + sb->sb_datalen) - sb->sb_wptr; 129 129 /* Should never succeed, but... */ 130 if (iov[0].iov_len > len) iov[0].iov_len = len; 130 if (iov[0].iov_len > len) 131 iov[0].iov_len = len; 131 132 len -= iov[0].iov_len; 132 133 if (len) … … 328 329 int n,nn; 329 330 struct sbuf *sb = &so->so_rcv; 330 int len = sb->sb_cc;331 size_t len = sb->sb_cc; 331 332 struct iovec iov[2]; 332 333 … … 355 356 iov[0].iov_len = sb->sb_wptr - sb->sb_rptr; 356 357 /* Should never succeed, but... */ 357 if (iov[0].iov_len > len) iov[0].iov_len = len; 358 if (iov[0].iov_len > len) 359 iov[0].iov_len = len; 358 360 n = 1; 359 361 } … … 361 363 { 362 364 iov[0].iov_len = (sb->sb_data + sb->sb_datalen) - sb->sb_rptr; 363 if (iov[0].iov_len > len) iov[0].iov_len = len; 365 if (iov[0].iov_len > len) 366 iov[0].iov_len = len; 364 367 len -= iov[0].iov_len; 365 368 if (len) … … 433 436 DEBUG_ARG("so = %lx", (long)so); 434 437 435 if (so->so_type == IPPROTO_ICMP) { /* This is a "ping" reply */ 438 if (so->so_type == IPPROTO_ICMP) 439 { 440 /* This is a "ping" reply */ 436 441 #if !defined(VBOX_WITH_SLIRP_ICMP) || (defined(VBOX_WITH_SLIRP_ICMP) && !defined(RT_OS_WINDOWS)) 437 442 sorecvfrom_icmp_unix(pData, so); 438 443 #endif 439 444 #if defined(VBOX_WITH_SLIRP_ICMP) && defined(RT_OS_WINDOWS) 440 sorecvfrom_icmp_win(pData, so); 441 #endif 442 udp_detach(pData, so); 443 } else { /* A "normal" UDP packet */ 444 struct mbuf *m; 445 int len, n; 445 sorecvfrom_icmp_win(pData, so); 446 #endif 447 udp_detach(pData, so); 448 } 449 else 450 { 451 /* A "normal" UDP packet */ 452 struct mbuf *m; 453 size_t len; 454 u_long n; 446 455 447 456 if (!(m = m_get(pData))) … … 774 783 send_icmp_to_guest(PNATState pData, char *buff, size_t len, struct socket *so, const struct sockaddr_in *addr) 775 784 { 776 struct ip *ip; 777 uint32_t dst,src; 778 char ip_copy[256]; 779 struct icmp *icp; 780 int old_ip_len; 781 struct mbuf *m; 782 struct icmp_msg *icm; 783 784 ip = (struct ip *)buff; 785 icp = (struct icmp *)((char *)ip + (ip->ip_hl << 2)); 786 787 Assert(icp->icmp_type == ICMP_ECHOREPLY || icp->icmp_type == ICMP_TIMXCEED); 788 789 if (icp->icmp_type == ICMP_TIMXCEED ) { 790 ip = &icp->icmp_ip; 791 } 792 793 icm = icmp_find_original_mbuf(pData, ip); 794 795 if (icm == NULL) 796 { 797 LogRel(("NAT: Can't find the corresponding packet for the received ICMP\n")); 798 return; 799 } 800 801 m = icm->im_m; 802 Assert(m != NULL); 803 804 src = addr->sin_addr.s_addr; 805 806 ip = mtod(m, struct ip *); 807 /* Now ip is pointing on header we've sent from guest */ 808 if (icp->icmp_type == ICMP_TIMXCEED) { 809 old_ip_len = (ip->ip_hl << 2) + 64; 810 memcpy(ip_copy, ip, old_ip_len); 811 } 812 813 /* source address from original IP packet*/ 814 dst = ip->ip_src.s_addr; 815 816 /* overide ther tail of old packet */ 817 memcpy(m->m_data, buff, len); 818 m->m_len = len; 819 ip = mtod(m, struct ip *); /* ip is from mbuf we've overrided */ 820 821 icp = (struct icmp *)((char *)ip + (ip->ip_hl << 2)); 822 if (icp->icmp_type == ICMP_TIMXCEED) { 823 /* according RFC 793 error messages required copy of initial IP header + 64 bit */ 824 memcpy(&icp->icmp_ip, ip_copy, old_ip_len); 825 ip->ip_tos=((ip->ip_tos & 0x1E) | 0xC0); /* high priority for errors */ 826 } 827 828 /* the low level expects fields to be in host format so let's convert them*/ 829 NTOHS(ip->ip_len); 830 NTOHS(ip->ip_off); 831 NTOHS(ip->ip_id); 832 ip->ip_src.s_addr = src; 833 ip->ip_dst.s_addr = dst; 834 icmp_reflect(pData, m); 835 LIST_REMOVE(icm, im_list); 836 /* Don't call m_free here*/ 837 free(icm); 785 struct ip *ip; 786 uint32_t dst,src; 787 char ip_copy[256]; 788 struct icmp *icp; 789 int old_ip_len; 790 struct mbuf *m; 791 struct icmp_msg *icm; 792 793 ip = (struct ip *)buff; 794 icp = (struct icmp *)((char *)ip + (ip->ip_hl << 2)); 795 796 Assert(icp->icmp_type == ICMP_ECHOREPLY || icp->icmp_type == ICMP_TIMXCEED); 797 798 if (icp->icmp_type == ICMP_TIMXCEED) 799 ip = &icp->icmp_ip; 800 801 icm = icmp_find_original_mbuf(pData, ip); 802 803 if (icm == NULL) 804 { 805 LogRel(("NAT: Can't find the corresponding packet for the received ICMP\n")); 806 return; 807 } 808 809 m = icm->im_m; 810 Assert(m != NULL); 811 812 src = addr->sin_addr.s_addr; 813 814 ip = mtod(m, struct ip *); 815 /* Now ip is pointing on header we've sent from guest */ 816 if (icp->icmp_type == ICMP_TIMXCEED) 817 { 818 old_ip_len = (ip->ip_hl << 2) + 64; 819 memcpy(ip_copy, ip, old_ip_len); 820 } 821 822 /* source address from original IP packet*/ 823 dst = ip->ip_src.s_addr; 824 825 /* overide ther tail of old packet */ 826 memcpy(m->m_data, buff, len); 827 m->m_len = len; 828 ip = mtod(m, struct ip *); /* ip is from mbuf we've overrided */ 829 830 icp = (struct icmp *)((char *)ip + (ip->ip_hl << 2)); 831 if (icp->icmp_type == ICMP_TIMXCEED) 832 { 833 /* according RFC 793 error messages required copy of initial IP header + 64 bit */ 834 memcpy(&icp->icmp_ip, ip_copy, old_ip_len); 835 ip->ip_tos=((ip->ip_tos & 0x1E) | 0xC0); /* high priority for errors */ 836 } 837 838 /* the low level expects fields to be in host format so let's convert them*/ 839 NTOHS(ip->ip_len); 840 NTOHS(ip->ip_off); 841 NTOHS(ip->ip_id); 842 ip->ip_src.s_addr = src; 843 ip->ip_dst.s_addr = dst; 844 icmp_reflect(pData, m); 845 LIST_REMOVE(icm, im_list); 846 /* Don't call m_free here*/ 847 free(icm); 838 848 } 839 849 … … 842 852 sorecvfrom_icmp_win(PNATState pData, struct socket *so) 843 853 { 844 int len; 845 int i; 846 struct ip *ip; 847 struct mbuf *m; 848 struct icmp *icp; 849 struct icmp_msg *icm; 850 struct ip *ip_broken; /* ICMP returns header + 64 bit of packet */ 851 uint32_t src; 852 ICMP_ECHO_REPLY *icr; 853 u_char code = ~0; 854 len = pData->pfIcmpParseReplies(pData->pvIcmpBuffer, pData->szIcmpBuffer); 855 if (len <= 0) 854 int len; 855 int i; 856 struct ip *ip; 857 struct mbuf *m; 858 struct icmp *icp; 859 struct icmp_msg *icm; 860 struct ip *ip_broken; /* ICMP returns header + 64 bit of packet */ 861 uint32_t src; 862 ICMP_ECHO_REPLY *icr; 863 u_char code = ~0; 864 len = pData->pfIcmpParseReplies(pData->pvIcmpBuffer, pData->szIcmpBuffer); 865 if (len <= 0) 866 { 867 LogRel(("NAT: Error (%d) occurred on ICMP receiving\n", GetLastError())); 868 return; 869 } 870 LogRel(("IcmpParseReplies returns %ld\n", len)); 871 icr = (ICMP_ECHO_REPLY *)pData->pvIcmpBuffer; 872 for (i = 0; i < len; ++i) 873 { 874 switch(icr[i].Status) 856 875 { 857 LogRel(("NAT: Error (%d) occurred on ICMP receiving\n", GetLastError())); 858 return; 876 case IP_DEST_HOST_UNREACHABLE: 877 code = (code != ~0 ? code : ICMP_UNREACH_HOST); 878 case IP_DEST_NET_UNREACHABLE: 879 code = (code != ~0 ? code : ICMP_UNREACH_NET); 880 case IP_DEST_PROT_UNREACHABLE: 881 code = (code != ~0 ? code : ICMP_UNREACH_PROTOCOL); 882 /* UNREACH error inject here */ 883 case IP_DEST_PORT_UNREACHABLE: 884 code = (code != ~0 ? code : ICMP_UNREACH_PORT); 885 icmp_error(pData, so->so_m, ICMP_UNREACH, code, 0, "Error occurred!!!"); 886 break; 887 case IP_SUCCESS: /* echo replied */ 888 m = m_get(pData); 889 ip = mtod(m, struct ip *); 890 ip->ip_src.s_addr = icr[i].Address; 891 ip->ip_p = IPPROTO_ICMP; 892 ip->ip_dst.s_addr = so->so_laddr.s_addr; /*XXX: still the hack*/ 893 ip->ip_hl = sizeof(struct ip) >> 2; /* requiered for icmp_reflect, no IP options */ 894 ip->ip_ttl = icr[i].Options.Ttl; 895 896 icp = (struct icmp *)&ip[1]; /* no options */ 897 icp->icmp_type = ICMP_ECHOREPLY; 898 icp->icmp_code = 0; 899 icp->icmp_id = so->so_icmp_id; 900 icp->icmp_seq = so->so_icmp_seq; 901 memcpy(icp->icmp_data, icr[i].Data, icr[i].DataSize); 902 903 ip->ip_len = sizeof(struct ip) + ICMP_MINLEN + icr[i].DataSize; 904 m->m_len = ip->ip_len; 905 906 icmp_reflect(pData, m); 907 case IP_TTL_EXPIRED_TRANSIT: /* TTL expired */ 908 909 ip_broken = icr[i].Data; 910 icm = icmp_find_original_mbuf(pData, ip_broken); 911 if (icm == NULL) { 912 LogRel(("ICMP: can't find original package (first double word %x)\n", *(uint32_t *)ip_broken)); 913 return; 914 } 915 m = icm->im_m; 916 ip = mtod(m, struct ip *); 917 ip->ip_ttl = icr[i].Options.Ttl; 918 src = ip->ip_src.s_addr; 919 ip->ip_dst.s_addr = src; 920 ip->ip_dst.s_addr = icr[i].Address; 921 icp = (struct icmp *)((char *)ip + (ip->ip_hl << 2)); 922 ip_broken->ip_src.s_addr = src; /*it packet sent from host not from guest*/ 923 memcpy(icp->icmp_data, ip_broken, (ip_broken->ip_hl << 2) + 64); 924 icmp_reflect(pData, m); 925 break; 926 default: 927 LogRel(("ICMP(default): message with Status: %x was received from %s\n", icr[i].Status, icr[i].Address)); 928 break; 859 929 } 860 LogRel(("IcmpParseReplies returns %ld\n", len)); 861 icr = (ICMP_ECHO_REPLY *)pData->pvIcmpBuffer; 862 for (i = 0; i < len; ++i) 863 { 864 switch(icr[i].Status) 865 { 866 case IP_DEST_HOST_UNREACHABLE: 867 code = (code != ~0 ? code :ICMP_UNREACH_HOST); 868 case IP_DEST_NET_UNREACHABLE: 869 code = (code != ~0 ? code : ICMP_UNREACH_NET); 870 case IP_DEST_PROT_UNREACHABLE: 871 code = (code != ~0 ? code : ICMP_UNREACH_PROTOCOL); 872 /* UNREACH error inject here */ 873 case IP_DEST_PORT_UNREACHABLE: 874 code = (code != ~0 ? code : ICMP_UNREACH_PORT); 875 icmp_error(pData, so->so_m, ICMP_UNREACH, code, 0, "Error occurred!!!"); 876 break; 877 case IP_SUCCESS: /* echo replied */ 878 m = m_get(pData); 879 ip = mtod(m, struct ip *); 880 ip->ip_src.s_addr = icr[i].Address; 881 ip->ip_p = IPPROTO_ICMP; 882 ip->ip_dst.s_addr = so->so_laddr.s_addr; /*XXX: still the hack*/ 883 ip->ip_hl = sizeof(struct ip) >> 2; /* requiered for icmp_reflect, no IP options */ 884 ip->ip_ttl = icr[i].Options.Ttl; 885 886 icp = (struct icmp *)&ip[1]; /* no options */ 887 icp->icmp_type = ICMP_ECHOREPLY; 888 icp->icmp_code = 0; 889 icp->icmp_id = so->so_icmp_id; 890 icp->icmp_seq = so->so_icmp_seq; 891 memcpy(icp->icmp_data, icr[i].Data, icr[i].DataSize); 892 893 ip->ip_len = sizeof(struct ip) + ICMP_MINLEN + icr[i].DataSize; 894 m->m_len = ip->ip_len; 895 896 icmp_reflect(pData, m); 897 case IP_TTL_EXPIRED_TRANSIT: /* TTL expired */ 898 899 ip_broken = icr[i].Data; 900 icm = icmp_find_original_mbuf(pData, ip_broken); 901 if (icm == NULL) { 902 LogRel(("ICMP: can't find original package (first double word %x)\n", *(uint32_t *)ip_broken)); 903 return; 904 } 905 m = icm->im_m; 906 ip = mtod(m, struct ip *); 907 ip->ip_ttl = icr[i].Options.Ttl; 908 src = ip->ip_src.s_addr; 909 ip->ip_dst.s_addr = src; 910 ip->ip_dst.s_addr = icr[i].Address; 911 icp = (struct icmp *)((char *)ip + (ip->ip_hl << 2)); 912 ip_broken->ip_src.s_addr = src; /*it packet sent from host not from guest*/ 913 memcpy(icp->icmp_data, ip_broken, (ip_broken->ip_hl << 2) + 64); 914 icmp_reflect(pData, m); 915 break; 916 default: 917 LogRel(("ICMP(default): message with Status: %x was received from %s\n", icr[i].Status, icr[i].Address)); 918 break; 919 } 920 } 930 } 921 931 } 922 932 # endif /* RT_OS_WINDOWS */ … … 933 943 /* XXX Check if reply is "correct"? */ 934 944 935 if (len == -1 || len == 0)945 if (len == -1 || len == 0) 936 946 { 937 947 u_char code = ICMP_UNREACH_PORT; … … 941 951 else if(errno == ENETUNREACH) 942 952 code=ICMP_UNREACH_NET; 943 944 953 945 954 DEBUG_MISC((dfd," udp icmp rx errno = %d-%s\n",
Note:
See TracChangeset
for help on using the changeset viewer.