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