MCPcopy Create free account
hub / github.com/F-Stack/f-stack / mlx5_nl_init

Function mlx5_nl_init

dpdk/drivers/common/mlx5/linux/mlx5_nl.c:195–251  ·  view source on GitHub ↗

* Opens a Netlink socket. * * @param protocol * Netlink protocol (e.g. NETLINK_ROUTE, NETLINK_RDMA). * @param groups * Groups to listen (e.g. RTMGRP_LINK), can be 0. * * @return * A file descriptor on success, a negative errno value otherwise and * rte_errno is set. */

Source from the content-addressed store, hash-verified

193 * rte_errno is set.
194 */
195int
196mlx5_nl_init(int protocol, int groups)
197{
198 int fd;
199 int buf_size;
200 socklen_t opt_size;
201 struct sockaddr_nl local = {
202 .nl_family = AF_NETLINK,
203 .nl_groups = groups,
204 };
205 int ret;
206
207 fd = socket(AF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, protocol);
208 if (fd == -1) {
209 rte_errno = errno;
210 return -rte_errno;
211 }
212 opt_size = sizeof(buf_size);
213 ret = getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &buf_size, &opt_size);
214 if (ret == -1) {
215 rte_errno = errno;
216 goto error;
217 }
218 DRV_LOG(DEBUG, "Netlink socket send buffer: %d", buf_size);
219 if (buf_size < MLX5_SEND_BUF_SIZE) {
220 ret = setsockopt(fd, SOL_SOCKET, SO_SNDBUF,
221 &buf_size, sizeof(buf_size));
222 if (ret == -1) {
223 rte_errno = errno;
224 goto error;
225 }
226 }
227 opt_size = sizeof(buf_size);
228 ret = getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &buf_size, &opt_size);
229 if (ret == -1) {
230 rte_errno = errno;
231 goto error;
232 }
233 DRV_LOG(DEBUG, "Netlink socket recv buffer: %d", buf_size);
234 if (buf_size < MLX5_RECV_BUF_SIZE) {
235 ret = setsockopt(fd, SOL_SOCKET, SO_RCVBUF,
236 &buf_size, sizeof(buf_size));
237 if (ret == -1) {
238 rte_errno = errno;
239 goto error;
240 }
241 }
242 ret = bind(fd, (struct sockaddr *)&local, sizeof(local));
243 if (ret == -1) {
244 rte_errno = errno;
245 goto error;
246 }
247 return fd;
248error:
249 close(fd);
250 return -rte_errno;
251}
252

Callers 7

mlx5_vlan_vmwa_initFunction · 0.85
mlx5_dev_spawnFunction · 0.85
mlx5_os_pci_probe_pfFunction · 0.85
mlx5_nl_roce_disableFunction · 0.85

Calls 5

getsockoptFunction · 0.85
socketClass · 0.50
setsockoptFunction · 0.50
bindFunction · 0.50
closeFunction · 0.50

Tested by

no test coverage detected