Browse code

acc Remove radius support code (now in separate module - acc_radius.so)

Olle E. Johansson authored on 02/01/2017 20:07:38
Showing 8 changed files
... ...
@@ -47,10 +47,6 @@
47 47
 #include "acc_logic.h"
48 48
 #include "acc_api.h"
49 49
 
50
-#ifdef RAD_ACC
51
-#include "../misc_radius/radius.h"
52
-#endif
53
-
54 50
 #ifdef DIAM_ACC
55 51
 #include "diam_dict.h"
56 52
 #include "diam_message.h"
... ...
@@ -62,10 +58,6 @@ extern struct acc_extra *leg_info;
62 58
 extern struct acc_enviroment acc_env;
63 59
 extern char *acc_time_format;
64 60
 
65
-#ifdef RAD_ACC
66
-extern struct acc_extra *rad_extra;
67
-#endif
68
-
69 61
 #ifdef DIAM_ACC
70 62
 extern char *diameter_client_host;
71 63
 extern int diameter_client_port;
... ...
@@ -530,7 +522,7 @@ error:
530 522
 
531 523
 
532 524
 /************ RADIUS & DIAMETER helper functions **************/
533
-#if defined(RAD_ACC) || defined (DIAM_ACC)
525
+#if defined (DIAM_ACC)
534 526
 #ifndef UINT4
535 527
 #define UINT4 uint32_t
536 528
 #endif
... ...
@@ -551,176 +543,6 @@ inline static UINT4 phrase2code(str *phrase)
551 543
 #endif
552 544
 
553 545
 
