Details of TCP/IP 2: Implementation-Route Selection

Source: Internet
Author: User

Details of TCP/IP 2: Implementation-Route Selection

A process uses a plug-in the routing domain to send and receive routing packets. A PF_ROUTE

And a SOCK_RAW plug-in type. This process can send the following five optional packets to the kernel:

1. RTM_ADD: Add a new route.

2. RTM_DELETE: delete an existing route.

3. RTM_GET: obtains all information about a route.

4. RTM_CHANGE: Change the gateway, interface, or measurement of an existing route.

5. RTM_LOCK: indicates which variable should not be modified by the kernel.

This chapter describes the selection fields, the routing control blocks created for each selection plug-in, the functions used to process the packets generated by the process (route_output), and the routing packets sent to

Or multiple process functions (raw_input), and different functions that support all plug-in operations on an optional plug-in.

1. routedomain and protosw Structure

Lists the domain structure of the PF_ROUTE domain called routedomain.


Unlike Internet domains that support multiple protocols (TCP, UDP, and ICMP), only one protocol of the SOCK_RAW type is supported in the routing domain. List <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + wctQRl9ST1VURdPytcTQrdLp16q7u8/uoaM8L3A + CjxwPjxpbWcgc3JjPQ = "http://www.2cto.com/uploadfile/Collfiles/20141024/2014102409240761.png" alt = "\">

2. Optional control blocks

When you create an optional plug-in by calling the following method,

Socket (PF_ROUTE, SOCK_RAW, protocol );

Assign a routing control block to a corresponding PRU_ATTACH request of the Protocol's user request function (route_usrreq) and connect it to the plug-in structure.

The protocol Parameter limits the type of messages sent to the process on the plug-in to a specific family. For example, if the protocol parameter is described as AF_INET,

Only selected packets containing the Internet address will be sent to this process.

We call these structures a routing control block instead of a raw control block, which shows the definition of the rawcb structure.


In addition, a global structure with the same name is assigned, rawcb, as the header of the two-way linked list, as shown in.


3. route_output Function

When a PRU_SEND request is sent to the user request function of the protocol, route_output is called. This is a process that performs some operations on a routing plug-in.

. The approximate process of the function is as follows:

The system calls the PRU_DETACH request. If the socket Structure points to a protocol control block, two counters in the route_cb structure are reduced by 1: One

Is any_count; the other is a counter based on this protocol.

3. process the request. The raw_usrreq function is called to further process the PRU_xxx request.

4. Increase the number of counters.

5. Connect the plug-in. Connect to the new plug-in permanently to receive route selection packets from the PF_ROUTE family.

6. SO_USELOOPBACK is enabled by default. Enable the SO_USELOOPBACK plug-in option. This is a default enabled plug-in option.

6. raw_usrreq Function

Raw_usrreq completes most of the work of processing user requests in the routing domain. It is called by the route_usrreq function. The processing of user requests is divided into these two functions,

It is because some other protocols call raw_usrreq instead of route_userreq. Raw_usrreq does not want to be a pr_usrreq function. Instead, it is

Common subroutines called by different pr_usrreq functions.

The function mainly processes various PRU_XXX requests:

The result of a socket system call when a PRU_ATTACH request is sent. The request calls the raw_attach function to connect the control block to the two-way linked list.

PRU_DETACH is a request sent by the close system call. This request will call the raw_detach function to delete the control block from the two-way linked list.

The PRU_CONNECT2 request comes from the socketpair System Call and is not supported in the routing selection domain.

The PRU_DISCONNECT request is sent by close before the PRU_DETACH request, because an optional plug-in is always connected. This request will call raw_disconnect to release the control block of the plug-in.

When a PRU_SHUTDOWN request is sent by the shutdown system, the request will call the socantsendmore function to prohibit subsequent write operations.

When a PRU_SEND request is sent by sosend, The pr_output function is called, that is, the route_output function.

If a PRU_ABORT request is sent, the control block is disconnected, the plug is released, and then disconnected.

If a PRU_SENSE request is sent by the fstat system, the function returns OK.

PRU_RCVOOB, PRU_RCVD, PRU_LISTEN, PRU_ACCEPT, and PRU_SENDOOB requests are not supported.

PRU_SOCKADDR and PRU_PEERADDR requests are called by the getsockname and getpeername systems respectively. The former always returns an error,

The bind system call with the local address is not supported in the routing domain. The latter always returns the contents of route_src, which is composed

Route_usrreq is set as an external address.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.