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