Netnetlinkafnetlinkc

struct sock *

netlink_kernel_create(struct net *net, int unit, unsigned int groups, void (*input)(struct sk_buff *skb), struct mutex *cb_mutex, struct module *module);

net denotes the networking namespace, unit specifies the protocol family member, and input is a callback function that is activated when data arrives for the socket.39 If a null pointer is passed for input, the socket will only be able to transport data from kernel to userland, but not vice versa. The tasks performed in netlink_kernel_create are summarized by the code flow diagram in Figure 12-36.

netlink_kernel_create 1

sock_create_lite1

__netlink_create

Store input function

netlink_insert |

Figure 12-36: Code flow diagram for netlink_kernel_create (multicast handling is omitted).

1. All required data structures need to be allocated, especially an instance of struct socket and struct netlink_sock. sock_create_lite handles the first requirement, and allocating netlink_sock is delegated to the auxiliary function_netlink_create.

2. If an input function is specified, it is stored in netlink_sock->netlink_rcv.

3. The new sock instance is inserted into the netlink hash via netlink_insert.

Consider, for instance, how the generic object model creates a netlink socket for the uevent mechanism (refer to Section 7.4.2 on how to use this connection):

Continue reading here: Libkobjectueventc

Was this article helpful?

0 0