X-Git-Url: https://git.distorted.org.uk/~mdw/userv-utils/blobdiff_plain/f9e59051127e72847e1bee84ad52670e875f7d2f..f0e54a9987423f0f5939b961fa10ab4ca7a2c406:/ipif/mech-timestamp.c diff --git a/ipif/mech-timestamp.c b/ipif/mech-timestamp.c index e250c08..93d30e6 100644 --- a/ipif/mech-timestamp.c +++ b/ipif/mech-timestamp.c @@ -1,5 +1,5 @@ /* - * Timestamp mechanism + * Timestamp mechanism for udp tunnel * * arguments: * @@ -10,14 +10,34 @@ * accept a packet (or 0 for any future age). * */ +/* + * Copyright (C) 2000 Ian Jackson + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * 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 userv-utils; if not, write to the Free Software + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ #include #include #include "forwarder.h" +#define WARN_EVERY 30 + struct mechdata { - uint32_t max_skew, max_age; + time_t max_skew, max_age; + time_t next_warn; }; static void mds_timestamp(struct mechdata **md_r) { @@ -27,6 +47,7 @@ static void mds_timestamp(struct mechdata **md_r) { md->max_skew= getarg_ulong(); md->max_age= getarg_ulong(); + md->next_warn= now(); *md_r= md; } @@ -42,27 +63,27 @@ static void menc_timestamp(struct mechdata *md, struct buffer *buf) { static const char *mdec_timestamp(struct mechdata *md, struct buffer *buf) { static char cbuf[40]; - uint32_t *tp, timestamp, tnow; + uint32_t *tp, timestamp; + time_t tnow; long age; BUF_UNPREPEND(tp,buf,4); timestamp= ntohl(*tp); tnow= now(); - age= timestamp - tnow; + age= timestamp - (uint32_t)tnow; if (age > 0) { - if (md->max_age && age > md->max_age) { - sprintf(cbuf,"packet too old (%lds)",age); - return cbuf; - } + if (!md->max_age || age <= md->max_age) return 0; + sprintf(cbuf,"packet too old (%lds)",age); } else if (age < 0) { - if (md->max_skew && age > md->max_skew) { - sprintf(cbuf,"too much skew (%lds)",-age); - return cbuf; - } + if (!md->max_skew || age >= -md->max_skew) return 0; + sprintf(cbuf,"too much skew (%lds)",-age); } - return 0; + if (tnow < md->next_warn) return ""; + + md->next_warn= tnow+WARN_EVERY; + return cbuf; } STANDARD_MECHANISMLIST("timestamp",timestamp);