Commit Graph

233 Commits

Author SHA1 Message Date
Lennart Poettering 7d367b45f6 networkctl: add new call that unifies link data acquisition between "status" and "lldp" verbs 2016-02-21 20:40:57 +01:00
Lennart Poettering 1fb82beb38 networkctl: fix dispatch_verb() table
VERB_DEFAULT may only appear once.
2016-02-21 20:40:57 +01:00
Lennart Poettering 0070333f26 networkctl: split out system status stuff into its own function 2016-02-21 20:40:56 +01:00
Lennart Poettering 34437b4f9c sd-lldp: rework sd-lldp API
This reworks the sd-lldp substantially, simplifying things on one hand, and
extending the logic a bit on the other.

Specifically:

- Besides the sd_lldp object only one other object is maintained now,
  sd_lldp_neighbor. It's used both as storage for literal LLDP packets, and for
  maintainging info about peers in the database. Separation between packet, TLV
  and chassis data is not maintained anymore. This should be a major
  simplification.

- The sd-lldp API has been extended so that a couple of per-neighbor fields may
  be queried directly, without iterating through the object. Other fields that
  may appear multiple times, OTOH have to be iterated through.

- The maximum number of entries in the neighbor database is now configurable
  during runtime.

- The generation of callbacks from sd_lldp objects is more restricted:
  callbacks are only invoked when actual data changed.

- The TTL information is now hooked with a timer event, so that removals from
  the neighbor database due to TTLs now result in a callback event.

- Querying LLDP neighbor database will now return a strictly ordered array, to
  guarantee stability.

- A "capabilities" mask may now be configured, that selects what type of LLDP
  neighbor data is collected. This may be used to restrict collection of LLDP
  info about routers instead of all neighbors. This is now exposed via
  networkd's LLDP= setting.

- sd-lldp's API to serialize the collected data to text files has been removed.
  Instead, there's now an API to extract the raw binary data from LLDP neighbor
  objects, as well as one to convert this raw binary data back to an LLDP
  neighbor object. networkd will save this raw binary data to /run now, and the
  client side can simply parse the information.

- support for parsing the more exotic TLVs has been removed, since we are not
  using that. Instead there are now APIs to extract the raw data from TLVs.
  Given how easy it is to parse the TLVs clients should do so now directly
  instead of relying on our APIs for that.

- A lot of the APIs that parse out LLDP strings have been simplified so that
  they actually return strings, instead of char arrays with a length. To deal
  with possibly dangerous characters the strings are escaped if needed.

- APIs to extract and format the chassis and port IDs as strings has been
  added.

- lldp.h has been simplified a lot. The enums are anonymous now, since they
  were never used as enums, but simply as constants. Most definitions we don't
  actually use ourselves have eben removed.
2016-02-21 20:40:56 +01:00
Lennart Poettering 1c4a6088ed sd-netlink: fix ifi_iftype type
The iftype is an unsigned short, and not just an unsigned.
2016-02-20 22:42:29 +01:00
Daniel Mack b26fa1a2fb tree-wide: remove Emacs lines from all files
This should be handled fine now by .dir-locals.el, so need to carry that
stuff in every file.
2016-02-10 13:41:57 +01:00
Lennart Poettering dce8364918 networkctl: move strv_isempty() check into dump_list()
Previously, each invocation of dump_list() was prefixed with a call to strv_isempty() to suppress invocation of the
function when the list is empty anyway. Move the check into the function itself, so that we can reduce the code a bit
in size.

(Also, prefix a couple of invocations we knowingly ignore return errors with a (void) cast).
2016-01-26 14:42:03 +01:00
Lennart Poettering 3df9bec57c networkd: rework Domains= setting
Previously, .network files only knew a vaguely defined "Domains=" concept, for which the documentation declared it was
the "DNS domain" for the network connection, without specifying what that means.

With this the Domains setting is reworked, so that there are now "routing" domains and "search" domains. The former are
to be used by resolved to route DNS request to specific network interfaces, the latter is to be used for searching
single-label hostnames with (in addition to being used for routing). Both settings are configured in the "Domains="
setting. Normal domain names listed in it are now considered search domains (for compatibility with existing setups),
while those prefixed with "~" are considered routing domains only. To route all lookups to a specific interface the
routing domain "." may be used, referring to the root domain. An alternative syntax for this is the "*", as was already
implemented before using the "wildcard" domain concept.

