Data Accelerator Offload
Loading...
Searching...
No Matches
Typedefs | Functions
dao_netlink.h File Reference
#include <dao_net.h>
#include <dao_util.h>
#include <linux/netlink.h>
#include <linux/xfrm.h>
#include <linux/if.h>
#include <netlink/socket.h>
#include <netlink/addr.h>
#include <dao_netlink_route.h>
#include <dao_netlink_xfrm.h>
#include <dao_log.h>

Go to the source code of this file.

Typedefs

typedef void(* dao_netlink_parse_cb_t) (struct nl_object *nl_obj, void *notifier)
 

Functions

int dao_netlink_poll (void)
 
int dao_netlink_poll_complete (void)
 
int dao_netlink_cleanup (void)
 
int dao_netlink_close (void *netlink)
 
int dao_netlink_register (int protocol, dao_netlink_parse_cb_t parse_cb, void *app_callback_ops, void *app_cookie,...)
 
int dao_netlink_nl_addr_to_in6 (struct in6_addr *ip_addr, struct nl_addr *nladdr)
 
int dao_netlink_nl_addr_to_ip_addr (dao_netlink_ip_addr_t *ip_addr, struct nl_addr *nladdr)
 
void * dao_netlink_lookup (int protocol)
 
int dao_netlink_has_poll_recv (void *netlink)
 
void * dao_netlink_socket_get (void *netlink)
 
int dao_netlink_fd_get (void *netlink)
 
void * dao_netlink_notifier_lookup_by_parse_cb (void *netlink, dao_netlink_parse_cb_t parse_cb)
 
void * dao_netlink_notifier_lookup_by_multicast_group (void *netlink, dao_netlink_parse_cb_t parse_cb, uint32_t multicast_group)
 
void * dao_netlink_notifier_callback_ops_get (void *netlink_notifier)
 
void * dao_netlink_notifier_app_cookie_get (void *netlink_notifier)
 
void * dao_netlink_notifier_nl_msg_get (void *netlink_notifier)
 

Detailed Description

DAO Netlink Notification Infra

This file, using open-source libnl library, provides low-level APIs to get netlink notifications in application. Application registers to receive notification for a netlink protocol (eg: NETLINK_ROUTE, NETLINK_XFRM, etc..) and multicast groups (eg: RTM_IP4_ROUTE, RTM_IP6_ADDR, etc..) with parse_cb function pointer which is called when a netlink message corresponding to [protocol, multicast_group] is received.

Multiple multicast groups, corresponding to a protocol, can be passed as comma-separated arguments to dao_netlink_register. In fact, calling dao_netlink_register() for each multicast group with same protocol but different parse_cb is a valid usage.

Library does not support providing different parse_cb for unique combination of [protocol, multicast_group].

On a very first call to dao_netlink_register(protocol,... ), a netlink socket is internally created(specific to protocol) which needs to be periodically polled for any new message. Applications are required to periodically call dao_netlink_poll(), in control processing context, which internally polls all opened netlink sockets. All parse_cbs are called in dao_netlink_poll() processing context.

Once parse_cb() is called in dao_netlink_poll() context, further polling to corresponding netlink socket is disabled temporarily until application does not enable it by calling dao_netlink_poll_complete() in the same control context in which dao_netlink_poll() is called. This gives flexibility to application to control when netlink socket should be polled for new message

This file defines low-level netlink infrastructure APIs where applications are supposed to parse nl_object in parse_cb using libnl library. However for NETLINK_ROUTE and NETLINK_XFRM, high-level APIs are provided by this library. Please refer to dao_netlink_route_notifier_register() and dao_netlink_xfrm_notifier_register() for more information

Definition in file dao_netlink.h.

Typedef Documentation

◆ dao_netlink_parse_cb_t

typedef void(* dao_netlink_parse_cb_t) (struct nl_object *nl_obj, void *notifier)

