nl: Provide API to specify the default buffer size when receiving netlink messages
New functions: nl_socket_set_msg_buf_size(sk, size) nl_socket_get_msg_buf_size(sk) Default remains getpagesize() Signed-off-by: Thomas Graf <tgraf@redhat.com>
This commit is contained in:
parent
72c2cb9e29
commit
e4192ff97f
|
@ -69,6 +69,7 @@ struct nl_sock
|
||||||
unsigned int s_seq_expect;
|
unsigned int s_seq_expect;
|
||||||
int s_flags;
|
int s_flags;
|
||||||
struct nl_cb * s_cb;
|
struct nl_cb * s_cb;
|
||||||
|
size_t s_bufsize;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct nl_cache
|
struct nl_cache
|
||||||
|
|
|
@ -49,6 +49,8 @@ extern int nl_socket_modify_err_cb(struct nl_sock *, enum nl_cb_kind,
|
||||||
nl_recvmsg_err_cb_t, void *);
|
nl_recvmsg_err_cb_t, void *);
|
||||||
|
|
||||||
extern int nl_socket_set_buffer_size(struct nl_sock *, int, int);
|
extern int nl_socket_set_buffer_size(struct nl_sock *, int, int);
|
||||||
|
extern int nl_socket_set_msg_buf_size(struct nl_sock *, size_t);
|
||||||
|
extern size_t nl_socket_get_msg_buf_size(struct nl_sock *);
|
||||||
extern int nl_socket_set_passcred(struct nl_sock *, int);
|
extern int nl_socket_set_passcred(struct nl_sock *, int);
|
||||||
extern int nl_socket_recv_pktinfo(struct nl_sock *, int);
|
extern int nl_socket_recv_pktinfo(struct nl_sock *, int);
|
||||||
|
|
||||||
|
|
2
lib/nl.c
2
lib/nl.c
|
@ -447,7 +447,7 @@ int nl_recv(struct nl_sock *sk, struct sockaddr_nl *nla,
|
||||||
if (page_size == 0)
|
if (page_size == 0)
|
||||||
page_size = getpagesize();
|
page_size = getpagesize();
|
||||||
|
|
||||||
iov.iov_len = page_size;
|
iov.iov_len = sk->s_bufsize ? : page_size;
|
||||||
iov.iov_base = *buf = malloc(iov.iov_len);
|
iov.iov_base = *buf = malloc(iov.iov_len);
|
||||||
|
|
||||||
if (sk->s_flags & NL_SOCK_PASSCRED) {
|
if (sk->s_flags & NL_SOCK_PASSCRED) {
|
||||||
|
|
30
lib/socket.c
30
lib/socket.c
|
@ -586,6 +586,36 @@ int nl_socket_set_buffer_size(struct nl_sock *sk, int rxbuf, int txbuf)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set default message buffer size of netlink socket.
|
||||||
|
* @arg sk Netlink socket.
|
||||||
|
* @arg bufsize Default message buffer size in bytes.
|
||||||
|
*
|
||||||
|
* Sets the default message buffer size to the specified length in bytes.
|
||||||
|
* The default message buffer size limits the maximum message size the
|
||||||
|
* socket will be able to receive. It is generally recommneded to specify
|
||||||
|
* a buffer size no less than the size of a memory page.
|
||||||
|
*
|
||||||
|
* @return 0 on success or a negative error code.
|
||||||
|
*/
|
||||||
|
int nl_socket_set_msg_buf_size(struct nl_sock *sk, size_t bufsize)
|
||||||
|
{
|
||||||
|
sk->s_bufsize = bufsize;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get default message buffer size of netlink socket.
|
||||||
|
* @arg sk Netlink socket.
|
||||||
|
*
|
||||||
|
* @return Size of default message buffer.
|
||||||
|
*/
|
||||||
|
size_t nl_socket_get_msg_buf_size(struct nl_sock *sk)
|
||||||
|
{
|
||||||
|
return sk->s_bufsize;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable/disable credential passing on netlink socket.
|
* Enable/disable credential passing on netlink socket.
|
||||||
* @arg sk Netlink socket.
|
* @arg sk Netlink socket.
|
||||||
|
|
Reference in New Issue