[1/3] alfred: move interface check into helper function
Commit Message
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
---
alfred.h | 1 +
server.c | 4 ++--
util.c | 11 +++++++++++
3 files changed, 14 insertions(+), 2 deletions(-)
@@ -204,5 +204,6 @@ int time_diff(struct timespec *tv1, struct timespec *tv2,
void time_random_seed(void);
uint16_t get_random_id(void);
bool is_valid_ether_addr(uint8_t *addr);
+bool is_iface_disabled(char *iface);
int ipv4_arp_request(struct interface *interface, const alfred_addr *addr,
struct ether_addr *mac);
@@ -205,7 +205,7 @@ static void update_server_info(struct globals *globals)
if (globals->opmode == OPMODE_PRIMARY)
return;
- if (strcmp(globals->mesh_iface, "none") != 0) {
+ if (!is_iface_disabled(globals->mesh_iface)) {
tg_hash = tg_hash_new(globals->mesh_iface);
if (!tg_hash) {
fprintf(stderr, "Failed to create translation hash\n");
@@ -385,7 +385,7 @@ int alfred_server(struct globals *globals)
return -1;
}
- if (strcmp(globals->mesh_iface, "none") != 0 &&
+ if (!is_iface_disabled(globals->mesh_iface) &&
batadv_interface_check(globals->mesh_iface) < 0 &&
!globals->force) {
fprintf(stderr, "Can't start server: batman-adv interface %s not found\n",
@@ -67,6 +67,17 @@ bool is_valid_ether_addr(uint8_t addr[ETH_ALEN])
return true;
}
+bool is_iface_disabled(char *iface)
+{
+ if (!iface)
+ return false;
+
+ if (strcmp(iface, "none") != 0)
+ return false;
+
+ return true;
+}
+
static void ipv4_request_mac_resolve(const alfred_addr *addr)
{
const struct sockaddr *sockaddr;