~ubuntu-branches/ubuntu/trusty/keepalived/trusty

« back to all changes in this revision

Viewing changes to keepalived/vrrp/vrrp_if.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:        Interfaces manipulation.
7
7
 *
8
 
 * Version:     $Id: vrrp_if.c,v 1.1.15 2007/09/15 04:07:41 acassen Exp $
 
8
 * Version:     $Id: vrrp_if.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
/* global include */
55
55
#include "vrrp_netlink.h"
56
56
#include "memory.h"
57
57
#include "utils.h"
 
58
#include "logger.h"
58
59
 
59
60
/* Global vars */
60
61
static list if_queue;
85
86
        interface *ifp;
86
87
        element e;
87
88
 
88
 
        if (LIST_ISEMPTY(if_queue))
 
89
        if (LIST_ISEMPTY(if_queue)) {
 
90
                log_message(LOG_ERR, "Interface queue is empty");
89
91
                return NULL;
 
92
        }
90
93
 
91
94
        for (e = LIST_HEAD(if_queue); e; ELEMENT_NEXT(e)) {
92
95
                ifp = ELEMENT_DATA(e);
93
96
                if (!strcmp(ifp->ifname, ifname))
94
97
                        return ifp;
95
98
        }
 
99
        log_message(LOG_ERR, "No such interface, %s", ifname);
96
100
        return NULL;
97
101
}
98
102
 
106
110
        data[1] = location;
107
111
 
108
112
        if (ioctl(fd, SIOCGMIIREG, &ifr) < 0) {
109
 
                syslog(LOG_ERR, "SIOCGMIIREG on %s failed: %s", ifr.ifr_name,
 
113
                log_message(LOG_ERR, "SIOCGMIIREG on %s failed: %s", ifr.ifr_name,
110
114
                       strerror(errno));
111
115
                return -1;
112
116
        }
142
146
// if_mii_dump(mii_regs, phy_id);
143
147
 
144
148
        if (mii_regs[0] == 0xffff) {
145
 
                syslog(LOG_ERR, "No MII transceiver present for %s !!!",
 
149
                log_message(LOG_ERR, "No MII transceiver present for %s !!!",
146
150
                       ifr.ifr_name);
147
151
                return -1;
148
152
        }
169
173
int
170
174
if_mii_probe(const char *ifname)
171
175
{
 
176
        uint16_t *data = (uint16_t *) (&ifr.ifr_data);
 
177
        int phy_id;
172
178
        int fd = socket(AF_INET, SOCK_DGRAM, 0);
173
179
        int status = 0;
174
180
 
181
187
                return -1;
182
188
        }
183
189
 
 
190
        /* check if the driver reports BMSR using the MII interface, as we
 
191
         * will need this and we already know that some don't support it.
 
192
         */
 
193
        phy_id = data[0]; /* save it in case it is overwritten */
 
194
        data[1] = 1;
 
195
        if (ioctl(fd, SIOCGMIIREG, &ifr) < 0) {
 
196
                close(fd);
 
197
                return -1;
 
198
        }
 
199
        data[0] = phy_id;
 
200
 
184
201
        /* Dump the MII transceiver */
185
202
        status = if_mii_status(fd);
186
203
        close(fd);
249
266
{
250
267
        interface *ifp = if_data_obj;
251
268
 
252
 
        syslog(LOG_INFO, "------< NIC >------");
253
 
        syslog(LOG_INFO, " Name = %s", ifp->ifname);
254
 
        syslog(LOG_INFO, " index = %d", ifp->ifindex);
255
 
        syslog(LOG_INFO, " address = %s", inet_ntop2(ifp->address));
 
269
        log_message(LOG_INFO, "------< NIC >------");
 
270
        log_message(LOG_INFO, " Name = %s", ifp->ifname);
 
271
        log_message(LOG_INFO, " index = %d", ifp->ifindex);
 
272
        log_message(LOG_INFO, " address = %s", inet_ntop2(ifp->address));
256
273
 
257
274
        /* FIXME: Harcoded for ethernet */
258
275
        if (ifp->hw_type == ARPHRD_ETHER)
259
 
                syslog(LOG_INFO, " MAC = %.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
 
276
                log_message(LOG_INFO, " MAC = %.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
260
277
                       ifp->hw_addr[0], ifp->hw_addr[1], ifp->hw_addr[2]
261
278
                       , ifp->hw_addr[3], ifp->hw_addr[4], ifp->hw_addr[5]);
262
279
 
263
280
        if (ifp->flags & IFF_UP)
264
 
                syslog(LOG_INFO, " is UP");
 
281
                log_message(LOG_INFO, " is UP");
265
282
 
266
283
        if (ifp->flags & IFF_RUNNING)
267
 
                syslog(LOG_INFO, " is RUNNING");
 
284
                log_message(LOG_INFO, " is RUNNING");
268
285
 
269
286
        if (!(ifp->flags & IFF_UP) && !(ifp->flags & IFF_RUNNING))
270
 
                syslog(LOG_INFO, " is DOWN");
 
287
                log_message(LOG_INFO, " is DOWN");
271
288
 
272
 
        syslog(LOG_INFO, " MTU = %d", ifp->mtu);
 
289
        log_message(LOG_INFO, " MTU = %d", ifp->mtu);
273
290
 
274
291
        switch (ifp->hw_type) {
275
292
        case ARPHRD_LOOPBACK:
276
 
                syslog(LOG_INFO, " HW Type = LOOPBACK");
 
293
                log_message(LOG_INFO, " HW Type = LOOPBACK");
277
294
                break;
278
295
        case ARPHRD_ETHER:
279
 
                syslog(LOG_INFO, " HW Type = ETHERNET");
 
296
                log_message(LOG_INFO, " HW Type = ETHERNET");
280
297
                break;
281
298
        default:
282
 
                syslog(LOG_INFO, " HW Type = UNKNOWN");
 
299
                log_message(LOG_INFO, " HW Type = UNKNOWN");
283
300
                break;
284
301
        }
285
302
 
286
303
        /* MII channel supported ? */
287
304
        if (IF_MII_SUPPORTED(ifp))
288
 
                syslog(LOG_INFO, " NIC support MII regs");
 
305
                log_message(LOG_INFO, " NIC support MII regs");
289
306
        else if (IF_ETHTOOL_SUPPORTED(ifp))
290
 
                syslog(LOG_INFO, " NIC support EHTTOOL GLINK interface");
 
307
                log_message(LOG_INFO, " NIC support EHTTOOL GLINK interface");
291
308
        else
292
 
                syslog(LOG_INFO, " Enabling NIC ioctl refresh polling");
 
309
                log_message(LOG_INFO, " Enabling NIC ioctl refresh polling");
293
310
}
294
311
 
295
312
static void
351
368
                }
352
369
 
353
370
                /* Register new monitor thread */
354
 
                thread_add_timer(master, if_linkbeat_refresh_thread, ifp
355
 
                                 , POLLING_DELAY);
 
371
                thread_add_timer(master, if_linkbeat_refresh_thread, ifp, POLLING_DELAY);
356
372
        }
357
373
}
358
374
 
