Changeset 996:cf09fde3d7f5 in freeDiameter
- Timestamp:
- Mar 20, 2013, 12:13:14 AM (11 years ago)
- Branch:
- default
- Children:
- 997:632913581c37, 998:ad6c1ee04d2d
- Phase:
- public
- Location:
- extensions/app_radgw
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/app_radgw/radius.c
r979 r996 57 57 /*********************************************************************************/ 58 58 #include "rgw.h" 59 60 /* Overwrite printf */61 #define printf(args...) fd_log_debug(args)62 63 59 64 60 static struct radius_attr_hdr * … … 237 233 } 238 234 239 240 static void print_char(char c) 235 static char print_char_buf[5]; 236 237 static char * print_char(char c) 241 238 { 242 239 if (c >= 32 && c < 127) 243 printf("%c", c);240 sprintf(print_char_buf, "%c", c); 244 241 else 245 printf("<%02x>", c); 246 } 247 248 249 static void radius_msg_dump_attr_val(struct radius_attr_hdr *hdr) 242 sprintf(print_char_buf, "<%02x>", c); 243 return print_char_buf; 244 } 245 246 247 static char * radius_msg_dump_attr_val(struct radius_attr_hdr *hdr, char * outbuf, size_t buflen) 250 248 { 251 249 struct radius_attr_type *attr; … … 253 251 unsigned char *pos; 254 252 u8 attrtype; 253 size_t offset = 0; 254 255 memset(outbuf, 0, buflen); 255 256 256 257 attr = radius_get_attr_type(hdr->type); … … 266 267 switch (attrtype) { 267 268 case RADIUS_ATTR_TEXT: 268 printf(" Value: '");269 snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), " Value: '"); 269 270 for (i = 0; i < len; i++) 270 print_char(pos[i]);271 printf("'\n");271 snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), "%s", print_char(pos[i])); 272 snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), "'"); 272 273 break; 273 274 … … 276 277 struct in_addr addr; 277 278 os_memcpy(&addr, pos, 4); 278 printf(" Value: %s\n", inet_ntoa(addr));279 snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), " Value: %s", inet_ntoa(addr)); 279 280 } else 280 printf(" Invalid IP address length %d\n", len);281 snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), " Invalid IP address length %d", len); 281 282 break; 282 283 … … 287 288 struct in6_addr *addr = (struct in6_addr *) pos; 288 289 atxt = inet_ntop(AF_INET6, addr, buf, sizeof(buf)); 289 printf(" Value: %s\n", atxt ? atxt : "?");290 snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), " Value: %s", atxt ? atxt : "?"); 290 291 } else 291 printf(" Invalid IPv6 address length %d\n", len);292 snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), " Invalid IPv6 address length %d", len); 292 293 break; 293 294 294 295 case RADIUS_ATTR_INT32: 295 296 if (len == 4) 296 printf(" Value: %u\n", WPA_GET_BE32(pos));297 snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), " Value: %u", WPA_GET_BE32(pos)); 297 298 else 298 printf(" Invalid INT32 length %d\n", len);299 snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), " Invalid INT32 length %d", len); 299 300 break; 300 301 … … 302 303 case RADIUS_ATTR_UNDIST: 303 304 default: 304 printf(" Value:");305 snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), " Value:"); 305 306 for (i = 0; i < len; i++) 306 printf(" %02x", pos[i]); 307 printf("\n"); 307 snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), " %02x", pos[i]); 308 308 break; 309 309 } 310 311 return outbuf; 310 312 } 311 313 … … 314 316 { 315 317 unsigned char *auth; 318 char buf[256]; 316 319 size_t i; 317 320 if (! TRACE_BOOL(FULL) ) … … 329 332 struct radius_attr_hdr *attr = (struct radius_attr_hdr *)(msg->radius.buf + msg->radius.attr_pos[i]); 330 333 fd_log_debug(" - Type: 0x%02hhx (%s) Len: %-3hhu", attr->type, rgw_msg_attrtype_str(attr->type), attr->length); 331 radius_msg_dump_attr_val(attr);334 fd_log_debug("%s", radius_msg_dump_attr_val(attr, buf, sizeof(buf))); 332 335 } 333 336 if (has_meta && msg->ps_nb) { … … 336 339 struct radius_attr_hdr *attr = (struct radius_attr_hdr *)(msg->radius.buf + msg->radius.attr_pos[i]); 337 340 fd_log_debug(" - Type: 0x%02hhx (%s) Len: %-3hhu", attr->type, rgw_msg_attrtype_str(attr->type), attr->length); 338 radius_msg_dump_attr_val(attr);341 fd_log_debug("%s", radius_msg_dump_attr_val(attr, buf, sizeof(buf))); 339 342 } 340 343 } … … 355 358 auth, MD5_MAC_LEN); 356 359 if (attr == NULL) { 357 printf("WARNING: Could not add Message-Authenticator\n");360 fd_log_debug("WARNING: Could not add Message-Authenticator"); 358 361 return -1; 359 362 } … … 365 368 366 369 if (msg->buf_used > 0xffff) { 367 printf("WARNING: too long RADIUS message (%lu)\n",370 fd_log_debug("WARNING: too long RADIUS message (%lu)", 368 371 (unsigned long) msg->buf_used); 369 372 return -1; … … 386 389 auth, MD5_MAC_LEN); 387 390 if (attr == NULL) { 388 printf("WARNING: Could not add Message-Authenticator\n");391 fd_log_debug("WARNING: Could not add Message-Authenticator"); 389 392 return -1; 390 393 } … … 410 413 411 414 if (msg->buf_used > 0xffff) { 412 printf("WARNING: too long RADIUS message (%lu)\n",415 fd_log_debug("WARNING: too long RADIUS message (%lu)", 413 416 (unsigned long) msg->buf_used); 414 417 return -1; … … 433 436 434 437 if (msg->buf_used > 0xffff) { 435 printf("WARNING: too long RADIUS messages (%lu)\n",438 fd_log_debug("WARNING: too long RADIUS messages (%lu)", 436 439 (unsigned long) msg->buf_used); 437 440 } … … 468 471 469 472 if (data_len > RADIUS_MAX_ATTR_LEN) { 470 printf("radius_msg_add_attr: too long attribute (%lu bytes)\n",473 fd_log_debug("radius_msg_add_attr: too long attribute (%lu bytes)", 471 474 (unsigned long) data_len); 472 475 return NULL; … … 692 695 if (tmp->type == RADIUS_ATTR_MESSAGE_AUTHENTICATOR) { 693 696 if (attr != NULL) { 694 printf("Multiple Message-Authenticator attributes in RADIUS message\n");697 fd_log_debug("Multiple Message-Authenticator attributes in RADIUS message"); 695 698 return 1; 696 699 } … … 700 703 701 704 if (attr == NULL) { 702 printf("No Message-Authenticator attribute found\n");705 fd_log_debug("No Message-Authenticator attribute found"); 703 706 return 1; 704 707 } … … 720 723 721 724 if (os_memcmp(orig, auth, MD5_MAC_LEN) != 0) { 722 printf("Invalid Message-Authenticator!\n");725 fd_log_debug("Invalid Message-Authenticator!"); 723 726 return 1; 724 727 } … … 736 739 737 740 if (sent_msg == NULL) { 738 printf("No matching Access-Request message found\n");741 fd_log_debug("No matching Access-Request message found"); 739 742 return 1; 740 743 } … … 757 760 md5_vector(4, addr, len, hash); 758 761 if (os_memcmp(hash, msg->hdr->authenticator, MD5_MAC_LEN) != 0) { 759 printf("Response Authenticator invalid!\n");762 fd_log_debug("Response Authenticator invalid!"); 760 763 return 1; 761 764 } … … 895 898 left = len - 2; 896 899 if (left % 16) { 897 printf("Invalid ms key len %lu\n", (unsigned long) left);900 fd_log_debug("Invalid ms key len %lu", (unsigned long) left); 898 901 return NULL; 899 902 } … … 929 932 930 933 if (plain[0] == 0 || plain[0] > plen - 1) { 931 printf("Failed to decrypt MPPE key\n");934 fd_log_debug("Failed to decrypt MPPE key"); 932 935 os_free(plain); 933 936 return NULL; -
extensions/app_radgw/rgw.h
r741 r996 116 116 void rgw_plg_dump(void); 117 117 void rgw_plg_start_cache(void); 118 int rgw_plg_loop_req(struct rgw_radius_msg_meta **rad, struct session **session, structmsg **diam_msg, struct rgw_client * cli);119 int rgw_plg_loop_ans(struct rgw_radius_msg_meta *req, struct session *session, struct msg **diam_ans, struct radius_msg ** rad_ans, struct rgw_client * cli, int * stateful);118 int rgw_plg_loop_req(struct rgw_radius_msg_meta **rad, struct msg **diam_msg, struct rgw_client * cli); 119 int rgw_plg_loop_ans(struct rgw_radius_msg_meta *req, struct msg **diam_ans, struct radius_msg ** rad_ans, struct rgw_client * cli); 120 120 void rgw_plg_fini(void); 121 121 -
extensions/app_radgw/rgw_common.h
r740 r996 74 74 75 75 /* handle an incoming RADIUS message */ 76 int (*rgwp_rad_req) ( struct rgwp_config * conf, struct session ** session, structradius_msg * rad_req, struct radius_msg ** rad_ans, struct msg ** diam_fw, struct rgw_client * cli );76 int (*rgwp_rad_req) ( struct rgwp_config * conf, struct radius_msg * rad_req, struct radius_msg ** rad_ans, struct msg ** diam_fw, struct rgw_client * cli ); 77 77 /* ret >0: critical error (errno), log and exit. 78 78 ret 0: continue; … … 82 82 83 83 /* handle the corresponding Diameter answer */ 84 int (*rgwp_diam_ans) ( struct rgwp_config * conf, struct session * session, struct msg ** diam_ans, struct radius_msg ** rad_fw, struct rgw_client * cli, int * stateful);84 int (*rgwp_diam_ans) ( struct rgwp_config * conf, struct msg ** diam_ans, struct radius_msg ** rad_fw, struct rgw_client * cli ); 85 85 /* ret 0: continue; ret >0: error; ret: -1 ... (tbd) */ 86 /* if *stateful = 1 on return, the session will not be destroyed after RADIUS answer is sent. The extension must ensure to register a timeout on the session in this case. */87 86 88 87 } rgwp_descriptor; -
extensions/app_radgw/rgw_plugins.c
r974 r996 328 328 } 329 329 330 int rgw_plg_loop_req(struct rgw_radius_msg_meta **rad, struct session **session, structmsg **diam_msg, struct rgw_client * cli)330 int rgw_plg_loop_req(struct rgw_radius_msg_meta **rad, struct msg **diam_msg, struct rgw_client * cli) 331 331 { 332 332 int ret = 0; … … 334 334 struct radius_msg * rad_ans = NULL; 335 335 336 TRACE_ENTRY("%p %p %p %p", rad, session, diam_msg, cli);337 CHECK_PARAMS( rad && *rad && session &&diam_msg && *diam_msg && cli);336 TRACE_ENTRY("%p %p %p", rad, diam_msg, cli); 337 CHECK_PARAMS( rad && *rad && diam_msg && *diam_msg && cli); 338 338 339 339 /* First, get the list of extensions for this message */ … … 348 348 if (plg->descriptor->rgwp_rad_req) { 349 349 TRACE_DEBUG(ANNOYING, "Calling next plugin: %s", plg->descriptor->rgwp_name); 350 ret = (*plg->descriptor->rgwp_rad_req)(plg->cs, session,&(*rad)->radius, &rad_ans, diam_msg, cli);350 ret = (*plg->descriptor->rgwp_rad_req)(plg->cs, &(*rad)->radius, &rad_ans, diam_msg, cli); 351 351 if (ret) 352 352 break; … … 368 368 } 369 369 370 /* Destroy the session, there won't be a reply message to retrieve the data */371 if (*session) {372 CHECK_FCT_DO( fd_sess_destroy(session), );373 }374 375 370 /* Send the radius message back if required */ 376 371 if ((ret == -2) && rad_ans && rad) { … … 390 385 391 386 /* Loop in the extension list (same as req) to convert data from diam_ans to rad_ans */ 392 int rgw_plg_loop_ans(struct rgw_radius_msg_meta *req, struct session *session, struct msg **diam_ans, struct radius_msg ** rad_ans, struct rgw_client * cli, int * stateful)387 int rgw_plg_loop_ans(struct rgw_radius_msg_meta *req, struct msg **diam_ans, struct radius_msg ** rad_ans, struct rgw_client * cli) 393 388 { 394 389 int ret = 0; 395 390 struct fd_list * head = NULL, *li; 396 391 397 TRACE_ENTRY("%p %p %p %p %p %p", req, session, diam_ans, rad_ans, cli, stateful); 398 CHECK_PARAMS( req && session && diam_ans && *diam_ans && rad_ans && *rad_ans && cli && stateful); 399 400 *stateful = 0; /* default: stateless gateway */ 392 TRACE_ENTRY("%p %p %p %p", req, diam_ans, rad_ans, cli); 393 CHECK_PARAMS( req && diam_ans && *diam_ans && rad_ans && *rad_ans && cli); 401 394 402 395 /* Get the list of extensions of the RADIUS request */ … … 412 405 if (plg->descriptor->rgwp_diam_ans) { 413 406 TRACE_DEBUG(ANNOYING, "Calling next plugin: %s", plg->descriptor->rgwp_name); 414 ret = (*plg->descriptor->rgwp_diam_ans)(plg->cs, session, diam_ans, rad_ans, (void *)cli, &locstateful);407 ret = (*plg->descriptor->rgwp_diam_ans)(plg->cs, diam_ans, rad_ans, (void *)cli); 415 408 if (ret) 416 409 break; 417 *stateful |= locstateful;418 410 } else { 419 411 TRACE_DEBUG(ANNOYING, "Skipping extension '%s' (NULL callback)", plg->descriptor->rgwp_name); -
extensions/app_radgw/rgw_servers.c
r974 r996 133 133 } 134 134 135 TRACE_DEBUG(FULL, "Received %d bytes", len); 136 TRACE_sSA(FD_LOG_DEBUG, FULL, " from ", &from, NI_NUMERICHOST | NI_NUMERICSERV, "" ); 135 { 136 char __buf[1024]; 137 sSA_DUMP_NODE_SERV(__buf, sizeof(__buf), &from, NI_NUMERICHOST | NI_NUMERICSERV ); 138 TRACE_DEBUG(FULL, "Received %d bytes from %s", len, __buf); 139 } 137 140 138 141 /* Search the associated client definition, if any */ … … 273 276 } 274 277 275 TRACE_DEBUG(FULL, "Sending %d bytes", buflen); 276 TRACE_sSA(FD_LOG_DEBUG, FULL, " to ", &sto, NI_NUMERICHOST | NI_NUMERICSERV, "" ); 278 { 279 char __buf[1024]; 280 sSA_DUMP_NODE_SERV(__buf, sizeof(__buf), &sto, NI_NUMERICHOST | NI_NUMERICSERV ); 281 TRACE_DEBUG(FULL, "Sending %d bytes to %s", buflen, __buf); 282 } 277 283 278 284 /* Send */ -
extensions/app_radgw/rgw_worker.c
r979 r996 54 54 struct rgw_radius_msg_meta * rad; /* the RADIUS message that was received and translated */ 55 55 struct rgw_client * cli; /* the client it was received from */ 56 struct session * sess; /* the Diameter session created for this message (useful?) */57 56 }; 58 57 … … 76 75 struct rgw_radius_msg_meta * msg; 77 76 struct rgw_client * cli; 78 struct session * session;79 77 struct msg * diam_msg; 80 78 int pb, a; … … 133 131 } ); 134 132 135 session = NULL;136 137 133 /* Pass the message to the list of registered plugins */ 138 CHECK_FCT_DO( rgw_plg_loop_req(&msg, & session, &diam_msg, cli),134 CHECK_FCT_DO( rgw_plg_loop_req(&msg, &diam_msg, cli), 139 135 { 140 136 /* An error occurred, discard message */ … … 142 138 CHECK_FCT_DO( fd_msg_free(diam_msg), ); 143 139 diam_msg = NULL; 144 }145 if (session) {146 CHECK_FCT_DO( fd_sess_destroy(&session), );147 140 } 148 141 rgw_msg_free(&msg); … … 181 174 if (pb) { 182 175 /* Something went wrong during the conversion */ 183 if (session) {184 CHECK_FCT_DO( fd_sess_destroy(&session), );185 }186 187 176 if (diam_msg) { 188 177 CHECK_FCT_DO( fd_msg_free(diam_msg), ); … … 202 191 pa->rad = msg; 203 192 pa->cli = cli; 204 pa->sess= session;205 193 206 194 CHECK_FCT_DO( fd_msg_send( &diam_msg, receive_diam_answer, pa), … … 208 196 /* If an error occurs, log and destroy the data */ 209 197 fd_log_debug("An error occurred while sending Diameter message, please turn Debug on for detail."); 210 if (session) {211 CHECK_FCT_DO( fd_sess_destroy(&session), );212 }213 198 214 199 if (diam_msg) { … … 239 224 struct avp_hdr *ahdr; 240 225 int pb = 0; 241 int keepsession=0;242 226 243 227 TRACE_ENTRY("%p %p", pa, ans); … … 248 232 249 233 /* Pass the Diameter answer to the same extensions as the request */ 250 CHECK_FCT_DO( rgw_plg_loop_ans(pa->rad, pa->sess, ans, &rad_ans, pa->cli, &keepsession), goto out );234 CHECK_FCT_DO( rgw_plg_loop_ans(pa->rad, ans, &rad_ans, pa->cli), goto out ); 251 235 252 236 if (*ans != NULL) { … … 300 284 } 301 285 302 if (!keepsession) {303 /* Destroy remaining session data (stateless gateway) */304 CHECK_FCT_DO( fd_sess_destroy(&pa->sess), );305 }306 307 286 /* Clear the RADIUS request */ 308 287 if (pa->rad) { -
extensions/app_radgw/rgwx_acct.c
r974 r996 289 289 290 290 /* Incoming RADIUS request */ 291 static int acct_rad_req( struct rgwp_config * cs, struct session ** session, structradius_msg * rad_req, struct radius_msg ** rad_ans, struct msg ** diam_fw, struct rgw_client * cli )291 static int acct_rad_req( struct rgwp_config * cs, struct radius_msg * rad_req, struct radius_msg ** rad_ans, struct msg ** diam_fw, struct rgw_client * cli ) 292 292 { 293 293 int idx; … … 303 303 union avp_value value; 304 304 struct avp ** avp_tun = NULL, *avp = NULL; 305 struct session * sess; 305 306 306 307 const char * prefix = "Diameter/"; … … 311 312 size_t un_len = 0; 312 313 313 TRACE_ENTRY("%p %p %p %p %p %p", cs, session, rad_req, rad_ans, diam_fw, cli);314 TRACE_ENTRY("%p %p %p %p %p", cs, rad_req, rad_ans, diam_fw, cli); 314 315 CHECK_PARAMS(rad_req && (rad_req->hdr->code == RADIUS_CODE_ACCOUNTING_REQUEST) && rad_ans && diam_fw && *diam_fw); 315 316 … … 452 453 if (status_type == RADIUS_ACCT_STATUS_TYPE_ACCOUNTING_OFF) { 453 454 TRACE_DEBUG(FULL, "[acct.rgwx] Received Accounting-Off Acct-Status-Type attribute, we must terminate all active sessions."); 454 TODO("RADIUS side is rebooting, send STR on all sessions? ");455 TODO("RADIUS side is rebooting, send STR on all sessions???"); 455 456 return ENOTSUP; 456 457 } 457 458 458 459 /* Check if we got a valid session information, otherwise the server will not be able to handle the data... */ 459 if (! *session && !si) {460 if (!si) { 460 461 TRACE_DEBUG(INFO, "[acct.rgwx] RADIUS Account-Request from %s did not contain a CLASS attribute with Diameter session information, reject.", rgw_clients_id(cli)); 461 462 return EINVAL; … … 483 484 } 484 485 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); 485 CHECK_FCT( fd_msg_avp_add ( *diam_fw, *session ? MSG_BRW_LAST_CHILD :MSG_BRW_FIRST_CHILD, avp) );486 487 /* Create the Session-Id AVP if needed*/488 if (!*session){489 CHECK_FCT( fd_sess_fromsid ( si, si_len, session, NULL) );486 CHECK_FCT( fd_msg_avp_add ( *diam_fw, MSG_BRW_FIRST_CHILD, avp) ); 487 488 /* Create the Session-Id AVP */ 489 { 490 CHECK_FCT( fd_sess_fromsid_msg ( si, si_len, &sess, NULL) ); 490 491 491 492 TRACE_DEBUG(FULL, "[acct.rgwx] Translating new accounting message for session '%.*s'...", si_len, si); … … 497 498 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); 498 499 CHECK_FCT( fd_msg_avp_add ( *diam_fw, MSG_BRW_FIRST_CHILD, avp) ); 500 CHECK_FCT( fd_msg_sess_set(*diam_fw, sess) ); 499 501 } 500 502 … … 1177 1179 { 1178 1180 struct sess_state * st; 1179 CHECK_PARAMS(session);1180 1181 1181 1182 CHECK_MALLOC( st = malloc(sizeof(struct sess_state)) ); … … 1186 1187 } 1187 1188 st->term_cause = str_cause; 1188 CHECK_FCT( fd_sess_state_store( cs->sess_hdl, *session, &st ) );1189 CHECK_FCT( fd_sess_state_store( cs->sess_hdl, sess, &st ) ); 1189 1190 } 1190 1191 … … 1222 1223 } 1223 1224 1224 static int acct_diam_ans( struct rgwp_config * cs, struct session * session, struct msg ** diam_ans, struct radius_msg ** rad_fw, struct rgw_client * cli, int * stateful)1225 static int acct_diam_ans( struct rgwp_config * cs, struct msg ** diam_ans, struct radius_msg ** rad_fw, struct rgw_client * cli ) 1225 1226 { 1227 struct session * sess; 1226 1228 struct sess_state * st = NULL, stloc; 1227 1229 struct avp *avp, *next; 1228 struct avp_hdr *ahdr, *sid, *oh, *or; 1229 1230 TRACE_ENTRY("%p %p %p %p %p", cs, session, diam_ans, rad_fw, cli); 1230 struct avp_hdr *ahdr, *oh, *or; 1231 os0_t sid = NULL; 1232 size_t sidlen; 1233 1234 TRACE_ENTRY("%p %p %p %p", cs, diam_ans, rad_fw, cli); 1231 1235 CHECK_PARAMS(cs); 1232 1236 1233 if (session) { 1234 CHECK_FCT( fd_sess_state_retrieve( cs->sess_hdl, session, &st ) ); 1237 CHECK_FCT( fd_msg_sess_get(fd_g_config->cnf_dict, *diam_ans, &sess, NULL) ); 1238 if (sess) { 1239 CHECK_FCT( fd_sess_state_retrieve( cs->sess_hdl, sess, &st ) ); 1240 CHECK_FCT( fd_sess_getsid(sess, &sid, &sidlen) ); 1235 1241 } 1236 1242 … … 1246 1252 1247 1253 /* Search these AVPs first */ 1248 CHECK_FCT( fd_msg_search_avp (*diam_ans, cs->dict.Session_Id, &avp) );1249 CHECK_FCT( fd_msg_avp_hdr ( avp, &sid ) );1250 1251 1254 CHECK_FCT( fd_msg_search_avp (*diam_ans, cs->dict.Origin_Host, &avp) ); 1252 1255 CHECK_FCT( fd_msg_avp_hdr ( avp, &oh ) ); … … 1269 1272 ahdr->avp_value->u32, 1270 1273 oh->avp_value->os.len, oh->avp_value->os.data, 1271 sid ->avp_value->os.len, sid->avp_value->os.data);1274 sidlen, sid); 1272 1275 CHECK_FCT( fd_msg_search_avp (*diam_ans, cs->dict.Error_Message, &avp) ); 1273 1276 if (avp) { … … 1310 1313 CHECK_FCT( fd_msg_new ( cs->dict.Session_Termination_Request, MSGFL_ALLOC_ETEID, &str ) ); 1311 1314 1312 /* Set the application-id to the auth application if available, accou ting otherwise (not sure what is actually expected...) */1315 /* Set the application-id to the auth application if available, accounting otherwise (not sure what is actually expected...) */ 1313 1316 CHECK_FCT( fd_msg_hdr ( str, &hdr ) ); 1314 1317 hdr->msg_appl = st->auth_appl ?: AI_ACCT; … … 1316 1319 /* Add the Session-Id AVP as first AVP */ 1317 1320 CHECK_FCT( fd_msg_avp_new ( cs->dict.Session_Id, 0, &avp ) ); 1318 CHECK_FCT( fd_msg_avp_setvalue ( avp, sid->avp_value ) ); 1321 avp_val.os.data = sid; 1322 avp_val.os.len = sidlen; 1323 CHECK_FCT( fd_msg_avp_setvalue ( avp, &avp_val ) ); 1319 1324 CHECK_FCT( fd_msg_avp_add ( str, MSG_BRW_FIRST_CHILD, avp) ); 1325 CHECK_FCT( fd_sess_ref_msg(sess) ); 1320 1326 1321 1327 /* Add the Destination-Realm as next AVP */ -
extensions/app_radgw/rgwx_auth.c
r979 r996 229 229 230 230 /* Handle an incoming RADIUS request */ 231 static int auth_rad_req( struct rgwp_config * cs, struct session ** session, structradius_msg * rad_req, struct radius_msg ** rad_ans, struct msg ** diam_fw, struct rgw_client * cli )231 static int auth_rad_req( struct rgwp_config * cs, struct radius_msg * rad_req, struct radius_msg ** rad_ans, struct msg ** diam_fw, struct rgw_client * cli ) 232 232 { 233 233 int idx; … … 250 250 struct avp ** avp_tun = NULL, *avp = NULL; 251 251 union avp_value value; 252 253 TRACE_ENTRY("%p %p %p %p %p %p", cs, session, rad_req, rad_ans, diam_fw, cli); 254 CHECK_PARAMS(cs && session && rad_req && (rad_req->hdr->code == RADIUS_CODE_ACCESS_REQUEST) && rad_ans && diam_fw && *diam_fw); 252 struct session * sess; 253 254 TRACE_ENTRY("%p %p %p %p %p", cs, rad_req, rad_ans, diam_fw, cli); 255 CHECK_PARAMS(cs && rad_req && (rad_req->hdr->code == RADIUS_CODE_ACCESS_REQUEST) && rad_ans && diam_fw && *diam_fw); 255 256 256 257 pref_len = strlen(prefix); … … 440 441 } 441 442 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); 442 CHECK_FCT( fd_msg_avp_add ( *diam_fw, *session ? MSG_BRW_LAST_CHILD :MSG_BRW_FIRST_CHILD, avp) );443 CHECK_FCT( fd_msg_avp_add ( *diam_fw, MSG_BRW_FIRST_CHILD, avp) ); 443 444 444 445 /* Add the Destination-Host if found */ … … 448 449 value.os.len = dh_len; 449 450 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); 450 CHECK_FCT( fd_msg_avp_add ( *diam_fw, *session ? MSG_BRW_LAST_CHILD :MSG_BRW_FIRST_CHILD, avp) );451 CHECK_FCT( fd_msg_avp_add ( *diam_fw, MSG_BRW_FIRST_CHILD, avp) ); 451 452 } 452 453 453 454 /* Create the session if it is not already done */ 454 if (*session == NULL){455 { 455 456 os0_t sess_str = NULL; 456 457 size_t sess_strlen; … … 458 459 if (si_len) { 459 460 /* We already have the Session-Id, just use it */ 460 CHECK_FCT( fd_sess_fromsid_msg ( si, si_len, session, NULL) );461 CHECK_FCT( fd_sess_fromsid_msg ( si, si_len, &sess, NULL) ); 461 462 } else { 462 463 /* Create a new Session-Id string */ … … 476 477 CHECK_MALLOC( sess_str = malloc(un_len + 1 /* ';' */ + fd_g_config->cnf_diamid_len + 1 /* '\0' */) ); 477 478 len = sprintf((char *)sess_str, "%.*s;%s", (int)un_len, un, fd_g_config->cnf_diamid); 478 CHECK_FCT( fd_sess_new( session, fqdn, fqdnlen, sess_str, len) );479 CHECK_FCT( fd_sess_new(&sess, fqdn, fqdnlen, sess_str, len) ); 479 480 free(sess_str); 480 481 } else { … … 486 487 487 488 /* Now, add the Session-Id AVP at beginning of Diameter message */ 488 CHECK_FCT( fd_sess_getsid(*session, &sess_str, &sess_strlen) ); 489 489 CHECK_FCT( fd_sess_getsid(sess, &sess_str, &sess_strlen) ); 490 490 TRACE_DEBUG(FULL, "[auth.rgwx] Translating new message for session '%s'...", sess_str); 491 491 492 /* Add the Session-Id AVP as first AVP*/492 /* Now add this session in the message */ 493 493 CHECK_FCT( fd_msg_avp_new ( cs->dict.Session_Id, 0, &avp ) ); 494 494 value.os.data = sess_str; … … 496 496 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); 497 497 CHECK_FCT( fd_msg_avp_add ( *diam_fw, MSG_BRW_FIRST_CHILD, avp) ); 498 CHECK_FCT( fd_msg_sess_set( *diam_fw, *session) );498 CHECK_FCT( fd_msg_sess_set(*diam_fw, sess) ); 499 499 } 500 500 … … 1056 1056 1057 1057 /* Store the request identifier in the session (if provided) */ 1058 if (*session){1058 { 1059 1059 unsigned char * req_auth; 1060 1060 CHECK_MALLOC(req_auth = malloc(16)); 1061 1061 memcpy(req_auth, &rad_req->hdr->authenticator[0], 16); 1062 1062 1063 CHECK_FCT( fd_sess_state_store( cs->sess_hdl, *session, &req_auth ) );1063 CHECK_FCT( fd_sess_state_store( cs->sess_hdl, sess, &req_auth ) ); 1064 1064 } 1065 1065 … … 1067 1067 } 1068 1068 1069 static int auth_diam_ans( struct rgwp_config * cs, struct session * session, struct msg ** diam_ans, struct radius_msg ** rad_fw, struct rgw_client * cli, int * stateful)1069 static int auth_diam_ans( struct rgwp_config * cs, struct msg ** diam_ans, struct radius_msg ** rad_fw, struct rgw_client * cli ) 1070 1070 { 1071 1071 struct msg_hdr * hdr; 1072 struct avp *avp, *next, *avp_x, *avp_y, *a sid, *aoh;1073 struct avp_hdr *ahdr, * sid, *oh;1072 struct avp *avp, *next, *avp_x, *avp_y, *aoh; 1073 struct avp_hdr *ahdr, *oh; 1074 1074 uint8_t buf[254]; /* to store some attributes values (with final '\0') */ 1075 1075 size_t sz; … … 1079 1079 unsigned char * req_auth = NULL; 1080 1080 int error_cause = 0; 1081 1082 TRACE_ENTRY("%p %p %p %p %p", cs, session, diam_ans, rad_fw, cli); 1083 CHECK_PARAMS(cs && session && diam_ans && *diam_ans && rad_fw && *rad_fw); 1081 struct session * sess; 1082 os0_t sid = NULL; 1083 size_t sidlen; 1084 1085 TRACE_ENTRY("%p %p %p %p", cs, diam_ans, rad_fw, cli); 1086 CHECK_PARAMS(cs && diam_ans && *diam_ans && rad_fw && *rad_fw); 1084 1087 1085 1088 /* Retrieve the request identified which was stored in the session */ 1086 if (session) { 1087 CHECK_FCT( fd_sess_state_retrieve( cs->sess_hdl, session, &req_auth ) ); 1088 } 1089 CHECK_FCT( fd_msg_sess_get(fd_g_config->cnf_dict, *diam_ans, &sess, NULL) ); 1090 if (sess) { 1091 CHECK_FCT( fd_sess_state_retrieve( cs->sess_hdl, sess, &req_auth ) ); 1092 CHECK_FCT( fd_sess_getsid(sess, &sid, &sidlen) ); 1093 } /* else ? */ 1089 1094 1090 1095 /* … … 1145 1150 1146 1151 /* Search the different AVPs we handle here */ 1147 CHECK_FCT( fd_msg_search_avp (*diam_ans, cs->dict.Session_Id, &asid) );1148 CHECK_FCT( fd_msg_avp_hdr ( asid, &sid ) );1149 1152 CHECK_FCT( fd_msg_search_avp (*diam_ans, cs->dict.Origin_Host, &aoh) ); 1150 1153 CHECK_FCT( fd_msg_avp_hdr ( aoh, &oh ) ); … … 1240 1243 ahdr->avp_value->u32, 1241 1244 oh->avp_value->os.len, oh->avp_value->os.data, 1242 sid ->avp_value->os.len, sid->avp_value->os.data);1245 sidlen, sid); 1243 1246 CHECK_FCT( fd_msg_search_avp (*diam_ans, cs->dict.Error_Message, &avp_x) ); 1244 1247 if (avp_x) { … … 1271 1274 (int)oh->avp_value->os.len, (char *)oh->avp_value->os.data, 1272 1275 (int)ahdr->avp_value->os.len, (char *)ahdr->avp_value->os.data, 1273 (int)sid ->avp_value->os.len, (char *)sid->avp_value->os.data))) {1276 (int)sidlen, (char *)sid))) { 1274 1277 TRACE_DEBUG(INFO, "Data truncated in State attribute: %s", buf); 1275 1278 } … … 1280 1283 /* Add the Session-Id */ 1281 1284 if (sizeof(buf) < (sz = snprintf((char *)buf, sizeof(buf), "Diameter/%.*s", 1282 (int)sid ->avp_value->os.len, sid->avp_value->os.data))) {1285 (int)sidlen, sid))) { 1283 1286 TRACE_DEBUG(INFO, "Data truncated in Class attribute: %s", buf); 1284 1287 } … … 1455 1458 ((ahdr->avp_value->u32 == 2) ? "AUTHORIZE_ONLY" : "???"), 1456 1459 oh->avp_value->os.len, oh->avp_value->os.data, 1457 sid ->avp_value->os.len, sid->avp_value->os.len);1460 sidlen, sid); 1458 1461 } 1459 1462 break; … … 1616 1619 fd_log_debug("[auth.rgwx] Received Diameter answer with non-translatable NAS-Filter-Rule AVP from '%.*s' (session: '%.*s'), ignoring.", 1617 1620 oh->avp_value->os.len, oh->avp_value->os.data, 1618 sid ->avp_value->os.len, sid->avp_value->os.data);1621 sidlen, sid); 1619 1622 handled = 0; 1620 1623 break; … … 1649 1652 fd_log_debug("[auth.rgwx] Received Diameter answer with non-translatable QoS-Filter-Rule AVP from '%.*s' (session: '%.*s'), ignoring.", 1650 1653 oh->avp_value->os.len, oh->avp_value->os.data, 1651 sid ->avp_value->os.len, sid->avp_value->os.data);1654 sidlen, sid); 1652 1655 handled = 0; 1653 1656 break; … … 1921 1924 } 1922 1925 1923 CHECK_FCT( fd_msg_free( asid ) );1924 1926 CHECK_FCT( fd_msg_free( aoh ) ); 1925 1927 free(req_auth); … … 1930 1932 return ENOMEM; 1931 1933 } 1932 } 1934 } 1933 1935 1934 1936 if ((*rad_fw)->hdr->code == RADIUS_CODE_ACCESS_ACCEPT) { -
extensions/app_radgw/rgwx_debug.c
r974 r996 72 72 73 73 /* Function called when a new RADIUS message is being converted to Diameter */ 74 static int debug_rad_req( struct rgwp_config * cs, struct session ** session, structradius_msg * rad_req, struct radius_msg ** rad_ans, struct msg ** diam_fw, struct rgw_client * cli )74 static int debug_rad_req( struct rgwp_config * cs, struct radius_msg * rad_req, struct radius_msg ** rad_ans, struct msg ** diam_fw, struct rgw_client * cli ) 75 75 { 76 TRACE_ENTRY("%p %p %p %p %p %p", cs, session, rad_req, rad_ans, diam_fw, cli);76 TRACE_ENTRY("%p %p %p %p %p", cs, rad_req, rad_ans, diam_fw, cli); 77 77 78 78 fd_log_debug("------------- RADIUS/Diameter Request Debug%s%s%s -------------", cs ? " [" : "", cs ? (char *)cs : "", cs ? "]" : ""); … … 99 99 } 100 100 101 if (!session || ! *session) {102 fd_log_debug(" Diameter session: NULL pointer");103 } else {104 os0_t str;105 size_t str_len;106 CHECK_FCT( fd_sess_getsid(*session, &str, &str_len) );107 108 fd_log_debug(" Diameter session: %s", str);109 }110 111 101 fd_log_debug("=========== Debug%s%s%s complete =============", cs ? " [" : "", cs ? (char *)cs : "", cs ? "]" : ""); 112 102 … … 115 105 116 106 /* This one, when Diameter answer is converted to RADIUS */ 117 static int debug_diam_ans( struct rgwp_config * cs, struct session * session, struct msg ** diam_ans, struct radius_msg ** rad_fw, struct rgw_client * cli, int * stateful)107 static int debug_diam_ans( struct rgwp_config * cs, struct msg ** diam_ans, struct radius_msg ** rad_fw, struct rgw_client * cli ) 118 108 { 119 TRACE_ENTRY("%p %p %p %p %p %p", cs, session, diam_ans, rad_fw, cli, stateful);109 TRACE_ENTRY("%p %p %p %p", cs, diam_ans, rad_fw, cli); 120 110 121 111 fd_log_debug("------------- RADIUS/Diameter Answer Debug%s%s%s -------------", cs ? " [" : "", cs ? (char *)cs : "", cs ? "]" : ""); -
extensions/app_radgw/rgwx_echodrop.c
r979 r996 119 119 120 120 /* Handle attributes from a RADIUS request as specified in the configuration */ 121 static int ed_rad_req( struct rgwp_config * cs, struct session ** session, structradius_msg * rad_req, struct radius_msg ** rad_ans, struct msg ** diam_fw, struct rgw_client * cli )121 static int ed_rad_req( struct rgwp_config * cs, struct radius_msg * rad_req, struct radius_msg ** rad_ans, struct msg ** diam_fw, struct rgw_client * cli ) 122 122 { 123 123 size_t nattr_used = 0; 124 124 int idx; 125 126 125 struct fd_list echo_list = FD_LIST_INITIALIZER(echo_list); 127 126 struct fd_list *li; 128 127 129 TRACE_ENTRY("%p %p %p %p %p %p", cs, session, rad_req, rad_ans, diam_fw, cli);130 CHECK_PARAMS(cs && rad_req && session);128 TRACE_ENTRY("%p %p %p %p %p", cs, rad_req, rad_ans, diam_fw, cli); 129 CHECK_PARAMS(cs && rad_req); 131 130 132 131 /* For each attribute in the original message */ … … 217 216 /* Save the echoed values in the session, if any */ 218 217 if (!FD_IS_LIST_EMPTY(&echo_list)) { 219 CHECK_PARAMS_DO(*session, 218 struct session * sess; 219 220 CHECK_FCT( fd_msg_sess_get(fd_g_config->cnf_dict, *diam_fw, &sess, NULL) ); 221 222 CHECK_PARAMS_DO(sess, 220 223 { 221 224 fd_log_debug( "[echodrop.rgwx] The extension is configured to echo some attributes from this message, but no session object has been created for it (yet)." … … 231 234 232 235 /* Save the list in the session */ 233 CHECK_FCT( fd_sess_state_store( cs->sess_hdl, *session, &li ) );236 CHECK_FCT( fd_sess_state_store( cs->sess_hdl, sess, &li ) ); 234 237 } 235 238 … … 238 241 239 242 /* Process an answer: add the ECHO attributes back, if any */ 240 static int ed_diam_ans( struct rgwp_config * cs, struct session * session, struct msg ** diam_ans, struct radius_msg ** rad_fw, struct rgw_client * cli, int * stateful)243 static int ed_diam_ans( struct rgwp_config * cs, struct msg ** diam_ans, struct radius_msg ** rad_fw, struct rgw_client * cli ) 241 244 { 242 245 struct fd_list * list = NULL; 243 244 TRACE_ENTRY("%p %p %p %p %p %p", cs, session, diam_ans, rad_fw, cli, stateful); 246 struct session * sess; 247 248 TRACE_ENTRY("%p %p %p %p", cs, diam_ans, rad_fw, cli); 245 249 CHECK_PARAMS(cs); 246 250 251 CHECK_FCT( fd_msg_sess_get(fd_g_config->cnf_dict, *diam_ans, &sess, NULL) ); 252 247 253 /* If there is no session associated, just give up */ 248 if (! sess ion) {254 if (! sess ) { 249 255 TRACE_DEBUG(FULL, "No session associated with the message, nothing to do here..."); 250 256 return 0; … … 252 258 253 259 /* Now try and retrieve any data from the session */ 254 CHECK_FCT( fd_sess_state_retrieve( cs->sess_hdl, sess ion, &list ) );260 CHECK_FCT( fd_sess_state_retrieve( cs->sess_hdl, sess, &list ) ); 255 261 if (list == NULL) { 256 262 /* No attribute saved in the session, just return */ -
extensions/app_radgw/rgwx_sample.c
r741 r996 70 70 71 71 /* This function is called on incoming RADIUS messages. It should handle (some) RADIUS data and store into the Diameter message. */ 72 static int sample_rad_req( struct rgwp_config * cs, struct session ** session, structradius_msg * rad_req, struct radius_msg ** rad_ans, struct msg ** diam_fw, struct rgw_client * cli )72 static int sample_rad_req( struct rgwp_config * cs, struct radius_msg * rad_req, struct radius_msg ** rad_ans, struct msg ** diam_fw, struct rgw_client * cli ) 73 73 { 74 TRACE_ENTRY("%p %p %p %p %p %p", cs, session, rad_req, rad_ans, diam_fw, cli);74 TRACE_ENTRY("%p %p %p %p %p", cs, rad_req, rad_ans, diam_fw, cli); 75 75 CHECK_PARAMS(cs); 76 76 TRACE_DEBUG(INFO, "RADIUS/Diameter Sample plugin received a new RADIUS message."); … … 79 79 80 80 /* This function is called when a Diameter answer is coming back. It should remove the AVPs and add the attributes in the RADIUS message. */ 81 static int sample_diam_ans( struct rgwp_config * cs, struct session * session, struct msg ** diam_ans, struct radius_msg ** rad_fw, struct rgw_client * cli, int * stateful)81 static int sample_diam_ans( struct rgwp_config * cs, struct msg ** diam_ans, struct radius_msg ** rad_fw, struct rgw_client * cli ) 82 82 { 83 TRACE_ENTRY("%p %p %p %p %p %p", cs, session, diam_ans, rad_fw, cli, stateful);83 TRACE_ENTRY("%p %p %p %p", cs, diam_ans, rad_fw, cli); 84 84 CHECK_PARAMS(cs); 85 85 TRACE_DEBUG(INFO, "RADIUS/Diameter Sample plugin received a new Diameter answer."); -
extensions/app_radgw/rgwx_sip.c
r974 r996 2 2 * Software License Agreement (BSD License) * 3 3 * Author: Alexandre Westfahl <awestfahl@freediameter.net> * 4 * * 4 * * * 5 * Copyright (c) 2013, WIDE Project and NICT * 5 6 * Copyright (c) 2010, Alexandre Westfahl, Teraoka Laboratory (Keio University), and the WIDE Project. * 6 7 * * … … 322 323 323 324 /* Handle an incoming RADIUS request */ 324 static int sip_rad_req( struct rgwp_config * cs, struct session ** session, structradius_msg * rad_req, struct radius_msg ** rad_ans, struct msg ** diam_fw, struct rgw_client * cli )325 static int sip_rad_req( struct rgwp_config * cs, struct radius_msg * rad_req, struct radius_msg ** rad_ans, struct msg ** diam_fw, struct rgw_client * cli ) 325 326 { 326 327 int idx; … … 340 341 struct avp *auth_data=NULL, *auth=NULL, *avp = NULL; 341 342 union avp_value value; 342 343 TRACE_ENTRY("%p %p %p %p %p %p", cs, session, rad_req, rad_ans, diam_fw, cli); 344 345 CHECK_PARAMS(rad_req && (rad_req->hdr->code == RADIUS_CODE_ACCESS_REQUEST) && rad_ans && diam_fw && *diam_fw && session); 346 347 //We check that session is not already filled 348 if(*session) 349 { 350 TRACE_DEBUG(INFO,"INTERNAL ERROR: We are not supposed to receive a session in radSIP plugin."); 351 return EINVAL; 352 } 343 struct session * sess; 344 345 TRACE_ENTRY("%p %p %p %p %p", cs, rad_req, rad_ans, diam_fw, cli); 346 347 CHECK_PARAMS(rad_req && (rad_req->hdr->code == RADIUS_CODE_ACCESS_REQUEST) && rad_ans && diam_fw && *diam_fw); 353 348 354 349 /* 355 350 RFC5090 RADIUS Extension Digest Application 356 351 */ 352 CHECK_FCT( fd_msg_sess_get(fd_g_config->cnf_dict, *diam_fw, &sess, NULL) ); 353 if (sess != NULL) { 354 TRACE_DEBUG(INFO,"INTERNAL ERROR: We are not supposed to receive a session in radSIP plugin."); 355 return EINVAL; 356 } 357 357 358 358 /* Check basic information is there */ … … 398 398 return EINVAL; 399 399 } 400 CHECK_FCT(fd_sess_fromsid (sid, sidlen, session, NULL));400 CHECK_FCT(fd_sess_fromsid_msg (sid, sidlen, &sess, NULL)); 401 401 free(sid); 402 402 … … 424 424 425 425 /* Create the session if it is not already done */ 426 if (! *session) {426 if (!sess) { 427 427 428 428 DiamId_t fqdn; … … 431 431 size_t realm_len; 432 432 433 434 435 436 433 /* Get information on the RADIUS client */ 437 434 CHECK_FCT( rgw_clients_get_origin(cli, &fqdn, &fqdn_len, &realm, &realm_len) ); … … 440 437 CHECK_MALLOC( sid = malloc(un_len + 1 /* ';' */ + fd_g_config->cnf_diamid_len + 1 /* '\0' */) ); 441 438 sidlen = sprintf((char *)sid, "%.*s;%s", (int)un_len, un, fd_g_config->cnf_diamid); 442 CHECK_FCT( fd_sess_new( session, fqdn, fqdn_len, sid, sidlen) );439 CHECK_FCT( fd_sess_new(&sess, fqdn, fqdn_len, sid, sidlen) ); 443 440 free(sid); 444 441 } 442 443 /* Now, add the Session-Id AVP at beginning of Diameter message */ 444 CHECK_FCT( fd_msg_avp_new ( cs->dict.Session_Id, 0, &avp ) ); 445 value.os.data = sid; 446 value.os.len = sidlen; 447 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); 448 CHECK_FCT( fd_msg_avp_add ( *diam_fw, MSG_BRW_FIRST_CHILD, avp) ); 449 450 TRACE_DEBUG(FULL, "[sip.rgwx] Translating new message for session '%s'...", sid); 451 452 /* Now add this session in the message */ 453 CHECK_FCT( fd_msg_sess_set(*diam_fw, sess) ); 445 454 446 455 /* Add the Destination-Realm AVP */ … … 467 476 468 477 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); 469 CHECK_FCT( fd_msg_avp_add ( *diam_fw, MSG_BRW_FIRST_CHILD, avp) ); 470 471 /* Now, add the Session-Id AVP at beginning of Diameter message */ 472 CHECK_FCT( fd_sess_getsid(*session, &sid, &sidlen) ); 473 474 TRACE_DEBUG(FULL, "[sip.rgwx] Translating new message for session '%s'...", sid); 475 476 /* Add the Session-Id AVP as first AVP */ 477 CHECK_FCT( fd_msg_avp_new ( cs->dict.Session_Id, 0, &avp ) ); 478 value.os.data = sid; 479 value.os.len = sidlen; 480 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); 481 CHECK_FCT( fd_msg_avp_add ( *diam_fw, MSG_BRW_FIRST_CHILD, avp) ); 482 CHECK_FCT( fd_msg_sess_set( *diam_fw, *session) ); 478 CHECK_FCT( fd_msg_avp_add ( *diam_fw, MSG_BRW_LAST_CHILD, avp) ); 483 479 484 480 /* … … 721 717 //fd_msg_dump_walk(1,*diam_fw); 722 718 723 /* Store the request identifier in the session (if provided)*/724 if (*session){719 /* Store the request identifier in the session */ 720 { 725 721 unsigned char * req_sip; 726 722 CHECK_MALLOC(req_sip = malloc(16)); 727 723 memcpy(req_sip, &rad_req->hdr->authenticator[0], 16); 728 724 729 CHECK_FCT( fd_sess_state_store( cs->sess_hdl, *session, &req_sip ) );725 CHECK_FCT( fd_sess_state_store( cs->sess_hdl, sess, &req_sip ) ); 730 726 } 731 727 … … 734 730 } 735 731 736 static int sip_diam_ans( struct rgwp_config * cs, struct session * session, struct msg ** diam_ans, struct radius_msg ** rad_fw, struct rgw_client * cli, int * statefull)732 static int sip_diam_ans( struct rgwp_config * cs, struct msg ** diam_ans, struct radius_msg ** rad_fw, struct rgw_client * cli ) 737 733 { 738 734 739 735 740 struct avp *avp, *next , *asid;741 struct avp_hdr *ahdr , *sid;736 struct avp *avp, *next; 737 struct avp_hdr *ahdr; 742 738 //char buf[254]; /* to store some attributes values (with final '\0') */ 743 739 unsigned char * req_sip = NULL; 744 745 TRACE_ENTRY("%p %p %p %p %p", cs, session, diam_ans, rad_fw, cli);746 CHECK_PARAMS(cs && session && diam_ans && *diam_ans && rad_fw && *rad_fw);747 748 749 740 struct session * sess; 741 os0_t sid = NULL; 742 size_t sidlen; 743 744 TRACE_ENTRY("%p %p %p %p", cs, diam_ans, rad_fw, cli); 745 CHECK_PARAMS(cs && diam_ans && *diam_ans && rad_fw && *rad_fw); 750 746 751 747 … … 777 773 } 778 774 779 780 775 /* Search the different AVPs we handle here */ 781 CHECK_FCT( fd_msg_search_avp (*diam_ans, cs->dict.Session_Id, &asid) ); 782 CHECK_FCT( fd_msg_avp_hdr ( asid, &sid ) ); 776 CHECK_FCT( fd_msg_sess_get(fd_g_config->cnf_dict, *diam_ans, &sess, NULL) ); 777 if (sess) { 778 CHECK_FCT( fd_sess_getsid(sess, &sid, &sidlen) ); 779 } 780 783 781 784 782 /* Check the Diameter error code */ … … 804 802 (*rad_fw)->hdr->code = RADIUS_CODE_ACCESS_REJECT; 805 803 fd_log_debug("[sip.rgwx] Received Diameter answer with error code '%d', session %.*s, translating into Access-Reject", 806 ahdr->avp_value->u32, 807 sid->avp_value->os.len, sid->avp_value->os.data); 804 ahdr->avp_value->u32, sidlen, sid); 808 805 return 0; 809 806 } … … 827 824 case DIAM_ATTR_DIGEST_NONCE: 828 825 CONV2RAD_STR(DIAM_ATTR_DIGEST_NONCE, ahdr->avp_value->os.data, ahdr->avp_value->os.len, 0); 829 /* Retrieve the request identified which was stored in the session */ 830 if (session) { 831 os0_t sid=NULL; 832 size_t sidlen; 833 fd_sess_getsid (session, &sid, &sidlen ); 834 835 nonce_add_element(ahdr->avp_value->os.data, ahdr->avp_value->os.len, sid, sidlen, cs); 836 } 826 nonce_add_element(ahdr->avp_value->os.data, ahdr->avp_value->os.len, sid, sidlen, cs); 837 827 break; 838 828 case DIAM_ATTR_DIGEST_REALM: … … 867 857 } 868 858 869 if (session) 870 { 871 CHECK_FCT( fd_sess_state_retrieve( cs->sess_hdl, session, &req_sip ) ); 872 } 859 CHECK_FCT( fd_sess_state_retrieve( cs->sess_hdl, sess, &req_sip ) ); 873 860 free(req_sip); 874 875 861 876 862 return 0;
Note: See TracChangeset
for help on using the changeset viewer.