Added the ipv6-prefix configuration option

This commit is contained in:
Nikos Mavrogiannopoulos
2013-10-29 10:01:53 +01:00
parent 2480a2cf58
commit 30f0e93e70
9 changed files with 70 additions and 11 deletions
+4 -3
View File
@@ -1,9 +1,10 @@
* Version 0.1.8 (unreleased) * Version 0.1.8 (unreleased)
- Added configuration directives 'config-per-user' and 'config-per-group'. - Added configuration directives 'config-per-user' and 'config-per-group'.
They allow loading an additional configuration client per user or per They allow loading an additional configuration client per user or per
group from the setup directory. group from the setup directory.
- Added the ipv6-prefix configuration option to replace ipv6-netmask. The
new option accepts IPv6 subnet prefixes.
* Version 0.1.7 (released 2013-10-25) * Version 0.1.7 (released 2013-10-25)
+7 -3
View File
@@ -151,9 +151,11 @@ ipv4-dns = local
#ipv4-nbns = 192.168.2.3 #ipv4-nbns = 192.168.2.3
#ipv6-address = #ipv6-address =
#ipv6-mask =
#ipv6-dns = #ipv6-dns =
# The IPv6 subnet prefix
#ipv6-prefix =
# Prior to leasing any IP from the pool ping it to verify that # Prior to leasing any IP from the pool ping it to verify that
# it is not in use by another (unrelated to this server) host. # it is not in use by another (unrelated to this server) host.
ping-leases = false ping-leases = false
@@ -172,8 +174,10 @@ route = 192.168.1.0/255.255.255.0
# Configuration files that will be applied per user connection or # Configuration files that will be applied per user connection or
# per group. Each file name on these directories must match the username # per group. Each file name on these directories must match the username
# or the groupname. # or the groupname.
config-per-user = /etc/ocserv/config-per-user/ # The options allow in such configuration files are ipv?-dns, ipv?-nbns,
config-per-group = /etc/ocserv/config-per-group/ # ipv?-network, ipv?-netmask, ipv6-prefix and route.
#config-per-user = /etc/ocserv/config-per-user/
#config-per-group = /etc/ocserv/config-per-group/
# #
# The following options are for (experimental) AnyConnect client # The following options are for (experimental) AnyConnect client
+26
View File
@@ -76,3 +76,29 @@ int ip_cmp(const struct sockaddr_storage *s1, const struct sockaddr_storage *s2,
return memcmp(SA_IN6_P(s1), SA_IN6_P(s2), sizeof(struct in6_addr)); return memcmp(SA_IN6_P(s1), SA_IN6_P(s2), sizeof(struct in6_addr));
} }
} }
/* returns an allocated string with the mask to apply for the prefix
*/
char* ipv6_prefix_to_mask(unsigned prefix)
{
switch (prefix) {
case 16:
return strdup("FFFF::");
case 32:
return strdup("FFFF:FFFF::");
case 48:
return strdup("FFFF:FFFF:FFFF::");
case 64:
return strdup("FFFF:FFFF:FFFF:FFFF::");
case 80:
return strdup("FFFF:FFFF:FFFF:FFFF:FFFF::");
case 96:
return strdup("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF::");
case 112:
return strdup("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF::");
case 128:
return strdup("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF");
default:
return NULL;
}
}
+4
View File
@@ -1,8 +1,12 @@
#ifndef COMMON_H #ifndef COMMON_H
# define COMMON_H # define COMMON_H
#include <sys/socket.h>
ssize_t force_write(int sockfd, const void *buf, size_t len); ssize_t force_write(int sockfd, const void *buf, size_t len);
ssize_t force_read(int sockfd, void *buf, size_t len); ssize_t force_read(int sockfd, void *buf, size_t len);
int ip_cmp(const struct sockaddr_storage *s1, const struct sockaddr_storage *s2, size_t n); int ip_cmp(const struct sockaddr_storage *s1, const struct sockaddr_storage *s2, size_t n);
char* ipv6_prefix_to_mask(unsigned prefix);
#endif #endif
+8
View File
@@ -29,6 +29,7 @@
#include <ocserv-args.h> #include <ocserv-args.h>
#include <autoopts/options.h> #include <autoopts/options.h>
#include <limits.h> #include <limits.h>
#include <common.h>
#include <c-strcase.h> #include <c-strcase.h>
#include <vpn.h> #include <vpn.h>
@@ -96,6 +97,7 @@ static struct cfg_options available_options[] = {
{ .name = "ipv4-nbns", .type = OPTION_STRING, .mandatory = 0 }, { .name = "ipv4-nbns", .type = OPTION_STRING, .mandatory = 0 },
{ .name = "ipv6-network", .type = OPTION_STRING, .mandatory = 0 }, { .name = "ipv6-network", .type = OPTION_STRING, .mandatory = 0 },
{ .name = "ipv6-netmask", .type = OPTION_STRING, .mandatory = 0 }, { .name = "ipv6-netmask", .type = OPTION_STRING, .mandatory = 0 },
{ .name = "ipv6-prefix", .type = OPTION_NUMERIC, .mandatory = 0 },
{ .name = "ipv6-dns", .type = OPTION_STRING, .mandatory = 0 }, { .name = "ipv6-dns", .type = OPTION_STRING, .mandatory = 0 },
{ .name = "ipv6-nbns", .type = OPTION_STRING, .mandatory = 0 }, { .name = "ipv6-nbns", .type = OPTION_STRING, .mandatory = 0 },
{ .name = "config-per-user", .type = OPTION_STRING, .mandatory = 0 }, { .name = "config-per-user", .type = OPTION_STRING, .mandatory = 0 },
@@ -204,6 +206,7 @@ const tOptionValue* val, *prev;
unsigned j, mand; unsigned j, mand;
char** auth = NULL; char** auth = NULL;
unsigned auth_size = 0; unsigned auth_size = 0;
unsigned prefix = 0;
pov = configFileLoad(file); pov = configFileLoad(file);
if (pov == NULL) { if (pov == NULL) {
@@ -346,6 +349,11 @@ unsigned auth_size = 0;
READ_STRING("ipv6-network", config->network.ipv6); READ_STRING("ipv6-network", config->network.ipv6);
READ_STRING("ipv6-netmask", config->network.ipv6_netmask); READ_STRING("ipv6-netmask", config->network.ipv6_netmask);
READ_NUMERIC("ipv6-prefix", prefix);
if (prefix > 0)
config->network.ipv6_netmask = ipv6_prefix_to_mask(prefix);
READ_STRING("ipv6-dns", config->network.ipv6_dns); READ_STRING("ipv6-dns", config->network.ipv6_dns);
READ_STRING("ipv4-nbns", config->network.ipv4_nbns); READ_STRING("ipv4-nbns", config->network.ipv4_nbns);
+15 -1
View File
@@ -29,6 +29,7 @@
#include <ocserv-args.h> #include <ocserv-args.h>
#include <autoopts/options.h> #include <autoopts/options.h>
#include <limits.h> #include <limits.h>
#include <common.h>
#include <c-strcase.h> #include <c-strcase.h>
#include <vpn.h> #include <vpn.h>
@@ -48,6 +49,7 @@ static struct cfg_options available_options[] = {
{ .name = "ipv4-network", .type = OPTION_STRING }, { .name = "ipv4-network", .type = OPTION_STRING },
{ .name = "ipv6-network", .type = OPTION_STRING }, { .name = "ipv6-network", .type = OPTION_STRING },
{ .name = "ipv4-netmask", .type = OPTION_STRING }, { .name = "ipv4-netmask", .type = OPTION_STRING },
{ .name = "ipv6-prefix", .type = OPTION_NUMERIC },
{ .name = "ipv6-netmask", .type = OPTION_STRING }, { .name = "ipv6-netmask", .type = OPTION_STRING },
}; };
@@ -69,13 +71,21 @@ static struct cfg_options available_options[] = {
} \ } \
} }
#undef READ_RAW_STRING
#define READ_RAW_STRING(name, s_name) \ #define READ_RAW_STRING(name, s_name) \
val = optionGetValue(pov, name); \ val = optionGetValue(pov, name); \
if (val != NULL && val->valType == OPARG_TYPE_STRING) { \ if (val != NULL && val->valType == OPARG_TYPE_STRING) { \
s_name = strdup(val->v.strVal); \ s_name = strdup(val->v.strVal); \
} }
#define READ_RAW_NUMERIC(name, s_name) \
val = optionGetValue(pov, name); \
if (val != NULL) { \
if (val->valType == OPARG_TYPE_NUMERIC) \
s_name = val->v.longVal; \
else if (val->valType == OPARG_TYPE_STRING) \
s_name = atoi(val->v.strVal); \
}
static int handle_option(const tOptionValue* val) static int handle_option(const tOptionValue* val)
{ {
@@ -94,6 +104,7 @@ int parse_group_cfg_file(main_server_st* s, const char* file, struct group_cfg_s
{ {
tOptionValue const * pov; tOptionValue const * pov;
const tOptionValue* val, *prev; const tOptionValue* val, *prev;
unsigned prefix = 0;
memset(config, 0, sizeof(*config)); memset(config, 0, sizeof(*config));
@@ -126,6 +137,9 @@ const tOptionValue* val, *prev;
READ_RAW_STRING("ipv6-network", config->ipv6_network); READ_RAW_STRING("ipv6-network", config->ipv6_network);
READ_RAW_STRING("ipv4-netmask", config->ipv4_netmask); READ_RAW_STRING("ipv4-netmask", config->ipv4_netmask);
READ_RAW_STRING("ipv6-netmask", config->ipv6_netmask); READ_RAW_STRING("ipv6-netmask", config->ipv6_netmask);
READ_RAW_NUMERIC("ipv6-prefix", prefix);
if (prefix > 0)
config->ipv6_netmask = ipv6_prefix_to_mask(prefix);
optionUnloadNested(pov); optionUnloadNested(pov);
+1 -1
View File
@@ -2,7 +2,7 @@
* *
* DO NOT EDIT THIS FILE (ocserv-args.c) * DO NOT EDIT THIS FILE (ocserv-args.c)
* *
* It has been AutoGen-ed October 28, 2013 at 07:03:52 PM by AutoGen 5.17 * It has been AutoGen-ed October 29, 2013 at 10:00:37 AM by AutoGen 5.17
* From the definitions ocserv-args.def * From the definitions ocserv-args.def
* and the template file options * and the template file options
* *
+4 -2
View File
@@ -238,10 +238,12 @@ ipv4-dns = 192.168.1.2
# The same, but for IPv6. # The same, but for IPv6.
#ipv6-network = #ipv6-network =
#ipv6-mask =
#ipv6-dns = #ipv6-dns =
#ipv6-nbns = #ipv6-nbns =
# The IPv6 subnet prefix
#ipv6-prefix =
# Prior to leasing any IP from the pool ping it to verify that # Prior to leasing any IP from the pool ping it to verify that
# it is not in use by another (unrelated to this server) host. # it is not in use by another (unrelated to this server) host.
ping-leases = false ping-leases = false
@@ -264,7 +266,7 @@ route = 192.168.5.0/255.255.255.0
# per group. Each file name on these directories must match the username # per group. Each file name on these directories must match the username
# or the groupname. # or the groupname.
# The options allow in such configuration files are ipv?-dns, ipv?-nbns, # The options allow in such configuration files are ipv?-dns, ipv?-nbns,
# ipv?-network, ipv?-netmask and route. # ipv?-network, ipv?-netmask, ipv6-prefix and route.
#config-per-user = /etc/ocserv/config-per-user/ #config-per-user = /etc/ocserv/config-per-user/
#config-per-group = /etc/ocserv/config-per-group/ #config-per-group = /etc/ocserv/config-per-group/
+1 -1
View File
@@ -2,7 +2,7 @@
* *
* DO NOT EDIT THIS FILE (ocserv-args.h) * DO NOT EDIT THIS FILE (ocserv-args.h)
* *
* It has been AutoGen-ed October 28, 2013 at 07:03:52 PM by AutoGen 5.17 * It has been AutoGen-ed October 29, 2013 at 10:00:36 AM by AutoGen 5.17
* From the definitions ocserv-args.def * From the definitions ocserv-args.def
* and the template file options * and the template file options
* *