annotate packages/net/ppp/current/src/lcp.c @ 1777:c16341b1bac6 default tip

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