XRootD
XrdNetPMarkCfg Class Reference

#include <XrdNetPMarkCfg.hh>

+ Inheritance diagram for XrdNetPMarkCfg:
+ Collaboration diagram for XrdNetPMarkCfg:

Public Member Functions

 XrdNetPMarkCfg ()
 
XrdNetPMark::HandleBegin (XrdNetAddrInfo &addr, XrdNetPMark::Handle &handle, const char *tident) override
 
XrdNetPMark::HandleBegin (XrdSecEntity &Client, const char *path=0, const char *cgi=0, const char *app=0) override
 
- Public Member Functions inherited from XrdNetPMark
 XrdNetPMark ()
 
virtual ~XrdNetPMark ()
 

Static Public Member Functions

static XrdNetPMarkConfig (XrdSysError *eLog, XrdScheduler *sched, XrdSysTrace *trc, bool &fatal)
 
static int Parse (XrdSysError *eLog, XrdOucStream &Config)
 
- Static Public Member Functions inherited from XrdNetPMark
static bool getEA (const char *cgi, int &ecode, int &acode)
 

Additional Inherited Members

- Static Public Attributes inherited from XrdNetPMark
static const int maxTotID = 65535
 
static const int minTotID = 65
 
- Static Protected Attributes inherited from XrdNetPMark
static const int btsActID = 6
 
static const int maxActID = maxTotID & mskActID
 
static const int maxExpID = maxTotID >> btsActID
 
static const int minActID = minTotID & mskActID
 
static const int minExpID = minTotID >> btsActID
 
static const int mskActID = 63
 

Detailed Description

Definition at line 43 of file XrdNetPMarkCfg.hh.

Constructor & Destructor Documentation

◆ XrdNetPMarkCfg()

XrdNetPMarkCfg::XrdNetPMarkCfg ( )
inline

Definition at line 61 of file XrdNetPMarkCfg.hh.

61 {}

Member Function Documentation

◆ Begin() [1/2]

XrdNetPMark::Handle * XrdNetPMarkCfg::Begin ( XrdNetAddrInfo addr,
XrdNetPMark::Handle handle,
const char *  tident 
)
overridevirtual

Implements XrdNetPMark.

Definition at line 217 of file XrdNetPMarkCfg.cc.

220 {
221 
222 // If we are allowed to use the flow label set on the incoming connection
223 // then try to do so. This is only valid for IPv6 connections. Currently,
224 // this is not implemented.
225 //
226 // if (useFLbl && addrInfo.isIPType(XrdNetAddrInfo::IPv6)
227 // && !addrInfo.isMapped())
228 // {
229 // TODO???
230 // }
231 
232 // If we are allowed to use firefly, return a firefly handle
233 //
234  if (handle.Valid() && useFFly)
235  {XrdNetPMarkFF *pmFF = new XrdNetPMarkFF(handle, tident);
236  if (pmFF->Start(addrInfo)) return pmFF;
237  delete pmFF;
238  }
239 
240 // All done, nothing will be pmarked
241 //
242  return 0;
243 }
#define tident
bool Start(XrdNetAddrInfo &addr)

References XrdNetPMarkFF::Start(), tident, XrdNetPMarkConfig::useFFly, and XrdNetPMark::Handle::Valid().

+ Here is the call graph for this function:

◆ Begin() [2/2]

XrdNetPMark::Handle * XrdNetPMarkCfg::Begin ( XrdSecEntity Client,
const char *  path = 0,
const char *  cgi = 0,
const char *  app = 0 
)
overridevirtual

Implements XrdNetPMark.

Definition at line 175 of file XrdNetPMarkCfg.cc.

