networkd: VXLAN add support to configure port

This patch add support to configure port

PortRange:
VXLAN bases source UDP port based on flow to help the
receiver to be able to load balance based on outer header flow.

DestinatinPort:

Allow configuring the default destination port on a per-device basis.
This commit is contained in:
Susant Sahani
2016-01-19 12:17:54 +05:30
parent 17af840b1d
commit ea0288d17c
4 changed files with 146 additions and 0 deletions
+2
View File
@@ -57,6 +57,8 @@ VXLAN.UDP6ZeroCheckSumTx, config_parse_bool, 0,
VXLAN.FDBAgeingSec, config_parse_sec, 0, offsetof(VxLan, fdb_ageing)
VXLAN.GroupPolicyExtension, config_parse_bool, 0, offsetof(VxLan, group_policy)
VXLAN.MaximumFDBEntries, config_parse_unsigned, 0, offsetof(VxLan, max_fdb)
VXLAN.PortRange, config_parse_port_range, 0, 0
VXLAN.DestinationPort, config_parse_destination_port, 0, offsetof(VxLan, dest_port)
Tun.OneQueue, config_parse_bool, 0, offsetof(TunTap, one_queue)
Tun.MultiQueue, config_parse_bool, 0, offsetof(TunTap, multi_queue)
Tun.PacketInfo, config_parse_bool, 0, offsetof(TunTap, packet_info)
+100
View File
@@ -24,6 +24,8 @@
#include "sd-netlink.h"
#include "conf-parser.h"
#include "alloc-util.h"
#include "parse-util.h"
#include "missing.h"
#include "networkd-link.h"
#include "networkd-netdev-vxlan.h"
@@ -110,6 +112,21 @@ static int netdev_vxlan_fill_message_create(NetDev *netdev, Link *link, sd_netli
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_UDP_ZERO_CSUM6_RX attribute: %m");
r = sd_netlink_message_append_u16(m, IFLA_VXLAN_PORT, htobe16(v->dest_port));
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_PORT attribute: %m");
if (v->port_range.low || v->port_range.high) {
struct ifla_vxlan_port_range port_range;
port_range.low = htobe16(v->port_range.low);
port_range.high = htobe16(v->port_range.high);
r = sd_netlink_message_append_data(m, IFLA_VXLAN_PORT_RANGE, &port_range, sizeof(port_range));
if (r < 0)
return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_PORT_RANGE attribute: %m");
}
if (v->group_policy) {
r = sd_netlink_message_append_flag(m, IFLA_VXLAN_GBP);
if (r < 0)
@@ -155,6 +172,89 @@ int config_parse_vxlan_group_address(const char *unit,
return 0;
}
int config_parse_port_range(const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
_cleanup_free_ char *word = NULL;
VxLan *v = userdata;
unsigned low, high;
int r;
assert(filename);
assert(lvalue);
assert(rvalue);
assert(data);
r = extract_first_word(&rvalue, &word, NULL, 0);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r, "Failed to extract VXLAN port range, ignoring: %s", rvalue);
return 0;
}
if (r == 0)
return 0;
r = parse_range(word, &low, &high);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse VXLAN port range '%s'", word);
return 0;
}
if (low <= 0 || low > 65535 || high <= 0 || high > 65535) {
log_syntax(unit, LOG_ERR, filename, line, r,
"Failed to parse VXLAN port range '%s'. Port should be greater than 0 and less than 65535.", word);
return 0;
}
if (high < low) {
log_syntax(unit, LOG_ERR, filename, line, r,
"Failed to parse VXLAN port range '%s'. Port range %u .. %u not valid", word, low, high);
return 0;
}
v->port_range.low = low;
v->port_range.high = high;
return 0;
}
int config_parse_destination_port(const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
VxLan *v = userdata;
uint16_t port;
int r;
assert(filename);
assert(lvalue);
assert(rvalue);
assert(data);
r = safe_atou16(rvalue, &port);
if (r < 0 || port <= 0) {
log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse VXLAN destination port '%s'.", rvalue);
return 0;
}
v->dest_port = port;
return 0;
}
static int netdev_vxlan_verify(NetDev *netdev, const char *filename) {
VxLan *v = VXLAN(netdev);
+25
View File
@@ -40,6 +40,8 @@ struct VxLan {
unsigned ttl;
unsigned max_fdb;
uint16_t dest_port;
usec_t fdb_ageing;
bool learning;
@@ -51,6 +53,8 @@ struct VxLan {
bool udp6zerocsumtx;
bool udp6zerocsumrx;
bool group_policy;
struct ifla_vxlan_port_range port_range;
};
extern const NetDevVTable vxlan_vtable;
@@ -65,3 +69,24 @@ int config_parse_vxlan_group_address(const char *unit,
const char *rvalue,
void *data,
void *userdata);
int config_parse_port_range(const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata);
int config_parse_destination_port(const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata);