Mod aaa-12 描述:添加netlink两个模块pdeliv和cfg模块的调试手段,查看报文统计

RCA:
SOL:
修改人:xusaiqun
检视人:xusaiqun

Signed-off-by: xusaiqun <xusaiqun@cmhi.chinamobile.com>
This commit is contained in:
xusaiqun 2019-06-20 19:35:43 -07:00
parent d686305674
commit 3fbaf4aede
11 changed files with 372 additions and 243 deletions

View File

@ -8,6 +8,10 @@
/**********************NETLINK MODULE CONFIG:being**************************/
//#define NLDEBUG_ACK_COOKIES
/**********************NETLINK MODULE CONFIG:end****************************/
/* netlink proto*/ /* netlink proto*/
#define NETLINK_COMMMAX_MIN_FAMILY 21 #define NETLINK_COMMMAX_MIN_FAMILY 21
#define NETLINK_COMMCFG 22 #define NETLINK_COMMCFG 22
@ -41,9 +45,9 @@ enum pdeliverynetlink_groups {
/*netlink pdelivery msg type*/ /*netlink pdelivery msg type*/
enum pdelivmsgtype{ enum pdelivmsgtype{
PDNL_BASE = 0x10,/*netlink 保留控制消息*/ PDNL_BASE = 0x10,/*netlink 保留控制消息*/
PDNLGRP_REQUEST, /*用户态发送给内核态的请求消息用于查看pdiliv模块本身的状态及配置与业务无关*/ NLMSG_PDELIV_DEBUGFS = 0x11, /*用户态发送给内核态的请求消息用于查看pdiliv模块本身的状态及配置与业务无关*/
NLMSG_RECV_RAW_PKT,/*上送DPI的报文消息*/ NLMSG_RECV_RAW_PKT,/*上送DPI的报文消息*/
NLMSG_DEBUGFS, PDNLGRP_REQUEST,
NLMGS_PDELIVERY_MAX_TYPE, NLMGS_PDELIVERY_MAX_TYPE,
}; };
@ -72,9 +76,8 @@ enum pdelivattr{
enum commcfgmsgtype{ enum commcfgmsgtype{
//COMMMSGNL_BASE = NLMSG_MIN_TYPE,/*netlink 保留控制消息*/ //COMMMSGNL_BASE = NLMSG_MIN_TYPE,/*netlink 保留控制消息*/
COMMMSGNL_BASE = 0x10,/*netlink 保留控制消息*/ COMMMSGNL_BASE = 0x10,/*netlink 保留控制消息*/
COMMNMSG_CFG_DEBUGFS = 0x11,/*keep the same with NLMSG_PDELIV_DEBUGFS */
COMMNMSG_POLICYCONF, COMMNMSG_POLICYCONF,
COMMNMSG_USER,
COMMNMSG_DEBUGFS,
/*for trace*/ /*for trace*/
TRACE_CFG_POLICY = 0x20, TRACE_CFG_POLICY = 0x20,
TRACE_CFG_MAX = 0X25, TRACE_CFG_MAX = 0X25,
@ -84,9 +87,25 @@ enum commcfgmsgtype{
COMMCFG_NLMSG_MAX_TYPE, COMMCFG_NLMSG_MAX_TYPE,
}; };
#if 0
struct pdeliv_debugfs {
unsigned int rev_succ;
unsigned int rev_fail;
unsigned int pde_succ;
unsigned int pde_fail;
};
#endif
struct netlink_debugfs {
unsigned char cfg_rev_succ;
unsigned char cfg_rev_fail;
unsigned char pde_rev_succ;
unsigned char pde_rev_fail;
unsigned char pde_pkt_succ;
unsigned char pde_pkt_fail;
};
#endif /* _UAPI__LINUX_COMMNETLINK_H */ #endif /* _UAPI__LINUX_COMMNETLINK_H */

View File

@ -19,6 +19,7 @@ enum {
POLICYCONFA_DSTPORT,/* used in NLMSG_POLICYCONF*/ POLICYCONFA_DSTPORT,/* used in NLMSG_POLICYCONF*/
POLICYCONFA_PROTO, /* used in NLMSG_POLICYCONF*/ POLICYCONFA_PROTO, /* used in NLMSG_POLICYCONF*/
POLICYCONFA_ACTION,/* used in NLMSG_POLICYCONF*/ POLICYCONFA_ACTION,/* used in NLMSG_POLICYCONF*/
NLDEBUG_MSG_TYPE,
__POLICYCONFA_MAX __POLICYCONFA_MAX
}; };
#define POLICYCONFA_MAX (__POLICYCONFA_MAX - 1) #define POLICYCONFA_MAX (__POLICYCONFA_MAX - 1)

View File

@ -10,24 +10,15 @@
#include "../netlink_api/libnetlink_k.h" #include "../netlink_api/libnetlink_k.h"
#include "../../../Common/commuapinl.h" #include "../../../Common/commuapinl.h"
#define strict_strtoul kstrtoul
/**************************************************************************************************************/
#include <linux/rtnetlink.h>
#define NLMSG_TAIL(nmsg) \
((struct rtattr *) (((void *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len)))
#define RTA_LENGTH(len) (RTA_ALIGN(sizeof(struct rtattr)) + (len))
#define RTA_ALIGNTO 4U
#define RTA_ALIGN(len) ( ((len)+RTA_ALIGNTO-1) & ~(RTA_ALIGNTO-1) )
struct policyconfmsg {
__u8 policy_id;
};
/**************************************************************************************************************/
struct netlinkk_cfg g_upmnlcfg; struct netlinkk_cfg g_upmnlcfg;
int cfgnl_unicast(struct sk_buff *skb, u32 portid)
{
return(commnl_unicast(g_upmnlcfg.sk, skb, portid));
}
#if 0 #if 0
int nl_upm_data_ready(struct sk_buff *skb, struct nlmsghdr *nlh) int nl_upm_data_ready(struct sk_buff *skb, struct nlmsghdr *nlh)
@ -75,44 +66,20 @@ failure:
} }
#endif #endif
int upm_rcv_policycfg(struct sk_buff *skb, struct nlmsghdr *nlh) int cfgrcv_debugfs(struct sk_buff *skb, struct nlmsghdr *nlh,struct netlink_ext_ack *extack)
{ {
printk(KERN_INFO "upm_rcv_policycfg, From pid: %d\n", nlh->nlmsg_pid); int ret = 0;
/**************************************************************************************************************/ printk(KERN_INFO "cfgrcv_debugfs, From pid: %d\n", nlh->nlmsg_pid);
char *pload;
struct nlattr *rta;
char* load;
pload = nlmsg_data(nlh) + NLMSG_ALIGN(sizeof(struct policyconfmsg)); #ifdef NLDEBUG_ACK_COOKIES
rta = (struct nlattr *)pload; ret = debugfs_pkt_num_stati(&g_upmnlcfg, nlh,extack);
load = RTA_DATA(rta); #else
unsigned long fk_type; ret = debugfs_pkt_num_stati_witisend(&g_upmnlcfg, nlh,extack);
#endif
printk("***************************rta->nla_type=%d********************\n", rta->nla_type); //nla_type
printk("**************************load=*****%s**********\n",(char *)load); //string printf
/**************************************************************************************************************/
strict_strtoul(load, 10, &fk_type);
/**************************************************************************************************************/
switch(nlh->nlmsg_type)
{
//case COMMNMSG_POLICYCONF:/**/
case NLMSG_DEBUGFS:
if(nlh->nlmsg_type == NLMSG_DEBUGFS)
{
debugfs_pkt_num_stati(&g_upmnlcfg, nlh, fk_type);
printk("*****************biduichengong***************\n"); printk("*****************biduichengong***************\n");
return 0; return ret;
}
break;
default:
printk(KERN_INFO "libnetlink Unknow msgtype recieved!\n");
return 0;
}
/**************************************************************************************************************/
return 0;
} }
@ -134,8 +101,7 @@ int __init upm_init(void)
} }
/*do msg process register*/ /*do msg process register*/
cfg_msgtype_register(COMMNMSG_POLICYCONF,upm_rcv_policycfg,NULL,NULL); cfg_msgtype_register(COMMNMSG_CFG_DEBUGFS,cfgrcv_debugfs,NULL,NULL);
cfg_msgtype_register(NLMSG_DEBUGFS,upm_rcv_policycfg,NULL,NULL);
return 0; return 0;
} }
@ -148,6 +114,7 @@ void __exit upm_exit(void)
return; return;
} }
EXPORT_SYMBOL_GPL(cfgnl_unicast);
module_init(upm_init); module_init(upm_init);
module_exit(upm_exit); module_exit(upm_exit);