179 {
180  EPName("PMBegin");
181  int eCode, aCode;
182 
183 // If we need to screen out domains, do that
184 //
185  if (chkDom)
186  {XrdNetAddrInfo &addrInfo = *client.addrInfo;
187  char domType = (addrInfo.isPrivate() ? domLcl : domRmt);
188  if (domType == domRmt && *myDomain)
189  {const char *urName = addrInfo.Name();
190  if (urName && XrdNetAddrInfo::isHostName(urName))
191  {const char *dot = index(urName, '.');
192  if (dot && !strcmp(dot+1, myDomain)) domType = domLcl;
193  }
194  }
195  if (domType != chkDom)
196  {DBGID(client.tident, "Skipping sending flow info; unwanted domain");
197  return 0;
198  }
199  }
200 
201 // Now get the experiment and activity code. If we can't get at least the
202 // experiment code, then proceed without marking the flow.
203 //
204  if (!getCodes(client, path, cgi, eCode, aCode))
205  {TRACE("Unable to determine experiment; flow not marked.");
206  return 0;
207  }
208 
209 // Continue with successor function to complete the logic
210 //
211  XrdNetPMark::Handle handle(app, eCode, aCode);
212  return Begin(*client.addrInfo, handle, client.tident);
213 }
#define TRACE(txt)
#define EPName(ep)
#define DBGID(tid, txt)
static bool isHostName(const char *name)
const char * Name(const char *eName=0, const char **eText=0)
XrdNetPMark::Handle * Begin(XrdSecEntity &Client, const char *path=0, const char *cgi=0, const char *app=0) override
static const int domLcl
const char * myDomain
static const int domRmt

References XrdSecEntity::addrInfo, XrdNetPMarkConfig::chkDom, DBGID, XrdNetPMarkConfig::domLcl, XrdNetPMarkConfig::domRmt, EPName, XrdNetAddrInfo::isHostName(), XrdNetAddrInfo::isPrivate(), XrdNetPMarkConfig::myDomain, XrdNetAddrInfo::Name(), XrdSecEntity::tident, and TRACE.

+ Here is the call graph for this function:

◆ Config()

XrdNetPMark * XrdNetPMarkCfg::Config ( XrdSysError eLog,
XrdScheduler sched,
XrdSysTrace trc,
bool &  fatal 
)
static

Definition at line 249 of file XrdNetPMarkCfg.cc.

