Statistics
| Branch: | Revision:

iof-bird-daemon / nest / rt-dev.c @ 4a591d4b

History | View | Annotate | Download (2.79 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, ad->iface->addr))
34
    /* Empty list is automagically treated as "*" */
35
    return;
36

    
37
  if (ad->flags & IA_SECONDARY)
38
    return;
39

    
40
  if (ad->scope <= SCOPE_LINK)
41
    return;
42

    
43
  if (c & IF_CHANGE_DOWN)
44
    {
45
      net *n;
46

    
47
      DBG("dev_if_notify: %s:%I going down\n", ad->iface->name, ad->ip);
48
      n = net_find(p->table, ad->prefix, ad->pxlen);
49
      if (!n)
50
        {
51
          DBG("dev_if_notify: device shutdown: prefix not found\n");
52
          return;
53
        }
54
      rte_update(p, n, NULL);
55
    }
56
  else if (c & IF_CHANGE_UP)
57
    {
58
      rta *a;
59
      net *n;
60
      rte *e;
61

    
62
      DBG("dev_if_notify: %s:%I going up\n", ad->iface->name, ad->ip);
63

    
64
      rta a0 = {
65
        .src = p->main_source,
66
        .source = RTS_DEVICE,
67
        .scope = SCOPE_UNIVERSE,
68
        .cast = RTC_UNICAST,
69
        .dest = RTD_DEVICE,
70
        .iface = ad->iface
71
      };
72

    
73
      a = rta_lookup(&a0);
74
      n = net_get(p->table, ad->prefix, ad->pxlen);
75
      e = rte_get_temp(a);
76
      e->net = n;
77
      e->pflags = 0;
78
      rte_update(p, n, e);
79
    }
80
}
81

    
82
static struct proto *
83
dev_init(struct proto_config *c)
84
{
85
  struct proto *p = proto_new(c, sizeof(struct proto));
86

    
87
  p->ifa_notify = dev_ifa_notify;
88
  return p;
89
}
90

    
91
static int
92
dev_reconfigure(struct proto *p, struct proto_config *new)
93
{
94
  struct rt_dev_config *o = (struct rt_dev_config *) p->cf;
95
  struct rt_dev_config *n = (struct rt_dev_config *) new;
96
  
97
  return iface_patts_equal(&o->iface_list, &n->iface_list, NULL);
98
}
99

    
100
static void
101
dev_copy_config(struct proto_config *dest, struct proto_config *src)
102
{
103
  struct rt_dev_config *d = (struct rt_dev_config *) dest;
104
  struct rt_dev_config *s = (struct rt_dev_config *) src;
105

    
106
  /*
107
   * We copy iface_list as ifaces can be shared by more direct protocols.
108
   * Copy suffices to be is shallow, because new nodes can be added, but
109
   * old nodes cannot be modified (although they contain internal lists).
110
   */
111
  cfg_copy_list(&d->iface_list, &s->iface_list, sizeof(struct iface_patt));
112
}
113

    
114
struct protocol proto_device = {
115
  .name =                 "Direct",
116
  .template =                 "direct%d",
117
  .preference =         DEF_PREF_DIRECT,
118
  .init =                 dev_init,
119
  .reconfigure =         dev_reconfigure,
120
  .copy_config =         dev_copy_config
121
};