提交 419de8f6 编写于 作者: D Dmitry Kozlov

dynamicaly check if radius module loaded (so not more require to rebuild...

dynamicaly check if radius module loaded (so not more require to rebuild project without RADIUS to switch to chap-secrets)
上级 b997d19f
......@@ -311,7 +311,7 @@ static void connect_channel(struct pppoe_conn_t *conn)
goto out_err_close;
#ifdef RADIUS
if (conn->tr101) {
if (conn->tr101 && triton_module_loaded("radius")) {
conn->radius.send_access_request = pppoe_rad_send_access_request;
conn->radius.send_accounting_request = pppoe_rad_send_accounting_request;
rad_register_plugin(&conn->ppp, &conn->radius);
......
......@@ -531,7 +531,9 @@ static void __init init(void)
triton_event_register_handler(EV_PPP_FINISHING, (triton_event_func)ev_ppp_finishing);
triton_event_register_handler(EV_PPP_FINISHED, (triton_event_func)ev_ppp_finished);
#ifdef RADIUS
triton_event_register_handler(EV_RADIUS_ACCESS_ACCEPT, (triton_event_func)ev_radius_access_accept);
triton_event_register_handler(EV_RADIUS_COA, (triton_event_func)ev_radius_coa);
if (triton_module_loaded("radius")) {
triton_event_register_handler(EV_RADIUS_ACCESS_ACCEPT, (triton_event_func)ev_radius_access_accept);
triton_event_register_handler(EV_RADIUS_COA, (triton_event_func)ev_radius_coa);
}
#endif
}
......@@ -1161,27 +1161,29 @@ static void load_config(void)
const char *opt;
#ifdef RADIUS
opt = conf_get_opt("tbf", "vendor");
if (opt)
conf_vendor = parse_vendor_opt(opt);
opt = conf_get_opt("tbf", "attr");
if (opt) {
conf_attr_down = parse_attr_opt(opt);
conf_attr_up = parse_attr_opt(opt);
}
if (triton_module_loaded("radius")) {
opt = conf_get_opt("tbf", "vendor");
if (opt)
conf_vendor = parse_vendor_opt(opt);
opt = conf_get_opt("tbf", "attr");
if (opt) {
conf_attr_down = parse_attr_opt(opt);
conf_attr_up = parse_attr_opt(opt);
}
opt = conf_get_opt("tbf", "attr-down");
if (opt)
conf_attr_down = parse_attr_opt(opt);
opt = conf_get_opt("tbf", "attr-up");
if (opt)
conf_attr_up = parse_attr_opt(opt);
opt = conf_get_opt("tbf", "attr-down");
if (opt)
conf_attr_down = parse_attr_opt(opt);
opt = conf_get_opt("tbf", "attr-up");
if (opt)
conf_attr_up = parse_attr_opt(opt);
if (conf_attr_up <= 0 || conf_attr_down <= 0) {
log_emerg("tbf: incorrect attribute(s), tbf disabled...\n");
return;
if (conf_attr_up <= 0 || conf_attr_down <= 0) {
log_emerg("tbf: incorrect attribute(s), tbf disabled...\n");
return;
}
}
#endif
......@@ -1260,8 +1262,10 @@ static void __init init(void)
load_config();
#ifdef RADIUS
triton_event_register_handler(EV_RADIUS_ACCESS_ACCEPT, (triton_event_func)ev_radius_access_accept);
triton_event_register_handler(EV_RADIUS_COA, (triton_event_func)ev_radius_coa);
if (triton_module_loaded("radius")) {
triton_event_register_handler(EV_RADIUS_ACCESS_ACCEPT, (triton_event_func)ev_radius_access_accept);
triton_event_register_handler(EV_RADIUS_COA, (triton_event_func)ev_radius_coa);
}
#endif
triton_event_register_handler(EV_CTRL_FINISHED, (triton_event_func)ev_ctrl_finished);
triton_event_register_handler(EV_SHAPER, (triton_event_func)ev_shaper);
......
......@@ -146,6 +146,9 @@ static int check(struct pwdb_t *pwdb, struct ppp_t *ppp, const char *username, i
va_end(args);
if (r == PWDB_SUCCESS)
rpd->authenticated = 1;
return r;
}
......@@ -192,6 +195,9 @@ static void ppp_starting(struct ppp_t *ppp)
static void ppp_acct_start(struct ppp_t *ppp)
{
struct radius_pd_t *rpd = find_pd(ppp);
if (!rpd->authenticated)
return;
if (rad_acct_start(rpd)) {
ppp_terminate(rpd->ppp, TERM_NAS_ERROR, 0);
......@@ -207,6 +213,9 @@ static void ppp_finishing(struct ppp_t *ppp)
{
struct radius_pd_t *rpd = find_pd(ppp);
if (!rpd->authenticated)
return;
rad_acct_stop(rpd);
}
static void ppp_finished(struct ppp_t *ppp)
......
......@@ -15,6 +15,7 @@ struct radius_pd_t
struct ppp_pd_t pd;
struct ppp_t *ppp;
pthread_mutex_t lock;
int authenticated:1;
struct rad_req_t *auth_req;
struct rad_req_t *acct_req;
......@@ -37,7 +38,7 @@ struct radius_pd_t
int attr_class_len;
uint8_t *attr_state;
int attr_state_len;
int termination_action;
int termination_action;
struct list_head plugin_list;
};
......
......@@ -10,12 +10,24 @@
#include "memdebug.h"
struct module_t
{
struct list_head entry;
char *name;
void *handle;
};
static LIST_HEAD(modules);
int load_modules(const char *name)
{
struct conf_sect_t *sect;
struct conf_option_t *opt;
char *fname;
char *path = MODULE_PATH;
char *ptr1, *ptr2;
struct module_t *m;
void *h;
sect = conf_get_section(name);
if (!sect) {
......@@ -48,11 +60,32 @@ int load_modules(const char *name)
}
}
if (!dlopen(fname, RTLD_LAZY | RTLD_GLOBAL)) {
h = dlopen(fname, RTLD_LAZY | RTLD_GLOBAL);
if (!h) {
triton_log_error("loader: failed to load '%s': %s\n", opt->name, dlerror());
_free(fname);
return -1;
}
ptr1 = fname;
while (1) {
ptr2 = strchr(ptr1, '/');
if (!ptr2)
break;
ptr1 = ptr2 + 1;
}
if (!strncmp(ptr1, "lib", 3))
ptr1 += 3;
ptr2 = strstr(ptr1, ".so\x0");
if (ptr2)
*ptr2 = 0;
m = _malloc(sizeof(*m));
m->name = _strdup(ptr1);
m->handle = h;
list_add_tail(&m->entry, &modules);
}
_free(fname);
......@@ -60,3 +93,16 @@ int load_modules(const char *name)
return 0;
}
int __export triton_module_loaded(const char *name)
{
struct module_t *m;
list_for_each_entry(m, &modules, entry) {
if (strcmp(m->name, name))
continue;
return 1;
}
return 0;
}
......@@ -104,6 +104,8 @@ void triton_conf_reload(void (*notify)(int));
void triton_collect_cpu_usage(void);
void triton_stop_collect_cpu_usage(void);
int triton_module_loaded(const char *name);
#define TRITON_OK 0
#define TRITON_ERR_NOCOMP -1
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册