Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 12: Networks


Data are sent and received by placing them on wait queues (sk_receive_queueandsk_write_queue)
that contain socket buffers.

In addition, a list of callback functions is associated with eachsockstructure used by the kernel to draw
attention to special events or bring about state changes. Our simplified version shows only one function
pointer calledsk_data_readybecause it is the most significant and its name has already been mentioned
several times in the last few chapters. The function it contains is invoked when data arrive for handling
by the user process. Typically, the value of the pointer issock_def_readable.

There is a great danger of confusion between theopselement of typestruct proto_opsin thesocket
structure and theprotentry of typestruct protoinsock. The latter is defined as follows:

include/net/sock.h
struct proto {
void (*close)(struct sock *sk,
long timeout);
int (*connect)(struct sock *sk,
struct sockaddr *uaddr,
int addr_len);
int (*disconnect)(struct sock *sk, int flags);

struct sock * (*accept) (struct sock *sk, int flags, int *err);

int (*ioctl)(struct sock *sk, int cmd,
unsigned long arg);
int (*init)(struct sock *sk);
int (*destroy)(struct sock *sk);
void (*shutdown)(struct sock *sk, int how);
int (*setsockopt)(struct sock *sk, int level,
int optname, char __user *optval,
int optlen);
int (*getsockopt)(struct sock *sk, int level,
int optname, char __user *optval,
int __user *option);
...
int (*sendmsg)(struct kiocb *iocb, struct sock *sk,
struct msghdr *msg, size_t len);
int (*recvmsg)(struct kiocb *iocb, struct sock *sk,
struct msghdr *msg,
size_t len, int noblock, int flags,
int *addr_len);
int (*sendpage)(struct sock *sk, struct page *page,
int offset, size_t size, int flags);
int (*bind)(struct sock *sk,
struct sockaddr *uaddr, int addr_len);
struct sockaddr *uaddr, int addr_len);
...
};

Both structures have member elements with similar (and often identical) names although they represent
different functions. Whereas the operations shown here are used for communication between the (kernel-
side) socket layer and transport layer, the functions held in the function pointer block of thesocket
Free download pdf