Mod aaa-12 描述:添加内核态pdeliv模块报文统计
RCA: SOL: 修改人:xusaiqun 检视人:xusaiqun Signed-off-by: xusaiqun <xusaiqun@cmhi.chinamobile.com>
This commit is contained in:
parent
efecb56c67
commit
ee7be5ff7f
|
@ -43,6 +43,7 @@ enum pdelivmsgtype{
|
|||
PDNL_BASE = 0x10,/*netlink 保留控制消息*/
|
||||
PDNLGRP_REQUEST, /*用户态发送给内核态的请求消息,用于查看pdiliv模块本身的状态及配置,与业务无关*/
|
||||
NLMSG_RECV_RAW_PKT,/*上送DPI的报文消息*/
|
||||
NLMSG_DEBUGFS,
|
||||
NLMGS_PDELIVERY_MAX_TYPE,
|
||||
};
|
||||
|
||||
|
@ -73,7 +74,7 @@ enum commcfgmsgtype{
|
|||
COMMMSGNL_BASE = 0x10,/*netlink 保留控制消息*/
|
||||
COMMNMSG_POLICYCONF,
|
||||
COMMNMSG_USER,
|
||||
|
||||
COMMNMSG_DEBUGFS,
|
||||
/*for trace*/
|
||||
TRACE_CFG_POLICY = 0x20,
|
||||
TRACE_CFG_MAX = 0X25,
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
#!/bin/sh
|
||||
echo '---------build kernel_ko:-------'
|
||||
cd ../../modules/cfgrcv
|
||||
echo 'clean cfgrcv..'
|
||||
make clean
|
||||
make
|
||||
echo 'build cfgrcv.ko sucess!'
|
||||
echo '---------------------------'
|
||||
|
||||
echo 'clean pdelivery..'
|
||||
cd ../../modules/pdelivery
|
||||
make clean
|
||||
make
|
||||
echo 'build pdeliv.ko sucess!'
|
||||
echo '---------------------------'
|
||||
echo ' '
|
||||
echo '---------build user_apps:-------'
|
||||
cd ../../user/netlink_uapi
|
||||
echo 'clean libnetlinku.so..'
|
||||
make clean
|
||||
make
|
||||
echo 'build libnetlinku.so sucess!'
|
||||
echo '---------------------------'
|
||||
|
||||
cd ../../user/pdeliv_u
|
||||
echo 'clean pdeliv..'
|
||||
make clean
|
||||
make
|
||||
echo 'build pdeliv sucess!'
|
||||
echo '---------------------------'
|
||||
|
||||
cd ../../user/cfg2kernel
|
||||
echo 'clean commcfg..'
|
||||
make clean
|
||||
make
|
||||
echo 'build commcfg sucess!'
|
||||
echo '---------------------------'
|
|
@ -246,7 +246,7 @@ int libnetlinkk_init_byproto(struct netlinkk_cfg *g_nlcfg)
|
|||
g_nlcfg->cfg.flags = NL_CFG_F_NONROOT_RECV;
|
||||
g_nlcfg->user_pid = -1;
|
||||
//g_nlcfg->sk = -1;
|
||||
g_nlcfg->pkt_delev_num = 0;
|
||||
//g_nlcfg->pkt_delev_num = 0;
|
||||
|
||||
g_nlcfg->sk = netlink_kernel_create(&init_net, g_nlcfg->subscriptions, &(g_nlcfg->cfg));
|
||||
if (!g_nlcfg->sk)
|
||||
|
@ -297,6 +297,48 @@ EXPORT_SYMBOL_GPL(commnl_unicast);
|
|||
EXPORT_SYMBOL_GPL(printk_mem);
|
||||
EXPORT_SYMBOL_GPL(printk_ipaddress);
|
||||
|
||||
int debugfs_pkt_num_stati(struct netlinkk_cfg *g_nlcfg, struct nlmsghdr *nlh)
|
||||
{
|
||||
int err;
|
||||
struct sk_buff *out_skb;
|
||||
struct nlmsghdr *out_nlh;
|
||||
unsigned int length = sizeof(struct pdeliv_debugfs);
|
||||
|
||||
out_skb = nlmsg_new(length, GFP_KERNEL);
|
||||
if (!out_skb) goto failure;
|
||||
out_nlh = nlmsg_put(out_skb, 0, 0, NLMSG_DEBUGFS, length, 0);
|
||||
if (!out_nlh) goto failure;
|
||||
memcpy(nlmsg_data(out_nlh), &(g_nlcfg->pdeliv_dfs), length);
|
||||
printk("******************************g_nlcfg->pdeliv_dfs.pde_fail=%d****************\n",g_nlcfg->pdeliv_dfs.pde_fail);
|
||||
printk("******************************g_nlcfg->pdeliv_dfs.pde_succ=%d****************\n",g_nlcfg->pdeliv_dfs.pde_succ);
|
||||
err = commnl_unicast(g_nlcfg->sk, out_skb, nlh->nlmsg_pid);
|
||||
if (err > 0)
|
||||
err = 0;
|
||||
|
||||
return err;
|
||||
failure:
|
||||
printk(KERN_INFO " failed in fun dataready!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int nf_nlmsg_multicast(struct netlinkk_cfg *g_nlcfg, struct sk_buff *skb)
|
||||
{
|
||||
int ret = -1;
|
||||
ret = nlmsg_multicast(g_nlcfg->sk,skb,0,PDNLGRP_ALLRAW,0);
|
||||
if (ret < 0)
|
||||
{
|
||||
(g_nlcfg->pdeliv_dfs.pde_fail)++;
|
||||
printk(KERN_INFO "Error while sending pkt to user, err id: %d\n", ret);
|
||||
}
|
||||
|
||||
if(ret==0)
|
||||
{
|
||||
(g_nlcfg->pdeliv_dfs.pde_succ)++;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int __init libnetlink_k_init(void)
|
||||
{
|
||||
printk(KERN_INFO "insmod netlink.ko...\n");
|
||||
|
|
|
@ -8,7 +8,12 @@
|
|||
#include <net/net_namespace.h>
|
||||
|
||||
|
||||
|
||||
struct pdeliv_debugfs {
|
||||
unsigned int rev_succ;
|
||||
unsigned int rev_fail;
|
||||
unsigned int pde_succ;
|
||||
unsigned int pde_fail;
|
||||
};
|
||||
|
||||
struct netlinkk_cfg
|
||||
{
|
||||
|
@ -18,10 +23,7 @@ struct netlinkk_cfg
|
|||
int user_pid;/*用户态pid*/
|
||||
unsigned int subscriptions;/*netlink总线,netlink协议号*/
|
||||
unsigned int groups;/*netlink 组播组*/
|
||||
|
||||
//struct upmnl_link *upmnl_msg_handlers[UPMNL_FAMILY_MAX + 1];
|
||||
unsigned int pkt_delev_num;/*上送的包数量*/
|
||||
|
||||
struct pdeliv_debugfs pdeliv_dfs;
|
||||
};
|
||||
|
||||
typedef int (*commnl_doit_func)(struct sk_buff *, struct nlmsghdr *);
|
||||
|
|
|
@ -10,9 +10,11 @@
|
|||
#include "../netlink_api/libnetlink_k.h"
|
||||
#include "../../../Common/commuapinl.h"
|
||||
|
||||
int nf_nlmsg_multicast(struct netlinkk_cfg *g_nlcfg, struct sk_buff *skb);
|
||||
unsigned int pdelivery_hook_func(void *priv,
|
||||
struct sk_buff *skb,
|
||||
const struct nf_hook_state *state);
|
||||
int debugfs_pkt_num_stati(struct netlinkk_cfg *g_nlcfg, struct nlmsghdr *nlh);
|
||||
|
||||
|
||||
|
||||
|
@ -31,6 +33,26 @@ int pdeliv_rcv_stat(struct sk_buff *skb, struct nlmsghdr *nlh)
|
|||
{
|
||||
printk(KERN_INFO "pdeliv_rcv_stat, From: %d\n", nlh->nlmsg_pid);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
switch(nlh->nlmsg_type)
|
||||
{
|
||||
//case COMMNMSG_POLICYCONF:/**/
|
||||
case NLMSG_DEBUGFS:
|
||||
if(nlh->nlmsg_type == NLMSG_DEBUGFS)
|
||||
{
|
||||
debugfs_pkt_num_stati(&g_nlcfg, nlh);
|
||||
printk("*****************biduichengong***************\n");
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
printk(KERN_INFO "libnetlink Unknow msgtype recieved!\n");
|
||||
return 0;
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -60,6 +82,7 @@ int __init pdelivery_init(void)
|
|||
|
||||
/*do msg process register*/
|
||||
pdeliv_msgtype_register(PDNLGRP_REQUEST,pdeliv_rcv_stat,NULL,NULL);
|
||||
pdeliv_msgtype_register(NLMSG_DEBUGFS,pdeliv_rcv_stat,NULL,NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -124,6 +147,9 @@ unsigned int pdelivery_hook_func(void *priv,
|
|||
*((char*)out_payload+6),*((char*)out_payload+7));
|
||||
#endif
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -131,7 +157,9 @@ unsigned int pdelivery_hook_func(void *priv,
|
|||
}
|
||||
g_nlcfg.pkt_delev_num ++;
|
||||
|
||||
printk(KERN_INFO "pdelivery_hook_func() end,pkt_delev_num =%u.\n",g_nlcfg.pkt_delev_num);
|
||||
#endif
|
||||
//g_nlcfg.pkt_delev_num ++;
|
||||
printk(KERN_INFO "pdelivery_hook_func() end.\n");
|
||||
return NF_ACCEPT;/*must return a value*/
|
||||
|
||||
failure:
|
||||
|
|
|
@ -370,6 +370,9 @@ static int commnl_recvmsg(int fd, struct msghdr *msg, char **answer)
|
|||
struct iovec *iov = msg->msg_iov;
|
||||
char *buf;
|
||||
int len;
|
||||
struct pdeliv_debugfs *debugfs_statis;
|
||||
struct nlmsghdr *recv_hdr;
|
||||
|
||||
|
||||
iov->iov_base = NULL;
|
||||
iov->iov_len = 0;
|
||||
|
@ -399,6 +402,16 @@ static int commnl_recvmsg(int fd, struct msghdr *msg, char **answer)
|
|||
*answer = buf;
|
||||
else
|
||||
free(buf);
|
||||
recv_hdr = *answer;
|
||||
|
||||
if(recv_hdr->nlmsg_type == COMMNMSG_DEBUGFS)
|
||||
{
|
||||
debugfs_statis = NLMSG_DATA(*answer);
|
||||
//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 len;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <netinet/in.h>
|
||||
#include <linux/types.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "libnetlinku.h"
|
||||
#include "commuapinl.h"
|
||||
|
||||
#if 0
|
||||
|
||||
|
||||
static int process_pkt(struct pdelivnl_ctrl_data *ctrl,
|
||||
struct nlmsghdr *n, void *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_mem(NLMSG_DATA(n),n->nlmsg_len-NLMSG_HDRLEN);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int main( int argc, char **argv)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
ret = pdeliv_main(process_pkt);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
@ -6,41 +7,66 @@
|
|||
#include <errno.h>
|
||||
|
||||
#include "libnetlinku.h"
|
||||
#include "policyconf.h"
|
||||
#include "commuapinl.h"
|
||||
|
||||
struct upmnl_handle cfgnlh;
|
||||
|
||||
|
||||
|
||||
static int process_pkt(struct pdelivnl_ctrl_data *ctrl,
|
||||
struct nlmsghdr *n, void *arg)
|
||||
int set_user_policy()
|
||||
{
|
||||
unsigned char debug[]={"debug"};/*需要发送的数据*/
|
||||
int debug_len = strlen((const char *)debug);
|
||||
|
||||
printf("pdelivery main process_msg begin:\r\n");
|
||||
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_DEBUGFS,
|
||||
.ncm.policy_id =17,
|
||||
.n.nlmsg_pid = getpid(),
|
||||
};
|
||||
|
||||
/*可选属性*/
|
||||
commnl_addattr_l(&req.n, sizeof(req), POLICYCONFA_SRCIP, debug, debug_len);
|
||||
|
||||
//if (timestamp)
|
||||
//print_timestamp(fp);
|
||||
|
||||
switch (n->nlmsg_type) {
|
||||
case NLMSG_RECV_RAW_PKT:
|
||||
printf("netlink msg type RAW_pkt:\r\n");
|
||||
printf_mem(NLMSG_DATA(n),n->nlmsg_len-NLMSG_HDRLEN);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
/*发送组装好的netlink消息*/
|
||||
if (pdeliv_talk(1,&req.n, NULL) < 0)
|
||||
return -2;
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int main( int argc, char **argv)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
ret = pdeliv_main(process_pkt);
|
||||
printf("cfgchannel main begin:\r\n");
|
||||
|
||||
/*创建通道*/
|
||||
ret = pdelivnl_open();
|
||||
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();
|
||||
|
||||
printf("cfgchannel main exit!\r\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue