platform: add option to suppress error message from nm_platform_ip_route_add()

When an error happens, we want to print a better message.
Avoid duplicate error messages by adding a flag to suppress
logging in the lower layer.
This commit is contained in:
Thomas Haller
2017-08-21 18:02:08 +02:00
parent b524d879f0
commit 8f65f96a43
4 changed files with 29 additions and 9 deletions

View File

@@ -1223,6 +1223,8 @@ ip_route_add (NMPlatform *platform,
g_assert (NM_IN_SET (addr_family, AF_INET, AF_INET6));
flags = NM_FLAGS_UNSET (flags, NMP_NLM_FLAG_SUPPRESS_NETLINK_FAILURE);
/* currently, only replace is implemented. */
g_assert (flags == NMP_NLM_FLAG_REPLACE);

View File

@@ -2585,7 +2585,7 @@ ip_route_get_lock_flag (const NMPlatformIPRoute *route)
/* Copied and modified from libnl3's build_route_msg() and rtnl_route_build_msg(). */
static struct nl_msg *
_nl_msg_new_route (int nlmsg_type,
NMPNlmFlags nlmsgflags,
guint16 nlmsgflags,
const NMPObject *obj)
{
struct nl_msg *msg;
@@ -2615,7 +2615,6 @@ _nl_msg_new_route (int nlmsg_type,
nm_assert (NM_IN_SET (NMP_OBJECT_GET_TYPE (obj), NMP_OBJECT_TYPE_IP4_ROUTE, NMP_OBJECT_TYPE_IP6_ROUTE));
nm_assert (NM_IN_SET (nlmsg_type, RTM_NEWROUTE, RTM_DELROUTE));
nm_assert (((NMPNlmFlags) ((int) nlmsgflags)) == nlmsgflags);
msg = nlmsg_alloc_simple (nlmsg_type, (int) nlmsgflags);
if (!msg)
g_return_val_if_reached (NULL);
@@ -4214,7 +4213,10 @@ do_add_link_with_lookup (NMPlatform *platform,
}
static NMPlatformError
do_add_addrroute (NMPlatform *platform, const NMPObject *obj_id, struct nl_msg *nlmsg)
do_add_addrroute (NMPlatform *platform,
const NMPObject *obj_id,
struct nl_msg *nlmsg,
gboolean suppress_netlink_failure)
{
WaitForNlResponseResult seq_result = WAIT_FOR_NL_RESPONSE_RESULT_UNKNOWN;
int nle;
@@ -4239,7 +4241,9 @@ do_add_addrroute (NMPlatform *platform, const NMPObject *obj_id, struct nl_msg *
nm_assert (seq_result);
_NMLOG (seq_result == WAIT_FOR_NL_RESPONSE_RESULT_RESPONSE_OK
_NMLOG (( seq_result == WAIT_FOR_NL_RESPONSE_RESULT_RESPONSE_OK
|| ( suppress_netlink_failure
&& seq_result < 0))
? LOGL_DEBUG
: LOGL_WARN,
"do-add-%s[%s]: %s",
@@ -5887,7 +5891,7 @@ ip4_address_add (NMPlatform *platform,
label);
nmp_object_stackinit_id_ip4_address (&obj_id, ifindex, addr, plen, peer_addr);
return do_add_addrroute (platform, &obj_id, nlmsg) == NM_PLATFORM_ERROR_SUCCESS;
return do_add_addrroute (platform, &obj_id, nlmsg, FALSE) == NM_PLATFORM_ERROR_SUCCESS;
}
static gboolean
@@ -5917,7 +5921,7 @@ ip6_address_add (NMPlatform *platform,
NULL);
nmp_object_stackinit_id_ip6_address (&obj_id, ifindex, &addr);
return do_add_addrroute (platform, &obj_id, nlmsg) == NM_PLATFORM_ERROR_SUCCESS;
return do_add_addrroute (platform, &obj_id, nlmsg, FALSE) == NM_PLATFORM_ERROR_SUCCESS;
}
static gboolean
@@ -5994,10 +5998,13 @@ ip_route_add (NMPlatform *platform,
nm_platform_ip_route_normalize (addr_family, NMP_OBJECT_CAST_IP_ROUTE (&obj));
nlmsg = _nl_msg_new_route (RTM_NEWROUTE, flags, &obj);
nlmsg = _nl_msg_new_route (RTM_NEWROUTE, flags & NMP_NLM_FLAG_FMASK, &obj);
if (!nlmsg)
g_return_val_if_reached (NM_PLATFORM_ERROR_BUG);
return do_add_addrroute (platform, &obj, nlmsg);
return do_add_addrroute (platform,
&obj,
nlmsg,
NM_FLAGS_HAS (flags, NMP_NLM_FLAG_SUPPRESS_NETLINK_FAILURE));
}
static gboolean

View File

@@ -288,6 +288,8 @@ NM_UTILS_LOOKUP_STR_DEFINE_STATIC (_nmp_nlm_flag_to_string_lookup, NMPNlmFlags,
NM_UTILS_LOOKUP_ITEM (NMP_NLM_FLAG_APPEND, "append"),
NM_UTILS_LOOKUP_ITEM (NMP_NLM_FLAG_TEST, "test"),
NM_UTILS_LOOKUP_ITEM_IGNORE (NMP_NLM_FLAG_F_APPEND),
NM_UTILS_LOOKUP_ITEM_IGNORE (NMP_NLM_FLAG_FMASK),
NM_UTILS_LOOKUP_ITEM_IGNORE (NMP_NLM_FLAG_SUPPRESS_NETLINK_FAILURE),
);
#define _nmp_nlm_flag_to_string(flags) \
@@ -3755,7 +3757,7 @@ _ip_route_add (NMPlatform *self,
nm_assert (NM_IN_SET (addr_family, AF_INET, AF_INET6));
_LOGD ("route: %-10s IPv%c route: %s",
_nmp_nlm_flag_to_string (flags),
_nmp_nlm_flag_to_string (flags & NMP_NLM_FLAG_FMASK),
addr_family == AF_INET ? '4' : '6',
addr_family == AF_INET
? nm_platform_ip4_route_to_string (route, sbuf, sizeof (sbuf))

View File

@@ -86,6 +86,15 @@ typedef enum {
NMP_NLM_FLAG_F_CREATE = 0x400, /* NLM_F_CREATE, Create, if it does not exist */
NMP_NLM_FLAG_F_APPEND = 0x800, /* NLM_F_APPEND, Add to end of list */
NMP_NLM_FLAG_FMASK = 0xFFFF, /* a mask for all NMP_NLM_FLAG_F_* flags */
/* instructs NM to suppress logging an error message for any failures
* received from kernel.
*
* It will still log with debug-level, and it will still log
* other failures aside the kernel response. */
NMP_NLM_FLAG_SUPPRESS_NETLINK_FAILURE = 0x10000,
/* the following aliases correspond to iproute2's `ip route CMD` for
* RTM_NEWROUTE, with CMD being one of add, change, replace, prepend,
* append and test. */