1 /* SPDX-License-Identifier: LGPL-2.1-only */
2 /*
3 * lib/idiag/idiagnl_vegasinfo_obj.c Inet Diag TCP Vegas Info 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/vegasinfo.h>
15
16 /**
17 * @ingroup idiag
18 * @defgroup idiagnl_vegasinfo Inet Diag TCP Vegas Info
19 *
20 * @details
21 * @idiagnl_doc{idiagnl_vegasinfo, Inet Diag TCP Vegas Info Documentation}
22 * @{
23 */
idiagnl_vegasinfo_alloc(void)24 struct idiagnl_vegasinfo *idiagnl_vegasinfo_alloc(void)
25 {
26 return (struct idiagnl_vegasinfo *) nl_object_alloc(&idiagnl_vegasinfo_obj_ops);
27 }
28
idiagnl_vegasinfo_get(struct idiagnl_vegasinfo * vinfo)29 void idiagnl_vegasinfo_get(struct idiagnl_vegasinfo *vinfo)
30 {
31 nl_object_get((struct nl_object *) vinfo);
32 }
33
idiagnl_vegasinfo_put(struct idiagnl_vegasinfo * vinfo)34 void idiagnl_vegasinfo_put(struct idiagnl_vegasinfo *vinfo)
35 {
36 nl_object_put((struct nl_object *) vinfo);
37 }
38
39 /**
40 * @name Attributes
41 * @{
42 */
idiagnl_vegasinfo_get_enabled(const struct idiagnl_vegasinfo * vinfo)43 uint32_t idiagnl_vegasinfo_get_enabled(const struct idiagnl_vegasinfo *vinfo)
44 {
45 return vinfo->tcpv_enabled;
46 }
47
idiagnl_vegasinfo_set_enabled(struct idiagnl_vegasinfo * vinfo,uint32_t enabled)48 void idiagnl_vegasinfo_set_enabled(struct idiagnl_vegasinfo *vinfo, uint32_t
49 enabled)
50 {
51 vinfo->tcpv_enabled = enabled;
52 }
53
idiagnl_vegasinfo_get_rttcnt(const struct idiagnl_vegasinfo * vinfo)54 uint32_t idiagnl_vegasinfo_get_rttcnt(const struct idiagnl_vegasinfo *vinfo)
55 {
56 return vinfo->tcpv_rttcnt;
57 }
58
idiagnl_vegasinfo_set_rttcnt(struct idiagnl_vegasinfo * vinfo,uint32_t rttcnt)59 void idiagnl_vegasinfo_set_rttcnt(struct idiagnl_vegasinfo *vinfo, uint32_t
60 rttcnt)
61 {
62 vinfo->tcpv_rttcnt = rttcnt;
63 }
64
idiagnl_vegasinfo_get_rtt(const struct idiagnl_vegasinfo * vinfo)65 uint32_t idiagnl_vegasinfo_get_rtt(const struct idiagnl_vegasinfo *vinfo)
66 {
67 return vinfo->tcpv_rtt;
68 }
69
idiagnl_vegasinfo_set_rtt(struct idiagnl_vegasinfo * vinfo,uint32_t rtt)70 void idiagnl_vegasinfo_set_rtt(struct idiagnl_vegasinfo *vinfo, uint32_t rtt)
71 {
72 vinfo->tcpv_rtt = rtt;
73 }
74
idiagnl_vegasinfo_get_minrtt(const struct idiagnl_vegasinfo * vinfo)75 uint32_t idiagnl_vegasinfo_get_minrtt(const struct idiagnl_vegasinfo *vinfo)
76 {
77 return vinfo->tcpv_minrtt;
78 }
79
idiagnl_vegasinfo_set_minrtt(struct idiagnl_vegasinfo * vinfo,uint32_t minrtt)80 void idiagnl_vegasinfo_set_minrtt(struct idiagnl_vegasinfo *vinfo, uint32_t
81 minrtt)
82 {
83 vinfo->tcpv_minrtt = minrtt;
84 }
85 /** @} */
86
87 /** @cond SKIP */
idiagnl_vegasinfo_compare(struct nl_object * _a,struct nl_object * _b,uint64_t attrs,int flags)88 static uint64_t idiagnl_vegasinfo_compare(struct nl_object *_a, struct nl_object *_b,
89 uint64_t attrs, int flags)
90 {
91 struct idiagnl_vegasinfo *a = (struct idiagnl_vegasinfo *) _a;
92 struct idiagnl_vegasinfo *b = (struct idiagnl_vegasinfo *) _b;
93
94 /* vegasinfo is a very simple object. It has no attribe flags (ce_mask),
95 * hence compare just returns 0 or 1, not a bit mask of attributes. */
96 return a->tcpv_enabled != b->tcpv_enabled ||
97 a->tcpv_rttcnt != b->tcpv_rttcnt ||
98 a->tcpv_rtt != b->tcpv_rtt ||
99 a->tcpv_minrtt != b->tcpv_minrtt;
100 }
101
102 struct nl_object_ops idiagnl_vegasinfo_obj_ops = {
103 .oo_name = "idiag/idiag_vegasinfo",
104 .oo_size = sizeof(struct idiagnl_vegasinfo),
105 .oo_compare = idiagnl_vegasinfo_compare,
106 };
107 /** @endcond */
108 /** @} */
109