Skip to content

Commit

Permalink
fixed issue where incorrect interface bool check in interface diag an…
Browse files Browse the repository at this point in the history
…d added code to only attempt to process interfaces up MAX_IF_ENTRIES -1
  • Loading branch information
r-caamano committed Nov 28, 2023
1 parent ec6bba6 commit b6c2f77
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/zfw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1028,12 +1028,13 @@ void interface_tc()
struct ifaddrs *address = addrs;
uint32_t idx = 0;
uint32_t cur_idx = 0;
uint32_t index_count = 0;
/*
* traverse linked list of interfaces and for each non-loopback interface
* populate the index into the map with ifindex as the key and ip address
* as the value
*/
while (address)
while (address && (index_count < MAX_IF_ENTRIES))
{
if(address->ifa_addr && ((!strncmp(address->ifa_name, "ziti0", 4) && (address->ifa_addr->sa_family == AF_INET))
|| (!strncmp(address->ifa_name, "tun", 3) && (address->ifa_addr->sa_family == AF_INET))
Expand Down Expand Up @@ -1062,6 +1063,7 @@ void interface_tc()
address = address->ifa_next;
continue;
}else{
index_count++;
cur_idx = idx;
}
if (tc || tcfilter)
Expand Down Expand Up @@ -1124,7 +1126,8 @@ void interface_diag()
struct ifaddrs *address = addrs;
uint32_t idx = 0;
uint32_t cur_idx = 0;
while (address)
uint32_t index_count =0;
while (address && (index_count < MAX_IF_ENTRIES))
{
if (address->ifa_addr && ((!strncmp(address->ifa_name, "ziti0", 4) && (address->ifa_addr->sa_family == AF_INET))
|| (!strncmp(address->ifa_name, "tun", 3) && (address->ifa_addr->sa_family == AF_INET))
Expand All @@ -1141,6 +1144,7 @@ void interface_diag()
address = address->ifa_next;
continue;
}else{
index_count++;
cur_idx = idx;
}
if (all_interface)
Expand Down Expand Up @@ -1229,7 +1233,7 @@ void interface_diag()

if (list_diag)
{
if(!strncmp(address->ifa_name, "ziti", 4) && !strncmp(verbose_interface,"ziti", 4)){
if(!strncmp(address->ifa_name, "ziti", 4) && !strncmp(diag_interface,"ziti", 4)){
set_tun_diag();
}
else if (!strcmp(diag_interface, address->ifa_name))
Expand Down Expand Up @@ -1436,7 +1440,7 @@ bool interface_map()
char *cur_name;
uint32_t cur_idx;
uint8_t addr_count = 0;
while (address)
while (address && (index_count < MAX_IF_ENTRIES))
{
idx = if_nametoindex(address->ifa_name);
if (address->ifa_addr && (address->ifa_addr->sa_family == AF_INET))
Expand Down

0 comments on commit b6c2f77

Please sign in to comment.