--- embedaddon/quagga/ospfd/ospf_zebra.c 2013/07/21 23:54:40 1.1.1.3 +++ embedaddon/quagga/ospfd/ospf_zebra.c 2016/11/02 10:09:12 1.1.1.4 @@ -59,7 +59,7 @@ struct in_addr router_id_zebra; /* Router-id update message from zebra. */ static int ospf_router_id_update_zebra (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct ospf *ospf; struct prefix router_id; @@ -84,11 +84,12 @@ ospf_router_id_update_zebra (int command, struct zclie /* Inteface addition message from zebra. */ static int -ospf_interface_add (int command, struct zclient *zclient, zebra_size_t length) +ospf_interface_add (int command, struct zclient *zclient, zebra_size_t length, + vrf_id_t vrf_id) { struct interface *ifp; - ifp = zebra_interface_add_read (zclient->ibuf); + ifp = zebra_interface_add_read (zclient->ibuf, vrf_id); if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE)) zlog_debug ("Zebra: interface add %s index %d flags %llx metric %d mtu %d", @@ -114,7 +115,7 @@ ospf_interface_add (int command, struct zclient *zclie static int ospf_interface_delete (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct interface *ifp; struct stream *s; @@ -122,7 +123,7 @@ ospf_interface_delete (int command, struct zclient *zc s = zclient->ibuf; /* zebra_interface_state_read() updates interface structure in iflist */ - ifp = zebra_interface_state_read (s); + ifp = zebra_interface_state_read (s, vrf_id); if (ifp == NULL) return 0; @@ -149,7 +150,7 @@ ospf_interface_delete (int command, struct zclient *zc } static struct interface * -zebra_interface_if_lookup (struct stream *s) +zebra_interface_if_lookup (struct stream *s, vrf_id_t vrf_id) { char ifname_tmp[INTERFACE_NAMSIZ]; @@ -163,13 +164,13 @@ zebra_interface_if_lookup (struct stream *s) static int ospf_interface_state_up (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct interface *ifp; struct ospf_interface *oi; struct route_node *rn; - ifp = zebra_interface_if_lookup (zclient->ibuf); + ifp = zebra_interface_if_lookup (zclient->ibuf, vrf_id); if (ifp == NULL) return 0; @@ -225,13 +226,13 @@ ospf_interface_state_up (int command, struct zclient * static int ospf_interface_state_down (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct interface *ifp; struct ospf_interface *oi; struct route_node *node; - ifp = zebra_interface_state_read (zclient->ibuf); + ifp = zebra_interface_state_read (zclient->ibuf, vrf_id); if (ifp == NULL) return 0; @@ -251,11 +252,11 @@ ospf_interface_state_down (int command, struct zclient static int ospf_interface_address_add (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct connected *c; - c = zebra_interface_address_read (command, zclient->ibuf); + c = zebra_interface_address_read (command, zclient->ibuf, vrf_id); if (c == NULL) return 0; @@ -278,7 +279,7 @@ ospf_interface_address_add (int command, struct zclien static int ospf_interface_address_delete (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct connected *c; struct interface *ifp; @@ -286,7 +287,7 @@ ospf_interface_address_delete (int command, struct zcl struct route_node *rn; struct prefix p; - c = zebra_interface_address_read (command, zclient->ibuf); + c = zebra_interface_address_read (command, zclient->ibuf, vrf_id); if (c == NULL) return 0; @@ -311,6 +312,7 @@ ospf_interface_address_delete (int command, struct zcl assert (rn->info); oi = rn->info; + route_unlock_node (rn); /* Call interface hook functions to clean up */ ospf_if_free (oi); @@ -335,7 +337,7 @@ ospf_zebra_add (struct prefix_ipv4 *p, struct ospf_rou struct ospf_path *path; struct listnode *node; - if (zclient->redist[ZEBRA_ROUTE_OSPF]) + if (vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_OSPF], VRF_DEFAULT)) { message = 0; flags = 0; @@ -354,7 +356,7 @@ ospf_zebra_add (struct prefix_ipv4 *p, struct ospf_rou stream_reset (s); /* Put command, type, flags, message. */ - zclient_create_header (s, ZEBRA_IPV4_ROUTE_ADD); + zclient_create_header (s, ZEBRA_IPV4_ROUTE_ADD, VRF_DEFAULT); stream_putc (s, ZEBRA_ROUTE_OSPF); stream_putc (s, flags); stream_putc (s, message); @@ -433,7 +435,7 @@ ospf_zebra_delete (struct prefix_ipv4 *p, struct ospf_ struct ospf_path *path; struct listnode *node; - if (zclient->redist[ZEBRA_ROUTE_OSPF]) + if (vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_OSPF], VRF_DEFAULT)) { message = 0; flags = 0; @@ -444,7 +446,7 @@ ospf_zebra_delete (struct prefix_ipv4 *p, struct ospf_ stream_reset (s); /* Put command, type, flags, message. */ - zclient_create_header (s, ZEBRA_IPV4_ROUTE_DELETE); + zclient_create_header (s, ZEBRA_IPV4_ROUTE_DELETE, VRF_DEFAULT); stream_putc (s, ZEBRA_ROUTE_OSPF); stream_putc (s, flags); stream_putc (s, message); @@ -482,7 +484,7 @@ ospf_zebra_delete (struct prefix_ipv4 *p, struct ospf_ if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE)) { char buf[2][INET_ADDRSTRLEN]; - zlog_debug("Zebra: Route add %s/%d nexthop %s", + zlog_debug("Zebra: Route delete %s/%d nexthop %s", inet_ntop(AF_INET, &p->prefix, buf[0], sizeof(buf[0])), p->prefixlen, @@ -514,8 +516,9 @@ ospf_zebra_add_discard (struct prefix_ipv4 *p) { struct zapi_ipv4 api; - if (zclient->redist[ZEBRA_ROUTE_OSPF]) + if (vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_OSPF], VRF_DEFAULT)) { + api.vrf_id = VRF_DEFAULT; api.type = ZEBRA_ROUTE_OSPF; api.flags = ZEBRA_FLAG_BLACKHOLE; api.message = 0; @@ -537,8 +540,9 @@ ospf_zebra_delete_discard (struct prefix_ipv4 *p) { struct zapi_ipv4 api; - if (zclient->redist[ZEBRA_ROUTE_OSPF]) + if (vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_OSPF], VRF_DEFAULT)) { + api.vrf_id = VRF_DEFAULT; api.type = ZEBRA_ROUTE_OSPF; api.flags = ZEBRA_FLAG_BLACKHOLE; api.message = 0; @@ -560,7 +564,8 @@ int ospf_is_type_redistributed (int type) { return (DEFAULT_ROUTE_TYPE (type)) ? - zclient->default_information : zclient->redist[type]; + vrf_bitmap_check (zclient->default_information, VRF_DEFAULT) : \ + vrf_bitmap_check (zclient->redist[type], VRF_DEFAULT); } int @@ -594,7 +599,7 @@ ospf_redistribute_set (struct ospf *ospf, int type, in ospf->dmetric[type].type = mtype; ospf->dmetric[type].value = mvalue; - zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, type); + zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, type, VRF_DEFAULT); if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE)) zlog_debug ("Redistribute[%s]: Start Type[%d], Metric[%d]", @@ -615,7 +620,7 @@ ospf_redistribute_unset (struct ospf *ospf, int type) if (!ospf_is_type_redistributed (type)) return CMD_SUCCESS; - zclient_redistribute (ZEBRA_REDISTRIBUTE_DELETE, zclient, type); + zclient_redistribute (ZEBRA_REDISTRIBUTE_DELETE, zclient, type, VRF_DEFAULT); if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE)) zlog_debug ("Redistribute[%s]: Stop", @@ -655,7 +660,8 @@ ospf_redistribute_default_set (struct ospf *ospf, int return CMD_SUCCESS; } - zclient_redistribute_default (ZEBRA_REDISTRIBUTE_DEFAULT_ADD, zclient); + zclient_redistribute_default (ZEBRA_REDISTRIBUTE_DEFAULT_ADD, zclient, + VRF_DEFAULT); if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE)) zlog_debug ("Redistribute[DEFAULT]: Start Type[%d], Metric[%d]", @@ -682,7 +688,8 @@ ospf_redistribute_default_unset (struct ospf *ospf) ospf->dmetric[DEFAULT_ROUTE].type = -1; ospf->dmetric[DEFAULT_ROUTE].value = -1; - zclient_redistribute_default (ZEBRA_REDISTRIBUTE_DEFAULT_DELETE, zclient); + zclient_redistribute_default (ZEBRA_REDISTRIBUTE_DEFAULT_DELETE, zclient, + VRF_DEFAULT); if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE)) zlog_debug ("Redistribute[DEFAULT]: Stop"); @@ -816,7 +823,7 @@ ospf_routemap_unset (struct ospf *ospf, int type) /* Zebra route add and delete treatment. */ static int ospf_zebra_read_ipv4 (int command, struct zclient *zclient, - zebra_size_t length) + zebra_size_t length, vrf_id_t vrf_id) { struct stream *s; struct zapi_ipv4 api; @@ -825,6 +832,7 @@ ospf_zebra_read_ipv4 (int command, struct zclient *zcl struct prefix_ipv4 p; struct external_info *ei; struct ospf *ospf; + unsigned char plength = 0; s = zclient->ibuf; ifindex = 0; @@ -838,7 +846,8 @@ ospf_zebra_read_ipv4 (int command, struct zclient *zcl /* IPv4 prefix. */ memset (&p, 0, sizeof (struct prefix_ipv4)); p.family = AF_INET; - p.prefixlen = stream_getc (s); + plength = stream_getc (s); + p.prefixlen = MIN(IPV4_MAX_PREFIXLEN, plength); stream_get (&p.prefix, s, PSIZE (p.prefixlen)); if (IPV4_NET127(ntohl(p.prefix.s_addr))) @@ -918,8 +927,8 @@ ospf_zebra_read_ipv4 (int command, struct zclient *zcl return 0; } - + int ospf_distribute_list_out_set (struct ospf *ospf, int type, const char *name) { @@ -1000,8 +1009,6 @@ ospf_distribute_list_update_timer (struct thread *thre return 0; } -#define OSPF_DISTRIBUTE_UPDATE_DELAY 5 - /* Update distribute-list and set timer to apply access-list. */ void ospf_distribute_list_update (struct ospf *ospf, uintptr_t type) @@ -1018,8 +1025,8 @@ ospf_distribute_list_update (struct ospf *ospf, uintpt /* Set timer. */ ospf->t_distribute_update = - thread_add_timer (master, ospf_distribute_list_update_timer, - (void *) type, OSPF_DISTRIBUTE_UPDATE_DELAY); + thread_add_timer_msec (master, ospf_distribute_list_update_timer, + (void *) type, ospf->min_ls_interval); } /* If access-list is updated, apply some check. */ @@ -1126,7 +1133,7 @@ ospf_prefix_list_update (struct prefix_list *plist) { /* Update filter-list in. */ if (PREFIX_NAME_IN (area)) - if (strcmp (PREFIX_NAME_IN (area), plist->name) == 0) + if (strcmp (PREFIX_NAME_IN (area), prefix_list_name (plist)) == 0) { PREFIX_LIST_IN (area) = prefix_list_lookup (AFI_IP, PREFIX_NAME_IN (area)); @@ -1135,7 +1142,7 @@ ospf_prefix_list_update (struct prefix_list *plist) /* Update filter-list out. */ if (PREFIX_NAME_OUT (area)) - if (strcmp (PREFIX_NAME_OUT (area), plist->name) == 0) + if (strcmp (PREFIX_NAME_OUT (area), prefix_list_name (plist)) == 0) { PREFIX_LIST_IN (area) = prefix_list_lookup (AFI_IP, PREFIX_NAME_OUT (area)); @@ -1292,12 +1299,19 @@ ospf_distance_apply (struct prefix_ipv4 *p, struct osp return 0; } +static void +ospf_zebra_connected (struct zclient *zclient) +{ + zclient_send_requests (zclient, VRF_DEFAULT); +} + void -ospf_zebra_init () +ospf_zebra_init (struct thread_master *master) { /* Allocate zebra structure. */ - zclient = zclient_new (); + zclient = zclient_new (master); zclient_init (zclient, ZEBRA_ROUTE_OSPF); + zclient->zebra_connected = ospf_zebra_connected; zclient->router_id_update = ospf_router_id_update_zebra; zclient->interface_add = ospf_interface_add; zclient->interface_delete = ospf_interface_delete;