Loading...
Searching...
No Matches
XrdNetIF.hh
Go to the documentation of this file.
#ifndef __XRDNETIF_HH__
#define __XRDNETIF_HH__
/******************************************************************************/
/* */
/* X r d N e t I F . h h */
/* */
/* (c) 2013 by the Board of Trustees of the Leland Stanford, Jr., University */
/* All Rights Reserved */
/* Produced by Andrew Hanushevsky for Stanford University under contract */
/* DE-AC02-76-SFO0515 with the Department of Energy */
/* */
/* This file is part of the XRootD software suite. */
/* */
/* XRootD is free software: you can redistribute it and/or modify it under */
/* the terms of the GNU Lesser General Public License as published by the */
/* Free Software Foundation, either version 3 of the License, or (at your */
/* option) any later version. */
/* */
/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
/* License for more details. */
/* */
/* You should have received a copy of the GNU Lesser General Public License */
/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
/* */
/* The copyright holder's institutional names and contributor's names may not */
/* be used to endorse or promote products derived from this software without */
/* specific prior written permission of the institution or contributor. */
/******************************************************************************/
#include <cstdlib>
#include <cstring>
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
class XrdNetAddrInfo;
class XrdOucTList;
class XrdSysError;
struct sockaddr;
class XrdNetIF
{
public:
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void Display(const char *pfx="=====> ");
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
enum ifType {PublicV4 = 0, //<! Public IPv4 network
PrivateV4 = 1, //<! Private IPv4 network
PublicV6 = 2, //<! Public IPv6 network
PrivateV6 = 3, //<! Private IPv6 network
PrivateIF = 1, //<! Bit to change PublicVx -> PrivateVx
ifNum = 4, //<! Count of actual interface types
Public46 = 4, //<! Public v4|6 network (dual stack)
Private46 = 5, //<! Private v4|6 network (dual stack)
Public64 = 6, //<! Public v6|4 network (dual stack)
Private64 = 7, //<! Private v6|4 network (dual stack)
ifMax = 8, //<! Total elements in if vector
ifAny = 8}; //<! Used to select any avilable i/f
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
int GetDest(char *dest, int dlen, ifType ifT=PublicV6, bool prefn=false);
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
inline int GetName(const char *&name, ifType ifT=PublicV6)
{if (ifT >= ifAny) ifT = static_cast<ifType>(ifAvail);
name = ifName[ifT]->iVal;
return ifName[ifT]->iLen;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
inline int GetName(char *nbuff, int &nport, ifType ifT=PublicV6)
{if (ifT >= ifAny) ifT = static_cast<ifType>(ifAvail);
strcpy(nbuff, ifName[ifT]->iVal); nport = ifPort;
return ifName[ifT]->iLen;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
static
const int haveNoGI = 0;
static
const int haveIPv4 = 1;
static
const int haveIPv6 = 2;
static
const int havePrv4 = 4;
static
const int havePrv6 = 8;
static
const int havePub4 =16;
static
const int havePub6 =32;
static int GetIF(XrdOucTList **ifList, const char **eText=0);
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
static int GetIF(char *buff, int blen, const char **eText=0, bool show=false);
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
static int GetIF(char *&ifline, const char **eText=0, bool show=false);
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
static ifType GetIFType(bool conIPv4, bool hasIP64, bool pvtIP)
{ifType ifT;
if (conIPv4) ifT = (hasIP64 ? Public46 : PublicV4);
else ifT = (hasIP64 ? Public64 : PublicV6);
if (pvtIP) Privatize(ifT);
return ifT;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
inline bool HasDest(ifType ifT=PublicV6)
{return ifT >= ifAny || ifDest[ifT]->iLen != 0;}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
static bool InDomain(XrdNetAddrInfo *epaddr);
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
char Mask() {return ifMask;}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
static char Mask(ifType ifT)
{if (ifT >= ifAny) return 0x0f;
return ifMaskVec[ifT];
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
static
const char *Name(ifType ifT) {if (ifT >= ifAny) return "any";
return ifTName[ifT];
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
inline int Port() {return ifPort;}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
static void Privatize(ifType &x) {x = ifType(x | PrivateIF);}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
int Port(int pnum);
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
static void PortDefault(int pnum=1094);
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
enum netType {netDefault = 0, netSplit, netCommon, netLocal};
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
static void Routing(netType nettype);
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
bool SetIF(XrdNetAddrInfo *src, const char *ifList, int port=0,
netType nettype=netDefault, const char *xName=0);
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
static bool SetIFNames(char *ifnames);
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
static void SetMsgs(XrdSysError *erp);
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
static void SetRPIPA(bool rval);
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
XrdNetIF() : ifBuff(0), ifMask(0), ifAvail(0) {}
~XrdNetIF() {if (ifBuff) free(ifBuff);}
private:
struct ifAddrs
{short hALen;
short hDLen;
bool ipV6;
bool prvt;
char hAddr[64]; // address
char hDest[64]; // address possibly in deprecated format
};
bool GenAddrs(ifAddrs &ifTab, XrdNetAddrInfo *src);
bool GenAddrs(ifAddrs &ifTab, const char *hName, bool wantV6);
bool GenIF(XrdNetAddrInfo **src, int srcnum, const char *xName=0);
static const
char *GetDomain();
static
bool IsOkName(const char *ifn, short &ifIdx);
void SetIFPP();
bool SetIF64(bool retVal);
static
bool V4LinkLocal(struct sockaddr *saP);
struct ifData
{
short iLen;
char iVal[6]; // Actually of size iLen
ifData() : iLen(0) {*iVal = 0;}
~ifData() {}
};
ifData *ifName[ifMax];
ifData *ifDest[ifMax];
bool ifxDNS[ifMax];
char *ifBuff;
struct pInfo {char len;
char val[7]; // Contains ":12345\0"
pInfo() : len(0) {*val = 0;}
} portSfx;
int ifPort;
short ifRoute;
char ifMask;
char ifAvail;
static
XrdSysError *eDest;
static
const char *myDomain;
static char *ifCfg[2];
static
const char *ifTName[ifMax];
static
const char *ifMaskVec;
static
netType netRoutes;
static int dfPort;
static ifData ifNull;
static bool rPIPA;
};
#endif
Display
void Display()
Definition XrdCks.cc:56
XrdNetAddrInfo
Definition XrdNetAddrInfo.hh:54
XrdNetIF::haveNoGI
static const int haveNoGI
ifList == 0 && getifaddrs() is not supported
Definition XrdNetIF.hh:148
XrdNetIF::Mask
char Mask()
Definition XrdNetIF.hh:242
XrdNetIF::SetIF
bool SetIF(XrdNetAddrInfo *src, const char *ifList, int port=0, netType nettype=netDefault, const char *xName=0)
Definition XrdNetIF.cc:688
XrdNetIF::haveIPv4
static const int haveIPv4
ifList == 0 && non-local ipv4 i/f found (or'd)
Definition XrdNetIF.hh:150
XrdNetIF::SetRPIPA
static void SetRPIPA(bool rval)
Definition XrdNetIF.cc:876
XrdNetIF::GetName
int GetName(char *nbuff, int &nport, ifType ifT=PublicV6)
Definition XrdNetIF.hh:120
XrdNetIF::InDomain
static bool InDomain(XrdNetAddrInfo *epaddr)
Definition XrdNetIF.cc:606
XrdNetIF::XrdNetIF
XrdNetIF()
Constructor and Destructor.
Definition XrdNetIF.hh:385
XrdNetIF::GetIF
static int GetIF(XrdOucTList **ifList, const char **eText=0)
Definition XrdNetIF.cc:413
XrdNetIF::Routing
static void Routing(netType nettype)
Definition XrdNetIF.cc:670
XrdNetIF::Mask
static char Mask(ifType ifT)
Definition XrdNetIF.hh:252
XrdNetIF::Name
static const char * Name(ifType ifT)
Definition XrdNetIF.hh:266
XrdNetIF::Port
int Port()
Definition XrdNetIF.hh:276
XrdNetIF::~XrdNetIF
~XrdNetIF()
Definition XrdNetIF.hh:387
XrdNetIF::SetMsgs
static void SetMsgs(XrdSysError *erp)
Definition XrdNetIF.cc:870
XrdNetIF::HasDest
bool HasDest(ifType ifT=PublicV6)
Definition XrdNetIF.hh:221
XrdNetIF::PortDefault
static void PortDefault(int pnum=1094)
Definition XrdNetIF.cc:664
XrdNetIF::havePub6
static const int havePub6
ifList == 0 && public ipv6 i/f found (or'd)
Definition XrdNetIF.hh:160
XrdNetIF::GetIFType
static ifType GetIFType(bool conIPv4, bool hasIP64, bool pvtIP)
Definition XrdNetIF.hh:204
XrdNetIF::SetIFNames
static bool SetIFNames(char *ifnames)
Definition XrdNetIF.cc:763
XrdNetIF::GetName
int GetName(const char *&name, ifType ifT=PublicV6)
Definition XrdNetIF.hh:102
XrdNetIF::havePub4
static const int havePub4
ifList == 0 && public ipv4 i/f found (or'd)
Definition XrdNetIF.hh:158
XrdNetIF::GetDest
int GetDest(char *dest, int dlen, ifType ifT=PublicV6, bool prefn=false)
Definition XrdNetIF.cc:389
XrdNetIF::haveIPv6
static const int haveIPv6
ifList == 0 && non-local ipv6 i/f found (or'd)
Definition XrdNetIF.hh:152
XrdNetIF::ifType
ifType
The enum that is used to index into ifData to get appropriate interface.
Definition XrdNetIF.hh:64
XrdNetIF::PrivateV4
@ PrivateV4
Definition XrdNetIF.hh:65
XrdNetIF::ifMax
@ ifMax
Definition XrdNetIF.hh:74
XrdNetIF::Public46
@ Public46
Definition XrdNetIF.hh:70
XrdNetIF::PublicV4
@ PublicV4
Definition XrdNetIF.hh:64
XrdNetIF::Private64
@ Private64
Definition XrdNetIF.hh:73
XrdNetIF::ifAny
@ ifAny
Definition XrdNetIF.hh:75
XrdNetIF::Public64
@ Public64
Definition XrdNetIF.hh:72
XrdNetIF::PrivateIF
@ PrivateIF
Definition XrdNetIF.hh:68
XrdNetIF::ifNum
@ ifNum
Definition XrdNetIF.hh:69
XrdNetIF::Private46
@ Private46
Definition XrdNetIF.hh:71
XrdNetIF::PrivateV6
@ PrivateV6
Definition XrdNetIF.hh:67
XrdNetIF::PublicV6
@ PublicV6
Definition XrdNetIF.hh:66
XrdNetIF::havePrv6
static const int havePrv6
ifList == 0 && private ipv6 i/f found (or'd)
Definition XrdNetIF.hh:156
XrdNetIF::Privatize
static void Privatize(ifType &x)
Definition XrdNetIF.hh:284
XrdNetIF::netType
netType
Definition XrdNetIF.hh:318
XrdNetIF::netSplit
@ netSplit
Definition XrdNetIF.hh:318
XrdNetIF::netDefault
@ netDefault
Definition XrdNetIF.hh:318
XrdNetIF::netCommon
@ netCommon
Definition XrdNetIF.hh:318
XrdNetIF::netLocal
@ netLocal
Definition XrdNetIF.hh:318
XrdNetIF::havePrv4
static const int havePrv4
ifList == 0 && private ipv4 i/f found (or'd)
Definition XrdNetIF.hh:154
XrdOucTList
Definition XrdOucTList.hh:42
XrdSysError
Definition XrdSysError.hh:90