ADD aaa-12 增加配置管理-用户老化时间配置

RCA:
SOL:
修改人:chenling
检视人:
This commit is contained in:
ChenLing 2019-07-04 15:11:22 +08:00
parent 76e0ad8308
commit da4ef8eca1
4 changed files with 286 additions and 0 deletions

View File

@ -85,6 +85,7 @@ enum commcfgmsgtype{
COMMMSGNL_BASE = 0x10,/*netlink 保留控制消息*/ COMMMSGNL_BASE = 0x10,/*netlink 保留控制消息*/
COMMNMSG_CFG_DEBUGFS = 0x11,/*keep the same with NLMSG_PDELIV_DEBUGFS */ COMMNMSG_CFG_DEBUGFS = 0x11,/*keep the same with NLMSG_PDELIV_DEBUGFS */
FREEAUTH_CFG = 0x13, /*用户态发送给内核态的免认证规则消息*/ FREEAUTH_CFG = 0x13, /*用户态发送给内核态的免认证规则消息*/
AGINGTIME_CFG = 0x14, /*用户态发送给内核态的用户老化时间消息 */
COMMNMSG_POLICYCONF, COMMNMSG_POLICYCONF,
NK_DEBUGFS_PRK_ONOFF_CFG = 0X16,/*keep the same with DEBUGFS PRINTK ON OR OFF */ NK_DEBUGFS_PRK_ONOFF_CFG = 0X16,/*keep the same with DEBUGFS PRINTK ON OR OFF */

View File

@ -0,0 +1,238 @@
#include "../include/parsefile.h"
#include "../include/configm.h"
#include "../../../netlink_uapi/libnetlinku.h"
#include "../../../../common/rpc/rpc.h"
#include "../include/agingtime.h"
#include <cjson/cJSON.h>
#include "../../../../../Common/s2j/s2j.h"
#include "../../../../../Common/commuapinl.h"
#ifdef AGINGTIME_ACK_COOKIES
#define CFG_AGINGTIME_ACK_COOKIES
#endif
/*全局变量,存放配置的用户老化时间 */
int *aging_time = NULL;
/*下发用户老化时间配置到内核态 */
int set_agingtimecfg_waitack(int *agingtime)
{
int agingtime_len = 0;
struct nlmsghdr *ack = NULL;
struct nlmsghdr **answer = &ack;
struct{
struct nlmsghdr n;
char buf[1024];
} req ={
.n.nlmsg_len = NLMSG_LENGTH(0),
#ifdef CFG_AGINGTIME_ACK_COOKIES
.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK,/*set NLM_F_ACKuse kernel auto ack*/
#else
.n.nlmsg_flags = NLM_F_REQUEST, /*not use kernel auto ack */
#endif
.n.nlmsg_type = AGINGTIME_CFG, /*用户态发送给内核态的用户老化时间消息 */
.n.nlmsg_pid = getpid(),
};
/*判断要发送的数据是否为NULL,不为NULL,打印出来 */
if (agingtime == NULL)
{
printf("set_agingtimecfg_waitack is error: input struct_agingtime is NULL.\r\n");
return -1;
}else
{
printf("set_freeauthcfg_waitack :agingtime %d\n", *agingtime);
}
/*计算需要发送的数据的长度 */
agingtime_len = sizeof(int);
printf("%d\n", agingtime_len);
/*可选属性 */
commnl_addattr_l(&req.n, sizeof(req), 1, agingtime, agingtime_len);
/*发送组装好的netlink消息 */
if(pdeliv_talk(1, &req.n, answer) < 0)
{
printf("set_user_agingtime_waitack rcv ack msg faild.\r\n");
return -2;
}
else
{
printf("set_user_agingtime_waitack rcv ack msg success.\r\n");
}
if(*answer != NULL)
{
printf("set_user_agingtime_waitack rcv answer.\r\n");
}
else{
printf("set_user_agingtime_waitack rcv answer error.\r\n");
return -3;
}
#ifdef CFG_AGINGTIME_ACK_COOKIES
/*recv answer*/
if((*answer)->nlmsg_type == NLMSG_ERROR){
nl_debugfs_extack(*answer);
}
#else
/*recv answer*/
if((*answer)->nlmsg_type == AGINGTIME_CFG)
{
nl_debugfs(*answer);
}
#endif
return 0;
}
/*判断配置的老化时间是否有效老化时间大于0 */
/*input格式 '{\"type\":0, \"time\":24}' */
ret_code agingtime_config_chk(uint source, uint config_type,
pointer input, int input_len,
pointer output, int *output_len)
{
ret_code ret = RET_OK;
cJSON *cjson, *time, *res;
char * ret_char = NULL;
int * ret_int = NULL;
/*JSON字符串到JSON格式 */
cjson = cJSON_Parse(input);
if(!cjson)
{
ret = RET_INPUTERR;
ASSERT_RET(ret);
return ret;
}
/*获取键值内容 */
time = cJSON_GetObjectItem(cjson , "time");
if(!time)
{
ret = RET_INPUTERR;
ASSERT_RET(ret);
cJSON_Delete(cjson);
return ret;
}
if(time->valueint < 0)
{
ret = RET_ERR;
ASSERT_RET(ret);
return ret;
}
/*创建json对象 */
res = cJSON_CreateObject();
if(!res)
{
ret = RET_ERR;
ASSERT_RET(ret);
return ret;
}
cJSON_AddNumberToObject(res, "time", time->valueint);
/*将json对象转换成json字符串 */
ret_char = cJSON_PrintUnformatted(res);
ret_int = (int*)ret_char;
memcpy(output, ret_int, sizeof(ret_int)+1);
cJSON_Delete(res);
return RET_OK;
}
/*系统管理模块将配置的用户老化时间通过netlink下发到内核态 */
/*输入和输出的参数形式都为JSON字符串 '{"time": 30}' */
ret_code agingtime_config_proc(uint source, uint config_type,
pointer input, int input_len,
pointer output, int *output_len)
{
ret_code ret = RET_OK;
cJSON *cjson, *time, *res;
int * agingtime = NULL;
char * ret_char = NULL;
int * ret_int = NULL;
/*JSON字符串到JSON格式 */
cjson = cJSON_Parse(input);
if(!cjson)
{
ret = RET_INPUTERR;
ASSERT_RET(ret);
return ret;
}
/*获取键值内容 */
time = cJSON_GetObjectItem(cjson , "time");
if(!time)
{
ret = RET_INPUTERR;
ASSERT_RET(ret);
cJSON_Delete(cjson);
return ret;
}
else
{
int a = time->valueint;
agingtime = &a;
}
rpc_log_info("agingtime configure: agingtime %d\n", time->valueint);
/*用户态下发到内核态auth_hook */
int r = -1;
printf("cfgchannel main begin:\r\n");
/*创建通道 */
r = commcfgnl_open();
if(r < 0)
{
printf(" pdlivnl_open fail, exit.\r\n");
return RET_ERR;
}
/*下发配置到内核态 */
r = set_agingtimecfg_waitack(agingtime);
if(r < 0)
{
printf("set_cfg_debug_waitack failed.\r\n");
return RET_ERR;
}
/*关闭netlink通道 */
commcfgnl_close();
printf("cfgchannel main exit!\r\n");
/*创建json对象 */
res = cJSON_CreateObject();
if(!res)
{
ret = RET_ERR;
ASSERT_RET(ret);
return ret;
}
cJSON_AddNumberToObject(res, "result", r);
/*将json对象转换成json字符串 */
ret_char = cJSON_PrintUnformatted(res);
ret_int =(int*)ret_char;
memcpy(output, ret_int, sizeof(ret_int)+1);
cJSON_Delete(res);
/*把免认证规则的配置信息存入全局变量 */
aging_time = agingtime;
return RET_OK;
}

View File

@ -0,0 +1,35 @@
#ifndef AGINGTIME_H_
#define AGINGTIME_H_
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include "../../../../common/rpc/rpc_common.h"
/*判断配置的老化时间是否有效老化时间大于0 */
ret_code agingtime_config_chk(uint source, uint config_type,
pointer input, int input_len,
pointer output, int *output_len);
/*系统管理模块将配置的用户老化时间通过netlink下发到内核态 */
ret_code agingtime_config_proc(uint source, uint config_type,
pointer input, int input_len,
pointer output, int *output_len);
ret_code agingtime_config_get(uint source,
pointer input, int input_len,
pointer output, int *output_len);
ret_code agingtime_config_get_all(uint source, uint64 config_id,
pointer output, short *single_len,
int *cnt);
#endif

View File

@ -9,6 +9,7 @@
#include "localportal.h" #include "localportal.h"
#include "jumppage.h" #include "jumppage.h"
#include "userlock.h" #include "userlock.h"
#include "agingtime.h"
/* 类型定义 */ /* 类型定义 */
@ -32,6 +33,7 @@
#define AUTHFREE_CONFIG (uint64)((uint64)LOCALAUTH_CONFIG_MODULE<<32|2) #define AUTHFREE_CONFIG (uint64)((uint64)LOCALAUTH_CONFIG_MODULE<<32|2)
#define USERLOCK_CONFIG (uint64)((uint64)LOCALAUTH_CONFIG_MODULE<<32|3) #define USERLOCK_CONFIG (uint64)((uint64)LOCALAUTH_CONFIG_MODULE<<32|3)
#define JUMPPAGE_CONFIG (uint64)((uint64)LOCALAUTH_CONFIG_MODULE<<32|4) #define JUMPPAGE_CONFIG (uint64)((uint64)LOCALAUTH_CONFIG_MODULE<<32|4)
#define AGINGTIME_CONFIG (uint64)((uint64)LOCALAUTH_CONFIG_MODULE<<32|5)
/* /*
@ -106,6 +108,16 @@
jumppage_config_proc, \ jumppage_config_proc, \
NULL, \ NULL, \
NULL \ NULL \
}, \
{\
AGINGTIME_CONFIG, \
CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \
FALSE, \
FALSE, \
agingtime_config_chk, \
agingtime_config_proc, \
agingtime_config_get, \
agingtime_config_get_all \
} \ } \
\ \
} }