2 * Copyright (c) 1996 - 2001 Brian Somers <brian@Awfulhak.org>
3 * based on work by Toshiharu OHNO <tony-o@iij.ad.jp>
4 * Internet Initiative Japan, Inc (IIJ)
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include <sys/param.h>
32 #include <netinet/in_systm.h>
33 #include <netinet/in.h>
34 #include <netinet/ip.h>
35 #include <arpa/inet.h>
36 #include <sys/socket.h>
38 #include <net/route.h>
70 #include "throughput.h"
71 #include "slcompress.h"
79 #include "descriptor.h"
100 #define REJECTED(p, x) ((p)->peer_reject & (1<<(x)))
101 #define issep(ch) ((ch) == ' ' || (ch) == '\t')
102 #define isip(ch) (((ch) >= '0' && (ch) <= '9') || (ch) == '.')
110 static int IpcpLayerUp(struct fsm *);
111 static void IpcpLayerDown(struct fsm *);
112 static void IpcpLayerStart(struct fsm *);
113 static void IpcpLayerFinish(struct fsm *);
114 static void IpcpInitRestartCounter(struct fsm *, int);
115 static void IpcpSendConfigReq(struct fsm *);
116 static void IpcpSentTerminateReq(struct fsm *);
117 static void IpcpSendTerminateAck(struct fsm *, u_char);
118 static void IpcpDecodeConfig(struct fsm *, u_char *, u_char *, int,
119 struct fsm_decode *);
121 extern struct libalias *la;
123 static struct fsm_callbacks ipcp_Callbacks = {
128 IpcpInitRestartCounter,
130 IpcpSentTerminateReq,
131 IpcpSendTerminateAck,
133 fsm_NullRecvResetReq,
144 /* Check out the latest ``Assigned numbers'' rfc (rfc1700.txt) */
145 { 1, "IPADDRS" }, /* IP-Addresses */ /* deprecated */
146 { 2, "COMPPROTO" }, /* IP-Compression-Protocol */
147 { 3, "IPADDR" }, /* IP-Address */
148 { 129, "PRIDNS" }, /* 129: Primary DNS Server Address */
149 { 130, "PRINBNS" }, /* 130: Primary NBNS Server Address */
150 { 131, "SECDNS" }, /* 131: Secondary DNS Server Address */
151 { 132, "SECNBNS" } /* 132: Secondary NBNS Server Address */
155 for (f = 0; f < sizeof cftypes / sizeof *cftypes; f++)
156 if (cftypes[f].id == proto)
157 return cftypes[f].txt;
159 return NumStr(proto, NULL, 0);
163 ipcp_AddInOctets(struct ipcp *ipcp, int n)
165 throughput_addin(&ipcp->throughput, n);
169 ipcp_AddOutOctets(struct ipcp *ipcp, int n)
171 throughput_addout(&ipcp->throughput, n);
175 ipcp_LoadDNS(struct ipcp *ipcp)
179 ipcp->ns.dns[0].s_addr = ipcp->ns.dns[1].s_addr = INADDR_NONE;
181 if (ipcp->ns.resolv != NULL) {
182 free(ipcp->ns.resolv);
183 ipcp->ns.resolv = NULL;
185 if (ipcp->ns.resolv_nons != NULL) {
186 free(ipcp->ns.resolv_nons);
187 ipcp->ns.resolv_nons = NULL;
189 ipcp->ns.resolver = 0;
191 if ((fd = open(_PATH_RESCONF, O_RDONLY)) != -1) {
194 if (fstat(fd, &st) == 0) {
198 * Note, ns.resolv and ns.resolv_nons are assumed to always point to
199 * buffers of the same size! See the strcpy() below.
201 if ((ipcp->ns.resolv_nons = (char *)malloc(st.st_size + 1)) == NULL)
202 log_Printf(LogERROR, "Failed to malloc %lu for %s: %s\n",
203 (unsigned long)st.st_size, _PATH_RESCONF, strerror(errno));
204 else if ((ipcp->ns.resolv = (char *)malloc(st.st_size + 1)) == NULL) {
205 log_Printf(LogERROR, "Failed(2) to malloc %lu for %s: %s\n",
206 (unsigned long)st.st_size, _PATH_RESCONF, strerror(errno));
207 free(ipcp->ns.resolv_nons);
208 ipcp->ns.resolv_nons = NULL;
209 } else if ((got = read(fd, ipcp->ns.resolv, st.st_size)) != st.st_size) {
211 log_Printf(LogERROR, "Failed to read %s: %s\n",
212 _PATH_RESCONF, strerror(errno));
214 log_Printf(LogERROR, "Failed to read %s, got %lu not %lu\n",
215 _PATH_RESCONF, (unsigned long)got,
216 (unsigned long)st.st_size);
217 free(ipcp->ns.resolv_nons);
218 ipcp->ns.resolv_nons = NULL;
219 free(ipcp->ns.resolv);
220 ipcp->ns.resolv = NULL;
222 char *cp, *cp_nons, *ncp, ch;
225 ipcp->ns.resolv[st.st_size] = '\0';
226 ipcp->ns.resolver = 1;
228 cp_nons = ipcp->ns.resolv_nons;
229 cp = ipcp->ns.resolv;
232 while ((ncp = strstr(cp, "nameserver")) != NULL) {
234 memcpy(cp_nons, cp, ncp - cp);
237 if ((ncp != cp && ncp[-1] != '\n') || !issep(ncp[10])) {
238 memcpy(cp_nons, ncp, 9);
240 cp = ncp + 9; /* Can't match "nameserver" at cp... */
244 for (cp = ncp + 11; issep(*cp); cp++) /* Skip whitespace */
247 for (ncp = cp; isip(*ncp); ncp++) /* Jump over IP */
252 if (n < 2 && inet_aton(cp, ipcp->ns.dns))
256 if ((cp = strchr(ncp, '\n')) == NULL) /* Point at next line */
257 cp = ncp + strlen(ncp);
262 * Note, cp_nons and cp always point to buffers of the same size, so
265 strcpy(cp_nons, cp); /* Copy the end - including the NUL */
266 cp_nons += strlen(cp_nons) - 1;
267 while (cp_nons >= ipcp->ns.resolv_nons && *cp_nons == '\n')
269 if (n == 2 && ipcp->ns.dns[0].s_addr == INADDR_ANY) {
270 ipcp->ns.dns[0].s_addr = ipcp->ns.dns[1].s_addr;
271 ipcp->ns.dns[1].s_addr = INADDR_ANY;
273 bundle_AdjustDNS(ipcp->fsm.bundle);
276 log_Printf(LogERROR, "Failed to stat opened %s: %s\n",
277 _PATH_RESCONF, strerror(errno));
284 ipcp_WriteDNS(struct ipcp *ipcp)
290 if (ipcp->ns.dns[0].s_addr == INADDR_ANY &&
291 ipcp->ns.dns[1].s_addr == INADDR_ANY) {
292 log_Printf(LogIPCP, "%s not modified: All nameservers NAKd\n",
297 if (ipcp->ns.dns[0].s_addr == INADDR_ANY) {
298 ipcp->ns.dns[0].s_addr = ipcp->ns.dns[1].s_addr;
299 ipcp->ns.dns[1].s_addr = INADDR_ANY;
303 if ((fp = ID0fopen(_PATH_RESCONF, "w")) != NULL) {
305 if (ipcp->ns.resolv_nons)
306 fputs(ipcp->ns.resolv_nons, fp);
307 paddr = inet_ntoa(ipcp->ns.dns[0]);
308 log_Printf(LogIPCP, "Primary nameserver set to %s\n", paddr);
309 fprintf(fp, "\nnameserver %s\n", paddr);
310 if (ipcp->ns.dns[1].s_addr != INADDR_ANY &&
311 ipcp->ns.dns[1].s_addr != INADDR_NONE &&
312 ipcp->ns.dns[1].s_addr != ipcp->ns.dns[0].s_addr) {
313 paddr = inet_ntoa(ipcp->ns.dns[1]);
314 log_Printf(LogIPCP, "Secondary nameserver set to %s\n", paddr);
315 fprintf(fp, "nameserver %s\n", paddr);
317 if (fclose(fp) == EOF) {
318 log_Printf(LogERROR, "write(): Failed updating %s: %s\n", _PATH_RESCONF,
324 log_Printf(LogERROR,"fopen(\"%s\", \"w\") failed: %s\n", _PATH_RESCONF,
332 ipcp_RestoreDNS(struct ipcp *ipcp)
334 if (ipcp->ns.resolver) {
338 if ((fd = ID0open(_PATH_RESCONF, O_WRONLY|O_TRUNC, 0644)) != -1) {
339 len = strlen(ipcp->ns.resolv);
340 if ((got = write(fd, ipcp->ns.resolv, len)) != len) {
342 log_Printf(LogERROR, "Failed rewriting %s: write: %s\n",
343 _PATH_RESCONF, strerror(errno));
345 log_Printf(LogERROR, "Failed rewriting %s: wrote %ld of %ld\n",
346 _PATH_RESCONF, (long)got, (long)len);
350 log_Printf(LogERROR, "Failed rewriting %s: open: %s\n", _PATH_RESCONF,
352 } else if (remove(_PATH_RESCONF) == -1)
353 log_Printf(LogERROR, "Failed removing %s: %s\n", _PATH_RESCONF,
359 ipcp_Show(struct cmdargs const *arg)
361 struct ipcp *ipcp = &arg->bundle->ncp.ipcp;
363 prompt_Printf(arg->prompt, "%s [%s]\n", ipcp->fsm.name,
364 State2Nam(ipcp->fsm.state));
365 if (ipcp->fsm.state == ST_OPENED) {
366 prompt_Printf(arg->prompt, " His side: %s, %s\n",
367 inet_ntoa(ipcp->peer_ip), vj2asc(ipcp->peer_compproto));
368 prompt_Printf(arg->prompt, " My side: %s, %s\n",
369 inet_ntoa(ipcp->my_ip), vj2asc(ipcp->my_compproto));
370 prompt_Printf(arg->prompt, " Queued packets: %lu\n",
371 (unsigned long)ipcp_QueueLen(ipcp));
374 prompt_Printf(arg->prompt, "\nDefaults:\n");
375 prompt_Printf(arg->prompt, " FSM retry = %us, max %u Config"
376 " REQ%s, %u Term REQ%s\n", ipcp->cfg.fsm.timeout,
377 ipcp->cfg.fsm.maxreq, ipcp->cfg.fsm.maxreq == 1 ? "" : "s",
378 ipcp->cfg.fsm.maxtrm, ipcp->cfg.fsm.maxtrm == 1 ? "" : "s");
379 prompt_Printf(arg->prompt, " My Address: %s\n",
380 ncprange_ntoa(&ipcp->cfg.my_range));
381 if (ipcp->cfg.HaveTriggerAddress)
382 prompt_Printf(arg->prompt, " Trigger address: %s\n",
383 inet_ntoa(ipcp->cfg.TriggerAddress));
385 prompt_Printf(arg->prompt, " VJ compression: %s (%d slots %s slot "
386 "compression)\n", command_ShowNegval(ipcp->cfg.vj.neg),
387 ipcp->cfg.vj.slots, ipcp->cfg.vj.slotcomp ? "with" : "without");
389 if (iplist_isvalid(&ipcp->cfg.peer_list))
390 prompt_Printf(arg->prompt, " His Address: %s\n",
391 ipcp->cfg.peer_list.src);
393 prompt_Printf(arg->prompt, " His Address: %s\n",
394 ncprange_ntoa(&ipcp->cfg.peer_range));
396 prompt_Printf(arg->prompt, " DNS: %s",
397 ipcp->cfg.ns.dns[0].s_addr == INADDR_NONE ?
398 "none" : inet_ntoa(ipcp->cfg.ns.dns[0]));
399 if (ipcp->cfg.ns.dns[1].s_addr != INADDR_NONE)
400 prompt_Printf(arg->prompt, ", %s",
401 inet_ntoa(ipcp->cfg.ns.dns[1]));
402 prompt_Printf(arg->prompt, ", %s\n",
403 command_ShowNegval(ipcp->cfg.ns.dns_neg));
404 prompt_Printf(arg->prompt, " Resolver DNS: %s",
405 ipcp->ns.dns[0].s_addr == INADDR_NONE ?
406 "none" : inet_ntoa(ipcp->ns.dns[0]));
407 if (ipcp->ns.dns[1].s_addr != INADDR_NONE &&
408 ipcp->ns.dns[1].s_addr != ipcp->ns.dns[0].s_addr)
409 prompt_Printf(arg->prompt, ", %s",
410 inet_ntoa(ipcp->ns.dns[1]));
411 prompt_Printf(arg->prompt, "\n NetBIOS NS: %s, ",
412 inet_ntoa(ipcp->cfg.ns.nbns[0]));
413 prompt_Printf(arg->prompt, "%s\n\n",
414 inet_ntoa(ipcp->cfg.ns.nbns[1]));
416 throughput_disp(&ipcp->throughput, arg->prompt);
422 ipcp_vjset(struct cmdargs const *arg)
424 if (arg->argc != arg->argn+2)
426 if (!strcasecmp(arg->argv[arg->argn], "slots")) {
429 slots = atoi(arg->argv[arg->argn+1]);
430 if (slots < 4 || slots > 16)
432 arg->bundle->ncp.ipcp.cfg.vj.slots = slots;
434 } else if (!strcasecmp(arg->argv[arg->argn], "slotcomp")) {
435 if (!strcasecmp(arg->argv[arg->argn+1], "on"))
436 arg->bundle->ncp.ipcp.cfg.vj.slotcomp = 1;
437 else if (!strcasecmp(arg->argv[arg->argn+1], "off"))
438 arg->bundle->ncp.ipcp.cfg.vj.slotcomp = 0;
447 ipcp_Init(struct ipcp *ipcp, struct bundle *bundle, struct link *l,
448 const struct fsm_parent *parent)
452 char name[MAXHOSTNAMELEN];
453 static const char * const timer_names[] =
454 {"IPCP restart", "IPCP openmode", "IPCP stopped"};
456 fsm_Init(&ipcp->fsm, "IPCP", PROTO_IPCP, 1, IPCP_MAXCODE, LogIPCP,
457 bundle, l, parent, &ipcp_Callbacks, timer_names);
459 ipcp->cfg.vj.slots = DEF_VJ_STATES;
460 ipcp->cfg.vj.slotcomp = 1;
461 memset(&ipcp->cfg.my_range, '\0', sizeof ipcp->cfg.my_range);
463 host.s_addr = htonl(INADDR_LOOPBACK);
464 ipcp->cfg.netmask.s_addr = INADDR_ANY;
465 if (gethostname(name, sizeof name) == 0) {
466 hp = gethostbyname(name);
467 if (hp && hp->h_addrtype == AF_INET && hp->h_length == sizeof host.s_addr)
468 memcpy(&host.s_addr, hp->h_addr, sizeof host.s_addr);
470 ncprange_setip4(&ipcp->cfg.my_range, host, ipcp->cfg.netmask);
471 ncprange_setip4(&ipcp->cfg.peer_range, ipcp->cfg.netmask, ipcp->cfg.netmask);
473 iplist_setsrc(&ipcp->cfg.peer_list, "");
474 ipcp->cfg.HaveTriggerAddress = 0;
476 ipcp->cfg.ns.dns[0].s_addr = INADDR_NONE;
477 ipcp->cfg.ns.dns[1].s_addr = INADDR_NONE;
478 ipcp->cfg.ns.dns_neg = 0;
479 ipcp->cfg.ns.nbns[0].s_addr = INADDR_ANY;
480 ipcp->cfg.ns.nbns[1].s_addr = INADDR_ANY;
482 ipcp->cfg.fsm.timeout = DEF_FSMRETRY;
483 ipcp->cfg.fsm.maxreq = DEF_FSMTRIES;
484 ipcp->cfg.fsm.maxtrm = DEF_FSMTRIES;
485 ipcp->cfg.vj.neg = NEG_ENABLED|NEG_ACCEPTED;
487 memset(&ipcp->vj, '\0', sizeof ipcp->vj);
489 ipcp->ns.resolv = NULL;
490 ipcp->ns.resolv_nons = NULL;
491 ipcp->ns.writable = 1;
494 throughput_init(&ipcp->throughput, SAMPLE_PERIOD);
495 memset(ipcp->Queue, '\0', sizeof ipcp->Queue);
496 ipcp_Setup(ipcp, INADDR_NONE);
500 ipcp_Destroy(struct ipcp *ipcp)
502 throughput_destroy(&ipcp->throughput);
504 if (ipcp->ns.resolv != NULL) {
505 free(ipcp->ns.resolv);
506 ipcp->ns.resolv = NULL;
508 if (ipcp->ns.resolv_nons != NULL) {
509 free(ipcp->ns.resolv_nons);
510 ipcp->ns.resolv_nons = NULL;
515 ipcp_SetLink(struct ipcp *ipcp, struct link *l)
521 ipcp_Setup(struct ipcp *ipcp, u_int32_t mask)
523 struct iface *iface = ipcp->fsm.bundle->iface;
524 struct ncpaddr ipaddr;
529 ipcp->fsm.open_mode = 0;
530 ipcp->ifmask.s_addr = mask == INADDR_NONE ? ipcp->cfg.netmask.s_addr : mask;
532 if (iplist_isvalid(&ipcp->cfg.peer_list)) {
533 /* Try to give the peer a previously configured IP address */
534 for (n = 0; n < iface->addrs; n++) {
535 if (!ncpaddr_getip4(&iface->addr[n].peer, &peer))
537 if ((pos = iplist_ip2pos(&ipcp->cfg.peer_list, peer)) != -1) {
538 ncpaddr_setip4(&ipaddr, iplist_setcurpos(&ipcp->cfg.peer_list, pos));
542 if (n == iface->addrs)
543 /* Ok, so none of 'em fit.... pick a random one */
544 ncpaddr_setip4(&ipaddr, iplist_setrandpos(&ipcp->cfg.peer_list));
546 ncprange_sethost(&ipcp->cfg.peer_range, &ipaddr);
551 ncprange_getip4addr(&ipcp->cfg.peer_range, &ipcp->peer_ip);
552 ipcp->peer_compproto = 0;
554 if (ipcp->cfg.HaveTriggerAddress) {
556 * Some implementations of PPP require that we send a
557 * *special* value as our address, even though the rfc specifies
558 * full negotiation (e.g. "0.0.0.0" or Not "0.0.0.0").
560 ipcp->my_ip = ipcp->cfg.TriggerAddress;
561 log_Printf(LogIPCP, "Using trigger address %s\n",
562 inet_ntoa(ipcp->cfg.TriggerAddress));
565 * Otherwise, if we've used an IP number before and it's still within
566 * the network specified on the ``set ifaddr'' line, we really
567 * want to keep that IP number so that we can keep any existing
568 * connections that are bound to that IP.
570 for (n = 0; n < iface->addrs; n++) {
571 ncprange_getaddr(&iface->addr[n].ifa, &ipaddr);
572 if (ncprange_contains(&ipcp->cfg.my_range, &ipaddr)) {
573 ncpaddr_getip4(&ipaddr, &ipcp->my_ip);
577 if (n == iface->addrs)
578 ncprange_getip4addr(&ipcp->cfg.my_range, &ipcp->my_ip);
581 if (IsEnabled(ipcp->cfg.vj.neg)
583 || (ipcp->fsm.bundle->radius.valid && ipcp->fsm.bundle->radius.vj)
586 ipcp->my_compproto = (PROTO_VJCOMP << 16) +
587 ((ipcp->cfg.vj.slots - 1) << 8) +
588 ipcp->cfg.vj.slotcomp;
590 ipcp->my_compproto = 0;
591 sl_compress_init(&ipcp->vj.cslc, ipcp->cfg.vj.slots - 1);
593 ipcp->peer_reject = 0;
596 /* Copy startup values into ipcp->ns.dns */
597 if (ipcp->cfg.ns.dns[0].s_addr != INADDR_NONE)
598 memcpy(ipcp->ns.dns, ipcp->cfg.ns.dns, sizeof ipcp->ns.dns);
602 numaddresses(struct in_addr mask)
604 u_int32_t bit, haddr;
607 haddr = ntohl(mask.s_addr);
620 ipcp_proxyarp(struct ipcp *ipcp,
621 int (*proxyfun)(struct bundle *, struct in_addr),
622 const struct iface_addr *addr)
624 struct bundle *bundle = ipcp->fsm.bundle;
625 struct in_addr peer, mask, ip;
628 if (!ncpaddr_getip4(&addr->peer, &peer)) {
629 log_Printf(LogERROR, "Oops, ipcp_proxyarp() called with unexpected addr\n");
635 if (Enabled(bundle, OPT_PROXYALL)) {
636 ncprange_getip4mask(&addr->ifa, &mask);
637 if ((n = numaddresses(mask)) > 256) {
638 log_Printf(LogWARN, "%s: Too many addresses for proxyall\n",
639 ncprange_ntoa(&addr->ifa));
642 ip.s_addr = peer.s_addr & mask.s_addr;
644 ip.s_addr = htonl(ntohl(ip.s_addr) + 1);
648 if (!((ip.s_addr ^ peer.s_addr) & mask.s_addr)) {
649 if (!(ret = (*proxyfun)(bundle, ip)))
653 ip.s_addr = htonl(ntohl(ip.s_addr) + 1);
656 } else if (Enabled(bundle, OPT_PROXY))
657 ret = (*proxyfun)(bundle, peer);
663 ipcp_SetIPaddress(struct ipcp *ipcp, struct in_addr myaddr,
664 struct in_addr hisaddr)
666 struct bundle *bundle = ipcp->fsm.bundle;
667 struct ncpaddr myncpaddr, hisncpaddr;
668 struct ncprange myrange;
670 struct sockaddr_storage ssdst, ssgw, ssmask;
671 struct sockaddr *sadst, *sagw, *samask;
673 sadst = (struct sockaddr *)&ssdst;
674 sagw = (struct sockaddr *)&ssgw;
675 samask = (struct sockaddr *)&ssmask;
677 ncpaddr_setip4(&hisncpaddr, hisaddr);
678 ncpaddr_setip4(&myncpaddr, myaddr);
679 ncprange_sethost(&myrange, &myncpaddr);
681 mask = addr2mask(myaddr);
683 if (ipcp->ifmask.s_addr != INADDR_ANY &&
684 (ipcp->ifmask.s_addr & mask.s_addr) == mask.s_addr)
685 ncprange_setip4mask(&myrange, ipcp->ifmask);
687 if (!iface_Add(bundle->iface, &bundle->ncp, &myrange, &hisncpaddr,
688 IFACE_ADD_FIRST|IFACE_FORCE_ADD|IFACE_SYSTEM))
691 if (!Enabled(bundle, OPT_IFACEALIAS))
692 iface_Clear(bundle->iface, &bundle->ncp, AF_INET,
693 IFACE_CLEAR_ALIASES|IFACE_SYSTEM);
695 if (bundle->ncp.cfg.sendpipe > 0 || bundle->ncp.cfg.recvpipe > 0) {
696 ncprange_getsa(&myrange, &ssgw, &ssmask);
697 ncpaddr_getsa(&hisncpaddr, &ssdst);
698 rt_Update(bundle, sadst, sagw, samask, NULL, NULL);
701 if (Enabled(bundle, OPT_SROUTES))
702 route_Change(bundle, bundle->ncp.route, &myncpaddr, &hisncpaddr);
705 if (bundle->radius.valid)
706 route_Change(bundle, bundle->radius.routes, &myncpaddr, &hisncpaddr);
712 static struct in_addr
713 ChooseHisAddr(struct bundle *bundle, struct in_addr gw)
718 for (f = 0; f < bundle->ncp.ipcp.cfg.peer_list.nItems; f++) {
719 try = iplist_next(&bundle->ncp.ipcp.cfg.peer_list);
720 log_Printf(LogDEBUG, "ChooseHisAddr: Check item %ld (%s)\n",
722 if (ipcp_SetIPaddress(&bundle->ncp.ipcp, gw, try)) {
723 log_Printf(LogIPCP, "Selected IP address %s\n", inet_ntoa(try));
728 if (f == bundle->ncp.ipcp.cfg.peer_list.nItems) {
729 log_Printf(LogDEBUG, "ChooseHisAddr: All addresses in use !\n");
730 try.s_addr = INADDR_ANY;
737 IpcpInitRestartCounter(struct fsm *fp, int what)
739 /* Set fsm timer load */
740 struct ipcp *ipcp = fsm2ipcp(fp);
742 fp->FsmTimer.load = ipcp->cfg.fsm.timeout * SECTICKS;
745 fp->restart = ipcp->cfg.fsm.maxreq;
748 fp->restart = ipcp->cfg.fsm.maxtrm;
757 IpcpSendConfigReq(struct fsm *fp)
759 /* Send config REQ please */
760 struct physical *p = link2physical(fp->link);
761 struct ipcp *ipcp = fsm2ipcp(fp);
762 u_char buff[MAX_FSM_OPT_LEN];
765 o = (struct fsm_opt *)buff;
767 if ((p && !physical_IsSync(p)) || !REJECTED(ipcp, TY_IPADDR)) {
768 memcpy(o->data, &ipcp->my_ip.s_addr, 4);
769 INC_FSM_OPT(TY_IPADDR, 6, o);
772 if (ipcp->my_compproto && !REJECTED(ipcp, TY_COMPPROTO)) {
773 if (ipcp->heis1172) {
774 u_int16_t proto = PROTO_VJCOMP;
776 ua_htons(&proto, o->data);
777 INC_FSM_OPT(TY_COMPPROTO, 4, o);
781 req.proto = htons(ipcp->my_compproto >> 16);
782 req.slots = (ipcp->my_compproto >> 8) & 255;
783 req.compcid = ipcp->my_compproto & 1;
784 memcpy(o->data, &req, 4);
785 INC_FSM_OPT(TY_COMPPROTO, 6, o);
789 if (IsEnabled(ipcp->cfg.ns.dns_neg)) {
790 if (!REJECTED(ipcp, TY_PRIMARY_DNS - TY_ADJUST_NS)) {
791 memcpy(o->data, &ipcp->ns.dns[0].s_addr, 4);
792 INC_FSM_OPT(TY_PRIMARY_DNS, 6, o);
795 if (!REJECTED(ipcp, TY_SECONDARY_DNS - TY_ADJUST_NS)) {
796 memcpy(o->data, &ipcp->ns.dns[1].s_addr, 4);
797 INC_FSM_OPT(TY_SECONDARY_DNS, 6, o);
801 fsm_Output(fp, CODE_CONFIGREQ, fp->reqid, buff, (u_char *)o - buff,
806 IpcpSentTerminateReq(struct fsm *fp __unused)
808 /* Term REQ just sent by FSM */
812 IpcpSendTerminateAck(struct fsm *fp, u_char id)
814 /* Send Term ACK please */
815 fsm_Output(fp, CODE_TERMACK, id, NULL, 0, MB_IPCPOUT);
819 IpcpLayerStart(struct fsm *fp)
821 /* We're about to start up ! */
822 struct ipcp *ipcp = fsm2ipcp(fp);
824 log_Printf(LogIPCP, "%s: LayerStart.\n", fp->link->name);
825 throughput_start(&ipcp->throughput, "IPCP throughput",
826 Enabled(fp->bundle, OPT_THROUGHPUT));
827 fp->more.reqs = fp->more.naks = fp->more.rejs = ipcp->cfg.fsm.maxreq * 3;
832 IpcpLayerFinish(struct fsm *fp)
835 struct ipcp *ipcp = fsm2ipcp(fp);
837 log_Printf(LogIPCP, "%s: LayerFinish.\n", fp->link->name);
838 throughput_stop(&ipcp->throughput);
839 throughput_log(&ipcp->throughput, LogIPCP, NULL);
843 * Called from iface_Add() via ncp_IfaceAddrAdded()
846 ipcp_IfaceAddrAdded(struct ipcp *ipcp, const struct iface_addr *addr)
848 struct bundle *bundle = ipcp->fsm.bundle;
850 if (Enabled(bundle, OPT_PROXY) || Enabled(bundle, OPT_PROXYALL))
851 ipcp_proxyarp(ipcp, arp_SetProxy, addr);
855 * Called from iface_Clear() and iface_Delete() via ncp_IfaceAddrDeleted()
858 ipcp_IfaceAddrDeleted(struct ipcp *ipcp, const struct iface_addr *addr)
860 struct bundle *bundle = ipcp->fsm.bundle;
862 if (Enabled(bundle, OPT_PROXY) || Enabled(bundle, OPT_PROXYALL))
863 ipcp_proxyarp(ipcp, arp_ClearProxy, addr);
867 IpcpLayerDown(struct fsm *fp)
869 /* About to come down */
870 struct ipcp *ipcp = fsm2ipcp(fp);
871 static int recursing;
875 snprintf(addr, sizeof addr, "%s", inet_ntoa(ipcp->my_ip));
876 log_Printf(LogIPCP, "%s: LayerDown: %s\n", fp->link->name, addr);
879 radius_Flush(&fp->bundle->radius);
880 radius_Account(&fp->bundle->radius, &fp->bundle->radacct,
881 fp->bundle->links, RAD_STOP, &ipcp->throughput);
883 if (fp->bundle->radius.cfg.file && fp->bundle->radius.filterid)
884 system_Select(fp->bundle, fp->bundle->radius.filterid, LINKDOWNFILE,
886 radius_StopTimer(&fp->bundle->radius);
890 * XXX this stuff should really live in the FSM. Our config should
891 * associate executable sections in files with events.
893 if (system_Select(fp->bundle, addr, LINKDOWNFILE, NULL, NULL) < 0) {
894 if (bundle_GetLabel(fp->bundle)) {
895 if (system_Select(fp->bundle, bundle_GetLabel(fp->bundle),
896 LINKDOWNFILE, NULL, NULL) < 0)
897 system_Select(fp->bundle, "MYADDR", LINKDOWNFILE, NULL, NULL);
899 system_Select(fp->bundle, "MYADDR", LINKDOWNFILE, NULL, NULL);
902 ipcp_Setup(ipcp, INADDR_NONE);
908 ipcp_InterfaceUp(struct ipcp *ipcp)
910 if (!ipcp_SetIPaddress(ipcp, ipcp->my_ip, ipcp->peer_ip)) {
911 log_Printf(LogERROR, "ipcp_InterfaceUp: unable to set ip address\n");
915 if (!iface_SetFlags(ipcp->fsm.bundle->iface->name, IFF_UP)) {
916 log_Printf(LogERROR, "ipcp_InterfaceUp: Can't set the IFF_UP flag on %s\n",
917 ipcp->fsm.bundle->iface->name);
922 if (ipcp->fsm.bundle->NatEnabled)
923 LibAliasSetAddress(la, ipcp->my_ip);
930 IpcpLayerUp(struct fsm *fp)
933 struct ipcp *ipcp = fsm2ipcp(fp);
936 log_Printf(LogIPCP, "%s: LayerUp.\n", fp->link->name);
937 snprintf(tbuff, sizeof tbuff, "%s", inet_ntoa(ipcp->my_ip));
938 log_Printf(LogIPCP, "myaddr %s hisaddr = %s\n",
939 tbuff, inet_ntoa(ipcp->peer_ip));
941 if (ipcp->peer_compproto >> 16 == PROTO_VJCOMP)
942 sl_compress_init(&ipcp->vj.cslc, (ipcp->peer_compproto >> 8) & 255);
944 if (!ipcp_InterfaceUp(ipcp))
948 radius_Account_Set_Ip(&fp->bundle->radacct, &ipcp->peer_ip, &ipcp->ifmask);
949 radius_Account(&fp->bundle->radius, &fp->bundle->radacct, fp->bundle->links,
950 RAD_START, &ipcp->throughput);
952 if (fp->bundle->radius.cfg.file && fp->bundle->radius.filterid)
953 system_Select(fp->bundle, fp->bundle->radius.filterid, LINKUPFILE,
955 radius_StartTimer(fp->bundle);
959 * XXX this stuff should really live in the FSM. Our config should
960 * associate executable sections in files with events.
962 if (system_Select(fp->bundle, tbuff, LINKUPFILE, NULL, NULL) < 0) {
963 if (bundle_GetLabel(fp->bundle)) {
964 if (system_Select(fp->bundle, bundle_GetLabel(fp->bundle),
965 LINKUPFILE, NULL, NULL) < 0)
966 system_Select(fp->bundle, "MYADDR", LINKUPFILE, NULL, NULL);
968 system_Select(fp->bundle, "MYADDR", LINKUPFILE, NULL, NULL);
971 fp->more.reqs = fp->more.naks = fp->more.rejs = ipcp->cfg.fsm.maxreq * 3;
972 log_DisplayPrompts();
978 ipcp_ValidateReq(struct ipcp *ipcp, struct in_addr ip, struct fsm_decode *dec)
980 struct bundle *bundle = ipcp->fsm.bundle;
981 struct iface *iface = bundle->iface;
982 struct in_addr myaddr, peer;
985 if (iplist_isvalid(&ipcp->cfg.peer_list)) {
986 ncprange_getip4addr(&ipcp->cfg.my_range, &myaddr);
987 if (ip.s_addr == INADDR_ANY ||
988 iplist_ip2pos(&ipcp->cfg.peer_list, ip) < 0 ||
989 !ipcp_SetIPaddress(ipcp, myaddr, ip)) {
990 log_Printf(LogIPCP, "%s: Address invalid or already in use\n",
993 * If we've already had a valid address configured for the peer,
994 * try NAKing with that so that we don't have to upset things
997 for (n = 0; n < iface->addrs; n++) {
998 if (!ncpaddr_getip4(&iface->addr[n].peer, &peer))
1000 if (iplist_ip2pos(&ipcp->cfg.peer_list, peer) >= 0) {
1001 ipcp->peer_ip = peer;
1006 if (n == iface->addrs) {
1007 /* Just pick an IP number from our list */
1008 ipcp->peer_ip = ChooseHisAddr(bundle, myaddr);
1011 if (ipcp->peer_ip.s_addr == INADDR_ANY) {
1012 *dec->rejend++ = TY_IPADDR;
1014 memcpy(dec->rejend, &ip.s_addr, 4);
1017 *dec->nakend++ = TY_IPADDR;
1019 memcpy(dec->nakend, &ipcp->peer_ip.s_addr, 4);
1024 } else if (ip.s_addr == INADDR_ANY ||
1025 !ncprange_containsip4(&ipcp->cfg.peer_range, ip)) {
1027 * If the destination address is not acceptable, NAK with what we
1030 *dec->nakend++ = TY_IPADDR;
1032 for (n = 0; n < iface->addrs; n++)
1033 if (ncprange_contains(&ipcp->cfg.peer_range, &iface->addr[n].peer)) {
1034 /* We prefer the already-configured address */
1035 ncpaddr_getip4addr(&iface->addr[n].peer, (u_int32_t *)dec->nakend);
1039 if (n == iface->addrs)
1040 memcpy(dec->nakend, &ipcp->peer_ip.s_addr, 4);
1047 *dec->ackend++ = TY_IPADDR;
1049 memcpy(dec->ackend, &ip.s_addr, 4);
1054 IpcpDecodeConfig(struct fsm *fp, u_char *cp, u_char *end, int mode_type,
1055 struct fsm_decode *dec)
1057 /* Deal with incoming PROTO_IPCP */
1058 struct ncpaddr ncpaddr;
1059 struct ipcp *ipcp = fsm2ipcp(fp);
1061 u_int32_t compproto;
1062 struct compreq pcomp;
1063 struct in_addr ipaddr, dstipaddr, have_ip;
1064 char tbuff[100], tbuff2[100];
1065 struct fsm_opt *opt, nak;
1069 while (end - cp >= (int)sizeof(opt->hdr)) {
1070 if ((opt = fsm_readopt(&cp)) == NULL)
1073 snprintf(tbuff, sizeof tbuff, " %s[%d]", protoname(opt->hdr.id),
1076 switch (opt->hdr.id) {
1077 case TY_IPADDR: /* RFC1332 */
1078 memcpy(&ipaddr.s_addr, opt->data, 4);
1079 log_Printf(LogIPCP, "%s %s\n", tbuff, inet_ntoa(ipaddr));
1081 switch (mode_type) {
1084 ipcp_ValidateReq(ipcp, ipaddr, dec);
1088 if (ncprange_containsip4(&ipcp->cfg.my_range, ipaddr)) {
1089 /* Use address suggested by peer */
1090 snprintf(tbuff2, sizeof tbuff2, "%s changing address: %s ", tbuff,
1091 inet_ntoa(ipcp->my_ip));
1092 log_Printf(LogIPCP, "%s --> %s\n", tbuff2, inet_ntoa(ipaddr));
1093 ipcp->my_ip = ipaddr;
1094 ncpaddr_setip4(&ncpaddr, ipcp->my_ip);
1095 bundle_AdjustFilters(fp->bundle, &ncpaddr, NULL);
1097 log_Printf(log_IsKept(LogIPCP) ? LogIPCP : LogPHASE,
1098 "%s: Unacceptable address!\n", inet_ntoa(ipaddr));
1099 fsm_Close(&ipcp->fsm);
1104 ipcp->peer_reject |= (1 << opt->hdr.id);
1110 memcpy(&pcomp, opt->data, sizeof pcomp);
1111 compproto = (ntohs(pcomp.proto) << 16) + ((int)pcomp.slots << 8) +
1113 log_Printf(LogIPCP, "%s %s\n", tbuff, vj2asc(compproto));
1115 switch (mode_type) {
1117 if (!IsAccepted(ipcp->cfg.vj.neg))
1120 switch (opt->hdr.len) {
1121 case 4: /* RFC1172 */
1122 if (ntohs(pcomp.proto) == PROTO_VJCOMP) {
1123 log_Printf(LogWARN, "Peer is speaking RFC1172 compression "
1126 ipcp->peer_compproto = compproto;
1129 pcomp.proto = htons(PROTO_VJCOMP);
1130 nak.hdr.id = TY_COMPPROTO;
1132 memcpy(nak.data, &pcomp, 2);
1136 case 6: /* RFC1332 */
1137 if (ntohs(pcomp.proto) == PROTO_VJCOMP) {
1138 /* We know pcomp.slots' max value == MAX_VJ_STATES */
1139 if (pcomp.slots >= MIN_VJ_STATES) {
1140 /* Ok, we can do that */
1141 ipcp->peer_compproto = compproto;
1145 /* Get as close as we can to what he wants */
1147 pcomp.slots = MIN_VJ_STATES;
1148 nak.hdr.id = TY_COMPPROTO;
1150 memcpy(nak.data, &pcomp, 2);
1154 /* What we really want */
1155 pcomp.proto = htons(PROTO_VJCOMP);
1156 pcomp.slots = DEF_VJ_STATES;
1158 nak.hdr.id = TY_COMPPROTO;
1160 memcpy(nak.data, &pcomp, sizeof pcomp);
1172 if (ntohs(pcomp.proto) == PROTO_VJCOMP) {
1173 /* We know pcomp.slots' max value == MAX_VJ_STATES */
1174 if (pcomp.slots < MIN_VJ_STATES)
1175 pcomp.slots = MIN_VJ_STATES;
1176 compproto = (ntohs(pcomp.proto) << 16) + (pcomp.slots << 8) +
1180 log_Printf(LogIPCP, "%s changing compproto: %08x --> %08x\n",
1181 tbuff, ipcp->my_compproto, compproto);
1182 ipcp->my_compproto = compproto;
1186 ipcp->peer_reject |= (1 << opt->hdr.id);
1191 case TY_IPADDRS: /* RFC1172 */
1192 memcpy(&ipaddr.s_addr, opt->data, 4);
1193 memcpy(&dstipaddr.s_addr, opt->data + 4, 4);
1194 snprintf(tbuff2, sizeof tbuff2, "%s %s,", tbuff, inet_ntoa(ipaddr));
1195 log_Printf(LogIPCP, "%s %s\n", tbuff2, inet_ntoa(dstipaddr));
1197 switch (mode_type) {
1208 case TY_PRIMARY_DNS: /* DNS negotiation (rfc1877) */
1209 case TY_SECONDARY_DNS:
1210 memcpy(&ipaddr.s_addr, opt->data, 4);
1211 log_Printf(LogIPCP, "%s %s\n", tbuff, inet_ntoa(ipaddr));
1213 switch (mode_type) {
1215 if (!IsAccepted(ipcp->cfg.ns.dns_neg)) {
1216 ipcp->my_reject |= (1 << (opt->hdr.id - TY_ADJUST_NS));
1220 have_ip = ipcp->ns.dns[opt->hdr.id == TY_PRIMARY_DNS ? 0 : 1];
1222 if (opt->hdr.id == TY_PRIMARY_DNS && ipaddr.s_addr != have_ip.s_addr &&
1223 ipaddr.s_addr == ipcp->ns.dns[1].s_addr) {
1224 /* Swap 'em 'round */
1225 ipcp->ns.dns[0] = ipcp->ns.dns[1];
1226 ipcp->ns.dns[1] = have_ip;
1227 have_ip = ipcp->ns.dns[0];
1230 if (ipaddr.s_addr != have_ip.s_addr) {
1232 * The client has got the DNS stuff wrong (first request) so
1233 * we'll tell 'em how it is
1235 nak.hdr.id = opt->hdr.id;
1237 memcpy(nak.data, &have_ip.s_addr, 4);
1241 * Otherwise they have it right (this time) so we send an ack packet
1242 * back confirming it... end of story
1249 if (IsEnabled(ipcp->cfg.ns.dns_neg)) {
1251 memcpy(&ipcp->ns.dns[opt->hdr.id == TY_PRIMARY_DNS ? 0 : 1].s_addr,
1256 case MODE_REJ: /* Can't do much, stop asking */
1257 ipcp->peer_reject |= (1 << (opt->hdr.id - TY_ADJUST_NS));
1262 case TY_PRIMARY_NBNS: /* M$ NetBIOS nameserver hack (rfc1877) */
1263 case TY_SECONDARY_NBNS:
1264 memcpy(&ipaddr.s_addr, opt->data, 4);
1265 log_Printf(LogIPCP, "%s %s\n", tbuff, inet_ntoa(ipaddr));
1267 switch (mode_type) {
1270 ipcp->cfg.ns.nbns[opt->hdr.id == TY_PRIMARY_NBNS ? 0 : 1].s_addr;
1272 if (have_ip.s_addr == INADDR_ANY) {
1273 log_Printf(LogIPCP, "NBNS REQ - rejected - nbns not set\n");
1274 ipcp->my_reject |= (1 << (opt->hdr.id - TY_ADJUST_NS));
1279 if (ipaddr.s_addr != have_ip.s_addr) {
1280 nak.hdr.id = opt->hdr.id;
1282 memcpy(nak.data, &have_ip.s_addr, 4);
1289 log_Printf(LogIPCP, "MS NBNS req %d - NAK??\n", opt->hdr.id);
1293 log_Printf(LogIPCP, "MS NBNS req %d - REJ??\n", opt->hdr.id);
1299 if (mode_type != MODE_NOP) {
1300 ipcp->my_reject |= (1 << opt->hdr.id);
1308 if (ipcp->ns.writable) {
1309 log_Printf(LogDEBUG, "Updating resolver\n");
1310 if (!ipcp_WriteDNS(ipcp)) {
1311 ipcp->peer_reject |= (1 << (TY_PRIMARY_DNS - TY_ADJUST_NS));
1312 ipcp->peer_reject |= (1 << (TY_SECONDARY_DNS - TY_ADJUST_NS));
1314 bundle_AdjustDNS(fp->bundle);
1316 log_Printf(LogDEBUG, "Not updating resolver (readonly)\n");
1317 bundle_AdjustDNS(fp->bundle);
1321 if (mode_type != MODE_NOP) {
1322 if (mode_type == MODE_REQ && !ipcp->peer_req) {
1323 if (dec->rejend == dec->rej && dec->nakend == dec->nak) {
1325 * Pretend the peer has requested an IP.
1326 * We do this to ensure that we only send one NAK if the only
1327 * reason for the NAK is because the peer isn't sending a
1328 * TY_IPADDR REQ. This stops us from repeatedly trying to tell
1329 * the peer that we have to have an IP address on their end.
1333 ipaddr.s_addr = INADDR_ANY;
1334 ipcp_ValidateReq(ipcp, ipaddr, dec);
1336 fsm_opt_normalise(dec);
1340 extern struct mbuf *
1341 ipcp_Input(struct bundle *bundle, struct link *l, struct mbuf *bp)
1343 /* Got PROTO_IPCP from link */
1344 m_settype(bp, MB_IPCPIN);
1345 if (bundle_Phase(bundle) == PHASE_NETWORK)
1346 fsm_Input(&bundle->ncp.ipcp.fsm, bp);
1348 if (bundle_Phase(bundle) < PHASE_NETWORK)
1349 log_Printf(LogIPCP, "%s: Error: Unexpected IPCP in phase %s (ignored)\n",
1350 l->name, bundle_PhaseName(bundle));
1357 ipcp_UseHisIPaddr(struct bundle *bundle, struct in_addr hisaddr)
1359 struct ipcp *ipcp = &bundle->ncp.ipcp;
1360 struct in_addr myaddr;
1362 memset(&ipcp->cfg.peer_range, '\0', sizeof ipcp->cfg.peer_range);
1363 iplist_reset(&ipcp->cfg.peer_list);
1364 ipcp->peer_ip = hisaddr;
1365 ncprange_setip4host(&ipcp->cfg.peer_range, hisaddr);
1366 ncprange_getip4addr(&ipcp->cfg.my_range, &myaddr);
1368 return ipcp_SetIPaddress(ipcp, myaddr, hisaddr);
1372 ipcp_UseHisaddr(struct bundle *bundle, const char *hisaddr, int setaddr)
1374 struct in_addr myaddr;
1375 struct ncp *ncp = &bundle->ncp;
1376 struct ipcp *ipcp = &ncp->ipcp;
1377 struct ncpaddr ncpaddr;
1379 /* Use `hisaddr' for the peers address (set iface if `setaddr') */
1380 memset(&ipcp->cfg.peer_range, '\0', sizeof ipcp->cfg.peer_range);
1381 iplist_reset(&ipcp->cfg.peer_list);
1382 if (strpbrk(hisaddr, ",-")) {
1383 iplist_setsrc(&ipcp->cfg.peer_list, hisaddr);
1384 if (iplist_isvalid(&ipcp->cfg.peer_list)) {
1385 iplist_setrandpos(&ipcp->cfg.peer_list);
1386 ipcp->peer_ip = ChooseHisAddr(bundle, ipcp->my_ip);
1387 if (ipcp->peer_ip.s_addr == INADDR_ANY) {
1388 log_Printf(LogWARN, "%s: None available !\n", ipcp->cfg.peer_list.src);
1391 ncprange_setip4host(&ipcp->cfg.peer_range, ipcp->peer_ip);
1393 log_Printf(LogWARN, "%s: Invalid range !\n", hisaddr);
1396 } else if (ncprange_aton(&ipcp->cfg.peer_range, ncp, hisaddr) != 0) {
1397 if (ncprange_family(&ipcp->cfg.my_range) != AF_INET) {
1398 log_Printf(LogWARN, "%s: Not an AF_INET address !\n", hisaddr);
1401 ncprange_getip4addr(&ipcp->cfg.my_range, &myaddr);
1402 ncprange_getip4addr(&ipcp->cfg.peer_range, &ipcp->peer_ip);
1404 if (setaddr && !ipcp_SetIPaddress(ipcp, myaddr, ipcp->peer_ip))
1409 ncpaddr_setip4(&ncpaddr, ipcp->peer_ip);
1410 bundle_AdjustFilters(bundle, NULL, &ncpaddr);
1416 addr2mask(struct in_addr addr)
1418 u_int32_t haddr = ntohl(addr.s_addr);
1420 haddr = IN_CLASSA(haddr) ? IN_CLASSA_NET :
1421 IN_CLASSB(haddr) ? IN_CLASSB_NET :
1423 addr.s_addr = htonl(haddr);
1429 ipcp_QueueLen(struct ipcp *ipcp)
1435 for (q = ipcp->Queue; q < ipcp->Queue + IPCP_QUEUES(ipcp); q++)
1442 ipcp_PushPacket(struct ipcp *ipcp, struct link *l)
1444 struct bundle *bundle = ipcp->fsm.bundle;
1445 struct mqueue *queue;
1449 unsigned alivesecs = 0;
1451 if (ipcp->fsm.state != ST_OPENED)
1455 * If ccp is not open but is required, do nothing.
1457 if (l->ccp.fsm.state != ST_OPENED && ccp_Required(&l->ccp)) {
1458 log_Printf(LogPHASE, "%s: Not transmitting... waiting for CCP\n", l->name);
1462 queue = ipcp->Queue + IPCP_QUEUES(ipcp) - 1;
1465 bp = m_dequeue(queue);
1466 bp = mbuf_Read(bp, &secs, sizeof secs);
1468 m_len = m_length(bp);
1469 if (!FilterCheck(MBUF_CTOP(bp), AF_INET, &bundle->filter.alive,
1473 bundle_StartIdleTimer(bundle, secs);
1475 link_PushPacket(l, bp, bundle, 0, PROTO_IP);
1476 ipcp_AddOutOctets(ipcp, m_len);
1479 } while (queue-- != ipcp->Queue);