XRootD
Loading...
Searching...
No Matches
XrdInet Class Reference

#include <XrdInet.hh>

+ Inheritance diagram for XrdInet:
+ Collaboration diagram for XrdInet:

Public Member Functions

 XrdInet (XrdSysError *erp, XrdNetSecurity *secp=0)
 
 ~XrdInet ()
 
XrdLinkAccept (int opts=0, int timeout=-1, XrdSysSemaphore *theSem=0)
 
int BindSD (int port, const char *contype="tcp")
 
XrdLinkConnect (const char *host, int port, int opts=0, int timeout=-1)
 
void Secure (XrdNetSecurity *secp)
 
- Public Member Functions inherited from XrdNet
 XrdNet (XrdSysError *erp, XrdNetSecurity *secp=0)
 
virtual ~XrdNet ()
 Destructor.
 
int Accept (XrdNetAddr &myAddr, int opts=0, int timeout=-1)
 
int Accept (XrdNetPeer &myPeer, int opts=0, int timeout=-1)
 
int Bind (char *path, const char *contype="stream")
 
int Bind (int port, const char *contype="tcp")
 
int Connect (XrdNetAddr &myAddr, const char *dest, int port=-1, int opts=0, int timeout=-1)
 
int Connect (XrdNetPeer &myPeer, const char *dest, int port=-1, int opts=0, int timeout=-1)
 
int Port ()
 
int Relay (const char *dest)
 
int Relay (XrdNetPeer &Peer, const char *dest, int opts=0)
 
virtual void Secure (XrdNetSecurity *secp)
 
void setDefaults (int options, int buffsz=0)
 
void setDomain (const char *dname)
 
void Trim (char *hname)
 
void unBind ()
 Unbind the network from any bound resouces.
 
int WSize ()
 

Static Public Member Functions

static bool GetAssumeV4 ()
 
static void SetAssumeV4 (bool newVal)
 

Static Public Attributes

static XrdNetIF netIF
 

Additional Inherited Members

- Protected Attributes inherited from XrdNet
XrdNetBufferQBuffQ
 
int BuffSize
 
char * Domain
 
int Domlen
 
XrdSysErroreDest
 
int iofd
 
int netOpts
 
XrdNetSecurityPolice
 
int Portnum
 
int PortType
 
int Windowsz
 

Detailed Description

Definition at line 47 of file XrdInet.hh.

Constructor & Destructor Documentation

◆ XrdInet()

XrdInet::XrdInet ( XrdSysError erp,
XrdNetSecurity secp = 0 
)
inline

Definition at line 59 of file XrdInet.hh.

60 : XrdNet(erp,0), Patrol(secp) {}

◆ ~XrdInet()

XrdInet::~XrdInet ( )
inline

Definition at line 61 of file XrdInet.hh.

61{}

Member Function Documentation

◆ Accept()

XrdLink * XrdInet::Accept ( int  opts = 0,
int  timeout = -1,
XrdSysSemaphore theSem = 0 
)

Definition at line 72 of file XrdInet.cc.

