summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-12-12 14:07:34 +0100
committerThomas Haller <thaller@redhat.com>2018-12-12 14:07:50 +0100
commit99befe7e518da99ff4e0de6ee9b6f15bb4d5446d (patch)
tree1746c7ac63d905b89a6b60992908e7b3e5bee36e
parentf44c793f6cd89c3e84e83872478daf286821ed64 (diff)
downloadNetworkManager-99befe7e518da99ff4e0de6ee9b6f15bb4d5446d.tar.gz
libnm: implement nm_team_link_watcher_new_arp_ping() based on nm_team_link_watcher_new_arp_ping2()
nm_team_link_watcher_new_arp_ping2() is the more powerful variant of nm_team_link_watcher_new_arp_ping(). It can do everything the new variant can, and more. Hence, v1 should be implemented based on v2. This way, validating and constructing the watcher is all done in one place, not split in two places.
-rw-r--r--libnm-core/nm-setting-team.c101
1 files changed, 47 insertions, 54 deletions
diff --git a/libnm-core/nm-setting-team.c b/libnm-core/nm-setting-team.c
index b12ef0bbcd..0ca47e83fa 100644
--- a/libnm-core/nm-setting-team.c
+++ b/libnm-core/nm-setting-team.c
@@ -234,53 +234,14 @@ nm_team_link_watcher_new_arp_ping (int init_wait,
NMTeamLinkWatcherArpPingFlags flags,
GError **error)
{
- NMTeamLinkWatcher *watcher;
- const char *val_fail = NULL;
-
- if (!target_host || !source_host) {
- g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_FAILED,
- _("Missing %s in arp_ping link watcher"),
- target_host ? "source-host" : "target-host");
- return NULL;
- }
-
- if (strpbrk (target_host, " \\/\t=\"\'")) {
- g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_FAILED,
- _("target-host '%s' contains invalid characters"), target_host);
- return NULL;
- }
-
- if (strpbrk (source_host, " \\/\t=\"\'")) {
- g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_FAILED,
- _("source-host '%s' contains invalid characters"), source_host);
- return NULL;
- }
-
- if (init_wait < 0 || !_NM_INT_LE_MAXINT32 (init_wait))
- val_fail = "init-wait";
- if (interval < 0 || !_NM_INT_LE_MAXINT32 (interval))
- val_fail = "interval";
- if (missed_max < 0 || !_NM_INT_LE_MAXINT32 (missed_max))
- val_fail = "missed-max";
- if (val_fail) {
- g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_FAILED,
- _("%s is out of range [0, %d]"), val_fail, G_MAXINT32);
- return NULL;
- }
-
- watcher = g_slice_new0 (NMTeamLinkWatcher);
- watcher->refcount = 1;
-
- watcher->type = LINK_WATCHER_ARP_PING;
- watcher->arp_ping.init_wait = init_wait;
- watcher->arp_ping.interval = interval;
- watcher->arp_ping.missed_max = missed_max;
- watcher->arp_ping.target_host = g_strdup (target_host);
- watcher->arp_ping.source_host = g_strdup (source_host);
- watcher->arp_ping.flags = flags;
- watcher->arp_ping.vlanid = -1;
-
- return watcher;
+ return nm_team_link_watcher_new_arp_ping2 (init_wait,
+ interval,
+ missed_max,
+ -1,
+ target_host,
+ source_host,
+ flags,
+ error);
}
/**
@@ -315,21 +276,53 @@ nm_team_link_watcher_new_arp_ping2 (int init_wait,
NMTeamLinkWatcher *watcher;
const char *val_fail = NULL;
- watcher = nm_team_link_watcher_new_arp_ping (init_wait, interval, missed_max,
- target_host, source_host, flags,
- error);
+ if (!target_host || !source_host) {
+ g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_FAILED,
+ _("Missing %s in arp_ping link watcher"),
+ target_host ? "source-host" : "target-host");
+ return NULL;
+ }
+
+ if (strpbrk (target_host, " \\/\t=\"\'")) {
+ g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_FAILED,
+ _("target-host '%s' contains invalid characters"), target_host);
+ return NULL;
+ }
- if (!watcher)
+ if (strpbrk (source_host, " \\/\t=\"\'")) {
+ g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_FAILED,
+ _("source-host '%s' contains invalid characters"), source_host);
return NULL;
- if (vlanid < -1 || vlanid > 4094)
- val_fail = "vlanid";
+ }
+
+ else if (init_wait < 0 || !_NM_INT_LE_MAXINT32 (init_wait))
+ val_fail = "init-wait";
+ else if (interval < 0 || !_NM_INT_LE_MAXINT32 (interval))
+ val_fail = "interval";
+ else if (missed_max < 0 || !_NM_INT_LE_MAXINT32 (missed_max))
+ val_fail = "missed-max";
if (val_fail) {
+ g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_FAILED,
+ _("%s is out of range [0, %d]"), val_fail, G_MAXINT32);
+ return NULL;
+ }
+
+ if (vlanid < -1 || vlanid > 4094) {
g_set_error_literal (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_FAILED,
_("vlanid is out of range [-1, 4094]"));
- nm_team_link_watcher_unref (watcher);
return NULL;
}
+ watcher = g_slice_new0 (NMTeamLinkWatcher);
+ watcher->refcount = 1;
+
+ watcher->type = LINK_WATCHER_ARP_PING;
+ watcher->arp_ping.init_wait = init_wait;
+ watcher->arp_ping.interval = interval;
+ watcher->arp_ping.missed_max = missed_max;
+ watcher->arp_ping.target_host = g_strdup (target_host);
+ watcher->arp_ping.source_host = g_strdup (source_host);
+ watcher->arp_ping.flags = flags;
watcher->arp_ping.vlanid = vlanid;
return watcher;