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 ().