/share/doc/smm/18.net/b.t

https://bitbucket.org/freebsd/freebsd-head/ · Raku · 145 lines · 145 code · 0 blank · 0 comment · 18 complexity · cdb980f8393abfa5238e05a709ed99ad MD5 · raw file

  1. .\" Copyright (c) 1983, 1986, 1993
  2. .\" The Regents of the University of California. All rights reserved.
  3. .\"
  4. .\" Redistribution and use in source and binary forms, with or without
  5. .\" modification, are permitted provided that the following conditions
  6. .\" are met:
  7. .\" 1. Redistributions of source code must retain the above copyright
  8. .\" notice, this list of conditions and the following disclaimer.
  9. .\" 2. Redistributions in binary form must reproduce the above copyright
  10. .\" notice, this list of conditions and the following disclaimer in the
  11. .\" documentation and/or other materials provided with the distribution.
  12. .\" 3. All advertising materials mentioning features or use of this software
  13. .\" must display the following acknowledgement:
  14. .\" This product includes software developed by the University of
  15. .\" California, Berkeley and its contributors.
  16. .\" 4. Neither the name of the University nor the names of its contributors
  17. .\" may be used to endorse or promote products derived from this software
  18. .\" without specific prior written permission.
  19. .\"
  20. .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  21. .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23. .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  24. .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25. .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  26. .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27. .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  28. .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  29. .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. .\" SUCH DAMAGE.
  31. .\"
  32. .\" @(#)b.t 8.1 (Berkeley) 6/8/93
  33. .\"
  34. .nr H2 1
  35. .\".ds RH "Raw sockets
  36. .br
  37. .ne 2i
  38. .NH
  39. \s+2Raw sockets\s0
  40. .PP
  41. A raw socket is an object which allows users direct access
  42. to a lower-level protocol. Raw sockets are intended for knowledgeable
  43. processes which wish to take advantage of some protocol
  44. feature not directly accessible through the normal interface, or
  45. for the development of new protocols built atop existing lower level
  46. protocols. For example, a new version of TCP might be developed at the
  47. user level by utilizing a raw IP socket for delivery of packets.
  48. The raw IP socket interface attempts to provide an identical interface
  49. to the one a protocol would have if it were resident in the kernel.
  50. .PP
  51. The raw socket support is built around a generic raw socket interface,
  52. (possibly) augmented by protocol-specific processing routines.
  53. This section will describe the core of the raw socket interface.
  54. .NH 2
  55. Control blocks
  56. .PP
  57. Every raw socket has a protocol control block of the following form:
  58. .DS
  59. .ta \w'struct 'u +\w'caddr_t 'u +\w'sockproto rcb_proto; 'u
  60. struct rawcb {
  61. struct rawcb *rcb_next; /* doubly linked list */
  62. struct rawcb *rcb_prev;
  63. struct socket *rcb_socket; /* back pointer to socket */
  64. struct sockaddr rcb_faddr; /* destination address */
  65. struct sockaddr rcb_laddr; /* socket's address */
  66. struct sockproto rcb_proto; /* protocol family, protocol */
  67. caddr_t rcb_pcb; /* protocol specific stuff */
  68. struct mbuf *rcb_options; /* protocol specific options */
  69. struct route rcb_route; /* routing information */
  70. short rcb_flags;
  71. };
  72. .DE
  73. All the control blocks are kept on a doubly linked list for
  74. performing lookups during packet dispatch. Associations may
  75. be recorded in the control block and used by the output routine
  76. in preparing packets for transmission.
  77. The \fIrcb_proto\fP structure contains the protocol family and protocol
  78. number with which the raw socket is associated.
  79. The protocol, family and addresses are
  80. used to filter packets on input; this will be described in more
  81. detail shortly. If any protocol-specific information is required,
  82. it may be attached to the control block using the \fIrcb_pcb\fP
  83. field.
  84. Protocol-specific options for transmission in outgoing packets
  85. may be stored in \fIrcb_options\fP.
  86. .PP
  87. A raw socket interface is datagram oriented. That is, each send
  88. or receive on the socket requires a destination address. This
  89. address may be supplied by the user or stored in the control block
  90. and automatically installed in the outgoing packet by the output
  91. routine. Since it is not possible to determine whether an address
  92. is present or not in the control block, two flags, RAW_LADDR and
  93. RAW_FADDR, indicate if a local and foreign address are present.
  94. Routing is expected to be performed by the underlying protocol
  95. if necessary.
  96. .NH 2
  97. Input processing
  98. .PP
  99. Input packets are ``assigned'' to raw sockets based on a simple
  100. pattern matching scheme. Each network interface or protocol
  101. gives unassigned packets
  102. to the raw input routine with the call:
  103. .DS
  104. raw_input(m, proto, src, dst)
  105. struct mbuf *m; struct sockproto *proto, struct sockaddr *src, *dst;
  106. .DE
  107. The data packet then has a generic header prepended to it of the
  108. form
  109. .DS
  110. ._f
  111. struct raw_header {
  112. struct sockproto raw_proto;
  113. struct sockaddr raw_dst;
  114. struct sockaddr raw_src;
  115. };
  116. .DE
  117. and it is placed in a packet queue for the ``raw input protocol'' module.
  118. Packets taken from this queue are copied into any raw sockets that
  119. match the header according to the following rules,
  120. .IP 1)
  121. The protocol family of the socket and header agree.
  122. .IP 2)
  123. If the protocol number in the socket is non-zero, then it agrees
  124. with that found in the packet header.
  125. .IP 3)
  126. If a local address is defined for the socket, the address format
  127. of the local address is the same as the destination address's and
  128. the two addresses agree bit for bit.
  129. .IP 4)
  130. The rules of 3) are applied to the socket's foreign address and the packet's
  131. source address.
  132. .LP
  133. A basic assumption is that addresses present in the
  134. control block and packet header (as constructed by the network
  135. interface and any raw input protocol module) are in a canonical
  136. form which may be ``block compared''.
  137. .NH 2
  138. Output processing
  139. .PP
  140. On output the raw \fIpr_usrreq\fP routine
  141. passes the packet and a pointer to the raw control block to the
  142. raw protocol output routine for any processing required before
  143. it is delivered to the appropriate network interface. The
  144. output routine is normally the only code required to implement
  145. a raw socket interface.