net: mqtt: Modify SOCKS5 based connections

Current SOCKS5 based connections in mqtt are only
TCP (nonsecure) based. To support TLS based SOCKS5
connections, new methods needs to be introduced.

Instead, removed CONFIG_MQTT_LIB_SOCKS based implementation.
And now mqtt provides an api to set proxy
(mqtt_client_set_proxy()) details. That's enough,
socket layer will take care of making connections through
proxy server.

Fixes: #17037

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
This commit is contained in:
Ravi kumar Veeramally 2019-08-01 16:09:29 +03:00 committed by Jukka Rissanen
commit 8e70bd6f48
8 changed files with 69 additions and 87 deletions

View file

@ -27,6 +27,7 @@
#include <zephyr.h>
#include <zephyr/types.h>
#include <net/tls_credentials.h>
#include <net/net_ip.h>
#include <sys/mutex.h>
#ifdef __cplusplus
@ -349,11 +350,6 @@ enum mqtt_transport_type {
MQTT_TRANSPORT_SECURE,
#endif /* CONFIG_MQTT_LIB_TLS */
#if defined(CONFIG_MQTT_LIB_SOCKS)
/** Use SOCKS5 proxy for MQTT connection. */
MQTT_TRANSPORT_SOCKS,
#endif /* CONFIG_MQTT_LIB_SOCKS */
/** Shall not be used as a transport type.
* Indicator of maximum transport types possible.
*/
@ -387,19 +383,14 @@ struct mqtt_transport {
struct mqtt_sec_config config;
} tls;
#endif /* CONFIG_MQTT_LIB_TLS */
#if defined(CONFIG_MQTT_LIB_SOCKS)
/* SOCKS5 proxy transport for MQTT */
struct {
/** Socket descriptor. */
int sock;
/** SOCKS5 proxy address. */
struct sockaddr_storage *proxy;
} socks5;
#endif /* CONFIG_MQTT_LIB_SOCKS */
};
#if defined(CONFIG_SOCKS)
struct {
struct sockaddr addr;
socklen_t addrlen;
} proxy;
#endif
};
/** @brief MQTT internal state. */
@ -505,6 +496,24 @@ struct mqtt_client {
*/
void mqtt_client_init(struct mqtt_client *client);
#if defined(CONFIG_SOCKS)
/*
* @brief Set proxy server details
*
* @param[in] client Client instance for which the procedure is requested,
* Shall not be NULL.
* @param[in] proxy_addr Proxy server address.
* @param[in] addrlen Proxy server address length.
*
* @return 0 or a negative error code (errno.h) indicating reason of failure.
*
* @note Must be called before calling mqtt_connect().
*/
int mqtt_client_set_proxy(struct mqtt_client *client,
struct sockaddr *proxy_addr,
socklen_t addrlen);
#endif
/**
* @brief API to request new MQTT client connection.
*