Merge branch 'master' of http://git.komect.net/ISG/secogateway
This commit is contained in:
commit
a08b3e8b2a
|
@ -42,12 +42,16 @@ enum pdeliverynetlink_groups {
|
|||
|
||||
#define COMMLIBNLGRP_MAX 16 /*支持的最大组数量*/
|
||||
|
||||
#define DEBUGFS_PRK_ONOFF 0
|
||||
|
||||
/*netlink pdelivery msg type*/
|
||||
enum pdelivmsgtype{
|
||||
PDNL_BASE = 0x10,/*netlink 保留控制消息*/
|
||||
NLMSG_PDELIV_DEBUGFS = 0x11, /*用户态发送给内核态的请求消息,用于查看pdiliv模块本身的状态及配置,与业务无关*/
|
||||
NLMSG_RECV_RAW_PKT = 0x12,/*上送DPI的报文消息*/
|
||||
PDNLGRP_REQUEST,
|
||||
NK_DEBUGFS_PRK_ONOFF = 0X16,/*DEBUGFS PRINTK ON 0R OFF: 1->ON; 0->OFF */
|
||||
|
||||
/*for trace*/
|
||||
TRACE_CFG_POLICY_REQ = 0x20,
|
||||
TRACE_CFG_POLICY_REPLY,
|
||||
|
@ -80,8 +84,11 @@ enum commcfgmsgtype{
|
|||
//COMMMSGNL_BASE = NLMSG_MIN_TYPE,/*netlink 保留控制消息*/
|
||||
COMMMSGNL_BASE = 0x10,/*netlink 保留控制消息*/
|
||||
COMMNMSG_CFG_DEBUGFS = 0x11,/*keep the same with NLMSG_PDELIV_DEBUGFS */
|
||||
FREEAUTH_CFG = 0x13, /*用户态发送给内核态的免认证规则消息*/
|
||||
COMMNMSG_POLICYCONF,
|
||||
|
||||
NK_DEBUGFS_PRK_ONOFF_CFG = 0X16,/*keep the same with DEBUGFS PRINTK ON OR OFF */
|
||||
|
||||
/*add your msg type here:*/
|
||||
|
||||
/*commcfg nsmsg max type,must :add your msg type before this */
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
/* This file is auto generated,for sGATE version info */
|
||||
/* Used readelf to get this information form driver of application */
|
||||
/* "readelf --debug-dump=macro <filename>" */
|
||||
#define sGATE_COMPILE_DATE "2019-06-19"
|
||||
#define sGATE_COMPILE_TIME "14:18:13"
|
||||
#define sGATE_COMPILE_MAJOR "20190619"
|
||||
#define sGATE_COMPILE_SUB "141813"
|
||||
#define sGATE_COMPILE_BY "hx"
|
||||
#define sGATE_COMPILE_DATE "2019-07-01"
|
||||
#define sGATE_COMPILE_TIME "17:53:10"
|
||||
#define sGATE_COMPILE_MAJOR "20190701"
|
||||
#define sGATE_COMPILE_SUB "175310"
|
||||
#define sGATE_COMPILE_BY "cl"
|
||||
#define sGATE_COMPILE_HOST "esgwdev01"
|
||||
#define sGATE_GIT_TAGS "c0ad51e6f-dev"
|
||||
#define sGATE_GIT_VERS "c0ad51e6f27589e51268ec92a14ee1cb701a2d5f"
|
||||
#define sGATE_GIT_TAGS "aaa812c65-dev"
|
||||
#define sGATE_GIT_VERS "aaa812c654225f595f12a32bc7d56bcc225f3ee4"
|
||||
|
|
|
@ -81,8 +81,30 @@ extern "C" {
|
|||
S2J_STRUCT_GET_STRUCT_ELEMENT(child_struct, to_struct, child_json, from_json, type, element)
|
||||
|
||||
/* s2j.c */
|
||||
extern S2jHook s2jHook;
|
||||
void s2j_init(S2jHook *hook);
|
||||
//extern S2jHook s2jHook;
|
||||
S2jHook s2jHook = {
|
||||
.malloc_fn = malloc,
|
||||
.free_fn = free,
|
||||
};
|
||||
|
||||
static void s2j_init(S2jHook *hook)
|
||||
{
|
||||
/* initialize cJSON library */
|
||||
if(hook == NULL)
|
||||
{
|
||||
hook = &s2jHook;
|
||||
}
|
||||
|
||||
cJSON_InitHooks((cJSON_Hooks *)hook);
|
||||
/* initialize hooks */
|
||||
if (hook) {
|
||||
s2jHook.malloc_fn = (hook->malloc_fn) ? hook->malloc_fn : malloc;
|
||||
s2jHook.free_fn = (hook->free_fn) ? hook->free_fn : free;
|
||||
} else {
|
||||
s2jHook.malloc_fn = malloc;
|
||||
s2jHook.free_fn = free;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
1
Makefile
1
Makefile
|
@ -138,6 +138,7 @@ else
|
|||
$(MLOG)make all $(MAKE_FLAGS) -C Platform/build -f user.configmtest.Makefile MLOG=$(MLOG) DISABLE_WARRING=$(DIS_BUILD_WARRING) MAKE_TARGET=configmtest
|
||||
endif
|
||||
|
||||
|
||||
redismq:
|
||||
ifeq ($(OPT), clean)
|
||||
$(MLOG)make $(MAKE_FLAGS) -C Platform/build -f user.redismq.Makefile cleanall MLOG=$(MLOG) MAKE_TARGET=redismq
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
|
||||
# target name, the target name must have the same name of c source file
|
||||
TARGET_NAME=authfree
|
||||
|
||||
# target
|
||||
# for linux module driver: KO
|
||||
# for application: EXE
|
||||
# for dynamic library: DLL
|
||||
TARGET_TYPE = EXE
|
||||
|
||||
# target object
|
||||
# for application: APP
|
||||
# for device driver: DRV
|
||||
TARGET_OBJ = APP
|
||||
|
||||
# custom install dir
|
||||
TARGET_BOX =
|
||||
|
||||
#debug mode or release mode
|
||||
DEBUG = TRUE
|
||||
|
||||
PLAT_LINUX ?= TRUE
|
||||
PLAT_ARM64 ?= FALSE
|
||||
|
||||
VPATH = ../user/configm/config-server/authfree_config/
|
||||
|
||||
# source code
|
||||
|
||||
# set the source file, don't used .o because of ...
|
||||
|
||||
COMMON_SRCS = authfree.c
|
||||
|
||||
# MRS Board Source Files
|
||||
PLAT_LINUX_SRCS = $(COMMON_SRCS)
|
||||
PLAT_ARM64_SRCS = $(COMMON_SRCS)
|
||||
|
||||
# gcc CFLAGS
|
||||
PLAT_ARM64_CFLAGS := -I../user/configm/config-server/include -I../../Common -I../common/configm -I../common/rpc -I../common/rpc/hashtable
|
||||
PLAT_LINUX_CFLAGS := $(PLAT_ARM64_CFLAGS)
|
||||
|
||||
|
||||
PLAT_ARM64_LDFLAGS :=
|
||||
PLAT_LINUX_LDFLAGS :=
|
||||
|
||||
#gcc libs
|
||||
ARM64_LIBS := -lcjson ../thirdparty/arm64/libev-arm64.so ./libopenrpc-arm64.so ./libnetlinku-arm64.so -lpthread -lm
|
||||
LINUX_LIBS := -lcjson ../thirdparty/x86_64/libev-linux.so ./libopenrpc-linux.so ./libnetlinku-linux.so -lpthread -lm
|
||||
|
||||
ifeq ($(PLAT_ARM64), TRUE)
|
||||
DEPEND_LIB += ../thirdparty/arm64/libev-arm64.so ./debug/libopenrpc-arm64.so
|
||||
USER_CLEAN_ITEMS += ./libopenrpc-arm64.so
|
||||
endif
|
||||
|
||||
ifeq ($(PLAT_LINUX), TRUE)
|
||||
DEPEND_LIB += ../thirdparty/x86_64/libev-linux.so ./debug/libopenrpc-linux.so
|
||||
USER_CLEAN_ITEMS += ./libopenrpc-linux.so
|
||||
endif
|
||||
|
||||
|
||||
# this line must be at below of thus, because of...
|
||||
include ../../Common/common.Makefile
|
||||
|
||||
ifneq ($(MAKECMDGOALS), clean)
|
||||
ifneq ($(MAKECMDGOALS), cleanall)
|
||||
ifneq ($(notdir $(DEPEND_LIB)), $(wildcard $(DEPEND_LIB)))
|
||||
$(shell $(CP) $(DEPEND_LIB) ./)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(MAKECMDGOALS), )
|
||||
$(shell find ./ -name "$(TARGET)-*.ko" -delete)
|
||||
else
|
||||
ifeq ($(MAKECMDGOALS), all)
|
||||
$(shell find ./ -name "$(TARGET)-*.ko" -delete)
|
||||
endif
|
||||
endif
|
||||
|
Binary file not shown.
|
@ -1,7 +1,7 @@
|
|||
#ifndef CONFIGMAPI_H_
|
||||
#define CONFIGMAPI_H_
|
||||
|
||||
#include "rpc_common.h"
|
||||
#include "../rpc/rpc_common.h"
|
||||
|
||||
#define CONFIG_FROM_WEB 0x00000001
|
||||
#define CONFIG_FROM_NETOPEER 0x00000010
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#define RPC_CONN_H_
|
||||
|
||||
#include "rpc_common.h"
|
||||
#include <ev.h>
|
||||
#include "ev.h"
|
||||
|
||||
struct _rpc_conn {
|
||||
int sfd;
|
||||
|
|
|
@ -158,8 +158,8 @@ int cfgrcv_debugfs(struct sk_buff *skb, struct nlmsghdr *nlh,struct netlink_ext_
|
|||
{
|
||||
int ret = 0;
|
||||
|
||||
printk(KERN_INFO "cfgrcv_debugfs, From pid: %d\n", nlh->nlmsg_pid);
|
||||
|
||||
NETLINK_DEBUG(g_upmnlcfg.debugfs_prk_enable, "cfgrcv_debugfs, From pid: %d\n", nlh->nlmsg_pid);
|
||||
/*
|
||||
#ifdef NLDEBUG_ACK_COOKIES
|
||||
ret = debugfs_pkt_num_stati(&g_upmnlcfg, nlh,extack);
|
||||
#else
|
||||
|
@ -168,7 +168,34 @@ int cfgrcv_debugfs(struct sk_buff *skb, struct nlmsghdr *nlh,struct netlink_ext_
|
|||
|
||||
printk("*****************biduichengong***************\n");
|
||||
return ret;
|
||||
*/
|
||||
switch(nlh->nlmsg_type)
|
||||
{
|
||||
//case COMMNMSG_POLICYCONF:/**/
|
||||
case NLMSG_PDELIV_DEBUGFS:
|
||||
|
||||
#ifdef NLDEBUG_ACK_COOKIES
|
||||
ret = debugfs_pkt_num_stati(&g_upmnlcfg, nlh,extack);
|
||||
#else
|
||||
ret = debugfs_pkt_num_stati_witisend(&g_upmnlcfg, nlh,cfgnl_msg_handlers);
|
||||
#endif
|
||||
|
||||
NETLINK_DEBUG(g_upmnlcfg.debugfs_prk_enable, "*****************biduichengong********%d*******\n", nlh->nlmsg_type);
|
||||
|
||||
return ret;
|
||||
break;
|
||||
case NK_DEBUGFS_PRK_ONOFF:
|
||||
ret = debugfs_prk_onoff(&g_upmnlcfg, nlh, extack);
|
||||
return ret;
|
||||
break;
|
||||
|
||||
default:
|
||||
NETLINK_DEBUG(g_upmnlcfg.debugfs_prk_enable, "libnetlink Unknow msgtype recieved!\n");
|
||||
return 0;
|
||||
}
|
||||
/**************************************************************************************************************/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cfg_msgtype_register( int msgtype,commnl_doit_func doit,
|
||||
|
@ -226,6 +253,7 @@ int __init cfgrcv_init(void)
|
|||
|
||||
/*do msg process register*/
|
||||
ret = cfg_msgtype_register(COMMNMSG_CFG_DEBUGFS,cfgrcv_debugfs,NULL,NULL);
|
||||
ret = cfg_msgtype_register(NK_DEBUGFS_PRK_ONOFF,cfgrcv_debugfs,NULL,NULL);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -148,19 +148,29 @@ int commnl_unicast(struct sock *sk, struct sk_buff *skb, u32 portid)
|
|||
return err;
|
||||
}
|
||||
|
||||
|
||||
int debugfs_pkt_num_stati(struct netlinkk_cfg *g_nlcfg, struct nlmsghdr *nlh,struct netlink_ext_ack *extack)
|
||||
int debugfs_prk_onoff(struct netlinkk_cfg *g_nlcfg, struct nlmsghdr *nlh,struct netlink_ext_ack *extack)
|
||||
{
|
||||
unsigned char * cookies = "test cookies";
|
||||
int len = 0;
|
||||
|
||||
printk("debugfs_pkt_num_stati.\r\n");
|
||||
char *pload;
|
||||
struct nlattr *rta;
|
||||
char* load;
|
||||
unsigned long fk_type;
|
||||
|
||||
pload = nlmsg_data(nlh);
|
||||
rta = (struct nlattr *)pload;
|
||||
load = RTA_DATA(rta);
|
||||
strict_strtoul(load, 10, &fk_type);
|
||||
g_nlcfg->debugfs_prk_enable = fk_type;
|
||||
|
||||
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, "***gift***%s", __func__);
|
||||
|
||||
len = strlen(cookies);
|
||||
|
||||
if(len > sizeof(extack->cookie) )/*check len*/
|
||||
{
|
||||
printk("debugfs_pkt_num_stati:cookies oversize the netlinkt cookies.\r\n");
|
||||
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, "debugfs_pkt_num_stati:cookies oversize the netlinkt cookies.\r\n");
|
||||
extack->cookie_len = sizeof(extack->cookie);
|
||||
}
|
||||
else
|
||||
|
@ -170,7 +180,35 @@ int debugfs_pkt_num_stati(struct netlinkk_cfg *g_nlcfg, struct nlmsghdr *nlh,str
|
|||
|
||||
memcpy(extack->cookie, cookies, extack->cookie_len);/*becare:size must small than 20 u8!!!!!!!!!!*/
|
||||
|
||||
printk("------------------debugfs_pkt_num_stati ack type=%d,seq=%d,extack->cookie_len=%d.\n",
|
||||
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, "-debugfs_pkt_num_stati ack type=%d,seq=%d,extack->cookie_len=%d.\n",
|
||||
nlh->nlmsg_type,nlh->nlmsg_seq,extack->cookie_len);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int debugfs_pkt_num_stati(struct netlinkk_cfg *g_nlcfg, struct nlmsghdr *nlh,struct netlink_ext_ack *extack)
|
||||
{
|
||||
unsigned char * cookies = "test cookies";
|
||||
int len = 0;
|
||||
|
||||
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, "debugfs_pkt_num_stati.\r\n");
|
||||
|
||||
len = strlen(cookies);
|
||||
|
||||
if(len > sizeof(extack->cookie) )/*check len*/
|
||||
{
|
||||
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, "debugfs_pkt_num_stati:cookies oversize the netlinkt cookies.\r\n");
|
||||
extack->cookie_len = sizeof(extack->cookie);
|
||||
}
|
||||
else
|
||||
{
|
||||
extack->cookie_len = len;
|
||||
}
|
||||
|
||||
memcpy(extack->cookie, cookies, extack->cookie_len);/*becare:size must small than 20 u8!!!!!!!!!!*/
|
||||
|
||||
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, "-debugfs_pkt_num_stati ack type=%d,seq=%d,extack->cookie_len=%d.\n",
|
||||
nlh->nlmsg_type,nlh->nlmsg_seq,extack->cookie_len);
|
||||
|
||||
return 0;
|
||||
|
@ -193,10 +231,10 @@ int debugfs_pkt_num_stati_witisend(struct netlinkk_cfg *g_nlcfg,
|
|||
rta = (struct nlattr *)pload;
|
||||
load = RTA_DATA(rta);
|
||||
|
||||
printk("***************************rta->nla_type=%d********************\n", rta->nla_type); //nla_type
|
||||
printk("**************************load=*****%s**********\n",(char *)load); //string printf
|
||||
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, "*******rta->nla_type=%d*********\n", rta->nla_type); //nla_type
|
||||
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, "*******load=*****%s**********\n",(char *)load); //string printf
|
||||
strict_strtoul(load, 10, &fk_type);
|
||||
printk("***************************fk_type%lu********************\n", fk_type);
|
||||
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, "*******fk_type%lu********************\n", fk_type);
|
||||
|
||||
|
||||
out_skb = nlmsg_new(2*length, GFP_KERNEL);
|
||||
|
@ -214,27 +252,27 @@ int debugfs_pkt_num_stati_witisend(struct netlinkk_cfg *g_nlcfg,
|
|||
memcpy(nlmsg_data(out_nlh)+length, tmp_dfs, length);
|
||||
|
||||
#if 1
|
||||
printk("netlink total msg stats:\r\n");
|
||||
printk(" rev_total = %d\n",g_nlcfg->dfs.rev_total);
|
||||
printk(" rev_cb_sucess = %d\n",g_nlcfg->dfs.rev_cb_sucess);
|
||||
printk(" rev_cb_fail = %d\n",g_nlcfg->dfs.rev_cb_fail);
|
||||
printk(" rev_drop_total = %d\n",g_nlcfg->dfs.rev_drop_total);
|
||||
printk(" rev_drop_nodoit = %d\n",g_nlcfg->dfs.rev_drop_nodoit);
|
||||
printk(" send_succ = %d\n",g_nlcfg->dfs.send_succ);
|
||||
printk(" send_fail = %d\n",g_nlcfg->dfs.send_fail);
|
||||
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, " netlink total msg stats:\r\n");
|
||||
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, " rev_total = %d\n",g_nlcfg->dfs.rev_total);
|
||||
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, " rev_cb_sucess = %d\n",g_nlcfg->dfs.rev_cb_sucess);
|
||||
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, " rev_cb_fail = %d\n",g_nlcfg->dfs.rev_cb_fail);
|
||||
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, " rev_drop_total = %d\n",g_nlcfg->dfs.rev_drop_total);
|
||||
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, " rev_drop_nodoit = %d\n",g_nlcfg->dfs.rev_drop_nodoit);
|
||||
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, " send_succ = %d\n",g_nlcfg->dfs.send_succ);
|
||||
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, " send_fail = %d\n",g_nlcfg->dfs.send_fail);
|
||||
|
||||
printk("netlink msg stats:\r\n");
|
||||
printk(" rev_total = %d\n",tmp_dfs->rev_total);
|
||||
printk(" rev_cb_sucess = %d\n",tmp_dfs->rev_cb_sucess);
|
||||
printk(" rev_cb_fail = %d\n",tmp_dfs->rev_cb_fail);
|
||||
printk(" rev_drop_total = %d\n",tmp_dfs->rev_drop_total);
|
||||
printk(" rev_drop_nodoit = %d\n",tmp_dfs->rev_drop_nodoit);
|
||||
printk(" send_succ = %d\n",tmp_dfs->send_succ);
|
||||
printk(" send_fail = %d\n",tmp_dfs->send_fail);
|
||||
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, " netlink msg stats:\r\n");
|
||||
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, " rev_total = %d\n",tmp_dfs->rev_total);
|
||||
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, " rev_cb_sucess = %d\n",tmp_dfs->rev_cb_sucess);
|
||||
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, " rev_cb_fail = %d\n",tmp_dfs->rev_cb_fail);
|
||||
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, " rev_drop_total = %d\n",tmp_dfs->rev_drop_total);
|
||||
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, " rev_drop_nodoit = %d\n",tmp_dfs->rev_drop_nodoit);
|
||||
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, " send_succ = %d\n",tmp_dfs->send_succ);
|
||||
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, " send_fail = %d\n",tmp_dfs->send_fail);
|
||||
|
||||
#endif
|
||||
|
||||
printk("------------------debugfs_pkt_num_stati ack msg_type %d,seq=%d!\n",out_nlh->nlmsg_type,nlh->nlmsg_seq);
|
||||
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, "------------------debugfs_pkt_num_stati ack msg_type %d,seq=%d!\n",out_nlh->nlmsg_type,nlh->nlmsg_seq);
|
||||
err = commnl_unicast(g_nlcfg->sk, out_skb, nlh->nlmsg_pid);
|
||||
if (err > 0)
|
||||
{
|
||||
|
@ -252,7 +290,7 @@ failure:
|
|||
//kfree_skb(out_skb);
|
||||
}
|
||||
|
||||
printk(KERN_INFO " failed in fun dataready!\n");
|
||||
NETLINK_DEBUG(g_nlcfg->debugfs_prk_enable, " failed in fun dataready!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -284,6 +322,7 @@ EXPORT_SYMBOL_GPL(printk_ipaddress);
|
|||
EXPORT_SYMBOL_GPL(debugfs_pkt_num_stati);
|
||||
EXPORT_SYMBOL_GPL(debugfs_pkt_num_stati_witisend);
|
||||
EXPORT_SYMBOL_GPL(nf_nlmsg_multicast);
|
||||
EXPORT_SYMBOL_GPL(debugfs_prk_onoff);
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -11,6 +11,9 @@
|
|||
#include <net/net_namespace.h>
|
||||
#include "../../../Common/commuapinl.h"
|
||||
|
||||
#define NETLINK_DEBUG(debugfs_enable, ...) \
|
||||
if(DEBUGFS_PRK_ONOFF != debugfs_enable) printk(__VA_ARGS__)
|
||||
|
||||
|
||||
struct netlinkk_cfg
|
||||
{
|
||||
|
@ -23,6 +26,7 @@ struct netlinkk_cfg
|
|||
struct netlink_debugfs dfs;
|
||||
struct commnl_msgtype_process* msg_processer;
|
||||
int msg_processer_num;
|
||||
unsigned long debugfs_prk_enable;
|
||||
};
|
||||
|
||||
typedef int (*commnl_doit_func)(struct sk_buff *, struct nlmsghdr *,struct netlink_ext_ack *);
|
||||
|
@ -83,5 +87,8 @@ extern int debugfs_pkt_num_stati_witisend(struct netlinkk_cfg *g_nlcfg,
|
|||
|
||||
extern int nf_nlmsg_multicast(struct netlinkk_cfg *g_nlcfg, struct sk_buff *skb);
|
||||
|
||||
extern int debugfs_prk_onoff(struct netlinkk_cfg *g_nlcfg,
|
||||
struct nlmsghdr *nlh,struct netlink_ext_ack *extack);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -49,12 +49,16 @@ int pdeliv_rcv_stat(struct sk_buff *skb, struct nlmsghdr *nlh,struct netlink_ext
|
|||
#else
|
||||
ret = debugfs_pkt_num_stati_witisend(&g_nlcfg, nlh,pdelivnl_msg_handlers);
|
||||
#endif
|
||||
printk("*****************biduichengong********%d*******\n", nlh->nlmsg_type);
|
||||
NETLINK_DEBUG(g_nlcfg.debugfs_prk_enable, "*****************biduichengong********%d*******\n", nlh->nlmsg_type);
|
||||
return ret;
|
||||
break;
|
||||
case NK_DEBUGFS_PRK_ONOFF:
|
||||
ret = debugfs_prk_onoff(&g_nlcfg, nlh, ext_ack);
|
||||
return ret;
|
||||
break;
|
||||
|
||||
default:
|
||||
printk(KERN_INFO "libnetlink Unknow msgtype recieved!\n");
|
||||
NETLINK_DEBUG(g_nlcfg.debugfs_prk_enable, "libnetlink Unknow msgtype recieved!\n");
|
||||
return 0;
|
||||
}
|
||||
/**************************************************************************************************************/
|
||||
|
@ -66,7 +70,7 @@ int nl_pdeliv_data_ready(struct sk_buff *skb, struct nlmsghdr *nlh, struct netli
|
|||
{
|
||||
int ret = 0;
|
||||
|
||||
printk(KERN_DEBUG "nl_pdeliv_data_ready() nlmsg_type = %d begin.\n",nlh->nlmsg_type);
|
||||
NETLINK_DEBUG(g_nlcfg.debugfs_prk_enable, "nl_pdeliv_data_ready() nlmsg_type = %d begin.\n",nlh->nlmsg_type);
|
||||
g_nlcfg.dfs.rev_total++;
|
||||
|
||||
if(NULL != pdelivnl_msg_handlers[nlh->nlmsg_type].doit)
|
||||
|
@ -92,10 +96,10 @@ int nl_pdeliv_data_ready(struct sk_buff *skb, struct nlmsghdr *nlh, struct netli
|
|||
g_nlcfg.dfs.rev_drop_total++;
|
||||
g_nlcfg.dfs.rev_drop_nodoit++;
|
||||
|
||||
printk(KERN_WARNING "no doit fun register with nlmsg_type = %d .\n",nlh->nlmsg_type);
|
||||
NETLINK_DEBUG(g_nlcfg.debugfs_prk_enable, "no doit fun register with nlmsg_type = %d .\n",nlh->nlmsg_type);
|
||||
}
|
||||
|
||||
printk(KERN_DEBUG "nl_pdeliv_data_ready() nlmsg_type = %d end.\n",nlh->nlmsg_type);
|
||||
NETLINK_DEBUG(g_nlcfg.debugfs_prk_enable, "nl_pdeliv_data_ready() nlmsg_type = %d end.\n",nlh->nlmsg_type);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -103,7 +107,7 @@ int nl_pdeliv_data_ready(struct sk_buff *skb, struct nlmsghdr *nlh, struct netli
|
|||
|
||||
static void libpdelivnl_rcv(struct sk_buff *skb)
|
||||
{
|
||||
printk(KERN_DEBUG "libpdelivnl_rcv:\n");
|
||||
NETLINK_DEBUG(g_nlcfg.debugfs_prk_enable, "libpdelivnl_rcv:\n");
|
||||
|
||||
netlink_rcv_skb(skb, &nl_pdeliv_data_ready);
|
||||
|
||||
|
@ -169,6 +173,8 @@ int __init pdelivery_init(void)
|
|||
/*do msg process register*/
|
||||
pdeliv_msgtype_register(PDNLGRP_REQUEST,pdeliv_rcv_stat,NULL,NULL);
|
||||
pdeliv_msgtype_register(NLMSG_PDELIV_DEBUGFS,pdeliv_rcv_stat,NULL,NULL);
|
||||
pdeliv_msgtype_register(NK_DEBUGFS_PRK_ONOFF,pdeliv_rcv_stat,NULL,NULL);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
######################################
|
||||
#
|
||||
######################################
|
||||
#source file
|
||||
#源文件,自动找所有.c和.cpp文件,并将目标定义为同名.o文件
|
||||
SOURCE := $(wildcard *.c) $(wildcard *.cpp)
|
||||
OBJS := $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCE)))
|
||||
|
||||
#target you can change test to what you want
|
||||
#目标文件名,输入任意你想要的执行文件名
|
||||
TARGET := cfgchannel_test_sample
|
||||
|
||||
#compile and lib parameter
|
||||
#编译参数
|
||||
CC := gcc
|
||||
LIBS := -L../netlink_uapi -lnetlinku
|
||||
LDFLAGS :=
|
||||
DEFINES :=
|
||||
INCLUDE := -I../lib -I../../../Common -I../netlink_uapi
|
||||
CFLAGS := -g -Wall -O3 $(DEFINES) $(INCLUDE)
|
||||
CXXFLAGS:= $(CFLAGS) -DHAVE_CONFIG_H
|
||||
|
||||
|
||||
#i think you should do anything here
|
||||
#下面的基本上不需要做任何改动了
|
||||
.PHONY : everything objs clean veryclean rebuild
|
||||
|
||||
everything : $(TARGET)
|
||||
|
||||
all : $(TARGET)
|
||||
|
||||
objs : $(OBJS)
|
||||
|
||||
rebuild: veryclean everything
|
||||
|
||||
clean :
|
||||
rm -fr *.so
|
||||
rm -fr *.o
|
||||
|
||||
veryclean : clean
|
||||
rm -fr $(TARGET)
|
||||
|
||||
$(TARGET) : $(OBJS)
|
||||
$(CC) $(CXXFLAGS) -o $@ $(OBJS) $(LDFLAGS) $(LIBS)
|
|
@ -1,141 +0,0 @@
|
|||
|
||||
#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
|
||||
|
||||
int set_user_policy_waitack()
|
||||
{
|
||||
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,
|
||||
.n.nlmsg_type = COMMNMSG_DEBUGFS,
|
||||
.ncm.policy_id = 17,
|
||||
.n.nlmsg_pid = getpid(),
|
||||
};
|
||||
|
||||
printf("set_user_policy_waitack\r\n");
|
||||
|
||||
/*可选属性*/
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int set_user_policy_nowaitack()
|
||||
{
|
||||
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,
|
||||
.n.nlmsg_pid = getpid(),
|
||||
};
|
||||
|
||||
printf("set_user_policy_nowaitack\r\n");
|
||||
|
||||
/*可选属性*/
|
||||
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_send(&req.n) < 0)
|
||||
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;
|
||||
}
|
||||
|
||||
/*下发配置到内核态*/
|
||||
ret = set_user_policy_nowaitack();
|
||||
if(ret < 0)
|
||||
{
|
||||
printf("set_user_policy failed.\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*关闭netlink通道*/
|
||||
commcfgnl_close();
|
||||
|
||||
printf("cfgchannel main exit!\r\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
Binary file not shown.
|
@ -1,44 +0,0 @@
|
|||
######################################
|
||||
#
|
||||
######################################
|
||||
#source file
|
||||
#源文件,自动找所有.c和.cpp文件,并将目标定义为同名.o文件
|
||||
SOURCE := $(wildcard *.c) $(wildcard *.cpp)
|
||||
OBJS := $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCE)))
|
||||
|
||||
#target you can change test to what you want
|
||||
#目标文件名,输入任意你想要的执行文件名
|
||||
TARGET := pdeliv_test_main
|
||||
|
||||
#compile and lib parameter
|
||||
#编译参数
|
||||
CC := gcc
|
||||
LIBS := -L../netlink_uapi -lnetlinku
|
||||
LDFLAGS :=
|
||||
DEFINES :=
|
||||
INCLUDE := -I../lib -I../../../Common -I../netlink_uapi
|
||||
CFLAGS := -g -Wall -O3 $(DEFINES) $(INCLUDE)
|
||||
CXXFLAGS:= $(CFLAGS) -DHAVE_CONFIG_H
|
||||
|
||||
|
||||
#i think you should do anything here
|
||||
#下面的基本上不需要做任何改动了
|
||||
.PHONY : everything objs clean veryclean rebuild
|
||||
|
||||
everything : $(TARGET)
|
||||
|
||||
all : $(TARGET)
|
||||
|
||||
objs : $(OBJS)
|
||||
|
||||
rebuild: veryclean everything
|
||||
|
||||
clean :
|
||||
rm -fr *.so
|
||||
rm -fr *.o
|
||||
|
||||
veryclean : clean
|
||||
rm -fr $(TARGET)
|
||||
|
||||
$(TARGET) : $(OBJS)
|
||||
$(CC) $(CXXFLAGS) -o $@ $(OBJS) $(LDFLAGS) $(LIBS)
|
Binary file not shown.
|
@ -1,89 +0,0 @@
|
|||
|
||||
#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;
|
||||
|
||||
int set_user_policy()
|
||||
{
|
||||
unsigned char debug[]={"17"};/*需要发送的数据*/
|
||||
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_POLICYCONF,
|
||||
.ncm.policy_id =17,
|
||||
.n.nlmsg_pid = getpid(),
|
||||
};
|
||||
struct nlmsghdr **debugfs_nl;
|
||||
struct pdeliv_debugfs *debugfs_statis;
|
||||
struct nlmsghdr *recv_hdr;
|
||||
|
||||
/*可选属性*/
|
||||
commnl_addattr_l(&req.n, sizeof(req), POLICYCONFA_SRCIP, debug, debug_len);
|
||||
|
||||
/*发送组装好的netlink消息*/
|
||||
if (pdeliv_talk(0, &req.n, NULL) < 0)
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
/*
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
*/
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int main( int argc, char **argv)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
printf("cfgchannel main begin:\r\n");
|
||||
|
||||
/*创建通道*/
|
||||
ret = pdelivnl_open(0);
|
||||
if(ret < 0)
|
||||
{
|
||||
printf("pdelivnl_open fail,exit.\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*下发配置到内核态*/
|
||||
ret = set_user_policy();
|
||||
if(ret < 0)
|
||||
{
|
||||
printf("set_user_policy failed.\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*关闭netlink通道*/
|
||||
pdelivnl_close(0);
|
||||
|
||||
printf("cfgchannel main exit!\r\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,236 @@
|
|||
#include "../include/parsefile.h"
|
||||
#include "../include/configm.h"
|
||||
#include "../../../netlink_uapi/libnetlinku.h"
|
||||
#include "../../../../common/rpc/rpc.h"
|
||||
#include "../include/authfree.h"
|
||||
#include <cjson/cJSON.h>
|
||||
#include "s2j/s2j.h"
|
||||
#include "../../../../../Common/commuapinl.h"
|
||||
|
||||
#ifdef FREEAUTH_ACK_COOKIES
|
||||
#define CFG_FREEAUTH_ACK_COOKIES
|
||||
#endif
|
||||
|
||||
/*全局变量,存放用户信息 */
|
||||
freeauth_configure_t *localuser;
|
||||
|
||||
/*全局变量初始化 失败为1 成功为0*/
|
||||
int Init(freeauth_configure_t *localuser)
|
||||
{
|
||||
localuser = (freeauth_configure_t *)malloc(sizeof * localuser);
|
||||
if (NULL == localuser)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* 判断IPv4格式是否正确*/
|
||||
int isIpV4Addr(const char *ipAddr)
|
||||
{
|
||||
int ip_part_1 = 0;
|
||||
int ip_part_2 = 0;
|
||||
int ip_part_3 = 0;
|
||||
int ip_part_4 = 0;
|
||||
char end_char = 0;
|
||||
if((NULL == ipAddr) || (0 == strlen(ipAddr)))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if(4 == sscanf(ipAddr,"%d.%d.%d.%d%c",&ip_part_1,&ip_part_2,&ip_part_3,&ip_part_4,&end_char))
|
||||
{
|
||||
if((ip_part_1 >= 0) && (ip_part_1 <= 255) &&
|
||||
(ip_part_2 >= 0) && (ip_part_2 <= 255) &&
|
||||
(ip_part_3 >= 0) && (ip_part_3 <= 255) &&
|
||||
(ip_part_4 >= 0) && (ip_part_4 <= 255)
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/*下发配置到内核态 */
|
||||
int set_freeauthcfg_waitack(freeauth_configure_t *struct_freeauth)
|
||||
{
|
||||
int freeauth_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_FREEAUTH_ACK_COOKIES
|
||||
.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK,/*set NLM_F_ACK:use kernel auto ack*/
|
||||
#else
|
||||
.n.nlmsg_flags = NLM_F_REQUEST, /*not use kernel auto ack */
|
||||
#endif
|
||||
.n.nlmsg_type = FREEAUTH_CFG,
|
||||
.n.nlmsg_pid = getpid(),
|
||||
};
|
||||
|
||||
/*判断要发送的数据是否为NULL,不为NULL,打印出来 */
|
||||
if (struct_freeauth == NULL)
|
||||
{
|
||||
printf("set_freeauthcfg_waitack is error: input struct_freeauth is NULL.\r\n");
|
||||
return -1;
|
||||
}else
|
||||
{
|
||||
char str[32];
|
||||
inet_ntop(AF_INET, (void *)&struct_freeauth->sip, str, 32);
|
||||
char *sip_addr = str;
|
||||
char dtr[32];
|
||||
inet_ntop(AF_INET, (void *)&struct_freeauth->dip, dtr, 32);
|
||||
char *dip_addr = dtr;
|
||||
printf("set_freeauthcfg_waitack :name %s sip %s dip %s dport %d\n",
|
||||
struct_freeauth->name, sip_addr, dip_addr,
|
||||
struct_freeauth->dport);
|
||||
}
|
||||
|
||||
/*计算需要发送的数据的长度 */
|
||||
freeauth_len = sizeof(freeauth_configure_t);
|
||||
|
||||
/*可选属性 */
|
||||
commnl_addattr_l(&req.n, sizeof(req), 1, struct_freeauth, freeauth_len);
|
||||
|
||||
/*发送组装好的netlink消息 */
|
||||
if(pdeliv_talk(1, &req.n, answer) < 0)
|
||||
{
|
||||
printf("set_user_freeauth_waitack rcv ack msg faild.\r\n");
|
||||
return -2;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("set_user_freeauth_waitack rcv ack msg success.\r\n");
|
||||
}
|
||||
|
||||
if(*answer != NULL)
|
||||
{
|
||||
printf("set_user_freeauth_waitack rcv answer.\r\n");
|
||||
}
|
||||
else{
|
||||
printf("set_user_freeauth_waitack rcv answer error.\r\n");
|
||||
return -3;
|
||||
}
|
||||
|
||||
#ifdef CFG_FREEAUTH_ACK_COOKIES
|
||||
/*recv answer*/
|
||||
if((*answer)->nlmsg_type == NLMSG_ERROR){
|
||||
nl_debugfs_extack(*answer);
|
||||
}
|
||||
#else
|
||||
/*recv answer*/
|
||||
if((*answer)->nlmsg_type == FREEAUTH_CFG)
|
||||
{
|
||||
nl_debugfs(*answer);
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*判断免认证规则源IP地址、目的IP地址是否有效,判断端口号是否有效 */
|
||||
ret_code freeauth_config_chk(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
freeauth_configure_t *struct_freeauth;
|
||||
struct_freeauth = (freeauth_configure_t *)input;
|
||||
|
||||
if(input_len < sizeof(freeauth_configure_t) )
|
||||
{
|
||||
ret = RET_INPUTERR;
|
||||
}
|
||||
|
||||
char str[32];
|
||||
inet_ntop(AF_INET, (void *)&struct_freeauth->sip, str, 32);
|
||||
char *sip_addr = str;
|
||||
if( isIpV4Addr(sip_addr) < 0 )
|
||||
{
|
||||
ret = RET_IPINVALID;
|
||||
}
|
||||
|
||||
char dtr[32];
|
||||
inet_ntop(AF_INET, (void *)&struct_freeauth->dip, dtr, 32);
|
||||
char *dip_addr = dtr;
|
||||
if( isIpV4Addr(dip_addr) < 0 )
|
||||
{
|
||||
ret = RET_IPINVALID;
|
||||
}
|
||||
|
||||
if ( (struct_freeauth->dport < DPORT_MIN_NUM) && (struct_freeauth->dport > DPORT_MAX_NUM ))
|
||||
{
|
||||
ret = RET_IPINVALID; /*先用IPVAILD表示,后面加PORTVAILD */
|
||||
}
|
||||
|
||||
ASSERT_RET(ret);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
|
||||
/*免认证规则有效,将免认证规则通过netlink下发到内核态 */
|
||||
int freeauth_config_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
int code;
|
||||
freeauth_configure_t *struct_freeauth;
|
||||
|
||||
struct_freeauth = (freeauth_configure_t *)input;
|
||||
|
||||
char str[32];
|
||||
inet_ntop(AF_INET, (void *)&struct_freeauth->sip, str, 32);
|
||||
char *sip_addr = str;
|
||||
char dtr[32];
|
||||
inet_ntop(AF_INET, (void *)&struct_freeauth->dip, dtr, 32);
|
||||
char *dip_addr = dtr;
|
||||
rpc_log_info("freeauth configure: name %s sip %s dip %s dport %d\n",
|
||||
struct_freeauth->name,sip_addr, dip_addr, struct_freeauth->dport);
|
||||
|
||||
/*用户态下发到内核态auth_hook */
|
||||
int ret1 = -1;
|
||||
printf("cfgchannel main begin:\r\n");
|
||||
|
||||
/*创建通道 */
|
||||
ret1 = commcfgnl_open();
|
||||
if(ret1 < 0)
|
||||
{
|
||||
printf(" pdlivnl_open fail, exit.\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*下发配置到内核态 */
|
||||
ret1 = set_freeauthcfg_waitack(struct_freeauth);
|
||||
if(ret1 < 0)
|
||||
{
|
||||
printf("set_cfg_debug_waitack failed.\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*关闭netlink通道 */
|
||||
commcfgnl_close();
|
||||
|
||||
printf("cfgchannel main exit!\r\n");
|
||||
|
||||
/*把免认证规则的配置信息存入全局变量 */
|
||||
localuser = struct_freeauth;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
#ifndef FREEAUTH_H_
|
||||
#define FREEAUTH_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"
|
||||
|
||||
#define DPORT_MIN_NUM 0
|
||||
#define DPORT_MAX_NUM 65535
|
||||
|
||||
/*配置消息 */
|
||||
typedef struct {
|
||||
uint32_t sip;
|
||||
uint32_t dip;
|
||||
int dport;
|
||||
char name[32];
|
||||
}freeauth_configure_t;
|
||||
|
||||
|
||||
/*全局变量初始化 失败为1 成功为0*/
|
||||
int Init(freeauth_configure_t *localuser);
|
||||
|
||||
|
||||
/* 判断IPv4格式是否正确*/
|
||||
int isIpV4Addr(const char *ipAddr);
|
||||
|
||||
|
||||
/*下发配置到内核态 */
|
||||
int set_freeauthcfg_waitack(freeauth_configure_t *struct_freeauth);
|
||||
|
||||
/*判断免认证规则源IP地址、目的IP地址是否有效,判断端口号是否有效 */
|
||||
ret_code freeauth_config_chk(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len);
|
||||
|
||||
|
||||
/*免认证规则有效,将免认证规则通过netlink下发到内核态 */
|
||||
int freeauth_config_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len);
|
||||
|
||||
#endif
|
Binary file not shown.
|
@ -1,17 +1,35 @@
|
|||
#ifndef CONFIGM_H_
|
||||
#define CONFIGM_H_
|
||||
|
||||
#include "rpc_common.h"
|
||||
#include "../../../../common/rpc/rpc_common.h"
|
||||
#include "ipconfig.h"
|
||||
#include "configmapi.h"
|
||||
#include "../../../../../Common/commuapinl.h"
|
||||
#include "user_group_config.h"
|
||||
/* 类型定义 */
|
||||
|
||||
/* IP CONFIG */
|
||||
#define IPCONFIG_MODULE 0x00000001
|
||||
|
||||
/* USER MANAGER CONFIG */
|
||||
#define USER_MANAGER_CONFIG_MODULE 0x00000002
|
||||
|
||||
/*PORTAL SERVER CONFIG */
|
||||
#define PORTAL_CONFIG_MODULE 0x00000003
|
||||
|
||||
/* AUTHFREE CONFIG*/
|
||||
#define AUTHFREE_CONFIG_MODULE 0x00000004
|
||||
|
||||
|
||||
|
||||
/* config id define*/
|
||||
#define IPCONFIG_V4 (uint64)((uint64)IPCONFIG_MODULE<<32|1)
|
||||
|
||||
#define USER_MANAGER_CONFIG_GROUP (uint64)((uint64)USER_MANAGER_CONFIG_MODULE<<32|1)
|
||||
#define USER_MANAGER_CONFIG_USER (uint64)((uint64)USER_MANAGER_CONFIG_MODULE<<32|2)
|
||||
|
||||
#define PORTALSERVER_CONFIG (uint64)((uint64)PORTAL_CONFIG_MODULE<<32|1)
|
||||
|
||||
#define AUTHFREE_CONFIG (uint64)((uint64)AUTHFREE_CONFIG_MODULE<<32|1)
|
||||
/*
|
||||
1、配置ID,全局唯一,用于寻找对应的配置业务
|
||||
2、配置源检查,全局唯一,用于寻找对应的配置业务,
|
||||
|
@ -34,7 +52,37 @@
|
|||
ip_config_proc, \
|
||||
ip_config_get, \
|
||||
ip_config_get_all \
|
||||
}\
|
||||
},\
|
||||
{\
|
||||
USER_MANAGER_CONFIG_GROUP, \
|
||||
CONFIG_FROM_WEB, \
|
||||
FALSE, \
|
||||
FALSE, \
|
||||
usergroup_config_chk, \
|
||||
usergroup_config_proc, \
|
||||
usergroup_config_get, \
|
||||
usergroup_config_get_all \
|
||||
},\
|
||||
{\
|
||||
PORTALSERVER_CONFIG, \
|
||||
CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \
|
||||
FALSE, \
|
||||
FALSE, \
|
||||
portalserver_config_chk, \
|
||||
portalserver_config_proc, \
|
||||
portalserver_config_get, \
|
||||
portalserver_get_all \
|
||||
},\
|
||||
{\
|
||||
AUTHFREE_CONFIG, \
|
||||
CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \
|
||||
FALSE, \
|
||||
FALSE, \
|
||||
freeauth_config_chk, \
|
||||
freeauth_config_proc, \
|
||||
freeauth_config_get, \
|
||||
freeauth_config_get_all \
|
||||
},\
|
||||
}
|
||||
|
||||
typedef ret_code (*cm_config_chk)(uint source, uint config_type,
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
#ifndef LOCALPORTAL_H_
|
||||
#define LOCALPORTAL_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"
|
||||
|
||||
|
||||
/*配置消息 */
|
||||
typedef struct {
|
||||
uint32_t ip;
|
||||
int port;
|
||||
}localportal_configure_t;
|
||||
|
||||
/*全局变量初始化 失败为1 成功为0*/
|
||||
int Init(localportal_configure_t *localportal);
|
||||
|
||||
|
||||
/*检查IP地址是否有效,端口号是否被占用 */
|
||||
int _valid_ipv4_port(const char *str, int port);
|
||||
|
||||
|
||||
/*判断配置本地Portal服务器的IP地址是否有效,端口号是否被占用 */
|
||||
ret_code portalserver_config_chk(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len);
|
||||
|
||||
|
||||
/*系统管理模块将数据内容(IP地址、端口号)发送给web server */
|
||||
int portalserver_config_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len);
|
||||
|
||||
#endif
|
|
@ -2,7 +2,7 @@
|
|||
#define PARSEFILE_H_
|
||||
|
||||
#define IFCONFIG_PATH "/etc/network/interfaces"
|
||||
#define IF_BUFF_LEN 64
|
||||
#define IF_BUFF_LEN 128
|
||||
|
||||
void set_if_config(char *if_name, char *conf_name, char *conf_buff);
|
||||
void del_if_config(char *if_name, char *conf_buff);
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
#ifndef USER_GROUP_CONFIG_H_
|
||||
#define USER_GROUP_CONFIG_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 <cjson/cJSON.h>
|
||||
|
||||
|
||||
#include "../../../../common/configm/configmapi.h"
|
||||
#include "../../../../common/rpc/rpc_common.h"
|
||||
#include "../../../../../Product/user/user_manager/user_group.h"
|
||||
|
||||
|
||||
|
||||
|
||||
/* user group config */
|
||||
ret_code usergroup_config_chk(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len);
|
||||
|
||||
ret_code usergroup_config_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len);
|
||||
|
||||
ret_code usergroup_config_get(uint source,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len);
|
||||
|
||||
ret_code usergroup_config_get_all(uint source, uint64 config_id,
|
||||
pointer output, short *single_len,
|
||||
int *output_len);
|
||||
|
||||
#endif
|
|
@ -49,7 +49,7 @@ void ip_save_file(ip_config_t *ip_conf, uint config_type)
|
|||
sprintf(addr_buff, "address %s\n", inet_ntoa(ip_conf->prefix));
|
||||
masklen2ip(ip_conf->prefixlen, &netmask);
|
||||
sprintf(mask_buff, "netmask %s\n", inet_ntoa(netmask));
|
||||
printf("%s,%s\r\n",addr_buff, mask_buff);
|
||||
rpc_log_info("%s %s",addr_buff, mask_buff);
|
||||
|
||||
set_if_config(ip_conf->ifname, addr_name, addr_buff);
|
||||
set_if_config(ip_conf->ifname, mask_name, mask_buff);
|
||||
|
@ -233,11 +233,12 @@ ret_code ip_config_set_chk(uint source,uint config_type,
|
|||
ret = RET_INPUTERR;
|
||||
}
|
||||
|
||||
if (ipv4_martian(&ip_conf->prefix))
|
||||
if (config_type != CM_CONFIG_DEL && ipv4_martian(&ip_conf->prefix))
|
||||
{
|
||||
ret = RET_IPINVALID;
|
||||
}
|
||||
|
||||
|
||||
ASSERT_RET(ret);
|
||||
|
||||
if(ip_conf->prefixlen == 0 || ip_conf->prefixlen > IPV4_MAX_PREFIXLEN)
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#include "parsefile.h"
|
||||
#include "rpc.h"
|
||||
|
||||
#if 0
|
||||
/*
|
||||
|
@ -233,108 +234,134 @@ void set_if_config(char *if_name, char *conf_name, char *conf_buff)
|
|||
char config_linebuf[IF_BUFF_LEN];
|
||||
char static_name[IF_BUFF_LEN] = {0};
|
||||
char iface_str[IF_BUFF_LEN] = {0};
|
||||
char iface_str2[IF_BUFF_LEN] = {0};
|
||||
char auto_str[IF_BUFF_LEN] = {0};
|
||||
char *config_sign = "iface";
|
||||
char *leave_line;
|
||||
char *leave_line2;
|
||||
int alter_sign = 0;
|
||||
char *auto_line = NULL;
|
||||
char *iface_line = NULL;
|
||||
char *config_line = NULL;
|
||||
boolean next_flag = FALSE;
|
||||
|
||||
FILE *f;
|
||||
f = fopen(conf_path,"r+");
|
||||
if(f == NULL)
|
||||
{
|
||||
printf("OPEN CONFIG FALID\n");
|
||||
rpc_log_error("OPEN CONFIG FALID\n");
|
||||
return;
|
||||
}
|
||||
|
||||
fseek(f,0,SEEK_END);
|
||||
|
||||
long congig_lenth = ftell(f);
|
||||
long config_lenth = ftell(f);
|
||||
int configbuf_lenth = strlen(conf_buff);
|
||||
configbuf_lenth = configbuf_lenth + 5;
|
||||
char sum_buf[congig_lenth+configbuf_lenth];
|
||||
char sum_buf[config_lenth + configbuf_lenth];
|
||||
|
||||
memset(sum_buf,0,sizeof(sum_buf));
|
||||
fseek(f,0,SEEK_SET);
|
||||
|
||||
sprintf(iface_str, "%s %s", config_sign, if_name);
|
||||
sprintf(iface_str2, "auto %s", if_name);
|
||||
sprintf(auto_str, "auto %s", if_name);
|
||||
sprintf(iface_str, "iface %s inet", if_name);
|
||||
sprintf(static_name, "iface %s inet static\n", if_name);
|
||||
|
||||
leave_line = NULL;
|
||||
leave_line2 = NULL;
|
||||
memset(config_linebuf,0,sizeof(config_linebuf));
|
||||
|
||||
while(fgets(config_linebuf,IF_BUFF_LEN,f) != NULL)
|
||||
{
|
||||
if(strlen(config_linebuf) < 3 || leave_line2) //判断是否是空行
|
||||
/* 该做的事情已经做完 */
|
||||
if(next_flag == TRUE)
|
||||
{
|
||||
strcat(sum_buf,config_linebuf);
|
||||
continue;
|
||||
goto next_while;
|
||||
}
|
||||
|
||||
if(leave_line == NULL)
|
||||
{
|
||||
leave_line = strstr(config_linebuf, iface_str);
|
||||
|
||||
if(leave_line)
|
||||
{
|
||||
strcat(sum_buf,static_name);
|
||||
}
|
||||
else
|
||||
/* 判断是否是空行 */
|
||||
if(strlen(config_linebuf) < 3)
|
||||
{
|
||||
strcat(sum_buf,config_linebuf);
|
||||
}
|
||||
}
|
||||
/*leave_line != NULL && leave_line2 !=NULL*/
|
||||
else if((leave_line2 = strstr(config_linebuf,iface_str))
|
||||
|| (leave_line2 = strstr(config_linebuf,iface_str2)))
|
||||
{
|
||||
if(alter_sign == 0)
|
||||
{
|
||||
strcat(sum_buf,conf_buff);
|
||||
alter_sign = 1;
|
||||
goto next_while;
|
||||
}
|
||||
|
||||
strcat(sum_buf,config_linebuf);
|
||||
/* 没有找到接口配置块,则继续循环 */
|
||||
if(auto_line == NULL)
|
||||
{
|
||||
auto_line = strstr(config_linebuf, auto_str);
|
||||
strcat(sum_buf, config_linebuf);
|
||||
goto next_while;
|
||||
}
|
||||
/*leave_line != NULL && leave_line2 == NULL*/
|
||||
else
|
||||
|
||||
/* 已经是下一个接口了*/
|
||||
if(strstr(config_linebuf, "auto"))
|
||||
{
|
||||
if(strstr(config_linebuf,conf_name) != NULL)
|
||||
if(iface_line == NULL)
|
||||
{
|
||||
strcat(sum_buf,conf_buff);
|
||||
alter_sign = 1;
|
||||
strcat(sum_buf, static_name);
|
||||
}
|
||||
else
|
||||
if(config_line == NULL)
|
||||
{
|
||||
strcat(sum_buf,config_linebuf);
|
||||
strcat(sum_buf, conf_buff);
|
||||
}
|
||||
|
||||
strcat(sum_buf, config_linebuf);
|
||||
next_flag = TRUE;
|
||||
|
||||
goto next_while;
|
||||
}
|
||||
|
||||
/* 找到接口IP配置方式 */
|
||||
if(iface_line == NULL)
|
||||
{
|
||||
iface_line = strstr(config_linebuf, iface_str);
|
||||
if(iface_line)
|
||||
{
|
||||
strcat(sum_buf, static_name);
|
||||
goto next_while;
|
||||
}
|
||||
}
|
||||
|
||||
/* 找到配置行 */
|
||||
if(config_line == NULL)
|
||||
{
|
||||
config_line = strstr(config_linebuf, conf_name);
|
||||
if(config_line)
|
||||
{
|
||||
next_flag = TRUE;
|
||||
strcat(sum_buf, conf_buff);
|
||||
goto next_while;
|
||||
}
|
||||
}
|
||||
|
||||
strcat(sum_buf, config_linebuf);
|
||||
|
||||
next_while:
|
||||
if(fgetc(f)==EOF)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
fseek(f,-1,SEEK_CUR);
|
||||
|
||||
memset(config_linebuf,0,sizeof(config_linebuf));
|
||||
memset(config_linebuf, 0, sizeof(config_linebuf));
|
||||
}
|
||||
|
||||
if(leave_line == NULL)
|
||||
if( next_flag == FALSE )
|
||||
{
|
||||
sprintf(auto_str, "auto %s\n", if_name);
|
||||
sprintf(auto_str, "%s", static_name);
|
||||
strcat(sum_buf,auto_str);
|
||||
if(auto_line == NULL)
|
||||
{
|
||||
strcat(sum_buf, auto_str);
|
||||
strcat(sum_buf, "\n");
|
||||
}
|
||||
|
||||
if(alter_sign == 0)
|
||||
if(iface_line == NULL)
|
||||
{
|
||||
strcat(sum_buf, static_name);
|
||||
}
|
||||
|
||||
if(config_line == NULL)
|
||||
{
|
||||
//strcat(sum_buf,"\n");
|
||||
strcat(sum_buf, conf_buff);
|
||||
}
|
||||
}
|
||||
|
||||
printf("---sum_buf---->%s<----------/n",sum_buf);
|
||||
rpc_log_dbg("---sum_buf---->%s<----------\n",sum_buf);
|
||||
remove(conf_path);
|
||||
fclose(f);
|
||||
|
||||
|
@ -342,7 +369,7 @@ void set_if_config(char *if_name, char *conf_name, char *conf_buff)
|
|||
fp = fopen(conf_path,"w+");
|
||||
if(fp == NULL)
|
||||
{
|
||||
printf("OPEN CONFIG FALID/n");
|
||||
rpc_log_error("OPEN CONFIG FALID\n");
|
||||
return;
|
||||
}
|
||||
fseek(fp,0,SEEK_SET);
|
||||
|
@ -363,14 +390,9 @@ void del_if_config(char *if_name, char *conf_buff)
|
|||
{
|
||||
char *conf_path = IFCONFIG_PATH;
|
||||
char config_linebuf[IF_BUFF_LEN];
|
||||
char iface_str[IF_BUFF_LEN] = {0};
|
||||
char iface_str2[IF_BUFF_LEN] = {0};
|
||||
char auto_str[IF_BUFF_LEN] = {0};
|
||||
char *config_sign = "iface";
|
||||
char *leave_line;
|
||||
char *leave_line2;
|
||||
int alter_sign = 0;
|
||||
|
||||
boolean next_flag = FALSE;
|
||||
char *auto_line = NULL;
|
||||
FILE *f;
|
||||
f = fopen(conf_path,"r+");
|
||||
if(f == NULL)
|
||||
|
@ -389,41 +411,52 @@ void del_if_config(char *if_name, char *conf_buff)
|
|||
memset(sum_buf,0,sizeof(sum_buf));
|
||||
fseek(f,0,SEEK_SET);
|
||||
|
||||
sprintf(iface_str, "%s %s", config_sign, if_name);
|
||||
sprintf(iface_str2, "auto %s", if_name);
|
||||
sprintf(auto_str, "auto %s", if_name);
|
||||
|
||||
leave_line = NULL;
|
||||
leave_line2 = NULL;
|
||||
|
||||
while(fgets(config_linebuf,256,f) != NULL)
|
||||
while(fgets(config_linebuf,IF_BUFF_LEN,f) != NULL)
|
||||
{
|
||||
if(strlen(config_linebuf) < 3 || leave_line2) //判断是否是空行
|
||||
/* 该做的事情已经做完 */
|
||||
if(next_flag == TRUE)
|
||||
{
|
||||
strcat(sum_buf,config_linebuf);
|
||||
continue;
|
||||
goto next_while;
|
||||
}
|
||||
|
||||
if(leave_line == NULL)
|
||||
/* 判断是否是空行 */
|
||||
if(strlen(config_linebuf) < 3)
|
||||
{
|
||||
leave_line = strstr(config_linebuf, iface_str);
|
||||
strcat(sum_buf,config_linebuf);
|
||||
goto next_while;
|
||||
}
|
||||
/*leave_line != NULL && leave_line2 !=NULL*/
|
||||
else if((leave_line2 = strstr(config_linebuf,iface_str))
|
||||
|| (leave_line2 = strstr(config_linebuf,iface_str2)))
|
||||
{
|
||||
|
||||
/* 没有找到接口配置块,则继续循环 */
|
||||
if(auto_line == NULL)
|
||||
{
|
||||
auto_line = strstr(config_linebuf, auto_str);
|
||||
strcat(sum_buf,config_linebuf);
|
||||
goto next_while;
|
||||
}
|
||||
|
||||
/* 已经是下一个接口了, 则表示无法找到*/
|
||||
if(strstr(config_linebuf, "auto"))
|
||||
{
|
||||
strcat(sum_buf,config_linebuf);
|
||||
next_flag = TRUE;
|
||||
goto next_while;
|
||||
}
|
||||
|
||||
/* 找到配置行 */
|
||||
if(strstr(config_linebuf,conf_buff))
|
||||
{
|
||||
next_flag = TRUE;
|
||||
}
|
||||
/*leave_line != NULL && leave_line2 == NULL*/
|
||||
else
|
||||
{
|
||||
if(strstr(config_linebuf,conf_buff) == NULL)
|
||||
{
|
||||
strcat(sum_buf,config_linebuf);
|
||||
}
|
||||
strcat(sum_buf, config_linebuf);
|
||||
}
|
||||
|
||||
next_while:
|
||||
|
||||
if(fgetc(f)==EOF)
|
||||
{
|
||||
break;
|
||||
|
|
|
@ -0,0 +1,133 @@
|
|||
#include "../../../../common/rpc/rpc.h"
|
||||
#include "../include/parsefile.h"
|
||||
#include "../include/configm.h"
|
||||
#include "../../../netlink_uapi/libnetlinku.h"
|
||||
#include "../include/localportal.h"
|
||||
#include <cjson/cJSON.h>
|
||||
#include "../../../../../Common/s2j/s2j.h"
|
||||
#include "../../../../../Common/commuapinl.h"
|
||||
|
||||
/*全局变量,存放本地Portal服务器的IP地址和端口号 */
|
||||
localportal_configure_t *localportal;
|
||||
|
||||
/*全局变量初始化 失败为1 成功为0*/
|
||||
int Init(localportal_configure_t *localportal)
|
||||
{
|
||||
localportal = (localportal_configure_t *)malloc(sizeof * localportal);
|
||||
if (NULL == localportal)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*检查IP地址是否有效,端口号是否被占用 */
|
||||
int _valid_ipv4_port(const char *str, int port)
|
||||
{
|
||||
int ret;
|
||||
int fd;
|
||||
int i;
|
||||
volatile int local_errno;
|
||||
struct sockaddr_in addr;
|
||||
fd = socket(AF_INET,SOCK_STREAM,0); //初始化socket
|
||||
|
||||
if(fd ==-1) //检查是否正常初始化socket
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
local_errno = errno;
|
||||
|
||||
ret = inet_pton(AF_INET, str ,&addr.sin_addr);
|
||||
printf("the value of ret is:%d\n",ret);
|
||||
if(ret > 0)
|
||||
{
|
||||
fprintf(stderr, "\"%s\" is a vaild IPv4 address\n", str);
|
||||
|
||||
addr.sin_family = AF_INET; //地址结构的协议簇
|
||||
addr.sin_port=htons(port); //地址结构的端口地址,网络字节序
|
||||
printf("the value of str:%s\n", str);
|
||||
i = (bind(fd, (struct sockaddr*)&addr, sizeof(struct sockaddr)));
|
||||
printf("the value of i:%d\n", i);
|
||||
|
||||
if( i < 0)
|
||||
{
|
||||
printf("port %d has been used. \n", port);
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("port %d is ok. \n", port);
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
else if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "EAFNOSUPPORT: %s\n", strerror(local_errno));
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "\"%s\" is not a vaild IPv4 address\n", str);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*判断配置本地Portal服务器的IP地址是否有效,端口号是否被占用 */
|
||||
ret_code portalserver_config_chk(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
localportal_configure_t *struct_portal;
|
||||
struct_portal = (localportal_configure_t *)input;
|
||||
|
||||
if(input_len < sizeof(localportal_configure_t) )
|
||||
{
|
||||
ret = RET_INPUTERR;
|
||||
}
|
||||
|
||||
char str[32];
|
||||
inet_ntop(AF_INET, (void *)&struct_portal->ip, str, 32);
|
||||
char *ip_addr = str;
|
||||
if( (_valid_ipv4_port(ip_addr, struct_portal->port)) < 0 )
|
||||
{
|
||||
ret = RET_ERR;
|
||||
}
|
||||
|
||||
ASSERT_RET(ret);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
|
||||
/*系统管理模块将数据内容(IP地址、端口号)发送给web server */
|
||||
int portalserver_config_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
int code;
|
||||
localportal_configure_t *struct_portal;
|
||||
struct_portal = (localportal_configure_t *)input;
|
||||
|
||||
char str[32];
|
||||
inet_ntop(AF_INET, (void *)&struct_portal->ip, str, 32);
|
||||
char *ip_addr = str;
|
||||
rpc_log_info("portalserver configure: ip: %s port: %d\n",
|
||||
struct_portal->ip, struct_portal->port);
|
||||
|
||||
/*将配置信息发送到web server */
|
||||
|
||||
/*把本地Portal server的配置信息存入全局变量 */
|
||||
localportal = struct_portal;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,160 @@
|
|||
#include "configm.h"
|
||||
#include "user_group_config.h"
|
||||
#include "rpc.h"
|
||||
#include "parsefile.h"
|
||||
|
||||
/* check暂时不做操作,所有的检查在业务接口中完成 */
|
||||
ret_code usergroup_config_chk(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
int code = 0;
|
||||
cJSON *root;
|
||||
cJSON *name, *description;
|
||||
|
||||
switch(config_type)
|
||||
{
|
||||
case CM_CONFIG_ADD:
|
||||
// root = cJSON_Parse(input);
|
||||
// if(!root)
|
||||
// {
|
||||
// ret = RET_INPUTERR;
|
||||
// ASSERT_RET(ret);
|
||||
// return ret;
|
||||
// }
|
||||
// name = cJSON_GetObjectItem(root, "gname");
|
||||
// if(!name)
|
||||
// {
|
||||
// cJSON_Delete(root);
|
||||
// ret = RET_INPUTERR;
|
||||
// ASSERT_RET(ret);
|
||||
// return ret;
|
||||
// }
|
||||
// description = cJSON_GetObjectItem(root, "gdescription");
|
||||
// if(!description)
|
||||
// {
|
||||
// cJSON_Delete(root);
|
||||
// ret = RET_INPUTERR;
|
||||
// ASSERT_RET(ret);
|
||||
// return ret;
|
||||
// }
|
||||
//cJSON_Delete(root);
|
||||
break;
|
||||
case CM_CONFIG_DEL:
|
||||
break;
|
||||
case CM_CONFIG_GET:
|
||||
break;
|
||||
case CM_CONFIG_GET_ALL:
|
||||
break;
|
||||
default:
|
||||
ret = RET_NOTSUPPORT;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* 新增用户组-处理 */
|
||||
ret_code usergroup_config_add_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
unsigned short result;
|
||||
cJSON *root, *name, *description, *res;
|
||||
char *des = NULL;
|
||||
char *ret_char = NULL;
|
||||
|
||||
root = cJSON_Parse(input);
|
||||
if(!root)
|
||||
{
|
||||
ret = RET_INPUTERR;
|
||||
ASSERT_RET(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
name = cJSON_GetObjectItem(root, "gname");
|
||||
if(!name)
|
||||
{
|
||||
ret = RET_INPUTERR;
|
||||
ASSERT_RET(ret);
|
||||
cJSON_Delete(root);
|
||||
return ret;
|
||||
}
|
||||
|
||||
description = cJSON_GetObjectItem(root, "gdescription");
|
||||
if(description)
|
||||
{
|
||||
des = description->valuestring;
|
||||
}
|
||||
|
||||
result = add_group(name->valuestring, des); //增加用户组
|
||||
cJSON_Delete(root);
|
||||
|
||||
res = cJSON_CreateObject();
|
||||
if(!res)
|
||||
{
|
||||
ret = RET_ERR;
|
||||
ASSERT_RET(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
cJSON_AddNumberToObject(res, "result", result);
|
||||
ret_char = cJSON_PrintUnformatted(res);
|
||||
memcpy(output, ret_char, strlen(ret_char)+1);
|
||||
cJSON_Delete(res);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret_code usergroup_config_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
int code;
|
||||
|
||||
switch(config_type)
|
||||
{
|
||||
case CM_CONFIG_ADD:
|
||||
ret = usergroup_config_add_proc(source, config_type,
|
||||
input, input_len,
|
||||
output, output_len);
|
||||
break;
|
||||
case CM_CONFIG_DEL:
|
||||
ret = usergroup_config_del_proc(source, config_type,
|
||||
input, input_len,
|
||||
output, output_len);
|
||||
break;
|
||||
case CM_CONFIG_GET:
|
||||
ret = usergroup_config_get_proc(source, config_type,
|
||||
input, input_len,
|
||||
output, output_len);
|
||||
break;
|
||||
case CM_CONFIG_GET_ALL:
|
||||
ret = usergroup_config_getall_proc(source, config_type,
|
||||
input, input_len,
|
||||
output, output_len);
|
||||
break;
|
||||
default:
|
||||
ret = RET_NOTSUPPORT;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret_code usergroup_config_get(uint source,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret_code usergroup_config_get_all(uint source, uint64 config_id,
|
||||
pointer output, short *single_len,
|
||||
int *output_len)
|
||||
{
|
||||
ret_code ret = RET_OK;
|
||||
return ret;
|
||||
}
|
|
@ -98,7 +98,7 @@ int parse_config_type(char *str)
|
|||
}
|
||||
|
||||
|
||||
void parse_input_str(int argc, char **argv, int *config_type, ip_config_t *ip_conf)
|
||||
ret_code parse_input_str(int argc, char **argv, int *config_type, ip_config_t *ip_conf)
|
||||
{
|
||||
int intput_cnt = argc;
|
||||
int idx = 1;
|
||||
|
@ -113,13 +113,13 @@ void parse_input_str(int argc, char **argv, int *config_type, ip_config_t *ip_co
|
|||
if(*config_type == CM_CONFIG_GET_ALL
|
||||
|| *config_type == 0)
|
||||
{
|
||||
return;
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
if(intput_cnt < 2)
|
||||
{
|
||||
printf("input error:<type> <if>\n");
|
||||
return;
|
||||
return RET_INPUTERR;
|
||||
}
|
||||
|
||||
idx++;
|
||||
|
@ -129,13 +129,13 @@ void parse_input_str(int argc, char **argv, int *config_type, ip_config_t *ip_co
|
|||
if(*config_type == CM_CONFIG_GET)
|
||||
{
|
||||
ip_conf->family = AF_INET;
|
||||
return;
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
if(argc < 4)
|
||||
{
|
||||
printf("input error:<type> <if> <ip> <mask>\n");
|
||||
return;
|
||||
return RET_INPUTERR;
|
||||
}
|
||||
|
||||
printf("if %s\n",ip_conf->ifname);
|
||||
|
@ -151,7 +151,7 @@ void parse_input_str(int argc, char **argv, int *config_type, ip_config_t *ip_co
|
|||
ip_conf->prefixlen = atoi(argv[idx]);
|
||||
printf("prefix len is %d\n", ip_conf->prefixlen);
|
||||
|
||||
return;
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
|
@ -165,7 +165,10 @@ int main(int argc, char **argv)
|
|||
char* output = NULL;
|
||||
int output_len;
|
||||
|
||||
parse_input_str(argc, argv, &config_type, &ip_conf);
|
||||
if(parse_input_str(argc, argv, &config_type, &ip_conf) != RET_OK)
|
||||
{
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf("=============================\n");
|
||||
|
||||
|
|
|
@ -331,10 +331,10 @@ static void* thread_client_handler(void* data) {
|
|||
|
||||
//pthread_mutex_t mutex = th->client->mutex;
|
||||
|
||||
pthread_mutex_lock(&(th->client->mutex);
|
||||
pthread_mutex_lock(&(th->client->mutex));
|
||||
th->client->init_count++;
|
||||
pthread_cond_signal(&(th->client->cond));
|
||||
pthread_mutex_unlock(&(th->client->mutex);
|
||||
pthread_mutex_unlock(&(th->client->mutex));
|
||||
th->thread_receive_id = pthread_self();
|
||||
ev_run(th->loop, 0);
|
||||
return NULL;
|
||||
|
|
|
@ -1,81 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
struct authfree_configure
|
||||
{
|
||||
char name[32]; //免认证规则名称
|
||||
uint32_t sip; //免认证规则源ip
|
||||
uint32_t dip; //免认证规则目的ip
|
||||
int dport; //免认证规则目的端口号
|
||||
time_t begin_time; //有效时间范围的起始时间
|
||||
time_t over_time; //有效时间范围内的结束时间
|
||||
};
|
||||
|
||||
//判断IPv4格式是否正确
|
||||
int isIpV4Addr(const char *ipAddr)
|
||||
{
|
||||
int ip_part_1 = 0;
|
||||
int ip_part_2 = 0;
|
||||
int ip_part_3 = 0;
|
||||
int ip_part_4 = 0;
|
||||
char end_char = 0;
|
||||
if((NULL == ipAddr) || (0 == strlen(ipAddr)))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if(4 == sscanf(ipAddr,"%d.%d.%d.%d%c",&ip_part_1,&ip_part_2,&ip_part_3,&ip_part_4,&end_char))
|
||||
{
|
||||
if((ip_part_1 >= 0) && (ip_part_1 <= 255) &&
|
||||
(ip_part_2 >= 0) && (ip_part_2 <= 255) &&
|
||||
(ip_part_3 >= 0) && (ip_part_3 <= 255) &&
|
||||
(ip_part_4 >= 0) && (ip_part_4 <= 255)
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
//判断免认证规则是否有效,所有条件有效则返回值为0,其中一项条件无效则返回值为1
|
||||
int _valid_authfreerule(struct authfree_configure *s)
|
||||
{
|
||||
char sstr[32];
|
||||
inet_ntop(AF_INET, (void *)&s->sip, sstr, 32);
|
||||
char *sip_addr = sstr;
|
||||
if(!isIpV4Addr(sip_addr))
|
||||
{
|
||||
char dstr[32];
|
||||
inet_ntop(AF_INET, (void *)&s->dip, dstr, 32);
|
||||
char *dip_addr = dstr;
|
||||
if(!isIpV4Addr(dip_addr))
|
||||
{
|
||||
time_t lt;
|
||||
lt = time(NULL);
|
||||
if( (memcmp(&s->sip, &s->dip, 32) < 0) & (lt >= s->begin_time) & (lt <= s->over_time))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,136 +0,0 @@
|
|||
#ifndef __HLIST_H
|
||||
#define __HLIST_H
|
||||
|
||||
struct hlist_head {
|
||||
struct hlist_node *first;
|
||||
};
|
||||
|
||||
struct hlist_node {
|
||||
struct hlist_node *next, **pprev;
|
||||
};
|
||||
|
||||
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
|
||||
|
||||
#define container_of(ptr, type, member) ({ \
|
||||
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
|
||||
(type *)( (char *)__mptr - offsetof(type,member) );})
|
||||
|
||||
#define HLIST_HEAD_INIT { .first = NULL }
|
||||
#define HLIST_HEAD(name) struct hlist_head name = { .first = NULL }
|
||||
|
||||
#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
|
||||
|
||||
static inline void INIT_HLIST_NODE(struct hlist_node *h)
|
||||
{
|
||||
h->next = NULL;
|
||||
h->pprev = NULL;
|
||||
}
|
||||
|
||||
static inline int hlist_unhashed(const struct hlist_node *h)
|
||||
{
|
||||
return !h->pprev;
|
||||
}
|
||||
|
||||
static inline int hlist_empty(const struct hlist_head *h)
|
||||
{
|
||||
return !h->first;
|
||||
}
|
||||
|
||||
static inline void __hlist_del(struct hlist_node *n)
|
||||
{
|
||||
struct hlist_node *next = n->next;
|
||||
struct hlist_node **pprev = n->pprev;
|
||||
*pprev = next;
|
||||
if (next)
|
||||
next->pprev = pprev;
|
||||
}
|
||||
|
||||
static inline void hlist_del(struct hlist_node *n)
|
||||
{
|
||||
__hlist_del(n);
|
||||
n->next = NULL;
|
||||
n->pprev = NULL;
|
||||
}
|
||||
|
||||
static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
|
||||
{
|
||||
struct hlist_node *first = h->first;
|
||||
n->next = first;
|
||||
if (first)
|
||||
first->pprev = &n->next;
|
||||
h->first = n;
|
||||
n->pprev = &h->first;
|
||||
}
|
||||
|
||||
|
||||
static inline void hlist_del_init(struct hlist_node *n)
|
||||
{
|
||||
if (!hlist_unhashed(n)) {
|
||||
__hlist_del(n);
|
||||
INIT_HLIST_NODE(n);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void hlist_add_before(struct hlist_node *n,
|
||||
struct hlist_node *next)
|
||||
{
|
||||
n->pprev = next->pprev;
|
||||
n->next = next;
|
||||
next->pprev = &n->next;
|
||||
*(n->pprev) = n;
|
||||
}
|
||||
|
||||
static inline void hlist_add_after(struct hlist_node *n,
|
||||
struct hlist_node *next)
|
||||
{
|
||||
next->next = n->next;
|
||||
n->next = next;
|
||||
next->pprev = &n->next;
|
||||
|
||||
if(next->next)
|
||||
next->next->pprev = &next->next;
|
||||
}
|
||||
|
||||
static inline void hlist_move_list(struct hlist_head *old,
|
||||
struct hlist_head *new)
|
||||
{
|
||||
new->first = old->first;
|
||||
if (new->first)
|
||||
new->first->pprev = &new->first;
|
||||
old->first = NULL;
|
||||
}
|
||||
|
||||
#define hlist_entry(ptr, type, member) container_of(ptr,type,member)
|
||||
|
||||
|
||||
#define hlist_for_each_safe(pos, n, head) \
|
||||
for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
|
||||
pos = n)
|
||||
|
||||
#define hlist_for_each_entry(tpos, pos, head, member) \
|
||||
for (pos = (head)->first; \
|
||||
pos && ({ prefetch(pos->next); 1;}) && \
|
||||
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
|
||||
pos = pos->next)
|
||||
|
||||
#define hlist_for_each_entry_continue(tpos, pos, member) \
|
||||
for (pos = (pos)->next; \
|
||||
pos && ({ prefetch(pos->next); 1;}) && \
|
||||
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
|
||||
pos = pos->next)
|
||||
|
||||
#define hlist_for_each_entry_from(tpos, pos, member) \
|
||||
for (; pos && ({ prefetch(pos->next); 1;}) && \
|
||||
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
|
||||
pos = pos->next)
|
||||
|
||||
#define hlist_for_each_entry_safe(tpos, pos, n, head, member) \
|
||||
for (pos = (head)->first; \
|
||||
pos && ({ n = pos->next; 1; }) && \
|
||||
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
|
||||
pos = n)
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -1,116 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include "hlist.h"
|
||||
#include "k-hashtable.h"
|
||||
|
||||
struct hlist_head *hash;
|
||||
struct hlist_node *p = NULL, *n = NULL ;
|
||||
int i = 0;
|
||||
USER_INFO *pNode ;
|
||||
|
||||
/*计算hash值 */
|
||||
struct hlist_head *call_hash(struct hlist_head *hash, uint32_t ip)
|
||||
{
|
||||
unsigned int val = ip % 100;
|
||||
return &hash[val];
|
||||
}
|
||||
|
||||
/*初始化函数 */
|
||||
int Init_hash()
|
||||
{
|
||||
hash = (struct hlist_head*)malloc(sizeof(*hash)*100);
|
||||
if(NULL == hash)
|
||||
{
|
||||
printf("alloc error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
for(i = 0; i < 100; i++)
|
||||
INIT_HLIST_HEAD(&hash[i]);
|
||||
}
|
||||
|
||||
|
||||
/*查找用户信息*/
|
||||
struct user_info *kfind_user(uint32_t user_ip)
|
||||
{
|
||||
hlist_for_each_safe(p,n,call_hash(hash,user_ip))
|
||||
{
|
||||
pNode = hlist_entry(p, struct user_info ,hnode);
|
||||
if(pNode != NULL)
|
||||
printf("user_id :%d\n",pNode->id);
|
||||
return pNode;
|
||||
}
|
||||
}
|
||||
|
||||
/*增加用户信息*/
|
||||
int kadd_user(uint32_t user_ip, int user_id)
|
||||
{
|
||||
USER_INFO *pNode =NULL;
|
||||
hlist_for_each_safe(p,n,call_hash(hash, user_ip)) /*查找ip是否存在hash表中 */
|
||||
{
|
||||
pNode = hlist_entry(p, struct user_info ,hnode);
|
||||
if(pNode != NULL)
|
||||
printf("IP ALEADY EXISTED\n");
|
||||
}
|
||||
|
||||
if (pNode == NULL)
|
||||
{
|
||||
pNode = (struct user_info *)malloc(sizeof(struct user_info));
|
||||
if (NULL == pNode)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
memset(pNode,0,sizeof(struct user_info));
|
||||
INIT_HLIST_NODE(&pNode->hnode);
|
||||
pNode->ip = user_ip;
|
||||
hlist_add_head(&pNode->hnode, call_hash(hash, user_ip));
|
||||
}
|
||||
pNode->id = user_id;
|
||||
|
||||
}
|
||||
|
||||
/*删除用户信息 */
|
||||
void kdelete_user(int user_ip)
|
||||
{
|
||||
hlist_for_each_safe(p,n,call_hash(hash,user_ip))
|
||||
{
|
||||
pNode = hlist_entry(p, struct user_info ,hnode);
|
||||
hlist_del(&pNode->hnode);
|
||||
free(pNode);
|
||||
}
|
||||
}
|
||||
|
||||
/*删除所有的hash节点 */
|
||||
void kdelete_all()
|
||||
{
|
||||
for(i = 0; i < 100; i++)
|
||||
{
|
||||
hlist_for_each_safe(p,n,&hash[i])
|
||||
{
|
||||
pNode = hlist_entry(p, struct user_info ,hnode);
|
||||
hlist_del(&pNode->hnode);
|
||||
free(pNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*打印所有信息信息 */
|
||||
void kprintf_users()
|
||||
{
|
||||
for(i = 0; i < 100; i++)
|
||||
{
|
||||
hlist_for_each_safe(p,n,&hash[i])
|
||||
{
|
||||
char str[32];
|
||||
pNode = hlist_entry(p, struct user_info ,hnode);
|
||||
if(pNode != NULL)
|
||||
inet_ntop(AF_INET, (void *)&pNode->ip, str, 32);
|
||||
printf("user_ip :%s user_id:%d\n", str, pNode->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
#ifndef K_HASHTABLE_H
|
||||
#define K_HASHTABLE_H
|
||||
#include <stdint.h>
|
||||
#include "hlist.h"
|
||||
|
||||
typedef struct user_info{
|
||||
struct hlist_node hnode;
|
||||
int id;
|
||||
uint32_t ip;
|
||||
}USER_INFO;
|
||||
|
||||
/*计算hash值 */
|
||||
struct hlist_head *call_hash(struct hlist_head *hash, uint32_t ip);
|
||||
|
||||
/*初始化函数 */
|
||||
int Init_hash();
|
||||
|
||||
/*查找用户信息*/
|
||||
struct user_info *kfind_user(uint32_t user_ip);
|
||||
|
||||
/*增加用户信息*/
|
||||
int kadd_user(uint32_t user_ip, int user_id);
|
||||
|
||||
/*删除用户信息 */
|
||||
void kdelete_user(int user_ip);
|
||||
|
||||
/*删除所有的hash节点 */
|
||||
void kdelete_all();
|
||||
|
||||
/*打印所有信息信息 */
|
||||
void kprintf_users();
|
||||
|
||||
#endif
|
|
@ -1,62 +0,0 @@
|
|||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int _valid_ipv4_port(const char *str, int port)
|
||||
{
|
||||
int ret;
|
||||
int fd;
|
||||
int i;
|
||||
volatile int local_errno;
|
||||
struct sockaddr_in addr;
|
||||
fd = socket(AF_INET,SOCK_STREAM,0); //初始化socket
|
||||
|
||||
|
||||
if(fd ==-1) //检查是否正常初始化socket
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
local_errno = errno;
|
||||
|
||||
ret = inet_pton(AF_INET, str ,&addr.sin_addr);
|
||||
printf("the value of ret is:%d\n",ret);
|
||||
if(ret > 0)
|
||||
{
|
||||
fprintf(stderr, "\"%s\" is a vaild IPv4 address\n", str);
|
||||
|
||||
addr.sin_family = AF_INET; //地址结构的协议簇
|
||||
addr.sin_port=htons(port); //地址结构的端口地址,网络字节序
|
||||
printf("the value of str:%s\n", str);
|
||||
i = (bind(fd, (struct sockaddr*)&addr, sizeof(struct sockaddr)));
|
||||
printf("the value of i:%d\n", i);
|
||||
|
||||
if( i < 0)
|
||||
{
|
||||
printf("port %d has been used. \n", port);
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("port %d is ok. \n", port);
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
else if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "EAFNOSUPPORT: %s\n", strerror(local_errno));
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "\"%s\" is not a vaild IPv4 address\n", str);
|
||||
return -1;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue