Statistics
| Branch: | Revision:

iof-bird-daemon / nest / rt-dev.c @ 094d2bdb

History | View | Annotate | Download (2.73 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->scope <= SCOPE_LINK)
38
    return;
39

    
40
  if (c & IF_CHANGE_DOWN)
41
    {
42
      net *n;
43

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

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

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

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

    
79
static struct proto *
80
dev_init(struct proto_config *c)
81
{
82
  struct proto *p = proto_new(c, sizeof(struct proto));
83

    
84
  p->ifa_notify = dev_ifa_notify;
85
  return p;
86
}
87

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

    
97
static void
98
dev_copy_config(struct proto_config *dest, struct proto_config *src)
99
{
100
  struct rt_dev_config *d = (struct rt_dev_config *) dest;
101
  struct rt_dev_config *s = (struct rt_dev_config *) src;
102

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

    
111
struct protocol proto_device = {
112
  name:                "Direct",
113
  template:        "direct%d",
114
  preference:        DEF_PREF_DIRECT,
115
  init:                dev_init,
116
  reconfigure:        dev_reconfigure,
117
  copy_config:        dev_copy_config
118
};