[systemd-commits] 5 commits - Makefile.am src/libsystemd src/network
Tom Gundersen
tomegun at kemper.freedesktop.org
Mon Jun 2 07:23:17 PDT 2014
Makefile.am | 1
src/libsystemd/sd-rtnl/rtnl-types.c | 29 ++++
src/network/networkd-netdev-gperf.gperf | 2
src/network/networkd-netdev.c | 15 +-
src/network/networkd-network.c | 3
src/network/networkd-tunnel.c | 213 ++++++++++++++++++++++++++++++++
src/network/networkd-veth.c | 134 ++++++++++++++++++++
src/network/networkd.h | 5
8 files changed, 397 insertions(+), 5 deletions(-)
New commits:
commit a613382bbf4357ce13f17c988713b80172e091fb
Author: Susant Sahani <susant at redhat.com>
Date: Fri May 23 12:07:46 2014 +0530
networkd: introduce vti tunnel
This patch enables vti tunnel support.
example conf:
file : vti.netdev
[NetDev]
Name=vti-tun
Kind=vti
MTUBytes=1480
[Tunnel]
Local=X.X.X.X
Remote=X.X.X.X
file: vti.network
[Match]
Name=em1
[Network]
Tunnel=vti-tun
TODO:
Add more attributes for vti tunnel
IFLA_VTI_IKEY
IFLA_VTI_OKEY
diff --git a/src/libsystemd/sd-rtnl/rtnl-types.c b/src/libsystemd/sd-rtnl/rtnl-types.c
index d32855d..2218afd 100644
--- a/src/libsystemd/sd-rtnl/rtnl-types.c
+++ b/src/libsystemd/sd-rtnl/rtnl-types.c
@@ -130,6 +130,14 @@ static const NLType rtnl_link_info_data_ipgre_types[IFLA_GRE_MAX + 1] = {
[IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
};
+static const NLType rtnl_link_info_data_ipvti_types[IFLA_VTI_MAX + 1] = {
+ [IFLA_VTI_LINK] = { .type = NLA_U32 },
+ [IFLA_VTI_IKEY] = { .type = NLA_U32 },
+ [IFLA_VTI_OKEY] = { .type = NLA_U32 },
+ [IFLA_VTI_LOCAL] = { .type = NLA_IN_ADDR },
+ [IFLA_VTI_REMOTE] = { .type = NLA_IN_ADDR },
+};
+
typedef enum NLUnionLinkInfoData {
NL_UNION_LINK_INFO_DATA_BOND,
NL_UNION_LINK_INFO_DATA_BRIDGE,
@@ -139,6 +147,7 @@ typedef enum NLUnionLinkInfoData {
NL_UNION_LINK_INFO_DATA_IPIP_TUNNEL,
NL_UNION_LINK_INFO_DATA_IPGRE_TUNNEL,
NL_UNION_LINK_INFO_DATA_SIT_TUNNEL,
+ NL_UNION_LINK_INFO_DATA_VTI_TUNNEL,
_NL_UNION_LINK_INFO_DATA_MAX,
_NL_UNION_LINK_INFO_DATA_INVALID = -1
} NLUnionLinkInfoData;
@@ -156,6 +165,7 @@ static const char* const nl_union_link_info_data_table[_NL_UNION_LINK_INFO_DATA_
[NL_UNION_LINK_INFO_DATA_IPIP_TUNNEL] = "ipip",
[NL_UNION_LINK_INFO_DATA_IPGRE_TUNNEL] = "gre",
[NL_UNION_LINK_INFO_DATA_SIT_TUNNEL] = "sit",
+ [NL_UNION_LINK_INFO_DATA_VTI_TUNNEL] = "vti",
};
DEFINE_STRING_TABLE_LOOKUP(nl_union_link_info_data, NLUnionLinkInfoData);
@@ -177,6 +187,8 @@ static const NLTypeSystem rtnl_link_info_data_type_systems[_NL_UNION_LINK_INFO_D
.types = rtnl_link_info_data_ipgre_types },
[NL_UNION_LINK_INFO_DATA_SIT_TUNNEL] = { .max = ELEMENTSOF(rtnl_link_info_data_iptun_types) - 1,
.types = rtnl_link_info_data_iptun_types },
+ [NL_UNION_LINK_INFO_DATA_VTI_TUNNEL] = { .max = ELEMENTSOF(rtnl_link_info_data_ipvti_types) - 1,
+ .types = rtnl_link_info_data_ipvti_types },
};
static const NLTypeSystemUnion rtnl_link_info_data_type_system_union = {
diff --git a/src/network/networkd-netdev.c b/src/network/networkd-netdev.c
index 4439374..1519419 100644
--- a/src/network/networkd-netdev.c
+++ b/src/network/networkd-netdev.c
@@ -39,6 +39,7 @@ static const char* const netdev_kind_table[_NETDEV_KIND_MAX] = {
[NETDEV_KIND_GRE] = "gre",
[NETDEV_KIND_SIT] = "sit",
[NETDEV_KIND_VETH] = "veth",
+ [NETDEV_KIND_VTI] = "vti"
};
DEFINE_STRING_TABLE_LOOKUP(netdev_kind, NetDevKind);
@@ -393,7 +394,8 @@ int netdev_enslave(NetDev *netdev, Link *link, sd_rtnl_message_handler_t callbac
if(netdev->kind == NETDEV_KIND_IPIP ||
netdev->kind == NETDEV_KIND_GRE ||
- netdev->kind == NETDEV_KIND_SIT)
+ netdev->kind == NETDEV_KIND_SIT ||
+ netdev->kind == NETDEV_KIND_VTI)
return netdev_create_tunnel(link, netdev_create_handler);
if (netdev->state == NETDEV_STATE_READY) {
@@ -606,7 +608,8 @@ static int netdev_load_one(Manager *manager, const char *filename) {
netdev->kind != NETDEV_KIND_MACVLAN &&
netdev->kind != NETDEV_KIND_IPIP &&
netdev->kind != NETDEV_KIND_GRE &&
- netdev->kind != NETDEV_KIND_SIT) {
+ netdev->kind != NETDEV_KIND_SIT &&
+ netdev->kind != NETDEV_KIND_VTI) {
r = netdev_create(netdev, NULL, NULL);
if (r < 0)
return r;
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
index a6cbee2..f42fc17 100644
--- a/src/network/networkd-network.c
+++ b/src/network/networkd-network.c
@@ -363,7 +363,8 @@ int config_parse_tunnel(const char *unit,
if (netdev->kind != NETDEV_KIND_IPIP &&
netdev->kind != NETDEV_KIND_SIT &&
- netdev->kind != NETDEV_KIND_GRE) {
+ netdev->kind != NETDEV_KIND_GRE &&
+ netdev->kind != NETDEV_KIND_VTI) {
log_syntax(unit, LOG_ERR, filename, line, EINVAL,
"NetDev is not a tunnel, ignoring assignment: %s", rvalue);
return 0;
diff --git a/src/network/networkd-tunnel.c b/src/network/networkd-tunnel.c
index 1a06a17..e3ceb8b 100644
--- a/src/network/networkd-tunnel.c
+++ b/src/network/networkd-tunnel.c
@@ -339,6 +339,94 @@ static int netdev_fill_ipgre_rtnl_message(Link *link, sd_rtnl_message *m) {
return r;
}
+static int netdev_fill_vti_rtnl_message(Link *link, sd_rtnl_message *m) {
+ NetDev *netdev;
+ int r;
+
+ assert(link);
+ assert(link->network);
+ assert(link->network->tunnel);
+ assert(m);
+
+ netdev = link->network->tunnel;
+
+ r = sd_rtnl_message_append_string(m, IFLA_IFNAME, netdev->ifname);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not append IFLA_IFNAME, attribute: %s",
+ strerror(-r));
+ return r;
+ }
+
+ if(netdev->mtu) {
+ r = sd_rtnl_message_append_u32(m, IFLA_MTU, netdev->mtu);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not append IFLA_MTU attribute: %s",
+ strerror(-r));
+ return r;
+ }
+ }
+
+ r = sd_rtnl_message_open_container(m, IFLA_LINKINFO);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not append IFLA_LINKINFO attribute: %s",
+ strerror(-r));
+ return r;
+ }
+
+ r = sd_rtnl_message_open_container_union(m, IFLA_INFO_DATA,
+ netdev_kind_to_string(netdev->kind));
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not append IFLA_INFO_DATA attribute: %s",
+ strerror(-r));
+ return r;
+ }
+
+ r = sd_rtnl_message_append_u32(m, IFLA_VTI_LINK, link->ifindex);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not append IFLA_IPTUN_LINK attribute: %s",
+ strerror(-r));
+ return r;
+ }
+
+ r = sd_rtnl_message_append_in_addr(m, IFLA_VTI_LOCAL, &netdev->tunnel_local);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not append IFLA_IPTUN_LOCAL attribute: %s",
+ strerror(-r));
+ return r;
+ }
+
+ r = sd_rtnl_message_append_in_addr(m, IFLA_VTI_REMOTE, &netdev->tunnel_remote);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not append IFLA_IPTUN_REMOTE attribute: %s",
+ strerror(-r));
+ return r;
+ }
+
+ r = sd_rtnl_message_close_container(m);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not append IFLA_INFO_DATA attribute: %s",
+ strerror(-r));
+ return r;
+ }
+
+ r = sd_rtnl_message_close_container(m);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not append IFLA_LINKINFO attribute: %s",
+ strerror(-r));
+ return r;
+ }
+
+ return r;
+}
int netdev_create_tunnel(Link *link, sd_rtnl_message_handler_t callback) {
_cleanup_rtnl_message_unref_ sd_rtnl_message *m = NULL;
@@ -371,6 +459,8 @@ int netdev_create_tunnel(Link *link, sd_rtnl_message_handler_t callback) {
return r;
}
break;
+ case NETDEV_KIND_VTI:
+ break;
default:
return -ENOTSUP;
}
@@ -394,6 +484,11 @@ int netdev_create_tunnel(Link *link, sd_rtnl_message_handler_t callback) {
if(r < 0)
return r;
break;
+ case NETDEV_KIND_VTI:
+ netdev_fill_vti_rtnl_message(link, m);
+ if(r < 0)
+ return r;
+ break;
case NETDEV_KIND_GRE:
r = netdev_fill_ipgre_rtnl_message(link, m);
if(r < 0)
diff --git a/src/network/networkd.h b/src/network/networkd.h
index 6f69c9a..82d8d70 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -72,6 +72,7 @@ typedef enum NetDevKind {
NETDEV_KIND_GRE,
NETDEV_KIND_SIT,
NETDEV_KIND_VETH,
+ NETDEV_KIND_VTI,
_NETDEV_KIND_MAX,
_NETDEV_KIND_INVALID = -1
} NetDevKind;
commit a9f434cf00d1d36d9a013b9739efe69653dd7279
Author: Susant Sahani <susant at redhat.com>
Date: Thu May 22 11:59:19 2014 +0530
networkd: sit-tunnel add support for pmtudisc
This patch adds path of mtu discovery for sit tunnel.
To enable/disable DiscoverPathMTU is introduced.
Example configuration
file: sit.netdev
[NetDev]
Name=sit-tun
Kind=sit
MTUBytes=1480
[Tunnel]
DiscoverPathMTU=1
Local=X.X.X.X
Remote=X.X.X.X
By default pmtudisc is turned on , if DiscoverPathMTU
is missing from the config. To turn it off
DiscoverPathMTU=0 needs to be set.
diff --git a/src/network/networkd-netdev-gperf.gperf b/src/network/networkd-netdev-gperf.gperf
index f39c922..dff0ae6 100644
--- a/src/network/networkd-netdev-gperf.gperf
+++ b/src/network/networkd-netdev-gperf.gperf
@@ -29,4 +29,5 @@ Tunnel.Local, config_parse_tunnel_address, 0,
Tunnel.Remote, config_parse_tunnel_address, 0, offsetof(NetDev, tunnel_remote)
Tunnel.TOS, config_parse_unsigned, 0, offsetof(NetDev, tunnel_tos)
Tunnel.TTL, config_parse_unsigned, 0, offsetof(NetDev, tunnel_ttl)
+Tunnel.DiscoverPathMTU, config_parse_bool, 0, offsetof(NetDev, tunnel_pmtudisc)
Peer.Name, config_parse_ifname, 0, offsetof(NetDev, ifname_peer)
diff --git a/src/network/networkd-netdev.c b/src/network/networkd-netdev.c
index 1036daf..4439374 100644
--- a/src/network/networkd-netdev.c
+++ b/src/network/networkd-netdev.c
@@ -545,6 +545,7 @@ static int netdev_load_one(Manager *manager, const char *filename) {
netdev->kind = _NETDEV_KIND_INVALID;
netdev->macvlan_mode = _NETDEV_MACVLAN_MODE_INVALID;
netdev->vlanid = VLANID_MAX + 1;
+ netdev->tunnel_pmtudisc = true;
r = config_parse(NULL, filename, file, "Match\0NetDev\0VLAN\0MACVLAN\0Tunnel\0Peer\0",
config_item_perf_lookup, (void*) network_netdev_gperf_lookup,
diff --git a/src/network/networkd-tunnel.c b/src/network/networkd-tunnel.c
index 9b4cb4f..1a06a17 100644
--- a/src/network/networkd-tunnel.c
+++ b/src/network/networkd-tunnel.c
@@ -207,6 +207,14 @@ static int netdev_fill_sit_rtnl_message(Link *link, sd_rtnl_message *m) {
return r;
}
+ r = sd_rtnl_message_append_u8(m, IFLA_IPTUN_PMTUDISC, netdev->tunnel_pmtudisc);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not append IFLA_IPTUN_PMTUDISC attribute: %s",
+ strerror(-r));
+ return r;
+ }
+
r = sd_rtnl_message_close_container(m);
if (r < 0) {
log_error_netdev(netdev,
diff --git a/src/network/networkd.h b/src/network/networkd.h
index e504854..6f69c9a 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -109,6 +109,7 @@ struct NetDev {
int ifindex;
NetDevState state;
+ bool tunnel_pmtudisc;
unsigned tunnel_ttl;
unsigned tunnel_tos;
struct in_addr tunnel_local;
commit 8bb088c5d44e566eb101e3f093d690aeb2a82285
Author: Susant Sahani <susant at redhat.com>
Date: Thu May 22 16:05:03 2014 +0530
networkd: introduce gre tunnel
This patch enables gre tunnel support.
example conf:
file : gre.netdev
[NetDev]
Name=gre-tun
Kind=gre
MTUBytes=1480
[Tunnel]
Local=X.X.X.X
Remote=X.X.X.X
file: gre.network
[Match]
Name=em1
[Network]
Tunnel=gre-tun
TODO:
Add more attributes for gre tunnel
IFLA_GRE_IFLAGS
IFLA_GRE_IFLAGS
IFLA_GRE_IKEY
IFLA_GRE_OKEY
diff --git a/src/libsystemd/sd-rtnl/rtnl-types.c b/src/libsystemd/sd-rtnl/rtnl-types.c
index 96467a3..d32855d 100644
--- a/src/libsystemd/sd-rtnl/rtnl-types.c
+++ b/src/libsystemd/sd-rtnl/rtnl-types.c
@@ -117,6 +117,19 @@ static const NLType rtnl_link_info_data_iptun_types[IFLA_IPTUN_MAX + 1] = {
[IFLA_IPTUN_6RD_RELAY_PREFIXLEN] = { .type = NLA_U16 },
};
+static const NLType rtnl_link_info_data_ipgre_types[IFLA_GRE_MAX + 1] = {
+ [IFLA_GRE_LINK] = { .type = NLA_U32 },
+ [IFLA_GRE_IFLAGS] = { .type = NLA_U16 },
+ [IFLA_GRE_OFLAGS] = { .type = NLA_U16 },
+ [IFLA_GRE_IKEY] = { .type = NLA_U32 },
+ [IFLA_GRE_OKEY] = { .type = NLA_U32 },
+ [IFLA_GRE_LOCAL] = { .type = NLA_IN_ADDR },
+ [IFLA_GRE_REMOTE] = { .type = NLA_IN_ADDR },
+ [IFLA_GRE_TTL] = { .type = NLA_U8 },
+ [IFLA_GRE_TOS] = { .type = NLA_U8 },
+ [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
+};
+
typedef enum NLUnionLinkInfoData {
NL_UNION_LINK_INFO_DATA_BOND,
NL_UNION_LINK_INFO_DATA_BRIDGE,
@@ -124,6 +137,7 @@ typedef enum NLUnionLinkInfoData {
NL_UNION_LINK_INFO_DATA_VETH,
NL_UNION_LINK_INFO_DATA_MACVLAN,
NL_UNION_LINK_INFO_DATA_IPIP_TUNNEL,
+ NL_UNION_LINK_INFO_DATA_IPGRE_TUNNEL,
NL_UNION_LINK_INFO_DATA_SIT_TUNNEL,
_NL_UNION_LINK_INFO_DATA_MAX,
_NL_UNION_LINK_INFO_DATA_INVALID = -1
@@ -140,6 +154,7 @@ static const char* const nl_union_link_info_data_table[_NL_UNION_LINK_INFO_DATA_
[NL_UNION_LINK_INFO_DATA_VETH] = "veth",
[NL_UNION_LINK_INFO_DATA_MACVLAN] = "macvlan",
[NL_UNION_LINK_INFO_DATA_IPIP_TUNNEL] = "ipip",
+ [NL_UNION_LINK_INFO_DATA_IPGRE_TUNNEL] = "gre",
[NL_UNION_LINK_INFO_DATA_SIT_TUNNEL] = "sit",
};
@@ -158,6 +173,8 @@ static const NLTypeSystem rtnl_link_info_data_type_systems[_NL_UNION_LINK_INFO_D
.types = rtnl_link_info_data_macvlan_types },
[NL_UNION_LINK_INFO_DATA_IPIP_TUNNEL] = { .max = ELEMENTSOF(rtnl_link_info_data_iptun_types) - 1,
.types = rtnl_link_info_data_iptun_types },
+ [NL_UNION_LINK_INFO_DATA_IPGRE_TUNNEL] = { .max = ELEMENTSOF(rtnl_link_info_data_ipgre_types) - 1,
+ .types = rtnl_link_info_data_ipgre_types },
[NL_UNION_LINK_INFO_DATA_SIT_TUNNEL] = { .max = ELEMENTSOF(rtnl_link_info_data_iptun_types) - 1,
.types = rtnl_link_info_data_iptun_types },
};
diff --git a/src/network/networkd-tunnel.c b/src/network/networkd-tunnel.c
index fee474c..9b4cb4f 100644
--- a/src/network/networkd-tunnel.c
+++ b/src/network/networkd-tunnel.c
@@ -226,6 +226,112 @@ static int netdev_fill_sit_rtnl_message(Link *link, sd_rtnl_message *m) {
return r;
}
+static int netdev_fill_ipgre_rtnl_message(Link *link, sd_rtnl_message *m) {
+ NetDev *netdev;
+ int r;
+
+ assert(link);
+ assert(link->network);
+ assert(link->network->tunnel);
+ assert(m);
+
+ netdev = link->network->tunnel;
+
+ r = sd_rtnl_message_append_string(m, IFLA_IFNAME, netdev->ifname);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not append IFLA_IFNAME, attribute: %s",
+ strerror(-r));
+ return r;
+ }
+
+ if(netdev->mtu) {
+ r = sd_rtnl_message_append_u32(m, IFLA_MTU, netdev->mtu);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not append IFLA_MTU attribute: %s",
+ strerror(-r));
+ return r;
+ }
+ }
+
+ r = sd_rtnl_message_open_container(m, IFLA_LINKINFO);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not append IFLA_LINKINFO attribute: %s",
+ strerror(-r));
+ return r;
+ }
+
+ r = sd_rtnl_message_open_container_union(m, IFLA_INFO_DATA,
+ netdev_kind_to_string(netdev->kind));
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not append IFLA_INFO_DATA attribute: %s",
+ strerror(-r));
+ return r;
+ }
+
+ r = sd_rtnl_message_append_u32(m, IFLA_GRE_LINK, link->ifindex);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not append IFLA_GRE_LINK attribute: %s",
+ strerror(-r));
+ return r;
+ }
+
+ r = sd_rtnl_message_append_in_addr(m, IFLA_GRE_LOCAL, &netdev->tunnel_local);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not append IFLA_GRE_LOCAL attribute: %s",
+ strerror(-r));
+ return r;
+ }
+
+ r = sd_rtnl_message_append_in_addr(m, IFLA_GRE_REMOTE, &netdev->tunnel_remote);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not append IFLA_GRE_REMOTE attribute: %s",
+ strerror(-r));
+ return r;
+ }
+
+ r = sd_rtnl_message_append_u8(m, IFLA_GRE_TTL, netdev->tunnel_ttl);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not append IFLA_GRE_TTL attribute: %s",
+ strerror(-r));
+ return r;
+ }
+
+ r = sd_rtnl_message_append_u8(m, IFLA_GRE_TOS, netdev->tunnel_tos);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not append IFLA_GRE_TOS attribute: %s",
+ strerror(-r));
+ return r;
+ }
+
+ r = sd_rtnl_message_close_container(m);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not append IFLA_INFO_DATA attribute: %s",
+ strerror(-r));
+ return r;
+ }
+
+ r = sd_rtnl_message_close_container(m);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not append IFLA_LINKINFO attribute: %s",
+ strerror(-r));
+ return r;
+ }
+
+ return r;
+}
+
+
int netdev_create_tunnel(Link *link, sd_rtnl_message_handler_t callback) {
_cleanup_rtnl_message_unref_ sd_rtnl_message *m = NULL;
NetDev *netdev;
@@ -281,6 +387,10 @@ int netdev_create_tunnel(Link *link, sd_rtnl_message_handler_t callback) {
return r;
break;
case NETDEV_KIND_GRE:
+ r = netdev_fill_ipgre_rtnl_message(link, m);
+ if(r < 0)
+ return r;
+ break;
default:
return -ENOTSUP;
}
commit 4d7ec9fc36780ecad244d0cc35db737fffe95b8b
Author: Susant Sahani <susant at redhat.com>
Date: Wed May 21 15:25:30 2014 +0530
networkd-netdev: fix white space
diff --git a/src/network/networkd-netdev.c b/src/network/networkd-netdev.c
index 472028c..1036daf 100644
--- a/src/network/networkd-netdev.c
+++ b/src/network/networkd-netdev.c
@@ -449,7 +449,6 @@ int netdev_set_ifindex(NetDev *netdev, sd_rtnl_message *message) {
return r;
}
-
if (netdev->ifindex > 0) {
if (netdev->ifindex != ifindex) {
log_error_netdev(netdev, "Could not set ifindex to %d, already set to %d",
commit 10142d75cce10a92889cc11b7b1af07fecc78c5d
Author: Susant Sahani <susant at redhat.com>
Date: Wed May 21 14:01:04 2014 +0530
networkd: introduce veth device support
This patch adds veth device support to networkd.
Example conf:
File: veth.netdev
[NetDev]
Name=veth-test
Kind=veth
[Peer]
Name=veth-peer
diff --git a/Makefile.am b/Makefile.am
index 5158bbc..d2f2880 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -4269,6 +4269,7 @@ libsystemd_networkd_core_la_SOURCES = \
src/network/networkd-link.c \
src/network/networkd-netdev.c \
src/network/networkd-tunnel.c \
+ src/network/networkd-veth.c \
src/network/networkd-network.c \
src/network/networkd-address.c \
src/network/networkd-route.c \
diff --git a/src/network/networkd-netdev-gperf.gperf b/src/network/networkd-netdev-gperf.gperf
index 29889cd..f39c922 100644
--- a/src/network/networkd-netdev-gperf.gperf
+++ b/src/network/networkd-netdev-gperf.gperf
@@ -29,3 +29,4 @@ Tunnel.Local, config_parse_tunnel_address, 0,
Tunnel.Remote, config_parse_tunnel_address, 0, offsetof(NetDev, tunnel_remote)
Tunnel.TOS, config_parse_unsigned, 0, offsetof(NetDev, tunnel_tos)
Tunnel.TTL, config_parse_unsigned, 0, offsetof(NetDev, tunnel_ttl)
+Peer.Name, config_parse_ifname, 0, offsetof(NetDev, ifname_peer)
diff --git a/src/network/networkd-netdev.c b/src/network/networkd-netdev.c
index c54b0c1..472028c 100644
--- a/src/network/networkd-netdev.c
+++ b/src/network/networkd-netdev.c
@@ -38,6 +38,7 @@ static const char* const netdev_kind_table[_NETDEV_KIND_MAX] = {
[NETDEV_KIND_IPIP] = "ipip",
[NETDEV_KIND_GRE] = "gre",
[NETDEV_KIND_SIT] = "sit",
+ [NETDEV_KIND_VETH] = "veth",
};
DEFINE_STRING_TABLE_LOOKUP(netdev_kind, NetDevKind);
@@ -546,7 +547,7 @@ static int netdev_load_one(Manager *manager, const char *filename) {
netdev->macvlan_mode = _NETDEV_MACVLAN_MODE_INVALID;
netdev->vlanid = VLANID_MAX + 1;
- r = config_parse(NULL, filename, file, "Match\0NetDev\0VLAN\0MACVLAN\0Tunnel\0",
+ r = config_parse(NULL, filename, file, "Match\0NetDev\0VLAN\0MACVLAN\0Tunnel\0Peer\0",
config_item_perf_lookup, (void*) network_netdev_gperf_lookup,
false, false, netdev);
if (r < 0) {
@@ -598,6 +599,9 @@ static int netdev_load_one(Manager *manager, const char *filename) {
LIST_HEAD_INIT(netdev->callbacks);
+ if(netdev->kind == NETDEV_KIND_VETH)
+ return netdev_create_veth(netdev, netdev_create_handler);
+
if (netdev->kind != NETDEV_KIND_VLAN &&
netdev->kind != NETDEV_KIND_MACVLAN &&
netdev->kind != NETDEV_KIND_IPIP &&
diff --git a/src/network/networkd-veth.c b/src/network/networkd-veth.c
new file mode 100644
index 0000000..1a5d880
--- /dev/null
+++ b/src/network/networkd-veth.c
@@ -0,0 +1,134 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+ This file is part of systemd.
+
+ Copyright 2014 Susant Sahani <susant at redhat.com>
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <netinet/ether.h>
+#include <arpa/inet.h>
+#include <net/if.h>
+#include <linux/veth.h>
+
+#include "sd-rtnl.h"
+#include "networkd.h"
+
+
+static int netdev_fill_veth_rtnl_message(NetDev *netdev, sd_rtnl_message *m) {
+ int r;
+
+ assert(netdev);
+ assert(m);
+
+ r = sd_rtnl_message_append_string(m, IFLA_IFNAME, netdev->ifname);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not append IFLA_IFNAME, attribute: %s",
+ strerror(-r));
+ return r;
+ }
+
+ r = sd_rtnl_message_open_container(m, IFLA_LINKINFO);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not append IFLA_LINKINFO attribute: %s",
+ strerror(-r));
+ return r;
+ }
+
+ r = sd_rtnl_message_open_container_union(m, IFLA_INFO_DATA,
+ netdev_kind_to_string(netdev->kind));
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not append IFLA_INFO_DATA attribute: %s",
+ strerror(-r));
+ return r;
+ }
+
+ r = sd_rtnl_message_open_container(m, VETH_INFO_PEER);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not append IFLA_IPTUN_LINK attribute: %s",
+ strerror(-r));
+ return r;
+ }
+
+ if(netdev->ifname_peer) {
+ r = sd_rtnl_message_append_string(m, IFLA_IFNAME, netdev->ifname_peer);
+ if (r < 0) {
+ log_error("Failed to add netlink interface name: %s", strerror(-r));
+ return r;
+ }
+ }
+
+ r = sd_rtnl_message_close_container(m);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not append IFLA_INFO_DATA attribute: %s",
+ strerror(-r));
+ return r;
+ }
+
+ r = sd_rtnl_message_close_container(m);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not append IFLA_LINKINFO attribute: %s",
+ strerror(-r));
+ return r;
+ }
+
+ return r;
+}
+
+int netdev_create_veth(NetDev *netdev, sd_rtnl_message_handler_t callback) {
+ _cleanup_rtnl_message_unref_ sd_rtnl_message *m = NULL;
+ int r;
+
+ assert(netdev);
+ assert(netdev->ifname);
+ assert(netdev->manager);
+ assert(netdev->manager->rtnl);
+
+ r = sd_rtnl_message_new_link(netdev->manager->rtnl, &m, RTM_NEWLINK, 0);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not allocate RTM_NEWLINK message: %s",
+ strerror(-r));
+ return r;
+ }
+
+ if(netdev->kind != NETDEV_KIND_VETH)
+ return -ENOTSUP;
+
+ r = netdev_fill_veth_rtnl_message(netdev, m);
+ if(r < 0)
+ return r;
+
+ r = sd_rtnl_call_async(netdev->manager->rtnl, m, callback, netdev, 0, NULL);
+ if (r < 0) {
+ log_error_netdev(netdev,
+ "Could not send rtnetlink message: %s", strerror(-r));
+ return r;
+ }
+
+ log_debug_netdev(netdev, "Creating veth netdev: %s",
+ netdev_kind_to_string(netdev->kind));
+
+ netdev->state = NETDEV_STATE_CREATING;
+
+ return 0;
+}
diff --git a/src/network/networkd.h b/src/network/networkd.h
index cfe24f5..e504854 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -71,6 +71,7 @@ typedef enum NetDevKind {
NETDEV_KIND_IPIP,
NETDEV_KIND_GRE,
NETDEV_KIND_SIT,
+ NETDEV_KIND_VETH,
_NETDEV_KIND_MAX,
_NETDEV_KIND_INVALID = -1
} NetDevKind;
@@ -98,6 +99,7 @@ struct NetDev {
char *description;
char *ifname;
+ char *ifname_peer;
size_t mtu;
NetDevKind kind;
@@ -310,6 +312,7 @@ int netdev_get(Manager *manager, const char *name, NetDev **ret);
int netdev_set_ifindex(NetDev *netdev, sd_rtnl_message *newlink);
int netdev_enslave(NetDev *netdev, Link *link, sd_rtnl_message_handler_t cb);
int netdev_create_tunnel(Link *link, sd_rtnl_message_handler_t callback);
+int netdev_create_veth(NetDev *netdev, sd_rtnl_message_handler_t callback);
const char *netdev_kind_to_string(NetDevKind d) _const_;
NetDevKind netdev_kind_from_string(const char *d) _pure_;
More information about the systemd-commits
mailing list