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
77
78 err =
nlmsg_parse(nlh,
sizeof(
struct nfgenmsg), tb, NFULA_MAX,
79 log_policy);
80 if (err < 0)
81 goto errout;
82
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)
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)
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) {
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)
147
148 attr = tb[NFULA_SEQ];
149 if (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
uint32_t nla_get_u32(struct nlattr *nla)
Return payload of u32 attribute.
int nla_len(const struct nlattr *nla)
length of payload
int nlmsg_parse(struct nlmsghdr *nlh, int hdrlen, struct nlattr *tb[], int maxtype, struct nla_policy *policy)
parse attributes of a netlink message
uint8_t nfnlmsg_family(struct nlmsghdr *nlh)
Get netfilter family from message.
uint16_t nlmsg_type
Message type (content type)