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 * This file is part of ipif, part of userv-utils
18 * Copyright 1996-2013 Ian Jackson <ijackson@chiark.greenend.org.uk>
19 * Copyright 1998 David Damerell <damerell@chiark.greenend.org.uk>
21 * Chancellor Masters and Scholars of the University of Cambridge
22 * Copyright 2010 Tony Finch <fanf@dotat.at>
24 * This is free software; you can redistribute it and/or modify it
25 * under the terms of the GNU General Public License as published by
26 * the Free Software Foundation; either version 3 of the License, or
27 * (at your option) any later version.
29 * This program is distributed in the hope that it will be useful, but
30 * WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32 * General Public License for more details.
34 * You should have received a copy of the GNU General Public License
35 * along with userv-utils; if not, see http://www.gnu.org/licenses/.
39 #include <netinet/in.h>
41 #include "forwarder.h"
46 time_t max_skew, max_age;
50 static void mds_timestamp(struct mechdata **md_r) {
53 md= xmalloc(sizeof(md));
55 md->max_skew= getarg_ulong();
56 md->max_age= getarg_ulong();
61 static void mes_timestamp(struct mechdata **md_r, int *maxprefix_io, int *maxsuffix_io) {
66 static void menc_timestamp(struct mechdata *md, struct buffer *buf) {
67 *(uint32_t*)buf_prepend(buf,4)= htonl(now());
70 static const char *mdec_timestamp(struct mechdata *md, struct buffer *buf) {
73 uint32_t *tp, timestamp;
77 BUF_UNPREPEND(tp,buf,4);
78 timestamp= ntohl(*tp);
81 age= timestamp - (uint32_t)tnow;
83 if (!md->max_age || age <= md->max_age) return 0;
84 sprintf(cbuf,"packet too old (%lds)",age);
86 if (!md->max_skew || age >= -md->max_skew) return 0;
87 sprintf(cbuf,"too much skew (%lds)",-age);
92 if (tnow < md->next_warn) return "";
94 md->next_warn= tnow+WARN_EVERY;
98 STANDARD_MECHANISMLIST("timestamp",timestamp);