diff options
author | yasuoka <yasuoka@openbsd.org> | 2010-07-01 03:38:17 +0000 |
---|---|---|
committer | yasuoka <yasuoka@openbsd.org> | 2010-07-01 03:38:17 +0000 |
commit | f0a4e295ec0d8ba054b2deac9d5b70bfe31cda67 (patch) | |
tree | fffd65130608b1c4f467c15829e1419fb3b6dd1f /usr.sbin/npppd/l2tp | |
parent | Partially sync atomic.h with hppa so that we get real atomic ops and some (diff) | |
download | wireguard-openbsd-f0a4e295ec0d8ba054b2deac9d5b70bfe31cda67.tar.xz wireguard-openbsd-f0a4e295ec0d8ba054b2deac9d5b70bfe31cda67.zip |
Translate Japanese comments or labels into English. Translation was
done by IIJ people (MATSUI Yoshihiro, SAITOH Masanobu, Tomoyuki Sahara),
yuo@ and myself.
This diff also includes
- delete part of useless comments, correct spelling.
- add man page of npppdctl.
There is no functional change.
Diffstat (limited to 'usr.sbin/npppd/l2tp')
-rw-r--r-- | usr.sbin/npppd/l2tp/l2tp.h | 151 | ||||
-rw-r--r-- | usr.sbin/npppd/l2tp/l2tp_call.c | 182 | ||||
-rw-r--r-- | usr.sbin/npppd/l2tp/l2tp_ctrl.c | 311 | ||||
-rw-r--r-- | usr.sbin/npppd/l2tp/l2tp_local.h | 3 | ||||
-rw-r--r-- | usr.sbin/npppd/l2tp/l2tp_subr.c | 15 | ||||
-rw-r--r-- | usr.sbin/npppd/l2tp/l2tp_subr.h | 17 | ||||
-rw-r--r-- | usr.sbin/npppd/l2tp/l2tpd.c | 163 |
7 files changed, 395 insertions, 447 deletions
diff --git a/usr.sbin/npppd/l2tp/l2tp.h b/usr.sbin/npppd/l2tp/l2tp.h index c3910f91010..3dca153a73c 100644 --- a/usr.sbin/npppd/l2tp/l2tp.h +++ b/usr.sbin/npppd/l2tp/l2tp.h @@ -26,19 +26,19 @@ #ifndef L2TP_H #define L2TP_H 1 /*@file - * L2TPモジュールヘッダファイル + * header file for the L2TP module */ -/* $Id: l2tp.h,v 1.1 2010/01/11 04:20:57 yasuoka Exp $ */ +/* $Id: l2tp.h,v 1.2 2010/07/01 03:38:17 yasuoka Exp $ */ /************************************************************************ - * プロトコル上の定数 + * Protocol Constants ************************************************************************/ #define L2TP_RFC2661_VERSION 1 #define L2TP_RFC2661_REVISION 0 #define L2TP_AVP_MAXSIZ 1024 -/* ヘッダ */ +/* Header */ #define L2TP_HEADER_FLAG_TOM 0x8000 #define L2TP_HEADER_FLAG_LENGTH 0x4000 @@ -168,8 +168,8 @@ #define L2TP_BEARER_CAP_FLAGS_ANALOG 0x00000002 /* - * RFC2661 の pp.19 〜 pp.22 の定数 - * ラベル名は不適切かも。 + * Constants on pp.19-22 of RFC2661 + * macro names may be inappropriate. */ #define L2TP_STOP_CCN_RCODE_GENERAL 1 #define L2TP_STOP_CCN_RCODE_GENERAL_ERROR 2 @@ -209,7 +209,7 @@ #define L2TP_AUTH_TYPE_MS_CHAP_V1 5 /************************************************************************ - * この実装の定数 + * Implementation Specific Constants ************************************************************************/ #define L2TPD_BACKLOG 16 @@ -225,13 +225,13 @@ #endif #define L2TPD_DEFAULT_UDP_PORT 1701 -/** アドレスは最大何個 bind 可能か。*/ +/** maximum number of addresses we will listen on */ #ifndef L2TP_NLISTENER #define L2TP_NLISTENER 6 #endif /* - * デーモンの状態 + * state of daemon */ #define L2TPD_STATE_INIT 0 #define L2TPD_STATE_RUNNING 1 @@ -239,7 +239,7 @@ #define L2TPD_STATE_STOPPED 3 /* - * コントロール接続の状態 + * state of a control connection */ #define L2TP_CTRL_STATE_IDLE 0 #define L2TP_CTRL_STATE_WAIT_CTL_CONN 1 @@ -248,7 +248,7 @@ #define L2TP_CTRL_STATE_CLEANUP_WAIT 4 /* - * コールの状態 + * state of a call */ #define L2TP_CALL_STATE_IDLE 0 #define L2TP_CALL_STATE_WAIT_CONN 1 @@ -256,10 +256,10 @@ #define L2TP_CALL_STATE_CLEANUP_WAIT 3 /* - * タイムアウト関連 + * timeout */ #define L2TP_CTRL_CTRL_PKT_TIMEOUT 12 -/** 最初の Call を待つ時間 */ +/** wait time for the first call */ #define L2TP_CTRL_WAIT_CALL_TIMEOUT 16 #define L2TP_CTRL_CLEANUP_WAIT_TIME 3 #define L2TP_CTRL_DEFAULT_HELLO_INTERVAL 60 @@ -267,64 +267,64 @@ #define L2TPD_SHUTDOWN_TIMEOUT 5 -/** L2TPデーモンが停止したかどうかを返します。 */ +/** returns whether an L2TP daemon is stopped */ #define l2tpd_is_stopped(l2tpd) \ (((l2tpd)->state != L2TPD_STATE_SHUTTING_DOWN && \ (l2tpd)->state != L2TPD_STATE_RUNNING)? 1 : 0) -/** L2TPデーモンが停止処理中かどうかを返します。 */ +/** returns whether an L2TP daemon is going to shutdown */ #define l2tpd_is_shutting_down(l2tpd) \ (((l2tpd)->state == L2TPD_STATE_SHUTTING_DOWN)? 1 : 0) -/** l2tp_ctrl から、リスナーの物理層のラベルを取り出すマクロ */ +/** macro to retrieve a physical layer label from l2tp_ctrl */ #define L2TP_CTRL_LISTENER_LABEL(ctrl) \ ((l2tpd_listener *)slist_get(&(ctrl)->l2tpd->listener, \ (ctrl)->listener_index))->phy_label -/** L2TP のデーモンを示す型。*/ +/** datatype represents L2TP daemon */ struct _l2tpd; typedef struct _l2tpd_listener { - /** イベントコンテキスト */ + /** event context */ struct event ev_sock; - /** L2TPD 自身 */ + /** L2TPD itself */ struct _l2tpd *self; - /** インデックス番号 */ + /** index number */ uint16_t index; - /** 有効/無効 */ + /** enable/disable */ uint16_t enabled; - /** 待ち受けソケット */ + /** listening socket */ int sock; - /** 待ち受けアドレス UDP */ + /** listening socket address for UDP packets */ struct sockaddr_in bind_sin; - /** 物理層のラベル */ + /** physical layer label */ char phy_label[16]; } l2tpd_listener; -/** L2TP のデーモンを示す型。*/ +/** datatype represents L2TP daemon */ typedef struct _l2tpd { - /** タイムアウトイベントコンテキスト */ + /** timeout event context */ struct event ev_timeout; - /** インスタンスの ID */ + /** instance ID */ unsigned id; - /** 待ち受けリスト */ + /** listener list */ slist listener; - /** ステータス */ + /** state */ int state; - /** トンネル ID と {@link ::_l2tp_ctrl L2TP コントロール} のマップ */ + /** mappings from tunnel ID to {@link ::_l2tp_ctrl L2TP control} */ hash_table *ctrl_map; - /** 接続を許可するIPv4ネットワーク */ + /** IPv4 network addresses allowed to connect */ struct in_addr_range *ip4_allow; - /** デフォルトのホスト名 */ + /** default hostname */ char default_hostname[80]; - /** 設定 */ + /** configuration */ struct properties *config; - /** フラグ */ + /** flags */ uint32_t require_ipsec:1, purge_ipsec_sa:1, @@ -335,101 +335,104 @@ typedef struct _l2tpd { phy_label_with_ifname:1; } l2tpd; -/** L2TP コントロール接続を示す型。*/ +/** datatype represents L2TP control connection */ typedef struct _l2tp_ctrl { struct event ev_timeout; /** ID */ unsigned id; - /** 親 L2TPD */ + /** parent L2TPD */ l2tpd *l2tpd; - /** リスナー インデックス番号 */ + /** listener index number */ uint16_t listener_index; - /** 状態 */ + /** state */ int state; - /** トンネルId。 */ + /** tunnel Id */ int tunnel_id; - /** Window サイズ */ + /** window size */ int winsz; - /** 先方のトンネルId */ + /** peer's tunnel Id */ int peer_tunnel_id; - /** 先方の Window サイズ */ + /** peer's window size */ int peer_winsz; - /** 次の確認応答 */ + /** next acknowledgement number */ uint16_t snd_una; - /** 次の送信シーケンス番号 */ + /** next send sequence number */ uint16_t snd_nxt; - /** 受信シーケンス番号 */ + /** receive sequence number */ uint16_t rcv_nxt; - /** 先方のアドレス*/ + /** peer's IP address */ struct sockaddr_storage peer; - /** こちらのアドレス */ + /** my IP address */ struct sockaddr_storage sock; - /** IPSEC NAT-T SA クッキー */ + /** IPSEC NAT-T SA cookie */ void *sa_cookie; - /** 物理層のラベル (コピー) */ + /** physical layer label (copied) */ char phy_label[16]; - /** L2TPコールのリスト */ + /** list of L2TP calls */ slist call_list; /* - * 送信 Window 関連 - * pos == lim は、バッファが一杯であることを示します。 - * pos == -1、lim == 0 はバッファが空であることを示します。 + * Note about send window: + * pos == lim when buffer is full. + * pos == -1, lim == 0 when buffer is empty. */ - /** 利用可能な送信バッファ。#winsz 分のリストになってます*/ + /** bytes available in send buffer. it is a list of length #winsz */ bytebuffer **snd_buffers; - /** Sending buffer for ZLB */ + /** sending buffer for ZLB */ bytebuffer *zlb_buffer; - /** 最後にコントロールメッセージを送信した時間 */ + /** the time when last control message sent */ time_t last_snd_ctrl; - /** 最後にパケットを受信を送信した時間 */ + /** the time when last packet received */ time_t last_rcv; /** - * アクティブクローズの場合で、StopCCN を未送信の場合は、StopCCN - * で伝える result code が入ります。 + * If we are on active close and have not sent a StopCCN message yet, + * active_closing has the result code to be in the StopCCN message. */ int active_closing; - /** アイドル状態から HELLO 送信までの秒数。0以下は無効。*/ + /** + * delay between transition to idle state and sending HELLO in seconds. + * invalid if less than or equal to zero. + */ int hello_interval; - /** HELLO のタイムアウト */ + /** HELLO timeout */ int hello_timeout; - /** HELLO 送出時刻 */ + /** time when the last HELLO packet was sent */ time_t hello_io_time; - /** 確立した call 数 */ + /** number of calls established */ int ncalls; int - /* L2TP Data Message でシーケンス番号を使うか */ + /** use sequence number in L2TP Data Message? */ data_use_seq:1, - /** HELLO の応答待ちかどうか */ + /** waiting to acknowledge HELLO? */ hello_wait_ack:1; } l2tp_ctrl; /** - * L2TP コールを示す型。 + * datatype represents a L2TP call */ typedef struct _l2tp_call { /** ID */ unsigned id; - /** 状態 */ + /** state */ int state; - /** 親コントロールコネクション */ + /** parent control connection */ l2tp_ctrl *ctrl; - /** バインドした {@link ::_npppd_ppp ppp} */ + /** bound {@link ::_npppd_ppp ppp} */ void *ppp; - /** セッション ID */ + /** session ID */ int session_id; - /** 先方のセッション ID */ + /** peer's session ID */ int peer_session_id; - /** 次の送信シーケンス番号 */ + /** next sequence number */ uint16_t snd_nxt; - /** 受信シーケンス番号 */ + /** receiving sequence number */ uint16_t rcv_nxt; - /** Calling number */ + /** calling number */ char calling_number[32]; uint32_t /** Sequencing required */ diff --git a/usr.sbin/npppd/l2tp/l2tp_call.c b/usr.sbin/npppd/l2tp/l2tp_call.c index 1654681bc8d..03e7d550cea 100644 --- a/usr.sbin/npppd/l2tp/l2tp_call.c +++ b/usr.sbin/npppd/l2tp/l2tp_call.c @@ -1,3 +1,4 @@ +/* $OpenBSD: l2tp_call.c,v 1.4 2010/07/01 03:38:17 yasuoka Exp $ */ /*- * Copyright (c) 2009 Internet Initiative Japan Inc. * All rights reserved. @@ -23,10 +24,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ -/* $Id: l2tp_call.c,v 1.3 2010/01/27 07:27:02 yasuoka Exp $ */ -/**@file - * L2TP LNS のコールの実装。 - */ +/* $Id: l2tp_call.c,v 1.4 2010/07/01 03:38:17 yasuoka Exp $ */ +/**@file L2TP LNS call */ #include <sys/types.h> #include <sys/param.h> #include <sys/socket.h> @@ -40,6 +39,7 @@ #include <stdarg.h> #include <unistd.h> #include <event.h> +#include <net/if_dl.h> #include "debugutil.h" #include "bytebuf.h" @@ -48,12 +48,7 @@ #include "l2tp.h" #include "l2tp_subr.h" -#ifndef L2TPD_TEST -#include <net/if_dl.h> #include "npppd.h" -#else -typedef struct _dialin_proxy_info { } dialin_proxy_info; -#endif #include "l2tp_local.h" #ifdef L2TP_CALL_DEBUG @@ -77,11 +72,13 @@ static int l2tp_call_bind_ppp (l2tp_call *, dialin_proxy_info *); static void l2tp_call_notify_down (l2tp_call *); static int l2tp_call_send_data_packet (l2tp_call *, bytebuffer *); +static int l2tp_call_ppp_output (npppd_ppp *, unsigned char *, int, int); +static void l2tp_call_closed_by_ppp (npppd_ppp *); -/** l2tp_call の ID番号のシーケンス番号 */ +/* l2tp_call ID sequence # */ static unsigned l2tp_call_id_seq = 0; -/** {@link ::_l2tp_call L2TP コール} インスタンスを生成します。*/ +/* create {@link ::_l2tp_call L2TP call} instance */ l2tp_call * l2tp_call_create(void) { @@ -93,7 +90,7 @@ l2tp_call_create(void) return _this; } -/** {@link ::_l2tp_call L2TP コール} インスタンスを初期化します。 */ +/* initialize {@link ::_l2tp_call L2TP call} instance */ void l2tp_call_init(l2tp_call *_this, l2tp_ctrl *ctrl) { @@ -104,7 +101,7 @@ l2tp_call_init(l2tp_call *_this, l2tp_ctrl *ctrl) _this->use_seq = ctrl->data_use_seq; } -/** このインスタンスを解放します。 */ +/* free {@link ::_l2tp_call L2TP call} instance */ void l2tp_call_destroy(l2tp_call *_this, int from_l2tp_ctrl) { @@ -112,13 +109,13 @@ l2tp_call_destroy(l2tp_call *_this, int from_l2tp_ctrl) } /* - * 切断について - * a) npppdctl (vdipwho) から切断要求があった。 - * ppp_stop() で切断します。→ PPP LCP TermReq - * b) npppd が終了する、あるいは設定変更により l2tp.enabled = false - * l2tp_call_disconnect() で切断します。→ L2TP CDN + * l2tp disconnect will occur when + * 1) disconnect request issued from nppdctl command + * 2) npppd is terminated + * in case 1) ppp_stop() is used to terminal. (PPP LCP TermReq) + * and in case 2) l2tp_call_disconnect() is used (L2TP CDN) */ -/** 管理上の理由から切断します。 */ +/* administrative reason disconnection */ void l2tp_call_admin_disconnect(l2tp_call *_this) { @@ -126,10 +123,9 @@ l2tp_call_admin_disconnect(l2tp_call *_this) NULL, NULL, 0); } -/** - * 切断します。 - * @param result_code CDN を送信せずに切断(解放)する場合には、0 を指定 - * します。 +/* + * disconnect l2tp connection + * @param result_code disconect without CDN, specify zero */ static void l2tp_call_disconnect(l2tp_call *_this, int result_code, int error_code, @@ -138,8 +134,8 @@ l2tp_call_disconnect(l2tp_call *_this, int result_code, int error_code, L2TP_CALL_ASSERT(_this != NULL); if (_this->state == L2TP_CALL_STATE_CLEANUP_WAIT) { - // 既に CDN を受信、または送信済み - l2tp_call_notify_down(_this); // ねんのため + /* CDN received, or have been sent */ + l2tp_call_notify_down(_this); /* just in case */ return; } if (result_code > 0) { @@ -152,10 +148,11 @@ l2tp_call_disconnect(l2tp_call *_this, int result_code, int error_code, l2tp_call_notify_down(_this); } -/************************************************************************ - * 制御パケットの送受信 - ************************************************************************/ -/** 制御パケットが入力された時に呼び出します。 */ +/* + * control packet + */ + +/* call it when control packet is recieved */ int l2tp_call_recv_packet(l2tp_ctrl *ctrl, l2tp_call *_this, int mestype, u_char *pkt, int pktlen) @@ -164,7 +161,7 @@ l2tp_call_recv_packet(l2tp_ctrl *ctrl, l2tp_call *_this, int mestype, l2tp_call *call; dialin_proxy_info dpi; - // ICRQ の時だけ、_this == NULL + /* when ICRQ, this will be NULL */ L2TP_CALL_ASSERT(_this != NULL || mestype == L2TP_AVP_MESSAGE_TYPE_ICRQ); @@ -184,7 +181,7 @@ l2tp_call_recv_packet(l2tp_ctrl *ctrl, l2tp_call *_this, int mestype, len = slist_length(&ctrl->call_list); session_id = _this->id; again: - /* セッションIDの割り当て */ + /* assign a session ID */ session_id &= 0xffff; if (session_id == 0) session_id = 1; @@ -197,7 +194,7 @@ l2tp_call_recv_packet(l2tp_ctrl *ctrl, l2tp_call *_this, int mestype, } _this->session_id = session_id; - /* この l2tp_call をリストに追加。 */ + /* add the l2tp_call to call list */ slist_add(&_this->ctrl->call_list, _this); if (l2tp_call_send_ICRP(_this) != 0) @@ -206,7 +203,7 @@ l2tp_call_recv_packet(l2tp_ctrl *ctrl, l2tp_call *_this, int mestype, return 0; } - /* ステートマシン */ + /* state machine */ send_cdn = 0; switch (_this->state) { default: @@ -225,7 +222,7 @@ l2tp_call_recv_packet(l2tp_ctrl *ctrl, l2tp_call *_this, int mestype, case L2TP_AVP_MESSAGE_TYPE_ICRQ: case L2TP_AVP_MESSAGE_TYPE_ICRP: send_cdn = 1; - // FALL THROUGH + /* FALLTHROUGH */ default: l2tp_call_log(_this, LOG_ERR, "Waiting ICCN. But received %s", @@ -242,9 +239,7 @@ l2tp_call_recv_packet(l2tp_ctrl *ctrl, l2tp_call *_this, int mestype, case L2TP_CALL_STATE_ESTABLISHED: switch (mestype) { case L2TP_AVP_MESSAGE_TYPE_CDN: - /* - * peer からの切断。ログに残す - */ + /* disconnect from peer. log it */ l2tp_recv_CDN(_this, pkt, pktlen); _this->state = L2TP_CALL_STATE_CLEANUP_WAIT; l2tp_call_notify_down(_this); @@ -276,12 +271,12 @@ l2tp_call_recv_packet(l2tp_ctrl *ctrl, l2tp_call *_this, int mestype, l2tp_call_disconnect(_this, 0, 0, NULL, NULL, 0); return 1; } -/** - * ICRQ受信 - * @return acceptable な ICRQ の場合には、0 を返します。 - * 失敗した場合には、0 以外を返し、CDN は送信済みで、ステータス - * も変更済みです。 - */ +/* + * receieve ICRQ + * @return return 0 if the ICRQ is acceptable. + * other values means fail to receive, and + * CDN was sent and status was updated. + */ static int l2tp_call_recv_ICRQ(l2tp_call *_this, u_char *pkt, int pktlen) { @@ -326,9 +321,10 @@ l2tp_call_recv_ICRQ(l2tp_call *_this, u_char *pkt, int pktlen) case L2TP_AVP_TYPE_BEARER_TYPE: case L2TP_AVP_TYPE_PHYSICAL_CHANNEL_ID: /* - * Windows 98/Me/NT の MS "L2TP/IPsec VPN Client" - * では Physical Channel Id は mandatory ビットがたって - * いる。 + * Memo: + * Microsoft "L2TP/IPsec VPN Client" for + * Windows 98/Me/NT asserts mandatory bit in + * Physical Channel Id */ case L2TP_AVP_TYPE_CALLING_NUMBER: slen = MIN(sizeof(_this->calling_number) - 1, @@ -338,7 +334,6 @@ l2tp_call_recv_ICRQ(l2tp_call *_this, u_char *pkt, int pktlen) break; case L2TP_AVP_TYPE_CALLED_NUMBER: case L2TP_AVP_TYPE_SUB_ADDRESS: - // 使い途あれば。 continue; default: if (avp->is_mandatory) { @@ -384,7 +379,7 @@ size_check_failed: return 1; } -/** ICRP 送信 */ +/* send ICRP */ static int l2tp_call_send_ICRP(l2tp_call *_this) { @@ -423,7 +418,7 @@ l2tp_call_send_ICRP(l2tp_call *_this) return 0; } -/** L2TP data messageを送信します。*/ +/* send L2TP data message */ static int l2tp_call_send_data_packet(l2tp_call *_this, bytebuffer *buffer) { @@ -432,7 +427,7 @@ l2tp_call_send_data_packet(l2tp_call *_this, bytebuffer *buffer) bytebuffer_flip(buffer); hdr = (struct l2tp_header *)bytebuffer_pointer(buffer); - memset(hdr, 0, sizeof(*hdr) - 4); /* Nr, Ns はオプション */ + memset(hdr, 0, sizeof(*hdr) - 4); /* Nr, NS are option */ hdr->t = 0; hdr->ver = L2TP_HEADER_VERSION_RFC2661; @@ -461,10 +456,11 @@ l2tp_call_send_data_packet(l2tp_call *_this, bytebuffer *buffer) return (rval == bytebuffer_remaining(buffer))? 0 : 1; } -/** - * ICCN 受信 - * @return acceptable な ICCN の場合には、0 を返します。失敗した場合には、0 - * 以外を返し、CDN は送信済みで、ステータスも変更済みです。 +/* + * receive ICCN + * @return return 0 if the ICCN is acceptable. + * other value means fail to receive, and + * CDN was sent and status was updated. */ static int l2tp_call_recv_ICCN(l2tp_call *_this, u_char *pkt, int pktlen, @@ -608,7 +604,7 @@ size_check_failed: return 1; } -/** CDN 受信 */ +/* receive CDN */ static int l2tp_recv_CDN(l2tp_call *_this, u_char *pkt, int pktlen) { @@ -616,7 +612,7 @@ l2tp_recv_CDN(l2tp_call *_this, u_char *pkt, int pktlen) struct l2tp_avp *avp; char buf[L2TP_AVP_MAXSIZ], emes[256], pmes[256]; - /* 初期化 */ + /* initialize */ result = 0; error = 0; sessid = 0; @@ -707,13 +703,13 @@ l2tp_recv_CDN(l2tp_call *_this, u_char *pkt, int pktlen) return 0; size_check_failed: - // CDN のメッセージがおかしくても、続行 + /* continue to process even if the CDN message was broken */ l2tp_call_log(_this, LOG_ERR, "Received bad CDN: %s", emes); return 0; } -/** CDN 送信 */ +/* send CDN */ static int l2tp_call_send_CDN(l2tp_call *_this, int result_code, int error_code, const char *errmes, struct l2tp_avp *addavp[], int naddavp) @@ -745,8 +741,10 @@ l2tp_call_send_CDN(l2tp_call *_this, int result_code, int error_code, const avp->attr_type = L2TP_AVP_TYPE_RESULT_CODE; #if 0 /* - * エラーコード無しの長さ 8 の AVP を送信すると、Windows 2000 側が StopCCN で - * "2 - Length is wrong" を返してくる。長さ10にして回避。 + * Windows 2000 work around: + * Windows 2000 will return "2 - Length is wrong" in StopCCN, + * when it received "length = 8 and no error code AVP". + * Avoid the error, use AVP length = 10. */ if (error_code > 0) { val32 = (result_code << 16) | (error_code & 0xffff); @@ -802,7 +800,7 @@ l2tp_call_send_CDN(l2tp_call *_this, int result_code, int error_code, const return 0; } -/** ZLB の送信 */ +/* send ZLB */ static int l2tp_call_send_ZLB(l2tp_call *_this) { @@ -818,10 +816,10 @@ l2tp_call_send_ZLB(l2tp_call *_this) bytebuf, 1); } -/************************************************************************ - * その他 - ************************************************************************/ -/** このインスタンスに基づいたラベルから始まるログを記録します。 */ +/* + * misc + */ +/* logging with the label of the instance */ static void l2tp_call_log(l2tp_call *_this, int prio, const char *fmt, ...) { @@ -840,7 +838,7 @@ l2tp_call_log(l2tp_call *_this, int prio, const char *fmt, ...) va_end(ap); } -/** 現在のステータスの文字列表現を返します。 */ +/* convert current status to strings */ static inline const char * l2tp_call_state_string(l2tp_call *_this) { @@ -853,33 +851,11 @@ l2tp_call_state_string(l2tp_call *_this) return "unknown"; } +/* + * npppd physical layer + */ -#ifdef L2TPD_TEST - -void -l2tp_call_ppp_input(l2tp_call *_this, u_char *pkt, int pktlen) -{ -} -static int -l2tp_call_bind_ppp(l2tp_call *_this, dialin_proxy_info *dpi) -{ - return 0; -} -static void -l2tp_call_notify_down(l2tp_call *_this) -{ -} - -#else -/************************************************************************ - * npppd の物理層として - ************************************************************************/ -#include "npppd.h" - -static int l2tp_call_ppp_output (npppd_ppp *, unsigned char *, int, int); -static void l2tp_call_closed_by_ppp (npppd_ppp *); - -/** ppp にパケットを入力します。 */ +/* input packet to ppp */ void l2tp_call_ppp_input(l2tp_call *_this, u_char *pkt, int pktlen) { @@ -900,7 +876,7 @@ l2tp_call_ppp_input(l2tp_call *_this, u_char *pkt, int pktlen) } } -/** ppp からパケットが出力される時に呼び出されます。 */ +/* called ppp output a packet */ static int l2tp_call_ppp_output(npppd_ppp *ppp, unsigned char *bytes, int nbytes, int flags) @@ -926,7 +902,7 @@ l2tp_call_ppp_output(npppd_ppp *ppp, unsigned char *bytes, int nbytes, return 0; } -/** ppp で切断された場合に呼び出されます。 */ +/* it will be called when the connection was closed at ppp */ static void l2tp_call_closed_by_ppp(npppd_ppp *ppp) { @@ -937,7 +913,8 @@ l2tp_call_closed_by_ppp(npppd_ppp *ppp) _this = ppp->phy_context; - _this->ppp = NULL; // l2tp_call_disconnect より先に。 + /* do before l2tp_call_disconnect() */ + _this->ppp = NULL; if (_this->state == L2TP_CALL_STATE_CLEANUP_WAIT) { /* no need to call l2tp_call_disconnect */ @@ -980,7 +957,7 @@ l2tp_call_closed_by_ppp(npppd_ppp *ppp) l2tp_call_log(_this, LOG_NOTICE, "logtype=PPPUnbind"); } -/** ppp に切断した旨を通知し ppp の終了/解放を行います。 */ +/* notify disconnection to ppp to terminate or free of ppp */ static void l2tp_call_notify_down(l2tp_call *_this) { @@ -988,7 +965,7 @@ l2tp_call_notify_down(l2tp_call *_this) ppp_phy_downed(_this->ppp); } -/** ppp の bind。 */ +/* bind ppp */ static int l2tp_call_bind_ppp(l2tp_call *_this, dialin_proxy_info *dpi) { @@ -999,7 +976,7 @@ l2tp_call_bind_ppp(l2tp_call *_this, dialin_proxy_info *dpi) errcode = 0; ppp = NULL; if ((ppp = ppp_create()) == NULL) - goto reigai; + goto fail; ASSERT(_this->ppp == NULL); @@ -1021,7 +998,7 @@ l2tp_call_bind_ppp(l2tp_call *_this, dialin_proxy_info *dpi) sizeof(ppp->calling_number)); if (ppp_init(npppd_get_npppd(), ppp) != 0) { l2tp_call_log(_this, LOG_ERR, "failed binding ppp"); - goto reigai; + goto fail; } l2tp_call_log(_this, LOG_NOTICE, "logtype=PPPBind ppp=%d", ppp->id); @@ -1032,18 +1009,18 @@ l2tp_call_bind_ppp(l2tp_call *_this, dialin_proxy_info *dpi) "'accept_dialin' is 'false' in the setting."); code = L2TP_CDN_RCODE_ERROR_CODE; errcode = L2TP_ECODE_INVALID_MESSAGE; - goto reigai; + goto fail; } if (ppp_dialin_proxy_prepare(ppp, dpi) != 0) { code = L2TP_CDN_RCODE_TEMP_NOT_AVALIABLE; - goto reigai; + goto fail; } } ppp_start(ppp); return 0; -reigai: +fail: if (ppp != NULL) ppp_destroy(ppp); _this->ppp = NULL; @@ -1051,4 +1028,3 @@ reigai: l2tp_call_disconnect(_this, code, 0, NULL, NULL, 0); return 1; } -#endif diff --git a/usr.sbin/npppd/l2tp/l2tp_ctrl.c b/usr.sbin/npppd/l2tp/l2tp_ctrl.c index a7517b9f146..79bd0239981 100644 --- a/usr.sbin/npppd/l2tp/l2tp_ctrl.c +++ b/usr.sbin/npppd/l2tp/l2tp_ctrl.c @@ -1,3 +1,4 @@ +/* $OpenBSD: l2tp_ctrl.c,v 1.3 2010/07/01 03:38:17 yasuoka Exp $ */ /*- * Copyright (c) 2009 Internet Initiative Japan Inc. * All rights reserved. @@ -23,10 +24,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ -/**@file - * L2TP LNS のコントロールコネクションの処理を提供します。 - */ -// $Id: l2tp_ctrl.c,v 1.2 2010/01/13 07:49:44 yasuoka Exp $ +/**@file Control connection processing functions for L2TP LNS */ +/* $Id: l2tp_ctrl.c,v 1.3 2010/07/01 03:38:17 yasuoka Exp $ */ #include <sys/types.h> #include <sys/param.h> #include <sys/time.h> @@ -92,14 +91,14 @@ static inline const char *l2tp_ctrl_state_string (l2tp_ctrl *); #define L2TP_CTRL_DBG(x) #endif -/** l2tp_ctrl の ID番号のシーケンス番号 */ +/* Sequence # of l2tp_ctrl ID */ static unsigned l2tp_ctrl_id_seq = 0; #define SEQ_LT(a,b) ((int16_t)((a) - (b)) < 0) #define SEQ_GT(a,b) ((int16_t)((a) - (b)) > 0) /** - * {@link ::_l2tp_ctrl L2TP LNS コントロールコネクション}のインスタンス生成 + * Build instance of {@link ::_l2tp_ctrl L2TP LNS control connection} */ l2tp_ctrl * l2tp_ctrl_create(void) @@ -114,8 +113,8 @@ l2tp_ctrl_create(void) } /** - * {@link ::_l2tp_ctrl L2TP LNS コントロールコネクション}のインスタンスの - * 初期化と開始を行います。 + * initialize and startup of {@link ::_l2tp_ctrl L2TP LNS control connection} + * instance */ static int l2tp_ctrl_init(l2tp_ctrl *_this, l2tpd *_l2tpd, struct sockaddr *peer, @@ -133,9 +132,8 @@ l2tp_ctrl_init(l2tp_ctrl *_this, l2tpd *_l2tpd, struct sockaddr *peer, _this->last_snd_ctrl = curr_time; slist_init(&_this->call_list); - /* - * 空いているトンネルIDを探す - */ + + /* seek a free tunnel ID */ i = 0; _this->id = ++l2tp_ctrl_id_seq; for (i = 0, tunid = _this->id; ; i++, tunid++) { @@ -146,7 +144,7 @@ l2tp_ctrl_init(l2tp_ctrl *_this, l2tpd *_l2tpd, struct sockaddr *peer, if (l2tpd_get_ctrl(_l2tpd, tunid) == NULL) break; if (i > 80000) { - // バグに違いない + /* this must be happen, just log it. */ l2tpd_log(_l2tpd, LOG_ERR, "Too many l2tp controls"); return -1; } @@ -159,19 +157,19 @@ l2tp_ctrl_init(l2tp_ctrl *_this, l2tpd *_l2tpd, struct sockaddr *peer, memcpy(&_this->peer, peer, peer->sa_len); memcpy(&_this->sock, sock, sock->sa_len); - /* 送信バッファの準備 */ + /* prepare send buffer */ _this->winsz = L2TPD_DEFAULT_SEND_WINSZ; if ((_this->snd_buffers = calloc(_this->winsz, sizeof(bytebuffer *))) == NULL) { l2tpd_log(_l2tpd, LOG_ERR, "calloc() failed in %s(): %m", __func__); - goto reigai; + goto fail; } for (i = 0; i < _this->winsz; i++) { if ((bytebuf = bytebuffer_create(L2TPD_SND_BUFSIZ)) == NULL) { l2tpd_log(_l2tpd, LOG_ERR, "bytebuffer_create() failed in %s(): %m", __func__); - goto reigai; + goto fail; } _this->snd_buffers[i] = bytebuf; } @@ -179,7 +177,7 @@ l2tp_ctrl_init(l2tp_ctrl *_this, l2tpd *_l2tpd, struct sockaddr *peer, + 128)) == NULL) { l2tpd_log(_l2tpd, LOG_ERR, "bytebuffer_create() failed in %s(): %m", __func__); - goto reigai; + goto fail; } #ifdef USE_LIBSOCKUTIL if (nat_t_ctx != NULL) { @@ -190,7 +188,7 @@ l2tp_ctrl_init(l2tp_ctrl *_this, l2tpd *_l2tpd, struct sockaddr *peer, } else { l2tpd_log(_l2tpd, LOG_ERR, "creating sa_cookie failed: %m"); - goto reigai; + goto fail; } } #endif @@ -198,20 +196,19 @@ l2tp_ctrl_init(l2tp_ctrl *_this, l2tpd *_l2tpd, struct sockaddr *peer, _this->hello_timeout = L2TP_CTRL_DEFAULT_HELLO_TIMEOUT; _this->hello_io_time = curr_time; - /* タイマーのセット */ + /* initialize timeout timer */ l2tp_ctrl_reset_timeout(_this); - /* 登録 */ + /* register l2tp context */ l2tpd_add_ctrl(_l2tpd, _this); return 0; -reigai: +fail: l2tp_ctrl_stop(_this, 0); return -1; } -/** - * {@link ::_l2tp_ctrl L2TP LNS コントロールコネクション} のインスタンスの - * 設定を行います。 +/* + * setup {@link ::_l2tp_ctrl L2TP LNS control connection} instance */ static void l2tp_ctrl_reload(l2tp_ctrl *_this) @@ -229,9 +226,8 @@ l2tp_ctrl_reload(l2tp_ctrl *_this) return; } -/** - * {@link ::_l2tp_ctrl L2TP LNS コントロールコネクション}のインスタンスを解放 - * します。 +/* + * free {@link ::_l2tp_ctrl L2TP LNS control connection} instance */ void l2tp_ctrl_destroy(l2tp_ctrl *_this) @@ -244,12 +240,13 @@ l2tp_ctrl_destroy(l2tp_ctrl *_this) free(_this); } -/** - * 切断を先方に通知します。 +/* + * nortify disconnection to peer * - * @return CDN、StopCCN を送信済みの場合には 0。CDN を送信できていない - * コールが存在する場合にはその数、StopCCN の送信に失敗した場合 - * -1 が返ります。 + * @return 0: all CDN and StopCCN have been sent. + * N: if the remaining calls which still not sent CDN exist, + * return # of the calls. + * -1: when try to send of StopCCN failed. */ static int l2tp_ctrl_send_disconnect_notify(l2tp_ctrl *_this) @@ -260,19 +257,18 @@ l2tp_ctrl_send_disconnect_notify(l2tp_ctrl *_this) L2TP_CTRL_ASSERT(_this->state == L2TP_CTRL_STATE_ESTABLISHED || _this->state == L2TP_CTRL_STATE_CLEANUP_WAIT); - // アクティブじゃなかったり、StopCCN を送信済み。 + /* the contexts is not active or StopCCN have been sent */ if (_this->active_closing == 0) return 0; - // すべての Call に CDN + /* CDN have been sent for all Calls */ ncalls = 0; if (slist_length(&_this->call_list) != 0) { ncalls = l2tp_ctrl_disconnect_all_calls(_this); if (ncalls > 0) { - /* - * 送信 Window が埋まっているかどうかを検査するために - * 再度呼び出す。ゼロになれば、すべての call に CDN を - * 送信し終わった。 + /* + * Call l2tp_ctrl_disconnect_all_calls() to check + * the send window still filled. */ ncalls = l2tp_ctrl_disconnect_all_calls(_this); } @@ -287,19 +283,21 @@ l2tp_ctrl_send_disconnect_notify(l2tp_ctrl *_this) return 0; } -/** - * コントロールコネクションを終了します。 +/* + * Terminate the control connection * * <p> - * アクティブクローズの (StopCCN を送信する) 場合には、StopCCN の - * ResultCode AVP ように result に 1 以上の適切な値を指定してください。</p> + * please spcify an appropriate value to result( >0 ) for + * StopCCN ResultCode AVP, when to sent Active Close (which + * require StopCCN sent).</p> * <p> - * 戻り値が 0 の場合、_this は解放されていますので、l2tp_ctrl の処理を - * 続行することはできません。また、1 の場合(解放されていない場合) は、 - * タイマはリセットされています。</p> + * When the return value of this function is zero, the _this + * is already released. The lt2p_ctrl process that was bound to it + * could not contine. + * When the return value of this function is one, the timer + * is reset.</p> * - * @return 完全に終了した場合には 0 を、まだ完全に終了していない場合 - * には、0 以外を返します。 + * @return return 0 if terminate process was completed. */ int l2tp_ctrl_stop(l2tp_ctrl *_this, int result) @@ -321,9 +319,9 @@ l2tp_ctrl_stop(l2tp_ctrl *_this, int result) default: l2tp_ctrl_log(_this, LOG_DEBUG, "%s() unexpected state=%s", __func__, l2tp_ctrl_state_string(_this)); - // FALL THROUGH; + /* FALLTHROUGH */ case L2TP_CTRL_STATE_WAIT_CTL_CONN: - // FALL THROUGH; + /* FALLTHROUGH */ case L2TP_CTRL_STATE_CLEANUP_WAIT: cleanup: if (slist_length(&_this->call_list) != 0) { @@ -339,7 +337,7 @@ cleanup: evtimer_del(&_this->ev_timeout); - /* 送信バッファの解放 */ + /* free send buffer */ if (_this->snd_buffers != NULL) { for (i = 0; i < _this->winsz; i++) bytebuffer_destroy(_this->snd_buffers[i]); @@ -350,7 +348,8 @@ cleanup: bytebuffer_destroy(_this->zlb_buffer); _this->zlb_buffer = NULL; } - /* l2tp_call の解放 */ + + /* free l2tp_call */ l2tp_ctrl_destroy_all_calls(_this); slist_fini(&_this->call_list); @@ -360,7 +359,7 @@ cleanup: l2tp_ctrl_destroy(_this); l2tpd_ctrl_finished_notify(_l2tpd); - return 0; // stopped + return 0; /* stopped */ } l2tp_ctrl_reset_timeout(_this); @@ -459,7 +458,7 @@ l2tp_ctrl_purge_ipsec_sa(l2tp_ctrl *_this) } #endif -/** タイマー関連処理 */ +/* timeout processing */ static void l2tp_ctrl_timeout(int fd, short evtype, void *ctx) { @@ -468,10 +467,10 @@ l2tp_ctrl_timeout(int fd, short evtype, void *ctx) l2tp_ctrl *_this; l2tp_call *call; - /* - * この関数から抜ける場合は、タイマをリセットしなければならない。 - * l2tp_ctrl_stop は、l2tp_ctrl_stop 内でタイマをリセットする。 - * l2tp_ctrl_stop は、_this を解放する可能性がある点にも注意。 + /* + * the timer must be reset, when leave this function. + * MEMO: l2tp_ctrl_stop() will reset the timer in it. + * and please remember that the l2tp_ctrl_stop() may free _this. */ _this = ctx; L2TP_CTRL_ASSERT(_this != NULL); @@ -484,7 +483,7 @@ l2tp_ctrl_timeout(int fd, short evtype, void *ctx) if (l2tp_ctrl_txwin_size(_this) > 0) { if (_this->state == L2TP_CTRL_STATE_ESTABLISHED) { if (_this->hello_wait_ack != 0) { - /* Hello 応答待ち */ + /* wait Hello reply */ if (curr_time - _this->hello_io_time >= _this->hello_timeout) { l2tp_ctrl_log(_this, LOG_NOTICE, @@ -518,8 +517,8 @@ l2tp_ctrl_timeout(int fd, short evtype, void *ctx) switch (_this->state) { case L2TP_CTRL_STATE_IDLE: /* - * idle の場合 - * この実装ではあり得ない。 + * idle: + * XXX: never happen in current implementation */ l2tp_ctrl_log(_this, LOG_ERR, "Internal error, timeout on illegal state=idle"); @@ -527,10 +526,11 @@ l2tp_ctrl_timeout(int fd, short evtype, void *ctx) break; case L2TP_CTRL_STATE_WAIT_CTL_CONN: /* - * wait-ctrl-conn の場合 - * SCCRP に対する確認応答がない場合は、先方は SCCRQ - * を再送するが、この実装側で「再送」であることを検知 - * できない。こちらからは再送しない。 + * wait-ctrl-conn: + * if there is no ack for SCCRP, the peer will + * resend SCCRQ. however this implementation can + * not recognize that the SCCRQ was resent or not. + * Therefore, never resent from this side. */ need_resend = 0; break; @@ -539,7 +539,7 @@ l2tp_ctrl_timeout(int fd, short evtype, void *ctx) curr_time - _this->last_snd_ctrl >= L2TP_CTRL_WAIT_CALL_TIMEOUT) { if (_this->ncalls == 0) - /* 最初の call がこない。 */ + /* fail to recieve first call */ l2tp_ctrl_log(_this, LOG_WARNING, "timeout waiting call"); l2tp_ctrl_stop(_this, @@ -547,13 +547,11 @@ l2tp_ctrl_timeout(int fd, short evtype, void *ctx) return; } if (_this->hello_wait_ack == 0 && _this->hello_interval > 0) { - /* - * Hello 送信 - */ + /* send Hello */ if (curr_time - _this->hello_interval >= _this->hello_io_time) { if (l2tp_ctrl_send_HELLO(_this) == 0) - /* 成功した場合 */ + /* success */ _this->hello_wait_ack = 1; _this->hello_io_time = curr_time; need_resend = 0; @@ -578,7 +576,7 @@ l2tp_ctrl_timeout(int fd, short evtype, void *ctx) l2tp_ctrl_stop(_this, L2TP_STOP_CCN_RCODE_GENERAL); return; } - /* 再送の必要があれば、再送 */ + /* resend if required */ if (need_resend) l2tp_ctrl_resend_una_packets(_this); l2tp_ctrl_reset_timeout(_this); @@ -605,7 +603,7 @@ l2tp_ctrl_send(l2tp_ctrl *_this, const void *msg, int len) return rval; } -/** 確認応答待ちのパケットを再送する。 */ +/* resend una packets */ static int l2tp_ctrl_resend_una_packets(l2tp_ctrl *_this) { @@ -639,9 +637,7 @@ l2tp_ctrl_resend_una_packets(l2tp_ctrl *_this) return nsend; } -/** - * すべてのコールを解放します。 - */ +/* free all calls */ static void l2tp_ctrl_destroy_all_calls(l2tp_ctrl *_this) { @@ -653,9 +649,9 @@ l2tp_ctrl_destroy_all_calls(l2tp_ctrl *_this) l2tp_call_destroy(call, 1); } -/** - * このコントロールの全ての call を切断します。 - * @return 解放待ちになっていない call の数を返します。 + +/* disconnect all calls on the control context + * @return return # of calls that is not waiting cleanup. */ static int l2tp_ctrl_disconnect_all_calls(l2tp_ctrl *_this) @@ -684,9 +680,7 @@ l2tp_ctrl_disconnect_all_calls(l2tp_ctrl *_this) return ncalls; } -/** - * タイムアウトを再設定します。 - */ +/* reset timeout */ static void l2tp_ctrl_reset_timeout(l2tp_ctrl *_this) { @@ -713,12 +707,10 @@ l2tp_ctrl_reset_timeout(l2tp_ctrl *_this) evtimer_add(&_this->ev_timeout, &tv0); } -/*********************************************************************** - * プロトコル - 送受信 - ***********************************************************************/ -/** - * パケット受信 +/* + * protocols / send and receive */ +/* Recieve packet */ void l2tp_ctrl_input(l2tpd *_this, int listener_index, struct sockaddr *peer, struct sockaddr *sock, void *nat_t_ctx, u_char *pkt, int pktlen) @@ -746,7 +738,7 @@ l2tp_ctrl_input(l2tpd *_this, int listener_index, struct sockaddr *peer, l2tpd_log(_this, LOG_ERR, "Received a packet peer unknown address " "family=%d", peer->sa_family); - return; // ここまでは reigai に飛ばさない + return; } peersin = (struct sockaddr_in *)peer; socksin = (struct sockaddr_in *)sock; @@ -763,7 +755,7 @@ l2tp_ctrl_input(l2tpd *_this, int listener_index, struct sockaddr *peer, memcpy(&hdr, pkt, 2); pkt += 2; if (hdr.ver != L2TP_HEADER_VERSION_RFC2661) { - /* 現在 RFC2661 のみサポートします */ + /* XXX: only RFC2661 is supported */ snprintf(errmsg, sizeof(errmsg), "Unsupported version at header = %d", hdr.ver); goto bad_packet; @@ -824,7 +816,7 @@ l2tp_ctrl_input(l2tpd *_this, int listener_index, struct sockaddr *peer, ctrl = l2tpd_get_ctrl(_this, hdr.tunnel_id); if (ctrl == NULL) { - /* 新しいコントロール */ + /* new control */ if (!is_ctrl) { snprintf(errmsg, sizeof(errmsg), "bad data message: tunnelId=%d is not " @@ -847,7 +839,7 @@ l2tp_ctrl_input(l2tpd *_this, int listener_index, struct sockaddr *peer, l2tpd_log_access_deny(_this, "could not get interface informations", peer); - goto reigai; + goto fail; } if (l2tpd_config_str_equal(_this, config_key_prefix("l2tpd.interface", ifname), @@ -858,23 +850,23 @@ l2tp_ctrl_input(l2tpd *_this, int listener_index, struct sockaddr *peer, config_key_prefix("l2tpd.interface", "any"), "accept", 0)){ } else { - /* このインタフェースは許可されていない。*/ + /* the interface is not permited */ snprintf(errmsg, sizeof(errmsg), "'%s' is not allowed by config.", ifname); l2tpd_log_access_deny(_this, errmsg, peer); - goto reigai; + goto fail; } } if ((ctrl = l2tp_ctrl_create()) == NULL) { l2tp_ctrl_log(ctrl, LOG_ERR, "l2tp_ctrl_create() failed: %m"); - goto reigai; + goto fail; } if (l2tp_ctrl_init(ctrl, _this, peer, sock, nat_t_ctx) != 0) { l2tp_ctrl_log(ctrl, LOG_ERR, "l2tp_ctrl_start() failed: %m"); - goto reigai; + goto fail; } ctrl->listener_index = listener_index; @@ -882,8 +874,8 @@ l2tp_ctrl_input(l2tpd *_this, int listener_index, struct sockaddr *peer, l2tp_ctrl_reload(ctrl); } else { /* - * 始点アドレス/ポートが異なる場合には、エラーとする。(DoS - * の可能性があるので) + * treat as an error if src address and port is not + * match. (because it is potentially DoS attach) */ L2TP_CTRL_ASSERT(ctrl->peer.ss_family == peer->sa_family); @@ -909,7 +901,8 @@ l2tp_ctrl_input(l2tpd *_this, int listener_index, struct sockaddr *peer, ctrl->last_rcv = curr_time; call = NULL; if (hdr.session_id != 0) { - /* Session Id から l2tp_call を探す。リニアサーチ */ + /* search l2tp_call by Session ID */ + /* linear search is enough for this purpose */ len = slist_length(&ctrl->call_list); for (i = 0; i < len; i++) { call = slist_get(&ctrl->call_list, i); @@ -919,20 +912,18 @@ l2tp_ctrl_input(l2tpd *_this, int listener_index, struct sockaddr *peer, } } if (!is_ctrl) { - /* - * L2TP データ - */ + /* L2TP data */ if (ctrl->state != L2TP_CTRL_STATE_ESTABLISHED) { l2tp_ctrl_log(ctrl, LOG_WARNING, "Received Data packet in '%s'", l2tp_ctrl_state_string(ctrl)); - goto reigai; + goto fail; } if (call == NULL) { l2tp_ctrl_log(ctrl, LOG_WARNING, "Received a data packet but it has no call. " "session_id=%u", hdr.session_id); - goto reigai; + goto fail; } L2TP_CTRL_DBG((ctrl, DEBUG_LEVEL_2, "call=%u RECV ns=%u nr=%u snd_nxt=%u rcv_nxt=%u len=%d", @@ -942,13 +933,13 @@ l2tp_ctrl_input(l2tpd *_this, int listener_index, struct sockaddr *peer, l2tp_ctrl_log(ctrl, LOG_WARNING, "Received a data packet but call is not " "established"); - goto reigai; + goto fail; } if (hdr.s != 0) { if (SEQ_LT(hdr.ns, call->rcv_nxt)) { - /* シーケンスが戻った。*/ - /* 統計情報に残すべきかもしれない */ + /* sequence number seems to rewind */ + /* XXX: need to log? */ L2TP_CTRL_DBG((ctrl, LOG_DEBUG, "receive a out of sequence data packet: " "%u < %u. ", hdr.ns, call->rcv_nxt)); @@ -978,15 +969,15 @@ l2tp_ctrl_input(l2tpd *_this, int listener_index, struct sockaddr *peer, "Received message has bad Nr field: " "%u < %u.", hdr.ns, ctrl->snd_nxt); /* XXX Drop with ZLB? */ - goto reigai; + goto fail; } } if (l2tp_ctrl_txwin_size(ctrl) <= 0) { - /* 確認応答待ちなし */ + /* no waiting ack */ if (ctrl->hello_wait_ack != 0) { /* - * Hello に対する Ack が返ったので、Hello - * の状態をリセット + * Reset Hello state, as an ack for the Hello + * is recived. */ ctrl->hello_wait_ack = 0; ctrl->hello_io_time = curr_time; @@ -998,13 +989,13 @@ l2tp_ctrl_input(l2tpd *_this, int listener_index, struct sockaddr *peer, } } if (hdr.ns != ctrl->rcv_nxt) { - // 受信してないパケットがある + /* there are remaining packet */ if (l2tp_ctrl_resend_una_packets(ctrl) <= 0) { - // 再送または ZLB 送信 + /* resend or sent ZLB */ l2tp_ctrl_send_ZLB(ctrl); } #ifdef L2TP_CTRL_DEBUG - if (pktlen != 0) { // ZLB ではない。 + if (pktlen != 0) { /* not ZLB */ L2TP_CTRL_DBG((ctrl, LOG_DEBUG, "receive out of sequence %u must be %u. " "mestype=%s", hdr.ns, ctrl->rcv_nxt, @@ -1028,12 +1019,12 @@ l2tp_ctrl_input(l2tpd *_this, int listener_index, struct sockaddr *peer, if (avp == NULL) { l2tpd_log(_this, LOG_WARNING, "bad control message: no message-type AVP."); - goto reigai; + goto fail; } } /* - * ステートマシン (RFC2661 pp. 56-57) + * state machine (RFC2661 pp. 56-57) */ switch (ctrl->state) { case L2TP_CTRL_STATE_IDLE: @@ -1041,28 +1032,28 @@ l2tp_ctrl_input(l2tpd *_this, int listener_index, struct sockaddr *peer, case L2TP_AVP_MESSAGE_TYPE_SCCRQ: if (l2tp_ctrl_recv_SCCRQ(ctrl, pkt, pktlen, _this, peer) == 0) { - // acceptable + /* acceptable */ l2tp_ctrl_send_SCCRP(ctrl); ctrl->state = L2TP_CTRL_STATE_WAIT_CTL_CONN; return; } /* - * un-accectable な場合は、l2tp_ctrl_recv_SCCRQ 側で - * 処理済みです。 + * in case un-acceptable, it was already processed + * at l2tcp_ctrl_recv_SCCRQ */ return; case L2TP_AVP_MESSAGE_TYPE_SCCRP: /* - * RFC上は StopCCN を送信するが、この LNS の実装では、 - * Passive Open だけなので、 このパケットは受け取らな - * いはず。 + * RFC specifies that sent of StopCCN in the state, + * However as this implementation only support Passive + * open, this packet will not recieved. */ - // FALL THROUGH + /* FALLTHROUGH */ case L2TP_AVP_MESSAGE_TYPE_SCCCN: default: break; } - goto fsm_reigai; + goto fsm_fail; case L2TP_CTRL_STATE_WAIT_CTL_CONN: /* Wait-Ctl-Conn */ @@ -1080,7 +1071,7 @@ l2tp_ctrl_input(l2tpd *_this, int listener_index, struct sockaddr *peer, default: break; } - break; /* fsm_reigai */ + break; /* fsm_fail */ case L2TP_CTRL_STATE_ESTABLISHED: /* Established */ switch (mestype) { @@ -1112,9 +1103,9 @@ receive_stop_ccn: l2tp_ctrl_log(ctrl, LOG_INFO, "Unknown call message: %s", avp_mes_type_string(mestype)); - goto reigai; + goto fail; } - // FALL THROUGH + /* FALLTHROUGH */ case L2TP_AVP_MESSAGE_TYPE_ICRQ: l2tp_call_recv_packet(ctrl, call, mestype, pkt, pktlen); @@ -1122,26 +1113,25 @@ receive_stop_ccn: default: break; } - break; /* fsm_reigai */ + break; /* fsm_fail */ case L2TP_CTRL_STATE_CLEANUP_WAIT: if (mestype == L2TP_AVP_MESSAGE_TYPE_StopCCN) { /* - * StopCCN が交錯したか、Window が埋まっていて - * StopCCN が送信できない間に、StopCCN を受信 + * We left ESTABLISHED state, but the peer sent StopCCN. */ goto receive_stop_ccn; } - break; /* fsm_reigai */ + break; /* fsm_fail */ } -fsm_reigai: - /* ステートマシンのエラー */ +fsm_fail: + /* state machine error */ l2tp_ctrl_log(ctrl, LOG_WARNING, "Received %s in '%s' state", avp_mes_type_string(mestype), l2tp_ctrl_state_string(ctrl)); l2tp_ctrl_stop(ctrl, L2TP_STOP_CCN_RCODE_FSM_ERROR); return; -reigai: +fail: if (ctrl != NULL && mestype != 0) { l2tp_ctrl_log(ctrl, LOG_WARNING, "Received %s in '%s' state", avp_mes_type_string(mestype), l2tp_ctrl_state_string(ctrl)); @@ -1173,7 +1163,7 @@ l2tp_ctrl_txwin_is_full(l2tp_ctrl *_this) return (l2tp_ctrl_txwin_size(_this) >= _this->winsz)? 1 : 0; } -/** パケットの送信 */ +/* send control packet */ int l2tp_ctrl_send_packet(l2tp_ctrl *_this, int call_id, bytebuffer *bytebuf, int is_ctrl) @@ -1232,8 +1222,8 @@ l2tp_ctrl_send_packet(l2tp_ctrl *_this, int call_id, bytebuffer *bytebuf, return (rval == bytebuffer_remaining(bytebuf))? 0 : 1; } -/** - * SCCRQ の受信 +/* + * receiver SCCRQ */ static int l2tp_ctrl_recv_SCCRQ(l2tp_ctrl *_this, u_char *pkt, int pktlen, l2tpd *_l2tpd, @@ -1293,8 +1283,8 @@ l2tp_ctrl_recv_SCCRQ(l2tp_ctrl *_this, u_char *pkt, int pktlen, l2tpd *_l2tpd, case L2TP_AVP_TYPE_TIE_BREAKER: AVP_SIZE_CHECK(avp, ==, 14); /* - * この実装からは SCCRQ は送らないので常に peer が - * winner。 + * As the implementation never send SCCRQ, + * the peer is always winner */ continue; case L2TP_AVP_TYPE_FIRMWARE_REVISION: @@ -1359,8 +1349,8 @@ size_check_failed: return 1; } -/** - * StopCCN を送信します。 +/* + * send StopCCN */ static int l2tp_ctrl_send_StopCCN(l2tp_ctrl *_this, int result) @@ -1406,8 +1396,8 @@ l2tp_ctrl_send_StopCCN(l2tp_ctrl *_this, int result) return 0; } -/** - * StopCCN の受信 +/* + * Receiver StopCCN */ static int l2tp_ctrl_recv_StopCCN(l2tp_ctrl *_this, u_char *pkt, int pktlen) @@ -1487,15 +1477,12 @@ l2tp_ctrl_recv_StopCCN(l2tp_ctrl *_this, u_char *pkt, int pktlen) if (rcode == L2TP_CDN_RCODE_ERROR_CODE && ecode == L2TP_ECODE_NO_RESOURCE) { /* - * 現在観測された状況 - * - * (1) IDGWとWindows が同一 LAN セグメント上にあり、 - * Windows の(そのLAN IP アドレスが、ナチュラルマスク - * で評価した場合のブロードキャストアドレスだった場合 - * (192.168.0.255/23など) - * (2) Windows 2000 を起動しっぱなしで、L2TPの接続切断を繰り - * 返すと、あるタイミングからこの状況に陥り、接続できない。 - * Windows が再起動するまで、問題は継続。 + * Memo: + * This state may be happen in following state. + * - lots of connect/disconect by long-running + * windows2000, sometimes it fall to this state. + * Once it fall to here, connection will fail till + * the windows rebooted */ l2tp_ctrl_log(_this, LOG_WARNING, "Peer indicates \"No Resource\" error."); @@ -1514,8 +1501,8 @@ size_check_failed: return -1; } -/** - * SCCRP の送信 +/* + * send SCCRP */ static void l2tp_ctrl_send_SCCRP(l2tp_ctrl *_this) @@ -1563,7 +1550,7 @@ l2tp_ctrl_send_SCCRP(l2tp_ctrl *_this) if ((val = l2tp_ctrl_config_str(_this, "l2tp.host_name")) == NULL) val = _this->l2tpd->default_hostname; if (val[0] == '\0') - val = "G"; /* おまじない。ask yasuoka */ + val = "G"; /* XXX magic word, why? ask yasuoka */ len = strlen(val); memcpy(avp->attr_value, val, len); bytebuf_add_avp(bytebuf, avp, len); @@ -1576,8 +1563,7 @@ l2tp_ctrl_send_SCCRP(l2tp_ctrl *_this) bytebuf_add_avp(bytebuf, avp, 2); /* Bearer Capability - * - * この実装は LAC になり得ない LNS なので。 + * This implementation never act as LAC. * memset(avp, 0, sizeof(*avp)); avp->is_mandatory = 1; @@ -1652,7 +1638,7 @@ l2tp_ctrl_send_HELLO(l2tp_ctrl *_this) return 0; } -/** ZLB の送信 */ +/* Send ZLB */ static int l2tp_ctrl_send_ZLB(l2tp_ctrl *_this) { @@ -1668,12 +1654,13 @@ l2tp_ctrl_send_ZLB(l2tp_ctrl *_this) return l2tp_ctrl_send_packet(_this, 0, _this->zlb_buffer, 1); } -/*********************************************************************** - * ユーティリティ関数 - ***********************************************************************/ +/* + * Utitlity + */ + /** - * 送信バッファの準備 - * @return 送信バッファが Window を越えている場合には NULL が返ります。 + * Prepare send buffer + * @return return Null when the send buffer exceed Window. */ bytebuffer * l2tp_ctrl_prepare_snd_buffer(l2tp_ctrl *_this, int with_seq) @@ -1699,7 +1686,7 @@ l2tp_ctrl_prepare_snd_buffer(l2tp_ctrl *_this, int with_seq) } /** - * 現在のステータスの文字列表現を返します。 + * return current state as strings */ static inline const char * l2tp_ctrl_state_string(l2tp_ctrl *_this) @@ -1714,9 +1701,7 @@ l2tp_ctrl_state_string(l2tp_ctrl *_this) return "unknown"; } -/** - * このインスタンスに基づいたラベルから始まるログを記録します。 - */ +/* logging with the label of the l2tp instance. */ void l2tp_ctrl_log(l2tp_ctrl *_this, int prio, const char *fmt, ...) { diff --git a/usr.sbin/npppd/l2tp/l2tp_local.h b/usr.sbin/npppd/l2tp/l2tp_local.h index 517072db216..424b58f2cae 100644 --- a/usr.sbin/npppd/l2tp/l2tp_local.h +++ b/usr.sbin/npppd/l2tp/l2tp_local.h @@ -1,3 +1,4 @@ +/* $OpenBSD: l2tp_local.h,v 1.2 2010/07/01 03:38:17 yasuoka Exp $ */ /*- * Copyright (c) 2009 Internet Initiative Japan Inc. * All rights reserved. @@ -25,7 +26,7 @@ */ #ifndef L2TP_LOCAL_H #define L2TP_LOCAL_H 1 -/* $Id: l2tp_local.h,v 1.1 2010/01/11 04:20:57 yasuoka Exp $ */ +/* $Id: l2tp_local.h,v 1.2 2010/07/01 03:38:17 yasuoka Exp $ */ #ifndef GETSHORT #define GETSHORT(s, cp) { \ diff --git a/usr.sbin/npppd/l2tp/l2tp_subr.c b/usr.sbin/npppd/l2tp/l2tp_subr.c index 62a6326a687..fecfe603ab4 100644 --- a/usr.sbin/npppd/l2tp/l2tp_subr.c +++ b/usr.sbin/npppd/l2tp/l2tp_subr.c @@ -1,3 +1,4 @@ +/* $OpenBSD: l2tp_subr.c,v 1.2 2010/07/01 03:38:17 yasuoka Exp $ */ /*- * Copyright (c) 2009 Internet Initiative Japan Inc. * All rights reserved. @@ -23,10 +24,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ -/* $Id: l2tp_subr.c,v 1.1 2010/01/11 04:20:57 yasuoka Exp $ */ -/**@file - * L2TP 関連の補助的な関数を提供します。 - */ +/* $Id: l2tp_subr.c,v 1.2 2010/07/01 03:38:17 yasuoka Exp $ */ +/**@file L2TP related sub-routines */ #include <sys/types.h> #include <sys/time.h> #include <sys/socket.h> @@ -55,9 +54,9 @@ #define L2TP_SUBR_ASSERT(x) #endif -/*********************************************************************** - * AVP関連 - ***********************************************************************/ +/* + * AVP + */ int avp_enum(struct l2tp_avp *avp, const u_char *pkt, int pktlen, int filldata) { @@ -309,7 +308,7 @@ avp_find_message_type_avp(struct l2tp_avp *avp, const u_char *pkt, int pktlen) } /** - * bytebuffer に AVP を追加します。 + * add an AVP to bytebuffer */ int bytebuf_add_avp(bytebuffer *bytebuf, struct l2tp_avp *avp, int value_len) diff --git a/usr.sbin/npppd/l2tp/l2tp_subr.h b/usr.sbin/npppd/l2tp/l2tp_subr.h index 4aed34c29ff..8cb11cedbf3 100644 --- a/usr.sbin/npppd/l2tp/l2tp_subr.h +++ b/usr.sbin/npppd/l2tp/l2tp_subr.h @@ -1,3 +1,4 @@ +/* $OpenBSD: l2tp_subr.h,v 1.2 2010/07/01 03:38:17 yasuoka Exp $ */ /*- * Copyright (c) 2009 Internet Initiative Japan Inc. * All rights reserved. @@ -25,10 +26,10 @@ */ #ifndef L2TP_SUBR_H #define L2TP_SUBR_H 1 -/* $Id: l2tp_subr.h,v 1.1 2010/01/11 04:20:57 yasuoka Exp $ */ +/* $Id: l2tp_subr.h,v 1.2 2010/07/01 03:38:17 yasuoka Exp $ */ /** - * L2TP の Attribute Value Pair (AVP) のパケットヘッダを示す構造体です。 + * structure of L2TP Attribute Value Pair (AVP) packet header */ struct l2tp_avp { @@ -90,14 +91,10 @@ short_hash(const void *v, int sz) return (int)v % sz; } -/** - * AVPのサイズをチェックするマクロ。 - * <p> - * 準備<br> - * <ul> - * <li>エラーメッセージ用の char emes[256] を準備する。 - * <li>reigai ラベルを準備する。 - * </ul></p> +/* + * macro to check AVP size. + * Prepare 1) char emes[256] for error message, 2) size_check_failed label + * before use this macro. */ #define AVP_SIZE_CHECK(avp, op, exp) \ if (!((avp)->length op (exp))) { \ diff --git a/usr.sbin/npppd/l2tp/l2tpd.c b/usr.sbin/npppd/l2tp/l2tpd.c index baa8604c135..6df6d75bdf1 100644 --- a/usr.sbin/npppd/l2tp/l2tpd.c +++ b/usr.sbin/npppd/l2tp/l2tpd.c @@ -1,3 +1,4 @@ +/* $OpenBSD: l2tpd.c,v 1.3 2010/07/01 03:38:17 yasuoka Exp $ */ /*- * Copyright (c) 2009 Internet Initiative Japan Inc. * All rights reserved. @@ -23,13 +24,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ -/**@file - * L2TP(Layer Two Tunneling Protocol "L2TP") の実装 - */ -/* - * RFC 2661 - */ -// $Id: l2tpd.c,v 1.2 2010/01/13 07:49:44 yasuoka Exp $ +/**@file L2TP(Layer Two Tunneling Protocol "L2TP") / RFC2661 */ +/* $Id: l2tpd.c,v 1.3 2010/07/01 03:38:17 yasuoka Exp $ */ #include <sys/types.h> #include <sys/socket.h> #include <sys/time.h> @@ -81,11 +77,8 @@ static void l2tpd_io_event (int, short, void *); static inline int short_cmp (const void *, const void *); static inline uint32_t short_hash (const void *, int); -/* - * static 変数 - */ -/** l2tpd の ID番号のシーケンス番号 */ +/* sequence # of l2tpd ID */ static unsigned l2tpd_id_seq = 0; #ifndef USE_LIBSOCKUTIL @@ -93,15 +86,14 @@ struct in_ipsec_sa_cookie { }; #endif -/*********************************************************************** - * L2TP デーモンインスタンス操作 - ***********************************************************************/ +/* L2TP daemon instance */ /** - * L2TPデーモンインスタンスを初期化します。 + * initialize L2TP daemon instance * <p> - * {@link _l2tpd#bind_sin} は、.sin_family = AF_INET、.sin_port = 1701、 - * .sin_len が設定された状態で返ります。 </p> + * {@link _l2tpd#bind_sin} will return with .sin_family = AF_INET, + * .sin_port = 1701 and .sin_len = "appropriate value" + * </p> */ int l2tpd_init(l2tpd *_this) @@ -137,12 +129,12 @@ l2tpd_init(l2tpd *_this) return 0; } -/** - * {@link ::l2tpd L2TPデーモン}に{@link ::l2tpd_listener リスナ}を追加します。 - * @param _this {@link ::l2tpd L2TPデーモン} - * @param idx リスナのインデックス - * @param label 物理層としてのラベル。"L2TP" など - * @param bindaddr 待ち受けるアドレス +/* + * Add a {@link :l2tpd_listener} to the {@link ::l2tpd L2TP daemon} + * @param _this {@link ::l2tpd L2TP daemon} + * @param idx index of the lisnter + * @param label physical layer label (ex. "L2TP") + * @param bindaddr bind address */ int l2tpd_add_listener(l2tpd *_this, int idx, const char *label, @@ -166,18 +158,17 @@ l2tpd_add_listener(l2tpd *_this, int idx, const char *label, l2tpd_log(_this, LOG_ERR, "Invalid argument error on %s(): idx must be %d but %d", __func__, slist_length(&_this->listener), idx); - goto reigai; + goto fail; } if ((plistener = malloc(sizeof(l2tpd_listener))) == NULL) { l2tpd_log(_this, LOG_ERR, "malloc() failed in %s: %m", __func__); - goto reigai; + goto fail; } memset(plistener, 0, sizeof(l2tpd_listener)); L2TPD_ASSERT(sizeof(plistener->bind_sin) >= bindaddr->sa_len); memcpy(&plistener->bind_sin, bindaddr, bindaddr->sa_len); - /* ポート番号が省略された場合は、デフォルト (1701/udp)を使う */ if (plistener->bind_sin.sin_port == 0) plistener->bind_sin.sin_port = htons(L2TPD_DEFAULT_UDP_PORT); @@ -189,16 +180,16 @@ l2tpd_add_listener(l2tpd *_this, int idx, const char *label, if (slist_add(&_this->listener, plistener) == NULL) { l2tpd_log(_this, LOG_ERR, "slist_add() failed in %s: %m", __func__); - goto reigai; + goto fail; } return 0; -reigai: +fail: if (plistener != NULL) free(plistener); return 1; } -/** L2TPデーモンインスタンスの終了処理を行います。*/ +/* finalize L2TP daemon instance */ void l2tpd_uninit(l2tpd *_this) { @@ -223,12 +214,12 @@ l2tpd_uninit(l2tpd *_this) } slist_fini(&_this->listener); - event_del(&_this->ev_timeout); // ねんのため + event_del(&_this->ev_timeout); /* just in case */ _this->state = L2TPD_STATE_STOPPED; _this->config = NULL; } -/** 待ち受けを開始します。*/ +/* start l2tpd listner */ static int l2tpd_listener_start(l2tpd_listener *_this, char *ipsec_policy_in, char *ipsec_policy_out) @@ -251,7 +242,7 @@ l2tpd_listener_start(l2tpd_listener *_this, char *ipsec_policy_in, if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) { l2tpd_log(_l2tpd, LOG_ERR, "socket() failed in %s(): %m", __func__); - goto reigai; + goto fail; } #ifdef NPPPD_FAKEBIND if (!wildcardbinding) @@ -267,25 +258,25 @@ l2tpd_listener_start(l2tpd_listener *_this, char *ipsec_policy_in, if ((ival = fcntl(sock, F_GETFL, 0)) < 0) { l2tpd_log(_l2tpd, LOG_ERR, "fcntl(,F_GETFL) failed in %s(): %m", __func__); - goto reigai; + goto fail; } else if (fcntl(sock, F_SETFL, ival | O_NONBLOCK) < 0) { l2tpd_log(_l2tpd, LOG_ERR, "fcntl(,F_SETFL,O_NONBLOCK) failed " "in %s(): %m", __func__); - goto reigai; + goto fail; } ival = 1; if (setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, &ival, sizeof(ival)) != 0) { l2tpd_log(_l2tpd, LOG_ERR, "setsockopt(,,SO_REUSEPORT) failed in %s(): %m", __func__); - goto reigai; + goto fail; } if (bind(sock, (struct sockaddr *)&_this->bind_sin, _this->bind_sin.sin_len) != 0) { l2tpd_log(_l2tpd, LOG_ERR, "Binding %s:%u/udp: %m", inet_ntoa(_this->bind_sin.sin_addr), ntohs(_this->bind_sin.sin_port)); - goto reigai; + goto fail; } #ifdef NPPPD_FAKEBIND if (!wildcardbinding) @@ -298,24 +289,23 @@ l2tpd_listener_start(l2tpd_listener *_this, char *ipsec_policy_in, l2tpd_log(_l2tpd, LOG_ERR, "setsockopt(,,UDP_NO_CKSUM) failed in %s(): %m", __func__); - goto reigai; + goto fail; } #endif #ifdef USE_LIBSOCKUTIL if (setsockoptfromto(sock) != 0) { l2tpd_log(_l2tpd, LOG_ERR, "setsockoptfromto() failed in %s(): %m", __func__); - goto reigai; + goto fail; } #else - // recvfromto のために - ival = 1; + ival = 1; /* for recvfromto */ if (setsockopt(sock, IPPROTO_IP, IP_RECVDSTADDR, &ival, sizeof(ival)) != 0) { l2tpd_log(_l2tpd, LOG_ERR, "setsockopt(,,IP_RECVDSTADDR) failed in %s(): %m", __func__); - goto reigai; + goto fail; } #endif #ifdef IP_IPSEC_POLICY @@ -346,14 +336,14 @@ l2tpd_listener_start(l2tpd_listener *_this, char *ipsec_policy_in, ntohs(_this->bind_sin.sin_port), _this->phy_label); return 0; -reigai: +fail: if (sock >= 0) close(sock); return 1; } -/** L2TPデーモンを開始します。*/ +/* start L2TP daemon */ int l2tpd_start(l2tpd *_this) { @@ -374,23 +364,23 @@ l2tpd_start(l2tpd *_this) if (_this->require_ipsec != 0) { #if 0 /* - * NOTE ipsec_set_policy() 内で利用する yacc のスタック用の - * バッファは動的に割り当てられますが、解放されません。 - * yasuoka の調査時は 2000 バイトリークします。 + * Note: ipsec_set_policy() will assign the buffer for + * yacc parser stack, however it never free. + * it cause memory leak (-2000byte). */ if ((ipsec_policy_in = ipsec_set_policy(L2TPD_IPSEC_POLICY_IN, strlen(L2TPD_IPSEC_POLICY_IN))) == NULL) { l2tpd_log(_this, LOG_ERR, "ipsec_set_policy(L2TPD_IPSEC_POLICY_IN) failed " "at %s(): %s: %m", __func__, ipsec_strerror()); - goto reigai; + goto fail; } if ((ipsec_policy_out = ipsec_set_policy(L2TPD_IPSEC_POLICY_OUT, strlen(L2TPD_IPSEC_POLICY_OUT))) == NULL) { l2tpd_log(_this, LOG_ERR, "ipsec_set_policy(L2TPD_IPSEC_POLICY_OUT) failed " "at %s(): %s: %m", __func__, ipsec_strerror()); - goto reigai; + goto fail; } #endif } @@ -412,7 +402,7 @@ l2tpd_start(l2tpd *_this) return rval; #if 0 -reigai: +fail: #endif if (ipsec_policy_in != NULL) free(ipsec_policy_in); @@ -422,7 +412,7 @@ reigai: return 1; } -/** 待ち受けを終了します */ +/* stop l2tp lisnter */ static void l2tpd_listener_stop(l2tpd_listener *_this) { @@ -436,9 +426,8 @@ l2tpd_listener_stop(l2tpd_listener *_this) _this->sock = -1; } } -/** - * 切断を猶予せずにすぐに停止します。 - */ + +/* stop immediattly without disconnect operation */ void l2tpd_stop_immediatly(l2tpd *_this) { @@ -449,12 +438,13 @@ l2tpd_stop_immediatly(l2tpd *_this) plsnr = slist_itr_next(&_this->listener); l2tpd_listener_stop(plsnr); } - event_del(&_this->ev_timeout); // ねんのため + event_del(&_this->ev_timeout); /* XXX */ _this->state = L2TPD_STATE_STOPPED; } -/** - * {@link ::_l2tp_ctrl コントロール} が終了した際にコールされます。 +/* + * this function will be called when {@link ::_l2tp_ctrl control} + * is terminated. */ void l2tpd_ctrl_finished_notify(l2tpd *_this) @@ -485,9 +475,7 @@ l2tpd_stop_timeout(int fd, short evtype, void *ctx) l2tpd_stop_immediatly(_this); } -/** - * L2TPデーモンを停止します。 - */ +/* stop L2TP daemon */ void l2tpd_stop(l2tpd *_this) { @@ -500,9 +488,7 @@ l2tpd_stop(l2tpd *_this) if (l2tpd_is_stopped(_this)) return; if (l2tpd_is_shutting_down(_this)) { - /* - * 2度目はすぐに終了 - */ + /* terminate immidiatly, when 2nd call */ l2tpd_stop_immediatly(_this); return; } @@ -527,9 +513,9 @@ l2tpd_stop(l2tpd *_this) l2tpd_stop_immediatly(_this); } -/*********************************************************************** - * 設定関連 - ***********************************************************************/ +/* + * Configuration + */ #define CFG_KEY(p, s) config_key_prefix((p), (s)) #define VAL_SEP " \t\r\n" @@ -550,7 +536,7 @@ l2tpd_reload(l2tpd *_this, struct properties *config, const char *name, do_start = 0; if (l2tpd_config_str_equal(_this, CFG_KEY(name, "enabled"), "true", default_enabled)) { - // false にした直後に true にされるかもしれない。 + /* care the case false-true flapping */ if (l2tpd_is_shutting_down(_this)) l2tpd_stop_immediatly(_this); if (l2tpd_is_stopped(_this)) @@ -564,7 +550,7 @@ l2tpd_reload(l2tpd *_this, struct properties *config, const char *name, return 1; _this->config = config; - /* 設定がなかったら使われる */ + /* default value */ gethostname(_this->default_hostname, sizeof(_this->default_hostname)); _this->ctrl_in_pktdump = l2tpd_config_str_equal(_this, @@ -578,7 +564,7 @@ l2tpd_reload(l2tpd *_this, struct properties *config, const char *name, _this->phy_label_with_ifname = l2tpd_config_str_equal(_this, CFG_KEY(name, "label_with_ifname"), "true", 0); - // ip4_allow をパース + /* parse ip4_allow */ in_addr_range_list_remove_all(&_this->ip4_allow); val = l2tpd_config_str(_this, CFG_KEY(name, "ip4_allow")); if (val != NULL) { @@ -602,12 +588,12 @@ l2tpd_reload(l2tpd *_this, struct properties *config, const char *name, } if (do_start) { - /* - * 起動直後と、l2tpd.enable が false -> true に変更された - * 場合に、do_start。すべてのリスナーが、初期化された状態を - * 仮定できる - */ - // l2tpd.listener_in の読み込む + /* + * in the case of 1) cold-booted and 2) pptpd.enable + * toggled "false" to "true" do this, because we can + * assume that all pptpd listner are initialized. + */ + /* read l2tpd.lisnter_in */ val = l2tpd_config_str(_this, CFG_KEY(name, "listener_in")); if (val != NULL) { if (strlen(val) >= sizeof(buf)) { @@ -619,7 +605,8 @@ l2tpd_reload(l2tpd *_this, struct properties *config, const char *name, strlcpy(buf, val, sizeof(buf)); label = NULL; - // タブ、スペース区切りで、複数指定可能 + /* it can accept multiple values with tab/space + * separation */ for (i = 0, cp = buf; (tok = strsep(&cp, VAL_SEP)) != NULL;) { if (*tok == '\0') @@ -667,10 +654,10 @@ l2tpd_reload(l2tpd *_this, struct properties *config, const char *name, return 0; } -/*********************************************************************** - * I/O 関連 - ***********************************************************************/ -/** アクセスを拒否したことをログに残す */ +/* + * I/O functions + */ +/* logging when deny an access */ void l2tpd_log_access_deny(l2tpd *_this, const char *reason, struct sockaddr *peer) { @@ -686,7 +673,7 @@ l2tpd_log_access_deny(l2tpd *_this, const char *reason, struct sockaddr *peer) "%s", hostbuf, servbuf, reason); } -/** I/Oイベントハンドラ */ +/* I/O event handler */ static void l2tpd_io_event(int fd, short evtype, void *ctx) { @@ -728,7 +715,7 @@ l2tpd_io_event(int fd, short evtype, void *ctx) l2tpd_stop(_l2tpd); return; } - //送信元チェック(allows.in) + /* source address check (allows.in) */ switch (peer.ss_family) { case AF_INET: #ifdef USE_LIBSOCKUTIL @@ -740,7 +727,7 @@ l2tpd_io_event(int fd, short evtype, void *ctx) nat_t = NULL; #endif /* - * XXX NAT-T の場合の送信元チェック + * XXX check source address when NAT-T */ if (in_addr_range_list_includes( &_l2tpd->ip4_allow, @@ -764,9 +751,9 @@ l2tpd_io_event(int fd, short evtype, void *ctx) } } -/*********************************************************************** - * L2TPコントロール関連 - ***********************************************************************/ +/* + * L2TP control + */ l2tp_ctrl * l2tpd_get_ctrl(l2tpd *_this, int tunid) { @@ -792,9 +779,9 @@ l2tpd_remove_ctrl(l2tpd *_this, int tunid) } -/*********************************************************************** - * 雑多 - ***********************************************************************/ +/* + * misc + */ void l2tpd_log(l2tpd *_this, int prio, const char *fmt, ...) |