"Be conservative in what you send, be liberal in what you accept"
When receiving packets, the real limitation of how much data we can accept
is the size of our internal buffers, not the maximum size we expect
incoming packets to have.
I ran into this while working on cipher negotiation, which will need
separate bookkeeping for the required internal buffer size, and the
link/tun MTU. Basing this code on the buffer size instead of c2->frame
makes that easier. A nice side-effect of this change is that it
simplifies the code.
This should also reduce the impact of using asymmetric tun/link MTU's,
such as in trac ticket #647.
Signed-off-by: Steffan Karger <steffan@karger.me>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <1465388443-15484-2-git-send-email-steffan@karger.me>
URL: http://article.gmane.org/gmane.network.openvpn.devel/11850
Signed-off-by: Gert Doering <gert@greenie.muc.de>
... | ... |
@@ -2886,7 +2886,6 @@ union openvpn_pktinfo { |
2886 | 2886 |
static socklen_t |
2887 | 2887 |
link_socket_read_udp_posix_recvmsg (struct link_socket *sock, |
2888 | 2888 |
struct buffer *buf, |
2889 |
- int maxsize, |
|
2890 | 2889 |
struct link_socket_actual *from) |
2891 | 2890 |
{ |
2892 | 2891 |
struct iovec iov; |
... | ... |
@@ -2895,7 +2894,7 @@ link_socket_read_udp_posix_recvmsg (struct link_socket *sock, |
2895 | 2895 |
socklen_t fromlen = sizeof (from->dest.addr); |
2896 | 2896 |
|
2897 | 2897 |
iov.iov_base = BPTR (buf); |
2898 |
- iov.iov_len = maxsize; |
|
2898 |
+ iov.iov_len = buf_forward_capacity_total (buf); |
|
2899 | 2899 |
mesg.msg_iov = &iov; |
2900 | 2900 |
mesg.msg_iovlen = 1; |
2901 | 2901 |
mesg.msg_name = &from->dest.addr; |
... | ... |
@@ -2954,20 +2953,18 @@ link_socket_read_udp_posix_recvmsg (struct link_socket *sock, |
2954 | 2954 |
int |
2955 | 2955 |
link_socket_read_udp_posix (struct link_socket *sock, |
2956 | 2956 |
struct buffer *buf, |
2957 |
- int maxsize, |
|
2958 | 2957 |
struct link_socket_actual *from) |
2959 | 2958 |
{ |
2960 | 2959 |
socklen_t fromlen = sizeof (from->dest.addr); |
2961 | 2960 |
socklen_t expectedlen = af_addr_size(sock->info.af); |
2962 | 2961 |
addr_zero_host(&from->dest); |
2963 |
- ASSERT (buf_safe (buf, maxsize)); |
|
2964 | 2962 |
#if ENABLE_IP_PKTINFO |
2965 | 2963 |
/* Both PROTO_UDPv4 and PROTO_UDPv6 */ |
2966 | 2964 |
if (sock->info.proto == PROTO_UDP && sock->sockflags & SF_USE_IP_PKTINFO) |
2967 |
- fromlen = link_socket_read_udp_posix_recvmsg (sock, buf, maxsize, from); |
|
2965 |
+ fromlen = link_socket_read_udp_posix_recvmsg (sock, buf, from); |
|
2968 | 2966 |
else |
2969 | 2967 |
#endif |
2970 |
- buf->len = recvfrom (sock->sd, BPTR (buf), maxsize, 0, |
|
2968 |
+ buf->len = recvfrom (sock->sd, BPTR (buf), buf_forward_capacity(buf), 0, |
|
2971 | 2969 |
&from->dest.addr.sa, &fromlen); |
2972 | 2970 |
/* FIXME: won't do anything when sock->info.af == AF_UNSPEC */ |
2973 | 2971 |
if (buf->len >= 0 && expectedlen && fromlen != expectedlen) |
... | ... |
@@ -961,7 +961,6 @@ link_socket_read_udp_win32 (struct link_socket *sock, |
961 | 961 |
|
962 | 962 |
int link_socket_read_udp_posix (struct link_socket *sock, |
963 | 963 |
struct buffer *buf, |
964 |
- int maxsize, |
|
965 | 964 |
struct link_socket_actual *from); |
966 | 965 |
|
967 | 966 |
#endif |
... | ... |
@@ -970,7 +969,6 @@ int link_socket_read_udp_posix (struct link_socket *sock, |
970 | 970 |
static inline int |
971 | 971 |
link_socket_read (struct link_socket *sock, |
972 | 972 |
struct buffer *buf, |
973 |
- int maxsize, |
|
974 | 973 |
struct link_socket_actual *from) |
975 | 974 |
{ |
976 | 975 |
if (proto_is_udp(sock->info.proto)) /* unified UDPv4 and UDPv6 */ |
... | ... |
@@ -980,7 +978,7 @@ link_socket_read (struct link_socket *sock, |
980 | 980 |
#ifdef WIN32 |
981 | 981 |
res = link_socket_read_udp_win32 (sock, buf, from); |
982 | 982 |
#else |
983 |
- res = link_socket_read_udp_posix (sock, buf, maxsize, from); |
|
983 |
+ res = link_socket_read_udp_posix (sock, buf, from); |
|
984 | 984 |
#endif |
985 | 985 |
return res; |
986 | 986 |
} |