net: Allow disabling IPv4, IPv6, UDP and TCP simultaneously

This commit fixes compilation warnings if user disables
CONFIG_NET_IPV4, CONFIG_NET_IPV6, CONFIG_NET_TCP and
CONFIG_NET_UDP.

E.g Samples like packet-socket doesn't need above configuration.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
This commit is contained in:
Ravi kumar Veeramally 2019-02-07 15:00:44 +02:00 committed by Jukka Rissanen
parent 8a86b5aaac
commit 36aa7d1878
5 changed files with 42 additions and 11 deletions

View file

@ -53,6 +53,7 @@ static struct net_context contexts[NET_MAX_CONTEXT];
*/
static struct k_sem contexts_lock;
#if defined(CONFIG_NET_UDP) || defined(CONFIG_NET_TCP)
static int check_used_port(enum net_ip_protocol ip_proto,
u16_t local_port,
const struct sockaddr *local_addr)
@ -110,6 +111,7 @@ static u16_t find_available_port(struct net_context *context,
return htons(local_port);
}
#endif
int net_context_get(sa_family_t family,
enum net_sock_type type,
@ -932,7 +934,9 @@ int net_context_connect(struct net_context *context,
void *user_data)
{
struct sockaddr *laddr = NULL;
#if defined(CONFIG_NET_IPV4) || defined(CONFIG_NET_IPV6)
struct sockaddr local_addr;
#endif
u16_t lport, rport;
int ret;
@ -1457,8 +1461,8 @@ static int context_setup_udp_packet(struct net_context *context,
socklen_t addrlen)
{
int ret = -EINVAL;
u16_t dst_port = 0;
size_t written;
u16_t dst_port;
if (IS_ENABLED(CONFIG_NET_IPV4) &&
net_context_get_family(context) == AF_INET) {

View file

@ -41,7 +41,9 @@ extern struct net_if __net_if_end[];
extern struct net_if_dev __net_if_dev_start[];
extern struct net_if_dev __net_if_dev_end[];
#if defined(CONFIG_NET_IPV4) || defined(CONFIG_NET_IPV6)
static struct net_if_router routers[CONFIG_NET_MAX_ROUTERS];
#endif
#if defined(CONFIG_NET_IPV6)
/* Timer that triggers network address renewal */
@ -394,6 +396,7 @@ struct net_if *net_if_get_first_by_type(const struct net_l2 *l2)
return NULL;
}
#if defined(CONFIG_NET_IPV4) || defined(CONFIG_NET_IPV6)
/* Return how many bits are shared between two IP addresses */
static u8_t get_ipaddr_diff(const u8_t *src, const u8_t *dst, int addr_len)
{
@ -419,6 +422,7 @@ static u8_t get_ipaddr_diff(const u8_t *src, const u8_t *dst, int addr_len)
return len;
}
#endif
int net_if_config_ipv6_get(struct net_if *iface, struct net_if_ipv6 **ipv6)
{
@ -3067,7 +3071,10 @@ void net_if_add_tx_timestamp(struct net_pkt *pkt)
void net_if_init(void)
{
struct net_if *iface;
int i, if_count;
int if_count;
#if defined(CONFIG_NET_IPV4) || defined(CONFIG_NET_IPV6)
int i;
#endif
NET_DBG("");

View file

@ -43,7 +43,8 @@ LOG_MODULE_REGISTER(net_pkt, CONFIG_NET_PKT_LOG_LEVEL);
#include "tcp_internal.h"
/* Find max header size of IP protocol (IPv4 or IPv6) */
#if defined(CONFIG_NET_IPV6) || defined(CONFIG_NET_RAW_MODE)
#if defined(CONFIG_NET_IPV6) || defined(CONFIG_NET_RAW_MODE) || \
defined(CONFIG_NET_SOCKETS_PACKET)
#define MAX_IP_PROTO_LEN NET_IPV6H_LEN
#else
#if defined(CONFIG_NET_IPV4)

View file

@ -252,14 +252,18 @@ static void iface_cb(struct net_if *iface, void *user_data)
#if defined(CONFIG_NET_VLAN)
struct ethernet_context *eth_ctx;
#endif
#if defined(CONFIG_NET_IPV4) || defined(CONFIG_NET_IPV6)
struct net_if_addr *unicast;
struct net_if_mcast_addr *mcast;
#endif
#if defined(CONFIG_NET_L2_ETHERNET_MGMT)
struct ethernet_req_params params;
int ret;
#endif
const char *extra;
#if defined(CONFIG_NET_IPV4) || defined(CONFIG_NET_IPV6)
int i, count;
#endif
if (data->user_data && data->user_data != iface) {
return;
@ -725,6 +729,7 @@ static void net_shell_print_statistics(struct net_if *iface, void *user_data)
GET_STAT(iface, ip_errors.chkerr),
GET_STAT(iface, ip_errors.protoerr));
#if defined(CONFIG_NET_ICMPV4) || defined(CONFIG_NET_ICMPV6)
PR("ICMP recv %d\tsent\t%d\tdrop\t%d\n",
GET_STAT(iface, icmp.recv),
GET_STAT(iface, icmp.sent),
@ -732,6 +737,7 @@ static void net_shell_print_statistics(struct net_if *iface, void *user_data)
PR("ICMP typeer %d\tchkerr\t%d\n",
GET_STAT(iface, icmp.typeerr),
GET_STAT(iface, icmp.chkerr));
#endif
#if defined(CONFIG_NET_UDP)
PR("UDP recv %d\tsent\t%d\tdrop\t%d\n",
@ -2778,6 +2784,13 @@ static int _ping_ipv4(const struct shell *shell, char *host)
static int cmd_net_ping(const struct shell *shell, size_t argc, char *argv[])
{
#if !defined(CONFIG_NET_IPV4) && !defined(CONFIG_NET_IPV6)
ARG_UNUSED(shell);
ARG_UNUSED(argc);
ARG_UNUSED(argv);
return -EOPNOTSUPP;
#else
char *host;
int ret;
@ -2826,6 +2839,7 @@ wait_reply:
}
return 0;
#endif
}
static int cmd_net_route(const struct shell *shell, size_t argc, char *argv[])

View file

@ -634,6 +634,12 @@ static bool parse_ipv6(const char *str, size_t str_len,
return true;
}
#else
static inline bool parse_ipv6(const char *str, size_t str_len,
struct sockaddr *addr, bool has_port)
{
return false;
}
#endif /* CONFIG_NET_IPV6 */
#if defined(CONFIG_NET_IPV4)
@ -699,6 +705,12 @@ static bool parse_ipv4(const char *str, size_t str_len,
port);
return true;
}
#else
static inline bool parse_ipv4(const char *str, size_t str_len,
struct sockaddr *addr, bool has_port)
{
return false;
}
#endif /* CONFIG_NET_IPV4 */
bool net_ipaddr_parse(const char *str, size_t str_len, struct sockaddr *addr)
@ -715,11 +727,7 @@ bool net_ipaddr_parse(const char *str, size_t str_len, struct sockaddr *addr)
}
if (*str == '[') {
#if defined(CONFIG_NET_IPV6)
return parse_ipv6(str, str_len, addr, true);
#else
return false;
#endif /* CONFIG_NET_IPV6 */
}
for (count = i = 0; str[i] && i < str_len; i++) {
@ -729,11 +737,7 @@ bool net_ipaddr_parse(const char *str, size_t str_len, struct sockaddr *addr)
}
if (count == 1) {
#if defined(CONFIG_NET_IPV4)
return parse_ipv4(str, str_len, addr, true);
#else
return false;
#endif /* CONFIG_NET_IPV4 */
}
#if defined(CONFIG_NET_IPV4) && defined(CONFIG_NET_IPV6)
@ -751,6 +755,7 @@ bool net_ipaddr_parse(const char *str, size_t str_len, struct sockaddr *addr)
#if defined(CONFIG_NET_IPV6) && !defined(CONFIG_NET_IPV4)
return parse_ipv6(str, str_len, addr, false);
#endif
return false;
}
int net_bytes_from_str(u8_t *buf, int buf_len, const char *src)