summaryrefslogtreecommitdiff
path: root/accel-pppd
diff options
context:
space:
mode:
authorVladislav Grishenko <themiron@mail.ru>2015-02-28 22:03:22 +0500
committerDmitry Kozlov <xeb@mail.ru>2015-03-05 15:23:23 +0300
commitc5e859f1d3a4317f304366e5f083ef4ff7828e5d (patch)
treebf90d533f1e332016df5bdcd0ce62cd559d5f3c9 /accel-pppd
parent26a89d0fc3c2c015f68c80bddfdcbda963396271 (diff)
downloadaccel-ppp-c5e859f1d3a4317f304366e5f083ef4ff7828e5d.tar.gz
accel-ppp-c5e859f1d3a4317f304366e5f083ef4ff7828e5d.zip
ppp: fix mtu/mru set if not negotiated on any end plus cleanup
Diffstat (limited to 'accel-pppd')
-rw-r--r--accel-pppd/ppp/lcp_opt_mru.c42
-rw-r--r--accel-pppd/ppp/ppp.c4
2 files changed, 26 insertions, 20 deletions
diff --git a/accel-pppd/ppp/lcp_opt_mru.c b/accel-pppd/ppp/lcp_opt_mru.c
index 9a288171..1a6b187d 100644
--- a/accel-pppd/ppp/lcp_opt_mru.c
+++ b/accel-pppd/ppp/lcp_opt_mru.c
@@ -27,7 +27,7 @@ static int mru_send_conf_nak(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, ui
static int mru_recv_conf_req(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr);
static int mru_recv_conf_ack(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr);
static int mru_recv_conf_nak(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, uint8_t *ptr);
-static void mru_print(void (*print)(const char *fmt,...),struct lcp_option_t*, uint8_t *ptr);
+static void mru_print(void (*print)(const char *fmt, ...), struct lcp_option_t*, uint8_t *ptr);
struct mru_option_t
{
@@ -39,19 +39,20 @@ struct mru_option_t
static struct lcp_option_handler_t mru_opt_hnd=
{
- .init=mru_init,
- .send_conf_req=mru_send_conf_req,
- .send_conf_nak=mru_send_conf_nak,
- .recv_conf_req=mru_recv_conf_req,
- .recv_conf_ack=mru_recv_conf_ack,
- .recv_conf_nak=mru_recv_conf_nak,
- .free=mru_free,
- .print=mru_print,
+ .init = mru_init,
+ .send_conf_req = mru_send_conf_req,
+ .send_conf_nak = mru_send_conf_nak,
+ .recv_conf_req = mru_recv_conf_req,
+ .recv_conf_ack = mru_recv_conf_ack,
+ .recv_conf_nak = mru_recv_conf_nak,
+ .free = mru_free,
+ .print = mru_print,
};
static struct lcp_option_t *mru_init(struct ppp_lcp_t *lcp)
{
- struct mru_option_t *mru_opt=_malloc(sizeof(*mru_opt));
+ struct mru_option_t *mru_opt = _malloc(sizeof(*mru_opt));
+
memset(mru_opt, 0, sizeof(*mru_opt));
mru_opt->mru = (conf_mru && conf_mru <= lcp->ppp->ses.ctrl->max_mtu) ? conf_mru : lcp->ppp->ses.ctrl->max_mtu;
if (mru_opt->mru > conf_max_mtu)
@@ -62,6 +63,9 @@ static struct lcp_option_t *mru_init(struct ppp_lcp_t *lcp)
mru_opt->opt.id = CI_MRU;
mru_opt->opt.len = 4;
+ lcp->ppp->mru = mru_opt->mru;
+ lcp->ppp->mtu = mru_opt->mtu;
+
return &mru_opt->opt;
}
@@ -74,7 +78,7 @@ 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)
{
- 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);
struct lcp_opt16_t *opt16 = (struct lcp_opt16_t*)ptr;
if (mru_opt->naked)
@@ -88,8 +92,9 @@ static int mru_send_conf_req(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, ui
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 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);
@@ -98,7 +103,7 @@ static int mru_send_conf_nak(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, ui
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 mru_option_t *mru_opt = container_of(opt, typeof(*mru_opt), opt);
struct lcp_opt16_t *opt16 = (struct lcp_opt16_t*)ptr;
/*if (!ptr)
@@ -118,7 +123,7 @@ static int mru_recv_conf_req(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, ui
static int mru_recv_conf_ack(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 mru_option_t *mru_opt = container_of(opt, typeof(*mru_opt), opt);
if (ioctl(lcp->ppp->chan_fd, PPPIOCSMRU, &mru_opt->mru) &&
errno != EIO && errno != ENOTTY)
@@ -131,20 +136,21 @@ static int mru_recv_conf_ack(struct ppp_lcp_t *lcp, struct lcp_option_t *opt, ui
static int mru_recv_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 mru_option_t *mru_opt = container_of(opt, typeof(*mru_opt), opt);
+
mru_opt->naked = 1;
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;
if (ptr)
- print("<mru %i>",ntohs(opt16->val));
+ print("<mru %i>", ntohs(opt16->val));
else
- print("<mru %i>",mru_opt->mru);
+ print("<mru %i>", mru_opt->mru);
}
static void load_config(void)
diff --git a/accel-pppd/ppp/ppp.c b/accel-pppd/ppp/ppp.c
index bed84ab6..3a3b2fcc 100644
--- a/accel-pppd/ppp/ppp.c
+++ b/accel-pppd/ppp/ppp.c
@@ -185,12 +185,12 @@ int __export connect_ppp_channel(struct ppp_t *ppp)
ifr.ifr_mtu = ppp->mtu;
strcpy(ifr.ifr_name, ppp->ses.ifname);
- if (ioctl(sock_fd, SIOCSIFMTU, &ifr)) {
+ if (ppp->mtu && ioctl(sock_fd, SIOCSIFMTU, &ifr)) {
log_ppp_error("failed to set MTU: %s\n", strerror(errno));
goto exit_close_unit;
}
- if (ioctl(ppp->unit_fd, PPPIOCSMRU, &ppp->mru)) {
+ if (ppp->mru && ioctl(ppp->unit_fd, PPPIOCSMRU, &ppp->mru)) {
log_ppp_error("failed to set MRU: %s\n", strerror(errno));
goto exit_close_unit;
}