linux网络协议栈分析——套接字创建

时间:2022-06-20 01:46:56

基本流程是:

socketcall——socket——sock_create——__sock_create——sock_alloc——pf->create(inet_create)

                                              sock_map_fd

 

那么创建套接字时传递的几个参数的归宿如何:

sock->type = type;

family:

1、加载协议模块:

/* Attempt to load a protocol module if the find failed.
  *
  * 12/09/1996 Marcin: But! this makes REALLY only sense, if the user
  * requested real, full-featured networking support upon configuration.
  * Otherwise module support will break!
  */
 if (net_families[family] == NULL)
  request_module("net-pf-%d", family);

2、获得网络协议族指针:

pf = rcu_dereference(net_families[family]);

protocol:

err = pf->create(net, sock, protocol);

sk->sk_protocol    = protocol;