]> git.ipfire.org Git - thirdparty/bird.git/blob - nest/rt-dev.c
Merge branch 'socket2' into new
[thirdparty/bird.git] / nest / rt-dev.c
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->table, n, p, p, NULL);
52 }
53 else if (c & IF_CHANGE_UP)
54 {
55 rta *a, A;
56 net *n;
57 rte *e;
58
59 DBG("dev_if_notify: %s:%I going up\n", ad->iface->name, ad->ip);
60 bzero(&A, sizeof(A));
61 A.proto = p;
62 A.source = RTS_DEVICE;
63 A.scope = SCOPE_UNIVERSE;
64 A.cast = RTC_UNICAST;
65 A.dest = RTD_DEVICE;
66 A.iface = ad->iface;
67 A.eattrs = NULL;
68 a = rta_lookup(&A);
69 n = net_get(p->table, ad->prefix, ad->pxlen);
70 e = rte_get_temp(a);
71 e->net = n;
72 e->pflags = 0;
73 rte_update(p->table, n, p, p, e);
74 }
75 }
76
77 static struct proto *
78 dev_init(struct proto_config *c)
79 {
80 struct proto *p = proto_new(c, sizeof(struct proto));
81
82 p->ifa_notify = dev_ifa_notify;
83 return p;
84 }
85
86 static int
87 dev_reconfigure(struct proto *p, struct proto_config *new)
88 {
89 struct rt_dev_config *o = (struct rt_dev_config *) p->cf;
90 struct rt_dev_config *n = (struct rt_dev_config *) new;
91
92 return iface_patts_equal(&o->iface_list, &n->iface_list, NULL);
93 }
94
95 struct protocol proto_device = {
96 name: "Direct",
97 template: "direct%d",
98 init: dev_init,
99 reconfigure: dev_reconfigure
100 };