ip 22 KB

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