Added basic QoS rule handling

This commit is contained in:
Joseph Henry 2018-07-11 16:55:13 -07:00
parent f302fac423
commit 65b0030342
3 changed files with 21 additions and 2 deletions

View file

@ -744,6 +744,11 @@ enum ZT_VirtualNetworkRuleType
*/ */
ZT_NETWORK_RULE_ACTION_BREAK = 5, ZT_NETWORK_RULE_ACTION_BREAK = 5,
/**
* Place a matching frame in the specified QoS bucket
*/
ZT_NETWORK_RULE_ACTION_PRIORITY = 6,
/** /**
* Maximum ID for an ACTION, anything higher is a MATCH * Maximum ID for an ACTION, anything higher is a MATCH
*/ */
@ -934,6 +939,11 @@ typedef struct
uint32_t flags; uint32_t flags;
uint16_t length; uint16_t length;
} fwd; } fwd;
/**
* Quality of Service (QoS) bucket we want a frame to be placed in
*/
uint8_t qosBucket;
} v; } v;
} ZT_VirtualNetworkRule; } ZT_VirtualNetworkRule;

View file

@ -29,6 +29,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
#include "../include/ZeroTierDebug.h"
#include "Constants.hpp" #include "Constants.hpp"
#include "../version.h" #include "../version.h"
#include "Network.hpp" #include "Network.hpp"
@ -107,7 +109,7 @@ static _doZtFilterResult _doZtFilter(
Address &cc, // MUTABLE -- set to TEE destination if TEE action is taken or left alone otherwise Address &cc, // MUTABLE -- set to TEE destination if TEE action is taken or left alone otherwise
unsigned int &ccLength, // MUTABLE -- set to length of packet payload to TEE unsigned int &ccLength, // MUTABLE -- set to length of packet payload to TEE
bool &ccWatch, // MUTABLE -- set to true for WATCH target as opposed to normal TEE bool &ccWatch, // MUTABLE -- set to true for WATCH target as opposed to normal TEE
uint8_t &qosBucket) // MUTABLE -- set to the value of the argument provided to the matching action uint8_t &qosBucket) // MUTABLE -- set to the value of the argument provided to PRIORITY
{ {
// Set to true if we are a TEE/REDIRECT/WATCH target // Set to true if we are a TEE/REDIRECT/WATCH target
bool superAccept = false; bool superAccept = false;
@ -125,6 +127,10 @@ static _doZtFilterResult _doZtFilter(
if ((unsigned int)rt <= (unsigned int)ZT_NETWORK_RULE_ACTION__MAX_ID) { if ((unsigned int)rt <= (unsigned int)ZT_NETWORK_RULE_ACTION__MAX_ID) {
if (thisSetMatches) { if (thisSetMatches) {
switch(rt) { switch(rt) {
case ZT_NETWORK_RULE_ACTION_PRIORITY:
qosBucket = (rules[rn].v.qosBucket >= 0 || rules[rn].v.qosBucket <= 8) ? rules[rn].v.qosBucket : 4; // 4 = default bucket (no priority)
return DOZTFILTER_ACCEPT;
case ZT_NETWORK_RULE_ACTION_DROP: case ZT_NETWORK_RULE_ACTION_DROP:
return DOZTFILTER_DROP; return DOZTFILTER_DROP;

View file

@ -65,7 +65,8 @@ const OPEN_BLOCK_KEYWORDS = {
'tee': true, 'tee': true,
'watch': true, 'watch': true,
'redirect': true, 'redirect': true,
'break': true 'break': true,
'priority': true
}; };
// Reserved words that can't be used as tag, capability, or rule set names // Reserved words that can't be used as tag, capability, or rule set names
@ -81,6 +82,7 @@ const RESERVED_WORDS = {
'watch': true, 'watch': true,
'redirect': true, 'redirect': true,
'break': true, 'break': true,
'priority': true,
'ztsrc': true, 'ztsrc': true,
'ztdest': true, 'ztdest': true,
@ -131,6 +133,7 @@ const KEYWORD_TO_API_MAP = {
'watch': 'ACTION_WATCH', 'watch': 'ACTION_WATCH',
'redirect': 'ACTION_REDIRECT', 'redirect': 'ACTION_REDIRECT',
'break': 'ACTION_BREAK', 'break': 'ACTION_BREAK',
'priority': 'ACTION_PRIORITY',
'ztsrc': 'MATCH_SOURCE_ZEROTIER_ADDRESS', 'ztsrc': 'MATCH_SOURCE_ZEROTIER_ADDRESS',
'ztdest': 'MATCH_DEST_ZEROTIER_ADDRESS', 'ztdest': 'MATCH_DEST_ZEROTIER_ADDRESS',