libnl 1.1.4
Macros | Functions

Macros

#define NFNLMSG_LOG_TYPE(type)   NFNLMSG_TYPE(NFNL_SUBSYS_ULOG, (type))
 

Functions

struct nfnl_log * nfnlmsg_log_parse (struct nlmsghdr *nlh)
 

Log Commands

struct nl_msg * nfnl_log_build_bind (uint16_t queuenum)
 
int nfnl_log_bind (struct nl_handle *nlh, uint16_t queuenum)
 
struct nl_msg * nfnl_log_build_unbind (uint16_t queuenum)
 
int nfnl_log_unbind (struct nl_handle *nlh, uint16_t queuenum)
 
struct nl_msg * nfnl_log_build_pf_bind (uint8_t pf)
 
int nfnl_log_pf_bind (struct nl_handle *nlh, uint8_t pf)
 
struct nl_msg * nfnl_log_build_pf_unbind (uint8_t pf)
 
int nfnl_log_pf_unbind (struct nl_handle *nlh, uint8_t pf)
 
struct nl_msg * nfnl_log_build_mode (uint16_t queuenum, uint8_t copy_mode, uint32_t copy_range)
 
int nfnl_log_set_mode (struct nl_handle *nlh, uint16_t queuenum, uint8_t copy_mode, uint32_t copy_range)
 

Detailed Description

Macro Definition Documentation

◆ NFNLMSG_LOG_TYPE

#define NFNLMSG_LOG_TYPE (   type)    NFNLMSG_TYPE(NFNL_SUBSYS_ULOG, (type))

Definition at line 327 of file log.c.

Function Documentation

◆ nfnlmsg_log_parse()

struct nfnl_log * nfnlmsg_log_parse ( struct nlmsghdr nlh)

Definition at line 65 of file log.c.

66{
67 struct nfnl_log *log;
68 struct nlattr *tb[NFULA_MAX+1];
69 struct nlattr *attr;
70 int err;
71
72 log = nfnl_log_alloc();
73 if (!log)
74 return NULL;
75
76 log->ce_msgtype = nlh->nlmsg_type;
77
78 err = nlmsg_parse(nlh, sizeof(struct nfgenmsg), tb, NFULA_MAX,
79 log_policy);
80 if (err < 0)
81 goto errout;
82
83 nfnl_log_set_family(log, nfnlmsg_family(nlh));
84
85 attr = tb[NFULA_PACKET_HDR];
86 if (attr) {
87 struct nfulnl_msg_packet_hdr *hdr = nla_data(attr);
88
89 nfnl_log_set_hwproto(log, hdr->hw_protocol);
90 nfnl_log_set_hook(log, hdr->hook);
91 }
92
93 attr = tb[NFULA_MARK];
94 if (attr)
95 nfnl_log_set_mark(log, ntohl(nla_get_u32(attr)));
96
97 attr = tb[NFULA_TIMESTAMP];
98 if (attr) {
99 struct nfulnl_msg_packet_timestamp *timestamp = nla_data(attr);
100 struct timeval tv;
101
102 tv.tv_sec = ntohll(timestamp->sec);
103 tv.tv_usec = ntohll(timestamp->usec);
104 nfnl_log_set_timestamp(log, &tv);
105 }
106
107 attr = tb[NFULA_IFINDEX_INDEV];
108 if (attr)
109 nfnl_log_set_indev(log, ntohl(nla_get_u32(attr)));
110
111 attr = tb[NFULA_IFINDEX_OUTDEV];
112 if (attr)
113 nfnl_log_set_outdev(log, ntohl(nla_get_u32(attr)));
114
115 attr = tb[NFULA_IFINDEX_PHYSINDEV];
116 if (attr)
117 nfnl_log_set_physindev(log, ntohl(nla_get_u32(attr)));
118
119 attr = tb[NFULA_IFINDEX_PHYSOUTDEV];
120 if (attr)
121 nfnl_log_set_physoutdev(log, ntohl(nla_get_u32(attr)));
122
123 attr = tb[NFULA_HWADDR];
124 if (attr) {
125 struct nfulnl_msg_packet_hw *hw = nla_data(attr);
126
127 nfnl_log_set_hwaddr(log, hw->hw_addr, ntohs(hw->hw_addrlen));
128 }
129
130 attr = tb[NFULA_PAYLOAD];
131 if (attr) {
132 err = nfnl_log_set_payload(log, nla_data(attr), nla_len(attr));
133 if (err < 0)
134 goto errout;
135 }
136
137 attr = tb[NFULA_PREFIX];
138 if (attr) {
139 err = nfnl_log_set_prefix(log, nla_data(attr));
140 if (err < 0)
141 goto errout;
142 }
143
144 attr = tb[NFULA_UID];
145 if (attr)
146 nfnl_log_set_uid(log, ntohl(nla_get_u32(attr)));
147
148 attr = tb[NFULA_SEQ];
149 if (attr)
150 nfnl_log_set_seq(log, ntohl(nla_get_u32(attr)));
151
152 attr = tb[NFULA_SEQ_GLOBAL];
153 if (attr)
154 nfnl_log_set_seq_global(log, ntohl(nla_get_u32(attr)));
155
156 return log;
157
158errout:
159 nfnl_log_put(log);
160 return NULL;
161}
void * nla_data(const struct nlattr *nla)
head of payload
Definition: attr.c:151
uint32_t nla_get_u32(struct nlattr *nla)
Return payload of u32 attribute.
Definition: attr.c:693
int nla_len(const struct nlattr *nla)
length of payload
Definition: attr.c:160
int nlmsg_parse(struct nlmsghdr *nlh, int hdrlen, struct nlattr *tb[], int maxtype, struct nla_policy *policy)
parse attributes of a netlink message
Definition: msg.c:319
uint8_t nfnlmsg_family(struct nlmsghdr *nlh)
Get netfilter family from message.
Definition: nfnl.c:150
uint16_t nlmsg_type
Message type (content type)

