net: if: Separate IP address configuration from net_if

Move IP address settings from net_if to separate structs.
This is needed for VLAN support.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
Jukka Rissanen 2018-01-11 16:06:53 +02:00 committed by Anas Nashif
parent bdc5c72498
commit 47dafffb67
38 changed files with 947 additions and 559 deletions

View file

@ -676,7 +676,7 @@ static int eth_net_tx(struct net_if *iface, struct net_pkt *pkt)
SYS_LOG_DBG("pkt %p (len %u)", pkt, len); SYS_LOG_DBG("pkt %p (len %u)", pkt, len);
ret = eth_enc28j60_tx(iface->dev, pkt, len); ret = eth_enc28j60_tx(net_if_get_device(iface), pkt, len);
if (ret == 0) { if (ret == 0) {
net_pkt_unref(pkt); net_pkt_unref(pkt);
} }

View file

@ -312,7 +312,7 @@ static void eth_mcux_delayed_phy_work(struct k_work *item)
static int eth_tx(struct net_if *iface, struct net_pkt *pkt) static int eth_tx(struct net_if *iface, struct net_pkt *pkt)
{ {
struct eth_context *context = iface->dev->driver_data; struct eth_context *context = net_if_get_device(iface)->driver_data;
const struct net_buf *frag; const struct net_buf *frag;
u8_t *dst; u8_t *dst;
status_t status; status_t status;

View file

@ -69,7 +69,8 @@ static bool received_dest_addr_matched(u8_t *rx_buffer)
if (memcmp(&rx_buffer[DEST_ADDR_OFFSET], if (memcmp(&rx_buffer[DEST_ADDR_OFFSET],
BROADCAST_ADDRESS, BROADCAST_ADDRESS,
SHORT_ADDRESS_SIZE) != 0 && SHORT_ADDRESS_SIZE) != 0 &&
(upipe->iface->link_addr.len != SHORT_ADDRESS_SIZE || (net_if_get_link_addr(upipe->iface)->len !=
SHORT_ADDRESS_SIZE ||
memcmp(&rx_buffer[DEST_ADDR_OFFSET], memcmp(&rx_buffer[DEST_ADDR_OFFSET],
dev_short_addr, dev_short_addr,
SHORT_ADDRESS_SIZE) != 0)) { SHORT_ADDRESS_SIZE) != 0)) {
@ -79,7 +80,8 @@ static bool received_dest_addr_matched(u8_t *rx_buffer)
case DEST_ADDR_TYPE_EXTENDED: case DEST_ADDR_TYPE_EXTENDED:
/* If not broadcast, check if lenght and address matches */ /* If not broadcast, check if lenght and address matches */
if (upipe->iface->link_addr.len != EXTENDED_ADDRESS_SIZE || if (net_if_get_link_addr(upipe->iface)->len !=
EXTENDED_ADDRESS_SIZE ||
memcmp(&rx_buffer[DEST_ADDR_OFFSET], memcmp(&rx_buffer[DEST_ADDR_OFFSET],
dev_ext_addr, EXTENDED_ADDRESS_SIZE) != 0) { dev_ext_addr, EXTENDED_ADDRESS_SIZE) != 0) {
return false; return false;

View file

@ -162,6 +162,14 @@
__net_if_end = .; __net_if_end = .;
} GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) } GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
SECTION_DATA_PROLOGUE(net_if_dev, (OPTIONAL), SUBALIGN(4))
{
__net_if_dev_start = .;
*(".net_if_dev.*")
KEEP(*(SORT_BY_NAME(".net_if_dev.*")))
__net_if_dev_end = .;
} GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
SECTION_DATA_PROLOGUE(net_if_event, (OPTIONAL), SUBALIGN(4)) SECTION_DATA_PROLOGUE(net_if_event, (OPTIONAL), SUBALIGN(4))
{ {
__net_if_event_start = .; __net_if_event_start = .;

View file

@ -168,21 +168,153 @@ enum {
struct net_offload; struct net_offload;
#endif /* CONFIG_NET_OFFLOAD */ #endif /* CONFIG_NET_OFFLOAD */
#if defined(CONFIG_NET_IPV6)
#define NET_IF_MAX_IPV6_ADDR CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT
#define NET_IF_MAX_IPV6_MADDR CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT
#define NET_IF_MAX_IPV6_PREFIX CONFIG_NET_IF_IPV6_PREFIX_COUNT
struct net_if_ipv6 {
/** Unicast IP addresses */
struct net_if_addr unicast[NET_IF_MAX_IPV6_ADDR];
/** Multicast IP addresses */
struct net_if_mcast_addr mcast[NET_IF_MAX_IPV6_MADDR];
/** Prefixes */
struct net_if_ipv6_prefix prefix[NET_IF_MAX_IPV6_PREFIX];
/** Router solicitation timer */
struct k_delayed_work rs_timer;
/** Default reachable time (RFC 4861, page 52) */
u32_t base_reachable_time;
/** Reachable time (RFC 4861, page 20) */
u32_t reachable_time;
/** Retransmit timer (RFC 4861, page 52) */
u32_t retrans_timer;
/** IPv6 hop limit */
u8_t hop_limit;
#if defined(CONFIG_NET_IPV6_DAD)
/** IPv6 current duplicate address detection count */
u8_t dad_count;
#endif /* CONFIG_NET_IPV6_DAD */
/** RS count */
u8_t rs_count;
};
#endif /* CONFIG_NET_IPV6 */
#if defined(CONFIG_NET_IPV4)
#define NET_IF_MAX_IPV4_ADDR CONFIG_NET_IF_UNICAST_IPV4_ADDR_COUNT
#define NET_IF_MAX_IPV4_MADDR CONFIG_NET_IF_MCAST_IPV4_ADDR_COUNT
struct net_if_ipv4 {
/** Unicast IP addresses */
struct net_if_addr unicast[NET_IF_MAX_IPV4_ADDR];
/** Multicast IP addresses */
struct net_if_mcast_addr mcast[NET_IF_MAX_IPV4_MADDR];
/** Gateway */
struct in_addr gw;
/** Netmask */
struct in_addr netmask;
/** IPv4 time-to-live */
u8_t ttl;
};
#endif /* CONFIG_NET_IPV4 */
#if defined(CONFIG_NET_DHCPV4)
struct net_if_dhcpv4 {
u32_t xid;
/** IP address Lease time */
u32_t lease_time;
/** IP address Renewal time */
u32_t renewal_time;
/** IP address Rebinding time */
u32_t rebinding_time;
/** Server ID */
struct in_addr server_id;
/** Requested IP addr */
struct in_addr requested_ip;
/** Timer for DHCPv4 Client requests (DISCOVER, REQUEST or RENEWAL)
*/
struct k_delayed_work timer;
/** T1 (Renewal) timer */
struct k_delayed_work t1_timer;
/** T2 (Rebinding) timer */
struct k_delayed_work t2_timer;
/**
* DHCPv4 client state in the process of network
* address allocation.
*/
enum net_dhcpv4_state state;
/** Number of attempts made for REQUEST and RENEWAL messages */
u8_t attempts;
};
#endif /* CONFIG_NET_DHCPV4 */
/* We always need to have at least one IP config */
#define NET_IF_MAX_CONFIGS 1
/** /**
* @brief Network Interface structure * @brief Network interface IP address configuration.
*
* TODO: Use pointers here so that we could have IPv6 only interface which
* would save memory by not having IPv4 enabled.
*/
struct net_if_ip {
#if defined(CONFIG_NET_IPV6)
struct net_if_ipv6 ipv6;
#endif /* CONFIG_NET_IPV6 */
#if defined(CONFIG_NET_IPV4)
struct net_if_ipv4 ipv4;
#endif /* CONFIG_NET_IPV4 */
};
/**
* @brief IP and other configuration related data for network interface.
*/
struct net_if_config {
/** IP address configuration setting */
struct net_if_ip ip;
#if defined(CONFIG_NET_DHCPV4)
struct net_if_dhcpv4 dhcpv4;
#endif /* CONFIG_NET_DHCPV4 */
};
/**
* @brief Network Interface Device structure
* *
* Used to handle a network interface on top of a device driver instance. * Used to handle a network interface on top of a device driver instance.
* There can be many net_if instance against the same device. * There can be many net_if_dev instance against the same device.
* *
* Such interface is mainly to be used by the link layer, but is also tight * 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 * to a network context: it then makes the relation with a network context
* and the network device. * and the network device.
* *
* Because of the strong relationship between a device driver and such * Because of the strong relationship between a device driver and such
* network interface, each net_if should be instantiated by * network interface, each net_if_dev should be instantiated by
*/ */
struct net_if { struct net_if_dev {
/** The actually device driver instance the net_if is related to */ /** The actually device driver instance the net_if is related to */
struct device *dev; struct device *dev;
@ -213,107 +345,22 @@ struct net_if {
struct net_offload *offload; struct net_offload *offload;
#endif /* CONFIG_NET_OFFLOAD */ #endif /* CONFIG_NET_OFFLOAD */
#if defined(CONFIG_NET_IPV6) };
#define NET_IF_MAX_IPV6_ADDR CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT
#define NET_IF_MAX_IPV6_MADDR CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT
#define NET_IF_MAX_IPV6_PREFIX CONFIG_NET_IF_IPV6_PREFIX_COUNT
struct {
/** Unicast IP addresses */
struct net_if_addr unicast[NET_IF_MAX_IPV6_ADDR];
/** Multicast IP addresses */ /**
struct net_if_mcast_addr mcast[NET_IF_MAX_IPV6_MADDR]; * @brief Network Interface structure
*
* Used to handle a network interface on top of a net_if_dev instance.
* There can be many net_if instance against the same net_if_dev instance.
*
*/
struct net_if {
/** The net_if_dev instance the net_if is related to */
struct net_if_dev *if_dev;
/** Prefixes */ /** Network interface instance configuration */
struct net_if_ipv6_prefix prefix[NET_IF_MAX_IPV6_PREFIX]; struct net_if_config config;
};
/** Router solicitation timer */
struct k_delayed_work rs_timer;
/** Default reachable time (RFC 4861, page 52) */
u32_t base_reachable_time;
/** Reachable time (RFC 4861, page 20) */
u32_t reachable_time;
/** Retransmit timer (RFC 4861, page 52) */
u32_t retrans_timer;
/** IPv6 hop limit */
u8_t hop_limit;
#if defined(CONFIG_NET_IPV6_DAD)
/** IPv6 current duplicate address detection count */
u8_t dad_count;
#endif /* CONFIG_NET_IPV6_DAD */
/** RS count */
u8_t rs_count;
} ipv6;
#endif /* CONFIG_NET_IPV6 */
#if defined(CONFIG_NET_IPV4)
#define NET_IF_MAX_IPV4_ADDR CONFIG_NET_IF_UNICAST_IPV4_ADDR_COUNT
#define NET_IF_MAX_IPV4_MADDR CONFIG_NET_IF_MCAST_IPV4_ADDR_COUNT
struct {
/** Unicast IP addresses */
struct net_if_addr unicast[NET_IF_MAX_IPV4_ADDR];
/** Multicast IP addresses */
struct net_if_mcast_addr mcast[NET_IF_MAX_IPV4_MADDR];
/** Gateway */
struct in_addr gw;
/** Netmask */
struct in_addr netmask;
/** IPv4 time-to-live */
u8_t ttl;
} ipv4;
#endif /* CONFIG_NET_IPV4 */
#if defined(CONFIG_NET_DHCPV4)
struct {
u32_t xid;
/** IP address Lease time */
u32_t lease_time;
/** IP address Renewal time */
u32_t renewal_time;
/** IP address Rebinding time */
u32_t rebinding_time;
/** Server ID */
struct in_addr server_id;
/** Requested IP addr */
struct in_addr requested_ip;
/** Timer for DHCPv4 Client requests (DISCOVER,
* REQUEST or RENEWAL)
*/
struct k_delayed_work timer;
/** T1 (Renewal) timer */
struct k_delayed_work t1_timer;
/** T2 (Rebinding) timer */
struct k_delayed_work t2_timer;
/**
* DHCPv4 client state in the process of network
* address allocation.
*/
enum net_dhcpv4_state state;
/** Number of attempts made for REQUEST and RENEWAL messages */
u8_t attempts;
} dhcpv4;
#endif
} __net_if_align;
/** /**
* @brief Send a packet through a net iface * @brief Send a packet through a net iface
@ -325,6 +372,18 @@ struct net_if {
*/ */
enum net_verdict net_if_send_data(struct net_if *iface, struct net_pkt *pkt); enum net_verdict net_if_send_data(struct net_if *iface, struct net_pkt *pkt);
/**
* @brief Get a pointer to the interface L2
*
* @param iface a valid pointer to a network interface structure
*
* @return a pointer to the iface L2
*/
static inline const struct net_l2 * const net_if_l2(struct net_if *iface)
{
return iface->if_dev->l2;
}
/** /**
* @brief Input a packet through a net iface * @brief Input a packet through a net iface
* *
@ -336,7 +395,7 @@ enum net_verdict net_if_send_data(struct net_if *iface, struct net_pkt *pkt);
static inline enum net_verdict net_if_recv_data(struct net_if *iface, static inline enum net_verdict net_if_recv_data(struct net_if *iface,
struct net_pkt *pkt) struct net_pkt *pkt)
{ {
return iface->l2->recv(iface, pkt); return net_if_l2(iface)->recv(iface, pkt);
} }
/** /**
@ -351,7 +410,7 @@ static inline enum net_verdict net_if_recv_data(struct net_if *iface,
static inline u16_t net_if_get_ll_reserve(struct net_if *iface, static inline u16_t net_if_get_ll_reserve(struct net_if *iface,
const struct in6_addr *dst_ip6) const struct in6_addr *dst_ip6)
{ {
return iface->l2->reserve(iface, (void *)dst_ip6); return net_if_l2(iface)->reserve(iface, (void *)dst_ip6);
} }
/** /**
@ -363,7 +422,7 @@ static inline u16_t net_if_get_ll_reserve(struct net_if *iface,
*/ */
static inline void *net_if_l2_data(struct net_if *iface) static inline void *net_if_l2_data(struct net_if *iface)
{ {
return iface->l2_data; return iface->if_dev->l2_data;
} }
/** /**
@ -375,7 +434,7 @@ static inline void *net_if_l2_data(struct net_if *iface)
*/ */
static inline struct device *net_if_get_device(struct net_if *iface) static inline struct device *net_if_get_device(struct net_if *iface)
{ {
return iface->dev; return iface->if_dev->dev;
} }
/** /**
@ -386,7 +445,17 @@ static inline struct device *net_if_get_device(struct net_if *iface)
*/ */
static inline void net_if_queue_tx(struct net_if *iface, struct net_pkt *pkt) static inline void net_if_queue_tx(struct net_if *iface, struct net_pkt *pkt)
{ {
k_fifo_put(&iface->tx_queue, pkt); k_fifo_put(&iface->if_dev->tx_queue, pkt);
}
/**
* @brief Get TX queue of an network interface
*
* @param iface Pointer to a network interface structure
*/
static inline struct k_fifo *net_if_get_queue_tx(struct net_if *iface)
{
return &iface->if_dev->tx_queue;
} }
#if defined(CONFIG_NET_OFFLOAD) #if defined(CONFIG_NET_OFFLOAD)
@ -399,7 +468,19 @@ static inline void net_if_queue_tx(struct net_if *iface, struct net_pkt *pkt)
*/ */
static inline bool net_if_is_ip_offloaded(struct net_if *iface) static inline bool net_if_is_ip_offloaded(struct net_if *iface)
{ {
return (iface->offload != NULL); return (iface->if_dev->offload != NULL);
}
/**
* @brief Return the IP offload plugin
*
* @param iface Network interface
*
* @return NULL if there is no offload plugin defined, valid pointer otherwise
*/
static inline struct net_offload *net_if_offload(struct net_if *iface)
{
return iface->if_dev->offload;
} }
#endif #endif
@ -412,7 +493,19 @@ static inline bool net_if_is_ip_offloaded(struct net_if *iface)
*/ */
static inline struct net_linkaddr *net_if_get_link_addr(struct net_if *iface) static inline struct net_linkaddr *net_if_get_link_addr(struct net_if *iface)
{ {
return &iface->link_addr; return &iface->if_dev->link_addr;
}
/**
* @brief Return network configuration for this network interface
*
* @param iface Pointer to a network interface structure
*
* @return Pointer to configuration
*/
static inline struct net_if_config *net_if_get_config(struct net_if *iface)
{
return &iface->config;
} }
/** /**
@ -447,13 +540,13 @@ static inline int net_if_set_link_addr(struct net_if *iface,
u8_t *addr, u8_t len, u8_t *addr, u8_t len,
enum net_link_type type) enum net_link_type type)
{ {
if (atomic_test_bit(iface->flags, NET_IF_UP)) { if (atomic_test_bit(iface->if_dev->flags, NET_IF_UP)) {
return -EPERM; return -EPERM;
} }
iface->link_addr.addr = addr; net_if_get_link_addr(iface)->addr = addr;
iface->link_addr.len = len; net_if_get_link_addr(iface)->len = len;
iface->link_addr.type = type; net_if_get_link_addr(iface)->type = type;
net_hostname_set_postfix(addr, len); net_hostname_set_postfix(addr, len);
@ -469,7 +562,7 @@ static inline int net_if_set_link_addr(struct net_if *iface,
*/ */
static inline u16_t net_if_get_mtu(struct net_if *iface) static inline u16_t net_if_get_mtu(struct net_if *iface)
{ {
return iface->mtu; return iface->if_dev->mtu;
} }
/** /**
@ -481,7 +574,7 @@ static inline u16_t net_if_get_mtu(struct net_if *iface)
static inline void net_if_set_mtu(struct net_if *iface, static inline void net_if_set_mtu(struct net_if *iface,
u16_t mtu) u16_t mtu)
{ {
iface->mtu = mtu; iface->if_dev->mtu = mtu;
} }
/** /**
@ -514,6 +607,18 @@ struct net_if *net_if_get_by_link_addr(struct net_linkaddr *ll_addr);
*/ */
struct net_if *net_if_lookup_by_dev(struct device *dev); struct net_if *net_if_lookup_by_dev(struct device *dev);
/**
* @brief Get network interface IP config
*
* @param iface Interface to use.
*
* @return NULL if not found or pointer to correct config settings.
*/
static inline struct net_if_config *net_if_config_get(struct net_if *iface)
{
return &iface->config;
}
/** /**
* @brief Remove a router from the system * @brief Remove a router from the system
* *
@ -583,15 +688,16 @@ struct net_if_addr *net_if_ipv6_addr_lookup_by_iface(struct net_if *iface,
int i; int i;
for (i = 0; i < NET_IF_MAX_IPV6_ADDR; i++) { for (i = 0; i < NET_IF_MAX_IPV6_ADDR; i++) {
if (!iface->ipv6.unicast[i].is_used || if (!iface->config.ip.ipv6.unicast[i].is_used ||
iface->ipv6.unicast[i].address.family != AF_INET6) { iface->config.ip.ipv6.unicast[i].address.family
!= AF_INET6) {
continue; continue;
} }
if (net_is_ipv6_prefix(addr->s6_addr, if (net_is_ipv6_prefix(addr->s6_addr,
iface->ipv6.unicast[i].address.in6_addr.s6_addr, iface->config.ip.ipv6.unicast[i].address.in6_addr.s6_addr,
128)) { 128)) {
return &iface->ipv6.unicast[i]; return &iface->config.ip.ipv6.unicast[i];
} }
} }
@ -913,7 +1019,11 @@ bool net_if_ipv6_router_rm(struct net_if_router *router);
*/ */
static inline u8_t net_if_ipv6_get_hop_limit(struct net_if *iface) static inline u8_t net_if_ipv6_get_hop_limit(struct net_if *iface)
{ {
return iface->ipv6.hop_limit; struct net_if_config *config;
config = net_if_config_get(iface);
return config->ip.ipv6.hop_limit;
} }
/** /**
@ -925,7 +1035,11 @@ static inline u8_t net_if_ipv6_get_hop_limit(struct net_if *iface)
static inline void net_ipv6_set_hop_limit(struct net_if *iface, static inline void net_ipv6_set_hop_limit(struct net_if *iface,
u8_t hop_limit) u8_t hop_limit)
{ {
iface->ipv6.hop_limit = hop_limit; struct net_if_config *config;
config = net_if_config_get(iface);
config->ip.ipv6.hop_limit = hop_limit;
} }
/** /**
@ -935,9 +1049,13 @@ static inline void net_ipv6_set_hop_limit(struct net_if *iface,
* @param reachable_time New reachable time * @param reachable_time New reachable time
*/ */
static inline void net_if_ipv6_set_base_reachable_time(struct net_if *iface, static inline void net_if_ipv6_set_base_reachable_time(struct net_if *iface,
u32_t reachable_time) u32_t reachable_time)
{ {
iface->ipv6.base_reachable_time = reachable_time; struct net_if_config *config;
config = net_if_config_get(iface);
config->ip.ipv6.base_reachable_time = reachable_time;
} }
/** /**
@ -949,7 +1067,11 @@ static inline void net_if_ipv6_set_base_reachable_time(struct net_if *iface,
*/ */
static inline u32_t net_if_ipv6_get_reachable_time(struct net_if *iface) static inline u32_t net_if_ipv6_get_reachable_time(struct net_if *iface)
{ {
return iface->ipv6.reachable_time; struct net_if_config *config;
config = net_if_config_get(iface);
return config->ip.ipv6.reachable_time;
} }
/** /**
@ -969,7 +1091,12 @@ u32_t net_if_ipv6_calc_reachable_time(struct net_if *iface);
*/ */
static inline void net_if_ipv6_set_reachable_time(struct net_if *iface) static inline void net_if_ipv6_set_reachable_time(struct net_if *iface)
{ {
iface->ipv6.reachable_time = net_if_ipv6_calc_reachable_time(iface); struct net_if_config *config;
config = net_if_config_get(iface);
config->ip.ipv6.reachable_time =
net_if_ipv6_calc_reachable_time(iface);
} }
/** /**
@ -981,7 +1108,11 @@ static inline void net_if_ipv6_set_reachable_time(struct net_if *iface)
static inline void net_if_ipv6_set_retrans_timer(struct net_if *iface, static inline void net_if_ipv6_set_retrans_timer(struct net_if *iface,
u32_t retrans_timer) u32_t retrans_timer)
{ {
iface->ipv6.retrans_timer = retrans_timer; struct net_if_config *config;
config = net_if_config_get(iface);
config->ip.ipv6.retrans_timer = retrans_timer;
} }
/** /**
@ -993,7 +1124,11 @@ static inline void net_if_ipv6_set_retrans_timer(struct net_if *iface,
*/ */
static inline u32_t net_if_ipv6_get_retrans_timer(struct net_if *iface) static inline u32_t net_if_ipv6_get_retrans_timer(struct net_if *iface)
{ {
return iface->ipv6.retrans_timer; struct net_if_config *config;
config = net_if_config_get(iface);
return config->ip.ipv6.retrans_timer;
} }
/** /**
@ -1068,7 +1203,11 @@ struct in6_addr *net_if_ipv6_get_global_addr(struct net_if **iface);
*/ */
static inline u8_t net_if_ipv4_get_ttl(struct net_if *iface) static inline u8_t net_if_ipv4_get_ttl(struct net_if *iface)
{ {
return iface->ipv4.ttl; struct net_if_config *config;
config = net_if_config_get(iface);
return config->ip.ipv4.ttl;
} }
/** /**
@ -1188,7 +1327,11 @@ bool net_if_ipv4_addr_mask_cmp(struct net_if *iface,
static inline void net_if_ipv4_set_netmask(struct net_if *iface, static inline void net_if_ipv4_set_netmask(struct net_if *iface,
struct in_addr *netmask) struct in_addr *netmask)
{ {
net_ipaddr_copy(&iface->ipv4.netmask, netmask); struct net_if_config *config;
config = net_if_config_get(iface);
net_ipaddr_copy(&config->ip.ipv4.netmask, netmask);
} }
/** /**
@ -1200,7 +1343,11 @@ static inline void net_if_ipv4_set_netmask(struct net_if *iface,
static inline void net_if_ipv4_set_gw(struct net_if *iface, static inline void net_if_ipv4_set_gw(struct net_if *iface,
struct in_addr *gw) struct in_addr *gw)
{ {
net_ipaddr_copy(&iface->ipv4.gw, gw); struct net_if_config *config;
config = net_if_config_get(iface);
net_ipaddr_copy(&config->ip.ipv4.gw, gw);
} }
#endif /* CONFIG_NET_IPV4 */ #endif /* CONFIG_NET_IPV4 */
@ -1340,7 +1487,7 @@ static inline bool net_if_is_up(struct net_if *iface)
{ {
NET_ASSERT(iface); NET_ASSERT(iface);
return atomic_test_bit(iface->flags, NET_IF_UP); return atomic_test_bit(iface->if_dev->flags, NET_IF_UP);
} }
/** /**
@ -1363,7 +1510,15 @@ struct net_if_api {
#define NET_IF_DHCPV4_INIT #define NET_IF_DHCPV4_INIT
#endif #endif
#define NET_IF_CONFIG_INIT \
.config = { \
.ip = { \
}, \
NET_IF_DHCPV4_INIT \
}
#define NET_IF_GET_NAME(dev_name, sfx) (__net_if_##dev_name##_##sfx) #define NET_IF_GET_NAME(dev_name, sfx) (__net_if_##dev_name##_##sfx)
#define NET_IF_DEV_GET_NAME(dev_name, sfx) (__net_if_dev_##dev_name##_##sfx)
#define NET_IF_EVENT_GET_NAME(dev_name, sfx) \ #define NET_IF_EVENT_GET_NAME(dev_name, sfx) \
(__net_if_event_##dev_name##_##sfx) (__net_if_event_##dev_name##_##sfx)
@ -1371,13 +1526,20 @@ struct net_if_api {
((struct net_if *)&NET_IF_GET_NAME(dev_name, sfx)) ((struct net_if *)&NET_IF_GET_NAME(dev_name, sfx))
#define NET_IF_INIT(dev_name, sfx, _l2, _mtu) \ #define NET_IF_INIT(dev_name, sfx, _l2, _mtu) \
static struct net_if (NET_IF_GET_NAME(dev_name, sfx)) __used \ static struct net_if_dev (NET_IF_DEV_GET_NAME(dev_name, sfx)) __used \
__attribute__((__section__(".net_if.data"))) = { \ __attribute__((__section__(".net_if_dev.data"))) = { \
.dev = &(__device_##dev_name), \ .dev = &(__device_##dev_name), \
.l2 = &(NET_L2_GET_NAME(_l2)), \ .l2 = &(NET_L2_GET_NAME(_l2)), \
.l2_data = &(NET_L2_GET_DATA(dev_name, sfx)), \ .l2_data = &(NET_L2_GET_DATA(dev_name, sfx)), \
.mtu = _mtu, \ .mtu = _mtu, \
NET_IF_DHCPV4_INIT \ }; \
static struct net_if \
(NET_IF_GET_NAME(dev_name, sfx))[NET_IF_MAX_CONFIGS] __used \
__attribute__((__section__(".net_if.data"))) = { \
[0 ... (NET_IF_MAX_CONFIGS - 1)] = { \
.if_dev = &(NET_IF_DEV_GET_NAME(dev_name, sfx)), \
NET_IF_CONFIG_INIT \
} \
}; \ }; \
static struct k_poll_event \ static struct k_poll_event \
(NET_IF_EVENT_GET_NAME(dev_name, sfx)) __used \ (NET_IF_EVENT_GET_NAME(dev_name, sfx)) __used \

View file

@ -349,6 +349,7 @@ static inline bool net_is_ipv6_addr_mcast(const struct in6_addr *addr)
} }
struct net_if; struct net_if;
struct net_if_config;
extern struct net_if_addr *net_if_ipv6_addr_lookup(const struct in6_addr *addr, extern struct net_if_addr *net_if_ipv6_addr_lookup(const struct in6_addr *addr,
struct net_if **iface); struct net_if **iface);

View file

@ -133,10 +133,10 @@ static inline int net_offload_get(struct net_if *iface,
struct net_context **context) struct net_context **context)
{ {
NET_ASSERT(iface); NET_ASSERT(iface);
NET_ASSERT(iface->offload); NET_ASSERT(net_if_offload(iface));
NET_ASSERT(iface->offload->get); NET_ASSERT(net_if_offload(iface)->get);
return iface->offload->get(family, type, ip_proto, context); return net_if_offload(iface)->get(family, type, ip_proto, context);
} }
/** /**
@ -158,10 +158,10 @@ static inline int net_offload_bind(struct net_if *iface,
socklen_t addrlen) socklen_t addrlen)
{ {
NET_ASSERT(iface); NET_ASSERT(iface);
NET_ASSERT(iface->offload); NET_ASSERT(net_if_offload(iface));
NET_ASSERT(iface->offload->bind); NET_ASSERT(net_if_offload(iface)->bind);
return iface->offload->bind(context, addr, addrlen); return net_if_offload(iface)->bind(context, addr, addrlen);
} }
/** /**
@ -181,10 +181,10 @@ static inline int net_offload_listen(struct net_if *iface,
int backlog) int backlog)
{ {
NET_ASSERT(iface); NET_ASSERT(iface);
NET_ASSERT(iface->offload); NET_ASSERT(net_if_offload(iface));
NET_ASSERT(iface->offload->listen); NET_ASSERT(net_if_offload(iface)->listen);
return iface->offload->listen(context, backlog); return net_if_offload(iface)->listen(context, backlog);
} }
/** /**
@ -225,10 +225,10 @@ static inline int net_offload_connect(struct net_if *iface,
void *user_data) void *user_data)
{ {
NET_ASSERT(iface); NET_ASSERT(iface);
NET_ASSERT(iface->offload); NET_ASSERT(net_if_offload(iface));
NET_ASSERT(iface->offload->connect); NET_ASSERT(net_if_offload(iface)->connect);
return iface->offload->connect(context, addr, addrlen, cb, return net_if_offload(iface)->connect(context, addr, addrlen, cb,
timeout, user_data); timeout, user_data);
} }
@ -266,10 +266,10 @@ static inline int net_offload_accept(struct net_if *iface,
void *user_data) void *user_data)
{ {
NET_ASSERT(iface); NET_ASSERT(iface);
NET_ASSERT(iface->offload); NET_ASSERT(net_if_offload(iface));
NET_ASSERT(iface->offload->accept); NET_ASSERT(net_if_offload(iface)->accept);
return iface->offload->accept(context, cb, timeout, user_data); return net_if_offload(iface)->accept(context, cb, timeout, user_data);
} }
/** /**
@ -307,10 +307,10 @@ static inline int net_offload_send(struct net_if *iface,
void *user_data) void *user_data)
{ {
NET_ASSERT(iface); NET_ASSERT(iface);
NET_ASSERT(iface->offload); NET_ASSERT(net_if_offload(iface));
NET_ASSERT(iface->offload->send); NET_ASSERT(net_if_offload(iface)->send);
return iface->offload->send(pkt, cb, timeout, token, user_data); return net_if_offload(iface)->send(pkt, cb, timeout, token, user_data);
} }
/** /**
@ -352,10 +352,10 @@ static inline int net_offload_sendto(struct net_if *iface,
void *user_data) void *user_data)
{ {
NET_ASSERT(iface); NET_ASSERT(iface);
NET_ASSERT(iface->offload); NET_ASSERT(net_if_offload(iface));
NET_ASSERT(iface->offload->sendto); NET_ASSERT(net_if_offload(iface)->sendto);
return iface->offload->sendto(pkt, dst_addr, addrlen, cb, return net_if_offload(iface)->sendto(pkt, dst_addr, addrlen, cb,
timeout, token, user_data); timeout, token, user_data);
} }
@ -399,10 +399,10 @@ static inline int net_offload_recv(struct net_if *iface,
void *user_data) void *user_data)
{ {
NET_ASSERT(iface); NET_ASSERT(iface);
NET_ASSERT(iface->offload); NET_ASSERT(net_if_offload(iface));
NET_ASSERT(iface->offload->recv); NET_ASSERT(net_if_offload(iface)->recv);
return iface->offload->recv(context, cb, timeout, user_data); return net_if_offload(iface)->recv(context, cb, timeout, user_data);
} }
/** /**
@ -422,10 +422,10 @@ static inline int net_offload_put(struct net_if *iface,
struct net_context *context) struct net_context *context)
{ {
NET_ASSERT(iface); NET_ASSERT(iface);
NET_ASSERT(iface->offload); NET_ASSERT(net_if_offload(iface));
NET_ASSERT(iface->offload->put); NET_ASSERT(net_if_offload(iface)->put);
return iface->offload->put(context); return net_if_offload(iface)->put(context);
} }
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -181,8 +181,8 @@ static inline void net_pkt_set_iface(struct net_pkt *pkt, struct net_if *iface)
* the network address that is stored in pkt. This is done here so * the network address that is stored in pkt. This is done here so
* that the address type is properly set and is not forgotten. * that the address type is properly set and is not forgotten.
*/ */
pkt->lladdr_src.type = iface->link_addr.type; pkt->lladdr_src.type = net_if_get_link_addr(iface)->type;
pkt->lladdr_dst.type = iface->link_addr.type; pkt->lladdr_dst.type = net_if_get_link_addr(iface)->type;
} }
static inline struct net_if *net_pkt_orig_iface(struct net_pkt *pkt) static inline struct net_if *net_pkt_orig_iface(struct net_pkt *pkt)

View file

@ -283,7 +283,7 @@ void main(void)
#if defined(CONFIG_NET_MGMT_EVENT) #if defined(CONFIG_NET_MGMT_EVENT)
/* Subscribe to NET_IF_UP if interface is not ready */ /* Subscribe to NET_IF_UP if interface is not ready */
if (!atomic_test_bit(iface->flags, NET_IF_UP)) { if (!atomic_test_bit(iface->if_dev->flags, NET_IF_UP)) {
net_mgmt_init_event_callback(&cb, event_iface_up, net_mgmt_init_event_callback(&cb, event_iface_up,
NET_EVENT_IF_UP); NET_EVENT_IF_UP);
net_mgmt_add_event_callback(&cb); net_mgmt_add_event_callback(&cb);

View file

@ -38,20 +38,22 @@ static void handler(struct net_mgmt_event_callback *cb,
for (i = 0; i < NET_IF_MAX_IPV4_ADDR; i++) { for (i = 0; i < NET_IF_MAX_IPV4_ADDR; i++) {
char buf[NET_IPV4_ADDR_LEN]; char buf[NET_IPV4_ADDR_LEN];
if (iface->ipv4.unicast[i].addr_type != NET_ADDR_DHCP) { if (iface->config.ip.ipv4.unicast[i].addr_type !=
NET_ADDR_DHCP) {
continue; continue;
} }
NET_INFO("Your address: %s", NET_INFO("Your address: %s",
net_addr_ntop(AF_INET, net_addr_ntop(AF_INET,
&iface->ipv4.unicast[i].address.in_addr, &iface->config.ip.ipv4.unicast[i].address.in_addr,
buf, sizeof(buf))); buf, sizeof(buf)));
NET_INFO("Lease time: %u seconds", iface->dhcpv4.lease_time); NET_INFO("Lease time: %u seconds",
iface->config.dhcpv4.lease_time);
NET_INFO("Subnet: %s", NET_INFO("Subnet: %s",
net_addr_ntop(AF_INET, &iface->ipv4.netmask, net_addr_ntop(AF_INET, &iface->config.ip.ipv4.netmask,
buf, sizeof(buf))); buf, sizeof(buf)));
NET_INFO("Router: %s", NET_INFO("Router: %s",
net_addr_ntop(AF_INET, &iface->ipv4.gw, net_addr_ntop(AF_INET, &iface->config.ip.ipv4.gw,
buf, sizeof(buf))); buf, sizeof(buf)));
} }
} }

View file

@ -580,7 +580,8 @@ class SizeCalculator:
"_k_sem_area", "_k_mutex_area", "_k_alert_area", "_k_sem_area", "_k_mutex_area", "_k_alert_area",
"_k_fifo_area", "_k_lifo_area", "_k_stack_area", "_k_fifo_area", "_k_lifo_area", "_k_stack_area",
"_k_msgq_area", "_k_mbox_area", "_k_pipe_area", "_k_msgq_area", "_k_mbox_area", "_k_pipe_area",
"net_if", "net_if_event", "net_stack", "net_l2_data", "net_if", "net_if_dev", "net_if_event", "net_stack",
"net_l2_data",
"_k_queue_area", "_net_buf_pool_area", "app_datas", "_k_queue_area", "_net_buf_pool_area", "app_datas",
"kobject_data", "mmu_tables", "app_pad", "priv_stacks", "kobject_data", "mmu_tables", "app_pad", "priv_stacks",
"ccm_data"] "ccm_data"]

View file

@ -324,7 +324,7 @@ static struct net_pkt *prepare_message(struct net_if *iface, u8_t type,
msg->htype = HARDWARE_ETHERNET_TYPE; msg->htype = HARDWARE_ETHERNET_TYPE;
msg->hlen = HARDWARE_ETHERNET_LEN; msg->hlen = HARDWARE_ETHERNET_LEN;
msg->xid = htonl(iface->dhcpv4.xid); msg->xid = htonl(iface->config.dhcpv4.xid);
msg->flags = htons(DHCPV4_MSG_BROADCAST); msg->flags = htons(DHCPV4_MSG_BROADCAST);
if (ciaddr) { if (ciaddr) {
@ -335,7 +335,8 @@ static struct net_pkt *prepare_message(struct net_if *iface, u8_t type,
memcpy(msg->ciaddr, ciaddr, 4); memcpy(msg->ciaddr, ciaddr, 4);
} }
memcpy(msg->chaddr, iface->link_addr.addr, iface->link_addr.len); memcpy(msg->chaddr, net_if_get_link_addr(iface)->addr,
net_if_get_link_addr(iface)->len);
net_buf_add(frag, sizeof(struct dhcp_msg)); net_buf_add(frag, sizeof(struct dhcp_msg));
@ -363,16 +364,16 @@ static void send_request(struct net_if *iface)
bool with_server_id = false; bool with_server_id = false;
bool with_requested_ip = false; bool with_requested_ip = false;
iface->dhcpv4.xid++; iface->config.dhcpv4.xid++;
switch (iface->dhcpv4.state) { switch (iface->config.dhcpv4.state) {
case NET_DHCPV4_DISABLED: case NET_DHCPV4_DISABLED:
case NET_DHCPV4_INIT: case NET_DHCPV4_INIT:
case NET_DHCPV4_SELECTING: case NET_DHCPV4_SELECTING:
case NET_DHCPV4_BOUND: case NET_DHCPV4_BOUND:
/* Not possible */ /* Not possible */
NET_ASSERT_INFO(0, "Invalid state %s", NET_ASSERT_INFO(0, "Invalid state %s",
net_dhcpv4_state_name(iface->dhcpv4.state)); net_dhcpv4_state_name(iface->config.dhcpv4.state));
break; break;
case NET_DHCPV4_REQUESTING: case NET_DHCPV4_REQUESTING:
with_server_id = true; with_server_id = true;
@ -381,10 +382,10 @@ static void send_request(struct net_if *iface)
case NET_DHCPV4_RENEWING: case NET_DHCPV4_RENEWING:
/* Since we have an address populate the ciaddr field. /* Since we have an address populate the ciaddr field.
*/ */
ciaddr = &iface->dhcpv4.requested_ip; ciaddr = &iface->config.dhcpv4.requested_ip;
/* UNICAST the DHCPREQUEST */ /* UNICAST the DHCPREQUEST */
server_addr = &iface->dhcpv4.server_id; server_addr = &iface->config.dhcpv4.server_id;
/* RFC2131 4.4.5 Client MUST NOT include server /* RFC2131 4.4.5 Client MUST NOT include server
* identifier in the DHCPREQUEST. * identifier in the DHCPREQUEST.
@ -393,7 +394,7 @@ static void send_request(struct net_if *iface)
case NET_DHCPV4_REBINDING: case NET_DHCPV4_REBINDING:
/* Since we have an address populate the ciaddr field. /* Since we have an address populate the ciaddr field.
*/ */
ciaddr = &iface->dhcpv4.requested_ip; ciaddr = &iface->config.dhcpv4.requested_ip;
server_addr = net_ipv4_broadcast_address(); server_addr = net_ipv4_broadcast_address();
break; break;
@ -404,12 +405,13 @@ static void send_request(struct net_if *iface)
goto fail; goto fail;
} }
if (with_server_id && !add_server_id(pkt, &iface->dhcpv4.server_id)) { if (with_server_id &&
!add_server_id(pkt, &iface->config.dhcpv4.server_id)) {
goto fail; goto fail;
} }
if (with_requested_ip if (with_requested_ip
&& !add_req_ipaddr(pkt, &iface->dhcpv4.requested_ip)) { && !add_req_ipaddr(pkt, &iface->config.dhcpv4.requested_ip)) {
goto fail; goto fail;
} }
@ -425,11 +427,13 @@ static void send_request(struct net_if *iface)
goto fail; goto fail;
} }
timeout = DHCPV4_INITIAL_RETRY_TIMEOUT << iface->dhcpv4.attempts; timeout = DHCPV4_INITIAL_RETRY_TIMEOUT <<
iface->config.dhcpv4.attempts;
k_delayed_work_submit(&iface->dhcpv4.timer, timeout * MSEC_PER_SEC); k_delayed_work_submit(&iface->config.dhcpv4.timer,
timeout * MSEC_PER_SEC);
iface->dhcpv4.attempts++; iface->config.dhcpv4.attempts++;
const char *ciaddr_buf = 0; const char *ciaddr_buf = 0;
static char pbuf[NET_IPV4_ADDR_LEN]; static char pbuf[NET_IPV4_ADDR_LEN];
@ -443,7 +447,7 @@ static void send_request(struct net_if *iface)
NET_DBG("send request dst=%s xid=0x%"PRIx32" ciaddr=%s" NET_DBG("send request dst=%s xid=0x%"PRIx32" ciaddr=%s"
"%s%s timeout=%"PRIu32"s", "%s%s timeout=%"PRIu32"s",
net_sprint_ipv4_addr(server_addr), net_sprint_ipv4_addr(server_addr),
iface->dhcpv4.xid, iface->config.dhcpv4.xid,
ciaddr_buf, ciaddr_buf,
with_server_id ? " +server-id" : "", with_server_id ? " +server-id" : "",
with_requested_ip ? " +requested-ip" : "", with_requested_ip ? " +requested-ip" : "",
@ -465,7 +469,7 @@ static void send_discover(struct net_if *iface)
struct net_pkt *pkt; struct net_pkt *pkt;
u32_t timeout; u32_t timeout;
iface->dhcpv4.xid++; iface->config.dhcpv4.xid++;
pkt = prepare_message(iface, DHCPV4_MSG_TYPE_DISCOVER, NULL); pkt = prepare_message(iface, DHCPV4_MSG_TYPE_DISCOVER, NULL);
if (!pkt) { if (!pkt) {
@ -485,14 +489,15 @@ static void send_discover(struct net_if *iface)
goto fail; goto fail;
} }
timeout = DHCPV4_INITIAL_RETRY_TIMEOUT << iface->dhcpv4.attempts; timeout = DHCPV4_INITIAL_RETRY_TIMEOUT << iface->config.dhcpv4.attempts;
k_delayed_work_submit(&iface->dhcpv4.timer, timeout * MSEC_PER_SEC); k_delayed_work_submit(&iface->config.dhcpv4.timer,
timeout * MSEC_PER_SEC);
iface->dhcpv4.attempts++; iface->config.dhcpv4.attempts++;
NET_DBG("send discover xid=0x%"PRIx32" timeout=%"PRIu32"s", NET_DBG("send discover xid=0x%"PRIx32" timeout=%"PRIu32"s",
iface->dhcpv4.xid, timeout); iface->config.dhcpv4.xid, timeout);
return; return;
@ -506,25 +511,25 @@ fail:
static void enter_selecting(struct net_if *iface) static void enter_selecting(struct net_if *iface)
{ {
iface->dhcpv4.attempts = 0; iface->config.dhcpv4.attempts = 0;
iface->dhcpv4.lease_time = 0; iface->config.dhcpv4.lease_time = 0;
iface->dhcpv4.renewal_time = 0; iface->config.dhcpv4.renewal_time = 0;
iface->dhcpv4.rebinding_time = 0; iface->config.dhcpv4.rebinding_time = 0;
iface->dhcpv4.state = NET_DHCPV4_SELECTING; iface->config.dhcpv4.state = NET_DHCPV4_SELECTING;
NET_DBG("enter state=%s", NET_DBG("enter state=%s",
net_dhcpv4_state_name(iface->dhcpv4.state)); net_dhcpv4_state_name(iface->config.dhcpv4.state));
send_discover(iface); send_discover(iface);
} }
static void enter_requesting(struct net_if *iface) static void enter_requesting(struct net_if *iface)
{ {
iface->dhcpv4.attempts = 0; iface->config.dhcpv4.attempts = 0;
iface->dhcpv4.state = NET_DHCPV4_REQUESTING; iface->config.dhcpv4.state = NET_DHCPV4_REQUESTING;
NET_DBG("enter state=%s", NET_DBG("enter state=%s",
net_dhcpv4_state_name(iface->dhcpv4.state)); net_dhcpv4_state_name(iface->config.dhcpv4.state));
send_request(iface); send_request(iface);
} }
@ -532,11 +537,11 @@ static void enter_requesting(struct net_if *iface)
static void dhcpv4_t1_timeout(struct k_work *work) static void dhcpv4_t1_timeout(struct k_work *work)
{ {
struct net_if *iface = CONTAINER_OF(work, struct net_if, struct net_if *iface = CONTAINER_OF(work, struct net_if,
dhcpv4.t1_timer); config.dhcpv4.t1_timer);
NET_DBG(""); NET_DBG("");
switch (iface->dhcpv4.state) { switch (iface->config.dhcpv4.state) {
case NET_DHCPV4_DISABLED: case NET_DHCPV4_DISABLED:
case NET_DHCPV4_INIT: case NET_DHCPV4_INIT:
case NET_DHCPV4_SELECTING: case NET_DHCPV4_SELECTING:
@ -545,13 +550,13 @@ static void dhcpv4_t1_timeout(struct k_work *work)
case NET_DHCPV4_REBINDING: case NET_DHCPV4_REBINDING:
/* This path cannot happen. */ /* This path cannot happen. */
NET_ASSERT_INFO(0, "Invalid state %s", NET_ASSERT_INFO(0, "Invalid state %s",
net_dhcpv4_state_name(iface->dhcpv4.state)); net_dhcpv4_state_name(iface->config.dhcpv4.state));
break; break;
case NET_DHCPV4_BOUND: case NET_DHCPV4_BOUND:
iface->dhcpv4.state = NET_DHCPV4_RENEWING; iface->config.dhcpv4.state = NET_DHCPV4_RENEWING;
NET_DBG("enter state=%s", NET_DBG("enter state=%s",
net_dhcpv4_state_name(iface->dhcpv4.state)); net_dhcpv4_state_name(iface->config.dhcpv4.state));
iface->dhcpv4.attempts = 0; iface->config.dhcpv4.attempts = 0;
send_request(iface); send_request(iface);
break; break;
} }
@ -560,18 +565,18 @@ static void dhcpv4_t1_timeout(struct k_work *work)
static void dhcpv4_t2_timeout(struct k_work *work) static void dhcpv4_t2_timeout(struct k_work *work)
{ {
struct net_if *iface = CONTAINER_OF(work, struct net_if, struct net_if *iface = CONTAINER_OF(work, struct net_if,
dhcpv4.t2_timer); config.dhcpv4.t2_timer);
NET_DBG(""); NET_DBG("");
switch (iface->dhcpv4.state) { switch (iface->config.dhcpv4.state) {
case NET_DHCPV4_DISABLED: case NET_DHCPV4_DISABLED:
case NET_DHCPV4_INIT: case NET_DHCPV4_INIT:
case NET_DHCPV4_SELECTING: case NET_DHCPV4_SELECTING:
case NET_DHCPV4_REQUESTING: case NET_DHCPV4_REQUESTING:
case NET_DHCPV4_REBINDING: case NET_DHCPV4_REBINDING:
NET_ASSERT_INFO(0, "Invalid state %s", NET_ASSERT_INFO(0, "Invalid state %s",
net_dhcpv4_state_name(iface->dhcpv4.state)); net_dhcpv4_state_name(iface->config.dhcpv4.state));
break; break;
case NET_DHCPV4_BOUND: case NET_DHCPV4_BOUND:
/* If renewal time and rebinding time are /* If renewal time and rebinding time are
@ -580,10 +585,10 @@ static void dhcpv4_t2_timeout(struct k_work *work)
* through RENEWAL already. * through RENEWAL already.
*/ */
case NET_DHCPV4_RENEWING: case NET_DHCPV4_RENEWING:
iface->dhcpv4.state = NET_DHCPV4_REBINDING; iface->config.dhcpv4.state = NET_DHCPV4_REBINDING;
NET_DBG("enter state=%s", NET_DBG("enter state=%s",
net_dhcpv4_state_name(iface->dhcpv4.state)); net_dhcpv4_state_name(iface->config.dhcpv4.state));
iface->dhcpv4.attempts = 0; iface->config.dhcpv4.attempts = 0;
send_request(iface); send_request(iface);
break; break;
} }
@ -594,43 +599,43 @@ static void enter_bound(struct net_if *iface)
u32_t renewal_time; u32_t renewal_time;
u32_t rebinding_time; u32_t rebinding_time;
k_delayed_work_cancel(&iface->dhcpv4.timer); k_delayed_work_cancel(&iface->config.dhcpv4.timer);
renewal_time = iface->dhcpv4.renewal_time; renewal_time = iface->config.dhcpv4.renewal_time;
if (!renewal_time) { if (!renewal_time) {
/* The default renewal time rfc2131 4.4.5 */ /* The default renewal time rfc2131 4.4.5 */
renewal_time = iface->dhcpv4.lease_time / 2; renewal_time = iface->config.dhcpv4.lease_time / 2;
} }
rebinding_time = iface->dhcpv4.rebinding_time; rebinding_time = iface->config.dhcpv4.rebinding_time;
if (!rebinding_time) { if (!rebinding_time) {
/* The default rebinding time rfc2131 4.4.5 */ /* The default rebinding time rfc2131 4.4.5 */
rebinding_time = iface->dhcpv4.lease_time * 875 / 1000; rebinding_time = iface->config.dhcpv4.lease_time * 875 / 1000;
} }
iface->dhcpv4.state = NET_DHCPV4_BOUND; iface->config.dhcpv4.state = NET_DHCPV4_BOUND;
NET_DBG("enter state=%s renewal=%"PRIu32"s " NET_DBG("enter state=%s renewal=%"PRIu32"s "
"rebinding=%"PRIu32"s", "rebinding=%"PRIu32"s",
net_dhcpv4_state_name(iface->dhcpv4.state), net_dhcpv4_state_name(iface->config.dhcpv4.state),
renewal_time, rebinding_time); renewal_time, rebinding_time);
/* Start renewal time */ /* Start renewal time */
k_delayed_work_submit(&iface->dhcpv4.t1_timer, k_delayed_work_submit(&iface->config.dhcpv4.t1_timer,
renewal_time * MSEC_PER_SEC); renewal_time * MSEC_PER_SEC);
/* Start rebinding time */ /* Start rebinding time */
k_delayed_work_submit(&iface->dhcpv4.t2_timer, k_delayed_work_submit(&iface->config.dhcpv4.t2_timer,
rebinding_time * MSEC_PER_SEC); rebinding_time * MSEC_PER_SEC);
} }
static void dhcpv4_timeout(struct k_work *work) static void dhcpv4_timeout(struct k_work *work)
{ {
struct net_if *iface = CONTAINER_OF(work, struct net_if, struct net_if *iface = CONTAINER_OF(work, struct net_if,
dhcpv4.timer); config.dhcpv4.timer);
NET_DBG("state=%s", net_dhcpv4_state_name(iface->dhcpv4.state)); NET_DBG("state=%s", net_dhcpv4_state_name(iface->config.dhcpv4.state));
switch (iface->dhcpv4.state) { switch (iface->config.dhcpv4.state) {
case NET_DHCPV4_DISABLED: case NET_DHCPV4_DISABLED:
break; break;
case NET_DHCPV4_INIT: case NET_DHCPV4_INIT:
@ -644,7 +649,8 @@ static void dhcpv4_timeout(struct k_work *work)
/* Maximum number of renewal attempts failed, so start /* Maximum number of renewal attempts failed, so start
* from the beginning. * from the beginning.
*/ */
if (iface->dhcpv4.attempts >= DHCPV4_MAX_NUMBER_OF_ATTEMPTS) { if (iface->config.dhcpv4.attempts >=
DHCPV4_MAX_NUMBER_OF_ATTEMPTS) {
NET_DBG("too many attempts, restart"); NET_DBG("too many attempts, restart");
enter_selecting(iface); enter_selecting(iface);
} else { } else {
@ -656,10 +662,11 @@ static void dhcpv4_timeout(struct k_work *work)
break; break;
case NET_DHCPV4_RENEWING: case NET_DHCPV4_RENEWING:
case NET_DHCPV4_REBINDING: case NET_DHCPV4_REBINDING:
if (iface->dhcpv4.attempts >= DHCPV4_MAX_NUMBER_OF_ATTEMPTS) { if (iface->config.dhcpv4.attempts >=
DHCPV4_MAX_NUMBER_OF_ATTEMPTS) {
NET_DBG("too many attempts, restart"); NET_DBG("too many attempts, restart");
if (!net_if_ipv4_addr_rm(iface, if (!net_if_ipv4_addr_rm(iface,
&iface->dhcpv4.requested_ip)) { &iface->config.dhcpv4.requested_ip)) {
NET_DBG("Failed to remove addr from iface"); NET_DBG("Failed to remove addr from iface");
} }
/* Maximum number of renewal attempts failed, so start /* Maximum number of renewal attempts failed, so start
@ -802,10 +809,10 @@ static enum net_verdict parse_options(struct net_if *iface,
} }
frag = net_frag_read_be32(frag, pos, &pos, frag = net_frag_read_be32(frag, pos, &pos,
&iface->dhcpv4.lease_time); &iface->config.dhcpv4.lease_time);
NET_DBG("options_lease_time: %u", NET_DBG("options_lease_time: %u",
iface->dhcpv4.lease_time); iface->config.dhcpv4.lease_time);
if (!iface->dhcpv4.lease_time) { if (!iface->config.dhcpv4.lease_time) {
return NET_DROP; return NET_DROP;
} }
@ -817,10 +824,10 @@ static enum net_verdict parse_options(struct net_if *iface,
} }
frag = net_frag_read_be32(frag, pos, &pos, frag = net_frag_read_be32(frag, pos, &pos,
&iface->dhcpv4.renewal_time); &iface->config.dhcpv4.renewal_time);
NET_DBG("options_renewal: %u", NET_DBG("options_renewal: %u",
iface->dhcpv4.renewal_time); iface->config.dhcpv4.renewal_time);
if (!iface->dhcpv4.renewal_time) { if (!iface->config.dhcpv4.renewal_time) {
return NET_DROP; return NET_DROP;
} }
@ -832,10 +839,10 @@ static enum net_verdict parse_options(struct net_if *iface,
} }
frag = net_frag_read_be32(frag, pos, &pos, frag = net_frag_read_be32(frag, pos, &pos,
&iface->dhcpv4.rebinding_time); &iface->config.dhcpv4.rebinding_time);
NET_DBG("options_rebinding: %u", NET_DBG("options_rebinding: %u",
iface->dhcpv4.rebinding_time); iface->config.dhcpv4.rebinding_time);
if (!iface->dhcpv4.rebinding_time) { if (!iface->config.dhcpv4.rebinding_time) {
return NET_DROP; return NET_DROP;
} }
@ -847,9 +854,10 @@ static enum net_verdict parse_options(struct net_if *iface,
} }
frag = net_frag_read(frag, pos, &pos, length, frag = net_frag_read(frag, pos, &pos, length,
iface->dhcpv4.server_id.s4_addr); iface->config.dhcpv4.server_id.s4_addr);
NET_DBG("options_server_id: %s", NET_DBG("options_server_id: %s",
net_sprint_ipv4_addr(&iface->dhcpv4.server_id)); net_sprint_ipv4_addr(
&iface->config.dhcpv4.server_id));
break; break;
case DHCPV4_OPTIONS_MSG_TYPE: { case DHCPV4_OPTIONS_MSG_TYPE: {
u8_t v; u8_t v;
@ -880,7 +888,7 @@ static enum net_verdict parse_options(struct net_if *iface,
static inline void handle_offer(struct net_if *iface) static inline void handle_offer(struct net_if *iface)
{ {
switch (iface->dhcpv4.state) { switch (iface->config.dhcpv4.state) {
case NET_DHCPV4_DISABLED: case NET_DHCPV4_DISABLED:
case NET_DHCPV4_INIT: case NET_DHCPV4_INIT:
case NET_DHCPV4_REQUESTING: case NET_DHCPV4_REQUESTING:
@ -889,7 +897,7 @@ static inline void handle_offer(struct net_if *iface)
case NET_DHCPV4_BOUND: case NET_DHCPV4_BOUND:
break; break;
case NET_DHCPV4_SELECTING: case NET_DHCPV4_SELECTING:
k_delayed_work_cancel(&iface->dhcpv4.timer); k_delayed_work_cancel(&iface->config.dhcpv4.timer);
enter_requesting(iface); enter_requesting(iface);
break; break;
} }
@ -897,7 +905,7 @@ static inline void handle_offer(struct net_if *iface)
static void handle_ack(struct net_if *iface) static void handle_ack(struct net_if *iface)
{ {
switch (iface->dhcpv4.state) { switch (iface->config.dhcpv4.state) {
case NET_DHCPV4_DISABLED: case NET_DHCPV4_DISABLED:
case NET_DHCPV4_INIT: case NET_DHCPV4_INIT:
case NET_DHCPV4_SELECTING: case NET_DHCPV4_SELECTING:
@ -905,11 +913,12 @@ static void handle_ack(struct net_if *iface)
break; break;
case NET_DHCPV4_REQUESTING: case NET_DHCPV4_REQUESTING:
NET_INFO("Received: %s", NET_INFO("Received: %s",
net_sprint_ipv4_addr(&iface->dhcpv4.requested_ip)); net_sprint_ipv4_addr(
&iface->config.dhcpv4.requested_ip));
if (!net_if_ipv4_addr_add(iface, if (!net_if_ipv4_addr_add(iface,
&iface->dhcpv4.requested_ip, &iface->config.dhcpv4.requested_ip,
NET_ADDR_DHCP, NET_ADDR_DHCP,
iface->dhcpv4.lease_time)) { iface->config.dhcpv4.lease_time)) {
NET_DBG("Failed to add IPv4 addr to iface %p", iface); NET_DBG("Failed to add IPv4 addr to iface %p", iface);
return; return;
} }
@ -929,7 +938,7 @@ static void handle_ack(struct net_if *iface)
static void handle_nak(struct net_if *iface) static void handle_nak(struct net_if *iface)
{ {
switch (iface->dhcpv4.state) { switch (iface->config.dhcpv4.state) {
case NET_DHCPV4_DISABLED: case NET_DHCPV4_DISABLED:
case NET_DHCPV4_INIT: case NET_DHCPV4_INIT:
case NET_DHCPV4_SELECTING: case NET_DHCPV4_SELECTING:
@ -940,9 +949,9 @@ static void handle_nak(struct net_if *iface)
case NET_DHCPV4_REBINDING: case NET_DHCPV4_REBINDING:
/* Restart the configuration process. */ /* Restart the configuration process. */
k_delayed_work_cancel(&iface->dhcpv4.timer); k_delayed_work_cancel(&iface->config.dhcpv4.timer);
k_delayed_work_cancel(&iface->dhcpv4.t1_timer); k_delayed_work_cancel(&iface->config.dhcpv4.t1_timer);
k_delayed_work_cancel(&iface->dhcpv4.t2_timer); k_delayed_work_cancel(&iface->config.dhcpv4.t2_timer);
enter_selecting(iface); enter_selecting(iface);
break; break;
@ -953,7 +962,7 @@ static void handle_dhcpv4_reply(struct net_if *iface,
enum dhcpv4_msg_type msg_type) enum dhcpv4_msg_type msg_type)
{ {
NET_DBG("state=%s msg=%s", NET_DBG("state=%s msg=%s",
net_dhcpv4_state_name(iface->dhcpv4.state), net_dhcpv4_state_name(iface->config.dhcpv4.state),
net_dhcpv4_msg_type_name(msg_type)); net_dhcpv4_msg_type_name(msg_type));
switch (msg_type) { switch (msg_type) {
@ -1025,16 +1034,16 @@ static enum net_verdict net_dhcpv4_input(struct net_conn *conn,
net_sprint_ll_addr(msg->chaddr, 6)); net_sprint_ll_addr(msg->chaddr, 6));
if (!(msg->op == DHCPV4_MSG_BOOT_REPLY && if (!(msg->op == DHCPV4_MSG_BOOT_REPLY &&
iface->dhcpv4.xid == ntohl(msg->xid) && iface->config.dhcpv4.xid == ntohl(msg->xid) &&
!memcmp(msg->chaddr, iface->link_addr.addr, !memcmp(msg->chaddr, net_if_get_link_addr(iface)->addr,
iface->link_addr.len))) { net_if_get_link_addr(iface)->len))) {
NET_DBG("Unexpected op (%d), xid (%x vs %x) or chaddr", NET_DBG("Unexpected op (%d), xid (%x vs %x) or chaddr",
msg->op, iface->dhcpv4.xid, ntohl(msg->xid)); msg->op, iface->config.dhcpv4.xid, ntohl(msg->xid));
goto drop; goto drop;
} }
memcpy(iface->dhcpv4.requested_ip.s4_addr, msg->yiaddr, memcpy(iface->config.dhcpv4.requested_ip.s4_addr, msg->yiaddr,
sizeof(msg->yiaddr)); sizeof(msg->yiaddr));
/* SNAME, FILE are not used at the moment, skip it */ /* SNAME, FILE are not used at the moment, skip it */
@ -1064,21 +1073,25 @@ void net_dhcpv4_start(struct net_if *iface)
u32_t timeout; u32_t timeout;
u32_t entropy; u32_t entropy;
switch (iface->dhcpv4.state) { switch (iface->config.dhcpv4.state) {
case NET_DHCPV4_DISABLED: case NET_DHCPV4_DISABLED:
iface->dhcpv4.state = NET_DHCPV4_INIT; iface->config.dhcpv4.state = NET_DHCPV4_INIT;
NET_DBG("state=%s", net_dhcpv4_state_name(iface->dhcpv4.state)); NET_DBG("state=%s",
net_dhcpv4_state_name(iface->config.dhcpv4.state));
iface->dhcpv4.attempts = 0; iface->config.dhcpv4.attempts = 0;
iface->dhcpv4.lease_time = 0; iface->config.dhcpv4.lease_time = 0;
iface->dhcpv4.renewal_time = 0; iface->config.dhcpv4.renewal_time = 0;
iface->dhcpv4.server_id.s_addr = 0; iface->config.dhcpv4.server_id.s_addr = 0;
iface->dhcpv4.requested_ip.s_addr = 0; iface->config.dhcpv4.requested_ip.s_addr = 0;
k_delayed_work_init(&iface->dhcpv4.timer, dhcpv4_timeout); k_delayed_work_init(&iface->config.dhcpv4.timer,
k_delayed_work_init(&iface->dhcpv4.t1_timer, dhcpv4_t1_timeout); dhcpv4_timeout);
k_delayed_work_init(&iface->dhcpv4.t2_timer, dhcpv4_t2_timeout); k_delayed_work_init(&iface->config.dhcpv4.t1_timer,
dhcpv4_t1_timeout);
k_delayed_work_init(&iface->config.dhcpv4.t2_timer,
dhcpv4_t2_timeout);
/* We need entropy for both an XID and a random delay /* We need entropy for both an XID and a random delay
* before sending the initial discover message. * before sending the initial discover message.
@ -1090,7 +1103,7 @@ void net_dhcpv4_start(struct net_if *iface)
* one used by another client. Choose a random xid st * one used by another client. Choose a random xid st
* startup and increment it on each new request. * startup and increment it on each new request.
*/ */
iface->dhcpv4.xid = entropy; iface->config.dhcpv4.xid = entropy;
/* RFC2131 4.1.1 requires we wait a random period /* RFC2131 4.1.1 requires we wait a random period
@ -1103,7 +1116,7 @@ void net_dhcpv4_start(struct net_if *iface)
NET_DBG("wait timeout=%"PRIu32"s", timeout); NET_DBG("wait timeout=%"PRIu32"s", timeout);
k_delayed_work_submit(&iface->dhcpv4.timer, k_delayed_work_submit(&iface->config.dhcpv4.timer,
timeout * MSEC_PER_SEC); timeout * MSEC_PER_SEC);
break; break;
case NET_DHCPV4_INIT: case NET_DHCPV4_INIT:
@ -1118,13 +1131,13 @@ void net_dhcpv4_start(struct net_if *iface)
void net_dhcpv4_stop(struct net_if *iface) void net_dhcpv4_stop(struct net_if *iface)
{ {
switch (iface->dhcpv4.state) { switch (iface->config.dhcpv4.state) {
case NET_DHCPV4_DISABLED: case NET_DHCPV4_DISABLED:
break; break;
case NET_DHCPV4_BOUND: case NET_DHCPV4_BOUND:
if (!net_if_ipv4_addr_rm(iface, if (!net_if_ipv4_addr_rm(iface,
&iface->dhcpv4.requested_ip)) { &iface->config.dhcpv4.requested_ip)) {
NET_DBG("Failed to remove addr from iface"); NET_DBG("Failed to remove addr from iface");
} }
/* Fall through */ /* Fall through */
@ -1134,12 +1147,13 @@ void net_dhcpv4_stop(struct net_if *iface)
case NET_DHCPV4_REQUESTING: case NET_DHCPV4_REQUESTING:
case NET_DHCPV4_RENEWING: case NET_DHCPV4_RENEWING:
case NET_DHCPV4_REBINDING: case NET_DHCPV4_REBINDING:
iface->dhcpv4.state = NET_DHCPV4_DISABLED; iface->config.dhcpv4.state = NET_DHCPV4_DISABLED;
NET_DBG("state=%s", net_dhcpv4_state_name(iface->dhcpv4.state)); NET_DBG("state=%s",
net_dhcpv4_state_name(iface->config.dhcpv4.state));
k_delayed_work_cancel(&iface->dhcpv4.timer); k_delayed_work_cancel(&iface->config.dhcpv4.timer);
k_delayed_work_cancel(&iface->dhcpv4.t1_timer); k_delayed_work_cancel(&iface->config.dhcpv4.t1_timer);
k_delayed_work_cancel(&iface->dhcpv4.t2_timer); k_delayed_work_cancel(&iface->config.dhcpv4.t2_timer);
break; break;
} }
} }

View file

@ -189,12 +189,15 @@ int net_icmpv4_send_echo_request(struct net_if *iface,
u16_t identifier, u16_t identifier,
u16_t sequence) u16_t sequence)
{ {
struct net_if_config *config;
const struct in_addr *src; const struct in_addr *src;
struct net_pkt *pkt; struct net_pkt *pkt;
struct net_buf *frag; struct net_buf *frag;
config = net_if_config_get(iface);
/* Take the first address of the network interface */ /* Take the first address of the network interface */
src = &iface->ipv4.unicast[0].address.in_addr; src = &config->ip.ipv4.unicast[0].address.in_addr;
/* We cast to IPv6 address but that should be ok in this case /* We cast to IPv6 address but that should be ok in this case
* as IPv4 cannot be used in 802.15.4 where it is the reserve * as IPv4 cannot be used in 802.15.4 where it is the reserve

View file

@ -69,6 +69,10 @@ struct net_pkt *net_ipv4_create(struct net_context *context,
const struct in_addr *src, const struct in_addr *src,
const struct in_addr *dst) const struct in_addr *dst)
{ {
struct net_if_config *config;
config = net_if_config_get(net_pkt_iface(pkt));
NET_ASSERT(((struct sockaddr_in_ptr *)&context->local)->sin_addr); NET_ASSERT(((struct sockaddr_in_ptr *)&context->local)->sin_addr);
if (!src) { if (!src) {
@ -77,7 +81,7 @@ struct net_pkt *net_ipv4_create(struct net_context *context,
if (net_is_ipv4_addr_unspecified(src) if (net_is_ipv4_addr_unspecified(src)
|| net_is_ipv4_addr_mcast(src)) { || net_is_ipv4_addr_mcast(src)) {
src = &net_pkt_iface(pkt)->ipv4.unicast[0].address.in_addr; src = &config->ip.ipv4.unicast[0].address.in_addr;
} }
return net_ipv4_create_raw(pkt, return net_ipv4_create_raw(pkt,

View file

@ -1041,7 +1041,8 @@ ignore_frag_error:
/* Workaround Linux bug, see: /* Workaround Linux bug, see:
* https://github.com/zephyrproject-rtos/zephyr/issues/3111 * https://github.com/zephyrproject-rtos/zephyr/issues/3111
*/ */
if (atomic_test_bit(net_pkt_iface(pkt)->flags, NET_IF_POINTOPOINT)) { if (atomic_test_bit(net_pkt_iface(pkt)->if_dev->flags,
NET_IF_POINTOPOINT)) {
/* Update RPL header */ /* Update RPL header */
if (net_rpl_update_header(pkt, &NET_IPV6_HDR(pkt)->dst) < 0) { if (net_rpl_update_header(pkt, &NET_IPV6_HDR(pkt)->dst) < 0) {
net_pkt_unref(pkt); net_pkt_unref(pkt);
@ -1208,15 +1209,15 @@ struct net_nbr *net_ipv6_get_nbr(struct net_if *iface, u8_t idx)
static inline u8_t get_llao_len(struct net_if *iface) static inline u8_t get_llao_len(struct net_if *iface)
{ {
if (iface->link_addr.len == 6) { if (net_if_get_link_addr(iface)->len == 6) {
return 8; return 8;
} else if (iface->link_addr.len == 8) { } else if (net_if_get_link_addr(iface)->len == 8) {
return 16; return 16;
} }
/* What else could it be? */ /* What else could it be? */
NET_ASSERT_INFO(0, "Invalid link address length %d", NET_ASSERT_INFO(0, "Invalid link address length %d",
iface->link_addr.len); net_if_get_link_addr(iface)->len);
return 0; return 0;
} }
@ -1336,7 +1337,7 @@ int net_ipv6_send_na(struct net_if *iface, const struct in6_addr *src,
net_ipaddr_copy(&NET_IPV6_HDR(pkt)->dst, dst); net_ipaddr_copy(&NET_IPV6_HDR(pkt)->dst, dst);
net_ipaddr_copy(&na_hdr->tgt, tgt); net_ipaddr_copy(&na_hdr->tgt, tgt);
set_llao(&net_pkt_iface(pkt)->link_addr, set_llao(net_if_get_link_addr(net_pkt_iface(pkt)),
(u8_t *)net_pkt_icmp_data(pkt) + sizeof(struct net_icmp_hdr) + (u8_t *)net_pkt_icmp_data(pkt) + sizeof(struct net_icmp_hdr) +
sizeof(struct net_icmpv6_na_hdr), sizeof(struct net_icmpv6_na_hdr),
llao_len, NET_ICMPV6_ND_OPT_TLLAO); llao_len, NET_ICMPV6_ND_OPT_TLLAO);
@ -1749,7 +1750,8 @@ static void nd_reachable_timeout(struct k_work *work)
} }
} }
void net_ipv6_nbr_set_reachable_timer(struct net_if *iface, struct net_nbr *nbr) void net_ipv6_nbr_set_reachable_timer(struct net_if *iface,
struct net_nbr *nbr)
{ {
u32_t time; u32_t time;
@ -1792,7 +1794,7 @@ static inline bool handle_na_neighbor(struct net_pkt *pkt,
} }
if (tllao_offset) { if (tllao_offset) {
lladdr.len = net_pkt_iface(pkt)->link_addr.len; lladdr.len = net_if_get_link_addr(net_pkt_iface(pkt))->len;
frag = net_frag_read(pkt->frags, tllao_offset, frag = net_frag_read(pkt->frags, tllao_offset,
&pos, lladdr.len, lladdr.addr); &pos, lladdr.len, lladdr.addr);
@ -2133,7 +2135,7 @@ int net_ipv6_send_ns(struct net_if *iface,
net_buf_add(frag, llao_len); net_buf_add(frag, llao_len);
set_llao(&net_pkt_iface(pkt)->link_addr, set_llao(net_if_get_link_addr(net_pkt_iface(pkt)),
(u8_t *)net_pkt_icmp_data(pkt) + (u8_t *)net_pkt_icmp_data(pkt) +
sizeof(struct net_icmp_hdr) + sizeof(struct net_icmp_hdr) +
sizeof(struct net_icmpv6_ns_hdr), sizeof(struct net_icmpv6_ns_hdr),
@ -2250,7 +2252,7 @@ int net_ipv6_send_rs(struct net_if *iface)
if (!unspec_src) { if (!unspec_src) {
net_buf_add(frag, llao_len); net_buf_add(frag, llao_len);
set_llao(&net_pkt_iface(pkt)->link_addr, set_llao(net_if_get_link_addr(net_pkt_iface(pkt)),
(u8_t *)net_pkt_icmp_data(pkt) + (u8_t *)net_pkt_icmp_data(pkt) +
sizeof(struct net_icmp_hdr) + sizeof(struct net_icmp_hdr) +
sizeof(struct net_icmpv6_rs_hdr), sizeof(struct net_icmpv6_rs_hdr),
@ -2565,6 +2567,7 @@ static enum net_verdict handle_ra_input(struct net_pkt *pkt)
struct net_nbr *nbr = NULL; struct net_nbr *nbr = NULL;
struct net_icmpv6_ra_hdr hdr, *ra_hdr; struct net_icmpv6_ra_hdr hdr, *ra_hdr;
struct net_if_router *router; struct net_if_router *router;
struct net_if_config *config;
struct net_buf *frag; struct net_buf *frag;
u16_t router_lifetime; u16_t router_lifetime;
u32_t reachable_time; u32_t reachable_time;
@ -2758,8 +2761,10 @@ static enum net_verdict handle_ra_input(struct net_pkt *pkt)
nbr_clear_ns_pending(net_ipv6_nbr_data(nbr)); nbr_clear_ns_pending(net_ipv6_nbr_data(nbr));
} }
config = net_if_config_get(net_pkt_iface(pkt));
/* Cancel the RS timer on iface */ /* Cancel the RS timer on iface */
k_delayed_work_cancel(&net_pkt_iface(pkt)->ipv6.rs_timer); k_delayed_work_cancel(&config->ip.ipv6.rs_timer);
net_pkt_unref(pkt); net_pkt_unref(pkt);
@ -2949,21 +2954,25 @@ int net_ipv6_mld_leave(struct net_if *iface, const struct in6_addr *addr)
static void send_mld_report(struct net_if *iface) static void send_mld_report(struct net_if *iface)
{ {
struct net_if_config *config;
struct net_pkt *pkt; struct net_pkt *pkt;
int i, count = 0; int i, count = 0;
config = net_if_config_get(iface);
pkt = net_pkt_get_reserve_tx(net_if_get_ll_reserve(iface, NULL), pkt = net_pkt_get_reserve_tx(net_if_get_ll_reserve(iface, NULL),
K_FOREVER); K_FOREVER);
net_pkt_append_u8(pkt, 0); /* This will be the record count */ net_pkt_append_u8(pkt, 0); /* This will be the record count */
for (i = 0; i < NET_IF_MAX_IPV6_MADDR; i++) { for (i = 0; i < NET_IF_MAX_IPV6_MADDR; i++) {
if (!iface->ipv6.mcast[i].is_used || if (!config->ip.ipv6.mcast[i].is_used ||
!iface->ipv6.mcast[i].is_joined) { !config->ip.ipv6.mcast[i].is_joined) {
continue; continue;
} }
pkt = create_mldv2(pkt, &iface->ipv6.mcast[i].address.in6_addr, pkt = create_mldv2(pkt,
&config->ip.ipv6.mcast[i].address.in6_addr,
NET_IPV6_MLDv2_MODE_IS_EXCLUDE, 0); NET_IPV6_MLDv2_MODE_IS_EXCLUDE, 0);
count++; count++;
} }

View file

@ -78,13 +78,17 @@ static inline struct arp_entry *find_entry(struct net_if *iface,
static inline struct in_addr *if_get_addr(struct net_if *iface) static inline struct in_addr *if_get_addr(struct net_if *iface)
{ {
struct net_if_config *config;
int i; int i;
config = net_if_config_get(iface);
for (i = 0; i < NET_IF_MAX_IPV4_ADDR; i++) { for (i = 0; i < NET_IF_MAX_IPV4_ADDR; i++) {
if (iface->ipv4.unicast[i].is_used && if (config->ip.ipv4.unicast[i].is_used &&
iface->ipv4.unicast[i].address.family == AF_INET && config->ip.ipv4.unicast[i].address.family == AF_INET &&
iface->ipv4.unicast[i].addr_state == NET_ADDR_PREFERRED) { config->ip.ipv4.unicast[i].addr_state ==
return &iface->ipv4.unicast[i].address.in_addr; NET_ADDR_PREFERRED) {
return &config->ip.ipv4.unicast[i].address.in_addr;
} }
} }
@ -226,7 +230,11 @@ struct net_pkt *net_arp_prepare(struct net_pkt *pkt)
*/ */
if (!net_if_ipv4_addr_mask_cmp(net_pkt_iface(pkt), if (!net_if_ipv4_addr_mask_cmp(net_pkt_iface(pkt),
&NET_IPV4_HDR(pkt)->dst)) { &NET_IPV4_HDR(pkt)->dst)) {
addr = &net_pkt_iface(pkt)->ipv4.gw; struct net_if_config *config;
config = net_if_config_get(net_pkt_iface(pkt));
addr = &config->ip.ipv4.gw;
if (net_is_ipv4_addr_unspecified(addr)) { if (net_is_ipv4_addr_unspecified(addr)) {
NET_ERR("Gateway not set for iface %p", NET_ERR("Gateway not set for iface %p",
net_pkt_iface(pkt)); net_pkt_iface(pkt));

View file

@ -262,7 +262,7 @@ static void bt_iface_init(struct net_if *iface)
/* Workaround Linux bug, see: /* Workaround Linux bug, see:
* https://github.com/zephyrproject-rtos/zephyr/issues/3111 * https://github.com/zephyrproject-rtos/zephyr/issues/3111
*/ */
atomic_set_bit(iface->flags, NET_IF_POINTOPOINT); atomic_set_bit(iface->if_dev->flags, NET_IF_POINTOPOINT);
#endif #endif
} }

View file

@ -312,7 +312,7 @@ NET_L2_INIT(IEEE802154_L2,
void ieee802154_init(struct net_if *iface) void ieee802154_init(struct net_if *iface)
{ {
struct ieee802154_context *ctx = net_if_l2_data(iface); struct ieee802154_context *ctx = net_if_l2_data(iface);
const u8_t *mac = iface->link_addr.addr; const u8_t *mac = net_if_get_link_addr(iface)->addr;
s16_t tx_power = CONFIG_NET_L2_IEEE802154_RADIO_DFLT_TX_POWER; s16_t tx_power = CONFIG_NET_L2_IEEE802154_RADIO_DFLT_TX_POWER;
u8_t long_addr[8]; u8_t long_addr[8];

View file

@ -17,65 +17,74 @@
static inline static inline
enum ieee802154_hw_caps ieee802154_get_hw_capabilities(struct net_if *iface) enum ieee802154_hw_caps ieee802154_get_hw_capabilities(struct net_if *iface)
{ {
const struct ieee802154_radio_api *radio = iface->dev->driver_api; const struct ieee802154_radio_api *radio =
net_if_get_device(iface)->driver_api;
return radio->get_capabilities(iface->dev); return radio->get_capabilities(net_if_get_device(iface));
} }
static inline int ieee802154_cca(struct net_if *iface) static inline int ieee802154_cca(struct net_if *iface)
{ {
const struct ieee802154_radio_api *radio = iface->dev->driver_api; const struct ieee802154_radio_api *radio =
net_if_get_device(iface)->driver_api;
return radio->cca(iface->dev); return radio->cca(net_if_get_device(iface));
} }
static inline int ieee802154_set_channel(struct net_if *iface, u16_t channel) static inline int ieee802154_set_channel(struct net_if *iface, u16_t channel)
{ {
const struct ieee802154_radio_api *radio = iface->dev->driver_api; const struct ieee802154_radio_api *radio =
net_if_get_device(iface)->driver_api;
return radio->set_channel(iface->dev, channel); return radio->set_channel(net_if_get_device(iface), channel);
} }
static inline int ieee802154_set_tx_power(struct net_if *iface, s16_t dbm) static inline int ieee802154_set_tx_power(struct net_if *iface, s16_t dbm)
{ {
const struct ieee802154_radio_api *radio = iface->dev->driver_api; const struct ieee802154_radio_api *radio =
net_if_get_device(iface)->driver_api;
return radio->set_txpower(iface->dev, dbm); return radio->set_txpower(net_if_get_device(iface), dbm);
} }
static inline int ieee802154_tx(struct net_if *iface, static inline int ieee802154_tx(struct net_if *iface,
struct net_pkt *pkt, struct net_buf *frag) struct net_pkt *pkt, struct net_buf *frag)
{ {
const struct ieee802154_radio_api *radio = iface->dev->driver_api; const struct ieee802154_radio_api *radio =
net_if_get_device(iface)->driver_api;
return radio->tx(iface->dev, pkt, frag); return radio->tx(net_if_get_device(iface), pkt, frag);
} }
static inline int ieee802154_start(struct net_if *iface) static inline int ieee802154_start(struct net_if *iface)
{ {
const struct ieee802154_radio_api *radio = iface->dev->driver_api; const struct ieee802154_radio_api *radio =
net_if_get_device(iface)->driver_api;
return radio->start(iface->dev); return radio->start(net_if_get_device(iface));
} }
static inline int ieee802154_stop(struct net_if *iface) static inline int ieee802154_stop(struct net_if *iface)
{ {
const struct ieee802154_radio_api *radio = iface->dev->driver_api; const struct ieee802154_radio_api *radio =
net_if_get_device(iface)->driver_api;
return radio->stop(iface->dev); return radio->stop(net_if_get_device(iface));
} }
static inline void ieee802154_filter_ieee_addr(struct net_if *iface, static inline void ieee802154_filter_ieee_addr(struct net_if *iface,
u8_t *ieee_addr) u8_t *ieee_addr)
{ {
const struct ieee802154_radio_api *radio = iface->dev->driver_api; const struct ieee802154_radio_api *radio =
net_if_get_device(iface)->driver_api;
if (radio->get_capabilities(iface->dev) & IEEE802154_HW_FILTER) { if (radio->get_capabilities(net_if_get_device(iface)) &
IEEE802154_HW_FILTER) {
struct ieee802154_filter filter; struct ieee802154_filter filter;
filter.ieee_addr = ieee_addr; filter.ieee_addr = ieee_addr;
if (radio->set_filter(iface->dev, if (radio->set_filter(net_if_get_device(iface),
IEEE802154_FILTER_TYPE_IEEE_ADDR, IEEE802154_FILTER_TYPE_IEEE_ADDR,
&filter) != 0) { &filter) != 0) {
NET_WARN("Could not apply IEEE address filter"); NET_WARN("Could not apply IEEE address filter");
@ -86,14 +95,16 @@ static inline void ieee802154_filter_ieee_addr(struct net_if *iface,
static inline void ieee802154_filter_short_addr(struct net_if *iface, static inline void ieee802154_filter_short_addr(struct net_if *iface,
u16_t short_addr) u16_t short_addr)
{ {
const struct ieee802154_radio_api *radio = iface->dev->driver_api; const struct ieee802154_radio_api *radio =
net_if_get_device(iface)->driver_api;
if (radio->get_capabilities(iface->dev) & IEEE802154_HW_FILTER) { if (radio->get_capabilities(net_if_get_device(iface)) &
IEEE802154_HW_FILTER) {
struct ieee802154_filter filter; struct ieee802154_filter filter;
filter.short_addr = short_addr; filter.short_addr = short_addr;
if (radio->set_filter(iface->dev, if (radio->set_filter(net_if_get_device(iface),
IEEE802154_FILTER_TYPE_SHORT_ADDR, IEEE802154_FILTER_TYPE_SHORT_ADDR,
&filter) != 0) { &filter) != 0) {
NET_WARN("Could not apply short address filter"); NET_WARN("Could not apply short address filter");
@ -104,14 +115,16 @@ static inline void ieee802154_filter_short_addr(struct net_if *iface,
static inline void ieee802154_filter_pan_id(struct net_if *iface, static inline void ieee802154_filter_pan_id(struct net_if *iface,
u16_t pan_id) u16_t pan_id)
{ {
const struct ieee802154_radio_api *radio = iface->dev->driver_api; const struct ieee802154_radio_api *radio =
net_if_get_device(iface)->driver_api;
if (radio->get_capabilities(iface->dev) & IEEE802154_HW_FILTER) { if (radio->get_capabilities(net_if_get_device(iface)) &
IEEE802154_HW_FILTER) {
struct ieee802154_filter filter; struct ieee802154_filter filter;
filter.pan_id = pan_id; filter.pan_id = pan_id;
if (radio->set_filter(iface->dev, if (radio->set_filter(net_if_get_device(iface),
IEEE802154_FILTER_TYPE_PAN_ID, IEEE802154_FILTER_TYPE_PAN_ID,
&filter) != 0) { &filter) != 0) {
NET_WARN("Could not apply PAN ID filter"); NET_WARN("Could not apply PAN ID filter");
@ -127,10 +140,13 @@ static inline bool ieee802154_verify_channel(struct net_if *iface,
} }
#ifdef CONFIG_NET_L2_IEEE802154_SUB_GHZ #ifdef CONFIG_NET_L2_IEEE802154_SUB_GHZ
const struct ieee802154_radio_api *radio = iface->dev->driver_api; const struct ieee802154_radio_api *radio =
net_if_get_device(iface)->driver_api;
if (radio->get_capabilities(iface->dev) & IEEE802154_HW_SUB_GHZ) { if (radio->get_capabilities(net_if_get_device(iface)) &
if (channel > radio->get_subg_channel_count(iface->dev)) { IEEE802154_HW_SUB_GHZ) {
if (channel >
radio->get_subg_channel_count(net_if_get_device(iface))) {
return false; return false;
} }
} }

View file

@ -340,7 +340,7 @@ int net_recv_data(struct net_if *iface, struct net_pkt *pkt)
return -ENODATA; return -ENODATA;
} }
if (!atomic_test_bit(iface->flags, NET_IF_UP)) { if (!atomic_test_bit(iface->if_dev->flags, NET_IF_UP)) {
return -ENETDOWN; return -ENETDOWN;
} }

File diff suppressed because it is too large Load diff

View file

@ -100,7 +100,7 @@ static inline const char *addrstate2str(enum net_addr_state addr_state)
static const char *iface2str(struct net_if *iface, const char **extra) static const char *iface2str(struct net_if *iface, const char **extra)
{ {
#ifdef CONFIG_NET_L2_IEEE802154 #ifdef CONFIG_NET_L2_IEEE802154
if (iface->l2 == &NET_L2_GET_NAME(IEEE802154)) { if (net_if_l2(iface) == &NET_L2_GET_NAME(IEEE802154)) {
if (extra) { if (extra) {
*extra = "============="; *extra = "=============";
} }
@ -110,7 +110,7 @@ static const char *iface2str(struct net_if *iface, const char **extra)
#endif #endif
#ifdef CONFIG_NET_L2_ETHERNET #ifdef CONFIG_NET_L2_ETHERNET
if (iface->l2 == &NET_L2_GET_NAME(ETHERNET)) { if (net_if_l2(iface) == &NET_L2_GET_NAME(ETHERNET)) {
if (extra) { if (extra) {
*extra = "========"; *extra = "========";
} }
@ -120,7 +120,7 @@ static const char *iface2str(struct net_if *iface, const char **extra)
#endif #endif
#ifdef CONFIG_NET_L2_DUMMY #ifdef CONFIG_NET_L2_DUMMY
if (iface->l2 == &NET_L2_GET_NAME(DUMMY)) { if (net_if_l2(iface) == &NET_L2_GET_NAME(DUMMY)) {
if (extra) { if (extra) {
*extra = "====="; *extra = "=====";
} }
@ -130,7 +130,7 @@ static const char *iface2str(struct net_if *iface, const char **extra)
#endif #endif
#ifdef CONFIG_NET_L2_BT #ifdef CONFIG_NET_L2_BT
if (iface->l2 == &NET_L2_GET_NAME(BLUETOOTH)) { if (net_if_l2(iface) == &NET_L2_GET_NAME(BLUETOOTH)) {
if (extra) { if (extra) {
*extra = "========="; *extra = "=========";
} }
@ -140,7 +140,7 @@ static const char *iface2str(struct net_if *iface, const char **extra)
#endif #endif
#ifdef CONFIG_NET_OFFLOAD #ifdef CONFIG_NET_OFFLOAD
if (iface->l2 == &NET_L2_GET_NAME(OFFLOAD_IP)) { if (net_if_l2(iface) == &NET_L2_GET_NAME(OFFLOAD_IP)) {
if (extra) { if (extra) {
*extra = "=========="; *extra = "==========";
} }
@ -164,29 +164,34 @@ static void iface_cb(struct net_if *iface, void *user_data)
#endif #endif
struct net_if_addr *unicast; struct net_if_addr *unicast;
struct net_if_mcast_addr *mcast; struct net_if_mcast_addr *mcast;
struct net_if_config *config;
const char *extra; const char *extra;
int i, count; int i, count;
ARG_UNUSED(user_data); ARG_UNUSED(user_data);
printk("\nInterface %p (%s)\n", iface, iface2str(iface, &extra)); printk("\nInterface %p (%s) [%d]\n", iface, iface2str(iface, &extra),
printk("=======================%s\n", extra); net_if_get_by_iface(iface));
printk("===========================%s\n", extra);
if (!net_if_is_up(iface)) { if (!net_if_is_up(iface)) {
printk("Interface is down.\n"); printk("Interface is down.\n");
return; return;
} }
printk("Link addr : %s\n", net_sprint_ll_addr(iface->link_addr.addr, config = &iface->config;
iface->link_addr.len));
printk("MTU : %d\n", iface->mtu); printk("Link addr : %s\n", net_sprint_ll_addr(
net_if_get_link_addr(iface)->addr,
net_if_get_link_addr(iface)->len));
printk("MTU : %d\n", net_if_get_mtu(iface));
#if defined(CONFIG_NET_IPV6) #if defined(CONFIG_NET_IPV6)
count = 0; count = 0;
printk("IPv6 unicast addresses (max %d):\n", NET_IF_MAX_IPV6_ADDR); printk("IPv6 unicast addresses (max %d):\n", NET_IF_MAX_IPV6_ADDR);
for (i = 0; i < NET_IF_MAX_IPV6_ADDR; i++) { for (i = 0; i < NET_IF_MAX_IPV6_ADDR; i++) {
unicast = &iface->ipv6.unicast[i]; unicast = &config->ip.ipv6.unicast[i];
if (!unicast->is_used) { if (!unicast->is_used) {
continue; continue;
@ -208,7 +213,7 @@ static void iface_cb(struct net_if *iface, void *user_data)
printk("IPv6 multicast addresses (max %d):\n", NET_IF_MAX_IPV6_MADDR); printk("IPv6 multicast addresses (max %d):\n", NET_IF_MAX_IPV6_MADDR);
for (i = 0; i < NET_IF_MAX_IPV6_MADDR; i++) { for (i = 0; i < NET_IF_MAX_IPV6_MADDR; i++) {
mcast = &iface->ipv6.mcast[i]; mcast = &config->ip.ipv6.mcast[i];
if (!mcast->is_used) { if (!mcast->is_used) {
continue; continue;
@ -228,7 +233,7 @@ static void iface_cb(struct net_if *iface, void *user_data)
printk("IPv6 prefixes (max %d):\n", NET_IF_MAX_IPV6_PREFIX); printk("IPv6 prefixes (max %d):\n", NET_IF_MAX_IPV6_PREFIX);
for (i = 0; i < NET_IF_MAX_IPV6_PREFIX; i++) { for (i = 0; i < NET_IF_MAX_IPV6_PREFIX; i++) {
prefix = &iface->ipv6.prefix[i]; prefix = &config->ip.ipv6.prefix[i];
if (!prefix->is_used) { if (!prefix->is_used) {
continue; continue;
@ -254,11 +259,15 @@ static void iface_cb(struct net_if *iface, void *user_data)
router->is_infinite ? " infinite" : ""); router->is_infinite ? " infinite" : "");
} }
printk("IPv6 hop limit : %d\n", iface->ipv6.hop_limit); printk("IPv6 hop limit : %d\n",
config->ip.ipv6.hop_limit);
printk("IPv6 base reachable time : %d\n", printk("IPv6 base reachable time : %d\n",
iface->ipv6.base_reachable_time); config->ip.ipv6.base_reachable_time);
printk("IPv6 reachable time : %d\n", iface->ipv6.reachable_time); printk("IPv6 reachable time : %d\n",
printk("IPv6 retransmit timer : %d\n", iface->ipv6.retrans_timer); config->ip.ipv6.reachable_time);
printk("IPv6 retransmit timer : %d\n",
config->ip.ipv6.retrans_timer);
#endif /* CONFIG_NET_IPV6 */ #endif /* CONFIG_NET_IPV6 */
#if defined(CONFIG_NET_IPV4) #if defined(CONFIG_NET_IPV4)
@ -267,10 +276,10 @@ static void iface_cb(struct net_if *iface, void *user_data)
*/ */
if ( if (
#if defined(CONFIG_NET_L2_IEEE802154) #if defined(CONFIG_NET_L2_IEEE802154)
(iface->l2 == &NET_L2_GET_NAME(IEEE802154)) || (net_if_l2(iface) == &NET_L2_GET_NAME(IEEE802154)) ||
#endif #endif
#if defined(CONFIG_NET_L2_BT) #if defined(CONFIG_NET_L2_BT)
(iface->l2 == &NET_L2_GET_NAME(BLUETOOTH)) || (net_if_l2(iface) == &NET_L2_GET_NAME(BLUETOOTH)) ||
#endif #endif
0) { 0) {
printk("IPv4 not supported for this interface.\n"); printk("IPv4 not supported for this interface.\n");
@ -279,9 +288,10 @@ static void iface_cb(struct net_if *iface, void *user_data)
count = 0; count = 0;
printk("IPv4 unicast addresses (max %d):\n", NET_IF_MAX_IPV4_ADDR); printk("IPv4 unicast addresses (max %d):\n",
NET_IF_MAX_IPV4_ADDR);
for (i = 0; i < NET_IF_MAX_IPV4_ADDR; i++) { for (i = 0; i < NET_IF_MAX_IPV4_ADDR; i++) {
unicast = &iface->ipv4.unicast[i]; unicast = &config->ip.ipv4.unicast[i];
if (!unicast->is_used) { if (!unicast->is_used) {
continue; continue;
@ -302,9 +312,10 @@ static void iface_cb(struct net_if *iface, void *user_data)
count = 0; count = 0;
printk("IPv4 multicast addresses (max %d):\n", NET_IF_MAX_IPV4_MADDR); printk("IPv4 multicast addresses (max %d):\n",
NET_IF_MAX_IPV4_MADDR);
for (i = 0; i < NET_IF_MAX_IPV4_MADDR; i++) { for (i = 0; i < NET_IF_MAX_IPV4_MADDR; i++) {
mcast = &iface->ipv4.mcast[i]; mcast = &config->ip.ipv4.mcast[i];
if (!mcast->is_used) { if (!mcast->is_used) {
continue; continue;
@ -321,21 +332,24 @@ static void iface_cb(struct net_if *iface, void *user_data)
} }
printk("IPv4 gateway : %s\n", printk("IPv4 gateway : %s\n",
net_sprint_ipv4_addr(&iface->ipv4.gw)); net_sprint_ipv4_addr(&config->ip.ipv4.gw));
printk("IPv4 netmask : %s\n", printk("IPv4 netmask : %s\n",
net_sprint_ipv4_addr(&iface->ipv4.netmask)); net_sprint_ipv4_addr(&config->ip.ipv4.netmask));
#endif /* CONFIG_NET_IPV4 */ #endif /* CONFIG_NET_IPV4 */
#if defined(CONFIG_NET_DHCPV4) #if defined(CONFIG_NET_DHCPV4)
printk("DHCPv4 lease time : %u\n", iface->dhcpv4.lease_time); printk("DHCPv4 lease time : %u\n",
printk("DHCPv4 renew time : %u\n", iface->dhcpv4.renewal_time); config->dhcpv4.lease_time);
printk("DHCPv4 renew time : %u\n",
config->dhcpv4.renewal_time);
printk("DHCPv4 server : %s\n", printk("DHCPv4 server : %s\n",
net_sprint_ipv4_addr(&iface->dhcpv4.server_id)); net_sprint_ipv4_addr(&config->dhcpv4.server_id));
printk("DHCPv4 requested : %s\n", printk("DHCPv4 requested : %s\n",
net_sprint_ipv4_addr(&iface->dhcpv4.requested_ip)); net_sprint_ipv4_addr(&config->dhcpv4.requested_ip));
printk("DHCPv4 state : %s\n", printk("DHCPv4 state : %s\n",
net_dhcpv4_state_name(iface->dhcpv4.state)); net_dhcpv4_state_name(config->dhcpv4.state));
printk("DHCPv4 attempts : %d\n", iface->dhcpv4.attempts); printk("DHCPv4 attempts : %d\n",
config->dhcpv4.attempts);
#endif /* CONFIG_NET_DHCPV4 */ #endif /* CONFIG_NET_DHCPV4 */
} }
@ -2245,7 +2259,7 @@ static void get_my_ipv4_addr(struct net_if *iface,
{ {
/* Just take the first IPv4 address of an interface. */ /* Just take the first IPv4 address of an interface. */
memcpy(&net_sin(myaddr)->sin_addr, memcpy(&net_sin(myaddr)->sin_addr,
&iface->ipv4.unicast[0].address.in_addr, &iface->config.ip.ipv4.unicast[0].address.in_addr,
sizeof(struct in_addr)); sizeof(struct in_addr));
net_sin(myaddr)->sin_port = 0; /* let the IP stack to select */ net_sin(myaddr)->sin_port = 0; /* let the IP stack to select */

View file

@ -1208,7 +1208,8 @@ static void check_prefix(struct net_if *iface,
} }
if (last_prefix) { if (last_prefix) {
set_ip_from_prefix(&iface->link_addr, last_prefix, &addr); set_ip_from_prefix(net_if_get_link_addr(iface),
last_prefix, &addr);
if (net_if_ipv6_addr_rm(iface, &addr)) { if (net_if_ipv6_addr_rm(iface, &addr)) {
NET_DBG("Removed global IP address %s", NET_DBG("Removed global IP address %s",
@ -1217,7 +1218,8 @@ static void check_prefix(struct net_if *iface,
} }
if (new_prefix) { if (new_prefix) {
set_ip_from_prefix(&iface->link_addr, new_prefix, &addr); set_ip_from_prefix(net_if_get_link_addr(iface),
new_prefix, &addr);
if (net_if_ipv6_addr_add(iface, &addr, NET_ADDR_AUTOCONF, 0)) { if (net_if_ipv6_addr_add(iface, &addr, NET_ADDR_AUTOCONF, 0)) {
NET_DBG("Added global IP address %s", NET_DBG("Added global IP address %s",
@ -2177,9 +2179,10 @@ static void send_mcast_dao(struct net_rpl_instance *instance)
/* Send a DAO for own multicast addresses */ /* Send a DAO for own multicast addresses */
for (i = 0; i < NET_IF_MAX_IPV6_MADDR; i++) { for (i = 0; i < NET_IF_MAX_IPV6_MADDR; i++) {
addr = &instance->iface->ipv6.mcast[i].address.in6_addr; addr =
&instance->iface->config.ip.ipv6.mcast[i].address.in6_addr;
if (instance->iface->ipv6.mcast[i].is_used && if (instance->iface->config.ip.ipv6.mcast[i].is_used &&
net_is_ipv6_addr_mcast_global(addr)) { net_is_ipv6_addr_mcast_global(addr)) {
net_rpl_dao_send(instance->iface, net_rpl_dao_send(instance->iface,

View file

@ -576,11 +576,11 @@ u16_t net_tcp_get_recv_mss(const struct net_tcp *tcp)
#if defined(CONFIG_NET_IPV4) #if defined(CONFIG_NET_IPV4)
struct net_if *iface = net_context_get_iface(tcp->context); struct net_if *iface = net_context_get_iface(tcp->context);
if (iface && iface->mtu >= NET_IPV4TCPH_LEN) { if (iface && net_if_get_mtu(iface) >= NET_IPV4TCPH_LEN) {
/* Detect MSS based on interface MTU minus "TCP,IP /* Detect MSS based on interface MTU minus "TCP,IP
* header size" * header size"
*/ */
return iface->mtu - NET_IPV4TCPH_LEN; return net_if_get_mtu(iface) - NET_IPV4TCPH_LEN;
} }
#else #else
return 0; return 0;
@ -591,11 +591,11 @@ u16_t net_tcp_get_recv_mss(const struct net_tcp *tcp)
struct net_if *iface = net_context_get_iface(tcp->context); struct net_if *iface = net_context_get_iface(tcp->context);
int mss = 0; int mss = 0;
if (iface && iface->mtu >= NET_IPV6TCPH_LEN) { if (iface && net_if_get_mtu(iface) >= NET_IPV6TCPH_LEN) {
/* Detect MSS based on interface MTU minus "TCP,IP /* Detect MSS based on interface MTU minus "TCP,IP
* header size" * header size"
*/ */
mss = iface->mtu - NET_IPV6TCPH_LEN; mss = net_if_get_mtu(iface) - NET_IPV6TCPH_LEN;
} }
if (mss < NET_IPV6_MTU) { if (mss < NET_IPV6_MTU) {

View file

@ -638,7 +638,8 @@ static void check_local_address(struct net_app_ctx *ctx,
/* Just take the first IPv4 address of an interface */ /* Just take the first IPv4 address of an interface */
iface = net_context_get_iface(net_ctx); iface = net_context_get_iface(net_ctx);
if (iface) { if (iface) {
laddr = &iface->ipv4.unicast[0].address.in_addr; laddr =
&iface->config.ip.ipv4.unicast[0].address.in_addr;
net_ipaddr_copy(&net_sin(&ctx->ipv4.local)->sin_addr, net_ipaddr_copy(&net_sin(&ctx->ipv4.local)->sin_addr,
laddr); laddr);
} else { } else {

View file

@ -50,7 +50,8 @@ static void ipv4_addr_add_handler(struct net_mgmt_event_callback *cb,
} }
for (i = 0; i < NET_IF_MAX_IPV4_ADDR; i++) { for (i = 0; i < NET_IF_MAX_IPV4_ADDR; i++) {
struct net_if_addr *if_addr = &iface->ipv4.unicast[i]; struct net_if_addr *if_addr =
&iface->config.ip.ipv4.unicast[i];
if (if_addr->addr_type != NET_ADDR_DHCP || !if_addr->is_used) { if (if_addr->addr_type != NET_ADDR_DHCP || !if_addr->is_used) {
continue; continue;
@ -60,12 +61,13 @@ static void ipv4_addr_add_handler(struct net_mgmt_event_callback *cb,
NET_INFO("IPv4 address: %s", NET_INFO("IPv4 address: %s",
net_addr_ntop(AF_INET, &if_addr->address.in_addr, net_addr_ntop(AF_INET, &if_addr->address.in_addr,
hr_addr, NET_IPV4_ADDR_LEN)); hr_addr, NET_IPV4_ADDR_LEN));
NET_INFO("Lease time: %u seconds", iface->dhcpv4.lease_time); NET_INFO("Lease time: %u seconds",
iface->config.dhcpv4.lease_time);
NET_INFO("Subnet: %s", NET_INFO("Subnet: %s",
net_addr_ntop(AF_INET, &iface->ipv4.netmask, net_addr_ntop(AF_INET, &iface->config.ip.ipv4.netmask,
hr_addr, NET_IPV4_ADDR_LEN)); hr_addr, NET_IPV4_ADDR_LEN));
NET_INFO("Router: %s", NET_INFO("Router: %s",
net_addr_ntop(AF_INET, &iface->ipv4.gw, net_addr_ntop(AF_INET, &iface->config.ip.ipv4.gw,
hr_addr, NET_IPV4_ADDR_LEN)); hr_addr, NET_IPV4_ADDR_LEN));
#endif #endif
break; break;
@ -176,14 +178,17 @@ static struct in6_addr laddr;
static void ipv6_event_handler(struct net_mgmt_event_callback *cb, static void ipv6_event_handler(struct net_mgmt_event_callback *cb,
u32_t mgmt_event, struct net_if *iface) u32_t mgmt_event, struct net_if *iface)
{ {
struct net_if_config *config;
int i; int i;
config = net_if_config_get(iface);
if (mgmt_event == NET_EVENT_IPV6_ADDR_ADD) { if (mgmt_event == NET_EVENT_IPV6_ADDR_ADD) {
/* save the last added IP address for this interface */ /* save the last added IP address for this interface */
for (i = NET_IF_MAX_IPV6_ADDR - 1; i >= 0; i--) { for (i = NET_IF_MAX_IPV6_ADDR - 1; i >= 0; i--) {
if (iface->ipv6.unicast[i].is_used) { if (config->ip.ipv6.unicast[i].is_used) {
memcpy(&laddr, memcpy(&laddr,
&iface->ipv6.unicast[i].address.in6_addr, &config->ip.ipv6.unicast[i].address.in6_addr,
sizeof(laddr)); sizeof(laddr));
} }
} }

View file

@ -310,7 +310,7 @@ int _net_app_set_local_addr(struct sockaddr *addr, const char *myaddr,
/* For IPv4 we take the first address in the interface */ /* For IPv4 we take the first address in the interface */
net_ipaddr_copy(&net_sin(addr)->sin_addr, net_ipaddr_copy(&net_sin(addr)->sin_addr,
&iface->ipv4.unicast[0].address.in_addr); &iface->config.ip.ipv4.unicast[0].address.in_addr);
#else #else
return -EPFNOSUPPORT; return -EPFNOSUPPORT;
#endif #endif

View file

@ -109,7 +109,8 @@ static int sender_iface(struct net_if *iface, struct net_pkt *pkt)
} }
if (test_started) { if (test_started) {
struct net_if_test *data = iface->dev->driver_data; struct net_if_test *data =
net_if_get_device(iface)->driver_data;
DBG("Sending at iface %d %p\n", net_if_get_by_iface(iface), DBG("Sending at iface %d %p\n", net_if_get_by_iface(iface),
iface); iface);
@ -169,7 +170,7 @@ static void iface_setup(void)
iface1 = net_if_get_by_index(0); iface1 = net_if_get_by_index(0);
((struct net_if_test *)iface1->dev->driver_data)->idx = 0; ((struct net_if_test *)net_if_get_device(iface1)->driver_data)->idx = 0;
idx = net_if_get_by_iface(iface1); idx = net_if_get_by_iface(iface1);
zassert_equal(idx, 0, "Invalid index iface1"); zassert_equal(idx, 0, "Invalid index iface1");

View file

@ -151,10 +151,13 @@ static inline struct in_addr *if_get_addr(struct net_if *iface)
int i; int i;
for (i = 0; i < NET_IF_MAX_IPV4_ADDR; i++) { for (i = 0; i < NET_IF_MAX_IPV4_ADDR; i++) {
if (iface->ipv4.unicast[i].is_used && if (iface->config.ip.ipv4.unicast[i].is_used &&
iface->ipv4.unicast[i].address.family == AF_INET && iface->config.ip.ipv4.unicast[i].address.family ==
iface->ipv4.unicast[i].addr_state == NET_ADDR_PREFERRED) { AF_INET &&
return &iface->ipv4.unicast[i].address.in_addr; iface->config.ip.ipv4.unicast[i].addr_state ==
NET_ADDR_PREFERRED) {
return
&iface->config.ip.ipv4.unicast[i].address.in_addr;
} }
} }
@ -408,11 +411,11 @@ void run_tests(void)
} }
if (memcmp(net_pkt_ll(pkt2) + sizeof(struct net_eth_addr), if (memcmp(net_pkt_ll(pkt2) + sizeof(struct net_eth_addr),
iface->link_addr.addr, net_if_get_link_addr(iface)->addr,
sizeof(struct net_eth_addr))) { sizeof(struct net_eth_addr))) {
printk("ARP ETH source address invalid\n"); printk("ARP ETH source address invalid\n");
net_hexdump("ETH src correct", net_hexdump("ETH src correct",
iface->link_addr.addr, net_if_get_link_addr(iface)->addr,
sizeof(struct net_eth_addr)); sizeof(struct net_eth_addr));
net_hexdump("ETH src wrong ", net_hexdump("ETH src wrong ",
net_pkt_ll(pkt2) + sizeof(struct net_eth_addr), net_pkt_ll(pkt2) + sizeof(struct net_eth_addr),
@ -503,13 +506,14 @@ void run_tests(void)
arp_hdr = NET_ARP_HDR(pkt2); arp_hdr = NET_ARP_HDR(pkt2);
if (!net_ipv4_addr_cmp(&arp_hdr->dst_ipaddr, &iface->ipv4.gw)) { if (!net_ipv4_addr_cmp(&arp_hdr->dst_ipaddr,
&iface->config.ip.ipv4.gw)) {
char out[sizeof("xxx.xxx.xxx.xxx")]; char out[sizeof("xxx.xxx.xxx.xxx")];
snprintk(out, sizeof(out), "%s", snprintk(out, sizeof(out), "%s",
net_sprint_ipv4_addr(&arp_hdr->dst_ipaddr)); net_sprint_ipv4_addr(&arp_hdr->dst_ipaddr));
printk("ARP IP dst invalid %s, should be %s\n", out, printk("ARP IP dst invalid %s, should be %s\n", out,
net_sprint_ipv4_addr(&iface->ipv4.gw)); net_sprint_ipv4_addr(&iface->config.ip.ipv4.gw));
zassert_true(0, "exiting"); zassert_true(0, "exiting");
} }

View file

@ -269,13 +269,13 @@ struct user_data {
static const char *iface2str(struct net_if *iface) static const char *iface2str(struct net_if *iface)
{ {
#ifdef CONFIG_NET_L2_ETHERNET #ifdef CONFIG_NET_L2_ETHERNET
if (iface->l2 == &NET_L2_GET_NAME(ETHERNET)) { if (net_if_l2(iface) == &NET_L2_GET_NAME(ETHERNET)) {
return "Ethernet"; return "Ethernet";
} }
#endif #endif
#ifdef CONFIG_NET_L2_DUMMY #ifdef CONFIG_NET_L2_DUMMY
if (iface->l2 == &NET_L2_GET_NAME(DUMMY)) { if (net_if_l2(iface) == &NET_L2_GET_NAME(DUMMY)) {
return "Dummy"; return "Dummy";
} }
#endif #endif
@ -291,7 +291,7 @@ static void iface_cb(struct net_if *iface, void *user_data)
DBG("Interface %p (%s) [%d]\n", iface, iface2str(iface), DBG("Interface %p (%s) [%d]\n", iface, iface2str(iface),
net_if_get_by_iface(iface)); net_if_get_by_iface(iface));
if (iface->l2 == &NET_L2_GET_NAME(ETHERNET)) { if (net_if_l2(iface) == &NET_L2_GET_NAME(ETHERNET)) {
struct eth_context *eth_ctx = struct eth_context *eth_ctx =
net_if_get_device(iface)->driver_data; net_if_get_device(iface)->driver_data;

View file

@ -284,7 +284,7 @@ static bool initialize_test_environment(void)
NET_INFO("Fake IEEE 802.15.4 network interface ready\n"); NET_INFO("Fake IEEE 802.15.4 network interface ready\n");
ieee_addr_hexdump(iface->link_addr.addr, 8); ieee_addr_hexdump(net_if_get_link_addr(iface)->addr, 8);
return true; return true;
} }

View file

@ -107,7 +107,8 @@ static int sender_iface(struct net_if *iface, struct net_pkt *pkt)
} }
if (test_started) { if (test_started) {
struct net_if_test *data = iface->dev->driver_data; struct net_if_test *data =
net_if_get_device(iface)->driver_data;
DBG("Sending at iface %d %p\n", net_if_get_by_iface(iface), DBG("Sending at iface %d %p\n", net_if_get_by_iface(iface),
iface); iface);
@ -193,9 +194,9 @@ static void iface_setup(void)
iface2 = net_if_get_by_index(1); iface2 = net_if_get_by_index(1);
iface3 = net_if_get_by_index(2); iface3 = net_if_get_by_index(2);
((struct net_if_test *)iface1->dev->driver_data)->idx = 0; ((struct net_if_test *)net_if_get_device(iface1)->driver_data)->idx = 0;
((struct net_if_test *)iface2->dev->driver_data)->idx = 1; ((struct net_if_test *)net_if_get_device(iface2)->driver_data)->idx = 1;
((struct net_if_test *)iface3->dev->driver_data)->idx = 2; ((struct net_if_test *)net_if_get_device(iface3)->driver_data)->idx = 2;
idx = net_if_get_by_iface(iface1); idx = net_if_get_by_iface(iface1);
zassert_equal(idx, 0, "Invalid index iface1"); zassert_equal(idx, 0, "Invalid index iface1");

View file

@ -258,11 +258,11 @@ static bool test_init(void)
* pass. * pass.
*/ */
for (i = 0; i < NET_IF_MAX_IPV6_ADDR; i++) { for (i = 0; i < NET_IF_MAX_IPV6_ADDR; i++) {
if (iface->ipv6.unicast[i].is_used) { if (iface->config.ip.ipv6.unicast[i].is_used) {
continue; continue;
} }
ifaddr = &iface->ipv6.unicast[i]; ifaddr = &iface->config.ip.ipv6.unicast[i];
ifaddr->is_used = true; ifaddr->is_used = true;
ifaddr->address.family = AF_INET6; ifaddr->address.family = AF_INET6;

View file

@ -329,7 +329,8 @@ static int sender_iface(struct net_if *iface, struct net_pkt *pkt)
} }
if (test_started) { if (test_started) {
struct net_if_test *data = iface->dev->driver_data; struct net_if_test *data =
net_if_get_device(iface)->driver_data;
DBG("Sending at iface %d %p\n", net_if_get_by_iface(iface), DBG("Sending at iface %d %p\n", net_if_get_by_iface(iface),
iface); iface);
@ -452,8 +453,8 @@ static void setup(void)
iface1 = net_if_get_by_index(0); iface1 = net_if_get_by_index(0);
iface2 = net_if_get_by_index(1); iface2 = net_if_get_by_index(1);
((struct net_if_test *)iface1->dev->driver_data)->idx = 0; ((struct net_if_test *)net_if_get_device(iface1)->driver_data)->idx = 0;
((struct net_if_test *)iface2->dev->driver_data)->idx = 1; ((struct net_if_test *)net_if_get_device(iface2)->driver_data)->idx = 1;
idx = net_if_get_by_iface(iface1); idx = net_if_get_by_iface(iface1);
zassert_equal(idx, 0, "Invalid index iface1"); zassert_equal(idx, 0, "Invalid index iface1");

View file

@ -127,7 +127,8 @@ static int sender_iface(struct net_if *iface, struct net_pkt *pkt)
} }
if (!timeout_query) { if (!timeout_query) {
struct net_if_test *data = iface->dev->driver_data; struct net_if_test *data =
net_if_get_device(iface)->driver_data;
struct dns_resolve_context *ctx; struct dns_resolve_context *ctx;
int slot; int slot;
@ -211,7 +212,7 @@ static void test_init(void)
iface1 = net_if_get_by_index(0); iface1 = net_if_get_by_index(0);
((struct net_if_test *)iface1->dev->driver_data)->idx = 0; ((struct net_if_test *)net_if_get_device(iface1)->driver_data)->idx = 0;
#if defined(CONFIG_NET_IPV6) #if defined(CONFIG_NET_IPV6)
ifaddr = net_if_ipv6_addr_add(iface1, &my_addr1, ifaddr = net_if_ipv6_addr_add(iface1, &my_addr1,

View file

@ -129,7 +129,7 @@ static int tester_send(struct net_if *iface, struct net_pkt *pkt)
return -ENODATA; return -ENODATA;
} }
set_pkt_ll_addr(iface->dev, pkt); set_pkt_ll_addr(net_if_get_device(iface), pkt);
/* By default we assume that the test is ok */ /* By default we assume that the test is ok */
data_failure = false; data_failure = false;
@ -300,7 +300,7 @@ static void test_dio_dummy_input(void)
msg_sending = NET_RPL_DODAG_INFO_OBJ; msg_sending = NET_RPL_DODAG_INFO_OBJ;
set_pkt_ll_addr(net_if_get_default()->dev, pkt); set_pkt_ll_addr(net_if_get_device(net_if_get_default()), pkt);
ret = net_icmpv6_input(pkt, NET_ICMPV6_RPL, msg_sending); ret = net_icmpv6_input(pkt, NET_ICMPV6_RPL, msg_sending);
if (!ret) { if (!ret) {
@ -393,7 +393,7 @@ static bool net_test_send_ns(void)
*/ */
nbr = net_ipv6_nbr_add(iface, nbr = net_ipv6_nbr_add(iface,
&in6addr_my, &in6addr_my,
&iface->link_addr, net_if_get_link_addr(iface),
false, false,
NET_IPV6_NBR_STATE_REACHABLE); NET_IPV6_NBR_STATE_REACHABLE);
if (!nbr) { if (!nbr) {

View file

@ -196,10 +196,13 @@ static inline struct in_addr *if_get_addr(struct net_if *iface)
int i; int i;
for (i = 0; i < NET_IF_MAX_IPV4_ADDR; i++) { for (i = 0; i < NET_IF_MAX_IPV4_ADDR; i++) {
if (iface->ipv4.unicast[i].is_used && if (iface->config.ip.ipv4.unicast[i].is_used &&
iface->ipv4.unicast[i].address.family == AF_INET && iface->config.ip.ipv4.unicast[i].address.family ==
iface->ipv4.unicast[i].addr_state == NET_ADDR_PREFERRED) { AF_INET &&
return &iface->ipv4.unicast[i].address.in_addr; iface->config.ip.ipv4.unicast[i].addr_state ==
NET_ADDR_PREFERRED) {
return
&iface->config.ip.ipv4.unicast[i].address.in_addr;
} }
} }

View file

@ -106,10 +106,13 @@ static inline struct in_addr *if_get_addr(struct net_if *iface)
int i; int i;
for (i = 0; i < NET_IF_MAX_IPV4_ADDR; i++) { for (i = 0; i < NET_IF_MAX_IPV4_ADDR; i++) {
if (iface->ipv4.unicast[i].is_used && if (iface->config.ip.ipv4.unicast[i].is_used &&
iface->ipv4.unicast[i].address.family == AF_INET && iface->config.ip.ipv4.unicast[i].address.family ==
iface->ipv4.unicast[i].addr_state == NET_ADDR_PREFERRED) { AF_INET &&
return &iface->ipv4.unicast[i].address.in_addr; iface->config.ip.ipv4.unicast[i].addr_state ==
NET_ADDR_PREFERRED) {
return
&iface->config.ip.ipv4.unicast[i].address.in_addr;
} }
} }