netfilter
firewalling, NAT, and packet mangling for linux
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Management
Collaboration diagram for Management:

Modules

 Controller
 

Data Structures

struct  genl_cmd
 Generic Netlink Command. More...
 
struct  genl_ops
 Generic Netlink Operations. More...
 

Functions

char * genl_op2name (int family, int op, char *buf, size_t len)
 

Register/Unregister

int genl_register (struct nl_cache_ops *ops)
 Register generic netlink operations. More...
 
void genl_unregister (struct nl_cache_ops *ops)
 Unregister generic netlink operations. More...
 

Resolving ID/Name

int genl_ops_resolve (struct nl_sock *sk, struct genl_ops *ops)
 
int genl_mngt_resolve (struct nl_sock *sk)
 

Detailed Description

1) Registering a generic netlink module
// First step is to define all the commands being used in
// particular generic netlink family. The ID and name are
// mandatory to be filled out. A callback function and
// most the attribute policy that comes with it must be
// defined for commands expected to be issued towards
// userspace.
static struct genl_cmd foo_cmds[] = {
{
.c_id = FOO_CMD_NEW,
.c_name = "NEWFOO" ,
.c_maxattr = FOO_ATTR_MAX,
.c_attr_policy = foo_policy,
.c_msg_parser = foo_msg_parser,
},
{
.c_id = FOO_CMD_DEL,
.c_name = "DELFOO" ,
},
};
// The list of commands must then be integrated into a
// struct genl_ops serving as handle for this particular
// family.
static struct genl_ops my_genl_ops = {
.o_cmds = foo_cmds,
.o_ncmds = ARRAY_SIZE(foo_cmds),
};
// Using the above struct genl_ops an arbitary number of
// cache handles can be associated to it.
//
// The macro GENL_HDRSIZE() must be used to specify the
// length of the header to automatically take headers on
// generic layers into account.
//
// The macro GENL_FAMILY() is used to represent the generic
// netlink family id.
static struct nl_cache_ops genl_foo_ops = {
.co_name = "genl/foo",
.co_hdrsize = GENL_HDRSIZE(sizeof(struct my_hdr)),
.co_msgtypes = GENL_FAMILY(GENL_ID_GENERATE, "foo"),
.co_genl = &my_genl_ops,
.co_protocol = NETLINK_GENERIC,
.co_request_update = foo_request_update,
.co_obj_ops = &genl_foo_ops,
};
// Finally each cache handle for a generic netlink family
// must be registered using genl_register().
static void __init foo_init(void)
{
genl_register(&genl_foo_ops);
}
// ... respectively unregsted again.
static void __exit foo_exit(void)
{
genl_unregister(&genl_foo_ops);
}

Function Documentation

int genl_mngt_resolve ( struct nl_sock sk)

References genl_ctrl_alloc_cache(), nl_cache_free(), nl_list_for_each_entry, and genl_ops::o_list.

Here is the call graph for this function:

char* genl_op2name ( int  family,
int  op,
char *  buf,
size_t  len 
)
int genl_ops_resolve ( struct nl_sock sk,
struct genl_ops ops 
)

References genl_ctrl_alloc_cache(), and nl_cache_free().

Here is the call graph for this function:

void genl_unregister ( struct nl_cache_ops ops)

Unregister generic netlink operations.

  • ops cache operations

References nl_cache_ops::co_genl, nl_cache_mngt_unregister(), and genl_ops::o_list.

Here is the call graph for this function: