Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 12: Networks


int optname, char user *optval, int user optlen);
int (
compat_setsockopt)(struct socket sock, int level,
int optname, char __user
optval, int optlen);
int (compat_getsockopt)(struct socket sock, int level,
int optname, char user *optval, int user optlen);
int (
sendmsg) (struct kiocb iocb, struct socket sock,
struct msghdr m, size_t total_len);
int (
recvmsg) (struct kiocb iocb, struct socket sock,
struct msghdr m, size_t total_len,
int flags);
int (
mmap) (struct file file, struct socket sock,
struct vm_area_struct vma);
ssize_t (
sendpage) (struct socket sock, struct page page,
int offset, size_t size, int flags);
};


Many function pointers have the same name as the corresponding functions in the C standard library.
This is not a coincidence because the functions are directed to the functions stored in the pointers by
means of thesocketcallsystem call.

Thesockpointer also included in the structure points to a much lengthier structure that holds additional
socket management data of significance to the kernel. The structure consists of a horrendous number of
elements used for sometimes very subtle or seldom required features (the original definition is almost
100 lines long). Here I make do with a much shorter and simplified version. Note that the kernel itself
places the most important elements in the structuresock_commonthat is embedded intostruct sock
right at the beginning. The following code excerpt shows both structures:

include/net/sock.h
struct sock_common {
unsigned short skc_family;
volatile unsigned char skc_state;
struct hlist_node skc_node;
unsigned int skc_hash;
atomic_t skc_refcnt;
struct proto *skc_prot;
};

struct sock {
struct sock_common __sk_common;

struct sk_buff_head sk_receive_queue;
struct sk_buff_head sk_write_queue;

struct timer_list sk_timer;
void (*sk_data_ready)(struct sock *sk, int bytes);
...
};

Thesockstructures of the system are organized in a protocol-specific hash table.skc_nodeis the hash
linkage element, whileskc_hashdenotes the hash value.
Free download pdf