XRootD
Loading...
Searching...
No Matches
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{}

Referenced by Config().

+ Here is the caller graph for this function:

Member Function Documentation

◆ Begin() [1/2]

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

Implements XrdNetPMark.

Definition at line 235 of file XrdNetPMarkCfg.cc.

238{
239
240// If we are allowed to use the flow label set on the incoming connection
241// then try to do so. This is only valid for IPv6 connections. Currently,
242// this is not implemented.
243//
244// if (useFLbl && addrInfo.isIPType(XrdNetAddrInfo::IPv6)
245// && !addrInfo.isMapped())
246// {
247// TODO???
248// }
249
250// If we are allowed to use firefly, return a firefly handle
251//
252 if (handle.Valid() && useFFly)
253 {XrdNetPMarkFF *pmFF = new XrdNetPMarkFF(handle, tident);
254 if (pmFF->Start(addrInfo)) return pmFF;
255 delete pmFF;
256 }
257
258// All done, nothing will be pmarked
259//
260 return 0;
261}
#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 XrdOucString altApp;
182 int eCode, aCode;
183
184// If we need to screen out domains, do that
185//
186 if (chkDom)
187 {XrdNetAddrInfo &addrInfo = *client.addrInfo;
188 char domType = (addrInfo.isPrivate() ? domLcl : domRmt);
189 if (domType == domRmt && *myDomain)
190 {const char *urName = addrInfo.Name();
191 if (urName && XrdNetAddrInfo::isHostName(urName))
192 {const char *dot = index(urName, '.');
193 if (dot && !strcmp(dot+1, myDomain)) domType = domLcl;
194 }
195 }
196 if (domType != chkDom)
197 {DBGID(client.tident, "Skipping sending flow info; unwanted domain");
198 return 0;
199 }
200 }
201
202// Now get the experiment and activity code. If we can't get at least the
203// experiment code, then proceed without marking the flow.
204//
205 if (!getCodes(client, path, cgi, eCode, aCode))
206 {TRACE("Unable to determine experiment; flow not marked.");
207 return 0;
208 }
209
210// Obtain the appname overridefrom the cgi
211//
212 if (cgi) // 01234567890123
213 {const char *apP = strstr(cgi, "pmark.appname=");
214 if (apP)
215 {apP += 14;
216 const char* aP = apP;
217 while(*aP && *aP != '&') aP++;
218 int apLen = aP - apP;
219 if (apLen > 0)
220 {altApp = "";
221 altApp.insert(apP, 0, apLen);
222 app = altApp.c_str();
223 }
224 }
225 }
226
227// Continue with successor function to complete the logic
228//
229 XrdNetPMark::Handle handle(app, eCode, aCode);
230 return Begin(*client.addrInfo, handle, client.tident);
231}
#define EPName(ep)
#define DBGID(tid, txt)
#define TRACE(act, x)
Definition XrdTrace.hh:63
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
void insert(const int i, int start=-1)
const char * c_str() const
static const int domLcl
const char * myDomain
static const int domRmt

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

Referenced by Begin().

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

◆ Config()

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

Definition at line 267 of file XrdNetPMarkCfg.cc.

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

References XrdNetPMarkCfg(), XrdNetPMarkConfig::Cfg, XrdNetPMarkConfig::chkDom, XrdNetPMarkConfig::CfgInfo::defsFile, XrdNetPMarkConfig::doDebug, XrdNetPMarkConfig::doTrace, eDest, 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(), and Parse().

+ 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 966 of file XrdNetPMarkCfg.cc.

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