-static ssize_t netlink_check_ack(struct nlmsghdr *ack_nh, ssize_t len, int msg_count)
-{
- uint32_t seqnum = 0;
-
- // expect ack
- for (; NLMSG_OK (ack_nh, len); ack_nh = NLMSG_NEXT (ack_nh, len))
- {
- if (ack_nh->nlmsg_type == NLMSG_DONE)
- return msg_count != 0 || seqnum != nlseqnum;
- // 1 => lost an ack
-
- if (ack_nh->nlmsg_type == NLMSG_ERROR)
- {
- struct nlmsgerr *errmsg = NLMSG_DATA(ack_nh);
- if (errmsg->error)
- return errmsg->error; // got an error back
- else
- {
- // ack received
- --msg_count;
- if (errmsg->msg.nlmsg_seq > seqnum);
- seqnum = errmsg->msg.nlmsg_seq;
- // if this is a single message, return now
- if (!(ack_nh->nlmsg_flags & NLM_F_MULTI))
- return msg_count != 0 || seqnum != nlseqnum;
- }
- }
- else
- // unknown message
- LOG(3, 0, 0, "Got an unknown netlink message: type %d\n", ack_nh->nlmsg_type);
- }
-
- return 1; // malformed message?!
-}
-