#define NETLINK_MDB 30
struct sock *netlink_sk = NULL;
static int receive_message(struct sk_buff *skb, struct nlmsghdr *nlh, struct netlink_ext_ack *extack)
{
int pid;
void *data = NULL;
pid = nlh->nlmsg_pid;
data = NLMSG_DATA(nlh);
if(data)
{
printk("kernel receive data: %s\n", (int8_t *)data);
}
if (nlh->nlmsg_type == RTM_NEWMDB) {
printk("Received RTM_NEWMDB message from PID %d\n", pid);
//void *data = NLMSG_DATA(nlh);
} else if (nlh->nlmsg_type == RTM_DELMDB) {
printk("Received RTM_DELMDB message from PID %d\n", pid);
//void *data = NLMSG_DATA(nlh);
/* Do something with the message */
}
return 0;
}
static void netlink_callback(struct sk_buff *skb)
{
printk("Received RTM_NEWMDB message from PID\n");
netlink_rcv_skb(skb, &receive_message);
}
static int __init my_init(void) {
struct netlink_kernel_cfg cfg = {
.input = netlink_callback,
.groups = RTNLGRP_MDB,
};
netlink_sk = netlink_kernel_create(&init_net, NETLINK_MDB, &cfg);
if (netlink_sk == NULL) {
printk("Failed to create netlink socket\n");
return -ENOMEM;
}
printk("Listening to MDB changes\n");
return 0;
}
static void __exit my_exit(void) {
netlink_kernel_release(netlink_sk);
printk("Stopped listening to MDB changes\n");
}
module_init(my_init);
module_exit(my_exit);
why can't receive the netlink message from br_mdb_notify() in kernel?I don't konw how to deal with it.It seems to be no error.Can somebody help?Thanks a lot. why can't receive the netlink message from br_mdb_notify() in kernel?I don't konw how to deal with it.It seems to be no error.Can somebody help?Thanks a lot. why can't receive the netlink message from br_mdb_notify() in kernel?I don't konw how to deal with it.It seems to be no error.Can somebody help?Thanks a lot.