Skip to content

Commit

Permalink
Merge branch 'master' into dr_reload
Browse files Browse the repository at this point in the history
  • Loading branch information
wangdd committed May 9, 2023
2 parents 87157c1 + 028704c commit 9afa2ee
Show file tree
Hide file tree
Showing 14 changed files with 438 additions and 122 deletions.
14 changes: 12 additions & 2 deletions modules/aaa_diameter/aaa_diameter.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ static int dm_bind_api(aaa_prot *api);
int fd_log_level = FD_LOG_NOTICE;
str dm_realm = str_init("diameter.test");
str dm_peer_identity = str_init("server"); /* a.k.a. server.diameter.test */
static str dm_aaa_url = {NULL, 0};
int dm_answer_timeout = 2000; /* ms */

static const cmd_export_t cmds[]= {
Expand All @@ -65,7 +66,8 @@ static const param_export_t params[] =
{
{ "fd_log_level", INT_PARAM, &fd_log_level },
{ "realm", STR_PARAM, &dm_realm.s },
{ "peer_identity", STR_PARAM, &dm_peer_identity.s },
{ "peer_identity", STR_PARAM, &dm_peer_identity.s },
{ "aaa_url", STR_PARAM, &dm_aaa_url.s },
{ "answer_timeout", INT_PARAM, &dm_answer_timeout },
{ NULL, 0, NULL },
};
Expand All @@ -92,7 +94,7 @@ struct module_exports exports =
"aaa_diameter", /* module's name */
MOD_TYPE_AAA, /* class of this module */
MODULE_VERSION,
DEFAULT_DLFLAGS, /* dlopen flags */
RTLD_NOW | RTLD_GLOBAL, /* dlopen flags */
NULL, /* load function */
&deps, /* OpenSIPS module dependencies */
cmds, /* exported functions */
Expand Down Expand Up @@ -134,6 +136,14 @@ int mod_init(void)
return -1;
}

if (dm_aaa_url.s) {
dm_aaa_url.len = strlen(dm_aaa_url.s);
if (!dm_init_prot(&dm_aaa_url)) {
LM_ERR("failed to init Diameter AAA connection\n");
return -1;
}
}

return 0;
}

Expand Down
75 changes: 51 additions & 24 deletions modules/aaa_diameter/aaa_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,17 @@ static int dm_avps2json(void *root, cJSON *avps)

FD_CHECK_GT(fd_msg_avp_hdr(it, &h));

FD_CHECK_GT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_CODE,
&h->avp_code, &obj, ENOENT));
if (h->avp_flags & AVP_FLAG_VENDOR) {
struct dict_avp_request ar;
memset(&ar, 0, sizeof ar);
ar.avp_code = h->avp_code;
ar.avp_vendor = h->avp_vendor;
FD_CHECK_GT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_CODE_AND_VENDOR,
&ar, &obj, ENOENT));
} else {
FD_CHECK_GT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_CODE,
&h->avp_code, &obj, ENOENT));
}
FD_CHECK_GT(fd_dict_getval(obj, &dm_avp));

item = cJSON_CreateObject();
Expand All @@ -256,7 +265,7 @@ static int dm_avps2json(void *root, cJSON *avps)
goto out;
}

