network/tunconfig: Initial work on a tool to manage tunnels

* Modeled after pppconfig to some degree.
* Normally various VPN and other services will create / manage
  tunnels directly, however this gives us a good way to
  test / play with things initially.
This commit is contained in:
Alexander von Gluck IV 2019-04-17 21:16:00 +00:00
parent e60aa2b8f9
commit f8a5dd0828
3 changed files with 96 additions and 1 deletions

View File

@ -18,4 +18,4 @@ SubInclude HAIKU_TOP src bin network route ;
SubInclude HAIKU_TOP src bin network telnet ;
SubInclude HAIKU_TOP src bin network telnetd ;
SubInclude HAIKU_TOP src bin network traceroute ;
SubInclude HAIKU_TOP src bin network tunconfig ;

View File

@ -0,0 +1,19 @@
SubDir HAIKU_TOP src bin network tunconfig ;
UsePrivateKernelHeaders ;
UsePrivateHeaders net ;
UseHeaders [ FDirName $(HAIKU_TOP) src add-ons kernel network ppp shared libppp
headers ] : true ;
UseHeaders [ FDirName $(HAIKU_TOP) src add-ons kernel network ppp shared
libkernelppp headers ] : true ;
BinCommand tunconfig :
tunconfig.cpp
:
be libppp.a [ TargetLibsupc++ ] libbsd.so $(TARGET_NETWORK_LIBS)
;
# Installation
HaikuInstall install-tun
: /boot/home/config/non-packaged/bin
: tunconfig ;

View File

@ -0,0 +1,76 @@
/*
* Copyright 2006-2019, Haiku, Inc. All rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Alexander von Gluck IV <kallisti5@unixzen.com>
*/
#include <stdio.h>
#include <String.h>
#include <NetworkInterface.h>
#include <NetworkRoster.h>
static
status_t
print_help()
{
fprintf(stderr, "tunconfig\n");
fprintf(stderr, "With tunconfig you can create and manage tun/tap devices.\n");
fprintf(stderr, "Usage:\n");
fprintf(stderr, " tunconfig show | -a\n");
fprintf(stderr, " tunconfig init <name>\n");
fprintf(stderr, " tunconfig create <name>\n");
fprintf(stderr, " tunconfig delete <name|interface|id>\n");
fprintf(stderr, " tunconfig details <name|interface|id>\n");
fprintf(stderr, "\t<name> must be an interface description file\n");
return -1;
}
static
status_t
show_interface(const char* name)
{
printf("%s\n", name);
return B_OK;
}
static
status_t
show_all()
{
BNetworkRoster& roster = BNetworkRoster::Default();
BNetworkInterface interface;
uint32 cookie = 0;
while (roster.GetNextInterface(&cookie, interface) == B_OK) {
BNetworkAddress linkAddress;
status_t status = interface.GetHardwareAddress(linkAddress);
if (status == B_OK && linkAddress.LinkLevelType() == IFT_TUN)
show_interface(interface.Name());
}
return B_OK;
}
int
main(int argc, char *argv[])
{
if (argc == 2) {
if (!strcmp(argv[1], "show") || !strcmp(argv[1], "-a"))
return show_all();
else
return print_help();
} else {
return print_help();
}
return 0;
}