📄 b.t
字号:
.\" Copyright (c) 1983, 1986, 1993.\" The Regents of the University of California. All rights reserved..\".\" Redistribution and use in source and binary forms, with or without.\" modification, are permitted provided that the following conditions.\" are met:.\" 1. Redistributions of source code must retain the above copyright.\" notice, this list of conditions and the following disclaimer..\" 2. Redistributions in binary form must reproduce the above copyright.\" notice, this list of conditions and the following disclaimer in the.\" documentation and/or other materials provided with the distribution..\" 3. All advertising materials mentioning features or use of this software.\" must display the following acknowledgement:.\" This product includes software developed by the University of.\" California, Berkeley and its contributors..\" 4. Neither the name of the University nor the names of its contributors.\" may be used to endorse or promote products derived from this software.\" without specific prior written permission..\".\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION).\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF.\" SUCH DAMAGE..\".\" @(#)b.t 8.1 (Berkeley) 6/8/93.\".nr H2 1.\".ds RH "Raw sockets.br.ne 2i.NH\s+2Raw sockets\s0.PPA raw socket is an object which allows users direct accessto a lower-level protocol. Raw sockets are intended for knowledgeableprocesses which wish to take advantage of some protocolfeature not directly accessible through the normal interface, or for the development of new protocols built atop existing lower levelprotocols. For example, a new version of TCP might be developed at theuser level by utilizing a raw IP socket for delivery of packets.The raw IP socket interface attempts to provide an identical interfaceto the one a protocol would have if it were resident in the kernel..PPThe raw socket support is built around a generic raw socket interface,(possibly) augmented by protocol-specific processing routines.This section will describe the core of the raw socket interface..NH 2Control blocks.PPEvery raw socket has a protocol control block of the following form:.DS.ta \w'struct 'u +\w'caddr_t 'u +\w'sockproto rcb_proto; 'u struct rawcb { struct rawcb *rcb_next; /* doubly linked list */ struct rawcb *rcb_prev; struct socket *rcb_socket; /* back pointer to socket */ struct sockaddr rcb_faddr; /* destination address */ struct sockaddr rcb_laddr; /* socket's address */ struct sockproto rcb_proto; /* protocol family, protocol */ caddr_t rcb_pcb; /* protocol specific stuff */ struct mbuf *rcb_options; /* protocol specific options */ struct route rcb_route; /* routing information */ short rcb_flags;};.DEAll the control blocks are kept on a doubly linked list forperforming lookups during packet dispatch. Associations maybe recorded in the control block and used by the output routinein preparing packets for transmission.The \fIrcb_proto\fP structure contains the protocol family and protocolnumber with which the raw socket is associated.The protocol, family and addresses areused to filter packets on input; this will be described in moredetail shortly. If any protocol-specific information is required,it may be attached to the control block using the \fIrcb_pcb\fPfield.Protocol-specific options for transmission in outgoing packetsmay be stored in \fIrcb_options\fP..PPA raw socket interface is datagram oriented. That is, each sendor receive on the socket requires a destination address. Thisaddress may be supplied by the user or stored in the control blockand automatically installed in the outgoing packet by the outputroutine. Since it is not possible to determine whether an addressis present or not in the control block, two flags, RAW_LADDR andRAW_FADDR, indicate if a local and foreign address are present.Routing is expected to be performed by the underlying protocolif necessary..NH 2Input processing.PPInput packets are ``assigned'' to raw sockets based on a simplepattern matching scheme. Each network interface or protocolgives unassigned packetsto the raw input routine with the call:.DSraw_input(m, proto, src, dst)struct mbuf *m; struct sockproto *proto, struct sockaddr *src, *dst;.DEThe data packet then has a generic header prepended to it of theform.DS._fstruct raw_header { struct sockproto raw_proto; struct sockaddr raw_dst; struct sockaddr raw_src;};.DEand it is placed in a packet queue for the ``raw input protocol'' module.Packets taken from this queue are copied into any raw sockets thatmatch the header according to the following rules,.IP 1)The protocol family of the socket and header agree..IP 2)If the protocol number in the socket is non-zero, then it agreeswith that found in the packet header..IP 3)If a local address is defined for the socket, the address formatof the local address is the same as the destination address's andthe two addresses agree bit for bit..IP 4)The rules of 3) are applied to the socket's foreign address and the packet'ssource address..LPA basic assumption is that addresses present in thecontrol block and packet header (as constructed by the networkinterface and any raw input protocol module) are in a canonicalform which may be ``block compared''..NH 2Output processing.PPOn output the raw \fIpr_usrreq\fP routine passes the packet and a pointer to the raw control block to theraw protocol output routine for any processing required beforeit is delivered to the appropriate network interface. Theoutput routine is normally the only code required to implementa raw socket interface.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -