net: conn: Remove unregistered connection from cache

When connection handler was unregistered, we did not remove
it from cache. This caused invalid connection to be passed to
net_context after connection unregister if connection caching
was enabled.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
Jukka Rissanen 2017-05-17 13:53:55 +03:00
commit 6f25eb097e

View file

@ -311,10 +311,28 @@ static inline enum net_verdict cache_check(enum net_ip_protocol proto,
return NET_CONTINUE;
}
static inline void cache_remove(struct net_conn *conn)
{
int i;
for (i = 0; i < CONFIG_NET_MAX_CONN; i++) {
if (conn_cache[i].idx < 0 ||
conn_cache[i].idx >= CONFIG_NET_MAX_CONN) {
continue;
}
if (&conns[conn_cache[i].idx] == conn) {
conn_cache[i].idx = -1;
break;
}
}
}
#else
#define cache_clear(...)
#define cache_add_neg(...)
#define cache_check(...) NET_CONTINUE
#define cache_remove(...)
#endif /* CONFIG_NET_CONN_CACHE */
int net_conn_unregister(struct net_conn_handle *handle)
@ -329,6 +347,8 @@ int net_conn_unregister(struct net_conn_handle *handle)
return -ENOENT;
}
cache_remove(conn);
NET_DBG("[%zu] connection handler %p removed",
(conn - conns) / sizeof(*conn), conn);