5 #include "libnetlink.h"
9 static int dummy_filter(struct nlmsghdr
*n
, void *arg
)
11 /* just stops rtnl_dump_filter() */
15 static bool cgroup_filter_check(void)
17 struct sockaddr_nl nladdr
= { .nl_family
= AF_NETLINK
};
18 DIAG_REQUEST(req
, struct inet_diag_req_v2 r
);
20 struct inet_diag_bc_op op
;
22 } __attribute__((packed
));
23 int inslen
= sizeof(struct instr
);
24 struct instr instr
= {
25 { INET_DIAG_BC_CGROUP_COND
, inslen
, inslen
+ 4 },
28 struct rtnl_handle rth
;
35 if (rtnl_open_byproto(&rth
, 0, NETLINK_SOCK_DIAG
))
38 rth
.flags
= RTNL_HANDLE_F_SUPPRESS_NLERR
;
40 memset(&req
.r
, 0, sizeof(req
.r
));
41 req
.r
.sdiag_family
= AF_INET
;
42 req
.r
.sdiag_protocol
= IPPROTO_TCP
;
43 req
.nlh
.nlmsg_len
+= RTA_LENGTH(inslen
);
45 rta
.rta_type
= INET_DIAG_REQ_BYTECODE
;
46 rta
.rta_len
= RTA_LENGTH(inslen
);
48 iov
[0] = (struct iovec
) { &req
, sizeof(req
) };
49 iov
[1] = (struct iovec
) { &rta
, sizeof(rta
) };
50 iov
[2] = (struct iovec
) { &instr
, inslen
};
52 msg
= (struct msghdr
) {
53 .msg_name
= (void *)&nladdr
,
54 .msg_namelen
= sizeof(nladdr
),
59 if (sendmsg(rth
.fd
, &msg
, 0) < 0)
62 if (rtnl_dump_filter(&rth
, dummy_filter
, NULL
) < 0) {
63 ret
= (errno
!= EINVAL
);
76 struct filter_check_t
{
82 static struct filter_check_t filter_checks
[SSF__MAX
] = {
83 [SSF_CGROUPCOND
] = { cgroup_filter_check
, 0 },
86 bool ssfilter_is_supported(int type
)
88 struct filter_check_t f
;
93 f
= filter_checks
[type
];
98 f
.supported
= f
.check();