10 #include <libmnl/libmnl.h>
11 #include <libnetfilter_log/libnetfilter_log.h>
34 struct nlmsghdr *nlh = mnl_nlmsg_put_header(buf);
37 nlh->nlmsg_type = (NFNL_SUBSYS_ULOG << 8) | type;
38 nlh->nlmsg_flags = NLM_F_REQUEST;
40 nfg = mnl_nlmsg_put_extra_header(nlh,
sizeof(*nfg));
41 nfg->nfgen_family = family;
42 nfg->version = NFNETLINK_V0;
43 nfg->res_id = htons(qnum);
59 struct nfulnl_msg_config_mode nfmode = {
61 .copy_range = htonl(range)
64 mnl_attr_put(nlh, NFULA_CFG_MODE,
sizeof(nfmode), &nfmode);
80 struct nfulnl_msg_config_cmd nfcmd = {
84 mnl_attr_put(nlh, NFULA_CFG_CMD,
sizeof(nfcmd), &nfcmd);
90 static int nflog_parse_attr_cb(
const struct nlattr *attr,
void *data)
92 const struct nlattr **tb = data;
93 int type = mnl_attr_get_type(attr);
96 if (mnl_attr_type_valid(attr, NFULA_MAX) < 0)
102 if (mnl_attr_validate(attr, MNL_TYPE_U16) < 0)
106 case NFULA_IFINDEX_INDEV:
107 case NFULA_IFINDEX_OUTDEV:
108 case NFULA_IFINDEX_PHYSINDEV:
109 case NFULA_IFINDEX_PHYSOUTDEV:
112 case NFULA_SEQ_GLOBAL:
115 if (mnl_attr_validate(attr, MNL_TYPE_U32) < 0)
118 case NFULA_PACKET_HDR:
119 if (mnl_attr_validate2(attr, MNL_TYPE_UNSPEC,
120 sizeof(
struct nfulnl_msg_packet_hdr)) < 0) {
124 case NFULA_TIMESTAMP:
125 if (mnl_attr_validate2(attr, MNL_TYPE_UNSPEC,
126 sizeof(
struct nfulnl_msg_packet_timestamp)) < 0) {
131 if (mnl_attr_validate2(attr, MNL_TYPE_UNSPEC,
132 sizeof(
struct nfulnl_msg_packet_hw)) < 0) {
137 if (mnl_attr_validate(attr, MNL_TYPE_NUL_STRING) < 0)
159 return mnl_attr_parse(nlh,
sizeof(
struct nfgenmsg),
160 nflog_parse_attr_cb, attr);
192 struct nlattr **attr,
enum nflog_output_type type,
196 struct nflog_data nfad = {
197 .nfa = (
struct nfattr **)&attr[1],
202 case NFLOG_OUTPUT_XML:
int nflog_nlmsg_snprintf(char *buf, size_t bufsiz, const struct nlmsghdr *nlh, struct nlattr **attr, enum nflog_output_type type, uint32_t flags)
int nflog_attr_put_cfg_cmd(struct nlmsghdr *nlh, uint8_t cmd)
int nflog_nlmsg_parse(const struct nlmsghdr *nlh, struct nlattr **attr)
struct nlmsghdr * nflog_nlmsg_put_header(char *buf, uint8_t type, uint8_t family, uint16_t qnum)
int nflog_attr_put_cfg_mode(struct nlmsghdr *nlh, uint8_t mode, uint32_t range)
int nflog_snprintf_xml(char *buf, size_t rem, struct nflog_data *tb, int flags)