From 4e461dab4871feb78ca2248286b1d51bb944a6ba Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 31 Aug 2015 09:32:08 +0200 Subject: [PATCH 1/8] build: exclude private headers for mkenums and nm-enum-types.c --- src/Makefile.am | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Makefile.am b/src/Makefile.am index 0a60fb9745..1e05ec2831 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -379,7 +379,11 @@ endif GLIB_GENERATED = nm-enum-types.h nm-enum-types.c GLIB_MKENUMS_H_FLAGS = --identifier-prefix NM --fhead '\#include \n' GLIB_MKENUMS_C_FLAGS = --identifier-prefix NM -nm_enum_types_sources = $(libNetworkManager_la_SOURCES) +nm_enum_types_sources = $(filter-out \ + %/nm-device-private.h \ + %/nm-rdisc-private.h \ + %/wifi-utils-private.h \ + , $(libNetworkManager_la_SOURCES)) BUILT_SOURCES = $(GLIB_GENERATED) From ffb931ca5c17d35ff27413ddad6dfcd2a0113fd0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 30 Aug 2015 15:51:20 +0200 Subject: [PATCH 2/8] platform: refactor logging for sysctl functions Use the standard _LOG*() macros and make the static cache @sysctl_get_prev_values per instance. --- src/platform/nm-linux-platform.c | 72 ++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index b20e0837ef..937e1370f8 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -735,6 +735,8 @@ struct _NMLinuxPlatformPrivate { GIOChannel *event_channel; guint event_id; + GHashTable *sysctl_get_prev_values; + GUdevClient *udev_client; struct { @@ -2394,32 +2396,32 @@ event_notification (struct nl_msg *msg, gpointer user_data) /******************************************************************/ static void -_log_dbg_sysctl_set_impl (const char *path, const char *value) +_log_dbg_sysctl_set_impl (NMPlatform *platform, const char *path, const char *value) { GError *error = NULL; char *contents, *contents_escaped; char *value_escaped = g_strescape (value, NULL); if (!g_file_get_contents (path, &contents, NULL, &error)) { - debug ("sysctl: setting '%s' to '%s' (current value cannot be read: %s)", path, value_escaped, error->message); + _LOGD ("sysctl: setting '%s' to '%s' (current value cannot be read: %s)", path, value_escaped, error->message); g_clear_error (&error); } else { g_strstrip (contents); contents_escaped = g_strescape (contents, NULL); if (strcmp (contents, value) == 0) - debug ("sysctl: setting '%s' to '%s' (current value is identical)", path, value_escaped); + _LOGD ("sysctl: setting '%s' to '%s' (current value is identical)", path, value_escaped); else - debug ("sysctl: setting '%s' to '%s' (current value is '%s')", path, value_escaped, contents_escaped); + _LOGD ("sysctl: setting '%s' to '%s' (current value is '%s')", path, value_escaped, contents_escaped); g_free (contents); g_free (contents_escaped); } g_free (value_escaped); } -#define _log_dbg_sysctl_set(path, value) \ +#define _log_dbg_sysctl_set(platform, path, value) \ G_STMT_START { \ - if (nm_logging_enabled (LOGL_DEBUG, LOGD_PLATFORM)) { \ - _log_dbg_sysctl_set_impl (path, value); \ + if (_LOGD_ENABLED ()) { \ + _log_dbg_sysctl_set_impl (platform, path, value); \ } \ } G_STMT_END @@ -2441,16 +2443,16 @@ sysctl_set (NMPlatform *platform, const char *path, const char *value) fd = open (path, O_WRONLY | O_TRUNC); if (fd == -1) { if (errno == ENOENT) { - debug ("sysctl: failed to open '%s': (%d) %s", + _LOGD ("sysctl: failed to open '%s': (%d) %s", path, errno, strerror (errno)); } else { - error ("sysctl: failed to open '%s': (%d) %s", + _LOGE ("sysctl: failed to open '%s': (%d) %s", path, errno, strerror (errno)); } return FALSE; } - _log_dbg_sysctl_set (path, value); + _log_dbg_sysctl_set (platform, path, value); /* Most sysfs and sysctl options don't care about a trailing LF, while some * (like infiniband) do. So always add the LF. Also, neither sysfs nor @@ -2465,17 +2467,17 @@ sysctl_set (NMPlatform *platform, const char *path, const char *value) nwrote = write (fd, actual, len); if (nwrote == -1) { if (errno == EINTR) { - debug ("sysctl: interrupted, will try again"); + _LOGD ("sysctl: interrupted, will try again"); continue; } break; } } if (nwrote == -1 && errno != EEXIST) { - error ("sysctl: failed to set '%s' to '%s': (%d) %s", + _LOGE ("sysctl: failed to set '%s' to '%s': (%d) %s", path, value, errno, strerror (errno)); } else if (nwrote < len) { - error ("sysctl: failed to set '%s' to '%s' after three attempts", + _LOGE ("sysctl: failed to set '%s' to '%s' after three attempts", path, value); } @@ -2484,44 +2486,47 @@ sysctl_set (NMPlatform *platform, const char *path, const char *value) return (nwrote == len); } -static GHashTable *sysctl_get_prev_values; - static void -_log_dbg_sysctl_get_impl (const char *path, const char *contents) +_log_dbg_sysctl_get_impl (NMPlatform *platform, const char *path, const char *contents) { + NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform); const char *prev_value = NULL; - if (!sysctl_get_prev_values) - sysctl_get_prev_values = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + if (!priv->sysctl_get_prev_values) + priv->sysctl_get_prev_values = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); else - prev_value = g_hash_table_lookup (sysctl_get_prev_values, path); + prev_value = g_hash_table_lookup (priv->sysctl_get_prev_values, path); if (prev_value) { if (strcmp (prev_value, contents) != 0) { char *contents_escaped = g_strescape (contents, NULL); char *prev_value_escaped = g_strescape (prev_value, NULL); - debug ("sysctl: reading '%s': '%s' (changed from '%s' on last read)", path, contents_escaped, prev_value_escaped); + _LOGD ("sysctl: reading '%s': '%s' (changed from '%s' on last read)", path, contents_escaped, prev_value_escaped); g_free (contents_escaped); g_free (prev_value_escaped); - g_hash_table_insert (sysctl_get_prev_values, g_strdup (path), g_strdup (contents)); + g_hash_table_insert (priv->sysctl_get_prev_values, g_strdup (path), g_strdup (contents)); } } else { char *contents_escaped = g_strescape (contents, NULL); - debug ("sysctl: reading '%s': '%s'", path, contents_escaped); + _LOGD ("sysctl: reading '%s': '%s'", path, contents_escaped); g_free (contents_escaped); - g_hash_table_insert (sysctl_get_prev_values, g_strdup (path), g_strdup (contents)); + g_hash_table_insert (priv->sysctl_get_prev_values, g_strdup (path), g_strdup (contents)); } } -#define _log_dbg_sysctl_get(path, contents) \ +#define _log_dbg_sysctl_get(platform, path, contents) \ G_STMT_START { \ - if (nm_logging_enabled (LOGL_DEBUG, LOGD_PLATFORM)) { \ - _log_dbg_sysctl_get_impl (path, contents); \ - } else if (sysctl_get_prev_values) { \ - g_hash_table_destroy (sysctl_get_prev_values); \ - sysctl_get_prev_values = NULL; \ + if (_LOGD_ENABLED ()) { \ + _log_dbg_sysctl_get_impl (platform, path, contents); \ + } else { \ + NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform); \ + \ + if (priv->sysctl_get_prev_values) { \ + g_hash_table_destroy (priv->sysctl_get_prev_values); \ + priv->sysctl_get_prev_values = NULL; \ + } \ } \ } G_STMT_END @@ -2541,16 +2546,16 @@ sysctl_get (NMPlatform *platform, const char *path) /* We assume FAILED means EOPNOTSUP */ if ( g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT) || g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_FAILED)) - debug ("error reading %s: %s", path, error->message); + _LOGD ("error reading %s: %s", path, error->message); else - error ("error reading %s: %s", path, error->message); + _LOGE ("error reading %s: %s", path, error->message); g_clear_error (&error); return NULL; } g_strstrip (contents); - _log_dbg_sysctl_get (path, contents); + _log_dbg_sysctl_get (platform, path, contents); return contents; } @@ -4947,6 +4952,9 @@ nm_linux_platform_finalize (GObject *object) g_object_unref (priv->udev_client); g_hash_table_unref (priv->wifi_data); + if (priv->sysctl_get_prev_values) + g_hash_table_destroy (priv->sysctl_get_prev_values); + G_OBJECT_CLASS (nm_linux_platform_parent_class)->finalize (object); } From 084aec79dfd737ae004fcce267d0864b00563ae3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 30 Aug 2015 15:58:52 +0200 Subject: [PATCH 3/8] platform: refactor setup_socket() to accept explicit platform argument Also, use _LOGW() in verify_source() --- src/platform/nm-linux-platform.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 937e1370f8..4d44100033 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -4545,15 +4545,15 @@ ip6_route_get (NMPlatform *platform, int ifindex, struct in6_addr network, int p #define DISCONNECT_CONDITIONS ((GIOCondition) (G_IO_HUP)) static int -verify_source (struct nl_msg *msg, gpointer user_data) +verify_source (struct nl_msg *msg, NMPlatform *platform) { struct ucred *creds = nlmsg_get_creds (msg); if (!creds || creds->pid) { if (creds) - warning ("netlink: received non-kernel message (pid %d)", creds->pid); + _LOGW ("netlink: received non-kernel message (pid %d)", creds->pid); else - warning ("netlink: received message without credentials"); + _LOGW ("netlink: received message without credentials"); return NL_STOP; } @@ -4675,7 +4675,7 @@ event_handler_read_netlink_all (NMPlatform *platform, gboolean wait_for_acks) } static struct nl_sock * -setup_socket (gboolean event, gpointer user_data) +setup_socket (NMPlatform *platform, gboolean event) { struct nl_sock *sock; int nle; @@ -4684,14 +4684,14 @@ setup_socket (gboolean event, gpointer user_data) g_return_val_if_fail (sock, NULL); /* Only ever accept messages from kernel */ - nle = nl_socket_modify_cb (sock, NL_CB_MSG_IN, NL_CB_CUSTOM, verify_source, user_data); + nle = nl_socket_modify_cb (sock, NL_CB_MSG_IN, NL_CB_CUSTOM, (nl_recvmsg_msg_cb_t) verify_source, platform); g_assert (!nle); /* Dispatch event messages (event socket only) */ if (event) { - nl_socket_modify_cb (sock, NL_CB_VALID, NL_CB_CUSTOM, event_notification, user_data); - nl_socket_modify_cb (sock, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, event_seq_check, user_data); - nl_socket_modify_err_cb (sock, NL_CB_CUSTOM, event_err, user_data); + nl_socket_modify_cb (sock, NL_CB_VALID, NL_CB_CUSTOM, event_notification, platform); + nl_socket_modify_cb (sock, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, event_seq_check, platform); + nl_socket_modify_err_cb (sock, NL_CB_CUSTOM, event_err, platform); } nle = nl_connect (sock, NETLINK_ROUTE); @@ -4847,12 +4847,12 @@ constructed (GObject *_object) _LOGD ("create"); /* Initialize netlink socket for requests */ - priv->nlh = setup_socket (FALSE, platform); + priv->nlh = setup_socket (platform, FALSE); g_assert (priv->nlh); debug ("Netlink socket for requests established: port=%u, fd=%d", nl_socket_get_local_port (priv->nlh), nl_socket_get_fd (priv->nlh)); /* Initialize netlink socket for events */ - priv->nlh_event = setup_socket (TRUE, platform); + priv->nlh_event = setup_socket (platform, TRUE); g_assert (priv->nlh_event); /* The default buffer size wasn't enough for the testsuites. It might just * as well happen with NetworkManager itself. For now let's hope 128KB is From d47daeb4d9a5e0ddbafdb52017a5f2d384f64158 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 30 Aug 2015 16:01:55 +0200 Subject: [PATCH 4/8] platform: use _LOG*() macros instead of duplicated macros Use the common logging macros _LOGD(), etc. instead of calling nm_log_*() directly or the non-standard macros debug(), info(), etc. --- src/platform/nm-linux-platform.c | 60 ++++++++++++++++---------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 4d44100033..9b2faa3737 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -925,8 +925,8 @@ link_extract_type (NMPlatform *platform, struct rtnl_link *rtnllink, gboolean *c } flags = rtnl_link_get_flags (rtnllink); - nm_log_dbg (LOGD_PLATFORM, "Failed to read tun properties for interface %d (link flags: %X)", - rtnl_link_get_ifindex (rtnllink), flags); + _LOGD ("Failed to read tun properties for interface %d (link flags: %X)", + rtnl_link_get_ifindex (rtnllink), flags); /* try guessing the type using the link flags instead... */ if (flags & IFF_POINTOPOINT) @@ -2852,7 +2852,7 @@ link_add (NMPlatform *platform, nm_utils_modprobe (NULL, TRUE, "bonding", "max_bonds=0", NULL); } - debug ("link: add link '%s' of type '%s' (%d)", + _LOGD ("link: add link '%s' of type '%s' (%d)", name, nm_link_type_to_string (type), (int) type); l = build_rtnl_link (0, name, type); @@ -3019,7 +3019,7 @@ link_set_user_ipv6ll_enabled (NMPlatform *platform, int ifindex, gboolean enable char buf[32]; rtnl_link_inet6_set_addr_gen_mode (nlo, mode); - debug ("link: change %d: set IPv6 address generation mode to %s", + _LOGD ("link: change %d: set IPv6 address generation mode to %s", ifindex, rtnl_link_inet6_addrgenmode2str (mode, buf, sizeof (buf))); return do_change_link (platform, nlo, TRUE) == NM_PLATFORM_ERROR_SUCCESS; } @@ -3086,7 +3086,7 @@ link_set_mtu (NMPlatform *platform, int ifindex, guint32 mtu) auto_nl_object struct rtnl_link *change = _nl_rtnl_link_alloc (ifindex, NULL); rtnl_link_set_mtu (change, mtu); - debug ("link: change %d: mtu %lu", ifindex, (unsigned long)mtu); + _LOGD ("link: change %d: mtu %lu", ifindex, (unsigned long)mtu); return do_change_link (platform, change, TRUE) == NM_PLATFORM_ERROR_SUCCESS; } @@ -3157,7 +3157,7 @@ vlan_add (NMPlatform *platform, rtnl_link_vlan_set_id (rtnllink, vlan_id); rtnl_link_vlan_set_flags (rtnllink, kernel_flags); - debug ("link: add vlan '%s', parent %d, vlan id %d, flags %X (native: %X)", + _LOGD ("link: add vlan '%s', parent %d, vlan id %d, flags %X (native: %X)", name, parent, vlan_id, (unsigned int) vlan_flags, kernel_flags); return do_add_link_with_lookup (platform, name, rtnllink, NM_LINK_TYPE_VLAN, out_link); @@ -3188,7 +3188,7 @@ vlan_set_ingress_map (NMPlatform *platform, int ifindex, int from, int to) rtnl_link_set_type (change, "vlan"); rtnl_link_vlan_set_ingress_map (change, from, to); - debug ("link: change %d: vlan ingress map %d -> %d", ifindex, from, to); + _LOGD ("link: change %d: vlan ingress map %d -> %d", ifindex, from, to); return do_change_link (platform, change, TRUE) == NM_PLATFORM_ERROR_SUCCESS; } @@ -3201,7 +3201,7 @@ vlan_set_egress_map (NMPlatform *platform, int ifindex, int from, int to) rtnl_link_set_type (change, "vlan"); rtnl_link_vlan_set_egress_map (change, from, to); - debug ("link: change %d: vlan egress map %d -> %d", ifindex, from, to); + _LOGD ("link: change %d: vlan egress map %d -> %d", ifindex, from, to); return do_change_link (platform, change, TRUE) == NM_PLATFORM_ERROR_SUCCESS; } @@ -3212,7 +3212,7 @@ link_enslave (NMPlatform *platform, int master, int slave) auto_nl_object struct rtnl_link *change = _nl_rtnl_link_alloc (slave, NULL); rtnl_link_set_master (change, master); - debug ("link: change %d: enslave to master %d", slave, master); + _LOGD ("link: change %d: enslave to master %d", slave, master); return do_change_link (platform, change, TRUE) == NM_PLATFORM_ERROR_SUCCESS; } @@ -3592,8 +3592,8 @@ macvlan_get_properties (NMPlatform *platform, int ifindex, NMPlatformMacvlanProp err = _nl_link_parse_info_data (priv->nlh, ifindex, macvlan_info_data_parser, props); if (err != 0) { - warning ("(%s) could not read properties: %s", - obj->link.name, nl_geterror (err)); + _LOGW ("(%s) could not read properties: %s", + obj->link.name, nl_geterror (err)); } return (err == 0); } @@ -3723,8 +3723,8 @@ vxlan_get_properties (NMPlatform *platform, int ifindex, NMPlatformVxlanProperti err = _nl_link_parse_info_data (priv->nlh, ifindex, vxlan_info_data_parser, props); if (err != 0) { - warning ("(%s) could not read vxlan properties: %s", - nm_platform_link_get_name (platform, ifindex), nl_geterror (err)); + _LOGW ("(%s) could not read vxlan properties: %s", + nm_platform_link_get_name (platform, ifindex), nl_geterror (err)); } return (err == 0); } @@ -3777,8 +3777,8 @@ gre_get_properties (NMPlatform *platform, int ifindex, NMPlatformGreProperties * err = _nl_link_parse_info_data (priv->nlh, ifindex, gre_info_data_parser, props); if (err != 0) { - warning ("(%s) could not read gre properties: %s", - nm_platform_link_get_name (platform, ifindex), nl_geterror (err)); + _LOGW ("(%s) could not read gre properties: %s", + nm_platform_link_get_name (platform, ifindex), nl_geterror (err)); } return (err == 0); } @@ -4040,7 +4040,7 @@ build_rtnl_addr (NMPlatform *platform, /* IP address */ nle = rtnl_addr_set_local (rtnladdr, nladdr); if (nle) { - error ("build_rtnl_addr(): rtnl_addr_set_local failed with %s (%d)", nl_geterror (nle), nle); + _LOGE ("build_rtnl_addr(): rtnl_addr_set_local failed with %s (%d)", nl_geterror (nle), nle); return NULL; } @@ -4066,7 +4066,7 @@ build_rtnl_addr (NMPlatform *platform, nle = rtnl_addr_set_peer (rtnladdr, nlpeer); if (nle && nle != -NLE_AF_NOSUPPORT) { /* IPv6 doesn't support peer addresses yet */ - error ("build_rtnl_addr(): rtnl_addr_set_peer failed with %s (%d)", nl_geterror (nle), nle); + _LOGE ("build_rtnl_addr(): rtnl_addr_set_peer failed with %s (%d)", nl_geterror (nle), nle); return NULL; } } @@ -4586,10 +4586,10 @@ event_handler_read_netlink_one (NMPlatform *platform) case -NLE_AGAIN: return FALSE; case -NLE_DUMP_INTR: - debug ("Uncritical failure to retrieve incoming events: %s (%d)", nl_geterror (nle), nle); + _LOGD ("Uncritical failure to retrieve incoming events: %s (%d)", nl_geterror (nle), nle); break; case -NLE_NOMEM: - info ("Too many netlink events. Need to resynchronize platform cache"); + _LOGI ("Too many netlink events. Need to resynchronize platform cache"); /* Drain the event queue, we've lost events and are out of sync anyway and we'd * like to free up some space. We'll read in the status synchronously. */ _nl_sock_flush_data (priv->nlh_event); @@ -4603,7 +4603,7 @@ event_handler_read_netlink_one (NMPlatform *platform) NULL); break; default: - error ("Failed to retrieve incoming events: %s (%d)", nl_geterror (nle), nle); + _LOGE ("Failed to retrieve incoming events: %s (%d)", nl_geterror (nle), nle); break; } return TRUE; @@ -4731,23 +4731,23 @@ udev_device_added (NMPlatform *platform, ifname = g_udev_device_get_name (udev_device); if (!ifname) { - debug ("udev-add: failed to get device's interface"); + _LOGD ("udev-add: failed to get device's interface"); return; } if (g_udev_device_get_property (udev_device, "IFINDEX")) ifindex = g_udev_device_get_property_as_int (udev_device, "IFINDEX"); else { - warning ("(%s): udev-add: failed to get device's ifindex", ifname); + _LOGW ("(%s): udev-add: failed to get device's ifindex", ifname); return; } if (ifindex <= 0) { - warning ("(%s): udev-add: retrieved invalid IFINDEX=%d", ifname, ifindex); + _LOGW ("(%s): udev-add: retrieved invalid IFINDEX=%d", ifname, ifindex); return; } if (!g_udev_device_get_sysfs_path (udev_device)) { - debug ("(%s): udev-add: couldn't determine device path; ignoring...", ifname); + _LOGD ("(%s): udev-add: couldn't determine device path; ignoring...", ifname); return; } @@ -4777,7 +4777,7 @@ udev_device_removed (NMPlatform *platform, ifindex = obj->link.ifindex; } - debug ("udev-remove: IFINDEX=%d", ifindex); + _LOGD ("udev-remove: IFINDEX=%d", ifindex); if (ifindex <= 0) return; @@ -4803,9 +4803,9 @@ handle_udev_event (GUdevClient *client, ifindex = g_udev_device_get_property (udev_device, "IFINDEX"); seqnum = g_udev_device_get_seqnum (udev_device); - debug ("UDEV event: action '%s' subsys '%s' device '%s' (%s); seqnum=%" G_GUINT64_FORMAT, - action, subsys, g_udev_device_get_name (udev_device), - ifindex ? ifindex : "unknown", seqnum); + _LOGD ("UDEV event: action '%s' subsys '%s' device '%s' (%s); seqnum=%" G_GUINT64_FORMAT, + action, subsys, g_udev_device_get_name (udev_device), + ifindex ? ifindex : "unknown", seqnum); if (!strcmp (action, "add") || !strcmp (action, "move")) udev_device_added (platform, udev_device); @@ -4849,7 +4849,7 @@ constructed (GObject *_object) /* Initialize netlink socket for requests */ priv->nlh = setup_socket (platform, FALSE); g_assert (priv->nlh); - debug ("Netlink socket for requests established: port=%u, fd=%d", nl_socket_get_local_port (priv->nlh), nl_socket_get_fd (priv->nlh)); + _LOGD ("Netlink socket for requests established: port=%u, fd=%d", nl_socket_get_local_port (priv->nlh), nl_socket_get_fd (priv->nlh)); /* Initialize netlink socket for events */ priv->nlh_event = setup_socket (platform, TRUE); @@ -4866,7 +4866,7 @@ constructed (GObject *_object) RTNLGRP_IPV4_ROUTE, RTNLGRP_IPV6_ROUTE, 0); g_assert (!nle); - debug ("Netlink socket for events established: port=%u, fd=%d", nl_socket_get_local_port (priv->nlh_event), nl_socket_get_fd (priv->nlh_event)); + _LOGD ("Netlink socket for events established: port=%u, fd=%d", nl_socket_get_local_port (priv->nlh_event), nl_socket_get_fd (priv->nlh_event)); priv->event_channel = g_io_channel_unix_new (nl_socket_get_fd (priv->nlh_event)); g_io_channel_set_encoding (priv->event_channel, NULL, NULL); From ed5ebf7e74eddeb2c98af5d707ed8b6fe114c335 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 30 Aug 2015 16:05:44 +0200 Subject: [PATCH 5/8] logging: introduce an alternative set of logging macros We already have the macros _LOGD(), _LOGI(), etc. to provide context sensitive logging (such as printing the object pointer as prefix). In some implementations, we would like to have a second set of logging macros, that shall be used differently. For example, use the default _LOGD() for messages that are explicitly issued by one objects, and use _LOG2D() in a static context when no object is around. The "_LOG2" prefix is not great from a naming point of view. However, it is meant to be a second (alternative) set of logging macros with the same usage pattern as the _LOGD() macros. --- src/nm-logging.h | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/nm-logging.h b/src/nm-logging.h index d8cb2b874a..db9f0b1557 100644 --- a/src/nm-logging.h +++ b/src/nm-logging.h @@ -194,11 +194,43 @@ void nm_logging_syslog_openlog (const char *logging_backend); #define _LOGT_ENABLED(...) _NMLOG_ENABLED (LOGL_TRACE, ##__VA_ARGS__) #define _LOGT(...) _NMLOG (LOGL_TRACE, __VA_ARGS__) #else -/* still call the logging macros to get compile time checks, but they will be optimize out. */ +/* still call the logging macros to get compile time checks, but they will be optimized out. */ #define _LOGT_ENABLED(...) ( FALSE && (_NMLOG_ENABLED (LOGL_TRACE, ##__VA_ARGS__)) ) #define _LOGT(...) G_STMT_START { if (FALSE) { _NMLOG (LOGL_TRACE, __VA_ARGS__); } } G_STMT_END #endif /*****************************************************************************/ +/* Some implementation define a second set of logging macros, for a separate + * use. As with the _LOGD() macro familiy above, the exact implementation + * depends on the file that uses them. + * Still, it encourages a common pattern to have the common set of macros + * like _LOG2D(), _LOG2I(), etc. and have _LOG2T() which by default + * is disabled at compile time. */ + +#define _NMLOG2_ENABLED(level) ( nm_logging_enabled ((level), (_NMLOG2_DOMAIN)) ) + +#define _LOG2t(...) _NMLOG2 (LOGL_TRACE, __VA_ARGS__) +#define _LOG2D(...) _NMLOG2 (LOGL_DEBUG, __VA_ARGS__) +#define _LOG2I(...) _NMLOG2 (LOGL_INFO , __VA_ARGS__) +#define _LOG2W(...) _NMLOG2 (LOGL_WARN , __VA_ARGS__) +#define _LOG2E(...) _NMLOG2 (LOGL_ERR , __VA_ARGS__) + +#define _LOG2t_ENABLED(...) _NMLOG2_ENABLED (LOGL_TRACE, ##__VA_ARGS__) +#define _LOG2D_ENABLED(...) _NMLOG2_ENABLED (LOGL_DEBUG, ##__VA_ARGS__) +#define _LOG2I_ENABLED(...) _NMLOG2_ENABLED (LOGL_INFO , ##__VA_ARGS__) +#define _LOG2W_ENABLED(...) _NMLOG2_ENABLED (LOGL_WARN , ##__VA_ARGS__) +#define _LOG2E_ENABLED(...) _NMLOG2_ENABLED (LOGL_ERR , ##__VA_ARGS__) + +#ifdef NM_MORE_LOGGING +#define _LOG2T_ENABLED(...) _NMLOG2_ENABLED (LOGL_TRACE, ##__VA_ARGS__) +#define _LOG2T(...) _NMLOG2 (LOGL_TRACE, __VA_ARGS__) +#else +/* still call the logging macros to get compile time checks, but they will be optimized out. */ +#define _LOG2T_ENABLED(...) ( FALSE && (_NMLOG2_ENABLED (LOGL_TRACE, ##__VA_ARGS__)) ) +#define _LOG2T(...) G_STMT_START { if (FALSE) { _NMLOG2 (LOGL_TRACE, __VA_ARGS__); } } G_STMT_END +#endif + +/*****************************************************************************/ + #endif /* __NETWORKMANAGER_LOGGING_H__ */ From 6bb26f86802d2c4fa2e2bfc582a16ad2db6bb496 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 30 Aug 2015 16:08:51 +0200 Subject: [PATCH 6/8] platform: get rid of old logging macros The naming of these logging macros is unexpected, as we use such macros only here in platform. For these messages we cannot use the default _LOGD() set of macros, because there is no @platform instance around. So let's introduce an alternative set of logging macros (_LOG2D(), etc) and use it. --- src/platform/nm-linux-platform.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 9b2faa3737..6c17549426 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -66,9 +66,11 @@ /*********************************************************************************************/ -#define _NMLOG_DOMAIN LOGD_PLATFORM #define _NMLOG_PREFIX_NAME "platform-linux" -#define _NMLOG(level, ...) _LOG(level, _NMLOG_DOMAIN, platform, __VA_ARGS__) +#define _NMLOG_DOMAIN LOGD_PLATFORM +#define _NMLOG2_DOMAIN LOGD_PLATFORM +#define _NMLOG(level, ...) _LOG(level, _NMLOG_DOMAIN, platform, __VA_ARGS__) +#define _NMLOG2(level, ...) _LOG(level, _NMLOG2_DOMAIN, NULL, __VA_ARGS__) #define _LOG(level, domain, self, ...) \ G_STMT_START { \ @@ -90,12 +92,6 @@ } \ } G_STMT_END -#define trace(...) _LOG (LOGL_TRACE, _NMLOG_DOMAIN, NULL, __VA_ARGS__) -#define debug(...) _LOG (LOGL_DEBUG, _NMLOG_DOMAIN, NULL, __VA_ARGS__) -#define info(...) _LOG (LOGL_INFO, _NMLOG_DOMAIN, NULL, __VA_ARGS__) -#define warning(...) _LOG (LOGL_WARN , _NMLOG_DOMAIN, NULL, __VA_ARGS__) -#define error(...) _LOG (LOGL_ERR , _NMLOG_DOMAIN, NULL, __VA_ARGS__) - /****************************************************************** * Forward declarations and enums ******************************************************************/ @@ -167,7 +163,7 @@ _nl_get_vtable (void) if (!vtable.f_nl_has_capability) vtable.f_nl_has_capability = &_nl_f_nl_has_capability; - trace ("libnl: rtnl_link_get_link_netnsid() %s", vtable.f_rtnl_link_get_link_netnsid ? "supported" : "not supported"); + _LOG2t ("libnl: rtnl_link_get_link_netnsid() %s", vtable.f_rtnl_link_get_link_netnsid ? "supported" : "not supported"); g_return_val_if_fail (vtable.handle, &vtable); g_return_val_if_fail (vtable.handle_route, &vtable); @@ -529,7 +525,7 @@ _support_user_ipv6ll_get (void) #if HAVE_LIBNL_INET6_ADDR_GEN_MODE if (_support_user_ipv6ll_still_undecided ()) { _support_user_ipv6ll = -1; - nm_log_warn (LOGD_PLATFORM, "kernel support for IFLA_INET6_ADDR_GEN_MODE %s", "failed to detect; assume no support"); + _LOG2W ("kernel support for IFLA_INET6_ADDR_GEN_MODE %s", "failed to detect; assume no support"); } else return _support_user_ipv6ll > 0; #endif @@ -549,10 +545,10 @@ _support_user_ipv6ll_detect (const struct rtnl_link *rtnl_link) if (rtnl_link_inet6_get_addr_gen_mode ((struct rtnl_link *) rtnl_link, &mode) == 0) { _support_user_ipv6ll = 1; - nm_log_dbg (LOGD_PLATFORM, "kernel support for IFLA_INET6_ADDR_GEN_MODE %s", "detected"); + _LOG2D ("kernel support for IFLA_INET6_ADDR_GEN_MODE %s", "detected"); } else { _support_user_ipv6ll = -1; - nm_log_dbg (LOGD_PLATFORM, "kernel support for IFLA_INET6_ADDR_GEN_MODE %s", "not detected"); + _LOG2D ("kernel support for IFLA_INET6_ADDR_GEN_MODE %s", "not detected"); } } #endif @@ -593,7 +589,7 @@ static gboolean _support_kernel_extended_ifa_flags_get (void) { if (_support_kernel_extended_ifa_flags_still_undecided ()) { - nm_log_warn (LOGD_PLATFORM, "Unable to detect kernel support for extended IFA_FLAGS. Assume no kernel support."); + _LOG2W ("Unable to detect kernel support for extended IFA_FLAGS. Assume no kernel support."); _support_kernel_extended_ifa_flags = -1; } return _support_kernel_extended_ifa_flags > 0; From edadef563f90ce7df27c145b050c730fb1b9ab69 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 30 Aug 2015 16:35:06 +0200 Subject: [PATCH 7/8] platform/test: introduce _LOGD() macros to fake platform and platform tests --- src/platform/nm-fake-platform.c | 30 ++++++++++++++++++++++++++++-- src/platform/tests/test-address.c | 4 ++-- src/platform/tests/test-common.c | 18 +++++++++--------- src/platform/tests/test-common.h | 20 +++++++++++++++++++- src/platform/tests/test-route.c | 4 ++-- 5 files changed, 60 insertions(+), 16 deletions(-) diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c index 03ff8a5bdd..8259eac6b5 100644 --- a/src/platform/nm-fake-platform.c +++ b/src/platform/nm-fake-platform.c @@ -33,7 +33,33 @@ #include "nm-test-utils.h" -#define debug(format, ...) nm_log_dbg (LOGD_PLATFORM, format, __VA_ARGS__) +/*********************************************************************************************/ + +#define _NMLOG_PREFIX_NAME "platform-fake" +#define _NMLOG_DOMAIN LOGD_PLATFORM +#define _NMLOG(level, ...) _LOG(level, _NMLOG_DOMAIN, platform, __VA_ARGS__) + +#define _LOG(level, domain, self, ...) \ + G_STMT_START { \ + const NMLogLevel __level = (level); \ + const NMLogDomain __domain = (domain); \ + \ + if (nm_logging_enabled (__level, __domain)) { \ + char __prefix[32]; \ + const char *__p_prefix = _NMLOG_PREFIX_NAME; \ + const void *const __self = (self); \ + \ + if (__self && __self != nm_platform_try_get ()) { \ + g_snprintf (__prefix, sizeof (__prefix), "%s[%p]", _NMLOG_PREFIX_NAME, __self); \ + __p_prefix = __prefix; \ + } \ + _nm_log (__level, __domain, 0, \ + "%s: " _NM_UTILS_MACRO_FIRST (__VA_ARGS__), \ + __p_prefix _NM_UTILS_MACRO_REST (__VA_ARGS__)); \ + } \ + } G_STMT_END + +/*********************************************************************************************/ typedef struct { GHashTable *options; @@ -156,7 +182,7 @@ link_get (NMPlatform *platform, int ifindex) return device; not_found: - debug ("link not found: %d", ifindex); + _LOGD ("link not found: %d", ifindex); return NULL; } diff --git a/src/platform/tests/test-address.c b/src/platform/tests/test-address.c index d6f346b376..639fa0c80e 100644 --- a/src/platform/tests/test-address.c +++ b/src/platform/tests/test-address.c @@ -25,7 +25,7 @@ ip4_address_callback (NMPlatform *platform, NMPObjectType obj_type, int ifindex, g_main_loop_quit (data->loop); data->received_count++; - debug ("Received signal '%s' %dth time.", data->name, data->received_count); + _LOGD ("Received signal '%s' %dth time.", data->name, data->received_count); } static void @@ -45,7 +45,7 @@ ip6_address_callback (NMPlatform *platform, NMPObjectType obj_type, int ifindex, g_main_loop_quit (data->loop); data->received_count++; - debug ("Received signal '%s' %dth time.", data->name, data->received_count); + _LOGD ("Received signal '%s' %dth time.", data->name, data->received_count); } static void diff --git a/src/platform/tests/test-common.c b/src/platform/tests/test-common.c index b0eae63b77..dd8ec80c53 100644 --- a/src/platform/tests/test-common.c +++ b/src/platform/tests/test-common.c @@ -46,7 +46,7 @@ add_signal_full (const char *name, NMPlatformSignalChangeType change_type, GCall void _accept_signal (const char *file, int line, const char *func, SignalData *data) { - debug ("NMPlatformSignalAssert: %s:%d, %s(): Accepting signal one time: "SIGNAL_DATA_FMT, file, line, func, SIGNAL_DATA_ARG (data)); + _LOGD ("NMPlatformSignalAssert: %s:%d, %s(): Accepting signal one time: "SIGNAL_DATA_FMT, file, line, func, SIGNAL_DATA_ARG (data)); if (data->received_count != 1) g_error ("NMPlatformSignalAssert: %s:%d, %s(): failure to accept signal one time: "SIGNAL_DATA_FMT, file, line, func, SIGNAL_DATA_ARG (data)); data->received_count = 0; @@ -55,7 +55,7 @@ _accept_signal (const char *file, int line, const char *func, SignalData *data) void _accept_signals (const char *file, int line, const char *func, SignalData *data, int min, int max) { - debug ("NMPlatformSignalAssert: %s:%d, %s(): Accepting signal [%d,%d] times: "SIGNAL_DATA_FMT, file, line, func, min, max, SIGNAL_DATA_ARG (data)); + _LOGD ("NMPlatformSignalAssert: %s:%d, %s(): Accepting signal [%d,%d] times: "SIGNAL_DATA_FMT, file, line, func, min, max, SIGNAL_DATA_ARG (data)); if (data->received_count < min || data->received_count > max) g_error ("NMPlatformSignalAssert: %s:%d, %s(): failure to accept signal [%d,%d] times: "SIGNAL_DATA_FMT, file, line, func, min, max, SIGNAL_DATA_ARG (data)); data->received_count = 0; @@ -64,7 +64,7 @@ _accept_signals (const char *file, int line, const char *func, SignalData *data, void _ensure_no_signal (const char *file, int line, const char *func, SignalData *data) { - debug ("NMPlatformSignalAssert: %s:%d, %s(): Accepting signal 0 times: "SIGNAL_DATA_FMT, file, line, func, SIGNAL_DATA_ARG (data)); + _LOGD ("NMPlatformSignalAssert: %s:%d, %s(): Accepting signal 0 times: "SIGNAL_DATA_FMT, file, line, func, SIGNAL_DATA_ARG (data)); if (data->received_count > 0) g_error ("NMPlatformSignalAssert: %s:%d, %s(): failure to accept signal 0 times: "SIGNAL_DATA_FMT, file, line, func, SIGNAL_DATA_ARG (data)); } @@ -72,7 +72,7 @@ _ensure_no_signal (const char *file, int line, const char *func, SignalData *dat void _wait_signal (const char *file, int line, const char *func, SignalData *data) { - debug ("NMPlatformSignalAssert: %s:%d, %s(): wait signal: "SIGNAL_DATA_FMT, file, line, func, SIGNAL_DATA_ARG (data)); + _LOGD ("NMPlatformSignalAssert: %s:%d, %s(): wait signal: "SIGNAL_DATA_FMT, file, line, func, SIGNAL_DATA_ARG (data)); if (data->received_count) g_error ("NMPlatformSignalAssert: %s:%d, %s(): failure to wait for signal: "SIGNAL_DATA_FMT, file, line, func, SIGNAL_DATA_ARG (data)); @@ -86,7 +86,7 @@ _wait_signal (const char *file, int line, const char *func, SignalData *data) void _free_signal (const char *file, int line, const char *func, SignalData *data) { - debug ("NMPlatformSignalAssert: %s:%d, %s(): free signal: "SIGNAL_DATA_FMT, file, line, func, SIGNAL_DATA_ARG (data)); + _LOGD ("NMPlatformSignalAssert: %s:%d, %s(): free signal: "SIGNAL_DATA_FMT, file, line, func, SIGNAL_DATA_ARG (data)); if (data->received_count != 0) g_error ("NMPlatformSignalAssert: %s:%d, %s(): failure to free non-accepted signal: "SIGNAL_DATA_FMT, file, line, func, SIGNAL_DATA_ARG (data)); @@ -114,12 +114,12 @@ link_callback (NMPlatform *platform, NMPObjectType obj_type, int ifindex, NMPlat return; if (data->loop) { - debug ("Quitting main loop."); + _LOGD ("Quitting main loop."); g_main_loop_quit (data->loop); } data->received_count++; - debug ("Received signal '%s-%s' ifindex %d ifname '%s' %dth time.", data->name, nm_platform_signal_change_type_to_string (data->change_type), ifindex, received->name, data->received_count); + _LOGD ("Received signal '%s-%s' ifindex %d ifname '%s' %dth time.", data->name, nm_platform_signal_change_type_to_string (data->change_type), ifindex, received->name, data->received_count); if (change_type == NM_PLATFORM_SIGNAL_REMOVED) g_assert (!nm_platform_link_get_name (NM_PLATFORM_GET, ifindex)); @@ -262,9 +262,9 @@ run_command (const char *format, ...) va_start (ap, format); command = g_strdup_vprintf (format, ap); va_end (ap); - debug ("Running command: %s", command); + _LOGD ("Running command: %s", command); g_assert (!system (command)); - debug ("Command finished."); + _LOGD ("Command finished."); g_free (command); } diff --git a/src/platform/tests/test-common.h b/src/platform/tests/test-common.h index e69f956f5a..3a2f6d5f13 100644 --- a/src/platform/tests/test-common.h +++ b/src/platform/tests/test-common.h @@ -13,7 +13,25 @@ #define DEVICE_NAME "nm-test-device" -#define debug(...) nm_log_dbg (LOGD_PLATFORM, __VA_ARGS__) +/*********************************************************************************************/ + +#define _NMLOG_PREFIX_NAME "platform-test" +#define _NMLOG_DOMAIN LOGD_PLATFORM +#define _NMLOG(level, ...) _LOG(level, _NMLOG_DOMAIN, __VA_ARGS__) + +#define _LOG(level, domain, ...) \ + G_STMT_START { \ + const NMLogLevel __level = (level); \ + const NMLogDomain __domain = (domain); \ + \ + if (nm_logging_enabled (__level, __domain)) { \ + _nm_log (__level, __domain, 0, \ + "%s: " _NM_UTILS_MACRO_FIRST (__VA_ARGS__), \ + _NMLOG_PREFIX_NAME _NM_UTILS_MACRO_REST (__VA_ARGS__)); \ + } \ + } G_STMT_END + +/*********************************************************************************************/ typedef struct { int handler_id; diff --git a/src/platform/tests/test-route.c b/src/platform/tests/test-route.c index cf322dec6e..3f7e4463b5 100644 --- a/src/platform/tests/test-route.c +++ b/src/platform/tests/test-route.c @@ -25,7 +25,7 @@ ip4_route_callback (NMPlatform *platform, NMPObjectType obj_type, int ifindex, c g_main_loop_quit (data->loop); data->received_count++; - debug ("Received signal '%s' %dth time.", data->name, data->received_count); + _LOGD ("Received signal '%s' %dth time.", data->name, data->received_count); } static void @@ -45,7 +45,7 @@ ip6_route_callback (NMPlatform *platform, NMPObjectType obj_type, int ifindex, c g_main_loop_quit (data->loop); data->received_count++; - debug ("Received signal '%s' %dth time.", data->name, data->received_count); + _LOGD ("Received signal '%s' %dth time.", data->name, data->received_count); } static void From b10210a74402d16a7ccdf184080d2a780c7cbeca Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 30 Aug 2015 16:32:29 +0200 Subject: [PATCH 8/8] rdisc: refactor logging and use common _LOGD() macro --- src/rdisc/nm-fake-rdisc.c | 4 +--- src/rdisc/nm-lndp-rdisc.c | 14 ++++++------ src/rdisc/nm-rdisc-private.h | 29 +++++++++++++++++++++++++ src/rdisc/nm-rdisc.c | 42 ++++++++++++++++++------------------ 4 files changed, 57 insertions(+), 32 deletions(-) diff --git a/src/rdisc/nm-fake-rdisc.c b/src/rdisc/nm-fake-rdisc.c index 25ba3f7fb7..36f386c36f 100644 --- a/src/rdisc/nm-fake-rdisc.c +++ b/src/rdisc/nm-fake-rdisc.c @@ -28,9 +28,7 @@ #include "nm-default.h" -#define debug(...) nm_log_dbg (LOGD_IP6, __VA_ARGS__) -#define warning(...) nm_log_warn (LOGD_IP6, __VA_ARGS__) -#define error(...) nm_log_err (LOGD_IP6, __VA_ARGS__) +#define _NMLOG_PREFIX_NAME "rdisc-fake" typedef struct { guint id; diff --git a/src/rdisc/nm-lndp-rdisc.c b/src/rdisc/nm-lndp-rdisc.c index f31a13b2a1..a65ab03239 100644 --- a/src/rdisc/nm-lndp-rdisc.c +++ b/src/rdisc/nm-lndp-rdisc.c @@ -33,9 +33,7 @@ #include "nm-default.h" #include "nm-platform.h" -#define debug(...) nm_log_dbg (LOGD_IP6, __VA_ARGS__) -#define warning(...) nm_log_warn (LOGD_IP6, __VA_ARGS__) -#define error(...) nm_log_err (LOGD_IP6, __VA_ARGS__) +#define _NMLOG_PREFIX_NAME "rdisc-lndp" typedef struct { struct ndp *ndp; @@ -65,7 +63,7 @@ send_rs (NMRDisc *rdisc) error = ndp_msg_send (priv->ndp, msg); ndp_msg_destroy (msg); if (error) { - error ("(%s): cannot send router solicitation: %d.", rdisc->ifname, error); + _LOGE ("cannot send router solicitation: %d.", error); return FALSE; } @@ -109,7 +107,7 @@ receive_ra (struct ndp *ndp, struct ndp_msg *msg, gpointer user_data) * single time when the configuration is finished and updates can * come at any time. */ - debug ("(%s): received router advertisement at %u", rdisc->ifname, now); + _LOGD ("received router advertisement at %u", now); /* DHCP level: * @@ -260,7 +258,7 @@ receive_ra (struct ndp *ndp, struct ndp_msg *msg, gpointer user_data) * Kernel would set it, but would flush out all IPv6 addresses away * from the link, even the link-local, and we wouldn't be able to * listen for further RAs that could fix the MTU. */ - warning ("(%s): MTU too small for IPv6 ignored: %d", rdisc->ifname, mtu); + _LOGW ("MTU too small for IPv6 ignored: %d", mtu); } } @@ -273,7 +271,7 @@ event_ready (GIOChannel *source, GIOCondition condition, NMRDisc *rdisc) { NMLNDPRDiscPrivate *priv = NM_LNDP_RDISC_GET_PRIVATE (rdisc); - debug ("(%s): processing libndp events.", rdisc->ifname); + _LOGD ("processing libndp events"); ndp_callall_eventfd_handler (priv->ndp); return G_SOURCE_CONTINUE; } @@ -323,8 +321,8 @@ nm_lndp_rdisc_new (int ifindex, const char *ifname) priv = NM_LNDP_RDISC_GET_PRIVATE (rdisc); error = ndp_open (&priv->ndp); if (error != 0) { + _LOGD ("error creating socket for NDP; errno=%d", -error); g_object_unref (rdisc); - debug ("(%s): error creating socket for NDP; errno=%d", ifname, -error); return NULL; } return rdisc; diff --git a/src/rdisc/nm-rdisc-private.h b/src/rdisc/nm-rdisc-private.h index f95949def7..59c0cf3757 100644 --- a/src/rdisc/nm-rdisc-private.h +++ b/src/rdisc/nm-rdisc-private.h @@ -33,4 +33,33 @@ gboolean nm_rdisc_add_route (NMRDisc *rdisc, const NMRDiscRoute *new); gboolean nm_rdisc_add_dns_server (NMRDisc *rdisc, const NMRDiscDNSServer *new); gboolean nm_rdisc_add_dns_domain (NMRDisc *rdisc, const NMRDiscDNSDomain *new); +/*********************************************************************************************/ + +#define _NMLOG_DOMAIN LOGD_IP6 +#define _NMLOG(level, ...) _LOG(level, _NMLOG_DOMAIN, rdisc, __VA_ARGS__) + +#define _LOG(level, domain, self, ...) \ + G_STMT_START { \ + const NMLogLevel __level = (level); \ + const NMLogDomain __domain = (domain); \ + \ + if (nm_logging_enabled (__level, __domain)) { \ + char __prefix[64]; \ + const char *__p_prefix = _NMLOG_PREFIX_NAME; \ + const NMRDisc *const __self = (self); \ + \ + if (__self) { \ + g_snprintf (__prefix, sizeof (__prefix), "%s[%p,%s%s%s]", \ + _NMLOG_PREFIX_NAME, __self, \ + NM_PRINT_FMT_QUOTE_STRING (__self->ifname)); \ + __p_prefix = __prefix; \ + } \ + _nm_log (__level, __domain, 0, \ + "%s: " _NM_UTILS_MACRO_FIRST (__VA_ARGS__), \ + __p_prefix _NM_UTILS_MACRO_REST (__VA_ARGS__)); \ + } \ + } G_STMT_END + +/*********************************************************************************************/ + #endif /* __NETWORKMANAGER_RDISC_PRIVATE_H__ */ diff --git a/src/rdisc/nm-rdisc.c b/src/rdisc/nm-rdisc.c index 35436e9d11..cad3a90eed 100644 --- a/src/rdisc/nm-rdisc.c +++ b/src/rdisc/nm-rdisc.c @@ -30,7 +30,7 @@ #include "nm-default.h" #include "nm-utils.h" -#define debug(...) nm_log_dbg (LOGD_IP6, __VA_ARGS__) +#define _NMLOG_PREFIX_NAME "rdisc" typedef struct { int solicitations_left; @@ -243,7 +243,7 @@ nm_rdisc_set_iid (NMRDisc *rdisc, const NMUtilsIPv6IfaceId iid) if (rdisc->iid.id != iid.id) { rdisc->iid = iid; if (rdisc->addresses->len) { - debug ("(%s) IPv6 interface identifier changed, flushing addresses", rdisc->ifname); + _LOGD ("IPv6 interface identifier changed, flushing addresses"); g_array_remove_range (rdisc->addresses, 0, rdisc->addresses->len); g_signal_emit_by_name (rdisc, NM_RDISC_CONFIG_CHANGED, NM_RDISC_CONFIG_ADDRESSES); } @@ -281,20 +281,20 @@ send_rs (NMRDisc *rdisc) NMRDiscClass *klass = NM_RDISC_GET_CLASS (rdisc); NMRDiscPrivate *priv = NM_RDISC_GET_PRIVATE (rdisc); - debug ("(%s): sending router solicitation", rdisc->ifname); + _LOGD ("sending router solicitation"); if (klass->send_rs (rdisc)) priv->solicitations_left--; priv->last_rs = nm_utils_get_monotonic_timestamp_s (); if (priv->solicitations_left > 0) { - debug ("(%s): scheduling router solicitation retry in %d seconds.", - rdisc->ifname, rdisc->rtr_solicitation_interval); + _LOGD ("scheduling router solicitation retry in %d seconds.", + rdisc->rtr_solicitation_interval); priv->send_rs_id = g_timeout_add_seconds (rdisc->rtr_solicitation_interval, (GSourceFunc) send_rs, rdisc); } else { - debug ("(%s): did not receive a router advertisement after %d solicitations.", - rdisc->ifname, rdisc->rtr_solicitations); + _LOGD ("did not receive a router advertisement after %d solicitations.", + rdisc->rtr_solicitations); priv->send_rs_id = 0; } @@ -312,8 +312,8 @@ solicit (NMRDisc *rdisc) priv->solicitations_left = rdisc->rtr_solicitations; next = CLAMP (priv->last_rs + rdisc->rtr_solicitation_interval - now, 0, G_MAXINT32); - debug ("(%s): scheduling explicit router solicitation request in %" G_GINT64_FORMAT " seconds.", - rdisc->ifname, next); + _LOGD ("scheduling explicit router solicitation request in %" G_GINT64_FORMAT " seconds.", + next); priv->send_rs_id = g_timeout_add_seconds ((guint32) next, (GSourceFunc) send_rs, rdisc); } } @@ -337,12 +337,12 @@ nm_rdisc_start (NMRDisc *rdisc) g_assert (klass->start); - debug ("(%s): starting router discovery: %d", rdisc->ifname, rdisc->ifindex); + _LOGD ("starting router discovery: %d", rdisc->ifindex); clear_ra_timeout (rdisc); ra_wait_secs = CLAMP (rdisc->rtr_solicitations * rdisc->rtr_solicitation_interval, 30, 120); priv->ra_timeout_id = g_timeout_add_seconds (ra_wait_secs, rdisc_ra_timeout_cb, rdisc); - debug ("(%s): scheduling RA timeout in %d seconds", rdisc->ifname, ra_wait_secs); + _LOGD ("scheduling RA timeout in %d seconds", ra_wait_secs); if (klass->start) klass->start (rdisc); @@ -394,27 +394,27 @@ config_changed (NMRDisc *rdisc, NMRDiscConfigMap changed) char changedstr[CONFIG_MAP_MAX_STR]; char addrstr[INET6_ADDRSTRLEN]; - if (nm_logging_enabled (LOGL_DEBUG, LOGD_IP6)) { + if (_LOGD_ENABLED ()) { config_map_to_string (changed, changedstr); - debug ("(%s): router discovery configuration changed [%s]:", rdisc->ifname, changedstr); - debug (" dhcp-level %s", dhcp_level_to_string (rdisc->dhcp_level)); + _LOGD ("router discovery configuration changed [%s]:", changedstr); + _LOGD (" dhcp-level %s", dhcp_level_to_string (rdisc->dhcp_level)); for (i = 0; i < rdisc->gateways->len; i++) { NMRDiscGateway *gateway = &g_array_index (rdisc->gateways, NMRDiscGateway, i); inet_ntop (AF_INET6, &gateway->address, addrstr, sizeof (addrstr)); - debug (" gateway %s pref %d exp %u", addrstr, gateway->preference, expiry (gateway)); + _LOGD (" gateway %s pref %d exp %u", addrstr, gateway->preference, expiry (gateway)); } for (i = 0; i < rdisc->addresses->len; i++) { NMRDiscAddress *address = &g_array_index (rdisc->addresses, NMRDiscAddress, i); inet_ntop (AF_INET6, &address->address, addrstr, sizeof (addrstr)); - debug (" address %s exp %u", addrstr, expiry (address)); + _LOGD (" address %s exp %u", addrstr, expiry (address)); } for (i = 0; i < rdisc->routes->len; i++) { NMRDiscRoute *route = &g_array_index (rdisc->routes, NMRDiscRoute, i); inet_ntop (AF_INET6, &route->network, addrstr, sizeof (addrstr)); - debug (" route %s/%d via %s pref %d exp %u", addrstr, route->plen, + _LOGD (" route %s/%d via %s pref %d exp %u", addrstr, route->plen, nm_utils_inet6_ntop (&route->gateway, NULL), route->preference, expiry (route)); } @@ -422,12 +422,12 @@ config_changed (NMRDisc *rdisc, NMRDiscConfigMap changed) NMRDiscDNSServer *dns_server = &g_array_index (rdisc->dns_servers, NMRDiscDNSServer, i); inet_ntop (AF_INET6, &dns_server->address, addrstr, sizeof (addrstr)); - debug (" dns_server %s exp %u", addrstr, expiry (dns_server)); + _LOGD (" dns_server %s exp %u", addrstr, expiry (dns_server)); } for (i = 0; i < rdisc->dns_domains->len; i++) { NMRDiscDNSDomain *dns_domain = &g_array_index (rdisc->dns_domains, NMRDiscDNSDomain, i); - debug (" dns_domain %s exp %u", dns_domain->domain, expiry (dns_domain)); + _LOGD (" dns_domain %s exp %u", dns_domain->domain, expiry (dns_domain)); } } } @@ -564,8 +564,8 @@ check_timestamps (NMRDisc *rdisc, guint32 now, NMRDiscConfigMap changed) if (nextevent != never) { g_return_if_fail (nextevent > now); - debug ("(%s): scheduling next now/lifetime check: %u seconds", - rdisc->ifname, nextevent - now); + _LOGD ("scheduling next now/lifetime check: %u seconds", + nextevent - now); priv->timeout_id = g_timeout_add_seconds (nextevent - now, timeout_cb, rdisc); } }