zserv.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921
  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. vrf_id_t vrf_id)
  651. {
  652. struct stream *s;
  653. int blen;
  654. /* Check this client need interface information. */
  655. if (!client->ridinfo)
  656. return 0;
  657. s = client->obuf;
  658. stream_reset (s);
  659. /* Message type. */
  660. zserv_create_header (s, ZEBRA_ROUTER_ID_UPDATE);
  661. /* Prefix information. */
  662. stream_putc (s, p->family);
  663. blen = prefix_blen (p);
  664. stream_put (s, &p->u.prefix, blen);
  665. stream_putc (s, p->prefixlen);
  666. /* Write packet size. */
  667. stream_putw_at (s, 0, stream_get_endp (s));
  668. return zebra_server_send_message(client);
  669. }
  670. /* Register zebra server interface information. Send current all
  671. interface and address information. */
  672. static int
  673. zread_interface_add (struct zserv *client, u_short length)
  674. {
  675. struct listnode *ifnode, *ifnnode;
  676. struct listnode *cnode, *cnnode;
  677. struct interface *ifp;
  678. struct connected *c;
  679. /* Interface information is needed. */
  680. client->ifinfo = 1;
  681. for (ALL_LIST_ELEMENTS (iflist, ifnode, ifnnode, ifp))
  682. {
  683. /* Skip pseudo interface. */
  684. if (! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
  685. continue;
  686. if (zsend_interface_add (client, ifp) < 0)
  687. return -1;
  688. for (ALL_LIST_ELEMENTS (ifp->connected, cnode, cnnode, c))
  689. {
  690. if (CHECK_FLAG (c->conf, ZEBRA_IFC_REAL) &&
  691. (zsend_interface_address (ZEBRA_INTERFACE_ADDRESS_ADD, client,
  692. ifp, c) < 0))
  693. return -1;
  694. }
  695. }
  696. return 0;
  697. }
  698. /* Unregister zebra server interface information. */
  699. static int
  700. zread_interface_delete (struct zserv *client, u_short length)
  701. {
  702. client->ifinfo = 0;
  703. return 0;
  704. }
  705. /* This function support multiple nexthop. */
  706. /*
  707. * Parse the ZEBRA_IPV4_ROUTE_ADD sent from client. Update rib and
  708. * add kernel route.
  709. */
  710. static int
  711. zread_ipv4_add (struct zserv *client, u_short length)
  712. {
  713. int i;
  714. struct rib *rib;
  715. struct prefix_ipv4 p;
  716. u_char message;
  717. struct in_addr nexthop;
  718. u_char nexthop_num;
  719. u_char nexthop_type;
  720. struct stream *s;
  721. unsigned int ifindex;
  722. u_char ifname_len;
  723. safi_t safi;
  724. /* Get input stream. */
  725. s = client->ibuf;
  726. /* Allocate new rib. */
  727. rib = XCALLOC (MTYPE_RIB, sizeof (struct rib));
  728. /* Type, flags, message. */
  729. rib->type = stream_getc (s);
  730. rib->flags = stream_getc (s);
  731. message = stream_getc (s);
  732. safi = stream_getw (s);
  733. rib->uptime = time (NULL);
  734. /* IPv4 prefix. */
  735. memset (&p, 0, sizeof (struct prefix_ipv4));
  736. p.family = AF_INET;
  737. p.prefixlen = stream_getc (s);
  738. stream_get (&p.prefix, s, PSIZE (p.prefixlen));
  739. /* VRF ID */
  740. rib->vrf_id = VRF_DEFAULT;
  741. /* Nexthop parse. */
  742. if (CHECK_FLAG (message, ZAPI_MESSAGE_NEXTHOP))
  743. {
  744. nexthop_num = stream_getc (s);
  745. for (i = 0; i < nexthop_num; i++)
  746. {
  747. nexthop_type = stream_getc (s);
  748. switch (nexthop_type)
  749. {
  750. case ZEBRA_NEXTHOP_IFINDEX:
  751. ifindex = stream_getl (s);
  752. nexthop_ifindex_add (rib, ifindex);
  753. break;
  754. case ZEBRA_NEXTHOP_IFNAME:
  755. ifname_len = stream_getc (s);
  756. stream_forward_getp (s, ifname_len);
  757. break;
  758. case ZEBRA_NEXTHOP_IPV4:
  759. nexthop.s_addr = stream_get_ipv4 (s);
  760. nexthop_ipv4_add (rib, &nexthop, NULL);
  761. break;
  762. case ZEBRA_NEXTHOP_IPV4_IFINDEX:
  763. nexthop.s_addr = stream_get_ipv4 (s);
  764. ifindex = stream_getl (s);
  765. nexthop_ipv4_ifindex_add (rib, &nexthop, NULL, ifindex);
  766. break;
  767. case ZEBRA_NEXTHOP_IPV6:
  768. stream_forward_getp (s, IPV6_MAX_BYTELEN);
  769. break;
  770. case ZEBRA_NEXTHOP_BLACKHOLE:
  771. nexthop_blackhole_add (rib);
  772. break;
  773. }
  774. }
  775. }
  776. /* Distance. */
  777. if (CHECK_FLAG (message, ZAPI_MESSAGE_DISTANCE))
  778. rib->distance = stream_getc (s);
  779. /* Metric. */
  780. if (CHECK_FLAG (message, ZAPI_MESSAGE_METRIC))
  781. rib->metric = stream_getl (s);
  782. /* Table */
  783. rib->table=zebrad.rtm_table_default;
  784. rib_add_ipv4_multipath (&p, rib, safi);
  785. return 0;
  786. }
  787. /* Zebra server IPv4 prefix delete function. */
  788. static int
  789. zread_ipv4_delete (struct zserv *client, u_short length)
  790. {
  791. int i;
  792. struct stream *s;
  793. struct zapi_ipv4 api;
  794. struct in_addr nexthop, *nexthop_p;
  795. unsigned long ifindex;
  796. struct prefix_ipv4 p;
  797. u_char nexthop_num;
  798. u_char nexthop_type;
  799. u_char ifname_len;
  800. s = client->ibuf;
  801. ifindex = 0;
  802. nexthop.s_addr = 0;
  803. nexthop_p = NULL;
  804. /* Type, flags, message. */
  805. api.type = stream_getc (s);
  806. api.flags = stream_getc (s);
  807. api.message = stream_getc (s);
  808. api.safi = stream_getw (s);
  809. /* IPv4 prefix. */
  810. memset (&p, 0, sizeof (struct prefix_ipv4));
  811. p.family = AF_INET;
  812. p.prefixlen = stream_getc (s);
  813. stream_get (&p.prefix, s, PSIZE (p.prefixlen));
  814. /* Nexthop, ifindex, distance, metric. */
  815. if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
  816. {
  817. nexthop_num = stream_getc (s);
  818. for (i = 0; i < nexthop_num; i++)
  819. {
  820. nexthop_type = stream_getc (s);
  821. switch (nexthop_type)
  822. {
  823. case ZEBRA_NEXTHOP_IFINDEX:
  824. ifindex = stream_getl (s);
  825. break;
  826. case ZEBRA_NEXTHOP_IFNAME:
  827. ifname_len = stream_getc (s);
  828. stream_forward_getp (s, ifname_len);
  829. break;
  830. case ZEBRA_NEXTHOP_IPV4:
  831. nexthop.s_addr = stream_get_ipv4 (s);
  832. nexthop_p = &nexthop;
  833. break;
  834. case ZEBRA_NEXTHOP_IPV4_IFINDEX:
  835. nexthop.s_addr = stream_get_ipv4 (s);
  836. nexthop_p = &nexthop;
  837. ifindex = stream_getl (s);
  838. break;
  839. case ZEBRA_NEXTHOP_IPV6:
  840. stream_forward_getp (s, IPV6_MAX_BYTELEN);
  841. break;
  842. }
  843. }
  844. }
  845. /* Distance. */
  846. if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
  847. api.distance = stream_getc (s);
  848. else
  849. api.distance = 0;
  850. /* Metric. */
  851. if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
  852. api.metric = stream_getl (s);
  853. else
  854. api.metric = 0;
  855. rib_delete_ipv4 (api.type, api.flags, &p, nexthop_p, ifindex,
  856. VRF_DEFAULT, api.safi);
  857. return 0;
  858. }
  859. /* Nexthop lookup for IPv4. */
  860. static int
  861. zread_ipv4_nexthop_lookup (struct zserv *client, u_short length)
  862. {
  863. struct in_addr addr;
  864. char buf[BUFSIZ];
  865. addr.s_addr = stream_get_ipv4 (client->ibuf);
  866. if (IS_ZEBRA_DEBUG_PACKET && IS_ZEBRA_DEBUG_RECV)
  867. zlog_debug("%s: looking up %s", __func__,
  868. inet_ntop (AF_INET, &addr, buf, BUFSIZ));
  869. return zsend_ipv4_nexthop_lookup (client, addr);
  870. }
  871. /* MRIB Nexthop lookup for IPv4. */
  872. static int
  873. zread_ipv4_nexthop_lookup_mrib (struct zserv *client, u_short length)
  874. {
  875. struct in_addr addr;
  876. struct rib *rib;
  877. addr.s_addr = stream_get_ipv4 (client->ibuf);
  878. rib = rib_match_ipv4_multicast (addr, NULL, VRF_DEFAULT);
  879. return zsend_ipv4_nexthop_lookup_mrib (client, addr, rib);
  880. }
  881. /* Nexthop lookup for IPv4. */
  882. static int
  883. zread_ipv4_import_lookup (struct zserv *client, u_short length)
  884. {
  885. struct prefix_ipv4 p;
  886. p.family = AF_INET;
  887. p.prefixlen = stream_getc (client->ibuf);
  888. p.prefix.s_addr = stream_get_ipv4 (client->ibuf);
  889. return zsend_ipv4_import_lookup (client, &p);
  890. }
  891. #ifdef HAVE_IPV6
  892. /* Zebra server IPv6 prefix add function. */
  893. static int
  894. zread_ipv6_add (struct zserv *client, u_short length)
  895. {
  896. int i;
  897. struct stream *s;
  898. struct zapi_ipv6 api;
  899. struct in6_addr nexthop;
  900. unsigned long ifindex;
  901. struct prefix_ipv6 p;
  902. s = client->ibuf;
  903. ifindex = 0;
  904. memset (&nexthop, 0, sizeof (struct in6_addr));
  905. /* Type, flags, message. */
  906. api.type = stream_getc (s);
  907. api.flags = stream_getc (s);
  908. api.message = stream_getc (s);
  909. api.safi = stream_getw (s);
  910. /* IPv4 prefix. */
  911. memset (&p, 0, sizeof (struct prefix_ipv6));
  912. p.family = AF_INET6;
  913. p.prefixlen = stream_getc (s);
  914. stream_get (&p.prefix, s, PSIZE (p.prefixlen));
  915. /* Nexthop, ifindex, distance, metric. */
  916. if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
  917. {
  918. u_char nexthop_type;
  919. api.nexthop_num = stream_getc (s);
  920. for (i = 0; i < api.nexthop_num; i++)
  921. {
  922. nexthop_type = stream_getc (s);
  923. switch (nexthop_type)
  924. {
  925. case ZEBRA_NEXTHOP_IPV6:
  926. stream_get (&nexthop, s, 16);
  927. break;
  928. case ZEBRA_NEXTHOP_IFINDEX:
  929. ifindex = stream_getl (s);
  930. break;
  931. }
  932. }
  933. }
  934. if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
  935. api.distance = stream_getc (s);
  936. else
  937. api.distance = 0;
  938. if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
  939. api.metric = stream_getl (s);
  940. else
  941. api.metric = 0;
  942. if (IN6_IS_ADDR_UNSPECIFIED (&nexthop))
  943. rib_add_ipv6 (api.type, api.flags, &p, NULL, ifindex,
  944. VRF_DEFAULT, zebrad.rtm_table_default, api.metric,
  945. api.distance, api.safi);
  946. else
  947. rib_add_ipv6 (api.type, api.flags, &p, &nexthop, ifindex,
  948. VRF_DEFAULT, zebrad.rtm_table_default, api.metric,
  949. api.distance, api.safi);
  950. return 0;
  951. }
  952. /* Zebra server IPv6 prefix delete function. */
  953. static int
  954. zread_ipv6_delete (struct zserv *client, u_short length)
  955. {
  956. int i;
  957. struct stream *s;
  958. struct zapi_ipv6 api;
  959. struct in6_addr nexthop;
  960. unsigned long ifindex;
  961. struct prefix_ipv6 p;
  962. s = client->ibuf;
  963. ifindex = 0;
  964. memset (&nexthop, 0, sizeof (struct in6_addr));
  965. /* Type, flags, message. */
  966. api.type = stream_getc (s);
  967. api.flags = stream_getc (s);
  968. api.message = stream_getc (s);
  969. api.safi = stream_getw (s);
  970. /* IPv4 prefix. */
  971. memset (&p, 0, sizeof (struct prefix_ipv6));
  972. p.family = AF_INET6;
  973. p.prefixlen = stream_getc (s);
  974. stream_get (&p.prefix, s, PSIZE (p.prefixlen));
  975. /* Nexthop, ifindex, distance, metric. */
  976. if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
  977. {
  978. u_char nexthop_type;
  979. api.nexthop_num = stream_getc (s);
  980. for (i = 0; i < api.nexthop_num; i++)
  981. {
  982. nexthop_type = stream_getc (s);
  983. switch (nexthop_type)
  984. {
  985. case ZEBRA_NEXTHOP_IPV6:
  986. stream_get (&nexthop, s, 16);
  987. break;
  988. case ZEBRA_NEXTHOP_IFINDEX:
  989. ifindex = stream_getl (s);
  990. break;
  991. }
  992. }
  993. }
  994. if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
  995. api.distance = stream_getc (s);
  996. else
  997. api.distance = 0;
  998. if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
  999. api.metric = stream_getl (s);
  1000. else
  1001. api.metric = 0;
  1002. if (IN6_IS_ADDR_UNSPECIFIED (&nexthop))
  1003. rib_delete_ipv6 (api.type, api.flags, &p, NULL, ifindex, VRF_DEFAULT,
  1004. api.safi);
  1005. else
  1006. rib_delete_ipv6 (api.type, api.flags, &p, &nexthop, ifindex, VRF_DEFAULT,
  1007. api.safi);
  1008. return 0;
  1009. }
  1010. static int
  1011. zread_ipv6_nexthop_lookup (struct zserv *client, u_short length)
  1012. {
  1013. struct in6_addr addr;
  1014. char buf[BUFSIZ];
  1015. stream_get (&addr, client->ibuf, 16);
  1016. if (IS_ZEBRA_DEBUG_PACKET && IS_ZEBRA_DEBUG_RECV)
  1017. zlog_debug("%s: looking up %s", __func__,
  1018. inet_ntop (AF_INET6, &addr, buf, BUFSIZ));
  1019. return zsend_ipv6_nexthop_lookup (client, &addr);
  1020. }
  1021. #endif /* HAVE_IPV6 */
  1022. /* Register zebra server router-id information. Send current router-id */
  1023. static int
  1024. zread_router_id_add (struct zserv *client, u_short length)
  1025. {
  1026. struct prefix p;
  1027. /* Router-id information is needed. */
  1028. client->ridinfo = 1;
  1029. router_id_get (&p, VRF_DEFAULT);
  1030. return zsend_router_id_update (client, &p, VRF_DEFAULT);
  1031. }
  1032. /* Unregister zebra server router-id information. */
  1033. static int
  1034. zread_router_id_delete (struct zserv *client, u_short length)
  1035. {
  1036. client->ridinfo = 0;
  1037. return 0;
  1038. }
  1039. /* Tie up route-type and client->sock */
  1040. static void
  1041. zread_hello (struct zserv *client)
  1042. {
  1043. /* type of protocol (lib/zebra.h) */
  1044. u_char proto;
  1045. proto = stream_getc (client->ibuf);
  1046. /* accept only dynamic routing protocols */
  1047. if ((proto < ZEBRA_ROUTE_MAX)
  1048. && (proto > ZEBRA_ROUTE_STATIC))
  1049. {
  1050. zlog_notice ("client %d says hello and bids fair to announce only %s routes",
  1051. client->sock, zebra_route_string(proto));
  1052. /* if route-type was binded by other client */
  1053. if (route_type_oaths[proto])
  1054. zlog_warn ("sender of %s routes changed %c->%c",
  1055. zebra_route_string(proto), route_type_oaths[proto],
  1056. client->sock);
  1057. route_type_oaths[proto] = client->sock;
  1058. }
  1059. }
  1060. /* If client sent routes of specific type, zebra removes it
  1061. * and returns number of deleted routes.
  1062. */
  1063. static void
  1064. zebra_score_rib (int client_sock)
  1065. {
  1066. int i;
  1067. for (i = ZEBRA_ROUTE_RIP; i < ZEBRA_ROUTE_MAX; i++)
  1068. if (client_sock == route_type_oaths[i])
  1069. {
  1070. zlog_notice ("client %d disconnected. %lu %s routes removed from the rib",
  1071. client_sock, rib_score_proto (i), zebra_route_string (i));
  1072. route_type_oaths[i] = 0;
  1073. break;
  1074. }
  1075. }
  1076. /* Close zebra client. */
  1077. static void
  1078. zebra_client_close (struct zserv *client)
  1079. {
  1080. /* Close file descriptor. */
  1081. if (client->sock)
  1082. {
  1083. close (client->sock);
  1084. zebra_score_rib (client->sock);
  1085. client->sock = -1;
  1086. }
  1087. /* Free stream buffers. */
  1088. if (client->ibuf)
  1089. stream_free (client->ibuf);
  1090. if (client->obuf)
  1091. stream_free (client->obuf);
  1092. if (client->wb)
  1093. buffer_free(client->wb);
  1094. /* Release threads. */
  1095. if (client->t_read)
  1096. thread_cancel (client->t_read);
  1097. if (client->t_write)
  1098. thread_cancel (client->t_write);
  1099. if (client->t_suicide)
  1100. thread_cancel (client->t_suicide);
  1101. /* Free client structure. */
  1102. listnode_delete (zebrad.client_list, client);
  1103. XFREE (0, client);
  1104. }
  1105. /* Make new client. */
  1106. static void
  1107. zebra_client_create (int sock)
  1108. {
  1109. struct zserv *client;
  1110. client = XCALLOC (0, sizeof (struct zserv));
  1111. /* Make client input/output buffer. */
  1112. client->sock = sock;
  1113. client->ibuf = stream_new (ZEBRA_MAX_PACKET_SIZ);
  1114. client->obuf = stream_new (ZEBRA_MAX_PACKET_SIZ);
  1115. client->wb = buffer_new(0);
  1116. /* Set table number. */
  1117. client->rtm_table = zebrad.rtm_table_default;
  1118. /* Add this client to linked list. */
  1119. listnode_add (zebrad.client_list, client);
  1120. /* Make new read thread. */
  1121. zebra_event (ZEBRA_READ, sock, client);
  1122. }
  1123. /* Handler of zebra service request. */
  1124. static int
  1125. zebra_client_read (struct thread *thread)
  1126. {
  1127. int sock;
  1128. struct zserv *client;
  1129. size_t already;
  1130. uint16_t length, command;
  1131. uint8_t marker, version;
  1132. /* Get thread data. Reset reading thread because I'm running. */
  1133. sock = THREAD_FD (thread);
  1134. client = THREAD_ARG (thread);
  1135. client->t_read = NULL;
  1136. if (client->t_suicide)
  1137. {
  1138. zebra_client_close(client);
  1139. return -1;
  1140. }
  1141. /* Read length and command (if we don't have it already). */
  1142. if ((already = stream_get_endp(client->ibuf)) < ZEBRA_HEADER_SIZE)
  1143. {
  1144. ssize_t nbyte;
  1145. if (((nbyte = stream_read_try (client->ibuf, sock,
  1146. ZEBRA_HEADER_SIZE-already)) == 0) ||
  1147. (nbyte == -1))
  1148. {
  1149. if (IS_ZEBRA_DEBUG_EVENT)
  1150. zlog_debug ("connection closed socket [%d]", sock);
  1151. zebra_client_close (client);
  1152. return -1;
  1153. }
  1154. if (nbyte != (ssize_t)(ZEBRA_HEADER_SIZE-already))
  1155. {
  1156. /* Try again later. */
  1157. zebra_event (ZEBRA_READ, sock, client);
  1158. return 0;
  1159. }
  1160. already = ZEBRA_HEADER_SIZE;
  1161. }
  1162. /* Reset to read from the beginning of the incoming packet. */
  1163. stream_set_getp(client->ibuf, 0);
  1164. /* Fetch header values */
  1165. length = stream_getw (client->ibuf);
  1166. marker = stream_getc (client->ibuf);
  1167. version = stream_getc (client->ibuf);
  1168. command = stream_getw (client->ibuf);
  1169. if (marker != ZEBRA_HEADER_MARKER || version != ZSERV_VERSION)
  1170. {
  1171. zlog_err("%s: socket %d version mismatch, marker %d, version %d",
  1172. __func__, sock, marker, version);
  1173. zebra_client_close (client);
  1174. return -1;
  1175. }
  1176. if (length < ZEBRA_HEADER_SIZE)
  1177. {
  1178. zlog_warn("%s: socket %d message length %u is less than header size %d",
  1179. __func__, sock, length, ZEBRA_HEADER_SIZE);
  1180. zebra_client_close (client);
  1181. return -1;
  1182. }
  1183. if (length > STREAM_SIZE(client->ibuf))
  1184. {
  1185. zlog_warn("%s: socket %d message length %u exceeds buffer size %lu",
  1186. __func__, sock, length, (u_long)STREAM_SIZE(client->ibuf));
  1187. zebra_client_close (client);
  1188. return -1;
  1189. }
  1190. /* Read rest of data. */
  1191. if (already < length)
  1192. {
  1193. ssize_t nbyte;
  1194. if (((nbyte = stream_read_try (client->ibuf, sock,
  1195. length-already)) == 0) ||
  1196. (nbyte == -1))
  1197. {
  1198. if (IS_ZEBRA_DEBUG_EVENT)
  1199. zlog_debug ("connection closed [%d] when reading zebra data", sock);
  1200. zebra_client_close (client);
  1201. return -1;
  1202. }
  1203. if (nbyte != (ssize_t)(length-already))
  1204. {
  1205. /* Try again later. */
  1206. zebra_event (ZEBRA_READ, sock, client);
  1207. return 0;
  1208. }
  1209. }
  1210. length -= ZEBRA_HEADER_SIZE;
  1211. /* Debug packet information. */
  1212. if (IS_ZEBRA_DEBUG_EVENT)
  1213. zlog_debug ("zebra message comes from socket [%d]", sock);
  1214. if (IS_ZEBRA_DEBUG_PACKET && IS_ZEBRA_DEBUG_RECV)
  1215. zlog_debug ("zebra message received [%s] %d",
  1216. zserv_command_string (command), length);
  1217. switch (command)
  1218. {
  1219. case ZEBRA_ROUTER_ID_ADD:
  1220. zread_router_id_add (client, length);
  1221. break;
  1222. case ZEBRA_ROUTER_ID_DELETE:
  1223. zread_router_id_delete (client, length);
  1224. break;
  1225. case ZEBRA_INTERFACE_ADD:
  1226. zread_interface_add (client, length);
  1227. break;
  1228. case ZEBRA_INTERFACE_DELETE:
  1229. zread_interface_delete (client, length);
  1230. break;
  1231. case ZEBRA_IPV4_ROUTE_ADD:
  1232. zread_ipv4_add (client, length);
  1233. break;
  1234. case ZEBRA_IPV4_ROUTE_DELETE:
  1235. zread_ipv4_delete (client, length);
  1236. break;
  1237. #ifdef HAVE_IPV6
  1238. case ZEBRA_IPV6_ROUTE_ADD:
  1239. zread_ipv6_add (client, length);
  1240. break;
  1241. case ZEBRA_IPV6_ROUTE_DELETE:
  1242. zread_ipv6_delete (client, length);
  1243. break;
  1244. #endif /* HAVE_IPV6 */
  1245. case ZEBRA_REDISTRIBUTE_ADD:
  1246. zebra_redistribute_add (command, client, length);
  1247. break;
  1248. case ZEBRA_REDISTRIBUTE_DELETE:
  1249. zebra_redistribute_delete (command, client, length);
  1250. break;
  1251. case ZEBRA_REDISTRIBUTE_DEFAULT_ADD:
  1252. zebra_redistribute_default_add (command, client, length);
  1253. break;
  1254. case ZEBRA_REDISTRIBUTE_DEFAULT_DELETE:
  1255. zebra_redistribute_default_delete (command, client, length);
  1256. break;
  1257. case ZEBRA_IPV4_NEXTHOP_LOOKUP:
  1258. zread_ipv4_nexthop_lookup (client, length);
  1259. break;
  1260. case ZEBRA_IPV4_NEXTHOP_LOOKUP_MRIB:
  1261. zread_ipv4_nexthop_lookup_mrib (client, length);
  1262. break;
  1263. #ifdef HAVE_IPV6
  1264. case ZEBRA_IPV6_NEXTHOP_LOOKUP:
  1265. zread_ipv6_nexthop_lookup (client, length);
  1266. break;
  1267. #endif /* HAVE_IPV6 */
  1268. case ZEBRA_IPV4_IMPORT_LOOKUP:
  1269. zread_ipv4_import_lookup (client, length);
  1270. break;
  1271. case ZEBRA_HELLO:
  1272. zread_hello (client);
  1273. break;
  1274. default:
  1275. zlog_info ("Zebra received unknown command %d", command);
  1276. break;
  1277. }
  1278. if (client->t_suicide)
  1279. {
  1280. /* No need to wait for thread callback, just kill immediately. */
  1281. zebra_client_close(client);
  1282. return -1;
  1283. }
  1284. stream_reset (client->ibuf);
  1285. zebra_event (ZEBRA_READ, sock, client);
  1286. return 0;
  1287. }
  1288. /* Accept code of zebra server socket. */
  1289. static int
  1290. zebra_accept (struct thread *thread)
  1291. {
  1292. int accept_sock;
  1293. int client_sock;
  1294. struct sockaddr_in client;
  1295. socklen_t len;
  1296. accept_sock = THREAD_FD (thread);
  1297. /* Reregister myself. */
  1298. zebra_event (ZEBRA_SERV, accept_sock, NULL);
  1299. len = sizeof (struct sockaddr_in);
  1300. client_sock = accept (accept_sock, (struct sockaddr *) &client, &len);
  1301. if (client_sock < 0)
  1302. {
  1303. zlog_warn ("Can't accept zebra socket: %s", safe_strerror (errno));
  1304. return -1;
  1305. }
  1306. /* Make client socket non-blocking. */
  1307. set_nonblocking(client_sock);
  1308. /* Create new zebra client. */
  1309. zebra_client_create (client_sock);
  1310. return 0;
  1311. }
  1312. #ifdef HAVE_TCP_ZEBRA
  1313. /* Make zebra's server socket. */
  1314. static void
  1315. zebra_serv ()
  1316. {
  1317. int ret;
  1318. int accept_sock;
  1319. struct sockaddr_in addr;
  1320. accept_sock = socket (AF_INET, SOCK_STREAM, 0);
  1321. if (accept_sock < 0)
  1322. {
  1323. zlog_warn ("Can't create zserv stream socket: %s",
  1324. safe_strerror (errno));
  1325. zlog_warn ("zebra can't provice full functionality due to above error");
  1326. return;
  1327. }
  1328. memset (&route_type_oaths, 0, sizeof (route_type_oaths));
  1329. memset (&addr, 0, sizeof (struct sockaddr_in));
  1330. addr.sin_family = AF_INET;
  1331. addr.sin_port = htons (ZEBRA_PORT);
  1332. #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
  1333. addr.sin_len = sizeof (struct sockaddr_in);
  1334. #endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */
  1335. addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
  1336. sockopt_reuseaddr (accept_sock);
  1337. sockopt_reuseport (accept_sock);
  1338. if ( zserv_privs.change(ZPRIVS_RAISE) )
  1339. zlog (NULL, LOG_ERR, "Can't raise privileges");
  1340. ret = bind (accept_sock, (struct sockaddr *)&addr,
  1341. sizeof (struct sockaddr_in));
  1342. if (ret < 0)
  1343. {
  1344. zlog_warn ("Can't bind to stream socket: %s",
  1345. safe_strerror (errno));
  1346. zlog_warn ("zebra can't provice full functionality due to above error");
  1347. close (accept_sock); /* Avoid sd leak. */
  1348. return;
  1349. }
  1350. if ( zserv_privs.change(ZPRIVS_LOWER) )
  1351. zlog (NULL, LOG_ERR, "Can't lower privileges");
  1352. ret = listen (accept_sock, 1);
  1353. if (ret < 0)
  1354. {
  1355. zlog_warn ("Can't listen to stream socket: %s",
  1356. safe_strerror (errno));
  1357. zlog_warn ("zebra can't provice full functionality due to above error");
  1358. close (accept_sock); /* Avoid sd leak. */
  1359. return;
  1360. }
  1361. zebra_event (ZEBRA_SERV, accept_sock, NULL);
  1362. }
  1363. #else /* HAVE_TCP_ZEBRA */
  1364. /* For sockaddr_un. */
  1365. #include <sys/un.h>
  1366. /* zebra server UNIX domain socket. */
  1367. static void
  1368. zebra_serv_un (const char *path)
  1369. {
  1370. int ret;
  1371. int sock, len;
  1372. struct sockaddr_un serv;
  1373. mode_t old_mask;
  1374. /* First of all, unlink existing socket */
  1375. unlink (path);
  1376. /* Set umask */
  1377. old_mask = umask (0077);
  1378. /* Make UNIX domain socket. */
  1379. sock = socket (AF_UNIX, SOCK_STREAM, 0);
  1380. if (sock < 0)
  1381. {
  1382. zlog_warn ("Can't create zserv unix socket: %s",
  1383. safe_strerror (errno));
  1384. zlog_warn ("zebra can't provide full functionality due to above error");
  1385. return;
  1386. }
  1387. memset (&route_type_oaths, 0, sizeof (route_type_oaths));
  1388. /* Make server socket. */
  1389. memset (&serv, 0, sizeof (struct sockaddr_un));
  1390. serv.sun_family = AF_UNIX;
  1391. strncpy (serv.sun_path, path, strlen (path));
  1392. #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
  1393. len = serv.sun_len = SUN_LEN(&serv);
  1394. #else
  1395. len = sizeof (serv.sun_family) + strlen (serv.sun_path);
  1396. #endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
  1397. ret = bind (sock, (struct sockaddr *) &serv, len);
  1398. if (ret < 0)
  1399. {
  1400. zlog_warn ("Can't bind to unix socket %s: %s",
  1401. path, safe_strerror (errno));
  1402. zlog_warn ("zebra can't provide full functionality due to above error");
  1403. close (sock);
  1404. return;
  1405. }
  1406. ret = listen (sock, 5);
  1407. if (ret < 0)
  1408. {
  1409. zlog_warn ("Can't listen to unix socket %s: %s",
  1410. path, safe_strerror (errno));
  1411. zlog_warn ("zebra can't provide full functionality due to above error");
  1412. close (sock);
  1413. return;
  1414. }
  1415. umask (old_mask);
  1416. zebra_event (ZEBRA_SERV, sock, NULL);
  1417. }
  1418. #endif /* HAVE_TCP_ZEBRA */
  1419. static void
  1420. zebra_event (enum event event, int sock, struct zserv *client)
  1421. {
  1422. switch (event)
  1423. {
  1424. case ZEBRA_SERV:
  1425. thread_add_read (zebrad.master, zebra_accept, client, sock);
  1426. break;
  1427. case ZEBRA_READ:
  1428. client->t_read =
  1429. thread_add_read (zebrad.master, zebra_client_read, client, sock);
  1430. break;
  1431. case ZEBRA_WRITE:
  1432. /**/
  1433. break;
  1434. }
  1435. }
  1436. /* Display default rtm_table for all clients. */
  1437. DEFUN (show_table,
  1438. show_table_cmd,
  1439. "show table",
  1440. SHOW_STR
  1441. "default routing table to use for all clients\n")
  1442. {
  1443. vty_out (vty, "table %d%s", zebrad.rtm_table_default,
  1444. VTY_NEWLINE);
  1445. return CMD_SUCCESS;
  1446. }
  1447. DEFUN (config_table,
  1448. config_table_cmd,
  1449. "table TABLENO",
  1450. "Configure target kernel routing table\n"
  1451. "TABLE integer\n")
  1452. {
  1453. zebrad.rtm_table_default = strtol (argv[0], (char**)0, 10);
  1454. return CMD_SUCCESS;
  1455. }
  1456. DEFUN (ip_forwarding,
  1457. ip_forwarding_cmd,
  1458. "ip forwarding",
  1459. IP_STR
  1460. "Turn on IP forwarding")
  1461. {
  1462. int ret;
  1463. ret = ipforward ();
  1464. if (ret == 0)
  1465. ret = ipforward_on ();
  1466. if (ret == 0)
  1467. {
  1468. vty_out (vty, "Can't turn on IP forwarding%s", VTY_NEWLINE);
  1469. return CMD_WARNING;
  1470. }
  1471. return CMD_SUCCESS;
  1472. }
  1473. DEFUN (no_ip_forwarding,
  1474. no_ip_forwarding_cmd,
  1475. "no ip forwarding",
  1476. NO_STR
  1477. IP_STR
  1478. "Turn off IP forwarding")
  1479. {
  1480. int ret;
  1481. ret = ipforward ();
  1482. if (ret != 0)
  1483. ret = ipforward_off ();
  1484. if (ret != 0)
  1485. {
  1486. vty_out (vty, "Can't turn off IP forwarding%s", VTY_NEWLINE);
  1487. return CMD_WARNING;
  1488. }
  1489. return CMD_SUCCESS;
  1490. }
  1491. /* This command is for debugging purpose. */
  1492. DEFUN (show_zebra_client,
  1493. show_zebra_client_cmd,
  1494. "show zebra client",
  1495. SHOW_STR
  1496. "Zebra information"
  1497. "Client information")
  1498. {
  1499. struct listnode *node;
  1500. struct zserv *client;
  1501. for (ALL_LIST_ELEMENTS_RO (zebrad.client_list, node, client))
  1502. vty_out (vty, "Client fd %d%s", client->sock, VTY_NEWLINE);
  1503. return CMD_SUCCESS;
  1504. }
  1505. /* Table configuration write function. */
  1506. static int
  1507. config_write_table (struct vty *vty)
  1508. {
  1509. if (zebrad.rtm_table_default)
  1510. vty_out (vty, "table %d%s", zebrad.rtm_table_default,
  1511. VTY_NEWLINE);
  1512. return 0;
  1513. }
  1514. /* table node for routing tables. */
  1515. static struct cmd_node table_node =
  1516. {
  1517. TABLE_NODE,
  1518. "", /* This node has no interface. */
  1519. 1
  1520. };
  1521. /* Only display ip forwarding is enabled or not. */
  1522. DEFUN (show_ip_forwarding,
  1523. show_ip_forwarding_cmd,
  1524. "show ip forwarding",
  1525. SHOW_STR
  1526. IP_STR
  1527. "IP forwarding status\n")
  1528. {
  1529. int ret;
  1530. ret = ipforward ();
  1531. if (ret == 0)
  1532. vty_out (vty, "IP forwarding is off%s", VTY_NEWLINE);
  1533. else
  1534. vty_out (vty, "IP forwarding is on%s", VTY_NEWLINE);
  1535. return CMD_SUCCESS;
  1536. }
  1537. #ifdef HAVE_IPV6
  1538. /* Only display ipv6 forwarding is enabled or not. */
  1539. DEFUN (show_ipv6_forwarding,
  1540. show_ipv6_forwarding_cmd,
  1541. "show ipv6 forwarding",
  1542. SHOW_STR
  1543. "IPv6 information\n"
  1544. "Forwarding status\n")
  1545. {
  1546. int ret;
  1547. ret = ipforward_ipv6 ();
  1548. switch (ret)
  1549. {
  1550. case -1:
  1551. vty_out (vty, "ipv6 forwarding is unknown%s", VTY_NEWLINE);
  1552. break;
  1553. case 0:
  1554. vty_out (vty, "ipv6 forwarding is %s%s", "off", VTY_NEWLINE);
  1555. break;
  1556. case 1:
  1557. vty_out (vty, "ipv6 forwarding is %s%s", "on", VTY_NEWLINE);
  1558. break;
  1559. default:
  1560. vty_out (vty, "ipv6 forwarding is %s%s", "off", VTY_NEWLINE);
  1561. break;
  1562. }
  1563. return CMD_SUCCESS;
  1564. }
  1565. DEFUN (ipv6_forwarding,
  1566. ipv6_forwarding_cmd,
  1567. "ipv6 forwarding",
  1568. IPV6_STR
  1569. "Turn on IPv6 forwarding")
  1570. {
  1571. int ret;
  1572. ret = ipforward_ipv6 ();
  1573. if (ret == 0)
  1574. ret = ipforward_ipv6_on ();
  1575. if (ret == 0)
  1576. {
  1577. vty_out (vty, "Can't turn on IPv6 forwarding%s", VTY_NEWLINE);
  1578. return CMD_WARNING;
  1579. }
  1580. return CMD_SUCCESS;
  1581. }
  1582. DEFUN (no_ipv6_forwarding,
  1583. no_ipv6_forwarding_cmd,
  1584. "no ipv6 forwarding",
  1585. NO_STR
  1586. IPV6_STR
  1587. "Turn off IPv6 forwarding")
  1588. {
  1589. int ret;
  1590. ret = ipforward_ipv6 ();
  1591. if (ret != 0)
  1592. ret = ipforward_ipv6_off ();
  1593. if (ret != 0)
  1594. {
  1595. vty_out (vty, "Can't turn off IPv6 forwarding%s", VTY_NEWLINE);
  1596. return CMD_WARNING;
  1597. }
  1598. return CMD_SUCCESS;
  1599. }
  1600. #endif /* HAVE_IPV6 */
  1601. /* IPForwarding configuration write function. */
  1602. static int
  1603. config_write_forwarding (struct vty *vty)
  1604. {
  1605. /* FIXME: Find better place for that. */
  1606. router_id_write (vty);
  1607. if (ipforward ())
  1608. vty_out (vty, "ip forwarding%s", VTY_NEWLINE);
  1609. #ifdef HAVE_IPV6
  1610. if (ipforward_ipv6 ())
  1611. vty_out (vty, "ipv6 forwarding%s", VTY_NEWLINE);
  1612. #endif /* HAVE_IPV6 */
  1613. vty_out (vty, "!%s", VTY_NEWLINE);
  1614. return 0;
  1615. }
  1616. /* table node for routing tables. */
  1617. static struct cmd_node forwarding_node =
  1618. {
  1619. FORWARDING_NODE,
  1620. "", /* This node has no interface. */
  1621. 1
  1622. };
  1623. /* Initialisation of zebra and installation of commands. */
  1624. void
  1625. zebra_init (void)
  1626. {
  1627. /* Client list init. */
  1628. zebrad.client_list = list_new ();
  1629. /* Install configuration write function. */
  1630. install_node (&table_node, config_write_table);
  1631. install_node (&forwarding_node, config_write_forwarding);
  1632. install_element (VIEW_NODE, &show_ip_forwarding_cmd);
  1633. install_element (ENABLE_NODE, &show_ip_forwarding_cmd);
  1634. install_element (CONFIG_NODE, &ip_forwarding_cmd);
  1635. install_element (CONFIG_NODE, &no_ip_forwarding_cmd);
  1636. install_element (ENABLE_NODE, &show_zebra_client_cmd);
  1637. #ifdef HAVE_NETLINK
  1638. install_element (VIEW_NODE, &show_table_cmd);
  1639. install_element (ENABLE_NODE, &show_table_cmd);
  1640. install_element (CONFIG_NODE, &config_table_cmd);
  1641. #endif /* HAVE_NETLINK */
  1642. #ifdef HAVE_IPV6
  1643. install_element (VIEW_NODE, &show_ipv6_forwarding_cmd);
  1644. install_element (ENABLE_NODE, &show_ipv6_forwarding_cmd);
  1645. install_element (CONFIG_NODE, &ipv6_forwarding_cmd);
  1646. install_element (CONFIG_NODE, &no_ipv6_forwarding_cmd);
  1647. #endif /* HAVE_IPV6 */
  1648. /* Route-map */
  1649. zebra_route_map_init ();
  1650. }
  1651. /* Make zebra server socket, wiping any existing one (see bug #403). */
  1652. void
  1653. zebra_zserv_socket_init (char *path)
  1654. {
  1655. #ifdef HAVE_TCP_ZEBRA
  1656. zebra_serv ();
  1657. #else
  1658. zebra_serv_un (path ? path : ZEBRA_SERV_PATH);
  1659. #endif /* HAVE_TCP_ZEBRA */
  1660. }