paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* zebra client |
| 2 | Copyright (C) 1997, 98, 99 Kunihiro Ishiguro |
| 3 | |
| 4 | This file is part of GNU Zebra. |
| 5 | |
| 6 | GNU Zebra is free software; you can redistribute it and/or modify it |
| 7 | under the terms of the GNU General Public License as published by the |
| 8 | Free Software Foundation; either version 2, or (at your option) any |
| 9 | later version. |
| 10 | |
| 11 | GNU Zebra is distributed in the hope that it will be useful, but |
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with GNU Zebra; see the file COPYING. If not, write to the |
| 18 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 19 | Boston, MA 02111-1307, USA. */ |
| 20 | |
| 21 | #include <zebra.h> |
| 22 | |
| 23 | #include "command.h" |
| 24 | #include "stream.h" |
| 25 | #include "network.h" |
| 26 | #include "prefix.h" |
| 27 | #include "log.h" |
| 28 | #include "sockunion.h" |
| 29 | #include "zclient.h" |
| 30 | #include "routemap.h" |
| 31 | #include "thread.h" |
Donald Sharp | 0490729 | 2016-01-07 10:03:01 -0500 | [diff] [blame] | 32 | #include "filter.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 33 | |
| 34 | #include "bgpd/bgpd.h" |
| 35 | #include "bgpd/bgp_route.h" |
| 36 | #include "bgpd/bgp_attr.h" |
| 37 | #include "bgpd/bgp_nexthop.h" |
| 38 | #include "bgpd/bgp_zebra.h" |
| 39 | #include "bgpd/bgp_fsm.h" |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 40 | #include "bgpd/bgp_debug.h" |
Josh Bailey | 8196f13 | 2011-07-20 20:47:07 -0700 | [diff] [blame] | 41 | #include "bgpd/bgp_mpath.h" |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 42 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 43 | /* All information about zebra. */ |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 44 | struct zclient *zclient = NULL; |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 45 | struct in_addr router_id_zebra; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 46 | |
Josh Bailey | 8196f13 | 2011-07-20 20:47:07 -0700 | [diff] [blame] | 47 | /* Growable buffer for nexthops sent to zebra */ |
| 48 | struct stream *bgp_nexthop_buf = NULL; |
| 49 | |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 50 | /* Router-id update message from zebra. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 51 | static int |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 52 | bgp_router_id_update (int command, struct zclient *zclient, zebra_size_t length, |
| 53 | vrf_id_t vrf_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 54 | { |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 55 | struct prefix router_id; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 56 | struct listnode *node, *nnode; |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 57 | struct bgp *bgp; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 58 | |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 59 | zebra_router_id_update_read(zclient->ibuf,&router_id); |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 60 | |
| 61 | if (BGP_DEBUG(zebra, ZEBRA)) |
| 62 | { |
| 63 | char buf[128]; |
| 64 | prefix2str(&router_id, buf, sizeof(buf)); |
| 65 | zlog_debug("Zebra rcvd: router id update %s", buf); |
| 66 | } |
| 67 | |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 68 | router_id_zebra = router_id.u.prefix4; |
| 69 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 70 | for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 71 | { |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 72 | if (!bgp->router_id_static.s_addr) |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 73 | bgp_router_id_set (bgp, &router_id.u.prefix4); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 74 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 75 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 76 | return 0; |
| 77 | } |
| 78 | |
| 79 | /* Inteface addition message from zebra. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 80 | static int |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 81 | bgp_interface_add (int command, struct zclient *zclient, zebra_size_t length, |
| 82 | vrf_id_t vrf_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 83 | { |
| 84 | struct interface *ifp; |
| 85 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 86 | ifp = zebra_interface_add_read (zclient->ibuf, vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 87 | |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 88 | if (BGP_DEBUG(zebra, ZEBRA) && ifp) |
| 89 | zlog_debug("Zebra rcvd: interface add %s", ifp->name); |
| 90 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 91 | return 0; |
| 92 | } |
| 93 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 94 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 95 | bgp_interface_delete (int command, struct zclient *zclient, |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 96 | zebra_size_t length, vrf_id_t vrf_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 97 | { |
| 98 | struct stream *s; |
| 99 | struct interface *ifp; |
| 100 | |
| 101 | s = zclient->ibuf; |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 102 | ifp = zebra_interface_state_read (s, vrf_id); |
ajs | d2fc889 | 2005-04-02 18:38:43 +0000 | [diff] [blame] | 103 | ifp->ifindex = IFINDEX_INTERNAL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 104 | |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 105 | if (BGP_DEBUG(zebra, ZEBRA)) |
| 106 | zlog_debug("Zebra rcvd: interface delete %s", ifp->name); |
| 107 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 108 | return 0; |
| 109 | } |
| 110 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 111 | static int |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 112 | bgp_interface_up (int command, struct zclient *zclient, zebra_size_t length, |
| 113 | vrf_id_t vrf_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 114 | { |
| 115 | struct stream *s; |
| 116 | struct interface *ifp; |
| 117 | struct connected *c; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 118 | struct listnode *node, *nnode; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 119 | |
| 120 | s = zclient->ibuf; |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 121 | ifp = zebra_interface_state_read (s, vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 122 | |
| 123 | if (! ifp) |
| 124 | return 0; |
| 125 | |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 126 | if (BGP_DEBUG(zebra, ZEBRA)) |
| 127 | zlog_debug("Zebra rcvd: interface %s up", ifp->name); |
| 128 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 129 | for (ALL_LIST_ELEMENTS (ifp->connected, node, nnode, c)) |
| 130 | bgp_connected_add (c); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 131 | |
| 132 | return 0; |
| 133 | } |
| 134 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 135 | static int |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 136 | bgp_interface_down (int command, struct zclient *zclient, zebra_size_t length, |
| 137 | vrf_id_t vrf_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 138 | { |
| 139 | struct stream *s; |
| 140 | struct interface *ifp; |
| 141 | struct connected *c; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 142 | struct listnode *node, *nnode; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 143 | |
| 144 | s = zclient->ibuf; |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 145 | ifp = zebra_interface_state_read (s, vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 146 | if (! ifp) |
| 147 | return 0; |
| 148 | |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 149 | if (BGP_DEBUG(zebra, ZEBRA)) |
| 150 | zlog_debug("Zebra rcvd: interface %s down", ifp->name); |
| 151 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 152 | for (ALL_LIST_ELEMENTS (ifp->connected, node, nnode, c)) |
| 153 | bgp_connected_delete (c); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 154 | |
Pradosh Mohapatra | 8da8689 | 2013-09-11 03:33:55 +0000 | [diff] [blame] | 155 | /* Fast external-failover */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 156 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 157 | struct listnode *mnode; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 158 | struct bgp *bgp; |
| 159 | struct peer *peer; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 160 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 161 | for (ALL_LIST_ELEMENTS_RO (bm->bgp, mnode, bgp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 162 | { |
| 163 | if (CHECK_FLAG (bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER)) |
| 164 | continue; |
| 165 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 166 | for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 167 | { |
Pradosh Mohapatra | 8da8689 | 2013-09-11 03:33:55 +0000 | [diff] [blame] | 168 | if ((peer->ttl != 1) && (peer->gtsm_hops != 1)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 169 | continue; |
| 170 | |
Pradosh Mohapatra | 8da8689 | 2013-09-11 03:33:55 +0000 | [diff] [blame] | 171 | if (ifp == peer->nexthop.ifp) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 172 | BGP_EVENT_ADD (peer, BGP_Stop); |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | return 0; |
| 178 | } |
| 179 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 180 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 181 | bgp_interface_address_add (int command, struct zclient *zclient, |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 182 | zebra_size_t length, vrf_id_t vrf_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 183 | { |
| 184 | struct connected *ifc; |
| 185 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 186 | ifc = zebra_interface_address_read (command, zclient->ibuf, vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 187 | |
| 188 | if (ifc == NULL) |
| 189 | return 0; |
| 190 | |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 191 | if (BGP_DEBUG(zebra, ZEBRA)) |
| 192 | { |
| 193 | char buf[128]; |
| 194 | prefix2str(ifc->address, buf, sizeof(buf)); |
| 195 | zlog_debug("Zebra rcvd: interface %s address add %s", |
| 196 | ifc->ifp->name, buf); |
| 197 | } |
| 198 | |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 199 | if (if_is_operative (ifc->ifp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 200 | bgp_connected_add (ifc); |
| 201 | |
| 202 | return 0; |
| 203 | } |
| 204 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 205 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 206 | bgp_interface_address_delete (int command, struct zclient *zclient, |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 207 | zebra_size_t length, vrf_id_t vrf_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 208 | { |
| 209 | struct connected *ifc; |
| 210 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 211 | ifc = zebra_interface_address_read (command, zclient->ibuf, vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 212 | |
| 213 | if (ifc == NULL) |
| 214 | return 0; |
| 215 | |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 216 | if (BGP_DEBUG(zebra, ZEBRA)) |
| 217 | { |
| 218 | char buf[128]; |
| 219 | prefix2str(ifc->address, buf, sizeof(buf)); |
| 220 | zlog_debug("Zebra rcvd: interface %s address delete %s", |
| 221 | ifc->ifp->name, buf); |
| 222 | } |
| 223 | |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 224 | if (if_is_operative (ifc->ifp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 225 | bgp_connected_delete (ifc); |
| 226 | |
| 227 | connected_free (ifc); |
| 228 | |
| 229 | return 0; |
| 230 | } |
| 231 | |
| 232 | /* Zebra route add and delete treatment. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 233 | static int |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 234 | zebra_read_ipv4 (int command, struct zclient *zclient, zebra_size_t length, |
| 235 | vrf_id_t vrf_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 236 | { |
| 237 | struct stream *s; |
| 238 | struct zapi_ipv4 api; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 239 | struct in_addr nexthop; |
| 240 | struct prefix_ipv4 p; |
| 241 | |
| 242 | s = zclient->ibuf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 243 | nexthop.s_addr = 0; |
| 244 | |
| 245 | /* Type, flags, message. */ |
| 246 | api.type = stream_getc (s); |
| 247 | api.flags = stream_getc (s); |
| 248 | api.message = stream_getc (s); |
| 249 | |
| 250 | /* IPv4 prefix. */ |
| 251 | memset (&p, 0, sizeof (struct prefix_ipv4)); |
| 252 | p.family = AF_INET; |
| 253 | p.prefixlen = stream_getc (s); |
| 254 | stream_get (&p.prefix, s, PSIZE (p.prefixlen)); |
| 255 | |
| 256 | /* Nexthop, ifindex, distance, metric. */ |
| 257 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP)) |
| 258 | { |
| 259 | api.nexthop_num = stream_getc (s); |
| 260 | nexthop.s_addr = stream_get_ipv4 (s); |
| 261 | } |
| 262 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX)) |
| 263 | { |
| 264 | api.ifindex_num = stream_getc (s); |
Stephen Hemminger | 9206f9e | 2011-12-18 19:43:40 +0400 | [diff] [blame] | 265 | stream_getl (s); /* ifindex, unused */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 266 | } |
| 267 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE)) |
| 268 | api.distance = stream_getc (s); |
| 269 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC)) |
| 270 | api.metric = stream_getl (s); |
| 271 | else |
| 272 | api.metric = 0; |
| 273 | |
| 274 | if (command == ZEBRA_IPV4_ROUTE_ADD) |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 275 | { |
| 276 | if (BGP_DEBUG(zebra, ZEBRA)) |
| 277 | { |
| 278 | char buf[2][INET_ADDRSTRLEN]; |
| 279 | zlog_debug("Zebra rcvd: IPv4 route add %s %s/%d nexthop %s metric %u", |
| 280 | zebra_route_string(api.type), |
| 281 | inet_ntop(AF_INET, &p.prefix, buf[0], sizeof(buf[0])), |
| 282 | p.prefixlen, |
| 283 | inet_ntop(AF_INET, &nexthop, buf[1], sizeof(buf[1])), |
| 284 | api.metric); |
| 285 | } |
Stephen Hemminger | f04a80a | 2011-12-06 14:51:10 +0400 | [diff] [blame] | 286 | bgp_redistribute_add((struct prefix *)&p, &nexthop, NULL, |
| 287 | api.metric, api.type); |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 288 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 289 | else |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 290 | { |
| 291 | if (BGP_DEBUG(zebra, ZEBRA)) |
| 292 | { |
| 293 | char buf[2][INET_ADDRSTRLEN]; |
| 294 | zlog_debug("Zebra rcvd: IPv4 route delete %s %s/%d " |
| 295 | "nexthop %s metric %u", |
| 296 | zebra_route_string(api.type), |
| 297 | inet_ntop(AF_INET, &p.prefix, buf[0], sizeof(buf[0])), |
| 298 | p.prefixlen, |
| 299 | inet_ntop(AF_INET, &nexthop, buf[1], sizeof(buf[1])), |
| 300 | api.metric); |
| 301 | } |
| 302 | bgp_redistribute_delete((struct prefix *)&p, api.type); |
| 303 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 304 | |
| 305 | return 0; |
| 306 | } |
| 307 | |
| 308 | #ifdef HAVE_IPV6 |
| 309 | /* Zebra route add and delete treatment. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 310 | static int |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 311 | zebra_read_ipv6 (int command, struct zclient *zclient, zebra_size_t length, |
| 312 | vrf_id_t vrf_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 313 | { |
| 314 | struct stream *s; |
| 315 | struct zapi_ipv6 api; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 316 | struct in6_addr nexthop; |
| 317 | struct prefix_ipv6 p; |
| 318 | |
| 319 | s = zclient->ibuf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 320 | memset (&nexthop, 0, sizeof (struct in6_addr)); |
| 321 | |
| 322 | /* Type, flags, message. */ |
| 323 | api.type = stream_getc (s); |
| 324 | api.flags = stream_getc (s); |
| 325 | api.message = stream_getc (s); |
| 326 | |
| 327 | /* IPv6 prefix. */ |
| 328 | memset (&p, 0, sizeof (struct prefix_ipv6)); |
| 329 | p.family = AF_INET6; |
| 330 | p.prefixlen = stream_getc (s); |
| 331 | stream_get (&p.prefix, s, PSIZE (p.prefixlen)); |
| 332 | |
| 333 | /* Nexthop, ifindex, distance, metric. */ |
| 334 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP)) |
| 335 | { |
| 336 | api.nexthop_num = stream_getc (s); |
| 337 | stream_get (&nexthop, s, 16); |
| 338 | } |
| 339 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX)) |
| 340 | { |
| 341 | api.ifindex_num = stream_getc (s); |
Stephen Hemminger | 9206f9e | 2011-12-18 19:43:40 +0400 | [diff] [blame] | 342 | stream_getl (s); /* ifindex, unused */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 343 | } |
| 344 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE)) |
| 345 | api.distance = stream_getc (s); |
| 346 | else |
| 347 | api.distance = 0; |
| 348 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC)) |
| 349 | api.metric = stream_getl (s); |
| 350 | else |
| 351 | api.metric = 0; |
| 352 | |
| 353 | /* Simply ignore link-local address. */ |
| 354 | if (IN6_IS_ADDR_LINKLOCAL (&p.prefix)) |
| 355 | return 0; |
| 356 | |
| 357 | if (command == ZEBRA_IPV6_ROUTE_ADD) |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 358 | { |
| 359 | if (BGP_DEBUG(zebra, ZEBRA)) |
| 360 | { |
Stephen Hemminger | f04a80a | 2011-12-06 14:51:10 +0400 | [diff] [blame] | 361 | char buf[2][INET6_ADDRSTRLEN]; |
| 362 | zlog_debug("Zebra rcvd: IPv6 route add %s %s/%d nexthop %s metric %u", |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 363 | zebra_route_string(api.type), |
Stephen Hemminger | f04a80a | 2011-12-06 14:51:10 +0400 | [diff] [blame] | 364 | inet_ntop(AF_INET6, &p.prefix, buf[0], sizeof(buf[0])), |
| 365 | p.prefixlen, |
| 366 | inet_ntop(AF_INET, &nexthop, buf[1], sizeof(buf[1])), |
| 367 | api.metric); |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 368 | } |
Stephen Hemminger | f04a80a | 2011-12-06 14:51:10 +0400 | [diff] [blame] | 369 | bgp_redistribute_add ((struct prefix *)&p, NULL, &nexthop, |
| 370 | api.metric, api.type); |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 371 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 372 | else |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 373 | { |
| 374 | if (BGP_DEBUG(zebra, ZEBRA)) |
| 375 | { |
Stephen Hemminger | f04a80a | 2011-12-06 14:51:10 +0400 | [diff] [blame] | 376 | char buf[2][INET6_ADDRSTRLEN]; |
| 377 | zlog_debug("Zebra rcvd: IPv6 route delete %s %s/%d " |
| 378 | "nexthop %s metric %u", |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 379 | zebra_route_string(api.type), |
Stephen Hemminger | f04a80a | 2011-12-06 14:51:10 +0400 | [diff] [blame] | 380 | inet_ntop(AF_INET6, &p.prefix, buf[0], sizeof(buf[0])), |
| 381 | p.prefixlen, |
| 382 | inet_ntop(AF_INET6, &nexthop, buf[1], sizeof(buf[1])), |
| 383 | api.metric); |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 384 | } |
| 385 | bgp_redistribute_delete ((struct prefix *) &p, api.type); |
| 386 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 387 | |
| 388 | return 0; |
| 389 | } |
| 390 | #endif /* HAVE_IPV6 */ |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 391 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 392 | struct interface * |
| 393 | if_lookup_by_ipv4 (struct in_addr *addr) |
| 394 | { |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 395 | struct listnode *ifnode; |
| 396 | struct listnode *cnode; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 397 | struct interface *ifp; |
| 398 | struct connected *connected; |
| 399 | struct prefix_ipv4 p; |
| 400 | struct prefix *cp; |
| 401 | |
| 402 | p.family = AF_INET; |
| 403 | p.prefix = *addr; |
| 404 | p.prefixlen = IPV4_MAX_BITLEN; |
| 405 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 406 | for (ALL_LIST_ELEMENTS_RO (iflist, ifnode, ifp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 407 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 408 | for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 409 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 410 | cp = connected->address; |
| 411 | |
| 412 | if (cp->family == AF_INET) |
| 413 | if (prefix_match (cp, (struct prefix *)&p)) |
| 414 | return ifp; |
| 415 | } |
| 416 | } |
| 417 | return NULL; |
| 418 | } |
| 419 | |
| 420 | struct interface * |
| 421 | if_lookup_by_ipv4_exact (struct in_addr *addr) |
| 422 | { |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 423 | struct listnode *ifnode; |
| 424 | struct listnode *cnode; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 425 | struct interface *ifp; |
| 426 | struct connected *connected; |
| 427 | struct prefix *cp; |
| 428 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 429 | for (ALL_LIST_ELEMENTS_RO (iflist, ifnode, ifp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 430 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 431 | for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 432 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 433 | cp = connected->address; |
| 434 | |
| 435 | if (cp->family == AF_INET) |
| 436 | if (IPV4_ADDR_SAME (&cp->u.prefix4, addr)) |
| 437 | return ifp; |
| 438 | } |
| 439 | } |
| 440 | return NULL; |
| 441 | } |
| 442 | |
| 443 | #ifdef HAVE_IPV6 |
| 444 | struct interface * |
| 445 | if_lookup_by_ipv6 (struct in6_addr *addr) |
| 446 | { |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 447 | struct listnode *ifnode; |
| 448 | struct listnode *cnode; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 449 | struct interface *ifp; |
| 450 | struct connected *connected; |
| 451 | struct prefix_ipv6 p; |
| 452 | struct prefix *cp; |
| 453 | |
| 454 | p.family = AF_INET6; |
| 455 | p.prefix = *addr; |
| 456 | p.prefixlen = IPV6_MAX_BITLEN; |
| 457 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 458 | for (ALL_LIST_ELEMENTS_RO (iflist, ifnode, ifp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 459 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 460 | for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 461 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 462 | cp = connected->address; |
| 463 | |
| 464 | if (cp->family == AF_INET6) |
| 465 | if (prefix_match (cp, (struct prefix *)&p)) |
| 466 | return ifp; |
| 467 | } |
| 468 | } |
| 469 | return NULL; |
| 470 | } |
| 471 | |
| 472 | struct interface * |
| 473 | if_lookup_by_ipv6_exact (struct in6_addr *addr) |
| 474 | { |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 475 | struct listnode *ifnode; |
| 476 | struct listnode *cnode; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 477 | struct interface *ifp; |
| 478 | struct connected *connected; |
| 479 | struct prefix *cp; |
| 480 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 481 | for (ALL_LIST_ELEMENTS_RO (iflist, ifnode, ifp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 482 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 483 | for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 484 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 485 | cp = connected->address; |
| 486 | |
| 487 | if (cp->family == AF_INET6) |
| 488 | if (IPV6_ADDR_SAME (&cp->u.prefix6, addr)) |
| 489 | return ifp; |
| 490 | } |
| 491 | } |
| 492 | return NULL; |
| 493 | } |
| 494 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 495 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 496 | if_get_ipv6_global (struct interface *ifp, struct in6_addr *addr) |
| 497 | { |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 498 | struct listnode *cnode; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 499 | struct connected *connected; |
| 500 | struct prefix *cp; |
| 501 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 502 | for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 503 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 504 | cp = connected->address; |
| 505 | |
| 506 | if (cp->family == AF_INET6) |
| 507 | if (! IN6_IS_ADDR_LINKLOCAL (&cp->u.prefix6)) |
| 508 | { |
| 509 | memcpy (addr, &cp->u.prefix6, IPV6_MAX_BYTELEN); |
| 510 | return 1; |
| 511 | } |
| 512 | } |
| 513 | return 0; |
| 514 | } |
| 515 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 516 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 517 | if_get_ipv6_local (struct interface *ifp, struct in6_addr *addr) |
| 518 | { |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 519 | struct listnode *cnode; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 520 | struct connected *connected; |
| 521 | struct prefix *cp; |
| 522 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 523 | for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 524 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 525 | cp = connected->address; |
| 526 | |
| 527 | if (cp->family == AF_INET6) |
| 528 | if (IN6_IS_ADDR_LINKLOCAL (&cp->u.prefix6)) |
| 529 | { |
| 530 | memcpy (addr, &cp->u.prefix6, IPV6_MAX_BYTELEN); |
| 531 | return 1; |
| 532 | } |
| 533 | } |
| 534 | return 0; |
| 535 | } |
| 536 | #endif /* HAVE_IPV6 */ |
| 537 | |
Pradosh Mohapatra | 6ee06fa | 2014-01-12 18:30:13 +0000 | [diff] [blame] | 538 | static int |
| 539 | if_get_ipv4_address (struct interface *ifp, struct in_addr *addr) |
| 540 | { |
| 541 | struct listnode *cnode; |
| 542 | struct connected *connected; |
| 543 | struct prefix *cp; |
| 544 | |
| 545 | for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected)) |
| 546 | { |
| 547 | cp = connected->address; |
| 548 | if ((cp->family == AF_INET) && !ipv4_martian(&(cp->u.prefix4))) |
| 549 | { |
| 550 | *addr = cp->u.prefix4; |
| 551 | return 1; |
| 552 | } |
| 553 | } |
| 554 | return 0; |
| 555 | } |
| 556 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 557 | int |
| 558 | bgp_nexthop_set (union sockunion *local, union sockunion *remote, |
| 559 | struct bgp_nexthop *nexthop, struct peer *peer) |
| 560 | { |
| 561 | int ret = 0; |
| 562 | struct interface *ifp = NULL; |
| 563 | |
| 564 | memset (nexthop, 0, sizeof (struct bgp_nexthop)); |
| 565 | |
| 566 | if (!local) |
| 567 | return -1; |
| 568 | if (!remote) |
| 569 | return -1; |
| 570 | |
| 571 | if (local->sa.sa_family == AF_INET) |
| 572 | { |
| 573 | nexthop->v4 = local->sin.sin_addr; |
| 574 | ifp = if_lookup_by_ipv4 (&local->sin.sin_addr); |
| 575 | } |
| 576 | #ifdef HAVE_IPV6 |
| 577 | if (local->sa.sa_family == AF_INET6) |
| 578 | { |
| 579 | if (IN6_IS_ADDR_LINKLOCAL (&local->sin6.sin6_addr)) |
| 580 | { |
| 581 | if (peer->ifname) |
Feng Lu | 395828e | 2015-05-22 11:39:55 +0200 | [diff] [blame] | 582 | ifp = if_lookup_by_name (peer->ifname); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 583 | } |
| 584 | else |
| 585 | ifp = if_lookup_by_ipv6 (&local->sin6.sin6_addr); |
| 586 | } |
| 587 | #endif /* HAVE_IPV6 */ |
| 588 | |
| 589 | if (!ifp) |
| 590 | return -1; |
| 591 | |
| 592 | nexthop->ifp = ifp; |
| 593 | |
| 594 | /* IPv4 connection. */ |
| 595 | if (local->sa.sa_family == AF_INET) |
| 596 | { |
| 597 | #ifdef HAVE_IPV6 |
| 598 | /* IPv6 nexthop*/ |
| 599 | ret = if_get_ipv6_global (ifp, &nexthop->v6_global); |
| 600 | |
| 601 | /* There is no global nexthop. */ |
| 602 | if (!ret) |
| 603 | if_get_ipv6_local (ifp, &nexthop->v6_global); |
| 604 | else |
| 605 | if_get_ipv6_local (ifp, &nexthop->v6_local); |
| 606 | #endif /* HAVE_IPV6 */ |
| 607 | } |
| 608 | |
| 609 | #ifdef HAVE_IPV6 |
| 610 | /* IPv6 connection. */ |
| 611 | if (local->sa.sa_family == AF_INET6) |
| 612 | { |
| 613 | struct interface *direct = NULL; |
| 614 | |
Pradosh Mohapatra | 6ee06fa | 2014-01-12 18:30:13 +0000 | [diff] [blame] | 615 | /* IPv4 nexthop. */ |
| 616 | ret = if_get_ipv4_address(ifp, &nexthop->v4); |
| 617 | if (!ret && peer->local_id.s_addr) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 618 | nexthop->v4 = peer->local_id; |
| 619 | |
| 620 | /* Global address*/ |
| 621 | if (! IN6_IS_ADDR_LINKLOCAL (&local->sin6.sin6_addr)) |
| 622 | { |
| 623 | memcpy (&nexthop->v6_global, &local->sin6.sin6_addr, |
| 624 | IPV6_MAX_BYTELEN); |
| 625 | |
| 626 | /* If directory connected set link-local address. */ |
| 627 | direct = if_lookup_by_ipv6 (&remote->sin6.sin6_addr); |
| 628 | if (direct) |
| 629 | if_get_ipv6_local (ifp, &nexthop->v6_local); |
| 630 | } |
| 631 | else |
| 632 | /* Link-local address. */ |
| 633 | { |
| 634 | ret = if_get_ipv6_global (ifp, &nexthop->v6_global); |
| 635 | |
| 636 | /* If there is no global address. Set link-local address as |
| 637 | global. I know this break RFC specification... */ |
| 638 | if (!ret) |
| 639 | memcpy (&nexthop->v6_global, &local->sin6.sin6_addr, |
| 640 | IPV6_MAX_BYTELEN); |
| 641 | else |
| 642 | memcpy (&nexthop->v6_local, &local->sin6.sin6_addr, |
| 643 | IPV6_MAX_BYTELEN); |
| 644 | } |
| 645 | } |
| 646 | |
| 647 | if (IN6_IS_ADDR_LINKLOCAL (&local->sin6.sin6_addr) || |
| 648 | if_lookup_by_ipv6 (&remote->sin6.sin6_addr)) |
| 649 | peer->shared_network = 1; |
| 650 | else |
| 651 | peer->shared_network = 0; |
| 652 | |
| 653 | /* KAME stack specific treatment. */ |
| 654 | #ifdef KAME |
| 655 | if (IN6_IS_ADDR_LINKLOCAL (&nexthop->v6_global) |
| 656 | && IN6_LINKLOCAL_IFINDEX (nexthop->v6_global)) |
| 657 | { |
| 658 | SET_IN6_LINKLOCAL_IFINDEX (nexthop->v6_global, 0); |
| 659 | } |
| 660 | if (IN6_IS_ADDR_LINKLOCAL (&nexthop->v6_local) |
| 661 | && IN6_LINKLOCAL_IFINDEX (nexthop->v6_local)) |
| 662 | { |
| 663 | SET_IN6_LINKLOCAL_IFINDEX (nexthop->v6_local, 0); |
| 664 | } |
| 665 | #endif /* KAME */ |
| 666 | #endif /* HAVE_IPV6 */ |
| 667 | return ret; |
| 668 | } |
| 669 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 670 | void |
G.Balaji | 5a616c0 | 2011-11-26 21:58:42 +0400 | [diff] [blame] | 671 | bgp_zebra_announce (struct prefix *p, struct bgp_info *info, struct bgp *bgp, safi_t safi) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 672 | { |
| 673 | int flags; |
| 674 | u_char distance; |
| 675 | struct peer *peer; |
Josh Bailey | 8196f13 | 2011-07-20 20:47:07 -0700 | [diff] [blame] | 676 | struct bgp_info *mpinfo; |
| 677 | size_t oldsize, newsize; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 678 | |
| 679 | if (zclient->sock < 0) |
| 680 | return; |
| 681 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 682 | if (! vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_BGP], VRF_DEFAULT)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 683 | return; |
| 684 | |
| 685 | flags = 0; |
| 686 | peer = info->peer; |
| 687 | |
Jorge Boncompte [DTI2] | 6d85b15 | 2012-05-07 16:52:54 +0000 | [diff] [blame] | 688 | if (peer->sort == BGP_PEER_IBGP || peer->sort == BGP_PEER_CONFED) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 689 | { |
| 690 | SET_FLAG (flags, ZEBRA_FLAG_IBGP); |
| 691 | SET_FLAG (flags, ZEBRA_FLAG_INTERNAL); |
| 692 | } |
| 693 | |
Jorge Boncompte [DTI2] | 6d85b15 | 2012-05-07 16:52:54 +0000 | [diff] [blame] | 694 | if ((peer->sort == BGP_PEER_EBGP && peer->ttl != 1) |
hasso | 6ffd207 | 2005-02-02 14:50:11 +0000 | [diff] [blame] | 695 | || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 696 | SET_FLAG (flags, ZEBRA_FLAG_INTERNAL); |
| 697 | |
Josh Bailey | 8196f13 | 2011-07-20 20:47:07 -0700 | [diff] [blame] | 698 | /* resize nexthop buffer size if necessary */ |
| 699 | if ((oldsize = stream_get_size (bgp_nexthop_buf)) < |
| 700 | (sizeof (struct in_addr *) * (bgp_info_mpath_count (info) + 1))) |
| 701 | { |
| 702 | newsize = (sizeof (struct in_addr *) * (bgp_info_mpath_count (info) + 1)); |
| 703 | newsize = stream_resize (bgp_nexthop_buf, newsize); |
| 704 | if (newsize == oldsize) |
| 705 | { |
| 706 | zlog_err ("can't resize nexthop buffer"); |
| 707 | return; |
| 708 | } |
| 709 | } |
| 710 | |
| 711 | stream_reset (bgp_nexthop_buf); |
| 712 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 713 | if (p->family == AF_INET) |
| 714 | { |
| 715 | struct zapi_ipv4 api; |
| 716 | struct in_addr *nexthop; |
| 717 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 718 | api.vrf_id = VRF_DEFAULT; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 719 | api.flags = flags; |
| 720 | nexthop = &info->attr->nexthop; |
Josh Bailey | 8196f13 | 2011-07-20 20:47:07 -0700 | [diff] [blame] | 721 | stream_put (bgp_nexthop_buf, &nexthop, sizeof (struct in_addr *)); |
| 722 | for (mpinfo = bgp_info_mpath_first (info); mpinfo; |
| 723 | mpinfo = bgp_info_mpath_next (mpinfo)) |
| 724 | { |
| 725 | nexthop = &mpinfo->attr->nexthop; |
| 726 | stream_put (bgp_nexthop_buf, &nexthop, sizeof (struct in_addr *)); |
| 727 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 728 | |
| 729 | api.type = ZEBRA_ROUTE_BGP; |
| 730 | api.message = 0; |
G.Balaji | 5a616c0 | 2011-11-26 21:58:42 +0400 | [diff] [blame] | 731 | api.safi = safi; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 732 | SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); |
Josh Bailey | 8196f13 | 2011-07-20 20:47:07 -0700 | [diff] [blame] | 733 | api.nexthop_num = 1 + bgp_info_mpath_count (info); |
| 734 | api.nexthop = (struct in_addr **)STREAM_DATA (bgp_nexthop_buf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 735 | api.ifindex_num = 0; |
| 736 | SET_FLAG (api.message, ZAPI_MESSAGE_METRIC); |
| 737 | api.metric = info->attr->med; |
| 738 | |
| 739 | distance = bgp_distance_apply (p, info, bgp); |
| 740 | |
| 741 | if (distance) |
| 742 | { |
| 743 | SET_FLAG (api.message, ZAPI_MESSAGE_DISTANCE); |
| 744 | api.distance = distance; |
| 745 | } |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 746 | |
| 747 | if (BGP_DEBUG(zebra, ZEBRA)) |
| 748 | { |
Josh Bailey | 8196f13 | 2011-07-20 20:47:07 -0700 | [diff] [blame] | 749 | int i; |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 750 | char buf[2][INET_ADDRSTRLEN]; |
Josh Bailey | 8196f13 | 2011-07-20 20:47:07 -0700 | [diff] [blame] | 751 | zlog_debug("Zebra send: IPv4 route add %s/%d nexthop %s metric %u" |
| 752 | " count %d", |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 753 | inet_ntop(AF_INET, &p->u.prefix4, buf[0], sizeof(buf[0])), |
| 754 | p->prefixlen, |
Josh Bailey | 8196f13 | 2011-07-20 20:47:07 -0700 | [diff] [blame] | 755 | inet_ntop(AF_INET, api.nexthop[0], buf[1], sizeof(buf[1])), |
| 756 | api.metric, api.nexthop_num); |
| 757 | for (i = 1; i < api.nexthop_num; i++) |
| 758 | zlog_debug("Zebra send: IPv4 route add [nexthop %d] %s", |
| 759 | i, inet_ntop(AF_INET, api.nexthop[i], buf[1], |
| 760 | sizeof(buf[1]))); |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 761 | } |
| 762 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 763 | zapi_ipv4_route (ZEBRA_IPV4_ROUTE_ADD, zclient, |
| 764 | (struct prefix_ipv4 *) p, &api); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 765 | } |
| 766 | #ifdef HAVE_IPV6 |
| 767 | /* We have to think about a IPv6 link-local address curse. */ |
| 768 | if (p->family == AF_INET6) |
| 769 | { |
| 770 | unsigned int ifindex; |
| 771 | struct in6_addr *nexthop; |
| 772 | struct zapi_ipv6 api; |
| 773 | |
| 774 | ifindex = 0; |
| 775 | nexthop = NULL; |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 776 | |
| 777 | assert (info->attr->extra); |
| 778 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 779 | /* Only global address nexthop exists. */ |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 780 | if (info->attr->extra->mp_nexthop_len == 16) |
| 781 | nexthop = &info->attr->extra->mp_nexthop_global; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 782 | |
| 783 | /* If both global and link-local address present. */ |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 784 | if (info->attr->extra->mp_nexthop_len == 32) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 785 | { |
| 786 | /* Workaround for Cisco's nexthop bug. */ |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 787 | if (IN6_IS_ADDR_UNSPECIFIED (&info->attr->extra->mp_nexthop_global) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 788 | && peer->su_remote->sa.sa_family == AF_INET6) |
| 789 | nexthop = &peer->su_remote->sin6.sin6_addr; |
| 790 | else |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 791 | nexthop = &info->attr->extra->mp_nexthop_local; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 792 | |
| 793 | if (info->peer->nexthop.ifp) |
| 794 | ifindex = info->peer->nexthop.ifp->ifindex; |
| 795 | } |
| 796 | |
| 797 | if (nexthop == NULL) |
| 798 | return; |
| 799 | |
| 800 | if (IN6_IS_ADDR_LINKLOCAL (nexthop) && ! ifindex) |
| 801 | { |
| 802 | if (info->peer->ifname) |
Feng Lu | 395828e | 2015-05-22 11:39:55 +0200 | [diff] [blame] | 803 | ifindex = ifname2ifindex (info->peer->ifname); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 804 | else if (info->peer->nexthop.ifp) |
| 805 | ifindex = info->peer->nexthop.ifp->ifindex; |
| 806 | } |
| 807 | |
| 808 | /* Make Zebra API structure. */ |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 809 | api.vrf_id = VRF_DEFAULT; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 810 | api.flags = flags; |
| 811 | api.type = ZEBRA_ROUTE_BGP; |
| 812 | api.message = 0; |
G.Balaji | c7ec179 | 2011-11-26 22:04:05 +0400 | [diff] [blame] | 813 | api.safi = safi; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 814 | SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); |
| 815 | api.nexthop_num = 1; |
| 816 | api.nexthop = &nexthop; |
| 817 | SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX); |
| 818 | api.ifindex_num = 1; |
| 819 | api.ifindex = &ifindex; |
| 820 | SET_FLAG (api.message, ZAPI_MESSAGE_METRIC); |
| 821 | api.metric = info->attr->med; |
| 822 | |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 823 | if (BGP_DEBUG(zebra, ZEBRA)) |
| 824 | { |
| 825 | char buf[2][INET6_ADDRSTRLEN]; |
| 826 | zlog_debug("Zebra send: IPv6 route add %s/%d nexthop %s metric %u", |
| 827 | inet_ntop(AF_INET6, &p->u.prefix6, buf[0], sizeof(buf[0])), |
| 828 | p->prefixlen, |
| 829 | inet_ntop(AF_INET6, nexthop, buf[1], sizeof(buf[1])), |
| 830 | api.metric); |
| 831 | } |
| 832 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 833 | zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD, zclient, |
| 834 | (struct prefix_ipv6 *) p, &api); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 835 | } |
| 836 | #endif /* HAVE_IPV6 */ |
| 837 | } |
| 838 | |
| 839 | void |
G.Balaji | 5a616c0 | 2011-11-26 21:58:42 +0400 | [diff] [blame] | 840 | bgp_zebra_withdraw (struct prefix *p, struct bgp_info *info, safi_t safi) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 841 | { |
| 842 | int flags; |
| 843 | struct peer *peer; |
| 844 | |
| 845 | if (zclient->sock < 0) |
| 846 | return; |
| 847 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 848 | if (! vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_BGP], VRF_DEFAULT)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 849 | return; |
| 850 | |
| 851 | peer = info->peer; |
| 852 | flags = 0; |
| 853 | |
Jorge Boncompte [DTI2] | 6d85b15 | 2012-05-07 16:52:54 +0000 | [diff] [blame] | 854 | if (peer->sort == BGP_PEER_IBGP) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 855 | { |
| 856 | SET_FLAG (flags, ZEBRA_FLAG_INTERNAL); |
| 857 | SET_FLAG (flags, ZEBRA_FLAG_IBGP); |
| 858 | } |
| 859 | |
Jorge Boncompte [DTI2] | 6d85b15 | 2012-05-07 16:52:54 +0000 | [diff] [blame] | 860 | if ((peer->sort == BGP_PEER_EBGP && peer->ttl != 1) |
hasso | 6ffd207 | 2005-02-02 14:50:11 +0000 | [diff] [blame] | 861 | || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 862 | SET_FLAG (flags, ZEBRA_FLAG_INTERNAL); |
| 863 | |
| 864 | if (p->family == AF_INET) |
| 865 | { |
| 866 | struct zapi_ipv4 api; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 867 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 868 | api.vrf_id = VRF_DEFAULT; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 869 | api.flags = flags; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 870 | |
| 871 | api.type = ZEBRA_ROUTE_BGP; |
| 872 | api.message = 0; |
G.Balaji | 5a616c0 | 2011-11-26 21:58:42 +0400 | [diff] [blame] | 873 | api.safi = safi; |
Paul Jakma | 64e0ac2 | 2015-11-18 16:00:54 +0000 | [diff] [blame] | 874 | api.nexthop_num = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 875 | api.ifindex_num = 0; |
| 876 | SET_FLAG (api.message, ZAPI_MESSAGE_METRIC); |
| 877 | api.metric = info->attr->med; |
| 878 | |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 879 | if (BGP_DEBUG(zebra, ZEBRA)) |
| 880 | { |
| 881 | char buf[2][INET_ADDRSTRLEN]; |
Paul Jakma | 64e0ac2 | 2015-11-18 16:00:54 +0000 | [diff] [blame] | 882 | zlog_debug("Zebra send: IPv4 route delete %s/%d metric %u", |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 883 | inet_ntop(AF_INET, &p->u.prefix4, buf[0], sizeof(buf[0])), |
| 884 | p->prefixlen, |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 885 | api.metric); |
| 886 | } |
| 887 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 888 | zapi_ipv4_route (ZEBRA_IPV4_ROUTE_DELETE, zclient, |
| 889 | (struct prefix_ipv4 *) p, &api); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 890 | } |
| 891 | #ifdef HAVE_IPV6 |
| 892 | /* We have to think about a IPv6 link-local address curse. */ |
| 893 | if (p->family == AF_INET6) |
| 894 | { |
| 895 | struct zapi_ipv6 api; |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 896 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 897 | api.vrf_id = VRF_DEFAULT; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 898 | api.flags = flags; |
| 899 | api.type = ZEBRA_ROUTE_BGP; |
| 900 | api.message = 0; |
G.Balaji | c7ec179 | 2011-11-26 22:04:05 +0400 | [diff] [blame] | 901 | api.safi = safi; |
Paul Jakma | 64e0ac2 | 2015-11-18 16:00:54 +0000 | [diff] [blame] | 902 | api.nexthop_num = 0; |
| 903 | api.ifindex_num = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 904 | SET_FLAG (api.message, ZAPI_MESSAGE_METRIC); |
| 905 | api.metric = info->attr->med; |
| 906 | |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 907 | if (BGP_DEBUG(zebra, ZEBRA)) |
| 908 | { |
| 909 | char buf[2][INET6_ADDRSTRLEN]; |
Paul Jakma | 64e0ac2 | 2015-11-18 16:00:54 +0000 | [diff] [blame] | 910 | zlog_debug("Zebra send: IPv6 route delete %s/%d metric %u", |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 911 | inet_ntop(AF_INET6, &p->u.prefix6, buf[0], sizeof(buf[0])), |
| 912 | p->prefixlen, |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 913 | api.metric); |
| 914 | } |
| 915 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 916 | zapi_ipv6_route (ZEBRA_IPV6_ROUTE_DELETE, zclient, |
| 917 | (struct prefix_ipv6 *) p, &api); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 918 | } |
| 919 | #endif /* HAVE_IPV6 */ |
| 920 | } |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 921 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 922 | /* Other routes redistribution into BGP. */ |
| 923 | int |
| 924 | bgp_redistribute_set (struct bgp *bgp, afi_t afi, int type) |
| 925 | { |
| 926 | /* Set flag to BGP instance. */ |
| 927 | bgp->redist[afi][type] = 1; |
| 928 | |
| 929 | /* Return if already redistribute flag is set. */ |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 930 | if (vrf_bitmap_check (zclient->redist[type], VRF_DEFAULT)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 931 | return CMD_WARNING; |
| 932 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 933 | vrf_bitmap_set (zclient->redist[type], VRF_DEFAULT); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 934 | |
| 935 | /* Return if zebra connection is not established. */ |
| 936 | if (zclient->sock < 0) |
| 937 | return CMD_WARNING; |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 938 | |
| 939 | if (BGP_DEBUG(zebra, ZEBRA)) |
| 940 | zlog_debug("Zebra send: redistribute add %s", zebra_route_string(type)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 941 | |
| 942 | /* Send distribute add message to zebra. */ |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 943 | zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, type, VRF_DEFAULT); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 944 | |
| 945 | return CMD_SUCCESS; |
| 946 | } |
| 947 | |
| 948 | /* Redistribute with route-map specification. */ |
| 949 | int |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 950 | bgp_redistribute_rmap_set (struct bgp *bgp, afi_t afi, int type, |
| 951 | const char *name) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 952 | { |
| 953 | if (bgp->rmap[afi][type].name |
| 954 | && (strcmp (bgp->rmap[afi][type].name, name) == 0)) |
| 955 | return 0; |
| 956 | |
| 957 | if (bgp->rmap[afi][type].name) |
| 958 | free (bgp->rmap[afi][type].name); |
| 959 | bgp->rmap[afi][type].name = strdup (name); |
| 960 | bgp->rmap[afi][type].map = route_map_lookup_by_name (name); |
| 961 | |
| 962 | return 1; |
| 963 | } |
| 964 | |
| 965 | /* Redistribute with metric specification. */ |
| 966 | int |
| 967 | bgp_redistribute_metric_set (struct bgp *bgp, afi_t afi, int type, |
| 968 | u_int32_t metric) |
| 969 | { |
| 970 | if (bgp->redist_metric_flag[afi][type] |
| 971 | && bgp->redist_metric[afi][type] == metric) |
| 972 | return 0; |
| 973 | |
| 974 | bgp->redist_metric_flag[afi][type] = 1; |
| 975 | bgp->redist_metric[afi][type] = metric; |
| 976 | |
| 977 | return 1; |
| 978 | } |
| 979 | |
| 980 | /* Unset redistribution. */ |
| 981 | int |
| 982 | bgp_redistribute_unset (struct bgp *bgp, afi_t afi, int type) |
| 983 | { |
| 984 | /* Unset flag from BGP instance. */ |
| 985 | bgp->redist[afi][type] = 0; |
| 986 | |
| 987 | /* Unset route-map. */ |
| 988 | if (bgp->rmap[afi][type].name) |
| 989 | free (bgp->rmap[afi][type].name); |
| 990 | bgp->rmap[afi][type].name = NULL; |
| 991 | bgp->rmap[afi][type].map = NULL; |
| 992 | |
| 993 | /* Unset metric. */ |
| 994 | bgp->redist_metric_flag[afi][type] = 0; |
| 995 | bgp->redist_metric[afi][type] = 0; |
| 996 | |
| 997 | /* Return if zebra connection is disabled. */ |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 998 | if (! vrf_bitmap_check (zclient->redist[type], VRF_DEFAULT)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 999 | return CMD_WARNING; |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1000 | vrf_bitmap_unset (zclient->redist[type], VRF_DEFAULT); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1001 | |
| 1002 | if (bgp->redist[AFI_IP][type] == 0 |
| 1003 | && bgp->redist[AFI_IP6][type] == 0 |
| 1004 | && zclient->sock >= 0) |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 1005 | { |
| 1006 | /* Send distribute delete message to zebra. */ |
| 1007 | if (BGP_DEBUG(zebra, ZEBRA)) |
| 1008 | zlog_debug("Zebra send: redistribute delete %s", |
| 1009 | zebra_route_string(type)); |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1010 | zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, type, |
| 1011 | VRF_DEFAULT); |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 1012 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1013 | |
| 1014 | /* Withdraw redistributed routes from current BGP's routing table. */ |
| 1015 | bgp_redistribute_withdraw (bgp, afi, type); |
| 1016 | |
| 1017 | return CMD_SUCCESS; |
| 1018 | } |
| 1019 | |
| 1020 | /* Unset redistribution route-map configuration. */ |
| 1021 | int |
| 1022 | bgp_redistribute_routemap_unset (struct bgp *bgp, afi_t afi, int type) |
| 1023 | { |
| 1024 | if (! bgp->rmap[afi][type].name) |
| 1025 | return 0; |
| 1026 | |
| 1027 | /* Unset route-map. */ |
| 1028 | free (bgp->rmap[afi][type].name); |
| 1029 | bgp->rmap[afi][type].name = NULL; |
| 1030 | bgp->rmap[afi][type].map = NULL; |
| 1031 | |
| 1032 | return 1; |
| 1033 | } |
| 1034 | |
| 1035 | /* Unset redistribution metric configuration. */ |
| 1036 | int |
| 1037 | bgp_redistribute_metric_unset (struct bgp *bgp, afi_t afi, int type) |
| 1038 | { |
| 1039 | if (! bgp->redist_metric_flag[afi][type]) |
| 1040 | return 0; |
| 1041 | |
| 1042 | /* Unset metric. */ |
| 1043 | bgp->redist_metric_flag[afi][type] = 0; |
| 1044 | bgp->redist_metric[afi][type] = 0; |
| 1045 | |
| 1046 | return 1; |
| 1047 | } |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 1048 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1049 | void |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1050 | bgp_zclient_reset (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1051 | { |
| 1052 | zclient_reset (zclient); |
| 1053 | } |
| 1054 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1055 | static void |
| 1056 | bgp_zebra_connected (struct zclient *zclient) |
| 1057 | { |
| 1058 | zclient_send_requests (zclient, VRF_DEFAULT); |
| 1059 | } |
| 1060 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1061 | void |
Donald Sharp | 7125293 | 2015-09-24 09:25:19 -0400 | [diff] [blame] | 1062 | bgp_zebra_init (struct thread_master *master) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1063 | { |
| 1064 | /* Set default values. */ |
Donald Sharp | 7125293 | 2015-09-24 09:25:19 -0400 | [diff] [blame] | 1065 | zclient = zclient_new (master); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1066 | zclient_init (zclient, ZEBRA_ROUTE_BGP); |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1067 | zclient->zebra_connected = bgp_zebra_connected; |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 1068 | zclient->router_id_update = bgp_router_id_update; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1069 | zclient->interface_add = bgp_interface_add; |
| 1070 | zclient->interface_delete = bgp_interface_delete; |
| 1071 | zclient->interface_address_add = bgp_interface_address_add; |
| 1072 | zclient->interface_address_delete = bgp_interface_address_delete; |
| 1073 | zclient->ipv4_route_add = zebra_read_ipv4; |
| 1074 | zclient->ipv4_route_delete = zebra_read_ipv4; |
| 1075 | zclient->interface_up = bgp_interface_up; |
| 1076 | zclient->interface_down = bgp_interface_down; |
| 1077 | #ifdef HAVE_IPV6 |
| 1078 | zclient->ipv6_route_add = zebra_read_ipv6; |
| 1079 | zclient->ipv6_route_delete = zebra_read_ipv6; |
| 1080 | #endif /* HAVE_IPV6 */ |
| 1081 | |
Josh Bailey | 8196f13 | 2011-07-20 20:47:07 -0700 | [diff] [blame] | 1082 | bgp_nexthop_buf = stream_new(BGP_NEXTHOP_BUF_SIZE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1083 | } |