[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 | * 上記著作権者は,以下の (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_debug.h>
|
---|
| 96 | #include <net/net_count.h>
|
---|
| 97 | #include <net/ppp.h>
|
---|
| 98 | #include <net/ppp_var.h>
|
---|
| 99 | #include <net/ppp_fsm.h>
|
---|
| 100 | #include <net/ppp_ccp.h>
|
---|
| 101 |
|
---|
| 102 | /*
|
---|
| 103 | * 関数
|
---|
| 104 | */
|
---|
| 105 |
|
---|
| 106 | static void ccp_init (void);
|
---|
| 107 | static void ccp_input (T_NET_BUF *nbuf);
|
---|
| 108 | static void ccp_protrej (void);
|
---|
| 109 | static void ccp_lowerup (void);
|
---|
| 110 | static void ccp_lowerdown (void);
|
---|
| 111 | static void ccp_open (void);
|
---|
| 112 | static void ccp_close (void);
|
---|
| 113 |
|
---|
| 114 | /*
|
---|
| 115 | * FSM から呼出されるコールバック関
|
---|
| 116 | */
|
---|
| 117 |
|
---|
| 118 | static int_t ccp_reqci (T_PPP_FSM *fsm, T_NET_BUF *nbuf);
|
---|
| 119 | /* 相手の構成情報を確認する。 */
|
---|
| 120 |
|
---|
| 121 | /*
|
---|
| 122 | * 全域変数
|
---|
| 123 | */
|
---|
| 124 |
|
---|
| 125 | T_PPP_FSM_CALLBACKS ccp_callbacks = {
|
---|
| 126 | NULL, /* 自構成情報をリセットする。 */
|
---|
| 127 | NULL, /* 構成情報の長さを返す。 */
|
---|
| 128 | NULL, /* 自構成情報を追加する。 */
|
---|
| 129 | NULL, /* ACK を受信したときの処理 */
|
---|
| 130 | NULL, /* NAK を受信したときの処理 */
|
---|
| 131 | NULL, /* REJ を受信したときの処理 */
|
---|
| 132 | ccp_reqci, /* 相手の構成情報を確認する。 */
|
---|
| 133 | NULL, /* リンク接続を確立する。 */
|
---|
| 134 | NULL, /* リンク接続を解放する。 */
|
---|
| 135 | NULL, /* 下位層を開始する。 */
|
---|
| 136 | NULL, /* 下位層を終了する。 */
|
---|
| 137 | NULL, /* 再送する。 */
|
---|
| 138 | NULL, /* 不明な CP を受信したときの処理 */
|
---|
| 139 | };
|
---|
| 140 |
|
---|
| 141 | T_PPP_FSM ccp_fsm = {
|
---|
| 142 | &ccp_callbacks, /* コールバック関数 */
|
---|
| 143 | PPP_CCP, /* プロトコル */
|
---|
| 144 | };
|
---|
| 145 |
|
---|
| 146 | T_PPP_PROTENT ccp_protent = {
|
---|
| 147 | PPP_CCP,
|
---|
| 148 | ccp_init, /* 初期化 */
|
---|
| 149 | ccp_input, /* 入力 */
|
---|
| 150 | ccp_protrej, /* Proto-REJ 受信処理 */
|
---|
| 151 | ccp_lowerup, /* 下位層を起動する */
|
---|
| 152 | ccp_lowerdown, /* 下位層を停止する */
|
---|
| 153 | ccp_open, /* オープンする */
|
---|
| 154 | ccp_close, /* クローズする */
|
---|
| 155 | NULL, /* データ入力 */
|
---|
| 156 | };
|
---|
| 157 |
|
---|
| 158 | /*
|
---|
| 159 | * ccp_init -- CCP モジュールの初期化
|
---|
| 160 | */
|
---|
| 161 |
|
---|
| 162 | static void
|
---|
| 163 | ccp_init (void)
|
---|
| 164 | {
|
---|
| 165 | fsm_init(&ccp_fsm);
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | /*
|
---|
| 169 | * ccp_input -- CCP 入力
|
---|
| 170 | */
|
---|
| 171 |
|
---|
| 172 | static void
|
---|
| 173 | ccp_input (T_NET_BUF *nbuf)
|
---|
| 174 | {
|
---|
| 175 | NET_COUNT_PPP_CCP(net_count_ppp_ccp_in_octets, nbuf->len);
|
---|
| 176 | NET_COUNT_PPP_CCP(net_count_ppp_ccp_in_packets, 1);
|
---|
| 177 | fsm_input(&ccp_fsm, nbuf);
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | /*
|
---|
| 181 | * ccp_reqci -- 相手の構成情報を解析する。
|
---|
| 182 | */
|
---|
| 183 |
|
---|
| 184 | static int_t
|
---|
| 185 | ccp_reqci (T_PPP_FSM *fsm, T_NET_BUF *nbuf)
|
---|
| 186 | {
|
---|
| 187 | /*
|
---|
| 188 | * 実装予定、現在はすべてのオプションを拒否する。
|
---|
| 189 | */
|
---|
| 190 | return nbuf->len > (sizeof(T_PPP_HDR) + sizeof(T_PPP_CP_HDR)) ? PPP_CONFREJ : PPP_CONFACK;
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 | /*
|
---|
| 194 | * ccp_protrej -- Proto-REJ を受信したときの処理
|
---|
| 195 | */
|
---|
| 196 |
|
---|
| 197 | static void
|
---|
| 198 | ccp_protrej (void)
|
---|
| 199 | {
|
---|
| 200 | fsm_lowerdown(&ccp_fsm);
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | /*
|
---|
| 204 | * ccp_lowerup -- CCP 下位層を起動する。
|
---|
| 205 | */
|
---|
| 206 |
|
---|
| 207 | static void
|
---|
| 208 | ccp_lowerup (void)
|
---|
| 209 | {
|
---|
| 210 | fsm_lowerup(&ccp_fsm);
|
---|
| 211 | }
|
---|
| 212 |
|
---|
| 213 | /*
|
---|
| 214 | * ccp_lowerdown -- CCP 下位層を停止する。
|
---|
| 215 | */
|
---|
| 216 |
|
---|
| 217 | static void
|
---|
| 218 | ccp_lowerdown (void)
|
---|
| 219 | {
|
---|
| 220 | fsm_lowerdown(&ccp_fsm);
|
---|
| 221 | }
|
---|
| 222 |
|
---|
| 223 | /*
|
---|
| 224 | * ccp_open -- CCP のオープ
|
---|
| 225 | */
|
---|
| 226 |
|
---|
| 227 | static void
|
---|
| 228 | ccp_open (void)
|
---|
| 229 | {
|
---|
| 230 | fsm_open(&ccp_fsm);
|
---|
| 231 | }
|
---|
| 232 |
|
---|
| 233 | /*
|
---|
| 234 | * ccp_close -- CCP のクローズ
|
---|
| 235 | */
|
---|
| 236 |
|
---|
| 237 | static void
|
---|
| 238 | ccp_close (void)
|
---|
| 239 | {
|
---|
| 240 | fsm_close(&ccp_fsm);
|
---|
| 241 | }
|
---|