◆ nfnl_log_build_bind()

struct nl_msg * nfnl_log_build_bind ( uint16_t  queuenum)

Definition at line 227 of file log.c.

228{
229 return build_log_cmd_msg(0, queuenum, NFULNL_CFG_CMD_BIND);
230}

◆ nfnl_log_bind()

int nfnl_log_bind ( struct nl_handle *  nlh,
uint16_t  queuenum 
)

Definition at line 232 of file log.c.

233{
234 struct nl_msg *msg;
235
236 msg = nfnl_log_build_bind(queuenum);
237 if (!msg)
238 return nl_get_errno();
239
240 return send_log_msg(nlh, msg);
241}

◆ nfnl_log_build_unbind()

struct nl_msg * nfnl_log_build_unbind ( uint16_t  queuenum)

Definition at line 243 of file log.c.

244{
245 return build_log_cmd_msg(0, queuenum, NFULNL_CFG_CMD_UNBIND);
246}

◆ nfnl_log_unbind()

int nfnl_log_unbind ( struct nl_handle *  nlh,
uint16_t  queuenum 
)

Definition at line 248 of file log.c.

249{
250 struct nl_msg *msg;
251
252 msg = nfnl_log_build_bind(queuenum);
253 if (!msg)
254 return nl_get_errno();
255
256 return send_log_msg(nlh, msg);
257}

◆ nfnl_log_build_pf_bind()

struct nl_msg * nfnl_log_build_pf_bind ( uint8_t  pf)

Definition at line 259 of file log.c.

260{
261 return build_log_cmd_msg(pf, 0, NFULNL_CFG_CMD_PF_BIND);
262}

◆ nfnl_log_pf_bind()

int nfnl_log_pf_bind ( struct nl_handle *  nlh,
uint8_t  pf 
)

Definition at line 264 of file log.c.

265{
266 struct nl_msg *msg;
267
268 msg = nfnl_log_build_pf_bind(pf);
269 if (!msg)
270 return nl_get_errno();
271
272 return send_log_msg(nlh, msg);
273}

◆ nfnl_log_build_pf_unbind()

struct nl_msg * nfnl_log_build_pf_unbind ( uint8_t  pf)

Definition at line 275 of file log.c.

276{
277 return build_log_cmd_msg(pf, 0, NFULNL_CFG_CMD_PF_UNBIND);
278}

◆ nfnl_log_pf_unbind()

int nfnl_log_pf_unbind ( struct nl_handle *  nlh,
uint8_t  pf 
)

Definition at line 280 of file log.c.

281{
282 struct nl_msg *msg;
283
284 msg = nfnl_log_build_pf_unbind(pf);
285 if (!msg)
286 return nl_get_errno();
287
288 return send_log_msg(nlh, msg);
289}

◆ nfnl_log_build_mode()

struct nl_msg * nfnl_log_build_mode ( uint16_t  queuenum,
uint8_t  copy_mode,
uint32_t  copy_range 
)

Definition at line 291 of file log.c.

293{
294 struct nl_msg *msg;
295 struct nfulnl_msg_config_mode mode;
296
297 msg = nfnlmsg_alloc_simple(NFNL_SUBSYS_ULOG, NFULNL_MSG_CONFIG, 0,
298 0, queuenum);
299 if (msg == NULL)
300 return NULL;
301
302 mode.copy_mode = copy_mode;
303 mode.copy_range = htonl(copy_range);
304 if (nla_put(msg, NFULA_CFG_MODE, sizeof(mode), &mode) < 0)
305 goto nla_put_failure;
306
307 return msg;
308
309nla_put_failure:
310 nlmsg_free(msg);
311 return NULL;
312}
int nla_put(struct nl_msg *n, int attrtype, int attrlen, const void *data)
Add a netlink attribute to a netlink message.
Definition: attr.c:511
void nlmsg_free(struct nl_msg *n)
Free a netlink message.
Definition: msg.c:656
struct nl_msg * nfnlmsg_alloc_simple(uint8_t subsys_id, uint8_t type, int flags, uint8_t family, uint16_t res_id)
Allocate a new netfilter netlink message.
Definition: nfnl.c:201

◆ nfnl_log_set_mode()

int nfnl_log_set_mode ( struct nl_handle *  nlh,
uint16_t  queuenum,
uint8_t  copy_mode,
uint32_t  copy_range 
)

Definition at line 314 of file log.c.

316{
317 struct nl_msg *msg;
318
319 msg = nfnl_log_build_mode(queuenum, copy_mode, copy_range);
320 if (!msg)
321 return nl_get_errno();
322 return send_log_msg(nlh, msg);
323}