Lines Matching refs:nfnlh
74 struct nfnl_handle *nfnlh; member
145 static int recalc_rebind_subscriptions(struct nfnl_handle *nfnlh) in recalc_rebind_subscriptions() argument
148 u_int32_t new_subscriptions = nfnlh->subscriptions; in recalc_rebind_subscriptions()
151 new_subscriptions |= nfnlh->subsys[i].subscriptions; in recalc_rebind_subscriptions()
153 nfnlh->local.nl_groups = new_subscriptions; in recalc_rebind_subscriptions()
154 err = bind(nfnlh->fd, (struct sockaddr *)&nfnlh->local, in recalc_rebind_subscriptions()
155 sizeof(nfnlh->local)); in recalc_rebind_subscriptions()
159 nfnlh->subscriptions = new_subscriptions; in recalc_rebind_subscriptions()
164 static void recalc_subscriptions(struct nfnl_handle *nfnlh) in recalc_subscriptions() argument
167 u_int32_t new_subscriptions = nfnlh->subscriptions; in recalc_subscriptions()
170 new_subscriptions |= nfnlh->subsys[i].subscriptions; in recalc_subscriptions()
172 nfnlh->local.nl_groups = new_subscriptions; in recalc_subscriptions()
173 nfnlh->subscriptions = new_subscriptions; in recalc_subscriptions()
187 struct nfnl_handle *nfnlh; in nfnl_open() local
193 nfnlh = nfnl_open2(fd, true); in nfnl_open()
194 if (nfnlh == NULL) in nfnl_open()
196 return nfnlh; in nfnl_open()
212 struct nfnl_handle *nfnlh; in nfnl_open2() local
218 nfnlh = malloc(sizeof(*nfnlh)); in nfnl_open2()
219 if (!nfnlh) in nfnl_open2()
222 memset(nfnlh, 0, sizeof(*nfnlh)); in nfnl_open2()
223 nfnlh->fd = fd; in nfnl_open2()
225 nfnlh->local.nl_family = AF_NETLINK; in nfnl_open2()
226 nfnlh->peer.nl_family = AF_NETLINK; in nfnl_open2()
228 addr_len = sizeof(nfnlh->local); in nfnl_open2()
229 getsockname(nfnlh->fd, (struct sockaddr *)&nfnlh->local, &addr_len); in nfnl_open2()
230 if (addr_len != sizeof(nfnlh->local)) { in nfnl_open2()
234 if (nfnlh->local.nl_family != AF_NETLINK) { in nfnl_open2()
238 nfnlh->seq = time(NULL); in nfnl_open2()
239 nfnlh->rcv_buffer_size = NFNL_BUFFSIZE; in nfnl_open2()
246 if (recalc_rebind_subscriptions(nfnlh) < 0) in nfnl_open2()
249 recalc_subscriptions(nfnlh); in nfnl_open2()
253 addr_len = sizeof(nfnlh->local); in nfnl_open2()
254 getsockname(nfnlh->fd, (struct sockaddr *)&nfnlh->local, &addr_len); in nfnl_open2()
255 if (addr_len != sizeof(nfnlh->local)) { in nfnl_open2()
260 nfnlh->flags |= NFNL_F_SEQTRACK_ENABLED; in nfnl_open2()
262 return nfnlh; in nfnl_open2()
265 free(nfnlh); in nfnl_open2()
317 nfnl_subsys_open(struct nfnl_handle *nfnlh, u_int8_t subsys_id, in nfnl_subsys_open() argument
320 return nfnl_subsys_open2 (nfnlh, subsys_id, cb_count, subscriptions, true); in nfnl_subsys_open()
340 nfnl_subsys_open2(struct nfnl_handle *nfnlh, u_int8_t subsys_id, in nfnl_subsys_open2() argument
346 assert(nfnlh); in nfnl_subsys_open2()
353 ssh = &nfnlh->subsys[subsys_id]; in nfnl_subsys_open2()
363 ssh->nfnlh = nfnlh; in nfnl_subsys_open2()
371 err = recalc_rebind_subscriptions(nfnlh); in nfnl_subsys_open2()
373 recalc_subscriptions(nfnlh); in nfnl_subsys_open2()
407 int nfnl_close(struct nfnl_handle *nfnlh) in nfnl_close() argument
411 assert(nfnlh); in nfnl_close()
412 ret = close(nfnlh->fd); in nfnl_close()
415 return nfnl_close2(nfnlh); in nfnl_close()
425 int nfnl_close2(struct nfnl_handle *nfnlh) in nfnl_close2() argument
429 assert(nfnlh); in nfnl_close2()
432 nfnl_subsys_close(&nfnlh->subsys[i]); in nfnl_close2()
434 free(nfnlh); in nfnl_close2()
451 int nfnl_join(const struct nfnl_handle *nfnlh, unsigned int group) in nfnl_join() argument
453 assert(nfnlh); in nfnl_join()
454 return setsockopt(nfnlh->fd, SOL_NETLINK, NETLINK_ADD_MEMBERSHIP, in nfnl_join()
466 int nfnl_send(struct nfnl_handle *nfnlh, struct nlmsghdr *n) in nfnl_send() argument
468 assert(nfnlh); in nfnl_send()
473 return sendto(nfnlh->fd, n, n->nlmsg_len, 0, in nfnl_send()
474 (struct sockaddr *)&nfnlh->peer, sizeof(nfnlh->peer)); in nfnl_send()
477 int nfnl_sendmsg(const struct nfnl_handle *nfnlh, const struct msghdr *msg, in nfnl_sendmsg() argument
480 assert(nfnlh); in nfnl_sendmsg()
483 return sendmsg(nfnlh->fd, msg, flags); in nfnl_sendmsg()
486 int nfnl_sendiov(const struct nfnl_handle *nfnlh, const struct iovec *iov, in nfnl_sendiov() argument
491 assert(nfnlh); in nfnl_sendiov()
493 msg.msg_name = (struct sockaddr *) &nfnlh->peer; in nfnl_sendiov()
494 msg.msg_namelen = sizeof(nfnlh->peer); in nfnl_sendiov()
501 return nfnl_sendmsg(nfnlh, &msg, flags); in nfnl_sendiov()
535 if (ssh->nfnlh->flags & NFNL_F_SEQTRACK_ENABLED) { in nfnl_fill_hdr()
536 nlh->nlmsg_seq = ++ssh->nfnlh->seq; in nfnl_fill_hdr()
538 if (!ssh->nfnlh->seq) in nfnl_fill_hdr()
539 nlh->nlmsg_seq = ssh->nfnlh->seq = time(NULL); in nfnl_fill_hdr()
551 nfnl_parse_hdr(const struct nfnl_handle *nfnlh, in nfnl_parse_hdr() argument
644 int nfnl_listen(struct nfnl_handle *nfnlh, in nfnl_listen() argument
669 remain = recvmsg(nfnlh->fd, &msg, 0); in nfnl_listen()
753 int nfnl_talk(struct nfnl_handle *nfnlh, struct nlmsghdr *n, pid_t peer, in nfnl_talk() argument
778 n->nlmsg_seq = seq = ++nfnlh->seq; in nfnl_talk()
783 status = sendmsg(nfnlh->fd, &msg, 0); in nfnl_talk()
792 status = recvmsg(nfnlh->fd, &msg, 0); in nfnl_talk()
823 if (h->nlmsg_pid != nfnlh->local.nl_pid || in nfnl_talk()