paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* Zebra daemon server routine. |
| 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 | |
| 22 | #include <zebra.h> |
| 23 | |
| 24 | #include "prefix.h" |
| 25 | #include "command.h" |
| 26 | #include "if.h" |
| 27 | #include "thread.h" |
| 28 | #include "stream.h" |
| 29 | #include "memory.h" |
| 30 | #include "table.h" |
| 31 | #include "rib.h" |
| 32 | #include "network.h" |
| 33 | #include "sockunion.h" |
| 34 | #include "log.h" |
| 35 | #include "zclient.h" |
paul | edd7c24 | 2003-06-04 13:59:38 +0000 | [diff] [blame] | 36 | #include "privs.h" |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 37 | #include "network.h" |
| 38 | #include "buffer.h" |
Feng Lu | 0d0686f | 2015-05-22 11:40:02 +0200 | [diff] [blame] | 39 | #include "vrf.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 40 | |
| 41 | #include "zebra/zserv.h" |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 42 | #include "zebra/router-id.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 43 | #include "zebra/redistribute.h" |
| 44 | #include "zebra/debug.h" |
| 45 | #include "zebra/ipforward.h" |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 46 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 47 | /* Event list of zebra. */ |
| 48 | enum event { ZEBRA_SERV, ZEBRA_READ, ZEBRA_WRITE }; |
| 49 | |
paul | b21b19c | 2003-06-15 01:28:29 +0000 | [diff] [blame] | 50 | extern struct zebra_t zebrad; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 51 | |
paul | b9df2d2 | 2004-05-09 09:09:59 +0000 | [diff] [blame] | 52 | static void zebra_event (enum event event, int sock, struct zserv *client); |
paul | ccf3557 | 2003-03-01 11:42:20 +0000 | [diff] [blame] | 53 | |
paul | edd7c24 | 2003-06-04 13:59:38 +0000 | [diff] [blame] | 54 | extern struct zebra_privs_t zserv_privs; |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 55 | |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 56 | static void zebra_client_close (struct zserv *client); |
| 57 | |
| 58 | static int |
| 59 | zserv_delayed_close(struct thread *thread) |
paul | ccf3557 | 2003-03-01 11:42:20 +0000 | [diff] [blame] | 60 | { |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 61 | struct zserv *client = THREAD_ARG(thread); |
paul | ccf3557 | 2003-03-01 11:42:20 +0000 | [diff] [blame] | 62 | |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 63 | client->t_suicide = NULL; |
| 64 | zebra_client_close(client); |
paul | ccf3557 | 2003-03-01 11:42:20 +0000 | [diff] [blame] | 65 | return 0; |
| 66 | } |
| 67 | |
Vyacheslav Trushkin | 2ea1ab1 | 2011-12-11 18:48:47 +0400 | [diff] [blame] | 68 | /* When client connects, it sends hello message |
| 69 | * with promise to send zebra routes of specific type. |
| 70 | * Zebra stores a socket fd of the client into |
| 71 | * this array. And use it to clean up routes that |
| 72 | * client didn't remove for some reasons after closing |
| 73 | * connection. |
| 74 | */ |
| 75 | static int route_type_oaths[ZEBRA_ROUTE_MAX]; |
| 76 | |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 77 | static int |
| 78 | zserv_flush_data(struct thread *thread) |
paul | ccf3557 | 2003-03-01 11:42:20 +0000 | [diff] [blame] | 79 | { |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 80 | struct zserv *client = THREAD_ARG(thread); |
paul | ccf3557 | 2003-03-01 11:42:20 +0000 | [diff] [blame] | 81 | |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 82 | client->t_write = NULL; |
| 83 | if (client->t_suicide) |
| 84 | { |
| 85 | zebra_client_close(client); |
| 86 | return -1; |
| 87 | } |
| 88 | switch (buffer_flush_available(client->wb, client->sock)) |
| 89 | { |
| 90 | case BUFFER_ERROR: |
| 91 | zlog_warn("%s: buffer_flush_available failed on zserv client fd %d, " |
| 92 | "closing", __func__, client->sock); |
| 93 | zebra_client_close(client); |
| 94 | break; |
| 95 | case BUFFER_PENDING: |
| 96 | client->t_write = thread_add_write(zebrad.master, zserv_flush_data, |
| 97 | client, client->sock); |
| 98 | break; |
| 99 | case BUFFER_EMPTY: |
| 100 | break; |
| 101 | } |
| 102 | return 0; |
paul | ccf3557 | 2003-03-01 11:42:20 +0000 | [diff] [blame] | 103 | } |
| 104 | |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 105 | static int |
| 106 | zebra_server_send_message(struct zserv *client) |
paul | ccf3557 | 2003-03-01 11:42:20 +0000 | [diff] [blame] | 107 | { |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 108 | if (client->t_suicide) |
| 109 | return -1; |
| 110 | switch (buffer_write(client->wb, client->sock, STREAM_DATA(client->obuf), |
| 111 | stream_get_endp(client->obuf))) |
paul | ccf3557 | 2003-03-01 11:42:20 +0000 | [diff] [blame] | 112 | { |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 113 | case BUFFER_ERROR: |
| 114 | zlog_warn("%s: buffer_write failed to zserv client fd %d, closing", |
| 115 | __func__, client->sock); |
| 116 | /* Schedule a delayed close since many of the functions that call this |
| 117 | one do not check the return code. They do not allow for the |
| 118 | possibility that an I/O error may have caused the client to be |
| 119 | deleted. */ |
| 120 | client->t_suicide = thread_add_event(zebrad.master, zserv_delayed_close, |
| 121 | client, 0); |
| 122 | return -1; |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 123 | case BUFFER_EMPTY: |
| 124 | THREAD_OFF(client->t_write); |
| 125 | break; |
| 126 | case BUFFER_PENDING: |
| 127 | THREAD_WRITE_ON(zebrad.master, client->t_write, |
| 128 | zserv_flush_data, client, client->sock); |
| 129 | break; |
paul | ccf3557 | 2003-03-01 11:42:20 +0000 | [diff] [blame] | 130 | } |
paul | ccf3557 | 2003-03-01 11:42:20 +0000 | [diff] [blame] | 131 | return 0; |
| 132 | } |
| 133 | |
paul | c1b9800 | 2006-01-16 01:54:02 +0000 | [diff] [blame] | 134 | static void |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 135 | zserv_create_header (struct stream *s, uint16_t cmd, vrf_id_t vrf_id) |
paul | c1b9800 | 2006-01-16 01:54:02 +0000 | [diff] [blame] | 136 | { |
| 137 | /* length placeholder, caller can update */ |
| 138 | stream_putw (s, ZEBRA_HEADER_SIZE); |
| 139 | stream_putc (s, ZEBRA_HEADER_MARKER); |
| 140 | stream_putc (s, ZSERV_VERSION); |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 141 | stream_putw (s, vrf_id); |
paul | c1b9800 | 2006-01-16 01:54:02 +0000 | [diff] [blame] | 142 | stream_putw (s, cmd); |
| 143 | } |
| 144 | |
Josh Bailey | 51d4ef8 | 2012-03-21 17:13:39 -0700 | [diff] [blame] | 145 | static void |
| 146 | zserv_encode_interface (struct stream *s, struct interface *ifp) |
| 147 | { |
| 148 | /* Interface information. */ |
| 149 | stream_put (s, ifp->name, INTERFACE_NAMSIZ); |
| 150 | stream_putl (s, ifp->ifindex); |
| 151 | stream_putc (s, ifp->status); |
| 152 | stream_putq (s, ifp->flags); |
| 153 | stream_putl (s, ifp->metric); |
| 154 | stream_putl (s, ifp->mtu); |
| 155 | stream_putl (s, ifp->mtu6); |
| 156 | stream_putl (s, ifp->bandwidth); |
Timo Teräs | 954c7d6 | 2016-01-15 17:36:33 +0200 | [diff] [blame] | 157 | stream_putl (s, ifp->ll_type); |
Josh Bailey | 51d4ef8 | 2012-03-21 17:13:39 -0700 | [diff] [blame] | 158 | stream_putl (s, ifp->hw_addr_len); |
| 159 | if (ifp->hw_addr_len) |
| 160 | stream_put (s, ifp->hw_addr, ifp->hw_addr_len); |
Josh Bailey | 51d4ef8 | 2012-03-21 17:13:39 -0700 | [diff] [blame] | 161 | |
Olivier Dugeon | 15773a8 | 2016-04-19 18:29:55 +0200 | [diff] [blame] | 162 | zlog_info("Try to set TE Link Param"); |
| 163 | /* Then, Traffic Engineering parameters if any */ |
| 164 | if (HAS_LINK_PARAMS(ifp) && IS_LINK_PARAMS_SET(ifp->link_params)) |
| 165 | { |
| 166 | stream_putc (s, 1); |
| 167 | zebra_interface_link_params_write (s, ifp); |
| 168 | } |
| 169 | else |
| 170 | stream_putc (s, 0); |
| 171 | |
Josh Bailey | 51d4ef8 | 2012-03-21 17:13:39 -0700 | [diff] [blame] | 172 | /* Write packet size. */ |
| 173 | stream_putw_at (s, 0, stream_get_endp (s)); |
| 174 | } |
| 175 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 176 | /* Interface is added. Send ZEBRA_INTERFACE_ADD to client. */ |
paul | b9df2d2 | 2004-05-09 09:09:59 +0000 | [diff] [blame] | 177 | /* |
| 178 | * This function is called in the following situations: |
| 179 | * - in response to a 3-byte ZEBRA_INTERFACE_ADD request |
| 180 | * from the client. |
| 181 | * - at startup, when zebra figures out the available interfaces |
| 182 | * - when an interface is added (where support for |
| 183 | * RTM_IFANNOUNCE or AF_NETLINK sockets is available), or when |
| 184 | * an interface is marked IFF_UP (i.e., an RTM_IFINFO message is |
| 185 | * received) |
| 186 | */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 187 | int |
| 188 | zsend_interface_add (struct zserv *client, struct interface *ifp) |
| 189 | { |
| 190 | struct stream *s; |
| 191 | |
| 192 | /* Check this client need interface information. */ |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 193 | if (! vrf_bitmap_check (client->ifinfo, ifp->vrf_id)) |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 194 | return 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 195 | |
| 196 | s = client->obuf; |
| 197 | stream_reset (s); |
| 198 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 199 | zserv_create_header (s, ZEBRA_INTERFACE_ADD, ifp->vrf_id); |
Josh Bailey | 51d4ef8 | 2012-03-21 17:13:39 -0700 | [diff] [blame] | 200 | zserv_encode_interface (s, ifp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 201 | |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 202 | return zebra_server_send_message(client); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | /* Interface deletion from zebra daemon. */ |
| 206 | int |
| 207 | zsend_interface_delete (struct zserv *client, struct interface *ifp) |
| 208 | { |
| 209 | struct stream *s; |
| 210 | |
| 211 | /* Check this client need interface information. */ |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 212 | if (! vrf_bitmap_check (client->ifinfo, ifp->vrf_id)) |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 213 | return 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 214 | |
| 215 | s = client->obuf; |
| 216 | stream_reset (s); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 217 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 218 | zserv_create_header (s, ZEBRA_INTERFACE_DELETE, ifp->vrf_id); |
Josh Bailey | 51d4ef8 | 2012-03-21 17:13:39 -0700 | [diff] [blame] | 219 | zserv_encode_interface (s, ifp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 220 | |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 221 | return zebra_server_send_message (client); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 222 | } |
| 223 | |
Olivier Dugeon | 15773a8 | 2016-04-19 18:29:55 +0200 | [diff] [blame] | 224 | int |
| 225 | zsend_interface_link_params (struct zserv *client, struct interface *ifp) |
| 226 | { |
| 227 | struct stream *s; |
| 228 | |
| 229 | /* Check this client need interface information. */ |
| 230 | if (! client->ifinfo) |
| 231 | return 0; |
| 232 | |
| 233 | if (!ifp->link_params) |
| 234 | return 0; |
| 235 | s = client->obuf; |
| 236 | stream_reset (s); |
| 237 | |
| 238 | zserv_create_header (s, ZEBRA_INTERFACE_LINK_PARAMS, ifp->vrf_id); |
| 239 | |
| 240 | /* Add Interface Index */ |
| 241 | stream_putl (s, ifp->ifindex); |
| 242 | |
| 243 | /* Then TE Link Parameters */ |
| 244 | if (zebra_interface_link_params_write (s, ifp) == 0) |
| 245 | return 0; |
| 246 | |
| 247 | /* Write packet size. */ |
| 248 | stream_putw_at (s, 0, stream_get_endp (s)); |
| 249 | |
| 250 | return zebra_server_send_message (client); |
| 251 | } |
| 252 | |
paul | b9df2d2 | 2004-05-09 09:09:59 +0000 | [diff] [blame] | 253 | /* Interface address is added/deleted. Send ZEBRA_INTERFACE_ADDRESS_ADD or |
| 254 | * ZEBRA_INTERFACE_ADDRESS_DELETE to the client. |
| 255 | * |
| 256 | * A ZEBRA_INTERFACE_ADDRESS_ADD is sent in the following situations: |
| 257 | * - in response to a 3-byte ZEBRA_INTERFACE_ADD request |
| 258 | * from the client, after the ZEBRA_INTERFACE_ADD has been |
| 259 | * sent from zebra to the client |
| 260 | * - redistribute new address info to all clients in the following situations |
| 261 | * - at startup, when zebra figures out the available interfaces |
| 262 | * - when an interface is added (where support for |
| 263 | * RTM_IFANNOUNCE or AF_NETLINK sockets is available), or when |
| 264 | * an interface is marked IFF_UP (i.e., an RTM_IFINFO message is |
| 265 | * received) |
| 266 | * - for the vty commands "ip address A.B.C.D/M [<secondary>|<label LINE>]" |
| 267 | * and "no bandwidth <1-10000000>", "ipv6 address X:X::X:X/M" |
| 268 | * - when an RTM_NEWADDR message is received from the kernel, |
| 269 | * |
| 270 | * The call tree that triggers ZEBRA_INTERFACE_ADDRESS_DELETE: |
| 271 | * |
| 272 | * zsend_interface_address(DELETE) |
| 273 | * ^ |
| 274 | * | |
| 275 | * zebra_interface_address_delete_update |
| 276 | * ^ ^ ^ |
paul | 6eb8827 | 2005-07-29 14:36:00 +0000 | [diff] [blame] | 277 | * | | if_delete_update |
| 278 | * | | |
paul | b9df2d2 | 2004-05-09 09:09:59 +0000 | [diff] [blame] | 279 | * ip_address_uninstall connected_delete_ipv4 |
| 280 | * [ipv6_addresss_uninstall] [connected_delete_ipv6] |
| 281 | * ^ ^ |
| 282 | * | | |
| 283 | * | RTM_NEWADDR on routing/netlink socket |
| 284 | * | |
| 285 | * vty commands: |
| 286 | * "no ip address A.B.C.D/M [label LINE]" |
| 287 | * "no ip address A.B.C.D/M secondary" |
| 288 | * ["no ipv6 address X:X::X:X/M"] |
| 289 | * |
| 290 | */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 291 | int |
paul | b9df2d2 | 2004-05-09 09:09:59 +0000 | [diff] [blame] | 292 | zsend_interface_address (int cmd, struct zserv *client, |
| 293 | struct interface *ifp, struct connected *ifc) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 294 | { |
| 295 | int blen; |
| 296 | struct stream *s; |
| 297 | struct prefix *p; |
| 298 | |
| 299 | /* Check this client need interface information. */ |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 300 | if (! vrf_bitmap_check (client->ifinfo, ifp->vrf_id)) |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 301 | return 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 302 | |
| 303 | s = client->obuf; |
| 304 | stream_reset (s); |
paul | c1b9800 | 2006-01-16 01:54:02 +0000 | [diff] [blame] | 305 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 306 | zserv_create_header (s, cmd, ifp->vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 307 | stream_putl (s, ifp->ifindex); |
| 308 | |
| 309 | /* Interface address flag. */ |
| 310 | stream_putc (s, ifc->flags); |
| 311 | |
| 312 | /* Prefix information. */ |
| 313 | p = ifc->address; |
| 314 | stream_putc (s, p->family); |
| 315 | blen = prefix_blen (p); |
| 316 | stream_put (s, &p->u.prefix, blen); |
paul | b9df2d2 | 2004-05-09 09:09:59 +0000 | [diff] [blame] | 317 | |
| 318 | /* |
| 319 | * XXX gnu version does not send prefixlen for ZEBRA_INTERFACE_ADDRESS_DELETE |
| 320 | * but zebra_interface_address_delete_read() in the gnu version |
| 321 | * expects to find it |
| 322 | */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 323 | stream_putc (s, p->prefixlen); |
| 324 | |
| 325 | /* Destination. */ |
| 326 | p = ifc->destination; |
| 327 | if (p) |
| 328 | stream_put (s, &p->u.prefix, blen); |
| 329 | else |
| 330 | stream_put (s, NULL, blen); |
| 331 | |
| 332 | /* Write packet size. */ |
| 333 | stream_putw_at (s, 0, stream_get_endp (s)); |
| 334 | |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 335 | return zebra_server_send_message(client); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 336 | } |
| 337 | |
paul | b9df2d2 | 2004-05-09 09:09:59 +0000 | [diff] [blame] | 338 | /* |
| 339 | * The cmd passed to zsend_interface_update may be ZEBRA_INTERFACE_UP or |
| 340 | * ZEBRA_INTERFACE_DOWN. |
| 341 | * |
| 342 | * The ZEBRA_INTERFACE_UP message is sent from the zebra server to |
| 343 | * the clients in one of 2 situations: |
| 344 | * - an if_up is detected e.g., as a result of an RTM_IFINFO message |
| 345 | * - a vty command modifying the bandwidth of an interface is received. |
| 346 | * The ZEBRA_INTERFACE_DOWN message is sent when an if_down is detected. |
| 347 | */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 348 | int |
paul | b9df2d2 | 2004-05-09 09:09:59 +0000 | [diff] [blame] | 349 | zsend_interface_update (int cmd, struct zserv *client, struct interface *ifp) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 350 | { |
| 351 | struct stream *s; |
| 352 | |
| 353 | /* Check this client need interface information. */ |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 354 | if (! vrf_bitmap_check (client->ifinfo, ifp->vrf_id)) |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 355 | return 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 356 | |
| 357 | s = client->obuf; |
| 358 | stream_reset (s); |
| 359 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 360 | zserv_create_header (s, cmd, ifp->vrf_id); |
Josh Bailey | 51d4ef8 | 2012-03-21 17:13:39 -0700 | [diff] [blame] | 361 | zserv_encode_interface (s, ifp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 362 | |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 363 | return zebra_server_send_message(client); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 364 | } |
| 365 | |
paul | b9df2d2 | 2004-05-09 09:09:59 +0000 | [diff] [blame] | 366 | /* |
| 367 | * The zebra server sends the clients a ZEBRA_IPV4_ROUTE_ADD or a |
| 368 | * ZEBRA_IPV6_ROUTE_ADD via zsend_route_multipath in the following |
| 369 | * situations: |
| 370 | * - when the client starts up, and requests default information |
| 371 | * by sending a ZEBRA_REDISTRIBUTE_DEFAULT_ADD to the zebra server, in the |
| 372 | * - case of rip, ripngd, ospfd and ospf6d, when the client sends a |
| 373 | * ZEBRA_REDISTRIBUTE_ADD as a result of the "redistribute" vty cmd, |
| 374 | * - when the zebra server redistributes routes after it updates its rib |
| 375 | * |
| 376 | * The zebra server sends clients a ZEBRA_IPV4_ROUTE_DELETE or a |
| 377 | * ZEBRA_IPV6_ROUTE_DELETE via zsend_route_multipath when: |
| 378 | * - a "ip route" or "ipv6 route" vty command is issued, a prefix is |
| 379 | * - deleted from zebra's rib, and this info |
| 380 | * has to be redistributed to the clients |
| 381 | * |
| 382 | * XXX The ZEBRA_IPV*_ROUTE_ADD message is also sent by the client to the |
| 383 | * zebra server when the client wants to tell the zebra server to add a |
| 384 | * route to the kernel (zapi_ipv4_add etc. ). Since it's essentially the |
| 385 | * same message being sent back and forth, this function and |
| 386 | * zapi_ipv{4,6}_{add, delete} should be re-written to avoid code |
| 387 | * duplication. |
| 388 | */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 389 | int |
paul | b9df2d2 | 2004-05-09 09:09:59 +0000 | [diff] [blame] | 390 | zsend_route_multipath (int cmd, struct zserv *client, struct prefix *p, |
| 391 | struct rib *rib) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 392 | { |
| 393 | int psize; |
| 394 | struct stream *s; |
| 395 | struct nexthop *nexthop; |
paul | 1dcb517 | 2005-05-31 08:38:50 +0000 | [diff] [blame] | 396 | unsigned long nhnummark = 0, messmark = 0; |
paul | b9df2d2 | 2004-05-09 09:09:59 +0000 | [diff] [blame] | 397 | int nhnum = 0; |
paul | 1dcb517 | 2005-05-31 08:38:50 +0000 | [diff] [blame] | 398 | u_char zapi_flags = 0; |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 399 | |
| 400 | /* Check this client need this route. */ |
| 401 | if (!vrf_bitmap_check (client->redist[rib->type], rib->vrf_id) && |
| 402 | !(is_default (p) && |
| 403 | vrf_bitmap_check (client->redist_default, rib->vrf_id))) |
| 404 | return 0; |
| 405 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 406 | s = client->obuf; |
| 407 | stream_reset (s); |
paul | c1b9800 | 2006-01-16 01:54:02 +0000 | [diff] [blame] | 408 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 409 | zserv_create_header (s, cmd, rib->vrf_id); |
paul | c1b9800 | 2006-01-16 01:54:02 +0000 | [diff] [blame] | 410 | |
| 411 | /* Put type and nexthop. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 412 | stream_putc (s, rib->type); |
| 413 | stream_putc (s, rib->flags); |
paul | 1dcb517 | 2005-05-31 08:38:50 +0000 | [diff] [blame] | 414 | |
| 415 | /* marker for message flags field */ |
| 416 | messmark = stream_get_endp (s); |
| 417 | stream_putc (s, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 418 | |
| 419 | /* Prefix. */ |
| 420 | psize = PSIZE (p->prefixlen); |
| 421 | stream_putc (s, p->prefixlen); |
paul | b9df2d2 | 2004-05-09 09:09:59 +0000 | [diff] [blame] | 422 | stream_write (s, (u_char *) & p->u.prefix, psize); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 423 | |
paul | b9df2d2 | 2004-05-09 09:09:59 +0000 | [diff] [blame] | 424 | /* |
| 425 | * XXX The message format sent by zebra below does not match the format |
| 426 | * of the corresponding message expected by the zebra server |
| 427 | * itself (e.g., see zread_ipv4_add). The nexthop_num is not set correctly, |
| 428 | * (is there a bug on the client side if more than one segment is sent?) |
| 429 | * nexthop ZEBRA_NEXTHOP_IPV4 is never set, ZEBRA_NEXTHOP_IFINDEX |
| 430 | * is hard-coded. |
| 431 | */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 432 | /* Nexthop */ |
paul | 1dcb517 | 2005-05-31 08:38:50 +0000 | [diff] [blame] | 433 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 434 | for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next) |
| 435 | { |
Timo Teräs | 325823a | 2016-01-15 17:36:31 +0200 | [diff] [blame] | 436 | if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE)) |
paul | b9df2d2 | 2004-05-09 09:09:59 +0000 | [diff] [blame] | 437 | { |
paul | 1dcb517 | 2005-05-31 08:38:50 +0000 | [diff] [blame] | 438 | SET_FLAG (zapi_flags, ZAPI_MESSAGE_NEXTHOP); |
| 439 | SET_FLAG (zapi_flags, ZAPI_MESSAGE_IFINDEX); |
| 440 | |
| 441 | if (nhnummark == 0) |
| 442 | { |
| 443 | nhnummark = stream_get_endp (s); |
| 444 | stream_putc (s, 1); /* placeholder */ |
| 445 | } |
| 446 | |
paul | b9df2d2 | 2004-05-09 09:09:59 +0000 | [diff] [blame] | 447 | nhnum++; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 448 | |
paul | b9df2d2 | 2004-05-09 09:09:59 +0000 | [diff] [blame] | 449 | switch(nexthop->type) |
| 450 | { |
| 451 | case NEXTHOP_TYPE_IPV4: |
| 452 | case NEXTHOP_TYPE_IPV4_IFINDEX: |
| 453 | stream_put_in_addr (s, &nexthop->gate.ipv4); |
| 454 | break; |
| 455 | #ifdef HAVE_IPV6 |
| 456 | case NEXTHOP_TYPE_IPV6: |
| 457 | case NEXTHOP_TYPE_IPV6_IFINDEX: |
| 458 | case NEXTHOP_TYPE_IPV6_IFNAME: |
| 459 | stream_write (s, (u_char *) &nexthop->gate.ipv6, 16); |
| 460 | break; |
| 461 | #endif |
| 462 | default: |
| 463 | if (cmd == ZEBRA_IPV4_ROUTE_ADD |
| 464 | || cmd == ZEBRA_IPV4_ROUTE_DELETE) |
| 465 | { |
| 466 | struct in_addr empty; |
paul | 44983cf | 2004-09-22 13:15:58 +0000 | [diff] [blame] | 467 | memset (&empty, 0, sizeof (struct in_addr)); |
paul | b9df2d2 | 2004-05-09 09:09:59 +0000 | [diff] [blame] | 468 | stream_write (s, (u_char *) &empty, IPV4_MAX_BYTELEN); |
| 469 | } |
| 470 | else |
| 471 | { |
| 472 | struct in6_addr empty; |
| 473 | memset (&empty, 0, sizeof (struct in6_addr)); |
| 474 | stream_write (s, (u_char *) &empty, IPV6_MAX_BYTELEN); |
| 475 | } |
| 476 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 477 | |
paul | b9df2d2 | 2004-05-09 09:09:59 +0000 | [diff] [blame] | 478 | /* Interface index. */ |
| 479 | stream_putc (s, 1); |
| 480 | stream_putl (s, nexthop->ifindex); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 481 | |
paul | b9df2d2 | 2004-05-09 09:09:59 +0000 | [diff] [blame] | 482 | break; |
| 483 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | /* Metric */ |
Stephen Hemminger | cf8a831 | 2010-08-18 15:56:46 -0700 | [diff] [blame] | 487 | if (cmd == ZEBRA_IPV4_ROUTE_ADD || cmd == ZEBRA_IPV6_ROUTE_ADD) |
paul | 1dcb517 | 2005-05-31 08:38:50 +0000 | [diff] [blame] | 488 | { |
vincent | fbf5d03 | 2005-09-29 11:25:50 +0000 | [diff] [blame] | 489 | SET_FLAG (zapi_flags, ZAPI_MESSAGE_DISTANCE); |
| 490 | stream_putc (s, rib->distance); |
paul | 1dcb517 | 2005-05-31 08:38:50 +0000 | [diff] [blame] | 491 | SET_FLAG (zapi_flags, ZAPI_MESSAGE_METRIC); |
| 492 | stream_putl (s, rib->metric); |
Timo Teräs | b11f3b5 | 2015-11-02 16:50:07 +0200 | [diff] [blame] | 493 | SET_FLAG (zapi_flags, ZAPI_MESSAGE_MTU); |
| 494 | stream_putl (s, rib->mtu); |
paul | 1dcb517 | 2005-05-31 08:38:50 +0000 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | /* write real message flags value */ |
| 498 | stream_putc_at (s, messmark, zapi_flags); |
| 499 | |
paul | b9df2d2 | 2004-05-09 09:09:59 +0000 | [diff] [blame] | 500 | /* Write next-hop number */ |
| 501 | if (nhnummark) |
hasso | c1eaa44 | 2004-10-19 06:26:01 +0000 | [diff] [blame] | 502 | stream_putc_at (s, nhnummark, nhnum); |
paul | b9df2d2 | 2004-05-09 09:09:59 +0000 | [diff] [blame] | 503 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 504 | /* Write packet size. */ |
| 505 | stream_putw_at (s, 0, stream_get_endp (s)); |
| 506 | |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 507 | return zebra_server_send_message(client); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 508 | } |
| 509 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 510 | #ifdef HAVE_IPV6 |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 511 | static int |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 512 | zsend_ipv6_nexthop_lookup (struct zserv *client, struct in6_addr *addr, |
| 513 | vrf_id_t vrf_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 514 | { |
| 515 | struct stream *s; |
| 516 | struct rib *rib; |
| 517 | unsigned long nump; |
| 518 | u_char num; |
| 519 | struct nexthop *nexthop; |
| 520 | |
| 521 | /* Lookup nexthop. */ |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 522 | rib = rib_match_ipv6 (addr, vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 523 | |
| 524 | /* Get output stream. */ |
| 525 | s = client->obuf; |
| 526 | stream_reset (s); |
| 527 | |
| 528 | /* Fill in result. */ |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 529 | zserv_create_header (s, ZEBRA_IPV6_NEXTHOP_LOOKUP, vrf_id); |
Hiroshi Yokoi | 8ccd74c | 2015-09-08 11:52:20 +0900 | [diff] [blame] | 530 | stream_put (s, addr, 16); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 531 | |
| 532 | if (rib) |
| 533 | { |
| 534 | stream_putl (s, rib->metric); |
| 535 | num = 0; |
paul | 9985f83 | 2005-02-09 15:51:56 +0000 | [diff] [blame] | 536 | nump = stream_get_endp(s); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 537 | stream_putc (s, 0); |
Christian Franke | fa713d9 | 2013-07-05 15:35:37 +0000 | [diff] [blame] | 538 | /* Only non-recursive routes are elegible to resolve nexthop we |
| 539 | * are looking up. Therefore, we will just iterate over the top |
| 540 | * chain of nexthops. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 541 | for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next) |
Timo Teräs | 325823a | 2016-01-15 17:36:31 +0200 | [diff] [blame] | 542 | if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 543 | { |
| 544 | stream_putc (s, nexthop->type); |
| 545 | switch (nexthop->type) |
| 546 | { |
| 547 | case ZEBRA_NEXTHOP_IPV6: |
| 548 | stream_put (s, &nexthop->gate.ipv6, 16); |
| 549 | break; |
| 550 | case ZEBRA_NEXTHOP_IPV6_IFINDEX: |
| 551 | case ZEBRA_NEXTHOP_IPV6_IFNAME: |
| 552 | stream_put (s, &nexthop->gate.ipv6, 16); |
| 553 | stream_putl (s, nexthop->ifindex); |
| 554 | break; |
| 555 | case ZEBRA_NEXTHOP_IFINDEX: |
| 556 | case ZEBRA_NEXTHOP_IFNAME: |
| 557 | stream_putl (s, nexthop->ifindex); |
| 558 | break; |
hasso | fa2b17e | 2004-03-04 17:45:00 +0000 | [diff] [blame] | 559 | default: |
| 560 | /* do nothing */ |
| 561 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 562 | } |
| 563 | num++; |
| 564 | } |
| 565 | stream_putc_at (s, nump, num); |
| 566 | } |
| 567 | else |
| 568 | { |
| 569 | stream_putl (s, 0); |
| 570 | stream_putc (s, 0); |
| 571 | } |
| 572 | |
| 573 | stream_putw_at (s, 0, stream_get_endp (s)); |
| 574 | |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 575 | return zebra_server_send_message(client); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 576 | } |
| 577 | #endif /* HAVE_IPV6 */ |
| 578 | |
paul | b9df2d2 | 2004-05-09 09:09:59 +0000 | [diff] [blame] | 579 | static int |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 580 | zsend_ipv4_nexthop_lookup (struct zserv *client, struct in_addr addr, |
| 581 | vrf_id_t vrf_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 582 | { |
| 583 | struct stream *s; |
| 584 | struct rib *rib; |
| 585 | unsigned long nump; |
| 586 | u_char num; |
| 587 | struct nexthop *nexthop; |
| 588 | |
David Lamparter | f598cf7 | 2014-11-22 14:44:20 -0800 | [diff] [blame] | 589 | /* Lookup nexthop - eBGP excluded */ |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 590 | rib = rib_match_ipv4_safi (addr, SAFI_UNICAST, 1, NULL, vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 591 | |
| 592 | /* Get output stream. */ |
| 593 | s = client->obuf; |
| 594 | stream_reset (s); |
| 595 | |
| 596 | /* Fill in result. */ |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 597 | zserv_create_header (s, ZEBRA_IPV4_NEXTHOP_LOOKUP, vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 598 | stream_put_in_addr (s, &addr); |
| 599 | |
| 600 | if (rib) |
| 601 | { |
Christian Franke | bb97e46 | 2013-05-25 14:01:35 +0000 | [diff] [blame] | 602 | if (IS_ZEBRA_DEBUG_PACKET && IS_ZEBRA_DEBUG_RECV) |
| 603 | zlog_debug("%s: Matching rib entry found.", __func__); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 604 | stream_putl (s, rib->metric); |
| 605 | num = 0; |
paul | 9985f83 | 2005-02-09 15:51:56 +0000 | [diff] [blame] | 606 | nump = stream_get_endp(s); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 607 | stream_putc (s, 0); |
Christian Franke | fa713d9 | 2013-07-05 15:35:37 +0000 | [diff] [blame] | 608 | /* Only non-recursive routes are elegible to resolve the nexthop we |
| 609 | * are looking up. Therefore, we will just iterate over the top |
| 610 | * chain of nexthops. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 611 | for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next) |
Timo Teräs | 325823a | 2016-01-15 17:36:31 +0200 | [diff] [blame] | 612 | if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 613 | { |
| 614 | stream_putc (s, nexthop->type); |
| 615 | switch (nexthop->type) |
| 616 | { |
| 617 | case ZEBRA_NEXTHOP_IPV4: |
| 618 | stream_put_in_addr (s, &nexthop->gate.ipv4); |
| 619 | break; |
Christian Franke | bb97e46 | 2013-05-25 14:01:35 +0000 | [diff] [blame] | 620 | case ZEBRA_NEXTHOP_IPV4_IFINDEX: |
| 621 | stream_put_in_addr (s, &nexthop->gate.ipv4); |
| 622 | stream_putl (s, nexthop->ifindex); |
| 623 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 624 | case ZEBRA_NEXTHOP_IFINDEX: |
| 625 | case ZEBRA_NEXTHOP_IFNAME: |
| 626 | stream_putl (s, nexthop->ifindex); |
| 627 | break; |
hasso | fa2b17e | 2004-03-04 17:45:00 +0000 | [diff] [blame] | 628 | default: |
| 629 | /* do nothing */ |
| 630 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 631 | } |
| 632 | num++; |
| 633 | } |
| 634 | stream_putc_at (s, nump, num); |
| 635 | } |
| 636 | else |
| 637 | { |
Christian Franke | bb97e46 | 2013-05-25 14:01:35 +0000 | [diff] [blame] | 638 | if (IS_ZEBRA_DEBUG_PACKET && IS_ZEBRA_DEBUG_RECV) |
| 639 | zlog_debug("%s: No matching rib entry found.", __func__); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 640 | stream_putl (s, 0); |
| 641 | stream_putc (s, 0); |
| 642 | } |
| 643 | |
| 644 | stream_putw_at (s, 0, stream_get_endp (s)); |
| 645 | |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 646 | return zebra_server_send_message(client); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 647 | } |
| 648 | |
Everton Marques | 4e5275b | 2014-07-01 15:15:52 -0300 | [diff] [blame] | 649 | /* |
| 650 | Modified version of zsend_ipv4_nexthop_lookup(): |
| 651 | Query unicast rib if nexthop is not found on mrib. |
| 652 | Returns both route metric and protocol distance. |
| 653 | */ |
| 654 | static int |
David Lamparter | bd07812 | 2015-01-06 19:53:24 +0100 | [diff] [blame] | 655 | zsend_ipv4_nexthop_lookup_mrib (struct zserv *client, struct in_addr addr, |
| 656 | struct rib *rib) |
Everton Marques | 4e5275b | 2014-07-01 15:15:52 -0300 | [diff] [blame] | 657 | { |
| 658 | struct stream *s; |
Everton Marques | 4e5275b | 2014-07-01 15:15:52 -0300 | [diff] [blame] | 659 | unsigned long nump; |
| 660 | u_char num; |
| 661 | struct nexthop *nexthop; |
Everton Marques | 4e5275b | 2014-07-01 15:15:52 -0300 | [diff] [blame] | 662 | |
| 663 | /* Get output stream. */ |
| 664 | s = client->obuf; |
| 665 | stream_reset (s); |
| 666 | |
| 667 | /* Fill in result. */ |
Jafar Al-Gharaibeh | 190591f | 2016-04-21 17:40:12 -0500 | [diff] [blame] | 668 | zserv_create_header (s, ZEBRA_IPV4_NEXTHOP_LOOKUP_MRIB, |
| 669 | rib ? rib->vrf_id : VRF_DEFAULT); |
Everton Marques | 4e5275b | 2014-07-01 15:15:52 -0300 | [diff] [blame] | 670 | stream_put_in_addr (s, &addr); |
| 671 | |
| 672 | if (rib) |
| 673 | { |
| 674 | stream_putc (s, rib->distance); |
| 675 | stream_putl (s, rib->metric); |
| 676 | num = 0; |
| 677 | nump = stream_get_endp(s); /* remember position for nexthop_num */ |
| 678 | stream_putc (s, 0); /* reserve room for nexthop_num */ |
| 679 | /* Only non-recursive routes are elegible to resolve the nexthop we |
| 680 | * are looking up. Therefore, we will just iterate over the top |
| 681 | * chain of nexthops. */ |
| 682 | for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next) |
Timo Teräs | 325823a | 2016-01-15 17:36:31 +0200 | [diff] [blame] | 683 | if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE)) |
Everton Marques | 4e5275b | 2014-07-01 15:15:52 -0300 | [diff] [blame] | 684 | { |
| 685 | stream_putc (s, nexthop->type); |
| 686 | switch (nexthop->type) |
| 687 | { |
| 688 | case ZEBRA_NEXTHOP_IPV4: |
| 689 | stream_put_in_addr (s, &nexthop->gate.ipv4); |
| 690 | break; |
| 691 | case ZEBRA_NEXTHOP_IPV4_IFINDEX: |
| 692 | stream_put_in_addr (s, &nexthop->gate.ipv4); |
| 693 | stream_putl (s, nexthop->ifindex); |
| 694 | break; |
| 695 | case ZEBRA_NEXTHOP_IFINDEX: |
| 696 | case ZEBRA_NEXTHOP_IFNAME: |
| 697 | stream_putl (s, nexthop->ifindex); |
| 698 | break; |
| 699 | default: |
| 700 | /* do nothing */ |
| 701 | break; |
| 702 | } |
| 703 | num++; |
| 704 | } |
| 705 | |
| 706 | stream_putc_at (s, nump, num); /* store nexthop_num */ |
| 707 | } |
| 708 | else |
| 709 | { |
| 710 | stream_putc (s, 0); /* distance */ |
| 711 | stream_putl (s, 0); /* metric */ |
| 712 | stream_putc (s, 0); /* nexthop_num */ |
| 713 | } |
| 714 | |
| 715 | stream_putw_at (s, 0, stream_get_endp (s)); |
| 716 | |
| 717 | return zebra_server_send_message(client); |
| 718 | } |
| 719 | |
paul | b9df2d2 | 2004-05-09 09:09:59 +0000 | [diff] [blame] | 720 | static int |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 721 | zsend_ipv4_import_lookup (struct zserv *client, struct prefix_ipv4 *p, |
| 722 | vrf_id_t vrf_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 723 | { |
| 724 | struct stream *s; |
| 725 | struct rib *rib; |
| 726 | unsigned long nump; |
| 727 | u_char num; |
| 728 | struct nexthop *nexthop; |
| 729 | |
| 730 | /* Lookup nexthop. */ |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 731 | rib = rib_lookup_ipv4 (p, vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 732 | |
| 733 | /* Get output stream. */ |
| 734 | s = client->obuf; |
| 735 | stream_reset (s); |
| 736 | |
| 737 | /* Fill in result. */ |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 738 | zserv_create_header (s, ZEBRA_IPV4_IMPORT_LOOKUP, vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 739 | stream_put_in_addr (s, &p->prefix); |
| 740 | |
| 741 | if (rib) |
| 742 | { |
| 743 | stream_putl (s, rib->metric); |
| 744 | num = 0; |
paul | 9985f83 | 2005-02-09 15:51:56 +0000 | [diff] [blame] | 745 | nump = stream_get_endp(s); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 746 | stream_putc (s, 0); |
| 747 | for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next) |
Timo Teräs | 325823a | 2016-01-15 17:36:31 +0200 | [diff] [blame] | 748 | if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 749 | { |
| 750 | stream_putc (s, nexthop->type); |
| 751 | switch (nexthop->type) |
| 752 | { |
| 753 | case ZEBRA_NEXTHOP_IPV4: |
| 754 | stream_put_in_addr (s, &nexthop->gate.ipv4); |
| 755 | break; |
Christian Franke | a12afd5 | 2013-05-25 14:01:36 +0000 | [diff] [blame] | 756 | case ZEBRA_NEXTHOP_IPV4_IFINDEX: |
| 757 | stream_put_in_addr (s, &nexthop->gate.ipv4); |
| 758 | stream_putl (s, nexthop->ifindex); |
| 759 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 760 | case ZEBRA_NEXTHOP_IFINDEX: |
| 761 | case ZEBRA_NEXTHOP_IFNAME: |
| 762 | stream_putl (s, nexthop->ifindex); |
| 763 | break; |
hasso | fa2b17e | 2004-03-04 17:45:00 +0000 | [diff] [blame] | 764 | default: |
| 765 | /* do nothing */ |
| 766 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 767 | } |
| 768 | num++; |
| 769 | } |
| 770 | stream_putc_at (s, nump, num); |
| 771 | } |
| 772 | else |
| 773 | { |
| 774 | stream_putl (s, 0); |
| 775 | stream_putc (s, 0); |
| 776 | } |
| 777 | |
| 778 | stream_putw_at (s, 0, stream_get_endp (s)); |
| 779 | |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 780 | return zebra_server_send_message(client); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 781 | } |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 782 | |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 783 | /* Router-id is updated. Send ZEBRA_ROUTER_ID_ADD to client. */ |
| 784 | int |
Feng Lu | ac19a44 | 2015-05-22 11:40:07 +0200 | [diff] [blame] | 785 | zsend_router_id_update (struct zserv *client, struct prefix *p, |
| 786 | vrf_id_t vrf_id) |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 787 | { |
| 788 | struct stream *s; |
| 789 | int blen; |
| 790 | |
| 791 | /* Check this client need interface information. */ |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 792 | if (! vrf_bitmap_check (client->ridinfo, vrf_id)) |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 793 | return 0; |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 794 | |
| 795 | s = client->obuf; |
| 796 | stream_reset (s); |
| 797 | |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 798 | /* Message type. */ |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 799 | zserv_create_header (s, ZEBRA_ROUTER_ID_UPDATE, vrf_id); |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 800 | |
| 801 | /* Prefix information. */ |
| 802 | stream_putc (s, p->family); |
| 803 | blen = prefix_blen (p); |
| 804 | stream_put (s, &p->u.prefix, blen); |
| 805 | stream_putc (s, p->prefixlen); |
| 806 | |
| 807 | /* Write packet size. */ |
| 808 | stream_putw_at (s, 0, stream_get_endp (s)); |
| 809 | |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 810 | return zebra_server_send_message(client); |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 811 | } |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 812 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 813 | /* Register zebra server interface information. Send current all |
| 814 | interface and address information. */ |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 815 | static int |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 816 | zread_interface_add (struct zserv *client, u_short length, vrf_id_t vrf_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 817 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 818 | struct listnode *ifnode, *ifnnode; |
| 819 | struct listnode *cnode, *cnnode; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 820 | struct interface *ifp; |
| 821 | struct connected *c; |
| 822 | |
| 823 | /* Interface information is needed. */ |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 824 | vrf_bitmap_set (client->ifinfo, vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 825 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 826 | for (ALL_LIST_ELEMENTS (vrf_iflist (vrf_id), ifnode, ifnnode, ifp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 827 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 828 | /* Skip pseudo interface. */ |
| 829 | if (! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)) |
| 830 | continue; |
| 831 | |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 832 | if (zsend_interface_add (client, ifp) < 0) |
| 833 | return -1; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 834 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 835 | for (ALL_LIST_ELEMENTS (ifp->connected, cnode, cnnode, c)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 836 | { |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 837 | if (CHECK_FLAG (c->conf, ZEBRA_IFC_REAL) && |
| 838 | (zsend_interface_address (ZEBRA_INTERFACE_ADDRESS_ADD, client, |
| 839 | ifp, c) < 0)) |
| 840 | return -1; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 841 | } |
| 842 | } |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 843 | return 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | /* Unregister zebra server interface information. */ |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 847 | static int |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 848 | zread_interface_delete (struct zserv *client, u_short length, vrf_id_t vrf_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 849 | { |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 850 | vrf_bitmap_unset (client->ifinfo, vrf_id); |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 851 | return 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | /* This function support multiple nexthop. */ |
paul | b9df2d2 | 2004-05-09 09:09:59 +0000 | [diff] [blame] | 855 | /* |
| 856 | * Parse the ZEBRA_IPV4_ROUTE_ADD sent from client. Update rib and |
| 857 | * add kernel route. |
| 858 | */ |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 859 | static int |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 860 | zread_ipv4_add (struct zserv *client, u_short length, vrf_id_t vrf_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 861 | { |
| 862 | int i; |
| 863 | struct rib *rib; |
| 864 | struct prefix_ipv4 p; |
| 865 | u_char message; |
| 866 | struct in_addr nexthop; |
| 867 | u_char nexthop_num; |
| 868 | u_char nexthop_type; |
| 869 | struct stream *s; |
Paul Jakma | 9099f9b | 2016-01-18 10:12:10 +0000 | [diff] [blame] | 870 | ifindex_t ifindex; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 871 | u_char ifname_len; |
G.Balaji | cddf391 | 2011-11-26 21:59:32 +0400 | [diff] [blame] | 872 | safi_t safi; |
| 873 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 874 | |
| 875 | /* Get input stream. */ |
| 876 | s = client->ibuf; |
| 877 | |
| 878 | /* Allocate new rib. */ |
paul | 4d38fdb | 2005-04-28 17:35:14 +0000 | [diff] [blame] | 879 | rib = XCALLOC (MTYPE_RIB, sizeof (struct rib)); |
| 880 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 881 | /* Type, flags, message. */ |
| 882 | rib->type = stream_getc (s); |
| 883 | rib->flags = stream_getc (s); |
paul | b9df2d2 | 2004-05-09 09:09:59 +0000 | [diff] [blame] | 884 | message = stream_getc (s); |
G.Balaji | cddf391 | 2011-11-26 21:59:32 +0400 | [diff] [blame] | 885 | safi = stream_getw (s); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 886 | rib->uptime = time (NULL); |
| 887 | |
| 888 | /* IPv4 prefix. */ |
| 889 | memset (&p, 0, sizeof (struct prefix_ipv4)); |
| 890 | p.family = AF_INET; |
| 891 | p.prefixlen = stream_getc (s); |
| 892 | stream_get (&p.prefix, s, PSIZE (p.prefixlen)); |
| 893 | |
Feng Lu | 0d0686f | 2015-05-22 11:40:02 +0200 | [diff] [blame] | 894 | /* VRF ID */ |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 895 | rib->vrf_id = vrf_id; |
Feng Lu | 0d0686f | 2015-05-22 11:40:02 +0200 | [diff] [blame] | 896 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 897 | /* Nexthop parse. */ |
| 898 | if (CHECK_FLAG (message, ZAPI_MESSAGE_NEXTHOP)) |
| 899 | { |
| 900 | nexthop_num = stream_getc (s); |
| 901 | |
| 902 | for (i = 0; i < nexthop_num; i++) |
| 903 | { |
| 904 | nexthop_type = stream_getc (s); |
| 905 | |
| 906 | switch (nexthop_type) |
| 907 | { |
| 908 | case ZEBRA_NEXTHOP_IFINDEX: |
| 909 | ifindex = stream_getl (s); |
| 910 | nexthop_ifindex_add (rib, ifindex); |
| 911 | break; |
| 912 | case ZEBRA_NEXTHOP_IFNAME: |
| 913 | ifname_len = stream_getc (s); |
paul | 9985f83 | 2005-02-09 15:51:56 +0000 | [diff] [blame] | 914 | stream_forward_getp (s, ifname_len); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 915 | break; |
| 916 | case ZEBRA_NEXTHOP_IPV4: |
| 917 | nexthop.s_addr = stream_get_ipv4 (s); |
Paul Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 918 | nexthop_ipv4_add (rib, &nexthop, NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 919 | break; |
Joakim Tjernlund | c963c20 | 2012-07-07 17:06:13 +0200 | [diff] [blame] | 920 | case ZEBRA_NEXTHOP_IPV4_IFINDEX: |
| 921 | nexthop.s_addr = stream_get_ipv4 (s); |
| 922 | ifindex = stream_getl (s); |
| 923 | nexthop_ipv4_ifindex_add (rib, &nexthop, NULL, ifindex); |
| 924 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 925 | case ZEBRA_NEXTHOP_IPV6: |
paul | 9985f83 | 2005-02-09 15:51:56 +0000 | [diff] [blame] | 926 | stream_forward_getp (s, IPV6_MAX_BYTELEN); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 927 | break; |
Subbaiah Venkata | 6902c69 | 2012-03-27 19:21:29 -0700 | [diff] [blame] | 928 | case ZEBRA_NEXTHOP_BLACKHOLE: |
| 929 | nexthop_blackhole_add (rib); |
| 930 | break; |
| 931 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 932 | } |
| 933 | } |
| 934 | |
| 935 | /* Distance. */ |
| 936 | if (CHECK_FLAG (message, ZAPI_MESSAGE_DISTANCE)) |
| 937 | rib->distance = stream_getc (s); |
| 938 | |
| 939 | /* Metric. */ |
| 940 | if (CHECK_FLAG (message, ZAPI_MESSAGE_METRIC)) |
| 941 | rib->metric = stream_getl (s); |
| 942 | |
Timo Teräs | b11f3b5 | 2015-11-02 16:50:07 +0200 | [diff] [blame] | 943 | if (CHECK_FLAG (message, ZAPI_MESSAGE_MTU)) |
| 944 | rib->mtu = stream_getl (s); |
| 945 | |
Paul Jakma | 171eee3 | 2006-07-27 16:11:02 +0000 | [diff] [blame] | 946 | /* Table */ |
| 947 | rib->table=zebrad.rtm_table_default; |
G.Balaji | cddf391 | 2011-11-26 21:59:32 +0400 | [diff] [blame] | 948 | rib_add_ipv4_multipath (&p, rib, safi); |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 949 | return 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | /* Zebra server IPv4 prefix delete function. */ |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 953 | static int |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 954 | zread_ipv4_delete (struct zserv *client, u_short length, vrf_id_t vrf_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 955 | { |
| 956 | int i; |
| 957 | struct stream *s; |
| 958 | struct zapi_ipv4 api; |
Subbaiah Venkata | 6902c69 | 2012-03-27 19:21:29 -0700 | [diff] [blame] | 959 | struct in_addr nexthop, *nexthop_p; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 960 | unsigned long ifindex; |
| 961 | struct prefix_ipv4 p; |
| 962 | u_char nexthop_num; |
| 963 | u_char nexthop_type; |
| 964 | u_char ifname_len; |
| 965 | |
| 966 | s = client->ibuf; |
| 967 | ifindex = 0; |
| 968 | nexthop.s_addr = 0; |
Subbaiah Venkata | 6902c69 | 2012-03-27 19:21:29 -0700 | [diff] [blame] | 969 | nexthop_p = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 970 | |
| 971 | /* Type, flags, message. */ |
| 972 | api.type = stream_getc (s); |
| 973 | api.flags = stream_getc (s); |
| 974 | api.message = stream_getc (s); |
G.Balaji | cddf391 | 2011-11-26 21:59:32 +0400 | [diff] [blame] | 975 | api.safi = stream_getw (s); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 976 | |
| 977 | /* IPv4 prefix. */ |
| 978 | memset (&p, 0, sizeof (struct prefix_ipv4)); |
| 979 | p.family = AF_INET; |
| 980 | p.prefixlen = stream_getc (s); |
| 981 | stream_get (&p.prefix, s, PSIZE (p.prefixlen)); |
| 982 | |
| 983 | /* Nexthop, ifindex, distance, metric. */ |
| 984 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP)) |
| 985 | { |
| 986 | nexthop_num = stream_getc (s); |
| 987 | |
| 988 | for (i = 0; i < nexthop_num; i++) |
| 989 | { |
| 990 | nexthop_type = stream_getc (s); |
| 991 | |
| 992 | switch (nexthop_type) |
| 993 | { |
| 994 | case ZEBRA_NEXTHOP_IFINDEX: |
| 995 | ifindex = stream_getl (s); |
| 996 | break; |
| 997 | case ZEBRA_NEXTHOP_IFNAME: |
| 998 | ifname_len = stream_getc (s); |
paul | 9985f83 | 2005-02-09 15:51:56 +0000 | [diff] [blame] | 999 | stream_forward_getp (s, ifname_len); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1000 | break; |
| 1001 | case ZEBRA_NEXTHOP_IPV4: |
| 1002 | nexthop.s_addr = stream_get_ipv4 (s); |
Subbaiah Venkata | 6902c69 | 2012-03-27 19:21:29 -0700 | [diff] [blame] | 1003 | nexthop_p = &nexthop; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1004 | break; |
Joakim Tjernlund | c963c20 | 2012-07-07 17:06:13 +0200 | [diff] [blame] | 1005 | case ZEBRA_NEXTHOP_IPV4_IFINDEX: |
| 1006 | nexthop.s_addr = stream_get_ipv4 (s); |
Christian Franke | 23f5f7c | 2013-11-27 17:06:14 +0000 | [diff] [blame] | 1007 | nexthop_p = &nexthop; |
Joakim Tjernlund | c963c20 | 2012-07-07 17:06:13 +0200 | [diff] [blame] | 1008 | ifindex = stream_getl (s); |
| 1009 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1010 | case ZEBRA_NEXTHOP_IPV6: |
paul | 9985f83 | 2005-02-09 15:51:56 +0000 | [diff] [blame] | 1011 | stream_forward_getp (s, IPV6_MAX_BYTELEN); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1012 | break; |
| 1013 | } |
| 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | /* Distance. */ |
| 1018 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE)) |
| 1019 | api.distance = stream_getc (s); |
| 1020 | else |
| 1021 | api.distance = 0; |
| 1022 | |
| 1023 | /* Metric. */ |
| 1024 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC)) |
| 1025 | api.metric = stream_getl (s); |
| 1026 | else |
| 1027 | api.metric = 0; |
| 1028 | |
Subbaiah Venkata | 6902c69 | 2012-03-27 19:21:29 -0700 | [diff] [blame] | 1029 | rib_delete_ipv4 (api.type, api.flags, &p, nexthop_p, ifindex, |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1030 | vrf_id, api.safi); |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 1031 | return 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | /* Nexthop lookup for IPv4. */ |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 1035 | static int |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1036 | zread_ipv4_nexthop_lookup (struct zserv *client, u_short length, |
| 1037 | vrf_id_t vrf_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1038 | { |
| 1039 | struct in_addr addr; |
Christian Franke | bb97e46 | 2013-05-25 14:01:35 +0000 | [diff] [blame] | 1040 | char buf[BUFSIZ]; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1041 | |
| 1042 | addr.s_addr = stream_get_ipv4 (client->ibuf); |
Christian Franke | bb97e46 | 2013-05-25 14:01:35 +0000 | [diff] [blame] | 1043 | if (IS_ZEBRA_DEBUG_PACKET && IS_ZEBRA_DEBUG_RECV) |
| 1044 | zlog_debug("%s: looking up %s", __func__, |
| 1045 | inet_ntop (AF_INET, &addr, buf, BUFSIZ)); |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1046 | return zsend_ipv4_nexthop_lookup (client, addr, vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1047 | } |
| 1048 | |
Everton Marques | 4e5275b | 2014-07-01 15:15:52 -0300 | [diff] [blame] | 1049 | /* MRIB Nexthop lookup for IPv4. */ |
| 1050 | static int |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1051 | zread_ipv4_nexthop_lookup_mrib (struct zserv *client, u_short length, |
| 1052 | vrf_id_t vrf_id) |
Everton Marques | 4e5275b | 2014-07-01 15:15:52 -0300 | [diff] [blame] | 1053 | { |
| 1054 | struct in_addr addr; |
David Lamparter | bd07812 | 2015-01-06 19:53:24 +0100 | [diff] [blame] | 1055 | struct rib *rib; |
Everton Marques | 4e5275b | 2014-07-01 15:15:52 -0300 | [diff] [blame] | 1056 | |
| 1057 | addr.s_addr = stream_get_ipv4 (client->ibuf); |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1058 | rib = rib_match_ipv4_multicast (addr, NULL, vrf_id); |
David Lamparter | bd07812 | 2015-01-06 19:53:24 +0100 | [diff] [blame] | 1059 | return zsend_ipv4_nexthop_lookup_mrib (client, addr, rib); |
Everton Marques | 4e5275b | 2014-07-01 15:15:52 -0300 | [diff] [blame] | 1060 | } |
| 1061 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1062 | /* Nexthop lookup for IPv4. */ |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 1063 | static int |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1064 | zread_ipv4_import_lookup (struct zserv *client, u_short length, |
| 1065 | vrf_id_t vrf_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1066 | { |
| 1067 | struct prefix_ipv4 p; |
| 1068 | |
| 1069 | p.family = AF_INET; |
| 1070 | p.prefixlen = stream_getc (client->ibuf); |
| 1071 | p.prefix.s_addr = stream_get_ipv4 (client->ibuf); |
| 1072 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1073 | return zsend_ipv4_import_lookup (client, &p, vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1074 | } |
| 1075 | |
| 1076 | #ifdef HAVE_IPV6 |
| 1077 | /* Zebra server IPv6 prefix add function. */ |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 1078 | static int |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1079 | zread_ipv6_add (struct zserv *client, u_short length, vrf_id_t vrf_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1080 | { |
| 1081 | int i; |
| 1082 | struct stream *s; |
| 1083 | struct zapi_ipv6 api; |
| 1084 | struct in6_addr nexthop; |
| 1085 | unsigned long ifindex; |
| 1086 | struct prefix_ipv6 p; |
| 1087 | |
| 1088 | s = client->ibuf; |
| 1089 | ifindex = 0; |
| 1090 | memset (&nexthop, 0, sizeof (struct in6_addr)); |
| 1091 | |
| 1092 | /* Type, flags, message. */ |
| 1093 | api.type = stream_getc (s); |
| 1094 | api.flags = stream_getc (s); |
| 1095 | api.message = stream_getc (s); |
G.Balaji | f768f36 | 2011-11-26 22:10:39 +0400 | [diff] [blame] | 1096 | api.safi = stream_getw (s); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1097 | |
| 1098 | /* IPv4 prefix. */ |
| 1099 | memset (&p, 0, sizeof (struct prefix_ipv6)); |
| 1100 | p.family = AF_INET6; |
| 1101 | p.prefixlen = stream_getc (s); |
| 1102 | stream_get (&p.prefix, s, PSIZE (p.prefixlen)); |
| 1103 | |
| 1104 | /* Nexthop, ifindex, distance, metric. */ |
| 1105 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP)) |
| 1106 | { |
| 1107 | u_char nexthop_type; |
| 1108 | |
| 1109 | api.nexthop_num = stream_getc (s); |
| 1110 | for (i = 0; i < api.nexthop_num; i++) |
| 1111 | { |
| 1112 | nexthop_type = stream_getc (s); |
| 1113 | |
| 1114 | switch (nexthop_type) |
| 1115 | { |
| 1116 | case ZEBRA_NEXTHOP_IPV6: |
| 1117 | stream_get (&nexthop, s, 16); |
| 1118 | break; |
| 1119 | case ZEBRA_NEXTHOP_IFINDEX: |
| 1120 | ifindex = stream_getl (s); |
| 1121 | break; |
| 1122 | } |
| 1123 | } |
| 1124 | } |
| 1125 | |
| 1126 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE)) |
| 1127 | api.distance = stream_getc (s); |
| 1128 | else |
| 1129 | api.distance = 0; |
| 1130 | |
| 1131 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC)) |
| 1132 | api.metric = stream_getl (s); |
| 1133 | else |
| 1134 | api.metric = 0; |
Timo Teräs | b11f3b5 | 2015-11-02 16:50:07 +0200 | [diff] [blame] | 1135 | |
| 1136 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_MTU)) |
| 1137 | api.mtu = stream_getl (s); |
| 1138 | else |
| 1139 | api.mtu = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1140 | |
| 1141 | if (IN6_IS_ADDR_UNSPECIFIED (&nexthop)) |
Feng Lu | 0d0686f | 2015-05-22 11:40:02 +0200 | [diff] [blame] | 1142 | rib_add_ipv6 (api.type, api.flags, &p, NULL, ifindex, |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1143 | vrf_id, zebrad.rtm_table_default, api.metric, |
Timo Teräs | b11f3b5 | 2015-11-02 16:50:07 +0200 | [diff] [blame] | 1144 | api.mtu, api.distance, api.safi); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1145 | else |
Feng Lu | 0d0686f | 2015-05-22 11:40:02 +0200 | [diff] [blame] | 1146 | rib_add_ipv6 (api.type, api.flags, &p, &nexthop, ifindex, |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1147 | vrf_id, zebrad.rtm_table_default, api.metric, |
Timo Teräs | b11f3b5 | 2015-11-02 16:50:07 +0200 | [diff] [blame] | 1148 | api.mtu, api.distance, api.safi); |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 1149 | return 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | /* Zebra server IPv6 prefix delete function. */ |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 1153 | static int |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1154 | zread_ipv6_delete (struct zserv *client, u_short length, vrf_id_t vrf_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1155 | { |
| 1156 | int i; |
| 1157 | struct stream *s; |
| 1158 | struct zapi_ipv6 api; |
| 1159 | struct in6_addr nexthop; |
| 1160 | unsigned long ifindex; |
| 1161 | struct prefix_ipv6 p; |
| 1162 | |
| 1163 | s = client->ibuf; |
| 1164 | ifindex = 0; |
| 1165 | memset (&nexthop, 0, sizeof (struct in6_addr)); |
| 1166 | |
| 1167 | /* Type, flags, message. */ |
| 1168 | api.type = stream_getc (s); |
| 1169 | api.flags = stream_getc (s); |
| 1170 | api.message = stream_getc (s); |
G.Balaji | f768f36 | 2011-11-26 22:10:39 +0400 | [diff] [blame] | 1171 | api.safi = stream_getw (s); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1172 | |
| 1173 | /* IPv4 prefix. */ |
| 1174 | memset (&p, 0, sizeof (struct prefix_ipv6)); |
| 1175 | p.family = AF_INET6; |
| 1176 | p.prefixlen = stream_getc (s); |
| 1177 | stream_get (&p.prefix, s, PSIZE (p.prefixlen)); |
| 1178 | |
| 1179 | /* Nexthop, ifindex, distance, metric. */ |
| 1180 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP)) |
| 1181 | { |
| 1182 | u_char nexthop_type; |
| 1183 | |
| 1184 | api.nexthop_num = stream_getc (s); |
| 1185 | for (i = 0; i < api.nexthop_num; i++) |
| 1186 | { |
| 1187 | nexthop_type = stream_getc (s); |
| 1188 | |
| 1189 | switch (nexthop_type) |
| 1190 | { |
| 1191 | case ZEBRA_NEXTHOP_IPV6: |
| 1192 | stream_get (&nexthop, s, 16); |
| 1193 | break; |
| 1194 | case ZEBRA_NEXTHOP_IFINDEX: |
| 1195 | ifindex = stream_getl (s); |
| 1196 | break; |
| 1197 | } |
| 1198 | } |
| 1199 | } |
| 1200 | |
| 1201 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE)) |
| 1202 | api.distance = stream_getc (s); |
| 1203 | else |
| 1204 | api.distance = 0; |
| 1205 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC)) |
| 1206 | api.metric = stream_getl (s); |
| 1207 | else |
| 1208 | api.metric = 0; |
| 1209 | |
| 1210 | if (IN6_IS_ADDR_UNSPECIFIED (&nexthop)) |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1211 | rib_delete_ipv6 (api.type, api.flags, &p, NULL, ifindex, vrf_id, |
Feng Lu | 0d0686f | 2015-05-22 11:40:02 +0200 | [diff] [blame] | 1212 | api.safi); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1213 | else |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1214 | rib_delete_ipv6 (api.type, api.flags, &p, &nexthop, ifindex, vrf_id, |
Feng Lu | 0d0686f | 2015-05-22 11:40:02 +0200 | [diff] [blame] | 1215 | api.safi); |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 1216 | return 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1217 | } |
| 1218 | |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 1219 | static int |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1220 | zread_ipv6_nexthop_lookup (struct zserv *client, u_short length, |
| 1221 | vrf_id_t vrf_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1222 | { |
| 1223 | struct in6_addr addr; |
| 1224 | char buf[BUFSIZ]; |
| 1225 | |
| 1226 | stream_get (&addr, client->ibuf, 16); |
Christian Franke | a520708 | 2013-04-11 08:24:29 +0000 | [diff] [blame] | 1227 | if (IS_ZEBRA_DEBUG_PACKET && IS_ZEBRA_DEBUG_RECV) |
| 1228 | zlog_debug("%s: looking up %s", __func__, |
| 1229 | inet_ntop (AF_INET6, &addr, buf, BUFSIZ)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1230 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1231 | return zsend_ipv6_nexthop_lookup (client, &addr, vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1232 | } |
| 1233 | #endif /* HAVE_IPV6 */ |
| 1234 | |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 1235 | /* Register zebra server router-id information. Send current router-id */ |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 1236 | static int |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1237 | zread_router_id_add (struct zserv *client, u_short length, vrf_id_t vrf_id) |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 1238 | { |
| 1239 | struct prefix p; |
| 1240 | |
| 1241 | /* Router-id information is needed. */ |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1242 | vrf_bitmap_set (client->ridinfo, vrf_id); |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 1243 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1244 | router_id_get (&p, vrf_id); |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 1245 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1246 | return zsend_router_id_update (client, &p, vrf_id); |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 1247 | } |
| 1248 | |
| 1249 | /* Unregister zebra server router-id information. */ |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 1250 | static int |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1251 | zread_router_id_delete (struct zserv *client, u_short length, vrf_id_t vrf_id) |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 1252 | { |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1253 | vrf_bitmap_unset (client->ridinfo, vrf_id); |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 1254 | return 0; |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 1255 | } |
| 1256 | |
Vyacheslav Trushkin | 2ea1ab1 | 2011-12-11 18:48:47 +0400 | [diff] [blame] | 1257 | /* Tie up route-type and client->sock */ |
| 1258 | static void |
| 1259 | zread_hello (struct zserv *client) |
| 1260 | { |
| 1261 | /* type of protocol (lib/zebra.h) */ |
| 1262 | u_char proto; |
| 1263 | proto = stream_getc (client->ibuf); |
| 1264 | |
| 1265 | /* accept only dynamic routing protocols */ |
| 1266 | if ((proto < ZEBRA_ROUTE_MAX) |
| 1267 | && (proto > ZEBRA_ROUTE_STATIC)) |
| 1268 | { |
| 1269 | zlog_notice ("client %d says hello and bids fair to announce only %s routes", |
| 1270 | client->sock, zebra_route_string(proto)); |
| 1271 | |
| 1272 | /* if route-type was binded by other client */ |
| 1273 | if (route_type_oaths[proto]) |
| 1274 | zlog_warn ("sender of %s routes changed %c->%c", |
| 1275 | zebra_route_string(proto), route_type_oaths[proto], |
| 1276 | client->sock); |
| 1277 | |
| 1278 | route_type_oaths[proto] = client->sock; |
| 1279 | } |
| 1280 | } |
| 1281 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1282 | /* Unregister all information in a VRF. */ |
| 1283 | static int |
| 1284 | zread_vrf_unregister (struct zserv *client, u_short length, vrf_id_t vrf_id) |
| 1285 | { |
| 1286 | int i; |
| 1287 | |
| 1288 | for (i = 0; i < ZEBRA_ROUTE_MAX; i++) |
| 1289 | vrf_bitmap_unset (client->redist[i], vrf_id); |
| 1290 | vrf_bitmap_unset (client->redist_default, vrf_id); |
| 1291 | vrf_bitmap_unset (client->ifinfo, vrf_id); |
| 1292 | vrf_bitmap_unset (client->ridinfo, vrf_id); |
| 1293 | |
| 1294 | return 0; |
| 1295 | } |
| 1296 | |
Vyacheslav Trushkin | 2ea1ab1 | 2011-12-11 18:48:47 +0400 | [diff] [blame] | 1297 | /* If client sent routes of specific type, zebra removes it |
| 1298 | * and returns number of deleted routes. |
| 1299 | */ |
| 1300 | static void |
| 1301 | zebra_score_rib (int client_sock) |
| 1302 | { |
| 1303 | int i; |
| 1304 | |
| 1305 | for (i = ZEBRA_ROUTE_RIP; i < ZEBRA_ROUTE_MAX; i++) |
| 1306 | if (client_sock == route_type_oaths[i]) |
| 1307 | { |
| 1308 | zlog_notice ("client %d disconnected. %lu %s routes removed from the rib", |
| 1309 | client_sock, rib_score_proto (i), zebra_route_string (i)); |
| 1310 | route_type_oaths[i] = 0; |
| 1311 | break; |
| 1312 | } |
| 1313 | } |
| 1314 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1315 | /* Close zebra client. */ |
paul | b9df2d2 | 2004-05-09 09:09:59 +0000 | [diff] [blame] | 1316 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1317 | zebra_client_close (struct zserv *client) |
| 1318 | { |
| 1319 | /* Close file descriptor. */ |
| 1320 | if (client->sock) |
| 1321 | { |
| 1322 | close (client->sock); |
Vyacheslav Trushkin | 2ea1ab1 | 2011-12-11 18:48:47 +0400 | [diff] [blame] | 1323 | zebra_score_rib (client->sock); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1324 | client->sock = -1; |
| 1325 | } |
| 1326 | |
| 1327 | /* Free stream buffers. */ |
| 1328 | if (client->ibuf) |
| 1329 | stream_free (client->ibuf); |
| 1330 | if (client->obuf) |
| 1331 | stream_free (client->obuf); |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 1332 | if (client->wb) |
| 1333 | buffer_free(client->wb); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1334 | |
| 1335 | /* Release threads. */ |
| 1336 | if (client->t_read) |
| 1337 | thread_cancel (client->t_read); |
| 1338 | if (client->t_write) |
| 1339 | thread_cancel (client->t_write); |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 1340 | if (client->t_suicide) |
| 1341 | thread_cancel (client->t_suicide); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1342 | |
| 1343 | /* Free client structure. */ |
paul | b21b19c | 2003-06-15 01:28:29 +0000 | [diff] [blame] | 1344 | listnode_delete (zebrad.client_list, client); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1345 | XFREE (0, client); |
| 1346 | } |
| 1347 | |
| 1348 | /* Make new client. */ |
paul | b9df2d2 | 2004-05-09 09:09:59 +0000 | [diff] [blame] | 1349 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1350 | zebra_client_create (int sock) |
| 1351 | { |
| 1352 | struct zserv *client; |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1353 | int i; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1354 | |
David Lamparter | 23757db | 2016-02-24 06:26:02 +0100 | [diff] [blame] | 1355 | client = XCALLOC (MTYPE_TMP, sizeof (struct zserv)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1356 | |
| 1357 | /* Make client input/output buffer. */ |
| 1358 | client->sock = sock; |
| 1359 | client->ibuf = stream_new (ZEBRA_MAX_PACKET_SIZ); |
| 1360 | client->obuf = stream_new (ZEBRA_MAX_PACKET_SIZ); |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 1361 | client->wb = buffer_new(0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1362 | |
| 1363 | /* Set table number. */ |
paul | b21b19c | 2003-06-15 01:28:29 +0000 | [diff] [blame] | 1364 | client->rtm_table = zebrad.rtm_table_default; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1365 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1366 | /* Initialize flags */ |
| 1367 | for (i = 0; i < ZEBRA_ROUTE_MAX; i++) |
| 1368 | client->redist[i] = vrf_bitmap_init (); |
| 1369 | client->redist_default = vrf_bitmap_init (); |
| 1370 | client->ifinfo = vrf_bitmap_init (); |
| 1371 | client->ridinfo = vrf_bitmap_init (); |
| 1372 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1373 | /* Add this client to linked list. */ |
paul | b21b19c | 2003-06-15 01:28:29 +0000 | [diff] [blame] | 1374 | listnode_add (zebrad.client_list, client); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1375 | |
| 1376 | /* Make new read thread. */ |
| 1377 | zebra_event (ZEBRA_READ, sock, client); |
| 1378 | } |
| 1379 | |
| 1380 | /* Handler of zebra service request. */ |
paul | b9df2d2 | 2004-05-09 09:09:59 +0000 | [diff] [blame] | 1381 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1382 | zebra_client_read (struct thread *thread) |
| 1383 | { |
| 1384 | int sock; |
| 1385 | struct zserv *client; |
ajs | 57a1477 | 2005-04-10 15:01:56 +0000 | [diff] [blame] | 1386 | size_t already; |
paul | c1b9800 | 2006-01-16 01:54:02 +0000 | [diff] [blame] | 1387 | uint16_t length, command; |
| 1388 | uint8_t marker, version; |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1389 | vrf_id_t vrf_id; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1390 | |
| 1391 | /* Get thread data. Reset reading thread because I'm running. */ |
| 1392 | sock = THREAD_FD (thread); |
| 1393 | client = THREAD_ARG (thread); |
| 1394 | client->t_read = NULL; |
| 1395 | |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 1396 | if (client->t_suicide) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1397 | { |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 1398 | zebra_client_close(client); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1399 | return -1; |
| 1400 | } |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 1401 | |
| 1402 | /* Read length and command (if we don't have it already). */ |
ajs | 57a1477 | 2005-04-10 15:01:56 +0000 | [diff] [blame] | 1403 | if ((already = stream_get_endp(client->ibuf)) < ZEBRA_HEADER_SIZE) |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 1404 | { |
ajs | 57a1477 | 2005-04-10 15:01:56 +0000 | [diff] [blame] | 1405 | ssize_t nbyte; |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 1406 | if (((nbyte = stream_read_try (client->ibuf, sock, |
ajs | 57a1477 | 2005-04-10 15:01:56 +0000 | [diff] [blame] | 1407 | ZEBRA_HEADER_SIZE-already)) == 0) || |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 1408 | (nbyte == -1)) |
| 1409 | { |
| 1410 | if (IS_ZEBRA_DEBUG_EVENT) |
| 1411 | zlog_debug ("connection closed socket [%d]", sock); |
| 1412 | zebra_client_close (client); |
| 1413 | return -1; |
| 1414 | } |
ajs | 57a1477 | 2005-04-10 15:01:56 +0000 | [diff] [blame] | 1415 | if (nbyte != (ssize_t)(ZEBRA_HEADER_SIZE-already)) |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 1416 | { |
| 1417 | /* Try again later. */ |
| 1418 | zebra_event (ZEBRA_READ, sock, client); |
| 1419 | return 0; |
| 1420 | } |
ajs | 57a1477 | 2005-04-10 15:01:56 +0000 | [diff] [blame] | 1421 | already = ZEBRA_HEADER_SIZE; |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 1422 | } |
| 1423 | |
| 1424 | /* Reset to read from the beginning of the incoming packet. */ |
| 1425 | stream_set_getp(client->ibuf, 0); |
| 1426 | |
paul | c1b9800 | 2006-01-16 01:54:02 +0000 | [diff] [blame] | 1427 | /* Fetch header values */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1428 | length = stream_getw (client->ibuf); |
paul | c1b9800 | 2006-01-16 01:54:02 +0000 | [diff] [blame] | 1429 | marker = stream_getc (client->ibuf); |
| 1430 | version = stream_getc (client->ibuf); |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1431 | vrf_id = stream_getw (client->ibuf); |
paul | c1b9800 | 2006-01-16 01:54:02 +0000 | [diff] [blame] | 1432 | command = stream_getw (client->ibuf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1433 | |
paul | c1b9800 | 2006-01-16 01:54:02 +0000 | [diff] [blame] | 1434 | if (marker != ZEBRA_HEADER_MARKER || version != ZSERV_VERSION) |
| 1435 | { |
| 1436 | zlog_err("%s: socket %d version mismatch, marker %d, version %d", |
| 1437 | __func__, sock, marker, version); |
| 1438 | zebra_client_close (client); |
| 1439 | return -1; |
| 1440 | } |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 1441 | if (length < ZEBRA_HEADER_SIZE) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1442 | { |
ajs | 57a1477 | 2005-04-10 15:01:56 +0000 | [diff] [blame] | 1443 | zlog_warn("%s: socket %d message length %u is less than header size %d", |
| 1444 | __func__, sock, length, ZEBRA_HEADER_SIZE); |
| 1445 | zebra_client_close (client); |
| 1446 | return -1; |
| 1447 | } |
| 1448 | if (length > STREAM_SIZE(client->ibuf)) |
| 1449 | { |
| 1450 | zlog_warn("%s: socket %d message length %u exceeds buffer size %lu", |
| 1451 | __func__, sock, length, (u_long)STREAM_SIZE(client->ibuf)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1452 | zebra_client_close (client); |
| 1453 | return -1; |
| 1454 | } |
| 1455 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1456 | /* Read rest of data. */ |
ajs | 57a1477 | 2005-04-10 15:01:56 +0000 | [diff] [blame] | 1457 | if (already < length) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1458 | { |
ajs | 57a1477 | 2005-04-10 15:01:56 +0000 | [diff] [blame] | 1459 | ssize_t nbyte; |
| 1460 | if (((nbyte = stream_read_try (client->ibuf, sock, |
| 1461 | length-already)) == 0) || |
| 1462 | (nbyte == -1)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1463 | { |
| 1464 | if (IS_ZEBRA_DEBUG_EVENT) |
ajs | b617800 | 2004-12-07 21:12:56 +0000 | [diff] [blame] | 1465 | zlog_debug ("connection closed [%d] when reading zebra data", sock); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1466 | zebra_client_close (client); |
| 1467 | return -1; |
| 1468 | } |
ajs | 57a1477 | 2005-04-10 15:01:56 +0000 | [diff] [blame] | 1469 | if (nbyte != (ssize_t)(length-already)) |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 1470 | { |
| 1471 | /* Try again later. */ |
| 1472 | zebra_event (ZEBRA_READ, sock, client); |
| 1473 | return 0; |
| 1474 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1475 | } |
| 1476 | |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 1477 | length -= ZEBRA_HEADER_SIZE; |
| 1478 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1479 | /* Debug packet information. */ |
| 1480 | if (IS_ZEBRA_DEBUG_EVENT) |
ajs | b617800 | 2004-12-07 21:12:56 +0000 | [diff] [blame] | 1481 | zlog_debug ("zebra message comes from socket [%d]", sock); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1482 | |
| 1483 | if (IS_ZEBRA_DEBUG_PACKET && IS_ZEBRA_DEBUG_RECV) |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1484 | zlog_debug ("zebra message received [%s] %d in VRF %u", |
| 1485 | zserv_command_string (command), length, vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1486 | |
| 1487 | switch (command) |
| 1488 | { |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 1489 | case ZEBRA_ROUTER_ID_ADD: |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1490 | zread_router_id_add (client, length, vrf_id); |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 1491 | break; |
| 1492 | case ZEBRA_ROUTER_ID_DELETE: |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1493 | zread_router_id_delete (client, length, vrf_id); |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 1494 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1495 | case ZEBRA_INTERFACE_ADD: |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1496 | zread_interface_add (client, length, vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1497 | break; |
| 1498 | case ZEBRA_INTERFACE_DELETE: |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1499 | zread_interface_delete (client, length, vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1500 | break; |
| 1501 | case ZEBRA_IPV4_ROUTE_ADD: |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1502 | zread_ipv4_add (client, length, vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1503 | break; |
| 1504 | case ZEBRA_IPV4_ROUTE_DELETE: |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1505 | zread_ipv4_delete (client, length, vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1506 | break; |
| 1507 | #ifdef HAVE_IPV6 |
| 1508 | case ZEBRA_IPV6_ROUTE_ADD: |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1509 | zread_ipv6_add (client, length, vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1510 | break; |
| 1511 | case ZEBRA_IPV6_ROUTE_DELETE: |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1512 | zread_ipv6_delete (client, length, vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1513 | break; |
| 1514 | #endif /* HAVE_IPV6 */ |
| 1515 | case ZEBRA_REDISTRIBUTE_ADD: |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1516 | zebra_redistribute_add (command, client, length, vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1517 | break; |
| 1518 | case ZEBRA_REDISTRIBUTE_DELETE: |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1519 | zebra_redistribute_delete (command, client, length, vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1520 | break; |
| 1521 | case ZEBRA_REDISTRIBUTE_DEFAULT_ADD: |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1522 | zebra_redistribute_default_add (command, client, length, vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1523 | break; |
| 1524 | case ZEBRA_REDISTRIBUTE_DEFAULT_DELETE: |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1525 | zebra_redistribute_default_delete (command, client, length, vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1526 | break; |
| 1527 | case ZEBRA_IPV4_NEXTHOP_LOOKUP: |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1528 | zread_ipv4_nexthop_lookup (client, length, vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1529 | break; |
Everton Marques | 4e5275b | 2014-07-01 15:15:52 -0300 | [diff] [blame] | 1530 | case ZEBRA_IPV4_NEXTHOP_LOOKUP_MRIB: |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1531 | zread_ipv4_nexthop_lookup_mrib (client, length, vrf_id); |
Everton Marques | 4e5275b | 2014-07-01 15:15:52 -0300 | [diff] [blame] | 1532 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1533 | #ifdef HAVE_IPV6 |
| 1534 | case ZEBRA_IPV6_NEXTHOP_LOOKUP: |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1535 | zread_ipv6_nexthop_lookup (client, length, vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1536 | break; |
| 1537 | #endif /* HAVE_IPV6 */ |
| 1538 | case ZEBRA_IPV4_IMPORT_LOOKUP: |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1539 | zread_ipv4_import_lookup (client, length, vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1540 | break; |
Vyacheslav Trushkin | 2ea1ab1 | 2011-12-11 18:48:47 +0400 | [diff] [blame] | 1541 | case ZEBRA_HELLO: |
| 1542 | zread_hello (client); |
| 1543 | break; |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1544 | case ZEBRA_VRF_UNREGISTER: |
| 1545 | zread_vrf_unregister (client, length, vrf_id); |
| 1546 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1547 | default: |
| 1548 | zlog_info ("Zebra received unknown command %d", command); |
| 1549 | break; |
| 1550 | } |
| 1551 | |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 1552 | if (client->t_suicide) |
| 1553 | { |
| 1554 | /* No need to wait for thread callback, just kill immediately. */ |
| 1555 | zebra_client_close(client); |
| 1556 | return -1; |
| 1557 | } |
| 1558 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1559 | stream_reset (client->ibuf); |
| 1560 | zebra_event (ZEBRA_READ, sock, client); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1561 | return 0; |
| 1562 | } |
| 1563 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1564 | |
| 1565 | /* Accept code of zebra server socket. */ |
paul | b9df2d2 | 2004-05-09 09:09:59 +0000 | [diff] [blame] | 1566 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1567 | zebra_accept (struct thread *thread) |
| 1568 | { |
| 1569 | int accept_sock; |
| 1570 | int client_sock; |
| 1571 | struct sockaddr_in client; |
| 1572 | socklen_t len; |
| 1573 | |
| 1574 | accept_sock = THREAD_FD (thread); |
| 1575 | |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 1576 | /* Reregister myself. */ |
| 1577 | zebra_event (ZEBRA_SERV, accept_sock, NULL); |
| 1578 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1579 | len = sizeof (struct sockaddr_in); |
| 1580 | client_sock = accept (accept_sock, (struct sockaddr *) &client, &len); |
| 1581 | |
| 1582 | if (client_sock < 0) |
| 1583 | { |
ajs | 6099b3b | 2004-11-20 02:06:59 +0000 | [diff] [blame] | 1584 | zlog_warn ("Can't accept zebra socket: %s", safe_strerror (errno)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1585 | return -1; |
| 1586 | } |
| 1587 | |
paul | ccf3557 | 2003-03-01 11:42:20 +0000 | [diff] [blame] | 1588 | /* Make client socket non-blocking. */ |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 1589 | set_nonblocking(client_sock); |
paul | 865b852 | 2005-01-05 08:30:35 +0000 | [diff] [blame] | 1590 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1591 | /* Create new zebra client. */ |
| 1592 | zebra_client_create (client_sock); |
| 1593 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1594 | return 0; |
| 1595 | } |
| 1596 | |
paul | b9df2d2 | 2004-05-09 09:09:59 +0000 | [diff] [blame] | 1597 | #ifdef HAVE_TCP_ZEBRA |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1598 | /* Make zebra's server socket. */ |
paul | b9df2d2 | 2004-05-09 09:09:59 +0000 | [diff] [blame] | 1599 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1600 | zebra_serv () |
| 1601 | { |
| 1602 | int ret; |
| 1603 | int accept_sock; |
| 1604 | struct sockaddr_in addr; |
| 1605 | |
| 1606 | accept_sock = socket (AF_INET, SOCK_STREAM, 0); |
| 1607 | |
| 1608 | if (accept_sock < 0) |
| 1609 | { |
paul | 3d1dc85 | 2005-04-05 00:45:23 +0000 | [diff] [blame] | 1610 | zlog_warn ("Can't create zserv stream socket: %s", |
| 1611 | safe_strerror (errno)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1612 | zlog_warn ("zebra can't provice full functionality due to above error"); |
| 1613 | return; |
| 1614 | } |
| 1615 | |
Vyacheslav Trushkin | 2ea1ab1 | 2011-12-11 18:48:47 +0400 | [diff] [blame] | 1616 | memset (&route_type_oaths, 0, sizeof (route_type_oaths)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1617 | memset (&addr, 0, sizeof (struct sockaddr_in)); |
| 1618 | addr.sin_family = AF_INET; |
| 1619 | addr.sin_port = htons (ZEBRA_PORT); |
Paul Jakma | 6f0e3f6 | 2007-05-10 02:38:51 +0000 | [diff] [blame] | 1620 | #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1621 | addr.sin_len = sizeof (struct sockaddr_in); |
Paul Jakma | 6f0e3f6 | 2007-05-10 02:38:51 +0000 | [diff] [blame] | 1622 | #endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1623 | addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); |
| 1624 | |
| 1625 | sockopt_reuseaddr (accept_sock); |
| 1626 | sockopt_reuseport (accept_sock); |
| 1627 | |
paul | edd7c24 | 2003-06-04 13:59:38 +0000 | [diff] [blame] | 1628 | if ( zserv_privs.change(ZPRIVS_RAISE) ) |
| 1629 | zlog (NULL, LOG_ERR, "Can't raise privileges"); |
| 1630 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1631 | ret = bind (accept_sock, (struct sockaddr *)&addr, |
| 1632 | sizeof (struct sockaddr_in)); |
| 1633 | if (ret < 0) |
| 1634 | { |
paul | 3d1dc85 | 2005-04-05 00:45:23 +0000 | [diff] [blame] | 1635 | zlog_warn ("Can't bind to stream socket: %s", |
| 1636 | safe_strerror (errno)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1637 | zlog_warn ("zebra can't provice full functionality due to above error"); |
| 1638 | close (accept_sock); /* Avoid sd leak. */ |
| 1639 | return; |
| 1640 | } |
paul | edd7c24 | 2003-06-04 13:59:38 +0000 | [diff] [blame] | 1641 | |
| 1642 | if ( zserv_privs.change(ZPRIVS_LOWER) ) |
| 1643 | zlog (NULL, LOG_ERR, "Can't lower privileges"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1644 | |
| 1645 | ret = listen (accept_sock, 1); |
| 1646 | if (ret < 0) |
| 1647 | { |
paul | 3d1dc85 | 2005-04-05 00:45:23 +0000 | [diff] [blame] | 1648 | zlog_warn ("Can't listen to stream socket: %s", |
| 1649 | safe_strerror (errno)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1650 | zlog_warn ("zebra can't provice full functionality due to above error"); |
| 1651 | close (accept_sock); /* Avoid sd leak. */ |
| 1652 | return; |
| 1653 | } |
| 1654 | |
| 1655 | zebra_event (ZEBRA_SERV, accept_sock, NULL); |
| 1656 | } |
David Lamparter | 4b6c332 | 2015-04-21 09:47:57 +0200 | [diff] [blame] | 1657 | #else /* HAVE_TCP_ZEBRA */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1658 | |
| 1659 | /* For sockaddr_un. */ |
| 1660 | #include <sys/un.h> |
| 1661 | |
| 1662 | /* zebra server UNIX domain socket. */ |
paul | b9df2d2 | 2004-05-09 09:09:59 +0000 | [diff] [blame] | 1663 | static void |
hasso | fce954f | 2004-10-07 20:29:24 +0000 | [diff] [blame] | 1664 | zebra_serv_un (const char *path) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1665 | { |
| 1666 | int ret; |
| 1667 | int sock, len; |
| 1668 | struct sockaddr_un serv; |
| 1669 | mode_t old_mask; |
| 1670 | |
| 1671 | /* First of all, unlink existing socket */ |
| 1672 | unlink (path); |
| 1673 | |
| 1674 | /* Set umask */ |
| 1675 | old_mask = umask (0077); |
| 1676 | |
| 1677 | /* Make UNIX domain socket. */ |
| 1678 | sock = socket (AF_UNIX, SOCK_STREAM, 0); |
| 1679 | if (sock < 0) |
| 1680 | { |
paul | 3d1dc85 | 2005-04-05 00:45:23 +0000 | [diff] [blame] | 1681 | zlog_warn ("Can't create zserv unix socket: %s", |
| 1682 | safe_strerror (errno)); |
| 1683 | zlog_warn ("zebra can't provide full functionality due to above error"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1684 | return; |
| 1685 | } |
| 1686 | |
Vyacheslav Trushkin | 2ea1ab1 | 2011-12-11 18:48:47 +0400 | [diff] [blame] | 1687 | memset (&route_type_oaths, 0, sizeof (route_type_oaths)); |
| 1688 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1689 | /* Make server socket. */ |
| 1690 | memset (&serv, 0, sizeof (struct sockaddr_un)); |
| 1691 | serv.sun_family = AF_UNIX; |
| 1692 | strncpy (serv.sun_path, path, strlen (path)); |
Paul Jakma | 6f0e3f6 | 2007-05-10 02:38:51 +0000 | [diff] [blame] | 1693 | #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1694 | len = serv.sun_len = SUN_LEN(&serv); |
| 1695 | #else |
| 1696 | len = sizeof (serv.sun_family) + strlen (serv.sun_path); |
Paul Jakma | 6f0e3f6 | 2007-05-10 02:38:51 +0000 | [diff] [blame] | 1697 | #endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1698 | |
| 1699 | ret = bind (sock, (struct sockaddr *) &serv, len); |
| 1700 | if (ret < 0) |
| 1701 | { |
paul | 3d1dc85 | 2005-04-05 00:45:23 +0000 | [diff] [blame] | 1702 | zlog_warn ("Can't bind to unix socket %s: %s", |
| 1703 | path, safe_strerror (errno)); |
| 1704 | zlog_warn ("zebra can't provide full functionality due to above error"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1705 | close (sock); |
| 1706 | return; |
| 1707 | } |
| 1708 | |
| 1709 | ret = listen (sock, 5); |
| 1710 | if (ret < 0) |
| 1711 | { |
paul | 3d1dc85 | 2005-04-05 00:45:23 +0000 | [diff] [blame] | 1712 | zlog_warn ("Can't listen to unix socket %s: %s", |
| 1713 | path, safe_strerror (errno)); |
| 1714 | zlog_warn ("zebra can't provide full functionality due to above error"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1715 | close (sock); |
| 1716 | return; |
| 1717 | } |
| 1718 | |
| 1719 | umask (old_mask); |
| 1720 | |
| 1721 | zebra_event (ZEBRA_SERV, sock, NULL); |
| 1722 | } |
David Lamparter | 4b6c332 | 2015-04-21 09:47:57 +0200 | [diff] [blame] | 1723 | #endif /* HAVE_TCP_ZEBRA */ |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 1724 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1725 | |
paul | b9df2d2 | 2004-05-09 09:09:59 +0000 | [diff] [blame] | 1726 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1727 | zebra_event (enum event event, int sock, struct zserv *client) |
| 1728 | { |
| 1729 | switch (event) |
| 1730 | { |
| 1731 | case ZEBRA_SERV: |
paul | b21b19c | 2003-06-15 01:28:29 +0000 | [diff] [blame] | 1732 | thread_add_read (zebrad.master, zebra_accept, client, sock); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1733 | break; |
| 1734 | case ZEBRA_READ: |
| 1735 | client->t_read = |
paul | b21b19c | 2003-06-15 01:28:29 +0000 | [diff] [blame] | 1736 | thread_add_read (zebrad.master, zebra_client_read, client, sock); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1737 | break; |
| 1738 | case ZEBRA_WRITE: |
| 1739 | /**/ |
| 1740 | break; |
| 1741 | } |
| 1742 | } |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 1743 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1744 | /* Display default rtm_table for all clients. */ |
| 1745 | DEFUN (show_table, |
| 1746 | show_table_cmd, |
| 1747 | "show table", |
| 1748 | SHOW_STR |
| 1749 | "default routing table to use for all clients\n") |
| 1750 | { |
paul | b21b19c | 2003-06-15 01:28:29 +0000 | [diff] [blame] | 1751 | vty_out (vty, "table %d%s", zebrad.rtm_table_default, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1752 | VTY_NEWLINE); |
| 1753 | return CMD_SUCCESS; |
| 1754 | } |
| 1755 | |
| 1756 | DEFUN (config_table, |
| 1757 | config_table_cmd, |
| 1758 | "table TABLENO", |
| 1759 | "Configure target kernel routing table\n" |
| 1760 | "TABLE integer\n") |
| 1761 | { |
paul | b21b19c | 2003-06-15 01:28:29 +0000 | [diff] [blame] | 1762 | zebrad.rtm_table_default = strtol (argv[0], (char**)0, 10); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1763 | return CMD_SUCCESS; |
| 1764 | } |
| 1765 | |
hasso | 647e4f1 | 2003-05-25 11:43:52 +0000 | [diff] [blame] | 1766 | DEFUN (ip_forwarding, |
| 1767 | ip_forwarding_cmd, |
| 1768 | "ip forwarding", |
| 1769 | IP_STR |
| 1770 | "Turn on IP forwarding") |
| 1771 | { |
| 1772 | int ret; |
| 1773 | |
| 1774 | ret = ipforward (); |
hasso | b71f00f | 2004-10-13 12:20:35 +0000 | [diff] [blame] | 1775 | if (ret == 0) |
| 1776 | ret = ipforward_on (); |
hasso | 647e4f1 | 2003-05-25 11:43:52 +0000 | [diff] [blame] | 1777 | |
hasso | 647e4f1 | 2003-05-25 11:43:52 +0000 | [diff] [blame] | 1778 | if (ret == 0) |
| 1779 | { |
| 1780 | vty_out (vty, "Can't turn on IP forwarding%s", VTY_NEWLINE); |
| 1781 | return CMD_WARNING; |
| 1782 | } |
| 1783 | |
| 1784 | return CMD_SUCCESS; |
| 1785 | } |
| 1786 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1787 | DEFUN (no_ip_forwarding, |
| 1788 | no_ip_forwarding_cmd, |
| 1789 | "no ip forwarding", |
| 1790 | NO_STR |
| 1791 | IP_STR |
| 1792 | "Turn off IP forwarding") |
| 1793 | { |
| 1794 | int ret; |
| 1795 | |
| 1796 | ret = ipforward (); |
hasso | b71f00f | 2004-10-13 12:20:35 +0000 | [diff] [blame] | 1797 | if (ret != 0) |
| 1798 | ret = ipforward_off (); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1799 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1800 | if (ret != 0) |
| 1801 | { |
| 1802 | vty_out (vty, "Can't turn off IP forwarding%s", VTY_NEWLINE); |
| 1803 | return CMD_WARNING; |
| 1804 | } |
| 1805 | |
| 1806 | return CMD_SUCCESS; |
| 1807 | } |
| 1808 | |
| 1809 | /* This command is for debugging purpose. */ |
| 1810 | DEFUN (show_zebra_client, |
| 1811 | show_zebra_client_cmd, |
| 1812 | "show zebra client", |
| 1813 | SHOW_STR |
| 1814 | "Zebra information" |
| 1815 | "Client information") |
| 1816 | { |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 1817 | struct listnode *node; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1818 | struct zserv *client; |
| 1819 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1820 | for (ALL_LIST_ELEMENTS_RO (zebrad.client_list, node, client)) |
| 1821 | vty_out (vty, "Client fd %d%s", client->sock, VTY_NEWLINE); |
| 1822 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1823 | return CMD_SUCCESS; |
| 1824 | } |
| 1825 | |
| 1826 | /* Table configuration write function. */ |
paul | b9df2d2 | 2004-05-09 09:09:59 +0000 | [diff] [blame] | 1827 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1828 | config_write_table (struct vty *vty) |
| 1829 | { |
paul | b21b19c | 2003-06-15 01:28:29 +0000 | [diff] [blame] | 1830 | if (zebrad.rtm_table_default) |
| 1831 | vty_out (vty, "table %d%s", zebrad.rtm_table_default, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1832 | VTY_NEWLINE); |
| 1833 | return 0; |
| 1834 | } |
| 1835 | |
| 1836 | /* table node for routing tables. */ |
Stephen Hemminger | 7fc626d | 2008-12-01 11:10:34 -0800 | [diff] [blame] | 1837 | static struct cmd_node table_node = |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1838 | { |
| 1839 | TABLE_NODE, |
| 1840 | "", /* This node has no interface. */ |
| 1841 | 1 |
| 1842 | }; |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 1843 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1844 | /* Only display ip forwarding is enabled or not. */ |
| 1845 | DEFUN (show_ip_forwarding, |
| 1846 | show_ip_forwarding_cmd, |
| 1847 | "show ip forwarding", |
| 1848 | SHOW_STR |
| 1849 | IP_STR |
| 1850 | "IP forwarding status\n") |
| 1851 | { |
| 1852 | int ret; |
| 1853 | |
| 1854 | ret = ipforward (); |
| 1855 | |
| 1856 | if (ret == 0) |
| 1857 | vty_out (vty, "IP forwarding is off%s", VTY_NEWLINE); |
| 1858 | else |
| 1859 | vty_out (vty, "IP forwarding is on%s", VTY_NEWLINE); |
| 1860 | return CMD_SUCCESS; |
| 1861 | } |
| 1862 | |
| 1863 | #ifdef HAVE_IPV6 |
| 1864 | /* Only display ipv6 forwarding is enabled or not. */ |
| 1865 | DEFUN (show_ipv6_forwarding, |
| 1866 | show_ipv6_forwarding_cmd, |
| 1867 | "show ipv6 forwarding", |
| 1868 | SHOW_STR |
| 1869 | "IPv6 information\n" |
| 1870 | "Forwarding status\n") |
| 1871 | { |
| 1872 | int ret; |
| 1873 | |
| 1874 | ret = ipforward_ipv6 (); |
| 1875 | |
| 1876 | switch (ret) |
| 1877 | { |
| 1878 | case -1: |
| 1879 | vty_out (vty, "ipv6 forwarding is unknown%s", VTY_NEWLINE); |
| 1880 | break; |
| 1881 | case 0: |
| 1882 | vty_out (vty, "ipv6 forwarding is %s%s", "off", VTY_NEWLINE); |
| 1883 | break; |
| 1884 | case 1: |
| 1885 | vty_out (vty, "ipv6 forwarding is %s%s", "on", VTY_NEWLINE); |
| 1886 | break; |
| 1887 | default: |
| 1888 | vty_out (vty, "ipv6 forwarding is %s%s", "off", VTY_NEWLINE); |
| 1889 | break; |
| 1890 | } |
| 1891 | return CMD_SUCCESS; |
| 1892 | } |
| 1893 | |
hasso | 5590672 | 2004-02-11 22:42:16 +0000 | [diff] [blame] | 1894 | DEFUN (ipv6_forwarding, |
| 1895 | ipv6_forwarding_cmd, |
| 1896 | "ipv6 forwarding", |
| 1897 | IPV6_STR |
| 1898 | "Turn on IPv6 forwarding") |
| 1899 | { |
| 1900 | int ret; |
| 1901 | |
hasso | 41d3fc9 | 2004-04-06 11:59:00 +0000 | [diff] [blame] | 1902 | ret = ipforward_ipv6 (); |
hasso | b71f00f | 2004-10-13 12:20:35 +0000 | [diff] [blame] | 1903 | if (ret == 0) |
| 1904 | ret = ipforward_ipv6_on (); |
hasso | 41d3fc9 | 2004-04-06 11:59:00 +0000 | [diff] [blame] | 1905 | |
hasso | 41d3fc9 | 2004-04-06 11:59:00 +0000 | [diff] [blame] | 1906 | if (ret == 0) |
| 1907 | { |
hasso | 5590672 | 2004-02-11 22:42:16 +0000 | [diff] [blame] | 1908 | vty_out (vty, "Can't turn on IPv6 forwarding%s", VTY_NEWLINE); |
| 1909 | return CMD_WARNING; |
| 1910 | } |
| 1911 | |
| 1912 | return CMD_SUCCESS; |
| 1913 | } |
| 1914 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1915 | DEFUN (no_ipv6_forwarding, |
| 1916 | no_ipv6_forwarding_cmd, |
| 1917 | "no ipv6 forwarding", |
| 1918 | NO_STR |
hasso | 5590672 | 2004-02-11 22:42:16 +0000 | [diff] [blame] | 1919 | IPV6_STR |
| 1920 | "Turn off IPv6 forwarding") |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1921 | { |
| 1922 | int ret; |
| 1923 | |
hasso | 41d3fc9 | 2004-04-06 11:59:00 +0000 | [diff] [blame] | 1924 | ret = ipforward_ipv6 (); |
hasso | b71f00f | 2004-10-13 12:20:35 +0000 | [diff] [blame] | 1925 | if (ret != 0) |
| 1926 | ret = ipforward_ipv6_off (); |
hasso | 41d3fc9 | 2004-04-06 11:59:00 +0000 | [diff] [blame] | 1927 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1928 | if (ret != 0) |
| 1929 | { |
| 1930 | vty_out (vty, "Can't turn off IPv6 forwarding%s", VTY_NEWLINE); |
| 1931 | return CMD_WARNING; |
| 1932 | } |
| 1933 | |
| 1934 | return CMD_SUCCESS; |
| 1935 | } |
| 1936 | |
| 1937 | #endif /* HAVE_IPV6 */ |
| 1938 | |
| 1939 | /* IPForwarding configuration write function. */ |
ajs | 719e974 | 2005-02-28 20:52:15 +0000 | [diff] [blame] | 1940 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1941 | config_write_forwarding (struct vty *vty) |
| 1942 | { |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 1943 | /* FIXME: Find better place for that. */ |
| 1944 | router_id_write (vty); |
| 1945 | |
paul | 3e0b3a5 | 2004-08-23 18:58:32 +0000 | [diff] [blame] | 1946 | if (ipforward ()) |
| 1947 | vty_out (vty, "ip forwarding%s", VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1948 | #ifdef HAVE_IPV6 |
paul | 3e0b3a5 | 2004-08-23 18:58:32 +0000 | [diff] [blame] | 1949 | if (ipforward_ipv6 ()) |
| 1950 | vty_out (vty, "ipv6 forwarding%s", VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1951 | #endif /* HAVE_IPV6 */ |
| 1952 | vty_out (vty, "!%s", VTY_NEWLINE); |
| 1953 | return 0; |
| 1954 | } |
| 1955 | |
| 1956 | /* table node for routing tables. */ |
Stephen Hemminger | 7fc626d | 2008-12-01 11:10:34 -0800 | [diff] [blame] | 1957 | static struct cmd_node forwarding_node = |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1958 | { |
| 1959 | FORWARDING_NODE, |
| 1960 | "", /* This node has no interface. */ |
| 1961 | 1 |
| 1962 | }; |
| 1963 | |
Udaya Shankara KS | d869dbd | 2016-02-11 21:42:29 +0530 | [diff] [blame] | 1964 | #ifdef HAVE_FPM |
| 1965 | /* function to write the fpm config info */ |
| 1966 | static int |
| 1967 | config_write_fpm (struct vty *vty) |
| 1968 | { |
| 1969 | return |
| 1970 | fpm_remote_srv_write (vty); |
| 1971 | } |
| 1972 | |
| 1973 | /* Zebra node */ |
| 1974 | static struct cmd_node zebra_node = |
| 1975 | { |
| 1976 | ZEBRA_NODE, |
| 1977 | "", |
| 1978 | 1 |
| 1979 | }; |
| 1980 | #endif |
| 1981 | |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 1982 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1983 | /* Initialisation of zebra and installation of commands. */ |
| 1984 | void |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 1985 | zebra_init (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1986 | { |
| 1987 | /* Client list init. */ |
paul | b21b19c | 2003-06-15 01:28:29 +0000 | [diff] [blame] | 1988 | zebrad.client_list = list_new (); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1989 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1990 | /* Install configuration write function. */ |
| 1991 | install_node (&table_node, config_write_table); |
| 1992 | install_node (&forwarding_node, config_write_forwarding); |
Udaya Shankara KS | d869dbd | 2016-02-11 21:42:29 +0530 | [diff] [blame] | 1993 | #ifdef HAVE_FPM |
| 1994 | install_node (&zebra_node, config_write_fpm); |
| 1995 | #endif |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1996 | |
| 1997 | install_element (VIEW_NODE, &show_ip_forwarding_cmd); |
hasso | 647e4f1 | 2003-05-25 11:43:52 +0000 | [diff] [blame] | 1998 | install_element (CONFIG_NODE, &ip_forwarding_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1999 | install_element (CONFIG_NODE, &no_ip_forwarding_cmd); |
| 2000 | install_element (ENABLE_NODE, &show_zebra_client_cmd); |
| 2001 | |
| 2002 | #ifdef HAVE_NETLINK |
| 2003 | install_element (VIEW_NODE, &show_table_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2004 | install_element (CONFIG_NODE, &config_table_cmd); |
| 2005 | #endif /* HAVE_NETLINK */ |
| 2006 | |
| 2007 | #ifdef HAVE_IPV6 |
| 2008 | install_element (VIEW_NODE, &show_ipv6_forwarding_cmd); |
hasso | 5590672 | 2004-02-11 22:42:16 +0000 | [diff] [blame] | 2009 | install_element (CONFIG_NODE, &ipv6_forwarding_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2010 | install_element (CONFIG_NODE, &no_ipv6_forwarding_cmd); |
| 2011 | #endif /* HAVE_IPV6 */ |
Paul Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 2012 | |
| 2013 | /* Route-map */ |
| 2014 | zebra_route_map_init (); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2015 | } |
Denis Ovsienko | 97be79f | 2009-07-24 20:45:31 +0400 | [diff] [blame] | 2016 | |
| 2017 | /* Make zebra server socket, wiping any existing one (see bug #403). */ |
| 2018 | void |
Vyacheslav Trushkin | b511468 | 2011-11-25 18:51:48 +0400 | [diff] [blame] | 2019 | zebra_zserv_socket_init (char *path) |
Denis Ovsienko | 97be79f | 2009-07-24 20:45:31 +0400 | [diff] [blame] | 2020 | { |
| 2021 | #ifdef HAVE_TCP_ZEBRA |
| 2022 | zebra_serv (); |
| 2023 | #else |
Vyacheslav Trushkin | b511468 | 2011-11-25 18:51:48 +0400 | [diff] [blame] | 2024 | zebra_serv_un (path ? path : ZEBRA_SERV_PATH); |
Denis Ovsienko | 97be79f | 2009-07-24 20:45:31 +0400 | [diff] [blame] | 2025 | #endif /* HAVE_TCP_ZEBRA */ |
| 2026 | } |