2010-02-25 09:52:30 -08:00
|
|
|
/* nmcli - command-line tool to control NetworkManager
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
*
|
2015-02-16 13:13:15 +01:00
|
|
|
* Copyright 2010 - 2015 Red Hat, Inc.
|
2010-02-25 09:52:30 -08:00
|
|
|
*/
|
|
|
|
|
|
2016-02-19 14:57:48 +01:00
|
|
|
#include "nm-default.h"
|
2011-03-14 01:00:56 -05:00
|
|
|
|
2017-04-04 13:52:13 +02:00
|
|
|
#include "general.h"
|
|
|
|
|
|
2010-02-25 09:52:30 -08:00
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
2017-03-28 12:16:31 +02:00
|
|
|
#include "nm-common-macros.h"
|
|
|
|
|
|
|
|
|
|
#include "nm-client-utils.h"
|
|
|
|
|
|
2014-10-30 15:45:43 +01:00
|
|
|
#include "polkit-agent.h"
|
2010-02-25 09:52:30 -08:00
|
|
|
#include "utils.h"
|
2016-07-06 13:34:21 +02:00
|
|
|
#include "common.h"
|
2016-07-01 21:47:01 +02:00
|
|
|
#include "common.h"
|
2015-03-27 13:07:43 +01:00
|
|
|
#include "devices.h"
|
|
|
|
|
#include "connections.h"
|
|
|
|
|
|
2017-04-06 14:43:44 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
|
nm_state_to_string (NMState state)
|
|
|
|
|
{
|
|
|
|
|
switch (state) {
|
|
|
|
|
case NM_STATE_ASLEEP:
|
|
|
|
|
return _("asleep");
|
|
|
|
|
case NM_STATE_CONNECTING:
|
|
|
|
|
return _("connecting");
|
|
|
|
|
case NM_STATE_CONNECTED_LOCAL:
|
|
|
|
|
return _("connected (local only)");
|
|
|
|
|
case NM_STATE_CONNECTED_SITE:
|
|
|
|
|
return _("connected (site only)");
|
|
|
|
|
case NM_STATE_CONNECTED_GLOBAL:
|
|
|
|
|
return _("connected");
|
|
|
|
|
case NM_STATE_DISCONNECTING:
|
|
|
|
|
return _("disconnecting");
|
|
|
|
|
case NM_STATE_DISCONNECTED:
|
|
|
|
|
return _("disconnected");
|
|
|
|
|
case NM_STATE_UNKNOWN:
|
|
|
|
|
default:
|
|
|
|
|
return _("unknown");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static NMMetaTermColor
|
|
|
|
|
state_to_color (NMState state)
|
|
|
|
|
{
|
|
|
|
|
switch (state) {
|
|
|
|
|
case NM_STATE_CONNECTING:
|
|
|
|
|
return NM_META_TERM_COLOR_YELLOW;
|
|
|
|
|
case NM_STATE_CONNECTED_LOCAL:
|
|
|
|
|
case NM_STATE_CONNECTED_SITE:
|
|
|
|
|
case NM_STATE_CONNECTED_GLOBAL:
|
|
|
|
|
return NM_META_TERM_COLOR_GREEN;
|
|
|
|
|
case NM_STATE_DISCONNECTING:
|
|
|
|
|
return NM_META_TERM_COLOR_YELLOW;
|
|
|
|
|
case NM_STATE_ASLEEP:
|
|
|
|
|
case NM_STATE_DISCONNECTED:
|
|
|
|
|
return NM_META_TERM_COLOR_RED;
|
|
|
|
|
default:
|
|
|
|
|
return NM_META_TERM_COLOR_NORMAL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
|
nm_connectivity_to_string (NMConnectivityState connectivity)
|
|
|
|
|
{
|
|
|
|
|
switch (connectivity) {
|
|
|
|
|
case NM_CONNECTIVITY_NONE:
|
|
|
|
|
return _("none");
|
|
|
|
|
case NM_CONNECTIVITY_PORTAL:
|
|
|
|
|
return _("portal");
|
|
|
|
|
case NM_CONNECTIVITY_LIMITED:
|
|
|
|
|
return _("limited");
|
|
|
|
|
case NM_CONNECTIVITY_FULL:
|
|
|
|
|
return _("full");
|
|
|
|
|
case NM_CONNECTIVITY_UNKNOWN:
|
|
|
|
|
default:
|
|
|
|
|
return _("unknown");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static NMMetaTermColor
|
|
|
|
|
connectivity_to_color (NMConnectivityState connectivity)
|
|
|
|
|
{
|
|
|
|
|
switch (connectivity) {
|
|
|
|
|
case NM_CONNECTIVITY_NONE:
|
|
|
|
|
return NM_META_TERM_COLOR_RED;
|
|
|
|
|
case NM_CONNECTIVITY_PORTAL:
|
|
|
|
|
case NM_CONNECTIVITY_LIMITED:
|
|
|
|
|
return NM_META_TERM_COLOR_YELLOW;
|
|
|
|
|
case NM_CONNECTIVITY_FULL:
|
|
|
|
|
return NM_META_TERM_COLOR_GREEN;
|
|
|
|
|
default:
|
|
|
|
|
return NM_META_TERM_COLOR_NORMAL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
cli: split tracking of meta data out of NmcOutputField
When generating output data, nmcli iterates over a list of
property-descriptors (nmc_fields_ip4_config), creates an intermediate
array (output_data) and finally prints it.
However, previously both the meta data (nmc_fields_ip4_config) and
the intermediate format use the same type NmcOutputField. This means,
certain fields are relevant to describe a property, and other fields
are output/formatting fields.
Split this up. Now, the meta data is tracked in form of an NMMetaAbstractInfo
lists. This separates the information about properties from intermediate steps
during creation of the output.
Note that currently functions like print_ip4_config() still have all the
knowledge about how to generate the output. That is wrong, instead, the
meta data (NMMetaAbstractInfo) should describe how to create the output
and then all those functions could be replaced. This means, later we want
to add more knowledge to the NMMetaAbstractInfo, so it is important to
keep them separate from NmcOutputField.
2017-03-31 19:18:16 +02:00
|
|
|
static const NmcMetaGenericInfo *const nmc_fields_nm_status[] = {
|
|
|
|
|
NMC_META_GENERIC ("RUNNING"), /* 0 */
|
|
|
|
|
NMC_META_GENERIC ("VERSION"), /* 1 */
|
|
|
|
|
NMC_META_GENERIC ("STATE"), /* 2 */
|
|
|
|
|
NMC_META_GENERIC ("STARTUP"), /* 3 */
|
|
|
|
|
NMC_META_GENERIC ("CONNECTIVITY"), /* 4 */
|
|
|
|
|
NMC_META_GENERIC ("NETWORKING"), /* 5 */
|
|
|
|
|
NMC_META_GENERIC ("WIFI-HW"), /* 6 */
|
|
|
|
|
NMC_META_GENERIC ("WIFI"), /* 7 */
|
|
|
|
|
NMC_META_GENERIC ("WWAN-HW"), /* 8 */
|
|
|
|
|
NMC_META_GENERIC ("WWAN"), /* 9 */
|
|
|
|
|
NMC_META_GENERIC ("WIMAX-HW"), /* 10 */
|
|
|
|
|
NMC_META_GENERIC ("WIMAX"), /* 11 */
|
|
|
|
|
NULL,
|
2010-03-19 14:53:08 +01:00
|
|
|
};
|
2013-09-12 16:23:15 +02:00
|
|
|
#define NMC_FIELDS_NM_STATUS_ALL "RUNNING,VERSION,STATE,STARTUP,CONNECTIVITY,NETWORKING,WIFI-HW,WIFI,WWAN-HW,WWAN"
|
2012-12-12 13:03:12 +01:00
|
|
|
#define NMC_FIELDS_NM_STATUS_SWITCH "NETWORKING,WIFI-HW,WIFI,WWAN-HW,WWAN"
|
2013-02-28 14:53:11 +01:00
|
|
|
#define NMC_FIELDS_NM_STATUS_RADIO "WIFI-HW,WIFI,WWAN-HW,WWAN"
|
2013-08-28 10:06:54 -04:00
|
|
|
#define NMC_FIELDS_NM_STATUS_COMMON "STATE,CONNECTIVITY,WIFI-HW,WIFI,WWAN-HW,WWAN"
|
2012-12-10 19:11:04 +01:00
|
|
|
#define NMC_FIELDS_NM_NETWORKING "NETWORKING"
|
2010-03-19 14:53:08 +01:00
|
|
|
#define NMC_FIELDS_NM_WIFI "WIFI"
|
|
|
|
|
#define NMC_FIELDS_NM_WWAN "WWAN"
|
2011-01-06 17:01:55 -06:00
|
|
|
#define NMC_FIELDS_NM_WIMAX "WIMAX"
|
2013-08-28 10:06:54 -04:00
|
|
|
#define NMC_FIELDS_NM_CONNECTIVITY "CONNECTIVITY"
|
2010-03-19 14:53:08 +01:00
|
|
|
|
2012-12-10 19:11:04 +01:00
|
|
|
|
|
|
|
|
/* Available fields for 'general permissions' */
|
cli: split tracking of meta data out of NmcOutputField
When generating output data, nmcli iterates over a list of
property-descriptors (nmc_fields_ip4_config), creates an intermediate
array (output_data) and finally prints it.
However, previously both the meta data (nmc_fields_ip4_config) and
the intermediate format use the same type NmcOutputField. This means,
certain fields are relevant to describe a property, and other fields
are output/formatting fields.
Split this up. Now, the meta data is tracked in form of an NMMetaAbstractInfo
lists. This separates the information about properties from intermediate steps
during creation of the output.
Note that currently functions like print_ip4_config() still have all the
knowledge about how to generate the output. That is wrong, instead, the
meta data (NMMetaAbstractInfo) should describe how to create the output
and then all those functions could be replaced. This means, later we want
to add more knowledge to the NMMetaAbstractInfo, so it is important to
keep them separate from NmcOutputField.
2017-03-31 19:18:16 +02:00
|
|
|
static const NmcMetaGenericInfo *const nmc_fields_nm_permissions[] = {
|
|
|
|
|
NMC_META_GENERIC ("PERMISSION"), /* 0 */
|
|
|
|
|
NMC_META_GENERIC ("VALUE"), /* 1 */
|
|
|
|
|
NULL,
|
2012-04-30 11:50:26 +02:00
|
|
|
};
|
|
|
|
|
#define NMC_FIELDS_NM_PERMISSIONS_ALL "PERMISSION,VALUE"
|
|
|
|
|
#define NMC_FIELDS_NM_PERMISSIONS_COMMON "PERMISSION,VALUE"
|
|
|
|
|
|
2012-12-12 14:23:54 +01:00
|
|
|
/* Available fields for 'general logging' */
|
cli: split tracking of meta data out of NmcOutputField
When generating output data, nmcli iterates over a list of
property-descriptors (nmc_fields_ip4_config), creates an intermediate
array (output_data) and finally prints it.
However, previously both the meta data (nmc_fields_ip4_config) and
the intermediate format use the same type NmcOutputField. This means,
certain fields are relevant to describe a property, and other fields
are output/formatting fields.
Split this up. Now, the meta data is tracked in form of an NMMetaAbstractInfo
lists. This separates the information about properties from intermediate steps
during creation of the output.
Note that currently functions like print_ip4_config() still have all the
knowledge about how to generate the output. That is wrong, instead, the
meta data (NMMetaAbstractInfo) should describe how to create the output
and then all those functions could be replaced. This means, later we want
to add more knowledge to the NMMetaAbstractInfo, so it is important to
keep them separate from NmcOutputField.
2017-03-31 19:18:16 +02:00
|
|
|
static const NmcMetaGenericInfo *const nmc_fields_nm_logging[] = {
|
|
|
|
|
NMC_META_GENERIC ("LEVEL"), /* 0 */
|
|
|
|
|
NMC_META_GENERIC ("DOMAINS"), /* 1 */
|
|
|
|
|
NULL,
|
2012-12-12 14:23:54 +01:00
|
|
|
};
|
|
|
|
|
#define NMC_FIELDS_NM_LOGGING_ALL "LEVEL,DOMAINS"
|
|
|
|
|
#define NMC_FIELDS_NM_LOGGING_COMMON "LEVEL,DOMAINS"
|
|
|
|
|
|
2012-04-30 11:50:26 +02:00
|
|
|
|
2011-09-06 15:30:15 +02:00
|
|
|
/* glib main loop variable - defined in nmcli.c */
|
2010-02-25 09:52:30 -08:00
|
|
|
extern GMainLoop *loop;
|
|
|
|
|
|
2012-12-10 19:11:04 +01:00
|
|
|
|
2010-02-25 09:52:30 -08:00
|
|
|
static void
|
2012-12-10 19:11:04 +01:00
|
|
|
usage_general (void)
|
2010-02-25 09:52:30 -08:00
|
|
|
{
|
2014-09-19 16:04:40 -04:00
|
|
|
g_printerr (_("Usage: nmcli general { COMMAND | help }\n\n"
|
|
|
|
|
"COMMAND := { status | hostname | permissions | logging }\n\n"
|
|
|
|
|
" status\n\n"
|
|
|
|
|
" hostname [<hostname>]\n\n"
|
|
|
|
|
" permissions\n\n"
|
|
|
|
|
" logging [level <log level>] [domains <log domains>]\n\n"));
|
2013-12-18 14:49:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
usage_general_status (void)
|
|
|
|
|
{
|
2014-09-19 16:04:40 -04:00
|
|
|
g_printerr (_("Usage: nmcli general status { help }\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"Show overall status of NetworkManager.\n"
|
|
|
|
|
"'status' is the default action, which means 'nmcli gen' calls 'nmcli gen status'\n\n"));
|
2013-12-18 14:49:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
usage_general_hostname (void)
|
|
|
|
|
{
|
2014-09-19 16:04:40 -04:00
|
|
|
g_printerr (_("Usage: nmcli general hostname { ARGUMENTS | help }\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"ARGUMENTS := [<hostname>]\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"Get or change persistent system hostname.\n"
|
|
|
|
|
"With no arguments, this prints currently configured hostname. When you pass\n"
|
|
|
|
|
"a hostname, NetworkManager will set it as the new persistent system hostname.\n\n"));
|
2013-12-18 14:49:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
usage_general_permissions (void)
|
|
|
|
|
{
|
2014-09-19 16:04:40 -04:00
|
|
|
g_printerr (_("Usage: nmcli general permissions { help }\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"Show caller permissions for authenticated operations.\n\n"));
|
2013-12-18 14:49:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
usage_general_logging (void)
|
|
|
|
|
{
|
2014-09-19 16:04:40 -04:00
|
|
|
g_printerr (_("Usage: nmcli general logging { ARGUMENTS | help }\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"ARGUMENTS := [level <log level>] [domains <log domains>]\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"Get or change NetworkManager logging level and domains.\n"
|
|
|
|
|
"Without any argument current logging level and domains are shown. In order to\n"
|
|
|
|
|
"change logging state, provide level and/or domain. Please refer to the man page\n"
|
|
|
|
|
"for the list of possible logging domains.\n\n"));
|
2012-12-10 19:11:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-02-28 14:53:11 +01:00
|
|
|
usage_networking (void)
|
2012-12-10 19:11:04 +01:00
|
|
|
{
|
2014-09-19 16:04:40 -04:00
|
|
|
g_printerr (_("Usage: nmcli networking { COMMAND | help }\n\n"
|
|
|
|
|
"COMMAND := { [ on | off | connectivity ] }\n\n"
|
|
|
|
|
" on\n\n"
|
|
|
|
|
" off\n\n"
|
|
|
|
|
" connectivity [check]\n\n"));
|
2013-12-18 14:49:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
usage_networking_on (void)
|
|
|
|
|
{
|
2014-09-19 16:04:40 -04:00
|
|
|
g_printerr (_("Usage: nmcli networking on { help }\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"Switch networking on.\n\n"));
|
2013-12-18 14:49:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
usage_networking_off (void)
|
|
|
|
|
{
|
2014-09-19 16:04:40 -04:00
|
|
|
g_printerr (_("Usage: nmcli networking off { help }\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"Switch networking off.\n\n"));
|
2013-12-18 14:49:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
usage_networking_connectivity (void)
|
|
|
|
|
{
|
2014-09-19 16:04:40 -04:00
|
|
|
g_printerr (_("Usage: nmcli networking connectivity { ARGUMENTS | help }\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"ARGUMENTS := [check]\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"Get network connectivity state.\n"
|
|
|
|
|
"The optional 'check' argument makes NetworkManager re-check the connectivity.\n\n"));
|
2013-12-18 14:49:06 +01:00
|
|
|
|
2013-02-28 14:53:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
usage_radio (void)
|
|
|
|
|
{
|
2014-09-19 16:04:40 -04:00
|
|
|
g_printerr (_("Usage: nmcli radio { COMMAND | help }\n\n"
|
|
|
|
|
"COMMAND := { all | wifi | wwan }\n\n"
|
|
|
|
|
" all | wifi | wwan [ on | off ]\n\n"
|
|
|
|
|
));
|
2010-02-25 09:52:30 -08:00
|
|
|
}
|
|
|
|
|
|
2013-12-18 14:49:06 +01:00
|
|
|
static void
|
|
|
|
|
usage_radio_all (void)
|
|
|
|
|
{
|
2014-09-19 16:04:40 -04:00
|
|
|
g_printerr (_("Usage: nmcli radio all { ARGUMENTS | help }\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"ARGUMENTS := [on | off]\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"Get status of all radio switches, or turn them on/off.\n\n"));
|
2013-12-18 14:49:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
usage_radio_wifi (void)
|
|
|
|
|
{
|
2014-09-19 16:04:40 -04:00
|
|
|
g_printerr (_("Usage: nmcli radio wifi { ARGUMENTS | help }\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"ARGUMENTS := [on | off]\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"Get status of Wi-Fi radio switch, or turn it on/off.\n\n"));
|
2013-12-18 14:49:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
usage_radio_wwan (void)
|
|
|
|
|
{
|
2014-09-19 16:04:40 -04:00
|
|
|
g_printerr (_("Usage: nmcli radio wwan { ARGUMENTS | help }\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"ARGUMENTS := [on | off]\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"Get status of mobile broadband radio switch, or turn it on/off.\n\n"));
|
2013-12-18 14:49:06 +01:00
|
|
|
}
|
|
|
|
|
|
2015-03-27 13:07:43 +01:00
|
|
|
static void
|
|
|
|
|
usage_monitor (void)
|
|
|
|
|
{
|
|
|
|
|
g_printerr (_("Usage: nmcli monitor\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"Monitor NetworkManager changes.\n"
|
|
|
|
|
"Prints a line whenever a change occurs in NetworkManager\n\n"));
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-25 09:52:30 -08:00
|
|
|
/* quit main loop */
|
|
|
|
|
static void
|
|
|
|
|
quit (void)
|
|
|
|
|
{
|
|
|
|
|
g_main_loop_quit (loop); /* quit main loop */
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-10 19:11:04 +01:00
|
|
|
static gboolean
|
2013-04-18 15:07:21 +02:00
|
|
|
show_nm_status (NmCli *nmc, const char *pretty_header_name, const char *print_flds)
|
2010-02-25 09:52:30 -08:00
|
|
|
{
|
2014-07-30 08:49:59 -04:00
|
|
|
gboolean startup = FALSE;
|
2011-02-10 01:31:30 +01:00
|
|
|
NMState state = NM_STATE_UNKNOWN;
|
2013-08-28 10:06:54 -04:00
|
|
|
NMConnectivityState connectivity = NM_CONNECTIVITY_UNKNOWN;
|
2015-02-16 13:13:15 +01:00
|
|
|
gboolean net_enabled;
|
|
|
|
|
gboolean wireless_hw_enabled, wireless_enabled;
|
|
|
|
|
gboolean wwan_hw_enabled, wwan_enabled;
|
2010-03-19 14:53:08 +01:00
|
|
|
GError *error = NULL;
|
|
|
|
|
const char *fields_str;
|
2013-04-18 15:07:21 +02:00
|
|
|
const char *fields_all = print_flds ? print_flds : NMC_FIELDS_NM_STATUS_ALL;
|
|
|
|
|
const char *fields_common = print_flds ? print_flds : NMC_FIELDS_NM_STATUS_COMMON;
|
cli: split tracking of meta data out of NmcOutputField
When generating output data, nmcli iterates over a list of
property-descriptors (nmc_fields_ip4_config), creates an intermediate
array (output_data) and finally prints it.
However, previously both the meta data (nmc_fields_ip4_config) and
the intermediate format use the same type NmcOutputField. This means,
certain fields are relevant to describe a property, and other fields
are output/formatting fields.
Split this up. Now, the meta data is tracked in form of an NMMetaAbstractInfo
lists. This separates the information about properties from intermediate steps
during creation of the output.
Note that currently functions like print_ip4_config() still have all the
knowledge about how to generate the output. That is wrong, instead, the
meta data (NMMetaAbstractInfo) should describe how to create the output
and then all those functions could be replaced. This means, later we want
to add more knowledge to the NMMetaAbstractInfo, so it is important to
keep them separate from NmcOutputField.
2017-03-31 19:18:16 +02:00
|
|
|
const NMMetaAbstractInfo *const*tmpl;
|
|
|
|
|
NmcOutputField *arr;
|
2017-03-30 14:56:19 +02:00
|
|
|
NMC_OUTPUT_DATA_DEFINE_SCOPED (out);
|
2010-02-25 09:52:30 -08:00
|
|
|
|
2010-03-19 14:53:08 +01:00
|
|
|
if (!nmc->required_fields || strcasecmp (nmc->required_fields, "common") == 0)
|
|
|
|
|
fields_str = fields_common;
|
|
|
|
|
else if (!nmc->required_fields || strcasecmp (nmc->required_fields, "all") == 0)
|
|
|
|
|
fields_str = fields_all;
|
2012-04-28 22:54:02 +02:00
|
|
|
else
|
2010-03-19 14:53:08 +01:00
|
|
|
fields_str = nmc->required_fields;
|
|
|
|
|
|
cli: split tracking of meta data out of NmcOutputField
When generating output data, nmcli iterates over a list of
property-descriptors (nmc_fields_ip4_config), creates an intermediate
array (output_data) and finally prints it.
However, previously both the meta data (nmc_fields_ip4_config) and
the intermediate format use the same type NmcOutputField. This means,
certain fields are relevant to describe a property, and other fields
are output/formatting fields.
Split this up. Now, the meta data is tracked in form of an NMMetaAbstractInfo
lists. This separates the information about properties from intermediate steps
during creation of the output.
Note that currently functions like print_ip4_config() still have all the
knowledge about how to generate the output. That is wrong, instead, the
meta data (NMMetaAbstractInfo) should describe how to create the output
and then all those functions could be replaced. This means, later we want
to add more knowledge to the NMMetaAbstractInfo, so it is important to
keep them separate from NmcOutputField.
2017-03-31 19:18:16 +02:00
|
|
|
tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_nm_status;
|
2017-03-31 13:21:47 +02:00
|
|
|
out_indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error);
|
2010-03-19 14:53:08 +01:00
|
|
|
|
|
|
|
|
if (error) {
|
2013-12-10 12:00:53 +01:00
|
|
|
g_string_printf (nmc->return_text, _("Error: only these fields are allowed: %s"), fields_all);
|
2010-03-19 14:53:08 +01:00
|
|
|
g_error_free (error);
|
2010-03-24 13:42:47 +01:00
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
2012-12-10 19:11:04 +01:00
|
|
|
return FALSE;
|
2010-03-19 14:53:08 +01:00
|
|
|
}
|
|
|
|
|
|
2014-07-30 08:49:59 -04:00
|
|
|
state = nm_client_get_state (nmc->client);
|
|
|
|
|
startup = nm_client_get_startup (nmc->client);
|
|
|
|
|
connectivity = nm_client_get_connectivity (nmc->client);
|
2015-02-16 13:13:15 +01:00
|
|
|
net_enabled = nm_client_networking_get_enabled (nmc->client);
|
|
|
|
|
wireless_hw_enabled = nm_client_wireless_hardware_get_enabled (nmc->client);
|
|
|
|
|
wireless_enabled = nm_client_wireless_get_enabled (nmc->client);
|
|
|
|
|
wwan_hw_enabled = nm_client_wwan_hardware_get_enabled (nmc->client);
|
|
|
|
|
wwan_enabled = nm_client_wwan_get_enabled (nmc->client);
|
2010-02-25 09:52:30 -08:00
|
|
|
|
cli: split tracking of meta data out of NmcOutputField
When generating output data, nmcli iterates over a list of
property-descriptors (nmc_fields_ip4_config), creates an intermediate
array (output_data) and finally prints it.
However, previously both the meta data (nmc_fields_ip4_config) and
the intermediate format use the same type NmcOutputField. This means,
certain fields are relevant to describe a property, and other fields
are output/formatting fields.
Split this up. Now, the meta data is tracked in form of an NMMetaAbstractInfo
lists. This separates the information about properties from intermediate steps
during creation of the output.
Note that currently functions like print_ip4_config() still have all the
knowledge about how to generate the output. That is wrong, instead, the
meta data (NMMetaAbstractInfo) should describe how to create the output
and then all those functions could be replaced. This means, later we want
to add more knowledge to the NMMetaAbstractInfo, so it is important to
keep them separate from NmcOutputField.
2017-03-31 19:18:16 +02:00
|
|
|
arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES);
|
2017-03-30 14:56:19 +02:00
|
|
|
g_ptr_array_add (out.output_data, arr);
|
2013-05-22 08:37:50 +02:00
|
|
|
|
cli: split tracking of meta data out of NmcOutputField
When generating output data, nmcli iterates over a list of
property-descriptors (nmc_fields_ip4_config), creates an intermediate
array (output_data) and finally prints it.
However, previously both the meta data (nmc_fields_ip4_config) and
the intermediate format use the same type NmcOutputField. This means,
certain fields are relevant to describe a property, and other fields
are output/formatting fields.
Split this up. Now, the meta data is tracked in form of an NMMetaAbstractInfo
lists. This separates the information about properties from intermediate steps
during creation of the output.
Note that currently functions like print_ip4_config() still have all the
knowledge about how to generate the output. That is wrong, instead, the
meta data (NMMetaAbstractInfo) should describe how to create the output
and then all those functions could be replaced. This means, later we want
to add more knowledge to the NMMetaAbstractInfo, so it is important to
keep them separate from NmcOutputField.
2017-03-31 19:18:16 +02:00
|
|
|
arr = nmc_dup_fields_array (tmpl, 0);
|
2014-07-30 08:49:59 -04:00
|
|
|
set_val_strc (arr, 0, _("running"));
|
|
|
|
|
set_val_strc (arr, 1, nm_client_get_version (nmc->client));
|
2013-05-22 08:37:50 +02:00
|
|
|
set_val_strc (arr, 2, nm_state_to_string (state));
|
2014-07-30 08:49:59 -04:00
|
|
|
set_val_strc (arr, 3, startup ? _("starting") : _("started"));
|
2013-09-12 16:23:15 +02:00
|
|
|
set_val_strc (arr, 4, nm_connectivity_to_string (connectivity));
|
2015-02-16 13:13:15 +01:00
|
|
|
set_val_strc (arr, 5, net_enabled ? _("enabled") : _("disabled"));
|
|
|
|
|
set_val_strc (arr, 6, wireless_hw_enabled ? _("enabled") : _("disabled"));
|
|
|
|
|
set_val_strc (arr, 7, wireless_enabled ? _("enabled") : _("disabled"));
|
|
|
|
|
set_val_strc (arr, 8, wwan_hw_enabled ? _("enabled") : _("disabled"));
|
|
|
|
|
set_val_strc (arr, 9, wwan_enabled ? _("enabled") : _("disabled"));
|
|
|
|
|
|
|
|
|
|
/* Set colors */
|
|
|
|
|
arr[2].color = state_to_color (state);
|
2017-04-04 15:12:00 +02:00
|
|
|
arr[3].color = startup ? NM_META_TERM_COLOR_YELLOW : NM_META_TERM_COLOR_GREEN;
|
2015-02-16 13:13:15 +01:00
|
|
|
arr[4].color = connectivity_to_color (connectivity);
|
2017-04-04 15:12:00 +02:00
|
|
|
arr[5].color = net_enabled ? NM_META_TERM_COLOR_GREEN : NM_META_TERM_COLOR_RED;
|
|
|
|
|
arr[6].color = wireless_hw_enabled ? NM_META_TERM_COLOR_GREEN : NM_META_TERM_COLOR_RED;
|
|
|
|
|
arr[7].color = wireless_enabled ? NM_META_TERM_COLOR_GREEN : NM_META_TERM_COLOR_RED;
|
|
|
|
|
arr[8].color = wwan_hw_enabled ? NM_META_TERM_COLOR_GREEN : NM_META_TERM_COLOR_RED;
|
|
|
|
|
arr[9].color = wwan_enabled ? NM_META_TERM_COLOR_GREEN : NM_META_TERM_COLOR_RED;
|
2015-02-16 13:13:15 +01:00
|
|
|
|
2017-03-30 14:56:19 +02:00
|
|
|
g_ptr_array_add (out.output_data, arr);
|
2010-02-25 09:52:30 -08:00
|
|
|
|
2017-03-30 14:56:19 +02:00
|
|
|
print_data_prepare_width (out.output_data);
|
2017-03-31 13:21:47 +02:00
|
|
|
print_data (&nmc->nmc_config, out_indices,
|
|
|
|
|
pretty_header_name ?: _("NetworkManager status"),
|
|
|
|
|
0, &out);
|
2010-02-25 09:52:30 -08:00
|
|
|
|
2012-12-10 19:11:04 +01:00
|
|
|
return TRUE;
|
2010-02-25 09:52:30 -08:00
|
|
|
}
|
|
|
|
|
|
2016-07-06 13:34:21 +02:00
|
|
|
static NMCResultCode
|
|
|
|
|
do_general_status (NmCli *nmc, int argc, char **argv)
|
|
|
|
|
{
|
2017-03-30 16:09:46 +02:00
|
|
|
next_arg (nmc, &argc, &argv, NULL);
|
2016-07-06 14:43:13 +02:00
|
|
|
if (nmc->complete)
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
|
2016-07-06 13:34:21 +02:00
|
|
|
show_nm_status (nmc, NULL, NULL);
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-30 11:50:26 +02:00
|
|
|
static const char *
|
|
|
|
|
permission_to_string (NMClientPermission perm)
|
|
|
|
|
{
|
|
|
|
|
switch (perm) {
|
|
|
|
|
case NM_CLIENT_PERMISSION_ENABLE_DISABLE_NETWORK:
|
|
|
|
|
return NM_AUTH_PERMISSION_ENABLE_DISABLE_NETWORK;
|
|
|
|
|
case NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIFI:
|
|
|
|
|
return NM_AUTH_PERMISSION_ENABLE_DISABLE_WIFI;
|
|
|
|
|
case NM_CLIENT_PERMISSION_ENABLE_DISABLE_WWAN:
|
|
|
|
|
return NM_AUTH_PERMISSION_ENABLE_DISABLE_WWAN;
|
|
|
|
|
case NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIMAX:
|
|
|
|
|
return NM_AUTH_PERMISSION_ENABLE_DISABLE_WIMAX;
|
|
|
|
|
case NM_CLIENT_PERMISSION_SLEEP_WAKE:
|
|
|
|
|
return NM_AUTH_PERMISSION_SLEEP_WAKE;
|
|
|
|
|
case NM_CLIENT_PERMISSION_NETWORK_CONTROL:
|
|
|
|
|
return NM_AUTH_PERMISSION_NETWORK_CONTROL;
|
|
|
|
|
case NM_CLIENT_PERMISSION_WIFI_SHARE_PROTECTED:
|
|
|
|
|
return NM_AUTH_PERMISSION_WIFI_SHARE_PROTECTED;
|
|
|
|
|
case NM_CLIENT_PERMISSION_WIFI_SHARE_OPEN:
|
|
|
|
|
return NM_AUTH_PERMISSION_WIFI_SHARE_OPEN;
|
|
|
|
|
case NM_CLIENT_PERMISSION_SETTINGS_MODIFY_SYSTEM:
|
|
|
|
|
return NM_AUTH_PERMISSION_SETTINGS_MODIFY_SYSTEM;
|
|
|
|
|
case NM_CLIENT_PERMISSION_SETTINGS_MODIFY_OWN:
|
|
|
|
|
return NM_AUTH_PERMISSION_SETTINGS_MODIFY_OWN;
|
|
|
|
|
case NM_CLIENT_PERMISSION_SETTINGS_MODIFY_HOSTNAME:
|
|
|
|
|
return NM_AUTH_PERMISSION_SETTINGS_MODIFY_HOSTNAME;
|
2016-06-01 12:54:05 +02:00
|
|
|
case NM_CLIENT_PERMISSION_SETTINGS_MODIFY_GLOBAL_DNS:
|
|
|
|
|
return NM_AUTH_PERMISSION_SETTINGS_MODIFY_GLOBAL_DNS;
|
2016-05-30 15:42:44 +02:00
|
|
|
case NM_CLIENT_PERMISSION_RELOAD:
|
|
|
|
|
return NM_AUTH_PERMISSION_RELOAD;
|
2016-08-17 15:34:55 +02:00
|
|
|
case NM_CLIENT_PERMISSION_CHECKPOINT_ROLLBACK:
|
|
|
|
|
return NM_AUTH_PERMISSION_CHECKPOINT_ROLLBACK;
|
2016-08-10 11:54:32 +02:00
|
|
|
case NM_CLIENT_PERMISSION_ENABLE_DISABLE_STATISTICS:
|
|
|
|
|
return NM_AUTH_PERMISSION_ENABLE_DISABLE_STATISTICS;
|
2012-04-30 11:50:26 +02:00
|
|
|
default:
|
|
|
|
|
return _("unknown");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
|
permission_result_to_string (NMClientPermissionResult perm_result)
|
|
|
|
|
{
|
|
|
|
|
switch (perm_result) {
|
|
|
|
|
case NM_CLIENT_PERMISSION_RESULT_YES:
|
|
|
|
|
return _("yes");
|
|
|
|
|
case NM_CLIENT_PERMISSION_RESULT_NO:
|
|
|
|
|
return _("no");
|
|
|
|
|
case NM_CLIENT_PERMISSION_RESULT_AUTH:
|
|
|
|
|
return _("auth");
|
|
|
|
|
default:
|
|
|
|
|
return _("unknown");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-10 19:11:04 +01:00
|
|
|
static gboolean
|
2016-10-19 10:08:46 +02:00
|
|
|
timeout_cb (gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
NmCli *nmc = (NmCli *) user_data;
|
|
|
|
|
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: Timeout %d sec expired."), nmc->timeout);
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_TIMEOUT_EXPIRED;
|
|
|
|
|
quit ();
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
print_permissions (void *user_data)
|
2012-04-30 11:50:26 +02:00
|
|
|
{
|
2016-10-19 10:08:46 +02:00
|
|
|
NmCli *nmc = user_data;
|
2012-04-30 11:50:26 +02:00
|
|
|
NMClientPermission perm;
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
const char *fields_str;
|
|
|
|
|
const char *fields_all = NMC_FIELDS_NM_PERMISSIONS_ALL;
|
|
|
|
|
const char *fields_common = NMC_FIELDS_NM_PERMISSIONS_COMMON;
|
cli: split tracking of meta data out of NmcOutputField
When generating output data, nmcli iterates over a list of
property-descriptors (nmc_fields_ip4_config), creates an intermediate
array (output_data) and finally prints it.
However, previously both the meta data (nmc_fields_ip4_config) and
the intermediate format use the same type NmcOutputField. This means,
certain fields are relevant to describe a property, and other fields
are output/formatting fields.
Split this up. Now, the meta data is tracked in form of an NMMetaAbstractInfo
lists. This separates the information about properties from intermediate steps
during creation of the output.
Note that currently functions like print_ip4_config() still have all the
knowledge about how to generate the output. That is wrong, instead, the
meta data (NMMetaAbstractInfo) should describe how to create the output
and then all those functions could be replaced. This means, later we want
to add more knowledge to the NMMetaAbstractInfo, so it is important to
keep them separate from NmcOutputField.
2017-03-31 19:18:16 +02:00
|
|
|
const NMMetaAbstractInfo *const*tmpl;
|
|
|
|
|
NmcOutputField *arr;
|
2017-03-30 14:56:19 +02:00
|
|
|
NMC_OUTPUT_DATA_DEFINE_SCOPED (out);
|
2012-04-30 11:50:26 +02:00
|
|
|
|
|
|
|
|
if (!nmc->required_fields || strcasecmp (nmc->required_fields, "common") == 0)
|
|
|
|
|
fields_str = fields_common;
|
|
|
|
|
else if (!nmc->required_fields || strcasecmp (nmc->required_fields, "all") == 0)
|
|
|
|
|
fields_str = fields_all;
|
|
|
|
|
else
|
|
|
|
|
fields_str = nmc->required_fields;
|
|
|
|
|
|
cli: split tracking of meta data out of NmcOutputField
When generating output data, nmcli iterates over a list of
property-descriptors (nmc_fields_ip4_config), creates an intermediate
array (output_data) and finally prints it.
However, previously both the meta data (nmc_fields_ip4_config) and
the intermediate format use the same type NmcOutputField. This means,
certain fields are relevant to describe a property, and other fields
are output/formatting fields.
Split this up. Now, the meta data is tracked in form of an NMMetaAbstractInfo
lists. This separates the information about properties from intermediate steps
during creation of the output.
Note that currently functions like print_ip4_config() still have all the
knowledge about how to generate the output. That is wrong, instead, the
meta data (NMMetaAbstractInfo) should describe how to create the output
and then all those functions could be replaced. This means, later we want
to add more knowledge to the NMMetaAbstractInfo, so it is important to
keep them separate from NmcOutputField.
2017-03-31 19:18:16 +02:00
|
|
|
tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_nm_permissions;
|
2017-03-31 13:21:47 +02:00
|
|
|
out_indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error);
|
2012-04-30 11:50:26 +02:00
|
|
|
|
|
|
|
|
if (error) {
|
2013-12-10 12:00:53 +01:00
|
|
|
g_string_printf (nmc->return_text, _("Error: 'general permissions': %s"), error->message);
|
2012-04-30 11:50:26 +02:00
|
|
|
g_error_free (error);
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
2012-12-10 19:11:04 +01:00
|
|
|
return FALSE;
|
2012-04-30 11:50:26 +02:00
|
|
|
}
|
|
|
|
|
|
cli: split tracking of meta data out of NmcOutputField
When generating output data, nmcli iterates over a list of
property-descriptors (nmc_fields_ip4_config), creates an intermediate
array (output_data) and finally prints it.
However, previously both the meta data (nmc_fields_ip4_config) and
the intermediate format use the same type NmcOutputField. This means,
certain fields are relevant to describe a property, and other fields
are output/formatting fields.
Split this up. Now, the meta data is tracked in form of an NMMetaAbstractInfo
lists. This separates the information about properties from intermediate steps
during creation of the output.
Note that currently functions like print_ip4_config() still have all the
knowledge about how to generate the output. That is wrong, instead, the
meta data (NMMetaAbstractInfo) should describe how to create the output
and then all those functions could be replaced. This means, later we want
to add more knowledge to the NMMetaAbstractInfo, so it is important to
keep them separate from NmcOutputField.
2017-03-31 19:18:16 +02:00
|
|
|
arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES);
|
2017-03-30 14:56:19 +02:00
|
|
|
g_ptr_array_add (out.output_data, arr);
|
2012-04-30 11:50:26 +02:00
|
|
|
|
2016-10-19 10:08:46 +02:00
|
|
|
|
2012-04-30 11:50:26 +02:00
|
|
|
for (perm = NM_CLIENT_PERMISSION_NONE + 1; perm <= NM_CLIENT_PERMISSION_LAST; perm++) {
|
|
|
|
|
NMClientPermissionResult perm_result = nm_client_get_permission_result (nmc->client, perm);
|
|
|
|
|
|
cli: split tracking of meta data out of NmcOutputField
When generating output data, nmcli iterates over a list of
property-descriptors (nmc_fields_ip4_config), creates an intermediate
array (output_data) and finally prints it.
However, previously both the meta data (nmc_fields_ip4_config) and
the intermediate format use the same type NmcOutputField. This means,
certain fields are relevant to describe a property, and other fields
are output/formatting fields.
Split this up. Now, the meta data is tracked in form of an NMMetaAbstractInfo
lists. This separates the information about properties from intermediate steps
during creation of the output.
Note that currently functions like print_ip4_config() still have all the
knowledge about how to generate the output. That is wrong, instead, the
meta data (NMMetaAbstractInfo) should describe how to create the output
and then all those functions could be replaced. This means, later we want
to add more knowledge to the NMMetaAbstractInfo, so it is important to
keep them separate from NmcOutputField.
2017-03-31 19:18:16 +02:00
|
|
|
arr = nmc_dup_fields_array (tmpl, 0);
|
2013-05-22 08:37:50 +02:00
|
|
|
set_val_strc (arr, 0, permission_to_string (perm));
|
|
|
|
|
set_val_strc (arr, 1, permission_result_to_string (perm_result));
|
2017-03-30 14:56:19 +02:00
|
|
|
g_ptr_array_add (out.output_data, arr);
|
2012-04-30 11:50:26 +02:00
|
|
|
}
|
2017-03-30 14:56:19 +02:00
|
|
|
print_data_prepare_width (out.output_data);
|
2017-03-31 13:21:47 +02:00
|
|
|
print_data (&nmc->nmc_config,
|
|
|
|
|
out_indices,
|
|
|
|
|
_("NetworkManager permissions"),
|
|
|
|
|
0, &out);
|
2012-04-30 11:50:26 +02:00
|
|
|
|
2016-10-19 10:08:46 +02:00
|
|
|
quit ();
|
|
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
got_permissions (NmCli *nmc)
|
|
|
|
|
{
|
|
|
|
|
NMClientPermission perm;
|
|
|
|
|
|
|
|
|
|
/* The server returns all the permissions at once, so if at least one is there
|
|
|
|
|
* we already received the reply. */
|
|
|
|
|
for (perm = NM_CLIENT_PERMISSION_NONE + 1; perm <= NM_CLIENT_PERMISSION_LAST; perm++) {
|
|
|
|
|
if (nm_client_get_permission_result (nmc->client, perm) != NM_CLIENT_PERMISSION_RESULT_UNKNOWN)
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
permission_changed (NMClient *client,
|
|
|
|
|
NMClientPermission permission,
|
|
|
|
|
NMClientPermissionResult result,
|
|
|
|
|
NmCli *nmc)
|
|
|
|
|
{
|
|
|
|
|
if (got_permissions (nmc)) {
|
|
|
|
|
/* Defer the printing, so that we have a chance to process the other
|
|
|
|
|
* permission-changed signals. */
|
|
|
|
|
g_idle_remove_by_data (nmc);
|
|
|
|
|
g_idle_add (print_permissions, nmc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
show_nm_permissions (NmCli *nmc)
|
|
|
|
|
{
|
|
|
|
|
/* The permissions are available now, just print them. */
|
|
|
|
|
if (got_permissions (nmc)) {
|
|
|
|
|
print_permissions (nmc);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* The client didn't get the permissions reply yet. Subscribe to changes. */
|
|
|
|
|
g_signal_connect (nmc->client, NM_CLIENT_PERMISSION_CHANGED,
|
|
|
|
|
G_CALLBACK (permission_changed), nmc);
|
|
|
|
|
|
|
|
|
|
if (nmc->timeout == -1)
|
|
|
|
|
nmc->timeout = 10;
|
|
|
|
|
g_timeout_add_seconds (nmc->timeout, timeout_cb, nmc);
|
|
|
|
|
|
|
|
|
|
nmc->should_wait++;
|
2012-12-10 19:11:04 +01:00
|
|
|
return TRUE;
|
2012-04-30 11:50:26 +02:00
|
|
|
}
|
|
|
|
|
|
2016-07-06 13:34:21 +02:00
|
|
|
static NMCResultCode
|
|
|
|
|
do_general_permissions (NmCli *nmc, int argc, char **argv)
|
|
|
|
|
{
|
2017-03-30 16:09:46 +02:00
|
|
|
next_arg (nmc, &argc, &argv, NULL);
|
2016-07-06 14:43:13 +02:00
|
|
|
if (nmc->complete)
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
|
2016-07-06 13:34:21 +02:00
|
|
|
show_nm_permissions (nmc);
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-12 14:23:54 +01:00
|
|
|
static gboolean
|
|
|
|
|
show_general_logging (NmCli *nmc)
|
|
|
|
|
{
|
|
|
|
|
char *level = NULL;
|
|
|
|
|
char *domains = NULL;
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
const char *fields_str;
|
|
|
|
|
const char *fields_all = NMC_FIELDS_NM_LOGGING_ALL;
|
|
|
|
|
const char *fields_common = NMC_FIELDS_NM_LOGGING_COMMON;
|
cli: split tracking of meta data out of NmcOutputField
When generating output data, nmcli iterates over a list of
property-descriptors (nmc_fields_ip4_config), creates an intermediate
array (output_data) and finally prints it.
However, previously both the meta data (nmc_fields_ip4_config) and
the intermediate format use the same type NmcOutputField. This means,
certain fields are relevant to describe a property, and other fields
are output/formatting fields.
Split this up. Now, the meta data is tracked in form of an NMMetaAbstractInfo
lists. This separates the information about properties from intermediate steps
during creation of the output.
Note that currently functions like print_ip4_config() still have all the
knowledge about how to generate the output. That is wrong, instead, the
meta data (NMMetaAbstractInfo) should describe how to create the output
and then all those functions could be replaced. This means, later we want
to add more knowledge to the NMMetaAbstractInfo, so it is important to
keep them separate from NmcOutputField.
2017-03-31 19:18:16 +02:00
|
|
|
const NMMetaAbstractInfo *const*tmpl;
|
|
|
|
|
NmcOutputField *arr;
|
2017-03-30 14:56:19 +02:00
|
|
|
NMC_OUTPUT_DATA_DEFINE_SCOPED (out);
|
2012-12-12 14:23:54 +01:00
|
|
|
|
|
|
|
|
if (!nmc->required_fields || strcasecmp (nmc->required_fields, "common") == 0)
|
|
|
|
|
fields_str = fields_common;
|
|
|
|
|
else if (!nmc->required_fields || strcasecmp (nmc->required_fields, "all") == 0)
|
|
|
|
|
fields_str = fields_all;
|
|
|
|
|
else
|
|
|
|
|
fields_str = nmc->required_fields;
|
|
|
|
|
|
cli: split tracking of meta data out of NmcOutputField
When generating output data, nmcli iterates over a list of
property-descriptors (nmc_fields_ip4_config), creates an intermediate
array (output_data) and finally prints it.
However, previously both the meta data (nmc_fields_ip4_config) and
the intermediate format use the same type NmcOutputField. This means,
certain fields are relevant to describe a property, and other fields
are output/formatting fields.
Split this up. Now, the meta data is tracked in form of an NMMetaAbstractInfo
lists. This separates the information about properties from intermediate steps
during creation of the output.
Note that currently functions like print_ip4_config() still have all the
knowledge about how to generate the output. That is wrong, instead, the
meta data (NMMetaAbstractInfo) should describe how to create the output
and then all those functions could be replaced. This means, later we want
to add more knowledge to the NMMetaAbstractInfo, so it is important to
keep them separate from NmcOutputField.
2017-03-31 19:18:16 +02:00
|
|
|
tmpl = (const NMMetaAbstractInfo *const*) nmc_fields_nm_logging;
|
2017-03-31 13:21:47 +02:00
|
|
|
out_indices = parse_output_fields (fields_str, tmpl, FALSE, NULL, &error);
|
2013-05-22 08:37:50 +02:00
|
|
|
|
2012-12-12 14:23:54 +01:00
|
|
|
if (error) {
|
2013-12-10 12:00:53 +01:00
|
|
|
g_string_printf (nmc->return_text, _("Error: 'general logging': %s"), error->message);
|
2012-12-12 14:23:54 +01:00
|
|
|
g_error_free (error);
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nm_client_get_logging (nmc->client, &level, &domains, &error);
|
|
|
|
|
if (error) {
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: %s."), error->message);
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
cli: split tracking of meta data out of NmcOutputField
When generating output data, nmcli iterates over a list of
property-descriptors (nmc_fields_ip4_config), creates an intermediate
array (output_data) and finally prints it.
However, previously both the meta data (nmc_fields_ip4_config) and
the intermediate format use the same type NmcOutputField. This means,
certain fields are relevant to describe a property, and other fields
are output/formatting fields.
Split this up. Now, the meta data is tracked in form of an NMMetaAbstractInfo
lists. This separates the information about properties from intermediate steps
during creation of the output.
Note that currently functions like print_ip4_config() still have all the
knowledge about how to generate the output. That is wrong, instead, the
meta data (NMMetaAbstractInfo) should describe how to create the output
and then all those functions could be replaced. This means, later we want
to add more knowledge to the NMMetaAbstractInfo, so it is important to
keep them separate from NmcOutputField.
2017-03-31 19:18:16 +02:00
|
|
|
arr = nmc_dup_fields_array (tmpl, NMC_OF_FLAG_MAIN_HEADER_ADD | NMC_OF_FLAG_FIELD_NAMES);
|
2017-03-30 14:56:19 +02:00
|
|
|
g_ptr_array_add (out.output_data, arr);
|
2013-05-22 08:37:50 +02:00
|
|
|
|
cli: split tracking of meta data out of NmcOutputField
When generating output data, nmcli iterates over a list of
property-descriptors (nmc_fields_ip4_config), creates an intermediate
array (output_data) and finally prints it.
However, previously both the meta data (nmc_fields_ip4_config) and
the intermediate format use the same type NmcOutputField. This means,
certain fields are relevant to describe a property, and other fields
are output/formatting fields.
Split this up. Now, the meta data is tracked in form of an NMMetaAbstractInfo
lists. This separates the information about properties from intermediate steps
during creation of the output.
Note that currently functions like print_ip4_config() still have all the
knowledge about how to generate the output. That is wrong, instead, the
meta data (NMMetaAbstractInfo) should describe how to create the output
and then all those functions could be replaced. This means, later we want
to add more knowledge to the NMMetaAbstractInfo, so it is important to
keep them separate from NmcOutputField.
2017-03-31 19:18:16 +02:00
|
|
|
arr = nmc_dup_fields_array (tmpl, 0);
|
2013-05-22 08:37:50 +02:00
|
|
|
set_val_str (arr, 0, level);
|
|
|
|
|
set_val_str (arr, 1, domains);
|
2017-03-30 14:56:19 +02:00
|
|
|
g_ptr_array_add (out.output_data, arr);
|
2012-12-12 14:23:54 +01:00
|
|
|
|
2017-03-30 14:56:19 +02:00
|
|
|
print_data_prepare_width (out.output_data);
|
2017-03-31 13:21:47 +02:00
|
|
|
print_data (&nmc->nmc_config, out_indices,
|
|
|
|
|
_("NetworkManager logging"),
|
|
|
|
|
0, &out);
|
2012-12-12 14:23:54 +01:00
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-14 16:38:16 +01:00
|
|
|
static void
|
|
|
|
|
nmc_complete_strings_nocase (const char *prefix, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list args;
|
|
|
|
|
const char *candidate;
|
|
|
|
|
int len;
|
|
|
|
|
|
|
|
|
|
len = strlen (prefix);
|
|
|
|
|
|
|
|
|
|
va_start (args, prefix);
|
|
|
|
|
while ((candidate = va_arg (args, const char *))) {
|
|
|
|
|
if (strncasecmp (prefix, candidate, len) == 0)
|
|
|
|
|
g_print ("%s\n", candidate);
|
|
|
|
|
}
|
|
|
|
|
va_end (args);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-06 13:34:21 +02:00
|
|
|
static NMCResultCode
|
|
|
|
|
do_general_logging (NmCli *nmc, int argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
gs_free_error GError *error = NULL;
|
|
|
|
|
|
2017-03-30 16:09:46 +02:00
|
|
|
next_arg (nmc, &argc, &argv, NULL);
|
2016-07-06 13:34:21 +02:00
|
|
|
if (argc == 0) {
|
2016-07-06 14:43:13 +02:00
|
|
|
if (nmc->complete)
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
|
2016-07-06 13:34:21 +02:00
|
|
|
show_general_logging (nmc);
|
|
|
|
|
} else {
|
|
|
|
|
/* arguments provided -> set logging level and domains */
|
|
|
|
|
const char *level = NULL;
|
|
|
|
|
const char *domains = NULL;
|
|
|
|
|
|
2017-02-14 16:38:16 +01:00
|
|
|
do {
|
|
|
|
|
if (argc == 1 && nmc->complete)
|
|
|
|
|
nmc_complete_strings (*argv, "level", "domains", NULL);
|
|
|
|
|
|
cli: make match() return boolean
Coccinelle semantic patch:
@@
@@
-int
+gboolean
matches (...);
@@
expression pattern, cmd, len;
@@
-int
+gboolean
matches (...)
{
...
- return memcmp (pattern, cmd, len);
+ return memcmp (pattern, cmd, len) == 0;
}
@@
expression prefix, str;
@@
(
-matches (prefix, str) != 0
+!matches (prefix, str)
|
-matches (prefix, str) == 0
+matches (prefix, str)
)
@@
expression prefix, str;
@@
-(matches (prefix, str))
+matches (prefix, str)
@@
expression prefix, str;
@@
-(!matches (prefix, str))
+!matches (prefix, str)
spatch --smpl-spacing --sp-file match.cocci --dir clients/cli/ \
--include-headers --macro-file shared/nm-utils/gsystem-local-alloc.h
2017-02-15 12:20:55 +01:00
|
|
|
if (matches (*argv, "level")) {
|
2017-03-29 12:02:14 +02:00
|
|
|
argc--;
|
|
|
|
|
argv++;
|
2017-03-24 14:00:25 +01:00
|
|
|
if (!argc) {
|
2017-02-14 16:38:16 +01:00
|
|
|
g_string_printf (nmc->return_text, _("Error: '%s' argument is missing."), *(argv-1));
|
|
|
|
|
return NMC_RESULT_ERROR_USER_INPUT;
|
|
|
|
|
}
|
|
|
|
|
if (argc == 1 && nmc->complete) {
|
|
|
|
|
nmc_complete_strings_nocase (*argv, "TRACE", "DEBUG", "INFO", "WARN",
|
|
|
|
|
"ERR", "OFF", "KEEP", NULL);
|
|
|
|
|
}
|
|
|
|
|
level = *argv;
|
cli: make match() return boolean
Coccinelle semantic patch:
@@
@@
-int
+gboolean
matches (...);
@@
expression pattern, cmd, len;
@@
-int
+gboolean
matches (...)
{
...
- return memcmp (pattern, cmd, len);
+ return memcmp (pattern, cmd, len) == 0;
}
@@
expression prefix, str;
@@
(
-matches (prefix, str) != 0
+!matches (prefix, str)
|
-matches (prefix, str) == 0
+matches (prefix, str)
)
@@
expression prefix, str;
@@
-(matches (prefix, str))
+matches (prefix, str)
@@
expression prefix, str;
@@
-(!matches (prefix, str))
+!matches (prefix, str)
spatch --smpl-spacing --sp-file match.cocci --dir clients/cli/ \
--include-headers --macro-file shared/nm-utils/gsystem-local-alloc.h
2017-02-15 12:20:55 +01:00
|
|
|
} else if (matches (*argv, "domains")) {
|
2017-03-29 12:02:14 +02:00
|
|
|
argc--;
|
|
|
|
|
argv++;
|
2017-03-24 14:00:25 +01:00
|
|
|
if (!argc) {
|
2017-02-14 16:38:16 +01:00
|
|
|
g_string_printf (nmc->return_text, _("Error: '%s' argument is missing."), *(argv-1));
|
|
|
|
|
return NMC_RESULT_ERROR_USER_INPUT;
|
|
|
|
|
}
|
|
|
|
|
if (argc == 1 && nmc->complete) {
|
|
|
|
|
nmc_complete_strings_nocase (*argv, "PLATFORM", "RFKILL", "ETHER", "WIFI", "BT",
|
|
|
|
|
"MB", "DHCP4", "DHCP6", "PPP", "WIFI_SCAN", "IP4",
|
|
|
|
|
"IP6", "AUTOIP4", "DNS", "VPN", "SHARING", "SUPPLICANT",
|
|
|
|
|
"AGENTS", "SETTINGS", "SUSPEND", "CORE", "DEVICE", "OLPC",
|
|
|
|
|
"INFINIBAND", "FIREWALL", "ADSL", "BOND", "VLAN", "BRIDGE",
|
|
|
|
|
"DBUS_PROPS", "TEAM", "CONCHECK", "DCB", "DISPATCH", "AUDIT",
|
|
|
|
|
"SYSTEMD", "VPN_PLUGIN", "PROXY", NULL);
|
|
|
|
|
}
|
|
|
|
|
domains = *argv;
|
|
|
|
|
} else {
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: property '%s' is not known."), *argv);
|
|
|
|
|
return NMC_RESULT_ERROR_USER_INPUT;
|
|
|
|
|
}
|
2017-03-30 16:09:46 +02:00
|
|
|
} while (next_arg (nmc, &argc, &argv, NULL) == 0);
|
2017-02-14 16:38:16 +01:00
|
|
|
|
2016-07-06 14:43:13 +02:00
|
|
|
if (nmc->complete)
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
|
2016-07-06 13:34:21 +02:00
|
|
|
nm_client_set_logging (nmc->client, level, domains, &error);
|
|
|
|
|
if (error) {
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: failed to set logging: %s"),
|
2016-08-19 11:56:58 +02:00
|
|
|
nmc_error_get_simple_message (error));
|
2016-07-06 13:34:21 +02:00
|
|
|
return NMC_RESULT_ERROR_UNKNOWN;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-07 11:30:54 +01:00
|
|
|
static void
|
2014-09-11 16:27:13 -04:00
|
|
|
save_hostname_cb (GObject *object, GAsyncResult *result, gpointer user_data)
|
2013-11-07 11:30:54 +01:00
|
|
|
{
|
|
|
|
|
NmCli *nmc = (NmCli *) user_data;
|
2014-09-11 16:27:13 -04:00
|
|
|
GError *error = NULL;
|
2013-11-07 11:30:54 +01:00
|
|
|
|
2014-09-29 10:58:16 -04:00
|
|
|
nm_client_save_hostname_finish (NM_CLIENT (object), result, &error);
|
2013-11-07 11:30:54 +01:00
|
|
|
if (error) {
|
2014-10-01 10:31:03 +02:00
|
|
|
g_string_printf (nmc->return_text, _("Error: failed to set hostname: %s"),
|
|
|
|
|
error->message);
|
2013-11-07 11:30:54 +01:00
|
|
|
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
2014-09-11 16:27:13 -04:00
|
|
|
g_error_free (error);
|
2013-11-07 11:30:54 +01:00
|
|
|
}
|
|
|
|
|
quit ();
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-06 13:34:21 +02:00
|
|
|
static NMCResultCode
|
|
|
|
|
do_general_hostname (NmCli *nmc, int argc, char **argv)
|
|
|
|
|
{
|
2017-03-30 16:09:46 +02:00
|
|
|
next_arg (nmc, &argc, &argv, NULL);
|
2016-07-06 14:43:13 +02:00
|
|
|
if (nmc->complete)
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
|
2016-07-06 13:34:21 +02:00
|
|
|
if (argc == 0) {
|
|
|
|
|
/* no arguments -> get hostname */
|
|
|
|
|
char *hostname = NULL;
|
|
|
|
|
|
|
|
|
|
g_object_get (nmc->client, NM_CLIENT_HOSTNAME, &hostname, NULL);
|
|
|
|
|
if (hostname)
|
|
|
|
|
g_print ("%s\n", hostname);
|
|
|
|
|
g_free (hostname);
|
|
|
|
|
} else {
|
|
|
|
|
/* hostname provided -> set it */
|
|
|
|
|
const char *hostname = *argv;
|
|
|
|
|
|
2017-03-30 16:09:46 +02:00
|
|
|
if (next_arg (nmc, &argc, &argv, NULL) == 0)
|
2016-07-06 13:34:21 +02:00
|
|
|
g_print ("Warning: ignoring extra garbage after '%s' hostname\n", hostname);
|
|
|
|
|
|
|
|
|
|
nmc->should_wait++;
|
|
|
|
|
nm_client_save_hostname_async (nmc->client, hostname, NULL, save_hostname_cb, nmc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const NMCCommand general_cmds[] = {
|
2016-08-31 20:52:48 +02:00
|
|
|
{ "status", do_general_status, usage_general_status, TRUE, TRUE },
|
|
|
|
|
{ "hostname", do_general_hostname, usage_general_hostname, TRUE, TRUE },
|
|
|
|
|
{ "permissions", do_general_permissions, usage_general_permissions, TRUE, TRUE },
|
|
|
|
|
{ "logging", do_general_logging, usage_general_logging, TRUE, TRUE },
|
|
|
|
|
{ NULL, do_general_status, usage_general, TRUE, TRUE },
|
2016-07-06 13:34:21 +02:00
|
|
|
};
|
|
|
|
|
|
2012-12-10 19:11:04 +01:00
|
|
|
/*
|
|
|
|
|
* Entry point function for general operations 'nmcli general'
|
|
|
|
|
*/
|
|
|
|
|
NMCResultCode
|
|
|
|
|
do_general (NmCli *nmc, int argc, char **argv)
|
|
|
|
|
{
|
2017-03-30 16:09:46 +02:00
|
|
|
next_arg (nmc, &argc, &argv, NULL);
|
|
|
|
|
|
2014-10-30 15:45:43 +01:00
|
|
|
/* Register polkit agent */
|
|
|
|
|
nmc_start_polkit_agent_start_try (nmc);
|
|
|
|
|
|
2016-08-31 21:04:33 +02:00
|
|
|
nmc_do_cmd (nmc, general_cmds, *argv, argc, argv);
|
|
|
|
|
|
|
|
|
|
return nmc->return_value;
|
2012-12-10 19:11:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
nmc_switch_show (NmCli *nmc, const char *switch_name, const char *header)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (nmc != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (switch_name != NULL, FALSE);
|
|
|
|
|
|
|
|
|
|
if (nmc->required_fields && strcasecmp (nmc->required_fields, switch_name) != 0) {
|
2013-09-12 14:45:08 +02:00
|
|
|
g_string_printf (nmc->return_text, _("Error: '--fields' value '%s' is not valid here (allowed field: %s)"),
|
2012-12-10 19:11:04 +01:00
|
|
|
nmc->required_fields, switch_name);
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2017-03-30 12:45:41 +02:00
|
|
|
if (nmc->nmc_config.print_output == NMC_PRINT_NORMAL)
|
|
|
|
|
nmc->nmc_config_mutable.print_output = NMC_PRINT_TERSE;
|
2012-12-10 19:11:04 +01:00
|
|
|
|
2013-09-12 14:45:08 +02:00
|
|
|
if (!nmc->required_fields)
|
|
|
|
|
nmc->required_fields = g_strdup (switch_name);
|
|
|
|
|
return show_nm_status (nmc, header, NULL);
|
2012-12-10 19:11:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
nmc_switch_parse_on_off (NmCli *nmc, const char *arg1, const char *arg2, gboolean *res)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (nmc != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (arg1 && arg2, FALSE);
|
|
|
|
|
g_return_val_if_fail (res != NULL, FALSE);
|
|
|
|
|
|
|
|
|
|
if (!strcmp (arg2, "on"))
|
|
|
|
|
*res = TRUE;
|
|
|
|
|
else if (!strcmp (arg2, "off"))
|
|
|
|
|
*res = FALSE;
|
|
|
|
|
else {
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: invalid '%s' argument: '%s' (use on/off)."), arg1, arg2);
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-09 13:21:41 +01:00
|
|
|
static NMCResultCode
|
|
|
|
|
do_networking_on_off (NmCli *nmc, int argc, char **argv, gboolean enable)
|
2013-08-28 10:06:54 -04:00
|
|
|
{
|
2016-12-09 13:21:41 +01:00
|
|
|
if (nmc->complete)
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
|
|
|
|
|
/* Register polkit agent */
|
|
|
|
|
nmc_start_polkit_agent_start_try (nmc);
|
|
|
|
|
|
|
|
|
|
nm_client_networking_set_enabled (nmc->client, enable, NULL);
|
|
|
|
|
|
|
|
|
|
return nmc->return_value;
|
2013-08-28 10:06:54 -04:00
|
|
|
}
|
|
|
|
|
|
2016-12-09 13:21:41 +01:00
|
|
|
static NMCResultCode
|
|
|
|
|
do_networking_on (NmCli *nmc, int argc, char **argv)
|
2013-02-28 14:53:11 +01:00
|
|
|
{
|
2017-03-30 16:09:46 +02:00
|
|
|
next_arg (nmc, &argc, &argv, NULL);
|
2016-12-09 13:21:41 +01:00
|
|
|
return do_networking_on_off (nmc, argc, argv, TRUE);
|
|
|
|
|
}
|
2013-02-28 14:53:11 +01:00
|
|
|
|
2016-12-09 13:21:41 +01:00
|
|
|
static NMCResultCode
|
|
|
|
|
do_networking_off (NmCli *nmc, int argc, char **argv)
|
|
|
|
|
{
|
2017-03-30 16:09:46 +02:00
|
|
|
next_arg (nmc, &argc, &argv, NULL);
|
2016-12-09 13:21:41 +01:00
|
|
|
return do_networking_on_off (nmc, argc, argv, FALSE);
|
|
|
|
|
}
|
2014-10-30 15:45:43 +01:00
|
|
|
|
2016-12-09 13:21:41 +01:00
|
|
|
static NMCResultCode
|
|
|
|
|
do_networking_connectivity (NmCli *nmc, int argc, char **argv)
|
|
|
|
|
{
|
2017-03-30 16:09:46 +02:00
|
|
|
next_arg (nmc, &argc, &argv, NULL);
|
2016-12-09 13:21:41 +01:00
|
|
|
if (nmc->complete) {
|
|
|
|
|
if (argc == 1)
|
|
|
|
|
nmc_complete_strings (*argv, "check", NULL);
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!argc) {
|
|
|
|
|
/* no arguments -> get current state */
|
|
|
|
|
nmc_switch_show (nmc, NMC_FIELDS_NM_CONNECTIVITY, _("Connectivity"));
|
cli: make match() return boolean
Coccinelle semantic patch:
@@
@@
-int
+gboolean
matches (...);
@@
expression pattern, cmd, len;
@@
-int
+gboolean
matches (...)
{
...
- return memcmp (pattern, cmd, len);
+ return memcmp (pattern, cmd, len) == 0;
}
@@
expression prefix, str;
@@
(
-matches (prefix, str) != 0
+!matches (prefix, str)
|
-matches (prefix, str) == 0
+matches (prefix, str)
)
@@
expression prefix, str;
@@
-(matches (prefix, str))
+matches (prefix, str)
@@
expression prefix, str;
@@
-(!matches (prefix, str))
+!matches (prefix, str)
spatch --smpl-spacing --sp-file match.cocci --dir clients/cli/ \
--include-headers --macro-file shared/nm-utils/gsystem-local-alloc.h
2017-02-15 12:20:55 +01:00
|
|
|
} else if (matches (*argv, "check")) {
|
2016-12-09 13:21:41 +01:00
|
|
|
gs_free_error GError *error = NULL;
|
|
|
|
|
|
|
|
|
|
/* Register polkit agent */
|
|
|
|
|
nmc_start_polkit_agent_start_try (nmc);
|
|
|
|
|
|
|
|
|
|
nm_client_check_connectivity (nmc->client, NULL, &error);
|
|
|
|
|
if (error) {
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: %s."), error->message);
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
|
|
|
|
} else
|
|
|
|
|
nmc_switch_show (nmc, NMC_FIELDS_NM_CONNECTIVITY, _("Connectivity"));
|
|
|
|
|
} else {
|
|
|
|
|
usage_networking ();
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: 'networking' command '%s' is not valid."), *argv);
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
|
|
|
|
}
|
2016-07-06 14:52:25 +02:00
|
|
|
|
2016-12-09 13:21:41 +01:00
|
|
|
return nmc->return_value;
|
|
|
|
|
}
|
2016-07-06 14:52:25 +02:00
|
|
|
|
2016-12-09 13:21:41 +01:00
|
|
|
static NMCResultCode
|
|
|
|
|
do_networking_show (NmCli *nmc, int argc, char **argv)
|
|
|
|
|
{
|
2017-03-30 16:09:46 +02:00
|
|
|
next_arg (nmc, &argc, &argv, NULL);
|
2016-12-09 13:21:41 +01:00
|
|
|
if (nmc->complete)
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
|
|
|
|
|
nmc_switch_show (nmc, NMC_FIELDS_NM_NETWORKING, _("Networking"));
|
|
|
|
|
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const NMCCommand networking_cmds[] = {
|
|
|
|
|
{ "on", do_networking_on, usage_networking_on, TRUE, TRUE },
|
|
|
|
|
{ "off", do_networking_off, usage_networking_off, TRUE, TRUE },
|
|
|
|
|
{ "connectivity", do_networking_connectivity, usage_networking_connectivity, TRUE, TRUE },
|
|
|
|
|
{ NULL, do_networking_show, usage_networking, TRUE, TRUE },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Entry point function for networking commands 'nmcli networking'
|
|
|
|
|
*/
|
|
|
|
|
NMCResultCode
|
|
|
|
|
do_networking (NmCli *nmc, int argc, char **argv)
|
|
|
|
|
{
|
2017-03-30 16:09:46 +02:00
|
|
|
next_arg (nmc, &argc, &argv, NULL);
|
2016-12-09 13:21:41 +01:00
|
|
|
nmc_do_cmd (nmc, networking_cmds, *argv, argc, argv);
|
2013-02-28 14:53:11 +01:00
|
|
|
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-06 14:33:16 +02:00
|
|
|
static NMCResultCode
|
|
|
|
|
do_radio_all (NmCli *nmc, int argc, char **argv)
|
2012-12-10 19:11:04 +01:00
|
|
|
{
|
|
|
|
|
gboolean enable_flag;
|
2014-10-30 15:45:43 +01:00
|
|
|
|
2017-03-30 16:09:46 +02:00
|
|
|
next_arg (nmc, &argc, &argv, NULL);
|
2012-12-10 19:11:04 +01:00
|
|
|
if (argc == 0) {
|
2016-07-06 14:54:58 +02:00
|
|
|
if (nmc->complete)
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
|
2016-07-06 14:33:16 +02:00
|
|
|
/* no argument, show all radio switches */
|
2013-04-18 15:07:21 +02:00
|
|
|
show_nm_status (nmc, _("Radio switches"), NMC_FIELDS_NM_STATUS_RADIO);
|
2016-07-06 14:33:16 +02:00
|
|
|
} else {
|
2016-07-06 14:54:58 +02:00
|
|
|
if (nmc->complete) {
|
|
|
|
|
if (argc == 1)
|
|
|
|
|
nmc_complete_bool (*argv);
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-06 14:33:16 +02:00
|
|
|
if (!nmc_switch_parse_on_off (nmc, *(argv-1), *argv, &enable_flag))
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
|
|
|
|
|
nm_client_wireless_set_enabled (nmc->client, enable_flag);
|
|
|
|
|
nm_client_wimax_set_enabled (nmc->client, enable_flag);
|
|
|
|
|
nm_client_wwan_set_enabled (nmc->client, enable_flag);
|
2012-12-10 19:11:04 +01:00
|
|
|
}
|
|
|
|
|
|
2016-07-06 14:33:16 +02:00
|
|
|
return nmc->return_value;
|
|
|
|
|
}
|
2012-12-10 19:11:04 +01:00
|
|
|
|
2016-07-06 14:33:16 +02:00
|
|
|
static NMCResultCode
|
|
|
|
|
do_radio_wifi (NmCli *nmc, int argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
gboolean enable_flag;
|
2012-12-10 19:11:04 +01:00
|
|
|
|
2017-03-30 16:09:46 +02:00
|
|
|
next_arg (nmc, &argc, &argv, NULL);
|
2016-07-06 14:33:16 +02:00
|
|
|
if (argc == 0) {
|
2016-07-06 14:54:58 +02:00
|
|
|
if (nmc->complete)
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
|
2016-07-06 14:33:16 +02:00
|
|
|
/* no argument, show current WiFi state */
|
|
|
|
|
nmc_switch_show (nmc, NMC_FIELDS_NM_WIFI, _("Wi-Fi radio switch"));
|
|
|
|
|
} else {
|
2016-07-06 14:54:58 +02:00
|
|
|
if (nmc->complete) {
|
|
|
|
|
if (argc == 1)
|
|
|
|
|
nmc_complete_bool (*argv);
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
}
|
2016-07-06 14:33:16 +02:00
|
|
|
if (!nmc_switch_parse_on_off (nmc, *(argv-1), *argv, &enable_flag))
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
|
|
|
|
|
nm_client_wireless_set_enabled (nmc->client, enable_flag);
|
2012-12-10 19:11:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-06 14:33:16 +02:00
|
|
|
static NMCResultCode
|
|
|
|
|
do_radio_wwan (NmCli *nmc, int argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
gboolean enable_flag;
|
|
|
|
|
|
2017-03-30 16:09:46 +02:00
|
|
|
next_arg (nmc, &argc, &argv, NULL);
|
2016-07-06 14:33:16 +02:00
|
|
|
if (argc == 0) {
|
2016-07-06 14:54:58 +02:00
|
|
|
if (nmc->complete)
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
|
2016-07-06 14:33:16 +02:00
|
|
|
/* no argument, show current WWAN (mobile broadband) state */
|
|
|
|
|
nmc_switch_show (nmc, NMC_FIELDS_NM_WWAN, _("WWAN radio switch"));
|
|
|
|
|
} else {
|
2016-07-06 14:54:58 +02:00
|
|
|
if (nmc->complete) {
|
|
|
|
|
if (argc == 1)
|
|
|
|
|
nmc_complete_bool (*argv);
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
}
|
2016-07-06 14:33:16 +02:00
|
|
|
if (!nmc_switch_parse_on_off (nmc, *(argv-1), *argv, &enable_flag))
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
|
|
|
|
|
nm_client_wwan_set_enabled (nmc->client, enable_flag);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const NMCCommand radio_cmds[] = {
|
2016-08-31 20:52:48 +02:00
|
|
|
{ "all", do_radio_all, usage_radio_all, TRUE, TRUE },
|
|
|
|
|
{ "wifi", do_radio_wifi, usage_radio_wifi, TRUE, TRUE },
|
|
|
|
|
{ "wwan", do_radio_wwan, usage_radio_wwan, TRUE, TRUE },
|
|
|
|
|
{ NULL, do_radio_all, usage_radio, TRUE, TRUE },
|
2016-07-06 14:33:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Entry point function for radio switch commands 'nmcli radio'
|
|
|
|
|
*/
|
|
|
|
|
NMCResultCode
|
|
|
|
|
do_radio (NmCli *nmc, int argc, char **argv)
|
|
|
|
|
{
|
2017-03-30 16:09:46 +02:00
|
|
|
next_arg (nmc, &argc, &argv, NULL);
|
|
|
|
|
|
2016-07-06 14:33:16 +02:00
|
|
|
/* Register polkit agent */
|
|
|
|
|
nmc_start_polkit_agent_start_try (nmc);
|
|
|
|
|
|
2016-08-31 21:04:33 +02:00
|
|
|
nmc_do_cmd (nmc, radio_cmds, *argv, argc, argv);
|
|
|
|
|
|
|
|
|
|
return nmc->return_value;
|
2016-07-06 14:33:16 +02:00
|
|
|
}
|
|
|
|
|
|
2015-12-14 16:37:57 +01:00
|
|
|
static void
|
|
|
|
|
networkmanager_running (NMClient *client, GParamSpec *param, NmCli *nmc)
|
|
|
|
|
{
|
|
|
|
|
gboolean running;
|
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
|
|
running = nm_client_get_nm_running (client);
|
2017-03-30 12:23:26 +02:00
|
|
|
str = nmc_colorize (nmc->nmc_config.use_colors,
|
2017-04-04 15:12:00 +02:00
|
|
|
running ? NM_META_TERM_COLOR_GREEN : NM_META_TERM_COLOR_RED,
|
|
|
|
|
NM_META_TERM_FORMAT_NORMAL,
|
2016-06-05 11:46:06 +02:00
|
|
|
running ? _("NetworkManager has started") : _("NetworkManager has stopped"));
|
2015-12-14 16:37:57 +01:00
|
|
|
g_print ("%s\n", str);
|
|
|
|
|
g_free (str);
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-27 13:07:43 +01:00
|
|
|
static void
|
|
|
|
|
client_hostname (NMClient *client, GParamSpec *param, NmCli *nmc)
|
|
|
|
|
{
|
|
|
|
|
const char *hostname;
|
|
|
|
|
|
|
|
|
|
g_object_get (client, NM_CLIENT_HOSTNAME, &hostname, NULL);
|
|
|
|
|
g_print (_("Hostname set to '%s'\n"), hostname);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
client_primary_connection (NMClient *client, GParamSpec *param, NmCli *nmc)
|
|
|
|
|
{
|
2015-12-14 16:04:49 +01:00
|
|
|
NMActiveConnection *primary;
|
2015-03-27 13:07:43 +01:00
|
|
|
const char *id;
|
|
|
|
|
|
2015-12-14 16:04:49 +01:00
|
|
|
primary = nm_client_get_primary_connection (client);
|
2015-03-27 13:07:43 +01:00
|
|
|
if (primary) {
|
2015-12-14 16:04:49 +01:00
|
|
|
id = nm_active_connection_get_id (primary);
|
2015-03-27 13:07:43 +01:00
|
|
|
if (!id)
|
2015-12-14 16:04:49 +01:00
|
|
|
id = nm_active_connection_get_uuid (primary);
|
2015-03-27 13:07:43 +01:00
|
|
|
|
|
|
|
|
g_print (_("'%s' is now the primary connection\n"), id);
|
|
|
|
|
} else {
|
|
|
|
|
g_print (_("There's no primary connection\n"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
client_connectivity (NMClient *client, GParamSpec *param, NmCli *nmc)
|
|
|
|
|
{
|
|
|
|
|
NMConnectivityState connectivity;
|
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
|
|
g_object_get (client, NM_CLIENT_CONNECTIVITY, &connectivity, NULL);
|
2017-04-04 15:12:00 +02:00
|
|
|
str = nmc_colorize (nmc->nmc_config.use_colors, connectivity_to_color (connectivity), NM_META_TERM_FORMAT_NORMAL,
|
2015-03-27 13:07:43 +01:00
|
|
|
_("Connectivity is now '%s'\n"), nm_connectivity_to_string (connectivity));
|
|
|
|
|
g_print ("%s", str);
|
|
|
|
|
g_free (str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
client_state (NMClient *client, GParamSpec *param, NmCli *nmc)
|
|
|
|
|
{
|
|
|
|
|
NMState state;
|
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
|
|
g_object_get (client, NM_CLIENT_STATE, &state, NULL);
|
2017-04-04 15:12:00 +02:00
|
|
|
str = nmc_colorize (nmc->nmc_config.use_colors, state_to_color (state), NM_META_TERM_FORMAT_NORMAL,
|
2015-03-27 13:07:43 +01:00
|
|
|
_("Networkmanager is now in the '%s' state\n"),
|
|
|
|
|
nm_state_to_string (state));
|
|
|
|
|
g_print ("%s", str);
|
|
|
|
|
g_free (str);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-01 21:47:01 +02:00
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
device_overview (NmCli *nmc, NMDevice *device)
|
|
|
|
|
{
|
|
|
|
|
GString *outbuf = g_string_sized_new (80);
|
|
|
|
|
char *tmp;
|
|
|
|
|
const GPtrArray *activatable;
|
|
|
|
|
|
|
|
|
|
activatable = nm_device_get_available_connections (device);
|
|
|
|
|
|
|
|
|
|
g_string_append_printf (outbuf, "%s", nm_device_get_type_description (device));
|
|
|
|
|
|
|
|
|
|
if (nm_device_get_state (device) == NM_DEVICE_STATE_DISCONNECTED) {
|
|
|
|
|
if (activatable) {
|
|
|
|
|
if (activatable->len == 1)
|
|
|
|
|
g_print ("\t%d %s\n", activatable->len, _("connection available"));
|
|
|
|
|
else if (activatable->len > 1)
|
|
|
|
|
g_print ("\t%d %s\n", activatable->len, _("connections available"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( nm_device_get_driver (device)
|
|
|
|
|
&& strcmp (nm_device_get_driver (device), "")
|
|
|
|
|
&& strcmp (nm_device_get_driver (device), nm_device_get_type_description (device))) {
|
|
|
|
|
g_string_append_printf (outbuf, " (%s)", nm_device_get_driver (device));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_string_append_printf (outbuf, ", ");
|
|
|
|
|
|
|
|
|
|
if ( nm_device_get_hw_address (device)
|
|
|
|
|
&& strcmp (nm_device_get_hw_address (device), "")) {
|
|
|
|
|
g_string_append_printf (outbuf, "%s, ", nm_device_get_hw_address (device));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!nm_device_get_autoconnect (device))
|
|
|
|
|
g_string_append_printf (outbuf, "%s, ", _("autoconnect"));
|
|
|
|
|
if (nm_device_get_firmware_missing (device)) {
|
2017-04-04 15:12:00 +02:00
|
|
|
tmp = nmc_colorize (nmc->nmc_config.use_colors, NM_META_TERM_COLOR_RED, NM_META_TERM_FORMAT_NORMAL, _("fw missing"));
|
2016-07-01 21:47:01 +02:00
|
|
|
g_string_append_printf (outbuf, "%s, ", tmp);
|
|
|
|
|
g_free (tmp);
|
|
|
|
|
}
|
|
|
|
|
if (nm_device_get_nm_plugin_missing (device)) {
|
2017-04-04 15:12:00 +02:00
|
|
|
tmp = nmc_colorize (nmc->nmc_config.use_colors, NM_META_TERM_COLOR_RED, NM_META_TERM_FORMAT_NORMAL, _("plugin missing"));
|
2016-07-01 21:47:01 +02:00
|
|
|
g_string_append_printf (outbuf, "%s, ", tmp);
|
|
|
|
|
g_free (tmp);
|
|
|
|
|
}
|
|
|
|
|
if (nm_device_is_software (device))
|
|
|
|
|
g_string_append_printf (outbuf, "%s, ", _("sw"));
|
|
|
|
|
else
|
|
|
|
|
g_string_append_printf (outbuf, "%s, ", _("hw"));
|
|
|
|
|
|
|
|
|
|
if ( nm_device_get_ip_iface (device)
|
|
|
|
|
&& g_strcmp0 (nm_device_get_ip_iface (device), nm_device_get_iface (device))
|
|
|
|
|
&& g_strcmp0 (nm_device_get_ip_iface (device), ""))
|
|
|
|
|
g_string_append_printf (outbuf, "%s %s,", _("iface"), nm_device_get_ip_iface (device));
|
|
|
|
|
|
|
|
|
|
if (nm_device_get_physical_port_id (device))
|
|
|
|
|
g_string_append_printf (outbuf, "%s %s, ", _("port"), nm_device_get_physical_port_id (device));
|
|
|
|
|
|
|
|
|
|
if (nm_device_get_mtu (device))
|
|
|
|
|
g_string_append_printf (outbuf, "%s %d, ", _("mtu"), nm_device_get_mtu (device));
|
|
|
|
|
|
|
|
|
|
if (outbuf->len >= 2) {
|
|
|
|
|
g_string_truncate (outbuf, outbuf->len - 2);
|
|
|
|
|
g_print ("\t%s\n", outbuf->str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_string_free (outbuf, TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
ac_overview (NmCli *nmc, NMActiveConnection *ac)
|
|
|
|
|
{
|
|
|
|
|
GString *outbuf = g_string_sized_new (80);
|
|
|
|
|
NMIPConfig *ip;
|
|
|
|
|
|
|
|
|
|
if (nm_active_connection_get_master (ac)) {
|
2017-03-16 13:16:57 +00:00
|
|
|
g_string_append_printf (outbuf, "%s %s, ", _("master"),
|
2016-07-01 21:47:01 +02:00
|
|
|
nm_device_get_iface (nm_active_connection_get_master (ac)));
|
|
|
|
|
}
|
|
|
|
|
if (nm_active_connection_get_vpn (ac))
|
|
|
|
|
g_string_append_printf (outbuf, "%s, ", _("VPN"));
|
|
|
|
|
if (nm_active_connection_get_default (ac))
|
|
|
|
|
g_string_append_printf (outbuf, "%s, ", _("ip4 default"));
|
|
|
|
|
if (nm_active_connection_get_default6 (ac))
|
|
|
|
|
g_string_append_printf (outbuf, "%s, ", _("ip6 default"));
|
|
|
|
|
if (outbuf->len >= 2) {
|
|
|
|
|
g_string_truncate (outbuf, outbuf->len - 2);
|
|
|
|
|
g_print ("\t%s\n", outbuf->str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ip = nm_active_connection_get_ip4_config (ac);
|
|
|
|
|
if (ip) {
|
|
|
|
|
const GPtrArray *p;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
p = nm_ip_config_get_addresses (ip);
|
|
|
|
|
for (i = 0; i < p->len; i++) {
|
|
|
|
|
NMIPAddress *a = p->pdata[i];
|
|
|
|
|
g_print ("\tinet4 %s/%d\n", nm_ip_address_get_address (a),
|
|
|
|
|
nm_ip_address_get_prefix (a));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p = nm_ip_config_get_routes (ip);
|
|
|
|
|
for (i = 0; i < p->len; i++) {
|
|
|
|
|
NMIPRoute *a = p->pdata[i];
|
|
|
|
|
g_print ("\troute4 %s/%d\n", nm_ip_route_get_dest (a),
|
|
|
|
|
nm_ip_route_get_prefix (a));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ip = nm_active_connection_get_ip6_config (ac);
|
|
|
|
|
if (ip) {
|
|
|
|
|
const GPtrArray *p;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
p = nm_ip_config_get_addresses (ip);
|
|
|
|
|
for (i = 0; i < p->len; i++) {
|
|
|
|
|
NMIPAddress *a = p->pdata[i];
|
|
|
|
|
g_print ("\tinet6 %s/%d\n", nm_ip_address_get_address (a),
|
|
|
|
|
nm_ip_address_get_prefix (a));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p = nm_ip_config_get_routes (ip);
|
|
|
|
|
for (i = 0; i < p->len; i++) {
|
|
|
|
|
NMIPRoute *a = p->pdata[i];
|
|
|
|
|
g_print ("\troute6 %s/%d\n", nm_ip_route_get_dest (a),
|
|
|
|
|
nm_ip_route_get_prefix (a));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_string_free (outbuf, TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Entry point function for 'nmcli' without arguments.
|
|
|
|
|
*/
|
|
|
|
|
NMCResultCode
|
|
|
|
|
do_overview (NmCli *nmc, int argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
NMDevice **devices;
|
|
|
|
|
const GPtrArray *p;
|
|
|
|
|
NMActiveConnection *ac;
|
2017-04-04 15:12:00 +02:00
|
|
|
NMMetaTermColor color;
|
2016-10-27 09:09:13 +02:00
|
|
|
NMDnsEntry *dns;
|
2016-07-01 21:47:01 +02:00
|
|
|
char *tmp;
|
|
|
|
|
int i;
|
|
|
|
|
|
2017-03-30 16:09:46 +02:00
|
|
|
next_arg (nmc, &argc, &argv, NULL);
|
|
|
|
|
|
2016-07-01 21:47:01 +02:00
|
|
|
/* Register polkit agent */
|
|
|
|
|
nmc_start_polkit_agent_start_try (nmc);
|
|
|
|
|
|
|
|
|
|
/* The VPN connections don't have devices (yet?). */
|
|
|
|
|
p = nm_client_get_active_connections (nmc->client);
|
|
|
|
|
for (i = 0; i < p->len; i++) {
|
|
|
|
|
NMActiveConnectionState state;
|
|
|
|
|
|
|
|
|
|
ac = p->pdata[i];
|
|
|
|
|
|
|
|
|
|
if (!nm_active_connection_get_vpn (ac))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
state = nm_active_connection_get_state (ac);
|
|
|
|
|
nmc_active_connection_state_to_color (state, &color);
|
2017-04-04 15:12:00 +02:00
|
|
|
tmp = nmc_colorize (nmc->nmc_config.use_colors, color, NM_META_TERM_FORMAT_NORMAL, _("%s VPN connection"),
|
2016-07-01 21:47:01 +02:00
|
|
|
nm_active_connection_get_id (ac));
|
|
|
|
|
g_print ("%s\n", tmp);
|
|
|
|
|
g_free (tmp);
|
|
|
|
|
|
|
|
|
|
ac_overview (nmc, ac);
|
|
|
|
|
g_print ("\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
devices = nmc_get_devices_sorted (nmc->client);
|
|
|
|
|
for (i = 0; devices[i]; i++) {
|
2017-04-04 15:12:00 +02:00
|
|
|
NMMetaTermFormat color_fmt;
|
2016-07-01 21:47:01 +02:00
|
|
|
NMDeviceState state;
|
|
|
|
|
|
|
|
|
|
ac = nm_device_get_active_connection (devices[i]);
|
|
|
|
|
|
|
|
|
|
state = nm_device_get_state (devices[i]);
|
|
|
|
|
nmc_device_state_to_color (state, &color, &color_fmt);
|
2017-03-30 12:23:26 +02:00
|
|
|
tmp = nmc_colorize (nmc->nmc_config.use_colors, color, color_fmt, "%s: %s%s%s",
|
2016-07-01 21:47:01 +02:00
|
|
|
nm_device_get_iface (devices[i]),
|
|
|
|
|
nmc_device_state_to_string (state),
|
|
|
|
|
ac ? " to " : "",
|
|
|
|
|
ac ? nm_active_connection_get_id (ac) : "");
|
|
|
|
|
g_print ("%s\n", tmp);
|
|
|
|
|
g_free (tmp);
|
|
|
|
|
|
|
|
|
|
if (nm_device_get_description (devices[i]) && strcmp (nm_device_get_description (devices[i]), ""))
|
|
|
|
|
g_print ("\t\"%s\"\n", nm_device_get_description (devices[i]));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
device_overview (nmc, devices[i]);
|
|
|
|
|
if (ac)
|
|
|
|
|
ac_overview (nmc, ac);
|
|
|
|
|
g_print ("\n");
|
|
|
|
|
}
|
|
|
|
|
g_free (devices);
|
|
|
|
|
|
2016-10-27 09:09:13 +02:00
|
|
|
p = nm_client_get_dns_configuration (nmc->client);
|
|
|
|
|
for (i = 0; p && i < p->len; i++) {
|
|
|
|
|
const char * const *strv;
|
|
|
|
|
|
|
|
|
|
dns = p->pdata[i];
|
|
|
|
|
strv = nm_dns_entry_get_nameservers (dns);
|
|
|
|
|
if (!strv || !strv[0]) {
|
|
|
|
|
/* Invalid entry */
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (i == 0)
|
|
|
|
|
g_print ("DNS configuration:\n");
|
|
|
|
|
|
|
|
|
|
tmp = g_strjoinv (" ", (char **) strv);
|
|
|
|
|
g_print ("\tservers: %s\n", tmp);
|
|
|
|
|
g_free (tmp);
|
|
|
|
|
|
|
|
|
|
strv = nm_dns_entry_get_domains (dns);
|
|
|
|
|
if (strv && strv[0]) {
|
|
|
|
|
tmp = g_strjoinv (" ", (char **) strv);
|
|
|
|
|
g_print ("\tdomains: %s\n", tmp);
|
|
|
|
|
g_free (tmp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (nm_dns_entry_get_interface (dns))
|
|
|
|
|
g_print ("\tinterface: %s\n", nm_dns_entry_get_interface (dns));
|
|
|
|
|
|
|
|
|
|
if (nm_dns_entry_get_vpn (dns))
|
|
|
|
|
g_print ("\ttype: vpn\n");
|
|
|
|
|
g_print ("\n");
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-01 21:47:01 +02:00
|
|
|
g_print (_("Use \"nmcli device show\" to get complete information about known devices and\n"
|
|
|
|
|
"\"nmcli connection show\" to get an overview on active connection profiles.\n"
|
|
|
|
|
"\n"
|
2016-07-20 09:30:33 +02:00
|
|
|
"Consult nmcli(1) and nmcli-examples(5) manual pages for complete usage details.\n"));
|
2016-07-01 21:47:01 +02:00
|
|
|
|
|
|
|
|
return NMC_RESULT_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Entry point function for 'nmcli monitor'
|
|
|
|
|
*/
|
2015-03-27 13:07:43 +01:00
|
|
|
NMCResultCode
|
|
|
|
|
do_monitor (NmCli *nmc, int argc, char **argv)
|
|
|
|
|
{
|
2017-03-30 16:09:46 +02:00
|
|
|
next_arg (nmc, &argc, &argv, NULL);
|
|
|
|
|
|
2016-07-06 14:39:58 +02:00
|
|
|
if (nmc->complete)
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
|
2015-03-27 13:07:43 +01:00
|
|
|
if (argc > 0) {
|
|
|
|
|
if (!nmc_arg_is_help (*argv)) {
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: 'monitor' command '%s' is not valid."), *argv);
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
usage_monitor ();
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-14 16:37:57 +01:00
|
|
|
if (!nm_client_get_nm_running (nmc->client)) {
|
|
|
|
|
char *str;
|
|
|
|
|
|
2017-04-04 15:12:00 +02:00
|
|
|
str = nmc_colorize (nmc->nmc_config.use_colors, NM_META_TERM_COLOR_RED, NM_META_TERM_FORMAT_NORMAL,
|
2015-12-14 16:37:57 +01:00
|
|
|
_("Networkmanager is not running (waiting for it)\n"));
|
|
|
|
|
g_print ("%s", str);
|
|
|
|
|
g_free (str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_signal_connect (nmc->client, "notify::" NM_CLIENT_NM_RUNNING,
|
|
|
|
|
G_CALLBACK (networkmanager_running), nmc);
|
2015-03-27 13:07:43 +01:00
|
|
|
g_signal_connect (nmc->client, "notify::" NM_CLIENT_HOSTNAME,
|
|
|
|
|
G_CALLBACK (client_hostname), nmc);
|
|
|
|
|
g_signal_connect (nmc->client, "notify::" NM_CLIENT_PRIMARY_CONNECTION,
|
|
|
|
|
G_CALLBACK (client_primary_connection), nmc);
|
|
|
|
|
g_signal_connect (nmc->client, "notify::" NM_CLIENT_CONNECTIVITY,
|
|
|
|
|
G_CALLBACK (client_connectivity), nmc);
|
|
|
|
|
g_signal_connect (nmc->client, "notify::" NM_CLIENT_STATE,
|
|
|
|
|
G_CALLBACK (client_state), nmc);
|
|
|
|
|
|
|
|
|
|
nmc->should_wait++;
|
|
|
|
|
|
|
|
|
|
monitor_devices (nmc);
|
|
|
|
|
monitor_connections (nmc);
|
|
|
|
|
|
|
|
|
|
return NMC_RESULT_SUCCESS;
|
|
|
|
|
}
|