This commit adds proper parsers for this new logic, and exposes this via the sd-network API. This information is not
used by resolved yet, this will be added in a later commit.
2016-01-26 14:42:03 +01:00
Daniel Mack d054f0a4d4 tree-wide: use xsprintf() where applicable
Also add a coccinelle receipt to help with such transitions.
2016-01-12 15:36:32 +01:00
Lennart Poettering 4afd3348c7 tree-wide: expose "p"-suffix unref calls in public APIs to make gcc cleanup easy
GLIB has recently started to officially support the gcc cleanup
attribute in its public API, hence let's do the same for our APIs.

With this patch we'll define an xyz_unrefp() call for each public
xyz_unref() call, to make it easy to use inside a
__attribute__((cleanup())) expression. Then, all code is ported over to
make use of this.

The new calls are also documented in the man pages, with examples how to
use them (well, I only added docs where the _unref() call itself already
had docs, and the examples, only cover sd_bus_unrefp() and
sd_event_unrefp()).

This also renames sd_lldp_free() to sd_lldp_unref(), since that's how we
tend to call our destructors these days.

Note that this defines no public macro that wraps gcc's attribute and
makes it easier to use. While I think it's our duty in the library to
make our stuff easy to use, I figure it's not our duty to make gcc's own
features easy to use on its own. Most likely, client code which wants to
make use of this should define its own:

       #define _cleanup_(function) __attribute__((cleanup(function)))

Or similar, to make the gcc feature easier to use.

Making this logic public has the benefit that we can remove three header
files whose only purpose was to define these functions internally.

See #2008.
2015-11-27 19:19:36 +01:00
Thomas Hindoe Paaboel Andersen cf0fbc49e6 tree-wide: sort includes
Sort the includes accoding to the new coding style.
2015-11-16 22:09:36 +01:00
Susant Sahani af40397dea networkctl: lldp port to extract_first_word 2015-11-10 22:17:58 +05:30
Lennart Poettering 6ad623a3f7 parse-util: introduce parse_ifindex() and make use of it everywhere
We have enough places where we parse an ifindex, hence introduce a
proper parsing function for it, that verifies all parameters.
2015-11-03 00:02:00 +01:00
Lennart Poettering b5efdb8af4 util-lib: split out allocation calls into alloc-util.[ch] 2015-10-27 13:45:53 +01:00
Lennart Poettering 8752c5752f util-lib: move more locale-related calls to locale-util.[ch] 2015-10-27 13:25:56 +01:00
Lennart Poettering 8b43440b7e util-lib: move string table stuff into its own string-table.[ch] 2015-10-27 13:25:56 +01:00
Lennart Poettering 6bedfcbb29 util-lib: split string parsing related calls from util.[ch] into parse-util.[ch] 2015-10-27 13:25:55 +01:00
Lennart Poettering 07630cea1f util-lib: split our string related calls from util.[ch] into its own file string-util.[ch]
There are more than enough calls doing string manipulations to deserve
its own files, hence do something about it.

This patch also sorts the #include blocks of all files that needed to be
updated, according to the sorting suggestions from CODING_STYLE. Since
pretty much every file needs our string manipulation functions this
effectively means that most files have sorted #include blocks now.

