summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Chopin <87005181+schopin-pro@users.noreply.github.com>2021-09-30 14:17:13 +0200
committerGitHub <noreply@github.com>2021-09-30 14:17:13 +0200
commit467e88a2b01805a796169b8843fbf6d376606882 (patch)
tree29d165e40d2a1ee44d481074421288ba3415a7bb /src
parent76ae706aba57eb77c3863aca6c568b0d2700eb30 (diff)
API/ABI: restrict the symbol export to a determined public API (#227)
The goal of this PR is to properly determine what the public interface of libnetplan is. There is potentially a bit of ABI breakage, as symbols now default to hidden status unless explicitly marked otherwise, and said marking was done manually by looking at the current consumers I had on my system and trying to fill in the blanks. The API, on the other hand, has been conscientiously broken, as most of what was exposed in the headers are now safely hidden away in our internal headers. This is by design, and AFAICT should not break existing code. This PR depends on #230, as denoted by the merge commit in there. It should make independent review a bit easier :). Given the fact that the main purpose of this PR is to limit the amount of symbols we export, we can safely assume that strictly speaking, there is ABI breakage. However, the whole point was to only expose the symbols that are in actual use out there in the real world. As usual, the patchset has been edited expecting a review commit by commit, as the whole diff can be a bit daunting. COMMITS: * libnetplan: rework netplan,parse{-nm},util.h as public headers This work involves splitting out some things from those headers into new internal headers, and moving definitions around so that the public headers are as self-contained as possible. For the new internal headers, I decided to have a big "types.h" header containing all the types used in a network definition. In itself, these types aren't related to parsing except that the parser module is the only producer, so I decided they could live on their own. This is also the place where type-specific helpers can be found, such as reset_netdef(). The various macros used to generate YAML were gathered up from both source headers into a new yaml-helpers.h header, whereas the various global state definitions were split off into their own headers, making it easier to spot which areas of the code still rely on global state. The remainder functions were moved into util-internal.h This allows us to minimize the API exposed to the outside world. V2: * Remove the extraneous struct net_definition line, as it is redundant with the typedef * Normalize all the symbol declarations to have the symbol name at the beginning of their own line, at least in the headers we touched. V3: * Remove extraneous stdbool.h header * Split parse-helpers.h into yaml-helpers.h and util-internal.h * Add uuid as a dependency of the dbus generator to make it compile with the new lay of the land. * Add some missing copyright headers * libnetplan: Properly mark the lib/bin interface This patch cleanly marks which functions/objects are part of the public library API, and which are meant to be consumed by our own binaries. In order to reduce as much as possible the ABI dependencies between our binaries and the library, I move the various generator modules into the library as it make sense for them to access directly the objects. On the other hand, both generate.c and dbus.c should be relatively trivial to change to use getters and setters instead of direct structure access. Those changes will be the object of later patches. V3: * Makefile: consolidate the pkg-config calls and add back the LDFLAGS variable * Normalize the touched function declarations to always have the symbol name at the start of the line. * libnetplan: add back ABI compatibility Re-export (and recreate) various symbols that are needed by the `generate` binary as shipped in the Ubuntu package 0.103-0ubuntu5 I have chosen a separate marker for those, in order to distinguish what was exposed deliberately and by accident. That way, if we need to do a SONAME bump, we can clean up the symbols marked with NETPLAN_ABI. V3: * Normalize the declarations that are touched to always have the symbol name at the start of the line * libnetplan: export Python-used symbols as internal * libnetplan: hide all symbols by default Only those marked by NETPLAN_{PUBLIC,INTERNAL,ABI} will be available to the loader.
Diffstat (limited to 'src')
-rw-r--r--src/dbus.c2
-rw-r--r--src/error.c1
-rw-r--r--src/generate.c2
-rw-r--r--src/names.c4
-rw-r--r--src/names.h3
-rw-r--r--src/netplan.c6
-rw-r--r--src/networkd.c2
-rw-r--r--src/networkd.h17
-rw-r--r--src/nm.c3
-rw-r--r--src/nm.h13
-rw-r--r--src/openvswitch.c2
-rw-r--r--src/openvswitch.h13
-rw-r--r--src/parse-globals.h51
-rw-r--r--src/parse-nm.c1
-rw-r--r--src/parse-nm.h22
-rw-r--r--src/parse.c14
-rw-r--r--src/sriov.c3
-rw-r--r--src/sriov.h8
-rw-r--r--src/types.c (renamed from src/netdef.c)7
-rw-r--r--src/types.h (renamed from src/parse.h)120
-rw-r--r--src/util-internal.h70
-rw-r--r--src/util.c10
-rw-r--r--src/util.h41
-rw-r--r--src/validation.c6
-rw-r--r--src/validation.h5
-rw-r--r--src/yaml-helpers.h (renamed from src/netplan.h)8
26 files changed, 228 insertions, 206 deletions
diff --git a/src/dbus.c b/src/dbus.c
index a486b54..1442af3 100644
--- a/src/dbus.c
+++ b/src/dbus.c
@@ -15,7 +15,7 @@
#include <systemd/sd-event.h>
#include "_features.h"
-#include "util.h"
+#include "util-internal.h"
typedef struct {
sd_bus_slot *slot;
diff --git a/src/error.c b/src/error.c
index 0c34e17..ff28be9 100644
--- a/src/error.c
+++ b/src/error.c
@@ -22,6 +22,7 @@
#include <yaml.h>
#include "parse.h"
+#include "parse-globals.h"
/****************************************************
diff --git a/src/generate.c b/src/generate.c
index caff955..00c7035 100644
--- a/src/generate.c
+++ b/src/generate.c
@@ -27,7 +27,9 @@
#include <gio/gio.h>
#include "util.h"
+#include "util-internal.h"
#include "parse.h"
+#include "parse-globals.h"
#include "names.h"
#include "networkd.h"
#include "nm.h"
diff --git a/src/names.c b/src/names.c
index 378c6b4..3a085ba 100644
--- a/src/names.c
+++ b/src/names.c
@@ -107,8 +107,8 @@ NAME_FUNCTION(wifi_mode, NetplanWifiMode);
/* ABI compatibility definitions */
-const char*
+NETPLAN_ABI const char*
tunnel_mode_to_string(NetplanTunnelMode val) __attribute__ ((alias ("netplan_tunnel_mode_name")));
-extern const char*
+NETPLAN_ABI extern const char*
netplan_backend_to_name __attribute__((alias("netplan_backend_to_str")));
diff --git a/src/names.h b/src/names.h
index 256a600..c1b108b 100644
--- a/src/names.h
+++ b/src/names.h
@@ -18,8 +18,9 @@
#pragma once
#include "netplan.h"
+#include "types.h"
-const char*
+NETPLAN_INTERNAL const char*
netplan_backend_name(NetplanBackend val);
const char*
diff --git a/src/netplan.c b/src/netplan.c
index 7a7bc43..6285aa2 100644
--- a/src/netplan.c
+++ b/src/netplan.c
@@ -20,6 +20,8 @@
#include "netplan.h"
#include "parse.h"
+#include "parse-globals.h"
+#include "yaml-helpers.h"
#include "names.h"
gchar *tmp = NULL;
@@ -885,7 +887,7 @@ contains_netdef_type(gpointer key, gpointer value, gpointer user_data)
* @rootdir: If not %NULL, generate configuration in this root directory
* (useful for testing).
*/
-void
+NETPLAN_INTERNAL void
write_netplan_conf_full(const char* file_hint, const char* rootdir)
{
g_autofree gchar *path = NULL;
@@ -980,7 +982,7 @@ void cleanup_netplan_conf(const char* rootdir)
/**
* Helper function for testing only
*/
-void
+NETPLAN_INTERNAL void
_write_netplan_conf(const char* netdef_id, const char* rootdir)
{
GHashTable* ht = NULL;
diff --git a/src/networkd.c b/src/networkd.c
index e8e680e..f6c9ec9 100644
--- a/src/networkd.c
+++ b/src/networkd.c
@@ -27,8 +27,10 @@
#include "networkd.h"
#include "parse.h"
+#include "parse-globals.h"
#include "names.h"
#include "util.h"
+#include "util-internal.h"
#include "validation.h"
/**
diff --git a/src/networkd.h b/src/networkd.h
index 41ab125..be2bb29 100644
--- a/src/networkd.h
+++ b/src/networkd.h
@@ -17,10 +17,17 @@
#pragma once
-#include "parse.h"
+#include "netplan.h"
+#include <glib.h>
-gboolean write_networkd_conf(const NetplanNetDefinition* def, const char* rootdir);
-void cleanup_networkd_conf(const char* rootdir);
-void enable_networkd(const char* generator_dir);
+NETPLAN_INTERNAL gboolean
+write_networkd_conf(const NetplanNetDefinition* def, const char* rootdir);
-void write_network_file(const NetplanNetDefinition* def, const char* rootdir, const char* path);
+NETPLAN_INTERNAL void
+write_network_file(const NetplanNetDefinition* def, const char* rootdir, const char* path);
+
+NETPLAN_INTERNAL void
+cleanup_networkd_conf(const char* rootdir);
+
+NETPLAN_INTERNAL void
+enable_networkd(const char* generator_dir);
diff --git a/src/nm.c b/src/nm.c
index aef15ac..8e84a99 100644
--- a/src/nm.c
+++ b/src/nm.c
@@ -26,9 +26,12 @@
#include <glib/gprintf.h>
#include <uuid.h>
+#include "netplan.h"
#include "nm.h"
#include "parse.h"
+#include "parse-globals.h"
#include "util.h"
+#include "util-internal.h"
#include "validation.h"
#include "parse-nm.h"
diff --git a/src/nm.h b/src/nm.h
index 9f8f9ca..ac86f00 100644
--- a/src/nm.h
+++ b/src/nm.h
@@ -17,8 +17,13 @@
#pragma once
-#include "parse.h"
+#include "netplan.h"
-void write_nm_conf(NetplanNetDefinition* def, const char* rootdir);
-void write_nm_conf_finish(const char* rootdir);
-void cleanup_nm_conf(const char* rootdir);
+NETPLAN_INTERNAL void
+write_nm_conf(NetplanNetDefinition* def, const char* rootdir);
+
+NETPLAN_INTERNAL void
+write_nm_conf_finish(const char* rootdir);
+
+NETPLAN_INTERNAL void
+cleanup_nm_conf(const char* rootdir);
diff --git a/src/openvswitch.c b/src/openvswitch.c
index 2088fbe..3bf8631 100644
--- a/src/openvswitch.c
+++ b/src/openvswitch.c
@@ -25,7 +25,9 @@
#include "openvswitch.h"
#include "networkd.h"
#include "parse.h"
+#include "parse-globals.h"
#include "util.h"
+#include "util-internal.h"
static void
write_ovs_systemd_unit(const char* id, const GString* cmds, const char* rootdir, gboolean physical, gboolean cleanup, const char* dependency)
diff --git a/src/openvswitch.h b/src/openvswitch.h
index 69bd6ee..7abea4d 100644
--- a/src/openvswitch.h
+++ b/src/openvswitch.h
@@ -17,8 +17,13 @@
#pragma once
-#include "parse.h"
+#include "netplan.h"
-void write_ovs_conf(const NetplanNetDefinition* def, const char* rootdir);
-void write_ovs_conf_finish(const char* rootdir);
-void cleanup_ovs_conf(const char* rootdir);
+NETPLAN_INTERNAL void
+write_ovs_conf(const NetplanNetDefinition* def, const char* rootdir);
+
+NETPLAN_INTERNAL void
+write_ovs_conf_finish(const char* rootdir);
+
+NETPLAN_INTERNAL void
+cleanup_ovs_conf(const char* rootdir);
diff --git a/src/parse-globals.h b/src/parse-globals.h
new file mode 100644
index 0000000..a7b2be8
--- /dev/null
+++ b/src/parse-globals.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2021 Canonical, Ltd.
+ * Author: Simon Chopin <simon.chopin@canonical.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 3.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <glib.h>
+#include "types.h"
+
+/* file that is currently being processed, for useful error messages */
+extern const char*
+current_file;
+
+/* List of "seen" ids not found in netdefs yet by the parser.
+ * These are removed when it exists in this list and we reach the point of
+ * creating a netdef for that id; so by the time we're done parsing the yaml
+ * document it should be empty. */
+extern GHashTable*
+missing_id;
+
+extern int
+missing_ids_found;
+
+/* Written/updated by parse_yaml(): char* id → net_definition.
+ *
+ * Since both netdefs and netdefs_ordered store pointers to the same elements,
+ * we consider that only netdefs_ordered is owner of this data. One should not
+ * free() objects obtained from netdefs, and proper care should be taken to remove
+ * any reference of an object in netdefs when destroying it from netdefs_ordered.
+ */
+extern GHashTable*
+netdefs;
+
+extern GList*
+netdefs_ordered;
+
+extern NetplanOVSSettings
+ovs_settings_global;
diff --git a/src/parse-nm.c b/src/parse-nm.c
index bb83bf5..9d5d9cf 100644
--- a/src/parse-nm.c
+++ b/src/parse-nm.c
@@ -23,6 +23,7 @@
#include "parse-nm.h"
#include "parse.h"
#include "util.h"
+#include "util-internal.h"
/**
* NetworkManager writes the alias for '802-3-ethernet' (ethernet),
diff --git a/src/parse-nm.h b/src/parse-nm.h
deleted file mode 100644
index 53973f7..0000000
--- a/src/parse-nm.h
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Copyright (C) 2021 Canonical, Ltd.
- * Author: Lukas Märdian <slyon@ubuntu.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 3.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#pragma once
-
-#define NETPLAN_NM_EMPTY_GROUP "_"
-
-gboolean netplan_parse_keyfile(const char* filename, GError** error);
diff --git a/src/parse.c b/src/parse.c
index f62deef..55ead8f 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -28,11 +28,14 @@
#include <yaml.h>
#include "parse.h"
-#include "util.h"
#include "names.h"
+#include "util-internal.h"
#include "error.h"
#include "validation.h"
+#define NETPLAN_VERSION_MIN 2
+#define NETPLAN_VERSION_MAX 3
+
/* convenience macro to put the offset of a NetplanNetDefinition field into "void* data" */
#define access_point_offset(field) GUINT_TO_POINTER(offsetof(NetplanWifiAccessPoint, field))
#define addr_option_offset(field) GUINT_TO_POINTER(offsetof(NetplanAddressOptions, field))
@@ -73,12 +76,15 @@ const char* cur_filename;
static NetplanBackend backend_global, backend_cur_type;
/* global OpenVSwitch settings */
+NETPLAN_INTERNAL
NetplanOVSSettings ovs_settings_global;
/* Global ID → NetplanNetDefinition* map for all parsed config files */
+NETPLAN_INTERNAL
GHashTable* netdefs;
/* Contains the same objects as 'netdefs' but ordered by dependency */
+NETPLAN_INTERNAL
GList* netdefs_ordered;
/* Set of IDs in currently parsed YAML file, for being able to detect
@@ -900,7 +906,8 @@ handle_match(yaml_document_t* doc, yaml_node_t* node, const void* _, GError** er
return process_mapping(doc, node, match_handlers, NULL, error);
}
-struct NetplanWifiWowlanType NETPLAN_WIFI_WOWLAN_TYPES[] = {
+NETPLAN_ABI struct NetplanWifiWowlanType
+NETPLAN_WIFI_WOWLAN_TYPES[] = {
{"default", NETPLAN_WIFI_WOWLAN_DEFAULT},
{"any", NETPLAN_WIFI_WOWLAN_ANY},
{"disconnect", NETPLAN_WIFI_WOWLAN_DISCONNECT},
@@ -1311,7 +1318,8 @@ handle_link_local(yaml_document_t* doc, yaml_node_t* node, const void* _, GError
return TRUE;
}
-struct NetplanOptionalAddressType NETPLAN_OPTIONAL_ADDRESS_TYPES[] = {
+NETPLAN_ABI struct NetplanOptionalAddressType
+NETPLAN_OPTIONAL_ADDRESS_TYPES[] = {
{"ipv4-ll", NETPLAN_OPTIONAL_IPV4_LL},
{"ipv6-ra", NETPLAN_OPTIONAL_IPV6_RA},
{"dhcp4", NETPLAN_OPTIONAL_DHCP4},
diff --git a/src/sriov.c b/src/sriov.c
index 60f9800..906aac2 100644
--- a/src/sriov.c
+++ b/src/sriov.c
@@ -21,7 +21,8 @@
#include <glib/gstdio.h>
#include <glib-object.h>
-#include "util.h"
+#include "util-internal.h"
+#include "sriov.h"
void
write_sriov_conf_finish(const char* rootdir)
diff --git a/src/sriov.h b/src/sriov.h
index 7cd5896..e71f573 100644
--- a/src/sriov.h
+++ b/src/sriov.h
@@ -16,6 +16,10 @@
*/
#pragma once
+#include "netplan.h"
-void write_sriov_conf_finish(const char* rootdir);
-void cleanup_sriov_conf(const char* rootdir);
+NETPLAN_INTERNAL void
+write_sriov_conf_finish(const char* rootdir);
+
+NETPLAN_INTERNAL void
+cleanup_sriov_conf(const char* rootdir);
diff --git a/src/netdef.c b/src/types.c
index 36464f6..b723f15 100644
--- a/src/netdef.c
+++ b/src/types.c
@@ -15,12 +15,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-/* This module contains functions to deal with the NetplanNetDefinition objects.
- * Notably, accessors and destructors.
+/* This module contains functions to deal with the Netplan objects,
+ * notably, accessors and destructors. Note that types specific to parsing
+ * are implemented separately.
*/
#include <glib.h>
-#include "parse.h"
+#include "types.h"
#define FREE_AND_NULLIFY(ptr) { g_free(ptr); ptr = NULL; }
diff --git a/src/parse.h b/src/types.h
index 28050f2..48c7ad2 100644
--- a/src/parse.h
+++ b/src/types.h
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2016 Canonical, Ltd.
- * Author: Martin Pitt <martin.pitt@ubuntu.com>
+ * Copyright (C) 2021 Canonical, Ltd.
+ * Author: Simon Chopin <simon.chopin@canonical.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -17,52 +17,10 @@
#pragma once
-#include <uuid.h>
+#include "parse.h"
+#include <glib.h>
#include <yaml.h>
-
-#define NETPLAN_VERSION_MIN 2
-#define NETPLAN_VERSION_MAX 3
-
-
-/* file that is currently being processed, for useful error messages */
-extern const char* current_file;
-
-/* List of "seen" ids not found in netdefs yet by the parser.
- * These are removed when it exists in this list and we reach the point of
- * creating a netdef for that id; so by the time we're done parsing the yaml
- * document it should be empty. */
-extern GHashTable *missing_id;
-extern int missing_ids_found;
-
-/****************************************************
- * Parsed definitions
- ****************************************************/
-
-typedef enum {
- NETPLAN_DEF_TYPE_NONE,
- /* physical devices */
- NETPLAN_DEF_TYPE_ETHERNET,
- NETPLAN_DEF_TYPE_WIFI,
- NETPLAN_DEF_TYPE_MODEM,
- /* virtual devices */
- NETPLAN_DEF_TYPE_VIRTUAL,
- NETPLAN_DEF_TYPE_BRIDGE = NETPLAN_DEF_TYPE_VIRTUAL,
- NETPLAN_DEF_TYPE_BOND,
- NETPLAN_DEF_TYPE_VLAN,
- NETPLAN_DEF_TYPE_TUNNEL,
- NETPLAN_DEF_TYPE_PORT,
- /* Type fallback/passthrough */
- NETPLAN_DEF_TYPE_NM,
- NETPLAN_DEF_TYPE_MAX_
-} NetplanDefType;
-
-typedef enum {
- NETPLAN_BACKEND_NONE,
- NETPLAN_BACKEND_NETWORKD,
- NETPLAN_BACKEND_NM,
- NETPLAN_BACKEND_OVS,
- NETPLAN_BACKEND_MAX_,
-} NetplanBackend;
+#include <uuid.h>
typedef enum {
NETPLAN_RA_MODE_KERNEL,
@@ -90,6 +48,7 @@ struct NetplanOptionalAddressType {
NetplanOptionalAddressFlag flag;
};
+// Not strictly speaking a type, but seems fair to keep it around.
extern struct NetplanOptionalAddressType NETPLAN_OPTIONAL_ADDRESS_TYPES[];
/* Tunnel mode enum; sync with NetworkManager's DBUS API */
@@ -116,24 +75,6 @@ typedef enum {
NETPLAN_TUNNEL_MODE_MAX_,
} NetplanTunnelMode;
-static const char* const
-netplan_tunnel_mode_table[NETPLAN_TUNNEL_MODE_MAX_] = {
- [NETPLAN_TUNNEL_MODE_UNKNOWN] = "unknown",
- [NETPLAN_TUNNEL_MODE_IPIP] = "ipip",
- [NETPLAN_TUNNEL_MODE_GRE] = "gre",
- [NETPLAN_TUNNEL_MODE_SIT] = "sit",
- [NETPLAN_TUNNEL_MODE_ISATAP] = "isatap",
- [NETPLAN_TUNNEL_MODE_VTI] = "vti",
- [NETPLAN_TUNNEL_MODE_IP6IP6] = "ip6ip6",
- [NETPLAN_TUNNEL_MODE_IPIP6] = "ipip6",
- [NETPLAN_TUNNEL_MODE_IP6GRE] = "ip6gre",
- [NETPLAN_TUNNEL_MODE_VTI6] = "vti6",
-
- [NETPLAN_TUNNEL_MODE_GRETAP] = "gretap",
- [NETPLAN_TUNNEL_MODE_IP6GRETAP] = "ip6gretap",
- [NETPLAN_TUNNEL_MODE_WIREGUARD] = "wireguard",
-};
-
typedef enum {
NETPLAN_WIFI_WOWLAN_DEFAULT = 1<<0,
NETPLAN_WIFI_WOWLAN_ANY = 1<<1,
@@ -230,14 +171,6 @@ typedef union {
} networkd;
} NetplanBackendSettings;
-/**
- * Represent a configuration stanza
- */
-
-struct net_definition;
-
-typedef struct net_definition NetplanNetDefinition;
-
struct net_definition {
NetplanDefType type;
NetplanBackend backend;
@@ -450,15 +383,6 @@ typedef struct {
NetplanBackendSettings backend_settings;
} NetplanWifiAccessPoint;
-#define NETPLAN_ADVERTISED_RECEIVE_WINDOW_UNSPEC 0
-#define NETPLAN_CONGESTION_WINDOW_UNSPEC 0
-#define NETPLAN_MTU_UNSPEC 0
-#define NETPLAN_METRIC_UNSPEC G_MAXUINT
-#define NETPLAN_ROUTE_TABLE_UNSPEC 0
-#define NETPLAN_IP_RULE_PRIO_UNSPEC G_MAXUINT
-#define NETPLAN_IP_RULE_FW_MARK_UNSPEC 0
-#define NETPLAN_IP_RULE_TOS_UNSPEC G_MAXUINT
-
typedef struct {
guint family;
char* type;
@@ -495,27 +419,13 @@ typedef struct {
guint tos;
} NetplanIPRule;
-/* Written/updated by parse_yaml(): char* id → net_definition.
- *
- * Since both netdefs and netdefs_ordered store pointers to the same elements,
- * we consider that only netdefs_ordered is owner of this data. One should not
- * free() objects obtained from netdefs, and proper care should be taken to remove
- * any reference of an object in netdefs when destroying it from netdefs_ordered.
- */
-extern GHashTable* netdefs;
-extern GList* netdefs_ordered;
-extern NetplanOVSSettings ovs_settings_global;
-
-/****************************************************
- * Functions
- ****************************************************/
-
-gboolean netplan_parse_yaml(const char* filename, GError** error);
-GHashTable* netplan_finish_parse(GError** error);
-guint netplan_clear_netdefs();
-NetplanBackend netplan_get_global_backend();
-NetplanNetDefinition* netplan_netdef_new(const char* id, NetplanDefType type, NetplanBackend renderer);
-void reset_netdef(NetplanNetDefinition *netdef, NetplanDefType type, NetplanBackend renderer);
+#define NETPLAN_ADVERTISED_RECEIVE_WINDOW_UNSPEC 0
+#define NETPLAN_CONGESTION_WINDOW_UNSPEC 0
+#define NETPLAN_MTU_UNSPEC 0
+#define NETPLAN_METRIC_UNSPEC G_MAXUINT
+#define NETPLAN_ROUTE_TABLE_UNSPEC 0
+#define NETPLAN_IP_RULE_PRIO_UNSPEC G_MAXUINT
+#define NETPLAN_IP_RULE_FW_MARK_UNSPEC 0
+#define NETPLAN_IP_RULE_TOS_UNSPEC G_MAXUINT
-void process_input_file(const char* f);
-gboolean process_yaml_hierarchy(const char* rootdir);
+void reset_netdef(NetplanNetDefinition *netdef, NetplanDefType type, NetplanBackend renderer);
diff --git a/src/util-internal.h b/src/util-internal.h
new file mode 100644
index 0000000..fe792d4
--- /dev/null
+++ b/src/util-internal.h
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2016 Canonical, Ltd.
+ * Author: Martin Pitt <martin.pitt@ubuntu.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 3.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#define __USE_MISC
+#include <glob.h>
+#include <glib.h>
+#include "types.h"
+
+#include <glib.h>
+#include "netplan.h"
+
+extern GHashTable*
+wifi_frequency_24;
+
+extern GHashTable*
+wifi_frequency_5;
+
+NETPLAN_ABI void
+safe_mkdir_p_dir(const char* file_path);
+
+NETPLAN_INTERNAL void
+g_string_free_to_file(GString* s, const char* rootdir, const char* path, const char* suffix);
+
+NETPLAN_INTERNAL void
+unlink_glob(const char* rootdir, const char* _glob);
+
+NETPLAN_INTERNAL int
+find_yaml_glob(const char* rootdir, glob_t* out_glob);
+
+NETPLAN_ABI const char*
+get_global_network(int ip_family);
+
+NETPLAN_ABI int
+wifi_get_freq24(int channel);
+
+NETPLAN_ABI int
+wifi_get_freq5(int channel);
+
+NETPLAN_ABI gchar*
+systemd_escape(char* string);
+
+#define OPENVSWITCH_OVS_VSCTL "/usr/bin/ovs-vsctl"
+
+const char*
+tunnel_mode_to_string(NetplanTunnelMode mode);
+
+NetplanNetDefinition*
+netplan_netdef_new(const char* id, NetplanDefType type, NetplanBackend renderer);
+
+NETPLAN_INTERNAL void
+process_input_file(const char* f);
+
+NETPLAN_INTERNAL gboolean
+process_yaml_hierarchy(const char* rootdir);
diff --git a/src/util.c b/src/util.c
index b43aaf9..c8004cf 100644
--- a/src/util.c
+++ b/src/util.c
@@ -23,11 +23,17 @@
#include <glib/gprintf.h>
#include "util.h"
+#include "util-internal.h"
#include "netplan.h"
+#include "parse.h"
+#include "parse-globals.h"
#include "names.h"
-GHashTable* wifi_frequency_24;
-GHashTable* wifi_frequency_5;
+NETPLAN_ABI GHashTable*
+wifi_frequency_24;
+
+NETPLAN_ABI GHashTable*
+wifi_frequency_5;
/**
* Create the parent directories of given file path. Exit program on failure.
diff --git a/src/util.h b/src/util.h
deleted file mode 100644
index f34c601..0000000
--- a/src/util.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2016 Canonical, Ltd.
- * Author: Martin Pitt <martin.pitt@ubuntu.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 3.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#define __USE_MISC
-#include <glob.h>
-#pragma once
-
-extern GHashTable* wifi_frequency_24;
-extern GHashTable* wifi_frequency_5;
-
-void safe_mkdir_p_dir(const char* file_path);
-void g_string_free_to_file(GString* s, const char* rootdir, const char* path, const char* suffix);
-void unlink_glob(const char* rootdir, const char* _glob);
-int find_yaml_glob(const char* rootdir, glob_t* out_glob);
-
-const char *get_global_network(int ip_family);
-
-int wifi_get_freq24(int channel);
-int wifi_get_freq5(int channel);
-
-gchar* systemd_escape(char* string);
-gboolean netplan_delete_connection(const char* id, const char* rootdir);
-gboolean netplan_generate(const char* rootdir);
-gchar* netplan_get_id_from_nm_filename(const char* filename, const char* ssid);
-gchar* netplan_get_filename_by_id(const char* netdef_id, const char* rootdir);
-
-#define OPENVSWITCH_OVS_VSCTL "/usr/bin/ovs-vsctl"
diff --git a/src/validation.c b/src/validation.c
index 2ac5650..7b80559 100644
--- a/src/validation.c
+++ b/src/validation.c
@@ -24,10 +24,12 @@
#include <yaml.h>
#include "parse.h"
+#include "types.h"
+#include "parse-globals.h"
#include "names.h"
#include "error.h"
-#include "util.h"
-
+#include "util-internal.h"
+#include "validation.h"
/* Check sanity for address types */
diff --git a/src/validation.h b/src/validation.h
index 3f6e527..18e98fe 100644
--- a/src/validation.h
+++ b/src/validation.h
@@ -19,14 +19,17 @@
#include "parse.h"
#include <glib.h>
+#include <yaml.h>
gboolean is_ip4_address(const char* address);
gboolean is_ip6_address(const char* address);
gboolean is_hostname(const char* hostname);
-gboolean is_wireguard_key(const char* hostname);
gboolean validate_ovs_target(gboolean host_first, gchar* s);
+NETPLAN_ABI gboolean
+is_wireguard_key(const char* hostname);
+
gboolean
validate_netdef_grammar(NetplanNetDefinition* nd, yaml_node_t* node, GError** error);
diff --git a/src/netplan.h b/src/yaml-helpers.h
index f8c09d1..6408ac1 100644
--- a/src/netplan.h
+++ b/src/yaml-helpers.h
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2021 Canonical, Ltd.
- * Author: Lukas Märdian <slyon@ubuntu.com>
+ * Copyright (C) 2016 Canonical, Ltd.
+ * Author: Martin Pitt <martin.pitt@ubuntu.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -17,7 +17,7 @@
#pragma once
-#include "parse.h"
+#include <yaml.h>
#define YAML_MAPPING_OPEN(event_ptr, emitter_ptr) \
{ \
@@ -92,5 +92,3 @@
if (!yaml_emitter_emit(emitter_ptr, event_ptr)) goto error; \
yaml_emitter_delete(emitter_ptr); \
}
-
-void write_netplan_conf(const NetplanNetDefinition* def, const char* rootdir);