mptcpd
Multipath TCP Daemon
Loading...
Searching...
No Matches
Classes | Macros | Typedefs | Functions
network_monitor.c File Reference

mptcpd network device monitoring. More...

#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <linux/rtnetlink.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <netinet/in.h>
#include <ell/ell.h>
#include <mptcpd/private/path_manager.h>
#include <mptcpd/private/sockaddr.h>
#include <mptcpd/private/network_monitor.h>
#include <mptcpd/network_monitor.h>
Include dependency graph for network_monitor.c:

Classes

struct  nm_ops_info
 Network monitoring event tracking callback information. More...
 
struct  mptcpd_nm
 Data needed to run the network monitor. More...
 
struct  mptcpd_rtm_addr
 Encapsulate network address information. More...
 
struct  nm_addr_info
 Convenience structure to bundle address information. More...
 
struct  mptcpd_interface_callback_data
 Callback information supplied by the user. More...
 

Macros

#define _POSIX_C_SOURCE   200112L
 For XSI-compliant strerror_r().
 
#define _DEFAULT_SOURCE
 For standard network interface flags.
 
#define MPTCPD_MAX_ROUTE_CHECK   3
 

Typedefs

typedef void(* handle_ifaddr_func_t) (struct mptcpd_nm *nm, struct mptcpd_interface *interface, struct mptcpd_rtm_addr const *rtm_addr)
 Network address handler function signature.
 

Functions

struct mptcpd_nmmptcpd_nm_create (uint32_t flags)
 Create a network monitor.
 
void mptcpd_nm_destroy (struct mptcpd_nm *nm)
 Destroy a network monitor.
 
void mptcpd_nm_foreach_interface (struct mptcpd_nm const *nm, mptcpd_nm_callback callback, void *callback_data)
 Iterate over all monitored network interfaces.
 
bool mptcpd_nm_register_ops (struct mptcpd_nm *nm, struct mptcpd_nm_ops const *ops, void *user_data)
 Subscribe to mptcpd network monitor events.
 
bool mptcpd_nm_monitor_loopback (struct mptcpd_nm *nm, bool enable)
 Enable monitoring of the loopback network interface.
 

Detailed Description

mptcpd network device monitoring.

Copyright (c) 2017-2022, 2024, Intel Corporation

Function Documentation

◆ mptcpd_nm_create()

struct mptcpd_nm * mptcpd_nm_create ( uint32_t  flags)

Create a network monitor.

Parameters
[in]flagsFlags controlling address notification, any of: MPTCPD_NOTIFY_FLAG_EXISTING, MPTCPD_NOTIFY_FLAG_SKIP_LL, MPTCPD_NOTIFY_FLAG_SKIP_HOST
Todo:
As currently implemented, one could create multiple network monitors. Is that useful?
Returns
Pointer to new network monitor on success. NULL on failure.

Get network interface information.

Note
We force the second rtnetlink command, RTM_GETADDR, to be sent after this one completes by doing so in the destroy callback for this command. That guarantees that the potential multipart message response from this dump is fully read prior to sending the second command. This works around an issue in ELL where it was possible that the second command would be sent prior to receiving all of the parts of the multipart RTM_GETLINK response, which resulted in an EBUSY error.

◆ mptcpd_nm_destroy()

void mptcpd_nm_destroy ( struct mptcpd_nm nm)

Destroy a network monitor.

Parameters
[in,out]nmNetwork monitor to be destroyed.

◆ mptcpd_nm_foreach_interface()

void mptcpd_nm_foreach_interface ( struct mptcpd_nm const *  nm,
mptcpd_nm_callback  callback,
void *  data 
)

Iterate over all monitored network interfaces.

Parameters
[in]nmPointer to the mptcpd network monitor object.
[in]callbackFunction to be called during each network interface iteration.
[in]dataData to pass to the callback function during each iteration.

◆ mptcpd_nm_monitor_loopback()

bool mptcpd_nm_monitor_loopback ( struct mptcpd_nm nm,
bool  enable 
)

Enable monitoring of the loopback network interface.

Mptcpd normally only monitors non-loopback network interfaces. Call this function to enable monitoring of loopback network interfaces.

Note
Mptcpd monitoring of loopback network interfaces is meant primarily for testing purposes.
Parameters
[in,out]nmPointer to the mptcpd network monitor object.
[in]enableEnable or disable monitoring of loopback network interfaces.
Return values
trueSuccessfully enable or disabled.
falseInvalid nm argument.

◆ mptcpd_nm_register_ops()

bool mptcpd_nm_register_ops ( struct mptcpd_nm nm,
struct mptcpd_nm_ops const *  ops,
void *  user_data 
)

Subscribe to mptcpd network monitor events.

Register a set of operations that will be called on a corresponding mptcpd network monitoring event, e.g. network interface or address addition, update, or removal.

Parameters
[in,out]nmPointer to the mptcpd network monitor object.
[in]opsSet of network monitoring event handling functions.
[in]user_dataData to be passed to the network event tracking operations.
Return values
trueRegistration succeeded.
falseRegistration failed.