diff options
author | ed <ed@FreeBSD.org> | 2009-04-05 22:08:18 +0000 |
---|---|---|
committer | ed <ed@FreeBSD.org> | 2009-04-05 22:08:18 +0000 |
commit | 36d960175a8cfcbccee2d24424dc7677bbf9954a (patch) | |
tree | 8a97b6bb04afecdfb70c99fe4302c043d6d240e0 /sys/net | |
parent | 18eefdb2b28b2ccc1394a40d490c6b1b0c80086d (diff) | |
download | FreeBSD-src-36d960175a8cfcbccee2d24424dc7677bbf9954a.zip FreeBSD-src-36d960175a8cfcbccee2d24424dc7677bbf9954a.tar.gz |
Remove if_ppp(4) and if_sl(4).
Not only did these two drivers depend on IFF_NEEDSGIANT, they were
broken 7 months ago during the MPSAFE TTY import. if_ppp(4) has been
replaced by ppp(8). There is no replacement for if_sl(4).
If we see regressions in for example the ports tree, we should just use
__FreeBSD_version 800045 to check whether if_ppp(4) and if_sl(4) are
present. Version 800045 is used to denote the import of MPSAFE TTY.
Discussed with: rwatson, but also rwatson's IFF_NEEDSGIANT emails on the
lists.
Diffstat (limited to 'sys/net')
-rw-r--r-- | sys/net/bsd_comp.c | 1117 | ||||
-rw-r--r-- | sys/net/if_ppp.c | 1733 | ||||
-rw-r--r-- | sys/net/if_ppp.h | 139 | ||||
-rw-r--r-- | sys/net/if_pppvar.h | 113 | ||||
-rw-r--r-- | sys/net/if_sl.c | 1110 | ||||
-rw-r--r-- | sys/net/if_slvar.h | 83 | ||||
-rw-r--r-- | sys/net/ppp_comp.h | 153 | ||||
-rw-r--r-- | sys/net/ppp_deflate.c | 680 | ||||
-rw-r--r-- | sys/net/ppp_tty.c | 1076 | ||||
-rw-r--r-- | sys/net/slip.h | 58 |
10 files changed, 0 insertions, 6262 deletions
diff --git a/sys/net/bsd_comp.c b/sys/net/bsd_comp.c deleted file mode 100644 index 462567b..0000000 --- a/sys/net/bsd_comp.c +++ /dev/null @@ -1,1117 +0,0 @@ -/*- - * Because this code is derived from the 4.3BSD compress source: - * - * - * Copyright (c) 1985, 1986 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * James A. Woods, derived from original work by Spencer Thomas - * and Joseph Orost. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* - * This version is for use with mbufs on BSD-derived systems. - * - * $FreeBSD$ - */ - -#include "opt_mac.h" - -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/lock.h> -#include <sys/malloc.h> -#include <sys/mbuf.h> -#include <sys/mutex.h> - -#include <net/ppp_defs.h> - -#define PACKETPTR struct mbuf * -#include <net/ppp_comp.h> - -#include <security/mac/mac_framework.h> - -/* - * PPP "BSD compress" compression - * The differences between this compression and the classic BSD LZW - * source are obvious from the requirement that the classic code worked - * with files while this handles arbitrarily long streams that - * are broken into packets. They are: - * - * When the code size expands, a block of junk is not emitted by - * the compressor and not expected by the decompressor. - * - * New codes are not necessarily assigned every time an old - * code is output by the compressor. This is because a packet - * end forces a code to be emitted, but does not imply that a - * new sequence has been seen. - * - * The compression ratio is checked at the first end of a packet - * after the appropriate gap. Besides simplifying and speeding - * things up, this makes it more likely that the transmitter - * and receiver will agree when the dictionary is cleared when - * compression is not going well. - */ - -/* - * A dictionary for doing BSD compress. - */ -struct bsd_db { - int totlen; /* length of this structure */ - u_int hsize; /* size of the hash table */ - u_char hshift; /* used in hash function */ - u_char n_bits; /* current bits/code */ - u_char maxbits; - u_char debug; - u_char unit; - u_int16_t seqno; /* sequence # of next packet */ - u_int hdrlen; /* header length to preallocate */ - u_int mru; - u_int maxmaxcode; /* largest valid code */ - u_int max_ent; /* largest code in use */ - u_int in_count; /* uncompressed bytes, aged */ - u_int bytes_out; /* compressed bytes, aged */ - u_int ratio; /* recent compression ratio */ - u_int checkpoint; /* when to next check the ratio */ - u_int clear_count; /* times dictionary cleared */ - u_int incomp_count; /* incompressible packets */ - u_int incomp_bytes; /* incompressible bytes */ - u_int uncomp_count; /* uncompressed packets */ - u_int uncomp_bytes; /* uncompressed bytes */ - u_int comp_count; /* compressed packets */ - u_int comp_bytes; /* compressed bytes */ - u_int16_t *lens; /* array of lengths of codes */ - struct bsd_dict { - union { /* hash value */ - u_int32_t fcode; - struct { -#if BYTE_ORDER == LITTLE_ENDIAN - u_int16_t prefix; /* preceding code */ - u_char suffix; /* last character of new code */ - u_char pad; -#else - u_char pad; - u_char suffix; /* last character of new code */ - u_int16_t prefix; /* preceding code */ -#endif - } hs; - } f; - u_int16_t codem1; /* output of hash table -1 */ - u_int16_t cptr; /* map code to hash table entry */ - } dict[1]; -}; - -#define BSD_OVHD 2 /* BSD compress overhead/packet */ -#define BSD_INIT_BITS BSD_MIN_BITS - -static void bsd_clear(struct bsd_db *db); -static int bsd_check(struct bsd_db *db); -static void *bsd_alloc(u_char *options, int opt_len, int decomp); -static int bsd_init(struct bsd_db *db, u_char *options, int opt_len, - int unit, int hdrlen, int mru, int debug, int decomp); -static void *bsd_comp_alloc(u_char *options, int opt_len); -static void *bsd_decomp_alloc(u_char *options, int opt_len); -static void bsd_free(void *state); -static int bsd_comp_init(void *state, u_char *options, int opt_len, - int unit, int hdrlen, int debug); -static int bsd_decomp_init(void *state, u_char *options, int opt_len, - int unit, int hdrlen, int mru, int debug); -static int bsd_compress(void *state, struct mbuf **mret, struct mbuf *mp, - int slen, int maxolen); -static void bsd_incomp(void *state, struct mbuf *dmsg); -static int bsd_decompress(void *state, struct mbuf *cmp, - struct mbuf **dmpp); -static void bsd_reset(void *state); -static void bsd_comp_stats(void *state, struct compstat *stats); - -/* - * Procedures exported to if_ppp.c. - */ -struct compressor ppp_bsd_compress = { - CI_BSD_COMPRESS, /* compress_proto */ - bsd_comp_alloc, /* comp_alloc */ - bsd_free, /* comp_free */ - bsd_comp_init, /* comp_init */ - bsd_reset, /* comp_reset */ - bsd_compress, /* compress */ - bsd_comp_stats, /* comp_stat */ - bsd_decomp_alloc, /* decomp_alloc */ - bsd_free, /* decomp_free */ - bsd_decomp_init, /* decomp_init */ - bsd_reset, /* decomp_reset */ - bsd_decompress, /* decompress */ - bsd_incomp, /* incomp */ - bsd_comp_stats, /* decomp_stat */ -}; - -/* - * the next two codes should not be changed lightly, as they must not - * lie within the contiguous general code space. - */ -#define CLEAR 256 /* table clear output code */ -#define FIRST 257 /* first free entry */ -#define LAST 255 - -#define MAXCODE(b) ((1 << (b)) - 1) -#define BADCODEM1 MAXCODE(BSD_MAX_BITS) - -#define BSD_HASH(prefix,suffix,hshift) ((((u_int32_t)(suffix)) << (hshift)) \ - ^ (u_int32_t)(prefix)) -#define BSD_KEY(prefix,suffix) ((((u_int32_t)(suffix)) << 16) \ - + (u_int32_t)(prefix)) - -#define CHECK_GAP 10000 /* Ratio check interval */ - -#define RATIO_SCALE_LOG 8 -#define RATIO_SCALE (1<<RATIO_SCALE_LOG) -#define RATIO_MAX (0x7fffffff>>RATIO_SCALE_LOG) - -/* - * clear the dictionary - */ -static void -bsd_clear(db) - struct bsd_db *db; -{ - db->clear_count++; - db->max_ent = FIRST-1; - db->n_bits = BSD_INIT_BITS; - db->ratio = 0; - db->bytes_out = 0; - db->in_count = 0; - db->checkpoint = CHECK_GAP; -} - -/* - * If the dictionary is full, then see if it is time to reset it. - * - * Compute the compression ratio using fixed-point arithmetic - * with 8 fractional bits. - * - * Since we have an infinite stream instead of a single file, - * watch only the local compression ratio. - * - * Since both peers must reset the dictionary at the same time even in - * the absence of CLEAR codes (while packets are incompressible), they - * must compute the same ratio. - */ -static int /* 1=output CLEAR */ -bsd_check(db) - struct bsd_db *db; -{ - u_int new_ratio; - - if (db->in_count >= db->checkpoint) { - /* age the ratio by limiting the size of the counts */ - if (db->in_count >= RATIO_MAX - || db->bytes_out >= RATIO_MAX) { - db->in_count -= db->in_count/4; - db->bytes_out -= db->bytes_out/4; - } - - db->checkpoint = db->in_count + CHECK_GAP; - - if (db->max_ent >= db->maxmaxcode) { - /* Reset the dictionary only if the ratio is worse, - * or if it looks as if it has been poisoned - * by incompressible data. - * - * This does not overflow, because - * db->in_count <= RATIO_MAX. - */ - new_ratio = db->in_count << RATIO_SCALE_LOG; - if (db->bytes_out != 0) - new_ratio /= db->bytes_out; - - if (new_ratio < db->ratio || new_ratio < 1 * RATIO_SCALE) { - bsd_clear(db); - return 1; - } - db->ratio = new_ratio; - } - } - return 0; -} - -/* - * Return statistics. - */ -static void -bsd_comp_stats(state, stats) - void *state; - struct compstat *stats; -{ - struct bsd_db *db = (struct bsd_db *) state; - u_int out; - - stats->unc_bytes = db->uncomp_bytes; - stats->unc_packets = db->uncomp_count; - stats->comp_bytes = db->comp_bytes; - stats->comp_packets = db->comp_count; - stats->inc_bytes = db->incomp_bytes; - stats->inc_packets = db->incomp_count; - stats->ratio = db->in_count; - out = db->bytes_out; - if (stats->ratio <= 0x7fffff) - stats->ratio <<= 8; - else - out >>= 8; - if (out != 0) - stats->ratio /= out; -} - -/* - * Reset state, as on a CCP ResetReq. - */ -static void -bsd_reset(state) - void *state; -{ - struct bsd_db *db = (struct bsd_db *) state; - - db->seqno = 0; - bsd_clear(db); - db->clear_count = 0; -} - -/* - * Allocate space for a (de) compressor. - */ -static void * -bsd_alloc(options, opt_len, decomp) - u_char *options; - int opt_len, decomp; -{ - int bits; - u_int newlen, hsize, hshift, maxmaxcode; - struct bsd_db *db; - - if (opt_len < CILEN_BSD_COMPRESS || options[0] != CI_BSD_COMPRESS - || options[1] != CILEN_BSD_COMPRESS - || BSD_VERSION(options[2]) != BSD_CURRENT_VERSION) - return NULL; - bits = BSD_NBITS(options[2]); - switch (bits) { - case 9: /* needs 82152 for both directions */ - case 10: /* needs 84144 */ - case 11: /* needs 88240 */ - case 12: /* needs 96432 */ - hsize = 5003; - hshift = 4; - break; - case 13: /* needs 176784 */ - hsize = 9001; - hshift = 5; - break; - case 14: /* needs 353744 */ - hsize = 18013; - hshift = 6; - break; - case 15: /* needs 691440 */ - hsize = 35023; - hshift = 7; - break; - case 16: /* needs 1366160--far too much, */ - /* hsize = 69001; */ /* and 69001 is too big for cptr */ - /* hshift = 8; */ /* in struct bsd_db */ - /* break; */ - default: - return NULL; - } - - maxmaxcode = MAXCODE(bits); - newlen = sizeof(*db) + (hsize-1) * (sizeof(db->dict[0])); - db = malloc(newlen, M_DEVBUF, M_NOWAIT); - if (!db) - return NULL; - bzero(db, sizeof(*db) - sizeof(db->dict)); - - if (!decomp) { - db->lens = NULL; - } else { - db->lens = malloc((maxmaxcode+1) * sizeof(db->lens[0]), - M_DEVBUF, M_NOWAIT); - if (!db->lens) { - free(db, M_DEVBUF); - return NULL; - } - } - - db->totlen = newlen; - db->hsize = hsize; - db->hshift = hshift; - db->maxmaxcode = maxmaxcode; - db->maxbits = bits; - - return (void *) db; -} - -static void -bsd_free(state) - void *state; -{ - struct bsd_db *db = (struct bsd_db *) state; - - if (db->lens) - free(db->lens, M_DEVBUF); - free(db, M_DEVBUF); -} - -static void * -bsd_comp_alloc(options, opt_len) - u_char *options; - int opt_len; -{ - return bsd_alloc(options, opt_len, 0); -} - -static void * -bsd_decomp_alloc(options, opt_len) - u_char *options; - int opt_len; -{ - return bsd_alloc(options, opt_len, 1); -} - -/* - * Initialize the database. - */ -static int -bsd_init(db, options, opt_len, unit, hdrlen, mru, debug, decomp) - struct bsd_db *db; - u_char *options; - int opt_len, unit, hdrlen, mru, debug, decomp; -{ - int i; - - if (opt_len < CILEN_BSD_COMPRESS || options[0] != CI_BSD_COMPRESS - || options[1] != CILEN_BSD_COMPRESS - || BSD_VERSION(options[2]) != BSD_CURRENT_VERSION - || BSD_NBITS(options[2]) != db->maxbits - || (decomp && db->lens == NULL)) - return 0; - - if (decomp) { - i = LAST+1; - while (i != 0) - db->lens[--i] = 1; - } - i = db->hsize; - while (i != 0) { - db->dict[--i].codem1 = BADCODEM1; - db->dict[i].cptr = 0; - } - - db->unit = unit; - db->hdrlen = hdrlen; - db->mru = mru; -#ifndef DEBUG - if (debug) -#endif - db->debug = 1; - - bsd_reset(db); - - return 1; -} - -static int -bsd_comp_init(state, options, opt_len, unit, hdrlen, debug) - void *state; - u_char *options; - int opt_len, unit, hdrlen, debug; -{ - return bsd_init((struct bsd_db *) state, options, opt_len, - unit, hdrlen, 0, debug, 0); -} - -static int -bsd_decomp_init(state, options, opt_len, unit, hdrlen, mru, debug) - void *state; - u_char *options; - int opt_len, unit, hdrlen, mru, debug; -{ - return bsd_init((struct bsd_db *) state, options, opt_len, - unit, hdrlen, mru, debug, 1); -} - - -/* - * compress a packet - * One change from the BSD compress command is that when the - * code size expands, we do not output a bunch of padding. - */ -static int /* new slen */ -bsd_compress(state, mret, mp, slen, maxolen) - void *state; - struct mbuf **mret; /* return compressed mbuf chain here */ - struct mbuf *mp; /* from here */ - int slen; /* uncompressed length */ - int maxolen; /* max compressed length */ -{ - struct bsd_db *db = (struct bsd_db *) state; - int hshift = db->hshift; - u_int max_ent = db->max_ent; - u_int n_bits = db->n_bits; - u_int bitno = 32; - u_int32_t accm = 0, fcode; - struct bsd_dict *dictp; - u_char c; - int hval, disp, ent, ilen; - u_char *rptr, *wptr; - u_char *cp_end; - int olen; - struct mbuf *m; - -#define PUTBYTE(v) { \ - ++olen; \ - if (wptr) { \ - *wptr++ = (v); \ - if (wptr >= cp_end) { \ - m->m_len = wptr - mtod(m, u_char *); \ - MGET(m->m_next, M_DONTWAIT, MT_DATA); \ - m = m->m_next; \ - if (m) { \ - m->m_len = 0; \ - if (maxolen - olen > MLEN) \ - MCLGET(m, M_DONTWAIT); \ - wptr = mtod(m, u_char *); \ - cp_end = wptr + M_TRAILINGSPACE(m); \ - } else \ - wptr = NULL; \ - } \ - } \ -} - -#define OUTPUT(ent) { \ - bitno -= n_bits; \ - accm |= ((ent) << bitno); \ - do { \ - PUTBYTE(accm >> 24); \ - accm <<= 8; \ - bitno += 8; \ - } while (bitno <= 24); \ -} - - /* - * If the protocol is not in the range we're interested in, - * just return without compressing the packet. If it is, - * the protocol becomes the first byte to compress. - */ - rptr = mtod(mp, u_char *); - ent = PPP_PROTOCOL(rptr); - if (ent < 0x21 || ent > 0xf9) { - *mret = NULL; - return slen; - } - - /* Don't generate compressed packets which are larger than - the uncompressed packet. */ - if (maxolen > slen) - maxolen = slen; - - /* Allocate one mbuf to start with. */ - MGET(m, M_DONTWAIT, MT_DATA); - *mret = m; - if (m != NULL) { - m->m_len = 0; - if (maxolen + db->hdrlen > MLEN) - MCLGET(m, M_DONTWAIT); - m->m_data += db->hdrlen; - wptr = mtod(m, u_char *); - cp_end = wptr + M_TRAILINGSPACE(m); - } else - wptr = cp_end = NULL; - - /* - * Copy the PPP header over, changing the protocol, - * and install the 2-byte packet sequence number. - */ - if (wptr) { - *wptr++ = PPP_ADDRESS(rptr); /* assumes the ppp header is */ - *wptr++ = PPP_CONTROL(rptr); /* all in one mbuf */ - *wptr++ = 0; /* change the protocol */ - *wptr++ = PPP_COMP; - *wptr++ = db->seqno >> 8; - *wptr++ = db->seqno; - } - ++db->seqno; - - olen = 0; - rptr += PPP_HDRLEN; - slen = mp->m_len - PPP_HDRLEN; - ilen = slen + 1; - for (;;) { - if (slen <= 0) { - mp = mp->m_next; - if (!mp) - break; - rptr = mtod(mp, u_char *); - slen = mp->m_len; - if (!slen) - continue; /* handle 0-length buffers */ - ilen += slen; - } - - slen--; - c = *rptr++; - fcode = BSD_KEY(ent, c); - hval = BSD_HASH(ent, c, hshift); - dictp = &db->dict[hval]; - - /* Validate and then check the entry. */ - if (dictp->codem1 >= max_ent) - goto nomatch; - if (dictp->f.fcode == fcode) { - ent = dictp->codem1+1; - continue; /* found (prefix,suffix) */ - } - - /* continue probing until a match or invalid entry */ - disp = (hval == 0) ? 1 : hval; - do { - hval += disp; - if (hval >= db->hsize) - hval -= db->hsize; - dictp = &db->dict[hval]; - if (dictp->codem1 >= max_ent) - goto nomatch; - } while (dictp->f.fcode != fcode); - ent = dictp->codem1 + 1; /* finally found (prefix,suffix) */ - continue; - - nomatch: - OUTPUT(ent); /* output the prefix */ - - /* code -> hashtable */ - if (max_ent < db->maxmaxcode) { - struct bsd_dict *dictp2; - /* expand code size if needed */ - if (max_ent >= MAXCODE(n_bits)) - db->n_bits = ++n_bits; - - /* Invalidate old hash table entry using - * this code, and then take it over. - */ - dictp2 = &db->dict[max_ent+1]; - if (db->dict[dictp2->cptr].codem1 == max_ent) - db->dict[dictp2->cptr].codem1 = BADCODEM1; - dictp2->cptr = hval; - dictp->codem1 = max_ent; - dictp->f.fcode = fcode; - - db->max_ent = ++max_ent; - } - ent = c; - } - - OUTPUT(ent); /* output the last code */ - db->bytes_out += olen; - db->in_count += ilen; - if (bitno < 32) - ++db->bytes_out; /* count complete bytes */ - - if (bsd_check(db)) - OUTPUT(CLEAR); /* do not count the CLEAR */ - - /* - * Pad dribble bits of last code with ones. - * Do not emit a completely useless byte of ones. - */ - if (bitno != 32) - PUTBYTE((accm | (0xff << (bitno-8))) >> 24); - - if (m != NULL) { - m->m_len = wptr - mtod(m, u_char *); - m->m_next = NULL; - } - - /* - * Increase code size if we would have without the packet - * boundary and as the decompressor will. - */ - if (max_ent >= MAXCODE(n_bits) && max_ent < db->maxmaxcode) - db->n_bits++; - - db->uncomp_bytes += ilen; - ++db->uncomp_count; - if (olen + PPP_HDRLEN + BSD_OVHD > maxolen) { - /* throw away the compressed stuff if it is longer than uncompressed */ - if (*mret != NULL) { - m_freem(*mret); - *mret = NULL; - } - ++db->incomp_count; - db->incomp_bytes += ilen; - } else { - ++db->comp_count; - db->comp_bytes += olen + BSD_OVHD; - } - - return olen + PPP_HDRLEN + BSD_OVHD; -#undef OUTPUT -#undef PUTBYTE -} - - -/* - * Update the "BSD Compress" dictionary on the receiver for - * incompressible data by pretending to compress the incoming data. - */ -static void -bsd_incomp(state, dmsg) - void *state; - struct mbuf *dmsg; -{ - struct bsd_db *db = (struct bsd_db *) state; - u_int hshift = db->hshift; - u_int max_ent = db->max_ent; - u_int n_bits = db->n_bits; - struct bsd_dict *dictp; - u_int32_t fcode; - u_char c; - u_int32_t hval, disp; - int slen, ilen; - u_int bitno = 7; - u_char *rptr; - u_int ent; - - /* - * If the protocol is not in the range we're interested in, - * just return without looking at the packet. If it is, - * the protocol becomes the first byte to "compress". - */ - rptr = mtod(dmsg, u_char *); - ent = PPP_PROTOCOL(rptr); - if (ent < 0x21 || ent > 0xf9) - return; - - db->seqno++; - ilen = 1; /* count the protocol as 1 byte */ - rptr += PPP_HDRLEN; - slen = dmsg->m_len - PPP_HDRLEN; - for (;;) { - if (slen <= 0) { - dmsg = dmsg->m_next; - if (!dmsg) - break; - rptr = mtod(dmsg, u_char *); - slen = dmsg->m_len; - continue; - } - ilen += slen; - - do { - c = *rptr++; - fcode = BSD_KEY(ent, c); - hval = BSD_HASH(ent, c, hshift); - dictp = &db->dict[hval]; - - /* validate and then check the entry */ - if (dictp->codem1 >= max_ent) - goto nomatch; - if (dictp->f.fcode == fcode) { - ent = dictp->codem1+1; - continue; /* found (prefix,suffix) */ - } - - /* continue probing until a match or invalid entry */ - disp = (hval == 0) ? 1 : hval; - do { - hval += disp; - if (hval >= db->hsize) - hval -= db->hsize; - dictp = &db->dict[hval]; - if (dictp->codem1 >= max_ent) - goto nomatch; - } while (dictp->f.fcode != fcode); - ent = dictp->codem1+1; - continue; /* finally found (prefix,suffix) */ - - nomatch: /* output (count) the prefix */ - bitno += n_bits; - - /* code -> hashtable */ - if (max_ent < db->maxmaxcode) { - struct bsd_dict *dictp2; - /* expand code size if needed */ - if (max_ent >= MAXCODE(n_bits)) - db->n_bits = ++n_bits; - - /* Invalidate previous hash table entry - * assigned this code, and then take it over. - */ - dictp2 = &db->dict[max_ent+1]; - if (db->dict[dictp2->cptr].codem1 == max_ent) - db->dict[dictp2->cptr].codem1 = BADCODEM1; - dictp2->cptr = hval; - dictp->codem1 = max_ent; - dictp->f.fcode = fcode; - - db->max_ent = ++max_ent; - db->lens[max_ent] = db->lens[ent]+1; - } - ent = c; - } while (--slen != 0); - } - bitno += n_bits; /* output (count) the last code */ - db->bytes_out += bitno/8; - db->in_count += ilen; - (void)bsd_check(db); - - ++db->incomp_count; - db->incomp_bytes += ilen; - ++db->uncomp_count; - db->uncomp_bytes += ilen; - - /* Increase code size if we would have without the packet - * boundary and as the decompressor will. - */ - if (max_ent >= MAXCODE(n_bits) && max_ent < db->maxmaxcode) - db->n_bits++; -} - - -/* - * Decompress "BSD Compress". - * - * Because of patent problems, we return DECOMP_ERROR for errors - * found by inspecting the input data and for system problems, but - * DECOMP_FATALERROR for any errors which could possibly be said to - * be being detected "after" decompression. For DECOMP_ERROR, - * we can issue a CCP reset-request; for DECOMP_FATALERROR, we may be - * infringing a patent of Motorola's if we do, so we take CCP down - * instead. - * - * Given that the frame has the correct sequence number and a good FCS, - * errors such as invalid codes in the input most likely indicate a - * bug, so we return DECOMP_FATALERROR for them in order to turn off - * compression, even though they are detected by inspecting the input. - */ -static int -bsd_decompress(state, cmp, dmpp) - void *state; - struct mbuf *cmp, **dmpp; -{ - struct bsd_db *db = (struct bsd_db *) state; - u_int max_ent = db->max_ent; - u_int32_t accm = 0; - u_int bitno = 32; /* 1st valid bit in accm */ - u_int n_bits = db->n_bits; - u_int tgtbitno = 32-n_bits; /* bitno when we have a code */ - struct bsd_dict *dictp; - int explen, i, seq, len; - u_int incode, oldcode, finchar; - u_char *p, *rptr, *wptr; - struct mbuf *m, *dmp, *mret; - int adrs, ctrl, ilen; - int space, codelen, extra; - - /* - * Save the address/control from the PPP header - * and then get the sequence number. - */ - *dmpp = NULL; - rptr = mtod(cmp, u_char *); - adrs = PPP_ADDRESS(rptr); - ctrl = PPP_CONTROL(rptr); - rptr += PPP_HDRLEN; - len = cmp->m_len - PPP_HDRLEN; - seq = 0; - for (i = 0; i < 2; ++i) { - while (len <= 0) { - cmp = cmp->m_next; - if (cmp == NULL) - return DECOMP_ERROR; - rptr = mtod(cmp, u_char *); - len = cmp->m_len; - } - seq = (seq << 8) + *rptr++; - --len; - } - - /* - * Check the sequence number and give up if it differs from - * the value we're expecting. - */ - if (seq != db->seqno) { - if (db->debug) - printf("bsd_decomp%d: bad sequence # %d, expected %d\n", - db->unit, seq, db->seqno - 1); - return DECOMP_ERROR; - } - ++db->seqno; - - /* - * Allocate one mbuf to start with. - */ - MGETHDR(dmp, M_DONTWAIT, MT_DATA); - if (dmp == NULL) - return DECOMP_ERROR; - mret = dmp; - dmp->m_len = 0; - dmp->m_next = NULL; - MCLGET(dmp, M_DONTWAIT); - dmp->m_data += db->hdrlen; - wptr = mtod(dmp, u_char *); - space = M_TRAILINGSPACE(dmp) - PPP_HDRLEN + 1; -#ifdef MAC - mac_mbuf_copy(cmp, dmp); -#endif - - /* - * Fill in the ppp header, but not the last byte of the protocol - * (that comes from the decompressed data). - */ - wptr[0] = adrs; - wptr[1] = ctrl; - wptr[2] = 0; - wptr += PPP_HDRLEN - 1; - - ilen = len; - oldcode = CLEAR; - explen = 0; - for (;;) { - if (len == 0) { - cmp = cmp->m_next; - if (!cmp) /* quit at end of message */ - break; - rptr = mtod(cmp, u_char *); - len = cmp->m_len; - ilen += len; - continue; /* handle 0-length buffers */ - } - - /* - * Accumulate bytes until we have a complete code. - * Then get the next code, relying on the 32-bit, - * unsigned accm to mask the result. - */ - bitno -= 8; - accm |= *rptr++ << bitno; - --len; - if (tgtbitno < bitno) - continue; - incode = accm >> tgtbitno; - accm <<= n_bits; - bitno += n_bits; - - if (incode == CLEAR) { - /* - * The dictionary must only be cleared at - * the end of a packet. But there could be an - * empty mbuf at the end. - */ - if (len > 0 || cmp->m_next != NULL) { - while ((cmp = cmp->m_next) != NULL) - len += cmp->m_len; - if (len > 0) { - m_freem(mret); - if (db->debug) - printf("bsd_decomp%d: bad CLEAR\n", db->unit); - return DECOMP_FATALERROR; /* probably a bug */ - } - } - bsd_clear(db); - explen = ilen = 0; - break; - } - - if (incode > max_ent + 2 || incode > db->maxmaxcode - || (incode > max_ent && oldcode == CLEAR)) { - m_freem(mret); - if (db->debug) { - printf("bsd_decomp%d: bad code 0x%x oldcode=0x%x ", - db->unit, incode, oldcode); - printf("max_ent=0x%x explen=%d seqno=%d\n", - max_ent, explen, db->seqno); - } - return DECOMP_FATALERROR; /* probably a bug */ - } - - /* Special case for KwKwK string. */ - if (incode > max_ent) { - finchar = oldcode; - extra = 1; - } else { - finchar = incode; - extra = 0; - } - - codelen = db->lens[finchar]; - explen += codelen + extra; - if (explen > db->mru + 1) { - m_freem(mret); - if (db->debug) { - printf("bsd_decomp%d: ran out of mru\n", db->unit); -#ifdef DEBUG - while ((cmp = cmp->m_next) != NULL) - len += cmp->m_len; - printf(" len=%d, finchar=0x%x, codelen=%d, explen=%d\n", - len, finchar, codelen, explen); -#endif - } - return DECOMP_FATALERROR; - } - - /* - * For simplicity, the decoded characters go in a single mbuf, - * so we allocate a single extra cluster mbuf if necessary. - */ - if ((space -= codelen + extra) < 0) { - dmp->m_len = wptr - mtod(dmp, u_char *); - MGET(m, M_DONTWAIT, MT_DATA); - if (m == NULL) { - m_freem(mret); - return DECOMP_ERROR; - } - m->m_len = 0; - m->m_next = NULL; - dmp->m_next = m; - MCLGET(m, M_DONTWAIT); - space = M_TRAILINGSPACE(m) - (codelen + extra); - if (space < 0) { - /* now that's what I call *compression*. */ - m_freem(mret); - return DECOMP_ERROR; - } - dmp = m; - wptr = mtod(dmp, u_char *); - } - - /* - * Decode this code and install it in the decompressed buffer. - */ - p = (wptr += codelen); - while (finchar > LAST) { - dictp = &db->dict[db->dict[finchar].cptr]; -#ifdef DEBUG - if (--codelen <= 0 || dictp->codem1 != finchar-1) - goto bad; -#endif - *--p = dictp->f.hs.suffix; - finchar = dictp->f.hs.prefix; - } - *--p = finchar; - -#ifdef DEBUG - if (--codelen != 0) - printf("bsd_decomp%d: short by %d after code 0x%x, max_ent=0x%x\n", - db->unit, codelen, incode, max_ent); -#endif - - if (extra) /* the KwKwK case again */ - *wptr++ = finchar; - - /* - * If not first code in a packet, and - * if not out of code space, then allocate a new code. - * - * Keep the hash table correct so it can be used - * with uncompressed packets. - */ - if (oldcode != CLEAR && max_ent < db->maxmaxcode) { - struct bsd_dict *dictp2; - u_int32_t fcode; - u_int32_t hval, disp; - - fcode = BSD_KEY(oldcode,finchar); - hval = BSD_HASH(oldcode,finchar,db->hshift); - dictp = &db->dict[hval]; - - /* look for a free hash table entry */ - if (dictp->codem1 < max_ent) { - disp = (hval == 0) ? 1 : hval; - do { - hval += disp; - if (hval >= db->hsize) - hval -= db->hsize; - dictp = &db->dict[hval]; - } while (dictp->codem1 < max_ent); - } - - /* - * Invalidate previous hash table entry - * assigned this code, and then take it over - */ - dictp2 = &db->dict[max_ent+1]; - if (db->dict[dictp2->cptr].codem1 == max_ent) { - db->dict[dictp2->cptr].codem1 = BADCODEM1; - } - dictp2->cptr = hval; - dictp->codem1 = max_ent; - dictp->f.fcode = fcode; - - db->max_ent = ++max_ent; - db->lens[max_ent] = db->lens[oldcode]+1; - - /* Expand code size if needed. */ - if (max_ent >= MAXCODE(n_bits) && max_ent < db->maxmaxcode) { - db->n_bits = ++n_bits; - tgtbitno = 32-n_bits; - } - } - oldcode = incode; - } - dmp->m_len = wptr - mtod(dmp, u_char *); - - /* - * Keep the checkpoint right so that incompressible packets - * clear the dictionary at the right times. - */ - db->bytes_out += ilen; - db->in_count += explen; - if (bsd_check(db) && db->debug) { - printf("bsd_decomp%d: peer should have cleared dictionary\n", - db->unit); - } - - ++db->comp_count; - db->comp_bytes += ilen + BSD_OVHD; - ++db->uncomp_count; - db->uncomp_bytes += explen; - - *dmpp = mret; - return DECOMP_OK; - -#ifdef DEBUG - bad: - if (codelen <= 0) { - printf("bsd_decomp%d: fell off end of chain ", db->unit); - printf("0x%x at 0x%x by 0x%x, max_ent=0x%x\n", - incode, finchar, db->dict[finchar].cptr, max_ent); - } else if (dictp->codem1 != finchar-1) { - printf("bsd_decomp%d: bad code chain 0x%x finchar=0x%x ", - db->unit, incode, finchar); - printf("oldcode=0x%x cptr=0x%x codem1=0x%x\n", oldcode, - db->dict[finchar].cptr, dictp->codem1); - } - m_freem(mret); - return DECOMP_FATALERROR; -#endif /* DEBUG */ -} diff --git a/sys/net/if_ppp.c b/sys/net/if_ppp.c deleted file mode 100644 index 753adf9..0000000 --- a/sys/net/if_ppp.c +++ /dev/null @@ -1,1733 +0,0 @@ -/* - * if_ppp.c - Point-to-Point Protocol (PPP) Asynchronous driver. - */ - -/*- - * Copyright (c) 1989 Carnegie Mellon University. - * All rights reserved. - * - * Redistribution and use in source and binary forms are permitted - * provided that the above copyright notice and this paragraph are - * duplicated in all such forms and that any documentation, - * advertising materials, and other materials related to such - * distribution and use acknowledge that the software was developed - * by Carnegie Mellon University. The name of the - * University may not be used to endorse or promote products derived - * from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * Drew D. Perkins - * Carnegie Mellon University - * 4910 Forbes Ave. - * Pittsburgh, PA 15213 - * (412) 268-8576 - * ddp@andrew.cmu.edu - * - * Based on: - * @(#)if_sl.c 7.6.1.2 (Berkeley) 2/15/89 - * - * Copyright (c) 1987 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms are permitted - * provided that the above copyright notice and this paragraph are - * duplicated in all such forms and that any documentation, - * advertising materials, and other materials related to such - * distribution and use acknowledge that the software was developed - * by the University of California, Berkeley. The name of the - * University may not be used to endorse or promote products derived - * from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * Serial Line interface - * - * Rick Adams - * Center for Seismic Studies - * 1300 N 17th Street, Suite 1450 - * Arlington, Virginia 22209 - * (703)276-7900 - * rick@seismo.ARPA - * seismo!rick - * - * Pounded on heavily by Chris Torek (chris@mimsy.umd.edu, umcp-cs!chris). - * Converted to 4.3BSD Beta by Chris Torek. - * Other changes made at Berkeley, based in part on code by Kirk Smith. - * - * Converted to 4.3BSD+ 386BSD by Brad Parker (brad@cayman.com) - * Added VJ tcp header compression; more unified ioctls - * - * Extensively modified by Paul Mackerras (paulus@cs.anu.edu.au). - * Cleaned up a lot of the mbuf-related code to fix bugs that - * caused system crashes and packet corruption. Changed pppstart - * so that it doesn't just give up with a collision if the whole - * packet doesn't fit in the output ring buffer. - * - * Added priority queueing for interactive IP packets, following - * the model of if_sl.c, plus hooks for bpf. - * Paul Mackerras (paulus@cs.anu.edu.au). - */ - -/* $FreeBSD$ */ -/* from if_sl.c,v 1.11 84/10/04 12:54:47 rick Exp */ -/* from NetBSD: if_ppp.c,v 1.15.2.2 1994/07/28 05:17:58 cgd Exp */ - -#include "opt_inet.h" -#include "opt_inet6.h" -#include "opt_ipx.h" -#include "opt_mac.h" -#include "opt_ppp.h" - -#ifdef INET -#define VJC -#endif -#define PPP_COMPRESS - -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/priv.h> -#include <sys/proc.h> -#include <sys/mbuf.h> -#include <sys/socket.h> -#include <sys/filio.h> -#include <sys/sockio.h> -#include <sys/kernel.h> -#include <sys/time.h> -#include <sys/malloc.h> -#include <sys/module.h> - -#include <net/if.h> -#include <net/if_clone.h> -#include <net/if_types.h> -#include <net/netisr.h> -#include <net/bpf.h> - -#ifdef INET -#include <netinet/in.h> -#include <netinet/in_systm.h> -#include <netinet/in_var.h> -#include <netinet/ip.h> -#endif - -#ifdef IPX -#include <netipx/ipx.h> -#include <netipx/ipx_if.h> -#endif - -#ifdef VJC -#include <net/slcompress.h> -#endif - -#include <net/if_ppp.h> -#include <net/if_pppvar.h> - -#include <security/mac/mac_framework.h> - -/* minimise diffs */ -#ifndef splsoftnet -#define splsoftnet splnet -#endif - -#ifdef PPP_COMPRESS -#define PACKETPTR struct mbuf * -#include <net/ppp_comp.h> -#endif - -#define PPPNAME "ppp" -static MALLOC_DEFINE(M_PPP, PPPNAME, "PPP interface"); - -static struct mtx ppp_softc_list_mtx; -static LIST_HEAD(, ppp_softc) ppp_softc_list; - -#define PPP_LIST_LOCK_INIT() mtx_init(&ppp_softc_list_mtx, \ - "ppp_softc_list_mtx", NULL, MTX_DEF) -#define PPP_LIST_LOCK_DESTROY() mtx_destroy(&ppp_softc_list_mtx) -#define PPP_LIST_LOCK() mtx_lock(&ppp_softc_list_mtx) -#define PPP_LIST_UNLOCK() mtx_unlock(&ppp_softc_list_mtx) - -/* XXX layering violation */ -extern void pppasyncattach(void *); -extern void pppasyncdetach(void); - -static int pppsioctl(struct ifnet *ifp, u_long cmd, caddr_t data); -static void pppintr(void); - -static void ppp_requeue(struct ppp_softc *); -static void ppp_ccp(struct ppp_softc *, struct mbuf *m, int rcvd); -static void ppp_ccp_closed(struct ppp_softc *); -static void ppp_inproc(struct ppp_softc *, struct mbuf *); -static void pppdumpm(struct mbuf *m0); -static int ppp_clone_create(struct if_clone *, int, caddr_t); -static void ppp_clone_destroy(struct ifnet *); - -IFC_SIMPLE_DECLARE(ppp, 0); - -/* - * Some useful mbuf macros not in mbuf.h. - */ -#define M_IS_CLUSTER(m) ((m)->m_flags & M_EXT) - -#define M_DATASTART(m) \ - (M_IS_CLUSTER(m) ? (m)->m_ext.ext_buf : \ - (m)->m_flags & M_PKTHDR ? (m)->m_pktdat : (m)->m_dat) - -#define M_DATASIZE(m) \ - (M_IS_CLUSTER(m) ? (m)->m_ext.ext_size : \ - (m)->m_flags & M_PKTHDR ? MHLEN: MLEN) - -/* - * We steal two bits in the mbuf m_flags, to mark high-priority packets - * for output, and received packets following lost/corrupted packets. - */ -#define M_HIGHPRI 0x2000 /* output packet for sc_fastq */ -#define M_ERRMARK 0x4000 /* steal a bit in mbuf m_flags */ - - -#ifdef PPP_COMPRESS -/* - * List of compressors we know about. - * We leave some space so maybe we can modload compressors. - */ - -extern struct compressor ppp_bsd_compress; -extern struct compressor ppp_deflate, ppp_deflate_draft; - -static struct compressor *ppp_compressors[8] = { -#if defined(PPP_BSDCOMP) - &ppp_bsd_compress, -#endif -#if defined(PPP_DEFLATE) - &ppp_deflate, - &ppp_deflate_draft, -#endif - NULL -}; -#endif /* PPP_COMPRESS */ - -static int -ppp_clone_create(struct if_clone *ifc, int unit, caddr_t params) -{ - struct ifnet *ifp; - struct ppp_softc *sc; - - sc = malloc(sizeof(struct ppp_softc), M_PPP, M_WAITOK | M_ZERO); - ifp = sc->sc_ifp = if_alloc(IFT_PPP); - if (ifp == NULL) { - free(sc, M_PPP); - return (ENOSPC); - } - - callout_init(&sc->sc_timo_ch, 0); - ifp->if_softc = sc; - if_initname(ifp, ifc->ifc_name, unit); - ifp->if_mtu = PPP_MTU; - ifp->if_flags = IFF_POINTOPOINT | IFF_MULTICAST | IFF_NEEDSGIANT; - ifp->if_hdrlen = PPP_HDRLEN; - ifp->if_ioctl = pppsioctl; - ifp->if_output = pppoutput; - ifp->if_snd.ifq_maxlen = IFQ_MAXLEN; - sc->sc_inq.ifq_maxlen = IFQ_MAXLEN; - sc->sc_fastq.ifq_maxlen = IFQ_MAXLEN; - sc->sc_rawq.ifq_maxlen = IFQ_MAXLEN; - mtx_init(&sc->sc_inq.ifq_mtx, "ppp_inq", NULL, MTX_DEF); - mtx_init(&sc->sc_fastq.ifq_mtx, "ppp_fastq", NULL, MTX_DEF); - mtx_init(&sc->sc_rawq.ifq_mtx, "ppp_rawq", NULL, MTX_DEF); - if_attach(ifp); - bpfattach(ifp, DLT_PPP, PPP_HDRLEN); - - PPP_LIST_LOCK(); - LIST_INSERT_HEAD(&ppp_softc_list, sc, sc_list); - PPP_LIST_UNLOCK(); - - return (0); -} - -static void -ppp_clone_destroy(struct ifnet *ifp) -{ - struct ppp_softc *sc; - - sc = ifp->if_softc; - PPP_LIST_LOCK(); - LIST_REMOVE(sc, sc_list); - PPP_LIST_UNLOCK(); - - bpfdetach(ifp); - if_detach(ifp); - if_free(ifp); - mtx_destroy(&sc->sc_rawq.ifq_mtx); - mtx_destroy(&sc->sc_fastq.ifq_mtx); - mtx_destroy(&sc->sc_inq.ifq_mtx); - free(sc, M_PPP); -} - -static int -ppp_modevent(module_t mod, int type, void *data) -{ - - switch (type) { - case MOD_LOAD: - PPP_LIST_LOCK_INIT(); - LIST_INIT(&ppp_softc_list); - if_clone_attach(&ppp_cloner); - - netisr_register(NETISR_PPP, (netisr_t *)pppintr, NULL, - NETISR_FORCEQUEUE); - /* - * XXX layering violation - if_ppp can work over any lower - * level transport that cares to attach to it. - */ - pppasyncattach(NULL); - break; - case MOD_UNLOAD: - /* XXX: layering violation */ - pppasyncdetach(); - - netisr_unregister(NETISR_PPP); - - if_clone_detach(&ppp_cloner); - PPP_LIST_LOCK_DESTROY(); - break; - default: - return EOPNOTSUPP; - } - return 0; -} - -static moduledata_t ppp_mod = { - "if_ppp", - ppp_modevent, - 0 -}; - -DECLARE_MODULE(if_ppp, ppp_mod, SI_SUB_PSEUDO, SI_ORDER_ANY); - -/* - * Allocate a ppp interface unit and initialize it. - */ -struct ppp_softc * -pppalloc(pid) - pid_t pid; -{ - int i; - char tmpname[IFNAMSIZ]; - struct ifnet *ifp; - struct ppp_softc *sc; - - PPP_LIST_LOCK(); - LIST_FOREACH(sc, &ppp_softc_list, sc_list) { - if (sc->sc_xfer == pid) { - sc->sc_xfer = 0; - PPP_LIST_UNLOCK(); - return sc; - } - } - LIST_FOREACH(sc, &ppp_softc_list, sc_list) { - if (sc->sc_devp == NULL) - break; - } - PPP_LIST_UNLOCK(); - /* Try to clone an interface if we don't have a free one */ - if (sc == NULL) { - strcpy(tmpname, PPPNAME); - if (if_clone_create(tmpname, sizeof(tmpname), (caddr_t) 0) != 0) - return NULL; - ifp = ifunit(tmpname); - if (ifp == NULL) - return NULL; - sc = ifp->if_softc; - } - if (sc == NULL || sc->sc_devp != NULL) - return NULL; - - sc->sc_flags = 0; - sc->sc_mru = PPP_MRU; - sc->sc_relinq = NULL; - bzero((char *)&sc->sc_stats, sizeof(sc->sc_stats)); -#ifdef VJC - sc->sc_comp = malloc(sizeof(struct slcompress), - M_DEVBUF, M_NOWAIT); - if (sc->sc_comp) - sl_compress_init(sc->sc_comp, -1); -#endif -#ifdef PPP_COMPRESS - sc->sc_xc_state = NULL; - sc->sc_rc_state = NULL; -#endif /* PPP_COMPRESS */ - for (i = 0; i < NUM_NP; ++i) - sc->sc_npmode[i] = NPMODE_ERROR; - sc->sc_npqueue = NULL; - sc->sc_npqtail = &sc->sc_npqueue; - sc->sc_last_sent = sc->sc_last_recv = time_uptime; - - return sc; -} - -/* - * Deallocate a ppp unit. Must be called at splsoftnet or higher. - */ -void -pppdealloc(sc) - struct ppp_softc *sc; -{ - struct mbuf *m; - - if_down(PPP2IFP(sc)); - PPP2IFP(sc)->if_flags &= ~IFF_UP; - PPP2IFP(sc)->if_drv_flags &= ~IFF_DRV_RUNNING; - getmicrotime(&PPP2IFP(sc)->if_lastchange); - sc->sc_devp = NULL; - sc->sc_xfer = 0; - IF_DRAIN(&sc->sc_rawq); - IF_DRAIN(&sc->sc_inq); - IF_DRAIN(&sc->sc_fastq); - while ((m = sc->sc_npqueue) != NULL) { - sc->sc_npqueue = m->m_nextpkt; - m_freem(m); - } -#ifdef PPP_COMPRESS - ppp_ccp_closed(sc); - sc->sc_xc_state = NULL; - sc->sc_rc_state = NULL; -#endif /* PPP_COMPRESS */ -#ifdef PPP_FILTER - if (sc->sc_pass_filt.bf_insns != 0) { - free(sc->sc_pass_filt.bf_insns, M_DEVBUF); - sc->sc_pass_filt.bf_insns = 0; - sc->sc_pass_filt.bf_len = 0; - } - if (sc->sc_active_filt.bf_insns != 0) { - free(sc->sc_active_filt.bf_insns, M_DEVBUF); - sc->sc_active_filt.bf_insns = 0; - sc->sc_active_filt.bf_len = 0; - } -#endif /* PPP_FILTER */ -#ifdef VJC - if (sc->sc_comp != 0) { - free(sc->sc_comp, M_DEVBUF); - sc->sc_comp = 0; - } -#endif -} - -/* - * Ioctl routine for generic ppp devices. - */ -int -pppioctl(sc, cmd, data, flag, td) - struct ppp_softc *sc; - u_long cmd; - caddr_t data; - int flag; - struct thread *td; -{ - struct proc *p = td->td_proc; - int s, flags, mru, npx; - u_int nb; - int error = 0; - struct ppp_option_data *odp; - struct compressor **cp; - struct npioctl *npi; - time_t t; -#ifdef PPP_FILTER - struct bpf_program *bp, *nbp; - struct bpf_insn *newcode, *oldcode; - int newcodelen; -#endif /* PPP_FILTER */ -#ifdef PPP_COMPRESS - u_char ccp_option[CCP_MAX_OPTION_LENGTH]; -#endif - - switch (cmd) { - case FIONREAD: - *(int *)data = sc->sc_inq.ifq_len; - break; - - case PPPIOCGUNIT: - *(int *)data = PPP2IFP(sc)->if_dunit; - break; - - case PPPIOCGFLAGS: - *(u_int *)data = sc->sc_flags; - break; - - case PPPIOCSFLAGS: - error = priv_check(td, PRIV_NET_PPP); - if (error) - break; - flags = *(int *)data & SC_MASK; - s = splsoftnet(); -#ifdef PPP_COMPRESS - if (sc->sc_flags & SC_CCP_OPEN && !(flags & SC_CCP_OPEN)) - ppp_ccp_closed(sc); -#endif - splimp(); - sc->sc_flags = (sc->sc_flags & ~SC_MASK) | flags; - splx(s); - break; - - case PPPIOCSMRU: - error = priv_check(td, PRIV_NET_PPP); - if (error) - return (error); - mru = *(int *)data; - if (mru >= PPP_MRU && mru <= PPP_MAXMRU) - sc->sc_mru = mru; - break; - - case PPPIOCGMRU: - *(int *)data = sc->sc_mru; - break; - -#ifdef VJC - case PPPIOCSMAXCID: - error = priv_check(td, PRIV_NET_PPP); - if (error) - break; - if (sc->sc_comp) { - s = splsoftnet(); - sl_compress_init(sc->sc_comp, *(int *)data); - splx(s); - } - break; -#endif - - case PPPIOCXFERUNIT: - error = priv_check(td, PRIV_NET_PPP); - if (error) - break; - sc->sc_xfer = p->p_pid; - break; - -#ifdef PPP_COMPRESS - case PPPIOCSCOMPRESS: - error = priv_check(td, PRIV_NET_PPP); - if (error) - break; - odp = (struct ppp_option_data *) data; - nb = odp->length; - if (nb > sizeof(ccp_option)) - nb = sizeof(ccp_option); - if ((error = copyin(odp->ptr, ccp_option, nb)) != 0) - break; - if (ccp_option[1] < 2) { /* preliminary check on the length byte */ - error = EINVAL; - break; - } - for (cp = ppp_compressors; *cp != NULL; ++cp) - if ((*cp)->compress_proto == ccp_option[0]) { - /* - * Found a handler for the protocol - try to allocate - * a compressor or decompressor. - */ - error = 0; - if (odp->transmit) { - s = splsoftnet(); - if (sc->sc_xc_state != NULL) - (*sc->sc_xcomp->comp_free)(sc->sc_xc_state); - sc->sc_xcomp = *cp; - sc->sc_xc_state = (*cp)->comp_alloc(ccp_option, nb); - if (sc->sc_xc_state == NULL) { - if (sc->sc_flags & SC_DEBUG) - if_printf(PPP2IFP(sc), "comp_alloc failed\n"); - error = ENOBUFS; - } - splimp(); - sc->sc_flags &= ~SC_COMP_RUN; - splx(s); - } else { - s = splsoftnet(); - if (sc->sc_rc_state != NULL) - (*sc->sc_rcomp->decomp_free)(sc->sc_rc_state); - sc->sc_rcomp = *cp; - sc->sc_rc_state = (*cp)->decomp_alloc(ccp_option, nb); - if (sc->sc_rc_state == NULL) { - if (sc->sc_flags & SC_DEBUG) - if_printf(PPP2IFP(sc), "decomp_alloc failed\n"); - error = ENOBUFS; - } - splimp(); - sc->sc_flags &= ~SC_DECOMP_RUN; - splx(s); - } - return (error); - } - if (sc->sc_flags & SC_DEBUG) - if_printf(PPP2IFP(sc), "no compressor for [%x %x %x], %x\n", - ccp_option[0], ccp_option[1], ccp_option[2], nb); - error = EINVAL; /* no handler found */ - break; -#endif /* PPP_COMPRESS */ - - case PPPIOCGNPMODE: - case PPPIOCSNPMODE: - npi = (struct npioctl *) data; - npx = 0; /* XXX: quiet gcc */ - switch (npi->protocol) { - case PPP_IP: - npx = NP_IP; - break; - case PPP_IPV6: - npx = NP_IPV6; - break; - default: - error = EINVAL; - } - if (error) - break; - if (cmd == PPPIOCGNPMODE) { - npi->mode = sc->sc_npmode[npx]; - } else { - error = priv_check(td, PRIV_NET_PPP); - if (error) - break; - if (npi->mode != sc->sc_npmode[npx]) { - s = splsoftnet(); - sc->sc_npmode[npx] = npi->mode; - if (npi->mode != NPMODE_QUEUE) { - ppp_requeue(sc); - (*sc->sc_start)(sc); - } - splx(s); - } - } - break; - - case PPPIOCGIDLE: - s = splsoftnet(); - t = time_uptime; - ((struct ppp_idle *)data)->xmit_idle = t - sc->sc_last_sent; - ((struct ppp_idle *)data)->recv_idle = t - sc->sc_last_recv; - splx(s); - break; - -#ifdef PPP_FILTER - case PPPIOCSPASS: - case PPPIOCSACTIVE: - nbp = (struct bpf_program *) data; - if ((unsigned) nbp->bf_len > BPF_MAXINSNS) { - error = EINVAL; - break; - } - newcodelen = nbp->bf_len * sizeof(struct bpf_insn); - if (newcodelen != 0) { - newcode = malloc(newcodelen, M_DEVBUF, M_WAITOK); - if (newcode == 0) { - error = EINVAL; /* or sumpin */ - break; - } - if ((error = copyin((caddr_t)nbp->bf_insns, (caddr_t)newcode, - newcodelen)) != 0) { - free(newcode, M_DEVBUF); - break; - } - if (!bpf_validate(newcode, nbp->bf_len)) { - free(newcode, M_DEVBUF); - error = EINVAL; - break; - } - } else - newcode = 0; - bp = (cmd == PPPIOCSPASS)? &sc->sc_pass_filt: &sc->sc_active_filt; - oldcode = bp->bf_insns; - s = splimp(); - bp->bf_len = nbp->bf_len; - bp->bf_insns = newcode; - splx(s); - if (oldcode != 0) - free(oldcode, M_DEVBUF); - break; -#endif - - default: - error = ENOIOCTL; - break; - } - return (error); -} - -/* - * Process an ioctl request to the ppp network interface. - */ -static int -pppsioctl(ifp, cmd, data) - register struct ifnet *ifp; - u_long cmd; - caddr_t data; -{ - struct thread *td = curthread; /* XXX */ - register struct ppp_softc *sc = ifp->if_softc; - register struct ifaddr *ifa = (struct ifaddr *)data; - register struct ifreq *ifr = (struct ifreq *)data; - struct ppp_stats *psp; -#ifdef PPP_COMPRESS - struct ppp_comp_stats *pcp; -#endif - int s = splimp(), error = 0; - - switch (cmd) { - case SIOCSIFFLAGS: - if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) - ifp->if_flags &= ~IFF_UP; - break; - - case SIOCSIFADDR: - case SIOCAIFADDR: - switch(ifa->ifa_addr->sa_family) { -#ifdef INET - case AF_INET: - break; -#endif -#ifdef INET6 - case AF_INET6: - break; -#endif -#ifdef IPX - case AF_IPX: - break; -#endif - default: - error = EAFNOSUPPORT; - break; - } - break; - - case SIOCSIFDSTADDR: - switch(ifa->ifa_addr->sa_family) { -#ifdef INET - case AF_INET: - break; -#endif -#ifdef INET6 - case AF_INET6: - break; -#endif -#ifdef IPX - case AF_IPX: - break; -#endif - default: - error = EAFNOSUPPORT; - break; - } - break; - - case SIOCSIFMTU: - /* - * XXXRW: Isn't this priv_check() check redundant to the one at the - * ifnet layer? - */ - error = priv_check(td, PRIV_NET_SETIFMTU); - if (error) - break; - if (ifr->ifr_mtu > PPP_MAXMTU) - error = EINVAL; - else { - PPP2IFP(sc)->if_mtu = ifr->ifr_mtu; - if (sc->sc_setmtu) - (*sc->sc_setmtu)(sc); - } - break; - - case SIOCGIFMTU: - ifr->ifr_mtu = PPP2IFP(sc)->if_mtu; - break; - - case SIOCADDMULTI: - case SIOCDELMULTI: - if (ifr == 0) { - error = EAFNOSUPPORT; - break; - } - switch(ifr->ifr_addr.sa_family) { -#ifdef INET - case AF_INET: - break; -#endif -#ifdef INET6 - case AF_INET6: - break; -#endif - default: - error = EAFNOSUPPORT; - break; - } - break; - - case SIOCGPPPSTATS: - psp = &((struct ifpppstatsreq *) data)->stats; - bzero(psp, sizeof(*psp)); - psp->p = sc->sc_stats; -#if defined(VJC) && !defined(SL_NO_STATS) - if (sc->sc_comp) { - psp->vj.vjs_packets = sc->sc_comp->sls_packets; - psp->vj.vjs_compressed = sc->sc_comp->sls_compressed; - psp->vj.vjs_searches = sc->sc_comp->sls_searches; - psp->vj.vjs_misses = sc->sc_comp->sls_misses; - psp->vj.vjs_uncompressedin = sc->sc_comp->sls_uncompressedin; - psp->vj.vjs_compressedin = sc->sc_comp->sls_compressedin; - psp->vj.vjs_errorin = sc->sc_comp->sls_errorin; - psp->vj.vjs_tossed = sc->sc_comp->sls_tossed; - } -#endif /* VJC */ - break; - -#ifdef PPP_COMPRESS - case SIOCGPPPCSTATS: - pcp = &((struct ifpppcstatsreq *) data)->stats; - bzero(pcp, sizeof(*pcp)); - if (sc->sc_xc_state != NULL) - (*sc->sc_xcomp->comp_stat)(sc->sc_xc_state, &pcp->c); - if (sc->sc_rc_state != NULL) - (*sc->sc_rcomp->decomp_stat)(sc->sc_rc_state, &pcp->d); - break; -#endif /* PPP_COMPRESS */ - - default: - error = ENOTTY; - } - splx(s); - return (error); -} - -/* - * Queue a packet. Start transmission if not active. - * Packet is placed in Information field of PPP frame. - * Called at splnet as the if->if_output handler. - * Called at splnet from pppwrite(). - */ -int -pppoutput(ifp, m0, dst, rtp) - struct ifnet *ifp; - struct mbuf *m0; - struct sockaddr *dst; - struct rtentry *rtp; -{ - register struct ppp_softc *sc = ifp->if_softc; - int protocol, address, control; - u_char *cp; - int s, error; - struct ip *ip; - struct ifqueue *ifq; - enum NPmode mode; - int len; - -#ifdef MAC - error = mac_ifnet_check_transmit(ifp, m0); - if (error) - goto bad; -#endif - - if (sc->sc_devp == NULL || (ifp->if_drv_flags & IFF_DRV_RUNNING) == 0 - || ((ifp->if_flags & IFF_UP) == 0 && dst->sa_family != AF_UNSPEC)) { - error = ENETDOWN; /* sort of */ - goto bad; - } - - /* - * Compute PPP header. - */ - m0->m_flags &= ~M_HIGHPRI; - switch (dst->sa_family) { -#ifdef INET - case AF_INET: - address = PPP_ALLSTATIONS; - control = PPP_UI; - protocol = PPP_IP; - mode = sc->sc_npmode[NP_IP]; - - /* - * If this packet has the "low delay" bit set in the IP header, - * put it on the fastq instead. - */ - ip = mtod(m0, struct ip *); - if (ip->ip_tos & IPTOS_LOWDELAY) - m0->m_flags |= M_HIGHPRI; - break; -#endif -#ifdef INET6 - case AF_INET6: - address = PPP_ALLSTATIONS; /*XXX*/ - control = PPP_UI; /*XXX*/ - protocol = PPP_IPV6; - mode = sc->sc_npmode[NP_IPV6]; - -#if 0 /* XXX flowinfo/traffic class, maybe? */ - /* - * If this packet has the "low delay" bit set in the IP header, - * put it on the fastq instead. - */ - ip = mtod(m0, struct ip *); - if (ip->ip_tos & IPTOS_LOWDELAY) - m0->m_flags |= M_HIGHPRI; -#endif - break; -#endif -#ifdef IPX - case AF_IPX: - /* - * This is pretty bogus.. We dont have an ipxcp module in pppd - * yet to configure the link parameters. Sigh. I guess a - * manual ifconfig would do.... -Peter - */ - address = PPP_ALLSTATIONS; - control = PPP_UI; - protocol = PPP_IPX; - mode = NPMODE_PASS; - break; -#endif - case AF_UNSPEC: - address = PPP_ADDRESS(dst->sa_data); - control = PPP_CONTROL(dst->sa_data); - protocol = PPP_PROTOCOL(dst->sa_data); - mode = NPMODE_PASS; - break; - default: - if_printf(ifp, "af%d not supported\n", dst->sa_family); - error = EAFNOSUPPORT; - goto bad; - } - - /* - * Drop this packet, or return an error, if necessary. - */ - if (mode == NPMODE_ERROR) { - error = ENETDOWN; - goto bad; - } - if (mode == NPMODE_DROP) { - error = 0; - goto bad; - } - - /* - * Add PPP header. If no space in first mbuf, allocate another. - * (This assumes M_LEADINGSPACE is always 0 for a cluster mbuf.) - */ - if (M_LEADINGSPACE(m0) < PPP_HDRLEN) { - m0 = m_prepend(m0, PPP_HDRLEN, M_DONTWAIT); - if (m0 == 0) { - error = ENOBUFS; - goto bad; - } - m0->m_len = 0; - } else - m0->m_data -= PPP_HDRLEN; - - cp = mtod(m0, u_char *); - *cp++ = address; - *cp++ = control; - *cp++ = protocol >> 8; - *cp++ = protocol & 0xff; - m0->m_len += PPP_HDRLEN; - - len = m_length(m0, NULL); - - if (sc->sc_flags & SC_LOG_OUTPKT) { - printf("%s output: ", ifp->if_xname); - pppdumpm(m0); - } - - if ((protocol & 0x8000) == 0) { -#ifdef PPP_FILTER - /* - * Apply the pass and active filters to the packet, - * but only if it is a data packet. - */ - *mtod(m0, u_char *) = 1; /* indicates outbound */ - if (sc->sc_pass_filt.bf_insns != 0 - && bpf_filter(sc->sc_pass_filt.bf_insns, (u_char *) m0, - len, 0) == 0) { - error = 0; /* drop this packet */ - goto bad; - } - - /* - * Update the time we sent the most recent packet. - */ - if (sc->sc_active_filt.bf_insns == 0 - || bpf_filter(sc->sc_active_filt.bf_insns, (u_char *) m0, len, 0)) - sc->sc_last_sent = time_uptime; - - *mtod(m0, u_char *) = address; -#else - /* - * Update the time we sent the most recent data packet. - */ - sc->sc_last_sent = time_uptime; -#endif /* PPP_FILTER */ - } - - /* - * See if bpf wants to look at the packet. - */ - BPF_MTAP(ifp, m0); - - /* - * Put the packet on the appropriate queue. - */ - s = splsoftnet(); /* redundant */ - if (mode == NPMODE_QUEUE) { - /* XXX we should limit the number of packets on this queue */ - *sc->sc_npqtail = m0; - m0->m_nextpkt = NULL; - sc->sc_npqtail = &m0->m_nextpkt; - } else { - /* fastq and if_snd are emptied at spl[soft]net now */ - ifq = (m0->m_flags & M_HIGHPRI)? &sc->sc_fastq: - (struct ifqueue *)&ifp->if_snd; - IF_LOCK(ifq); - if (_IF_QFULL(ifq) && dst->sa_family != AF_UNSPEC) { - _IF_DROP(ifq); - IF_UNLOCK(ifq); - PPP2IFP(sc)->if_oerrors++; - sc->sc_stats.ppp_oerrors++; - error = ENOBUFS; - goto bad; - } - _IF_ENQUEUE(ifq, m0); - IF_UNLOCK(ifq); - (*sc->sc_start)(sc); - } - getmicrotime(&ifp->if_lastchange); - ifp->if_opackets++; - ifp->if_obytes += len; - - splx(s); - return (0); - -bad: - m_freem(m0); - return (error); -} - -/* - * After a change in the NPmode for some NP, move packets from the - * npqueue to the send queue or the fast queue as appropriate. - * Should be called at spl[soft]net. - */ -static void -ppp_requeue(sc) - struct ppp_softc *sc; -{ - struct mbuf *m, **mpp; - struct ifqueue *ifq; - enum NPmode mode; - - for (mpp = &sc->sc_npqueue; (m = *mpp) != NULL; ) { - switch (PPP_PROTOCOL(mtod(m, u_char *))) { - case PPP_IP: - mode = sc->sc_npmode[NP_IP]; - break; - case PPP_IPV6: - mode = sc->sc_npmode[NP_IPV6]; - break; - default: - mode = NPMODE_PASS; - } - - switch (mode) { - case NPMODE_PASS: - /* - * This packet can now go on one of the queues to be sent. - */ - *mpp = m->m_nextpkt; - m->m_nextpkt = NULL; - ifq = (m->m_flags & M_HIGHPRI)? &sc->sc_fastq: - (struct ifqueue *)&PPP2IFP(sc)->if_snd; - if (! IF_HANDOFF(ifq, m, NULL)) { - PPP2IFP(sc)->if_oerrors++; - sc->sc_stats.ppp_oerrors++; - } - break; - - case NPMODE_DROP: - case NPMODE_ERROR: - *mpp = m->m_nextpkt; - m_freem(m); - break; - - case NPMODE_QUEUE: - mpp = &m->m_nextpkt; - break; - } - } - sc->sc_npqtail = mpp; -} - -/* - * Transmitter has finished outputting some stuff; - * remember to call sc->sc_start later at splsoftnet. - */ -void -ppp_restart(sc) - struct ppp_softc *sc; -{ - int s = splimp(); - - sc->sc_flags &= ~SC_TBUSY; - schednetisr(NETISR_PPP); - splx(s); -} - - -/* - * Get a packet to send. This procedure is intended to be called at - * splsoftnet, since it may involve time-consuming operations such as - * applying VJ compression, packet compression, address/control and/or - * protocol field compression to the packet. - */ -struct mbuf * -ppp_dequeue(sc) - struct ppp_softc *sc; -{ - struct mbuf *m, *mp; - u_char *cp; - int address, control, protocol; - - /* - * Grab a packet to send: first try the fast queue, then the - * normal queue. - */ - IF_DEQUEUE(&sc->sc_fastq, m); - if (m == NULL) - IF_DEQUEUE(&PPP2IFP(sc)->if_snd, m); - if (m == NULL) - return NULL; - - ++sc->sc_stats.ppp_opackets; - - /* - * Extract the ppp header of the new packet. - * The ppp header will be in one mbuf. - */ - cp = mtod(m, u_char *); - address = PPP_ADDRESS(cp); - control = PPP_CONTROL(cp); - protocol = PPP_PROTOCOL(cp); - - switch (protocol) { - case PPP_IP: -#ifdef VJC - /* - * If the packet is a TCP/IP packet, see if we can compress it. - */ - if ((sc->sc_flags & SC_COMP_TCP) && sc->sc_comp != NULL) { - struct ip *ip; - int type; - - mp = m; - ip = (struct ip *) (cp + PPP_HDRLEN); - if (mp->m_len <= PPP_HDRLEN) { - mp = mp->m_next; - if (mp == NULL) - break; - ip = mtod(mp, struct ip *); - } - /* this code assumes the IP/TCP header is in one non-shared mbuf */ - if (ip->ip_p == IPPROTO_TCP) { - type = sl_compress_tcp(mp, ip, sc->sc_comp, - !(sc->sc_flags & SC_NO_TCP_CCID)); - switch (type) { - case TYPE_UNCOMPRESSED_TCP: - protocol = PPP_VJC_UNCOMP; - break; - case TYPE_COMPRESSED_TCP: - protocol = PPP_VJC_COMP; - cp = mtod(m, u_char *); - cp[0] = address; /* header has moved */ - cp[1] = control; - cp[2] = 0; - break; - } - cp[3] = protocol; /* update protocol in PPP header */ - } - } -#endif /* VJC */ - break; - -#ifdef PPP_COMPRESS - case PPP_CCP: - ppp_ccp(sc, m, 0); - break; -#endif /* PPP_COMPRESS */ - } - -#ifdef PPP_COMPRESS - if (protocol != PPP_LCP && protocol != PPP_CCP - && sc->sc_xc_state && (sc->sc_flags & SC_COMP_RUN)) { - struct mbuf *mcomp = NULL; - int slen, clen; - - slen = m_length(m, NULL); - clen = (*sc->sc_xcomp->compress) - (sc->sc_xc_state, &mcomp, m, slen, PPP2IFP(sc)->if_mtu + PPP_HDRLEN); - if (mcomp != NULL) { - if (sc->sc_flags & SC_CCP_UP) { - /* Send the compressed packet instead of the original. */ - m_freem(m); - m = mcomp; - cp = mtod(m, u_char *); - protocol = cp[3]; - } else { - /* Can't transmit compressed packets until CCP is up. */ - m_freem(mcomp); - } - } - } -#endif /* PPP_COMPRESS */ - - /* - * Compress the address/control and protocol, if possible. - */ - if (sc->sc_flags & SC_COMP_AC && address == PPP_ALLSTATIONS && - control == PPP_UI && protocol != PPP_ALLSTATIONS && - protocol != PPP_LCP) { - /* can compress address/control */ - m->m_data += 2; - m->m_len -= 2; - } - if (sc->sc_flags & SC_COMP_PROT && protocol < 0xFF) { - /* can compress protocol */ - if (mtod(m, u_char *) == cp) { - cp[2] = cp[1]; /* move address/control up */ - cp[1] = cp[0]; - } - ++m->m_data; - --m->m_len; - } - - return m; -} - -/* - * Software interrupt routine, called at spl[soft]net. - */ -static void -pppintr() -{ - struct ppp_softc *sc; - int s; - struct mbuf *m; - - mtx_lock(&Giant); - PPP_LIST_LOCK(); - LIST_FOREACH(sc, &ppp_softc_list, sc_list) { - s = splimp(); - if (!(sc->sc_flags & SC_TBUSY) - && (PPP2IFP(sc)->if_snd.ifq_head || sc->sc_fastq.ifq_head)) { - sc->sc_flags |= SC_TBUSY; - splx(s); - (*sc->sc_start)(sc); - } else - splx(s); - for (;;) { - s = splimp(); - IF_DEQUEUE(&sc->sc_rawq, m); - splx(s); - if (m == NULL) - break; -#ifdef MAC - mac_ifnet_create_mbuf(PPP2IFP(sc), m); -#endif - ppp_inproc(sc, m); - } - } - PPP_LIST_UNLOCK(); - mtx_unlock(&Giant); -} - -#ifdef PPP_COMPRESS -/* - * Handle a CCP packet. `rcvd' is 1 if the packet was received, - * 0 if it is about to be transmitted. - */ -static void -ppp_ccp(sc, m, rcvd) - struct ppp_softc *sc; - struct mbuf *m; - int rcvd; -{ - u_char *dp, *ep; - struct mbuf *mp; - int slen, s; - - /* - * Get a pointer to the data after the PPP header. - */ - if (m->m_len <= PPP_HDRLEN) { - mp = m->m_next; - if (mp == NULL) - return; - dp = (mp != NULL)? mtod(mp, u_char *): NULL; - } else { - mp = m; - dp = mtod(mp, u_char *) + PPP_HDRLEN; - } - - ep = mtod(mp, u_char *) + mp->m_len; - if (dp + CCP_HDRLEN > ep) - return; - slen = CCP_LENGTH(dp); - if (dp + slen > ep) { - if (sc->sc_flags & SC_DEBUG) - printf("if_ppp/ccp: not enough data in mbuf (%p+%x > %p+%x)\n", - dp, slen, mtod(mp, u_char *), mp->m_len); - return; - } - - switch (CCP_CODE(dp)) { - case CCP_CONFREQ: - case CCP_TERMREQ: - case CCP_TERMACK: - /* CCP must be going down - disable compression */ - if (sc->sc_flags & SC_CCP_UP) { - s = splimp(); - sc->sc_flags &= ~(SC_CCP_UP | SC_COMP_RUN | SC_DECOMP_RUN); - splx(s); - } - break; - - case CCP_CONFACK: - if (sc->sc_flags & SC_CCP_OPEN && !(sc->sc_flags & SC_CCP_UP) - && slen >= CCP_HDRLEN + CCP_OPT_MINLEN - && slen >= CCP_OPT_LENGTH(dp + CCP_HDRLEN) + CCP_HDRLEN) { - if (!rcvd) { - /* we're agreeing to send compressed packets. */ - if (sc->sc_xc_state != NULL - && (*sc->sc_xcomp->comp_init) - (sc->sc_xc_state, dp + CCP_HDRLEN, slen - CCP_HDRLEN, - PPP2IFP(sc)->if_dunit, 0, sc->sc_flags & SC_DEBUG)) { - s = splimp(); - sc->sc_flags |= SC_COMP_RUN; - splx(s); - } - } else { - /* peer is agreeing to send compressed packets. */ - if (sc->sc_rc_state != NULL - && (*sc->sc_rcomp->decomp_init) - (sc->sc_rc_state, dp + CCP_HDRLEN, slen - CCP_HDRLEN, - PPP2IFP(sc)->if_dunit, 0, sc->sc_mru, - sc->sc_flags & SC_DEBUG)) { - s = splimp(); - sc->sc_flags |= SC_DECOMP_RUN; - sc->sc_flags &= ~(SC_DC_ERROR | SC_DC_FERROR); - splx(s); - } - } - } - break; - - case CCP_RESETACK: - if (sc->sc_flags & SC_CCP_UP) { - if (!rcvd) { - if (sc->sc_xc_state && (sc->sc_flags & SC_COMP_RUN)) - (*sc->sc_xcomp->comp_reset)(sc->sc_xc_state); - } else { - if (sc->sc_rc_state && (sc->sc_flags & SC_DECOMP_RUN)) { - (*sc->sc_rcomp->decomp_reset)(sc->sc_rc_state); - s = splimp(); - sc->sc_flags &= ~SC_DC_ERROR; - splx(s); - } - } - } - break; - } -} - -/* - * CCP is down; free (de)compressor state if necessary. - */ -static void -ppp_ccp_closed(sc) - struct ppp_softc *sc; -{ - if (sc->sc_xc_state) { - (*sc->sc_xcomp->comp_free)(sc->sc_xc_state); - sc->sc_xc_state = NULL; - } - if (sc->sc_rc_state) { - (*sc->sc_rcomp->decomp_free)(sc->sc_rc_state); - sc->sc_rc_state = NULL; - } -} -#endif /* PPP_COMPRESS */ - -/* - * PPP packet input routine. - * The caller has checked and removed the FCS and has inserted - * the address/control bytes and the protocol high byte if they - * were omitted. - */ -void -ppppktin(sc, m, lost) - struct ppp_softc *sc; - struct mbuf *m; - int lost; -{ - int s = splimp(); - - if (lost) - m->m_flags |= M_ERRMARK; - IF_ENQUEUE(&sc->sc_rawq, m); - schednetisr(NETISR_PPP); - splx(s); -} - -/* - * Process a received PPP packet, doing decompression as necessary. - * Should be called at splsoftnet. - */ -#define COMPTYPE(proto) ((proto) == PPP_VJC_COMP? TYPE_COMPRESSED_TCP: \ - TYPE_UNCOMPRESSED_TCP) - -static void -ppp_inproc(sc, m) - struct ppp_softc *sc; - struct mbuf *m; -{ - struct ifnet *ifp = PPP2IFP(sc); - int isr; - int s, ilen = 0, xlen, proto, rv; - u_char *cp, adrs, ctrl; - struct mbuf *mp, *dmp = NULL; - u_char *iphdr; - u_int hlen; - - sc->sc_stats.ppp_ipackets++; - - if (sc->sc_flags & SC_LOG_INPKT) { - ilen = m_length(m, NULL); - if_printf(ifp, "got %d bytes\n", ilen); - pppdumpm(m); - } - - cp = mtod(m, u_char *); - adrs = PPP_ADDRESS(cp); - ctrl = PPP_CONTROL(cp); - proto = PPP_PROTOCOL(cp); - - if (m->m_flags & M_ERRMARK) { - m->m_flags &= ~M_ERRMARK; - s = splimp(); - sc->sc_flags |= SC_VJ_RESET; - splx(s); - } - -#ifdef PPP_COMPRESS - /* - * Decompress this packet if necessary, update the receiver's - * dictionary, or take appropriate action on a CCP packet. - */ - if (proto == PPP_COMP && sc->sc_rc_state && (sc->sc_flags & SC_DECOMP_RUN) - && !(sc->sc_flags & SC_DC_ERROR) && !(sc->sc_flags & SC_DC_FERROR)) { - /* decompress this packet */ - rv = (*sc->sc_rcomp->decompress)(sc->sc_rc_state, m, &dmp); - if (rv == DECOMP_OK) { - m_freem(m); - if (dmp == NULL) { - /* no error, but no decompressed packet produced */ - return; - } - m = dmp; - cp = mtod(m, u_char *); - proto = PPP_PROTOCOL(cp); - - } else { - /* - * An error has occurred in decompression. - * Pass the compressed packet up to pppd, which may take - * CCP down or issue a Reset-Req. - */ - if (sc->sc_flags & SC_DEBUG) - if_printf(ifp, "decompress failed %d\n", rv); - s = splimp(); - sc->sc_flags |= SC_VJ_RESET; - if (rv == DECOMP_ERROR) - sc->sc_flags |= SC_DC_ERROR; - else - sc->sc_flags |= SC_DC_FERROR; - splx(s); - } - - } else { - if (sc->sc_rc_state && (sc->sc_flags & SC_DECOMP_RUN)) { - (*sc->sc_rcomp->incomp)(sc->sc_rc_state, m); - } - if (proto == PPP_CCP) { - ppp_ccp(sc, m, 1); - } - } -#endif - - ilen = m_length(m, NULL); - -#ifdef VJC - if (sc->sc_flags & SC_VJ_RESET) { - /* - * If we've missed a packet, we must toss subsequent compressed - * packets which don't have an explicit connection ID. - */ - if (sc->sc_comp) - sl_uncompress_tcp(NULL, 0, TYPE_ERROR, sc->sc_comp); - s = splimp(); - sc->sc_flags &= ~SC_VJ_RESET; - splx(s); - } - - /* - * See if we have a VJ-compressed packet to uncompress. - */ - if (proto == PPP_VJC_COMP) { - if ((sc->sc_flags & SC_REJ_COMP_TCP) || sc->sc_comp == 0) - goto bad; - - xlen = sl_uncompress_tcp_core(cp + PPP_HDRLEN, m->m_len - PPP_HDRLEN, - ilen - PPP_HDRLEN, TYPE_COMPRESSED_TCP, - sc->sc_comp, &iphdr, &hlen); - - if (xlen <= 0) { - if (sc->sc_flags & SC_DEBUG) - if_printf(ifp, "VJ uncompress failed on type comp\n"); - goto bad; - } - - /* Copy the PPP and IP headers into a new mbuf. */ - MGETHDR(mp, M_DONTWAIT, MT_DATA); - if (mp == NULL) - goto bad; - mp->m_len = 0; - mp->m_next = NULL; - if (hlen + PPP_HDRLEN > MHLEN) { - MCLGET(mp, M_DONTWAIT); - if (M_TRAILINGSPACE(mp) < hlen + PPP_HDRLEN) { - m_freem(mp); - goto bad; /* lose if big headers and no clusters */ - } - } -#ifdef MAC - mac_mbuf_copy(m, mp); -#endif - cp = mtod(mp, u_char *); - cp[0] = adrs; - cp[1] = ctrl; - cp[2] = 0; - cp[3] = PPP_IP; - proto = PPP_IP; - bcopy(iphdr, cp + PPP_HDRLEN, hlen); - mp->m_len = hlen + PPP_HDRLEN; - - /* - * Trim the PPP and VJ headers off the old mbuf - * and stick the new and old mbufs together. - */ - m->m_data += PPP_HDRLEN + xlen; - m->m_len -= PPP_HDRLEN + xlen; - if (m->m_len <= M_TRAILINGSPACE(mp)) { - bcopy(mtod(m, u_char *), mtod(mp, u_char *) + mp->m_len, m->m_len); - mp->m_len += m->m_len; - mp->m_next = m_free(m); - } else { - mp->m_next = m; - } - m = mp; - ilen += hlen - xlen; - - } else if (proto == PPP_VJC_UNCOMP) { - if ((sc->sc_flags & SC_REJ_COMP_TCP) || sc->sc_comp == 0) - goto bad; - - xlen = sl_uncompress_tcp_core(cp + PPP_HDRLEN, m->m_len - PPP_HDRLEN, - ilen - PPP_HDRLEN, TYPE_UNCOMPRESSED_TCP, - sc->sc_comp, &iphdr, &hlen); - - if (xlen < 0) { - if (sc->sc_flags & SC_DEBUG) - if_printf(ifp, "VJ uncompress failed on type uncomp\n"); - goto bad; - } - - proto = PPP_IP; - cp[3] = PPP_IP; - } -#endif /* VJC */ - - /* - * If the packet will fit in a header mbuf, don't waste a - * whole cluster on it. - */ - if (ilen <= MHLEN && M_IS_CLUSTER(m)) { - MGETHDR(mp, M_DONTWAIT, MT_DATA); - if (mp != NULL) { -#ifdef MAC - mac_mbuf_copy(m, mp); -#endif - m_copydata(m, 0, ilen, mtod(mp, caddr_t)); - m_freem(m); - m = mp; - m->m_len = ilen; - } - } - m->m_pkthdr.len = ilen; - m->m_pkthdr.rcvif = ifp; - - if ((proto & 0x8000) == 0) { -#ifdef PPP_FILTER - /* - * See whether we want to pass this packet, and - * if it counts as link activity. - */ - adrs = *mtod(m, u_char *); /* save address field */ - *mtod(m, u_char *) = 0; /* indicate inbound */ - if (sc->sc_pass_filt.bf_insns != 0 - && bpf_filter(sc->sc_pass_filt.bf_insns, (u_char *) m, - ilen, 0) == 0) { - /* drop this packet */ - m_freem(m); - return; - } - if (sc->sc_active_filt.bf_insns == 0 - || bpf_filter(sc->sc_active_filt.bf_insns, (u_char *) m, ilen, 0)) - sc->sc_last_recv = time_uptime; - - *mtod(m, u_char *) = adrs; -#else - /* - * Record the time that we received this packet. - */ - sc->sc_last_recv = time_uptime; -#endif /* PPP_FILTER */ - } - - /* See if bpf wants to look at the packet. */ - BPF_MTAP(PPP2IFP(sc), m); - - isr = -1; - switch (proto) { -#ifdef INET - case PPP_IP: - /* - * IP packet - take off the ppp header and pass it up to IP. - */ - if ((ifp->if_flags & IFF_UP) == 0 - || sc->sc_npmode[NP_IP] != NPMODE_PASS) { - /* interface is down - drop the packet. */ - m_freem(m); - return; - } - m->m_pkthdr.len -= PPP_HDRLEN; - m->m_data += PPP_HDRLEN; - m->m_len -= PPP_HDRLEN; - if ((m = ip_fastforward(m)) == NULL) - return; - isr = NETISR_IP; - break; -#endif -#ifdef INET6 - case PPP_IPV6: - /* - * IPv6 packet - take off the ppp header and pass it up to IPv6. - */ - if ((ifp->if_flags & IFF_UP) == 0 - || sc->sc_npmode[NP_IPV6] != NPMODE_PASS) { - /* interface is down - drop the packet. */ - m_freem(m); - return; - } - m->m_pkthdr.len -= PPP_HDRLEN; - m->m_data += PPP_HDRLEN; - m->m_len -= PPP_HDRLEN; - isr = NETISR_IPV6; - break; -#endif -#ifdef IPX - case PPP_IPX: - /* - * IPX packet - take off the ppp header and pass it up to IPX. - */ - if ((PPP2IFP(sc)->if_flags & IFF_UP) == 0 - /* XXX: || sc->sc_npmode[NP_IPX] != NPMODE_PASS*/) { - /* interface is down - drop the packet. */ - m_freem(m); - return; - } - m->m_pkthdr.len -= PPP_HDRLEN; - m->m_data += PPP_HDRLEN; - m->m_len -= PPP_HDRLEN; - isr = NETISR_IPX; - sc->sc_last_recv = time_uptime; /* update time of last pkt rcvd */ - break; -#endif - - default: - /* - * Some other protocol - place on input queue for read(). - */ - break; - } - - if (isr == -1) - rv = IF_HANDOFF(&sc->sc_inq, m, NULL); - else - rv = netisr_queue(isr, m); /* (0) on success. */ - if ((isr == -1 && !rv) || (isr != -1 && rv)) { - if (sc->sc_flags & SC_DEBUG) - if_printf(ifp, "input queue full\n"); - ifp->if_iqdrops++; - m = NULL; - goto bad; - } - ifp->if_ipackets++; - ifp->if_ibytes += ilen; - getmicrotime(&ifp->if_lastchange); - - if (isr == -1) - (*sc->sc_ctlp)(sc); - - return; - - bad: - if (m) - m_freem(m); - PPP2IFP(sc)->if_ierrors++; - sc->sc_stats.ppp_ierrors++; -} - -#define MAX_DUMP_BYTES 128 - -static void -pppdumpm(m0) - struct mbuf *m0; -{ - char buf[3*MAX_DUMP_BYTES+4]; - char *bp = buf; - struct mbuf *m; - - for (m = m0; m; m = m->m_next) { - int l = m->m_len; - u_char *rptr = (u_char *)m->m_data; - - while (l--) { - if (bp > buf + (sizeof(buf) - 4)) - goto done; - *bp++ = hex2ascii(*rptr >> 4); - *bp++ = hex2ascii(*rptr++ & 0xf); - } - - if (m->m_next) { - if (bp > buf + (sizeof(buf) - 3)) - goto done; - *bp++ = '|'; - } else - *bp++ = ' '; - } -done: - if (m) - *bp++ = '>'; - *bp = 0; - printf("%s\n", buf); -} diff --git a/sys/net/if_ppp.h b/sys/net/if_ppp.h deleted file mode 100644 index d23255b..0000000 --- a/sys/net/if_ppp.h +++ /dev/null @@ -1,139 +0,0 @@ -/* - * if_ppp.h - Point-to-Point Protocol definitions. - */ - -/*- - * Copyright (c) 1989 Carnegie Mellon University. - * All rights reserved. - * - * Redistribution and use in source and binary forms are permitted - * provided that the above copyright notice and this paragraph are - * duplicated in all such forms and that any documentation, - * advertising materials, and other materials related to such - * distribution and use acknowledge that the software was developed - * by Carnegie Mellon University. The name of the - * University may not be used to endorse or promote products derived - * from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * $FreeBSD$ - */ - -#ifndef _IF_PPP_H_ -#define _IF_PPP_H_ - -/* XXX this used to be self-contained. */ -#include <net/ppp_defs.h> -#include <net/if.h> - -/* - * Packet sizes - */ -#define PPP_MTU 1500 /* Default MTU (size of Info field) */ -#define PPP_MAXMRU 65000 /* Largest MRU we allow */ -#define PPP_MAXMTU 16384 /* Largest MTU we allow */ - -/* - * Bit definitions for flags. - */ -#define SC_COMP_PROT 0x00000001 /* protocol compression (output) */ -#define SC_COMP_AC 0x00000002 /* header compression (output) */ -#define SC_COMP_TCP 0x00000004 /* TCP (VJ) compression (output) */ -#define SC_NO_TCP_CCID 0x00000008 /* disable VJ connection-id comp. */ -#define SC_REJ_COMP_AC 0x00000010 /* reject adrs/ctrl comp. on input */ -#define SC_REJ_COMP_TCP 0x00000020 /* reject TCP (VJ) comp. on input */ -#define SC_CCP_OPEN 0x00000040 /* Look at CCP packets */ -#define SC_CCP_UP 0x00000080 /* May send/recv compressed packets */ -#define SC_DEBUG 0x00010000 /* enable debug messages */ -#define SC_LOG_INPKT 0x00020000 /* log contents of good pkts recvd */ -#define SC_LOG_OUTPKT 0x00040000 /* log contents of pkts sent */ -#define SC_LOG_RAWIN 0x00080000 /* log all chars received */ -#define SC_LOG_FLUSH 0x00100000 /* log all chars flushed */ -#define SC_RCV_B7_0 0x01000000 /* have rcvd char with bit 7 = 0 */ -#define SC_RCV_B7_1 0x02000000 /* have rcvd char with bit 7 = 1 */ -#define SC_RCV_EVNP 0x04000000 /* have rcvd char with even parity */ -#define SC_RCV_ODDP 0x08000000 /* have rcvd char with odd parity */ -#define SC_MASK 0x0fff00ff /* bits that user can change */ - -/* - * State bits in sc_flags, not changeable by user. - */ -#define SC_TIMEOUT 0x00000400 /* timeout is currently pending */ -#define SC_VJ_RESET 0x00000800 /* need to reset VJ decomp */ -#define SC_COMP_RUN 0x00001000 /* compressor has been initiated */ -#define SC_DECOMP_RUN 0x00002000 /* decompressor has been initiated */ -#define SC_DC_ERROR 0x00004000 /* non-fatal decomp error detected */ -#define SC_DC_FERROR 0x00008000 /* fatal decomp error detected */ -#define SC_TBUSY 0x10000000 /* xmitter doesn't need a packet yet */ -#define SC_PKTLOST 0x20000000 /* have lost or dropped a packet */ -#define SC_FLUSH 0x40000000 /* flush input until next PPP_FLAG */ -#define SC_ESCAPED 0x80000000 /* saw a PPP_ESCAPE */ - -/* - * Ioctl definitions. - */ - -struct npioctl { - int protocol; /* PPP procotol, e.g. PPP_IP */ - enum NPmode mode; -}; - -/* Structure describing a CCP configuration option, for PPPIOCSCOMPRESS */ -struct ppp_option_data { - u_char *ptr; - u_int length; - int transmit; -}; - -struct ifpppstatsreq { - char ifr_name[IFNAMSIZ]; - struct ppp_stats stats; -}; - -struct ifpppcstatsreq { - char ifr_name[IFNAMSIZ]; - struct ppp_comp_stats stats; -}; - -/* - * Ioctl definitions. - */ - -#define PPPIOCGFLAGS _IOR('t', 90, int) /* get configuration flags */ -#define PPPIOCSFLAGS _IOW('t', 89, int) /* set configuration flags */ -#define PPPIOCGASYNCMAP _IOR('t', 88, int) /* get async map */ -#define PPPIOCSASYNCMAP _IOW('t', 87, int) /* set async map */ -#define PPPIOCGUNIT _IOR('t', 86, int) /* get ppp unit number */ -#define PPPIOCGRASYNCMAP _IOR('t', 85, int) /* get receive async map */ -#define PPPIOCSRASYNCMAP _IOW('t', 84, int) /* set receive async map */ -#define PPPIOCGMRU _IOR('t', 83, int) /* get max receive unit */ -#define PPPIOCSMRU _IOW('t', 82, int) /* set max receive unit */ -#define PPPIOCSMAXCID _IOW('t', 81, int) /* set VJ max slot ID */ -#define PPPIOCGXASYNCMAP _IOR('t', 80, ext_accm) /* get extended ACCM */ -#define PPPIOCSXASYNCMAP _IOW('t', 79, ext_accm) /* set extended ACCM */ -#define PPPIOCXFERUNIT _IO('t', 78) /* transfer PPP unit */ -#define PPPIOCSCOMPRESS _IOW('t', 77, struct ppp_option_data) -#define PPPIOCGNPMODE _IOWR('t', 76, struct npioctl) /* get NP mode */ -#define PPPIOCSNPMODE _IOW('t', 75, struct npioctl) /* set NP mode */ -#define PPPIOCGIDLE _IOR('t', 74, struct ppp_idle) /* get idle time */ -#define PPPIOCSPASS _IOW('t', 71, struct bpf_program) /* set pass filter */ -#define PPPIOCSACTIVE _IOW('t', 70, struct bpf_program) /* set active filt */ - -/* PPPIOC[GS]MTU are alternatives to SIOC[GS]IFMTU, used under Ultrix */ -#define PPPIOCGMTU _IOR('t', 73, int) /* get interface MTU */ -#define PPPIOCSMTU _IOW('t', 72, int) /* set interface MTU */ - -/* - * These two are interface ioctls so that pppstats can do them on - * a socket without having to open the serial device. - */ -#define SIOCGPPPSTATS _IOWR('i', 123, struct ifpppstatsreq) -#define SIOCGPPPCSTATS _IOWR('i', 122, struct ifpppcstatsreq) - -#if !defined(ifr_mtu) -#define ifr_mtu ifr_ifru.ifru_metric -#endif - -#endif /* _IF_PPP_H_ */ diff --git a/sys/net/if_pppvar.h b/sys/net/if_pppvar.h deleted file mode 100644 index 77e1ade..0000000 --- a/sys/net/if_pppvar.h +++ /dev/null @@ -1,113 +0,0 @@ -/* - * if_pppvar.h - private structures and declarations for PPP. - */ -/*- - * Copyright (c) 1994 The Australian National University. - * All rights reserved. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation is hereby granted, provided that the above copyright - * notice appears in all copies. This software is provided without any - * warranty, express or implied. The Australian National University - * makes no representations about the suitability of this software for - * any purpose. - * - * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY - * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES - * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF - * THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - * - * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS - * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO - * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, - * OR MODIFICATIONS. - * - * Copyright (c) 1989 Carnegie Mellon University. - * All rights reserved. - * - * Redistribution and use in source and binary forms are permitted - * provided that the above copyright notice and this paragraph are - * duplicated in all such forms and that any documentation, - * advertising materials, and other materials related to such - * distribution and use acknowledge that the software was developed - * by Carnegie Mellon University. The name of the - * University may not be used to endorse or promote products derived - * from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * $FreeBSD$ - */ - -/* - * Supported network protocols. These values are used for - * indexing sc_npmode. - */ -#define NP_IP 0 /* Internet Protocol */ -#define NP_IPV6 1 /* Internet Protocol version 6 */ -#define NUM_NP 2 /* Number of NPs. */ - -/* - * Structure describing each ppp unit. - */ -struct ppp_softc { - struct ifnet *sc_ifp; /* network-visible interface */ -/*hi*/ u_int sc_flags; /* control/status bits; see if_ppp.h */ - struct callout sc_timo_ch; /* Used for scheduling timeouts */ - void *sc_devp; /* pointer to device-dep structure */ - void (*sc_start)(struct ppp_softc *); /* start output proc */ - void (*sc_ctlp)(struct ppp_softc *); /* rcvd control pkt */ - void (*sc_relinq)(struct ppp_softc *); /* relinquish ifunit */ - void (*sc_setmtu)(struct ppp_softc *); /* set mtu */ - short sc_mru; /* max receive unit */ - pid_t sc_xfer; /* used in transferring unit */ -/*hi*/ struct ifqueue sc_rawq; /* received packets */ -/*net*/ struct ifqueue sc_inq; /* queue of input packets for daemon */ -/*net*/ struct ifqueue sc_fastq; /* interactive output packet q */ - struct mbuf *sc_npqueue; /* output packets not to be sent yet */ - struct mbuf **sc_npqtail; /* ptr to last next ptr in npqueue */ - struct pppstat sc_stats; /* count of bytes/pkts sent/rcvd */ - enum NPmode sc_npmode[NUM_NP]; /* what to do with each NP */ - struct compressor *sc_xcomp; /* transmit compressor */ - void *sc_xc_state; /* transmit compressor state */ - struct compressor *sc_rcomp; /* receive decompressor */ - void *sc_rc_state; /* receive decompressor state */ - time_t sc_last_sent; /* time (secs) last NP pkt sent */ - time_t sc_last_recv; /* time (secs) last NP pkt rcvd */ -#ifdef PPP_FILTER - struct bpf_program sc_pass_filt; /* filter for packets to pass */ - struct bpf_program sc_active_filt; /* filter for "non-idle" packets */ -#endif /* PPP_FILTER */ -#ifdef VJC - struct slcompress *sc_comp; /* vjc control buffer */ -#endif - - /* Device-dependent part for async lines. */ - ext_accm sc_asyncmap; /* async control character map */ - u_long sc_rasyncmap; /* receive async control char map */ - struct mbuf *sc_outm; /* mbuf chain currently being output */ - struct mbuf *sc_m; /* pointer to input mbuf chain */ - struct mbuf *sc_mc; /* pointer to current input mbuf */ - char *sc_mp; /* ptr to next char in input mbuf */ - short sc_ilen; /* length of input packet so far */ - u_short sc_fcs; /* FCS so far (input) */ - u_short sc_outfcs; /* FCS so far for output packet */ - u_char sc_rawin[16]; /* chars as received */ - int sc_rawin_count; /* # in sc_rawin */ - LIST_ENTRY(ppp_softc) sc_list; -}; -#define PPP2IFP(sc) ((sc)->sc_ifp) - -struct ppp_softc *pppalloc(pid_t pid); -void pppdealloc(struct ppp_softc *sc); -int pppioctl(struct ppp_softc *sc, u_long cmd, caddr_t data, int flag, - struct thread *td); -int pppoutput(struct ifnet *ifp, struct mbuf *m0, struct sockaddr *dst, - struct rtentry *rtp); -void ppp_restart(struct ppp_softc *sc); -void ppppktin(struct ppp_softc *sc, struct mbuf *m, int lost); -struct mbuf *ppp_dequeue(struct ppp_softc *sc); diff --git a/sys/net/if_sl.c b/sys/net/if_sl.c deleted file mode 100644 index 10853e9..0000000 --- a/sys/net/if_sl.c +++ /dev/null @@ -1,1110 +0,0 @@ -/*- - * Copyright (c) 1987, 1989, 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)if_sl.c 8.6 (Berkeley) 2/1/94 - * $FreeBSD$ - */ - -/* - * Serial Line interface - * - * Rick Adams - * Center for Seismic Studies - * 1300 N 17th Street, Suite 1450 - * Arlington, Virginia 22209 - * (703)276-7900 - * rick@seismo.ARPA - * seismo!rick - * - * Pounded on heavily by Chris Torek (chris@mimsy.umd.edu, umcp-cs!chris). - * N.B.: this belongs in netinet, not net, the way it stands now. - * Should have a link-layer type designation, but wouldn't be - * backwards-compatible. - * - * Converted to 4.3BSD Beta by Chris Torek. - * Other changes made at Berkeley, based in part on code by Kirk Smith. - * W. Jolitz added slip abort. - * - * Hacked almost beyond recognition by Van Jacobson (van@helios.ee.lbl.gov). - * Added priority queuing for "interactive" traffic; hooks for TCP - * header compression; ICMP filtering (at 2400 baud, some cretin - * pinging you can use up all your bandwidth). Made low clist behavior - * more robust and slightly less likely to hang serial line. - * Sped up a bunch of things. - * - * Note that splimp() is used throughout to block both (tty) input - * interrupts and network activity; thus, splimp must be >= spltty. - */ - -#include "opt_inet.h" -#include "opt_slip.h" - -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/malloc.h> -#include <sys/mbuf.h> -#include <sys/priv.h> -#include <sys/proc.h> -#include <sys/socket.h> -#include <sys/sockio.h> -#include <sys/fcntl.h> -#include <sys/signalvar.h> -#include <sys/tty.h> -#include <sys/clist.h> -#include <sys/kernel.h> -#include <sys/conf.h> -#include <sys/module.h> -#include <sys/proc.h> - -#include <net/if.h> -#include <net/if_types.h> -#include <net/netisr.h> - -#if INET -#include <netinet/in.h> -#include <netinet/in_systm.h> -#include <netinet/in_var.h> -#include <netinet/ip.h> -#else -#error "Huh? Slip without inet?" -#endif - -#include <net/slcompress.h> -#include <net/if_slvar.h> -#include <net/slip.h> - -#include <net/bpf.h> - -static MALLOC_DEFINE(M_SL, "sl", "SLIP Interface"); - -/* - * SLRMAX is a hard limit on input packet size. To simplify the code - * and improve performance, we require that packets fit in an mbuf - * cluster, and if we get a compressed packet, there's enough extra - * room to expand the header into a max length tcp/ip header (128 - * bytes). So, SLRMAX can be at most - * MCLBYTES - 128 - * - * SLMTU is the default transmit MTU. The transmit MTU should be kept - * small enough so that interactive use doesn't suffer, but large - * enough to provide good performance. 552 is a good choice for SLMTU - * because it is high enough to not fragment TCP packets being routed - * through this host. Packet fragmentation is bad with SLIP because - * fragment headers aren't compressed. The previous assumptions about - * the best MTU value don't really hold when using modern modems with - * BTLZ data compression because the modem buffers play a much larger - * role in interactive performance than the MTU. The MTU can be changed - * at any time to suit the specific environment with ifconfig(8), and - * its maximum value is defined as SLTMAX. SLTMAX must not be so large - * that it would overflow the stack if BPF is configured (XXX; if_ppp.c - * handles this better). - * - * SLIP_HIWAT is the amount of data that will be queued 'downstream' - * of us (i.e., in clists waiting to be picked up by the tty output - * interrupt). If we queue a lot of data downstream, it's immune to - * our t.o.s. queuing. - * E.g., if SLIP_HIWAT is 1024, the interactive traffic in mixed - * telnet/ftp will see a 1 sec wait, independent of the mtu (the - * wait is dependent on the ftp window size but that's typically - * 1k - 4k). So, we want SLIP_HIWAT just big enough to amortize - * the cost (in idle time on the wire) of the tty driver running - * off the end of its clists & having to call back slstart for a - * new packet. For a tty interface with any buffering at all, this - * cost will be zero. Even with a totally brain dead interface (like - * the one on a typical workstation), the cost will be <= 1 character - * time. So, setting SLIP_HIWAT to ~100 guarantees that we'll lose - * at most 1% while maintaining good interactive response. - */ -#define BUFOFFSET (128+sizeof(struct ifnet **)+SLIP_HDRLEN) -#define SLRMAX (MCLBYTES - BUFOFFSET) -#define SLBUFSIZE (SLRMAX + BUFOFFSET) -#ifndef SLMTU -#define SLMTU 552 /* default MTU */ -#endif -#define SLTMAX 1500 /* maximum MTU */ -#define SLIP_HIWAT roundup(50,CBSIZE) -#define CLISTRESERVE 1024 /* Can't let clists get too low */ - -/* - * SLIP ABORT ESCAPE MECHANISM: - * (inspired by HAYES modem escape arrangement) - * 1sec escape 1sec escape 1sec escape { 1sec escape 1sec escape } - * within window time signals a "soft" exit from slip mode by remote end - * if the IFF_DEBUG flag is on. - */ -#define ABT_ESC '\033' /* can't be t_intr - distant host must know it*/ -#define ABT_IDLE 1 /* in seconds - idle before an escape */ -#define ABT_COUNT 3 /* count of escapes for abort */ -#define ABT_WINDOW (ABT_COUNT*2+2) /* in seconds - time to count */ - -static LIST_HEAD(sl_list, sl_softc) sl_list; - -#define FRAME_END 0xc0 /* Frame End */ -#define FRAME_ESCAPE 0xdb /* Frame Esc */ -#define TRANS_FRAME_END 0xdc /* transposed frame end */ -#define TRANS_FRAME_ESCAPE 0xdd /* transposed frame esc */ - -static int slisstatic(int); -static void slmarkstatic(int); -static struct sl_softc *slcreate(void); -static void sldestroy(struct sl_softc *sc); -static struct mbuf *sl_btom(struct sl_softc *, int); -static timeout_t sl_keepalive; -static timeout_t sl_outfill; -static l_close_t slclose; -static l_rint_t slinput; -static l_ioctl_t sltioctl; -static l_start_t sltstart; -static int slioctl(struct ifnet *, u_long, caddr_t); -static int slopen(struct cdev *, struct tty *); -static int sloutput(struct ifnet *, - struct mbuf *, struct sockaddr *, struct rtentry *); -static void slstart(struct ifnet *); - -static struct linesw slipdisc = { - .l_open = slopen, - .l_close = slclose, - .l_read = l_noread, - .l_write = l_nowrite, - .l_ioctl = sltioctl, - .l_rint = slinput, - .l_start = sltstart, - .l_modem = ttymodem -}; - -/* - * Called from boot code to establish sl interfaces. - */ -static int -sl_modevent(module_t mod, int type, void *data) -{ - switch (type) { - case MOD_LOAD: - ldisc_register(SLIPDISC, &slipdisc); - LIST_INIT(&sl_list); - break; - case MOD_UNLOAD: - ldisc_deregister(SLIPDISC); - printf("if_sl module unload - not possible for this module type\n"); - return EINVAL; - default: - return EOPNOTSUPP; - } - return 0; -} - -static moduledata_t sl_mod = { - "if_sl", - sl_modevent, - 0 -}; - -DECLARE_MODULE(if_sl, sl_mod, SI_SUB_PSEUDO, SI_ORDER_ANY); - -static int *st_unit_list; -static size_t st_unit_max = 0; - -static int -slisunitfree(int unit) -{ - struct sl_softc *sc; - - LIST_FOREACH(sc, &sl_list, sl_next) { - if (SL2IFP(sc)->if_dunit == unit) - return (0); - } - return (1); -} - -static struct sl_softc * -sl_for_tty(struct tty *tp) -{ - struct sl_softc *nc; - - LIST_FOREACH(nc, &sl_list, sl_next) { - if (nc->sc_ttyp == tp) - return (nc); - } - return (NULL); -} -static int -slisstatic(int unit) -{ - size_t i; - - for (i = 0; i < st_unit_max; i++) - if (st_unit_list[i] == unit) - return 1; - return 0; -} - -static void -slmarkstatic(int unit) -{ - int *t; - - if (slisstatic(unit)) - return; - - t = malloc(sizeof(int) * (st_unit_max+1), M_SL, M_NOWAIT); - if (t == NULL) - return; - - if (st_unit_list) { - bcopy(st_unit_list, t, sizeof(int) * st_unit_max); - free(st_unit_list, M_SL); - } - st_unit_list = t; - st_unit_list[st_unit_max] = unit; - st_unit_max++; -} - -static struct sl_softc * -slcreate(void) -{ - struct sl_softc *sc; - int unit; - struct mbuf *m; - - sc = malloc(sizeof(*sc), M_SL, M_WAITOK | M_ZERO); - sc->sc_ifp = if_alloc(IFT_SLIP); - if (sc->sc_ifp == NULL) { - free(sc, M_SL); - return (NULL); - } - - m = m_gethdr(M_WAIT, MT_DATA); - MCLGET(m, M_WAIT); - - sc->sc_ep = mtod(m, u_char *) + SLBUFSIZE; - sc->sc_mbuf = m; - sc->sc_buf = sc->sc_ep - SLRMAX; - sc->sc_mp = sc->sc_buf; - sl_compress_init(&sc->sc_comp, -1); - - SL2IFP(sc)->if_softc = sc; - SL2IFP(sc)->if_mtu = SLMTU; - SL2IFP(sc)->if_flags = -#ifdef SLIP_IFF_OPTS - SLIP_IFF_OPTS; -#else - IFF_POINTOPOINT | SC_AUTOCOMP | IFF_MULTICAST | IFF_NEEDSGIANT; -#endif - SL2IFP(sc)->if_ioctl = slioctl; - SL2IFP(sc)->if_output = sloutput; - SL2IFP(sc)->if_start = slstart; - SL2IFP(sc)->if_snd.ifq_maxlen = 50; - sc->sc_fastq.ifq_maxlen = 32; - SL2IFP(sc)->if_linkmib = sc; - SL2IFP(sc)->if_linkmiblen = sizeof *sc; - mtx_init(&sc->sc_fastq.ifq_mtx, "sl_fastq", NULL, MTX_DEF); - - /* - * Find a suitable unit number. - */ - for (unit=0; ; unit++) { - if (slisstatic(unit)) - continue; - if (!slisunitfree(unit)) - continue; - break; - } - if_initname(SL2IFP(sc), "sl", unit); - LIST_INSERT_HEAD(&sl_list, sc, sl_next); - - if_attach(SL2IFP(sc)); - bpfattach(SL2IFP(sc), DLT_SLIP, SLIP_HDRLEN); - - return sc; -} - - -/* - * Line specific open routine. - * Attach the given tty to the first available sl unit. - */ -/* ARGSUSED */ -static int -slopen(struct cdev *dev, register struct tty *tp) -{ - register struct sl_softc *sc; - int s, error; - - error = priv_check(curthread, PRIV_NET_SLIP); - if (error) - return (error); - - if ((sc = slcreate()) == NULL) - return (ENOBUFS); - - tp->t_hotchar = FRAME_END; - sc->sc_ttyp = tp; - SL2IFP(sc)->if_baudrate = tp->t_ospeed; - ttyflush(tp, FREAD | FWRITE); - - /* - * We don't use t_canq or t_rawq, so reduce their - * cblock resources to 0. Reserve enough cblocks - * for t_outq to guarantee that we can fit a full - * packet if the SLIP_HIWAT check allows slstart() - * to loop. Use the same value for the cblock - * limit since the reserved blocks should always - * be enough. Reserving cblocks probably makes - * the CLISTRESERVE check unnecessary and wasteful. - */ - clist_alloc_cblocks(&tp->t_canq, 0, 0); - clist_alloc_cblocks(&tp->t_outq, - SLIP_HIWAT + 2 * SL2IFP(sc)->if_mtu + 1, - SLIP_HIWAT + 2 * SL2IFP(sc)->if_mtu + 1); - clist_alloc_cblocks(&tp->t_rawq, 0, 0); - - s = splnet(); - if_up(SL2IFP(sc)); - splx(s); - return (0); -} - -static void -sldestroy(struct sl_softc *sc) -{ - bpfdetach(SL2IFP(sc)); - if_detach(SL2IFP(sc)); - if_free(SL2IFP(sc)); - LIST_REMOVE(sc, sl_next); - m_free(sc->sc_mbuf); - mtx_destroy(&sc->sc_fastq.ifq_mtx); - if (sc->bpfbuf) - free(sc->bpfbuf, M_SL); - free(sc, M_SL); -} - -/* - * Line specific close routine. - * Detach the tty from the sl unit. - */ -static int -slclose(struct tty *tp, int flag) -{ - register struct sl_softc *sc; - int s; - - ttyflush(tp, FREAD | FWRITE); - /* - * XXX the placement of the following spl is misleading. tty - * interrupts must be blocked across line discipline switches - * and throughout closes to avoid races. - */ - s = splimp(); /* actually, max(spltty, splnet) */ - clist_free_cblocks(&tp->t_outq); - sc = sl_for_tty(tp); - if (sc != NULL) { - if (sc->sc_outfill) { - sc->sc_outfill = 0; - untimeout(sl_outfill, sc, sc->sc_ofhandle); - } - if (sc->sc_keepalive) { - sc->sc_keepalive = 0; - untimeout(sl_keepalive, sc, sc->sc_kahandle); - } - if_down(SL2IFP(sc)); - sc->sc_ttyp = NULL; - sldestroy(sc); - } - splx(s); - return 0; -} - -/* - * Line specific (tty) ioctl routine. - * Provide a way to get the sl unit number. - */ -/* ARGSUSED */ -static int -sltioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, - struct thread *td) -{ - struct sl_softc *sc = sl_for_tty(tp); - int s, unit, wasup; - - s = splimp(); - switch (cmd) { - case SLIOCGUNIT: - *(int *)data = SL2IFP(sc)->if_dunit; - break; - - case SLIOCSUNIT: - unit = *(u_int *)data; - if (unit < 0) { - splx(s); - return (ENXIO); - } - if (SL2IFP(sc)->if_dunit != unit) { - if (!slisunitfree(unit)) { - splx(s); - return (ENXIO); - } - - wasup = SL2IFP(sc)->if_flags & IFF_UP; - bpfdetach(SL2IFP(sc)); - if_detach(SL2IFP(sc)); - LIST_REMOVE(sc, sl_next); - if_initname(SL2IFP(sc), "sl", unit); - LIST_INSERT_HEAD(&sl_list, sc, sl_next); - if_attach(SL2IFP(sc)); - bpfattach(SL2IFP(sc), DLT_SLIP, SLIP_HDRLEN); - if (wasup) - if_up(SL2IFP(sc)); - else - if_down(SL2IFP(sc)); - clist_alloc_cblocks(&tp->t_outq, - SLIP_HIWAT + 2 * SL2IFP(sc)->if_mtu + 1, - SLIP_HIWAT + 2 * SL2IFP(sc)->if_mtu + 1); - } - slmarkstatic(unit); - break; - - case SLIOCSKEEPAL: - sc->sc_keepalive = *(u_int *)data * hz; - if (sc->sc_keepalive) { - sc->sc_flags |= SC_KEEPALIVE; - sc->sc_kahandle = timeout(sl_keepalive, sc, - sc->sc_keepalive); - } else { - if ((sc->sc_flags & SC_KEEPALIVE) != 0) { - untimeout(sl_keepalive, sc, sc->sc_kahandle); - sc->sc_flags &= ~SC_KEEPALIVE; - } - } - break; - - case SLIOCGKEEPAL: - *(int *)data = sc->sc_keepalive / hz; - break; - - case SLIOCSOUTFILL: - sc->sc_outfill = *(u_int *)data * hz; - if (sc->sc_outfill) { - sc->sc_flags |= SC_OUTWAIT; - sc->sc_ofhandle = timeout(sl_outfill, sc, - sc->sc_outfill); - } else { - if ((sc->sc_flags & SC_OUTWAIT) != 0) { - untimeout(sl_outfill, sc, sc->sc_ofhandle); - sc->sc_flags &= ~SC_OUTWAIT; - } - } - break; - - case SLIOCGOUTFILL: - *(int *)data = sc->sc_outfill / hz; - break; - - default: - splx(s); - return (ENOIOCTL); - } - splx(s); - return (0); -} - -/* - * Queue a packet. Start transmission if not active. - * Compression happens in slstart; if we do it here, IP TOS - * will cause us to not compress "background" packets, because - * ordering gets trashed. It can be done for all packets in slstart. - */ -static int -sloutput(struct ifnet *ifp, register struct mbuf *m, struct sockaddr *dst, - struct rtentry *rtp) -{ - register struct sl_softc *sc = ifp->if_softc; - register struct ip *ip; - int error; - - /* - * `Cannot happen' (see slioctl). Someday we will extend - * the line protocol to support other address families. - */ - if (dst->sa_family != AF_INET) { - if_printf(ifp, "af%d not supported\n", dst->sa_family); - m_freem(m); - SL2IFP(sc)->if_noproto++; - return (EAFNOSUPPORT); - } - - if (sc->sc_ttyp == NULL || !(ifp->if_flags & IFF_UP)) { - m_freem(m); - return (ENETDOWN); - } - if ((sc->sc_ttyp->t_state & TS_CONNECTED) == 0) { - m_freem(m); - return (EHOSTUNREACH); - } - ip = mtod(m, struct ip *); - if (SL2IFP(sc)->if_flags & SC_NOICMP && ip->ip_p == IPPROTO_ICMP) { - m_freem(m); - return (ENETRESET); /* XXX ? */ - } - if (ip->ip_tos & IPTOS_LOWDELAY && - !ALTQ_IS_ENABLED(&SL2IFP(sc)->if_snd)) - error = !(IF_HANDOFF(&sc->sc_fastq, m, SL2IFP(sc))); - else - IFQ_HANDOFF(SL2IFP(sc), m, error); - if (error) { - SL2IFP(sc)->if_oerrors++; - return (ENOBUFS); - } - return (0); -} - -static void -slstart(struct ifnet *ifp) -{ - struct sl_softc *sc = ifp->if_softc; - int s; - - s = splimp(); - if (sc->sc_ttyp->t_outq.c_cc == 0) - sltstart(sc->sc_ttyp); - splx(s); -} - -/* - * Start output on interface. Get another datagram - * to send from the interface queue and map it to - * the interface before starting output. - */ -static int -sltstart(struct tty *tp) -{ - register struct sl_softc *sc = sl_for_tty(tp); - register struct mbuf *m; - register u_char *cp; - register struct ip *ip; - int s; - register int len = 0; - - GIANT_REQUIRED; /* tty */ - - for (;;) { - /* - * Call output process whether or not there is more in the - * output queue. We are being called in lieu of ttstart - * and must do what it would. - */ - tt_oproc(tp); - - if (tp->t_outq.c_cc != 0) { - if (sc != NULL) - sc->sc_flags &= ~SC_OUTWAIT; - if (tp->t_outq.c_cc > SLIP_HIWAT) - return 0; - } - - /* - * This happens briefly when the line shuts down. - */ - if (sc == NULL) - return 0; - - /* - * Get a packet and send it to the interface. - */ - s = splimp(); - IF_DEQUEUE(&sc->sc_fastq, m); - if (m) - SL2IFP(sc)->if_omcasts++; /* XXX */ - else - IF_DEQUEUE(&SL2IFP(sc)->if_snd, m); - splx(s); - if (m == NULL) - return 0; - - /* - * We do the header compression here rather than in sloutput - * because the packets will be out of order if we are using TOS - * queueing, and the connection id compression will get - * munged when this happens. - */ - if (bpf_peers_present(SL2IFP(sc)->if_bpf)) { - /* - * We need to save the TCP/IP header before it's - * compressed. To avoid complicated code, we just - * copy the entire packet into a stack buffer (since - * this is a serial line, packets should be short - * and/or the copy should be negligible cost compared - * to the packet transmission time). - */ - register struct mbuf *m1 = m; - register u_char *cp; - - if (sc->bpfbuf == NULL) - sc->bpfbuf = malloc(SLTMAX + SLIP_HDRLEN, - M_SL, M_NOWAIT); - - if (sc->bpfbuf) { - cp = sc->bpfbuf + SLIP_HDRLEN; - len = 0; - do { - register int mlen = m1->m_len; - - bcopy(mtod(m1, caddr_t), cp, mlen); - cp += mlen; - len += mlen; - } while ((m1 = m1->m_next) != NULL); - } - } - ip = mtod(m, struct ip *); - if (ip->ip_v == IPVERSION && ip->ip_p == IPPROTO_TCP) { - if (SL2IFP(sc)->if_flags & SC_COMPRESS) - *mtod(m, u_char *) |= sl_compress_tcp(m, ip, - &sc->sc_comp, 1); - } - if (bpf_peers_present(SL2IFP(sc)->if_bpf) && sc->bpfbuf) { - /* - * Put the SLIP pseudo-"link header" in place. The - * compressed header is now at the beginning of the - * mbuf. - */ - sc->bpfbuf[SLX_DIR] = SLIPDIR_OUT; - bcopy(mtod(m, caddr_t), &sc->bpfbuf[SLX_CHDR], CHDR_LEN); - BPF_TAP(SL2IFP(sc), sc->bpfbuf, len + SLIP_HDRLEN); - } - - /* - * If system is getting low on clists, just flush our - * output queue (if the stuff was important, it'll get - * retransmitted). Note that SLTMAX is used instead of - * the current if_mtu setting because connections that - * have already been established still use the original - * (possibly larger) mss. - */ - if (cfreecount < CLISTRESERVE + SLTMAX) { - m_freem(m); - SL2IFP(sc)->if_collisions++; - continue; - } - - sc->sc_flags &= ~SC_OUTWAIT; - /* - * The extra FRAME_END will start up a new packet, and thus - * will flush any accumulated garbage. We do this whenever - * the line may have been idle for some time. - */ - if (tp->t_outq.c_cc == 0) { - ++SL2IFP(sc)->if_obytes; - (void) putc(FRAME_END, &tp->t_outq); - } - - while (m) { - register u_char *ep; - - cp = mtod(m, u_char *); ep = cp + m->m_len; - while (cp < ep) { - /* - * Find out how many bytes in the string we can - * handle without doing something special. - */ - register u_char *bp = cp; - - while (cp < ep) { - switch (*cp++) { - case FRAME_ESCAPE: - case FRAME_END: - --cp; - goto out; - } - } - out: - if (cp > bp) { - /* - * Put n characters at once - * into the tty output queue. - */ - if (b_to_q((char *)bp, cp - bp, - &tp->t_outq)) - break; - SL2IFP(sc)->if_obytes += cp - bp; - } - /* - * If there are characters left in the mbuf, - * the first one must be special.. - * Put it out in a different form. - */ - if (cp < ep) { - if (putc(FRAME_ESCAPE, &tp->t_outq)) - break; - if (putc(*cp++ == FRAME_ESCAPE ? - TRANS_FRAME_ESCAPE : TRANS_FRAME_END, - &tp->t_outq)) { - (void) unputc(&tp->t_outq); - break; - } - SL2IFP(sc)->if_obytes += 2; - } - } - m = m_free(m); - } - - if (putc(FRAME_END, &tp->t_outq)) { - /* - * Not enough room. Remove a char to make room - * and end the packet normally. - * If you get many collisions (more than one or two - * a day) you probably do not have enough clists - * and you should increase "nclist" in param.c. - */ - (void) unputc(&tp->t_outq); - (void) putc(FRAME_END, &tp->t_outq); - SL2IFP(sc)->if_collisions++; - } else { - ++SL2IFP(sc)->if_obytes; - SL2IFP(sc)->if_opackets++; - } - } - return 0; -} - -/* - * Copy data buffer to mbuf chain; add ifnet pointer. - */ -static struct mbuf * -sl_btom(struct sl_softc *sc, register int len) -{ - struct mbuf *m, *newm; - - MGETHDR(m, M_DONTWAIT, MT_DATA); - if (m == NULL) - return (NULL); - - /* - * If we have more than MHLEN bytes, it's cheaper to - * queue the cluster we just filled & allocate a new one - * for the input buffer. Otherwise, fill the mbuf we - * allocated above. Note that code in the input routine - * guarantees that packet will fit in a cluster. - */ - if (len >= MHLEN) { - MCLGET(m, M_DONTWAIT); - if ((m->m_flags & M_EXT) == 0) { - /* - * we couldn't get a cluster - if memory's this - * low, it's time to start dropping packets. - */ - (void) m_free(m); - return (NULL); - } - /* Swap the new and old clusters */ - newm = m; - m = sc->sc_mbuf; - sc->sc_mbuf = newm; - sc->sc_ep = mtod(newm, u_char *) + SLBUFSIZE; - - m->m_data = (caddr_t)sc->sc_buf; - } else - bcopy((caddr_t)sc->sc_buf, mtod(m, caddr_t), len); - - m->m_len = len; - m->m_pkthdr.len = len; - m->m_pkthdr.rcvif = SL2IFP(sc); - return (m); -} - -/* - * tty interface receiver interrupt. - */ -static int -slinput(int c, struct tty *tp) -{ - register struct sl_softc *sc; - register struct mbuf *m; - register int len; - u_char chdr[CHDR_LEN]; - - tk_nin++; - sc = sl_for_tty(tp); - if (sc == NULL) - return 0; - if (c & TTY_ERRORMASK || (tp->t_state & TS_CONNECTED) == 0) { - sc->sc_flags |= SC_ERROR; - return 0; - } - c &= TTY_CHARMASK; - - ++SL2IFP(sc)->if_ibytes; - - if (SL2IFP(sc)->if_flags & IFF_DEBUG) { - if (c == ABT_ESC) { - /* - * If we have a previous abort, see whether - * this one is within the time limit. - */ - if (sc->sc_abortcount && - time_uptime >= sc->sc_starttime + ABT_WINDOW) - sc->sc_abortcount = 0; - /* - * If we see an abort after "idle" time, count it; - * record when the first abort escape arrived. - */ - if (time_uptime >= sc->sc_lasttime + ABT_IDLE) { - if (++sc->sc_abortcount == 1) - sc->sc_starttime = time_uptime; - if (sc->sc_abortcount >= ABT_COUNT) { - slclose(tp,0); - return 0; - } - } - } else - sc->sc_abortcount = 0; - sc->sc_lasttime = time_uptime; - } - - switch (c) { - - case TRANS_FRAME_ESCAPE: - if (sc->sc_escape) - c = FRAME_ESCAPE; - break; - - case TRANS_FRAME_END: - if (sc->sc_escape) - c = FRAME_END; - break; - - case FRAME_ESCAPE: - sc->sc_escape = 1; - return 0; - - case FRAME_END: - sc->sc_flags &= ~SC_KEEPALIVE; - if(sc->sc_flags & SC_ERROR) { - sc->sc_flags &= ~SC_ERROR; - goto newpack; - } - len = sc->sc_mp - sc->sc_buf; - if (len < 3) - /* less than min length packet - ignore */ - goto newpack; - - if (bpf_peers_present(SL2IFP(sc)->if_bpf)) { - /* - * Save the compressed header, so we - * can tack it on later. Note that we - * will end up copying garbage in some - * cases but this is okay. We remember - * where the buffer started so we can - * compute the new header length. - */ - bcopy(sc->sc_buf, chdr, CHDR_LEN); - } - - if ((c = (*sc->sc_buf & 0xf0)) != (IPVERSION << 4)) { - if (c & 0x80) - c = TYPE_COMPRESSED_TCP; - else if (c == TYPE_UNCOMPRESSED_TCP) - *sc->sc_buf &= 0x4f; /* XXX */ - /* - * We've got something that's not an IP packet. - * If compression is enabled, try to decompress it. - * Otherwise, if `auto-enable' compression is on and - * it's a reasonable packet, decompress it and then - * enable compression. Otherwise, drop it. - */ - if (SL2IFP(sc)->if_flags & SC_COMPRESS) { - len = sl_uncompress_tcp(&sc->sc_buf, len, - (u_int)c, &sc->sc_comp); - if (len <= 0) - goto error; - } else if ((SL2IFP(sc)->if_flags & SC_AUTOCOMP) && - c == TYPE_UNCOMPRESSED_TCP && len >= 40) { - len = sl_uncompress_tcp(&sc->sc_buf, len, - (u_int)c, &sc->sc_comp); - if (len <= 0) - goto error; - SL2IFP(sc)->if_flags |= SC_COMPRESS; - } else - goto error; - } - if (bpf_peers_present(SL2IFP(sc)->if_bpf)) { - /* - * Put the SLIP pseudo-"link header" in place. - * We couldn't do this any earlier since - * decompression probably moved the buffer - * pointer. Then, invoke BPF. - */ - register u_char *hp = sc->sc_buf - SLIP_HDRLEN; - - hp[SLX_DIR] = SLIPDIR_IN; - bcopy(chdr, &hp[SLX_CHDR], CHDR_LEN); - BPF_TAP(SL2IFP(sc), hp, len + SLIP_HDRLEN); - } - m = sl_btom(sc, len); - if (m == NULL) - goto error; - - SL2IFP(sc)->if_ipackets++; - - if ((SL2IFP(sc)->if_flags & IFF_UP) == 0) { - m_freem(m); - goto newpack; - } - if (netisr_queue(NETISR_IP, m)) { /* (0) on success. */ - SL2IFP(sc)->if_ierrors++; - SL2IFP(sc)->if_iqdrops++; - } - goto newpack; - } - if (sc->sc_mp < sc->sc_ep) { - *sc->sc_mp++ = c; - sc->sc_escape = 0; - return 0; - } - - /* can't put lower; would miss an extra frame */ - sc->sc_flags |= SC_ERROR; - -error: - SL2IFP(sc)->if_ierrors++; -newpack: - sc->sc_mp = sc->sc_buf = sc->sc_ep - SLRMAX; - sc->sc_escape = 0; - return 0; -} - -/* - * Process an ioctl request. - */ -static int -slioctl(struct ifnet *ifp, u_long cmd, caddr_t data) -{ - register struct ifaddr *ifa = (struct ifaddr *)data; - register struct ifreq *ifr = (struct ifreq *)data; - register int s, error = 0; - struct sl_softc *sc = ifp->if_softc; - - s = splimp(); - - switch (cmd) { - - case SIOCSIFFLAGS: - /* - * if.c will set the interface up even if we - * don't want it to. - */ - if (sc->sc_ttyp == NULL) { - ifp->if_flags &= ~IFF_UP; - } - break; - case SIOCSIFADDR: - /* - * This is "historical" - set the interface up when - * setting the address. - */ - if (ifa->ifa_addr->sa_family == AF_INET) { - if (sc->sc_ttyp != NULL) - ifp->if_flags |= IFF_UP; - } else { - error = EAFNOSUPPORT; - } - break; - - case SIOCSIFDSTADDR: - if (ifa->ifa_addr->sa_family != AF_INET) - error = EAFNOSUPPORT; - break; - - case SIOCADDMULTI: - case SIOCDELMULTI: - break; - - case SIOCSIFMTU: - /* - * Set the interface MTU. - */ - if (ifr->ifr_mtu > SLTMAX) - error = EINVAL; - else { - struct tty *tp; - - ifp->if_mtu = ifr->ifr_mtu; - tp = sc->sc_ttyp; - if (tp != NULL) - clist_alloc_cblocks(&tp->t_outq, - SLIP_HIWAT + 2 * ifp->if_mtu + 1, - SLIP_HIWAT + 2 * ifp->if_mtu + 1); - } - break; - - default: - error = EINVAL; - } - splx(s); - return (error); -} - -static void -sl_keepalive(void *chan) -{ - struct sl_softc *sc = chan; - - if (sc->sc_keepalive) { - if (sc->sc_flags & SC_KEEPALIVE) { - if (sc->sc_ttyp->t_pgrp != NULL) { - PGRP_LOCK(sc->sc_ttyp->t_pgrp); - pgsignal (sc->sc_ttyp->t_pgrp, SIGURG, 1); - PGRP_UNLOCK(sc->sc_ttyp->t_pgrp); - } - } else - sc->sc_flags |= SC_KEEPALIVE; - sc->sc_kahandle = timeout(sl_keepalive, sc, sc->sc_keepalive); - } else { - sc->sc_flags &= ~SC_KEEPALIVE; - } -} - -static void -sl_outfill(void *chan) -{ - struct sl_softc *sc = chan; - register struct tty *tp = sc->sc_ttyp; - int s; - - if (sc->sc_outfill && tp != NULL) { - if (sc->sc_flags & SC_OUTWAIT) { - s = splimp (); - ++SL2IFP(sc)->if_obytes; - (void) putc(FRAME_END, &tp->t_outq); - tt_oproc(tp); - splx (s); - } else - sc->sc_flags |= SC_OUTWAIT; - sc->sc_ofhandle = timeout(sl_outfill, sc, sc->sc_outfill); - } else { - sc->sc_flags &= ~SC_OUTWAIT; - } -} diff --git a/sys/net/if_slvar.h b/sys/net/if_slvar.h deleted file mode 100644 index e6b6d2c..0000000 --- a/sys/net/if_slvar.h +++ /dev/null @@ -1,83 +0,0 @@ -/*- - * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)if_slvar.h 8.3 (Berkeley) 2/1/94 - * - * $FreeBSD$ - */ - -#ifndef _NET_IF_SLVAR_H_ -#define _NET_IF_SLVAR_H_ - -#include <sys/callout.h> - -/* - * Definitions for SLIP interface data structures - * - * (This exists so programs like slstats can get at the definition - * of sl_softc.) - */ -struct sl_softc { - struct ifnet *sc_ifp; /* network-visible interface */ - struct ifqueue sc_fastq; /* interactive output queue */ - struct tty *sc_ttyp; /* pointer to tty structure */ - struct mbuf *sc_mbuf; /* pointer to mbuf containing buffer */ - u_char *sc_mp; /* pointer to next available buf char */ - u_char *sc_ep; /* pointer to last available buf char */ - u_char *sc_buf; /* input buffer */ - u_int sc_flags; /* see below */ - u_int sc_escape; /* =1 if last char input was FRAME_ESCAPE */ - time_t sc_lasttime; /* last time a char arrived */ - long sc_abortcount; /* number of abort escape chars */ - time_t sc_starttime; /* time of first abort in window */ - u_int sc_keepalive; /* time to decide link hang */ - u_int sc_outfill; /* time to send FRAME_END when output idle */ - /* - * Handles for scheduling outfill and - * keepalive timeouts. - */ - struct callout_handle sc_ofhandle; - struct callout_handle sc_kahandle; - struct slcompress sc_comp; /* tcp compression data */ - LIST_ENTRY(sl_softc) sl_next; - u_char *bpfbuf; /* hang buffer for bpf here */ -}; -#define SL2IFP(sc) ((sc)->sc_ifp) - -/* internal flags */ -#define SC_ERROR 0x0001 /* had an input error */ -#define SC_OUTWAIT 0x0002 /* waiting for output fill */ -#define SC_KEEPALIVE 0x0004 /* input keepalive */ - -/* visible flags */ -#define SC_COMPRESS IFF_LINK0 /* compress TCP traffic */ -#define SC_NOICMP IFF_LINK1 /* suppress ICMP traffic */ -#define SC_AUTOCOMP IFF_LINK2 /* auto-enable TCP compression */ - - -#endif diff --git a/sys/net/ppp_comp.h b/sys/net/ppp_comp.h deleted file mode 100644 index 00591ef..0000000 --- a/sys/net/ppp_comp.h +++ /dev/null @@ -1,153 +0,0 @@ -/* - * ppp_comp.h - Definitions for doing PPP packet compression. - */ - -/*- - * Copyright (c) 1994 The Australian National University. - * All rights reserved. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation is hereby granted, provided that the above copyright - * notice appears in all copies. This software is provided without any - * warranty, express or implied. The Australian National University - * makes no representations about the suitability of this software for - * any purpose. - * - * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY - * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES - * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF - * THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - * - * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS - * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO - * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, - * OR MODIFICATIONS. - * - * $FreeBSD$ - */ - -#ifndef _NET_PPP_COMP_H -#define _NET_PPP_COMP_H - -/* - * Structure giving methods for compression/decompression. - */ -#ifdef PACKETPTR -struct compressor { - int compress_proto; /* CCP compression protocol number */ - - /* Allocate space for a compressor (transmit side) */ - void *(*comp_alloc)(u_char *options, int opt_len); - /* Free space used by a compressor */ - void (*comp_free)(void *state); - /* Initialize a compressor */ - int (*comp_init)(void *state, u_char *options, int opt_len, - int unit, int hdrlen, int debug); - /* Reset a compressor */ - void (*comp_reset)(void *state); - /* Compress a packet */ - int (*compress)(void *state, PACKETPTR *mret, PACKETPTR mp, - int orig_len, int max_len); - /* Return compression statistics */ - void (*comp_stat)(void *state, struct compstat *stats); - - /* Allocate space for a decompressor (receive side) */ - void *(*decomp_alloc)(u_char *options, int opt_len); - /* Free space used by a decompressor */ - void (*decomp_free)(void *state); - /* Initialize a decompressor */ - int (*decomp_init)(void *state, u_char *options, int opt_len, - int unit, int hdrlen, int mru, int debug); - /* Reset a decompressor */ - void (*decomp_reset)(void *state); - /* Decompress a packet. */ - int (*decompress)(void *state, PACKETPTR mp, PACKETPTR *dmpp); - /* Update state for an incompressible packet received */ - void (*incomp)(void *state, PACKETPTR mp); - /* Return decompression statistics */ - void (*decomp_stat)(void *state, struct compstat *stats); -}; -#endif /* PACKETPTR */ - -/* - * Return values for decompress routine. - * We need to make these distinctions so that we can disable certain - * useful functionality, namely sending a CCP reset-request as a result - * of an error detected after decompression. This is to avoid infringing - * a patent held by Motorola. - * Don't you just lurve software patents. - */ -#define DECOMP_OK 0 /* everything went OK */ -#define DECOMP_ERROR 1 /* error detected before decomp. */ -#define DECOMP_FATALERROR 2 /* error detected after decomp. */ - -/* - * CCP codes. - */ -#define CCP_CONFREQ 1 -#define CCP_CONFACK 2 -#define CCP_TERMREQ 5 -#define CCP_TERMACK 6 -#define CCP_RESETREQ 14 -#define CCP_RESETACK 15 - -/* - * Max # bytes for a CCP option - */ -#define CCP_MAX_OPTION_LENGTH 32 - -/* - * Parts of a CCP packet. - */ -#define CCP_CODE(dp) ((dp)[0]) -#define CCP_ID(dp) ((dp)[1]) -#define CCP_LENGTH(dp) (((dp)[2] << 8) + (dp)[3]) -#define CCP_HDRLEN 4 - -#define CCP_OPT_CODE(dp) ((dp)[0]) -#define CCP_OPT_LENGTH(dp) ((dp)[1]) -#define CCP_OPT_MINLEN 2 - -/* - * Definitions for BSD-Compress. - */ -#define CI_BSD_COMPRESS 21 /* config. option for BSD-Compress */ -#define CILEN_BSD_COMPRESS 3 /* length of config. option */ - -/* Macros for handling the 3rd byte of the BSD-Compress config option. */ -#define BSD_NBITS(x) ((x) & 0x1F) /* number of bits requested */ -#define BSD_VERSION(x) ((x) >> 5) /* version of option format */ -#define BSD_CURRENT_VERSION 1 /* current version number */ -#define BSD_MAKE_OPT(v, n) (((v) << 5) | (n)) - -#define BSD_MIN_BITS 9 /* smallest code size supported */ -#define BSD_MAX_BITS 15 /* largest code size supported */ - -/* - * Definitions for Deflate. - */ -#define CI_DEFLATE 26 /* config option for Deflate */ -#define CI_DEFLATE_DRAFT 24 /* value used in original draft RFC */ -#define CILEN_DEFLATE 4 /* length of its config option */ - -#define DEFLATE_MIN_SIZE 8 -#define DEFLATE_MAX_SIZE 15 -#define DEFLATE_METHOD_VAL 8 -#define DEFLATE_SIZE(x) (((x) >> 4) + DEFLATE_MIN_SIZE) -#define DEFLATE_METHOD(x) ((x) & 0x0F) -#define DEFLATE_MAKE_OPT(w) ((((w) - DEFLATE_MIN_SIZE) << 4) \ - + DEFLATE_METHOD_VAL) -#define DEFLATE_CHK_SEQUENCE 0 - -/* - * Definitions for other, as yet unsupported, compression methods. - */ -#define CI_PREDICTOR_1 1 /* config option for Predictor-1 */ -#define CILEN_PREDICTOR_1 2 /* length of its config option */ -#define CI_PREDICTOR_2 2 /* config option for Predictor-2 */ -#define CILEN_PREDICTOR_2 2 /* length of its config option */ - -#endif /* _NET_PPP_COMP_H */ diff --git a/sys/net/ppp_deflate.c b/sys/net/ppp_deflate.c deleted file mode 100644 index e3015bd..0000000 --- a/sys/net/ppp_deflate.c +++ /dev/null @@ -1,680 +0,0 @@ -/* $FreeBSD$ */ - -/*- - * ppp_deflate.c - interface the zlib procedures for Deflate compression - * and decompression (as used by gzip) to the PPP code. - * This version is for use with mbufs on BSD-derived systems. - * - * Copyright (c) 1994 The Australian National University. - * All rights reserved. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation is hereby granted, provided that the above copyright - * notice appears in all copies. This software is provided without any - * warranty, express or implied. The Australian National University - * makes no representations about the suitability of this software for - * any purpose. - * - * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY - * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES - * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF - * THE AUSTRALIAN NATIONAL UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - * - * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS - * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO - * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, - * OR MODIFICATIONS. - */ - -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/lock.h> -#include <sys/malloc.h> -#include <sys/mbuf.h> -#include <sys/module.h> -#include <sys/mutex.h> - -#include <net/ppp_defs.h> -#include <net/zlib.h> - -#define PACKETPTR struct mbuf * -#include <net/ppp_comp.h> - -#define DEFLATE_DEBUG 1 - -/* - * State for a Deflate (de)compressor. - */ -struct deflate_state { - int seqno; - int w_size; - int unit; - int hdrlen; - int mru; - int debug; - z_stream strm; - struct compstat stats; -}; - -#define DEFLATE_OVHD 2 /* Deflate overhead/packet */ - -static void *z_alloc(void *, u_int items, u_int size); -static void z_free(void *, void *ptr); -static void *z_comp_alloc(u_char *options, int opt_len); -static void *z_decomp_alloc(u_char *options, int opt_len); -static void z_comp_free(void *state); -static void z_decomp_free(void *state); -static int z_comp_init(void *state, u_char *options, int opt_len, - int unit, int hdrlen, int debug); -static int z_decomp_init(void *state, u_char *options, int opt_len, - int unit, int hdrlen, int mru, int debug); -static int z_compress(void *state, struct mbuf **mret, struct mbuf *mp, - int slen, int maxolen); -static void z_incomp(void *state, struct mbuf *dmsg); -static int z_decompress(void *state, struct mbuf *cmp, struct mbuf **dmpp); -static void z_comp_reset(void *state); -static void z_decomp_reset(void *state); -static void z_comp_stats(void *state, struct compstat *stats); - -/* - * Procedures exported to if_ppp.c. - */ -struct compressor ppp_deflate = { - CI_DEFLATE, /* compress_proto */ - z_comp_alloc, /* comp_alloc */ - z_comp_free, /* comp_free */ - z_comp_init, /* comp_init */ - z_comp_reset, /* comp_reset */ - z_compress, /* compress */ - z_comp_stats, /* comp_stat */ - z_decomp_alloc, /* decomp_alloc */ - z_decomp_free, /* decomp_free */ - z_decomp_init, /* decomp_init */ - z_decomp_reset, /* decomp_reset */ - z_decompress, /* decompress */ - z_incomp, /* incomp */ - z_comp_stats, /* decomp_stat */ -}; - -struct compressor ppp_deflate_draft = { - CI_DEFLATE_DRAFT, /* compress_proto */ - z_comp_alloc, /* comp_alloc */ - z_comp_free, /* comp_free */ - z_comp_init, /* comp_init */ - z_comp_reset, /* comp_reset */ - z_compress, /* compress */ - z_comp_stats, /* comp_stat */ - z_decomp_alloc, /* decomp_alloc */ - z_decomp_free, /* decomp_free */ - z_decomp_init, /* decomp_init */ - z_decomp_reset, /* decomp_reset */ - z_decompress, /* decompress */ - z_incomp, /* incomp */ - z_comp_stats, /* decomp_stat */ -}; - -/* - * Space allocation and freeing routines for use by zlib routines. - */ -static void * -z_alloc(notused, items, size) - void *notused; - u_int items, size; -{ - void *ptr; - - ptr = malloc(items * size, M_DEVBUF, M_NOWAIT); - return ptr; -} - -static void -z_free(notused, ptr) - void *notused; - void *ptr; -{ - free(ptr, M_DEVBUF); -} - -/* - * Allocate space for a compressor. - */ -static void * -z_comp_alloc(options, opt_len) - u_char *options; - int opt_len; -{ - struct deflate_state *state; - int w_size; - - if (opt_len != CILEN_DEFLATE - || (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT) - || options[1] != CILEN_DEFLATE - || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL - || options[3] != DEFLATE_CHK_SEQUENCE) - return NULL; - w_size = DEFLATE_SIZE(options[2]); - if (w_size < DEFLATE_MIN_SIZE || w_size > DEFLATE_MAX_SIZE) - return NULL; - - state = malloc(sizeof(struct deflate_state), - M_DEVBUF, M_NOWAIT); - if (state == NULL) - return NULL; - - state->strm.next_in = NULL; - state->strm.zalloc = z_alloc; - state->strm.zfree = z_free; - if (deflateInit2(&state->strm, Z_DEFAULT_COMPRESSION, DEFLATE_METHOD_VAL, - -w_size, 8, Z_DEFAULT_STRATEGY) != Z_OK) { - free(state, M_DEVBUF); - return NULL; - } - - state->w_size = w_size; - bzero(&state->stats, sizeof(state->stats)); - return (void *) state; -} - -static void -z_comp_free(arg) - void *arg; -{ - struct deflate_state *state = (struct deflate_state *) arg; - - deflateEnd(&state->strm); - free(state, M_DEVBUF); -} - -static int -z_comp_init(arg, options, opt_len, unit, hdrlen, debug) - void *arg; - u_char *options; - int opt_len, unit, hdrlen, debug; -{ - struct deflate_state *state = (struct deflate_state *) arg; - - if (opt_len < CILEN_DEFLATE - || (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT) - || options[1] != CILEN_DEFLATE - || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL - || DEFLATE_SIZE(options[2]) != state->w_size - || options[3] != DEFLATE_CHK_SEQUENCE) - return 0; - - state->seqno = 0; - state->unit = unit; - state->hdrlen = hdrlen; - state->debug = debug; - - deflateReset(&state->strm); - - return 1; -} - -static void -z_comp_reset(arg) - void *arg; -{ - struct deflate_state *state = (struct deflate_state *) arg; - - state->seqno = 0; - deflateReset(&state->strm); -} - -static int -z_compress(arg, mret, mp, orig_len, maxolen) - void *arg; - struct mbuf **mret; /* compressed packet (out) */ - struct mbuf *mp; /* uncompressed packet (in) */ - int orig_len, maxolen; -{ - struct deflate_state *state = (struct deflate_state *) arg; - u_char *rptr, *wptr; - int proto, olen, wspace, r, flush; - struct mbuf *m; - - /* - * Check that the protocol is in the range we handle. - */ - rptr = mtod(mp, u_char *); - proto = PPP_PROTOCOL(rptr); - if (proto > 0x3fff || proto == 0xfd || proto == 0xfb) { - *mret = NULL; - return orig_len; - } - - /* Allocate one mbuf initially. */ - if (maxolen > orig_len) - maxolen = orig_len; - MGET(m, M_DONTWAIT, MT_DATA); - *mret = m; - if (m != NULL) { - m->m_len = 0; - if (maxolen + state->hdrlen > MLEN) - MCLGET(m, M_DONTWAIT); - wspace = M_TRAILINGSPACE(m); - if (state->hdrlen + PPP_HDRLEN + 2 < wspace) { - m->m_data += state->hdrlen; - wspace -= state->hdrlen; - } - wptr = mtod(m, u_char *); - - /* - * Copy over the PPP header and store the 2-byte sequence number. - */ - wptr[0] = PPP_ADDRESS(rptr); - wptr[1] = PPP_CONTROL(rptr); - wptr[2] = PPP_COMP >> 8; - wptr[3] = PPP_COMP; - wptr += PPP_HDRLEN; - wptr[0] = state->seqno >> 8; - wptr[1] = state->seqno; - wptr += 2; - state->strm.next_out = wptr; - state->strm.avail_out = wspace - (PPP_HDRLEN + 2); - } else { - state->strm.next_out = NULL; - state->strm.avail_out = 1000000; - wptr = NULL; - wspace = 0; - } - ++state->seqno; - - rptr += (proto > 0xff)? 2: 3; /* skip 1st proto byte if 0 */ - state->strm.next_in = rptr; - state->strm.avail_in = mtod(mp, u_char *) + mp->m_len - rptr; - mp = mp->m_next; - flush = (mp == NULL)? Z_PACKET_FLUSH: Z_NO_FLUSH; - olen = 0; - for (;;) { - r = deflate(&state->strm, flush); - if (r != Z_OK) { - printf("z_compress: deflate returned %d (%s)\n", - r, (state->strm.msg? state->strm.msg: "")); - break; - } - if (flush != Z_NO_FLUSH && state->strm.avail_out != 0) - break; /* all done */ - if (state->strm.avail_in == 0 && mp != NULL) { - state->strm.next_in = mtod(mp, u_char *); - state->strm.avail_in = mp->m_len; - mp = mp->m_next; - if (mp == NULL) - flush = Z_PACKET_FLUSH; - } - if (state->strm.avail_out == 0) { - if (m != NULL) { - m->m_len = wspace; - olen += wspace; - MGET(m->m_next, M_DONTWAIT, MT_DATA); - m = m->m_next; - if (m != NULL) { - m->m_len = 0; - if (maxolen - olen > MLEN) - MCLGET(m, M_DONTWAIT); - state->strm.next_out = mtod(m, u_char *); - state->strm.avail_out = wspace = M_TRAILINGSPACE(m); - } - } - if (m == NULL) { - state->strm.next_out = NULL; - state->strm.avail_out = 1000000; - } - } - } - if (m != NULL) - olen += (m->m_len = wspace - state->strm.avail_out); - - /* - * See if we managed to reduce the size of the packet. - */ - if (m != NULL && olen < orig_len) { - state->stats.comp_bytes += olen; - state->stats.comp_packets++; - } else { - if (*mret != NULL) { - m_freem(*mret); - *mret = NULL; - } - state->stats.inc_bytes += orig_len; - state->stats.inc_packets++; - olen = orig_len; - } - state->stats.unc_bytes += orig_len; - state->stats.unc_packets++; - - return olen; -} - -static void -z_comp_stats(arg, stats) - void *arg; - struct compstat *stats; -{ - struct deflate_state *state = (struct deflate_state *) arg; - u_int out; - - *stats = state->stats; - stats->ratio = stats->unc_bytes; - out = stats->comp_bytes + stats->inc_bytes; - if (stats->ratio <= 0x7ffffff) - stats->ratio <<= 8; - else - out >>= 8; - if (out != 0) - stats->ratio /= out; -} - -/* - * Allocate space for a decompressor. - */ -static void * -z_decomp_alloc(options, opt_len) - u_char *options; - int opt_len; -{ - struct deflate_state *state; - int w_size; - - if (opt_len != CILEN_DEFLATE - || (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT) - || options[1] != CILEN_DEFLATE - || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL - || options[3] != DEFLATE_CHK_SEQUENCE) - return NULL; - w_size = DEFLATE_SIZE(options[2]); - if (w_size < DEFLATE_MIN_SIZE || w_size > DEFLATE_MAX_SIZE) - return NULL; - - state = malloc(sizeof(struct deflate_state), - M_DEVBUF, M_NOWAIT); - if (state == NULL) - return NULL; - - state->strm.next_out = NULL; - state->strm.zalloc = z_alloc; - state->strm.zfree = z_free; - if (inflateInit2(&state->strm, -w_size) != Z_OK) { - free(state, M_DEVBUF); - return NULL; - } - - state->w_size = w_size; - bzero(&state->stats, sizeof(state->stats)); - return (void *) state; -} - -static void -z_decomp_free(arg) - void *arg; -{ - struct deflate_state *state = (struct deflate_state *) arg; - - inflateEnd(&state->strm); - free(state, M_DEVBUF); -} - -static int -z_decomp_init(arg, options, opt_len, unit, hdrlen, mru, debug) - void *arg; - u_char *options; - int opt_len, unit, hdrlen, mru, debug; -{ - struct deflate_state *state = (struct deflate_state *) arg; - - if (opt_len < CILEN_DEFLATE - || (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT) - || options[1] != CILEN_DEFLATE - || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL - || DEFLATE_SIZE(options[2]) != state->w_size - || options[3] != DEFLATE_CHK_SEQUENCE) - return 0; - - state->seqno = 0; - state->unit = unit; - state->hdrlen = hdrlen; - state->debug = debug; - state->mru = mru; - - inflateReset(&state->strm); - - return 1; -} - -static void -z_decomp_reset(arg) - void *arg; -{ - struct deflate_state *state = (struct deflate_state *) arg; - - state->seqno = 0; - inflateReset(&state->strm); -} - -/* - * Decompress a Deflate-compressed packet. - * - * Because of patent problems, we return DECOMP_ERROR for errors - * found by inspecting the input data and for system problems, but - * DECOMP_FATALERROR for any errors which could possibly be said to - * be being detected "after" decompression. For DECOMP_ERROR, - * we can issue a CCP reset-request; for DECOMP_FATALERROR, we may be - * infringing a patent of Motorola's if we do, so we take CCP down - * instead. - * - * Given that the frame has the correct sequence number and a good FCS, - * errors such as invalid codes in the input most likely indicate a - * bug, so we return DECOMP_FATALERROR for them in order to turn off - * compression, even though they are detected by inspecting the input. - */ -static int -z_decompress(arg, mi, mop) - void *arg; - struct mbuf *mi, **mop; -{ - struct deflate_state *state = (struct deflate_state *) arg; - struct mbuf *mo, *mo_head; - u_char *rptr, *wptr; - int rlen, olen, ospace; - int seq, i, flush, r, decode_proto; - u_char hdr[PPP_HDRLEN + DEFLATE_OVHD]; - - *mop = NULL; - rptr = mtod(mi, u_char *); - rlen = mi->m_len; - for (i = 0; i < PPP_HDRLEN + DEFLATE_OVHD; ++i) { - while (rlen <= 0) { - mi = mi->m_next; - if (mi == NULL) - return DECOMP_ERROR; - rptr = mtod(mi, u_char *); - rlen = mi->m_len; - } - hdr[i] = *rptr++; - --rlen; - } - - /* Check the sequence number. */ - seq = (hdr[PPP_HDRLEN] << 8) + hdr[PPP_HDRLEN+1]; - if (seq != state->seqno) { - if (state->debug) - printf("z_decompress%d: bad seq # %d, expected %d\n", - state->unit, seq, state->seqno); - return DECOMP_ERROR; - } - ++state->seqno; - - /* Allocate an output mbuf. */ - MGETHDR(mo, M_DONTWAIT, MT_DATA); - if (mo == NULL) - return DECOMP_ERROR; - mo_head = mo; - mo->m_len = 0; - mo->m_next = NULL; - MCLGET(mo, M_DONTWAIT); - ospace = M_TRAILINGSPACE(mo); - if (state->hdrlen + PPP_HDRLEN < ospace) { - mo->m_data += state->hdrlen; - ospace -= state->hdrlen; - } - - /* - * Fill in the first part of the PPP header. The protocol field - * comes from the decompressed data. - */ - wptr = mtod(mo, u_char *); - wptr[0] = PPP_ADDRESS(hdr); - wptr[1] = PPP_CONTROL(hdr); - wptr[2] = 0; - - /* - * Set up to call inflate. We set avail_out to 1 initially so we can - * look at the first byte of the output and decide whether we have - * a 1-byte or 2-byte protocol field. - */ - state->strm.next_in = rptr; - state->strm.avail_in = rlen; - mi = mi->m_next; - flush = (mi == NULL)? Z_PACKET_FLUSH: Z_NO_FLUSH; - rlen += PPP_HDRLEN + DEFLATE_OVHD; - state->strm.next_out = wptr + 3; - state->strm.avail_out = 1; - decode_proto = 1; - olen = PPP_HDRLEN; - - /* - * Call inflate, supplying more input or output as needed. - */ - for (;;) { - r = inflate(&state->strm, flush); - if (r != Z_OK) { -#if !DEFLATE_DEBUG - if (state->debug) -#endif - printf("z_decompress%d: inflate returned %d (%s)\n", - state->unit, r, (state->strm.msg? state->strm.msg: "")); - m_freem(mo_head); - return DECOMP_FATALERROR; - } - if (flush != Z_NO_FLUSH && state->strm.avail_out != 0) - break; /* all done */ - if (state->strm.avail_in == 0 && mi != NULL) { - state->strm.next_in = mtod(mi, u_char *); - state->strm.avail_in = mi->m_len; - rlen += mi->m_len; - mi = mi->m_next; - if (mi == NULL) - flush = Z_PACKET_FLUSH; - } - if (state->strm.avail_out == 0) { - if (decode_proto) { - state->strm.avail_out = ospace - PPP_HDRLEN; - if ((wptr[3] & 1) == 0) { - /* 2-byte protocol field */ - wptr[2] = wptr[3]; - --state->strm.next_out; - ++state->strm.avail_out; - --olen; - } - decode_proto = 0; - } else { - mo->m_len = ospace; - olen += ospace; - MGET(mo->m_next, M_DONTWAIT, MT_DATA); - mo = mo->m_next; - if (mo == NULL) { - m_freem(mo_head); - return DECOMP_ERROR; - } - MCLGET(mo, M_DONTWAIT); - state->strm.next_out = mtod(mo, u_char *); - state->strm.avail_out = ospace = M_TRAILINGSPACE(mo); - } - } - } - if (decode_proto) { - m_freem(mo_head); - return DECOMP_ERROR; - } - olen += (mo->m_len = ospace - state->strm.avail_out); -#if DEFLATE_DEBUG - if (state->debug && olen > state->mru + PPP_HDRLEN) - printf("ppp_deflate%d: exceeded mru (%d > %d)\n", - state->unit, olen, state->mru + PPP_HDRLEN); -#endif - - state->stats.unc_bytes += olen; - state->stats.unc_packets++; - state->stats.comp_bytes += rlen; - state->stats.comp_packets++; - - *mop = mo_head; - return DECOMP_OK; -} - -/* - * Incompressible data has arrived - add it to the history. - */ -static void -z_incomp(arg, mi) - void *arg; - struct mbuf *mi; -{ - struct deflate_state *state = (struct deflate_state *) arg; - u_char *rptr; - int rlen, proto, r; - - /* - * Check that the protocol is one we handle. - */ - rptr = mtod(mi, u_char *); - proto = PPP_PROTOCOL(rptr); - if (proto > 0x3fff || proto == 0xfd || proto == 0xfb) - return; - - ++state->seqno; - - /* - * Iterate through the mbufs, adding the characters in them - * to the decompressor's history. For the first mbuf, we start - * at the either the 1st or 2nd byte of the protocol field, - * depending on whether the protocol value is compressible. - */ - rlen = mi->m_len; - state->strm.next_in = rptr + 3; - state->strm.avail_in = rlen - 3; - if (proto > 0xff) { - --state->strm.next_in; - ++state->strm.avail_in; - } - for (;;) { - r = inflateIncomp(&state->strm); - if (r != Z_OK) { - /* gak! */ -#if !DEFLATE_DEBUG - if (state->debug) -#endif - printf("z_incomp%d: inflateIncomp returned %d (%s)\n", - state->unit, r, (state->strm.msg? state->strm.msg: "")); - return; - } - mi = mi->m_next; - if (mi == NULL) - break; - state->strm.next_in = mtod(mi, u_char *); - state->strm.avail_in = mi->m_len; - rlen += mi->m_len; - } - - /* - * Update stats. - */ - state->stats.inc_bytes += rlen; - state->stats.inc_packets++; - state->stats.unc_bytes += rlen; - state->stats.unc_packets++; -} -MODULE_DEPEND(ppp_deflate, zlib, 1, 1, 1); diff --git a/sys/net/ppp_tty.c b/sys/net/ppp_tty.c deleted file mode 100644 index ae37bd7..0000000 --- a/sys/net/ppp_tty.c +++ /dev/null @@ -1,1076 +0,0 @@ -/* - * ppp_tty.c - Point-to-Point Protocol (PPP) driver for asynchronous - * tty devices. - */ -/*- - * Copyright (c) 1989 Carnegie Mellon University. - * All rights reserved. - * - * Redistribution and use in source and binary forms are permitted - * provided that the above copyright notice and this paragraph are - * duplicated in all such forms and that any documentation, - * advertising materials, and other materials related to such - * distribution and use acknowledge that the software was developed - * by Carnegie Mellon University. The name of the - * University may not be used to endorse or promote products derived - * from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * Drew D. Perkins - * Carnegie Mellon University - * 4910 Forbes Ave. - * Pittsburgh, PA 15213 - * (412) 268-8576 - * ddp@andrew.cmu.edu - * - * Based on: - * @(#)if_sl.c 7.6.1.2 (Berkeley) 2/15/89 - * - * Copyright (c) 1987 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms are permitted - * provided that the above copyright notice and this paragraph are - * duplicated in all such forms and that any documentation, - * advertising materials, and other materials related to such - * distribution and use acknowledge that the software was developed - * by the University of California, Berkeley. The name of the - * University may not be used to endorse or promote products derived - * from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * Serial Line interface - * - * Rick Adams - * Center for Seismic Studies - * 1300 N 17th Street, Suite 1450 - * Arlington, Virginia 22209 - * (703)276-7900 - * rick@seismo.ARPA - * seismo!rick - * - * Pounded on heavily by Chris Torek (chris@mimsy.umd.edu, umcp-cs!chris). - * Converted to 4.3BSD Beta by Chris Torek. - * Other changes made at Berkeley, based in part on code by Kirk Smith. - * - * Converted to 4.3BSD+ 386BSD by Brad Parker (brad@cayman.com) - * Added VJ tcp header compression; more unified ioctls - * - * Extensively modified by Paul Mackerras (paulus@cs.anu.edu.au). - * Cleaned up a lot of the mbuf-related code to fix bugs that - * caused system crashes and packet corruption. Changed pppstart - * so that it doesn't just give up with a "collision" if the whole - * packet doesn't fit in the output ring buffer. - * - * Added priority queueing for interactive IP packets, following - * the model of if_sl.c, plus hooks for bpf. - * Paul Mackerras (paulus@cs.anu.edu.au). - */ - -/* $FreeBSD$ */ - -#include "opt_ppp.h" /* XXX for ppp_defs.h */ - -#define VJC /* XXX for ppp_defs.h */ - -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/priv.h> -#include <sys/proc.h> -#include <sys/mbuf.h> -#include <sys/socket.h> -#include <sys/fcntl.h> -#include <sys/tty.h> -#include <sys/conf.h> -#include <sys/uio.h> - -#ifdef PPP_FILTER -#include <net/bpf.h> -#endif -#include <net/if_ppp.h> -#include <net/if_pppvar.h> - -static int pppopen(struct cdev *dev, struct tty *tp); -static int pppclose(struct tty *tp, int flag); -static int pppread(struct tty *tp, struct uio *uio, int flag); -static int pppwrite(struct tty *tp, struct uio *uio, int flag); -static int ppptioctl(struct tty *tp, u_long cmd, caddr_t data, - int flag, struct thread *td); -static int pppinput(int c, struct tty *tp); -static int pppstart(struct tty *tp); - -static u_short pppfcs(u_short fcs, u_char *cp, int len); -static void pppasyncstart(struct ppp_softc *); -static void pppasyncctlp(struct ppp_softc *); -static void pppasyncrelinq(struct ppp_softc *); -static void pppasyncsetmtu(struct ppp_softc *); -static void ppp_timeout(void *); -static void pppgetm(struct ppp_softc *sc); -static void ppplogchar(struct ppp_softc *, int); - -/* XXX called from if_ppp.c - layering violation */ -void pppasyncattach(void *); -void pppasyncdetach(void); - -/* - * Some useful mbuf macros not in mbuf.h. - */ -#define M_IS_CLUSTER(m) ((m)->m_flags & M_EXT) - -#define M_DATASTART(m) \ - (M_IS_CLUSTER(m) ? (m)->m_ext.ext_buf : \ - (m)->m_flags & M_PKTHDR ? (m)->m_pktdat : (m)->m_dat) - -#define M_DATASIZE(m) \ - (M_IS_CLUSTER(m) ? (m)->m_ext.ext_size : \ - (m)->m_flags & M_PKTHDR ? MHLEN: MLEN) - -/* - * Does c need to be escaped? - */ -#define ESCAPE_P(c) (sc->sc_asyncmap[(c) >> 5] & (1 << ((c) & 0x1F))) - -/* - * Procedures for using an async tty interface for PPP. - */ - -/* This is a FreeBSD-2.X kernel. */ -#define CCOUNT(q) ((q)->c_cc) -#define PPP_LOWAT 100 /* Process more output when < LOWAT on queue */ -#define PPP_HIWAT 400 /* Don't start a new packet if HIWAT on que */ - -/* - * Define the PPP line discipline. - */ - -static struct linesw pppdisc = { - pppopen, pppclose, pppread, pppwrite, - ppptioctl, pppinput, pppstart, ttymodem -}; - -void -pppasyncattach(dummy) - void *dummy; -{ - ldisc_register(PPPDISC, &pppdisc); -} - -void -pppasyncdetach() -{ - ldisc_deregister(PPPDISC); -} - -/* - * Line specific open routine for async tty devices. - * Attach the given tty to the first available ppp unit. - * Called from device open routine or ttioctl() at >= splsofttty() - */ -/* ARGSUSED */ -static int -pppopen(dev, tp) - struct cdev *dev; - register struct tty *tp; -{ - struct thread *td = curthread; /* XXX */ - register struct ppp_softc *sc; - int error, s; - - error = priv_check(td, PRIV_NET_PPP); - if (error) - return (error); - - s = spltty(); - - tp->t_hotchar = PPP_FLAG; - - if ((sc = pppalloc(td->td_proc->p_pid)) == NULL) { - splx(s); - return ENXIO; - } - - if (sc->sc_relinq) - (*sc->sc_relinq)(sc); /* get previous owner to relinquish the unit */ - - sc->sc_ilen = 0; - sc->sc_m = NULL; - bzero(sc->sc_asyncmap, sizeof(sc->sc_asyncmap)); - sc->sc_asyncmap[0] = 0xffffffff; - sc->sc_asyncmap[3] = 0x60000000; - sc->sc_rasyncmap = 0; - sc->sc_devp = (void *) tp; - sc->sc_start = pppasyncstart; - sc->sc_ctlp = pppasyncctlp; - sc->sc_relinq = pppasyncrelinq; - sc->sc_setmtu = pppasyncsetmtu; - sc->sc_outm = NULL; - pppgetm(sc); - PPP2IFP(sc)->if_drv_flags |= IFF_DRV_RUNNING; - getmicrotime(&PPP2IFP(sc)->if_lastchange); - PPP2IFP(sc)->if_baudrate = tp->t_ospeed; - - tp->t_hotchar = PPP_FLAG; - tp->t_lsc = sc; - ttyflush(tp, FREAD | FWRITE); - - /* - * Pre-allocate cblocks to the "just right" amount. The 1 byte t_canq - * allocation helps avoid the need for select and/or FIONREAD. - * We also pass 1 byte tokens through t_canq... - */ - clist_alloc_cblocks(&tp->t_canq, 1, 1); - clist_alloc_cblocks(&tp->t_outq, PPP2IFP(sc)->if_mtu + PPP_HIWAT, - PPP2IFP(sc)->if_mtu + PPP_HIWAT); - clist_alloc_cblocks(&tp->t_rawq, 0, 0); - - splx(s); - - return (0); -} - -/* - * Line specific close routine, called from device close routine - * and from ttioctl at >= splsofttty(). - * Detach the tty from the ppp unit. - * Mimics part of tty_close(). - */ -static int -pppclose(tp, flag) - struct tty *tp; - int flag; -{ - register struct ppp_softc *sc = (struct ppp_softc *)tp->t_lsc; - int s; - - s = spltty(); - ttyflush(tp, FREAD | FWRITE); - clist_free_cblocks(&tp->t_canq); - clist_free_cblocks(&tp->t_outq); - if (sc != NULL) { - pppasyncrelinq(sc); - pppdealloc(sc); - } - splx(s); - return 0; -} - -/* - * Relinquish the interface unit to another device. - */ -static void -pppasyncrelinq(sc) - struct ppp_softc *sc; -{ - int s; - - s = spltty(); - if (sc->sc_outm) { - m_freem(sc->sc_outm); - sc->sc_outm = NULL; - } - if (sc->sc_m) { - m_freem(sc->sc_m); - sc->sc_m = NULL; - } - if (sc->sc_flags & SC_TIMEOUT) { - callout_stop(&sc->sc_timo_ch); - sc->sc_flags &= ~SC_TIMEOUT; - } - splx(s); -} - -/* - * This gets called from the upper layer to notify a mtu change - */ -static void -pppasyncsetmtu(sc) -register struct ppp_softc *sc; -{ - register struct tty *tp = (struct tty *) sc->sc_devp; - int s; - - s = spltty(); - if (tp != NULL) - clist_alloc_cblocks(&tp->t_outq, PPP2IFP(sc)->if_mtu + PPP_HIWAT, - PPP2IFP(sc)->if_mtu + PPP_HIWAT); - splx(s); -} - -/* - * Line specific (tty) read routine. - * called at zero spl from the device driver in the response to user-level - * reads on the tty file descriptor (ie: pppd). - */ -static int -pppread(tp, uio, flag) - register struct tty *tp; - struct uio *uio; - int flag; -{ - register struct ppp_softc *sc = (struct ppp_softc *)tp->t_lsc; - struct mbuf *m, *m0; - register int s; - int error = 0; - - if (sc == NULL) - return 0; - /* - * Loop waiting for input, checking that nothing disasterous - * happens in the meantime. - */ - s = spltty(); - for (;;) { - if (tp != (struct tty *) sc->sc_devp || tp->t_line != PPPDISC) { - splx(s); - return 0; - } - if (sc->sc_inq.ifq_head != NULL) - break; - if ((tp->t_state & TS_CONNECTED) == 0) { - splx(s); - return 0; /* end of file */ - } - if (tp->t_state & TS_ASYNC || flag & O_NONBLOCK) { - splx(s); - return (EWOULDBLOCK); - } - error = ttysleep(tp, TSA_HUP_OR_INPUT(tp), TTIPRI | PCATCH, "pppin", 0); - if (error) { - splx(s); - return error; - } - } - - /* Pull place-holder byte out of canonical queue */ - getc(&tp->t_canq); - - /* Get the packet from the input queue */ - IF_DEQUEUE(&sc->sc_inq, m0); - splx(s); - - for (m = m0; m && uio->uio_resid; m = m->m_next) - if ((error = uiomove(mtod(m, u_char *), m->m_len, uio)) != 0) - break; - m_freem(m0); - return (error); -} - -/* - * Line specific (tty) write routine. - * called at zero spl from the device driver in the response to user-level - * writes on the tty file descriptor (ie: pppd). - */ -static int -pppwrite(tp, uio, flag) - register struct tty *tp; - struct uio *uio; - int flag; -{ - register struct ppp_softc *sc = (struct ppp_softc *)tp->t_lsc; - struct mbuf *m; - struct sockaddr dst; - int error, s; - - if ((tp->t_state & TS_CONNECTED) == 0) - return 0; /* wrote 0 bytes */ - if (tp->t_line != PPPDISC) - return (EINVAL); - if (sc == NULL) - return EIO; - if (uio->uio_resid > PPP2IFP(sc)->if_mtu + PPP_HDRLEN || - uio->uio_resid < PPP_HDRLEN) - return (EMSGSIZE); - - s = spltty(); - if ((m = m_uiotombuf(uio, M_DONTWAIT, 0, 0, M_PKTHDR)) == NULL) { - splx(s); - return (ENOBUFS); - } - - dst.sa_family = AF_UNSPEC; - bcopy(mtod(m, u_char *), dst.sa_data, PPP_HDRLEN); - m->m_data += PPP_HDRLEN; - m->m_len -= PPP_HDRLEN; - - /* call the upper layer to "transmit" it... */ - error = pppoutput(PPP2IFP(sc), m, &dst, NULL); - splx(s); - return (error); -} - -/* - * Line specific (tty) ioctl routine. - * This discipline requires that tty device drivers call - * the line specific l_ioctl routine from their ioctl routines. - */ -/* ARGSUSED */ -static int -ppptioctl(tp, cmd, data, flag, td) - struct tty *tp; - u_long cmd; - caddr_t data; - int flag; - struct thread *td; -{ - struct ppp_softc *sc = (struct ppp_softc *)tp->t_lsc; - int error, s; - - if (sc == NULL || tp != (struct tty *) sc->sc_devp) - return (ENOIOCTL); - - error = 0; - switch (cmd) { - case PPPIOCSASYNCMAP: - error = priv_check(td, PRIV_NET_PPP); - if (error) - break; - sc->sc_asyncmap[0] = *(u_int *)data; - break; - - case PPPIOCGASYNCMAP: - *(u_int *)data = sc->sc_asyncmap[0]; - break; - - case PPPIOCSRASYNCMAP: - error = priv_check(td, PRIV_NET_PPP); - if (error) - break; - sc->sc_rasyncmap = *(u_int *)data; - break; - - case PPPIOCGRASYNCMAP: - *(u_int *)data = sc->sc_rasyncmap; - break; - - case PPPIOCSXASYNCMAP: - error = priv_check(td, PRIV_NET_PPP); - if (error) - break; - s = spltty(); - bcopy(data, sc->sc_asyncmap, sizeof(sc->sc_asyncmap)); - sc->sc_asyncmap[1] = 0; /* mustn't escape 0x20 - 0x3f */ - sc->sc_asyncmap[2] &= ~0x40000000; /* mustn't escape 0x5e */ - sc->sc_asyncmap[3] |= 0x60000000; /* must escape 0x7d, 0x7e */ - splx(s); - break; - - case PPPIOCGXASYNCMAP: - bcopy(sc->sc_asyncmap, data, sizeof(sc->sc_asyncmap)); - break; - - default: - error = pppioctl(sc, cmd, data, flag, td); - if (error == 0 && cmd == PPPIOCSMRU) - pppgetm(sc); - } - - return error; -} - -/* - * FCS lookup table as calculated by genfcstab. - */ -static u_short fcstab[256] = { - 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, - 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, - 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, - 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876, - 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd, - 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5, - 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c, - 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974, - 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb, - 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3, - 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a, - 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72, - 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9, - 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1, - 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738, - 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70, - 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7, - 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff, - 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036, - 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e, - 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5, - 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd, - 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134, - 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c, - 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3, - 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb, - 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232, - 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a, - 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1, - 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9, - 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330, - 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78 -}; - -/* - * Calculate a new FCS given the current FCS and the new data. - */ -static u_short -pppfcs(u_short fcs, u_char *cp, int len) -{ - while (len--) - fcs = PPP_FCS(fcs, *cp++); - return (fcs); -} - -/* - * This gets called at splsoftnet from if_ppp.c at various times - * when there is data ready to be sent. - */ -static void -pppasyncstart(sc) - register struct ppp_softc *sc; -{ - register struct tty *tp = (struct tty *) sc->sc_devp; - register struct mbuf *m; - register int len; - register u_char *start, *stop, *cp; - int n, ndone, done, idle; - int s; - - idle = 0; - /* XXX assumes atomic access to *tp although we're not at spltty(). */ - while (CCOUNT(&tp->t_outq) < PPP_HIWAT) { - /* - * See if we have an existing packet partly sent. - * If not, get a new packet and start sending it. - */ - m = sc->sc_outm; - if (m == NULL) { - /* - * Get another packet to be sent. - */ - m = ppp_dequeue(sc); - if (m == NULL) { - idle = 1; - break; - } - - /* - * The extra PPP_FLAG will start up a new packet, and thus - * will flush any accumulated garbage. We do this whenever - * the line may have been idle for some time. - */ - /* XXX as above. */ - if (CCOUNT(&tp->t_outq) == 0) { - ++sc->sc_stats.ppp_obytes; - (void) putc(PPP_FLAG, &tp->t_outq); - } - - /* Calculate the FCS for the first mbuf's worth. */ - sc->sc_outfcs = pppfcs(PPP_INITFCS, mtod(m, u_char *), m->m_len); - getmicrotime(&PPP2IFP(sc)->if_lastchange); - } - - for (;;) { - start = mtod(m, u_char *); - len = m->m_len; - stop = start + len; - while (len > 0) { - /* - * Find out how many bytes in the string we can - * handle without doing something special. - */ - for (cp = start; cp < stop; cp++) - if (ESCAPE_P(*cp)) - break; - n = cp - start; - if (n) { - /* NetBSD (0.9 or later), 4.3-Reno or similar. */ - ndone = n - b_to_q(start, n, &tp->t_outq); - len -= ndone; - start += ndone; - sc->sc_stats.ppp_obytes += ndone; - - if (ndone < n) - break; /* packet doesn't fit */ - } - /* - * If there are characters left in the mbuf, - * the first one must be special. - * Put it out in a different form. - */ - if (len) { - s = spltty(); - if (putc(PPP_ESCAPE, &tp->t_outq)) { - splx(s); - break; - } - if (putc(*start ^ PPP_TRANS, &tp->t_outq)) { - (void) unputc(&tp->t_outq); - splx(s); - break; - } - splx(s); - sc->sc_stats.ppp_obytes += 2; - start++; - len--; - } - } - - /* - * If we didn't empty this mbuf, remember where we're up to. - * If we emptied the last mbuf, try to add the FCS and closing - * flag, and if we can't, leave sc_outm pointing to m, but with - * m->m_len == 0, to remind us to output the FCS and flag later. - */ - done = len == 0; - if (done && m->m_next == NULL) { - u_char *p, *q; - int c; - u_char endseq[8]; - - /* - * We may have to escape the bytes in the FCS. - */ - p = endseq; - c = ~sc->sc_outfcs & 0xFF; - if (ESCAPE_P(c)) { - *p++ = PPP_ESCAPE; - *p++ = c ^ PPP_TRANS; - } else - *p++ = c; - c = (~sc->sc_outfcs >> 8) & 0xFF; - if (ESCAPE_P(c)) { - *p++ = PPP_ESCAPE; - *p++ = c ^ PPP_TRANS; - } else - *p++ = c; - *p++ = PPP_FLAG; - - /* - * Try to output the FCS and flag. If the bytes - * don't all fit, back out. - */ - s = spltty(); - for (q = endseq; q < p; ++q) - if (putc(*q, &tp->t_outq)) { - done = 0; - for (; q > endseq; --q) - unputc(&tp->t_outq); - break; - } - splx(s); - if (done) - sc->sc_stats.ppp_obytes += q - endseq; - } - - if (!done) { - /* remember where we got to */ - m->m_data = start; - m->m_len = len; - break; - } - - /* Finished with this mbuf; free it and move on. */ - m = m_free(m); - if (m == NULL) { - /* Finished a packet */ - break; - } - sc->sc_outfcs = pppfcs(sc->sc_outfcs, mtod(m, u_char *), m->m_len); - } - - /* - * If m == NULL, we have finished a packet. - * If m != NULL, we've either done as much work this time - * as we need to, or else we've filled up the output queue. - */ - sc->sc_outm = m; - if (m) - break; - } - - /* Call pppstart to start output again if necessary. */ - s = spltty(); - pppstart(tp); - - /* - * This timeout is needed for operation on a pseudo-tty, - * because the pty code doesn't call pppstart after it has - * drained the t_outq. - */ - if (!idle && (sc->sc_flags & SC_TIMEOUT) == 0) { - callout_reset(&sc->sc_timo_ch, 1, ppp_timeout, sc); - sc->sc_flags |= SC_TIMEOUT; - } - - splx(s); -} - -/* - * This gets called when a received packet is placed on - * the inq, at splsoftnet. The pppd daemon is to be woken up to do a read(). - */ -static void -pppasyncctlp(sc) - struct ppp_softc *sc; -{ - struct tty *tp; - int s; - - /* Put a placeholder byte in canq for ttselect()/ttnread(). */ - s = spltty(); - tp = (struct tty *) sc->sc_devp; - putc(0, &tp->t_canq); - ttwakeup(tp); - splx(s); -} - -/* - * Start output on async tty interface. If the transmit queue - * has drained sufficiently, arrange for pppasyncstart to be - * called later at splsoftnet. - * Called at spltty or higher. - */ -static int -pppstart(tp) - register struct tty *tp; -{ - register struct ppp_softc *sc = (struct ppp_softc *)tp->t_lsc; - - /* - * Call output process whether or not there is any output. - * We are being called in lieu of ttstart and must do what it would. - */ - tt_oproc(tp); - - /* - * If the transmit queue has drained and the tty has not hung up - * or been disconnected from the ppp unit, then tell if_ppp.c that - * we need more output. - */ - if (CCOUNT(&tp->t_outq) < PPP_LOWAT - && !((tp->t_state & TS_CONNECTED) == 0) - && sc != NULL) { - ppp_restart(sc); - } - - return 0; -} - -/* - * Timeout routine - try to start some more output. - */ -static void -ppp_timeout(x) - void *x; -{ - struct ppp_softc *sc = (struct ppp_softc *) x; - struct tty *tp = (struct tty *) sc->sc_devp; - int s; - - s = spltty(); - sc->sc_flags &= ~SC_TIMEOUT; - pppstart(tp); - splx(s); -} - -/* - * Allocate enough mbuf to handle current MRU. - */ -static void -pppgetm(sc) - register struct ppp_softc *sc; -{ - struct mbuf *m, **mp; - int len; - - mp = &sc->sc_m; - for (len = sc->sc_mru + PPP_HDRLEN + PPP_FCSLEN; len > 0; ){ - if ((m = *mp) == NULL) { - MGETHDR(m, M_DONTWAIT, MT_DATA); - if (m == NULL) - break; - *mp = m; - MCLGET(m, M_DONTWAIT); - } - len -= M_DATASIZE(m); - mp = &m->m_next; - } -} - -/* - * tty interface receiver interrupt. - */ -static unsigned paritytab[8] = { - 0x96696996, 0x69969669, 0x69969669, 0x96696996, - 0x69969669, 0x96696996, 0x96696996, 0x69969669 -}; - -/* - * Called when character is available from device driver. - * Only guaranteed to be at splsofttty() or spltty() - * This is safe to be called while the upper half's netisr is preempted. - */ -static int -pppinput(c, tp) - int c; - register struct tty *tp; -{ - register struct ppp_softc *sc; - struct mbuf *m; - int ilen, s; - - sc = (struct ppp_softc *)tp->t_lsc; - if (sc == NULL) - return 0; - - ++tk_nin; - ++sc->sc_stats.ppp_ibytes; - - if ((tp->t_state & TS_CONNECTED) == 0) { - if (sc->sc_flags & SC_DEBUG) - if_printf(PPP2IFP(sc), "no carrier\n"); - goto flush; - } - - if (c & TTY_ERRORMASK) { - /* framing error or overrun on this char - abort packet */ - if (sc->sc_flags & SC_DEBUG) - if_printf(PPP2IFP(sc), "line error %x\n", c & TTY_ERRORMASK); - goto flush; - } - - c &= TTY_CHARMASK; - - /* - * Handle software flow control of output. - */ - if (tp->t_iflag & IXON) { - if (c == tp->t_cc[VSTOP] && tp->t_cc[VSTOP] != _POSIX_VDISABLE) { - if ((tp->t_state & TS_TTSTOP) == 0) { - tp->t_state |= TS_TTSTOP; - tt_stop(tp, 0); - } - return 0; - } - if (c == tp->t_cc[VSTART] && tp->t_cc[VSTART] != _POSIX_VDISABLE) { - tp->t_state &= ~TS_TTSTOP; - tt_oproc(tp); - return 0; - } - } - - s = spltty(); - if (c & 0x80) - sc->sc_flags |= SC_RCV_B7_1; - else - sc->sc_flags |= SC_RCV_B7_0; - if (paritytab[c >> 5] & (1 << (c & 0x1F))) - sc->sc_flags |= SC_RCV_ODDP; - else - sc->sc_flags |= SC_RCV_EVNP; - splx(s); - - if (sc->sc_flags & SC_LOG_RAWIN) - ppplogchar(sc, c); - - if (c == PPP_FLAG) { - ilen = sc->sc_ilen; - sc->sc_ilen = 0; - - if (sc->sc_rawin_count > 0) - ppplogchar(sc, -1); - - /* - * If SC_ESCAPED is set, then we've seen the packet - * abort sequence "}~". - */ - if (sc->sc_flags & (SC_FLUSH | SC_ESCAPED) - || (ilen > 0 && sc->sc_fcs != PPP_GOODFCS)) { - s = spltty(); - sc->sc_flags |= SC_PKTLOST; /* note the dropped packet */ - if ((sc->sc_flags & (SC_FLUSH | SC_ESCAPED)) == 0){ - if (sc->sc_flags & SC_DEBUG) - if_printf(PPP2IFP(sc), "bad fcs %x, pkt len %d\n", - sc->sc_fcs, ilen); - PPP2IFP(sc)->if_ierrors++; - sc->sc_stats.ppp_ierrors++; - } else - sc->sc_flags &= ~(SC_FLUSH | SC_ESCAPED); - splx(s); - return 0; - } - - if (ilen < PPP_HDRLEN + PPP_FCSLEN) { - if (ilen) { - if (sc->sc_flags & SC_DEBUG) - if_printf(PPP2IFP(sc), "too short (%d)\n", ilen); - s = spltty(); - PPP2IFP(sc)->if_ierrors++; - sc->sc_stats.ppp_ierrors++; - sc->sc_flags |= SC_PKTLOST; - splx(s); - } - return 0; - } - - /* - * Remove FCS trailer. Somewhat painful... - */ - ilen -= 2; - if (--sc->sc_mc->m_len == 0) { - for (m = sc->sc_m; m->m_next != sc->sc_mc; m = m->m_next) - ; - sc->sc_mc = m; - } - sc->sc_mc->m_len--; - - /* excise this mbuf chain */ - m = sc->sc_m; - sc->sc_m = sc->sc_mc->m_next; - sc->sc_mc->m_next = NULL; - - ppppktin(sc, m, sc->sc_flags & SC_PKTLOST); - if (sc->sc_flags & SC_PKTLOST) { - s = spltty(); - sc->sc_flags &= ~SC_PKTLOST; - splx(s); - } - - pppgetm(sc); - return 0; - } - - if (sc->sc_flags & SC_FLUSH) { - if (sc->sc_flags & SC_LOG_FLUSH) - ppplogchar(sc, c); - return 0; - } - - if (c < 0x20 && (sc->sc_rasyncmap & (1 << c))) - return 0; - - s = spltty(); - if (sc->sc_flags & SC_ESCAPED) { - sc->sc_flags &= ~SC_ESCAPED; - c ^= PPP_TRANS; - } else if (c == PPP_ESCAPE) { - sc->sc_flags |= SC_ESCAPED; - splx(s); - return 0; - } - splx(s); - - /* - * Initialize buffer on first octet received. - * First octet could be address or protocol (when compressing - * address/control). - * Second octet is control. - * Third octet is first or second (when compressing protocol) - * octet of protocol. - * Fourth octet is second octet of protocol. - */ - if (sc->sc_ilen == 0) { - /* reset the first input mbuf */ - if (sc->sc_m == NULL) { - pppgetm(sc); - if (sc->sc_m == NULL) { - if (sc->sc_flags & SC_DEBUG) - if_printf(PPP2IFP(sc), "no input mbufs!\n"); - goto flush; - } - } - m = sc->sc_m; - m->m_len = 0; - m->m_data = M_DATASTART(sc->sc_m); - sc->sc_mc = m; - sc->sc_mp = mtod(m, char *); - sc->sc_fcs = PPP_INITFCS; - if (c != PPP_ALLSTATIONS) { - if (sc->sc_flags & SC_REJ_COMP_AC) { - if (sc->sc_flags & SC_DEBUG) - if_printf(PPP2IFP(sc), - "garbage received: 0x%x (need 0xFF)\n", c); - goto flush; - } - *sc->sc_mp++ = PPP_ALLSTATIONS; - *sc->sc_mp++ = PPP_UI; - sc->sc_ilen += 2; - m->m_len += 2; - } - } - if (sc->sc_ilen == 1 && c != PPP_UI) { - if (sc->sc_flags & SC_DEBUG) - if_printf(PPP2IFP(sc), "missing UI (0x3), got 0x%x\n", c); - goto flush; - } - if (sc->sc_ilen == 2 && (c & 1) == 1) { - /* a compressed protocol */ - *sc->sc_mp++ = 0; - sc->sc_ilen++; - sc->sc_mc->m_len++; - } - if (sc->sc_ilen == 3 && (c & 1) == 0) { - if (sc->sc_flags & SC_DEBUG) - if_printf(PPP2IFP(sc), "bad protocol %x\n", - (sc->sc_mp[-1] << 8) + c); - goto flush; - } - - /* packet beyond configured mru? */ - if (++sc->sc_ilen > sc->sc_mru + PPP_HDRLEN + PPP_FCSLEN) { - if (sc->sc_flags & SC_DEBUG) - if_printf(PPP2IFP(sc), "packet too big\n"); - goto flush; - } - - /* is this mbuf full? */ - m = sc->sc_mc; - if (M_TRAILINGSPACE(m) <= 0) { - if (m->m_next == NULL) { - pppgetm(sc); - if (m->m_next == NULL) { - if (sc->sc_flags & SC_DEBUG) - if_printf(PPP2IFP(sc), "too few input mbufs!\n"); - goto flush; - } - } - sc->sc_mc = m = m->m_next; - m->m_len = 0; - m->m_data = M_DATASTART(m); - sc->sc_mp = mtod(m, char *); - } - - ++m->m_len; - *sc->sc_mp++ = c; - sc->sc_fcs = PPP_FCS(sc->sc_fcs, c); - return 0; - - flush: - if (!(sc->sc_flags & SC_FLUSH)) { - s = spltty(); - PPP2IFP(sc)->if_ierrors++; - sc->sc_stats.ppp_ierrors++; - sc->sc_flags |= SC_FLUSH; - splx(s); - if (sc->sc_flags & SC_LOG_FLUSH) - ppplogchar(sc, c); - } - return 0; -} - -#define MAX_DUMP_BYTES 128 - -static void -ppplogchar(sc, c) - struct ppp_softc *sc; - int c; -{ - if (c >= 0) - sc->sc_rawin[sc->sc_rawin_count++] = c; - if (sc->sc_rawin_count >= sizeof(sc->sc_rawin) - || (c < 0 && sc->sc_rawin_count > 0)) { - printf("%s input: %*D", PPP2IFP(sc)->if_xname, - sc->sc_rawin_count, sc->sc_rawin, " "); - sc->sc_rawin_count = 0; - } -} diff --git a/sys/net/slip.h b/sys/net/slip.h deleted file mode 100644 index 7b4164e..0000000 --- a/sys/net/slip.h +++ /dev/null @@ -1,58 +0,0 @@ -/*- - * Copyright (c) 1994 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)slip.h 8.1 (Berkeley) 2/12/94 - * $FreeBSD$ - */ - -#ifndef _NET_SLIP_H_ -#define _NET_SLIP_H_ - -/* Ioctls operating on SLIP ttys. */ -#define SLIOCGUNIT _IOR('t', 88, int) /* get slip unit number */ -#define SLIOCSKEEPAL _IOW('t', 84, int) /* set keepalive */ -#define SLIOCSOUTFILL _IOW('t', 83, int) /* set out fill time */ -#define SLIOCGKEEPAL _IOR('t', 82, int) /* get keepalive time */ -#define SLIOCGOUTFILL _IOR('t', 81, int) /* get out fill time */ -#define SLIOCSUNIT _IOW('t', 80, int) /* set slip unit number */ - -/* - * Definitions of the pseudo-link-level header attached to slip - * packets grabbed by the packet filter (bpf) traffic monitor. - */ -#define SLIP_HDRLEN 16 /* BPF SLIP header length */ - -/* Offsets into BPF SLIP header. */ -#define SLX_DIR 0 /* direction; see below */ -#define SLX_CHDR 1 /* compressed header data */ -#define CHDR_LEN 15 /* length of compressed header data */ - -#define SLIPDIR_IN 0 /* incoming */ -#define SLIPDIR_OUT 1 /* outgoing */ - -#endif /* !_NET_SLIP_H */ |