Browse code

modules_k/uac: uac_reg: add reg_retry_interval parameter

The new parameter allows to retry failed registration attempts.
Instead of unconditionally marking the entry as disabled, the
registration will be retried after the set interval. Setting it
to 0 (default) retains the old behaviour.

Alex Hermann authored on 10/07/2012 10:41:45
Showing 4 changed files
... ...
@@ -407,6 +407,25 @@ modparam("uac", "reg_timer_interval", 60)
407 407
 			</example>
408 408
 		</section>
409 409
 
410
+		<section id="reg-retry-interval-id">
411
+			<title><varname>reg_retry_interval</varname> (int)</title>
412
+			<para>
413
+			Failed registration attempts will be retried after this interval
414
+			(in seconds). The interval is not exact, retries may be
415
+			attempted as much as reg_timer_interval secs earlier.
416
+			If set to 0, failed registrations will be disabled permanently.
417
+			</para>
418
+			<para>The default value is 0 sec (disabled)</para>
419
+			<example>
420
+				<title>Set <varname>reg_retry_interval</varname> parameter</title>
421
+				<programlisting format="linespecific">
422
+...
423
+modparam("uac", "reg_retry_interval", 300)
424
+...
425
+				</programlisting>
426
+			</example>
427
+		</section>
428
+
410 429
 		<section id="reg-db-table-id">
411 430
 			<title><varname>reg_db_table</varname> (string)</title>
412 431
 			<para>
... ...
@@ -159,6 +159,7 @@ static param_export_t params[] = {
159 159
 	{"reg_db_table",      STR_PARAM,                &reg_db_table.s        },
160 160
 	{"reg_contact_addr",  STR_PARAM,                &reg_contact_addr.s    },
161 161
 	{"reg_timer_interval", INT_PARAM,		&reg_timer_interval	},
162
+	{"reg_retry_interval",INT_PARAM,                &reg_retry_interval    },
162 163
 	{0, 0, 0}
163 164
 };
164 165
 
... ...
@@ -93,6 +93,7 @@ static reg_ht_t *_reg_htable = NULL;
93 93
 
94 94
 int reg_use_domain = 0;
95 95
 int reg_timer_interval = 90;
96
+int reg_retry_interval = 0;
96 97
 int reg_htable_size = 4;
97 98
 int reg_fetch_rows = 1000;
98 99
 str reg_contact_addr = {0, 0};
... ...
@@ -477,17 +478,17 @@ void uac_reg_tm_callback( struct cell *t, int type, struct tmcb_params *ps)
477 478
 		if (parse_headers(ps->rpl, HDR_EOH_F, 0) == -1)
478 479
 		{
479 480
 			LM_ERR("failed to parse headers\n");
480
-			goto done;
481
+			goto error;
481 482
 		}
482 483
 		if (ps->rpl->contact==NULL)
483 484
 		{
484 485
 			LM_ERR("no Contact found\n");
485
-			goto done;
486
+			goto error;
486 487
 		}
487 488
 		if (parse_contact(ps->rpl->contact) < 0)
488 489
 		{
489 490
 			LM_ERR("failed to parse Contact HF\n");
490
-			goto done;
491
+			goto error;
491 492
 		}
492 493
 		if (((contact_body_t*)ps->rpl->contact->parsed)->star)
493 494
 		{
... ...
@@ -502,7 +503,7 @@ void uac_reg_tm_callback( struct cell *t, int type, struct tmcb_params *ps)
502 503
 			if(parse_uri(c->uri.s, c->uri.len, &puri)!=0)
503 504
 			{
504 505
 				LM_ERR("failed to parse c-uri\n");
505
-				goto done;
506
+				goto error;
506 507
 			}
507 508
 			if(suuid.len==puri.user.len
508 509
 					&& (strncmp(puri.user.s, suuid.s, suuid.len)==0))
... ...
@@ -517,7 +518,6 @@ void uac_reg_tm_callback( struct cell *t, int type, struct tmcb_params *ps)
517 518
 					str2int(&c->expires->body, (unsigned int*)(&expires));
518 519
 				}
519 520
 				ri->timer_expires = ri->timer_expires + expires;
520
-				ri->flags &= ~(UAC_REG_ONGOING|UAC_REG_AUTHSENT);
521 521
 				ri->flags |= UAC_REG_ONLINE;
522 522
 				goto done;
523 523
 			}
... ...
@@ -535,15 +535,13 @@ void uac_reg_tm_callback( struct cell *t, int type, struct tmcb_params *ps)
535 535
 		{
536 536
 			LM_ERR("authentication failed for <%.*s>\n",
537 537
 					ri->l_uuid.len, ri->l_uuid.s);
538
-			ri->flags &= ~UAC_REG_ONGOING;
539
-			ri->flags |= UAC_REG_DISABLED;
540
-			goto done;
538
+			goto error;
541 539
 		}
542 540
 		hdr = get_autenticate_hdr(ps->rpl, ps->code);
