Systemd/src/systemd/sd-network.h
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

177 lines
6.1 KiB
C

#ifndef foosdnetworkhfoo
#define foosdnetworkhfoo
/***
This file is part of systemd.
Copyright 2011 Lennart Poettering
Copyright 2014 Tom Gundersen
systemd is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <inttypes.h>
#include <sys/types.h>
#include "_sd-common.h"
/*
* A few points:
*
* Instead of returning an empty string array or empty integer array, we
* may return NULL.
*
* Free the data the library returns with libc free(). String arrays
* are NULL terminated, and you need to free the array itself in
* addition to the strings contained.
*
* We return error codes as negative errno, kernel-style. On success, we
* return 0 or positive.
*
* These functions access data in /run. This is a virtual file system;
* therefore, accesses are relatively cheap.
*
* See sd-network(3) for more information.
*/
_SD_BEGIN_DECLARATIONS;
/* Get overall operational state
* Possible states: down, up, dormant, carrier, degraded, routable
* Possible return codes:
* -ENODATA: networkd is not aware of any links
*/
int sd_network_get_operational_state(char **state);
/* Get DNS entries for all links. These are string representations of
* IP addresses */
int sd_network_get_dns(char ***dns);
/* Get NTP entries for all links. These are domain names or string
* representations of IP addresses */
int sd_network_get_ntp(char ***ntp);
/* Get the search domains for all links. */
int sd_network_get_search_domains(char ***domains);
/* Get the search domains for all links. */
int sd_network_get_route_domains(char ***domains);
/* Get setup state from ifindex.
* Possible states:
* pending: udev is still processing the link, we don't yet know if we will manage it
* failed: networkd failed to manage the link
* configuring: in the process of retrieving configuration or configuring the link
* configured: link configured successfully
* unmanaged: networkd is not handling the link
* linger: the link is gone, but has not yet been dropped by networkd
* Possible return codes:
* -ENODATA: networkd is not aware of the link
*/
int sd_network_link_get_setup_state(int ifindex, char **state);
/* Get operational state from ifindex.
* Possible states:
* off: the device is powered down
* no-carrier: the device is powered up, but it does not yet have a carrier
* dormant: the device has a carrier, but is not yet ready for normal traffic
* carrier: the link has a carrier
* degraded: the link has carrier and addresses valid on the local link configured
* routable: the link has carrier and routable address configured
* Possible return codes:
* -ENODATA: networkd is not aware of the link
*/
int sd_network_link_get_operational_state(int ifindex, char **state);
/* Get path to .network file applied to link */
int sd_network_link_get_network_file(int ifindex, char **filename);
/* Get DNS entries for a given link. These are string representations of
* IP addresses */
int sd_network_link_get_dns(int ifindex, char ***addr);
/* Get NTP entries for a given link. These are domain names or string
* representations of IP addresses */
int sd_network_link_get_ntp(int ifindex, char ***addr);
/* Indicates whether or not LLMNR should be enabled for the link
* Possible levels of support: yes, no, resolve
* Possible return codes:
* -ENODATA: networkd is not aware of the link
*/
int sd_network_link_get_llmnr(int ifindex, char **llmnr);
/* Indicates whether or not MulticastDNS should be enabled for the
* link.
* Possible levels of support: yes, no, resolve
* Possible return codes:
* -ENODATA: networkd is not aware of the link
*/
int sd_network_link_get_mdns(int ifindex, char **mdns);
/* Indicates whether or not DNSSEC should be enabled for the link
* Possible levels of support: yes, no, allow-downgrade
* Possible return codes:
* -ENODATA: networkd is not aware of the link
*/
int sd_network_link_get_dnssec(int ifindex, char **dnssec);
/* Returns the list of per-interface DNSSEC negative trust anchors
* Possible return codes:
* -ENODATA: networkd is not aware of the link, or has no such data
*/
int sd_network_link_get_dnssec_negative_trust_anchors(int ifindex, char ***nta);
/* Get the search DNS domain names for a given link. */
int sd_network_link_get_search_domains(int ifindex, char ***domains);
/* Get the route DNS domain names for a given link. */
int sd_network_link_get_route_domains(int ifindex, char ***domains);
/* Get the CARRIERS to which current link is bound to. */
int sd_network_link_get_carrier_bound_to(int ifindex, char ***carriers);
/* Get the CARRIERS that are bound to current link. */
int sd_network_link_get_carrier_bound_by(int ifindex, char ***carriers);
/* Get the timezone that was learnt on a specific link. */
int sd_network_link_get_timezone(int ifindex, char **timezone);
/* Monitor object */
typedef struct sd_network_monitor sd_network_monitor;
/* Create a new monitor. Category must be NULL, "links" or "leases". */
int sd_network_monitor_new(sd_network_monitor **ret, const char *category);
/* Destroys the passed monitor. Returns NULL. */
sd_network_monitor* sd_network_monitor_unref(sd_network_monitor *m);
/* Flushes the monitor */
int sd_network_monitor_flush(sd_network_monitor *m);
/* Get FD from monitor */
int sd_network_monitor_get_fd(sd_network_monitor *m);
/* Get poll() mask to monitor */
int sd_network_monitor_get_events(sd_network_monitor *m);
/* Get timeout for poll(), as usec value relative to CLOCK_MONOTONIC's epoch */
int sd_network_monitor_get_timeout(sd_network_monitor *m, uint64_t *timeout_usec);
_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_network_monitor, sd_network_monitor_unref);
_SD_END_DECLARATIONS;
#endif