Bonjour/Zerconf library

Dependencies:   mbed

Committer:
dirkx
Date:
Sat Aug 14 15:54:31 2010 +0000
Revision:
5:8e53abda9900
Parent:
0:355018f44c9f

        

Who changed what in which revision?

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