sd-network.h revision 6436165dbc500f14abfec738af28f87a71f6a12a
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen
82bdf8ce36ccfe1b6ff389a9c9c7e2b2d049a43dTom Gundersen#ifndef foosdnetworkhfoo
82bdf8ce36ccfe1b6ff389a9c9c7e2b2d049a43dTom Gundersen#define foosdnetworkhfoo
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen/***
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen This file is part of systemd.
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen Copyright 2011 Lennart Poettering
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen Copyright 2014 Tom Gundersen
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen systemd is free software; you can redistribute it and/or modify it
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen under the terms of the GNU Lesser General Public License as published by
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen the Free Software Foundation; either version 2.1 of the License, or
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen (at your option) any later version.
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen systemd is distributed in the hope that it will be useful, but
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen WITHOUT ANY WARRANTY; without even the implied warranty of
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen Lesser General Public License for more details.
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen You should have received a copy of the GNU Lesser General Public License
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen along with systemd; If not, see <http://www.gnu.org/licenses/>.
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen***/
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen#include <sys/types.h>
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen#include <inttypes.h>
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen#include "sd-dhcp-lease.h"
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen#include "_sd-common.h"
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen/*
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen * A few points:
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen *
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen * Instead of returning an empty string array or empty integer array, we
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen * may return NULL.
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen *
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen * Free the data the library returns with libc free(). String arrays
10b17992ee59ac1d03d6fc210a976bc2b59f6d75Jason St. John * are NULL terminated, and you need to free the array itself in
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen * addition to the strings contained.
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen *
10b17992ee59ac1d03d6fc210a976bc2b59f6d75Jason St. John * We return error codes as negative errno, kernel-style. On success, we
10b17992ee59ac1d03d6fc210a976bc2b59f6d75Jason St. John * return 0 or positive.
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen *
10b17992ee59ac1d03d6fc210a976bc2b59f6d75Jason St. John * These functions access data in /run. This is a virtual file system;
10b17992ee59ac1d03d6fc210a976bc2b59f6d75Jason St. John * therefore, accesses are relatively cheap.
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen *
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen * See sd-network(3) for more information.
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen */
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen_SD_BEGIN_DECLARATIONS;
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen
6436165dbc500f14abfec738af28f87a71f6a12aLennart Poettering/* Get overall operational state
6436165dbc500f14abfec738af28f87a71f6a12aLennart Poettering * Possible states: unknown, dormant, carrier, degraded, routable
6436165dbc500f14abfec738af28f87a71f6a12aLennart Poettering * Possible return codes:
6436165dbc500f14abfec738af28f87a71f6a12aLennart Poettering * -ENODATA: networkd is not aware of any links
6436165dbc500f14abfec738af28f87a71f6a12aLennart Poettering */
6436165dbc500f14abfec738af28f87a71f6a12aLennart Poetteringint sd_network_get_operational_state(char **state);
6436165dbc500f14abfec738af28f87a71f6a12aLennart Poettering
deb2e5230b4dcbc0e2e02cc47a0b2d0d7179a044Tom Gundersen/* Get state from ifindex.
560852ced07a647e2d288ce2932aaf608712867dTom Gundersen * Possible states: failed, configuring, configured, unmanaged
deb2e5230b4dcbc0e2e02cc47a0b2d0d7179a044Tom Gundersen * Possible return codes:
deb2e5230b4dcbc0e2e02cc47a0b2d0d7179a044Tom Gundersen * -ENODATA: networkd is not aware of the link
deb2e5230b4dcbc0e2e02cc47a0b2d0d7179a044Tom Gundersen * -EBUSY: udev is still processing the link, networkd does not yet know if it will manage it
deb2e5230b4dcbc0e2e02cc47a0b2d0d7179a044Tom Gundersen */
6dcaa6f59a39dd4acc67fc2e4873c37e2ed46430Tom Gundersenint sd_network_get_link_state(int ifindex, char **state);
deb2e5230b4dcbc0e2e02cc47a0b2d0d7179a044Tom Gundersen
deb2e5230b4dcbc0e2e02cc47a0b2d0d7179a044Tom Gundersen/* Get operatinal state from ifindex.
e375dcde7202d5df4e29f5258e0f8c2bcea4535cTom Gundersen * Possible states: unknown, dormant, carrier, degraded, routable
deb2e5230b4dcbc0e2e02cc47a0b2d0d7179a044Tom Gundersen * Possible return codes:
deb2e5230b4dcbc0e2e02cc47a0b2d0d7179a044Tom Gundersen * -ENODATA: networkd is not aware of the link
deb2e5230b4dcbc0e2e02cc47a0b2d0d7179a044Tom Gundersen */
6dcaa6f59a39dd4acc67fc2e4873c37e2ed46430Tom Gundersenint sd_network_get_link_operational_state(int ifindex, char **state);
deb2e5230b4dcbc0e2e02cc47a0b2d0d7179a044Tom Gundersen
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen/* Get DHCPv4 lease from ifindex. */
6436165dbc500f14abfec738af28f87a71f6a12aLennart Poetteringint sd_network_get_link_dhcp_lease(int ifindex, sd_dhcp_lease **ret);
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen
bd8f65387673e29f46136a4ed172097035002c23Tom Gundersen/* Indicates whether or not LLMNR should be enabled for the link
bd8f65387673e29f46136a4ed172097035002c23Tom Gundersen * Possible levels of support: yes, no, resolve
bd8f65387673e29f46136a4ed172097035002c23Tom Gundersen * Possible return codes:
bd8f65387673e29f46136a4ed172097035002c23Tom Gundersen * -ENODATA: networkd is not aware of the link*/
6436165dbc500f14abfec738af28f87a71f6a12aLennart Poetteringint sd_network_get_link_llmnr(int ifindex, char **llmnr);
bd8f65387673e29f46136a4ed172097035002c23Tom Gundersen
6f4dedb250f2d607eceefaa491f338becbeee7c0Tom Gundersen/* Get DNS entries for a given link. These are string representations of
6f4dedb250f2d607eceefaa491f338becbeee7c0Tom Gundersen * IP addresses */
6436165dbc500f14abfec738af28f87a71f6a12aLennart Poetteringint sd_network_get_link_dns(int ifindex, char ***addr);
7dbf94a9c4dcdf9b56384e66eb2652fb61da5063Tom Gundersen
6f4dedb250f2d607eceefaa491f338becbeee7c0Tom Gundersen/* Get NTP entries for a given link. These are domain names or string
6f4dedb250f2d607eceefaa491f338becbeee7c0Tom Gundersen * reperesentations of IP addresses */
6436165dbc500f14abfec738af28f87a71f6a12aLennart Poetteringint sd_network_get_link_ntp(int ifindex, char ***addr);
7dbf94a9c4dcdf9b56384e66eb2652fb61da5063Tom Gundersen
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen/* Monitor object */
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersentypedef struct sd_network_monitor sd_network_monitor;
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen
7e141e498c73ec7c8b61a0df37c4937f1d6becc7Tom Gundersen/* Create a new monitor. Category must be NULL, "links" or "leases". */
0014a4ad505d119c7ac4346d9d774c3f17f663a5Lennart Poetteringint sd_network_monitor_new(sd_network_monitor **ret, const char *category);
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen/* Destroys the passed monitor. Returns NULL. */
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersensd_network_monitor* sd_network_monitor_unref(sd_network_monitor *m);
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen/* Flushes the monitor */
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersenint sd_network_monitor_flush(sd_network_monitor *m);
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen/* Get FD from monitor */
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersenint sd_network_monitor_get_fd(sd_network_monitor *m);
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen/* Get poll() mask to monitor */
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersenint sd_network_monitor_get_events(sd_network_monitor *m);
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen/* Get timeout for poll(), as usec value relative to CLOCK_MONOTONIC's epoch */
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersenint sd_network_monitor_get_timeout(sd_network_monitor *m, uint64_t *timeout_usec);
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen_SD_END_DECLARATIONS;
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen
fe8db0c5ee3365a2fc80ee7ebffa238f9a0a2ae2Tom Gundersen#endif