12 #include <netlink-private/netlink.h>
13 #include <netlink/idiag/req.h>
14 #include <linux/inet_diag.h>
24 struct idiagnl_req *idiagnl_req_alloc(
void)
29 void idiagnl_req_get(
struct idiagnl_req *req)
34 void idiagnl_req_put(
struct idiagnl_req *req)
44 uint8_t idiagnl_req_get_family(
const struct idiagnl_req *req)
46 return req->idiag_family;
49 void idiagnl_req_set_family(
struct idiagnl_req *req, uint8_t family)
51 req->idiag_family = family;
54 uint8_t idiagnl_req_get_ext(
const struct idiagnl_req *req)
56 return req->idiag_ext;
59 void idiagnl_req_set_ext(
struct idiagnl_req *req, uint8_t ext)
64 uint32_t idiagnl_req_get_ifindex(
const struct idiagnl_req *req)
66 return req->idiag_ifindex;
69 void idiagnl_req_set_ifindex(
struct idiagnl_req *req, uint32_t ifindex)
71 req->idiag_states = ifindex;
74 uint32_t idiagnl_req_get_states(
const struct idiagnl_req *req)
76 return req->idiag_states;
79 void idiagnl_req_set_states(
struct idiagnl_req *req, uint32_t states)
81 req->idiag_states = states;
84 uint32_t idiagnl_req_get_dbs(
const struct idiagnl_req *req)
86 return req->idiag_dbs;
89 void idiagnl_req_set_dbs(
struct idiagnl_req *req, uint32_t dbs)
94 struct nl_addr *idiagnl_req_get_src(
const struct idiagnl_req *req)
96 return req->idiag_src;
99 int idiagnl_req_set_src(
struct idiagnl_req *req,
struct nl_addr *addr)
105 req->idiag_src = addr;
110 struct nl_addr *idiagnl_req_get_dst(
const struct idiagnl_req *req)
112 return req->idiag_dst;
115 int idiagnl_req_set_dst(
struct idiagnl_req *req,
struct nl_addr *addr)
121 req->idiag_dst = addr;
128 static void idiag_req_dump_line(
struct nl_object *a,
struct nl_dump_params *p)
130 struct idiagnl_req *req = (
struct idiagnl_req *) a;
131 char buf[64] = { 0 };
133 nl_dump_line(p,
"%s ", nl_af2str(req->idiag_family, buf,
sizeof(buf)));
136 nl_dump(p,
"iif %d ", req->idiag_ifindex);
140 static void idiag_req_dump_details(
struct nl_object *a,
struct nl_dump_params *p)
142 struct idiagnl_req *req = (
struct idiagnl_req *) a;
145 nl_dump_line(p,
" ");
146 nl_dump(p,
"%s ", nl_af2str(req->idiag_family, buf,
sizeof(buf)));
151 nl_dump(p,
"iif %d ", req->idiag_ifindex);
154 nl_dump(p,
"dbs %d", req->idiag_dbs);
158 static void idiag_req_dump_stats(
struct nl_object *obj,
struct nl_dump_params *p)
160 idiag_req_dump_details(obj, p);
163 static void idiagnl_req_free(
struct nl_object *a)
165 struct idiagnl_req *req = (
struct idiagnl_req *) a;
173 static int idiagnl_req_clone(
struct nl_object *_dst,
struct nl_object *_src)
175 struct idiagnl_req *dst = (
struct idiagnl_req *) _dst;
176 struct idiagnl_req *src = (
struct idiagnl_req *) _src;
189 int idiagnl_req_parse(
struct nlmsghdr *nlh,
struct idiagnl_req **result)
191 struct idiagnl_req *req = NULL;
192 struct inet_diag_req *raw_req = NULL;
193 struct nl_addr *src = NULL, *dst = NULL;
196 req = idiagnl_req_alloc();
201 req->idiag_family = raw_req->idiag_family;
202 req->idiag_ext = raw_req->idiag_ext;
203 req->idiag_states = raw_req->idiag_states;
204 req->idiag_dbs = raw_req->idiag_dbs;
205 req->idiag_ifindex = raw_req->id.idiag_if;
207 dst =
nl_addr_build(raw_req->idiag_family, raw_req->id.idiag_dst,
208 sizeof(raw_req->id.idiag_dst));
212 err = idiagnl_req_set_dst(req, dst);
218 src =
nl_addr_build(raw_req->idiag_family, raw_req->id.idiag_src,
219 sizeof(raw_req->id.idiag_src));
223 err = idiagnl_req_set_src(req, src);
233 idiagnl_req_put(req);
242 struct nl_object_ops idiagnl_req_obj_ops = {
243 .oo_name =
"idiag/idiag_req",
244 .oo_size =
sizeof(
struct idiagnl_req),
245 .oo_free_data = idiagnl_req_free,
246 .oo_clone = idiagnl_req_clone,