mirror of
https://github.com/markqvist/tncattach.git
synced 2025-07-30 12:32:25 -04:00
TAP
- Now link-local and normal v6 can be requested independently tncattach - Added `--ll` mode to add link-local
This commit is contained in:
parent
d2bade8dcc
commit
9272a16e52
87
TAP.c
87
TAP.c
@ -326,56 +326,59 @@ int open_tap(void) {
|
||||
close(dummySock);
|
||||
cleanup();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
char* ipPart = strtok(ipv6_addr, "/");
|
||||
char* prefixPart_s = strtok(NULL, "/");
|
||||
printf("ip part: %s\n", ipPart);
|
||||
|
||||
if(!prefixPart_s)
|
||||
{
|
||||
perror("No prefix length was provided"); // TODO: Move logic into arg parsing
|
||||
close(dummySock);
|
||||
cleanup();
|
||||
exit(1);
|
||||
}
|
||||
printf("prefix part: %s\n", prefixPart_s);
|
||||
|
||||
long prefixLen_l = strtol(prefixPart_s, NULL, 10); // TODO: Add handling here for errors (using errno)
|
||||
|
||||
|
||||
|
||||
// Convert ASCII IPv6 address to ABI structure
|
||||
struct in6_addr six_addr_itself;
|
||||
memset(&six_addr_itself, 0, sizeof(struct in6_addr));
|
||||
if(inet_pton(AF_INET6, ipv6_addr, &six_addr_itself) < 0)
|
||||
{
|
||||
printf("Error parsing IPv6 address '%s'\n", ipv6_addr);
|
||||
close(dummySock);
|
||||
cleanup();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Choose stratergy for generating link-local address
|
||||
if(device_type == IF_TAP)
|
||||
// If link-local was requested
|
||||
if(link_local_v6)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
// Add link-local address
|
||||
trySixSet(ifr.ifr_ifindex, generateLinkLocal(if_name), 64);
|
||||
}
|
||||
|
||||
// Add link-local address
|
||||
trySixSet(ifr.ifr_ifindex, generateLinkLocal(if_name), 64);
|
||||
// If use-specified non-link-local IPv6 was
|
||||
if(set_ipv6)
|
||||
{
|
||||
char* ipPart = strtok(ipv6_addr, "/");
|
||||
char* prefixPart_s = strtok(NULL, "/");
|
||||
printf("ip part: %s\n", ipPart);
|
||||
|
||||
// Add user's requested address
|
||||
trySixSet(ifr.ifr_ifindex, six_addr_itself, prefixLen_l);
|
||||
if(!prefixPart_s)
|
||||
{
|
||||
perror("No prefix length was provided"); // TODO: Move logic into arg parsing
|
||||
close(dummySock);
|
||||
cleanup();
|
||||
exit(1);
|
||||
}
|
||||
printf("prefix part: %s\n", prefixPart_s);
|
||||
|
||||
// FIXME: Allow the ipv6 to be empty and just do link-local
|
||||
long prefixLen_l = strtol(prefixPart_s, NULL, 10); // TODO: Add handling here for errors (using errno)
|
||||
|
||||
printf("IPv6 configuration done\n");
|
||||
|
||||
|
||||
// Convert ASCII IPv6 address to ABI structure
|
||||
struct in6_addr six_addr_itself;
|
||||
memset(&six_addr_itself, 0, sizeof(struct in6_addr));
|
||||
if(inet_pton(AF_INET6, ipv6_addr, &six_addr_itself) < 0)
|
||||
{
|
||||
printf("Error parsing IPv6 address '%s'\n", ipv6_addr);
|
||||
close(dummySock);
|
||||
cleanup();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Choose stratergy for generating link-local address
|
||||
if(device_type == IF_TAP)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Add user's requested address
|
||||
trySixSet(ifr.ifr_ifindex, six_addr_itself, prefixLen_l);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
32
tncattach.c
32
tncattach.c
@ -35,6 +35,7 @@ bool noup = false;
|
||||
bool daemonize = false;
|
||||
bool set_ipv4 = false;
|
||||
bool set_ipv6 = false;
|
||||
bool link_local_v6 = false; // FIXME: make this true by default
|
||||
bool set_netmask = false;
|
||||
bool kiss_over_tcp = false;
|
||||
char* ipv4_addr;
|
||||
@ -273,15 +274,16 @@ static struct argp_option options[] = {
|
||||
{ "ethernet", 'e', 0, 0, "Create a full ethernet device", 2},
|
||||
{ "ipv4", 'i', "IP_ADDRESS", 0, "Configure an IPv4 address on interface", 3},
|
||||
{ "ipv6", '6', "IP6_ADDRESS", 0, "Configure an IPv6 address on interface", 4},
|
||||
{ "noipv6", 'n', 0, 0, "Filter IPv6 traffic from reaching TNC", 5},
|
||||
{ "noup", 1, 0, 0, "Only create interface, don't bring it up", 6},
|
||||
{ "kisstcp", 'T', 0, 0, "Use KISS over TCP instead of serial port", 7},
|
||||
{ "tcphost", 'H', "TCP_HOST", 0, "Host to connect to when using KISS over TCP", 8},
|
||||
{ "tcpport", 'P', "TCP_PORT", 0, "TCP port when using KISS over TCP", 9},
|
||||
{ "interval", 't', "SECONDS", 0, "Maximum interval between station identifications", 10},
|
||||
{ "id", 's', "CALLSIGN", 0, "Station identification data", 11},
|
||||
{ "daemon", 'd', 0, 0, "Run tncattach as a daemon", 12},
|
||||
{ "verbose", 'v', 0, 0, "Enable verbose output", 13},
|
||||
{ "ll", 'l', 0, 0, "Add a link-local Ipv6 address", 5},
|
||||
{ "noipv6", 'n', 0, 0, "Filter IPv6 traffic from reaching TNC", 6},
|
||||
{ "noup", 1, 0, 0, "Only create interface, don't bring it up", 7},
|
||||
{ "kisstcp", 'T', 0, 0, "Use KISS over TCP instead of serial port", 8},
|
||||
{ "tcphost", 'H', "TCP_HOST", 0, "Host to connect to when using KISS over TCP", 9},
|
||||
{ "tcpport", 'P', "TCP_PORT", 0, "TCP port when using KISS over TCP", 10},
|
||||
{ "interval", 't', "SECONDS", 0, "Maximum interval between station identifications", 11},
|
||||
{ "id", 's', "CALLSIGN", 0, "Station identification data", 12},
|
||||
{ "daemon", 'd', 0, 0, "Run tncattach as a daemon", 13},
|
||||
{ "verbose", 'v', 0, 0, "Enable verbose output", 14},
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
@ -302,6 +304,7 @@ struct arguments {
|
||||
bool set_ipv4;
|
||||
bool set_netmask;
|
||||
bool set_ipv6;
|
||||
bool link_local_v6;
|
||||
bool set_netmask_v6;
|
||||
bool noipv6;
|
||||
bool noup;
|
||||
@ -487,6 +490,15 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
||||
strcpy(ipv6_addr, arguments->ipv6);
|
||||
printf("v6 now: %s\n", ipv6_addr);
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
if(arguments->noipv6)
|
||||
{
|
||||
perror("Sorry, but you had noipv6 set yet want to use ipv6 link-local?\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
arguments->link_local_v6 = true;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
arguments->noipv6 = true;
|
||||
@ -586,6 +598,7 @@ int main(int argc, char **argv) {
|
||||
arguments.set_ipv4 = false;
|
||||
arguments.set_netmask = false;
|
||||
arguments.set_ipv6 = false;
|
||||
arguments.link_local_v6 = false;
|
||||
arguments.set_netmask_v6 = false;
|
||||
arguments.noipv6 = false;
|
||||
arguments.daemon = false;
|
||||
@ -615,6 +628,7 @@ int main(int argc, char **argv) {
|
||||
if (arguments.set_ipv4) set_ipv4 = true;
|
||||
if (arguments.set_netmask) set_netmask = true;
|
||||
if (arguments.set_ipv6) set_ipv6 = true;
|
||||
if (arguments.link_local_v6) link_local_v6 = true;
|
||||
if (arguments.noup) noup = true;
|
||||
mtu = arguments.mtu;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user