Change in openvpn[master]: Add methods to read/write packet ids for epoch data
A message that is not in the archive (sent off-list or not yet received): gerrit.1731290343000.I2a104decdb1e77a460f7a6976bcd0560b67a07b5@...2715...
Attention is currently required from: flichtenheld.
Hello flichtenheld,
I'd like you to do a code review.
Please visit
http://gerrit.openvpn.net/c/openvpn/+/803?usp=email
to review the following change.
Change subject: Add methods to read/write packet ids for epoch data
......................................................................
Add methods to read/write packet ids for epoch data
---
M src/openvpn/packet_id.c
M src/openvpn/packet_id.h
M tests/unit_tests/openvpn/test_packet_id.c
3 files changed, 137 insertions(+), 2 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/03/803/1
src/openvpn/packet_id.c +57 -0
@@ -343,6 +343,21 @@return true; } +static bool +packet_id_send_update_epoch (struct packet_id_send *p) +{ +if (!p->time) + { + p->time = now; + } +if (p->id ==PACKET_ID_EPOCH_MAX ) + { +return false; + } + p->id++; +return true; +} +bool packet_id_write (struct packet_id_send *p,struct buffer *buf,bool long_form,bool prepend)
@@ -634,4 +649,46 @@gc_free (&gc); } +uint16_t +packet_id_read_epoch (struct packet_id_net *pin,struct buffer *buf) +{ +uint64_t packet_id; + + +if (!buf_read (buf, &packet_id,sizeof (packet_id))) + { +return 0 ; + } + +uint64_t id =ntohll (packet_id); +/* top most 16 bits */ +uint16_t epoch = id >>48 ; + + pin->id = id &0xffffffffffffull ; +return epoch; +} + +bool +packet_id_write_epoch (struct packet_id_send *p,uint16_t epoch,struct buffer *buf) +{ +if (!packet_id_send_update_epoch (p)) + { +return false; + } + +/* First 16 bits of packet id is the epoch +* +* Next 48 bits are the per-epoch packet id counter. Since we are +* writing a big endian counter, the last 6 bytes of the 64 bit +* integer contain our counter but the upper two bytes are always 0 */ + +uint64_t net_id = ((uint64_t ) epoch) <<48 | p->id; + +/* convert to network order */ + net_id =htonll (net_id); + +return buf_write (buf, &net_id,sizeof (net_id)); +} + +#endif /* ifdef ENABLE_DEBUG */
src/openvpn/packet_id.h +25 -2
@@ -44,7 +44,8 @@* These are ephemeral and are never saved to a file. */ typedef uint32_t packet_id_type ; -#define PACKET_ID_MAX UINT32_MAX +#define PACKET_ID_MAX UINT32_MAX +#define PACKET_ID_EPOCH_MAX 0x0000ffffffffffffulltypedef uint32_t net_time_t ;/*
@@ -158,7 +159,8 @@* includes a timestamp as well. * * An epoch packet-id is a 16 bit epoch -* counter plus a 48 per-epoch packet-id +* counter plus a 48 per-epoch packet-id. +* * * Long packet-ids are used as IVs for * CFB/OFB ciphers and for control channel
@@ -321,4 +323,25 @@ } } +/** +* Writes the packet ID containing both the epoch and the packet id to the +* buffer specified by buf. +* @param p packed id send structure to use for the packet id +* @param epoch epoch to write to the packet +* @param buf buffer to write the packet id/epcoh to +* @return false if the packet id space is exhausted and cannot be written +*/ +bool +packet_id_write_epoch (struct packet_id_send *p,uint16_t epoch,struct buffer *buf); + +/** +* Reads the packet ID containing both the epoch and the per-epoch counter +* from the buf. Will return 0 as epoch id if there is any error. +* @param p packet_id struct to popupulate with the on-wire counter +* @param buf buffer to read the packet id from. +* @return 0 for an error/invalid id, epoch otherwise +*/ +uint16_t +packet_id_read_epoch (struct packet_id_net *p,struct buffer *buf); +#endif /* PACKET_ID_H */
tests/unit_tests/openvpn/test_packet_id.c +55 -0
85 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/803?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I2a104decdb1e77a460f7a6976bcd0560b67a07b5
Gerrit-Change-Number: 803
Gerrit-PatchSet: 1
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newchange
Attention is currently required from: flichtenheld, plaisthos.
stipa has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/803?usp=email )
Change subject: Add methods to read/write packet ids for epoch data
......................................................................
Patch Set 5:
(1 comment)
File src/openvpn/packet_id.c:
http://gerrit.openvpn.net/c/openvpn/+/803/comment/72c0412e_6dab8a3e :
PS5, Line 667: pin->id = id & 0xffffffffffffull;
shouldn't we use PACKET_ID_EPOCH_MAX here?
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/803?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I2a104decdb1e77a460f7a6976bcd0560b67a07b5
Gerrit-Change-Number: 803
Gerrit-PatchSet: 5
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: stipa <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Mon, 25 Nov 2024 13:09:11 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, stipa.
plaisthos has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/803?usp=email )
Change subject: Add methods to read/write packet ids for epoch data
......................................................................
Patch Set 5:
(1 comment)
File src/openvpn/packet_id.c:
http://gerrit.openvpn.net/c/openvpn/+/803/comment/feb6ca8b_77e908f0 :
PS5, Line 667: pin->id = id & 0xffffffffffffull;
Quoted 1 line
shouldn't we use
PACKET_ID_EPOCH_MAXhere?
yes, will fix that. Technically it is a mask here but the mask is identical.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/803?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I2a104decdb1e77a460f7a6976bcd0560b67a07b5
Gerrit-Change-Number: 803
Gerrit-PatchSet: 5
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: stipa <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Sat, 30 Nov 2024 13:06:25 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: stipa <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, stipa.
Hello flichtenheld,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/803?usp=email
to look at the new patch set (#6).
Change subject: Add methods to read/write packet ids for epoch data
......................................................................
Add methods to read/write packet ids for epoch data
---
M src/openvpn/packet_id.c
M src/openvpn/packet_id.h
M tests/unit_tests/openvpn/test_packet_id.c
3 files changed, 141 insertions(+), 3 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/03/803/6
src/openvpn/packet_id.c +59 -1
@@ -120,7 +120,8 @@int64_t diff;/* -* If time value increases, start a new sequence number sequence. +* If time value increases, start a new sequence list of number +* sequence for the new time point. */ if (!CIRC_LIST_SIZE (p->seq_list) || pin->time > p->time
@@ -343,6 +344,21 @@return true; } +static bool +packet_id_send_update_epoch (struct packet_id_send *p) +{ +if (!p->time) + { + p->time = now; + } +if (p->id ==PACKET_ID_EPOCH_MAX ) + { +return false; + } + p->id++; +return true; +} +bool packet_id_write (struct packet_id_send *p,struct buffer *buf,bool long_form,bool prepend)
@@ -634,4 +650,46 @@gc_free (&gc); } +uint16_t +packet_id_read_epoch (struct packet_id_net *pin,struct buffer *buf) +{ +uint64_t packet_id; + + +if (!buf_read (buf, &packet_id,sizeof (packet_id))) + { +return 0 ; + } + +uint64_t id =ntohll (packet_id); +/* top most 16 bits */ +uint16_t epoch = id >>48 ; + + pin->id = id &PACKET_ID_MASK ; +return epoch; +} + +bool +packet_id_write_epoch (struct packet_id_send *p,uint16_t epoch,struct buffer *buf) +{ +if (!packet_id_send_update_epoch (p)) + { +return false; + } + +/* First 16 bits of packet id is the epoch +* +* Next 48 bits are the per-epoch packet id counter. Since we are +* writing a big endian counter, the last 6 bytes of the 64 bit +* integer contain our counter but the upper two bytes are always 0 */ + +uint64_t net_id = ((uint64_t ) epoch) <<48 | p->id; + +/* convert to network order */ + net_id =htonll (net_id); + +return buf_write (buf, &net_id,sizeof (net_id)); +} + +#endif /* ifdef ENABLE_DEBUG */
src/openvpn/packet_id.h +27 -2
@@ -44,7 +44,10 @@* These are ephemeral and are never saved to a file. */ typedef uint32_t packet_id_type ; -#define PACKET_ID_MAX UINT32_MAX +#define PACKET_ID_MAX UINT32_MAX +#define PACKET_ID_EPOCH_MAX 0x0000ffffffffffffull +/** Maks of the bits that make out the epoch in the packet counter */ +#define PACKET_ID_MASK 0x0000ffffffffffffulltypedef uint32_t net_time_t ;/*
@@ -158,7 +161,8 @@* includes a timestamp as well. * * An epoch packet-id is a 16 bit epoch -* counter plus a 48 per-epoch packet-id +* counter plus a 48 per-epoch packet-id. +* * * Long packet-ids are used as IVs for * CFB/OFB ciphers and for control channel
@@ -321,4 +325,25 @@ } } +/** +* Writes the packet ID containing both the epoch and the packet id to the +* buffer specified by buf. +* @param p packed id send structure to use for the packet id +* @param epoch epoch to write to the packet +* @param buf buffer to write the packet id/epcoh to +* @return false if the packet id space is exhausted and cannot be written +*/ +bool +packet_id_write_epoch (struct packet_id_send *p,uint16_t epoch,struct buffer *buf); + +/** +* Reads the packet ID containing both the epoch and the per-epoch counter +* from the buf. Will return 0 as epoch id if there is any error. +* @param p packet_id struct to popupulate with the on-wire counter +* @param buf buffer to read the packet id from. +* @return 0 for an error/invalid id, epoch otherwise +*/ +uint16_t +packet_id_read_epoch (struct packet_id_net *p,struct buffer *buf); +#endif /* PACKET_ID_H */
tests/unit_tests/openvpn/test_packet_id.c +55 -0
85 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/803?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I2a104decdb1e77a460f7a6976bcd0560b67a07b5
Gerrit-Change-Number: 803
Gerrit-PatchSet: 6
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: stipa <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: plaisthos, stipa.
flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/803?usp=email )
Change subject: Add methods to read/write packet ids for epoch data
......................................................................
Patch Set 8: Code-Review-1
(3 comments)
File src/openvpn/packet_id.h:
http://gerrit.openvpn.net/c/openvpn/+/803/comment/1049acea_ac1fd539 :
PS8, Line 49: /** Maks of the bits that make out the epoch in the packet counter */ "Maks" -> "Mask". "make out" -> "masks out"?
http://gerrit.openvpn.net/c/openvpn/+/803/comment/8ca67c36_92924ef3 :
PS8, Line 333: * @param buf buffer to write the packet id/epcoh to
"epoch"
File src/openvpn/packet_id.c:
http://gerrit.openvpn.net/c/openvpn/+/803/comment/7a433205_650c3d7a :
PS8, Line 684: * integer contain our counter but the upper two bytes are always 0 */
This is confusing. The point where we convert to network order the epoch is already joined, so the bytes aren't 0, are they?
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/803?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I2a104decdb1e77a460f7a6976bcd0560b67a07b5
Gerrit-Change-Number: 803
Gerrit-PatchSet: 8
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: stipa <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Fri, 27 Dec 2024 16:25:24 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, stipa.
plaisthos has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/803?usp=email )
Change subject: Add methods to read/write packet ids for epoch data
......................................................................
Patch Set 8:
(3 comments)
File src/openvpn/packet_id.h:
http://gerrit.openvpn.net/c/openvpn/+/803/comment/f34723d4_5781004e :
PS8, Line 49: /** Maks of the bits that make out the epoch in the packet counter */
Quoted 1 line
"Maks" -> "Mask". […]
Done
http://gerrit.openvpn.net/c/openvpn/+/803/comment/6fc94b17_3cb2fa5b :
PS8, Line 333: * @param buf buffer to write the packet id/epcoh to
Quoted 1 line
"epoch"
Done
File src/openvpn/packet_id.c:
http://gerrit.openvpn.net/c/openvpn/+/803/comment/3a7675bb_c3f00413 :
PS8, Line 684: * integer contain our counter but the upper two bytes are always 0 */
Quoted 1 line
This is confusing. […]
Done
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/803?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I2a104decdb1e77a460f7a6976bcd0560b67a07b5
Gerrit-Change-Number: 803
Gerrit-PatchSet: 8
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: stipa <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Fri, 27 Dec 2024 18:17:30 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, stipa.
Hello flichtenheld,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/803?usp=email
to look at the new patch set (#9).
The following approvals got outdated and were removed:
Code-Review-1 by flichtenheld
Change subject: Add methods to read/write packet ids for epoch data
......................................................................
Add methods to read/write packet ids for epoch data
---
M src/openvpn/packet_id.c
M src/openvpn/packet_id.h
M tests/unit_tests/openvpn/test_packet_id.c
3 files changed, 140 insertions(+), 3 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/03/803/9
src/openvpn/packet_id.c +57 -1
@@ -120,7 +120,8 @@int64_t diff;/* -* If time value increases, start a new sequence number sequence. +* If time value increases, start a new sequence list of number +* sequence for the new time point. */ if (!CIRC_LIST_SIZE (p->seq_list) || pin->time > p->time
@@ -343,6 +344,21 @@return true; } +static bool +packet_id_send_update_epoch (struct packet_id_send *p) +{ +if (!p->time) + { + p->time = now; + } +if (p->id ==PACKET_ID_EPOCH_MAX ) + { +return false; + } + p->id++; +return true; +} +bool packet_id_write (struct packet_id_send *p,struct buffer *buf,bool long_form,bool prepend)
@@ -634,4 +650,44 @@gc_free (&gc); } +uint16_t +packet_id_read_epoch (struct packet_id_net *pin,struct buffer *buf) +{ +uint64_t packet_id; + + +if (!buf_read (buf, &packet_id,sizeof (packet_id))) + { +return 0 ; + } + +uint64_t id =ntohll (packet_id); +/* top most 16 bits */ +uint16_t epoch = id >>48 ; + + pin->id = id &PACKET_ID_MASK ; +return epoch; +} + +bool +packet_id_write_epoch (struct packet_id_send *p,uint16_t epoch,struct buffer *buf) +{ +if (!packet_id_send_update_epoch (p)) + { +return false; + } + +/* Highest 16 bits of packet id is the epoch. +* +* The lower 48 bits are the per-epoch packet id counter. */ +uint64_t net_id = ((uint64_t ) epoch) <<48 | p->id; + +/* convert to network order. This ensures that the highest bytes +* also become the first ones on the wire*/ + net_id =htonll (net_id); + +return buf_write (buf, &net_id,sizeof (net_id)); +} + +#endif /* ifdef ENABLE_DEBUG */
src/openvpn/packet_id.h +28 -2
@@ -44,7 +44,11 @@* These are ephemeral and are never saved to a file. */ typedef uint32_t packet_id_type ; -#define PACKET_ID_MAX UINT32_MAX +#define PACKET_ID_MAX UINT32_MAX +#define PACKET_ID_EPOCH_MAX 0x0000ffffffffffffull +/** Mask of the bits that contain the 48-bit of the per-epoch packet +* counter in the packet id*/ +#define PACKET_ID_MASK 0x0000ffffffffffffulltypedef uint32_t net_time_t ;/*
@@ -158,7 +162,8 @@* includes a timestamp as well. * * An epoch packet-id is a 16 bit epoch -* counter plus a 48 per-epoch packet-id +* counter plus a 48 per-epoch packet-id. +* * * Long packet-ids are used as IVs for * CFB/OFB ciphers and for control channel
@@ -321,4 +326,25 @@ } } +/** +* Writes the packet ID containing both the epoch and the packet id to the +* buffer specified by buf. +* @param p packed id send structure to use for the packet id +* @param epoch epoch to write to the packet +* @param buf buffer to write the packet id/epoch to +* @return false if the packet id space is exhausted and cannot be written +*/ +bool +packet_id_write_epoch (struct packet_id_send *p,uint16_t epoch,struct buffer *buf); + +/** +* Reads the packet ID containing both the epoch and the per-epoch counter +* from the buf. Will return 0 as epoch id if there is any error. +* @param p packet_id struct to popupulate with the on-wire counter +* @param buf buffer to read the packet id from. +* @return 0 for an error/invalid id, epoch otherwise +*/ +uint16_t +packet_id_read_epoch (struct packet_id_net *p,struct buffer *buf); +#endif /* PACKET_ID_H */
tests/unit_tests/openvpn/test_packet_id.c +55 -0
85 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/803?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I2a104decdb1e77a460f7a6976bcd0560b67a07b5
Gerrit-Change-Number: 803
Gerrit-PatchSet: 9
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: stipa <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld, plaisthos, stipa.
MaxF has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/803?usp=email )
Change subject: Add methods to read/write packet ids for epoch data
......................................................................
Patch Set 8:
(5 comments)
Patchset:
PS8:
Nitpicks about comments, code looks good to me.
File src/openvpn/packet_id.h:
http://gerrit.openvpn.net/c/openvpn/+/803/comment/c836da37_30744229 :
PS8, Line 49: Maks
Mask
http://gerrit.openvpn.net/c/openvpn/+/803/comment/ecbf03a7_cb2058dd :
PS8, Line 331: packed
I'm thinking this is a typo. Or is it actually a packed struct?
http://gerrit.openvpn.net/c/openvpn/+/803/comment/8101af1b_44e6d50f :
PS8, Line 333: epcoh
epoch
File tests/unit_tests/openvpn/test_packet_id.c:
http://gerrit.openvpn.net/c/openvpn/+/803/comment/230d5a2f_40d775b3 :
PS8, Line 241: /* test writing/checking the 48 bit overflow */ I don't get it, what overflow?
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/803?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I2a104decdb1e77a460f7a6976bcd0560b67a07b5
Gerrit-Change-Number: 803
Gerrit-PatchSet: 8
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: MaxF <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: stipa <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Fri, 27 Dec 2024 18:32:47 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, plaisthos, stipa.
MaxF has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/803?usp=email )
Change subject: Add methods to read/write packet ids for epoch data
......................................................................
Patch Set 9:
(2 comments)
File src/openvpn/packet_id.h:
http://gerrit.openvpn.net/c/openvpn/+/803/comment/3292ddf7_01d6cdee :
PS8, Line 49: Maks
Quoted 1 line
Mask
Fixed while I had the tab open
http://gerrit.openvpn.net/c/openvpn/+/803/comment/6c8294d2_e55fc9fd :
PS8, Line 333: epcoh
Quoted 1 line
epoch
Fixed while I had the tab open
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/803?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I2a104decdb1e77a460f7a6976bcd0560b67a07b5
Gerrit-Change-Number: 803
Gerrit-PatchSet: 9
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: MaxF <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: stipa <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Fri, 27 Dec 2024 18:34:57 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: MaxF <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, plaisthos, stipa.
Hello flichtenheld,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/803?usp=email
to look at the new patch set (#10).
Change subject: Add methods to read/write packet ids for epoch data
......................................................................
Add methods to read/write packet ids for epoch data
---
M src/openvpn/packet_id.c
M src/openvpn/packet_id.h
M tests/unit_tests/openvpn/test_packet_id.c
3 files changed, 140 insertions(+), 3 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/03/803/10
src/openvpn/packet_id.c +57 -1
@@ -120,7 +120,8 @@int64_t diff;/* -* If time value increases, start a new sequence number sequence. +* If time value increases, start a new sequence list of number +* sequence for the new time point. */ if (!CIRC_LIST_SIZE (p->seq_list) || pin->time > p->time
@@ -343,6 +344,21 @@return true; } +static bool +packet_id_send_update_epoch (struct packet_id_send *p) +{ +if (!p->time) + { + p->time = now; + } +if (p->id ==PACKET_ID_EPOCH_MAX ) + { +return false; + } + p->id++; +return true; +} +bool packet_id_write (struct packet_id_send *p,struct buffer *buf,bool long_form,bool prepend)
@@ -634,4 +650,44 @@gc_free (&gc); } +uint16_t +packet_id_read_epoch (struct packet_id_net *pin,struct buffer *buf) +{ +uint64_t packet_id; + + +if (!buf_read (buf, &packet_id,sizeof (packet_id))) + { +return 0 ; + } + +uint64_t id =ntohll (packet_id); +/* top most 16 bits */ +uint16_t epoch = id >>48 ; + + pin->id = id &PACKET_ID_MASK ; +return epoch; +} + +bool +packet_id_write_epoch (struct packet_id_send *p,uint16_t epoch,struct buffer *buf) +{ +if (!packet_id_send_update_epoch (p)) + { +return false; + } + +/* Highest 16 bits of packet id is the epoch. +* +* The lower 48 bits are the per-epoch packet id counter. */ +uint64_t net_id = ((uint64_t ) epoch) <<48 | p->id; + +/* convert to network order. This ensures that the highest bytes +* also become the first ones on the wire*/ + net_id =htonll (net_id); + +return buf_write (buf, &net_id,sizeof (net_id)); +} + +#endif /* ifdef ENABLE_DEBUG */
src/openvpn/packet_id.h +28 -2
@@ -44,7 +44,11 @@* These are ephemeral and are never saved to a file. */ typedef uint32_t packet_id_type ; -#define PACKET_ID_MAX UINT32_MAX +#define PACKET_ID_MAX UINT32_MAX +#define PACKET_ID_EPOCH_MAX 0x0000ffffffffffffull +/** Mask of the bits that contain the 48-bit of the per-epoch packet +* counter in the packet id*/ +#define PACKET_ID_MASK 0x0000ffffffffffffulltypedef uint32_t net_time_t ;/*
@@ -158,7 +162,8 @@* includes a timestamp as well. * * An epoch packet-id is a 16 bit epoch -* counter plus a 48 per-epoch packet-id +* counter plus a 48 per-epoch packet-id. +* * * Long packet-ids are used as IVs for * CFB/OFB ciphers and for control channel
@@ -321,4 +326,25 @@ } } +/** +* Writes the packet ID containing both the epoch and the packet id to the +* buffer specified by buf. +* @param p packed id send structure to use for the packet id +* @param epoch epoch to write to the packet +* @param buf buffer to write the packet id/epoch to +* @return false if the packet id space is exhausted and cannot be written +*/ +bool +packet_id_write_epoch (struct packet_id_send *p,uint16_t epoch,struct buffer *buf); + +/** +* Reads the packet ID containing both the epoch and the per-epoch counter +* from the buf. Will return 0 as epoch id if there is any error. +* @param p packet_id struct to popupulate with the on-wire counter +* @param buf buffer to read the packet id from. +* @return 0 for an error/invalid id, epoch otherwise +*/ +uint16_t +packet_id_read_epoch (struct packet_id_net *p,struct buffer *buf); +#endif /* PACKET_ID_H */
tests/unit_tests/openvpn/test_packet_id.c +55 -0
85 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/803?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I2a104decdb1e77a460f7a6976bcd0560b67a07b5
Gerrit-Change-Number: 803
Gerrit-PatchSet: 10
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: MaxF <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: stipa <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: MaxF, flichtenheld, stipa.
plaisthos has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/803?usp=email )
Change subject: Add methods to read/write packet ids for epoch data
......................................................................
Patch Set 10:
(2 comments)
File src/openvpn/packet_id.h:
http://gerrit.openvpn.net/c/openvpn/+/803/comment/d417abd6_3a14c47d :
PS8, Line 331: packed
Quoted 1 line
I'm thinking this is a typo. […]
typo. Will fix.
File tests/unit_tests/openvpn/test_packet_id.c:
http://gerrit.openvpn.net/c/openvpn/+/803/comment/9930dda9_9f758def :
PS8, Line 241: /* test writing/checking the 48 bit overflow */
Quoted 1 line
I don't get it, what overflow?
Epoch packet counter is max 48 bit. This is 2**48-1. Will extend the comment.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/803?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I2a104decdb1e77a460f7a6976bcd0560b67a07b5
Gerrit-Change-Number: 803
Gerrit-PatchSet: 10
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: MaxF <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: stipa <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Attention: MaxF <[email protected]...>
Gerrit-Comment-Date: Sat, 04 Jan 2025 22:49:22 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: MaxF <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: MaxF, flichtenheld, stipa.
Hello flichtenheld,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/803?usp=email
to look at the new patch set (#12).
Change subject: Add methods to read/write packet ids for epoch data
......................................................................
Add methods to read/write packet ids for epoch data
---
M src/openvpn/packet_id.c
M src/openvpn/packet_id.h
M tests/unit_tests/openvpn/test_packet_id.c
3 files changed, 141 insertions(+), 3 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/03/803/12
src/openvpn/packet_id.c +57 -1
@@ -120,7 +120,8 @@int64_t diff;/* -* If time value increases, start a new sequence number sequence. +* If time value increases, start a new sequence list of number +* sequence for the new time point. */ if (!CIRC_LIST_SIZE (p->seq_list) || pin->time > p->time
@@ -343,6 +344,21 @@return true; } +static bool +packet_id_send_update_epoch (struct packet_id_send *p) +{ +if (!p->time) + { + p->time = now; + } +if (p->id ==PACKET_ID_EPOCH_MAX ) + { +return false; + } + p->id++; +return true; +} +bool packet_id_write (struct packet_id_send *p,struct buffer *buf,bool long_form,bool prepend)
@@ -634,4 +650,44 @@gc_free (&gc); } +uint16_t +packet_id_read_epoch (struct packet_id_net *pin,struct buffer *buf) +{ +uint64_t packet_id; + + +if (!buf_read (buf, &packet_id,sizeof (packet_id))) + { +return 0 ; + } + +uint64_t id =ntohll (packet_id); +/* top most 16 bits */ +uint16_t epoch = id >>48 ; + + pin->id = id &PACKET_ID_MASK ; +return epoch; +} + +bool +packet_id_write_epoch (struct packet_id_send *p,uint16_t epoch,struct buffer *buf) +{ +if (!packet_id_send_update_epoch (p)) + { +return false; + } + +/* Highest 16 bits of packet id is the epoch. +* +* The lower 48 bits are the per-epoch packet id counter. */ +uint64_t net_id = ((uint64_t ) epoch) <<48 | p->id; + +/* convert to network order. This ensures that the highest bytes +* also become the first ones on the wire*/ + net_id =htonll (net_id); + +return buf_write (buf, &net_id,sizeof (net_id)); +} + +#endif /* ifdef ENABLE_DEBUG */
src/openvpn/packet_id.h +28 -2
@@ -44,7 +44,11 @@* These are ephemeral and are never saved to a file. */ typedef uint32_t packet_id_type ; -#define PACKET_ID_MAX UINT32_MAX +#define PACKET_ID_MAX UINT32_MAX +#define PACKET_ID_EPOCH_MAX 0x0000ffffffffffffull +/** Mask of the bits that contain the 48-bit of the per-epoch packet +* counter in the packet id*/ +#define PACKET_ID_MASK 0x0000ffffffffffffulltypedef uint32_t net_time_t ;/*
@@ -158,7 +162,8 @@* includes a timestamp as well. * * An epoch packet-id is a 16 bit epoch -* counter plus a 48 per-epoch packet-id +* counter plus a 48 per-epoch packet-id. +* * * Long packet-ids are used as IVs for * CFB/OFB ciphers and for control channel
@@ -321,4 +326,25 @@ } } +/** +* Writes the packet ID containing both the epoch and the packet id to the +* buffer specified by buf. +* @param p packet id send structure to use for the packet id +* @param epoch epoch to write to the packet +* @param buf buffer to write the packet id/epoch to +* @return false if the packet id space is exhausted and cannot be written +*/ +bool +packet_id_write_epoch (struct packet_id_send *p,uint16_t epoch,struct buffer *buf); + +/** +* Reads the packet ID containing both the epoch and the per-epoch counter +* from the buf. Will return 0 as epoch id if there is any error. +* @param p packet_id struct to populate with the on-wire counter +* @param buf buffer to read the packet id from. +* @return 0 for an error/invalid id, epoch otherwise +*/ +uint16_t +packet_id_read_epoch (struct packet_id_net *p,struct buffer *buf); +#endif /* PACKET_ID_H */
tests/unit_tests/openvpn/test_packet_id.c +56 -0
86 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/803?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I2a104decdb1e77a460f7a6976bcd0560b67a07b5
Gerrit-Change-Number: 803
Gerrit-PatchSet: 12
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: MaxF <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: stipa <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Attention: MaxF <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: flichtenheld, plaisthos, stipa.
MaxF has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/803?usp=email )
Change subject: Add methods to read/write packet ids for epoch data
......................................................................
Patch Set 12: Code-Review+2
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/803?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I2a104decdb1e77a460f7a6976bcd0560b67a07b5
Gerrit-Change-Number: 803
Gerrit-PatchSet: 12
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: stipa <[email protected]...>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Thu, 09 Jan 2025 17:53:41 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
PATCH v12 1/1 Add methods to read/write packet ids for epoch data
In reply to a message not in the archiveFrom: Arne Schwabe <[email protected]...>
---
This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/803
This mail reflects revision 12 of this Change.
Acked-by according to Gerrit (reflected above):
MaxF <[email protected]...>
src/openvpn/packet_id.c +57 -1
@@ -120,7 +120,8 @@int64_t diff;/* -* If time value increases, start a new sequence number sequence. +* If time value increases, start a new sequence list of number +* sequence for the new time point. */ if (!CIRC_LIST_SIZE (p->seq_list) || pin->time > p->time
@@ -343,6 +344,21 @@return true; } +static bool +packet_id_send_update_epoch (struct packet_id_send *p) +{ +if (!p->time) + { + p->time = now; + } +if (p->id ==PACKET_ID_EPOCH_MAX ) + { +return false; + } + p->id++; +return true; +} +bool packet_id_write (struct packet_id_send *p,struct buffer *buf,bool long_form,bool prepend)
@@ -634,4 +650,44 @@gc_free (&gc); } +uint16_t +packet_id_read_epoch (struct packet_id_net *pin,struct buffer *buf) +{ +uint64_t packet_id; + + +if (!buf_read (buf, &packet_id,sizeof (packet_id))) + { +return 0 ; + } + +uint64_t id =ntohll (packet_id); +/* top most 16 bits */ +uint16_t epoch = id >>48 ; + + pin->id = id &PACKET_ID_MASK ; +return epoch; +} + +bool +packet_id_write_epoch (struct packet_id_send *p,uint16_t epoch,struct buffer *buf) +{ +if (!packet_id_send_update_epoch (p)) + { +return false; + } + +/* Highest 16 bits of packet id is the epoch. +* +* The lower 48 bits are the per-epoch packet id counter. */ +uint64_t net_id = ((uint64_t ) epoch) <<48 | p->id; + +/* convert to network order. This ensures that the highest bytes +* also become the first ones on the wire*/ + net_id =htonll (net_id); + +return buf_write (buf, &net_id,sizeof (net_id)); +} + +#endif /* ifdef ENABLE_DEBUG */
src/openvpn/packet_id.h +28 -2
@@ -44,7 +44,11 @@* These are ephemeral and are never saved to a file. */ typedef uint32_t packet_id_type ; -#define PACKET_ID_MAX UINT32_MAX +#define PACKET_ID_MAX UINT32_MAX +#define PACKET_ID_EPOCH_MAX 0x0000ffffffffffffull +/** Mask of the bits that contain the 48-bit of the per-epoch packet +* counter in the packet id*/ +#define PACKET_ID_MASK 0x0000ffffffffffffulltypedef uint32_t net_time_t ;/*
@@ -158,7 +162,8 @@* includes a timestamp as well. * * An epoch packet-id is a 16 bit epoch -* counter plus a 48 per-epoch packet-id +* counter plus a 48 per-epoch packet-id. +* * * Long packet-ids are used as IVs for * CFB/OFB ciphers and for control channel
@@ -321,4 +326,25 @@ } } +/** +* Writes the packet ID containing both the epoch and the packet id to the +* buffer specified by buf. +* @param p packet id send structure to use for the packet id +* @param epoch epoch to write to the packet +* @param buf buffer to write the packet id/epoch to +* @return false if the packet id space is exhausted and cannot be written +*/ +bool +packet_id_write_epoch (struct packet_id_send *p,uint16_t epoch,struct buffer *buf); + +/** +* Reads the packet ID containing both the epoch and the per-epoch counter +* from the buf. Will return 0 as epoch id if there is any error. +* @param p packet_id struct to populate with the on-wire counter +* @param buf buffer to read the packet id from. +* @return 0 for an error/invalid id, epoch otherwise +*/ +uint16_t +packet_id_read_epoch (struct packet_id_net *p,struct buffer *buf); +#endif /* PACKET_ID_H */
tests/unit_tests/openvpn/test_packet_id.c +56 -0
86 lines not on this page · raw message
[Openvpn-devel] [PATCH applied] Re: Add methods to read/write packet ids for epoch data
This basically does not really add "system testable" code yet - but it does add unit tests (which pass), the code looks reasonable, and it comes with a +2 from MaxF in Gerrit.
A comment explaining what packet_id_send_update_epoch() is about would be nice, though...
Your patch has been applied to the master branch.
commit bc62a9a02cb7365a678bcd3f2faf537a420cc5a0
Author: Arne Schwabe Date: Thu Jan 9 18:55:28 2025 +0100
Add methods to read/write packet ids for epoch data
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: MaxF <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg30389.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
cron2 has uploaded a new patch set (#13) to the change originally created by plaisthos. ( http://gerrit.openvpn.net/c/openvpn/+/803?usp=email )
The following approvals got outdated and were removed:
Code-Review+2 by MaxF
Change subject: Add methods to read/write packet ids for epoch data
......................................................................
Add methods to read/write packet ids for epoch data
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg30389.html
---
M src/openvpn/packet_id.c
M src/openvpn/packet_id.h
M tests/unit_tests/openvpn/test_packet_id.c
3 files changed, 141 insertions(+), 3 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/03/803/13
src/openvpn/packet_id.c +57 -1
@@ -120,7 +120,8 @@int64_t diff;/* -* If time value increases, start a new sequence number sequence. +* If time value increases, start a new sequence list of number +* sequence for the new time point. */ if (!CIRC_LIST_SIZE (p->seq_list) || pin->time > p->time
@@ -343,6 +344,21 @@return true; } +static bool +packet_id_send_update_epoch (struct packet_id_send *p) +{ +if (!p->time) + { + p->time = now; + } +if (p->id ==PACKET_ID_EPOCH_MAX ) + { +return false; + } + p->id++; +return true; +} +bool packet_id_write (struct packet_id_send *p,struct buffer *buf,bool long_form,bool prepend)
@@ -634,4 +650,44 @@gc_free (&gc); } +uint16_t +packet_id_read_epoch (struct packet_id_net *pin,struct buffer *buf) +{ +uint64_t packet_id; + + +if (!buf_read (buf, &packet_id,sizeof (packet_id))) + { +return 0 ; + } + +uint64_t id =ntohll (packet_id); +/* top most 16 bits */ +uint16_t epoch = id >>48 ; + + pin->id = id &PACKET_ID_MASK ; +return epoch; +} + +bool +packet_id_write_epoch (struct packet_id_send *p,uint16_t epoch,struct buffer *buf) +{ +if (!packet_id_send_update_epoch (p)) + { +return false; + } + +/* Highest 16 bits of packet id is the epoch. +* +* The lower 48 bits are the per-epoch packet id counter. */ +uint64_t net_id = ((uint64_t ) epoch) <<48 | p->id; + +/* convert to network order. This ensures that the highest bytes +* also become the first ones on the wire*/ + net_id =htonll (net_id); + +return buf_write (buf, &net_id,sizeof (net_id)); +} + +#endif /* ifdef ENABLE_DEBUG */
src/openvpn/packet_id.h +28 -2
@@ -44,7 +44,11 @@* These are ephemeral and are never saved to a file. */ typedef uint32_t packet_id_type ; -#define PACKET_ID_MAX UINT32_MAX +#define PACKET_ID_MAX UINT32_MAX +#define PACKET_ID_EPOCH_MAX 0x0000ffffffffffffull +/** Mask of the bits that contain the 48-bit of the per-epoch packet +* counter in the packet id*/ +#define PACKET_ID_MASK 0x0000ffffffffffffulltypedef uint32_t net_time_t ;/*
@@ -158,7 +162,8 @@* includes a timestamp as well. * * An epoch packet-id is a 16 bit epoch -* counter plus a 48 per-epoch packet-id +* counter plus a 48 per-epoch packet-id. +* * * Long packet-ids are used as IVs for * CFB/OFB ciphers and for control channel
@@ -321,4 +326,25 @@ } } +/** +* Writes the packet ID containing both the epoch and the packet id to the +* buffer specified by buf. +* @param p packet id send structure to use for the packet id +* @param epoch epoch to write to the packet +* @param buf buffer to write the packet id/epoch to +* @return false if the packet id space is exhausted and cannot be written +*/ +bool +packet_id_write_epoch (struct packet_id_send *p,uint16_t epoch,struct buffer *buf); + +/** +* Reads the packet ID containing both the epoch and the per-epoch counter +* from the buf. Will return 0 as epoch id if there is any error. +* @param p packet_id struct to populate with the on-wire counter +* @param buf buffer to read the packet id from. +* @return 0 for an error/invalid id, epoch otherwise +*/ +uint16_t +packet_id_read_epoch (struct packet_id_net *p,struct buffer *buf); +#endif /* PACKET_ID_H */
tests/unit_tests/openvpn/test_packet_id.c +56 -0
86 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/803?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I2a104decdb1e77a460f7a6976bcd0560b67a07b5
Gerrit-Change-Number: 803
Gerrit-PatchSet: 13
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: stipa <[email protected]...>
Gerrit-MessageType: newpatchset
cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/803?usp=email )
Change subject: Add methods to read/write packet ids for epoch data
......................................................................
Add methods to read/write packet ids for epoch data
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg30389.html
---
M src/openvpn/packet_id.c
M src/openvpn/packet_id.h
M tests/unit_tests/openvpn/test_packet_id.c
3 files changed, 141 insertions(+), 3 deletions(-)
src/openvpn/packet_id.c +57 -1
@@ -120,7 +120,8 @@int64_t diff;/* -* If time value increases, start a new sequence number sequence. +* If time value increases, start a new sequence list of number +* sequence for the new time point. */ if (!CIRC_LIST_SIZE (p->seq_list) || pin->time > p->time
@@ -343,6 +344,21 @@return true; } +static bool +packet_id_send_update_epoch (struct packet_id_send *p) +{ +if (!p->time) + { + p->time = now; + } +if (p->id ==PACKET_ID_EPOCH_MAX ) + { +return false; + } + p->id++; +return true; +} +bool packet_id_write (struct packet_id_send *p,struct buffer *buf,bool long_form,bool prepend)
@@ -634,4 +650,44 @@gc_free (&gc); } +uint16_t +packet_id_read_epoch (struct packet_id_net *pin,struct buffer *buf) +{ +uint64_t packet_id; + + +if (!buf_read (buf, &packet_id,sizeof (packet_id))) + { +return 0 ; + } + +uint64_t id =ntohll (packet_id); +/* top most 16 bits */ +uint16_t epoch = id >>48 ; + + pin->id = id &PACKET_ID_MASK ; +return epoch; +} + +bool +packet_id_write_epoch (struct packet_id_send *p,uint16_t epoch,struct buffer *buf) +{ +if (!packet_id_send_update_epoch (p)) + { +return false; + } + +/* Highest 16 bits of packet id is the epoch. +* +* The lower 48 bits are the per-epoch packet id counter. */ +uint64_t net_id = ((uint64_t ) epoch) <<48 | p->id; + +/* convert to network order. This ensures that the highest bytes +* also become the first ones on the wire*/ + net_id =htonll (net_id); + +return buf_write (buf, &net_id,sizeof (net_id)); +} + +#endif /* ifdef ENABLE_DEBUG */
src/openvpn/packet_id.h +28 -2
@@ -44,7 +44,11 @@* These are ephemeral and are never saved to a file. */ typedef uint32_t packet_id_type ; -#define PACKET_ID_MAX UINT32_MAX +#define PACKET_ID_MAX UINT32_MAX +#define PACKET_ID_EPOCH_MAX 0x0000ffffffffffffull +/** Mask of the bits that contain the 48-bit of the per-epoch packet +* counter in the packet id*/ +#define PACKET_ID_MASK 0x0000ffffffffffffulltypedef uint32_t net_time_t ;/*
@@ -158,7 +162,8 @@* includes a timestamp as well. * * An epoch packet-id is a 16 bit epoch -* counter plus a 48 per-epoch packet-id +* counter plus a 48 per-epoch packet-id. +* * * Long packet-ids are used as IVs for * CFB/OFB ciphers and for control channel
@@ -321,4 +326,25 @@ } } +/** +* Writes the packet ID containing both the epoch and the packet id to the +* buffer specified by buf. +* @param p packet id send structure to use for the packet id +* @param epoch epoch to write to the packet +* @param buf buffer to write the packet id/epoch to +* @return false if the packet id space is exhausted and cannot be written +*/ +bool +packet_id_write_epoch (struct packet_id_send *p,uint16_t epoch,struct buffer *buf); + +/** +* Reads the packet ID containing both the epoch and the per-epoch counter +* from the buf. Will return 0 as epoch id if there is any error. +* @param p packet_id struct to populate with the on-wire counter +* @param buf buffer to read the packet id from. +* @return 0 for an error/invalid id, epoch otherwise +*/ +uint16_t +packet_id_read_epoch (struct packet_id_net *p,struct buffer *buf); +#endif /* PACKET_ID_H */
tests/unit_tests/openvpn/test_packet_id.c +56 -0
86 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/803?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I2a104decdb1e77a460f7a6976bcd0560b67a07b5
Gerrit-Change-Number: 803
Gerrit-PatchSet: 13
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-CC: stipa <[email protected]...>
Gerrit-MessageType: merged