Data Accelerator Offload
|
#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) |
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 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
nl_obj | Libnl netlink object. Use libnl APIs to parse this objectk |
notifier | A netlink notifier object internally created by this library for registered [protocol, multicast_groups]. User can retrieve following from APIs
|
Definition at line 92 of file dao_netlink.h.
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
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
int dao_netlink_cleanup | ( | void | ) |
Close all opened netlink sockets and free any associated memory which is allocated by library internally
int dao_netlink_close | ( | void * | netlink | ) |
Close netlink sockets and free any associated memory which is allocated by library internally for netlink object
netlink | Netlink object created for a "netlink protocol". Can be retrieved from dao_netlink_lookup() |
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].
protocol | Netlink Protocol like NETLINK_ROUTE, NETLINK_XFRM |
parse_cb | Parse callback of syntax dao_netlink_parse_cb_t in which caller is supposed to parse nl_obj |
app_callback_ops | Caller specific callback_ops which can be retrieved in parse_cb via dao_netlink_notifier_callback_ops_get(notifier) |
app_cookie | Caller 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) |
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
[out] | ip_addr | Pointer to ip_addr object |
nladdr | Pointer to Netlink address object |
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}
[out] | ip_addr | Pointer to ip_addr object |
nladdr | Pointer to Netlink address object |
void * dao_netlink_lookup | ( | int | protocol | ) |
Retrieve netlink object specific to protocol
protocol | Netlink protocol like NETLINK_ROUTE, NETLINK_XFRM |
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()
netlink | Netlink object created for a "netlink protocol". Can be retrieved from dao_netlink_lookup() |
void * dao_netlink_socket_get | ( | void * | netlink | ) |
Get pointer to internal netlink socket created.
netlink | Netlink object created for a "netlink protocol". Can be retrieved from dao_netlink_lookup() |
int dao_netlink_fd_get | ( | void * | netlink | ) |
Get file descriptor with respect to netlink object
netlink | Netlink object created for a "netlink protocol". Can be retrieved from dao_netlink_lookup() |
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
netlink | Netlink object created for a "netlink protocol". Can be retrieved from dao_netlink_lookup() |
parse_cb | dao_netlink_parse_cb_t passed by application to dao_netlink_register() |
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
netlink | Netlink object created for a "netlink protocol". Can be retrieved from dao_netlink_lookup() |
parse_cb | dao_netlink_parse_cb_t passed by application to dao_netlink_register() |
multicast_group | A multicast group which is passed as comma-separated argument to dao_netlink_register() |
Following APIs are valid on NON-NULL returned netlink notifier object
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()
netlink_notifier | Netlink notifier object retrieved via |
void * dao_netlink_notifier_app_cookie_get | ( | void * | netlink_notifier | ) |
Get app_cookie from netlink_notifier object which is passed to dao_netlink_register()
netlink_notifier | Netlink notifier object retrieved via |
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
netlink_notifier | Netlink notifier object received in parse_cb which is passed to dao_netlink_register() |