]> git.ipfire.org Git - thirdparty/bird.git/blob - nest/rt-dev.c
We have full interface routes now.
[thirdparty/bird.git] / nest / rt-dev.c
1 /*
2 * BIRD -- Direct Device Routes
3 *
4 * (c) 1998 Martin Mares <mj@ucw.cz>
5 *
6 * Can be freely distributed and used under the terms of the GNU GPL.
7 */
8
9 #define LOCAL_DEBUG
10
11 #include <string.h>
12
13 #include "nest/bird.h"
14 #include "nest/iface.h"
15 #include "nest/protocol.h"
16 #include "nest/route.h"
17 #include "lib/resource.h"
18
19 static struct proto *dev_proto;
20
21 static void
22 dev_if_notify(struct proto *p, unsigned c, struct iface *old, struct iface *new)
23 {
24 if (c & IF_CHANGE_DOWN)
25 {
26 net *n;
27
28 debug("dev_if_notify: %s going down\n", old->name);
29 n = net_find(&master_table, 0, old->prefix, old->pxlen);
30 if (!n)
31 {
32 debug("dev_if_notify: device shutdown: prefix not found\n");
33 return;
34 }
35 rte_update(n, dev_proto, NULL);
36 }
37 else if (c & IF_CHANGE_UP)
38 {
39 rta *a, A;
40 net *n;
41 rte *e;
42
43 debug("dev_if_notify: %s going up\n", new->name);
44 bzero(&A, sizeof(A));
45 A.proto = dev_proto;
46 A.source = RTS_DEVICE;
47 A.scope = (new->flags & IF_LOOPBACK) ? SCOPE_HOST : SCOPE_UNIVERSE;
48 A.cast = RTC_UNICAST;
49 A.dest = RTD_DEVICE;
50 A.iface = new;
51 A.attrs = NULL;
52 a = rta_lookup(&A);
53 n = net_get(&master_table, 0, new->prefix, new->pxlen);
54 e = rte_get_temp(a);
55 e->pflags = 0;
56 rte_update(n, dev_proto, e);
57 }
58 }
59
60 static void
61 dev_start(struct proto *p)
62 {
63 }
64
65 static void
66 dev_init(struct protocol *p)
67 {
68 }
69
70 static void
71 dev_preconfig(struct protocol *x)
72 {
73 struct proto *p = proto_new(&proto_device, sizeof(struct proto));
74
75 dev_proto = p;
76 p->preference = DEF_PREF_DIRECT;
77 p->start = dev_start;
78 p->if_notify = dev_if_notify;
79 }
80
81 static void
82 dev_postconfig(struct protocol *p)
83 {
84 }
85
86 struct protocol proto_device = {
87 { NULL, NULL },
88 "Device",
89 0,
90 dev_init,
91 dev_preconfig,
92 dev_postconfig
93 };