From ee1ffc3d4ba44713affa47bb2f1d9b2a61013bd4 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 27 Jul 2014 20:35:17 +0200 Subject: all: add nm-core-internal.h header Add a header file to expose private utility functions from libnm-core that can be used by NetworkManager (core) and libnm.so. The header is also used to give privileged access to libnm-core. Since NM links statically, these functions are not exported and not part of public ABI. This also removes the NM_UTILS_PRIVATE_CALL() macro and libnm.so no longer exports nm_utils_get_private(). Before, this functionality was partly declared in nm-utils-private.h. This was wrong because nm-utils-private.h is for functionality entirely private to libnm-core. Signed-off-by: Thomas Haller --- callouts/tests/test-dispatcher-envp.c | 1 - clients/tui/nmt-route-table.c | 1 - docs/libnm/Makefile.am | 1 + libnm-core/Makefile.libnm-core | 1 + libnm-core/nm-core-internal.h | 49 ++++++++++++++++++++++ libnm-core/nm-setting-ip4-config.c | 11 ++--- libnm-core/nm-setting-private.h | 5 --- libnm-core/nm-utils-private.h | 26 ------------ libnm-core/nm-utils.c | 19 --------- libnm-core/tests/test-general.c | 24 +++++------ libnm/libnm.ver | 1 - src/nm-ip4-config.c | 6 +-- src/settings/plugins/ifcfg-rh/reader.c | 4 +- .../plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 10 ++--- src/settings/plugins/ifcfg-rh/writer.c | 6 +-- 15 files changed, 82 insertions(+), 83 deletions(-) create mode 100644 libnm-core/nm-core-internal.h diff --git a/callouts/tests/test-dispatcher-envp.c b/callouts/tests/test-dispatcher-envp.c index 97b839b5f3..a91ae2b27a 100644 --- a/callouts/tests/test-dispatcher-envp.c +++ b/callouts/tests/test-dispatcher-envp.c @@ -31,7 +31,6 @@ #include "nm-dbus-glib-types.h" #include "nm-dispatcher-api.h" #include "nm-utils.h" -#include "nm-utils-private.h" /*******************************************/ diff --git a/clients/tui/nmt-route-table.c b/clients/tui/nmt-route-table.c index c5a70761d1..82eefb457e 100644 --- a/clients/tui/nmt-route-table.c +++ b/clients/tui/nmt-route-table.c @@ -33,7 +33,6 @@ #include #include #include -#include #include "nmt-route-table.h" #include "nmt-route-entry.h" diff --git a/docs/libnm/Makefile.am b/docs/libnm/Makefile.am index 9d745b14c2..c99e242512 100644 --- a/docs/libnm/Makefile.am +++ b/docs/libnm/Makefile.am @@ -32,6 +32,7 @@ CFILE_GLOB=$(top_srcdir)/libnm-core/*.c $(top_srcdir)/libnm/*.c IGNORE_HFILES= \ crypto.h \ nm-dbus-helpers-private.h \ + nm-core-internal.h \ nm-device-private.h \ nm-object-cache.h \ nm-object-private.h \ diff --git a/libnm-core/Makefile.libnm-core b/libnm-core/Makefile.libnm-core index 57783b613a..a7f8c1d5f1 100644 --- a/libnm-core/Makefile.libnm-core +++ b/libnm-core/Makefile.libnm-core @@ -42,6 +42,7 @@ libnm_core_headers = \ libnm_core_private_headers = \ $(core)/crypto.h \ + $(core)/nm-core-internal.h \ $(core)/nm-param-spec-specialized.h \ $(core)/nm-setting-private.h \ $(core)/nm-utils-private.h diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h new file mode 100644 index 0000000000..41b51c2f69 --- /dev/null +++ b/libnm-core/nm-core-internal.h @@ -0,0 +1,49 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ + +/* + * This library 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 of the License, or (at your option) any later version. + * + * This library 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 this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + * (C) Copyright 2014 Red Hat, Inc. + */ + +#ifndef NM_CORE_NM_INTERNAL_H +#define NM_CORE_NM_INTERNAL_H + +/* This header file contain functions that are provided as private API + * by libnm-core. It will contain functions to give privileged access to + * libnm-core. This can be useful for NetworkManager and libnm.so + * which both are special users of libnm-core. + * It also exposes some utility functions for reuse. + * + * These functions are not exported and are only available to components that link + * statically against libnm-core. This basically means libnm-core, libnm, NetworkManager + * and some test programs. + **/ + +#include + +#include "nm-utils.h" + +#include "nm-setting-ip4-config.h" + +const char *_nm_setting_ip4_config_get_address_label (NMSettingIP4Config *setting, + guint32 i); +gboolean _nm_setting_ip4_config_add_address_with_label (NMSettingIP4Config *setting, + NMIP4Address *address, + const char *label); + + +#endif diff --git a/libnm-core/nm-setting-ip4-config.c b/libnm-core/nm-setting-ip4-config.c index f3de89e98c..aab5546ec6 100644 --- a/libnm-core/nm-setting-ip4-config.c +++ b/libnm-core/nm-setting-ip4-config.c @@ -30,6 +30,7 @@ #include "nm-dbus-glib-types.h" #include "nm-glib-compat.h" #include "nm-setting-private.h" +#include "nm-core-internal.h" /** @@ -435,7 +436,7 @@ nm_setting_ip4_config_get_address (NMSettingIP4Config *setting, guint32 i) } const char * -nm_setting_ip4_config_get_address_label (NMSettingIP4Config *setting, guint32 i) +_nm_setting_ip4_config_get_address_label (NMSettingIP4Config *setting, guint32 i) { NMSettingIP4ConfigPrivate *priv; @@ -462,13 +463,13 @@ gboolean nm_setting_ip4_config_add_address (NMSettingIP4Config *setting, NMIP4Address *address) { - return nm_setting_ip4_config_add_address_with_label (setting, address, NULL); + return _nm_setting_ip4_config_add_address_with_label (setting, address, NULL); } gboolean -nm_setting_ip4_config_add_address_with_label (NMSettingIP4Config *setting, - NMIP4Address *address, - const char *label) +_nm_setting_ip4_config_add_address_with_label (NMSettingIP4Config *setting, + NMIP4Address *address, + const char *label) { NMSettingIP4ConfigPrivate *priv; NMIP4Address *copy; diff --git a/libnm-core/nm-setting-private.h b/libnm-core/nm-setting-private.h index 99590b9e14..ac08e8421e 100644 --- a/libnm-core/nm-setting-private.h +++ b/libnm-core/nm-setting-private.h @@ -103,11 +103,6 @@ static void __attribute__((constructor)) register_setting (void) \ NMSetting *nm_setting_find_in_list (GSList *settings_list, const char *setting_name); -/* Private NMSettingIP4Config methods */ -#include "nm-setting-ip4-config.h" -const char *nm_setting_ip4_config_get_address_label (NMSettingIP4Config *setting, guint32 i); -gboolean nm_setting_ip4_config_add_address_with_label (NMSettingIP4Config *setting, NMIP4Address *address, const char *label); - NMSettingVerifyResult _nm_setting_verify_deprecated_virtual_iface_name (const char *interface_name, gboolean allow_missing, const char *setting_name, diff --git a/libnm-core/nm-utils-private.h b/libnm-core/nm-utils-private.h index c91652b8a3..0e7be21e28 100644 --- a/libnm-core/nm-utils-private.h +++ b/libnm-core/nm-utils-private.h @@ -34,30 +34,4 @@ gboolean _nm_utils_gvalue_array_validate (GValueArray *elements, void _nm_value_transforms_register (void); -/***********************************************************/ - -typedef struct NMUtilsPrivateData { - const char * (*nm_setting_ip4_config_get_address_label) (NMSettingIP4Config *setting, - guint32 i); - gboolean (*nm_setting_ip4_config_add_address_with_label) (NMSettingIP4Config *setting, - NMIP4Address *address, - const char *label); -} NMUtilsPrivateData; - -const NMUtilsPrivateData *nm_utils_get_private (void); - -/** - * NM_UTILS_PRIVATE_CALL: - * @call: a call to a private libnm function - * - * Used to call private libnm functions. Eg, if there was a - * private function called nm_foo_get_bar(), you could call it like: - * - * bar = NM_UTILS_PRIVATE_CALL (nm_foo_get_bar (foo, x, y, z)); - * - * This macro only exists inside the NetworkManager source tree and - * is not part of the public API. - */ -#define NM_UTILS_PRIVATE_CALL(call) (nm_utils_get_private ()->call) - #endif diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index aeb2063a38..9c30d2e8ed 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -2478,23 +2478,4 @@ nm_utils_check_virtual_device_compatibility (GType virtual_type, GType other_typ } } -/***********************************************************/ -static const NMUtilsPrivateData data = { - .nm_setting_ip4_config_get_address_label = nm_setting_ip4_config_get_address_label, - .nm_setting_ip4_config_add_address_with_label = nm_setting_ip4_config_add_address_with_label, -}; - -/** - * nm_utils_get_private: - * - * Entry point for NetworkManager-internal API. You should not use this - * function for any reason. - * - * Returns: Who knows? It's a mystery. - */ -const NMUtilsPrivateData * -nm_utils_get_private (void) -{ - return &data; -} diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c index 0f2f983a8c..de54a41879 100644 --- a/libnm-core/tests/test-general.c +++ b/libnm-core/tests/test-general.c @@ -39,7 +39,7 @@ #include "nm-setting-vlan.h" #include "nm-setting-bond.h" #include "nm-utils.h" -#include "nm-utils-private.h" +#include "nm-core-internal.h" #include "nm-dbus-glib-types.h" #include "nm-test-utils.h" @@ -330,7 +330,7 @@ test_setting_ip4_config_labels (void) nm_setting_verify (NM_SETTING (s_ip4), NULL, &error); g_assert_no_error (error); - label = NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, 0)); + label = _nm_setting_ip4_config_get_address_label (s_ip4, 0); g_assert_cmpstr (label, ==, NULL); /* addr 2 */ @@ -338,12 +338,12 @@ test_setting_ip4_config_labels (void) nm_ip4_address_set_address (addr, 0x02020202); nm_ip4_address_set_prefix (addr, 24); - NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_add_address_with_label (s_ip4, addr, "eth0:1")); + _nm_setting_ip4_config_add_address_with_label (s_ip4, addr, "eth0:1"); nm_ip4_address_unref (addr); nm_setting_verify (NM_SETTING (s_ip4), NULL, &error); g_assert_no_error (error); - label = NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, 1)); + label = _nm_setting_ip4_config_get_address_label (s_ip4, 1); g_assert_cmpstr (label, ==, "eth0:1"); /* addr 3 */ @@ -351,12 +351,12 @@ test_setting_ip4_config_labels (void) nm_ip4_address_set_address (addr, 0x03030303); nm_ip4_address_set_prefix (addr, 24); - NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_add_address_with_label (s_ip4, addr, NULL)); + _nm_setting_ip4_config_add_address_with_label (s_ip4, addr, NULL); nm_ip4_address_unref (addr); nm_setting_verify (NM_SETTING (s_ip4), NULL, &error); g_assert_no_error (error); - label = NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, 2)); + label = _nm_setting_ip4_config_get_address_label (s_ip4, 2); g_assert_cmpstr (label, ==, NULL); /* Remove addr 1 and re-verify remaining addresses */ @@ -366,12 +366,12 @@ test_setting_ip4_config_labels (void) addr = nm_setting_ip4_config_get_address (s_ip4, 0); g_assert_cmpint (nm_ip4_address_get_address (addr), ==, 0x02020202); - label = NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, 0)); + label = _nm_setting_ip4_config_get_address_label (s_ip4, 0); g_assert_cmpstr (label, ==, "eth0:1"); addr = nm_setting_ip4_config_get_address (s_ip4, 1); g_assert_cmpint (nm_ip4_address_get_address (addr), ==, 0x03030303); - label = NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, 1)); + label = _nm_setting_ip4_config_get_address_label (s_ip4, 1); g_assert_cmpstr (label, ==, NULL); @@ -395,12 +395,12 @@ test_setting_ip4_config_labels (void) addr = nm_setting_ip4_config_get_address (s_ip4, 0); g_assert_cmpint (nm_ip4_address_get_address (addr), ==, 0x02020202); - label = NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, 0)); + label = _nm_setting_ip4_config_get_address_label (s_ip4, 0); g_assert_cmpstr (label, ==, NULL); addr = nm_setting_ip4_config_get_address (s_ip4, 1); g_assert_cmpint (nm_ip4_address_get_address (addr), ==, 0x03030303); - label = NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, 1)); + label = _nm_setting_ip4_config_get_address_label (s_ip4, 1); g_assert_cmpstr (label, ==, NULL); /* Setting labels now will leave addresses untouched */ @@ -414,12 +414,12 @@ test_setting_ip4_config_labels (void) addr = nm_setting_ip4_config_get_address (s_ip4, 0); g_assert_cmpint (nm_ip4_address_get_address (addr), ==, 0x02020202); - label = NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, 0)); + label = _nm_setting_ip4_config_get_address_label (s_ip4, 0); g_assert_cmpstr (label, ==, "eth0:1"); addr = nm_setting_ip4_config_get_address (s_ip4, 1); g_assert_cmpint (nm_ip4_address_get_address (addr), ==, 0x03030303); - label = NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, 1)); + label = _nm_setting_ip4_config_get_address_label (s_ip4, 1); g_assert_cmpstr (label, ==, NULL); /* Setting labels to a value that's too short or too long will result in diff --git a/libnm/libnm.ver b/libnm/libnm.ver index 816979ffc7..f5c719bbb9 100644 --- a/libnm/libnm.ver +++ b/libnm/libnm.ver @@ -878,7 +878,6 @@ global: nm_utils_deinit; nm_utils_escape_ssid; nm_utils_file_is_pkcs12; - nm_utils_get_private; nm_utils_gvalue_hash_dup; nm_utils_hex2byte; nm_utils_hexstr2bin; diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c index b286edb995..e1395ed31c 100644 --- a/src/nm-ip4-config.c +++ b/src/nm-ip4-config.c @@ -29,7 +29,7 @@ #include "nm-dbus-glib-types.h" #include "nm-ip4-config-glue.h" #include "NetworkManagerUtils.h" -#include "nm-utils-private.h" +#include "nm-core-internal.h" G_DEFINE_TYPE (NMIP4Config, nm_ip4_config, G_TYPE_OBJECT) @@ -328,7 +328,7 @@ nm_ip4_config_merge_setting (NMIP4Config *config, NMSettingIP4Config *setting, i /* Addresses */ for (i = 0; i < naddresses; i++) { NMIP4Address *s_addr = nm_setting_ip4_config_get_address (setting, i); - const char *label = NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (setting, i)); + const char *label = _nm_setting_ip4_config_get_address_label (setting, i); NMPlatformIP4Address address; memset (&address, 0, sizeof (address)); @@ -426,7 +426,7 @@ nm_ip4_config_create_setting (const NMIP4Config *config) nm_ip4_address_set_gateway (s_addr, gateway); if (*address->label) - NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_add_address_with_label (s_ip4, s_addr, address->label)); + _nm_setting_ip4_config_add_address_with_label (s_ip4, s_addr, address->label); else nm_setting_ip4_config_add_address (s_ip4, s_addr); nm_ip4_address_unref (s_addr); diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c index a48290661a..2e990ecf33 100644 --- a/src/settings/plugins/ifcfg-rh/reader.c +++ b/src/settings/plugins/ifcfg-rh/reader.c @@ -48,7 +48,7 @@ #include #include #include -#include +#include "nm-core-internal.h" #include #include "nm-platform.h" @@ -1574,7 +1574,7 @@ read_aliases (NMSettingIP4Config *s_ip4, const char *filename, const char *netwo ok = read_full_ip4_address (parsed, network_file, -1, addr, &err); svCloseFile (parsed); if (ok) { - if (!NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_add_address_with_label (s_ip4, addr, device))) + if (!_nm_setting_ip4_config_add_address_with_label (s_ip4, addr, device)) PARSE_WARNING ("duplicate IP4 address in alias file %s", item); } else { PARSE_WARNING ("error reading IP4 address from alias file '%s': %s", diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index 8a726a3cea..724b9129b7 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -44,7 +44,7 @@ #include #include #include -#include +#include "nm-core-internal.h" #include "NetworkManagerUtils.h" @@ -2986,7 +2986,7 @@ test_read_wired_aliases_good (void) TEST_IFCFG_ALIASES_GOOD, i); - ASSERT (g_strcmp0 (NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, i)), expected_label[j]) == 0, + ASSERT (g_strcmp0 (_nm_setting_ip4_config_get_address_label (s_ip4, i), expected_label[j]) == 0, "aliases-good-verify-ip4", "failed to verify %s: unexpected IP4 address label #%d", TEST_IFCFG_ALIASES_GOOD, i); @@ -3113,7 +3113,7 @@ test_read_wired_aliases_bad (const char *base, const char *expected_id) "aliases-bad-verify-ip4", "failed to verify %s: unexpected IP4 address gateway", base); - ASSERT (g_strcmp0 (NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, 0)), expected_label) == 0, + ASSERT (g_strcmp0 (_nm_setting_ip4_config_get_address_label (s_ip4, 0), expected_label) == 0, "aliases-bad-verify-ip4", "failed to verify %s: unexpected IP4 address label", base); @@ -8185,7 +8185,7 @@ test_write_wired_aliases (void) nm_ip4_address_set_address (addr, ip[i]); nm_ip4_address_set_prefix (addr, prefix); nm_ip4_address_set_gateway (addr, gw); - NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_add_address_with_label (s_ip4, addr, label[i])); + _nm_setting_ip4_config_add_address_with_label (s_ip4, addr, label[i]); nm_ip4_address_unref (addr); } @@ -8293,7 +8293,7 @@ test_write_wired_aliases (void) testfile, i); - ASSERT (g_strcmp0 (NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, i)), label[j]) == 0, + ASSERT (g_strcmp0 (_nm_setting_ip4_config_get_address_label (s_ip4, i), label[j]) == 0, "wired-aliases-write-verify-ip4", "failed to verify %s: unexpected IP4 address label #%d", testfile, i); diff --git a/src/settings/plugins/ifcfg-rh/writer.c b/src/settings/plugins/ifcfg-rh/writer.c index ab12350837..e1c8f3678e 100644 --- a/src/settings/plugins/ifcfg-rh/writer.c +++ b/src/settings/plugins/ifcfg-rh/writer.c @@ -38,7 +38,7 @@ #include #include #include -#include +#include "nm-core-internal.h" #include #include "nm-logging.h" @@ -1927,7 +1927,7 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error) NMIP4Address *addr; guint32 ip; - if (i > 0 && NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, i))) + if (i > 0 && _nm_setting_ip4_config_get_address_label (s_ip4, i)) continue; if (n == 0) { @@ -2202,7 +2202,7 @@ write_ip4_aliases (NMConnection *connection, char *base_ifcfg_path) guint32 ip; shvarFile *ifcfg; - label = NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, i)); + label = _nm_setting_ip4_config_get_address_label (s_ip4, i); if (!label) continue; if ( strncmp (label, base_name, base_name_len) != 0 -- cgit v1.2.1