382
398
//      dump_list(if_queue);
383
399
        netlink_interface_lookup();
384
400
#ifdef _WITH_LINKWATCH_
385
 
        syslog(LOG_INFO, "Using LinkWatch kernel netlink reflector...");
 
401
          log_message(LOG_INFO, "Using LinkWatch kernel netlink reflector...");
386
402
#else
387
 
        syslog(LOG_INFO, "Using MII-BMSR NIC polling thread...");
388
 
        init_if_linkbeat();
 
403
          log_message(LOG_INFO, "Using MII-BMSR NIC polling thread...");
 
404
          init_if_linkbeat();
389
405
#endif
390
406
}
391
407
 
411
427
        ret = setsockopt(sd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
412
428
                         (char *) &req_add, sizeof (struct ip_mreqn));
413
429
        if (ret < 0) {
414
 
                syslog(LOG_INFO, "cant do IP_ADD_MEMBERSHIP errno=%s (%d)",
 
430
                log_message(LOG_INFO, "cant do IP_ADD_MEMBERSHIP errno=%s (%d)",
415
431
                       strerror(errno), errno);
416
432
                close(sd);
417
433
                return -1;
438
454
        ret = setsockopt(sd, IPPROTO_IP, IP_DROP_MEMBERSHIP,
439
455
                         (char *) &req_add, sizeof (struct ip_mreqn));
440
456
        if (ret < 0) {
441
 
                syslog(LOG_INFO, "cant do IP_DROP_MEMBERSHIP errno=%s (%d)",
 
457
                log_message(LOG_INFO, "cant do IP_DROP_MEMBERSHIP errno=%s (%d)",
442
458
                       strerror(errno), errno);
443
459
                return;
444
460
        }
468
484
                         , strlen(IF_NAME(ifp)) + 1);
469
485
        if (ret < 0) {
470
486
                int err = errno;
471
 
                syslog(LOG_INFO,
 
487
                log_message(LOG_INFO,
472
488
                       "cant bind to device %s. errno=%d. (try to run it as root)",
473
489
                       IF_NAME(ifp), err);
474
490
                close(sd);
488
504
        ret = setsockopt(sd, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on));
489
505
        if (ret < 0) {
490
506
                int err = errno;
491
 
                syslog(LOG_INFO, "cant set HDRINCL IP option. errno=%d.", err);
 
507
                log_message(LOG_INFO, "cant set HDRINCL IP option. errno=%d.", err);
492
508
                close(sd);
493
509
                return -1;
494
510
        }
506
522
        ret = setsockopt(sd, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof(loop));
507
523
        if (ret < 0) {
508
524
                int err = errno;
509
 
                syslog(LOG_INFO, "cant set MULTICAST_LOOP IP option. errno=%d.", err);
 
525
                log_message(LOG_INFO, "cant set MULTICAST_LOOP IP option. errno=%d.", err);
510
526
                close(sd);
511
527
                return -1;
512
528
        }