The registration process of socket address family in the kernel

Source: Internet
Author: User
Take af_bluetooth as an example to sort out the registration process of socket address family in the kernel. When the Linux kernel is started, each subsystem (subsystem) is initialized. Bluetooth is one of these sub-systems, Bluetooth/af_rjth.c subsys_initcall (bt_init); subsys_initcall is a macro definition, in include/Linux/init. in H: # define subsys_initcall (FN) _ define_initcall ("4", FN, 4) # DEFINE _ define_initcall (Level, FN, ID )\

Static initcall_t _ initcall _ # FN # ID _ used \

_ Attribute _ (_ Section __(". initcall "level ". init ") = FN // The bt_initcall code is defined in. initcall. Bluetooth/af_effecth.cstatic int _ init bt_init (void) bt_sysfs_init (); // initialize the Bluetooth Virtual File System sock_register (& bt_sock_family_ops); // register the Bluetooth address protocol cluster hci_sock_init (); // initialize the Bluetooth address protocol cluster l2cap_init (); // initialize the Logical Link Control and adaptation protocol, and control sco_init () by config_bt_l2cap; // initialize the synchronous and targeted link protocol, the config_bt_sco control focuses on the implementation of the Bluetooth address protocol family. Net/socket. c int sock_register (const struct net_proto_family * OPS) rcu_assign_pointer (net_families [OPS-> family], OPS); // RCU (read-copy update ), the lock-free Assignment Method (next study) is to assign the listener value to net_families [af_bluetooth]. Next, let's look at the implementation of hci_sock_init: net/Bluetooth/hci_sock.c int _ init hci_sock_init (void ); // initialize hci_sock proto_register (& hci_sk_proto, 0); // Add hci_sk_proto (struct proto *) to the global proto_list list bt_sock_register (btproto_hci, & register ); // register the socket ops callback bt_proto [proto] = OPS; // save hci_sock_family_ops into the bt_proto array. All BT protocols are as follows: # define btproto_l2cap 0

# Define btproto_hci 1

# Define btproto_sco 2 # define btproto_rfcomm 3 # define Protocol 4 # define btproto_cmtp 5 # define btproto_hidp 6 # define Protocol 7 when the execution system calls socket (af_bluetooth, sock_raw, btproto_hci, will be called to the kernel net/socket. C _ sock_create method: net/socket. csyscall_define3 (socket, Int, family, Int, type, Int, protocol) int _ sock_create (struct net * Net, int family, int type, int protocol,
Struct socket ** res, int Kern) struct socket * sock = sock_alloc (); // construct a socket structure sock-> type = type; // sock_raw const struct net_proto_family * pF = rcu_dereference (net_families [Family]); // retrieve the af_bluetooth protocol struct PF-> Create (net, Sock, protocol, Kern ); // call the newly registered net_proto_family, that is, the create method of bt_sock_family_ops. Check that create is the bt_sock_create method af_rjth.cstatic int bt_sock_create (struct net * Net, struct socket * sock, int proto,

Int Kern) // proto = btproto_hci

Bt_proto [proto]-> Create (net, Sock, proto, Kern); // call the create method of the registered hci_sock_family_ops, that is, using int hci_sock_create (struct net * Net, struct socket * sock, int protocol,
Int Kern) sock-> Ops = & hci_sock_ops; so far, af_bluetooth registration has been completed, socket has been created, and all socket read/write operations can be located in hci_cock.c.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.