networkctl.c revision 266b538958932e6fc27dfce4917336e70e17e29e
d29201dd5328b88140ce050100693c501852657dChristian Maeder/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
7165a916d2fa1bf87c4741ec63b253413eebbf69Karl Luc This file is part of systemd.
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu Prodescu Copyright 2014 Lennart Poettering
7165a916d2fa1bf87c4741ec63b253413eebbf69Karl Luc systemd is free software; you can redistribute it and/or modify it
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder under the terms of the GNU Lesser General Public License as published by
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder the Free Software Foundation; either version 2.1 of the License, or
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder (at your option) any later version.
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder systemd is distributed in the hope that it will be useful, but
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder WITHOUT ANY WARRANTY; without even the implied warranty of
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder Lesser General Public License for more details.
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder You should have received a copy of the GNU Lesser General Public License
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder along with systemd; If not, see <http://www.gnu.org/licenses/>.
75067b1beba1380cde707c30e7fc050d86f6927fKarl Lucstatic bool arg_no_pager = false;
75067b1beba1380cde707c30e7fc050d86f6927fKarl Lucstatic bool arg_legend = true;
75067b1beba1380cde707c30e7fc050d86f6927fKarl Lucstatic bool arg_all = false;
75067b1beba1380cde707c30e7fc050d86f6927fKarl Lucstatic void pager_open_if_enabled(void) {
551f1476dea3f969775527cb15fd512e86279307Karl Lucstatic int link_get_type_string(int iftype, struct udev_device *d, char **ret) {
75067b1beba1380cde707c30e7fc050d86f6927fKarl Luc const char *t;
7165a916d2fa1bf87c4741ec63b253413eebbf69Karl Luc /* WLANs have iftype ARPHRD_ETHER, but we want
c51d1f5ff88cce030fe543e271ca6b85625b70d8Karl Luc * to show a more useful type string for
de03ed90ff6efbbc4751301bcf6b50d9790c1afbKarl Luctypedef struct LinkInfo {
7165a916d2fa1bf87c4741ec63b253413eebbf69Karl Luc const char *name;
de03ed90ff6efbbc4751301bcf6b50d9790c1afbKarl Lucstatic int link_info_compare(const void *a, const void *b) {
de03ed90ff6efbbc4751301bcf6b50d9790c1afbKarl Luc const LinkInfo *x = a, *y = b;
75067b1beba1380cde707c30e7fc050d86f6927fKarl Lucstatic int decode_and_sort_links(sd_rtnl_message *m, LinkInfo **ret) {
75067b1beba1380cde707c30e7fc050d86f6927fKarl Luc for (i = m; i; i = sd_rtnl_message_next(i)) {
75067b1beba1380cde707c30e7fc050d86f6927fKarl Luc const char *name;
int ifindex;
return -ENOMEM;
if (!udev)
return rtnl_log_create_error(r);
return rtnl_log_create_error(r);
if (arg_legend)
return rtnl_log_parse_error(c);
if (arg_legend)
const char *description;
if (!hwdb)
return -EINVAL;
if (!mac)
return -EINVAL;
return -EINVAL;
if (!desc)
return -ENOMEM;
static int get_gateway_description(
int ifindex,
int family,
char **gateway_description) {
sd_rtnl_message *m;
r = sd_rtnl_message_get_errno(m);
switch (fam) {
case AF_INET:
case AF_INET6:
return -ENODATA;
static int dump_gateways(
const char *prefix,
int ifindex) {
r = get_gateway_description(rtnl, hwdb, local[i].ifindex, local[i].family, &local[i].address, &description);
gateway);
if (description)
if (ifindex <= 0) {
static int dump_addresses(
const char *prefix,
int ifindex) {
pretty);
if (ifindex <= 0) {
STRV_FOREACH(i, l) {
static int link_status_one(
const char *name) {
struct ether_addr e;
unsigned iftype;
int r, ifindex;
bool have_mac;
return rtnl_log_create_error(r);
return rtnl_log_create_error(r);
return rtnl_log_parse_error(r);
return rtnl_log_parse_error(r);
return rtnl_log_parse_error(r);
if (have_mac) {
const uint8_t *p;
bool all_zeroes = true;
all_zeroes = false;
if (all_zeroes)
have_mac = false;
char *wildcard;
if (!wildcard)
return log_oom();
return log_oom();
if (!vendor)
if (!model)
printf("%s%s%s %i: %s\n", on_color_operational, draw_special_char(DRAW_BLACK_CIRCLE), off_color_operational, ifindex, name);
strna(t),
if (path)
if (driver)
if (vendor)
if (model)
if (have_mac) {
if (description)
if (mtu > 0)
char **name;
if (!udev)
if (arg_all) {
return rtnl_log_create_error(r);
return rtnl_log_create_error(r);
return rtnl_log_parse_error(c);
static void help(void) {
help();
case ARG_VERSION:
case ARG_NO_PAGER:
arg_no_pager = true;
case ARG_NO_LEGEND:
arg_legend = false;
arg_all = true;
return -EINVAL;
log_open();
goto finish;
pager_close();