73{
74 static const char *unk = "unkown.endpoint";
75 XrdNetAddr myAddr;
76 XrdLink *lp;
77 int anum=0, lnkopts = (opts & XRDNET_MULTREAD ? XRDLINK_RDLOCK : 0);
78
79// Perform regular accept. This will be a unique TCP socket. We loop here
80// until the accept succeeds as it should never fail at this stage.
81//
82 while(!XrdNet::Accept(myAddr, opts | XRDNET_NORLKUP, timeout))
83 {if (timeout >= 0)
84 {if (theSem) theSem->Post();
85 return (XrdLink *)0;
86 }
87 sleep(1); anum++;
88 if (!(anum%60)) eDest->Emsg("Accept", "Unable to accept connections!");
89 }
90
91// If authorization was deferred, tell call we accepted the connection but
92// will be doing a background check on this connection.
93//
94 if (theSem) theSem->Post();
95 if (!(netOpts & XRDNET_NORLKUP)) myAddr.Name();
96
97// Authorize by ip address or full (slow) hostname format. We defer the check
98// so that the next accept can occur before we do any DNS resolution.
99//
100 if (Patrol)
101 {if (!Patrol->Authorize(myAddr))
102 {char ipbuff[512];
103 myAddr.Format(ipbuff, sizeof(ipbuff), XrdNetAddr::fmtAuto,
105 eDest->Emsg("Accept",EACCES,"accept TCP connection from",ipbuff);
106 close(myAddr.SockFD());
107 return (XrdLink *)0;
108 }
109 }
110
111// Allocate a new network object
112//
113 if (!(lp = XrdLinkCtl::Alloc(myAddr, lnkopts)))
114 {eDest->Emsg("Accept", ENOMEM, "allocate new link for", myAddr.Name(unk));
115 close(myAddr.SockFD());
116 } else {
117 TRACE(NET, "Accepted connection on port " <<Portnum <<" from "
118 <<myAddr.SockFD() <<'@' <<myAddr.Name(unk));
119 }
120
121// All done
122//
123 return lp;
124}
#define XRDLINK_RDLOCK
Definition XrdLinkCtl.hh:58
#define XRDNET_NORLKUP
Definition XrdNetOpts.hh:87
#define XRDNET_MULTREAD
Definition XrdNetOpts.hh:47
#define close(a)
Definition XrdPosix.hh:43
struct myOpts opts
#define TRACE(act, x)
Definition XrdTrace.hh:63
static XrdLink * Alloc(XrdNetAddr &peer, int opts=0)
static const int noPort
Do not add port number.
int Format(char *bAddr, int bLen, fmtUse fmtType=fmtAuto, int fmtOpts=0)
@ fmtAuto
Hostname if already resolved o/w use fmtAddr.
const char * Name(const char *eName=0, const char **eText=0)
bool Authorize(const char *hSpec)
XrdSysError * eDest
Definition XrdNet.hh:283
int netOpts
Definition XrdNet.hh:291
int Portnum
Definition XrdNet.hh:288
int Accept(XrdNetAddr &myAddr, int opts=0, int timeout=-1)
Definition XrdNet.cc:84
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)

References XrdNet::Accept(), XrdLinkCtl::Alloc(), XrdNetSecurity::Authorize(), close, XrdNet::eDest, XrdSysError::Emsg(), XrdNetAddrInfo::fmtAuto, XrdNetAddrInfo::Format(), XrdNetAddrInfo::Name(), XrdNet::netOpts, XrdNetAddrInfo::noPort, opts, XrdNet::Portnum, XrdSysSemaphore::Post(), XrdNetAddrInfo::SockFD(), TRACE, XRDLINK_RDLOCK, XRDNET_MULTREAD, and XRDNET_NORLKUP.

Referenced by XrdMain::DoIt(), mainAdmin(), and XrdCmsSupervisor::Start().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ BindSD()

int XrdInet::BindSD ( int  port,
const char *  contype = "tcp" 
)

Definition at line 130 of file XrdInet.cc.

131{
132#ifdef HAVE_SYSTEMD
133 int nSD, opts = XRDNET_SERVER | netOpts;
134
135// If an arbitrary port is wanted, then systemd can't supply such a socket.
136// Of course, do the same in the absencse of systemd sockets.
137//
138 if (port == 0 || (nSD = sd_listen_fds(0)) <= 0) return Bind(port, contype);
139
140// Do some presets here
141//
142 int v4Sock = AF_INET;
143 int v6Sock = (XrdNetAddr::IPV4Set() ? AF_INET : AF_INET6);
144 uint16_t sdPort = static_cast<uint16_t>(port);
145
146// Get correct socket type
147//
148 if (*contype != 'u') PortType = SOCK_STREAM;
149 else {PortType = SOCK_DGRAM;
151 }
152
153// For each fd, check if it is a socket that we should have bound to. Make
154// allowances for UDP sockets. Otherwise, make sure the socket is listening.
155//
156 for (int i = 0; i < nSD; i++)
157 {int sdFD = SD_LISTEN_FDS_START + i;
158 if (sd_is_socket_inet(sdFD, v4Sock, PortType, -1, sdPort) > 0
159 || sd_is_socket_inet(sdFD, v6Sock, PortType, -1, sdPort) > 0)
160 {iofd = sdFD;
161 Portnum = port;
163 if (PortType == SOCK_DGRAM)
166 } else {
167 if (sd_is_socket(sdFD,v4Sock,PortType,0) > 0
168 || sd_is_socket(sdFD,v6Sock,PortType,0) > 0) return Listen();
169 }
170 return 0;
171 }
172 }
173#endif
174
175// Either we have no systemd process or no acceptable FD available. Do an
176// old-style bind() call to setup the socket.
177//
178 return Bind(port, contype);
179}
#define XRDNET_SERVER
Definition XrdNetOpts.hh:99
#define XRDNET_UDPSOCKET
Definition XrdNetOpts.hh:79
#define XRDNET_UDPBUFFSZ
static bool IPV4Set()
Definition XrdNetAddr.hh:61
static int setOpts(int fd, int options, XrdSysError *eDest=0)
int Windowsz
Definition XrdNet.hh:290
int Bind(int port, const char *contype="tcp")
Definition XrdNet.cc:164
int iofd
Definition XrdNet.hh:287
XrdNetBufferQ * BuffQ
Definition XrdNet.hh:293
int BuffSize
Definition XrdNet.hh:292
int PortType
Definition XrdNet.hh:289