Also touches a few unrelated include files.
2015-10-24 23:05:02 +02:00
Lennart Poettering 3f6fd1ba65 util: introduce common version() implementation and use it everywhere
This also allows us to drop build.h from a ton of files, hence do so.
Since we touched the #includes of those files, let's order them properly
according to CODING_STYLE.
2015-09-29 21:08:37 +02:00
Lennart Poettering 1fc464f6fb cgtop: underline table header
Let's underline the header line of the table shown by cgtop, how it is
customary for tables. In order to do this, let's introduce new ANSI
underline macros, and clean up the existing ones as side effect.
2015-09-22 16:30:42 +02:00
Thomas Hindoe Paaboel Andersen 64d6c22905 tree-wide: do not shadow the global var timezone 2015-09-01 18:20:13 +02:00
Lennart Poettering 8eb9058dc1 dhcp,network: implement RFC 4833 (DHCP Timezone option)
This one is simply to add: encode the tzdata timezone in the DHCP
options and optionally make use of it.
2015-08-26 20:44:20 +02:00
Thomas Hindoe Paaboel Andersen 7d6884b65e tree-wide: fix indentation 2015-08-06 00:44:19 +02:00
Lennart Poettering 27ec691bfd tree-wide: convert bootchart and lldp code to use clock_boottime_or_monotonic()
We should avoid using CLOCK_BOOTTIME directly unless we actually can
sensible distuingish it from CLOCK_MONOTONIC. CLOCK_BOOTTIME is only
fully feature on very recent Linux kernels, hence we should stick to a
fallback logic, which is already available in the
clock_boottime_or_monotonic() call.
2015-08-03 17:40:46 +02:00
Tom Gundersen 1c4baffc18 sd-netlink: rename from sd-rtnl 2015-06-13 19:52:54 +02:00
Tom Gundersen 31710be527 sd-rtnl: make joining broadcast groups implicit 2015-06-11 17:47:40 +02:00
Thomas Hindoe Paaboel Andersen 920b52e490 tree-wide: remove spurious space 2015-06-08 23:11:26 +02:00
Ronny Chevalier 732b7f39a2 networkctl: fix uninitialized variable
We ignore the return value of sd_device_get_devtype, then devtype could
be uninitialized when used with streq_ptr. So we need to initialize it
first.
2015-05-30 11:19:36 +02:00
Ronny Chevalier 288a74cce5 shared: add terminal-util.[ch] 2015-04-11 00:34:02 +02:00
Tom Gundersen 914d6c09f1 networkctl: port from libudev to sd-device 2015-04-02 00:18:27 +02:00
Harald Hoyer a7f7d1bde4 fix gcc warnings about uninitialized variables
like:

src/shared/install.c: In function ‘unit_file_lookup_state’:
src/shared/install.c:1861:16: warning: ‘r’ may be used uninitialized in
this function [-Wmaybe-uninitialized]
         return r < 0 ? r : state;
                ^
src/shared/install.c:1796:13: note: ‘r’ was declared here
         int r;
             ^
2015-03-27 14:57:38 +01:00
Zbigniew Jędrzejewski-Szmek b4e3d5e14c networkctl: avoid leak if a field was specified twice
The input data would have to be borked, so this is unlikely to happen,
but since we have a nice helper function to do it properly... why not?

CID #1261390.
2015-03-07 14:06:35 -05:00
Alin Rauta 0d4ad91dd4 networkd: add support for Uplink Failure Detection
Introduce BindCarrier= to indicate the set of links that determine if
the current link should be brought UP or DOWN.

[tomegun: add a bit to commit message]
2015-02-27 13:58:30 -05:00
Zbigniew Jędrzejewski-Szmek d9000fd3b3 man: add networkctl(1) 2015-01-19 21:44:53 -05:00
Zbigniew Jędrzejewski-Szmek ba52f15a58 networkctl: avoid potential use of unitialized variables
Those values are based on a file we read from disk, so we should
verify everything we receive, and make sure everything we print
is sensible.

