1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
5 #include <linux/if_addrlabel.h>
11 #include <linux/if_bridge.h>
12 #include <linux/if_tunnel.h>
15 #include "sd-device.h"
16 #include "sd-dhcp-client.h"
18 #include "sd-netlink.h"
19 #include "sd-network.h"
21 #include "alloc-util.h"
22 #include "bond-util.h"
23 #include "bridge-util.h"
25 #include "bus-common-errors.h"
26 #include "bus-error.h"
27 #include "bus-locator.h"
28 #include "device-util.h"
30 #include "ether-addr-util.h"
31 #include "ethtool-util.h"
33 #include "format-table.h"
34 #include "format-util.h"
36 #include "geneve-util.h"
37 #include "glob-util.h"
38 #include "hwdb-util.h"
39 #include "ipvlan-util.h"
40 #include "local-addresses.h"
41 #include "locale-util.h"
42 #include "logs-show.h"
44 #include "macvlan-util.h"
45 #include "main-func.h"
46 #include "netif-util.h"
47 #include "netlink-util.h"
48 #include "network-internal.h"
49 #include "network-util.h"
50 #include "networkctl.h"
51 #include "networkctl-config-file.h"
53 #include "parse-argument.h"
54 #include "parse-util.h"
55 #include "path-lookup.h"
56 #include "path-util.h"
57 #include "pretty-print.h"
60 #include "socket-netlink.h"
61 #include "socket-util.h"
62 #include "sort-util.h"
63 #include "sparse-endian.h"
64 #include "stdio-util.h"
65 #include "string-table.h"
66 #include "string-util.h"
69 #include "terminal-util.h"
70 #include "udev-util.h"
74 #include "wifi-util.h"
76 /* Kernel defines MODULE_NAME_LEN as 64 - sizeof(unsigned long). So, 64 is enough. */
77 #define NETDEV_KIND_MAX 64
79 /* use 128 kB for receive socket kernel queue, we shouldn't need more here */
80 #define RCVBUF_SIZE (128*1024)
82 PagerFlags arg_pager_flags
= 0;
83 bool arg_legend
= true;
84 bool arg_no_reload
= false;
86 bool arg_stats
= false;
87 bool arg_full
= false;
88 bool arg_runtime
= false;
89 unsigned arg_lines
= 10;
90 char *arg_drop_in
= NULL
;
91 JsonFormatFlags arg_json_format_flags
= JSON_FORMAT_OFF
;
93 STATIC_DESTRUCTOR_REGISTER(arg_drop_in
, freep
);
95 static int varlink_connect_networkd(Varlink
**ret_varlink
) {
96 _cleanup_(varlink_unrefp
) Varlink
*vl
= NULL
;
101 r
= varlink_connect_address(&vl
, "/run/systemd/netif/io.systemd.Network");
103 return log_error_errno(r
, "Failed to connect to network service /run/systemd/netif/io.systemd.Network: %m");
105 r
= varlink_set_allow_fd_passing_output(vl
, true);
107 return log_error_errno(r
, "Failed to allow passing file descriptor through varlink: %m");
109 r
= varlink_call_and_log(vl
, "io.systemd.Network.GetNamespaceId", /* parameters= */ NULL
, &reply
);
113 static const JsonDispatch dispatch_table
[] = {
114 { "NamespaceId", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, 0, JSON_MANDATORY
},
118 r
= json_dispatch(reply
, dispatch_table
, JSON_LOG
|JSON_ALLOW_EXTENSIONS
, &id
);
123 log_debug("systemd-networkd.service not running in a network namespace (?), skipping netns check.");
127 if (stat("/proc/self/ns/net", &st
) < 0)
128 return log_error_errno(errno
, "Failed to determine our own network namespace ID: %m");
131 return log_error_errno(SYNTHETIC_ERRNO(EREMOTE
),
132 "networkctl must be invoked in same network namespace as systemd-networkd.service.");
136 *ret_varlink
= TAKE_PTR(vl
);
140 bool networkd_is_running(void) {
141 static int cached
= -1;
145 r
= access("/run/systemd/netif/state", F_OK
);
148 log_debug_errno(errno
,
149 "Failed to determine whether networkd is running, assuming it's not: %m");
159 int acquire_bus(sd_bus
**ret
) {
160 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
165 r
= sd_bus_open_system(&bus
);
167 return log_error_errno(r
, "Failed to connect to system bus: %m");
169 if (networkd_is_running()) {
170 r
= varlink_connect_networkd(/* ret_varlink = */ NULL
);
174 log_warning("systemd-networkd is not running, output might be incomplete.");
176 *ret
= TAKE_PTR(bus
);
180 static int get_description(sd_bus
*bus
, JsonVariant
**ret
) {
181 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
182 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
189 r
= bus_call_method(bus
, bus_network_mgr
, "Describe", &error
, &reply
, NULL
);
191 return log_error_errno(r
, "Failed to get description: %s", bus_error_message(&error
, r
));
193 r
= sd_bus_message_read(reply
, "s", &text
);
195 return bus_log_parse_error(r
);
197 r
= json_parse(text
, 0, ret
, NULL
, NULL
);
199 return log_error_errno(r
, "Failed to parse JSON: %m");
204 static int dump_manager_description(sd_bus
*bus
) {
205 _cleanup_(json_variant_unrefp
) JsonVariant
*v
= NULL
;
210 r
= get_description(bus
, &v
);
214 json_variant_dump(v
, arg_json_format_flags
, NULL
, NULL
);
218 static int dump_link_description(sd_bus
*bus
, char * const *patterns
) {
219 _cleanup_(json_variant_unrefp
) JsonVariant
*v
= NULL
;
220 _cleanup_free_
bool *matched_patterns
= NULL
;
228 r
= get_description(bus
, &v
);
232 matched_patterns
= new0(bool, strv_length(patterns
));
233 if (!matched_patterns
)
236 JSON_VARIANT_ARRAY_FOREACH(i
, json_variant_by_key(v
, "Interfaces")) {
237 char ifindex_str
[DECIMAL_STR_MAX(int64_t)];
242 name
= json_variant_string(json_variant_by_key(i
, "Name"));
243 index
= json_variant_integer(json_variant_by_key(i
, "Index"));
244 xsprintf(ifindex_str
, "%" PRIi64
, index
);
246 if (!strv_fnmatch_full(patterns
, ifindex_str
, 0, &pos
) &&
247 !strv_fnmatch_full(patterns
, name
, 0, &pos
)) {
251 JSON_VARIANT_ARRAY_FOREACH(a
, json_variant_by_key(i
, "AlternativeNames"))
252 if (strv_fnmatch_full(patterns
, json_variant_string(a
), 0, &pos
)) {
261 matched_patterns
[pos
] = true;
262 json_variant_dump(i
, arg_json_format_flags
, NULL
, NULL
);
266 /* Look if we matched all our arguments that are not globs. It is OK for a glob to match
267 * nothing, but not for an exact argument. */
268 for (size_t pos
= 0; pos
< strv_length(patterns
); pos
++) {
269 if (matched_patterns
[pos
])
272 if (string_is_glob(patterns
[pos
]))
273 log_debug("Pattern \"%s\" doesn't match any interface, ignoring.",
276 return log_error_errno(SYNTHETIC_ERRNO(ENODEV
),
277 "Interface \"%s\" not found.", patterns
[pos
]);
281 log_warning("No interfaces matched.");
286 static void operational_state_to_color(
292 if (STRPTR_IN_SET(state
, "routable", "enslaved") ||
293 (streq_ptr(name
, "lo") && streq_ptr(state
, "carrier"))) {
295 *on
= ansi_highlight_green();
297 *off
= ansi_normal();
298 } else if (streq_ptr(state
, "degraded")) {
300 *on
= ansi_highlight_yellow();
302 *off
= ansi_normal();
311 static void setup_state_to_color(const char *state
, const char **on
, const char **off
) {
312 if (streq_ptr(state
, "configured")) {
314 *on
= ansi_highlight_green();
316 *off
= ansi_normal();
317 } else if (streq_ptr(state
, "configuring")) {
319 *on
= ansi_highlight_yellow();
321 *off
= ansi_normal();
322 } else if (STRPTR_IN_SET(state
, "failed", "linger")) {
324 *on
= ansi_highlight_red();
326 *off
= ansi_normal();
335 static void online_state_to_color(const char *state
, const char **on
, const char **off
) {
336 if (streq_ptr(state
, "online")) {
338 *on
= ansi_highlight_green();
340 *off
= ansi_normal();
341 } else if (streq_ptr(state
, "partial")) {
343 *on
= ansi_highlight_yellow();
345 *off
= ansi_normal();
354 typedef struct VxLanInfo
{
361 union in_addr_union local
;
362 union in_addr_union group
;
375 typedef struct LinkInfo
{
376 char name
[IFNAMSIZ
+1];
378 sd_device
*sd_device
;
380 unsigned short iftype
;
381 struct hw_addr_data hw_address
;
382 struct hw_addr_data permanent_hw_address
;
389 uint8_t addr_gen_mode
;
391 char **alternative_names
;
394 struct rtnl_link_stats64 stats64
;
395 struct rtnl_link_stats stats
;
402 uint32_t forward_delay
;
405 uint32_t ageing_time
;
409 uint8_t mcast_igmp_version
;
413 VxLanInfo vxlan_info
;
426 uint16_t tunnel_port
;
429 union in_addr_union local
;
430 union in_addr_union remote
;
438 /* macvlan and macvtap info */
439 uint32_t macvlan_mode
;
442 uint16_t ipvlan_mode
;
443 uint16_t ipvlan_flags
;
452 enum nl80211_iftype wlan_iftype
;
454 struct ether_addr bssid
;
456 bool has_hw_address
:1;
457 bool has_permanent_hw_address
:1;
458 bool has_tx_queues
:1;
459 bool has_rx_queues
:1;
463 bool has_ethtool_link_info
:1;
464 bool has_wlan_link_info
:1;
465 bool has_tunnel_ipv4
:1;
466 bool has_ipv6_address_generation_mode
:1;
468 bool needs_freeing
:1;
471 static int link_info_compare(const LinkInfo
*a
, const LinkInfo
*b
) {
472 return CMP(a
->ifindex
, b
->ifindex
);
475 static LinkInfo
* link_info_array_free(LinkInfo
*array
) {
476 for (unsigned i
= 0; array
&& array
[i
].needs_freeing
; i
++) {
477 sd_device_unref(array
[i
].sd_device
);
478 free(array
[i
].netdev_kind
);
480 free(array
[i
].qdisc
);
481 strv_free(array
[i
].alternative_names
);
486 DEFINE_TRIVIAL_CLEANUP_FUNC(LinkInfo
*, link_info_array_free
);
488 static int decode_netdev(sd_netlink_message
*m
, LinkInfo
*info
) {
494 r
= sd_netlink_message_enter_container(m
, IFLA_LINKINFO
);
498 r
= sd_netlink_message_read_string_strdup(m
, IFLA_INFO_KIND
, &info
->netdev_kind
);
500 (void) sd_netlink_message_exit_container(m
);
504 r
= sd_netlink_message_enter_container(m
, IFLA_INFO_DATA
);
508 if (streq(info
->netdev_kind
, "bridge")) {
509 (void) sd_netlink_message_read_u32(m
, IFLA_BR_FORWARD_DELAY
, &info
->forward_delay
);
510 (void) sd_netlink_message_read_u32(m
, IFLA_BR_HELLO_TIME
, &info
->hello_time
);
511 (void) sd_netlink_message_read_u32(m
, IFLA_BR_MAX_AGE
, &info
->max_age
);
512 (void) sd_netlink_message_read_u32(m
, IFLA_BR_AGEING_TIME
, &info
->ageing_time
);
513 (void) sd_netlink_message_read_u32(m
, IFLA_BR_STP_STATE
, &info
->stp_state
);
514 (void) sd_netlink_message_read_u32(m
, IFLA_BRPORT_COST
, &info
->cost
);
515 (void) sd_netlink_message_read_u16(m
, IFLA_BR_PRIORITY
, &info
->priority
);
516 (void) sd_netlink_message_read_u8(m
, IFLA_BR_MCAST_IGMP_VERSION
, &info
->mcast_igmp_version
);
517 (void) sd_netlink_message_read_u8(m
, IFLA_BRPORT_STATE
, &info
->port_state
);
518 } if (streq(info
->netdev_kind
, "bond")) {
519 (void) sd_netlink_message_read_u8(m
, IFLA_BOND_MODE
, &info
->mode
);
520 (void) sd_netlink_message_read_u32(m
, IFLA_BOND_MIIMON
, &info
->miimon
);
521 (void) sd_netlink_message_read_u32(m
, IFLA_BOND_DOWNDELAY
, &info
->downdelay
);
522 (void) sd_netlink_message_read_u32(m
, IFLA_BOND_UPDELAY
, &info
->updelay
);
523 } else if (streq(info
->netdev_kind
, "vxlan")) {
524 (void) sd_netlink_message_read_u32(m
, IFLA_VXLAN_ID
, &info
->vxlan_info
.vni
);
526 r
= sd_netlink_message_read_in_addr(m
, IFLA_VXLAN_GROUP
, &info
->vxlan_info
.group
.in
);
528 info
->vxlan_info
.group_family
= AF_INET
;
530 r
= sd_netlink_message_read_in6_addr(m
, IFLA_VXLAN_GROUP6
, &info
->vxlan_info
.group
.in6
);
532 info
->vxlan_info
.group_family
= AF_INET6
;
535 r
= sd_netlink_message_read_in_addr(m
, IFLA_VXLAN_LOCAL
, &info
->vxlan_info
.local
.in
);
537 info
->vxlan_info
.local_family
= AF_INET
;
539 r
= sd_netlink_message_read_in6_addr(m
, IFLA_VXLAN_LOCAL6
, &info
->vxlan_info
.local
.in6
);
541 info
->vxlan_info
.local_family
= AF_INET6
;
544 (void) sd_netlink_message_read_u32(m
, IFLA_VXLAN_LINK
, &info
->vxlan_info
.link
);
545 (void) sd_netlink_message_read_u16(m
, IFLA_VXLAN_PORT
, &info
->vxlan_info
.dest_port
);
546 (void) sd_netlink_message_read_u8(m
, IFLA_VXLAN_PROXY
, &info
->vxlan_info
.proxy
);
547 (void) sd_netlink_message_read_u8(m
, IFLA_VXLAN_LEARNING
, &info
->vxlan_info
.learning
);
548 (void) sd_netlink_message_read_u8(m
, IFLA_VXLAN_RSC
, &info
->vxlan_info
.rsc
);
549 (void) sd_netlink_message_read_u8(m
, IFLA_VXLAN_L3MISS
, &info
->vxlan_info
.l3miss
);
550 (void) sd_netlink_message_read_u8(m
, IFLA_VXLAN_L2MISS
, &info
->vxlan_info
.l2miss
);
551 (void) sd_netlink_message_read_u8(m
, IFLA_VXLAN_TOS
, &info
->vxlan_info
.tos
);
552 (void) sd_netlink_message_read_u8(m
, IFLA_VXLAN_TTL
, &info
->vxlan_info
.ttl
);
553 } else if (streq(info
->netdev_kind
, "vlan"))
554 (void) sd_netlink_message_read_u16(m
, IFLA_VLAN_ID
, &info
->vlan_id
);
555 else if (STR_IN_SET(info
->netdev_kind
, "ipip", "sit")) {
556 (void) sd_netlink_message_read_in_addr(m
, IFLA_IPTUN_LOCAL
, &info
->local
.in
);
557 (void) sd_netlink_message_read_in_addr(m
, IFLA_IPTUN_REMOTE
, &info
->remote
.in
);
558 } else if (streq(info
->netdev_kind
, "geneve")) {
559 (void) sd_netlink_message_read_u32(m
, IFLA_GENEVE_ID
, &info
->vni
);
561 r
= sd_netlink_message_read_in_addr(m
, IFLA_GENEVE_REMOTE
, &info
->remote
.in
);
563 info
->has_tunnel_ipv4
= true;
565 (void) sd_netlink_message_read_in6_addr(m
, IFLA_GENEVE_REMOTE6
, &info
->remote
.in6
);
567 (void) sd_netlink_message_read_u8(m
, IFLA_GENEVE_TTL
, &info
->ttl
);
568 (void) sd_netlink_message_read_u8(m
, IFLA_GENEVE_TTL_INHERIT
, &info
->inherit
);
569 (void) sd_netlink_message_read_u8(m
, IFLA_GENEVE_TOS
, &info
->tos
);
570 (void) sd_netlink_message_read_u8(m
, IFLA_GENEVE_DF
, &info
->df
);
571 (void) sd_netlink_message_read_u8(m
, IFLA_GENEVE_UDP_CSUM
, &info
->csum
);
572 (void) sd_netlink_message_read_u8(m
, IFLA_GENEVE_UDP_ZERO_CSUM6_TX
, &info
->csum6_tx
);
573 (void) sd_netlink_message_read_u8(m
, IFLA_GENEVE_UDP_ZERO_CSUM6_RX
, &info
->csum6_rx
);
574 (void) sd_netlink_message_read_u16(m
, IFLA_GENEVE_PORT
, &info
->tunnel_port
);
575 (void) sd_netlink_message_read_u32(m
, IFLA_GENEVE_LABEL
, &info
->label
);
576 } else if (STR_IN_SET(info
->netdev_kind
, "gre", "gretap", "erspan")) {
577 (void) sd_netlink_message_read_in_addr(m
, IFLA_GRE_LOCAL
, &info
->local
.in
);
578 (void) sd_netlink_message_read_in_addr(m
, IFLA_GRE_REMOTE
, &info
->remote
.in
);
579 } else if (STR_IN_SET(info
->netdev_kind
, "ip6gre", "ip6gretap", "ip6erspan")) {
580 (void) sd_netlink_message_read_in6_addr(m
, IFLA_GRE_LOCAL
, &info
->local
.in6
);
581 (void) sd_netlink_message_read_in6_addr(m
, IFLA_GRE_REMOTE
, &info
->remote
.in6
);
582 } else if (streq(info
->netdev_kind
, "vti")) {
583 (void) sd_netlink_message_read_in_addr(m
, IFLA_VTI_LOCAL
, &info
->local
.in
);
584 (void) sd_netlink_message_read_in_addr(m
, IFLA_VTI_REMOTE
, &info
->remote
.in
);
585 } else if (streq(info
->netdev_kind
, "vti6")) {
586 (void) sd_netlink_message_read_in6_addr(m
, IFLA_VTI_LOCAL
, &info
->local
.in6
);
587 (void) sd_netlink_message_read_in6_addr(m
, IFLA_VTI_REMOTE
, &info
->remote
.in6
);
588 } else if (STR_IN_SET(info
->netdev_kind
, "macvlan", "macvtap"))
589 (void) sd_netlink_message_read_u32(m
, IFLA_MACVLAN_MODE
, &info
->macvlan_mode
);
590 else if (streq(info
->netdev_kind
, "ipvlan")) {
591 (void) sd_netlink_message_read_u16(m
, IFLA_IPVLAN_MODE
, &info
->ipvlan_mode
);
592 (void) sd_netlink_message_read_u16(m
, IFLA_IPVLAN_FLAGS
, &info
->ipvlan_flags
);
595 (void) sd_netlink_message_exit_container(m
);
596 (void) sd_netlink_message_exit_container(m
);
601 static int decode_link(
602 sd_netlink_message
*m
,
604 char * const *patterns
,
605 bool matched_patterns
[]) {
607 _cleanup_strv_free_
char **altnames
= NULL
;
608 const char *name
, *qdisc
;
615 r
= sd_netlink_message_get_type(m
, &type
);
619 if (type
!= RTM_NEWLINK
)
622 r
= sd_rtnl_message_link_get_ifindex(m
, &ifindex
);
626 r
= sd_netlink_message_read_string(m
, IFLA_IFNAME
, &name
);
630 r
= sd_netlink_message_read_strv(m
, IFLA_PROP_LIST
, IFLA_ALT_IFNAME
, &altnames
);
631 if (r
< 0 && r
!= -ENODATA
)
635 char str
[DECIMAL_STR_MAX(int)];
638 assert(matched_patterns
);
640 xsprintf(str
, "%i", ifindex
);
641 if (!strv_fnmatch_full(patterns
, str
, 0, &pos
) &&
642 !strv_fnmatch_full(patterns
, name
, 0, &pos
)) {
645 STRV_FOREACH(p
, altnames
)
646 if (strv_fnmatch_full(patterns
, *p
, 0, &pos
)) {
654 matched_patterns
[pos
] = true;
657 r
= sd_rtnl_message_link_get_type(m
, &info
->iftype
);
661 strscpy(info
->name
, sizeof info
->name
, name
);
662 info
->ifindex
= ifindex
;
663 info
->alternative_names
= TAKE_PTR(altnames
);
665 info
->has_hw_address
=
666 netlink_message_read_hw_addr(m
, IFLA_ADDRESS
, &info
->hw_address
) >= 0 &&
667 info
->hw_address
.length
> 0;
669 info
->has_permanent_hw_address
=
670 (netlink_message_read_hw_addr(m
, IFLA_PERM_ADDRESS
, &info
->permanent_hw_address
) >= 0 ||
671 ethtool_get_permanent_hw_addr(NULL
, info
->name
, &info
->permanent_hw_address
) >= 0) &&
672 !hw_addr_is_null(&info
->permanent_hw_address
) &&
673 !hw_addr_equal(&info
->permanent_hw_address
, &info
->hw_address
);
675 (void) sd_netlink_message_read_u32(m
, IFLA_MTU
, &info
->mtu
);
676 (void) sd_netlink_message_read_u32(m
, IFLA_MIN_MTU
, &info
->min_mtu
);
677 (void) sd_netlink_message_read_u32(m
, IFLA_MAX_MTU
, &info
->max_mtu
);
679 info
->has_rx_queues
=
680 sd_netlink_message_read_u32(m
, IFLA_NUM_RX_QUEUES
, &info
->rx_queues
) >= 0 &&
683 info
->has_tx_queues
=
684 sd_netlink_message_read_u32(m
, IFLA_NUM_TX_QUEUES
, &info
->tx_queues
) >= 0 &&
687 if (sd_netlink_message_read(m
, IFLA_STATS64
, sizeof info
->stats64
, &info
->stats64
) >= 0)
688 info
->has_stats64
= true;
689 else if (sd_netlink_message_read(m
, IFLA_STATS
, sizeof info
->stats
, &info
->stats
) >= 0)
690 info
->has_stats
= true;
692 r
= sd_netlink_message_read_string(m
, IFLA_QDISC
, &qdisc
);
694 info
->qdisc
= strdup(qdisc
);
699 (void) sd_netlink_message_read_u32(m
, IFLA_MASTER
, &info
->master
);
701 r
= sd_netlink_message_enter_container(m
, IFLA_AF_SPEC
);
703 r
= sd_netlink_message_enter_container(m
, AF_INET6
);
705 r
= sd_netlink_message_read_u8(m
, IFLA_INET6_ADDR_GEN_MODE
, &info
->addr_gen_mode
);
706 if (r
>= 0 && IN_SET(info
->addr_gen_mode
,
707 IN6_ADDR_GEN_MODE_EUI64
,
708 IN6_ADDR_GEN_MODE_NONE
,
709 IN6_ADDR_GEN_MODE_STABLE_PRIVACY
,
710 IN6_ADDR_GEN_MODE_RANDOM
))
711 info
->has_ipv6_address_generation_mode
= true;
713 (void) sd_netlink_message_exit_container(m
);
715 (void) sd_netlink_message_exit_container(m
);
719 (void) decode_netdev(m
, info
);
724 static int link_get_property(
726 const LinkInfo
*link
,
728 sd_bus_message
**reply
,
730 const char *propname
,
733 _cleanup_free_
char *path
= NULL
;
734 char ifindex_str
[DECIMAL_STR_MAX(int)];
739 assert(link
->ifindex
>= 0);
746 xsprintf(ifindex_str
, "%i", link
->ifindex
);
748 r
= sd_bus_path_encode("/org/freedesktop/network1/link", ifindex_str
, &path
);
752 return sd_bus_get_property(bus
, "org.freedesktop.network1", path
, iface
, propname
, error
, reply
, type
);
755 static int acquire_link_bitrates(sd_bus
*bus
, LinkInfo
*link
) {
756 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
757 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
763 r
= link_get_property(bus
, link
, &error
, &reply
, "org.freedesktop.network1.Link", "BitRates", "(tt)");
765 bool quiet
= sd_bus_error_has_names(&error
, SD_BUS_ERROR_UNKNOWN_PROPERTY
,
766 BUS_ERROR_SPEED_METER_INACTIVE
);
768 return log_full_errno(quiet
? LOG_DEBUG
: LOG_WARNING
,
769 r
, "Failed to query link bit rates: %s", bus_error_message(&error
, r
));
772 r
= sd_bus_message_read(reply
, "(tt)", &link
->tx_bitrate
, &link
->rx_bitrate
);
774 return bus_log_parse_error(r
);
776 r
= sd_bus_message_exit_container(reply
);
778 return bus_log_parse_error(r
);
780 link
->has_bitrates
= link
->tx_bitrate
!= UINT64_MAX
&& link
->rx_bitrate
!= UINT64_MAX
;
785 static void acquire_ether_link_info(int *fd
, LinkInfo
*link
) {
789 if (ethtool_get_link_info(fd
,
791 &link
->autonegotiation
,
795 link
->has_ethtool_link_info
= true;
798 static void acquire_wlan_link_info(LinkInfo
*link
) {
799 _cleanup_(sd_netlink_unrefp
) sd_netlink
*genl
= NULL
;
804 if (!link
->sd_device
)
807 if (!device_is_devtype(link
->sd_device
, "wlan"))
810 r
= sd_genl_socket_open(&genl
);
812 log_debug_errno(r
, "Failed to open generic netlink socket: %m");
816 (void) sd_netlink_increase_rxbuf(genl
, RCVBUF_SIZE
);
818 r
= wifi_get_interface(genl
, link
->ifindex
, &link
->wlan_iftype
, &link
->ssid
);
820 log_debug_errno(r
, "%s: failed to query ssid: %m", link
->name
);
822 if (link
->wlan_iftype
== NL80211_IFTYPE_STATION
) {
823 k
= wifi_get_station(genl
, link
->ifindex
, &link
->bssid
);
825 log_debug_errno(k
, "%s: failed to query bssid: %m", link
->name
);
828 link
->has_wlan_link_info
= r
> 0 || k
> 0;
831 static int acquire_link_info(sd_bus
*bus
, sd_netlink
*rtnl
, char * const *patterns
, LinkInfo
**ret
) {
832 _cleanup_(sd_netlink_message_unrefp
) sd_netlink_message
*req
= NULL
, *reply
= NULL
;
833 _cleanup_(link_info_array_freep
) LinkInfo
*links
= NULL
;
834 _cleanup_free_
bool *matched_patterns
= NULL
;
835 _cleanup_close_
int fd
= -EBADF
;
842 r
= sd_rtnl_message_new_link(rtnl
, &req
, RTM_GETLINK
, 0);
844 return rtnl_log_create_error(r
);
846 r
= sd_netlink_message_set_request_dump(req
, true);
848 return rtnl_log_create_error(r
);
850 r
= sd_netlink_call(rtnl
, req
, 0, &reply
);
852 return log_error_errno(r
, "Failed to enumerate links: %m");
855 matched_patterns
= new0(bool, strv_length(patterns
));
856 if (!matched_patterns
)
860 for (sd_netlink_message
*i
= reply
; i
; i
= sd_netlink_message_next(i
)) {
861 if (!GREEDY_REALLOC0(links
, c
+ 2)) /* We keep one trailing one as marker */
864 r
= decode_link(i
, links
+ c
, patterns
, matched_patterns
);
870 links
[c
].needs_freeing
= true;
872 (void) sd_device_new_from_ifindex(&links
[c
].sd_device
, links
[c
].ifindex
);
874 acquire_ether_link_info(&fd
, &links
[c
]);
875 acquire_wlan_link_info(&links
[c
]);
880 /* Look if we matched all our arguments that are not globs. It
881 * is OK for a glob to match nothing, but not for an exact argument. */
882 for (size_t pos
= 0; pos
< strv_length(patterns
); pos
++) {
883 if (matched_patterns
[pos
])
886 if (string_is_glob(patterns
[pos
]))
887 log_debug("Pattern \"%s\" doesn't match any interface, ignoring.",
890 return log_error_errno(SYNTHETIC_ERRNO(ENODEV
),
891 "Interface \"%s\" not found.", patterns
[pos
]);
894 typesafe_qsort(links
, c
, link_info_compare
);
897 FOREACH_ARRAY(link
, links
, c
)
898 (void) acquire_link_bitrates(bus
, link
);
900 *ret
= TAKE_PTR(links
);
902 if (patterns
&& c
== 0)
903 log_warning("No interfaces matched.");
908 static int list_links(int argc
, char *argv
[], void *userdata
) {
909 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
910 _cleanup_(sd_netlink_unrefp
) sd_netlink
*rtnl
= NULL
;
911 _cleanup_(link_info_array_freep
) LinkInfo
*links
= NULL
;
912 _cleanup_(table_unrefp
) Table
*table
= NULL
;
916 r
= acquire_bus(&bus
);
920 if (arg_json_format_flags
!= JSON_FORMAT_OFF
) {
921 if (arg_all
|| argc
<= 1)
922 return dump_manager_description(bus
);
924 return dump_link_description(bus
, strv_skip(argv
, 1));
927 r
= sd_netlink_open(&rtnl
);
929 return log_error_errno(r
, "Failed to connect to netlink: %m");
931 c
= acquire_link_info(NULL
, rtnl
, argc
> 1 ? argv
+ 1 : NULL
, &links
);
935 pager_open(arg_pager_flags
);
937 table
= table_new("idx", "link", "type", "operational", "setup");
942 table_set_width(table
, 0);
944 table_set_header(table
, arg_legend
);
945 table_set_ersatz_string(table
, TABLE_ERSATZ_DASH
);
947 assert_se(cell
= table_get_cell(table
, 0, 0));
948 (void) table_set_minimum_width(table
, cell
, 3);
949 (void) table_set_weight(table
, cell
, 0);
950 (void) table_set_ellipsize_percent(table
, cell
, 100);
951 (void) table_set_align_percent(table
, cell
, 100);
953 assert_se(cell
= table_get_cell(table
, 0, 1));
954 (void) table_set_ellipsize_percent(table
, cell
, 100);
956 FOREACH_ARRAY(link
, links
, c
) {
957 _cleanup_free_
char *setup_state
= NULL
, *operational_state
= NULL
;
958 _cleanup_free_
char *t
= NULL
;
959 const char *on_color_operational
, *on_color_setup
;
961 (void) sd_network_link_get_operational_state(link
->ifindex
, &operational_state
);
962 operational_state_to_color(link
->name
, operational_state
, &on_color_operational
, NULL
);
964 (void) sd_network_link_get_setup_state(link
->ifindex
, &setup_state
);
965 setup_state_to_color(setup_state
, &on_color_setup
, NULL
);
967 r
= net_get_type_string(link
->sd_device
, link
->iftype
, &t
);
971 r
= table_add_many(table
,
972 TABLE_INT
, link
->ifindex
,
973 TABLE_STRING
, link
->name
,
975 TABLE_STRING
, operational_state
,
976 TABLE_SET_COLOR
, on_color_operational
,
977 TABLE_STRING
, setup_state
?: "unmanaged",
978 TABLE_SET_COLOR
, on_color_setup
);
980 return table_log_add_error(r
);
983 r
= table_print(table
, NULL
);
985 return table_log_print_error(r
);
988 printf("\n%i links listed.\n", c
);
993 /* IEEE Organizationally Unique Identifier vendor string */
994 static int ieee_oui(sd_hwdb
*hwdb
, const struct ether_addr
*mac
, char **ret
) {
995 _cleanup_free_
char *desc
= NULL
;
996 const char *description
;
997 char modalias
[STRLEN("OUI:XXYYXXYYXXYY") + 1];
1005 /* skip commonly misused 00:00:00 (Xerox) prefix */
1006 if (memcmp(mac
, "\0\0\0", 3) == 0)
1009 xsprintf(modalias
, "OUI:" ETHER_ADDR_FORMAT_STR
, ETHER_ADDR_FORMAT_VAL(*mac
));
1011 r
= sd_hwdb_get(hwdb
, modalias
, "ID_OUI_FROM_DATABASE", &description
);
1015 desc
= strdup(description
);
1019 *ret
= TAKE_PTR(desc
);
1024 static int get_gateway_description(
1029 union in_addr_union
*gateway
,
1032 _cleanup_(sd_netlink_message_unrefp
) sd_netlink_message
*req
= NULL
, *reply
= NULL
;
1036 assert(ifindex
>= 0);
1037 assert(IN_SET(family
, AF_INET
, AF_INET6
));
1041 r
= sd_rtnl_message_new_neigh(rtnl
, &req
, RTM_GETNEIGH
, ifindex
, family
);
1045 r
= sd_netlink_message_set_request_dump(req
, true);
1049 r
= sd_netlink_call(rtnl
, req
, 0, &reply
);
1053 for (sd_netlink_message
*m
= reply
; m
; m
= sd_netlink_message_next(m
)) {
1054 union in_addr_union gw
= IN_ADDR_NULL
;
1055 struct ether_addr mac
= ETHER_ADDR_NULL
;
1059 r
= sd_netlink_message_get_errno(m
);
1061 log_error_errno(r
, "Failed to get netlink message, ignoring: %m");
1065 r
= sd_netlink_message_get_type(m
, &type
);
1067 log_error_errno(r
, "Failed to get netlink message type, ignoring: %m");
1071 if (type
!= RTM_NEWNEIGH
) {
1072 log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1073 "Got unexpected netlink message type %u, ignoring",
1078 r
= sd_rtnl_message_neigh_get_family(m
, &fam
);
1080 log_error_errno(r
, "Failed to get rtnl family, ignoring: %m");
1084 if (fam
!= family
) {
1085 log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Got invalid rtnl family %d, ignoring", fam
);
1089 r
= sd_rtnl_message_neigh_get_ifindex(m
, &ifi
);
1091 log_error_errno(r
, "Failed to get rtnl ifindex, ignoring: %m");
1095 if (ifindex
> 0 && ifi
!= ifindex
)
1101 r
= sd_netlink_message_read_in_addr(m
, NDA_DST
, &gw
.in
);
1108 r
= sd_netlink_message_read_in6_addr(m
, NDA_DST
, &gw
.in6
);
1115 assert_not_reached();
1118 if (!in_addr_equal(fam
, &gw
, gateway
))
1121 r
= sd_netlink_message_read(m
, NDA_LLADDR
, sizeof(mac
), &mac
);
1125 r
= ieee_oui(hwdb
, &mac
, ret
);
1135 static int dump_list(Table
*table
, const char *key
, char * const *l
) {
1141 if (strv_isempty(l
))
1144 r
= table_add_many(table
,
1148 return table_log_add_error(r
);
1153 static int dump_gateways(sd_netlink
*rtnl
, sd_hwdb
*hwdb
, Table
*table
, int ifindex
) {
1154 _cleanup_free_
struct local_address
*local_addrs
= NULL
;
1155 _cleanup_strv_free_
char **buf
= NULL
;
1161 n
= local_gateways(rtnl
, ifindex
, AF_UNSPEC
, &local_addrs
);
1165 FOREACH_ARRAY(local
, local_addrs
, n
) {
1166 _cleanup_free_
char *description
= NULL
;
1168 r
= get_gateway_description(rtnl
, hwdb
, local
->ifindex
, local
->family
, &local
->address
, &description
);
1170 log_debug_errno(r
, "Could not get description of gateway, ignoring: %m");
1172 /* Show interface name for the entry if we show entries for all interfaces */
1173 r
= strv_extendf(&buf
, "%s%s%s%s%s%s",
1174 IN_ADDR_TO_STRING(local
->family
, &local
->address
),
1175 description
? " (" : "",
1176 strempty(description
),
1177 description
? ")" : "",
1178 ifindex
<= 0 ? " on " : "",
1179 ifindex
<= 0 ? FORMAT_IFNAME_FULL(local
->ifindex
, FORMAT_IFNAME_IFINDEX_WITH_PERCENT
) : "");
1184 return dump_list(table
, "Gateway", buf
);
1187 static int dump_addresses(
1189 sd_dhcp_lease
*lease
,
1193 _cleanup_free_
struct local_address
*local_addrs
= NULL
;
1194 _cleanup_strv_free_
char **buf
= NULL
;
1195 struct in_addr dhcp4_address
= {};
1201 n
= local_addresses(rtnl
, ifindex
, AF_UNSPEC
, &local_addrs
);
1206 (void) sd_dhcp_lease_get_address(lease
, &dhcp4_address
);
1208 FOREACH_ARRAY(local
, local_addrs
, n
) {
1209 struct in_addr server_address
;
1212 if (local
->family
== AF_INET
&& in4_addr_equal(&local
->address
.in
, &dhcp4_address
))
1213 dhcp4
= sd_dhcp_lease_get_server_identifier(lease
, &server_address
) >= 0;
1215 r
= strv_extendf(&buf
, "%s%s%s%s%s%s",
1216 IN_ADDR_TO_STRING(local
->family
, &local
->address
),
1217 dhcp4
? " (DHCP4 via " : "",
1218 dhcp4
? IN4_ADDR_TO_STRING(&server_address
) : "",
1220 ifindex
<= 0 ? " on " : "",
1221 ifindex
<= 0 ? FORMAT_IFNAME_FULL(local
->ifindex
, FORMAT_IFNAME_IFINDEX_WITH_PERCENT
) : "");
1226 return dump_list(table
, "Address", buf
);
1229 static int dump_address_labels(sd_netlink
*rtnl
) {
1230 _cleanup_(sd_netlink_message_unrefp
) sd_netlink_message
*req
= NULL
, *reply
= NULL
;
1231 _cleanup_(table_unrefp
) Table
*table
= NULL
;
1237 r
= sd_rtnl_message_new_addrlabel(rtnl
, &req
, RTM_GETADDRLABEL
, 0, AF_INET6
);
1239 return log_error_errno(r
, "Could not allocate RTM_GETADDRLABEL message: %m");
1241 r
= sd_netlink_message_set_request_dump(req
, true);
1245 r
= sd_netlink_call(rtnl
, req
, 0, &reply
);
1249 table
= table_new("label", "prefix/prefixlen");
1254 table_set_width(table
, 0);
1256 r
= table_set_sort(table
, (size_t) 0);
1260 assert_se(cell
= table_get_cell(table
, 0, 0));
1261 (void) table_set_align_percent(table
, cell
, 100);
1262 (void) table_set_ellipsize_percent(table
, cell
, 100);
1264 assert_se(cell
= table_get_cell(table
, 0, 1));
1265 (void) table_set_align_percent(table
, cell
, 100);
1267 for (sd_netlink_message
*m
= reply
; m
; m
= sd_netlink_message_next(m
)) {
1268 struct in6_addr prefix
;
1272 r
= sd_netlink_message_get_errno(m
);
1274 log_error_errno(r
, "Failed to get netlink message, ignoring: %m");
1278 r
= sd_netlink_message_read_u32(m
, IFAL_LABEL
, &label
);
1279 if (r
< 0 && r
!= -ENODATA
) {
1280 log_error_errno(r
, "Could not read IFAL_LABEL, ignoring: %m");
1284 r
= sd_netlink_message_read_in6_addr(m
, IFAL_ADDRESS
, &prefix
);
1288 r
= sd_rtnl_message_addrlabel_get_prefixlen(m
, &prefixlen
);
1292 r
= table_add_cell(table
, NULL
, TABLE_UINT32
, &label
);
1294 return table_log_add_error(r
);
1296 r
= table_add_cell_stringf(table
, NULL
, "%s/%u", IN6_ADDR_TO_STRING(&prefix
), prefixlen
);
1298 return table_log_add_error(r
);
1301 r
= table_print(table
, NULL
);
1303 return table_log_print_error(r
);
1308 static int list_address_labels(int argc
, char *argv
[], void *userdata
) {
1309 _cleanup_(sd_netlink_unrefp
) sd_netlink
*rtnl
= NULL
;
1312 r
= sd_netlink_open(&rtnl
);
1314 return log_error_errno(r
, "Failed to connect to netlink: %m");
1316 return dump_address_labels(rtnl
);
1319 typedef struct InterfaceInfo
{
1326 static void interface_info_done(InterfaceInfo
*p
) {
1330 strv_free(p
->altnames
);
1331 json_variant_unref(p
->v
);
1334 static const JsonDispatch interface_info_dispatch_table
[] = {
1335 { "InterfaceIndex", _JSON_VARIANT_TYPE_INVALID
, json_dispatch_int
, offsetof(InterfaceInfo
, ifindex
), JSON_MANDATORY
},
1336 { "InterfaceName", JSON_VARIANT_STRING
, json_dispatch_const_string
, offsetof(InterfaceInfo
, ifname
), JSON_MANDATORY
},
1337 { "InterfaceAlternativeNames", JSON_VARIANT_ARRAY
, json_dispatch_strv
, offsetof(InterfaceInfo
, altnames
), 0 },
1338 { "Neighbors", JSON_VARIANT_ARRAY
, json_dispatch_variant
, offsetof(InterfaceInfo
, v
), 0 },
1342 typedef struct LLDPNeighborInfo
{
1343 const char *chassis_id
;
1344 const char *port_id
;
1345 const char *port_description
;
1346 const char *system_name
;
1347 const char *system_description
;
1348 uint16_t capabilities
;
1351 static const JsonDispatch lldp_neighbor_dispatch_table
[] = {
1352 { "ChassisID", JSON_VARIANT_STRING
, json_dispatch_const_string
, offsetof(LLDPNeighborInfo
, chassis_id
), 0 },
1353 { "PortID", JSON_VARIANT_STRING
, json_dispatch_const_string
, offsetof(LLDPNeighborInfo
, port_id
), 0 },
1354 { "PortDescription", JSON_VARIANT_STRING
, json_dispatch_const_string
, offsetof(LLDPNeighborInfo
, port_description
), 0 },
1355 { "SystemName", JSON_VARIANT_STRING
, json_dispatch_const_string
, offsetof(LLDPNeighborInfo
, system_name
), 0 },
1356 { "SystemDescription", JSON_VARIANT_STRING
, json_dispatch_const_string
, offsetof(LLDPNeighborInfo
, system_description
), 0 },
1357 { "EnabledCapabilities", _JSON_VARIANT_TYPE_INVALID
, json_dispatch_uint16
, offsetof(LLDPNeighborInfo
, capabilities
), 0 },
1361 static int dump_lldp_neighbors(Varlink
*vl
, Table
*table
, int ifindex
) {
1362 _cleanup_strv_free_
char **buf
= NULL
;
1368 assert(ifindex
> 0);
1370 r
= varlink_callb_and_log(vl
, "io.systemd.Network.GetLLDPNeighbors", &reply
,
1371 JSON_BUILD_OBJECT(JSON_BUILD_PAIR_INTEGER("InterfaceIndex", ifindex
)));
1376 JSON_VARIANT_ARRAY_FOREACH(i
, json_variant_by_key(reply
, "Neighbors")) {
1377 _cleanup_(interface_info_done
) InterfaceInfo info
= {};
1379 r
= json_dispatch(i
, interface_info_dispatch_table
, JSON_LOG
|JSON_ALLOW_EXTENSIONS
, &info
);
1383 if (info
.ifindex
!= ifindex
)
1386 JsonVariant
*neighbor
;
1387 JSON_VARIANT_ARRAY_FOREACH(neighbor
, info
.v
) {
1388 LLDPNeighborInfo neighbor_info
= {};
1390 r
= json_dispatch(neighbor
, lldp_neighbor_dispatch_table
, JSON_LOG
|JSON_ALLOW_EXTENSIONS
, &neighbor_info
);
1394 r
= strv_extendf(&buf
, "%s%s%s%s on port %s%s%s%s",
1395 strna(neighbor_info
.system_name
),
1396 isempty(neighbor_info
.system_description
) ? "" : " (",
1397 strempty(neighbor_info
.system_description
),
1398 isempty(neighbor_info
.system_description
) ? "" : ")",
1399 strna(neighbor_info
.port_id
),
1400 isempty(neighbor_info
.port_description
) ? "" : " (",
1401 strempty(neighbor_info
.port_description
),
1402 isempty(neighbor_info
.port_description
) ? "" : ")");
1408 return dump_list(table
, "Connected To", buf
);
1411 static int dump_dhcp_leases(Table
*table
, const char *prefix
, sd_bus
*bus
, const LinkInfo
*link
) {
1412 _cleanup_strv_free_
char **buf
= NULL
;
1413 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1414 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1422 r
= link_get_property(bus
, link
, &error
, &reply
, "org.freedesktop.network1.DHCPServer", "Leases", "a(uayayayayt)");
1424 bool quiet
= sd_bus_error_has_name(&error
, SD_BUS_ERROR_UNKNOWN_PROPERTY
);
1426 log_full_errno(quiet
? LOG_DEBUG
: LOG_WARNING
,
1427 r
, "Failed to query link DHCP leases: %s", bus_error_message(&error
, r
));
1431 r
= sd_bus_message_enter_container(reply
, 'a', "(uayayayayt)");
1433 return bus_log_parse_error(r
);
1435 while ((r
= sd_bus_message_enter_container(reply
, 'r', "uayayayayt")) > 0) {
1436 _cleanup_free_
char *id
= NULL
, *ip
= NULL
;
1437 const void *client_id
, *addr
, *gtw
, *hwaddr
;
1438 size_t client_id_sz
, sz
;
1439 uint64_t expiration
;
1442 r
= sd_bus_message_read(reply
, "u", &family
);
1444 return bus_log_parse_error(r
);
1446 r
= sd_bus_message_read_array(reply
, 'y', &client_id
, &client_id_sz
);
1448 return bus_log_parse_error(r
);
1450 r
= sd_bus_message_read_array(reply
, 'y', &addr
, &sz
);
1451 if (r
< 0 || sz
!= 4)
1452 return bus_log_parse_error(r
);
1454 r
= sd_bus_message_read_array(reply
, 'y', >w
, &sz
);
1455 if (r
< 0 || sz
!= 4)
1456 return bus_log_parse_error(r
);
1458 r
= sd_bus_message_read_array(reply
, 'y', &hwaddr
, &sz
);
1460 return bus_log_parse_error(r
);
1462 r
= sd_bus_message_read_basic(reply
, 't', &expiration
);
1464 return bus_log_parse_error(r
);
1466 r
= sd_dhcp_client_id_to_string_from_raw(client_id
, client_id_sz
, &id
);
1468 return bus_log_parse_error(r
);
1470 r
= in_addr_to_string(family
, addr
, &ip
);
1472 return bus_log_parse_error(r
);
1474 r
= strv_extendf(&buf
, "%s (to %s)", ip
, id
);
1478 r
= sd_bus_message_exit_container(reply
);
1480 return bus_log_parse_error(r
);
1483 return bus_log_parse_error(r
);
1485 r
= sd_bus_message_exit_container(reply
);
1487 return bus_log_parse_error(r
);
1489 r
= sd_bus_message_exit_container(reply
);
1491 return bus_log_parse_error(r
);
1493 if (strv_isempty(buf
)) {
1494 r
= strv_extendf(&buf
, "none");
1499 return dump_list(table
, prefix
, buf
);
1502 static int dump_ifindexes(Table
*table
, const char *prefix
, const int *ifindexes
) {
1511 for (unsigned c
= 0; ifindexes
[c
] > 0; c
++) {
1513 r
= table_add_cell(table
, NULL
, TABLE_FIELD
, prefix
);
1515 r
= table_add_cell(table
, NULL
, TABLE_EMPTY
, NULL
);
1517 return table_log_add_error(r
);
1519 r
= table_add_cell(table
, NULL
, TABLE_IFINDEX
, &ifindexes
[c
]);
1521 return table_log_add_error(r
);
1527 #define DUMP_STATS_ONE(name, val_name) \
1529 r = table_add_cell(table, NULL, TABLE_FIELD, name); \
1531 return table_log_add_error(r); \
1532 r = table_add_cell(table, NULL, \
1533 info->has_stats64 ? TABLE_UINT64 : TABLE_UINT32, \
1534 info->has_stats64 ? (void*) &info->stats64.val_name : (void*) &info->stats.val_name); \
1536 return table_log_add_error(r); \
1539 static int dump_statistics(Table
*table
, const LinkInfo
*info
) {
1548 if (!info
->has_stats64
&& !info
->has_stats
)
1551 DUMP_STATS_ONE("Rx Packets", rx_packets
);
1552 DUMP_STATS_ONE("Tx Packets", tx_packets
);
1553 DUMP_STATS_ONE("Rx Bytes", rx_bytes
);
1554 DUMP_STATS_ONE("Tx Bytes", tx_bytes
);
1555 DUMP_STATS_ONE("Rx Errors", rx_errors
);
1556 DUMP_STATS_ONE("Tx Errors", tx_errors
);
1557 DUMP_STATS_ONE("Rx Dropped", rx_dropped
);
1558 DUMP_STATS_ONE("Tx Dropped", tx_dropped
);
1559 DUMP_STATS_ONE("Multicast Packets", multicast
);
1560 DUMP_STATS_ONE("Collisions", collisions
);
1565 static int dump_hw_address(Table
*table
, sd_hwdb
*hwdb
, const char *field
, const struct hw_addr_data
*addr
) {
1566 _cleanup_free_
char *description
= NULL
;
1573 if (addr
->length
== ETH_ALEN
)
1574 (void) ieee_oui(hwdb
, &addr
->ether
, &description
);
1576 r
= table_add_cell(table
, NULL
, TABLE_FIELD
, field
);
1578 return table_log_add_error(r
);
1580 r
= table_add_cell_stringf(table
, NULL
, "%s%s%s%s",
1581 HW_ADDR_TO_STR(addr
),
1582 description
? " (" : "",
1583 strempty(description
),
1584 description
? ")" : "");
1586 return table_log_add_error(r
);
1591 static OutputFlags
get_output_flags(void) {
1593 arg_all
* OUTPUT_SHOW_ALL
|
1594 (arg_full
|| !on_tty() || pager_have()) * OUTPUT_FULL_WIDTH
|
1595 colors_enabled() * OUTPUT_COLOR
;
1598 static int show_logs(const LinkInfo
*info
) {
1599 _cleanup_(sd_journal_closep
) sd_journal
*j
= NULL
;
1605 r
= sd_journal_open(&j
, SD_JOURNAL_LOCAL_ONLY
| SD_JOURNAL_ASSUME_IMMUTABLE
);
1607 return log_error_errno(r
, "Failed to open journal: %m");
1609 r
= add_match_this_boot(j
, NULL
);
1611 return log_error_errno(r
, "Failed to add boot matches: %m");
1614 char m1
[STRLEN("_KERNEL_DEVICE=n") + DECIMAL_STR_MAX(int)];
1615 const char *m2
, *m3
;
1618 xsprintf(m1
, "_KERNEL_DEVICE=n%i", info
->ifindex
);
1620 m2
= strjoina("INTERFACE=", info
->name
);
1622 m3
= strjoina("DEVICE=", info
->name
);
1625 (r
= sd_journal_add_match(j
, m1
, 0)) ||
1626 (r
= sd_journal_add_disjunction(j
)) ||
1627 (r
= sd_journal_add_match(j
, m2
, 0)) ||
1628 (r
= sd_journal_add_disjunction(j
)) ||
1629 (r
= sd_journal_add_match(j
, m3
, 0))
1632 return log_error_errno(r
, "Failed to add link matches: %m");
1634 r
= add_matches_for_unit(j
, "systemd-networkd.service");
1636 return log_error_errno(r
, "Failed to add unit matches: %m");
1638 r
= add_matches_for_unit(j
, "systemd-networkd-wait-online.service");
1640 return log_error_errno(r
, "Failed to add unit matches: %m");
1643 return show_journal(
1650 get_output_flags() | OUTPUT_BEGIN_NEWLINE
,
1654 static int table_add_string_line(Table
*table
, const char *key
, const char *value
) {
1663 r
= table_add_many(table
,
1665 TABLE_STRING
, value
);
1667 return table_log_add_error(r
);
1672 static int format_dropins(char **dropins
) {
1673 STRV_FOREACH(d
, dropins
) {
1674 _cleanup_free_
char *s
= NULL
;
1675 int glyph
= *(d
+ 1) == NULL
? SPECIAL_GLYPH_TREE_RIGHT
: SPECIAL_GLYPH_TREE_BRANCH
;
1677 s
= strjoin(special_glyph(glyph
), *d
);
1681 free_and_replace(*d
, s
);
1687 static int link_status_one(
1692 const LinkInfo
*info
) {
1694 _cleanup_strv_free_
char **dns
= NULL
, **ntp
= NULL
, **sip
= NULL
, **search_domains
= NULL
,
1695 **route_domains
= NULL
, **link_dropins
= NULL
, **network_dropins
= NULL
;
1696 _cleanup_free_
char *t
= NULL
, *network
= NULL
, *iaid
= NULL
, *duid
= NULL
, *captive_portal
= NULL
,
1697 *setup_state
= NULL
, *operational_state
= NULL
, *online_state
= NULL
, *activation_policy
= NULL
;
1698 const char *driver
= NULL
, *path
= NULL
, *vendor
= NULL
, *model
= NULL
, *link
= NULL
,
1699 *on_color_operational
, *off_color_operational
, *on_color_setup
, *off_color_setup
, *on_color_online
;
1700 _cleanup_free_
int *carrier_bound_to
= NULL
, *carrier_bound_by
= NULL
;
1701 _cleanup_(sd_dhcp_lease_unrefp
) sd_dhcp_lease
*lease
= NULL
;
1702 _cleanup_(table_unrefp
) Table
*table
= NULL
;
1710 (void) sd_network_link_get_operational_state(info
->ifindex
, &operational_state
);
1711 operational_state_to_color(info
->name
, operational_state
, &on_color_operational
, &off_color_operational
);
1713 (void) sd_network_link_get_online_state(info
->ifindex
, &online_state
);
1714 online_state_to_color(online_state
, &on_color_online
, NULL
);
1716 (void) sd_network_link_get_setup_state(info
->ifindex
, &setup_state
);
1717 setup_state_to_color(setup_state
, &on_color_setup
, &off_color_setup
);
1719 (void) sd_network_link_get_dns(info
->ifindex
, &dns
);
1720 (void) sd_network_link_get_search_domains(info
->ifindex
, &search_domains
);
1721 (void) sd_network_link_get_route_domains(info
->ifindex
, &route_domains
);
1722 (void) sd_network_link_get_ntp(info
->ifindex
, &ntp
);
1723 (void) sd_network_link_get_sip(info
->ifindex
, &sip
);
1724 (void) sd_network_link_get_captive_portal(info
->ifindex
, &captive_portal
);
1725 (void) sd_network_link_get_network_file(info
->ifindex
, &network
);
1726 (void) sd_network_link_get_network_file_dropins(info
->ifindex
, &network_dropins
);
1727 (void) sd_network_link_get_carrier_bound_to(info
->ifindex
, &carrier_bound_to
);
1728 (void) sd_network_link_get_carrier_bound_by(info
->ifindex
, &carrier_bound_by
);
1729 (void) sd_network_link_get_activation_policy(info
->ifindex
, &activation_policy
);
1731 if (info
->sd_device
) {
1734 (void) sd_device_get_property_value(info
->sd_device
, "ID_NET_LINK_FILE", &link
);
1736 if (sd_device_get_property_value(info
->sd_device
, "ID_NET_LINK_FILE_DROPINS", &joined
) >= 0) {
1737 r
= strv_split_full(&link_dropins
, joined
, ":", EXTRACT_CUNESCAPE
);
1742 (void) sd_device_get_property_value(info
->sd_device
, "ID_NET_DRIVER", &driver
);
1743 (void) sd_device_get_property_value(info
->sd_device
, "ID_PATH", &path
);
1744 (void) device_get_vendor_string(info
->sd_device
, &vendor
);
1745 (void) device_get_model_string(info
->sd_device
, &model
);
1748 r
= net_get_type_string(info
->sd_device
, info
->iftype
, &t
);
1752 char lease_file
[STRLEN("/run/systemd/netif/leases/") + DECIMAL_STR_MAX(int)];
1753 xsprintf(lease_file
, "/run/systemd/netif/leases/%i", info
->ifindex
);
1755 (void) dhcp_lease_load(&lease
, lease_file
);
1757 r
= format_dropins(network_dropins
);
1761 if (strv_prepend(&network_dropins
, network
) < 0)
1764 r
= format_dropins(link_dropins
);
1768 if (strv_prepend(&link_dropins
, link
) < 0)
1771 table
= table_new_vertical();
1776 table_set_width(table
, 0);
1778 /* unit files and basic states. */
1779 r
= table_add_many(table
,
1780 TABLE_FIELD
, "Link File",
1781 TABLE_STRV
, link_dropins
?: STRV_MAKE("n/a"),
1782 TABLE_FIELD
, "Network File",
1783 TABLE_STRV
, network_dropins
?: STRV_MAKE("n/a"),
1784 TABLE_FIELD
, "State");
1786 return table_log_add_error(r
);
1788 r
= table_add_cell_stringf(table
, NULL
, "%s%s%s (%s%s%s)",
1789 on_color_operational
, strna(operational_state
), off_color_operational
,
1790 on_color_setup
, setup_state
?: "unmanaged", off_color_setup
);
1792 return table_log_add_error(r
);
1794 r
= table_add_many(table
,
1795 TABLE_FIELD
, "Online state",
1796 TABLE_STRING
, online_state
?: "unknown",
1797 TABLE_SET_COLOR
, on_color_online
);
1799 return table_log_add_error(r
);
1801 r
= table_add_string_line(table
, "Type", t
);
1805 r
= table_add_string_line(table
, "Kind", info
->netdev_kind
);
1809 r
= table_add_string_line(table
, "Path", path
);
1813 r
= table_add_string_line(table
, "Driver", driver
);
1817 r
= table_add_string_line(table
, "Vendor", vendor
);
1821 r
= table_add_string_line(table
, "Model", model
);
1825 strv_sort(info
->alternative_names
);
1826 r
= dump_list(table
, "Alternative Names", info
->alternative_names
);
1830 if (info
->has_hw_address
) {
1831 r
= dump_hw_address(table
, hwdb
, "Hardware Address", &info
->hw_address
);
1836 if (info
->has_permanent_hw_address
) {
1837 r
= dump_hw_address(table
, hwdb
, "Permanent Hardware Address", &info
->permanent_hw_address
);
1842 if (info
->mtu
> 0) {
1843 char min_str
[DECIMAL_STR_MAX(uint32_t)], max_str
[DECIMAL_STR_MAX(uint32_t)];
1845 xsprintf(min_str
, "%" PRIu32
, info
->min_mtu
);
1846 xsprintf(max_str
, "%" PRIu32
, info
->max_mtu
);
1848 r
= table_add_cell(table
, NULL
, TABLE_FIELD
, "MTU");
1850 return table_log_add_error(r
);
1852 r
= table_add_cell_stringf(table
, NULL
, "%" PRIu32
"%s%s%s%s%s%s%s",
1854 info
->min_mtu
> 0 || info
->max_mtu
> 0 ? " (" : "",
1855 info
->min_mtu
> 0 ? "min: " : "",
1856 info
->min_mtu
> 0 ? min_str
: "",
1857 info
->min_mtu
> 0 && info
->max_mtu
> 0 ? ", " : "",
1858 info
->max_mtu
> 0 ? "max: " : "",
1859 info
->max_mtu
> 0 ? max_str
: "",
1860 info
->min_mtu
> 0 || info
->max_mtu
> 0 ? ")" : "");
1862 return table_log_add_error(r
);
1865 r
= table_add_string_line(table
, "QDisc", info
->qdisc
);
1869 if (info
->master
> 0) {
1870 r
= table_add_many(table
,
1871 TABLE_FIELD
, "Master",
1872 TABLE_IFINDEX
, info
->master
);
1874 return table_log_add_error(r
);
1877 if (info
->has_ipv6_address_generation_mode
) {
1878 static const struct {
1883 { "stable-privacy" },
1887 r
= table_add_many(table
,
1888 TABLE_FIELD
, "IPv6 Address Generation Mode",
1889 TABLE_STRING
, mode_table
[info
->addr_gen_mode
]);
1891 return table_log_add_error(r
);
1894 if (streq_ptr(info
->netdev_kind
, "bridge")) {
1895 r
= table_add_many(table
,
1896 TABLE_FIELD
, "Forward Delay",
1897 TABLE_TIMESPAN_MSEC
, jiffies_to_usec(info
->forward_delay
),
1898 TABLE_FIELD
, "Hello Time",
1899 TABLE_TIMESPAN_MSEC
, jiffies_to_usec(info
->hello_time
),
1900 TABLE_FIELD
, "Max Age",
1901 TABLE_TIMESPAN_MSEC
, jiffies_to_usec(info
->max_age
),
1902 TABLE_FIELD
, "Ageing Time",
1903 TABLE_TIMESPAN_MSEC
, jiffies_to_usec(info
->ageing_time
),
1904 TABLE_FIELD
, "Priority",
1905 TABLE_UINT16
, info
->priority
,
1907 TABLE_BOOLEAN
, info
->stp_state
> 0,
1908 TABLE_FIELD
, "Multicast IGMP Version",
1909 TABLE_UINT8
, info
->mcast_igmp_version
,
1910 TABLE_FIELD
, "Cost",
1911 TABLE_UINT32
, info
->cost
);
1913 return table_log_add_error(r
);
1915 if (info
->port_state
<= BR_STATE_BLOCKING
) {
1916 r
= table_add_many(table
,
1917 TABLE_FIELD
, "Port State",
1918 TABLE_STRING
, bridge_state_to_string(info
->port_state
));
1920 return table_log_add_error(r
);
1923 } else if (streq_ptr(info
->netdev_kind
, "bond")) {
1924 r
= table_add_many(table
,
1925 TABLE_FIELD
, "Mode",
1926 TABLE_STRING
, bond_mode_to_string(info
->mode
),
1927 TABLE_FIELD
, "Miimon",
1928 TABLE_TIMESPAN_MSEC
, info
->miimon
* USEC_PER_MSEC
,
1929 TABLE_FIELD
, "Updelay",
1930 TABLE_TIMESPAN_MSEC
, info
->updelay
* USEC_PER_MSEC
,
1931 TABLE_FIELD
, "Downdelay",
1932 TABLE_TIMESPAN_MSEC
, info
->downdelay
* USEC_PER_MSEC
);
1934 return table_log_add_error(r
);
1936 } else if (streq_ptr(info
->netdev_kind
, "vxlan")) {
1937 char ttl
[CONST_MAX(STRLEN("auto") + 1, DECIMAL_STR_MAX(uint8_t))];
1939 if (info
->vxlan_info
.vni
> 0) {
1940 r
= table_add_many(table
,
1942 TABLE_UINT32
, info
->vxlan_info
.vni
);
1944 return table_log_add_error(r
);
1947 if (IN_SET(info
->vxlan_info
.group_family
, AF_INET
, AF_INET6
)) {
1950 r
= in_addr_is_multicast(info
->vxlan_info
.group_family
, &info
->vxlan_info
.group
);
1956 r
= table_add_many(table
,
1958 info
->vxlan_info
.group_family
== AF_INET
? TABLE_IN_ADDR
: TABLE_IN6_ADDR
, &info
->vxlan_info
.group
);
1960 return table_log_add_error(r
);
1963 if (IN_SET(info
->vxlan_info
.local_family
, AF_INET
, AF_INET6
)) {
1964 r
= table_add_many(table
,
1965 TABLE_FIELD
, "Local",
1966 info
->vxlan_info
.local_family
== AF_INET
? TABLE_IN_ADDR
: TABLE_IN6_ADDR
, &info
->vxlan_info
.local
);
1968 return table_log_add_error(r
);
1971 if (info
->vxlan_info
.dest_port
> 0) {
1972 r
= table_add_many(table
,
1973 TABLE_FIELD
, "Destination Port",
1974 TABLE_UINT16
, be16toh(info
->vxlan_info
.dest_port
));
1976 return table_log_add_error(r
);
1979 if (info
->vxlan_info
.link
> 0) {
1980 r
= table_add_many(table
,
1981 TABLE_FIELD
, "Underlying Device",
1982 TABLE_IFINDEX
, info
->vxlan_info
.link
);
1984 return table_log_add_error(r
);
1987 r
= table_add_many(table
,
1988 TABLE_FIELD
, "Learning",
1989 TABLE_BOOLEAN
, info
->vxlan_info
.learning
,
1991 TABLE_BOOLEAN
, info
->vxlan_info
.rsc
,
1992 TABLE_FIELD
, "L3MISS",
1993 TABLE_BOOLEAN
, info
->vxlan_info
.l3miss
,
1994 TABLE_FIELD
, "L2MISS",
1995 TABLE_BOOLEAN
, info
->vxlan_info
.l2miss
);
1997 return table_log_add_error(r
);
1999 if (info
->vxlan_info
.tos
> 1) {
2000 r
= table_add_many(table
,
2002 TABLE_UINT8
, info
->vxlan_info
.tos
);
2004 return table_log_add_error(r
);
2007 if (info
->vxlan_info
.ttl
> 0)
2008 xsprintf(ttl
, "%" PRIu8
, info
->vxlan_info
.ttl
);
2010 strcpy(ttl
, "auto");
2012 r
= table_add_many(table
,
2016 return table_log_add_error(r
);
2018 } else if (streq_ptr(info
->netdev_kind
, "vlan") && info
->vlan_id
> 0) {
2019 r
= table_add_many(table
,
2020 TABLE_FIELD
, "VLan Id",
2021 TABLE_UINT16
, info
->vlan_id
);
2023 return table_log_add_error(r
);
2025 } else if (STRPTR_IN_SET(info
->netdev_kind
, "ipip", "sit", "gre", "gretap", "erspan", "vti")) {
2026 if (in_addr_is_set(AF_INET
, &info
->local
)) {
2027 r
= table_add_many(table
,
2028 TABLE_FIELD
, "Local",
2029 TABLE_IN_ADDR
, &info
->local
);
2031 return table_log_add_error(r
);
2034 if (in_addr_is_set(AF_INET
, &info
->remote
)) {
2035 r
= table_add_many(table
,
2036 TABLE_FIELD
, "Remote",
2037 TABLE_IN_ADDR
, &info
->remote
);
2039 return table_log_add_error(r
);
2042 } else if (STRPTR_IN_SET(info
->netdev_kind
, "ip6gre", "ip6gretap", "ip6erspan", "vti6")) {
2043 if (in_addr_is_set(AF_INET6
, &info
->local
)) {
2044 r
= table_add_many(table
,
2045 TABLE_FIELD
, "Local",
2046 TABLE_IN6_ADDR
, &info
->local
);
2048 return table_log_add_error(r
);
2051 if (in_addr_is_set(AF_INET6
, &info
->remote
)) {
2052 r
= table_add_many(table
,
2053 TABLE_FIELD
, "Remote",
2054 TABLE_IN6_ADDR
, &info
->remote
);
2056 return table_log_add_error(r
);
2059 } else if (streq_ptr(info
->netdev_kind
, "geneve")) {
2060 r
= table_add_many(table
,
2062 TABLE_UINT32
, info
->vni
);
2064 return table_log_add_error(r
);
2066 if (info
->has_tunnel_ipv4
&& in_addr_is_set(AF_INET
, &info
->remote
)) {
2067 r
= table_add_many(table
,
2068 TABLE_FIELD
, "Remote",
2069 TABLE_IN_ADDR
, &info
->remote
);
2071 return table_log_add_error(r
);
2072 } else if (in_addr_is_set(AF_INET6
, &info
->remote
)) {
2073 r
= table_add_many(table
,
2074 TABLE_FIELD
, "Remote",
2075 TABLE_IN6_ADDR
, &info
->remote
);
2077 return table_log_add_error(r
);
2080 if (info
->ttl
> 0) {
2081 r
= table_add_many(table
,
2083 TABLE_UINT8
, info
->ttl
);
2085 return table_log_add_error(r
);
2088 if (info
->tos
> 0) {
2089 r
= table_add_many(table
,
2091 TABLE_UINT8
, info
->tos
);
2093 return table_log_add_error(r
);
2096 r
= table_add_many(table
,
2097 TABLE_FIELD
, "Port",
2098 TABLE_UINT16
, info
->tunnel_port
,
2099 TABLE_FIELD
, "Inherit",
2100 TABLE_STRING
, geneve_df_to_string(info
->inherit
));
2102 return table_log_add_error(r
);
2105 r
= table_add_many(table
,
2106 TABLE_FIELD
, "IPDoNotFragment",
2107 TABLE_UINT8
, info
->df
);
2109 return table_log_add_error(r
);
2112 r
= table_add_many(table
,
2113 TABLE_FIELD
, "UDPChecksum",
2114 TABLE_BOOLEAN
, info
->csum
,
2115 TABLE_FIELD
, "UDP6ZeroChecksumTx",
2116 TABLE_BOOLEAN
, info
->csum6_tx
,
2117 TABLE_FIELD
, "UDP6ZeroChecksumRx",
2118 TABLE_BOOLEAN
, info
->csum6_rx
);
2120 return table_log_add_error(r
);
2122 if (info
->label
> 0) {
2123 r
= table_add_many(table
,
2124 TABLE_FIELD
, "FlowLabel",
2125 TABLE_UINT32
, info
->label
);
2127 return table_log_add_error(r
);
2130 } else if (STRPTR_IN_SET(info
->netdev_kind
, "macvlan", "macvtap")) {
2131 r
= table_add_many(table
,
2132 TABLE_FIELD
, "Mode",
2133 TABLE_STRING
, macvlan_mode_to_string(info
->macvlan_mode
));
2135 return table_log_add_error(r
);
2137 } else if (streq_ptr(info
->netdev_kind
, "ipvlan")) {
2140 if (info
->ipvlan_flags
& IPVLAN_F_PRIVATE
)
2142 else if (info
->ipvlan_flags
& IPVLAN_F_VEPA
)
2147 r
= table_add_cell(table
, NULL
, TABLE_FIELD
, "Mode");
2149 return table_log_add_error(r
);
2151 r
= table_add_cell_stringf(table
, NULL
, "%s (%s)",
2152 ipvlan_mode_to_string(info
->ipvlan_mode
), p
);
2154 return table_log_add_error(r
);
2157 if (info
->has_wlan_link_info
) {
2158 _cleanup_free_
char *esc
= NULL
;
2160 r
= table_add_cell(table
, NULL
, TABLE_FIELD
, "Wi-Fi access point");
2162 return table_log_add_error(r
);
2165 esc
= cescape(info
->ssid
);
2167 r
= table_add_cell_stringf(table
, NULL
, "%s (%s)",
2169 ETHER_ADDR_TO_STR(&info
->bssid
));
2171 return table_log_add_error(r
);
2174 if (info
->has_bitrates
) {
2175 r
= table_add_cell(table
, NULL
, TABLE_FIELD
, "Bit Rate (Tx/Rx)");
2177 return table_log_add_error(r
);
2179 r
= table_add_cell_stringf(table
, NULL
, "%sbps/%sbps",
2180 FORMAT_BYTES_FULL(info
->tx_bitrate
, 0),
2181 FORMAT_BYTES_FULL(info
->rx_bitrate
, 0));
2183 return table_log_add_error(r
);
2186 if (info
->has_tx_queues
|| info
->has_rx_queues
) {
2187 r
= table_add_cell(table
, NULL
, TABLE_FIELD
, "Number of Queues (Tx/Rx)");
2189 return table_log_add_error(r
);
2191 r
= table_add_cell_stringf(table
, NULL
, "%" PRIu32
"/%" PRIu32
, info
->tx_queues
, info
->rx_queues
);
2193 return table_log_add_error(r
);
2196 if (info
->has_ethtool_link_info
) {
2197 if (IN_SET(info
->autonegotiation
, AUTONEG_DISABLE
, AUTONEG_ENABLE
)) {
2198 r
= table_add_many(table
,
2199 TABLE_FIELD
, "Auto negotiation",
2200 TABLE_BOOLEAN
, info
->autonegotiation
== AUTONEG_ENABLE
);
2202 return table_log_add_error(r
);
2205 if (info
->speed
> 0 && info
->speed
!= UINT64_MAX
) {
2206 r
= table_add_many(table
,
2207 TABLE_FIELD
, "Speed",
2208 TABLE_BPS
, info
->speed
);
2210 return table_log_add_error(r
);
2213 r
= table_add_string_line(table
, "Duplex", duplex_to_string(info
->duplex
));
2217 r
= table_add_string_line(table
, "Port", port_to_string(info
->port
));
2222 r
= dump_addresses(rtnl
, lease
, table
, info
->ifindex
);
2226 r
= dump_gateways(rtnl
, hwdb
, table
, info
->ifindex
);
2230 r
= dump_list(table
, "DNS", dns
);
2234 r
= dump_list(table
, "Search Domains", search_domains
);
2238 r
= dump_list(table
, "Route Domains", route_domains
);
2242 r
= dump_list(table
, "NTP", ntp
);
2246 r
= dump_list(table
, "SIP", sip
);
2250 r
= dump_ifindexes(table
, "Carrier Bound To", carrier_bound_to
);
2254 r
= dump_ifindexes(table
, "Carrier Bound By", carrier_bound_by
);
2258 r
= table_add_string_line(table
, "Activation Policy", activation_policy
);
2262 r
= sd_network_link_get_required_for_online(info
->ifindex
);
2264 r
= table_add_many(table
,
2265 TABLE_FIELD
, "Required For Online",
2268 return table_log_add_error(r
);
2271 if (captive_portal
) {
2272 r
= table_add_many(table
,
2273 TABLE_FIELD
, "Captive Portal",
2274 TABLE_STRING
, captive_portal
,
2275 TABLE_SET_URL
, captive_portal
);
2277 return table_log_add_error(r
);
2281 const sd_dhcp_client_id
*client_id
;
2284 r
= sd_dhcp_lease_get_timezone(lease
, &tz
);
2286 r
= table_add_many(table
,
2287 TABLE_FIELD
, "Time Zone",
2290 return table_log_add_error(r
);
2293 r
= sd_dhcp_lease_get_client_id(lease
, &client_id
);
2295 _cleanup_free_
char *id
= NULL
;
2297 r
= sd_dhcp_client_id_to_string(client_id
, &id
);
2299 r
= table_add_many(table
,
2300 TABLE_FIELD
, "DHCP4 Client ID",
2303 return table_log_add_error(r
);
2308 r
= sd_network_link_get_dhcp6_client_iaid_string(info
->ifindex
, &iaid
);
2310 r
= table_add_many(table
,
2311 TABLE_FIELD
, "DHCP6 Client IAID",
2312 TABLE_STRING
, iaid
);
2314 return table_log_add_error(r
);
2317 r
= sd_network_link_get_dhcp6_client_duid_string(info
->ifindex
, &duid
);
2319 r
= table_add_many(table
,
2320 TABLE_FIELD
, "DHCP6 Client DUID",
2321 TABLE_STRING
, duid
);
2323 return table_log_add_error(r
);
2326 r
= dump_lldp_neighbors(vl
, table
, info
->ifindex
);
2330 r
= dump_dhcp_leases(table
, "Offered DHCP leases", bus
, info
);
2334 r
= dump_statistics(table
, info
);
2338 /* First line: circle, ifindex, ifname. */
2339 printf("%s%s%s %d: %s\n",
2340 on_color_operational
, special_glyph(SPECIAL_GLYPH_BLACK_CIRCLE
), off_color_operational
,
2341 info
->ifindex
, info
->name
);
2343 r
= table_print(table
, NULL
);
2345 return table_log_print_error(r
);
2347 return show_logs(info
);
2350 static int system_status(sd_netlink
*rtnl
, sd_hwdb
*hwdb
) {
2351 _cleanup_free_
char *operational_state
= NULL
, *online_state
= NULL
, *netifs_joined
= NULL
;
2352 _cleanup_strv_free_
char **netifs
= NULL
, **dns
= NULL
, **ntp
= NULL
, **search_domains
= NULL
, **route_domains
= NULL
;
2353 const char *on_color_operational
, *off_color_operational
, *on_color_online
;
2354 _cleanup_(table_unrefp
) Table
*table
= NULL
;
2359 (void) sd_network_get_operational_state(&operational_state
);
2360 operational_state_to_color(NULL
, operational_state
, &on_color_operational
, &off_color_operational
);
2362 (void) sd_network_get_online_state(&online_state
);
2363 online_state_to_color(online_state
, &on_color_online
, NULL
);
2365 table
= table_new_vertical();
2370 table_set_width(table
, 0);
2372 r
= get_files_in_directory("/run/systemd/netif/links/", &netifs
);
2373 if (r
< 0 && r
!= -ENOENT
)
2374 return log_error_errno(r
, "Failed to list network interfaces: %m");
2376 netifs_joined
= strv_join(netifs
, ", ");
2381 r
= table_add_many(table
,
2382 TABLE_FIELD
, "State",
2383 TABLE_STRING
, strna(operational_state
),
2384 TABLE_SET_COLOR
, on_color_operational
,
2385 TABLE_FIELD
, "Online state",
2386 TABLE_STRING
, online_state
?: "unknown",
2387 TABLE_SET_COLOR
, on_color_online
);
2389 return table_log_add_error(r
);
2391 r
= dump_addresses(rtnl
, NULL
, table
, 0);
2395 r
= dump_gateways(rtnl
, hwdb
, table
, 0);
2399 (void) sd_network_get_dns(&dns
);
2400 r
= dump_list(table
, "DNS", dns
);
2404 (void) sd_network_get_search_domains(&search_domains
);
2405 r
= dump_list(table
, "Search Domains", search_domains
);
2409 (void) sd_network_get_route_domains(&route_domains
);
2410 r
= dump_list(table
, "Route Domains", route_domains
);
2414 (void) sd_network_get_ntp(&ntp
);
2415 r
= dump_list(table
, "NTP", ntp
);
2419 printf("%s%s%s Interfaces: %s\n",
2420 on_color_operational
, special_glyph(SPECIAL_GLYPH_BLACK_CIRCLE
), off_color_operational
,
2421 strna(netifs_joined
));
2423 r
= table_print(table
, NULL
);
2425 return table_log_print_error(r
);
2427 return show_logs(NULL
);
2430 static int link_status(int argc
, char *argv
[], void *userdata
) {
2431 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
2432 _cleanup_(sd_netlink_unrefp
) sd_netlink
*rtnl
= NULL
;
2433 _cleanup_(sd_hwdb_unrefp
) sd_hwdb
*hwdb
= NULL
;
2434 _cleanup_(varlink_unrefp
) Varlink
*vl
= NULL
;
2435 _cleanup_(link_info_array_freep
) LinkInfo
*links
= NULL
;
2438 r
= acquire_bus(&bus
);
2442 if (arg_json_format_flags
!= JSON_FORMAT_OFF
) {
2443 if (arg_all
|| argc
<= 1)
2444 return dump_manager_description(bus
);
2446 return dump_link_description(bus
, strv_skip(argv
, 1));
2449 pager_open(arg_pager_flags
);
2451 r
= sd_netlink_open(&rtnl
);
2453 return log_error_errno(r
, "Failed to connect to netlink: %m");
2455 r
= sd_hwdb_new(&hwdb
);
2457 log_debug_errno(r
, "Failed to open hardware database: %m");
2459 r
= varlink_connect_networkd(&vl
);
2464 c
= acquire_link_info(bus
, rtnl
, NULL
, &links
);
2466 return system_status(rtnl
, hwdb
);
2468 c
= acquire_link_info(bus
, rtnl
, argv
+ 1, &links
);
2475 FOREACH_ARRAY(i
, links
, c
) {
2479 RET_GATHER(r
, link_status_one(bus
, rtnl
, hwdb
, vl
, i
));
2487 static char *lldp_capabilities_to_string(uint64_t x
) {
2488 static const char characters
[] = {
2489 'o', 'p', 'b', 'w', 'r', 't', 'd', 'a', 'c', 's', 'm',
2494 ret
= new(char, ELEMENTSOF(characters
) + 1);
2498 for (i
= 0; i
< ELEMENTSOF(characters
); i
++)
2499 ret
[i
] = (x
& (1U << i
)) ? characters
[i
] : '.';
2505 static void lldp_capabilities_legend(uint16_t x
) {
2506 unsigned cols
= columns();
2507 static const char* const table
[] = {
2511 "w - WLAN Access Point",
2514 "d - DOCSIS cable device",
2516 "c - Customer VLAN",
2518 "m - Two-port MAC Relay (TPMR)",
2524 printf("\nCapability Flags:\n");
2525 for (unsigned w
= 0, i
= 0; i
< ELEMENTSOF(table
); i
++)
2526 if (x
& (1U << i
) || arg_all
) {
2529 newline
= w
+ strlen(table
[i
]) + (w
== 0 ? 0 : 2) > cols
;
2532 w
+= printf("%s%s%s", newline
? "\n" : "", w
== 0 ? "" : "; ", table
[i
]);
2537 static bool interface_match_pattern(const InterfaceInfo
*info
, char * const *patterns
) {
2540 if (strv_isempty(patterns
))
2543 if (strv_fnmatch(patterns
, info
->ifname
))
2546 char str
[DECIMAL_STR_MAX(int)];
2547 xsprintf(str
, "%i", info
->ifindex
);
2548 if (strv_fnmatch(patterns
, str
))
2551 STRV_FOREACH(a
, info
->altnames
)
2552 if (strv_fnmatch(patterns
, *a
))
2558 static int dump_lldp_neighbors_json(JsonVariant
*reply
, char * const *patterns
) {
2559 _cleanup_(json_variant_unrefp
) JsonVariant
*array
= NULL
, *v
= NULL
;
2564 if (strv_isempty(patterns
))
2565 return json_variant_dump(reply
, arg_json_format_flags
, NULL
, NULL
);
2567 /* Filter and dump the result. */
2570 JSON_VARIANT_ARRAY_FOREACH(i
, json_variant_by_key(reply
, "Neighbors")) {
2571 _cleanup_(interface_info_done
) InterfaceInfo info
= {};
2573 r
= json_dispatch(i
, interface_info_dispatch_table
, JSON_LOG
|JSON_ALLOW_EXTENSIONS
, &info
);
2577 if (!interface_match_pattern(&info
, patterns
))
2580 r
= json_variant_append_array(&array
, i
);
2582 return log_error_errno(r
, "Failed to append json variant to array: %m");
2587 JSON_BUILD_PAIR_CONDITION(json_variant_is_blank_array(array
), "Neighbors", JSON_BUILD_EMPTY_ARRAY
),
2588 JSON_BUILD_PAIR_CONDITION(!json_variant_is_blank_array(array
), "Neighbors", JSON_BUILD_VARIANT(array
))));
2590 return log_error_errno(r
, "Failed to build json varinat: %m");
2592 return json_variant_dump(v
, arg_json_format_flags
, NULL
, NULL
);
2595 static int link_lldp_status(int argc
, char *argv
[], void *userdata
) {
2596 _cleanup_(varlink_unrefp
) Varlink
*vl
= NULL
;
2597 _cleanup_(table_unrefp
) Table
*table
= NULL
;
2604 r
= varlink_connect_networkd(&vl
);
2608 r
= varlink_call_and_log(vl
, "io.systemd.Network.GetLLDPNeighbors", NULL
, &reply
);
2612 if (arg_json_format_flags
!= JSON_FORMAT_OFF
)
2613 return dump_lldp_neighbors_json(reply
, strv_skip(argv
, 1));
2615 pager_open(arg_pager_flags
);
2617 table
= table_new("index",
2620 "system-description",
2629 table_set_width(table
, 0);
2631 table_set_header(table
, arg_legend
);
2632 table_set_ersatz_string(table
, TABLE_ERSATZ_DASH
);
2633 table_set_sort(table
, (size_t) 0, (size_t) 2);
2634 table_hide_column_from_display(table
, (size_t) 0);
2636 /* Make the capabilities not truncated */
2637 assert_se(cell
= table_get_cell(table
, 0, 7));
2638 table_set_minimum_width(table
, cell
, 11);
2641 JSON_VARIANT_ARRAY_FOREACH(i
, json_variant_by_key(reply
, "Neighbors")) {
2642 _cleanup_(interface_info_done
) InterfaceInfo info
= {};
2644 r
= json_dispatch(i
, interface_info_dispatch_table
, JSON_LOG
|JSON_ALLOW_EXTENSIONS
, &info
);
2648 if (!interface_match_pattern(&info
, strv_skip(argv
, 1)))
2651 JsonVariant
*neighbor
;
2652 JSON_VARIANT_ARRAY_FOREACH(neighbor
, info
.v
) {
2653 LLDPNeighborInfo neighbor_info
= {};
2655 r
= json_dispatch(neighbor
, lldp_neighbor_dispatch_table
, JSON_LOG
|JSON_ALLOW_EXTENSIONS
, &neighbor_info
);
2659 all
|= neighbor_info
.capabilities
;
2661 _cleanup_free_
char *cap_str
= lldp_capabilities_to_string(neighbor_info
.capabilities
);
2663 r
= table_add_many(table
,
2664 TABLE_INT
, info
.ifindex
,
2665 TABLE_STRING
, info
.ifname
,
2666 TABLE_STRING
, neighbor_info
.system_name
,
2667 TABLE_STRING
, neighbor_info
.system_description
,
2668 TABLE_STRING
, neighbor_info
.chassis_id
,
2669 TABLE_STRING
, neighbor_info
.port_id
,
2670 TABLE_STRING
, neighbor_info
.port_description
,
2671 TABLE_STRING
, cap_str
);
2673 return table_log_add_error(r
);
2679 r
= table_print(table
, NULL
);
2681 return table_log_print_error(r
);
2684 lldp_capabilities_legend(all
);
2685 printf("\n%zu neighbor(s) listed.\n", m
);
2691 static int link_delete_send_message(sd_netlink
*rtnl
, int index
) {
2692 _cleanup_(sd_netlink_message_unrefp
) sd_netlink_message
*req
= NULL
;
2698 r
= sd_rtnl_message_new_link(rtnl
, &req
, RTM_DELLINK
, index
);
2700 return rtnl_log_create_error(r
);
2702 r
= sd_netlink_call(rtnl
, req
, 0, NULL
);
2709 static int link_up_down_send_message(sd_netlink
*rtnl
, char *command
, int index
) {
2710 _cleanup_(sd_netlink_message_unrefp
) sd_netlink_message
*req
= NULL
;
2716 r
= sd_rtnl_message_new_link(rtnl
, &req
, RTM_SETLINK
, index
);
2718 return rtnl_log_create_error(r
);
2720 if (streq(command
, "up"))
2721 r
= sd_rtnl_message_link_set_flags(req
, IFF_UP
, IFF_UP
);
2723 r
= sd_rtnl_message_link_set_flags(req
, 0, IFF_UP
);
2725 return log_error_errno(r
, "Could not set link flags: %m");
2727 r
= sd_netlink_call(rtnl
, req
, 0, NULL
);
2734 static int link_up_down(int argc
, char *argv
[], void *userdata
) {
2735 _cleanup_(sd_netlink_unrefp
) sd_netlink
*rtnl
= NULL
;
2736 _cleanup_set_free_ Set
*indexes
= NULL
;
2740 r
= sd_netlink_open(&rtnl
);
2742 return log_error_errno(r
, "Failed to connect to netlink: %m");
2744 indexes
= set_new(NULL
);
2748 for (int i
= 1; i
< argc
; i
++) {
2749 index
= rtnl_resolve_interface_or_warn(&rtnl
, argv
[i
]);
2753 r
= set_put(indexes
, INT_TO_PTR(index
));
2758 SET_FOREACH(p
, indexes
) {
2759 index
= PTR_TO_INT(p
);
2760 r
= link_up_down_send_message(rtnl
, argv
[0], index
);
2762 return log_error_errno(r
, "Failed to bring %s interface %s: %m",
2763 argv
[0], FORMAT_IFNAME_FULL(index
, FORMAT_IFNAME_IFINDEX
));
2769 static int link_delete(int argc
, char *argv
[], void *userdata
) {
2770 _cleanup_(sd_netlink_unrefp
) sd_netlink
*rtnl
= NULL
;
2771 _cleanup_set_free_ Set
*indexes
= NULL
;
2775 r
= sd_netlink_open(&rtnl
);
2777 return log_error_errno(r
, "Failed to connect to netlink: %m");
2779 indexes
= set_new(NULL
);
2783 for (int i
= 1; i
< argc
; i
++) {
2784 index
= rtnl_resolve_interface_or_warn(&rtnl
, argv
[i
]);
2788 r
= set_put(indexes
, INT_TO_PTR(index
));
2793 SET_FOREACH(p
, indexes
) {
2794 index
= PTR_TO_INT(p
);
2795 r
= link_delete_send_message(rtnl
, index
);
2797 return log_error_errno(r
, "Failed to delete interface %s: %m",
2798 FORMAT_IFNAME_FULL(index
, FORMAT_IFNAME_IFINDEX
));
2804 static int link_renew_one(sd_bus
*bus
, int index
, const char *name
) {
2805 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2812 r
= bus_call_method(bus
, bus_network_mgr
, "RenewLink", &error
, NULL
, "i", index
);
2814 return log_error_errno(r
, "Failed to renew dynamic configuration of interface %s: %s",
2815 name
, bus_error_message(&error
, r
));
2820 static int link_renew(int argc
, char *argv
[], void *userdata
) {
2821 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
2822 _cleanup_(sd_netlink_unrefp
) sd_netlink
*rtnl
= NULL
;
2825 r
= acquire_bus(&bus
);
2831 for (int i
= 1; i
< argc
; i
++) {
2834 index
= rtnl_resolve_interface_or_warn(&rtnl
, argv
[i
]);
2838 RET_GATHER(r
, link_renew_one(bus
, index
, argv
[i
]));
2844 static int link_force_renew_one(sd_bus
*bus
, int index
, const char *name
) {
2845 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2852 r
= bus_call_method(bus
, bus_network_mgr
, "ForceRenewLink", &error
, NULL
, "i", index
);
2854 return log_error_errno(r
, "Failed to force renew dynamic configuration of interface %s: %s",
2855 name
, bus_error_message(&error
, r
));
2860 static int link_force_renew(int argc
, char *argv
[], void *userdata
) {
2861 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
2862 _cleanup_(sd_netlink_unrefp
) sd_netlink
*rtnl
= NULL
;
2865 r
= acquire_bus(&bus
);
2869 for (int i
= 1; i
< argc
; i
++) {
2870 int index
= rtnl_resolve_interface_or_warn(&rtnl
, argv
[i
]);
2874 r
= link_force_renew_one(bus
, index
, argv
[i
]);
2875 if (r
< 0 && k
>= 0)
2882 static int verb_reload(int argc
, char *argv
[], void *userdata
) {
2883 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
2884 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2887 r
= acquire_bus(&bus
);
2891 r
= bus_call_method(bus
, bus_network_mgr
, "Reload", &error
, NULL
, NULL
);
2893 return log_error_errno(r
, "Failed to reload network settings: %s", bus_error_message(&error
, r
));
2898 static int verb_reconfigure(int argc
, char *argv
[], void *userdata
) {
2899 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
2900 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2901 _cleanup_(sd_netlink_unrefp
) sd_netlink
*rtnl
= NULL
;
2902 _cleanup_set_free_ Set
*indexes
= NULL
;
2906 r
= acquire_bus(&bus
);
2910 indexes
= set_new(NULL
);
2914 for (int i
= 1; i
< argc
; i
++) {
2915 index
= rtnl_resolve_interface_or_warn(&rtnl
, argv
[i
]);
2919 r
= set_put(indexes
, INT_TO_PTR(index
));
2924 SET_FOREACH(p
, indexes
) {
2925 index
= PTR_TO_INT(p
);
2926 r
= bus_call_method(bus
, bus_network_mgr
, "ReconfigureLink", &error
, NULL
, "i", index
);
2928 return log_error_errno(r
, "Failed to reconfigure network interface %s: %s",
2929 FORMAT_IFNAME_FULL(index
, FORMAT_IFNAME_IFINDEX
),
2930 bus_error_message(&error
, r
));
2936 static int verb_persistent_storage(int argc
, char *argv
[], void *userdata
) {
2937 _cleanup_(varlink_unrefp
) Varlink
*vl
= NULL
;
2941 r
= parse_boolean(argv
[1]);
2943 return log_error_errno(r
, "Failed to parse argument: %s", argv
[1]);
2946 r
= varlink_connect_networkd(&vl
);
2951 _cleanup_close_
int fd
= -EBADF
;
2953 fd
= open("/var/lib/systemd/network/", O_CLOEXEC
| O_DIRECTORY
);
2955 return log_error_errno(errno
, "Failed to open /var/lib/systemd/network/: %m");
2957 r
= varlink_push_fd(vl
, fd
);
2959 return log_error_errno(r
, "Failed to push file descriptor of /var/lib/systemd/network/ into varlink: %m");
2964 return varlink_callb_and_log(vl
, "io.systemd.Network.SetPersistentStorage", /* reply = */ NULL
,
2965 JSON_BUILD_OBJECT(JSON_BUILD_PAIR_BOOLEAN("Ready", ready
)));
2968 static int help(void) {
2969 _cleanup_free_
char *link
= NULL
;
2972 r
= terminal_urlify_man("networkctl", "1", &link
);
2976 printf("%s [OPTIONS...] COMMAND\n\n"
2977 "%sQuery and control the networking subsystem.%s\n"
2979 " list [PATTERN...] List links\n"
2980 " status [PATTERN...] Show link status\n"
2981 " lldp [PATTERN...] Show LLDP neighbors\n"
2982 " label Show current address label entries in the kernel\n"
2983 " delete DEVICES... Delete virtual netdevs\n"
2984 " up DEVICES... Bring devices up\n"
2985 " down DEVICES... Bring devices down\n"
2986 " renew DEVICES... Renew dynamic configurations\n"
2987 " forcerenew DEVICES... Trigger DHCP reconfiguration of all connected clients\n"
2988 " reconfigure DEVICES... Reconfigure interfaces\n"
2989 " reload Reload .network and .netdev files\n"
2990 " edit FILES|DEVICES... Edit network configuration files\n"
2991 " cat FILES|DEVICES... Show network configuration files\n"
2992 " mask FILES... Mask network configuration files\n"
2993 " unmask FILES... Unmask network configuration files\n"
2994 " persistent-storage BOOL\n"
2995 " Notify systemd-networkd if persistent storage is ready\n"
2997 " -h --help Show this help\n"
2998 " --version Show package version\n"
2999 " --no-pager Do not pipe output into a pager\n"
3000 " --no-legend Do not show the headers and footers\n"
3001 " -a --all Show status for all links\n"
3002 " -s --stats Show detailed link statistics\n"
3003 " -l --full Do not ellipsize output\n"
3004 " -n --lines=INTEGER Number of journal entries to show\n"
3005 " --json=pretty|short|off\n"
3006 " Generate JSON output\n"
3007 " --no-reload Do not reload systemd-networkd or systemd-udevd\n"
3008 " after editing network config\n"
3009 " --drop-in=NAME Edit specified drop-in instead of main config file\n"
3010 " --runtime Edit runtime config files\n"
3011 "\nSee the %s for details.\n",
3012 program_invocation_short_name
,
3020 static int parse_argv(int argc
, char *argv
[]) {
3022 ARG_VERSION
= 0x100,
3031 static const struct option options
[] = {
3032 { "help", no_argument
, NULL
, 'h' },
3033 { "version", no_argument
, NULL
, ARG_VERSION
},
3034 { "no-pager", no_argument
, NULL
, ARG_NO_PAGER
},
3035 { "no-legend", no_argument
, NULL
, ARG_NO_LEGEND
},
3036 { "all", no_argument
, NULL
, 'a' },
3037 { "stats", no_argument
, NULL
, 's' },
3038 { "full", no_argument
, NULL
, 'l' },
3039 { "lines", required_argument
, NULL
, 'n' },
3040 { "json", required_argument
, NULL
, ARG_JSON
},
3041 { "no-reload", no_argument
, NULL
, ARG_NO_RELOAD
},
3042 { "drop-in", required_argument
, NULL
, ARG_DROP_IN
},
3043 { "runtime", no_argument
, NULL
, ARG_RUNTIME
},
3052 while ((c
= getopt_long(argc
, argv
, "hasln:", options
, NULL
)) >= 0) {
3063 arg_pager_flags
|= PAGER_DISABLE
;
3071 arg_no_reload
= true;
3079 if (isempty(optarg
))
3080 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Empty drop-in file name.");
3082 if (!endswith(optarg
, ".conf")) {
3085 conf
= strjoin(optarg
, ".conf");
3089 free_and_replace(arg_drop_in
, conf
);
3091 r
= free_and_strdup(&arg_drop_in
, optarg
);
3096 if (!filename_is_valid(arg_drop_in
))
3097 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
3098 "Invalid drop-in file name '%s'.", arg_drop_in
);
3115 if (safe_atou(optarg
, &arg_lines
) < 0)
3116 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
3117 "Failed to parse lines '%s'", optarg
);
3121 r
= parse_json_argument(optarg
, &arg_json_format_flags
);
3130 assert_not_reached();
3137 static int networkctl_main(int argc
, char *argv
[]) {
3138 static const Verb verbs
[] = {
3139 { "list", VERB_ANY
, VERB_ANY
, VERB_DEFAULT
|VERB_ONLINE_ONLY
, list_links
},
3140 { "status", VERB_ANY
, VERB_ANY
, VERB_ONLINE_ONLY
, link_status
},
3141 { "lldp", VERB_ANY
, VERB_ANY
, 0, link_lldp_status
},
3142 { "label", 1, 1, 0, list_address_labels
},
3143 { "delete", 2, VERB_ANY
, 0, link_delete
},
3144 { "up", 2, VERB_ANY
, 0, link_up_down
},
3145 { "down", 2, VERB_ANY
, 0, link_up_down
},
3146 { "renew", 2, VERB_ANY
, VERB_ONLINE_ONLY
, link_renew
},
3147 { "forcerenew", 2, VERB_ANY
, VERB_ONLINE_ONLY
, link_force_renew
},
3148 { "reconfigure", 2, VERB_ANY
, VERB_ONLINE_ONLY
, verb_reconfigure
},
3149 { "reload", 1, 1, VERB_ONLINE_ONLY
, verb_reload
},
3150 { "edit", 2, VERB_ANY
, 0, verb_edit
},
3151 { "cat", 2, VERB_ANY
, 0, verb_cat
},
3152 { "mask", 2, VERB_ANY
, 0, verb_mask
},
3153 { "unmask", 2, VERB_ANY
, 0, verb_unmask
},
3154 { "persistent-storage", 2, 2, 0, verb_persistent_storage
},
3158 return dispatch_verb(argc
, argv
, verbs
, NULL
);
3161 static int run(int argc
, char* argv
[]) {
3168 r
= parse_argv(argc
, argv
);
3172 return networkctl_main(argc
, argv
);
3175 DEFINE_MAIN_FUNCTION(run
);