Lines Matching refs:nl
30 static int broadcast_groups_get(sd_netlink *nl) { in broadcast_groups_get() argument
35 assert(nl); in broadcast_groups_get()
36 assert(nl->fd >= 0); in broadcast_groups_get()
38 if (getsockopt(nl->fd, SOL_NETLINK, NETLINK_LIST_MEMBERSHIPS, NULL, &len) < 0) { in broadcast_groups_get()
42 nl->broadcast_group_dont_leave = true; in broadcast_groups_get()
55 if (getsockopt(nl->fd, SOL_NETLINK, NETLINK_LIST_MEMBERSHIPS, groups, &len) < 0) in broadcast_groups_get()
66 … r = hashmap_ensure_put(&nl->broadcast_group_refs, NULL, UINT_TO_PTR(group), UINT_TO_PTR(1)); in broadcast_groups_get()
74 int socket_bind(sd_netlink *nl) { in socket_bind() argument
78 r = setsockopt_int(nl->fd, SOL_NETLINK, NETLINK_PKTINFO, true); in socket_bind()
82 addrlen = sizeof(nl->sockaddr); in socket_bind()
85 if (bind(nl->fd, &nl->sockaddr.sa, addrlen) < 0 && errno != EINVAL) in socket_bind()
88 if (getsockname(nl->fd, &nl->sockaddr.sa, &addrlen) < 0) in socket_bind()
91 return broadcast_groups_get(nl); in socket_bind()
94 static unsigned broadcast_group_get_ref(sd_netlink *nl, unsigned group) { in broadcast_group_get_ref() argument
95 assert(nl); in broadcast_group_get_ref()
97 return PTR_TO_UINT(hashmap_get(nl->broadcast_group_refs, UINT_TO_PTR(group))); in broadcast_group_get_ref()
100 static int broadcast_group_set_ref(sd_netlink *nl, unsigned group, unsigned n_ref) { in broadcast_group_set_ref() argument
103 assert(nl); in broadcast_group_set_ref()
105 r = hashmap_ensure_allocated(&nl->broadcast_group_refs, NULL); in broadcast_group_set_ref()
109 return hashmap_replace(nl->broadcast_group_refs, UINT_TO_PTR(group), UINT_TO_PTR(n_ref)); in broadcast_group_set_ref()
112 static int broadcast_group_join(sd_netlink *nl, unsigned group) { in broadcast_group_join() argument
113 assert(nl); in broadcast_group_join()
114 assert(nl->fd >= 0); in broadcast_group_join()
118 return setsockopt_int(nl->fd, SOL_NETLINK, NETLINK_ADD_MEMBERSHIP, group); in broadcast_group_join()
121 int socket_broadcast_group_ref(sd_netlink *nl, unsigned group) { in socket_broadcast_group_ref() argument
125 assert(nl); in socket_broadcast_group_ref()
127 n_ref = broadcast_group_get_ref(nl, group); in socket_broadcast_group_ref()
131 r = broadcast_group_set_ref(nl, group, n_ref); in socket_broadcast_group_ref()
139 return broadcast_group_join(nl, group); in socket_broadcast_group_ref()
142 static int broadcast_group_leave(sd_netlink *nl, unsigned group) { in broadcast_group_leave() argument
143 assert(nl); in broadcast_group_leave()
144 assert(nl->fd >= 0); in broadcast_group_leave()
147 if (nl->broadcast_group_dont_leave) in broadcast_group_leave()
151 return setsockopt_int(nl->fd, SOL_NETLINK, NETLINK_DROP_MEMBERSHIP, group); in broadcast_group_leave()
154 int socket_broadcast_group_unref(sd_netlink *nl, unsigned group) { in socket_broadcast_group_unref() argument
158 assert(nl); in socket_broadcast_group_unref()
160 n_ref = broadcast_group_get_ref(nl, group); in socket_broadcast_group_unref()
166 r = broadcast_group_set_ref(nl, group, n_ref); in socket_broadcast_group_unref()
174 return broadcast_group_leave(nl, group); in socket_broadcast_group_unref()
178 int socket_write_message(sd_netlink *nl, sd_netlink_message *m) { in socket_write_message() argument
180 .nl.nl_family = AF_NETLINK, in socket_write_message()
184 assert(nl); in socket_write_message()
188 k = sendto(nl->fd, m->hdr, m->hdr->nlmsg_len, 0, &addr.sa, sizeof(addr)); in socket_write_message()
195 int socket_writev_message(sd_netlink *nl, sd_netlink_message **m, size_t msgcount) { in socket_writev_message() argument
199 assert(nl); in socket_writev_message()
214 k = writev(nl->fd, iovs, msgcount); in socket_writev_message()
246 if (sender.nl.nl_pid != 0) { in socket_recv_message()
248 log_debug("sd-netlink: ignoring message from PID %"PRIu32, sender.nl.nl_pid); in socket_recv_message()
278 int socket_read_message(sd_netlink *nl) { in socket_read_message() argument
287 assert(nl); in socket_read_message()
288 assert(nl->rbuffer); in socket_read_message()
291 r = socket_recv_message(nl->fd, &iov, NULL, true); in socket_read_message()
298 if (!greedy_realloc((void**) &nl->rbuffer, len, sizeof(uint8_t))) in socket_read_message()
301 allocated = MALLOC_SIZEOF_SAFE(nl->rbuffer); in socket_read_message()
302 iov = IOVEC_MAKE(nl->rbuffer, allocated); in socket_read_message()
305 r = socket_recv_message(nl->fd, &iov, &group, false); in socket_read_message()
315 if (NLMSG_OK(nl->rbuffer, len) && nl->rbuffer->nlmsg_flags & NLM_F_MULTI) { in socket_read_message()
318 for (i = 0; i < nl->rqueue_partial_size; i++) in socket_read_message()
319 if (message_get_serial(nl->rqueue_partial[i]) == in socket_read_message()
320 nl->rbuffer->nlmsg_seq) { in socket_read_message()
321 first = nl->rqueue_partial[i]; in socket_read_message()
326 …for (struct nlmsghdr *new_msg = nl->rbuffer; NLMSG_OK(new_msg, len) && !done; new_msg = NLMSG_NEXT… in socket_read_message()
330 if (group == 0 && new_msg->nlmsg_pid != nl->sockaddr.nl.nl_pid) in socket_read_message()
348 … r = type_system_root_get_type_system_and_header_size(nl, new_msg->nlmsg_type, NULL, &size); in socket_read_message()
363 r = message_new_empty(nl, &m); in socket_read_message()
373 r = sd_netlink_message_rewind(m, nl); in socket_read_message()
391 r = netlink_rqueue_make_room(nl); in socket_read_message()
395 nl->rqueue[nl->rqueue_size++] = TAKE_PTR(first); in socket_read_message()
397 if (multi_part && (i < nl->rqueue_partial_size)) { in socket_read_message()
399 memmove(nl->rqueue_partial + i, nl->rqueue_partial + i + 1, in socket_read_message()
400 sizeof(sd_netlink_message*) * (nl->rqueue_partial_size - i - 1)); in socket_read_message()
401 nl->rqueue_partial_size--; in socket_read_message()
408 if (i < nl->rqueue_partial_size) in socket_read_message()
409 nl->rqueue_partial[i] = TAKE_PTR(first); in socket_read_message()
411 r = netlink_rqueue_partial_make_room(nl); in socket_read_message()
415 nl->rqueue_partial[nl->rqueue_partial_size++] = TAKE_PTR(first); in socket_read_message()