View File

@ -1,5 +1,12 @@
#!/bin/sh #!/bin/sh
echo '---------build kernel_ko:-------' echo '---------build kernel_ko:-------'
cd ../../modules/netlink_api
echo 'clean netlink_api..'
make clean
make
echo 'build netlink_api.ko sucess!'
echo '---------------------------'
cd ../../modules/cfgrcv cd ../../modules/cfgrcv
echo 'clean cfgrcv..' echo 'clean cfgrcv..'
make clean make clean

View File

@ -10,6 +10,19 @@
#include "libnetlink_k.h" #include "libnetlink_k.h"
#include "../../../Common/commuapinl.h" #include "../../../Common/commuapinl.h"
#define strict_strtoul kstrtoul
/**************************************************************************************************************/
#include <linux/rtnetlink.h>
#define NLMSG_TAIL(nmsg) \
((struct rtattr *) (((void *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len)))
#define RTA_LENGTH(len) (RTA_ALIGN(sizeof(struct rtattr)) + (len))
#define RTA_ALIGNTO 4U
#define RTA_ALIGN(len) ( ((len)+RTA_ALIGNTO-1) & ~(RTA_ALIGNTO-1) )
/**************************************************************************************************************/
struct commnl_msgtype_process pdelivnl_msg_handlers[NLMGS_PDELIVERY_MAX_TYPE]; struct commnl_msgtype_process pdelivnl_msg_handlers[NLMGS_PDELIVERY_MAX_TYPE];
struct commnl_msgtype_process cfgnl_msg_handlers[COMMCFG_NLMSG_MAX_TYPE]; struct commnl_msgtype_process cfgnl_msg_handlers[COMMCFG_NLMSG_MAX_TYPE];
struct recv_debugfs recv_dfs; struct recv_debugfs recv_dfs;
@ -174,14 +187,14 @@ void printk_ipaddress(unsigned int address)
int nl_cfg_data_ready(struct sk_buff *skb, struct nlmsghdr *nlh, struct netlink_ext_ack *extack) int nl_cfg_data_ready(struct sk_buff *skb, struct nlmsghdr *nlh, struct netlink_ext_ack *extack)
{ {
int ret = -1; int ret = 0;
printk(KERN_DEBUG "nl_cfg_data_ready() nlmsg_type = %d begin.\n",nlh->nlmsg_type); printk(KERN_DEBUG "nl_cfg_data_ready() nlmsg_type = %d begin.\n",nlh->nlmsg_type);
if(NULL != cfgnl_msg_handlers[nlh->nlmsg_type].doit) if(NULL != cfgnl_msg_handlers[nlh->nlmsg_type].doit)
{ {
cfgnl_msg_handlers[nlh->nlmsg_type].cfg_recv_succ++; cfgnl_msg_handlers[nlh->nlmsg_type].cfg_recv_succ++;
ret = cfgnl_msg_handlers[nlh->nlmsg_type].doit(skb, nlh); ret = cfgnl_msg_handlers[nlh->nlmsg_type].doit(skb, nlh,extack);
recv_dfs.cfg_recv_succ++; recv_dfs.cfg_recv_succ++;
} }
@ -196,18 +209,19 @@ int nl_cfg_data_ready(struct sk_buff *skb, struct nlmsghdr *nlh, struct netlink_
printk(KERN_DEBUG "nl_cfg_data_ready() nlmsg_type = %d end.\n",nlh->nlmsg_type); printk(KERN_DEBUG "nl_cfg_data_ready() nlmsg_type = %d end.\n",nlh->nlmsg_type);
return 0; return ret;
} }
int nl_pdeliv_data_ready(struct sk_buff *skb, struct nlmsghdr *nlh, struct netlink_ext_ack *extack) int nl_pdeliv_data_ready(struct sk_buff *skb, struct nlmsghdr *nlh, struct netlink_ext_ack *extack)
{ {
int ret = -1; int ret = 0;
printk(KERN_DEBUG "nl_pdeliv_data_ready() nlmsg_type = %d begin.\n",nlh->nlmsg_type); printk(KERN_DEBUG "nl_pdeliv_data_ready() nlmsg_type = %d begin.\n",nlh->nlmsg_type);
if(NULL != pdelivnl_msg_handlers[nlh->nlmsg_type].doit) if(NULL != pdelivnl_msg_handlers[nlh->nlmsg_type].doit)
{ {
pdelivnl_msg_handlers[nlh->nlmsg_type].cfg_recv_succ++; pdelivnl_msg_handlers[nlh->nlmsg_type].cfg_recv_succ++;
ret = pdelivnl_msg_handlers[nlh->nlmsg_type].doit(skb, nlh); ret = pdelivnl_msg_handlers[nlh->nlmsg_type].doit(skb, nlh,extack);
recv_dfs.pde_recv_succ++; recv_dfs.pde_recv_succ++;
} }
@ -220,7 +234,7 @@ int nl_pdeliv_data_ready(struct sk_buff *skb, struct nlmsghdr *nlh, struct netli
printk(KERN_DEBUG "nl_pdeliv_data_ready() nlmsg_type = %d end.\n",nlh->nlmsg_type); printk(KERN_DEBUG "nl_pdeliv_data_ready() nlmsg_type = %d end.\n",nlh->nlmsg_type);
return 0; return ret;
} }
static void libcfgnl_rcv(struct sk_buff *skb) static void libcfgnl_rcv(struct sk_buff *skb)
@ -302,27 +316,77 @@ int commnl_unicast(struct sock *sk, struct sk_buff *skb, u32 portid)
} }
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;
int debugfs_pkt_num_stati(struct netlinkk_cfg *g_nlcfg, struct nlmsghdr *nlh, unsigned long fk_type) printk("debugfs_pkt_num_stati.\r\n");
len = strlen(cookies);
if(len > sizeof(extack->cookie) )/*check len*/
{
printk("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!!!!!!!!!!*/
printk("------------------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_witisend(struct netlinkk_cfg *g_nlcfg, struct nlmsghdr *nlh,struct netlink_ext_ack *extack)
{ {
int err; int err;
struct sk_buff *out_skb; struct sk_buff *out_skb;
struct nlmsghdr *out_nlh; struct nlmsghdr *out_nlh;
unsigned int length = sizeof(struct netlink_debugfs); unsigned int length = sizeof(struct netlink_debugfs);
char *pload;
struct nlattr *rta;
char* load;
unsigned long fk_type;
struct netlink_debugfs netlink_dfs_temp ={0};
pload = nlmsg_data(nlh);
rta = (struct nlattr *)pload;
load = RTA_DATA(rta);
printk("***************************rta->nla_type=%d********************\n", rta->nla_type); //nla_type
printk("**************************load=*****%s**********\n",(char *)load); //string printf
strict_strtoul(load, 10, &fk_type);
printk("***************************fk_type%lu********************\n", fk_type);
out_skb = nlmsg_new(length, GFP_KERNEL); out_skb = nlmsg_new(length, GFP_KERNEL);
if (!out_skb) goto failure; if (!out_skb) goto failure;
out_nlh = nlmsg_put(out_skb, 0, 0, NLMSG_DEBUGFS, length, 0); out_nlh = nlmsg_put(out_skb,nlh->nlmsg_pid, nlh->nlmsg_seq, 0x11, length, 0);
if (!out_nlh) goto failure; if (!out_nlh) goto failure;
g_nlcfg->netlink_dfs.cfg_rev_succ = cfgnl_msg_handlers[fk_type].cfg_recv_succ; netlink_dfs_temp.cfg_rev_succ = cfgnl_msg_handlers[fk_type].cfg_recv_succ;
g_nlcfg->netlink_dfs.cfg_rev_fail = cfgnl_msg_handlers[fk_type].cfg_recv_fail; netlink_dfs_temp.cfg_rev_fail = cfgnl_msg_handlers[fk_type].cfg_recv_fail;
g_nlcfg->netlink_dfs.pde_rev_succ = pdelivnl_msg_handlers[fk_type].cfg_recv_succ; netlink_dfs_temp.pde_rev_succ = pdelivnl_msg_handlers[fk_type].cfg_recv_succ;
g_nlcfg->netlink_dfs.pde_rev_fail = pdelivnl_msg_handlers[fk_type].cfg_recv_fail; netlink_dfs_temp.pde_rev_fail = pdelivnl_msg_handlers[fk_type].cfg_recv_fail;
netlink_dfs_temp.pde_pkt_fail = g_nlcfg->netlink_dfs.pde_pkt_fail;
netlink_dfs_temp.pde_pkt_succ = g_nlcfg->netlink_dfs.pde_pkt_succ;
memcpy(nlmsg_data(out_nlh), &(g_nlcfg->netlink_dfs), length); memcpy(nlmsg_data(out_nlh), &(netlink_dfs_temp), length);
printk("******************************g_nlcfg->pdeliv_dfs.pde_fail=%d****************\n",g_nlcfg->netlink_dfs.pde_pkt_fail); printk("******************************g_nlcfg->pdeliv_dfs.cfg_rev_succ=%d****************\n",g_nlcfg->netlink_dfs.cfg_rev_succ);
printk("******************************g_nlcfg->pdeliv_dfs.pde_succ=%d****************\n",g_nlcfg->netlink_dfs.pde_pkt_succ); printk("******************************g_nlcfg->pdeliv_dfs.cfg_rev_fail=%d****************\n",g_nlcfg->netlink_dfs.cfg_rev_fail);
printk("******************************g_nlcfg->pdeliv_dfs.pde_rev_succ=%d****************\n",g_nlcfg->netlink_dfs.pde_rev_succ);
printk("******************************g_nlcfg->pdeliv_dfs.pde_rev_fail=%d****************\n",g_nlcfg->netlink_dfs.pde_rev_fail);
printk("******************************g_nlcfg->pdeliv_dfs.pde_pkt_succ=%d****************\n",g_nlcfg->netlink_dfs.pde_pkt_succ);
printk("******************************g_nlcfg->pdeliv_dfs.pde_pkt_fail=%d****************\n",g_nlcfg->netlink_dfs.pde_pkt_fail);
printk("------------------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)
err = 0; err = 0;
@ -361,8 +425,12 @@ EXPORT_SYMBOL_GPL(commnl_unicast);
EXPORT_SYMBOL_GPL(printk_mem); EXPORT_SYMBOL_GPL(printk_mem);
EXPORT_SYMBOL_GPL(printk_ipaddress); 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(nf_nlmsg_multicast); EXPORT_SYMBOL_GPL(nf_nlmsg_multicast);
int __init libnetlink_k_init(void) int __init libnetlink_k_init(void)
{ {
printk(KERN_INFO "insmod netlink.ko...\n"); printk(KERN_INFO "insmod netlink.ko...\n");

View File

@ -6,6 +6,7 @@
#include <uapi/linux/ip.h> #include <uapi/linux/ip.h>
#include <net/netlink.h> #include <net/netlink.h>
#include <net/net_namespace.h> #include <net/net_namespace.h>
#include "../../../Common/commuapinl.h"
struct recv_debugfs { struct recv_debugfs {
unsigned int cfg_recv_succ; unsigned int cfg_recv_succ;
@ -15,16 +16,7 @@ struct recv_debugfs {
}; };
struct netlink_debugfs {
unsigned int cfg_rev_succ;
unsigned int cfg_rev_fail;
unsigned int pde_rev_succ;
unsigned int pde_rev_fail;
unsigned int pde_pkt_succ;
unsigned int pde_pkt_fail;
};
struct netlinkk_cfg struct netlinkk_cfg
{ {
@ -37,9 +29,9 @@ struct netlinkk_cfg
struct netlink_debugfs netlink_dfs; struct netlink_debugfs netlink_dfs;
}; };
typedef int (*commnl_doit_func)(struct sk_buff *, struct nlmsghdr *); typedef int (*commnl_doit_func)(struct sk_buff *, struct nlmsghdr *,struct netlink_ext_ack *);
typedef int (*commnl_dumpit_func)(struct sk_buff *, struct netlink_callback *); typedef int (*commnl_dumpit_func)(struct sk_buff *, struct netlink_callback *,struct netlink_ext_ack *);
typedef u16 (*commnl_calcit_func)(struct sk_buff *, struct nlmsghdr *); typedef u16 (*commnl_calcit_func)(struct sk_buff *, struct nlmsghdr *,struct netlink_ext_ack *);
struct commnl_msgtype_process struct commnl_msgtype_process
{ {
@ -89,7 +81,10 @@ extern void libnetlinkk_exit(struct netlinkk_cfg *g_nlcfg);
extern int commnl_unicast(struct sock *sk, struct sk_buff *skb, u32 portid); extern int commnl_unicast(struct sock *sk, struct sk_buff *skb, u32 portid);
extern int debugfs_pkt_num_stati(struct netlinkk_cfg *g_nlcfg, struct nlmsghdr *nlh, unsigned long fk_value); extern int debugfs_pkt_num_stati(struct netlinkk_cfg *g_nlcfg,
struct nlmsghdr *nlh,struct netlink_ext_ack *extack);
extern int debugfs_pkt_num_stati_witisend(struct netlinkk_cfg *g_nlcfg,
struct nlmsghdr *nlh,struct netlink_ext_ack *extack);
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);

View File

@ -9,19 +9,7 @@
#include "../netlink_api/libnetlink_k.h" #include "../netlink_api/libnetlink_k.h"
#include "../../../Common/commuapinl.h" #include "../../../Common/commuapinl.h"
#define strict_strtoul kstrtoul
/**************************************************************************************************************/
#include <linux/rtnetlink.h>
#define NLMSG_TAIL(nmsg) \
((struct rtattr *) (((void *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len)))
#define RTA_LENGTH(len) (RTA_ALIGN(sizeof(struct rtattr)) + (len))
#define RTA_ALIGNTO 4U
#define RTA_ALIGN(len) ( ((len)+RTA_ALIGNTO-1) & ~(RTA_ALIGNTO-1) )
struct policyconfmsg {
__u8 policy_id;
};
/**************************************************************************************************************/
//int nf_nlmsg_multicast(struct netlinkk_cfg *g_nlcfg, struct sk_buff *skb); //int nf_nlmsg_multicast(struct netlinkk_cfg *g_nlcfg, struct sk_buff *skb);
unsigned int pdelivery_hook_func(void *priv, unsigned int pdelivery_hook_func(void *priv,
@ -42,38 +30,24 @@ static struct nf_hook_ops upm_nfho = {
}; };
int pdeliv_rcv_stat(struct sk_buff *skb, struct nlmsghdr *nlh) int pdeliv_rcv_stat(struct sk_buff *skb, struct nlmsghdr *nlh,struct netlink_ext_ack * ext_ack)
{ {
printk(KERN_INFO "pdeliv_rcv_stat, From: %d\n", nlh->nlmsg_pid); int ret = 0;
/**************************************************************************************************************/
char *pload;
struct nlattr *rta;
char* load;
unsigned long fk_type;
pload = nlmsg_data(nlh) + NLMSG_ALIGN(sizeof(struct policyconfmsg));
rta = (struct nlattr *)pload;
load = RTA_DATA(rta);
printk("***************************rta->nla_type=%d********************\n", rta->nla_type); //nla_type
printk("**************************load=*****%s**********\n",(char *)load); //string printf
strict_strtoul(load, 10, &fk_type);
printk("***************************fk_type%d********************\n", fk_type);
/**************************************************************************************************************/
/**************************************************************************************************************/ /**************************************************************************************************************/
switch(nlh->nlmsg_type) switch(nlh->nlmsg_type)
{ {
//case COMMNMSG_POLICYCONF:/**/ //case COMMNMSG_POLICYCONF:/**/
case NLMSG_DEBUGFS: case NLMSG_PDELIV_DEBUGFS:
if(nlh->nlmsg_type == NLMSG_DEBUGFS)
{ #ifdef NLDEBUG_ACK_COOKIES
debugfs_pkt_num_stati(&g_nlcfg, nlh, fk_type); ret = debugfs_pkt_num_stati(&g_nlcfg, nlh, ext_ack);
#else
ret = debugfs_pkt_num_stati_witisend(&g_nlcfg, nlh,ext_ack);
#endif
printk("*****************biduichengong********%d*******\n", nlh->nlmsg_type); printk("*****************biduichengong********%d*******\n", nlh->nlmsg_type);
return 0; return ret;
}
break; break;
default: default:
@ -111,7 +85,7 @@ 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_DEBUGFS,pdeliv_rcv_stat,NULL,NULL); pdeliv_msgtype_register(NLMSG_PDELIV_DEBUGFS,pdeliv_rcv_stat,NULL,NULL);
return 0; return 0;
} }
@ -168,6 +142,10 @@ unsigned int pdelivery_hook_func(void *priv,
out_payload = nlmsg_data(out_nlh); out_payload = nlmsg_data(out_nlh);
memcpy(out_payload, payload,payload_len);/**/ memcpy(out_payload, payload,payload_len);/**/
/*example:use nla_put to add other attr here. ***********************************/
/*int nla_put(struct sk_buff *skb, int attrtype, int attrlen, const void *data);*/
/********************************************************************************/
#if 1 #if 1
printk(KERN_INFO "%02x %02x %02x %02x %02x %02x %02x %02x\r\n", printk(KERN_INFO "%02x %02x %02x %02x %02x %02x %02x %02x\r\n",
*((char*)out_payload),*((char*)out_payload+1), *((char*)out_payload),*((char*)out_payload+1),
@ -178,16 +156,6 @@ unsigned int pdelivery_hook_func(void *priv,
ret = nf_nlmsg_multicast(&g_nlcfg, out_skb); ret = nf_nlmsg_multicast(&g_nlcfg, out_skb);
#if 0
ret = nlmsg_multicast(g_nlcfg.sk,out_skb,0,PDNLGRP_ALLRAW,0);
if (ret < 0)
{
printk(KERN_INFO "Error while sending pkt to user, err id: %d\n", ret);
}
g_nlcfg.pkt_delev_num ++;
#endif
//g_nlcfg.pkt_delev_num ++;
printk(KERN_INFO "pdelivery_hook_func() end.\n"); printk(KERN_INFO "pdelivery_hook_func() end.\n");
return NF_ACCEPT;/*must return a value*/ return NF_ACCEPT;/*must return a value*/

View File

@ -10,74 +10,91 @@
#include "policyconf.h" #include "policyconf.h"
#include "commuapinl.h" #include "commuapinl.h"
struct upmnl_handle cfgnlh; #ifdef NLDEBUG_ACK_COOKIES
#define CFG_DEBUG_ACK_COOKIES
#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 #endif
int set_user_policy_waitack() struct upmnl_handle cfgnlh;
int set_cfg_debug_waitack()
{ {
unsigned char srcip[]={"17"};/*需要发送的数据*/ struct nlmsghdr *ack = NULL;
int srcip_len = strlen((const char *)srcip); struct nlmsghdr **answer = &ack;
unsigned char debug_msg_type[]={"17"};/*需要发送的数据*/
int msg_len = strlen((const char *)debug_msg_type);
struct { struct {
struct nlmsghdr n; struct nlmsghdr n;
struct policyconfmsg ncm;
char buf[1024]; char buf[1024];
} req = { } req = {
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct policyconfmsg)), .n.nlmsg_len = NLMSG_LENGTH(0),
.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK, #ifdef CFG_DEBUG_ACK_COOKIES
//.n.nlmsg_type = COMMNMSG_POLICYCONF, .n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK,/*set NLM_F_ACKuse kernel auto ack*/
.n.nlmsg_type = COMMNMSG_DEBUGFS, #else
.ncm.policy_id = 17, .n.nlmsg_flags = NLM_F_REQUEST,/*not use kernel auto ack*/
#endif
.n.nlmsg_type = COMMNMSG_CFG_DEBUGFS,
.n.nlmsg_pid = getpid(), .n.nlmsg_pid = getpid(),
}; };
printf("set_user_policy_waitack\r\n"); printf("set_cfg_debug_waitack\r\n");
/*可选属性*/ /*可选属性*/
commnl_addattr_l(&req.n, sizeof(req), POLICYCONFA_SRCIP, srcip, srcip_len); commnl_addattr_l(&req.n, sizeof(req), NLDEBUG_MSG_TYPE, debug_msg_type, msg_len);
printf("srcip_len =%d.req.n.nlmsg_type =%d\r\n",srcip_len,req.n.nlmsg_type); printf("cfg send debugfs msg to kernel:srcip_len =%d.req.n.nlmsg_type =%d\r\n",msg_len,req.n.nlmsg_type);
/*发送组装好的netlink消息*/ /*发送组装好的netlink消息*/
if (commcfg_talk(&req.n, NULL) < 0) if (commcfg_talk(&req.n, answer) < 0)
{
printf("set_cfg_debug_waitack rcv ack msg faild.\r\n");
return -2; return -2;
}
else{
printf("set_cfg_debug_waitack rcv ack msg sucess.\r\n");
}
if(*answer != NULL)
{
printf("set_cfg_debug_waitack rcv answer.\r\n");
}
else{
printf("set_cfg_debug_waitack rcv answer error.\r\n");
return -3;
}
#ifdef CFG_DEBUG_ACK_COOKIES
/*recv answer*/
if((*answer)->nlmsg_type == NLMSG_ERROR){
nl_debugfs_extack(*answer);
}
else{
printf("set_cfg_debug_waitack nlmsg_type is=0x%x,not debugfsmsg ack.\r\n",ack->nlmsg_type);
}
#else
if((*answer)->nlmsg_type == COMMNMSG_CFG_DEBUGFS){
nl_debugfs(*answer);
}
else{
printf("set_cfg_debug_waitack nlmsg_type is=0x%x,not COMMNMSG_CFG_DEBUGFS ack.\r\n",ack->nlmsg_type);
}
#endif
return 0; return 0;
} }
int set_user_policy_nowaitack() int set_cfg_debug_nowaitack()
{ {
unsigned char srcip[64]={"192.168.1.1"};/*需要发送的数据*/ unsigned char debug_msg_type[]={"17"};/*需要发送的数据*/
int srcip_len = strlen((const char *)srcip); int msg_len = strlen((const char *)debug_msg_type);
struct { struct {
struct nlmsghdr n; struct nlmsghdr n;
@ -86,17 +103,17 @@ int set_user_policy_nowaitack()
} req = { } req = {
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct policyconfmsg)), .n.nlmsg_len = NLMSG_LENGTH(sizeof(struct policyconfmsg)),
.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK, .n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK,
.n.nlmsg_type = COMMNMSG_POLICYCONF, .n.nlmsg_type = COMMNMSG_CFG_DEBUGFS,
.ncm.policy_id = 17, .ncm.policy_id = 17,
.n.nlmsg_pid = getpid(), .n.nlmsg_pid = getpid(),
}; };
printf("set_user_policy_nowaitack\r\n"); printf("set_cfg_debug_nowaitack\r\n");
/*可选属性*/ /*可选属性*/
commnl_addattr_l(&req.n, sizeof(req), POLICYCONFA_SRCIP, srcip, srcip_len); commnl_addattr_l(&req.n, sizeof(req), NLDEBUG_MSG_TYPE, debug_msg_type, msg_len);
printf("srcip_len =%d.req.n.nlmsg_type =%d\r\n",srcip_len,req.n.nlmsg_type); printf("msg_len =%d.req.n.nlmsg_type =%d\r\n",msg_len,req.n.nlmsg_type);
/*发送组装好的netlink消息*/ /*发送组装好的netlink消息*/
if (commcfg_send(&req.n) < 0) if (commcfg_send(&req.n) < 0)
@ -123,13 +140,15 @@ int main( int argc, char **argv)
} }
/*下发配置到内核态*/ /*下发配置到内核态*/
ret = set_user_policy_waitack(); //ret = set_cfg_debug_nowaitack();
ret = set_cfg_debug_waitack();
if(ret < 0) if(ret < 0)
{ {
printf("set_user_policy failed.\r\n"); printf("set_cfg_debug_waitack failed.\r\n");
return -1; return -1;
} }
/*关闭netlink通道*/ /*关闭netlink通道*/
commcfgnl_close(); commcfgnl_close();

View File

@ -15,6 +15,14 @@
#include "libnetlinku.h" #include "libnetlinku.h"
#include "commuapinl.h" #include "commuapinl.h"
#ifndef SOL_NETLINK
#define SOL_NETLINK 270
#endif
#ifndef NETLINK_EXT_ACK
#define NETLINK_EXT_ACK 11
#endif
#if 0 #if 0
struct nlumsg_list { struct nlumsg_list {
struct list_head list; struct list_head list;
@ -201,11 +209,12 @@ int commnl_open_byproto( unsigned int subscriptions,int protocol)
goto ERR; goto ERR;
} }
#if 0
/* Older kernels may no support extended ACK reporting */ /* Older kernels may no support extended ACK reporting */
setsockopt(upmh->fd, SOL_NETLINK, NETLINK_EXT_ACK, if (setsockopt(upmh->fd, SOL_NETLINK, NETLINK_EXT_ACK,
&one, sizeof(one)); &one, sizeof(one))){
#endif perror("NETLINK_EXT_ACK");
goto ERR;
}
memset(&upmh->local, 0, sizeof(upmh->local)); memset(&upmh->local, 0, sizeof(upmh->local));
upmh->local.nl_family = AF_NETLINK; upmh->local.nl_family = AF_NETLINK;
@ -338,15 +347,16 @@ int pdelivnl_send(int group,struct nlmsghdr *n)
static int __commnl_recvmsg(int fd, struct msghdr *msg, int flags) static int __commnl_recvmsg(int fd, struct msghdr *msg, int flags)
{ {
int len; int len = 0;
unsigned int num = COMMNL_TALKRCV_TIMEOUT;/*10秒超时*/ unsigned int num = COMMNL_TALKRCV_TIMEOUT;/*timeout*/
do { do {
len = recvmsg(fd, msg, flags); len = recvmsg(fd, msg, flags);
#if 1
num --; num --;
if(num ==0) if(num ==0)
break; break;
#endif
printf("__rtnl_recvmsg return num %d.\r\n",num); printf("__rtnl_recvmsg return num %d.\r\n",num);
} while (len < 0 && (errno == EINTR || errno == EAGAIN));/*超时*/ } while (len < 0 && (errno == EINTR || errno == EAGAIN));/*超时*/
@ -370,7 +380,6 @@ static int commnl_recvmsg(int fd, struct msghdr *msg, char **answer)
struct iovec *iov = msg->msg_iov; struct iovec *iov = msg->msg_iov;
char *buf; char *buf;
int len; int len;
struct netlink_debugfs *debugfs_statis;
struct nlmsghdr *recv_hdr; struct nlmsghdr *recv_hdr;
@ -402,22 +411,7 @@ static int commnl_recvmsg(int fd, struct msghdr *msg, char **answer)
*answer = buf; *answer = buf;
else else
free(buf); free(buf);
recv_hdr = (struct nlmsghdr *)(*answer);
recv_hdr = *answer;
printf("*******************answer******%d****************\n", *answer);
if(recv_hdr->nlmsg_type == COMMNMSG_DEBUGFS)
{
debugfs_statis = NLMSG_DATA(*answer);
printf("******debugfs_statis->cfg_rev_succ = %d******\n",debugfs_statis->cfg_rev_succ);
printf("******debugfs_statis->cfg_rev_fail = %d******\n",debugfs_statis->cfg_rev_fail);
printf("******debugfs_statis->pde_rev_succ = %d******\n",debugfs_statis->pde_rev_succ);
printf("******debugfs_statis->pde_rev_fail = %d******\n",debugfs_statis->pde_rev_fail);
printf("******debugfs_statis->pde_pkt_succ = %d******\n",debugfs_statis->pde_pkt_succ);
printf("******debugfs_statis->pde_pkt_fail = %d******\n",debugfs_statis->pde_pkt_fail);
}
return len; return len;
} }
@ -452,6 +446,9 @@ static int __commnl_talk_iov(struct upmnl_handle *rtnl, struct iovec *iov,
perror("Cannot talk to rtnetlink"); perror("Cannot talk to rtnetlink");
return -1; return -1;
} }
else{
printf("__commnl_talk_iov send msg sucess.\r\n");
}
/* change msg to use the response iov */ /* change msg to use the response iov */
msg.msg_iov = &riov; msg.msg_iov = &riov;
@ -459,11 +456,15 @@ static int __commnl_talk_iov(struct upmnl_handle *rtnl, struct iovec *iov,
i = 0; i = 0;
while (1) { while (1) {
next: next:
printf("talk recvmsg-ing...\r\n");
status = commnl_recvmsg(rtnl->fd, &msg, &buf); status = commnl_recvmsg(rtnl->fd, &msg, &buf);
++i; ++i;
if (status < 0) if (status < 0)
{
printf("__commnl_talk_iov: commnl_recvmsg return error=%d...\r\n",status);
return status; return status;
}
if (msg.msg_namelen != sizeof(nladdr)) { if (msg.msg_namelen != sizeof(nladdr)) {
fprintf(stderr, fprintf(stderr,
@ -494,10 +495,13 @@ next:
/* Don't forget to skip that message. */ /* Don't forget to skip that message. */
status -= NLMSG_ALIGN(len); status -= NLMSG_ALIGN(len);
h = (struct nlmsghdr *)((char *)h + NLMSG_ALIGN(len)); h = (struct nlmsghdr *)((char *)h + NLMSG_ALIGN(len));
printf("__commnl_talk_iov recv a msg,but not to me:h->nlmsg_pid=%d,local_pid=%d,h->nlmsg_seq=%d,seq=%d.\r\n",
h->nlmsg_pid,rtnl->local.nl_pid,h->nlmsg_seq,seq);
continue; continue;
} }
if (h->nlmsg_type == NLMSG_ERROR) { if (h->nlmsg_type == NLMSG_ERROR) {
printf("nltalk recv a ack msg.\r\n");
struct nlmsgerr *err = (struct nlmsgerr *)NLMSG_DATA(h); struct nlmsgerr *err = (struct nlmsgerr *)NLMSG_DATA(h);
int error = err->error; int error = err->error;
@ -518,9 +522,7 @@ next:
} }
if (answer) if (answer)
{
*answer = (struct nlmsghdr *)buf; *answer = (struct nlmsghdr *)buf;
}
else else
free(buf); free(buf);
@ -538,6 +540,7 @@ next:
status -= NLMSG_ALIGN(len); status -= NLMSG_ALIGN(len);
h = (struct nlmsghdr *)((char *)h + NLMSG_ALIGN(len)); h = (struct nlmsghdr *)((char *)h + NLMSG_ALIGN(len));
printf("goto next nlmsghdr");
} }
free(buf); free(buf);
@ -608,6 +611,8 @@ int pdelivnl_listen(int group,
{ {
struct upmnl_handle *nl = NULL; struct upmnl_handle *nl = NULL;
printf("pdelivnl_listen:.\r\n");
nl = commnl_get_handle(NETLINK_PDELIVERY,group); nl = commnl_get_handle(NETLINK_PDELIVERY,group);
if(nl == NULL) if(nl == NULL)
{ {
@ -635,7 +640,7 @@ int conmnl_listen(struct upmnl_handle *nl,
char buf[16384]; char buf[16384];
char cmsgbuf[BUFSIZ]; char cmsgbuf[BUFSIZ];
printf("pdelivnl_listen begin.\r\n"); printf("conmnl_listen begin.\r\n");
#if 0 #if 0
if (nl->flags & RTNL_HANDLE_F_LISTEN_ALL_NSID) { if (nl->flags & RTNL_HANDLE_F_LISTEN_ALL_NSID) {
@ -651,12 +656,13 @@ int conmnl_listen(struct upmnl_handle *nl,
printf("pdelivnl_listen recvmsg....\r\n"); printf("pdelivnl_listen recvmsg....\r\n");
iov.iov_len = sizeof(buf); iov.iov_len = sizeof(buf);
status = recvmsg(nl->fd, &msg, MSG_WAITALL); //status = recvmsg(nl->fd, &msg, MSG_WAITALL);
status = recvmsg(nl->fd, &msg, MSG_WAITFORONE);
if (status < 0) { if (status < 0) {
if (errno == EINTR || errno == EAGAIN)/*超时*/ if (errno == EINTR || errno == EAGAIN)/*超时*/
continue; continue;
fprintf(stderr, "netlink receive error %s (%d)\n", fprintf(stderr, "netlink receive error: %s (%d)\n",
strerror(errno), errno); strerror(errno), errno);
if (errno == ENOBUFS) if (errno == ENOBUFS)
continue; continue;
@ -779,3 +785,64 @@ int pdeliv_main(pdelivnl_listen_filter_t process_pkt)
return 0; return 0;
} }
void nl_debugfs(struct nlmsghdr *n)
{
struct netlink_debugfs *debugfs_statis =NULL;
int msg_len = 0;
debugfs_statis = (struct netlink_debugfs *)NLMSG_DATA(n);/*msg data*/
msg_len = (n)->nlmsg_len - NLMSG_HDRLEN; /*msg_len*/
printf("******debugfs_statis->cfg_rev_succ = %d******\n",debugfs_statis->cfg_rev_succ);
printf("******debugfs_statis->cfg_rev_fail = %d******\n",debugfs_statis->cfg_rev_fail);
printf("******debugfs_statis->pde_rev_succ = %d******\n",debugfs_statis->pde_rev_succ);
printf("******debugfs_statis->pde_rev_fail = %d******\n",debugfs_statis->pde_rev_fail);
printf("******debugfs_statis->pde_pkt_succ = %d******\n",debugfs_statis->pde_pkt_succ);
printf("******debugfs_statis->pde_pkt_fail = %d******\n",debugfs_statis->pde_pkt_fail);
return;
}
void nl_debugfs_extack(struct nlmsghdr *n)
{
//struct netlink_debugfs *debugfs_statis =NULL;
char * rcv_cookies = NULL;
int msg_len = 0;
struct nlmsgerr *errmsg = NULL;
struct rtattr * cookies = NULL;
int cookies_len = 0;
char * ptr;
printf("nl_debugfs_extack said:\r\nmsgtype=%d,msglen=%d\r\n",n->nlmsg_type,n->nlmsg_len);
errmsg = (struct nlmsgerr *)NLMSG_DATA(n);/*msg data*/
msg_len = (n)->nlmsg_len - NLMSG_HDRLEN; /*msg_len*/
printf("ack result=%d,ack msgtype:%d\r\n",errmsg->error,errmsg->msg.nlmsg_type);
if(errmsg->error == 0)/*ack result is SUCESS*/
{
ptr = (char * )errmsg + sizeof(struct nlmsgerr);
cookies = (struct rtattr *)ptr;
//if(NLMSGERR_ATTR_COOKIE == cookies->rta_type)
{
cookies_len = cookies->rta_len;
rcv_cookies = RTA_DATA(cookies);
printf("nl_debugfs_extack rcv cookies:%s.\r\n",rcv_cookies);
}
}
else{
printf("nl_debugfs kernel said fail,error =%d.\r\n",errmsg->error);
}
return;
}

View File

@ -10,7 +10,7 @@
with attribute type. with attribute type.
*/ */
#define COMMNL_TALKRCV_TIMEOUT (1) /*超时时间10毫秒*1次*/ #define COMMNL_TALKRCV_TIMEOUT (2) /*超时时间10毫秒*1次*/
struct rtattr { struct rtattr {
unsigned short rta_len; unsigned short rta_len;
@ -156,6 +156,7 @@ int commnl_talk(struct upmnl_handle *nl, struct nlmsghdr *n,
struct nlmsghdr **answer); struct nlmsghdr **answer);
int commcfg_talk(struct nlmsghdr *n, struct nlmsghdr **answer); int commcfg_talk(struct nlmsghdr *n, struct nlmsghdr **answer);
int pdeliv_talk(int group,struct nlmsghdr *n, struct nlmsghdr **answer);
/****************************************************************/ /****************************************************************/
/*函数功能:发送配置消息,不等待内核应答。*/ /*函数功能:发送配置消息,不等待内核应答。*/
@ -165,19 +166,12 @@ int commcfg_talk(struct nlmsghdr *n, struct nlmsghdr **answer);
/*输出参数: */ /*输出参数: */
/*返回值0成功< 0,失败 */ /*返回值0成功< 0,失败 */
/****************************************************************/ /****************************************************************/
int commnl_send(struct upmnl_handle *nl, struct nlmsghdr *n); int commcfg_send(struct nlmsghdr *n);
int pdelivnl_send(int group,struct nlmsghdr *n);
int pdeliv_main(pdelivnl_listen_filter_t process_pkt); int pdeliv_main(pdelivnl_listen_filter_t process_pkt);
struct netlink_debugfs { void nl_debugfs(struct nlmsghdr *n);
unsigned int cfg_rev_succ; void nl_debugfs_extack(struct nlmsghdr *n);
unsigned int cfg_rev_fail;
unsigned int pde_rev_succ;
unsigned int pde_rev_fail;
unsigned int pde_pkt_succ;
unsigned int pde_pkt_fail;
};

View File

@ -12,46 +12,70 @@
struct upmnl_handle cfgnlh; struct upmnl_handle cfgnlh;
int set_user_policy() #ifdef NLDEBUG_ACK_COOKIES
#define PDELIV_DEBUG_ACK_COOKIES
#endif
int set_pdeliv_debug_waitack()
{ {
unsigned char debug[]={"17"};/*需要发送的数据*/ unsigned char debug[]={"17"};/*需要发送的数据*/
int debug_len = strlen((const char *)debug); int debug_len = strlen((const char *)debug);
struct nlmsghdr *ack = NULL;
struct nlmsghdr **answer = &ack;
struct { struct {
struct nlmsghdr n; struct nlmsghdr n;
struct policyconfmsg ncm;
char buf[1024]; char buf[1024];
} req = { } req = {
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct policyconfmsg)), .n.nlmsg_len = NLMSG_LENGTH(0),
#ifdef PDELIV_DEBUG_ACK_COOKIES
.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK, .n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK,
.n.nlmsg_type = COMMNMSG_DEBUGFS, #else
.ncm.policy_id =17, .n.nlmsg_flags = NLM_F_REQUEST,
#endif
.n.nlmsg_type = NLMSG_PDELIV_DEBUGFS,
.n.nlmsg_pid = getpid(), .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); commnl_addattr_l(&req.n, sizeof(req), NLDEBUG_MSG_TYPE, debug, debug_len);
/*发送组装好的netlink消息*/ /*发送组装好的netlink消息*/
if (pdeliv_talk(1, &req.n, NULL) < 0) if (pdeliv_talk(1, &req.n, answer) < 0)
{ {
printf("set_user_policy_waitack rcv ack msg faild.\r\n");
return -2; return -2;
} }
/* else{
printf("set_user_policy_waitack rcv ack msg sucess.\r\n");
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);
} }
*/ if(*answer != NULL)
{
printf("set_user_policy_waitack rcv answer.\r\n");
}
else{
printf("set_user_policy_waitack rcv answer error.\r\n");
return -3;
}
#ifdef PDELIV_DEBUG_ACK_COOKIES
/*recv answer*/
if((*answer)->nlmsg_type == NLMSG_ERROR){
nl_debugfs_extack(*answer);
}
#else
/*recv answer*/
if((*answer)->nlmsg_type == NLMSG_PDELIV_DEBUGFS)
{
nl_debugfs(*answer);
}
#endif
return 0; return 0;
} }
@ -71,10 +95,10 @@ int main( int argc, char **argv)
} }
/*下发配置到内核态*/ /*下发配置到内核态*/
ret = set_user_policy(); ret = set_pdeliv_debug_waitack();
if(ret < 0) if(ret < 0)
{ {
printf("set_user_policy failed.\r\n"); printf("set_pdeliv_debug_waitack failed.\r\n");
return -1; return -1;
} }