ip 24 KB

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