-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b05a8a
commit 01d1a1f
Showing
4 changed files
with
140 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* Copyright (c) 2023, Rafael Santiago | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
#include <cmd/macgonuts_maddaddy_task.h> | ||
#include <cmd/macgonuts_option.h> | ||
#include <macgonuts_etherconv.h> | ||
#include <macgonuts_socket_common.h> | ||
#include <macgonuts_status_info.h> | ||
|
||
static int g_QuitMadDaddy = 0; | ||
|
||
static int do_mad_daddy(const char *iface, const uint8_t *hw_addrs, const size_t hw_addrs_size); | ||
|
||
static __attribute__((unused)) int send_fake_na(const macgonuts_socket_t rsk, const uint8_t *hw_addr); | ||
|
||
static void sigint_watchdog(int signo); | ||
|
||
static uint8_t *preprocess_targets_array(char **targets, const size_t targets_nr, size_t *macs_buf_size); | ||
|
||
static uint8_t *preprocess_targets_array(char **targets, const size_t targets_nr, size_t *macs_buf_size); | ||
|
||
int macgonuts_maddaddy_task(void) { | ||
int err = EXIT_FAILURE; | ||
const char *lo_iface = macgonuts_get_option("lo-iface", NULL); | ||
char **targets = NULL; | ||
size_t targets_nr = 0; | ||
uint8_t *hw_addrs = NULL; | ||
size_t hw_addrs_size = 0; | ||
|
||
if (lo_iface == NULL) { | ||
macgonuts_si_error("--lo-iface option is missing.\n"); | ||
goto macgonuts_maddaddy_task_epilogue; | ||
} | ||
|
||
targets = macgonuts_get_array_option("targets", NULL, &targets_nr); | ||
if (targets != NULL) { | ||
hw_addrs = preprocess_targets_array(targets, targets_nr, &hw_addrs_size); | ||
macgonuts_free_array_option_value(targets, targets_nr); | ||
targets = NULL; | ||
} | ||
|
||
err = do_mad_daddy(lo_iface, hw_addrs, hw_addrs_size); | ||
|
||
macgonuts_maddaddy_task_epilogue: | ||
|
||
if (hw_addrs != NULL) { | ||
free(hw_addrs); | ||
} | ||
|
||
if (targets != NULL) { | ||
macgonuts_free_array_option_value(targets, targets_nr); | ||
} | ||
|
||
return err; | ||
} | ||
|
||
int macgonuts_maddaddy_task_help(void) { | ||
macgonuts_si_print("use: macgonuts maddady --lo-iface=<label> [ --targets=<hw-addr-list> ]\n"); | ||
return EXIT_SUCCESS; | ||
} | ||
|
||
static int do_mad_daddy(const char *iface, const uint8_t *hw_addrs, const size_t hw_addrs_size) { | ||
char buf[256]; | ||
|
||
if (macgonuts_get_addr_from_iface_unix(buf, sizeof(buf) - 1, 6, iface) != EXIT_SUCCESS) { | ||
macgonuts_si_error("interface `%s` does not support IPv6.\n"); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
signal(SIGINT, sigint_watchdog); | ||
signal(SIGTERM, sigint_watchdog); | ||
|
||
// TODO(Rafael): - Sniff network. | ||
// - If hw_addrs is not null inspect relevant packets for relevant MAC address. | ||
// - Being a NS send a fake NA. | ||
|
||
return EXIT_SUCCESS; | ||
} | ||
|
||
static void sigint_watchdog(int signo) { | ||
g_QuitMadDaddy = 1; | ||
} | ||
|
||
static int send_fake_na(const macgonuts_socket_t rsk, const uint8_t *hw_addr) { | ||
return EXIT_FAILURE; | ||
} | ||
|
||
static uint8_t *preprocess_targets_array(char **targets, const size_t targets_nr, size_t *macs_buf_size) { | ||
char **target = targets; | ||
char **targets_end = targets + targets_nr; | ||
uint8_t *macs_buf = NULL; | ||
uint8_t *mp = NULL; | ||
|
||
*macs_buf_size = targets_nr * 6; | ||
macs_buf = (uint8_t *)malloc(*macs_buf_size); | ||
|
||
if (macs_buf == NULL) { | ||
macgonuts_si_error("unable to allocate MAC bufs list.\n"); | ||
return NULL; | ||
} | ||
|
||
mp = macs_buf; | ||
|
||
while (target != targets_end) { | ||
if (macgonuts_get_raw_ether_addr(mp, 6, *target, strlen(*target)) != EXIT_SUCCESS) { | ||
macgonuts_si_error("unable to pre-process MAC `%s`.\n", *target); | ||
free(macs_buf); | ||
return NULL; | ||
} | ||
target++; | ||
mp += 6; | ||
} | ||
|
||
return macs_buf; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright (c) 2023, Rafael Santiago | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
#ifndef MACGONUTS_CMD_MACGONUTS_MADDADDY_TASK_H | ||
#define MACGONUTS_CMD_MACGONUTS_MADDADDY_TASK_H 1 | ||
|
||
#include <macgonuts_types.h> | ||
|
||
int macgonuts_maddaddy_task(void); | ||
|
||
int macgonuts_maddaddy_task_help(void); | ||
|
||
#endif // MACGONUTS_CMD_MACGONUTS_MADDADDY_TASK_H |