Statistics
| Branch: | Revision:

iof-bird-daemon / nest / rt-dev.c @ fbde6c39

History | View | Annotate | Download (2.2 KB)

1 c5ffa447 Martin Mares
/*
2
 *        BIRD -- Direct Device Routes
3
 *
4 394aec8f Martin Mares
 *        (c) 1998--2000 Martin Mares <mj@ucw.cz>
5 c5ffa447 Martin Mares
 *
6
 *        Can be freely distributed and used under the terms of the GNU GPL.
7
 */
8
9 47f8e0c2 Martin Mares
/**
10
 * DOC: Direct
11
 *
12 2e9b2421 Martin Mares
 * The Direct protocol works by converting all ifa_notify() events it receives
13 47f8e0c2 Martin Mares
 * to rte_update() calls for the corresponding network.
14
 */
15
16 6b9fa320 Martin Mares
#undef LOCAL_DEBUG
17 c5ffa447 Martin Mares
18
#include "nest/bird.h"
19
#include "nest/iface.h"
20
#include "nest/protocol.h"
21
#include "nest/route.h"
22 50d8424a Martin Mares
#include "nest/rt-dev.h"
23
#include "conf/conf.h"
24 c5ffa447 Martin Mares
#include "lib/resource.h"
25 221135d6 Martin Mares
#include "lib/string.h"
26 c5ffa447 Martin Mares
27
static void
28 9a158361 Martin Mares
dev_ifa_notify(struct proto *p, unsigned c, struct ifa *ad)
29 c5ffa447 Martin Mares
{
30 31b3e1bb Martin Mares
  struct rt_dev_config *P = (void *) p->cf;
31 50d8424a Martin Mares
32 8edf2361 Martin Mares
  if (!EMPTY_LIST(P->iface_list) &&
33
      !iface_patt_match(&P->iface_list, ad->iface))
34
    /* Empty list is automagically treated as "*" */
35 50d8424a Martin Mares
    return;
36 b1e4f814 Martin Mares
  if (c & IF_CHANGE_DOWN)
37
    {
38
      net *n;
39
40 9a158361 Martin Mares
      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 b1e4f814 Martin Mares
      if (!n)
43
        {
44 6b9fa320 Martin Mares
          DBG("dev_if_notify: device shutdown: prefix not found\n");
45 b1e4f814 Martin Mares
          return;
46
        }
47 4f1a6d27 Martin Mares
      rte_update(p->table, n, p, NULL);
48 b1e4f814 Martin Mares
    }
49
  else if (c & IF_CHANGE_UP)
50
    {
51
      rta *a, A;
52
      net *n;
53
      rte *e;
54
55 6b9fa320 Martin Mares
      DBG("dev_if_notify: %s:%I going up\n", ad->iface->name, ad->ip);
56 b1e4f814 Martin Mares
      bzero(&A, sizeof(A));
57 05e56feb Martin Mares
      A.proto = p;
58 b1e4f814 Martin Mares
      A.source = RTS_DEVICE;
59 9a158361 Martin Mares
      A.scope = ad->scope;
60 b1e4f814 Martin Mares
      A.cast = RTC_UNICAST;
61
      A.dest = RTD_DEVICE;
62 9a158361 Martin Mares
      A.iface = ad->iface;
63 2727bb7c Martin Mares
      A.eattrs = NULL;
64 b1e4f814 Martin Mares
      a = rta_lookup(&A);
65 6a636392 Martin Mares
      n = net_get(p->table, ad->prefix, ad->pxlen);
66 b1e4f814 Martin Mares
      e = rte_get_temp(a);
67 a0762910 Martin Mares
      e->net = n;
68 b1e4f814 Martin Mares
      e->pflags = 0;
69 4f1a6d27 Martin Mares
      rte_update(p->table, n, p, e);
70 b1e4f814 Martin Mares
    }
71 c5ffa447 Martin Mares
}
72
73 31b3e1bb Martin Mares
static struct proto *
74
dev_init(struct proto_config *c)
75 c5ffa447 Martin Mares
{
76 31b3e1bb Martin Mares
  struct proto *p = proto_new(c, sizeof(struct proto));
77 c5ffa447 Martin Mares
78 9a158361 Martin Mares
  p->ifa_notify = dev_ifa_notify;
79 394aec8f Martin Mares
  p->min_scope = SCOPE_HOST;
80 31b3e1bb Martin Mares
  return p;
81 c5ffa447 Martin Mares
}
82
83 88dc89f9 Martin Mares
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 c5ffa447 Martin Mares
struct protocol proto_device = {
93 7e5f5ffd Martin Mares
  name:                "Direct",
94 d272fe22 Martin Mares
  template:        "direct%d",
95 31b3e1bb Martin Mares
  init:                dev_init,
96 88dc89f9 Martin Mares
  reconfigure:        dev_reconfigure
97 c5ffa447 Martin Mares
};