* Send a message to the kernel on the netlink socket. * * @param[in] nlsk_fd * The netlink socket file descriptor used for communication. * @param[in] nh * The netlink message send to the kernel. * * @return * the number of sent bytes on success, -1 otherwise. */
| 115 | * the number of sent bytes on success, -1 otherwise. |
| 116 | */ |
| 117 | int |
| 118 | tap_nl_send(int nlsk_fd, struct nlmsghdr *nh) |
| 119 | { |
| 120 | int send_bytes; |
| 121 | |
| 122 | nh->nlmsg_pid = 0; /* communication with the kernel uses pid 0 */ |
| 123 | nh->nlmsg_seq = (uint32_t)rte_rand(); |
| 124 | |
| 125 | retry: |
| 126 | send_bytes = send(nlsk_fd, nh, nh->nlmsg_len, 0); |
| 127 | if (send_bytes < 0) { |
| 128 | if (errno == EINTR) |
| 129 | goto retry; |
| 130 | |
| 131 | TAP_LOG(ERR, "Failed to send netlink message: %s (%d)", |
| 132 | strerror(errno), errno); |
| 133 | return -1; |
| 134 | } |
| 135 | return send_bytes; |
| 136 | } |
| 137 | |
| 138 | #ifdef NETLINK_EXT_ACK |
| 139 | static const struct nlattr * |
no test coverage detected