]> git.lizzy.rs Git - plan9front.git/blob - sys/man/3/ip
/sys/lib/rootstub
[plan9front.git] / sys / man / 3 / ip
1 .TH IP 3
2 .SH NAME
3 ip, esp, gre, icmp, icmpv6, ipmux, rudp, tcp, udp, il \- network protocols over IP
4 .SH SYNOPSIS
5 .nf
6 .2C
7 .B bind -a #I\fIspec\fP /net
8 .sp 0.3v
9 .B /net/ipifc
10 .B /net/ipifc/clone
11 .B /net/ipifc/stats
12 .BI /net/ipifc/ n
13 .BI /net/ipifc/ n /status
14 .BI /net/ipifc/ n /ctl
15 \&...
16 .sp 0.3v
17 .B /net/arp
18 .B /net/bootp
19 .B /net/iproute
20 .B /net/ipselftab
21 .B /net/log
22 .B /net/ndb
23 .sp 0.3v
24 .B /net/esp
25 .B /net/gre
26 .B /net/icmp
27 .B /net/icmpv6
28 .B /net/ipmux
29 .B /net/rudp
30 .B /net/tcp
31 .B /net/udp
32 .B /net/il
33 .sp 0.3v
34 .B /net/tcp/clone
35 .B /net/tcp/stats
36 .BI /net/tcp/ n
37 .BI /net/tcp/ n /data
38 .BI /net/tcp/ n /ctl
39 .BI /net/tcp/ n /local
40 .BI /net/tcp/ n /remote
41 .BI /net/tcp/ n /status
42 .BI /net/tcp/ n /listen
43 \&...
44 .1C
45 .fi
46 .SH DESCRIPTION
47 The
48 .I ip
49 device provides the interface to Internet Protocol stacks.
50 .I Spec
51 is an integer from 0 to 15 identifying a stack.
52 Each stack implements IPv4 and IPv6.
53 Each stack is independent of all others:
54 the only information transfer between them is via programs that
55 mount multiple stacks.
56 Normally a system uses only one stack.
57 However multiple stacks can be used for debugging
58 new IP networks or implementing firewalls or proxy
59 services.
60 .PP
61 All addresses used are 16-byte IPv6 addresses.
62 IPv4 addresses are a subset of the IPv6 addresses and both standard
63 .SM ASCII
64 formats are accepted.
65 In binary representation, all v4 addresses start with the 12 bytes, in hex:
66 .IP
67 .EX
68 00 00 00 00 00 00 00 00 00 00 ff ff
69 .EE
70 .
71 .SS "Configuring interfaces
72 Each stack may have multiple interfaces and each interface
73 may have multiple addresses.
74 The
75 .B /net/ipifc
76 directory contains a
77 .B clone
78 file, a
79 .B stats
80 file, and numbered subdirectories for each physical interface.
81 .PP
82 Opening the
83 .B clone
84 file reserves an interface.
85 The file descriptor returned from the
86 .IR open (2)
87 will point to the control file,
88 .BR ctl ,
89 of the newly allocated interface.
90 Reading
91 .B ctl
92 returns a text string representing the number of the interface.
93 Writing
94 .B ctl
95 alters aspects of the interface.
96 The possible
97 .I ctl
98 messages are those described under
99 .B "Protocol directories"
100 below and these:
101 .TF "\fLbind loopback\fR"
102 .PD
103 .
104 .\" from devip.c
105 .
106 .TP
107 .BI "bind ether " path
108 Treat the device mounted at
109 .I path
110 as an Ethernet medium carrying IP and ARP packets
111 and associate it with this interface.
112 The kernel will
113 .IR dial (2)
114 .IR path !0x800
115 and
116 .IR path !0x806
117 and use the two connections for IPv4 and
118 ARP respectively.
119 .TP
120 .B "bind pkt
121 Treat this interface as a packet interface.  Assume
122 a user program will read and write the
123 .I data
124 file to receive and transmit IP packets to the kernel.
125 This is used by programs such as
126 .IR ppp (8)
127 to mediate IP packet transfer between the kernel and
128 a PPP encoded device.
129 .TP
130 .BI "bind netdev " path
131 Treat this interface as a packet interface.
132 The kernel will open
133 .I path
134 and read and write the resulting file descriptor
135 to receive and transmit IP packets.
136 .TP
137 .BI "bind loopback "
138 Treat this interface as a local loopback.  Anything
139 written to it will be looped back.
140 .
141 .\" from ipifc.c
142 .
143 .TP
144 .B "unbind
145 Disassociate the physical device from an IP interface.
146 .TP
147 .BI add\  "local mask remote mtu " proxy
148 .PD 0
149 .TP
150 .BI try\  "local mask remote mtu " proxy
151 .PD
152 Add a local IP address to the interface.
153 .I Try
154 adds the
155 .I local
156 address as a tentative address
157 if it's an IPv6 address.
158 The
159 .IR mask ,
160 .IR remote ,
161 .IR mtu ,
162 and
163 .B proxy
164 arguments are all optional.
165 The default
166 .I mask
167 is the class mask for the local address.
168 The default
169 .I remote
170 address is
171 .I local
172 ANDed with
173 .IR mask .
174 The default
175 .I mtu
176 (maximum transmission unit)
177 is 1514 for Ethernet and 4096 for packet media.
178 The
179 .I mtu
180 is the size in bytes of the largest packet that this interface can send.
181 .IR Proxy ,
182 if specified, means that this machine should answer
183 ARP requests for the remote address.
184 .IR Ppp (8)
185 does this to make remote machines appear
186 to be connected to the local Ethernet.
187 .TP
188 .BI remove\  "local mask"
189 Remove a local IP address from an interface.
190 .TP
191 .BI mtu\  n
192 Set the maximum transfer unit for this device to
193 .IR n .
194 The mtu is the maximum size of the packet including any
195 medium-specific headers.
196 .TP
197 .BI reassemble
198 Reassemble IP fragments before forwarding to this interface
199 .TP
200 .BI iprouting\  n
201 Allow
202 .RI ( n
203 is missing or non-zero) or disallow
204 .RI ( n
205 is 0) forwarding packets between this interface and
206 others.
207 .
208 .\" remainder from netif.c (thus called from devether.c),
209 .\" except add6 and ra6 from ipifc.c
210 .
211 .TP
212 .B bridge
213 Enable bridging (see
214 .IR bridge (3)).
215 .TP
216 .B promiscuous
217 Set the interface into promiscuous mode,
218 which makes it accept all incoming packets,
219 whether addressed to it or not.
220 .TP
221 .BI "connect " type
222 marks the Ethernet packet
223 .I type
224 as being in use, if not already in use
225 on this interface.
226 A
227 .I type
228 of -1 means `all' but appears to be a no-op.
229 .TP
230 .BI addmulti\  Media-addr
231 Treat the multicast
232 .I Media-addr
233 on this interface as a local address.
234 .TP
235 .BI remmulti\  Media-addr
236 Remove the multicast address
237 .I Media-addr
238 from this interface.
239 .TP
240 .B scanbs
241 Make the wireless interface scan for base stations.
242 .TP
243 .B headersonly
244 Set the interface to pass only packet headers, not data too.
245 .
246 .\" remainder from ipifc.c; tedious, so put them last
247 .
248 .TP
249 .BI "add6 " "v6addr pfx-len [onlink auto validlt preflt]"
250 Add the local IPv6 address
251 .I v6addr
252 with prefix length
253 .I pfx-len
254 to this interface.
255 See RFC 2461 §6.2.1 for more detail.
256 The remaining arguments are optional:
257 .RS
258 .TF "\fIonlink\fR"
259 .TP
260 .I onlink
261 flag: address is `on-link'
262 .TP
263 .I auto
264 flag: autonomous
265 .TP
266 .I validlt
267 valid life-time in seconds
268 .TP
269 .I preflt
270 preferred life-time in seconds
271 .RE
272 .PD
273 .TP
274 .BI "ra6 " "keyword value ..."
275 Set IPv6 router advertisement (RA) parameter
276 .IR keyword 's
277 .IR value .
278 Known
279 .IR keyword s
280 and the meanings of their values follow.
281 See RFC 2461 §6.2.1 for more detail.
282 Flags are true iff non-zero.
283 .RS
284 .TF "\fLreachtime\fR"
285 .TP
286 .B recvra
287 flag: receive and process RAs.
288 .TP
289 .B sendra
290 flag: generate and send RAs.
291 .TP
292 .B mflag
293 flag: ``Managed address configuration'',
294 goes into RAs.
295 .TP
296 .B oflag
297 flag: ``Other stateful configuration'',
298 goes into RAs.
299 .TP
300 .B maxraint
301 ``maximum time allowed between sending unsolicited multicast''
302 RAs from the interface, in ms.
303 .TP
304 .B minraint
305 ``minimum time allowed between sending unsolicited multicast''
306 RAs from the interface, in ms.
307 .TP
308 .B linkmtu
309 ``value to be placed in MTU options sent by the router.''
310 Zero indicates none.
311 .TP
312 .B reachtime
313 sets the Reachable Time field in RAs sent by the router.
314 ``Zero means unspecified (by this router).''
315 .TP
316 .B rxmitra
317 sets the Retrans Timer field in RAs sent by the router.
318 ``Zero means unspecified (by this router).''
319 .TP
320 .B ttl
321 default value of the Cur Hop Limit field in RAs sent by the router.
322 Should be set to the ``current diameter of the Internet.''
323 ``Zero means unspecified (by this router).''
324 .TP
325 .B routerlt
326 sets the Router Lifetime field of RAs sent from the interface, in ms.
327 Zero means the router is not to be used as a default router.
328 .PD
329 .RE
330 .PP
331 Reading the interface's
332 .I status
333 file returns information about the interface. The first line
334 is composed of white-space-separated fields, the first two
335 fields are: device and maxmtu. Subsequent lines list the
336 ip addresses assigned to that inferface. The colums are:
337 ip address, network mask, network address and valid/preferred
338 life times in milliseconds. See
339 .I readipifc
340 in
341 .IR ip (2).
342 .
343 .SS "Routing
344 The file
345 .I iproute
346 controls information about IP routing.
347 When read, it returns one line per routing entry.
348 Each line contains six white-space-separated fields:
349 target address, target mask, address of next hop, flags,
350 tag, and interface number.
351 The entry used for routing an IP packet is the one with
352 the longest mask for which destination address ANDed with
353 target mask equals the target address.
354 The one-character flags are:
355 .TF m
356 .TP
357 .B 4
358 IPv4 route
359 .TP
360 .B 6
361 IPv6 route
362 .TP
363 .B i
364 local interface
365 .TP
366 .B b
367 broadcast address
368 .TP
369 .B u
370 local unicast address
371 .TP
372 .B m
373 multicast route
374 .TP
375 .B p
376 point-to-point route
377 .PD
378 .PP
379 The tag is an arbitrary, up to 4 character, string.  It is normally used to
380 indicate what routing protocol originated the route.
381 .PP
382 Writing to
383 .B /net/iproute
384 changes the route table.  The messages are:
385 .TF "\fLtag \fIstring\fR"
386 .PD
387 .TP
388 .B flush
389 Remove all routes.
390 .TP
391 .BI tag\  string
392 Associate the tag,
393 .IR string ,
394 with all subsequent routes added via this file descriptor.
395 .TP
396 .BI add\  "target mask nexthop"
397 Add the route to the table.  If one already exists with the
398 same target and mask, replace it.
399 .TP
400 .BI remove\  "target mask"
401 Remove a route with a matching target and mask.
402 .
403 .SS "Address resolution
404 The file
405 .B /net/arp
406 controls information about address resolution.
407 The kernel automatically updates the v4 ARP and v6 Neighbour Discovery
408 information for Ethernet interfaces.
409 When read, the file returns one line per address containing the
410 type of medium, the status of the entry (OK, WAIT), the IP
411 address, and the medium address.
412 Writing to
413 .B /net/arp
414 administers the ARP information.
415 The control messages are:
416 .TF "\fLdel \fIIP-addr\fR"
417 .PD
418 .TP
419 .B flush
420 Remove all entries.
421 .TP
422 .BI add\  "type IP-addr Media-addr"
423 Add an entry or replace an existing one for the
424 same IP address.
425 .TP
426 .BI del\  "IP-addr"
427 Delete an individual entry.
428 .PP
429 ARP entries do not time out.  The ARP table is a
430 cache with an LRU replacement policy.  The IP stack
431 listens for all ARP requests and, if the requester is in
432 the table, the entry is updated.
433 Also, whenever a new address is configured onto an
434 Ethernet, an ARP request is sent to help
435 update the table on other systems.
436 .PP
437 Currently, the only medium type is
438 .BR ether .
439 .br
440 .ne 3
441 .
442 .SS "Debugging and stack information
443 If any process is holding
444 .B /net/log
445 open, the IP stack queues debugging information to it.
446 This is intended primarily for debugging the IP stack.
447 The information provided is implementation-defined;
448 see the source for details.  Generally, what is returned is error messages
449 about bad packets.
450 .PP
451 Writing to
452 .B /net/log
453 controls debugging.  The control messages are:
454 .TF "\fLclear \fIarglist\fR"
455 .PD
456 .TP
457 .BI set\  arglist
458 .I Arglist
459 is a space-separated list of items for which to enable debugging.
460 The possible items are:
461 .BR ppp ,
462 .BR ip ,
463 .BR fs ,
464 .BR tcp ,
465 .BR il ,
466 .BR icmp ,
467 .BR udp ,
468 .BR compress ,
469 .BR ilmsg ,
470 .BR gre ,
471 .BR tcpwin ,
472 .BR tcprxmt ,
473 .BR udpmsg ,
474 .BR ipmsg ,
475 and
476 .BR esp .
477 .TP
478 .BI clear\  arglist
479 .I Arglist
480 is a space-separated list of items for which to disable debugging.
481 .TP
482 .BI only\  addr
483 If
484 .I addr
485 is non-zero, restrict debugging to only those
486 packets whose source or destination is that
487 address.
488 .PP
489 The file
490 .B /net/ndb
491 can be read or written by
492 programs.  It is normally used by
493 .IR ipconfig (8)
494 to leave configuration information for other programs
495 such as
496 .B dns
497 and
498 .B cs
499 (see
500 .IR ndb (8)).
501 .B /net/ndb
502 may contain up to 1024 bytes.
503 .PP
504 The file
505 .B /net/ipselftab
506 is a read-only file containing all the IP addresses
507 considered local.  Each line in the file contains
508 three white-space-separated fields: IP address, usage count,
509 and flags.  The usage count is the number of interfaces to which
510 the address applies.  The flags are the same as for routing
511 entries.
512 Note that the `IPv4 route' flag will never be set.
513 .br
514 .ne 3
515 .
516 .SS "Protocol directories
517 The
518 .I ip
519 device
520 supports IP as well as several protocols that run over it:
521 TCP, UDP, RUDP, ICMP, IL, GRE, and ESP.
522 TCP and UDP provide the standard Internet
523 protocols for reliable stream and unreliable datagram
524 communication.
525 RUDP is a locally-developed reliable datagram protocol based on UDP.
526 ICMP is IP's catch-all control protocol used to send
527 low level error messages and to implement
528 .IR ping (8).
529 GRE is a general encapsulation protocol.
530 ESP is the encapsulation protocol for IPsec.
531 IL provides a reliable datagram service for communication
532 between Plan 9 machines but is now deprecated.
533 .PP
534 Each protocol is a subdirectory of the IP stack.
535 The top level directory of each protocol contains a
536 .B clone
537 file, a
538 .B stats
539 file, and subdirectories numbered from zero to the number of connections
540 opened for this protocol.
541 .PP
542 Opening the
543 .B clone
544 file reserves a connection.  The file descriptor returned from the
545 .IR open (2)
546 will point to the control file,
547 .BR ctl ,
548 of the newly allocated connection.
549 Reading
550 .B ctl
551 returns a text
552 string representing the number of the
553 connection.
554 Connections may be used either to listen for incoming calls
555 or to initiate calls to other machines.
556 .PP
557 A connection is controlled by writing text strings to the associated
558 .B ctl
559 file.
560 After a connection has been established data may be read from
561 and written to
562 .BR data .
563 A connection can be actively established using the
564 .B connect
565 message (see also
566 .IR dial (2)).
567 A connection can be established passively by first
568 using an
569 .B announce
570 message (see
571 .IR dial (2))
572 to bind to a local port and then
573 opening the
574 .B listen
575 file (see
576 .IR dial (2))
577 to receive incoming calls.
578 .PP
579 The following control messages are supported:
580 .TF "\fLremmulti \fIip\fR"
581 .PD
582 .TP
583 .BI connect\  ip-address ! port "!r " local
584 Establish a connection to the remote
585 .I ip-address
586 and
587 .IR port .
588 If
589 .I local
590 is specified, it is used as the local port number.
591 If
592 .I local
593 is not specified but
594 .B !r
595 is, the system will allocate
596 a restricted port number (less than 1024) for the connection to allow communication
597 with Unix
598 .B login
599 and
600 .B exec
601 services.
602 Otherwise a free port number starting at 5000 is chosen.
603 The connect fails if the combination of local and remote address/port pairs
604 are already assigned to another port.
605 .TP
606 .BI announce\  X
607 .I X
608 is a decimal port number or
609 .LR * .
610 Set the local port
611 number to
612 .I X
613 and accept calls to
614 .IR X .
615 If
616 .I X
617 is
618 .LR * ,
619 accept
620 calls for any port that no process has explicitly announced.
621 The local IP address cannot be set.
622 .B Announce
623 fails if the connection is already announced or connected.
624 .TP
625 .BI bind\  X
626 .I X
627 is a decimal port number or
628 .LR * .
629 Set the local port number to
630 .IR X .
631 This exists to support emulation
632 of BSD sockets by the APE libraries (see
633 .IR pcc (1))
634 and is not otherwise used.
635 .\" this is gone
636 .\" .TP
637 .\" .BI backlog\  n
638 .\" Set the maximum number of unanswered (queued) incoming
639 .\" connections to an announced port to
640 .\" .IR n .
641 .\" By default
642 .\" .I n
643 .\" is set to five.  If more than
644 .\" .I n
645 .\" connections are pending,
646 .\" further requests for a service will be rejected.
647 .TP
648 .BI ttl\  n
649 Set the time to live IP field in outgoing packets to
650 .IR n .
651 .TP
652 .BI tos\  n
653 Set the service type IP field in outgoing packets to
654 .IR n .
655 .TP
656 .B ignoreadvice
657 Don't break (UDP) connections because of ICMP errors.
658 .TP
659 .BI addmulti\  "ifc-ip [ mcast-ip ]"
660 Treat
661 .I ifc-ip
662 on this multicast interface as a local address.
663 If
664 .I mcast-ip
665 is present,
666 use it as the interface's multicast address.
667 .TP
668 .BI remmulti\  ip
669 Remove the address
670 .I ip
671 from this multicast interface.
672 .PP
673 Port numbers must be in the range 1 to 32767.
674 .PP
675 Several files report the status of a
676 connection.
677 The
678 .B remote
679 and
680 .B local
681 files contain the IP address and port number for the remote and local side of the
682 connection.  The
683 .B status
684 file contains protocol-dependent information to help debug network connections.
685 On receiving and error or EOF reading or writing the
686 .B data
687 file, the
688 .B err
689 file contains the reason for error.
690 .PP
691 A process may accept incoming connections by
692 .IR open (2)ing
693 the
694 .B listen
695 file.
696 The
697 .B open
698 will block until a new connection request arrives.
699 Then
700 .B open
701 will return an open file descriptor which points to the control file of the
702 newly accepted connection.
703 This procedure will accept all calls for the
704 given protocol.
705 See
706 .IR dial (2).
707 .
708 .SS TCP
709 TCP connections are reliable point-to-point byte streams; there are no
710 message delimiters.
711 A connection is determined by the address and port numbers of the two
712 ends.
713 TCP
714 .B ctl
715 files support the following additional messages:
716 .TF "\fLkeepalive\fI n\fR"
717 .PD
718 .TP
719 .B hangup
720 close down this TCP connection
721 .TP
722 .BI keepalive \ n
723 turn on keep alive messages.
724 .IR N ,
725 if given, is the milliseconds between keepalives
726 (default 30000).
727 .TP
728 .BI checksum \ n
729 emit TCP checksums of zero if
730 .I n
731 is zero; otherwise, and by default,
732 TCP checksums are computed and sent normally.
733 .TP
734 .BI tcpporthogdefense \ onoff
735 .I onoff
736 of
737 .L on
738 enables the TCP port-hog defense for all TCP connections;
739 .I onoff
740 of
741 .L off
742 disables it.
743 The defense is a solution to hijacked systems staking out ports
744 as a form of denial-of-service attack.
745 To avoid stateless TCP conversation hogs,
746 .I ip
747 picks a TCP sequence number at random for keepalives.
748 If that number gets acked by the other end,
749 .I ip
750 shuts down the connection.
751 Some firewalls,
752 notably ones that perform stateful inspection,
753 discard such out-of-specification keepalives,
754 so connections through such firewalls
755 will be killed after five minutes
756 by the lack of keepalives.
757 .
758 .SS UDP
759 UDP connections carry unreliable and unordered datagrams.  A read from
760 .B data
761 will return the next datagram, discarding anything
762 that doesn't fit in the read buffer.
763 A write is sent as a single datagram.
764 .PP
765 By default, a UDP connection is a point-to-point link.
766 Either a
767 .B connect
768 establishes a local and remote address/port pair or
769 after an
770 .BR announce ,
771 each datagram coming from a different remote address/port pair
772 establishes a new incoming connection.
773 However, many-to-one semantics is also possible.
774 .PP
775 If, after an
776 .BR announce ,
777 the message
778 .L headers
779 is written to
780 .BR ctl ,
781 then all messages sent to the announced port
782 are received on the announced connection prefixed
783 with the corresponding structure,
784 declared in
785 .BR <ip.h> :
786 .IP
787 .EX
788 typedef struct Udphdr Udphdr;
789 struct Udphdr
790 {
791         uchar   raddr[16];      /* V6 remote address and port */
792         uchar   laddr[16];      /* V6 local address and port */
793         uchar   ifcaddr[16];    /* V6 interface address (receive only) */
794         uchar   rport[2];       /* remote port */
795         uchar   lport[2];       /* local port */
796 };
797 .EE
798 .PP
799 Before a write, a user must prefix a similar structure to each message.
800 The system overrides the user specified local port with the announced
801 one.  If the user specifies an address that isn't a unicast address in
802 .BR /net/ipselftab ,
803 that too is overridden.
804 Since the prefixed structure is the same in read and write, it is relatively
805 easy to write a server that responds to client requests by just copying new
806 data into the message body and then writing back the same buffer that was
807 read.
808 .PP
809 In this case (writing
810 .L headers
811 to the
812 .I ctl
813 file),
814 no
815 .I listen
816 nor
817 .I accept
818 is needed;
819 otherwise,
820 the usual sequence of
821 .IR announce ,
822 .IR listen ,
823 .I accept
824 must be executed before performing I/O on the corresponding
825 .I data
826 file.
827 .
828 .SS RUDP
829 RUDP is a reliable datagram protocol based on UDP,
830 currently only for IPv4.
831 Packets are delivered in order.
832 RUDP does not support
833 .BR listen .
834 One must write either
835 .L connect
836 or
837 .L announce
838 followed immediately by
839 .L headers
840 to
841 .BR ctl .
842 .PP
843 Unlike TCP, the reboot of one end of a connection does
844 not force a closing of the connection.  Communications will
845 resume when the rebooted machine resumes talking.  Any unacknowledged
846 packets queued before the reboot will be lost.  A reboot can
847 be detected by reading the
848 .B err
849 file.  It will contain the message
850 .IP
851 .BI hangup\  address ! port
852 .PP
853 where
854 .I address
855 and
856 .I port
857 are of the far side of the connection.
858 Retransmitting a datagram more than 10 times
859 is treated like a reboot:
860 all queued messages are dropped, an error is queued to the
861 .B err
862 file, and the conversation resumes.
863 .PP
864 RUDP
865 .I ctl
866 files accept the following messages:
867 .TF "\fLranddrop \fI[ percent ]\fR"
868 .TP
869 .B headers
870 Corresponds to the
871 .L headers
872 format of UDP.
873 .TP
874 .BI "hangup " "IP port"
875 Drop the connection to address
876 .I IP
877 and
878 .IR port .
879 .TP
880 .BI "randdrop " "[ percent ]"
881 Randomly drop
882 .I percent
883 of outgoing packets.
884 Default is 10%.
885 .
886 .SS ICMP
887 ICMP is a datagram protocol for IPv4 used to exchange control requests and
888 their responses with other machines' IP implementations.
889 ICMP is primarily a kernel-to-kernel protocol, but it is possible
890 to generate `echo request' and read `echo reply' packets from user programs.
891 .
892 .SS ICMPV6
893 ICMPv6 is the IPv6 equivalent of ICMP.
894 If, after an
895 .BR announce ,
896 the message
897 .L headers
898 is written to
899 .BR ctl ,
900 then before a write,
901 a user must prefix each message with a corresponding structure,
902 declared in
903 .BR <ip.h> :
904 .IP
905 .EX
906 /*
907  *  user level icmpv6 with control message "headers"
908  */
909 typedef struct Icmp6hdr Icmp6hdr;
910 struct Icmp6hdr {
911         uchar   unused[8];
912         uchar   laddr[IPaddrlen];       /* local address */
913         uchar   raddr[IPaddrlen];       /* remote address */
914 };
915 .EE
916 .PP
917 In this case (writing
918 .L headers
919 to the
920 .I ctl
921 file),
922 no
923 .I listen
924 nor
925 .I accept
926 is needed;
927 otherwise,
928 the usual sequence of
929 .IR announce ,
930 .IR listen ,
931 .I accept
932 must be executed before performing I/O on the corresponding
933 .I data
934 file.
935 .
936 .SS IL
937 IL is a reliable point-to-point datagram protocol that runs over IPv4.
938 Like TCP, IL delivers datagrams
939 reliably and in order. Also like TCP, a connection is
940 determined by the address and port numbers of the two ends.
941 Like UDP, each read and write transfers a single datagram.
942 .PP
943 IL is efficient for LANs but doesn't have the
944 congestion control features needed for use through
945 the Internet.
946 It is no longer necessary, except to communicate with old standalone
947 .IR fs (4)
948 file servers.
949 Its use is now deprecated.
950 .
951 .SS GRE
952 GRE is the encapsulation protocol used by PPTP.
953 The kernel implements just enough of the protocol
954 to multiplex it.
955 Our implementation encapsulates in IPv4, per RFC 1702.
956 .B Announce
957 is not allowed in GRE, only
958 .BR connect .
959 Since GRE has no port numbers, the port number in the connect
960 is actually the 16 bit
961 .B eproto
962 field in the GRE header.
963 .PP
964 Reads and writes transfer a
965 GRE datagram starting at the GRE header.
966 On write, the kernel fills in the
967 .B eproto
968 field with the port number specified
969 in the connect message.
970 .br
971 .ne 3
972 .
973 .SS ESP
974 ESP is the Encapsulating Security Payload (RFC 1827, obsoleted by RFC 4303)
975 for IPsec (RFC 4301).
976 We currently implement only tunnel mode, not transport mode.
977 It is used to set up an encrypted tunnel between machines.
978 Like GRE, ESP has no port numbers.  Instead, the
979 port number in the
980 .B connect
981 message is the SPI (Security Association Identifier (sic)).
982 IP packets are written to and read from
983 .BR data .
984 The kernel encrypts any packets written to
985 .BR data ,
986 appends a MAC, and prefixes an ESP header before
987 sending to the other end of the tunnel.
988 Received packets are checked against their MAC's,
989 decrypted, and queued for reading from
990 .BR data .
991 In the following,
992 .I secret
993 is the hexadecimal encoding of a key,
994 without a leading
995 .LR 0x .
996 The control messages are:
997 .TF "\fLesp \fIalg secret\fR"
998 .PD
999 .TP
1000 .BI esp\  "alg secret
1001 Encrypt with the algorithm,
1002 .IR alg ,
1003 using
1004 .I secret
1005 as the key.
1006 Possible algorithms are:
1007 .BR null ,
1008 .BR des_56_cbc ,
1009 .BR des3_cbc ,
1010 and eventually
1011 .BR aes_128_cbc ,
1012 and
1013 .BR aes_ctr .
1014 .TP
1015 .BI ah\  "alg secret
1016 Use the hash algorithm,
1017 .IR alg ,
1018 with
1019 .I secret
1020 as the key for generating the MAC.
1021 Possible algorithms are:
1022 .BR null ,
1023 .BR hmac_sha1_96 ,
1024 .BR hmac_md5_96 ,
1025 and eventually
1026 .BR aes_xcbc_mac_96 .
1027 .TP
1028 .B header
1029 Turn on header mode.  Every buffer read from
1030 .B data
1031 starts with 4 unused bytes, and the first 4 bytes
1032 of every buffer written to
1033 .B data
1034 are ignored.
1035 .TP
1036 .B noheader
1037 Turn off header mode.
1038 .
1039 .SS "IP packet filter
1040 The directory
1041 .B /net/ipmux
1042 looks like another protocol directory.
1043 It is a packet filter built on top of IP.
1044 Each numbered
1045 subdirectory represents a different filter.
1046 The connect messages written to the
1047 .I ctl
1048 file describe the filter. Packets matching the filter can be read on the
1049 .B data
1050 file.  Packets written to the
1051 .B data
1052 file are routed to an interface and transmitted.
1053 .PP
1054 A filter is a semicolon-separated list of
1055 relations.  Each relation describes a portion
1056 of a packet to match.  The possible relations are:
1057 .TF "\fLdata[\fIn\fL:\fIm\fL]=\fIexpr\fR "
1058 .PD
1059 .TP
1060 .BI proto= n
1061 the IP protocol number must be
1062 .IR n .
1063 .TP
1064 .BI data[ n : m ]= expr
1065 bytes
1066 .I n
1067 through
1068 .I m
1069 following the IP packet must match
1070 .IR expr .
1071 .TP
1072 .BI iph[ n : m ]= expr
1073 bytes
1074 .I n
1075 through
1076 .I m
1077 of the IP packet header must match
1078 .IR expr .
1079 .TP
1080 .BI ifc= expr
1081 the packet must have been received on an interface whose address
1082 matches
1083 .IR expr .
1084 .TP
1085 .BI src= expr
1086 The source address in the packet must match
1087 .IR expr .
1088 .TP
1089 .BI dst= expr
1090 The destination address in the packet must match
1091 .IR expr .
1092 .PP
1093 .I Expr
1094 is of the form:
1095 .TP
1096 .I \    value
1097 .TP
1098 .IB \   value | value | ...
1099 .TP
1100 .IB \   value & mask
1101 .TP
1102 .IB \   value | value & mask
1103 .PP
1104 If a mask is given, the relevant field is first ANDed with
1105 the mask.  The result is compared against the value or list
1106 of values for a match.  In the case of
1107 .BR ifc ,
1108 .BR dst ,
1109 and
1110 .B src
1111 the value is a dot-formatted IP address and the mask is a dot-formatted
1112 IP mask.  In the case of
1113 .BR data ,
1114 .B iph
1115 and
1116 .BR proto ,
1117 both value and mask are strings of 2 hexadecimal digits representing
1118 8-bit values.
1119 .PP
1120 A packet is delivered to only one filter.
1121 The filters are merged into a single comparison tree.
1122 If two filters match the same packet, the following
1123 rules apply in order (here '>' means is preferred to):
1124 .IP 1)
1125 protocol > data > source > destination > interface
1126 .IP 2)
1127 lower data offsets > higher data offsets
1128 .IP 3)
1129 longer matches > shorter matches
1130 .IP 4)
1131 older > younger
1132 .PP
1133 So far this has just been used to implement a version of
1134 OSPF in Inferno
1135 and 6to4 tunnelling.
1136 .br
1137 .ne 5
1138 .
1139 .SS Statistics
1140 The
1141 .B stats
1142 files are read only and contain statistics useful to network monitoring.
1143 .br
1144 .ne 12
1145 .PP
1146 Reading
1147 .B /net/ipifc/stats
1148 returns a list of 19 tagged and newline-separated fields representing:
1149 .EX
1150 .ft 1
1151 .2C
1152 .in +0.25i
1153 forwarding status (0 and 2 mean forwarding off,
1154         1 means on)
1155 default TTL
1156 input packets
1157 input header errors
1158 input address errors
1159 packets forwarded
1160 input packets for unknown protocols
1161 input packets discarded
1162 input packets delivered to higher level protocols
1163 output packets
1164 output packets discarded
1165 output packets with no route
1166 timed out fragments in reassembly queue
1167 requested reassemblies
1168 successful reassemblies
1169 failed reassemblies
1170 successful fragmentations
1171 unsuccessful fragmentations
1172 fragments created
1173 .in -0.25i
1174 .1C
1175 .ft
1176 .EE
1177 .br
1178 .ne 16
1179 .PP
1180 Reading
1181 .B /net/icmp/stats
1182 returns a list of 26 tagged and newline-separated fields representing:
1183 .EX
1184 .ft 1
1185 .2C
1186 .in +0.25i
1187 messages received
1188 bad received messages
1189 unreachables received
1190 time exceededs received
1191 input parameter problems received
1192 source quenches received
1193 redirects received
1194 echo requests received
1195 echo replies received
1196 timestamps received
1197 timestamp replies received
1198 address mask requests received
1199 address mask replies received
1200 messages sent
1201 transmission errors
1202 unreachables sent
1203 time exceededs sent
1204 input parameter problems sent
1205 source quenches sent
1206 redirects sent
1207 echo requests sent
1208 echo replies sent
1209 timestamps sent
1210 timestamp replies sent
1211 address mask requests sent
1212 address mask replies sent
1213 .in -0.25i
1214 .1C
1215 .EE
1216 .PP
1217 Reading
1218 .B /net/tcp/stats
1219 returns a list of 11 tagged and newline-separated fields representing:
1220 .EX
1221 .ft 1
1222 .2C
1223 .in +0.25i
1224 maximum number of connections
1225 total outgoing calls
1226 total incoming calls
1227 number of established connections to be reset
1228 number of currently established connections
1229 segments received
1230 segments sent
1231 segments retransmitted
1232 retransmit timeouts
1233 bad received segments
1234 transmission failures
1235 .in -0.25i
1236 .1C
1237 .EE
1238 .PP
1239 Reading
1240 .B /net/udp/stats
1241 returns a list of 4 tagged and newline-separated fields representing:
1242 .EX
1243 .ft 1
1244 .2C
1245 .in +0.25i
1246 datagrams received
1247 datagrams received for bad ports
1248 malformed datagrams received
1249 datagrams sent
1250 .in -0.25i
1251 .1C
1252 .EE
1253 .PP
1254 Reading
1255 .B /net/il/stats
1256 returns a list of 6 tagged and newline-separated fields representing:
1257 .EX
1258 .ft 1
1259 .2C
1260 .in +0.25i
1261 checksum errors
1262 header length errors
1263 out of order messages
1264 retransmitted messages
1265 duplicate messages
1266 duplicate bytes
1267 .in -0.25i
1268 .1C
1269 .EE
1270 .PP
1271 Reading
1272 .B /net/gre/stats
1273 returns a list of 1 tagged number representing:
1274 .EX
1275 .ft 1
1276 .in +0.25i
1277 header length errors
1278 .in -0.25i
1279 .EE
1280 .SH "SEE ALSO"
1281 .IR dial (2),
1282 .IR ip (2),
1283 .IR bridge (3),
1284 .\" .IR ike (4),
1285 .IR ndb (6),
1286 .IR listen (8)
1287 .br
1288 .PD 0
1289 .TF "\fL/lib/rfc/rfc2822"
1290 .TP
1291 .B /lib/rfc/rfc2460
1292 IPv6
1293 .TP
1294 .B /lib/rfc/rfc4291
1295 IPv6 address architecture
1296 .TP
1297 .B /lib/rfc/rfc4443
1298 ICMPv6
1299 .SH SOURCE
1300 .B /sys/src/9/ip
1301 .SH BUGS
1302 .I Ipmux
1303 has not been heavily used and should be considered experimental.
1304 It may disappear in favor of a more traditional packet filter in the future.