I have a problem getting this to work. Server only recieves half of the data being sent. Whats wrong

Dependencies:   mbed

Committer:
tax
Date:
Tue Mar 29 13:20:15 2011 +0000
Revision:
0:66300c77c6e9

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tax 0:66300c77c6e9 1 /*****************************************************************************
tax 0:66300c77c6e9 2 * lcp.c - Network Link Control Protocol program file.
tax 0:66300c77c6e9 3 *
tax 0:66300c77c6e9 4 * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
tax 0:66300c77c6e9 5 * portions Copyright (c) 1997 by Global Election Systems Inc.
tax 0:66300c77c6e9 6 *
tax 0:66300c77c6e9 7 * The authors hereby grant permission to use, copy, modify, distribute,
tax 0:66300c77c6e9 8 * and license this software and its documentation for any purpose, provided
tax 0:66300c77c6e9 9 * that existing copyright notices are retained in all copies and that this
tax 0:66300c77c6e9 10 * notice and the following disclaimer are included verbatim in any
tax 0:66300c77c6e9 11 * distributions. No written agreement, license, or royalty fee is required
tax 0:66300c77c6e9 12 * for any of the authorized uses.
tax 0:66300c77c6e9 13 *
tax 0:66300c77c6e9 14 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
tax 0:66300c77c6e9 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
tax 0:66300c77c6e9 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
tax 0:66300c77c6e9 17 * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
tax 0:66300c77c6e9 18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
tax 0:66300c77c6e9 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
tax 0:66300c77c6e9 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
tax 0:66300c77c6e9 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
tax 0:66300c77c6e9 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
tax 0:66300c77c6e9 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
tax 0:66300c77c6e9 24 *
tax 0:66300c77c6e9 25 ******************************************************************************
tax 0:66300c77c6e9 26 * REVISION HISTORY
tax 0:66300c77c6e9 27 *
tax 0:66300c77c6e9 28 * 03-01-01 Marc Boucher <marc@mbsi.ca>
tax 0:66300c77c6e9 29 * Ported to lwIP.
tax 0:66300c77c6e9 30 * 97-12-01 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc.
tax 0:66300c77c6e9 31 * Original.
tax 0:66300c77c6e9 32 *****************************************************************************/
tax 0:66300c77c6e9 33
tax 0:66300c77c6e9 34 /*
tax 0:66300c77c6e9 35 * lcp.c - PPP Link Control Protocol.
tax 0:66300c77c6e9 36 *
tax 0:66300c77c6e9 37 * Copyright (c) 1989 Carnegie Mellon University.
tax 0:66300c77c6e9 38 * All rights reserved.
tax 0:66300c77c6e9 39 *
tax 0:66300c77c6e9 40 * Redistribution and use in source and binary forms are permitted
tax 0:66300c77c6e9 41 * provided that the above copyright notice and this paragraph are
tax 0:66300c77c6e9 42 * duplicated in all such forms and that any documentation,
tax 0:66300c77c6e9 43 * advertising materials, and other materials related to such
tax 0:66300c77c6e9 44 * distribution and use acknowledge that the software was developed
tax 0:66300c77c6e9 45 * by Carnegie Mellon University. The name of the
tax 0:66300c77c6e9 46 * University may not be used to endorse or promote products derived
tax 0:66300c77c6e9 47 * from this software without specific prior written permission.
tax 0:66300c77c6e9 48 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
tax 0:66300c77c6e9 49 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
tax 0:66300c77c6e9 50 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
tax 0:66300c77c6e9 51 */
tax 0:66300c77c6e9 52
tax 0:66300c77c6e9 53
tax 0:66300c77c6e9 54 #include "lwip/opt.h"
tax 0:66300c77c6e9 55
tax 0:66300c77c6e9 56 #if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
tax 0:66300c77c6e9 57
tax 0:66300c77c6e9 58 #include "ppp.h"
tax 0:66300c77c6e9 59 #include "pppdebug.h"
tax 0:66300c77c6e9 60
tax 0:66300c77c6e9 61 #include "fsm.h"
tax 0:66300c77c6e9 62 #include "chap.h"
tax 0:66300c77c6e9 63 #include "magic.h"
tax 0:66300c77c6e9 64 #include "auth.h"
tax 0:66300c77c6e9 65 #include "lcp.h"
tax 0:66300c77c6e9 66
tax 0:66300c77c6e9 67 #include <string.h>
tax 0:66300c77c6e9 68
tax 0:66300c77c6e9 69 #if PPPOE_SUPPORT
tax 0:66300c77c6e9 70 #include "netif/ppp_oe.h"
tax 0:66300c77c6e9 71 #else
tax 0:66300c77c6e9 72 #define PPPOE_MAXMTU PPP_MAXMRU
tax 0:66300c77c6e9 73 #endif
tax 0:66300c77c6e9 74
tax 0:66300c77c6e9 75 #if 0 /* UNUSED */
tax 0:66300c77c6e9 76 /*
tax 0:66300c77c6e9 77 * LCP-related command-line options.
tax 0:66300c77c6e9 78 */
tax 0:66300c77c6e9 79 int lcp_echo_interval = 0; /* Interval between LCP echo-requests */
tax 0:66300c77c6e9 80 int lcp_echo_fails = 0; /* Tolerance to unanswered echo-requests */
tax 0:66300c77c6e9 81 bool lax_recv = 0; /* accept control chars in asyncmap */
tax 0:66300c77c6e9 82
tax 0:66300c77c6e9 83 static int setescape (char **);
tax 0:66300c77c6e9 84
tax 0:66300c77c6e9 85 static option_t lcp_option_list[] = {
tax 0:66300c77c6e9 86 /* LCP options */
tax 0:66300c77c6e9 87 /* list stripped for simplicity */
tax 0:66300c77c6e9 88 {NULL}
tax 0:66300c77c6e9 89 };
tax 0:66300c77c6e9 90 #endif /* UNUSED */
tax 0:66300c77c6e9 91
tax 0:66300c77c6e9 92 /* options */
tax 0:66300c77c6e9 93 LinkPhase lcp_phase[NUM_PPP]; /* Phase of link session (RFC 1661) */
tax 0:66300c77c6e9 94 static u_int lcp_echo_interval = LCP_ECHOINTERVAL; /* Interval between LCP echo-requests */
tax 0:66300c77c6e9 95 static u_int lcp_echo_fails = LCP_MAXECHOFAILS; /* Tolerance to unanswered echo-requests */
tax 0:66300c77c6e9 96
tax 0:66300c77c6e9 97 /* global vars */
tax 0:66300c77c6e9 98 static fsm lcp_fsm[NUM_PPP]; /* LCP fsm structure (global)*/
tax 0:66300c77c6e9 99 lcp_options lcp_wantoptions[NUM_PPP]; /* Options that we want to request */
tax 0:66300c77c6e9 100 lcp_options lcp_gotoptions[NUM_PPP]; /* Options that peer ack'd */
tax 0:66300c77c6e9 101 lcp_options lcp_allowoptions[NUM_PPP]; /* Options we allow peer to request */
tax 0:66300c77c6e9 102 lcp_options lcp_hisoptions[NUM_PPP]; /* Options that we ack'd */
tax 0:66300c77c6e9 103 ext_accm xmit_accm[NUM_PPP]; /* extended transmit ACCM */
tax 0:66300c77c6e9 104
tax 0:66300c77c6e9 105 static u32_t lcp_echos_pending = 0; /* Number of outstanding echo msgs */
tax 0:66300c77c6e9 106 static u32_t lcp_echo_number = 0; /* ID number of next echo frame */
tax 0:66300c77c6e9 107 static u32_t lcp_echo_timer_running = 0; /* TRUE if a timer is running */
tax 0:66300c77c6e9 108
tax 0:66300c77c6e9 109 /* @todo: do we really need such a large buffer? The typical 1500 bytes seem too much. */
tax 0:66300c77c6e9 110 static u_char nak_buffer[PPP_MRU]; /* where we construct a nak packet */
tax 0:66300c77c6e9 111
tax 0:66300c77c6e9 112 /*
tax 0:66300c77c6e9 113 * Callbacks for fsm code. (CI = Configuration Information)
tax 0:66300c77c6e9 114 */
tax 0:66300c77c6e9 115 static void lcp_resetci (fsm*); /* Reset our CI */
tax 0:66300c77c6e9 116 static int lcp_cilen (fsm*); /* Return length of our CI */
tax 0:66300c77c6e9 117 static void lcp_addci (fsm*, u_char*, int*); /* Add our CI to pkt */
tax 0:66300c77c6e9 118 static int lcp_ackci (fsm*, u_char*, int); /* Peer ack'd our CI */
tax 0:66300c77c6e9 119 static int lcp_nakci (fsm*, u_char*, int); /* Peer nak'd our CI */
tax 0:66300c77c6e9 120 static int lcp_rejci (fsm*, u_char*, int); /* Peer rej'd our CI */
tax 0:66300c77c6e9 121 static int lcp_reqci (fsm*, u_char*, int*, int); /* Rcv peer CI */
tax 0:66300c77c6e9 122 static void lcp_up (fsm*); /* We're UP */
tax 0:66300c77c6e9 123 static void lcp_down (fsm*); /* We're DOWN */
tax 0:66300c77c6e9 124 static void lcp_starting (fsm*); /* We need lower layer up */
tax 0:66300c77c6e9 125 static void lcp_finished (fsm*); /* We need lower layer down */
tax 0:66300c77c6e9 126 static int lcp_extcode (fsm*, int, u_char, u_char*, int);
tax 0:66300c77c6e9 127 static void lcp_rprotrej (fsm*, u_char*, int);
tax 0:66300c77c6e9 128
tax 0:66300c77c6e9 129 /*
tax 0:66300c77c6e9 130 * routines to send LCP echos to peer
tax 0:66300c77c6e9 131 */
tax 0:66300c77c6e9 132
tax 0:66300c77c6e9 133 static void lcp_echo_lowerup (int);
tax 0:66300c77c6e9 134 static void lcp_echo_lowerdown (int);
tax 0:66300c77c6e9 135 static void LcpEchoTimeout (void*);
tax 0:66300c77c6e9 136 static void lcp_received_echo_reply (fsm*, int, u_char*, int);
tax 0:66300c77c6e9 137 static void LcpSendEchoRequest (fsm*);
tax 0:66300c77c6e9 138 static void LcpLinkFailure (fsm*);
tax 0:66300c77c6e9 139 static void LcpEchoCheck (fsm*);
tax 0:66300c77c6e9 140
tax 0:66300c77c6e9 141 static fsm_callbacks lcp_callbacks = { /* LCP callback routines */
tax 0:66300c77c6e9 142 lcp_resetci, /* Reset our Configuration Information */
tax 0:66300c77c6e9 143 lcp_cilen, /* Length of our Configuration Information */
tax 0:66300c77c6e9 144 lcp_addci, /* Add our Configuration Information */
tax 0:66300c77c6e9 145 lcp_ackci, /* ACK our Configuration Information */
tax 0:66300c77c6e9 146 lcp_nakci, /* NAK our Configuration Information */
tax 0:66300c77c6e9 147 lcp_rejci, /* Reject our Configuration Information */
tax 0:66300c77c6e9 148 lcp_reqci, /* Request peer's Configuration Information */
tax 0:66300c77c6e9 149 lcp_up, /* Called when fsm reaches LS_OPENED state */
tax 0:66300c77c6e9 150 lcp_down, /* Called when fsm leaves LS_OPENED state */
tax 0:66300c77c6e9 151 lcp_starting, /* Called when we want the lower layer up */
tax 0:66300c77c6e9 152 lcp_finished, /* Called when we want the lower layer down */
tax 0:66300c77c6e9 153 NULL, /* Called when Protocol-Reject received */
tax 0:66300c77c6e9 154 NULL, /* Retransmission is necessary */
tax 0:66300c77c6e9 155 lcp_extcode, /* Called to handle LCP-specific codes */
tax 0:66300c77c6e9 156 "LCP" /* String name of protocol */
tax 0:66300c77c6e9 157 };
tax 0:66300c77c6e9 158
tax 0:66300c77c6e9 159 /*
tax 0:66300c77c6e9 160 * Protocol entry points.
tax 0:66300c77c6e9 161 * Some of these are called directly.
tax 0:66300c77c6e9 162 */
tax 0:66300c77c6e9 163
tax 0:66300c77c6e9 164 static void lcp_input (int, u_char *, int);
tax 0:66300c77c6e9 165 static void lcp_protrej (int);
tax 0:66300c77c6e9 166
tax 0:66300c77c6e9 167 struct protent lcp_protent = {
tax 0:66300c77c6e9 168 PPP_LCP,
tax 0:66300c77c6e9 169 lcp_init,
tax 0:66300c77c6e9 170 lcp_input,
tax 0:66300c77c6e9 171 lcp_protrej,
tax 0:66300c77c6e9 172 lcp_lowerup,
tax 0:66300c77c6e9 173 lcp_lowerdown,
tax 0:66300c77c6e9 174 lcp_open,
tax 0:66300c77c6e9 175 lcp_close,
tax 0:66300c77c6e9 176 #if PPP_ADDITIONAL_CALLBACKS
tax 0:66300c77c6e9 177 lcp_printpkt,
tax 0:66300c77c6e9 178 NULL,
tax 0:66300c77c6e9 179 #endif /* PPP_ADDITIONAL_CALLBACKS */
tax 0:66300c77c6e9 180 1,
tax 0:66300c77c6e9 181 "LCP",
tax 0:66300c77c6e9 182 #if PPP_ADDITIONAL_CALLBACKS
tax 0:66300c77c6e9 183 NULL,
tax 0:66300c77c6e9 184 NULL,
tax 0:66300c77c6e9 185 NULL
tax 0:66300c77c6e9 186 #endif /* PPP_ADDITIONAL_CALLBACKS */
tax 0:66300c77c6e9 187 };
tax 0:66300c77c6e9 188
tax 0:66300c77c6e9 189 int lcp_loopbackfail = DEFLOOPBACKFAIL;
tax 0:66300c77c6e9 190
tax 0:66300c77c6e9 191 /*
tax 0:66300c77c6e9 192 * Length of each type of configuration option (in octets)
tax 0:66300c77c6e9 193 */
tax 0:66300c77c6e9 194 #define CILEN_VOID 2
tax 0:66300c77c6e9 195 #define CILEN_CHAR 3
tax 0:66300c77c6e9 196 #define CILEN_SHORT 4 /* CILEN_VOID + sizeof(short) */
tax 0:66300c77c6e9 197 #define CILEN_CHAP 5 /* CILEN_VOID + sizeof(short) + 1 */
tax 0:66300c77c6e9 198 #define CILEN_LONG 6 /* CILEN_VOID + sizeof(long) */
tax 0:66300c77c6e9 199 #define CILEN_LQR 8 /* CILEN_VOID + sizeof(short) + sizeof(long) */
tax 0:66300c77c6e9 200 #define CILEN_CBCP 3
tax 0:66300c77c6e9 201
tax 0:66300c77c6e9 202 #define CODENAME(x) ((x) == CONFACK ? "ACK" : (x) == CONFNAK ? "NAK" : "REJ")
tax 0:66300c77c6e9 203
tax 0:66300c77c6e9 204 #if 0 /* UNUSED */
tax 0:66300c77c6e9 205 /*
tax 0:66300c77c6e9 206 * setescape - add chars to the set we escape on transmission.
tax 0:66300c77c6e9 207 */
tax 0:66300c77c6e9 208 static int
tax 0:66300c77c6e9 209 setescape(argv)
tax 0:66300c77c6e9 210 char **argv;
tax 0:66300c77c6e9 211 {
tax 0:66300c77c6e9 212 int n, ret;
tax 0:66300c77c6e9 213 char *p, *endp;
tax 0:66300c77c6e9 214
tax 0:66300c77c6e9 215 p = *argv;
tax 0:66300c77c6e9 216 ret = 1;
tax 0:66300c77c6e9 217 while (*p) {
tax 0:66300c77c6e9 218 n = strtol(p, &endp, 16);
tax 0:66300c77c6e9 219 if (p == endp) {
tax 0:66300c77c6e9 220 option_error("escape parameter contains invalid hex number '%s'", p);
tax 0:66300c77c6e9 221 return 0;
tax 0:66300c77c6e9 222 }
tax 0:66300c77c6e9 223 p = endp;
tax 0:66300c77c6e9 224 if (n < 0 || n == 0x5E || n > 0xFF) {
tax 0:66300c77c6e9 225 option_error("can't escape character 0x%x", n);
tax 0:66300c77c6e9 226 ret = 0;
tax 0:66300c77c6e9 227 } else
tax 0:66300c77c6e9 228 xmit_accm[0][n >> 5] |= 1 << (n & 0x1F);
tax 0:66300c77c6e9 229 while (*p == ',' || *p == ' ')
tax 0:66300c77c6e9 230 ++p;
tax 0:66300c77c6e9 231 }
tax 0:66300c77c6e9 232 return ret;
tax 0:66300c77c6e9 233 }
tax 0:66300c77c6e9 234 #endif /* UNUSED */
tax 0:66300c77c6e9 235
tax 0:66300c77c6e9 236 /*
tax 0:66300c77c6e9 237 * lcp_init - Initialize LCP.
tax 0:66300c77c6e9 238 */
tax 0:66300c77c6e9 239 void
tax 0:66300c77c6e9 240 lcp_init(int unit)
tax 0:66300c77c6e9 241 {
tax 0:66300c77c6e9 242 fsm *f = &lcp_fsm[unit];
tax 0:66300c77c6e9 243 lcp_options *wo = &lcp_wantoptions[unit];
tax 0:66300c77c6e9 244 lcp_options *ao = &lcp_allowoptions[unit];
tax 0:66300c77c6e9 245
tax 0:66300c77c6e9 246 f->unit = unit;
tax 0:66300c77c6e9 247 f->protocol = PPP_LCP;
tax 0:66300c77c6e9 248 f->callbacks = &lcp_callbacks;
tax 0:66300c77c6e9 249
tax 0:66300c77c6e9 250 fsm_init(f);
tax 0:66300c77c6e9 251
tax 0:66300c77c6e9 252 wo->passive = 0;
tax 0:66300c77c6e9 253 wo->silent = 0;
tax 0:66300c77c6e9 254 wo->restart = 0; /* Set to 1 in kernels or multi-line implementations */
tax 0:66300c77c6e9 255 wo->neg_mru = 1;
tax 0:66300c77c6e9 256 wo->mru = PPP_DEFMRU;
tax 0:66300c77c6e9 257 wo->neg_asyncmap = 1;
tax 0:66300c77c6e9 258 wo->asyncmap = 0x00000000l; /* Assume don't need to escape any ctl chars. */
tax 0:66300c77c6e9 259 wo->neg_chap = 0; /* Set to 1 on server */
tax 0:66300c77c6e9 260 wo->neg_upap = 0; /* Set to 1 on server */
tax 0:66300c77c6e9 261 wo->chap_mdtype = CHAP_DIGEST_MD5;
tax 0:66300c77c6e9 262 wo->neg_magicnumber = 1;
tax 0:66300c77c6e9 263 wo->neg_pcompression = 1;
tax 0:66300c77c6e9 264 wo->neg_accompression = 1;
tax 0:66300c77c6e9 265 wo->neg_lqr = 0; /* no LQR implementation yet */
tax 0:66300c77c6e9 266 wo->neg_cbcp = 0;
tax 0:66300c77c6e9 267
tax 0:66300c77c6e9 268 ao->neg_mru = 1;
tax 0:66300c77c6e9 269 ao->mru = PPP_MAXMRU;
tax 0:66300c77c6e9 270 ao->neg_asyncmap = 1;
tax 0:66300c77c6e9 271 ao->asyncmap = 0x00000000l; /* Assume don't need to escape any ctl chars. */
tax 0:66300c77c6e9 272 ao->neg_chap = (CHAP_SUPPORT != 0);
tax 0:66300c77c6e9 273 ao->chap_mdtype = CHAP_DIGEST_MD5;
tax 0:66300c77c6e9 274 ao->neg_upap = (PAP_SUPPORT != 0);
tax 0:66300c77c6e9 275 ao->neg_magicnumber = 1;
tax 0:66300c77c6e9 276 ao->neg_pcompression = 1;
tax 0:66300c77c6e9 277 ao->neg_accompression = 1;
tax 0:66300c77c6e9 278 ao->neg_lqr = 0; /* no LQR implementation yet */
tax 0:66300c77c6e9 279 ao->neg_cbcp = (CBCP_SUPPORT != 0);
tax 0:66300c77c6e9 280
tax 0:66300c77c6e9 281 /*
tax 0:66300c77c6e9 282 * Set transmit escape for the flag and escape characters plus anything
tax 0:66300c77c6e9 283 * set for the allowable options.
tax 0:66300c77c6e9 284 */
tax 0:66300c77c6e9 285 memset(xmit_accm[unit], 0, sizeof(xmit_accm[0]));
tax 0:66300c77c6e9 286 xmit_accm[unit][15] = 0x60;
tax 0:66300c77c6e9 287 xmit_accm[unit][0] = (u_char)((ao->asyncmap & 0xFF));
tax 0:66300c77c6e9 288 xmit_accm[unit][1] = (u_char)((ao->asyncmap >> 8) & 0xFF);
tax 0:66300c77c6e9 289 xmit_accm[unit][2] = (u_char)((ao->asyncmap >> 16) & 0xFF);
tax 0:66300c77c6e9 290 xmit_accm[unit][3] = (u_char)((ao->asyncmap >> 24) & 0xFF);
tax 0:66300c77c6e9 291 LCPDEBUG(LOG_INFO, ("lcp_init: xmit_accm=%X %X %X %X\n",
tax 0:66300c77c6e9 292 xmit_accm[unit][0],
tax 0:66300c77c6e9 293 xmit_accm[unit][1],
tax 0:66300c77c6e9 294 xmit_accm[unit][2],
tax 0:66300c77c6e9 295 xmit_accm[unit][3]));
tax 0:66300c77c6e9 296
tax 0:66300c77c6e9 297 lcp_phase[unit] = PHASE_INITIALIZE;
tax 0:66300c77c6e9 298 }
tax 0:66300c77c6e9 299
tax 0:66300c77c6e9 300
tax 0:66300c77c6e9 301 /*
tax 0:66300c77c6e9 302 * lcp_open - LCP is allowed to come up.
tax 0:66300c77c6e9 303 */
tax 0:66300c77c6e9 304 void
tax 0:66300c77c6e9 305 lcp_open(int unit)
tax 0:66300c77c6e9 306 {
tax 0:66300c77c6e9 307 fsm *f = &lcp_fsm[unit];
tax 0:66300c77c6e9 308 lcp_options *wo = &lcp_wantoptions[unit];
tax 0:66300c77c6e9 309
tax 0:66300c77c6e9 310 f->flags = 0;
tax 0:66300c77c6e9 311 if (wo->passive) {
tax 0:66300c77c6e9 312 f->flags |= OPT_PASSIVE;
tax 0:66300c77c6e9 313 }
tax 0:66300c77c6e9 314 if (wo->silent) {
tax 0:66300c77c6e9 315 f->flags |= OPT_SILENT;
tax 0:66300c77c6e9 316 }
tax 0:66300c77c6e9 317 fsm_open(f);
tax 0:66300c77c6e9 318
tax 0:66300c77c6e9 319 lcp_phase[unit] = PHASE_ESTABLISH;
tax 0:66300c77c6e9 320 }
tax 0:66300c77c6e9 321
tax 0:66300c77c6e9 322
tax 0:66300c77c6e9 323 /*
tax 0:66300c77c6e9 324 * lcp_close - Take LCP down.
tax 0:66300c77c6e9 325 */
tax 0:66300c77c6e9 326 void
tax 0:66300c77c6e9 327 lcp_close(int unit, char *reason)
tax 0:66300c77c6e9 328 {
tax 0:66300c77c6e9 329 fsm *f = &lcp_fsm[unit];
tax 0:66300c77c6e9 330
tax 0:66300c77c6e9 331 if (lcp_phase[unit] != PHASE_DEAD) {
tax 0:66300c77c6e9 332 lcp_phase[unit] = PHASE_TERMINATE;
tax 0:66300c77c6e9 333 }
tax 0:66300c77c6e9 334 if (f->state == LS_STOPPED && f->flags & (OPT_PASSIVE|OPT_SILENT)) {
tax 0:66300c77c6e9 335 /*
tax 0:66300c77c6e9 336 * This action is not strictly according to the FSM in RFC1548,
tax 0:66300c77c6e9 337 * but it does mean that the program terminates if you do an
tax 0:66300c77c6e9 338 * lcp_close() in passive/silent mode when a connection hasn't
tax 0:66300c77c6e9 339 * been established.
tax 0:66300c77c6e9 340 */
tax 0:66300c77c6e9 341 f->state = LS_CLOSED;
tax 0:66300c77c6e9 342 lcp_finished(f);
tax 0:66300c77c6e9 343 } else {
tax 0:66300c77c6e9 344 fsm_close(f, reason);
tax 0:66300c77c6e9 345 }
tax 0:66300c77c6e9 346 }
tax 0:66300c77c6e9 347
tax 0:66300c77c6e9 348
tax 0:66300c77c6e9 349 /*
tax 0:66300c77c6e9 350 * lcp_lowerup - The lower layer is up.
tax 0:66300c77c6e9 351 */
tax 0:66300c77c6e9 352 void
tax 0:66300c77c6e9 353 lcp_lowerup(int unit)
tax 0:66300c77c6e9 354 {
tax 0:66300c77c6e9 355 lcp_options *wo = &lcp_wantoptions[unit];
tax 0:66300c77c6e9 356
tax 0:66300c77c6e9 357 /*
tax 0:66300c77c6e9 358 * Don't use A/C or protocol compression on transmission,
tax 0:66300c77c6e9 359 * but accept A/C and protocol compressed packets
tax 0:66300c77c6e9 360 * if we are going to ask for A/C and protocol compression.
tax 0:66300c77c6e9 361 */
tax 0:66300c77c6e9 362 ppp_set_xaccm(unit, &xmit_accm[unit]);
tax 0:66300c77c6e9 363 ppp_send_config(unit, PPP_MRU, 0xffffffffl, 0, 0);
tax 0:66300c77c6e9 364 ppp_recv_config(unit, PPP_MRU, 0x00000000l,
tax 0:66300c77c6e9 365 wo->neg_pcompression, wo->neg_accompression);
tax 0:66300c77c6e9 366 peer_mru[unit] = PPP_MRU;
tax 0:66300c77c6e9 367 lcp_allowoptions[unit].asyncmap = (u_long)xmit_accm[unit][0]
tax 0:66300c77c6e9 368 | ((u_long)xmit_accm[unit][1] << 8)
tax 0:66300c77c6e9 369 | ((u_long)xmit_accm[unit][2] << 16)
tax 0:66300c77c6e9 370 | ((u_long)xmit_accm[unit][3] << 24);
tax 0:66300c77c6e9 371 LCPDEBUG(LOG_INFO, ("lcp_lowerup: asyncmap=%X %X %X %X\n",
tax 0:66300c77c6e9 372 xmit_accm[unit][3],
tax 0:66300c77c6e9 373 xmit_accm[unit][2],
tax 0:66300c77c6e9 374 xmit_accm[unit][1],
tax 0:66300c77c6e9 375 xmit_accm[unit][0]));
tax 0:66300c77c6e9 376
tax 0:66300c77c6e9 377 fsm_lowerup(&lcp_fsm[unit]);
tax 0:66300c77c6e9 378 }
tax 0:66300c77c6e9 379
tax 0:66300c77c6e9 380
tax 0:66300c77c6e9 381 /*
tax 0:66300c77c6e9 382 * lcp_lowerdown - The lower layer is down.
tax 0:66300c77c6e9 383 */
tax 0:66300c77c6e9 384 void
tax 0:66300c77c6e9 385 lcp_lowerdown(int unit)
tax 0:66300c77c6e9 386 {
tax 0:66300c77c6e9 387 fsm_lowerdown(&lcp_fsm[unit]);
tax 0:66300c77c6e9 388 }
tax 0:66300c77c6e9 389
tax 0:66300c77c6e9 390
tax 0:66300c77c6e9 391 /*
tax 0:66300c77c6e9 392 * lcp_input - Input LCP packet.
tax 0:66300c77c6e9 393 */
tax 0:66300c77c6e9 394 static void
tax 0:66300c77c6e9 395 lcp_input(int unit, u_char *p, int len)
tax 0:66300c77c6e9 396 {
tax 0:66300c77c6e9 397 fsm *f = &lcp_fsm[unit];
tax 0:66300c77c6e9 398
tax 0:66300c77c6e9 399 fsm_input(f, p, len);
tax 0:66300c77c6e9 400 }
tax 0:66300c77c6e9 401
tax 0:66300c77c6e9 402
tax 0:66300c77c6e9 403 /*
tax 0:66300c77c6e9 404 * lcp_extcode - Handle a LCP-specific code.
tax 0:66300c77c6e9 405 */
tax 0:66300c77c6e9 406 static int
tax 0:66300c77c6e9 407 lcp_extcode(fsm *f, int code, u_char id, u_char *inp, int len)
tax 0:66300c77c6e9 408 {
tax 0:66300c77c6e9 409 u_char *magp;
tax 0:66300c77c6e9 410
tax 0:66300c77c6e9 411 switch( code ){
tax 0:66300c77c6e9 412 case PROTREJ:
tax 0:66300c77c6e9 413 lcp_rprotrej(f, inp, len);
tax 0:66300c77c6e9 414 break;
tax 0:66300c77c6e9 415
tax 0:66300c77c6e9 416 case ECHOREQ:
tax 0:66300c77c6e9 417 if (f->state != LS_OPENED) {
tax 0:66300c77c6e9 418 break;
tax 0:66300c77c6e9 419 }
tax 0:66300c77c6e9 420 LCPDEBUG(LOG_INFO, ("lcp: Echo-Request, Rcvd id %d\n", id));
tax 0:66300c77c6e9 421 magp = inp;
tax 0:66300c77c6e9 422 PUTLONG(lcp_gotoptions[f->unit].magicnumber, magp);
tax 0:66300c77c6e9 423 fsm_sdata(f, ECHOREP, id, inp, len);
tax 0:66300c77c6e9 424 break;
tax 0:66300c77c6e9 425
tax 0:66300c77c6e9 426 case ECHOREP:
tax 0:66300c77c6e9 427 lcp_received_echo_reply(f, id, inp, len);
tax 0:66300c77c6e9 428 break;
tax 0:66300c77c6e9 429
tax 0:66300c77c6e9 430 case DISCREQ:
tax 0:66300c77c6e9 431 break;
tax 0:66300c77c6e9 432
tax 0:66300c77c6e9 433 default:
tax 0:66300c77c6e9 434 return 0;
tax 0:66300c77c6e9 435 }
tax 0:66300c77c6e9 436 return 1;
tax 0:66300c77c6e9 437 }
tax 0:66300c77c6e9 438
tax 0:66300c77c6e9 439
tax 0:66300c77c6e9 440 /*
tax 0:66300c77c6e9 441 * lcp_rprotrej - Receive an Protocol-Reject.
tax 0:66300c77c6e9 442 *
tax 0:66300c77c6e9 443 * Figure out which protocol is rejected and inform it.
tax 0:66300c77c6e9 444 */
tax 0:66300c77c6e9 445 static void
tax 0:66300c77c6e9 446 lcp_rprotrej(fsm *f, u_char *inp, int len)
tax 0:66300c77c6e9 447 {
tax 0:66300c77c6e9 448 int i;
tax 0:66300c77c6e9 449 struct protent *protp;
tax 0:66300c77c6e9 450 u_short prot;
tax 0:66300c77c6e9 451
tax 0:66300c77c6e9 452 if (len < (int)sizeof (u_short)) {
tax 0:66300c77c6e9 453 LCPDEBUG(LOG_INFO, ("lcp_rprotrej: Rcvd short Protocol-Reject packet!\n"));
tax 0:66300c77c6e9 454 return;
tax 0:66300c77c6e9 455 }
tax 0:66300c77c6e9 456
tax 0:66300c77c6e9 457 GETSHORT(prot, inp);
tax 0:66300c77c6e9 458
tax 0:66300c77c6e9 459 LCPDEBUG(LOG_INFO, ("lcp_rprotrej: Rcvd Protocol-Reject packet for %x!\n", prot));
tax 0:66300c77c6e9 460
tax 0:66300c77c6e9 461 /*
tax 0:66300c77c6e9 462 * Protocol-Reject packets received in any state other than the LCP
tax 0:66300c77c6e9 463 * LS_OPENED state SHOULD be silently discarded.
tax 0:66300c77c6e9 464 */
tax 0:66300c77c6e9 465 if( f->state != LS_OPENED ) {
tax 0:66300c77c6e9 466 LCPDEBUG(LOG_INFO, ("Protocol-Reject discarded: LCP in state %d\n", f->state));
tax 0:66300c77c6e9 467 return;
tax 0:66300c77c6e9 468 }
tax 0:66300c77c6e9 469
tax 0:66300c77c6e9 470 /*
tax 0:66300c77c6e9 471 * Upcall the proper Protocol-Reject routine.
tax 0:66300c77c6e9 472 */
tax 0:66300c77c6e9 473 for (i = 0; (protp = ppp_protocols[i]) != NULL; ++i) {
tax 0:66300c77c6e9 474 if (protp->protocol == prot && protp->enabled_flag) {
tax 0:66300c77c6e9 475 (*protp->protrej)(f->unit);
tax 0:66300c77c6e9 476 return;
tax 0:66300c77c6e9 477 }
tax 0:66300c77c6e9 478 }
tax 0:66300c77c6e9 479
tax 0:66300c77c6e9 480 LCPDEBUG(LOG_WARNING, ("Protocol-Reject for unsupported protocol 0x%x\n", prot));
tax 0:66300c77c6e9 481 }
tax 0:66300c77c6e9 482
tax 0:66300c77c6e9 483
tax 0:66300c77c6e9 484 /*
tax 0:66300c77c6e9 485 * lcp_protrej - A Protocol-Reject was received.
tax 0:66300c77c6e9 486 */
tax 0:66300c77c6e9 487 static void
tax 0:66300c77c6e9 488 lcp_protrej(int unit)
tax 0:66300c77c6e9 489 {
tax 0:66300c77c6e9 490 LWIP_UNUSED_ARG(unit);
tax 0:66300c77c6e9 491 /*
tax 0:66300c77c6e9 492 * Can't reject LCP!
tax 0:66300c77c6e9 493 */
tax 0:66300c77c6e9 494 LCPDEBUG(LOG_WARNING, ("lcp_protrej: Received Protocol-Reject for LCP!\n"));
tax 0:66300c77c6e9 495 fsm_protreject(&lcp_fsm[unit]);
tax 0:66300c77c6e9 496 }
tax 0:66300c77c6e9 497
tax 0:66300c77c6e9 498
tax 0:66300c77c6e9 499 /*
tax 0:66300c77c6e9 500 * lcp_sprotrej - Send a Protocol-Reject for some protocol.
tax 0:66300c77c6e9 501 */
tax 0:66300c77c6e9 502 void
tax 0:66300c77c6e9 503 lcp_sprotrej(int unit, u_char *p, int len)
tax 0:66300c77c6e9 504 {
tax 0:66300c77c6e9 505 /*
tax 0:66300c77c6e9 506 * Send back the protocol and the information field of the
tax 0:66300c77c6e9 507 * rejected packet. We only get here if LCP is in the LS_OPENED state.
tax 0:66300c77c6e9 508 */
tax 0:66300c77c6e9 509
tax 0:66300c77c6e9 510 fsm_sdata(&lcp_fsm[unit], PROTREJ, ++lcp_fsm[unit].id, p, len);
tax 0:66300c77c6e9 511 }
tax 0:66300c77c6e9 512
tax 0:66300c77c6e9 513
tax 0:66300c77c6e9 514 /*
tax 0:66300c77c6e9 515 * lcp_resetci - Reset our CI.
tax 0:66300c77c6e9 516 */
tax 0:66300c77c6e9 517 static void
tax 0:66300c77c6e9 518 lcp_resetci(fsm *f)
tax 0:66300c77c6e9 519 {
tax 0:66300c77c6e9 520 lcp_wantoptions[f->unit].magicnumber = magic();
tax 0:66300c77c6e9 521 lcp_wantoptions[f->unit].numloops = 0;
tax 0:66300c77c6e9 522 lcp_gotoptions[f->unit] = lcp_wantoptions[f->unit];
tax 0:66300c77c6e9 523 peer_mru[f->unit] = PPP_MRU;
tax 0:66300c77c6e9 524 auth_reset(f->unit);
tax 0:66300c77c6e9 525 }
tax 0:66300c77c6e9 526
tax 0:66300c77c6e9 527
tax 0:66300c77c6e9 528 /*
tax 0:66300c77c6e9 529 * lcp_cilen - Return length of our CI.
tax 0:66300c77c6e9 530 */
tax 0:66300c77c6e9 531 static int
tax 0:66300c77c6e9 532 lcp_cilen(fsm *f)
tax 0:66300c77c6e9 533 {
tax 0:66300c77c6e9 534 lcp_options *go = &lcp_gotoptions[f->unit];
tax 0:66300c77c6e9 535
tax 0:66300c77c6e9 536 #define LENCIVOID(neg) ((neg) ? CILEN_VOID : 0)
tax 0:66300c77c6e9 537 #define LENCICHAP(neg) ((neg) ? CILEN_CHAP : 0)
tax 0:66300c77c6e9 538 #define LENCISHORT(neg) ((neg) ? CILEN_SHORT : 0)
tax 0:66300c77c6e9 539 #define LENCILONG(neg) ((neg) ? CILEN_LONG : 0)
tax 0:66300c77c6e9 540 #define LENCILQR(neg) ((neg) ? CILEN_LQR: 0)
tax 0:66300c77c6e9 541 #define LENCICBCP(neg) ((neg) ? CILEN_CBCP: 0)
tax 0:66300c77c6e9 542 /*
tax 0:66300c77c6e9 543 * NB: we only ask for one of CHAP and UPAP, even if we will
tax 0:66300c77c6e9 544 * accept either.
tax 0:66300c77c6e9 545 */
tax 0:66300c77c6e9 546 return (LENCISHORT(go->neg_mru && go->mru != PPP_DEFMRU) +
tax 0:66300c77c6e9 547 LENCILONG(go->neg_asyncmap && go->asyncmap != 0xFFFFFFFFl) +
tax 0:66300c77c6e9 548 LENCICHAP(go->neg_chap) +
tax 0:66300c77c6e9 549 LENCISHORT(!go->neg_chap && go->neg_upap) +
tax 0:66300c77c6e9 550 LENCILQR(go->neg_lqr) +
tax 0:66300c77c6e9 551 LENCICBCP(go->neg_cbcp) +
tax 0:66300c77c6e9 552 LENCILONG(go->neg_magicnumber) +
tax 0:66300c77c6e9 553 LENCIVOID(go->neg_pcompression) +
tax 0:66300c77c6e9 554 LENCIVOID(go->neg_accompression));
tax 0:66300c77c6e9 555 }
tax 0:66300c77c6e9 556
tax 0:66300c77c6e9 557
tax 0:66300c77c6e9 558 /*
tax 0:66300c77c6e9 559 * lcp_addci - Add our desired CIs to a packet.
tax 0:66300c77c6e9 560 */
tax 0:66300c77c6e9 561 static void
tax 0:66300c77c6e9 562 lcp_addci(fsm *f, u_char *ucp, int *lenp)
tax 0:66300c77c6e9 563 {
tax 0:66300c77c6e9 564 lcp_options *go = &lcp_gotoptions[f->unit];
tax 0:66300c77c6e9 565 u_char *start_ucp = ucp;
tax 0:66300c77c6e9 566
tax 0:66300c77c6e9 567 #define ADDCIVOID(opt, neg) \
tax 0:66300c77c6e9 568 if (neg) { \
tax 0:66300c77c6e9 569 LCPDEBUG(LOG_INFO, ("lcp_addci: opt=%d\n", opt)); \
tax 0:66300c77c6e9 570 PUTCHAR(opt, ucp); \
tax 0:66300c77c6e9 571 PUTCHAR(CILEN_VOID, ucp); \
tax 0:66300c77c6e9 572 }
tax 0:66300c77c6e9 573 #define ADDCISHORT(opt, neg, val) \
tax 0:66300c77c6e9 574 if (neg) { \
tax 0:66300c77c6e9 575 LCPDEBUG(LOG_INFO, ("lcp_addci: INT opt=%d %X\n", opt, val)); \
tax 0:66300c77c6e9 576 PUTCHAR(opt, ucp); \
tax 0:66300c77c6e9 577 PUTCHAR(CILEN_SHORT, ucp); \
tax 0:66300c77c6e9 578 PUTSHORT(val, ucp); \
tax 0:66300c77c6e9 579 }
tax 0:66300c77c6e9 580 #define ADDCICHAP(opt, neg, val, digest) \
tax 0:66300c77c6e9 581 if (neg) { \
tax 0:66300c77c6e9 582 LCPDEBUG(LOG_INFO, ("lcp_addci: CHAP opt=%d %X\n", opt, val)); \
tax 0:66300c77c6e9 583 PUTCHAR(opt, ucp); \
tax 0:66300c77c6e9 584 PUTCHAR(CILEN_CHAP, ucp); \
tax 0:66300c77c6e9 585 PUTSHORT(val, ucp); \
tax 0:66300c77c6e9 586 PUTCHAR(digest, ucp); \
tax 0:66300c77c6e9 587 }
tax 0:66300c77c6e9 588 #define ADDCILONG(opt, neg, val) \
tax 0:66300c77c6e9 589 if (neg) { \
tax 0:66300c77c6e9 590 LCPDEBUG(LOG_INFO, ("lcp_addci: L opt=%d %lX\n", opt, val)); \
tax 0:66300c77c6e9 591 PUTCHAR(opt, ucp); \
tax 0:66300c77c6e9 592 PUTCHAR(CILEN_LONG, ucp); \
tax 0:66300c77c6e9 593 PUTLONG(val, ucp); \
tax 0:66300c77c6e9 594 }
tax 0:66300c77c6e9 595 #define ADDCILQR(opt, neg, val) \
tax 0:66300c77c6e9 596 if (neg) { \
tax 0:66300c77c6e9 597 LCPDEBUG(LOG_INFO, ("lcp_addci: LQR opt=%d %lX\n", opt, val)); \
tax 0:66300c77c6e9 598 PUTCHAR(opt, ucp); \
tax 0:66300c77c6e9 599 PUTCHAR(CILEN_LQR, ucp); \
tax 0:66300c77c6e9 600 PUTSHORT(PPP_LQR, ucp); \
tax 0:66300c77c6e9 601 PUTLONG(val, ucp); \
tax 0:66300c77c6e9 602 }
tax 0:66300c77c6e9 603 #define ADDCICHAR(opt, neg, val) \
tax 0:66300c77c6e9 604 if (neg) { \
tax 0:66300c77c6e9 605 LCPDEBUG(LOG_INFO, ("lcp_addci: CHAR opt=%d %X '%z'\n", opt, val, val)); \
tax 0:66300c77c6e9 606 PUTCHAR(opt, ucp); \
tax 0:66300c77c6e9 607 PUTCHAR(CILEN_CHAR, ucp); \
tax 0:66300c77c6e9 608 PUTCHAR(val, ucp); \
tax 0:66300c77c6e9 609 }
tax 0:66300c77c6e9 610
tax 0:66300c77c6e9 611 ADDCISHORT(CI_MRU, go->neg_mru && go->mru != PPP_DEFMRU, go->mru);
tax 0:66300c77c6e9 612 ADDCILONG(CI_ASYNCMAP, go->neg_asyncmap && go->asyncmap != 0xFFFFFFFFl, go->asyncmap);
tax 0:66300c77c6e9 613 ADDCICHAP(CI_AUTHTYPE, go->neg_chap, PPP_CHAP, go->chap_mdtype);
tax 0:66300c77c6e9 614 ADDCISHORT(CI_AUTHTYPE, !go->neg_chap && go->neg_upap, PPP_PAP);
tax 0:66300c77c6e9 615 ADDCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period);
tax 0:66300c77c6e9 616 ADDCICHAR(CI_CALLBACK, go->neg_cbcp, CBCP_OPT);
tax 0:66300c77c6e9 617 ADDCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber);
tax 0:66300c77c6e9 618 ADDCIVOID(CI_PCOMPRESSION, go->neg_pcompression);
tax 0:66300c77c6e9 619 ADDCIVOID(CI_ACCOMPRESSION, go->neg_accompression);
tax 0:66300c77c6e9 620
tax 0:66300c77c6e9 621 if (ucp - start_ucp != *lenp) {
tax 0:66300c77c6e9 622 /* this should never happen, because peer_mtu should be 1500 */
tax 0:66300c77c6e9 623 LCPDEBUG(LOG_ERR, ("Bug in lcp_addci: wrong length\n"));
tax 0:66300c77c6e9 624 }
tax 0:66300c77c6e9 625 }
tax 0:66300c77c6e9 626
tax 0:66300c77c6e9 627
tax 0:66300c77c6e9 628 /*
tax 0:66300c77c6e9 629 * lcp_ackci - Ack our CIs.
tax 0:66300c77c6e9 630 * This should not modify any state if the Ack is bad.
tax 0:66300c77c6e9 631 *
tax 0:66300c77c6e9 632 * Returns:
tax 0:66300c77c6e9 633 * 0 - Ack was bad.
tax 0:66300c77c6e9 634 * 1 - Ack was good.
tax 0:66300c77c6e9 635 */
tax 0:66300c77c6e9 636 static int
tax 0:66300c77c6e9 637 lcp_ackci(fsm *f, u_char *p, int len)
tax 0:66300c77c6e9 638 {
tax 0:66300c77c6e9 639 lcp_options *go = &lcp_gotoptions[f->unit];
tax 0:66300c77c6e9 640 u_char cilen, citype, cichar;
tax 0:66300c77c6e9 641 u_short cishort;
tax 0:66300c77c6e9 642 u32_t cilong;
tax 0:66300c77c6e9 643
tax 0:66300c77c6e9 644 /*
tax 0:66300c77c6e9 645 * CIs must be in exactly the same order that we sent.
tax 0:66300c77c6e9 646 * Check packet length and CI length at each step.
tax 0:66300c77c6e9 647 * If we find any deviations, then this packet is bad.
tax 0:66300c77c6e9 648 */
tax 0:66300c77c6e9 649 #define ACKCIVOID(opt, neg) \
tax 0:66300c77c6e9 650 if (neg) { \
tax 0:66300c77c6e9 651 if ((len -= CILEN_VOID) < 0) \
tax 0:66300c77c6e9 652 goto bad; \
tax 0:66300c77c6e9 653 GETCHAR(citype, p); \
tax 0:66300c77c6e9 654 GETCHAR(cilen, p); \
tax 0:66300c77c6e9 655 if (cilen != CILEN_VOID || citype != opt) \
tax 0:66300c77c6e9 656 goto bad; \
tax 0:66300c77c6e9 657 }
tax 0:66300c77c6e9 658 #define ACKCISHORT(opt, neg, val) \
tax 0:66300c77c6e9 659 if (neg) { \
tax 0:66300c77c6e9 660 if ((len -= CILEN_SHORT) < 0) \
tax 0:66300c77c6e9 661 goto bad; \
tax 0:66300c77c6e9 662 GETCHAR(citype, p); \
tax 0:66300c77c6e9 663 GETCHAR(cilen, p); \
tax 0:66300c77c6e9 664 if (cilen != CILEN_SHORT || citype != opt) \
tax 0:66300c77c6e9 665 goto bad; \
tax 0:66300c77c6e9 666 GETSHORT(cishort, p); \
tax 0:66300c77c6e9 667 if (cishort != val) \
tax 0:66300c77c6e9 668 goto bad; \
tax 0:66300c77c6e9 669 }
tax 0:66300c77c6e9 670 #define ACKCICHAR(opt, neg, val) \
tax 0:66300c77c6e9 671 if (neg) { \
tax 0:66300c77c6e9 672 if ((len -= CILEN_CHAR) < 0) \
tax 0:66300c77c6e9 673 goto bad; \
tax 0:66300c77c6e9 674 GETCHAR(citype, p); \
tax 0:66300c77c6e9 675 GETCHAR(cilen, p); \
tax 0:66300c77c6e9 676 if (cilen != CILEN_CHAR || citype != opt) \
tax 0:66300c77c6e9 677 goto bad; \
tax 0:66300c77c6e9 678 GETCHAR(cichar, p); \
tax 0:66300c77c6e9 679 if (cichar != val) \
tax 0:66300c77c6e9 680 goto bad; \
tax 0:66300c77c6e9 681 }
tax 0:66300c77c6e9 682 #define ACKCICHAP(opt, neg, val, digest) \
tax 0:66300c77c6e9 683 if (neg) { \
tax 0:66300c77c6e9 684 if ((len -= CILEN_CHAP) < 0) \
tax 0:66300c77c6e9 685 goto bad; \
tax 0:66300c77c6e9 686 GETCHAR(citype, p); \
tax 0:66300c77c6e9 687 GETCHAR(cilen, p); \
tax 0:66300c77c6e9 688 if (cilen != CILEN_CHAP || citype != opt) \
tax 0:66300c77c6e9 689 goto bad; \
tax 0:66300c77c6e9 690 GETSHORT(cishort, p); \
tax 0:66300c77c6e9 691 if (cishort != val) \
tax 0:66300c77c6e9 692 goto bad; \
tax 0:66300c77c6e9 693 GETCHAR(cichar, p); \
tax 0:66300c77c6e9 694 if (cichar != digest) \
tax 0:66300c77c6e9 695 goto bad; \
tax 0:66300c77c6e9 696 }
tax 0:66300c77c6e9 697 #define ACKCILONG(opt, neg, val) \
tax 0:66300c77c6e9 698 if (neg) { \
tax 0:66300c77c6e9 699 if ((len -= CILEN_LONG) < 0) \
tax 0:66300c77c6e9 700 goto bad; \
tax 0:66300c77c6e9 701 GETCHAR(citype, p); \
tax 0:66300c77c6e9 702 GETCHAR(cilen, p); \
tax 0:66300c77c6e9 703 if (cilen != CILEN_LONG || citype != opt) \
tax 0:66300c77c6e9 704 goto bad; \
tax 0:66300c77c6e9 705 GETLONG(cilong, p); \
tax 0:66300c77c6e9 706 if (cilong != val) \
tax 0:66300c77c6e9 707 goto bad; \
tax 0:66300c77c6e9 708 }
tax 0:66300c77c6e9 709 #define ACKCILQR(opt, neg, val) \
tax 0:66300c77c6e9 710 if (neg) { \
tax 0:66300c77c6e9 711 if ((len -= CILEN_LQR) < 0) \
tax 0:66300c77c6e9 712 goto bad; \
tax 0:66300c77c6e9 713 GETCHAR(citype, p); \
tax 0:66300c77c6e9 714 GETCHAR(cilen, p); \
tax 0:66300c77c6e9 715 if (cilen != CILEN_LQR || citype != opt) \
tax 0:66300c77c6e9 716 goto bad; \
tax 0:66300c77c6e9 717 GETSHORT(cishort, p); \
tax 0:66300c77c6e9 718 if (cishort != PPP_LQR) \
tax 0:66300c77c6e9 719 goto bad; \
tax 0:66300c77c6e9 720 GETLONG(cilong, p); \
tax 0:66300c77c6e9 721 if (cilong != val) \
tax 0:66300c77c6e9 722 goto bad; \
tax 0:66300c77c6e9 723 }
tax 0:66300c77c6e9 724
tax 0:66300c77c6e9 725 ACKCISHORT(CI_MRU, go->neg_mru && go->mru != PPP_DEFMRU, go->mru);
tax 0:66300c77c6e9 726 ACKCILONG(CI_ASYNCMAP, go->neg_asyncmap && go->asyncmap != 0xFFFFFFFFl, go->asyncmap);
tax 0:66300c77c6e9 727 ACKCICHAP(CI_AUTHTYPE, go->neg_chap, PPP_CHAP, go->chap_mdtype);
tax 0:66300c77c6e9 728 ACKCISHORT(CI_AUTHTYPE, !go->neg_chap && go->neg_upap, PPP_PAP);
tax 0:66300c77c6e9 729 ACKCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period);
tax 0:66300c77c6e9 730 ACKCICHAR(CI_CALLBACK, go->neg_cbcp, CBCP_OPT);
tax 0:66300c77c6e9 731 ACKCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber);
tax 0:66300c77c6e9 732 ACKCIVOID(CI_PCOMPRESSION, go->neg_pcompression);
tax 0:66300c77c6e9 733 ACKCIVOID(CI_ACCOMPRESSION, go->neg_accompression);
tax 0:66300c77c6e9 734
tax 0:66300c77c6e9 735 /*
tax 0:66300c77c6e9 736 * If there are any remaining CIs, then this packet is bad.
tax 0:66300c77c6e9 737 */
tax 0:66300c77c6e9 738 if (len != 0) {
tax 0:66300c77c6e9 739 goto bad;
tax 0:66300c77c6e9 740 }
tax 0:66300c77c6e9 741 LCPDEBUG(LOG_INFO, ("lcp_acki: Ack\n"));
tax 0:66300c77c6e9 742 return (1);
tax 0:66300c77c6e9 743 bad:
tax 0:66300c77c6e9 744 LCPDEBUG(LOG_WARNING, ("lcp_acki: received bad Ack!\n"));
tax 0:66300c77c6e9 745 return (0);
tax 0:66300c77c6e9 746 }
tax 0:66300c77c6e9 747
tax 0:66300c77c6e9 748
tax 0:66300c77c6e9 749 /*
tax 0:66300c77c6e9 750 * lcp_nakci - Peer has sent a NAK for some of our CIs.
tax 0:66300c77c6e9 751 * This should not modify any state if the Nak is bad
tax 0:66300c77c6e9 752 * or if LCP is in the LS_OPENED state.
tax 0:66300c77c6e9 753 *
tax 0:66300c77c6e9 754 * Returns:
tax 0:66300c77c6e9 755 * 0 - Nak was bad.
tax 0:66300c77c6e9 756 * 1 - Nak was good.
tax 0:66300c77c6e9 757 */
tax 0:66300c77c6e9 758 static int
tax 0:66300c77c6e9 759 lcp_nakci(fsm *f, u_char *p, int len)
tax 0:66300c77c6e9 760 {
tax 0:66300c77c6e9 761 lcp_options *go = &lcp_gotoptions[f->unit];
tax 0:66300c77c6e9 762 lcp_options *wo = &lcp_wantoptions[f->unit];
tax 0:66300c77c6e9 763 u_char citype, cichar, *next;
tax 0:66300c77c6e9 764 u_short cishort;
tax 0:66300c77c6e9 765 u32_t cilong;
tax 0:66300c77c6e9 766 lcp_options no; /* options we've seen Naks for */
tax 0:66300c77c6e9 767 lcp_options try; /* options to request next time */
tax 0:66300c77c6e9 768 int looped_back = 0;
tax 0:66300c77c6e9 769 int cilen;
tax 0:66300c77c6e9 770
tax 0:66300c77c6e9 771 BZERO(&no, sizeof(no));
tax 0:66300c77c6e9 772 try = *go;
tax 0:66300c77c6e9 773
tax 0:66300c77c6e9 774 /*
tax 0:66300c77c6e9 775 * Any Nak'd CIs must be in exactly the same order that we sent.
tax 0:66300c77c6e9 776 * Check packet length and CI length at each step.
tax 0:66300c77c6e9 777 * If we find any deviations, then this packet is bad.
tax 0:66300c77c6e9 778 */
tax 0:66300c77c6e9 779 #define NAKCIVOID(opt, neg, code) \
tax 0:66300c77c6e9 780 if (go->neg && \
tax 0:66300c77c6e9 781 len >= CILEN_VOID && \
tax 0:66300c77c6e9 782 p[1] == CILEN_VOID && \
tax 0:66300c77c6e9 783 p[0] == opt) { \
tax 0:66300c77c6e9 784 len -= CILEN_VOID; \
tax 0:66300c77c6e9 785 INCPTR(CILEN_VOID, p); \
tax 0:66300c77c6e9 786 no.neg = 1; \
tax 0:66300c77c6e9 787 code \
tax 0:66300c77c6e9 788 }
tax 0:66300c77c6e9 789 #define NAKCICHAP(opt, neg, code) \
tax 0:66300c77c6e9 790 if (go->neg && \
tax 0:66300c77c6e9 791 len >= CILEN_CHAP && \
tax 0:66300c77c6e9 792 p[1] == CILEN_CHAP && \
tax 0:66300c77c6e9 793 p[0] == opt) { \
tax 0:66300c77c6e9 794 len -= CILEN_CHAP; \
tax 0:66300c77c6e9 795 INCPTR(2, p); \
tax 0:66300c77c6e9 796 GETSHORT(cishort, p); \
tax 0:66300c77c6e9 797 GETCHAR(cichar, p); \
tax 0:66300c77c6e9 798 no.neg = 1; \
tax 0:66300c77c6e9 799 code \
tax 0:66300c77c6e9 800 }
tax 0:66300c77c6e9 801 #define NAKCICHAR(opt, neg, code) \
tax 0:66300c77c6e9 802 if (go->neg && \
tax 0:66300c77c6e9 803 len >= CILEN_CHAR && \
tax 0:66300c77c6e9 804 p[1] == CILEN_CHAR && \
tax 0:66300c77c6e9 805 p[0] == opt) { \
tax 0:66300c77c6e9 806 len -= CILEN_CHAR; \
tax 0:66300c77c6e9 807 INCPTR(2, p); \
tax 0:66300c77c6e9 808 GETCHAR(cichar, p); \
tax 0:66300c77c6e9 809 no.neg = 1; \
tax 0:66300c77c6e9 810 code \
tax 0:66300c77c6e9 811 }
tax 0:66300c77c6e9 812 #define NAKCISHORT(opt, neg, code) \
tax 0:66300c77c6e9 813 if (go->neg && \
tax 0:66300c77c6e9 814 len >= CILEN_SHORT && \
tax 0:66300c77c6e9 815 p[1] == CILEN_SHORT && \
tax 0:66300c77c6e9 816 p[0] == opt) { \
tax 0:66300c77c6e9 817 len -= CILEN_SHORT; \
tax 0:66300c77c6e9 818 INCPTR(2, p); \
tax 0:66300c77c6e9 819 GETSHORT(cishort, p); \
tax 0:66300c77c6e9 820 no.neg = 1; \
tax 0:66300c77c6e9 821 code \
tax 0:66300c77c6e9 822 }
tax 0:66300c77c6e9 823 #define NAKCILONG(opt, neg, code) \
tax 0:66300c77c6e9 824 if (go->neg && \
tax 0:66300c77c6e9 825 len >= CILEN_LONG && \
tax 0:66300c77c6e9 826 p[1] == CILEN_LONG && \
tax 0:66300c77c6e9 827 p[0] == opt) { \
tax 0:66300c77c6e9 828 len -= CILEN_LONG; \
tax 0:66300c77c6e9 829 INCPTR(2, p); \
tax 0:66300c77c6e9 830 GETLONG(cilong, p); \
tax 0:66300c77c6e9 831 no.neg = 1; \
tax 0:66300c77c6e9 832 code \
tax 0:66300c77c6e9 833 }
tax 0:66300c77c6e9 834 #define NAKCILQR(opt, neg, code) \
tax 0:66300c77c6e9 835 if (go->neg && \
tax 0:66300c77c6e9 836 len >= CILEN_LQR && \
tax 0:66300c77c6e9 837 p[1] == CILEN_LQR && \
tax 0:66300c77c6e9 838 p[0] == opt) { \
tax 0:66300c77c6e9 839 len -= CILEN_LQR; \
tax 0:66300c77c6e9 840 INCPTR(2, p); \
tax 0:66300c77c6e9 841 GETSHORT(cishort, p); \
tax 0:66300c77c6e9 842 GETLONG(cilong, p); \
tax 0:66300c77c6e9 843 no.neg = 1; \
tax 0:66300c77c6e9 844 code \
tax 0:66300c77c6e9 845 }
tax 0:66300c77c6e9 846
tax 0:66300c77c6e9 847 /*
tax 0:66300c77c6e9 848 * We don't care if they want to send us smaller packets than
tax 0:66300c77c6e9 849 * we want. Therefore, accept any MRU less than what we asked for,
tax 0:66300c77c6e9 850 * but then ignore the new value when setting the MRU in the kernel.
tax 0:66300c77c6e9 851 * If they send us a bigger MRU than what we asked, accept it, up to
tax 0:66300c77c6e9 852 * the limit of the default MRU we'd get if we didn't negotiate.
tax 0:66300c77c6e9 853 */
tax 0:66300c77c6e9 854 if (go->neg_mru && go->mru != PPP_DEFMRU) {
tax 0:66300c77c6e9 855 NAKCISHORT(CI_MRU, neg_mru,
tax 0:66300c77c6e9 856 if (cishort <= wo->mru || cishort < PPP_DEFMRU) {
tax 0:66300c77c6e9 857 try.mru = cishort;
tax 0:66300c77c6e9 858 }
tax 0:66300c77c6e9 859 );
tax 0:66300c77c6e9 860 }
tax 0:66300c77c6e9 861
tax 0:66300c77c6e9 862 /*
tax 0:66300c77c6e9 863 * Add any characters they want to our (receive-side) asyncmap.
tax 0:66300c77c6e9 864 */
tax 0:66300c77c6e9 865 if (go->neg_asyncmap && go->asyncmap != 0xFFFFFFFFl) {
tax 0:66300c77c6e9 866 NAKCILONG(CI_ASYNCMAP, neg_asyncmap,
tax 0:66300c77c6e9 867 try.asyncmap = go->asyncmap | cilong;
tax 0:66300c77c6e9 868 );
tax 0:66300c77c6e9 869 }
tax 0:66300c77c6e9 870
tax 0:66300c77c6e9 871 /*
tax 0:66300c77c6e9 872 * If they've nak'd our authentication-protocol, check whether
tax 0:66300c77c6e9 873 * they are proposing a different protocol, or a different
tax 0:66300c77c6e9 874 * hash algorithm for CHAP.
tax 0:66300c77c6e9 875 */
tax 0:66300c77c6e9 876 if ((go->neg_chap || go->neg_upap)
tax 0:66300c77c6e9 877 && len >= CILEN_SHORT
tax 0:66300c77c6e9 878 && p[0] == CI_AUTHTYPE && p[1] >= CILEN_SHORT && p[1] <= len) {
tax 0:66300c77c6e9 879 cilen = p[1];
tax 0:66300c77c6e9 880 len -= cilen;
tax 0:66300c77c6e9 881 no.neg_chap = go->neg_chap;
tax 0:66300c77c6e9 882 no.neg_upap = go->neg_upap;
tax 0:66300c77c6e9 883 INCPTR(2, p);
tax 0:66300c77c6e9 884 GETSHORT(cishort, p);
tax 0:66300c77c6e9 885 if (cishort == PPP_PAP && cilen == CILEN_SHORT) {
tax 0:66300c77c6e9 886 /*
tax 0:66300c77c6e9 887 * If we were asking for CHAP, they obviously don't want to do it.
tax 0:66300c77c6e9 888 * If we weren't asking for CHAP, then we were asking for PAP,
tax 0:66300c77c6e9 889 * in which case this Nak is bad.
tax 0:66300c77c6e9 890 */
tax 0:66300c77c6e9 891 if (!go->neg_chap) {
tax 0:66300c77c6e9 892 goto bad;
tax 0:66300c77c6e9 893 }
tax 0:66300c77c6e9 894 try.neg_chap = 0;
tax 0:66300c77c6e9 895
tax 0:66300c77c6e9 896 } else if (cishort == PPP_CHAP && cilen == CILEN_CHAP) {
tax 0:66300c77c6e9 897 GETCHAR(cichar, p);
tax 0:66300c77c6e9 898 if (go->neg_chap) {
tax 0:66300c77c6e9 899 /*
tax 0:66300c77c6e9 900 * We were asking for CHAP/MD5; they must want a different
tax 0:66300c77c6e9 901 * algorithm. If they can't do MD5, we'll have to stop
tax 0:66300c77c6e9 902 * asking for CHAP.
tax 0:66300c77c6e9 903 */
tax 0:66300c77c6e9 904 if (cichar != go->chap_mdtype) {
tax 0:66300c77c6e9 905 try.neg_chap = 0;
tax 0:66300c77c6e9 906 }
tax 0:66300c77c6e9 907 } else {
tax 0:66300c77c6e9 908 /*
tax 0:66300c77c6e9 909 * Stop asking for PAP if we were asking for it.
tax 0:66300c77c6e9 910 */
tax 0:66300c77c6e9 911 try.neg_upap = 0;
tax 0:66300c77c6e9 912 }
tax 0:66300c77c6e9 913
tax 0:66300c77c6e9 914 } else {
tax 0:66300c77c6e9 915 /*
tax 0:66300c77c6e9 916 * We don't recognize what they're suggesting.
tax 0:66300c77c6e9 917 * Stop asking for what we were asking for.
tax 0:66300c77c6e9 918 */
tax 0:66300c77c6e9 919 if (go->neg_chap) {
tax 0:66300c77c6e9 920 try.neg_chap = 0;
tax 0:66300c77c6e9 921 } else {
tax 0:66300c77c6e9 922 try.neg_upap = 0;
tax 0:66300c77c6e9 923 }
tax 0:66300c77c6e9 924 p += cilen - CILEN_SHORT;
tax 0:66300c77c6e9 925 }
tax 0:66300c77c6e9 926 }
tax 0:66300c77c6e9 927
tax 0:66300c77c6e9 928 /*
tax 0:66300c77c6e9 929 * If they can't cope with our link quality protocol, we'll have
tax 0:66300c77c6e9 930 * to stop asking for LQR. We haven't got any other protocol.
tax 0:66300c77c6e9 931 * If they Nak the reporting period, take their value XXX ?
tax 0:66300c77c6e9 932 */
tax 0:66300c77c6e9 933 NAKCILQR(CI_QUALITY, neg_lqr,
tax 0:66300c77c6e9 934 if (cishort != PPP_LQR) {
tax 0:66300c77c6e9 935 try.neg_lqr = 0;
tax 0:66300c77c6e9 936 } else {
tax 0:66300c77c6e9 937 try.lqr_period = cilong;
tax 0:66300c77c6e9 938 }
tax 0:66300c77c6e9 939 );
tax 0:66300c77c6e9 940
tax 0:66300c77c6e9 941 /*
tax 0:66300c77c6e9 942 * Only implementing CBCP...not the rest of the callback options
tax 0:66300c77c6e9 943 */
tax 0:66300c77c6e9 944 NAKCICHAR(CI_CALLBACK, neg_cbcp,
tax 0:66300c77c6e9 945 try.neg_cbcp = 0;
tax 0:66300c77c6e9 946 );
tax 0:66300c77c6e9 947
tax 0:66300c77c6e9 948 /*
tax 0:66300c77c6e9 949 * Check for a looped-back line.
tax 0:66300c77c6e9 950 */
tax 0:66300c77c6e9 951 NAKCILONG(CI_MAGICNUMBER, neg_magicnumber,
tax 0:66300c77c6e9 952 try.magicnumber = magic();
tax 0:66300c77c6e9 953 looped_back = 1;
tax 0:66300c77c6e9 954 );
tax 0:66300c77c6e9 955
tax 0:66300c77c6e9 956 /*
tax 0:66300c77c6e9 957 * Peer shouldn't send Nak for protocol compression or
tax 0:66300c77c6e9 958 * address/control compression requests; they should send
tax 0:66300c77c6e9 959 * a Reject instead. If they send a Nak, treat it as a Reject.
tax 0:66300c77c6e9 960 */
tax 0:66300c77c6e9 961 NAKCIVOID(CI_PCOMPRESSION, neg_pcompression,
tax 0:66300c77c6e9 962 try.neg_pcompression = 0;
tax 0:66300c77c6e9 963 );
tax 0:66300c77c6e9 964 NAKCIVOID(CI_ACCOMPRESSION, neg_accompression,
tax 0:66300c77c6e9 965 try.neg_accompression = 0;
tax 0:66300c77c6e9 966 );
tax 0:66300c77c6e9 967
tax 0:66300c77c6e9 968 /*
tax 0:66300c77c6e9 969 * There may be remaining CIs, if the peer is requesting negotiation
tax 0:66300c77c6e9 970 * on an option that we didn't include in our request packet.
tax 0:66300c77c6e9 971 * If we see an option that we requested, or one we've already seen
tax 0:66300c77c6e9 972 * in this packet, then this packet is bad.
tax 0:66300c77c6e9 973 * If we wanted to respond by starting to negotiate on the requested
tax 0:66300c77c6e9 974 * option(s), we could, but we don't, because except for the
tax 0:66300c77c6e9 975 * authentication type and quality protocol, if we are not negotiating
tax 0:66300c77c6e9 976 * an option, it is because we were told not to.
tax 0:66300c77c6e9 977 * For the authentication type, the Nak from the peer means
tax 0:66300c77c6e9 978 * `let me authenticate myself with you' which is a bit pointless.
tax 0:66300c77c6e9 979 * For the quality protocol, the Nak means `ask me to send you quality
tax 0:66300c77c6e9 980 * reports', but if we didn't ask for them, we don't want them.
tax 0:66300c77c6e9 981 * An option we don't recognize represents the peer asking to
tax 0:66300c77c6e9 982 * negotiate some option we don't support, so ignore it.
tax 0:66300c77c6e9 983 */
tax 0:66300c77c6e9 984 while (len > CILEN_VOID) {
tax 0:66300c77c6e9 985 GETCHAR(citype, p);
tax 0:66300c77c6e9 986 GETCHAR(cilen, p);
tax 0:66300c77c6e9 987 if (cilen < CILEN_VOID || (len -= cilen) < 0) {
tax 0:66300c77c6e9 988 goto bad;
tax 0:66300c77c6e9 989 }
tax 0:66300c77c6e9 990 next = p + cilen - 2;
tax 0:66300c77c6e9 991
tax 0:66300c77c6e9 992 switch (citype) {
tax 0:66300c77c6e9 993 case CI_MRU:
tax 0:66300c77c6e9 994 if ((go->neg_mru && go->mru != PPP_DEFMRU)
tax 0:66300c77c6e9 995 || no.neg_mru || cilen != CILEN_SHORT) {
tax 0:66300c77c6e9 996 goto bad;
tax 0:66300c77c6e9 997 }
tax 0:66300c77c6e9 998 GETSHORT(cishort, p);
tax 0:66300c77c6e9 999 if (cishort < PPP_DEFMRU) {
tax 0:66300c77c6e9 1000 try.mru = cishort;
tax 0:66300c77c6e9 1001 }
tax 0:66300c77c6e9 1002 break;
tax 0:66300c77c6e9 1003 case CI_ASYNCMAP:
tax 0:66300c77c6e9 1004 if ((go->neg_asyncmap && go->asyncmap != 0xFFFFFFFFl)
tax 0:66300c77c6e9 1005 || no.neg_asyncmap || cilen != CILEN_LONG) {
tax 0:66300c77c6e9 1006 goto bad;
tax 0:66300c77c6e9 1007 }
tax 0:66300c77c6e9 1008 break;
tax 0:66300c77c6e9 1009 case CI_AUTHTYPE:
tax 0:66300c77c6e9 1010 if (go->neg_chap || no.neg_chap || go->neg_upap || no.neg_upap) {
tax 0:66300c77c6e9 1011 goto bad;
tax 0:66300c77c6e9 1012 }
tax 0:66300c77c6e9 1013 break;
tax 0:66300c77c6e9 1014 case CI_MAGICNUMBER:
tax 0:66300c77c6e9 1015 if (go->neg_magicnumber || no.neg_magicnumber ||
tax 0:66300c77c6e9 1016 cilen != CILEN_LONG) {
tax 0:66300c77c6e9 1017 goto bad;
tax 0:66300c77c6e9 1018 }
tax 0:66300c77c6e9 1019 break;
tax 0:66300c77c6e9 1020 case CI_PCOMPRESSION:
tax 0:66300c77c6e9 1021 if (go->neg_pcompression || no.neg_pcompression
tax 0:66300c77c6e9 1022 || cilen != CILEN_VOID) {
tax 0:66300c77c6e9 1023 goto bad;
tax 0:66300c77c6e9 1024 }
tax 0:66300c77c6e9 1025 break;
tax 0:66300c77c6e9 1026 case CI_ACCOMPRESSION:
tax 0:66300c77c6e9 1027 if (go->neg_accompression || no.neg_accompression
tax 0:66300c77c6e9 1028 || cilen != CILEN_VOID) {
tax 0:66300c77c6e9 1029 goto bad;
tax 0:66300c77c6e9 1030 }
tax 0:66300c77c6e9 1031 break;
tax 0:66300c77c6e9 1032 case CI_QUALITY:
tax 0:66300c77c6e9 1033 if (go->neg_lqr || no.neg_lqr || cilen != CILEN_LQR) {
tax 0:66300c77c6e9 1034 goto bad;
tax 0:66300c77c6e9 1035 }
tax 0:66300c77c6e9 1036 break;
tax 0:66300c77c6e9 1037 }
tax 0:66300c77c6e9 1038 p = next;
tax 0:66300c77c6e9 1039 }
tax 0:66300c77c6e9 1040
tax 0:66300c77c6e9 1041 /* If there is still anything left, this packet is bad. */
tax 0:66300c77c6e9 1042 if (len != 0) {
tax 0:66300c77c6e9 1043 goto bad;
tax 0:66300c77c6e9 1044 }
tax 0:66300c77c6e9 1045
tax 0:66300c77c6e9 1046 /*
tax 0:66300c77c6e9 1047 * OK, the Nak is good. Now we can update state.
tax 0:66300c77c6e9 1048 */
tax 0:66300c77c6e9 1049 if (f->state != LS_OPENED) {
tax 0:66300c77c6e9 1050 if (looped_back) {
tax 0:66300c77c6e9 1051 if (++try.numloops >= lcp_loopbackfail) {
tax 0:66300c77c6e9 1052 LCPDEBUG(LOG_NOTICE, ("Serial line is looped back.\n"));
tax 0:66300c77c6e9 1053 lcp_close(f->unit, "Loopback detected");
tax 0:66300c77c6e9 1054 }
tax 0:66300c77c6e9 1055 } else {
tax 0:66300c77c6e9 1056 try.numloops = 0;
tax 0:66300c77c6e9 1057 }
tax 0:66300c77c6e9 1058 *go = try;
tax 0:66300c77c6e9 1059 }
tax 0:66300c77c6e9 1060
tax 0:66300c77c6e9 1061 return 1;
tax 0:66300c77c6e9 1062
tax 0:66300c77c6e9 1063 bad:
tax 0:66300c77c6e9 1064 LCPDEBUG(LOG_WARNING, ("lcp_nakci: received bad Nak!\n"));
tax 0:66300c77c6e9 1065 return 0;
tax 0:66300c77c6e9 1066 }
tax 0:66300c77c6e9 1067
tax 0:66300c77c6e9 1068
tax 0:66300c77c6e9 1069 /*
tax 0:66300c77c6e9 1070 * lcp_rejci - Peer has Rejected some of our CIs.
tax 0:66300c77c6e9 1071 * This should not modify any state if the Reject is bad
tax 0:66300c77c6e9 1072 * or if LCP is in the LS_OPENED state.
tax 0:66300c77c6e9 1073 *
tax 0:66300c77c6e9 1074 * Returns:
tax 0:66300c77c6e9 1075 * 0 - Reject was bad.
tax 0:66300c77c6e9 1076 * 1 - Reject was good.
tax 0:66300c77c6e9 1077 */
tax 0:66300c77c6e9 1078 static int
tax 0:66300c77c6e9 1079 lcp_rejci(fsm *f, u_char *p, int len)
tax 0:66300c77c6e9 1080 {
tax 0:66300c77c6e9 1081 lcp_options *go = &lcp_gotoptions[f->unit];
tax 0:66300c77c6e9 1082 u_char cichar;
tax 0:66300c77c6e9 1083 u_short cishort;
tax 0:66300c77c6e9 1084 u32_t cilong;
tax 0:66300c77c6e9 1085 lcp_options try; /* options to request next time */
tax 0:66300c77c6e9 1086
tax 0:66300c77c6e9 1087 try = *go;
tax 0:66300c77c6e9 1088
tax 0:66300c77c6e9 1089 /*
tax 0:66300c77c6e9 1090 * Any Rejected CIs must be in exactly the same order that we sent.
tax 0:66300c77c6e9 1091 * Check packet length and CI length at each step.
tax 0:66300c77c6e9 1092 * If we find any deviations, then this packet is bad.
tax 0:66300c77c6e9 1093 */
tax 0:66300c77c6e9 1094 #define REJCIVOID(opt, neg) \
tax 0:66300c77c6e9 1095 if (go->neg && \
tax 0:66300c77c6e9 1096 len >= CILEN_VOID && \
tax 0:66300c77c6e9 1097 p[1] == CILEN_VOID && \
tax 0:66300c77c6e9 1098 p[0] == opt) { \
tax 0:66300c77c6e9 1099 len -= CILEN_VOID; \
tax 0:66300c77c6e9 1100 INCPTR(CILEN_VOID, p); \
tax 0:66300c77c6e9 1101 try.neg = 0; \
tax 0:66300c77c6e9 1102 LCPDEBUG(LOG_INFO, ("lcp_rejci: void opt %d rejected\n", opt)); \
tax 0:66300c77c6e9 1103 }
tax 0:66300c77c6e9 1104 #define REJCISHORT(opt, neg, val) \
tax 0:66300c77c6e9 1105 if (go->neg && \
tax 0:66300c77c6e9 1106 len >= CILEN_SHORT && \
tax 0:66300c77c6e9 1107 p[1] == CILEN_SHORT && \
tax 0:66300c77c6e9 1108 p[0] == opt) { \
tax 0:66300c77c6e9 1109 len -= CILEN_SHORT; \
tax 0:66300c77c6e9 1110 INCPTR(2, p); \
tax 0:66300c77c6e9 1111 GETSHORT(cishort, p); \
tax 0:66300c77c6e9 1112 /* Check rejected value. */ \
tax 0:66300c77c6e9 1113 if (cishort != val) { \
tax 0:66300c77c6e9 1114 goto bad; \
tax 0:66300c77c6e9 1115 } \
tax 0:66300c77c6e9 1116 try.neg = 0; \
tax 0:66300c77c6e9 1117 LCPDEBUG(LOG_INFO, ("lcp_rejci: short opt %d rejected\n", opt)); \
tax 0:66300c77c6e9 1118 }
tax 0:66300c77c6e9 1119 #define REJCICHAP(opt, neg, val, digest) \
tax 0:66300c77c6e9 1120 if (go->neg && \
tax 0:66300c77c6e9 1121 len >= CILEN_CHAP && \
tax 0:66300c77c6e9 1122 p[1] == CILEN_CHAP && \
tax 0:66300c77c6e9 1123 p[0] == opt) { \
tax 0:66300c77c6e9 1124 len -= CILEN_CHAP; \
tax 0:66300c77c6e9 1125 INCPTR(2, p); \
tax 0:66300c77c6e9 1126 GETSHORT(cishort, p); \
tax 0:66300c77c6e9 1127 GETCHAR(cichar, p); \
tax 0:66300c77c6e9 1128 /* Check rejected value. */ \
tax 0:66300c77c6e9 1129 if (cishort != val || cichar != digest) { \
tax 0:66300c77c6e9 1130 goto bad; \
tax 0:66300c77c6e9 1131 } \
tax 0:66300c77c6e9 1132 try.neg = 0; \
tax 0:66300c77c6e9 1133 try.neg_upap = 0; \
tax 0:66300c77c6e9 1134 LCPDEBUG(LOG_INFO, ("lcp_rejci: chap opt %d rejected\n", opt)); \
tax 0:66300c77c6e9 1135 }
tax 0:66300c77c6e9 1136 #define REJCILONG(opt, neg, val) \
tax 0:66300c77c6e9 1137 if (go->neg && \
tax 0:66300c77c6e9 1138 len >= CILEN_LONG && \
tax 0:66300c77c6e9 1139 p[1] == CILEN_LONG && \
tax 0:66300c77c6e9 1140 p[0] == opt) { \
tax 0:66300c77c6e9 1141 len -= CILEN_LONG; \
tax 0:66300c77c6e9 1142 INCPTR(2, p); \
tax 0:66300c77c6e9 1143 GETLONG(cilong, p); \
tax 0:66300c77c6e9 1144 /* Check rejected value. */ \
tax 0:66300c77c6e9 1145 if (cilong != val) { \
tax 0:66300c77c6e9 1146 goto bad; \
tax 0:66300c77c6e9 1147 } \
tax 0:66300c77c6e9 1148 try.neg = 0; \
tax 0:66300c77c6e9 1149 LCPDEBUG(LOG_INFO, ("lcp_rejci: long opt %d rejected\n", opt)); \
tax 0:66300c77c6e9 1150 }
tax 0:66300c77c6e9 1151 #define REJCILQR(opt, neg, val) \
tax 0:66300c77c6e9 1152 if (go->neg && \
tax 0:66300c77c6e9 1153 len >= CILEN_LQR && \
tax 0:66300c77c6e9 1154 p[1] == CILEN_LQR && \
tax 0:66300c77c6e9 1155 p[0] == opt) { \
tax 0:66300c77c6e9 1156 len -= CILEN_LQR; \
tax 0:66300c77c6e9 1157 INCPTR(2, p); \
tax 0:66300c77c6e9 1158 GETSHORT(cishort, p); \
tax 0:66300c77c6e9 1159 GETLONG(cilong, p); \
tax 0:66300c77c6e9 1160 /* Check rejected value. */ \
tax 0:66300c77c6e9 1161 if (cishort != PPP_LQR || cilong != val) { \
tax 0:66300c77c6e9 1162 goto bad; \
tax 0:66300c77c6e9 1163 } \
tax 0:66300c77c6e9 1164 try.neg = 0; \
tax 0:66300c77c6e9 1165 LCPDEBUG(LOG_INFO, ("lcp_rejci: LQR opt %d rejected\n", opt)); \
tax 0:66300c77c6e9 1166 }
tax 0:66300c77c6e9 1167 #define REJCICBCP(opt, neg, val) \
tax 0:66300c77c6e9 1168 if (go->neg && \
tax 0:66300c77c6e9 1169 len >= CILEN_CBCP && \
tax 0:66300c77c6e9 1170 p[1] == CILEN_CBCP && \
tax 0:66300c77c6e9 1171 p[0] == opt) { \
tax 0:66300c77c6e9 1172 len -= CILEN_CBCP; \
tax 0:66300c77c6e9 1173 INCPTR(2, p); \
tax 0:66300c77c6e9 1174 GETCHAR(cichar, p); \
tax 0:66300c77c6e9 1175 /* Check rejected value. */ \
tax 0:66300c77c6e9 1176 if (cichar != val) { \
tax 0:66300c77c6e9 1177 goto bad; \
tax 0:66300c77c6e9 1178 } \
tax 0:66300c77c6e9 1179 try.neg = 0; \
tax 0:66300c77c6e9 1180 LCPDEBUG(LOG_INFO, ("lcp_rejci: Callback opt %d rejected\n", opt)); \
tax 0:66300c77c6e9 1181 }
tax 0:66300c77c6e9 1182
tax 0:66300c77c6e9 1183 REJCISHORT(CI_MRU, neg_mru, go->mru);
tax 0:66300c77c6e9 1184 REJCILONG(CI_ASYNCMAP, neg_asyncmap, go->asyncmap);
tax 0:66300c77c6e9 1185 REJCICHAP(CI_AUTHTYPE, neg_chap, PPP_CHAP, go->chap_mdtype);
tax 0:66300c77c6e9 1186 if (!go->neg_chap) {
tax 0:66300c77c6e9 1187 REJCISHORT(CI_AUTHTYPE, neg_upap, PPP_PAP);
tax 0:66300c77c6e9 1188 }
tax 0:66300c77c6e9 1189 REJCILQR(CI_QUALITY, neg_lqr, go->lqr_period);
tax 0:66300c77c6e9 1190 REJCICBCP(CI_CALLBACK, neg_cbcp, CBCP_OPT);
tax 0:66300c77c6e9 1191 REJCILONG(CI_MAGICNUMBER, neg_magicnumber, go->magicnumber);
tax 0:66300c77c6e9 1192 REJCIVOID(CI_PCOMPRESSION, neg_pcompression);
tax 0:66300c77c6e9 1193 REJCIVOID(CI_ACCOMPRESSION, neg_accompression);
tax 0:66300c77c6e9 1194
tax 0:66300c77c6e9 1195 /*
tax 0:66300c77c6e9 1196 * If there are any remaining CIs, then this packet is bad.
tax 0:66300c77c6e9 1197 */
tax 0:66300c77c6e9 1198 if (len != 0) {
tax 0:66300c77c6e9 1199 goto bad;
tax 0:66300c77c6e9 1200 }
tax 0:66300c77c6e9 1201 /*
tax 0:66300c77c6e9 1202 * Now we can update state.
tax 0:66300c77c6e9 1203 */
tax 0:66300c77c6e9 1204 if (f->state != LS_OPENED) {
tax 0:66300c77c6e9 1205 *go = try;
tax 0:66300c77c6e9 1206 }
tax 0:66300c77c6e9 1207 return 1;
tax 0:66300c77c6e9 1208
tax 0:66300c77c6e9 1209 bad:
tax 0:66300c77c6e9 1210 LCPDEBUG(LOG_WARNING, ("lcp_rejci: received bad Reject!\n"));
tax 0:66300c77c6e9 1211 return 0;
tax 0:66300c77c6e9 1212 }
tax 0:66300c77c6e9 1213
tax 0:66300c77c6e9 1214
tax 0:66300c77c6e9 1215 /*
tax 0:66300c77c6e9 1216 * lcp_reqci - Check the peer's requested CIs and send appropriate response.
tax 0:66300c77c6e9 1217 *
tax 0:66300c77c6e9 1218 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
tax 0:66300c77c6e9 1219 * appropriately. If reject_if_disagree is non-zero, doesn't return
tax 0:66300c77c6e9 1220 * CONFNAK; returns CONFREJ if it can't return CONFACK.
tax 0:66300c77c6e9 1221 */
tax 0:66300c77c6e9 1222 static int
tax 0:66300c77c6e9 1223 lcp_reqci(fsm *f,
tax 0:66300c77c6e9 1224 u_char *inp, /* Requested CIs */
tax 0:66300c77c6e9 1225 int *lenp, /* Length of requested CIs */
tax 0:66300c77c6e9 1226 int reject_if_disagree)
tax 0:66300c77c6e9 1227 {
tax 0:66300c77c6e9 1228 lcp_options *go = &lcp_gotoptions[f->unit];
tax 0:66300c77c6e9 1229 lcp_options *ho = &lcp_hisoptions[f->unit];
tax 0:66300c77c6e9 1230 lcp_options *ao = &lcp_allowoptions[f->unit];
tax 0:66300c77c6e9 1231 u_char *cip, *next; /* Pointer to current and next CIs */
tax 0:66300c77c6e9 1232 int cilen, citype; /* Parsed len, type */
tax 0:66300c77c6e9 1233 u_char cichar; /* Parsed char value */
tax 0:66300c77c6e9 1234 u_short cishort; /* Parsed short value */
tax 0:66300c77c6e9 1235 u32_t cilong; /* Parse long value */
tax 0:66300c77c6e9 1236 int rc = CONFACK; /* Final packet return code */
tax 0:66300c77c6e9 1237 int orc; /* Individual option return code */
tax 0:66300c77c6e9 1238 u_char *p; /* Pointer to next char to parse */
tax 0:66300c77c6e9 1239 u_char *rejp; /* Pointer to next char in reject frame */
tax 0:66300c77c6e9 1240 u_char *nakp; /* Pointer to next char in Nak frame */
tax 0:66300c77c6e9 1241 int l = *lenp; /* Length left */
tax 0:66300c77c6e9 1242 #if TRACELCP > 0
tax 0:66300c77c6e9 1243 char traceBuf[80];
tax 0:66300c77c6e9 1244 size_t traceNdx = 0;
tax 0:66300c77c6e9 1245 #endif
tax 0:66300c77c6e9 1246
tax 0:66300c77c6e9 1247 /*
tax 0:66300c77c6e9 1248 * Reset all his options.
tax 0:66300c77c6e9 1249 */
tax 0:66300c77c6e9 1250 BZERO(ho, sizeof(*ho));
tax 0:66300c77c6e9 1251
tax 0:66300c77c6e9 1252 /*
tax 0:66300c77c6e9 1253 * Process all his options.
tax 0:66300c77c6e9 1254 */
tax 0:66300c77c6e9 1255 next = inp;
tax 0:66300c77c6e9 1256 nakp = nak_buffer;
tax 0:66300c77c6e9 1257 rejp = inp;
tax 0:66300c77c6e9 1258 while (l) {
tax 0:66300c77c6e9 1259 orc = CONFACK; /* Assume success */
tax 0:66300c77c6e9 1260 cip = p = next; /* Remember begining of CI */
tax 0:66300c77c6e9 1261 if (l < 2 || /* Not enough data for CI header or */
tax 0:66300c77c6e9 1262 p[1] < 2 || /* CI length too small or */
tax 0:66300c77c6e9 1263 p[1] > l) { /* CI length too big? */
tax 0:66300c77c6e9 1264 LCPDEBUG(LOG_WARNING, ("lcp_reqci: bad CI length!\n"));
tax 0:66300c77c6e9 1265 orc = CONFREJ; /* Reject bad CI */
tax 0:66300c77c6e9 1266 cilen = l; /* Reject till end of packet */
tax 0:66300c77c6e9 1267 l = 0; /* Don't loop again */
tax 0:66300c77c6e9 1268 citype = 0;
tax 0:66300c77c6e9 1269 goto endswitch;
tax 0:66300c77c6e9 1270 }
tax 0:66300c77c6e9 1271 GETCHAR(citype, p); /* Parse CI type */
tax 0:66300c77c6e9 1272 GETCHAR(cilen, p); /* Parse CI length */
tax 0:66300c77c6e9 1273 l -= cilen; /* Adjust remaining length */
tax 0:66300c77c6e9 1274 next += cilen; /* Step to next CI */
tax 0:66300c77c6e9 1275
tax 0:66300c77c6e9 1276 switch (citype) { /* Check CI type */
tax 0:66300c77c6e9 1277 case CI_MRU:
tax 0:66300c77c6e9 1278 if (!ao->neg_mru) { /* Allow option? */
tax 0:66300c77c6e9 1279 LCPDEBUG(LOG_INFO, ("lcp_reqci: Reject MRU - not allowed\n"));
tax 0:66300c77c6e9 1280 orc = CONFREJ; /* Reject CI */
tax 0:66300c77c6e9 1281 break;
tax 0:66300c77c6e9 1282 } else if (cilen != CILEN_SHORT) { /* Check CI length */
tax 0:66300c77c6e9 1283 LCPDEBUG(LOG_INFO, ("lcp_reqci: Reject MRU - bad length\n"));
tax 0:66300c77c6e9 1284 orc = CONFREJ; /* Reject CI */
tax 0:66300c77c6e9 1285 break;
tax 0:66300c77c6e9 1286 }
tax 0:66300c77c6e9 1287 GETSHORT(cishort, p); /* Parse MRU */
tax 0:66300c77c6e9 1288
tax 0:66300c77c6e9 1289 /*
tax 0:66300c77c6e9 1290 * He must be able to receive at least our minimum.
tax 0:66300c77c6e9 1291 * No need to check a maximum. If he sends a large number,
tax 0:66300c77c6e9 1292 * we'll just ignore it.
tax 0:66300c77c6e9 1293 */
tax 0:66300c77c6e9 1294 if (cishort < PPP_MINMRU) {
tax 0:66300c77c6e9 1295 LCPDEBUG(LOG_INFO, ("lcp_reqci: Nak - MRU too small\n"));
tax 0:66300c77c6e9 1296 orc = CONFNAK; /* Nak CI */
tax 0:66300c77c6e9 1297 PUTCHAR(CI_MRU, nakp);
tax 0:66300c77c6e9 1298 PUTCHAR(CILEN_SHORT, nakp);
tax 0:66300c77c6e9 1299 PUTSHORT(PPP_MINMRU, nakp); /* Give him a hint */
tax 0:66300c77c6e9 1300 break;
tax 0:66300c77c6e9 1301 }
tax 0:66300c77c6e9 1302 ho->neg_mru = 1; /* Remember he sent MRU */
tax 0:66300c77c6e9 1303 ho->mru = cishort; /* And remember value */
tax 0:66300c77c6e9 1304 #if TRACELCP > 0
tax 0:66300c77c6e9 1305 snprintf(&traceBuf[traceNdx], sizeof(traceBuf), " MRU %d", cishort);
tax 0:66300c77c6e9 1306 traceNdx = strlen(traceBuf);
tax 0:66300c77c6e9 1307 #endif
tax 0:66300c77c6e9 1308 break;
tax 0:66300c77c6e9 1309
tax 0:66300c77c6e9 1310 case CI_ASYNCMAP:
tax 0:66300c77c6e9 1311 if (!ao->neg_asyncmap) {
tax 0:66300c77c6e9 1312 LCPDEBUG(LOG_INFO, ("lcp_reqci: Reject ASYNCMAP not allowed\n"));
tax 0:66300c77c6e9 1313 orc = CONFREJ;
tax 0:66300c77c6e9 1314 break;
tax 0:66300c77c6e9 1315 } else if (cilen != CILEN_LONG) {
tax 0:66300c77c6e9 1316 LCPDEBUG(LOG_INFO, ("lcp_reqci: Reject ASYNCMAP bad length\n"));
tax 0:66300c77c6e9 1317 orc = CONFREJ;
tax 0:66300c77c6e9 1318 break;
tax 0:66300c77c6e9 1319 }
tax 0:66300c77c6e9 1320 GETLONG(cilong, p);
tax 0:66300c77c6e9 1321
tax 0:66300c77c6e9 1322 /*
tax 0:66300c77c6e9 1323 * Asyncmap must have set at least the bits
tax 0:66300c77c6e9 1324 * which are set in lcp_allowoptions[unit].asyncmap.
tax 0:66300c77c6e9 1325 */
tax 0:66300c77c6e9 1326 if ((ao->asyncmap & ~cilong) != 0) {
tax 0:66300c77c6e9 1327 LCPDEBUG(LOG_INFO, ("lcp_reqci: Nak ASYNCMAP %lX missing %lX\n",
tax 0:66300c77c6e9 1328 cilong, ao->asyncmap));
tax 0:66300c77c6e9 1329 orc = CONFNAK;
tax 0:66300c77c6e9 1330 PUTCHAR(CI_ASYNCMAP, nakp);
tax 0:66300c77c6e9 1331 PUTCHAR(CILEN_LONG, nakp);
tax 0:66300c77c6e9 1332 PUTLONG(ao->asyncmap | cilong, nakp);
tax 0:66300c77c6e9 1333 break;
tax 0:66300c77c6e9 1334 }
tax 0:66300c77c6e9 1335 ho->neg_asyncmap = 1;
tax 0:66300c77c6e9 1336 ho->asyncmap = cilong;
tax 0:66300c77c6e9 1337 #if TRACELCP > 0
tax 0:66300c77c6e9 1338 snprintf(&traceBuf[traceNdx], sizeof(traceBuf), " ASYNCMAP=%lX", cilong);
tax 0:66300c77c6e9 1339 traceNdx = strlen(traceBuf);
tax 0:66300c77c6e9 1340 #endif
tax 0:66300c77c6e9 1341 break;
tax 0:66300c77c6e9 1342
tax 0:66300c77c6e9 1343 case CI_AUTHTYPE:
tax 0:66300c77c6e9 1344 if (cilen < CILEN_SHORT) {
tax 0:66300c77c6e9 1345 LCPDEBUG(LOG_INFO, ("lcp_reqci: Reject AUTHTYPE missing arg\n"));
tax 0:66300c77c6e9 1346 orc = CONFREJ;
tax 0:66300c77c6e9 1347 break;
tax 0:66300c77c6e9 1348 } else if (!(ao->neg_upap || ao->neg_chap)) {
tax 0:66300c77c6e9 1349 /*
tax 0:66300c77c6e9 1350 * Reject the option if we're not willing to authenticate.
tax 0:66300c77c6e9 1351 */
tax 0:66300c77c6e9 1352 LCPDEBUG(LOG_INFO, ("lcp_reqci: Reject AUTHTYPE not allowed\n"));
tax 0:66300c77c6e9 1353 orc = CONFREJ;
tax 0:66300c77c6e9 1354 break;
tax 0:66300c77c6e9 1355 }
tax 0:66300c77c6e9 1356 GETSHORT(cishort, p);
tax 0:66300c77c6e9 1357
tax 0:66300c77c6e9 1358 /*
tax 0:66300c77c6e9 1359 * Authtype must be UPAP or CHAP.
tax 0:66300c77c6e9 1360 *
tax 0:66300c77c6e9 1361 * Note: if both ao->neg_upap and ao->neg_chap are set,
tax 0:66300c77c6e9 1362 * and the peer sends a Configure-Request with two
tax 0:66300c77c6e9 1363 * authenticate-protocol requests, one for CHAP and one
tax 0:66300c77c6e9 1364 * for UPAP, then we will reject the second request.
tax 0:66300c77c6e9 1365 * Whether we end up doing CHAP or UPAP depends then on
tax 0:66300c77c6e9 1366 * the ordering of the CIs in the peer's Configure-Request.
tax 0:66300c77c6e9 1367 */
tax 0:66300c77c6e9 1368
tax 0:66300c77c6e9 1369 if (cishort == PPP_PAP) {
tax 0:66300c77c6e9 1370 if (ho->neg_chap) { /* we've already accepted CHAP */
tax 0:66300c77c6e9 1371 LCPDEBUG(LOG_WARNING, ("lcp_reqci: Reject AUTHTYPE PAP already accepted\n"));
tax 0:66300c77c6e9 1372 orc = CONFREJ;
tax 0:66300c77c6e9 1373 break;
tax 0:66300c77c6e9 1374 } else if (cilen != CILEN_SHORT) {
tax 0:66300c77c6e9 1375 LCPDEBUG(LOG_WARNING, ("lcp_reqci: Reject AUTHTYPE PAP bad len\n"));
tax 0:66300c77c6e9 1376 orc = CONFREJ;
tax 0:66300c77c6e9 1377 break;
tax 0:66300c77c6e9 1378 }
tax 0:66300c77c6e9 1379 if (!ao->neg_upap) { /* we don't want to do PAP */
tax 0:66300c77c6e9 1380 LCPDEBUG(LOG_WARNING, ("lcp_reqci: Nak AUTHTYPE PAP not allowed\n"));
tax 0:66300c77c6e9 1381 orc = CONFNAK; /* NAK it and suggest CHAP */
tax 0:66300c77c6e9 1382 PUTCHAR(CI_AUTHTYPE, nakp);
tax 0:66300c77c6e9 1383 PUTCHAR(CILEN_CHAP, nakp);
tax 0:66300c77c6e9 1384 PUTSHORT(PPP_CHAP, nakp);
tax 0:66300c77c6e9 1385 PUTCHAR(ao->chap_mdtype, nakp);
tax 0:66300c77c6e9 1386 break;
tax 0:66300c77c6e9 1387 }
tax 0:66300c77c6e9 1388 ho->neg_upap = 1;
tax 0:66300c77c6e9 1389 #if TRACELCP > 0
tax 0:66300c77c6e9 1390 snprintf(&traceBuf[traceNdx], sizeof(traceBuf), " PAP (%X)", cishort);
tax 0:66300c77c6e9 1391 traceNdx = strlen(traceBuf);
tax 0:66300c77c6e9 1392 #endif
tax 0:66300c77c6e9 1393 break;
tax 0:66300c77c6e9 1394 }
tax 0:66300c77c6e9 1395 if (cishort == PPP_CHAP) {
tax 0:66300c77c6e9 1396 if (ho->neg_upap) { /* we've already accepted PAP */
tax 0:66300c77c6e9 1397 LCPDEBUG(LOG_WARNING, ("lcp_reqci: Reject AUTHTYPE CHAP accepted PAP\n"));
tax 0:66300c77c6e9 1398 orc = CONFREJ;
tax 0:66300c77c6e9 1399 break;
tax 0:66300c77c6e9 1400 } else if (cilen != CILEN_CHAP) {
tax 0:66300c77c6e9 1401 LCPDEBUG(LOG_WARNING, ("lcp_reqci: Reject AUTHTYPE CHAP bad len\n"));
tax 0:66300c77c6e9 1402 orc = CONFREJ;
tax 0:66300c77c6e9 1403 break;
tax 0:66300c77c6e9 1404 }
tax 0:66300c77c6e9 1405 if (!ao->neg_chap) { /* we don't want to do CHAP */
tax 0:66300c77c6e9 1406 LCPDEBUG(LOG_WARNING, ("lcp_reqci: Nak AUTHTYPE CHAP not allowed\n"));
tax 0:66300c77c6e9 1407 orc = CONFNAK; /* NAK it and suggest PAP */
tax 0:66300c77c6e9 1408 PUTCHAR(CI_AUTHTYPE, nakp);
tax 0:66300c77c6e9 1409 PUTCHAR(CILEN_SHORT, nakp);
tax 0:66300c77c6e9 1410 PUTSHORT(PPP_PAP, nakp);
tax 0:66300c77c6e9 1411 break;
tax 0:66300c77c6e9 1412 }
tax 0:66300c77c6e9 1413 GETCHAR(cichar, p); /* get digest type*/
tax 0:66300c77c6e9 1414 if (cichar != CHAP_DIGEST_MD5
tax 0:66300c77c6e9 1415 #if MSCHAP_SUPPORT
tax 0:66300c77c6e9 1416 && cichar != CHAP_MICROSOFT
tax 0:66300c77c6e9 1417 #endif
tax 0:66300c77c6e9 1418 ) {
tax 0:66300c77c6e9 1419 LCPDEBUG(LOG_WARNING, ("lcp_reqci: Nak AUTHTYPE CHAP digest=%d\n", (int)cichar));
tax 0:66300c77c6e9 1420 orc = CONFNAK;
tax 0:66300c77c6e9 1421 PUTCHAR(CI_AUTHTYPE, nakp);
tax 0:66300c77c6e9 1422 PUTCHAR(CILEN_CHAP, nakp);
tax 0:66300c77c6e9 1423 PUTSHORT(PPP_CHAP, nakp);
tax 0:66300c77c6e9 1424 PUTCHAR(ao->chap_mdtype, nakp);
tax 0:66300c77c6e9 1425 break;
tax 0:66300c77c6e9 1426 }
tax 0:66300c77c6e9 1427 #if TRACELCP > 0
tax 0:66300c77c6e9 1428 snprintf(&traceBuf[traceNdx], sizeof(traceBuf), " CHAP %X,%d", cishort, (int)cichar);
tax 0:66300c77c6e9 1429 traceNdx = strlen(traceBuf);
tax 0:66300c77c6e9 1430 #endif
tax 0:66300c77c6e9 1431 ho->chap_mdtype = cichar; /* save md type */
tax 0:66300c77c6e9 1432 ho->neg_chap = 1;
tax 0:66300c77c6e9 1433 break;
tax 0:66300c77c6e9 1434 }
tax 0:66300c77c6e9 1435
tax 0:66300c77c6e9 1436 /*
tax 0:66300c77c6e9 1437 * We don't recognize the protocol they're asking for.
tax 0:66300c77c6e9 1438 * Nak it with something we're willing to do.
tax 0:66300c77c6e9 1439 * (At this point we know ao->neg_upap || ao->neg_chap.)
tax 0:66300c77c6e9 1440 */
tax 0:66300c77c6e9 1441 orc = CONFNAK;
tax 0:66300c77c6e9 1442 PUTCHAR(CI_AUTHTYPE, nakp);
tax 0:66300c77c6e9 1443 if (ao->neg_chap) {
tax 0:66300c77c6e9 1444 LCPDEBUG(LOG_WARNING, ("lcp_reqci: Nak AUTHTYPE %d req CHAP\n", cishort));
tax 0:66300c77c6e9 1445 PUTCHAR(CILEN_CHAP, nakp);
tax 0:66300c77c6e9 1446 PUTSHORT(PPP_CHAP, nakp);
tax 0:66300c77c6e9 1447 PUTCHAR(ao->chap_mdtype, nakp);
tax 0:66300c77c6e9 1448 } else {
tax 0:66300c77c6e9 1449 LCPDEBUG(LOG_WARNING, ("lcp_reqci: Nak AUTHTYPE %d req PAP\n", cishort));
tax 0:66300c77c6e9 1450 PUTCHAR(CILEN_SHORT, nakp);
tax 0:66300c77c6e9 1451 PUTSHORT(PPP_PAP, nakp);
tax 0:66300c77c6e9 1452 }
tax 0:66300c77c6e9 1453 break;
tax 0:66300c77c6e9 1454
tax 0:66300c77c6e9 1455 case CI_QUALITY:
tax 0:66300c77c6e9 1456 GETSHORT(cishort, p);
tax 0:66300c77c6e9 1457 GETLONG(cilong, p);
tax 0:66300c77c6e9 1458 #if TRACELCP > 0
tax 0:66300c77c6e9 1459 snprintf(&traceBuf[traceNdx], sizeof(traceBuf), " QUALITY (%x %x)", cishort, (unsigned int) cilong);
tax 0:66300c77c6e9 1460 traceNdx = strlen(traceBuf);
tax 0:66300c77c6e9 1461 #endif
tax 0:66300c77c6e9 1462
tax 0:66300c77c6e9 1463 if (!ao->neg_lqr ||
tax 0:66300c77c6e9 1464 cilen != CILEN_LQR) {
tax 0:66300c77c6e9 1465 orc = CONFREJ;
tax 0:66300c77c6e9 1466 break;
tax 0:66300c77c6e9 1467 }
tax 0:66300c77c6e9 1468
tax 0:66300c77c6e9 1469 /*
tax 0:66300c77c6e9 1470 * Check the protocol and the reporting period.
tax 0:66300c77c6e9 1471 * XXX When should we Nak this, and what with?
tax 0:66300c77c6e9 1472 */
tax 0:66300c77c6e9 1473 if (cishort != PPP_LQR) {
tax 0:66300c77c6e9 1474 orc = CONFNAK;
tax 0:66300c77c6e9 1475 PUTCHAR(CI_QUALITY, nakp);
tax 0:66300c77c6e9 1476 PUTCHAR(CILEN_LQR, nakp);
tax 0:66300c77c6e9 1477 PUTSHORT(PPP_LQR, nakp);
tax 0:66300c77c6e9 1478 PUTLONG(ao->lqr_period, nakp);
tax 0:66300c77c6e9 1479 break;
tax 0:66300c77c6e9 1480 }
tax 0:66300c77c6e9 1481 break;
tax 0:66300c77c6e9 1482
tax 0:66300c77c6e9 1483 case CI_MAGICNUMBER:
tax 0:66300c77c6e9 1484 if (!(ao->neg_magicnumber || go->neg_magicnumber) ||
tax 0:66300c77c6e9 1485 cilen != CILEN_LONG) {
tax 0:66300c77c6e9 1486 orc = CONFREJ;
tax 0:66300c77c6e9 1487 break;
tax 0:66300c77c6e9 1488 }
tax 0:66300c77c6e9 1489 GETLONG(cilong, p);
tax 0:66300c77c6e9 1490 #if TRACELCP > 0
tax 0:66300c77c6e9 1491 snprintf(&traceBuf[traceNdx], sizeof(traceBuf), " MAGICNUMBER (%lX)", cilong);
tax 0:66300c77c6e9 1492 traceNdx = strlen(traceBuf);
tax 0:66300c77c6e9 1493 #endif
tax 0:66300c77c6e9 1494
tax 0:66300c77c6e9 1495 /*
tax 0:66300c77c6e9 1496 * He must have a different magic number.
tax 0:66300c77c6e9 1497 */
tax 0:66300c77c6e9 1498 if (go->neg_magicnumber &&
tax 0:66300c77c6e9 1499 cilong == go->magicnumber) {
tax 0:66300c77c6e9 1500 cilong = magic(); /* Don't put magic() inside macro! */
tax 0:66300c77c6e9 1501 orc = CONFNAK;
tax 0:66300c77c6e9 1502 PUTCHAR(CI_MAGICNUMBER, nakp);
tax 0:66300c77c6e9 1503 PUTCHAR(CILEN_LONG, nakp);
tax 0:66300c77c6e9 1504 PUTLONG(cilong, nakp);
tax 0:66300c77c6e9 1505 break;
tax 0:66300c77c6e9 1506 }
tax 0:66300c77c6e9 1507 ho->neg_magicnumber = 1;
tax 0:66300c77c6e9 1508 ho->magicnumber = cilong;
tax 0:66300c77c6e9 1509 break;
tax 0:66300c77c6e9 1510
tax 0:66300c77c6e9 1511
tax 0:66300c77c6e9 1512 case CI_PCOMPRESSION:
tax 0:66300c77c6e9 1513 #if TRACELCP > 0
tax 0:66300c77c6e9 1514 snprintf(&traceBuf[traceNdx], sizeof(traceBuf), " PCOMPRESSION");
tax 0:66300c77c6e9 1515 traceNdx = strlen(traceBuf);
tax 0:66300c77c6e9 1516 #endif
tax 0:66300c77c6e9 1517 if (!ao->neg_pcompression ||
tax 0:66300c77c6e9 1518 cilen != CILEN_VOID) {
tax 0:66300c77c6e9 1519 orc = CONFREJ;
tax 0:66300c77c6e9 1520 break;
tax 0:66300c77c6e9 1521 }
tax 0:66300c77c6e9 1522 ho->neg_pcompression = 1;
tax 0:66300c77c6e9 1523 break;
tax 0:66300c77c6e9 1524
tax 0:66300c77c6e9 1525 case CI_ACCOMPRESSION:
tax 0:66300c77c6e9 1526 #if TRACELCP > 0
tax 0:66300c77c6e9 1527 snprintf(&traceBuf[traceNdx], sizeof(traceBuf), " ACCOMPRESSION");
tax 0:66300c77c6e9 1528 traceNdx = strlen(traceBuf);
tax 0:66300c77c6e9 1529 #endif
tax 0:66300c77c6e9 1530 if (!ao->neg_accompression ||
tax 0:66300c77c6e9 1531 cilen != CILEN_VOID) {
tax 0:66300c77c6e9 1532 orc = CONFREJ;
tax 0:66300c77c6e9 1533 break;
tax 0:66300c77c6e9 1534 }
tax 0:66300c77c6e9 1535 ho->neg_accompression = 1;
tax 0:66300c77c6e9 1536 break;
tax 0:66300c77c6e9 1537
tax 0:66300c77c6e9 1538 case CI_MRRU:
tax 0:66300c77c6e9 1539 #if TRACELCP > 0
tax 0:66300c77c6e9 1540 snprintf(&traceBuf[traceNdx], sizeof(traceBuf), " CI_MRRU");
tax 0:66300c77c6e9 1541 traceNdx = strlen(traceBuf);
tax 0:66300c77c6e9 1542 #endif
tax 0:66300c77c6e9 1543 orc = CONFREJ;
tax 0:66300c77c6e9 1544 break;
tax 0:66300c77c6e9 1545
tax 0:66300c77c6e9 1546 case CI_SSNHF:
tax 0:66300c77c6e9 1547 #if TRACELCP > 0
tax 0:66300c77c6e9 1548 snprintf(&traceBuf[traceNdx], sizeof(traceBuf), " CI_SSNHF");
tax 0:66300c77c6e9 1549 traceNdx = strlen(traceBuf);
tax 0:66300c77c6e9 1550 #endif
tax 0:66300c77c6e9 1551 orc = CONFREJ;
tax 0:66300c77c6e9 1552 break;
tax 0:66300c77c6e9 1553
tax 0:66300c77c6e9 1554 case CI_EPDISC:
tax 0:66300c77c6e9 1555 #if TRACELCP > 0
tax 0:66300c77c6e9 1556 snprintf(&traceBuf[traceNdx], sizeof(traceBuf), " CI_EPDISC");
tax 0:66300c77c6e9 1557 traceNdx = strlen(traceBuf);
tax 0:66300c77c6e9 1558 #endif
tax 0:66300c77c6e9 1559 orc = CONFREJ;
tax 0:66300c77c6e9 1560 break;
tax 0:66300c77c6e9 1561
tax 0:66300c77c6e9 1562 default:
tax 0:66300c77c6e9 1563 #if TRACELCP
tax 0:66300c77c6e9 1564 snprintf(&traceBuf[traceNdx], sizeof(traceBuf), " unknown %d", citype);
tax 0:66300c77c6e9 1565 traceNdx = strlen(traceBuf);
tax 0:66300c77c6e9 1566 #endif
tax 0:66300c77c6e9 1567 orc = CONFREJ;
tax 0:66300c77c6e9 1568 break;
tax 0:66300c77c6e9 1569 }
tax 0:66300c77c6e9 1570
tax 0:66300c77c6e9 1571 endswitch:
tax 0:66300c77c6e9 1572 #if TRACELCP
tax 0:66300c77c6e9 1573 if (traceNdx >= 80 - 32) {
tax 0:66300c77c6e9 1574 LCPDEBUG(LOG_INFO, ("lcp_reqci: rcvd%s\n", traceBuf));
tax 0:66300c77c6e9 1575 traceNdx = 0;
tax 0:66300c77c6e9 1576 }
tax 0:66300c77c6e9 1577 #endif
tax 0:66300c77c6e9 1578 if (orc == CONFACK && /* Good CI */
tax 0:66300c77c6e9 1579 rc != CONFACK) { /* but prior CI wasnt? */
tax 0:66300c77c6e9 1580 continue; /* Don't send this one */
tax 0:66300c77c6e9 1581 }
tax 0:66300c77c6e9 1582
tax 0:66300c77c6e9 1583 if (orc == CONFNAK) { /* Nak this CI? */
tax 0:66300c77c6e9 1584 if (reject_if_disagree /* Getting fed up with sending NAKs? */
tax 0:66300c77c6e9 1585 && citype != CI_MAGICNUMBER) {
tax 0:66300c77c6e9 1586 orc = CONFREJ; /* Get tough if so */
tax 0:66300c77c6e9 1587 } else {
tax 0:66300c77c6e9 1588 if (rc == CONFREJ) { /* Rejecting prior CI? */
tax 0:66300c77c6e9 1589 continue; /* Don't send this one */
tax 0:66300c77c6e9 1590 }
tax 0:66300c77c6e9 1591 rc = CONFNAK;
tax 0:66300c77c6e9 1592 }
tax 0:66300c77c6e9 1593 }
tax 0:66300c77c6e9 1594 if (orc == CONFREJ) { /* Reject this CI */
tax 0:66300c77c6e9 1595 rc = CONFREJ;
tax 0:66300c77c6e9 1596 if (cip != rejp) { /* Need to move rejected CI? */
tax 0:66300c77c6e9 1597 BCOPY(cip, rejp, cilen); /* Move it */
tax 0:66300c77c6e9 1598 }
tax 0:66300c77c6e9 1599 INCPTR(cilen, rejp); /* Update output pointer */
tax 0:66300c77c6e9 1600 }
tax 0:66300c77c6e9 1601 }
tax 0:66300c77c6e9 1602
tax 0:66300c77c6e9 1603 /*
tax 0:66300c77c6e9 1604 * If we wanted to send additional NAKs (for unsent CIs), the
tax 0:66300c77c6e9 1605 * code would go here. The extra NAKs would go at *nakp.
tax 0:66300c77c6e9 1606 * At present there are no cases where we want to ask the
tax 0:66300c77c6e9 1607 * peer to negotiate an option.
tax 0:66300c77c6e9 1608 */
tax 0:66300c77c6e9 1609
tax 0:66300c77c6e9 1610 switch (rc) {
tax 0:66300c77c6e9 1611 case CONFACK:
tax 0:66300c77c6e9 1612 *lenp = (int)(next - inp);
tax 0:66300c77c6e9 1613 break;
tax 0:66300c77c6e9 1614 case CONFNAK:
tax 0:66300c77c6e9 1615 /*
tax 0:66300c77c6e9 1616 * Copy the Nak'd options from the nak_buffer to the caller's buffer.
tax 0:66300c77c6e9 1617 */
tax 0:66300c77c6e9 1618 *lenp = (int)(nakp - nak_buffer);
tax 0:66300c77c6e9 1619 BCOPY(nak_buffer, inp, *lenp);
tax 0:66300c77c6e9 1620 break;
tax 0:66300c77c6e9 1621 case CONFREJ:
tax 0:66300c77c6e9 1622 *lenp = (int)(rejp - inp);
tax 0:66300c77c6e9 1623 break;
tax 0:66300c77c6e9 1624 }
tax 0:66300c77c6e9 1625
tax 0:66300c77c6e9 1626 #if TRACELCP > 0
tax 0:66300c77c6e9 1627 if (traceNdx > 0) {
tax 0:66300c77c6e9 1628 LCPDEBUG(LOG_INFO, ("lcp_reqci: %s\n", traceBuf));
tax 0:66300c77c6e9 1629 }
tax 0:66300c77c6e9 1630 #endif
tax 0:66300c77c6e9 1631 LCPDEBUG(LOG_INFO, ("lcp_reqci: returning CONF%s.\n", CODENAME(rc)));
tax 0:66300c77c6e9 1632 return (rc); /* Return final code */
tax 0:66300c77c6e9 1633 }
tax 0:66300c77c6e9 1634
tax 0:66300c77c6e9 1635
tax 0:66300c77c6e9 1636 /*
tax 0:66300c77c6e9 1637 * lcp_up - LCP has come UP.
tax 0:66300c77c6e9 1638 */
tax 0:66300c77c6e9 1639 static void
tax 0:66300c77c6e9 1640 lcp_up(fsm *f)
tax 0:66300c77c6e9 1641 {
tax 0:66300c77c6e9 1642 lcp_options *wo = &lcp_wantoptions[f->unit];
tax 0:66300c77c6e9 1643 lcp_options *ho = &lcp_hisoptions[f->unit];
tax 0:66300c77c6e9 1644 lcp_options *go = &lcp_gotoptions[f->unit];
tax 0:66300c77c6e9 1645 lcp_options *ao = &lcp_allowoptions[f->unit];
tax 0:66300c77c6e9 1646
tax 0:66300c77c6e9 1647 if (!go->neg_magicnumber) {
tax 0:66300c77c6e9 1648 go->magicnumber = 0;
tax 0:66300c77c6e9 1649 }
tax 0:66300c77c6e9 1650 if (!ho->neg_magicnumber) {
tax 0:66300c77c6e9 1651 ho->magicnumber = 0;
tax 0:66300c77c6e9 1652 }
tax 0:66300c77c6e9 1653
tax 0:66300c77c6e9 1654 /*
tax 0:66300c77c6e9 1655 * Set our MTU to the smaller of the MTU we wanted and
tax 0:66300c77c6e9 1656 * the MRU our peer wanted. If we negotiated an MRU,
tax 0:66300c77c6e9 1657 * set our MRU to the larger of value we wanted and
tax 0:66300c77c6e9 1658 * the value we got in the negotiation.
tax 0:66300c77c6e9 1659 */
tax 0:66300c77c6e9 1660 ppp_send_config(f->unit, LWIP_MIN(ao->mru, (ho->neg_mru? ho->mru: PPP_MRU)),
tax 0:66300c77c6e9 1661 (ho->neg_asyncmap? ho->asyncmap: 0xffffffffl),
tax 0:66300c77c6e9 1662 ho->neg_pcompression, ho->neg_accompression);
tax 0:66300c77c6e9 1663 /*
tax 0:66300c77c6e9 1664 * If the asyncmap hasn't been negotiated, we really should
tax 0:66300c77c6e9 1665 * set the receive asyncmap to ffffffff, but we set it to 0
tax 0:66300c77c6e9 1666 * for backwards contemptibility.
tax 0:66300c77c6e9 1667 */
tax 0:66300c77c6e9 1668 ppp_recv_config(f->unit, (go->neg_mru? LWIP_MAX(wo->mru, go->mru): PPP_MRU),
tax 0:66300c77c6e9 1669 (go->neg_asyncmap? go->asyncmap: 0x00000000),
tax 0:66300c77c6e9 1670 go->neg_pcompression, go->neg_accompression);
tax 0:66300c77c6e9 1671
tax 0:66300c77c6e9 1672 if (ho->neg_mru) {
tax 0:66300c77c6e9 1673 peer_mru[f->unit] = ho->mru;
tax 0:66300c77c6e9 1674 }
tax 0:66300c77c6e9 1675
tax 0:66300c77c6e9 1676 lcp_echo_lowerup(f->unit); /* Enable echo messages */
tax 0:66300c77c6e9 1677
tax 0:66300c77c6e9 1678 link_established(f->unit); /* The link is up; authenticate now */
tax 0:66300c77c6e9 1679 }
tax 0:66300c77c6e9 1680
tax 0:66300c77c6e9 1681
tax 0:66300c77c6e9 1682 /*
tax 0:66300c77c6e9 1683 * lcp_down - LCP has gone DOWN.
tax 0:66300c77c6e9 1684 *
tax 0:66300c77c6e9 1685 * Alert other protocols.
tax 0:66300c77c6e9 1686 */
tax 0:66300c77c6e9 1687 static void
tax 0:66300c77c6e9 1688 lcp_down(fsm *f)
tax 0:66300c77c6e9 1689 {
tax 0:66300c77c6e9 1690 lcp_options *go = &lcp_gotoptions[f->unit];
tax 0:66300c77c6e9 1691
tax 0:66300c77c6e9 1692 lcp_echo_lowerdown(f->unit);
tax 0:66300c77c6e9 1693
tax 0:66300c77c6e9 1694 link_down(f->unit);
tax 0:66300c77c6e9 1695
tax 0:66300c77c6e9 1696 ppp_send_config(f->unit, PPP_MRU, 0xffffffffl, 0, 0);
tax 0:66300c77c6e9 1697 ppp_recv_config(f->unit, PPP_MRU,
tax 0:66300c77c6e9 1698 (go->neg_asyncmap? go->asyncmap: 0x00000000),
tax 0:66300c77c6e9 1699 go->neg_pcompression, go->neg_accompression);
tax 0:66300c77c6e9 1700 peer_mru[f->unit] = PPP_MRU;
tax 0:66300c77c6e9 1701 }
tax 0:66300c77c6e9 1702
tax 0:66300c77c6e9 1703
tax 0:66300c77c6e9 1704 /*
tax 0:66300c77c6e9 1705 * lcp_starting - LCP needs the lower layer up.
tax 0:66300c77c6e9 1706 */
tax 0:66300c77c6e9 1707 static void
tax 0:66300c77c6e9 1708 lcp_starting(fsm *f)
tax 0:66300c77c6e9 1709 {
tax 0:66300c77c6e9 1710 link_required(f->unit); /* lwip: currently does nothing */
tax 0:66300c77c6e9 1711 }
tax 0:66300c77c6e9 1712
tax 0:66300c77c6e9 1713
tax 0:66300c77c6e9 1714 /*
tax 0:66300c77c6e9 1715 * lcp_finished - LCP has finished with the lower layer.
tax 0:66300c77c6e9 1716 */
tax 0:66300c77c6e9 1717 static void
tax 0:66300c77c6e9 1718 lcp_finished(fsm *f)
tax 0:66300c77c6e9 1719 {
tax 0:66300c77c6e9 1720 link_terminated(f->unit); /* we are finished with the link */
tax 0:66300c77c6e9 1721 }
tax 0:66300c77c6e9 1722
tax 0:66300c77c6e9 1723
tax 0:66300c77c6e9 1724 #if PPP_ADDITIONAL_CALLBACKS
tax 0:66300c77c6e9 1725 /*
tax 0:66300c77c6e9 1726 * print_string - print a readable representation of a string using
tax 0:66300c77c6e9 1727 * printer.
tax 0:66300c77c6e9 1728 */
tax 0:66300c77c6e9 1729 static void
tax 0:66300c77c6e9 1730 print_string( char *p, int len, void (*printer) (void *, char *, ...), void *arg)
tax 0:66300c77c6e9 1731 {
tax 0:66300c77c6e9 1732 int c;
tax 0:66300c77c6e9 1733
tax 0:66300c77c6e9 1734 printer(arg, "\"");
tax 0:66300c77c6e9 1735 for (; len > 0; --len) {
tax 0:66300c77c6e9 1736 c = *p++;
tax 0:66300c77c6e9 1737 if (' ' <= c && c <= '~') {
tax 0:66300c77c6e9 1738 if (c == '\\' || c == '"') {
tax 0:66300c77c6e9 1739 printer(arg, "\\");
tax 0:66300c77c6e9 1740 }
tax 0:66300c77c6e9 1741 printer(arg, "%c", c);
tax 0:66300c77c6e9 1742 } else {
tax 0:66300c77c6e9 1743 switch (c) {
tax 0:66300c77c6e9 1744 case '\n':
tax 0:66300c77c6e9 1745 printer(arg, "\\n");
tax 0:66300c77c6e9 1746 break;
tax 0:66300c77c6e9 1747 case '\r':
tax 0:66300c77c6e9 1748 printer(arg, "\\r");
tax 0:66300c77c6e9 1749 break;
tax 0:66300c77c6e9 1750 case '\t':
tax 0:66300c77c6e9 1751 printer(arg, "\\t");
tax 0:66300c77c6e9 1752 break;
tax 0:66300c77c6e9 1753 default:
tax 0:66300c77c6e9 1754 printer(arg, "\\%.3o", c);
tax 0:66300c77c6e9 1755 }
tax 0:66300c77c6e9 1756 }
tax 0:66300c77c6e9 1757 }
tax 0:66300c77c6e9 1758 printer(arg, "\"");
tax 0:66300c77c6e9 1759 }
tax 0:66300c77c6e9 1760
tax 0:66300c77c6e9 1761
tax 0:66300c77c6e9 1762 /*
tax 0:66300c77c6e9 1763 * lcp_printpkt - print the contents of an LCP packet.
tax 0:66300c77c6e9 1764 */
tax 0:66300c77c6e9 1765 static char *lcp_codenames[] = {
tax 0:66300c77c6e9 1766 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
tax 0:66300c77c6e9 1767 "TermReq", "TermAck", "CodeRej", "ProtRej",
tax 0:66300c77c6e9 1768 "EchoReq", "EchoRep", "DiscReq"
tax 0:66300c77c6e9 1769 };
tax 0:66300c77c6e9 1770
tax 0:66300c77c6e9 1771 static int
tax 0:66300c77c6e9 1772 lcp_printpkt( u_char *p, int plen, void (*printer) (void *, char *, ...), void *arg)
tax 0:66300c77c6e9 1773 {
tax 0:66300c77c6e9 1774 int code, id, len, olen;
tax 0:66300c77c6e9 1775 u_char *pstart, *optend;
tax 0:66300c77c6e9 1776 u_short cishort;
tax 0:66300c77c6e9 1777 u32_t cilong;
tax 0:66300c77c6e9 1778
tax 0:66300c77c6e9 1779 if (plen < HEADERLEN) {
tax 0:66300c77c6e9 1780 return 0;
tax 0:66300c77c6e9 1781 }
tax 0:66300c77c6e9 1782 pstart = p;
tax 0:66300c77c6e9 1783 GETCHAR(code, p);
tax 0:66300c77c6e9 1784 GETCHAR(id, p);
tax 0:66300c77c6e9 1785 GETSHORT(len, p);
tax 0:66300c77c6e9 1786 if (len < HEADERLEN || len > plen) {
tax 0:66300c77c6e9 1787 return 0;
tax 0:66300c77c6e9 1788 }
tax 0:66300c77c6e9 1789
tax 0:66300c77c6e9 1790 if (code >= 1 && code <= sizeof(lcp_codenames) / sizeof(char *)) {
tax 0:66300c77c6e9 1791 printer(arg, " %s", lcp_codenames[code-1]);
tax 0:66300c77c6e9 1792 } else {
tax 0:66300c77c6e9 1793 printer(arg, " code=0x%x", code);
tax 0:66300c77c6e9 1794 }
tax 0:66300c77c6e9 1795 printer(arg, " id=0x%x", id);
tax 0:66300c77c6e9 1796 len -= HEADERLEN;
tax 0:66300c77c6e9 1797 switch (code) {
tax 0:66300c77c6e9 1798 case CONFREQ:
tax 0:66300c77c6e9 1799 case CONFACK:
tax 0:66300c77c6e9 1800 case CONFNAK:
tax 0:66300c77c6e9 1801 case CONFREJ:
tax 0:66300c77c6e9 1802 /* print option list */
tax 0:66300c77c6e9 1803 while (len >= 2) {
tax 0:66300c77c6e9 1804 GETCHAR(code, p);
tax 0:66300c77c6e9 1805 GETCHAR(olen, p);
tax 0:66300c77c6e9 1806 p -= 2;
tax 0:66300c77c6e9 1807 if (olen < 2 || olen > len) {
tax 0:66300c77c6e9 1808 break;
tax 0:66300c77c6e9 1809 }
tax 0:66300c77c6e9 1810 printer(arg, " <");
tax 0:66300c77c6e9 1811 len -= olen;
tax 0:66300c77c6e9 1812 optend = p + olen;
tax 0:66300c77c6e9 1813 switch (code) {
tax 0:66300c77c6e9 1814 case CI_MRU:
tax 0:66300c77c6e9 1815 if (olen == CILEN_SHORT) {
tax 0:66300c77c6e9 1816 p += 2;
tax 0:66300c77c6e9 1817 GETSHORT(cishort, p);
tax 0:66300c77c6e9 1818 printer(arg, "mru %d", cishort);
tax 0:66300c77c6e9 1819 }
tax 0:66300c77c6e9 1820 break;
tax 0:66300c77c6e9 1821 case CI_ASYNCMAP:
tax 0:66300c77c6e9 1822 if (olen == CILEN_LONG) {
tax 0:66300c77c6e9 1823 p += 2;
tax 0:66300c77c6e9 1824 GETLONG(cilong, p);
tax 0:66300c77c6e9 1825 printer(arg, "asyncmap 0x%lx", cilong);
tax 0:66300c77c6e9 1826 }
tax 0:66300c77c6e9 1827 break;
tax 0:66300c77c6e9 1828 case CI_AUTHTYPE:
tax 0:66300c77c6e9 1829 if (olen >= CILEN_SHORT) {
tax 0:66300c77c6e9 1830 p += 2;
tax 0:66300c77c6e9 1831 printer(arg, "auth ");
tax 0:66300c77c6e9 1832 GETSHORT(cishort, p);
tax 0:66300c77c6e9 1833 switch (cishort) {
tax 0:66300c77c6e9 1834 case PPP_PAP:
tax 0:66300c77c6e9 1835 printer(arg, "pap");
tax 0:66300c77c6e9 1836 break;
tax 0:66300c77c6e9 1837 case PPP_CHAP:
tax 0:66300c77c6e9 1838 printer(arg, "chap");
tax 0:66300c77c6e9 1839 break;
tax 0:66300c77c6e9 1840 default:
tax 0:66300c77c6e9 1841 printer(arg, "0x%x", cishort);
tax 0:66300c77c6e9 1842 }
tax 0:66300c77c6e9 1843 }
tax 0:66300c77c6e9 1844 break;
tax 0:66300c77c6e9 1845 case CI_QUALITY:
tax 0:66300c77c6e9 1846 if (olen >= CILEN_SHORT) {
tax 0:66300c77c6e9 1847 p += 2;
tax 0:66300c77c6e9 1848 printer(arg, "quality ");
tax 0:66300c77c6e9 1849 GETSHORT(cishort, p);
tax 0:66300c77c6e9 1850 switch (cishort) {
tax 0:66300c77c6e9 1851 case PPP_LQR:
tax 0:66300c77c6e9 1852 printer(arg, "lqr");
tax 0:66300c77c6e9 1853 break;
tax 0:66300c77c6e9 1854 default:
tax 0:66300c77c6e9 1855 printer(arg, "0x%x", cishort);
tax 0:66300c77c6e9 1856 }
tax 0:66300c77c6e9 1857 }
tax 0:66300c77c6e9 1858 break;
tax 0:66300c77c6e9 1859 case CI_CALLBACK:
tax 0:66300c77c6e9 1860 if (olen >= CILEN_CHAR) {
tax 0:66300c77c6e9 1861 p += 2;
tax 0:66300c77c6e9 1862 printer(arg, "callback ");
tax 0:66300c77c6e9 1863 GETSHORT(cishort, p);
tax 0:66300c77c6e9 1864 switch (cishort) {
tax 0:66300c77c6e9 1865 case CBCP_OPT:
tax 0:66300c77c6e9 1866 printer(arg, "CBCP");
tax 0:66300c77c6e9 1867 break;
tax 0:66300c77c6e9 1868 default:
tax 0:66300c77c6e9 1869 printer(arg, "0x%x", cishort);
tax 0:66300c77c6e9 1870 }
tax 0:66300c77c6e9 1871 }
tax 0:66300c77c6e9 1872 break;
tax 0:66300c77c6e9 1873 case CI_MAGICNUMBER:
tax 0:66300c77c6e9 1874 if (olen == CILEN_LONG) {
tax 0:66300c77c6e9 1875 p += 2;
tax 0:66300c77c6e9 1876 GETLONG(cilong, p);
tax 0:66300c77c6e9 1877 printer(arg, "magic 0x%x", cilong);
tax 0:66300c77c6e9 1878 }
tax 0:66300c77c6e9 1879 break;
tax 0:66300c77c6e9 1880 case CI_PCOMPRESSION:
tax 0:66300c77c6e9 1881 if (olen == CILEN_VOID) {
tax 0:66300c77c6e9 1882 p += 2;
tax 0:66300c77c6e9 1883 printer(arg, "pcomp");
tax 0:66300c77c6e9 1884 }
tax 0:66300c77c6e9 1885 break;
tax 0:66300c77c6e9 1886 case CI_ACCOMPRESSION:
tax 0:66300c77c6e9 1887 if (olen == CILEN_VOID) {
tax 0:66300c77c6e9 1888 p += 2;
tax 0:66300c77c6e9 1889 printer(arg, "accomp");
tax 0:66300c77c6e9 1890 }
tax 0:66300c77c6e9 1891 break;
tax 0:66300c77c6e9 1892 }
tax 0:66300c77c6e9 1893 while (p < optend) {
tax 0:66300c77c6e9 1894 GETCHAR(code, p);
tax 0:66300c77c6e9 1895 printer(arg, " %.2x", code);
tax 0:66300c77c6e9 1896 }
tax 0:66300c77c6e9 1897 printer(arg, ">");
tax 0:66300c77c6e9 1898 }
tax 0:66300c77c6e9 1899 break;
tax 0:66300c77c6e9 1900
tax 0:66300c77c6e9 1901 case TERMACK:
tax 0:66300c77c6e9 1902 case TERMREQ:
tax 0:66300c77c6e9 1903 if (len > 0 && *p >= ' ' && *p < 0x7f) {
tax 0:66300c77c6e9 1904 printer(arg, " ");
tax 0:66300c77c6e9 1905 print_string((char*)p, len, printer, arg);
tax 0:66300c77c6e9 1906 p += len;
tax 0:66300c77c6e9 1907 len = 0;
tax 0:66300c77c6e9 1908 }
tax 0:66300c77c6e9 1909 break;
tax 0:66300c77c6e9 1910
tax 0:66300c77c6e9 1911 case ECHOREQ:
tax 0:66300c77c6e9 1912 case ECHOREP:
tax 0:66300c77c6e9 1913 case DISCREQ:
tax 0:66300c77c6e9 1914 if (len >= 4) {
tax 0:66300c77c6e9 1915 GETLONG(cilong, p);
tax 0:66300c77c6e9 1916 printer(arg, " magic=0x%x", cilong);
tax 0:66300c77c6e9 1917 p += 4;
tax 0:66300c77c6e9 1918 len -= 4;
tax 0:66300c77c6e9 1919 }
tax 0:66300c77c6e9 1920 break;
tax 0:66300c77c6e9 1921 }
tax 0:66300c77c6e9 1922
tax 0:66300c77c6e9 1923 /* print the rest of the bytes in the packet */
tax 0:66300c77c6e9 1924 for (; len > 0; --len) {
tax 0:66300c77c6e9 1925 GETCHAR(code, p);
tax 0:66300c77c6e9 1926 printer(arg, " %.2x", code);
tax 0:66300c77c6e9 1927 }
tax 0:66300c77c6e9 1928
tax 0:66300c77c6e9 1929 return (int)(p - pstart);
tax 0:66300c77c6e9 1930 }
tax 0:66300c77c6e9 1931 #endif /* PPP_ADDITIONAL_CALLBACKS */
tax 0:66300c77c6e9 1932
tax 0:66300c77c6e9 1933 /*
tax 0:66300c77c6e9 1934 * Time to shut down the link because there is nothing out there.
tax 0:66300c77c6e9 1935 */
tax 0:66300c77c6e9 1936 static void
tax 0:66300c77c6e9 1937 LcpLinkFailure (fsm *f)
tax 0:66300c77c6e9 1938 {
tax 0:66300c77c6e9 1939 if (f->state == LS_OPENED) {
tax 0:66300c77c6e9 1940 LCPDEBUG(LOG_INFO, ("No response to %d echo-requests\n", lcp_echos_pending));
tax 0:66300c77c6e9 1941 LCPDEBUG(LOG_NOTICE, ("Serial link appears to be disconnected.\n"));
tax 0:66300c77c6e9 1942 lcp_close(f->unit, "Peer not responding");
tax 0:66300c77c6e9 1943 }
tax 0:66300c77c6e9 1944 }
tax 0:66300c77c6e9 1945
tax 0:66300c77c6e9 1946 /*
tax 0:66300c77c6e9 1947 * Timer expired for the LCP echo requests from this process.
tax 0:66300c77c6e9 1948 */
tax 0:66300c77c6e9 1949 static void
tax 0:66300c77c6e9 1950 LcpEchoCheck (fsm *f)
tax 0:66300c77c6e9 1951 {
tax 0:66300c77c6e9 1952 LcpSendEchoRequest (f);
tax 0:66300c77c6e9 1953
tax 0:66300c77c6e9 1954 /*
tax 0:66300c77c6e9 1955 * Start the timer for the next interval.
tax 0:66300c77c6e9 1956 */
tax 0:66300c77c6e9 1957 LWIP_ASSERT("lcp_echo_timer_running == 0", lcp_echo_timer_running == 0);
tax 0:66300c77c6e9 1958
tax 0:66300c77c6e9 1959 TIMEOUT (LcpEchoTimeout, f, lcp_echo_interval);
tax 0:66300c77c6e9 1960 lcp_echo_timer_running = 1;
tax 0:66300c77c6e9 1961 }
tax 0:66300c77c6e9 1962
tax 0:66300c77c6e9 1963 /*
tax 0:66300c77c6e9 1964 * LcpEchoTimeout - Timer expired on the LCP echo
tax 0:66300c77c6e9 1965 */
tax 0:66300c77c6e9 1966 static void
tax 0:66300c77c6e9 1967 LcpEchoTimeout (void *arg)
tax 0:66300c77c6e9 1968 {
tax 0:66300c77c6e9 1969 if (lcp_echo_timer_running != 0) {
tax 0:66300c77c6e9 1970 lcp_echo_timer_running = 0;
tax 0:66300c77c6e9 1971 LcpEchoCheck ((fsm *) arg);
tax 0:66300c77c6e9 1972 }
tax 0:66300c77c6e9 1973 }
tax 0:66300c77c6e9 1974
tax 0:66300c77c6e9 1975 /*
tax 0:66300c77c6e9 1976 * LcpEchoReply - LCP has received a reply to the echo
tax 0:66300c77c6e9 1977 */
tax 0:66300c77c6e9 1978 static void
tax 0:66300c77c6e9 1979 lcp_received_echo_reply (fsm *f, int id, u_char *inp, int len)
tax 0:66300c77c6e9 1980 {
tax 0:66300c77c6e9 1981 u32_t magic;
tax 0:66300c77c6e9 1982
tax 0:66300c77c6e9 1983 LWIP_UNUSED_ARG(id);
tax 0:66300c77c6e9 1984
tax 0:66300c77c6e9 1985 /* Check the magic number - don't count replies from ourselves. */
tax 0:66300c77c6e9 1986 if (len < 4) {
tax 0:66300c77c6e9 1987 LCPDEBUG(LOG_WARNING, ("lcp: received short Echo-Reply, length %d\n", len));
tax 0:66300c77c6e9 1988 return;
tax 0:66300c77c6e9 1989 }
tax 0:66300c77c6e9 1990 GETLONG(magic, inp);
tax 0:66300c77c6e9 1991 if (lcp_gotoptions[f->unit].neg_magicnumber && magic == lcp_gotoptions[f->unit].magicnumber) {
tax 0:66300c77c6e9 1992 LCPDEBUG(LOG_WARNING, ("appear to have received our own echo-reply!\n"));
tax 0:66300c77c6e9 1993 return;
tax 0:66300c77c6e9 1994 }
tax 0:66300c77c6e9 1995
tax 0:66300c77c6e9 1996 /* Reset the number of outstanding echo frames */
tax 0:66300c77c6e9 1997 lcp_echos_pending = 0;
tax 0:66300c77c6e9 1998 }
tax 0:66300c77c6e9 1999
tax 0:66300c77c6e9 2000 /*
tax 0:66300c77c6e9 2001 * LcpSendEchoRequest - Send an echo request frame to the peer
tax 0:66300c77c6e9 2002 */
tax 0:66300c77c6e9 2003 static void
tax 0:66300c77c6e9 2004 LcpSendEchoRequest (fsm *f)
tax 0:66300c77c6e9 2005 {
tax 0:66300c77c6e9 2006 u32_t lcp_magic;
tax 0:66300c77c6e9 2007 u_char pkt[4], *pktp;
tax 0:66300c77c6e9 2008
tax 0:66300c77c6e9 2009 /*
tax 0:66300c77c6e9 2010 * Detect the failure of the peer at this point.
tax 0:66300c77c6e9 2011 */
tax 0:66300c77c6e9 2012 if (lcp_echo_fails != 0) {
tax 0:66300c77c6e9 2013 if (lcp_echos_pending >= lcp_echo_fails) {
tax 0:66300c77c6e9 2014 LcpLinkFailure(f);
tax 0:66300c77c6e9 2015 lcp_echos_pending = 0;
tax 0:66300c77c6e9 2016 }
tax 0:66300c77c6e9 2017 }
tax 0:66300c77c6e9 2018
tax 0:66300c77c6e9 2019 /*
tax 0:66300c77c6e9 2020 * Make and send the echo request frame.
tax 0:66300c77c6e9 2021 */
tax 0:66300c77c6e9 2022 if (f->state == LS_OPENED) {
tax 0:66300c77c6e9 2023 lcp_magic = lcp_gotoptions[f->unit].magicnumber;
tax 0:66300c77c6e9 2024 pktp = pkt;
tax 0:66300c77c6e9 2025 PUTLONG(lcp_magic, pktp);
tax 0:66300c77c6e9 2026 fsm_sdata(f, ECHOREQ, (u_char)(lcp_echo_number++ & 0xFF), pkt, (int)(pktp - pkt));
tax 0:66300c77c6e9 2027 ++lcp_echos_pending;
tax 0:66300c77c6e9 2028 }
tax 0:66300c77c6e9 2029 }
tax 0:66300c77c6e9 2030
tax 0:66300c77c6e9 2031 /*
tax 0:66300c77c6e9 2032 * lcp_echo_lowerup - Start the timer for the LCP frame
tax 0:66300c77c6e9 2033 */
tax 0:66300c77c6e9 2034
tax 0:66300c77c6e9 2035 static void
tax 0:66300c77c6e9 2036 lcp_echo_lowerup (int unit)
tax 0:66300c77c6e9 2037 {
tax 0:66300c77c6e9 2038 fsm *f = &lcp_fsm[unit];
tax 0:66300c77c6e9 2039
tax 0:66300c77c6e9 2040 /* Clear the parameters for generating echo frames */
tax 0:66300c77c6e9 2041 lcp_echos_pending = 0;
tax 0:66300c77c6e9 2042 lcp_echo_number = 0;
tax 0:66300c77c6e9 2043 lcp_echo_timer_running = 0;
tax 0:66300c77c6e9 2044
tax 0:66300c77c6e9 2045 /* If a timeout interval is specified then start the timer */
tax 0:66300c77c6e9 2046 if (lcp_echo_interval != 0) {
tax 0:66300c77c6e9 2047 LcpEchoCheck (f);
tax 0:66300c77c6e9 2048 }
tax 0:66300c77c6e9 2049 }
tax 0:66300c77c6e9 2050
tax 0:66300c77c6e9 2051 /*
tax 0:66300c77c6e9 2052 * lcp_echo_lowerdown - Stop the timer for the LCP frame
tax 0:66300c77c6e9 2053 */
tax 0:66300c77c6e9 2054
tax 0:66300c77c6e9 2055 static void
tax 0:66300c77c6e9 2056 lcp_echo_lowerdown (int unit)
tax 0:66300c77c6e9 2057 {
tax 0:66300c77c6e9 2058 fsm *f = &lcp_fsm[unit];
tax 0:66300c77c6e9 2059
tax 0:66300c77c6e9 2060 if (lcp_echo_timer_running != 0) {
tax 0:66300c77c6e9 2061 UNTIMEOUT (LcpEchoTimeout, f);
tax 0:66300c77c6e9 2062 lcp_echo_timer_running = 0;
tax 0:66300c77c6e9 2063 }
tax 0:66300c77c6e9 2064 }
tax 0:66300c77c6e9 2065
tax 0:66300c77c6e9 2066 #endif /* PPP_SUPPORT */