2019-06-14 09:14:06 +00:00
|
|
|
|
2019-06-11 03:21:35 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "libnetlinku.h"
|
2019-06-14 09:14:06 +00:00
|
|
|
#include "policyconf.h"
|
2019-06-11 03:21:35 +00:00
|
|
|
#include "commuapinl.h"
|
|
|
|
|
2019-06-14 09:14:06 +00:00
|
|
|
struct upmnl_handle cfgnlh;
|
2019-06-11 03:21:35 +00:00
|
|
|
|
2019-06-14 09:14:06 +00:00
|
|
|
int set_user_policy()
|
2019-06-11 03:21:35 +00:00
|
|
|
{
|
2019-06-20 03:20:46 +00:00
|
|
|
unsigned char debug[]={"17"};/*需要发送的数据*/
|
2019-06-14 09:14:06 +00:00
|
|
|
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_DEBUGFS,
|
|
|
|
.ncm.policy_id =17,
|
|
|
|
.n.nlmsg_pid = getpid(),
|
|
|
|
};
|
2019-06-20 03:20:46 +00:00
|
|
|
struct nlmsghdr **debugfs_nl;
|
|
|
|
struct pdeliv_debugfs *debugfs_statis;
|
|
|
|
struct nlmsghdr *recv_hdr;
|
2019-06-14 09:14:06 +00:00
|
|
|
|
|
|
|
/*可选属性*/
|
|
|
|
commnl_addattr_l(&req.n, sizeof(req), POLICYCONFA_SRCIP, debug, debug_len);
|
2019-06-11 03:21:35 +00:00
|
|
|
|
2019-06-14 09:14:06 +00:00
|
|
|
/*发送组装好的netlink消息*/
|
2019-06-20 03:20:46 +00:00
|
|
|
if (pdeliv_talk(1, &req.n, NULL) < 0)
|
|
|
|
{
|
2019-06-14 09:14:06 +00:00
|
|
|
return -2;
|
2019-06-20 03:20:46 +00:00
|
|
|
}
|
|
|
|
/*
|
2019-06-14 09:14:06 +00:00
|
|
|
|
2019-06-20 03:20:46 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
2019-06-14 09:14:06 +00:00
|
|
|
return 0;
|
2019-06-11 03:21:35 +00:00
|
|
|
|
2019-06-14 09:14:06 +00:00
|
|
|
}
|
2019-06-11 03:21:35 +00:00
|
|
|
|
2019-06-14 09:14:06 +00:00
|
|
|
int main( int argc, char **argv)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
2019-06-11 03:21:35 +00:00
|
|
|
|
2019-06-14 09:14:06 +00:00
|
|
|
printf("cfgchannel main begin:\r\n");
|
2019-06-11 03:21:35 +00:00
|
|
|
|
2019-06-14 09:14:06 +00:00
|
|
|
/*创建通道*/
|
|
|
|
ret = pdelivnl_open();
|
|
|
|
if(ret < 0)
|
|
|
|
{
|
|
|
|
printf("pdelivnl_open fail,exit.\r\n");
|
|
|
|
return -1;
|
2019-06-11 03:21:35 +00:00
|
|
|
}
|
|
|
|
|
2019-06-14 09:14:06 +00:00
|
|
|
/*下发配置到内核态*/
|
|
|
|
ret = set_user_policy();
|
|
|
|
if(ret < 0)
|
|
|
|
{
|
|
|
|
printf("set_user_policy failed.\r\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2019-06-11 03:21:35 +00:00
|
|
|
|
2019-06-14 09:14:06 +00:00
|
|
|
/*关闭netlink通道*/
|
|
|
|
pdelivnl_close();
|
2019-06-11 03:21:35 +00:00
|
|
|
|
2019-06-14 09:14:06 +00:00
|
|
|
printf("cfgchannel main exit!\r\n");
|
|
|
|
return 0;
|
2019-06-11 03:21:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|