00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef __EAP_SERVER_FSM_H__
00043 #define __EAP_SERVER_FSM_H__
00044
00045 #include "framework.h"
00046 #include "diameter_eap_parser.hxx"
00047
00048 #ifdef WIN32
00049 #if defined(DIAMETER_EAP_SERVER_EXPORT)
00050 #define DIAMETER_EAP_SERVER_EXPORTS __declspec(dllexport)
00051 #else
00052 #define DIAMETER_EAP_SERVER_EXPORTS __declspec(dllimport)
00053 #endif
00054 #else
00055 #define DIAMETER_EAP_SERVER_EXPORTS
00056 #define DIAMETER_EAP_SERVER_EXPORTS
00057 #endif
00058
00059 typedef AAA_JobHandle<AAA_GroupedJob> DiameterJobHandle;
00060
00061 class DiameterEapServerSession;
00062
00098 class DIAMETER_EAP_SERVER_EXPORTS DiameterEapServerStateMachine
00099 : public AAA_StateMachine<DiameterEapServerStateMachine>,
00100 public AAA_EventQueueJob
00101 {
00102 friend class DiameterJobMultiplexor;
00103
00104 public:
00106 DiameterEapServerStateMachine(DiameterEapServerSession& s,
00107 DiameterJobHandle &h);
00108
00109 ~DiameterEapServerStateMachine()
00110 {
00111 handle.Job().Remove(this);
00112 }
00113
00114 enum {
00115 EvSgStart,
00116 EvRxEapRequest,
00117 EvRxEapSuccess,
00118 EvRxEapFailure,
00119 EvSgAuthorizationSuccess,
00120 EvSgAuthorizationFailure,
00121 EvRxDER,
00122 EvSgSessionTimeout,
00123 EvSgAuthLifetimeTimeout,
00124 EvSgAuthGracePeriodTimeout,
00125 EvSgTimeout,
00126 EvSgDisconnect,
00127 EvSgValidDER,
00128 EvSgInvalidDER
00129 };
00130
00132 inline void Notify(AAA_Event ev) throw (int) {
00133
00134 if (AAA_EventQueueJob::Enqueue(ev) <= 0)
00135 Abort();
00136
00137 if (handle.Job().Schedule(this) < 0)
00138 Abort();
00139 }
00140
00143 inline DiameterEapServerSession& Session() { return session; }
00144
00147 virtual void Abort()=0;
00148
00151 virtual void ForwardEapResponse(std::string &eapMsg)=0;
00152
00155 void SignalContinue(std::string &eapMsg);
00156
00160 void SignalSuccess(std::string &eapMsg);
00161
00165 void SignalFailure(std::string &eapMsg);
00166
00169 void SendDEA();
00170
00175 bool CheckDER();
00176
00184 virtual bool Authorize();
00185
00187 bool AuthorizationDone() { return authorizationDone; }
00188
00189 inline AAA_JobData& JobData() { return *handle.Job().Data(); }
00190
00191 template <class T> inline T& JobData(Type2Type<T>)
00192 { return (T&)*handle.Job().Data(); }
00193
00195 virtual bool AuthorizeOriginHost
00196 (const diameter_identity_t &originHost)
00197 {
00198 return true;
00199 }
00200
00202 virtual bool AuthorizeOriginRealm
00203 (const diameter_identity_t &originRealm)
00204 {
00205 return true;
00206 }
00207
00209 virtual bool AuthorizeMultiRoundTimeOut
00210 (AAA_ScholarAttribute<diameter_unsigned32_t> &multiRoundTimeout)
00211 {
00212 return true;
00213 }
00214
00216 virtual bool AuthorizeServiceType
00217 (AAA_ScholarAttribute<diameter_enumerated_t> &serviceType)
00218 {
00219 return true;
00220 }
00221
00223 virtual bool AuthorizeServiceType
00224 (const diameter_enumerated_t &serviceType1,
00225 AAA_ScholarAttribute<diameter_enumerated_t> &serviceType2)
00226 {
00227 return true;
00228 }
00229
00231 virtual bool AuthorizeClass
00232 (AAA_VectorAttribute<diameter_octetstring_t> &Class)
00233 {
00234 return true;
00235 }
00236
00238 virtual bool AuthorizeClass
00239 (const std::vector<diameter_octetstring_t> &Class1,
00240 AAA_VectorAttribute<diameter_octetstring_t> &Class2)
00241 {
00242 return true;
00243 }
00244
00249 virtual bool AuthorizeConfigurationToken
00250 (AAA_VectorAttribute<diameter_octetstring_t> &configurationToken)
00251 {
00252 return true;
00253 }
00254
00256 virtual bool AuthorizeAcctInterimInterval
00257 (AAA_ScholarAttribute<diameter_unsigned32_t> &acctInterimInterval)
00258 {
00259 return true;
00260 }
00261
00263 virtual bool AuthorizeIdleTimeout
00264 (AAA_ScholarAttribute<diameter_unsigned32_t> &idleTimeout)
00265 {
00266 return true;
00267 }
00268
00270 virtual bool AuthorizeAuthorizationLifetime
00271 (AAA_ScholarAttribute<diameter_unsigned32_t> &authorizationLifetime)
00272 {
00273 return true;
00274 }
00275
00277 virtual bool AuthorizeAuthGracePeriod
00278 (AAA_ScholarAttribute<diameter_unsigned32_t> &authGracePeriod)
00279 {
00280 return true;
00281 }
00282
00284 virtual bool AuthorizeAuthSessionState
00285 (AAA_ScholarAttribute<diameter_enumerated_t> &authSessionState)
00286 {
00287 return true;
00288 }
00289
00291 virtual bool AuthorizeReAuthRequestType
00292 (AAA_ScholarAttribute<diameter_enumerated_t> &reAuthRequestType)
00293 {
00294 return true;
00295 }
00296
00298 virtual bool AuthorizeSessionTimeout
00299 (AAA_ScholarAttribute<diameter_unsigned32_t> &sessionTimeout)
00300 {
00301 return true;
00302 }
00303
00305 virtual bool AuthorizeFilterId
00306 (AAA_VectorAttribute<diameter_utf8string_t> &filterId)
00307 {
00308 return true;
00309 }
00310
00312 virtual bool AuthorizePortLimit
00313 (AAA_ScholarAttribute<diameter_unsigned32_t> &portLimit)
00314 {
00315 return true;
00316 }
00317
00319 virtual bool AuthorizePortLimit
00320 (const diameter_unsigned32_t &portLimit1,
00321 AAA_ScholarAttribute<diameter_unsigned32_t> &portLimit2)
00322 {
00323 return true;
00324 }
00325
00327 virtual bool AuthorizeCallbackId
00328 (AAA_ScholarAttribute<diameter_utf8string_t> &callbackId)
00329 {
00330 return true;
00331 }
00332
00334 virtual bool AuthorizeCallbackNumber
00335 (AAA_ScholarAttribute<diameter_utf8string_t> &callbackNumber)
00336 {
00337 return true;
00338 }
00339
00341 virtual bool AuthorizeCallbackNumber
00342 (const diameter_utf8string_t &callbackNumber1,
00343 AAA_ScholarAttribute<diameter_utf8string_t> &callbackNumber2)
00344 {
00345 return true;
00346 }
00347
00349 virtual bool AuthorizeFramedAppletalkLink
00350 (AAA_ScholarAttribute<diameter_unsigned32_t> &framedAppletalkLink)
00351 {
00352 return true;
00353 }
00354
00356 virtual bool AuthorizeFramedAppletalkZone
00357 (AAA_ScholarAttribute<diameter_octetstring_t> &framedAppletalkZone)
00358 {
00359 return true;
00360 }
00361
00363 virtual bool AuthorizeFramedAppletalkNetwork
00364 (AAA_VectorAttribute<diameter_unsigned32_t> &framedAppletalkNetwork)
00365 {
00366 return true;
00367 }
00368
00370 virtual bool AuthorizeFramedCompression
00371 (AAA_VectorAttribute<diameter_enumerated_t> &framedCompression)
00372 {
00373 return true;
00374 }
00375
00377 virtual bool AuthorizeFramedCompression
00378 (const AAA_VectorAttribute<diameter_enumerated_t> &framedCompression1,
00379 AAA_VectorAttribute<diameter_enumerated_t> &framedCompression2)
00380 {
00381 return true;
00382 }
00383
00385 virtual bool AuthorizeFramedInterfaceId
00386 (AAA_ScholarAttribute<diameter_unsigned64_t> &framedInterfaceId)
00387 {
00388 return true;
00389 }
00390
00392 virtual bool AuthorizeFramedInterfaceId
00393 (const diameter_unsigned64_t &framedInterfaceId1,
00394 AAA_ScholarAttribute<diameter_unsigned64_t> &framedInterfaceId2)
00395 {
00396 return true;
00397 }
00398
00400 virtual bool AuthorizeFramedIpAddress
00401 (AAA_ScholarAttribute<diameter_octetstring_t> &framedIpAddress)
00402 {
00403 return true;
00404 }
00405
00407 virtual bool AuthorizeFramedIpAddress
00408 (const diameter_octetstring_t &framedIpAddress1,
00409 AAA_ScholarAttribute<diameter_octetstring_t> &framedIpAddress2)
00410 {
00411 return true;
00412 }
00413
00415 virtual bool AuthorizeFramedIpv6Prefix
00416 (AAA_VectorAttribute<diameter_octetstring_t> &framedIpv6Prefix)
00417 {
00418 return true;
00419 }
00420
00422 virtual bool AuthorizeFramedIpv6Prefix
00423 (const std::vector<diameter_octetstring_t> &framedIpv6Prefix1,
00424 AAA_VectorAttribute<diameter_octetstring_t> &framedIpv6Prefix2)
00425 {
00426 return true;
00427 }
00428
00430 virtual bool AuthorizeFramedIpv6Pool
00431 (AAA_ScholarAttribute<diameter_octetstring_t> &framedIpv6Pool)
00432 {
00433 return true;
00434 }
00435
00437 virtual bool AuthorizeFramedPool
00438 (AAA_ScholarAttribute<diameter_octetstring_t> &framedPool)
00439 {
00440 return true;
00441 }
00442
00444 virtual bool AuthorizeFramedIpv6Route
00445 (AAA_VectorAttribute<diameter_utf8string_t> &framedIpv6Route)
00446 {
00447 return true;
00448 }
00449
00451 virtual bool AuthorizeFramedRoute
00452 (AAA_VectorAttribute<diameter_utf8string_t> &framedRoute)
00453 {
00454 return true;
00455 }
00456
00458 virtual bool AuthorizeFramedIpNetmask
00459 (AAA_ScholarAttribute<diameter_octetstring_t> &framedIpNetmask)
00460 {
00461 return true;
00462 }
00463
00465 virtual bool AuthorizeFramedIpNetmask
00466 (const diameter_octetstring_t &framedIpNetmask1,
00467 AAA_ScholarAttribute<diameter_octetstring_t> &framedIpNetmask2)
00468 {
00469 return true;
00470 }
00471
00473 virtual bool AuthorizeFramedIpxNetwork
00474 (AAA_ScholarAttribute<diameter_utf8string_t> &framedIpxNetwork)
00475 {
00476 return true;
00477 }
00478
00480 virtual bool AuthorizeFramedMtu
00481 (AAA_ScholarAttribute<diameter_unsigned32_t> &framedMtu)
00482 {
00483 return true;
00484 }
00485
00487 virtual bool AuthorizeFramedMtu
00488 (const diameter_unsigned32_t &framedMtu1,
00489 AAA_ScholarAttribute<diameter_unsigned32_t> &framedMtu2)
00490 {
00491 return true;
00492 }
00493
00495 virtual bool AuthorizeFramedProtocol
00496 (AAA_ScholarAttribute<diameter_enumerated_t> &framedProtocol)
00497 {
00498 return true;
00499 }
00500
00502 virtual bool AuthorizeFramedProtocol
00503 (const diameter_enumerated_t &framedProtocol1,
00504 AAA_ScholarAttribute<diameter_enumerated_t> &framedProtoco2)
00505 {
00506 return true;
00507 }
00508
00510 virtual bool AuthorizeFramedRouting
00511 (AAA_ScholarAttribute<diameter_enumerated_t> &framedRouting)
00512 {
00513 return true;
00514 }
00515
00517 virtual bool AuthorizeNasFilterRule
00518 (AAA_VectorAttribute<diameter_ipfilter_rule_t> &nasFilterRule)
00519 {
00520 return true;
00521 }
00522
00524 virtual bool AuthorizeTunneling
00525 (AAA_VectorAttribute<tunneling_t> &tunneling)
00526 {
00527 return true;
00528 }
00529
00531 virtual bool AuthorizeTunneling
00532 (const std::vector<tunneling_t> &tunneling1,
00533 AAA_VectorAttribute<tunneling_t> &tunneling2)
00534 {
00535 return true;
00536 }
00537
00539 virtual bool AuthorizeEapMasterSessionKey
00540 (AAA_ScholarAttribute<diameter_octetstring_t> &eapMasterSessionKey)
00541 {
00542 return true;
00543 }
00544
00546 virtual bool AuthorizeAccountingEapAuthMethod
00547 (AAA_VectorAttribute<diameter_unsigned64_t> &accountingEapAuthMethod)
00548 {
00549 return true;
00550 }
00551
00554 virtual void SetReplyMessage
00555 (AAA_VectorAttribute<diameter_utf8string_t> &replyMessage,
00556 const diameter_unsigned32_t &resultCode)
00557 {}
00558
00560 virtual void SetReissuedEapPayload
00561 (AAA_ScholarAttribute<diameter_octetstring_t> &reissuedEapPayload)
00562 {}
00563
00565 virtual bool ValidateUserName
00566 (const diameter_utf8string_t &userName)
00567 {
00568 return false;
00569 }
00570
00573 virtual bool ValidateState
00574 (const diameter_octetstring_t &stateInDER,
00575 const diameter_octetstring_t &stateInDEA)
00576 {
00577 return false;
00578 }
00579
00581 virtual void SetState(AAA_ScholarAttribute<diameter_octetstring_t> &state)
00582 {
00583 }
00584
00585 DER_Data& DER() { return derData; }
00586 DEA_Data& DEA() { return deaData; }
00587
00588 protected:
00589
00590 private:
00592 int Schedule(AAA_Job*, size_t=1) { return (-1); }
00593
00595 inline int Serve()
00596 {
00597 if (!AAA_EventQueueJob::ExistBacklog())
00598 {
00599 AAA_LOG(LM_ERROR, "%N: no backlog to serve.");
00600 return 0;
00601 }
00602
00603
00604 AAA_Event ev;
00605 AAA_EventQueueJob::Dequeue(ev);
00606
00607 bool existBacklog = AAA_EventQueueJob::ExistBacklog();
00608
00609
00610 Event(ev);
00611 return existBacklog ? 1 : 0;
00612 }
00613
00614 DiameterEapServerSession& session;
00616 DiameterJobHandle handle;
00617
00618 bool authorizationDone;
00619
00621 DER_Data derData;
00622 DEA_Data deaData;
00623 };
00624
00625 #endif