xref: /aosp_15_r20/external/libnl/src/lib/class.c (revision 4dc78e53d49367fa8e61b07018507c90983a077d)
1 /* SPDX-License-Identifier: LGPL-2.1-only */
2 /*
3  * Copyright (c) 2010-2011 Thomas Graf <[email protected]>
4  */
5 
6 /**
7  * @ingroup cli
8  * @defgroup cli_class Traffic Classes
9  * @{
10  */
11 
12 #include "nl-default.h"
13 
14 #include <netlink/cli/utils.h>
15 #include <netlink/cli/class.h>
16 
nl_cli_class_alloc(void)17 struct rtnl_class *nl_cli_class_alloc(void)
18 {
19 	struct rtnl_class *class;
20 
21 	if (!(class = rtnl_class_alloc()))
22 		nl_cli_fatal(ENOMEM, "Unable to allocate class object");
23 
24 	return class;
25 }
26 
nl_cli_class_alloc_cache(struct nl_sock * sock,int ifindex)27 struct nl_cache *nl_cli_class_alloc_cache(struct nl_sock *sock, int ifindex)
28 {
29 	struct nl_cache *cache;
30 	int err;
31 
32 	if ((err = rtnl_class_alloc_cache(sock, ifindex, &cache)) < 0)
33 		nl_cli_fatal(err, "Unable to allocate class cache: %s",
34 			     nl_geterror(err));
35 
36 	nl_cache_mngt_provide(cache);
37 
38 	return cache;
39 }
40 
41 /** @} */
42