Reduce the interface MTU by 2 when MPPE has been successfully negotiated.
This is necessary because MPPE will combine the protocol id with the payload received on the tun interface, encrypt it, then prepend its own protocol id, effectively increasing the payload by two bytes.
This commit is contained in:
parent
4bb6aac05e
commit
6301d506fb
@ -276,7 +276,8 @@ bundle_LayerUp(void *v, struct fsm *fp)
|
||||
bundle_StartIdleTimer(bundle, 0);
|
||||
bundle_Notify(bundle, EX_NORMAL);
|
||||
mp_CheckAutoloadTimer(&fp->bundle->ncp.mp);
|
||||
}
|
||||
} else if (fp->proto == PROTO_CCP)
|
||||
bundle_CalculateBandwidth(fp->bundle); /* Against ccp_MTUOverhead */
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1816,11 +1817,16 @@ void
|
||||
bundle_CalculateBandwidth(struct bundle *bundle)
|
||||
{
|
||||
struct datalink *dl;
|
||||
int sp;
|
||||
int sp, overhead, maxoverhead;
|
||||
|
||||
bundle->bandwidth = 0;
|
||||
bundle->iface->mtu = 0;
|
||||
for (dl = bundle->links; dl; dl = dl->next)
|
||||
maxoverhead = 0;
|
||||
|
||||
for (dl = bundle->links; dl; dl = dl->next) {
|
||||
overhead = ccp_MTUOverhead(&dl->physical->link.ccp);
|
||||
if (maxoverhead < overhead)
|
||||
maxoverhead = overhead;
|
||||
if (dl->state == DATALINK_OPEN) {
|
||||
if ((sp = dl->mp.bandwidth) == 0 &&
|
||||
(sp = physical_GetSpeed(dl->physical)) == 0)
|
||||
@ -1833,13 +1839,17 @@ bundle_CalculateBandwidth(struct bundle *bundle)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(bundle->bandwidth == 0)
|
||||
bundle->bandwidth = 115200; /* Shrug */
|
||||
|
||||
if (bundle->ncp.mp.active)
|
||||
if (bundle->ncp.mp.active) {
|
||||
bundle->iface->mtu = bundle->ncp.mp.peer_mrru;
|
||||
else if (!bundle->iface->mtu)
|
||||
overhead = ccp_MTUOverhead(&bundle->ncp.mp.link.ccp);
|
||||
if (maxoverhead < overhead)
|
||||
maxoverhead = overhead;
|
||||
} else if (!bundle->iface->mtu)
|
||||
bundle->iface->mtu = DEF_MRU;
|
||||
|
||||
#ifndef NORADIUS
|
||||
@ -1851,6 +1861,12 @@ bundle_CalculateBandwidth(struct bundle *bundle)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (maxoverhead) {
|
||||
log_Printf(LogLCP, "Reducing MTU from %d to %d (CCP requirement)\n",
|
||||
bundle->iface->mtu, bundle->iface->mtu - maxoverhead);
|
||||
bundle->iface->mtu -= maxoverhead;
|
||||
}
|
||||
|
||||
tun_configure(bundle);
|
||||
|
||||
route_UpdateMTU(bundle);
|
||||
|
@ -299,6 +299,19 @@ ccp_Required(struct ccp *ccp)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Report whether it's possible to increase a packet's size after
|
||||
* compression (and by how much).
|
||||
*/
|
||||
int
|
||||
ccp_MTUOverhead(struct ccp *ccp)
|
||||
{
|
||||
if (ccp->fsm.state == ST_OPENED)
|
||||
return algorithm[ccp->out.algorithm]->o.MTUOverhead;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
CcpInitRestartCounter(struct fsm *fp, int what)
|
||||
{
|
||||
@ -474,7 +487,24 @@ CcpLayerUp(struct fsm *fp)
|
||||
/* We're now up */
|
||||
struct ccp *ccp = fsm2ccp(fp);
|
||||
struct ccp_opt **o;
|
||||
int f;
|
||||
int f, fail;
|
||||
|
||||
for (f = fail = 0; f < NALGORITHMS; f++)
|
||||
if (IsEnabled(ccp->cfg.neg[algorithm[f]->Neg]) &&
|
||||
(*algorithm[f]->Required)(&ccp->fsm) &&
|
||||
(ccp->in.algorithm != f || ccp->out.algorithm != f)) {
|
||||
/* Blow it all away - we haven't negotiated a required algorithm */
|
||||
log_Printf(LogWARN, "%s: Failed to negotiate (required) %s\n",
|
||||
fp->link->name, protoname(algorithm[f]->id));
|
||||
fail = 1;
|
||||
}
|
||||
|
||||
if (fail) {
|
||||
ccp->his_proto = ccp->my_proto = -1;
|
||||
fsm_Close(fp);
|
||||
fsm_Close(&fp->link->lcp.fsm);
|
||||
return 0;
|
||||
}
|
||||
|
||||
log_Printf(LogCCP, "%s: LayerUp.\n", fp->link->name);
|
||||
|
||||
|
@ -135,6 +135,7 @@ struct ccp_algorithm {
|
||||
void (*DictSetup)(void *, struct ccp *, u_short, struct mbuf *);
|
||||
} i;
|
||||
struct {
|
||||
int MTUOverhead;
|
||||
void (*OptInit)(struct lcp_opt *, const struct ccp_config *);
|
||||
int (*Set)(struct lcp_opt *, const struct ccp_config *);
|
||||
void *(*Init)(struct lcp_opt *);
|
||||
@ -149,6 +150,7 @@ extern void ccp_Init(struct ccp *, struct bundle *, struct link *,
|
||||
const struct fsm_parent *);
|
||||
extern void ccp_Setup(struct ccp *);
|
||||
extern int ccp_Required(struct ccp *);
|
||||
extern int ccp_MTUOverhead(struct ccp *);
|
||||
|
||||
extern void ccp_SendResetReq(struct fsm *);
|
||||
extern struct mbuf *ccp_Input(struct bundle *, struct link *, struct mbuf *);
|
||||
|
@ -570,7 +570,8 @@ datalink_LayerUp(void *v, struct fsm *fp)
|
||||
auth_StartReq(&dl->chap.auth);
|
||||
} else
|
||||
datalink_AuthOk(dl);
|
||||
}
|
||||
} else if (fp->proto == PROTO_CCP)
|
||||
(*dl->parent->LayerUp)(dl->parent->object, &dl->physical->link.ccp.fsm);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -567,6 +567,7 @@ const struct ccp_algorithm PppdDeflateAlgorithm = {
|
||||
DeflateDictSetup
|
||||
},
|
||||
{
|
||||
0,
|
||||
DeflateInitOptsOutput,
|
||||
DeflateSetOptsOutput,
|
||||
DeflateInitOutput,
|
||||
@ -591,6 +592,7 @@ const struct ccp_algorithm DeflateAlgorithm = {
|
||||
DeflateDictSetup
|
||||
},
|
||||
{
|
||||
0,
|
||||
DeflateInitOptsOutput,
|
||||
DeflateSetOptsOutput,
|
||||
DeflateInitOutput,
|
||||
|
@ -167,6 +167,8 @@ static void
|
||||
mp_LayerUp(void *v, struct fsm *fp)
|
||||
{
|
||||
/* The given fsm (ccp) is now up */
|
||||
|
||||
bundle_CalculateBandwidth(fp->bundle); /* Against ccp_MTUOverhead */
|
||||
}
|
||||
|
||||
static void
|
||||
@ -646,6 +648,11 @@ mp_Output(struct mp *mp, struct bundle *bundle, struct link *l,
|
||||
mp->out.seq, m_length(m), l->name);
|
||||
mp->out.seq = inc_seq(mp->peer_is12bit, mp->out.seq);
|
||||
|
||||
if (l->ccp.fsm.state != ST_OPENED && ccp_Required(&l->ccp)) {
|
||||
log_Printf(LogPHASE, "%s: Not transmitting... waiting for CCP\n", l->name);
|
||||
return;
|
||||
}
|
||||
|
||||
link_PushPacket(l, m, bundle, LINK_QUEUES(l) - 1, PROTO_MP);
|
||||
}
|
||||
|
||||
|
@ -721,6 +721,7 @@ const struct ccp_algorithm MPPEAlgorithm = {
|
||||
MPPEDictSetup
|
||||
},
|
||||
{
|
||||
2,
|
||||
MPPEInitOptsOutput,
|
||||
MPPESetOptsOutput,
|
||||
MPPEInitOutput,
|
||||
|
@ -340,6 +340,7 @@ const struct ccp_algorithm Pred1Algorithm = {
|
||||
Pred1DictSetup
|
||||
},
|
||||
{
|
||||
0,
|
||||
Pred1InitOptsOutput,
|
||||
Pred1SetOptsOutput,
|
||||
Pred1InitOutput,
|
||||
|
Loading…
Reference in New Issue
Block a user