- if (cmsg == NULL) {
- WARN("no message");
- goto out;
- }
- if ((cmsg->cmsg_type == SCM_CREDENTIALS) &&
- (cmsg->cmsg_len >= sizeof(*cred))) {
- cred = (struct ucred *)CMSG_DATA(cmsg);
- assert(cred != NULL);
- }
- cmsg = CMSG_NXTHDR(&msg, cmsg);
- if (cmsg != NULL) {
- WARN("Message wrongly formatted");
- goto out;
- }
- /* Make sure all the ancillary data was received and valid. */
- if ((cred == NULL) || (cred->uid != getuid()) ||
- (cred->gid != getgid())) {
- WARN("wrong credentials");
- goto out;
- }
- /* Set-up the ancillary data. */
- cmsg = CMSG_FIRSTHDR(&msg);
- assert(cmsg != NULL);
- cmsg->cmsg_level = SOL_SOCKET;
- cmsg->cmsg_type = SCM_RIGHTS;
- cmsg->cmsg_len = CMSG_LEN(sizeof(priv->ctx->cmd_fd));
- fd = (int *)CMSG_DATA(cmsg);
- *fd = priv->ctx->cmd_fd;
- ret = sendmsg(conn_sock, &msg, 0);
+ if (cmsg == NULL || cmsg->cmsg_type != SCM_RIGHTS ||
+ cmsg->cmsg_len < sizeof(int)) {
+ DRV_LOG(WARNING, "invalid file descriptor message");
+ goto error;
+ }
+ memcpy(&fd, CMSG_DATA(cmsg), sizeof(fd));
+ file = fdopen(fd, "w");
+ if (!file) {
+ DRV_LOG(WARNING, "Failed to open file");
+ goto error;
+ }
+ /* Receive port number. */
+ if (msg.msg_iovlen != 1 || msg.msg_iov->iov_len < sizeof(uint16_t)) {
+ DRV_LOG(WARNING, "wrong port number message");
+ goto error;
+ }
+ memcpy(&port_id, msg.msg_iov->iov_base, sizeof(port_id));
+ if (!rte_eth_dev_is_valid_port(port_id)) {
+ DRV_LOG(WARNING, "Invalid port %u", port_id);
+ goto error;
+ }
+ /* Dump flow. */
+ dev = &rte_eth_devices[port_id];
+ ret = mlx5_flow_dev_dump(dev, file, NULL);
+ /* Set-up the ancillary data and reply. */
+ msg.msg_controllen = 0;
+ msg.msg_control = NULL;
+ msg.msg_iovlen = 1;
+ msg.msg_iov = &io;
+ data = -ret;
+ io.iov_len = sizeof(data);
+ io.iov_base = &data;
+ do {
+ ret = sendmsg(conn_sock, &msg, 0);
+ } while (ret < 0 && errno == EINTR);