Linux kernel Analysis

Source: Internet
Author: User
Tags socket

Kernel version: 2.6.34

When sending a message, you can call the function setsockopt () to set the appropriate options, this article mainly analyzes the generation of IP options, send and receive the implementation of the process, selected LSRR as an example to illustrate, mainly divided into the generation of options, option forwarding, the choice of receiving three parts.

Take a look at the example of a source-station routing option, which is illustrated below.

Host ip:192.168.1.99

Source route: 192.168.1.1 192.168.1.2 192.168.1.100 [dest IP]

Source Station routing options on individual hosts:

The figure differs from the example on the <TCP/IP volume > because the options [#R1, R2, D] are annotated in the form of the actual transfer, and the following figure is the specific form of the source-station routing option in this process:

When you create a socket, you can use setsockopt () to set various properties that create the socket, setsockopt () to eventually invoke the System interface Sys_setsockopt ().

Sys_setsockopt ()

Level (levels) specifies the code that interprets the options in the system: a generic set interface code, or code for a particular protocol. Level==sol_socket is a generic set of interface options, that is, not for a protocol's socket, using the function sock_setsockopt () to set the options; level other value: Ipproto_ip, Ipproto_icmpv6, Ipproto_ipv6 is a specific protocol set interface that uses sock->ops->setsockopt (socket-specific functions) to set options.

if (level = = Sol_socket)     
 err = sock_setsockopt (sock, level, optname, Optval, Optlen);     
else 
err = sock->ops->setsockopt (sock, level, optname, Optval, Optlen);

The following is a specific example, build options-use setsockopt () to set IP options as follows:

SetSockOpt (FD, IPPROTO_IP, Ip_options, &opt, Optlen);

The incoming opt format is as follows:

Regardless of the message (corresponding to different sock), setting the IP option will eventually invoke Ip_setsockopt (). For example, the UDP socket is created, the calling process is: sock->ops->setsockopt () => udp_setsockopt ()-> ip_setsockopt (). The main processing IP options are done by do_ip_setsockopt ().

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.