554
-/********************************************
555
- *        RADIUS  ACCOUNTING
556
- ********************************************/
557
-#ifdef RAD_ACC
558
-enum { RA_ACCT_STATUS_TYPE=0, RA_SERVICE_TYPE, RA_SIP_RESPONSE_CODE,
559
-	RA_SIP_METHOD, RA_TIME_STAMP, RA_STATIC_MAX};
560
-enum {RV_STATUS_START=0, RV_STATUS_STOP, RV_STATUS_ALIVE, RV_STATUS_FAILED,
561
-	RV_SIP_SESSION, RV_STATIC_MAX};
562
-static struct attr
563
-	rd_attrs[RA_STATIC_MAX+ACC_CORE_LEN-2+MAX_ACC_EXTRA+MAX_ACC_LEG];
564
-static struct val rd_vals[RV_STATIC_MAX];
565
-
566
-int init_acc_rad(char *rad_cfg, int srv_type)
567
-{
568
-	int n;
569
-
570
-	memset(rd_attrs, 0, sizeof(rd_attrs));
571
-	memset(rd_vals, 0, sizeof(rd_vals));
572
-	rd_attrs[RA_ACCT_STATUS_TYPE].n  = "Acct-Status-Type";
573
-	rd_attrs[RA_SERVICE_TYPE].n      = "Service-Type";
574
-	rd_attrs[RA_SIP_RESPONSE_CODE].n = "Sip-Response-Code";
575
-	rd_attrs[RA_SIP_METHOD].n        = "Sip-Method";
576
-	rd_attrs[RA_TIME_STAMP].n        = "Event-Timestamp";
577
-	n = RA_STATIC_MAX;
578
-	/* caution: keep these aligned to core acc output */
579
-	rd_attrs[n++].n                  = "Sip-From-Tag";
580
-	rd_attrs[n++].n                  = "Sip-To-Tag";
581
-	rd_attrs[n++].n                  = "Acct-Session-Id";
582
-
583
-	rd_vals[RV_STATUS_START].n        = "Start";
584
-	rd_vals[RV_STATUS_STOP].n         = "Stop";
585
-	rd_vals[RV_STATUS_ALIVE].n        = "Alive";
586
-	rd_vals[RV_STATUS_FAILED].n       = "Failed";
587
-	rd_vals[RV_SIP_SESSION].n         = "Sip-Session";
588
-
589
-	/* add and count the extras as attributes */
590
-	n += extra2attrs( rad_extra, rd_attrs, n);
591
-	/* add and count the legs as attributes */
592
-	n += extra2attrs( leg_info, rd_attrs, n);
593
-
594
-	/* read config */
595
-	if ((rh = rc_read_config(rad_cfg)) == NULL) {
596
-		LM_ERR("failed to open radius config file: %s\n", rad_cfg );
597
-		return -1;
598
-	}
599
-	/* read dictionary */
600
-	if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary"))!=0) {
601
-		LM_ERR("failed to read radius dictionary\n");
602
-		return -1;
603
-	}
604
-
605
-	INIT_AV(rh, rd_attrs, n, rd_vals, RV_STATIC_MAX, "acc", -1, -1);
606
-
607
-	if (srv_type != -1)
608
-		rd_vals[RV_SIP_SESSION].v = srv_type;
609
-
610
-	return 0;
611
-}
612
-
613
-
614
-static inline UINT4 rad_status( struct sip_msg *req, int code )
615
-{
616
-        str tag;
617
-        unsigned int in_dialog_req = 0;
618
-
619
-        tag = get_to(req)->tag_value;
620
-        if(tag.s!=0 && tag.len!=0)
621
-		in_dialog_req = 1;
622
-
623
-	if (req->REQ_METHOD==METHOD_INVITE && in_dialog_req == 0
624
-	            && code>=200 && code<300)
625
- 		return rd_vals[RV_STATUS_START].v;
626
- 	if ((req->REQ_METHOD==METHOD_BYE || req->REQ_METHOD==METHOD_CANCEL))
627
- 		return rd_vals[RV_STATUS_STOP].v;
628
-	if (in_dialog_req != 0)
629
-		return rd_vals[RV_STATUS_ALIVE].v;
630
- 	return rd_vals[RV_STATUS_FAILED].v;
631
- }
632
-
633
-#define ADD_RAD_AVPAIR(_attr,_val,_len)		\
634
-    do {								\
635
-	if (!rc_avpair_add(rh, &send, rd_attrs[_attr].v, _val, _len, 0)) { \
636
-	    LM_ERR("failed to add %s, %d\n", rd_attrs[_attr].n, _attr);	\
637
-	    goto error;							\
638
-	} \
639
-    }while(0)
640
-
641
-int acc_rad_request( struct sip_msg *req )
642
-{
643
-	int attr_cnt;
644
-	VALUE_PAIR *send;
645
-	UINT4 av_type;
646
-	int offset;
647
-	int i;
648
-	int m;
649
-	int o;
650
-
651
-	send=NULL;
652
-
653
-	attr_cnt = core2strar( req, val_arr, int_arr, type_arr );
654
-	/* not interested in the last 2 values */
655
-	attr_cnt -= 2;
656
-
657
-	av_type = rad_status( req, acc_env.code); /* RADIUS status */
658
-	ADD_RAD_AVPAIR( RA_ACCT_STATUS_TYPE, &av_type, -1);
659
-
660
-	av_type = rd_vals[RV_SIP_SESSION].v; /* session*/
661
-	ADD_RAD_AVPAIR( RA_SERVICE_TYPE, &av_type, -1);
662
-
663
-	av_type = (UINT4)acc_env.code; /* status=integer */
664
-	ADD_RAD_AVPAIR( RA_SIP_RESPONSE_CODE, &av_type, -1);
665
-
666
-	av_type = req->REQ_METHOD; /* method */
667
-	ADD_RAD_AVPAIR( RA_SIP_METHOD, &av_type, -1);
668
-
669
-	/* unix time */
670
-	av_type = (UINT4)acc_env.ts;
671
-	ADD_RAD_AVPAIR( RA_TIME_STAMP, &av_type, -1);
672
-
673
-	/* add extra also */
674
-	o = extra2strar(rad_extra, req, val_arr+attr_cnt,
675
-				int_arr+attr_cnt, type_arr+attr_cnt);
676
-	attr_cnt += o;
677
-	m = attr_cnt;
678
-
679
-	/* add the values for the vector - start from 1 instead of
680
-	 * 0 to skip the first value which is the METHOD as string */
681
-	offset = RA_STATIC_MAX-1;
682
-	for( i=1; i<attr_cnt; i++) {
683
-	    switch (type_arr[i]) {
684
-	    case TYPE_STR:
685
-		ADD_RAD_AVPAIR(offset+i, val_arr[i].s, val_arr[i].len);
686
-		break;
687
-	    case TYPE_INT:
688
-		ADD_RAD_AVPAIR(offset+i, &(int_arr[i]), -1);
689
-		break;
690
-	    default:
691
-		break;
692
-	    }
693
-	}
694
-
695
-	/* call-legs attributes also get inserted */
696
-	if ( leg_info ) {
697
-		offset += attr_cnt;
698
-		attr_cnt = legs2strar(leg_info,req,val_arr,int_arr,type_arr,1);
699
-		do {
700
-			for (i=0; i<attr_cnt; i++)
701
-				ADD_RAD_AVPAIR( offset+i, val_arr[i].s, val_arr[i].len );
702
-		}while ( (attr_cnt=legs2strar(leg_info,req,val_arr,int_arr,
703
-					      type_arr, 0))!=0 );
704
-	}
705
-
706
-	if (rc_acct(rh, SIP_PORT, send)!=OK_RC) {
707
-		LM_ERR("radius-ing failed\n");
708
-		goto error;
709
-	}
710
-	rc_avpair_free(send);
711
-	/* free memory allocated by extra2strar */
712
-	free_strar_mem( &(type_arr[m-o]), &(val_arr[m-o]), o, m);
713
-	return 1;
714
-
715
-error:
716
-	rc_avpair_free(send);
717
-	/* free memory allocated by extra2strar */
718
-	free_strar_mem( &(type_arr[m-o]), &(val_arr[m-o]), o, m);
719
-	return -1;
720
-}
721
-
722
-#endif
723
-
724 546
 
