ip 27 KB

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