543 541
 		if (hdr==0)
544 542
 		{
545 543
 			LM_ERR("failed to extract authenticate hdr\n");
546
-			goto done;
544
+			goto error;
547 545
 		}
548 546
 
549 547
 		LM_DBG("auth header body [%.*s]\n",
... ...
@@ -552,7 +550,7 @@ void uac_reg_tm_callback( struct cell *t, int type, struct tmcb_params *ps)
552 550
 		if (parse_authenticate_body(&hdr->body, &auth)<0)
553 551
 		{
554 552
 			LM_ERR("failed to parse auth hdr body\n");
555
-			goto done;
553
+			goto error;
556 554
 		}
557 555
 		if (ri->realm.len>0) {
558 556
 			/* only check if realms match if it is non-empty */
... ...
@@ -579,7 +577,7 @@ void uac_reg_tm_callback( struct cell *t, int type, struct tmcb_params *ps)
579 577
 		if (new_auth_hdr==0)
580 578
 		{
581 579
 			LM_ERR("failed to build authorization hdr\n");
582
-			goto done;
580
+			goto error;
583 581
 		}
584 582
 		
585 583
 #ifdef UAC_OLD_AUTH
... ...
@@ -603,7 +601,7 @@ void uac_reg_tm_callback( struct cell *t, int type, struct tmcb_params *ps)
603 601
 		if(uac_reg_tmdlg(&tmdlg, ps->rpl)<0)
604 602
 		{
605 603
 			LM_ERR("failed to build tm dialog\n");
606
-			goto done;
604
+			goto error;
607 605
 		}
608 606
 		tmdlg.rem_target = s_ruri;
609 607
 		if(ri->auth_proxy.len)
... ...
@@ -625,15 +623,30 @@ void uac_reg_tm_callback( struct cell *t, int type, struct tmcb_params *ps)
625 623
 			);
626 624
 #endif
627 625
 		ret = uac_tmb.t_request_within(&uac_r);
628
-		ri->flags |= UAC_REG_AUTHSENT;
629 626
 
630
-		if(ret<0)
631
-			goto done;
627
+		if(ret<0) {
628
+			LM_ERR("failed to send request with authentication for [%.*s]",
629
+			       ri->l_uuid.len, ri->l_uuid.s);
630
+			goto error;
631
+		}
632
+
633
+		ri->flags |= UAC_REG_AUTHSENT;
632 634
 		return;
635
+	} else
636
+	{
637
+		LM_ERR("got sip response %d while registering [%.*s]\n",
638
+		       ps->code, ri->l_uuid.len, ri->l_uuid.s);
639
+		goto error;
633 640
 	}
634 641
 
642
+error:
643
+	if(reg_retry_interval)
644
+		ri->timer_expires = time(NULL) + reg_retry_interval;
645
+	else
646
+		ri->flags |= UAC_REG_DISABLED;
635 647
 done:
636
-	if(ri) ri->flags &= ~UAC_REG_ONGOING;
648
+	if(ri)
649
+		ri->flags &= ~UAC_REG_ONGOING|UAC_REG_AUTHSENT;
637 650
 	shm_free(uuid);
638 651
 }
639 652
 
... ...
@@ -656,10 +669,10 @@ int uac_reg_update(reg_uac_t *reg, time_t tn)
656 669
 		return 1;
657 670
 	if(reg->flags&UAC_REG_ONGOING)
658 671
 		return 2;
659
-	if(reg->timer_expires > tn + reg_timer_interval + 3)
660
-		return 3;
661 672
 	if(reg->flags&UAC_REG_DISABLED)
662 673
 		return 4;
674
+	if(reg->timer_expires > tn + reg_timer_interval + 3)
675
+		return 3;
663 676
 	reg->timer_expires = tn;
664 677
 	reg->flags |= UAC_REG_ONGOING;
665 678
 	reg->flags &= ~UAC_REG_ONLINE;
... ...
@@ -706,7 +719,13 @@ int uac_reg_update(reg_uac_t *reg, time_t tn)
706 719
 
707 720
 	if(ret<0)
708 721
 	{
722
+		LM_ERR("failed to send request for [%.*s]", reg->l_uuid.len, reg->l_uuid.s);
709 723
 		shm_free(uuid);
724
+		if (reg_retry_interval)
725
+			reg->timer_expires = (tn ? tn : time(NULL)) + reg_retry_interval;
726
+		else
727
+			reg->flags |= UAC_REG_DISABLED;
728
+		reg->flags &= ~UAC_REG_ONGOING;
710 729
 		return -1;
711 730
 	}
712 731
 	return 0;
... ...
@@ -26,6 +26,7 @@
26 26
 #include "../../pvar.h"
27 27
 
28 28
 extern int reg_timer_interval;
29
+extern int reg_retry_interval;
29 30
 extern int reg_htable_size;
30 31
 extern int reg_fetch_rows;
31 32
 extern str reg_contact_addr;