Beispiel #1
0
int nftnl_cmd_header_snprintf(char *buf, size_t size, uint32_t cmd, uint32_t type,
			    uint32_t flags)
{
	NFTNL_BUF_INIT(b, buf, size);

	if (cmd == NFTNL_CMD_UNSPEC)
		return 0;

	switch (type) {
	case NFTNL_OUTPUT_XML:
	case NFTNL_OUTPUT_JSON:
		nftnl_buf_open_array(&b, type, nftnl_cmd2tag(cmd));
		break;
	default:
		switch (cmd) {
		case NFTNL_CMD_ADD:
			return snprintf(buf, size, "%9s", "[ADD] ");
		case NFTNL_CMD_DELETE:
			return snprintf(buf, size, "%9s", "[DELETE] ");
		default:
			return snprintf(buf, size, "%9s", "[unknown] ");
		}
		break;
	}
	return nftnl_buf_done(&b);
}
Beispiel #2
0
static int nftnl_rule_exp_target_export(char *buf, size_t size,
				        const struct nftnl_expr *e, int type)
{
	struct nftnl_expr_target *target = nftnl_expr_data(e);
	NFTNL_BUF_INIT(b, buf, size);

	if (e->flags & (1 << NFTNL_EXPR_TG_NAME))
		nftnl_buf_str(&b, type, target->name, NAME);

	return nftnl_buf_done(&b);
}
Beispiel #3
0
static int nftnl_expr_match_export(char *buf, size_t size,
				      struct nftnl_expr *e, int type)
{
	struct nftnl_expr_match *mt = nftnl_expr_data(e);
	NFTNL_BUF_INIT(b, buf, size);

	if (e->flags & (1 << NFTNL_EXPR_MT_NAME))
		nftnl_buf_str(&b, type, mt->name, NAME);

	return nftnl_buf_done(&b);
}
Beispiel #4
0
static int nftnl_expr_queue_export(char *buf, size_t size,
				      struct nftnl_expr *e, int type)
{
	struct nftnl_expr_queue *queue = nftnl_expr_data(e);
	NFTNL_BUF_INIT(b, buf, size);

	if (e->flags & (1 << NFTNL_EXPR_QUEUE_NUM))
		nftnl_buf_u32(&b, type, queue->queuenum, NUM);
	if (e->flags & (1 << NFTNL_EXPR_QUEUE_TOTAL))
		nftnl_buf_u32(&b, type, queue->queues_total, TOTAL);
	if (e->flags & (1 << NFTNL_EXPR_QUEUE_FLAGS))
		nftnl_buf_u32(&b, type, queue->flags, FLAGS);

	return nftnl_buf_done(&b);
}
Beispiel #5
0
static int
nftnl_expr_lookup_export(char *buf, size_t size,
			    struct nftnl_expr *e, int type)
{
	struct nftnl_expr_lookup *l = nftnl_expr_data(e);
	NFTNL_BUF_INIT(b, buf, size);

	if (e->flags & (1 << NFTNL_EXPR_LOOKUP_SET))
		nftnl_buf_str(&b, type, l->set_name, SET);
	if (e->flags & (1 << NFTNL_EXPR_LOOKUP_SREG))
		nftnl_buf_u32(&b, type, l->sreg, SREG);
	if (e->flags & (1 << NFTNL_EXPR_LOOKUP_DREG))
		nftnl_buf_u32(&b, type, l->dreg, DREG);

	return nftnl_buf_done(&b);
}
Beispiel #6
0
static int nftnl_expr_payload_export(char *buf, size_t size, uint32_t flags,
					struct nftnl_expr *e, int type)
{
	struct nftnl_expr_payload *payload = nftnl_expr_data(e);
	NFTNL_BUF_INIT(b, buf, size);

	if (e->flags & (1 << NFTNL_EXPR_PAYLOAD_DREG))
		nftnl_buf_u32(&b, type, payload->dreg, DREG);
	if (e->flags & (1 << NFTNL_EXPR_PAYLOAD_OFFSET))
		nftnl_buf_u32(&b, type, payload->offset, OFFSET);
	if (e->flags & (1 << NFTNL_EXPR_PAYLOAD_LEN))
		nftnl_buf_u32(&b, type, payload->len, LEN);
	if (e->flags & (1 << NFTNL_EXPR_PAYLOAD_BASE))
		nftnl_buf_str(&b, type, base2str(payload->base), BASE);

	return nftnl_buf_done(&b);
}
Beispiel #7
0
int nftnl_cmd_footer_snprintf(char *buf, size_t size, uint32_t cmd, uint32_t type,
			    uint32_t flags)
{
	NFTNL_BUF_INIT(b, buf, size);

	if (cmd == NFTNL_CMD_UNSPEC)
		return 0;

	switch (type) {
	case NFTNL_OUTPUT_XML:
	case NFTNL_OUTPUT_JSON:
		nftnl_buf_close_array(&b, type, nftnl_cmd2tag(cmd));
		break;
	default:
		return 0;
	}
	return nftnl_buf_done(&b);
}
Beispiel #8
0
static int nftnl_expr_log_export(char *buf, size_t size,
				    struct nftnl_expr *e, int type)
{
	struct nftnl_expr_log *log = nftnl_expr_data(e);
	NFTNL_BUF_INIT(b, buf, size);

	if (e->flags & (1 << NFTNL_EXPR_LOG_PREFIX))
		nftnl_buf_str(&b, type, log->prefix, PREFIX);
	if (e->flags & (1 << NFTNL_EXPR_LOG_GROUP))
		nftnl_buf_u32(&b, type, log->group, GROUP);
	if (e->flags & (1 << NFTNL_EXPR_LOG_SNAPLEN))
		nftnl_buf_u32(&b, type, log->snaplen, SNAPLEN);
	if (e->flags & (1 << NFTNL_EXPR_LOG_QTHRESHOLD))
		nftnl_buf_u32(&b, type, log->qthreshold, QTHRESH);
	if (e->flags & (1 << NFTNL_EXPR_LOG_LEVEL))
		nftnl_buf_u32(&b, type, log->level, LEVEL);
	if (e->flags & (1 << NFTNL_EXPR_LOG_FLAGS))
		nftnl_buf_u32(&b, type, log->level, FLAGS);

	return nftnl_buf_done(&b);
}