X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=userv-utils.git;a=blobdiff_plain;f=ipif%2Fmech-timestamp.c;h=793ea6c4aeae7a021b6b3da629dcc8b515743085;hp=e250c084d89f87fe26472618c7eae06afd2feffd;hb=44a77f4851d3c819f9b364018a9695f332758a71;hpb=f9e59051127e72847e1bee84ad52670e875f7d2f diff --git a/ipif/mech-timestamp.c b/ipif/mech-timestamp.c index e250c08..793ea6c 100644 --- a/ipif/mech-timestamp.c +++ b/ipif/mech-timestamp.c @@ -1,8 +1,10 @@ /* - * Timestamp mechanism + * Timestamp mechanism for udp tunnel * + * mechanism: timestamp * arguments: * + * restrictions: none * encoding: prepend 4 bytes of UNIX time in network byte order * * is maximum age in seconds we will accept a packet (or 0 @@ -10,14 +12,35 @@ * accept a packet (or 0 for any future age). * */ +/* + * Copyright (C) 2000,2003 Ian Jackson + * This file is part of ipif, part of userv-utils + * + * 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 +50,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 +66,29 @@ 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); + } else { + return 0; } - return 0; + if (tnow < md->next_warn) return ""; + + md->next_warn= tnow+WARN_EVERY; + return cbuf; } STANDARD_MECHANISMLIST("timestamp",timestamp);