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

#include <XrdNetIF.hh>

+ Collaboration diagram for XrdNetIF:

Public Types

enum  ifType {
  PublicV4 = 0 ,
  PrivateV4 = 1 ,
  PublicV6 = 2 ,
  PrivateV6 = 3 ,
  PrivateIF = 1 ,
  ifNum = 4 ,
  Public46 = 4 ,
  Private46 = 5 ,
  Public64 = 6 ,
  Private64 = 7 ,
  ifMax = 8 ,
  ifAny = 8
}
 The enum that is used to index into ifData to get appropriate interface. More...
 
enum  netType {
  netDefault = 0 ,
  netSplit ,
  netCommon ,
  netLocal
}
 

Public Member Functions

 XrdNetIF ()
 Constructor and Destructor.
 
 ~XrdNetIF ()
 
void Display (const char *pfx="=====> ")
 
int GetDest (char *dest, int dlen, ifType ifT=PublicV6, bool prefn=false)
 
int GetName (char *nbuff, int &nport, ifType ifT=PublicV6)
 
int GetName (const char *&name, ifType ifT=PublicV6)
 
bool HasDest (ifType ifT=PublicV6)
 
char Mask ()
 
int Port ()
 
int Port (int pnum)
 
bool SetIF (XrdNetAddrInfo *src, const char *ifList, int port=0, netType nettype=netDefault, const char *xName=0)
 

Static Public Member Functions

static int GetIF (char *&ifline, const char **eText=0, bool show=false)
 
static int GetIF (char *buff, int blen, const char **eText=0, bool show=false)
 
static int GetIF (XrdOucTList **ifList, const char **eText=0)
 
static ifType GetIFType (bool conIPv4, bool hasIP64, bool pvtIP)
 
static bool InDomain (XrdNetAddrInfo *epaddr)
 
static char Mask (ifType ifT)
 
static const char * Name (ifType ifT)
 
static void PortDefault (int pnum=1094)
 
static void Privatize (ifType &x)
 
static void Routing (netType nettype)
 
static bool SetIFNames (char *ifnames)
 
static void SetMsgs (XrdSysError *erp)
 
static void SetRPIPA (bool rval)
 

Static Public Attributes

