diff options
author | Kozlov Dmitry <dima@server> | 2010-11-10 18:33:36 +0300 |
---|---|---|
committer | Kozlov Dmitry <dima@server> | 2010-11-10 18:33:36 +0300 |
commit | 058e7ff66b8fbb1f9494ae5077e5294db288fb1c (patch) | |
tree | e5d4c535539681843efb80bb1f06a643cee88904 /accel-pptpd/ppp | |
parent | 4d826710d0d30606da88ff3543a4b43521e404df (diff) | |
download | accel-ppp-058e7ff66b8fbb1f9494ae5077e5294db288fb1c.tar.gz accel-ppp-058e7ff66b8fbb1f9494ae5077e5294db288fb1c.zip |
cli: implemented following command list: show stat, show sessions, terminate (sessison)
Diffstat (limited to 'accel-pptpd/ppp')
-rw-r--r-- | accel-pptpd/ppp/ppp.c | 37 | ||||
-rw-r--r-- | accel-pptpd/ppp/ppp.h | 24 |
2 files changed, 56 insertions, 5 deletions
diff --git a/accel-pptpd/ppp/ppp.c b/accel-pptpd/ppp/ppp.c index 4cb5e163..5b1dd7cd 100644 --- a/accel-pptpd/ppp/ppp.c +++ b/accel-pptpd/ppp/ppp.c @@ -24,12 +24,17 @@ int __export conf_ppp_verbose; +pthread_rwlock_t __export ppp_lock; +__export LIST_HEAD(ppp_list); + static LIST_HEAD(layers); int __export sock_fd; static spinlock_t seq_lock = SPINLOCK_INITIALIZER; static uint64_t seq; +struct ppp_stat_t ppp_stat; + struct layer_node_t { struct list_head entry; @@ -146,6 +151,13 @@ int __export establish_ppp(struct ppp_t *ppp) triton_md_enable_handler(&ppp->chan_hnd, MD_MODE_READ); triton_md_enable_handler(&ppp->unit_hnd, MD_MODE_READ); + ppp->state = PPP_STATE_STARTING; + __sync_fetch_and_add(&ppp_stat.starting, 1); + + pthread_rwlock_wrlock(&ppp_lock); + list_add_tail(&ppp->entry, &ppp_list); + pthread_rwlock_unlock(&ppp_lock); + log_ppp_debug("ppp established\n"); triton_event_fire(EV_PPP_STARTING, ppp); @@ -166,6 +178,22 @@ exit_close_chan: static void destablish_ppp(struct ppp_t *ppp) { + pthread_rwlock_wrlock(&ppp_lock); + list_del(&ppp->entry); + pthread_rwlock_unlock(&ppp_lock); + + switch (ppp->state) { + case PPP_STATE_ACTIVE: + __sync_fetch_and_sub(&ppp_stat.active, 1); + break; + case PPP_STATE_STARTING: + __sync_fetch_and_sub(&ppp_stat.starting, 1); + break; + case PPP_STATE_FINISHING: + __sync_fetch_and_sub(&ppp_stat.finishing, 1); + break; + } + triton_md_unregister_handler(&ppp->chan_hnd); triton_md_unregister_handler(&ppp->unit_hnd); @@ -343,6 +371,9 @@ void __export ppp_layer_started(struct ppp_t *ppp, struct ppp_layer_data_t *d) if (!d->started) return; if (n->entry.next == &ppp->layers) { + ppp->state = PPP_STATE_ACTIVE; + __sync_fetch_and_sub(&ppp_stat.starting, 1); + __sync_fetch_and_add(&ppp_stat.active, 1); ppp->ctrl->started(ppp); triton_event_fire(EV_PPP_STARTED, ppp); } else { @@ -392,6 +423,12 @@ void __export ppp_terminate(struct ppp_t *ppp, int cause, int hard) } ppp->terminating = 1; + if (ppp->state == PPP_STATE_ACTIVE) + __sync_fetch_and_sub(&ppp_stat.active, 1); + else + __sync_fetch_and_sub(&ppp_stat.starting, 1); + __sync_fetch_and_add(&ppp_stat.finishing, 1); + ppp->state = PPP_STATE_FINISHING; log_ppp_debug("ppp_terminate\n"); diff --git a/accel-pptpd/ppp/ppp.h b/accel-pptpd/ppp/ppp.h index b36f0e42..f74351d4 100644 --- a/accel-pptpd/ppp/ppp.h +++ b/accel-pptpd/ppp/ppp.h @@ -4,6 +4,7 @@ #include <sys/types.h> #include <time.h> #include <netinet/in.h> +#include <pthread.h> #include "triton.h" #include "list.h" @@ -38,14 +39,13 @@ #define PPP_CBCP 0xc029 /* Callback Control Protocol */ #define PPP_EAP 0xc227 /* Extensible Authentication Protocol */ -#define PPP_LAYER_LCP 1 -#define PPP_LAYER_AUTH 2 -#define PPP_LAYER_CCP 3 -#define PPP_LAYER_IPCP 4 - #define PPP_SESSIONID_LEN 16 #define PPP_IFNAME_LEN 10 +#define PPP_STATE_STARTING 1 +#define PPP_STATE_ACTIVE 2 +#define PPP_STATE_FINISHING 3 + #define TERM_USER_REQUEST 1 #define TERM_SESSION_TIMEOUT 2 #define TERM_ADMIN_RESET 3 @@ -75,6 +75,7 @@ struct ppp_pd_t struct ppp_t { + struct list_head entry; struct triton_md_handler_t chan_hnd; struct triton_md_handler_t unit_hnd; int fd; @@ -84,6 +85,7 @@ struct ppp_t int chan_idx; int unit_idx; + int state; char *chan_name; char ifname[PPP_IFNAME_LEN]; char sessionid[PPP_SESSIONID_LEN+1]; @@ -142,6 +144,13 @@ struct ppp_handler_t void (*recv_proto_rej)(struct ppp_handler_t *h); }; +struct ppp_stat_t +{ + uint32_t active; + uint32_t starting; + uint32_t finishing; +}; + struct ppp_t *alloc_ppp(void); void ppp_init(struct ppp_t *ppp); int establish_ppp(struct ppp_t *ppp); @@ -165,5 +174,10 @@ struct ppp_layer_data_t *ppp_find_layer_data(struct ppp_t *, struct ppp_layer_t extern int conf_ppp_verbose; +extern pthread_rwlock_t ppp_lock; +extern struct list_head ppp_list; + +extern struct ppp_stat_t ppp_stat; + extern int sock_fd; // internet socket for ioctls #endif |