ncp.c (102500) | ncp.c (134789) |
---|---|
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 102500 2002-08-27 20:11:58Z brian $ | 26 * $FreeBSD: head/usr.sbin/ppp/ncp.c 134789 2004-09-05 01:46:52Z 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 <sys/socket.h> 34#include <net/route.h> --- 49 unchanged lines hidden (view full) --- 84 22, /* ssh */ 85 23, /* telnet */ 86 513, /* login */ 87 514, /* shell */ 88 543, /* klogin */ 89 544 /* kshell */ 90}; 91 | 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 <sys/socket.h> 34#include <net/route.h> --- 49 unchanged lines hidden (view full) --- 84 22, /* ssh */ 85 23, /* telnet */ 86 513, /* login */ 87 514, /* shell */ 88 543, /* klogin */ 89 544 /* kshell */ 90}; 91 |
92static u_short default_urgent_udp_ports[] = { }; 93 | |
94#define NDEFTCPPORTS \ 95 (sizeof default_urgent_tcp_ports / sizeof default_urgent_tcp_ports[0]) | 92#define NDEFTCPPORTS \ 93 (sizeof default_urgent_tcp_ports / sizeof default_urgent_tcp_ports[0]) |
96#define NDEFUDPPORTS \ 97 (sizeof default_urgent_udp_ports / sizeof default_urgent_udp_ports[0]) | |
98 99void 100ncp_Init(struct ncp *ncp, struct bundle *bundle) 101{ 102 ncp->afq = AF_INET; 103 ncp->route = NULL; 104 105 ncp->cfg.urgent.tcp.nports = ncp->cfg.urgent.tcp.maxports = NDEFTCPPORTS; 106 ncp->cfg.urgent.tcp.port = (u_short *)malloc(NDEFTCPPORTS * sizeof(u_short)); 107 memcpy(ncp->cfg.urgent.tcp.port, default_urgent_tcp_ports, 108 NDEFTCPPORTS * sizeof(u_short)); 109 ncp->cfg.urgent.tos = 1; 110 | 94 95void 96ncp_Init(struct ncp *ncp, struct bundle *bundle) 97{ 98 ncp->afq = AF_INET; 99 ncp->route = NULL; 100 101 ncp->cfg.urgent.tcp.nports = ncp->cfg.urgent.tcp.maxports = NDEFTCPPORTS; 102 ncp->cfg.urgent.tcp.port = (u_short *)malloc(NDEFTCPPORTS * sizeof(u_short)); 103 memcpy(ncp->cfg.urgent.tcp.port, default_urgent_tcp_ports, 104 NDEFTCPPORTS * sizeof(u_short)); 105 ncp->cfg.urgent.tos = 1; 106 |
111 ncp->cfg.urgent.udp.nports = ncp->cfg.urgent.udp.maxports = NDEFUDPPORTS; 112 ncp->cfg.urgent.udp.port = (u_short *)malloc(NDEFUDPPORTS * sizeof(u_short)); 113 memcpy(ncp->cfg.urgent.udp.port, default_urgent_udp_ports, 114 NDEFUDPPORTS * sizeof(u_short)); | 107 ncp->cfg.urgent.udp.nports = ncp->cfg.urgent.udp.maxports = 0; 108 ncp->cfg.urgent.udp.port = NULL; |
115 | 109 |
116 | |
117 mp_Init(&ncp->mp, bundle); 118 119 /* Send over the first physical link by default */ 120 ipcp_Init(&ncp->ipcp, bundle, &bundle->links->physical->link, 121 &bundle->fsm); 122#ifndef NOINET6 123 ipv6cp_Init(&ncp->ipv6cp, bundle, &bundle->links->physical->link, 124 &bundle->fsm); --- 75 unchanged lines hidden (view full) --- 200#endif 201} 202 203/* 204 * Enqueue a packet of the given address family. Nothing will make it 205 * down to the physical link level 'till ncp_FillPhysicalQueues() is used. 206 */ 207void | 110 mp_Init(&ncp->mp, bundle); 111 112 /* Send over the first physical link by default */ 113 ipcp_Init(&ncp->ipcp, bundle, &bundle->links->physical->link, 114 &bundle->fsm); 115#ifndef NOINET6 116 ipv6cp_Init(&ncp->ipv6cp, bundle, &bundle->links->physical->link, 117 &bundle->fsm); --- 75 unchanged lines hidden (view full) --- 193#endif 194} 195 196/* 197 * Enqueue a packet of the given address family. Nothing will make it 198 * down to the physical link level 'till ncp_FillPhysicalQueues() is used. 199 */ 200void |
208ncp_Enqueue(struct ncp *ncp, int af, int pri, char *ptr, int count) | 201ncp_Enqueue(struct ncp *ncp, int af, unsigned pri, char *ptr, int count) |
209{ 210#ifndef NOINET6 211 struct ipv6cp *ipv6cp = &ncp->ipv6cp; 212#endif 213 struct ipcp *ipcp = &ncp->ipcp; 214 struct mbuf *bp; 215 216 /* 217 * We allocate an extra 6 bytes, four at the front and two at the end. 218 * This is an optimisation so that we need to do less work in 219 * m_prepend() in acf_LayerPush() and proto_LayerPush() and 220 * appending in hdlc_LayerPush(). 221 */ 222 223 switch (af) { 224 case AF_INET: | 202{ 203#ifndef NOINET6 204 struct ipv6cp *ipv6cp = &ncp->ipv6cp; 205#endif 206 struct ipcp *ipcp = &ncp->ipcp; 207 struct mbuf *bp; 208 209 /* 210 * We allocate an extra 6 bytes, four at the front and two at the end. 211 * This is an optimisation so that we need to do less work in 212 * m_prepend() in acf_LayerPush() and proto_LayerPush() and 213 * appending in hdlc_LayerPush(). 214 */ 215 216 switch (af) { 217 case AF_INET: |
225 if (pri < 0 || pri >= IPCP_QUEUES(ipcp)) { 226 log_Printf(LogERROR, "Can't store in ip queue %d\n", pri); | 218 if (pri >= IPCP_QUEUES(ipcp)) { 219 log_Printf(LogERROR, "Can't store in ip queue %u\n", pri); |
227 break; 228 } 229 230 bp = m_get(count + 6, MB_IPOUT); 231 bp->m_offset += 4; 232 bp->m_len -= 6; 233 memcpy(MBUF_CTOP(bp), ptr, count); 234 m_enqueue(ipcp->Queue + pri, bp); 235 break; 236 237#ifndef NOINET6 238 case AF_INET6: | 220 break; 221 } 222 223 bp = m_get(count + 6, MB_IPOUT); 224 bp->m_offset += 4; 225 bp->m_len -= 6; 226 memcpy(MBUF_CTOP(bp), ptr, count); 227 m_enqueue(ipcp->Queue + pri, bp); 228 break; 229 230#ifndef NOINET6 231 case AF_INET6: |
239 if (pri < 0 || pri >= IPV6CP_QUEUES(ipcp)) { 240 log_Printf(LogERROR, "Can't store in ipv6 queue %d\n", pri); | 232 if (pri >= IPV6CP_QUEUES(ipcp)) { 233 log_Printf(LogERROR, "Can't store in ipv6 queue %u\n", pri); |
241 break; 242 } 243 244 bp = m_get(count + 6, MB_IPOUT); 245 bp->m_offset += 4; 246 bp->m_len -= 6; 247 memcpy(MBUF_CTOP(bp), ptr, count); 248 m_enqueue(ipv6cp->Queue + pri, bp); --- 79 unchanged lines hidden (view full) --- 328 return total + ncp_QueueLen(&bundle->ncp); 329} 330 331/* 332 * Push a packet into the given link. ``af'' is used as a persistent record 333 * of what is to be pushed next, coming either from mp->out or ncp->afq. 334 */ 335int | 234 break; 235 } 236 237 bp = m_get(count + 6, MB_IPOUT); 238 bp->m_offset += 4; 239 bp->m_len -= 6; 240 memcpy(MBUF_CTOP(bp), ptr, count); 241 m_enqueue(ipv6cp->Queue + pri, bp); --- 79 unchanged lines hidden (view full) --- 321 return total + ncp_QueueLen(&bundle->ncp); 322} 323 324/* 325 * Push a packet into the given link. ``af'' is used as a persistent record 326 * of what is to be pushed next, coming either from mp->out or ncp->afq. 327 */ 328int |
336ncp_PushPacket(struct ncp *ncp, int *af, struct link *l) | 329ncp_PushPacket(struct ncp *ncp __unused, int *af, struct link *l) |
337{ 338 struct bundle *bundle = l->lcp.fsm.bundle; 339 int res; 340 341#ifndef NOINET6 342 if (*af == AF_INET) { 343 if ((res = ipcp_PushPacket(&bundle->ncp.ipcp, l))) 344 *af = AF_INET6; --- 10 unchanged lines hidden (view full) --- 355#endif 356 357 return res; 358} 359 360int 361ncp_IsUrgentPort(struct port_range *range, u_short src, u_short dst) 362{ | 330{ 331 struct bundle *bundle = l->lcp.fsm.bundle; 332 int res; 333 334#ifndef NOINET6 335 if (*af == AF_INET) { 336 if ((res = ipcp_PushPacket(&bundle->ncp.ipcp, l))) 337 *af = AF_INET6; --- 10 unchanged lines hidden (view full) --- 348#endif 349 350 return res; 351} 352 353int 354ncp_IsUrgentPort(struct port_range *range, u_short src, u_short dst) 355{ |
363 int f; | 356 unsigned f; |
364 365 for (f = 0; f < range->nports; f++) 366 if (range->port[f] == src || range->port[f] == dst) 367 return 1; 368 369 return 0; 370} 371 372void 373ncp_AddUrgentPort(struct port_range *range, u_short port) 374{ 375 u_short *newport; | 357 358 for (f = 0; f < range->nports; f++) 359 if (range->port[f] == src || range->port[f] == dst) 360 return 1; 361 362 return 0; 363} 364 365void 366ncp_AddUrgentPort(struct port_range *range, u_short port) 367{ 368 u_short *newport; |
376 int p; | 369 unsigned p; |
377 378 if (range->nports == range->maxports) { 379 range->maxports += 10; 380 newport = (u_short *)realloc(range->port, 381 range->maxports * sizeof(u_short)); 382 if (newport == NULL) { 383 log_Printf(LogERROR, "ncp_AddUrgentPort: realloc: %s\n", 384 strerror(errno)); --- 17 unchanged lines hidden (view full) --- 402 403 if (p == range->nports) 404 range->port[range->nports++] = port; 405} 406 407void 408ncp_RemoveUrgentPort(struct port_range *range, u_short port) 409{ | 370 371 if (range->nports == range->maxports) { 372 range->maxports += 10; 373 newport = (u_short *)realloc(range->port, 374 range->maxports * sizeof(u_short)); 375 if (newport == NULL) { 376 log_Printf(LogERROR, "ncp_AddUrgentPort: realloc: %s\n", 377 strerror(errno)); --- 17 unchanged lines hidden (view full) --- 395 396 if (p == range->nports) 397 range->port[range->nports++] = port; 398} 399 400void 401ncp_RemoveUrgentPort(struct port_range *range, u_short port) 402{ |
410 int p; | 403 unsigned p; |
411 412 for (p = 0; p < range->nports; p++) 413 if (range->port[p] == port) { | 404 405 for (p = 0; p < range->nports; p++) 406 if (range->port[p] == port) { |
414 if (p != range->nports - 1) | 407 if (p + 1 != range->nports) |
415 memmove(range->port + p, range->port + p + 1, 416 (range->nports - p - 1) * sizeof(u_short)); 417 range->nports--; 418 return; 419 } 420 421 if (p == range->nports) 422 log_Printf(LogWARN, "%u: Port not set to urgent\n", port); --- 4 unchanged lines hidden (view full) --- 427{ 428 range->nports = 0; 429} 430 431int 432ncp_Show(struct cmdargs const *arg) 433{ 434 struct ncp *ncp = &arg->bundle->ncp; | 408 memmove(range->port + p, range->port + p + 1, 409 (range->nports - p - 1) * sizeof(u_short)); 410 range->nports--; 411 return; 412 } 413 414 if (p == range->nports) 415 log_Printf(LogWARN, "%u: Port not set to urgent\n", port); --- 4 unchanged lines hidden (view full) --- 420{ 421 range->nports = 0; 422} 423 424int 425ncp_Show(struct cmdargs const *arg) 426{ 427 struct ncp *ncp = &arg->bundle->ncp; |
435 int p; | 428 unsigned p; |
436 437#ifndef NOINET6 438 prompt_Printf(arg->prompt, "Next queued AF: %s\n", 439 ncp->afq == AF_INET6 ? "inet6" : "inet"); 440#endif 441 442 if (ncp->route) { 443 prompt_Printf(arg->prompt, "\n"); --- 94 unchanged lines hidden --- | 429 430#ifndef NOINET6 431 prompt_Printf(arg->prompt, "Next queued AF: %s\n", 432 ncp->afq == AF_INET6 ? "inet6" : "inet"); 433#endif 434 435 if (ncp->route) { 436 prompt_Printf(arg->prompt, "\n"); --- 94 unchanged lines hidden --- |