[85a0f07] | 1 | /* |
---|
| 2 | * if_ppp.c - Point-to-Point Protocol (PPP) Asynchronous driver. |
---|
[41ff670] | 3 | */ |
---|
| 4 | |
---|
| 5 | /*- |
---|
[85a0f07] | 6 | * Copyright (c) 1989 Carnegie Mellon University. |
---|
| 7 | * All rights reserved. |
---|
| 8 | * |
---|
| 9 | * Redistribution and use in source and binary forms are permitted |
---|
| 10 | * provided that the above copyright notice and this paragraph are |
---|
| 11 | * duplicated in all such forms and that any documentation, |
---|
| 12 | * advertising materials, and other materials related to such |
---|
| 13 | * distribution and use acknowledge that the software was developed |
---|
| 14 | * by Carnegie Mellon University. The name of the |
---|
| 15 | * University may not be used to endorse or promote products derived |
---|
| 16 | * from this software without specific prior written permission. |
---|
| 17 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
---|
| 19 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
---|
| 20 | * |
---|
| 21 | * Drew D. Perkins |
---|
| 22 | * Carnegie Mellon University |
---|
| 23 | * 4910 Forbes Ave. |
---|
| 24 | * Pittsburgh, PA 15213 |
---|
| 25 | * (412) 268-8576 |
---|
| 26 | * ddp@andrew.cmu.edu |
---|
| 27 | * |
---|
| 28 | * Based on: |
---|
| 29 | * @(#)if_sl.c 7.6.1.2 (Berkeley) 2/15/89 |
---|
| 30 | * |
---|
| 31 | * Copyright (c) 1987 Regents of the University of California. |
---|
| 32 | * All rights reserved. |
---|
| 33 | * |
---|
| 34 | * Redistribution and use in source and binary forms are permitted |
---|
| 35 | * provided that the above copyright notice and this paragraph are |
---|
| 36 | * duplicated in all such forms and that any documentation, |
---|
| 37 | * advertising materials, and other materials related to such |
---|
| 38 | * distribution and use acknowledge that the software was developed |
---|
| 39 | * by the University of California, Berkeley. The name of the |
---|
| 40 | * University may not be used to endorse or promote products derived |
---|
| 41 | * from this software without specific prior written permission. |
---|
| 42 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
---|
| 43 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
---|
| 44 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
---|
| 45 | * |
---|
| 46 | * Serial Line interface |
---|
| 47 | * |
---|
| 48 | * Rick Adams |
---|
| 49 | * Center for Seismic Studies |
---|
| 50 | * 1300 N 17th Street, Suite 1450 |
---|
| 51 | * Arlington, Virginia 22209 |
---|
| 52 | * (703)276-7900 |
---|
| 53 | * rick@seismo.ARPA |
---|
| 54 | * seismo!rick |
---|
| 55 | * |
---|
| 56 | * Pounded on heavily by Chris Torek (chris@mimsy.umd.edu, umcp-cs!chris). |
---|
| 57 | * Converted to 4.3BSD Beta by Chris Torek. |
---|
| 58 | * Other changes made at Berkeley, based in part on code by Kirk Smith. |
---|
| 59 | * |
---|
| 60 | * Converted to 4.3BSD+ 386BSD by Brad Parker (brad@cayman.com) |
---|
| 61 | * Added VJ tcp header compression; more unified ioctls |
---|
| 62 | * |
---|
| 63 | * Extensively modified by Paul Mackerras (paulus@cs.anu.edu.au). |
---|
| 64 | * Cleaned up a lot of the mbuf-related code to fix bugs that |
---|
| 65 | * caused system crashes and packet corruption. Changed pppstart |
---|
| 66 | * so that it doesn't just give up with a collision if the whole |
---|
| 67 | * packet doesn't fit in the output ring buffer. |
---|
| 68 | * |
---|
| 69 | * Added priority queueing for interactive IP packets, following |
---|
| 70 | * the model of if_sl.c, plus hooks for bpf. |
---|
| 71 | * Paul Mackerras (paulus@cs.anu.edu.au). |
---|
| 72 | */ |
---|
| 73 | |
---|
[393f75f] | 74 | /* $FreeBSD: src/sys/net/if_ppp.c,v 1.109 2005/10/12 19:52:16 thompsa Exp $ */ |
---|
[85a0f07] | 75 | /* from if_sl.c,v 1.11 84/10/04 12:54:47 rick Exp */ |
---|
| 76 | /* from NetBSD: if_ppp.c,v 1.15.2.2 1994/07/28 05:17:58 cgd Exp */ |
---|
| 77 | |
---|
[b25b88e7] | 78 | #ifdef HAVE_CONFIG_H |
---|
| 79 | #include "config.h" |
---|
| 80 | #endif |
---|
| 81 | |
---|
[393f75f] | 82 | #include "opt_inet.h" |
---|
| 83 | #include "opt_ipx.h" |
---|
| 84 | #include "opt_mac.h" |
---|
| 85 | #include "opt_ppp.h" |
---|
| 86 | |
---|
[85a0f07] | 87 | #if NPPP > 0 |
---|
| 88 | |
---|
[0286b9f] | 89 | #include <termios.h> |
---|
| 90 | #include <rtems/termiostypes.h> |
---|
| 91 | #include <rtems/rtems_bsdnet.h> |
---|
[85a0f07] | 92 | #include <sys/param.h> |
---|
| 93 | #include <sys/systm.h> |
---|
| 94 | #include <sys/proc.h> |
---|
| 95 | #include <sys/mbuf.h> |
---|
| 96 | #include <sys/socket.h> |
---|
| 97 | #include <sys/ioctl.h> |
---|
| 98 | #include <sys/kernel.h> |
---|
| 99 | #include <sys/time.h> |
---|
| 100 | #include <sys/malloc.h> |
---|
| 101 | |
---|
| 102 | #include <net/if.h> |
---|
| 103 | #include <net/if_types.h> |
---|
| 104 | #include <net/netisr.h> |
---|
| 105 | #include <net/route.h> |
---|
| 106 | #ifdef PPP_FILTER |
---|
| 107 | #include <net/bpf.h> |
---|
| 108 | #endif |
---|
| 109 | |
---|
[0286b9f] | 110 | #if INET |
---|
[85a0f07] | 111 | #include <netinet/in.h> |
---|
| 112 | #include <netinet/in_systm.h> |
---|
| 113 | #include <netinet/in_var.h> |
---|
| 114 | #include <netinet/ip.h> |
---|
| 115 | #endif |
---|
| 116 | |
---|
| 117 | #if NBPFILTER > 0 |
---|
| 118 | #include <net/bpf.h> |
---|
| 119 | #endif |
---|
| 120 | |
---|
| 121 | #ifdef VJC |
---|
[47a8868] | 122 | #include <net/slcompress.h> |
---|
[85a0f07] | 123 | #endif |
---|
| 124 | |
---|
| 125 | #include <net/ppp_defs.h> |
---|
| 126 | #include <net/if_ppp.h> |
---|
| 127 | #include <net/if_pppvar.h> |
---|
| 128 | #include <machine/cpu.h> |
---|
| 129 | |
---|
| 130 | #define splsoftnet splnet |
---|
| 131 | |
---|
| 132 | #ifdef PPP_COMPRESS |
---|
| 133 | #define PACKETPTR struct mbuf * |
---|
| 134 | #include <net/ppp-comp.h> |
---|
| 135 | #endif |
---|
[0286b9f] | 136 | |
---|
[a184e5e] | 137 | static struct ppp_softc ppp_softc[NPPP]; |
---|
| 138 | |
---|
[a009d94] | 139 | static int pppsioctl(struct ifnet *ifp, ioctl_command_t cmd, caddr_t data); |
---|
[41ff670] | 140 | static void ppp_requeue(struct ppp_softc *); |
---|
[78d6a50] | 141 | #ifdef PPP_COMPRESS |
---|
[41ff670] | 142 | static void ppp_ccp(struct ppp_softc *, struct mbuf *m, int rcvd); |
---|
| 143 | static void ppp_ccp_closed(struct ppp_softc *); |
---|
[78d6a50] | 144 | #endif |
---|
[41ff670] | 145 | static struct mbuf *ppp_inproc(struct ppp_softc *, struct mbuf *); |
---|
| 146 | static void pppdumpm(struct mbuf *m0); |
---|
[85a0f07] | 147 | |
---|
| 148 | /* |
---|
| 149 | * Some useful mbuf macros not in mbuf.h. |
---|
| 150 | */ |
---|
| 151 | #define M_IS_CLUSTER(m) ((m)->m_flags & M_EXT) |
---|
| 152 | |
---|
| 153 | #define M_DATASTART(m) \ |
---|
| 154 | (M_IS_CLUSTER(m) ? (m)->m_ext.ext_buf : \ |
---|
| 155 | (m)->m_flags & M_PKTHDR ? (m)->m_pktdat : (m)->m_dat) |
---|
| 156 | |
---|
| 157 | #define M_DATASIZE(m) \ |
---|
| 158 | (M_IS_CLUSTER(m) ? (m)->m_ext.ext_size : \ |
---|
| 159 | (m)->m_flags & M_PKTHDR ? MHLEN: MLEN) |
---|
| 160 | |
---|
| 161 | /* |
---|
| 162 | * We steal two bits in the mbuf m_flags, to mark high-priority packets |
---|
| 163 | * for output, and received packets following lost/corrupted packets. |
---|
| 164 | */ |
---|
| 165 | #define M_HIGHPRI 0x2000 /* output packet for sc_fastq */ |
---|
| 166 | #define M_ERRMARK 0x4000 /* steal a bit in mbuf m_flags */ |
---|
| 167 | |
---|
| 168 | |
---|
| 169 | #ifdef PPP_COMPRESS |
---|
| 170 | /* |
---|
| 171 | * List of compressors we know about. |
---|
| 172 | * We leave some space so maybe we can modload compressors. |
---|
| 173 | */ |
---|
| 174 | |
---|
| 175 | extern struct compressor ppp_bsd_compress; |
---|
| 176 | extern struct compressor ppp_deflate, ppp_deflate_draft; |
---|
| 177 | |
---|
| 178 | struct compressor *ppp_compressors[8] = { |
---|
| 179 | #if DO_BSD_COMPRESS |
---|
| 180 | &ppp_bsd_compress, |
---|
| 181 | #endif |
---|
| 182 | #if DO_DEFLATE |
---|
| 183 | &ppp_deflate, |
---|
| 184 | &ppp_deflate_draft, |
---|
| 185 | #endif |
---|
| 186 | NULL |
---|
| 187 | }; |
---|
| 188 | #endif /* PPP_COMPRESS */ |
---|
| 189 | |
---|
[0286b9f] | 190 | extern struct ifqueue ipintrq; |
---|
| 191 | static struct timeval ppp_time; |
---|
| 192 | |
---|
[36799d4] | 193 | #ifndef __rtems__ |
---|
[0286b9f] | 194 | TEXT_SET(pseudo_set, ppp_rxdaemon); |
---|
[36799d4] | 195 | #endif |
---|
[0286b9f] | 196 | |
---|
| 197 | static rtems_task ppp_rxdaemon(rtems_task_argument arg) |
---|
| 198 | { |
---|
| 199 | rtems_event_set events; |
---|
| 200 | rtems_interrupt_level level; |
---|
| 201 | struct ppp_softc *sc = (struct ppp_softc *)arg; |
---|
| 202 | struct mbuf *mp = (struct mbuf *)0; |
---|
| 203 | struct mbuf *m; |
---|
| 204 | |
---|
| 205 | /* enter processing loop */ |
---|
| 206 | while ( 1 ) { |
---|
| 207 | /* wait for event */ |
---|
| 208 | rtems_event_receive(RX_PACKET|RX_MBUF|RX_EMPTY,RTEMS_WAIT|RTEMS_EVENT_ANY,RTEMS_NO_TIMEOUT,&events); |
---|
| 209 | if ( events & RX_EMPTY ) { |
---|
| 210 | printf("RX: QUEUE is EMPTY\n"); |
---|
| 211 | events &= ~RX_EMPTY; |
---|
| 212 | } |
---|
| 213 | |
---|
| 214 | if ( events ) { |
---|
| 215 | /* get the network semaphore */ |
---|
| 216 | rtems_bsdnet_semaphore_obtain(); |
---|
| 217 | |
---|
| 218 | /* check to see if new packet was received */ |
---|
| 219 | if ( events & RX_PACKET ) { |
---|
| 220 | /* get received packet mbuf chain */ |
---|
| 221 | rtems_interrupt_disable(level); |
---|
| 222 | IF_DEQUEUE(&sc->sc_rawq, m); |
---|
| 223 | rtems_interrupt_enable(level); |
---|
| 224 | |
---|
| 225 | /* ensure packet was retrieved */ |
---|
| 226 | if ( m != (struct mbuf *)0 ) { |
---|
| 227 | /* process the received packet */ |
---|
| 228 | mp = ppp_inproc(sc, m); |
---|
| 229 | } |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | /* allocate a new mbuf to replace one */ |
---|
| 233 | if ( mp == NULL ) { |
---|
| 234 | pppallocmbuf(sc, &mp); |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | /* place mbuf on freeq */ |
---|
| 238 | rtems_interrupt_disable(level); |
---|
| 239 | IF_ENQUEUE(&sc->sc_freeq, mp); |
---|
| 240 | rtems_interrupt_enable(level); |
---|
| 241 | mp = (struct mbuf *)0; |
---|
| 242 | |
---|
| 243 | /* release the network semaphore */ |
---|
| 244 | rtems_bsdnet_semaphore_release(); |
---|
| 245 | |
---|
| 246 | /* check to see if queue is empty */ |
---|
| 247 | if ( sc->sc_rawq.ifq_head ) { |
---|
| 248 | /* queue is not empty - post another event */ |
---|
| 249 | rtems_event_send(sc->sc_rxtask, RX_PACKET); |
---|
| 250 | } |
---|
| 251 | } |
---|
| 252 | } |
---|
| 253 | } |
---|
| 254 | |
---|
| 255 | static rtems_task ppp_txdaemon(rtems_task_argument arg) |
---|
| 256 | { |
---|
| 257 | rtems_event_set events; |
---|
| 258 | int iprocess = (int )0; |
---|
| 259 | struct ppp_softc *sc = (struct ppp_softc *)arg; |
---|
| 260 | struct mbuf *mp; |
---|
| 261 | struct mbuf *mf; |
---|
| 262 | struct mbuf *m; |
---|
| 263 | struct rtems_termios_tty *tp; |
---|
[c07aa0c5] | 264 | |
---|
| 265 | int frag; |
---|
[0286b9f] | 266 | |
---|
| 267 | /* enter processing loop */ |
---|
| 268 | while ( 1 ) { |
---|
| 269 | /* wait for event */ |
---|
| 270 | rtems_event_receive(TX_PACKET|TX_TRANSMIT,RTEMS_WAIT|RTEMS_EVENT_ANY,RTEMS_NO_TIMEOUT,&events); |
---|
| 271 | if ( events & TX_TRANSMIT ) { |
---|
| 272 | /* received event from interrupt handler - free current mbuf */ |
---|
| 273 | rtems_bsdnet_semaphore_obtain(); |
---|
[c07aa0c5] | 274 | |
---|
[0286b9f] | 275 | m_freem(sc->sc_outm); |
---|
[c07aa0c5] | 276 | |
---|
[0286b9f] | 277 | rtems_bsdnet_semaphore_release(); |
---|
| 278 | |
---|
| 279 | /* chain is done - clear the values */ |
---|
| 280 | sc->sc_outm = (struct mbuf *)0; |
---|
| 281 | sc->sc_outmc = (struct mbuf *)0; |
---|
| 282 | |
---|
| 283 | /* now set flag to fake receive of TX_PACKET event */ |
---|
| 284 | /* this will check to see if we have any pending packets */ |
---|
[9532e55] | 285 | events |= TX_PACKET; |
---|
[0286b9f] | 286 | } |
---|
| 287 | |
---|
| 288 | /* received event from pppasyncstart */ |
---|
| 289 | if ( events & TX_PACKET ) { |
---|
| 290 | /* ensure we are not busy */ |
---|
| 291 | if ( sc->sc_outm == (struct mbuf *)0 ) { |
---|
| 292 | /* try dequeuing a packet */ |
---|
| 293 | sc->sc_outm = ppp_dequeue(sc); |
---|
| 294 | if ( sc->sc_outm == NULL ) { |
---|
| 295 | /* clear output flags */ |
---|
| 296 | sc->sc_outflag = 0; |
---|
| 297 | sc->sc_if.if_flags &= ~IFF_OACTIVE; |
---|
| 298 | } |
---|
| 299 | else { |
---|
| 300 | /* set flag to start process */ |
---|
| 301 | iprocess = 1; |
---|
| 302 | sc->sc_outflag = SC_TX_BUSY; |
---|
| 303 | sc->sc_if.if_flags |= IFF_OACTIVE; |
---|
| 304 | } |
---|
| 305 | } |
---|
| 306 | } |
---|
| 307 | |
---|
| 308 | /* check to see if there is any processing required */ |
---|
| 309 | if ( iprocess ) { |
---|
| 310 | /* clear process flag */ |
---|
| 311 | iprocess = (int)0; |
---|
[c07aa0c5] | 312 | frag=0; |
---|
[0286b9f] | 313 | |
---|
| 314 | /* initialize output values */ |
---|
| 315 | sc->sc_outfcs = PPP_INITFCS; |
---|
| 316 | sc->sc_outbuf = (u_char *)0; |
---|
| 317 | sc->sc_outlen = (short )0; |
---|
| 318 | sc->sc_outoff = (short )0; |
---|
| 319 | sc->sc_outfcslen = (short )0; |
---|
[1f788a3] | 320 | |
---|
[c07aa0c5] | 321 | /* printf("Start Transmit Packet..\n"); */ |
---|
[0286b9f] | 322 | |
---|
| 323 | /* loop over all mbufs in chain */ |
---|
| 324 | mf = NULL; |
---|
| 325 | mp = NULL; |
---|
| 326 | m = sc->sc_outm; |
---|
[c07aa0c5] | 327 | |
---|
| 328 | sc->sc_outmc = m; |
---|
| 329 | sc->sc_outlen = m->m_len; |
---|
| 330 | sc->sc_outbuf = mtod(m, u_char *); |
---|
| 331 | |
---|
[0286b9f] | 332 | while (( m != (struct mbuf *)0 ) && ( m->m_len > 0 )) { |
---|
[c07aa0c5] | 333 | frag++; |
---|
[0286b9f] | 334 | |
---|
| 335 | /* update the FCS value and then check next packet length */ |
---|
[c07aa0c5] | 336 | if(m->m_len){ |
---|
| 337 | sc->sc_outfcs = pppfcs(sc->sc_outfcs, mtod(m, u_char *), m->m_len); |
---|
| 338 | } |
---|
[1f788a3] | 339 | |
---|
| 340 | if(( m->m_next != NULL ) && ( m->m_next->m_len == 0 )) { |
---|
| 341 | if(mf){ |
---|
| 342 | printf(" if_ppp.c : MBUF Error !!!!\n"); |
---|
| 343 | } |
---|
| 344 | else{ |
---|
[c07aa0c5] | 345 | mf = m->m_next; |
---|
[1f788a3] | 346 | m->m_next = NULL; |
---|
[c07aa0c5] | 347 | } |
---|
| 348 | } |
---|
[1f788a3] | 349 | |
---|
[c07aa0c5] | 350 | #ifdef LALL_X |
---|
[0286b9f] | 351 | /* check next packet to see if it is empty */ |
---|
| 352 | while (( m->m_next != NULL ) && ( m->m_next->m_len == 0 )) { |
---|
| 353 | /* next mbuf is zero length */ |
---|
| 354 | /* add empty mbuf to free chain */ |
---|
| 355 | if ( mp == NULL ) { |
---|
| 356 | /* item is head of free list */ |
---|
| 357 | mf = m->m_next; |
---|
| 358 | mp = mf; |
---|
| 359 | } |
---|
| 360 | else { |
---|
| 361 | /* add item to end of the free list */ |
---|
| 362 | mp->m_next = m->m_next; |
---|
| 363 | mp = m->m_next; |
---|
| 364 | } |
---|
| 365 | |
---|
| 366 | /* remove empty item from process chain */ |
---|
| 367 | m->m_next = m->m_next->m_next; |
---|
| 368 | mp->m_next = NULL; |
---|
| 369 | } |
---|
[c07aa0c5] | 370 | #endif |
---|
[0286b9f] | 371 | /* move to next packet */ |
---|
| 372 | m = m->m_next; |
---|
| 373 | } |
---|
| 374 | |
---|
| 375 | /* ensure there is data to be sent out */ |
---|
| 376 | tp = (struct rtems_termios_tty *)sc->sc_devp; |
---|
| 377 | if (( tp != NULL ) && ( sc->sc_outmc != (struct mbuf *)0 )) { |
---|
| 378 | /* place FCS value into buffer */ |
---|
| 379 | sc->sc_outfcsbuf[sc->sc_outfcslen++] = ~sc->sc_outfcs & 0xff; |
---|
| 380 | sc->sc_outfcsbuf[sc->sc_outfcslen++] = (~sc->sc_outfcs >> 8) & 0xff; |
---|
| 381 | microtime(&sc->sc_if.if_lastchange); |
---|
| 382 | |
---|
| 383 | /* write out frame byte to start the transmission */ |
---|
[c07aa0c5] | 384 | sc->sc_outchar = (u_char)PPP_FLAG; |
---|
[33739be] | 385 | (*tp->handler.write)(tp, (char *)&sc->sc_outchar, 1); |
---|
[0286b9f] | 386 | } |
---|
| 387 | |
---|
| 388 | /* check to see if we need to free some empty mbufs */ |
---|
| 389 | if ( mf != (struct mbuf *)0 ) { |
---|
| 390 | /* free empty mbufs */ |
---|
| 391 | rtems_bsdnet_semaphore_obtain(); |
---|
| 392 | m_freem(mf); |
---|
| 393 | rtems_bsdnet_semaphore_release(); |
---|
[1f788a3] | 394 | } |
---|
[0286b9f] | 395 | } |
---|
| 396 | } |
---|
| 397 | } |
---|
| 398 | |
---|
| 399 | static void ppp_init(struct ppp_softc *sc) |
---|
| 400 | { |
---|
| 401 | rtems_status_code status; |
---|
[d8dbdc0] | 402 | uint32_t priority = 100; |
---|
[0286b9f] | 403 | |
---|
| 404 | /* determine priority value */ |
---|
| 405 | if ( rtems_bsdnet_config.network_task_priority ) { |
---|
| 406 | priority = rtems_bsdnet_config.network_task_priority; |
---|
| 407 | } |
---|
| 408 | |
---|
| 409 | /* check to see if we need to start up daemons */ |
---|
| 410 | if ( sc->sc_rxtask == 0 ) { |
---|
| 411 | /* start rx daemon task */ |
---|
[fd55b7d] | 412 | status = rtems_task_create(rtems_build_name('R','x','P','0'+sc->sc_if.if_unit), priority, 2048, |
---|
[0286b9f] | 413 | RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0), |
---|
| 414 | RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL, |
---|
| 415 | &sc->sc_rxtask); |
---|
| 416 | if (status != RTEMS_SUCCESSFUL) { |
---|
| 417 | rtems_fatal_error_occurred(status); |
---|
| 418 | } |
---|
| 419 | else { |
---|
| 420 | status = rtems_task_start(sc->sc_rxtask, ppp_rxdaemon, (rtems_task_argument)sc); |
---|
| 421 | if (status != RTEMS_SUCCESSFUL) { |
---|
| 422 | rtems_fatal_error_occurred(status); |
---|
| 423 | } |
---|
| 424 | } |
---|
| 425 | |
---|
| 426 | /* start tx daemon task */ |
---|
[fd55b7d] | 427 | status = rtems_task_create(rtems_build_name('T','x','P','0'+sc->sc_if.if_unit), priority, 2048, |
---|
[0286b9f] | 428 | RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0), |
---|
| 429 | RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL, |
---|
| 430 | &sc->sc_txtask); |
---|
| 431 | if (status != RTEMS_SUCCESSFUL) { |
---|
| 432 | rtems_fatal_error_occurred(status); |
---|
| 433 | } |
---|
| 434 | else { |
---|
| 435 | status = rtems_task_start(sc->sc_txtask, ppp_txdaemon, (rtems_task_argument)sc); |
---|
| 436 | if (status != RTEMS_SUCCESSFUL) { |
---|
| 437 | rtems_fatal_error_occurred(status); |
---|
| 438 | } |
---|
| 439 | } |
---|
| 440 | } |
---|
| 441 | |
---|
| 442 | /* mark driver running and output inactive */ |
---|
[fd55b7d] | 443 | /* ilya: IFF_RUNNING flag will be marked after the IPCP goes up */ |
---|
| 444 | /* sc->sc_if.if_flags |= IFF_RUNNING; */ |
---|
[0286b9f] | 445 | } |
---|
[85a0f07] | 446 | |
---|
| 447 | /* |
---|
| 448 | * Called from boot code to establish ppp interfaces. |
---|
| 449 | */ |
---|
[0286b9f] | 450 | int rtems_ppp_driver_attach(struct rtems_bsdnet_ifconfig *config, int attaching) |
---|
[85a0f07] | 451 | { |
---|
[fd55b7d] | 452 | /* int i = (int)0; */ |
---|
[0286b9f] | 453 | struct ppp_softc *sc; |
---|
[fd55b7d] | 454 | char *name; |
---|
| 455 | int number; |
---|
| 456 | |
---|
| 457 | |
---|
| 458 | number = rtems_bsdnet_parse_driver_name (config, &name); |
---|
| 459 | |
---|
| 460 | if (!attaching || (number >= NPPP)) |
---|
| 461 | return 0; |
---|
| 462 | |
---|
| 463 | sc = &ppp_softc[number]; |
---|
| 464 | |
---|
| 465 | if (sc->sc_if.if_name != NULL) |
---|
| 466 | return 0; /* interface is already attached */ |
---|
| 467 | |
---|
| 468 | /* for (sc = ppp_softc; i < NPPP; sc++) { */ |
---|
| 469 | sc->sc_if.if_name = name /*"ppp"*/; |
---|
| 470 | sc->sc_if.if_unit = number /*i++*/; |
---|
[85a0f07] | 471 | sc->sc_if.if_mtu = PPP_MTU; |
---|
| 472 | sc->sc_if.if_flags = IFF_POINTOPOINT | IFF_MULTICAST; |
---|
| 473 | sc->sc_if.if_type = IFT_PPP; |
---|
| 474 | sc->sc_if.if_hdrlen = PPP_HDRLEN; |
---|
| 475 | sc->sc_if.if_ioctl = pppsioctl; |
---|
| 476 | sc->sc_if.if_output = pppoutput; |
---|
| 477 | sc->sc_if.if_snd.ifq_maxlen = IFQ_MAXLEN; |
---|
| 478 | sc->sc_inq.ifq_maxlen = IFQ_MAXLEN; |
---|
| 479 | sc->sc_fastq.ifq_maxlen = IFQ_MAXLEN; |
---|
| 480 | sc->sc_rawq.ifq_maxlen = IFQ_MAXLEN; |
---|
[0286b9f] | 481 | sc->sc_freeq.ifq_maxlen = NUM_MBUFQ; |
---|
| 482 | |
---|
| 483 | /* initialize and attach */ |
---|
| 484 | ppp_init(sc); |
---|
[85a0f07] | 485 | if_attach(&sc->sc_if); |
---|
| 486 | #if NBPFILTER > 0 |
---|
| 487 | bpfattach(&sc->sc_bpf, &sc->sc_if, DLT_PPP, PPP_HDRLEN); |
---|
| 488 | #endif |
---|
[fd55b7d] | 489 | /* } */ |
---|
[0286b9f] | 490 | |
---|
| 491 | return ( 1 ); |
---|
[85a0f07] | 492 | } |
---|
| 493 | |
---|
| 494 | /* |
---|
| 495 | * Allocate a ppp interface unit and initialize it. |
---|
| 496 | */ |
---|
| 497 | struct ppp_softc * |
---|
[42e10fa2] | 498 | pppalloc(pid_t pid) |
---|
[85a0f07] | 499 | { |
---|
| 500 | int nppp, i; |
---|
| 501 | struct ppp_softc *sc; |
---|
[0286b9f] | 502 | |
---|
[85a0f07] | 503 | for (nppp = 0, sc = ppp_softc; nppp < NPPP; nppp++, sc++) |
---|
| 504 | if (sc->sc_xfer == pid) { |
---|
| 505 | sc->sc_xfer = 0; |
---|
| 506 | return sc; |
---|
| 507 | } |
---|
| 508 | for (nppp = 0, sc = ppp_softc; nppp < NPPP; nppp++, sc++) |
---|
| 509 | if (sc->sc_devp == NULL) |
---|
| 510 | break; |
---|
| 511 | if (nppp >= NPPP) |
---|
| 512 | return NULL; |
---|
| 513 | |
---|
| 514 | sc->sc_flags = 0; |
---|
| 515 | sc->sc_mru = PPP_MRU; |
---|
| 516 | sc->sc_relinq = NULL; |
---|
| 517 | bzero((char *)&sc->sc_stats, sizeof(sc->sc_stats)); |
---|
| 518 | #ifdef VJC |
---|
[0286b9f] | 519 | MALLOC(sc->sc_comp, struct vjcompress *, sizeof(struct vjcompress), |
---|
| 520 | M_DEVBUF, M_NOWAIT); |
---|
[85a0f07] | 521 | if (sc->sc_comp) |
---|
[47a8868] | 522 | sl_compress_init(sc->sc_comp, -1); |
---|
[85a0f07] | 523 | #endif |
---|
| 524 | #ifdef PPP_COMPRESS |
---|
| 525 | sc->sc_xc_state = NULL; |
---|
| 526 | sc->sc_rc_state = NULL; |
---|
| 527 | #endif /* PPP_COMPRESS */ |
---|
| 528 | for (i = 0; i < NUM_NP; ++i) |
---|
| 529 | sc->sc_npmode[i] = NPMODE_ERROR; |
---|
| 530 | sc->sc_npqueue = NULL; |
---|
| 531 | sc->sc_npqtail = &sc->sc_npqueue; |
---|
[0286b9f] | 532 | microtime(&ppp_time); |
---|
[85a0f07] | 533 | sc->sc_last_sent = sc->sc_last_recv = ppp_time.tv_sec; |
---|
| 534 | |
---|
| 535 | return sc; |
---|
| 536 | } |
---|
| 537 | |
---|
| 538 | /* |
---|
| 539 | * Deallocate a ppp unit. Must be called at splsoftnet or higher. |
---|
| 540 | */ |
---|
| 541 | void |
---|
[42e10fa2] | 542 | pppdealloc(struct ppp_softc *sc) |
---|
[85a0f07] | 543 | { |
---|
| 544 | struct mbuf *m; |
---|
[0286b9f] | 545 | rtems_interrupt_level level; |
---|
[85a0f07] | 546 | |
---|
| 547 | if_down(&sc->sc_if); |
---|
| 548 | sc->sc_if.if_flags &= ~(IFF_UP|IFF_RUNNING); |
---|
| 549 | sc->sc_devp = NULL; |
---|
| 550 | sc->sc_xfer = 0; |
---|
[0286b9f] | 551 | |
---|
| 552 | rtems_interrupt_disable(level); |
---|
| 553 | if ( sc->sc_m != NULL ) { |
---|
| 554 | m_freem(sc->sc_m); |
---|
| 555 | sc->sc_m = (struct mbuf *)0; |
---|
| 556 | } |
---|
| 557 | if ( sc->sc_outm != NULL ) { |
---|
| 558 | m_freem(sc->sc_outm); |
---|
| 559 | sc->sc_outm = (struct mbuf *)0; |
---|
| 560 | sc->sc_outmc = (struct mbuf *)0; |
---|
| 561 | sc->sc_outflag = 0; |
---|
[85a0f07] | 562 | } |
---|
[0286b9f] | 563 | do { |
---|
| 564 | IF_DEQUEUE(&sc->sc_freeq, m); |
---|
| 565 | if (m != NULL) { |
---|
| 566 | m_freem(m); |
---|
| 567 | } |
---|
| 568 | } while ( m != NULL ); |
---|
| 569 | do { |
---|
| 570 | IF_DEQUEUE(&sc->sc_rawq, m); |
---|
| 571 | if (m != NULL) { |
---|
| 572 | m_freem(m); |
---|
| 573 | } |
---|
| 574 | } while ( m != NULL ); |
---|
| 575 | rtems_interrupt_enable(level); |
---|
| 576 | |
---|
[85a0f07] | 577 | for (;;) { |
---|
| 578 | IF_DEQUEUE(&sc->sc_inq, m); |
---|
| 579 | if (m == NULL) |
---|
| 580 | break; |
---|
| 581 | m_freem(m); |
---|
| 582 | } |
---|
| 583 | for (;;) { |
---|
| 584 | IF_DEQUEUE(&sc->sc_fastq, m); |
---|
| 585 | if (m == NULL) |
---|
| 586 | break; |
---|
| 587 | m_freem(m); |
---|
| 588 | } |
---|
| 589 | while ((m = sc->sc_npqueue) != NULL) { |
---|
| 590 | sc->sc_npqueue = m->m_nextpkt; |
---|
| 591 | m_freem(m); |
---|
| 592 | } |
---|
| 593 | #ifdef PPP_COMPRESS |
---|
| 594 | ppp_ccp_closed(sc); |
---|
| 595 | sc->sc_xc_state = NULL; |
---|
| 596 | sc->sc_rc_state = NULL; |
---|
| 597 | #endif /* PPP_COMPRESS */ |
---|
| 598 | #ifdef PPP_FILTER |
---|
| 599 | if (sc->sc_pass_filt.bf_insns != 0) { |
---|
[0286b9f] | 600 | FREE(sc->sc_pass_filt.bf_insns, M_DEVBUF); |
---|
[85a0f07] | 601 | sc->sc_pass_filt.bf_insns = 0; |
---|
| 602 | sc->sc_pass_filt.bf_len = 0; |
---|
| 603 | } |
---|
| 604 | if (sc->sc_active_filt.bf_insns != 0) { |
---|
[0286b9f] | 605 | FREE(sc->sc_active_filt.bf_insns, M_DEVBUF); |
---|
[85a0f07] | 606 | sc->sc_active_filt.bf_insns = 0; |
---|
| 607 | sc->sc_active_filt.bf_len = 0; |
---|
| 608 | } |
---|
| 609 | #endif /* PPP_FILTER */ |
---|
| 610 | #ifdef VJC |
---|
| 611 | if (sc->sc_comp != 0) { |
---|
[0286b9f] | 612 | FREE(sc->sc_comp, M_DEVBUF); |
---|
[85a0f07] | 613 | sc->sc_comp = 0; |
---|
| 614 | } |
---|
| 615 | #endif |
---|
| 616 | } |
---|
| 617 | |
---|
| 618 | /* |
---|
| 619 | * Ioctl routine for generic ppp devices. |
---|
| 620 | */ |
---|
| 621 | int |
---|
[42e10fa2] | 622 | pppioctl(struct ppp_softc *sc, ioctl_command_t cmd, caddr_t data, |
---|
| 623 | int flag, struct proc *p) |
---|
[85a0f07] | 624 | { |
---|
[0286b9f] | 625 | int s, flags, mru, npx, taskid; |
---|
[85a0f07] | 626 | struct npioctl *npi; |
---|
| 627 | time_t t; |
---|
| 628 | #ifdef PPP_FILTER |
---|
[78d6a50] | 629 | int error; |
---|
[85a0f07] | 630 | struct bpf_program *bp, *nbp; |
---|
| 631 | struct bpf_insn *newcode, *oldcode; |
---|
| 632 | int newcodelen; |
---|
| 633 | #endif /* PPP_FILTER */ |
---|
| 634 | #ifdef PPP_COMPRESS |
---|
[78d6a50] | 635 | int nb; |
---|
| 636 | struct ppp_option_data *odp; |
---|
| 637 | struct compressor **cp; |
---|
[85a0f07] | 638 | u_char ccp_option[CCP_MAX_OPTION_LENGTH]; |
---|
| 639 | #endif |
---|
| 640 | |
---|
| 641 | switch (cmd) { |
---|
| 642 | case FIONREAD: |
---|
| 643 | *(int *)data = sc->sc_inq.ifq_len; |
---|
| 644 | break; |
---|
| 645 | |
---|
[0286b9f] | 646 | case PPPIOCSTASK: |
---|
| 647 | taskid = *(int *)data; |
---|
| 648 | sc->sc_pppdtask = taskid; |
---|
| 649 | break; |
---|
| 650 | |
---|
[85a0f07] | 651 | case PPPIOCGUNIT: |
---|
| 652 | *(int *)data = sc->sc_if.if_unit; |
---|
| 653 | break; |
---|
| 654 | |
---|
| 655 | case PPPIOCGFLAGS: |
---|
| 656 | *(u_int *)data = sc->sc_flags; |
---|
| 657 | break; |
---|
| 658 | |
---|
| 659 | case PPPIOCSFLAGS: |
---|
| 660 | flags = *(int *)data & SC_MASK; |
---|
| 661 | s = splsoftnet(); |
---|
| 662 | #ifdef PPP_COMPRESS |
---|
| 663 | if (sc->sc_flags & SC_CCP_OPEN && !(flags & SC_CCP_OPEN)) |
---|
| 664 | ppp_ccp_closed(sc); |
---|
| 665 | #endif |
---|
[cb1e8a46] | 666 | s = splimp(); |
---|
[85a0f07] | 667 | sc->sc_flags = (sc->sc_flags & ~SC_MASK) | flags; |
---|
| 668 | splx(s); |
---|
| 669 | break; |
---|
| 670 | |
---|
| 671 | case PPPIOCSMRU: |
---|
| 672 | mru = *(int *)data; |
---|
[0286b9f] | 673 | if ( mru >= MCLBYTES ) { |
---|
| 674 | /* error - currently only handle 1 culster sized MRU */ |
---|
| 675 | /* if we want to handle up to PPP_MAXMRU then we */ |
---|
| 676 | /* need to reallocate all mbufs on the freeq */ |
---|
| 677 | /* this can only be done with iterrupts disabled */ |
---|
| 678 | return ( -1 ); |
---|
| 679 | } |
---|
| 680 | else if ( mru >= PPP_MRU ) { |
---|
| 681 | /* update the size */ |
---|
| 682 | sc->sc_mru = mru; |
---|
| 683 | } |
---|
[85a0f07] | 684 | break; |
---|
| 685 | |
---|
| 686 | case PPPIOCGMRU: |
---|
| 687 | *(int *)data = sc->sc_mru; |
---|
| 688 | break; |
---|
| 689 | |
---|
| 690 | #ifdef VJC |
---|
| 691 | case PPPIOCSMAXCID: |
---|
| 692 | if (sc->sc_comp) { |
---|
| 693 | s = splsoftnet(); |
---|
[47a8868] | 694 | sl_compress_init(sc->sc_comp, *(int *)data); |
---|
[85a0f07] | 695 | splx(s); |
---|
| 696 | } |
---|
| 697 | break; |
---|
| 698 | #endif |
---|
| 699 | |
---|
| 700 | case PPPIOCXFERUNIT: |
---|
| 701 | sc->sc_xfer = 0; /* Always root p->p_pid;*/ |
---|
| 702 | break; |
---|
| 703 | |
---|
| 704 | #ifdef PPP_COMPRESS |
---|
| 705 | case PPPIOCSCOMPRESS: |
---|
| 706 | odp = (struct ppp_option_data *) data; |
---|
| 707 | nb = odp->length; |
---|
| 708 | if (nb > sizeof(ccp_option)) |
---|
| 709 | nb = sizeof(ccp_option); |
---|
| 710 | if ((error = copyin(odp->ptr, ccp_option, nb)) != 0) |
---|
| 711 | return (error); |
---|
| 712 | if (ccp_option[1] < 2) /* preliminary check on the length byte */ |
---|
| 713 | return (EINVAL); |
---|
| 714 | for (cp = ppp_compressors; *cp != NULL; ++cp) |
---|
| 715 | if ((*cp)->compress_proto == ccp_option[0]) { |
---|
| 716 | /* |
---|
| 717 | * Found a handler for the protocol - try to allocate |
---|
| 718 | * a compressor or decompressor. |
---|
| 719 | */ |
---|
| 720 | error = 0; |
---|
| 721 | if (odp->transmit) { |
---|
| 722 | s = splsoftnet(); |
---|
| 723 | if (sc->sc_xc_state != NULL) |
---|
| 724 | (*sc->sc_xcomp->comp_free)(sc->sc_xc_state); |
---|
| 725 | sc->sc_xcomp = *cp; |
---|
| 726 | sc->sc_xc_state = (*cp)->comp_alloc(ccp_option, nb); |
---|
| 727 | if (sc->sc_xc_state == NULL) { |
---|
| 728 | if (sc->sc_flags & SC_DEBUG) |
---|
| 729 | printf("ppp%d: comp_alloc failed\n", |
---|
| 730 | sc->sc_if.if_unit); |
---|
| 731 | error = ENOBUFS; |
---|
| 732 | } |
---|
| 733 | splimp(); |
---|
| 734 | sc->sc_flags &= ~SC_COMP_RUN; |
---|
| 735 | splx(s); |
---|
| 736 | } else { |
---|
| 737 | s = splsoftnet(); |
---|
| 738 | if (sc->sc_rc_state != NULL) |
---|
| 739 | (*sc->sc_rcomp->decomp_free)(sc->sc_rc_state); |
---|
| 740 | sc->sc_rcomp = *cp; |
---|
| 741 | sc->sc_rc_state = (*cp)->decomp_alloc(ccp_option, nb); |
---|
| 742 | if (sc->sc_rc_state == NULL) { |
---|
| 743 | if (sc->sc_flags & SC_DEBUG) |
---|
| 744 | printf("ppp%d: decomp_alloc failed\n", |
---|
| 745 | sc->sc_if.if_unit); |
---|
| 746 | error = ENOBUFS; |
---|
| 747 | } |
---|
| 748 | splimp(); |
---|
| 749 | sc->sc_flags &= ~SC_DECOMP_RUN; |
---|
| 750 | splx(s); |
---|
| 751 | } |
---|
| 752 | return (error); |
---|
| 753 | } |
---|
| 754 | if (sc->sc_flags & SC_DEBUG) |
---|
| 755 | printf("ppp%d: no compressor for [%x %x %x], %x\n", |
---|
| 756 | sc->sc_if.if_unit, ccp_option[0], ccp_option[1], |
---|
| 757 | ccp_option[2], nb); |
---|
| 758 | return (EINVAL); /* no handler found */ |
---|
| 759 | #endif /* PPP_COMPRESS */ |
---|
| 760 | |
---|
| 761 | case PPPIOCGNPMODE: |
---|
| 762 | case PPPIOCSNPMODE: |
---|
| 763 | npi = (struct npioctl *) data; |
---|
| 764 | switch (npi->protocol) { |
---|
| 765 | case PPP_IP: |
---|
| 766 | npx = NP_IP; |
---|
| 767 | break; |
---|
| 768 | default: |
---|
| 769 | return EINVAL; |
---|
| 770 | } |
---|
| 771 | if (cmd == PPPIOCGNPMODE) { |
---|
| 772 | npi->mode = sc->sc_npmode[npx]; |
---|
| 773 | } else { |
---|
| 774 | if (npi->mode != sc->sc_npmode[npx]) { |
---|
| 775 | s = splsoftnet(); |
---|
| 776 | sc->sc_npmode[npx] = npi->mode; |
---|
| 777 | if (npi->mode != NPMODE_QUEUE) { |
---|
| 778 | ppp_requeue(sc); |
---|
| 779 | (*sc->sc_start)(sc); |
---|
| 780 | } |
---|
| 781 | splx(s); |
---|
| 782 | } |
---|
| 783 | } |
---|
| 784 | break; |
---|
| 785 | |
---|
| 786 | case PPPIOCGIDLE: |
---|
| 787 | s = splsoftnet(); |
---|
[0286b9f] | 788 | microtime(&ppp_time); |
---|
[85a0f07] | 789 | t = ppp_time.tv_sec; |
---|
| 790 | ((struct ppp_idle *)data)->xmit_idle = t - sc->sc_last_sent; |
---|
| 791 | ((struct ppp_idle *)data)->recv_idle = t - sc->sc_last_recv; |
---|
| 792 | splx(s); |
---|
| 793 | break; |
---|
| 794 | |
---|
| 795 | #ifdef PPP_FILTER |
---|
| 796 | case PPPIOCSPASS: |
---|
| 797 | case PPPIOCSACTIVE: |
---|
| 798 | nbp = (struct bpf_program *) data; |
---|
| 799 | if ((unsigned) nbp->bf_len > BPF_MAXINSNS) |
---|
| 800 | return EINVAL; |
---|
| 801 | newcodelen = nbp->bf_len * sizeof(struct bpf_insn); |
---|
| 802 | if (newcodelen != 0) { |
---|
[0286b9f] | 803 | MALLOC(newcode, struct bpf_insn *, newcodelen, M_DEVBUF, M_WAITOK); |
---|
[85a0f07] | 804 | if (newcode == 0) { |
---|
| 805 | return EINVAL; /* or sumpin */ |
---|
| 806 | } |
---|
| 807 | if ((error = copyin((caddr_t)nbp->bf_insns, (caddr_t)newcode, |
---|
| 808 | newcodelen)) != 0) { |
---|
[0286b9f] | 809 | FREE(newcode, M_DEVBUF); |
---|
[85a0f07] | 810 | return error; |
---|
| 811 | } |
---|
| 812 | if (!bpf_validate(newcode, nbp->bf_len)) { |
---|
[0286b9f] | 813 | FREE(newcode, M_DEVBUF); |
---|
[85a0f07] | 814 | return EINVAL; |
---|
| 815 | } |
---|
| 816 | } else |
---|
| 817 | newcode = 0; |
---|
| 818 | bp = (cmd == PPPIOCSPASS)? &sc->sc_pass_filt: &sc->sc_active_filt; |
---|
| 819 | oldcode = bp->bf_insns; |
---|
| 820 | s = splimp(); |
---|
| 821 | bp->bf_len = nbp->bf_len; |
---|
| 822 | bp->bf_insns = newcode; |
---|
| 823 | splx(s); |
---|
| 824 | if (oldcode != 0) |
---|
[0286b9f] | 825 | FREE(oldcode, M_DEVBUF); |
---|
[85a0f07] | 826 | break; |
---|
| 827 | #endif |
---|
| 828 | |
---|
| 829 | default: |
---|
| 830 | return (-1); |
---|
| 831 | } |
---|
| 832 | return (0); |
---|
| 833 | } |
---|
| 834 | |
---|
| 835 | /* |
---|
| 836 | * Process an ioctl request to the ppp network interface. |
---|
| 837 | */ |
---|
| 838 | static int |
---|
[a009d94] | 839 | pppsioctl(struct ifnet *ifp, ioctl_command_t cmd, caddr_t data) |
---|
[85a0f07] | 840 | { |
---|
[0286b9f] | 841 | /*struct proc *p = curproc;*/ /* XXX */ |
---|
[85a0f07] | 842 | register struct ppp_softc *sc = &ppp_softc[ifp->if_unit]; |
---|
| 843 | register struct ifaddr *ifa = (struct ifaddr *)data; |
---|
| 844 | register struct ifreq *ifr = (struct ifreq *)data; |
---|
| 845 | struct ppp_stats *psp; |
---|
| 846 | #ifdef PPP_COMPRESS |
---|
| 847 | struct ppp_comp_stats *pcp; |
---|
| 848 | #endif |
---|
| 849 | int s = splimp(), error = 0; |
---|
| 850 | |
---|
| 851 | switch (cmd) { |
---|
| 852 | case SIOCSIFFLAGS: |
---|
| 853 | if ((ifp->if_flags & IFF_RUNNING) == 0) |
---|
| 854 | ifp->if_flags &= ~IFF_UP; |
---|
| 855 | break; |
---|
| 856 | |
---|
| 857 | case SIOCSIFADDR: |
---|
| 858 | if (ifa->ifa_addr->sa_family != AF_INET) |
---|
| 859 | error = EAFNOSUPPORT; |
---|
| 860 | break; |
---|
| 861 | |
---|
| 862 | case SIOCSIFDSTADDR: |
---|
| 863 | if (ifa->ifa_addr->sa_family != AF_INET) |
---|
| 864 | error = EAFNOSUPPORT; |
---|
| 865 | break; |
---|
| 866 | |
---|
| 867 | case SIOCSIFMTU: |
---|
| 868 | sc->sc_if.if_mtu = ifr->ifr_mtu; |
---|
| 869 | break; |
---|
| 870 | |
---|
| 871 | case SIOCGIFMTU: |
---|
| 872 | ifr->ifr_mtu = sc->sc_if.if_mtu; |
---|
| 873 | break; |
---|
| 874 | |
---|
| 875 | case SIOCADDMULTI: |
---|
| 876 | case SIOCDELMULTI: |
---|
| 877 | if (ifr == 0) { |
---|
| 878 | error = EAFNOSUPPORT; |
---|
| 879 | break; |
---|
| 880 | } |
---|
| 881 | switch(ifr->ifr_addr.sa_family) { |
---|
| 882 | #ifdef INET |
---|
| 883 | case AF_INET: |
---|
| 884 | break; |
---|
| 885 | #endif |
---|
| 886 | default: |
---|
| 887 | error = EAFNOSUPPORT; |
---|
| 888 | break; |
---|
| 889 | } |
---|
| 890 | break; |
---|
[0286b9f] | 891 | |
---|
| 892 | case SIO_RTEMS_SHOW_STATS: |
---|
| 893 | printf(" MRU:%-8u", sc->sc_mru); |
---|
| 894 | printf(" Bytes received:%-8u", sc->sc_stats.ppp_ibytes); |
---|
| 895 | printf(" Packets received:%-8u", sc->sc_stats.ppp_ipackets); |
---|
| 896 | printf(" Receive errors:%-8u\n", sc->sc_stats.ppp_ierrors); |
---|
| 897 | printf(" Bytes sent:%-8u", sc->sc_stats.ppp_obytes); |
---|
| 898 | printf(" Packets sent:%-8u", sc->sc_stats.ppp_opackets); |
---|
| 899 | printf(" Transmit errors:%-8u\n", sc->sc_stats.ppp_oerrors); |
---|
[85a0f07] | 900 | break; |
---|
| 901 | |
---|
| 902 | case SIOCGPPPSTATS: |
---|
| 903 | psp = &((struct ifpppstatsreq *) data)->stats; |
---|
| 904 | bzero(psp, sizeof(*psp)); |
---|
| 905 | psp->p = sc->sc_stats; |
---|
| 906 | #if defined(VJC) && !defined(SL_NO_STATS) |
---|
| 907 | if (sc->sc_comp) { |
---|
| 908 | psp->vj.vjs_packets = sc->sc_comp->sls_packets; |
---|
| 909 | psp->vj.vjs_compressed = sc->sc_comp->sls_compressed; |
---|
| 910 | psp->vj.vjs_searches = sc->sc_comp->sls_searches; |
---|
| 911 | psp->vj.vjs_misses = sc->sc_comp->sls_misses; |
---|
| 912 | psp->vj.vjs_uncompressedin = sc->sc_comp->sls_uncompressedin; |
---|
| 913 | psp->vj.vjs_compressedin = sc->sc_comp->sls_compressedin; |
---|
| 914 | psp->vj.vjs_errorin = sc->sc_comp->sls_errorin; |
---|
| 915 | psp->vj.vjs_tossed = sc->sc_comp->sls_tossed; |
---|
| 916 | } |
---|
| 917 | #endif /* VJC */ |
---|
| 918 | break; |
---|
| 919 | |
---|
| 920 | #ifdef PPP_COMPRESS |
---|
| 921 | case SIOCGPPPCSTATS: |
---|
| 922 | pcp = &((struct ifpppcstatsreq *) data)->stats; |
---|
| 923 | bzero(pcp, sizeof(*pcp)); |
---|
| 924 | if (sc->sc_xc_state != NULL) |
---|
| 925 | (*sc->sc_xcomp->comp_stat)(sc->sc_xc_state, &pcp->c); |
---|
| 926 | if (sc->sc_rc_state != NULL) |
---|
| 927 | (*sc->sc_rcomp->decomp_stat)(sc->sc_rc_state, &pcp->d); |
---|
| 928 | break; |
---|
| 929 | #endif /* PPP_COMPRESS */ |
---|
| 930 | |
---|
| 931 | default: |
---|
| 932 | error = EINVAL; |
---|
| 933 | } |
---|
| 934 | splx(s); |
---|
| 935 | return (error); |
---|
| 936 | } |
---|
| 937 | |
---|
| 938 | /* |
---|
| 939 | * Queue a packet. Start transmission if not active. |
---|
| 940 | * Packet is placed in Information field of PPP frame. |
---|
| 941 | */ |
---|
| 942 | int |
---|
[42e10fa2] | 943 | pppoutput(struct ifnet *ifp, struct mbuf *m0, struct sockaddr *dst, |
---|
| 944 | struct rtentry *rtp) |
---|
[85a0f07] | 945 | { |
---|
| 946 | register struct ppp_softc *sc = &ppp_softc[ifp->if_unit]; |
---|
| 947 | int protocol, address, control; |
---|
| 948 | u_char *cp; |
---|
| 949 | int s, error; |
---|
| 950 | struct ip *ip; |
---|
| 951 | struct ifqueue *ifq; |
---|
| 952 | enum NPmode mode; |
---|
| 953 | int len; |
---|
| 954 | struct mbuf *m; |
---|
[0286b9f] | 955 | |
---|
[85a0f07] | 956 | if (sc->sc_devp == NULL || (ifp->if_flags & IFF_RUNNING) == 0 |
---|
| 957 | || ((ifp->if_flags & IFF_UP) == 0 && dst->sa_family != AF_UNSPEC)) { |
---|
| 958 | error = ENETDOWN; /* sort of */ |
---|
| 959 | goto bad; |
---|
| 960 | } |
---|
| 961 | |
---|
| 962 | /* |
---|
| 963 | * Compute PPP header. |
---|
| 964 | */ |
---|
| 965 | m0->m_flags &= ~M_HIGHPRI; |
---|
| 966 | switch (dst->sa_family) { |
---|
| 967 | #ifdef INET |
---|
| 968 | case AF_INET: |
---|
| 969 | address = PPP_ALLSTATIONS; |
---|
| 970 | control = PPP_UI; |
---|
| 971 | protocol = PPP_IP; |
---|
| 972 | mode = sc->sc_npmode[NP_IP]; |
---|
| 973 | |
---|
| 974 | /* |
---|
| 975 | * If this packet has the "low delay" bit set in the IP header, |
---|
| 976 | * put it on the fastq instead. |
---|
| 977 | */ |
---|
| 978 | ip = mtod(m0, struct ip *); |
---|
| 979 | if (ip->ip_tos & IPTOS_LOWDELAY) |
---|
| 980 | m0->m_flags |= M_HIGHPRI; |
---|
| 981 | break; |
---|
| 982 | #endif |
---|
| 983 | case AF_UNSPEC: |
---|
| 984 | address = PPP_ADDRESS(dst->sa_data); |
---|
| 985 | control = PPP_CONTROL(dst->sa_data); |
---|
| 986 | protocol = PPP_PROTOCOL(dst->sa_data); |
---|
| 987 | mode = NPMODE_PASS; |
---|
| 988 | break; |
---|
| 989 | default: |
---|
| 990 | printf("ppp%d: af%d not supported\n", ifp->if_unit, dst->sa_family); |
---|
| 991 | error = EAFNOSUPPORT; |
---|
| 992 | goto bad; |
---|
| 993 | } |
---|
| 994 | |
---|
| 995 | /* |
---|
| 996 | * Drop this packet, or return an error, if necessary. |
---|
| 997 | */ |
---|
| 998 | if (mode == NPMODE_ERROR) { |
---|
| 999 | error = ENETDOWN; |
---|
| 1000 | goto bad; |
---|
| 1001 | } |
---|
| 1002 | if (mode == NPMODE_DROP) { |
---|
| 1003 | error = 0; |
---|
| 1004 | goto bad; |
---|
| 1005 | } |
---|
| 1006 | |
---|
| 1007 | /* |
---|
| 1008 | * Add PPP header. If no space in first mbuf, allocate another. |
---|
| 1009 | * (This assumes M_LEADINGSPACE is always 0 for a cluster mbuf.) |
---|
| 1010 | */ |
---|
| 1011 | if (M_LEADINGSPACE(m0) < PPP_HDRLEN) { |
---|
| 1012 | m0 = m_prepend(m0, PPP_HDRLEN, M_DONTWAIT); |
---|
| 1013 | if (m0 == 0) { |
---|
| 1014 | error = ENOBUFS; |
---|
| 1015 | goto bad; |
---|
| 1016 | } |
---|
| 1017 | m0->m_len = 0; |
---|
| 1018 | } else |
---|
| 1019 | m0->m_data -= PPP_HDRLEN; |
---|
| 1020 | |
---|
| 1021 | cp = mtod(m0, u_char *); |
---|
| 1022 | *cp++ = address; |
---|
| 1023 | *cp++ = control; |
---|
| 1024 | *cp++ = protocol >> 8; |
---|
| 1025 | *cp++ = protocol & 0xff; |
---|
| 1026 | m0->m_len += PPP_HDRLEN; |
---|
| 1027 | |
---|
| 1028 | len = 0; |
---|
| 1029 | for (m = m0; m != 0; m = m->m_next) |
---|
| 1030 | len += m->m_len; |
---|
| 1031 | |
---|
| 1032 | if (sc->sc_flags & SC_LOG_OUTPKT) { |
---|
| 1033 | printf("ppp%d output: ", ifp->if_unit); |
---|
| 1034 | pppdumpm(m0); |
---|
| 1035 | } |
---|
| 1036 | |
---|
| 1037 | if ((protocol & 0x8000) == 0) { |
---|
| 1038 | #ifdef PPP_FILTER |
---|
| 1039 | /* |
---|
| 1040 | * Apply the pass and active filters to the packet, |
---|
| 1041 | * but only if it is a data packet. |
---|
| 1042 | */ |
---|
| 1043 | *mtod(m0, u_char *) = 1; /* indicates outbound */ |
---|
| 1044 | if (sc->sc_pass_filt.bf_insns != 0 |
---|
| 1045 | && bpf_filter(sc->sc_pass_filt.bf_insns, (u_char *) m0, |
---|
| 1046 | len, 0) == 0) { |
---|
| 1047 | error = 0; /* drop this packet */ |
---|
| 1048 | goto bad; |
---|
| 1049 | } |
---|
| 1050 | |
---|
| 1051 | /* |
---|
| 1052 | * Update the time we sent the most recent packet. |
---|
| 1053 | */ |
---|
| 1054 | if (sc->sc_active_filt.bf_insns == 0 |
---|
| 1055 | || bpf_filter(sc->sc_active_filt.bf_insns, (u_char *) m0, len, 0)) |
---|
[0286b9f] | 1056 | sc->sc_last_sent = time.tv_sec; |
---|
[85a0f07] | 1057 | |
---|
| 1058 | *mtod(m0, u_char *) = address; |
---|
| 1059 | #else |
---|
| 1060 | /* |
---|
| 1061 | * Update the time we sent the most recent data packet. |
---|
| 1062 | */ |
---|
[0286b9f] | 1063 | microtime(&ppp_time); |
---|
[85a0f07] | 1064 | sc->sc_last_sent = ppp_time.tv_sec; |
---|
| 1065 | #endif /* PPP_FILTER */ |
---|
| 1066 | } |
---|
| 1067 | |
---|
| 1068 | #if NBPFILTER > 0 |
---|
| 1069 | /* |
---|
| 1070 | * See if bpf wants to look at the packet. |
---|
| 1071 | */ |
---|
| 1072 | if (sc->sc_bpf) |
---|
| 1073 | bpf_mtap(sc->sc_bpf, m0); |
---|
| 1074 | #endif |
---|
| 1075 | |
---|
| 1076 | /* |
---|
| 1077 | * Put the packet on the appropriate queue. |
---|
| 1078 | */ |
---|
[0286b9f] | 1079 | s = splsoftnet(); |
---|
[85a0f07] | 1080 | if (mode == NPMODE_QUEUE) { |
---|
| 1081 | /* XXX we should limit the number of packets on this queue */ |
---|
| 1082 | *sc->sc_npqtail = m0; |
---|
| 1083 | m0->m_nextpkt = NULL; |
---|
| 1084 | sc->sc_npqtail = &m0->m_nextpkt; |
---|
| 1085 | } else { |
---|
| 1086 | ifq = (m0->m_flags & M_HIGHPRI)? &sc->sc_fastq: &ifp->if_snd; |
---|
| 1087 | if (IF_QFULL(ifq) && dst->sa_family != AF_UNSPEC) { |
---|
| 1088 | IF_DROP(ifq); |
---|
| 1089 | splx(s); |
---|
| 1090 | sc->sc_if.if_oerrors++; |
---|
| 1091 | sc->sc_stats.ppp_oerrors++; |
---|
| 1092 | error = ENOBUFS; |
---|
| 1093 | goto bad; |
---|
| 1094 | } |
---|
| 1095 | IF_ENQUEUE(ifq, m0); |
---|
| 1096 | (*sc->sc_start)(sc); |
---|
| 1097 | } |
---|
| 1098 | ifp->if_lastchange = ppp_time; |
---|
| 1099 | ifp->if_opackets++; |
---|
| 1100 | ifp->if_obytes += len; |
---|
| 1101 | |
---|
[0286b9f] | 1102 | splx(s); |
---|
[85a0f07] | 1103 | return (0); |
---|
| 1104 | |
---|
| 1105 | bad: |
---|
| 1106 | m_freem(m0); |
---|
| 1107 | return (error); |
---|
| 1108 | } |
---|
| 1109 | |
---|
| 1110 | /* |
---|
| 1111 | * After a change in the NPmode for some NP, move packets from the |
---|
| 1112 | * npqueue to the send queue or the fast queue as appropriate. |
---|
[41ff670] | 1113 | * Should be called at spl[soft]net. |
---|
[85a0f07] | 1114 | */ |
---|
| 1115 | static void |
---|
[42e10fa2] | 1116 | ppp_requeue(struct ppp_softc *sc) |
---|
[85a0f07] | 1117 | { |
---|
| 1118 | struct mbuf *m, **mpp; |
---|
| 1119 | struct ifqueue *ifq; |
---|
| 1120 | enum NPmode mode; |
---|
| 1121 | |
---|
| 1122 | for (mpp = &sc->sc_npqueue; (m = *mpp) != NULL; ) { |
---|
| 1123 | switch (PPP_PROTOCOL(mtod(m, u_char *))) { |
---|
| 1124 | case PPP_IP: |
---|
| 1125 | mode = sc->sc_npmode[NP_IP]; |
---|
| 1126 | break; |
---|
| 1127 | default: |
---|
| 1128 | mode = NPMODE_PASS; |
---|
| 1129 | } |
---|
| 1130 | |
---|
| 1131 | switch (mode) { |
---|
| 1132 | case NPMODE_PASS: |
---|
| 1133 | /* |
---|
| 1134 | * This packet can now go on one of the queues to be sent. |
---|
| 1135 | */ |
---|
| 1136 | *mpp = m->m_nextpkt; |
---|
| 1137 | m->m_nextpkt = NULL; |
---|
| 1138 | ifq = (m->m_flags & M_HIGHPRI)? &sc->sc_fastq: &sc->sc_if.if_snd; |
---|
| 1139 | if (IF_QFULL(ifq)) { |
---|
| 1140 | IF_DROP(ifq); |
---|
| 1141 | sc->sc_if.if_oerrors++; |
---|
| 1142 | sc->sc_stats.ppp_oerrors++; |
---|
| 1143 | } else |
---|
| 1144 | IF_ENQUEUE(ifq, m); |
---|
| 1145 | break; |
---|
| 1146 | |
---|
| 1147 | case NPMODE_DROP: |
---|
| 1148 | case NPMODE_ERROR: |
---|
| 1149 | *mpp = m->m_nextpkt; |
---|
| 1150 | m_freem(m); |
---|
| 1151 | break; |
---|
| 1152 | |
---|
| 1153 | case NPMODE_QUEUE: |
---|
| 1154 | mpp = &m->m_nextpkt; |
---|
| 1155 | break; |
---|
| 1156 | } |
---|
| 1157 | } |
---|
| 1158 | sc->sc_npqtail = mpp; |
---|
| 1159 | } |
---|
| 1160 | |
---|
| 1161 | /* |
---|
| 1162 | * Get a packet to send. This procedure is intended to be called at |
---|
| 1163 | * splsoftnet, since it may involve time-consuming operations such as |
---|
| 1164 | * applying VJ compression, packet compression, address/control and/or |
---|
| 1165 | * protocol field compression to the packet. |
---|
| 1166 | */ |
---|
| 1167 | struct mbuf * |
---|
[42e10fa2] | 1168 | ppp_dequeue(struct ppp_softc *sc) |
---|
[85a0f07] | 1169 | { |
---|
[3274c876] | 1170 | #ifdef PPP_COMPRESS |
---|
| 1171 | struct mbuf *mp; |
---|
| 1172 | #endif |
---|
| 1173 | struct mbuf *m; |
---|
[85a0f07] | 1174 | u_char *cp; |
---|
| 1175 | int address, control, protocol; |
---|
| 1176 | |
---|
| 1177 | /* |
---|
| 1178 | * Grab a packet to send: first try the fast queue, then the |
---|
| 1179 | * normal queue. |
---|
| 1180 | */ |
---|
[0286b9f] | 1181 | rtems_bsdnet_semaphore_obtain(); |
---|
[85a0f07] | 1182 | IF_DEQUEUE(&sc->sc_fastq, m); |
---|
| 1183 | if (m == NULL) |
---|
| 1184 | IF_DEQUEUE(&sc->sc_if.if_snd, m); |
---|
[0286b9f] | 1185 | rtems_bsdnet_semaphore_release(); |
---|
| 1186 | |
---|
[85a0f07] | 1187 | if (m == NULL) |
---|
| 1188 | return NULL; |
---|
| 1189 | |
---|
| 1190 | ++sc->sc_stats.ppp_opackets; |
---|
| 1191 | |
---|
| 1192 | /* |
---|
| 1193 | * Extract the ppp header of the new packet. |
---|
| 1194 | * The ppp header will be in one mbuf. |
---|
| 1195 | */ |
---|
| 1196 | cp = mtod(m, u_char *); |
---|
| 1197 | address = PPP_ADDRESS(cp); |
---|
| 1198 | control = PPP_CONTROL(cp); |
---|
| 1199 | protocol = PPP_PROTOCOL(cp); |
---|
| 1200 | |
---|
| 1201 | switch (protocol) { |
---|
| 1202 | case PPP_IP: |
---|
| 1203 | #ifdef VJC |
---|
| 1204 | /* |
---|
| 1205 | * If the packet is a TCP/IP packet, see if we can compress it. |
---|
| 1206 | */ |
---|
| 1207 | if ((sc->sc_flags & SC_COMP_TCP) && sc->sc_comp != NULL) { |
---|
| 1208 | struct ip *ip; |
---|
| 1209 | int type; |
---|
| 1210 | |
---|
| 1211 | mp = m; |
---|
| 1212 | ip = (struct ip *) (cp + PPP_HDRLEN); |
---|
| 1213 | if (mp->m_len <= PPP_HDRLEN) { |
---|
| 1214 | mp = mp->m_next; |
---|
| 1215 | if (mp == NULL) |
---|
| 1216 | break; |
---|
| 1217 | ip = mtod(mp, struct ip *); |
---|
| 1218 | } |
---|
| 1219 | /* this code assumes the IP/TCP header is in one non-shared mbuf */ |
---|
| 1220 | if (ip->ip_p == IPPROTO_TCP) { |
---|
[47a8868] | 1221 | type = sl_compress_tcp(mp, ip, sc->sc_comp, |
---|
[85a0f07] | 1222 | !(sc->sc_flags & SC_NO_TCP_CCID)); |
---|
| 1223 | switch (type) { |
---|
| 1224 | case TYPE_UNCOMPRESSED_TCP: |
---|
| 1225 | protocol = PPP_VJC_UNCOMP; |
---|
| 1226 | break; |
---|
| 1227 | case TYPE_COMPRESSED_TCP: |
---|
| 1228 | protocol = PPP_VJC_COMP; |
---|
| 1229 | cp = mtod(m, u_char *); |
---|
| 1230 | cp[0] = address; /* header has moved */ |
---|
| 1231 | cp[1] = control; |
---|
| 1232 | cp[2] = 0; |
---|
| 1233 | break; |
---|
| 1234 | } |
---|
| 1235 | cp[3] = protocol; /* update protocol in PPP header */ |
---|
| 1236 | } |
---|
| 1237 | } |
---|
| 1238 | #endif /* VJC */ |
---|
| 1239 | break; |
---|
| 1240 | |
---|
| 1241 | #ifdef PPP_COMPRESS |
---|
| 1242 | case PPP_CCP: |
---|
| 1243 | ppp_ccp(sc, m, 0); |
---|
| 1244 | break; |
---|
| 1245 | #endif /* PPP_COMPRESS */ |
---|
| 1246 | } |
---|
| 1247 | |
---|
| 1248 | #ifdef PPP_COMPRESS |
---|
| 1249 | if (protocol != PPP_LCP && protocol != PPP_CCP |
---|
| 1250 | && sc->sc_xc_state && (sc->sc_flags & SC_COMP_RUN)) { |
---|
| 1251 | struct mbuf *mcomp = NULL; |
---|
| 1252 | int slen, clen; |
---|
| 1253 | |
---|
| 1254 | slen = 0; |
---|
| 1255 | for (mp = m; mp != NULL; mp = mp->m_next) |
---|
| 1256 | slen += mp->m_len; |
---|
| 1257 | clen = (*sc->sc_xcomp->compress) |
---|
| 1258 | (sc->sc_xc_state, &mcomp, m, slen, sc->sc_if.if_mtu + PPP_HDRLEN); |
---|
| 1259 | if (mcomp != NULL) { |
---|
| 1260 | if (sc->sc_flags & SC_CCP_UP) { |
---|
| 1261 | /* Send the compressed packet instead of the original. */ |
---|
| 1262 | m_freem(m); |
---|
| 1263 | m = mcomp; |
---|
| 1264 | cp = mtod(m, u_char *); |
---|
| 1265 | protocol = cp[3]; |
---|
| 1266 | } else { |
---|
| 1267 | /* Can't transmit compressed packets until CCP is up. */ |
---|
| 1268 | m_freem(mcomp); |
---|
| 1269 | } |
---|
| 1270 | } |
---|
| 1271 | } |
---|
| 1272 | #endif /* PPP_COMPRESS */ |
---|
| 1273 | |
---|
| 1274 | /* |
---|
| 1275 | * Compress the address/control and protocol, if possible. |
---|
| 1276 | */ |
---|
| 1277 | if (sc->sc_flags & SC_COMP_AC && address == PPP_ALLSTATIONS && |
---|
| 1278 | control == PPP_UI && protocol != PPP_ALLSTATIONS && |
---|
| 1279 | protocol != PPP_LCP) { |
---|
| 1280 | /* can compress address/control */ |
---|
| 1281 | m->m_data += 2; |
---|
| 1282 | m->m_len -= 2; |
---|
| 1283 | } |
---|
| 1284 | if (sc->sc_flags & SC_COMP_PROT && protocol < 0xFF) { |
---|
| 1285 | /* can compress protocol */ |
---|
| 1286 | if (mtod(m, u_char *) == cp) { |
---|
| 1287 | cp[2] = cp[1]; /* move address/control up */ |
---|
| 1288 | cp[1] = cp[0]; |
---|
| 1289 | } |
---|
| 1290 | ++m->m_data; |
---|
| 1291 | --m->m_len; |
---|
| 1292 | } |
---|
| 1293 | |
---|
| 1294 | return m; |
---|
| 1295 | } |
---|
| 1296 | |
---|
| 1297 | #ifdef PPP_COMPRESS |
---|
| 1298 | /* |
---|
| 1299 | * Handle a CCP packet. `rcvd' is 1 if the packet was received, |
---|
| 1300 | * 0 if it is about to be transmitted. |
---|
| 1301 | */ |
---|
| 1302 | static void |
---|
[42e10fa2] | 1303 | ppp_ccp(struct ppp_softc *sc, struct mbuf *m, int rcvd) |
---|
[85a0f07] | 1304 | { |
---|
| 1305 | u_char *dp, *ep; |
---|
| 1306 | struct mbuf *mp; |
---|
| 1307 | int slen, s; |
---|
| 1308 | |
---|
| 1309 | /* |
---|
| 1310 | * Get a pointer to the data after the PPP header. |
---|
| 1311 | */ |
---|
| 1312 | if (m->m_len <= PPP_HDRLEN) { |
---|
| 1313 | mp = m->m_next; |
---|
| 1314 | if (mp == NULL) |
---|
| 1315 | return; |
---|
| 1316 | dp = (mp != NULL)? mtod(mp, u_char *): NULL; |
---|
| 1317 | } else { |
---|
| 1318 | mp = m; |
---|
| 1319 | dp = mtod(mp, u_char *) + PPP_HDRLEN; |
---|
| 1320 | } |
---|
| 1321 | |
---|
| 1322 | ep = mtod(mp, u_char *) + mp->m_len; |
---|
| 1323 | if (dp + CCP_HDRLEN > ep) |
---|
| 1324 | return; |
---|
| 1325 | slen = CCP_LENGTH(dp); |
---|
| 1326 | if (dp + slen > ep) { |
---|
| 1327 | if (sc->sc_flags & SC_DEBUG) |
---|
| 1328 | printf("if_ppp/ccp: not enough data in mbuf (%p+%x > %p+%x)\n", |
---|
| 1329 | dp, slen, mtod(mp, u_char *), mp->m_len); |
---|
| 1330 | return; |
---|
| 1331 | } |
---|
| 1332 | |
---|
| 1333 | switch (CCP_CODE(dp)) { |
---|
| 1334 | case CCP_CONFREQ: |
---|
| 1335 | case CCP_TERMREQ: |
---|
| 1336 | case CCP_TERMACK: |
---|
| 1337 | /* CCP must be going down - disable compression */ |
---|
| 1338 | if (sc->sc_flags & SC_CCP_UP) { |
---|
| 1339 | s = splimp(); |
---|
| 1340 | sc->sc_flags &= ~(SC_CCP_UP | SC_COMP_RUN | SC_DECOMP_RUN); |
---|
| 1341 | splx(s); |
---|
| 1342 | } |
---|
| 1343 | break; |
---|
| 1344 | |
---|
| 1345 | case CCP_CONFACK: |
---|
| 1346 | if (sc->sc_flags & SC_CCP_OPEN && !(sc->sc_flags & SC_CCP_UP) |
---|
| 1347 | && slen >= CCP_HDRLEN + CCP_OPT_MINLEN |
---|
| 1348 | && slen >= CCP_OPT_LENGTH(dp + CCP_HDRLEN) + CCP_HDRLEN) { |
---|
| 1349 | if (!rcvd) { |
---|
| 1350 | /* we're agreeing to send compressed packets. */ |
---|
| 1351 | if (sc->sc_xc_state != NULL |
---|
| 1352 | && (*sc->sc_xcomp->comp_init) |
---|
| 1353 | (sc->sc_xc_state, dp + CCP_HDRLEN, slen - CCP_HDRLEN, |
---|
| 1354 | sc->sc_if.if_unit, 0, sc->sc_flags & SC_DEBUG)) { |
---|
| 1355 | s = splimp(); |
---|
| 1356 | sc->sc_flags |= SC_COMP_RUN; |
---|
| 1357 | splx(s); |
---|
| 1358 | } |
---|
| 1359 | } else { |
---|
| 1360 | /* peer is agreeing to send compressed packets. */ |
---|
| 1361 | if (sc->sc_rc_state != NULL |
---|
| 1362 | && (*sc->sc_rcomp->decomp_init) |
---|
| 1363 | (sc->sc_rc_state, dp + CCP_HDRLEN, slen - CCP_HDRLEN, |
---|
| 1364 | sc->sc_if.if_unit, 0, sc->sc_mru, |
---|
| 1365 | sc->sc_flags & SC_DEBUG)) { |
---|
| 1366 | s = splimp(); |
---|
| 1367 | sc->sc_flags |= SC_DECOMP_RUN; |
---|
| 1368 | sc->sc_flags &= ~(SC_DC_ERROR | SC_DC_FERROR); |
---|
| 1369 | splx(s); |
---|
| 1370 | } |
---|
| 1371 | } |
---|
| 1372 | } |
---|
| 1373 | break; |
---|
| 1374 | |
---|
| 1375 | case CCP_RESETACK: |
---|
| 1376 | if (sc->sc_flags & SC_CCP_UP) { |
---|
| 1377 | if (!rcvd) { |
---|
| 1378 | if (sc->sc_xc_state && (sc->sc_flags & SC_COMP_RUN)) |
---|
| 1379 | (*sc->sc_xcomp->comp_reset)(sc->sc_xc_state); |
---|
| 1380 | } else { |
---|
| 1381 | if (sc->sc_rc_state && (sc->sc_flags & SC_DECOMP_RUN)) { |
---|
| 1382 | (*sc->sc_rcomp->decomp_reset)(sc->sc_rc_state); |
---|
| 1383 | s = splimp(); |
---|
| 1384 | sc->sc_flags &= ~SC_DC_ERROR; |
---|
| 1385 | splx(s); |
---|
| 1386 | } |
---|
| 1387 | } |
---|
| 1388 | } |
---|
| 1389 | break; |
---|
| 1390 | } |
---|
| 1391 | } |
---|
| 1392 | |
---|
| 1393 | /* |
---|
| 1394 | * CCP is down; free (de)compressor state if necessary. |
---|
| 1395 | */ |
---|
| 1396 | static void |
---|
[42e10fa2] | 1397 | ppp_ccp_closed(struct ppp_softc *sc) |
---|
[85a0f07] | 1398 | { |
---|
| 1399 | if (sc->sc_xc_state) { |
---|
| 1400 | (*sc->sc_xcomp->comp_free)(sc->sc_xc_state); |
---|
| 1401 | sc->sc_xc_state = NULL; |
---|
| 1402 | } |
---|
| 1403 | if (sc->sc_rc_state) { |
---|
| 1404 | (*sc->sc_rcomp->decomp_free)(sc->sc_rc_state); |
---|
| 1405 | sc->sc_rc_state = NULL; |
---|
| 1406 | } |
---|
| 1407 | } |
---|
| 1408 | #endif /* PPP_COMPRESS */ |
---|
| 1409 | |
---|
| 1410 | /* |
---|
| 1411 | * Process a received PPP packet, doing decompression as necessary. |
---|
| 1412 | * Should be called at splsoftnet. |
---|
| 1413 | */ |
---|
| 1414 | #define COMPTYPE(proto) ((proto) == PPP_VJC_COMP? TYPE_COMPRESSED_TCP: \ |
---|
| 1415 | TYPE_UNCOMPRESSED_TCP) |
---|
| 1416 | |
---|
[0286b9f] | 1417 | static struct mbuf * |
---|
[42e10fa2] | 1418 | ppp_inproc(struct ppp_softc *sc, struct mbuf *m) |
---|
[85a0f07] | 1419 | { |
---|
[0286b9f] | 1420 | struct mbuf *mf = (struct mbuf *)0; |
---|
[85a0f07] | 1421 | struct ifnet *ifp = &sc->sc_if; |
---|
| 1422 | struct ifqueue *inq; |
---|
[cb1e8a46] | 1423 | int s, ilen, proto, rv; |
---|
[85a0f07] | 1424 | u_char *cp, adrs, ctrl; |
---|
[78d6a50] | 1425 | struct mbuf *mp; |
---|
| 1426 | #ifdef PPP_COMPRESS |
---|
[0286b9f] | 1427 | struct mbuf *dmp = NULL; |
---|
[78d6a50] | 1428 | #endif |
---|
[cb1e8a46] | 1429 | #ifdef VJC |
---|
[85a0f07] | 1430 | u_char *iphdr; |
---|
[cb1e8a46] | 1431 | u_int hlen; |
---|
| 1432 | int xlen; |
---|
| 1433 | #endif |
---|
[85a0f07] | 1434 | |
---|
| 1435 | sc->sc_stats.ppp_ipackets++; |
---|
| 1436 | |
---|
| 1437 | if (sc->sc_flags & SC_LOG_INPKT) { |
---|
| 1438 | ilen = 0; |
---|
| 1439 | for (mp = m; mp != NULL; mp = mp->m_next) |
---|
| 1440 | ilen += mp->m_len; |
---|
| 1441 | printf("ppp%d: got %d bytes\n", ifp->if_unit, ilen); |
---|
| 1442 | pppdumpm(m); |
---|
| 1443 | } |
---|
| 1444 | |
---|
| 1445 | cp = mtod(m, u_char *); |
---|
| 1446 | adrs = PPP_ADDRESS(cp); |
---|
| 1447 | ctrl = PPP_CONTROL(cp); |
---|
| 1448 | proto = PPP_PROTOCOL(cp); |
---|
| 1449 | |
---|
| 1450 | if (m->m_flags & M_ERRMARK) { |
---|
| 1451 | m->m_flags &= ~M_ERRMARK; |
---|
| 1452 | s = splimp(); |
---|
| 1453 | sc->sc_flags |= SC_VJ_RESET; |
---|
| 1454 | splx(s); |
---|
| 1455 | } |
---|
| 1456 | |
---|
| 1457 | #ifdef PPP_COMPRESS |
---|
| 1458 | /* |
---|
| 1459 | * Decompress this packet if necessary, update the receiver's |
---|
| 1460 | * dictionary, or take appropriate action on a CCP packet. |
---|
| 1461 | */ |
---|
| 1462 | if (proto == PPP_COMP && sc->sc_rc_state && (sc->sc_flags & SC_DECOMP_RUN) |
---|
| 1463 | && !(sc->sc_flags & SC_DC_ERROR) && !(sc->sc_flags & SC_DC_FERROR)) { |
---|
| 1464 | /* decompress this packet */ |
---|
| 1465 | rv = (*sc->sc_rcomp->decompress)(sc->sc_rc_state, m, &dmp); |
---|
| 1466 | if (rv == DECOMP_OK) { |
---|
| 1467 | m_freem(m); |
---|
| 1468 | if (dmp == NULL) { |
---|
| 1469 | /* no error, but no decompressed packet produced */ |
---|
[0286b9f] | 1470 | return mf; |
---|
[85a0f07] | 1471 | } |
---|
| 1472 | m = dmp; |
---|
| 1473 | cp = mtod(m, u_char *); |
---|
| 1474 | proto = PPP_PROTOCOL(cp); |
---|
| 1475 | |
---|
| 1476 | } else { |
---|
| 1477 | /* |
---|
| 1478 | * An error has occurred in decompression. |
---|
| 1479 | * Pass the compressed packet up to pppd, which may take |
---|
| 1480 | * CCP down or issue a Reset-Req. |
---|
| 1481 | */ |
---|
| 1482 | if (sc->sc_flags & SC_DEBUG) |
---|
| 1483 | printf("ppp%d: decompress failed %d\n", ifp->if_unit, rv); |
---|
| 1484 | s = splimp(); |
---|
| 1485 | sc->sc_flags |= SC_VJ_RESET; |
---|
| 1486 | if (rv == DECOMP_ERROR) |
---|
| 1487 | sc->sc_flags |= SC_DC_ERROR; |
---|
| 1488 | else |
---|
| 1489 | sc->sc_flags |= SC_DC_FERROR; |
---|
| 1490 | splx(s); |
---|
| 1491 | } |
---|
| 1492 | |
---|
| 1493 | } else { |
---|
| 1494 | if (sc->sc_rc_state && (sc->sc_flags & SC_DECOMP_RUN)) { |
---|
| 1495 | (*sc->sc_rcomp->incomp)(sc->sc_rc_state, m); |
---|
| 1496 | } |
---|
| 1497 | if (proto == PPP_CCP) { |
---|
| 1498 | ppp_ccp(sc, m, 1); |
---|
| 1499 | } |
---|
| 1500 | } |
---|
| 1501 | #endif |
---|
| 1502 | |
---|
| 1503 | ilen = 0; |
---|
| 1504 | for (mp = m; mp != NULL; mp = mp->m_next) |
---|
| 1505 | ilen += mp->m_len; |
---|
| 1506 | |
---|
| 1507 | #ifdef VJC |
---|
| 1508 | if (sc->sc_flags & SC_VJ_RESET) { |
---|
| 1509 | /* |
---|
| 1510 | * If we've missed a packet, we must toss subsequent compressed |
---|
| 1511 | * packets which don't have an explicit connection ID. |
---|
| 1512 | */ |
---|
| 1513 | if (sc->sc_comp) |
---|
[47a8868] | 1514 | sl_uncompress_tcp(NULL, 0, TYPE_ERROR, sc->sc_comp); |
---|
[85a0f07] | 1515 | s = splimp(); |
---|
| 1516 | sc->sc_flags &= ~SC_VJ_RESET; |
---|
| 1517 | splx(s); |
---|
| 1518 | } |
---|
| 1519 | |
---|
| 1520 | /* |
---|
| 1521 | * See if we have a VJ-compressed packet to uncompress. |
---|
| 1522 | */ |
---|
| 1523 | if (proto == PPP_VJC_COMP) { |
---|
| 1524 | if ((sc->sc_flags & SC_REJ_COMP_TCP) || sc->sc_comp == 0) |
---|
| 1525 | goto bad; |
---|
| 1526 | |
---|
[47a8868] | 1527 | xlen = sl_uncompress_tcp_core(cp + PPP_HDRLEN, m->m_len - PPP_HDRLEN, |
---|
[85a0f07] | 1528 | ilen - PPP_HDRLEN, TYPE_COMPRESSED_TCP, |
---|
| 1529 | sc->sc_comp, &iphdr, &hlen); |
---|
| 1530 | |
---|
| 1531 | if (xlen <= 0) { |
---|
| 1532 | if (sc->sc_flags & SC_DEBUG) |
---|
| 1533 | printf("ppp%d: VJ uncompress failed on type comp\n", |
---|
| 1534 | ifp->if_unit); |
---|
| 1535 | goto bad; |
---|
| 1536 | } |
---|
| 1537 | |
---|
| 1538 | /* Copy the PPP and IP headers into a new mbuf. */ |
---|
| 1539 | MGETHDR(mp, M_DONTWAIT, MT_DATA); |
---|
| 1540 | if (mp == NULL) |
---|
| 1541 | goto bad; |
---|
| 1542 | mp->m_len = 0; |
---|
| 1543 | mp->m_next = NULL; |
---|
| 1544 | if (hlen + PPP_HDRLEN > MHLEN) { |
---|
| 1545 | MCLGET(mp, M_DONTWAIT); |
---|
| 1546 | if (M_TRAILINGSPACE(mp) < hlen + PPP_HDRLEN) { |
---|
| 1547 | m_freem(mp); |
---|
| 1548 | goto bad; /* lose if big headers and no clusters */ |
---|
| 1549 | } |
---|
| 1550 | } |
---|
[41ff670] | 1551 | #ifdef MAC |
---|
| 1552 | mac_create_mbuf_from_mbuf(m, mp); |
---|
| 1553 | #endif |
---|
[85a0f07] | 1554 | cp = mtod(mp, u_char *); |
---|
| 1555 | cp[0] = adrs; |
---|
| 1556 | cp[1] = ctrl; |
---|
| 1557 | cp[2] = 0; |
---|
| 1558 | cp[3] = PPP_IP; |
---|
| 1559 | proto = PPP_IP; |
---|
| 1560 | bcopy(iphdr, cp + PPP_HDRLEN, hlen); |
---|
| 1561 | mp->m_len = hlen + PPP_HDRLEN; |
---|
| 1562 | |
---|
| 1563 | /* |
---|
| 1564 | * Trim the PPP and VJ headers off the old mbuf |
---|
| 1565 | * and stick the new and old mbufs together. |
---|
| 1566 | */ |
---|
| 1567 | m->m_data += PPP_HDRLEN + xlen; |
---|
| 1568 | m->m_len -= PPP_HDRLEN + xlen; |
---|
| 1569 | if (m->m_len <= M_TRAILINGSPACE(mp)) { |
---|
| 1570 | bcopy(mtod(m, u_char *), mtod(mp, u_char *) + mp->m_len, m->m_len); |
---|
| 1571 | mp->m_len += m->m_len; |
---|
| 1572 | MFREE(m, mp->m_next); |
---|
| 1573 | } else |
---|
| 1574 | mp->m_next = m; |
---|
| 1575 | m = mp; |
---|
| 1576 | ilen += hlen - xlen; |
---|
| 1577 | |
---|
| 1578 | } else if (proto == PPP_VJC_UNCOMP) { |
---|
| 1579 | if ((sc->sc_flags & SC_REJ_COMP_TCP) || sc->sc_comp == 0) |
---|
| 1580 | goto bad; |
---|
| 1581 | |
---|
[47a8868] | 1582 | xlen = sl_uncompress_tcp_core(cp + PPP_HDRLEN, m->m_len - PPP_HDRLEN, |
---|
[85a0f07] | 1583 | ilen - PPP_HDRLEN, TYPE_UNCOMPRESSED_TCP, |
---|
| 1584 | sc->sc_comp, &iphdr, &hlen); |
---|
| 1585 | |
---|
| 1586 | if (xlen < 0) { |
---|
| 1587 | if (sc->sc_flags & SC_DEBUG) |
---|
| 1588 | printf("ppp%d: VJ uncompress failed on type uncomp\n", |
---|
| 1589 | ifp->if_unit); |
---|
| 1590 | goto bad; |
---|
| 1591 | } |
---|
| 1592 | |
---|
| 1593 | proto = PPP_IP; |
---|
| 1594 | cp[3] = PPP_IP; |
---|
| 1595 | } |
---|
| 1596 | #endif /* VJC */ |
---|
| 1597 | |
---|
| 1598 | /* |
---|
| 1599 | * If the packet will fit in a header mbuf, don't waste a |
---|
| 1600 | * whole cluster on it. |
---|
| 1601 | */ |
---|
| 1602 | if (ilen <= MHLEN && M_IS_CLUSTER(m)) { |
---|
| 1603 | MGETHDR(mp, M_DONTWAIT, MT_DATA); |
---|
| 1604 | if (mp != NULL) { |
---|
| 1605 | m_copydata(m, 0, ilen, mtod(mp, caddr_t)); |
---|
[0286b9f] | 1606 | /* instead of freeing - return cluster mbuf so it can be reused */ |
---|
| 1607 | /* m_freem(m); */ |
---|
| 1608 | mf = m; |
---|
[85a0f07] | 1609 | m = mp; |
---|
| 1610 | m->m_len = ilen; |
---|
| 1611 | } |
---|
| 1612 | } |
---|
| 1613 | m->m_pkthdr.len = ilen; |
---|
| 1614 | m->m_pkthdr.rcvif = ifp; |
---|
| 1615 | |
---|
| 1616 | if ((proto & 0x8000) == 0) { |
---|
| 1617 | #ifdef PPP_FILTER |
---|
| 1618 | /* |
---|
| 1619 | * See whether we want to pass this packet, and |
---|
| 1620 | * if it counts as link activity. |
---|
| 1621 | */ |
---|
| 1622 | adrs = *mtod(m, u_char *); /* save address field */ |
---|
| 1623 | *mtod(m, u_char *) = 0; /* indicate inbound */ |
---|
| 1624 | if (sc->sc_pass_filt.bf_insns != 0 |
---|
| 1625 | && bpf_filter(sc->sc_pass_filt.bf_insns, (u_char *) m, |
---|
| 1626 | ilen, 0) == 0) { |
---|
| 1627 | /* drop this packet */ |
---|
| 1628 | m_freem(m); |
---|
[0286b9f] | 1629 | return mf; |
---|
[85a0f07] | 1630 | } |
---|
| 1631 | if (sc->sc_active_filt.bf_insns == 0 |
---|
| 1632 | || bpf_filter(sc->sc_active_filt.bf_insns, (u_char *) m, ilen, 0)) |
---|
[0286b9f] | 1633 | sc->sc_last_recv = time.tv_sec; |
---|
[85a0f07] | 1634 | |
---|
| 1635 | *mtod(m, u_char *) = adrs; |
---|
| 1636 | #else |
---|
| 1637 | /* |
---|
| 1638 | * Record the time that we received this packet. |
---|
| 1639 | */ |
---|
| 1640 | microtime(&ppp_time); |
---|
| 1641 | sc->sc_last_recv = ppp_time.tv_sec; |
---|
| 1642 | #endif /* PPP_FILTER */ |
---|
| 1643 | } |
---|
| 1644 | |
---|
| 1645 | #if NBPFILTER > 0 |
---|
| 1646 | /* See if bpf wants to look at the packet. */ |
---|
| 1647 | if (sc->sc_bpf) |
---|
| 1648 | bpf_mtap(sc->sc_bpf, m); |
---|
| 1649 | #endif |
---|
| 1650 | |
---|
| 1651 | rv = 0; |
---|
| 1652 | switch (proto) { |
---|
| 1653 | #ifdef INET |
---|
| 1654 | case PPP_IP: |
---|
| 1655 | /* |
---|
| 1656 | * IP packet - take off the ppp header and pass it up to IP. |
---|
| 1657 | */ |
---|
| 1658 | if ((ifp->if_flags & IFF_UP) == 0 |
---|
| 1659 | || sc->sc_npmode[NP_IP] != NPMODE_PASS) { |
---|
| 1660 | /* interface is down - drop the packet. */ |
---|
| 1661 | m_freem(m); |
---|
[0286b9f] | 1662 | return mf; |
---|
[85a0f07] | 1663 | } |
---|
| 1664 | m->m_pkthdr.len -= PPP_HDRLEN; |
---|
| 1665 | m->m_data += PPP_HDRLEN; |
---|
| 1666 | m->m_len -= PPP_HDRLEN; |
---|
| 1667 | schednetisr(NETISR_IP); |
---|
| 1668 | inq = &ipintrq; |
---|
| 1669 | break; |
---|
| 1670 | #endif |
---|
| 1671 | |
---|
| 1672 | default: |
---|
| 1673 | /* |
---|
| 1674 | * Some other protocol - place on input queue for read(). |
---|
| 1675 | */ |
---|
| 1676 | inq = &sc->sc_inq; |
---|
| 1677 | rv = 1; |
---|
| 1678 | break; |
---|
| 1679 | } |
---|
| 1680 | |
---|
| 1681 | /* |
---|
| 1682 | * Put the packet on the appropriate input queue. |
---|
| 1683 | */ |
---|
| 1684 | s = splimp(); |
---|
| 1685 | if (IF_QFULL(inq)) { |
---|
| 1686 | IF_DROP(inq); |
---|
| 1687 | splx(s); |
---|
| 1688 | if (sc->sc_flags & SC_DEBUG) |
---|
| 1689 | printf("ppp%d: input queue full\n", ifp->if_unit); |
---|
| 1690 | ifp->if_iqdrops++; |
---|
| 1691 | goto bad; |
---|
| 1692 | } |
---|
| 1693 | IF_ENQUEUE(inq, m); |
---|
| 1694 | splx(s); |
---|
[0286b9f] | 1695 | |
---|
[85a0f07] | 1696 | ifp->if_ipackets++; |
---|
| 1697 | ifp->if_ibytes += ilen; |
---|
[0286b9f] | 1698 | microtime(&ppp_time); |
---|
[85a0f07] | 1699 | ifp->if_lastchange = ppp_time; |
---|
| 1700 | |
---|
[0286b9f] | 1701 | if (rv) { |
---|
| 1702 | (*sc->sc_ctlp)(sc); |
---|
| 1703 | } |
---|
[85a0f07] | 1704 | |
---|
[0286b9f] | 1705 | return mf; |
---|
[85a0f07] | 1706 | |
---|
| 1707 | bad: |
---|
| 1708 | m_freem(m); |
---|
| 1709 | sc->sc_if.if_ierrors++; |
---|
| 1710 | sc->sc_stats.ppp_ierrors++; |
---|
[0286b9f] | 1711 | return mf; |
---|
[85a0f07] | 1712 | } |
---|
| 1713 | |
---|
| 1714 | #define MAX_DUMP_BYTES 128 |
---|
| 1715 | |
---|
| 1716 | static void |
---|
[42e10fa2] | 1717 | pppdumpm(struct mbuf *m0) |
---|
[85a0f07] | 1718 | { |
---|
| 1719 | char buf[3*MAX_DUMP_BYTES+4]; |
---|
| 1720 | char *bp = buf; |
---|
| 1721 | struct mbuf *m; |
---|
| 1722 | static char digits[] = "0123456789abcdef"; |
---|
| 1723 | |
---|
| 1724 | for (m = m0; m; m = m->m_next) { |
---|
| 1725 | int l = m->m_len; |
---|
| 1726 | u_char *rptr = (u_char *)m->m_data; |
---|
| 1727 | |
---|
| 1728 | while (l--) { |
---|
| 1729 | if (bp > buf + sizeof(buf) - 4) |
---|
| 1730 | goto done; |
---|
| 1731 | *bp++ = digits[*rptr >> 4]; /* convert byte to ascii hex */ |
---|
| 1732 | *bp++ = digits[*rptr++ & 0xf]; |
---|
| 1733 | } |
---|
| 1734 | |
---|
| 1735 | if (m->m_next) { |
---|
| 1736 | if (bp > buf + sizeof(buf) - 3) |
---|
| 1737 | goto done; |
---|
| 1738 | *bp++ = '|'; |
---|
| 1739 | } else |
---|
| 1740 | *bp++ = ' '; |
---|
| 1741 | } |
---|
| 1742 | done: |
---|
| 1743 | if (m) |
---|
| 1744 | *bp++ = '>'; |
---|
| 1745 | *bp = 0; |
---|
| 1746 | printf("%s\n", buf); |
---|
| 1747 | } |
---|
| 1748 | |
---|
| 1749 | #endif /* NPPP > 0 */ |
---|