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"
|
|
|
|
#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
|
|
|
|
|
2019-06-13 09:58:51 +00:00
|
|
|
int set_user_policy_waitack()
|
2019-06-11 03:21:35 +00:00
|
|
|
{
|
2019-06-20 03:20:46 +00:00
|
|
|
unsigned char srcip[]={"17"};/*需要发送的数据*/
|
2019-06-11 03:21:35 +00:00
|
|
|
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,
|
2019-06-20 03:20:46 +00:00
|
|
|
//.n.nlmsg_type = COMMNMSG_POLICYCONF,
|
|
|
|
.n.nlmsg_type = COMMNMSG_DEBUGFS,
|
2019-06-11 03:21:35 +00:00
|
|
|
.ncm.policy_id = 17,
|
|
|
|
.n.nlmsg_pid = getpid(),
|
|
|
|
};
|
2019-06-13 09:58:51 +00:00
|
|
|
|
|
|
|
printf("set_user_policy_waitack\r\n");
|
2019-06-11 03:21:35 +00:00
|
|
|
|
|
|
|
/*可选属性*/
|
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-13 09:58:51 +00:00
|
|
|
int set_user_policy_nowaitack()
|
2019-06-11 03:21:35 +00:00
|
|
|
{
|
|
|
|
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,
|
2019-06-20 03:20:46 +00:00
|
|
|
.n.nlmsg_pid = getpid(),
|
2019-06-11 03:21:35 +00:00
|
|
|
};
|
2019-06-13 09:58:51 +00:00
|
|
|
|
|
|
|
printf("set_user_policy_nowaitack\r\n");
|
|
|
|
|
2019-06-11 03:21:35 +00:00
|
|
|
/*可选属性*/
|
|
|
|
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);
|
2019-06-13 09:58:51 +00:00
|
|
|
|
2019-06-11 03:21:35 +00:00
|
|
|
/*发送组装好的netlink消息*/
|
2019-06-13 09:58:51 +00:00
|
|
|
if (commcfg_send(&req.n) < 0)
|
2019-06-11 03:21:35 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*下发配置到内核态*/
|
2019-06-20 03:20:46 +00:00
|
|
|
ret = set_user_policy_waitack();
|
2019-06-11 03:21:35 +00:00
|
|
|
if(ret < 0)
|
|
|
|
{
|
|
|
|
printf("set_user_policy failed.\r\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*关闭netlink通道*/
|
|
|
|
commcfgnl_close();
|
|
|
|
|
|
|
|
printf("cfgchannel main exit!\r\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|