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 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 308 | /* Zebra route add and delete treatment. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 309 | static int |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 310 | zebra_read_ipv6 (int command, struct zclient *zclient, zebra_size_t length, |
| 311 | vrf_id_t vrf_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 312 | { |
| 313 | struct stream *s; |
| 314 | struct zapi_ipv6 api; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 315 | struct in6_addr nexthop; |
| 316 | struct prefix_ipv6 p; |
| 317 | |
| 318 | s = zclient->ibuf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 319 | memset (&nexthop, 0, sizeof (struct in6_addr)); |
| 320 | |
| 321 | /* Type, flags, message. */ |
| 322 | api.type = stream_getc (s); |
| 323 | api.flags = stream_getc (s); |
| 324 | api.message = stream_getc (s); |
| 325 | |
| 326 | /* IPv6 prefix. */ |
| 327 | memset (&p, 0, sizeof (struct prefix_ipv6)); |
| 328 | p.family = AF_INET6; |
| 329 | p.prefixlen = stream_getc (s); |
| 330 | stream_get (&p.prefix, s, PSIZE (p.prefixlen)); |
| 331 | |
| 332 | /* Nexthop, ifindex, distance, metric. */ |
| 333 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP)) |
| 334 | { |
| 335 | api.nexthop_num = stream_getc (s); |
| 336 | stream_get (&nexthop, s, 16); |
| 337 | } |
| 338 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX)) |
| 339 | { |
| 340 | api.ifindex_num = stream_getc (s); |
Stephen Hemminger | 9206f9e | 2011-12-18 19:43:40 +0400 | [diff] [blame] | 341 | stream_getl (s); /* ifindex, unused */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 342 | } |
| 343 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE)) |
| 344 | api.distance = stream_getc (s); |
| 345 | else |
| 346 | api.distance = 0; |
| 347 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC)) |
| 348 | api.metric = stream_getl (s); |
| 349 | else |
| 350 | api.metric = 0; |
| 351 | |
| 352 | /* Simply ignore link-local address. */ |
| 353 | if (IN6_IS_ADDR_LINKLOCAL (&p.prefix)) |
| 354 | return 0; |
| 355 | |
| 356 | if (command == ZEBRA_IPV6_ROUTE_ADD) |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 357 | { |
| 358 | if (BGP_DEBUG(zebra, ZEBRA)) |
| 359 | { |
Stephen Hemminger | f04a80a | 2011-12-06 14:51:10 +0400 | [diff] [blame] | 360 | char buf[2][INET6_ADDRSTRLEN]; |
| 361 | 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] | 362 | zebra_route_string(api.type), |
Stephen Hemminger | f04a80a | 2011-12-06 14:51:10 +0400 | [diff] [blame] | 363 | inet_ntop(AF_INET6, &p.prefix, buf[0], sizeof(buf[0])), |
| 364 | p.prefixlen, |
| 365 | inet_ntop(AF_INET, &nexthop, buf[1], sizeof(buf[1])), |
| 366 | api.metric); |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 367 | } |
Stephen Hemminger | f04a80a | 2011-12-06 14:51:10 +0400 | [diff] [blame] | 368 | bgp_redistribute_add ((struct prefix *)&p, NULL, &nexthop, |
| 369 | api.metric, api.type); |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 370 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 371 | else |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 372 | { |
| 373 | if (BGP_DEBUG(zebra, ZEBRA)) |
| 374 | { |
Stephen Hemminger | f04a80a | 2011-12-06 14:51:10 +0400 | [diff] [blame] | 375 | char buf[2][INET6_ADDRSTRLEN]; |
| 376 | zlog_debug("Zebra rcvd: IPv6 route delete %s %s/%d " |
| 377 | "nexthop %s metric %u", |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 378 | zebra_route_string(api.type), |
Stephen Hemminger | f04a80a | 2011-12-06 14:51:10 +0400 | [diff] [blame] | 379 | inet_ntop(AF_INET6, &p.prefix, buf[0], sizeof(buf[0])), |
| 380 | p.prefixlen, |
| 381 | inet_ntop(AF_INET6, &nexthop, buf[1], sizeof(buf[1])), |
| 382 | api.metric); |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 383 | } |
| 384 | bgp_redistribute_delete ((struct prefix *) &p, api.type); |
| 385 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 386 | |
| 387 | return 0; |
| 388 | } |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 389 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 390 | struct interface * |
| 391 | if_lookup_by_ipv4 (struct in_addr *addr) |
| 392 | { |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 393 | struct listnode *ifnode; |
| 394 | struct listnode *cnode; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 395 | struct interface *ifp; |
| 396 | struct connected *connected; |
| 397 | struct prefix_ipv4 p; |
| 398 | struct prefix *cp; |
| 399 | |
| 400 | p.family = AF_INET; |
| 401 | p.prefix = *addr; |
| 402 | p.prefixlen = IPV4_MAX_BITLEN; |
| 403 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 404 | for (ALL_LIST_ELEMENTS_RO (iflist, ifnode, ifp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 405 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 406 | for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 407 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 408 | cp = connected->address; |
| 409 | |
| 410 | if (cp->family == AF_INET) |
| 411 | if (prefix_match (cp, (struct prefix *)&p)) |
| 412 | return ifp; |
| 413 | } |
| 414 | } |
| 415 | return NULL; |
| 416 | } |
| 417 | |
| 418 | struct interface * |
| 419 | if_lookup_by_ipv4_exact (struct in_addr *addr) |
| 420 | { |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 421 | struct listnode *ifnode; |
| 422 | struct listnode *cnode; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 423 | struct interface *ifp; |
| 424 | struct connected *connected; |
| 425 | struct prefix *cp; |
| 426 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 427 | for (ALL_LIST_ELEMENTS_RO (iflist, ifnode, ifp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 428 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 429 | for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 430 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 431 | cp = connected->address; |
| 432 | |
| 433 | if (cp->family == AF_INET) |
| 434 | if (IPV4_ADDR_SAME (&cp->u.prefix4, addr)) |
| 435 | return ifp; |
| 436 | } |
| 437 | } |
| 438 | return NULL; |
| 439 | } |
| 440 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 441 | struct interface * |
| 442 | if_lookup_by_ipv6 (struct in6_addr *addr) |
| 443 | { |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 444 | struct listnode *ifnode; |
| 445 | struct listnode *cnode; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 446 | struct interface *ifp; |
| 447 | struct connected *connected; |
| 448 | struct prefix_ipv6 p; |
| 449 | struct prefix *cp; |
| 450 | |
| 451 | p.family = AF_INET6; |
| 452 | p.prefix = *addr; |
| 453 | p.prefixlen = IPV6_MAX_BITLEN; |
| 454 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 455 | for (ALL_LIST_ELEMENTS_RO (iflist, ifnode, ifp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 456 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 457 | for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 458 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 459 | cp = connected->address; |
| 460 | |
| 461 | if (cp->family == AF_INET6) |
| 462 | if (prefix_match (cp, (struct prefix *)&p)) |
| 463 | return ifp; |
| 464 | } |
| 465 | } |
| 466 | return NULL; |
| 467 | } |
| 468 | |
| 469 | struct interface * |
| 470 | if_lookup_by_ipv6_exact (struct in6_addr *addr) |
| 471 | { |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 472 | struct listnode *ifnode; |
| 473 | struct listnode *cnode; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 474 | struct interface *ifp; |
| 475 | struct connected *connected; |
| 476 | struct prefix *cp; |
| 477 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 478 | for (ALL_LIST_ELEMENTS_RO (iflist, ifnode, ifp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 479 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 480 | for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 481 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 482 | cp = connected->address; |
| 483 | |
| 484 | if (cp->family == AF_INET6) |
| 485 | if (IPV6_ADDR_SAME (&cp->u.prefix6, addr)) |
| 486 | return ifp; |
| 487 | } |
| 488 | } |
| 489 | return NULL; |
| 490 | } |
| 491 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 492 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 493 | if_get_ipv6_global (struct interface *ifp, struct in6_addr *addr) |
| 494 | { |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 495 | struct listnode *cnode; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 496 | struct connected *connected; |
| 497 | struct prefix *cp; |
| 498 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 499 | for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 500 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 501 | cp = connected->address; |
| 502 | |
| 503 | if (cp->family == AF_INET6) |
| 504 | if (! IN6_IS_ADDR_LINKLOCAL (&cp->u.prefix6)) |
| 505 | { |
| 506 | memcpy (addr, &cp->u.prefix6, IPV6_MAX_BYTELEN); |
| 507 | return 1; |
| 508 | } |
| 509 | } |
| 510 | return 0; |
| 511 | } |
| 512 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 513 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 514 | if_get_ipv6_local (struct interface *ifp, struct in6_addr *addr) |
| 515 | { |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 516 | struct listnode *cnode; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 517 | struct connected *connected; |
| 518 | struct prefix *cp; |
| 519 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 520 | for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 521 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 522 | cp = connected->address; |
| 523 | |
| 524 | if (cp->family == AF_INET6) |
| 525 | if (IN6_IS_ADDR_LINKLOCAL (&cp->u.prefix6)) |
| 526 | { |
| 527 | memcpy (addr, &cp->u.prefix6, IPV6_MAX_BYTELEN); |
| 528 | return 1; |
| 529 | } |
| 530 | } |
| 531 | return 0; |
| 532 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 533 | |
Pradosh Mohapatra | 6ee06fa | 2014-01-12 18:30:13 +0000 | [diff] [blame] | 534 | static int |
| 535 | if_get_ipv4_address (struct interface *ifp, struct in_addr *addr) |
| 536 | { |
| 537 | struct listnode *cnode; |
| 538 | struct connected *connected; |
| 539 | struct prefix *cp; |
| 540 | |
| 541 | for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected)) |
| 542 | { |
| 543 | cp = connected->address; |
| 544 | if ((cp->family == AF_INET) && !ipv4_martian(&(cp->u.prefix4))) |
| 545 | { |
| 546 | *addr = cp->u.prefix4; |
| 547 | return 1; |
| 548 | } |
| 549 | } |
| 550 | return 0; |
| 551 | } |
| 552 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 553 | int |
| 554 | bgp_nexthop_set (union sockunion *local, union sockunion *remote, |
| 555 | struct bgp_nexthop *nexthop, struct peer *peer) |
| 556 | { |
| 557 | int ret = 0; |
| 558 | struct interface *ifp = NULL; |
| 559 | |
| 560 | memset (nexthop, 0, sizeof (struct bgp_nexthop)); |
| 561 | |
| 562 | if (!local) |
| 563 | return -1; |
| 564 | if (!remote) |
| 565 | return -1; |
| 566 | |
| 567 | if (local->sa.sa_family == AF_INET) |
| 568 | { |
| 569 | nexthop->v4 = local->sin.sin_addr; |
| 570 | ifp = if_lookup_by_ipv4 (&local->sin.sin_addr); |
| 571 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 572 | if (local->sa.sa_family == AF_INET6) |
| 573 | { |
| 574 | if (IN6_IS_ADDR_LINKLOCAL (&local->sin6.sin6_addr)) |
| 575 | { |
| 576 | if (peer->ifname) |
Feng Lu | 395828e | 2015-05-22 11:39:55 +0200 | [diff] [blame] | 577 | ifp = if_lookup_by_name (peer->ifname); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 578 | } |
| 579 | else |
| 580 | ifp = if_lookup_by_ipv6 (&local->sin6.sin6_addr); |
| 581 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 582 | |
| 583 | if (!ifp) |
| 584 | return -1; |
| 585 | |
| 586 | nexthop->ifp = ifp; |
| 587 | |
| 588 | /* IPv4 connection. */ |
| 589 | if (local->sa.sa_family == AF_INET) |
| 590 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 591 | /* IPv6 nexthop*/ |
| 592 | ret = if_get_ipv6_global (ifp, &nexthop->v6_global); |
| 593 | |
| 594 | /* There is no global nexthop. */ |
| 595 | if (!ret) |
| 596 | if_get_ipv6_local (ifp, &nexthop->v6_global); |
| 597 | else |
| 598 | if_get_ipv6_local (ifp, &nexthop->v6_local); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 599 | } |
| 600 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 601 | /* IPv6 connection. */ |
| 602 | if (local->sa.sa_family == AF_INET6) |
| 603 | { |
| 604 | struct interface *direct = NULL; |
| 605 | |
Pradosh Mohapatra | 6ee06fa | 2014-01-12 18:30:13 +0000 | [diff] [blame] | 606 | /* IPv4 nexthop. */ |
| 607 | ret = if_get_ipv4_address(ifp, &nexthop->v4); |
| 608 | if (!ret && peer->local_id.s_addr) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 609 | nexthop->v4 = peer->local_id; |
| 610 | |
| 611 | /* Global address*/ |
| 612 | if (! IN6_IS_ADDR_LINKLOCAL (&local->sin6.sin6_addr)) |
| 613 | { |
| 614 | memcpy (&nexthop->v6_global, &local->sin6.sin6_addr, |
| 615 | IPV6_MAX_BYTELEN); |
| 616 | |
| 617 | /* If directory connected set link-local address. */ |
| 618 | direct = if_lookup_by_ipv6 (&remote->sin6.sin6_addr); |
| 619 | if (direct) |
| 620 | if_get_ipv6_local (ifp, &nexthop->v6_local); |
| 621 | } |
| 622 | else |
| 623 | /* Link-local address. */ |
| 624 | { |
| 625 | ret = if_get_ipv6_global (ifp, &nexthop->v6_global); |
| 626 | |
| 627 | /* If there is no global address. Set link-local address as |
| 628 | global. I know this break RFC specification... */ |
| 629 | if (!ret) |
| 630 | memcpy (&nexthop->v6_global, &local->sin6.sin6_addr, |
| 631 | IPV6_MAX_BYTELEN); |
| 632 | else |
| 633 | memcpy (&nexthop->v6_local, &local->sin6.sin6_addr, |
| 634 | IPV6_MAX_BYTELEN); |
| 635 | } |
| 636 | } |
| 637 | |
| 638 | if (IN6_IS_ADDR_LINKLOCAL (&local->sin6.sin6_addr) || |
| 639 | if_lookup_by_ipv6 (&remote->sin6.sin6_addr)) |
| 640 | peer->shared_network = 1; |
| 641 | else |
| 642 | peer->shared_network = 0; |
| 643 | |
| 644 | /* KAME stack specific treatment. */ |
| 645 | #ifdef KAME |
| 646 | if (IN6_IS_ADDR_LINKLOCAL (&nexthop->v6_global) |
| 647 | && IN6_LINKLOCAL_IFINDEX (nexthop->v6_global)) |
| 648 | { |
| 649 | SET_IN6_LINKLOCAL_IFINDEX (nexthop->v6_global, 0); |
| 650 | } |
| 651 | if (IN6_IS_ADDR_LINKLOCAL (&nexthop->v6_local) |
| 652 | && IN6_LINKLOCAL_IFINDEX (nexthop->v6_local)) |
| 653 | { |
| 654 | SET_IN6_LINKLOCAL_IFINDEX (nexthop->v6_local, 0); |
| 655 | } |
| 656 | #endif /* KAME */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 657 | return ret; |
| 658 | } |
| 659 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 660 | void |
G.Balaji | 5a616c0 | 2011-11-26 21:58:42 +0400 | [diff] [blame] | 661 | 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] | 662 | { |
| 663 | int flags; |
| 664 | u_char distance; |
| 665 | struct peer *peer; |
Josh Bailey | 8196f13 | 2011-07-20 20:47:07 -0700 | [diff] [blame] | 666 | struct bgp_info *mpinfo; |
| 667 | size_t oldsize, newsize; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 668 | |
| 669 | if (zclient->sock < 0) |
| 670 | return; |
| 671 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 672 | if (! vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_BGP], VRF_DEFAULT)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 673 | return; |
| 674 | |
| 675 | flags = 0; |
| 676 | peer = info->peer; |
| 677 | |
Jorge Boncompte [DTI2] | 6d85b15 | 2012-05-07 16:52:54 +0000 | [diff] [blame] | 678 | if (peer->sort == BGP_PEER_IBGP || peer->sort == BGP_PEER_CONFED) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 679 | { |
| 680 | SET_FLAG (flags, ZEBRA_FLAG_IBGP); |
| 681 | SET_FLAG (flags, ZEBRA_FLAG_INTERNAL); |
| 682 | } |
| 683 | |
Jorge Boncompte [DTI2] | 6d85b15 | 2012-05-07 16:52:54 +0000 | [diff] [blame] | 684 | if ((peer->sort == BGP_PEER_EBGP && peer->ttl != 1) |
hasso | 6ffd207 | 2005-02-02 14:50:11 +0000 | [diff] [blame] | 685 | || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 686 | SET_FLAG (flags, ZEBRA_FLAG_INTERNAL); |
| 687 | |
Josh Bailey | 8196f13 | 2011-07-20 20:47:07 -0700 | [diff] [blame] | 688 | /* resize nexthop buffer size if necessary */ |
| 689 | if ((oldsize = stream_get_size (bgp_nexthop_buf)) < |
| 690 | (sizeof (struct in_addr *) * (bgp_info_mpath_count (info) + 1))) |
| 691 | { |
| 692 | newsize = (sizeof (struct in_addr *) * (bgp_info_mpath_count (info) + 1)); |
| 693 | newsize = stream_resize (bgp_nexthop_buf, newsize); |
| 694 | if (newsize == oldsize) |
| 695 | { |
| 696 | zlog_err ("can't resize nexthop buffer"); |
| 697 | return; |
| 698 | } |
| 699 | } |
| 700 | |
| 701 | stream_reset (bgp_nexthop_buf); |
| 702 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 703 | if (p->family == AF_INET) |
| 704 | { |
| 705 | struct zapi_ipv4 api; |
| 706 | struct in_addr *nexthop; |
| 707 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 708 | api.vrf_id = VRF_DEFAULT; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 709 | api.flags = flags; |
| 710 | nexthop = &info->attr->nexthop; |
Josh Bailey | 8196f13 | 2011-07-20 20:47:07 -0700 | [diff] [blame] | 711 | stream_put (bgp_nexthop_buf, &nexthop, sizeof (struct in_addr *)); |
| 712 | for (mpinfo = bgp_info_mpath_first (info); mpinfo; |
| 713 | mpinfo = bgp_info_mpath_next (mpinfo)) |
| 714 | { |
| 715 | nexthop = &mpinfo->attr->nexthop; |
| 716 | stream_put (bgp_nexthop_buf, &nexthop, sizeof (struct in_addr *)); |
| 717 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 718 | |
| 719 | api.type = ZEBRA_ROUTE_BGP; |
| 720 | api.message = 0; |
G.Balaji | 5a616c0 | 2011-11-26 21:58:42 +0400 | [diff] [blame] | 721 | api.safi = safi; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 722 | SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); |
Josh Bailey | 8196f13 | 2011-07-20 20:47:07 -0700 | [diff] [blame] | 723 | api.nexthop_num = 1 + bgp_info_mpath_count (info); |
| 724 | api.nexthop = (struct in_addr **)STREAM_DATA (bgp_nexthop_buf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 725 | api.ifindex_num = 0; |
| 726 | SET_FLAG (api.message, ZAPI_MESSAGE_METRIC); |
| 727 | api.metric = info->attr->med; |
| 728 | |
| 729 | distance = bgp_distance_apply (p, info, bgp); |
| 730 | |
| 731 | if (distance) |
| 732 | { |
| 733 | SET_FLAG (api.message, ZAPI_MESSAGE_DISTANCE); |
| 734 | api.distance = distance; |
| 735 | } |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 736 | |
| 737 | if (BGP_DEBUG(zebra, ZEBRA)) |
| 738 | { |
Josh Bailey | 8196f13 | 2011-07-20 20:47:07 -0700 | [diff] [blame] | 739 | int i; |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 740 | char buf[2][INET_ADDRSTRLEN]; |
Josh Bailey | 8196f13 | 2011-07-20 20:47:07 -0700 | [diff] [blame] | 741 | zlog_debug("Zebra send: IPv4 route add %s/%d nexthop %s metric %u" |
| 742 | " count %d", |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 743 | inet_ntop(AF_INET, &p->u.prefix4, buf[0], sizeof(buf[0])), |
| 744 | p->prefixlen, |
Josh Bailey | 8196f13 | 2011-07-20 20:47:07 -0700 | [diff] [blame] | 745 | inet_ntop(AF_INET, api.nexthop[0], buf[1], sizeof(buf[1])), |
| 746 | api.metric, api.nexthop_num); |
| 747 | for (i = 1; i < api.nexthop_num; i++) |
| 748 | zlog_debug("Zebra send: IPv4 route add [nexthop %d] %s", |
| 749 | i, inet_ntop(AF_INET, api.nexthop[i], buf[1], |
| 750 | sizeof(buf[1]))); |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 751 | } |
| 752 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 753 | zapi_ipv4_route (ZEBRA_IPV4_ROUTE_ADD, zclient, |
| 754 | (struct prefix_ipv4 *) p, &api); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 755 | } |
Lou Berger | 205e674 | 2016-01-12 13:42:11 -0500 | [diff] [blame] | 756 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 757 | /* We have to think about a IPv6 link-local address curse. */ |
| 758 | if (p->family == AF_INET6) |
| 759 | { |
| 760 | unsigned int ifindex; |
| 761 | struct in6_addr *nexthop; |
| 762 | struct zapi_ipv6 api; |
| 763 | |
| 764 | ifindex = 0; |
| 765 | nexthop = NULL; |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 766 | |
| 767 | assert (info->attr->extra); |
| 768 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 769 | /* Only global address nexthop exists. */ |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 770 | if (info->attr->extra->mp_nexthop_len == 16) |
| 771 | nexthop = &info->attr->extra->mp_nexthop_global; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 772 | |
| 773 | /* If both global and link-local address present. */ |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 774 | if (info->attr->extra->mp_nexthop_len == 32) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 775 | { |
| 776 | /* Workaround for Cisco's nexthop bug. */ |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 777 | if (IN6_IS_ADDR_UNSPECIFIED (&info->attr->extra->mp_nexthop_global) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 778 | && peer->su_remote->sa.sa_family == AF_INET6) |
| 779 | nexthop = &peer->su_remote->sin6.sin6_addr; |
| 780 | else |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 781 | nexthop = &info->attr->extra->mp_nexthop_local; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 782 | |
| 783 | if (info->peer->nexthop.ifp) |
| 784 | ifindex = info->peer->nexthop.ifp->ifindex; |
| 785 | } |
| 786 | |
| 787 | if (nexthop == NULL) |
| 788 | return; |
| 789 | |
| 790 | if (IN6_IS_ADDR_LINKLOCAL (nexthop) && ! ifindex) |
| 791 | { |
| 792 | if (info->peer->ifname) |
Feng Lu | 395828e | 2015-05-22 11:39:55 +0200 | [diff] [blame] | 793 | ifindex = ifname2ifindex (info->peer->ifname); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 794 | else if (info->peer->nexthop.ifp) |
| 795 | ifindex = info->peer->nexthop.ifp->ifindex; |
| 796 | } |
| 797 | |
| 798 | /* Make Zebra API structure. */ |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 799 | api.vrf_id = VRF_DEFAULT; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 800 | api.flags = flags; |
| 801 | api.type = ZEBRA_ROUTE_BGP; |
| 802 | api.message = 0; |
G.Balaji | c7ec179 | 2011-11-26 22:04:05 +0400 | [diff] [blame] | 803 | api.safi = safi; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 804 | SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); |
| 805 | api.nexthop_num = 1; |
| 806 | api.nexthop = &nexthop; |
| 807 | SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX); |
| 808 | api.ifindex_num = 1; |
| 809 | api.ifindex = &ifindex; |
| 810 | SET_FLAG (api.message, ZAPI_MESSAGE_METRIC); |
| 811 | api.metric = info->attr->med; |
| 812 | |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 813 | if (BGP_DEBUG(zebra, ZEBRA)) |
| 814 | { |
| 815 | char buf[2][INET6_ADDRSTRLEN]; |
| 816 | zlog_debug("Zebra send: IPv6 route add %s/%d nexthop %s metric %u", |
| 817 | inet_ntop(AF_INET6, &p->u.prefix6, buf[0], sizeof(buf[0])), |
| 818 | p->prefixlen, |
| 819 | inet_ntop(AF_INET6, nexthop, buf[1], sizeof(buf[1])), |
| 820 | api.metric); |
| 821 | } |
| 822 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 823 | zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD, zclient, |
| 824 | (struct prefix_ipv6 *) p, &api); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 825 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | void |
G.Balaji | 5a616c0 | 2011-11-26 21:58:42 +0400 | [diff] [blame] | 829 | bgp_zebra_withdraw (struct prefix *p, struct bgp_info *info, safi_t safi) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 830 | { |
| 831 | int flags; |
| 832 | struct peer *peer; |
| 833 | |
| 834 | if (zclient->sock < 0) |
| 835 | return; |
| 836 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 837 | if (! vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_BGP], VRF_DEFAULT)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 838 | return; |
| 839 | |
| 840 | peer = info->peer; |
| 841 | flags = 0; |
| 842 | |
Jorge Boncompte [DTI2] | 6d85b15 | 2012-05-07 16:52:54 +0000 | [diff] [blame] | 843 | if (peer->sort == BGP_PEER_IBGP) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 844 | { |
| 845 | SET_FLAG (flags, ZEBRA_FLAG_INTERNAL); |
| 846 | SET_FLAG (flags, ZEBRA_FLAG_IBGP); |
| 847 | } |
| 848 | |
Jorge Boncompte [DTI2] | 6d85b15 | 2012-05-07 16:52:54 +0000 | [diff] [blame] | 849 | if ((peer->sort == BGP_PEER_EBGP && peer->ttl != 1) |
hasso | 6ffd207 | 2005-02-02 14:50:11 +0000 | [diff] [blame] | 850 | || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 851 | SET_FLAG (flags, ZEBRA_FLAG_INTERNAL); |
| 852 | |
| 853 | if (p->family == AF_INET) |
| 854 | { |
| 855 | struct zapi_ipv4 api; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 856 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 857 | api.vrf_id = VRF_DEFAULT; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 858 | api.flags = flags; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 859 | |
| 860 | api.type = ZEBRA_ROUTE_BGP; |
| 861 | api.message = 0; |
G.Balaji | 5a616c0 | 2011-11-26 21:58:42 +0400 | [diff] [blame] | 862 | api.safi = safi; |
Paul Jakma | 64e0ac2 | 2015-11-18 16:00:54 +0000 | [diff] [blame] | 863 | api.nexthop_num = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 864 | api.ifindex_num = 0; |
| 865 | SET_FLAG (api.message, ZAPI_MESSAGE_METRIC); |
| 866 | api.metric = info->attr->med; |
| 867 | |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 868 | if (BGP_DEBUG(zebra, ZEBRA)) |
| 869 | { |
| 870 | char buf[2][INET_ADDRSTRLEN]; |
Paul Jakma | 64e0ac2 | 2015-11-18 16:00:54 +0000 | [diff] [blame] | 871 | zlog_debug("Zebra send: IPv4 route delete %s/%d metric %u", |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 872 | inet_ntop(AF_INET, &p->u.prefix4, buf[0], sizeof(buf[0])), |
| 873 | p->prefixlen, |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 874 | api.metric); |
| 875 | } |
| 876 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 877 | zapi_ipv4_route (ZEBRA_IPV4_ROUTE_DELETE, zclient, |
| 878 | (struct prefix_ipv4 *) p, &api); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 879 | } |
Lou Berger | 205e674 | 2016-01-12 13:42:11 -0500 | [diff] [blame] | 880 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 881 | /* We have to think about a IPv6 link-local address curse. */ |
| 882 | if (p->family == AF_INET6) |
| 883 | { |
| 884 | struct zapi_ipv6 api; |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 885 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 886 | api.vrf_id = VRF_DEFAULT; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 887 | api.flags = flags; |
| 888 | api.type = ZEBRA_ROUTE_BGP; |
| 889 | api.message = 0; |
G.Balaji | c7ec179 | 2011-11-26 22:04:05 +0400 | [diff] [blame] | 890 | api.safi = safi; |
Paul Jakma | 64e0ac2 | 2015-11-18 16:00:54 +0000 | [diff] [blame] | 891 | api.nexthop_num = 0; |
| 892 | api.ifindex_num = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 893 | SET_FLAG (api.message, ZAPI_MESSAGE_METRIC); |
| 894 | api.metric = info->attr->med; |
| 895 | |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 896 | if (BGP_DEBUG(zebra, ZEBRA)) |
| 897 | { |
| 898 | char buf[2][INET6_ADDRSTRLEN]; |
Paul Jakma | 64e0ac2 | 2015-11-18 16:00:54 +0000 | [diff] [blame] | 899 | zlog_debug("Zebra send: IPv6 route delete %s/%d metric %u", |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 900 | inet_ntop(AF_INET6, &p->u.prefix6, buf[0], sizeof(buf[0])), |
| 901 | p->prefixlen, |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 902 | api.metric); |
| 903 | } |
| 904 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 905 | zapi_ipv6_route (ZEBRA_IPV6_ROUTE_DELETE, zclient, |
| 906 | (struct prefix_ipv6 *) p, &api); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 907 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 908 | } |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 909 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 910 | /* Other routes redistribution into BGP. */ |
| 911 | int |
| 912 | bgp_redistribute_set (struct bgp *bgp, afi_t afi, int type) |
| 913 | { |
| 914 | /* Set flag to BGP instance. */ |
| 915 | bgp->redist[afi][type] = 1; |
| 916 | |
| 917 | /* Return if already redistribute flag is set. */ |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 918 | if (vrf_bitmap_check (zclient->redist[type], VRF_DEFAULT)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 919 | return CMD_WARNING; |
| 920 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 921 | vrf_bitmap_set (zclient->redist[type], VRF_DEFAULT); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 922 | |
| 923 | /* Return if zebra connection is not established. */ |
| 924 | if (zclient->sock < 0) |
| 925 | return CMD_WARNING; |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 926 | |
| 927 | if (BGP_DEBUG(zebra, ZEBRA)) |
| 928 | zlog_debug("Zebra send: redistribute add %s", zebra_route_string(type)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 929 | |
| 930 | /* Send distribute add message to zebra. */ |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 931 | zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, type, VRF_DEFAULT); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 932 | |
| 933 | return CMD_SUCCESS; |
| 934 | } |
| 935 | |
| 936 | /* Redistribute with route-map specification. */ |
| 937 | int |
paul | fd79ac9 | 2004-10-13 05:06:08 +0000 | [diff] [blame] | 938 | bgp_redistribute_rmap_set (struct bgp *bgp, afi_t afi, int type, |
| 939 | const char *name) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 940 | { |
| 941 | if (bgp->rmap[afi][type].name |
| 942 | && (strcmp (bgp->rmap[afi][type].name, name) == 0)) |
| 943 | return 0; |
| 944 | |
| 945 | if (bgp->rmap[afi][type].name) |
| 946 | free (bgp->rmap[afi][type].name); |
| 947 | bgp->rmap[afi][type].name = strdup (name); |
| 948 | bgp->rmap[afi][type].map = route_map_lookup_by_name (name); |
| 949 | |
| 950 | return 1; |
| 951 | } |
| 952 | |
| 953 | /* Redistribute with metric specification. */ |
| 954 | int |
| 955 | bgp_redistribute_metric_set (struct bgp *bgp, afi_t afi, int type, |
| 956 | u_int32_t metric) |
| 957 | { |
| 958 | if (bgp->redist_metric_flag[afi][type] |
| 959 | && bgp->redist_metric[afi][type] == metric) |
| 960 | return 0; |
| 961 | |
| 962 | bgp->redist_metric_flag[afi][type] = 1; |
| 963 | bgp->redist_metric[afi][type] = metric; |
| 964 | |
| 965 | return 1; |
| 966 | } |
| 967 | |
| 968 | /* Unset redistribution. */ |
| 969 | int |
| 970 | bgp_redistribute_unset (struct bgp *bgp, afi_t afi, int type) |
| 971 | { |
| 972 | /* Unset flag from BGP instance. */ |
| 973 | bgp->redist[afi][type] = 0; |
| 974 | |
| 975 | /* Unset route-map. */ |
| 976 | if (bgp->rmap[afi][type].name) |
| 977 | free (bgp->rmap[afi][type].name); |
| 978 | bgp->rmap[afi][type].name = NULL; |
| 979 | bgp->rmap[afi][type].map = NULL; |
| 980 | |
| 981 | /* Unset metric. */ |
| 982 | bgp->redist_metric_flag[afi][type] = 0; |
| 983 | bgp->redist_metric[afi][type] = 0; |
| 984 | |
| 985 | /* Return if zebra connection is disabled. */ |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 986 | if (! vrf_bitmap_check (zclient->redist[type], VRF_DEFAULT)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 987 | return CMD_WARNING; |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 988 | vrf_bitmap_unset (zclient->redist[type], VRF_DEFAULT); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 989 | |
| 990 | if (bgp->redist[AFI_IP][type] == 0 |
| 991 | && bgp->redist[AFI_IP6][type] == 0 |
| 992 | && zclient->sock >= 0) |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 993 | { |
| 994 | /* Send distribute delete message to zebra. */ |
| 995 | if (BGP_DEBUG(zebra, ZEBRA)) |
| 996 | zlog_debug("Zebra send: redistribute delete %s", |
| 997 | zebra_route_string(type)); |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 998 | zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, type, |
| 999 | VRF_DEFAULT); |
Andrew J. Schorr | a39275d | 2006-11-30 16:36:57 +0000 | [diff] [blame] | 1000 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1001 | |
| 1002 | /* Withdraw redistributed routes from current BGP's routing table. */ |
| 1003 | bgp_redistribute_withdraw (bgp, afi, type); |
| 1004 | |
| 1005 | return CMD_SUCCESS; |
| 1006 | } |
| 1007 | |
| 1008 | /* Unset redistribution route-map configuration. */ |
| 1009 | int |
| 1010 | bgp_redistribute_routemap_unset (struct bgp *bgp, afi_t afi, int type) |
| 1011 | { |
| 1012 | if (! bgp->rmap[afi][type].name) |
| 1013 | return 0; |
| 1014 | |
| 1015 | /* Unset route-map. */ |
| 1016 | free (bgp->rmap[afi][type].name); |
| 1017 | bgp->rmap[afi][type].name = NULL; |
| 1018 | bgp->rmap[afi][type].map = NULL; |
| 1019 | |
| 1020 | return 1; |
| 1021 | } |
| 1022 | |
| 1023 | /* Unset redistribution metric configuration. */ |
| 1024 | int |
| 1025 | bgp_redistribute_metric_unset (struct bgp *bgp, afi_t afi, int type) |
| 1026 | { |
| 1027 | if (! bgp->redist_metric_flag[afi][type]) |
| 1028 | return 0; |
| 1029 | |
| 1030 | /* Unset metric. */ |
| 1031 | bgp->redist_metric_flag[afi][type] = 0; |
| 1032 | bgp->redist_metric[afi][type] = 0; |
| 1033 | |
| 1034 | return 1; |
| 1035 | } |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 1036 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1037 | void |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1038 | bgp_zclient_reset (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1039 | { |
| 1040 | zclient_reset (zclient); |
| 1041 | } |
| 1042 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1043 | static void |
| 1044 | bgp_zebra_connected (struct zclient *zclient) |
| 1045 | { |
| 1046 | zclient_send_requests (zclient, VRF_DEFAULT); |
| 1047 | } |
| 1048 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1049 | void |
Donald Sharp | 7125293 | 2015-09-24 09:25:19 -0400 | [diff] [blame] | 1050 | bgp_zebra_init (struct thread_master *master) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1051 | { |
| 1052 | /* Set default values. */ |
Donald Sharp | 7125293 | 2015-09-24 09:25:19 -0400 | [diff] [blame] | 1053 | zclient = zclient_new (master); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1054 | zclient_init (zclient, ZEBRA_ROUTE_BGP); |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1055 | zclient->zebra_connected = bgp_zebra_connected; |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 1056 | zclient->router_id_update = bgp_router_id_update; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1057 | zclient->interface_add = bgp_interface_add; |
| 1058 | zclient->interface_delete = bgp_interface_delete; |
| 1059 | zclient->interface_address_add = bgp_interface_address_add; |
| 1060 | zclient->interface_address_delete = bgp_interface_address_delete; |
| 1061 | zclient->ipv4_route_add = zebra_read_ipv4; |
| 1062 | zclient->ipv4_route_delete = zebra_read_ipv4; |
| 1063 | zclient->interface_up = bgp_interface_up; |
| 1064 | zclient->interface_down = bgp_interface_down; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1065 | zclient->ipv6_route_add = zebra_read_ipv6; |
| 1066 | zclient->ipv6_route_delete = zebra_read_ipv6; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1067 | |
Josh Bailey | 8196f13 | 2011-07-20 20:47:07 -0700 | [diff] [blame] | 1068 | bgp_nexthop_buf = stream_new(BGP_NEXTHOP_BUF_SIZE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1069 | } |
Lou Berger | 82dd707 | 2016-01-12 13:41:57 -0500 | [diff] [blame] | 1070 | |
| 1071 | void |
| 1072 | bgp_zebra_destroy(void) |
| 1073 | { |
| 1074 | if (zclient == NULL) |
| 1075 | return; |
| 1076 | zclient_stop(zclient); |
| 1077 | zclient_free(zclient); |
| 1078 | zclient = NULL; |
| 1079 | } |