X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fnetwork%2Fnetworkctl.c;h=035dce162b02b6e1fb9456ccb84b203bef581f27;hp=8e021888843ceee73c69dd2abc73dec82571ee8b;hb=f647962d64e844689f3e2acfce6102fc47e76df2;hpb=e92da1e5d0a3b38804e173af136ec7a076c7757e diff --git a/src/network/networkctl.c b/src/network/networkctl.c index 8e0218888..035dce162 100644 --- a/src/network/networkctl.c +++ b/src/network/networkctl.c @@ -33,6 +33,7 @@ #include "udev-util.h" #include "arphrd-list.h" #include "local-addresses.h" +#include "socket-util.h" static bool arg_no_pager = false; static bool arg_legend = true; @@ -140,7 +141,7 @@ static int decode_and_sort_links(sd_rtnl_message *m, LinkInfo **ret) { c++; } - qsort(links, c, sizeof(LinkInfo), link_info_compare); + qsort_safe(links, c, sizeof(LinkInfo), link_info_compare); *ret = links; links = NULL; @@ -189,10 +190,8 @@ static int list_links(char **args, unsigned n) { pager_open_if_enabled(); r = sd_rtnl_open(&rtnl, 0); - if (r < 0) { - log_error("Failed to connect to netlink: %s", strerror(-r)); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to connect to netlink: %m"); udev = udev_new(); if (!udev) { @@ -209,13 +208,11 @@ static int list_links(char **args, unsigned n) { return rtnl_log_create_error(r); r = sd_rtnl_call(rtnl, req, 0, &reply); - if (r < 0) { - log_error("Failed to enumerate links: %s", strerror(-r)); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to enumerate links: %m"); if (arg_legend) - printf("%3s %-16s %-10s %-11s %-10s\n", "IDX", "LINK", "TYPE", "OPERATIONAL", "SETUP"); + printf("%3s %-16s %-18s %-11s %-10s\n", "IDX", "LINK", "TYPE", "OPERATIONAL", "SETUP"); c = decode_and_sort_links(reply, &links); if (c < 0) @@ -240,7 +237,7 @@ static int list_links(char **args, unsigned n) { link_get_type_string(links[i].iftype, d, &t); - printf("%3i %-16s %-10s %s%-11s%s %s%-10s%s\n", + printf("%3i %-16s %-18s %s%-11s%s %s%-10s%s\n", links[i].ifindex, links[i].name, strna(t), on_color_operational, strna(operational_state), off_color_operational, on_color_setup, strna(setup_state), off_color_setup); @@ -288,13 +285,13 @@ static void dump_list(const char *prefix, char **l) { } static int link_status_one(sd_rtnl *rtnl, struct udev *udev, const char *name) { - _cleanup_strv_free_ char **dns = NULL, **ntp = NULL; + _cleanup_strv_free_ char **dns = NULL, **ntp = NULL, **domains = NULL; _cleanup_free_ char *setup_state = NULL, *operational_state = NULL; _cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL, *reply = NULL; _cleanup_udev_device_unref_ struct udev_device *d = NULL; char devid[2 + DECIMAL_STR_MAX(int)]; - _cleanup_free_ char *t = NULL; - const char *driver = NULL, *path = NULL, *vendor = NULL, *model = NULL; + _cleanup_free_ char *t = NULL, *network = NULL; + const char *driver = NULL, *path = NULL, *vendor = NULL, *model = NULL, *link = NULL; const char *on_color_operational, *off_color_operational, *on_color_setup, *off_color_setup; struct ether_addr e; @@ -321,10 +318,8 @@ static int link_status_one(sd_rtnl *rtnl, struct udev *udev, const char *name) { return rtnl_log_create_error(r); r = sd_rtnl_call(rtnl, req, 0, &reply); - if (r < 0) { - log_error("Failed to query link: %s", strerror(-r)); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to query link: %m"); r = sd_rtnl_message_link_get_ifindex(reply, &ifindex); if (r < 0) @@ -364,6 +359,18 @@ static int link_status_one(sd_rtnl *rtnl, struct udev *udev, const char *name) { sd_network_link_get_dns(ifindex, &dns); sd_network_link_get_ntp(ifindex, &ntp); + sd_network_link_get_domains(ifindex, &domains); + r = sd_network_link_get_wildcard_domain(ifindex); + if (r > 0) { + char *wildcard; + + wildcard = strdup("*"); + if (!wildcard) + return log_oom(); + + if (strv_consume(&domains, wildcard) < 0) + return log_oom(); + } sprintf(devid, "n%i", ifindex); d = udev_device_new_from_device_id(udev, devid); @@ -371,6 +378,7 @@ static int link_status_one(sd_rtnl *rtnl, struct udev *udev, const char *name) { link_get_type_string(iftype, d, &t); if (d) { + link = udev_device_get_property_value(d, "ID_NET_LINK_FILE"); driver = udev_device_get_property_value(d, "ID_NET_DRIVER"); path = udev_device_get_property_value(d, "ID_PATH"); @@ -383,11 +391,16 @@ static int link_status_one(sd_rtnl *rtnl, struct udev *udev, const char *name) { model = udev_device_get_property_value(d, "ID_MODEL"); } + sd_network_link_get_network_file(ifindex, &network); printf("%s%s%s %i: %s\n", on_color_operational, draw_special_char(DRAW_BLACK_CIRCLE), off_color_operational, ifindex, name); - printf(" Type: %s\n" + printf(" Link File: %s\n" + "Network File: %s\n" + " Type: %s\n" " State: %s%s%s (%s%s%s)\n", + strna(link), + strna(network), strna(t), on_color_operational, strna(operational_state), off_color_operational, on_color_setup, strna(setup_state), off_color_setup); @@ -401,8 +414,10 @@ static int link_status_one(sd_rtnl *rtnl, struct udev *udev, const char *name) { if (model) printf(" Model: %s\n", model); - if (have_mac) - printf(" HW Address: %s\n", ether_ntoa(&e)); + if (have_mac) { + char ea[ETHER_ADDR_TO_STRING_MAX]; + printf(" HW Address: %s\n", ether_addr_to_string(&e, ea)); + } if (mtu > 0) printf(" MTU: %u\n", mtu); @@ -411,6 +426,8 @@ static int link_status_one(sd_rtnl *rtnl, struct udev *udev, const char *name) { if (!strv_isempty(dns)) dump_list(" DNS: ", dns); + if (!strv_isempty(domains)) + dump_list(" Domain: ", domains); if (!strv_isempty(ntp)) dump_list(" NTP: ", ntp); @@ -424,10 +441,8 @@ static int link_status(char **args, unsigned n) { int r; r = sd_rtnl_open(&rtnl, 0); - if (r < 0) { - log_error("Failed to connect to netlink: %s", strerror(-r)); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to connect to netlink: %m"); udev = udev_new(); if (!udev) { @@ -437,7 +452,7 @@ static int link_status(char **args, unsigned n) { if (n <= 1 && !arg_all) { _cleanup_free_ char *operational_state = NULL; - _cleanup_strv_free_ char **dns = NULL, **ntp = NULL; + _cleanup_strv_free_ char **dns = NULL, **ntp = NULL, **domains = NULL; _cleanup_free_ struct local_address *addresses = NULL; const char *on_color_operational, *off_color_operational; int i, c; @@ -463,7 +478,11 @@ static int link_status(char **args, unsigned n) { if (!strv_isempty(dns)) dump_list(" DNS: ", dns); - sd_network_get_dns(&ntp); + sd_network_get_domains(&domains); + if (!strv_isempty(domains)) + dump_list(" Domain: ", domains); + + sd_network_get_ntp(&ntp); if (!strv_isempty(ntp)) dump_list(" NTP: ", ntp); @@ -486,10 +505,8 @@ static int link_status(char **args, unsigned n) { return rtnl_log_create_error(r); r = sd_rtnl_call(rtnl, req, 0, &reply); - if (r < 0) { - log_error("Failed to enumerate links: %s", strerror(-r)); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to enumerate links: %m"); c = decode_and_sort_links(reply, &links); if (c < 0)