summaryrefslogtreecommitdiff
path: root/src/openvpn/packet_id.h
diff options
context:
space:
mode:
authorBernhard Schmidt <berni@debian.org>2018-10-14 22:51:08 +0200
committerBernhard Schmidt <berni@debian.org>2018-10-14 22:51:08 +0200
commit87c2fd4310e5b345102d7a4915dc5e3a65052305 (patch)
treeb7dc3d6d209bdb926c9e1ece7f9639aa1724b39e /src/openvpn/packet_id.h
parent3804bc2606a92e2f2f4b3a2b043af0d77d92b386 (diff)
Revert "Merge branch 'stretch' of ssh://git.debian.org/git/collab-maint/openvpn into stretch"
This reverts commit 3804bc2606a92e2f2f4b3a2b043af0d77d92b386, reversing changes made to 678cfd249add7ca758e4c41933c7b730132c99f4.
Diffstat (limited to 'src/openvpn/packet_id.h')
-rw-r--r--src/openvpn/packet_id.h36
1 files changed, 23 insertions, 13 deletions
diff --git a/src/openvpn/packet_id.h b/src/openvpn/packet_id.h
index aceacf8..ecc25a6 100644
--- a/src/openvpn/packet_id.h
+++ b/src/openvpn/packet_id.h
@@ -50,7 +50,6 @@
* to for network transmission.
*/
typedef uint32_t packet_id_type;
-#define PACKET_ID_MAX UINT32_MAX
typedef uint32_t net_time_t;
/*
@@ -255,18 +254,7 @@ const char *packet_id_persist_print(const struct packet_id_persist *p, struct gc
bool packet_id_read(struct packet_id_net *pin, struct buffer *buf, bool long_form);
-/**
- * Write a packet ID to buf, and update the packet ID state.
- *
- * @param p Packet ID state.
- * @param buf Buffer to write the packet ID too
- * @param long_form If true, also update and write time_t to buf
- * @param prepend If true, prepend to buffer, otherwise apppend.
- *
- * @return true if successful, false otherwise.
- */
-bool packet_id_write(struct packet_id_send *p, struct buffer *buf,
- bool long_form, bool prepend);
+bool packet_id_write(const struct packet_id_net *pin, struct buffer *buf, bool long_form, bool prepend);
/*
* Inline functions.
@@ -316,6 +304,28 @@ packet_id_close_to_wrapping(const struct packet_id_send *p)
return p->id >= PACKET_ID_WRAP_TRIGGER;
}
+/*
+ * Allocate an outgoing packet id.
+ * Sequence number ranges from 1 to 2^32-1.
+ * In long_form, a time_t is added as well.
+ */
+static inline void
+packet_id_alloc_outgoing(struct packet_id_send *p, struct packet_id_net *pin, bool long_form)
+{
+ if (!p->time)
+ {
+ p->time = now;
+ }
+ pin->id = ++p->id;
+ if (!pin->id)
+ {
+ ASSERT(long_form);
+ p->time = now;
+ pin->id = p->id = 1;
+ }
+ pin->time = p->time;
+}
+
static inline bool
check_timestamp_delta(time_t remote, unsigned int max_delta)
{