Statistics
| Branch: | Revision:

iof-bird-daemon / nest / rt-dev.c @ 9a158361

History | View | Annotate | Download (1.71 KB)

1
/*
2
 *        BIRD -- Direct Device Routes
3
 *
4
 *        (c) 1998--1999 Martin Mares <mj@ucw.cz>
5
 *
6
 *        Can be freely distributed and used under the terms of the GNU GPL.
7
 */
8

    
9
#define LOCAL_DEBUG
10

    
11
#include <string.h>
12

    
13
#include "nest/bird.h"
14
#include "nest/iface.h"
15
#include "nest/protocol.h"
16
#include "nest/route.h"
17
#include "nest/rt-dev.h"
18
#include "conf/conf.h"
19
#include "lib/resource.h"
20

    
21
static void
22
dev_ifa_notify(struct proto *p, unsigned c, struct ifa *ad)
23
{
24
  struct rt_dev_config *P = (void *) p->cf;
25

    
26
  if (!iface_patt_match(&P->iface_list, ad->iface))
27
    return;
28
  if (c & IF_CHANGE_DOWN)
29
    {
30
      net *n;
31

    
32
      DBG("dev_if_notify: %s:%I going down\n", ad->iface->name, ad->ip);
33
      n = net_find(p->table, ad->prefix, ad->pxlen);
34
      if (!n)
35
        {
36
          debug("dev_if_notify: device shutdown: prefix not found\n");
37
          return;
38
        }
39
      rte_update(n, p, NULL);
40
    }
41
  else if (c & IF_CHANGE_UP)
42
    {
43
      rta *a, A;
44
      net *n;
45
      rte *e;
46

    
47
      debug("dev_if_notify: %s:%I going up\n", ad->iface->name, ad->ip);
48
      bzero(&A, sizeof(A));
49
      A.proto = p;
50
      A.source = RTS_DEVICE;
51
      A.scope = ad->scope;
52
      A.cast = RTC_UNICAST;
53
      A.dest = RTD_DEVICE;
54
      A.iface = ad->iface;
55
      A.attrs = NULL;
56
      a = rta_lookup(&A);
57
      if (ad->flags & IF_UNNUMBERED)
58
        n = net_get(p->table, ad->opposite, ad->pxlen);
59
      else
60
        n = net_get(p->table, ad->prefix, ad->pxlen);
61
      e = rte_get_temp(a);
62
      e->net = n;
63
      e->pflags = 0;
64
      rte_update(n, p, e);
65
    }
66
}
67

    
68
static struct proto *
69
dev_init(struct proto_config *c)
70
{
71
  struct proto *p = proto_new(c, sizeof(struct proto));
72

    
73
  p->ifa_notify = dev_ifa_notify;
74
  return p;
75
}
76

    
77
struct protocol proto_device = {
78
  name:                "Direct",
79
  priority:        90,
80
  init:                dev_init,
81
};