mirror of
https://github.com/neocturne/fastd.git
synced 2025-05-13 20:15:07 +02:00
shell: pass ifname and mtu to fastd_shell_env_set_iface() individually
Make the function reusable for non-fastd_iface_t interfaces.
This commit is contained in:
parent
cc98d2fc97
commit
f6fc1a39dd
4 changed files with 18 additions and 12 deletions
|
@ -182,7 +182,7 @@ static inline void on_pre_up(void) {
|
|||
/** Calls the on-up command */
|
||||
static inline void on_up(fastd_iface_t *iface) {
|
||||
fastd_shell_env_t *env = fastd_shell_env_alloc();
|
||||
fastd_shell_env_set_iface(env, iface);
|
||||
fastd_shell_env_set_iface(env, iface->name, iface->mtu);
|
||||
fastd_shell_command_exec_sync(&conf.peer_group->on_up, env, NULL);
|
||||
fastd_shell_env_free(env);
|
||||
}
|
||||
|
@ -190,7 +190,7 @@ static inline void on_up(fastd_iface_t *iface) {
|
|||
/** Calls the on-down command */
|
||||
static inline void on_down(fastd_iface_t *iface) {
|
||||
fastd_shell_env_t *env = fastd_shell_env_alloc();
|
||||
fastd_shell_env_set_iface(env, iface);
|
||||
fastd_shell_env_set_iface(env, iface->name, iface->mtu);
|
||||
fastd_shell_command_exec_sync(&conf.peer_group->on_down, env, NULL);
|
||||
fastd_shell_env_free(env);
|
||||
}
|
||||
|
|
10
src/peer.c
10
src/peer.c
|
@ -64,7 +64,15 @@ void fastd_peer_set_shell_env(
|
|||
|
||||
fastd_shell_env_set(env, "PEER_NAME", peer ? peer->name : NULL);
|
||||
|
||||
fastd_shell_env_set_iface(env, peer ? peer->iface : NULL);
|
||||
const char *ifname = NULL;
|
||||
uint16_t mtu = 0;
|
||||
if (peer) {
|
||||
if (peer->iface) {
|
||||
ifname = peer->iface->name;
|
||||
mtu = peer->iface->mtu;
|
||||
}
|
||||
}
|
||||
fastd_shell_env_set_iface(env, ifname, mtu);
|
||||
|
||||
fastd_peer_set_shell_env_addr(env, local_addr, "LOCAL_ADDRESS", "LOCAL_PORT");
|
||||
fastd_peer_set_shell_env_addr(env, peer_addr, "PEER_ADDRESS", "PEER_PORT");
|
||||
|
|
14
src/shell.c
14
src/shell.c
|
@ -55,17 +55,15 @@ void fastd_shell_env_free(fastd_shell_env_t *env) {
|
|||
free(env);
|
||||
}
|
||||
|
||||
/** Adds an interface name to a shell environment */
|
||||
void fastd_shell_env_set_iface(fastd_shell_env_t *env, const fastd_iface_t *iface) {
|
||||
if (iface) {
|
||||
/** Adds an interface name and MTU to a shell environment */
|
||||
void fastd_shell_env_set_iface(fastd_shell_env_t *env, const char *ifname, uint16_t mtu) {
|
||||
fastd_shell_env_set(env, "INTERFACE", ifname);
|
||||
|
||||
if (mtu) {
|
||||
char buf[6];
|
||||
|
||||
fastd_shell_env_set(env, "INTERFACE", iface->name);
|
||||
|
||||
snprintf(buf, sizeof(buf), "%u", iface->mtu);
|
||||
snprintf(buf, sizeof(buf), "%u", mtu);
|
||||
fastd_shell_env_set(env, "INTERFACE_MTU", buf);
|
||||
} else {
|
||||
fastd_shell_env_set(env, "INTERFACE", NULL);
|
||||
fastd_shell_env_set(env, "INTERFACE_MTU", NULL);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ static inline bool fastd_shell_command_isset(const fastd_shell_command_t *comman
|
|||
|
||||
fastd_shell_env_t *fastd_shell_env_alloc(void);
|
||||
void fastd_shell_env_set(fastd_shell_env_t *env, const char *key, const char *value);
|
||||
void fastd_shell_env_set_iface(fastd_shell_env_t *env, const fastd_iface_t *iface);
|
||||
void fastd_shell_env_set_iface(fastd_shell_env_t *env, const char *ifname, uint16_t mtu);
|
||||
void fastd_shell_env_free(fastd_shell_env_t *env);
|
||||
|
||||
bool fastd_shell_command_exec_sync(const fastd_shell_command_t *command, const fastd_shell_env_t *env, int *ret);
|
||||
|
|
Loading…
Add table
Reference in a new issue