NetTribute library with debug turned on in FShandler Donatien Garner -> Segundo Equipo -> this version

Committer:
hexley
Date:
Fri Nov 19 01:54:45 2010 +0000
Revision:
0:281d6ff68967

        

Who changed what in which revision?

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