linux nettlink套接字

用於處理用戶空間和內核空間的通信機制

套接字地址結構函數:

struct sockaddr_nl

{

_kernel_sa_family_t           nl_family;    /af_netlink/

unsigned short                         nl_pad ;   

_u32                                  nl_pid;

_u32                                  nl_groups;                               /組播組掩碼/

};


nl_family:始終爲af_netlink

pad爲0

pid值內核爲0,在用戶棧根據情況自動設置。


netlink消息報頭。由結構nlmsghdr定義,長16字節。

nlmsg_len:

nlmsg_type:其中有四種基本netlik消息類型,noop,error,done,overrun。

nlmsg_flags;

nlmsg_seq;

nlmsg_pid;

屬性頭由nlattr定義

struct nlattr{

_u16 nla_len;

_u16 nla_type;};

nla_len;

nla_type:


通用netlink內核套接字由方法net_kernel_creat *net()創建,結構

static  int_net_init genl_pernet_init(struct net *net){

struct netlink_kernel_cfg cfg = {

input =genl_rcv,

cb_mutex =&genl_mutex,

flags =nl_cfg_f_nonroot_recv,

};

net->genl_sock =netlink_kernel_creatr(net,netlink_generic,&cfg);

}

創建通用netlink內核套接字自後,需要註冊控制器簇(genl_ctrl)

static struct genl_family genl_ctrl={

id =genl_id_ctrl,

name="nlctrl"

cersion =0x2,

maxattr = ctrl_attr_max,

netnsok = true,}

創建和發送通用netlink消息,消息報頭

struct genlmsghdr{

——u8 cmd;

——u8 version;

——u16 reserved;}


套接字監視接口

netlink_sock_diag

結構函數如下

索引協議號

sock_diag_handler

struct sock_diag_handler{

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章