Summary:
Step 1 of moving TAsyncSocket and friends to folly.
folly::IPAddress changes (can split these off if requested):
* isLoopback looks for a single address, as opposed to subnet
* For V6, isPrivate & isLoopback don't seem to check mapped addresses
TSocketAddress changes:
* Make union use folly::IPAddress instead of sockaddr struct. external_ bool to tell if using AF_UNIX instead.
* manage the port and scope/zone info ourselves
@override-unit-failures
Overriding failures, can't get contbuild to finish all builds after several tries. None of the failures look related
Test Plan:
fbconfig -r thrift
fbmake runtests
fbconfig folly/test:network_address_test
fbmake runtests
Reviewed By: simpkins@fb.com
Subscribers: snaptu-diffs@, trunkagent, hphp-diffs@, njormrod, fbcode-common-diffs@, doug, ruibalp, ps, alandau, bmatheny
FB internal diff:
D1479365
Tasks:
3658665
namespace folly {
+static IPAddressV4 loopback_addr("127.0.0.0");
+
// free functions
size_t hash_value(const IPAddressV4& addr) {
return addr.hash();
return (mask == subMask);
}
+bool IPAddressV4::isLoopback() const {
+ return inSubnetWithMask(loopback_addr, fetchMask(8));
+}
+
// public
bool IPAddressV4::isNonroutable() const {
auto ip = toLongHBO();
bool inSubnetWithMask(const IPAddressV4& subnet, const ByteArray4 mask) const;
// @see IPAddress#isLoopback
- bool isLoopback() const {
- return (INADDR_LOOPBACK == toLongHBO());
- }
+ bool isLoopback() const;
// @see IPAddress#isNonroutable
bool isNonroutable() const;
// public
bool IPAddressV6::isLoopback() const {
- const unsigned char* by = bytes();
- for (int i = 0; i < 15; i++) {
- if (by[i] != 0x00) {
- return false;
- }
+ // Check if v4 mapped is loopback
+ if (isIPv4Mapped() && createIPv4().isLoopback()) {
+ return true;
}
- return (by[15] == 0x01);
+ auto socka = toSockAddr();
+ return IN6_IS_ADDR_LOOPBACK(&socka.sin6_addr);
}
bool IPAddressV6::isRoutable() const {
// public
bool IPAddressV6::isPrivate() const {
+ // Check if mapped is private
+ if (isIPv4Mapped() && createIPv4().isPrivate()) {
+ return true;
+ }
return isLoopback() || inBinarySubnet({{0xfc, 0x00}}, 7);
}
detail/FunctionalExcept.h \
detail/Futex.h \
detail/GroupVarintDetail.h \
+ detail/IPAddress.h \
detail/Malloc.h \
detail/MemoryIdler.h \
detail/MPMCPipelineDetail.h \
AddressFlags("10.0.0.0", 4, IS_PVT_NONROUTE),
AddressFlags("10.11.12.13", 4, IS_PVT_NONROUTE),
AddressFlags("10.255.255.255", 4, IS_PVT_NONROUTE),
- AddressFlags("127.128.129.200", 4, IS_PVT_NONROUTE),
- AddressFlags("127.255.255.255", 4, IS_PVT_NONROUTE),
+ AddressFlags("127.128.129.200", 4, IS_LOCAL | IS_PVT_NONROUTE),
+ AddressFlags("127.255.255.255", 4, IS_LOCAL | IS_PVT_NONROUTE),
AddressFlags("169.254.0.0", 4, IS_PVT_NONROUTE),
AddressFlags("192.168.0.0", 4, IS_PVT_NONROUTE),
AddressFlags("192.168.200.255", 4, IS_PVT_NONROUTE),