mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-24 07:50:06 +01:00
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.
This commit is contained in:
parent
f44c793f6c
commit
99befe7e51
1 changed files with 52 additions and 59 deletions
|
|
@ -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 (!watcher)
|
||||
return NULL;
|
||||
if (vlanid < -1 || vlanid > 4094)
|
||||
val_fail = "vlanid";
|
||||
if (val_fail) {
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
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]"));
|
||||
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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue