]>
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"
42 static struct list rid_all_sorted_list
;
43 static struct list rid_lo_sorted_list
;
44 static struct prefix rid_user_assigned
;
46 /* master zebra server structure */
47 extern struct zebra_t zebrad
;
49 static struct connected
*
50 router_id_find_node (struct list
*l
, struct connected
*ifc
)
52 struct listnode
*node
;
55 for (ALL_LIST_ELEMENTS_RO (l
, node
, c
))
56 if (prefix_same (ifc
->address
, c
->address
))
63 router_id_bad_address (struct connected
*ifc
)
67 if (ifc
->address
->family
!= AF_INET
)
70 n
.u
.prefix4
.s_addr
= htonl (INADDR_LOOPBACK
);
74 if (prefix_match (&n
, ifc
->address
))
81 router_id_get (struct prefix
*p
)
83 struct listnode
*node
;
86 p
->u
.prefix4
.s_addr
= 0;
90 if (rid_user_assigned
.u
.prefix4
.s_addr
)
91 p
->u
.prefix4
.s_addr
= rid_user_assigned
.u
.prefix4
.s_addr
;
92 else if (!list_isempty (&rid_lo_sorted_list
))
94 node
= listtail (&rid_lo_sorted_list
);
95 c
= listgetdata (node
);
96 p
->u
.prefix4
.s_addr
= c
->address
->u
.prefix4
.s_addr
;
98 else if (!list_isempty (&rid_all_sorted_list
))
100 node
= listtail (&rid_all_sorted_list
);
101 c
= listgetdata (node
);
102 p
->u
.prefix4
.s_addr
= c
->address
->u
.prefix4
.s_addr
;
107 router_id_set (struct prefix
*p
)
110 struct listnode
*node
;
111 struct zserv
*client
;
113 rid_user_assigned
.u
.prefix4
.s_addr
= p
->u
.prefix4
.s_addr
;
117 for (ALL_LIST_ELEMENTS_RO (zebrad
.client_list
, node
, client
))
118 zsend_router_id_update (client
, &p2
);
122 router_id_add_address (struct connected
*ifc
)
124 struct list
*l
= NULL
;
125 struct listnode
*node
;
126 struct prefix before
;
128 struct zserv
*client
;
130 if (router_id_bad_address (ifc
))
133 router_id_get (&before
);
135 if (!strncmp (ifc
->ifp
->name
, "lo", 2)
136 || !strncmp (ifc
->ifp
->name
, "dummy", 5))
137 l
= &rid_lo_sorted_list
;
139 l
= &rid_all_sorted_list
;
141 if (!router_id_find_node (l
, ifc
))
142 listnode_add (l
, ifc
);
144 router_id_get (&after
);
146 if (prefix_same (&before
, &after
))
149 for (ALL_LIST_ELEMENTS_RO (zebrad
.client_list
, node
, client
))
150 zsend_router_id_update (client
, &after
);
154 router_id_del_address (struct connected
*ifc
)
159 struct prefix before
;
160 struct listnode
*node
;
161 struct zserv
*client
;
163 if (router_id_bad_address (ifc
))
166 router_id_get (&before
);
168 if (!strncmp (ifc
->ifp
->name
, "lo", 2)
169 || !strncmp (ifc
->ifp
->name
, "dummy", 5))
170 l
= &rid_lo_sorted_list
;
172 l
= &rid_all_sorted_list
;
174 if ((c
= router_id_find_node (l
, ifc
)))
175 listnode_delete (l
, c
);
177 router_id_get (&after
);
179 if (prefix_same (&before
, &after
))
182 for (ALL_LIST_ELEMENTS_RO (zebrad
.client_list
, node
, client
))
183 zsend_router_id_update (client
, &after
);
187 router_id_write (struct vty
*vty
)
189 if (rid_user_assigned
.u
.prefix4
.s_addr
)
190 vty_out (vty
, "router-id %s%s", inet_ntoa (rid_user_assigned
.u
.prefix4
),
197 "Manually set the router-id\n"
198 "IP address to use for router-id\n")
202 rid
.u
.prefix4
.s_addr
= inet_addr (argv
[0]);
203 if (!rid
.u
.prefix4
.s_addr
)
207 rid
.family
= AF_INET
;
209 router_id_set (&rid
);
218 "Remove the manually configured router-id\n")
222 rid
.u
.prefix4
.s_addr
= 0;
224 rid
.family
= AF_INET
;
226 router_id_set (&rid
);
232 router_id_cmp (void *a
, void *b
)
236 A
= ((struct connected
*) a
)->address
->u
.prefix4
.s_addr
;
237 B
= ((struct connected
*) b
)->address
->u
.prefix4
.s_addr
;
247 router_id_init (void)
249 install_element (CONFIG_NODE
, &router_id_cmd
);
250 install_element (CONFIG_NODE
, &no_router_id_cmd
);
252 memset (&rid_all_sorted_list
, 0, sizeof (rid_all_sorted_list
));
253 memset (&rid_lo_sorted_list
, 0, sizeof (rid_lo_sorted_list
));
254 memset (&rid_user_assigned
, 0, sizeof (rid_user_assigned
));
256 rid_all_sorted_list
.cmp
= router_id_cmp
;
257 rid_lo_sorted_list
.cmp
= router_id_cmp
;
259 rid_user_assigned
.family
= AF_INET
;
260 rid_user_assigned
.prefixlen
= 32;