/* * lcp.h - Self explanitory * Copyright (C) 1997-2000 SpellCaster Telecommunications Inc. * $Id: lcp.h,v 1.3 2004/08/15 03:01:06 bcrl Exp $ * Released under the GNU Public License. See LICENSE file for details. */ #ifndef LCP_H #define LCP_H #include "config.h" #include "debug.h" #include "fsm.h" #include "protocol.h" #include "packet.h" class CLink; #define LCP_HEADER_LENGTH 4 // Packet Codes #define LCP_CODE_CONFREQ 1 #define LCP_CODE_CONFACK 2 #define LCP_CODE_CONFNAK 3 #define LCP_CODE_CONFREJ 4 #define LCP_CODE_TERMREQ 5 #define LCP_CODE_TERMACK 6 #define LCP_CODE_CODEREJ 7 #define LCP_CODE_PROTOREJ 8 #define LCP_CODE_ECHOREQ 9 #define LCP_CODE_ECHORPLY 10 #define LCP_CODE_DISCREQ 11 // Options Types #define LCP_OPT_MRU 1 #define LCP_OPT_AUTH 3 #define LCP_OPT_AUTH_CHAP LCP_OPT_AUTH #define LCP_OPT_AUTH_PAP LCP_OPT_AUTH #define LCP_OPT_QUAL 4 #define LCP_OPT_MAGIC 5 #define LCP_OPT_PFC 7 #define LCP_OPT_ACFC 8 #define LCP_OPT_ACCM 2 #define LCP_OPT_MRRU 17 // MP Max-Receive-Recon-Unit #define LCP_OPT_SSN 18 // MP Short Sequence Number #define LCP_OPT_EPD 19 // Multilink End-point Discriptor #define LCP_OPT_LDISC 23 // Link Discriminator // Option value constraints #define LCP_OPT_MRU_MIN 48 #define LCP_OPT_CHAP_MD5 5 #define LCP_OPT_CHAP_RAS 0x80 // Option Defaults #define LCP_OPT_MRU_DEFAULT 1500 #define LCP_OPT_CHAP_DEFAULT LCP_OPT_CHAP_MD5 // Option Lengths #define LCP_OPT_MRU_LEN 4 #define LCP_OPT_PAP_LEN 4 #define LCP_OPT_CHAP_LEN 5 #define LCP_OPT_PFC_LEN 2 #define LCP_OPT_MAGIC_LEN 6 #define LCP_OPT_ACCM_LEN 6 #define LCP_OPT_ACFC_LEN 2 #define LCP_OPT_MRRU_LEN 4 #define LCP_OPT_SSN_LEN 2 #define LCP_OPT_EPD_LEN 3 /* Minimum */ #define LCP_OPT_EPD_ADDR_LEN 20 /* Maximum */ #define LCP_OPT_LDISC_LEN 4 class ctrlfd_t; class dfs_object_t; class l2tp_packet_t; class lcp_ping; class CLcpProtocol : public CFsmProtocol, public CQueueItem { public: CLcpProtocol(); virtual ~CLcpProtocol(); virtual void Up(); public: // External Events void Input(CPppPacket *); void RejectProtocol(CPppPacket *); void EchoTimeout(void); #define LCP_ECHO_LEN (PPP_HEADER_LENGTH + LCP_HEADER_LENGTH + 1 + \ sizeof(u32) + sizeof(u64) + sizeof(u32)) int SndEchoReq(unsigned size = 0); CLink *m_parent; lcp_ping *m_lcpPing; void dump_full_state(ctrlfd_t *cfd); void dfs_restore(dfs_object_t *obj); void RestartLCPForMRRU(OptionSet_t *os); CPppPacket *m_initialReceivedConfReq; CPppPacket *m_lastSentConfReq; CPppPacket *m_lastReceivedConfReq; void SetupICCN(l2tp_packet_t *iccn); private: CTimer m_echoIntervalTimer; /* used for non-global echo interval */ int m_echoInterval; CTimer m_echoTimer; /* used to time out sent echo requests */ int m_echoTime; u16 m_lastEchoIdent;/* identifier of the last echo request sent */ u16 m_echoSent; /* count of echo reqs sent since last reply */ u16 m_mruNaks; u16 m_restartedForMRRU; int m_rxPackets; protected: virtual void RcvProtoReject(CPppPacket *); virtual void RcvCodeReject(CPppPacket *); // State Machine triggered events virtual void SndEchoReply(CPppPacket *); virtual void SndCodeReject(CPppPacket *); virtual void ThisLayerDown(); virtual void ThisLayerUp(); virtual void ThisLayerFinished(const char *why); virtual void SndTermReq(); virtual void SndConfReq(); virtual void SndTermAck(); virtual void SndConfAck(); virtual void SndConfNak(); // Configuration Functions virtual void RcvConfAck(CPppPacket *); virtual void RcvConfRej(CPppPacket *); virtual void RcvConfNak(CPppPacket *); virtual void RcvConfReq(CPppPacket *); friend void echoIntervalTimer(void *data); }; int GetMRRUFromPacket(CPppPacket *packet); class CLink; class lcp_ping : public CTimer, ctrlfd_die_listener { private: ctrlfd_t *m_cfd; CLink *m_link; int m_success; int m_ident; public: lcp_ping *m_next, **m_prevp; lcp_ping(ctrlfd_t *cfd, CLink *link, unsigned size = LCP_ECHO_LEN); ~lcp_ping(); void got_ping(int ident, struct timeval delta); virtual void TimerExpired(void); void ctrlfd_die_notification(ctrlfd_t *cfd); virtual void got_good_ping(int ident, struct timeval delta); }; class lcp_probe_t; class lcp_probe_ping_t : public lcp_ping { lcp_probe_t *m_probe; public: lcp_probe_ping_t(lcp_probe_t *probe, CLink *link); virtual void got_good_ping(int ident, struct timeval delta); virtual void TimerExpired(void); }; class lcp_probe_complete_t { public: virtual void lcp_probe_complete(int alive, int dead) { fprintf(stderr, "lcp_probe_complete(%p) alive=%d dead=%d\n", this, alive, dead); delete this; } virtual ~lcp_probe_complete_t() { return; } }; class lcp_probe_t { lcp_probe_complete_t *m_req; int m_outstanding; int m_nr_alive; int m_nr_dead; public: lcp_probe_t(lcp_probe_complete_t *req, const char *user); void ping_complete(lcp_probe_ping_t *ping, int alive); }; #endif // LCP_H