mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2026-05-27 10:41:12 +08:00
Some code cleanup related to netif index handling
Made the macro "netif_index_to_num" private, if someone needs it externally, please complain.
This commit is contained in:
@@ -104,6 +104,7 @@
|
||||
struct netif *netif_list;
|
||||
struct netif *netif_default;
|
||||
|
||||
#define netif_index_to_num(index) ((index) - 1)
|
||||
static u8_t netif_num;
|
||||
|
||||
#if LWIP_NUM_NETIF_CLIENT_DATA > 0
|
||||
@@ -1309,7 +1310,7 @@ netif_name_to_index(const char *name)
|
||||
{
|
||||
struct netif *netif = netif_find(name);
|
||||
if (netif != NULL) {
|
||||
return netif_num_to_index(netif);
|
||||
return netif_get_index(netif);
|
||||
}
|
||||
/* No name found, return invalid index */
|
||||
return 0;
|
||||
@@ -1345,3 +1346,25 @@ netif_index_to_name(u8_t idx, char *name)
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup netif
|
||||
* Return the interface for the netif index
|
||||
*
|
||||
* @param index index of netif to find
|
||||
*/
|
||||
struct netif*
|
||||
netif_get_by_index(u8_t index)
|
||||
{
|
||||
struct netif* netif;
|
||||
|
||||
if (index != NETIF_NO_INDEX) {
|
||||
for (netif = netif_list; netif != NULL; netif = netif->next) {
|
||||
if (index == netif_get_index(netif)) {
|
||||
return netif; /* found! */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -327,15 +327,11 @@ raw_sendto(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *ipaddr)
|
||||
|
||||
#if LWIP_MULTICAST_TX_OPTIONS
|
||||
netif = NULL;
|
||||
if (ip_addr_ismulticast(ipaddr) && (pcb->mcast_ifindex != NETIF_NO_INDEX)) {
|
||||
if (ip_addr_ismulticast(ipaddr)) {
|
||||
/* For multicast-destined packets, use the user-provided interface index to
|
||||
* determine the outgoing interface, if an interface index is set and a
|
||||
* matching netif can be found. Otherwise, fall back to regular routing. */
|
||||
for (netif = netif_list; netif != NULL; netif = netif->next) {
|
||||
if (pcb->mcast_ifindex == netif_num_to_index(netif)) {
|
||||
break; /* found! */
|
||||
}
|
||||
}
|
||||
netif = netif_get_by_index(pcb->mcast_ifindex);
|
||||
}
|
||||
|
||||
if (netif == NULL)
|
||||
|
||||
@@ -540,11 +540,7 @@ udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip,
|
||||
* list, but by doing so we skip a route lookup. If the interface index has
|
||||
* gone stale, we fall through and do the regular route lookup after all. */
|
||||
if (pcb->mcast_ifindex != NETIF_NO_INDEX) {
|
||||
for (netif = netif_list; netif != NULL; netif = netif->next) {
|
||||
if (pcb->mcast_ifindex == netif_num_to_index(netif)) {
|
||||
break; /* found! */
|
||||
}
|
||||
}
|
||||
netif = netif_get_by_index(pcb->mcast_ifindex);
|
||||
}
|
||||
#if LWIP_IPV4
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user