if (dm_avps2json(&it, val) != 0) {
if (dm_avps2json(it, val) != 0) {
cJSON_Delete(val);
LM_ERR("failed to encode Grouped AVP as JSON string (AVP: %s, code: %u)\n",
dm_avp.avp_name, dm_avp.avp_code);
Expand Down Expand Up @@ -365,19 +374,31 @@ static int dm_custom_cmd_reply(struct msg **_msg, struct avp * avp, struct sessi
goto out;
}

rc = fd_msg_search_avp(msg, dm_dict.Transaction_Id, &a);
rc = fd_msg_search_avp(msg, dm_dict.Session_Id, &a);
if (rc != 0) {
LM_WARN("Missing Transaction-Id AVP in Diameter Answer %d/%d\n",
LM_DBG("Missing Session-Id AVP in Diameter Answer %d/%d, looking for Transaction-Id\n",
hdr->msg_appl, hdr->msg_code);
goto out;
}
rc = fd_msg_search_avp(msg, dm_dict.Transaction_Id, &a);
if (rc != 0) {
LM_WARN("Missing Transaction-Id AVP in Diameter Answer %d/%d\n",
hdr->msg_appl, hdr->msg_code);
goto out;
}

FD_CHECK_GT(fd_msg_avp_hdr(a, &h));
tid.s = (char *)h->avp_value->os.data;
tid.len = (int)h->avp_value->os.len;

FD_CHECK_GT(fd_msg_avp_hdr(a, &h));
tid.s = (char *)h->avp_value->os.data;
tid.len = (int)h->avp_value->os.len;
LM_DBG("%d/%d reply %d, Transaction-Id: %.*s\n", hdr->msg_appl,
hdr->msg_code, rc, tid.len, tid.s);
} else {
FD_CHECK_GT(fd_msg_avp_hdr(a, &h));
tid.s = (char *)h->avp_value->os.data;
tid.len = (int)h->avp_value->os.len;

LM_DBG("%d/%d reply %d, Transaction-Id: %.*s\n", hdr->msg_appl,
hdr->msg_code, rc, tid.len, tid.s);
LM_DBG("%d/%d reply %d, Session-Id: %.*s\n", hdr->msg_appl,
hdr->msg_code, rc, tid.len, tid.s);
}

prpl_cond = (struct dm_cond **)hash_find_key(pending_replies, tid);
if (!prpl_cond) {
Expand Down Expand Up @@ -432,6 +453,7 @@ static int dm_custom_cmd_reply(struct msg **_msg, struct avp * avp, struct sessi
int dm_register_callbacks(void)
{
struct disp_when data;
struct dict_object *vendor_dict;

/* accounting */
{
Expand Down Expand Up @@ -474,16 +496,26 @@ int dm_register_callbacks(void)
for (i = 0; i < n_app_ids; i++) {
/* Initialize the dictionary objects we use */
FD_CHECK_dict_search(DICT_APPLICATION, APPLICATION_BY_ID,
&app_ids[i], &data.app);
&app_defs[i].id, &data.app);

/* Register the dispatch callback */
FD_CHECK(fd_disp_register(dm_custom_cmd_reply,
DISP_HOW_APPID, &data, NULL, NULL));

if (app_defs[i].vendor != (unsigned int)-1) {
FD_CHECK_dict_search(DICT_VENDOR, VENDOR_BY_ID,
&app_defs[i].vendor, &vendor_dict);
} else {
vendor_dict = NULL;
}

/* Advertise support for the respective app */
FD_CHECK(fd_disp_app_support(data.app, NULL, 0, 1 ));
FD_CHECK(fd_disp_app_support(data.app,
vendor_dict,
(app_defs[i].auth?1:0),
(app_defs[i].auth?0:1)));

LM_DBG("registered a reply callback for App ID %d ...\n", app_ids[i]);
LM_DBG("registered a reply callback for App ID %d ...\n", app_defs[i].id);
}
}

Expand Down Expand Up @@ -1516,6 +1548,7 @@ int dm_build_avps(struct list_head *subavps, cJSON *array)
struct dict_object *obj;
char *name;
unsigned int code;
str st;

for (_avp = array; _avp; _avp = _avp->next) {
if (_avp->type != cJSON_Object) {
Expand All @@ -1531,14 +1564,8 @@ int dm_build_avps(struct list_head *subavps, cJSON *array)
goto error;
}

if (_isdigit(avp->string[0])) {
str st;

init_str(&st, avp->string);
if (str2int(&st, &code) != 0) {
LM_ERR("bad AVP key: cannot start with a digit (%s)\n", avp->string);
goto error;
}
init_str(&st, avp->string);
if (str2int(&st, &code) == 0) {

LM_DBG("AVP:: searching AVP by int: %d\n", code);
FD_CHECK(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_CODE,
Expand All @@ -1549,7 +1576,7 @@ int dm_build_avps(struct list_head *subavps, cJSON *array)
} else {
LM_DBG("AVP:: searching AVP by string: %s\n", avp->string);

FD_CHECK(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME,
FD_CHECK(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME_ALL_VENDORS,
avp->string, &obj, ENOENT));
FD_CHECK(fd_dict_getval(obj, &dm_avp));

Expand Down
1 change: 1 addition & 0 deletions modules/aaa_diameter/aaa_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ struct _dm_dict {
struct dict_object *SIP_Method;

struct dict_object *Transaction_Id;
struct dict_object *Session_Id;
struct dict_object *Event_Timestamp;
struct dict_object *Route_Record;
};
Expand Down
2 changes: 2 additions & 0 deletions modules/aaa_diameter/app_opensips/app_opensips.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ static struct {
struct dict_object * Acct_Session_Id;
struct dict_object * Event_Timestamp;
struct dict_object * Transaction_Id;
struct dict_object * Session_Id;

struct dict_object * Auth_Application_Id;
struct dict_object * Auth_Session_State;
Expand Down Expand Up @@ -726,6 +727,7 @@ static int os_entry(char *confstring)
CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Acct-Session-Id", &dm_dict.Acct_Session_Id, ENOENT) );
CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Event-Timestamp", &dm_dict.Event_Timestamp, ENOENT) );
CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Transaction-Id", &dm_dict.Transaction_Id, ENOENT) );
CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Session-Id", &dm_dict.Session_Id, ENOENT) );

CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Auth-Application-Id", &dm_dict.Auth_Application_Id, ENOENT) );
CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Auth-Session-State", &dm_dict.Auth_Session_State, ENOENT) );
Expand Down

0 comments on commit 9afa2ee

Please sign in to comment.