summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2013-02-25 05:01:45 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2013-02-25 05:01:45 +0100
commit0b6cc8b646d4824658e1534d4bbebe62d47b5695 (patch)
tree636ca6a2bde6a75c2b93c46fb3ef3c6a4ec8d330 /src
parent698ede3ce4ab7ff88e5c69b3910544094c7f9814 (diff)
downloadfastd-0b6cc8b646d4824658e1534d4bbebe62d47b5695.tar
fastd-0b6cc8b646d4824658e1534d4bbebe62d47b5695.zip
Set some more environment variables for shell commands
Diffstat (limited to 'src')
-rw-r--r--src/shell.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/shell.c b/src/shell.c
index c80a32a..c9dfab0 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -37,15 +37,45 @@ bool fastd_shell_exec(fastd_context_t *ctx, const fastd_peer_t *peer, const char
char *cwd = get_current_dir_name();
if(!chdir(dir)) {
+ char buf[INET6_ADDRSTRLEN];
+
+ snprintf(buf, sizeof(buf), "%u", (unsigned)getpid());
+ setenv("FASTD_PID", buf, 1);
+
setenv("INTERFACE", ctx->ifname, 1);
- char buf[INET6_ADDRSTRLEN];
+ snprintf(buf, sizeof(buf), "%u", ctx->conf->mtu);
+ setenv("INTERFACE_MTU", buf, 1);
if (peer && peer->config && peer->config->name)
setenv("PEER_NAME", peer->config->name, 1);
else
unsetenv("PEER_NAME");
+ switch((peer && peer->sock) ? peer->sock->addr->addr.sa.sa_family : AF_UNSPEC) {
+ case AF_INET:
+ inet_ntop(AF_INET, &peer->sock->addr->addr.in.sin_addr, buf, sizeof(buf));
+ setenv("LOCAL_ADDRESS", buf, 1);
+
+ snprintf(buf, sizeof(buf), "%u", ntohs(peer->sock->addr->addr.in.sin_port));
+ setenv("LOCAL_PORT", buf, 1);
+
+ break;
+
+ case AF_INET6:
+ inet_ntop(AF_INET6, &peer->sock->addr->addr.in6.sin6_addr, buf, sizeof(buf));
+ setenv("LOCAL_ADDRESS", buf, 1);
+
+ snprintf(buf, sizeof(buf), "%u", ntohs(peer->sock->addr->addr.in6.sin6_port));
+ setenv("LOCAL_PORT", buf, 1);
+
+ break;
+
+ default:
+ unsetenv("LOCAL_ADDRESS");
+ unsetenv("LOCAL_PORT");
+ }
+
switch(peer ? peer->address.sa.sa_family : AF_UNSPEC) {
case AF_INET:
inet_ntop(AF_INET, &peer->address.in.sin_addr, buf, sizeof(buf));