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