Browse code

registrar: new parameter lookup_filter_mode

- control what filters should be applied for lookup(...) operations
- filter values are specified via filed of xavp_cfg
- implemented filter for branch flags matching

Daniel-Constantin Mierla authored on 15/04/2019 09:22:45
Showing 2 changed files
... ...
@@ -45,6 +45,54 @@
45 45
 #include "lookup.h"
46 46
 #include "config.h"
47 47
 
48
+
49
+extern int reg_lookup_filter_mode;
50
+
51
+typedef struct reg_lookup_filter {
52
+	uint32_t factive;
53
+	uint32_t bflags;
54
+} reg_lookup_filter_t;
55
+
56
+static reg_lookup_filter_t _reg_lookup_filter;
57
+
58
+static void reg_lookup_filter_init(void)
59
+{
60
+	str filter_bflags = str_init("rlf_bflags");
61
+	sr_xavp_t *vavp = NULL;
62
+
63
+	if(reg_lookup_filter_mode==0 || reg_xavp_cfg.s==NULL) {
64
+		return;
65
+	}
66
+	memset(&_reg_lookup_filter, 0, sizeof(reg_lookup_filter_t));
67
+
68
+	if((reg_lookup_filter_mode & 1)
69
+			&& (vavp = xavp_get_child_with_ival(&reg_xavp_cfg,
70
+					&filter_bflags)) != NULL) {
71
+		if(vavp->val.v.i != 0) {
72
+			_reg_lookup_filter.bflags = (uint32_t)vavp->val.v.i;
73
+			_reg_lookup_filter.factive = 1;
74
+		}
75
+	}
76
+	return;
77
+}
78
+
79
+static int reg_lookup_filter_match(ucontact_t* ptr)
80
+{
81
+	if(reg_lookup_filter_mode==0 || reg_xavp_cfg.s==NULL) {
82
+		return 1;
83
+	}
84
+	if(_reg_lookup_filter.factive==0) {
85
+		return 1;
86
+	}
87
+	if(_reg_lookup_filter.bflags!=0) {
88
+		if((_reg_lookup_filter.bflags & ptr->cflags)==0) {
89
+			return 0;
90
+		}
91
+	}
92
+	return 1;
93
+
94
+}
95
+
48 96
 static int has_to_tag(struct sip_msg* msg)
49 97
 {
50 98
 	if (parse_to_header(msg) < 0) return 0;
... ...
@@ -223,6 +271,7 @@ int lookup_helper(struct sip_msg* _m, udomain_t* _d, str* _uri, int _mode)
223 271
 	}
224 272
 
225 273
 	get_act_time();
274
+	reg_lookup_filter_init();
226 275
 
227 276
 	if(puri.gr.s==NULL || puri.gr_val.len>0)
228 277
 	{
... ...
@@ -251,10 +300,12 @@ int lookup_helper(struct sip_msg* _m, udomain_t* _d, str* _uri, int _mode)
251 300
 							break;
252 301
 						}
253 302
 					} else {
254
-						/* no-gruu - found by address */
255
-						LM_DBG("contact for [%.*s] found by address\n",
256
-								aor.len, ZSW(aor.s));
257
-						break;
303
+						if(reg_lookup_filter_match(ptr)) {
304
+							/* no-gruu - found by address */
305
+							LM_DBG("contact for [%.*s] found by address\n",
306
+									aor.len, ZSW(aor.s));
307
+							break;
308
+						}
258 309
 					}
259 310
 				} else {
260 311
 					LM_DBG("contact for [%.*s] cannot handle the SIP method\n",
... ...
@@ -417,7 +468,8 @@ int lookup_helper(struct sip_msg* _m, udomain_t* _d, str* _uri, int _mode)
417 468
 	if (!cfg_get(registrar, registrar_cfg, append_branches)) goto done;
418 469
 
419 470
 	for( ; ptr ; ptr = ptr->next ) {
420
-		if (VALID_CONTACT(ptr, act_time) && allowed_method(_m, ptr)) {
471
+		if (VALID_CONTACT(ptr, act_time) && allowed_method(_m, ptr)
472
+				&& reg_lookup_filter_match(ptr)) {
421 473
 			path_dst.len = 0;
422 474
 			if(ptr->path.s && ptr->path.len) {
423 475
 				path_str = ptr->path;
... ...
@@ -135,6 +135,8 @@ str sock_hdr_name = {0,0};
135 135
 int reg_expire_event_rt = -1; /* default disabled */
136 136
 str reg_event_callback = STR_NULL;
137 137
 
138
+int reg_lookup_filter_mode = 0;
139
+
138 140
 sr_kemi_eng_t *keng = NULL;
139 141
 
140 142
 #define RCV_NAME "received"
... ...
@@ -239,6 +241,7 @@ static param_export_t params[] = {
239 241
 	{"flow_timer",         INT_PARAM, &reg_flow_timer					},
240 242
 	{"contact_max_size",   INT_PARAM, &contact_max_size					},
241 243
 	{"event_callback",     PARAM_STR, &reg_event_callback				},
244
+	{"lookup_filter_mode", INT_PARAM, &reg_lookup_filter_mode			},
242 245
 	{0, 0, 0}
243 246
 };
244 247