@@ -730,21 +730,16 @@ static bool ipcache_get_hostname(const struct in_addr *a4, const struct in6_addr
730730 if (!params .cache_hostname )
731731 {
732732 * hostname = 0 ;
733- return true ;
733+ return false ;
734734 }
735735 if (params .debug )
736736 {
737737 char s [40 ];
738738 ntopa46 (a4 , a6 , s , sizeof (s ));
739739 DLOG ("ipcache hostname search for %s\n" , s );
740740 }
741- ip_cache_item * ipc = ipcacheTouch (& params .ipcache , a4 , a6 , NULL );
742- if (!ipc )
743- {
744- DLOG_ERR ("ipcache_get_hostname: out of memory\n" );
745- return false;
746- }
747- if (ipc -> hostname )
741+ ip_cache_item * ipc = ipcacheFind (& params .ipcache , a4 , a6 , NULL );
742+ if (ipc && ipc -> hostname )
748743 {
749744 if (params .debug )
750745 {
@@ -757,31 +752,36 @@ static bool ipcache_get_hostname(const struct in_addr *a4, const struct in6_addr
757752 }
758753 else
759754 * hostname = 0 ;
760- return true ;
755+ return * hostname ;
761756}
762757static void ipcache_update_ttl (t_ctrack * ctrack , const struct in_addr * a4 , const struct in6_addr * a6 , const char * iface )
763758{
764759 // no need to cache ttl in server mode because first packet is incoming
765760 if (ctrack && !params .server )
766761 {
767- ip_cache_item * ipc = ipcacheTouch (& params .ipcache , a4 , a6 , iface );
768- if (!ipc )
769- {
770- DLOG_ERR ("ipcache: out of memory\n" );
771- return ;
772- }
762+ ip_cache_item * ipc ;
773763 if (ctrack -> incoming_ttl )
774764 {
765+ ipc = ipcacheTouch (& params .ipcache , a4 , a6 , iface );
766+ if (!ipc )
767+ {
768+ DLOG_ERR ("ipcache: out of memory\n" );
769+ return ;
770+ }
775771 if (ipc -> ttl != ctrack -> incoming_ttl )
776772 {
777773 DLOG ("updated ttl cache\n" );
778774 ipc -> ttl = ctrack -> incoming_ttl ;
779775 }
780776 }
781- else if ( ipc -> ttl )
777+ else
782778 {
783- DLOG ("got cached ttl %u\n" , ipc -> ttl );
784- ctrack -> incoming_ttl = ipc -> ttl ;
779+ ipc = ipcacheFind (& params .ipcache , a4 , a6 , iface );
780+ if (ipc && ipc -> ttl )
781+ {
782+ DLOG ("got cached ttl %u\n" , ipc -> ttl );
783+ ctrack -> incoming_ttl = ipc -> ttl ;
784+ }
785785 }
786786 }
787787}
@@ -790,10 +790,8 @@ static void ipcache_get_ttl(t_ctrack *ctrack, const struct in_addr *a4, const st
790790 // no need to cache ttl in server mode because first packet is incoming
791791 if (ctrack && !ctrack -> incoming_ttl && !params .server )
792792 {
793- ip_cache_item * ipc = ipcacheTouch (& params .ipcache , a4 , a6 , iface );
794- if (!ipc )
795- DLOG_ERR ("ipcache: out of memory\n" );
796- else if (ipc -> ttl )
793+ ip_cache_item * ipc = ipcacheFind (& params .ipcache , a4 , a6 , iface );
794+ if (ipc && ipc -> ttl )
797795 {
798796 DLOG ("got cached ttl %u\n" , ipc -> ttl );
799797 ctrack -> incoming_ttl = ipc -> ttl ;
@@ -897,7 +895,7 @@ static uint8_t desync(
897895 if (LIST_FIRST (& dp -> lua_desync ))
898896 {
899897 lua_rawgeti (params .L , LUA_REGISTRYINDEX , params .ref_desync_ctx );
900- t_lua_desync_context * ctx = (t_lua_desync_context * )luaL_checkudata (params .L , 1 , "desync_ctx" );
898+ t_lua_desync_context * ctx = (t_lua_desync_context * )luaL_checkudata (params .L , - 1 , "desync_ctx" );
901899 // this is singleton stored in the registry. safe to pop
902900 lua_pop (params .L ,1 );
903901
@@ -1264,7 +1262,7 @@ static bool play_prolog(
12641262 hostname_is_ip = ps -> ctrack -> hostname_is_ip ;
12651263 if (!hostname && !ps -> bReverse )
12661264 {
1267- if (ipcache_get_hostname (ps -> sdip4 , ps -> sdip6 , ps -> host , sizeof (ps -> host ), & hostname_is_ip ) && * ps -> host )
1265+ if (ipcache_get_hostname (ps -> sdip4 , ps -> sdip6 , ps -> host , sizeof (ps -> host ), & hostname_is_ip ))
12681266 if (!(hostname = ps -> ctrack -> hostname = strdup (ps -> host )))
12691267 DLOG_ERR ("strdup(host): out of memory\n" );
12701268 }
@@ -1985,8 +1983,8 @@ static uint8_t dpi_desync_icmp_packet(
19851983 hostname = ctrack -> hostname ;
19861984 hostname_is_ip = ctrack -> hostname_is_ip ;
19871985 }
1988- else if (ipcache_get_hostname (dis -> ip ? & dis -> ip -> ip_dst : NULL , dis -> ip6 ? & dis -> ip6 -> ip6_dst : NULL , host , sizeof (host ), & hostname_is_ip ) && * host ||
1989- ipcache_get_hostname (dis -> ip ? & dis -> ip -> ip_src : NULL , dis -> ip6 ? & dis -> ip6 -> ip6_src : NULL , host , sizeof (host ), & hostname_is_ip ) && * host )
1986+ else if (ipcache_get_hostname (dis -> ip ? & dis -> ip -> ip_dst : NULL , dis -> ip6 ? & dis -> ip6 -> ip6_dst : NULL , host , sizeof (host ), & hostname_is_ip ) ||
1987+ ipcache_get_hostname (dis -> ip ? & dis -> ip -> ip_src : NULL , dis -> ip6 ? & dis -> ip6 -> ip6_src : NULL , host , sizeof (host ), & hostname_is_ip ))
19901988 {
19911989 hostname = host ;
19921990 }
@@ -2052,8 +2050,8 @@ static uint8_t dpi_desync_ip_packet(
20522050 bool hostname_is_ip = false;
20532051 const char * hostname = NULL ;
20542052 char host [256 ];
2055- if (ipcache_get_hostname (dis -> ip ? & dis -> ip -> ip_dst : NULL , dis -> ip6 ? & dis -> ip6 -> ip6_dst : NULL , host , sizeof (host ), & hostname_is_ip ) && * host ||
2056- ipcache_get_hostname (dis -> ip ? & dis -> ip -> ip_src : NULL , dis -> ip6 ? & dis -> ip6 -> ip6_src : NULL , host , sizeof (host ), & hostname_is_ip ) && * host )
2053+ if (ipcache_get_hostname (dis -> ip ? & dis -> ip -> ip_dst : NULL , dis -> ip6 ? & dis -> ip6 -> ip6_dst : NULL , host , sizeof (host ), & hostname_is_ip ) ||
2054+ ipcache_get_hostname (dis -> ip ? & dis -> ip -> ip_src : NULL , dis -> ip6 ? & dis -> ip6 -> ip6_src : NULL , host , sizeof (host ), & hostname_is_ip ))
20572055 {
20582056 hostname = host ;
20592057 }
0 commit comments