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 Ian Jackson
18 * This is free software; you can redistribute it and/or modify it
19 * under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful, but
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 * General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with userv-utils; if not, write to the Free Software
30 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #include <netinet/in.h>
36 #include "forwarder.h"
41 time_t max_skew, max_age;
45 static void mds_timestamp(struct mechdata **md_r) {
48 md= xmalloc(sizeof(md));
50 md->max_skew= getarg_ulong();
51 md->max_age= getarg_ulong();
56 static void mes_timestamp(struct mechdata **md_r, int *maxprefix_io, int *maxsuffix_io) {
61 static void menc_timestamp(struct mechdata *md, struct buffer *buf) {
62 *(uint32_t*)buf_prepend(buf,4)= htonl(now());
65 static const char *mdec_timestamp(struct mechdata *md, struct buffer *buf) {
68 uint32_t *tp, timestamp;
72 BUF_UNPREPEND(tp,buf,4);
73 timestamp= ntohl(*tp);
76 age= timestamp - (uint32_t)tnow;
78 if (!md->max_age || age <= md->max_age) return 0;
79 sprintf(cbuf,"packet too old (%lds)",age);
81 if (!md->max_skew || age >= -md->max_skew) return 0;
82 sprintf(cbuf,"too much skew (%lds)",-age);
87 if (tnow < md->next_warn) return "";
89 md->next_warn= tnow+WARN_EVERY;
93 STANDARD_MECHANISMLIST("timestamp",timestamp);