Lines Matching full:mp

77 #include "mp.h"
136 mp_ReadHeader(struct mp *mp, struct mbuf *m, struct mp_header *header) in mp_ReadHeader() argument
138 if (mp->local_is12bit) { in mp_ReadHeader()
143 log_Printf(LogWARN, "Oops - MP header without required zero bits\n"); in mp_ReadHeader()
153 log_Printf(LogWARN, "Oops - MP header without required zero bits\n"); in mp_ReadHeader()
194 struct mp *mp = (struct mp *)v; in mp_UpDown() local
197 percent = MAX(mp->link.stats.total.in.OctetsPerSecond, in mp_UpDown()
198 mp->link.stats.total.out.OctetsPerSecond) * 800 / in mp_UpDown()
199 mp->bundle->bandwidth; in mp_UpDown()
200 if (percent >= mp->cfg.autoload.max) { in mp_UpDown()
202 bundle_AutoAdjust(mp->bundle, percent, AUTO_UP); in mp_UpDown()
203 } else if (percent <= mp->cfg.autoload.min) { in mp_UpDown()
205 bundle_AutoAdjust(mp->bundle, percent, AUTO_DOWN); in mp_UpDown()
210 mp_StopAutoloadTimer(struct mp *mp) in mp_StopAutoloadTimer() argument
212 throughput_stop(&mp->link.stats.total); in mp_StopAutoloadTimer()
216 mp_CheckAutoloadTimer(struct mp *mp) in mp_CheckAutoloadTimer() argument
218 if (mp->link.stats.total.SamplePeriod != mp->cfg.autoload.period) { in mp_CheckAutoloadTimer()
219 throughput_destroy(&mp->link.stats.total); in mp_CheckAutoloadTimer()
220 throughput_init(&mp->link.stats.total, mp->cfg.autoload.period); in mp_CheckAutoloadTimer()
221 throughput_callback(&mp->link.stats.total, mp_UpDown, mp); in mp_CheckAutoloadTimer()
224 if (bundle_WantAutoloadTimer(mp->bundle)) in mp_CheckAutoloadTimer()
225 throughput_start(&mp->link.stats.total, "MP throughput", 1); in mp_CheckAutoloadTimer()
227 mp_StopAutoloadTimer(mp); in mp_CheckAutoloadTimer()
231 mp_RestartAutoloadTimer(struct mp *mp) in mp_RestartAutoloadTimer() argument
233 if (mp->link.stats.total.SamplePeriod != mp->cfg.autoload.period) in mp_RestartAutoloadTimer()
234 mp_CheckAutoloadTimer(mp); in mp_RestartAutoloadTimer()
236 throughput_clear(&mp->link.stats.total, THROUGHPUT_OVERALL, NULL); in mp_RestartAutoloadTimer()
240 mp_Init(struct mp *mp, struct bundle *bundle) in mp_Init() argument
242 mp->peer_is12bit = mp->local_is12bit = 0; in mp_Init()
243 mp->peer_mrru = mp->local_mrru = 0; in mp_Init()
245 peerid_Init(&mp->peer); in mp_Init()
247 mp->out.seq = 0; in mp_Init()
248 mp->out.link = 0; in mp_Init()
249 mp->out.af = AF_INET; in mp_Init()
250 mp->seq.min_in = 0; in mp_Init()
251 mp->seq.next_in = 0; in mp_Init()
252 mp->inbufs = NULL; in mp_Init()
253 mp->bundle = bundle; in mp_Init()
255 mp->link.type = LOGICAL_LINK; in mp_Init()
256 mp->link.name = "mp"; in mp_Init()
257 mp->link.len = sizeof *mp; in mp_Init()
259 mp->cfg.autoload.period = SAMPLE_PERIOD; in mp_Init()
260 mp->cfg.autoload.min = mp->cfg.autoload.max = 0; in mp_Init()
261 throughput_init(&mp->link.stats.total, mp->cfg.autoload.period); in mp_Init()
262 throughput_callback(&mp->link.stats.total, mp_UpDown, mp); in mp_Init()
263 mp->link.stats.parent = NULL; in mp_Init()
264 mp->link.stats.gather = 0; /* Let the physical links gather stats */ in mp_Init()
265 memset(mp->link.Queue, '\0', sizeof mp->link.Queue); in mp_Init()
266 memset(mp->link.proto_in, '\0', sizeof mp->link.proto_in); in mp_Init()
267 memset(mp->link.proto_out, '\0', sizeof mp->link.proto_out); in mp_Init()
269 mp->fsmp.LayerStart = mp_LayerStart; in mp_Init()
270 mp->fsmp.LayerUp = mp_LayerUp; in mp_Init()
271 mp->fsmp.LayerDown = mp_LayerDown; in mp_Init()
272 mp->fsmp.LayerFinish = mp_LayerFinish; in mp_Init()
273 mp->fsmp.object = mp; in mp_Init()
275 mpserver_Init(&mp->server); in mp_Init()
277 mp->cfg.mrru = 0; in mp_Init()
278 mp->cfg.shortseq = NEG_ENABLED|NEG_ACCEPTED; in mp_Init()
279 mp->cfg.negenddisc = NEG_ENABLED|NEG_ACCEPTED; in mp_Init()
280 mp->cfg.enddisc.class = 0; in mp_Init()
281 *mp->cfg.enddisc.address = '\0'; in mp_Init()
282 mp->cfg.enddisc.len = 0; in mp_Init()
284 lcp_Init(&mp->link.lcp, mp->bundle, &mp->link, NULL); in mp_Init()
285 ccp_Init(&mp->link.ccp, mp->bundle, &mp->link, &mp->fsmp); in mp_Init()
287 link_EmptyStack(&mp->link); in mp_Init()
288 link_Stack(&mp->link, &protolayer); in mp_Init()
289 link_Stack(&mp->link, &ccplayer); in mp_Init()
290 link_Stack(&mp->link, &vjlayer); in mp_Init()
292 link_Stack(&mp->link, &natlayer); in mp_Init()
297 mp_Up(struct mp *mp, struct datalink *dl) in mp_Up() argument
301 if (mp->active) { in mp_Up()
303 if (!peerid_Equal(&dl->peer, &mp->peer)) { in mp_Up()
305 log_Printf(LogPHASE, " Attached to peer %s/%s\n", mp->peer.authname, in mp_Up()
306 mp_Enddisc(mp->peer.enddisc.class, mp->peer.enddisc.address, in mp_Up()
307 mp->peer.enddisc.len)); in mp_Up()
313 if (mp->local_mrru != lcp->want_mrru || in mp_Up()
314 mp->peer_mrru != lcp->his_mrru || in mp_Up()
315 mp->local_is12bit != lcp->want_shortseq || in mp_Up()
316 mp->peer_is12bit != lcp->his_shortseq) { in mp_Up()
317 log_Printf(LogPHASE, "%s: Invalid MRRU/SHORTSEQ MP parameters !\n", in mp_Up()
325 mp->local_mrru = lcp->want_mrru; in mp_Up()
326 mp->peer_mrru = lcp->his_mrru; in mp_Up()
327 mp->local_is12bit = lcp->want_shortseq; in mp_Up()
328 mp->peer_is12bit = lcp->his_shortseq; in mp_Up()
329 mp->peer = dl->peer; in mp_Up()
331 throughput_destroy(&mp->link.stats.total); in mp_Up()
332 throughput_init(&mp->link.stats.total, mp->cfg.autoload.period); in mp_Up()
333 throughput_callback(&mp->link.stats.total, mp_UpDown, mp); in mp_Up()
334 memset(mp->link.Queue, '\0', sizeof mp->link.Queue); in mp_Up()
335 memset(mp->link.proto_in, '\0', sizeof mp->link.proto_in); in mp_Up()
336 memset(mp->link.proto_out, '\0', sizeof mp->link.proto_out); in mp_Up()
339 dl->physical->link.stats.parent = &mp->link.stats.total; in mp_Up()
341 mp->out.seq = 0; in mp_Up()
342 mp->out.link = 0; in mp_Up()
343 mp->out.af = AF_INET; in mp_Up()
344 mp->seq.min_in = 0; in mp_Up()
345 mp->seq.next_in = 0; in mp_Up()
351 switch (mpserver_Open(&mp->server, &mp->peer)) { in mp_Up()
353 log_Printf(LogPHASE, "mp: Transfer link on %s\n", in mp_Up()
354 mp->server.socket.sun_path); in mp_Up()
355 mp->server.send.dl = dl; /* Defer 'till it's safe to send */ in mp_Up()
360 log_Printf(LogPHASE, "mp: Listening on %s\n", mp->server.socket.sun_path); in mp_Up()
363 /* Re-point our NCP layers at our MP link */ in mp_Up()
364 ncp_SetLink(&mp->bundle->ncp, &mp->link); in mp_Up()
367 if (ccp_SetOpenMode(&mp->link.ccp)) { in mp_Up()
368 fsm_Up(&mp->link.ccp.fsm); in mp_Up()
369 fsm_Open(&mp->link.ccp.fsm); in mp_Up()
372 mp->active = 1; in mp_Up()
381 mp_Down(struct mp *mp) in mp_Down() argument
383 if (mp->active) { in mp_Down()
387 mp_StopAutoloadTimer(mp); in mp_Down()
390 mpserver_Close(&mp->server); in mp_Down()
393 fsm2initial(&mp->link.ccp.fsm); in mp_Down()
396 while (mp->inbufs) { in mp_Down()
397 next = mp->inbufs->m_nextpkt; in mp_Down()
398 m_freem(mp->inbufs); in mp_Down()
399 mp->inbufs = next; in mp_Down()
402 peerid_Init(&mp->peer); in mp_Down()
403 mp->active = 0; in mp_Down()
415 mp_Assemble(struct mp *mp, struct mbuf *m, struct physical *p) in mp_Assemble() argument
427 if (m && mp_ReadHeader(mp, m, &mh) == 0) { in mp_Assemble()
433 seq = p->dl->mp.seq; in mp_Assemble()
434 p->dl->mp.seq = mh.seq; in mp_Assemble()
436 seq = mp->seq.min_in; in mp_Assemble()
438 if (mp->seq.min_in == seq) { in mp_Assemble()
445 mp->seq.min_in = (u_int32_t)-1; in mp_Assemble()
446 for (dl = mp->bundle->links; dl; dl = dl->next) in mp_Assemble()
448 (mp->seq.min_in == (u_int32_t)-1 || in mp_Assemble()
449 isbefore(mp->local_is12bit, dl->mp.seq, mp->seq.min_in))) in mp_Assemble()
450 mp->seq.min_in = dl->mp.seq; in mp_Assemble()
460 seq = mp->seq.next_in; in mp_Assemble()
461 q = mp->inbufs; in mp_Assemble()
467 mp->inbufs = m; in mp_Assemble()
472 mp_ReadHeader(mp, q, &h); in mp_Assemble()
474 if (m && isbefore(mp->local_is12bit, mh.seq, h.seq)) { in mp_Assemble()
479 mp->inbufs = m; in mp_Assemble()
489 if (isbefore(mp->local_is12bit, seq, mp->seq.min_in)) { in mp_Assemble()
494 while (mp->inbufs != q) { in mp_Assemble()
496 next = mp->inbufs->m_nextpkt; in mp_Assemble()
497 m_freem(mp->inbufs); in mp_Assemble()
498 mp->inbufs = next; in mp_Assemble()
507 mp_ReadHeader(mp, mp->inbufs, &h); in mp_Assemble()
513 next = mp->inbufs->m_nextpkt; in mp_Assemble()
515 m_freem(mp->inbufs); in mp_Assemble()
516 mp->inbufs = next; in mp_Assemble()
517 } while (mp->inbufs && (isbefore(mp->local_is12bit, mp->seq.min_in, in mp_Assemble()
528 mp->seq.next_in = seq = inc_seq(mp->local_is12bit, h.seq); in mp_Assemble()
530 q = mp->inbufs; in mp_Assemble()
541 *frag = mp->inbufs; in mp_Assemble()
542 mp->inbufs = mp->inbufs->m_nextpkt; in mp_Assemble()
543 len = mp_ReadHeader(mp, *frag, &h); in mp_Assemble()
547 log_Printf(LogWARN, "Oops - MP frag %lu should have a begin flag\n", in mp_Assemble()
552 log_Printf(LogWARN, "Oops - MP frag %lu should have an end flag\n", in mp_Assemble()
558 (*frag)->m_nextpkt = mp->inbufs; in mp_Assemble()
559 mp->inbufs = *frag; in mp_Assemble()
577 log_Printf(LogDEBUG, "MP: Reassembled frags %lu-%lu, length %zd\n", in mp_Assemble()
579 link_PullPacket(&mp->link, MBUF_CTOP(q), q->m_len, mp->bundle); in mp_Assemble()
583 mp->seq.next_in = seq = inc_seq(mp->local_is12bit, h.seq); in mp_Assemble()
585 q = mp->inbufs; in mp_Assemble()
588 seq = inc_seq(mp->local_is12bit, seq); in mp_Assemble()
597 for (q = mp->inbufs; q; last = q, q = q->m_nextpkt) { in mp_Assemble()
598 mp_ReadHeader(mp, q, &h); in mp_Assemble()
599 if (isbefore(mp->local_is12bit, mh.seq, h.seq)) in mp_Assemble()
606 mp->inbufs = m; in mp_Assemble()
616 if (!bundle->ncp.mp.active) in mp_Input()
621 log_Printf(LogWARN, "DecodePacket: Can't do MP inside MP !\n"); in mp_Input()
625 mp_Assemble(&bundle->ncp.mp, bp, p); in mp_Input()
632 mp_Output(struct mp *mp, struct bundle *bundle, struct link *l, in mp_Output() argument
637 /* Stuff an MP header on the front of our packet and send it */ in mp_Output()
639 if (mp->peer_is12bit) { in mp_Output()
642 val = (begin << 15) | (end << 14) | (u_int16_t)mp->out.seq; in mp_Output()
648 val = (begin << 31) | (end << 30) | (u_int32_t)mp->out.seq; in mp_Output()
653 log_Printf(LogDEBUG, "MP[frag %d]: Send %zd bytes on link `%s'\n", in mp_Output()
654 mp->out.seq, m_length(m), l->name); in mp_Output()
655 mp->out.seq = inc_seq(mp->peer_is12bit, mp->out.seq); in mp_Output()
668 struct mp *mp = &bundle->ncp.mp; in mp_FillPhysicalQueues() local
678 /* Include non-open links here as mp->out.link will stay more correct */ in mp_FillPhysicalQueues()
680 if (thislink == mp->out.link) in mp_FillPhysicalQueues()
718 if (!mp_QueueLen(mp)) { in mp_FillPhysicalQueues()
723 * MP level link compression, queue outbound traffic directly via that in mp_FillPhysicalQueues()
724 * link's protocol stack rather than using the MP link. This results in mp_FillPhysicalQueues()
732 if (dl->physical->link.lcp.his_mru < mp->peer_mrru) { in mp_FillPhysicalQueues()
736 * in MP fragments and some data in PROTO_IP packets. That's just in mp_FillPhysicalQueues()
744 bestlink = sendasip ? &dl->physical->link : &mp->link; in mp_FillPhysicalQueues()
745 if (!ncp_PushPacket(&bundle->ncp, &mp->out.af, bestlink)) in mp_FillPhysicalQueues()
763 m = link_Dequeue(&mp->link); in mp_FillPhysicalQueues()
782 mp_Output(mp, bundle, &dl->physical->link, mo, begin, end); in mp_FillPhysicalQueues()
798 mp->out.link = thislink; /* Start here next time */ in mp_FillPhysicalQueues()
816 arg->cx->mp.bandwidth = val; in mp_SetDatalinkBandwidth()
827 struct mp *mp = &arg->bundle->ncp.mp; in mp_ShowStatus() local
829 prompt_Printf(arg->prompt, "Multilink is %sactive\n", mp->active ? "" : "in"); in mp_ShowStatus()
830 if (mp->active) { in mp_ShowStatus()
836 mp->server.socket.sun_path); in mp_ShowStatus()
837 for (m = mp->inbufs; m; m = m->m_nextpkt) { in mp_ShowStatus()
846 first = mp_ReadHeader(mp, mp->inbufs, &mh) ? mh.seq : 0; in mp_ShowStatus()
847 last = mp_ReadHeader(mp, lm, &mh) ? mh.seq : 0; in mp_ShowStatus()
849 first, last, (unsigned long)mp->seq.next_in, in mp_ShowStatus()
850 (unsigned long)mp->seq.min_in); in mp_ShowStatus()
858 if (mp->active) { in mp_ShowStatus()
859 prompt_Printf(arg->prompt, " Output SEQ: %u\n", mp->out.seq); in mp_ShowStatus()
860 prompt_Printf(arg->prompt, " MRRU: %u\n", mp->local_mrru); in mp_ShowStatus()
862 mp->local_is12bit ? "on" : "off"); in mp_ShowStatus()
865 mp_Enddisc(mp->cfg.enddisc.class, mp->cfg.enddisc.address, in mp_ShowStatus()
866 mp->cfg.enddisc.len)); in mp_ShowStatus()
869 if (mp->active) { in mp_ShowStatus()
870 prompt_Printf(arg->prompt, " Auth Name: %s\n", mp->peer.authname); in mp_ShowStatus()
871 prompt_Printf(arg->prompt, " Input SEQ: %u\n", mp->seq.next_in); in mp_ShowStatus()
872 prompt_Printf(arg->prompt, " MRRU: %u\n", mp->peer_mrru); in mp_ShowStatus()
874 mp->peer_is12bit ? "on" : "off"); in mp_ShowStatus()
877 mp_Enddisc(mp->peer.enddisc.class, mp->peer.enddisc.address, in mp_ShowStatus()
878 mp->peer.enddisc.len)); in mp_ShowStatus()
883 if (mp->cfg.mrru) in mp_ShowStatus()
884 prompt_Printf(arg->prompt, "%d (multilink enabled)\n", mp->cfg.mrru); in mp_ShowStatus()
888 command_ShowNegval(mp->cfg.shortseq)); in mp_ShowStatus()
890 command_ShowNegval(mp->cfg.negenddisc)); in mp_ShowStatus()
892 " period %d secs\n", mp->cfg.autoload.min, in mp_ShowStatus()
893 mp->cfg.autoload.max, mp->cfg.autoload.period); in mp_ShowStatus()
959 struct mp *mp = &arg->bundle->ncp.mp; in mp_SetEnddisc() local
979 mp->cfg.enddisc.class = 0; in mp_SetEnddisc()
980 *mp->cfg.enddisc.address = '\0'; in mp_SetEnddisc()
981 mp->cfg.enddisc.len = 0; in mp_SetEnddisc()
984 mp->cfg.enddisc.class = ENDDISC_LOCAL; in mp_SetEnddisc()
985 strcpy(mp->cfg.enddisc.address, arg->bundle->cfg.label); in mp_SetEnddisc()
986 mp->cfg.enddisc.len = strlen(mp->cfg.enddisc.address); in mp_SetEnddisc()
992 memcpy(mp->cfg.enddisc.address, &addr.s_addr, sizeof addr.s_addr); in mp_SetEnddisc()
993 mp->cfg.enddisc.class = ENDDISC_IP; in mp_SetEnddisc()
994 mp->cfg.enddisc.len = sizeof arg->bundle->ncp.ipcp.my_ip.s_addr; in mp_SetEnddisc()
1004 mp->cfg.enddisc.class = ENDDISC_MAC; in mp_SetEnddisc()
1005 memcpy(mp->cfg.enddisc.address, hwaddr.sdl_data + hwaddr.sdl_nlen, in mp_SetEnddisc()
1007 mp->cfg.enddisc.len = hwaddr.sdl_alen; in mp_SetEnddisc()
1018 *(long *)(mp->cfg.enddisc.address + f) = random(); in mp_SetEnddisc()
1019 mp->cfg.enddisc.class = ENDDISC_MAGIC; in mp_SetEnddisc()
1020 mp->cfg.enddisc.len = 20; in mp_SetEnddisc()
1023 mp->cfg.enddisc.class = ENDDISC_PSN; in mp_SetEnddisc()
1024 strcpy(mp->cfg.enddisc.address, arg->argv[arg->argn+1]); in mp_SetEnddisc()
1025 mp->cfg.enddisc.len = strlen(mp->cfg.enddisc.address); in mp_SetEnddisc()
1064 log_Printf(LogTIMER, "mp: fdset(r) %d\n", s->fd); in mpserver_UpdateSet()
1198 mp_LinkLost(struct mp *mp, struct datalink *dl) in mp_LinkLost() argument
1200 if (mp->seq.min_in == dl->mp.seq) in mp_LinkLost()
1202 mp_Assemble(mp, NULL, NULL); in mp_LinkLost()
1206 mp_QueueLen(struct mp *mp) in mp_QueueLen() argument
1208 return link_QueueLen(&mp->link); in mp_QueueLen()