]>
git.ipfire.org Git - thirdparty/bird.git/blob - nest/rt-dev.c
2 * BIRD -- Direct Device Routes
4 * (c) 1998--2000 Martin Mares <mj@ucw.cz>
6 * Can be freely distributed and used under the terms of the GNU GPL.
12 * The Direct protocol works by converting all ifa_notify() events it receives
13 * to rte_update() calls for the corresponding network.
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"
28 dev_ifa_notify(struct proto
*p
, unsigned c
, struct ifa
*ad
)
30 struct rt_dev_config
*P
= (void *) p
->cf
;
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 "*" */
37 if (ad
->flags
& IA_SECONDARY
)
40 if (ad
->scope
<= SCOPE_LINK
)
43 if (c
& IF_CHANGE_DOWN
)
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
);
51 DBG("dev_if_notify: device shutdown: prefix not found\n");
55 /* Use iface ID as local source ID */
56 struct rte_src
*src
= rt_get_source(p
, ad
->iface
->index
);
57 rte_update2(p
->main_ahook
, n
, NULL
, src
);
59 else if (c
& IF_CHANGE_UP
)
65 DBG("dev_if_notify: %s:%I going up\n", ad
->iface
->name
, ad
->ip
);
67 /* Use iface ID as local source ID */
68 struct rte_src
*src
= rt_get_source(p
, ad
->iface
->index
);
73 .scope
= SCOPE_UNIVERSE
,
80 n
= net_get(p
->table
, ad
->prefix
, ad
->pxlen
);
84 rte_update2(p
->main_ahook
, n
, e
, src
);
89 dev_init(struct proto_config
*c
)
91 struct proto
*p
= proto_new(c
, sizeof(struct proto
));
93 p
->ifa_notify
= dev_ifa_notify
;
98 dev_reconfigure(struct proto
*p
, struct proto_config
*new)
100 struct rt_dev_config
*o
= (struct rt_dev_config
*) p
->cf
;
101 struct rt_dev_config
*n
= (struct rt_dev_config
*) new;
103 return iface_patts_equal(&o
->iface_list
, &n
->iface_list
, NULL
);
107 dev_copy_config(struct proto_config
*dest
, struct proto_config
*src
)
109 struct rt_dev_config
*d
= (struct rt_dev_config
*) dest
;
110 struct rt_dev_config
*s
= (struct rt_dev_config
*) src
;
113 * We copy iface_list as ifaces can be shared by more direct protocols.
114 * Copy suffices to be is shallow, because new nodes can be added, but
115 * old nodes cannot be modified (although they contain internal lists).
117 cfg_copy_list(&d
->iface_list
, &s
->iface_list
, sizeof(struct iface_patt
));
120 struct protocol proto_device
= {
122 .template = "direct%d",
123 .preference
= DEF_PREF_DIRECT
,
124 .config_size
= sizeof(struct rt_dev_config
),
126 .reconfigure
= dev_reconfigure
,
127 .copy_config
= dev_copy_config