libnl 1.1.4
Functions

Functions

int genl_ctrl_resolve (struct nl_handle *handle, const char *name)
 Resolve generic netlink family name to its identifier.
 

Cache Management

struct nl_cache * genl_ctrl_alloc_cache (struct nl_handle *handle)
 
struct genl_family * genl_ctrl_search (struct nl_cache *cache, int id)
 Look up generic netlink family by id in the provided cache.
 

Resolver

struct genl_family * genl_ctrl_search_by_name (struct nl_cache *cache, const char *name)
 Look up generic netlink family by family name in the provided cache.
 

Detailed Description

Function Documentation

◆ genl_ctrl_alloc_cache()

struct nl_cache * genl_ctrl_alloc_cache ( struct nl_handle *  handle)

Definition at line 146 of file ctrl.c.

147{
148 struct nl_cache * cache;
149
150 cache = nl_cache_alloc(&genl_ctrl_ops);
151 if (cache == NULL)
152 return NULL;
153
154 if (handle && nl_cache_refill(handle, cache) < 0) {
155 nl_cache_free(cache);
156 return NULL;
157 }
158
159 return cache;
160}
void nl_cache_free(struct nl_cache *cache)
Free a cache.
Definition: cache.c:277
struct nl_cache * nl_cache_alloc(struct nl_cache_ops *ops)
Allocate an empty cache.
Definition: cache.c:170
int nl_cache_refill(struct nl_handle *handle, struct nl_cache *cache)
(Re)fill a cache with the contents in the kernel.
Definition: cache.c:680

◆ genl_ctrl_search()

struct genl_family * genl_ctrl_search ( struct nl_cache *  cache,
int  id 
)
Parameters
cacheGeneric netlink family cache.
idFamily identifier.

Searches through the cache looking for a registered family matching the specified identifier. The caller will own a reference on the returned object which needs to be given back after usage using genl_family_put().

Returns
Generic netlink family object or NULL if no match was found.

Definition at line 174 of file ctrl.c.

175{
176 struct genl_family *fam;
177
178 if (cache->c_ops != &genl_ctrl_ops)
179 BUG();
180
181 nl_list_for_each_entry(fam, &cache->c_items, ce_list) {
182 if (fam->gf_id == id) {
183 nl_object_get((struct nl_object *) fam);
184 return fam;
185 }
186 }
187
188 return NULL;
189}
void nl_object_get(struct nl_object *obj)
Acquire a reference on a object.
Definition: object.c:167

References nl_object_get().

◆ genl_ctrl_search_by_name()

struct genl_family * genl_ctrl_search_by_name ( struct nl_cache *  cache,
const char *  name 
)
Parameters
cacheGeneric netlink family cache.
nameFamily name.

Searches through the cache looking for a registered family matching the specified name. The caller will own a reference on the returned object which needs to be given back after usage using genl_family_put().

Returns
Generic netlink family object or NULL if no match was found.

Definition at line 208 of file ctrl.c.

210{
211 struct genl_family *fam;
212
213 if (cache->c_ops != &genl_ctrl_ops)
214 BUG();
215
216 nl_list_for_each_entry(fam, &cache->c_items, ce_list) {
217 if (!strcmp(name, fam->gf_name)) {
218 nl_object_get((struct nl_object *) fam);
219 return fam;
220 }
221 }
222
223 return NULL;
224}

References nl_object_get().

Referenced by genl_ctrl_resolve().

◆ genl_ctrl_resolve()

int genl_ctrl_resolve ( struct nl_handle *  handle,
const char *  name 
)
Parameters
handleNetlink Handle
nameName of generic netlink family

Resolves the generic netlink family name to its identifer and returns it.

Returns
A positive identifier or a negative error code.

Definition at line 238 of file ctrl.c.

239{
240 struct nl_cache *cache;
241 struct genl_family *family;
242 int err;
243
244 cache = genl_ctrl_alloc_cache(handle);
245 if (cache == NULL)
246 return nl_get_errno();
247
248 family = genl_ctrl_search_by_name(cache, name);
249 if (family == NULL) {
250 err = nl_error(ENOENT, "Generic Netlink Family not found");
251 goto errout;
252 }
253
254 err = genl_family_get_id(family);
255 genl_family_put(family);
256errout:
257 nl_cache_free(cache);
258
259 return err;
260}
struct genl_family * genl_ctrl_search_by_name(struct nl_cache *cache, const char *name)
Look up generic netlink family by family name in the provided cache.
Definition: ctrl.c:208

References genl_ctrl_search_by_name(), and nl_cache_free().