diff options
author | Kozlov Dmitry <dima@server> | 2010-08-17 17:29:46 +0400 |
---|---|---|
committer | Kozlov Dmitry <dima@server> | 2010-08-17 17:29:46 +0400 |
commit | 760d8427f133df486a145e6e7ac7610caf2356fc (patch) | |
tree | ebd109efc8882e56165e05f050dd30c9313bb9c7 /accel-pptpd/lcp_base_opt.c | |
parent | ab418b16bf2c9a57dbb7c18141af2eb283c44447 (diff) | |
download | accel-ppp-760d8427f133df486a145e6e7ac7610caf2356fc.tar.gz accel-ppp-760d8427f133df486a145e6e7ac7610caf2356fc.zip |
reworked/rewrited lcp handling code to become more abstract
Diffstat (limited to 'accel-pptpd/lcp_base_opt.c')
-rw-r--r-- | accel-pptpd/lcp_base_opt.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/accel-pptpd/lcp_base_opt.c b/accel-pptpd/lcp_base_opt.c new file mode 100644 index 00000000..352dee24 --- /dev/null +++ b/accel-pptpd/lcp_base_opt.c @@ -0,0 +1,75 @@ +#include "ppp_lcp.h" + +static struct lcp_option_t *mru_init(struct ppp_lcp_t *lcp); +static void mru_free(struct ppp_lcp_t *lcp, struct lcp_option_t *opt); +static int mru_send_conf_req(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr); +static int mru_send_conf_nak(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr); +static int mru_recv_conf_req(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr); + +struct mru_option_t +{ + struct lcp_option_t opt; + int mru; + int mtu; +}; + +static struct lcp_option_handler_t opt_mru= +{ + .id=CI_MRU, + .init=mru_init, + .send_conf_req=mru_send_conf_req, + .send_conf_nak=mru_send_conf_nak, + .recv_conf_req=mru_recv_conf_req, + .free=mru_free, +}; + +static struct lcp_option_t *mru_init(struct ppp_lcp_t *lcp) +{ + struct mru_option_t *mru_opt=malloc(sizeof(*mru_opt)); + memset(mru_opt,0,sizeof(*mru_opt)); + mru_opt->mtu=0; + mru_opt->mru=1500; + mru_opt->opt.len=4; + + return &mru_opt->opt; +} + +static void mru_free(struct ppp_lcp_t *lcp, struct lcp_option_t *opt) +{ + struct mru_option_t *mru_opt=container_of(opt,typeof(*mru_opt),opt); + + free(mru_opt); +} + +static int mru_send_conf_req(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr) +{ + struct mru_option_t *mru_opt=container_of(opt,typeof(*mru_opt),opt); + struct lcp_opt16_t *opt16=(struct lcp_opt16_t*)ptr; + opt16->hdr.type=CI_MRU; + opt16->hdr.len=4; + opt16->val=htons(mru_opt->mru); + return 4; +} + +static int mru_send_conf_nak(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr) +{ + struct mru_option_t *mru_opt=container_of(opt,typeof(*mru_opt),opt); + struct lcp_opt16_t *opt16=(struct lcp_opt16_t*)ptr; + opt16->hdr.type=CI_MRU; + opt16->hdr.len=4; + opt16->val=htons(mru_opt->mtu); + return 4; +} + +static int mru_recv_conf_req(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr) +{ + struct mru_option_t *mru_opt=container_of(opt,typeof(*mru_opt),opt); + struct lcp_opt16_t *opt16=(struct lcp_opt16_t*)ptr; + + if (!mru_opt->mtu || mru_opt->mtu==ntohs(opt16->val)) + { + mru_opt->mtu=ntohs(opt16->val); + return LCP_OPT_ACK; + }else return LCP_OPT_NAK; +} + |