2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 1996 - 2001 Brian Somers <brian@Awfulhak.org>
5 * based on work by Toshiharu OHNO <tony-o@iij.ad.jp>
6 * Internet Initiative Japan, Inc (IIJ)
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/param.h>
34 #include <netinet/in_systm.h>
35 #include <netinet/in.h>
36 #include <netinet/ip.h>
37 #include <arpa/inet.h>
38 #include <sys/socket.h>
40 #include <net/route.h>
72 #include "throughput.h"
73 #include "slcompress.h"
81 #include "descriptor.h"
102 #define REJECTED(p, x) ((p)->peer_reject & (1<<(x)))
103 #define issep(ch) ((ch) == ' ' || (ch) == '\t')
104 #define isip(ch) (((ch) >= '0' && (ch) <= '9') || (ch) == '.')
112 static int IpcpLayerUp(struct fsm *);
113 static void IpcpLayerDown(struct fsm *);
114 static void IpcpLayerStart(struct fsm *);
115 static void IpcpLayerFinish(struct fsm *);
116 static void IpcpInitRestartCounter(struct fsm *, int);
117 static void IpcpSendConfigReq(struct fsm *);
118 static void IpcpSentTerminateReq(struct fsm *);
119 static void IpcpSendTerminateAck(struct fsm *, u_char);
120 static void IpcpDecodeConfig(struct fsm *, u_char *, u_char *, int,
121 struct fsm_decode *);
123 extern struct libalias *la;
125 static struct fsm_callbacks ipcp_Callbacks = {
130 IpcpInitRestartCounter,
132 IpcpSentTerminateReq,
133 IpcpSendTerminateAck,
135 fsm_NullRecvResetReq,
146 /* Check out the latest ``Assigned numbers'' rfc (rfc1700.txt) */
147 { 1, "IPADDRS" }, /* IP-Addresses */ /* deprecated */
148 { 2, "COMPPROTO" }, /* IP-Compression-Protocol */
149 { 3, "IPADDR" }, /* IP-Address */
150 { 129, "PRIDNS" }, /* 129: Primary DNS Server Address */
151 { 130, "PRINBNS" }, /* 130: Primary NBNS Server Address */
152 { 131, "SECDNS" }, /* 131: Secondary DNS Server Address */
153 { 132, "SECNBNS" } /* 132: Secondary NBNS Server Address */
157 for (f = 0; f < sizeof cftypes / sizeof *cftypes; f++)
158 if (cftypes[f].id == proto)
159 return cftypes[f].txt;
161 return NumStr(proto, NULL, 0);
165 ipcp_AddInOctets(struct ipcp *ipcp, int n)
167 throughput_addin(&ipcp->throughput, n);
171 ipcp_AddOutOctets(struct ipcp *ipcp, int n)
173 throughput_addout(&ipcp->throughput, n);
177 ipcp_LoadDNS(struct ipcp *ipcp)
181 ipcp->ns.dns[0].s_addr = ipcp->ns.dns[1].s_addr = INADDR_NONE;
183 if (ipcp->ns.resolv != NULL) {
184 free(ipcp->ns.resolv);
185 ipcp->ns.resolv = NULL;
187 if (ipcp->ns.resolv_nons != NULL) {
188 free(ipcp->ns.resolv_nons);
189 ipcp->ns.resolv_nons = NULL;
191 ipcp->ns.resolver = 0;
193 if ((fd = open(_PATH_RESCONF, O_RDONLY)) != -1) {
196 if (fstat(fd, &st) == 0) {
200 * Note, ns.resolv and ns.resolv_nons are assumed to always point to
201 * buffers of the same size! See the strcpy() below.
203 if ((ipcp->ns.resolv_nons = (char *)malloc(st.st_size + 1)) == NULL)
204 log_Printf(LogERROR, "Failed to malloc %lu for %s: %s\n",
205 (unsigned long)st.st_size, _PATH_RESCONF, strerror(errno));
206 else if ((ipcp->ns.resolv = (char *)malloc(st.st_size + 1)) == NULL) {
207 log_Printf(LogERROR, "Failed(2) to malloc %lu for %s: %s\n",
208 (unsigned long)st.st_size, _PATH_RESCONF, strerror(errno));
209 free(ipcp->ns.resolv_nons);
210 ipcp->ns.resolv_nons = NULL;
211 } else if ((got = read(fd, ipcp->ns.resolv, st.st_size)) != st.st_size) {
213 log_Printf(LogERROR, "Failed to read %s: %s\n",
214 _PATH_RESCONF, strerror(errno));
216 log_Printf(LogERROR, "Failed to read %s, got %lu not %lu\n",
217 _PATH_RESCONF, (unsigned long)got,
218 (unsigned long)st.st_size);
219 free(ipcp->ns.resolv_nons);
220 ipcp->ns.resolv_nons = NULL;
221 free(ipcp->ns.resolv);
222 ipcp->ns.resolv = NULL;
224 char *cp, *cp_nons, *ncp, ch;
227 ipcp->ns.resolv[st.st_size] = '\0';
228 ipcp->ns.resolver = 1;
230 cp_nons = ipcp->ns.resolv_nons;
231 cp = ipcp->ns.resolv;
234 while ((ncp = strstr(cp, "nameserver")) != NULL) {
236 memcpy(cp_nons, cp, ncp - cp);
239 if ((ncp != cp && ncp[-1] != '\n') || !issep(ncp[10])) {
240 memcpy(cp_nons, ncp, 9);
242 cp = ncp + 9; /* Can't match "nameserver" at cp... */
246 for (cp = ncp + 11; issep(*cp); cp++) /* Skip whitespace */
249 for (ncp = cp; isip(*ncp); ncp++) /* Jump over IP */
254 if (n < 2 && inet_aton(cp, ipcp->ns.dns))
258 if ((cp = strchr(ncp, '\n')) == NULL) /* Point at next line */
259 cp = ncp + strlen(ncp);
264 * Note, cp_nons and cp always point to buffers of the same size, so
267 strcpy(cp_nons, cp); /* Copy the end - including the NUL */
268 cp_nons += strlen(cp_nons) - 1;
269 while (cp_nons >= ipcp->ns.resolv_nons && *cp_nons == '\n')
271 if (n == 2 && ipcp->ns.dns[0].s_addr == INADDR_ANY) {
272 ipcp->ns.dns[0].s_addr = ipcp->ns.dns[1].s_addr;
273 ipcp->ns.dns[1].s_addr = INADDR_ANY;
275 bundle_AdjustDNS(ipcp->fsm.bundle);
278 log_Printf(LogERROR, "Failed to stat opened %s: %s\n",
279 _PATH_RESCONF, strerror(errno));
286 ipcp_WriteDNS(struct ipcp *ipcp)
292 if (ipcp->ns.dns[0].s_addr == INADDR_ANY &&
293 ipcp->ns.dns[1].s_addr == INADDR_ANY) {
294 log_Printf(LogIPCP, "%s not modified: All nameservers NAKd\n",
299 if (ipcp->ns.dns[0].s_addr == INADDR_ANY) {
300 ipcp->ns.dns[0].s_addr = ipcp->ns.dns[1].s_addr;
301 ipcp->ns.dns[1].s_addr = INADDR_ANY;
305 if ((fp = ID0fopen(_PATH_RESCONF, "w")) != NULL) {
307 if (ipcp->ns.resolv_nons)
308 fputs(ipcp->ns.resolv_nons, fp);
309 paddr = inet_ntoa(ipcp->ns.dns[0]);
310 log_Printf(LogIPCP, "Primary nameserver set to %s\n", paddr);
311 fprintf(fp, "\nnameserver %s\n", paddr);
312 if (ipcp->ns.dns[1].s_addr != INADDR_ANY &&
313 ipcp->ns.dns[1].s_addr != INADDR_NONE &&
314 ipcp->ns.dns[1].s_addr != ipcp->ns.dns[0].s_addr) {
315 paddr = inet_ntoa(ipcp->ns.dns[1]);
316 log_Printf(LogIPCP, "Secondary nameserver set to %s\n", paddr);
317 fprintf(fp, "nameserver %s\n", paddr);
319 if (fclose(fp) == EOF) {
320 log_Printf(LogERROR, "write(): Failed updating %s: %s\n", _PATH_RESCONF,
326 log_Printf(LogERROR,"fopen(\"%s\", \"w\") failed: %s\n", _PATH_RESCONF,
334 ipcp_RestoreDNS(struct ipcp *ipcp)
336 if (ipcp->ns.resolver) {
340 if ((fd = ID0open(_PATH_RESCONF, O_WRONLY|O_TRUNC, 0644)) != -1) {
341 len = strlen(ipcp->ns.resolv);
342 if ((got = write(fd, ipcp->ns.resolv, len)) != len) {
344 log_Printf(LogERROR, "Failed rewriting %s: write: %s\n",
345 _PATH_RESCONF, strerror(errno));
347 log_Printf(LogERROR, "Failed rewriting %s: wrote %ld of %ld\n",
348 _PATH_RESCONF, (long)got, (long)len);
352 log_Printf(LogERROR, "Failed rewriting %s: open: %s\n", _PATH_RESCONF,
354 } else if (remove(_PATH_RESCONF) == -1)
355 log_Printf(LogERROR, "Failed removing %s: %s\n", _PATH_RESCONF,
361 ipcp_Show(struct cmdargs const *arg)
363 struct ipcp *ipcp = &arg->bundle->ncp.ipcp;
365 prompt_Printf(arg->prompt, "%s [%s]\n", ipcp->fsm.name,
366 State2Nam(ipcp->fsm.state));
367 if (ipcp->fsm.state == ST_OPENED) {
368 prompt_Printf(arg->prompt, " His side: %s, %s\n",
369 inet_ntoa(ipcp->peer_ip), vj2asc(ipcp->peer_compproto));
370 prompt_Printf(arg->prompt, " My side: %s, %s\n",
371 inet_ntoa(ipcp->my_ip), vj2asc(ipcp->my_compproto));
372 prompt_Printf(arg->prompt, " Queued packets: %lu\n",
373 (unsigned long)ipcp_QueueLen(ipcp));
376 prompt_Printf(arg->prompt, "\nDefaults:\n");
377 prompt_Printf(arg->prompt, " FSM retry = %us, max %u Config"
378 " REQ%s, %u Term REQ%s\n", ipcp->cfg.fsm.timeout,
379 ipcp->cfg.fsm.maxreq, ipcp->cfg.fsm.maxreq == 1 ? "" : "s",
380 ipcp->cfg.fsm.maxtrm, ipcp->cfg.fsm.maxtrm == 1 ? "" : "s");
381 prompt_Printf(arg->prompt, " My Address: %s\n",
382 ncprange_ntoa(&ipcp->cfg.my_range));
383 if (ipcp->cfg.HaveTriggerAddress)
384 prompt_Printf(arg->prompt, " Trigger address: %s\n",
385 inet_ntoa(ipcp->cfg.TriggerAddress));
387 prompt_Printf(arg->prompt, " VJ compression: %s (%d slots %s slot "
388 "compression)\n", command_ShowNegval(ipcp->cfg.vj.neg),
389 ipcp->cfg.vj.slots, ipcp->cfg.vj.slotcomp ? "with" : "without");
391 if (iplist_isvalid(&ipcp->cfg.peer_list))
392 prompt_Printf(arg->prompt, " His Address: %s\n",
393 ipcp->cfg.peer_list.src);
395 prompt_Printf(arg->prompt, " His Address: %s\n",
396 ncprange_ntoa(&ipcp->cfg.peer_range));
398 prompt_Printf(arg->prompt, " DNS: %s",
399 ipcp->cfg.ns.dns[0].s_addr == INADDR_NONE ?
400 "none" : inet_ntoa(ipcp->cfg.ns.dns[0]));
401 if (ipcp->cfg.ns.dns[1].s_addr != INADDR_NONE)
402 prompt_Printf(arg->prompt, ", %s",
403 inet_ntoa(ipcp->cfg.ns.dns[1]));
404 prompt_Printf(arg->prompt, ", %s\n",
405 command_ShowNegval(ipcp->cfg.ns.dns_neg));
406 prompt_Printf(arg->prompt, " Resolver DNS: %s",
407 ipcp->ns.dns[0].s_addr == INADDR_NONE ?
408 "none" : inet_ntoa(ipcp->ns.dns[0]));
409 if (ipcp->ns.dns[1].s_addr != INADDR_NONE &&
410 ipcp->ns.dns[1].s_addr != ipcp->ns.dns[0].s_addr)
411 prompt_Printf(arg->prompt, ", %s",
412 inet_ntoa(ipcp->ns.dns[1]));
413 prompt_Printf(arg->prompt, "\n NetBIOS NS: %s, ",
414 inet_ntoa(ipcp->cfg.ns.nbns[0]));
415 prompt_Printf(arg->prompt, "%s\n\n",
416 inet_ntoa(ipcp->cfg.ns.nbns[1]));
418 throughput_disp(&ipcp->throughput, arg->prompt);
424 ipcp_vjset(struct cmdargs const *arg)
426 if (arg->argc != arg->argn+2)
428 if (!strcasecmp(arg->argv[arg->argn], "slots")) {
431 slots = atoi(arg->argv[arg->argn+1]);
432 if (slots < 4 || slots > 16)
434 arg->bundle->ncp.ipcp.cfg.vj.slots = slots;
436 } else if (!strcasecmp(arg->argv[arg->argn], "slotcomp")) {
437 if (!strcasecmp(arg->argv[arg->argn+1], "on"))
438 arg->bundle->ncp.ipcp.cfg.vj.slotcomp = 1;
439 else if (!strcasecmp(arg->argv[arg->argn+1], "off"))
440 arg->bundle->ncp.ipcp.cfg.vj.slotcomp = 0;
449 ipcp_Init(struct ipcp *ipcp, struct bundle *bundle, struct link *l,
450 const struct fsm_parent *parent)
454 char name[MAXHOSTNAMELEN];
455 static const char * const timer_names[] =
456 {"IPCP restart", "IPCP openmode", "IPCP stopped"};
458 fsm_Init(&ipcp->fsm, "IPCP", PROTO_IPCP, 1, IPCP_MAXCODE, LogIPCP,
459 bundle, l, parent, &ipcp_Callbacks, timer_names);
461 ipcp->cfg.vj.slots = DEF_VJ_STATES;
462 ipcp->cfg.vj.slotcomp = 1;
463 memset(&ipcp->cfg.my_range, '\0', sizeof ipcp->cfg.my_range);
465 host.s_addr = htonl(INADDR_LOOPBACK);
466 ipcp->cfg.netmask.s_addr = INADDR_ANY;
467 if (gethostname(name, sizeof name) == 0) {
468 hp = gethostbyname(name);
469 if (hp && hp->h_addrtype == AF_INET && hp->h_length == sizeof host.s_addr)
470 memcpy(&host.s_addr, hp->h_addr, sizeof host.s_addr);
472 ncprange_setip4(&ipcp->cfg.my_range, host, ipcp->cfg.netmask);
473 ncprange_setip4(&ipcp->cfg.peer_range, ipcp->cfg.netmask, ipcp->cfg.netmask);
475 iplist_setsrc(&ipcp->cfg.peer_list, "");
476 ipcp->cfg.HaveTriggerAddress = 0;
478 ipcp->cfg.ns.dns[0].s_addr = INADDR_NONE;
479 ipcp->cfg.ns.dns[1].s_addr = INADDR_NONE;
480 ipcp->cfg.ns.dns_neg = 0;
481 ipcp->cfg.ns.nbns[0].s_addr = INADDR_ANY;
482 ipcp->cfg.ns.nbns[1].s_addr = INADDR_ANY;
484 ipcp->cfg.fsm.timeout = DEF_FSMRETRY;
485 ipcp->cfg.fsm.maxreq = DEF_FSMTRIES;
486 ipcp->cfg.fsm.maxtrm = DEF_FSMTRIES;
487 ipcp->cfg.vj.neg = NEG_ENABLED|NEG_ACCEPTED;
489 memset(&ipcp->vj, '\0', sizeof ipcp->vj);
491 ipcp->ns.resolv = NULL;
492 ipcp->ns.resolv_nons = NULL;
493 ipcp->ns.writable = 1;
496 throughput_init(&ipcp->throughput, SAMPLE_PERIOD);
497 memset(ipcp->Queue, '\0', sizeof ipcp->Queue);
498 ipcp_Setup(ipcp, INADDR_NONE);
502 ipcp_Destroy(struct ipcp *ipcp)
504 throughput_destroy(&ipcp->throughput);
506 if (ipcp->ns.resolv != NULL) {
507 free(ipcp->ns.resolv);
508 ipcp->ns.resolv = NULL;
510 if (ipcp->ns.resolv_nons != NULL) {
511 free(ipcp->ns.resolv_nons);
512 ipcp->ns.resolv_nons = NULL;
517 ipcp_SetLink(struct ipcp *ipcp, struct link *l)
523 ipcp_Setup(struct ipcp *ipcp, u_int32_t mask)
525 struct iface *iface = ipcp->fsm.bundle->iface;
526 struct ncpaddr ipaddr;
531 ipcp->fsm.open_mode = 0;
532 ipcp->ifmask.s_addr = mask == INADDR_NONE ? ipcp->cfg.netmask.s_addr : mask;
534 if (iplist_isvalid(&ipcp->cfg.peer_list)) {
535 /* Try to give the peer a previously configured IP address */
536 for (n = 0; n < iface->addrs; n++) {
537 if (!ncpaddr_getip4(&iface->addr[n].peer, &peer))
539 if ((pos = iplist_ip2pos(&ipcp->cfg.peer_list, peer)) != -1) {
540 ncpaddr_setip4(&ipaddr, iplist_setcurpos(&ipcp->cfg.peer_list, pos));
544 if (n == iface->addrs)
545 /* Ok, so none of 'em fit.... pick a random one */
546 ncpaddr_setip4(&ipaddr, iplist_setrandpos(&ipcp->cfg.peer_list));
548 ncprange_sethost(&ipcp->cfg.peer_range, &ipaddr);
553 ncprange_getip4addr(&ipcp->cfg.peer_range, &ipcp->peer_ip);
554 ipcp->peer_compproto = 0;
556 if (ipcp->cfg.HaveTriggerAddress) {
558 * Some implementations of PPP require that we send a
559 * *special* value as our address, even though the rfc specifies
560 * full negotiation (e.g. "0.0.0.0" or Not "0.0.0.0").
562 ipcp->my_ip = ipcp->cfg.TriggerAddress;
563 log_Printf(LogIPCP, "Using trigger address %s\n",
564 inet_ntoa(ipcp->cfg.TriggerAddress));
567 * Otherwise, if we've used an IP number before and it's still within
568 * the network specified on the ``set ifaddr'' line, we really
569 * want to keep that IP number so that we can keep any existing
570 * connections that are bound to that IP.
572 for (n = 0; n < iface->addrs; n++) {
573 ncprange_getaddr(&iface->addr[n].ifa, &ipaddr);
574 if (ncprange_contains(&ipcp->cfg.my_range, &ipaddr)) {
575 ncpaddr_getip4(&ipaddr, &ipcp->my_ip);
579 if (n == iface->addrs)
580 ncprange_getip4addr(&ipcp->cfg.my_range, &ipcp->my_ip);
583 if (IsEnabled(ipcp->cfg.vj.neg)
585 || (ipcp->fsm.bundle->radius.valid && ipcp->fsm.bundle->radius.vj)
588 ipcp->my_compproto = (PROTO_VJCOMP << 16) +
589 ((ipcp->cfg.vj.slots - 1) << 8) +
590 ipcp->cfg.vj.slotcomp;
592 ipcp->my_compproto = 0;
593 sl_compress_init(&ipcp->vj.cslc, ipcp->cfg.vj.slots - 1);
595 ipcp->peer_reject = 0;
598 /* Copy startup values into ipcp->ns.dns */
599 if (ipcp->cfg.ns.dns[0].s_addr != INADDR_NONE)
600 memcpy(ipcp->ns.dns, ipcp->cfg.ns.dns, sizeof ipcp->ns.dns);
604 numaddresses(struct in_addr mask)
606 u_int32_t bit, haddr;
609 haddr = ntohl(mask.s_addr);
622 ipcp_proxyarp(struct ipcp *ipcp,
623 int (*proxyfun)(struct bundle *, struct in_addr),
624 const struct iface_addr *addr)
626 struct bundle *bundle = ipcp->fsm.bundle;
627 struct in_addr peer, mask, ip;
630 if (!ncpaddr_getip4(&addr->peer, &peer)) {
631 log_Printf(LogERROR, "Oops, ipcp_proxyarp() called with unexpected addr\n");
637 if (Enabled(bundle, OPT_PROXYALL)) {
638 ncprange_getip4mask(&addr->ifa, &mask);
639 if ((n = numaddresses(mask)) > 256) {
640 log_Printf(LogWARN, "%s: Too many addresses for proxyall\n",
641 ncprange_ntoa(&addr->ifa));
644 ip.s_addr = peer.s_addr & mask.s_addr;
646 ip.s_addr = htonl(ntohl(ip.s_addr) + 1);
650 if (!((ip.s_addr ^ peer.s_addr) & mask.s_addr)) {
651 if (!(ret = (*proxyfun)(bundle, ip)))
655 ip.s_addr = htonl(ntohl(ip.s_addr) + 1);
658 } else if (Enabled(bundle, OPT_PROXY))
659 ret = (*proxyfun)(bundle, peer);
665 ipcp_SetIPaddress(struct ipcp *ipcp, struct in_addr myaddr,
666 struct in_addr hisaddr)
668 struct bundle *bundle = ipcp->fsm.bundle;
669 struct ncpaddr myncpaddr, hisncpaddr;
670 struct ncprange myrange;
672 struct sockaddr_storage ssdst, ssgw, ssmask;
673 struct sockaddr *sadst, *sagw, *samask;
675 sadst = (struct sockaddr *)&ssdst;
676 sagw = (struct sockaddr *)&ssgw;
677 samask = (struct sockaddr *)&ssmask;
679 ncpaddr_setip4(&hisncpaddr, hisaddr);
680 ncpaddr_setip4(&myncpaddr, myaddr);
681 ncprange_sethost(&myrange, &myncpaddr);
683 mask = addr2mask(myaddr);
685 if (ipcp->ifmask.s_addr != INADDR_ANY &&
686 (ipcp->ifmask.s_addr & mask.s_addr) == mask.s_addr)
687 ncprange_setip4mask(&myrange, ipcp->ifmask);
689 if (!iface_Add(bundle->iface, &bundle->ncp, &myrange, &hisncpaddr,
690 IFACE_ADD_FIRST|IFACE_FORCE_ADD|IFACE_SYSTEM))
693 if (!Enabled(bundle, OPT_IFACEALIAS))
694 iface_Clear(bundle->iface, &bundle->ncp, AF_INET,
695 IFACE_CLEAR_ALIASES|IFACE_SYSTEM);
697 if (bundle->ncp.cfg.sendpipe > 0 || bundle->ncp.cfg.recvpipe > 0) {
698 ncprange_getsa(&myrange, &ssgw, &ssmask);
699 ncpaddr_getsa(&hisncpaddr, &ssdst);
700 rt_Update(bundle, sadst, sagw, samask, NULL, NULL);
703 if (Enabled(bundle, OPT_SROUTES))
704 route_Change(bundle, bundle->ncp.route, &myncpaddr, &hisncpaddr);
707 if (bundle->radius.valid)
708 route_Change(bundle, bundle->radius.routes, &myncpaddr, &hisncpaddr);
714 static struct in_addr
715 ChooseHisAddr(struct bundle *bundle, struct in_addr gw)
720 for (f = 0; f < bundle->ncp.ipcp.cfg.peer_list.nItems; f++) {
721 try = iplist_next(&bundle->ncp.ipcp.cfg.peer_list);
722 log_Printf(LogDEBUG, "ChooseHisAddr: Check item %ld (%s)\n",
724 if (ipcp_SetIPaddress(&bundle->ncp.ipcp, gw, try)) {
725 log_Printf(LogIPCP, "Selected IP address %s\n", inet_ntoa(try));
730 if (f == bundle->ncp.ipcp.cfg.peer_list.nItems) {
731 log_Printf(LogDEBUG, "ChooseHisAddr: All addresses in use !\n");
732 try.s_addr = INADDR_ANY;
739 IpcpInitRestartCounter(struct fsm *fp, int what)
741 /* Set fsm timer load */
742 struct ipcp *ipcp = fsm2ipcp(fp);
744 fp->FsmTimer.load = ipcp->cfg.fsm.timeout * SECTICKS;
747 fp->restart = ipcp->cfg.fsm.maxreq;
750 fp->restart = ipcp->cfg.fsm.maxtrm;
759 IpcpSendConfigReq(struct fsm *fp)
761 /* Send config REQ please */
762 struct physical *p = link2physical(fp->link);
763 struct ipcp *ipcp = fsm2ipcp(fp);
764 u_char buff[MAX_FSM_OPT_LEN];
767 o = (struct fsm_opt *)buff;
769 if ((p && !physical_IsSync(p)) || !REJECTED(ipcp, TY_IPADDR)) {
770 memcpy(o->data, &ipcp->my_ip.s_addr, 4);
771 INC_FSM_OPT(TY_IPADDR, 6, o);
774 if (ipcp->my_compproto && !REJECTED(ipcp, TY_COMPPROTO)) {
775 if (ipcp->heis1172) {
776 u_int16_t proto = PROTO_VJCOMP;
778 ua_htons(&proto, o->data);
779 INC_FSM_OPT(TY_COMPPROTO, 4, o);
783 req.proto = htons(ipcp->my_compproto >> 16);
784 req.slots = (ipcp->my_compproto >> 8) & 255;
785 req.compcid = ipcp->my_compproto & 1;
786 memcpy(o->data, &req, 4);
787 INC_FSM_OPT(TY_COMPPROTO, 6, o);
791 if (IsEnabled(ipcp->cfg.ns.dns_neg)) {
792 if (!REJECTED(ipcp, TY_PRIMARY_DNS - TY_ADJUST_NS)) {
793 memcpy(o->data, &ipcp->ns.dns[0].s_addr, 4);
794 INC_FSM_OPT(TY_PRIMARY_DNS, 6, o);
797 if (!REJECTED(ipcp, TY_SECONDARY_DNS - TY_ADJUST_NS)) {
798 memcpy(o->data, &ipcp->ns.dns[1].s_addr, 4);
799 INC_FSM_OPT(TY_SECONDARY_DNS, 6, o);
803 fsm_Output(fp, CODE_CONFIGREQ, fp->reqid, buff, (u_char *)o - buff,
808 IpcpSentTerminateReq(struct fsm *fp __unused)
810 /* Term REQ just sent by FSM */
814 IpcpSendTerminateAck(struct fsm *fp, u_char id)
816 /* Send Term ACK please */
817 fsm_Output(fp, CODE_TERMACK, id, NULL, 0, MB_IPCPOUT);
821 IpcpLayerStart(struct fsm *fp)
823 /* We're about to start up ! */
824 struct ipcp *ipcp = fsm2ipcp(fp);
826 log_Printf(LogIPCP, "%s: LayerStart.\n", fp->link->name);
827 throughput_start(&ipcp->throughput, "IPCP throughput",
828 Enabled(fp->bundle, OPT_THROUGHPUT));
829 fp->more.reqs = fp->more.naks = fp->more.rejs = ipcp->cfg.fsm.maxreq * 3;
834 IpcpLayerFinish(struct fsm *fp)
837 struct ipcp *ipcp = fsm2ipcp(fp);
839 log_Printf(LogIPCP, "%s: LayerFinish.\n", fp->link->name);
840 throughput_stop(&ipcp->throughput);
841 throughput_log(&ipcp->throughput, LogIPCP, NULL);
845 * Called from iface_Add() via ncp_IfaceAddrAdded()
848 ipcp_IfaceAddrAdded(struct ipcp *ipcp, const struct iface_addr *addr)
850 struct bundle *bundle = ipcp->fsm.bundle;
852 if (Enabled(bundle, OPT_PROXY) || Enabled(bundle, OPT_PROXYALL))
853 ipcp_proxyarp(ipcp, arp_SetProxy, addr);
857 * Called from iface_Clear() and iface_Delete() via ncp_IfaceAddrDeleted()
860 ipcp_IfaceAddrDeleted(struct ipcp *ipcp, const struct iface_addr *addr)
862 struct bundle *bundle = ipcp->fsm.bundle;
864 if (Enabled(bundle, OPT_PROXY) || Enabled(bundle, OPT_PROXYALL))
865 ipcp_proxyarp(ipcp, arp_ClearProxy, addr);
869 IpcpLayerDown(struct fsm *fp)
871 /* About to come down */
872 struct ipcp *ipcp = fsm2ipcp(fp);
873 static int recursing;
877 snprintf(addr, sizeof addr, "%s", inet_ntoa(ipcp->my_ip));
878 log_Printf(LogIPCP, "%s: LayerDown: %s\n", fp->link->name, addr);
881 radius_Flush(&fp->bundle->radius);
882 radius_Account(&fp->bundle->radius, &fp->bundle->radacct,
883 fp->bundle->links, RAD_STOP, &ipcp->throughput);
885 if (*fp->bundle->radius.cfg.file && fp->bundle->radius.filterid)
886 system_Select(fp->bundle, fp->bundle->radius.filterid, LINKDOWNFILE,
888 radius_StopTimer(&fp->bundle->radius);
892 * XXX this stuff should really live in the FSM. Our config should
893 * associate executable sections in files with events.
895 if (system_Select(fp->bundle, addr, LINKDOWNFILE, NULL, NULL) < 0) {
896 if (bundle_GetLabel(fp->bundle)) {
897 if (system_Select(fp->bundle, bundle_GetLabel(fp->bundle),
898 LINKDOWNFILE, NULL, NULL) < 0)
899 system_Select(fp->bundle, "MYADDR", LINKDOWNFILE, NULL, NULL);
901 system_Select(fp->bundle, "MYADDR", LINKDOWNFILE, NULL, NULL);
904 ipcp_Setup(ipcp, INADDR_NONE);
910 ipcp_InterfaceUp(struct ipcp *ipcp)
912 if (!ipcp_SetIPaddress(ipcp, ipcp->my_ip, ipcp->peer_ip)) {
913 log_Printf(LogERROR, "ipcp_InterfaceUp: unable to set ip address\n");
917 if (!iface_SetFlags(ipcp->fsm.bundle->iface->name, IFF_UP)) {
918 log_Printf(LogERROR, "ipcp_InterfaceUp: Can't set the IFF_UP flag on %s\n",
919 ipcp->fsm.bundle->iface->name);
924 if (ipcp->fsm.bundle->NatEnabled)
925 LibAliasSetAddress(la, ipcp->my_ip);
932 IpcpLayerUp(struct fsm *fp)
935 struct ipcp *ipcp = fsm2ipcp(fp);
938 log_Printf(LogIPCP, "%s: LayerUp.\n", fp->link->name);
939 snprintf(tbuff, sizeof tbuff, "%s", inet_ntoa(ipcp->my_ip));
940 log_Printf(LogIPCP, "myaddr %s hisaddr = %s\n",
941 tbuff, inet_ntoa(ipcp->peer_ip));
943 if (ipcp->peer_compproto >> 16 == PROTO_VJCOMP)
944 sl_compress_init(&ipcp->vj.cslc, (ipcp->peer_compproto >> 8) & 255);
946 if (!ipcp_InterfaceUp(ipcp))
950 radius_Account_Set_Ip(&fp->bundle->radacct, &ipcp->peer_ip, &ipcp->ifmask);
951 radius_Account(&fp->bundle->radius, &fp->bundle->radacct, fp->bundle->links,
952 RAD_START, &ipcp->throughput);
954 if (*fp->bundle->radius.cfg.file && fp->bundle->radius.filterid)
955 system_Select(fp->bundle, fp->bundle->radius.filterid, LINKUPFILE,
957 radius_StartTimer(fp->bundle);
961 * XXX this stuff should really live in the FSM. Our config should
962 * associate executable sections in files with events.
964 if (system_Select(fp->bundle, tbuff, LINKUPFILE, NULL, NULL) < 0) {
965 if (bundle_GetLabel(fp->bundle)) {
966 if (system_Select(fp->bundle, bundle_GetLabel(fp->bundle),
967 LINKUPFILE, NULL, NULL) < 0)
968 system_Select(fp->bundle, "MYADDR", LINKUPFILE, NULL, NULL);
970 system_Select(fp->bundle, "MYADDR", LINKUPFILE, NULL, NULL);
973 fp->more.reqs = fp->more.naks = fp->more.rejs = ipcp->cfg.fsm.maxreq * 3;
974 log_DisplayPrompts();
980 ipcp_ValidateReq(struct ipcp *ipcp, struct in_addr ip, struct fsm_decode *dec)
982 struct bundle *bundle = ipcp->fsm.bundle;
983 struct iface *iface = bundle->iface;
984 struct in_addr myaddr, peer;
987 if (iplist_isvalid(&ipcp->cfg.peer_list)) {
988 ncprange_getip4addr(&ipcp->cfg.my_range, &myaddr);
989 if (ip.s_addr == INADDR_ANY ||
990 iplist_ip2pos(&ipcp->cfg.peer_list, ip) < 0 ||
991 !ipcp_SetIPaddress(ipcp, myaddr, ip)) {
992 log_Printf(LogIPCP, "%s: Address invalid or already in use\n",
995 * If we've already had a valid address configured for the peer,
996 * try NAKing with that so that we don't have to upset things
999 for (n = 0; n < iface->addrs; n++) {
1000 if (!ncpaddr_getip4(&iface->addr[n].peer, &peer))
1002 if (iplist_ip2pos(&ipcp->cfg.peer_list, peer) >= 0) {
1003 ipcp->peer_ip = peer;
1008 if (n == iface->addrs) {
1009 /* Just pick an IP number from our list */
1010 ipcp->peer_ip = ChooseHisAddr(bundle, myaddr);
1013 if (ipcp->peer_ip.s_addr == INADDR_ANY) {
1014 *dec->rejend++ = TY_IPADDR;
1016 memcpy(dec->rejend, &ip.s_addr, 4);
1019 *dec->nakend++ = TY_IPADDR;
1021 memcpy(dec->nakend, &ipcp->peer_ip.s_addr, 4);
1026 } else if (ip.s_addr == INADDR_ANY ||
1027 !ncprange_containsip4(&ipcp->cfg.peer_range, ip)) {
1029 * If the destination address is not acceptable, NAK with what we
1032 *dec->nakend++ = TY_IPADDR;
1034 for (n = 0; n < iface->addrs; n++)
1035 if (ncprange_contains(&ipcp->cfg.peer_range, &iface->addr[n].peer)) {
1036 /* We prefer the already-configured address */
1037 ncpaddr_getip4addr(&iface->addr[n].peer, (u_int32_t *)dec->nakend);
1041 if (n == iface->addrs)
1042 memcpy(dec->nakend, &ipcp->peer_ip.s_addr, 4);
1049 *dec->ackend++ = TY_IPADDR;
1051 memcpy(dec->ackend, &ip.s_addr, 4);
1056 IpcpDecodeConfig(struct fsm *fp, u_char *cp, u_char *end, int mode_type,
1057 struct fsm_decode *dec)
1059 /* Deal with incoming PROTO_IPCP */
1060 struct ncpaddr ncpaddr;
1061 struct ipcp *ipcp = fsm2ipcp(fp);
1063 u_int32_t compproto;
1064 struct compreq pcomp;
1065 struct in_addr ipaddr, dstipaddr, have_ip;
1066 char tbuff[100], tbuff2[100];
1067 struct fsm_opt *opt, nak;
1071 while (end - cp >= (int)sizeof(opt->hdr)) {
1072 if ((opt = fsm_readopt(&cp)) == NULL)
1075 snprintf(tbuff, sizeof tbuff, " %s[%d]", protoname(opt->hdr.id),
1078 switch (opt->hdr.id) {
1079 case TY_IPADDR: /* RFC1332 */
1080 memcpy(&ipaddr.s_addr, opt->data, 4);
1081 log_Printf(LogIPCP, "%s %s\n", tbuff, inet_ntoa(ipaddr));
1083 switch (mode_type) {
1086 ipcp_ValidateReq(ipcp, ipaddr, dec);
1090 if (ncprange_containsip4(&ipcp->cfg.my_range, ipaddr)) {
1091 /* Use address suggested by peer */
1092 snprintf(tbuff2, sizeof tbuff2, "%s changing address: %s ", tbuff,
1093 inet_ntoa(ipcp->my_ip));
1094 log_Printf(LogIPCP, "%s --> %s\n", tbuff2, inet_ntoa(ipaddr));
1095 ipcp->my_ip = ipaddr;
1096 ncpaddr_setip4(&ncpaddr, ipcp->my_ip);
1097 bundle_AdjustFilters(fp->bundle, &ncpaddr, NULL);
1099 log_Printf(log_IsKept(LogIPCP) ? LogIPCP : LogPHASE,
1100 "%s: Unacceptable address!\n", inet_ntoa(ipaddr));
1101 fsm_Close(&ipcp->fsm);
1106 ipcp->peer_reject |= (1 << opt->hdr.id);
1112 memcpy(&pcomp, opt->data, sizeof pcomp);
1113 compproto = (ntohs(pcomp.proto) << 16) + ((int)pcomp.slots << 8) +
1115 log_Printf(LogIPCP, "%s %s\n", tbuff, vj2asc(compproto));
1117 switch (mode_type) {
1119 if (!IsAccepted(ipcp->cfg.vj.neg))
1122 switch (opt->hdr.len) {
1123 case 4: /* RFC1172 */
1124 if (ntohs(pcomp.proto) == PROTO_VJCOMP) {
1125 log_Printf(LogWARN, "Peer is speaking RFC1172 compression "
1128 ipcp->peer_compproto = compproto;
1131 pcomp.proto = htons(PROTO_VJCOMP);
1132 nak.hdr.id = TY_COMPPROTO;
1134 memcpy(nak.data, &pcomp, 2);
1138 case 6: /* RFC1332 */
1139 if (ntohs(pcomp.proto) == PROTO_VJCOMP) {
1140 /* We know pcomp.slots' max value == MAX_VJ_STATES */
1141 if (pcomp.slots >= MIN_VJ_STATES) {
1142 /* Ok, we can do that */
1143 ipcp->peer_compproto = compproto;
1147 /* Get as close as we can to what he wants */
1149 pcomp.slots = MIN_VJ_STATES;
1150 nak.hdr.id = TY_COMPPROTO;
1152 memcpy(nak.data, &pcomp, 2);
1156 /* What we really want */
1157 pcomp.proto = htons(PROTO_VJCOMP);
1158 pcomp.slots = DEF_VJ_STATES;
1160 nak.hdr.id = TY_COMPPROTO;
1162 memcpy(nak.data, &pcomp, sizeof pcomp);
1174 if (ntohs(pcomp.proto) == PROTO_VJCOMP) {
1175 /* We know pcomp.slots' max value == MAX_VJ_STATES */
1176 if (pcomp.slots < MIN_VJ_STATES)
1177 pcomp.slots = MIN_VJ_STATES;
1178 compproto = (ntohs(pcomp.proto) << 16) + (pcomp.slots << 8) +
1182 log_Printf(LogIPCP, "%s changing compproto: %08x --> %08x\n",
1183 tbuff, ipcp->my_compproto, compproto);
1184 ipcp->my_compproto = compproto;
1188 ipcp->peer_reject |= (1 << opt->hdr.id);
1193 case TY_IPADDRS: /* RFC1172 */
1194 memcpy(&ipaddr.s_addr, opt->data, 4);
1195 memcpy(&dstipaddr.s_addr, opt->data + 4, 4);
1196 snprintf(tbuff2, sizeof tbuff2, "%s %s,", tbuff, inet_ntoa(ipaddr));
1197 log_Printf(LogIPCP, "%s %s\n", tbuff2, inet_ntoa(dstipaddr));
1199 switch (mode_type) {
1210 case TY_PRIMARY_DNS: /* DNS negotiation (rfc1877) */
1211 case TY_SECONDARY_DNS:
1212 memcpy(&ipaddr.s_addr, opt->data, 4);
1213 log_Printf(LogIPCP, "%s %s\n", tbuff, inet_ntoa(ipaddr));
1215 switch (mode_type) {
1217 if (!IsAccepted(ipcp->cfg.ns.dns_neg)) {
1218 ipcp->my_reject |= (1 << (opt->hdr.id - TY_ADJUST_NS));
1222 have_ip = ipcp->ns.dns[opt->hdr.id == TY_PRIMARY_DNS ? 0 : 1];
1224 if (opt->hdr.id == TY_PRIMARY_DNS && ipaddr.s_addr != have_ip.s_addr &&
1225 ipaddr.s_addr == ipcp->ns.dns[1].s_addr) {
1226 /* Swap 'em 'round */
1227 ipcp->ns.dns[0] = ipcp->ns.dns[1];
1228 ipcp->ns.dns[1] = have_ip;
1229 have_ip = ipcp->ns.dns[0];
1232 if (ipaddr.s_addr != have_ip.s_addr) {
1234 * The client has got the DNS stuff wrong (first request) so
1235 * we'll tell 'em how it is
1237 nak.hdr.id = opt->hdr.id;
1239 memcpy(nak.data, &have_ip.s_addr, 4);
1243 * Otherwise they have it right (this time) so we send an ack packet
1244 * back confirming it... end of story
1251 if (IsEnabled(ipcp->cfg.ns.dns_neg)) {
1253 memcpy(&ipcp->ns.dns[opt->hdr.id == TY_PRIMARY_DNS ? 0 : 1].s_addr,
1258 case MODE_REJ: /* Can't do much, stop asking */
1259 ipcp->peer_reject |= (1 << (opt->hdr.id - TY_ADJUST_NS));
1264 case TY_PRIMARY_NBNS: /* M$ NetBIOS nameserver hack (rfc1877) */
1265 case TY_SECONDARY_NBNS:
1266 memcpy(&ipaddr.s_addr, opt->data, 4);
1267 log_Printf(LogIPCP, "%s %s\n", tbuff, inet_ntoa(ipaddr));
1269 switch (mode_type) {
1272 ipcp->cfg.ns.nbns[opt->hdr.id == TY_PRIMARY_NBNS ? 0 : 1].s_addr;
1274 if (have_ip.s_addr == INADDR_ANY) {
1275 log_Printf(LogIPCP, "NBNS REQ - rejected - nbns not set\n");
1276 ipcp->my_reject |= (1 << (opt->hdr.id - TY_ADJUST_NS));
1281 if (ipaddr.s_addr != have_ip.s_addr) {
1282 nak.hdr.id = opt->hdr.id;
1284 memcpy(nak.data, &have_ip.s_addr, 4);
1291 log_Printf(LogIPCP, "MS NBNS req %d - NAK??\n", opt->hdr.id);
1295 log_Printf(LogIPCP, "MS NBNS req %d - REJ??\n", opt->hdr.id);
1301 if (mode_type != MODE_NOP) {
1302 ipcp->my_reject |= (1 << opt->hdr.id);
1310 if (ipcp->ns.writable) {
1311 log_Printf(LogDEBUG, "Updating resolver\n");
1312 if (!ipcp_WriteDNS(ipcp)) {
1313 ipcp->peer_reject |= (1 << (TY_PRIMARY_DNS - TY_ADJUST_NS));
1314 ipcp->peer_reject |= (1 << (TY_SECONDARY_DNS - TY_ADJUST_NS));
1316 bundle_AdjustDNS(fp->bundle);
1318 log_Printf(LogDEBUG, "Not updating resolver (readonly)\n");
1319 bundle_AdjustDNS(fp->bundle);
1323 if (mode_type != MODE_NOP) {
1324 if (mode_type == MODE_REQ && !ipcp->peer_req) {
1325 if (dec->rejend == dec->rej && dec->nakend == dec->nak) {
1327 * Pretend the peer has requested an IP.
1328 * We do this to ensure that we only send one NAK if the only
1329 * reason for the NAK is because the peer isn't sending a
1330 * TY_IPADDR REQ. This stops us from repeatedly trying to tell
1331 * the peer that we have to have an IP address on their end.
1335 ipaddr.s_addr = INADDR_ANY;
1336 ipcp_ValidateReq(ipcp, ipaddr, dec);
1338 fsm_opt_normalise(dec);
1342 extern struct mbuf *
1343 ipcp_Input(struct bundle *bundle, struct link *l, struct mbuf *bp)
1345 /* Got PROTO_IPCP from link */
1346 m_settype(bp, MB_IPCPIN);
1347 if (bundle_Phase(bundle) == PHASE_NETWORK)
1348 fsm_Input(&bundle->ncp.ipcp.fsm, bp);
1350 if (bundle_Phase(bundle) < PHASE_NETWORK)
1351 log_Printf(LogIPCP, "%s: Error: Unexpected IPCP in phase %s (ignored)\n",
1352 l->name, bundle_PhaseName(bundle));
1359 ipcp_UseHisIPaddr(struct bundle *bundle, struct in_addr hisaddr)
1361 struct ipcp *ipcp = &bundle->ncp.ipcp;
1362 struct in_addr myaddr;
1364 memset(&ipcp->cfg.peer_range, '\0', sizeof ipcp->cfg.peer_range);
1365 iplist_reset(&ipcp->cfg.peer_list);
1366 ipcp->peer_ip = hisaddr;
1367 ncprange_setip4host(&ipcp->cfg.peer_range, hisaddr);
1368 ncprange_getip4addr(&ipcp->cfg.my_range, &myaddr);
1370 return ipcp_SetIPaddress(ipcp, myaddr, hisaddr);
1374 ipcp_UseHisaddr(struct bundle *bundle, const char *hisaddr, int setaddr)
1376 struct in_addr myaddr;
1377 struct ncp *ncp = &bundle->ncp;
1378 struct ipcp *ipcp = &ncp->ipcp;
1379 struct ncpaddr ncpaddr;
1381 /* Use `hisaddr' for the peers address (set iface if `setaddr') */
1382 memset(&ipcp->cfg.peer_range, '\0', sizeof ipcp->cfg.peer_range);
1383 iplist_reset(&ipcp->cfg.peer_list);
1384 if (strpbrk(hisaddr, ",-")) {
1385 iplist_setsrc(&ipcp->cfg.peer_list, hisaddr);
1386 if (iplist_isvalid(&ipcp->cfg.peer_list)) {
1387 iplist_setrandpos(&ipcp->cfg.peer_list);
1388 ipcp->peer_ip = ChooseHisAddr(bundle, ipcp->my_ip);
1389 if (ipcp->peer_ip.s_addr == INADDR_ANY) {
1390 log_Printf(LogWARN, "%s: None available !\n", ipcp->cfg.peer_list.src);
1393 ncprange_setip4host(&ipcp->cfg.peer_range, ipcp->peer_ip);
1395 log_Printf(LogWARN, "%s: Invalid range !\n", hisaddr);
1398 } else if (ncprange_aton(&ipcp->cfg.peer_range, ncp, hisaddr) != 0) {
1399 if (ncprange_family(&ipcp->cfg.my_range) != AF_INET) {
1400 log_Printf(LogWARN, "%s: Not an AF_INET address !\n", hisaddr);
1403 ncprange_getip4addr(&ipcp->cfg.my_range, &myaddr);
1404 ncprange_getip4addr(&ipcp->cfg.peer_range, &ipcp->peer_ip);
1406 if (setaddr && !ipcp_SetIPaddress(ipcp, myaddr, ipcp->peer_ip))
1411 ncpaddr_setip4(&ncpaddr, ipcp->peer_ip);
1412 bundle_AdjustFilters(bundle, NULL, &ncpaddr);
1418 addr2mask(struct in_addr addr)
1420 u_int32_t haddr = ntohl(addr.s_addr);
1422 haddr = IN_CLASSA(haddr) ? IN_CLASSA_NET :
1423 IN_CLASSB(haddr) ? IN_CLASSB_NET :
1425 addr.s_addr = htonl(haddr);
1431 ipcp_QueueLen(struct ipcp *ipcp)
1437 for (q = ipcp->Queue; q < ipcp->Queue + IPCP_QUEUES(ipcp); q++)
1444 ipcp_PushPacket(struct ipcp *ipcp, struct link *l)
1446 struct bundle *bundle = ipcp->fsm.bundle;
1447 struct mqueue *queue;
1451 unsigned alivesecs = 0;
1453 if (ipcp->fsm.state != ST_OPENED)
1457 * If ccp is not open but is required, do nothing.
1459 if (l->ccp.fsm.state != ST_OPENED && ccp_Required(&l->ccp)) {
1460 log_Printf(LogPHASE, "%s: Not transmitting... waiting for CCP\n", l->name);
1464 queue = ipcp->Queue + IPCP_QUEUES(ipcp) - 1;
1467 bp = m_dequeue(queue);
1468 bp = mbuf_Read(bp, &secs, sizeof secs);
1470 m_len = m_length(bp);
1471 if (!FilterCheck(MBUF_CTOP(bp), AF_INET, &bundle->filter.alive,
1475 bundle_StartIdleTimer(bundle, secs);
1477 link_PushPacket(l, bp, bundle, 0, PROTO_IP);
1478 ipcp_AddOutOctets(ipcp, m_len);
1481 } while (queue-- != ipcp->Queue);