2 * Timestamp mechanism for udp tunnel
5 * arguments: <max-skew> <max-age>
8 * encoding: prepend 4 bytes of UNIX time in network byte order
10 * <max-age> is maximum age in seconds we will accept a packet (or 0
11 * for any age); <max-skew> is maximum future age in seconds we will
12 * accept a packet (or 0 for any future age).
16 * Copyright (C) 2000,2003 Ian Jackson
17 * This file is part of ipif, part of userv-utils
19 * This is free software; you can redistribute it and/or modify it
20 * under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
24 * This program is distributed in the hope that it will be useful, but
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with userv-utils; if not, write to the Free Software
31 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
35 #include <netinet/in.h>
37 #include "forwarder.h"
42 time_t max_skew, max_age;
46 static void mds_timestamp(struct mechdata **md_r) {
49 md= xmalloc(sizeof(md));
51 md->max_skew= getarg_ulong();
52 md->max_age= getarg_ulong();
57 static void mes_timestamp(struct mechdata **md_r, int *maxprefix_io, int *maxsuffix_io) {
62 static void menc_timestamp(struct mechdata *md, struct buffer *buf) {
63 *(uint32_t*)buf_prepend(buf,4)= htonl(now());
66 static const char *mdec_timestamp(struct mechdata *md, struct buffer *buf) {
69 uint32_t *tp, timestamp;
73 BUF_UNPREPEND(tp,buf,4);
74 timestamp= ntohl(*tp);
77 age= timestamp - (uint32_t)tnow;
79 if (!md->max_age || age <= md->max_age) return 0;
80 sprintf(cbuf,"packet too old (%lds)",age);
82 if (!md->max_skew || age >= -md->max_skew) return 0;
83 sprintf(cbuf,"too much skew (%lds)",-age);
88 if (tnow < md->next_warn) return "";
90 md->next_warn= tnow+WARN_EVERY;
94 STANDARD_MECHANISMLIST("timestamp",timestamp);