• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: LGPL-2.1-only */
2 /*
3  * lib/idiag/idiagnl_meminfo_obj.c Inet Diag Meminfo Object
4  *
5  *	This library is free software; you can redistribute it and/or
6  *	modify it under the terms of the GNU Lesser General Public
7  *	License as published by the Free Software Foundation version 2.1
8  *	of the License.
9  *
10  * Copyright (c) 2013 Sassano Systems LLC <joe@sassanosystems.com>
11  */
12 
13 #include <netlink-private/netlink.h>
14 #include <netlink/idiag/meminfo.h>
15 
16 /**
17  * @ingroup idiag
18  * @defgroup idiagnl_meminfo Inet Diag Memory Info
19  *
20  * @details
21  * @idiagnl_doc{idiagnl_meminfo, Inet Diag Memory Info Documentation}
22  * @{
23  */
idiagnl_meminfo_alloc(void)24 struct idiagnl_meminfo *idiagnl_meminfo_alloc(void)
25 {
26 	return (struct idiagnl_meminfo *) nl_object_alloc(&idiagnl_meminfo_obj_ops);
27 }
28 
idiagnl_meminfo_get(struct idiagnl_meminfo * minfo)29 void idiagnl_meminfo_get(struct idiagnl_meminfo *minfo)
30 {
31 	nl_object_get((struct nl_object *) minfo);
32 }
33 
idiagnl_meminfo_put(struct idiagnl_meminfo * minfo)34 void idiagnl_meminfo_put(struct idiagnl_meminfo *minfo)
35 {
36 	nl_object_put((struct nl_object *) minfo);
37 }
38 
39 /**
40  * @name Attributes
41  * @{
42  */
idiagnl_meminfo_get_rmem(const struct idiagnl_meminfo * minfo)43 uint32_t idiagnl_meminfo_get_rmem(const struct idiagnl_meminfo *minfo)
44 {
45 	return minfo->idiag_rmem;
46 }
47 
idiagnl_meminfo_set_rmem(struct idiagnl_meminfo * minfo,uint32_t rmem)48 void idiagnl_meminfo_set_rmem(struct idiagnl_meminfo *minfo, uint32_t rmem)
49 {
50 	minfo->idiag_rmem = rmem;
51 }
52 
idiagnl_meminfo_get_wmem(const struct idiagnl_meminfo * minfo)53 uint32_t idiagnl_meminfo_get_wmem(const struct idiagnl_meminfo *minfo)
54 {
55 	return minfo->idiag_wmem;
56 }
57 
idiagnl_meminfo_set_wmem(struct idiagnl_meminfo * minfo,uint32_t wmem)58 void idiagnl_meminfo_set_wmem(struct idiagnl_meminfo *minfo, uint32_t wmem)
59 {
60 	minfo->idiag_wmem = wmem;
61 }
62 
idiagnl_meminfo_get_fmem(const struct idiagnl_meminfo * minfo)63 uint32_t idiagnl_meminfo_get_fmem(const struct idiagnl_meminfo *minfo)
64 {
65 	return minfo->idiag_fmem;
66 }
67 
idiagnl_meminfo_set_fmem(struct idiagnl_meminfo * minfo,uint32_t fmem)68 void idiagnl_meminfo_set_fmem(struct idiagnl_meminfo *minfo, uint32_t fmem)
69 {
70 	minfo->idiag_fmem = fmem;
71 }
72 
idiagnl_meminfo_get_tmem(const struct idiagnl_meminfo * minfo)73 uint32_t idiagnl_meminfo_get_tmem(const struct idiagnl_meminfo *minfo)
74 {
75 	return minfo->idiag_tmem;
76 }
77 
idiagnl_meminfo_set_tmem(struct idiagnl_meminfo * minfo,uint32_t tmem)78 void idiagnl_meminfo_set_tmem(struct idiagnl_meminfo *minfo, uint32_t tmem)
79 {
80 	minfo->idiag_tmem = tmem;
81 }
82 /** @} */
83 
84 /** @cond SKIP */
idiagnl_meminfo_compare(struct nl_object * _a,struct nl_object * _b,uint64_t attrs,int flags)85 static uint64_t idiagnl_meminfo_compare(struct nl_object *_a, struct nl_object *_b,
86                                      uint64_t attrs, int flags)
87 {
88 	struct idiagnl_meminfo *a = (struct idiagnl_meminfo *) _a;
89 	struct idiagnl_meminfo *b = (struct idiagnl_meminfo *) _b;
90 
91 	/* meminfo is a very simple object. It has no attribe flags (ce_mask),
92 	 * hence compare just returns 0 or 1, not a bit mask of attributes. */
93 	return a->idiag_rmem != b->idiag_rmem ||
94 	       a->idiag_wmem != b->idiag_wmem ||
95 	       a->idiag_fmem != b->idiag_fmem ||
96 	       a->idiag_tmem != b->idiag_tmem;
97 }
98 
99 struct nl_object_ops idiagnl_meminfo_obj_ops = {
100 	.oo_name	= "idiag/idiag_meminfo",
101 	.oo_size	= sizeof(struct idiagnl_meminfo),
102 	.oo_compare     = idiagnl_meminfo_compare,
103 };
104 /** @endcond */
105 /** @} */
106