13#include <netlink-private/netlink.h>
14#include <netlink/netlink.h>
15#include <netlink/attr.h>
16#include <netlink/utils.h>
17#include <netlink/object.h>
18#include <netlink/fib_lookup/request.h>
20static struct nl_object_ops request_obj_ops;
23#define REQUEST_ATTR_ADDR 0x01
24#define REQUEST_ATTR_FWMARK 0x02
25#define REQUEST_ATTR_TOS 0x04
26#define REQUEST_ATTR_SCOPE 0x08
27#define REQUEST_ATTR_TABLE 0x10
30static void request_free_data(
struct nl_object *obj)
32 struct flnl_request *req = REQUEST_CAST(obj);
38static int request_clone(
struct nl_object *_dst,
struct nl_object *_src)
40 struct flnl_request *dst = nl_object_priv(_dst);
41 struct flnl_request *src = nl_object_priv(_src);
53static uint64_t request_compare(
struct nl_object *_a,
struct nl_object *_b,
54 uint64_t attrs,
int flags)
56 struct flnl_request *a = (
struct flnl_request *) _a;
57 struct flnl_request *b = (
struct flnl_request *) _b;
60#define REQ_DIFF(ATTR, EXPR) ATTR_DIFF(attrs, REQUEST_ATTR_##ATTR, a, b, EXPR)
62 diff |= REQ_DIFF(FWMARK, a->lr_fwmark != b->lr_fwmark);
63 diff |= REQ_DIFF(TOS, a->lr_tos != b->lr_tos);
64 diff |= REQ_DIFF(SCOPE, a->lr_scope != b->lr_scope);
65 diff |= REQ_DIFF(TABLE, a->lr_table != b->lr_table);
66 diff |= REQ_DIFF(ADDR,
nl_addr_cmp(a->lr_addr, b->lr_addr));
79struct flnl_request *flnl_request_alloc(
void)
91void flnl_request_set_fwmark(
struct flnl_request *req, uint64_t fwmark)
93 req->lr_fwmark = fwmark;
94 req->ce_mask |= REQUEST_ATTR_FWMARK;
97uint64_t flnl_request_get_fwmark(
struct flnl_request *req)
99 if (req->ce_mask & REQUEST_ATTR_FWMARK)
100 return req->lr_fwmark;
102 return UINT_LEAST64_MAX;
105void flnl_request_set_tos(
struct flnl_request *req,
int tos)
108 req->ce_mask |= REQUEST_ATTR_TOS;
111int flnl_request_get_tos(
struct flnl_request *req)
113 if (req->ce_mask & REQUEST_ATTR_TOS)
119void flnl_request_set_scope(
struct flnl_request *req,
int scope)
121 req->lr_scope = scope;
122 req->ce_mask |= REQUEST_ATTR_SCOPE;
125int flnl_request_get_scope(
struct flnl_request *req)
127 if (req->ce_mask & REQUEST_ATTR_SCOPE)
128 return req->lr_scope;
133void flnl_request_set_table(
struct flnl_request *req,
int table)
135 req->lr_table = table;
136 req->ce_mask |= REQUEST_ATTR_TABLE;
139int flnl_request_get_table(
struct flnl_request *req)
141 if (req->ce_mask & REQUEST_ATTR_TABLE)
142 return req->lr_table;
147int flnl_request_set_addr(
struct flnl_request *req,
struct nl_addr *addr)
149 if (addr->a_family != AF_INET)
150 return -NLE_AF_NOSUPPORT;
158 req->ce_mask |= REQUEST_ATTR_ADDR;
163struct nl_addr *flnl_request_get_addr(
struct flnl_request *req)
165 if (req->ce_mask & REQUEST_ATTR_ADDR)
173static struct nl_object_ops request_obj_ops = {
174 .oo_name =
"fib_lookup/request",
175 .oo_size =
sizeof(
struct flnl_request),
176 .oo_free_data = request_free_data,
177 .oo_clone = request_clone,
178 .oo_compare = request_compare,
struct nl_addr * nl_addr_get(struct nl_addr *addr)
Increase the reference counter of an abstract address.
int nl_addr_cmp(const struct nl_addr *a, const struct nl_addr *b)
Compare abstract addresses.
struct nl_addr * nl_addr_clone(const struct nl_addr *addr)
Clone existing abstract address object.
void nl_addr_put(struct nl_addr *addr)
Decrease the reference counter of an abstract address.
struct nl_object * nl_object_alloc(struct nl_object_ops *ops)
Allocate a new object of kind specified by the operations handle.