Changeset 87791 in vbox for trunk/src/VBox/NetworkServices
- Timestamp:
- Feb 18, 2021 6:00:02 PM (4 years ago)
- svn:sync-xref-src-repo-rev:
- 142851
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/NetworkServices/NAT/VBoxNetLwipNAT.cpp
r87790 r87791 622 622 623 623 /** 624 * Create raw IPv4 socket for sending and snooping ICMP. 625 */ 626 void VBoxNetLwipNAT::initIPv4RawSock() 627 { 628 SOCKET icmpsock4 = INVALID_SOCKET; 629 630 #ifndef RT_OS_DARWIN 631 const int icmpstype = SOCK_RAW; 632 #else 633 /* on OS X it's not privileged */ 634 const int icmpstype = SOCK_DGRAM; 635 #endif 636 637 icmpsock4 = socket(AF_INET, icmpstype, IPPROTO_ICMP); 638 if (icmpsock4 == INVALID_SOCKET) 639 { 640 perror("IPPROTO_ICMP"); 641 #ifdef VBOX_RAWSOCK_DEBUG_HELPER 642 icmpsock4 = getrawsock(AF_INET); 643 #endif 644 } 645 646 if (icmpsock4 != INVALID_SOCKET) 647 { 648 #ifdef ICMP_FILTER // Linux specific 649 struct icmp_filter flt = { 650 ~(uint32_t)( 651 (1U << ICMP_ECHOREPLY) 652 | (1U << ICMP_DEST_UNREACH) 653 | (1U << ICMP_TIME_EXCEEDED) 654 ) 655 }; 656 657 int status = setsockopt(icmpsock4, SOL_RAW, ICMP_FILTER, 658 &flt, sizeof(flt)); 659 if (status < 0) 660 { 661 perror("ICMP_FILTER"); 662 } 663 #endif 664 } 665 666 m_ProxyOptions.icmpsock4 = icmpsock4; 667 } 668 669 670 /** 624 671 * Init mapping from the natnet's IPv4 addresses to host's IPv4 625 672 * loopbacks. Plural "loopbacks" because it's now quite common to run … … 862 909 863 910 return VINF_SUCCESS; 911 } 912 913 914 /** 915 * Create raw IPv6 socket for sending and snooping ICMP6. 916 */ 917 void VBoxNetLwipNAT::initIPv6RawSock() 918 { 919 SOCKET icmpsock6 = INVALID_SOCKET; 920 921 #ifndef RT_OS_DARWIN 922 const int icmpstype = SOCK_RAW; 923 #else 924 /* on OS X it's not privileged */ 925 const int icmpstype = SOCK_DGRAM; 926 #endif 927 928 icmpsock6 = socket(AF_INET6, icmpstype, IPPROTO_ICMPV6); 929 if (icmpsock6 == INVALID_SOCKET) 930 { 931 perror("IPPROTO_ICMPV6"); 932 #ifdef VBOX_RAWSOCK_DEBUG_HELPER 933 icmpsock6 = getrawsock(AF_INET6); 934 #endif 935 } 936 937 if (icmpsock6 != INVALID_SOCKET) 938 { 939 #ifdef ICMP6_FILTER // Windows doesn't support RFC 3542 API 940 /* 941 * XXX: We do this here for now, not in pxping.c, to avoid 942 * name clashes between lwIP and system headers. 943 */ 944 struct icmp6_filter flt; 945 ICMP6_FILTER_SETBLOCKALL(&flt); 946 947 ICMP6_FILTER_SETPASS(ICMP6_ECHO_REPLY, &flt); 948 949 ICMP6_FILTER_SETPASS(ICMP6_DST_UNREACH, &flt); 950 ICMP6_FILTER_SETPASS(ICMP6_PACKET_TOO_BIG, &flt); 951 ICMP6_FILTER_SETPASS(ICMP6_TIME_EXCEEDED, &flt); 952 ICMP6_FILTER_SETPASS(ICMP6_PARAM_PROB, &flt); 953 954 int status = setsockopt(icmpsock6, IPPROTO_ICMPV6, ICMP6_FILTER, 955 &flt, sizeof(flt)); 956 if (status < 0) 957 { 958 perror("ICMP6_FILTER"); 959 } 960 #endif 961 } 962 963 m_ProxyOptions.icmpsock6 = icmpsock6; 864 964 } 865 965 … … 1038 1138 1039 1139 return VINF_SUCCESS; 1040 }1041 1042 1043 /**1044 * Create raw IPv4 socket for sending and snooping ICMP.1045 */1046 void VBoxNetLwipNAT::initIPv4RawSock()1047 {1048 SOCKET icmpsock4 = INVALID_SOCKET;1049 1050 #ifndef RT_OS_DARWIN1051 const int icmpstype = SOCK_RAW;1052 #else1053 /* on OS X it's not privileged */1054 const int icmpstype = SOCK_DGRAM;1055 #endif1056 1057 icmpsock4 = socket(AF_INET, icmpstype, IPPROTO_ICMP);1058 if (icmpsock4 == INVALID_SOCKET)1059 {1060 perror("IPPROTO_ICMP");1061 #ifdef VBOX_RAWSOCK_DEBUG_HELPER1062 icmpsock4 = getrawsock(AF_INET);1063 #endif1064 }1065 1066 if (icmpsock4 != INVALID_SOCKET)1067 {1068 #ifdef ICMP_FILTER // Linux specific1069 struct icmp_filter flt = {1070 ~(uint32_t)(1071 (1U << ICMP_ECHOREPLY)1072 | (1U << ICMP_DEST_UNREACH)1073 | (1U << ICMP_TIME_EXCEEDED)1074 )1075 };1076 1077 int status = setsockopt(icmpsock4, SOL_RAW, ICMP_FILTER,1078 &flt, sizeof(flt));1079 if (status < 0)1080 {1081 perror("ICMP_FILTER");1082 }1083 #endif1084 }1085 1086 m_ProxyOptions.icmpsock4 = icmpsock4;1087 }1088 1089 1090 /**1091 * Create raw IPv6 socket for sending and snooping ICMP6.1092 */1093 void VBoxNetLwipNAT::initIPv6RawSock()1094 {1095 SOCKET icmpsock6 = INVALID_SOCKET;1096 1097 #ifndef RT_OS_DARWIN1098 const int icmpstype = SOCK_RAW;1099 #else1100 /* on OS X it's not privileged */1101 const int icmpstype = SOCK_DGRAM;1102 #endif1103 1104 icmpsock6 = socket(AF_INET6, icmpstype, IPPROTO_ICMPV6);1105 if (icmpsock6 == INVALID_SOCKET)1106 {1107 perror("IPPROTO_ICMPV6");1108 #ifdef VBOX_RAWSOCK_DEBUG_HELPER1109 icmpsock6 = getrawsock(AF_INET6);1110 #endif1111 }1112 1113 if (icmpsock6 != INVALID_SOCKET)1114 {1115 #ifdef ICMP6_FILTER // Windows doesn't support RFC 3542 API1116 /*1117 * XXX: We do this here for now, not in pxping.c, to avoid1118 * name clashes between lwIP and system headers.1119 */1120 struct icmp6_filter flt;1121 ICMP6_FILTER_SETBLOCKALL(&flt);1122 1123 ICMP6_FILTER_SETPASS(ICMP6_ECHO_REPLY, &flt);1124 1125 ICMP6_FILTER_SETPASS(ICMP6_DST_UNREACH, &flt);1126 ICMP6_FILTER_SETPASS(ICMP6_PACKET_TOO_BIG, &flt);1127 ICMP6_FILTER_SETPASS(ICMP6_TIME_EXCEEDED, &flt);1128 ICMP6_FILTER_SETPASS(ICMP6_PARAM_PROB, &flt);1129 1130 int status = setsockopt(icmpsock6, IPPROTO_ICMPV6, ICMP6_FILTER,1131 &flt, sizeof(flt));1132 if (status < 0)1133 {1134 perror("ICMP6_FILTER");1135 }1136 #endif1137 }1138 1139 m_ProxyOptions.icmpsock6 = icmpsock6;1140 1140 } 1141 1141
Note:
See TracChangeset
for help on using the changeset viewer.