251 {
252  class DelCfgInfo
253  {public: DelCfgInfo(CfgInfo *&cfg) : cfgInfo(cfg) {}
254  ~DelCfgInfo() {if (cfgInfo) {delete cfgInfo; cfgInfo = 0;}}
255  private:
256  CfgInfo *&cfgInfo;
257  } cleanup(Cfg);
258 
259 // If we have not been configured then simply retrn nil
260 //
261  if (!Cfg)
262  {useFFly = false;
263  return 0;
264  }
265 
266 // Save the message handler
267 //
268  eDest = eLog;
269  Sched = sched;
270  Trace = trc;
271  fatal = false;
272 
273 // If firefly is enabled, make sure we have an ffdest
274 //
275  if (useFFly < 0)
276  {if (ffPortD || ffPortO)
277  {useFFly = true;
278  if (!ffPortO) ffPortO = ffPORT;
279  } else {
280  useFFly = false;
281  eLog->Say("Config warning: firefly disabled; "
282  "configuration incomplete!");
283  return 0;
284  }
285  } else if (useFFly && !ffPortO) ffPortO = ffPORT;
286 
287 // Resolve trace and debug settings
288 //
289  if (doDebug) doTrace = true;
290 
291 // Check if we need a defsfile, if so, construct the map.
292 //
293  if (Cfg->x2aSet.size() == 0 && Cfg->x2eSet.size() == 0)
294  {if (Cfg->defsFile.length())
295  eLog->Say("Config warning: ignoring defsfile; "
296  "no mappings have been specified!");
297  useDefs = false;
298  } else {
299  if (!Cfg->defsFile.length())
300  {eLog->Say("Config invalid: pmark mappings cannot be resolved "
301  "without specifying defsfile!");
302  fatal = true;
303  return 0;
304  }
305  useDefs = true;
306  if (!ConfigDefs())
307  {if (useDefs)
308  {fatal = true;
309  return 0;
310  }
311  eLog->Say("Config warning: pmark ignoring defsfile; "
312  "unable to process and nofail is in effect!");
313  }
314  }
315 
316 // At this point either we still enabled or not. We can be disabled for a
317 // number of reasons and appropriate messages will have been issued.
318 //
319  if (!useFFly) return 0;
320 
321 // Create a netmsg object for firefly reporting if a dest was specified
322 //
323  bool aOK = false;
324  if (ffDest)
325  {XrdNetAddr spec;
326  char buff[1024];
327  const char *eTxt = spec.Set(ffDest, -ffPortD);
328  if (eTxt)
329  {snprintf(buff, sizeof(buff), "%s:%d; %s", ffDest, ffPortD, eTxt);
330  eLog->Emsg("Config", "pmark unable to create UDP tunnel to", buff);
331  useFFly = false;
332  fatal = true;
333  return 0;
334  }
335  if (spec.Format(buff, sizeof(buff)))
336  netMsg = new XrdNetMsg(eDest, buff, &aOK);
337  if (!aOK)
338  {eLog->Emsg("Config", "pmark unable to create UDP tunnel to", ffDest);
339  fatal = true;
340  delete netMsg;
341  netMsg = 0;
342  useFFly= false;
343  return 0;
344  }
345  }
346 
347 // Handle the firefly messages to origin
348 //
349  if (ffPortO)
350  {netOrg = new XrdNetMsg(eDest, 0, &aOK);
351  if (!aOK)
352  {eLog->Emsg("Config","pmark unable to create origin UDP tunnel");
353  fatal = true;
354  useFFly= false;
355  return 0;
356  }
357  }
358 
359 // Get our host name.
360 //
361  myHostName = XrdNetUtils::MyHostName("-"); // Never deleted!
362 
363 // Setup for domain checking
364 //
365  if (chkDom)
366  {const char *dot = index(myHostName, '.');
367  if (dot) myDomain = dot+1;
368  else eDest->Say("Config warning: Unable to determine local domain; "
369  " domain check restricted to IP address type!");
370  }
371 
372 // Finally, we are done. Return the packet markling stub.
373 //
374  return new XrdNetPMarkCfg;
375 }
int Format(char *bAddr, int bLen, fmtUse fmtType=fmtAuto, int fmtOpts=0)
const char * Set(const char *hSpec, int pNum=PortInSpec)
Definition: XrdNetAddr.cc:216
static char * MyHostName(const char *eName="*unknown*", const char **eText=0)
Definition: XrdNetUtils.cc:667
int length() const
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition: XrdSysError.cc:95
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)
Definition: XrdSysError.cc:141
XrdSysTrace * Trace
static const int ffPORT
XrdScheduler * Sched
XrdSysError * eDest
const char * myHostName
XrdSysError * eLog
std::set< std::string > x2eSet
std::set< std::string > x2aSet

References XrdNetPMarkConfig::Cfg, XrdNetPMarkConfig::chkDom, XrdNetPMarkConfig::CfgInfo::defsFile, XrdNetPMarkConfig::doDebug, XrdNetPMarkConfig::doTrace, XrdNetPMarkConfig::eDest, XrdOfsPrepGPIReal::eLog, XrdSysError::Emsg(), XrdNetPMarkConfig::ffDest, XrdNetPMarkConfig::ffPORT, XrdNetPMarkConfig::ffPortD, XrdNetPMarkConfig::ffPortO, XrdNetAddrInfo::Format(), XrdOucString::length(), XrdNetPMarkConfig::myDomain, XrdNetPMarkConfig::myHostName, XrdNetUtils::MyHostName(), XrdNetPMarkConfig::netMsg, XrdNetPMarkConfig::netOrg, XrdSysError::Say(), XrdNetPMarkConfig::Sched, XrdNetAddr::Set(), XrdNetPMarkConfig::Trace, XrdNetPMarkConfig::useDefs, XrdNetPMarkConfig::useFFly, XrdNetPMarkConfig::CfgInfo::x2aSet, and XrdNetPMarkConfig::CfgInfo::x2eSet.

