Add support for setting packet marks

This commit is contained in:
Matthias Schiffer 2014-01-26 03:37:36 +01:00
parent cc498848b3
commit 53d331406d
7 changed files with 26 additions and 0 deletions

View file

@ -8,6 +8,7 @@ endif()
set(USE_BINDTODEVICE ${LINUX})
set(USE_PMTU ${LINUX})
set(USE_PKTINFO ${LINUX})
set(USE_PACKET_MARK ${LINUX})
if(${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD")
set(USE_MULTIAF_BIND FALSE)

View file

@ -554,6 +554,11 @@ void fastd_config_check(fastd_context_t *ctx, fastd_config_t *conf) {
exit_error(ctx, "config error: setting pmtu is not supported on this system");
#endif
#ifndef USE_PACKET_MARK
if (conf->packet_mark)
exit_error(ctx, "config error: setting a packet mark is not supported on this system");
#endif
if (!conf->method_list) {
pr_warn(ctx, "no encryption method configured, falling back to method `null' (unencrypted)");
fastd_config_method(ctx, conf, "null");

View file

@ -95,11 +95,13 @@
%token TOK_LIMIT
%token TOK_LOG
%token TOK_MAC
%token TOK_MARK
%token TOK_METHOD
%token TOK_MODE
%token TOK_MTU
%token TOK_NO
%token TOK_ON
%token TOK_PACKET
%token TOK_PEER
%token TOK_PEERS
%token TOK_PMTU
@ -175,6 +177,7 @@ statement: peer_group_statement
| TOK_HIDE hide ';'
| TOK_INTERFACE interface ';'
| TOK_BIND bind ';'
| TOK_PACKET TOK_MARK packet_mark ';'
| TOK_MTU mtu ';'
| TOK_PMTU pmtu ';'
| TOK_MODE mode ';'
@ -328,6 +331,10 @@ bind_default:
}
;
packet_mark: TOK_UINT {
conf->packet_mark = $1;
}
mtu: TOK_UINT {
if ($1 < 576 || $1 > 65535) {
fastd_config_error(&@$, ctx, conf, filename, depth, "invalid MTU");

View file

@ -172,6 +172,7 @@ struct fastd_config {
uint16_t mtu;
fastd_mode_t mode;
uint32_t packet_mark;
bool forward;
fastd_tristate_t pmtu;
bool secure_handshakes_set;

View file

@ -35,6 +35,7 @@
#cmakedefine USE_BINDTODEVICE
#cmakedefine USE_PMTU
#cmakedefine USE_PKTINFO
#cmakedefine USE_PACKET_MARK
#cmakedefine USE_MULTIAF_BIND

View file

@ -82,11 +82,13 @@ static const keyword_t keywords[] = {
{ "limit", TOK_LIMIT },
{ "log", TOK_LOG },
{ "mac", TOK_MAC },
{ "mark", TOK_MARK },
{ "method", TOK_METHOD },
{ "mode", TOK_MODE },
{ "mtu", TOK_MTU },
{ "no", TOK_NO },
{ "on", TOK_ON },
{ "packet", TOK_PACKET },
{ "peer", TOK_PEER },
{ "peers", TOK_PEERS },
{ "pmtu", TOK_PMTU },

View file

@ -96,6 +96,15 @@ static int bind_socket(fastd_context_t *ctx, const fastd_bind_address_t *addr, b
}
#endif
#ifdef USE_PACKET_MARK
if (ctx->conf->packet_mark) {
if (setsockopt(fd, SOL_SOCKET, SO_MARK, &ctx->conf->packet_mark, sizeof(ctx->conf->packet_mark))) {
pr_error_errno(ctx, "setsockopt: unable to set packet mark");
goto error;
}
}
#endif
fastd_peer_address_t bind_address = addr->addr;
if (bind_address.sa.sa_family == AF_UNSPEC) {