summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLukas Märdian <slyon@ubuntu.com>2021-05-17 14:00:52 +0200
committerLukas Märdian <slyon@ubuntu.com>2021-08-04 13:39:20 +0200
commit3f05ac5424ace4ce4b4944b7dd1cae6bfff12d8a (patch)
tree84a346c3d55a6efeb769e25f71bf400e9577ba7b /src
parentfee77e6ac256cb1d7549c7669375b32b97f5f841 (diff)
Fix ABI regression LP: #1922898 FR-1273 (#206)
In libnetplan v0.102 we introduced a regression, by breaking the ABI compatibility with netplan.io v0.101 (https://pad.lv/1922898) This happened by introducing two new settings to the NetplanNetDefinition struct (char* filename and guint tunnel.ttl), modifying the memory layout, thus breaking applications linked against older versions of libnetplan0. For char* filename, we can fix the problem by moving the new field to the end of the NetplanNetDefinition struct, thus not modifying the existing data layout, but only appending to it for the newer version. For guint netdef->tunnels.ttl we cannot easily fix the problem easily, as this is a struct inside a struct and there seems to be only one byte left (at least on x86_64) before we hit the memory boundary, while this new guint field needs 4 bytes. So we rename that field as tunnel_ttl and append it to the end of the net_definition struct. COMMITS: * Revert "Added TTL option for tunnels (LP: #1846783) (#194)" This reverts commit 6c8ed65df7c7f31280d5d27b67195a1e9a746e7a. * parse.h: move new 'filename' pointer to the end to avoid changes in the memory layout * Revert "Revert "Added TTL option for tunnels (LP: #1846783) (#194)"" This reverts commit 97d7d35704f3c3b80ba63e4f054fd8ac6303ba37. * parse: fix ABI compatibility with tunnel.ttl * doc: update tunnel_ttl documentation
Diffstat (limited to 'src')
-rw-r--r--src/networkd.c4
-rw-r--r--src/nm.c4
-rw-r--r--src/parse.c2
-rw-r--r--src/parse.h6
-rw-r--r--src/validation.c2
5 files changed, 10 insertions, 8 deletions
diff --git a/src/networkd.c b/src/networkd.c
index 05a6bf9..08cb0f1 100644
--- a/src/networkd.c
+++ b/src/networkd.c
@@ -142,8 +142,8 @@ write_tunnel_params(GString* s, const NetplanNetDefinition* def)
g_string_append_printf(params, "Mode=%s\n", tunnel_mode_to_string(def->tunnel.mode));
g_string_append_printf(params, "Local=%s\n", def->tunnel.local_ip);
g_string_append_printf(params, "Remote=%s\n", def->tunnel.remote_ip);
- if (def->tunnel.ttl)
- g_string_append_printf(params, "TTL=%u\n", def->tunnel.ttl);
+ if (def->tunnel_ttl)
+ g_string_append_printf(params, "TTL=%u\n", def->tunnel_ttl);
if (def->tunnel.input_key)
g_string_append_printf(params, "InputKey=%s\n", def->tunnel.input_key);
if (def->tunnel.output_key)
diff --git a/src/nm.c b/src/nm.c
index 2049c19..a15b5dd 100644
--- a/src/nm.c
+++ b/src/nm.c
@@ -409,8 +409,8 @@ write_tunnel_params(const NetplanNetDefinition* def, GKeyFile *kf)
g_key_file_set_integer(kf, "ip-tunnel", "mode", def->tunnel.mode);
g_key_file_set_string(kf, "ip-tunnel", "local", def->tunnel.local_ip);
g_key_file_set_string(kf, "ip-tunnel", "remote", def->tunnel.remote_ip);
- if (def->tunnel.ttl)
- g_key_file_set_uint64(kf, "ip-tunnel", "ttl", def->tunnel.ttl);
+ if (def->tunnel_ttl)
+ g_key_file_set_uint64(kf, "ip-tunnel", "ttl", def->tunnel_ttl);
if (def->tunnel.input_key)
g_key_file_set_string(kf, "ip-tunnel", "input-key", def->tunnel.input_key);
if (def->tunnel.output_key)
diff --git a/src/parse.c b/src/parse.c
index dcea8bc..7ebbced 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -2323,7 +2323,7 @@ static const mapping_entry_handler tunnel_def_handlers[] = {
{"mode", YAML_SCALAR_NODE, handle_tunnel_mode},
{"local", YAML_SCALAR_NODE, handle_tunnel_addr, NULL, netdef_offset(tunnel.local_ip)},
{"remote", YAML_SCALAR_NODE, handle_tunnel_addr, NULL, netdef_offset(tunnel.remote_ip)},
- {"ttl", YAML_SCALAR_NODE, handle_netdef_guint, NULL, netdef_offset(tunnel.ttl)},
+ {"ttl", YAML_SCALAR_NODE, handle_netdef_guint, NULL, netdef_offset(tunnel_ttl)},
/* Handle key/keys for clarity in config: this can be either a scalar or
* mapping of multiple keys (input and output)
diff --git a/src/parse.h b/src/parse.h
index 19abf10..92bfbd4 100644
--- a/src/parse.h
+++ b/src/parse.h
@@ -246,7 +246,6 @@ struct net_definition {
NetplanDefType type;
NetplanBackend backend;
char* id;
- char* filename;
/* only necessary for NetworkManager connection UUIDs in some cases */
uuid_t uuid;
@@ -376,7 +375,6 @@ struct net_definition {
char *private_key; /* used for wireguard */
guint fwmark;
guint port;
- guint ttl;
} tunnel;
NetplanAuthenticationSettings auth;
@@ -393,6 +391,10 @@ struct net_definition {
NetplanOVSSettings ovs_settings;
NetplanBackendSettings backend_settings;
+
+ char* filename;
+ /* it cannot be in the tunnel struct: https://github.com/canonical/netplan/pull/206 */
+ guint tunnel_ttl;
};
typedef enum {
diff --git a/src/validation.c b/src/validation.c
index 5cdfb15..c9e093e 100644
--- a/src/validation.c
+++ b/src/validation.c
@@ -205,7 +205,7 @@ validate_tunnel_grammar(NetplanNetDefinition* nd, yaml_node_t* node, GError** er
return yaml_error(node, error, "%s: missing 'local' property for tunnel", nd->id);
if (!nd->tunnel.remote_ip)
return yaml_error(node, error, "%s: missing 'remote' property for tunnel", nd->id);
- if (nd->tunnel.ttl && nd->tunnel.ttl > 255)
+ if (nd->tunnel_ttl && nd->tunnel_ttl > 255)
return yaml_error(node, error, "%s: 'ttl' property for tunnel must be in range [1...255]", nd->id);
switch(nd->tunnel.mode) {