PageRenderTime 39ms CodeModel.GetById 14ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/freebsd/freebsd-head/
Unknown | 145 lines | 145 code | 0 blank | 0 comment | 0 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
 41A raw socket is an object which allows users direct access
 42to a lower-level protocol.  Raw sockets are intended for knowledgeable
 43processes which wish to take advantage of some protocol
 44feature not directly accessible through the normal interface, or 
 45for the development of new protocols built atop existing lower level
 46protocols.  For example, a new version of TCP might be developed at the
 47user level by utilizing a raw IP socket for delivery of packets.
 48The raw IP socket interface attempts to provide an identical interface
 49to the one a protocol would have if it were resident in the kernel.
 50.PP
 51The raw socket support is built around a generic raw socket interface,
 52(possibly) augmented by protocol-specific processing routines.
 53This section will describe the core of the raw socket interface.
 54.NH 2
 55Control blocks
 56.PP
 57Every 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 
 60struct 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
 73All the control blocks are kept on a doubly linked list for
 74performing lookups during packet dispatch.  Associations may
 75be recorded in the control block and used by the output routine
 76in preparing packets for transmission.
 77The \fIrcb_proto\fP structure contains the protocol family and protocol
 78number with which the raw socket is associated.
 79The protocol, family and addresses are
 80used to filter packets on input; this will be described in more
 81detail shortly.  If any protocol-specific information is required,
 82it may be attached to the control block using the \fIrcb_pcb\fP
 83field.
 84Protocol-specific options for transmission in outgoing packets
 85may be stored in \fIrcb_options\fP.
 86.PP
 87A raw socket interface is datagram oriented.  That is, each send
 88or receive on the socket requires a destination address.  This
 89address may be supplied by the user or stored in the control block
 90and automatically installed in the outgoing packet by the output
 91routine.  Since it is not possible to determine whether an address
 92is present or not in the control block, two flags, RAW_LADDR and
 93RAW_FADDR, indicate if a local and foreign address are present.
 94Routing is expected to be performed by the underlying protocol
 95if necessary.
 96.NH 2
 97Input processing
 98.PP
 99Input packets are ``assigned'' to raw sockets based on a simple
100pattern matching scheme.  Each network interface or protocol
101gives unassigned packets
102to the raw input routine with the call:
103.DS
104raw_input(m, proto, src, dst)
105struct mbuf *m; struct sockproto *proto, struct sockaddr *src, *dst;
106.DE
107The data packet then has a generic header prepended to it of the
108form
109.DS
110._f
111struct raw_header {
112	struct	sockproto raw_proto;
113	struct	sockaddr raw_dst;
114	struct	sockaddr raw_src;
115};
116.DE
117and it is placed in a packet queue for the ``raw input protocol'' module.
118Packets taken from this queue are copied into any raw sockets that
119match the header according to the following rules,
120.IP 1)
121The protocol family of the socket and header agree.
122.IP 2)
123If the protocol number in the socket is non-zero, then it agrees
124with that found in the packet header.
125.IP 3)
126If a local address is defined for the socket, the address format
127of the local address is the same as the destination address's and
128the two addresses agree bit for bit.
129.IP 4)
130The rules of 3) are applied to the socket's foreign address and the packet's
131source address.
132.LP
133A basic assumption is that addresses present in the
134control block and packet header (as constructed by the network
135interface and any raw input protocol module) are in a canonical
136form which may be ``block compared''.
137.NH 2
138Output processing
139.PP
140On output the raw \fIpr_usrreq\fP routine 
141passes the packet and a pointer to the raw control block to the
142raw protocol output routine for any processing required before
143it is delivered to the appropriate network interface.  The
144output routine is normally the only code required to implement
145a raw socket interface.