1 .\"O .TH LIBIPQ 3 "16 October 2001" "Linux iptables 1.2" "Linux Programmer's Manual"
2 .TH LIBIPQ 3 "16 October 2001" "Linux iptables 1.2" "Linux Programmer's Manual"
4 .\" $Id: libipq.3,v 1.4 2001/10/16 16:58:25 jamesm Exp $
6 .\" Copyright (c) 2000-2001 Netfilter Core Team
8 .\" This program is free software; you can redistribute it and/or modify
9 .\" it under the terms of the GNU General Public License as published by
10 .\" the Free Software Foundation; either version 2 of the License, or
11 .\" (at your option) any later version.
13 .\" This program is distributed in the hope that it will be useful,
14 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
15 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 .\" GNU General Public License for more details.
18 .\" You should have received a copy of the GNU General Public License
19 .\" along with this program; if not, write to the Free Software
20 .\" Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 .\" Japanese Version Copyright (c) 2003 Susumu ISHIZUKA
23 .\" all rights reserved.
24 .\" Translated Tue Jun 6 19:25:23 JST 2003
25 .\" by Susumu ISHIZUKA <szuka@isp.co.jp>
27 .\"WORD: userspace ユーザ空間
31 libipq \- iptables userspace packet queuing library.
34 .B #include <linux/netfilter.h>
36 .B #include <libipq.h>
39 .\"O libipq is a development library for iptables userspace packet queuing.
40 libipq は iptables を 使って ユーザ空間でパケット操作を
42 .SS Userspace Packet Queuing
43 .\"O Netfilter provides a mechanism for passing packets out of the stack for
44 .\"O queueing to userspace, then receiving these packets back into the kernel
45 .\"O with a verdict specifying what to do with the packets (such as ACCEPT
46 .\"O or DROP). These packets may also be modified in userspace prior to
47 .\"O reinjection back into the kernel.
48 Netfilter は、ユーザ空間でパケット操作をするための機構を
49 提供している。 この機構はプロトコルスタックからパケットを
50 ユーザ空間に渡してキューイング(queuing) し、ユーザ空間で
51 (ACCEPT や DROP といった) パケット処理の判断を行った後に
52 パケットをカーネルに戻している。 これらのパケットは、
53 ユーザ空間で変更を加えられて、カーネルに返されることもある。
55 .\"O For each supported protocol, a kernel module called a
57 .\"O may register with Netfilter to perform the mechanics of passing
58 .\"O packets to and from userspace.
60 .I キューハンドラー (queue handler)
63 キューハンドラーは、各プロトコルごとに 用意される。
65 .\"O The standard queue handler for IPv4 is ip_queue. It is provided as an
66 .\"O experimental module with 2.4 kernels, and uses a Netlink socket for
67 .\"O kernel/userspace communication.
68 IPv4 での 標準のキューハンドラーは ip_queue である。
69 2.4カーネルでは experimental モジュールとして提供され、
70 Netlink ソケットを使って、カーネルとユーザ空間との通信を
73 .\"O Once ip_queue is loaded, IP packets may be selected with iptables
74 .\"O and queued for userspace processing via the QUEUE target. For example,
75 .\"O running the following commands:
76 ip_queue が、メモリ上にロードされると IP パケットは iptables で
77 フィルタリングされ QUEUE ターゲットによって ユーザ空間の 処理のために
78 キューイングされる。 例として 次の一連の コマンドが発行されると、
80 # modprobe iptable_filter
84 # iptables -A OUTPUT -p icmp -j QUEUE
86 .\"O will cause any locally generated ICMP packets (e.g. ping output) to
87 .\"O be sent to the ip_queue module, which will then attempt to deliver the
88 .\"O packets to a userspace application. If no userspace application is waiting,
89 .\"O the packets will be dropped
90 ローカルホストから送信されたICMPパケット(pingの送信など)が
91 ip_queueモジュールに送られ、そこからパケットをユーザ空間の
92 アプリケーションに渡そうとする。 パケットを受け取る
93 アプリケーションがない場合は、パケットは破棄(drop)される。
95 .\"O An application may receive and process these packets via libipq.
96 アプリケーションは、libipq を使うことでパケットを受信・
101 .\"O Libipq provides an API for communicating with ip_queue. The following is
102 .\"O an overview of API usage, refer to individual man pages for more details
103 .\"O on each function.
104 libipq は、ip_queue と通信するための API を提供する。
105 以下は、API の簡単な説明である。 関数の詳細は各 manpage を
108 .\"O .B Initialisation
111 .\"O To initialise the library, call
112 .\"O .BR ipq_create_handle (3).
113 .\"O This will attempt to bind to the Netlink socket used by ip_queue and
114 .\"O return an opaque context handle for subsequent library calls.
116 .BR ipq_create_handle (3)
118 この関数は ip_queue が使用している Netlink ソケットを bind
119 し、この後のライブラリ関数が使用するコンテキストハンドルを
122 .\"O .B Setting the Queue Mode
123 .B キューモード(queue mode)の設定
125 .\"O .BR ipq_set_mode (3)
126 .\"O allows the application to specify whether packet metadata, or packet
127 .\"O payloads as well as metadata are copied to userspace. It is also used to
128 .\"O initially notify ip_queue that an application is ready to receive queue
131 は、ユーザ空間にパケットのメタデータだけを
132 コピーするのか、パケットのメタデータとペイロードの両方を
133 コピーするのか指定する。この関数はまた ip_queue に
134 アプリケーションがキューメッセージ (queue message)を受け
137 .\"O .B Receiving Packets from the Queue
140 .\"O .BR ipq_read (3)
141 .\"O waits for queue messages to arrive from ip_queue and copies
142 .\"O them into a supplied buffer.
143 .\"O Queue messages may be
144 .\"O .I packet messages
146 .\"O .I error messages.
148 関数は ip_queue からのキューメッセージを
149 待って、バッファにコピーする。 キューメッセージは
155 .\"O The type of packet may be determined with
156 .\"O .BR ipq_message_type (3).
158 .BR ipq_message_type (3)
161 .\"O If it's a packet message, the metadata and optional payload may be retrieved with
162 .\"O .BR ipq_get_packet (3).
163 パケットメッセージの場合は、メタデータとペイロードを
164 .BR ipq_get_packet (3)
167 .\"O To retrieve the value of an error message, use
168 .\"O .BR ipq_get_msgerr (3).
170 .BR ipq_get_msgerr (3)
173 .\"O .B Issuing Verdicts on Packets
176 .\"O To issue a verdict on a packet, and optionally return a modified version
177 .\"O of the packet to the kernel, call
178 .\"O .BR ipq_set_verdict (3).
179 パケットの処理を決定し、必要ならパケットに変更を加えて
181 .BR ipq_set_verdict (3)
184 .\"O .B Error Handling
187 .\"O An error string corresponding to the current value of the internal error
190 .\"O may be obtained with
191 .\"O .BR ipq_errstr (3).
199 .\"O For simple applications, calling
200 .\"O .BR ipq_perror (3)
201 .\"O will print the same message as
202 .\"O .BR ipq_errstr (3),
203 .\"O as well as the string corresponding to the global
205 .\"O value (if set) to stderr.
206 単純なアプリケーションに使える関数として、
210 で返されるのと同じ文字列を標準出力 (stderr) に
219 .\"O To free up the Netlink socket and destroy resources associated with
220 .\"O the context handle, call
221 .\"O .BR ipq_destroy_handle (3).
222 Netlink ソケットを解放し、コンテキストハンドルに関連付け
224 .BR ipq_destroy_handle (3)
229 .BR ipq_create_handle (3)
230 .\"O Initialise library, return context handle.
231 は、ライブラリを初期化し、コンテキストハンドルを返す。
234 .\"O Set the queue mode, to copy either packet metadata, or payloads
235 .\"O as well as metadata to userspace.
236 は、パケットのメタデータだけをコピーするか、ペイロードも
240 .\"O Wait for a queue message to arrive from ip_queue and read it into
242 ip_queue からのメッセージを待ち、受信するとバッファに
245 .BR ipq_message_type (3)
246 .\"O Determine message type in the buffer.
247 は、バッファされたメッセージのタイプを返す。
249 .BR ipq_get_packet (3)
250 .\"O Retrieve a packet message from the buffer.
253 .BR ipq_get_msgerr (3)
254 .\"O Retrieve an error message from the buffer.
255 は、バッファからエラーメッセージを取得する。
257 .BR ipq_set_verdict (3)
258 .\"O Set a verdict on a packet, optionally replacing its contents.
259 は、パケットの判断を下す。内容を書き換えることもできる。
262 .\"O Return an error message corresponding to the internal ipq_errno variable.
263 は、内部変数 ipq_errno の値に応じたエラーメッセージを
267 .\"O Helper function to print error messages to stderr.
268 は、エラーメッセージを標準出力(stderr)に表示する
271 .BR ipq_destroy_handle (3)
272 .\"O Destroy context handle and associated resources.
273 は、コンテキストハンドルを破棄し、リソースを解放する。
276 .\"O The following is an example of a simple application which receives
277 .\"O packets and issues NF_ACCEPT verdicts on each packet.
278 次のコードは、パケットを受け取って NF_ACCEPT の判断を返す単純な
285 #include <linux/netfilter.h>
291 static void die(struct ipq_handle *h)
293 ipq_perror("passer");
294 ipq_destroy_handle(h);
298 int main(int argc, char **argv)
301 unsigned char buf[BUFSIZE];
302 struct ipq_handle *h;
304 h = ipq_create_handle(0);
308 status = ipq_set_mode(h, IPQ_COPY_PACKET, BUFSIZE);
313 status = ipq_read(h, buf, BUFSIZE, 0);
317 switch (ipq_message_type(buf)) {
319 fprintf(stderr, "Received error message %d\\n",
320 ipq_get_msgerr(buf));
324 ipq_packet_msg_t *m = ipq_get_packet(buf);
326 status = ipq_set_verdict(h, m->packet_id,
334 fprintf(stderr, "Unknown message type!\\n");
339 ipq_destroy_handle(h);
345 .\"O Pointers to more libipq application examples may be found in The
347 libipq を使ったアプリケーションの例は
351 .\"O For information about monitoring and tuning ip_queue, refer to the
352 .\"O Linux 2.4 Packet Filtering HOWTO.
353 ip_queue の監視とチューニングに関しては Linux 2.4 Packet
354 Filtering HOWTO を参照すること。
356 .\"O If an application modifies a packet, it needs to also update any
357 .\"O checksums for the packet. Typically, the kernel will silently discard
358 .\"O modified packets with invalid checksums.
359 アプリケーションがパケットに変更を加えた時には、関連する
360 チェックサムも変更する必要がある。 変更されたパケットの
361 チェックサムが異常なときにはカーネルは黙って破棄 (silently discard) する。
364 .\"O Processes require CAP_NET_ADMIN capabilty to access the kernel ip_queue
365 .\"O module. Such processes can potentially access and modify any IP packets
366 .\"O received, generated or forwarded by the kernel.
367 ip_queue カーネルモジュールにアクセスするプロセスは
368 CAP_NET_ADMIN 権限が必要である。 そのようなプロセスは、
369 潜在的にカーネルが受信 (送信、転送) する全ての IP パケットを
384 James Morris <jmorris@intercode.com.au>
387 Copyright (c) 2000-2001 Netfilter Core Team.
389 Distributed under the GNU General Public License.
391 .\"O Joost Remijn implemented the
393 .\"O timeout feature, which appeared in the 1.2.4 release of iptables.
396 のタイムアウトを実装した。 この機能は iptables の 1.2.4 から使用できる。
400 .BR ipq_create_handle (3),
401 .BR ipq_destroy_handle (3),
403 .BR ipq_get_msgerr (3),
404 .BR ipq_get_packet (3),
405 .BR ipq_message_type (3),
408 .BR ipq_set_mode (3),
409 .BR ipq_set_verdict (3).
411 .\"O The Netfilter home page at http://netfilter.samba.org/
412 .\"O which has links to The Networking Concepts HOWTO, The Linux 2.4 Packet
413 .\"O Filtering HOWTO, The Linux 2.4 NAT HOWTO, The Netfilter Hacking HOWTO,
414 .\"O The Netfilter FAQ and many other useful resources.
415 Netfilter のホームページは http://netfilter.samba.org/ にある。
416 The Networking Concepts HOWTO, The Linux 2.4 Packet
417 Filtering HOWTO, The Linux 2.4 NAT HOWTO, The Netfilter Hacking HOWTO,
418 The Netfilter FAQ などの有益な 情報がある。