]>
git.proxmox.com Git - mirror_frr.git/blob - zebra/router-id.c
2 * Router ID for zebra daemon.
4 * Copyright (C) 2004 James R. Leu
6 * This file is part of Quagga routing suite.
8 * Quagga is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
13 * Quagga is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with GNU Zebra; see the file COPYING. If not, write to the Free
20 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
28 #include "sockunion.h"
34 #include "connected.h"
40 #include "zebra/zserv.h"
41 #include "zebra/router-id.h"
43 static struct list rid_all_sorted_list
;
44 static struct list rid_lo_sorted_list
;
45 static struct prefix rid_user_assigned
;
47 /* master zebra server structure */
48 extern struct zebra_t zebrad
;
50 static struct connected
*
51 router_id_find_node (struct list
*l
, struct connected
*ifc
)
53 struct listnode
*node
;
56 for (ALL_LIST_ELEMENTS_RO (l
, node
, c
))
57 if (prefix_same (ifc
->address
, c
->address
))
64 router_id_bad_address (struct connected
*ifc
)
68 if (ifc
->address
->family
!= AF_INET
)
71 n
.u
.prefix4
.s_addr
= htonl (INADDR_LOOPBACK
);
75 if (prefix_match (&n
, ifc
->address
))
82 router_id_get (struct prefix
*p
)
84 struct listnode
*node
;
87 p
->u
.prefix4
.s_addr
= 0;
91 if (rid_user_assigned
.u
.prefix4
.s_addr
)
92 p
->u
.prefix4
.s_addr
= rid_user_assigned
.u
.prefix4
.s_addr
;
93 else if (!list_isempty (&rid_lo_sorted_list
))
95 node
= listtail (&rid_lo_sorted_list
);
96 c
= listgetdata (node
);
97 p
->u
.prefix4
.s_addr
= c
->address
->u
.prefix4
.s_addr
;
99 else if (!list_isempty (&rid_all_sorted_list
))
101 node
= listtail (&rid_all_sorted_list
);
102 c
= listgetdata (node
);
103 p
->u
.prefix4
.s_addr
= c
->address
->u
.prefix4
.s_addr
;
108 router_id_set (struct prefix
*p
)
111 struct listnode
*node
;
112 struct zserv
*client
;
114 rid_user_assigned
.u
.prefix4
.s_addr
= p
->u
.prefix4
.s_addr
;
118 for (ALL_LIST_ELEMENTS_RO (zebrad
.client_list
, node
, client
))
119 zsend_router_id_update (client
, &p2
);
123 router_id_add_address (struct connected
*ifc
)
125 struct list
*l
= NULL
;
126 struct listnode
*node
;
127 struct prefix before
;
129 struct zserv
*client
;
131 if (router_id_bad_address (ifc
))
134 router_id_get (&before
);
136 if (!strncmp (ifc
->ifp
->name
, "lo", 2)
137 || !strncmp (ifc
->ifp
->name
, "dummy", 5))
138 l
= &rid_lo_sorted_list
;
140 l
= &rid_all_sorted_list
;
142 if (!router_id_find_node (l
, ifc
))
143 listnode_add (l
, ifc
);
145 router_id_get (&after
);
147 if (prefix_same (&before
, &after
))
150 for (ALL_LIST_ELEMENTS_RO (zebrad
.client_list
, node
, client
))
151 zsend_router_id_update (client
, &after
);
155 router_id_del_address (struct connected
*ifc
)
160 struct prefix before
;
161 struct listnode
*node
;
162 struct zserv
*client
;
164 if (router_id_bad_address (ifc
))
167 router_id_get (&before
);
169 if (!strncmp (ifc
->ifp
->name
, "lo", 2)
170 || !strncmp (ifc
->ifp
->name
, "dummy", 5))
171 l
= &rid_lo_sorted_list
;
173 l
= &rid_all_sorted_list
;
175 if ((c
= router_id_find_node (l
, ifc
)))
176 listnode_delete (l
, c
);
178 router_id_get (&after
);
180 if (prefix_same (&before
, &after
))
183 for (ALL_LIST_ELEMENTS_RO (zebrad
.client_list
, node
, client
))
184 zsend_router_id_update (client
, &after
);
188 router_id_write (struct vty
*vty
)
190 if (rid_user_assigned
.u
.prefix4
.s_addr
)
191 vty_out (vty
, "router-id %s%s", inet_ntoa (rid_user_assigned
.u
.prefix4
),
198 "Manually set the router-id\n"
199 "IP address to use for router-id\n")
203 rid
.u
.prefix4
.s_addr
= inet_addr (argv
[0]);
204 if (!rid
.u
.prefix4
.s_addr
)
208 rid
.family
= AF_INET
;
210 router_id_set (&rid
);
219 "Remove the manually configured router-id\n")
223 rid
.u
.prefix4
.s_addr
= 0;
225 rid
.family
= AF_INET
;
227 router_id_set (&rid
);
233 router_id_cmp (void *a
, void *b
)
237 A
= ((struct connected
*) a
)->address
->u
.prefix4
.s_addr
;
238 B
= ((struct connected
*) b
)->address
->u
.prefix4
.s_addr
;
248 router_id_init (void)
250 install_element (CONFIG_NODE
, &router_id_cmd
);
251 install_element (CONFIG_NODE
, &no_router_id_cmd
);
253 memset (&rid_all_sorted_list
, 0, sizeof (rid_all_sorted_list
));
254 memset (&rid_lo_sorted_list
, 0, sizeof (rid_lo_sorted_list
));
255 memset (&rid_user_assigned
, 0, sizeof (rid_user_assigned
));
257 rid_all_sorted_list
.cmp
= router_id_cmp
;
258 rid_lo_sorted_list
.cmp
= router_id_cmp
;
260 rid_user_assigned
.family
= AF_INET
;
261 rid_user_assigned
.prefixlen
= 32;