... | ... |
@@ -290,6 +290,10 @@ static pv_spec_t *media_duration_pvar = NULL; |
290 | 290 |
char* force_send_ip_str=""; |
291 | 291 |
int force_send_ip_af = AF_UNSPEC; |
292 | 292 |
|
293 |
+ |
|
294 |
+ |
|
295 |
+static enum hash_algo_t hash_algo = RTP_HASH_CALLID; |
|
296 |
+ |
|
293 | 297 |
typedef struct rtpp_set_link { |
294 | 298 |
struct rtpp_set *rset; |
295 | 299 |
pv_spec_t *rpv; |
... | ... |
@@ -443,6 +447,7 @@ static param_export_t params[] = { |
443 | 447 |
{"hash_table_size", INT_PARAM, &hash_table_size }, |
444 | 448 |
{"setid_default", INT_PARAM, &setid_default }, |
445 | 449 |
{"media_duration", PARAM_STR, &media_duration_pvar_str}, |
450 |
+ {"hash_algo", INT_PARAM, &hash_algo}, |
|
446 | 451 |
|
447 | 452 |
/* MOS stats output */ |
448 | 453 |
/* global averages */ |
... | ... |
@@ -1724,9 +1729,11 @@ mod_init(void) |
1724 | 1729 |
return -1; |
1725 | 1730 |
} |
1726 | 1731 |
|
1727 |
- if (load_crypto_api(&rtpengine_cb) != 0) { |
|
1728 |
- LM_WARN("Crypto module not loaded! Won't use SHA1 hashing! Distribution " |
|
1729 |
- "algorithm might not perform well under heavy load!\n"); |
|
1732 |
+ if (hash_algo == RTP_HASH_SHA1_CALLID) { |
|
1733 |
+ if (load_crypto_api(&rtpengine_cb) != 0) { |
|
1734 |
+ LM_ERR("Crypto module required in order to have SHA1 hashing!\n"); |
|
1735 |
+ return -1; |
|
1736 |
+ } |
|
1730 | 1737 |
} |
1731 | 1738 |
|
1732 | 1739 |
return 0; |
... | ... |
@@ -2912,13 +2919,27 @@ select_rtpp_node_new(str callid, str viabranch, int do_test, struct rtpp_node ** |
2912 | 2919 |
|
2913 | 2920 |
str hash_data; |
2914 | 2921 |
|
2915 |
- if (rtpengine_cb.SHA1 == NULL) { |
|
2916 |
- hash_data = callid; |
|
2917 |
- } else { |
|
2918 |
- if (rtpengine_cb.SHA1(&callid, &hash_data) < 0) { |
|
2919 |
- LM_ERR("SHA1 hash in crypto module failed!\n"); |
|
2922 |
+ switch (hash_algo) { |
|
2923 |
+ case RTP_HASH_CALLID: |
|
2924 |
+ hash_data = callid; |
|
2925 |
+ |
|
2926 |
+ break; |
|
2927 |
+ case RTP_HASH_SHA1_CALLID: |
|
2928 |
+ if (rtpengine_cb.SHA1 == NULL) { |
|
2929 |
+ /* don't throw warning here; there is already a warni*/ |
|
2930 |
+ LM_BUG("SHA1 algo set but crypto not loaded! Program shouldn't have started!"); |
|
2931 |
+ return NULL; |
|
2932 |
+ } |
|
2933 |
+ |
|
2934 |
+ if (rtpengine_cb.SHA1(&callid, &hash_data) < 0) { |
|
2935 |
+ LM_ERR("SHA1 hash in crypto module failed!\n"); |
|
2936 |
+ return NULL; |
|
2937 |
+ } |
|
2938 |
+ |
|
2939 |
+ break; |
|
2940 |
+ default: |
|
2941 |
+ LM_ERR("unknown hashing algo %d\n", hash_algo); |
|
2920 | 2942 |
return NULL; |
2921 |
- } |
|
2922 | 2943 |
} |
2923 | 2944 |
|
2924 | 2945 |
/* XXX Use quick-and-dirty hashing algo */ |
... | ... |
@@ -2926,8 +2947,11 @@ select_rtpp_node_new(str callid, str viabranch, int do_test, struct rtpp_node ** |
2926 | 2947 |
for(i = 0; i < hash_data.len; i++) |
2927 | 2948 |
sum += hash_data.s[i]; |
2928 | 2949 |
|
2929 |
- /* FIXME this seems to affect the algorithm in a negative way */ |
|
2930 |
- // sum &= 0xff; |
|
2950 |
+ /* FIXME this seems to affect the algorithm in a negative way |
|
2951 |
+ * legacy code uses it; disable it for other algos */ |
|
2952 |
+ if (hash_algo == RTP_HASH_CALLID) { |
|
2953 |
+ sum &= 0xff; |
|
2954 |
+ } |
|
2931 | 2955 |
|
2932 | 2956 |
retry: |
2933 | 2957 |
weight_sum = 0; |