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