Referenced by XrdXrootdProtocol::Configure().

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

◆ Parse()

int XrdNetPMarkCfg::Parse ( XrdSysError eLog,
XrdOucStream Config 
)
static

Definition at line 948 of file XrdNetPMarkCfg.cc.

949 {
950 // Parse pmark directive parameters:
951 //
952 // [[no]debug] [defsfile [[no]fail] {<path> | {curl | wget} [tmo] <url>}]
953 // [domain {any | local | remote}] [[no]fail] [ffdest <udpdest>]
954 // [ffecho <intvl>]
955 // [map2act <ename> {default | {role | user} <name>} <aname>]
956 // [map2exp {default | {path <path> | vo <vo>} <ename>}] [[no]trace]
957 // [use {[no]flowlabel | flowlabel+ff | [no]firefly | [no]scitag}
958 //
959 // <udpdest>: {origin[:<port>] | <host>[:port]} [,<udpdest>]
960 //
961  std::string name;
962  char *val;
963 
964 // If this is the first time here, allocate config info object
965 //
966  if (!Cfg) Cfg = new CfgInfo;
967 
968 // Make sure we have something to parse
969 //
970  if (!(val = Config.GetWord()))
971  {eLog->Say("Config invalid: pmark argument not specified"); return 1;}
972 
973 // Parse the directive options
974 //
975 do{if (!strcmp("debug", val) || !strcmp("nodebug", val))
976  {doDebug = (*val != 'n');
977  continue;
978  }
979 
980  if (!strcmp("defsfile", val))
981  {if (!(val = Config.GetWord()))
982  {eLog->Say("Config invalid: pmark defsfile value not specified");
983  return 1;
984  }
985 
986  if (*val == '/')
987  {Cfg->defsFile = val;
988  continue;
989  }
990 
991  if (strcmp("curl", val) && strcmp("wget", val))
992  {eLog->Say("Config invalid: unknown defsfile transfer agent '",val,"'");
993  return 1;
994  }
995  if (!XrdOucUtils::findPgm(val, Cfg->pgmPath))
996  {eLog->Say("Config invalid: defsfile transfer agent '",val,"' not found.");
997  return 1;
998  }
999 
1000  if (*val == 'c')
1001  {Cfg->pgmOpts[0]="-m"; Cfg->pgmOpts[2]="-s"; Cfg->pgmOpts[3]="-o";
1002  } else {
1003  Cfg->pgmOpts[0]="-T"; Cfg->pgmOpts[2]="-q"; Cfg->pgmOpts[3]="-O";
1004  }
1005 
1006  val = Config.GetWord();
1007  if (val && isdigit(*val))
1008  {if (XrdOuca2x::a2tm(*eLog,"defsfile timeout",val,&Cfg->defsTO,10))
1009  return 1;
1010  val = Config.GetWord();
1011  }
1012 
1013  if (!val) {eLog->Say("Config invalid: pmark defsfile url not specified");
1014  return 1;
1015  }
1016  Cfg->defsFile = val;
1017  continue;
1018  }
1019 
1020  if (!strcmp("domain", val))
1021  {if (!(val = Config.GetWord()))
1022  {eLog->Say("Config invalid: pmark domain value not specified");
1023  return 1;
1024  }
1025  if (!strcmp(val, "any" )
1026  || !strcmp(val, "all" )) chkDom = domAny;
1027  else if (!strcmp(val, "local" )) chkDom = domLcl;
1028  else if (!strcmp(val, "remote")) chkDom = domRmt;
1029  else {eLog->Say("Config invalid: pmark invalid domain determinant '",
1030  val, "'");
1031  return 1;
1032  }
1033  continue;
1034  }
1035 
1036  if (!strcmp("fail", val) || !strcmp("nofail", val))
1037  {noFail = (*val == 'n');
1038  continue;
1039  }
1040 
1041  // We accept 'origin' as a dest for backward compatibility. That is the
1042  // enforced default should 'use firefly' be specified.
1043  //
1044  if (!strcmp("ffdest", val))
1045  {const char *addtxt = "";
1046  char *colon, *comma;
1047  int xPort;
1048  val = Config.GetWord();
1049  do {if (!val || *val == 0 || *val == ',' || *val == ':')
1050  {eLog->Say("Config invalid: pmark ffdest value not specified",
1051  addtxt); return 1;
1052  }
1053  if ((comma = index(val, ','))) *comma++ = 0;
1054  if ((colon = index(val, ':')))
1055  {*colon++ = 0;
1056  if ((xPort = XrdOuca2x::a2p(*eLog, "udp", colon, false)) <= 0)
1057  return 1;
1058  } else xPort = ffPORT;
1059  if (!strcmp(val, "origin")) ffPortO = xPort;
1060  else {if (ffDest) free(ffDest);
1061  ffDest = strdup(val);
1062  ffPortD = xPort;
1063  }
1064  addtxt = " after comma";
1065  } while((val = comma));
1066  if (useFFly < 0) useFFly = 1;
1067  continue;
1068  }
1069 
1070  if (!strcmp("ffecho", val))
1071  {if (!(val = Config.GetWord()))
1072  {eLog->Say("Config invalid: pmark ffecho value not specified");
1073  return 1;
1074  }
1075  if (XrdOuca2x::a2tm(*eLog,"ffecho interval", val, &ffEcho, 0)) return 1;
1076  if (ffEcho < 30) ffEcho = 0;
1077  continue;
1078  }
1079 
1080  if (!strcmp("map2act", val))
1081  {if (!(val = Config.GetWord()))
1082  {eLog->Say("Config invalid: pmark activity experiment not specified");
1083  return 1;
1084  }
1085  name = val;
1086 
1087  if (!(val = Config.GetWord()))
1088  {eLog->Say("Config invalid: pmark activity determinant not specified");
1089  return 1;
1090  }
1091 
1092  const char *adet;
1093  if (!strcmp(val, "default")) adet = "dflt";
1094  else if (!strcmp(val, "role")) adet = "role";
1095  else if (!strcmp(val, "user")) adet = "user";
1096  else {eLog->Say("Config invalid: pmark invalid activity determinant '",
1097  val, "'");
1098  return 1;
1099  }
1100  name += ' '; name += val;
1101 
1102  if (*adet != 'd' && !(val = Config.GetWord()))
1103  {eLog->Say("Config invalid: pmark activity", adet, "not specified");
1104  return 1;
1105  }
1106  name += ' '; name += val;
1107 
1108  if (!(val = Config.GetWord()))
1109  {eLog->Say("Config invalid: pmark", adet, "activity not specified");
1110  return 1;
1111  }
1112  name += ' '; name += val;
1113 
1114  Cfg->x2aSet.insert(name);
1115  continue;
1116  }
1117 
1118  if (!strcmp("map2exp", val))
1119  {if (!(val = Config.GetWord()))
1120  {eLog->Say("Config invalid: pmark map2exp type not specified");
1121  return 1;
1122  }
1123  if (strcmp("default", val) && strcmp("path", val)
1124  && strcmp("vo", val) && strcmp("vorg", val))
1125  {eLog->Say("Config invalid: invalid pmark map2exp type, '",val,"'.");
1126  return 1;
1127  }
1128  name = val;
1129 
1130  if (*val != 'd' && !(val = Config.GetWord()))
1131  {eLog->Say("Config invalid: pmark map2exp ", name.c_str(),
1132  "not specified");
1133  return 1;
1134  }
1135  name += ' '; name += val;
1136 
1137  if (!(val = Config.GetWord()))
1138  {eLog->Say("Config invalid: pmark map2exp expirement not specified");
1139  return 1;
1140  }
1141  name += ' '; name += val;
1142 
1143  Cfg->x2eSet.insert(name);
1144  continue;
1145  }
1146 
1147  if (!strcmp("trace", val) || !strcmp("notrace", val))
1148  {doTrace = (*val != 'n');
1149  continue;
1150  }
1151 
1152  if (!strcmp("use", val))
1153  {if (!(val = Config.GetWord()))
1154  {eLog->Say("Config invalid: pmark use argument not specified");
1155  return 1;
1156  }
1157  bool argOK = false;
1158  char *arg;
1159  do {bool theval = strncmp(val, "no", 2) != 0;
1160  arg = (!theval ? val += 2 : val);
1161  if (!strcmp("flowlabel", arg))
1162  {useFLbl = theval; addFLFF = false; argOK = true;}
1163  else if (!strcmp("flowlabel+ff", arg))
1164  {addFLFF = useFLbl = theval; argOK = true;}
1165  else if (!strcmp("firefly", arg))
1166  {useFFly = (theval ? 1 : 0); argOK = true;}
1167  else if (!strcmp("scitag", arg)) {useSTag = theval; argOK = true;}
1168  else if (argOK) {Config.RetToken(); break;}
1169  else {eLog->Say("Config invalid: 'use ",val,"' is invalid");
1170  return 1;
1171  }
1172  } while((val = Config.GetWord()));
1173  if (!val) break;
1174  continue;
1175  }
1176 
1177  eLog->Say("Config warning: ignoring unknown pmark argument'",val,"'.");
1178 
1179  } while ((val = Config.GetWord()));
1180 
1181  return 0;
1182 }
static XrdNetPMark * Config(XrdSysError *eLog, XrdScheduler *sched, XrdSysTrace *trc, bool &fatal)
static bool findPgm(const char *pgm, XrdOucString &path)
Definition: XrdOucUtils.cc:354
static int a2tm(XrdSysError &, const char *emsg, const char *item, int *val, int minv=-1, int maxv=-1)
Definition: XrdOuca2x.cc:288
static int a2p(XrdSysError &, const char *ptype, const char *val, bool anyOK=true)
Definition: XrdOuca2x.cc:140
static const int domAny
const char * pgmOpts[pgmOptN]