725 547
 /********************************************
726 548
  *        DIAMETER  ACCOUNTING
... ...
@@ -85,11 +85,6 @@ int  acc_db_request( struct sip_msg *req);
85 85
 int acc_get_db_handlers(void **vf, void **vh);
86 86
 #endif
87 87
 
88
-#ifdef RAD_ACC
89
-int  init_acc_rad(char *rad_cfg, int srv_type);
90
-int  acc_rad_request( struct sip_msg *req );
91
-#endif
92
-
93 88
 #ifdef DIAM_ACC
94 89
 int  acc_diam_init(void);
95 90
 int  acc_diam_request( struct sip_msg *req );
... ...
@@ -189,22 +189,6 @@ void destroy_extras( struct acc_extra *extra)
189 189
 }
190 190
 
191 191
 
192
-#ifdef RAD_ACC
193
-/*! \brief extra name is moved as string part of an attribute; str.len will contain an
194
- * index to the corresponding attribute
195
- */
196
-int extra2attrs( struct acc_extra *extra, struct attr *attrs, int offset)
197
-{
198
-	int i;
199
-
200
-	for(i=0 ; extra ; i++, extra=extra->next) {
201
-		attrs[offset+i].n = extra->name.s;
202
-	}
203
-	return i;
204
-}
205
-#endif
206
-
207
-
208 192
 /*! \brief converts the name of the extra from str to integer 
209 193
  * and stores it over str.len ; str.s is freed and made zero
210 194
  */
... ...
@@ -56,11 +56,6 @@ int legs2strar( struct acc_extra *legs, struct sip_msg *rq, str *val_arr,
56 56
 
57 57
 int extra2int( struct acc_extra *extra, int *attrs );
58 58
 
59
-#ifdef RAD_ACC
60
-#include "../misc_radius/radius.h"
61
-int extra2attrs( struct acc_extra *extra, struct attr *attrs, int offset);
62
-#endif
63
-
64 59
 static inline void free_strar_mem( char* type_arr, str* alloc_arr, int dim_arr, int dim_ext){
65 60
 	int i = 0;
66 61
 	for ( i = 0; i < dim_arr; i ++ ) {
... ...
@@ -67,14 +67,6 @@ struct acc_enviroment acc_env;
67 67
 	#define is_db_mc_on(_rq)      (0)
68 68
 #endif
69 69
 
70
-#ifdef RAD_ACC
71
-	#define is_rad_acc_on(_rq)     is_acc_flag_set(_rq,radius_flag)
72
-	#define is_rad_mc_on(_rq)      is_acc_flag_set(_rq,radius_missed_flag)
73
-#else
74
-	#define is_rad_acc_on(_rq)     (0)
75
-	#define is_rad_mc_on(_rq)      (0)
76
-#endif
77
-
78 70
 
79 71
 #ifdef DIAM_ACC
80 72
 	#define is_diam_acc_on(_rq)     is_acc_flag_set(_rq,diameter_flag)
... ...
@@ -86,11 +78,11 @@ struct acc_enviroment acc_env;
86 78
 
87 79
 #define is_acc_on(_rq) \
88 80
 	( (is_log_acc_on(_rq)) || (is_db_acc_on(_rq)) \
89
-	|| (is_rad_acc_on(_rq)) || (is_diam_acc_on(_rq)) )
81
+	|| (is_diam_acc_on(_rq)) )
90 82
 
91 83
 #define is_mc_on(_rq) \
92 84
 	( (is_log_mc_on(_rq)) || (is_db_mc_on(_rq)) \
93
-	|| (is_rad_mc_on(_rq)) || (is_diam_mc_on(_rq)) )
85
+	|| (is_diam_mc_on(_rq)) )
94 86
 
95 87
 #define skip_cancel(_rq) \
96 88
 	(((_rq)->REQ_METHOD==METHOD_CANCEL) && report_cancels==0)
... ...
@@ -279,22 +271,6 @@ int w_acc_db_request(struct sip_msg *rq, char *comment, char *table)
279 271
 }
