ip 25 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186
  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. The IP device implements 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\ Media-addr
  168. Treat the multicast
  169. .I Media-addr
  170. on this interface as a local address.
  171. .TP
  172. .BI remmulti\ Media-addr
  173. Remove the multicast address
  174. .I Media-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. .I 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. .TF "tag str"
  353. .PD
  354. .TP
  355. .B flush
  356. Remove all routes.
  357. .TP
  358. .BI tag\ string
  359. Associate the tag,
  360. .IR string ,
  361. with all subsequent routes added via this file descriptor.
  362. .TP
  363. .BI add\ "target mask nexthop"
  364. Add the route to the table. If one already exists with the
  365. same target and mask, replace it.
  366. .TP
  367. .BI remove\ "target mask"
  368. Remove a route with a matching target and mask.
  369. .SS "Address resolution
  370. .PP
  371. The file
  372. .B /net/arp
  373. controls information about address resolution.
  374. The kernel automatically updates the v4 ARP and v6 Neighbour Discovery
  375. information for Ethernet interfaces.
  376. When read, the file returns one line per address containing the
  377. type of medium, the status of the entry (OK, WAIT), the IP
  378. address, and the medium address.
  379. Writing to
  380. .B /net/arp
  381. administers the ARP information.
  382. The control messages are:
  383. .TF "del addr"
  384. .PD
  385. .TP
  386. .B flush
  387. Remove all entries.
  388. .TP
  389. .BI add\ "type IP-addr Media-addr"
  390. Add an entry or replace an existing one for the
  391. same IP address.
  392. .TP
  393. .BI del\ "IP-addr"
  394. Delete an individual entry.
  395. .PP
  396. ARP entries do not time out. The ARP table is a
  397. cache with an LRU replacement policy. The IP stack
  398. listens for all ARP requests and, if the requester is in
  399. the table, the entry is updated.
  400. Also, whenever a new address is configured onto an
  401. Ethernet, an ARP request is sent to help
  402. update the table on other systems.
  403. .PP
  404. Currently, the only medium type is
  405. .BR ether .
  406. .br
  407. .ne 3
  408. .SS "Debugging and stack information
  409. .PP
  410. If any process is holding
  411. .B /net/log
  412. open, the IP stack queues debugging information to it.
  413. This is intended primarily for debugging the IP stack.
  414. The information provided is implementation-defined;
  415. see the source for details. Generally, what is returned is error messages
  416. about bad packets.
  417. .PP
  418. Writing to
  419. .B /net/log
  420. controls debugging. The control messages
  421. are:
  422. .TP
  423. .BI set\ arglist
  424. .I Arglist
  425. is a space-separated list of items for which to enable debugging.
  426. The possible items are:
  427. .BR ppp ,
  428. .BR ip ,
  429. .BR fs ,
  430. .BR tcp ,
  431. .BR il ,
  432. .BR icmp ,
  433. .BR udb ,
  434. .BR compress ,
  435. .BR ilmsg ,
  436. .BR gre ,
  437. .BR tcpmsg ,
  438. .BR udpmsg ,
  439. .BR ipmsg ,
  440. and
  441. .BR esp .
  442. .TP
  443. .BI clear\ arglist
  444. .I Arglist
  445. is a space-separated list of items for which to disable debugging.
  446. .TP
  447. .BI only\ addr
  448. If
  449. .I addr
  450. is non-zero, restrict debugging to only those
  451. packets whose source or destination is that
  452. address.
  453. .PP
  454. The file
  455. .B /net/ndb
  456. can be read or written by
  457. programs. It is normally used by
  458. .IR ipconfig (8)
  459. to leave configuration information for other programs
  460. such as
  461. .B dns
  462. and
  463. .B cs
  464. (see
  465. .IR ndb (8)).
  466. .B /net/ndb
  467. may contain up to 1024 bytes.
  468. .PP
  469. The file
  470. .B /net/ipselftab
  471. is a read-only file containing all the IP addresses
  472. considered local. Each line in the file contains
  473. three white-space-separated fields: IP address, usage count,
  474. and flags. The usage count is the number of interfaces to which
  475. the address applies. The flags are the same as for routing
  476. entries.
  477. Note that the `IPv4 route' flag will never be set.
  478. .br
  479. .ne 3
  480. .SS "Protocol directories
  481. .PP
  482. The
  483. .I ip
  484. device
  485. supports IP as well as several protocols that run over it:
  486. TCP, UDP, RUDP, ICMP, IL, GRE, and ESP.
  487. TCP and UDP provide the standard Internet
  488. protocols for reliable stream and unreliable datagram
  489. communication.
  490. RUDP is a locally developed reliable datagram protocol based on
  491. UDP.
  492. ICMP is IP's catch-all control protocol used to send
  493. low level error messages and to implement
  494. .IR ping (8).
  495. IL provides a reliable datagram service for communication
  496. between Plan 9 machines but is now deprecated.
  497. GRE is a general encapsulation protocol.
  498. ESP is the encapsulation protocol for IPsec.
  499. .PP
  500. Each protocol is a subdirectory of the IP stack.
  501. The top level directory of each protocol contains a
  502. .B clone
  503. file, a
  504. .B stats
  505. file, and subdirectories numbered from zero to the number of connections
  506. opened for this protocol.
  507. .PP
  508. Opening the
  509. .B clone
  510. file reserves a connection. The file descriptor returned from the
  511. .IR open (2)
  512. will point to the control file,
  513. .BR ctl ,
  514. of the newly allocated connection.
  515. Reading
  516. .B ctl
  517. returns a text
  518. string representing the number of the
  519. connection.
  520. Connections may be used either to listen for incoming calls
  521. or to initiate calls to other machines.
  522. .PP
  523. A connection is controlled by writing text strings to the associated
  524. .B ctl
  525. file.
  526. After a connection has been established data may be read from
  527. and written to
  528. .BR data .
  529. A connection can be actively established using the
  530. .B connect
  531. message (see also
  532. .IR dial (2)).
  533. A connection can be established passively by first
  534. using an
  535. .B announce
  536. message (see
  537. .IR dial (2))
  538. to bind to a local port and then
  539. opening the
  540. .B listen
  541. file (see
  542. .IR dial (2))
  543. to receive incoming calls.
  544. .PP
  545. The following control messages are supported:
  546. .TF "bind X"
  547. .PD
  548. .TP
  549. .BI connect\ ipaddress ! port "!r " local
  550. Establish a connection to the remote address
  551. .I ipaddress
  552. and remote port
  553. .IR port .
  554. If
  555. .I local
  556. is specified, it is used as the local port number.
  557. If
  558. .I local
  559. is not specified but
  560. .B !r
  561. is, the system will allocate
  562. a restricted port number (less than 1024) for the connection to allow communication
  563. with Unix
  564. .B login
  565. and
  566. .B exec
  567. services.
  568. Otherwise a free port number starting at 5000 is chosen.
  569. The connect fails if the combination of local and remote address/port pairs
  570. are already assigned to another port.
  571. .TP
  572. .BI announce\ X
  573. .I X
  574. is a decimal port number or
  575. .LR * .
  576. Set the local port
  577. number to
  578. .I X
  579. and accept calls to
  580. .IR X .
  581. If
  582. .I X
  583. is
  584. .LR * ,
  585. accept
  586. calls for any port that no process has explicitly announced.
  587. The local IP address cannot be set.
  588. .B Announce
  589. fails if the connection is already announced or connected.
  590. .TP
  591. .BI bind\ X
  592. .I X
  593. is a decimal port number or
  594. .LR * .
  595. Set the local port number to
  596. .IR X .
  597. This exists to support emulation
  598. of BSD sockets by the APE libraries (see
  599. .IR pcc (1))
  600. and is not otherwise used.
  601. .TP
  602. .BI backlog\ n
  603. Set the maximum number of unanswered (queued) incoming
  604. connections to an announced port to
  605. .IR n .
  606. By default
  607. .I n
  608. is set to five. If more than
  609. .I n
  610. connections are pending,
  611. further requests for a service will be rejected.
  612. .TP
  613. .BI ttl\ n
  614. Set the time to live IP field in outgoing packets to
  615. .IR n .
  616. .TP
  617. .BI tos\ n
  618. Set the service type IP field in outgoing packets to
  619. .IR n .
  620. .PP
  621. Port numbers must be in the range 1 to 32767.
  622. .PP
  623. Several files report the status of a
  624. connection.
  625. The
  626. .B remote
  627. and
  628. .B local
  629. files contain the IP address and port number for the remote and local side of the
  630. connection. The
  631. .B status
  632. file contains protocol-dependent information to help debug network connections.
  633. On receiving and error or EOF reading or writing the
  634. .B data
  635. file, the
  636. .B err
  637. file contains the reason for error.
  638. .PP
  639. A process may accept incoming connections by
  640. .IR open (2)ing
  641. the
  642. .B listen
  643. file.
  644. The
  645. .B open
  646. will block until a new connection request arrives.
  647. Then
  648. .B open
  649. will return an open file descriptor which points to the control file of the
  650. newly accepted connection.
  651. This procedure will accept all calls for the
  652. given protocol.
  653. See
  654. .IR dial (2).
  655. .SS TCP
  656. .PP
  657. TCP connections are reliable point-to-point byte streams; there are no
  658. message delimiters.
  659. A connection is determined by the address and port numbers of the two
  660. ends.
  661. TCP
  662. .B ctl
  663. files support the following additional messages:
  664. .TF keepaliven
  665. .PD
  666. .TP
  667. .B hangup
  668. close down a TCP connection
  669. .TP
  670. .BI keepalive \ n
  671. turn on keep alive messages.
  672. .IR N ,
  673. if given, is the milliseconds between keepalives
  674. (default 30000).
  675. .SS UDP
  676. .PP
  677. UDP connections carry unreliable and unordered datagrams. A read from
  678. .B data
  679. will return the next datagram, discarding anything
  680. that doesn't fit in the read buffer.
  681. A write is sent as a single datagram.
  682. .PP
  683. By default, a UDP connection is a point-to-point link.
  684. Either a
  685. .B connect
  686. establishes a local and remote address/port pair or
  687. after an
  688. .BR announce ,
  689. each datagram coming from a different remote address/port pair
  690. establishes a new incoming connection.
  691. However, many-to-one semantics is also possible.
  692. .PP
  693. If, after an
  694. .BR announce ,
  695. the following message is written to
  696. .BR ctl ,
  697. then all messages sent to the announced port
  698. are received on the announced connection prefixed
  699. with the corresponding structure,
  700. declared in
  701. .BR <ip.h> .
  702. .TP
  703. .B headers
  704. .EX
  705. typedef struct Udphdr Udphdr;
  706. struct Udphdr
  707. {
  708. uchar raddr[16]; /* V6 remote address and port */
  709. uchar laddr[16]; /* V6 local address and port */
  710. uchar ifcaddr[16]; /* V6 interface address (receive only) */
  711. uchar rport[2]; /* remote port */
  712. uchar lport[2]; /* local port */
  713. };
  714. .EE
  715. .PP
  716. Before a write, a user must prefix a similar structure to each message.
  717. The system overrides the user specified local port with the announced
  718. one. If the user specifies an address that isn't a unicast address in
  719. .BR /net/ipselftab ,
  720. that too is overridden.
  721. Since the prefixed structure is the same in read and write, it is relatively
  722. easy to write a server that responds to client requests by just copying new
  723. data into the message body and then writing back the same buffer that was
  724. read.
  725. .PP
  726. In this case (writing
  727. .L headers
  728. or
  729. .L noheaders
  730. to the
  731. .I ctl
  732. file),
  733. no
  734. .I listen
  735. nor
  736. .I accept
  737. is needed;
  738. otherwise,
  739. the usual sequence of
  740. .IR announce ,
  741. .IR listen ,
  742. .I accept
  743. must be executed before performing I/O on the corresponding
  744. .I data
  745. file.
  746. .SS RUDP
  747. .PP
  748. RUDP is a reliable datagram protocol based on UDP.
  749. Packets are delivered in order.
  750. RUDP does not support
  751. .BR listen .
  752. One must write either
  753. .B connect
  754. or
  755. .B announce
  756. followed immediately by
  757. .B headers
  758. to
  759. .BR ctl .
  760. .PP
  761. Unlike IL or TCP, the reboot of one end of a connection does
  762. not force a closing of the connection. Communications will
  763. resume when the rebooted machine resumes talking. Any unacknowledged
  764. packets queued before the reboot will be lost. A reboot can
  765. be detected by reading the
  766. .B err
  767. file. It will contain the message
  768. .IP
  769. .BI hangup\ address ! port
  770. .PP
  771. where
  772. .I address
  773. and
  774. .I port
  775. are of the far side of the connection.
  776. Retransmitting a datagram more than 10 times
  777. is treated like a reboot:
  778. all queued messages are dropped, an error is queued to the
  779. .B err
  780. file, and the conversation resumes.
  781. .SS ICMP
  782. .PP
  783. ICMP is a datagram protocol for IPv4 used to exchange control requests and
  784. their responses with other machines' IP implementations.
  785. ICMP is primarily a kernel-to-kernel protocol, but it is possible
  786. to generate `echo request' and read `echo reply' packets from user programs.
  787. .SS ICMPV6
  788. ICMPv6 is the IPv6 equivalent of ICMP.
  789. If, after an
  790. .BR announce ,
  791. the following message is written to
  792. .BR ctl ,
  793. then before a write,
  794. a user must prefix each message with a corresponding structure,
  795. declared in
  796. .BR <ip.h> .
  797. .TP
  798. .B headers
  799. .EX
  800. /*
  801. * user level icmpv6 with control message "headers"
  802. */
  803. typedef struct Icmp6hdr Icmp6hdr;
  804. struct Icmp6hdr {
  805. uchar unused[8];
  806. uchar laddr[IPaddrlen]; /* local address */
  807. uchar raddr[IPaddrlen]; /* remote address */
  808. };
  809. .EE
  810. .PP
  811. In this case (writing
  812. .L headers
  813. to the
  814. .I ctl
  815. file),
  816. no
  817. .I listen
  818. nor
  819. .I accept
  820. is needed;
  821. otherwise,
  822. the usual sequence of
  823. .IR announce ,
  824. .IR listen ,
  825. .I accept
  826. must be executed before performing I/O on the corresponding
  827. .I data
  828. file.
  829. .SS IL
  830. .PP
  831. IL is a reliable point-to-point datagram protocol. Like TCP, IL delivers datagrams
  832. reliably and in order. Also like TCP, a connection is
  833. determined by the address and port numbers of the two ends.
  834. Like UDP, each read and write transfers a single datagram.
  835. .PP
  836. IL is efficient for LANs but doesn't have the
  837. congestion control features needed for use through
  838. the Internet.
  839. It is no longer necessary, except to communicate with old standalone
  840. .IR fs (4)
  841. file servers.
  842. Its use is now deprecated.
  843. .SS GRE
  844. .PP
  845. GRE is the encapsulation protocol used by PPTP.
  846. The kernel implements just enough of the protocol
  847. to multiplex it.
  848. .B Announce
  849. is not allowed in GRE, only
  850. .BR connect .
  851. Since GRE has no port numbers, the port number in the connect
  852. is actually the 16 bit
  853. .B eproto
  854. field in the GRE header.
  855. .PP
  856. Reads and writes transfer a
  857. GRE datagram starting at the GRE header.
  858. On write, the kernel fills in the
  859. .B eproto
  860. field with the port number specified
  861. in the connect message.
  862. .br
  863. .ne 3
  864. .SS ESP
  865. .PP
  866. ESP is the Encapsulating Security Payload (RFC 1827).
  867. It is used to set up an encrypted tunnel between machines.
  868. Like GRE, ESP has no port numbers. Instead, the
  869. port number in the
  870. .B connect
  871. message is the SPI (Security Association Identifier (sic)).
  872. IP packets are written to and read from
  873. .BR data .
  874. The kernel encrypts any packets written to
  875. .BR data ,
  876. appends a MAC, and prefixes an ESP header before
  877. sending to the other end of the tunnel.
  878. Received packets are checked against their MAC's,
  879. decrypted, and queued for reading from
  880. .BR data .
  881. The control messages are:
  882. .TF "alg secret"
  883. .PD
  884. .TP
  885. .BI esp\ "alg secret
  886. Encrypt with the algorithm,
  887. .IR alg ,
  888. using
  889. .I secret
  890. as the key.
  891. Possible algorithms are:
  892. .BR null ,
  893. .BR des_56_cbc ,
  894. and
  895. .BR rc4_128 .
  896. .TP
  897. .BI ah\ "alg secret
  898. Use the hash algorithm,
  899. .IR alg ,
  900. with
  901. .I secret
  902. as the key for generating the MAC.
  903. Possible algorithms are:
  904. .BR null ,
  905. .BR hmac_sha1_96 ,
  906. and
  907. .BR hmac_md5_96 .
  908. .TP
  909. .B header
  910. Turn on header mode. Every buffer read from
  911. .B data
  912. starts with 4 unused bytes, and the first 4 bytes
  913. of every buffer written to
  914. .B data
  915. are ignored.
  916. .TP
  917. .B noheader
  918. Turn off header mode.
  919. .SS "IP packet filter
  920. .PP
  921. The directory
  922. .B /net/ipmux
  923. looks like another protocol directory.
  924. It is a packet filter built on top of IP. Each numbered
  925. subdirectory represents a different filter.
  926. The connect messages written to the
  927. .I ctl
  928. file describe the filter. Packets matching the filter can be read on the
  929. .B data
  930. file. Packets written to the
  931. .B data
  932. file are routed to an interface and transmitted.
  933. .PP
  934. A filter is a semicolon-separated list of
  935. relations. Each relation describes a portion
  936. of a packet to match. The possible relations are:
  937. .TF "ifc=expr"
  938. .PD
  939. .TP
  940. .BI proto= n
  941. the IP protocol number must be
  942. .IR n .
  943. .TP
  944. .BI data[ n : m ]= expr
  945. bytes
  946. .I n
  947. through
  948. .I m
  949. following the IP packet must match
  950. .IR expr .
  951. .TP
  952. .BI iph[ n : m ]= expr
  953. bytes
  954. .I n
  955. through
  956. .I m
  957. of the IP packet header must match
  958. .IR expr .
  959. .TP
  960. .BI ifc= expr
  961. the packet must have been received on an interface whose address
  962. matches
  963. .IR expr .
  964. .TP
  965. .BI src= expr
  966. The source address in the packet must match
  967. .IR expr .
  968. .TP
  969. .BI dst= expr
  970. The destination address in the packet must match
  971. .IR expr .
  972. .PP
  973. .I Expr
  974. is of the form:
  975. .TP
  976. .I \ value
  977. .TP
  978. .IB \ value | value | ...
  979. .TP
  980. .IB \ value & mask
  981. .TP
  982. .IB \ value | value & mask
  983. .PP
  984. If a mask is given, the relevant field is first ANDed with
  985. the mask. The result is compared against the value or list
  986. of values for a match. In the case of
  987. .BR ifc ,
  988. .BR dst ,
  989. and
  990. .B src
  991. the value is a dot-formatted IP address and the mask is a dot-formatted
  992. IP mask. In the case of
  993. .BR data ,
  994. .B iph
  995. and
  996. .BR proto ,
  997. both value and mask are strings of 2 hexadecimal digits representing
  998. 8-bit values.
  999. .PP
  1000. A packet is delivered to only one filter.
  1001. The filters are merged into a single comparison tree.
  1002. If two filters match the same packet, the following
  1003. rules apply in order (here '>' means is preferred to):
  1004. .IP 1)
  1005. protocol > data > source > destination > interface
  1006. .IP 2)
  1007. lower data offsets > higher data offsets
  1008. .IP 3)
  1009. longer matches > shorter matches
  1010. .IP 4)
  1011. older > younger
  1012. .PP
  1013. So far this has just been used to implement a version of
  1014. OSPF in Inferno
  1015. and 6to4 tunnelling.
  1016. .br
  1017. .ne 5
  1018. .SS Statistics
  1019. .PP
  1020. The
  1021. .B stats
  1022. files are read only and contain statistics useful to network monitoring.
  1023. .br
  1024. .ne 14
  1025. .PP
  1026. Reading
  1027. .B /net/ipifc/stats
  1028. returns a list of 19 tagged and newline-separated fields representing:
  1029. .EX
  1030. .ft 1
  1031. .2C
  1032. .in +0.25i
  1033. forwarding status (0 and 2 mean forwarding off,
  1034. 1 means on)
  1035. default TTL
  1036. input packets
  1037. input header errors
  1038. input address errors
  1039. packets forwarded
  1040. input packets for unknown protocols
  1041. input packets discarded
  1042. input packets delivered to higher level protocols
  1043. output packets
  1044. output packets discarded
  1045. output packets with no route
  1046. timed out fragments in reassembly queue
  1047. requested reassemblies
  1048. successful reassemblies
  1049. failed reassemblies
  1050. successful fragmentations
  1051. unsuccessful fragmentations
  1052. fragments created
  1053. .in -0.25i
  1054. .1C
  1055. .ft
  1056. .EE
  1057. .br
  1058. .ne 16
  1059. .PP
  1060. Reading
  1061. .B /net/icmp/stats
  1062. returns a list of 26 tagged and newline-separated fields representing:
  1063. .EX
  1064. .ft 1
  1065. .2C
  1066. .in +0.25i
  1067. messages received
  1068. bad received messages
  1069. unreachables received
  1070. time exceededs received
  1071. input parameter problems received
  1072. source quenches received
  1073. redirects received
  1074. echo requests received
  1075. echo replies received
  1076. timestamps received
  1077. timestamp replies received
  1078. address mask requests received
  1079. address mask replies received
  1080. messages sent
  1081. transmission errors
  1082. unreachables sent
  1083. time exceededs sent
  1084. input parameter problems sent
  1085. source quenches sent
  1086. redirects sent
  1087. echo requests sent
  1088. echo replies sent
  1089. timestamps sent
  1090. timestamp replies sent
  1091. address mask requests sent
  1092. address mask replies sent
  1093. .in -0.25i
  1094. .1C
  1095. .EE
  1096. .PP
  1097. Reading
  1098. .B /net/tcp/stats
  1099. returns a list of 11 tagged and newline-separated fields representing:
  1100. .EX
  1101. .ft 1
  1102. .2C
  1103. .in +0.25i
  1104. maximum number of connections
  1105. total outgoing calls
  1106. total incoming calls
  1107. number of established connections to be reset
  1108. number of currently established connections
  1109. segments received
  1110. segments sent
  1111. segments retransmitted
  1112. retransmit timeouts
  1113. bad received segments
  1114. transmission failures
  1115. .in -0.25i
  1116. .1C
  1117. .EE
  1118. .PP
  1119. Reading
  1120. .B /net/udp/stats
  1121. returns a list of 4 tagged and newline-separated fields representing:
  1122. .EX
  1123. .ft 1
  1124. .2C
  1125. .in +0.25i
  1126. datagrams received
  1127. datagrams received for bad ports
  1128. malformed datagrams received
  1129. datagrams sent
  1130. .in -0.25i
  1131. .1C
  1132. .EE
  1133. .PP
  1134. Reading
  1135. .B /net/il/stats
  1136. returns a list of 6 tagged and newline-separated fields representing:
  1137. .EX
  1138. .ft 1
  1139. .2C
  1140. .in +0.25i
  1141. checksum errors
  1142. header length errors
  1143. out of order messages
  1144. retransmitted messages
  1145. duplicate messages
  1146. duplicate bytes
  1147. .in -0.25i
  1148. .1C
  1149. .EE
  1150. .PP
  1151. Reading
  1152. .B /net/gre/stats
  1153. returns a list of 1 tagged number representing:
  1154. .EX
  1155. .ft 1
  1156. .in +0.25i
  1157. header length errors
  1158. .in -0.25i
  1159. .EE
  1160. .SH "SEE ALSO"
  1161. .IR dial (2),
  1162. .IR ip (2),
  1163. .IR ndb (6),
  1164. .IR listen (8)
  1165. .br
  1166. .PD 0
  1167. .TF /lib/rfc/rfc2822
  1168. .TP
  1169. .B /lib/rfc/rfc2460
  1170. IPv6
  1171. .TP
  1172. .B /lib/rfc/rfc4291
  1173. IPv6 address architecture
  1174. .TP
  1175. .B /lib/rfc/rfc4443
  1176. ICMPv6
  1177. .SH SOURCE
  1178. .B /sys/src/9/ip
  1179. .SH BUGS
  1180. .I Ipmux
  1181. has not been heavily used and should be considered experimental.
  1182. It may disappear in favor of a more traditional packet filter in the future.