2019-06-21 09:02:36 +00:00
|
|
|
#if 1
|
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-21 02:35:43 +00:00
|
|
|
#ifdef NLDEBUG_ACK_COOKIES
|
|
|
|
#define PDELIV_DEBUG_ACK_COOKIES
|
|
|
|
#endif
|
|
|
|
|
2019-06-25 06:42:36 +00:00
|
|
|
int set_pdeliv_debug_waitack(unsigned char * msgtype)
|
2019-06-11 03:21:35 +00:00
|
|
|
{
|
2019-06-25 06:42:36 +00:00
|
|
|
int debug_len = 0;
|
2019-06-21 02:35:43 +00:00
|
|
|
struct nlmsghdr *ack = NULL;
|
|
|
|
struct nlmsghdr **answer = &ack;
|
2019-06-14 09:14:06 +00:00
|
|
|
|
|
|
|
struct {
|
|
|
|
struct nlmsghdr n;
|
|
|
|
char buf[1024];
|
|
|
|
} req = {
|
2019-06-21 02:35:43 +00:00
|
|
|
.n.nlmsg_len = NLMSG_LENGTH(0),
|
|
|
|
#ifdef PDELIV_DEBUG_ACK_COOKIES
|
2019-06-14 09:14:06 +00:00
|
|
|
.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK,
|
2019-06-21 02:35:43 +00:00
|
|
|
#else
|
|
|
|
.n.nlmsg_flags = NLM_F_REQUEST,
|
|
|
|
#endif
|
|
|
|
.n.nlmsg_type = NLMSG_PDELIV_DEBUGFS,
|
2019-06-14 09:14:06 +00:00
|
|
|
.n.nlmsg_pid = getpid(),
|
|
|
|
};
|
2019-06-21 02:35:43 +00:00
|
|
|
|
2019-06-25 06:42:36 +00:00
|
|
|
if( msgtype == NULL )
|
|
|
|
{
|
|
|
|
printf("set_pdeliv_debug_waitack err:input msgtype is NULL.\r\n");
|
|
|
|
return -1;
|
|
|
|
}else
|
|
|
|
{
|
|
|
|
printf("set_pdeliv_debug msgtype %s\r\n",msgtype);
|
|
|
|
}
|
|
|
|
|
|
|
|
debug_len = strlen((const char *)msgtype);
|
2019-06-14 09:14:06 +00:00
|
|
|
|
|
|
|
/*可选属性*/
|
2019-06-25 06:42:36 +00:00
|
|
|
commnl_addattr_l(&req.n, sizeof(req), NLDEBUG_MSG_TYPE, msgtype, debug_len);
|
2019-06-11 03:21:35 +00:00
|
|
|
|
2019-06-14 09:14:06 +00:00
|
|
|
/*发送组装好的netlink消息*/
|
2019-06-26 07:26:25 +00:00
|
|
|
if (pdeliv_talk(0, &req.n, answer) < 0)
|
2019-06-20 03:20:46 +00:00
|
|
|
{
|
2019-06-21 02:35:43 +00:00
|
|
|
printf("set_user_policy_waitack rcv ack msg faild.\r\n");
|
2019-06-14 09:14:06 +00:00
|
|
|
return -2;
|
2019-06-20 03:20:46 +00:00
|
|
|
}
|
2019-06-21 02:35:43 +00:00
|
|
|
else{
|
|
|
|
printf("set_user_policy_waitack rcv ack msg sucess.\r\n");
|
|
|
|
}
|
2019-06-14 09:14:06 +00:00
|
|
|
|
2019-06-21 02:35:43 +00:00
|
|
|
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;
|
2019-06-20 03:20:46 +00:00
|
|
|
}
|
2019-06-21 02:35:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
2019-06-20 03:20:46 +00:00
|
|
|
|
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-25 06:42:36 +00:00
|
|
|
unsigned char* msgtype = NULL;
|
|
|
|
|
|
|
|
printf("pdeliv_debug main begin:\r\n");
|
|
|
|
|
|
|
|
if(argc == 1)
|
|
|
|
{
|
|
|
|
msgtype = (unsigned char*)"18";
|
|
|
|
}
|
|
|
|
else if(argc == 2)
|
|
|
|
{
|
|
|
|
msgtype = (unsigned char*)argv[1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("invalid input msgtype\r\n");
|
|
|
|
}
|
2019-06-11 03:21:35 +00:00
|
|
|
|
2019-06-14 09:14:06 +00:00
|
|
|
/*创建通道*/
|
2019-06-26 07:26:25 +00:00
|
|
|
ret = pdelivnl_open(0);
|
2019-06-14 09:14:06 +00:00
|
|
|
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
|
|
|
/*下发配置到内核态*/
|
2019-06-25 06:42:36 +00:00
|
|
|
ret = set_pdeliv_debug_waitack(msgtype);
|
2019-06-14 09:14:06 +00:00
|
|
|
if(ret < 0)
|
|
|
|
{
|
2019-06-21 02:35:43 +00:00
|
|
|
printf("set_pdeliv_debug_waitack failed.\r\n");
|
2019-06-14 09:14:06 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2019-06-11 03:21:35 +00:00
|
|
|
|
2019-06-14 09:14:06 +00:00
|
|
|
/*关闭netlink通道*/
|
2019-06-26 07:26:25 +00:00
|
|
|
pdelivnl_close(0);
|
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
|
|
|
}
|
|
|
|
|
2019-06-21 09:02:36 +00:00
|
|
|
#endif
|
2019-06-11 03:21:35 +00:00
|
|
|
|