rtt更新

This commit is contained in:
2025-01-18 13:25:25 +08:00
parent c6a7554b51
commit d6009a0773
726 changed files with 103376 additions and 6270 deletions

View File

@@ -19,7 +19,11 @@ if RT_USING_NETDEV
config NETDEV_USING_AUTO_DEFAULT
bool "Enable default netdev automatic change features"
default y
config NETDEV_USING_LINK_STATUS_CALLBACK
bool "Enable netdev callback on link status change"
default n
config NETDEV_USING_IPV6
bool "Enable IPV6 protocol support"
default n

View File

@@ -101,6 +101,8 @@ struct netdev
netdev_callback_fn status_callback; /* network interface device flags change callback */
netdev_callback_fn addr_callback; /* network interface device address information change callback */
int ifindex; /* network interface device ifindex */
#ifdef RT_USING_SAL
void *sal_user_data; /* user-specific data for SAL */
#endif /* RT_USING_SAL */
@@ -111,8 +113,6 @@ struct netdev
extern struct netdev *netdev_list;
/* The default network interface device */
extern struct netdev *netdev_default;
/* The local virtual network device */
extern struct netdev *netdev_lo;
/* The network interface device ping response object */
struct netdev_ping_resp
{
@@ -153,10 +153,14 @@ int netdev_unregister(struct netdev *netdev);
struct netdev *netdev_get_first_by_flags(uint16_t flags);
struct netdev *netdev_get_by_ipaddr(ip_addr_t *ip_addr);
struct netdev *netdev_get_by_name(const char *name);
struct netdev *netdev_get_by_ifindex(int ifindex);
#ifdef RT_USING_SAL
struct netdev *netdev_get_by_family(int family);
int netdev_family_get(struct netdev *netdev);
#endif /* RT_USING_SAL */
#if defined(SAL_USING_AF_NETLINK)
int netdev_getnetdev(struct msg_buf *msg, int (*cb)(struct msg_buf *m_buf, struct netdev *nd, int nd_num, int index, int ipvx));
#endif
/* Set default network interface device in list */
void netdev_set_default(struct netdev *netdev);

View File

@@ -35,12 +35,11 @@
struct netdev *netdev_list = RT_NULL;
/* The default network interface device */
struct netdev *netdev_default = RT_NULL;
/* The local virtual network device */
struct netdev *netdev_lo = RT_NULL;
/* The global network register callback */
static netdev_callback_fn g_netdev_register_callback = RT_NULL;
static netdev_callback_fn g_netdev_default_change_callback = RT_NULL;
static RT_DEFINE_SPINLOCK(_spinlock);
static int netdev_num;
/**
* This function will register network interface device and
@@ -55,7 +54,6 @@ static RT_DEFINE_SPINLOCK(_spinlock);
*/
int netdev_register(struct netdev *netdev, const char *name, void *user_data)
{
rt_base_t level;
rt_uint16_t flags_mask;
rt_uint16_t index;
@@ -103,7 +101,7 @@ int netdev_register(struct netdev *netdev, const char *name, void *user_data)
/* initialize current network interface device single list */
rt_slist_init(&(netdev->list));
level = rt_spin_lock_irqsave(&_spinlock);
rt_spin_lock(&_spinlock);
if (netdev_list == RT_NULL)
{
@@ -115,7 +113,10 @@ int netdev_register(struct netdev *netdev, const char *name, void *user_data)
rt_slist_append(&(netdev_list->list), &(netdev->list));
}
rt_spin_unlock_irqrestore(&_spinlock, level);
netdev_num++;
netdev->ifindex = netdev_num;
rt_spin_unlock(&_spinlock);
if (netdev_default == RT_NULL)
{
@@ -146,7 +147,6 @@ int netdev_register(struct netdev *netdev, const char *name, void *user_data)
*/
int netdev_unregister(struct netdev *netdev)
{
rt_base_t level;
rt_slist_t *node = RT_NULL;
struct netdev *cur_netdev = RT_NULL;
@@ -157,7 +157,7 @@ int netdev_unregister(struct netdev *netdev)
return -RT_ERROR;
}
level = rt_spin_lock_irqsave(&_spinlock);
rt_spin_lock(&_spinlock);
for (node = &(netdev_list->list); node; node = rt_slist_next(node))
{
@@ -188,7 +188,7 @@ int netdev_unregister(struct netdev *netdev)
break;
}
}
rt_spin_unlock_irqrestore(&_spinlock, level);
rt_spin_unlock(&_spinlock);
#if defined(SAL_USING_AF_NETLINK)
rtnl_ip_notify(netdev, RTM_DELLINK);
@@ -233,7 +233,6 @@ void netdev_set_register_callback(netdev_callback_fn register_callback)
*/
struct netdev *netdev_get_first_by_flags(uint16_t flags)
{
rt_base_t level;
rt_slist_t *node = RT_NULL;
struct netdev *netdev = RT_NULL;
@@ -242,19 +241,19 @@ struct netdev *netdev_get_first_by_flags(uint16_t flags)
return RT_NULL;
}
level = rt_spin_lock_irqsave(&_spinlock);
rt_spin_lock(&_spinlock);
for (node = &(netdev_list->list); node; node = rt_slist_next(node))
{
netdev = rt_slist_entry(node, struct netdev, list);
if (netdev && (netdev->flags & flags) != 0)
{
rt_spin_unlock_irqrestore(&_spinlock, level);
rt_spin_unlock(&_spinlock);
return netdev;
}
}
rt_spin_unlock_irqrestore(&_spinlock, level);
rt_spin_unlock(&_spinlock);
return RT_NULL;
}
@@ -270,7 +269,6 @@ struct netdev *netdev_get_first_by_flags(uint16_t flags)
*/
struct netdev *netdev_get_by_ipaddr(ip_addr_t *ip_addr)
{
rt_base_t level;
rt_slist_t *node = RT_NULL;
struct netdev *netdev = RT_NULL;
@@ -279,19 +277,19 @@ struct netdev *netdev_get_by_ipaddr(ip_addr_t *ip_addr)
return RT_NULL;
}
level = rt_spin_lock_irqsave(&_spinlock);
rt_spin_lock(&_spinlock);
for (node = &(netdev_list->list); node; node = rt_slist_next(node))
{
netdev = rt_slist_entry(node, struct netdev, list);
if (netdev && ip_addr_cmp(&(netdev->ip_addr), ip_addr))
{
rt_spin_unlock_irqrestore(&_spinlock, level);
rt_spin_unlock(&_spinlock);
return netdev;
}
}
rt_spin_unlock_irqrestore(&_spinlock, level);
rt_spin_unlock(&_spinlock);
return RT_NULL;
}
@@ -307,7 +305,6 @@ struct netdev *netdev_get_by_ipaddr(ip_addr_t *ip_addr)
*/
struct netdev *netdev_get_by_name(const char *name)
{
rt_base_t level;
rt_slist_t *node = RT_NULL;
struct netdev *netdev = RT_NULL;
@@ -316,19 +313,55 @@ struct netdev *netdev_get_by_name(const char *name)
return RT_NULL;
}
level = rt_spin_lock_irqsave(&_spinlock);
rt_spin_lock(&_spinlock);
for (node = &(netdev_list->list); node; node = rt_slist_next(node))
{
netdev = rt_slist_entry(node, struct netdev, list);
if (netdev && (rt_strncmp(netdev->name, name, rt_strlen(name) < RT_NAME_MAX ? rt_strlen(name) : RT_NAME_MAX) == 0))
{
rt_spin_unlock_irqrestore(&_spinlock, level);
rt_spin_unlock(&_spinlock);
return netdev;
}
}
rt_spin_unlock_irqrestore(&_spinlock, level);
rt_spin_unlock(&_spinlock);
return RT_NULL;
}
/**
* This function will get network interface device
* in network interface device list by netdev ifindex.
*
* @param ifindex the ifindex of network interface device
*
* @return != NULL: network interface device object
* NULL: get failed
*/
struct netdev *netdev_get_by_ifindex(int ifindex)
{
rt_slist_t *node = RT_NULL;
struct netdev *netdev = RT_NULL;
if (netdev_list == RT_NULL)
{
return RT_NULL;
}
rt_spin_lock(&_spinlock);
for (node = &(netdev_list->list); node; node = rt_slist_next(node))
{
netdev = rt_slist_entry(node, struct netdev, list);
if (netdev && (netdev->ifindex == ifindex))
{
rt_spin_unlock(&_spinlock);
return netdev;
}
}
rt_spin_unlock(&_spinlock);
return RT_NULL;
}
@@ -345,7 +378,6 @@ struct netdev *netdev_get_by_name(const char *name)
*/
struct netdev *netdev_get_by_family(int family)
{
rt_base_t level;
rt_slist_t *node = RT_NULL;
struct netdev *netdev = RT_NULL;
struct sal_proto_family *pf = RT_NULL;
@@ -355,7 +387,7 @@ struct netdev *netdev_get_by_family(int family)
return RT_NULL;
}
level = rt_spin_lock_irqsave(&_spinlock);
rt_spin_lock(&_spinlock);
for (node = &(netdev_list->list); node; node = rt_slist_next(node))
{
@@ -363,7 +395,7 @@ struct netdev *netdev_get_by_family(int family)
pf = (struct sal_proto_family *) netdev->sal_user_data;
if (pf && pf->skt_ops && pf->family == family && netdev_is_up(netdev))
{
rt_spin_unlock_irqrestore(&_spinlock, level);
rt_spin_unlock(&_spinlock);
return netdev;
}
}
@@ -374,12 +406,12 @@ struct netdev *netdev_get_by_family(int family)
pf = (struct sal_proto_family *) netdev->sal_user_data;
if (pf && pf->skt_ops && pf->sec_family == family && netdev_is_up(netdev))
{
rt_spin_unlock_irqrestore(&_spinlock, level);
rt_spin_unlock(&_spinlock);
return netdev;
}
}
rt_spin_unlock_irqrestore(&_spinlock, level);
rt_spin_unlock(&_spinlock);
return RT_NULL;
}
@@ -400,6 +432,44 @@ int netdev_family_get(struct netdev *netdev)
#endif /* RT_USING_SAL */
#if defined(SAL_USING_AF_NETLINK)
int netdev_getnetdev(struct msg_buf *msg, int (*cb)(struct msg_buf *m_buf, struct netdev *nd, int nd_num, int index, int ipvx))
{
struct netdev *cur_nd_list = netdev_list;
struct netdev *nd_node;
int nd_num = 0;
int err = 0;
if (cur_nd_list == RT_NULL)
return 0;
rt_spin_lock(&_spinlock);
nd_num = rt_slist_len(&cur_nd_list->list) + 1;
rt_spin_unlock(&_spinlock);
err = cb(msg, cur_nd_list, nd_num, nd.ifindex, ROUTE_IPV4_TRUE);
if (err < 0)
return err;
rt_spin_lock(&_spinlock);
rt_slist_for_each_entry(nd_node, &(cur_nd_list->list), list)
{
rt_spin_unlock(&_spinlock);
err = cb(msg, nd_node, nd_num, nd.ifindex, ROUTE_IPV4_TRUE);
if (err < 0)
{
return err;
}
rt_spin_lock(&_spinlock);
}
rt_spin_unlock(&_spinlock);
return 0;
}
#endif
/**
* This function will set default network interface device.
*