122 lines
2.6 KiB
C
122 lines
2.6 KiB
C
|
#include <linux/module.h>
|
||
|
#include <linux/netlink.h>
|
||
|
#include <linux/netfilter.h>
|
||
|
#include <linux/ip.h>
|
||
|
#include <uapi/linux/netfilter_ipv4.h>
|
||
|
#include <uapi/linux/ip.h>
|
||
|
#include <net/netlink.h>
|
||
|
#include <net/net_namespace.h>
|
||
|
|
||
|
#include "../netlink_api/libnetlink_k.h"
|
||
|
#include "../../../Common/commuapinl.h"
|
||
|
|
||
|
|
||
|
|
||
|
struct netlinkk_cfg g_upmnlcfg;
|
||
|
|
||
|
|
||
|
#if 0
|
||
|
int nl_upm_data_ready(struct sk_buff *skb, struct nlmsghdr *nlh)
|
||
|
{
|
||
|
void *payload;
|
||
|
struct sk_buff *out_skb;
|
||
|
void *out_payload;
|
||
|
struct nlmsghdr *out_nlh;
|
||
|
int payload_len; // with padding, but ok for echo
|
||
|
|
||
|
printk(KERN_DEBUG "nl_upm_data_ready() begin.\n");
|
||
|
|
||
|
switch(nlh->nlmsg_type)
|
||
|
{
|
||
|
case COMMNMSG_POLICYCONF:/**/
|
||
|
|
||
|
payload = nlmsg_data(nlh);
|
||
|
payload_len = nlmsg_len(nlh);
|
||
|
printk(KERN_INFO "Recievid: %s, From: %d\n", (char *)payload, nlh->nlmsg_pid);
|
||
|
|
||
|
out_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); //分配足以存放默认大小的sk_buff
|
||
|
if (!out_skb) goto failure;
|
||
|
|
||
|
out_nlh = nlmsg_put(out_skb, 0, 0, COMMNMSG_POLICYCONF, payload_len, 0); //填充协议头数据
|
||
|
if (!out_nlh) goto failure;
|
||
|
|
||
|
//out_payload = nlmsg_data(out_nlh);
|
||
|
//nla_put_u32(out_skb,PDELIVERY_DUMP_PKTNUM_ATTR,g_nlcfg->pkt_delev_num);
|
||
|
|
||
|
commnl_unicast(g_upmnlcfg.sk, out_skb, nlh->nlmsg_pid);
|
||
|
break;
|
||
|
|
||
|
default:
|
||
|
printk(KERN_INFO "libnetlink Unknow msgtype recieved!\n");
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
printk(KERN_DEBUG "nl_upm_data_ready() end.\n");
|
||
|
|
||
|
return 0;
|
||
|
failure:
|
||
|
printk(KERN_INFO " failed in fun dataready!\n");
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
int upm_rcv_policycfg(struct sk_buff *skb, struct nlmsghdr *nlh)
|
||
|
{
|
||
|
printk(KERN_INFO "upm_rcv_policycfg, From pid: %d\n", nlh->nlmsg_pid);
|
||
|
|
||
|
//printk_mem((unsigned char*)nlh,nlh->nlmsg_len);
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
|
||
|
int __init upm_init(void)
|
||
|
{
|
||
|
int ret = -1;
|
||
|
|
||
|
printk(KERN_CRIT "nl_upm initialed ok!\n");
|
||
|
|
||
|
/*init for pdelivery module*/
|
||
|
g_upmnlcfg.groups = 0;
|
||
|
g_upmnlcfg.subscriptions = NETLINK_COMMCFG;/*创建配置处理通道*/
|
||
|
ret = libnetlinkk_init_byproto(&g_upmnlcfg);
|
||
|
if(ret < 0)
|
||
|
{
|
||
|
printk (KERN_CRIT "upm_init netlink init fail!.\n");
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
/*do msg process register*/
|
||
|
cfg_msgtype_register(COMMNMSG_POLICYCONF,upm_rcv_policycfg,NULL,NULL);
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
void __exit upm_exit(void)
|
||
|
{
|
||
|
printk(KERN_CRIT "nl_upm existing...\n");
|
||
|
libnetlinkk_exit(&g_upmnlcfg);
|
||
|
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
|
||
|
module_init(upm_init);
|
||
|
module_exit(upm_exit);
|
||
|
|
||
|
MODULE_LICENSE("GPL");
|
||
|
MODULE_DESCRIPTION("a simple example for upm(user policy manage) netlink protocal family");
|
||
|
MODULE_AUTHOR("RSLjdkt");
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|