6#include <netlink-private/netlink.h>
7#include <netlink/idiag/req.h>
8#include <linux/inet_diag.h>
18struct idiagnl_req *idiagnl_req_alloc(
void)
23void idiagnl_req_get(
struct idiagnl_req *req)
28void idiagnl_req_put(
struct idiagnl_req *req)
38uint8_t idiagnl_req_get_family(
const struct idiagnl_req *req)
40 return req->idiag_family;
43void idiagnl_req_set_family(
struct idiagnl_req *req, uint8_t family)
45 req->idiag_family = family;
48uint8_t idiagnl_req_get_ext(
const struct idiagnl_req *req)
50 return req->idiag_ext;
53void idiagnl_req_set_ext(
struct idiagnl_req *req, uint8_t ext)
58uint32_t idiagnl_req_get_ifindex(
const struct idiagnl_req *req)
60 return req->idiag_ifindex;
63void idiagnl_req_set_ifindex(
struct idiagnl_req *req, uint32_t ifindex)
65 req->idiag_ifindex = ifindex;
68uint32_t idiagnl_req_get_states(
const struct idiagnl_req *req)
70 return req->idiag_states;
73void idiagnl_req_set_states(
struct idiagnl_req *req, uint32_t states)
75 req->idiag_states = states;
78uint32_t idiagnl_req_get_dbs(
const struct idiagnl_req *req)
80 return req->idiag_dbs;
83void idiagnl_req_set_dbs(
struct idiagnl_req *req, uint32_t dbs)
88struct nl_addr *idiagnl_req_get_src(
const struct idiagnl_req *req)
90 return req->idiag_src;
93int idiagnl_req_set_src(
struct idiagnl_req *req,
struct nl_addr *addr)
99 req->idiag_src = addr;
104struct nl_addr *idiagnl_req_get_dst(
const struct idiagnl_req *req)
106 return req->idiag_dst;
109int idiagnl_req_set_dst(
struct idiagnl_req *req,
struct nl_addr *addr)
115 req->idiag_dst = addr;
122static void idiag_req_dump_line(
struct nl_object *a,
struct nl_dump_params *p)
124 struct idiagnl_req *req = (
struct idiagnl_req *) a;
125 char buf[64] = { 0 };
127 nl_dump_line(p,
"%s ", nl_af2str(req->idiag_family, buf,
sizeof(buf)));
130 nl_dump(p,
"iif %d ", req->idiag_ifindex);
134static void idiag_req_dump_details(
struct nl_object *a,
struct nl_dump_params *p)
136 struct idiagnl_req *req = (
struct idiagnl_req *) a;
139 nl_dump_line(p,
" ");
140 nl_dump(p,
"%s ", nl_af2str(req->idiag_family, buf,
sizeof(buf)));
145 nl_dump(p,
"iif %d ", req->idiag_ifindex);
148 nl_dump(p,
"dbs %d", req->idiag_dbs);
152static void idiag_req_dump_stats(
struct nl_object *obj,
struct nl_dump_params *p)
154 idiag_req_dump_details(obj, p);
157static void idiagnl_req_free(
struct nl_object *a)
159 struct idiagnl_req *req = (
struct idiagnl_req *) a;
167static int idiagnl_req_clone(
struct nl_object *_dst,
struct nl_object *_src)
169 struct idiagnl_req *dst = (
struct idiagnl_req *) _dst;
170 struct idiagnl_req *src = (
struct idiagnl_req *) _src;
172 src->idiag_src = NULL;
173 src->idiag_dst = NULL;
186int idiagnl_req_parse(
struct nlmsghdr *nlh,
struct idiagnl_req **result)
188 struct idiagnl_req *req = NULL;
189 struct inet_diag_req *raw_req = NULL;
190 struct nl_addr *src = NULL, *dst = NULL;
193 req = idiagnl_req_alloc();
198 req->idiag_family = raw_req->idiag_family;
199 req->idiag_ext = raw_req->idiag_ext;
200 req->idiag_states = raw_req->idiag_states;
201 req->idiag_dbs = raw_req->idiag_dbs;
202 req->idiag_ifindex = raw_req->id.idiag_if;
204 dst =
nl_addr_build(raw_req->idiag_family, raw_req->id.idiag_dst,
205 sizeof(raw_req->id.idiag_dst));
209 err = idiagnl_req_set_dst(req, dst);
215 src =
nl_addr_build(raw_req->idiag_family, raw_req->id.idiag_src,
216 sizeof(raw_req->id.idiag_src));
220 err = idiagnl_req_set_src(req, src);
230 idiagnl_req_put(req);
239struct nl_object_ops idiagnl_req_obj_ops = {
240 .oo_name =
"idiag/idiag_req",
241 .oo_size =
sizeof(
struct idiagnl_req),
242 .oo_free_data = idiagnl_req_free,
243 .oo_clone = idiagnl_req_clone,
struct nl_addr * nl_addr_get(struct nl_addr *addr)
Increase the reference counter of an abstract address.
struct nl_addr * nl_addr_build(int family, const void *buf, size_t size)
Allocate abstract address based on a binary address.
struct nl_addr * nl_addr_clone(const struct nl_addr *addr)
Clone existing abstract address object.
char * nl_addr2str(const struct nl_addr *addr, char *buf, size_t size)
Convert abstract address object to character string.
void nl_addr_put(struct nl_addr *addr)
Decrease the reference counter of an abstract address.
char * idiagnl_state2str(int state, char *buf, size_t len)
Convert inet diag socket states to strings.
char * idiagnl_exts2str(uint8_t attrs, char *buf, size_t len)
Convert inet diag extension flags to a string.
void * nlmsg_data(const struct nlmsghdr *nlh)
Return pointer to message payload.
void nl_object_put(struct nl_object *obj)
Release a reference from an object.
void nl_object_get(struct nl_object *obj)
Acquire a reference on a object.
struct nl_object * nl_object_alloc(struct nl_object_ops *ops)
Allocate a new object of kind specified by the operations handle.
void nl_dump(struct nl_dump_params *params, const char *fmt,...)
Dump a formatted character string.
@ NL_DUMP_STATS
Dump all attributes including statistics.
@ NL_DUMP_LINE
Dump object briefly on one line.
@ NL_DUMP_DETAILS
Dump all attributes but no statistics.