This commit is contained in:
gechangwei 2019-08-06 15:16:06 +08:00
commit 1ab7215e2d
37 changed files with 1088 additions and 297 deletions

14
Common/log_types.h Executable file
View File

@ -0,0 +1,14 @@
#ifndef _LOG_CONFIG_API_H
#define _LOG_CONFIG_API_H
#include "ulog_api.h"
typedef struct _log_console {
u8 level;
u8 on;
char module_name[MAX_MODULE_NAME_SZ];
} log_console_t;
typedef log_console_t log_pty_t;
#endif

View File

@ -72,10 +72,22 @@ extern "C" {
#define s2j_struct_get_basic_element(to_struct, from_json, type, element) \
S2J_STRUCT_GET_BASIC_ELEMENT(to_struct, from_json, type, element)
#define s2j_struct_get_string_element(to_struct, from_json, element, n) \
S2J_STRUCT_GET_STRING_ELEMENT_N(to_struct, from_json, element, n)
/* Get array type element for structure object */
#define s2j_struct_get_array_element(to_struct, from_json, type, element) \
S2J_STRUCT_GET_ARRAY_ELEMENT(to_struct, from_json, type, element)
/* Get array type element for structure object */
#define s2j_struct_get_array_element_n(to_struct, from_json, type, element, NUM) \
S2J_STRUCT_GET_ARRAY_ELEMENT_N(to_struct, from_json, type, element)
/* Get array type element for structure object */
#define s2j_struct_get_array_string_n(to_struct, from_json, element, NUM, BUFFLEN) \
S2J_STRUCT_GET_STR_ARRAY_ELEMENT_N(to_struct, from_json, element, NUM, BUFFLEN)
/* Get child structure type element for structure object */
#define s2j_struct_get_struct_element(child_struct, to_struct, child_json, from_json, type, element) \
S2J_STRUCT_GET_STRUCT_ELEMENT(child_struct, to_struct, child_json, from_json, type, element)

View File

@ -52,8 +52,9 @@ typedef struct {
#define S2J_STRUCT_GET_STRING_ELEMENT_N(to_struct, from_json, _element, n) \
json_temp = cJSON_GetObjectItem(from_json, #_element); \
if (json_temp && json_temp->valuestring && n > 1)\
strncpy((to_struct)->_element, json_temp->valuestring, n-1);
if (json_temp && json_temp->valuestring && n > 1){\
strncpy((to_struct)->_element, json_temp->valuestring, n - 1);\
to_struct->_element[n - 1] = '\0';}
#define S2J_STRUCT_GET_double_ELEMENT(to_struct, from_json, _element) \
json_temp = cJSON_GetObjectItem(from_json, #_element); \
@ -65,6 +66,9 @@ typedef struct {
#define S2J_STRUCT_ARRAY_GET_string_ELEMENT(to_struct, from_json, _element, index) \
strcpy((to_struct)->_element[index], from_json->valuestring);
#define S2J_STRUCT_ARRAY_GET_string_ELEMENT_n(to_struct, from_json, _element, index, maxlen) \
strncpy((to_struct)->_element[index], from_json->valuestring, maxlen - 1);
#define S2J_STRUCT_ARRAY_GET_double_ELEMENT(to_struct, from_json, _element, index) \
(to_struct)->_element[index] = from_json->valuedouble;
@ -145,6 +149,39 @@ typedef struct {
} \
}
#define S2J_STRUCT_GET_ARRAY_ELEMENT_N(to_struct, from_json, type, _element, NUM) \
{ \
cJSON *array, *array_element; \
size_t index = 0, size = 0; \
array = cJSON_GetObjectItem(from_json, #_element); \
if (array) { \
size = cJSON_GetArraySize(array); \
while (index < size && index < NUM) { \
array_element = cJSON_GetArrayItem(array, index); \
if (array_element) S2J_STRUCT_ARRAY_GET_ELEMENT(to_struct, array_element, type, _element, index++); \
} \
} \
}
#define S2J_STRUCT_GET_STR_ARRAY_ELEMENT_N(to_struct, from_json, _element, NUM, LEN) \
{ \
cJSON *array, *array_element; \
size_t index = 0, size = 0; \
array = cJSON_GetObjectItem(from_json, #_element); \
if (array) { \
size = cJSON_GetArraySize(array); \
NUM = size;\
(to_struct)->_element = (char **)malloc(size * sizeof(char *));\
memset((to_struct)->_element, 0, size * sizeof(char *));\
while (index < size) { \
array_element = cJSON_GetArrayItem(array, index); \
(to_struct)->_element[index] = (char *)calloc(1, LEN);\
if (array_element) S2J_STRUCT_ARRAY_GET_string_ELEMENT_n(to_struct, array_element, _element, index++, LEN); \
} \
} \
}
#define S2J_STRUCT_GET_STRUCT_ELEMENT(child_struct, to_struct, child_json, from_json, type, _element) \
type *child_struct = &((to_struct)->_element); \
cJSON *child_json = cJSON_GetObjectItem(from_json, #_element);

View File

@ -28,9 +28,9 @@ MAKE_FLAGS += -j$(shell cat /proc/cpuinfo | grep processor | wc -l)
endif
endif
.PHONY : demo conntrack netlink trace openrpc redismq usermanager configm ulog database webauth khashtable
.PHONY : openrpc ulog demo conntrack netlink trace redismq usermanager configm database webauth khashtable
all: demo conntrack netlink trace openrpc redismq usermanager configm ulog database webauth khashtable
all: openrpc ulog demo conntrack netlink trace redismq usermanager configm database webauth khashtable
ifeq ($(OPT), install)
#$(shell `find ../release -name "*.zip" -delete`)

View File

@ -28,19 +28,22 @@ VPATH = ../user/configm/config-server
COMMON_SRCS = configserver.c \
netconfig/ipconfig/ipconfig.c netconfig/parsefile.c \
authfree_config/authfree.c \
netconfig/bridge/brconfig.c netconfig/bridge/brnetlink.c \
netconfig/bridge/libbridge/libbridge_if.c netconfig/bridge/libbridge/libbridge_init.c netconfig/bridge/libbridge/libbridge_devif.c\
authfree_config/authfree.c \
localportal_config/localportal.c \
userlock_config/userlock.c \
jumppage_config/jumppage.c \
agingtime_config/agingtime.c \
user_manager_config/user_group_config.c user_manager_config/user_account_config.c user_manager_config/usermanager-server/array_index.c \
user_manager_config/usermanager-server/user_group.c user_manager_config/usermanager-server/user_mod.c user_manager_config/usermanager-server/user.c
user_manager_config/usermanager-server/user_group.c user_manager_config/usermanager-server/user_mod.c user_manager_config/usermanager-server/user.c \
log_config/log_config_console.c log_config/log_config_init.c
# MRS Board Source Files
PLAT_LINUX_SRCS = $(COMMON_SRCS)
PLAT_ARM64_SRCS = $(COMMON_SRCS)
COMMOM_CFLAGS = -I../user/configm/config-server/include -I../../Common -I../common/redismq -I../common/configm -I../common/rpc -I../common/rpc/hashtable
COMMOM_CFLAGS = -I../user/configm/config-server/include -I../../Common -I../common/redismq -I../common/configm -I../common/rpc -I../common/rpc/hashtable -I../common/ulog -I../user/configm/config-server/netconfig/bridge/include
# gcc CFLAGS
PLAT_ARM64_CFLAGS := $(COMMOM_CFLAGS) -I../thirdparty/arm64/usr/local/include
PLAT_LINUX_CFLAGS := $(COMMOM_CFLAGS) -I../thirdparty/x86_64/usr/local/include
@ -49,10 +52,10 @@ PLAT_ARM64_LDFLAGS :=
PLAT_LINUX_LDFLAGS :=
#gcc libs
ARM64_LIBS := ../thirdparty/arm64/libev-arm64.so ./libopenrpc-arm64.so ./libnetlinku-arm64.so ./libredismq-arm64.so
ARM64_LIBS := ../thirdparty/arm64/libev-arm64.so ./libopenrpc-arm64.so ./libnetlinku-arm64.so ./libredismq-arm64.so ./libulogapi-arm64.so
ARM64_LIBS += -lpthread -lm -lcjson -levent -ljson-c -lhiredis
LINUX_LIBS := ../thirdparty/x86_64/libev-linux.so ./libopenrpc-linux.so ./libnetlinku-linux.so ./libredismq-linux.so
LINUX_LIBS := ../thirdparty/x86_64/libev-linux.so ./libopenrpc-linux.so ./libnetlinku-linux.so ./libredismq-linux.so ./libulogapi-linux.so
LINUX_LIBS += -lpthread -lm -lcjson -levent -ljson-c -lhiredis
ifeq ($(PLAT_ARM64), TRUE)

View File

@ -34,7 +34,7 @@ PLAT_LINUX_SRCS = $(COMMON_SRCS)
PLAT_ARM64_SRCS = $(COMMON_SRCS)
# gcc CFLAGS
PLAT_ARM64_CFLAGS := -fPIC -I../../Common -I../common/rpc -I../user/ulog
PLAT_ARM64_CFLAGS := -fPIC -I../../Common -I../common/rpc -I../common/ulog -I../user/ulog
PLAT_LINUX_CFLAGS := $(PLAT_ARM64_CFLAGS)

0
Platform/common/configm/configmapi.h Normal file → Executable file
View File

View File

@ -75,12 +75,12 @@ do { \
}\
} while (0)
#define ASSERT_PTR_RET(ptr) \
#define ASSERT_PTR(ptr, RET_REASON) \
do { \
if (ptr == NULL) \
{\
rpc_log_error("ret error: %s\n", rpc_code_format(RET_NULLP));\
return RET_NULLP;\
rpc_log_error("Assert PTR NULL\n");\
return RET_REASON;\
}\
} while (0)

11
Platform/common/ulog/ulog_in.h Executable file
View File

@ -0,0 +1,11 @@
#ifndef _ULOG_IN_H
#define _ULOG_IN_H
#define SERVICE_LOG_FILE_NAME "log-file"
#define SERIVCE_LOG_CONSOLE_NAME "log-console"
#define SERVICE_LOG_PTY_NAME "log-pty"
#define SERVICE_LOG_REMOTE_NAME "log-remote"
#define CONF_LOG_CONSOLE_FUNC "conf_log_console"
#endif

View File

@ -11,6 +11,7 @@
config_service_t g_config_service[] = CONFIG_SERVICE_ARRAY;
config_init_t g_config_init[] = CONFIG_INIT_ARRAY;
void test_big_data(rpc_conn *conn, pointer input, int input_len, void* data) {
char buf[input_len];
@ -145,6 +146,23 @@ ret_code cm_config_get_allconfig(uint source,
return ret;
}
void cm_config_module_init()
{
int len = sizeof(g_config_init) / sizeof(config_init_t);
config_init_t *config_svr;
int config_idx;
for(config_idx = 0; config_idx < len; config_idx++)
{
config_svr = &(g_config_init[config_idx]);
rpc_log_info("MODULE %d init\n", config_svr->config_mudlue);
if(config_svr->init_callback)
{
config_svr->init_callback();
}
}
}
/* 配置恢复 */
void cm_config_recovery()
@ -382,6 +400,9 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
/* 模块初始化 */
cm_config_module_init();
/* 配置恢复 */
cm_config_recovery();

View File

@ -1,6 +1,8 @@
#ifndef BRCONFIG_H_
#define BRCONFIG_H_
#include "list.h"
#define BR_NAMSIZ INTERFACE_NAMSIZ
#define MAC_STRSIZ 32
#define LOCAL_STRSIZ 16
@ -11,13 +13,15 @@
typedef enum {
BR_CREATE_EVENT = 1,
BR_DELETE_EVENT,
BR_CREATE_EVENT_PRE,
BR_DELETE_EVENT_PRE,
BR_IF_JOIN_EVENT,
BR_IF_LEAVE_EVENT,
BR_IF_JOIN_EVENT_PRE,
BR_IF_LEAVE_EVENT_PRE,
BR_EVENT_INVALID
} BR_EVENT_TYPE;
typedef int (*BR_EVENT_FUNC)(BR_EVENT_TYPE event_type, br_event_t event_arg);
/************************************************************/
/* 结构体 */
/************************************************************/
@ -28,6 +32,9 @@ struct _br_event {
};
typedef struct _br_event br_event_t;
typedef int (*BR_EVENT_FUNC)(BR_EVENT_TYPE event_type,
br_event_t event_arg);
struct _br_event_node {
struct hlist_node list;
BR_EVENT_TYPE br_event;
@ -44,12 +51,6 @@ typedef struct _br_event_head br_event_head_t;
/* 临时数据结构 */
struct _brif_temp {
int index;
char *if_list;
};
typedef struct _brif_temp br_if_temp_t;
struct _br_temp {
char *br_name;
boolean result;
@ -60,7 +61,7 @@ typedef struct _br_temp br_temp_t;
struct _br_config {
char br_name[BR_NAMSIZ];
int port_num;
char *ports;
char **ports;
};
typedef struct _br_config br_config_t;
@ -79,7 +80,7 @@ typedef struct _br_config_string br_config_string_t;
struct _br_if_config_string {
int config_type;
char br_name[BR_NAMSIZ];
char *ports;
char **ports;
};
typedef struct _br_if_config_string br_if_config_string_t;
@ -109,8 +110,14 @@ typedef struct _br_fdb_status br_fdb_status_t;
/* 提供给其他模块调用的函数 */
/************************************************************/
/* 添加桥sys_err 表示内核返回的系统错误码*/
ret_code br_bridge_add(char *br_name, int *sys_err);
/* 删除桥sys_err 表示内核返回的系统错误码 */
ret_code br_bridge_del(char * br_name, int *sys_err);
/* 通过接口名获取所在桥名 */
int br_if_bridge_get(char *port_name , char *br_name);
ret_code br_if_bridge_get(char *port_name , char *br_name);
/* 向桥中添加接口 */
ret_code br_if_bridge_add(char *br_name, char *port_list,
@ -123,6 +130,14 @@ ret_code br_if_bridge_del(char *br_name, char *port_list,
/* 获取桥中接口数量 */
int br_if_bridge_num(char *br_name);
/* 注册桥事件通知函数 */
ret_code br_event_register(BR_EVENT_TYPE event_type,
BR_EVENT_FUNC event_func);
/* 去注册桥事件通知函数 */
ret_code br_event_unregister(BR_EVENT_TYPE event_type,
BR_EVENT_FUNC event_func);
/* **********************************************************/
/* 配置管理注册函数 */
/************************************************************/
@ -159,4 +174,7 @@ ret_code br_fdb_config_get(uint source,
pointer input, int input_len,
pointer output, int *output_len);
/* 模块初始化 */
ret_code br_bridge_init();
#endif

79
Platform/user/configm/config-server/include/configm.h Normal file → Executable file
View File

@ -7,11 +7,13 @@
#include "../../../../../Common/commuapinl.h"
#include "../user_manager_config/user_group_config.h"
#include "../user_manager_config/user_account_config.h"
#include "log_config.h"
#include "authfree.h"
#include "localportal.h"
#include "jumppage.h"
#include "userlock.h"
#include "agingtime.h"
#include "brconfig.h"
/* 类型定义 */
@ -24,9 +26,16 @@
/*PORTAL SERVER CONFIG */
#define LOCALAUTH_CONFIG_MODULE 0x00000003
#define LOG_CONFIG_MODULE 0x00000004
/* config id define*/
#define IPCONFIG_V4 (uint64)((uint64)NETCONFIG_MODULE<<32|1)
#define IPCONFIG_V4 (uint64)((uint64)NETCONFIG_MODULE<<32|1)
#define BR_CONFIG (uint64)((uint64)NETCONFIG_MODULE<<32|2)
#define BRIF_CONFIG (uint64)((uint64)NETCONFIG_MODULE<<32|3)
#define BRFDB_CONFIG (uint64)((uint64)NETCONFIG_MODULE<<32|4)
#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)
@ -37,6 +46,19 @@
#define JUMPPAGE_CONFIG (uint64)((uint64)LOCALAUTH_CONFIG_MODULE<<32|4)
#define AGINGTIME_CONFIG (uint64)((uint64)LOCALAUTH_CONFIG_MODULE<<32|5)
#define LOG_CONFIG_CONSOLE (uint64)((uint64)LOG_CONFIG_MODULE<<32|1)
#define CONFIG_INIT_ARRAY \
{\
{ \
NETCONFIG_MODULE, \
br_bridge_init \
}, \
{ \
LOG_CONFIG_MODULE, \
log_config_init \
} \
}
/*
1ID
@ -55,17 +77,42 @@
IPCONFIG_V4, \
CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \
FALSE, \
FALSE, \
ip_config_chk, \
ip_config_proc, \
ip_config_get, \
ip_config_get_all \
},\
{\
BR_CONFIG, \
CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \
FALSE, \
br_config_chk, \
br_config_proc, \
NULL, \
NULL \
},\
{\
BRIF_CONFIG, \
CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \
FALSE, \
br_if_config_chk, \
br_if_config_proc, \
br_if_config_get, \
br_if_config_get_all \
},\
{\
BRFDB_CONFIG, \
CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \
FALSE, \
br_fdb_config_chk, \
NULL, \
br_fdb_config_get, \
NULL \
},\
{\
USER_MANAGER_CONFIG_GROUP, \
CONFIG_FROM_WEB, \
FALSE, \
FALSE, \
usergroup_config_chk, \
usergroup_config_proc, \
usergroup_config_get, \
@ -75,7 +122,6 @@
PORTALSERVER_CONFIG, \
CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \
FALSE, \
FALSE, \
portalserver_config_chk, \
portalserver_config_proc, \
NULL, \
@ -85,7 +131,6 @@
AUTHFREE_CONFIG, \
CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \
FALSE, \
FALSE, \
freeauth_config_chk, \
freeauth_config_proc, \
NULL, \
@ -95,7 +140,6 @@
USERLOCK_CONFIG, \
CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \
FALSE, \
FALSE, \
userlock_config_chk, \
userlock_config_proc, \
NULL, \
@ -105,7 +149,6 @@
JUMPPAGE_CONFIG, \
CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \
FALSE, \
FALSE, \
NULL, \
jumppage_config_proc, \
NULL, \
@ -115,7 +158,6 @@
AGINGTIME_CONFIG, \
CONFIG_FROM_WEB|CONFIG_FROM_NETOPEER, \
FALSE, \
FALSE, \
agingtime_config_chk, \
agingtime_config_proc, \
agingtime_config_get, \
@ -125,14 +167,24 @@
USER_MANAGER_CONFIG_USER, \
CONFIG_FROM_WEB, \
FALSE, \
FALSE, \
user_config_chk, \
user_config_proc, \
user_config_get, \
user_config_get_all \
},\
{\
LOG_CONFIG_CONSOLE, \
CONFIG_FROM_WEB, \
FALSE, \
log_console_config_chk, \
log_console_config_proc, \
NULL, \
NULL \
}\
}
typedef ret_code (*cm_config_init)();
typedef ret_code (*cm_config_chk)(uint source, uint *config_type,
pointer input, int *input_len,
pointer output, int *output_len);
@ -148,12 +200,19 @@ typedef ret_code (*cm_config_get)(uint source,
typedef ret_code (*cm_config_get_all)(uint source,
pointer output, int *output_len);
/* 配置注册 */
struct _config_init {
uint config_mudlue;
cm_config_init init_callback;
};
typedef struct _config_init config_init_t;
/* 配置注册 */
struct _config_service {
uint64 config_id; /* 配置ID全局唯一用于寻找对应的配置业务*/
uint config_src; /* 配置源检查,全局唯一,用于寻找对应的配置业务,从低位到高位第一位表示web后续配置扩展 */
boolean recovery; /* 配置恢复处理函数如果为FALSE则不进行配置恢复 */
boolean multi_inst; /* 是否是多实例 */
cm_config_chk chk_callback; /* 配置校验回调函数 */
cm_config_proc proc_callback; /* 配置接口 */
cm_config_get get_callback; /* 获取配置接口 */

View File

@ -0,0 +1,17 @@
#ifndef _LOG_CONFIG_H
#define _LOG_CONFIG_H
#include <stdio.h>
#include "rpc_types.h"
#include "rpc_common.h"
ret_code log_config_init();
ret_code log_console_config_chk(uint source, uint *config_type,
pointer input, int *input_len,
pointer output, int *output_len);
ret_code log_console_config_proc(uint source, uint config_type,
pointer input, int input_len,
pointer output, int *output_len);
#endif

View File

@ -1,10 +1,19 @@
#ifndef PARSEFILE_H_
#define PARSEFILE_H_
#include "rpc_common.h"
#define IFCONFIG_PATH "/etc/network/interfaces"
#define IF_BUFF_LEN 128
ret_code if_conf_file_add(char *if_name);
ret_code if_conf_file_del(char *if_name);
ret_code if_conf_file_set(char *if_name, char *conf_name, char *conf_buff);
ret_code if_conf_file_get(char *if_name, char *conf_name, char *conf_buff);
void ip_conf_file_set(char *if_name, char *conf_name, char *conf_buff);
void ip_conf_file_del(char *if_name, char *conf_buff);
ret_code del_sub_string(char *str_in,char *str_sub);
#endif

View File

@ -0,0 +1,63 @@
#include <cjson/cJSON.h>
#include "rpc_server.h"
#include "log_config.h"
#include "configm.h"
#include "log_types.h"
#include "ulog_in.h"
#include "log_config_h.h"
ret_code log_console_config_chk(uint source, uint *config_type,
pointer input, int *input_len,
pointer output, int *output_len)
{
if (input == NULL) {
ULOG_ERR(g_log_h, "input can't null");
return RET_INPUTERR;
}
cJSON *json_obj = cJSON_Parse(input);
if(!json_obj)
{
ULOG_ERR(g_log_h, "Error log console format");
return RET_INPUTERR;
}
ULOG_DEBUG("json input: %s", cJSON_Print(json_obj));
s2j_create_struct_obj(log_console, log_console_t);
if(log_console == NULL)
{
cJSON_Delete(json_obj);
ULOG_ERR(g_log_h, "Creating log console of object is failure");
return RET_NOMEM;
}
s2j_struct_get_basic_element(log_console, json_obj, int, level);
s2j_struct_get_basic_element(log_console, json_obj, int, on);
S2J_STRUCT_GET_STRING_ELEMENT_N(log_console, json_obj, module_name, MAX_MODULE_NAME_SZ);
*input_len = sizeof(*log_console);
memcpy(input, log_console, *input_len);
return RET_OK;
}
ret_code log_console_config_proc(uint source, uint config_type,
pointer input, int input_len,
pointer output, int *output_len)
{
if ((input == NULL)
&& input_len < sizeof(log_console_t)) {
return RET_INPUTERR;
}
ret_code ret = rpc_client_call(g_log_client, SERIVCE_LOG_CONSOLE_NAME,
CONF_LOG_CONSOLE_FUNC, input, input_len, NULL, NULL);
if (ret != RET_OK) {
ULOG_ERR(g_log_h, "rpc call is failure[ret:%u, method:%s]", ret, CONF_LOG_CONSOLE_FUNC);
}
return ret;
}

View File

@ -0,0 +1,7 @@
#ifndef _LOG_CONFIG_H_H
#define _LOG_CONFIG_H_H
extern rpc_client *g_log_client;
extern ulog_t *g_log_h;
#endif

View File

@ -0,0 +1,27 @@
#include "rpc_server.h"
#include "log_config.h"
#include "ulog_in.h"
#include "ulog_api.h"
rpc_client *g_log_client;
ulog_t *g_log_h;
ret_code log_config_init()
{
g_log_h = ulog_init("log_config", 1);
if (g_log_h) {
fprintf(stderr, "Initiating log_config is failure");
return RET_ERR;
}
g_log_client = rpc_client_connect_ex(RPC_MODULE_SYSLOG_NAME);
if (g_log_client == NULL) {
ULOG_ERR(g_log_h, "Initiating rpc client is failure");
return RET_ERR;
}
return RET_OK;
}

View File

@ -4,17 +4,19 @@
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include "list.h"
#include "configm.h"
#include "brconfig.h"
#include "rpc.h"
#include "parsefile.h"
#include "libbridge.h"
#include "brnetlink.h"
#include "list.h"
#include "parsefile.h"
#include "libbridge.h"
#include "libbridge_private.h"
#ifndef DESC("事件通知函数")
struct br_event_head_t br_event_tbl = {.lock = 0, .init = false};
/* 事件通知函数 */
br_event_head_t br_event_tbl = {.head.first = NULL, .lock = 0, .init = FALSE};
int br_invoke_event(BR_EVENT_TYPE event_type, br_event_t event_arg)
{
@ -26,50 +28,52 @@ int br_invoke_event(BR_EVENT_TYPE event_type, br_event_t event_arg)
if(hnode->br_event == event_type)
{
hnode->event_func(event_type, event_arg);
rpc_log_info("br event:%d\n", event_type);
}
}
pthread_mutex_unlock(&(br_event_tbl.lock));
}
int br_event_register(BR_EVENT_TYPE event_type, BR_EVENT_FUNC event_func)
ret_code br_event_register(BR_EVENT_TYPE event_type, BR_EVENT_FUNC event_func)
{
br_event_node_t *hnode = NULL;
if(br_event_tbl.init == false)
{ INIT_HLIST_HEAD(&(br_event_tbl.head);
if(br_event_tbl.init == FALSE)
{
INIT_HLIST_HEAD(&(br_event_tbl.head));
pthread_mutex_init(&(br_event_tbl.lock), NULL);
br_event_tbl.init = true;
br_event_tbl.init = TRUE;
}
rpc_log_info("br event register:%d\n", event_type);
hnode = (br_event_node_t *)rpc_new0(br_event_node_t, 1);
if(!hnode)
{
rpc_log_error("br_event_register failed\n");
return -1;
}
ASSERT_PTR(hnode, RET_NOMEM);
INIT_HLIST_NODE(&hnode->list);
hnode->br_event = event_type;
hnode->event_func = event_func;
pthread_mutex_lock(&(br_event_tbl.lock));
pthread_mutex_lock(&(br_event_tbl.lock));
hlist_add_head(&hnode->list, &(br_event_tbl.head));
pthread_mutex_unlock(&(br_event_tbl.lock));
return 0;
return RET_OK;
}
int br_event_unregister(BR_EVENT_TYPE event_type, BR_EVENT_FUNC event_func)
ret_code br_event_unregister(BR_EVENT_TYPE event_type, BR_EVENT_FUNC event_func)
{
br_event_node_t *hnode = NULL;
struct hlist_node *n;
if(br_event_tbl.init == false)
if(br_event_tbl.init == FALSE)
{
return 0;
return RET_OK;
}
rpc_log_info("br event unregister:%d\n", event_type);
pthread_mutex_lock(&(br_event_tbl.lock));
hlist_for_each_entry_safe(hnode, n, &(br_event_tbl.head), list)
{
@ -83,23 +87,20 @@ int br_event_unregister(BR_EVENT_TYPE event_type, BR_EVENT_FUNC event_func)
}
pthread_mutex_unlock(&(br_event_tbl.lock));
return 0;
return RET_OK;
}
#endif
#ifndef DESC("桥配置辅助函数")
/* 桥配置辅助函数 */
int br_copy_port_name(const char *b, const char *p, void *arg)
{
br_if_temp_t *br_if = (br_if_temp_t *)arg;
char *dst_ptr = NULL;
br_config_t *br_if = (br_config_t *)arg;
br_if->if_list = realloc(br_if->if_list, INTERFACE_NAMSIZ);
ASSERT_PTR_RET(br_if->if_list);
br_if->ports[br_if->port_num] = rpc_new0(char, INTERFACE_NAMSIZ);
ASSERT_PTR(br_if->ports[br_if->port_num], RET_NULLP);
dst_ptr = br_if->if_list + br_if->index * INTERFACE_NAMSIZ
strncpy(dst_ptr, p, INTERFACE_NAMSIZ - 1);
strncpy(br_if->ports[br_if->port_num], p, INTERFACE_NAMSIZ - 1);
br_if->index++;
br_if->port_num++;
return 0;
}
@ -115,13 +116,13 @@ ret_code br_name_chk(char *br_name)
return RET_OK;
}
int br_name_cmp(char *br_name, void *args)
int br_name_cmp(const char *br_name, void *args)
{
br_temp_t *cmp_args = (br_temp_t *)args;
if(strcmp(br_name, cmp_args->br_name) == 0)
{
cmp_args->result = true;
cmp_args->result = TRUE;
return 1;
}
@ -130,7 +131,7 @@ int br_name_cmp(char *br_name, void *args)
boolean br_is_exist(char *br_name)
{
br_temp_t cmp_args = {br_name, false};
br_temp_t cmp_args = {br_name, FALSE};
br_foreach_bridge(br_name_cmp, &cmp_args);
@ -155,14 +156,14 @@ ret_code br_if_bridge_get(char *port_name, char* br_name)
return RET_NOTFOUND;
}
ret_code br_if_bridge_check(char *port_list, int cnt, uint config_type)
ret_code br_if_bridge_check(char **port_list, int cnt, uint config_type)
{
char *ptr_name = NULL;
int i;
for(i = 0; i< cnt; i++)
{
ptr_name = port_list + INTERFACE_NAMSIZ * i;
ptr_name = port_list [i];
if (if_nametoindex(ptr_name) == 0)
{
return RET_NOTFOUND;
@ -184,26 +185,79 @@ ret_code br_if_bridge_check(char *port_list, int cnt, uint config_type)
return RET_OK;
}
ret_code br_if_bridge_add(char * br_name, char *port_list, int cnt, int *sys_err)
ret_code br_save_file(BR_EVENT_TYPE event_type,
char *br_name, char *port_name)
{
char *key_str = "bridge_ports";
char config_str[IF_BUFF_LEN] = {0};
ret_code ret;
switch(event_type)
{
case BR_CREATE_EVENT:
if_conf_file_add(br_name);
break;
case BR_DELETE_EVENT:
if_conf_file_del(br_name);
break;
case BR_IF_JOIN_EVENT:
if(if_conf_file_get(br_name, key_str, config_str) == RET_OK)
{
if(strstr(config_str, port_name) != NULL)
{
return RET_OK;
}
strcat(config_str, " ");
strcat(config_str, port_name);
}
if_conf_file_set(br_name, key_str, config_str);
break;
case BR_IF_LEAVE_EVENT:
if(if_conf_file_get(br_name, key_str, config_str) == RET_OK)
{
if(strstr(config_str, port_name) != NULL)
{
del_sub_string(config_str, port_name);
rpc_log_info("BR_IF_LEAVE_EVENT: %s\n", config_str);
if_conf_file_set(br_name, key_str, config_str);
return RET_OK;
}
}
break;
default:
break;
}
return RET_OK;
}
ret_code br_if_bridge_add(char *br_name, char *port_list, int cnt, int *sys_err)
{
br_event_t event_arg = {0};
ret_code ret = RET_OK;
char *port_name;
int err = 0;
int i;
for(i = 0; i < cnt)
for(i = 0; i < cnt; i++)
{
br_invoke_event(BR_IF_JOIN_EVENT_PRE, event_arg);
port_name = port_list + INTERFACE_NAMSIZ * i;
err = br_add_interface(br_name, port_name);
if(err != 0)
{
sys_err = err;
*sys_err = err;
ret = RET_SYSERR;
continue;
}
br_event_t event_arg = {br_name, port_name};
event_arg.br_name = br_name;
event_arg.if_name = port_name;
br_invoke_event(BR_IF_JOIN_EVENT, event_arg);
br_save_file(BR_IF_JOIN_EVENT, br_name, port_name);
}
return ret;
@ -211,24 +265,30 @@ ret_code br_if_bridge_add(char * br_name, char *port_list, int cnt, int *sys_err
ret_code br_if_bridge_del(char * br_name, char *port_list, int cnt, int *sys_err)
{
br_event_t event_arg = {0};
ret_code ret = RET_OK;
char *port_name;
char *port_name;
int err = 0;
int i;
for(i = 0; i < cnt)
for(i = 0; i < cnt; i++)
{
br_invoke_event(BR_IF_LEAVE_EVENT_PRE, event_arg);
port_name = port_list + INTERFACE_NAMSIZ * i;
err = br_del_interface(br_name, port_name);
if(err != 0)
{
sys_err = err;
*sys_err = err;
ret = RET_SYSERR;
continue;
}
br_event_t event_arg = {br_name, port_name};
event_arg.br_name = br_name;
event_arg.if_name = port_name;
br_invoke_event(BR_IF_LEAVE_EVENT, event_arg);
br_save_file(BR_IF_LEAVE_EVENT, br_name, port_name);
}
return ret;
@ -237,6 +297,7 @@ ret_code br_if_bridge_del(char * br_name, char *port_list, int cnt, int *sys_err
int br_if_bridge_num(char *br_name)
{
int cnt = 0;
int err = 0;
err = br_for_port_num(br_name, &cnt);
cnt = (err != 0) ? 0 : cnt;
@ -244,10 +305,12 @@ int br_if_bridge_num(char *br_name)
return cnt;
}
ret_code br_bridge_add(char * br_name, int *sys_err)
ret_code br_bridge_add(char *br_name, int *sys_err)
{
br_event_t event_arg = {br_name, NULL};
int sys_ret = 0;
br_invoke_event(BR_CREATE_EVENT_PRE, event_arg);
sys_ret = br_add_bridge(br_name);
*sys_err = sys_ret;
@ -258,7 +321,9 @@ ret_code br_bridge_add(char * br_name, int *sys_err)
}
br_invoke_event(BR_CREATE_EVENT, event_arg);
br_save_file(BR_CREATE_EVENT, br_name, NULL);
return RET_OK;
}
@ -267,6 +332,8 @@ ret_code br_bridge_del(char * br_name, int *sys_err)
br_event_t event_arg = {br_name, NULL};
int sys_ret = 0;
br_invoke_event(BR_DELETE_EVENT_PRE, event_arg);
sys_ret = br_del_bridge(br_name);
*sys_err = sys_ret;
@ -276,22 +343,20 @@ ret_code br_bridge_del(char * br_name, int *sys_err)
}
br_invoke_event(BR_DELETE_EVENT, event_arg);
br_save_file(BR_DELETE_EVENT, br_name, NULL);
return RET_OK;
}
#endif
#ifndef DESC("桥配置json格式转换函数")
/* 桥配置json格式转换函数 */
ret_code br_config_json_parse(pointer input, uint *conf_type, char *br_name)
{
cJSON *json_obj;
json_obj = cJSON_Parse(input);
ASSERT_PTR_RET(json_obj);
ASSERT_PTR(json_obj, RET_NULLP);
rpc_log_info("json input:\n %s\n", cJSON_Print(json_obj));
@ -325,7 +390,7 @@ int br_json_to_string( cJSON *json_obj, pointer output)
return 0;
}
json_str = cJSON_PrintUnformatted(json_array);
json_str = cJSON_PrintUnformatted(json_obj);
output_len = strlen(json_str) + 1;
if(output_len > CM_BUFF_SIZE)
@ -343,50 +408,74 @@ int br_json_to_string( cJSON *json_obj, pointer output)
return output_len;
}
cJSON *br_config_format_json(br_config_t *br_config)
cJSON *br_config_format_json(br_config_t *br_if)
{
cJSON *json_obj;
s2j_create_json_obj(json_obj);
if(json_obj == NULL)
{
return NULL;
}
ASSERT_PTR(json_obj, NULL);
s2j_json_set_basic_element(json_obj, br_config, string, br_name);
s2j_json_set_array_element(json_obj, br_config, string,
ports, br_config->port_num);
s2j_json_set_basic_element(json_obj, br_if, string, br_name);
if(br_if->port_num)
{
s2j_json_set_array_element(json_obj, br_if, string, ports, br_if->port_num);
}
if (DEBUG_INFO)
{
char *json_str;
json_str = cJSON_PrintUnformatted(json_obj);
rpc_log_info("bridge info: %s", json_str);
rpc_free(json_str);
}
return json_obj;
}
ret_code br_bridge_info( char *br_name, cJSON *json_obj, int *err)
ret_code br_bridge_info(const char *br_name, cJSON **json_obj, int *err)
{
ret_code ret = RET_OK;
br_if_temp_t br_if = {0};
br_config_t br_config = {0};
br_if.index = 0;
br_if.if_list = NULL;
*err = br_foreach_port(br_name, br_copy_port_name, &br_if)
if (*err >= 0)
{
strncpy(br_config.br_name, br_name, BR_NAMSIZ - 1);
br_config.ports = br_if.if_list;
br_config.port_num = br_if.index;
json_obj = br_config_format_json(&br_config);
}
else
{
ret = RET_SYSERR;
}
if(br_if.if_list)
{
rpc_free(br_if.if_list);
}
br_config_t br_if = {0};
int port_num = 0;
int i = 0;
rpc_log_info("get bridge %s info ",br_name);
port_num = br_if_bridge_num((char *)br_name);
strncpy(br_if.br_name, br_name, BR_NAMSIZ);
br_if.port_num = 0;
br_if.ports = NULL;
if(port_num > 0)
{
br_if.ports = rpc_new0(char *, port_num);
*err = br_foreach_port(br_if.br_name, br_copy_port_name, &br_if);
if (*err < 0)
{
ret = RET_SYSERR;
}
}
rpc_log_info("ret %d\n",ret);
*json_obj = br_config_format_json(&br_if);
rpc_log_info("bridge %s has %d ports\n",br_name, br_if.port_num);
for(i = 0; i < br_if.port_num; i++)
{
if(br_if.ports[i])
{
rpc_free(br_if.ports[i]);
}
}
if(br_if.ports)
{
rpc_free(br_if.ports);
}
return ret;
}
@ -397,7 +486,7 @@ int br_bridge_info_each(const char *br_name, void *args)
ret_code ret = RET_OK;
int err = 0;
ret = br_bridge_info(br_name, json_obj, &err);
ret = br_bridge_info(br_name, &json_obj, &err);
if(json_obj)
{
@ -413,7 +502,7 @@ ret_code br_if_config_json_parse(pointer input, uint *conf_type, br_config_t *br
int port_num = 0;
json_obj = cJSON_Parse(input);
ASSERT_PTR_RET(json_obj);
ASSERT_PTR(json_obj, RET_NULLP);
rpc_log_info("json input:\n %s\n", cJSON_Print(json_obj));
@ -430,15 +519,14 @@ ret_code br_if_config_json_parse(pointer input, uint *conf_type, br_config_t *br
if(br_if_conf->config_type != CM_CONFIG_GET_ALL)
{
s2j_struct_get_string_element(br_if_conf, json_obj, string, br_name, BR_NAMSIZ);
s2j_struct_get_string_element(br_if_conf, json_obj, br_name, BR_NAMSIZ);
strncpy(br_if->br_name, br_if_conf->br_name, BR_NAMSIZ - 1);
}
if(br_if_conf->config_type == CM_CONFIG_ADD
|| br_if_conf->config_type == CM_CONFIG_DEL)
{
s2j_struct_get_array_string_n(br_if_conf, json_obj, string,
ports, port_num, INTERFACE_NAMSIZ);
s2j_struct_get_array_string_n(br_if_conf, json_obj, ports, port_num, INTERFACE_NAMSIZ);
br_if->port_num = port_num;
br_if->ports = br_if_conf->ports; /*指针赋值,后续需要对该指针进行内存释放*/
br_if_conf->ports = NULL;
@ -450,9 +538,7 @@ ret_code br_if_config_json_parse(pointer input, uint *conf_type, br_config_t *br
return RET_OK;
}
#endif
#ifndef DESC("桥配置钩子函数")
/* 桥配置钩子函数 */
ret_code br_config_chk(uint source,uint *config_type,
pointer input, int *input_len,
pointer output, int *output_len)
@ -522,22 +608,19 @@ ret_code br_config_proc(uint source, uint config_type,
return ret;
}
#endif
#ifndef DESC("桥接口配置钩子函数")
/* 桥接口配置钩子函数 */
ret_code br_if_config_chk(uint source,uint *config_type,
pointer input, int *input_len,
pointer output, int *output_len)
{
ret_code ret = RET_OK;
br_config_t br_config = {0};
br_config_t *temp_conf = NULL;
int cfg_len = 0;
int i = 0;
br_if_config_json_parse(input, config_type, &br_config);
cfg_len = BR_NAMSIZ + sizeof(br_config.port_num)
cfg_len = sizeof(br_config)
+ br_config.port_num * INTERFACE_NAMSIZ;
if(cfg_len > CM_BUFF_SIZE)
@ -545,20 +628,23 @@ ret_code br_if_config_chk(uint source,uint *config_type,
ret = RET_NOMEM;
goto exit;
}
ret = br_name_chk(br_config.br_name);
if(ret != RET_OK)
if(*config_type != CM_CONFIG_GET_ALL)
{
goto exit;
ret = br_name_chk(br_config.br_name);
if(ret != RET_OK)
{
goto exit;
}
if(br_is_exist(br_config.br_name) == FALSE)
{
ret = RET_NOTFOUND;
goto exit;
}
}
if(br_is_exist(br_config.br_name) == false)
{
ret = RET_NOTFOUND;
goto exit;
}
if(*config_type != CM_CONFIG_ADD && *config_type != CM_CONFIG_DEL)
if(*config_type < CM_CONFIG_ADD && *config_type > CM_CONFIG_GET_ALL)
{
ret = RET_INPUTERR;
goto exit;
@ -571,17 +657,33 @@ ret_code br_if_config_chk(uint source,uint *config_type,
}
memset(input, 0, *input_len);
temp_conf = (br_config_t *)input;
strncpy(temp_conf->br_name, br_config.br_name, BR_NAMSIZ - 1);
temp_conf->port_num = br_config.port_num;
memcpy(temp_conf->ports, br_config.ports, br_config.port_num * INTERFACE_NAMSIZ);
strncpy(input, br_config.br_name, BR_NAMSIZ - 1);
input += BR_NAMSIZ;
*(int *)input = br_config.port_num;
input += sizeof(int);
for(i = 0; i < br_config.port_num; i++)
{
if(br_config.ports[i])
{
strncpy(input, br_config.ports[i], INTERFACE_NAMSIZ);
rpc_free(br_config.ports[i]);
input += INTERFACE_NAMSIZ;
}
}
*input_len = cfg_len;
exit:
RET_ERR_FORMART(ret, 0, output, *output_len);
rpc_free(br_config.ports);
if(br_config.ports)
{
rpc_free(br_config.ports);
}
return ret;
}
@ -589,19 +691,27 @@ ret_code br_if_config_proc(uint source, uint config_type,
pointer input, int input_len,
pointer output, int *output_len)
{
br_config_t *br_conf = (br_config_t *)input;
char *br_name = NULL;
char *port_list = NULL;
int *port_num = NULL;
ret_code ret = RET_OK;
int err = 0;
br_name = input;
input += BR_NAMSIZ;
port_num = (int *)input;
input += sizeof(int);
port_list = input;
if(config_type == CM_CONFIG_ADD)
{
ret = br_if_bridge_add(br_conf->br_name, br_conf->ports,
br_conf->port_num, &err);
ret = br_if_bridge_add(br_name, port_list, *port_num, &err);
}
else if(config_type == CM_CONFIG_DEL)
{
ret = br_if_bridge_del(br_conf->br_name, br_conf->ports,
br_conf->port_num, &err);
ret = br_if_bridge_del(br_name, port_list, *port_num, &err);
}
RET_ERR_FORMART(ret, err, output, *output_len);
@ -616,9 +726,9 @@ ret_code br_if_config_get(uint source,
cJSON *json_obj = NULL;
int err = 0;
ret = br_bridge_info((char *)input, json_obj, &err);
ret = br_bridge_info((char *)input, &json_obj, &err);
if(ret != RET_OK)
if(ret != RET_OK || json_obj == NULL)
{
RET_ERR_FORMART(ret, err, output, *output_len);
}
@ -653,10 +763,7 @@ ret_code br_if_config_get_all(uint source,
return ret;
}
#endif
#ifndef DESC("桥FDB配置辅助函数")
/* 桥FDB配置辅助函数 */
void br_format_time(const struct timeval *tv, char *str, int len)
{
@ -677,7 +784,8 @@ int br_get_if_from_portno(const char *brname, int port_no, char *ifname)
int ifindices[MAX_PORTS];
unsigned long args[4] = { BRCTL_GET_PORT_LIST,
(unsigned long)ifindices, MAX_PORTS, 0 };
struct ifreq ifr;
struct ifreq ifr;
int br_fd = -1;
if (port_no >= MAX_PORTS)
return -1;
@ -686,7 +794,14 @@ int br_get_if_from_portno(const char *brname, int port_no, char *ifname)
strncpy(ifr.ifr_name, brname, IFNAMSIZ);
ifr.ifr_data = (char *) &args;
if (ioctl(br_socket_fd, SIOCDEVPRIVATE, &ifr) < 0) {
if ((br_fd = br_ioctl_sock()) < 0)
{
return -1;
}
if (ioctl(br_fd, SIOCDEVPRIVATE, &ifr) < 0) {
dprintf("get_portno: get ports of %s failed: %s\n",
brname, strerror(errno));
return -1;
@ -696,7 +811,7 @@ int br_get_if_from_portno(const char *brname, int port_no, char *ifname)
{
return -1;
}
return 0;
}
@ -791,9 +906,7 @@ int br_fdb_cpy(br_fdb_status_t *fdb_status, struct fdb_entry *fdb)
return i;
}
#endif
#ifndef DESC("桥FDB配置json格式转换")
/* 桥FDB配置json格式转换 */
ret_code br_fdb_config_json_parse(pointer input, uint *conf_type, br_fdb_config_t *br_fdb)
{
cJSON *json_obj;
@ -815,7 +928,7 @@ ret_code br_fdb_config_json_parse(pointer input, uint *conf_type, br_fdb_config_
return RET_NOMEM;
}
s2j_struct_get_string_element(br_fdb_conf, json_obj, string, br_name, BR_NAMSIZ);
s2j_struct_get_string_element(br_fdb_conf, json_obj, br_name, BR_NAMSIZ);
*conf_type = br_fdb_conf->config_type;
strncpy(br_fdb->br_name, br_fdb_conf->br_name, BR_NAMSIZ - 1);
@ -828,9 +941,8 @@ ret_code br_fdb_config_json_parse(pointer input, uint *conf_type, br_fdb_config_
ret_code br_each_fdb_to_json_string(cJSON *json_array, fdb_info_t *fdb_info)
{
cJSON *fdb_obj;
s2j_create_json_obj(fdb_obj);
if(fdb_obj == NULL)
{
return RET_NOMEM;
@ -843,12 +955,11 @@ ret_code br_each_fdb_to_json_string(cJSON *json_array, fdb_info_t *fdb_info)
cJSON_AddItemToArray(json_array, fdb_obj);
return RET_OK
return RET_OK;
}
int br_fdb_to_json_string(br_fdb_status_t *fdb_status, char *output)
{
cJSON *br_obj;
cJSON *fdb_array;
char *json_str;
int i;
@ -876,10 +987,7 @@ int br_fdb_to_json_string(br_fdb_status_t *fdb_status, char *output)
return (strlen(output) + 1);
}
#endif
#ifndef DESC("桥FDB表配置钩子函数")
/* 桥FDB表配置钩子函数 */
ret_code br_fdb_config_chk(uint source,uint *config_type,
pointer input, int *input_len,
pointer output, int *output_len)
@ -946,4 +1054,16 @@ ret_code br_fdb_config_get(uint source,
return ret;
}
#endif
ret_code br_bridge_init()
{
int err;
err = br_init();
if (err < 0)
{
rpc_log_error("bridge init fail:%s\n",strerror(err));
}
}

View File

@ -10,9 +10,19 @@
#include <linux/rtnetlink.h>
#include <bits/socket.h>
#include <net/if.h>
#include "libnetlink.h"
#include "list.h"
#include "rpc_types.h"
#include "rpc_util.h"
#include "rpc_common.h"
#include "brnetlink.h"
#include "ipconfig.h"
#include "brconfig.h"
#include "libbridge.h"
#define BR_NLMSG_TAIL(nmsg) \
((struct rtattr *) (((void *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len)))
#define BR_MIN(a, b) ((a) < (b) ? (a) : (b))

View File

@ -1,79 +1,80 @@
/* libbridge/config.h. Generated from config.h.in by configure. */
/* libbridge/config.h.in. Generated from configure.in by autoheader. */
/* Define to 1 if you have the `gethostname' function. */
#undef HAVE_GETHOSTNAME
#define HAVE_GETHOSTNAME 1
/* Define to 1 if you have the `if_indextoname' function. */
#undef HAVE_IF_INDEXTONAME
#define HAVE_IF_INDEXTONAME 1
/* Define to 1 if you have the `if_nametoindex' function. */
#undef HAVE_IF_NAMETOINDEX
#define HAVE_IF_NAMETOINDEX 1
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
#define HAVE_INTTYPES_H 1
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
#define HAVE_MEMORY_H 1
/* Define to 1 if you have the `socket' function. */
#undef HAVE_SOCKET
#define HAVE_SOCKET 1
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
#define HAVE_STDINT_H 1
/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
#define HAVE_STDLIB_H 1
/* Define to 1 if you have the `strdup' function. */
#undef HAVE_STRDUP
#define HAVE_STRDUP 1
/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
#define HAVE_STRINGS_H 1
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
#define HAVE_STRING_H 1
/* Define to 1 if you have the <sys/ioctl.h> header file. */
#undef HAVE_SYS_IOCTL_H
#define HAVE_SYS_IOCTL_H 1
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
#define HAVE_SYS_STAT_H 1
/* Define to 1 if you have the <sys/time.h> header file. */
#undef HAVE_SYS_TIME_H
#define HAVE_SYS_TIME_H 1
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
#define HAVE_SYS_TYPES_H 1
/* Define to 1 if you have the `uname' function. */
#undef HAVE_UNAME
#define HAVE_UNAME 1
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
#define HAVE_UNISTD_H 1
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
#define PACKAGE_BUGREPORT ""
/* Define to the full name of this package. */
#undef PACKAGE_NAME
#define PACKAGE_NAME "bridge-utils"
/* Define to the full name and version of this package. */
#undef PACKAGE_STRING
#define PACKAGE_STRING "bridge-utils 1.6"
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
#define PACKAGE_TARNAME "bridge-utils"
/* Define to the home page for this package. */
#undef PACKAGE_URL
#define PACKAGE_URL ""
/* Define to the version of this package. */
#undef PACKAGE_VERSION
#define PACKAGE_VERSION "1.6"
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
#define STDC_HEADERS 1
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
#undef TIME_WITH_SYS_TIME
#define TIME_WITH_SYS_TIME 1
/* Define to empty if `const' does not conform to ANSI C. */
#undef const
/* #undef const */

View File

@ -86,6 +86,7 @@ struct port_info
};
extern int br_init(void);
extern int br_ioctl_sock();
extern int br_refresh(void);
extern void br_shutdown(void);

View File

@ -19,7 +19,7 @@
#ifndef _LIBBRIDGE_PRIVATE_H
#define _LIBBRIDGE_PRIVATE_H
#include "config.h"
#include "libbrconfig.h"
#include <linux/sockios.h>
#include <sys/time.h>

View File

@ -0,0 +1,280 @@
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef __LIBNETLINK_H__
#define __LIBNETLINK_H__ 1
#include <stdio.h>
#include <string.h>
#include <asm/types.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
#include <linux/if_link.h>
#include <linux/if_addr.h>
#include <linux/neighbour.h>
#include <linux/netconf.h>
#include <arpa/inet.h>
struct rtnl_handle {
int fd;
struct sockaddr_nl local;
struct sockaddr_nl peer;
__u32 seq;
__u32 dump;
int proto;
FILE *dump_fp;
#define RTNL_HANDLE_F_LISTEN_ALL_NSID 0x01
#define RTNL_HANDLE_F_SUPPRESS_NLERR 0x02
#define RTNL_HANDLE_F_STRICT_CHK 0x04
int flags;
};
struct nlmsg_list {
struct nlmsg_list *next;
struct nlmsghdr h;
};
struct nlmsg_chain {
struct nlmsg_list *head;
struct nlmsg_list *tail;
};
extern int rcvbuf;
int rtnl_open(struct rtnl_handle *rth, unsigned int subscriptions)
__attribute__((warn_unused_result));
int rtnl_open_byproto(struct rtnl_handle *rth, unsigned int subscriptions,
int protocol)
__attribute__((warn_unused_result));
void rtnl_close(struct rtnl_handle *rth);
void rtnl_set_strict_dump(struct rtnl_handle *rth);
typedef int (*req_filter_fn_t)(struct nlmsghdr *nlh, int reqlen);
int rtnl_addrdump_req(struct rtnl_handle *rth, int family,
req_filter_fn_t filter_fn)
__attribute__((warn_unused_result));
int rtnl_addrlbldump_req(struct rtnl_handle *rth, int family)
__attribute__((warn_unused_result));
int rtnl_routedump_req(struct rtnl_handle *rth, int family,
req_filter_fn_t filter_fn)
__attribute__((warn_unused_result));
int rtnl_ruledump_req(struct rtnl_handle *rth, int family)
__attribute__((warn_unused_result));
int rtnl_neighdump_req(struct rtnl_handle *rth, int family,
req_filter_fn_t filter_fn)
__attribute__((warn_unused_result));
int rtnl_neightbldump_req(struct rtnl_handle *rth, int family)
__attribute__((warn_unused_result));
int rtnl_mdbdump_req(struct rtnl_handle *rth, int family)
__attribute__((warn_unused_result));
int rtnl_netconfdump_req(struct rtnl_handle *rth, int family)
__attribute__((warn_unused_result));
int rtnl_nsiddump_req(struct rtnl_handle *rth, int family)
__attribute__((warn_unused_result));
int rtnl_linkdump_req(struct rtnl_handle *rth, int fam)
__attribute__((warn_unused_result));
int rtnl_linkdump_req_filter(struct rtnl_handle *rth, int fam, __u32 filt_mask)
__attribute__((warn_unused_result));
int rtnl_linkdump_req_filter_fn(struct rtnl_handle *rth, int fam,
req_filter_fn_t fn)
__attribute__((warn_unused_result));
int rtnl_fdb_linkdump_req_filter_fn(struct rtnl_handle *rth,
req_filter_fn_t filter_fn)
__attribute__((warn_unused_result));
int rtnl_statsdump_req_filter(struct rtnl_handle *rth, int fam, __u32 filt_mask)
__attribute__((warn_unused_result));
int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req,
int len)
__attribute__((warn_unused_result));
int rtnl_dump_request_n(struct rtnl_handle *rth, struct nlmsghdr *n)
__attribute__((warn_unused_result));
struct rtnl_ctrl_data {
int nsid;
};
typedef int (*rtnl_filter_t)(struct nlmsghdr *n, void *);
typedef int (*rtnl_listen_filter_t)(struct rtnl_ctrl_data *,
struct nlmsghdr *n, void *);
typedef int (*nl_ext_ack_fn_t)(const char *errmsg, uint32_t off,
const struct nlmsghdr *inner_nlh);
struct rtnl_dump_filter_arg {
rtnl_filter_t filter;
void *arg1;
__u16 nc_flags;
};
int rtnl_dump_filter_nc(struct rtnl_handle *rth,
rtnl_filter_t filter,
void *arg, __u16 nc_flags);
#define rtnl_dump_filter(rth, filter, arg) \
rtnl_dump_filter_nc(rth, filter, arg, 0)
/*int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n,
struct nlmsghdr **answer)
__attribute__((warn_unused_result));*/
int rtnl_talk_iov(struct rtnl_handle *rtnl, struct iovec *iovec, size_t iovlen,
struct nlmsghdr **answer)
__attribute__((warn_unused_result));
int rtnl_talk_suppress_rtnl_errmsg(struct rtnl_handle *rtnl, struct nlmsghdr *n,
struct nlmsghdr **answer)
__attribute__((warn_unused_result));
int rtnl_send(struct rtnl_handle *rth, const void *buf, int)
__attribute__((warn_unused_result));
int rtnl_send_check(struct rtnl_handle *rth, const void *buf, int)
__attribute__((warn_unused_result));
int nl_dump_ext_ack(const struct nlmsghdr *nlh, nl_ext_ack_fn_t errfn);
int addattr(struct nlmsghdr *n, int maxlen, int type);
int addattr8(struct nlmsghdr *n, int maxlen, int type, __u8 data);
int addattr16(struct nlmsghdr *n, int maxlen, int type, __u16 data);
int addattr32(struct nlmsghdr *n, int maxlen, int type, __u32 data);
int addattr64(struct nlmsghdr *n, int maxlen, int type, __u64 data);
int addattrstrz(struct nlmsghdr *n, int maxlen, int type, const char *data);
int addattr_l(struct nlmsghdr *n, int maxlen, int type,
const void *data, int alen);
int addraw_l(struct nlmsghdr *n, int maxlen, const void *data, int len);
struct rtattr *addattr_nest(struct nlmsghdr *n, int maxlen, int type);
int addattr_nest_end(struct nlmsghdr *n, struct rtattr *nest);
struct rtattr *addattr_nest_compat(struct nlmsghdr *n, int maxlen, int type,
const void *data, int len);
int addattr_nest_compat_end(struct nlmsghdr *n, struct rtattr *nest);
int rta_addattr8(struct rtattr *rta, int maxlen, int type, __u8 data);
int rta_addattr16(struct rtattr *rta, int maxlen, int type, __u16 data);
int rta_addattr32(struct rtattr *rta, int maxlen, int type, __u32 data);
int rta_addattr64(struct rtattr *rta, int maxlen, int type, __u64 data);
int rta_addattr_l(struct rtattr *rta, int maxlen, int type,
const void *data, int alen);
/*int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len);*/
int parse_rtattr_flags(struct rtattr *tb[], int max, struct rtattr *rta,
int len, unsigned short flags);
struct rtattr *parse_rtattr_one(int type, struct rtattr *rta, int len);
int __parse_rtattr_nested_compat(struct rtattr *tb[], int max, struct rtattr *rta, int len);
struct rtattr *rta_nest(struct rtattr *rta, int maxlen, int type);
int rta_nest_end(struct rtattr *rta, struct rtattr *nest);
#define RTA_TAIL(rta) \
((struct rtattr *) (((void *) (rta)) + \
RTA_ALIGN((rta)->rta_len)))
#define parse_rtattr_nested(tb, max, rta) \
(parse_rtattr((tb), (max), RTA_DATA(rta), RTA_PAYLOAD(rta)))
#define parse_rtattr_one_nested(type, rta) \
(parse_rtattr_one(type, RTA_DATA(rta), RTA_PAYLOAD(rta)))
#define parse_rtattr_nested_compat(tb, max, rta, data, len) \
({ data = RTA_PAYLOAD(rta) >= len ? RTA_DATA(rta) : NULL; \
__parse_rtattr_nested_compat(tb, max, rta, len); })
static inline __u8 rta_getattr_u8(const struct rtattr *rta)
{
return *(__u8 *)RTA_DATA(rta);
}
static inline __u16 rta_getattr_u16(const struct rtattr *rta)
{
return *(__u16 *)RTA_DATA(rta);
}
static inline __be16 rta_getattr_be16(const struct rtattr *rta)
{
return ntohs(rta_getattr_u16(rta));
}
static inline __u32 rta_getattr_u32(const struct rtattr *rta)
{
return *(__u32 *)RTA_DATA(rta);
}
static inline __be32 rta_getattr_be32(const struct rtattr *rta)
{
return ntohl(rta_getattr_u32(rta));
}
static inline __u64 rta_getattr_u64(const struct rtattr *rta)
{
__u64 tmp;
memcpy(&tmp, RTA_DATA(rta), sizeof(__u64));
return tmp;
}
static inline __s32 rta_getattr_s32(const struct rtattr *rta)
{
return *(__s32 *)RTA_DATA(rta);
}
static inline __s64 rta_getattr_s64(const struct rtattr *rta)
{
__s64 tmp;
memcpy(&tmp, RTA_DATA(rta), sizeof(tmp));
return tmp;
}
static inline const char *rta_getattr_str(const struct rtattr *rta)
{
return (const char *)RTA_DATA(rta);
}
int rtnl_listen_all_nsid(struct rtnl_handle *);
int rtnl_listen(struct rtnl_handle *, rtnl_listen_filter_t handler,
void *jarg);
int rtnl_from_file(FILE *, rtnl_listen_filter_t handler,
void *jarg);
#define NLMSG_TAIL(nmsg) \
((struct rtattr *) (((void *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len)))
#ifndef IFA_RTA
#define IFA_RTA(r) \
((struct rtattr *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct ifaddrmsg))))
#endif
#ifndef IFA_PAYLOAD
#define IFA_PAYLOAD(n) NLMSG_PAYLOAD(n, sizeof(struct ifaddrmsg))
#endif
#ifndef IFLA_RTA
#define IFLA_RTA(r) \
((struct rtattr *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct ifinfomsg))))
#endif
#ifndef IFLA_PAYLOAD
#define IFLA_PAYLOAD(n) NLMSG_PAYLOAD(n, sizeof(struct ifinfomsg))
#endif
#ifndef NDA_RTA
#define NDA_RTA(r) \
((struct rtattr *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct ndmsg))))
#endif
#ifndef NDA_PAYLOAD
#define NDA_PAYLOAD(n) NLMSG_PAYLOAD(n, sizeof(struct ndmsg))
#endif
#ifndef NDTA_RTA
#define NDTA_RTA(r) \
((struct rtattr *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct ndtmsg))))
#endif
#ifndef NDTA_PAYLOAD
#define NDTA_PAYLOAD(n) NLMSG_PAYLOAD(n, sizeof(struct ndtmsg))
#endif
#ifndef NETNS_RTA
#define NETNS_RTA(r) \
((struct rtattr *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct rtgenmsg))))
#endif
#ifndef NETNS_PAYLOAD
#define NETNS_PAYLOAD(n) NLMSG_PAYLOAD(n, sizeof(struct rtgenmsg))
#endif
#ifndef IFLA_STATS_RTA
#define IFLA_STATS_RTA(r) \
((struct rtattr *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct if_stats_msg))))
#endif
/* User defined nlmsg_type which is used mostly for logging netlink
* messages from dump file */
#define NLMSG_TSTAMP 15
#endif /* __LIBNETLINK_H__ */

View File

@ -1,2 +0,0 @@
config.h
stamp-h1

View File

@ -1,41 +0,0 @@
KERNEL_HEADERS=-I@KERNEL_HEADERS@
AR=ar
RANLIB=@RANLIB@
CC=@CC@
CFLAGS = -Wall -g $(KERNEL_HEADERS)
prefix=@prefix@
exec_prefix=@exec_prefix@
includedir=@includedir@
libdir=@libdir@
libbridge_SOURCES= \
libbridge_devif.c \
libbridge_if.c \
libbridge_init.c \
libbridge_misc.c
libbridge_OBJECTS=$(libbridge_SOURCES:.c=.o)
all: libbridge.a
# At present there is no need for a bridge-utils-devel package
install:
clean:
rm -f *.o libbridge.a
libbridge.a: $(libbridge_OBJECTS)
$(AR) rcs $@ $(libbridge_OBJECTS)
$(RANLIB) $@
%.o: %.c libbridge.h libbridge_private.h
$(CC) $(CFLAGS) $(INCLUDE) -c $<
libbridge_compat.o: libbridge_compat.c if_index.c
$(CC) $(CFLAGS) -c libbridge_compat.c

View File

@ -37,6 +37,11 @@ int br_init(void)
return 0;
}
int br_ioctl_sock()
{
return br_socket_fd;
}
void br_shutdown(void)
{
close(br_socket_fd);
@ -151,7 +156,7 @@ int br_cnt_num(const char *name, void *arg)
(*cnt)++;
return 0
return 0;
}
int br_for_bridge_num(int *cnt)

View File

@ -151,6 +151,116 @@ int conf_value_in_block_exist(char *conf_path, char *conf_buff)
return RET_NOTFOUND;
}
/* 设置指定配置块中的配置 */
int conf_value_in_block_set_ex(char *conf_path,
char *start_str, char *end_str,
char *conf_name, char *conf_buff)
{
char config_linebuf[IF_BUFF_LEN];
int configbuf_lenth = strlen(conf_buff) + 5;
long config_lenth = 0;
boolean next_flag = FALSE;
char *start_line = NULL;
char *config_line = NULL;
FILE *f;
f = fopen(conf_path,"r+");
if(f == NULL)
{
rpc_log_error("OPEN CONFIG %s FALID\n", conf_path);
return RET_ERR;
}
fseek(f, 0, SEEK_END);
config_lenth = ftell(f);
char sum_buf[config_lenth + configbuf_lenth];
memset(sum_buf, 0, sizeof(sum_buf));
fseek(f, 0, SEEK_SET);
memset(config_linebuf, 0, sizeof(config_linebuf));
while(fgets(config_linebuf, IF_BUFF_LEN, f) != NULL)
{
/* 该做的事情已经做完 */
if(next_flag == TRUE)
{
strcat(sum_buf, config_linebuf);
goto next_while;
}
/* 判断是否是空行 */
if(strlen(config_linebuf) < 3)
{
strcat(sum_buf, config_linebuf);
goto next_while;
}
/* 没有找到配置块,则继续循环 */
if(start_line == NULL)
{
start_line = strstr(config_linebuf, start_str);
strcat(sum_buf, config_linebuf);
goto next_while;
}
/* 配置块结束 */
if(strstr(config_linebuf, end_str))
{
if(config_line == NULL)
{
strcat(sum_buf, conf_buff);
}
strcat(sum_buf, config_linebuf);
next_flag = TRUE;
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));
}
fclose(f);
/* 整个配置块都没有,则新创建该配置块 */
if( next_flag == FALSE )
{
return RET_NOTFOUND;
}
remove(conf_path);
rpc_log_dbg("---sum_buf---->%s<----------\n",sum_buf);
return conf_file_write(conf_path, sum_buf);
}
/* 设置指定配置块中的配置 */
int conf_value_in_block_set(char *conf_path,
@ -530,51 +640,45 @@ int conf_value_block_del(char *conf_path, char *start_str, char *end_str)
}
/* 增加接口配置块 */
void if_conf_file_add(char *if_name)
ret_code if_conf_file_add(char *if_name)
{
char auto_str[IF_BUFF_LEN] = {0};
sprintf(auto_str, "auto %s", if_name);
conf_value_block_add(IFCONFIG_PATH, auto_str);
return;
return conf_value_block_add(IFCONFIG_PATH, auto_str);
}
/* 删除整个接口配置块 */
void if_conf_file_del(char *if_name)
ret_code if_conf_file_del(char *if_name)
{
char auto_str[IF_BUFF_LEN] = {0};
sprintf(auto_str, "auto %s", if_name);
conf_value_block_del(IFCONFIG_PATH, auto_str, "auto");
return;
return conf_value_block_del(IFCONFIG_PATH, auto_str, "auto");
}
/* 设置接口中的配置 */
void if_conf_file_set(char *if_name, char *conf_name, char *conf_buff)
ret_code if_conf_file_set(char *if_name, char *conf_name, char *conf_buff)
{
char auto_str[IF_BUFF_LEN] = {0};
sprintf(auto_str, "auto %s", if_name);
conf_value_in_block_set(IFCONFIG_PATH, auto_str, "auto", conf_name, conf_buff);
return;
return conf_value_in_block_set_ex(IFCONFIG_PATH, auto_str,
"auto", conf_name, conf_buff);
}
/* 获取接口中的配置 */
void if_conf_file_get(char *if_name, char *conf_name, char *conf_buff)
ret_code if_conf_file_get(char *if_name, char *conf_name, char *conf_buff)
{
char auto_str[IF_BUFF_LEN] = {0};
sprintf(auto_str, "auto %s", if_name);
conf_value_in_block_get(IFCONFIG_PATH, auto_str, "auto", conf_name, conf_buff);
return;
return conf_value_in_block_get(IFCONFIG_PATH, auto_str,
"auto", conf_name, conf_buff);
}
ret_code if_conf_file_exist(char *if_name, char *conf_buff)
@ -610,7 +714,6 @@ void ip_conf_file_set(char *if_name, char *conf_name, char *conf_buff)
return;
}
/*
*
*
@ -628,3 +731,25 @@ void ip_conf_file_del(char *if_name, char *conf_buff)
return;
}
ret_code del_sub_string(char *str_in,char *str_sub)
{
char* str_out = (char *)malloc(strlen(str_in) + 1);
char* p;
if(str_out == NULL)
{
return RET_NULLP;
}
while((p = strstr(str_in, str_sub)) != NULL)
{
*p = '\0';
strcpy(str_out, p + strlen(str_sub));
strcat(str_in, str_out);
}
return RET_OK;
}

View File

@ -124,7 +124,7 @@ int log_conf_append(const u8 level, const char *conf_path, const char *conf_file
return __log_conf("a", level, conf_path, conf_file, filter_mod, cb_content, arg);
}
int log_level_to_str(const u8 level, char *str, u8 len)
int log_level_to_str(const u8 level, char *str, u32 len)
{
u8 i;
char tmp[20];

View File

@ -41,7 +41,7 @@ int log_conf_append(const u8 level, const char *conf_path, const char *conf_file
int (*cb_content)(FILE *fp, const u8 level, const char *filter_mod, void *arg), void *arg);
int write_conf_content(FILE *fp, const u8 level, const char *filter_mod, void *arg);
int write_conf_content_authorizing(FILE *fp, const u8 level, const char *filter_mod, void *arg);
int log_level_to_str(const u8 level, char *str, u8 len);
int log_level_to_str(const u8 level, char *str, u32 len);
#endif

View File

@ -3,6 +3,7 @@
#include <sys/types.h>
#include "log_console.h"
#include "log_types.h"
#include "log_common.h"
#define LOG_CONF_COSOLE_FILE_NAME "log-console.conf"

View File

@ -5,12 +5,6 @@
#include "common_types.h"
#include "rpc_common.h"
typedef struct _log_console {
u8 level;
u8 on;
char module_name[MAX_MODULE_NAME_SZ];
} log_console_t;
void rpc_conf_log_console(rpc_conn *conn, pointer input, int input_len, pointer data);
#endif

View File

@ -4,6 +4,7 @@
#include <errno.h>
#include "log_pty.h"
#include "log_types.h"
#include "log_common.h"
#define LOG_DEV_PTY_DIR LOG_DEV_DIR"pts/"

View File

@ -3,8 +3,6 @@
#include "log_console.h"
typedef log_console_t log_pty_t;
void rpc_conf_log_pty(rpc_conn *conn, pointer input, int input_len, pointer data);
#endif

View File

@ -172,7 +172,7 @@ static int remote_conf_level_content(FILE *fp, const u8 level)
ULOG_DEBUG(g_log, "Recover old line:%s to file:%s", rewrite_line, path);
n1 = fwrite(rewrite_line, 1, n3, fp);
if (n3 != n1) {
ULOG_ERR(g_log, "Recovering old line:%s to file is failure:%s", line, strerror(errno));
ULOG_ERR(g_log, "Recovering old line:%s to file is failure:%s", rewrite_line, strerror(errno));
goto END;
}
}

View File

@ -12,15 +12,11 @@
#include "log_pty.h"
#include "log_remote.h"
#include "rpc_module.h"
#include "ulog_in.h"
#define LOG_SCHED_MODULE_NAME "log-sched"
#define SERVICE_LOG_FILE_NAME "log-file"
#define SERIVCE_LOG_CONSOLE_NAME "log-console"
#define SERVICE_LOG_PTY_NAME "log-pty"
#define SERVICE_LOG_REMOTE_NAME "log-remote"
#define DEFAULT_CONFIG_FILE "/etc/log-sched.conf"
ulog_t *g_log = NULL;
@ -89,7 +85,7 @@ int main(int argc, char **argv)
/* 注册配置处理函数 */
rpc_server_regservice(server, SERVICE_LOG_FILE_NAME, "conf_log_file", rpc_conf_log_file);
rpc_server_regservice(server, SERIVCE_LOG_CONSOLE_NAME, "conf_log_console", rpc_conf_log_console);
rpc_server_regservice(server, SERIVCE_LOG_CONSOLE_NAME, CONF_LOG_CONSOLE_FUNC, rpc_conf_log_console);
rpc_server_regservice(server, SERVICE_LOG_PTY_NAME, "conf_log_pty", rpc_conf_log_pty);
rpc_server_regservice(server, SERVICE_LOG_REMOTE_NAME, "conf_log_add_remote", rpc_conf_log_add_remote);
rpc_server_regservice(server, SERVICE_LOG_REMOTE_NAME, "conf_log_del_remote", rpc_conf_log_del_remote);

View File

@ -1,5 +1,10 @@
#include "k-userhash.h"
#include <linux/slab.h>
#include <asm/errno.h>
#include <linux/kthread.h>
/*声明读写锁 */
DEFINE_RWLOCK(g_obj_lock);
/*定义大小为HASH_SIZE的hashtable */
static struct list_head hash_array[HASH_SIZE];
@ -15,7 +20,7 @@ void init_hashMap(void)
/*获取hashtable位置索引 */
int get_hash_index(uint32_t ip)
{
unsigned int val = ip % HASH_SIZE;
int val = ip % HASH_SIZE;
return val;
}
@ -29,15 +34,8 @@ USERINFO *search_user(uint32_t ip)
index = get_hash_index(ip);
/*判断表中该单元是否为NLL */
/* list_empty - tests whether a list is empty*/
/* @head: the list to test.*/
if( list_empty(&hash_array[index]))
{
return NULL;
}
/*查找用户IP */
read_lock(&g_obj_lock);
list_for_each(pos, &hash_array[index])
{
@ -47,9 +45,10 @@ USERINFO *search_user(uint32_t ip)
* @member: the name of the list_head within the struct. */
pNode = list_entry(pos, USERINFO, hnode);
if(pNode != NULL)
printk("user ip:%d user id:%d\n", pNode->user_ip, pNode->user_id);
printk("user ip:%ld user id:%d\n", pNode->user_ip, pNode->user_id);
return pNode;
}
read_unlock(&g_obj_lock);
return NULL;
}
@ -71,11 +70,10 @@ int add_user(uint32_t ip, int id)
pNode = (USERINFO *)kmalloc(sizeof(USERINFO), GFP_KERNEL);
if (pNode == NULL)
{
return -1;
return ENOMEM;
}
pNode->user_ip = ip;
list_add_tail(&pNode->hnode,&hash_array[index]);
}
printk("IP ALEADY EXISTED\n");
@ -88,7 +86,7 @@ int add_user(uint32_t ip, int id)
void del_user(uint32_t ip)
{
int index;
struct list_head *pos;
struct list_head *pos, *n;
USERINFO *pNode;
index = get_hash_index(ip);
@ -100,13 +98,15 @@ void del_user(uint32_t ip)
}
/*查找用户ip */
list_for_each(pos, &hash_array[index])
write_lock(&g_obj_lock);
list_for_each_safe(pos, n, &hash_array[index])
{
pNode = list_entry(pos, USERINFO, hnode);
if(pNode->user_ip == ip)
list_del(&pNode->hnode);
kfree(pNode);
}
write_unlock(&g_obj_lock);
return;
}
@ -123,12 +123,14 @@ void free_all_user(void)
{
if(list_empty(&hash_array[i]))
continue;
write_lock(&g_obj_lock);
list_for_each_safe(pos, n, &hash_array[i])
{
pNode = list_entry(pos, USERINFO, hnode);
list_del(&pNode->hnode);
kfree(pNode);
}
write_unlock(&g_obj_lock);
}
}
@ -142,11 +144,13 @@ void printk_all_user(void)
for(i = 0; i < HASH_SIZE; i++)
continue;
read_lock(&g_obj_lock);
list_for_each_safe(pos, n, &hash_array[i])
{
pNode = list_entry(pos, USERINFO, hnode);
printk("user ip:%d user id:%d\n", pNode->user_ip, pNode->user_id);
}
read_unlock(&g_obj_lock);
}