Application specific parse callback function of this type passed to dao_netlink_register() as an argument

Parameters
nl_objLibnl netlink object. Use libnl APIs to parse this objectk
notifierA netlink notifier object internally created by this library for registered [protocol, multicast_groups]. User can retrieve following from APIs
Returns
None

Definition at line 92 of file dao_netlink.h.

Function Documentation

◆ dao_netlink_poll()

int dao_netlink_poll ( void  )

API to call recvmsg() on all created netlink sockets for any new netlink message Must be periodically called by an application in control core context

Returns
0: Success <0: Failure

◆ dao_netlink_poll_complete()

int dao_netlink_poll_complete ( void  )

Enable polling to netlink sockets for getting new message. Required to be called after dao_netlink_poll() in control core context

Returns
0: Success <0: Failure

◆ dao_netlink_cleanup()

int dao_netlink_cleanup ( void  )

Close all opened netlink sockets and free any associated memory which is allocated by library internally

Returns
0: Success <0: Failure

◆ dao_netlink_close()

int dao_netlink_close ( void *  netlink)

Close netlink sockets and free any associated memory which is allocated by library internally for netlink object

Parameters
netlinkNetlink object created for a "netlink protocol". Can be retrieved from dao_netlink_lookup()
Returns
0: Success <0: Failure

◆ dao_netlink_register()

int dao_netlink_register ( int  protocol,
dao_netlink_parse_cb_t  parse_cb,
void *  app_callback_ops,
void *  app_cookie,
  ... 
)

Register to receive notification for netlink messages corresponding to [protocol, multicast_groups].

Parameters
protocolNetlink Protocol like NETLINK_ROUTE, NETLINK_XFRM
parse_cbParse callback of syntax dao_netlink_parse_cb_t in which caller is supposed to parse nl_obj
app_callback_opsCaller specific callback_ops which can be retrieved in parse_cb via dao_netlink_notifier_callback_ops_get(notifier)
app_cookieCaller specific app_cookie which can be retrieved in parse_cb via dao_netlink_notifier_app_cookie_get(notifier)
...Comma-separated multi-cast groups like dao_netlink_register(..., RTNL_IP4_ROUTE, RTNL_IP4_ADDR, RTNL_IP4_LINK, RTNL_IP6_LINK)
Returns
0: Success <0: Failure

◆ dao_netlink_nl_addr_to_in6()

int dao_netlink_nl_addr_to_in6 ( struct in6_addr *  ip_addr,
struct nl_addr *  nladdr 
)

Translate netlink address object to generic struct in6_addr

Parameters
[out]ip_addrPointer to ip_addr object
nladdrPointer to Netlink address object
Returns
0: Success <0: Failure

◆ dao_netlink_nl_addr_to_ip_addr()

int dao_netlink_nl_addr_to_ip_addr ( dao_netlink_ip_addr_t ip_addr,
struct nl_addr *  nladdr 
)

Translate netlink address object to generic ip address format with {struct in6_addr, prefixlen and family}

Parameters
[out]ip_addrPointer to ip_addr object
nladdrPointer to Netlink address object
Returns
0: Success <0: Failure

◆ dao_netlink_lookup()

void * dao_netlink_lookup ( int  protocol)

Retrieve netlink object specific to protocol

Parameters
protocolNetlink protocol like NETLINK_ROUTE, NETLINK_XFRM
Returns
NULL: When no netlink object is found for "netlink protocol", NON-NULL: A valid internal netlink object on which following APIs are valid
See also
dao_netlink_socket_get(), dao_netlink_fd_get(), dao_netlink_has_poll_recv()

◆ dao_netlink_has_poll_recv()

int dao_netlink_has_poll_recv ( void *  netlink)

Has netlink socket received any message from polling. Also dao_netlink_poll_complete() is yet to be called by application after dao_netlink_poll()

Parameters
netlinkNetlink object created for a "netlink protocol". Can be retrieved from dao_netlink_lookup()

