nfs4: Let GenerateClientID take advantage of PeerAddress methods
This commit is contained in:
@@ -28,22 +28,22 @@
|
||||
|
||||
|
||||
bool
|
||||
ServerAddress::operator==(const ServerAddress& address)
|
||||
PeerAddress::operator==(const PeerAddress& address)
|
||||
{
|
||||
return memcmp(&fAddress, &address.fAddress, sizeof(fAddress)) == 0
|
||||
&& fProtocol == address.fProtocol;
|
||||
}
|
||||
|
||||
bool
|
||||
ServerAddress::operator<(const ServerAddress& address)
|
||||
PeerAddress::operator<(const PeerAddress& address)
|
||||
{
|
||||
int compare = memcmp(&fAddress, &address.fAddress, sizeof(fAddress));
|
||||
return compare < 0 || (compare == 0 && fProtocol < address.fProtocol);
|
||||
}
|
||||
|
||||
|
||||
ServerAddress&
|
||||
ServerAddress::operator=(const ServerAddress& address)
|
||||
PeerAddress&
|
||||
PeerAddress::operator=(const PeerAddress& address)
|
||||
{
|
||||
fAddress = address.fAddress;
|
||||
fProtocol = address.fProtocol;
|
||||
@@ -51,7 +51,7 @@ ServerAddress::operator=(const ServerAddress& address)
|
||||
}
|
||||
|
||||
|
||||
ServerAddress::ServerAddress()
|
||||
PeerAddress::PeerAddress()
|
||||
:
|
||||
fProtocol(0)
|
||||
{
|
||||
@@ -60,7 +60,7 @@ ServerAddress::ServerAddress()
|
||||
|
||||
|
||||
const char*
|
||||
ServerAddress::ProtocolString() const
|
||||
PeerAddress::ProtocolString() const
|
||||
{
|
||||
static const char* tcpName = "tcp";
|
||||
static const char* udpName = "udp";
|
||||
@@ -78,7 +78,7 @@ ServerAddress::ProtocolString() const
|
||||
|
||||
|
||||
char*
|
||||
ServerAddress::UniversalAddress() const
|
||||
PeerAddress::UniversalAddress() const
|
||||
{
|
||||
const sockaddr* address = reinterpret_cast<const sockaddr*>(&fAddress);
|
||||
|
||||
@@ -98,7 +98,7 @@ ServerAddress::UniversalAddress() const
|
||||
|
||||
|
||||
socklen_t
|
||||
ServerAddress::AddressSize() const
|
||||
PeerAddress::AddressSize() const
|
||||
{
|
||||
switch (reinterpret_cast<const sockaddr*>(&fAddress)->sa_family) {
|
||||
case AF_INET:
|
||||
@@ -112,7 +112,7 @@ ServerAddress::AddressSize() const
|
||||
|
||||
|
||||
uint16
|
||||
ServerAddress::Port() const
|
||||
PeerAddress::Port() const
|
||||
{
|
||||
uint16 port;
|
||||
|
||||
@@ -132,7 +132,7 @@ ServerAddress::Port() const
|
||||
|
||||
|
||||
void
|
||||
ServerAddress::SetPort(uint16 port)
|
||||
PeerAddress::SetPort(uint16 port)
|
||||
{
|
||||
port = htons(port);
|
||||
|
||||
@@ -148,7 +148,7 @@ ServerAddress::SetPort(uint16 port)
|
||||
|
||||
|
||||
const void*
|
||||
ServerAddress::InAddr() const
|
||||
PeerAddress::InAddr() const
|
||||
{
|
||||
switch (reinterpret_cast<const sockaddr*>(&fAddress)->sa_family) {
|
||||
case AF_INET:
|
||||
@@ -161,9 +161,22 @@ ServerAddress::InAddr() const
|
||||
}
|
||||
|
||||
|
||||
size_t
|
||||
PeerAddress::InAddrSize() const
|
||||
{
|
||||
switch (reinterpret_cast<const sockaddr*>(&fAddress)->sa_family) {
|
||||
case AF_INET:
|
||||
return sizeof(in_addr);
|
||||
case AF_INET6:
|
||||
return sizeof(in6_addr);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
ServerAddress::ResolveName(const char* name, ServerAddress* address)
|
||||
PeerAddress::ResolveName(const char* name, PeerAddress* address)
|
||||
{
|
||||
address->fProtocol = IPPROTO_TCP;
|
||||
|
||||
@@ -210,39 +223,39 @@ ServerAddress::ResolveName(const char* name, ServerAddress* address)
|
||||
}
|
||||
|
||||
|
||||
Connection::Connection(const ServerAddress& address)
|
||||
Connection::Connection(const PeerAddress& address)
|
||||
:
|
||||
ConnectionBase(address)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ConnectionListener::ConnectionListener(const ServerAddress& address)
|
||||
ConnectionListener::ConnectionListener(const PeerAddress& address)
|
||||
:
|
||||
ConnectionBase(address)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ConnectionBase::ConnectionBase(const ServerAddress& address)
|
||||
ConnectionBase::ConnectionBase(const PeerAddress& address)
|
||||
:
|
||||
fWaitCancel(create_sem(0, NULL)),
|
||||
fSocket(-1),
|
||||
fServerAddress(address)
|
||||
fPeerAddress(address)
|
||||
{
|
||||
mutex_init(&fSocketLock, NULL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
ConnectionStream::ConnectionStream(const ServerAddress& address)
|
||||
ConnectionStream::ConnectionStream(const PeerAddress& address)
|
||||
:
|
||||
Connection(address)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ConnectionPacket::ConnectionPacket(const ServerAddress& address)
|
||||
ConnectionPacket::ConnectionPacket(const PeerAddress& address)
|
||||
:
|
||||
Connection(address)
|
||||
{
|
||||
@@ -259,9 +272,9 @@ ConnectionBase::~ConnectionBase()
|
||||
|
||||
|
||||
status_t
|
||||
ConnectionBase::GetLocalAddress(ServerAddress* address)
|
||||
ConnectionBase::GetLocalAddress(PeerAddress* address)
|
||||
{
|
||||
address->fProtocol = fServerAddress.fProtocol;
|
||||
address->fProtocol = fPeerAddress.fProtocol;
|
||||
|
||||
socklen_t addressSize = sizeof(address->fAddress);
|
||||
return getsockname(fSocket, (struct sockaddr*)&address->fAddress,
|
||||
@@ -443,7 +456,7 @@ ConnectionPacket::Receive(void** _buffer, uint32* _size)
|
||||
|
||||
|
||||
Connection*
|
||||
Connection::CreateObject(const ServerAddress& address)
|
||||
Connection::CreateObject(const PeerAddress& address)
|
||||
{
|
||||
switch (address.fProtocol) {
|
||||
case IPPROTO_TCP:
|
||||
@@ -457,7 +470,7 @@ Connection::CreateObject(const ServerAddress& address)
|
||||
|
||||
|
||||
status_t
|
||||
Connection::Connect(Connection **_connection, const ServerAddress& address)
|
||||
Connection::Connect(Connection **_connection, const PeerAddress& address)
|
||||
{
|
||||
Connection* conn = CreateObject(address);
|
||||
if (conn == NULL)
|
||||
@@ -477,7 +490,7 @@ Connection::Connect(Connection **_connection, const ServerAddress& address)
|
||||
|
||||
status_t
|
||||
Connection::SetTo(Connection **_connection, int socket,
|
||||
const ServerAddress& address)
|
||||
const PeerAddress& address)
|
||||
{
|
||||
Connection* conn = CreateObject(address);
|
||||
if (conn == NULL)
|
||||
@@ -494,9 +507,9 @@ status_t
|
||||
Connection::Connect()
|
||||
{
|
||||
const sockaddr& address =
|
||||
*reinterpret_cast<const sockaddr*>(&fServerAddress);
|
||||
*reinterpret_cast<const sockaddr*>(&fPeerAddress);
|
||||
|
||||
switch (fServerAddress.fProtocol) {
|
||||
switch (fPeerAddress.fProtocol) {
|
||||
case IPPROTO_TCP:
|
||||
fSocket = socket(address.sa_family, SOCK_STREAM, IPPROTO_TCP);
|
||||
break;
|
||||
@@ -619,7 +632,7 @@ ConnectionListener::Listen(ConnectionListener** listener, uint16 port)
|
||||
return errno;
|
||||
}
|
||||
|
||||
ServerAddress address;
|
||||
PeerAddress address;
|
||||
address.fProtocol = IPPROTO_TCP;
|
||||
memset(&address.fAddress, 0, sizeof(address.fAddress));
|
||||
|
||||
@@ -663,7 +676,7 @@ ConnectionListener::AcceptConnection(Connection** connection)
|
||||
if (sock < 0)
|
||||
return errno;
|
||||
|
||||
ServerAddress address;
|
||||
PeerAddress address;
|
||||
address.fProtocol = IPPROTO_TCP;
|
||||
address.fAddress = addr;
|
||||
|
||||
|
||||
@@ -15,16 +15,16 @@
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
struct ServerAddress {
|
||||
struct PeerAddress {
|
||||
sockaddr_storage fAddress;
|
||||
int fProtocol;
|
||||
|
||||
bool operator==(const ServerAddress& address);
|
||||
bool operator<(const ServerAddress& address);
|
||||
bool operator==(const PeerAddress& address);
|
||||
bool operator<(const PeerAddress& address);
|
||||
|
||||
ServerAddress& operator=(const ServerAddress& address);
|
||||
PeerAddress& operator=(const PeerAddress& address);
|
||||
|
||||
ServerAddress();
|
||||
PeerAddress();
|
||||
|
||||
const char* ProtocolString() const;
|
||||
char* UniversalAddress() const;
|
||||
@@ -35,17 +35,18 @@ struct ServerAddress {
|
||||
uint16 Port() const;
|
||||
|
||||
const void* InAddr() const;
|
||||
size_t InAddrSize() const;
|
||||
|
||||
static status_t ResolveName(const char* name,
|
||||
ServerAddress* address);
|
||||
PeerAddress* address);
|
||||
};
|
||||
|
||||
class ConnectionBase {
|
||||
public:
|
||||
ConnectionBase(const ServerAddress& address);
|
||||
ConnectionBase(const PeerAddress& address);
|
||||
virtual ~ConnectionBase();
|
||||
|
||||
status_t GetLocalAddress(ServerAddress* address);
|
||||
status_t GetLocalAddress(PeerAddress* address);
|
||||
|
||||
void Disconnect();
|
||||
|
||||
@@ -54,15 +55,15 @@ protected:
|
||||
int fSocket;
|
||||
mutex fSocketLock;
|
||||
|
||||
const ServerAddress fServerAddress;
|
||||
const PeerAddress fPeerAddress;
|
||||
};
|
||||
|
||||
class Connection : public ConnectionBase {
|
||||
public:
|
||||
static status_t Connect(Connection **connection,
|
||||
const ServerAddress& address);
|
||||
const PeerAddress& address);
|
||||
static status_t SetTo(Connection **connection, int socket,
|
||||
const ServerAddress& address);
|
||||
const PeerAddress& address);
|
||||
|
||||
virtual status_t Send(const void* buffer, uint32 size) = 0;
|
||||
virtual status_t Receive(void** buffer, uint32* size) = 0;
|
||||
@@ -70,16 +71,16 @@ public:
|
||||
status_t Reconnect();
|
||||
|
||||
protected:
|
||||
static Connection* CreateObject(const ServerAddress& address);
|
||||
static Connection* CreateObject(const PeerAddress& address);
|
||||
|
||||
Connection(const ServerAddress& address);
|
||||
Connection(const PeerAddress& address);
|
||||
status_t Connect();
|
||||
|
||||
};
|
||||
|
||||
class ConnectionStream : public Connection {
|
||||
public:
|
||||
ConnectionStream(const ServerAddress& address);
|
||||
ConnectionStream(const PeerAddress& address);
|
||||
|
||||
virtual status_t Send(const void* buffer, uint32 size);
|
||||
virtual status_t Receive(void** buffer, uint32* size);
|
||||
@@ -87,7 +88,7 @@ public:
|
||||
|
||||
class ConnectionPacket : public Connection {
|
||||
public:
|
||||
ConnectionPacket(const ServerAddress& address);
|
||||
ConnectionPacket(const PeerAddress& address);
|
||||
|
||||
virtual status_t Send(const void* buffer, uint32 size);
|
||||
virtual status_t Receive(void** buffer, uint32* size);
|
||||
@@ -100,7 +101,7 @@ public:
|
||||
status_t AcceptConnection(Connection** connection);
|
||||
|
||||
protected:
|
||||
ConnectionListener(const ServerAddress& address);
|
||||
ConnectionListener(const PeerAddress& address);
|
||||
};
|
||||
|
||||
#endif // CONNECTION_H
|
||||
|
||||
@@ -224,10 +224,10 @@ FileSystem::Migrate(const RPC::Server* serv)
|
||||
reinterpret_cast<FSLocations*>(values[0].fData.fLocations);
|
||||
|
||||
RPC::Server* server = fServer;
|
||||
ServerAddress addr = fServer->ID();
|
||||
PeerAddress addr = fServer->ID();
|
||||
for (uint32 i = 0; i < locs->fCount; i++) {
|
||||
for (uint32 j = 0; j < locs->fLocations[i].fCount; j++) {
|
||||
if (ServerAddress::ResolveName(locs->fLocations[i].fLocations[j],
|
||||
if (PeerAddress::ResolveName(locs->fLocations[i].fLocations[j],
|
||||
&addr) != B_OK)
|
||||
continue;
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
status_t RegisterCallback(Callback* callback);
|
||||
status_t UnregisterCallback(Callback* callback);
|
||||
|
||||
inline ServerAddress LocalID();
|
||||
inline PeerAddress LocalID();
|
||||
|
||||
protected:
|
||||
status_t StartServer();
|
||||
@@ -72,10 +72,10 @@ private:
|
||||
};
|
||||
|
||||
|
||||
inline ServerAddress
|
||||
inline PeerAddress
|
||||
CallbackServer::LocalID()
|
||||
{
|
||||
ServerAddress address;
|
||||
PeerAddress address;
|
||||
fListener->GetLocalAddress(&address);
|
||||
return address;
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ RequestManager::FindRequest(uint32 xid)
|
||||
}
|
||||
|
||||
|
||||
Server::Server(Connection* connection, ServerAddress* address)
|
||||
Server::Server(Connection* connection, PeerAddress* address)
|
||||
:
|
||||
fConnection(connection),
|
||||
fAddress(address),
|
||||
@@ -301,7 +301,7 @@ ServerManager::~ServerManager()
|
||||
|
||||
|
||||
status_t
|
||||
ServerManager::Acquire(Server** _server, const ServerAddress& address,
|
||||
ServerManager::Acquire(Server** _server, const PeerAddress& address,
|
||||
ProgramData* (*createPrivateData)(Server*))
|
||||
{
|
||||
status_t result;
|
||||
@@ -372,7 +372,7 @@ ServerManager::Release(Server* server)
|
||||
|
||||
|
||||
ServerNode*
|
||||
ServerManager::_Find(const ServerAddress& address)
|
||||
ServerManager::_Find(const PeerAddress& address)
|
||||
{
|
||||
ServerNode* node = fRoot;
|
||||
while (node != NULL) {
|
||||
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
class Server {
|
||||
public:
|
||||
Server(Connection* connection,
|
||||
ServerAddress* address);
|
||||
PeerAddress* address);
|
||||
virtual ~Server();
|
||||
|
||||
status_t SendCall(Call* call, Reply** reply);
|
||||
@@ -74,8 +74,8 @@ public:
|
||||
|
||||
status_t Repair();
|
||||
|
||||
inline const ServerAddress& ID() const;
|
||||
inline ServerAddress LocalID() const;
|
||||
inline const PeerAddress& ID() const;
|
||||
inline PeerAddress LocalID() const;
|
||||
|
||||
inline ProgramData* PrivateData();
|
||||
inline void SetPrivateData(ProgramData* privateData);
|
||||
@@ -96,7 +96,7 @@ private:
|
||||
|
||||
RequestManager fRequests;
|
||||
Connection* fConnection;
|
||||
const ServerAddress* fAddress;
|
||||
const PeerAddress* fAddress;
|
||||
|
||||
ProgramData* fPrivateData;
|
||||
|
||||
@@ -125,17 +125,17 @@ Server::CancelCall(Request* request)
|
||||
}
|
||||
|
||||
|
||||
inline const ServerAddress&
|
||||
inline const PeerAddress&
|
||||
Server::ID() const
|
||||
{
|
||||
return *fAddress;
|
||||
}
|
||||
|
||||
|
||||
inline ServerAddress
|
||||
inline PeerAddress
|
||||
Server::LocalID() const
|
||||
{
|
||||
ServerAddress addr;
|
||||
PeerAddress addr;
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
fConnection->GetLocalAddress(&addr);
|
||||
return addr;
|
||||
@@ -158,7 +158,7 @@ Server::SetPrivateData(ProgramData* privateData)
|
||||
|
||||
|
||||
struct ServerNode {
|
||||
ServerAddress fID;
|
||||
PeerAddress fID;
|
||||
Server* fServer;
|
||||
int fRefCount;
|
||||
|
||||
@@ -171,13 +171,13 @@ public:
|
||||
ServerManager();
|
||||
~ServerManager();
|
||||
|
||||
status_t Acquire(Server** _server, const ServerAddress& address,
|
||||
status_t Acquire(Server** _server, const PeerAddress& address,
|
||||
ProgramData* (*createPrivateData)(Server*));
|
||||
void Release(Server* server);
|
||||
|
||||
private:
|
||||
|
||||
ServerNode* _Find(const ServerAddress& address);
|
||||
ServerNode* _Find(const PeerAddress& address);
|
||||
void _Delete(ServerNode* node);
|
||||
ServerNode* _Insert(ServerNode* node);
|
||||
|
||||
|
||||
@@ -673,8 +673,8 @@ RequestBuilder::SetClientID(RPC::Server* server)
|
||||
|
||||
uint32 id = server->GetCallback()->ID();
|
||||
|
||||
ServerAddress local = gRPCCallbackServer->LocalID();
|
||||
ServerAddress servAddr = server->LocalID();
|
||||
PeerAddress local = gRPCCallbackServer->LocalID();
|
||||
PeerAddress servAddr = server->LocalID();
|
||||
servAddr.SetPort(local.Port());
|
||||
|
||||
fRequest->Stream().AddString(local.ProtocolString());
|
||||
@@ -700,46 +700,15 @@ RequestBuilder::_GenerateClientId(XDR::WriteStream& stream,
|
||||
char id[512] = "HAIKU:kernel:";
|
||||
int pos = strlen(id);
|
||||
|
||||
const sockaddr* remoteAddress =
|
||||
reinterpret_cast<const sockaddr*>(&server->ID().fAddress);
|
||||
PeerAddress local = server->LocalID();
|
||||
|
||||
ServerAddress local = server->LocalID();
|
||||
const sockaddr* localAddress = reinterpret_cast<sockaddr*>(&local.fAddress);
|
||||
|
||||
const sockaddr_in* address4;
|
||||
const sockaddr_in6* address6;
|
||||
switch (remoteAddress->sa_family) {
|
||||
case AF_INET:
|
||||
address4 = reinterpret_cast<const sockaddr_in*>(remoteAddress);
|
||||
memcpy(id + pos, server->ID().InAddr(), server->ID().InAddrSize());
|
||||
pos += sizeof(server->ID().InAddrSize());
|
||||
|
||||
memcpy(id + pos, &address4->sin_addr, sizeof(address4->sin_addr));
|
||||
pos += sizeof(address4->sin_addr);
|
||||
memcpy(id + pos, local.InAddr(), local.InAddrSize());
|
||||
pos += sizeof(local.InAddrSize());
|
||||
|
||||
memcpy(id + pos,
|
||||
&reinterpret_cast<const sockaddr_in*>(localAddress)->sin_addr,
|
||||
sizeof(address4->sin_addr));
|
||||
pos += sizeof(address4->sin_addr);
|
||||
|
||||
*(uint16*)(id + pos) = address4->sin_port;
|
||||
break;
|
||||
|
||||
case AF_INET6:
|
||||
address6 = reinterpret_cast<const sockaddr_in6*>(remoteAddress);
|
||||
|
||||
memcpy(id + pos, &address6->sin6_addr, sizeof(address6->sin6_addr));
|
||||
pos += sizeof(address6->sin6_addr);
|
||||
|
||||
memcpy(id + pos,
|
||||
&reinterpret_cast<const sockaddr_in6*>(localAddress)->sin6_addr,
|
||||
sizeof(address6->sin6_addr));
|
||||
pos += sizeof(address6->sin6_addr);
|
||||
|
||||
*(uint16*)(id + pos) = address6->sin6_port;
|
||||
break;
|
||||
|
||||
default:
|
||||
return B_BAD_VALUE;
|
||||
}
|
||||
*(uint16*)(id + pos) = server->ID().Port();
|
||||
pos += sizeof(uint16);
|
||||
|
||||
*(uint16*)(id + pos) = server->ID().fProtocol;
|
||||
|
||||
@@ -45,7 +45,7 @@ CreateNFS4Server(RPC::Server* serv)
|
||||
|
||||
// TODO: IPv6 address will cause problems
|
||||
static status_t
|
||||
ParseArguments(const char* _args, ServerAddress* address, char* _path)
|
||||
ParseArguments(const char* _args, PeerAddress* address, char* _path)
|
||||
{
|
||||
if (_args == NULL)
|
||||
return B_BAD_VALUE;
|
||||
@@ -58,7 +58,7 @@ ParseArguments(const char* _args, ServerAddress* address, char* _path)
|
||||
}
|
||||
*path++ = '\0';
|
||||
|
||||
status_t result = ServerAddress::ResolveName(args, address);
|
||||
status_t result = PeerAddress::ResolveName(args, address);
|
||||
if (result != B_OK)
|
||||
return result;
|
||||
|
||||
@@ -82,7 +82,7 @@ nfs4_mount(fs_volume* volume, const char* device, uint32 flags,
|
||||
return B_NO_MEMORY;
|
||||
locker.Unlock();
|
||||
|
||||
ServerAddress address;
|
||||
PeerAddress address;
|
||||
char path[256];
|
||||
result = ParseArguments(args, &address, path);
|
||||
if (result != B_OK)
|
||||
|
||||
Reference in New Issue
Block a user