[352] | 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 | * 上記著作権者は,以下の (1)~(4) の条件か,Free Software Foundation
|
---|
| 8 | * によって公表されている GNU General Public License の Version 2 に記
|
---|
| 9 | * 述されている条件を満たす場合に限り,本ソフトウェア(本ソフトウェア
|
---|
| 10 | * を改変したものを含む.以下同じ)を使用・複製・改変・再配布(以下,
|
---|
| 11 | * 利用と呼ぶ)することを無償で許諾する.
|
---|
| 12 | * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
|
---|
| 13 | * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
|
---|
| 14 | * スコード中に含まれていること.
|
---|
| 15 | * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
|
---|
| 16 | * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
|
---|
| 17 | * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
|
---|
| 18 | * の無保証規定を掲載すること.
|
---|
| 19 | * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
|
---|
| 20 | * 用できない形で再配布する場合には,次の条件を満たすこと.
|
---|
| 21 | * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
|
---|
| 22 | * 作権表示,この利用条件および下記の無保証規定を掲載すること.
|
---|
| 23 | * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
|
---|
| 24 | * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
|
---|
| 25 | *
|
---|
| 26 | * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
|
---|
| 27 | * よびTOPPERSプロジェクトは,本ソフトウェアに関して,その適用可能性も
|
---|
| 28 | * 含めて,いかなる保証も行わない.また,本ソフトウェアの利用により直
|
---|
| 29 | * 接的または間接的に生じたいかなる損害に関しても,その責任を負わない.
|
---|
| 30 | *
|
---|
| 31 | * @(#) $Id$
|
---|
| 32 | */
|
---|
| 33 |
|
---|
| 34 | /*
|
---|
| 35 | * ccp.c - PPP Compression Control Protocol.
|
---|
| 36 | *
|
---|
| 37 | * Copyright (c) 1994 The Australian National University.
|
---|
| 38 | * All rights reserved.
|
---|
| 39 | *
|
---|
| 40 | * Permission to use, copy, modify, and distribute this software and its
|
---|
| 41 | * documentation is hereby granted, provided that the above copyright
|
---|
| 42 | * notice appears in all copies. This software is provided without any
|
---|
| 43 | * warranty, express or implied. The Australian National University
|
---|
| 44 | * makes no representations about the suitability of this software for
|
---|
| 45 | * any purpose.
|
---|
| 46 | *
|
---|
| 47 | * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
|
---|
| 48 | * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
---|
| 49 | * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
|
---|
| 50 | * THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY
|
---|
| 51 | * OF SUCH DAMAGE.
|
---|
| 52 | *
|
---|
| 53 | * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
|
---|
| 54 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
---|
| 55 | * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
---|
| 56 | * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
|
---|
| 57 | * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
|
---|
| 58 | * OR MODIFICATIONS.
|
---|
| 59 | */
|
---|
| 60 |
|
---|
| 61 | /*
|
---|
| 62 | * PPP Compression Control Protocol (CCP) Module
|
---|
| 63 | *
|
---|
| 64 | * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
|
---|
| 65 | *
|
---|
| 66 | * Copyright (C) 1994, Internet Initiative Japan, Inc. All rights reserverd.
|
---|
| 67 | *
|
---|
| 68 | * Redistribution and use in source and binary forms are permitted
|
---|
| 69 | * provided that the above copyright notice and this paragraph are
|
---|
| 70 | * duplicated in all such forms and that any documentation,
|
---|
| 71 | * advertising materials, and other materials related to such
|
---|
| 72 | * distribution and use acknowledge that the software was developed
|
---|
| 73 | * by the Internet Initiative Japan, Inc. The name of the
|
---|
| 74 | * IIJ may not be used to endorse or promote products derived
|
---|
| 75 | * from this software without specific prior written permission.
|
---|
| 76 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
---|
| 77 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
---|
| 78 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
---|
| 79 | *
|
---|
| 80 | * $FreeBSD: src/usr.sbin/ppp/ccp.c,v 1.54.2.2 2000/08/19 09:29:59 brian Exp $
|
---|
| 81 | *
|
---|
| 82 | * TODO:
|
---|
| 83 | * o Support other compression protocols
|
---|
| 84 | */
|
---|
| 85 |
|
---|
| 86 | /*
|
---|
| 87 | * 実装予定、現在はすべて拒否
|
---|
| 88 | */
|
---|
| 89 |
|
---|
| 90 | #include <t_services.h>
|
---|
| 91 |
|
---|
| 92 | #include <net/if.h>
|
---|
| 93 | #include <net/if_ppp.h>
|
---|
| 94 | #include <net/net_buf.h>
|
---|
| 95 | #include <net/net_count.h>
|
---|
| 96 | #include <net/ppp.h>
|
---|
| 97 | #include <net/ppp_var.h>
|
---|
| 98 | #include <net/ppp_fsm.h>
|
---|
| 99 | #include <net/ppp_ccp.h>
|
---|
| 100 |
|
---|
| 101 | /*
|
---|
| 102 | * 関数
|
---|
| 103 | */
|
---|
| 104 |
|
---|
| 105 | static void ccp_init (void);
|
---|
| 106 | static void ccp_input (T_NET_BUF *nbuf);
|
---|
| 107 | static void ccp_protrej (void);
|
---|
| 108 | static void ccp_lowerup (void);
|
---|
| 109 | static void ccp_lowerdown (void);
|
---|
| 110 | static void ccp_open (void);
|
---|
| 111 | static void ccp_close (void);
|
---|
| 112 |
|
---|
| 113 | /*
|
---|
| 114 | * FSM から呼出されるコールバック関
|
---|
| 115 | */
|
---|
| 116 |
|
---|
| 117 | static int_t ccp_reqci (T_PPP_FSM *fsm, T_NET_BUF *nbuf);
|
---|
| 118 | /* 相手の構成情報を確認する。 */
|
---|
| 119 |
|
---|
| 120 | /*
|
---|
| 121 | * 全域変数
|
---|
| 122 | */
|
---|
| 123 |
|
---|
| 124 | T_PPP_FSM_CALLBACKS ccp_callbacks = {
|
---|
| 125 | NULL, /* 自構成情報をリセットする。 */
|
---|
| 126 | NULL, /* 構成情報の長さを返す。 */
|
---|
| 127 | NULL, /* 自構成情報を追加する。 */
|
---|
| 128 | NULL, /* ACK を受信したときの処理 */
|
---|
| 129 | NULL, /* NAK を受信したときの処理 */
|
---|
| 130 | NULL, /* REJ を受信したときの処理 */
|
---|
| 131 | ccp_reqci, /* 相手の構成情報を確認する。 */
|
---|
| 132 | NULL, /* リンク接続を確立する。 */
|
---|
| 133 | NULL, /* リンク接続を解放する。 */
|
---|
| 134 | NULL, /* 下位層を開始する。 */
|
---|
| 135 | NULL, /* 下位層を終了する。 */
|
---|
| 136 | NULL, /* 再送する。 */
|
---|
| 137 | NULL, /* 不明な CP を受信したときの処理 */
|
---|
| 138 | };
|
---|
| 139 |
|
---|
| 140 | T_PPP_FSM ccp_fsm = {
|
---|
| 141 | &ccp_callbacks, /* コールバック関数 */
|
---|
| 142 | PPP_CCP, /* プロトコル */
|
---|
| 143 | };
|
---|
| 144 |
|
---|
| 145 | T_PPP_PROTENT ccp_protent = {
|
---|
| 146 | PPP_CCP,
|
---|
| 147 | ccp_init, /* 初期化 */
|
---|
| 148 | ccp_input, /* 入力 */
|
---|
| 149 | ccp_protrej, /* Proto-REJ 受信処理 */
|
---|
| 150 | ccp_lowerup, /* 下位層を起動する */
|
---|
| 151 | ccp_lowerdown, /* 下位層を停止する */
|
---|
| 152 | ccp_open, /* オープンする */
|
---|
| 153 | ccp_close, /* クローズする */
|
---|
| 154 | NULL, /* データ入力 */
|
---|
| 155 | };
|
---|
| 156 |
|
---|
| 157 | /*
|
---|
| 158 | * ccp_init -- CCP モジュールの初期化
|
---|
| 159 | */
|
---|
| 160 |
|
---|
| 161 | static void
|
---|
| 162 | ccp_init (void)
|
---|
| 163 | {
|
---|
| 164 | fsm_init(&ccp_fsm);
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | /*
|
---|
| 168 | * ccp_input -- CCP 入力
|
---|
| 169 | */
|
---|
| 170 |
|
---|
| 171 | static void
|
---|
| 172 | ccp_input (T_NET_BUF *nbuf)
|
---|
| 173 | {
|
---|
| 174 | NET_COUNT_PPP_CCP(net_count_ppp_ccp_in_octets, nbuf->len);
|
---|
| 175 | NET_COUNT_PPP_CCP(net_count_ppp_ccp_in_packets, 1);
|
---|
| 176 | fsm_input(&ccp_fsm, nbuf);
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 | /*
|
---|
| 180 | * ccp_reqci -- 相手の構成情報を解析する。
|
---|
| 181 | */
|
---|
| 182 |
|
---|
| 183 | static int_t
|
---|
| 184 | ccp_reqci (T_PPP_FSM *fsm, T_NET_BUF *nbuf)
|
---|
| 185 | {
|
---|
| 186 | /*
|
---|
| 187 | * 実装予定、現在はすべてのオプションを拒否する。
|
---|
| 188 | */
|
---|
| 189 | return nbuf->len > (sizeof(T_PPP_HDR) + sizeof(T_PPP_CP_HDR)) ? PPP_CONFREJ : PPP_CONFACK;
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | /*
|
---|
| 193 | * ccp_protrej -- Proto-REJ を受信したときの処理
|
---|
| 194 | */
|
---|
| 195 |
|
---|
| 196 | static void
|
---|
| 197 | ccp_protrej (void)
|
---|
| 198 | {
|
---|
| 199 | fsm_lowerdown(&ccp_fsm);
|
---|
| 200 | }
|
---|
| 201 |
|
---|
| 202 | /*
|
---|
| 203 | * ccp_lowerup -- CCP 下位層を起動する。
|
---|
| 204 | */
|
---|
| 205 |
|
---|
| 206 | static void
|
---|
| 207 | ccp_lowerup (void)
|
---|
| 208 | {
|
---|
| 209 | fsm_lowerup(&ccp_fsm);
|
---|
| 210 | }
|
---|
| 211 |
|
---|
| 212 | /*
|
---|
| 213 | * ccp_lowerdown -- CCP 下位層を停止する。
|
---|
| 214 | */
|
---|
| 215 |
|
---|
| 216 | static void
|
---|
| 217 | ccp_lowerdown (void)
|
---|
| 218 | {
|
---|
| 219 | fsm_lowerdown(&ccp_fsm);
|
---|
| 220 | }
|
---|
| 221 |
|
---|
| 222 | /*
|
---|
| 223 | * ccp_open -- CCP のオープ
|
---|
| 224 | */
|
---|
| 225 |
|
---|
| 226 | static void
|
---|
| 227 | ccp_open (void)
|
---|
| 228 | {
|
---|
| 229 | fsm_open(&ccp_fsm);
|
---|
| 230 | }
|
---|
| 231 |
|
---|
| 232 | /*
|
---|
| 233 | * ccp_close -- CCP のクローズ
|
---|
| 234 | */
|
---|
| 235 |
|
---|
| 236 | static void
|
---|
| 237 | ccp_close (void)
|
---|
| 238 | {
|
---|
| 239 | fsm_close(&ccp_fsm);
|
---|
| 240 | }
|
---|