/* Send requests to zebra daemon for the information in a VRF. */ void zclient_send_requests (struct zclient *zclient, vrf_id_t vrf_id) { int i; /* zclient is disabled. */ if (! zclient->enable) return; /* If not connected to the zebra yet. */ if (zclient->sock < 0) return; if (zclient_debug) zlog_debug ("%s: send messages for VRF %u", __func__, vrf_id); /* We need router-id information. */ zebra_message_send (zclient, ZEBRA_ROUTER_ID_ADD, vrf_id); /* We need interface information. */ zebra_message_send (zclient, ZEBRA_INTERFACE_ADD, vrf_id); /* Set unwanted redistribute route. */ vrf_bitmap_set (zclient->redist[zclient->redist_default], vrf_id); /* Flush all redistribute request. */ for (i = 0; i < ZEBRA_ROUTE_MAX; i++) if (i != zclient->redist_default && vrf_bitmap_check (zclient->redist[i], vrf_id)) zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, i, vrf_id); /* If default information is needed. */ if (vrf_bitmap_check (zclient->default_information, VRF_DEFAULT)) zebra_message_send (zclient, ZEBRA_REDISTRIBUTE_DEFAULT_ADD, vrf_id); }
/* Make connection to zebra daemon. */ int zclient_start (struct zclient *zclient) { int i; if (zclient_debug) zlog_debug ("zclient_start is called"); /* zclient is disabled. */ if (! zclient->enable) return 0; /* If already connected to the zebra. */ if (zclient->sock >= 0) return 0; /* Check connect thread. */ if (zclient->t_connect) return 0; if (zclient_socket_connect(zclient) < 0) { if (zclient_debug) zlog_debug ("zclient connection fail"); zclient->fail++; zclient_event (ZCLIENT_CONNECT, zclient); return -1; } if (set_nonblocking(zclient->sock) < 0) zlog_warn("%s: set_nonblocking(%d) failed", __func__, zclient->sock); /* Clear fail count. */ zclient->fail = 0; if (zclient_debug) zlog_debug ("zclient connect success with socket [%d]", zclient->sock); /* Create read thread. */ zclient_event (ZCLIENT_READ, zclient); zebra_hello_send (zclient); /* We need router-id information. */ zebra_message_send (zclient, ZEBRA_ROUTER_ID_ADD); /* We need interface information. */ zebra_message_send (zclient, ZEBRA_INTERFACE_ADD); /* Flush all redistribute request. */ for (i = 0; i < ZEBRA_ROUTE_MAX; i++) if (i != zclient->redist_default && zclient->redist[i]) zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, i); /* If default information is needed. */ if (zclient->default_information) zebra_message_send (zclient, ZEBRA_REDISTRIBUTE_DEFAULT_ADD); return 0; }
void zclient_redistribute_default (int command, struct zclient *zclient) { if (command == ZEBRA_REDISTRIBUTE_DEFAULT_ADD) { if (zclient->default_information) return; zclient->default_information = 1; } else { if (!zclient->default_information) return; zclient->default_information = 0; } if (zclient->sock > 0) zebra_message_send (zclient, command); }
void zclient_redistribute_default (int command, struct zclient *zclient, vrf_id_t vrf_id) { if (command == ZEBRA_REDISTRIBUTE_DEFAULT_ADD) { if (vrf_bitmap_check (zclient->default_information, vrf_id)) return; vrf_bitmap_set (zclient->default_information, vrf_id); } else { if (!vrf_bitmap_check (zclient->default_information, vrf_id)) return; vrf_bitmap_unset (zclient->default_information, vrf_id); } if (zclient->sock > 0) zebra_message_send (zclient, command, vrf_id); }
/* Make connection to zebra daemon. */ int #undef zclient zclient_start (struct_zclient *zclient) { int i; if (zclient_debug) zlog_debug ("zclient_start is called"); /* zclient is disabled. */ if (! zclient->enable) return 0; /* If already connected to the zebra. */ if (zclient->sock >= 0) return 0; /* Check connect thread. */ if (zclient->t_connect) return 0; /* Make socket. */ #ifdef HAVE_TCP_ZEBRA zclient->sock = zclient_socket (); #else zclient->sock = zclient_socket_un (ZEBRA_SERV_PATH); #endif /* HAVE_TCP_ZEBRA */ if (zclient->sock < 0) { if (zclient_debug) zlog_debug ("zclient connection fail"); zclient->fail++; zclient_event (ZCLIENT_CONNECT, zclient); return -1; } /* Clear fail count. */ zclient->fail = 0; if (zclient_debug) zlog_debug ("zclient connect success with socket [%d]", zclient->sock); /* Create read thread. */ zclient_event (ZCLIENT_READ, zclient); /* We need interface information. */ zebra_message_send (zclient, ZEBRA_INTERFACE_ADD); /* We need router-id information. */ zebra_message_send (zclient, ZEBRA_ROUTER_ID_ADD); /* Flush all redistribute request. */ for (i = 0; i < ZEBRA_ROUTE_MAX; i++) if (i != zclient->redist_default && zclient->redist[i]) zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient->sock, i); /* If default information is needed. */ if (zclient->default_information) zebra_message_send (zclient, ZEBRA_REDISTRIBUTE_DEFAULT_ADD); return 0; }