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}

References ifNum.

Referenced by XrdXrootdProtocol::Configure().

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 GetIF().

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 GetIF(), XrdOucTList::next, 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}
const char * XrdSysE2T(int errcode)
Definition XrdSysE2T.cc:101
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
XrdOucTList(const char *tval, long long *dv, XrdOucTList *np=0)

References XrdOucTList::XrdOucTList(), 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(), getMyFQN(), XrdNetUtils::NetConfig(), and XrdNetUtils::SetAuto().

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

◆ GetIFType()

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, and PublicV6.

◆ 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, and PublicV6.

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, and PublicV6.

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 607 of file XrdNetIF.cc.

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

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

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

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().

Here is the caller graph for this function:

◆ Mask() [2/2]

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()

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(), XrdCmsCluster::List(), and SetIF().

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 643 of file XrdNetIF.cc.

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

◆ PortDefault()

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

Set the default assigned port number.

Parameters
pnumThe port number.

Definition at line 666 of file XrdNetIF.cc.

666{dfPort = pnum;}

◆ Privatize()

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 672 of file XrdNetIF.cc.

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

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 690 of file XrdNetIF.cc.

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

Here is the call 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 765 of file XrdNetIF.cc.

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

◆ 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 872 of file XrdNetIF.cc.

872{eDest = erp;}

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 878 of file XrdNetIF.cc.

878{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: