zserv.c 49 KB

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