diff options
author | Kozlov Dmitry <dima@server> | 2010-09-10 11:58:34 +0400 |
---|---|---|
committer | Kozlov Dmitry <dima@server> | 2010-09-10 11:58:34 +0400 |
commit | c471cd62571f654b92bad0bd9f431927758f4d45 (patch) | |
tree | 8f08d11522ae9b3d0e2c44d04746ca0f0e5ed22c /accel-pptpd/radius | |
parent | 35d38d2c3f3db22216d43604b8750ecb6089e525 (diff) | |
download | accel-ppp-c471cd62571f654b92bad0bd9f431927758f4d45.tar.gz accel-ppp-c471cd62571f654b92bad0bd9f431927758f4d45.zip |
ippool: implemented module ippool which gives IP address from configurable ranges
Diffstat (limited to 'accel-pptpd/radius')
-rw-r--r-- | accel-pptpd/radius/dm_coa.c (renamed from accel-pptpd/radius/pd_coa.c) | 106 | ||||
-rw-r--r-- | accel-pptpd/radius/radius.c | 33 | ||||
-rw-r--r-- | accel-pptpd/radius/radius.h | 5 |
3 files changed, 97 insertions, 47 deletions
diff --git a/accel-pptpd/radius/pd_coa.c b/accel-pptpd/radius/dm_coa.c index 0d2f4050..c337b6af 100644 --- a/accel-pptpd/radius/pd_coa.c +++ b/accel-pptpd/radius/dm_coa.c @@ -24,6 +24,8 @@ struct dm_coa_serv_t struct triton_md_handler_t hnd; }; +static struct dm_coa_serv_t serv; + static int dm_coa_check_RA(struct rad_packet_t *pack, const char *secret) { uint8_t RA[16]; @@ -51,8 +53,77 @@ static void dm_coa_set_RA(struct rad_packet_t *pack, const char *secret) MD5_Final(pack->buf + 4, &ctx); } +static int dm_coa_send_ack(int fd, struct rad_packet_t *req, struct sockaddr_in *addr) +{ + struct rad_packet_t *reply; + uint8_t RA[16]; + + memcpy(RA, req->buf + 4, sizeof(RA)); + + reply = rad_packet_alloc(req->code == CODE_COA_REQUEST ? CODE_COA_ACK : CODE_DISCONNECT_ACK); + if (!reply) + return -1; + + reply->id = req->id; + + if (rad_packet_build(reply, RA)) { + rad_packet_free(reply); + return -1; + } + + dm_coa_set_RA(reply, conf_dm_coa_secret); + + if (conf_verbose) { + log_debug("send "); + rad_packet_print(reply, log_debug); + } + + rad_packet_send(reply, fd, addr); + + rad_packet_free(reply); + + return 0; +} + +static int dm_coa_send_nak(int fd, struct rad_packet_t *req, struct sockaddr_in *addr, int err_code) +{ + struct rad_packet_t *reply; + uint8_t RA[16]; + + memcpy(RA, req->buf + 4, sizeof(RA)); + + reply = rad_packet_alloc(req->code == CODE_COA_REQUEST ? CODE_COA_NAK : CODE_DISCONNECT_NAK); + if (!reply) + return -1; + + reply->id = req->id; + + rad_packet_add_int(reply, "Error-Cause", err_code); + + if (rad_packet_build(reply, RA)) { + rad_packet_free(reply); + return -1; + } + + dm_coa_set_RA(reply, conf_dm_coa_secret); + + if (conf_verbose) { + log_debug("send "); + rad_packet_print(reply, log_debug); + } + + rad_packet_send(reply, fd, addr); + + rad_packet_free(reply); + + return 0; +} + + static void disconnect_request(struct radius_pd_t *rpd) { + dm_coa_send_ack(serv.hnd.fd, rpd->dm_coa_req, &rpd->dm_coa_addr); + rad_packet_free(rpd->dm_coa_req); rpd->dm_coa_req = NULL; @@ -61,19 +132,17 @@ static void disconnect_request(struct radius_pd_t *rpd) static void coa_request(struct radius_pd_t *rpd) { +/// TODO: CoA handling + rad_packet_free(rpd->dm_coa_req); rpd->dm_coa_req = NULL; - -/// TODO: CoA handling } static int dm_coa_read(struct triton_md_handler_t *h) { struct rad_packet_t *pack; - struct rad_packet_t *reply = NULL; struct radius_pd_t *rpd; int err_code; - uint8_t RA[16]; struct sockaddr_in addr; @@ -91,8 +160,6 @@ static int dm_coa_read(struct triton_md_handler_t *h) goto out_err_no_reply; } - memcpy(RA, pack->buf + 4, sizeof(RA)); - if (conf_verbose) { log_debug("recv "); rad_packet_print(pack, log_debug); @@ -112,6 +179,7 @@ static int dm_coa_read(struct triton_md_handler_t *h) } rpd->dm_coa_req = pack; + memcpy(&rpd->dm_coa_addr, &addr, sizeof(addr)); if (pack->code == CODE_DISCONNECT_REQUEST) triton_context_call(rpd->ppp->ctrl->ctx, (void (*)(void *))disconnect_request, rpd); @@ -120,37 +188,13 @@ static int dm_coa_read(struct triton_md_handler_t *h) pthread_mutex_unlock(&rpd->lock); - reply = rad_packet_alloc(pack->code == CODE_COA_REQUEST ? CODE_COA_ACK : CODE_DISCONNECT_ACK); - reply->id = pack->id; - if (rad_packet_build(reply, RA)) - goto out_err_no_reply; - dm_coa_set_RA(reply, conf_dm_coa_secret); - if (conf_verbose) { - log_debug("send "); - rad_packet_print(reply, log_debug); - } - rad_packet_send(reply, h->fd, &addr); - rad_packet_free(reply); - return 0; out_err: - reply = rad_packet_alloc(pack->code == CODE_COA_REQUEST ? CODE_COA_NAK : CODE_DISCONNECT_NAK); - rad_packet_add_int(reply, "Error-Cause", err_code); - reply->id = pack->id; - if (rad_packet_build(reply, RA)) - goto out_err_no_reply; - dm_coa_set_RA(reply, conf_dm_coa_secret); - if (conf_verbose) { - log_debug("send "); - rad_packet_print(reply, log_debug); - } - rad_packet_send(reply, h->fd, &addr); + dm_coa_send_nak(h->fd, pack, &addr, err_code); out_err_no_reply: rad_packet_free(pack); - if (reply) - rad_packet_free(reply); return 0; } diff --git a/accel-pptpd/radius/radius.c b/accel-pptpd/radius/radius.c index d709963e..3fc1171c 100644 --- a/accel-pptpd/radius/radius.c +++ b/accel-pptpd/radius/radius.c @@ -36,15 +36,22 @@ static LIST_HEAD(sessions); static pthread_rwlock_t sessions_lock = PTHREAD_RWLOCK_INITIALIZER; static struct ppp_notified_t notified; +static struct ipdb_t ipdb; void rad_proc_attrs(struct rad_req_t *req) { struct rad_attr_t *attr; list_for_each_entry(attr, &req->reply->attrs, entry) { - if (!strcmp(attr->attr->name, "Framed-IP-Address")) - req->rpd->ipaddr = attr->val.ipaddr; - else if (!strcmp(attr->attr->name, "Acct-Interim-Interval")) + if (!strcmp(attr->attr->name, "Framed-IP-Address")) { + if (!conf_gw_ip_address) + log_warn("radius: gw-ip-address not specified, cann't assign IP address...\n"); + else { + req->rpd->ipaddr.owner = &ipdb; + req->rpd->ipaddr.peer_addr = attr->val.ipaddr; + req->rpd->ipaddr.addr = inet_addr(conf_gw_ip_address); + } + } else if (!strcmp(attr->attr->name, "Acct-Interim-Interval")) req->rpd->acct_interim_interval = attr->val.integer; } } @@ -83,20 +90,13 @@ static int check(struct pwdb_t *pwdb, struct ppp_t *ppp, const char *username, i return r; } -static int get_ip(struct ppp_t *ppp, in_addr_t *addr, in_addr_t *peer_addr) +static struct ipdb_item_t *get_ip(struct ppp_t *ppp) { struct radius_pd_t *rpd = find_pd(ppp); - if (rpd->ipaddr) { - if (!conf_gw_ip_address) { - log_warn("radius: gw-ip-address not specified, cann't assign IP address...\n"); - return -1; - } - *peer_addr = rpd->ipaddr; - *addr = inet_addr(conf_gw_ip_address); - return 0; - } - return -1; + if (rpd->ipaddr.peer_addr) + return &rpd->ipaddr; + return NULL; } static void ppp_starting(struct ppp_notified_t *n, struct ppp_t *ppp) @@ -172,7 +172,7 @@ struct radius_pd_t *rad_find_session(const char *sessionid, const char *username continue; if (port_id >= 0 && port_id != rpd->ppp->unit_idx) continue; - if (ipaddr && ipaddr != rpd->ipaddr) + if (ipaddr && ipaddr != rpd->ipaddr.peer_addr) continue; pthread_mutex_lock(&rpd->lock); pthread_rwlock_unlock(&sessions_lock); @@ -201,6 +201,9 @@ struct radius_pd_t *rad_find_session_pack(struct rad_packet_t *pack) ipaddr = attr->val.ipaddr; } + if (!sessionid && !username && port_id == -1 && ipaddr == 0) + return NULL; + if (username && !sessionid) return NULL; diff --git a/accel-pptpd/radius/radius.h b/accel-pptpd/radius/radius.h index cededbe8..99cb7e42 100644 --- a/accel-pptpd/radius/radius.h +++ b/accel-pptpd/radius/radius.h @@ -7,6 +7,7 @@ #include "triton.h" #include "ppp.h" +#include "ipdb.h" #define REQ_LENGTH_MAX 4096 @@ -40,9 +41,11 @@ struct radius_pd_t struct rad_req_t *acct_req; struct triton_timer_t acct_interim_timer; + struct rad_packet_t *dm_coa_req; + struct sockaddr_in dm_coa_addr; - in_addr_t ipaddr; + struct ipdb_item_t ipaddr; int acct_interim_interval; }; |