◆ dao_netlink_socket_get()

void * dao_netlink_socket_get ( void *  netlink)

Get pointer to internal netlink socket created.

Parameters
netlinkNetlink object created for a "netlink protocol". Can be retrieved from dao_netlink_lookup()

◆ dao_netlink_fd_get()

int dao_netlink_fd_get ( void *  netlink)

Get file descriptor with respect to netlink object

Parameters
netlinkNetlink object created for a "netlink protocol". Can be retrieved from dao_netlink_lookup()

◆ dao_netlink_notifier_lookup_by_parse_cb()

void * dao_netlink_notifier_lookup_by_parse_cb ( void *  netlink,
dao_netlink_parse_cb_t  parse_cb 
)

Retrieve internal netlink_notifier object, if any, for a given app-specific parse_cb

A netlink notifier object corresponds to [protocol, multicast_groups] holding application specific parse_cb, app_callback_ops and app_cookie

Parameters
netlinkNetlink object created for a "netlink protocol". Can be retrieved from dao_netlink_lookup()
parse_cbdao_netlink_parse_cb_t passed by application to dao_netlink_register()
Returns
NULL: When no netlink notifier object is found for parse_cb NON-NULL: A valid internal netlink notifier object on which following APIs are valid
See also
dao_netlink_notifier_app_cookie_get(), dao_netlink_notifier_callback_ops_get(), dao_netlink_notifier_nl_msg_get()

◆ dao_netlink_notifier_lookup_by_multicast_group()

void * dao_netlink_notifier_lookup_by_multicast_group ( void *  netlink,
dao_netlink_parse_cb_t  parse_cb,
uint32_t  multicast_group 
)

Retrieve internal netlink_notifier object, if any, for a given app-specific [parse_cb, multicast_group].

A netlink notifier object corresponds to [protocol, multicast_groups] holding application specific parse_cb, app_callback_ops and app_cookie

Parameters
netlinkNetlink object created for a "netlink protocol". Can be retrieved from dao_netlink_lookup()
parse_cbdao_netlink_parse_cb_t passed by application to dao_netlink_register()
multicast_groupA multicast group which is passed as comma-separated argument to dao_netlink_register()
Returns
NULL: if netlink notifier object is not found NON_NULL: Valid internal netlink notifier object:
  • If parse_cb is passed as NULL, an internal netlink notifier object with matching multicast_group is returned.
  • If valid parse_cb is provided, an internal netlink notifier with matching [parse_cb, multicast_group] is returned

Following APIs are valid on NON-NULL returned netlink notifier object

See also
dao_netlink_notifier_app_cookie_get(), dao_netlink_notifier_callback_ops_get(). dao_netlink_notifier_nl_msg_get()

◆ dao_netlink_notifier_callback_ops_get()

void * dao_netlink_notifier_callback_ops_get ( void *  netlink_notifier)

Get app_callback_ops from netlink_notifier object which is passed to dao_netlink_register()

Parameters
netlink_notifierNetlink notifier object retrieved via
Returns
app_callback_ops passed by application in dao_netlink_register

◆ dao_netlink_notifier_app_cookie_get()

void * dao_netlink_notifier_app_cookie_get ( void *  netlink_notifier)

Get app_cookie from netlink_notifier object which is passed to dao_netlink_register()

Parameters
netlink_notifierNetlink notifier object retrieved via
Returns
app_cookie passed by application in dao_netlink_register

◆ dao_netlink_notifier_nl_msg_get()

void * dao_netlink_notifier_nl_msg_get ( void *  netlink_notifier)

Get netlink message of type "struct nl_msg", a libnl object, from netlink notifier object

Parameters
netlink_notifierNetlink notifier object received in parse_cb which is passed to dao_netlink_register()
Returns
Pointer to Netlink message is valid only a netlink message is received and dao_netlink_parse_cb_t "parse_cb" has been called by library as part of its message notification action