Statistics
| Branch: | Revision:

iof-bird-daemon / nest / rt-dev.c @ 11361a10

History | View | Annotate | Download (2.21 KB)

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

    
9
/**
10
 * DOC: Direct
11
 *
12
 * The Direct protocol works by converting all ifa_notify() events it receives
13
 * to rte_update() calls for the corresponding network.
14
 */
15

    
16
#undef LOCAL_DEBUG
17

    
18
#include "nest/bird.h"
19
#include "nest/iface.h"
20
#include "nest/protocol.h"
21
#include "nest/route.h"
22
#include "nest/rt-dev.h"
23
#include "conf/conf.h"
24
#include "lib/resource.h"
25
#include "lib/string.h"
26

    
27
static void
28
dev_ifa_notify(struct proto *p, unsigned c, struct ifa *ad)
29
{
30
  struct rt_dev_config *P = (void *) p->cf;
31

    
32
  if (!EMPTY_LIST(P->iface_list) &&
33
      !iface_patt_find(&P->iface_list, ad->iface))
34
    /* Empty list is automagically treated as "*" */
35
    return;
36
  if (c & IF_CHANGE_DOWN)
37
    {
38
      net *n;
39

    
40
      DBG("dev_if_notify: %s:%I going down\n", ad->iface->name, ad->ip);
41
      n = net_find(p->table, ad->prefix, ad->pxlen);
42
      if (!n)
43
        {
44
          DBG("dev_if_notify: device shutdown: prefix not found\n");
45
          return;
46
        }
47
      rte_update(p->table, n, p, p, NULL);
48
    }
49
  else if (c & IF_CHANGE_UP)
50
    {
51
      rta *a, A;
52
      net *n;
53
      rte *e;
54

    
55
      DBG("dev_if_notify: %s:%I going up\n", ad->iface->name, ad->ip);
56
      bzero(&A, sizeof(A));
57
      A.proto = p;
58
      A.source = RTS_DEVICE;
59
      A.scope = ad->scope;
60
      A.cast = RTC_UNICAST;
61
      A.dest = RTD_DEVICE;
62
      A.iface = ad->iface;
63
      A.eattrs = NULL;
64
      a = rta_lookup(&A);
65
      n = net_get(p->table, ad->prefix, ad->pxlen);
66
      e = rte_get_temp(a);
67
      e->net = n;
68
      e->pflags = 0;
69
      rte_update(p->table, n, p, p, e);
70
    }
71
}
72

    
73
static struct proto *
74
dev_init(struct proto_config *c)
75
{
76
  struct proto *p = proto_new(c, sizeof(struct proto));
77

    
78
  p->ifa_notify = dev_ifa_notify;
79
  p->min_scope = SCOPE_HOST;
80
  return p;
81
}
82

    
83
static int
84
dev_reconfigure(struct proto *p, struct proto_config *new)
85
{
86
  struct rt_dev_config *o = (struct rt_dev_config *) p->cf;
87
  struct rt_dev_config *n = (struct rt_dev_config *) new;
88
  
89
  return iface_patts_equal(&o->iface_list, &n->iface_list, NULL);
90
}
91

    
92
struct protocol proto_device = {
93
  name:                "Direct",
94
  template:        "direct%d",
95
  init:                dev_init,
96
  reconfigure:        dev_reconfigure
97
};