static const int haveIPv4 = 1
 ifList == 0 && non-local ipv4 i/f found (or'd)
 
static const int haveIPv6 = 2
 ifList == 0 && non-local ipv6 i/f found (or'd)
 
static const int haveNoGI = 0
 ifList == 0 && getifaddrs() is not supported
 
static const int havePrv4 = 4
 ifList == 0 && private ipv4 i/f found (or'd)
 
static const int havePrv6 = 8
 ifList == 0 && private ipv6 i/f found (or'd)
 
static const int havePub4 =16
 ifList == 0 && public ipv4 i/f found (or'd)
 
static const int havePub6 =32
 ifList == 0 && public ipv6 i/f found (or'd)
 

Detailed Description

Definition at line 48 of file XrdNetIF.hh.

Member Enumeration Documentation

◆ ifType

The enum that is used to index into ifData to get appropriate interface.

Enumerator
PublicV4 
PrivateV4 
PublicV6 
PrivateV6 
PrivateIF 
ifNum 
Public46 
Private46 
Public64 
Private64 
ifMax 
ifAny 

Definition at line 64 of file XrdNetIF.hh.

64 {PublicV4 = 0, //<! Public IPv4 network
65 PrivateV4 = 1, //<! Private IPv4 network
66 PublicV6 = 2, //<! Public IPv6 network
67 PrivateV6 = 3, //<! Private IPv6 network
68 PrivateIF = 1, //<! Bit to change PublicVx -> PrivateVx
69 ifNum = 4, //<! Count of actual interface types
70 Public46 = 4, //<! Public v4|6 network (dual stack)
71 Private46 = 5, //<! Private v4|6 network (dual stack)
72 Public64 = 6, //<! Public v6|4 network (dual stack)
73 Private64 = 7, //<! Private v6|4 network (dual stack)
74 ifMax = 8, //<! Total elements in if vector
75 ifAny = 8}; //<! Used to select any avilable i/f
@ PrivateV4
Definition XrdNetIF.hh:65
@ Private64
Definition XrdNetIF.hh:73
@ PrivateIF
Definition XrdNetIF.hh:68
@ Private46
Definition XrdNetIF.hh:71
@ PrivateV6
Definition XrdNetIF.hh:67

◆ netType

Routing() and SetIF() parameter.

netDefault - netSplit for Routing() and Routing() value for SetIF(). netSplit - public and private addresses are routed separately so that substitution of one type of address for another is not allowed. netCommon - clients with private addresses also have public addresses. Source and target addresses should match but a public address may be used in the absence of a private address. netLocal - private addresses are registered and can be used by public clients within this domain. Clients with public addresses can be routed to private addresses.

Enumerator
netDefault 
netSplit 
netCommon 
netLocal 

Definition at line 318 of file XrdNetIF.hh.

Constructor & Destructor Documentation

◆ XrdNetIF()

XrdNetIF::XrdNetIF ( )
inline

Constructor and Destructor.

Definition at line 385 of file XrdNetIF.hh.

385: ifBuff(0), ifMask(0), ifAvail(0) {}

◆ ~XrdNetIF()

XrdNetIF::~XrdNetIF ( )
inline

Definition at line 387 of file XrdNetIF.hh.

387{if (ifBuff) free(ifBuff);}

Member Function Documentation

◆ Display()

void XrdNetIF::Display ( const char * pfx = "=====> ")

Display the final interface configuration.

Parameters
pfxThe desired message prefix (default is as shown).

Definition at line 142 of file XrdNetIF.cc.

143{
144 static const char *ifN[] = {"pub4", "prv4", "pub6", "prv6"};
145 static const char *ifT[] = {"all4", 0, "all6", 0};
146 static const char *nNM[] = {"local", "split", "common", "local"};
147 const char *iHX[hasNum] = {"", "", "", ""};
148 const char *ifRType, *hName = "";
149 char buff[256];
150 bool nameOK = false;
151
152// If we have no error routing object, just return
153//
154 if (!eDest) return;
155
156// Get a hostname
157//
158 for (int i = 0; i < (int)ifNum; i++)
159 {if (ifName[i] != &ifNull)
160 {hName = ifName[i]->iVal;
161 if (ifxDNS[i]) {nameOK = true; break;}
162 }
163 }
164
165// Compute selection mask
166//
167 for (int i = 0; i < hasNum; i++)
168 if (ifMask & sMask[i]) iHX[i] = sName[i];
169
170// Print results
171//
172 sprintf(buff, ": %s %s%s%s%s", nNM[ifRoute], iHX[0],iHX[1],iHX[2],iHX[3]);
173 eDest->Say(pfx, "Routing for ", hName, buff);
174
175 for (int i = 0; i < (int)ifNum; i++)
176 {if (ifName[i] != &ifNull)
177 {if (ifT[i] && ifDest[i] == ifDest[i+1]) {ifRType = ifT[i]; i++;}
178 else ifRType = ifN[i];
179 sprintf(buff, "Route %s: ", ifRType);
180 eDest->Say(pfx, buff, (nameOK ? hName : ifName[i]->iVal),
181 " Dest=", ifDest[i]->iVal, portSfx.val);
182 }
183 }
184}
void Say(const char *text1, const char *text2=0, const char *txt3=0, const char *text4=0, const char *text5=0, const char *txt6=0)

References ifNum, and XrdSysError::Say().

Referenced by XrdXrootdProtocol::Configure(), and XrdCmsNode::ShowIF().

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

◆ GetDest()

int XrdNetIF::GetDest ( char * dest,
int dlen,
ifType ifT = PublicV6,
bool prefn = false )

Get the interface address with a port number.

Parameters
destPointer to the buffer where dest will be placed.
dlenThe length of the buffer.
ifTDesired ifType (PublicV6 is the default)
prefnWhen true, a hostname:port is returned if possible
Returns
The length of the name whose pointer is placed in name. A value of zero indicates that no such interface exists or the buffer was too small.

Definition at line 389 of file XrdNetIF.cc.

390{
391 ifType ifX = (ifT >= ifAny ? static_cast<ifType>(ifAvail) : ifT);
392 ifData *ifP = (prefn && ifxDNS[ifX] ? ifName[ifX] : ifDest[ifX]);
393 int n;
394
395// Compute length and make sure we don't overflow
396//
397 n = ifP->iLen + portSfx.len;
398 if (!(ifP->iLen) || n >= dlen) return 0;
399
400// Return result with port appended
401//
402 strcpy(dest, ifP->iVal);
403 strcpy(dest +ifP->iLen, portSfx.val);
404 return n;
405}
ifType
The enum that is used to index into ifData to get appropriate interface.
Definition XrdNetIF.hh:64

References ifAny.

Referenced by XrdOfs::fsctl(), XrdSsiSfs::fsctl(), and XrdCmsCluster::List().

+ Here is the caller graph for this function:

◆ GetIF() [1/3]

int XrdNetIF::GetIF ( char *& ifline,
const char ** eText = 0,
bool show = false )
static

Obtain an easily transmittable IP routable interfaces to this machine.

Parameters
iflineReference to a char * pointer that will get the result.
eTextWhen not nil, is where to place error message text.
showWhen true configured interfaces are also displayed.
Returns
Success: Number of bytes in the returned string ecluding the null. The caller is responsible for unallocating it via free(). Failure: Zero is returned. If eText is supplied, the error message, in persistent storage, is returned. *ifline is set to 0.

Definition at line 573 of file XrdNetIF.cc.

574{
575 char buff[4096];
576 int n;
577
578 if ((n = GetIF(buff, sizeof(buff), eText, show))) ifline = strdup(buff);
579 else ifline = 0;
580
581// Warn about no interfaces
582//
583 if (!ifline && show && eDest)
584 eDest->Say("Config ", "No usable interfaces; using DNS registered "
585 "address as the interface.");
586 return n;
587}
static int GetIF(XrdOucTList **ifList, const char **eText=0)
Definition XrdNetIF.cc:413

References eDest, GetIF(), and XrdSysError::Say().

+ Here is the call graph for this function:

◆ GetIF() [2/3]

int XrdNetIF::GetIF ( char * buff,
int blen,
const char ** eText = 0,
bool show = false )
static

Obtain an easily transmittable IP routable interfaces to this machine.

Parameters
buffPointer to buffer to hold result which can be fed to SetIF.
blenThe length of the buffer (4K is really sufficient).
eTextWhen not nil, is where to place error message text.
showWhen true configured interfaces are also displayed.
Returns
Success: Number of bytes placed in buff, excluding the null. Failure: Zero is returned. If eText is supplied, the error message, in persistent storage, is returned.

Definition at line 520 of file XrdNetIF.cc.

521{
522 XrdOucTList *ifP, *ifN;
523 const char *ifName[3] = {ifCfg[0], ifCfg[1], "anon"};
524 char *bP = buff;
525 int n, bLeft = blen-8;
526 bool ifOK[3] = {false, false, false};
527
528#ifndef HAVE_GETIFADDRS
529// Display warning on how we are getting the interface addresses
530//
531 if (eDest && show)
532 eDest->Say("Config Warning: using DNS registered address as interface!");
533#endif
534
535// Create the interface list here
536//
537 *buff = 0;
538 if (GetIF(&ifN, eText))
539 {while((ifP = ifN))
540 {n = ifP->sval[0];
541 if (bLeft > n+2)
542 {if (bP != buff) {*bP++ = ' '; bLeft--;}
543 strcpy(bP, ifP->text);
544 bP += n; bLeft -= (n+1);
545 }
546 ifOK[ifP->sval[2]] = true;
547 if (show && eDest)
548 {const char *kind = (ifP->sval[1] ? " private" : " public ");
549 eDest->Say("Config ", ifName[ifP->sval[2]], kind,
550 " network interface: ", ifP->text);
551 }
552 ifN = ifP->next; delete ifP;
553 }
554 }
555
556// Warn about missing interfaces
557//
558 if (show && eDest)
559 {for (n = 0; n < 2; n++)
560 {if (!ifOK[n] && ifCfg[n])
561 eDest->Say("Config ", ifCfg[n],
562 " interface not found or is not usable.");
563 }
564 }
565
566// Return result
567//
568 return bP-buff;
569}
XrdOucTList * next

References eDest, GetIF(), XrdOucTList::next, XrdSysError::Say(), and XrdOucTList::text.

+ Here is the call graph for this function:

◆ GetIF() [3/3]

int XrdNetIF::GetIF ( XrdOucTList ** ifList,
const char ** eText = 0 )
static

Definition at line 413 of file XrdNetIF.cc.

414{
415 static const int prvIF[] = {havePrv4, havePrv6};
416 static const int pubIF[] = {havePub4, havePub6};
417
418 char ipBuff[256];
419 short ifIdx = 0, sval[4] = {0, 0, 0, 0};
420 short iLen;
421 int ifT, haveIF = 0;
422
423#ifdef HAVE_GETIFADDRS
424
425// Obtain the list of interfaces
426//
427 XrdNetAddr netAddr;
428 struct ifaddrs *ifBase, *ifP;
429 XrdOucTList *tLP, *tList = 0, *tLast = 0;
430 int n = 0;
431 bool anyIF = (ifCfg[0] == 0 && ifCfg[1] == 0);
432
433 if (getifaddrs(&ifBase) < 0)
434 {if (eText) *eText = XrdSysE2T(errno);
435 if (ifList) *ifList = 0;
436 if (eDest) eDest->Emsg("GetIF", errno, "get interface addresses.");
437 return 0;
438 }
439
440// Report only those interfaces that are up and are not loop-back devices and
441// have been specified by actual name
442//
443 ifP = ifBase;
444 while(ifP)
445 {if ((ifP->ifa_addr != 0)
446 && (!ifList || anyIF || IsOkName(ifP->ifa_name, ifIdx))
447 && (ifP->ifa_flags & (IFF_UP))
448 && (ifP->ifa_flags & (IFF_RUNNING))
449 && !(ifP->ifa_flags & (IFF_LOOPBACK))
450 && ((ifP->ifa_addr->sa_family == AF_INET &&
451 !V4LinkLocal(ifP->ifa_addr))
452 ||
453 (ifP->ifa_addr->sa_family == AF_INET6 &&
454 !(IN6_IS_ADDR_LINKLOCAL(&((sockaddr_in6 *)(ifP->ifa_addr))->sin6_addr)))
455 )
456 )
457 {if (ifP->ifa_addr->sa_family == AF_INET){haveIF |= haveIPv4;ifT=0;}
458 else {haveIF |= haveIPv6; ifT = 1;}
459 if (ifList)
460 {netAddr.Set(ifP->ifa_addr);
461 if ((iLen = netAddr.Format(ipBuff, sizeof(ipBuff),
463 {sval[2] = (anyIF ? 3 : ifIdx);
464 sval[1] = (netAddr.isPrivate() ? 1 : 0);
465 sval[0] = iLen;
466 haveIF |= (sval[1] ? prvIF[ifT] : pubIF[ifT]);
467 tLP = new XrdOucTList(ipBuff, sval);
468 if (tList) tLast->next = tLP;
469 else tList = tLP;
470 tLast = tLP;
471 n++;
472 }
473 } else {
474 netAddr.Set(ifP->ifa_addr);
475 haveIF |= (netAddr.isPrivate() ? prvIF[ifT] : pubIF[ifT]);
476 }
477 }
478 ifP = ifP->ifa_next;
479 }
480
481// All done
482//
483 if (ifBase) freeifaddrs(ifBase);
484 if (eText) *eText = 0;
485 if (!ifList) return haveIF;
486 *ifList = tList;
487 return n;
488
489#else
490
491// If we just need to provide the interface type, indicate we cannot
492//
493 if (!ifList) return haveNoGI;
494
495// For platforms that don't support getifaddrs() use our address
496//
497 XrdNetAddr netAddr((int)0);
498
499// Simply return our formatted address as the interface address
500//
501 if ((iLen = netAddr.Format(ipBuff, sizeof(ipBuff),
503 {if (eText) *eText = 0;
504 sval[0] = iLen;
505 *ifList = new XrdOucTList(ipBuff, sval);
506 return 1;
507 }
508
509// Something bad happened and it shouldn't have
510//
511 if (eText) *eText = "unknown error";
512 if (eDest) eDest->Emsg("GetIF", "Unable to get interface address; "
513 "check if IPV6 enabled!");
514 return 0;
515#endif
516}
static XrdSysError eDest(0,"crypto_")
const char * XrdSysE2T(int errcode)
Definition XrdSysE2T.cc:104
static const int noPort
Do not add port number.
int Format(char *bAddr, int bLen, fmtUse fmtType=fmtAuto, int fmtOpts=0)
@ fmtAddr
Address using suitable ipv4 or ipv6 format.
const char * Set(const char *hSpec, int pNum=PortInSpec)
static const int haveNoGI
ifList == 0 && getifaddrs() is not supported
Definition XrdNetIF.hh:148
static const int haveIPv4
ifList == 0 && non-local ipv4 i/f found (or'd)
Definition XrdNetIF.hh:150
static const int havePub6
ifList == 0 && public ipv6 i/f found (or'd)
Definition XrdNetIF.hh:160
static const int havePub4
ifList == 0 && public ipv4 i/f found (or'd)
Definition XrdNetIF.hh:158
static const int haveIPv6
ifList == 0 && non-local ipv6 i/f found (or'd)
Definition XrdNetIF.hh:152
static const int havePrv6
ifList == 0 && private ipv6 i/f found (or'd)
Definition XrdNetIF.hh:156
static const int havePrv4
ifList == 0 && private ipv4 i/f found (or'd)
Definition XrdNetIF.hh:154
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)

References eDest, XrdSysError::Emsg(), XrdNetAddrInfo::fmtAddr, XrdNetAddrInfo::Format(), haveIPv4, haveIPv6, haveNoGI, havePrv4, havePrv6, havePub4, havePub6, XrdNetAddrInfo::isPrivate(), XrdNetAddrInfo::noPort, XrdNetAddr::Set(), and XrdSysE2T().

Referenced by XrdConfig::Configure(), GetIF(), GetIF(), XrdNetUtils::NetConfig(), and XrdNetUtils::SetAuto().

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

◆ GetIFType()

static ifType XrdNetIF::GetIFType ( bool conIPv4,
bool hasIP64,
bool pvtIP )
inlinestatic

Get the ifType for client connection.

Parameters
conIPv4True if connected via IPv4, false means IPv6.
hasIP64True if the client has an IPv4 and IPv6 address.
pvtIPTrue if the ip address is private.
Returns
The ifType correspodning to the passed arguments.

Definition at line 204 of file XrdNetIF.hh.

205 {ifType ifT;
206 if (conIPv4) ifT = (hasIP64 ? Public46 : PublicV4);
207 else ifT = (hasIP64 ? Public64 : PublicV6);
208 if (pvtIP) Privatize(ifT);
209 return ifT;
210 }
static void Privatize(ifType &x)
Definition XrdNetIF.hh:284

References Privatize(), Public46, Public64, PublicV4, and PublicV6.

Referenced by XrdOfs::fsctl(), and XrdSsiSfs::fsctl().

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

◆ GetName() [1/2]

int XrdNetIF::GetName ( char * nbuff,
int & nport,
ifType ifT = PublicV6 )
inline

Copy the interface name and return port number.

Parameters
nbuffReference to buffer where the name will be placed. It must be atleast 256 bytes in length.
nportPlace where the port number will be placed.
ifTDesired ifType (PublicV6 is the default)
Returns
The length of the name copied into the buffer. A value of zero indicates that no such interface exists.

Definition at line 120 of file XrdNetIF.hh.

121 {if (ifT >= ifAny) ifT = static_cast<ifType>(ifAvail);
122 strcpy(nbuff, ifName[ifT]->iVal); nport = ifPort;
123 return ifName[ifT]->iLen;
124 }

References ifAny.

◆ GetName() [2/2]

int XrdNetIF::GetName ( const char *& name,
ifType ifT = PublicV6 )
inline

Get the interface name without a port number.

Parameters
nameReference to where a pointer to the name will be placed
ifTDesired ifType (PublicV6 is the default)
Returns
The length of the name whose pointer is placed in name. A value of zero indicates that no such interface exists.

Definition at line 102 of file XrdNetIF.hh.

103 {if (ifT >= ifAny) ifT = static_cast<ifType>(ifAvail);
104 name = ifName[ifT]->iVal;
105 return ifName[ifT]->iLen;
106 }

References ifAny.

Referenced by XrdCmsCluster::Select().

+ Here is the caller graph for this function:

◆ HasDest()

bool XrdNetIF::HasDest ( ifType ifT = PublicV6)
inline

Determine whether or not an interface exists.

Parameters
ifT-> Desired ifType (PublicV6 is the default)
Returns
true -> desired dest exists. false -> desired dest does not exist.

Definition at line 221 of file XrdNetIF.hh.

222 {return ifT >= ifAny || ifDest[ifT]->iLen != 0;}

References ifAny.

Referenced by XrdCmsCluster::List().

+ Here is the caller graph for this function:

◆ InDomain()

bool XrdNetIF::InDomain ( XrdNetAddrInfo * epaddr)
static

Determine if an endpoint is this domain based on hostname.

Parameters
epaddrPointer to the endpoint NetAddrInfo object.
Returns
true The endpoint is in this domain.
false Either the endpoint is not in this domain, is a private address, or is not registered in DNS.

Definition at line 606 of file XrdNetIF.cc.

607{
608 const char *hnP;
609
610// Do not attempt to resolve private addresses as they are always in the domain.
611//
612 if (epaddr->isPrivate()) return true;
613
614// Checkout the domain
615//
616 if (!myDomain || !(hnP = epaddr->Name(0)) || !(hnP = index(hnP, '.')))
617 return false;
618
619// Match the domain and returnthe result
620//
621 return strcmp(myDomain, hnP+1) == 0;
622}
const char * Name(const char *eName=0, const char **eText=0)

References XrdNetAddrInfo::isPrivate(), and XrdNetAddrInfo::Name().

Referenced by XrdCmsNode::inDomain(), XrdSecProtector::New4Server(), XrdXrootdProtocol::Process2(), XrdSecProtector::ProtResp(), and XrdCmsNode::setName().

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

◆ Mask() [1/2]

char XrdNetIF::Mask ( )
inline

Get the ifType selection mask for this object.

Returns
A single char that represents the selection mask.

Definition at line 242 of file XrdNetIF.hh.

242{return ifMask;}

Referenced by XrdCmsCluster::Select(), and XrdCmsNode::setName().

+ Here is the caller graph for this function:

◆ Mask() [2/2]

static char XrdNetIF::Mask ( ifType ifT)
inlinestatic

Convert an ifType to its corresponding selection mask.

Parameters
ifTThe ifType to convert.
Returns
A single char that represents the selection mask.

Definition at line 252 of file XrdNetIF.hh.

253 {if (ifT >= ifAny) return 0x0f;
254 return ifMaskVec[ifT];
255 }

References ifAny.

◆ Name()

static const char * XrdNetIF::Name ( ifType ifT)
inlinestatic

Get the human readable for for an ifType.

Parameters
ifTThe ifType to convert.
Returns
A pointer to the human readable name. The string resides in static storage and is always valid.

Definition at line 266 of file XrdNetIF.hh.

266 {if (ifT >= ifAny) return "any";
267 return ifTName[ifT];
268 }

References ifAny.

Referenced by XrdCmsNode::do_Locate().

+ Here is the caller graph for this function:

◆ Port() [1/2]

int XrdNetIF::Port ( )
inline

Get the assigned port number

Returns
The port number.

Definition at line 276 of file XrdNetIF.hh.

276{return ifPort;}

Referenced by XrdXrootdProtocol::Configure(), XrdCmsNode::do_Status(), XrdCmsNode::isNode(), XrdCmsCluster::List(), SetIF(), and XrdCmsNode::setName().

+ Here is the caller graph for this function:

◆ Port() [2/2]

int XrdNetIF::Port ( int pnum)

Set the assigned port number. This method is not thread safe!

Parameters
pnumThe port number.
Returns
The previous port number.

Definition at line 641 of file XrdNetIF.cc.

642{
643 int prevport = ifPort;
644
645// Check if anything is really changing
646//
647 pnum &= 0x0000ffff;
648 if (pnum == prevport) return prevport;
649
650// Format the port number (can't be more than 5 characters)
651//
652 portSfx.len = sprintf(portSfx.val, ":%d", pnum);
653 ifPort = pnum;
654
655// All done
656//
657 return prevport;
658}

◆ PortDefault()

void XrdNetIF::PortDefault ( int pnum = 1094)
static

Set the default assigned port number.

Parameters
pnumThe port number.

Definition at line 664 of file XrdNetIF.cc.

664{dfPort = pnum;}

◆ Privatize()

static void XrdNetIF::Privatize ( ifType & x)
inlinestatic

Make an iofType refer to the private network.

Parameters
xThe iftype variable that will have the private bit set.

Definition at line 284 of file XrdNetIF.hh.

284{x = ifType(x | PrivateIF);}

References PrivateIF.

Referenced by XrdCmsNode::do_Locate(), XrdCmsNode::do_Select(), and GetIFType().

+ Here is the caller graph for this function:

◆ Routing()

void XrdNetIF::Routing ( XrdNetIF::netType nettype)
static

Set default interface network routing.

Parameters
nettypeNetwork routing (see netType definition).

Definition at line 670 of file XrdNetIF.cc.

671{
672
673// Set the routing type
674//
675 netRoutes = (nettype == netDefault ? netLocal : nettype);
676
677// Based on the routing we need to set the appropriate selection mask vector
678//
679 if (netRoutes == netLocal) ifMaskVec = ifMaskLocal;
680 else if (netRoutes == netSplit) ifMaskVec = ifMaskSplit;
681 else ifMaskVec = ifMaskComm;
682}

References netDefault, netLocal, and netSplit.

◆ SetIF()

bool XrdNetIF::SetIF ( XrdNetAddrInfo * src,
const char * ifList,
int port = 0,
netType nettype = netDefault,
const char * xName = 0 )

Set the ifData structure based on the interface string generated by GetIF().

Parameters
srcThe network information of host supplying the if string.
ifListThe interface string, it must be null terminated.
portThe port associated with the interfaces; as follows: <0 -> Use previous setting if any. =0 -> use default port (the default). >0 -> Use the number passed.
nettypeDetermines how undefined interfaces are resolved. See the netType definition.
xNamethe known registered host name should ip address translation fail.
Returns
Success: True. Failure: False and if eText is supplied, the error message, in persistent storage, is returned.

Definition at line 688 of file XrdNetIF.cc.

690{
691 XrdNetAddrInfo *netIF[4] = {0,0,0,0}; //pub 0:v4, prv 1:v4 pub 2:v6 prv 3:v6
692 XrdNetAddr netAdr[4];
693 const char *ifErr = 0, *ifBeg = ifList, *ifEnd, *ifAdr, *ifBad = 0;
694 int i, n, ifCnt = 1;
695 char abuff[64];
696
697// Setup the port number (this sets ifPort)
698//
699 if (port >= 0) Port((port ? port : dfPort));
700
701// Set routing mode for this interface
702//
703 ifRoute = static_cast<short>(nettype == netDefault ? netRoutes : nettype);
704
705// If no list is supplied then fill out based on the source address
706//
707 if (!ifList || !(*ifList))
708 {XrdNetAddrInfo *ifVec[8];
709 XrdNetAddr *iP;
710 const char *hName = src->Name();
711 if (!(src->isRegistered()) && xName) hName = xName;
712 ifCnt = 0;
713 if (!hName
714 || XrdNetUtils::GetAddrs(hName,&iP,ifCnt,XrdNetUtils::allIPv64,ifPort)
715 || !ifCnt) return SetIF64(GenIF(&src, 1));
716 if (ifCnt > 8) ifCnt = 8;
717 for (i = 0; i < ifCnt; i++) ifVec[i] = &iP[i];
718 bool aOK = GenIF(ifVec, ifCnt, hName);
719 delete [] iP;
720 return SetIF64(aOK);
721 }
722
723// Prefrentially use the connect address as the primary interface. This
724// avoids using reported interfaces that may have strange routing.
725//
726 i = (src->isIPType(XrdNetAddrInfo::IPv4) || src->isMapped() ? 0 : 2);
727 if (src->isPrivate()) i |= 1;
728 netIF[i] = src;
729
730// Process the iflist (up to four interfaces)
731//
732 do {while (*ifBeg && *ifBeg == ' ') ifBeg++;
733 if ( !(*ifBeg)) break;
734 if (!(ifEnd = index(ifBeg, ' '))) {ifAdr = ifBeg; ifBeg = "";}
735 else {n = ifEnd - ifBeg;
736 if (n >= (int)sizeof(abuff))
737 {ifAdr = 0; ifBad = ifBeg; ifErr = "invalid";}
738 else {strncpy(abuff, ifBeg, n); abuff[n] = 0; ifAdr = abuff;}
739 ifBeg = ifEnd+1;
740 }
741 if (!ifAdr || (ifErr = netAdr[ifCnt].Set(ifAdr, ifPort)))
742 {if (eDest)
743 {if (!ifAdr) ifAdr = ifBad;
744 eDest->Emsg("SetIF", "Unable to use interface", ifAdr, ifErr);
745 }
746 continue;
747 }
748 i = (netAdr[ifCnt].isIPType(XrdNetAddrInfo::IPv4) ||
749 netAdr[ifCnt].isMapped() ? 0 : 2);
750 if (netAdr[ifCnt].isPrivate()) i |= 1;
751 if (!netIF[i]) netIF[i] = &netAdr[ifCnt--];
752 } while(ifCnt >= 0);
753
754// Set the interface data
755//
756 return SetIF64(GenIF(netIF, 4));
757}
bool isMapped() const
bool isIPType(IPType ipType) const
int Port()
Definition XrdNetIF.hh:276
static const char * GetAddrs(const char *hSpec, XrdNetAddr *aListP[], int &aListN, AddrOpts opts=allIPMap, int pNum=PortInSpec)

References XrdNetUtils::allIPv64, eDest, XrdSysError::Emsg(), XrdNetUtils::GetAddrs(), XrdNetAddrInfo::IPv4, XrdNetAddrInfo::isIPType(), XrdNetAddrInfo::isMapped(), XrdNetAddrInfo::isPrivate(), XrdNetAddrInfo::isRegistered(), XrdNetAddrInfo::Name(), netDefault, and Port().

Referenced by XrdCmsNode::setName().

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

◆ SetIFNames()

bool XrdNetIF::SetIFNames ( char * ifnames)
static

Set the public and private network interface names.

Parameters
ifnamesPointer to the comma seperated interface names. This string is modified.
Returns
true Names have been set.
false Invalid interface name list.

Definition at line 763 of file XrdNetIF.cc.

764{
765 char *comma;
766
767// Parse the interface names
768//
769 if ((comma = index(ifnames, ',')))
770 {if (comma == ifnames || !(*(comma+1)))
771 {if (eDest) eDest->Say("Config","Invalid interface name - ",ifnames);
772 return false;
773 }
774 }
775
776// Free old names, if any
777//
778 if (ifCfg[0]) free(ifCfg[0]);
779 if (ifCfg[1]) free(ifCfg[1]);
780
781// Copy the new names
782//
783 if (comma)
784 {*comma = 0;
785 ifCfg[1] = (strcmp(ifnames, comma+1) ? strdup(comma+1) : 0);
786 *comma = ',';
787 } else ifCfg[1] = 0;
788 ifCfg[0] = strdup(ifnames);
789 return true;
790}

References eDest, and XrdSysError::Say().

+ Here is the call graph for this function:

◆ SetMsgs()

void XrdNetIF::SetMsgs ( XrdSysError * erp)
static

Specify where messages are to be sent.

Parameters
erpPointer to the error message object. By default, no error messages are printed. This is not a thread-safe call and the err disposition must be set at initialization time.

Definition at line 870 of file XrdNetIF.cc.

870{eDest = erp;}

References eDest.

Referenced by XrdConfig::Configure().

+ Here is the caller graph for this function:

◆ SetRPIPA()

void XrdNetIF::SetRPIPA ( bool rval)
static

Specify wheter or not private IP addresses should be resolved.

Parameters
rvalWhen true, private IP addresses are resolved. Otherwise, the IP addresses is used as the hostname.

Definition at line 876 of file XrdNetIF.cc.

876{rPIPA = rval;}

Member Data Documentation

◆ haveIPv4

const int XrdNetIF::haveIPv4 = 1
static

ifList == 0 && non-local ipv4 i/f found (or'd)

Definition at line 150 of file XrdNetIF.hh.

Referenced by GetIF(), XrdNetUtils::NetConfig(), and XrdNetUtils::SetAuto().

◆ haveIPv6

const int XrdNetIF::haveIPv6 = 2
static

ifList == 0 && non-local ipv6 i/f found (or'd)

Definition at line 152 of file XrdNetIF.hh.

Referenced by GetIF(), XrdNetUtils::NetConfig(), and XrdNetUtils::SetAuto().

◆ haveNoGI

const int XrdNetIF::haveNoGI = 0
static

ifList == 0 && getifaddrs() is not supported

Obtain an easily digestable list of IP routable interfaces to this machine.

Parameters
ifListPlace where the list of interfaces will be placed. If ifList is null, returns configured interface types.
eTextWhen not nil, is where to place error message text.
Returns
Success: ifList != 0: returns the count of interfaces in the list. *ifList->sval[0] strlen(ifList->text) *ifList->sval[1] when != 0 the address is private. *ifList->text the interface address is standard format. The list of objects belongs to the caller and must be deleted when no longer needed.

ifList == 0: returns types of configured non-local i/f. This is or'd values of the static const ints haveXXXX.

Failure: Zero is returned. If eText is supplied, the error message, in persistent storage, is returned.

Definition at line 148 of file XrdNetIF.hh.

Referenced by GetIF().

◆ havePrv4

const int XrdNetIF::havePrv4 = 4
static

ifList == 0 && private ipv4 i/f found (or'd)

Definition at line 154 of file XrdNetIF.hh.

Referenced by GetIF().

◆ havePrv6

const int XrdNetIF::havePrv6 = 8
static

ifList == 0 && private ipv6 i/f found (or'd)

Definition at line 156 of file XrdNetIF.hh.

Referenced by GetIF().

◆ havePub4

const int XrdNetIF::havePub4 =16
static

ifList == 0 && public ipv4 i/f found (or'd)

Definition at line 158 of file XrdNetIF.hh.

Referenced by GetIF(), and XrdNetUtils::NetConfig().

◆ havePub6

const int XrdNetIF::havePub6 =32
static

ifList == 0 && public ipv6 i/f found (or'd)

Definition at line 160 of file XrdNetIF.hh.

Referenced by GetIF(), and XrdNetUtils::NetConfig().


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