Also, print fractional seconds for TTL.
2015-01-01 13:36:44 -05:00
Zbigniew Jędrzejewski-Szmek 1bf7dd6e7d networkctl: remove unused variable 2015-01-01 13:36:43 -05:00
Zbigniew Jędrzejewski-Szmek ef75325319 network: fix scanf/printf format
usec_t is defined as 64 bit wide, but long is 32 bit on many archs.
2015-01-01 13:36:43 -05:00
David Herrmann fbee1d8587 networkctl: fix strappend() error checking
Make sure to test the right variable for NULL.
2014-12-31 15:56:11 +01:00
Tom Gundersen 19727828d2 networkctl: lldp - respect arg_legend 2014-12-19 08:33:46 +01:00
Susant Sahani 49699bac94 LLDP: Add support for networkctl 2014-12-19 08:15:05 +05:30
Tom Gundersen 266b538958 networkctl: port to verbs helper 2014-12-19 03:16:45 +01:00
Tom Gundersen 81fd1dd3a2 networkctl: port from libudev to sd-hwdb 2014-12-15 20:40:09 +01:00
Thomas Hindoe Paaboel Andersen b7378b89d2 networkctl: remove unused variable 2014-12-12 21:57:44 +01:00
Lennart Poettering b1acce80cd networkctl: also draw a nice unicode cirlce when "networkctl status" is run without parameters 2014-12-12 19:11:35 +01:00
Lennart Poettering 1693a943ca networkctl: show interface names next to IP addresses if we dump adresses from all interfaces 2014-12-12 19:07:26 +01:00
Lennart Poettering 69fb1176c4 networkctl: also show gateway address when "networkctl status" without further arguments is passed 2014-12-12 18:57:15 +01:00
Lennart Poettering 888943fc62 networkctl: show MAC address OUI vendor next to MAC addresses 2014-12-12 18:56:35 +01:00
Tom Gundersen b6a3ca6d87 networkctl: use the shared functions for enumerating the local gateways 2014-12-04 12:19:27 +01:00
Lennart Poettering 1d050e1e0a rtnl: when querying local addresses and gateways, take address family into account 2014-12-04 01:42:42 +01:00
Thomas Hindoe Paaboel Andersen 6c03d27d9f networkctl: remove unused variable 2014-12-03 23:51:56 +01:00
Torstein Husebø 144232a8e0 networkd: fix typo
V2: found another one
2014-12-03 21:36:10 +01:00
Tom Gundersen d8500c5378 shared: add format helpers for printing MAC addresses
Use these in networctl.
2014-12-02 14:31:16 +01:00
Tom Gundersen c09da72900 networkctl: print the Gateway in the status output
This is the IP address of the default route on the link, if present. A
description is printed when available (the manufacturer of the gateway NIC based
on its MAC address).

In the future we should prefer LLDP information over MAC info.
2014-12-02 10:46:22 +01:00
Michal Schmidt 4a62c710b6 treewide: another round of simplifications
Using the same scripts as in f647962d64 "treewide: yet more log_*_errno
+ return simplifications".
2014-11-28 19:57:32 +01:00
Michal Schmidt 56f64d9576 treewide: use log_*_errno whenever %m is in the format string
If the format string contains %m, clearly errno must have a meaningful
value, so we might as well use log_*_errno to have ERRNO= logged.

Using:
find . -name '*.[ch]' | xargs sed -r -i -e \
's/log_(debug|info|notice|warning|error|emergency)\((".*%m.*")/log_\1_errno(errno, \2/'

