MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / put_dnscache_value

Function put_dnscache_value

modules/dns_cache/dns_cache.c:830–896  ·  view source on GitHub ↗

Pushes internal structure ( hostent or rdata ) to a cache backend * * Params: * name - what query to be saved - binary IP for PTR and strings for other queries * r_type - type of DNS query * record - pointer to hostent or rdata * rdata_len - If rdata record, rdata_len holds the actual length of rdata buf, * in order to avoid double iterations on the rdata struct. If it's a * PTR record,

Source from the content-addressed store, hash-verified

828 * -1 - internal failure
829 */
830int put_dnscache_value(char *name,int r_type,void *record,int rdata_len,
831 int failure,int ttl)
832{
833 str key,value;
834 int key_ttl;
835
836 if (cdbc == NULL) {
837 /* assume dns request before forking - cache is not ready yet */
838 return 1;
839 }
840
841 /* avoid caching records with TTL=0 */
842 if (!failure && ttl==0) {
843 /* RFC1035 states : "Zero TTL values are interpreted to mean that
844 the RR can only be used for the transaction in progress, and
845 should not be cached." */
846 return 1;
847 }
848
849 /* generate key */
850 key.s=create_keyname_for_record(name,r_type,rdata_len,&key.len);
851 if (key.s == NULL) {
852 LM_ERR("failed to create key\n");
853 return -1;
854 }
855 value.len = 0;
856 value.s = 0;
857
858 if (failure) {
859 /* just set value as failure marker, and push to back-end
860 * with the default timeout */
861 value.s = FAILURE_MARKER;
862 value.len= FAILURE_MARKER_LEN;
863 key_ttl = blacklist_timeout;
864 } else {
865 if (r_type == T_A || r_type == T_AAAA || r_type == T_PTR) {
866 value.s = serialize_he_rdata((struct hostent *)record,
867 &value.len,CACHEDB_CAPABILITY(&cdbf,CACHEDB_CAP_BINARY_VALUE)?0:1);
868 if (value.s == NULL) {
869 LM_ERR("failed to serialize he rdata\n");
870 return -1;
871 }
872 } else {
873 value.s = serialize_dns_rdata((struct rdata *)record,
874 rdata_len,&value.len,CACHEDB_CAPABILITY(&cdbf,CACHEDB_CAP_BINARY_VALUE)?0:1);
875 if (value.s == NULL) {
876 LM_ERR("failed to serialize rdata record\n");
877 return -1;
878 }
879 }
880
881 key_ttl = ttl;
882
883 if (min_ttl > 0 && key_ttl < min_ttl) {
884 key_ttl = min_ttl;
885 }
886 }
887

Callers

nothing calls this directly

Calls 3

serialize_he_rdataFunction · 0.85
serialize_dns_rdataFunction · 0.85

Tested by

no test coverage detected