Skip to content

Commit

Permalink
[global] restrict max packet size to 65536 bytes
Browse files Browse the repository at this point in the history
and apply workaround in data buf allocation while we cleanup
the whole buffer allocation handling situation

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
  • Loading branch information
fabbione committed Sep 16, 2015
1 parent 501d0f8 commit 3781305
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
9 changes: 3 additions & 6 deletions libknet/handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -997,12 +997,9 @@ ssize_t knet_send(knet_handle_t knet_h, const char *buff, const size_t buff_len)
struct iovec iov_out[1];
int sock;

if (!knet_h) {
errno = EINVAL;
return -1;
}

if ((buff == NULL) || (buff_len == 0)) {
if ((!knet_h) ||
(buff == NULL) ||
(buff_len == 0) || (buff_len > KNET_MAX_PACKET_SIZE)) {
errno = EINVAL;
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion libknet/internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "libknet.h"
#include "onwire.h"

#define KNET_DATABUFSIZE KNET_MAX_PACKET_SIZE + KNET_HEADER_DATA_SIZE
#define KNET_DATABUFSIZE (KNET_MAX_PACKET_SIZE * 2) + KNET_HEADER_DATA_SIZE
#define KNET_DATABUFSIZE_CRYPT KNET_DATABUFSIZE * 2

struct knet_listener {
Expand Down
12 changes: 9 additions & 3 deletions libknet/libknet.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* see knet_handle_new for details
*/

#define KNET_MAX_PACKET_SIZE 131072
#define KNET_MAX_PACKET_SIZE 65536

/*
* buffers used for pretty logging
Expand Down Expand Up @@ -63,8 +63,14 @@ typedef struct knet_handle *knet_handle_t;
* knet will read data here to send to the other hosts
* and will write data received from the network.
* Each data packet can be of max size KNET_MAX_PACKET_SIZE!
* Applications might be able to write more data at a time
* but they will be delivered in KNET_MAX_PACKET_SIZE chunks.
* Applications using knet_send/knet_recv will receive
* proper error in case of packet size is not within boundaries.
* Applications using their own functions to write to the
* datafd should NOT write more than KNET_MAX_PACKET_SIZE
* or the packet will be fragmented by readv inside the
* delivery thread. Be aware that while you can write
* more than KNET_MAX_PACKET_SIZE, that can break any
* custom delivery filters (see below) due to data offset.
* Please refer to ping_test.c on how to setup socketpair.
* datafd can be 0, and knet_handle_new will create a properly
* populated socket pair the same way as ping_test, or a value
Expand Down
2 changes: 1 addition & 1 deletion libknet/ping_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ static void pmtud_notify(void *private_data, unsigned int link_mtu, unsigned int

int main(int argc, char *argv[])
{
char out_big_buff[64000], out_big_frag[66000], hello_world[16];
char out_big_buff[64000], out_big_frag[65536], hello_world[16];
char recvbuff[66000];
size_t len;
fd_set rfds;
Expand Down

0 comments on commit 3781305

Please sign in to comment.