Skip to content

Commit

Permalink
Add and use a new FindIFCInterface to deal with the slightly differen…
Browse files Browse the repository at this point in the history
…t valid interface ID ranges
  • Loading branch information
peternewman committed Sep 11, 2024
1 parent 5d3a3f4 commit 7b58de2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
24 changes: 19 additions & 5 deletions common/rdm/ResponderHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ RDMResponse *ResponderHelper::GetIFCInterfaceFixedLabel(
}

Interface interface;
if (!FindInterface(network_manager, &interface, index)) {
if (!FindIFCInterface(network_manager, &interface, index)) {
return NackWithReason(request, NR_DATA_OUT_OF_RANGE);
}

Expand Down Expand Up @@ -1174,7 +1174,7 @@ RDMResponse *ResponderHelper::GetIFCInterfaceType(
}

Interface interface;
if (!FindInterface(network_manager, &interface, index)) {
if (!FindIFCInterface(network_manager, &interface, index)) {
return NackWithReason(request, NR_DATA_OUT_OF_RANGE);
}

Expand Down Expand Up @@ -1212,7 +1212,7 @@ RDMResponse *ResponderHelper::GetIFCIPV4DNS(
// TODO(Peter): For now we always return a common set of DNS servers as long
// as any valid interface is supplied
Interface interface;
if (!FindInterface(network_manager, &interface, index)) {
if (!FindIFCInterface(network_manager, &interface, index)) {
// TODO(Peter): Should this be NR_INTERFACE_UNAVAILABLE?
return NackWithReason(request, NR_DATA_OUT_OF_RANGE);
}
Expand Down Expand Up @@ -1270,7 +1270,7 @@ RDMResponse *ResponderHelper::GetIFCDNSLabel(
// TODO(Peter): For now we always return the one hostname as long as any
// valid interface is supplied
Interface interface;
if (!FindInterface(network_manager, &interface, index)) {
if (!FindIFCInterface(network_manager, &interface, index)) {
// TODO(Peter): Should this be NR_INTERFACE_UNAVAILABLE?
return NackWithReason(request, NR_DATA_OUT_OF_RANGE);
}
Expand Down Expand Up @@ -1318,7 +1318,7 @@ RDMResponse *ResponderHelper::GetIFCDNSDomain(
// TODO(Peter): For now we always return the one domain name as long as any
// valid interface is supplied
Interface interface;
if (!FindInterface(network_manager, &interface, index)) {
if (!FindIFCInterface(network_manager, &interface, index)) {
// TODO(Peter): Should this be NR_INTERFACE_UNAVAILABLE?
return NackWithReason(request, NR_DATA_OUT_OF_RANGE);
}
Expand Down Expand Up @@ -1510,6 +1510,20 @@ bool ResponderHelper::IsInterfaceIndexValidInterface(Interface interface) {
return IsInterfaceIndexValid(interface.index);
}

bool ResponderHelper::FindIFCInterface(
const NetworkManagerInterface *network_manager,
Interface *interface, uint32_t index) {
if (!IsIFCInterfaceIndexValid(index)) {
// Invalid index
return false;
}

InterfacePicker::Options options;
options.specific_only = true;
return network_manager->GetInterfacePicker()->ChooseInterface(
interface, index, options);
}

bool ResponderHelper::IsIFCInterfaceIndexValid(uint32_t index) {
return (index >= MIN_RDM_IFC_INTERFACE_INDEX &&
index <= MAX_RDM_IFC_INTERFACE_INDEX);
Expand Down
4 changes: 4 additions & 0 deletions include/ola/rdm/ResponderHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ class ResponderHelper {
uint32_t index);
static bool IsInterfaceIndexValid(uint32_t index);
static bool IsInterfaceIndexValidInterface(ola::network::Interface interface);
static bool FindIFCInterface(
const NetworkManagerInterface *network_manager,
ola::network::Interface *interface,
uint32_t index);
static bool IsIFCInterfaceIndexValid(uint32_t index);
static bool IsIFCInterfaceIndexValidInterface(ola::network::Interface interface);
};
Expand Down

0 comments on commit 7b58de2

Please sign in to comment.