Logo Search packages:      
Sourcecode: libnl2 version File versions  Download package


Detailed Description

Helps keeping caches up to date.

The purpose of a cache manager is to keep track of caches and automatically receive event notifications to keep the caches up to date with the kernel state. Each manager has exactly one netlink socket assigned which limits the scope of each manager to exactly one netlink family. Therefore all caches committed to a manager must be part of the same netlink family. Due to the nature of a manager, it is not possible to have a cache maintain two instances of the same cache type. The socket is subscribed to the event notification group of each cache and also put into non-blocking mode. Functions exist to poll() on the socket to wait for new events to be received.

 App       libnl                        Kernel
        |                            |
            +-----------------+        [ notification, link change ]
        |   |  Cache Manager  |      | [   (IFF_UP | IFF_RUNNING)  ]
            |                 |                |
        |   |   +------------+|      |         |  [ notification, new addr ]
    <-------|---| route/link |<-------(async)--+  [ dev eth1  ]
        |   |   +------------+|      |                      |
            |   +------------+|                             |
    <---|---|---| route/addr |<------|-(async)--------------+
            |   +------------+|
        |   |   +------------+|      |
    <-------|---| ...        ||
        |   |   +------------+|      |
        |                            |

1) Creating a new cache manager
 struct nl_cache_mngr *mngr;

 // Allocate a new cache manager for RTNETLINK and automatically
 // provide the caches added to the manager.
 mngr = nl_cache_mngr_alloc(NETLINK_ROUTE, NL_AUTO_PROVIDE);
2) Keep track of a cache
 struct nl_cache *cache;

 // Create a new cache for links/interfaces and ask the manager to
 // keep it up to date for us. This will trigger a full dump request
 // to initially fill the cache.
 cache = nl_cache_mngr_add(mngr, "route/link");
3) Make the manager receive updates
 // Give the manager the ability to receive updates, will call poll()
 // with a timeout of 5 seconds.
 if (nl_cache_mngr_poll(mngr, 5000) > 0) {
         // Manager received at least one update, dump cache?
         nl_cache_dump(cache, ...);
4) Release cache manager


static int event_input (struct nl_msg *msg, void *arg)
static int include_cb (struct nl_object *obj, struct nl_parser_param *p)
int nl_cache_mngr_add (struct nl_cache_mngr *mngr, const char *name, change_func_t cb, struct nl_cache **result)
int nl_cache_mngr_alloc (struct nl_sock *sk, int protocol, int flags, struct nl_cache_mngr **result)
int nl_cache_mngr_data_ready (struct nl_cache_mngr *mngr)
void nl_cache_mngr_free (struct nl_cache_mngr *mngr)
int nl_cache_mngr_get_fd (struct nl_cache_mngr *mngr)
int nl_cache_mngr_poll (struct nl_cache_mngr *mngr, int timeout)

Generated by  Doxygen 1.6.0   Back to index