ncp.c (81888) | ncp.c (81897) |
---|---|
1/*- 2 * Copyright (c) 2001 Brian Somers <brian@Awfulhak.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * | 1/*- 2 * Copyright (c) 2001 Brian Somers <brian@Awfulhak.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * |
26 * $FreeBSD: head/usr.sbin/ppp/ncp.c 81888 2001-08-18 13:04:52Z brian $ | 26 * $FreeBSD: head/usr.sbin/ppp/ncp.c 81897 2001-08-18 19:07:13Z brian $ |
27 */ 28 29#include <sys/param.h> 30#include <netinet/in_systm.h> 31#include <netinet/in.h> 32#include <netinet/ip.h> 33#include <arpa/inet.h> 34#include <sys/socket.h> --- 50 unchanged lines hidden (view full) --- 85#include "route.h" 86#include "iface.h" 87#include "chat.h" 88#include "auth.h" 89#include "chap.h" 90#include "pap.h" 91#include "cbcp.h" 92#include "datalink.h" | 27 */ 28 29#include <sys/param.h> 30#include <netinet/in_systm.h> 31#include <netinet/in.h> 32#include <netinet/ip.h> 33#include <arpa/inet.h> 34#include <sys/socket.h> --- 50 unchanged lines hidden (view full) --- 85#include "route.h" 86#include "iface.h" 87#include "chat.h" 88#include "auth.h" 89#include "chap.h" 90#include "pap.h" 91#include "cbcp.h" 92#include "datalink.h" |
93#include "probe.h" | |
94 95 96static u_short default_urgent_tcp_ports[] = { 97 21, /* ftp */ 98 22, /* ssh */ 99 23, /* telnet */ 100 513, /* login */ 101 514, /* shell */ --- 27 unchanged lines hidden (view full) --- 129 130 131 mp_Init(&ncp->mp, bundle); 132 133 /* Send over the first physical link by default */ 134 ipcp_Init(&ncp->ipcp, bundle, &bundle->links->physical->link, 135 &bundle->fsm); 136#ifndef NOINET6 | 93 94 95static u_short default_urgent_tcp_ports[] = { 96 21, /* ftp */ 97 22, /* ssh */ 98 23, /* telnet */ 99 513, /* login */ 100 514, /* shell */ --- 27 unchanged lines hidden (view full) --- 128 129 130 mp_Init(&ncp->mp, bundle); 131 132 /* Send over the first physical link by default */ 133 ipcp_Init(&ncp->ipcp, bundle, &bundle->links->physical->link, 134 &bundle->fsm); 135#ifndef NOINET6 |
137 if (probe.ipv6_available) 138 ipv6cp_Init(&ncp->ipv6cp, bundle, &bundle->links->physical->link, 139 &bundle->fsm); | 136 ipv6cp_Init(&ncp->ipv6cp, bundle, &bundle->links->physical->link, 137 &bundle->fsm); |
140#endif 141} 142 143void 144ncp_Destroy(struct ncp *ncp) 145{ 146 ipcp_Destroy(&ncp->ipcp); 147#ifndef NOINET6 | 138#endif 139} 140 141void 142ncp_Destroy(struct ncp *ncp) 143{ 144 ipcp_Destroy(&ncp->ipcp); 145#ifndef NOINET6 |
148 if (probe.ipv6_available) 149 ipv6cp_Destroy(&ncp->ipv6cp); | 146 ipv6cp_Destroy(&ncp->ipv6cp); |
150#endif 151 152 if (ncp->cfg.urgent.tcp.maxports) { 153 ncp->cfg.urgent.tcp.nports = ncp->cfg.urgent.tcp.maxports = 0; 154 free(ncp->cfg.urgent.tcp.port); 155 ncp->cfg.urgent.tcp.port = NULL; 156 } 157 if (ncp->cfg.urgent.udp.maxports) { --- 12 unchanged lines hidden (view full) --- 170 if (Enabled(bundle, OPT_IPCP)) { 171#endif 172 fsm_Up(&ncp->ipcp.fsm); 173 fsm_Open(&ncp->ipcp.fsm); 174 res++; 175#ifndef NOINET6 176 } 177 | 147#endif 148 149 if (ncp->cfg.urgent.tcp.maxports) { 150 ncp->cfg.urgent.tcp.nports = ncp->cfg.urgent.tcp.maxports = 0; 151 free(ncp->cfg.urgent.tcp.port); 152 ncp->cfg.urgent.tcp.port = NULL; 153 } 154 if (ncp->cfg.urgent.udp.maxports) { --- 12 unchanged lines hidden (view full) --- 167 if (Enabled(bundle, OPT_IPCP)) { 168#endif 169 fsm_Up(&ncp->ipcp.fsm); 170 fsm_Open(&ncp->ipcp.fsm); 171 res++; 172#ifndef NOINET6 173 } 174 |
178 if (probe.ipv6_available && Enabled(bundle, OPT_IPV6CP)) { | 175 if (Enabled(bundle, OPT_IPV6CP)) { |
179 fsm_Up(&ncp->ipv6cp.fsm); 180 fsm_Open(&ncp->ipv6cp.fsm); 181 res++; 182 } 183#endif 184 185 return res; 186} --- 20 unchanged lines hidden (view full) --- 207 ipcp_IfaceAddrDeleted(&ncp->ipcp, addr); 208} 209 210void 211ncp_SetLink(struct ncp *ncp, struct link *l) 212{ 213 ipcp_SetLink(&ncp->ipcp, l); 214#ifndef NOINET6 | 176 fsm_Up(&ncp->ipv6cp.fsm); 177 fsm_Open(&ncp->ipv6cp.fsm); 178 res++; 179 } 180#endif 181 182 return res; 183} --- 20 unchanged lines hidden (view full) --- 204 ipcp_IfaceAddrDeleted(&ncp->ipcp, addr); 205} 206 207void 208ncp_SetLink(struct ncp *ncp, struct link *l) 209{ 210 ipcp_SetLink(&ncp->ipcp, l); 211#ifndef NOINET6 |
215 if (probe.ipv6_available) 216 ipv6cp_SetLink(&ncp->ipv6cp, l); | 212 ipv6cp_SetLink(&ncp->ipv6cp, l); |
217#endif 218} 219 220/* 221 * Enqueue a packet of the given address family. Nothing will make it 222 * down to the physical link level 'till ncp_FillPhysicalQueues() is used. 223 */ 224void --- 51 unchanged lines hidden (view full) --- 276 */ 277size_t 278ncp_QueueLen(struct ncp *ncp) 279{ 280 size_t result; 281 282 result = ipcp_QueueLen(&ncp->ipcp); 283#ifndef NOINET6 | 213#endif 214} 215 216/* 217 * Enqueue a packet of the given address family. Nothing will make it 218 * down to the physical link level 'till ncp_FillPhysicalQueues() is used. 219 */ 220void --- 51 unchanged lines hidden (view full) --- 272 */ 273size_t 274ncp_QueueLen(struct ncp *ncp) 275{ 276 size_t result; 277 278 result = ipcp_QueueLen(&ncp->ipcp); 279#ifndef NOINET6 |
284 if (probe.ipv6_available) 285 result += ipv6cp_QueueLen(&ncp->ipv6cp); | 280 result += ipv6cp_QueueLen(&ncp->ipv6cp); |
286#endif 287 result += mp_QueueLen(&ncp->mp); /* Usually empty */ 288 289 return result; 290} 291 292/* 293 * Ditch all queued packets. This is usually done after our choked timer --- 10 unchanged lines hidden (view full) --- 304 struct mp *mp = &ncp->mp; 305 struct mqueue *q; 306 307 for (q = ipcp->Queue; q < ipcp->Queue + IPCP_QUEUES(ipcp); q++) 308 while (q->top) 309 m_freem(m_dequeue(q)); 310 311#ifndef NOINET6 | 281#endif 282 result += mp_QueueLen(&ncp->mp); /* Usually empty */ 283 284 return result; 285} 286 287/* 288 * Ditch all queued packets. This is usually done after our choked timer --- 10 unchanged lines hidden (view full) --- 299 struct mp *mp = &ncp->mp; 300 struct mqueue *q; 301 302 for (q = ipcp->Queue; q < ipcp->Queue + IPCP_QUEUES(ipcp); q++) 303 while (q->top) 304 m_freem(m_dequeue(q)); 305 306#ifndef NOINET6 |
312 if (probe.ipv6_available) 313 for (q = ipv6cp->Queue; q < ipv6cp->Queue + IPV6CP_QUEUES(ipv6cp); q++) 314 while (q->top) 315 m_freem(m_dequeue(q)); | 307 for (q = ipv6cp->Queue; q < ipv6cp->Queue + IPV6CP_QUEUES(ipv6cp); q++) 308 while (q->top) 309 m_freem(m_dequeue(q)); |
316#endif 317 318 link_DeleteQueue(&mp->link); /* Usually empty anyway */ 319} 320 321/* 322 * Arrange that each of our links has at least one packet. We keep the 323 * number of packets queued at the link level to a minimum so that the --- 29 unchanged lines hidden (view full) --- 353 */ 354int 355ncp_PushPacket(struct ncp *ncp, int *af, struct link *l) 356{ 357 struct bundle *bundle = l->lcp.fsm.bundle; 358 int res; 359 360#ifndef NOINET6 | 310#endif 311 312 link_DeleteQueue(&mp->link); /* Usually empty anyway */ 313} 314 315/* 316 * Arrange that each of our links has at least one packet. We keep the 317 * number of packets queued at the link level to a minimum so that the --- 29 unchanged lines hidden (view full) --- 347 */ 348int 349ncp_PushPacket(struct ncp *ncp, int *af, struct link *l) 350{ 351 struct bundle *bundle = l->lcp.fsm.bundle; 352 int res; 353 354#ifndef NOINET6 |
361 if (!probe.ipv6_available) 362 res = ipcp_PushPacket(&bundle->ncp.ipcp, l); 363 else if (*af == AF_INET) { | 355 if (*af == AF_INET) { |
364 if ((res = ipcp_PushPacket(&bundle->ncp.ipcp, l))) 365 *af = AF_INET6; 366 else 367 res = ipv6cp_PushPacket(&bundle->ncp.ipv6cp, l); 368 } else { 369 if ((res = ipv6cp_PushPacket(&bundle->ncp.ipv6cp, l))) 370 *af = AF_INET; 371 else --- 79 unchanged lines hidden (view full) --- 451 452int 453ncp_Show(struct cmdargs const *arg) 454{ 455 struct ncp *ncp = &arg->bundle->ncp; 456 int p; 457 458#ifndef NOINET6 | 356 if ((res = ipcp_PushPacket(&bundle->ncp.ipcp, l))) 357 *af = AF_INET6; 358 else 359 res = ipv6cp_PushPacket(&bundle->ncp.ipv6cp, l); 360 } else { 361 if ((res = ipv6cp_PushPacket(&bundle->ncp.ipv6cp, l))) 362 *af = AF_INET; 363 else --- 79 unchanged lines hidden (view full) --- 443 444int 445ncp_Show(struct cmdargs const *arg) 446{ 447 struct ncp *ncp = &arg->bundle->ncp; 448 int p; 449 450#ifndef NOINET6 |
459 if (probe.ipv6_available) 460 prompt_Printf(arg->prompt, "Next queued AF: %s\n", 461 ncp->afq == AF_INET6 ? "inet6" : "inet"); | 451 prompt_Printf(arg->prompt, "Next queued AF: %s\n", 452 ncp->afq == AF_INET6 ? "inet6" : "inet"); |
462#endif 463 464 if (ncp->route) { 465 prompt_Printf(arg->prompt, "\n"); 466 route_ShowSticky(arg->prompt, ncp->route, "Sticky routes", 1); 467 } 468 469 prompt_Printf(arg->prompt, "\nDefaults:\n"); --- 36 unchanged lines hidden (view full) --- 506 507int 508ncp_LayersOpen(struct ncp *ncp) 509{ 510 int n; 511 512 n = !!(ncp->ipcp.fsm.state == ST_OPENED); 513#ifndef NOINET6 | 453#endif 454 455 if (ncp->route) { 456 prompt_Printf(arg->prompt, "\n"); 457 route_ShowSticky(arg->prompt, ncp->route, "Sticky routes", 1); 458 } 459 460 prompt_Printf(arg->prompt, "\nDefaults:\n"); --- 36 unchanged lines hidden (view full) --- 497 498int 499ncp_LayersOpen(struct ncp *ncp) 500{ 501 int n; 502 503 n = !!(ncp->ipcp.fsm.state == ST_OPENED); 504#ifndef NOINET6 |
514 if (probe.ipv6_available) 515 n += !!(ncp->ipv6cp.fsm.state == ST_OPENED); | 505 n += !!(ncp->ipv6cp.fsm.state == ST_OPENED); |
516#endif 517 518 return n; 519} 520 521int 522ncp_LayersUnfinished(struct ncp *ncp) 523{ 524 int n = 0; 525 526 if (ncp->ipcp.fsm.state > ST_CLOSED || 527 ncp->ipcp.fsm.state == ST_STARTING) 528 n++; 529 530#ifndef NOINET6 | 506#endif 507 508 return n; 509} 510 511int 512ncp_LayersUnfinished(struct ncp *ncp) 513{ 514 int n = 0; 515 516 if (ncp->ipcp.fsm.state > ST_CLOSED || 517 ncp->ipcp.fsm.state == ST_STARTING) 518 n++; 519 520#ifndef NOINET6 |
531 if (probe.ipv6_available) 532 if (ncp->ipv6cp.fsm.state > ST_CLOSED || 533 ncp->ipv6cp.fsm.state == ST_STARTING) 534 n++; | 521 if (ncp->ipv6cp.fsm.state > ST_CLOSED || 522 ncp->ipv6cp.fsm.state == ST_STARTING) 523 n++; |
535#endif 536 537 return n; 538} 539 540void 541ncp_Close(struct ncp *ncp) 542{ 543 if (ncp->ipcp.fsm.state > ST_CLOSED || 544 ncp->ipcp.fsm.state == ST_STARTING) 545 fsm_Close(&ncp->ipcp.fsm); 546 547#ifndef NOINET6 | 524#endif 525 526 return n; 527} 528 529void 530ncp_Close(struct ncp *ncp) 531{ 532 if (ncp->ipcp.fsm.state > ST_CLOSED || 533 ncp->ipcp.fsm.state == ST_STARTING) 534 fsm_Close(&ncp->ipcp.fsm); 535 536#ifndef NOINET6 |
548 if (probe.ipv6_available) 549 if (ncp->ipv6cp.fsm.state > ST_CLOSED || 550 ncp->ipv6cp.fsm.state == ST_STARTING) 551 fsm_Close(&ncp->ipv6cp.fsm); | 537 if (ncp->ipv6cp.fsm.state > ST_CLOSED || 538 ncp->ipv6cp.fsm.state == ST_STARTING) 539 fsm_Close(&ncp->ipv6cp.fsm); |
552#endif 553} 554 555void 556ncp2initial(struct ncp *ncp) 557{ 558 fsm2initial(&ncp->ipcp.fsm); 559#ifndef NOINET6 | 540#endif 541} 542 543void 544ncp2initial(struct ncp *ncp) 545{ 546 fsm2initial(&ncp->ipcp.fsm); 547#ifndef NOINET6 |
560 if (probe.ipv6_available) 561 fsm2initial(&ncp->ipv6cp.fsm); | 548 fsm2initial(&ncp->ipv6cp.fsm); |
562#endif 563} | 549#endif 550} |