diff options
author | Kozlov Dmitry <dima@server> | 2011-01-28 14:41:44 +0300 |
---|---|---|
committer | Kozlov Dmitry <dima@server> | 2011-01-28 14:41:44 +0300 |
commit | a69ae308efe400d14ecbab676a5e7592908c6b46 (patch) | |
tree | 664b19521bc0fe81f7863aba2218ec54ba1826e2 /accel-pppd | |
parent | 673bea74d2beb8d4260355f928499230c7ff9b17 (diff) | |
download | accel-ppp-a69ae308efe400d14ecbab676a5e7592908c6b46.tar.gz accel-ppp-a69ae308efe400d14ecbab676a5e7592908c6b46.zip |
ppp: send ConfNak with random magic number if magic number in CanfReq is equal to self magic number
Diffstat (limited to 'accel-pppd')
-rw-r--r-- | accel-pppd/ppp/lcp_opt_magic.c | 56 | ||||
-rw-r--r-- | accel-pppd/ppp/ppp_lcp.c | 9 | ||||
-rw-r--r-- | accel-pppd/radius/stat_accm.c | 1 |
3 files changed, 42 insertions, 24 deletions
diff --git a/accel-pppd/ppp/lcp_opt_magic.c b/accel-pppd/ppp/lcp_opt_magic.c index 4a61ef91..6c0deb54 100644 --- a/accel-pppd/ppp/lcp_opt_magic.c +++ b/accel-pppd/ppp/lcp_opt_magic.c @@ -11,6 +11,7 @@ static struct lcp_option_t *magic_init(struct ppp_lcp_t *lcp); static void magic_free(struct ppp_lcp_t *lcp, struct lcp_option_t *opt); static int magic_send_conf_req(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr); +static int magic_send_conf_nak(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr); static int magic_recv_conf_req(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr); static void magic_print(void (*print)(const char *fmt,...),struct lcp_option_t*, uint8_t *ptr); @@ -22,20 +23,21 @@ struct magic_option_t static struct lcp_option_handler_t magic_opt_hnd= { - .init=magic_init, - .send_conf_req=magic_send_conf_req, - .recv_conf_req=magic_recv_conf_req, - .free=magic_free, - .print=magic_print, + .init = magic_init, + .send_conf_req = magic_send_conf_req, + .send_conf_nak = magic_send_conf_nak, + .recv_conf_req = magic_recv_conf_req, + .free = magic_free, + .print = magic_print, }; static struct lcp_option_t *magic_init(struct ppp_lcp_t *lcp) { - struct magic_option_t *magic_opt=_malloc(sizeof(*magic_opt)); - memset(magic_opt,0,sizeof(*magic_opt)); - magic_opt->magic=random(); - magic_opt->opt.id=CI_MAGIC; - magic_opt->opt.len=6; + struct magic_option_t *magic_opt = _malloc(sizeof(*magic_opt)); + memset(magic_opt, 0, sizeof(*magic_opt)); + magic_opt->magic = random(); + magic_opt->opt.id = CI_MAGIC; + magic_opt->opt.len = 6; lcp->magic = magic_opt->magic; @@ -44,7 +46,7 @@ static struct lcp_option_t *magic_init(struct ppp_lcp_t *lcp) static void magic_free(struct ppp_lcp_t *lcp, struct lcp_option_t *opt) { - struct magic_option_t *magic_opt=container_of(opt,typeof(*magic_opt),opt); + struct magic_option_t *magic_opt = container_of(opt,typeof(*magic_opt),opt); _free(magic_opt); } @@ -52,17 +54,27 @@ static void magic_free(struct ppp_lcp_t *lcp, struct lcp_option_t *opt) static int magic_send_conf_req(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr) { struct magic_option_t *magic_opt=container_of(opt,typeof(*magic_opt),opt); - struct lcp_opt32_t *opt32=(struct lcp_opt32_t*)ptr; + struct lcp_opt32_t *opt32 = (struct lcp_opt32_t *)ptr; opt32->hdr.id=CI_MAGIC; opt32->hdr.len=6; opt32->val=htonl(magic_opt->magic); return 6; } -static int magic_recv_conf_req(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr) +static int magic_send_conf_nak(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr) { struct magic_option_t *magic_opt=container_of(opt,typeof(*magic_opt),opt); - struct lcp_opt32_t *opt32=(struct lcp_opt32_t*)ptr; + struct lcp_opt32_t *opt32 = (struct lcp_opt32_t *)ptr; + opt32->hdr.id=CI_MAGIC; + opt32->hdr.len=6; + opt32->val=random(); + return 6; +} + +static int magic_recv_conf_req(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr) +{ + struct magic_option_t *magic_opt = container_of(opt, typeof(*magic_opt), opt); + struct lcp_opt32_t *opt32 = (struct lcp_opt32_t *)ptr; /*if (!ptr) return LCP_OPT_NAK;*/ @@ -70,19 +82,21 @@ static int magic_recv_conf_req(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, if (opt32->hdr.len != 6) return LCP_OPT_REJ; - if (magic_opt->magic==ntohl(opt32->val)) - { - log_ppp_error("loop detected"); - return -1; - } + if (magic_opt->magic == ntohl(opt32->val)) + return LCP_OPT_NAK; + return LCP_OPT_ACK; } static void magic_print(void (*print)(const char *fmt,...),struct lcp_option_t *opt, uint8_t *ptr) { - struct magic_option_t *magic_opt=container_of(opt,typeof(*magic_opt),opt); + struct magic_option_t *magic_opt = container_of(opt, typeof(*magic_opt), opt); + struct lcp_opt32_t *opt32 = (struct lcp_opt32_t *)ptr; - print("<magic %04x>",magic_opt->magic); + if (ptr) + print("<magic %04x>", ntohl(opt32->val)); + else + print("<magic %04x>", magic_opt->magic); } static void __init magic_opt_init() diff --git a/accel-pppd/ppp/ppp_lcp.c b/accel-pppd/ppp/ppp_lcp.c index 10e25fb1..c46c5a49 100644 --- a/accel-pppd/ppp/ppp_lcp.c +++ b/accel-pppd/ppp/ppp_lcp.c @@ -281,6 +281,7 @@ static void send_conf_nak(struct ppp_fsm_t *fsm) uint8_t *buf = _malloc(lcp->conf_req_len), *ptr = buf; struct lcp_hdr_t *lcp_hdr = (struct lcp_hdr_t*)ptr; struct lcp_option_t *lopt; + int n; if (conf_ppp_verbose) log_ppp_info2("send [LCP ConfNak id=%x", lcp->fsm.recv_id); @@ -294,12 +295,14 @@ static void send_conf_nak(struct ppp_fsm_t *fsm) list_for_each_entry(lopt, &lcp->options, entry) { if (lopt->state == LCP_OPT_NAK) { - ptr+=lopt->h->send_conf_nak(lcp,lopt,ptr); + n = lopt->h->send_conf_nak(lcp, lopt, ptr); - if (conf_ppp_verbose) { + if (conf_ppp_verbose && n) { log_ppp_info2(" "); - lopt->h->print(log_ppp_info2, lopt, NULL); + lopt->h->print(log_ppp_info2, lopt, ptr); } + + ptr += n; } } diff --git a/accel-pppd/radius/stat_accm.c b/accel-pppd/radius/stat_accm.c index 9367ceb3..8d4ad3df 100644 --- a/accel-pppd/radius/stat_accm.c +++ b/accel-pppd/radius/stat_accm.c @@ -1,4 +1,5 @@ #include <string.h> +#include <stdlib.h> #include "radius_p.h" #include "mempool.h" |