280 272
 #endif
281 273
 
282
-
283
-#ifdef RAD_ACC
284
-int w_acc_rad_request(struct sip_msg *rq, char *comment, char *foo)
285
-{
286
-	struct acc_param *param = (struct acc_param*)comment;
287
-	if (acc_preparse_req(rq)<0)
288
-		return -1;
289
-	if(acc_get_param_value(rq, param)<0)
290
-		return -1;
291
-	env_set_to( rq->to );
292
-	env_set_comment(param);
293
-	return acc_rad_request(rq);
294
-}
295
-#endif
296
-
297
-
298 274
 #ifdef DIAM_ACC
299 275
 int w_acc_diam_request(struct sip_msg *rq, char *comment, char *foo)
300 276
 {
... ...
@@ -445,12 +421,7 @@ static inline void on_missed(struct cell *t, struct sip_msg *req,
445 421
 		flags_to_reset |= db_missed_flag;
446 422
 	}
447 423
 #endif
448
-#ifdef RAD_ACC
449
-	if (is_rad_mc_on(req)) {
450
-		acc_rad_request( req );
451
-		flags_to_reset |= radius_missed_flag;
452
-	}
453
-#endif
424
+
454 425
 /* DIAMETER */
455 426
 #ifdef DIAM_ACC
456 427
 	if (is_diam_mc_on(req)) {
... ...
@@ -539,10 +510,7 @@ static inline void acc_onreply( struct cell* t, struct sip_msg *req,
539 510
 		}
540 511
 	}
541 512
 #endif
542
-#ifdef RAD_ACC
543
-	if (is_rad_acc_on(preq))
544
-		acc_rad_request(preq);
545
-#endif
513
+
546 514
 /* DIAMETER */
547 515
 #ifdef DIAM_ACC
548 516
 	if (is_diam_acc_on(preq))
... ...
@@ -596,11 +564,7 @@ static inline void acc_onack( struct cell* t, struct sip_msg *req,
596 564
 		acc_db_request( ack );
597 565
 	}
598 566
 #endif
599
-#ifdef RAD_ACC
600
-	if (is_rad_acc_on(req)) {
601
-		acc_rad_request(ack);
602
-	}
603
-#endif
567
+
604 568
 /* DIAMETER */
605 569
 #ifdef DIAM_ACC
606 570
 	if (is_diam_acc_on(req)) {
... ...
@@ -45,10 +45,6 @@ int w_acc_log_request(struct sip_msg *rq, char *comment, char *foo);
45 45
 int w_acc_db_request(struct sip_msg *rq, char *comment, char *table);
46 46
 #endif
47 47
 
48
-#ifdef RAD_ACC
49
-int w_acc_rad_request(struct sip_msg *rq, char *comment, char *foo);
50
-#endif
51
-
52 48
 #ifdef DIAM_ACC
53 49
 int w_acc_diam_request(struct sip_msg *rq, char *comment, char *foo);
54 50
 #endif
... ...
@@ -53,10 +53,6 @@
53 53
 #include "acc_logic.h"
54 54
 #include "acc_cdr.h"
55 55
 
56
-#ifdef RAD_ACC
57
-#include "../misc_radius/radius.h"
58
-#endif
59
-
60 56
 #ifdef DIAM_ACC
61 57
 #include "diam_dict.h"
62 58
 #include "diam_tcp.h"
... ...
@@ -136,23 +132,6 @@ str acc_cdrs_table = str_init("");
136 132
 
137 133
 /*@}*/
138 134
 
139
-/* ----- RADIUS acc variables ----------- */
140
-/*! \name AccRadiusVariables  Radius Variables */     
141
-/*@{*/
142
-
143
-#ifdef RAD_ACC
144
-static char *radius_config = 0;
145
-int radius_flag = -1;
146
-int radius_missed_flag = -1;
147
-static int service_type = -1;
148
-void *rh;
149
-/* rad extra variables */
150
-static char *rad_extra_str = 0;
151
-struct acc_extra *rad_extra = 0;
152
-#endif
153
-/*@}*/
154
-
155
-
156 135
 /* ----- DIAMETER acc variables ----------- */
157 136
 
158 137
 /*! \name AccDiamaterVariables  Radius Variables */     
... ...
@@ -216,11 +195,6 @@ static cmd_export_t cmds[] = {
216 195
 		acc_fixup, free_acc_fixup,
217 196
 		ANY_ROUTE},
218 197
 #endif
219
-#ifdef RAD_ACC
220
-	{"acc_rad_request", (cmd_function)w_acc_rad_request, 1,
221
-		acc_fixup, free_acc_fixup,
222
-		ANY_ROUTE},
223
-#endif
224 198
 #ifdef DIAM_ACC
225 199
 	{"acc_diam_request",(cmd_function)w_acc_diam_request,1,
226 200
 		acc_fixup, free_acc_fixup,
... ...
@@ -259,13 +233,6 @@ static param_export_t params[] = {
259 233
 	{"cdr_end_id",		 PARAM_STR, &cdr_end_str		},
260 234
 	{"cdr_duration_id",	 PARAM_STR, &cdr_duration_str	},
261 235
 	{"cdr_expired_dlg_enable", INT_PARAM, &cdr_expired_dlg_enable   },
262
-#ifdef RAD_ACC
263
-	{"radius_config",        PARAM_STRING, &radius_config     },
264
-	{"radius_flag",          INT_PARAM, &radius_flag          },
265
-	{"radius_missed_flag",   INT_PARAM, &radius_missed_flag   },
266
-	{"service_type",         INT_PARAM, &service_type         },
267
-	{"radius_extra",         PARAM_STRING, &rad_extra_str     },
268
-#endif
269 236
 	/* DIAMETER specific */
270 237
 #ifdef DIAM_ACC
271 238
 	{"diameter_flag",        INT_PARAM, &diameter_flag        },
... ...
@@ -618,37 +585,6 @@ static int mod_init( void )
618 585
 	}
619 586
 #endif
620 587
 
621
-	/* ------------ RADIUS INIT SECTION ----------- */
622
-
623
-#ifdef RAD_ACC
624
-	if (radius_config && radius_config[0]) {
625
-		/* parse the extra string, if any */
626
-		if (rad_extra_str && (rad_extra=parse_acc_extra(rad_extra_str))==0 ) {
627
-			LM_ERR("failed to parse rad_extra param\n");
628
-			return -1;
629
-		}
630
-
631
-		/* fix the flags */
632
-		if ((radius_flag != -1) && !flag_in_range(radius_flag)) {
633
-			LM_ERR("radius_flag set to invalid value\n");
634
-			return -1;
635
-		}
636
-
637
-		if ((radius_missed_flag != -1) && !flag_in_range(radius_missed_flag)) {
638
-			LM_ERR("radius_missed_flag set to invalid value\n");
639
-			return -1;
640
-		}
641
-
642
-		if (init_acc_rad( radius_config, service_type)!=0 ) {
643
-			LM_ERR("failed to init radius\n");
644
-			return -1;
645
-		}
646
-	} else {
647
-		radius_config = 0;
648
-		radius_flag = -1;
649
-		radius_missed_flag = -1;
650
-	}
651
-#endif
652 588
 
653 589
 	/* ------------ DIAMETER INIT SECTION ----------- */
654 590
 
... ...
@@ -732,10 +668,6 @@ static void destroy(void)
732 668
 	if (db_extra)
733 669
 		destroy_extras( db_extra);
734 670
 #endif
735
-#ifdef RAD_ACC
736
-	if (rad_extra)
737
-		destroy_extras( rad_extra);
738
-#endif
739 671
 #ifdef DIAM_ACC
740 672
 	close_tcp_connection(sockfd);
741 673
 	if (dia_extra)
... ...
@@ -53,12 +53,6 @@ extern int cdr_start_on_confirmed;
53 53
 extern int cdr_log_facility;
54 54
 extern int cdr_expired_dlg_enable;
55 55
 
56
-#ifdef RAD_ACC
57
-extern int radius_flag;
58
-extern int radius_missed_flag;
59
-extern void *rh;
60
-#endif
61
-
62 56
 #ifdef DIAM_ACC
63 57
 #include "diam_tcp.h"
64 58
 extern rd_buf_t *rb;