Exemple #1
0
static struct nfnl_log *alloc_log(void)
{
	struct nfnl_log *log;

	log = nfnl_log_alloc();
	if (!log)
		nl_cli_fatal(ENOMEM, "Unable to allocate log object");

	return log;
}
Exemple #2
0
Fichier : log.c Projet : DINKIN/tuo
struct nfnl_log *nfnlmsg_log_parse(struct nlmsghdr *nlh)
{
	struct nfnl_log *log;
	struct nlattr *tb[NFULA_MAX+1];
	struct nlattr *attr;
	int err;

	log = nfnl_log_alloc();
	if (!log)
		return NULL;

	log->ce_msgtype = nlh->nlmsg_type;

	err = nlmsg_parse(nlh, sizeof(struct nfgenmsg), tb, NFULA_MAX,
			  log_policy);
	if (err < 0)
		goto errout;

	nfnl_log_set_family(log, nfnlmsg_family(nlh));

	attr = tb[NFULA_PACKET_HDR];
	if (attr) {
		struct nfulnl_msg_packet_hdr *hdr = nla_data(attr);

		nfnl_log_set_hwproto(log, hdr->hw_protocol);
		nfnl_log_set_hook(log, hdr->hook);
	}

	attr = tb[NFULA_MARK];
	if (attr)
		nfnl_log_set_mark(log, ntohl(nla_get_u32(attr)));

	attr = tb[NFULA_TIMESTAMP];
	if (attr) {
		struct nfulnl_msg_packet_timestamp *timestamp = nla_data(attr);
		struct timeval tv;

		tv.tv_sec = ntohll(timestamp->sec);
		tv.tv_usec = ntohll(timestamp->usec);
		nfnl_log_set_timestamp(log, &tv);
	}

	attr = tb[NFULA_IFINDEX_INDEV];
	if (attr)
		nfnl_log_set_indev(log, ntohl(nla_get_u32(attr)));

	attr = tb[NFULA_IFINDEX_OUTDEV];
	if (attr)
		nfnl_log_set_outdev(log, ntohl(nla_get_u32(attr)));

	attr = tb[NFULA_IFINDEX_PHYSINDEV];
	if (attr)
		nfnl_log_set_physindev(log, ntohl(nla_get_u32(attr)));

	attr = tb[NFULA_IFINDEX_PHYSOUTDEV];
	if (attr)
		nfnl_log_set_physoutdev(log, ntohl(nla_get_u32(attr)));

	attr = tb[NFULA_HWADDR];
	if (attr) {
		struct nfulnl_msg_packet_hw *hw = nla_data(attr);

		nfnl_log_set_hwaddr(log, hw->hw_addr, ntohs(hw->hw_addrlen));
	}

	attr = tb[NFULA_PAYLOAD];
	if (attr) {
		err = nfnl_log_set_payload(log, nla_data(attr), nla_len(attr));
		if (err < 0)
			goto errout;
	}

	attr = tb[NFULA_PREFIX];
	if (attr) {
		err = nfnl_log_set_prefix(log, nla_data(attr));
		if (err < 0)
			goto errout;
	}

	attr = tb[NFULA_UID];
	if (attr)
		nfnl_log_set_uid(log, ntohl(nla_get_u32(attr)));

	attr = tb[NFULA_SEQ];
	if (attr)
		nfnl_log_set_seq(log, ntohl(nla_get_u32(attr)));

	attr = tb[NFULA_SEQ_GLOBAL];
	if (attr)
		nfnl_log_set_seq_global(log, ntohl(nla_get_u32(attr)));

	return log;

errout:
	nfnl_log_put(log);
	return NULL;
}