]>
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"
29 dev_ifa_notify(struct proto
*P
, uint flags
, struct ifa
*ad
)
31 struct rt_dev_proto
*p
= (void *) P
;
32 struct rt_dev_config
*cf
= (void *) P
->cf
;
35 if (!EMPTY_LIST(cf
->iface_list
) &&
36 !iface_patt_find(&cf
->iface_list
, ad
->iface
, ad
->iface
->addr
))
37 /* Empty list is automatically treated as "*" */
40 if (ad
->flags
& IA_SECONDARY
)
43 if (ad
->scope
<= SCOPE_LINK
)
46 if (ad
->prefix
.type
== NET_IP4
)
48 else if (ad
->prefix
.type
== NET_IP6
)
56 if (flags
& IF_CHANGE_DOWN
)
58 DBG("dev_if_notify: %s:%I going down\n", ad
->iface
->name
, ad
->ip
);
60 /* Use iface ID as local source ID */
61 struct rte_src
*src
= rt_get_source(P
, ad
->iface
->index
);
62 rte_update2(c
, &ad
->prefix
, NULL
, src
);
64 else if (flags
& IF_CHANGE_UP
)
69 DBG("dev_if_notify: %s:%I going up\n", ad
->iface
->name
, ad
->ip
);
71 /* Use iface ID as local source ID */
72 struct rte_src
*src
= rt_get_source(P
, ad
->iface
->index
);
77 .scope
= SCOPE_UNIVERSE
,
86 rte_update2(c
, &ad
->prefix
, e
, src
);
91 dev_init(struct proto_config
*CF
)
93 struct proto
*P
= proto_new(CF
);
94 struct rt_dev_proto
*p
= (void *) P
;
95 // struct rt_dev_config *cf = (void *) CF;
97 proto_configure_channel(P
, &p
->ip4_channel
, proto_cf_find_channel(CF
, NET_IP4
));
98 proto_configure_channel(P
, &p
->ip6_channel
, proto_cf_find_channel(CF
, NET_IP6
));
100 P
->ifa_notify
= dev_ifa_notify
;
106 dev_reconfigure(struct proto
*P
, struct proto_config
*CF
)
108 struct rt_dev_proto
*p
= (void *) P
;
109 struct rt_dev_config
*o
= (void *) P
->cf
;
110 struct rt_dev_config
*n
= (void *) CF
;
112 if (!iface_patts_equal(&o
->iface_list
, &n
->iface_list
, NULL
))
116 proto_configure_channel(P
, &p
->ip4_channel
, proto_cf_find_channel(CF
, NET_IP4
)) &&
117 proto_configure_channel(P
, &p
->ip6_channel
, proto_cf_find_channel(CF
, NET_IP6
));
123 dev_copy_config(struct proto_config
*dest
, struct proto_config
*src
)
125 struct rt_dev_config
*d
= (void *) dest
;
126 struct rt_dev_config
*s
= (void *) src
;
129 * We copy iface_list as ifaces can be shared by more direct protocols.
130 * Copy suffices to be is shallow, because new nodes can be added, but
131 * old nodes cannot be modified (although they contain internal lists).
133 cfg_copy_list(&d
->iface_list
, &s
->iface_list
, sizeof(struct iface_patt
));
136 struct protocol proto_device
= {
138 .template = "direct%d",
139 .preference
= DEF_PREF_DIRECT
,
140 .channel_mask
= NB_IP
,
141 .proto_size
= sizeof(struct rt_dev_proto
),
142 .config_size
= sizeof(struct rt_dev_config
),
144 .reconfigure
= dev_reconfigure
,
145 .copy_config
= dev_copy_config