References XrdNet::Bind(), XrdNet::BuffQ, XrdNet::BuffSize, XrdNet::eDest, XrdNet::iofd, XrdNetAddr::IPV4Set(), XrdNet::netOpts, opts, XrdNet::Portnum, XrdNet::PortType, XrdNetSocket::setOpts(), XrdNet::Windowsz, XRDNET_SERVER, XRDNET_UDPBUFFSZ, and XRDNET_UDPSOCKET.

+ Here is the call graph for this function:

◆ Connect()

XrdLink * XrdInet::Connect ( const char *  host,
int  port,
int  opts = 0,
int  timeout = -1 
)

Definition at line 185 of file XrdInet.cc.

186{
187 static const char *unk = "unkown.endpoint";
188 XrdNetAddr myAddr;
189 XrdLink *lp;
190 int lnkopts = (opts & XRDNET_MULTREAD ? XRDLINK_RDLOCK : 0);
191
192// Try to do a connect. This will be a unique TCP socket.
193//
194 if (!XrdNet::Connect(myAddr, host, port, opts, tmo)) return (XrdLink *)0;
195
196// Return a link object
197//
198 if (!(lp = XrdLinkCtl::Alloc(myAddr, lnkopts)))
199 {eDest->Emsg("Connect", ENOMEM, "allocate new link to", myAddr.Name(unk));
200 close(myAddr.SockFD());
201 } else {
202 TRACE(NET, "Connected to " <<myAddr.Name(unk) <<':' <<port);
203 }
204
205// All done, return whatever object we have
206//
207 return lp;
208}
int Connect(XrdNetAddr &myAddr, const char *dest, int port=-1, int opts=0, int timeout=-1)
Definition XrdNet.cc:252

References XrdLinkCtl::Alloc(), close, XrdNet::Connect(), XrdNet::eDest, XrdSysError::Emsg(), XrdNetAddrInfo::Name(), opts, XrdNetAddrInfo::SockFD(), TRACE, XRDLINK_RDLOCK, and XRDNET_MULTREAD.

+ Here is the call graph for this function:

◆ GetAssumeV4()

static bool XrdInet::GetAssumeV4 ( )
inlinestatic

Definition at line 65 of file XrdInet.hh.

65{return AssumeV4;}

◆ Secure()

void XrdInet::Secure ( XrdNetSecurity secp)
virtual

Add a NetSecurity object to the existing accept() security constraints.

Parameters
secpPointer to the network security object. This object must not be deleted nor directly used after the call as this object assumes its ownership and may delete it at any time.

Reimplemented from XrdNet.

Definition at line 244 of file XrdInet.cc.

245{
246
247// If we don't have a Patrol object then use the one supplied. Otherwise
248// merge the supplied object into the existing object.
249//
250 if (Patrol) Patrol->Merge(secp);
251 else Patrol = secp;
252}
void Merge(XrdNetSecurity *srcp)

References XrdNetSecurity::Merge().

Referenced by XrdgetProtocol().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetAssumeV4()

static void XrdInet::SetAssumeV4 ( bool  newVal)
inlinestatic

Definition at line 63 of file XrdInet.hh.

63{AssumeV4 = newVal;}

Member Data Documentation

◆ netIF

XrdNetIF XrdInet::netIF
static

Definition at line 68 of file XrdInet.hh.

Referenced by XrdXrootdProtocol::Configure(), and XrdConfig::Configure().


The documentation for this class was generated from the following files: