summaryrefslogtreecommitdiffstats
path: root/proto.c
diff options
context:
space:
mode:
authorjames <james@e7ae566f-a301-0410-adde-c780ea21d3b5>2005-09-26 07:40:02 +0000
committerjames <james@e7ae566f-a301-0410-adde-c780ea21d3b5>2005-09-26 07:40:02 +0000
commit3c7f2f553be4b3ba9412c1b3f64a258c469d78f4 (patch)
tree9d58836b0f1eade372de7ce15c41d6555d55ef21 /proto.c
parent6fbf66fad3367b24fd6743bcd50254902fd9c8d5 (diff)
downloadopenvpn-3c7f2f553be4b3ba9412c1b3f64a258c469d78f4.tar.gz
openvpn-3c7f2f553be4b3ba9412c1b3f64a258c469d78f4.tar.xz
openvpn-3c7f2f553be4b3ba9412c1b3f64a258c469d78f4.zip
version 2.1_beta1
git-svn-id: http://svn.openvpn.net/projects/openvpn/branches/BETA21/openvpn@581 e7ae566f-a301-0410-adde-c780ea21d3b5
Diffstat (limited to 'proto.c')
-rw-r--r--proto.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/proto.c b/proto.c
index df5b77b..4e8a309 100644
--- a/proto.c
+++ b/proto.c
@@ -31,6 +31,7 @@
#include "syshead.h"
#include "proto.h"
+#include "error.h"
#include "memdbg.h"
@@ -72,3 +73,56 @@ is_ipv4 (int tunnel_type, struct buffer *buf)
else
return false;
}
+
+#ifdef PACKET_TRUNCATION_CHECK
+
+void
+ipv4_packet_size_verify (const uint8_t *data,
+ const int size,
+ const int tunnel_type,
+ const char *prefix,
+ counter_type *errors)
+{
+ if (size > 0)
+ {
+ struct buffer buf;
+
+ buf_set_read (&buf, data, size);
+
+ if (is_ipv4 (tunnel_type, &buf))
+ {
+ const struct openvpn_iphdr *pip;
+ int hlen;
+ int totlen;
+ const char *msgstr = "PACKET SIZE INFO";
+ unsigned int msglevel = D_PACKET_TRUNC_DEBUG;
+
+ if (BLEN (&buf) < (int) sizeof (struct openvpn_iphdr))
+ return;
+
+ verify_align_4 (&buf);
+ pip = (struct openvpn_iphdr *) BPTR (&buf);
+
+ hlen = OPENVPN_IPH_GET_LEN (pip->version_len);
+ totlen = ntohs (pip->tot_len);
+
+ if (BLEN (&buf) != totlen)
+ {
+ msgstr = "PACKET TRUNCATION ERROR";
+ msglevel = D_PACKET_TRUNC_ERR;
+ if (errors)
+ ++(*errors);
+ }
+
+ msg (msglevel, "%s %s: size=%d totlen=%d hlen=%d errcount=" counter_format,
+ msgstr,
+ prefix,
+ BLEN (&buf),
+ totlen,
+ hlen,
+ errors ? *errors : (counter_type)0);
+ }
+ }
+}
+
+#endif