Plus some whitespace, linewrap, and indent adjustments.
2014-11-28 19:49:27 +01:00
Michal Schmidt f647962d64 treewide: yet more log_*_errno + return simplifications
Using:
find . -name '*.[ch]' | while read f; do perl -i.mmm -e \
 'local $/;
  local $_=<>;
  s/(if\s*\([^\n]+\))\s*{\n(\s*)(log_[a-z_]*_errno\(\s*([->a-zA-Z_]+)\s*,[^;]+);\s*return\s+\g4;\s+}/\1\n\2return \3;/msg;
  print;'
 $f
done

And a couple of manual whitespace fixups.
2014-11-28 18:56:16 +01:00
Michal Schmidt da927ba997 treewide: no need to negate errno for log_*_errno()
It corrrectly handles both positive and negative errno values.
2014-11-28 13:29:21 +01:00
Michal Schmidt 0a1beeb642 treewide: auto-convert the simple cases to log_*_errno()
As a followup to 086891e5c1 "log: add an "error" parameter to all
low-level logging calls and intrdouce log_error_errno() as log calls
that take error numbers", use sed to convert the simple cases to use
the new macros:

find . -name '*.[ch]' | xargs sed -r -i -e \
's/log_(debug|info|notice|warning|error|emergency)\("(.*)%s"(.*), strerror\(-([a-zA-Z_]+)\)\);/log_\1_errno(-\4, "\2%m"\3);/'

Multi-line log_*() invocations are not covered.
And we also should add log_unit_*_errno().
2014-11-28 12:04:41 +01:00
Tom Gundersen af5effc422 networkctl: show the link file applied to each link 2014-09-08 15:09:08 +02:00
Tom Gundersen 373d9f173f networkctl: show the network file applied to each link 2014-09-08 15:09:07 +02:00
Zbigniew Jędrzejewski-Szmek ddb7f7fc07 networkctl: do not mix dns and ntp servers 2014-08-28 09:41:29 -04:00
Thomas Hindoe Paaboel Andersen a6a4f52889 networkctl: use safe_qsort in case no links are present
Unlikely to happen but still...
2014-08-16 23:49:36 +02:00
Lennart Poettering c627729fc4 networkctl: show acquired system domains 2014-08-15 16:02:29 +02:00
Lennart Poettering 1405434b69 networkctl: two OOM fixes 2014-08-15 15:34:56 +02:00
Tom Gundersen 67272d157a sd-network: add support for wildcard domains 2014-08-15 15:15:24 +02:00
Lennart Poettering db73295acc util: never use ether_ntoa(), since it formats with %x, not %02x, which makes ethernet addresses look funny 2014-08-15 13:19:03 +02:00
Lennart Poettering 3e3db0ee86 networkctl: increase column width for link type to 18, to accomodate for 'ieee80211_radiotap' 2014-08-15 13:19:03 +02:00
Lennart Poettering 2301cb9fdb networkctl: print local domain name in status output 2014-08-15 03:10:20 +02:00
Lennart Poettering e92da1e5d0 networkctl: also use the same color logic when running "networkctl status" without arguments 2014-08-14 01:23:20 +02:00
Lennart Poettering d57c365bf8 networkctl: add the same color logic to "list" and "status" outputs
And always put operational state first, setup state second.
2014-08-14 01:18:37 +02:00
Lennart Poettering ab1525bc2d networkctl: name setup state variable setup_state 2014-08-14 01:10:08 +02:00
Lennart Poettering 2368512a31 networkctl: update column header to new 'setup' state naming 2014-08-14 01:08:46 +02:00
Tom Gundersen 438ca2bbd4 sd-networkd: rename link_get_state to link_get_setup_state
Suggested by Kay and Lennart.
2014-08-13 22:55:49 +02:00
Tom Gundersen d6731e4c79 sd-network: /_get_link_/_link_get_/
The link is the 'object', so make this in line with our usual naming convention.

Suggested by Kay and Lennart.
2014-08-13 22:37:45 +02:00
Daniel Buch 5323ead145 networkctl: color status dump without link name
Lets mimic colored operational state dump as if link name is appiled
2014-08-13 22:31:03 +02:00
Tom Gundersen 636db02d54 networkctl: add colors to admin state and fix alignment
It is useful to color in the admin state both to easily spot failed links, but also to quickly
distinguish between links that are fully configured and in degraded mode (only IPv4LL) or in
degraded mode and still waiting for DHCP.
2014-08-13 15:39:57 +02:00
Lennart Poettering f7d68aa8c9 networkctl: make networkctl status without link name show all local IP addresses 2014-08-12 16:19:37 +02:00
Lennart Poettering 6d0c65ffb4 networkctl: when outputing a list fo links, sort them by ifindex 2014-08-12 16:03:45 +02:00
Lennart Poettering df3fb561b2 networkctl: add a bit of color to the output 2014-08-12 15:41:01 +02:00
Lennart Poettering 9085f64a66 networkctl: add new switch "-a" to "networkctl status" to show verbose status of all local links 2014-08-12 15:19:30 +02:00
Lennart Poettering 1b17f21198 networkctl: properly format MAC addresses 2014-08-12 15:08:09 +02:00
Lennart Poettering 03cc0fd143 sd-network: add API to output all collected system-wide NTP and DNS servers
Also, output the collected information in "networkctl".
2014-08-12 15:06:51 +02:00
Lennart Poettering ee8c456895 networkd: add minimal client tool "networkd" to query network status
In the long run this should become a full fledged client to networkd
(but not before networkd learns bus support). For now, just pull
interesting data out of networkd, udev, and rtnl and present it to the
user, in a simple but useful output.
2014-08-12 01:54:40 +02:00