networkd: Add support for ERSPAN tunnel
Please see: https://patchwork.ozlabs.org/patch/800327/ ``` [NetDev] Name=erspan-test Kind=erspan [Tunnel] Independent=true ERSPANIndex=123 Local = 172.16.1.200 Remote = 172.16.1.100 Key=101 SerializeTunneledPackets=true ```
This commit is contained in:
committed by
Yu Watanabe
parent
5c6b51ff79
commit
2266864b04
@@ -71,6 +71,8 @@ Tunnel.FOUDestinationPort, config_parse_ip_port, 0,
|
||||
Tunnel.FOUSourcePort, config_parse_ip_port, 0, offsetof(Tunnel, encap_src_port)
|
||||
Tunnel.Encapsulation, config_parse_fou_encap_type, 0, offsetof(Tunnel, fou_encap_type)
|
||||
Tunnel.IPv6RapidDeploymentPrefix, config_parse_6rd_prefix, 0, 0
|
||||
Tunnel.ERSPANIndex, config_parse_uint32, 0, offsetof(Tunnel, erspan_index)
|
||||
Tunnel.SerializeTunneledPackets, config_parse_tristate, 0, offsetof(Tunnel, erspan_sequence)
|
||||
FooOverUDP.Protocol, config_parse_uint8, 0, offsetof(FouTunnel, fou_protocol)
|
||||
FooOverUDP.Encapsulation, config_parse_fou_encap_type, 0, offsetof(FouTunnel, fou_encap_type)
|
||||
FooOverUDP.Port, config_parse_ip_port, 0, offsetof(FouTunnel, port)
|
||||
|
||||
@@ -64,6 +64,7 @@ const NetDevVTable * const netdev_vtable[_NETDEV_KIND_MAX] = {
|
||||
[NETDEV_KIND_WIREGUARD] = &wireguard_vtable,
|
||||
[NETDEV_KIND_NETDEVSIM] = &netdevsim_vtable,
|
||||
[NETDEV_KIND_FOU] = &foutnl_vtable,
|
||||
[NETDEV_KIND_ERSPAN] = &erspan_vtable,
|
||||
};
|
||||
|
||||
static const char* const netdev_kind_table[_NETDEV_KIND_MAX] = {
|
||||
@@ -94,6 +95,7 @@ static const char* const netdev_kind_table[_NETDEV_KIND_MAX] = {
|
||||
[NETDEV_KIND_WIREGUARD] = "wireguard",
|
||||
[NETDEV_KIND_NETDEVSIM] = "netdevsim",
|
||||
[NETDEV_KIND_FOU] = "fou",
|
||||
[NETDEV_KIND_ERSPAN] = "erspan",
|
||||
};
|
||||
|
||||
DEFINE_STRING_TABLE_LOOKUP(netdev_kind, NetDevKind);
|
||||
|
||||
@@ -45,6 +45,7 @@ typedef enum NetDevKind {
|
||||
NETDEV_KIND_WIREGUARD,
|
||||
NETDEV_KIND_NETDEVSIM,
|
||||
NETDEV_KIND_FOU,
|
||||
NETDEV_KIND_ERSPAN,
|
||||
_NETDEV_KIND_MAX,
|
||||
_NETDEV_KIND_INVALID = -1
|
||||
} NetDevKind;
|
||||
|
||||
+102
-2
@@ -173,6 +173,77 @@ static int netdev_gre_fill_message_create(NetDev *netdev, Link *link, sd_netlink
|
||||
return r;
|
||||
}
|
||||
|
||||
static int netdev_erspan_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
|
||||
uint32_t ikey = 0;
|
||||
uint32_t okey = 0;
|
||||
uint16_t iflags = 0;
|
||||
uint16_t oflags = 0;
|
||||
Tunnel *t;
|
||||
int r;
|
||||
|
||||
assert(netdev);
|
||||
|
||||
t = ERSPAN(netdev);
|
||||
|
||||
assert(t);
|
||||
assert(IN_SET(t->family, AF_INET, AF_UNSPEC));
|
||||
assert(m);
|
||||
|
||||
r = sd_netlink_message_append_u32(m, IFLA_GRE_ERSPAN_INDEX, t->erspan_index);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_ERSPAN_INDEX attribute: %m");
|
||||
|
||||
if (t->key != 0) {
|
||||
ikey = okey = htobe32(t->key);
|
||||
iflags |= GRE_KEY;
|
||||
oflags |= GRE_KEY;
|
||||
}
|
||||
|
||||
if (t->ikey != 0) {
|
||||
ikey = htobe32(t->ikey);
|
||||
iflags |= GRE_KEY;
|
||||
}
|
||||
|
||||
if (t->okey != 0) {
|
||||
okey = htobe32(t->okey);
|
||||
oflags |= GRE_KEY;
|
||||
}
|
||||
|
||||
if (t->erspan_sequence > 0) {
|
||||
iflags |= GRE_SEQ;
|
||||
oflags |= GRE_SEQ;
|
||||
} else if (t->erspan_sequence == 0) {
|
||||
iflags &= ~GRE_SEQ;
|
||||
oflags &= ~GRE_SEQ;
|
||||
}
|
||||
|
||||
r = sd_netlink_message_append_u32(m, IFLA_GRE_IKEY, ikey);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_IKEY attribute: %m");
|
||||
|
||||
r = sd_netlink_message_append_u32(m, IFLA_GRE_OKEY, okey);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_OKEY attribute: %m");
|
||||
|
||||
r = sd_netlink_message_append_u16(m, IFLA_GRE_IFLAGS, iflags);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_IFLAGS attribute: %m");
|
||||
|
||||
r = sd_netlink_message_append_u16(m, IFLA_GRE_OFLAGS, oflags);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_OFLAGS, attribute: %m");
|
||||
|
||||
r = sd_netlink_message_append_in_addr(m, IFLA_GRE_LOCAL, &t->local.in);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_LOCAL attribute: %m");
|
||||
|
||||
r = sd_netlink_message_append_in_addr(m, IFLA_GRE_REMOTE, &t->remote.in);
|
||||
if (r < 0)
|
||||
log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_REMOTE attribute: %m");
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static int netdev_ip6gre_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
|
||||
Tunnel *t;
|
||||
int r;
|
||||
@@ -415,6 +486,9 @@ static int netdev_tunnel_verify(NetDev *netdev, const char *filename) {
|
||||
case NETDEV_KIND_IP6TNL:
|
||||
t = IP6TNL(netdev);
|
||||
break;
|
||||
case NETDEV_KIND_ERSPAN:
|
||||
t = ERSPAN(netdev);
|
||||
break;
|
||||
default:
|
||||
assert_not_reached("Invalid tunnel kind");
|
||||
}
|
||||
@@ -427,10 +501,10 @@ static int netdev_tunnel_verify(NetDev *netdev, const char *filename) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (IN_SET(netdev->kind, NETDEV_KIND_VTI, NETDEV_KIND_IPIP, NETDEV_KIND_SIT, NETDEV_KIND_GRE, NETDEV_KIND_GRETAP) &&
|
||||
if (IN_SET(netdev->kind, NETDEV_KIND_VTI, NETDEV_KIND_IPIP, NETDEV_KIND_SIT, NETDEV_KIND_GRE, NETDEV_KIND_GRETAP, NETDEV_KIND_ERSPAN) &&
|
||||
(t->family != AF_INET || in_addr_is_null(t->family, &t->local))) {
|
||||
log_netdev_error(netdev,
|
||||
"vti/ipip/sit/gre/gretap tunnel without a local IPv4 address configured in %s. Ignoring", filename);
|
||||
"vti/ipip/sit/gre/gretap/erspan tunnel without a local IPv4 address configured in %s. Ignoring", filename);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@@ -453,6 +527,11 @@ static int netdev_tunnel_verify(NetDev *netdev, const char *filename) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (netdev->kind == NETDEV_KIND_ERSPAN && (t->erspan_index >= (1 << 20) || t->erspan_index == 0)) {
|
||||
log_netdev_error(netdev, "Invalid erspan index %d. Ignoring", t->erspan_index);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -729,6 +808,18 @@ static void ip6gre_init(NetDev *n) {
|
||||
t->ttl = DEFAULT_TNL_HOP_LIMIT;
|
||||
}
|
||||
|
||||
static void erspan_init(NetDev *n) {
|
||||
Tunnel *t;
|
||||
|
||||
assert(n);
|
||||
|
||||
t = ERSPAN(n);
|
||||
|
||||
assert(t);
|
||||
|
||||
t->erspan_sequence = -1;
|
||||
}
|
||||
|
||||
static void ip6tnl_init(NetDev *n) {
|
||||
Tunnel *t = IP6TNL(n);
|
||||
|
||||
@@ -822,3 +913,12 @@ const NetDevVTable ip6tnl_vtable = {
|
||||
.create_type = NETDEV_CREATE_STACKED,
|
||||
.config_verify = netdev_tunnel_verify,
|
||||
};
|
||||
|
||||
const NetDevVTable erspan_vtable = {
|
||||
.object_size = sizeof(Tunnel),
|
||||
.init = erspan_init,
|
||||
.sections = "Match\0NetDev\0Tunnel\0",
|
||||
.fill_message_create = netdev_erspan_fill_message_create,
|
||||
.create_type = NETDEV_CREATE_INDEPENDENT,
|
||||
.config_verify = netdev_tunnel_verify,
|
||||
};
|
||||
|
||||
@@ -29,6 +29,7 @@ typedef struct Tunnel {
|
||||
int family;
|
||||
int ipv6_flowlabel;
|
||||
int allow_localremote;
|
||||
int erspan_sequence;
|
||||
|
||||
unsigned ttl;
|
||||
unsigned tos;
|
||||
@@ -37,6 +38,7 @@ typedef struct Tunnel {
|
||||
uint32_t key;
|
||||
uint32_t ikey;
|
||||
uint32_t okey;
|
||||
uint32_t erspan_index;
|
||||
|
||||
union in_addr_union local;
|
||||
union in_addr_union remote;
|
||||
@@ -65,6 +67,7 @@ DEFINE_NETDEV_CAST(SIT, Tunnel);
|
||||
DEFINE_NETDEV_CAST(VTI, Tunnel);
|
||||
DEFINE_NETDEV_CAST(VTI6, Tunnel);
|
||||
DEFINE_NETDEV_CAST(IP6TNL, Tunnel);
|
||||
DEFINE_NETDEV_CAST(ERSPAN, Tunnel);
|
||||
extern const NetDevVTable ipip_vtable;
|
||||
extern const NetDevVTable sit_vtable;
|
||||
extern const NetDevVTable vti_vtable;
|
||||
@@ -74,6 +77,7 @@ extern const NetDevVTable gretap_vtable;
|
||||
extern const NetDevVTable ip6gre_vtable;
|
||||
extern const NetDevVTable ip6gretap_vtable;
|
||||
extern const NetDevVTable ip6tnl_vtable;
|
||||
extern const NetDevVTable erspan_vtable;
|
||||
|
||||
const char *ip6tnl_mode_to_string(Ip6TnlMode d) _const_;
|
||||
Ip6TnlMode ip6tnl_mode_from_string(const char *d) _pure_;
|
||||
|
||||
Reference in New Issue
Block a user