From 4d958e0557ea479093b13246e83aeef0cbaee22d Mon Sep 17 00:00:00 2001 From: Vladislav Grishenko Date: Sat, 28 Feb 2015 22:03:22 +0500 Subject: [PATCH] ppp: fix mtu/mru set if not negotiated on any end plus cleanup --- accel-pppd/ppp/lcp_opt_mru.c | 42 ++++++++++++++++++++++++------------------ accel-pppd/ppp/ppp.c | 4 ++-- 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 9a28817..1a6b187 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("",ntohs(opt16->val)); + print("", ntohs(opt16->val)); else - print("",mru_opt->mru); + print("", mru_opt->mru); } static void load_config(void) diff --git a/accel-pppd/ppp/ppp.c b/accel-pppd/ppp/ppp.c index bed84ab..3a3b2fc 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; } -- 1.7.2.5