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 __NASREQ_SERVER_FSM_H__
00043 #define __NASREQ_SERVER_FSM_H__
00044
00045 #include "framework.h"
00046 #include "diameter_nasreq_parser.hxx"
00047 #include "diameter_nasreq_authinfo.hxx"
00048
00049 #ifdef WIN32
00050 #if defined(DIAMETER_NASREQ_SERVER_EXPORT)
00051 #define DIAMETER_NASREQ_SERVER_EXPORTS __declspec(dllexport)
00052 #else
00053 #define DIAMETER_NASREQ_SERVER_EXPORTS __declspec(dllimport)
00054 #endif
00055 #else
00056 #define DIAMETER_NASREQ_SERVER_EXPORTS
00057 #define DIAMETER_NASREQ_SERVER_EXPORTS
00058 #endif
00059
00060 typedef AAA_JobHandle<AAA_GroupedJob> DiameterNasreqJobHandle;
00061
00062 class DiameterNasreqServerSession;
00063
00098 class DIAMETER_NASREQ_SERVER_EXPORTS DiameterNasreqServerStateMachine
00099 : public AAA_StateMachine<DiameterNasreqServerStateMachine>,
00100 public AAA_EventQueueJob
00101 {
00102 public:
00104 DiameterNasreqServerStateMachine(DiameterNasreqServerSession& s,
00105 DiameterNasreqJobHandle &h);
00106
00107 ~DiameterNasreqServerStateMachine()
00108 {
00109 handle.Job().Remove(this);
00110 }
00111
00112 enum {
00113 EvSgStart,
00114 EvRxAuthContinue,
00115 EvRxAuthSuccess,
00116 EvRxAuthFailure,
00117 EvSgAuthorizationSuccess,
00118 EvSgAuthorizationFailure,
00119 EvRxAA_Request,
00120 EvSgSessionTimeout,
00121 EvSgAuthLifetimeTimeout,
00122 EvSgAuthGracePeriodTimeout,
00123 EvSgTimeout,
00124 EvSgDisconnect,
00125 EvSgValidAA_Request,
00126 EvSgInvalidAA_Request
00127 };
00128
00130 inline void Notify(AAA_Event ev) throw (int) {
00131
00132 if (AAA_EventQueueJob::Enqueue(ev) <= 0)
00133 Abort();
00134
00135 if (handle.Job().Schedule(this) < 0)
00136 Abort();
00137 }
00138
00141 inline DiameterNasreqServerSession& Session() { return session; }
00142
00145 virtual void Abort()=0;
00146
00149 virtual void ForwardAuthenticationInfo
00150 (DiameterNasreqAuthenticationInfo& authenticationInfo)=0;
00151
00154 void SignalContinue(DiameterNasreqAuthenticationInfo &authInfo);
00155
00158 void SignalSuccess();
00159
00162 void SignalFailure();
00163
00165 void SendAA_Answer();
00166
00171 bool CheckAA_Request();
00172
00179 virtual bool Authorize();
00180
00182 bool AuthorizationDone() { return authorizationDone; }
00183
00184 inline AAA_JobData& JobData() { return *handle.Job().Data(); }
00185
00186 template <class T> inline T& JobData(Type2Type<T>)
00187 { return (T&)*handle.Job().Data(); }
00188
00190 virtual bool AuthorizeOriginHost
00191 (const diameter_identity_t &originHost)
00192 {
00193 return true;
00194 }
00195
00197 virtual bool AuthorizeOriginRealm
00198 (const diameter_identity_t &originRealm)
00199 {
00200 return true;
00201 }
00202
00204 virtual bool AuthorizeNasIdentifier
00205 (const AAA_ScholarAttribute<diameter_utf8string_t> &nasIdentifier)
00206 {
00207 return true;
00208 }
00209
00211 virtual bool AuthorizeNasIpAddress
00212 (const AAA_ScholarAttribute<diameter_octetstring_t> &nasIpaddress)
00213 {
00214 return true;
00215 }
00216
00218 virtual bool AuthorizeNasIpv6Address
00219 (const AAA_ScholarAttribute<diameter_octetstring_t> &nasIpv6address)
00220 {
00221 return true;
00222 }
00223
00225 virtual bool AuthorizeNasPort
00226 (const AAA_ScholarAttribute<diameter_unsigned32_t> &nasPort)
00227 {
00228 return true;
00229 }
00230
00232 virtual bool AuthorizeNasPortId
00233 (const AAA_ScholarAttribute<diameter_utf8string_t> &nasPortId)
00234 {
00235 return true;
00236 }
00237
00239 virtual bool AuthorizeNasPortType
00240 (const AAA_ScholarAttribute<diameter_enumerated_t> &nasPortType)
00241 {
00242 return true;
00243 }
00244
00246 virtual bool AuthorizeOriginStateId
00247 (const AAA_ScholarAttribute<diameter_unsigned32_t> &nasOriginStateId)
00248 {
00249 return true;
00250 }
00251
00253 virtual bool AuthorizeFilterId
00254 (AAA_VectorAttribute<diameter_utf8string_t> &FilterId)
00255 {
00256 return true;
00257 }
00258
00260 virtual bool AuthorizePortLimit
00261 (AAA_ScholarAttribute<diameter_unsigned32_t> &portLimit)
00262 {
00263 return true;
00264 }
00265
00267 virtual bool AuthorizePortLimit
00268 (const diameter_unsigned32_t &portLimit1,
00269 AAA_ScholarAttribute<diameter_unsigned32_t> &portLimit2)
00270 {
00271 return true;
00272 }
00273
00275 virtual bool AuthorizeServiceType
00276 (AAA_ScholarAttribute<diameter_enumerated_t> &serviceType)
00277 {
00278 return true;
00279 }
00280
00282 virtual bool AuthorizeServiceType
00283 (const diameter_enumerated_t &serviceType1,
00284 AAA_ScholarAttribute<diameter_enumerated_t> &serviceType2)
00285 {
00286 return true;
00287 }
00288
00290 virtual bool AuthorizeClass
00291 (AAA_VectorAttribute<diameter_octetstring_t> &Class)
00292 {
00293 return true;
00294 }
00295
00297 virtual bool AuthorizeConfigurationToken
00298 (const AAA_VectorAttribute<diameter_octetstring_t> &configurationToken)
00299 {
00300 return true;
00301 }
00302
00304 virtual bool AuthorizeAcctInterimInterval
00305 (AAA_ScholarAttribute<diameter_unsigned32_t> &acctInterimInterval)
00306 {
00307 return true;
00308 }
00309
00311 virtual bool AuthorizeIdleTimeout
00312 (AAA_ScholarAttribute<diameter_unsigned32_t> &idleTimeout)
00313 {
00314 return true;
00315 }
00316
00318 virtual bool AuthorizeAuthorizationLifetime
00319 (AAA_ScholarAttribute<diameter_unsigned32_t> &authorizationLifetime)
00320 {
00321 return true;
00322 }
00323
00325 virtual bool AuthorizeAuthGracePeriod
00326 (AAA_ScholarAttribute<diameter_unsigned32_t> &authGracePeriod)
00327 {
00328 return true;
00329 }
00330
00332 virtual bool AuthorizeAuthSessionState
00333 (AAA_ScholarAttribute<diameter_enumerated_t> &authSessionState)
00334 {
00335 return true;
00336 }
00337
00339 virtual bool AuthorizeReAuthRequestType
00340 (AAA_ScholarAttribute<diameter_enumerated_t> &authReAuthRequestType)
00341 {
00342 return true;
00343 }
00344
00346 virtual bool AuthorizeSessionTimeout
00347 (AAA_ScholarAttribute<diameter_unsigned32_t> &authSessionTimeout)
00348 {
00349 return true;
00350 }
00351
00353 virtual bool AuthorizeCallbackId
00354 (AAA_ScholarAttribute<diameter_utf8string_t> &callbackId)
00355 {
00356 return true;
00357 }
00358
00360 virtual bool AuthorizeCallbackNumber
00361 (AAA_ScholarAttribute<diameter_utf8string_t> &callbackNumber)
00362 {
00363 return true;
00364 }
00365
00367 virtual bool AuthorizeCallbackNumber
00368 (const diameter_utf8string_t &callbackNumber1,
00369 AAA_ScholarAttribute<diameter_utf8string_t> &callbackNumber2)
00370 {
00371 return true;
00372 }
00373
00375 virtual bool AuthorizeCallingStationId
00376 (const diameter_utf8string_t &callingStationId)
00377 {
00378 return true;
00379 }
00380
00382 virtual bool AuthorizeCalledStationId
00383 (const diameter_utf8string_t &calledStationId)
00384 {
00385 return true;
00386 }
00387
00389 virtual bool AuthorizeOriginatingLineInfo
00390 (const AAA_ScholarAttribute<diameter_octetstring_t> &originatingLineInfo)
00391 {
00392 return true;
00393 }
00394
00395 virtual bool AuthorizeConnectInfo
00396 (const AAA_ScholarAttribute<diameter_utf8string_t> &connectInfo)
00397 {
00398 return true;
00399 }
00400
00402 virtual bool AuthorizeFramedAppletalkLink
00403 (AAA_ScholarAttribute<diameter_unsigned32_t> &framedAppletalkLink)
00404 {
00405 return true;
00406 }
00407
00409 virtual bool AuthorizeFramedAppletalkZone
00410 (AAA_ScholarAttribute<diameter_octetstring_t> &framedAppletalkZone)
00411 {
00412 return true;
00413 }
00414
00416 virtual bool AuthorizeFramedAppletalkNetwork
00417 (AAA_VectorAttribute<diameter_unsigned32_t> &framedAppletalkNetwork)
00418 {
00419 return true;
00420 }
00421
00423 virtual bool AuthorizeFramedCompression
00424 (AAA_VectorAttribute<diameter_enumerated_t> &framedCompression)
00425 {
00426 return true;
00427 }
00428
00430 virtual bool AuthorizeFramedCompression
00431 (const std::vector<diameter_enumerated_t> &framedCompression1,
00432 AAA_VectorAttribute<diameter_enumerated_t> &framedCompression2)
00433 {
00434 return true;
00435 }
00436
00438 virtual bool AuthorizeFramedInterfaceId
00439 (AAA_ScholarAttribute<diameter_unsigned64_t> &framedInterfaceId)
00440 {
00441 return true;
00442 }
00443
00445 virtual bool AuthorizeFramedInterfaceId
00446 (const diameter_unsigned64_t &framedInterfaceId1,
00447 AAA_ScholarAttribute<diameter_unsigned64_t> &framedInterfaceId2)
00448 {
00449 return true;
00450 }
00451
00453 virtual bool AuthorizeFramedIpAddress
00454 (AAA_ScholarAttribute<diameter_octetstring_t> &framedIpAddress)
00455 {
00456 return true;
00457 }
00458
00460 virtual bool AuthorizeFramedIpAddress
00461 (const diameter_octetstring_t &framedIpAddress1,
00462 AAA_ScholarAttribute<diameter_octetstring_t> &framedIpAddress2)
00463 {
00464 return true;
00465 }
00466
00468 virtual bool AuthorizeFramedIpv6Prefix
00469 (AAA_VectorAttribute<diameter_octetstring_t> &framedIpv6Prefix)
00470 {
00471 return true;
00472 }
00473
00475 virtual bool AuthorizeFramedIpv6Prefix
00476 (const std::vector<diameter_octetstring_t> &framedIpv6Prefix1,
00477 AAA_VectorAttribute<diameter_octetstring_t> &framedIpv6Prefix2)
00478 {
00479 return true;
00480 }
00481
00483 virtual bool AuthorizeFramedIpv6Pool
00484 (AAA_ScholarAttribute<diameter_octetstring_t> &framedIpv6Pool)
00485 {
00486 return true;
00487 }
00488
00490 virtual bool AuthorizeFramedPool
00491 (AAA_ScholarAttribute<diameter_octetstring_t> &framedPool)
00492 {
00493 return true;
00494 }
00495
00497 virtual bool AuthorizeFramedIpv6Route
00498 (AAA_VectorAttribute<diameter_utf8string_t> &framedIpv6Route)
00499 {
00500 return true;
00501 }
00502
00504 virtual bool AuthorizeFramedRoute
00505 (AAA_VectorAttribute<diameter_utf8string_t> &framedRoute)
00506 {
00507 return true;
00508 }
00509
00511 virtual bool AuthorizeFramedIpNetmask
00512 (AAA_ScholarAttribute<diameter_octetstring_t> &framedIpNetmask)
00513 {
00514 return true;
00515 }
00516
00518 virtual bool AuthorizeFramedIpNetmask
00519 (const diameter_octetstring_t &framedIpNetmask1,
00520 AAA_ScholarAttribute<diameter_octetstring_t> &framedIpNetmask2)
00521 {
00522 return true;
00523 }
00524
00526 virtual bool AuthorizeFramedIpxNetwork
00527 (AAA_ScholarAttribute<diameter_utf8string_t> &framedIpxNetwork)
00528 {
00529 return true;
00530 }
00531
00533 virtual bool AuthorizeFramedMtu
00534 (AAA_ScholarAttribute<diameter_unsigned32_t> &framedMtu)
00535 {
00536 return true;
00537 }
00538
00540 virtual bool AuthorizeFramedMtu
00541 (const diameter_unsigned32_t &framedMtu1,
00542 AAA_ScholarAttribute<diameter_unsigned32_t> &framedMtu2)
00543 {
00544 return true;
00545 }
00546
00548 virtual bool AuthorizeFramedProtocol
00549 (AAA_ScholarAttribute<diameter_enumerated_t> &framedProtocol)
00550 {
00551 return true;
00552 }
00553
00555 virtual bool AuthorizeFramedProtocol
00556 (const diameter_enumerated_t &framedProtocol1,
00557 AAA_ScholarAttribute<diameter_enumerated_t> &framedProtoco2)
00558 {
00559 return true;
00560 }
00561
00563 virtual bool AuthorizeFramedRouting
00564 (AAA_ScholarAttribute<diameter_enumerated_t> &framedRouting)
00565 {
00566 return true;
00567 }
00568
00570 virtual bool AuthorizeLoginIpHost
00571 (AAA_VectorAttribute<diameter_octetstring_t> &loginIpHost)
00572 {
00573 return true;
00574 }
00576 virtual bool AuthorizeLoginIpHost
00577 (const std::vector<diameter_octetstring_t> &loginIpHost1,
00578 AAA_VectorAttribute<diameter_octetstring_t> &loginIpHost2)
00579 {
00580 return true;
00581 }
00582
00584 virtual bool AuthorizeLoginIpv6Host
00585 (AAA_VectorAttribute<diameter_octetstring_t> &loginIpv6Host)
00586 {
00587 return true;
00588 }
00589
00591 virtual bool AuthorizeLoginIpv6Host
00592 (const std::vector<diameter_octetstring_t> &loginIpv6Host1,
00593 AAA_VectorAttribute<diameter_octetstring_t> &loginIpv6Host2)
00594 {
00595 return true;
00596 }
00597
00599 virtual bool AuthorizeLoginLatGroup
00600 (AAA_ScholarAttribute<diameter_octetstring_t> &loginLatGroup)
00601 {
00602 return true;
00603 }
00604
00606 virtual bool AuthorizeLoginLatGroup
00607 (const AAA_ScholarAttribute<diameter_octetstring_t> &loginLatGroup1,
00608 AAA_ScholarAttribute<diameter_octetstring_t> &loginLatGroup2)
00609 {
00610 return true;
00611 }
00612
00614 virtual bool AuthorizeLoginLatNode
00615 (AAA_ScholarAttribute<diameter_octetstring_t> &loginLatNode)
00616 {
00617 return true;
00618 }
00619
00621 virtual bool AuthorizeLoginLatNode
00622 (const AAA_ScholarAttribute<diameter_octetstring_t> &loginLatNode1,
00623 AAA_ScholarAttribute<diameter_octetstring_t> &loginLatNode2)
00624 {
00625 return true;
00626 }
00627
00629 virtual bool AuthorizeLoginLatPort
00630 (AAA_ScholarAttribute<diameter_octetstring_t> &loginLatPort)
00631 {
00632 return true;
00633 }
00634
00636 virtual bool AuthorizeLoginLatPort
00637 (const AAA_ScholarAttribute<diameter_octetstring_t> &loginLatPort1,
00638 AAA_ScholarAttribute<diameter_octetstring_t> &loginLatPort2)
00639 {
00640 return true;
00641 }
00642
00644 virtual bool AuthorizeLoginLatService
00645 (AAA_ScholarAttribute<diameter_octetstring_t> &loginLatService2)
00646 {
00647 return true;
00648 }
00649
00651 virtual bool AuthorizeLoginLatService
00652 (const AAA_ScholarAttribute<diameter_octetstring_t> &loginLatService1,
00653 AAA_ScholarAttribute<diameter_octetstring_t> &loginLatService2)
00654 {
00655 return true;
00656 }
00657
00659 virtual bool AuthorizeLoginTcpPort
00660 (AAA_ScholarAttribute<diameter_unsigned32_t> &loginTcpPort)
00661 {
00662 return true;
00663 }
00664
00666 virtual bool AuthorizeNasFilterRule
00667 (AAA_VectorAttribute<diameter_ipfilter_rule_t> &nasFilterRule)
00668 {
00669 return true;
00670 }
00671
00673 virtual bool AuthorizeTunneling
00674 (AAA_VectorAttribute<tunneling_t> &tunneling)
00675 {
00676 return true;
00677 }
00678
00680 virtual bool AuthorizeTunneling
00681 (const std::vector<tunneling_t> &tunneling1,
00682 AAA_VectorAttribute<tunneling_t> &tunneling2)
00683 {
00684 return true;
00685 }
00686
00689 virtual void SetReplyMessage
00690 (AAA_VectorAttribute<diameter_utf8string_t> &replyMessage,
00691 const diameter_unsigned32_t &resultCode)
00692 {}
00693
00695 virtual bool ValidateAuthRequestType
00696 (const diameter_enumerated_t &authRequestType)
00697 {
00698 if (authRequestType != AUTH_REQUEST_TYPE_AUTHENTICATION_ONLY &&
00699 authRequestType != AUTH_REQUEST_TYPE_AUTHORIZE_AUTHENTICATE)
00700 return false;
00701 return true;
00702 }
00703
00706 virtual bool ValidateState
00707 (const diameter_octetstring_t &stateInDER,
00708 const diameter_octetstring_t &stateInDEA)
00709 {
00710 return false;
00711 }
00712
00714 virtual void SetState(AAA_ScholarAttribute<diameter_octetstring_t> &state)
00715 {
00716 }
00717
00719 virtual void SetArapMultiExchange
00720 (AAA_ScholarAttribute<diameter_unsigned32_t> &ArapSecurity,
00721 AAA_VectorAttribute<diameter_octetstring_t> &ArapSecurityData)
00722 {
00723 }
00724
00725 inline DiameterNasreqAuthenticationInfo& AuthenticationInfo()
00726 { return *authenticationInfo; }
00727
00728 inline AA_RequestData& AA_Request() { return aaRequestData; }
00729 inline AA_AnswerData& AA_Answer() { return aaAnswerData; }
00730
00731 protected:
00732
00733 private:
00735 int Schedule(AAA_Job*, size_t=1) { return (-1); }
00736
00738 inline int Serve()
00739 {
00740 if (!AAA_EventQueueJob::ExistBacklog())
00741 {
00742 AAA_LOG(LM_ERROR, "%N: no backlog to serve.");
00743 return 0;
00744 }
00745
00746
00747 AAA_Event ev;
00748 AAA_EventQueueJob::Dequeue(ev);
00749
00750 bool existBacklog = AAA_EventQueueJob::ExistBacklog();
00751
00752
00753 Event(ev);
00754 return existBacklog ? 1 : 0;
00755 }
00756
00757 DiameterNasreqServerSession& session;
00758
00759
00760 DiameterNasreqJobHandle handle;
00761
00762
00763 boost::shared_ptr<DiameterNasreqAuthenticationInfo> authenticationInfo;
00764
00765 bool authorizationDone;
00766
00767
00768 AA_RequestData aaRequestData;
00769 AA_AnswerData aaAnswerData;
00770
00771 };
00772
00773 #endif