References XrdOuca2x::a2p(), XrdOuca2x::a2tm(), XrdNetPMarkConfig::addFLFF, XrdNetPMarkConfig::Cfg, XrdNetPMarkConfig::chkDom, XrdCms::Config, XrdNetPMarkConfig::CfgInfo::defsFile, XrdNetPMarkConfig::CfgInfo::defsTO, XrdNetPMarkConfig::doDebug, XrdNetPMarkConfig::domAny, XrdNetPMarkConfig::domLcl, XrdNetPMarkConfig::domRmt, XrdNetPMarkConfig::doTrace, XrdOfsPrepGPIReal::eLog, XrdNetPMarkConfig::ffDest, XrdNetPMarkConfig::ffEcho, XrdNetPMarkConfig::ffPORT, XrdNetPMarkConfig::ffPortD, XrdNetPMarkConfig::ffPortO, XrdOucUtils::findPgm(), XrdNetPMarkConfig::noFail, XrdNetPMarkConfig::CfgInfo::pgmOpts, XrdNetPMarkConfig::CfgInfo::pgmPath, XrdSysError::Say(), XrdNetPMarkConfig::useFFly, XrdNetPMarkConfig::useFLbl, XrdNetPMarkConfig::useSTag, XrdNetPMarkConfig::CfgInfo::x2aSet, and XrdNetPMarkConfig::CfgInfo::x2eSet.

+ Here is the call graph for this function:

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