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