Mod aaa-12 aync interface has been debuged finally
RCA: SOL: 修改人:zhangtao 检视人:zhangtao
This commit is contained in:
parent
c22ad8f5d9
commit
bb0011b4d5
|
@ -48,6 +48,9 @@ enum pdelivmsgtype{
|
|||
NLMSG_PDELIV_DEBUGFS = 0x11, /*用户态发送给内核态的请求消息,用于查看pdiliv模块本身的状态及配置,与业务无关*/
|
||||
NLMSG_RECV_RAW_PKT = 0x12,/*上送DPI的报文消息*/
|
||||
PDNLGRP_REQUEST,
|
||||
/*for trace*/
|
||||
TRACE_CFG_POLICY_REQ = 0x20,
|
||||
TRACE_CFG_POLICY_REPLY,
|
||||
NLMGS_PDELIVERY_MAX_TYPE,
|
||||
};
|
||||
|
||||
|
@ -78,9 +81,7 @@ enum commcfgmsgtype{
|
|||
COMMMSGNL_BASE = 0x10,/*netlink 保留控制消息*/
|
||||
COMMNMSG_CFG_DEBUGFS = 0x11,/*keep the same with NLMSG_PDELIV_DEBUGFS */
|
||||
COMMNMSG_POLICYCONF,
|
||||
/*for trace*/
|
||||
TRACE_CFG_POLICY = 0x20,
|
||||
TRACE_CFG_MAX = 0X25,
|
||||
|
||||
/*add your msg type here:*/
|
||||
|
||||
/*commcfg nsmsg max type,must :add your msg type before this */
|
||||
|
|
|
@ -35,7 +35,7 @@ PLAT_LINUX_SRCS = $(COMMON_SRCS)
|
|||
PLAT_ARM64_SRCS = $(COMMON_SRCS)
|
||||
|
||||
# gcc CFLAGS
|
||||
PLAT_ARM64_CFLAGS := -I../modules/netlink_api/ -I../modules/cfgrcv -I../modules/conntrack_api/api/ -I../../Common -I../common/trace
|
||||
PLAT_ARM64_CFLAGS := -I../modules/netlink_api/ -I../modules/pdelivery -I../modules/conntrack_api/api/ -I../../Common -I../common/trace
|
||||
PLAT_LINUX_CFLAGS := $(PLAT_ARM64_CFLAGS)
|
||||
|
||||
# this line must be at below of thus, because of...
|
||||
|
|
|
@ -9,8 +9,9 @@ typedef enum {
|
|||
} reply_op_t;
|
||||
|
||||
enum {
|
||||
TRACE_MSG_POLICY_REQ = 0x0,
|
||||
TRACE_MSG_POLICY_REQ = 0x0/*,
|
||||
TRACE_MSG_POLICY_REPLY
|
||||
*/
|
||||
};
|
||||
|
||||
typedef struct _trace_hdr {
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
#include <net/netlink.h>
|
||||
|
||||
#include "trace_def.h"
|
||||
#include "../netlink_api/libnetlink_k.h"
|
||||
#include "libnetlink_k.h"
|
||||
#include "trace_msg.h"
|
||||
#include "commuapinl.h"
|
||||
#include "conntrack_api.h"
|
||||
#include "cfgrcv_kinit.h"
|
||||
#include "pdeliverynl_kinit.h"
|
||||
|
||||
|
||||
|
||||
|
@ -37,7 +37,7 @@ static int trace_rcv_policy(struct sk_buff *skb, struct nlmsghdr *nlh, struct ne
|
|||
|
||||
printk(KERN_INFO "Trace recv policy, msg_type:%u", nlh->nlmsg_type);
|
||||
switch (nlh->nlmsg_type) {
|
||||
case TRACE_CFG_POLICY:
|
||||
case TRACE_CFG_POLICY_REQ:
|
||||
buf = nlmsg_data(nlh);
|
||||
if (buf == NULL) {
|
||||
printk(KERN_ERR"Receiving data is null");
|
||||
|
@ -104,7 +104,7 @@ static int trace_rcv_policy(struct sk_buff *skb, struct nlmsghdr *nlh, struct ne
|
|||
printk(KERN_ERR"Allocating skb memory is failure");
|
||||
goto FAIL;
|
||||
}
|
||||
reply_hdr = nlmsg_put(reply_skb, 0, 0, TRACE_MSG_POLICY_REPLY, TRACE_REPLY_SZ, 0);
|
||||
reply_hdr = nlmsg_put(reply_skb, 0, 0, TRACE_CFG_POLICY_REPLY, TRACE_REPLY_SZ, 0);
|
||||
if (reply_hdr == NULL) {
|
||||
printk(KERN_ERR"Putting length of reply is failure");
|
||||
goto FAIL;
|
||||
|
@ -117,14 +117,16 @@ static int trace_rcv_policy(struct sk_buff *skb, struct nlmsghdr *nlh, struct ne
|
|||
reply = (trace_reply_t *)reply_data;
|
||||
memcpy(&reply->hdr, hdr, sizeof(*hdr));
|
||||
reply->result = ret;
|
||||
|
||||
reply_ret = cfgnl_unicast(reply_skb, nlh->nlmsg_pid);
|
||||
|
||||
reply_ret = pdeliv_unicast(reply_skb, nlh->nlmsg_pid);
|
||||
if (reply_ret != 0) {
|
||||
printk(KERN_ERR"Reply message is failure");
|
||||
goto FAIL;
|
||||
}
|
||||
|
||||
nlmsg_free(reply_skb);
|
||||
printk(KERN_INFO"Reply message final");
|
||||
|
||||
//nlmsg_free(reply_skb);
|
||||
return 0;
|
||||
|
||||
FAIL:
|
||||
|
@ -138,14 +140,14 @@ FAIL:
|
|||
static int __init trace_init(void)
|
||||
{
|
||||
printk(KERN_INFO"Trace is initiating");
|
||||
cfg_msgtype_register(TRACE_CFG_POLICY, trace_rcv_policy, NULL, NULL);
|
||||
pdeliv_msgtype_register(TRACE_CFG_POLICY_REQ, trace_rcv_policy, NULL, NULL);
|
||||
printk(KERN_INFO"Trace is initiated");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void __exit trace_exit(void)
|
||||
{
|
||||
cfg_msgtype_unregister(TRACE_CFG_POLICY);
|
||||
pdeliv_msgtype_unregister(TRACE_CFG_POLICY_REQ);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,8 @@
|
|||
|
||||
#define SESS_HASH_INDEX(seq) (seq >> HASH_SESS_TAB_BITS)
|
||||
|
||||
#define NETLINK_GROUP_TRACE_ID 0
|
||||
|
||||
typedef struct _cb_arg {
|
||||
struct hlist_node node;
|
||||
uint32_t seq;
|
||||
|
@ -97,50 +99,68 @@ END:
|
|||
return ret;
|
||||
}
|
||||
|
||||
static void *cb_thread(void *arg)
|
||||
static trace_ret_t msg_handle(const trace_reply_t *msg)
|
||||
{
|
||||
ssize_t size;
|
||||
trace_reply_t msg;
|
||||
|
||||
return NULL; // todo
|
||||
|
||||
while(1) {
|
||||
if (g_client_stop) {
|
||||
SYSLOG_INFO("Callback thread is stopping");
|
||||
break;
|
||||
}
|
||||
|
||||
// todo 需要考虑长期没收到消息,hash怎么清除数据
|
||||
// size = msgrcv(g_client_msgid, &msg, sizeof(msg.mtext), g_pid, MSG_NOERROR | IPC_NOWAIT);
|
||||
if ((size == -1)/* || (size != sizeof(msg.mtext))*/) {
|
||||
if ((errno != ENOMSG)) {
|
||||
printf("msg queue receive is failure:%d\n", errno);
|
||||
}
|
||||
|
||||
// usleep(SLEEP_THREAD_TIME); //防止CPU占用过高,睡眠一会儿,让出CPU todo
|
||||
continue;
|
||||
}
|
||||
|
||||
cb_arg_t *cb_arg = NULL;
|
||||
if (get_and_del_arg_from_hlist(msg.hdr.seq, &cb_arg) == TRACE_FAILURE) {
|
||||
SYSLOG_ERR("Get arg is failure");
|
||||
break;
|
||||
}
|
||||
|
||||
if (cb_arg == NULL) {
|
||||
SYSLOG_INFO("The seq:[%u] is not found", msg.hdr.seq);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (cb_arg->cb != NULL) {
|
||||
SYSLOG_DEBUG("Execute callback of seq:[%u]", msg.hdr.seq);
|
||||
cb_arg->cb(msg.result, cb_arg->arg);
|
||||
} else {
|
||||
SYSLOG_DEBUG("The callback of seq:[%u] is not set", msg.hdr.seq);
|
||||
}
|
||||
free(cb_arg);
|
||||
cb_arg_t *cb_arg = NULL;
|
||||
if (get_and_del_arg_from_hlist(msg->hdr.seq, &cb_arg) == TRACE_FAILURE) {
|
||||
SYSLOG_ERR("Get arg is failure");
|
||||
return TRACE_FAILURE;
|
||||
}
|
||||
|
||||
if (cb_arg == NULL) {
|
||||
SYSLOG_INFO("The seq:[%u] is not found", msg->hdr.seq);
|
||||
return TRACE_FAILURE;
|
||||
}
|
||||
|
||||
if (cb_arg->cb != NULL) {
|
||||
SYSLOG_DEBUG("Execute callback of seq:[%u]", msg->hdr.seq);
|
||||
cb_arg->cb(msg->result, cb_arg->arg);
|
||||
} else {
|
||||
SYSLOG_DEBUG("The callback of seq:[%u] is not set", msg->hdr.seq);
|
||||
}
|
||||
free(cb_arg);
|
||||
|
||||
return TRACE_SUCCESS;
|
||||
}
|
||||
|
||||
static int trace_recv_handle(struct pdelivnl_ctrl_data *ctrl,
|
||||
struct nlmsghdr *n, void *arg)
|
||||
{
|
||||
trace_reply_t *reply;
|
||||
trace_ret_t ret;
|
||||
|
||||
SYSLOG_INFO("Trace receives reply message, msg_type:%u", n->nlmsg_type);
|
||||
switch (n->nlmsg_type) {
|
||||
case TRACE_CFG_POLICY_REPLY:
|
||||
reply = (trace_reply_t *)NLMSG_DATA(n);
|
||||
if (sizeof(*reply) < (n->nlmsg_len - NLMSG_HDRLEN)) {
|
||||
SYSLOG_WARN("The length of the reply message is required to be %u, but fact length is %u",
|
||||
sizeof(*reply), (n->nlmsg_len - NLMSG_HDRLEN));
|
||||
break;
|
||||
}
|
||||
ret = msg_handle(reply);
|
||||
if (ret != TRACE_SUCCESS) {
|
||||
SYSLOG_ERR("Processing message is fail");
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
SYSLOG_WARN("Unknown type:%u of the message is received from netlink", n->nlmsg_type);
|
||||
break;
|
||||
}
|
||||
|
||||
SYSLOG_INFO("Reply message of trace finalizes, msg_type:%u", n->nlmsg_type);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void *cb_thread(void *arg)
|
||||
{
|
||||
SYSLOG_INFO("Callback thread is started");
|
||||
|
||||
pdelivnl_listen(NETLINK_GROUP_TRACE_ID, trace_recv_handle, NULL);
|
||||
|
||||
SYSLOG_INFO("Callback thread is stopped");
|
||||
return NULL;
|
||||
}
|
||||
|
@ -153,12 +173,13 @@ static trace_ret_t cfg_channel_send(const uint32_t seq, const trace_policy_t *p
|
|||
|
||||
hdr->nlmsg_len = NLMSG_HDRLEN;
|
||||
hdr->nlmsg_flags = NLM_F_REQUEST /* | NLM_F_ACK */;
|
||||
hdr->nlmsg_type = TRACE_CFG_POLICY;
|
||||
hdr->nlmsg_type = TRACE_CFG_POLICY_REQ;
|
||||
hdr->nlmsg_pid = getpid();
|
||||
|
||||
trace_req_t req;
|
||||
req.hdr.ver = 1;
|
||||
req.hdr.seq = seq;
|
||||
req.hdr.is_reply = is_reply;
|
||||
memcpy(&req.policy, policy, sizeof(*policy));
|
||||
|
||||
commnl_addattr_l(hdr, sizeof(buf), TRACE_MSG_POLICY_REQ, &req, sizeof(trace_req_t));
|
||||
|
@ -172,7 +193,8 @@ static trace_ret_t cfg_channel_send(const uint32_t seq, const trace_policy_t *p
|
|||
SYSLOG_DEBUG(" protocol:%u, app_type:%u", req.policy.protocol, req.policy.app_type);
|
||||
|
||||
/*发送组装好的netlink消息*/
|
||||
if (commcfg_send(hdr) < 0) {
|
||||
//if (commcfg_send(hdr) < 0) {
|
||||
if (pdelivnl_send(NETLINK_GROUP_TRACE_ID, hdr) < 0) {
|
||||
SYSLOG_ERR("Message(seq:%u) which been sent is failure", seq);
|
||||
return TRACE_FAILURE;
|
||||
}
|
||||
|
@ -185,7 +207,7 @@ static trace_ret_t cfg_channel_send(const uint32_t seq, const trace_policy_t *p
|
|||
static void cfg_channel_close()
|
||||
{
|
||||
if (g_channel_open >= 0) {
|
||||
commcfgnl_close();
|
||||
pdelivnl_close(NETLINK_GROUP_TRACE_ID);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -207,7 +229,8 @@ trace_ret_t trace_client_init()
|
|||
}
|
||||
}
|
||||
|
||||
g_channel_open = commcfgnl_open();
|
||||
//g_channel_open = commcfgnl_open();
|
||||
g_channel_open = pdelivnl_open(NETLINK_GROUP_TRACE_ID);
|
||||
if(g_channel_open < 0)
|
||||
{
|
||||
SYSLOG_ERR("pdelivnl_open fail:%d", g_channel_open);
|
||||
|
@ -347,6 +370,7 @@ static trace_ret_t __trace_async_exec(const trace_policy_t *in,
|
|||
}
|
||||
|
||||
is_reply = REPLY_OP_NEED;
|
||||
SYSLOG_DEBUG("Need reply:%u from kernel", is_reply);
|
||||
}
|
||||
|
||||
ret = cfg_channel_send(seq, in, is_reply);
|
||||
|
|
Loading…
Reference in New Issue