net: yaip: Add network address information to interface
Change-Id: I14b9257362a1e6f4144900c7acde6a125ecf6a02 Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
parent
cba9d3096c
commit
d4e0025eb7
5 changed files with 356 additions and 114 deletions
|
@ -14,118 +14,10 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Public API for network interface
|
||||
*/
|
||||
|
||||
#ifndef __NET_IF_H__
|
||||
#define __NET_IF_H__
|
||||
|
||||
#include <device.h>
|
||||
|
||||
#include <net/net_linkaddr.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Network Interface structure
|
||||
*
|
||||
* Used to handle a network interface on top of a device driver instance.
|
||||
* There can be many net_if instance against the same device.
|
||||
*
|
||||
* Such interface is mainly to be used by the link layer, but is also tight
|
||||
* to a network context: it then makes the relation with a network context
|
||||
* and the network device.
|
||||
*
|
||||
* Because of the strong relationship between a device driver and such
|
||||
* network interface, each net_if should be instanciated by
|
||||
*/
|
||||
struct net_if {
|
||||
/** The actualy device driver instance the net_if is related to */
|
||||
struct device *dev;
|
||||
|
||||
/** The harware link address */
|
||||
struct net_linkaddr link_addr;
|
||||
|
||||
/** The hardware MTU */
|
||||
uint16_t mtu;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Get an network interface's device
|
||||
* @param iface Pointer to a network interface structure
|
||||
* @return a pointer on the device driver instance
|
||||
*/
|
||||
static inline struct device *net_if_get_device(struct net_if *iface)
|
||||
{
|
||||
return iface->dev;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get an network interface's link address
|
||||
* @param iface Pointer to a network interface structure
|
||||
* @return a pointer on the network link address
|
||||
*/
|
||||
static inline struct net_linkaddr *net_if_get_link_addr(struct net_if *iface)
|
||||
{
|
||||
return &iface->link_addr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set a network interfac's link address
|
||||
* @param iface Pointer to a network interface structure
|
||||
* @param addr a pointer on a uint8_t buffer representing the address
|
||||
* @param len length of the address buffer
|
||||
*/
|
||||
static inline void net_if_set_link_addr(struct net_if *iface,
|
||||
uint8_t *addr, uint8_t len)
|
||||
{
|
||||
iface->link_addr.addr = addr;
|
||||
iface->link_addr.len = len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get an network interface's MTU
|
||||
* @param iface Pointer to a network interface structure
|
||||
* @return the MTU
|
||||
*/
|
||||
static inline uint16_t net_if_get_mtu(struct net_if *iface)
|
||||
{
|
||||
return iface->mtu;
|
||||
}
|
||||
|
||||
struct net_if_api {
|
||||
void (*init)(struct net_if *iface);
|
||||
};
|
||||
|
||||
#ifdef CONFIG_NET_YAIP
|
||||
|
||||
#define NET_IF_INIT(dev_name, sfx, _mtu) \
|
||||
static struct net_if (__net_if_ ##dev_name _##sfx) __used \
|
||||
__attribute__((__section__(".net_if.data"))) = { \
|
||||
.dev = &(__device_##dev_name), \
|
||||
.mtu = _mtu, \
|
||||
}
|
||||
|
||||
#if defined(CONFIG_NET_UIP)
|
||||
#include <net/uip/net_if.h>
|
||||
#elif defined(CONFIG_NET_YAIP)
|
||||
#include <net/yaip/net_if.h>
|
||||
#else
|
||||
|
||||
#define NET_IF_INIT(...)
|
||||
|
||||
#endif /* CONFIG_NET_YAIP */
|
||||
|
||||
/* Network device intialization macro */
|
||||
|
||||
#define NET_DEVICE_INIT(dev_name, drv_name, init_fn, \
|
||||
data, cfg_info, prio, api, mtu) \
|
||||
DEVICE_AND_API_INIT(dev_name, drv_name, init_fn, data, \
|
||||
cfg_info, NANOKERNEL, prio, api); \
|
||||
NET_IF_INIT(dev_name, 0, mtu)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#error "Either uIP or YAIP needs to be selected."
|
||||
#endif
|
||||
|
||||
#endif /* __NET_IFACE_H__ */
|
||||
|
|
163
include/net/uip/net_if.h
Normal file
163
include/net/uip/net_if.h
Normal file
|
@ -0,0 +1,163 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Public API for network interface
|
||||
*/
|
||||
|
||||
#ifndef __NET_IF_H__
|
||||
#define __NET_IF_H__
|
||||
|
||||
#include <device.h>
|
||||
|
||||
#include <net/net_linkaddr.h>
|
||||
#include <net/net_ip.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Network Interface unicast IP addresses
|
||||
*
|
||||
* Stores the unicast IP addresses assigned to this network interface.
|
||||
*
|
||||
*/
|
||||
struct net_if_addr {
|
||||
/** Is this IP address used or not */
|
||||
bool is_used;
|
||||
|
||||
/** IP address */
|
||||
struct net_addr address;
|
||||
|
||||
/** How the IP address was set */
|
||||
enum net_addr_type addr_type;
|
||||
|
||||
/** What is the current state of the address */
|
||||
enum net_addr_state addr_state;
|
||||
|
||||
/** Is the IP address valid forever */
|
||||
bool is_infinite;
|
||||
|
||||
/** Timer that triggers renewal */
|
||||
struct nano_timer lifetime;
|
||||
|
||||
#if defined(CONFIG_NET_IPV6)
|
||||
/** Duplicate address detection (DAD) timer */
|
||||
struct nano_timer dad_timer;
|
||||
|
||||
/** How many times we have done DAD */
|
||||
uint8_t dad_count;
|
||||
#endif /* CONFIG_NET_IPV6 */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Network Interface structure
|
||||
*
|
||||
* Used to handle a network interface on top of a device driver instance.
|
||||
* There can be many net_if instance against the same device.
|
||||
*
|
||||
* Such interface is mainly to be used by the link layer, but is also tight
|
||||
* to a network context: it then makes the relation with a network context
|
||||
* and the network device.
|
||||
*
|
||||
* Because of the strong relationship between a device driver and such
|
||||
* network interface, each net_if should be instanciated by
|
||||
*/
|
||||
struct net_if {
|
||||
/** The actualy device driver instance the net_if is related to */
|
||||
struct device *dev;
|
||||
|
||||
/** The harware link address */
|
||||
struct net_linkaddr link_addr;
|
||||
|
||||
/** The hardware MTU */
|
||||
uint16_t mtu;
|
||||
|
||||
#if defined(CONFIG_NET_IPV6)
|
||||
#define NET_IF_MAX_IPV6_ADDR CONFIG_NET_IFACE_UNICAST_IPV6_ADDR_COUNT
|
||||
struct {
|
||||
/** Unicast IP addresses */
|
||||
struct net_if_addr unicast[NET_IF_MAX_IPV6_ADDR];
|
||||
} ipv6;
|
||||
|
||||
uint8_t hop_limit;
|
||||
#endif /* CONFIG_NET_IPV6 */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Get an network interface's device
|
||||
* @param iface Pointer to a network interface structure
|
||||
* @return a pointer on the device driver instance
|
||||
*/
|
||||
static inline struct device *net_if_get_device(struct net_if *iface)
|
||||
{
|
||||
return iface->dev;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get an network interface's link address
|
||||
* @param iface Pointer to a network interface structure
|
||||
* @return a pointer on the network link address
|
||||
*/
|
||||
static inline struct net_linkaddr *net_if_get_link_addr(struct net_if *iface)
|
||||
{
|
||||
return &iface->link_addr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set a network interfac's link address
|
||||
* @param iface Pointer to a network interface structure
|
||||
* @param addr a pointer on a uint8_t buffer representing the address
|
||||
* @param len length of the address buffer
|
||||
*/
|
||||
static inline void net_if_set_link_addr(struct net_if *iface,
|
||||
uint8_t *addr, uint8_t len)
|
||||
{
|
||||
iface->link_addr.addr = addr;
|
||||
iface->link_addr.len = len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get an network interface's MTU
|
||||
* @param iface Pointer to a network interface structure
|
||||
* @return the MTU
|
||||
*/
|
||||
static inline uint16_t net_if_get_mtu(struct net_if *iface)
|
||||
{
|
||||
return iface->mtu;
|
||||
}
|
||||
|
||||
struct net_if_api {
|
||||
void (*init)(struct net_if *iface);
|
||||
};
|
||||
|
||||
#define NET_IF_INIT(...)
|
||||
|
||||
/* Network device intialization macro */
|
||||
|
||||
#define NET_DEVICE_INIT(dev_name, drv_name, init_fn, \
|
||||
data, cfg_info, prio, api, mtu) \
|
||||
DEVICE_AND_API_INIT(dev_name, drv_name, init_fn, data, \
|
||||
cfg_info, NANOKERNEL, prio, api); \
|
||||
NET_IF_INIT(dev_name, 0, mtu)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __NET_IFACE_H__ */
|
168
include/net/yaip/net_if.h
Normal file
168
include/net/yaip/net_if.h
Normal file
|
@ -0,0 +1,168 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Public API for network interface
|
||||
*/
|
||||
|
||||
#ifndef __NET_IF_H__
|
||||
#define __NET_IF_H__
|
||||
|
||||
#include <device.h>
|
||||
|
||||
#include <net/net_linkaddr.h>
|
||||
#include <net/net_ip.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Network Interface unicast IP addresses
|
||||
*
|
||||
* Stores the unicast IP addresses assigned to this network interface.
|
||||
*
|
||||
*/
|
||||
struct net_if_addr {
|
||||
/** Is this IP address used or not */
|
||||
bool is_used;
|
||||
|
||||
/** IP address */
|
||||
struct net_addr address;
|
||||
|
||||
/** How the IP address was set */
|
||||
enum net_addr_type addr_type;
|
||||
|
||||
/** What is the current state of the address */
|
||||
enum net_addr_state addr_state;
|
||||
|
||||
/** Is the IP address valid forever */
|
||||
bool is_infinite;
|
||||
|
||||
/** Timer that triggers renewal */
|
||||
struct nano_timer lifetime;
|
||||
|
||||
#if defined(CONFIG_NET_IPV6)
|
||||
/** Duplicate address detection (DAD) timer */
|
||||
struct nano_timer dad_timer;
|
||||
|
||||
/** How many times we have done DAD */
|
||||
uint8_t dad_count;
|
||||
#endif /* CONFIG_NET_IPV6 */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Network Interface structure
|
||||
*
|
||||
* Used to handle a network interface on top of a device driver instance.
|
||||
* There can be many net_if instance against the same device.
|
||||
*
|
||||
* Such interface is mainly to be used by the link layer, but is also tight
|
||||
* to a network context: it then makes the relation with a network context
|
||||
* and the network device.
|
||||
*
|
||||
* Because of the strong relationship between a device driver and such
|
||||
* network interface, each net_if should be instanciated by
|
||||
*/
|
||||
struct net_if {
|
||||
/** The actualy device driver instance the net_if is related to */
|
||||
struct device *dev;
|
||||
|
||||
/** The hardware link address */
|
||||
struct net_linkaddr link_addr;
|
||||
|
||||
/** The hardware MTU */
|
||||
uint16_t mtu;
|
||||
|
||||
#if defined(CONFIG_NET_IPV6)
|
||||
#define NET_IF_MAX_IPV6_ADDR CONFIG_NET_IFACE_UNICAST_IPV6_ADDR_COUNT
|
||||
struct {
|
||||
/** Unicast IP addresses */
|
||||
struct net_if_addr unicast[NET_IF_MAX_IPV6_ADDR];
|
||||
} ipv6;
|
||||
|
||||
uint8_t hop_limit;
|
||||
#endif /* CONFIG_NET_IPV6 */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Get an network interface's device
|
||||
* @param iface Pointer to a network interface structure
|
||||
* @return a pointer on the device driver instance
|
||||
*/
|
||||
static inline struct device *net_if_get_device(struct net_if *iface)
|
||||
{
|
||||
return iface->dev;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get an network interface's link address
|
||||
* @param iface Pointer to a network interface structure
|
||||
* @return a pointer on the network link address
|
||||
*/
|
||||
static inline struct net_linkaddr *net_if_get_link_addr(struct net_if *iface)
|
||||
{
|
||||
return &iface->link_addr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set a network interfac's link address
|
||||
* @param iface Pointer to a network interface structure
|
||||
* @param addr a pointer on a uint8_t buffer representing the address
|
||||
* @param len length of the address buffer
|
||||
*/
|
||||
static inline void net_if_set_link_addr(struct net_if *iface,
|
||||
uint8_t *addr, uint8_t len)
|
||||
{
|
||||
iface->link_addr.addr = addr;
|
||||
iface->link_addr.len = len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get an network interface's MTU
|
||||
* @param iface Pointer to a network interface structure
|
||||
* @return the MTU
|
||||
*/
|
||||
static inline uint16_t net_if_get_mtu(struct net_if *iface)
|
||||
{
|
||||
return iface->mtu;
|
||||
}
|
||||
|
||||
struct net_if_api {
|
||||
void (*init)(struct net_if *iface);
|
||||
};
|
||||
|
||||
#define NET_IF_INIT(dev_name, sfx, _mtu) \
|
||||
static struct net_if (__net_if_ ##dev_name _##sfx) __used \
|
||||
__attribute__((__section__(".net_if.data"))) = { \
|
||||
.dev = &(__device_##dev_name), \
|
||||
.mtu = _mtu, \
|
||||
}
|
||||
|
||||
/* Network device intialization macro */
|
||||
|
||||
#define NET_DEVICE_INIT(dev_name, drv_name, init_fn, \
|
||||
data, cfg_info, prio, api, mtu) \
|
||||
DEVICE_AND_API_INIT(dev_name, drv_name, init_fn, data, \
|
||||
cfg_info, NANOKERNEL, prio, api); \
|
||||
NET_IF_INIT(dev_name, 0, mtu)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __NET_IFACE_H__ */
|
|
@ -111,6 +111,21 @@ struct net_tuple {
|
|||
enum ip_protocol ip_proto;
|
||||
};
|
||||
|
||||
/** How the network address is assigned to network interface */
|
||||
enum net_addr_type {
|
||||
NET_ADDR_ANY = 0,
|
||||
NET_ADDR_AUTOCONF,
|
||||
NET_ADDR_DHCP,
|
||||
NET_ADDR_MANUAL,
|
||||
};
|
||||
|
||||
/** What is the current state of the network address */
|
||||
enum net_addr_state {
|
||||
NET_ADDR_TENTATIVE = 0,
|
||||
NET_ADDR_PREFERRED,
|
||||
NET_ADDR_DEPRECATED,
|
||||
};
|
||||
|
||||
#define NET_UDPH_LEN 8 /* Size of UDP header */
|
||||
#define NET_TCPH_LEN 20 /* Size of TCP header */
|
||||
#define NET_ICMPH_LEN 4 /* Size of ICMP header */
|
||||
|
|
|
@ -18,4 +18,8 @@
|
|||
|
||||
config NET_YAIP_INIT_PRIO
|
||||
int
|
||||
default 99
|
||||
default 99
|
||||
|
||||
config NET_IFACE_UNICAST_IPV6_ADDR_COUNT
|
||||
int "Max number of unicast IPv6 addresses assigned to network interface"
|
||||
default 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue