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$
|
---|
44 | */
|
---|
45 |
|
---|
46 | /*
|
---|
47 | * ipv6cp.c - PPP IP 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 IP Control Protocol (IPV6CP) 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/ipv6cp.c,v 1.90.2.4 2000/08/19 09:30:03 brian Exp $
|
---|
85 | *
|
---|
86 | * TODO:
|
---|
87 | * o Support IPADDRS properly
|
---|
88 | * o Validate the length in IpcpDecodeConfig
|
---|
89 | */
|
---|
90 |
|
---|
91 | #include <string.h>
|
---|
92 |
|
---|
93 | #include <s_services.h>
|
---|
94 | #include <t_services.h>
|
---|
95 | #include "kernel_id.h"
|
---|
96 |
|
---|
97 | #include <tinet_defs.h>
|
---|
98 | #include <tinet_config.h>
|
---|
99 |
|
---|
100 | #include <net/if.h>
|
---|
101 | #include <net/if_ppp.h>
|
---|
102 | #include <net/net.h>
|
---|
103 | #include <net/net_endian.h>
|
---|
104 | #include <net/net_buf.h>
|
---|
105 | #include <net/net_count.h>
|
---|
106 | #include <net/ppp.h>
|
---|
107 | #include <net/ppp_var.h>
|
---|
108 | #include <net/ppp_fsm.h>
|
---|
109 | #include <net/ppp_lcp.h>
|
---|
110 | #include <net/ppp_ipv6cp.h>
|
---|
111 | #include <net/ppp_modem.h>
|
---|
112 |
|
---|
113 | #include <netinet/in.h>
|
---|
114 | #include <netinet/in_var.h>
|
---|
115 | #include <netinet/ip.h>
|
---|
116 | #include <netinet/tcp.h>
|
---|
117 | #include <netinet/tcp_var.h>
|
---|
118 | #include <netinet/tcp_timer.h>
|
---|
119 | #include <netinet/udp_var.h>
|
---|
120 |
|
---|
121 | #include <net/if_var.h>
|
---|
122 |
|
---|
123 | #ifdef SUPPORT_PPP
|
---|
124 |
|
---|
125 | /*
|
---|
126 | * é¢æ°
|
---|
127 | */
|
---|
128 |
|
---|
129 | static void ipv6cp_init (void);
|
---|
130 | static void ipv6cp_input (T_NET_BUF *input);
|
---|
131 | static void ipv6cp_protrej (void);
|
---|
132 | static void ipv6cp_lowerup (void);
|
---|
133 | static void ipv6cp_lowerdown (void);
|
---|
134 | static void ipv6cp_open (void);
|
---|
135 | static void ipv6cp_close (void);
|
---|
136 |
|
---|
137 | /*
|
---|
138 | * FSM ããå¼åºãããã³ã¼ã«ããã¯é¢
|
---|
139 | */
|
---|
140 |
|
---|
141 | static void ipv6cp_resetci(T_PPP_FSM *fsm); /* èªæ§ææ
|
---|
142 | å ±ããªã»ããããã */
|
---|
143 | static int_t ipv6cp_cilen (T_PPP_FSM *fsm); /* æ§ææ
|
---|
144 | å ±ã®é·ããè¿ãã */
|
---|
145 | static void ipv6cp_addci (T_PPP_FSM *fsm, T_NET_BUF *output);
|
---|
146 | /* èªæ§ææ
|
---|
147 | å ±ã追å ããã */
|
---|
148 | static bool_t ipv6cp_ackci (T_PPP_FSM *fsm, T_NET_BUF *input);
|
---|
149 | /* ACK ãåä¿¡ããã¨ãã®å¦ç */
|
---|
150 | static bool_t ipv6cp_nakci (T_PPP_FSM *fsm, T_NET_BUF *input);
|
---|
151 | /* NAK ãåä¿¡ããã¨ãã®å¦ç */
|
---|
152 | static bool_t ipv6cp_rejci (T_PPP_FSM *fsm, T_NET_BUF *input);
|
---|
153 | /* REJ ãåä¿¡ããã¨ãã®å¦ç */
|
---|
154 | static int_t ipv6cp_reqci (T_PPP_FSM *fsm, T_NET_BUF *input, T_NET_BUF *output);
|
---|
155 | /* ç¸æã®æ§ææ
|
---|
156 | å ±ã確èªããã */
|
---|
157 | static void ipv6cp_up (T_PPP_FSM *fsm); /* ãªã³ã¯æ¥ç¶ã確ç«ããã */
|
---|
158 | static void ipv6cp_down (T_PPP_FSM *fsm); /* ãªã³ã¯æ¥ç¶ã解æ¾ããã */
|
---|
159 | static void ipv6cp_finished(T_PPP_FSM *fsm); /* ä¸ä½å±¤ãçµäºããã */
|
---|
160 |
|
---|
161 | /*
|
---|
162 | * å¤æ°
|
---|
163 | */
|
---|
164 |
|
---|
165 | static T_IFNET ipv6cp_local_def_cfg = { /* èªæ§ææ
|
---|
166 | å ±ã®è¦å®å¤ */
|
---|
167 | NULL, /* ãããã¯ã¼ã¯ã¤ã³ã¿ãã§ã¼ã¹ã®ã½ããã¦ã§ã¢æ
|
---|
168 | å ± */
|
---|
169 | {}, /* IPv6 ã¢ãã¬ã¹æ
|
---|
170 | å ± */
|
---|
171 | {}, /* ãã«ããã£ã¹ã IPv6 ã¢ãã¬ã¹ */
|
---|
172 | 0, /* ãã©ã° */
|
---|
173 | };
|
---|
174 |
|
---|
175 | static T_IFNET ipv6cp_remote_def_cfg = { /* ç¸æã®æ§ææ
|
---|
176 | å ±ã®è¦å®å¤ */
|
---|
177 | NULL, /* ãããã¯ã¼ã¯ã¤ã³ã¿ãã§ã¼ã¹ã®ã½ããã¦ã§ã¢æ
|
---|
178 | å ± */
|
---|
179 | {}, /* IPv6 ã¢ãã¬ã¹æ
|
---|
180 | å ± */
|
---|
181 | {}, /* ãã«ããã£ã¹ã IPv6 ã¢ãã¬ã¹ */
|
---|
182 | 0, /* ãã©ã° */
|
---|
183 | };
|
---|
184 |
|
---|
185 | static T_IFNET ipv6cp_local_neg_cfg; /* ãã´ä¸ã®èªæ§ææ
|
---|
186 | å ± */
|
---|
187 |
|
---|
188 | static T_IFNET ipv6cp_remote_neg_cfg; /* ãã´ä¸ã®ç¸æã®æ§ææ
|
---|
189 | å ± */
|
---|
190 |
|
---|
191 | /*
|
---|
192 | * å
|
---|
193 | ¨åå¤æ°
|
---|
194 | */
|
---|
195 |
|
---|
196 | T_PPP_FSM_CALLBACKS ipv6cp_callbacks = {
|
---|
197 | ipv6cp_resetci, /* èªæ§ææ
|
---|
198 | å ±ããªã»ããããã */
|
---|
199 | ipv6cp_cilen, /* æ§ææ
|
---|
200 | å ±ã®é·ããè¿ãã */
|
---|
201 | ipv6cp_addci, /* èªæ§ææ
|
---|
202 | å ±ã追å ããã */
|
---|
203 | ipv6cp_ackci, /* ACK ãåä¿¡ããã¨ãã®å¦ç */
|
---|
204 | ipv6cp_nakci, /* NAK ãåä¿¡ããã¨ãã®å¦ç */
|
---|
205 | ipv6cp_rejci, /* REJ ãåä¿¡ããã¨ãã®å¦ç */
|
---|
206 | ipv6cp_reqci, /* ç¸æã®æ§ææ
|
---|
207 | å ±ã確èªããã */
|
---|
208 | ipv6cp_up, /* ãªã³ã¯æ¥ç¶ã確ç«ããã */
|
---|
209 | ipv6cp_down, /* ãªã³ã¯æ¥ç¶ã解æ¾ããã */
|
---|
210 | NULL, /* ä¸ä½å±¤ãéå§ããã */
|
---|
211 | ipv6cp_finished, /* ä¸ä½å±¤ãçµäºããã */
|
---|
212 | NULL, /* åéããã */
|
---|
213 | NULL, /* ä¸æ㪠CP ãåä¿¡ããã¨ãã®å¦ç */
|
---|
214 | };
|
---|
215 |
|
---|
216 | T_PPP_FSM ipv6cp_fsm = {
|
---|
217 | &ipv6cp_callbacks, /* ã³ã¼ã«ããã¯é¢æ° */
|
---|
218 | PPP_IPV6CP, /* ãããã³ã« */
|
---|
219 | };
|
---|
220 |
|
---|
221 | T_PPP_PROTENT ipv6cp_protent = {
|
---|
222 | PPP_IPV6CP,
|
---|
223 | ipv6cp_init, /* åæå */
|
---|
224 | ipv6cp_input, /* å
|
---|
225 | ¥å */
|
---|
226 | ipv6cp_protrej, /* Proto-REJ åä¿¡å¦ç */
|
---|
227 | ipv6cp_lowerup, /* ä¸ä½å±¤ãèµ·åãã */
|
---|
228 | ipv6cp_lowerdown, /* ä¸ä½å±¤ãåæ¢ãã */
|
---|
229 | ipv6cp_open, /* ãªã¼ãã³ãã */
|
---|
230 | ipv6cp_close, /* ã¯ãã¼ãºãã */
|
---|
231 | ip6_input, /* ãã¼ã¿å
|
---|
232 | ¥åãIPv6 å
|
---|
233 | ¥å */
|
---|
234 | };
|
---|
235 |
|
---|
236 | T_IFNET ipv6cp_local_ack_cfg; /* ç¸æã«è¨±å¯ãããã®èªæ§ææ
|
---|
237 | å ± */
|
---|
238 | T_IFNET ipv6cp_remote_ack_cfg; /* ç¸æã«è¨±å¯ããæ§ææ
|
---|
239 | å ± */
|
---|
240 |
|
---|
241 | /*
|
---|
242 | * ppp_get_ifnet -- ãããã¯ã¼ã¯ã¤ã³ã¿ãã§ã¼ã¹æ§é ä½ãè¿ãã
|
---|
243 | */
|
---|
244 |
|
---|
245 | T_IFNET *
|
---|
246 | ppp_get_ifnet (void)
|
---|
247 | {
|
---|
248 | return &ipv6cp_local_ack_cfg;
|
---|
249 | }
|
---|
250 |
|
---|
251 | /*
|
---|
252 | * wait_ipv6cp -- IP æ¥ç¶å®äºã¾ã§å¾
|
---|
253 | ã¤ã
|
---|
254 | *
|
---|
255 | * æ»ãå¤: æ¥ç¶ã«å¤±æããã E_OBJ ãè¿ãã
|
---|
256 | */
|
---|
257 |
|
---|
258 | ER
|
---|
259 | wait_ipv6cp (void)
|
---|
260 | {
|
---|
261 | #ifdef PPP_CFG_MODEM
|
---|
262 | ER error;
|
---|
263 | #endif /* of #ifdef PPP_CFG_MODEM */
|
---|
264 |
|
---|
265 | if (ipv6cp_fsm.state <= PPP_FSM_STOPPED) {
|
---|
266 |
|
---|
267 | #ifdef PPP_CFG_MODEM
|
---|
268 |
|
---|
269 | /* ã¢ãã ã®æ¥ç¶å®äºã¾ã§å¾
|
---|
270 | ã¤ã*/
|
---|
271 | if ((error = wait_modem()) != E_OK)
|
---|
272 | return error;
|
---|
273 |
|
---|
274 | #else /* of #ifdef PPP_CFG_MODEM */
|
---|
275 |
|
---|
276 | /*
|
---|
277 | * ååãªã¼ãã³ããç¸æããã®æ¥ç¶å¾
|
---|
278 | ã¡ãªã LCP ãä¸åº¦ã¯ãã¼ãºãã
|
---|
279 | * è½åãªã¼ãã³ç¶æ
|
---|
280 | ã§ãåãªã¼ãã³ããã
|
---|
281 | */
|
---|
282 | lcp_close();
|
---|
283 | lcp_open(PPP_OPEN_ACTIVE);
|
---|
284 |
|
---|
285 | #endif /* of #ifdef PPP_CFG_MODEM */
|
---|
286 |
|
---|
287 | }
|
---|
288 |
|
---|
289 | if (ipv6cp_fsm.state != PPP_FSM_OPENED) {
|
---|
290 | /* IP æ¥ç¶å®äºã¾ã§å¾
|
---|
291 | ã¤ã*/
|
---|
292 | wai_sem(SEM_IPV6CP_READY);
|
---|
293 | if (ipv6cp_fsm.state != PPP_FSM_OPENED)
|
---|
294 | return E_OBJ;
|
---|
295 | }
|
---|
296 |
|
---|
297 | return E_OK;
|
---|
298 | }
|
---|
299 |
|
---|
300 | /*
|
---|
301 | * ipv6cp_init -- IPV6CP ã¢ã¸ã¥ã¼ã«ã®åæå
|
---|
302 | */
|
---|
303 |
|
---|
304 | static void
|
---|
305 | ipv6cp_init (void)
|
---|
306 | {
|
---|
307 | fsm_init(&ipv6cp_fsm);
|
---|
308 | }
|
---|
309 |
|
---|
310 | /*
|
---|
311 | * ipv6cp_input -- IPV6CP å
|
---|
312 | ¥å
|
---|
313 | */
|
---|
314 |
|
---|
315 | static void
|
---|
316 | ipv6cp_input (T_NET_BUF *input)
|
---|
317 | {
|
---|
318 | NET_COUNT_PPP_IPV6CP(net_count_ppp_ipv6cp_in_octets, input->len);
|
---|
319 | NET_COUNT_PPP_IPV6CP(net_count_ppp_ipv6cp_in_packets, 1);
|
---|
320 | fsm_input(&ipv6cp_fsm, input);
|
---|
321 | }
|
---|
322 |
|
---|
323 | /*
|
---|
324 | * ipv6cp_resetci -- IPV6CPã®æ§ææ
|
---|
325 | å ±ããªã»ããããã
|
---|
326 | */
|
---|
327 |
|
---|
328 | static void
|
---|
329 | ipv6cp_resetci (T_PPP_FSM *fsm)
|
---|
330 | {
|
---|
331 | /* èªæ§ææ
|
---|
332 | å ±ã®åæè¨å® */
|
---|
333 | ipv6cp_local_neg_cfg = ipv6cp_local_def_cfg;
|
---|
334 | memset((void*)&ipv6cp_local_ack_cfg, 0, sizeof(T_IFNET));
|
---|
335 |
|
---|
336 | /* ç¸æã®æ§ææ
|
---|
337 | å ±ã®åæè¨å® */
|
---|
338 | ipv6cp_remote_neg_cfg = ipv6cp_remote_def_cfg;
|
---|
339 | memset((void*)&ipv6cp_remote_ack_cfg, 0, sizeof(T_IFNET));
|
---|
340 | }
|
---|
341 |
|
---|
342 | /*
|
---|
343 | * ipv6cp_cilen -- æ§ææ
|
---|
344 | å ±ã®é·ããè¿ãã
|
---|
345 | */
|
---|
346 |
|
---|
347 | static int_t
|
---|
348 | ipv6cp_cilen (T_PPP_FSM *fsm)
|
---|
349 | {
|
---|
350 | int_t cilen = 0;
|
---|
351 |
|
---|
352 | cilen += sizeof(T_PPP_CI_HDR) + sizeof(uint32_t); /* IPv6 ã¢ãã¬ã¹ */
|
---|
353 |
|
---|
354 | return cilen;
|
---|
355 | }
|
---|
356 |
|
---|
357 | /*
|
---|
358 | * ipv6cp_addci -- IPV6CPã®æ§ææ
|
---|
359 | å ±ã追å ããã
|
---|
360 | */
|
---|
361 |
|
---|
362 | static void
|
---|
363 | ipv6cp_addci (T_PPP_FSM *fsm, T_NET_BUF *output)
|
---|
364 | {
|
---|
365 | uint8_t *buf;
|
---|
366 |
|
---|
367 | buf = output->buf + sizeof(T_PPP_HDR) + sizeof(T_PPP_CP_HDR);
|
---|
368 |
|
---|
369 | /* IPv6 ã¢ãã¬ã¹ãªãã·ã§ã³ã追å ããã */
|
---|
370 | *buf ++ = IPV6CP_CIT_ADDR;
|
---|
371 | *buf ++ = sizeof(T_PPP_CI_HDR) + sizeof(uint32_t);
|
---|
372 | ahtonl(buf, ipv6cp_local_neg_cfg.in6_ifaddrs[0].addr);
|
---|
373 | buf += sizeof(uint32_t);
|
---|
374 | }
|
---|
375 |
|
---|
376 | /*
|
---|
377 | * ipv6cp_ackci -- ACK ãåä¿¡ããã¨ãã®å¦ç
|
---|
378 | *
|
---|
379 | * æ»ãå¤: true ACK ã¯æ£å¸¸
|
---|
380 | * false ACK ã¯ç°å¸¸
|
---|
381 | */
|
---|
382 |
|
---|
383 | static bool_t
|
---|
384 | ipv6cp_ackci (T_PPP_FSM *fsm, T_NET_BUF *input)
|
---|
385 | {
|
---|
386 | uint8_t *buf;
|
---|
387 | uint16_t len;
|
---|
388 |
|
---|
389 | buf = input->buf + sizeof(T_PPP_HDR) + sizeof(T_PPP_CP_HDR);
|
---|
390 | len = input->len - (sizeof(T_PPP_HDR) + sizeof(T_PPP_CP_HDR));
|
---|
391 |
|
---|
392 | /*
|
---|
393 | * æ§ææ
|
---|
394 | å ±ã¯éä¿¡ããé ã«å®å
|
---|
395 | ¨ã«ä¸è´ããªããã°ãªããªãã
|
---|
396 | * å¾ã£ã¦ãipv6cp_addci ã§ä½æããé ã«è§£æããã
|
---|
397 | */
|
---|
398 |
|
---|
399 | /* ADDR ãªãã·ã§ã³ã解æããã */
|
---|
400 | if (len < sizeof(T_PPP_CI_HDR) + sizeof(uint32_t) ||
|
---|
401 | *buf ++ != IPV6CP_CIT_ADDR ||
|
---|
402 | *buf ++ != sizeof(T_PPP_CI_HDR) + sizeof(uint32_t)||
|
---|
403 | nahcmpl(buf, ipv6cp_local_neg_cfg.in6_ifaddrs[0].addr))
|
---|
404 | return false;
|
---|
405 | buf += sizeof(uint32_t);
|
---|
406 | len -= sizeof(T_PPP_CI_HDR) + sizeof(uint32_t);
|
---|
407 |
|
---|
408 | return true;
|
---|
409 | }
|
---|
410 |
|
---|
411 | /*
|
---|
412 | * ipv6cp_nakci -- NAK ãåä¿¡ããã¨ãã®å¦ç
|
---|
413 | *
|
---|
414 | * æ»ãå¤: 1 NAK ã¯æ£å¸¸
|
---|
415 | * 0 NAK ã¯ç°å¸¸
|
---|
416 | */
|
---|
417 |
|
---|
418 | static int_t
|
---|
419 | ipv6cp_nakci (T_PPP_FSM *fsm, T_NET_BUF *input)
|
---|
420 | {
|
---|
421 | T_IFNET new_cfg;
|
---|
422 | uint32_t addr;
|
---|
423 | uint16_t len;
|
---|
424 | uint8_t *buf, cilen;
|
---|
425 |
|
---|
426 | buf = input->buf + sizeof(T_PPP_HDR) + sizeof(T_PPP_CP_HDR);
|
---|
427 | len = input->len - (sizeof(T_PPP_HDR) + sizeof(T_PPP_CP_HDR));
|
---|
428 |
|
---|
429 | new_cfg = ipv6cp_local_neg_cfg;
|
---|
430 |
|
---|
431 | /* ADDR ãªãã·ã§ã³ã解æããã */
|
---|
432 | if (len >= sizeof(T_PPP_CI_HDR) + sizeof(addr) &&
|
---|
433 | * buf == IPV6CP_CIT_ADDR &&
|
---|
434 | *(buf + 1) == sizeof(T_PPP_CI_HDR) + sizeof(addr)) {
|
---|
435 | memcpy(&new_cfg.in6_ifaddrs[0].addr, buf + 2, sizeof(addr));
|
---|
436 | buf += sizeof(T_PPP_CI_HDR) + sizeof(addr);
|
---|
437 | len -= sizeof(T_PPP_CI_HDR) + sizeof(addr);
|
---|
438 | }
|
---|
439 |
|
---|
440 | /* å¾ã¯ç¡è¦ããã*/
|
---|
441 | while (len > sizeof(T_PPP_CI_HDR)) {
|
---|
442 | cilen = *(buf + 1);
|
---|
443 | if (len < cilen)
|
---|
444 | return 0;
|
---|
445 | buf += cilen;
|
---|
446 | len -= cilen;
|
---|
447 | }
|
---|
448 |
|
---|
449 | /* é·ãã 0 ã§ãªããã°ã¨ã©ã¼ */
|
---|
450 | if (len != 0)
|
---|
451 | return 0;
|
---|
452 |
|
---|
453 | /* æ°ãããªãã·ã§ã³ãè¨å®ããã*/
|
---|
454 | if (fsm->state != PPP_FSM_OPENED)
|
---|
455 | ipv6cp_local_neg_cfg = new_cfg;
|
---|
456 |
|
---|
457 | return 1;
|
---|
458 | }
|
---|
459 |
|
---|
460 | /*
|
---|
461 | * ipv6cp_rejci -- REJ ãåä¿¡ããã¨ãã®å¦ç
|
---|
462 | *
|
---|
463 | * æ»ãå¤: 1 REJ ã¯æ£å¸¸
|
---|
464 | * 0 REJ ã¯ç°å¸¸
|
---|
465 | */
|
---|
466 |
|
---|
467 | static int_t
|
---|
468 | ipv6cp_rejci (T_PPP_FSM *fsm, T_NET_BUF *input)
|
---|
469 | {
|
---|
470 | T_IFNET new_cfg;
|
---|
471 | uint8_t *buf;
|
---|
472 | uint16_t len;
|
---|
473 |
|
---|
474 | buf = input->buf + sizeof(T_PPP_HDR) + sizeof(T_PPP_CP_HDR);
|
---|
475 | len = input->len - (sizeof(T_PPP_HDR) + sizeof(T_PPP_CP_HDR));
|
---|
476 |
|
---|
477 | new_cfg = ipv6cp_local_neg_cfg;
|
---|
478 |
|
---|
479 | /* ADDR ãªãã·ã§ã³ã解æããã */
|
---|
480 | if (len >= sizeof(T_PPP_CI_HDR) + sizeof(new_cfg.in6_ifaddrs[0].addr) &&
|
---|
481 | * buf == IPV6CP_CIT_ADDR &&
|
---|
482 | *(buf + 1) == sizeof(T_PPP_CI_HDR) + sizeof(new_cfg.in6_ifaddrs[0].addr)) {
|
---|
483 | memcpy(&new_cfg.in6_ifaddrs[0].addr, &in6_addr_unspecified,
|
---|
484 | sizeof(new_cfg.in6_ifaddrs[0].addr));
|
---|
485 | buf += sizeof(T_PPP_CI_HDR) + sizeof(new_cfg.in6_ifaddrs[0].addr);
|
---|
486 | len -= sizeof(T_PPP_CI_HDR) + sizeof(new_cfg.in6_ifaddrs[0].addr);
|
---|
487 | }
|
---|
488 |
|
---|
489 | /* é·ãã 0 ã§ãªããã°ã¨ã©ã¼ */
|
---|
490 | if (len != 0)
|
---|
491 | return 0;
|
---|
492 |
|
---|
493 | /* æ°ãããªãã·ã§ã³ãè¨å®ããã*/
|
---|
494 | if (fsm->state != PPP_FSM_OPENED)
|
---|
495 | ipv6cp_local_neg_cfg = new_cfg;
|
---|
496 |
|
---|
497 | return 1;
|
---|
498 | }
|
---|
499 |
|
---|
500 | /*
|
---|
501 | * ipv6cp_reqci -- ç¸æã®æ§ææ
|
---|
502 | å ±ã解æããã
|
---|
503 | */
|
---|
504 |
|
---|
505 | static int_t
|
---|
506 | ipv6cp_reqci (T_PPP_FSM *fsm, T_NET_BUF *input, T_NET_BUF *output)
|
---|
507 | {
|
---|
508 | T_IN6_ADDR addr;
|
---|
509 | uint16_t code, final, len, cilen;
|
---|
510 | uint8_t *np, *rp, *ap, *cp, type = 0;
|
---|
511 |
|
---|
512 | rp = ap = input->buf + sizeof(T_PPP_HDR) + sizeof(T_PPP_CP_HDR);
|
---|
513 | /* rp: REJãap: ACK ãã CI ã®ãã¤ã³ã¿ */
|
---|
514 | /* æå¦ããå ´åã¯ãå¼æ° buf ã«ä¸æ¸ãããã */
|
---|
515 | len = input->len - (sizeof(T_PPP_HDR) + sizeof(T_PPP_CP_HDR));
|
---|
516 | np = output->buf + sizeof(T_PPP_HDR) + sizeof(T_PPP_CP_HDR);
|
---|
517 | final = PPP_CONFACK; /* æçµçã«éä¿¡ããã³ã¼ã */
|
---|
518 | while (len > 0) {
|
---|
519 | code = PPP_CONFACK;
|
---|
520 | cp = ap; /* cp: ç¾å¨å¦çä¸ã® CI */
|
---|
521 |
|
---|
522 | if (len < sizeof(T_PPP_CI_HDR)) {
|
---|
523 |
|
---|
524 | /* æ®ãã CI ãããããçã */
|
---|
525 | syslog(LOG_NOTICE, "[PPP/IPV6CP] bad CI len: %d.", len);
|
---|
526 | cilen = len; /* ãã¼ã¿é·ãç°å¸¸ã®å ´åã®å¦ç½® */
|
---|
527 | len = 0; /* ã«ã¼ãããæããã */
|
---|
528 | code = PPP_CONFREJ;
|
---|
529 | goto endswitch;
|
---|
530 | }
|
---|
531 |
|
---|
532 | type = *ap ++; /* CI ã®å */
|
---|
533 | cilen = *ap ++; /* CI ã®é·ã */
|
---|
534 | if (len < cilen) {
|
---|
535 |
|
---|
536 | /* æ®ãã CI é·ããçã */
|
---|
537 | syslog(LOG_NOTICE, "[PPP/IPV6CP] bad CI len: %d.", cilen);
|
---|
538 | cilen = len; /* ãã¼ã¿é·ãç°å¸¸ã®å ´åã®å¦ç½® */
|
---|
539 | len = 0; /* ã«ã¼ãããæããã */
|
---|
540 | code = PPP_CONFREJ;
|
---|
541 | goto endswitch;
|
---|
542 | }
|
---|
543 | len -= sizeof(T_PPP_CI_HDR);
|
---|
544 |
|
---|
545 | /* CI ã®åã«ããåå²ããã*/
|
---|
546 | switch (type) {
|
---|
547 |
|
---|
548 | case IPV6CP_CIT_ADDR: /* IPv6 ã¢ãã¬ã¹ */
|
---|
549 |
|
---|
550 | /* CI é·ããããã + 4 ãªã¯ãããã§ãªããã°ã¨ã©ã¼ */
|
---|
551 | if (cilen != sizeof(T_PPP_CI_HDR) + sizeof(addr))
|
---|
552 | code = PPP_CONFREJ;
|
---|
553 | else {
|
---|
554 | memcpy((uint8_t*)&ipv6cp_remote_neg_cfg.in6_ifaddrs[0].addr, ap,
|
---|
555 | sizeof(ipv6cp_remote_neg_cfg.in6_ifaddrs[0].addr));
|
---|
556 | if (!IN6_ARE_ADDR_EQUAL(&addr, &ipv6cp_remote_neg_cfg.in6_ifaddrs[0].addr) &&
|
---|
557 | (IN6_IS_ADDR_UNSPECIFIED(&addr) ||
|
---|
558 | IN6_IS_ADDR_UNSPECIFIED(&ipv6cp_remote_neg_cfg.in6_ifaddrs[0].addr))) {
|
---|
559 | memcpy(np, (uint8_t*)&ipv6cp_remote_neg_cfg.in6_ifaddrs[0].addr,
|
---|
560 | sizeof(ipv6cp_remote_neg_cfg.in6_ifaddrs[0].addr));
|
---|
561 | *np ++ = IPV6CP_CIT_ADDR;
|
---|
562 | *np ++ = sizeof(T_PPP_CI_HDR) + sizeof(uint32_t);
|
---|
563 | np += sizeof(ipv6cp_remote_neg_cfg.in6_ifaddrs[0].addr);
|
---|
564 | code = PPP_CONFNAK;
|
---|
565 | }
|
---|
566 | #if 1 /* è¦ç¢ºèª */
|
---|
567 | else if (IN6_IS_ADDR_UNSPECIFIED(&addr) &&
|
---|
568 | IN6_IS_ADDR_UNSPECIFIED(&ipv6cp_remote_neg_cfg.in6_ifaddrs[0]))
|
---|
569 | #else
|
---|
570 | else if (IN6_IS_ADDR_UNSPECIFIED(&addr) ||
|
---|
571 | IN6_IS_ADDR_UNSPECIFIED(&ipv6cp_remote_neg_cfg.in6_ifaddrs[0]))
|
---|
572 | #endif
|
---|
573 | code = PPP_CONFREJ;
|
---|
574 | else
|
---|
575 | ipv6cp_remote_neg_cfg.in6_ifaddrs[0].addr = addr;
|
---|
576 | }
|
---|
577 | break;
|
---|
578 |
|
---|
579 | default:
|
---|
580 | syslog(LOG_INFO, "[PPP/IPV6CP] unexp opt: %d.", type);
|
---|
581 | code = PPP_CONFREJ;
|
---|
582 | break;
|
---|
583 | }
|
---|
584 | endswitch:
|
---|
585 |
|
---|
586 | if (code == PPP_CONFNAK) {
|
---|
587 | /* CI ã®åã Magic Number ã®å ´åãé¤ãã¦ãNAK ã®åæ°ã */
|
---|
588 | /* æå¤§å¤ MAX_PPP_FAILURES ãè¶
|
---|
589 | ãããæå¦ããã */
|
---|
590 | if (fsm->failures >= MAX_PPP_FAILURES)
|
---|
591 | code = PPP_CONFREJ;
|
---|
592 | else if (final != PPP_CONFREJ)
|
---|
593 | final = PPP_CONFNAK;
|
---|
594 | }
|
---|
595 |
|
---|
596 | /* ãã® CI ãæå¦ãã */
|
---|
597 | if (code == PPP_CONFREJ) {
|
---|
598 | if (rp < cp) /* åã«è©°ããã*/
|
---|
599 | memcpy(rp, cp, cilen);
|
---|
600 | rp += cilen;
|
---|
601 | final = PPP_CONFREJ;
|
---|
602 | }
|
---|
603 |
|
---|
604 | ap += cilen - sizeof(T_PPP_CI_HDR);
|
---|
605 | len -= cilen - sizeof(T_PPP_CI_HDR);
|
---|
606 | }
|
---|
607 |
|
---|
608 | /* æçµçãªé·ãã調æ´ããã*/
|
---|
609 | switch (final) {
|
---|
610 | case PPP_CONFNAK:
|
---|
611 | output->len = np - output->buf;
|
---|
612 | memcpy(output->buf, input->buf, sizeof(T_PPP_HDR) + sizeof(T_PPP_CP_HDR));
|
---|
613 | break;
|
---|
614 | case PPP_CONFREJ:
|
---|
615 | memcpy(output->buf, input->buf, output->len = rp - input->buf);
|
---|
616 | break;
|
---|
617 | case PPP_CONFACK:
|
---|
618 | memcpy(output->buf, input->buf, input->len);
|
---|
619 | break;
|
---|
620 | }
|
---|
621 |
|
---|
622 | return final;
|
---|
623 | }
|
---|
624 |
|
---|
625 | /*
|
---|
626 | * ipv6cp_up -- ãªã³ã¯æ¥ç¶ã確ç«ããã
|
---|
627 | */
|
---|
628 |
|
---|
629 | static void
|
---|
630 | ipv6cp_up (T_PPP_FSM *fsm)
|
---|
631 | {
|
---|
632 | /* èªæ§ææ
|
---|
633 | å ±ã®åæè¨å® */
|
---|
634 | ipv6cp_local_ack_cfg = ipv6cp_local_neg_cfg;
|
---|
635 |
|
---|
636 | sig_sem(SEM_IPV6CP_READY);
|
---|
637 |
|
---|
638 | syslog(LOG_NOTICE, "[PPP/IPV6CP] up, Local IPv6 Addr: %s, Remote IPv6 Addr: %s.",
|
---|
639 | ipv62str(NULL, &ipv6cp_local_neg_cfg.in6_ifaddrs[0].addr),
|
---|
640 | ipv62str(NULL, &ipv6cp_remote_neg_cfg.in6_ifaddrs[0].addr));
|
---|
641 | }
|
---|
642 |
|
---|
643 | /*
|
---|
644 | * ipv6cp_down -- ãªã³ã¯æ¥ç¶ã解æ¾ããã
|
---|
645 | */
|
---|
646 |
|
---|
647 | static void
|
---|
648 | ipv6cp_down (T_PPP_FSM *fsm)
|
---|
649 | {
|
---|
650 | sig_sem(SEM_IPV6CP_READY);
|
---|
651 | syslog(LOG_NOTICE, "[PPP/IPV6CP] down.");
|
---|
652 | }
|
---|
653 |
|
---|
654 | /*
|
---|
655 | * ipv6cp_finished -- ä¸ä½å±¤ãçµäºããã
|
---|
656 | */
|
---|
657 |
|
---|
658 | static void
|
---|
659 | ipv6cp_finished (T_PPP_FSM *fsm)
|
---|
660 | {
|
---|
661 | }
|
---|
662 |
|
---|
663 | /*
|
---|
664 | * ipv6cp_protrej -- Proto-REJ ãåä¿¡ããã¨ãã®å¦ç
|
---|
665 | */
|
---|
666 |
|
---|
667 | static void
|
---|
668 | ipv6cp_protrej (void)
|
---|
669 | {
|
---|
670 | fsm_lowerdown(&ipv6cp_fsm);
|
---|
671 | }
|
---|
672 |
|
---|
673 | /*
|
---|
674 | * ipv6cp_lowerup -- IPV6CP ä¸ä½å±¤ãèµ·åããã
|
---|
675 | */
|
---|
676 |
|
---|
677 | static void
|
---|
678 | ipv6cp_lowerup (void)
|
---|
679 | {
|
---|
680 | fsm_lowerup(&ipv6cp_fsm);
|
---|
681 | }
|
---|
682 |
|
---|
683 | /*
|
---|
684 | * ipv6cp_lowerdown -- IPV6CP ä¸ä½å±¤ãåæ¢ããã
|
---|
685 | */
|
---|
686 |
|
---|
687 | static void
|
---|
688 | ipv6cp_lowerdown (void)
|
---|
689 | {
|
---|
690 | fsm_lowerdown(&ipv6cp_fsm);
|
---|
691 | }
|
---|
692 |
|
---|
693 | /*
|
---|
694 | * ipv6cp_open -- IPV6CP ã®ãªã¼ãã³
|
---|
695 | */
|
---|
696 |
|
---|
697 | static void
|
---|
698 | ipv6cp_open (void)
|
---|
699 | {
|
---|
700 | fsm_open(&ipv6cp_fsm);
|
---|
701 | }
|
---|
702 |
|
---|
703 | /*
|
---|
704 | * ipv6cp_close -- IPV6CP ã®ã¯ãã¼ãº
|
---|
705 | */
|
---|
706 |
|
---|
707 | static void
|
---|
708 | ipv6cp_close (void)
|
---|
709 | {
|
---|
710 | fsm_close(&ipv6cp_fsm);
|
---|
711 | }
|
---|
712 |
|
---|
713 | #endif /* fo #ifdef SUPPORT_PPP */
|
---|