Lines Matching refs:sk
183 struct nl_sock *sk; in __alloc_socket() local
185 sk = calloc(1, sizeof(*sk)); in __alloc_socket()
186 if (!sk) in __alloc_socket()
189 sk->s_fd = -1; in __alloc_socket()
190 sk->s_cb = nl_cb_get(cb); in __alloc_socket()
191 sk->s_local.nl_family = AF_NETLINK; in __alloc_socket()
192 sk->s_peer.nl_family = AF_NETLINK; in __alloc_socket()
193 sk->s_seq_expect = sk->s_seq_next = time(NULL); in __alloc_socket()
196 sk->s_flags = NL_OWN_PORT; in __alloc_socket()
198 return sk; in __alloc_socket()
209 struct nl_sock *sk; in nl_socket_alloc() local
216 sk = __alloc_socket(cb); in nl_socket_alloc()
220 return sk; in nl_socket_alloc()
244 void nl_socket_free(struct nl_sock *sk) in nl_socket_free() argument
246 if (!sk) in nl_socket_free()
249 if (sk->s_fd >= 0) in nl_socket_free()
250 close(sk->s_fd); in nl_socket_free()
252 if (!(sk->s_flags & NL_OWN_PORT)) in nl_socket_free()
253 release_local_port(sk->s_local.nl_pid); in nl_socket_free()
255 nl_cb_put(sk->s_cb); in nl_socket_free()
256 free(sk); in nl_socket_free()
283 void nl_socket_disable_seq_check(struct nl_sock *sk) in nl_socket_disable_seq_check() argument
285 nl_cb_set(sk->s_cb, NL_CB_SEQ_CHECK, in nl_socket_disable_seq_check()
298 unsigned int nl_socket_use_seq(struct nl_sock *sk) in nl_socket_use_seq() argument
300 return sk->s_seq_next++; in nl_socket_use_seq()
315 void nl_socket_disable_auto_ack(struct nl_sock *sk) in nl_socket_disable_auto_ack() argument
317 sk->s_flags |= NL_NO_AUTO_ACK; in nl_socket_disable_auto_ack()
325 void nl_socket_enable_auto_ack(struct nl_sock *sk) in nl_socket_enable_auto_ack() argument
327 sk->s_flags &= ~NL_NO_AUTO_ACK; in nl_socket_enable_auto_ack()
333 int _nl_socket_is_local_port_unspecified(struct nl_sock *sk) in _nl_socket_is_local_port_unspecified() argument
335 return (sk->s_local.nl_pid == 0); in _nl_socket_is_local_port_unspecified()
338 uint32_t _nl_socket_set_local_port_no_release(struct nl_sock *sk, int generate_other) in _nl_socket_set_local_port_no_release() argument
349 sk->s_local.nl_pid = port; in _nl_socket_set_local_port_no_release()
353 sk->s_flags |= NL_OWN_PORT; in _nl_socket_set_local_port_no_release()
355 sk->s_flags &= ~NL_OWN_PORT; in _nl_socket_set_local_port_no_release()
365 uint32_t nl_socket_get_local_port(const struct nl_sock *sk) in nl_socket_get_local_port() argument
367 if (sk->s_local.nl_pid == 0) { in nl_socket_get_local_port()
368 struct nl_sock *sk_mutable = (struct nl_sock *) sk; in nl_socket_get_local_port()
389 return sk->s_local.nl_pid; in nl_socket_get_local_port()
404 void nl_socket_set_local_port(struct nl_sock *sk, uint32_t port) in nl_socket_set_local_port() argument
406 if (!(sk->s_flags & NL_OWN_PORT)) in nl_socket_set_local_port()
407 release_local_port(sk->s_local.nl_pid); in nl_socket_set_local_port()
408 sk->s_flags |= NL_OWN_PORT; in nl_socket_set_local_port()
409 sk->s_local.nl_pid = port; in nl_socket_set_local_port()
435 int nl_socket_add_memberships(struct nl_sock *sk, int group, ...) in nl_socket_add_memberships() argument
440 if (sk->s_fd == -1) in nl_socket_add_memberships()
451 err = setsockopt(sk->s_fd, SOL_NETLINK, NETLINK_ADD_MEMBERSHIP, in nl_socket_add_memberships()
456 sk, errno, nl_strerror_l(errno)); in nl_socket_add_memberships()
468 int nl_socket_add_membership(struct nl_sock *sk, int group) in nl_socket_add_membership() argument
470 return nl_socket_add_memberships(sk, group, 0); in nl_socket_add_membership()
485 int nl_socket_drop_memberships(struct nl_sock *sk, int group, ...) in nl_socket_drop_memberships() argument
490 if (sk->s_fd == -1) in nl_socket_drop_memberships()
501 err = setsockopt(sk->s_fd, SOL_NETLINK, NETLINK_DROP_MEMBERSHIP, in nl_socket_drop_memberships()
506 sk, errno, nl_strerror_l(errno)); in nl_socket_drop_memberships()
518 int nl_socket_drop_membership(struct nl_sock *sk, int group) in nl_socket_drop_membership() argument
520 return nl_socket_drop_memberships(sk, group, 0); in nl_socket_drop_membership()
533 void nl_join_groups(struct nl_sock *sk, int groups) in nl_join_groups() argument
535 sk->s_local.nl_groups |= groups; in nl_join_groups()
546 uint32_t nl_socket_get_peer_port(const struct nl_sock *sk) in nl_socket_get_peer_port() argument
548 return sk->s_peer.nl_pid; in nl_socket_get_peer_port()
551 void nl_socket_set_peer_port(struct nl_sock *sk, uint32_t port) in nl_socket_set_peer_port() argument
553 sk->s_peer.nl_pid = port; in nl_socket_set_peer_port()
556 uint32_t nl_socket_get_peer_groups(const struct nl_sock *sk) in nl_socket_get_peer_groups() argument
558 return sk->s_peer.nl_groups; in nl_socket_get_peer_groups()
561 void nl_socket_set_peer_groups(struct nl_sock *sk, uint32_t groups) in nl_socket_set_peer_groups() argument
563 sk->s_peer.nl_groups = groups; in nl_socket_set_peer_groups()
584 int nl_socket_get_fd(const struct nl_sock *sk) in nl_socket_get_fd() argument
586 return sk->s_fd; in nl_socket_get_fd()
616 int nl_socket_set_fd(struct nl_sock *sk, int protocol, int fd) in nl_socket_set_fd() argument
623 if (sk->s_fd != -1) in nl_socket_set_fd()
633 sk, fd, errno, nl_strerror_l(errno)); in nl_socket_set_fd()
640 sk, fd, local.nl_family, AF_NETLINK); in nl_socket_set_fd()
648 sk, fd, errno, nl_strerror_l(errno)); in nl_socket_set_fd()
655 sk, fd, so_type, SOCK_RAW); in nl_socket_set_fd()
666 sk, fd, errno, nl_strerror_l(errno)); in nl_socket_set_fd()
673 sk, fd, so_protocol, protocol); in nl_socket_set_fd()
683 sk, fd); in nl_socket_set_fd()
689 nl_socket_set_local_port (sk, local.nl_pid); in nl_socket_set_fd()
690 sk->s_local = local; in nl_socket_set_fd()
691 sk->s_fd = fd; in nl_socket_set_fd()
692 sk->s_proto = so_protocol; in nl_socket_set_fd()
703 int nl_socket_set_nonblocking(const struct nl_sock *sk) in nl_socket_set_nonblocking() argument
705 if (sk->s_fd == -1) in nl_socket_set_nonblocking()
708 if (fcntl(sk->s_fd, F_SETFL, O_NONBLOCK) < 0) { in nl_socket_set_nonblocking()
710 sk, errno, nl_strerror_l(errno)); in nl_socket_set_nonblocking()
723 void nl_socket_enable_msg_peek(struct nl_sock *sk) in nl_socket_enable_msg_peek() argument
725 sk->s_flags |= (NL_MSG_PEEK | NL_MSG_PEEK_EXPLICIT); in nl_socket_enable_msg_peek()
734 void nl_socket_disable_msg_peek(struct nl_sock *sk) in nl_socket_disable_msg_peek() argument
736 sk->s_flags |= NL_MSG_PEEK_EXPLICIT; in nl_socket_disable_msg_peek()
737 sk->s_flags &= ~NL_MSG_PEEK; in nl_socket_disable_msg_peek()
747 struct nl_cb *nl_socket_get_cb(const struct nl_sock *sk) in nl_socket_get_cb() argument
749 return nl_cb_get(sk->s_cb); in nl_socket_get_cb()
752 void nl_socket_set_cb(struct nl_sock *sk, struct nl_cb *cb) in nl_socket_set_cb() argument
757 nl_cb_put(sk->s_cb); in nl_socket_set_cb()
758 sk->s_cb = nl_cb_get(cb); in nl_socket_set_cb()
771 int nl_socket_modify_cb(struct nl_sock *sk, enum nl_cb_type type, in nl_socket_modify_cb() argument
775 return nl_cb_set(sk->s_cb, type, kind, func, arg); in nl_socket_modify_cb()
787 int nl_socket_modify_err_cb(struct nl_sock *sk, enum nl_cb_kind kind, in nl_socket_modify_err_cb() argument
790 return nl_cb_err(sk->s_cb, kind, func, arg); in nl_socket_modify_err_cb()
813 int nl_socket_set_buffer_size(struct nl_sock *sk, int rxbuf, int txbuf) in nl_socket_set_buffer_size() argument
823 if (sk->s_fd == -1) in nl_socket_set_buffer_size()
826 err = setsockopt(sk->s_fd, SOL_SOCKET, SO_SNDBUF, in nl_socket_set_buffer_size()
830 sk, errno, nl_strerror_l(errno)); in nl_socket_set_buffer_size()
834 err = setsockopt(sk->s_fd, SOL_SOCKET, SO_RCVBUF, in nl_socket_set_buffer_size()
838 sk, errno, nl_strerror_l(errno)); in nl_socket_set_buffer_size()
870 int nl_socket_set_msg_buf_size(struct nl_sock *sk, size_t bufsize) in nl_socket_set_msg_buf_size() argument
872 sk->s_bufsize = bufsize; in nl_socket_set_msg_buf_size()
883 size_t nl_socket_get_msg_buf_size(struct nl_sock *sk) in nl_socket_get_msg_buf_size() argument
885 return sk->s_bufsize; in nl_socket_get_msg_buf_size()
895 int nl_socket_set_passcred(struct nl_sock *sk, int state) in nl_socket_set_passcred() argument
899 if (sk->s_fd == -1) in nl_socket_set_passcred()
902 err = setsockopt(sk->s_fd, SOL_SOCKET, SO_PASSCRED, in nl_socket_set_passcred()
906 sk, errno, nl_strerror_l(errno)); in nl_socket_set_passcred()
911 sk->s_flags |= NL_SOCK_PASSCRED; in nl_socket_set_passcred()
913 sk->s_flags &= ~NL_SOCK_PASSCRED; in nl_socket_set_passcred()
925 int nl_socket_recv_pktinfo(struct nl_sock *sk, int state) in nl_socket_recv_pktinfo() argument
929 if (sk->s_fd == -1) in nl_socket_recv_pktinfo()
932 err = setsockopt(sk->s_fd, SOL_NETLINK, NETLINK_PKTINFO, in nl_socket_recv_pktinfo()
936 sk, errno, nl_strerror_l(errno)); in nl_socket_recv_pktinfo()