Lines Matching refs:sk

92 	struct nl_sock *sk;  in __alloc_socket()  local
94 sk = calloc(1, sizeof(*sk)); in __alloc_socket()
95 if (!sk) in __alloc_socket()
98 sk->s_fd = -1; in __alloc_socket()
99 sk->s_cb = cb; in __alloc_socket()
100 sk->s_local.nl_family = AF_NETLINK; in __alloc_socket()
101 sk->s_peer.nl_family = AF_NETLINK; in __alloc_socket()
102 sk->s_seq_expect = sk->s_seq_next = time(0); in __alloc_socket()
103 sk->s_local.nl_pid = generate_local_port(); in __alloc_socket()
104 if (sk->s_local.nl_pid == UINT_MAX) { in __alloc_socket()
105 nl_socket_free(sk); in __alloc_socket()
109 return sk; in __alloc_socket()
149 void nl_socket_free(struct nl_sock *sk) in nl_socket_free() argument
151 if (!sk) in nl_socket_free()
154 if (sk->s_fd >= 0) in nl_socket_free()
155 close(sk->s_fd); in nl_socket_free()
157 if (!(sk->s_flags & NL_OWN_PORT)) in nl_socket_free()
158 release_local_port(sk->s_local.nl_pid); in nl_socket_free()
160 nl_cb_put(sk->s_cb); in nl_socket_free()
161 free(sk); in nl_socket_free()
188 void nl_socket_disable_seq_check(struct nl_sock *sk) in nl_socket_disable_seq_check() argument
190 nl_cb_set(sk->s_cb, NL_CB_SEQ_CHECK, in nl_socket_disable_seq_check()
203 unsigned int nl_socket_use_seq(struct nl_sock *sk) in nl_socket_use_seq() argument
205 return sk->s_seq_next++; in nl_socket_use_seq()
220 void nl_socket_disable_auto_ack(struct nl_sock *sk) in nl_socket_disable_auto_ack() argument
222 sk->s_flags |= NL_NO_AUTO_ACK; in nl_socket_disable_auto_ack()
230 void nl_socket_enable_auto_ack(struct nl_sock *sk) in nl_socket_enable_auto_ack() argument
232 sk->s_flags &= ~NL_NO_AUTO_ACK; in nl_socket_enable_auto_ack()
242 uint32_t nl_socket_get_local_port(struct nl_sock *sk) in nl_socket_get_local_port() argument
244 return sk->s_local.nl_pid; in nl_socket_get_local_port()
255 void nl_socket_set_local_port(struct nl_sock *sk, uint32_t port) in nl_socket_set_local_port() argument
259 sk->s_flags &= ~NL_OWN_PORT; in nl_socket_set_local_port()
261 if (!(sk->s_flags & NL_OWN_PORT)) in nl_socket_set_local_port()
262 release_local_port(sk->s_local.nl_pid); in nl_socket_set_local_port()
263 sk->s_flags |= NL_OWN_PORT; in nl_socket_set_local_port()
266 sk->s_local.nl_pid = port; in nl_socket_set_local_port()
292 int nl_socket_add_memberships(struct nl_sock *sk, int group, ...) in nl_socket_add_memberships() argument
297 if (sk->s_fd == -1) in nl_socket_add_memberships()
306 err = setsockopt(sk->s_fd, SOL_NETLINK, NETLINK_ADD_MEMBERSHIP, in nl_socket_add_memberships()
319 int nl_socket_add_membership(struct nl_sock *sk, int group) in nl_socket_add_membership() argument
321 return nl_socket_add_memberships(sk, group, 0); in nl_socket_add_membership()
336 int nl_socket_drop_memberships(struct nl_sock *sk, int group, ...) in nl_socket_drop_memberships() argument
341 if (sk->s_fd == -1) in nl_socket_drop_memberships()
350 err = setsockopt(sk->s_fd, SOL_NETLINK, NETLINK_DROP_MEMBERSHIP, in nl_socket_drop_memberships()
363 int nl_socket_drop_membership(struct nl_sock *sk, int group) in nl_socket_drop_membership() argument
365 return nl_socket_drop_memberships(sk, group, 0); in nl_socket_drop_membership()
378 void nl_join_groups(struct nl_sock *sk, int groups) in nl_join_groups() argument
380 sk->s_local.nl_groups |= groups; in nl_join_groups()
391 uint32_t nl_socket_get_peer_port(struct nl_sock *sk) in nl_socket_get_peer_port() argument
393 return sk->s_peer.nl_pid; in nl_socket_get_peer_port()
396 void nl_socket_set_peer_port(struct nl_sock *sk, uint32_t port) in nl_socket_set_peer_port() argument
398 sk->s_peer.nl_pid = port; in nl_socket_set_peer_port()
408 int nl_socket_get_fd(struct nl_sock *sk) in nl_socket_get_fd() argument
410 return sk->s_fd; in nl_socket_get_fd()
419 int nl_socket_set_nonblocking(struct nl_sock *sk) in nl_socket_set_nonblocking() argument
421 if (sk->s_fd == -1) in nl_socket_set_nonblocking()
424 if (fcntl(sk->s_fd, F_SETFL, O_NONBLOCK) < 0) in nl_socket_set_nonblocking()
434 void nl_socket_enable_msg_peek(struct nl_sock *sk) in nl_socket_enable_msg_peek() argument
436 sk->s_flags |= NL_MSG_PEEK; in nl_socket_enable_msg_peek()
443 void nl_socket_disable_msg_peek(struct nl_sock *sk) in nl_socket_disable_msg_peek() argument
445 sk->s_flags &= ~NL_MSG_PEEK; in nl_socket_disable_msg_peek()
455 struct nl_cb *nl_socket_get_cb(struct nl_sock *sk) in nl_socket_get_cb() argument
457 return nl_cb_get(sk->s_cb); in nl_socket_get_cb()
460 void nl_socket_set_cb(struct nl_sock *sk, struct nl_cb *cb) in nl_socket_set_cb() argument
462 nl_cb_put(sk->s_cb); in nl_socket_set_cb()
463 sk->s_cb = nl_cb_get(cb); in nl_socket_set_cb()
476 int nl_socket_modify_cb(struct nl_sock *sk, enum nl_cb_type type, in nl_socket_modify_cb() argument
480 return nl_cb_set(sk->s_cb, type, kind, func, arg); in nl_socket_modify_cb()
503 int nl_socket_set_buffer_size(struct nl_sock *sk, int rxbuf, int txbuf) in nl_socket_set_buffer_size() argument
513 if (sk->s_fd == -1) in nl_socket_set_buffer_size()
516 err = setsockopt(sk->s_fd, SOL_SOCKET, SO_SNDBUF, in nl_socket_set_buffer_size()
521 err = setsockopt(sk->s_fd, SOL_SOCKET, SO_RCVBUF, in nl_socket_set_buffer_size()
526 sk->s_flags |= NL_SOCK_BUFSIZE_SET; in nl_socket_set_buffer_size()
538 int nl_socket_set_passcred(struct nl_sock *sk, int state) in nl_socket_set_passcred() argument
542 if (sk->s_fd == -1) in nl_socket_set_passcred()
545 err = setsockopt(sk->s_fd, SOL_SOCKET, SO_PASSCRED, in nl_socket_set_passcred()
551 sk->s_flags |= NL_SOCK_PASSCRED; in nl_socket_set_passcred()
553 sk->s_flags &= ~NL_SOCK_PASSCRED; in nl_socket_set_passcred()
565 int nl_socket_recv_pktinfo(struct nl_sock *sk, int state) in nl_socket_recv_pktinfo() argument
569 if (sk->s_fd == -1) in nl_socket_recv_pktinfo()
572 err = setsockopt(sk->s_fd, SOL_NETLINK, NETLINK_PKTINFO, in nl_socket_recv_pktinfo()