~ubuntu-branches/ubuntu/trusty/conntrack/trusty-proposed

« back to all changes in this revision

Viewing changes to src/sync-alarm.c

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Wirt, Max Kellermann
  • Date: 2008-04-14 23:09:22 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080414230922-9xoi1gl38tc8lyng
Tags: 1:0.9.6-4
[ Max Kellermann ]
fix compilation on SPARC (printf argument mismatch)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * (C) 2006-2007 by Pablo Neira Ayuso <pablo@netfilter.org>
 
3
 * 
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; either version 2 of the License, or
 
7
 * (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
17
 */
 
18
 
 
19
#include "conntrackd.h"
 
20
#include "sync.h"
 
21
#include "network.h"
 
22
#include "us-conntrack.h"
 
23
#include "alarm.h"
 
24
#include "cache.h"
 
25
#include "debug.h"
 
26
 
 
27
#include <stdlib.h>
 
28
#include <string.h>
 
29
 
 
30
static void refresher(struct alarm_block *a, void *data)
 
31
{
 
32
        size_t len;
 
33
        struct nethdr *net;
 
34
        struct us_conntrack *u = data;
 
35
 
 
36
        debug_ct(u->ct, "persistence update");
 
37
 
 
38
        add_alarm(a, 
 
39
                  random() % CONFIG(refresh) + 1,
 
40
                  ((random() % 5 + 1)  * 200000) - 1);
 
41
 
 
42
        net = BUILD_NETMSG(u->ct, NFCT_Q_UPDATE);
 
43
        len = prepare_send_netmsg(STATE_SYNC(mcast_client), net);
 
44
        mcast_buffered_send_netmsg(STATE_SYNC(mcast_client), net, len);
 
45
}
 
46
 
 
47
static void cache_alarm_add(struct us_conntrack *u, void *data)
 
48
{
 
49
        struct alarm_block *alarm = data;
 
50
 
 
51
        init_alarm(alarm, u, refresher);
 
52
        add_alarm(alarm,
 
53
                  random() % CONFIG(refresh) + 1,
 
54
                  ((random() % 5 + 1)  * 200000) - 1);
 
55
}
 
56
 
 
57
static void cache_alarm_update(struct us_conntrack *u, void *data)
 
58
{
 
59
        struct alarm_block *alarm = data;
 
60
        add_alarm(alarm, 
 
61
                  random() % CONFIG(refresh) + 1,
 
62
                  ((random() % 5 + 1)  * 200000) - 1);
 
63
}
 
64
 
 
65
static void cache_alarm_destroy(struct us_conntrack *u, void *data)
 
66
{
 
67
        struct alarm_block *alarm = data;
 
68
        del_alarm(alarm);
 
69
}
 
70
 
 
71
static struct cache_extra cache_alarm_extra = {
 
72
        .size           = sizeof(struct alarm_block),
 
73
        .add            = cache_alarm_add,
 
74
        .update         = cache_alarm_update,
 
75
        .destroy        = cache_alarm_destroy
 
76
};
 
77
 
 
78
static int alarm_recv(const struct nethdr *net)
 
79
{
 
80
        unsigned int exp_seq;
 
81
 
 
82
        /* 
 
83
         * Ignore error messages: Although this message type is not ever
 
84
         * generated in alarm mode, we don't want to crash the daemon 
 
85
         * if someone nuts mixes ftfw and alarm.
 
86
         */
 
87
        if (net->flags)
 
88
                return 1;
 
89
 
 
90
        /* 
 
91
         * Multicast sequence tracking: we keep track of multicast messages
 
92
         * although we don't do any explicit message recovery. So, why do
 
93
         * we do sequence tracking? Just to let know the sysadmin.
 
94
         *
 
95
         * Let t be 1 < t < RefreshTime. To ensure consistency, conntrackd
 
96
         * retransmit every t seconds a message with the state of a certain
 
97
         * entry even if such entry did not change. This mechanism also
 
98
         * provides passive resynchronization, in other words, there is
 
99
         * no facility to request a full synchronization from new nodes that
 
100
         * just joined the cluster, instead they just get resynchronized in
 
101
         * RefreshTime seconds at worst case.
 
102
         */
 
103
        mcast_track_seq(net->seq, &exp_seq);
 
104
 
 
105
        return 0;
 
106
}
 
107
 
 
108
struct sync_mode sync_alarm = {
 
109
        .internal_cache_flags   = LIFETIME,
 
110
        .external_cache_flags   = TIMER | LIFETIME,
 
111
        .internal_cache_extra   = &cache_alarm_extra,
 
112
        .recv                   = alarm_recv,
 
113
};