~ubuntu-branches/ubuntu/vivid/keepalived/vivid

« back to all changes in this revision

Viewing changes to keepalived/vrrp/vrrp_track.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2009-05-12 20:26:15 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20090512202615-k850bw35qpuvpq4p
Tags: 1.1.17-1ubuntu1
* Merge from debian unstable, remaining changes:
  - debian/rules: DEB_UPDATE_RCD_PARAMS := expicit init start/stop
    parameters (don't stop at 0 and 6)
  - debian/init.d: init script header adapted to stop rule
  - debian/keepalived.postinst: Remove shutdown and reboot links

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *
6
6
 * Part:        Interface tracking framework.
7
7
 *
8
 
 * Version:     $Id: vrrp_track.c,v 1.1.15 2007/09/15 04:07:41 acassen Exp $
 
8
 * Version:     $Id: vrrp_track.c,v 1.1.17 2009/03/05 01:31:12 acassen Exp $
9
9
 *
10
10
 * Author:      Alexandre Cassen, <acassen@linux-vs.org>
11
11
 *
19
19
 *              as published by the Free Software Foundation; either version
20
20
 *              2 of the License, or (at your option) any later version.
21
21
 *
22
 
 * Copyright (C) 2001-2007 Alexandre Cassen, <acassen@freebox.fr>
 
22
 * Copyright (C) 2001-2009 Alexandre Cassen, <acassen@freebox.fr>
23
23
 */
24
24
 
25
25
/* local include */
26
26
#include "vrrp_track.h"
27
27
#include "vrrp_if.h"
28
28
#include "vrrp_data.h"
 
29
#include "logger.h"
29
30
#include "memory.h"
30
31
 
31
32
/* Track interface dump */
33
34
dump_track(void *track_data_obj)
34
35
{
35
36
        tracked_if *tip = track_data_obj;
36
 
        syslog(LOG_INFO, "     %s weight %d", IF_NAME(tip->ifp), tip->weight);
 
37
        log_message(LOG_INFO, "     %s weight %d", IF_NAME(tip->ifp), tip->weight);
37
38
}
38
39
void
39
40
alloc_track(list track_list, vector strvec)
47
48
 
48
49
        /* Ignoring if no interface found */
49
50
        if (!ifp) {
50
 
                syslog(LOG_INFO, "     %s no match, ignoring...", tracked);
 
51
                log_message(LOG_INFO, "     %s no match, ignoring...", tracked);
51
52
                return;
52
53
        }
53
54
 
55
56
            !strcmp(VECTOR_SLOT(strvec, 1), "weight")) {
56
57
                weight = atoi(VECTOR_SLOT(strvec, 2));
57
58
                if (weight < -254 || weight > 254) {
58
 
                        syslog(LOG_INFO, "     %s: weight must be between "
 
59
                        log_message(LOG_INFO, "     %s: weight must be between "
59
60
                                         "[-254..254] inclusive. Ignoring...", tracked);
60
61
                        weight = 0;
61
62
                }
68
69
        list_add(track_list, tip);
69
70
}
70
71
 
71
 
static vrrp_script *
 
72
vrrp_script *
72
73
find_script_by_name(char *name)
73
74
{
74
75
        element e;
90
91
dump_track_script(void *track_data_obj)
91
92
{
92
93
        tracked_sc *tsc = track_data_obj;
93
 
        syslog(LOG_INFO, "     %s weight %d", tsc->scr->sname, tsc->weight);
 
94
        log_message(LOG_INFO, "     %s weight %d", tsc->scr->sname, tsc->weight);
94
95
}
95
96
void
96
97
alloc_track_script(list track_list, vector strvec)
104
105
 
105
106
        /* Ignoring if no interface found */
106
107
        if (!vsc) {
107
 
                syslog(LOG_INFO, "     %s no match, ignoring...", tracked);
 
108
                log_message(LOG_INFO, "     %s no match, ignoring...", tracked);
108
109
                return;
109
110
        }
110
111
 
116
117
                weight = atoi(VECTOR_SLOT(strvec, 2));
117
118
                if (weight < -254 || weight > 254) {
118
119
                        weight = vsc->weight;
119
 
                        syslog(LOG_INFO, "     %s: weight must be between [-254..254]"
 
120
                        log_message(LOG_INFO, "     %s: weight must be between [-254..254]"
120
121
                                         " inclusive, ignoring...",
121
122
                               tracked);
122
123
                }
125
126
        tsc         = (tracked_sc *) MALLOC(sizeof (tracked_sc));
126
127
        tsc->scr    = vsc;
127
128
        tsc->weight = weight;
128
 
        if (weight != 0)
129
 
                vsc->inuse++;
 
129
        vsc->inuse++;
130
130
        list_add(track_list, tsc);
131
131
}
132
132
 
156
156
        for (e = LIST_HEAD(l); e; ELEMENT_NEXT(e)) {
157
157
                tip = ELEMENT_DATA(e);
158
158
                if (!IF_ISUP(tip->ifp))
159
 
                        syslog(LOG_INFO, "Kernel is reporting: interface %s DOWN",
 
159
                        log_message(LOG_INFO, "Kernel is reporting: interface %s DOWN",
160
160
                               IF_NAME(tip->ifp));
161
161
        }
162
162
}
189
189
        return weight;
190
190
}
191
191
 
 
192
/* Test if all tracked scripts are either OK or weight-tracked */
 
193
int
 
194
vrrp_script_up(list l)
 
195
{
 
196
        element e;
 
197
        tracked_sc *tsc;
 
198
 
 
199
        for (e = LIST_HEAD(l); e; ELEMENT_NEXT(e)) {
 
200
                tsc = ELEMENT_DATA(e);
 
201
                if (!tsc->weight && tsc->scr->result == VRRP_SCRIPT_STATUS_NONE)
 
202
                        return 0;
 
203
        }
 
204
 
 
205
        return 1;
 
206
}
 
207
 
192
208
/* Returns total weights of all tracked scripts :
193
209
 * - a positive weight adds to the global weight when the result is OK
194
210
 * - a negative weight subtracts from the global weight when the result is bad