From 9683f890944ffb114f5f8214f694e0b339cf5a5a Mon Sep 17 00:00:00 2001 From: Alberto Gonzalez Iniesta Date: Thu, 22 Jun 2017 13:16:46 +0200 Subject: New upstream version 2.4.3 --- src/openvpn/packet_id.c | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) (limited to 'src/openvpn/packet_id.c') diff --git a/src/openvpn/packet_id.c b/src/openvpn/packet_id.c index fe13e1d..30ae8fb 100644 --- a/src/openvpn/packet_id.c +++ b/src/openvpn/packet_id.c @@ -16,10 +16,9 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program (see the file COPYING included with this - * distribution); if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ /* @@ -325,12 +324,40 @@ packet_id_read(struct packet_id_net *pin, struct buffer *buf, bool long_form) return true; } +static bool +packet_id_send_update(struct packet_id_send *p, bool long_form) +{ + if (!p->time) + { + p->time = now; + } + if (p->id == PACKET_ID_MAX) + { + /* Packet ID only allowed to roll over if using long form and time has + * moved forward since last roll over. + */ + if (!long_form || now <= p->time) + { + return false; + } + p->time = now; + p->id = 0; + } + p->id++; + return true; +} + bool -packet_id_write(const struct packet_id_net *pin, struct buffer *buf, bool long_form, bool prepend) +packet_id_write(struct packet_id_send *p, struct buffer *buf, bool long_form, + bool prepend) { - packet_id_type net_id = htonpid(pin->id); - net_time_t net_time = htontime(pin->time); + if (!packet_id_send_update(p, long_form)) + { + return false; + } + const packet_id_type net_id = htonpid(p->id); + const net_time_t net_time = htontime(p->time); if (prepend) { if (long_form) @@ -629,7 +656,8 @@ packet_id_interactive_test() packet_id_init(&pid, seq_backtrack, time_backtrack); - while (true) { + while (true) + { char buf[80]; if (!fgets(buf, sizeof(buf), stdin)) { -- cgit v1.2.3