1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
/*
* lib/fib_lookup/request.c FIB Lookup Request
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
*/
/**
* @ingroup fib_lookup
* @defgroup flreq Request
* @brief
* @{
*/
#include <netlink-private/netlink.h>
#include <netlink/netlink.h>
#include <netlink/attr.h>
#include <netlink/utils.h>
#include <netlink/object.h>
#include <netlink/fib_lookup/request.h>
static struct nl_object_ops request_obj_ops;
/** @cond SKIP */
#define REQUEST_ATTR_ADDR 0x01
#define REQUEST_ATTR_FWMARK 0x02
#define REQUEST_ATTR_TOS 0x04
#define REQUEST_ATTR_SCOPE 0x08
#define REQUEST_ATTR_TABLE 0x10
/** @endcond */
static void request_free_data(struct nl_object *obj)
{
struct flnl_request *req = REQUEST_CAST(obj);
if (req)
nl_addr_put(req->lr_addr);
}
static int request_clone(struct nl_object *_dst, struct nl_object *_src)
{
struct flnl_request *dst = nl_object_priv(_dst);
struct flnl_request *src = nl_object_priv(_src);
if (src->lr_addr)
if (!(dst->lr_addr = nl_addr_clone(src->lr_addr)))
return -NLE_NOMEM;
return 0;
}
static int request_compare(struct nl_object *_a, struct nl_object *_b,
uint32_t attrs, int flags)
{
struct flnl_request *a = (struct flnl_request *) _a;
struct flnl_request *b = (struct flnl_request *) _b;
int diff = 0;
#define REQ_DIFF(ATTR, EXPR) ATTR_DIFF(attrs, REQUEST_ATTR_##ATTR, a, b, EXPR)
diff |= REQ_DIFF(FWMARK, a->lr_fwmark != b->lr_fwmark);
diff |= REQ_DIFF(TOS, a->lr_tos != b->lr_tos);
diff |= REQ_DIFF(SCOPE, a->lr_scope != b->lr_scope);
diff |= REQ_DIFF(TABLE, a->lr_table != b->lr_table);
diff |= REQ_DIFF(ADDR, nl_addr_cmp(a->lr_addr, b->lr_addr));
#undef REQ_DIFF
return diff;
}
/**
* @name Lookup Request Creation/Deletion
* @{
*/
struct flnl_request *flnl_request_alloc(void)
{
return REQUEST_CAST(nl_object_alloc(&request_obj_ops));
}
/** @} */
/**
* @name Attributes
* @{
*/
void flnl_request_set_fwmark(struct flnl_request *req, uint64_t fwmark)
{
req->lr_fwmark = fwmark;
req->ce_mask |= REQUEST_ATTR_FWMARK;
}
uint64_t flnl_request_get_fwmark(struct flnl_request *req)
{
if (req->ce_mask & REQUEST_ATTR_FWMARK)
return req->lr_fwmark;
else
return UINT_LEAST64_MAX;
}
void flnl_request_set_tos(struct flnl_request *req, int tos)
{
req->lr_tos = tos;
req->ce_mask |= REQUEST_ATTR_TOS;
}
int flnl_request_get_tos(struct flnl_request *req)
{
if (req->ce_mask & REQUEST_ATTR_TOS)
return req->lr_tos;
else
return -1;
}
void flnl_request_set_scope(struct flnl_request *req, int scope)
{
req->lr_scope = scope;
req->ce_mask |= REQUEST_ATTR_SCOPE;
}
int flnl_request_get_scope(struct flnl_request *req)
{
if (req->ce_mask & REQUEST_ATTR_SCOPE)
return req->lr_scope;
else
return -1;
}
void flnl_request_set_table(struct flnl_request *req, int table)
{
req->lr_table = table;
req->ce_mask |= REQUEST_ATTR_TABLE;
}
int flnl_request_get_table(struct flnl_request *req)
{
if (req->ce_mask & REQUEST_ATTR_TABLE)
return req->lr_table;
else
return -1;
}
int flnl_request_set_addr(struct flnl_request *req, struct nl_addr *addr)
{
if (addr->a_family != AF_INET)
return -NLE_AF_NOSUPPORT;
if (req->lr_addr)
nl_addr_put(req->lr_addr);
nl_addr_get(addr);
req->lr_addr = addr;
req->ce_mask |= REQUEST_ATTR_ADDR;
return 0;
}
struct nl_addr *flnl_request_get_addr(struct flnl_request *req)
{
if (req->ce_mask & REQUEST_ATTR_ADDR)
return req->lr_addr;
else
return NULL;
}
/** @} */
static struct nl_object_ops request_obj_ops = {
.oo_name = "fib_lookup/request",
.oo_size = sizeof(struct flnl_request),
.oo_free_data = request_free_data,
.oo_clone = request_clone,
.oo_compare = request_compare,
.oo_id_attrs = ~0,
};
/** @} */
|