MOD aaa-12 netlink通道内核模块添加打印开关(默认关闭)
SOL 修改人:gechangwei 检视人:gechangwei Signed-off-by: gechangwei <gechangwei@cmhi.chinamobile.com>
This commit is contained in:
parent
4a15ae5dd2
commit
0a1d170e7a
|
@ -42,12 +42,16 @@ enum pdeliverynetlink_groups {
|
||||||
|
|
||||||
#define COMMLIBNLGRP_MAX 16 /*支持的最大组数量*/
|
#define COMMLIBNLGRP_MAX 16 /*支持的最大组数量*/
|
||||||
|
|
||||||
|
#define DEBUGFS_PRK_ONOFF 0
|
||||||
|
|
||||||
/*netlink pdelivery msg type*/
|
/*netlink pdelivery msg type*/
|
||||||
enum pdelivmsgtype{
|
enum pdelivmsgtype{
|
||||||
PDNL_BASE = 0x10,/*netlink 保留控制消息*/
|
PDNL_BASE = 0x10,/*netlink 保留控制消息*/
|
||||||
NLMSG_PDELIV_DEBUGFS = 0x11, /*用户态发送给内核态的请求消息,用于查看pdiliv模块本身的状态及配置,与业务无关*/
|
NLMSG_PDELIV_DEBUGFS = 0x11, /*用户态发送给内核态的请求消息,用于查看pdiliv模块本身的状态及配置,与业务无关*/
|
||||||
NLMSG_RECV_RAW_PKT = 0x12,/*上送DPI的报文消息*/
|
NLMSG_RECV_RAW_PKT = 0x12,/*上送DPI的报文消息*/
|
||||||
PDNLGRP_REQUEST,
|
PDNLGRP_REQUEST,
|
||||||
|
NK_DEBUGFS_PRK_ONOFF = 0X16,/*DEBUGFS PRINTK ON 0R OFF: 1->ON; 0->OFF */
|
||||||
|
|
||||||
/*for trace*/
|
/*for trace*/
|
||||||
TRACE_CFG_POLICY_REQ = 0x20,
|
TRACE_CFG_POLICY_REQ = 0x20,
|
||||||
TRACE_CFG_POLICY_REPLY,
|
TRACE_CFG_POLICY_REPLY,
|
||||||
|
@ -82,6 +86,8 @@ enum commcfgmsgtype{
|
||||||
COMMNMSG_CFG_DEBUGFS = 0x11,/*keep the same with NLMSG_PDELIV_DEBUGFS */
|
COMMNMSG_CFG_DEBUGFS = 0x11,/*keep the same with NLMSG_PDELIV_DEBUGFS */
|
||||||
COMMNMSG_POLICYCONF,
|
COMMNMSG_POLICYCONF,
|
||||||
|
|
||||||
|
NK_DEBUGFS_PRK_ONOFF_CFG = 0X16,/*keep the same with DEBUGFS PRINTK ON OR OFF */
|
||||||
|
|
||||||
/*add your msg type here:*/
|
/*add your msg type here:*/
|
||||||
|
|
||||||
/*commcfg nsmsg max type,must :add your msg type before this */
|
/*commcfg nsmsg max type,must :add your msg type before this */
|
||||||
|
|
|
@ -158,8 +158,8 @@ int cfgrcv_debugfs(struct sk_buff *skb, struct nlmsghdr *nlh,struct netlink_ext_
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
printk(KERN_INFO "cfgrcv_debugfs, From pid: %d\n", nlh->nlmsg_pid);
|
NETLINK_DEBUG(g_upmnlcfg.debugfs_prk_enable, "cfgrcv_debugfs, From pid: %d\n", nlh->nlmsg_pid);
|
||||||
|
/*
|
||||||
#ifdef NLDEBUG_ACK_COOKIES
|
#ifdef NLDEBUG_ACK_COOKIES
|
||||||
ret = debugfs_pkt_num_stati(&g_upmnlcfg, nlh,extack);
|
ret = debugfs_pkt_num_stati(&g_upmnlcfg, nlh,extack);
|
||||||
#else
|
#else
|
||||||
|
@ -168,7 +168,34 @@ int cfgrcv_debugfs(struct sk_buff *skb, struct nlmsghdr *nlh,struct netlink_ext_
|
||||||
|
|
||||||
printk("*****************biduichengong***************\n");
|
printk("*****************biduichengong***************\n");
|
||||||
return ret;
|
return ret;
|
||||||
|
*/
|
||||||
|
switch(nlh->nlmsg_type)
|
||||||
|
{
|
||||||
|
//case COMMNMSG_POLICYCONF:/**/
|
||||||
|
case NLMSG_PDELIV_DEBUGFS:
|
||||||
|
|
||||||
|
#ifdef NLDEBUG_ACK_COOKIES
|
||||||
|
ret = debugfs_pkt_num_stati(&g_upmnlcfg, nlh,extack);
|
||||||
|
#else
|
||||||
|
ret = debugfs_pkt_num_stati_witisend(&g_upmnlcfg, nlh,cfgnl_msg_handlers);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
NETLINK_DEBUG(g_upmnlcfg.debugfs_prk_enable, "*****************biduichengong********%d*******\n", nlh->nlmsg_type);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
break;
|
||||||
|
case NK_DEBUGFS_PRK_ONOFF:
|
||||||
|
ret = debugfs_prk_onoff(&g_upmnlcfg, nlh, extack);
|
||||||
|
return ret;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
NETLINK_DEBUG(g_upmnlcfg.debugfs_prk_enable, "libnetlink Unknow msgtype recieved!\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/**************************************************************************************************************/
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cfg_msgtype_register( int msgtype,commnl_doit_func doit,
|
int cfg_msgtype_register( int msgtype,commnl_doit_func doit,
|
||||||
|
@ -226,6 +253,7 @@ int __init cfgrcv_init(void)
|
||||||
|
|
||||||
/*do msg process register*/
|
/*do msg process register*/
|
||||||
ret = cfg_msgtype_register(COMMNMSG_CFG_DEBUGFS,cfgrcv_debugfs,NULL,NULL);
|
ret = cfg_msgtype_register(COMMNMSG_CFG_DEBUGFS,cfgrcv_debugfs,NULL,NULL);
|
||||||
|
ret = cfg_msgtype_register(NK_DEBUGFS_PRK_ONOFF,cfgrcv_debugfs,NULL,NULL);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -148,19 +148,29 @@ int commnl_unicast(struct sock *sk, struct sk_buff *skb, u32 portid)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int debugfs_prk_onoff(struct netlinkk_cfg *g_nlcfg, struct nlmsghdr *nlh,struct netlink_ext_ack *extack)
|
||||||
int debugfs_pkt_num_stati(struct netlinkk_cfg *g_nlcfg, struct nlmsghdr *nlh,struct netlink_ext_ack *extack)
|
|
||||||
{
|
{
|
||||||
unsigned char * cookies = "test cookies";
|
unsigned char * cookies = "test cookies";
|
||||||
int len = 0;
|
int len = 0;
|
||||||
|
|
||||||
printk("debugfs_pkt_num_stati.\r\n");
|
char *pload;
|
||||||
|
struct nlattr *rta;
|
||||||
|
char* load;
|
||||||
|
unsigned long fk_type;
|
||||||
|
|
||||||
|
pload = nlmsg_data(nlh);
|
||||||
|
rta = (struct nlattr *)pload;
|
||||||
|
load = RTA_DATA(rta);
|
||||||
|
strict_strtoul(load, 10, &fk_type);
|
||||||
|
g_nlcfg->debugfs_prk_enable = fk_type;
|
||||||
|
|
||||||
|
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, "***gift***%s", __func__);
|
||||||
|
|
||||||
len = strlen(cookies);
|
len = strlen(cookies);
|
||||||
|
|
||||||
if(len > sizeof(extack->cookie) )/*check len*/
|
if(len > sizeof(extack->cookie) )/*check len*/
|
||||||
{
|
{
|
||||||
printk("debugfs_pkt_num_stati:cookies oversize the netlinkt cookies.\r\n");
|
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, "debugfs_pkt_num_stati:cookies oversize the netlinkt cookies.\r\n");
|
||||||
extack->cookie_len = sizeof(extack->cookie);
|
extack->cookie_len = sizeof(extack->cookie);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -170,7 +180,35 @@ int debugfs_pkt_num_stati(struct netlinkk_cfg *g_nlcfg, struct nlmsghdr *nlh,str
|
||||||
|
|
||||||
memcpy(extack->cookie, cookies, extack->cookie_len);/*becare:size must small than 20 u8!!!!!!!!!!*/
|
memcpy(extack->cookie, cookies, extack->cookie_len);/*becare:size must small than 20 u8!!!!!!!!!!*/
|
||||||
|
|
||||||
printk("------------------debugfs_pkt_num_stati ack type=%d,seq=%d,extack->cookie_len=%d.\n",
|
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, "-debugfs_pkt_num_stati ack type=%d,seq=%d,extack->cookie_len=%d.\n",
|
||||||
|
nlh->nlmsg_type,nlh->nlmsg_seq,extack->cookie_len);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int debugfs_pkt_num_stati(struct netlinkk_cfg *g_nlcfg, struct nlmsghdr *nlh,struct netlink_ext_ack *extack)
|
||||||
|
{
|
||||||
|
unsigned char * cookies = "test cookies";
|
||||||
|
int len = 0;
|
||||||
|
|
||||||
|
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, "debugfs_pkt_num_stati.\r\n");
|
||||||
|
|
||||||
|
len = strlen(cookies);
|
||||||
|
|
||||||
|
if(len > sizeof(extack->cookie) )/*check len*/
|
||||||
|
{
|
||||||
|
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, "debugfs_pkt_num_stati:cookies oversize the netlinkt cookies.\r\n");
|
||||||
|
extack->cookie_len = sizeof(extack->cookie);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
extack->cookie_len = len;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(extack->cookie, cookies, extack->cookie_len);/*becare:size must small than 20 u8!!!!!!!!!!*/
|
||||||
|
|
||||||
|
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, "-debugfs_pkt_num_stati ack type=%d,seq=%d,extack->cookie_len=%d.\n",
|
||||||
nlh->nlmsg_type,nlh->nlmsg_seq,extack->cookie_len);
|
nlh->nlmsg_type,nlh->nlmsg_seq,extack->cookie_len);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -193,10 +231,10 @@ int debugfs_pkt_num_stati_witisend(struct netlinkk_cfg *g_nlcfg,
|
||||||
rta = (struct nlattr *)pload;
|
rta = (struct nlattr *)pload;
|
||||||
load = RTA_DATA(rta);
|
load = RTA_DATA(rta);
|
||||||
|
|
||||||
printk("***************************rta->nla_type=%d********************\n", rta->nla_type); //nla_type
|
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, "*******rta->nla_type=%d*********\n", rta->nla_type); //nla_type
|
||||||
printk("**************************load=*****%s**********\n",(char *)load); //string printf
|
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, "*******load=*****%s**********\n",(char *)load); //string printf
|
||||||
strict_strtoul(load, 10, &fk_type);
|
strict_strtoul(load, 10, &fk_type);
|
||||||
printk("***************************fk_type%lu********************\n", fk_type);
|
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, "*******fk_type%lu********************\n", fk_type);
|
||||||
|
|
||||||
|
|
||||||
out_skb = nlmsg_new(2*length, GFP_KERNEL);
|
out_skb = nlmsg_new(2*length, GFP_KERNEL);
|
||||||
|
@ -214,27 +252,27 @@ int debugfs_pkt_num_stati_witisend(struct netlinkk_cfg *g_nlcfg,
|
||||||
memcpy(nlmsg_data(out_nlh)+length, tmp_dfs, length);
|
memcpy(nlmsg_data(out_nlh)+length, tmp_dfs, length);
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
printk("netlink total msg stats:\r\n");
|
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, " netlink total msg stats:\r\n");
|
||||||
printk(" rev_total = %d\n",g_nlcfg->dfs.rev_total);
|
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, " rev_total = %d\n",g_nlcfg->dfs.rev_total);
|
||||||
printk(" rev_cb_sucess = %d\n",g_nlcfg->dfs.rev_cb_sucess);
|
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, " rev_cb_sucess = %d\n",g_nlcfg->dfs.rev_cb_sucess);
|
||||||
printk(" rev_cb_fail = %d\n",g_nlcfg->dfs.rev_cb_fail);
|
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, " rev_cb_fail = %d\n",g_nlcfg->dfs.rev_cb_fail);
|
||||||
printk(" rev_drop_total = %d\n",g_nlcfg->dfs.rev_drop_total);
|
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, " rev_drop_total = %d\n",g_nlcfg->dfs.rev_drop_total);
|
||||||
printk(" rev_drop_nodoit = %d\n",g_nlcfg->dfs.rev_drop_nodoit);
|
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, " rev_drop_nodoit = %d\n",g_nlcfg->dfs.rev_drop_nodoit);
|
||||||
printk(" send_succ = %d\n",g_nlcfg->dfs.send_succ);
|
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, " send_succ = %d\n",g_nlcfg->dfs.send_succ);
|
||||||
printk(" send_fail = %d\n",g_nlcfg->dfs.send_fail);
|
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, " send_fail = %d\n",g_nlcfg->dfs.send_fail);
|
||||||
|
|
||||||
printk("netlink msg stats:\r\n");
|
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, " netlink msg stats:\r\n");
|
||||||
printk(" rev_total = %d\n",tmp_dfs->rev_total);
|
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, " rev_total = %d\n",tmp_dfs->rev_total);
|
||||||
printk(" rev_cb_sucess = %d\n",tmp_dfs->rev_cb_sucess);
|
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, " rev_cb_sucess = %d\n",tmp_dfs->rev_cb_sucess);
|
||||||
printk(" rev_cb_fail = %d\n",tmp_dfs->rev_cb_fail);
|
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, " rev_cb_fail = %d\n",tmp_dfs->rev_cb_fail);
|
||||||
printk(" rev_drop_total = %d\n",tmp_dfs->rev_drop_total);
|
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, " rev_drop_total = %d\n",tmp_dfs->rev_drop_total);
|
||||||
printk(" rev_drop_nodoit = %d\n",tmp_dfs->rev_drop_nodoit);
|
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, " rev_drop_nodoit = %d\n",tmp_dfs->rev_drop_nodoit);
|
||||||
printk(" send_succ = %d\n",tmp_dfs->send_succ);
|
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, " send_succ = %d\n",tmp_dfs->send_succ);
|
||||||
printk(" send_fail = %d\n",tmp_dfs->send_fail);
|
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, " send_fail = %d\n",tmp_dfs->send_fail);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
printk("------------------debugfs_pkt_num_stati ack msg_type %d,seq=%d!\n",out_nlh->nlmsg_type,nlh->nlmsg_seq);
|
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, "------------------debugfs_pkt_num_stati ack msg_type %d,seq=%d!\n",out_nlh->nlmsg_type,nlh->nlmsg_seq);
|
||||||
err = commnl_unicast(g_nlcfg->sk, out_skb, nlh->nlmsg_pid);
|
err = commnl_unicast(g_nlcfg->sk, out_skb, nlh->nlmsg_pid);
|
||||||
if (err > 0)
|
if (err > 0)
|
||||||
{
|
{
|
||||||
|
@ -252,7 +290,7 @@ failure:
|
||||||
//kfree_skb(out_skb);
|
//kfree_skb(out_skb);
|
||||||
}
|
}
|
||||||
|
|
||||||
printk(KERN_INFO " failed in fun dataready!\n");
|
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, " failed in fun dataready!\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,6 +322,7 @@ EXPORT_SYMBOL_GPL(printk_ipaddress);
|
||||||
EXPORT_SYMBOL_GPL(debugfs_pkt_num_stati);
|
EXPORT_SYMBOL_GPL(debugfs_pkt_num_stati);
|
||||||
EXPORT_SYMBOL_GPL(debugfs_pkt_num_stati_witisend);
|
EXPORT_SYMBOL_GPL(debugfs_pkt_num_stati_witisend);
|
||||||
EXPORT_SYMBOL_GPL(nf_nlmsg_multicast);
|
EXPORT_SYMBOL_GPL(nf_nlmsg_multicast);
|
||||||
|
EXPORT_SYMBOL_GPL(debugfs_prk_onoff);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,9 @@
|
||||||
#include <net/net_namespace.h>
|
#include <net/net_namespace.h>
|
||||||
#include "../../../Common/commuapinl.h"
|
#include "../../../Common/commuapinl.h"
|
||||||
|
|
||||||
|
#define NETLINK_DEBUG(debugfs_enable, ...) \
|
||||||
|
if(DEBUGFS_PRK_ONOFF != debugfs_enable) printk(__VA_ARGS__)
|
||||||
|
|
||||||
|
|
||||||
struct netlinkk_cfg
|
struct netlinkk_cfg
|
||||||
{
|
{
|
||||||
|
@ -23,6 +26,7 @@ struct netlinkk_cfg
|
||||||
struct netlink_debugfs dfs;
|
struct netlink_debugfs dfs;
|
||||||
struct commnl_msgtype_process* msg_processer;
|
struct commnl_msgtype_process* msg_processer;
|
||||||
int msg_processer_num;
|
int msg_processer_num;
|
||||||
|
unsigned long debugfs_prk_enable;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef int (*commnl_doit_func)(struct sk_buff *, struct nlmsghdr *,struct netlink_ext_ack *);
|
typedef int (*commnl_doit_func)(struct sk_buff *, struct nlmsghdr *,struct netlink_ext_ack *);
|
||||||
|
@ -83,5 +87,8 @@ extern int debugfs_pkt_num_stati_witisend(struct netlinkk_cfg *g_nlcfg,
|
||||||
|
|
||||||
extern int nf_nlmsg_multicast(struct netlinkk_cfg *g_nlcfg, struct sk_buff *skb);
|
extern int nf_nlmsg_multicast(struct netlinkk_cfg *g_nlcfg, struct sk_buff *skb);
|
||||||
|
|
||||||
|
extern int debugfs_prk_onoff(struct netlinkk_cfg *g_nlcfg,
|
||||||
|
struct nlmsghdr *nlh,struct netlink_ext_ack *extack);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -49,12 +49,16 @@ int pdeliv_rcv_stat(struct sk_buff *skb, struct nlmsghdr *nlh,struct netlink_ext
|
||||||
#else
|
#else
|
||||||
ret = debugfs_pkt_num_stati_witisend(&g_nlcfg, nlh,pdelivnl_msg_handlers);
|
ret = debugfs_pkt_num_stati_witisend(&g_nlcfg, nlh,pdelivnl_msg_handlers);
|
||||||
#endif
|
#endif
|
||||||
printk("*****************biduichengong********%d*******\n", nlh->nlmsg_type);
|
NETLINK_DEBUG(g_nlcfg.debugfs_prk_enable, "*****************biduichengong********%d*******\n", nlh->nlmsg_type);
|
||||||
return ret;
|
return ret;
|
||||||
break;
|
break;
|
||||||
|
case NK_DEBUGFS_PRK_ONOFF:
|
||||||
|
ret = debugfs_prk_onoff(&g_nlcfg, nlh, ext_ack);
|
||||||
|
return ret;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
printk(KERN_INFO "libnetlink Unknow msgtype recieved!\n");
|
NETLINK_DEBUG(g_nlcfg.debugfs_prk_enable, "libnetlink Unknow msgtype recieved!\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/**************************************************************************************************************/
|
/**************************************************************************************************************/
|
||||||
|
@ -66,7 +70,7 @@ int nl_pdeliv_data_ready(struct sk_buff *skb, struct nlmsghdr *nlh, struct netli
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
printk(KERN_DEBUG "nl_pdeliv_data_ready() nlmsg_type = %d begin.\n",nlh->nlmsg_type);
|
NETLINK_DEBUG(g_nlcfg.debugfs_prk_enable, "nl_pdeliv_data_ready() nlmsg_type = %d begin.\n",nlh->nlmsg_type);
|
||||||
g_nlcfg.dfs.rev_total++;
|
g_nlcfg.dfs.rev_total++;
|
||||||
|
|
||||||
if(NULL != pdelivnl_msg_handlers[nlh->nlmsg_type].doit)
|
if(NULL != pdelivnl_msg_handlers[nlh->nlmsg_type].doit)
|
||||||
|
@ -92,10 +96,10 @@ int nl_pdeliv_data_ready(struct sk_buff *skb, struct nlmsghdr *nlh, struct netli
|
||||||
g_nlcfg.dfs.rev_drop_total++;
|
g_nlcfg.dfs.rev_drop_total++;
|
||||||
g_nlcfg.dfs.rev_drop_nodoit++;
|
g_nlcfg.dfs.rev_drop_nodoit++;
|
||||||
|
|
||||||
printk(KERN_WARNING "no doit fun register with nlmsg_type = %d .\n",nlh->nlmsg_type);
|
NETLINK_DEBUG(g_nlcfg.debugfs_prk_enable, "no doit fun register with nlmsg_type = %d .\n",nlh->nlmsg_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
printk(KERN_DEBUG "nl_pdeliv_data_ready() nlmsg_type = %d end.\n",nlh->nlmsg_type);
|
NETLINK_DEBUG(g_nlcfg.debugfs_prk_enable, "nl_pdeliv_data_ready() nlmsg_type = %d end.\n",nlh->nlmsg_type);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -103,7 +107,7 @@ int nl_pdeliv_data_ready(struct sk_buff *skb, struct nlmsghdr *nlh, struct netli
|
||||||
|
|
||||||
static void libpdelivnl_rcv(struct sk_buff *skb)
|
static void libpdelivnl_rcv(struct sk_buff *skb)
|
||||||
{
|
{
|
||||||
printk(KERN_DEBUG "libpdelivnl_rcv:\n");
|
NETLINK_DEBUG(g_nlcfg.debugfs_prk_enable, "libpdelivnl_rcv:\n");
|
||||||
|
|
||||||
netlink_rcv_skb(skb, &nl_pdeliv_data_ready);
|
netlink_rcv_skb(skb, &nl_pdeliv_data_ready);
|
||||||
|
|
||||||
|
@ -169,6 +173,8 @@ int __init pdelivery_init(void)
|
||||||
/*do msg process register*/
|
/*do msg process register*/
|
||||||
pdeliv_msgtype_register(PDNLGRP_REQUEST,pdeliv_rcv_stat,NULL,NULL);
|
pdeliv_msgtype_register(PDNLGRP_REQUEST,pdeliv_rcv_stat,NULL,NULL);
|
||||||
pdeliv_msgtype_register(NLMSG_PDELIV_DEBUGFS,pdeliv_rcv_stat,NULL,NULL);
|
pdeliv_msgtype_register(NLMSG_PDELIV_DEBUGFS,pdeliv_rcv_stat,NULL,NULL);
|
||||||
|
pdeliv_msgtype_register(NK_DEBUGFS_PRK_ONOFF,pdeliv_rcv_stat,NULL,NULL);
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,44 +0,0 @@
|
||||||
######################################
|
|
||||||
#
|
|
||||||
######################################
|
|
||||||
#source file
|
|
||||||
#源文件,自动找所有.c和.cpp文件,并将目标定义为同名.o文件
|
|
||||||
SOURCE := $(wildcard *.c) $(wildcard *.cpp)
|
|
||||||
OBJS := $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCE)))
|
|
||||||
|
|
||||||
#target you can change test to what you want
|
|
||||||
#目标文件名,输入任意你想要的执行文件名
|
|
||||||
TARGET := cfgchannel_test_sample
|
|
||||||
|
|
||||||
#compile and lib parameter
|
|
||||||
#编译参数
|
|
||||||
CC := gcc
|
|
||||||
LIBS := -L../netlink_uapi -lnetlinku
|
|
||||||
LDFLAGS :=
|
|
||||||
DEFINES :=
|
|
||||||
INCLUDE := -I../lib -I../../../Common -I../netlink_uapi
|
|
||||||
CFLAGS := -g -Wall -O3 $(DEFINES) $(INCLUDE)
|
|
||||||
CXXFLAGS:= $(CFLAGS) -DHAVE_CONFIG_H
|
|
||||||
|
|
||||||
|
|
||||||
#i think you should do anything here
|
|
||||||
#下面的基本上不需要做任何改动了
|
|
||||||
.PHONY : everything objs clean veryclean rebuild
|
|
||||||
|
|
||||||
everything : $(TARGET)
|
|
||||||
|
|
||||||
all : $(TARGET)
|
|
||||||
|
|
||||||
objs : $(OBJS)
|
|
||||||
|
|
||||||
rebuild: veryclean everything
|
|
||||||
|
|
||||||
clean :
|
|
||||||
rm -fr *.so
|
|
||||||
rm -fr *.o
|
|
||||||
|
|
||||||
veryclean : clean
|
|
||||||
rm -fr $(TARGET)
|
|
||||||
|
|
||||||
$(TARGET) : $(OBJS)
|
|
||||||
$(CC) $(CXXFLAGS) -o $@ $(OBJS) $(LDFLAGS) $(LIBS)
|
|
|
@ -1,141 +0,0 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <linux/types.h>
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
#include "libnetlinku.h"
|
|
||||||
#include "policyconf.h"
|
|
||||||
#include "commuapinl.h"
|
|
||||||
|
|
||||||
struct upmnl_handle cfgnlh;
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
static int process_msg(struct pdelivnl_ctrl_data *ctrl,
|
|
||||||
struct nlmsghdr *n, void *arg)
|
|
||||||
{
|
|
||||||
// FILE *fp = arg;
|
|
||||||
|
|
||||||
printf("pdelivery main process_msg begin:\r\n");
|
|
||||||
|
|
||||||
|
|
||||||
//if (timestamp)
|
|
||||||
//print_timestamp(fp);
|
|
||||||
|
|
||||||
switch (n->nlmsg_type) {
|
|
||||||
case NLMSG_RECV_RAW_PKT:
|
|
||||||
printf("netlink msg type RAW_pkt:\r\n");
|
|
||||||
printf_pkt(NLMSG_DATA(n),n->nlmsg_len-NLMSG_HDRLEN);
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int set_user_policy_waitack()
|
|
||||||
{
|
|
||||||
unsigned char srcip[64]={"192.168.1.1"};/*需要发送的数据*/
|
|
||||||
int srcip_len = strlen((const char *)srcip);
|
|
||||||
|
|
||||||
struct {
|
|
||||||
struct nlmsghdr n;
|
|
||||||
struct policyconfmsg ncm;
|
|
||||||
char buf[1024];
|
|
||||||
} req = {
|
|
||||||
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct policyconfmsg)),
|
|
||||||
.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK,
|
|
||||||
//.n.nlmsg_type = COMMNMSG_POLICYCONF,
|
|
||||||
.n.nlmsg_type = COMMNMSG_DEBUGFS,
|
|
||||||
.ncm.policy_id = 17,
|
|
||||||
.n.nlmsg_pid = getpid(),
|
|
||||||
};
|
|
||||||
|
|
||||||
printf("set_user_policy_waitack\r\n");
|
|
||||||
|
|
||||||
/*可选属性*/
|
|
||||||
commnl_addattr_l(&req.n, sizeof(req), POLICYCONFA_SRCIP, srcip, srcip_len);
|
|
||||||
|
|
||||||
printf("srcip_len =%d.req.n.nlmsg_type =%d\r\n",srcip_len,req.n.nlmsg_type);
|
|
||||||
|
|
||||||
|
|
||||||
/*发送组装好的netlink消息*/
|
|
||||||
if (commcfg_talk(&req.n, NULL) < 0)
|
|
||||||
return -2;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int set_user_policy_nowaitack()
|
|
||||||
{
|
|
||||||
unsigned char srcip[64]={"192.168.1.1"};/*需要发送的数据*/
|
|
||||||
int srcip_len = strlen((const char *)srcip);
|
|
||||||
|
|
||||||
struct {
|
|
||||||
struct nlmsghdr n;
|
|
||||||
struct policyconfmsg ncm;
|
|
||||||
char buf[1024];
|
|
||||||
} req = {
|
|
||||||
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct policyconfmsg)),
|
|
||||||
.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK,
|
|
||||||
.n.nlmsg_type = COMMNMSG_POLICYCONF,
|
|
||||||
.ncm.policy_id = 17,
|
|
||||||
.n.nlmsg_pid = getpid(),
|
|
||||||
};
|
|
||||||
|
|
||||||
printf("set_user_policy_nowaitack\r\n");
|
|
||||||
|
|
||||||
/*可选属性*/
|
|
||||||
commnl_addattr_l(&req.n, sizeof(req), POLICYCONFA_SRCIP, srcip, srcip_len);
|
|
||||||
|
|
||||||
printf("srcip_len =%d.req.n.nlmsg_type =%d\r\n",srcip_len,req.n.nlmsg_type);
|
|
||||||
|
|
||||||
/*发送组装好的netlink消息*/
|
|
||||||
if (commcfg_send(&req.n) < 0)
|
|
||||||
return -2;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int main( int argc, char **argv)
|
|
||||||
{
|
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
|
|
||||||
printf("cfgchannel main begin:\r\n");
|
|
||||||
|
|
||||||
/*创建通道*/
|
|
||||||
ret = commcfgnl_open();
|
|
||||||
if(ret < 0)
|
|
||||||
{
|
|
||||||
printf("pdelivnl_open fail,exit.\r\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*下发配置到内核态*/
|
|
||||||
ret = set_user_policy_nowaitack();
|
|
||||||
if(ret < 0)
|
|
||||||
{
|
|
||||||
printf("set_user_policy failed.\r\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*关闭netlink通道*/
|
|
||||||
commcfgnl_close();
|
|
||||||
|
|
||||||
printf("cfgchannel main exit!\r\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Binary file not shown.
|
@ -1,44 +0,0 @@
|
||||||
######################################
|
|
||||||
#
|
|
||||||
######################################
|
|
||||||
#source file
|
|
||||||
#源文件,自动找所有.c和.cpp文件,并将目标定义为同名.o文件
|
|
||||||
SOURCE := $(wildcard *.c) $(wildcard *.cpp)
|
|
||||||
OBJS := $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCE)))
|
|
||||||
|
|
||||||
#target you can change test to what you want
|
|
||||||
#目标文件名,输入任意你想要的执行文件名
|
|
||||||
TARGET := pdeliv_test_main
|
|
||||||
|
|
||||||
#compile and lib parameter
|
|
||||||
#编译参数
|
|
||||||
CC := gcc
|
|
||||||
LIBS := -L../netlink_uapi -lnetlinku
|
|
||||||
LDFLAGS :=
|
|
||||||
DEFINES :=
|
|
||||||
INCLUDE := -I../lib -I../../../Common -I../netlink_uapi
|
|
||||||
CFLAGS := -g -Wall -O3 $(DEFINES) $(INCLUDE)
|
|
||||||
CXXFLAGS:= $(CFLAGS) -DHAVE_CONFIG_H
|
|
||||||
|
|
||||||
|
|
||||||
#i think you should do anything here
|
|
||||||
#下面的基本上不需要做任何改动了
|
|
||||||
.PHONY : everything objs clean veryclean rebuild
|
|
||||||
|
|
||||||
everything : $(TARGET)
|
|
||||||
|
|
||||||
all : $(TARGET)
|
|
||||||
|
|
||||||
objs : $(OBJS)
|
|
||||||
|
|
||||||
rebuild: veryclean everything
|
|
||||||
|
|
||||||
clean :
|
|
||||||
rm -fr *.so
|
|
||||||
rm -fr *.o
|
|
||||||
|
|
||||||
veryclean : clean
|
|
||||||
rm -fr $(TARGET)
|
|
||||||
|
|
||||||
$(TARGET) : $(OBJS)
|
|
||||||
$(CC) $(CXXFLAGS) -o $@ $(OBJS) $(LDFLAGS) $(LIBS)
|
|
Binary file not shown.
|
@ -1,89 +0,0 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <linux/types.h>
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
#include "libnetlinku.h"
|
|
||||||
#include "policyconf.h"
|
|
||||||
#include "commuapinl.h"
|
|
||||||
|
|
||||||
struct upmnl_handle cfgnlh;
|
|
||||||
|
|
||||||
int set_user_policy()
|
|
||||||
{
|
|
||||||
unsigned char debug[]={"17"};/*需要发送的数据*/
|
|
||||||
int debug_len = strlen((const char *)debug);
|
|
||||||
|
|
||||||
struct {
|
|
||||||
struct nlmsghdr n;
|
|
||||||
struct policyconfmsg ncm;
|
|
||||||
char buf[1024];
|
|
||||||
} req = {
|
|
||||||
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct policyconfmsg)),
|
|
||||||
.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK,
|
|
||||||
.n.nlmsg_type = COMMNMSG_POLICYCONF,
|
|
||||||
.ncm.policy_id =17,
|
|
||||||
.n.nlmsg_pid = getpid(),
|
|
||||||
};
|
|
||||||
struct nlmsghdr **debugfs_nl;
|
|
||||||
struct pdeliv_debugfs *debugfs_statis;
|
|
||||||
struct nlmsghdr *recv_hdr;
|
|
||||||
|
|
||||||
/*可选属性*/
|
|
||||||
commnl_addattr_l(&req.n, sizeof(req), POLICYCONFA_SRCIP, debug, debug_len);
|
|
||||||
|
|
||||||
/*发送组装好的netlink消息*/
|
|
||||||
if (pdeliv_talk(0, &req.n, NULL) < 0)
|
|
||||||
{
|
|
||||||
return -2;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
|
|
||||||
if(recv_hdr->nlmsg_type == COMMNMSG_DEBUGFS)
|
|
||||||
{
|
|
||||||
debugfs_statis = NLMSG_DATA(recv_hdr);
|
|
||||||
printf("******debugfs_statis->pde_fail = %d******\n",debugfs_statis->pde_fail);
|
|
||||||
printf("******debugfs_statis->pde_succ = %d******\n",debugfs_statis->pde_succ);
|
|
||||||
printf("******debugfs_statis->rev_fail = %d******\n",debugfs_statis->rev_fail);
|
|
||||||
printf("******debugfs_statis->rev_succ = %d******\n",debugfs_statis->rev_succ);
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int main( int argc, char **argv)
|
|
||||||
{
|
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
printf("cfgchannel main begin:\r\n");
|
|
||||||
|
|
||||||
/*创建通道*/
|
|
||||||
ret = pdelivnl_open(0);
|
|
||||||
if(ret < 0)
|
|
||||||
{
|
|
||||||
printf("pdelivnl_open fail,exit.\r\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*下发配置到内核态*/
|
|
||||||
ret = set_user_policy();
|
|
||||||
if(ret < 0)
|
|
||||||
{
|
|
||||||
printf("set_user_policy failed.\r\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*关闭netlink通道*/
|
|
||||||
pdelivnl_close(0);
|
|
||||||
|
|
||||||
printf("cfgchannel main exit!\r\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue