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