diff options
Diffstat (limited to 'accel-pptpd/ppp')
-rw-r--r-- | accel-pptpd/ppp/ppp.c | 33 | ||||
-rw-r--r-- | accel-pptpd/ppp/ppp.h | 10 | ||||
-rw-r--r-- | accel-pptpd/ppp/ppp_auth.c | 3 | ||||
-rw-r--r-- | accel-pptpd/ppp/ppp_auth.h | 2 | ||||
-rw-r--r-- | accel-pptpd/ppp/ppp_notify.c | 20 |
5 files changed, 64 insertions, 4 deletions
diff --git a/accel-pptpd/ppp/ppp.c b/accel-pptpd/ppp/ppp.c index 247f819..1e2ed86 100644 --- a/accel-pptpd/ppp/ppp.c +++ b/accel-pptpd/ppp/ppp.c @@ -10,6 +10,7 @@ #include <arpa/inet.h> #include <linux/ppp_defs.h> #include <linux/if_ppp.h> +#include <openssl/md5.h> #include "triton.h" @@ -20,7 +21,7 @@ int conf_ppp_verbose; static LIST_HEAD(layers); -int sock_fd; +int __export sock_fd; struct layer_node_t { @@ -46,6 +47,28 @@ static void free_ppp(struct ppp_t *ppp) { free(ppp->chan_buf); free(ppp->unit_buf); + + if (ppp->username) + free(ppp->username); +} + +static void generate_sessionid(struct ppp_t *ppp) +{ + MD5_CTX ctx; + uint8_t md5[MD5_DIGEST_LENGTH]; + int i; + + MD5_Init(&ctx); + MD5_Update(&ctx,&ppp->unit_idx, 4); + MD5_Update(&ctx,&ppp->unit_fd, 4); + MD5_Update(&ctx,&ppp->chan_fd, 4); + MD5_Update(&ctx,&ppp->fd, 4); + MD5_Update(&ctx,&ppp->start_time, sizeof(time_t)); + MD5_Update(&ctx,ppp->ctrl->ctx, sizeof(void *)); + MD5_Final(md5,&ctx); + + for( i = 0; i < 16; i++) + sprintf(ppp->sessionid + i*2, "%02X", md5[i]); } int __export establish_ppp(struct ppp_t *ppp) @@ -90,6 +113,9 @@ int __export establish_ppp(struct ppp_t *ppp) goto exit_close_unit; } + ppp->start_time = time(NULL); + generate_sessionid(ppp); + log_info("connect: ppp%i <--> pptp(%s)\n",ppp->unit_idx,ppp->chan_name); ppp->chan_buf=malloc(PPP_MRU); @@ -131,7 +157,7 @@ int __export establish_ppp(struct ppp_t *ppp) log_debug("ppp established\n"); - ppp_notify_started(ppp); + ppp_notify_starting(ppp); start_first_layer(ppp); return 0; @@ -298,6 +324,7 @@ void __export ppp_layer_started(struct ppp_t *ppp, struct ppp_layer_data_t *d) if (n->entry.next==&ppp->layers) { ppp->ctrl->started(ppp); + ppp_notify_started(ppp); }else { n=list_entry(n->entry.next,typeof(*n),entry); @@ -339,6 +366,8 @@ void __export ppp_terminate(struct ppp_t *ppp, int hard) log_debug("ppp_terminate\n"); + ppp_notify_finishing(ppp); + if (hard) { destablish_ppp(ppp); return; diff --git a/accel-pptpd/ppp/ppp.h b/accel-pptpd/ppp/ppp.h index e287b7b..a82e975 100644 --- a/accel-pptpd/ppp/ppp.h +++ b/accel-pptpd/ppp/ppp.h @@ -2,6 +2,7 @@ #define PPP_H #include <sys/types.h> +#include <time.h> #include "triton.h" #include "list.h" @@ -41,6 +42,8 @@ #define PPP_LAYER_CCP 3 #define PPP_LAYER_IPCP 4 +#define PPP_SESSIONID_LEN 32 + struct ppp_t; struct ppp_ctrl_t @@ -53,7 +56,9 @@ struct ppp_ctrl_t struct ppp_notified_t { struct list_head entry; + void (*starting)(struct ppp_notified_t *, struct ppp_t *); void (*started)(struct ppp_notified_t *, struct ppp_t *); + void (*finishing)(struct ppp_notified_t *, struct ppp_t *); void (*finished)(struct ppp_notified_t *, struct ppp_t *); void (*authenticated)(struct ppp_notified_t *, struct ppp_t *); }; @@ -76,6 +81,9 @@ struct ppp_t int unit_idx; char *chan_name; + char sessionid[PPP_SESSIONID_LEN+1]; + time_t start_time; + char *username; struct ppp_ctrl_t *ctrl; @@ -143,7 +151,9 @@ struct ppp_layer_data_t *ppp_find_layer_data(struct ppp_t *, struct ppp_layer_t void ppp_register_notified(struct ppp_notified_t *); void ppp_unregister_notified(struct ppp_notified_t *); +void ppp_notify_starting(struct ppp_t *ppp); void ppp_notify_started(struct ppp_t *ppp); +void ppp_notify_finishing(struct ppp_t *ppp); void ppp_notify_finished(struct ppp_t *ppp); extern int conf_ppp_verbose; diff --git a/accel-pptpd/ppp/ppp_auth.c b/accel-pptpd/ppp/ppp_auth.c index b767fdb..0a362e6 100644 --- a/accel-pptpd/ppp/ppp_auth.c +++ b/accel-pptpd/ppp/ppp_auth.c @@ -296,10 +296,11 @@ static void auth_layer_free(struct ppp_layer_data_t *ld) free(ad); } -void __export auth_successed(struct ppp_t *ppp) +void __export auth_successed(struct ppp_t *ppp, char *username) { struct auth_layer_data_t *ad=container_of(ppp_find_layer_data(ppp,&auth_layer),typeof(*ad),ld); log_debug("auth_layer_started\n"); + ppp->username = username; ppp_layer_started(ppp,&ad->ld); } diff --git a/accel-pptpd/ppp/ppp_auth.h b/accel-pptpd/ppp/ppp_auth.h index f1880d5..f858d33 100644 --- a/accel-pptpd/ppp/ppp_auth.h +++ b/accel-pptpd/ppp/ppp_auth.h @@ -27,7 +27,7 @@ struct ppp_auth_handler_t int ppp_auth_register_handler(struct ppp_auth_handler_t*); -void auth_successed(struct ppp_t *ppp); +void auth_successed(struct ppp_t *ppp, char *username); void auth_failed(struct ppp_t *ppp); #endif diff --git a/accel-pptpd/ppp/ppp_notify.c b/accel-pptpd/ppp/ppp_notify.c index 94ceb6d..ad9fd1f 100644 --- a/accel-pptpd/ppp/ppp_notify.c +++ b/accel-pptpd/ppp/ppp_notify.c @@ -12,6 +12,16 @@ void __export ppp_unregister_notified(struct ppp_notified_t *n) list_del(&n->entry); } +void ppp_notify_starting(struct ppp_t *ppp) +{ + struct ppp_notified_t *n; + + list_for_each_entry(n, ¬ified_list, entry) { + if (n->starting) + n->starting(n, ppp); + } +} + void ppp_notify_started(struct ppp_t *ppp) { struct ppp_notified_t *n; @@ -32,3 +42,13 @@ void ppp_notify_finished(struct ppp_t *ppp) } } +void ppp_notify_finishing(struct ppp_t *ppp) +{ + struct ppp_notified_t *n; + + list_for_each_entry(n, ¬ified_list, entry) { + if (n->finishing) + n->finishing(n, ppp); + } +} + |