tcpのヘルプ・マニュアル
日本語 英語
tcp --help
man tcp
TCP(7) Linux Programmer’s Manual TCP(7)
名前
tcp - TCP プロトコル
書式
#include
#include
#include
tcp_socket = socket(AF_INET, SOCK_STREAM, 0);
説明
こ れ は RFC 793, RFC 1122, RFC 2001 で定義されている TCP プロトコルを
NewReno 拡張と SACK 拡張を含めて実装したものである。 TCP は、 ip(7) 上
の 二 つ の ソ ケ ット間に、信頼性の高い、ストリーム指向の全二重 (full-
duplex) 通信を提供する。 v4 と v6 の両方のバージョンの ip(7) に対応して
いる。 TCP は、データが順序を守って到着すること、途中で失われたパケット
が再送されることを保証する。また、パケット単位にチェックサムを生成、 検
査 することで、転送エラーを検知する。 TCP はレコード境界 (record bound-
ary) を保存しない。
新しく生成されたばかりの TCP ソケットは、リモートアドレスかローカルアド
レ スがなく、したがって詳細が完全に指定された状態ではない。外部への TCP
接続を生成するには、 connect(2) を用いてもう一方の TCP ソケットへの接続
を確立する。外部からの新たな接続を受けるには、まず bind(2) でソケットを
ローカルなアドレスとポートに結びつけ、次に listen(2) を呼んでソケットを
接続待ち受け状態にする。その後、到着した接続要求に対して accept(2) を用
い、ソケットを新しく生成する。 accept(2) または connect(2) のコールが成
功 したソケットは、詳細が完全に指定された状態となり、データのやりとりが
可能となる。接続待ち受け状態の (listening) ソケットや、接 続 (connect)
されていないソケットを通してデータをやりとりすることはできない。
Linux は RFC 1323 の TCP high performance 拡張をサポートしている。これ
には、Protection Against Wrapped Sequence Numbers (PAWS)、ウィンドウ ス
ケ ーリング、タイムスタンプなどが含まれている。ウィンドウスケーリングを
利用すると、遅延または帯域の大きな接続で、 (64K 以上の) 巨大な TCP ウィ
ン ドウを用いることが可能となる。これを用いるには、送受信のバッファサイ
ズを大きくしなければならない。システム全体に対するバッファサイズの変 更
は、ファイル /proc/sys/net/ipv4/tcp_wmem と /proc/sys/net/ipv4/tcp_rmem
を用いて行うことができる。また、個々のソケットのみを大きくしたい場合 に
は、 SO_SNDBUF や SO_RCVBUF ソケットオプションを用いて setsockopt(2) コ
ールを用いて設定すればよい。
SO_SNDBUF や SO_RCVBUF のメカニズムで宣言されるソケットバッファの最大サ
イ ズ は 、 フ ァ イ ル /proc/sys/net/core/rmem_max や
/proc/sys/net/core/wmem_max で指定されたシステムとしての制限値を超え る
こ とはできない。 TCP は実際には setsockopt(2) コールが要求したバッファ
サイズの二倍を割り当てる。そのため、この後で getsockopt(2) コールを行う
と 、 setsockopt(2) で要求したバッファサイズとは異なる値が返る。 TCP は
この余分な空間を、管理目的やカーネル内部の構造体に用いている。 /proc フ
ァイルの値は、これらを反映し、実際の TCP ウィンドウよりも大きな値となる
。各接続におけるソケットのバッファサイズ変更を有効にする に は 、 lis-
ten(2) や connect(2) コールの前に設定しなければならない。より詳しい情報
は socket(7) を見よ。
TCP は緊急データ (urgent data) をサポートしている。緊急データは何らかの
重 要なメッセージがデータストリームに含まれていること、そのデータをでき
るだけ早く処理すべきこと、を受信者に伝えるために用いられる。緊急デー タ
を 送るには、 send(2) に MSG_OOB オプションを指定する。緊急データを受信
すると、カーネルは SIGURG シグナルを送信する。送信先 は SIOCSPGRP や
FIOSETOWN ioctl (や POSIX.1-2001 で規定されている fcntl(2) F_SETOWN 操
作) を用いてそのソケットの「所有者」として設定されたプロセスかプロセ ス
グ ループである。 SO_OOBINLINE ソケットオプションが有効になっていると、
緊急データは通常のデータストリームの中に混ぜて送られる (プログラムは 下
記の SIOCATMARK ioctl を使って緊急データの場所を調べることができる)。無
効になっている場合には、 recv(2) や recvmsg(2) で MSG_OOB フラグがセ ッ
トされているときにのみ、緊急データを受信できる。
Linux 2.4 では多くの変更がなされ、スループットとスケーリングが向上し、
機能も高まった。これらの機能には、ゼロコピ ー sendfile(2) 、 Explicit
Congestion Notification、 TIME_WAIT ソケットの新しい管理法、 keep-alive
ソケットオプション、 Duplicate SACK 拡張のサポートなどがある。
アドレスのフォーマット
TCP は IP の上層に構築されている (ip(7) を参照)。 ip(7) に定義されて い
る アドレスフォーマットは TCP にも適用される。 TCP は point-to-point の
通信だけをサポートする。ブロードキャストやマルチキャストはサポートし な
い。
/proc インタフェース
シ ステム全体に対する TCP パラメータの設定には、 /proc/sys/net/ipv4/ デ
ィレクトリ内のファイルによりアクセスできる。さらに、IP に関連する /proc
イ ンタフェースのほとんどは TCP についても適用される。 ip(7) を参照のこ
と。 Boolean は整数値で、 0 以外の値 ("true") は対応するオプションが 有
効、 0 値 ("false") は無効、であることを意味する。
tcp_abc (Integer; default: 0; Linux 2.6.15 以降)
RFC 3465 で定義されている Appropriate Byte Count (ABC) を制御す
る。 ABC は、部分的な ACK に応じた輻輳ウィンドウ (cwnd) の増加を
より緩やかにする方法である。以下の値を指定できる。
0 ACK を受信する毎に cwnd を増やす (ABC なし)。
1 フルサイズのセグメントの ACK を受信する毎に cwnd を増やす。
2 ACK が遅延 ACK (delayed acknowledgment) を相殺するための 2 セ
グメントに対する ACK の場合に、 cwnd を 2 増やすことができ る
。
tcp_abort_on_overflow (Boolean; default: disabled; Linux 2.4 以降)
接続を待ち受けているサービスが遅すぎて、受信についていけない場合
に、接続をリセットできるようにする。これを用いると、バーストによ
ってオーバーフローが起こったときに、接続を回復できるようになる。
このオプションを用いるのは、受信デーモンを高速化できない場合に「
限定する」こと。このオプションを用いると、そのサーバに接続してい
るクライアントにとっては害になることがある。
tcp_adv_win_scale (integer; default: 2; Linux 2.4 以降)
バッファリングのオーバーヘッドの計算方法を 、 tcp_adv_win_scale
が正の場合は bytes/2^tcp_adv_win_scale に、 tcp_adv_win_scale が
負か 0 の場合は bytes-bytes/2^(-tcp_adv_win_scale) とする。
ソケットの受信バッファ空間はアプリケーションとカーネルで共有され
る。 TCP はバッファの一部を TCP ウィンドウとして管理し、これを受
信ウィンドウとして接続の他端に通知する。空間の残りは「アプリケー
ション」バッファとして用いられ、スケジューリングやアプリケーショ
ンの遅延からネットワークを隔離する。 tcp_adv_win_scale のデフ ォ
ル ト値は 2 であり、この場合アプリケーションバッファは全体の 1/4
になる。
tcp_allowed_congestion_control (String; default: see text; Linux 2.4.20
以降)
非特権プロセスで利用できる輻輳制御アルゴリズムの選択肢を表示/ 設
定する (TCP_CONGESTION ソケットオプションの説明を参照のこと)。こ
のリストは tcp_available_congestion_control で表示されるリストの
部 分 集合となる。このリストのデフォルト値は、"reno" と tcp_con-
gestion_control のデフォルト設定をあわせたものとなる。
tcp_available_congestion_control (String; read-only; Linux 2.4.20 以降)
登録されている輻輳制御アルゴリズムのリストを表示する。このリスト
に載っているものだけが、 tcp_allowed_congestion_control に表示さ
れる。他の輻輳制御アルゴリズムがモジュールとして利用可能だが、モ
ジュールがロードされていないこともある。
tcp_app_win (integer; default: 31; Linux 2.4 以降)
この変数は、TCP ウィンドウの何バイト分をバッファリングのオーバー
ヘッド用に予約するかを指定する。
そのウィンドウの window/2^tcp_app_win と mss の大きいほう (バ イ
ト 単位) がアプリケーションバッファとして予約される。 0 を指定す
ると一切予約領域を取らない。
tcp_base_mss (Integer; default: 512; Linux 2.6.17 以降)
パケット化レイヤの Path MTU discovery (MTU probing) で 、
search_low の初期値と使用される値。 MTU probing が有効な場合、こ
の値はその接続の MSS の初期値となる。
tcp_bic (Boolean; default: disabled; Linux 2.4.27/2.6.6 から 2.6.13 ま
で)
BIC TCP 輻輳制御アルゴリズムを有効にする。 BIC-TCP は送信側の み
の 変更で、スケーラビリティと TCP 親和性 (friendliness) の両方を
提供しつつ、大きなウィンドウの下での線形な RTT 公平性を保証す る
も のである。このプロトコルでは additive increase (追加的な増加)
と binary search increase (二分探索増加) といわれる二つの仕組 み
を 組 み合わせている。輻輳ウィンドウが大きいときは、増分の大きい
additive increase により、スケーラビリティを確保しながら線 形 な
RTT 公 平 性 を保証する。輻輳ウィンドウが小さいときには binary
search increase により TCP 親和性を達成している。
tcp_bic_low_window (integer; default: 14; Linux 2.4.27/2.6.6 以 降
2.6.13 まで)
BIC TCP が輻輳ウィンドウの調整を開始する閾値ウィンドウ (パケット
単 位) を設定する。この閾値を下回る場合、BIC TCP はデフォルトの
TCP Reno と同じ動作をする。
tcp_bic_fast_convergence (Boolean; default: enabled; Linux 2.4.27/2.6.6
以降 2.6.13 まで)
BIC TCP が輻輳ウィンドウの変化により速く反応するようにする。同じ
コネクションを共有する二つのフローが一つにまとまるのをより速く行
うようにする。
tcp_congestion_control (String; default: enabled; Linux 2.4.13 以降)
新規の接続で使用されるデフォルトの輻輳制御アルゴリズムを設定する
。 "reno" アルゴリズムは常に利用可能だが、カーネル設定次第では別
の選択肢が利用できることもある。このファイルのデフォルト値はカー
ネル設定の一つとして設定される。
tcp_dma_copybreak (integer; default: 4096; Linux 2.6.24 以降)
システムに DMA コピーエンジンが存在し、カーネルで CONFIG_NET_DMA
オプションが有効になっている場合に、 DMA コピーエンジンにオフ ロ
ードされるソケットの読み込みサイズの下限値 (バイト単位)。
tcp_dsack (Boolean; default: enabled; Linux 2.4 以降)
RFC 2883 の TCP Duplicate SACK のサポートを有効にする。
tcp_ecn (Boolean; default: disabled; Linux 2.4 以降)
RFC 2884 の Explicit Congestion Notification を有効にする。これ
を有効にすると、間違った振舞いをする古いルータが経路の途中にある
ような接続先に対して影響が生じ、場合によっては接続が落ちるかもし
れない。
tcp_fack (Boolean; default: enabled; Linux 2.2 以降)
TCP Forward Acknowledgement のサポートを有効にする。
tcp_fin_timeout (integer; default: 60; Linux 2.2 以降)
ソケットを強制的にクローズする前に、最後の FIN パケットを待つ 時
間 を秒単位で指定する。これは厳密には TCP の仕様を満たしていない
が、 DoS 攻撃 (denial of service attack) から身を守るために必 要
である。 Linux 2.2 ではデフォルト値は 180 であった。
tcp_frto (integer; default: 0; Linux 2.4.21/2.6 以降)
F-RTO を有効にする。F-RTO は TCP 再送タイムアウト (RTO) からの復
旧性能を向上させたアルゴリズムである。この機能は無線環境で特に効
果を発揮する。無線環境では、通常は、中間ルータの輻輳ではなくラン
ダムな無線の干渉によりパケットロスが発生する。詳細は RFC 4138 を
参照。
このファイルは以下のいずれかの値を取ることができる。
0 F-RTO を無効にする。
1 基本版の F-RTO アルゴリズムを有効にする。
2 そのフローで SACK を使用する場合、SACK 拡張版の F-RTO を有効
にする。基本版の F-RTO も SACK が使用されている場合にも使用で
き るが、基本版の場合には F-RTO が SACK が有効になった TCP フ
ローでのパケット数計測と、相性が悪く相互干渉が起こる場面が 存
在する。
Linu 2.6.22 より前では、このパラメータはブール値であり、上記の 0
と 1 のみをサポートしていた。
tcp_frto_response (integer; default: 0; Linux 2.6.22 以降)
F-RTO が TCP 再送タイムアウトが偽物だと検出した場合 (つまり、TCP
がもっと長い再送タイムアウトを設定していればタイムアウトが避けら
れた場合)、次にどうするかに関して選択肢がいくつかある。以下の 値
を選択できる。
0 レートを元の半分にする。滑らかで、保守的な反応を行い、RTT 1回
分の時間後に輻輳ウィンドウ (cwnd) とスロースタ ー ト の 閾 値
(ssthresh) が半分になる。
1 非常に保守的な反応。このオプションの使用は推奨されない。反応
が正しかった場合であっても、Linux TCP の他の部分とうまく連 携
できないからである。 cwnd と ssthresh は直ちに半分にされる。
2 積極的な反応。不要と判明した輻輳制御の測定情報を取り消す (TCP
がもっと注意深く扱うべき再送が失われる可能性を無視する) 。 。
cwnd と ssthresh はタイムアウト前の値に戻される。
tcp_keepalive_intvl (integer; default: 75; Linux 2.4 以降)
TCP keep-alive のプローブを送る間隔 (秒単位)。
tcp_keepalive_probes (integer; default: 9; Linux 2.2 以降)
TCP keep-alive プローブの最大回数。この回数だけ試しても接続先か
ら反応が得られない場合は、あきらめて接続を切断する。
tcp_keepalive_time (integer; default: 7200; Linux 2.2 以降)
接続がアイドル状態になってから、keep-alive プローブを送信する ま
での時間を秒単位で指定する。 SO_KEEPALIVE ソケットオプションが有
効になっていないと keep-alive は送られない。デフォルト値は 7200
秒 (2 時間)。 keep-alive が有効になっている場合、さらにおよそ 11
分 (75 秒間隔の 9 プローブ分) 経過するとアイドル状態の接続は終了
させられる。
下層にある接続追跡機構やアプリケーションでのタイムアウトは、もっ
とずっと短いかもしれない。
tcp_low_latency (Boolean; default: disabled; Linux 2.4.21/2.6 以降)
有効にすると、TCP スタックはスループットを高くするよりも遅延を少
なくすることを優先して判断を行う。このオプションを無効にすると、
スループットを高くすることが優先される。このデフォルト値を変更し
た 方がよいアプリケーションの例としては Beowulf コンピュータクラ
スタが挙げられるだろう。
tcp_max_orphans (integer; default: see below; Linux 2.4 以降)
システムが許容する、 orphan な (どのユーザファイルハンドルにもア
タ ッ チ さ れ て いない) TCP ソケットの最大数。この数を越えると
、orphan な接続はリセットされ、警告が表示される。この制限が存 在
す るのは、単純な使用不能 (denial-of-service) 攻撃を防ぐために過
ぎない。この値を小さくすることは推奨しない。ネットワークの条件に
よ っ て は 、 こ の数値を大きくしないといけないかもしれないが、
orphan なソケットひとつあたり 64K 程度のスワップ不可能なメモリを
消費することも注意せよ。デフォルトの初期値はカーネルパラメータの
NR_FILE と等しい。この初期デフォルト値はシステムのメモリに応じて
調整される。
tcp_max_syn_backlog (integer; default: 下記参照; Linux 2.2 以降)
接 続してきているクライアントから ack を受信していない状態の接続
リクエストをキューに置ける最大数。この数値を越えると、カーネルは
リ クエストを捨て始める。デフォルトの値は 256 で、システムに充分
なメモリがある (128Mb 以上) 場合は 1024 になり、メモリが非常に少
な い場合 (32 Mb 以下) は 128 になる。この数値を 1024 以上に増や
した い 場 合 は 、 include/net/tcp.h の TCP_SYNQ_HSIZE を
TCP_SYNQ_HSIZE*16<=tcp_max_syn_backlog のように修正し、カーネル
を再コンパイルすることを奨める。
tcp_max_tw_buckets (integer; default: 下記参照; Linux 2.4 以降)
システムが許容する TIME_WAIT 状態にあるソケットの最大数。この 制
限 が存在するのは、単純な使用不能 (denial-of-service) 攻撃を防ぐ
ために過ぎない。デフォルト値は NR_FILE*2 で、システムのメモリ に
応じて調整される。この数値を越えると、そのようなソケットはクロー
ズされ、警告が表示される。
tcp_moderate_rcvbuf (Boolean; default: enabled; Linux 2.4.17/2.6.7 以
降)
有効にすると、TCP は受信バッファの自動調整を行う。具体的に は 、
(tcp_rmem[2] を超えない範囲で) バッファの大きさを自動的に変化さ
せ、その経路で最大のスループットを達成するのに必要な大きさに合わ
せようとする。
tcp_mem (Linux 2.4 以降)
これは 3 つの整数 [low, pressure, high] からなるベクトル値である
。これらは TCP がメモリ使用量を追跡するために用いられる (使用 量
は システムのページサイズ単位で計測される)。デフォルトはブート時
に利用できるメモリの量から計算される。 (実際には 、TCP は low
memory のみを使用する。値は 32ビットシステムでは約 900 メガバイ
トに制限される。 64 ビットシステムではこの制限はない。)
low TCP は、グローバルにアロケートしたページがこの数値以下
の場合は、メモリアロケーションを調整しない。
pressure TCP がアロケートしたメモリがこの数値分のページ数を越え
ると、 TCP はメモリ消費を抑えるようになる。アロケー ト
し たページ数が low 以下になると、このメモリ圧迫状態か
ら脱する。
high TCP がグローバルに割り当てるページ数の最大値。この値は
カーネルによって課されるあらゆる制限よりも優先される。
tcp_mtu_probing (integer; default: 0; Linux 2.6.17 以降)
このパラメータは、TCP のパケット化レイヤの Path MTU discovery を
制御する。このファイルには以下の値を設定できる。
0 無効にする。
1 デフォルトでは無効だが、ICMP ブラックホールが検出された場合は
有効にする。
2 常に有効にする。 MSS の初期値として tcp_base_mss が使用される
。
tcp_no_metrics_save (Boolean; default: disabled; Linux 2.6.6 以降)
デフォルトでは、TCP は接続クローズ時に各種の接続パラメータをルー
トキャッシュ (route cache) に保存し、近い将来に接続が確立され た
際にこれらの情報を初期状態として使用できるようになっている。通常
は、これにより全体として性能が向上するが、時として性能の劣化を引
き 起こすこともある。 tcp_no_metrics_save を有効にすると、TCP は
接続クローズ時に接続パラメータをキャッシュしなくなる。
tcp_orphan_retries (integer; default: 8; Linux 2.4 以降)
こちらからクローズした接続について、先方をプローブする最大試行数
。
tcp_reordering (integer; default: 3; Linux 2.4 以降)
TCP パケットストリームでパケット順序の逆転が発生しただけであり、
パケットロスが起こったとはみなさない、パケット数の最大値。この値
を超えてパケットの順序逆転が起こると、パケットロスが生じたとみな
し、slow start に入る。この数値は変更しないほうが良い。これは 、
接続中のパケットの並び替えによって生じる不必要な速度低下や再送を
最小化するように設計された、パケット並び替え (packet reordering)
の検知メトリックなのである。
tcp_retrans_collapse (Boolean; default: enabled; Linux 2.2 以降)
再送の際にフルサイズのパケットを送ろうとする。
tcp_retries1 (integer; default: 3; Linux 2.2 以降)
普 通に確立されている接続上に、 TCP がネットワーク層を巻き込まず
に再送を試みる回数。再送がこの回数を越えると、まず最初に、新しい
再送を送る前に可能ならネットワーク層に経路を更新させる。デフォル
トは RFC が指定している最少数である 3。
tcp_retries2 (integer; default: 15; Linux 2.2 以降)
確立状態の接続に、この回数 TCP パケットの再送信を行なってもだ め
な場合はあきらめる。デフォルト値は 15 で、これは (再送のタイムア
ウトに依存するが) およそ 13〜30 分程度の 期 間 に 対 応 す る 。
RFC 1122 は最小の限界を 100 秒と置いているが、これはたいていの場
合には短すぎると思われる。
tcp_rfc1337 (Boolean; default: disabled; Linux 2.2 以降)
TCP の動作を RFC 1337 に準拠させる。無効にすると、TIME_WAIT 状態
のときに RST が受信された場合、 TIME_WAIT 期間の終了を待たずにそ
のソケットを直ちにクローズする。
tcp_rmem (Linux 2.4 以降)
これは 3 つの整数 [min, default, max] からなるベクトル値である。
こ れ ら は TCP が受信バッファサイズを調整するために用いられる。
TCP は、システムで利用できるメモリに応じて、受信バッファのサイズ
をこれらの変数の範囲で以下に示すデフォルトから動的に調整する。
min 各 TCP ソケットが用いる受信バッファの最小サイズ。デフ
ォルト値はシステムのページサイズである (Linux 2.4 では
、デフォルト値は 4K バイトで、メモリの少ないシステムで
は PAGE_SIZE バイトに減らされる)。この値は、メモリ圧迫
モードにおいても、このサイズの割り当てが成功することを
保証するために用いられる。これは、 SO_RCVBUF を用い て
ソケットの最低受信バッファサイズを宣言する際には用いら
れない。
default TCP ソケットの受信バッファのデフォルトサイズ。この値は
、すべてのプロトコルに対して定義されている、ジェネリッ
クなグローバ ル の デ フ ォ ル ト バ ッ フ ァ サ イ ズ
net.core.rmem_default より優先される。デフォルト値は
87380 バイトである (Linux 2.4 では、メモリの少ないシス
テムの場合 43689 まで減らされる)。大きな受信バッファサ
イズが必要な場合は、この値を増やすべきである (すべての
ソケットに影響する)。大きな TCP ウィンドウを用いるには
、 net.ipv4.tcp_window_scaling を有効にしておかなけ れ
ばならない (デフォルトは有効)。
max 各 TCP ソケットで用いる受信バッファの最大サイズ。この
値よりもグローバルの net.core.rmem_max が優先される 。
こ れは、 SO_RCVBUF を用いてソケットの受信バッファサイ
ズ制限を宣言する際には用いられない。デフォルト値は以下
の式で計算される。
max(87380, min(4MB, tcp_mem[1]*PAGE_SIZE/128))
(Linux 2.4 では、デフォルト値は 87380*2 バイトで、メモ
リの少ないシステムでは 87380 まで減らされる。)
tcp_sack (Boolean; default: enabled; Linux 2.2 以降)
RFC 2018 の TCP Selective Acknowledgements を有効にする。
tcp_slow_start_after_idle (Boolean; default: enabled; Linux 2.6.18 以
降)
有効にすると、RFC 2861 の動作が行われ、アイドル時間経過後に輻 輳
ウィンドウをタイムアウトさせる。アイドル時間は現在の RTO (再送タ
イムアウト) で定義される。無効にすると、輻輳ウィンドウはアイドル
時間経過後もタイムアウトされない。
tcp_stdurg (Boolean; default: disabled; Linux 2.2 以降)
このオプションを有効にすると、 TCP 緊急ポインタ (urgent-pointer)
フィールドを RFC 1122 に従った解釈を行う。この解釈に従うと、緊急
ポインタは緊急データの最後のバイトを指す。このオプションを無効に
すると、緊急ポインタの解釈が BSD 互換の方法で行われる: 緊急ポ イ
ンタは緊急データの後の最初のバイトを指す。このオプションを有効に
すると、相互運用性に問題が生じるかもしれない。
tcp_syn_retries (integer; default: 5; Linux 2.2 以降)
アクティブな TCP 接続に初期 SYN の再送を試みる最大回数。この数値
は 255 よりも大きくすべきではない。デフォルトの値は 5 で、およそ
180 秒に対応する。
tcp_synack_retries (integer; default: 5; Linux 2.2 以降)
passive な TCP 接続の SYN/ACK セグメントで再送を試みる最大数。こ
の数値は 255 よりも大きくすべきではない。
tcp_syncookies (Boolean; Linux 2.2 以降)
CONFIG_SYNCOOKIES をつけてコンパイルしておかなければならない。ソ
ケットのバックログキューがオーバーフローすると、 syncookies が送
信される。 syncookies 機能は、SYN flood 攻撃からソケットを守ろう
とする。これはいずれにしても、最終手段として用いるべきである。こ
れは TCP プロトコルに違反しており、 TCP 拡張のような、TCP の他の
部分と衝突してしまう。クライアントやリレーで問題が起こることもあ
る。過負荷や設定間違いによって負荷の大きな状態にあるサーバを調整
して救うための機構とみなすべきではない。そのような用途には、代わ
りに tcp_max_syn_backlog, tcp_synack_retries, tcp_abort_on_over-
flow などの使用を考えること。
tcp_timestamps (Boolean; default: enabled; Linux 2.2 以降)
RFC 1323 の TCP timestamps を有効にする。
tcp_tso_win_divisor (integer; default: 3; Linux 2.6.9 以降)
このパラメータは、一つの TCP Segmentation Offload (TSO) フレーム
で消費できる輻輳ウィンドウの割合 (パーセント) を制御する。バース
ト性と、どれだけ大きな TSO フレームを構築するかのはトレードオ フ
であり、このパラメータはその度合いを設定する。
tcp_tw_recycle (Boolean; default: disabled; Linux 2.4 以降)
TIME_WAIT ソケットの素早い再利用を有効にする。このオプションを有
効にすると、 NAT (ネットワークアドレス変換) を用いていると問題が
生じるので、あまり推奨しない。
tcp_tw_reuse (Boolean; default: disabled; Linux 2.4.19/2.6 以降)
プロトコルの面から見て問題ない場合に新規コネクションに TIME_WAIT
状態のソケットを再利用することを許可する。技術的に詳しい人の助言
や要請なしにこのオプションを変更すべきではない。
tcp_vegas_cong_avoid (Boolean; default: disabled; Linux 2.2 から 2.6.13
まで)
TCP Vegas 輻輳制御アルゴリズムを有効にする。 TCP Vegas は帯域を
推測することで輻輳の起こり始めを予想するように TCP の送信側の み
に 変更を加えたものである。 TCP Vegas は輻輳ウィンドウを修正する
ことで、送信レートを調整する。 TCP Vegas は TCP Reno と比べて パ
ケットロスは少ないが、 TCP Reno ほど積極的な挙動はしない。
tcp_westwood (Boolean; default: disabled; Linux 2.4.26/2.6.3 から
2.6.13 まで)
TCP Westwood+ 輻輳制御アルゴリズムを有効にする。 TCP Westwood+
は TCP 輻輳制御の性能を最適化するように TCP Reno のプロトコル ス
タックの送信側のみに修正を加えたものである。輻輳が起こった後で、
輻輳ウィンドウや slow start の閾値を通信両端間の帯域の推測に基づ
いて設定する。この推測を使って、TCP Westwood+ は輻輳が発生した時
に使っていた帯域を考慮に入れた slow start の閾値と輻輳ウィンドウ
を設定する。 TCP Westwood+ は、有線ネットワークにおける TCP Reno
の公平性 (fairness) と、無線リンクでのスループットを大きく向上す
る。
tcp_window_scaling (Boolean; default: enabled; Linux 2.2 以降)
RFC 1323 の TCP ウィンドウスケーリングを有効にする。この機能を用
いると、接続先が対応していれば、 TCP 接続で大きな (64K 以 上 の)
ウ ィンドウが使えるようになる。通常は TCP ヘッダのウインドウ長フ
ィールドは 16 ビットなので、ウィンドウサイズは 64K バイト以下 に
限られる。もっと大きなウィンドウを使いたい場合は、アプリケーショ
ンはソケットバッファのサイズを増やして、ウィンドウスケーリングの
オプションを利用すればよい。 tcp_window_scaling を無効にしている
と、 TCP は他端との接続設定の際に、ウィンドウスケーリングのネ ゴ
シエーションを行なわない。
tcp_wmem (Linux 2.4 以降)
これは 3 つの整数 [min, default, max] からなるベクトル値である。
これらは TCP が送信バッファサイズを調整するために用いら れ る 。
TCP は、システムで利用できるメモリに応じて、送信バッファのサイズ
をこれらの変数の範囲で以下に示すデフォルトから動的に調整する。
min 各 TCP ソケットが用いる送信バッファの最小サイズ。デ フ
ォルト値はシステムのページサイズである (Linux 2.4 では
、デフォルト値は 4K である)。この値は、メモリ圧迫モ ー
ドにおいても、このサイズ以下の割り当てが成功することを
保証するために用いられる。これは、 SO_SNDBUF を用い て
ソケットの最低送信バッファサイズを宣言する際には用いら
れない。
default TCP ソケットの送信バッファのデフォルトサイズ。この値は
、すべてのプロトコルに対して定義されている、ジェネリッ
クなグローバ ル の デ フ ォ ル ト バ ッ フ ァ サ イ ズ
net.core.rmem_default より優先される。デフォルト値は
16K バイトである。大きな送信バッファサイズが必要な場合
は、この値を増やすべきである (すべてのソケットに影響す
る)。大きな TCP ウ ィ ン ド ウ を 用 い る に は 、
/proc/sys/net/ipv4/tcp_window_scaling を 0 以外の値 (
デフォルト値) にしておかなければならない。
max 各 TCP ソケットで用いる送信バッファの最大サイズ。こ の
値 よりも /proc/sys/net/core/wmem_max が優先される。こ
れは SO_SNDBUF を用いてソケットの送信バッファサイズ 制
限を宣言する際には用いられない。デフォルト値は以下の式
で計算される。
max(65536, min(4MB, tcp_mem[1]*PAGE_SIZE/128))
(Linux 2.4 では、デフォルト値は 128K バイトで、メモ リ
の少ないシステムでは 64K にまで減らされる。)
tcp_workaround_signed_windows (Boolean; default: disabled; Linux 2.6.26
以降)
有効にすると、ウィンドウスケーリングオプションを受信しないのは、
接続相手の TCP が壊れていると考え、ウィンドウを符号付きの量と み
なす。無効にすると、接続相手からウィンドウスケーリングオプション
を受信しなかった場合であっても、接続相手の TCP が壊れていると は
みなさない。
ソケットオプション
TCP ソケットのオプションは、オプションレベル引数に IPPROTO_TCP を指定し
た setsockopt(2) で設定でき、 getsockopt(2) で取得できる。さらに、ほ と
んどの IPPROTO_IP ソケットオプションも TCP ソケットに対して有効である。
詳細は ip(7) を見よ。
TCP_CORK (Linux 2.2 以降)
セットされると、 partial フレームを送信しない。このオプション が
解 除されると、キューイングされた partial フレームが送られる。こ
れは sendfile(2) を呼ぶ前にヘッダを前置したり、スループットを 最
適化したい場合に便利である。現在の実装では、 TCP_CORK で出力を抑
えることができる時間の上限は 200 ミリ秒である。この上限に達す る
と 、キューイングされたデータは自動的に送信される。 Linux 2.5.71
以降においてのみ、このオプションを TCP_NODELAY と同時に用いる こ
とができる。移植性の必要なプログラムではこのオプションを用いるべ
きではない。
TCP_DEFER_ACCEPT (Linux 2.4 以降)
これを用いると、リスナはデータがソケットに到着した時のみ目覚める
よ うになる。整数値 (秒) をとり、 TCP が接続を完了しようと試みる
回数を制限できる。移植性の必要なプログラムではこのオプションを用
いるべきではない。
TCP_INFO (Linux 2.4 以降)
こ の ソ ケ ッ ト の 情 報 を 収 集 す る のに用いる。カーネルは
/usr/include/linux/tcp.h ファイルで 定 義 さ れ て い る struct
tcp_info を返す。移植性の必要なプログラムではこのオプションを用
いるべきではない。
TCP_KEEPCNT (Linux 2.4 以降)
接続を落とす前に TCP が試みる keepalive プローブの最大回数。移植
性の必要なプログラムではこのオプションを用いるべきではない。
TCP_KEEPIDLE (Linux 2.4 以降)
この時間 (秒単位) を越えて接続がアイドル状態に留まっていると、こ
のソケットに SO_KEEPALIVE ソケットオプションが設定されている場合
、 TCP は keepalive プローブを送りはじめる。移植性の必要なプログ
ラムではこのオプションを用いるべきではない。
TCP_KEEPINTVL (Linux 2.4 以降)
各 keepalive プローブの間隔 (秒単位)。移植性の必要なプログラムで
はこのオプションを用いるべきではない。
TCP_LINGER2 (Linux 2.4 以降)
orphan された FIN_WAIT2 状態のソケットの寿命。このオプションを用
い る と 、 シ ス テ ム 全 体 に 適 用 さ れ る フ ァ イ ル
/proc/sys/net/ipv4/tcp_fin_timeout の値を、このソケットに対して
のみ変更できる。 socket(7) レベルのオプション SO_LINGER と混同し
ないこと。移植性の必要なプログラムではこのオプションを用いるべき
ではない。
TCP_MAXSEG
送出 TCP パケットの最大セグメントサイズ。このオプションを接続 確
立 の前に設定すると、初期パケットで他端にアナウンスする MSS の値
も変化する。インターフェースの MTU よりも大きな (あるいは大き く
な ってしまった) 値は効果を持たない。また TCP は、この値よりも最
小・最大の制限の方を優先する。
TCP_NODELAY
設定すると Nagle アルゴリズムを無効にする。すなわち、データ量 が
少ない場合でも各セグメントは可能な限り早く送信される。設定されて
いないと、送信する分だけ溜まるまでデータはバッファされ、小さなパ
ケットを頻繁に送らずにすみ、ネットワークを有効に利用できる。この
オプションは TCP_CORK により上書きされる 。 し か し な が ら 、
TCP_CORK が設定されている場合であっても、このオプションを設定す
ると、送信待ちの出力を明示的に掃き出す (flush) ことになる。
TCP_QUICKACK (Linux 2.4.4 以降)
設定されていると quickack モードを有効にし、クリアされると無効に
する。通常の TCP 動作では ack は必要に応じて遅延されるのに対し、
quickack モードでは ack はすぐに送信される。このフラグは永続的な
も のではなく、 quickack モードから/モードへ切り替えるためのもの
である。これ以降の TCP プロトコルの動作によっては、内部のプロ ト
コ ル処理や、遅延 ack タイムアウトの発生、データ転送などの要因に
よって、再び quickack から出たり入ったりする。移植性の必要なプロ
グラムではこのオプションを用いるべきではない。
TCP_SYNCNT (Linux 2.4 以降)
接続の試行を中止させる前に TCP が送る SYN 再送数を設定する。これ
は 255 より大きくはできない。移植性の必要なプログラムではこの オ
プションを用いるべきではない。
TCP_WINDOW_CLAMP (Linux 2.4 以降)
広報するウィンドウのサイズをこの値に固定する。カーネルによって最
小サイズは SOCK_MIN_RCVBUF/2 に制限されている。このオプション は
移植性の必要なコードでは用いるべきでない。
ソケット API
TCP は帯域外データ (out-of-band data) を限定的にサポートしており、 (1
バイトの) 緊急データという形である。つまり Linux においては、接続先が (
新 しいやり方の) 帯域外データを送ってきた場合、 (古いやり方の) 緊急デー
タは通常のデータとしてストリームに挿入される こ と に な る ( こ れ は
SO_OOBINLINE がセットされている場合でも同様である)。これは BSD ベースの
スタックとは異なる。
Linux は、デフォルトでは urgent ポインタフィールドの解釈に BSD 互換の方
法 を用いる。これは RFC 1122 に反しているが、他のスタックと同時に動作さ
せるにはやむを得ない。これは /proc/sys/net/ipv4/tcp_stdurg によって変更
できる。
recv(2) の MSG_PEEK フラグを使うと、帯域外データを覗き見することができ
る。
Linux 2.4 以降では、 recv(2) (や recvmsg(2)) の flags 引 き 数 に
MSG_TRUNC を使うことができる。このフラグを指定すると、受信データは、呼
び出し元から渡されたバッファにコピーされて返されるのではなく、廃棄さ れ
るようになる。 Linux 2.4.4 以降では、 MSG_PEEK を、帯域外データを受信す
るための MSG_OOB と組み合わせて使った場合にも、これと同じ効果を持つよう
になっている。
ioctl
以下の ioctl(2) 呼び出しは value に情報を入れて返す。正しい書式は以下の
通り。
int value;
error = ioctl(tcp_socket, ioctl_type, &value);
ioctl_type は以下のいずれか一つである:
SIOCINQ
受信バッファのキューにある、まだ読んでいないデータの量を返す。ソ
ケ ットは LISTEN 状態にあってはならず、さもないとエラー (EINVAL)
が返る。
SIOCATMARK
受信データストリームが緊急マークの位置であれば、真を返す (つまり
value が 0 以外)。
SO_OOBINLINE ソケットオプションが設定されていて、 SIOCATMARK が
真を返した場合、次のソケットからの読み込みでは緊急データが返され
る。 SO_OOBINLINE ソケットオプションが設定されておらず、 SIOCAT-
MARK が真を返した場合、次のソケットからの読み込みでは緊急デー タ
に 続 く デ ー タ が 返 さ れ る (実際に緊急データを読み込むには
recv(MSG_OOB) とフラグをつける必要がある)。
データの一回の読み込みでは緊急マークを跨がっての読み込みは行われ
ない。アプリケーションが緊急データの存在を (exceptfds 引き数を使
って) select(2) 経由または SIGURG シグナルの配送を通じて知らされ
た場合、 SIOCATMARK のチェックと読み込み (何バイト読み込み要求を
してもよい) を SIOCATMARK が偽を返さなくなるまで繰り返し行うこと
で、緊急マークの位置まで読み進めることができる。
SIOCOUTQ
ソケットの送信キューに残っている未送信データの量を返す。ソケット
は LISTEN 状態にあってはならない。 LISTEN 状態の場合にはエ ラ ー
(EINVAL) となる。
エラー処理
ネットワークエラーが起こると、 TCP はパケットの再送を試みる。何回かやっ
ても成功しなければ、この接続に対して ETIMEOUT エラーか最後に受信した エ
ラーが返される。
ア プリケーションによっては、もっと早くエラーを知らせてほしい場合がある
。これには IPPROTO_IP レベルの IP_RECVERR ソケットオプションを用いる と
良 い。このオプションが有効になっていると、到着したエラーはすべてただち
にユーザープログラムに渡される。このオプションは慎重に用いること — ルー
ティングの変更など、通常ありうるネットワーク状態に対して TCP をより脆弱
にしてしまう。
エラー
EAFNOTSUPPORT
sin_family に渡されたソケットアドレスのタイプが AF_INET ではなか
った。
EPIPE 接続先が予期しなかったかたちでソケットをクローズした。またはシャ
ットダウンされたソケットに読み込みが実行された。
ETIMEDOUT
接続先が、何回かデータを再送しても反応しない。
ip(7) で定義されているエラーや、ジェネリックなソケット層におけるエラ ー
も TCP に返されることがある。
バージョン
Explicit Congestion Notification、zero-copy の sendfile(2)、並び替えの
サポート、SACK 拡張 (DSACK) などのサポートは 2.4 で導入された。フォワー
ド 確認 (FACK)、TIME_WAIT リサイクル、接続ごとの keepalive に対するソケ
ットオプションは 2.3 で導入された。
バグ
まだ説明されていないエラーがある。
IPv6 に関する記述がない。
関連項目
accept(2), bind(2), connect(2), getsockopt(2), listen(2), recvmsg(2),
sendfile(2), sendmsg(2), socket(2), ip(7), socket(7)
RFC 793: TCP の仕様。
RFC 1122: TCP の要求事項と Nagle アルゴリズムの記述。
RFC 1323: TCP のタイムスタンプ・ウィンドウスケーリング各オプション。
RFC 1644: TIME_WAIT assassination hazard に関する記述。
RFC 3168: Explicit Congestion Notification に関する記述。
RFC 2581: TCP 輻輳制御アルゴリズム。
RFC 2018 と RFC 2883: SACK とその拡張。
Linux 2008-12-01 TCP(7)
TCP(7) Linux Programmer’s Manual TCP(7)
NAME
tcp - TCP protocol
SYNOPSIS
#include
#include
#include
tcp_socket = socket(AF_INET, SOCK_STREAM, 0);
DESCRIPTION
This is an implementation of the TCP protocol defined in RFC 793,
RFC 1122 and RFC 2001 with the NewReno and SACK extensions. It pro-
vides a reliable, stream-oriented, full-duplex connection between two
sockets on top of ip(7), for both v4 and v6 versions. TCP guarantees
that the data arrives in order and retransmits lost packets. It gener-
ates and checks a per-packet checksum to catch transmission errors.
TCP does not preserve record boundaries.
A newly created TCP socket has no remote or local address and is not
fully specified. To create an outgoing TCP connection use connect(2)
to establish a connection to another TCP socket. To receive new incom-
ing connections, first bind(2) the socket to a local address and port
and then call listen(2) to put the socket into the listening state.
After that a new socket for each incoming connection can be accepted
using accept(2). A socket which has had accept(2) or connect(2) suc-
cessfully called on it is fully specified and may transmit data. Data
cannot be transmitted on listening or not yet connected sockets.
Linux supports RFC 1323 TCP high performance extensions. These include
Protection Against Wrapped Sequence Numbers (PAWS), Window Scaling and
Timestamps. Window scaling allows the use of large (> 64K) TCP windows
in order to support links with high latency or bandwidth. To make use
of them, the send and receive buffer sizes must be increased. They can
be set globally with the /proc/sys/net/ipv4/tcp_wmem and
/proc/sys/net/ipv4/tcp_rmem files, or on individual sockets by using
the SO_SNDBUF and SO_RCVBUF socket options with the setsockopt(2) call.
The maximum sizes for socket buffers declared via the SO_SNDBUF and
SO_RCVBUF mechanisms are limited by the values in the
/proc/sys/net/core/rmem_max and /proc/sys/net/core/wmem_max files.
Note that TCP actually allocates twice the size of the buffer requested
in the setsockopt(2) call, and so a succeeding getsockopt(2) call will
not return the same size of buffer as requested in the setsockopt(2)
call. TCP uses the extra space for administrative purposes and inter-
nal kernel structures, and the /proc file values reflect the larger
sizes compared to the actual TCP windows. On individual connections,
the socket buffer size must be set prior to the listen(2) or connect(2)
calls in order to have it take effect. See socket(7) for more informa-
tion.
TCP supports urgent data. Urgent data is used to signal the receiver
that some important message is part of the data stream and that it
should be processed as soon as possible. To send urgent data specify
the MSG_OOB option to send(2). When urgent data is received, the ker-
nel sends a SIGURG signal to the process or process group that has been
set as the socket "owner" using the SIOCSPGRP or FIOSETOWN ioctls (or
the POSIX.1-2001-specified fcntl(2) F_SETOWN operation). When the
SO_OOBINLINE socket option is enabled, urgent data is put into the nor-
mal data stream (a program can test for its location using the SIOCAT-
MARK ioctl described below), otherwise it can be only received when the
MSG_OOB flag is set for recv(2) or recvmsg(2).
Linux 2.4 introduced a number of changes for improved throughput and
scaling, as well as enhanced functionality. Some of these features
include support for zero-copy sendfile(2), Explicit Congestion Notifi-
cation, new management of TIME_WAIT sockets, keep-alive socket options
and support for Duplicate SACK extensions.
Address Formats
TCP is built on top of IP (see ip(7)). The address formats defined by
ip(7) apply to TCP. TCP only supports point-to-point communication;
broadcasting and multicasting are not supported.
/proc interfaces
System-wide TCP parameter settings can be accessed by files in the
directory /proc/sys/net/ipv4/. In addition, most IP /proc interfaces
also apply to TCP; see ip(7). Variables described as Boolean take an
integer value, with a non-zero value ("true") meaning that the corre-
sponding option is enabled, and a zero value ("false") meaning that the
option is disabled.
tcp_abc (Integer; default: 0; since Linux 2.6.15)
Controls the Appropriate Byte Count (ABC), defined in RFC 3465.
ABC is a way of increasing the congestion window (cwnd) more
slowly in response to partial acknowledgments. Possible values
are:
0 increase cwnd once per acknowledgment (no ABC)
1 increase cwnd once per acknowledgment of full sized segment
2 allow increase cwnd by two if acknowledgment is of two seg-
ments to compensate for delayed acknowledgments.
tcp_abort_on_overflow (Boolean; default: disabled; since Linux 2.4)
Enable resetting connections if the listening service is too
slow and unable to keep up and accept them. It means that if
overflow occurred due to a burst, the connection will recover.
Enable this option only if you are really sure that the listen-
ing daemon cannot be tuned to accept connections faster.
Enabling this option can harm the clients of your server.
tcp_adv_win_scale (integer; default: 2; since Linux 2.4)
Count buffering overhead as bytes/2^tcp_adv_win_scale, if
tcp_adv_win_scale is greater than 0; or bytes-
bytes/2^(-tcp_adv_win_scale), if tcp_adv_win_scale is less than
or equal to zero.
The socket receive buffer space is shared between the applica-
tion and kernel. TCP maintains part of the buffer as the TCP
window, this is the size of the receive window advertised to the
other end. The rest of the space is used as the "application"
buffer, used to isolate the network from scheduling and applica-
tion latencies. The tcp_adv_win_scale default value of 2
implies that the space used for the application buffer is one
fourth that of the total.
tcp_allowed_congestion_control (String; default: see text; since Linux
2.4.20)
Show/set the congestion control choices available to non-privi-
leged processes (see the description of the TCP_CONGESTION
socket option). The list is a subset of those listed in
tcp_available_congestion_control. The default value for this
list is "reno" plus the default setting of tcp_congestion_con-
trol.
tcp_available_congestion_control (String; read-only; since Linux
2.4.20)
Shows a list of the congestion-control algorithms that are
registered. This list is a limiting set for the list in
tcp_allowed_congestion_control. More congestion-control algo-
rithms may be available as modules, but not loaded.
tcp_app_win (integer; default: 31; since Linux 2.4)
This variable defines how many bytes of the TCP window are
reserved for buffering overhead.
A maximum of (window/2^tcp_app_win, mss) bytes in the window are
reserved for the application buffer. A value of 0 implies that
no amount is reserved.
tcp_base_mss (Integer; default: 512; since Linux 2.6.17)
The initial value of search_low to be used by the packetization
layer Path MTU discovery (MTU probing). If MTU probing is
enabled, this is the initial MSS used by the connection.
tcp_bic (Boolean; default: disabled; Linux 2.4.27/2.6.6 to 2.6.13)
Enable BIC TCP congestion control algorithm. BIC-TCP is a
sender-side only change that ensures a linear RTT fairness under
large windows while offering both scalability and bounded TCP-
friendliness. The protocol combines two schemes called additive
increase and binary search increase. When the congestion window
is large, additive increase with a large increment ensures lin-
ear RTT fairness as well as good scalability. Under small con-
gestion windows, binary search increase provides TCP friendli-
ness.
tcp_bic_low_window (integer; default: 14; Linux 2.4.27/2.6.6 to 2.6.13)
Sets the threshold window (in packets) where BIC TCP starts to
adjust the congestion window. Below this threshold BIC TCP
behaves the same as the default TCP Reno.
tcp_bic_fast_convergence (Boolean; default: enabled; Linux 2.4.27/2.6.6
to 2.6.13)
Forces BIC TCP to more quickly respond to changes in congestion
window. Allows two flows sharing the same connection to con-
verge more rapidly.
tcp_congestion_control (String; default: enabled; since Linux 2.4.13)
Set the default congestion-control algorithm to be used for new
connections. The algorithm "reno" is always available, but
additional choices may be available depending on kernel configu-
ration. The default value for this file is set as part of ker-
nel configuration.
tcp_dma_copybreak (integer; default: 4096; since Linux 2.6.24)
Lower limit, in bytes, of the size of socket reads that will be
offloaded to a DMA copy engine, if one is present in the system
and the kernel was configured with the CONFIG_NET_DMA option.
tcp_dsack (Boolean; default: enabled; since Linux 2.4)
Enable RFC 2883 TCP Duplicate SACK support.
tcp_ecn (Boolean; default: disabled; since Linux 2.4)
Enable RFC 2884 Explicit Congestion Notification. When enabled,
connectivity to some destinations could be affected due to
older, misbehaving routers along the path causing connections to
be dropped.
tcp_fack (Boolean; default: enabled; since Linux 2.2)
Enable TCP Forward Acknowledgement support.
tcp_fin_timeout (integer; default: 60; since Linux 2.2)
This specifies how many seconds to wait for a final FIN packet
before the socket is forcibly closed. This is strictly a viola-
tion of the TCP specification, but required to prevent denial-
of-service attacks. In Linux 2.2, the default value was 180.
tcp_frto (integer; default: 0; since Linux 2.4.21/2.6)
Enables F-RTO, an enhanced recovery algorithm for TCP retrans-
mission timeouts (RTOs). It is particularly beneficial in wire-
less environments where packet loss is typically due to random
radio interference rather than intermediate router congestion.
See RFC 4138 for more details.
This file can have one of the following values:
0 Disabled.
1 The basic version F-RTO algorithm is enabled.
2 Enable SACK-enhanced F-RTO if flow uses SACK. The basic ver-
sion can be used also when SACK is in use though in that case
scenario(s) exists where F-RTO interacts badly with the
packet counting of the SACK-enabled TCP flow.
Before Linux 2.6.22, this parameter was a Boolean value, sup-
porting just values 0 and 1 above.
tcp_frto_response (integer; default: 0; since Linux 2.6.22)
When F-RTO has detected that a TCP retransmission timeout was
spurious (i.e, the timeout would have been avoided had TCP set a
longer retransmission timeout), TCP has several options concern-
ing what to do next. Possible values are:
0 Rate halving based; a smooth and conservative response,
results in halved congestion window (cwnd) and slow-start
threshold (ssthresh) after one RTT.
1 Very conservative response; not recommended because even
though being valid, it interacts poorly with the rest of
Linux TCP; halves cwnd and ssthresh immediately.
2 Aggressive response; undoes congestion-control measures that
are now known to be unnecessary (ignoring the possibility of
a lost retransmission that would require TCP to be more cau-
tious); cwnd and ssthresh are restored to the values prior to
timeout.
tcp_keepalive_intvl (integer; default: 75; since Linux 2.4)
The number of seconds between TCP keep-alive probes.
tcp_keepalive_probes (integer; default: 9; since Linux 2.2)
The maximum number of TCP keep-alive probes to send before giv-
ing up and killing the connection if no response is obtained
from the other end.
tcp_keepalive_time (integer; default: 7200; since Linux 2.2)
The number of seconds a connection needs to be idle before TCP
begins sending out keep-alive probes. Keep-alives are only sent
when the SO_KEEPALIVE socket option is enabled. The default
value is 7200 seconds (2 hours). An idle connection is termi-
nated after approximately an additional 11 minutes (9 probes an
interval of 75 seconds apart) when keep-alive is enabled.
Note that underlying connection tracking mechanisms and applica-
tion timeouts may be much shorter.
tcp_low_latency (Boolean; default: disabled; since Linux 2.4.21/2.6)
If enabled, the TCP stack makes decisions that prefer lower
latency as opposed to higher throughput. It this option is dis-
abled, then higher throughput is preferred. An example of an
application where this default should be changed would be a
Beowulf compute cluster.
tcp_max_orphans (integer; default: see below; since Linux 2.4)
The maximum number of orphaned (not attached to any user file
handle) TCP sockets allowed in the system. When this number is
exceeded, the orphaned connection is reset and a warning is
printed. This limit exists only to prevent simple denial-of-
service attacks. Lowering this limit is not recommended. Net-
work conditions might require you to increase the number of
orphans allowed, but note that each orphan can eat up to ~64K of
unswappable memory. The default initial value is set equal to
the kernel parameter NR_FILE. This initial default is adjusted
depending on the memory in the system.
tcp_max_syn_backlog (integer; default: see below; since Linux 2.2)
The maximum number of queued connection requests which have
still not received an acknowledgement from the connecting
client. If this number is exceeded, the kernel will begin drop-
ping requests. The default value of 256 is increased to 1024
when the memory present in the system is adequate or greater (>=
128Mb), and reduced to 128 for those systems with very low mem-
ory (<= 32Mb). It is recommended that if this needs to be
increased above 1024, TCP_SYNQ_HSIZE in include/net/tcp.h be
modified to keep TCP_SYNQ_HSIZE*16<=tcp_max_syn_backlog, and the
kernel be recompiled.
tcp_max_tw_buckets (integer; default: see below; since Linux 2.4)
The maximum number of sockets in TIME_WAIT state allowed in the
system. This limit exists only to prevent simple denial-of-ser-
vice attacks. The default value of NR_FILE*2 is adjusted
depending on the memory in the system. If this number is
exceeded, the socket is closed and a warning is printed.
tcp_moderate_rcvbuf (Boolean; default: enabled; since Linux
2.4.17/2.6.7)
If enabled, TCP performs receive buffer auto-tuning, attempting
to automatically size the buffer (no greater than tcp_rmem[2])
to match the size required by the path for full throughput.
tcp_mem (since Linux 2.4)
This is a vector of 3 integers: [low, pressure, high]. These
bounds, measured in units of the system page size, are used by
TCP to track its memory usage. The defaults are calculated at
boot time from the amount of available memory. (TCP can only
use low memory for this, which is limited to around 900
megabytes on 32-bit systems. 64-bit systems do not suffer this
limitation.)
low TCP doesn’t regulate its memory allocation when the
number of pages it has allocated globally is below
this number.
pressure When the amount of memory allocated by TCP exceeds
this number of pages, TCP moderates its memory con-
sumption. This memory pressure state is exited once
the number of pages allocated falls below the low
mark.
high The maximum number of pages, globally, that TCP will
allocate. This value overrides any other limits
imposed by the kernel.
tcp_mtu_probing (integer; default: 0; since Linux 2.6.17)
This parameter controls TCP Packetization-Layer Path MTU Discov-
ery. The following values may be assigned to the file:
0 Disabled
1 Disabled by default, enabled when an ICMP black hole detected
2 Always enabled, use initial MSS of tcp_base_mss.
tcp_no_metrics_save (Boolean; default: disabled; since Linux 2.6.6)
By default, TCP saves various connection metrics in the route
cache when the connection closes, so that connections estab-
lished in the near future can use these to set initial condi-
tions. Usually, this increases overall performance, but it may
sometimes cause performance degradation. If tcp_no_metrics_save
is enabled, TCP will not cache metrics on closing connections.
tcp_orphan_retries (integer; default: 8; since Linux 2.4)
The maximum number of attempts made to probe the other end of a
connection which has been closed by our end.
tcp_reordering (integer; default: 3; since Linux 2.4)
The maximum a packet can be reordered in a TCP packet stream
without TCP assuming packet loss and going into slow start. It
is not advisable to change this number. This is a packet
reordering detection metric designed to minimize unnecessary
back off and retransmits provoked by reordering of packets on a
connection.
tcp_retrans_collapse (Boolean; default: enabled; since Linux 2.2)
Try to send full-sized packets during retransmit.
tcp_retries1 (integer; default: 3; since Linux 2.2)
The number of times TCP will attempt to retransmit a packet on
an established connection normally, without the extra effort of
getting the network layers involved. Once we exceed this number
of retransmits, we first have the network layer update the route
if possible before each new retransmit. The default is the RFC
specified minimum of 3.
tcp_retries2 (integer; default: 15; since Linux 2.2)
The maximum number of times a TCP packet is retransmitted in
established state before giving up. The default value is 15,
which corresponds to a duration of approximately between 13 to
30 minutes, depending on the retransmission timeout. The
RFC 1122 specified minimum limit of 100 seconds is typically
deemed too short.
tcp_rfc1337 (Boolean; default: disabled; since Linux 2.2)
Enable TCP behavior conformant with RFC 1337. When disabled, if
a RST is received in TIME_WAIT state, we close the socket imme-
diately without waiting for the end of the TIME_WAIT period.
tcp_rmem (since Linux 2.4)
This is a vector of 3 integers: [min, default, max]. These
parameters are used by TCP to regulate receive buffer sizes.
TCP dynamically adjusts the size of the receive buffer from the
defaults listed below, in the range of these values, depending
on memory available in the system.
min minimum size of the receive buffer used by each TCP
socket. The default value is the system page size.
(On Linux 2.4, the default value is 4K, lowered to
PAGE_SIZE bytes in low-memory systems.) This value is
used to ensure that in memory pressure mode, alloca-
tions below this size will still succeed. This is not
used to bound the size of the receive buffer declared
using SO_RCVBUF on a socket.
default the default size of the receive buffer for a TCP
socket. This value overwrites the initial default
buffer size from the generic global
net.core.rmem_default defined for all protocols. The
default value is 87380 bytes. (On Linux 2.4, this
will be lowered to 43689 in low-memory systems.) If
larger receive buffer sizes are desired, this value
should be increased (to affect all sockets). To
employ large TCP windows, the net.ipv4.tcp_win-
dow_scaling must be enabled (default).
max the maximum size of the receive buffer used by each
TCP socket. This value does not override the global
net.core.rmem_max. This is not used to limit the size
of the receive buffer declared using SO_RCVBUF on a
socket. The default value is calculated using the
formula
max(87380, min(4MB, tcp_mem[1]*PAGE_SIZE/128))
(On Linux 2.4, the default is 87380*2 bytes, lowered
to 87380 in low-memory systems).
tcp_sack (Boolean; default: enabled; since Linux 2.2)
Enable RFC 2018 TCP Selective Acknowledgements.
tcp_slow_start_after_idle (Boolean; default: enabled; since Linux
2.6.18)
If enabled, provide RFC 2861 behavior and time out the conges-
tion window after an idle period. An idle period is defined as
the current RTO (retransmission timeout). If disabled, the con-
gestion window will not be timed out after an idle period.
tcp_stdurg (Boolean; default: disabled; since Linux 2.2)
If this option is enabled, then use the RFC 1122 interpretation
of the TCP urgent-pointer field. According to this interpreta-
tion, the urgent pointer points to the last byte of urgent data.
If this option is disabled, then use the BSD-compatible inter-
pretation of the urgent pointer: the urgent pointer points to
the first byte after the urgent data. Enabling this option may
lead to interoperability problems.
tcp_syn_retries (integer; default: 5; since Linux 2.2)
The maximum number of times initial SYNs for an active TCP con-
nection attempt will be retransmitted. This value should not be
higher than 255. The default value is 5, which corresponds to
approximately 180 seconds.
tcp_synack_retries (integer; default: 5; since Linux 2.2)
The maximum number of times a SYN/ACK segment for a passive TCP
connection will be retransmitted. This number should not be
higher than 255.
tcp_syncookies (Boolean; since Linux 2.2)
Enable TCP syncookies. The kernel must be compiled with CON-
FIG_SYN_COOKIES. Send out syncookies when the syn backlog queue
of a socket overflows. The syncookies feature attempts to pro-
tect a socket from a SYN flood attack. This should be used as a
last resort, if at all. This is a violation of the TCP proto-
col, and conflicts with other areas of TCP such as TCP exten-
sions. It can cause problems for clients and relays. It is not
recommended as a tuning mechanism for heavily loaded servers to
help with overloaded or misconfigured conditions. For recom-
mended alternatives see tcp_max_syn_backlog, tcp_synack_retries,
and tcp_abort_on_overflow.
tcp_timestamps (Boolean; default: enabled; since Linux 2.2)
Enable RFC 1323 TCP timestamps.
tcp_tso_win_divisor (integer; default: 3; since Linux 2.6.9)
This parameter controls what percentage of the congestion window
can be consumed by a single TCP Segmentation Offload (TSO)
frame. The setting of this parameter is a tradeoff between
burstiness and building larger TSO frames.
tcp_tw_recycle (Boolean; default: disabled; since Linux 2.4)
Enable fast recycling of TIME_WAIT sockets. Enabling this
option is not recommended since this causes problems when work-
ing with NAT (Network Address Translation).
tcp_tw_reuse (Boolean; default: disabled; since Linux 2.4.19/2.6)
Allow to reuse TIME_WAIT sockets for new connections when it is
safe from protocol viewpoint. It should not be changed without
advice/request of technical experts.
tcp_vegas_cong_avoid (Boolean; default: disabled; Linux 2.2 to 2.6.13)
Enable TCP Vegas congestion avoidance algorithm. TCP Vegas is a
sender-side only change to TCP that anticipates the onset of
congestion by estimating the bandwidth. TCP Vegas adjusts the
sending rate by modifying the congestion window. TCP Vegas
should provide less packet loss, but it is not as aggressive as
TCP Reno.
tcp_westwood (Boolean; default: disabled; Linux 2.4.26/2.6.3 to 2.6.13)
Enable TCP Westwood+ congestion control algorithm. TCP West-
wood+ is a sender-side only modification of the TCP Reno proto-
col stack that optimizes the performance of TCP congestion con-
trol. It is based on end-to-end bandwidth estimation to set
congestion window and slow start threshold after a congestion
episode. Using this estimation, TCP Westwood+ adaptively sets a
slow start threshold and a congestion window which takes into
account the bandwidth used at the time congestion is experi-
enced. TCP Westwood+ significantly increases fairness with
respect to TCP Reno in wired networks and throughput over wire-
less links.
tcp_window_scaling (Boolean; default: enabled; since Linux 2.2)
Enable RFC 1323 TCP window scaling. This feature allows the use
of a large window (> 64K) on a TCP connection, should the other
end support it. Normally, the 16 bit window length field in the
TCP header limits the window size to less than 64K bytes. If
larger windows are desired, applications can increase the size
of their socket buffers and the window scaling option will be
employed. If tcp_window_scaling is disabled, TCP will not nego-
tiate the use of window scaling with the other end during con-
nection setup.
tcp_wmem (since Linux 2.4)
This is a vector of 3 integers: [min, default, max]. These
parameters are used by TCP to regulate send buffer sizes. TCP
dynamically adjusts the size of the send buffer from the default
values listed below, in the range of these values, depending on
memory available.
min Minimum size of the send buffer used by each TCP
socket. The default value is the system page size.
(On Linux 2.4, the default value is 4K bytes.) This
value is used to ensure that in memory pressure mode,
allocations below this size will still succeed. This
is not used to bound the size of the send buffer
declared using SO_SNDBUF on a socket.
default The default size of the send buffer for a TCP socket.
This value overwrites the initial default buffer size
from the generic global net.core.wmem_default defined
for all protocols. The default value is 16K bytes.
If larger send buffer sizes are desired, this value
should be increased (to affect all sockets). To
employ large TCP windows, the
/proc/sys/net/ipv4/tcp_window_scaling must be set to a
non-zero value (default).
max The maximum size of the send buffer used by each TCP
socket. This value does not override the value in
/proc/sys/net/core/wmem_max. This is not used to
limit the size of the send buffer declared using
SO_SNDBUF on a socket. The default value is calcu-
lated using the formula
max(65536, min(4MB, tcp_mem[1]*PAGE_SIZE/128))
(On Linux 2.4, the default value is 128K bytes, low-
ered 64K depending on low-memory systems.)
tcp_workaround_signed_windows (Boolean; default: disabled; since Linux
2.6.26)
If enabled, assume that no receipt of a window-scaling option
means that the remote TCP is broken and treats the window as a
signed quantity. If disabled, assume that the remote TCP is not
broken even if we do not receive a window scaling option from
it.
Socket Options
To set or get a TCP socket option, call getsockopt(2) to read or set-
sockopt(2) to write the option with the option level argument set to
IPPROTO_TCP. In addition, most IPPROTO_IP socket options are valid on
TCP sockets. For more information see ip(7).
TCP_CONGESTION (since Linux 2.6.13)
Get or set the congestion-control algorithm for this socket.
The optval argument is a pointer to a character-string buffer.
For getsockopt() *optlen specifies the amount of space available
in the buffer pointed to by optval, which should be at least 16
bytes (defined by the kernel-internal constant TCP_CA_NAME_MAX).
On return, the buffer pointed to by optval is set to a null-ter-
minated string containing the name of the congestion-control
algorithm for this socket, and *optlen is set to the minimum of
its original value and TCP_CA_NAME_MAX. If the value passed in
*optlen is too small, then the string returned in *optval is
silently truncated, and no terminating null byte is added. If
an empty string is returned, then the socket is using the
default congestion-control algorithm, determined as described
under tcp_congestion_control above.
For setsockopt() optlen specifies the length of the congestion-
control algorithm name contained in the buffer pointed to by
optval; this length need not include any terminating null byte.
The algorithm "reno" is always permitted; other algorithms may
be available, depending on kernel configuration. Possible
errors from setsockopt() include: algorithm not found/available
(ENOENT); setting this algorithm requires the CAP_NET_ADMIN
capability (EPERM); and failure getting kernel module (EBUSY).
TCP_CORK (since Linux 2.2)
If set, don’t send out partial frames. All queued partial
frames are sent when the option is cleared again. This is use-
ful for prepending headers before calling sendfile(2), or for
throughput optimization. As currently implemented, there is a
200 millisecond ceiling on the time for which output is corked
by TCP_CORK. If this ceiling is reached, then queued data is
automatically transmitted. This option can be combined with
TCP_NODELAY only since Linux 2.5.71. This option should not be
used in code intended to be portable.
TCP_DEFER_ACCEPT (since Linux 2.4)
Allows a listener to be awakened only when data arrives on the
socket. Takes an integer value (seconds), this can bound the
maximum number of attempts TCP will make to complete the connec-
tion. This option should not be used in code intended to be
portable.
TCP_INFO (since Linux 2.4)
Used to collect information about this socket. The kernel
returns a struct tcp_info as defined in the file
/usr/include/linux/tcp.h. This option should not be used in
code intended to be portable.
TCP_KEEPCNT (since Linux 2.4)
The maximum number of keepalive probes TCP should send before
dropping the connection. This option should not be used in code
intended to be portable.
TCP_KEEPIDLE (since Linux 2.4)
The time (in seconds) the connection needs to remain idle before
TCP starts sending keepalive probes, if the socket option
SO_KEEPALIVE has been set on this socket. This option should
not be used in code intended to be portable.
TCP_KEEPINTVL (since Linux 2.4)
The time (in seconds) between individual keepalive probes. This
option should not be used in code intended to be portable.
TCP_LINGER2 (since Linux 2.4)
The lifetime of orphaned FIN_WAIT2 state sockets. This option
can be used to override the system-wide setting in the file
/proc/sys/net/ipv4/tcp_fin_timeout for this socket. This is not
to be confused with the socket(7) level option SO_LINGER. This
option should not be used in code intended to be portable.
TCP_MAXSEG
The maximum segment size for outgoing TCP packets. If this
option is set before connection establishment, it also changes
the MSS value announced to the other end in the initial packet.
Values greater than the (eventual) interface MTU have no effect.
TCP will also impose its minimum and maximum bounds over the
value provided.
TCP_NODELAY
If set, disable the Nagle algorithm. This means that segments
are always sent as soon as possible, even if there is only a
small amount of data. When not set, data is buffered until
there is a sufficient amount to send out, thereby avoiding the
frequent sending of small packets, which results in poor uti-
lization of the network. This option is overridden by TCP_CORK;
however, setting this option forces an explicit flush of pending
output, even if TCP_CORK is currently set.
TCP_QUICKACK (since Linux 2.4.4)
Enable quickack mode if set or disable quickack mode if cleared.
In quickack mode, acks are sent immediately, rather than delayed
if needed in accordance to normal TCP operation. This flag is
not permanent, it only enables a switch to or from quickack
mode. Subsequent operation of the TCP protocol will once again
enter/leave quickack mode depending on internal protocol pro-
cessing and factors such as delayed ack timeouts occurring and
data transfer. This option should not be used in code intended
to be portable.
TCP_SYNCNT (since Linux 2.4)
Set the number of SYN retransmits that TCP should send before
aborting the attempt to connect. It cannot exceed 255. This
option should not be used in code intended to be portable.
TCP_WINDOW_CLAMP (since Linux 2.4)
Bound the size of the advertised window to this value. The ker-
nel imposes a minimum size of SOCK_MIN_RCVBUF/2. This option
should not be used in code intended to be portable.
Sockets API
TCP provides limited support for out-of-band data, in the form of (a
single byte of) urgent data. In Linux this means if the other end
sends newer out-of-band data the older urgent data is inserted as nor-
mal data into the stream (even when SO_OOBINLINE is not set). This
differs from BSD-based stacks.
Linux uses the BSD compatible interpretation of the urgent pointer
field by default. This violates RFC 1122, but is required for interop-
erability with other stacks. It can be changed via
/proc/sys/net/ipv4/tcp_stdurg.
It is possible to peek at out-of-band data using the recv(2) MSG_PEEK
flag.
Since version 2.4, Linux supports the use of MSG_TRUNC in the flags
argument of recv(2) (and recvmsg(2)). This flag causes the received
bytes of data to be discarded, rather than passed back in a caller-sup-
plied buffer. Since Linux 2.4.4, MSG_PEEK also has this effect when
used in conjunction with MSG_OOB to receive out-of-band data.
Ioctls
These following ioctl(2) calls return information in value. The cor-
rect syntax is:
int value;
error = ioctl(tcp_socket, ioctl_type, &value);
ioctl_type is one of the following:
SIOCINQ
Returns the amount of queued unread data in the receive buffer.
The socket must not be in LISTEN state, otherwise an error (EIN-
VAL) is returned.
SIOCATMARK
Returns true (i.e., value is non-zero) if the inbound data
stream is at the urgent mark.
If the SO_OOBINLINE socket option is set, and SIOCATMARK returns
true, then the next read from the socket will return the urgent
data. If the SO_OOBINLINE socket option is not set, and SIOCAT-
MARK returns true, then the next read from the socket will
return the bytes following the urgent data (to actually read the
urgent data requires the recv(MSG_OOB) flag).
Note that a read never reads across the urgent mark. If an
application is informed of the presence of urgent data via
select(2) (using the exceptfds argument) or through delivery of
a SIGURG signal, then it can advance up to the mark using a loop
which repeatedly tests SIOCATMARK and performs a read (request-
ing any number of bytes) as long as SIOCATMARK returns false.
SIOCOUTQ
Returns the amount of unsent data in the socket send queue. The
socket must not be in LISTEN state, otherwise an error (EINVAL)
is returned.
Error Handling
When a network error occurs, TCP tries to resend the packet. If it
doesn’t succeed after some time, either ETIMEDOUT or the last received
error on this connection is reported.
Some applications require a quicker error notification. This can be
enabled with the IPPROTO_IP level IP_RECVERR socket option. When this
option is enabled, all incoming errors are immediately passed to the
user program. Use this option with care — it makes TCP less tolerant
to routing changes and other normal network conditions.
ERRORS
EAFNOTSUPPORT
Passed socket address type in sin_family was not AF_INET.
EPIPE The other end closed the socket unexpectedly or a read is exe-
cuted on a shut down socket.
ETIMEDOUT
The other end didn’t acknowledge retransmitted data after some
time.
Any errors defined for ip(7) or the generic socket layer may also be
returned for TCP.
VERSIONS
Support for Explicit Congestion Notification, zero-copy sendfile(2),
reordering support and some SACK extensions (DSACK) were introduced in
2.4. Support for forward acknowledgement (FACK), TIME_WAIT recycling,
and per-connection keepalive socket options were introduced in 2.3.
BUGS
Not all errors are documented.
IPv6 is not described.
SEE ALSO
accept(2), bind(2), connect(2), getsockopt(2), listen(2), recvmsg(2),
sendfile(2), sendmsg(2), socket(2), ip(7), socket(7)
RFC 793 for the TCP specification.
RFC 1122 for the TCP requirements and a description of the Nagle algo-
rithm.
RFC 1323 for TCP timestamp and window scaling options.
RFC 1644 for a description of TIME_WAIT assassination hazards.
RFC 3168 for a description of Explicit Congestion Notification.
RFC 2581 for TCP congestion control algorithms.
RFC 2018 and RFC 2883 for SACK and extensions to SACK.
COLOPHON
This page is part of release 3.22 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
Linux 2008-12-01 TCP(7)