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