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/netlink.h>`
`#include <ell/log.h>`
`#include <ell/util.h>`
`#include <ell/queue.h>`
`#include <ell/timeout.h>`
`#include <ell/rtnl.h>`
`#include <mptcpd/private/path_manager.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_nm * | mptcpd_nm_create (uint32_t flags)
| Create a network monitor. More...
void | mptcpd_nm_destroy (struct mptcpd_nm *nm)
| Destroy a network monitor. More...
void | mptcpd_nm_foreach_interface (struct mptcpd_nm const *nm, mptcpd_nm_callback callback, void *callback_data)
| Iterate over all monitored network interfaces. More...
bool | mptcpd_nm_register_ops (struct mptcpd_nm *nm, struct mptcpd_nm_ops const *ops, void *user_data)
| Subscribe to mptcpd network monitor events. More...

## Detailed Description

mptcpd network device monitoring.

Copyright (c) 2017-2021, Intel Corporation

## Function Documentation

## mptcpd_nm_create()

struct mptcpd_nm* mptcpd_nm_create | ( | uint32_t | flags | ) |

Create a network monitor.

Parameters

  [in] | flags | flags 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] | nm | Network 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] | nm | Pointer to the mptcpd network monitor object.
  [in] | callback | Function to be called during each network interface iteration.
  [in] | data | Data to pass to the callback function during each iteration.

## 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] | nm | Pointer to the mptcpd network monitor object.
  [in] | ops | Set of network monitoring event handling functions.
  [in] | user_data | Data to be passed to the network event tracking operations.

Return values

  true | Registration succeeded.
  false | Registration failed.