rdisc: refactor logging and use common _LOGD() macro
This commit is contained in:
@@ -28,9 +28,7 @@
|
|||||||
|
|
||||||
#include "nm-default.h"
|
#include "nm-default.h"
|
||||||
|
|
||||||
#define debug(...) nm_log_dbg (LOGD_IP6, __VA_ARGS__)
|
#define _NMLOG_PREFIX_NAME "rdisc-fake"
|
||||||
#define warning(...) nm_log_warn (LOGD_IP6, __VA_ARGS__)
|
|
||||||
#define error(...) nm_log_err (LOGD_IP6, __VA_ARGS__)
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
guint id;
|
guint id;
|
||||||
|
@@ -33,9 +33,7 @@
|
|||||||
#include "nm-default.h"
|
#include "nm-default.h"
|
||||||
#include "nm-platform.h"
|
#include "nm-platform.h"
|
||||||
|
|
||||||
#define debug(...) nm_log_dbg (LOGD_IP6, __VA_ARGS__)
|
#define _NMLOG_PREFIX_NAME "rdisc-lndp"
|
||||||
#define warning(...) nm_log_warn (LOGD_IP6, __VA_ARGS__)
|
|
||||||
#define error(...) nm_log_err (LOGD_IP6, __VA_ARGS__)
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
struct ndp *ndp;
|
struct ndp *ndp;
|
||||||
@@ -65,7 +63,7 @@ send_rs (NMRDisc *rdisc)
|
|||||||
error = ndp_msg_send (priv->ndp, msg);
|
error = ndp_msg_send (priv->ndp, msg);
|
||||||
ndp_msg_destroy (msg);
|
ndp_msg_destroy (msg);
|
||||||
if (error) {
|
if (error) {
|
||||||
error ("(%s): cannot send router solicitation: %d.", rdisc->ifname, error);
|
_LOGE ("cannot send router solicitation: %d.", error);
|
||||||
return FALSE;
|
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
|
* single time when the configuration is finished and updates can
|
||||||
* come at any time.
|
* come at any time.
|
||||||
*/
|
*/
|
||||||
debug ("(%s): received router advertisement at %u", rdisc->ifname, now);
|
_LOGD ("received router advertisement at %u", now);
|
||||||
|
|
||||||
/* DHCP level:
|
/* 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
|
* 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
|
* from the link, even the link-local, and we wouldn't be able to
|
||||||
* listen for further RAs that could fix the MTU. */
|
* 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);
|
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);
|
ndp_callall_eventfd_handler (priv->ndp);
|
||||||
return G_SOURCE_CONTINUE;
|
return G_SOURCE_CONTINUE;
|
||||||
}
|
}
|
||||||
@@ -323,8 +321,8 @@ nm_lndp_rdisc_new (int ifindex, const char *ifname)
|
|||||||
priv = NM_LNDP_RDISC_GET_PRIVATE (rdisc);
|
priv = NM_LNDP_RDISC_GET_PRIVATE (rdisc);
|
||||||
error = ndp_open (&priv->ndp);
|
error = ndp_open (&priv->ndp);
|
||||||
if (error != 0) {
|
if (error != 0) {
|
||||||
|
_LOGD ("error creating socket for NDP; errno=%d", -error);
|
||||||
g_object_unref (rdisc);
|
g_object_unref (rdisc);
|
||||||
debug ("(%s): error creating socket for NDP; errno=%d", ifname, -error);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return rdisc;
|
return rdisc;
|
||||||
|
@@ -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_server (NMRDisc *rdisc, const NMRDiscDNSServer *new);
|
||||||
gboolean nm_rdisc_add_dns_domain (NMRDisc *rdisc, const NMRDiscDNSDomain *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__ */
|
#endif /* __NETWORKMANAGER_RDISC_PRIVATE_H__ */
|
||||||
|
@@ -30,7 +30,7 @@
|
|||||||
#include "nm-default.h"
|
#include "nm-default.h"
|
||||||
#include "nm-utils.h"
|
#include "nm-utils.h"
|
||||||
|
|
||||||
#define debug(...) nm_log_dbg (LOGD_IP6, __VA_ARGS__)
|
#define _NMLOG_PREFIX_NAME "rdisc"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int solicitations_left;
|
int solicitations_left;
|
||||||
@@ -243,7 +243,7 @@ nm_rdisc_set_iid (NMRDisc *rdisc, const NMUtilsIPv6IfaceId iid)
|
|||||||
if (rdisc->iid.id != iid.id) {
|
if (rdisc->iid.id != iid.id) {
|
||||||
rdisc->iid = iid;
|
rdisc->iid = iid;
|
||||||
if (rdisc->addresses->len) {
|
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_array_remove_range (rdisc->addresses, 0, rdisc->addresses->len);
|
||||||
g_signal_emit_by_name (rdisc, NM_RDISC_CONFIG_CHANGED, NM_RDISC_CONFIG_ADDRESSES);
|
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);
|
NMRDiscClass *klass = NM_RDISC_GET_CLASS (rdisc);
|
||||||
NMRDiscPrivate *priv = NM_RDISC_GET_PRIVATE (rdisc);
|
NMRDiscPrivate *priv = NM_RDISC_GET_PRIVATE (rdisc);
|
||||||
|
|
||||||
debug ("(%s): sending router solicitation", rdisc->ifname);
|
_LOGD ("sending router solicitation");
|
||||||
|
|
||||||
if (klass->send_rs (rdisc))
|
if (klass->send_rs (rdisc))
|
||||||
priv->solicitations_left--;
|
priv->solicitations_left--;
|
||||||
|
|
||||||
priv->last_rs = nm_utils_get_monotonic_timestamp_s ();
|
priv->last_rs = nm_utils_get_monotonic_timestamp_s ();
|
||||||
if (priv->solicitations_left > 0) {
|
if (priv->solicitations_left > 0) {
|
||||||
debug ("(%s): scheduling router solicitation retry in %d seconds.",
|
_LOGD ("scheduling router solicitation retry in %d seconds.",
|
||||||
rdisc->ifname, rdisc->rtr_solicitation_interval);
|
rdisc->rtr_solicitation_interval);
|
||||||
priv->send_rs_id = g_timeout_add_seconds (rdisc->rtr_solicitation_interval,
|
priv->send_rs_id = g_timeout_add_seconds (rdisc->rtr_solicitation_interval,
|
||||||
(GSourceFunc) send_rs, rdisc);
|
(GSourceFunc) send_rs, rdisc);
|
||||||
} else {
|
} else {
|
||||||
debug ("(%s): did not receive a router advertisement after %d solicitations.",
|
_LOGD ("did not receive a router advertisement after %d solicitations.",
|
||||||
rdisc->ifname, rdisc->rtr_solicitations);
|
rdisc->rtr_solicitations);
|
||||||
priv->send_rs_id = 0;
|
priv->send_rs_id = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -312,8 +312,8 @@ solicit (NMRDisc *rdisc)
|
|||||||
priv->solicitations_left = rdisc->rtr_solicitations;
|
priv->solicitations_left = rdisc->rtr_solicitations;
|
||||||
|
|
||||||
next = CLAMP (priv->last_rs + rdisc->rtr_solicitation_interval - now, 0, G_MAXINT32);
|
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.",
|
_LOGD ("scheduling explicit router solicitation request in %" G_GINT64_FORMAT " seconds.",
|
||||||
rdisc->ifname, next);
|
next);
|
||||||
priv->send_rs_id = g_timeout_add_seconds ((guint32) next, (GSourceFunc) send_rs, rdisc);
|
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);
|
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);
|
clear_ra_timeout (rdisc);
|
||||||
ra_wait_secs = CLAMP (rdisc->rtr_solicitations * rdisc->rtr_solicitation_interval, 30, 120);
|
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);
|
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)
|
if (klass->start)
|
||||||
klass->start (rdisc);
|
klass->start (rdisc);
|
||||||
@@ -394,27 +394,27 @@ config_changed (NMRDisc *rdisc, NMRDiscConfigMap changed)
|
|||||||
char changedstr[CONFIG_MAP_MAX_STR];
|
char changedstr[CONFIG_MAP_MAX_STR];
|
||||||
char addrstr[INET6_ADDRSTRLEN];
|
char addrstr[INET6_ADDRSTRLEN];
|
||||||
|
|
||||||
if (nm_logging_enabled (LOGL_DEBUG, LOGD_IP6)) {
|
if (_LOGD_ENABLED ()) {
|
||||||
config_map_to_string (changed, changedstr);
|
config_map_to_string (changed, changedstr);
|
||||||
debug ("(%s): router discovery configuration changed [%s]:", rdisc->ifname, changedstr);
|
_LOGD ("router discovery configuration changed [%s]:", changedstr);
|
||||||
debug (" dhcp-level %s", dhcp_level_to_string (rdisc->dhcp_level));
|
_LOGD (" dhcp-level %s", dhcp_level_to_string (rdisc->dhcp_level));
|
||||||
for (i = 0; i < rdisc->gateways->len; i++) {
|
for (i = 0; i < rdisc->gateways->len; i++) {
|
||||||
NMRDiscGateway *gateway = &g_array_index (rdisc->gateways, NMRDiscGateway, i);
|
NMRDiscGateway *gateway = &g_array_index (rdisc->gateways, NMRDiscGateway, i);
|
||||||
|
|
||||||
inet_ntop (AF_INET6, &gateway->address, addrstr, sizeof (addrstr));
|
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++) {
|
for (i = 0; i < rdisc->addresses->len; i++) {
|
||||||
NMRDiscAddress *address = &g_array_index (rdisc->addresses, NMRDiscAddress, i);
|
NMRDiscAddress *address = &g_array_index (rdisc->addresses, NMRDiscAddress, i);
|
||||||
|
|
||||||
inet_ntop (AF_INET6, &address->address, addrstr, sizeof (addrstr));
|
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++) {
|
for (i = 0; i < rdisc->routes->len; i++) {
|
||||||
NMRDiscRoute *route = &g_array_index (rdisc->routes, NMRDiscRoute, i);
|
NMRDiscRoute *route = &g_array_index (rdisc->routes, NMRDiscRoute, i);
|
||||||
|
|
||||||
inet_ntop (AF_INET6, &route->network, addrstr, sizeof (addrstr));
|
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,
|
nm_utils_inet6_ntop (&route->gateway, NULL), route->preference,
|
||||||
expiry (route));
|
expiry (route));
|
||||||
}
|
}
|
||||||
@@ -422,12 +422,12 @@ config_changed (NMRDisc *rdisc, NMRDiscConfigMap changed)
|
|||||||
NMRDiscDNSServer *dns_server = &g_array_index (rdisc->dns_servers, NMRDiscDNSServer, i);
|
NMRDiscDNSServer *dns_server = &g_array_index (rdisc->dns_servers, NMRDiscDNSServer, i);
|
||||||
|
|
||||||
inet_ntop (AF_INET6, &dns_server->address, addrstr, sizeof (addrstr));
|
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++) {
|
for (i = 0; i < rdisc->dns_domains->len; i++) {
|
||||||
NMRDiscDNSDomain *dns_domain = &g_array_index (rdisc->dns_domains, NMRDiscDNSDomain, 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) {
|
if (nextevent != never) {
|
||||||
g_return_if_fail (nextevent > now);
|
g_return_if_fail (nextevent > now);
|
||||||
debug ("(%s): scheduling next now/lifetime check: %u seconds",
|
_LOGD ("scheduling next now/lifetime check: %u seconds",
|
||||||
rdisc->ifname, nextevent - now);
|
nextevent - now);
|
||||||
priv->timeout_id = g_timeout_add_seconds (nextevent - now, timeout_cb, rdisc);
|
priv->timeout_id = g_timeout_add_seconds (nextevent - now, timeout_cb, rdisc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user