net: Initial UDP support

Create a handler for catching UDP network traffic. This commit
is only providing infrastructure for UDP management.

Change-Id: Ia6f8de62773a85f7b637b73bfe3c89197cc2abb1
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
Jukka Rissanen 2016-06-14 10:00:55 +03:00
parent 00e77da356
commit 4c9c626129
5 changed files with 104 additions and 1 deletions

View file

@ -191,6 +191,7 @@ static inline void net_nbuf_ll_swap(struct net_buf *buf)
#define NET_IPV6_BUF(buf) ((struct net_ipv6_hdr *)net_nbuf_ip_data(buf))
#define NET_IPV4_BUF(buf) ((struct net_ipv4_hdr *)net_nbuf_ip_data(buf))
#define NET_ICMP_BUF(buf) ((struct net_icmp_hdr *)net_nbuf_icmp_data(buf))
#define NET_UDP_BUF(buf) ((struct net_udp_hdr *)(net_nbuf_udp_data(buf)))
#define net_nbuf_set_src_ipv6_addr(buf) \
net_if_select_src(net_context_get_if(nbuf_context(buf)), \

View file

@ -322,6 +322,12 @@ config NETWORK_IP_STACK_DEBUG_L2
help
Enables L2 output debug messages
config NETWORK_IP_STACK_DEBUG_UDP
bool "Debug UDP"
default n
help
Enables UDP debug messages
config NETWORK_IP_STACK_DEBUG_CONN
bool "Debug connection handling"
default n

View file

@ -121,6 +121,12 @@ config NET_MAX_ROUTERS
help
The value depends on your network needs.
config NET_UDP
bool "Enable UDP"
default y
help
The value depends on your network needs.
config NET_MAX_CONN
int "How many network connections are supported"
depends on NET_UDP || NET_TCP

View file

@ -114,7 +114,7 @@ static inline void stats(void)
GET_STAT(udp.sent),
GET_STAT(udp.drop));
PRINT("UDP chkerr %d",
GET_STAT(icmp.chkerr));
GET_STAT(udp.chkerr));
#endif
PRINT("Processing err %d", GET_STAT(processing_error));

90
net/yaip/udp.h Normal file
View file

@ -0,0 +1,90 @@
/** @file
@brief UDP data handler
This is not to be included by the application.
*/
/*
* Copyright (c) 2016 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __UDP_H
#define __UDP_H
#include <stdint.h>
#include <net/net_core.h>
#include <net/net_ip.h>
#include <net/nbuf.h>
#include "connection.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Register a callback to be called when UDP packet
* is received corresponding to received packet.
*
* @param remote_addr Remote address of the connection end point.
* @param local_addr Local address of the connection end point.
* @param remote_port Remote port of the connection end point.
* @param local_port Local port of the connection end point.
* @param cb Callback to be called
* @param user_data User data supplied by caller.
* @param handle UDP handle that can be used when unregistering
*
* @return Return 0 if the registration succeed, <0 otherwise.
*/
static inline int net_udp_register(const struct net_addr *remote_addr,
const struct net_addr *local_addr,
uint16_t remote_port,
uint16_t local_port,
net_conn_cb_t cb,
void *user_data,
void **handle)
{
return net_conn_register(IPPROTO_UDP, remote_addr, local_addr,
remote_port, local_port, cb, user_data,
handle);
}
/**
* @brief Unregister UDP handler.
*
* @param handle Handle from registering.
*
* @return Return 0 if the unregistration succeed, <0 otherwise.
*/
static inline int net_udp_unregister(void *handle)
{
return net_conn_unregister(handle);
}
#if defined(CONFIG_NET_UDP)
static inline void net_udp_init(void)
{
return;
}
#else
#define net_udp_init(...)
#endif
#ifdef __cplusplus
}
#endif
#endif /* __UDP_H */