summaryrefslogtreecommitdiff
path: root/accel-pptpd/ppp/lcp_opt_mru.c
diff options
context:
space:
mode:
authorKozlov Dmitry <dima@server>2010-09-23 09:54:52 +0400
committerKozlov Dmitry <dima@server>2010-09-23 09:54:52 +0400
commit82b0f0953159fc9ab8e387f5e6014dc377b14b38 (patch)
tree974bf5ff111aed10829c4326d627c9e26d7f2189 /accel-pptpd/ppp/lcp_opt_mru.c
parent3e61cb3f8d58f64c8023e95bf74341e6bc61560e (diff)
downloadaccel-ppp-82b0f0953159fc9ab8e387f5e6014dc377b14b38.tar.gz
accel-ppp-82b0f0953159fc9ab8e387f5e6014dc377b14b38.zip
radius: implemented attributes Calling-Station-Id, Called-Station-Id, NAS-IP-Address
radius: implemented extension Acct-Input-Gigawords, Acct-Output-Gigawords lcp: implemented maximum/minimum mtu/mru checks
Diffstat (limited to 'accel-pptpd/ppp/lcp_opt_mru.c')
-rw-r--r--accel-pptpd/ppp/lcp_opt_mru.c73
1 files changed, 43 insertions, 30 deletions
diff --git a/accel-pptpd/ppp/lcp_opt_mru.c b/accel-pptpd/ppp/lcp_opt_mru.c
index 4dc96851..f13b0148 100644
--- a/accel-pptpd/ppp/lcp_opt_mru.c
+++ b/accel-pptpd/ppp/lcp_opt_mru.c
@@ -13,7 +13,8 @@
#include "memdebug.h"
-#define MAX_MTU 1436
+static int conf_mtu;
+static int conf_min_mtu = 100;
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);
@@ -44,52 +45,52 @@ static struct lcp_option_handler_t mru_opt_hnd=
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=MAX_MTU;
- mru_opt->opt.id=CI_MRU;
- mru_opt->opt.len=4;
+ memset(mru_opt, 0, sizeof(*mru_opt));
+ mru_opt->mtu = 0;
+ mru_opt->mru = (conf_mtu && conf_mtu <= lcp->ppp->ctrl->max_mtu) ? conf_mtu : lcp->ppp->ctrl->max_mtu;
+ mru_opt->opt.id = CI_MRU;
+ 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);
+ 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.id=CI_MRU;
- opt16->hdr.len=4;
- opt16->val=htons(mru_opt->mru);
+ 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.id = 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.id=CI_MRU;
- opt16->hdr.len=4;
- opt16->val=htons(mru_opt->mtu);
+ 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.id = CI_MRU;
+ opt16->hdr.len = 4;
+ opt16->val = htons(mru_opt->mtu ? mru_opt->mtu : lcp->ppp->ctrl->max_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;
+ struct mru_option_t *mru_opt = container_of(opt,typeof(*mru_opt),opt);
+ struct lcp_opt16_t *opt16 = (struct lcp_opt16_t*)ptr;
+
+ if (ntohs(opt16->val) < conf_min_mtu || ntohs(opt16->val) > lcp->ppp->ctrl->max_mtu)
+ return LCP_OPT_NAK;
+
+ mru_opt->mtu = ntohs(opt16->val);
+ return LCP_OPT_ACK;
}
static int mru_recv_conf_ack(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr)
@@ -110,17 +111,29 @@ static int mru_recv_conf_ack(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, ui
return 0;
}
-static void mru_print(void (*print)(const char *fmt,...),struct lcp_option_t *opt, uint8_t *ptr)
+static void mru_print(void (*print)(const char *fmt,...), 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;
+ struct mru_option_t *mru_opt = container_of(opt, typeof(*mru_opt), opt);
+ struct lcp_opt16_t *opt16 = (struct lcp_opt16_t*)ptr;
- if (ptr) print("<mru %i>",ntohs(opt16->val));
- else print("<mru %i>",mru_opt->mru);
+ if (ptr)
+ print("<mru %i>",ntohs(opt16->val));
+ else
+ print("<mru %i>",mru_opt->mru);
}
static void __init mru_opt_init()
{
+ char *opt;
+
+ opt = conf_get_opt("ppp", "mtu");
+ if (opt && atoi(opt) > 0)
+ conf_mtu = atoi(opt);
+
+ opt = conf_get_opt("ppp", "min-mtu");
+ if (opt && atoi(opt) > 0)
+ conf_min_mtu = atoi(opt);
+
lcp_option_register(&mru_opt_hnd);
}