net: Use section foreach macros
Use system provided Z_STRUCT_SECTION_FOREACH() and Z_STRUCT_SECTION_ITERABLE() macros instead of manually coding everything for network sections. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
parent
83ee9a8676
commit
62580748e5
9 changed files with 106 additions and 198 deletions
|
@ -99,29 +99,11 @@
|
|||
KEEP(*(SORT_BY_NAME("._net_buf_pool.static.*")))
|
||||
} GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
|
||||
|
||||
SECTION_DATA_PROLOGUE(net_if,,SUBALIGN(4))
|
||||
{
|
||||
__net_if_start = .;
|
||||
*(".net_if.*")
|
||||
KEEP(*(SORT_BY_NAME(".net_if.*")))
|
||||
__net_if_end = .;
|
||||
} GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
|
||||
|
||||
SECTION_DATA_PROLOGUE(net_if_dev,,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_l2_data,,SUBALIGN(4))
|
||||
{
|
||||
__net_l2_data_start = .;
|
||||
*(".net_l2.data")
|
||||
KEEP(*(SORT_BY_NAME(".net_l2.data*")))
|
||||
__net_l2_data_end = .;
|
||||
} GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
|
||||
#if defined(CONFIG_NETWORKING)
|
||||
Z_ITERABLE_SECTION_RAM(net_if, 4)
|
||||
Z_ITERABLE_SECTION_RAM(net_if_dev, 4)
|
||||
Z_ITERABLE_SECTION_RAM(net_l2, 4)
|
||||
#endif /* NETWORKING */
|
||||
|
||||
#if defined(CONFIG_UART_MUX)
|
||||
SECTION_DATA_PROLOGUE(uart_mux,,SUBALIGN(4))
|
||||
|
|
|
@ -86,26 +86,12 @@
|
|||
__app_shmem_regions_end = .;
|
||||
} GROUP_LINK_IN(ROMABLE_REGION)
|
||||
|
||||
SECTION_PROLOGUE(net_l2,,)
|
||||
{
|
||||
__net_l2_start = .;
|
||||
*(".net_l2.init")
|
||||
KEEP(*(SORT_BY_NAME(".net_l2.init*")))
|
||||
__net_l2_end = .;
|
||||
} GROUP_LINK_IN(ROMABLE_REGION)
|
||||
|
||||
#if defined(CONFIG_NET_SOCKETS)
|
||||
Z_ITERABLE_SECTION_ROM(net_socket_register, 4)
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_NET_L2_PPP)
|
||||
SECTION_PROLOGUE(net_ppp_proto,,)
|
||||
{
|
||||
__net_ppp_proto_start = .;
|
||||
*(".net_ppp_proto.*")
|
||||
KEEP(*(SORT_BY_NAME(".net_ppp_proto.*")))
|
||||
__net_ppp_proto_end = .;
|
||||
} GROUP_LINK_IN(ROMABLE_REGION)
|
||||
Z_ITERABLE_SECTION_ROM(ppp_protocol_handler, 4)
|
||||
#endif
|
||||
|
||||
Z_ITERABLE_SECTION_ROM(bt_l2cap_fixed_chan, 4)
|
||||
|
|
|
@ -2179,23 +2179,23 @@ struct net_if_api {
|
|||
NET_IF_DHCPV4_INIT \
|
||||
}
|
||||
|
||||
#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_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_GET(dev_name, sfx) \
|
||||
((struct net_if *)&NET_IF_GET_NAME(dev_name, sfx))
|
||||
|
||||
#define NET_IF_INIT(dev_name, sfx, _l2, _mtu, _num_configs) \
|
||||
static struct net_if_dev (NET_IF_DEV_GET_NAME(dev_name, sfx)) \
|
||||
__used __attribute__((__section__(".net_if_dev.data"))) = { \
|
||||
static Z_STRUCT_SECTION_ITERABLE(net_if_dev, \
|
||||
NET_IF_DEV_GET_NAME(dev_name, sfx)) = { \
|
||||
.dev = &(DEVICE_NAME_GET(dev_name)), \
|
||||
.l2 = &(NET_L2_GET_NAME(_l2)), \
|
||||
.l2_data = &(NET_L2_GET_DATA(dev_name, sfx)), \
|
||||
.mtu = _mtu, \
|
||||
}; \
|
||||
static struct net_if \
|
||||
(NET_IF_GET_NAME(dev_name, sfx))[_num_configs] __used \
|
||||
__attribute__((__section__(".net_if.data"))) = { \
|
||||
static Z_DECL_ALIGN(struct net_if) \
|
||||
NET_IF_GET_NAME(dev_name, sfx)[_num_configs] \
|
||||
__used __in_section(_net_if, static, net_if) = { \
|
||||
[0 ... (_num_configs - 1)] = { \
|
||||
.if_dev = &(NET_IF_DEV_GET_NAME(dev_name, sfx)), \
|
||||
NET_IF_CONFIG_INIT \
|
||||
|
|
|
@ -77,7 +77,7 @@ struct net_l2 {
|
|||
};
|
||||
|
||||
/** @cond INTERNAL_HIDDEN */
|
||||
#define NET_L2_GET_NAME(_name) __net_l2_##_name
|
||||
#define NET_L2_GET_NAME(_name) _net_l2_##_name
|
||||
#define NET_L2_DECLARE_PUBLIC(_name) \
|
||||
extern const struct net_l2 NET_L2_GET_NAME(_name)
|
||||
#define NET_L2_GET_CTX_TYPE(_name) _name##_CTX_TYPE
|
||||
|
@ -126,19 +126,18 @@ NET_L2_DECLARE_PUBLIC(CANBUS_L2);
|
|||
#endif /* CONFIG_NET_L2_CANBUS */
|
||||
|
||||
#define NET_L2_INIT(_name, _recv_fn, _send_fn, _enable_fn, _get_flags_fn) \
|
||||
const struct net_l2 (NET_L2_GET_NAME(_name)) __used \
|
||||
__attribute__((__section__(".net_l2.init"))) = { \
|
||||
const Z_STRUCT_SECTION_ITERABLE(net_l2, \
|
||||
NET_L2_GET_NAME(_name)) = { \
|
||||
.recv = (_recv_fn), \
|
||||
.send = (_send_fn), \
|
||||
.enable = (_enable_fn), \
|
||||
.get_flags = (_get_flags_fn), \
|
||||
}
|
||||
|
||||
#define NET_L2_GET_DATA(name, sfx) (__net_l2_data_##name##sfx)
|
||||
#define NET_L2_GET_DATA(name, sfx) _net_l2_data_##name##sfx
|
||||
|
||||
#define NET_L2_DATA_INIT(name, sfx, ctx_type) \
|
||||
static ctx_type NET_L2_GET_DATA(name, sfx) __used \
|
||||
__attribute__((__section__(".net_l2.data")));
|
||||
static ctx_type NET_L2_GET_DATA(name, sfx) __used;
|
||||
|
||||
/** @endcond */
|
||||
|
||||
|
|
|
@ -37,11 +37,8 @@ LOG_MODULE_REGISTER(net_if, CONFIG_NET_IF_LOG_LEVEL);
|
|||
#define MAX_RANDOM_DENOM (2)
|
||||
|
||||
/* net_if dedicated section limiters */
|
||||
extern struct net_if __net_if_start[];
|
||||
extern struct net_if __net_if_end[];
|
||||
|
||||
extern struct net_if_dev __net_if_dev_start[];
|
||||
extern struct net_if_dev __net_if_dev_end[];
|
||||
extern struct net_if _net_if_list_start[];
|
||||
extern struct net_if _net_if_list_end[];
|
||||
|
||||
#if defined(CONFIG_NET_NATIVE_IPV4) || defined(CONFIG_NET_NATIVE_IPV6)
|
||||
static struct net_if_router routers[CONFIG_NET_MAX_ROUTERS];
|
||||
|
@ -305,9 +302,7 @@ void net_if_queue_tx(struct net_if *iface, struct net_pkt *pkt)
|
|||
void net_if_stats_reset(struct net_if *iface)
|
||||
{
|
||||
#if defined(CONFIG_NET_STATISTICS_PER_INTERFACE)
|
||||
struct net_if *tmp;
|
||||
|
||||
for (tmp = __net_if_start; tmp != __net_if_end; tmp++) {
|
||||
Z_STRUCT_SECTION_FOREACH(net_if, tmp) {
|
||||
if (iface == tmp) {
|
||||
memset(&iface->stats, 0, sizeof(iface->stats));
|
||||
return;
|
||||
|
@ -319,9 +314,8 @@ void net_if_stats_reset(struct net_if *iface)
|
|||
void net_if_stats_reset_all(void)
|
||||
{
|
||||
#if defined(CONFIG_NET_STATISTICS_PER_INTERFACE)
|
||||
struct net_if *iface;
|
||||
|
||||
for (iface = __net_if_start; iface != __net_if_end; iface++) {
|
||||
Z_STRUCT_SECTION_FOREACH(net_if, iface) {
|
||||
memset(&iface->stats, 0, sizeof(iface->stats));
|
||||
}
|
||||
#endif
|
||||
|
@ -422,9 +416,7 @@ done:
|
|||
|
||||
struct net_if *net_if_get_by_link_addr(struct net_linkaddr *ll_addr)
|
||||
{
|
||||
struct net_if *iface;
|
||||
|
||||
for (iface = __net_if_start; iface != __net_if_end; iface++) {
|
||||
Z_STRUCT_SECTION_FOREACH(net_if, iface) {
|
||||
if (!memcmp(net_if_get_link_addr(iface)->addr, ll_addr->addr,
|
||||
ll_addr->len)) {
|
||||
return iface;
|
||||
|
@ -436,9 +428,7 @@ 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 *iface;
|
||||
|
||||
for (iface = __net_if_start; iface != __net_if_end; iface++) {
|
||||
Z_STRUCT_SECTION_FOREACH(net_if, iface) {
|
||||
if (net_if_get_device(iface) == dev) {
|
||||
return iface;
|
||||
}
|
||||
|
@ -451,7 +441,7 @@ struct net_if *net_if_get_default(void)
|
|||
{
|
||||
struct net_if *iface = NULL;
|
||||
|
||||
if (__net_if_start == __net_if_end) {
|
||||
if (_net_if_list_start == _net_if_list_end) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -480,14 +470,12 @@ struct net_if *net_if_get_default(void)
|
|||
iface = net_if_get_first_by_type(&NET_L2_GET_NAME(PPP));
|
||||
#endif
|
||||
|
||||
return iface ? iface : __net_if_start;
|
||||
return iface ? iface : _net_if_list_start;
|
||||
}
|
||||
|
||||
struct net_if *net_if_get_first_by_type(const struct net_l2 *l2)
|
||||
{
|
||||
struct net_if *iface;
|
||||
|
||||
for (iface = __net_if_start; iface != __net_if_end; iface++) {
|
||||
Z_STRUCT_SECTION_FOREACH(net_if, iface) {
|
||||
if (IS_ENABLED(CONFIG_NET_OFFLOAD) &&
|
||||
!l2 && net_if_offload(iface)) {
|
||||
return iface;
|
||||
|
@ -1067,7 +1055,7 @@ static void rs_timeout(struct k_work *work)
|
|||
|
||||
SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&active_rs_timers,
|
||||
ipv6, next, rs_node) {
|
||||
struct net_if *iface;
|
||||
struct net_if *iface = NULL;
|
||||
|
||||
if ((int32_t)(ipv6->rs_start + RS_TIMEOUT - current_time) > 0) {
|
||||
break;
|
||||
|
@ -1079,13 +1067,14 @@ static void rs_timeout(struct k_work *work)
|
|||
/* Did not receive RA yet. */
|
||||
ipv6->rs_count++;
|
||||
|
||||
for (iface = __net_if_start; iface != __net_if_end; iface++) {
|
||||
if (iface->config.ip.ipv6 == ipv6) {
|
||||
Z_STRUCT_SECTION_FOREACH(net_if, tmp) {
|
||||
if (tmp->config.ip.ipv6 == ipv6) {
|
||||
iface = tmp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (iface != __net_if_end) {
|
||||
if (!iface) {
|
||||
NET_DBG("RS no respond iface %p count %d",
|
||||
iface, ipv6->rs_count);
|
||||
if (ipv6->rs_count < RS_COUNT) {
|
||||
|
@ -1153,9 +1142,7 @@ static inline void iface_ipv6_nd_init(void)
|
|||
struct net_if_addr *net_if_ipv6_addr_lookup(const struct in6_addr *addr,
|
||||
struct net_if **ret)
|
||||
{
|
||||
struct net_if *iface;
|
||||
|
||||
for (iface = __net_if_start; iface != __net_if_end; iface++) {
|
||||
Z_STRUCT_SECTION_FOREACH(net_if, iface) {
|
||||
struct net_if_ipv6 *ipv6 = iface->config.ip.ipv6;
|
||||
int i;
|
||||
|
||||
|
@ -1701,9 +1688,7 @@ bool net_if_ipv6_maddr_rm(struct net_if *iface, const struct in6_addr *addr)
|
|||
struct net_if_mcast_addr *net_if_ipv6_maddr_lookup(const struct in6_addr *maddr,
|
||||
struct net_if **ret)
|
||||
{
|
||||
struct net_if *iface;
|
||||
|
||||
for (iface = __net_if_start; iface != __net_if_end; iface++) {
|
||||
Z_STRUCT_SECTION_FOREACH(net_if, iface) {
|
||||
struct net_if_ipv6 *ipv6 = iface->config.ip.ipv6;
|
||||
int i;
|
||||
|
||||
|
@ -2121,9 +2106,7 @@ struct net_if_ipv6_prefix *net_if_ipv6_prefix_lookup(struct net_if *iface,
|
|||
|
||||
bool net_if_ipv6_addr_onlink(struct net_if **iface, struct in6_addr *addr)
|
||||
{
|
||||
struct net_if *tmp;
|
||||
|
||||
for (tmp = __net_if_start; tmp != __net_if_end; tmp++) {
|
||||
Z_STRUCT_SECTION_FOREACH(net_if, tmp) {
|
||||
struct net_if_ipv6 *ipv6 = tmp->config.ip.ipv6;
|
||||
int i;
|
||||
|
||||
|
@ -2240,9 +2223,7 @@ struct in6_addr *net_if_ipv6_get_ll(struct net_if *iface,
|
|||
struct in6_addr *net_if_ipv6_get_ll_addr(enum net_addr_state state,
|
||||
struct net_if **iface)
|
||||
{
|
||||
struct net_if *tmp;
|
||||
|
||||
for (tmp = __net_if_start; tmp != __net_if_end; tmp++) {
|
||||
Z_STRUCT_SECTION_FOREACH(net_if, tmp) {
|
||||
struct in6_addr *addr;
|
||||
|
||||
addr = net_if_ipv6_get_ll(tmp, state);
|
||||
|
@ -2286,9 +2267,7 @@ static inline struct in6_addr *check_global_addr(struct net_if *iface,
|
|||
struct in6_addr *net_if_ipv6_get_global_addr(enum net_addr_state state,
|
||||
struct net_if **iface)
|
||||
{
|
||||
struct net_if *tmp;
|
||||
|
||||
for (tmp = __net_if_start; tmp != __net_if_end; tmp++) {
|
||||
Z_STRUCT_SECTION_FOREACH(net_if, tmp) {
|
||||
struct in6_addr *addr;
|
||||
|
||||
if (iface && *iface && tmp != *iface) {
|
||||
|
@ -2366,43 +2345,40 @@ const struct in6_addr *net_if_ipv6_select_src_addr(struct net_if *dst_iface,
|
|||
{
|
||||
struct in6_addr *src = NULL;
|
||||
uint8_t best_match = 0U;
|
||||
struct net_if *iface;
|
||||
|
||||
if (!net_ipv6_is_ll_addr(dst) && (!net_ipv6_is_addr_mcast(dst) ||
|
||||
net_ipv6_is_addr_mcast_mesh(dst))) {
|
||||
for (iface = __net_if_start;
|
||||
!dst_iface && iface != __net_if_end;
|
||||
iface++) {
|
||||
struct in6_addr *addr;
|
||||
|
||||
addr = net_if_ipv6_get_best_match(iface, dst,
|
||||
&best_match);
|
||||
if (addr) {
|
||||
src = addr;
|
||||
}
|
||||
}
|
||||
|
||||
/* If caller has supplied interface, then use that */
|
||||
if (dst_iface) {
|
||||
src = net_if_ipv6_get_best_match(dst_iface, dst,
|
||||
&best_match);
|
||||
}
|
||||
} else {
|
||||
Z_STRUCT_SECTION_FOREACH(net_if, iface) {
|
||||
struct in6_addr *addr;
|
||||
|
||||
} else {
|
||||
for (iface = __net_if_start;
|
||||
!dst_iface && iface != __net_if_end;
|
||||
iface++) {
|
||||
struct in6_addr *addr;
|
||||
|
||||
addr = net_if_ipv6_get_ll(iface, NET_ADDR_PREFERRED);
|
||||
if (addr) {
|
||||
src = addr;
|
||||
break;
|
||||
addr = net_if_ipv6_get_best_match(iface, dst,
|
||||
&best_match);
|
||||
if (addr) {
|
||||
src = addr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
if (dst_iface) {
|
||||
src = net_if_ipv6_get_ll(dst_iface, NET_ADDR_PREFERRED);
|
||||
} else {
|
||||
Z_STRUCT_SECTION_FOREACH(net_if, iface) {
|
||||
struct in6_addr *addr;
|
||||
|
||||
addr = net_if_ipv6_get_ll(iface,
|
||||
NET_ADDR_PREFERRED);
|
||||
if (addr) {
|
||||
src = addr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2656,7 +2632,7 @@ bool net_if_ipv4_is_addr_bcast(struct net_if *iface,
|
|||
return ipv4_is_broadcast_address(iface, addr);
|
||||
}
|
||||
|
||||
for (iface = __net_if_start; iface != __net_if_end; iface++) {
|
||||
Z_STRUCT_SECTION_FOREACH(net_if, iface) {
|
||||
bool ret;
|
||||
|
||||
ret = ipv4_is_broadcast_address(iface, addr);
|
||||
|
@ -2670,9 +2646,7 @@ bool net_if_ipv4_is_addr_bcast(struct net_if *iface,
|
|||
|
||||
struct net_if *net_if_ipv4_select_src_iface(const struct in_addr *dst)
|
||||
{
|
||||
struct net_if *iface;
|
||||
|
||||
for (iface = __net_if_start; iface != __net_if_end; iface++) {
|
||||
Z_STRUCT_SECTION_FOREACH(net_if, iface) {
|
||||
bool ret;
|
||||
|
||||
ret = net_if_ipv4_addr_mask_cmp(iface, dst);
|
||||
|
@ -2785,43 +2759,39 @@ const struct in_addr *net_if_ipv4_select_src_addr(struct net_if *dst_iface,
|
|||
{
|
||||
struct in_addr *src = NULL;
|
||||
uint8_t best_match = 0U;
|
||||
struct net_if *iface;
|
||||
|
||||
if (!net_ipv4_is_ll_addr(dst) && !net_ipv4_is_addr_mcast(dst)) {
|
||||
|
||||
for (iface = __net_if_start;
|
||||
!dst_iface && iface != __net_if_end;
|
||||
iface++) {
|
||||
struct in_addr *addr;
|
||||
|
||||
addr = net_if_ipv4_get_best_match(iface, dst,
|
||||
&best_match);
|
||||
if (addr) {
|
||||
src = addr;
|
||||
}
|
||||
}
|
||||
|
||||
/* If caller has supplied interface, then use that */
|
||||
if (dst_iface) {
|
||||
src = net_if_ipv4_get_best_match(dst_iface, dst,
|
||||
&best_match);
|
||||
}
|
||||
} else {
|
||||
Z_STRUCT_SECTION_FOREACH(net_if, iface) {
|
||||
struct in_addr *addr;
|
||||
|
||||
} else {
|
||||
for (iface = __net_if_start;
|
||||
!dst_iface && iface != __net_if_end;
|
||||
iface++) {
|
||||
struct in_addr *addr;
|
||||
|
||||
addr = net_if_ipv4_get_ll(iface, NET_ADDR_PREFERRED);
|
||||
if (addr) {
|
||||
src = addr;
|
||||
break;
|
||||
addr = net_if_ipv4_get_best_match(iface, dst,
|
||||
&best_match);
|
||||
if (addr) {
|
||||
src = addr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
if (dst_iface) {
|
||||
src = net_if_ipv4_get_ll(dst_iface, NET_ADDR_PREFERRED);
|
||||
} else {
|
||||
Z_STRUCT_SECTION_FOREACH(net_if, iface) {
|
||||
struct in_addr *addr;
|
||||
|
||||
addr = net_if_ipv4_get_ll(iface,
|
||||
NET_ADDR_PREFERRED);
|
||||
if (addr) {
|
||||
src = addr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2841,9 +2811,7 @@ const struct in_addr *net_if_ipv4_select_src_addr(struct net_if *dst_iface,
|
|||
struct net_if_addr *net_if_ipv4_addr_lookup(const struct in_addr *addr,
|
||||
struct net_if **ret)
|
||||
{
|
||||
struct net_if *iface;
|
||||
|
||||
for (iface = __net_if_start; iface != __net_if_end; iface++) {
|
||||
Z_STRUCT_SECTION_FOREACH(net_if, iface) {
|
||||
struct net_if_ipv4 *ipv4 = iface->config.ip.ipv4;
|
||||
int i;
|
||||
|
||||
|
@ -3260,9 +3228,8 @@ struct net_if_mcast_addr *net_if_ipv4_maddr_lookup(const struct in_addr *maddr,
|
|||
struct net_if **ret)
|
||||
{
|
||||
struct net_if_mcast_addr *addr;
|
||||
struct net_if *iface;
|
||||
|
||||
for (iface = __net_if_start; iface != __net_if_end; iface++) {
|
||||
Z_STRUCT_SECTION_FOREACH(net_if, iface) {
|
||||
if (ret && *ret && iface != *ret) {
|
||||
continue;
|
||||
}
|
||||
|
@ -3456,28 +3423,26 @@ struct net_if *net_if_get_by_index(int index)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (&__net_if_start[index - 1] >= __net_if_end) {
|
||||
if (&_net_if_list_start[index - 1] >= _net_if_list_end) {
|
||||
NET_DBG("Index %d is too large", index);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &__net_if_start[index - 1];
|
||||
return &_net_if_list_start[index - 1];
|
||||
}
|
||||
|
||||
int net_if_get_by_iface(struct net_if *iface)
|
||||
{
|
||||
if (!(iface >= __net_if_start && iface < __net_if_end)) {
|
||||
if (!(iface >= _net_if_list_start && iface < _net_if_list_end)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return (iface - __net_if_start) + 1;
|
||||
return (iface - _net_if_list_start) + 1;
|
||||
}
|
||||
|
||||
void net_if_foreach(net_if_cb_t cb, void *user_data)
|
||||
{
|
||||
struct net_if *iface;
|
||||
|
||||
for (iface = __net_if_start; iface != __net_if_end; iface++) {
|
||||
Z_STRUCT_SECTION_FOREACH(net_if, iface) {
|
||||
cb(iface, user_data);
|
||||
}
|
||||
}
|
||||
|
@ -3732,19 +3697,18 @@ void net_if_add_tx_timestamp(struct net_pkt *pkt)
|
|||
|
||||
void net_if_init(void)
|
||||
{
|
||||
struct net_if *iface;
|
||||
int if_count;
|
||||
int if_count = 0;
|
||||
|
||||
NET_DBG("");
|
||||
|
||||
net_tc_tx_init();
|
||||
|
||||
for (iface = __net_if_start, if_count = 0; iface != __net_if_end;
|
||||
iface++, if_count++) {
|
||||
Z_STRUCT_SECTION_FOREACH(net_if, iface) {
|
||||
init_iface(iface);
|
||||
if_count++;
|
||||
}
|
||||
|
||||
if (iface == __net_if_start) {
|
||||
if (if_count == 0) {
|
||||
NET_ERR("There is no network interface to work with!");
|
||||
return;
|
||||
}
|
||||
|
@ -3765,8 +3729,9 @@ void net_if_init(void)
|
|||
/* Make sure that we do not have too many network interfaces
|
||||
* compared to the number of VLAN interfaces.
|
||||
*/
|
||||
for (iface = __net_if_start, if_count = 0;
|
||||
iface != __net_if_end; iface++) {
|
||||
if_count = 0;
|
||||
|
||||
Z_STRUCT_SECTION_FOREACH(net_if, iface) {
|
||||
if (net_if_l2(iface) == &NET_L2_GET_NAME(ETHERNET)) {
|
||||
if_count++;
|
||||
}
|
||||
|
@ -3782,12 +3747,10 @@ void net_if_init(void)
|
|||
|
||||
void net_if_post_init(void)
|
||||
{
|
||||
struct net_if *iface;
|
||||
|
||||
NET_DBG("");
|
||||
|
||||
/* After TX is running, attempt to bring the interface up */
|
||||
for (iface = __net_if_start; iface != __net_if_end; iface++) {
|
||||
Z_STRUCT_SECTION_FOREACH(net_if, iface) {
|
||||
if (!net_if_flag_is_set(iface, NET_IF_NO_AUTO_START)) {
|
||||
net_if_up(iface);
|
||||
}
|
||||
|
|
|
@ -18,11 +18,7 @@ LOG_MODULE_DECLARE(net_l2_ppp, CONFIG_NET_L2_PPP_LOG_LEVEL);
|
|||
|
||||
static void lcp_up(struct ppp_context *ctx)
|
||||
{
|
||||
struct ppp_protocol_handler *proto;
|
||||
|
||||
for (proto = __net_ppp_proto_start;
|
||||
proto != __net_ppp_proto_end;
|
||||
proto++) {
|
||||
Z_STRUCT_SECTION_FOREACH(ppp_protocol_handler, proto) {
|
||||
if (proto->protocol == PPP_LCP) {
|
||||
continue;
|
||||
}
|
||||
|
@ -35,13 +31,9 @@ static void lcp_up(struct ppp_context *ctx)
|
|||
|
||||
static void do_network(struct ppp_context *ctx)
|
||||
{
|
||||
const struct ppp_protocol_handler *proto;
|
||||
|
||||
ppp_change_phase(ctx, PPP_NETWORK);
|
||||
|
||||
for (proto = __net_ppp_proto_start;
|
||||
proto != __net_ppp_proto_end;
|
||||
proto++) {
|
||||
Z_STRUCT_SECTION_FOREACH(ppp_protocol_handler, proto) {
|
||||
if (proto->protocol == PPP_CCP || proto->protocol == PPP_ECP) {
|
||||
if (proto->open) {
|
||||
proto->open(ctx);
|
||||
|
@ -54,9 +46,7 @@ static void do_network(struct ppp_context *ctx)
|
|||
*/
|
||||
/* TODO possible encryption stuff here*/
|
||||
|
||||
for (proto = __net_ppp_proto_start;
|
||||
proto != __net_ppp_proto_end;
|
||||
proto++) {
|
||||
Z_STRUCT_SECTION_FOREACH(ppp_protocol_handler, proto) {
|
||||
if (proto->protocol == PPP_CCP || proto->protocol == PPP_ECP ||
|
||||
proto->protocol >= 0xC000) {
|
||||
continue;
|
||||
|
@ -69,7 +59,8 @@ static void do_network(struct ppp_context *ctx)
|
|||
}
|
||||
|
||||
if (ctx->network_protos_open == 0) {
|
||||
proto = ppp_lcp_get();
|
||||
const struct ppp_protocol_handler *proto = ppp_lcp_get();
|
||||
|
||||
if (proto) {
|
||||
proto->close(ctx, "No network protocols open");
|
||||
}
|
||||
|
|
|
@ -55,11 +55,7 @@ void ppp_network_done(struct ppp_context *ctx, int proto)
|
|||
|
||||
void ppp_network_all_down(struct ppp_context *ctx)
|
||||
{
|
||||
struct ppp_protocol_handler *proto;
|
||||
|
||||
for (proto = __net_ppp_proto_start;
|
||||
proto != __net_ppp_proto_end;
|
||||
proto++) {
|
||||
Z_STRUCT_SECTION_FOREACH(ppp_protocol_handler, proto) {
|
||||
if (proto->protocol != PPP_LCP && proto->lower_down) {
|
||||
proto->lower_down(ctx);
|
||||
}
|
||||
|
|
|
@ -82,9 +82,8 @@ struct ppp_protocol_handler {
|
|||
#define PPP_PROTOCOL_REGISTER(name, proto, init_func, proto_handler, \
|
||||
proto_lower_up, proto_lower_down, \
|
||||
proto_open, proto_close) \
|
||||
static const struct ppp_protocol_handler \
|
||||
(PPP_PROTO_GET_NAME(name)) __used \
|
||||
__attribute__((__section__(".net_ppp_proto.data"))) = { \
|
||||
static const Z_STRUCT_SECTION_ITERABLE(ppp_protocol_handler, \
|
||||
PPP_PROTO_GET_NAME(name)) = { \
|
||||
.protocol = proto, \
|
||||
.init = init_func, \
|
||||
.handler = proto_handler, \
|
||||
|
@ -94,9 +93,6 @@ struct ppp_protocol_handler {
|
|||
.close = proto_close, \
|
||||
}
|
||||
|
||||
extern struct ppp_protocol_handler __net_ppp_proto_start[];
|
||||
extern struct ppp_protocol_handler __net_ppp_proto_end[];
|
||||
|
||||
const char *ppp_phase_str(enum ppp_phase phase);
|
||||
const char *ppp_state_str(enum ppp_state state);
|
||||
const char *ppp_proto2str(uint16_t proto);
|
||||
|
|
|
@ -60,7 +60,6 @@ static enum net_verdict process_ppp_msg(struct net_if *iface,
|
|||
{
|
||||
struct ppp_context *ctx = net_if_l2_data(iface);
|
||||
enum net_verdict verdict = NET_DROP;
|
||||
struct ppp_protocol_handler *proto;
|
||||
uint16_t protocol;
|
||||
int ret;
|
||||
|
||||
|
@ -83,9 +82,7 @@ static enum net_verdict process_ppp_msg(struct net_if *iface,
|
|||
return NET_CONTINUE;
|
||||
}
|
||||
|
||||
for (proto = __net_ppp_proto_start;
|
||||
proto != __net_ppp_proto_end;
|
||||
proto++) {
|
||||
Z_STRUCT_SECTION_FOREACH(ppp_protocol_handler, proto) {
|
||||
if (proto->protocol != protocol) {
|
||||
continue;
|
||||
}
|
||||
|
@ -418,8 +415,7 @@ static void ppp_startup(struct k_work *work)
|
|||
{
|
||||
struct ppp_context *ctx = CONTAINER_OF(work, struct ppp_context,
|
||||
startup);
|
||||
const struct ppp_protocol_handler *proto;
|
||||
int count;
|
||||
int count = 0;
|
||||
|
||||
if (!ctx->is_init) {
|
||||
return;
|
||||
|
@ -427,14 +423,13 @@ static void ppp_startup(struct k_work *work)
|
|||
|
||||
NET_DBG("PPP %p startup for interface %p", ctx, ctx->iface);
|
||||
|
||||
for (proto = __net_ppp_proto_start, count = 0;
|
||||
proto != __net_ppp_proto_end;
|
||||
proto++, count++) {
|
||||
Z_STRUCT_SECTION_FOREACH(ppp_protocol_handler, proto) {
|
||||
if (proto->protocol == PPP_LCP) {
|
||||
ppp_lcp = proto;
|
||||
}
|
||||
|
||||
proto->init(ctx);
|
||||
count++;
|
||||
}
|
||||
|
||||
if (count == 0) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue