linux/net/socket.c
1. pops is inited in the sock_register() function, and sock_register is called in inet_proto_init/ipx_proto_init, and inet_proto_init/ipx_proto_init is used to initialize the global protocol table.
/*
* The protocol list. Each protocol is registered in here.
*/
static struct proto_ops *pops[NPROTO];
/*
* Protocol Table
*/
struct net_proto protocols[] = {
#ifdef CONFIG_IPX
{ "IPX", ipx_proto_init },
#endif
...
}
and the protocols init is like following,
void proto_init(void)
{
extern struct net_proto protocols[]; /* Network protocols */
struct net_proto *pro;
/* Kick all configured protocols. */
pro = protocols;
while (pro->name != NULL)
{
(*pro->init_func)(pro);
pro++;
}
/* We're all done... */
}
and start_kernel -> sock_init -> proto_init
2. definition of sockaddr
struct sockaddr {
unsigned short sa_family; /* address family, AF_xxx */
char sa_data[14]; /* 14 bytes of protocol address */
};
3. __asm__ and __volatile__ 内嵌汇编用法
例如: # define barrier() _asm__volatile_("": : :"memory")
refer to : http://www.dzsc.com/data/html/2009-5-31/76505.html
4. the struct of socket is below,
/*
* Internal representation of a socket. not all the fields are used by
* all configurations:
*
* server client
* conn client connected to server connected to
* iconn list of clients -unused-
* awaiting connections
* wait sleep for clients, sleep for connection,
* sleep for i/o sleep for i/o
*/
struct socket {
short type; /* SOCK_STREAM, ... */
socket_state state;
long flags;
struct proto_ops *ops; /* protocols do most everything */
void *data; /* protocol data */
struct socket *conn; /* server socket connected to */
struct socket *iconn; /* incomplete client conn.s */
struct socket *next;
struct wait_queue **wait; /* ptr to place to wait on */
struct inode *inode;
struct fasync_struct *fasync_list; /* Asynchronous wake up list */
};
when creating a new socket using function sock_socket(), it will call sock_alloc() and get_fd(), return the file descriptor.
5. sys_socketcall 是所有sock_*函数的入口。
6. socket.c 文件中定义的函数作为BSD 层的函数集,对于INET 正常网络操作而言,其下层即对应inet/af_inet.c 文件中定义的函数。从对af_inet.c 文件的分析来看,其中定义的函数实际上也没有进行具体功能的实现,而是将请求继续传递给下一层(此时即传输层)。
reference: LINUX-2.4.0内核网络栈实现源代码分析