1 | /*
|
---|
2 | * TINET (TCP/IP Protocol Stack)
|
---|
3 | *
|
---|
4 | * Copyright (C) 2001-2017 by Dep. of Computer Science and Engineering
|
---|
5 | * Tomakomai National College of Technology, JAPAN
|
---|
6 | *
|
---|
7 | * ä¸è¨èä½æ¨©è
|
---|
8 | ã¯ï¼ä»¥ä¸ã® (1)ï½(4) ã®æ¡ä»¶ãï¼Free Software Foundation
|
---|
9 | * ã«ãã£ã¦å
|
---|
10 | ¬è¡¨ããã¦ãã GNU General Public License ã® Version 2 ã«è¨
|
---|
11 | * è¿°ããã¦ããæ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§ã¢ï¼æ¬ã½ããã¦ã§ã¢
|
---|
12 | * ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹å¤ã»åé
|
---|
13 | å¸ï¼ä»¥ä¸ï¼
|
---|
14 | * å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
15 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
16 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
17 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
18 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
19 | * ç¨ã§ããå½¢ã§åé
|
---|
20 | å¸ããå ´åã«ã¯ï¼åé
|
---|
21 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
22 | * è
|
---|
23 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
24 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
25 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
26 | * ç¨ã§ããªãå½¢ã§åé
|
---|
27 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®æ¡ä»¶ãæºãããã¨ï¼
|
---|
28 | * (a) åé
|
---|
29 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
30 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
31 | * ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
32 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
33 | * 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
34 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
35 | 責ãããã¨ï¼
|
---|
36 | *
|
---|
37 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
38 | ã
|
---|
39 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ãã®é©ç¨å¯è½æ§ã
|
---|
40 | * å«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´
|
---|
41 | * æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ãã®è²¬ä»»ãè² ããªãï¼
|
---|
42 | *
|
---|
43 | * @(#) $Id: ppp_lcp.c 317 2017-08-03 13:14:26Z coas-nagasima $
|
---|
44 | */
|
---|
45 |
|
---|
46 | /*
|
---|
47 | * lcp.c - PPP Link Control Protocol.
|
---|
48 | *
|
---|
49 | * Copyright (c) 1989 Carnegie Mellon University.
|
---|
50 | * All rights reserved.
|
---|
51 | *
|
---|
52 | * Redistribution and use in source and binary forms are permitted
|
---|
53 | * provided that the above copyright notice and this paragraph are
|
---|
54 | * duplicated in all such forms and that any documentation,
|
---|
55 | * advertising materials, and other materials related to such
|
---|
56 | * distribution and use acknowledge that the software was developed
|
---|
57 | * by Carnegie Mellon University. The name of the
|
---|
58 | * University may not be used to endorse or promote products derived
|
---|
59 | * from this software without specific prior written permission.
|
---|
60 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
---|
61 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
---|
62 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
---|
63 | */
|
---|
64 |
|
---|
65 | /*
|
---|
66 | * PPP Link Control Protocol (LCP) Module
|
---|
67 | *
|
---|
68 | * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
|
---|
69 | *
|
---|
70 | * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
|
---|
71 | *
|
---|
72 | * Redistribution and use in source and binary forms are permitted
|
---|
73 | * provided that the above copyright notice and this paragraph are
|
---|
74 | * duplicated in all such forms and that any documentation,
|
---|
75 | * advertising materials, and other materials related to such
|
---|
76 | * distribution and use acknowledge that the software was developed
|
---|
77 | * by the Internet Initiative Japan, Inc. The name of the
|
---|
78 | * IIJ may not be used to endorse or promote products derived
|
---|
79 | * from this software without specific prior written permission.
|
---|
80 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
---|
81 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
---|
82 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
---|
83 | *
|
---|
84 | * $FreeBSD: src/usr.sbin/ppp/lcp.c,v 1.81.2.3 2000/08/19 09:30:04 brian Exp $
|
---|
85 | *
|
---|
86 | */
|
---|
87 |
|
---|
88 | #include <string.h>
|
---|
89 |
|
---|
90 | #include <s_services.h>
|
---|
91 | #include <t_services.h>
|
---|
92 | #include "kernel_id.h"
|
---|
93 |
|
---|
94 | #include <tinet_defs.h>
|
---|
95 | #include <tinet_config.h>
|
---|
96 |
|
---|
97 | #include <net/if.h>
|
---|
98 | #include <net/if_ppp.h>
|
---|
99 | #include <net/net.h>
|
---|
100 | #include <net/net_endian.h>
|
---|
101 | #include <net/net_var.h>
|
---|
102 | #include <net/net_buf.h>
|
---|
103 | #include <net/net_timer.h>
|
---|
104 | #include <net/net_count.h>
|
---|
105 | #include <net/ppp.h>
|
---|
106 | #include <net/ppp_var.h>
|
---|
107 | #include <net/ppp_hdlc.h>
|
---|
108 | #include <net/ppp_auth.h>
|
---|
109 | #include <net/ppp_fsm.h>
|
---|
110 | #include <net/ppp_lcp.h>
|
---|
111 |
|
---|
112 | #ifdef SUPPORT_PPP
|
---|
113 |
|
---|
114 | /*
|
---|
115 | * é¢æ°
|
---|
116 | */
|
---|
117 |
|
---|
118 | static void lcp_init (void);
|
---|
119 | static void lcp_protrej (void);
|
---|
120 | static void lcp_input (T_NET_BUF *input);
|
---|
121 |
|
---|
122 | #if DEF_LCP_LOCAL_CFGS & LCP_CFG_MAGIC
|
---|
123 |
|
---|
124 | static void send_echo_req (T_PPP_FSM *fsm);
|
---|
125 | static void recv_echo_rep (T_PPP_FSM *fsm, uint8_t id, T_NET_BUF *input);
|
---|
126 | static void echo_timeout (void *arg);
|
---|
127 | static void echo_lowerup (void);
|
---|
128 | static void echo_lowerdown (void);
|
---|
129 |
|
---|
130 | #endif /* of #if DEF_LCP_LOCAL_CFGS & LCP_CFG_MAGIC */
|
---|
131 |
|
---|
132 | /*
|
---|
133 | * FSM ããå¼åºãããã³ã¼ã«ããã¯é¢æ°
|
---|
134 | */
|
---|
135 |
|
---|
136 | static void lcp_resetci(T_PPP_FSM *fsm); /* èªæ§ææ
|
---|
137 | å ±ããªã»ããããã */
|
---|
138 | static int_t lcp_cilen (T_PPP_FSM *fsm); /* æ§ææ
|
---|
139 | å ±ã®é·ããè¿ãã */
|
---|
140 | static void lcp_addci (T_PPP_FSM *fsm, T_NET_BUF *output);
|
---|
141 | /* èªæ§ææ
|
---|
142 | å ±ã追å ããã */
|
---|
143 | static bool_t lcp_ackci (T_PPP_FSM *fsm, T_NET_BUF *input);
|
---|
144 | /* ACK ãåä¿¡ããã¨ãã®å¦ç */
|
---|
145 | static bool_t lcp_nakci (T_PPP_FSM *fsm, T_NET_BUF *input);
|
---|
146 | /* NAK ãåä¿¡ããã¨ãã®å¦ç */
|
---|
147 | static bool_t lcp_rejci (T_PPP_FSM *fsm, T_NET_BUF *input);
|
---|
148 | /* REJ ãåä¿¡ããã¨ãã®å¦ç */
|
---|
149 | static int_t lcp_reqci (T_PPP_FSM *fsm, T_NET_BUF *input, T_NET_BUF *output);
|
---|
150 | /* ç¸æã®æ§ææ
|
---|
151 | å ±ã確èªããã */
|
---|
152 | static void lcp_up (T_PPP_FSM *fsm); /* ãªã³ã¯æ¥ç¶ã確ç«ããã */
|
---|
153 | static void lcp_starting(T_PPP_FSM *fsm); /* ä¸ä½å±¤ãéå§ããã */
|
---|
154 | static bool_t lcp_extcode (T_PPP_FSM *fsm, uint8_t code, uint8_t id, T_NET_BUF *input);
|
---|
155 | /* ä¸æ㪠CP ãåä¿¡ããã¨ãã®å¦ç */
|
---|
156 | static void lcp_rprotrej(T_PPP_FSM *fsm, T_NET_BUF *input);
|
---|
157 | /* Proto-REJ ãåä¿¡ããã¨ãã®å¦ç */
|
---|
158 | /*
|
---|
159 | * å¤æ°
|
---|
160 | */
|
---|
161 |
|
---|
162 | static T_LCP_CONFIGS lcp_def_cfg = { /* æ§ææ
|
---|
163 | å ±ã®åæè¨å®å¤ */
|
---|
164 | DEF_REMOTE_ACCM, /* ACCM */
|
---|
165 |
|
---|
166 | #ifdef LCP_CFG_MAGIC
|
---|
167 |
|
---|
168 | ULONG_C(0), /* ãã¸ãã¯çªå· */
|
---|
169 |
|
---|
170 | #endif /* of #ifdef LCP_CFG_MAGIC */
|
---|
171 |
|
---|
172 | DEF_PPP_MTU, /* MRU */
|
---|
173 | UINT_C(0), /* ãªãã·ã§ã³ãã©ã° */
|
---|
174 | };
|
---|
175 |
|
---|
176 | static T_LCP_CONFIGS lcp_local_def_cfg = { /* èªæ§ææ
|
---|
177 | å ±ã®è¦å®å¤ */
|
---|
178 | DEF_LOCAL_ACCM, /* ACCM */
|
---|
179 |
|
---|
180 | #ifdef LCP_CFG_MAGIC
|
---|
181 |
|
---|
182 | ULONG_C(0), /* ãã¸ãã¯çªå· */
|
---|
183 |
|
---|
184 | #endif /* of #ifdef LCP_CFG_MAGIC */
|
---|
185 |
|
---|
186 | DEF_PPP_MTU, /* MRU */
|
---|
187 | DEF_LCP_LOCAL_CFGS, /* ãªãã·ã§ã³ãã©ã° */
|
---|
188 | };
|
---|
189 |
|
---|
190 | static T_LCP_CONFIGS lcp_local_neg_cfg; /* ãã´ä¸ã®èªæ§ææ
|
---|
191 | å ± */
|
---|
192 |
|
---|
193 | static T_LCP_CONFIGS lcp_remote_neg_cfg; /* ãã´ä¸ã®ç¸æã®æ§ææ
|
---|
194 | å ± */
|
---|
195 |
|
---|
196 | #if DEF_LCP_LOCAL_CFGS & LCP_CFG_MAGIC
|
---|
197 |
|
---|
198 | static uint8_t echo_pending = UINT_C(0);
|
---|
199 | static uint8_t echo_number = UINT_C(0);
|
---|
200 | static uint8_t timer_running = false;
|
---|
201 |
|
---|
202 | #endif /* of #if DEF_LCP_LOCAL_CFGS & LCP_CFG_MAGIC */
|
---|
203 |
|
---|
204 | /*
|
---|
205 | * å
|
---|
206 | ¨åå¤æ°
|
---|
207 | */
|
---|
208 |
|
---|
209 | T_PPP_FSM_CALLBACKS lcp_callbacks = {
|
---|
210 | lcp_resetci, /* èªæ§ææ
|
---|
211 | å ±ããªã»ããããã */
|
---|
212 | lcp_cilen, /* æ§ææ
|
---|
213 | å ±ã®é·ããè¿ãã */
|
---|
214 | lcp_addci, /* èªæ§ææ
|
---|
215 | å ±ã追å ããã */
|
---|
216 | lcp_ackci, /* ACK ãåä¿¡ããã¨ãã®å¦ç */
|
---|
217 | lcp_nakci, /* NAK ãåä¿¡ããã¨ãã®å¦ç */
|
---|
218 | lcp_rejci, /* REJ ãåä¿¡ããã¨ãã®å¦ç */
|
---|
219 | lcp_reqci, /* ç¸æã®æ§ææ
|
---|
220 | å ±ã確èªããã */
|
---|
221 | lcp_up, /* ãªã³ã¯æ¥ç¶ã確ç«ããã */
|
---|
222 | lcp_down, /* ãªã³ã¯æ¥ç¶ã解æ¾ããã */
|
---|
223 | lcp_starting, /* ä¸ä½å±¤ãéå§ããã */
|
---|
224 | lcp_finished, /* ä¸ä½å±¤ãçµäºããã */
|
---|
225 | NULL, /* åéããã */
|
---|
226 | lcp_extcode, /* ä¸æ㪠CP ãåä¿¡ããã¨ãã®å¦ç */
|
---|
227 | };
|
---|
228 |
|
---|
229 | T_PPP_FSM lcp_fsm = {
|
---|
230 | &lcp_callbacks, /* ã³ã¼ã«ããã¯é¢æ° */
|
---|
231 | PPP_LCP, /* ãããã³ã« */
|
---|
232 | };
|
---|
233 |
|
---|
234 | T_PPP_PROTENT lcp_protent = {
|
---|
235 | PPP_LCP,
|
---|
236 | lcp_init, /* åæå */
|
---|
237 | lcp_input, /* å
|
---|
238 | ¥å */
|
---|
239 | lcp_protrej, /* Proto-REJ åä¿¡å¦ç */
|
---|
240 | NULL, /* ä¸ä½å±¤ãèµ·åãã */
|
---|
241 | lcp_lowerdown, /* ä¸ä½å±¤ãåæ¢ãã */
|
---|
242 | NULL, /* ãªã¼ãã³ãã */
|
---|
243 | lcp_close, /* ã¯ãã¼ãºãã */
|
---|
244 | NULL, /* ãã¼ã¿å
|
---|
245 | ¥å */
|
---|
246 | };
|
---|
247 |
|
---|
248 | T_LCP_CONFIGS lcp_local_ack_cfg; /* ç¸æã«è¨±å¯ãããã®èªæ§ææ
|
---|
249 | å ± */
|
---|
250 | T_LCP_CONFIGS lcp_remote_ack_cfg; /* ç¸æã«è¨±å¯ããæ§ææ
|
---|
251 | å ± */
|
---|
252 |
|
---|
253 | /*
|
---|
254 | * lcp_init -- LCP ã¢ã¸ã¥ã¼ã«ã®åæå
|
---|
255 | */
|
---|
256 |
|
---|
257 | static void
|
---|
258 | lcp_init (void)
|
---|
259 | {
|
---|
260 | fsm_init(&lcp_fsm);
|
---|
261 | }
|
---|
262 |
|
---|
263 | /*
|
---|
264 | * lcp_input -- LCP å
|
---|
265 | ¥å
|
---|
266 | */
|
---|
267 |
|
---|
268 | static void
|
---|
269 | lcp_input (T_NET_BUF *input)
|
---|
270 | {
|
---|
271 | NET_COUNT_PPP_LCP(net_count_ppp_lcp_in_octets, input->len);
|
---|
272 | NET_COUNT_PPP_LCP(net_count_ppp_lcp_in_packets, 1);
|
---|
273 | fsm_input(&lcp_fsm, input);
|
---|
274 | }
|
---|
275 |
|
---|
276 | /*
|
---|
277 | * lcp_resetci -- LCPã®æ§ææ
|
---|
278 | å ±ããªã»ããããã
|
---|
279 | */
|
---|
280 |
|
---|
281 | static void
|
---|
282 | lcp_resetci (T_PPP_FSM *fsm)
|
---|
283 | {
|
---|
284 | #ifdef LCP_CFG_MAGIC
|
---|
285 |
|
---|
286 | SYSTIM time;
|
---|
287 |
|
---|
288 | #endif /* of #ifdef LCP_CFG_MAGIC */
|
---|
289 |
|
---|
290 | /* èªæ§ææ
|
---|
291 | å ±ã®åæè¨å® */
|
---|
292 | lcp_local_neg_cfg = lcp_local_def_cfg;
|
---|
293 | lcp_local_ack_cfg = lcp_def_cfg;
|
---|
294 |
|
---|
295 | /* ç¸æã®æ§ææ
|
---|
296 | å ±ã®åæè¨å® */
|
---|
297 | lcp_remote_neg_cfg = lcp_def_cfg;
|
---|
298 | lcp_remote_ack_cfg = lcp_def_cfg;
|
---|
299 |
|
---|
300 | #ifdef LCP_CFG_MAGIC
|
---|
301 |
|
---|
302 | syscall(get_tim(&time));
|
---|
303 | net_srand((unsigned int)time);
|
---|
304 | lcp_local_neg_cfg.magic = net_rand();
|
---|
305 |
|
---|
306 | #endif /* of #ifdef LCP_CFG_MAGIC */
|
---|
307 |
|
---|
308 | auth_reset();
|
---|
309 | }
|
---|
310 |
|
---|
311 | /*
|
---|
312 | * lcp_cilen -- æ§ææ
|
---|
313 | å ±ã®é·ããè¿ãã
|
---|
314 | */
|
---|
315 |
|
---|
316 | static int_t
|
---|
317 | lcp_cilen (T_PPP_FSM *fsm)
|
---|
318 | {
|
---|
319 | int_t cilen = 0;
|
---|
320 |
|
---|
321 | if (lcp_local_neg_cfg.options & LCP_CFG_MRU)
|
---|
322 | cilen += sizeof(T_PPP_CI_HDR) + sizeof(uint16_t); /* MRU */
|
---|
323 |
|
---|
324 | if (lcp_local_neg_cfg.options & LCP_CFG_ACCM)
|
---|
325 | cilen += sizeof(T_PPP_CI_HDR) + sizeof(uint32_t); /* ACCM */
|
---|
326 |
|
---|
327 | #ifdef LCP_CFG_MAGIC
|
---|
328 |
|
---|
329 | if (lcp_local_neg_cfg.options & LCP_CFG_MAGIC)
|
---|
330 | cilen += sizeof(T_PPP_CI_HDR) + sizeof(uint32_t); /* Magic */
|
---|
331 |
|
---|
332 | #endif /* of #ifdef LCP_CFG_MAGIC */
|
---|
333 |
|
---|
334 | #ifdef LCP_CFG_PAP
|
---|
335 |
|
---|
336 | if (lcp_local_neg_cfg.options & LCP_CFG_PAP)
|
---|
337 | cilen += sizeof(T_PPP_CI_HDR) + sizeof(uint16_t); /* PAP */
|
---|
338 |
|
---|
339 | #endif /* of #ifdef LCP_CFG_PAP */
|
---|
340 |
|
---|
341 | #ifdef LCP_CFG_PCOMP
|
---|
342 |
|
---|
343 | if (lcp_local_neg_cfg.options & LCP_CFG_PCOMP)
|
---|
344 | cilen += sizeof(T_PPP_CI_HDR); /* ãããã³ã«å§ç¸® */
|
---|
345 |
|
---|
346 | #endif /* of #ifdef LCP_CFG_PCOMP */
|
---|
347 |
|
---|
348 | #ifdef LCP_CFG_ACCOMP
|
---|
349 |
|
---|
350 | if (lcp_local_neg_cfg.options & LCP_CFG_ACCOMP)
|
---|
351 | cilen += sizeof(T_PPP_CI_HDR); /* ã¢ãã¬ã¹ã»å¶å¾¡å§ç¸® */
|
---|
352 |
|
---|
353 | #endif /* of #ifdef LCP_CFG_ACCOMP */
|
---|
354 |
|
---|
355 | return cilen;
|
---|
356 | }
|
---|
357 |
|
---|
358 | /*
|
---|
359 | * lcp_addci -- LCPã®æ§ææ
|
---|
360 | å ±ã追å ããã
|
---|
361 | */
|
---|
362 |
|
---|
363 | static void
|
---|
364 | lcp_addci (T_PPP_FSM *fsm, T_NET_BUF *output)
|
---|
365 | {
|
---|
366 | uint8_t *buf;
|
---|
367 |
|
---|
368 | buf = output->buf + sizeof(T_PPP_HDR) + sizeof(T_PPP_CP_HDR);
|
---|
369 |
|
---|
370 | /* MRU ãªãã·ã§ã³ã追å ããã */
|
---|
371 | if (lcp_local_neg_cfg.options & LCP_CFG_MRU) {
|
---|
372 | *buf ++ = LCP_CIT_MRU;
|
---|
373 | *buf ++ = sizeof(T_PPP_CI_HDR) + sizeof(uint16_t);
|
---|
374 | *((uint16_t*)buf) = htons(lcp_local_neg_cfg.MRU);
|
---|
375 | buf += sizeof(uint16_t);
|
---|
376 | }
|
---|
377 |
|
---|
378 | /* ACCM ãªãã·ã§ã³ã追å ããã */
|
---|
379 | if (lcp_local_neg_cfg.options & LCP_CFG_ACCM) {
|
---|
380 | *buf ++ = LCP_CIT_ACCM;
|
---|
381 | *buf ++ = sizeof(T_PPP_CI_HDR) + sizeof(uint32_t);
|
---|
382 | ahtonl(buf, lcp_local_neg_cfg.ACCM);
|
---|
383 | buf += sizeof(uint32_t);
|
---|
384 | }
|
---|
385 |
|
---|
386 | #ifdef LCP_CFG_MAGIC
|
---|
387 |
|
---|
388 | /* Magic Number ãªãã·ã§ã³ã追å ããã */
|
---|
389 | if (lcp_local_neg_cfg.options & LCP_CFG_MAGIC) {
|
---|
390 | *buf ++ = LCP_CIT_MAGIC;
|
---|
391 | *buf ++ = sizeof(T_PPP_CI_HDR) + sizeof(uint32_t);
|
---|
392 | ahtonl(buf, lcp_local_neg_cfg.magic);
|
---|
393 | buf += sizeof(uint32_t);
|
---|
394 | }
|
---|
395 |
|
---|
396 | #endif /* of #ifdef LCP_CFG_MAGIC */
|
---|
397 |
|
---|
398 | #ifdef LCP_CFG_PAP
|
---|
399 |
|
---|
400 | /* èªè¨¼ãããã³ã«ãªãã·ã§ã³ã追å ããã */
|
---|
401 | if (lcp_local_neg_cfg.options & LCP_CFG_PAP) {
|
---|
402 | *buf ++ = LCP_CIT_AUTH;
|
---|
403 | *buf ++ = sizeof(T_PPP_CI_HDR) + sizeof(uint16_t);
|
---|
404 | *((uint16_t*)buf) = htons(PPP_PAP);
|
---|
405 | buf += sizeof(uint16_t);
|
---|
406 | }
|
---|
407 |
|
---|
408 | #endif /* of #ifdef LCP_CFG_PAP */
|
---|
409 |
|
---|
410 | #ifdef LCP_CFG_PCOMP
|
---|
411 |
|
---|
412 | /* ãããã³ã«å§ç¸®ãªãã·ã§ã³ã追å ããã */
|
---|
413 | if (lcp_local_neg_cfg.options & LCP_CFG_PCOMP) {
|
---|
414 | *buf ++ = LCP_CIT_PCOMP;
|
---|
415 | *buf ++ = sizeof(T_PPP_CI_HDR);
|
---|
416 | }
|
---|
417 |
|
---|
418 | #endif /* of #ifdef LCP_CFG_PCOMP */
|
---|
419 |
|
---|
420 | #ifdef LCP_CFG_ACCOMP
|
---|
421 |
|
---|
422 | /* ã¢ãã¬ã¹ã»å¶å¾¡å§ç¸®ãªãã·ã§ã³ã追å ããã */
|
---|
423 | if (lcp_local_neg_cfg.options & LCP_CFG_ACCOMP) {
|
---|
424 | *buf ++ = LCP_CIT_ACCOMP;
|
---|
425 | *buf ++ = sizeof(T_PPP_CI_HDR);
|
---|
426 | }
|
---|
427 |
|
---|
428 | #endif /* of #ifdef LCP_CFG_ACCOMP */
|
---|
429 | }
|
---|
430 |
|
---|
431 | /*
|
---|
432 | * lcp_ackci -- ACK ãåä¿¡ããã¨ãã®å¦ç
|
---|
433 | *
|
---|
434 | * æ»ãå¤: TURE ACK ã¯æ£å¸¸
|
---|
435 | * false ACK ã¯ç°å¸¸
|
---|
436 | */
|
---|
437 |
|
---|
438 | static bool_t
|
---|
439 | lcp_ackci (T_PPP_FSM *fsm, T_NET_BUF *input)
|
---|
440 | {
|
---|
441 | uint8_t *buf;
|
---|
442 | uint16_t len;
|
---|
443 |
|
---|
444 | buf = input->buf + sizeof(T_PPP_HDR) + sizeof(T_PPP_CP_HDR);
|
---|
445 | len = input->len - (sizeof(T_PPP_HDR) + sizeof(T_PPP_CP_HDR));
|
---|
446 |
|
---|
447 | /*
|
---|
448 | * æ§ææ
|
---|
449 | å ±ã¯éä¿¡ããé ã«å®å
|
---|
450 | ¨ã«ä¸è´ããªããã°ãªããªãã
|
---|
451 | * å¾ã£ã¦ãlcp_addci ã§ä½æããé ã«è§£æããã
|
---|
452 | */
|
---|
453 |
|
---|
454 | /* MRU ãªãã·ã§ã³ã解æããã */
|
---|
455 | if (lcp_local_neg_cfg.options & LCP_CFG_MRU) {
|
---|
456 | if (len < sizeof(T_PPP_CI_HDR) + sizeof(uint16_t) ||
|
---|
457 | *buf ++ != LCP_CIT_MRU ||
|
---|
458 | *buf ++ != sizeof(T_PPP_CI_HDR) + sizeof(uint16_t)||
|
---|
459 | *((uint16_t*)buf) != htons(lcp_local_neg_cfg.MRU) )
|
---|
460 | return false;
|
---|
461 | buf += sizeof(uint16_t);
|
---|
462 | len -= sizeof(T_PPP_CI_HDR) + sizeof(uint16_t);
|
---|
463 | }
|
---|
464 |
|
---|
465 | /* ACCM ãªãã·ã§ã³ã解æããã */
|
---|
466 | if (lcp_local_neg_cfg.options & LCP_CFG_ACCM) {
|
---|
467 | if (len < sizeof(T_PPP_CI_HDR) + sizeof(uint32_t) ||
|
---|
468 | *buf ++ != LCP_CIT_ACCM ||
|
---|
469 | *buf ++ != sizeof(T_PPP_CI_HDR) + sizeof(uint32_t)||
|
---|
470 | nahcmpl(buf, lcp_local_neg_cfg.ACCM) )
|
---|
471 | return false;
|
---|
472 | buf += sizeof(uint32_t);
|
---|
473 | len -= sizeof(T_PPP_CI_HDR) + sizeof(uint32_t);
|
---|
474 | }
|
---|
475 |
|
---|
476 | #ifdef LCP_CFG_MAGIC
|
---|
477 |
|
---|
478 | /* Magic Number ãªãã·ã§ã³ã解æããã */
|
---|
479 | if (lcp_local_neg_cfg.options & LCP_CFG_MAGIC) {
|
---|
480 | if (len < sizeof(T_PPP_CI_HDR) + sizeof(uint32_t) ||
|
---|
481 | *buf ++ != LCP_CIT_MAGIC ||
|
---|
482 | *buf ++ != sizeof(T_PPP_CI_HDR) + sizeof(uint32_t)||
|
---|
483 | nahcmpl(buf, lcp_local_neg_cfg.magic) )
|
---|
484 | return false;
|
---|
485 | buf += sizeof(uint32_t);
|
---|
486 | len -= sizeof(T_PPP_CI_HDR) + sizeof(uint32_t);
|
---|
487 | }
|
---|
488 |
|
---|
489 | #endif /* of #ifdef LCP_CFG_MAGIC */
|
---|
490 |
|
---|
491 | #ifdef LCP_CFG_PAP
|
---|
492 |
|
---|
493 | /* èªè¨¼ãããã³ã«ãªãã·ã§ã³ã解æããã */
|
---|
494 | if (lcp_local_neg_cfg.options & LCP_CFG_PAP) {
|
---|
495 | if (len < sizeof(T_PPP_CI_HDR) + sizeof(uint16_t) ||
|
---|
496 | *buf ++ != LCP_CIT_AUTH ||
|
---|
497 | *buf ++ != sizeof(T_PPP_CI_HDR) + sizeof(uint16_t)||
|
---|
498 | *((uint16_t*)buf) != htons(PPP_PAP) )
|
---|
499 | return false;
|
---|
500 | buf += sizeof(uint16_t);
|
---|
501 | len -= sizeof(T_PPP_CI_HDR) + sizeof(uint16_t);
|
---|
502 | }
|
---|
503 |
|
---|
504 | #endif /* of #ifdef LCP_CFG_PAP */
|
---|
505 |
|
---|
506 | #ifdef LCP_CFG_PCOMP
|
---|
507 |
|
---|
508 | /* ãããã³ã«å§ç¸®ãªãã·ã§ã³ã解æããã */
|
---|
509 | if (lcp_local_neg_cfg.options & LCP_CFG_PCOMP) {
|
---|
510 | if (len < sizeof(T_PPP_CI_HDR) ||
|
---|
511 | *buf ++ != LCP_CIT_PCOMP ||
|
---|
512 | *buf ++ != sizeof(T_PPP_CI_HDR))
|
---|
513 | return false;
|
---|
514 | len -= sizeof(T_PPP_CI_HDR);
|
---|
515 | }
|
---|
516 |
|
---|
517 | #endif /* of #ifdef LCP_CFG_PCOMP */
|
---|
518 |
|
---|
519 | #ifdef LCP_CFG_ACCOMP
|
---|
520 |
|
---|
521 | /* ã¢ãã¬ã¹ã»å¶å¾¡å§ç¸®ãªãã·ã§ã³ã解æããã */
|
---|
522 | if (lcp_local_neg_cfg.options & LCP_CFG_ACCOMP) {
|
---|
523 | if (len < sizeof(T_PPP_CI_HDR) ||
|
---|
524 | *buf ++ != LCP_CIT_ACCOMP ||
|
---|
525 | *buf ++ != sizeof(T_PPP_CI_HDR))
|
---|
526 | return false;
|
---|
527 | len -= sizeof(T_PPP_CI_HDR);
|
---|
528 | }
|
---|
529 |
|
---|
530 | #endif /* of #ifdef LCP_CFG_ACCOMP */
|
---|
531 | return true;
|
---|
532 | }
|
---|
533 |
|
---|
534 | /*
|
---|
535 | * lcp_nakci -- NAK ãåä¿¡ããã¨ãã®å¦ç
|
---|
536 | *
|
---|
537 | * æ»ãå¤: 1 NAK ã¯æ£å¸¸
|
---|
538 | * 0 NAK ã¯ç°å¸¸
|
---|
539 | */
|
---|
540 |
|
---|
541 | static int_t
|
---|
542 | lcp_nakci (T_PPP_FSM *fsm, T_NET_BUF *input)
|
---|
543 | {
|
---|
544 | T_LCP_CONFIGS new_cfg;
|
---|
545 | bool_t loop = false; /* ã«ã¼ãããã¯ããã§ã㯠*/
|
---|
546 | uint32_t cilong;
|
---|
547 | uint16_t cishort, len;
|
---|
548 | uint8_t *buf, cilen;
|
---|
549 |
|
---|
550 | buf = input->buf + sizeof(T_PPP_HDR) + sizeof(T_PPP_CP_HDR);
|
---|
551 | len = input->len - (sizeof(T_PPP_HDR) + sizeof(T_PPP_CP_HDR));
|
---|
552 |
|
---|
553 | new_cfg = lcp_local_neg_cfg;
|
---|
554 |
|
---|
555 | /* MRU ãªãã·ã§ã³ã解æããã */
|
---|
556 | if (len >= sizeof(T_PPP_CI_HDR) + sizeof(uint16_t) &&
|
---|
557 | * buf == LCP_CIT_MRU &&
|
---|
558 | *(buf + 1) == sizeof(T_PPP_CI_HDR) + sizeof(uint16_t) &&
|
---|
559 | (lcp_local_neg_cfg.options & LCP_CFG_MRU)) {
|
---|
560 | cishort = ntohs(*((uint16_t*)(buf + 2)));
|
---|
561 | buf += sizeof(T_PPP_CI_HDR) + sizeof(uint16_t);
|
---|
562 | len -= sizeof(T_PPP_CI_HDR) + sizeof(uint16_t);
|
---|
563 | if (cishort <= lcp_local_neg_cfg.MRU || cishort <= DEF_PPP_MTU)
|
---|
564 | new_cfg.MRU = cishort;
|
---|
565 | }
|
---|
566 |
|
---|
567 | /* ACCM ãªãã·ã§ã³ã解æããã */
|
---|
568 | if (len >= sizeof(T_PPP_CI_HDR) + sizeof(uint32_t) &&
|
---|
569 | * buf == LCP_CIT_ACCM &&
|
---|
570 | *(buf + 1) == sizeof(T_PPP_CI_HDR) + sizeof(uint32_t) &&
|
---|
571 | (lcp_local_neg_cfg.options & LCP_CFG_ACCM)) {
|
---|
572 | ntoahl(cilong, buf + 2);
|
---|
573 | buf += sizeof(T_PPP_CI_HDR) + sizeof(uint32_t);
|
---|
574 | len -= sizeof(T_PPP_CI_HDR) + sizeof(uint32_t);
|
---|
575 | new_cfg.ACCM |= cilong;
|
---|
576 | }
|
---|
577 |
|
---|
578 | #ifdef LCP_CFG_MAGIC
|
---|
579 |
|
---|
580 | /* Magic Number ãªãã·ã§ã³ã解æããã */
|
---|
581 | if (len >= sizeof(T_PPP_CI_HDR) + sizeof(uint32_t) &&
|
---|
582 | * buf == LCP_CIT_MAGIC &&
|
---|
583 | *(buf + 1) == sizeof(T_PPP_CI_HDR) + sizeof(uint32_t) &&
|
---|
584 | (lcp_local_neg_cfg.options & LCP_CFG_MAGIC)) {
|
---|
585 | ntoahl(cilong, buf + 2);
|
---|
586 | buf += sizeof(T_PPP_CI_HDR) + sizeof(uint32_t);
|
---|
587 | len -= sizeof(T_PPP_CI_HDR) + sizeof(uint32_t);
|
---|
588 | new_cfg.magic = cilong;
|
---|
589 | loop = true;
|
---|
590 | }
|
---|
591 |
|
---|
592 | #endif /* of #ifdef LCP_CFG_MAGIC */
|
---|
593 |
|
---|
594 | #ifdef LCP_CFG_PAP
|
---|
595 |
|
---|
596 | /* èªè¨¼ãããã³ã«ãªãã·ã§ã³ã解æããã */
|
---|
597 | if (len >= sizeof(T_PPP_CI_HDR) + sizeof(uint16_t) &&
|
---|
598 | * buf == LCP_CIT_AUTH &&
|
---|
599 | *(buf + 1) == sizeof(T_PPP_CI_HDR) + sizeof(uint16_t) &&
|
---|
600 | (lcp_local_neg_cfg.options & LCP_CFG_PAP)) {
|
---|
601 | cishort = ntohs(*((uint16_t*)(buf + 2)));
|
---|
602 | buf += sizeof(T_PPP_CI_HDR) + sizeof(uint16_t);
|
---|
603 | len -= sizeof(T_PPP_CI_HDR) + sizeof(uint16_t);
|
---|
604 | if (cishort == PPP_PAP)
|
---|
605 | new_cfg.options &= ~LCP_CFG_PAP;
|
---|
606 | else
|
---|
607 | return 0;
|
---|
608 | }
|
---|
609 |
|
---|
610 | #endif /* of #ifdef LCP_CFG_PAP */
|
---|
611 |
|
---|
612 | #ifdef LCP_CFG_PCOMP
|
---|
613 |
|
---|
614 | /* ãããã³ã«å§ç¸®ãªãã·ã§ã³ã解æããã */
|
---|
615 | if (len >= sizeof(T_PPP_CI_HDR) &&
|
---|
616 | * buf == LCP_CIT_PCOMP &&
|
---|
617 | *(buf + 1) == sizeof(T_PPP_CI_HDR) &&
|
---|
618 | (lcp_local_neg_cfg.options & LCP_CFG_PCOMP)) {
|
---|
619 | buf += sizeof(T_PPP_CI_HDR);
|
---|
620 | len -= sizeof(T_PPP_CI_HDR);
|
---|
621 | new_cfg.options &= ~LCP_CFG_PCOMP;
|
---|
622 | }
|
---|
623 |
|
---|
624 | #endif /* of #ifdef LCP_CFG_PCOMP */
|
---|
625 |
|
---|
626 | #ifdef LCP_CFG_ACCOMP
|
---|
627 |
|
---|
628 | /* ã¢ãã¬ã¹ã»å¶å¾¡å§ç¸®ãªãã·ã§ã³ã解æããã */
|
---|
629 | if (len >= sizeof(T_PPP_CI_HDR) &&
|
---|
630 | * buf == LCP_CIT_ACCOMP &&
|
---|
631 | *(buf + 1) == sizeof(T_PPP_CI_HDR) &&
|
---|
632 | (lcp_local_neg_cfg.options & LCP_CFG_ACCOMP)) {
|
---|
633 | buf += sizeof(T_PPP_CI_HDR);
|
---|
634 | len -= sizeof(T_PPP_CI_HDR);
|
---|
635 | new_cfg.options &= ~LCP_CFG_ACCOMP;
|
---|
636 | }
|
---|
637 |
|
---|
638 | #endif /* of #ifdef LCP_CFG_ACCOMP */
|
---|
639 |
|
---|
640 | /* å¾ã¯ç¡è¦ããã*/
|
---|
641 | while (len > sizeof(T_PPP_CI_HDR)) {
|
---|
642 | cilen = *(buf + 1);
|
---|
643 | if (len < cilen)
|
---|
644 | return 0;
|
---|
645 | buf += cilen;
|
---|
646 | len -= cilen;
|
---|
647 | }
|
---|
648 |
|
---|
649 | /* é·ãã 0 ã§ãªããã°ã¨ã©ã¼ */
|
---|
650 | if (len != 0)
|
---|
651 | return 0;
|
---|
652 |
|
---|
653 | /* æ°ãããªãã·ã§ã³ãè¨å®ããã*/
|
---|
654 | if (fsm->state != PPP_FSM_OPENED) {
|
---|
655 | if (loop) {
|
---|
656 | syslog(LOG_WARNING, "[PPP/LCP] line looped.");
|
---|
657 | lcp_close();
|
---|
658 | }
|
---|
659 | lcp_local_neg_cfg = new_cfg;
|
---|
660 | }
|
---|
661 | return 1;
|
---|
662 | }
|
---|
663 |
|
---|
664 | /*
|
---|
665 | * lcp_rejci -- REJ ãåä¿¡ããã¨ãã®å¦ç
|
---|
666 | *
|
---|
667 | * æ»ãå¤: 1 REJ ã¯æ£å¸¸
|
---|
668 | * 0 REJ ã¯ç°å¸¸
|
---|
669 | */
|
---|
670 |
|
---|
671 | static int_t
|
---|
672 | lcp_rejci (T_PPP_FSM *fsm, T_NET_BUF *input)
|
---|
673 | {
|
---|
674 | T_LCP_CONFIGS new_cfg;
|
---|
675 | uint32_t cilong;
|
---|
676 | uint16_t cishort, len;
|
---|
677 | uint8_t *buf;
|
---|
678 |
|
---|
679 | buf = input->buf + sizeof(T_PPP_HDR) + sizeof(T_PPP_CP_HDR);
|
---|
680 | len = input->len - (sizeof(T_PPP_HDR) + sizeof(T_PPP_CP_HDR));
|
---|
681 |
|
---|
682 | new_cfg = lcp_local_neg_cfg;
|
---|
683 |
|
---|
684 | /* MRU ãªãã·ã§ã³ã解æããã */
|
---|
685 | if (len >= sizeof(T_PPP_CI_HDR) + sizeof(uint16_t) &&
|
---|
686 | * buf == LCP_CIT_MRU &&
|
---|
687 | *(buf + 1) == sizeof(T_PPP_CI_HDR) + sizeof(uint16_t) &&
|
---|
688 | (lcp_local_neg_cfg.options & LCP_CFG_MRU)) {
|
---|
689 | cishort = ntohs(*((uint16_t*)(buf + 2)));
|
---|
690 | buf += sizeof(T_PPP_CI_HDR) + sizeof(uint16_t);
|
---|
691 | len -= sizeof(T_PPP_CI_HDR) + sizeof(uint16_t);
|
---|
692 | if (cishort != lcp_local_neg_cfg.MRU)
|
---|
693 | return 0;
|
---|
694 | else
|
---|
695 | new_cfg.options &= ~LCP_CFG_MRU;
|
---|
696 | }
|
---|
697 |
|
---|
698 | /* ACCM ãªãã·ã§ã³ã解æããã */
|
---|
699 | if (len >= sizeof(T_PPP_CI_HDR) + sizeof(uint32_t) &&
|
---|
700 | * buf == LCP_CIT_ACCM &&
|
---|
701 | *(buf + 1) == sizeof(T_PPP_CI_HDR) + sizeof(uint32_t) &&
|
---|
702 | (lcp_local_neg_cfg.options & LCP_CFG_ACCM)) {
|
---|
703 | ntoahl(cilong, buf + 2);
|
---|
704 | buf += sizeof(T_PPP_CI_HDR) + sizeof(uint32_t);
|
---|
705 | len -= sizeof(T_PPP_CI_HDR) + sizeof(uint32_t);
|
---|
706 | if (cilong != lcp_local_neg_cfg.ACCM)
|
---|
707 | return 0;
|
---|
708 | else
|
---|
709 | new_cfg.options &= ~LCP_CFG_ACCM;
|
---|
710 | }
|
---|
711 |
|
---|
712 | #ifdef LCP_CFG_MAGIC
|
---|
713 |
|
---|
714 | /* Magic Number ãªãã·ã§ã³ã解æããã */
|
---|
715 | if (len >= sizeof(T_PPP_CI_HDR) + sizeof(uint32_t) &&
|
---|
716 | * buf == LCP_CIT_MAGIC &&
|
---|
717 | *(buf + 1) == sizeof(T_PPP_CI_HDR) + sizeof(uint32_t) &&
|
---|
718 | (lcp_local_neg_cfg.options & LCP_CFG_MAGIC)) {
|
---|
719 | ntoahl(cilong, buf + 2);
|
---|
720 | buf += sizeof(T_PPP_CI_HDR) + sizeof(uint32_t);
|
---|
721 | len -= sizeof(T_PPP_CI_HDR) + sizeof(uint32_t);
|
---|
722 | if (cilong != lcp_local_neg_cfg.magic)
|
---|
723 | return 0;
|
---|
724 | else
|
---|
725 | new_cfg.options &= ~LCP_CFG_MAGIC;
|
---|
726 | }
|
---|
727 |
|
---|
728 | #endif /* of #ifdef LCP_CFG_MAGIC */
|
---|
729 |
|
---|
730 | #ifdef LCP_CFG_PAP
|
---|
731 |
|
---|
732 | /* èªè¨¼ãããã³ã«ãªãã·ã§ã³ã解æããã */
|
---|
733 | if (len >= sizeof(T_PPP_CI_HDR) + sizeof(uint16_t) &&
|
---|
734 | * buf == LCP_CIT_AUTH &&
|
---|
735 | *(buf + 1) == sizeof(T_PPP_CI_HDR) + sizeof(uint16_t) &&
|
---|
736 | (lcp_local_neg_cfg.options & LCP_CFG_PAP)) {
|
---|
737 | cishort = ntohs(*((uint16_t*)(buf + 2)));
|
---|
738 | buf += sizeof(T_PPP_CI_HDR) + sizeof(uint16_t);
|
---|
739 | len -= sizeof(T_PPP_CI_HDR) + sizeof(uint16_t);
|
---|
740 | if (cishort != PPP_PAP)
|
---|
741 | return 0;
|
---|
742 | else
|
---|
743 | new_cfg.options &= ~LCP_CFG_PAP;
|
---|
744 | }
|
---|
745 |
|
---|
746 | #endif /* of #ifdef LCP_CFG_PAP */
|
---|
747 |
|
---|
748 | #ifdef LCP_CFG_PCOMP
|
---|
749 |
|
---|
750 | /* ãããã³ã«å§ç¸®ãªãã·ã§ã³ã解æããã */
|
---|
751 | if (len >= sizeof(T_PPP_CI_HDR) &&
|
---|
752 | * buf == LCP_CIT_PCOMP &&
|
---|
753 | *(buf + 1) == sizeof(T_PPP_CI_HDR) &&
|
---|
754 | (lcp_local_neg_cfg.options & LCP_CFG_PCOMP)) {
|
---|
755 | buf += sizeof(T_PPP_CI_HDR);
|
---|
756 | len -= sizeof(T_PPP_CI_HDR);
|
---|
757 | new_cfg.options &= ~LCP_CFG_PCOMP;
|
---|
758 | }
|
---|
759 |
|
---|
760 | #endif /* of #ifdef LCP_CFG_PCOMP */
|
---|
761 |
|
---|
762 | #ifdef LCP_CFG_ACCOMP
|
---|
763 |
|
---|
764 | /* ã¢ãã¬ã¹ã»å¶å¾¡å§ç¸®ãªãã·ã§ã³ã解æããã */
|
---|
765 | if (len >= sizeof(T_PPP_CI_HDR) &&
|
---|
766 | * buf == LCP_CIT_ACCOMP &&
|
---|
767 | *(buf + 1) == sizeof(T_PPP_CI_HDR) &&
|
---|
768 | (lcp_local_neg_cfg.options & LCP_CFG_ACCOMP)) {
|
---|
769 | buf += sizeof(T_PPP_CI_HDR);
|
---|
770 | len -= sizeof(T_PPP_CI_HDR);
|
---|
771 | new_cfg.options &= ~LCP_CFG_ACCOMP;
|
---|
772 | }
|
---|
773 |
|
---|
774 | #endif /* of #ifdef LCP_CFG_ACCOMP */
|
---|
775 |
|
---|
776 | /* é·ãã 0 ã§ãªããã°ã¨ã©ã¼ */
|
---|
777 | if (len != 0)
|
---|
778 | return 0;
|
---|
779 |
|
---|
780 | /* æ°ãããªãã·ã§ã³ãè¨å®ããã*/
|
---|
781 | if (fsm->state != PPP_FSM_OPENED)
|
---|
782 | lcp_local_neg_cfg = new_cfg;
|
---|
783 |
|
---|
784 | return 1;
|
---|
785 | }
|
---|
786 |
|
---|
787 | /*
|
---|
788 | * lcp_reqci -- ç¸æã®æ§ææ
|
---|
789 | å ±ã解æããã
|
---|
790 | */
|
---|
791 |
|
---|
792 | static int_t
|
---|
793 | lcp_reqci (T_PPP_FSM *fsm, T_NET_BUF *input, T_NET_BUF *output)
|
---|
794 | {
|
---|
795 | #if DEF_LCP_REMOTE_CFGS & LCP_CFG_MAGIC
|
---|
796 |
|
---|
797 | uint32_t cilong;
|
---|
798 |
|
---|
799 | #endif /* of #if DEF_LCP_REMOTE_CFGS & LCP_CFG_MAGIC */
|
---|
800 |
|
---|
801 | uint16_t code, final, len, cilen, cishort;
|
---|
802 | uint8_t *np, *rp, *ap, *cp, type = 0;
|
---|
803 |
|
---|
804 | rp = ap = input->buf + sizeof(T_PPP_HDR) + sizeof(T_PPP_CP_HDR);
|
---|
805 | /* rp: REJãap: ACK ãã CI ã®ãã¤ã³ã¿ */
|
---|
806 | /* æå¦ããå ´åã¯ãå¼æ° input ã«ä¸æ¸ãããã */
|
---|
807 | len = input->len - (sizeof(T_PPP_HDR) + sizeof(T_PPP_CP_HDR));
|
---|
808 | np = output->buf + sizeof(T_PPP_HDR) + sizeof(T_PPP_CP_HDR);
|
---|
809 | final = PPP_CONFACK; /* æçµçã«éä¿¡ããã³ã¼ã */
|
---|
810 | while (len > 0) {
|
---|
811 | code = PPP_CONFACK;
|
---|
812 | cp = ap; /* cp: ç¾å¨å¦çä¸ã® CI */
|
---|
813 |
|
---|
814 | if (len < sizeof(T_PPP_CI_HDR)) {
|
---|
815 |
|
---|
816 | /* æ®ãã CI ãããããçã */
|
---|
817 | syslog(LOG_WARNING, "[PPP/LCP] bad CI len: %d.", len);
|
---|
818 | cilen = len; /* ãã¼ã¿é·ãç°å¸¸ã®å ´åã®å¦ç½® */
|
---|
819 | len = 0; /* ã«ã¼ãããæããã */
|
---|
820 | code = PPP_CONFREJ;
|
---|
821 | goto endswitch;
|
---|
822 | }
|
---|
823 |
|
---|
824 | type = *ap ++; /* CI ã®å */
|
---|
825 | cilen = *ap ++; /* CI ã®é·ã */
|
---|
826 | if (len < cilen) {
|
---|
827 |
|
---|
828 | /* æ®ãã CI é·ããçã */
|
---|
829 | syslog(LOG_WARNING, "[PPP/LCP] bad CI len: %d.", cilen);
|
---|
830 | cilen = len; /* ãã¼ã¿é·ãç°å¸¸ã®å ´åã®å¦ç½® */
|
---|
831 | len = 0; /* ã«ã¼ãããæããã */
|
---|
832 | code = PPP_CONFREJ;
|
---|
833 | goto endswitch;
|
---|
834 | }
|
---|
835 | len -= sizeof(T_PPP_CI_HDR);
|
---|
836 |
|
---|
837 | /* CI ã®åã«ããåå²ããã*/
|
---|
838 | switch (type) {
|
---|
839 |
|
---|
840 | case LCP_CIT_MRU: /* æ大åä¿¡é (Maximum Receive Unit) */
|
---|
841 |
|
---|
842 | #if (DEF_LCP_REMOTE_CFGS & LCP_CFG_MRU) == 0
|
---|
843 |
|
---|
844 | code = PPP_CONFREJ;
|
---|
845 |
|
---|
846 | #else /* of #if (DEF_LCP_REMOTE_CFGS & LCP_CFG_MRU) == 0 */
|
---|
847 |
|
---|
848 | /* CI é·ããããã + 2 ãªã¯ãããã§ãªããã° REJ */
|
---|
849 | if (cilen != sizeof(T_PPP_CI_HDR) + sizeof(uint16_t))
|
---|
850 | code = PPP_CONFREJ;
|
---|
851 | {
|
---|
852 | cishort = ntohs(*(uint16_t*)ap);
|
---|
853 |
|
---|
854 | /* æå°åä¿¡éããå°ãããã° NAK */
|
---|
855 | if (cishort < MIN_PPP_MTU) {
|
---|
856 | *np ++ = LCP_CIT_MRU;
|
---|
857 | *np ++ = sizeof(T_PPP_CI_HDR) + sizeof(uint16_t);
|
---|
858 | *((uint16_t*)np) = htons(MIN_PPP_MTU);
|
---|
859 | np += sizeof(uint16_t);
|
---|
860 | code = PPP_CONFNAK;
|
---|
861 | }
|
---|
862 | else {
|
---|
863 | lcp_remote_neg_cfg.MRU = cishort;
|
---|
864 | lcp_remote_neg_cfg.options |= LCP_CFG_MRU;
|
---|
865 | }
|
---|
866 | }
|
---|
867 |
|
---|
868 | #endif /* of #if (DEF_LCP_REMOTE_CFGS & LCP_CFG_MRU) == 0 */
|
---|
869 |
|
---|
870 | break;
|
---|
871 |
|
---|
872 | case LCP_CIT_ACCM: /* Async Control Character Map */
|
---|
873 |
|
---|
874 | #if (DEF_LCP_REMOTE_CFGS & LCP_CFG_ACCM) == 0
|
---|
875 |
|
---|
876 | code = PPP_CONFREJ;
|
---|
877 |
|
---|
878 | #else /* of #if (DEF_LCP_REMOTE_CFGS & LCP_CFG_ACCM) == 0 */
|
---|
879 |
|
---|
880 | /* CI é·ããããã + 4 ãªã¯ãããã§ãªããã° REJ */
|
---|
881 | if (cilen != sizeof(T_PPP_CI_HDR) + sizeof(uint32_t))
|
---|
882 | code = PPP_CONFREJ;
|
---|
883 | else {
|
---|
884 | ntoahl(lcp_remote_neg_cfg.ACCM, ap);
|
---|
885 | lcp_remote_neg_cfg.options |= LCP_CFG_ACCM;
|
---|
886 | }
|
---|
887 |
|
---|
888 | #endif /* of #if (DEF_LCP_REMOTE_CFGS & LCP_CFG_ACCM) == 0 */
|
---|
889 |
|
---|
890 | break;
|
---|
891 |
|
---|
892 | case LCP_CIT_MAGIC: /* ãã¸ãã¯çªå· */
|
---|
893 |
|
---|
894 | #if (DEF_LCP_REMOTE_CFGS & LCP_CFG_MAGIC) == 0
|
---|
895 |
|
---|
896 | code = PPP_CONFREJ;
|
---|
897 |
|
---|
898 | #else /* of #if (DEF_LCP_REMOTE_CFGS & LCP_CFG_MAGIC) == 0 */
|
---|
899 |
|
---|
900 | /* CI é·ããããã + 4 ãªã¯ãããã§ãªããã° REJ */
|
---|
901 | if (cilen != sizeof(T_PPP_CI_HDR) + sizeof(uint32_t))
|
---|
902 | code = PPP_CONFREJ;
|
---|
903 | else {
|
---|
904 | ntoahl(cilong, ap);
|
---|
905 |
|
---|
906 | /* çªå·ãèªåã¨åããªã NAK */
|
---|
907 | if (cilong == lcp_local_neg_cfg.magic) {
|
---|
908 | cilong = net_rand();
|
---|
909 | *np ++ = LCP_CIT_MAGIC;
|
---|
910 | *np ++ = sizeof(T_PPP_CI_HDR) + sizeof(uint32_t);
|
---|
911 | ahtonl(np, cilong);
|
---|
912 | np += sizeof(uint32_t);
|
---|
913 | code = PPP_CONFNAK;
|
---|
914 | }
|
---|
915 | else {
|
---|
916 | lcp_remote_neg_cfg.magic = cilong;
|
---|
917 | lcp_remote_neg_cfg.options |= LCP_CFG_MAGIC;
|
---|
918 | }
|
---|
919 | }
|
---|
920 |
|
---|
921 | #endif /* of #if (DEF_LCP_REMOTE_CFGS & LCP_CFG_MAGIC) == 0 */
|
---|
922 |
|
---|
923 | break;
|
---|
924 |
|
---|
925 | #ifdef LCP_CFG_PAP
|
---|
926 | /* CHAP ã¯å®è£
|
---|
927 | äºå® */
|
---|
928 |
|
---|
929 | case LCP_CIT_AUTH: /* èªè¨¼ãããã³ã« */
|
---|
930 |
|
---|
931 | /* CI é·ããããã + 2 ãªã¯ãããããçãã¨ãã¯ã¨ã©ã¼ */
|
---|
932 | if (cilen < sizeof(T_PPP_CI_HDR) + sizeof(uint16_t))
|
---|
933 | code = PPP_CONFREJ;
|
---|
934 | else {
|
---|
935 | cishort = ntohs(*(uint16_t*)ap);
|
---|
936 |
|
---|
937 | /* èªè¨¼ãããã³ã«ã«ããåå²ãã */
|
---|
938 | if (cishort == PPP_PAP &&
|
---|
939 | cilen == sizeof(T_PPP_CI_HDR) + sizeof(uint16_t) &&
|
---|
940 | (DEF_LCP_REMOTE_CFGS & LCP_CFG_PAP) != 0)
|
---|
941 | lcp_remote_neg_cfg.options |= LCP_CFG_PAP;
|
---|
942 | else
|
---|
943 | code = PPP_CONFREJ;
|
---|
944 | }
|
---|
945 | break;
|
---|
946 |
|
---|
947 | #endif /* of #ifdef LCP_CFG_PAP */
|
---|
948 |
|
---|
949 | #ifdef LCP_CFG_PCOMP
|
---|
950 |
|
---|
951 | case LCP_CIT_PCOMP: /* ãããã³ã«é¨å§ç¸®ã¯å®è£
|
---|
952 | äºå® */
|
---|
953 |
|
---|
954 | #if (DEF_LCP_REMOTE_CFGS & LCP_CFG_PCOMP) == 0
|
---|
955 |
|
---|
956 | code = PPP_CONFREJ;
|
---|
957 |
|
---|
958 | #else /* of #if (DEF_LCP_REMOTE_CFGS & LCP_CFG_PCOMP) == 0 */
|
---|
959 |
|
---|
960 | /* CI é·ãããããé·ã ãã§ãªããã° REJ */
|
---|
961 | if (cilen != sizeof(T_PPP_CI_HDR))
|
---|
962 | code = PPP_CONFREJ;
|
---|
963 | else
|
---|
964 | lcp_remote_neg_cfg.options |= LCP_CFG_PCOMP;
|
---|
965 |
|
---|
966 | #endif /* of #if (DEF_LCP_REMOTE_CFGS & LCP_CFG_PCOMP) == 0 */
|
---|
967 |
|
---|
968 | break;
|
---|
969 |
|
---|
970 | #endif /* of #ifdef LCP_CFG_PCOMP */
|
---|
971 |
|
---|
972 | #ifdef LCP_CFG_ACCOMP
|
---|
973 |
|
---|
974 | case LCP_CIT_ACCOMP: /* ã¢ãã¬ã¹ã»å¶å¾¡é¨å§ç¸® */
|
---|
975 |
|
---|
976 | #if (DEF_LCP_REMOTE_CFGS & LCP_CFG_ACCOMP) == 0
|
---|
977 |
|
---|
978 | code = PPP_CONFREJ;
|
---|
979 |
|
---|
980 | #else /* of #if (DEF_LCP_REMOTE_CFGS & LCP_CFG_ACCOMP) == 0 */
|
---|
981 |
|
---|
982 | /* CI é·ãããããé·ã ãã§ãªããã° REJ */
|
---|
983 | if (cilen != sizeof(T_PPP_CI_HDR))
|
---|
984 | code = PPP_CONFREJ;
|
---|
985 | else
|
---|
986 | lcp_remote_neg_cfg.options |= LCP_CFG_ACCOMP;
|
---|
987 |
|
---|
988 | #endif /* of #if (DEF_LCP_REMOTE_CFGS & LCP_CFG_ACCOMP) == 0 */
|
---|
989 |
|
---|
990 | break;
|
---|
991 |
|
---|
992 | #endif /* of #ifdef LCP_CFG_ACCOMP */
|
---|
993 |
|
---|
994 | default:
|
---|
995 | syslog(LOG_WARNING, "[PPP/LCP] unexp opt: %d.", type);
|
---|
996 | code = PPP_CONFREJ;
|
---|
997 | break;
|
---|
998 | }
|
---|
999 | endswitch:
|
---|
1000 | if (code == PPP_CONFNAK) {
|
---|
1001 | /* CI ã®åã Magic Number ã®å ´åãé¤ãã¦ãNAK ã®åæ°ã */
|
---|
1002 | /* æå¤§å¤ MAX_PPP_FAILURES ãè¶
|
---|
1003 | ãããæå¦ããã */
|
---|
1004 | if (fsm->failures >= MAX_PPP_FAILURES && type != LCP_CIT_MAGIC)
|
---|
1005 | code = PPP_CONFREJ;
|
---|
1006 | else if (final != PPP_CONFREJ)
|
---|
1007 | final = PPP_CONFNAK;
|
---|
1008 | }
|
---|
1009 |
|
---|
1010 | /* ãã® CI ãæå¦ãã */
|
---|
1011 | if (code == PPP_CONFREJ) {
|
---|
1012 | if (rp < cp) /* åã«è©°ããã*/
|
---|
1013 | memcpy(rp, cp, cilen);
|
---|
1014 | rp += cilen;
|
---|
1015 | final = PPP_CONFREJ;
|
---|
1016 | }
|
---|
1017 |
|
---|
1018 | ap += cilen - sizeof(T_PPP_CI_HDR);
|
---|
1019 | len -= cilen - sizeof(T_PPP_CI_HDR);
|
---|
1020 | }
|
---|
1021 |
|
---|
1022 | /* æçµçãªé·ãã調æ´ããã*/
|
---|
1023 | switch (final) {
|
---|
1024 | case PPP_CONFNAK:
|
---|
1025 | output->len = np - output->buf;
|
---|
1026 | memcpy(output->buf, input->buf, sizeof(T_PPP_HDR) + sizeof(T_PPP_CP_HDR));
|
---|
1027 | break;
|
---|
1028 | case PPP_CONFREJ:
|
---|
1029 | memcpy(output->buf, input->buf, output->len = rp - input->buf);
|
---|
1030 | break;
|
---|
1031 | case PPP_CONFACK:
|
---|
1032 | memcpy(output->buf, input->buf, input->len);
|
---|
1033 | break;
|
---|
1034 | }
|
---|
1035 | return final;
|
---|
1036 | }
|
---|
1037 |
|
---|
1038 | /*
|
---|
1039 | * lcp_up -- ãªã³ã¯æ¥ç¶ã確ç«ãã (Phase: Establish ã«ç§»è¡ãã)ã
|
---|
1040 | */
|
---|
1041 |
|
---|
1042 | static void
|
---|
1043 | lcp_up (T_PPP_FSM *fsm)
|
---|
1044 | {
|
---|
1045 | /* èªæ§ææ
|
---|
1046 | å ±ã®è¨å® */
|
---|
1047 | lcp_local_ack_cfg = lcp_local_neg_cfg;
|
---|
1048 |
|
---|
1049 | /* ç¸æã®æ§ææ
|
---|
1050 | å ±ã®è¨å® */
|
---|
1051 | lcp_remote_ack_cfg = lcp_remote_neg_cfg;
|
---|
1052 |
|
---|
1053 | #if DEF_LCP_LOCAL_CFGS & LCP_CFG_MAGIC
|
---|
1054 |
|
---|
1055 | echo_lowerup();
|
---|
1056 |
|
---|
1057 | #endif /* of #if DEF_LCP_LOCAL_CFGS & LCP_CFG_MAGIC */
|
---|
1058 |
|
---|
1059 | link_established();
|
---|
1060 | }
|
---|
1061 |
|
---|
1062 | /*
|
---|
1063 | * lcp_starting -- ä¸ä½å±¤ãéå§ããã
|
---|
1064 | */
|
---|
1065 |
|
---|
1066 | static void
|
---|
1067 | lcp_starting (T_PPP_FSM *fsm)
|
---|
1068 | {
|
---|
1069 | link_required();
|
---|
1070 | }
|
---|
1071 |
|
---|
1072 | /*
|
---|
1073 | * lcp_extcode -- LCP ç¹æã® CP ãåä¿¡ããã¨ãã®å¦ç
|
---|
1074 | */
|
---|
1075 |
|
---|
1076 | static bool_t
|
---|
1077 | lcp_extcode (T_PPP_FSM *fsm, uint8_t code, uint8_t id, T_NET_BUF *input)
|
---|
1078 | {
|
---|
1079 | #if DEF_LCP_REMOTE_CFGS & LCP_CFG_MAGIC
|
---|
1080 |
|
---|
1081 | T_NET_BUF *output;
|
---|
1082 |
|
---|
1083 | #endif /* of #if DEF_LCP_REMOTE_CFGS & LCP_CFG_MAGIC */
|
---|
1084 |
|
---|
1085 | switch (code) {
|
---|
1086 | case PPP_PROTREJ:
|
---|
1087 | lcp_rprotrej(fsm, input);
|
---|
1088 | break;
|
---|
1089 |
|
---|
1090 | case PPP_ECHOREQ:
|
---|
1091 |
|
---|
1092 | #if DEF_LCP_REMOTE_CFGS & LCP_CFG_MAGIC
|
---|
1093 |
|
---|
1094 | if (fsm->state == PPP_FSM_OPENED) {
|
---|
1095 | syscall(get_net_buf(&output, sizeof(T_PPP_HDR)
|
---|
1096 | + sizeof(T_PPP_CP_HDR)
|
---|
1097 | + sizeof(uint32_t)));
|
---|
1098 | *(uint32_t*)(output->buf + sizeof(T_PPP_HDR)
|
---|
1099 | + sizeof(T_PPP_CP_HDR)) = lcp_local_ack_cfg.magic;
|
---|
1100 | IF_SET_PROTO(output, PPP_LCP);
|
---|
1101 | ppp_cp_output(PPP_ECHOREP, id, output);
|
---|
1102 | }
|
---|
1103 |
|
---|
1104 | #endif /* of #if DEF_LCP_REMOTE_CFGS & LCP_CFG_MAGIC */
|
---|
1105 |
|
---|
1106 | break;
|
---|
1107 |
|
---|
1108 | case PPP_ECHOREP:
|
---|
1109 |
|
---|
1110 | #if DEF_LCP_LOCAL_CFGS & LCP_CFG_MAGIC
|
---|
1111 |
|
---|
1112 | recv_echo_rep(fsm, id, input);
|
---|
1113 |
|
---|
1114 | #endif /* of #if DEF_LCP_LOCAL_CFGS & LCP_CFG_MAGIC */
|
---|
1115 |
|
---|
1116 | break;
|
---|
1117 |
|
---|
1118 | case PPP_DISCREQ:
|
---|
1119 | break;
|
---|
1120 |
|
---|
1121 | default:
|
---|
1122 | return false;
|
---|
1123 | break;
|
---|
1124 |
|
---|
1125 | }
|
---|
1126 | return true;
|
---|
1127 | }
|
---|
1128 |
|
---|
1129 | /*
|
---|
1130 | * lcp_rprotrej -- Proto-REJ ãåä¿¡ããã¨ãã®å¦ç
|
---|
1131 | */
|
---|
1132 |
|
---|
1133 | static void
|
---|
1134 | lcp_rprotrej (T_PPP_FSM *fsm, T_NET_BUF *input)
|
---|
1135 | {
|
---|
1136 | T_PPP_PROTENT *entry;
|
---|
1137 | int_t ix;
|
---|
1138 | uint16_t proto;
|
---|
1139 |
|
---|
1140 | if (input->len < sizeof(uint16_t)) {
|
---|
1141 | syslog(LOG_WARNING, "[PPP/LCP] bad len: %d in recv Proto-REJ.");
|
---|
1142 | return;
|
---|
1143 | }
|
---|
1144 |
|
---|
1145 | proto = ntohs(*GET_PPP_HDR(input));
|
---|
1146 |
|
---|
1147 | if (fsm->state != PPP_FSM_OPENED) {
|
---|
1148 | return;
|
---|
1149 | }
|
---|
1150 |
|
---|
1151 | /* ä¸ä½ãããã³ã«ãåæåãã */
|
---|
1152 | for (ix = 0; (entry = protocols[ix]) != NULL; ix ++)
|
---|
1153 | if (entry->proto == proto) {
|
---|
1154 | (*entry->protrej)();
|
---|
1155 | return;
|
---|
1156 | }
|
---|
1157 |
|
---|
1158 | syslog(LOG_WARNING, "[PPP/LCP] unexp proto: %d in recv Proto-REJ.", proto);
|
---|
1159 | }
|
---|
1160 |
|
---|
1161 | /*
|
---|
1162 | * lcp_protrej -- Proto-REJ ãåä¿¡ããã¨ãã®å¦ç
|
---|
1163 | */
|
---|
1164 |
|
---|
1165 | static void
|
---|
1166 | lcp_protrej (void)
|
---|
1167 | {
|
---|
1168 | fsm_protreject(&lcp_fsm);
|
---|
1169 | }
|
---|
1170 |
|
---|
1171 | /*
|
---|
1172 | * lcp_lowerup -- LCP ä¸ä½å±¤ãèµ·åããã
|
---|
1173 | */
|
---|
1174 |
|
---|
1175 | void
|
---|
1176 | lcp_lowerup (void)
|
---|
1177 | {
|
---|
1178 | fsm_lowerup(&lcp_fsm);
|
---|
1179 | }
|
---|
1180 |
|
---|
1181 | /*
|
---|
1182 | * lcp_lowerdown -- LCP ä¸ä½å±¤ãåæ¢ããã
|
---|
1183 | */
|
---|
1184 |
|
---|
1185 | void
|
---|
1186 | lcp_lowerdown (void)
|
---|
1187 | {
|
---|
1188 | fsm_lowerdown(&lcp_fsm);
|
---|
1189 | }
|
---|
1190 |
|
---|
1191 | /*
|
---|
1192 | * lcp_open -- LCP ã®ãªã¼ã
|
---|
1193 | */
|
---|
1194 |
|
---|
1195 | void
|
---|
1196 | lcp_open (uint8_t open_mode)
|
---|
1197 | {
|
---|
1198 | ppp_open_mode = open_mode; /* ãªã¼ãã³æã®åä½ã¢ã¼ã */
|
---|
1199 | fsm_open(&lcp_fsm);
|
---|
1200 | }
|
---|
1201 |
|
---|
1202 | /*
|
---|
1203 | * lcp_close -- LCP ã®ã¯ãã¼ãº
|
---|
1204 | */
|
---|
1205 |
|
---|
1206 | void
|
---|
1207 | lcp_close (void)
|
---|
1208 | {
|
---|
1209 | if (ppp_phase != PPP_PHASE_DEAD)
|
---|
1210 | ppp_phase = PPP_PHASE_TERMINATE;
|
---|
1211 |
|
---|
1212 | if (ppp_open_mode == PPP_OPEN_PASSIVE && lcp_fsm.state == PPP_FSM_STOPPED) {
|
---|
1213 | lcp_fsm.state = PPP_FSM_CLOSED;
|
---|
1214 | lcp_finished(&lcp_fsm);
|
---|
1215 | }
|
---|
1216 | else
|
---|
1217 | fsm_close(&lcp_fsm);
|
---|
1218 | }
|
---|
1219 |
|
---|
1220 | /*
|
---|
1221 | * lcp_sprotrej -- èªèã§ããªããããã³ã«ãéããã¦ããã¨ãã®å¦ç
|
---|
1222 | */
|
---|
1223 |
|
---|
1224 | void
|
---|
1225 | lcp_sprotrej (T_NET_BUF *input)
|
---|
1226 | {
|
---|
1227 | T_NET_BUF *output;
|
---|
1228 | /*
|
---|
1229 | * Protocol-Reject ãéãè¿ãã
|
---|
1230 | */
|
---|
1231 |
|
---|
1232 | syscall(get_net_buf(&output, input->len + sizeof(T_PPP_HDR) + sizeof(T_PPP_CP_HDR)));
|
---|
1233 |
|
---|
1234 | memcpy(output->buf, input->buf, sizeof(T_PPP_HDR) + sizeof(T_PPP_CP_HDR));
|
---|
1235 | memcpy(output->buf + sizeof(T_PPP_HDR) + sizeof(T_PPP_CP_HDR), input->buf, input->len);
|
---|
1236 |
|
---|
1237 | IF_SET_PROTO(output, PPP_LCP);
|
---|
1238 | ppp_cp_output(PPP_PROTREJ, ++ lcp_fsm.id, output);
|
---|
1239 | }
|
---|
1240 |
|
---|
1241 | /*
|
---|
1242 | * lcp_down -- ãªã³ã¯æ¥ç¶ã解æ¾ãã (Phase: Dead ã«ç§»è¡ãã)ã
|
---|
1243 | */
|
---|
1244 |
|
---|
1245 | void
|
---|
1246 | lcp_down (T_PPP_FSM *fsm)
|
---|
1247 | {
|
---|
1248 |
|
---|
1249 | #if DEF_LCP_LOCAL_CFGS & LCP_CFG_MAGIC
|
---|
1250 |
|
---|
1251 | echo_lowerdown();
|
---|
1252 |
|
---|
1253 | #endif /* of #if DEF_LCP_LOCAL_CFGS & LCP_CFG_MAGIC */
|
---|
1254 |
|
---|
1255 | link_down();
|
---|
1256 | }
|
---|
1257 |
|
---|
1258 | /*
|
---|
1259 | * lcp_finished -- ä¸ä½å±¤ãçµäºããã
|
---|
1260 | */
|
---|
1261 |
|
---|
1262 | void
|
---|
1263 | lcp_finished (T_PPP_FSM *fsm)
|
---|
1264 | {
|
---|
1265 | link_terminated();
|
---|
1266 | }
|
---|
1267 |
|
---|
1268 | #if DEF_LCP_LOCAL_CFGS & LCP_CFG_MAGIC
|
---|
1269 |
|
---|
1270 | /*
|
---|
1271 | * recv_echo_rep -- ECHOREP ãåä¿¡ããã¨ãã®å¦ç
|
---|
1272 | */
|
---|
1273 |
|
---|
1274 | static void
|
---|
1275 | recv_echo_rep(T_PPP_FSM *fsm, uint8_t id, T_NET_BUF *input)
|
---|
1276 | {
|
---|
1277 | T_PPP_CP_HDR *hdr;
|
---|
1278 | uint32_t magic;
|
---|
1279 |
|
---|
1280 | hdr = GET_PPP_CP_HDR(input);
|
---|
1281 |
|
---|
1282 | /* Magic Number ã®é·ã以ä¸ãªãã¨ã©ã¼ */
|
---|
1283 | if (hdr->len < sizeof(T_PPP_CP_HDR) + sizeof(uint32_t)) {
|
---|
1284 | syslog(LOG_WARNING, "[PPP/LCP] bad ECHOREP len: %d.", hdr->len);
|
---|
1285 | return;
|
---|
1286 | }
|
---|
1287 |
|
---|
1288 | ntoahl(magic, input->buf + sizeof(T_PPP_HDR) + sizeof(T_PPP_CP_HDR));
|
---|
1289 |
|
---|
1290 | /* åä¿¡ãã Magic Number ãèªåã¨åããªãã«ã¼ããã¦ããã*/
|
---|
1291 | if ((lcp_local_ack_cfg.options & LCP_CFG_MAGIC) && magic == lcp_local_ack_cfg.magic) {
|
---|
1292 | syslog(LOG_WARNING, "[PPP/LCP] ECHOREP looped.");
|
---|
1293 | return;
|
---|
1294 | }
|
---|
1295 |
|
---|
1296 | echo_pending = 0;
|
---|
1297 | }
|
---|
1298 |
|
---|
1299 | /*
|
---|
1300 | * echo_timeout -- ECHO REQ/REP ã®ã¿ã¤ã ã¢ã¦ãå¦ç
|
---|
1301 | */
|
---|
1302 |
|
---|
1303 | static void
|
---|
1304 | echo_timeout (void *arg)
|
---|
1305 | {
|
---|
1306 | if (timer_running) {
|
---|
1307 | timer_running = false;
|
---|
1308 | send_echo_req((T_PPP_FSM *)arg);
|
---|
1309 | }
|
---|
1310 | }
|
---|
1311 |
|
---|
1312 | /*
|
---|
1313 | * send_echo_req -- ECHO REQ ãéä¿¡ããã
|
---|
1314 | */
|
---|
1315 |
|
---|
1316 | static void
|
---|
1317 | send_echo_req (T_PPP_FSM *fsm)
|
---|
1318 | {
|
---|
1319 | T_NET_BUF *input;
|
---|
1320 |
|
---|
1321 | #if LCP_ECHO_FAILS > 0
|
---|
1322 |
|
---|
1323 | if (echo_pending >= LCP_ECHO_FAILS) {
|
---|
1324 | syslog(LOG_WARNING, "[PPP/LCP] no reply to ECHOREQ.");
|
---|
1325 | lcp_close();
|
---|
1326 | echo_pending = 0;
|
---|
1327 | }
|
---|
1328 |
|
---|
1329 | #endif /* of #if LCP_ECHO_FAILS > 0 */
|
---|
1330 |
|
---|
1331 | if (fsm->state == PPP_FSM_OPENED) {
|
---|
1332 |
|
---|
1333 | /* ECHOREQ ãéä¿¡ããã*/
|
---|
1334 | syscall(get_net_buf(&input, sizeof(T_PPP_HDR) + sizeof(T_PPP_CP_HDR) + sizeof(uint32_t)));
|
---|
1335 | *(uint32_t*)(input->buf + sizeof(T_PPP_HDR) + sizeof(T_PPP_CP_HDR)) = lcp_local_ack_cfg.magic;
|
---|
1336 | IF_SET_PROTO(input, PPP_LCP);
|
---|
1337 | ppp_cp_output(PPP_ECHOREQ, echo_number ++, input);
|
---|
1338 | echo_pending ++;
|
---|
1339 |
|
---|
1340 | /* ã¿ã¤ãã¼ãã¹ã¿ã¼ãããã*/
|
---|
1341 | timeout((FP)echo_timeout, fsm, LCP_ECHO_INTERVAL);
|
---|
1342 | timer_running = true;
|
---|
1343 | }
|
---|
1344 | }
|
---|
1345 |
|
---|
1346 | /*
|
---|
1347 | * echo_lowerup -- ECHO REQ/REP ã®èµ·å
|
---|
1348 | */
|
---|
1349 |
|
---|
1350 | static void
|
---|
1351 | echo_lowerup (void)
|
---|
1352 | {
|
---|
1353 | echo_pending = 0;
|
---|
1354 | echo_number = 0;
|
---|
1355 | timer_running = false;
|
---|
1356 |
|
---|
1357 | send_echo_req(&lcp_fsm);
|
---|
1358 | }
|
---|
1359 |
|
---|
1360 | /*
|
---|
1361 | * echo_lowerdown -- ECHO REQ/REP ã®åæ¢
|
---|
1362 | */
|
---|
1363 |
|
---|
1364 | static void
|
---|
1365 | echo_lowerdown (void)
|
---|
1366 | {
|
---|
1367 | if (timer_running) {
|
---|
1368 | untimeout((FP)echo_timeout, &lcp_fsm);
|
---|
1369 | timer_running = false;
|
---|
1370 | }
|
---|
1371 | }
|
---|
1372 |
|
---|
1373 | #endif /* of #if DEF_LCP_LOCAL_CFGS & LCP_CFG_MAGIC */
|
---|
1374 |
|
---|
1375 | #endif /* fo #ifdef SUPPORT_PPP */
|
---|