summaryrefslogtreecommitdiff
path: root/src/vpn
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-07-02 19:58:12 +0000
committerChristian Grothoff <christian@grothoff.org>2016-07-02 19:58:12 +0000
commit80a401db776bf42db639cb501a3214b1a71c50e6 (patch)
tree02dcf605af2409c76707dc378d3261ae3d7a6976 /src/vpn
parentdeb0bd1ab2d227f60f07842642e35e4dc497d952 (diff)
-reindent
Diffstat (limited to 'src/vpn')
-rw-r--r--src/vpn/gnunet-helper-vpn.c132
1 files changed, 98 insertions, 34 deletions
diff --git a/src/vpn/gnunet-helper-vpn.c b/src/vpn/gnunet-helper-vpn.c
index 0519680eb..02889d65b 100644
--- a/src/vpn/gnunet-helper-vpn.c
+++ b/src/vpn/gnunet-helper-vpn.c
@@ -91,14 +91,18 @@ init_tun (char *dev)
if (-1 == (fd = open ("/dev/net/tun", O_RDWR)))
{
- fprintf (stderr, "Error opening `%s': %s\n", "/dev/net/tun",
+ fprintf (stderr,
+ "Error opening `%s': %s\n",
+ "/dev/net/tun",
strerror (errno));
return -1;
}
if (fd >= FD_SETSIZE)
{
- fprintf (stderr, "File descriptor to large: %d", fd);
+ fprintf (stderr,
+ "File descriptor to large: %d",
+ fd);
(void) close (fd);
return -1;
}
@@ -107,9 +111,13 @@ init_tun (char *dev)
ifr.ifr_flags = IFF_TUN;
if ('\0' != *dev)
- strncpy (ifr.ifr_name, dev, IFNAMSIZ);
+ strncpy (ifr.ifr_name,
+ dev,
+ IFNAMSIZ);
- if (-1 == ioctl (fd, TUNSETIFF, (void *) &ifr))
+ if (-1 == ioctl (fd,
+ TUNSETIFF,
+ (void *) &ifr))
{
fprintf (stderr,
"Error with ioctl on `%s': %s\n",
@@ -131,7 +139,9 @@ init_tun (char *dev)
* @param prefix_len the length of the network-prefix
*/
static void
-set_address6 (const char *dev, const char *address, unsigned long prefix_len)
+set_address6 (const char *dev,
+ const char *address,
+ unsigned long prefix_len)
{
struct ifreq ifr;
struct in6_ifreq ifr6;
@@ -163,10 +173,17 @@ set_address6 (const char *dev, const char *address, unsigned long prefix_len)
/*
* Get the index of the if
*/
- strncpy (ifr.ifr_name, dev, IFNAMSIZ);
- if (-1 == ioctl (fd, SIOGIFINDEX, &ifr))
+ strncpy (ifr.ifr_name,
+ dev,
+ IFNAMSIZ);
+ if (-1 == ioctl (fd,
+ SIOGIFINDEX,
+ &ifr))
{
- fprintf (stderr, "ioctl failed at %d: %s\n", __LINE__, strerror (errno));
+ fprintf (stderr,
+ "ioctl failed at %d: %s\n",
+ __LINE__,
+ strerror (errno));
(void) close (fd);
exit (1);
}
@@ -179,9 +196,13 @@ set_address6 (const char *dev, const char *address, unsigned long prefix_len)
/*
* Set the address
*/
- if (-1 == ioctl (fd, SIOCSIFADDR, &ifr6))
+ if (-1 == ioctl (fd,
+ SIOCSIFADDR,
+ &ifr6))
{
- fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__,
+ fprintf (stderr,
+ "ioctl failed at line %d: %s\n",
+ __LINE__,
strerror (errno));
(void) close (fd);
exit (1);
@@ -190,9 +211,13 @@ set_address6 (const char *dev, const char *address, unsigned long prefix_len)
/*
* Get the flags
*/
- if (-1 == ioctl (fd, SIOCGIFFLAGS, &ifr))
+ if (-1 == ioctl (fd,
+ SIOCGIFFLAGS,
+ &ifr))
{
- fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__,
+ fprintf (stderr,
+ "ioctl failed at line %d: %s\n",
+ __LINE__,
strerror (errno));
(void) close (fd);
exit (1);
@@ -202,9 +227,13 @@ set_address6 (const char *dev, const char *address, unsigned long prefix_len)
* Add the UP and RUNNING flags
*/
ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
- if (-1 == ioctl (fd, SIOCSIFFLAGS, &ifr))
+ if (-1 == ioctl (fd,
+ SIOCSIFFLAGS,
+ &ifr))
{
- fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__,
+ fprintf (stderr,
+ "ioctl failed at line %d: %s\n",
+ __LINE__,
strerror (errno));
(void) close (fd);
exit (1);
@@ -212,7 +241,9 @@ set_address6 (const char *dev, const char *address, unsigned long prefix_len)
if (0 != close (fd))
{
- fprintf (stderr, "close failed: %s\n", strerror (errno));
+ fprintf (stderr,
+ "close failed: %s\n",
+ strerror (errno));
exit (1);
}
}
@@ -226,7 +257,9 @@ set_address6 (const char *dev, const char *address, unsigned long prefix_len)
* @param mask the netmask
*/
static void
-set_address4 (const char *dev, const char *address, const char *mask)
+set_address4 (const char *dev,
+ const char *address,
+ const char *mask)
{
int fd;
struct sockaddr_in *addr;
@@ -239,7 +272,9 @@ set_address4 (const char *dev, const char *address, const char *mask)
/*
* Parse the address
*/
- if (1 != inet_pton (AF_INET, address, &addr->sin_addr.s_addr))
+ if (1 != inet_pton (AF_INET,
+ address,
+ &addr->sin_addr.s_addr))
{
fprintf (stderr,
"Failed to parse IPv4 address `%s'\n",
@@ -274,7 +309,9 @@ set_address4 (const char *dev, const char *address, const char *mask)
* Parse the netmask
*/
addr = (struct sockaddr_in *) &(ifr.ifr_netmask);
- if (1 != inet_pton (AF_INET, mask, &addr->sin_addr.s_addr))
+ if (1 != inet_pton (AF_INET,
+ mask,
+ &addr->sin_addr.s_addr))
{
fprintf (stderr,
"Failed to parse IPv4 address mask `%s'\n",
@@ -301,7 +338,9 @@ set_address4 (const char *dev, const char *address, const char *mask)
*/
if (-1 == ioctl (fd, SIOCGIFFLAGS, &ifr))
{
- fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__,
+ fprintf (stderr,
+ "ioctl failed at line %d: %s\n",
+ __LINE__,
strerror (errno));
(void) close (fd);
exit (1);
@@ -313,7 +352,9 @@ set_address4 (const char *dev, const char *address, const char *mask)
ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
if (-1 == ioctl (fd, SIOCSIFFLAGS, &ifr))
{
- fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__,
+ fprintf (stderr,
+ "ioctl failed at line %d: %s\n",
+ __LINE__,
strerror (errno));
(void) close (fd);
exit (1);
@@ -321,7 +362,9 @@ set_address4 (const char *dev, const char *address, const char *mask)
if (0 != close (fd))
{
- fprintf (stderr, "close failed: %s\n", strerror (errno));
+ fprintf (stderr,
+ "close failed: %s\n",
+ strerror (errno));
(void) close (fd);
exit (1);
}
@@ -399,7 +442,9 @@ run (int fd_tun)
{
if (EINTR == errno)
continue;
- fprintf (stderr, "select failed: %s\n", strerror (errno));
+ fprintf (stderr,
+ "select failed: %s\n",
+ strerror (errno));
exit (1);
}
@@ -440,7 +485,9 @@ run (int fd_tun)
}
else if (FD_ISSET (1, &fds_w))
{
- ssize_t written = write (1, buftun_read, buftun_size);
+ ssize_t written = write (1,
+ buftun_read,
+ buftun_size);
if (-1 == written)
{
@@ -457,7 +504,8 @@ run (int fd_tun)
}
else if (0 == written)
{
- fprintf (stderr, "write returned 0!?\n");
+ fprintf (stderr,
+ "write returned 0!?\n");
exit (1);
}
else
@@ -501,7 +549,8 @@ PROCESS_BUFFER:
hdr = (struct GNUNET_MessageHeader *) bufin;
if (ntohs (hdr->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER)
{
- fprintf (stderr, "protocol violation!\n");
+ fprintf (stderr,
+ "protocol violation!\n");
exit (1);
}
if (ntohs (hdr->size) > bufin_rpos)
@@ -513,11 +562,15 @@ PROCESS_BUFFER:
}
else if (FD_ISSET (fd_tun, &fds_w))
{
- ssize_t written = write (fd_tun, bufin_read, bufin_size);
+ ssize_t written = write (fd_tun,
+ bufin_read,
+ bufin_size);
if (-1 == written)
{
- fprintf (stderr, "write-error to tun: %s\n", strerror (errno));
+ fprintf (stderr,
+ "write-error to tun: %s\n",
+ strerror (errno));
shutdown (0, SHUT_RD);
shutdown (fd_tun, SHUT_WR);
write_open = 0;
@@ -570,12 +623,15 @@ main (int argc, char **argv)
return 1;
}
- strncpy (dev, argv[1], IFNAMSIZ);
+ strncpy (dev,
+ argv[1],
+ IFNAMSIZ);
dev[IFNAMSIZ - 1] = '\0';
if (-1 == (fd_tun = init_tun (dev)))
{
- fprintf (stderr, "Fatal: could not initialize tun-interface `%s' with IPv6 %s/%s and IPv4 %s/%s\n",
+ fprintf (stderr,
+ "Fatal: could not initialize tun-interface `%s' with IPv6 %s/%s and IPv4 %s/%s\n",
dev,
argv[2],
argv[3],
@@ -591,11 +647,14 @@ main (int argc, char **argv)
if ((prefix_len < 1) || (prefix_len > 127))
{
- fprintf (stderr, "Fatal: prefix_len out of range\n");
+ fprintf (stderr,
+ "Fatal: prefix_len out of range\n");
return 1;
}
- set_address6 (dev, address, prefix_len);
+ set_address6 (dev,
+ address,
+ prefix_len);
}
if (0 != strcmp (argv[4], "-"))
@@ -610,14 +669,18 @@ main (int argc, char **argv)
#ifdef HAVE_SETRESUID
if (0 != setresuid (uid, uid, uid))
{
- fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno));
+ fprintf (stderr,
+ "Failed to setresuid: %s\n",
+ strerror (errno));
global_ret = 2;
goto cleanup;
}
#else
if (0 != (setuid (uid) | seteuid (uid)))
{
- fprintf (stderr, "Failed to setuid: %s\n", strerror (errno));
+ fprintf (stderr,
+ "Failed to setuid: %s\n",
+ strerror (errno));
global_ret = 2;
goto cleanup;
}
@@ -625,7 +688,8 @@ main (int argc, char **argv)
if (SIG_ERR == signal (SIGPIPE, SIG_IGN))
{
- fprintf (stderr, "Failed to protect against SIGPIPE: %s\n",
+ fprintf (stderr,
+ "Failed to protect against SIGPIPE: %s\n",
strerror (errno));
/* no exit, we might as well die with SIGPIPE should it ever happen */
}